vdk 2.4.0
siglisthandle.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 SIGLISTHANDLE_H
27 #define SIGLISTHANDLE_H
28 #include <string.h>
29 #include <vdk/vdkobj.h>
30 // #include <vdk/vdkstring.h>
31 #include <vdk/value_sem_list.h>
32 #include <gdk/gdktypes.h>
33 #include <cstring>
34 #define VDK_SIGNAL_NAME_LENGHT 63
35 /*
36 ==============================================
37  SIGNAL LIST ROUTINES
38 ==============================================
39 */
40 /*
41 A signal unit is a single signal package
42 generated by SignalConnect and added to
43 object callback list. As a signal is emitted
44 by a gtk+ widget this list is searched to
45 find informations to compute response method
46 address and call it with sender object as
47 argument
48  */
49 template <class T>
50 class _VDK_Signal_Unit {
51 
52  public:
53  typedef bool (T::*PMF)(VDKObject* sender);
54  VDKObject* Pm;
55  // *** VDKString signal; /* signal name ala Gtk+ */
56  char signal[VDK_SIGNAL_NAME_LENGHT+1];
57  PMF Pmf; /* <class T> member function offset */
58  gint slot; /* gtk+ slot returned by gtk_signal_connect() */
59  bool connected;
60  GtkObject* gtkobj; /* gtk object */
61  _VDK_Signal_Unit(VDKObject* Pm, char* sign,
62  PMF Pmf):
63  //*** Pm(Pm),signal(sign),Pmf(Pmf), slot(-1),connected(true) {}
64  Pm(Pm),Pmf(Pmf), slot(-1),connected(true)
65  {
66  std::strncpy(signal,sign,VDK_SIGNAL_NAME_LENGHT);
67  // for safe
68  signal[VDK_SIGNAL_NAME_LENGHT] = '\0';
69  }
70  bool operator ==(_VDK_Signal_Unit& su)
71  //*** { return (signal == su.signal) && (Pm == su.Pm); }
72  { return ((!std::strcmp(signal,su.signal)) && (Pm == su.Pm)); }
73 };
74 
75 
76 
77 #define DECLARE_SIGNAL_LIST(_owner_class) \
78 \
79 private:\
80 typedef _VDK_Signal_Unit<_owner_class> _SignalUnit;\
81 typedef VDKValueList< _SignalUnit > _CallbackList;\
82 typedef VDKValueListIterator< _SignalUnit > _CallbackListIterator;\
83 _CallbackList _cbList;\
84 public:\
85 /*virtual bool FindSignalAtClassLevel(VDKObject* Pm, VDKString& signal);*/\
86 /*virtual bool FindSignalAtParentLevel(VDKObject* Pm, VDKString& signal);*/\
87 virtual bool FindSignalAtClassLevel(VDKObject* Pm, char* signal);\
88 virtual bool FindSignalAtParentLevel(VDKObject* Pm, char* signal);\
89 virtual int VDKSignalUnitResponse(GtkWidget* , char* , void*);\
90 \
91 \
92 \
93 int SignalConnect(VDKObject* object, char* signal,\
94  bool (_owner_class::*Pmf)(VDKObject* sender), bool gtk = true, bool after = false);\
95 int SignalConnect(char* signal,\
96  bool (_owner_class::*Pmf)(VDKObject* sender), bool gtk = true, bool after = false)\
97 {\
98 return SignalConnect(this, signal, Pmf,gtk, after);\
99 }\
100 \
101 virtual int VDKSignalResponseListSize() { return _cbList.size(); }\
102 \
103 bool SignalDisconnect(int slot);
104 
105 /*
106 Routines logic: (valid also for events)
107 
108 1. Signal connecting: SignalConnect()
109 
110  A signal unit is generated and a recursive visiting
111  algorithm are called: FindSignalAtClassLevel() and
112  FindSignalAtParentLevel(). If the signal is not found
113  into ancestor or parent classes callback lists a "real"
114  Gtk+ connecting is called (in this case slot number
115  will be positive), otherwise no "real" Gtk+ is used
116  (slot number < 0). Signal unit is added to object callback list.
117 
118 2.Signal emitted: VDKSignalUnitResponse()
119 
120  This routine receives signal name and sender address.
121  Search into callback list to find a match. If found
122  computes response method address and call it with
123  sender as argument. If response method answers true
124  flag the signal as treated and return. Otherwise
125  recursively call himself into ancestor class.
126 
127 3. Signal disconnecting: SignalDisconnect()
128 
129  Callback list is searched to find a match with slot.
130  If found and slot number is > 0 a "real" Gtk+ disconnecting
131  is called too.
132  Signal unit is removed from callback list.
133  */
134 
135 #define DEFINE_SIGNAL_LIST(_owner_class, _ancestor_class)\
136 \
137 \
138 /*bool _owner_class::FindSignalAtClassLevel(VDKObject* Pm, VDKString& signal)*/\
139 bool _owner_class::FindSignalAtClassLevel(VDKObject* Pm, char* signal)\
140 {\
141 _SignalUnit su(Pm,signal, (bool (_owner_class::*)(VDKObject*)) NULL);\
142 if(_cbList.find(su))\
143  return true;\
144 else\
145  return _ancestor_class::FindSignalAtClassLevel(Pm,signal);\
146 }\
147 \
148 \
149 /*bool _owner_class::FindSignalAtParentLevel(VDKObject* Pm, VDKString& signal)*/\
150 bool _owner_class::FindSignalAtParentLevel(VDKObject* Pm, char* signal)\
151 {\
152 VDKObject* parent;\
153 for(parent = Parent(); parent; parent = parent->Parent())\
154  if(parent->FindSignalAtClassLevel(Pm,signal))\
155  return true;\
156 return false;\
157 }\
158 \
159 \
160 \
161 int _owner_class::SignalConnect(VDKObject* obj,char* signal,\
162  bool (_owner_class::*Pmf)(VDKObject* sender), bool gtk, bool after)\
163 {\
164 bool found = false;\
165 VDKObjectSignalUnit* su = new VDKObjectSignalUnit(this,obj,signal);\
166 suList.add(su);\
167 _SignalUnit sigUnit(obj,signal,Pmf);\
168 found = obj->FindSignalAtClassLevel(sigUnit.Pm,sigUnit.signal) || \
169  obj->FindSignalAtParentLevel(sigUnit.Pm,sigUnit.signal);\
170 if(!found && gtk)\
171 sigUnit.slot = after ? gtk_signal_connect_after(GTK_OBJECT(obj->ConnectingWidget()),signal,\
172  GTK_SIGNAL_FUNC(VDKObject::VDKSignalUnitPipe),\
173  reinterpret_cast<gpointer>(su) ):\
174  gtk_signal_connect(GTK_OBJECT(obj->ConnectingWidget()),signal,\
175  GTK_SIGNAL_FUNC(VDKObject::VDKSignalUnitPipe),\
176  reinterpret_cast<gpointer>(su) );\
177 else\
178  sigUnit.slot = (_cbList.size()+1)*-1;\
179 sigUnit.gtkobj = obj->ConnectingWidget() != NULL ? \
180  GTK_OBJECT(obj->ConnectingWidget()) : NULL;\
181 _cbList.add(sigUnit);\
182 return sigUnit.slot;\
183 }\
184 \
185 \
186 \
187 bool _owner_class::SignalDisconnect(int slot)\
188 {\
189 int t = 0;\
190 _CallbackListIterator li(_cbList);\
191 for(;li;li++,t++)\
192 {\
193 _SignalUnit su = li.current();\
194 if(su.slot == slot)\
195  {\
196  if(su.slot > 0)\
197  gtk_signal_disconnect(su.gtkobj,su.slot);\
198  _cbList.unlink(t);\
199  return true;\
200  }\
201 }\
202 return false;\
203 }\
204 \
205 \
206 int _owner_class::VDKSignalUnitResponse(GtkWidget* mobj,\
207  char* signal, void* obj)\
208 {\
209 bool treated = false;\
210 VDKObject* vdkobj = reinterpret_cast<VDKObject*>(obj);\
211 _CallbackListIterator li(_cbList);\
212 for(;li;li++)\
213 {\
214 _SignalUnit su = li.current();\
215 if ( (su.Pm == vdkobj) &&\
216  (!std::strcmp(su.signal,signal) && su.connected))\
217  {\
218  bool(_owner_class::*response)(VDKObject* sender)= \
219  su.Pmf;\
220  if(((*this).*response)(vdkobj) == true)\
221  treated = true;\
222  }\
223 }\
224 if(treated)\
225  return 1;\
226 else\
227  return _ancestor_class::VDKSignalUnitResponse(mobj,signal,obj);\
228 }
229 
230 #endif
231 /*
232 if(!found && gtk)\
233  sigUnit.slot = after ? gtk_signal_connect_after(GTK_OBJECT(obj->ConnectingWidget()),signal,\
234  GTK_SIGNAL_FUNC(VDKObject::VDKSignalUnitPipe),\
235  reinterpret_cast<gpointer>(su) ):\
236  gtk_signal_connect(GTK_OBJECT(obj->ConnectingWidget()),signal,\
237  GTK_SIGNAL_FUNC(VDKObject::VDKSignalUnitPipe),\
238  reinterpret_cast<gpointer>(su) );\
239 */
240 
241 
242 
243 
Definition: vdkobj.h:141