GtkOL Reference Manual

CWidget


    The GtkOL widget encapsulates the Gtk+ widget and lets it accessible if desired. It manages all of the generic allocation and deletion process coherence according to expected specific virtual functions resolution. This process checks protected attributes to see if the definition must handle the Gtk+ container encapsulation aspect of the associated Gtk+ widget and the listening associated default functions. Those members are set to "true" by default and must be modified accordinaly by derived classes if desired when launching the process.

    The GtkOL widget handles drag and drop of widgets and owned controls and it calls the Gtk+ container aspect functions to reduce programmer code according to implicit hierarchy construction as widgets are instanciated one under each others.

    Typically, derived classes must call CWidget::CreateWidget in their constructors and CWidget::DestroyWidget in their destructors. Regarding the CComponent specifications, they have to overwrite OwnerMustBe and ChildMustBe functions too. If the derived class handles no windowed controls, it must overwrite the GetControlAtPoint and GetControlPixbuf functions in order to give the widget drag and drop engine the control it should work on and a friendly pixbuf representation of the managed control.

XML serialization

<cwidget shown="true|false" enabled="true|false">
  ...
</cwidget>

Metaclass declaration

DECLARE_GENERIC_METACLASS ('wdgt', CWidget,         CControl);
DECLARE_GENERIC_METACLASS ('_wdg', CWidgetListener, CObjectListener);

Hierarchy Definition

    [CClass]
        [CSerialized]
            [CMetaModule]
                [CObject]
                    CComponent
                        CControl
                            CWidget
    [CClass]
        [CSerialized]
            [CMetaModule]
                [CObjectListener]
                    CWidgetListener

API description

#include "ccontrol.h"

class CWidget; typedef TBuffer <CWidget *> CWidgets;

typedef enum
{
    SHIFTSTATE_LBUTTON    =(1L),       // mouse left button
    SHIFTSTATE_MBUTTON    =(1L<<1),    // mouse middle button
    SHIFTSTATE_RBUTTON    =(1L<<2),    // mouse right button

    SHIFTSTATE_DBUTTON    =(1L<<3),    // button double click
    SHIFTSTATE_TBUTTON    =(1L<<4),    // triple click

    SHIFTSTATE_SHIFT      =(1L<<5),    // shift key hold
    SHIFTSTATE_CONTROL    =(1L<<6),    // control key hold
    SHIFTSTATE_ALT        =(1L<<7),    // alt key hold
    SHIFTSTATE_LOCK       =(1L<<8)     // shift lock active
} TShiftState;

class CWidgetListener : public CObjectListener
{
    
public :

        CWidgetListener                              ();
        
virtual ~CWidgetListener                     () =0;

    
public :

        
virtual void            OnQueryDestroy       (CObject *inSender, Bool &ioDoDestroy)                             { }
        
virtual void            OnDestroy            (CObject *inSender)                                                { }

        
virtual void            OnShow               (CObject *inSender)                                                { }
        
virtual void            OnHide               (CObject *inSender)                                                { }

        
virtual void            OnSetFocus           (CObject *inSender)                                                { }
        
virtual void            OnKillFocus          (CObject *inSender)                                                { }

        
virtual void            OnQueryResize        (CObject *inSender, TSize &ioSize)                                 { }
        
virtual void            OnResize             (CObject *inSender)                                                { }

        
virtual void            OnKeyPress           (CObject *inSender, int inShiftStates, UInt16 &ioKey)              { }
        
virtual void            OnKeyRelease         (CObject *inSender, int inShiftStates, UInt16 inKey)               { }

        
virtual void            OnMouseEnter         (CObject *inSender)                                                { }
        
virtual void            OnMouseExit          (CObject *inSender)                                                { }

        
virtual void            OnMouseDown          (CObject *inSender, int inShiftStates, TPoint inRelativePoint)     { }
        
virtual void            OnMouseUp            (CObject *inSender, int inShiftStates, TPoint inRelativePoint)     { }
        
virtual void            OnMouseMove          (CObject *inSender, int inShiftStates, TPoint inRelativePoint)     { }

        
virtual void            OnDragStart          (CObject *&ioSender, TPoint &ioRelativePoint, CPixbuf *&ioPixbuf)  { }

        
virtual void            OnDragOver           (CObject *inDragged, CObject *inReceiver, CObject *inTargeted,
                                                      TPoint inRelativePoint, Bool &ioAccept)                           { }

        
virtual void            OnDragDrop           (CObject *inDragged, CObject *inReceiver, CObject *&ioTargeted,
                                                      SInt16 &ioIndex, TPoint inRelativePoint, Bool &ioDoDrop)          { }

        
virtual void            OnDragStop           (CObject *inSender)                                                { }

        
virtual void            OnPaint              (CObject *inSender, CGraphics &ioGraphics)                         { }

        
virtual void            OnEventAfter         (CObject *inSender, GdkEvent *inGdkEvent)                          { }

