1 /***************************************************************************
3 NListtree.mcc - New Listtree MUI Custom Class
4 Copyright (C) 1999-2001 by Carsten Scholling
5 Copyright (C) 2001-2014 NList Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 NList classes Support Site: http://www.sf.net/projects/nlist-classes
21 ***************************************************************************/
24 #define MUI_OBSOLETE 1
30 #include <proto/muimaster.h>
31 #include <proto/exec.h>
32 #include <proto/intuition.h>
33 #include <proto/utility.h>
35 #if !defined(__amigaos4__)
36 #include <clib/alib_protos.h>
39 #include <exec/memory.h>
40 #include <exec/types.h>
42 #include <mui/NListtree_mcc.h>
43 #include <mui/NListview_mcc.h>
44 #include <mui/NList_mcc.h>
53 void kprintf( UBYTE
*fmt
, ... );
61 #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
66 #ifndef MUIA_Slider_Level
67 #define MUIA_Slider_Level 0x8042ae3a /* V4 isg LONG */
71 ** Do not use stack sizes below 8KB!!
79 struct Library
*MUIMasterBase
= NULL
;
81 #if defined(__amigaos4__)
82 struct Library
*IntuitionBase
= NULL
;
84 struct IntuitionBase
*IntuitionBase
= NULL
;
87 #if defined(__amigaos4__)
88 struct IntuitionIFace
*IIntuition
= NULL
;
89 struct MUIMasterIFace
*IMUIMaster
= NULL
;
92 struct MUI_NListtree_TreeNode
*tntest
;
97 STATIC APTR app
, window
,lt_nodes
,
98 tx_info1
, tx_info2
, tx_info3
,
99 sl_treecol
, st_string
,
100 bt_open
, bt_close
, bt_expand
, bt_collapse
,
101 bt_insert
, bt_remove
, bt_exchange
,bt_rename
,
102 bt_move
, bt_copy
, bt_moveks
, bt_copyks
,
103 bt_find
, bt_parent
, bt_sort
, bt_getnr
,
104 bt_redraw
, bt_selected
,bt_showtree
,bt_seltogg
,
105 bt_test
, bt_test2
, bt_test3
, bt_test4
;
109 ** Sample tree structure.
117 STATIC
const struct SampleArray sa
[] =
119 { "comp", TNF_LIST
| TNF_OPEN
},
120 { "sys", TNF_LIST
| TNF_OPEN
},
121 { "amiga", TNF_LIST
| TNF_OPEN
},
124 { "system", 0x8000 },
126 {"de", TNF_LIST
| TNF_OPEN
},
127 { "comm", TNF_LIST
},
128 { "software", TNF_LIST
},
130 { "comp", TNF_LIST
| TNF_OPEN
},
131 { "sys", TNF_LIST
| TNF_OPEN
},
132 { "amiga", TNF_LIST
},
137 {"sort test", TNF_LIST
| TNF_OPEN
},
183 { "Sort Test 2", TNF_LIST
},
189 ** This function draws the sample tree structure.
191 STATIC VOID
DrawSampleTree( Object
*ltobj
)
193 struct MUI_NListtree_TreeNode
*tn1
, *tn2
, *tn3
;
197 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, MUIV_NListtree_Insert_ListNode_Root
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
198 tn2
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
199 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn2
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
200 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
201 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn2
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
202 tntest
= tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
204 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, MUIV_NListtree_Insert_ListNode_Root
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
205 tn2
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
206 tn2
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn2
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
207 tn2
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn2
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
208 tn3
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
209 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn3
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
210 tn2
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
211 tn3
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn2
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
212 tn3
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn2
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
213 tn3
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
215 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, MUIV_NListtree_Insert_ListNode_Root
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
217 for( j
= 0; j
< 26; j
++ )
219 DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
222 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, MUIV_NListtree_Insert_ListNode_Root
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
224 for( j
= 0; j
< 11; j
++ )
226 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
229 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, MUIV_NListtree_Insert_ListNode_Root
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
230 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
231 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
234 tn1
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, sa
[i
].name
, (IPTR
)sa
[i
].flags
, MUIV_NListtree_Insert_ListNode_Root
, MUIV_NListtree_Insert_PrevNode_Tail
, sa
[i
].flags
); i
++;
236 for( i
= 0; i
< 2500; i
++ )
238 if ( i
% 2 ) snprintf( txt
, sizeof(txt
), "Sort Entry %d", i
+ 1 );
239 else snprintf( txt
, sizeof(txt
), "Entry Sort %d", i
+ 1 );
241 tn2
= (struct MUI_NListtree_TreeNode
*)DoMethod( ltobj
, MUIM_NListtree_Insert
, txt
, 0, ( i
% 5 ) ? tn2
: tn1
, MUIV_NListtree_Insert_PrevNode_Tail
, ( i
% 5 ) ? TNF_LIST
: 0 );
245 DoMethod( ltobj
, MUIM_NListtree_InsertStruct
, "This/is/a/very/long/test/for/Blafasel_InsertStruct", 0, "/", 0 );
246 DoMethod( ltobj
, MUIM_NListtree_InsertStruct
, "This/is/another/very/long/test/for/Blafasel_InsertStruct", 0, "/", 0 );
251 static struct MUI_NListtree_TreeNode
*GetParent( Object
*obj
, struct MUI_NListtree_TreeNode
*tn
)
255 return( (struct MUI_NListtree_TreeNode
*)DoMethod( obj
, MUIM_NListtree_GetEntry
, MUIV_NListtree_GetEntry_ListNode_Root
, MUIV_NListtree_GetEntry_Position_Parent
, 0 ) );
262 static struct MUI_NListtree_TreeNode
*GetParentNotRoot( Object
*obj
, struct MUI_NListtree_TreeNode
*tn
)
264 if((tn
= GetParent( obj
, tn
)))
266 if ( GetParent( obj
, tn
) )
276 struct MUI_NListtree_TreeNode
*IsXChildOfY( Object
*obj
, struct MUI_NListtree_TreeNode
*x
, struct MUI_NListtree_TreeNode
*y
)
285 while((y
= GetParentNotRoot( obj
, y
)));
293 ** Allocates memory for each entry we create.
295 HOOKPROTONHNO(confunc
, SIPTR
, struct MUIP_NListtree_ConstructMessage
*msg
)
297 struct SampleArray
*sa
;
300 ** Allocate needed piece of memory for the new entry.
302 if((sa
= (struct SampleArray
*)AllocVec( sizeof( struct SampleArray
) + strlen( msg
->Name
) + 1, MEMF_CLEAR
)))
305 ** Save the user data field right after the
308 strcpy( (STRPTR
)&sa
[1], msg
->Name
);
309 sa
->name
= (STRPTR
)&sa
[1];
311 sa
->flags
= (IPTR
)msg
->UserData
;
316 MakeStaticHook(conhook
, confunc
);
320 ** Free memory we just allocated above.
322 HOOKPROTONHNO(desfunc
, LONG
, struct MUIP_NListtree_DestructMessage
*msg
)
324 if ( msg
->UserData
!= NULL
)
326 FreeVec( msg
->UserData
);
327 msg
->UserData
= NULL
;
332 MakeStaticHook(deshook
, desfunc
);
336 ** Compare hook function.
338 HOOKPROTONHNO(compfunc
, LONG
, struct MUIP_NListtree_CompareMessage
*msg
)
340 return( stricmp( msg
->TreeNode1
->tn_Name
, msg
->TreeNode2
->tn_Name
) );
342 MakeStaticHook(comphook
, compfunc
);
346 ** MultiTest hook function.
348 HOOKPROTONHNO(mtfunc
, LONG
, struct MUIP_NListtree_MultiTestMessage
*msg
)
350 if ( msg
->TreeNode
->tn_Flags
& TNF_LIST
)
355 MakeStaticHook(mthook
, mtfunc
);
359 ** Format the entry data for displaying.
361 HOOKPROTONHNO(dspfunc
, LONG
, struct MUIP_NListtree_DisplayMessage
*msg
)
363 STATIC CONST_STRPTR t1
= "Newsgroups", t2
= "Flags", t3
= "subscribed", t4
= "\0", t5
= "Count";
366 if ( msg
->TreeNode
!= NULL
)
369 ** The user data is a pointer to a SampleArray struct.
371 struct SampleArray
*a
= (struct SampleArray
*)msg
->TreeNode
->tn_User
;
373 snprintf( buf
, sizeof(buf
), "%3d", (unsigned int)(IPTR
)msg
->Array
[-1] );
375 *msg
->Array
++ = msg
->TreeNode
->tn_Name
;
376 *msg
->Array
++ = (STRPTR
)(( a
->flags
& 0x8000 ) ? t3
: t4
);
381 *msg
->Array
++ = (STRPTR
)t1
;
382 *msg
->Array
++ = (STRPTR
)t2
;
383 *msg
->Array
++ = (STRPTR
)t5
;
385 *msg
->Preparse
++ = (STRPTR
)"\033b\033u";
386 *msg
->Preparse
++ = (STRPTR
)"\033b\033u";
387 *msg
->Preparse
++ = (STRPTR
)"\033b\033u";
392 MakeStaticHook(dsphook
, dspfunc
);
396 ** Insert a new entry which name is given in
397 ** the string gadget.
399 HOOKPROTONHNP(insertfunc
, LONG
, Object
*obj
)
406 get( st_string
, MUIA_String_Contents
, &x
);
409 ** Insert the new entry after
412 DoMethod( obj
, MUIM_NListtree_Insert
, x
, 0, MUIV_NListtree_Insert_ListNode_Active
,
413 MUIV_NListtree_Insert_PrevNode_Active
, MUIV_NListtree_Insert_Flag_Active
);
417 MakeStaticHook(inserthook
, insertfunc
);
421 ** Exchange two entries.
423 HOOKPROTONH(exchangefunc
, LONG
, Object
*obj
, ULONG
**para
)
425 STATIC
struct MUI_NListtree_TreeNode
*tn1
, *tn2
;
426 STATIC LONG exchcnt
= 0;
428 if ( ( exchcnt
== 0 ) && ( (IPTR
)*para
== 42 ) )
430 get( obj
, MUIA_NListtree_Active
, &tn1
);
432 if ( tn1
!= MUIV_NListtree_Active_Off
)
434 nnset( tx_info3
, MUIA_Text_Contents
, "Select entry to exchange selected entry with." );
440 else if ( exchcnt
== 1 )
442 get( obj
, MUIA_NListtree_Active
, &tn2
);
444 if ( ( tn2
!= MUIV_NListtree_Active_Off
) && ( tn1
!= tn2
) )
446 if ( !IsXChildOfY( obj
, tn1
, tn2
) && !IsXChildOfY( obj
, tn1
, tn2
) )
448 struct MUI_NListtree_ListNode
*ln1
;
450 if((ln1
= (struct MUI_NListtree_ListNode
*)DoMethod( obj
, MUIM_NListtree_GetEntry
, tn1
, MUIV_NListtree_GetEntry_Position_Parent
, 0)))
452 DoMethod( obj
, MUIM_NListtree_Exchange
, ln1
, tn1
, MUIV_NListtree_Exchange_ListNode2_Active
, MUIV_NListtree_Exchange_TreeNode2_Active
, 0 );
454 nnset( tx_info3
, MUIA_Text_Contents
, "Entries successfully exchanged!" );
457 nnset( tx_info3
, MUIA_Text_Contents
, "Something went wrong! Try again to select." );
460 nnset( tx_info3
, MUIA_Text_Contents
, "You can not exchange with childs!" );
463 nnset( tx_info3
, MUIA_Text_Contents
, "You should not exchange an entry with itself!" );
470 MakeStaticHook(exchangehook
, exchangefunc
);
474 ** Rename the selected entry with the name is given in
475 ** the string gadget.
477 HOOKPROTONHNP(renamefunc
, LONG
, Object
*obj
)
479 struct MUI_NListtree_TreeNode
*tn
= NULL
;
485 get( st_string
, MUIA_String_Contents
, &x
);
486 get( obj
, MUIA_NListtree_Active
, &tn
);
489 ** Insert the new entry sorted (compare hook)
490 ** into the active list node.
492 DoMethod( obj
, MUIM_NListtree_Rename
, tn
,
497 MakeStaticHook(renamehook
, renamefunc
);
501 ** Insert a new entry which name is given in
502 ** the string gadget.
504 HOOKPROTONH(movefunc
, LONG
, Object
*obj
, ULONG
**para
)
506 STATIC
struct MUI_NListtree_TreeNode
*tn1
, *tn2
;
507 STATIC LONG movecnt
= 0;
509 if ( ( movecnt
== 0 ) && ( (IPTR
)*para
== 42 ) )
511 get( obj
, MUIA_NListtree_Active
, &tn1
);
513 if ( tn1
!= MUIV_NListtree_Active_Off
)
515 nnset( tx_info3
, MUIA_Text_Contents
, "Select entry to insert after by simple click." );
521 else if ( movecnt
== 1 )
523 get( obj
, MUIA_NListtree_Active
, &tn2
);
525 if ( ( tn2
!= MUIV_NListtree_Active_Off
) && ( tn1
!= tn2
) )
527 if ( !IsXChildOfY( obj
, tn1
, tn2
) && !IsXChildOfY( obj
, tn1
, tn2
) )
529 struct MUI_NListtree_ListNode
*ln1
;
531 if((ln1
= (struct MUI_NListtree_ListNode
*)DoMethod( obj
, MUIM_NListtree_GetEntry
, tn1
, MUIV_NListtree_GetEntry_Position_Parent
, 0)))
533 DoMethod( obj
, MUIM_NListtree_Move
, ln1
, tn1
, MUIV_NListtree_Move_NewListNode_Active
, tn2
, 0 );
535 nnset( tx_info3
, MUIA_Text_Contents
, "Entry successfully moved!" );
538 nnset( tx_info3
, MUIA_Text_Contents
, "Something went wrong! Try again to select destination." );
541 nnset( tx_info3
, MUIA_Text_Contents
, "You can not move childs!" );
544 nnset( tx_info3
, MUIA_Text_Contents
, "You should not move an entry to itself!" );
551 MakeStaticHook(movehook
, movefunc
);
555 ** Insert a new entry which name is given in
556 ** the string gadget.
558 HOOKPROTONH(copyfunc
, LONG
, Object
*obj
, ULONG
**para
)
560 STATIC
struct MUI_NListtree_TreeNode
*tn1
, *tn2
;
561 STATIC LONG copycnt
= 0;
563 if ( ( copycnt
== 0 ) && ( (IPTR
)*para
== 42 ) )
565 get( obj
, MUIA_NListtree_Active
, &tn1
);
567 if ( tn1
!= MUIV_NListtree_Active_Off
)
569 nnset( tx_info3
, MUIA_Text_Contents
, "Select entry to insert after by simple click." );
575 else if ( copycnt
== 1 )
577 get( obj
, MUIA_NListtree_Active
, &tn2
);
579 if ( ( tn2
!= MUIV_NListtree_Active_Off
) && ( tn1
!= tn2
) )
581 struct MUI_NListtree_ListNode
*ln1
;
583 if((ln1
= (struct MUI_NListtree_ListNode
*)DoMethod( obj
, MUIM_NListtree_GetEntry
, tn1
, MUIV_NListtree_GetEntry_Position_Parent
, 0)))
585 DoMethod( obj
, MUIM_NListtree_Copy
, ln1
, tn1
, MUIV_NListtree_Copy_DestListNode_Active
, tn2
, 0 );
587 nnset( tx_info3
, MUIA_Text_Contents
, "Entry successfully copied!" );
590 nnset( tx_info3
, MUIA_Text_Contents
, "Something went wrong! Try again to select destination." );
593 nnset( tx_info3
, MUIA_Text_Contents
, "You should not copy an entry to itself!" );
600 MakeStaticHook(copyhook
, copyfunc
);
604 ** Move KeepStructure
606 HOOKPROTONH(moveksfunc
, LONG
, Object
*obj
, ULONG
**para
)
608 STATIC
struct MUI_NListtree_TreeNode
*tn1
, *tn2
;
609 STATIC LONG movekscnt
= 0;
611 if ( ( movekscnt
== 0 ) && ( (IPTR
)*para
== 42 ) )
613 get( obj
, MUIA_NListtree_Active
, &tn1
);
615 if ( tn1
!= MUIV_NListtree_Active_Off
)
617 nnset( tx_info3
, MUIA_Text_Contents
, "Select entry to make KeepStructure move with." );
623 else if ( movekscnt
== 1 )
625 get( obj
, MUIA_NListtree_Active
, &tn2
);
627 if ( ( tn2
!= MUIV_NListtree_Active_Off
) && ( tn1
!= tn2
) )
629 struct MUI_NListtree_ListNode
*ln1
;
631 if((ln1
= (struct MUI_NListtree_ListNode
*)DoMethod( obj
, MUIM_NListtree_GetEntry
, tn1
, MUIV_NListtree_GetEntry_Position_Parent
, 0)))
633 DoMethod( obj
, MUIM_NListtree_Move
, ln1
, tn1
, MUIV_NListtree_Move_NewListNode_Active
, tn2
, MUIV_NListtree_Move_Flag_KeepStructure
);
635 nnset( tx_info3
, MUIA_Text_Contents
, "Entry successfully moved (structure keeped)" );
638 nnset( tx_info3
, MUIA_Text_Contents
, "Something went wrong! Try again to select destination." );
641 nnset( tx_info3
, MUIA_Text_Contents
, "You should not move an entry to itself!" );
648 MakeStaticHook(movekshook
, moveksfunc
);
651 ** Copy KeepStructure
653 HOOKPROTONH(copyksfunc
, LONG
, Object
*obj
, ULONG
**para
)
655 STATIC
struct MUI_NListtree_TreeNode
*tn1
, *tn2
;
656 STATIC LONG copykscnt
= 0;
658 if ( ( copykscnt
== 0 ) && ( (IPTR
)*para
== 42 ) )
660 get( obj
, MUIA_NListtree_Active
, &tn1
);
662 if ( tn1
!= MUIV_NListtree_Active_Off
)
664 nnset( tx_info3
, MUIA_Text_Contents
, "Select entry to make KeepStructure copy with." );
670 else if ( copykscnt
== 1 )
672 get( obj
, MUIA_NListtree_Active
, &tn2
);
674 if ( ( tn2
!= MUIV_NListtree_Active_Off
) && ( tn1
!= tn2
) )
676 struct MUI_NListtree_ListNode
*ln1
;
678 if((ln1
= (struct MUI_NListtree_ListNode
*)DoMethod( obj
, MUIM_NListtree_GetEntry
, tn1
, MUIV_NListtree_GetEntry_Position_Parent
, 0)))
680 DoMethod( obj
, MUIM_NListtree_Copy
, ln1
, tn1
, MUIV_NListtree_Copy_DestListNode_Active
, tn2
, MUIV_NListtree_Copy_Flag_KeepStructure
);
682 nnset( tx_info3
, MUIA_Text_Contents
, "Entry successfully copied (structure keeped)" );
685 nnset( tx_info3
, MUIA_Text_Contents
, "Something went wrong! Try again to select destination." );
688 nnset( tx_info3
, MUIA_Text_Contents
, "You should not copy an entry to itself!" );
695 MakeStaticHook(copykshook
, copyksfunc
);
698 HOOKPROTONHNO(fudf
, LONG
, struct MUIP_NListtree_FindUserDataMessage
*msg
)
700 nnset( tx_info1
, MUIA_Text_Contents
, "FindUserData Hook passed!" );
701 return( strncmp( (STRPTR
)msg
->User
, (STRPTR
)msg
->UserData
, strlen( (STRPTR
)msg
->User
) ) );
703 MakeStaticHook(fudh
, fudf
);
706 ** Find the specified tree node by name.
708 HOOKPROTONHNP(findnamefunc
, LONG
, Object
*obj
)
710 struct MUI_NListtree_TreeNode
*tn
;
714 ** Let us see, which string the user wants to search for...
716 get( st_string
, MUIA_String_Contents
, &x
);
719 ** Is it somewhere in the tree?
721 if((tn
= (struct MUI_NListtree_TreeNode
*)DoMethod(obj
, MUIM_NListtree_FindUserData
, MUIV_NListtree_FindUserData_ListNode_Root
, x
, MUIV_NListtree_FindUserData_Flag_Activate
)))
724 ** Found! Inform the user.
726 nnset( tx_info3
, MUIA_Text_Contents
, "Found your node!" );
731 ** Not found. Inform the user.
733 nnset( tx_info3
, MUIA_Text_Contents
, "NOT found specified node!" );
738 MakeStaticHook(findnamehook
, findnamefunc
);
742 ** Sort the active list.
744 HOOKPROTONHNP(sortfunc
, LONG
, Object
*obj
)
749 get( obj
, MUIA_NListtree_Active
, &lastactive
);
750 set( obj
, MUIA_NListtree_Active
, MUIV_NListtree_Active_Off
);
753 DoMethod( obj
, MUIM_NListtree_Sort
, lastactive
, 0 );
756 set( obj
, MUIA_NListtree_Active
, lastactive
);
758 DoMethod( tx_info3
, MUIM_SetAsString
, MUIA_Text_Contents
, "Sort took %ld.%03lds", ( end
- start
) / CLOCKS_PER_SEC
, ( end
- start
) % CLOCKS_PER_SEC
);
762 MakeStaticHook(sorthook
, sortfunc
);
766 ** Find the specified tree node by name.
768 HOOKPROTONHNP(getnrfunc
, LONG
, Object
*obj
)
772 temp
= DoMethod( obj
, MUIM_NListtree_GetNr
,
773 MUIV_NListtree_GetNr_TreeNode_Active
, MUIV_NListtree_GetNr_Flag_CountLevel
);
776 DoMethod( tx_info1
, MUIM_SetAsString
, MUIA_Text_Contents
, "1 entry in parent node." );
778 DoMethod( tx_info1
, MUIM_SetAsString
, MUIA_Text_Contents
, "%ld entries in parent node.", temp
);
781 temp
= DoMethod( obj
, MUIM_NListtree_GetNr
,
782 MUIV_NListtree_GetNr_TreeNode_Active
, MUIV_NListtree_GetNr_Flag_CountAll
);
785 DoMethod( tx_info2
, MUIM_SetAsString
, MUIA_Text_Contents
, "1 entry total." );
787 DoMethod( tx_info2
, MUIM_SetAsString
, MUIA_Text_Contents
, "%ld entries total.", temp
);
790 temp
= DoMethod( obj
, MUIM_NListtree_GetNr
,
791 MUIV_NListtree_GetNr_TreeNode_Active
, 0 );
793 temp2
= DoMethod( obj
, MUIM_NListtree_GetNr
,
794 MUIV_NListtree_GetNr_TreeNode_Active
, MUIV_NListtree_GetNr_Flag_Visible
);
796 DoMethod( tx_info3
, MUIM_SetAsString
, MUIA_Text_Contents
, "Active entry pos: %ld (visible: %ld).", temp
, temp2
);
800 MakeStaticHook(getnrhook
, getnrfunc
);
803 ** Find the specified tree node by name.
805 HOOKPROTONHNP(numselfunc
, LONG
, Object
*obj
)
809 DoMethod( obj
, MUIM_NListtree_Select
, MUIV_NListtree_Select_All
,
810 MUIV_NListtree_Select_Ask
, 0, &temp
);
813 DoMethod( tx_info1
, MUIM_SetAsString
, MUIA_Text_Contents
, "1 node selected." );
815 DoMethod( tx_info1
, MUIM_SetAsString
, MUIA_Text_Contents
, "%ld nodes selected.", temp
);
818 struct MUI_NListtree_TreeNode
*tn
;
820 tn
= (struct MUI_NListtree_TreeNode
*)MUIV_NListtree_NextSelected_Start
;
824 DoMethod( obj
, MUIM_NListtree_NextSelected
, &tn
);
826 if ( (IPTR
)tn
== (IPTR
)MUIV_NListtree_NextSelected_End
)
829 D(bug( "Next TreeNode: 0x%08lx - %s\n", tn
, tn
->tn_Name
) );
834 tn
= (struct MUI_NListtree_TreeNode
*)MUIV_NListtree_PrevSelected_Start
;
838 DoMethod( obj
, MUIM_NListtree_PrevSelected
, &tn
);
840 if ( (IPTR
)tn
== (IPTR
)MUIV_NListtree_PrevSelected_End
)
843 D(bug( "Prev TreeNode: 0x%08lx - %s\n", tn
, tn
->tn_Name
) );
849 MakeStaticHook(numselhook
, numselfunc
);
854 HOOKPROTONHNP(testfunc
, LONG
, Object
*obj
)
859 id
= MUIV_NListtree_NextSelected_Start
;
863 DoMethod( obj
, MUIM_NListtree_NextSelected
, &id
);
865 if(id
== (SIPTR
)MUIV_NListtree_NextSelected_End
)
868 //GetAttr( MUIA_List_Entries, obj, &num );
870 num
= DoMethod( obj
, MUIM_NListtree_GetNr
,
871 MUIV_NListtree_GetNr_TreeNode_Active
, MUIV_NListtree_GetNr_Flag_CountAll
);
874 DoMethod( obj
, MUIM_NListtree_Remove
, MUIV_NListtree_Remove_ListNode_Active
, id
, 0 );
881 MakeStaticHook(testhook
, testfunc
);
884 #if defined(__amigaos4__)
885 #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL))
886 #define DROPINTERFACE(iface) (DropInterface((struct Interface *)iface), iface = NULL)
888 #define GETINTERFACE(iface, base) TRUE
889 #define DROPINTERFACE(iface)
895 int main(UNUSED
int argc
, UNUSED
char *argv
[])
898 static const char *const UsedClasses
[] = {
906 ** Is MUI V19 available?
908 if((IntuitionBase
= (APTR
)OpenLibrary("intuition.library", 36)) &&
909 GETINTERFACE(IIntuition
, IntuitionBase
))
910 if((MUIMasterBase
= OpenLibrary("muimaster.library", 19)) &&
911 GETINTERFACE(IMUIMaster
, MUIMasterBase
))
914 ** Create application object.
916 app
= ApplicationObject
,
917 MUIA_Application_Title
, "NListtree-Demo",
918 MUIA_Application_Version
, "$VER: NListtree-Demo 1.0 (" __DATE__
")",
919 MUIA_Application_Copyright
, "(C) 2001-2014 NList Open Source Team",
920 MUIA_Application_Author
, "NList Open Source Team",
921 MUIA_Application_Description
, "Demonstration program for MUI class NListtree.mcc",
922 MUIA_Application_Base
, "NLISTTREEDEMO",
923 MUIA_Application_UsedClasses
, UsedClasses
,
928 SubWindow
, window
= WindowObject
,
929 MUIA_Window_Title
, "NListtree-Demo",
930 MUIA_Window_ID
, MAKE_ID( 'N', 'L', 'T', 'R' ),
931 MUIA_Window_AppWindow
, TRUE
,
932 WindowContents
, VGroup
,
935 ** Create a NListview embedded NListtree object
937 Child
, NListviewObject
,
938 MUIA_ShortHelp
, "The NListtree object...",
939 MUIA_NListview_NList
, lt_nodes
= NListtreeObject
,
941 MUIA_CycleChain
, TRUE
,
942 MUIA_NList_MinLineHeight
, 18,
943 MUIA_NListtree_MultiSelect
, MUIV_NListtree_MultiSelect_Shifted
,
944 MUIA_NListtree_MultiTestHook
, &mthook
,
945 MUIA_NListtree_DisplayHook
, &dsphook
,
946 MUIA_NListtree_ConstructHook
, &conhook
,
947 MUIA_NListtree_DestructHook
, &deshook
, /* This is the same as MUIV_NListtree_CompareHook_LeavesMixed. */
948 MUIA_NListtree_CompareHook
, &comphook
,
949 MUIA_NListtree_DoubleClick
, MUIV_NListtree_DoubleClick_Tree
,
950 MUIA_NListtree_EmptyNodes
, FALSE
,
951 MUIA_NListtree_TreeColumn
, 0,
952 MUIA_NListtree_DragDropSort
, TRUE
,
953 MUIA_NListtree_Title
, TRUE
,
954 MUIA_NListtree_Format
, ",,",
955 MUIA_NListtree_FindUserDataHook
,&fudh
,
956 //MUIA_NListtree_NoRootTree, TRUE,
961 ** Build some controls.
963 Child
, tx_info1
= TextObject
,
964 MUIA_Background
, MUII_TextBack
,
968 Child
, tx_info2
= TextObject
,
969 MUIA_Background
, MUII_TextBack
,
973 Child
, tx_info3
= TextObject
,
974 MUIA_Background
, MUII_TextBack
,
978 Child
, ColGroup( 2 ),
979 Child
, FreeKeyLabel( "TreeCol:", 'c' ),
980 Child
, sl_treecol
= Slider( 0, 2, 0 ),
984 Child
, st_string
= StringObject
,
986 MUIA_String_MaxLen
, 50,
991 Child
, ColGroup( 4 ),
992 Child
, bt_open
= KeyButton( "Open", 'o' ),
993 Child
, bt_close
= KeyButton( "Close", 'c' ),
994 Child
, bt_expand
= KeyButton( "Expand", 'e' ),
995 Child
, bt_collapse
= KeyButton( "Collapse", 'a' ),
997 Child
, bt_insert
= KeyButton( "Insert", 'i' ),
998 Child
, bt_remove
= KeyButton( "Remove", 'r' ),
999 Child
, bt_exchange
= KeyButton( "Exchange", 'x' ),
1000 Child
, bt_rename
= KeyButton( "Rename", 'r' ),
1002 Child
, bt_move
= KeyButton( "Move", 'm' ),
1003 Child
, bt_copy
= KeyButton( "Copy", 'y' ),
1004 Child
, bt_moveks
= KeyButton( "Move KS", 'v' ),
1005 Child
, bt_copyks
= KeyButton( "Copy KS", 'k' ),
1007 Child
, bt_find
= KeyButton( "FindName", 'f' ),
1008 Child
, bt_parent
= KeyButton( "Parent", 'p' ),
1009 Child
, bt_sort
= KeyButton( "Sort", 's' ),
1010 Child
, bt_getnr
= KeyButton( "GetNr", 'n' ),
1012 Child
, bt_redraw
= KeyButton( "Redraw", 'w' ),
1013 Child
, bt_selected
= KeyButton( "Selected", 'd' ),
1014 Child
, bt_seltogg
= KeyButton( "Sel Togg", 't' ),
1015 Child
, bt_showtree
= KeyButton( "Show tree", 'h' ),
1017 Child
, bt_test
= KeyButton( "Test", ' ' ),
1018 Child
, bt_test2
= KeyButton( "Test2", ' ' ),
1019 Child
, bt_test3
= KeyButton( "Test3", ' ' ),
1020 Child
, bt_test4
= KeyButton( "Test4", ' ' ),
1032 ** generate notifications
1034 DoMethod( window
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
1035 app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
1038 ** open/close/expand/collapse
1040 DoMethod( bt_open
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1041 lt_nodes
, 4, MUIM_NListtree_Open
, MUIV_NListtree_Open_ListNode_Active
, MUIV_NListtree_Open_TreeNode_Active
, 0 );
1043 DoMethod( bt_close
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1044 lt_nodes
, 4, MUIM_NListtree_Close
, MUIV_NListtree_Close_ListNode_Active
, MUIV_NListtree_Close_TreeNode_Active
, 0 );
1046 DoMethod( bt_expand
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1047 lt_nodes
, 4, MUIM_NListtree_Open
, MUIV_NListtree_Open_ListNode_Root
, MUIV_NListtree_Open_TreeNode_All
, 0 );
1049 DoMethod( bt_collapse
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1050 lt_nodes
, 4, MUIM_NListtree_Close
, MUIV_NListtree_Close_ListNode_Root
, MUIV_NListtree_Close_TreeNode_All
, 0 );
1055 ** insert/remove/exchange/rename
1057 DoMethod( bt_insert
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1058 lt_nodes
, 2, MUIM_CallHook
, &inserthook
);
1060 DoMethod( bt_remove
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1061 lt_nodes
, 4, MUIM_NListtree_Remove
, MUIV_NListtree_Remove_ListNode_Root
, MUIV_NListtree_Remove_TreeNode_Selected
, 0 );
1063 DoMethod( bt_exchange
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1064 lt_nodes
, 3, MUIM_CallHook
, &exchangehook
, 42 );
1066 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_Active
, MUIV_EveryTime
,
1067 lt_nodes
, 3, MUIM_CallHook
, &exchangehook
, 0 );
1069 DoMethod( bt_rename
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1070 lt_nodes
, 2, MUIM_CallHook
, &renamehook
);
1074 ** move/copy/moveks/copyks
1076 DoMethod( bt_move
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1077 lt_nodes
, 3, MUIM_CallHook
, &movehook
, 42 );
1079 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_Active
, MUIV_EveryTime
,
1080 lt_nodes
, 3, MUIM_CallHook
, &movehook
, 0 );
1082 DoMethod( bt_copy
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1083 lt_nodes
, 3, MUIM_CallHook
, ©hook
, 42 );
1085 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_Active
, MUIV_EveryTime
,
1086 lt_nodes
, 3, MUIM_CallHook
, ©hook
, 0 );
1088 DoMethod( bt_moveks
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1089 lt_nodes
, 3, MUIM_CallHook
, &movekshook
, 42 );
1091 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_Active
, MUIV_EveryTime
,
1092 lt_nodes
, 3, MUIM_CallHook
, &movekshook
, 0 );
1094 DoMethod( bt_copyks
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1095 lt_nodes
, 3, MUIM_CallHook
, ©kshook
, 42 );
1097 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_Active
, MUIV_EveryTime
,
1098 lt_nodes
, 3, MUIM_CallHook
, ©kshook
, 0 );
1102 ** find/parent/sort/getnr
1104 DoMethod( bt_find
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1105 lt_nodes
, 2, MUIM_CallHook
, &findnamehook
);
1107 DoMethod( bt_parent
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1108 lt_nodes
, 3, MUIM_Set
, MUIA_NListtree_Active
, MUIV_NListtree_Active_Parent
);
1110 DoMethod( bt_sort
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1111 lt_nodes
, 2, MUIM_CallHook
, &sorthook
);
1114 DoMethod( bt_sort, MUIM_Notify, MUIA_Pressed, FALSE,
1115 lt_nodes, 3, MUIM_NListtree_Sort, MUIV_NListtree_Sort_TreeNode_Active, 0 );
1118 DoMethod( bt_getnr
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1119 lt_nodes
, 2, MUIM_CallHook
, &getnrhook
);
1123 ** redraw/selected/seltogg/showtree
1125 DoMethod( bt_redraw
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1126 lt_nodes
, 3, MUIM_NListtree_Redraw
, MUIV_NListtree_Redraw_All
);
1128 DoMethod( bt_selected
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1129 lt_nodes
, 2, MUIM_CallHook
, &numselhook
);
1131 DoMethod( bt_seltogg
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1132 lt_nodes
, 5, MUIM_NListtree_Select
, MUIV_NListtree_Select_All
, MUIV_NListtree_Select_Toggle
, 0, NULL
);
1134 DoMethod( bt_showtree
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1135 lt_nodes
, 3, MUIM_Set
, MUIA_NListtree_ShowTree
, MUIV_NListtree_ShowTree_Toggle
);
1141 DoMethod( sl_treecol
, MUIM_Notify
, MUIA_Slider_Level
, MUIV_EveryTime
,
1142 lt_nodes
, 3, MUIM_Set
, MUIA_NListtree_TreeColumn
, MUIV_TriggerValue
);
1144 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_Active
, MUIV_EveryTime
,
1145 tx_info1
, 4, MUIM_SetAsString
, MUIA_Text_Contents
, "Active node: 0x%08lx", MUIV_TriggerValue
);
1147 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_ActiveList
, MUIV_EveryTime
,
1148 tx_info2
, 4, MUIM_SetAsString
, MUIA_Text_Contents
, "Active list: 0x%08lx", MUIV_TriggerValue
);
1150 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_DoubleClick
, MUIV_EveryTime
,
1151 tx_info3
, 4, MUIM_SetAsString
, MUIA_Text_Contents
, "Double clicked on node: 0x%08lx", MUIV_TriggerValue
);
1153 DoMethod( lt_nodes
, MUIM_Notify
, MUIA_NListtree_SelectChange
, TRUE
,
1154 tx_info3
, 3, MUIM_SetAsString
, MUIA_Text_Contents
, "Selection state changed" );
1160 DoMethod( bt_test
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
1161 lt_nodes
, 2, MUIM_CallHook
, &testhook
);
1169 set( window
, MUIA_Window_Open
, TRUE
);
1173 ** Set the tree into quiet state.
1175 set( lt_nodes
, MUIA_NListtree_Quiet
, TRUE
);
1179 ** Insert sample nodes.
1181 DrawSampleTree( lt_nodes
);
1185 ** Set the tree back to normal state.
1187 set( lt_nodes
, MUIA_NListtree_Quiet
, FALSE
);
1190 ** Minimal input loop.
1192 while((LONG
)DoMethod( app
, MUIM_Application_NewInput
, &signals
) != (LONG
)MUIV_Application_ReturnID_Quit
)
1196 signals
= Wait( signals
| SIGBREAKF_CTRL_C
);
1198 if ( signals
& SIGBREAKF_CTRL_C
)
1206 DoMethod( lt_nodes
, MUIM_NListtree_Clear
, NULL
, 0 );
1210 ** Close the window.
1212 set( window
, MUIA_Window_Open
, FALSE
);
1218 MUI_DisposeObject( app
);
1221 printf( "Failed to create Application.\n" );
1226 DROPINTERFACE(IMUIMaster
);
1227 CloseLibrary(MUIMasterBase
);
1232 DROPINTERFACE(IIntuition
);
1233 CloseLibrary((struct Library
*)IntuitionBase
);