home *** CD-ROM | disk | FTP | other *** search
- #ifndef CPP_INTUITION_GADGETS_H
- #define CPP_INTUITION_GADGETS_H
-
- // Klassen für Gadget EventCs
- //
- // Alle Gadgetklassen (GadTools, BOOPSI und auch einfache Gadgets) müssen
- // in g->UserData einen APTR auf eine Instanz von GadgetEventC haben. Die
- // GadgetEventHandlerC nehmen diesen Pointer und rufen die passenden
- // virtuellen Memberfunktionen auf.
- //
- // Autor: Jochen Becher
- //
- // Historie:
- // Version 1.0, am 9. Januar 94
-
- #ifndef INTUITION_INTUITION_H
- #include <intuition/intuition.h>
- #endif
-
- #ifndef LIBRARIES_COMMODITIES_H
- #include <libraries/commodities.h>
- #endif
-
- #ifndef CPP_EXEC_LISTS_H
- #include <classes/exec/lists.h>
- #endif
-
- #ifndef CPP_INTUITION_WINDOW_H
- #include <classes/intuition/window.h>
- #endif
-
- #ifndef CPP_GRAPHICS_TEXT_H
- #include <classes/graphics/text.h>
- #endif
-
- #ifndef CPP_DATASTRUCTURES_GENARRAYLIST_H
- #include <classes/datastructures/genarraylist.h>
- #endif
-
- #ifndef INCLUDE_TOOLS_STR_H
- #include <tools/str.h>
- #endif
-
- // Durch GadgetEventC.id werden verschiedene Ausbaustufen der GadgetEventCs
- // unterschieden:
- #define NORMAL_GADGETEVENT 0 // Halt wie es unten steht
- #define HELP_GADGETEVENT 2 // kennt noch help()
- #define BOOPSI_GADGETEVENT 3 // Kennt noch update()
-
- class GadgetEventC;
-
- class GadgetC : public NodeC {
- friend class GadgetListC;
- public:
- ~GadgetC();
- GadgetEventC *event() const { return gevent; };
- struct Gadget *gadget() const { return gadget_ob; };
- VOID setEvent(GadgetEventC *ev) { gevent = ev; };
- virtual VOID free() { };
- virtual struct Gadget *rebuild(struct Gadget *prev) { return prev; };
- virtual VOID erase(WindowC *);
- virtual VOID refresh(WindowC *);
- virtual VOID setLeft(WORD left) = 0;
- virtual VOID setTop(WORD top) = 0;
- virtual VOID setWidth(WORD width) = 0;
- virtual VOID setHeight(WORD height) = 0;
- virtual WORD left() const { return gadget_ob ? gadget_ob->LeftEdge : 0; };
- virtual WORD top() const { return gadget_ob ? gadget_ob->TopEdge : 0; };
- virtual WORD width() const { return (gadget_ob != NULL) ? gadget_ob->Width : 0; };
- virtual WORD height() const { return (gadget_ob != NULL) ? gadget_ob->Height : 0; };
- virtual WORD leftBorder() const { return 0; };
- virtual WORD topBorder() const { return 0; };
- virtual WORD rightBorder() const { return 0; };
- virtual WORD bottomBorder() const { return 0; };
- virtual BOOL disable(BOOL value) { return FALSE; };
- virtual BOOL isDisabled() const { return FALSE; };
- virtual BOOL activate(BOOL value) { return FALSE; };
- virtual ULONG idcmp() const { return 0; };
- virtual VOID setTextAttr(const TextAttrC *) { };
- virtual VOID setDefTextAttr(const TextAttrC *) { };
- virtual TextAttrC *textAttr() const { return NULL; };
- virtual BOOL deepfollow() const { return TRUE; };
- protected:
- GadgetC(GadgetEventC *event = NULL);
- struct Gadget *gadget_ob;
- private:
- GadgetEventC *gevent;
- };
-
- // *************************************************************
-
- class GModelSnapshotC {
- public:
- VOID setDisabled(BOOL d) { disabled = d; };
- BOOL isDisabled() const { return disabled; };
- private:
- BOOL disabled;
- };
-
- class GModelC {
- public:
- virtual BOOL disable(BOOL value) = 0;
- virtual BOOL isDisabled() const = 0;
- virtual BOOL activate(BOOL value) = 0;
- BOOL snapshot(GModelSnapshotC &);
- BOOL stamp(GModelSnapshotC &);
- };
-
- class GButtonC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- };
-
- class GStringSnapshotC : public GModelSnapshotC {
- public:
- VOID setString(STRPTR s) { str = s; };
- STRPTR string() const { return (STRPTR) str; };
- private:
- String str;
- };
-
- class GStringC : public GModelC {
- public:
- virtual VOID set(STRPTR) = 0;
- virtual STRPTR get() = 0;
- BOOL snapshot(GStringSnapshotC &);
- BOOL stamp(GStringSnapshotC &);
- };
-
- class GIntegerSnapshotC : public GModelSnapshotC {
- public:
- VOID setInteger(LONG i) { number = i; };
- LONG integer() const { return number; };
- private:
- LONG number;
- };
-
- class GIntegerC : public GModelC {
- public:
- virtual VOID set(LONG) = 0;
- virtual LONG get() = 0;
- BOOL snapshot(GIntegerSnapshotC &);
- BOOL stamp(GIntegerSnapshotC &);
- };
-
- class GCheckboxSnapshotC : public GModelSnapshotC {
- public:
- VOID setCheck(BOOL b) { check = b; };
- BOOL checked() const { return check; };
- private:
- BOOL check;
- };
-
- class GCheckboxC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID check(BOOL) = 0;
- virtual BOOL checked() = 0;
- BOOL snapshot(GCheckboxSnapshotC &);
- BOOL stamp(GCheckboxSnapshotC &);
- };
-
- class GRadioSnapshotC : public GModelSnapshotC {
- public:
- VOID setSelection(ULONG i) { selection = i; };
- ULONG selected() const { return selection; };
- private:
- ULONG selection;
- };
-
- class GRadioC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID select(ULONG) = 0;
- virtual ULONG selected() = 0;
- BOOL snapshot(GRadioSnapshotC &);
- BOOL stamp(GRadioSnapshotC &);
- };
-
- class GCycleSnapshotC : public GModelSnapshotC {
- public:
- VOID setSelection(ULONG i) { selection = i; };
- ULONG selected() const { return selection; };
- private:
- ULONG selection;
- };
-
- class GCycleC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID select(ULONG) = 0;
- virtual ULONG selected() = 0;
- virtual VOID setLabels(STRPTR *labels) = 0;
- virtual VOID setLabels(STRPTR label1, ...) = 0;
- virtual STRPTR *getLabels() = 0;
- virtual ULONG labelsCount() = 0;
- virtual UWORD addLabel(STRPTR label) = 0;
- virtual VOID remLabel(UWORD count) = 0;
- BOOL snapshot(GCycleSnapshotC &);
- BOOL stamp(GCycleSnapshotC &);
- };
-
- class GSliderSnapshotC : public GModelSnapshotC {
- public:
- VOID setMin(UWORD m) { minimum = m; };
- VOID setMax(UWORD m) { maximum = m; };
- VOID setLevel(UWORD l) { lev = l; };
- UWORD min() const { return minimum; };
- UWORD max() const { return maximum; };
- UWORD level() const { return lev; };
- private:
- UWORD minimum;
- UWORD maximum;
- UWORD lev;
- };
-
- class GSliderC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID setMin(UWORD) = 0;
- virtual VOID setMax(UWORD) = 0;
- virtual VOID setLevel(UWORD) = 0;
- virtual UWORD min() = 0;
- virtual UWORD max() = 0;
- virtual UWORD level() = 0;
- BOOL snapshot(GSliderSnapshotC &);
- BOOL stamp(GSliderSnapshotC &);
- };
-
- class GScrollerSnapshotC : public GModelSnapshotC {
- public:
- VOID setPot(UWORD p) { potent = p; };
- VOID setTotal(UWORD t) { tot = t; };
- VOID setVisible(UWORD v) { vis = v; };
- UWORD pot() const { return potent; };
- UWORD total() const { return tot; };
- UWORD visible() const { return vis; };
- private:
- UWORD potent;
- UWORD tot;
- UWORD vis;
- };
-
- class GScrollerC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID setPot(UWORD) = 0;
- virtual VOID setTotal(UWORD) = 0;
- virtual VOID setVisible(UWORD) = 0;
- virtual UWORD pot() = 0;
- virtual UWORD total() = 0;
- virtual UWORD visible() = 0;
- BOOL snapshot(GScrollerSnapshotC &);
- BOOL stamp(GScrollerSnapshotC &);
- };
-
- class GListviewSnapshotC : public GModelSnapshotC {
- public:
- VOID setSelection(ULONG i) { selection = i; };
- ULONG selected() const { return selection; };
- private:
- ULONG selection;
- };
-
- class GListviewC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID select(ULONG) = 0;
- virtual ULONG selected() = 0;
- virtual VOID clearSelection() = 0;
- virtual VOID setList(EListC *header) = 0;
- virtual EListC *getList() = 0;
- virtual VOID detachList() = 0;
- virtual VOID attachList() = 0;
- BOOL snapshot(GListviewSnapshotC &);
- BOOL stamp(GListviewSnapshotC &);
- };
-
- class GPaletteSnapshotC : public GModelSnapshotC {
- public:
- VOID setSelection(ULONG i) { selection = i; };
- ULONG selected() const { return selection; };
- private:
- ULONG selection;
- };
-
- class GPaletteC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID select(ULONG) = 0;
- virtual ULONG selected() = 0;
- BOOL snapshot(GPaletteSnapshotC &);
- BOOL stamp(GPaletteSnapshotC &);
- };
-
- class GTextSnapshotC : public GModelSnapshotC {
- public:
- VOID setString(STRPTR s) { str = s; };
- STRPTR string() const { return (STRPTR) str; };
- private:
- String str;
- };
-
- class GTextC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID set(STRPTR) = 0;
- virtual STRPTR get() = 0;
- BOOL snapshot(GTextSnapshotC &);
- BOOL stamp(GTextSnapshotC &);
- };
-
- class GNumberSnapshotC : public GModelSnapshotC {
- public:
- VOID setInteger(LONG i) { number = i; };
- LONG integer() const { return number; };
- private:
- LONG number;
- };
-
- class GNumberC : public GModelC {
- public:
- BOOL activate(BOOL value) { return FALSE; };
- virtual VOID set(LONG) = 0;
- virtual LONG get() = 0;
- BOOL snapshot(GNumberSnapshotC &);
- BOOL stamp(GNumberSnapshotC &);
- };
-
- // *************************************************************
-
- class GadgetListC : public GadgetC, protected ListC {
- public:
- GadgetListC();
- ~GadgetListC();
- VOID add(GadgetC &);
- struct Gadget *rebuild(struct Gadget *prev);
- VOID erase(WindowC *);
- VOID refresh(WindowC *);
- VOID setLeft(WORD left) { };
- VOID setTop(WORD top) { };
- VOID setWidth(WORD width) { };
- VOID setHeight(WORD height) { };
- WORD left() const { return 0; };
- WORD top() const { return 0; };
- WORD width() const { return 0; };
- WORD height() const { return 0; };
- BOOL disable(BOOL value);
- BOOL isDisabled() const { return disabled; };
- ULONG idcmp() const { return idcmpFlags; };
- VOID setTextAttr(const TextAttrC *);
- VOID setDefTextAttr(const TextAttrC *);
- private:
- BOOL disabled;
- ULONG idcmpFlags;
- };
-
- class AnchorGadgetListC : public GadgetListC {
- public:
- AnchorGadgetListC();
- ~AnchorGadgetListC();
- BOOL deepfollow() const { return FALSE; };
- };
-
- class RootGadgetListC {
- public:
- RootGadgetListC(WindowC &);
- ~RootGadgetListC();
- VOID add(GadgetC &);
- VOID rebuild(BOOL refresh = TRUE);
- VOID erase();
- VOID refresh();
- VOID setTextAttr(const TextAttrC *);
- VOID setDefTextAttr(const TextAttrC *);
- protected:
- GadgetListC glist;
- WindowC *window;
- };
-
- class GadgetEventC {
- friend class GadgetUpHandlerC;
- friend class GadgetDownHandlerC;
- friend class GadgetMoveHandlerC;
- friend class GadgetKeyHandlerC;
- public:
- GadgetEventC() { id = NORMAL_GADGETEVENT };
- virtual VOID down(WindowC *, GadgetC *, IntuiMessageC *) { };
- virtual VOID up(WindowC *, GadgetC *, IntuiMessageC *) { };
- virtual VOID move(WindowC *, GadgetC *, IntuiMessageC *) { };
- virtual VOID keyDown(WindowC *w, GadgetC *g, IntuiMessageC *m)
- { down(w,g,m); };
- virtual VOID keyUp(WindowC *w, GadgetC *g, IntuiMessageC *m)
- { up(w,g,m); };
- virtual BOOL exit() { return FALSE; };
- private:
- UBYTE id;
- };
-
- class GadgetEventHandlerC : public IDCMPEventHandlerC {
- public:
- GadgetEventHandlerC(ULONG idcmpClass)
- : IDCMPEventHandlerC(idcmpClass) { };
- };
-
- class GadgetUpHandlerC : public GadgetEventHandlerC {
- public:
- GadgetUpHandlerC()
- : GadgetEventHandlerC(IDCMP_GADGETUP), _exit(FALSE) { };
- BOOL exit();
- protected:
- BOOL _handle(IntuiMessageC &);
- private:
- BOOL _exit;
- };
-
- class GadgetDownHandlerC : public GadgetEventHandlerC {
- public:
- GadgetDownHandlerC()
- : GadgetEventHandlerC(IDCMP_GADGETDOWN), _exit(FALSE) { };
- BOOL exit();
- protected:
- BOOL _handle(IntuiMessageC &);
- private:
- BOOL _exit;
- };
-
- // Achtung, der GadgetMoveHandlerC ist mit etwas Vorsicht zu genießen:
- // Da IDCMP_MOUSEMOVE Events keine Information über das Gadget enthalten,
- // trägt der GadgetMoveHandlerC noch zwei andere HandlerC ein:
- // Einen GadgetDownHandlerC, der ihm ein neues aktuelles Gadget mitteilt,
- // und einen GadgetUpHandlerC, der sicherheitshalber das aktuelle Gadget
- // wieder zurücksetzt (auf NULL). Dieser wird aber nicht immer aufgerufen
- // (z.B. beim "wegklicken" aus einen string gadget).
- // Zur korrekten Funktion des GadgetMoveHandlerC MUSS also das Gadget einen
- // GadgetDown Event empfangen können und am besten auch einen GadgetUp Event.
- // Achja, das Feld IAddress der IntuiMessageC wird trotzdem nicht verändert,
- // wie das GadTools macht...
-
- class GadgetMoveHandlerC;
-
- class GadgetMoveDownHandlerC : public GadgetDownHandlerC {
- friend class GadgetMoveHandlerC;
- private:
- GadgetMoveDownHandlerC(GadgetMoveHandlerC &h)
- : GadgetDownHandlerC() { handler = &h; };
- protected:
- BOOL _handle(IntuiMessageC &);
- private:
- GadgetMoveHandlerC *handler;
- };
-
- class GadgetMoveUpHandlerC : public GadgetUpHandlerC {
- friend class GadgetMoveHandlerC;
- private:
- GadgetMoveUpHandlerC(GadgetMoveHandlerC &h)
- : GadgetUpHandlerC() { handler = &h; };
- protected:
- BOOL _handle(IntuiMessageC &);
- private:
- class GadgetMoveHandlerC *handler;
- };
-
- class GadgetMoveHandlerC : public GadgetEventHandlerC {
- friend class GadgetMoveDownHandlerC;
- friend class GadgetMoveUpHandlerC;
- public:
- GadgetMoveHandlerC();
- BOOL exit();
- protected:
- BOOL _handle(IntuiMessageC &);
- private:
- struct Gadget *gadget;
- GadgetMoveDownHandlerC down_handler;
- GadgetMoveUpHandlerC up_handler;
- BOOL _exit;
- };
-
- struct GadgetKey {
- GadgetC *gadget;
- IX ix;
- };
-
- class GadgetKeyHandlerC : public WindowEventHandlerC {
- public:
- GadgetKeyHandlerC(WindowC &) throw (MemoryX);
- BOOL add(STRPTR, GadgetC &) throw (MemoryX);
- BOOL exit();
- protected:
- BOOL _handle(IntuiMessageC &);
- private:
- gen_arraylist keys;
- BOOL _exit;
- };
-
- #endif
-