        SECTION_GENERIC_METACLASS;
};

class CWidget : public CControl
{
    
public :

        CWidget                    (CComponent *inOwner, 
const CWidgetListener *inListener=NULL);
        
virtual ~CWidget           ();

    
protected :

        
static Bool                CreateWidget             (CWidget *This);
        
static Bool                DestroyWidget            (CWidget *This);

    
protected :

        
virtual GtkWidget *        PerformWidgetInstanciate () =0;
        
virtual void               PerformWidgetInitialize  () =0;

    
public :

        
static CWidget *           GetGtkolWidget           (const GtkWidget *);
        
static CWidget *           GetGtkolWidget           (const GdkWindow *);

        GtkWidget *                GetGtkWidget             () 
const;

        
virtual const CMetaClassListenerMustBe           () const;

        
virtual Bool               CheckSetOwner            (const CComponent *inCandidate) const;
        
virtual Bool               SetOwner                 (CComponent *inOwner, const SInt16 inIndex=-1);

        
virtual CMetaClasses       OwnerMustBe              () const;
        
virtual CMetaClasses       ChildMustBe              () const;

        
virtual void               SetBounds                (const TBounds &inBounds);

        
virtual void               SetDraggable             (const Bool inDraggable);
        
virtual void               SetDropSite              (const Bool inDropSite);

        
virtual CPixbuf *          GetControlPixbuf         () const;

        
virtual CControl *         GetControlAtPoint        (const TPoint &inRelativePoint) const;

        
virtual void               Show                     (const Bool inAll=false);
        
virtual void               Hide                     (const Bool inAll=false);
        Bool                       IsShown                  () 
const;

        
virtual void               Enable                   ();
        
virtual void               Disable                  ();
        Bool                       IsEnabled                () 
const;

        Bool                       CanFocus                 () 
const;
        
virtual void               SetFocus                 ();
        
virtual Bool               IsFocused                () const;

        
virtual void               Invalidate               (const TBounds &inInvalidate=TBounds());
        
virtual void               Validate                 ();

        
virtual void               Serialize                (CXMLElementNode *&ioXMLElementNode, const int inMode) THROWABLE;

    
private :

        GtkWidget *                m_GtkWidget;

        
static CWidget *           m_DraggedWidget;
        
static CControl *          m_DraggedControl;
        
static TPoint              m_DraggedPoint;

    
protected :

        bool                       m_PerformContainerProcess;
        bool                       m_PerformSignalConnection;

