4 * BGUI Tree List View class
6 * (C) Copyright 1999 Manuel Lemos.
7 * (C) Copyright 1996-1999 Nick Christie.
11 * Revision 42.4 2004/06/16 20:16:49 verhaegs
12 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
14 * Revision 42.3 2000/08/09 10:17:25 chodorowski
15 * #include <bgui/bgui_compilerspecific.h> for the REGFUNC and REGPARAM
16 * macros. Some of these files didn't need them at all...
18 * Revision 42.2 2000/08/08 14:02:07 chodorowski
19 * Removed all REGFUNC, REGPARAM and REG macros. Now includes
20 * contrib/bgui/compilerspecific.h where they are defined.
22 * Revision 42.1 2000/05/15 19:29:08 stegerg
23 * replacements for REG macro
25 * Revision 42.0 2000/05/09 22:22:11 mlemos
26 * Bumped to revision 42.0 before handing BGUI to AROS team
28 * Revision 41.11 2000/05/09 20:35:59 mlemos
29 * Bumped to revision 41.11
31 * Revision 1.2 2000/05/09 20:00:54 mlemos
32 * Merged with the branch Manuel_Lemos_fixes.
34 * Revision 1.1.2.2 1999/05/31 01:19:20 mlemos
35 * Made the program create TreeView object instances using the bgui.library to
36 * setup the gadget library.
38 * Revision 1.1.2.1 1999/02/21 04:08:13 mlemos
39 * Nick Christie sources.
45 /************************************************************************
46 ************************* TEST TREEVIEW CLASS *************************
47 ************************************************************************/
49 #include <exec/exec.h>
51 #include <libraries/bgui.h>
52 #include <libraries/bgui_macros.h>
54 #include <clib/alib_protos.h>
55 #include <clib/macros.h>
57 #include <proto/exec.h>
58 #include <proto/dos.h>
59 #include <proto/intuition.h>
60 #include <proto/bgui.h>
61 #include <proto/utility.h>
63 #include <bgui/bgui_treeview.h>
65 #ifndef BGUI_COMPILERSPECIFIC_H
66 #include <bgui/bgui_compilerspecific.h>
69 /************************************************************************
70 ***************************** DEFINITIONS *****************************
71 ************************************************************************/
81 #define ID_CYC_METHOD 5
82 #define ID_CYC_ENTRY 6
83 #define ID_CYC_WHICH 7
84 #define ID_CH_SELECTED 8
85 #define ID_CH_VISIBLE 9
86 #define ID_CH_MAKEVISIBLE 10
87 #define ID_CH_SELECT 11
88 #define ID_CH_DESELECT 12
89 #define ID_CH_MULTISELECT 13
90 #define ID_CH_EXPAND 14
91 #define ID_CH_CONTRACT 15
92 #define ID_CH_TOGGLE 16
99 #define RAW_UPARROW 76
100 #define RAW_DOWNARROW 77
102 #define SHIFTKEYS (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)
103 #define CTRLKEY (IEQUALIFIER_CONTROL)
104 #define ALTKEYS (IEQUALIFIER_LALT|IEQUALIFIER_RALT)
106 /************************************************************************
107 ***************************** PROTOTYPES ******************************
108 ************************************************************************/
110 int main(int argc
,char **argv
);
112 //ASM SAVEDS ULONG WindowHandler(REG(a0) struct Hook *hook,
113 // REG(a2) Object *obj, REG(a1) struct IntuiMessage *imsg);
114 ASM SAVEDS
REGFUNCPROTO3(ULONG
, WindowHandler
,
115 REGPARAM(A0
, struct Hook
*, hook
),
116 REGPARAM(A2
, Object
*, obj
),
117 REGPARAM(A1
, struct IntuiMessage
*, imsg
));
119 //ASM SAVEDS ULONG TVNotifyHandler(REG(a0) struct Hook *hook,
120 // REG(a2) Object *obj, REG(a1) struct opUpdate *opu);
121 ASM SAVEDS
REGFUNCPROTO3(ULONG
, TVNotifyHandler
,
122 REGPARAM(A0
, struct Hook
*, hook
),
123 REGPARAM(A2
, Object
*, obj
),
124 REGPARAM(A1
, struct opUpdate
*, opu
));
126 struct List
*MakeList(void);
127 void FreeList(struct List
*list
);
130 #include <aros/arossupport.h>
131 #define KPrintF kprintf
133 extern void __stdargs
KPrintF(char *fmt
,...);
136 /************************************************************************
137 ***************************** LOCAL DATA ******************************
138 ************************************************************************/
144 struct Library
*BGUIBase
= NULL
;
146 /************************************************************************
147 ******************************* MAIN() ********************************
148 ************************************************************************/
150 int main(int argc
,char **argv
)
153 static STRPTR CycEntryLabels
[] = {
154 "Root", "Selected", NULL
157 static STRPTR CycWhichLabels
[] = {
158 "Entry", "Parent", "Child First", "Child Last", "Child Sorted",
159 "Child All", "Child Tree", "Sib. First", "Sib. Last",
160 "Sib. Next", "Sibl. Prev", "Sib. Sorted", "Sib. All",
161 "Sib. Tree", "Tree First", "Tree Last", "Tree Next",
162 "Tree Prev", "Tree PgUp", "Tree PgDn", NULL
165 static ULONG WhichValues
[] = {
166 TVW_ENTRY
, TVW_PARENT
, TVW_CHILD_FIRST
, TVW_CHILD_LAST
, TVW_CHILD_SORTED
,
167 TVW_CHILD_ALL
, TVW_CHILD_TREE
, TVW_SIBLING_FIRST
, TVW_SIBLING_LAST
,
168 TVW_SIBLING_NEXT
, TVW_SIBLING_PREV
, TVW_SIBLING_SORTED
, TVW_SIBLING_ALL
,
169 TVW_SIBLING_TREE
, TVW_TREE_FIRST
, TVW_TREE_LAST
, TVW_TREE_NEXT
,
170 TVW_TREE_PREV
, TVW_TREE_PAGE_UP
, TVW_TREE_PAGE_DOWN
173 static STRPTR CycMethodLabels
[] = {
174 "TVM_INSERT", "TVM_REMOVE", "TVM_REPLACE", "TVM_MOVE", "TVM_GETENTRY",
175 "TVM_SELECT", "TVM_VISIBLE", "TVM_EXPAND", "TVM_CLEAR", "TVM_LOCK",
176 "TVM_UNLOCK", "TVM_SORT", "TVM_REDRAW", "TVM_REFRESH", "TVM_REBUILD",
180 static ULONG MethodValues
[] = {
181 TVM_INSERT
, TVM_REMOVE
, TVM_REPLACE
, TVM_MOVE
, TVM_GETENTRY
, TVM_SELECT
,
182 TVM_VISIBLE
, TVM_EXPAND
, TVM_CLEAR
, TVM_LOCK
, TVM_UNLOCK
, TVM_SORT
,
183 TVM_REDRAW
, TVM_REFRESH
, TVM_REBUILD
186 static STRPTR NewEntry
= "New Entry";
188 static STRPTR RepEntry
= "Replacement Entry";
191 if (BGUIBase
= OpenLibrary("bgui.library",40))
193 struct Hook idcmphook
,tvnotifyhook
;
194 Object
*WI_Main
,*TV_Test
,*BT_Test1
,*BT_Test2
,*BT_Quit
;
195 Object
*CYC_Method
,*CYC_Which
, *CYC_Entry
;
196 Object
*CH_Selected
,*CH_Visible
,*CH_MakeVisible
;
197 Object
*CH_Select
,*CH_Deselect
,*CH_MultiSelect
;
198 Object
*CH_Expand
,*CH_Contract
,*CH_Toggle
;
199 Object
*IMG_Expand
,*IMG_Contract
;
201 IMG_Expand
= VectorObject
,VIT_BuiltIn
,BUILTIN_ARROW_DOWN
,
202 IA_Width
,9,IA_Height
,9,EndObject
;
203 IMG_Contract
= VectorObject
,VIT_BuiltIn
,BUILTIN_ARROW_RIGHT
,
204 IA_Width
,9,IA_Height
,9,EndObject
;
206 TV_Test
= BGUI_NewObject(BGUI_TREEVIEW_GADGET
,
209 TVA_ImageStyle
, TVIS_BOX
,
210 TVA_LineStyle
, TVLS_DOTS
,
211 TVA_LeftAlignImage
, FALSE
,
212 TVA_NoLeafImage
, TRUE
,
213 /*TVA_ExpandedImage, IMG_Expand,*/
214 /*TVA_ContractedImage, IMG_Contract,*/
215 LISTV_MinEntriesShown
,5,
216 LISTV_MultiSelect
, TRUE
,
220 idcmphook
.h_Entry
= (HOOKFUNC
) WindowHandler
;
221 idcmphook
.h_Data
= (APTR
) TV_Test
;
222 tvnotifyhook
.h_Entry
= (HOOKFUNC
) TVNotifyHandler
;
223 tvnotifyhook
.h_Data
= (APTR
) TV_Test
;
225 WI_Main
= WindowObject
,
226 WINDOW_Title
, "TreeView Class Testbed",
227 WINDOW_AutoAspect
, TRUE
,
228 WINDOW_SmartRefresh
, TRUE
,
229 WINDOW_RMBTrap
, TRUE
,
230 WINDOW_AutoKeyLabel
, TRUE
,
231 WINDOW_ScaleHeight
, 33,
232 WINDOW_IDCMPHook
, &idcmphook
,
233 WINDOW_IDCMPHookBits
, IDCMP_RAWKEY
,
235 VGroupObject
, HOffset(4), VOffset(4), Spacing(4),
242 VGroupObject
, HOffset(4), VOffset(4), Spacing(4),
245 VarSpace(DEFAULT_WEIGHT
/2),
247 CYC_Method
= CycleObject
,
248 LAB_Label
, "_Method",
249 GA_ID
, ID_CYC_METHOD
,
250 CYC_Labels
, CycMethodLabels
,
255 VarSpace(DEFAULT_WEIGHT
/2),
257 CYC_Entry
= CycleObject
,
260 CYC_Labels
, CycEntryLabels
,
265 VarSpace(DEFAULT_WEIGHT
/2),
267 CYC_Which
= CycleObject
,
270 CYC_Labels
, CycWhichLabels
,
275 VarSpace(DEFAULT_WEIGHT
/2),
276 EndObject
, FixMinHeight
,
278 VarSpace(DEFAULT_WEIGHT
/2),
280 VGroupObject
, HOffset(4), VOffset(4), Spacing(2),
283 VarSpace(DEFAULT_WEIGHT
/2),
285 CH_Selected
= CheckBox("_Selected",FALSE
,ID_CH_SELECTED
),
287 VarSpace(DEFAULT_WEIGHT
/2),
289 CH_Visible
= CheckBox("_Visible",FALSE
,ID_CH_VISIBLE
),
291 VarSpace(DEFAULT_WEIGHT
/2),
293 CH_MakeVisible
= CheckBox("Ma_keVisible",FALSE
,ID_CH_MAKEVISIBLE
),
295 VarSpace(DEFAULT_WEIGHT
/2),
298 VarSpace(DEFAULT_WEIGHT
/2),
300 VGroupObject
, HOffset(4), VOffset(4), Spacing(2),
303 VarSpace(DEFAULT_WEIGHT
/2),
305 CH_Select
= CheckBox("Se_lect",FALSE
,ID_CH_SELECT
),
307 VarSpace(DEFAULT_WEIGHT
/2),
309 CH_Deselect
= CheckBox("_Deselect",FALSE
,ID_CH_DESELECT
),
311 VarSpace(DEFAULT_WEIGHT
/2),
313 CH_MultiSelect
= CheckBox("M_ultiSelect",FALSE
,ID_CH_MULTISELECT
),
315 VarSpace(DEFAULT_WEIGHT
/2),
318 VarSpace(DEFAULT_WEIGHT
/2),
320 VGroupObject
, HOffset(4), VOffset(4), Spacing(2),
323 VarSpace(DEFAULT_WEIGHT
/2),
325 CH_Expand
= CheckBox("E_xpand",FALSE
,ID_CH_EXPAND
),
327 VarSpace(DEFAULT_WEIGHT
/2),
329 CH_Contract
= CheckBox("_Contract",FALSE
,ID_CH_CONTRACT
),
331 VarSpace(DEFAULT_WEIGHT
/2),
333 CH_Toggle
= CheckBox("To_ggle",FALSE
,ID_CH_TOGGLE
),
335 VarSpace(DEFAULT_WEIGHT
/2),
338 VarSpace(DEFAULT_WEIGHT
/2),
339 EndObject
, FixMinHeight
,
342 HGroupObject
, HOffset(4), VOffset(4), Spacing(4),
343 VarSpace(DEFAULT_WEIGHT
/2),
345 BT_Test1
= ButtonObject
,
346 LAB_Label
, "Test _1",
350 VarSpace(DEFAULT_WEIGHT
/2),
352 BT_Test2
= ButtonObject
,
353 LAB_Label
, "Test _2",
357 VarSpace(DEFAULT_WEIGHT
/2),
359 BT_Quit
= ButtonObject
,
364 VarSpace(DEFAULT_WEIGHT
/2),
365 EndObject
, FixMinHeight
,
375 static STRPTR Parent
[] = {"Parent 0A","Parent 1A","Parent 2A"};
376 static STRPTR Child
[] = {"Child 0A","Child 1A","Child 2A"};
377 static STRPTR Grand
[] = {"Grandchild 0A","Grandchild 1A","Grandchild 2A"};
379 /* ok = AddHook(TV_Test,&tvnotifyhook); */
381 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
382 TVM_INSERT
,NULL
,Parent
[0],TV_ROOT
,TVW_CHILD_LAST
,TVF_EXPAND
);
385 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
386 TVM_INSERT
,NULL
,Child
[0],Parent
[0],TVW_CHILD_LAST
,TVF_EXPAND
);
389 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
390 TVM_INSERT
,NULL
,Grand
[0],Child
[0],TVW_CHILD_LAST
,TVF_EXPAND
);
393 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
394 TVM_INSERT
,NULL
,Grand
[1],Child
[0],TVW_CHILD_LAST
,0);
397 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
398 TVM_INSERT
,NULL
,Grand
[2],Child
[0],TVW_CHILD_LAST
,0);
401 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
402 TVM_INSERT
,NULL
,Parent
[1],TV_ROOT
,TVW_CHILD_LAST
,TVF_EXPAND
);
405 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
406 TVM_INSERT
,NULL
,Child
[1],Parent
[1],TVW_CHILD_LAST
,0);
409 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
410 TVM_INSERT
,NULL
,Parent
[2],TV_ROOT
,TVW_CHILD_LAST
,TVF_EXPAND
);
413 ok
= (BOOL
) BGUI_DoGadgetMethod(TV_Test
,NULL
,NULL
,
414 TVM_INSERT
,NULL
,Child
[2],Parent
[2],TVW_CHILD_LAST
,0);
418 if (win
= WindowOpen(WI_Main
))
420 ULONG winsig
,sigs
,id
,rc
;
423 GetAttr(WINDOW_SigMask
,WI_Main
,&winsig
);
428 sigs
= Wait(winsig
|SIGBREAKF_CTRL_C
);
432 while((id
= HandleEvent(WI_Main
)) != WMHI_NOMORE
)
434 ULONG method
,methodid
,entryid
,tmp
;
435 ULONG whichid
,entry
,which
,flags
;
440 case WMHI_CLOSEWINDOW
:
446 GetAttr(CYC_Active
,CYC_Method
,&methodid
);
447 GetAttr(CYC_Active
,CYC_Entry
,&entryid
);
448 GetAttr(CYC_Active
,CYC_Which
,&whichid
);
450 method
= MethodValues
[methodid
];
451 entry
= entryid
? (ULONG
) TV_SELECTED
: (ULONG
) TV_ROOT
;
452 which
= WhichValues
[whichid
];
456 GetAttr(GA_Selected
,CH_Selected
,&tmp
);
457 if (tmp
) flags
|= TVF_SELECTED
;
458 GetAttr(GA_Selected
,CH_Visible
,&tmp
);
459 if (tmp
) flags
|= TVF_VISIBLE
;
460 GetAttr(GA_Selected
,CH_Select
,&tmp
);
461 if (tmp
) flags
|= TVF_SELECT
;
462 GetAttr(GA_Selected
,CH_Deselect
,&tmp
);
463 if (tmp
) flags
|= TVF_DESELECT
;
464 GetAttr(GA_Selected
,CH_MultiSelect
,&tmp
);
465 if (tmp
) flags
|= TVF_MULTISELECT
;
466 GetAttr(GA_Selected
,CH_MakeVisible
,&tmp
);
467 if (tmp
) flags
|= TVF_MAKEVISIBLE
;
468 GetAttr(GA_Selected
,CH_Expand
,&tmp
);
469 if (tmp
) flags
|= TVF_EXPAND
;
470 GetAttr(GA_Selected
,CH_Contract
,&tmp
);
471 if (tmp
) flags
|= TVF_CONTRACT
;
472 GetAttr(GA_Selected
,CH_Toggle
,&tmp
);
473 if (tmp
) flags
|= TVF_TOGGLE
;
479 rc
= BGUI_DoGadgetMethod(TV_Test
,win
,NULL
,method
,
480 NULL
,NewEntry
,entry
,which
,flags
);
484 rc
= BGUI_DoGadgetMethod(TV_Test
,win
,NULL
,method
,
485 NULL
,entry
,RepEntry
,which
,flags
);
489 rc
= DoMethod(TV_Test
,method
,
491 rcstr
= rc
? (STRPTR
) rc
: "NULL";
498 rc
= BGUI_DoGadgetMethod(TV_Test
,win
,NULL
,method
,
499 NULL
,entry
,which
,flags
);
503 rc
= BGUI_DoGadgetMethod(TV_Test
,win
,NULL
,method
,NULL
);
508 KPrintF("ID_BT_TEST1: rc=%08lx (%ld) [%s]\n",rc,rc,rcstr);
513 if (entry
= DoMethod(TV_Test
,TVM_GETENTRY
,
514 TV_SELECTED
,TVW_ENTRY
,0))
517 KPrintF("ID_BT_TEST2: entry=%08lx\n",entry);
519 SetGadgetAttrs((struct Gadget
*) TV_Test
,
520 win
,NULL
,TVA_Top
,entry
,TAG_DONE
);
530 if (sigs
& SIGBREAKF_CTRL_C
)
536 DisposeObject(WI_Main
);
537 DisposeObject(IMG_Contract
);
538 DisposeObject(IMG_Expand
);
540 CloseLibrary(BGUIBase
);
545 /*************************************************************************/
547 //ASM SAVEDS ULONG TVNotifyHandler(REG(a0) struct Hook *hook,
548 // REG(a2) Object *obj, REG(a1) struct opUpdate *opu)
549 ASM SAVEDS
REGFUNC3(ULONG
, TVNotifyHandler
,
550 REGPARAM(A0
, struct Hook
*, hook
),
551 REGPARAM(A2
, Object
*, obj
),
552 REGPARAM(A1
, struct opUpdate
*, opu
))
557 struct TagItem
*tstate
;
560 tstate
= opu
->opu_AttrList
;
562 entry
= (STRPTR
) GetTagData(TVA_Entry
,(ULONG
) "None",tstate
);
565 KPrintF("Test/TVNotify: Entry=%s Flags=%lu\n",entry,opu->opu_Flags);
567 while(tag = NextTagItem(&tstate))
568 KPrintF(" Tag: %08lx Value: %08lx\n",tag->ti_Tag,tag->ti_Data);
575 /************************************************************************
576 *************************** WINDOWHANDLER() ***************************
577 *************************************************************************
578 * Hook for main window IDCMP messages. Called by window object after its
579 * intuimsg processing has finished, before main() gets control. Used
580 * here to provide extra keyboard control not possible using normal
581 * gadget-key assignment, specifically: crsr up/down to select entry in
582 * treeview and ESC to close window.
584 *************************************************************************/
586 //ASM SAVEDS ULONG WindowHandler(REG(a0) struct Hook *hook,
587 // REG(a2) Object *obj, REG(a1) struct IntuiMessage *imsg)
588 ASM SAVEDS
REGFUNC3(ULONG
, WindowHandler
,
589 REGPARAM(A0
, struct Hook
*, hook
),
590 REGPARAM(A2
, Object
*, obj
),
591 REGPARAM(A1
, struct IntuiMessage
*, imsg
))
594 ULONG cursel
,method
,entry
,which
,flags
;
597 view
= (Object
*) hook
->h_Data
;
598 win
= imsg
->IDCMPWindow
;
600 if (imsg
->Class
== IDCMP_RAWKEY
)
603 entry
= (ULONG
) TV_SELECTED
;
605 flags
= TVF_MAKEVISIBLE
;
606 cursel
= DoMethod(view
,TVM_GETENTRY
,TV_SELECTED
,TVW_ENTRY
,0);
608 if (imsg
->Code
== RAW_UPARROW
)
612 which
= TVW_TREE_PREV
;
614 if (imsg
->Qualifier
& SHIFTKEYS
)
615 which
= TVW_TREE_PAGE_UP
;
617 if (imsg
->Qualifier
& CTRLKEY
)
619 entry
= (ULONG
) TV_ROOT
;
620 which
= TVW_CHILD_FIRST
;
625 which
= TVW_CHILD_FIRST
;
626 entry
= (ULONG
) TV_ROOT
;
630 if (imsg
->Code
== RAW_DOWNARROW
)
634 which
= TVW_TREE_NEXT
;
636 if (imsg
->Qualifier
& SHIFTKEYS
)
637 which
= TVW_TREE_PAGE_DOWN
;
639 if (imsg
->Qualifier
& CTRLKEY
)
641 entry
= (ULONG
) TV_ROOT
;
642 which
= TVW_TREE_LAST
;
647 which
= TVW_CHILD_FIRST
;
648 entry
= (ULONG
) TV_ROOT
;
652 if (imsg
->Code
== RAW_RETURN
)
660 BGUI_DoGadgetMethod(view
,win
,NULL
,method
,
661 NULL
,entry
,which
,flags
);
668 /*************************************************************************/
670 struct List
*MakeList(void)
674 static STRPTR TestStrs
[] = {
675 "Hello", "Cruel", "World",
679 if (list
= AllocVec(sizeof(struct List
),MEMF_ANY
|MEMF_CLEAR
))
687 n
= (struct Node
*) 1;
691 if (n
= (struct Node
*) AllocVec(sizeof(struct Node
),MEMF_ANY
|MEMF_CLEAR
))
708 /*************************************************************************/
710 void FreeList(struct List
*list
)
716 while(n
= RemTail(list
))