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/*
41A signal unit is a single signal package
42generated by SignalConnect and added to
43object callback list. As a signal is emitted
44by a gtk+ widget this list is searched to
45find informations to compute response method
46address and call it with sender object as
47argument
48 */
49template <class T>
50class _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\
79private:\
80typedef _VDK_Signal_Unit<_owner_class> _SignalUnit;\
81typedef VDKValueList< _SignalUnit > _CallbackList;\
82typedef VDKValueListIterator< _SignalUnit > _CallbackListIterator;\
83_CallbackList _cbList;\
84public:\
85/*virtual bool FindSignalAtClassLevel(VDKObject* Pm, VDKString& signal);*/\
86/*virtual bool FindSignalAtParentLevel(VDKObject* Pm, VDKString& signal);*/\
87virtual bool FindSignalAtClassLevel(VDKObject* Pm, char* signal);\
88virtual bool FindSignalAtParentLevel(VDKObject* Pm, char* signal);\
89virtual int VDKSignalUnitResponse(GtkWidget* , char* , void*);\
90\
91\
92\
93int SignalConnect(VDKObject* object, char* signal,\
94 bool (_owner_class::*Pmf)(VDKObject* sender), bool gtk = true, bool after = false);\
95int SignalConnect(char* signal,\
96 bool (_owner_class::*Pmf)(VDKObject* sender), bool gtk = true, bool after = false)\
97{\
98return SignalConnect(this, signal, Pmf,gtk, after);\
99}\
100\
101virtual int VDKSignalResponseListSize() { return _cbList.size(); }\
102\
103bool SignalDisconnect(int slot);
104
105/*
106Routines logic: (valid also for events)
107
1081. 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
1182.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
1273. 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)*/\
139bool _owner_class::FindSignalAtClassLevel(VDKObject* Pm, char* signal)\
140{\
141_SignalUnit su(Pm,signal, (bool (_owner_class::*)(VDKObject*)) NULL);\
142if(_cbList.find(su))\
143 return true;\
144else\
145 return _ancestor_class::FindSignalAtClassLevel(Pm,signal);\
146}\
147\
148\
149/*bool _owner_class::FindSignalAtParentLevel(VDKObject* Pm, VDKString& signal)*/\
150bool _owner_class::FindSignalAtParentLevel(VDKObject* Pm, char* signal)\
151{\
152VDKObject* parent;\
153for(parent = Parent(); parent; parent = parent->Parent())\
154 if(parent->FindSignalAtClassLevel(Pm,signal))\
155 return true;\
156return false;\
157}\
158\
159\
160\
161int _owner_class::SignalConnect(VDKObject* obj,char* signal,\
162 bool (_owner_class::*Pmf)(VDKObject* sender), bool gtk, bool after)\
163{\
164bool found = false;\
165VDKObjectSignalUnit* su = new VDKObjectSignalUnit(this,obj,signal);\
166suList.add(su);\
167_SignalUnit sigUnit(obj,signal,Pmf);\
168found = obj->FindSignalAtClassLevel(sigUnit.Pm,sigUnit.signal) || \
169 obj->FindSignalAtParentLevel(sigUnit.Pm,sigUnit.signal);\
170if(!found && gtk)\
171sigUnit.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) );\
177else\
178 sigUnit.slot = (_cbList.size()+1)*-1;\
179sigUnit.gtkobj = obj->ConnectingWidget() != NULL ? \
180 GTK_OBJECT(obj->ConnectingWidget()) : NULL;\
181_cbList.add(sigUnit);\
182return sigUnit.slot;\
183}\
184\
185\
186\
187bool _owner_class::SignalDisconnect(int slot)\
188{\
189int t = 0;\
190_CallbackListIterator li(_cbList);\
191for(;li;li++,t++)\
192{\
193_SignalUnit su = li.current();\
194if(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}\
202return false;\
203}\
204\
205\
206int _owner_class::VDKSignalUnitResponse(GtkWidget* mobj,\
207 char* signal, void* obj)\
208{\
209bool treated = false;\
210VDKObject* vdkobj = reinterpret_cast<VDKObject*>(obj);\
211_CallbackListIterator li(_cbList);\
212for(;li;li++)\
213{\
214_SignalUnit su = li.current();\
215if ( (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}\
224if(treated)\
225 return 1;\
226else\
227 return _ancestor_class::VDKSignalUnitResponse(mobj,signal,obj);\
228}
229
230#endif
231/*
232if(!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