        bool                       m_SerializeShown;
        bool                       m_SerializeEnabled;

    
protected :

        
static gboolean            OnQueryDestroy           (GtkWidget *, GdkEvent *, gpointer);
        
static void                OnDestroy                (GtkWidget *, gpointer);
        
static void                OnShow                   (GtkWidget *, gpointer);
        
static void                OnHide                   (GtkWidget *, gpointer);
        
static gboolean            OnSetFocus               (GtkWidget *, GdkEventFocus *, gpointer);
        
static gboolean            OnKillFocus              (GtkWidget *, GdkEventFocus *, gpointer);
        
static gboolean            OnKeyPress               (GtkWidget *, GdkEventKey *, gpointer);
        
static gboolean            OnKeyRelease             (GtkWidget *, GdkEventKey *, gpointer);
        
static gboolean            OnMouseDown              (GtkWidget *, GdkEventButton *, gpointer);
        
static gboolean            OnMouseUp                (GtkWidget *, GdkEventButton *, gpointer);
        
static gboolean            OnMouseMove              (GtkWidget *, GdkEventMotion *, gpointer);
        
static gboolean            OnMouseEnter             (GtkWidget *, GdkEventCrossing *, gpointer);
        
static gboolean            OnMouseExit              (GtkWidget *, GdkEventCrossing *, gpointer);
        
static void                OnDragDataGet            (GtkWidget *, GdkDragContext *, GtkSelectionData *, guint, guint,
                                                             gpointer);
        
static void                OnDragDataReceived       (GtkWidget *, GdkDragContext *, gint, gint, GtkSelectionData *,
                                                             guint, guint, gpointer);
        
static void                OnDragStart              (GtkWidget *, GdkDragContext *, gpointer);
        
static gboolean            OnDragOver               (GtkWidget *, GdkDragContext *, gint, gint, guint, gpointer);
        
static gboolean            OnDragDrop               (GtkWidget *, GdkDragContext *, gint, gint, guint, gpointer);
        
static void                OnDragStop               (GtkWidget *, GdkDragContext *, gpointer);
        
static gboolean            OnConfigure              (GtkWidget *, GdkEventConfigure *, gpointer);
        
static void                OnQueryResize            (GtkWidget *, GtkRequisition *, gpointer);
        
static void                OnResize                 (GtkWidget *, GtkAllocation *, gpointer);
        
static void                OnEventAfter             (GtkWidget *, GdkEvent *, gpointer);
        
static gboolean            OnPaint                  (GtkWidget *, GdkEventExpose *, gpointer);

        friend 
class               CContainer;

        SECTION_GENERIC_METACLASS;
};

CWidgetListener API details

virtual void            CWidgetListener::OnQueryDestroy       (CObject *inSender, Bool &ioDoDestroy);
Called when the Gtk widget of the inSender GtkOL widget is about to be destroyed.

virtual void            CWidgetListener::OnDestroy            (CObject *inSender);
Called when the Gtk widget of the inSender GtkOL widget has been destroyed.

virtual void            CWidgetListener::OnShow               (CObject *inSender);
Called when inSender is about to be shown.

virtual void            CWidgetListener::OnHide               (CObject *inSender);
Called when inSender is about to be hidden.

virtual void            CWidgetListener::OnSetFocus           (CObject *inSender);
Called when inSender receives the focus.

virtual void            CWidgetListener::OnKillFocus          (CObject *inSender);
Called when inSender looses the focus.

virtual void            CWidgetListener::OnQueryResize        (CObject *inSender, TSize &ioSize);
Called to perform inSender size calculation.

virtual void            CWidgetListener::OnResize             (CObject *inSender);
Called when inSender has been [re]sized or moved.

virtual void            CWidgetListener::OnKeyPress           (CObject *inSender, int inShiftStates, UInt16 &ioKey);
Called when a key has been pressed on inSender.

virtual void            CWidgetListener::OnKeyRelease         (CObject *inSender, int inShiftStates, UInt16 inKey);
Called when a key has been released on inSender.

virtual void            CWidgetListener::OnMouseEnter         (CObject *inSender);
Called when the mouse enters in inSender.

virtual void            CWidgetListener::OnMouseExit          (CObject *inSender);
Called when the mouse exists from inSender.

virtual void            CWidgetListener::OnMouseDown          (CObject *inSender, int inShiftStates, TPoint inRelativePoint);
Called when a mouse button is pressed on inSender.

virtual void            CWidgetListener::OnMouseUp            (CObject *inSender, int inShiftStates, TPoint inRelativePoint);
Called when a mouse button is released on inSender.

virtual void            CWidgetListener::OnMouseMove          (CObject *inSender, int inShiftStates, TPoint inRelativePoint);
Called when mouse is moved over inSender.

