forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / bgui / gadgets / TreeView / TreeViewDemo.c
blob1b3b64f9a1192eee11c3c1c2ee33789d0c4240e1
1 /*
2 * @(#) $Header$
4 * BGUI Tree List View class
6 * (C) Copyright 1999 Manuel Lemos.
7 * (C) Copyright 1996-1999 Nick Christie.
8 * All Rights Reserved.
10 * $Log$
11 * Revision 42.7 2004/06/16 20:16:49 verhaegs
12 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
14 * Revision 42.6 2003/01/18 19:10:20 chodorowski
15 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
17 * Revision 42.5 2000/08/09 10:17:25 chodorowski
18 * #include <bgui/bgui_compilerspecific.h> for the REGFUNC and REGPARAM
19 * macros. Some of these files didn't need them at all...
21 * Revision 42.4 2000/08/08 14:02:07 chodorowski
22 * Removed all REGFUNC, REGPARAM and REG macros. Now includes
23 * contrib/bgui/compilerspecific.h where they are defined.
25 * Revision 42.3 2000/07/09 11:03:10 stegerg
26 * bug fix.
28 * Revision 42.2 2000/07/09 03:05:09 bergers
29 * Makes the gadgets compilable.
31 * Revision 42.1 2000/05/15 19:29:08 stegerg
32 * replacements for REG macro
34 * Revision 42.0 2000/05/09 22:22:17 mlemos
35 * Bumped to revision 42.0 before handing BGUI to AROS team
37 * Revision 41.11 2000/05/09 20:36:05 mlemos
38 * Bumped to revision 41.11
40 * Revision 1.2 2000/05/09 20:00:59 mlemos
41 * Merged with the branch Manuel_Lemos_fixes.
43 * Revision 1.1.2.2 1999/05/31 01:19:23 mlemos
44 * Made the program create TreeView object instances using the bgui.library to
45 * setup the gadget library.
47 * Revision 1.1.2.1 1999/02/21 04:08:19 mlemos
48 * Nick Christie sources.
54 /************************************************************************
55 ************************* TREEVIEW CLASS DEMO *************************
56 ************************************************************************/
58 #include <exec/exec.h>
59 #include <dos/dos.h>
60 #include <libraries/bgui.h>
61 #include <libraries/bgui_macros.h>
63 #include <clib/alib_protos.h>
64 #include <clib/macros.h>
66 #include <proto/exec.h>
67 #include <proto/dos.h>
68 #include <proto/intuition.h>
69 #include <proto/bgui.h>
70 #include <proto/utility.h>
72 #include <bgui/bgui_treeview.h>
74 #ifndef BGUI_COMPILERSPECIFIC_H
75 #include <bgui/bgui_compilerspecific.h>
76 #endif
78 /************************************************************************
79 ***************************** DEFINITIONS *****************************
80 ************************************************************************/
83 * Object IDs
86 #define ID_TV_TEST 1
87 #define ID_BT_ADD 2
88 #define ID_BT_REMOVE 3
89 #define ID_BT_QUIT 4
92 * Some rawkey codes
95 #define RAW_RETURN 68
96 #define RAW_UPARROW 76
97 #define RAW_DOWNARROW 77
99 #define SHIFTKEYS (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)
100 #define CTRLKEY (IEQUALIFIER_CONTROL)
101 #define ALTKEYS (IEQUALIFIER_LALT|IEQUALIFIER_RALT)
103 /************************************************************************
104 ***************************** PROTOTYPES ******************************
105 ************************************************************************/
107 int main(int argc,char **argv);
109 //ASM SAVEDS ULONG WindowHandler(REG(a0) struct Hook *hook,
110 // REG(a2) Object *obj, REG(a1) struct IntuiMessage *imsg);
111 ASM SAVEDS REGFUNCPROTO3(ULONG, WindowHandler,
112 REGPARAM(A0, struct Hook *, hook),
113 REGPARAM(A2, Object *, obj),
114 REGPARAM(A1, struct IntuiMessage *, imsg));
116 /************************************************************************
117 ***************************** LOCAL DATA ******************************
118 ************************************************************************/
121 * Library base.
124 struct Library *BGUIBase = NULL;
126 struct IntuitionBase * IntuitionBase = NULL;
127 /************************************************************************
128 ******************************* MAIN() ********************************
129 ************************************************************************/
131 int main(int argc,char **argv)
134 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
136 if ((BGUIBase = OpenLibrary("bgui.library",40)) && IntuitionBase)
138 struct Hook idcmphook;
139 Object *WI_Main,*TV_Test,*BT_Add,*BT_Remove,*BT_Quit;
141 TV_Test = BGUI_NewObject(BGUI_TREEVIEW_GADGET,
142 GA_ID, ID_TV_TEST,
143 TVA_Indentation, 12,
144 TVA_ImageStyle, TVIS_BOX,
145 TVA_LineStyle, TVLS_DOTS,
146 TVA_NoLeafImage, TRUE,
147 LISTV_MinEntriesShown,5,
148 PGA_NewLook, TRUE,
149 TAG_DONE);
151 idcmphook.h_Entry = (HOOKFUNC) WindowHandler;
152 idcmphook.h_Data= (APTR) TV_Test;
154 WI_Main = WindowObject,
155 WINDOW_Title, "TreeView Class Demo",
156 WINDOW_ScreenTitle, "TreeView Class for BGUI by Nick Christie (18.09.96)",
157 WINDOW_AutoAspect, TRUE,
158 WINDOW_SmartRefresh, TRUE,
159 WINDOW_RMBTrap, TRUE,
160 WINDOW_AutoKeyLabel, TRUE,
161 WINDOW_ScaleHeight, 33,
162 WINDOW_IDCMPHook, &idcmphook,
163 WINDOW_IDCMPHookBits, IDCMP_RAWKEY,
164 WINDOW_MasterGroup,
165 VGroupObject, HOffset(4), VOffset(4), Spacing(4),
166 StartMember,
167 TV_Test,
168 EndMember,
169 StartMember,
170 HGroupObject, HOffset(4), VOffset(4), Spacing(4),
171 VarSpace(DEFAULT_WEIGHT/2),
172 StartMember,
173 BT_Add = ButtonObject,
174 LAB_Label, "_Add",
175 GA_ID, ID_BT_ADD,
176 EndObject,
177 EndMember,
178 VarSpace(DEFAULT_WEIGHT/2),
179 StartMember,
180 BT_Remove = ButtonObject,
181 LAB_Label, "_Remove",
182 GA_ID, ID_BT_REMOVE,
183 GA_Disabled, TRUE,
184 EndObject,
185 EndMember,
186 VarSpace(DEFAULT_WEIGHT/2),
187 StartMember,
188 BT_Quit = ButtonObject,
189 LAB_Label, "_Quit",
190 GA_ID, ID_BT_QUIT,
191 EndObject,
192 EndMember,
193 VarSpace(DEFAULT_WEIGHT/2),
194 EndObject, FixMinHeight,
195 EndMember,
196 EndObject,
197 EndObject;
199 if (WI_Main)
201 struct Window *win;
202 BOOL ok;
204 static STRPTR GrandParent = "Grandparent";
205 static STRPTR Parent[] = {"Parent A","Parent B","Parent C"};
206 static STRPTR ChildA[] = {"Child A0","Child A1","Child A2"};
207 static STRPTR GrandA[] = {"Grandchild A0A","Grandchild A0B","Grandchild A2A"};
208 static STRPTR ChildB[] = {"Child B0"};
209 static STRPTR NewEntry = "New Entry";
211 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
212 TVM_INSERT,NULL,GrandParent,TV_ROOT,TVW_CHILD_LAST,TVF_EXPAND);
214 if (ok)
215 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
216 TVM_INSERT,NULL,Parent[0],GrandParent,TVW_CHILD_LAST,TVF_EXPAND);
218 if (ok)
219 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
220 TVM_INSERT,NULL,Parent[1],GrandParent,TVW_CHILD_LAST,TVF_EXPAND);
222 if (ok)
223 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
224 TVM_INSERT,NULL,Parent[2],GrandParent,TVW_CHILD_LAST,TVF_EXPAND);
226 if (ok)
227 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
228 TVM_INSERT,NULL,ChildA[0],Parent[0],TVW_CHILD_LAST,TVF_EXPAND);
230 if (ok)
231 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
232 TVM_INSERT,NULL,ChildA[1],Parent[0],TVW_CHILD_LAST,TVF_EXPAND);
234 if (ok)
235 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
236 TVM_INSERT,NULL,ChildA[2],Parent[0],TVW_CHILD_LAST,TVF_EXPAND);
238 if (ok)
239 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
240 TVM_INSERT,NULL,GrandA[0],ChildA[0],TVW_CHILD_LAST,TVF_EXPAND);
242 if (ok)
243 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
244 TVM_INSERT,NULL,GrandA[1],ChildA[0],TVW_CHILD_LAST,TVF_EXPAND);
246 if (ok)
247 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
248 TVM_INSERT,NULL,GrandA[2],ChildA[2],TVW_CHILD_LAST,TVF_EXPAND);
250 if (ok)
251 ok = (BOOL) BGUI_DoGadgetMethod(TV_Test,NULL,NULL,
252 TVM_INSERT,NULL,ChildB[0],Parent[1],TVW_CHILD_LAST,TVF_EXPAND);
254 if (ok)
256 if ((win = WindowOpen(WI_Main)))
258 IPTR winsig;
259 ULONG sigs,id;
260 BOOL running;
262 GetAttr(WINDOW_SigMask,WI_Main,&winsig);
263 running = TRUE;
265 while(running)
267 sigs = Wait(winsig|SIGBREAKF_CTRL_C);
269 if (sigs & winsig)
271 while((id = HandleEvent(WI_Main)) != WMHI_NOMORE)
273 switch(id)
275 case WMHI_CLOSEWINDOW:
276 case ID_BT_QUIT:
277 running = FALSE;
278 break;
280 case ID_BT_ADD:
281 if (BGUI_DoGadgetMethod(TV_Test,win,NULL,TVM_INSERT,
282 NULL,NewEntry,TV_SELECTED,TVW_CHILD_FIRST,0))
284 SetGadgetAttrs((struct Gadget *) BT_Add,
285 win,NULL,GA_Disabled,TRUE,TAG_DONE);
286 SetGadgetAttrs((struct Gadget *) BT_Remove,
287 win,NULL,GA_Disabled,FALSE,TAG_DONE);
289 break;
291 case ID_BT_REMOVE:
292 if (BGUI_DoGadgetMethod(TV_Test,win,NULL,TVM_REMOVE,
293 NULL,NewEntry,TVW_ENTRY,0))
295 SetGadgetAttrs((struct Gadget *) BT_Add,
296 win,NULL,GA_Disabled,FALSE,TAG_DONE);
297 SetGadgetAttrs((struct Gadget *) BT_Remove,
298 win,NULL,GA_Disabled,TRUE,TAG_DONE);
300 break;
302 default:
303 break;
308 if (sigs & SIGBREAKF_CTRL_C)
309 running = FALSE;
314 DisposeObject(WI_Main);
316 CloseLibrary(BGUIBase);
319 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
320 return(0);
323 /************************************************************************
324 *************************** WINDOWHANDLER() ***************************
325 *************************************************************************
326 * Hook for main window IDCMP messages. Called by window object after its
327 * intuimsg processing has finished, before main() gets control. Used
328 * here to provide extra keyboard control not possible using normal
329 * gadget-key assignment, specifically: crsr up/down to select entry in
330 * treeview and ESC to close window.
332 *************************************************************************/
334 //ASM SAVEDS ULONG WindowHandler(REG(a0) struct Hook *hook,
335 // REG(a2) Object *obj, REG(a1) struct IntuiMessage *imsg)
336 ASM SAVEDS REGFUNC3(ULONG, WindowHandler,
337 REGPARAM(A0, struct Hook *, hook),
338 REGPARAM(A2, Object *, obj),
339 REGPARAM(A1, struct IntuiMessage *, imsg))
341 struct Window *win;
342 ULONG cursel,method,which,flags;
343 IPTR entry;
344 Object *view;
346 view = (Object *) hook->h_Data;
347 win = imsg->IDCMPWindow;
349 if (imsg->Class == IDCMP_RAWKEY)
351 method = TVM_SELECT;
352 entry = (IPTR) TV_SELECTED;
353 which = ~0;
354 flags = TVF_MAKEVISIBLE;
355 cursel = DoMethod(view,TVM_GETENTRY,TV_SELECTED,TVW_ENTRY,0);
357 if (imsg->Code == RAW_UPARROW)
359 if (cursel)
361 which = TVW_TREE_PREV;
363 if (imsg->Qualifier & SHIFTKEYS)
364 which = TVW_TREE_PAGE_UP;
366 if (imsg->Qualifier & CTRLKEY)
368 entry = (IPTR) TV_ROOT;
369 which = TVW_CHILD_FIRST;
372 else
374 which = TVW_CHILD_FIRST;
375 entry = (IPTR) TV_ROOT;
379 if (imsg->Code == RAW_DOWNARROW)
381 if (cursel)
383 which = TVW_TREE_NEXT;
385 if (imsg->Qualifier & SHIFTKEYS)
386 which = TVW_TREE_PAGE_DOWN;
388 if (imsg->Qualifier & CTRLKEY)
390 entry = (IPTR) TV_ROOT;
391 which = TVW_TREE_LAST;
394 else
396 which = TVW_CHILD_FIRST;
397 entry = (IPTR) TV_ROOT;
401 if (imsg->Code == RAW_RETURN)
403 method = TVM_EXPAND;
404 which = TVW_ENTRY;
405 flags = TVF_TOGGLE;
408 if (which != ~0)
409 BGUI_DoGadgetMethod(view,win,NULL,method,
410 NULL,entry,which,flags);
413 return(0);
415 REGFUNC_END