home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classes.lha / Classes / Intuition / Gadgets.h next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  12.8 KB  |  496 lines

  1. #ifndef CPP_INTUITION_GADGETS_H
  2. #define CPP_INTUITION_GADGETS_H
  3.  
  4. // Klassen für Gadget EventCs
  5. //
  6. // Alle Gadgetklassen (GadTools, BOOPSI und auch einfache Gadgets) müssen
  7. // in g->UserData einen APTR auf eine Instanz von GadgetEventC haben. Die
  8. // GadgetEventHandlerC nehmen diesen Pointer und rufen die passenden
  9. // virtuellen Memberfunktionen auf.
  10. //
  11. // Autor: Jochen Becher
  12. //
  13. // Historie:
  14. // Version 1.0, am 9. Januar 94
  15.  
  16. #ifndef INTUITION_INTUITION_H
  17. #include <intuition/intuition.h>
  18. #endif
  19.  
  20. #ifndef LIBRARIES_COMMODITIES_H
  21. #include <libraries/commodities.h>
  22. #endif
  23.  
  24. #ifndef CPP_EXEC_LISTS_H
  25. #include <classes/exec/lists.h>
  26. #endif
  27.  
  28. #ifndef CPP_INTUITION_WINDOW_H
  29. #include <classes/intuition/window.h>
  30. #endif
  31.  
  32. #ifndef CPP_GRAPHICS_TEXT_H
  33. #include <classes/graphics/text.h>
  34. #endif
  35.  
  36. #ifndef CPP_DATASTRUCTURES_GENARRAYLIST_H
  37. #include <classes/datastructures/genarraylist.h>
  38. #endif
  39.  
  40. #ifndef INCLUDE_TOOLS_STR_H
  41. #include <tools/str.h>
  42. #endif
  43.  
  44. // Durch GadgetEventC.id werden verschiedene Ausbaustufen der GadgetEventCs
  45. // unterschieden:
  46. #define NORMAL_GADGETEVENT 0    // Halt wie es unten steht
  47. #define HELP_GADGETEVENT   2    // kennt noch help()
  48. #define BOOPSI_GADGETEVENT 3    // Kennt noch update()
  49.  
  50. class GadgetEventC;
  51.  
  52. class GadgetC : public NodeC {
  53. friend class GadgetListC;
  54. public:
  55.     ~GadgetC();
  56.     GadgetEventC *event() const { return gevent; };
  57.     struct Gadget *gadget() const { return gadget_ob; };
  58.     VOID setEvent(GadgetEventC *ev) { gevent = ev; };
  59.     virtual VOID free() { };
  60.     virtual struct Gadget *rebuild(struct Gadget *prev) { return prev; };
  61.     virtual VOID erase(WindowC *);
  62.     virtual VOID refresh(WindowC *);
  63.     virtual VOID setLeft(WORD left) = 0;
  64.     virtual VOID setTop(WORD top) = 0;
  65.     virtual VOID setWidth(WORD width) = 0;
  66.     virtual VOID setHeight(WORD height) = 0;
  67.     virtual WORD left() const { return gadget_ob ? gadget_ob->LeftEdge : 0; };
  68.     virtual WORD top() const { return gadget_ob ? gadget_ob->TopEdge : 0; };
  69.     virtual WORD width() const { return (gadget_ob != NULL) ? gadget_ob->Width : 0; };
  70.     virtual WORD height() const { return (gadget_ob != NULL) ? gadget_ob->Height : 0; };
  71.     virtual WORD leftBorder() const { return 0; };
  72.     virtual WORD topBorder() const { return 0; };
  73.     virtual WORD rightBorder() const { return 0; };
  74.     virtual WORD bottomBorder() const { return 0; };
  75.     virtual BOOL disable(BOOL value) { return FALSE; };
  76.     virtual BOOL isDisabled() const { return FALSE; };
  77.     virtual BOOL activate(BOOL value) { return FALSE; };
  78.     virtual ULONG idcmp() const { return 0; };
  79.     virtual VOID setTextAttr(const TextAttrC *) { };
  80.     virtual VOID setDefTextAttr(const TextAttrC *) { };
  81.     virtual TextAttrC *textAttr() const { return NULL; };
  82.     virtual BOOL deepfollow() const { return TRUE; };
  83. protected:
  84.     GadgetC(GadgetEventC *event = NULL);
  85.     struct Gadget *gadget_ob;
  86. private:
  87.     GadgetEventC *gevent;
  88. };
  89.  
  90. // *************************************************************
  91.  
  92. class GModelSnapshotC {
  93. public:
  94.     VOID setDisabled(BOOL d) { disabled = d; };
  95.     BOOL isDisabled() const { return disabled; };
  96. private:
  97.     BOOL disabled;
  98. };
  99.  
  100. class GModelC {
  101. public:
  102.     virtual BOOL disable(BOOL value) = 0;
  103.     virtual BOOL isDisabled() const = 0;
  104.     virtual BOOL activate(BOOL value) = 0;
  105.     BOOL snapshot(GModelSnapshotC &);
  106.     BOOL stamp(GModelSnapshotC &);
  107. };
  108.  
  109. class GButtonC : public GModelC {
  110. public:
  111.     BOOL activate(BOOL value) { return FALSE; };
  112. };
  113.  
  114. class GStringSnapshotC : public GModelSnapshotC {
  115. public:
  116.     VOID setString(STRPTR s) { str = s; };
  117.     STRPTR string() const { return (STRPTR) str; };
  118. private:
  119.     String str;
  120. };
  121.  
  122. class GStringC : public GModelC {
  123. public:
  124.     virtual VOID set(STRPTR) = 0;
  125.     virtual STRPTR get() = 0;
  126.     BOOL snapshot(GStringSnapshotC &);
  127.     BOOL stamp(GStringSnapshotC &);
  128. };
  129.  
  130. class GIntegerSnapshotC : public GModelSnapshotC {
  131. public:
  132.     VOID setInteger(LONG i) { number = i; };
  133.     LONG integer() const { return number; };
  134. private:
  135.     LONG number;
  136. };
  137.  
  138. class GIntegerC : public GModelC {
  139. public:
  140.     virtual VOID set(LONG) = 0;
  141.     virtual LONG get() = 0;
  142.     BOOL snapshot(GIntegerSnapshotC &);
  143.     BOOL stamp(GIntegerSnapshotC &);
  144. };
  145.  
  146. class GCheckboxSnapshotC : public GModelSnapshotC {
  147. public:
  148.     VOID setCheck(BOOL b) { check = b; };
  149.     BOOL checked() const { return check; };
  150. private:
  151.     BOOL check;
  152. };
  153.  
  154. class GCheckboxC : public GModelC {
  155. public:
  156.     BOOL activate(BOOL value) { return FALSE; };
  157.     virtual VOID check(BOOL) = 0;
  158.     virtual BOOL checked() = 0;
  159.     BOOL snapshot(GCheckboxSnapshotC &);
  160.     BOOL stamp(GCheckboxSnapshotC &);
  161. };
  162.  
  163. class GRadioSnapshotC : public GModelSnapshotC {
  164. public:
  165.     VOID setSelection(ULONG i) { selection = i; };
  166.     ULONG selected() const { return selection; };
  167. private:
  168.     ULONG selection;
  169. };
  170.  
  171. class GRadioC : public GModelC {
  172. public:
  173.     BOOL activate(BOOL value) { return FALSE; };
  174.     virtual VOID select(ULONG) = 0;
  175.     virtual ULONG selected() = 0;
  176.     BOOL snapshot(GRadioSnapshotC &);
  177.     BOOL stamp(GRadioSnapshotC &);
  178. };
  179.  
  180. class GCycleSnapshotC : public GModelSnapshotC {
  181. public:
  182.     VOID setSelection(ULONG i) { selection = i; };
  183.     ULONG selected() const { return selection; };
  184. private:
  185.     ULONG selection;
  186. };
  187.  
  188. class GCycleC : public GModelC {
  189. public:
  190.     BOOL activate(BOOL value) { return FALSE; };
  191.     virtual VOID select(ULONG) = 0;
  192.     virtual ULONG selected() = 0;
  193.     virtual VOID setLabels(STRPTR *labels) = 0;
  194.     virtual VOID setLabels(STRPTR label1, ...) = 0;
  195.     virtual STRPTR *getLabels() = 0;
  196.     virtual ULONG labelsCount() = 0;
  197.     virtual UWORD addLabel(STRPTR label) = 0;
  198.     virtual VOID remLabel(UWORD count) = 0;
  199.     BOOL snapshot(GCycleSnapshotC &);
  200.     BOOL stamp(GCycleSnapshotC &);
  201. };
  202.  
  203. class GSliderSnapshotC : public GModelSnapshotC {
  204. public:
  205.     VOID setMin(UWORD m) { minimum = m; };
  206.     VOID setMax(UWORD m) { maximum = m; };
  207.     VOID setLevel(UWORD l) { lev = l; };
  208.     UWORD min() const { return minimum; };
  209.     UWORD max() const { return maximum; };
  210.     UWORD level() const { return lev; };
  211. private:
  212.     UWORD minimum;
  213.     UWORD maximum;
  214.     UWORD lev;
  215. };
  216.  
  217. class GSliderC : public GModelC {
  218. public:
  219.     BOOL activate(BOOL value) { return FALSE; };
  220.     virtual VOID setMin(UWORD) = 0;
  221.     virtual VOID setMax(UWORD) = 0;
  222.     virtual VOID setLevel(UWORD) = 0;
  223.     virtual UWORD min() = 0;
  224.     virtual UWORD max() = 0;
  225.     virtual UWORD level() = 0;
  226.     BOOL snapshot(GSliderSnapshotC &);
  227.     BOOL stamp(GSliderSnapshotC &);
  228. };
  229.  
  230. class GScrollerSnapshotC : public GModelSnapshotC {
  231. public:
  232.     VOID setPot(UWORD p) { potent = p; };
  233.     VOID setTotal(UWORD t) { tot = t; };
  234.     VOID setVisible(UWORD v) { vis = v; };
  235.     UWORD pot() const { return potent; };
  236.     UWORD total() const { return tot; };
  237.     UWORD visible() const { return vis; };
  238. private:
  239.     UWORD potent;
  240.     UWORD tot;
  241.     UWORD vis;
  242. };
  243.  
  244. class GScrollerC : public GModelC {
  245. public:
  246.     BOOL activate(BOOL value) { return FALSE; };
  247.     virtual VOID setPot(UWORD) = 0;
  248.     virtual VOID setTotal(UWORD) = 0;
  249.     virtual VOID setVisible(UWORD) = 0;
  250.     virtual UWORD pot() = 0;
  251.     virtual UWORD total() = 0;
  252.     virtual UWORD visible() = 0;
  253.     BOOL snapshot(GScrollerSnapshotC &);
  254.     BOOL stamp(GScrollerSnapshotC &);
  255. };
  256.  
  257. class GListviewSnapshotC : public GModelSnapshotC {
  258. public:
  259.     VOID setSelection(ULONG i) { selection = i; };
  260.     ULONG selected() const { return selection; };
  261. private:
  262.     ULONG selection;
  263. };
  264.  
  265. class GListviewC : public GModelC {
  266. public:
  267.     BOOL activate(BOOL value) { return FALSE; };
  268.     virtual VOID select(ULONG) = 0;
  269.     virtual ULONG selected() = 0;
  270.     virtual VOID clearSelection() = 0;
  271.     virtual VOID setList(EListC *header) = 0;
  272.     virtual EListC *getList() = 0;
  273.     virtual VOID detachList() = 0;
  274.     virtual VOID attachList() = 0;
  275.     BOOL snapshot(GListviewSnapshotC &);
  276.     BOOL stamp(GListviewSnapshotC &);
  277. };
  278.  
  279. class GPaletteSnapshotC : public GModelSnapshotC {
  280. public:
  281.     VOID setSelection(ULONG i) { selection = i; };
  282.     ULONG selected() const { return selection; };
  283. private:
  284.     ULONG selection;
  285. };
  286.  
  287. class GPaletteC : public GModelC {
  288. public:
  289.     BOOL activate(BOOL value) { return FALSE; };
  290.     virtual VOID select(ULONG) = 0;
  291.     virtual ULONG selected() = 0;
  292.     BOOL snapshot(GPaletteSnapshotC &);
  293.     BOOL stamp(GPaletteSnapshotC &);
  294. };
  295.  
  296. class GTextSnapshotC : public GModelSnapshotC {
  297. public:
  298.     VOID setString(STRPTR s) { str = s; };
  299.     STRPTR string() const { return (STRPTR) str; };
  300. private:
  301.     String str;
  302. };
  303.  
  304. class GTextC : public GModelC {
  305. public:
  306.     BOOL activate(BOOL value) { return FALSE; };
  307.     virtual VOID set(STRPTR) = 0;
  308.     virtual STRPTR get() = 0;
  309.     BOOL snapshot(GTextSnapshotC &);
  310.     BOOL stamp(GTextSnapshotC &);
  311. };
  312.  
  313. class GNumberSnapshotC : public GModelSnapshotC {
  314. public:
  315.     VOID setInteger(LONG i) { number = i; };
  316.     LONG integer() const { return number; };
  317. private:
  318.     LONG number;
  319. };
  320.  
  321. class GNumberC : public GModelC {
  322. public:
  323.     BOOL activate(BOOL value) { return FALSE; };
  324.     virtual VOID set(LONG) = 0;
  325.     virtual LONG get() = 0;
  326.     BOOL snapshot(GNumberSnapshotC &);
  327.     BOOL stamp(GNumberSnapshotC &);
  328. };
  329.  
  330. // *************************************************************
  331.  
  332. class GadgetListC : public GadgetC, protected ListC {
  333. public:
  334.     GadgetListC();
  335.     ~GadgetListC();
  336.     VOID add(GadgetC &);
  337.     struct Gadget *rebuild(struct Gadget *prev);
  338.     VOID erase(WindowC *);
  339.     VOID refresh(WindowC *);
  340.     VOID setLeft(WORD left) { };
  341.     VOID setTop(WORD top) { };
  342.     VOID setWidth(WORD width) { };
  343.     VOID setHeight(WORD height) { };
  344.     WORD left() const { return 0; };
  345.     WORD top() const { return 0; };
  346.     WORD width() const { return 0; };
  347.     WORD height() const { return 0; };
  348.     BOOL disable(BOOL value);
  349.     BOOL isDisabled() const { return disabled; };
  350.     ULONG idcmp() const { return idcmpFlags; };
  351.     VOID setTextAttr(const TextAttrC *);
  352.     VOID setDefTextAttr(const TextAttrC *);
  353. private:
  354.     BOOL disabled;
  355.     ULONG idcmpFlags;
  356. };
  357.  
  358. class AnchorGadgetListC : public GadgetListC {
  359. public:
  360.     AnchorGadgetListC();
  361.     ~AnchorGadgetListC();
  362.     BOOL deepfollow() const { return FALSE; };
  363. };
  364.  
  365. class RootGadgetListC {
  366. public:
  367.     RootGadgetListC(WindowC &);
  368.     ~RootGadgetListC();
  369.     VOID add(GadgetC &);
  370.     VOID rebuild(BOOL refresh = TRUE);
  371.     VOID erase();
  372.     VOID refresh();
  373.     VOID setTextAttr(const TextAttrC *);
  374.     VOID setDefTextAttr(const TextAttrC *);
  375. protected:
  376.     GadgetListC glist;
  377.     WindowC *window;
  378. };
  379.  
  380. class GadgetEventC {
  381. friend class GadgetUpHandlerC;
  382. friend class GadgetDownHandlerC;
  383. friend class GadgetMoveHandlerC;
  384. friend class GadgetKeyHandlerC;
  385. public:
  386.     GadgetEventC() { id = NORMAL_GADGETEVENT };
  387.     virtual VOID down(WindowC *, GadgetC *, IntuiMessageC *) { };
  388.     virtual VOID up(WindowC *, GadgetC *, IntuiMessageC *) { };
  389.     virtual VOID move(WindowC *, GadgetC *, IntuiMessageC *) { };
  390.     virtual VOID keyDown(WindowC *w, GadgetC *g, IntuiMessageC *m)
  391.         { down(w,g,m); };
  392.     virtual VOID keyUp(WindowC *w, GadgetC *g, IntuiMessageC *m)
  393.         { up(w,g,m); };
  394.     virtual BOOL exit() { return FALSE; };
  395. private:
  396.     UBYTE id;
  397. };
  398.  
  399. class GadgetEventHandlerC : public IDCMPEventHandlerC {
  400. public:
  401.     GadgetEventHandlerC(ULONG idcmpClass)
  402.         : IDCMPEventHandlerC(idcmpClass) { };
  403. };
  404.  
  405. class GadgetUpHandlerC : public GadgetEventHandlerC {
  406. public:
  407.     GadgetUpHandlerC()
  408.         : GadgetEventHandlerC(IDCMP_GADGETUP), _exit(FALSE) { };
  409.     BOOL exit();
  410. protected:
  411.     BOOL _handle(IntuiMessageC &);
  412. private:
  413.     BOOL _exit;
  414. };
  415.  
  416. class GadgetDownHandlerC : public GadgetEventHandlerC {
  417. public:
  418.     GadgetDownHandlerC()
  419.         : GadgetEventHandlerC(IDCMP_GADGETDOWN), _exit(FALSE) { };
  420.     BOOL exit();
  421. protected:
  422.     BOOL _handle(IntuiMessageC &);
  423. private:
  424.     BOOL _exit;
  425. };
  426.  
  427. // Achtung, der GadgetMoveHandlerC ist mit etwas Vorsicht zu genießen:
  428. // Da IDCMP_MOUSEMOVE Events keine Information über das Gadget enthalten,
  429. // trägt der GadgetMoveHandlerC noch zwei andere HandlerC ein:
  430. // Einen GadgetDownHandlerC, der ihm ein neues aktuelles Gadget mitteilt,
  431. // und einen GadgetUpHandlerC, der sicherheitshalber das aktuelle Gadget
  432. // wieder zurücksetzt (auf NULL). Dieser wird aber nicht immer aufgerufen
  433. // (z.B. beim "wegklicken" aus einen string gadget).
  434. // Zur korrekten Funktion des GadgetMoveHandlerC MUSS also das Gadget einen
  435. // GadgetDown Event empfangen können und am besten auch einen GadgetUp Event.
  436. // Achja, das Feld IAddress der IntuiMessageC wird trotzdem nicht verändert,
  437. // wie das GadTools macht...
  438.  
  439. class GadgetMoveHandlerC;
  440.  
  441. class GadgetMoveDownHandlerC : public GadgetDownHandlerC {
  442. friend class GadgetMoveHandlerC;
  443. private:
  444.     GadgetMoveDownHandlerC(GadgetMoveHandlerC &h)
  445.         : GadgetDownHandlerC() { handler = &h; };
  446. protected:
  447.     BOOL _handle(IntuiMessageC &);
  448. private:
  449.     GadgetMoveHandlerC *handler;
  450. };
  451.  
  452. class GadgetMoveUpHandlerC : public GadgetUpHandlerC {
  453. friend class GadgetMoveHandlerC;
  454. private:
  455.     GadgetMoveUpHandlerC(GadgetMoveHandlerC &h)
  456.         : GadgetUpHandlerC() { handler = &h; };
  457. protected:
  458.     BOOL _handle(IntuiMessageC &);
  459. private:
  460.     class GadgetMoveHandlerC *handler;
  461. };
  462.  
  463. class GadgetMoveHandlerC : public GadgetEventHandlerC {
  464. friend class GadgetMoveDownHandlerC;
  465. friend class GadgetMoveUpHandlerC;
  466. public:
  467.     GadgetMoveHandlerC();
  468.     BOOL exit();
  469. protected:
  470.     BOOL _handle(IntuiMessageC &);
  471. private:
  472.     struct Gadget *gadget;
  473.     GadgetMoveDownHandlerC down_handler;
  474.     GadgetMoveUpHandlerC up_handler;
  475.     BOOL _exit;
  476. };
  477.  
  478. struct GadgetKey {
  479.     GadgetC *gadget;
  480.     IX ix;
  481. };
  482.  
  483. class GadgetKeyHandlerC : public WindowEventHandlerC {
  484. public:
  485.     GadgetKeyHandlerC(WindowC &) throw (MemoryX);
  486.     BOOL add(STRPTR, GadgetC &) throw (MemoryX);
  487.     BOOL exit();
  488. protected:
  489.     BOOL _handle(IntuiMessageC &);
  490. private:
  491.     gen_arraylist keys;
  492.     BOOL _exit;
  493. };
  494.  
  495. #endif
  496.