virtual void            CWidgetListener::OnDragStart          (CObject *&ioSender, TPoint &ioRelativePoint,
                                                               CPixbuf *&ioPixbuf);

Called when a drag is started on ioSender that could be the GtkOL widget itself or any of its draggable non windowed owned controls if any.  You may change the ioSender parameter to reflect wich control will effectively be managed by the dnd gtkol engine, the relative point to set your personnal pointer's hot spot on the pre-allocated drag representation of the control that you can change as well or delete and set to null if so.

virtual void            CWidgetListener::OnDragOver           (CObject *inDragged, CObject *inReceiver, CObject *inTargeted,
                                                               TPoint inRelativePoint, Bool &ioAccept);

Called on inDragged when inDragged is moved over inReceiver; the gtkol inTargeted control reflects wich control would own the inDragged control if a drop occured, may equal the inReceiver parameter or its parent layout if inReceiver is not a drop site itself; inRelativePoint is relative to the inReceiver widget or inReceiver parent widget if not a widget itself.

virtual void            CWidgetListener::OnDragDrop           (CObject *inDragged, CObject *inReceiver, CObject *&ioTargeted,
                                                               SInt16 &ioIndex, TPoint inRelativePoint, Bool &ioDoDrop);

Called on inDragged when inDragged is dropped on inReceiver; the gtkol ioTargeted control reflects wich control would own the inDragged control if the ioDoDrop parameter is set to true and the expected gtkol hierarchy rules are respected, may equal the inReceiver parameter or its parent layout if inReceiver is not a drop site itself; the ioIndex parameter specifies the index placement of the inDragged control in its new owner if droped on; inRelativePoint is relative to the inReceiver widget or inReceiver parent widget if not a widget itself.

virtual void            CWidgetListener::OnDragStop           (CObject *inSender);
Called when drag motion of inSender is ending.

virtual void            CWidgetListener::OnEventAfter         (CObject *inSender, GdkEvent *inGdkEvent);
Called after the specified GDK event has been handled on inSender.

virtual void            CWidgetListener::OnPaint              (CObject *inSender, CGraphics &ioGraphics);
called when inSender is about to be painted on graphics specified invalidated bounds

CWidget API details

CWidget::CWidget                 (CComponent *inOwner, const CWidgetListener *inListener=NULL);
CWidget constructor. This level does nothing but setting the following members default values :
m_GtkWidget               (NULL),
m_PerformContainerProcess (true),
m_PerformSignalConnection (true),
m_SerializeShown          (true),
m_SerializeEnabled        (true)

virtual CWidget::~CWidget        ();
CWidget destructor performs a "last chance" call on the CWidget::DestroyWidget (this) function; this function should not be handled at this point, if so, it may introduce some dangerous behaviour; derived classes call CWidget::DestroyWidget in their specific destructors to keep entire memory stacks available while deletion.

static Bool             CWidget::CreateWidget             (CWidget *This);
Internally used : the derived definitions call the CWidget::CreateWidget function (typically in their constructors) in order to correctly manage the process of associating the gtkol widget instance to the to be allocated gtk widget; it calls the virtual CWidget::PerformWidgetInstanciate and virtual CWidget::PerformWidgetInitialize of the specified instance and performs the gtk container process assignement if any (see CContainer abstraction). This function is based on the m_PerformContainerProcess and m_PerformSignalConnection values of the specific instance that sets it for its specific need before calling the process.

static Bool             CWidget::DestroyWidget            (CWidget *This);
Internally used : this function is called in order to destroy the associated gtk widget of the specified instance; CWidget::DestroyWidget performs recursive calls in order to properly delete the children gtk instances too and preserve the gui coherence.

virtual GtkWidget *     CWidget::PerformWidgetInstanciate () =0;
Internally used : this function should be defined in derived definition; it has to instanciate and return the gtk widget that is to be assoaciated to the gtkol widget instance; it is automatically called by CWidget::CreateWidget.

virtual void            CWidget::PerformWidgetInitialize  () =0;
Internally used : this function is called by CWidget::CreateWidget and must perform all of the gtkol and gtk widget initialization such as specific signals connection, widget display and so on.

