Programmable real-time audio signal processing application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Fl_CbLinker.h 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //| Copyright: (C) 2019-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #ifndef Fl_CbLinker_h
  4. #define Fl_CbLinker_h
  5. class Fl_Widget;
  6. class Fl_Button;
  7. class Fl_Scrollbar;
  8. class Fl_Menu_Button;
  9. struct Fl_Menu_Item;
  10. /*
  11. This class solves the problem of linking static control callback functions
  12. to an object instance.
  13. registerCtl() creates a record which links a control to an instance
  14. of a Fl_CbLinker. The control is then given a static callback function:
  15. _s_callback(). When _s_callback() is called from the control event
  16. handler it links locates the controls link record an calls the
  17. appropriate handler (e.g. onButton(), onScrollBar(), etc.)
  18. */
  19. class Fl_CbLinker
  20. {
  21. public:
  22. Fl_CbLinker();
  23. virtual ~Fl_CbLinker();
  24. void registerCtl( Fl_Button* c, unsigned id );
  25. void registerCtl( Fl_Scrollbar* c, unsigned id );
  26. void registerCtl( Fl_Menu_Button* c, unsigned id );
  27. void registerCtl( Fl_Menu_Item* c, unsigned id );
  28. virtual void onButton( Fl_Button* c, unsigned id );
  29. virtual void onScrollbar( Fl_Scrollbar* c, unsigned id );
  30. virtual void onMenuBtn( Fl_Menu_Button* c, unsigned id );
  31. virtual void onMenuItem( Fl_Menu_Item* c, unsigned id );
  32. private:
  33. enum
  34. {
  35. kButtonTId,
  36. kScrollbarTId,
  37. kMenuBtnTId,
  38. kMenuItemTId
  39. };
  40. typedef struct ctl_str
  41. {
  42. Fl_CbLinker* thisPtr;
  43. unsigned typeId;
  44. unsigned ctlId;
  45. union
  46. {
  47. Fl_Button* btn;
  48. Fl_Scrollbar* sb;
  49. Fl_Menu_Button* mbtn;
  50. Fl_Menu_Item* mitem;
  51. Fl_Widget* w;
  52. } u;
  53. ctl_str( Fl_CbLinker* t, Fl_Button* c, unsigned id) : thisPtr(t), typeId(kButtonTId), ctlId(id) { u.btn=c; }
  54. ctl_str( Fl_CbLinker* t, Fl_Scrollbar* c, unsigned id ) : thisPtr(t), typeId(kScrollbarTId),ctlId(id) { u.sb=c; }
  55. ctl_str( Fl_CbLinker* t, Fl_Menu_Button* c, unsigned id ) : thisPtr(t), typeId(kMenuBtnTId), ctlId(id) { u.mbtn=c; }
  56. ctl_str( Fl_CbLinker* t, Fl_Menu_Item* c, unsigned id ) : thisPtr(t), typeId(kMenuItemTId), ctlId(id) { u.mitem=c; }
  57. } ctl_t;
  58. std::vector< ctl_t* > _ctlV;
  59. static void _s_callback( Fl_Widget* w, void* arg );
  60. };
  61. #endif