vdk 2.4.0
evlisthandle.h
1 /*
2  * ===========================
3  * VDK Visual Develeopment Kit
4  * Version 0.4
5  * October 1998
6  * ===========================
7  *
8  * Copyright (C) 1998, Mario Motta
9  * Developed by Mario Motta <mmotta@guest.net>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26 #ifndef EVLISTHANDLE_H
27 #define EVLISTHANDLE_H
28 #include <vdk/vdkobj.h>
29 // #include <vdk/vdkstring.h>
30 #include <cstring>
31 #include <vdk/value_sem_list.h>
32 #include <gdk/gdktypes.h>
33 #define VDK_EVENT_NAME_LENGHT 63
34 /*
35 ==============================================
36  EVENT LIST ROUTINES
37 ==============================================
38 */
39 template <class T>
40 class _VDK_Event_Unit {
41 
42  public:
43  typedef bool (T::*PMF)(VDKObject* sender, GdkEvent* event);
44  VDKObject* Pm;
45  // VDKString event; /* Event name ala Gtk+ */
46  char event[VDK_EVENT_NAME_LENGHT+1];
47  PMF Pmf; /* <class T> member function offset */
48  gint slot; /* gtk+ slot returned by gtk_signal_connect() */
49  bool connected;
50  GtkObject* gtkobj; /* gtk object */
51  /*
52  _VDK_Event_Unit(VDKObject* Pm, char* event,
53  PMF Pmf):
54  Pm(Pm),event(event),Pmf(Pmf), slot(-1),connected(true) {}
55  */
56  _VDK_Event_Unit(VDKObject* Pm, char* ev,
57  PMF Pmf):
58  Pm(Pm),Pmf(Pmf), slot(-1),connected(true)
59  {
60  std::strncpy(event,ev,VDK_EVENT_NAME_LENGHT);
61  // for safe
62  event[VDK_EVENT_NAME_LENGHT] ='\0';
63  }
64  /*
65  bool operator ==(_VDK_Event_Unit& su)
66  { return (event == su.event) && (Pm == su.Pm); }
67  */
68  bool operator ==(_VDK_Event_Unit& su)
69  { return ((!std::strcmp(event,su.event)) && (Pm == su.Pm)); }
70 };
71 
72 
73 
74 #define DECLARE_EVENT_LIST(_owner_class) \
75 \
76 private:\
77 typedef _VDK_Event_Unit<_owner_class> _EventUnit;\
78 typedef VDKValueList< _EventUnit > _EventCallbackList;\
79 typedef VDKValueListIterator< _EventUnit > _EventCallbackListIterator;\
80 _EventCallbackList _event_cbList;\
81 public:\
82 /*virtual bool FindEventAtClassLevel(VDKObject* Pm, VDKString& event);*/\
83 virtual bool FindEventAtClassLevel(VDKObject* Pm, char* event);\
84 /*virtual bool FindEventAtParentLevel(VDKObject* Pm, VDKString& event);*/\
85 virtual bool FindEventAtParentLevel(VDKObject* Pm, char* event);\
86 virtual int VDKEventUnitResponse(GtkWidget* , char* , GdkEvent* , void*);\
87 \
88 \
89 \
90 int EventConnect(VDKObject* object, char* event,\
91  bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after = false);\
92 int EventConnect(char* event,\
93  bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after = false)\
94 {\
95 return EventConnect(this, event, Pmf,after);\
96 }\
97 \
98 \
99 bool EventDisconnect(int slot);
100 
101 /*
102  */
103 
104 #define DEFINE_EVENT_LIST(_owner_class, _ancestor_class)\
105 \
106 \
107 /*bool _owner_class::FindEventAtClassLevel(VDKObject* Pm, VDKString& event)*/\
108 bool _owner_class::FindEventAtClassLevel(VDKObject* Pm, char* event)\
109 {\
110 _EventUnit su(Pm,event, (bool (_owner_class::*)(VDKObject*, GdkEvent*)) NULL);\
111 if(_event_cbList.find(su))\
112  return true;\
113 else\
114  return _ancestor_class::FindEventAtClassLevel(Pm,event);\
115 }\
116 \
117 \
118 /*bool _owner_class::FindEventAtParentLevel(VDKObject* Pm, VDKString& event)*/\
119 bool _owner_class::FindEventAtParentLevel(VDKObject* Pm, char* event)\
120 {\
121 VDKObject* parent;\
122 for(parent = Parent(); parent; parent = parent->Parent())\
123  if(parent->FindEventAtClassLevel(Pm,event))\
124  return true;\
125 return false;\
126 }\
127 \
128 \
129 \
130 int _owner_class::EventConnect(VDKObject* obj, char* event,\
131  bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after)\
132 {\
133 bool found = false;\
134 VDKObjectEventUnit* su = new VDKObjectEventUnit(this,obj,event);\
135 euList.add(su);\
136 _EventUnit sigUnit(obj,event,Pmf);\
137 found = obj->FindEventAtClassLevel(sigUnit.Pm,sigUnit.event) || \
138  obj->FindEventAtParentLevel(sigUnit.Pm,sigUnit.event);\
139 if(!found)\
140  sigUnit.slot = after ? gtk_signal_connect_after(GTK_OBJECT(obj->ConnectingWidget()),event,\
141  GTK_SIGNAL_FUNC(VDKObject::VDKEventUnitPipe),\
142  reinterpret_cast<gpointer>(su) ):\
143  gtk_signal_connect(GTK_OBJECT(obj->ConnectingWidget()),event,\
144  GTK_SIGNAL_FUNC(VDKObject::VDKEventUnitPipe),\
145  reinterpret_cast<gpointer>(su) );\
146 else\
147  sigUnit.slot = (_event_cbList.size()+1)*-1;\
148 sigUnit.gtkobj = obj->ConnectingWidget() != NULL ? \
149  GTK_OBJECT(obj->ConnectingWidget()) : NULL;\
150 _event_cbList.add(sigUnit);\
151 return sigUnit.slot;\
152 }\
153 \
154 \
155 \
156 bool _owner_class::EventDisconnect(int slot)\
157 {\
158 int t = 0;\
159 _EventCallbackListIterator li(_event_cbList);\
160 for(;li;li++,t++)\
161 {\
162 _EventUnit su = li.current();\
163 if(su.slot == slot)\
164  {\
165  if(su.slot > 0)\
166  gtk_signal_disconnect(su.gtkobj,su.slot);\
167  _event_cbList.unlink(t);\
168  return true;\
169  }\
170 }\
171 return false;\
172 }\
173 \
174 \
175 int _owner_class::VDKEventUnitResponse(GtkWidget* mobj,\
176  char* event,\
177  GdkEvent* evType,\
178  void* obj)\
179 {\
180 bool treated = false;\
181 VDKObject* vdkobj = reinterpret_cast<VDKObject*>(obj);\
182 _EventCallbackListIterator li(_event_cbList);\
183 for(;li;li++)\
184 {\
185 _EventUnit su = li.current();\
186 if ( (su.Pm == vdkobj) &&\
187  (!std::strcmp(su.event,event) && su.connected))\
188  {\
189  bool(_owner_class::*response)(VDKObject* sender, GdkEvent* )= \
190  su.Pmf;\
191  if(((*this).*response)(vdkobj, evType) == true)\
192  treated = true;\
193  }\
194 }\
195 if(treated)\
196  return 1;\
197 else\
198  return _ancestor_class::VDKEventUnitResponse(mobj,event,evType,obj);\
199 }
200 
201 #endif
202 
Definition: vdkobj.h:137