static CWidget *        CWidget::GetGtkolWidget           (const GtkWidget *);
Get the gtkol instance associated to the specified gtk widget, null if any.

static CWidget *        CWidget::GetGtkolWidget           (const GdkWindow *);
Get the gtkol instance associated to the specified gdk window, null if any.

GtkWidget *             CWidget::GetGtkWidget             () const;
Get the gtk widget handled by the gtkol caller instance.

virtual const CMetaClass * CWidget::ListenerMustBe        () const;
Gtkol widget listener affectation; checks that inListener is derived from CWidgetListener

virtual Bool            CWidget::CheckSetOwner            (const CComponent *inCandidate) const;
Checks if the specified component could be assigned as an owner of the caller instance. A gtkol container may be restricted to only one child handling, so this version adds a check for the potential inCandidate container empty state acknowledgment by requesting the children number left it may handle.

virtual Bool            CWidget::SetOwner                 (CComponent *inOwner, const SInt16 inIndex=-1);
Sets the widget's owner, handles the gui container affectation process if it has to do so (see CContainer abstraction).

virtual CMetaClasses    CWidget::OwnerMustBe              () const;
Returns the default expected owner type of the caller instance by specifying __metaclasses(CWidget).

virtual CMetaClasses    CWidget::ChildMustBe              () const;
Returns the default expected children type of the caller instance by specifying __metaclasses(CWidget).

virtual void            CWidget::SetBounds                (const TBounds &inBounds);
Set the bounds of the widget, because the widget position depends on its container managed placement, only the size section of the bounds is handled at this level; specific overwritten definitions may handle the placement section anyway.

virtual void            CWidget::SetDraggable             (const Bool inDraggable);
Sets the draggable state of the widget.

virtual void            CWidget::SetDropSite              (const Bool inDropSite);
Sets the dropsiteable state of the widget.

virtual CPixbuf *       CWidget::GetControlPixbuf         () const;
Returns a default representation of the widget.

virtual CControl *      CWidget::GetControlAtPoint        (const TPoint &inRelativePoint) const;
Retreives the widget owned control at the specified relative point, defaults to the caller instance until overloaded; this function is overwritten whenever a derived widget handles specific non windowed controls. 

virtual void            CWidget::Show                     (const Bool inAll=false);
Shows the widget and its inAll descent hierarchy.

virtual void            CWidget::Hide                     (const Bool inAll=false);
Hide the widget and its inAll descent hierarchy.
Bool                    CWidget::IsShown                  ();
Retreives the widget shown state.

virtual void            CWidget::Enable                   ();
Sets the widget sensitive.

virtual void            CWidget::Disable                  ();
Sets the widget unsensitive.

Bool                    CWidget::IsEnabled                () const;
Retreives the widget sensitive state.

Bool                    CWidget::CanFocus                 () const;
Checks if the widget may receive the focus.

virtual void            CWidget::SetFocus                 ();
Sets the focus on the widget.

virtual Bool            CWidget::IsFocused                () const;
Checks the widget has the focus.

virtual void            CWidget::Invalidate               (const TBounds &inInvalidate=TBounds());
Invalidates a portion of the widget i.e. a zone that must be redrawn.

virtual void            CWidget::Validate                 ();
Immediately validates the widget invalidated zone set i.e. performs the repaint pending requests if any.

virtual void            CWidget::Serialize                (CXMLElementNode *&ioXMLElementNode, const int inMode) THROWABLE;
Performs the widget level serialization according to the m_SerializeShown and m_SerializeEnabled attributes member values.

GtkWidget *             CWidget::m_GtkWidget;
The gtkol handled gtk widget.

static CWidget *        CWidget::m_DraggedWidget;
Internally used : gtkol CWidget drag and drop instance handling.

static CControl *       CWidget::m_DraggedControl;
Internally used : gtkol drag and drop real CControl instance handling.

static TPoint           CWidget::m_DraggedPoint;
Internally used : gtkol drag and drop hot spot beginning.

bool                    CWidget::m_PerformContainerProcess;
Internally used : true if the widget should handle its owner container requests when performing the CWidget::CreateWidget and CWidget::SetOwner resolution.

