1 // $Header: x:/prj/tech/libsrc/gadget/RCS/gadmenu.h 1.7 1996/11/08 14:23:13 xemu Exp $
8 ////////////////////////////////////////////////////////////
11 // A menu is pretty much a vertical array of buttons, usually text.
12 // It can be transient, and will save under itself.
15 typedef struct _LGadMenu LGadMenu
;
17 //------------------------------------------------------------
21 typedef bool (*LGadMenuCallback
)(int which_sel
,LGadMenu
*vm
);
22 /* When a menu item is chosen, the callback is called with the data of which item was chosen. Returns
23 TRUE if the selection was valid and the menu should be destroyed, otherwise FALSE. */
25 typedef bool (*LGadMenuRedraw
)(short x
, short y
, short w
, short h
);
26 /* After the menu goes away, it wants to restore some information underneath it. This callback gets called
27 when the menu goes away, with the dimensions of the LGadMenu so that the right thing can get done. */
29 //------------------------------------------------------------
30 // STRUCTURE DEFINITION
39 LGadMenuCallback vmenuc;\
40 LGadMenuRedraw vmredraw;\
43 grs_bitmap saveunder;\
53 //------------------------------------------------------------
57 #define LGadMenuNumElems(m) (((LGadMenu*)m)->num_elems )
58 #define LGadMenuVisibleElems(m) (((LGadMenu*)m)->vis_elems )
59 #define LGadMenuDrawElem(m,i) (&((LGadMenu*)m->elems[i] ))
60 #define LGadMenuFlags(m) (((LGadMenu*)m)->flags )
61 #define LGadMenuCallback(m) (((LGadMenu*)m)->vmenuc )
62 #define LGadMenuRedrawCall(m) (((LGadMenu*)m)->vmredraw )
63 #define LGadMenuCurrentSelection(m) (((LGadMenu*)m)->cur_sel )
65 #define LGadMenuSaveUnder(m) (&((LGadMenu*)m)->saveunder)
68 #define LGadMenuSetNumElems(m,v) (((LGadMenu*)m)->num_elems = (v))
69 #define LGadMenuSetVisibleElems(m,v) (((LGadMenu*)m)->vis_elems = (v))
70 #define LGadMenuSetDrawElem(m,i,v) (&((LGadMenu*)m)->elems[i] = *(v))
71 #define LGadMenuSetFlags(m,v) (((LGadMenu*)m)->flags = (v))
72 #define LGadMenuSetCallback(m,v) (((LGadMenu*)m)->vmenuc = (v))
73 #define LGadMenuSetRedrawCall(m,v) (((LGadMenu*)m)->vmredraw = (v))
74 #define LGadMenuSetCurrentSelection(m,v) (((LGadMenu*)m)->cur_sel = (v))
76 //------------------------------------------------------------
80 // These flags are for user configuration of the menu
81 #define MENU_TRANSIENT 0x001 // menu goes away if mouse leaves box
82 #define MENU_ALLOC_ELEMS 0x002 // allocate local copy of elems and copy in info
83 #define MENU_GRAB_FOCUS 0x004 // grab all input focus while up
84 #define MENU_HORIZONTAL 0x008 // orient it horizontally, duh
85 #define MENU_MOUSEDOWNS 0x010 // are we interested in mouse down events?
86 #define MENU_SCROLLBAR 0x020 // add a scrollbar on the left/top
87 #define MENU_MOVEKEYS 0x040 // respond to the "standard" key sets for manipulation
88 #define MENU_ESC 0x080 // respond to ESC for termination
89 #define MENU_OUTER_DISMISS 0x100 // destroy if clicks out of region when not tracking
90 #define MENU_SELBOX 0x200 // selection box around current item
91 #define MENU_NOAUTODRAW 0x400 // do not automatically draw on creation
93 #define MENU_STDKEYS (MENU_ESC|MENU_MOVEKEYS)
95 // This is some selection-specific information flags
96 #define MENU_SELINFO_LUP 0x01
97 #define MENU_SELINFO_RUP 0x02
98 #define MENU_SELINFO_LDN 0x04
99 #define MENU_SELINFO_RDN 0x08
105 // These flags are secretly used by the menu itself
106 #define MENU_ALLOC_BASE 0x010000 // did we allocate the basic memory ourselves?
107 #define MENU_SCROLLBARS_USED 0x020000 // did we actually make scrollbuttons?
108 #define MENU_SAVEUNDER_DISABLE 0x040000 // the menu has decided to disable saveunders, typically because of
109 // rendered area overlap
110 #define MENU_SAVEUNDER_TAKEN 0x080000 // have we grabbed a saveunder yet?
111 #define MENU_SCROLL_TRACK 0x100000 // are we currently tracking mouse motion for scrollbars
113 //------------------------------------------------------------
114 // MENU GADGET FUNCTIONS
118 // Creation/Destruction
121 EXTERN LGadMenu
*LGadCreateMenu(LGadMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
, short h
, char paltype
);
122 EXTERN LGadMenu
*LGadCreateMenuArgs(LGadMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
,
123 short h
, short num_elems
, short vis_elems
, DrawElement
*elems
, LGadMenuCallback vmc
,
124 LGadMenuRedraw vmredraw
, ushort flags
, ushort draw_flags
, DrawElement
*inner
, char paltype
);
125 EXTERN
int LGadDestroyMenu(LGadMenu
*vm
);
127 // Change the "focus" (first visible element) of the menu
128 EXTERN
int LGadFocusMenu(LGadMenu
*vm
, int new_f
);
130 // Compute the size of a menu
131 EXTERN
void LGadMenuComputeSize(short *w
, short *h
, short num_elems
, short vis_elems
, uint flags
,
132 DrawElement
*elems
, uint draw_flags
, short extra_w
, short extra_h
);
134 ////////////////////////////////////////////////////////////
137 // An edit menu is an array of editable fields. Each field edits a different variable.
140 //------------------------------------------------------------
141 // VARELEM DEFINITION
144 // A VarElem is a description of a variable, combined with all the state necessary to edit it.
145 #define VARELEM_STRING_LEN 64
148 void *vdata
; // the variable being edited
149 char vtype
; // the type of the variable (see below)
150 uchar flags
; // some flags
152 char edit
[VARELEM_STRING_LEN
];
155 //------------------------------------------------------------
159 #define EDITTYPE_INT 0
160 #define EDITTYPE_SHORT 1
161 #define EDITTYPE_CHAR 2
162 #define EDITTYPE_STRING 3
163 #define EDITTYPE_FIX 4
164 #define EDITTYPE_FLOAT 5
165 /* These 4 all interpret the vdata pointer as a pointer to that specific kind of data type. */
166 #define EDITTYPE_CALLBACK 6
167 /* This vartype will just make a button in the editable area when can be pushed to trigger the
168 callback. The vdata will be interpreted as a LGadButtonCallback. */
169 #define EDITTYPE_CLOSE 7
170 /* Really a special case of EDITTYPE_CALLBACK. Makes a "close" button which when pressed will
171 go process all the text in the various edit boxes and interpret them, storing the final values
172 into the vdata for that VarElem. The menu is then destroyed. */
173 #define EDITTYPE_CANCEL 8
174 /* A button that is like EDITTYPE_CLOSE but it doesn't process any of the edit information, just
175 terminates the menu without affecting the vdata variables. */
176 #define EDITTYPE_APPLY 9
177 /* like EDITTYPE_CLOSE but doesn't actually destroy it (just reprocesses the
179 #define EDITTYPE_TOGGLE 10
180 // when clicked, will cycle through values and pass those off to the drawelement with the value of the
181 // variable passed off to the drawelem as draw_data2. This is most useful with
182 // DRAWTYPE_VARRES and DRAWTYPE_VARSTRING. Note that vdata actually points to an EditToggleInfo struct!!
184 // Note that for EDITTYPE_CLOSE, CANCEL, and APPLY, a non-NULL vdata is interpreted as like
185 // EDITTYPE_CALLBACK.
193 //------------------------------------------------------------
197 #define EDITFLAG_NORMAL 0
199 #define EDITFLAG_HEX 0x01
200 #define EDITFLAG_OCTAL 0x02
201 #define EDITFLAG_BINARY 0x04
202 #define EDITFLAG_READONLY 0x08
203 #define EDITFLAG_UNSIGNED 0x10
204 #define EDITFLAG_INITCLEAR 0x20
205 #define EDITFLAG_PRISTINE 0x40
207 //------------------------------------------------------------
208 // EDIT MENU STRUCTURE DEFINITION
216 //------------------------------------------------------------
220 #define LGadEditMenuNumElems(m) LGadMenuNumElems(m)
221 #define LGadEditMenuVisibleElems(m) LGadMenuVisibleElems(m)
222 #define LGadEditMenuDrawElem(m,i) LGadMenuDrawElem(m,i)
223 #define LGadEditMenuFlags(m) LGadMenuFlags(m)
224 #define LGadEditMenuCallback(m) LGadMenuCallback(m)
225 #define LGadEditMenuRedrawCall(m) LGadMenuRedrawCall(m)
226 #define LGadEditMenuCurrentSelection(m) LGadMenuCurrentSelection(m)
228 #define LGadEditMenuVarElem(m,i) (&((LGadEditMenu*)m)->varlist[i])
231 #define LGadEditMenuSaveUnder(m) LGadMenuSaveUnder(m)
234 #define LGadEditMenuSetNumElems(m,v) LGadMenuSetNumElems(m,v)
235 #define LGadEditMenuSetVisibleElems(m,v) LGadMenuSetVisibleElems(m,v)
236 #define LGadEditMenuSetDrawElem(m,i,v) LGadMenuSetDrawElem(m,i,v)
237 #define LGadEditMenuSetFlags(m,v) LGadMenuSetFlags(m,v)
238 #define LGadEditMenuSetCallback(m,v) LGadMenuSetCallback(m,v)
239 #define LGadEditMenuSetRedrawCall(m,v) LGadMenuSetRedrawCall(m,v)
240 #define LGadEditMenuSetCurrentSelection(m,v) LGadMenuSetCurrentSelection(m,v)
242 //------------------------------------------------------------
243 // EDIT MENU FUNCTIONS
250 EXTERN LGadEditMenu
*LGadCreateEditMenuArgs(LGadEditMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
,
251 short h
, short num_elems
, short vis_elems
, DrawElement
*elems
, ushort flags
, ushort draw_flags
,
252 DrawElement
*inner
, VarElem
*varlist
, char paltype
);
253 EXTERN LGadEditMenu
*LGadCreateEditMenu(LGadEditMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
, short h
, char paltype
);
255 // Force an editmenu's variables to update
256 EXTERN
void LGadEditMenuProcess(LGadEditMenu
*vem
);
258 // Set the text fields for a menu from the data
259 EXTERN
void LGadEditMenuSetText(LGadEditMenu
*vm
);
261 #endif // __GADMENU_H