1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //| Copyright: (C) 2019-2020 Kevin Larke <contact AT larke DOT org>
- //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
- #ifndef Fl_CbLinker_h
- #define Fl_CbLinker_h
-
- class Fl_Widget;
- class Fl_Button;
- class Fl_Scrollbar;
- class Fl_Menu_Button;
- struct Fl_Menu_Item;
-
- /*
- This class solves the problem of linking static control callback functions
- to an object instance.
-
- registerCtl() creates a record which links a control to an instance
- of a Fl_CbLinker. The control is then given a static callback function:
- _s_callback(). When _s_callback() is called from the control event
- handler it links locates the controls link record an calls the
- appropriate handler (e.g. onButton(), onScrollBar(), etc.)
- */
-
- class Fl_CbLinker
- {
- public:
- Fl_CbLinker();
- virtual ~Fl_CbLinker();
-
- void registerCtl( Fl_Button* c, unsigned id );
- void registerCtl( Fl_Scrollbar* c, unsigned id );
- void registerCtl( Fl_Menu_Button* c, unsigned id );
- void registerCtl( Fl_Menu_Item* c, unsigned id );
-
- virtual void onButton( Fl_Button* c, unsigned id );
- virtual void onScrollbar( Fl_Scrollbar* c, unsigned id );
- virtual void onMenuBtn( Fl_Menu_Button* c, unsigned id );
- virtual void onMenuItem( Fl_Menu_Item* c, unsigned id );
-
- private:
- enum
- {
- kButtonTId,
- kScrollbarTId,
- kMenuBtnTId,
- kMenuItemTId
- };
-
- typedef struct ctl_str
- {
- Fl_CbLinker* thisPtr;
- unsigned typeId;
- unsigned ctlId;
- union
- {
- Fl_Button* btn;
- Fl_Scrollbar* sb;
- Fl_Menu_Button* mbtn;
- Fl_Menu_Item* mitem;
- Fl_Widget* w;
- } u;
-
- ctl_str( Fl_CbLinker* t, Fl_Button* c, unsigned id) : thisPtr(t), typeId(kButtonTId), ctlId(id) { u.btn=c; }
- ctl_str( Fl_CbLinker* t, Fl_Scrollbar* c, unsigned id ) : thisPtr(t), typeId(kScrollbarTId),ctlId(id) { u.sb=c; }
- ctl_str( Fl_CbLinker* t, Fl_Menu_Button* c, unsigned id ) : thisPtr(t), typeId(kMenuBtnTId), ctlId(id) { u.mbtn=c; }
- ctl_str( Fl_CbLinker* t, Fl_Menu_Item* c, unsigned id ) : thisPtr(t), typeId(kMenuItemTId), ctlId(id) { u.mitem=c; }
-
- } ctl_t;
-
- std::vector< ctl_t* > _ctlV;
-
- static void _s_callback( Fl_Widget* w, void* arg );
- };
-
- #endif
|