home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / AACD / Programming / MCC_NListtree / Developer / C / Examples / NListtree-Demo.c < prev   
Encoding:
C/C++ Source or Header  |  2001-02-24  |  34.9 KB  |  1,250 lines

  1. /******************************************************************************\
  2. ********************************************************************************
  3. ***
  4. ***    NListtree.mcc    Copyright (c) 1999-2000 by Apocalypse Hard- and Software
  5. ***                    Carsten Scholling
  6. ***
  7. ***    Example program for MUI class NListtree.mcc
  8. ***
  9. ***
  10. ***    Please do not use this "to be rewritten"-piece of software as an
  11. ***    information resource on how to write programs in an object oriented
  12. ***    MUI environment. It simply shows how to use some of the NListtree
  13. ***    functions.
  14. ***
  15. ***
  16. ********************************************************************************
  17. \******************************************************************************/
  18.  
  19.  
  20. /*
  21. **    Includes
  22. */
  23. #ifdef __SASC
  24.  #include <pragmas/muimaster_pragmas.h>
  25.  #include <pragmas/intuition_pragmas.h>
  26.  #include <pragmas/graphics_pragmas.h>
  27.  #include <pragmas/exec_pragmas.h>
  28.  
  29.  #include <clib/muimaster_protos.h>
  30.  #include <clib/exec_protos.h>
  31.  #include <clib/alib_protos.h>
  32. #else
  33.  #ifdef __GNUC__
  34.   #include <proto/muimaster.h>
  35.   #include <proto/exec.h>
  36.  #endif
  37. #endif
  38.  
  39. #include <exec/memory.h>
  40. #include <exec/types.h>
  41.  
  42. #include <mui/nlisttree_mcc.h>
  43. #include <mui/nlistview_mcc.h>
  44. #include <mui/nlist_mcc.h>
  45. #include <libraries/mui.h>
  46.  
  47. #include <string.h>
  48. #include <stdio.h>
  49.  
  50. #include "Compiler.h"
  51.  
  52. #ifdef MYDEBUG
  53.  #ifdef __APHASO__
  54.   #include <Debug.h>
  55.  #else
  56.   #define bug kprintf
  57.   #define D(x)
  58.   void kprintf( UBYTE *fmt, ... );
  59.  #endif
  60. #else
  61.  #define bug
  62.  #define D(x)
  63. #endif
  64.  
  65.  
  66. #ifndef MAKE_ID
  67. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  68. #endif
  69.  
  70.  
  71. /*
  72. **    Do not use stack sizes below 8KB!!
  73. */
  74. LONG __stack = 16384;
  75.  
  76.  
  77. /*
  78. **    MUI library base.
  79. */
  80. struct Library *MUIMasterBase;
  81. struct IntuitionBase *IntuitionBase;
  82.  
  83. struct MUI_NListtree_TreeNode *tntest;
  84.  
  85. /*
  86. **    MUI objects.
  87. */
  88. STATIC APTR        app, window,lt_nodes,
  89.                 tx_info1,    tx_info2,    tx_info3,
  90.                 sl_treecol,    st_string,
  91.                 bt_open,    bt_close,    bt_expand,    bt_collapse,
  92.                 bt_insert,    bt_remove,    bt_exchange,bt_rename,
  93.                 bt_move,    bt_copy,    bt_moveks,    bt_copyks,
  94.                 bt_find,    bt_parent,    bt_sort,    bt_getnr,
  95.                 bt_redraw,    bt_selected,bt_showtree,bt_seltogg;
  96.  
  97.  
  98. /*
  99. **    Sample tree structure.
  100. */
  101. struct SampleArray {
  102.     STRPTR    name;
  103.     UWORD   flags;
  104. };
  105.  
  106. STATIC const struct SampleArray sa[] =
  107. {
  108.     "comp", TNF_LIST | TNF_OPEN,
  109.         "sys", TNF_LIST | TNF_OPEN,
  110.             "amiga", TNF_LIST | TNF_OPEN,
  111.                 "misc", 0x8000,
  112.             "mac", TNF_LIST,
  113.                 "system", 0x8000,
  114.  
  115.     "de", TNF_LIST | TNF_OPEN,
  116.         "comm", TNF_LIST,
  117.             "software", TNF_LIST,
  118.                 "ums", 0x8000,
  119.         "comp", TNF_LIST | TNF_OPEN,
  120.             "sys", TNF_LIST | TNF_OPEN,
  121.                 "amiga", TNF_LIST,
  122.                     "misc", 0x8000,
  123.                     "tech", 0x8000,
  124.                 "amiga", 0x8000,
  125.  
  126.     "sort test", TNF_LIST | TNF_OPEN,
  127.         "a", 0,
  128.         "x", TNF_LIST,
  129.         "v", 0,
  130.         "g", TNF_LIST,
  131.         "h", 0,
  132.         "k", TNF_LIST,
  133.         "u", 0,
  134.         "i", TNF_LIST,
  135.         "t", 0,
  136.         "e", TNF_LIST,
  137.         "q", 0,
  138.         "s", TNF_LIST,
  139.         "c", 0,
  140.         "f", TNF_LIST,
  141.         "p", 0,
  142.         "l", TNF_LIST,
  143.         "z", 0,
  144.         "w", TNF_LIST,
  145.         "b", 0,
  146.         "o", TNF_LIST,
  147.         "d", 0,
  148.         "m", TNF_LIST,
  149.         "r", 0,
  150.         "y", TNF_LIST,
  151.         "n", 0,
  152.         "j", TNF_LIST,
  153.  
  154.  
  155.     "m", TNF_LIST,
  156.         "i", TNF_LIST,
  157.             "c", TNF_LIST,
  158.                 "h", TNF_LIST,
  159.                     "e", TNF_LIST,
  160.                         "l", TNF_LIST,
  161.                             "a", TNF_LIST,
  162.                                 "n", TNF_LIST,
  163.                                     "g", TNF_LIST,
  164.                                         "e", TNF_LIST,
  165.                                             "l", TNF_LIST,
  166.                                                 "o", 0,
  167.  
  168.     "end", TNF_LIST,
  169.         "of", TNF_LIST,
  170.             "tree", 0,
  171.  
  172.     NULL, 0
  173. };
  174.  
  175.  
  176.  
  177. #ifdef MORPHOS
  178. #undef MUI_NewObject
  179. #undef MUI_MakeObject
  180.  
  181. #define DoMethod(obj, tags...)                ({ULONG _tags[] = { tags }; DoMethodA((obj), (APTR)_tags);})
  182. #define DoSuperMethod(cl, obj, tags...)        ({ULONG _tags[] = { tags }; DoSuperMethodA((cl), (obj), (APTR)_tags);})
  183. #define CoerceMethod(cl, obj, tags...)        ({ULONG _tags[] = { tags }; CoerceMethodA((cl), (obj), (APTR)_tags);})
  184.  
  185. Object *MUI_NewObject(char *classname, Tag tag1,...)
  186. {
  187.     ULONG mav[50];
  188.     va_list tags;
  189.     int i=0;
  190.  
  191.     mav[i] = tag1;
  192.     if(mav[i] != TAG_DONE)
  193.     {
  194.         va_start(tags, tag1);
  195.         mav[++i] = va_arg(tags, ULONG);
  196.         i++;
  197.         while(i<50)
  198.         {
  199.             mav[i] = va_arg(tags, ULONG);
  200.             if(mav[i] == TAG_DONE) break;
  201.             mav[++i] = va_arg(tags, ULONG);
  202.             i++;
  203.         }
  204.         va_end(tags);
  205.     }
  206.     return(MUI_NewObjectA(classname, (struct TagItem *)&mav));
  207. }
  208.  
  209. Object *MUI_MakeObject(long type, ...)
  210. {
  211.     ULONG mav[15];
  212.     va_list tags;
  213.     int i=0;
  214.  
  215.     va_start(tags, type);
  216.     while(i<10)
  217.     {
  218.         mav[i] = va_arg(tags, ULONG);
  219.         i++;
  220.     }
  221.     va_end(tags);
  222.  
  223.     return(MUI_MakeObjectA(type, (ULONG *)&mav));
  224. }
  225.  
  226. #endif
  227.  
  228.  
  229.  
  230. /*
  231. **    Prototypes and hooks.
  232. */
  233. LONG SAVEDS ASM confunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_ConstructMessage *msg GNUCREG(a1) );
  234. STATIC struct Hook conhook = { {NULL, NULL}, (void *)confunc, NULL, NULL };
  235.  
  236. LONG SAVEDS ASM desfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_DestructMessage *msg GNUCREG(a1) );
  237. STATIC struct Hook deshook = { {NULL, NULL}, (void *)desfunc, NULL, NULL };
  238.  
  239. LONG SAVEDS ASM mtfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_MultiTestMessage *msg GNUCREG(a1) );
  240. STATIC struct Hook mthook = { {NULL, NULL}, (void *)mtfunc, NULL, NULL };
  241.  
  242. LONG SAVEDS ASM dspfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_DisplayMessage *msg GNUCREG(a1) );
  243. STATIC struct Hook dsphook = { { NULL,NULL }, (void *)dspfunc, NULL, NULL };
  244.  
  245. LONG SAVEDS ASM compfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_CompareMessage *msg GNUCREG(a1) );
  246. STATIC struct Hook comphook = { {NULL, NULL}, (void *)compfunc, NULL, NULL };
  247.  
  248. LONG SAVEDS ASM insertfunc( REG(a2) APTR obj GNUCREG(a2) );
  249. STATIC struct Hook inserthook = { {NULL, NULL}, (void *)insertfunc, NULL, NULL };
  250.  
  251. LONG SAVEDS ASM exchangefunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) );
  252. STATIC struct Hook exchangehook = { {NULL, NULL}, (void *)exchangefunc, NULL, NULL };
  253.  
  254. LONG SAVEDS ASM renamefunc( REG(a2) APTR obj GNUCREG(a2) );
  255. STATIC struct Hook renamehook = { {NULL, NULL}, (void *)renamefunc, NULL, NULL };
  256.  
  257. LONG SAVEDS ASM movefunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) );
  258. STATIC struct Hook movehook = { {NULL, NULL}, (void *)movefunc, NULL, NULL };
  259.  
  260. LONG SAVEDS ASM copyfunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) );
  261. STATIC struct Hook copyhook = { {NULL, NULL}, (void *)copyfunc, NULL, NULL };
  262.  
  263. LONG SAVEDS ASM moveksfunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) );
  264. STATIC struct Hook movekshook = { {NULL, NULL}, (void *)moveksfunc, NULL, NULL };
  265.  
  266. LONG SAVEDS ASM copyksfunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) );
  267. STATIC struct Hook copykshook = { {NULL, NULL}, (void *)copyksfunc, NULL, NULL };
  268.  
  269. LONG SAVEDS ASM findnamefunc( REG(a2) APTR obj GNUCREG(a2) );
  270. STATIC struct Hook findnamehook = { {NULL, NULL}, (void *)findnamefunc, NULL, NULL };
  271.  
  272. LONG SAVEDS ASM getnrfunc( REG(a2) APTR obj GNUCREG(a2) );
  273. STATIC struct Hook getnrhook = { {NULL, NULL}, (void *)getnrfunc, NULL, NULL };
  274.  
  275. LONG SAVEDS ASM numselfunc( REG(a2) APTR obj GNUCREG(a2) );
  276. STATIC struct Hook numselhook = { {NULL, NULL}, (void *)numselfunc, NULL, NULL };
  277.  
  278. LONG SAVEDS ASM testfunc( REG(a2) APTR obj GNUCREG(a2) );
  279. STATIC struct Hook testhook = { {NULL, NULL}, (void *)testfunc, NULL, NULL };
  280.  
  281.  
  282.  
  283.  
  284. /*
  285. **    This function draws the sample tree structure.
  286. */
  287. STATIC VOID DrawSampleTree( Object *ltobj )
  288. {
  289.     struct MUI_NListtree_TreeNode *tn1, *tn2, *tn3;
  290.     WORD i = 0, j;
  291.  
  292.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  293.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  294.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  295.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  296.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  297.     tntest = tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  298.  
  299.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  300.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  301.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  302.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  303.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  304.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn3, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  305.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  306.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  307.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  308.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  309.  
  310.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  311.  
  312.     for( j = 0; j < 26; j++ )
  313.     {
  314.         DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  315.     }
  316.  
  317.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  318.  
  319.     for( j = 0; j < 11; j++ )
  320.     {
  321.         tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  322.     }
  323.  
  324.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  325.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  326.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  327.  
  328.  
  329.     DoMethod( ltobj, MUIM_NListtree_InsertStruct, "This/is/a/very/long/test/for/Blafasel_InsertStruct", 0, "/", 0 );
  330.     DoMethod( ltobj, MUIM_NListtree_InsertStruct, "This/is/another/very/long/test/for/Blafasel_InsertStruct", 0, "/", 0 );
  331. }
  332.  
  333.  
  334.  
  335. __inline struct MUI_NListtree_TreeNode *GetParent( Object *obj, struct MUI_NListtree_TreeNode *tn )
  336. {
  337.     if ( tn != NULL )
  338.     {
  339.         return( (struct MUI_NListtree_TreeNode *)DoMethod( obj, MUIM_NListtree_GetEntry, MUIV_NListtree_GetEntry_ListNode_Root, MUIV_NListtree_GetEntry_Position_Parent, 0 ) );
  340.     }
  341.  
  342.     return( NULL );
  343. }
  344.  
  345.  
  346. __inline struct MUI_NListtree_TreeNode *GetParentNotRoot( Object *obj, struct MUI_NListtree_TreeNode *tn )
  347. {
  348.     if ( tn = GetParent( obj, tn ) )
  349.     {
  350.         if ( GetParent( obj, tn ) )
  351.         {
  352.             return( tn );
  353.         }
  354.     }
  355.  
  356.     return( NULL );
  357. }
  358.  
  359.  
  360. struct MUI_NListtree_TreeNode *IsXChildOfY( Object *obj, struct MUI_NListtree_TreeNode *x, struct MUI_NListtree_TreeNode *y )
  361. {
  362.     do
  363.     {
  364.         if ( y == x )
  365.         {
  366.             return( y );
  367.         }
  368.     }
  369.     while( y = GetParentNotRoot( obj, y ) );
  370.  
  371.     return( NULL );
  372. }
  373.  
  374.  
  375.  
  376. /*
  377. **    Allocates memory for each entry we create.
  378. */
  379. LONG ASM SAVEDS confunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_ConstructMessage *msg GNUCREG(a1) )
  380. {
  381.     struct SampleArray *sa;
  382.  
  383.     /*
  384.     **    Allocate needed piece of memory for the new entry.
  385.     */
  386.     if ( sa = (struct SampleArray *)AllocVec( sizeof( struct SampleArray) + strlen( msg->Name ) + 1, MEMF_CLEAR ) )
  387.     {
  388.         /*
  389.         **    Save the user data field right after the
  390.         **    array structure.
  391.         */
  392.         strcpy( (STRPTR)&sa[1], msg->Name );
  393.         sa->name = (STRPTR)&sa[1];
  394.  
  395.         sa->flags = (UWORD)msg->UserData;
  396.     }
  397.  
  398.     return( (LONG)sa );
  399. }
  400.  
  401.  
  402.  
  403. /*
  404. **    Free memory we just allocated above.
  405. */
  406. LONG ASM SAVEDS desfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_DestructMessage *msg GNUCREG(a1) )
  407. {
  408.     if ( msg->UserData != NULL )
  409.     {
  410.         FreeVec( msg->UserData );
  411.         msg->UserData = NULL;
  412.     }
  413.  
  414.     return( 0 );
  415. }
  416.  
  417.  
  418.  
  419. /*
  420. **    Compare hook function.
  421. */
  422. LONG ASM SAVEDS compfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_CompareMessage *msg GNUCREG(a1) )
  423. {
  424.     return( stricmp( msg->TreeNode1->tn_Name, msg->TreeNode2->tn_Name ) );
  425. }
  426.  
  427.  
  428. /*
  429. **    MultiTest hook function.
  430. */
  431. LONG ASM SAVEDS mtfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_MultiTestMessage *msg GNUCREG(a1) )
  432. {
  433.     if ( msg->TreeNode->tn_Flags & TNF_LIST )
  434.         return( FALSE );
  435.  
  436.     return( TRUE );
  437. }
  438.  
  439.  
  440.  
  441. /*
  442. **    Format the entry data for displaying.
  443. */
  444. LONG ASM SAVEDS dspfunc( REG(a0) struct Hook *hook GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_DisplayMessage *msg GNUCREG(a1) )
  445. {
  446.     STATIC STRPTR t1 = "Newsgroups", t2 = "Flags", t3 = "subscribed", t4 = "\0", t5 = "Count";
  447.     STATIC char buf[10];
  448.  
  449.     if ( msg->TreeNode != NULL )
  450.     {
  451.         /*
  452.         **    The user data is a pointer to a SampleArray struct.
  453.         */
  454.         struct SampleArray *a = (struct SampleArray *)msg->TreeNode->tn_User;
  455.  
  456.         sprintf( buf, "%3ld", msg->Array[-1] );
  457.  
  458.         *msg->Array++    = msg->TreeNode->tn_Name;
  459.         *msg->Array++    = ( a->flags & 0x8000 ) ? t3 : t4;
  460.         *msg->Array++    = buf;
  461.     }
  462.     else
  463.     {
  464.         *msg->Array++    = t1;
  465.         *msg->Array++    = t2;
  466.         *msg->Array++    = t5;
  467.  
  468.         *msg->Preparse++    = "\033b\033u";
  469.         *msg->Preparse++    = "\033b\033u";
  470.         *msg->Preparse++    = "\033b\033u";
  471.     }
  472.  
  473.     return( 0 );
  474. }
  475.  
  476.  
  477.  
  478. /*
  479. **    Insert a new entry which name is given in
  480. **    the string gadget.
  481. */
  482. LONG SAVEDS ASM insertfunc( REG(a2) APTR obj GNUCREG(a2) )
  483. {
  484.     STRPTR x;
  485.  
  486.     /*
  487.     **    Get user string.
  488.     */
  489.     get( st_string, MUIA_String_Contents, &x );
  490.  
  491.     /*
  492.     **    Insert the new entry after
  493.     **    the active entry.
  494.     */
  495.     DoMethod( obj, MUIM_NListtree_Insert, x, 0, MUIV_NListtree_Insert_ListNode_Active,
  496.         MUIV_NListtree_Insert_PrevNode_Active, MUIV_NListtree_Insert_Flag_Active );
  497.  
  498.     return( 0 );
  499. }
  500.  
  501.  
  502.  
  503. /*
  504. **    Exchange two entries.
  505. */
  506. LONG SAVEDS ASM exchangefunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) )
  507. {
  508.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  509.     STATIC LONG exchcnt = 0;
  510.     LONG x;
  511.  
  512.     if ( ( exchcnt == 0 ) && ( (ULONG)*para == 42 ) )
  513.     {
  514.         get( obj, MUIA_NListtree_Active, &tn1 );
  515.  
  516.         if ( tn1 != MUIV_NListtree_Active_Off )
  517.         {
  518.             nnset( tx_info3, MUIA_Text_Contents, "Select entry to exchange selected entry with." );
  519.  
  520.             exchcnt++;
  521.         }
  522.     }
  523.  
  524.     else if ( exchcnt == 1 )
  525.     {
  526.         get( obj, MUIA_NListtree_Active, &tn2 );
  527.  
  528.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  529.         {
  530.             if ( !IsXChildOfY( obj, tn1, tn2 ) && !IsXChildOfY( obj, tn1, tn2 ) )
  531.             {
  532.                 struct MUI_NListtree_ListNode *ln1;
  533.  
  534.                 if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  535.                 {
  536.                     DoMethod( obj, MUIM_NListtree_Exchange, ln1, tn1, MUIV_NListtree_Exchange_ListNode2_Active, MUIV_NListtree_Exchange_TreeNode2_Active, 0 );
  537.  
  538.                     nnset( tx_info3, MUIA_Text_Contents, "Entries successfully exchanged!" );
  539.                 }
  540.                 else
  541.                     nnset( tx_info3, MUIA_Text_Contents, "Something went wrong! Try again to select." );
  542.             }
  543.             else
  544.                 nnset( tx_info3, MUIA_Text_Contents, "You can not exchange with childs!" );
  545.         }
  546.         else
  547.             nnset( tx_info3, MUIA_Text_Contents, "You should not exchange an entry with itself!" );
  548.  
  549.         exchcnt = 0;
  550.     }
  551.  
  552.     return( 0 );
  553. }
  554.  
  555.  
  556.  
  557. /*
  558. **    Rename the selected entry with the name is given in
  559. **    the string gadget.
  560. */
  561. LONG SAVEDS ASM renamefunc( REG(a2) APTR obj GNUCREG(a2) )
  562. {
  563.     struct MUI_NListtree_TreeNode *tn;
  564.     STRPTR x;
  565.  
  566.     /*
  567.     **    Get user string.
  568.     */
  569.     get( st_string, MUIA_String_Contents, &x );
  570.     get( obj, MUIA_NListtree_Active, &tn );
  571.  
  572.     /*
  573.     **    Insert the new entry sorted (compare hook)
  574.     **    into the active list node.
  575.     */
  576.     DoMethod( obj, MUIM_NListtree_Rename, tn,
  577.         x, 0 );
  578.  
  579.     return( 0 );
  580. }
  581.  
  582.  
  583.  
  584. /*
  585. **    Insert a new entry which name is given in
  586. **    the string gadget.
  587. */
  588. LONG SAVEDS ASM movefunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) )
  589. {
  590.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  591.     STATIC LONG movecnt = 0;
  592.     LONG x;
  593.  
  594.     if ( ( movecnt == 0 ) && ( (ULONG)*para == 42 ) )
  595.     {
  596.         get( obj, MUIA_NListtree_Active, &tn1 );
  597.  
  598.         if ( tn1 != MUIV_NListtree_Active_Off )
  599.         {
  600.             nnset( tx_info3, MUIA_Text_Contents, "Select entry to insert after by simple click." );
  601.  
  602.             movecnt++;
  603.         }
  604.     }
  605.  
  606.     else if ( movecnt == 1 )
  607.     {
  608.         get( obj, MUIA_NListtree_Active, &tn2 );
  609.  
  610.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  611.         {
  612.             if ( !IsXChildOfY( obj, tn1, tn2 ) && !IsXChildOfY( obj, tn1, tn2 ) )
  613.             {
  614.                 struct MUI_NListtree_ListNode *ln1;
  615.  
  616.                 if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  617.                 {
  618.                     DoMethod( obj, MUIM_NListtree_Move, ln1, tn1, MUIV_NListtree_Move_NewListNode_Active, tn2, 0 );
  619.  
  620.                     nnset( tx_info3, MUIA_Text_Contents, "Entry successfully moved!" );
  621.                 }
  622.                 else
  623.                     nnset( tx_info3, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  624.             }
  625.             else
  626.                 nnset( tx_info3, MUIA_Text_Contents, "You can not move childs!" );
  627.         }
  628.         else
  629.             nnset( tx_info3, MUIA_Text_Contents, "You should not move an entry to itself!" );
  630.  
  631.         movecnt = 0;
  632.     }
  633.  
  634.     return( 0 );
  635. }
  636.  
  637.  
  638. /*
  639. **    Insert a new entry which name is given in
  640. **    the string gadget.
  641. */
  642. LONG SAVEDS ASM copyfunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) )
  643. {
  644.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  645.     STATIC LONG copycnt = 0;
  646.     LONG x;
  647.  
  648.     if ( ( copycnt == 0 ) && ( (ULONG)*para == 42 ) )
  649.     {
  650.         get( obj, MUIA_NListtree_Active, &tn1 );
  651.  
  652.         if ( tn1 != MUIV_NListtree_Active_Off )
  653.         {
  654.             nnset( tx_info3, MUIA_Text_Contents, "Select entry to insert after by simple click." );
  655.  
  656.             copycnt++;
  657.         }
  658.     }
  659.  
  660.     else if ( copycnt == 1 )
  661.     {
  662.         get( obj, MUIA_NListtree_Active, &tn2 );
  663.  
  664.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  665.         {
  666.             struct MUI_NListtree_ListNode *ln1;
  667.  
  668.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  669.             {
  670.                 DoMethod( obj, MUIM_NListtree_Copy, ln1, tn1, MUIV_NListtree_Copy_DestListNode_Active, tn2, 0 );
  671.  
  672.                 nnset( tx_info3, MUIA_Text_Contents, "Entry successfully copied!" );
  673.             }
  674.             else
  675.                 nnset( tx_info3, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  676.         }
  677.         else
  678.             nnset( tx_info3, MUIA_Text_Contents, "You should not copy an entry to itself!" );
  679.  
  680.         copycnt = 0;
  681.     }
  682.  
  683.     return( 0 );
  684. }
  685.  
  686.  
  687.  
  688. /*
  689. **    Move KeepStructure
  690. */
  691. LONG SAVEDS ASM moveksfunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) )
  692. {
  693.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  694.     STATIC LONG movekscnt = 0;
  695.     LONG x;
  696.  
  697.     if ( ( movekscnt == 0 ) && ( (ULONG)*para == 42 ) )
  698.     {
  699.         get( obj, MUIA_NListtree_Active, &tn1 );
  700.  
  701.         if ( tn1 != MUIV_NListtree_Active_Off )
  702.         {
  703.             nnset( tx_info3, MUIA_Text_Contents, "Select entry to make KeepStructure move with." );
  704.  
  705.             movekscnt++;
  706.         }
  707.     }
  708.  
  709.     else if ( movekscnt == 1 )
  710.     {
  711.         get( obj, MUIA_NListtree_Active, &tn2 );
  712.  
  713.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  714.         {
  715.             struct MUI_NListtree_ListNode *ln1;
  716.  
  717.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  718.             {
  719.                 DoMethod( obj, MUIM_NListtree_Move, ln1, tn1, MUIV_NListtree_Move_NewListNode_Active, tn2, MUIV_NListtree_Move_Flag_KeepStructure );
  720.  
  721.                 nnset( tx_info3, MUIA_Text_Contents, "Entry successfully moved (structure keeped)" );
  722.             }
  723.             else
  724.                 nnset( tx_info3, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  725.         }
  726.         else
  727.             nnset( tx_info3, MUIA_Text_Contents, "You should not move an entry to itself!" );
  728.  
  729.         movekscnt = 0;
  730.     }
  731.  
  732.     return( 0 );
  733. }
  734.  
  735.  
  736. /*
  737. **    Copy KeepStructure
  738. */
  739. LONG SAVEDS ASM copyksfunc( REG(a2) APTR obj GNUCREG(a2), REG(a1) ULONG **para GNUCREG(a1) )
  740. {
  741.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  742.     STATIC LONG copykscnt = 0;
  743.     LONG x;
  744.  
  745.     if ( ( copykscnt == 0 ) && ( (ULONG)*para == 42 ) )
  746.     {
  747.         get( obj, MUIA_NListtree_Active, &tn1 );
  748.  
  749.         if ( tn1 != MUIV_NListtree_Active_Off )
  750.         {
  751.             nnset( tx_info3, MUIA_Text_Contents, "Select entry to make KeepStructure copy with." );
  752.  
  753.             copykscnt++;
  754.         }
  755.     }
  756.  
  757.     else if ( copykscnt == 1 )
  758.     {
  759.         get( obj, MUIA_NListtree_Active, &tn2 );
  760.  
  761.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  762.         {
  763.             struct MUI_NListtree_ListNode *ln1;
  764.  
  765.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  766.             {
  767.                 DoMethod( obj, MUIM_NListtree_Copy, ln1, tn1, MUIV_NListtree_Copy_DestListNode_Active, tn2, MUIV_NListtree_Copy_Flag_KeepStructure );
  768.  
  769.                 nnset( tx_info3, MUIA_Text_Contents, "Entry successfully copied (structure keeped)" );
  770.             }
  771.             else
  772.                 nnset( tx_info3, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  773.         }
  774.         else
  775.             nnset( tx_info3, MUIA_Text_Contents, "You should not copy an entry to itself!" );
  776.  
  777.         copykscnt = 0;
  778.     }
  779.  
  780.     return( 0 );
  781. }
  782.  
  783.  
  784.  
  785. LONG ASM SAVEDS fudf( REG(a0) struct Hook *h GNUCREG(a0), REG(a2) Object *obj GNUCREG(a2), REG(a1) struct MUIP_NListtree_FindUserDataMessage *msg GNUCREG(a1) )
  786. {
  787.     nnset( tx_info1, MUIA_Text_Contents, "FindUserData Hook passed!" );
  788.     return( strncmp( (STRPTR)msg->User, (STRPTR)msg->UserData, strlen( (STRPTR)msg->User ) ) );
  789. }
  790.  
  791. STATIC struct Hook fudh = { {NULL, NULL}, (void *)fudf, NULL, NULL };
  792.  
  793. /*
  794. **    Find the specified tree node by name.
  795. */
  796. LONG SAVEDS ASM findnamefunc( REG(a2) APTR obj GNUCREG(a2) )
  797. {
  798.     struct MUI_NListtree_TreeNode *tn;
  799.     char buf[100];
  800.     STRPTR x;
  801.  
  802.     /*
  803.     **    Let us see, which string the user wants to search for...
  804.     */
  805.     get( st_string, MUIA_String_Contents, &x );
  806.  
  807.     /*
  808.     **    Is it somewhere in the tree?
  809.     */
  810.     if ( tn = (struct MUI_NListtree_TreeNode *)DoMethod(obj, MUIM_NListtree_FindUserData, MUIV_NListtree_FindUserData_ListNode_Root, x, MUIV_NListtree_FindUserData_Flag_Activate ) )
  811.     {
  812.         /*
  813.         **    Found! Inform the user.
  814.         */
  815.         nnset( tx_info3, MUIA_Text_Contents, "Found your node!" );
  816.     }
  817.     else
  818.     {
  819.         /*
  820.         **    Not found. Inform the user.
  821.         */
  822.         nnset( tx_info3, MUIA_Text_Contents, "NOT found specified node!" );
  823.     }
  824.  
  825.     return( 0 );
  826. }
  827.  
  828.  
  829.  
  830. /*
  831. **    Find the specified tree node by name.
  832. */
  833. LONG SAVEDS ASM getnrfunc( REG(a2) APTR obj GNUCREG(a2) )
  834. {
  835.     LONG temp, temp2;
  836.  
  837.     temp = DoMethod( obj, MUIM_NListtree_GetNr,
  838.         MUIV_NListtree_GetNr_TreeNode_Active, MUIV_NListtree_GetNr_Flag_CountLevel );
  839.  
  840.     if ( temp == 1 )
  841.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "1 entry in parent node." );
  842.     else
  843.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "%ld entries in parent node.", temp );
  844.  
  845.  
  846.     temp = DoMethod( obj, MUIM_NListtree_GetNr,
  847.         MUIV_NListtree_GetNr_TreeNode_Active, MUIV_NListtree_GetNr_Flag_CountAll );
  848.  
  849.     if ( temp == 1 )
  850.         DoMethod( tx_info2, MUIM_SetAsString, MUIA_Text_Contents, "1 entry total." );
  851.     else
  852.         DoMethod( tx_info2, MUIM_SetAsString, MUIA_Text_Contents, "%ld entries total.", temp );
  853.  
  854.  
  855.     temp = DoMethod( obj, MUIM_NListtree_GetNr,
  856.         MUIV_NListtree_GetNr_TreeNode_Active, 0 );
  857.  
  858.     temp2 = DoMethod( obj, MUIM_NListtree_GetNr,
  859.         MUIV_NListtree_GetNr_TreeNode_Active, MUIV_NListtree_GetNr_Flag_Visible );
  860.  
  861.     DoMethod( tx_info3, MUIM_SetAsString, MUIA_Text_Contents, "Active entry pos: %ld (visible: %ld).", temp, temp2 );
  862.  
  863.     return( 0 );
  864. }
  865.  
  866.  
  867. /*
  868. **    Find the specified tree node by name.
  869. */
  870. LONG SAVEDS ASM numselfunc( REG(a2) APTR obj GNUCREG(a2) )
  871. {
  872.     LONG temp = 0;
  873.  
  874.     DoMethod( obj, MUIM_NListtree_Select, MUIV_NListtree_Select_All,
  875.         MUIV_NListtree_Select_Ask, 0, &temp );
  876.  
  877.     if ( temp == 1 )
  878.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "1 node selected." );
  879.     else
  880.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "%ld nodes selected.", temp );
  881.  
  882.     {
  883.         struct MUI_NListtree_TreeNode *tn;
  884.  
  885.         tn = (struct MUI_NListtree_TreeNode *)MUIV_NListtree_NextSelected_Start;
  886.  
  887.         for (;;)
  888.         {
  889.             DoMethod( obj, MUIM_NListtree_NextSelected, &tn );
  890.  
  891.             if ( (LONG)tn == MUIV_NListtree_NextSelected_End )
  892.                 break;
  893.  
  894.             D(bug( "Next TreeNode: 0x%08lx - %s\n", tn, tn->tn_Name ) );
  895.         }
  896.  
  897.         D(bug( "\n" ) );
  898.  
  899.         tn = (struct MUI_NListtree_TreeNode *)MUIV_NListtree_PrevSelected_Start;
  900.  
  901.         for (;;)
  902.         {
  903.             DoMethod( obj, MUIM_NListtree_PrevSelected, &tn );
  904.  
  905.             if ( (LONG)tn == MUIV_NListtree_PrevSelected_End )
  906.                 break;
  907.  
  908.             D(bug( "Prev TreeNode: 0x%08lx - %s\n", tn, tn->tn_Name ) );
  909.         }
  910.     }
  911.  
  912.     return( 0 );
  913. }
  914.  
  915.  
  916. /*
  917. **    Test func
  918. */
  919. LONG SAVEDS ASM testfunc( REG(a2) APTR obj GNUCREG(a2) )
  920. {
  921.     STATIC BOOL q = FALSE;
  922.  
  923.     if ( q == FALSE )    q = TRUE;
  924.     else                q = FALSE;
  925.  
  926.     set( obj, MUIA_NListtree_Quiet, q );
  927.  
  928.     return( 0 );
  929. }
  930.  
  931.  
  932.  
  933.  
  934.  
  935. /*
  936. **    Main
  937. */
  938. int main( int argc, STRPTR argv[] )
  939. {
  940.     ULONG signals;
  941.  
  942.     MUIMasterBase = OpenLibrary( "muimaster.library", 19 );
  943.     IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 36 );
  944.  
  945.     /*
  946.     **    Is MUI V19 available?
  947.     */
  948.     if ( MUIMasterBase && IntuitionBase )
  949.     {
  950.         /*
  951.         **    Create application object.
  952.         */
  953.         app = ApplicationObject,
  954.             MUIA_Application_Title,            "NListtree-Demo",
  955.             MUIA_Application_Copyright,        "©1999-2000 by Apocalypse Hard- and Software",
  956.             MUIA_Application_Author,        "Carsten Scholling",
  957.             MUIA_Application_Description,    "Demonstration program for MUI class NListtree.mcc",
  958.             MUIA_Application_Base,            "NLISTTREEDEMO",
  959.  
  960.             /*
  961.             **    Build the window.
  962.             */
  963.             SubWindow, window = WindowObject,
  964.                 MUIA_Window_Title,            "NListtree-Demo",
  965.                 MUIA_Window_ID,                MAKE_ID( 'N', 'L', 'T', 'R' ),
  966.                 MUIA_Window_AppWindow,        TRUE,
  967.                 WindowContents,                VGroup,
  968.  
  969.                     /*
  970.                     **    Create a NListview embedded NListtree object
  971.                     */
  972.                     Child, NListviewObject,
  973.                         MUIA_ShortHelp,            "The NListtree object...",
  974.                         MUIA_NListview_NList,    lt_nodes = NListtreeObject,
  975.                             InputListFrame,
  976.                             MUIA_CycleChain,                TRUE,
  977.                             MUIA_NList_MinLineHeight,        18,
  978.                             MUIA_NListtree_MultiSelect,        MUIV_NListtree_MultiSelect_Shifted,
  979.                             //MUIA_NListtree_MultiTestHook,    &mthook,
  980.                             MUIA_NListtree_DisplayHook,        &dsphook,
  981.                             MUIA_NListtree_ConstructHook,    &conhook,
  982.                             MUIA_NListtree_DestructHook,    &deshook,    /* This is the same as MUIV_NListtree_CompareHook_LeavesMixed. */
  983.                             MUIA_NListtree_CompareHook,        &comphook,
  984.                             MUIA_NListtree_DoubleClick,        MUIV_NListtree_DoubleClick_Tree,
  985.                             MUIA_NListtree_EmptyNodes,        FALSE,
  986.                             MUIA_NListtree_TreeColumn,        0,
  987.                             MUIA_NListtree_DragDropSort,    TRUE,
  988.                             MUIA_NListtree_Title,            TRUE,
  989.                             MUIA_NListtree_Format,            ",,",
  990.                             MUIA_NListtree_FindUserDataHook,&fudh,
  991.                         End,
  992.                     End,
  993.  
  994.                     /*
  995.                     **    Build some controls.
  996.                     */
  997.                     Child, tx_info1 = TextObject,
  998.                         MUIA_Background, MUII_TextBack,
  999.                         TextFrame,
  1000.                     End,
  1001.  
  1002.                     Child, tx_info2 = TextObject,
  1003.                         MUIA_Background, MUII_TextBack,
  1004.                         TextFrame,
  1005.                     End,
  1006.  
  1007.                     Child, tx_info3 = TextObject,
  1008.                         MUIA_Background, MUII_TextBack,
  1009.                         TextFrame,
  1010.                     End,
  1011.  
  1012.                     Child, ColGroup( 2 ),
  1013.                         Child, FreeKeyLabel( "TreeCol:", 'c' ),
  1014.                         Child, sl_treecol    = Slider( 0, 2, 0 ),
  1015.                     End,
  1016.  
  1017.                     Child, HGroup,
  1018.                         Child, st_string = StringObject,
  1019.                             StringFrame,
  1020.                             MUIA_String_MaxLen, 50,
  1021.                         End,
  1022.                     End,
  1023.  
  1024.  
  1025.                     Child, ColGroup( 4 ),
  1026.                         Child, bt_open        = KeyButton( "Open",        'o' ),
  1027.                         Child, bt_close        = KeyButton( "Close",        'c' ),
  1028.                         Child, bt_expand    = KeyButton( "Expand",        'e' ),
  1029.                         Child, bt_collapse    = KeyButton( "Collapse",    'a' ),
  1030.  
  1031.                         Child, bt_insert    = KeyButton( "Insert",        'i' ),
  1032.                         Child, bt_remove    = KeyButton( "Remove",        'r' ),
  1033.                         Child, bt_exchange    = KeyButton( "Exchange",    'x' ),
  1034.                         Child, bt_rename    = KeyButton( "Rename",        'r' ),
  1035.  
  1036.                         Child, bt_move        = KeyButton( "Move",        'm' ),
  1037.                         Child, bt_copy        = KeyButton( "Copy",        'y' ),
  1038.                         Child, bt_moveks    = KeyButton( "Move KS",        'v' ),
  1039.                         Child, bt_copyks    = KeyButton( "Copy KS",        'k' ),
  1040.  
  1041.                         Child, bt_find        = KeyButton( "FindName",    'f' ),
  1042.                         Child, bt_parent    = KeyButton( "Parent",        'p' ),
  1043.                         Child, bt_sort        = KeyButton( "Sort",        's' ),
  1044.                         Child, bt_getnr        = KeyButton( "GetNr",        'n' ),
  1045.  
  1046.                         Child, bt_redraw    = KeyButton( "Redraw",        'w' ),
  1047.                         Child, bt_selected    = KeyButton( "Selected",    'd' ),
  1048.                         Child, bt_seltogg    = KeyButton( "Sel Togg",    't' ),
  1049.                         Child, bt_showtree    = KeyButton( "Show tree",    'h' ),
  1050.                     End,
  1051.  
  1052.                 End,
  1053.  
  1054.             End,
  1055.         End;
  1056.  
  1057.  
  1058.         if( app )
  1059.         {
  1060.             /*
  1061.             **    generate notifications
  1062.             */
  1063.             DoMethod( window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  1064.                 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  1065.  
  1066.             /*
  1067.             **    open/close/expand/collapse
  1068.             */
  1069.             DoMethod( bt_open, MUIM_Notify, MUIA_Pressed, FALSE,
  1070.                 lt_nodes, 4, MUIM_NListtree_Open, MUIV_NListtree_Open_ListNode_Active, MUIV_NListtree_Open_TreeNode_Active, 0 );
  1071.  
  1072.             DoMethod( bt_close, MUIM_Notify, MUIA_Pressed, FALSE,
  1073.                 lt_nodes, 4, MUIM_NListtree_Close, MUIV_NListtree_Close_ListNode_Active, MUIV_NListtree_Close_TreeNode_Active, 0 );
  1074.  
  1075.             DoMethod( bt_expand, MUIM_Notify, MUIA_Pressed, FALSE,
  1076.                 lt_nodes, 4, MUIM_NListtree_Open, MUIV_NListtree_Open_ListNode_Root, MUIV_NListtree_Open_TreeNode_All, 0 );
  1077.  
  1078.             DoMethod( bt_collapse, MUIM_Notify, MUIA_Pressed, FALSE,
  1079.                 lt_nodes, 4, MUIM_NListtree_Close, MUIV_NListtree_Close_ListNode_Root, MUIV_NListtree_Close_TreeNode_All, 0 );
  1080.  
  1081.  
  1082.  
  1083.             /*
  1084.             **    insert/remove/exchange/rename
  1085.             */
  1086.             DoMethod( bt_insert, MUIM_Notify, MUIA_Pressed, FALSE,
  1087.                 lt_nodes, 2, MUIM_CallHook, &inserthook );
  1088.  
  1089.             DoMethod( bt_remove, MUIM_Notify, MUIA_Pressed, FALSE,
  1090.                 lt_nodes, 4, MUIM_NListtree_Remove, MUIV_NListtree_Remove_ListNode_Active, MUIV_NListtree_Remove_TreeNode_Active, 0 );
  1091.  
  1092.             DoMethod( bt_exchange, MUIM_Notify, MUIA_Pressed, FALSE,
  1093.                 lt_nodes, 3, MUIM_CallHook, &exchangehook, 42 );
  1094.  
  1095.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  1096.                 lt_nodes, 3, MUIM_CallHook, &exchangehook, 0 );
  1097.  
  1098.             DoMethod( bt_rename, MUIM_Notify, MUIA_Pressed, FALSE,
  1099.                 lt_nodes, 2, MUIM_CallHook, &renamehook );
  1100.  
  1101.  
  1102.             /*
  1103.             **    move/copy/moveks/copyks
  1104.             */
  1105.             DoMethod( bt_move, MUIM_Notify, MUIA_Pressed, FALSE,
  1106.                 lt_nodes, 3, MUIM_CallHook, &movehook, 42 );
  1107.  
  1108.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  1109.                 lt_nodes, 3, MUIM_CallHook, &movehook, 0 );
  1110.  
  1111.             DoMethod( bt_copy, MUIM_Notify, MUIA_Pressed, FALSE,
  1112.                 lt_nodes, 3, MUIM_CallHook, ©hook, 42 );
  1113.  
  1114.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  1115.                 lt_nodes, 3, MUIM_CallHook, ©hook, 0 );
  1116.  
  1117.             DoMethod( bt_moveks, MUIM_Notify, MUIA_Pressed, FALSE,
  1118.                 lt_nodes, 3, MUIM_CallHook, &movekshook, 42 );
  1119.  
  1120.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  1121.                 lt_nodes, 3, MUIM_CallHook, &movekshook, 0 );
  1122.  
  1123.             DoMethod( bt_copyks, MUIM_Notify, MUIA_Pressed, FALSE,
  1124.                 lt_nodes, 3, MUIM_CallHook, ©kshook, 42 );
  1125.  
  1126.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  1127.                 lt_nodes, 3, MUIM_CallHook, ©kshook, 0 );
  1128.  
  1129.  
  1130.             /*
  1131.             **    find/parent/sort/getnr
  1132.             */
  1133.             DoMethod( bt_find, MUIM_Notify, MUIA_Pressed, FALSE,
  1134.                 lt_nodes, 2, MUIM_CallHook, &findnamehook );
  1135.  
  1136.             DoMethod( bt_parent, MUIM_Notify, MUIA_Pressed, FALSE,
  1137.                 lt_nodes, 3, MUIM_Set, MUIA_NListtree_Active, MUIV_NListtree_Active_Parent );
  1138.  
  1139.             DoMethod( bt_sort, MUIM_Notify, MUIA_Pressed, FALSE,
  1140.                 lt_nodes, 3, MUIM_NListtree_Sort, MUIV_NListtree_Sort_TreeNode_Active, 0 );
  1141.  
  1142.             DoMethod( bt_getnr, MUIM_Notify, MUIA_Pressed, FALSE,
  1143.                 lt_nodes, 2, MUIM_CallHook, &getnrhook );
  1144.  
  1145.  
  1146.             /*
  1147.             **    redraw/selected/seltogg/showtree
  1148.             */
  1149.             DoMethod( bt_redraw, MUIM_Notify, MUIA_Pressed, FALSE,
  1150.                 lt_nodes, 3, MUIM_NListtree_Redraw, MUIV_NListtree_Redraw_All );
  1151.  
  1152.             DoMethod( bt_selected, MUIM_Notify, MUIA_Pressed, FALSE,
  1153.                 lt_nodes, 2, MUIM_CallHook, &numselhook );
  1154.  
  1155.             DoMethod( bt_seltogg, MUIM_Notify, MUIA_Pressed, FALSE,
  1156.                 lt_nodes, 4, MUIM_NListtree_Select, MUIV_NListtree_Select_All, MUIV_NListtree_Select_Toggle, 0 );
  1157.  
  1158.             DoMethod( bt_showtree, MUIM_Notify, MUIA_Pressed, FALSE,
  1159.                 lt_nodes, 3, MUIM_Set, MUIA_NListtree_ShowTree, MUIV_NListtree_ShowTree_Toggle );
  1160.  
  1161.  
  1162.             /*
  1163.             **    misc
  1164.             */
  1165.             DoMethod( sl_treecol, MUIM_Notify, MUIA_Slider_Level, MUIV_EveryTime,
  1166.                 lt_nodes, 3, MUIM_Set, MUIA_NListtree_TreeColumn, MUIV_TriggerValue );
  1167.  
  1168.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  1169.                 tx_info1, 4, MUIM_SetAsString, MUIA_Text_Contents, "Active node: 0x%08lx", MUIV_TriggerValue );
  1170.  
  1171.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_ActiveList, MUIV_EveryTime,
  1172.                 tx_info2, 4, MUIM_SetAsString, MUIA_Text_Contents, "Active list: 0x%08lx", MUIV_TriggerValue );
  1173.  
  1174.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_DoubleClick, MUIV_EveryTime,
  1175.                 tx_info3, 4, MUIM_SetAsString, MUIA_Text_Contents, "Double clicked on node: 0x%08lx", MUIV_TriggerValue );
  1176.  
  1177.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_SelectChange, TRUE,
  1178.                 tx_info3, 3, MUIM_SetAsString, MUIA_Text_Contents, "Selection state changed" );
  1179.  
  1180.  
  1181.             /*
  1182.             **    Open the window.
  1183.             **
  1184.             */
  1185.             set( window, MUIA_Window_Open, TRUE );
  1186.  
  1187.  
  1188.             /*
  1189.             **    Set the tree into quiet state.
  1190.             */
  1191.             set( lt_nodes, MUIA_NListtree_Quiet, TRUE );
  1192.  
  1193.  
  1194.             /*
  1195.             **    Insert sample nodes.
  1196.             */
  1197.             DrawSampleTree( lt_nodes );
  1198.  
  1199.  
  1200.             /*
  1201.             **    Set the tree back to normal state.
  1202.             */
  1203.             set( lt_nodes, MUIA_NListtree_Quiet, FALSE );
  1204.  
  1205.             /*
  1206.             **    Minimal input loop.
  1207.             */
  1208.             while( DoMethod( app, MUIM_Application_NewInput, &signals ) != MUIV_Application_ReturnID_Quit )
  1209.             {
  1210.                 if ( signals )
  1211.                 {
  1212.                     signals = Wait( signals | SIGBREAKF_CTRL_C );
  1213.  
  1214.                     if ( signals & SIGBREAKF_CTRL_C )
  1215.                         break;
  1216.                 }
  1217.             }
  1218.  
  1219.             /*
  1220.             **    Clear the list.
  1221.             */
  1222.             DoMethod( lt_nodes, MUIM_NListtree_Clear, NULL, 0 );
  1223.  
  1224.  
  1225.             /*
  1226.             **    Close the window.
  1227.             */
  1228.             set( window, MUIA_Window_Open, FALSE );
  1229.  
  1230.  
  1231.             /*
  1232.             **    Shutdown
  1233.             */
  1234.             MUI_DisposeObject( app );
  1235.         }
  1236.         else
  1237.             printf( "Failed to create Application.\n" );
  1238.     }
  1239.  
  1240.     if ( IntuitionBase )
  1241.         CloseLibrary( (struct Library *)IntuitionBase );
  1242.  
  1243.     if ( MUIMasterBase )
  1244.         CloseLibrary( MUIMasterBase );
  1245.  
  1246.     return( 0 );
  1247. }
  1248.  
  1249.  
  1250.