vdk 2.4.0
vdkobj.h
00001 /* -*- c++ -*- */
00002 /*
00003  * ===========================
00004  * VDK Visual Development Kit
00005  * Version 0.4
00006  * October 1998
00007  * ===========================
00008  *
00009  * Copyright (C) 1998, Mario Motta
00010  * Developed by Mario Motta <mmotta@guest.net>
00011  *
00012  * This library is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Library General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2 of the License, or (at your option) any later version.
00016  *
00017  * This library is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Library General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Library General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00025  * 02111-130
00026  */
00027 
00028 #ifndef VDKOBJ_H
00029 #define VDKOBJ_H
00030 #include <gtk/gtk.h>
00031 #include <vdk/vdktypes.h>
00032 #include <vdk/dlist.h>
00033 #include <vdk/vdkutils.h>
00034 #include <vdk/rawobj.h>
00035 #include <vdk/vdkprops.h>
00036 #include <vdk/vdkstring.h>
00037 
00038 #ifdef USE_SIGCPLUSPLUS
00039 #     include <vdk/sigc_addon.h>
00040 #     include <vdk/sigc_events.h>
00041 #     include <vdk/sigc_eventsignals.h>
00042 #endif /* USE_SIGCPLUSPLUS */
00043 
00044 class VDKForm;
00045 class VDKTooltip;
00046 class VDKFont;
00047 class VDKObject;
00051 enum { object_class, form_class , container_class};
00052 
00053 /*
00054  */
00055 typedef VDKList<VDKObject> ItemList;
00056 typedef VDKListiterator<VDKObject> ItemListIterator;
00057 
00062 struct VDKObjectSignal {
00063     void* obj;
00064     int signal;
00065 };
00066 
00071 class VDKObjectSignalUnit
00072 {
00073 public:
00074     void* owner;
00075     void* obj;
00076     VDKString signal;
00077     VDKObjectSignalUnit(void* owner,void *obj, char* signal):
00078         owner(owner),obj(obj),signal(signal) {}
00079     ~VDKObjectSignalUnit() {}
00080 };
00084 typedef VDKList<VDKObjectSignalUnit> SignalUnitList;
00085 typedef VDKListiterator<VDKObjectSignalUnit> SignalUnitListIterator;
00086 
00091 class VDKObjectEventUnit
00092 {
00093 public:
00094     void* owner;
00095     void* obj;
00096     VDKString signal;
00097     VDKObjectEventUnit(void* owner,void *obj, char* signal):
00098         owner(owner),obj(obj),signal(signal) {}
00099     ~VDKObjectEventUnit() {}
00100 };
00104 typedef VDKList<VDKObjectEventUnit> EventUnitList;
00105 typedef VDKListiterator<VDKObjectEventUnit> EventUnitListIterator;
00106 
00107 /*
00108 =============
00109 SIZE PROPERTY
00110 =============
00111 */
00112 typedef VDKReadWriteValueProp<VDKObject,VDKPoint> SizeOProp;
00113 
00114 class SizeObjectProp: public SizeOProp
00115 {
00116 public:
00117     SizeObjectProp(){}
00118     SizeObjectProp(char* name, VDKObject* object,
00119                    void (VDKObject::*write)(VDKPoint) =  NULL,
00120                    VDKPoint (VDKObject::*read)(void) = NULL) : SizeOProp(name,object,VDKPoint(0,0),write,read) {}
00121     void operator = (VDKPoint);
00122     operator VDKPoint();
00123 };
00124 
00125 /*
00126   ===============
00127   VDKOBJECT CLASS
00128   ===============
00129 */
00130 typedef VDKList<VDKRawObject> RawList;
00131 typedef VDKListiterator<VDKRawObject> RawListIterator;
00132 
00136 #ifndef USE_SIGCPLUSPLUS
00137 class VDKObject : public VDKNotCopyAble
00138 #else
00139 class VDKObject : public SigC::Object, public VDKNotCopyAble
00140 #endif
00141 {
00142 
00143  public:
00144   /*
00145     properties
00146   */
00156   VDKReadWriteValueProp<VDKObject,VDKRgb> NormalBackground;
00157   VDKReadWriteValueProp<VDKObject,VDKRgb> PrelightBackground;
00158   VDKReadWriteValueProp<VDKObject,VDKRgb> InsensitiveBackground;
00159   VDKReadWriteValueProp<VDKObject,VDKRgb> ActiveBackground;
00160   VDKReadWriteValueProp<VDKObject,VDKRgb> SelectedBackground;
00161   VDKReadWriteValueProp<VDKObject,VDKRgb> Foreground;
00168   VDKReadWriteValueProp<VDKObject,VDKFont*> Font;
00172   SizeObjectProp Usize;
00176   VDKReadWriteValueProp<VDKObject,bool> Enabled;
00180   VDKReadWriteValueProp<VDKObject,VDKCursorType> Cursor;
00184   VDKReadWriteValueProp<VDKObject,bool> Visible;
00185   int Tag;
00186 
00187 // GTK_STATE_NORMAL = 0, GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT,
00188   // GTK_STATE_SELECTED,GTK_STATE_INSENSITIVE
00189   void SetNormalBackground(VDKRgb c) {
00190       SetBackground(c,GTK_STATE_NORMAL);
00191   }
00192   void SetPrelightBackground(VDKRgb c) {
00193       SetBackground(c,GTK_STATE_PRELIGHT);
00194   }
00195   void SetInsensitiveBackground(VDKRgb c) {
00196       SetBackground(c,GTK_STATE_INSENSITIVE);
00197   }
00198   void SetActiveBackground(VDKRgb c) {
00199       SetBackground(c,GTK_STATE_ACTIVE);
00200   }
00201   void SetSelectedBackground(VDKRgb c) {
00202       SetBackground(c,GTK_STATE_SELECTED);
00203   }
00207   VDKRgb
00208     GetBackground(GtkStateType state = GTK_STATE_NORMAL);
00212   VDKRgb
00213     GetForeground(GtkStateType state = GTK_STATE_NORMAL);
00214 
00215 private:
00216   /*
00217     copy and assignement prohibited
00218     */
00219     friend class VDKRawObject;
00220 //     VDKObject(VDKObject& ) {}
00221 //     VDKObject& operator=(VDKObject& ) {
00222 //         return *this;
00223 //     }
00224     VDKTooltip* tip;
00225 protected:
00226     ItemList items;
00227     ItemList garbages;
00228     RawList  raws;
00229     SignalUnitList suList;
00230     EventUnitList euList;
00234     VDKObjectSignal s_clicked,s_pressed,s_released,s_enter,s_leave,
00235         s_list_select,s_list_unselect,s_list_click_column,s_realize,
00236             s_toggled,s_value_changed,s_child_attached,s_child_detached;
00237     VDKForm* owner;
00241     GtkWidget* widget;
00249     GtkWidget* sigwid;
00253     VDKObject* parent;
00256     static int VDKEventPipe(GtkWidget* w, GdkEvent* event, void* obj);
00259     void _setBackground_(GtkWidget* wid,
00260                          int red,int green, int blue,
00261                          GtkStateType state);
00264     void _setForeground_(GtkWidget* wid,
00265                          int red,int green, int blue,
00266                          GtkStateType state);
00269     void _setFont_(GtkWidget* wid, VDKFont* f);
00272     void ConnectDefaultEvents();
00275     void ConnectDefaultSignals();
00278     void SignalEmit(int signal, int level);
00282     virtual void ShowWidget(bool visible);
00283 
00284 public:
00288     VDKObject(VDKForm* owner = NULL);
00292     VDKObject(VDKForm* owner, GtkWidget* widget);
00296     virtual ~VDKObject();
00303     bool Destroy();
00307     virtual int isA() { return object_class; }
00311     VDKForm* Owner() {
00312         return owner;
00313     }
00317     virtual GtkWidget* Widget();
00321     GtkWidget* ConnectingWidget();
00334     GtkWidget* WrappedWidget();
00338     virtual void SetFont(VDKFont* f);
00342     VDKFont* GetFont() 
00343       {
00344         return Font;
00345       }
00350     void SetVisible(bool visible);
00354     bool GetVisible() 
00355       {
00356         return GTK_WIDGET_VISIBLE(widget);
00357       }
00361     void SetCursor(VDKCursorType);
00365     VDKCursorType     GetCursor() 
00366       {
00367         return Cursor;
00368       }
00374     virtual void SetForeground(VDKRgb color,
00375                                GtkStateType state = GTK_STATE_NORMAL);
00376 
00377     void SetNormalForeground(VDKRgb color) 
00378       {
00379         SetForeground(color);
00380       }
00386     virtual void SetBackground(VDKRgb color,
00387                                GtkStateType state = GTK_STATE_NORMAL);
00393     void SetSize(int w, int h) 
00394       {
00395         if(GTK_IS_WIDGET(widget))
00396           gtk_widget_set_usize(GTK_WIDGET(widget),w,h);
00397       }
00403     void SetUsize(VDKPoint s) 
00404       {
00405         SetSize(s.X(),s.Y());
00406       }
00407     /*
00408       Sets/unsets object sensitivity
00409       \param   flag, either true or false
00410       Tip: with flag=false object does not answer to signal/events
00411     */
00412     virtual void Enable(bool flag = true);
00413     /*
00414       Returns if the object is enable or not
00415     */
00416     bool GetEnabled() 
00417       {
00418         return Enabled;
00419       }
00423     virtual void SetTip(char* );
00434     virtual void Add(VDKObject* obj, int justify = l_justify,
00435                      int expand = TRUE, int fill = TRUE ,
00436                      int padding = 0);
00440     ItemList& Items() 
00441       {
00442         return items;
00443       }
00447     ItemList& Garbages() 
00448       {
00449         return garbages;
00450       }
00454     RawList& Raws() 
00455       {
00456         return raws;
00457       }
00461     void Draw(GdkRectangle* area = NULL);
00467     virtual void Setup() {}
00472     void SignalEmit(int signal);
00477     void SignalEmit(char* sig);
00482     void SignalEmitParent(int signal) {
00483         SignalEmit(signal,Parent_level);
00484     }
00489     void SignalEmitParent(char* sig);
00493     void GrabFocus();
00497     void AddItem(VDKObject* item);
00501     void RemoveItem(VDKObject* item);
00505     void RemoveItems();
00506   /*
00507 ==================== signal/event management  ======================
00508   */
00512     VDKObject* Parent(VDKObject* p = NULL) {
00513         if(p) parent = p; return parent;
00514     }
00515     // signal and events default dispatchers for class level
00519     static void VDKSignalPipe(GtkWidget* w, void* obj);
00523     virtual int VDKObjectSignalResponse(GtkWidget* , int , void*, bool) 
00524       {
00525         return FALSE;
00526       }
00530     virtual int VDKObjectEventResponse(GtkWidget* , GdkEvent*, void*, bool) 
00531       {
00532         return FALSE;
00533       }
00534 
00535     virtual int ObjectSignalDetach(int , int ) 
00536       {
00537         return -1;
00538       }
00539     virtual bool ObjectSignalAttach(int ) 
00540       {
00541         return false;
00542       }
00543     virtual int ObjectEventDetach(VDKEvent ) 
00544       {
00545         return -1;
00546       }
00547     virtual bool ObjectEventAttach(int ) 
00548       {
00549         return false;
00550       }
00551  protected:
00552      virtual int VDKObjectSignalResponseTableSize() 
00553        {
00554          return 0;
00555        }
00556      virtual int VDKObjectEventResponseTableSize() 
00557        {
00558          return 0;
00559        }
00560   /*
00561    */
00562   // signal and events default dispatchers for parent level
00563 public:
00567     virtual int VDKSignalResponse(GtkWidget* , int , void*, void *, bool) 
00568       {
00569         return 0;
00570       }
00574     virtual int VDKEventResponse(GtkWidget* , GdkEvent* , void*, void*, bool )
00575       {
00576         return 0;
00577       }
00578     virtual int SignalDetach(VDKObject* , int ) 
00579       {
00580         return -1;
00581       }
00582     virtual bool SignalAttach(int ) 
00583       {
00584         return false;
00585       }
00586     virtual int EventDetach(VDKObject* ,VDKEvent ) 
00587       {
00588         return -1;
00589       }
00590     virtual bool EventAttach(int ) 
00591       {
00592         return false;
00593       }
00594 protected:
00598     virtual int VDKSignalResponseTableSize() 
00599       {
00600         return 0;
00601       }
00605     virtual int VDKEventResponseTableSize() 
00606       {
00607         return 0;
00608       }
00609   /*
00610 ==================== signal management ala Gtk+ ======================
00611   */
00612 public:
00627     int SignalConnect(VDKObject* obj, 
00628                       char* signal,
00629                       bool (VDKObject::*method)(VDKObject*), 
00630                       bool gtk = true,
00631                       bool after = false) 
00632       {
00633         return -1;
00634       }
00648     int SignalConnect(char* signal ,
00649                       bool (VDKObject::*method)(VDKObject*), 
00650                       bool gtk = true,
00651                       bool after = false) 
00652       {
00653         return -1;
00654       }
00655    // general signal unit response (at this level simply answer false)
00656     virtual int VDKSignalUnitResponse(GtkWidget* , char* , void*) 
00657       {
00658         return 0;
00659       }
00664     bool SignalDisconnect(int connection) 
00665       {
00666         return false;
00667       }
00668   // find signal at class level
00672     virtual bool FindSignalAtClassLevel(VDKObject* , char* ) 
00673       //    virtual bool FindSignalAtClassLevel(VDKObject* , VDKString& ) 
00674       {
00675         return false;
00676       }
00677   // find signal at parent level
00681   //   virtual bool FindSignalAtParentLevel(VDKObject* , VDKString& ) 
00682     virtual bool FindSignalAtParentLevel(VDKObject* , char* ) 
00683       {
00684         return false;
00685       }
00686 protected:
00687     // unique Gtk+ callback that redirects to
00688     // above VDKSignalUnitResponse()
00692     static void VDKSignalUnitPipe(GtkWidget* , void* );
00693   /*
00694 ==================== event management ala Gtk+ ======================
00695   */
00696 public:
00700   //  virtual bool FindEventAtClassLevel(VDKObject* , VDKString& ) 
00701   virtual bool FindEventAtClassLevel(VDKObject* , char* ) 
00702   {
00703     return false;
00704   }
00708   //  virtual bool FindEventAtParentLevel(VDKObject* , VDKString& ) 
00709   virtual bool FindEventAtParentLevel(VDKObject* , char* ) 
00710   {
00711     return false;
00712   }
00716       virtual int  VDKEventUnitResponse(GtkWidget* , char* , 
00717                                         GdkEvent* , void*) {
00718           return 0;
00719       }
00729       int EventConnect(VDKObject* obj, 
00730                        char* event, 
00731                        bool (VDKObject::*method) (VDKObject* , GdkEvent*), 
00732                        bool after = false) 
00733         {
00734           return -1;
00735       
00736         }
00745       int EventConnect(char* , bool (VDKObject::*) (VDKObject* , GdkEvent*), 
00746                        bool after = false) 
00747         {
00748           return -1;
00749         }
00754       bool EventDisconnect(int connection) 
00755         {
00756           return false;
00757         }
00758       virtual int  VDKSignalResponseListSize() {
00759           return 0;
00760       }
00761 protected:
00762     // unique Gtk+ callback that redirects to
00763     // above VDKEventUnitResponse()
00767     static int VDKEventUnitPipe(GtkWidget* , GdkEvent*, void* );
00768 
00769 #ifdef USE_SIGCPLUSPLUS
00770  public:
00772     VDKRawEventSignal     OnRawEvent;
00774     VDKButtonSignal       OnButtonEvent;
00776     VDKKeySignal          OnKeyEvent;
00778     VDKKeyFocusSignal     OnKeyFocusEvent;
00780     VDKPointerFocusSignal OnPointerFocusEvent;
00782     VDKPointerSignal      OnPointerEvent;
00784      VDKMapSignal         OnMapEvent;
00786      VDKGeometrySignal    OnGeometryEvent;
00788      VDKPaintSignal       OnPaintEvent;
00789 #endif // USE_SIGCPLUSPLUS
00790 };
00791 #endif
00792 
00793 
00794 
00795 
00796 
00797 
00798 
00799