4 * BGUI Tree List View class
6 * (C) Copyright 1999 Manuel Lemos.
7 * (C) Copyright 1996-1999 Nick Christie.
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
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>
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>
78 /************************************************************************
79 ***************************** DEFINITIONS *****************************
80 ************************************************************************/
88 #define ID_BT_REMOVE 3
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 ************************************************************************/
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
,
144 TVA_ImageStyle
, TVIS_BOX
,
145 TVA_LineStyle
, TVLS_DOTS
,
146 TVA_NoLeafImage
, TRUE
,
147 LISTV_MinEntriesShown
,5,
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
,
165 VGroupObject
, HOffset(4), VOffset(4), Spacing(4),
170 HGroupObject
, HOffset(4), VOffset(4), Spacing(4),
171 VarSpace(DEFAULT_WEIGHT
/2),
173 BT_Add
= ButtonObject
,
178 VarSpace(DEFAULT_WEIGHT
/2),
180 BT_Remove
= ButtonObject
,
181 LAB_Label
, "_Remove",
186 VarSpace(DEFAULT_WEIGHT
/2),
188 BT_Quit
= ButtonObject
,
193 VarSpace(DEFAULT_WEIGHT
/2),
194 EndObject
, FixMinHeight
,
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
);
215 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
216 TVM_INSERT
,NULL
,Parent
[0],GrandParent
,TVW_CHILD_LAST
,TVF_EXPAND
);
219 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
220 TVM_INSERT
,NULL
,Parent
[1],GrandParent
,TVW_CHILD_LAST
,TVF_EXPAND
);
223 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
224 TVM_INSERT
,NULL
,Parent
[2],GrandParent
,TVW_CHILD_LAST
,TVF_EXPAND
);
227 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
228 TVM_INSERT
,NULL
,ChildA
[0],Parent
[0],TVW_CHILD_LAST
,TVF_EXPAND
);
231 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
232 TVM_INSERT
,NULL
,ChildA
[1],Parent
[0],TVW_CHILD_LAST
,TVF_EXPAND
);
235 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
236 TVM_INSERT
,NULL
,ChildA
[2],Parent
[0],TVW_CHILD_LAST
,TVF_EXPAND
);
239 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
240 TVM_INSERT
,NULL
,GrandA
[0],ChildA
[0],TVW_CHILD_LAST
,TVF_EXPAND
);
243 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
244 TVM_INSERT
,NULL
,GrandA
[1],ChildA
[0],TVW_CHILD_LAST
,TVF_EXPAND
);
247 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
248 TVM_INSERT
,NULL
,GrandA
[2],ChildA
[2],TVW_CHILD_LAST
,TVF_EXPAND
);
251 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
252 TVM_INSERT
,NULL
,ChildB
[0],Parent
[1],TVW_CHILD_LAST
,TVF_EXPAND
);
256 if ((win
= WindowOpen(WI_Main
)))
262 GetAttr(WINDOW_SigMask
,WI_Main
,&winsig
);
267 sigs
= Wait(winsig
|SIGBREAKF_CTRL_C
);
271 while((id
= HandleEvent(WI_Main
)) != WMHI_NOMORE
)
275 case WMHI_CLOSEWINDOW
:
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
);
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
);
308 if (sigs
& SIGBREAKF_CTRL_C
)
314 DisposeObject(WI_Main
);
316 CloseLibrary(BGUIBase
);
319 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
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
))
342 ULONG cursel
,method
,which
,flags
;
346 view
= (Object
*) hook
->h_Data
;
347 win
= imsg
->IDCMPWindow
;
349 if (imsg
->Class
== IDCMP_RAWKEY
)
352 entry
= (IPTR
) TV_SELECTED
;
354 flags
= TVF_MAKEVISIBLE
;
355 cursel
= DoMethod(view
,TVM_GETENTRY
,TV_SELECTED
,TVW_ENTRY
,0);
357 if (imsg
->Code
== RAW_UPARROW
)
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
;
374 which
= TVW_CHILD_FIRST
;
375 entry
= (IPTR
) TV_ROOT
;
379 if (imsg
->Code
== RAW_DOWNARROW
)
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
;
396 which
= TVW_CHILD_FIRST
;
397 entry
= (IPTR
) TV_ROOT
;
401 if (imsg
->Code
== RAW_RETURN
)
409 BGUI_DoGadgetMethod(view
,win
,NULL
,method
,
410 NULL
,entry
,which
,flags
);