vdk 2.4.0
vdkobj.h
1 /* -*- c++ -*- */
2 /*
3  * ===========================
4  * VDK Visual Development Kit
5  * Version 0.4
6  * October 1998
7  * ===========================
8  *
9  * Copyright (C) 1998, Mario Motta
10  * Developed by Mario Motta <mmotta@guest.net>
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Library General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  * 02111-130
26  */
27 
28 #ifndef VDKOBJ_H
29 #define VDKOBJ_H
30 #include <gtk/gtk.h>
31 #include <vdk/vdktypes.h>
32 #include <vdk/dlist.h>
33 #include <vdk/vdkutils.h>
34 #include <vdk/rawobj.h>
35 #include <vdk/vdkprops.h>
36 #include <vdk/vdkstring.h>
37 
38 #ifdef USE_SIGCPLUSPLUS
39 # include <vdk/sigc_addon.h>
40 # include <vdk/sigc_events.h>
41 # include <vdk/sigc_eventsignals.h>
42 #endif /* USE_SIGCPLUSPLUS */
43 
44 class VDKForm;
45 class VDKTooltip;
46 class VDKFont;
47 class VDKObject;
51 enum { object_class, form_class , container_class};
52 
53 /*
54  */
57 
63  void* obj;
64  int signal;
65 };
66 
72 {
73 public:
74  void* owner;
75  void* obj;
76  VDKString signal;
77  VDKObjectSignalUnit(void* owner,void *obj, char* signal):
78  owner(owner),obj(obj),signal(signal) {}
80 };
86 
92 {
93 public:
94  void* owner;
95  void* obj;
96  VDKString signal;
97  VDKObjectEventUnit(void* owner,void *obj, char* signal):
98  owner(owner),obj(obj),signal(signal) {}
99  ~VDKObjectEventUnit() {}
100 };
106 
107 /*
108 =============
109 SIZE PROPERTY
110 =============
111 */
112 typedef VDKReadWriteValueProp<VDKObject,VDKPoint> SizeOProp;
113 
114 class SizeObjectProp: public SizeOProp
115 {
116 public:
117  SizeObjectProp(){}
118  SizeObjectProp(char* name, VDKObject* object,
119  void (VDKObject::*write)(VDKPoint) = NULL,
120  VDKPoint (VDKObject::*read)(void) = NULL) : SizeOProp(name,object,VDKPoint(0,0),write,read) {}
121  void operator = (VDKPoint);
122  operator VDKPoint();
123 };
124 
125 /*
126  ===============
127  VDKOBJECT CLASS
128  ===============
129 */
132 
136 #ifndef USE_SIGCPLUSPLUS
137 class VDKObject : public VDKNotCopyAble
138 #else
139 class VDKObject : public SigC::Object, public VDKNotCopyAble
140 #endif
141 {
142 
143  public:
144  /*
145  properties
146  */
156  VDKReadWriteValueProp<VDKObject,VDKRgb> NormalBackground;
157  VDKReadWriteValueProp<VDKObject,VDKRgb> PrelightBackground;
158  VDKReadWriteValueProp<VDKObject,VDKRgb> InsensitiveBackground;
159  VDKReadWriteValueProp<VDKObject,VDKRgb> ActiveBackground;
160  VDKReadWriteValueProp<VDKObject,VDKRgb> SelectedBackground;
161  VDKReadWriteValueProp<VDKObject,VDKRgb> Foreground;
168  VDKReadWriteValueProp<VDKObject,VDKFont*> Font;
172  SizeObjectProp Usize;
176  VDKReadWriteValueProp<VDKObject,bool> Enabled;
180  VDKReadWriteValueProp<VDKObject,VDKCursorType> Cursor;
184  VDKReadWriteValueProp<VDKObject,bool> Visible;
185  int Tag;
186 
187 // GTK_STATE_NORMAL = 0, GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT,
188  // GTK_STATE_SELECTED,GTK_STATE_INSENSITIVE
189  void SetNormalBackground(VDKRgb c) {
190  SetBackground(c,GTK_STATE_NORMAL);
191  }
192  void SetPrelightBackground(VDKRgb c) {
193  SetBackground(c,GTK_STATE_PRELIGHT);
194  }
195  void SetInsensitiveBackground(VDKRgb c) {
196  SetBackground(c,GTK_STATE_INSENSITIVE);
197  }
198  void SetActiveBackground(VDKRgb c) {
199  SetBackground(c,GTK_STATE_ACTIVE);
200  }
201  void SetSelectedBackground(VDKRgb c) {
202  SetBackground(c,GTK_STATE_SELECTED);
203  }
207  VDKRgb
208  GetBackground(GtkStateType state = GTK_STATE_NORMAL);
212  VDKRgb
213  GetForeground(GtkStateType state = GTK_STATE_NORMAL);
214 
215 private:
216  /*
217  copy and assignement prohibited
218  */
219  friend class VDKRawObject;
220 // VDKObject(VDKObject& ) {}
221 // VDKObject& operator=(VDKObject& ) {
222 // return *this;
223 // }
224  VDKTooltip* tip;
225 protected:
226  ItemList items;
227  ItemList garbages;
228  RawList raws;
229  SignalUnitList suList;
230  EventUnitList euList;
234  VDKObjectSignal s_clicked,s_pressed,s_released,s_enter,s_leave,
235  s_list_select,s_list_unselect,s_list_click_column,s_realize,
236  s_toggled,s_value_changed,s_child_attached,s_child_detached;
237  VDKForm* owner;
241  GtkWidget* widget;
249  GtkWidget* sigwid;
256  static int VDKEventPipe(GtkWidget* w, GdkEvent* event, void* obj);
259  void _setBackground_(GtkWidget* wid,
260  int red,int green, int blue,
261  GtkStateType state);
264  void _setForeground_(GtkWidget* wid,
265  int red,int green, int blue,
266  GtkStateType state);
269  void _setFont_(GtkWidget* wid, VDKFont* f);
272  void ConnectDefaultEvents();
275  void ConnectDefaultSignals();
278  void SignalEmit(int signal, int level);
282  virtual void ShowWidget(bool visible);
283 
284 public:
288  VDKObject(VDKForm* owner = NULL);
292  VDKObject(VDKForm* owner, GtkWidget* widget);
296  virtual ~VDKObject();
303  bool Destroy();
307  virtual int isA() { return object_class; }
312  return owner;
313  }
317  virtual GtkWidget* Widget();
321  GtkWidget* ConnectingWidget();
334  GtkWidget* WrappedWidget();
338  virtual void SetFont(VDKFont* f);
343  {
344  return Font;
345  }
350  void SetVisible(bool visible);
354  bool GetVisible()
355  {
356  return GTK_WIDGET_VISIBLE(widget);
357  }
361  void SetCursor(VDKCursorType);
365  VDKCursorType GetCursor()
366  {
367  return Cursor;
368  }
374  virtual void SetForeground(VDKRgb color,
375  GtkStateType state = GTK_STATE_NORMAL);
376 
377  void SetNormalForeground(VDKRgb color)
378  {
379  SetForeground(color);
380  }
386  virtual void SetBackground(VDKRgb color,
387  GtkStateType state = GTK_STATE_NORMAL);
393  void SetSize(int w, int h)
394  {
395  if(GTK_IS_WIDGET(widget))
396  gtk_widget_set_usize(GTK_WIDGET(widget),w,h);
397  }
404  {
405  SetSize(s.X(),s.Y());
406  }
407  /*
408  Sets/unsets object sensitivity
409  \param flag, either true or false
410  Tip: with flag=false object does not answer to signal/events
411  */
412  virtual void Enable(bool flag = true);
413  /*
414  Returns if the object is enable or not
415  */
416  bool GetEnabled()
417  {
418  return Enabled;
419  }
423  virtual void SetTip(char* );
434  virtual void Add(VDKObject* obj, int justify = l_justify,
435  int expand = TRUE, int fill = TRUE ,
436  int padding = 0);
441  {
442  return items;
443  }
447  ItemList& Garbages()
448  {
449  return garbages;
450  }
454  RawList& Raws()
455  {
456  return raws;
457  }
461  void Draw(GdkRectangle* area = NULL);
467  virtual void Setup() {}
472  void SignalEmit(int signal);
477  void SignalEmit(char* sig);
482  void SignalEmitParent(int signal) {
483  SignalEmit(signal,Parent_level);
484  }
489  void SignalEmitParent(char* sig);
493  void GrabFocus();
497  void AddItem(VDKObject* item);
501  void RemoveItem(VDKObject* item);
505  void RemoveItems();
506  /*
507 ==================== signal/event management ======================
508  */
512  VDKObject* Parent(VDKObject* p = NULL) {
513  if(p) parent = p; return parent;
514  }
515  // signal and events default dispatchers for class level
519  static void VDKSignalPipe(GtkWidget* w, void* obj);
523  virtual int VDKObjectSignalResponse(GtkWidget* , int , void*, bool)
524  {
525  return FALSE;
526  }
530  virtual int VDKObjectEventResponse(GtkWidget* , GdkEvent*, void*, bool)
531  {
532  return FALSE;
533  }
534 
535  virtual int ObjectSignalDetach(int , int )
536  {
537  return -1;
538  }
539  virtual bool ObjectSignalAttach(int )
540  {
541  return false;
542  }
543  virtual int ObjectEventDetach(VDKEvent )
544  {
545  return -1;
546  }
547  virtual bool ObjectEventAttach(int )
548  {
549  return false;
550  }
551  protected:
552  virtual int VDKObjectSignalResponseTableSize()
553  {
554  return 0;
555  }
556  virtual int VDKObjectEventResponseTableSize()
557  {
558  return 0;
559  }
560  /*
561  */
562  // signal and events default dispatchers for parent level
563 public:
567  virtual int VDKSignalResponse(GtkWidget* , int , void*, void *, bool)
568  {
569  return 0;
570  }
574  virtual int VDKEventResponse(GtkWidget* , GdkEvent* , void*, void*, bool )
575  {
576  return 0;
577  }
578  virtual int SignalDetach(VDKObject* , int )
579  {
580  return -1;
581  }
582  virtual bool SignalAttach(int )
583  {
584  return false;
585  }
586  virtual int EventDetach(VDKObject* ,VDKEvent )
587  {
588  return -1;
589  }
590  virtual bool EventAttach(int )
591  {
592  return false;
593  }
594 protected:
598  virtual int VDKSignalResponseTableSize()
599  {
600  return 0;
601  }
605  virtual int VDKEventResponseTableSize()
606  {
607  return 0;
608  }
609  /*
610 ==================== signal management ala Gtk+ ======================
611  */
612 public:
628  char* signal,
629  bool (VDKObject::*method)(VDKObject*),
630  bool gtk = true,
631  bool after = false)
632  {
633  return -1;
634  }
648  int SignalConnect(char* signal ,
649  bool (VDKObject::*method)(VDKObject*),
650  bool gtk = true,
651  bool after = false)
652  {
653  return -1;
654  }
655  // general signal unit response (at this level simply answer false)
656  virtual int VDKSignalUnitResponse(GtkWidget* , char* , void*)
657  {
658  return 0;
659  }
664  bool SignalDisconnect(int connection)
665  {
666  return false;
667  }
668  // find signal at class level
672  virtual bool FindSignalAtClassLevel(VDKObject* , char* )
673  // virtual bool FindSignalAtClassLevel(VDKObject* , VDKString& )
674  {
675  return false;
676  }
677  // find signal at parent level
681  // virtual bool FindSignalAtParentLevel(VDKObject* , VDKString& )
682  virtual bool FindSignalAtParentLevel(VDKObject* , char* )
683  {
684  return false;
685  }
686 protected:
687  // unique Gtk+ callback that redirects to
688  // above VDKSignalUnitResponse()
692  static void VDKSignalUnitPipe(GtkWidget* , void* );
693  /*
694 ==================== event management ala Gtk+ ======================
695  */
696 public:
700  // virtual bool FindEventAtClassLevel(VDKObject* , VDKString& )
701  virtual bool FindEventAtClassLevel(VDKObject* , char* )
702  {
703  return false;
704  }
708  // virtual bool FindEventAtParentLevel(VDKObject* , VDKString& )
709  virtual bool FindEventAtParentLevel(VDKObject* , char* )
710  {
711  return false;
712  }
716  virtual int VDKEventUnitResponse(GtkWidget* , char* ,
717  GdkEvent* , void*) {
718  return 0;
719  }
730  char* event,
731  bool (VDKObject::*method) (VDKObject* , GdkEvent*),
732  bool after = false)
733  {
734  return -1;
735 
736  }
745  int EventConnect(char* , bool (VDKObject::*) (VDKObject* , GdkEvent*),
746  bool after = false)
747  {
748  return -1;
749  }
754  bool EventDisconnect(int connection)
755  {
756  return false;
757  }
758  virtual int VDKSignalResponseListSize() {
759  return 0;
760  }
761 protected:
762  // unique Gtk+ callback that redirects to
763  // above VDKEventUnitResponse()
767  static int VDKEventUnitPipe(GtkWidget* , GdkEvent*, void* );
768 
769 #ifdef USE_SIGCPLUSPLUS
770  public:
772  VDKRawEventSignal OnRawEvent;
774  VDKButtonSignal OnButtonEvent;
776  VDKKeySignal OnKeyEvent;
778  VDKKeyFocusSignal OnKeyFocusEvent;
780  VDKPointerFocusSignal OnPointerFocusEvent;
782  VDKPointerSignal OnPointerEvent;
784  VDKMapSignal OnMapEvent;
786  VDKGeometrySignal OnGeometryEvent;
788  VDKPaintSignal OnPaintEvent;
789 #endif // USE_SIGCPLUSPLUS
790 };
791 #endif
792 
793 
794 
795 
796 
797 
798 
799 
Provides a raw font.
Definition: vdkfont.h:38
VDKForm widgets, generally the outermost widget container.
Definition: forms.h:69
Provides a VDKList iterator.
Definition: dlist.h:201
Hierarchy root class.
Definition: vdkutils.h:264
Definition: vdkobj.h:92
Definition: vdkobj.h:72
Definition: vdkobj.h:141
virtual ~VDKObject()
Definition: vdkobj.cc:235
void SetVisible(bool visible)
Definition: vdkobj.cc:270
GtkWidget * widget
Definition: vdkobj.h:241
VDKReadWriteValueProp< VDKObject, VDKRgb > NormalBackground
Definition: vdkobj.h:156
virtual void SetForeground(VDKRgb color, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdkobj.cc:577
void SetUsize(VDKPoint s)
Definition: vdkobj.h:403
GtkWidget * sigwid
Definition: vdkobj.h:249
VDKObject(VDKForm *owner=NULL)
Definition: vdkobj.cc:69
int EventConnect(VDKObject *obj, char *event, bool(VDKObject::*method)(VDKObject *, GdkEvent *), bool after=false)
Definition: vdkobj.h:729
int EventConnect(char *, bool(VDKObject::*)(VDKObject *, GdkEvent *), bool after=false)
Definition: vdkobj.h:745
virtual void SetBackground(VDKRgb color, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdkobj.cc:586
bool SignalDisconnect(int connection)
Definition: vdkobj.h:664
VDKRgb GetBackground(GtkStateType state=GTK_STATE_NORMAL)
Definition: vdkobj.cc:596
VDKReadWriteValueProp< VDKObject, bool > Enabled
Definition: vdkobj.h:176
VDKFont * GetFont()
Definition: vdkobj.h:342
bool EventDisconnect(int connection)
Definition: vdkobj.h:754
void SetCursor(VDKCursorType)
Definition: vdkobj.cc:180
void GrabFocus()
Definition: vdkobj.cc:682
virtual void Add(VDKObject *obj, int justify=l_justify, int expand=TRUE, int fill=TRUE, int padding=0)
Definition: vdkobj.cc:708
virtual GtkWidget * Widget()
Definition: vdkobj.cc:49
VDKObjectSignal s_clicked
Definition: vdkobj.h:234
GtkWidget * WrappedWidget()
Definition: vdkobj.cc:62
GtkWidget * ConnectingWidget()
Definition: vdkobj.cc:56
void Draw(GdkRectangle *area=NULL)
Definition: vdkobj.cc:789
VDKForm * Owner()
Definition: vdkobj.h:311
SizeObjectProp Usize
Definition: vdkobj.h:172
ItemList & Items()
Definition: vdkobj.h:440
VDKReadWriteValueProp< VDKObject, VDKCursorType > Cursor
Definition: vdkobj.h:180
bool GetVisible()
Definition: vdkobj.h:354
VDKCursorType GetCursor()
Definition: vdkobj.h:365
virtual void SetFont(VDKFont *f)
Definition: vdkobj.cc:535
VDKObject * Parent(VDKObject *p=NULL)
Definition: vdkobj.h:512
virtual void SetTip(char *)
Definition: vdkobj.cc:671
virtual int isA()
Definition: vdkobj.h:307
VDKReadWriteValueProp< VDKObject, VDKFont * > Font
Definition: vdkobj.h:168
void SetSize(int w, int h)
Definition: vdkobj.h:393
VDKRgb GetForeground(GtkStateType state=GTK_STATE_NORMAL)
Definition: vdkobj.cc:622
bool Destroy()
Definition: vdkobj.cc:765
VDKObject * parent
Definition: vdkobj.h:253
virtual void Setup()
Definition: vdkobj.h:467
int SignalConnect(char *signal, bool(VDKObject::*method)(VDKObject *), bool gtk=true, bool after=false)
Definition: vdkobj.h:648
void SignalEmitParent(int signal)
Definition: vdkobj.h:482
VDKReadWriteValueProp< VDKObject, bool > Visible
Definition: vdkobj.h:184
int SignalConnect(VDKObject *obj, char *signal, bool(VDKObject::*method)(VDKObject *), bool gtk=true, bool after=false)
Definition: vdkobj.h:627
Provides a simple point object.
Definition: vdkutils.h:94
Provides a base class for derived raw objects.
Definition: rawobj.h:39
Provides a simple RGB color structure.
Definition: vdkutils.h:38
Implements famous cont referenced string objects.
Definition: vdkstring.h:46
Provides a tooltip.
Definition: tooltips.h:37
Definition: vdkobj.h:62