Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

evlisthandle.h

00001 /* 00002 * =========================== 00003 * VDK Visual Develeopment Kit 00004 * Version 0.4 00005 * October 1998 00006 * =========================== 00007 * 00008 * Copyright (C) 1998, Mario Motta 00009 * Developed by Mario Motta <mmotta@guest.net> 00010 * 00011 * This library is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU Library General Public 00013 * License as published by the Free Software Foundation; either 00014 * version 2 of the License, or (at your option) any later version. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Library General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Library General Public 00022 * License along with this library; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00024 * 02111-1307, USA. 00025 */ 00026 #ifndef EVLISTHANDLE_H 00027 #define EVLISTHANDLE_H 00028 #include <vdk/vdkobj.h> 00029 // #include <vdk/vdkstring.h> 00030 #include <cstring> 00031 #include <vdk/value_sem_list.h> 00032 #include <gdk/gdktypes.h> 00033 #define VDK_EVENT_NAME_LENGHT 63 00034 /* 00035 ============================================== 00036 EVENT LIST ROUTINES 00037 ============================================== 00038 */ 00039 template <class T> 00040 class _VDK_Event_Unit { 00041 00042 public: 00043 typedef bool (T::*PMF)(VDKObject* sender, GdkEvent* event); 00044 VDKObject* Pm; 00045 // VDKString event; /* Event name ala Gtk+ */ 00046 char event[VDK_EVENT_NAME_LENGHT+1]; 00047 PMF Pmf; /* <class T> member function offset */ 00048 gint slot; /* gtk+ slot returned by gtk_signal_connect() */ 00049 bool connected; 00050 GtkObject* gtkobj; /* gtk object */ 00051 /* 00052 _VDK_Event_Unit(VDKObject* Pm, char* event, 00053 PMF Pmf): 00054 Pm(Pm),event(event),Pmf(Pmf), slot(-1),connected(true) {} 00055 */ 00056 _VDK_Event_Unit(VDKObject* Pm, char* ev, 00057 PMF Pmf): 00058 Pm(Pm),Pmf(Pmf), slot(-1),connected(true) 00059 { 00060 std::strncpy(event,ev,VDK_EVENT_NAME_LENGHT); 00061 // for safe 00062 event[VDK_EVENT_NAME_LENGHT] ='\0'; 00063 } 00064 /* 00065 bool operator ==(_VDK_Event_Unit& su) 00066 { return (event == su.event) && (Pm == su.Pm); } 00067 */ 00068 bool operator ==(_VDK_Event_Unit& su) 00069 { return ((!std::strcmp(event,su.event)) && (Pm == su.Pm)); } 00070 }; 00071 00072 00073 00074 #define DECLARE_EVENT_LIST(_owner_class) \ 00075 \ 00076 private:\ 00077 typedef _VDK_Event_Unit<_owner_class> _EventUnit;\ 00078 typedef VDKValueList< _EventUnit > _EventCallbackList;\ 00079 typedef VDKValueListIterator< _EventUnit > _EventCallbackListIterator;\ 00080 _EventCallbackList _event_cbList;\ 00081 public:\ 00082 /*virtual bool FindEventAtClassLevel(VDKObject* Pm, VDKString& event);*/\ 00083 virtual bool FindEventAtClassLevel(VDKObject* Pm, char* event);\ 00084 /*virtual bool FindEventAtParentLevel(VDKObject* Pm, VDKString& event);*/\ 00085 virtual bool FindEventAtParentLevel(VDKObject* Pm, char* event);\ 00086 virtual int VDKEventUnitResponse(GtkWidget* , char* , GdkEvent* , void*);\ 00087 \ 00088 \ 00089 \ 00090 int EventConnect(VDKObject* object, char* event,\ 00091 bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after = false);\ 00092 int EventConnect(char* event,\ 00093 bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after = false)\ 00094 {\ 00095 return EventConnect(this, event, Pmf,after);\ 00096 }\ 00097 \ 00098 \ 00099 bool EventDisconnect(int slot); 00100 00101 /* 00102 */ 00103 00104 #define DEFINE_EVENT_LIST(_owner_class, _ancestor_class)\ 00105 \ 00106 \ 00107 /*bool _owner_class::FindEventAtClassLevel(VDKObject* Pm, VDKString& event)*/\ 00108 bool _owner_class::FindEventAtClassLevel(VDKObject* Pm, char* event)\ 00109 {\ 00110 _EventUnit su(Pm,event, (bool (_owner_class::*)(VDKObject*, GdkEvent*)) NULL);\ 00111 if(_event_cbList.find(su))\ 00112 return true;\ 00113 else\ 00114 return _ancestor_class::FindEventAtClassLevel(Pm,event);\ 00115 }\ 00116 \ 00117 \ 00118 /*bool _owner_class::FindEventAtParentLevel(VDKObject* Pm, VDKString& event)*/\ 00119 bool _owner_class::FindEventAtParentLevel(VDKObject* Pm, char* event)\ 00120 {\ 00121 VDKObject* parent;\ 00122 for(parent = Parent(); parent; parent = parent->Parent())\ 00123 if(parent->FindEventAtClassLevel(Pm,event))\ 00124 return true;\ 00125 return false;\ 00126 }\ 00127 \ 00128 \ 00129 \ 00130 int _owner_class::EventConnect(VDKObject* obj, char* event,\ 00131 bool (_owner_class::*Pmf)(VDKObject* sender, GdkEvent*), bool after)\ 00132 {\ 00133 bool found = false;\ 00134 VDKObjectEventUnit* su = new VDKObjectEventUnit(this,obj,event);\ 00135 euList.add(su);\ 00136 _EventUnit sigUnit(obj,event,Pmf);\ 00137 found = obj->FindEventAtClassLevel(sigUnit.Pm,sigUnit.event) || \ 00138 obj->FindEventAtParentLevel(sigUnit.Pm,sigUnit.event);\ 00139 if(!found)\ 00140 sigUnit.slot = after ? gtk_signal_connect_after(GTK_OBJECT(obj->ConnectingWidget()),event,\ 00141 GTK_SIGNAL_FUNC(VDKObject::VDKEventUnitPipe),\ 00142 reinterpret_cast<gpointer>(su) ):\ 00143 gtk_signal_connect(GTK_OBJECT(obj->ConnectingWidget()),event,\ 00144 GTK_SIGNAL_FUNC(VDKObject::VDKEventUnitPipe),\ 00145 reinterpret_cast<gpointer>(su) );\ 00146 else\ 00147 sigUnit.slot = (_event_cbList.size()+1)*-1;\ 00148 sigUnit.gtkobj = obj->ConnectingWidget() != NULL ? \ 00149 GTK_OBJECT(obj->ConnectingWidget()) : NULL;\ 00150 _event_cbList.add(sigUnit);\ 00151 return sigUnit.slot;\ 00152 }\ 00153 \ 00154 \ 00155 \ 00156 bool _owner_class::EventDisconnect(int slot)\ 00157 {\ 00158 int t = 0;\ 00159 _EventCallbackListIterator li(_event_cbList);\ 00160 for(;li;li++,t++)\ 00161 {\ 00162 _EventUnit su = li.current();\ 00163 if(su.slot == slot)\ 00164 {\ 00165 if(su.slot > 0)\ 00166 gtk_signal_disconnect(su.gtkobj,su.slot);\ 00167 _event_cbList.unlink(t);\ 00168 return true;\ 00169 }\ 00170 }\ 00171 return false;\ 00172 }\ 00173 \ 00174 \ 00175 int _owner_class::VDKEventUnitResponse(GtkWidget* mobj,\ 00176 char* event,\ 00177 GdkEvent* evType,\ 00178 void* obj)\ 00179 {\ 00180 bool treated = false;\ 00181 VDKObject* vdkobj = reinterpret_cast<VDKObject*>(obj);\ 00182 _EventCallbackListIterator li(_event_cbList);\ 00183 for(;li;li++)\ 00184 {\ 00185 _EventUnit su = li.current();\ 00186 if ( (su.Pm == vdkobj) &&\ 00187 (!std::strcmp(su.event,event) && su.connected))\ 00188 {\ 00189 bool(_owner_class::*response)(VDKObject* sender, GdkEvent* )= \ 00190 su.Pmf;\ 00191 if(((*this).*response)(vdkobj, evType) == true)\ 00192 treated = true;\ 00193 }\ 00194 }\ 00195 if(treated)\ 00196 return 1;\ 00197 else\ 00198 return _ancestor_class::VDKEventUnitResponse(mobj,event,evType,obj);\ 00199 } 00200 00201 #endif 00202

Generated on Wed Jul 28 17:23:53 2004 for vdk 2.0.3 by doxygen 1.3.7