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*/
39template <class T>
40class _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\
76private:\
77typedef _VDK_Event_Unit<_owner_class> _EventUnit;\
78typedef VDKValueList< _EventUnit > _EventCallbackList;\
79typedef VDKValueListIterator< _EventUnit > _EventCallbackListIterator;\
80_EventCallbackList _event_cbList;\
81public:\
82/*virtual bool FindEventAtClassLevel(VDKObject* Pm, VDKString& event);*/\
83virtual bool FindEventAtClassLevel(VDKObject* Pm, char* event);\
84/*virtual bool FindEventAtParentLevel(VDKObject* Pm, VDKString& event);*/\
85virtual bool FindEventAtParentLevel(VDKObject* Pm, char* event);\
86virtual int VDKEventUnitResponse(GtkWidget* , char* , GdkEvent* , void*);\
87\
88\
89\
90int EventConnect(VDKObject* object, char* event,\
91 bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after = false);\
92int EventConnect(char* event,\
93 bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after = false)\
94{\
95return EventConnect(this, event, Pmf,after);\
96}\
97\
98\
99bool 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)*/\
108bool _owner_class::FindEventAtClassLevel(VDKObject* Pm, char* event)\
109{\
110_EventUnit su(Pm,event, (bool (_owner_class::*)(VDKObject*, GdkEvent*)) NULL);\
111if(_event_cbList.find(su))\
112 return true;\
113else\
114 return _ancestor_class::FindEventAtClassLevel(Pm,event);\
115}\
116\
117\
118/*bool _owner_class::FindEventAtParentLevel(VDKObject* Pm, VDKString& event)*/\
119bool _owner_class::FindEventAtParentLevel(VDKObject* Pm, char* event)\
120{\
121VDKObject* parent;\
122for(parent = Parent(); parent; parent = parent->Parent())\
123 if(parent->FindEventAtClassLevel(Pm,event))\
124 return true;\
125return false;\
126}\
127\
128\
129\
130int _owner_class::EventConnect(VDKObject* obj, char* event,\
131 bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after)\
132{\
133bool found = false;\
134VDKObjectEventUnit* su = new VDKObjectEventUnit(this,obj,event);\
135euList.add(su);\
136_EventUnit sigUnit(obj,event,Pmf);\
137found = obj->FindEventAtClassLevel(sigUnit.Pm,sigUnit.event) || \
138 obj->FindEventAtParentLevel(sigUnit.Pm,sigUnit.event);\
139if(!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) );\
146else\
147 sigUnit.slot = (_event_cbList.size()+1)*-1;\
148sigUnit.gtkobj = obj->ConnectingWidget() != NULL ? \
149 GTK_OBJECT(obj->ConnectingWidget()) : NULL;\
150_event_cbList.add(sigUnit);\
151return sigUnit.slot;\
152}\
153\
154\
155\
156bool _owner_class::EventDisconnect(int slot)\
157{\
158int t = 0;\
159_EventCallbackListIterator li(_event_cbList);\
160for(;li;li++,t++)\
161{\
162_EventUnit su = li.current();\
163if(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}\
171return false;\
172}\
173\
174\
175int _owner_class::VDKEventUnitResponse(GtkWidget* mobj,\
176 char* event,\
177 GdkEvent* evType,\
178 void* obj)\
179{\
180bool treated = false;\
181VDKObject* vdkobj = reinterpret_cast<VDKObject*>(obj);\
182_EventCallbackListIterator li(_event_cbList);\
183for(;li;li++)\
184{\
185_EventUnit su = li.current();\
186if ( (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}\
195if(treated)\
196 return 1;\
197else\
198 return _ancestor_class::VDKEventUnitResponse(mobj,event,evType,obj);\
199}
200
201#endif
202
Definition: vdkobj.h:141