bool                    CWidget::m_PerformSignalConnection;
Internally used : true if the CWidget level should connect the CWidgetListener API definition when performing the CWidget::CreateWidget resolution.

bool                    CWidget::m_SerializeShown;
Internally used : true if the CWidget serialization level should handle the shown state of the widget.

bool                    CWidget::m_SerializeEnabled;
Internally used : true if the CWidget serialization level should handle the sensivity state of the widget.

static gboolean         CWidget::OnQueryDestroy           (GtkWidget *, GdkEvent *, gpointer);
Internally used : "delete-event" connection.

static void             CWidget::OnDestroy                (GtkWidget *, gpointer);
Internally used : "destroy" event connection.

static void             CWidget::OnShow                   (GtkWidget *, gpointer);
Internally used : "show" event connection.

static void             CWidget::OnHide                   (GtkWidget *, gpointer);
Internally used : "hide" event connection.

static gboolean         CWidget::OnSetFocus               (GtkWidget *, GdkEventFocus *, gpointer);
Internally used : "focus-in-event" event connection.

static gboolean         CWidget::OnKillFocus              (GtkWidget *, GdkEventFocus *, gpointer);
Internally used : "focus-out-event" connection.

static gboolean         CWidget::OnKeyPress               (GtkWidget *, GdkEventKey *, gpointer);
Internally used : "key-press-event" connection.

static gboolean         CWidget::OnKeyRelease             (GtkWidget *, GdkEventKey *, gpointer);
Internally used : "key-release-event" connection.

static gboolean         CWidget::OnMouseDown              (GtkWidget *, GdkEventButton *, gpointer);
Internally used : "button-press-event" connection.

static gboolean         CWidget::OnMouseUp                (GtkWidget *, GdkEventButton *, gpointer);
Internally used : "button-release-event" connection.

static gboolean         CWidget::OnMouseMove              (GtkWidget *, GdkEventMotion *, gpointer);
Internally used : "motion-notify-event" connection.

static gboolean         CWidget::OnMouseEnter             (GtkWidget *, GdkEventCrossing *, gpointer);
Internally used : "enter-notify-event" connection.

static gboolean         CWidget::OnMouseExit              (GtkWidget *, GdkEventCrossing *, gpointer);
Internally used : "leave-notify-event" connection.

static void             CWidget::OnDragDataGet            (GtkWidget *, GdkDragContext *, GtkSelectionData *, guint, guint,
                                                           gpointer);

Internally used : "drag-data-get" connection.

static void             CWidget::OnDragDataReceived       (GtkWidget *, GdkDragContext *, gint, gint, GtkSelectionData *,
                                                           guint, guint, gpointer);

Internally used : "drag-data-received" connection.

static void             CWidget::OnDragStart              (GtkWidget *, GdkDragContext *, gpointer);
Internally used : "drag-begin" connection.

static gboolean         CWidget::OnDragOver               (GtkWidget *, GdkDragContext *, gint, gint, guint, gpointer);
Internally used : "drag-motion" connection.

static gboolean         CWidget::OnDragDrop               (GtkWidget *, GdkDragContext *, gint, gint, guint, gpointer);
Internally used : "drag-drop" connection.

static void             CWidget::OnDragStop               (GtkWidget *, GdkDragContext *, gpointer);
Internally used : "drag-end" connection.

static gboolean         CWidget::OnConfigure              (GtkWidget *, GdkEventConfigure *, gpointer);
Internally used : "configure-event" connection.

static void             CWidget::OnQueryResize            (GtkWidget *, GtkRequisition *, gpointer);
Internally used : "size-request" connection.

static void             CWidget::OnResize                 (GtkWidget *, GtkAllocation *, gpointer);
Internally used : "size-allocate" connection.

static void             CWidget::OnEventAfter             (GtkWidget *, GdkEvent *, gpointer);
Internally used : "event-after" connection.

static gboolean         CWidget::OnPaint                  (GtkWidget *, GdkEventExpose *, gpointer);
Internally used : "expose-event" connection.