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.0KB

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