home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / MCC_NListtree / Developer / C / Examples / NListtree-Demo.c < prev   
C/C++ Source or Header  |  2000-08-01  |  28KB  |  1,004 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. #include <proto/muimaster.h>
  24.  
  25. #include <clib/alib_protos.h>
  26. #include <clib/exec_protos.h>
  27.  
  28. #include <exec/memory.h>
  29. #include <exec/types.h>
  30.  
  31. #include <string.h>
  32. #include <stdio.h>
  33.  
  34. #include "Compiler.h"
  35.  
  36. #include <libraries/mui.h>
  37.  
  38. #include <mui/nlistview_mcc.h>
  39. #include <mui/nlist_mcc.h>
  40. #include "mui/nlisttree_mcc.h"
  41.  
  42.  
  43. #ifdef MYDEBUG
  44.     #ifdef __APHASO__
  45.         #include <Debug.h>
  46.     #else
  47.         #define bug kprintf
  48.         #define D(x)
  49.         void kprintf( UBYTE *fmt, ... );
  50.     #endif
  51. #endif
  52.  
  53.  
  54. #ifndef MAKE_ID
  55. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  56. #endif
  57.  
  58.  
  59. /*
  60. **    Do not use stack sizes below 8KB!!
  61. */
  62. LONG __stack = 16384;
  63.  
  64.  
  65. /*
  66. **    MUI library base.
  67. */
  68. struct Library    *MUIMasterBase;
  69.  
  70. /*
  71. **    MUI objects.
  72. */
  73. STATIC APTR        app, window,lt_nodes,
  74.                 tx_info1,    tx_info2,
  75.                 sl_treecol,    st_string,
  76.                 bt_open,    bt_close,    bt_expand,    bt_collapse,
  77.                 bt_insert,    bt_remove,    bt_exchange,bt_rename,
  78.                 bt_move,    bt_copy,    bt_moveks,    bt_copyks,
  79.                 bt_find,    bt_parent,    bt_sort,    bt_getnr,
  80.                 bt_redraw,    bt_selected;
  81.  
  82.  
  83.  
  84. /*
  85. **    Sample tree structure.
  86. */
  87. struct SampleArray {
  88.     STRPTR    name;
  89.     UWORD   flags;
  90. };
  91.  
  92. STATIC const struct SampleArray sa[] =
  93. {
  94.     "comp", TNF_LIST | TNF_OPEN,
  95.         "sys", TNF_LIST | TNF_OPEN,
  96.             "amiga", TNF_LIST | TNF_OPEN,
  97.                 "misc", 0x8000,
  98.             "mac", TNF_LIST,
  99.                 "system", 0x8000,
  100.  
  101.     "de", TNF_LIST | TNF_OPEN,
  102.         "comm", TNF_LIST,
  103.             "software", TNF_LIST,
  104.                 "ums", 0x8000,
  105.         "comp", TNF_LIST | TNF_OPEN,
  106.             "sys", TNF_LIST | TNF_OPEN,
  107.                 "amiga", TNF_LIST,
  108.                     "misc", 0x8000,
  109.                     "tech", 0x8000,
  110.                 "amiga", 0x8000,
  111.  
  112.     "sort test", TNF_LIST | TNF_OPEN,
  113.         "a", 0,
  114.         "x", TNF_LIST,
  115.         "v", 0,
  116.         "g", TNF_LIST,
  117.         "h", 0,
  118.         "k", TNF_LIST,
  119.         "u", 0,
  120.         "i", TNF_LIST,
  121.         "t", 0,
  122.         "e", TNF_LIST,
  123.         "q", 0,
  124.         "s", TNF_LIST,
  125.         "c", 0,
  126.         "f", TNF_LIST,
  127.         "p", 0,
  128.         "l", TNF_LIST,
  129.         "z", 0,
  130.         "w", TNF_LIST,
  131.         "b", 0,
  132.         "o", TNF_LIST,
  133.         "d", 0,
  134.         "m", TNF_LIST,
  135.         "r", 0,
  136.         "y", TNF_LIST,
  137.         "n", 0,
  138.         "j", TNF_LIST,
  139.  
  140.  
  141.     "m", TNF_LIST,
  142.         "i", TNF_LIST,
  143.             "c", TNF_LIST,
  144.                 "h", TNF_LIST,
  145.                     "e", TNF_LIST,
  146.                         "l", TNF_LIST,
  147.                             "a", TNF_LIST,
  148.                                 "n", TNF_LIST,
  149.                                     "g", TNF_LIST,
  150.                                         "e", TNF_LIST,
  151.                                             "l", TNF_LIST,
  152.                                                 "o", 0,
  153.  
  154.     "end", TNF_LIST,
  155.         "of", TNF_LIST,
  156.             "tree", 0,
  157.  
  158.     NULL, 0
  159. };
  160.  
  161.  
  162.  
  163. /*
  164. **    Prototypes and hooks.
  165. */
  166. SAVEDS ASM LONG confunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_ConstructMessage *msg );
  167. STATIC struct Hook conhook = { {NULL, NULL}, (void *)confunc, NULL, NULL };
  168.  
  169. SAVEDS ASM LONG desfunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_DestructMessage *msg );
  170. STATIC struct Hook deshook = { {NULL, NULL}, (void *)desfunc, NULL, NULL };
  171.  
  172. SAVEDS ASM LONG dspfunc( REG(a0) struct Hook *hook, REG( a2 ) Object *obj, REG( a1 ) struct MUIP_NListtree_DisplayMessage *msg );
  173. STATIC struct Hook dsphook = { { NULL,NULL }, (void *)dspfunc, NULL, NULL };
  174.  
  175. SAVEDS ASM LONG compfunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_CompareMessage *msg );
  176. STATIC struct Hook comphook = { {NULL, NULL}, (void *)compfunc, NULL, NULL };
  177.  
  178. SAVEDS ASM LONG insertfunc( REG(a2) APTR obj );
  179. STATIC struct Hook inserthook = { {NULL, NULL}, (void *)insertfunc, NULL, NULL };
  180.  
  181. SAVEDS ASM LONG exchangefunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  182. STATIC struct Hook exchangehook = { {NULL, NULL}, (void *)exchangefunc, NULL, NULL };
  183.  
  184. SAVEDS ASM LONG renamefunc( REG(a2) APTR obj );
  185. STATIC struct Hook renamehook = { {NULL, NULL}, (void *)renamefunc, NULL, NULL };
  186.  
  187. SAVEDS ASM LONG movefunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  188. STATIC struct Hook movehook = { {NULL, NULL}, (void *)movefunc, NULL, NULL };
  189.  
  190. SAVEDS ASM LONG copyfunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  191. STATIC struct Hook copyhook = { {NULL, NULL}, (void *)copyfunc, NULL, NULL };
  192.  
  193. SAVEDS ASM LONG moveksfunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  194. STATIC struct Hook movekshook = { {NULL, NULL}, (void *)moveksfunc, NULL, NULL };
  195.  
  196. SAVEDS ASM LONG copyksfunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  197. STATIC struct Hook copykshook = { {NULL, NULL}, (void *)copyksfunc, NULL, NULL };
  198.  
  199. SAVEDS ASM LONG findnamefunc( REG(a2) APTR obj );
  200. STATIC struct Hook findnamehook = { {NULL, NULL}, (void *)findnamefunc, NULL, NULL };
  201.  
  202. SAVEDS ASM LONG getnrfunc( REG(a2) APTR obj );
  203. STATIC struct Hook getnrhook = { {NULL, NULL}, (void *)getnrfunc, NULL, NULL };
  204.  
  205. SAVEDS ASM LONG numselfunc( REG(a2) APTR obj );
  206. STATIC struct Hook numselhook = { {NULL, NULL}, (void *)numselfunc, NULL, NULL };
  207.  
  208.  
  209.  
  210.  
  211. /*
  212. **    This function draws the sample tree structure.
  213. */
  214. STATIC VOID DrawSampleTree( Object *ltobj )
  215. {
  216.     struct MUI_NListtree_TreeNode *tn1, *tn2, *tn3;
  217.     WORD i = 0, j;
  218.  
  219.     set( ltobj, MUIA_NListtree_Quiet, TRUE );
  220.  
  221.     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++;
  222.     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++;
  223.     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++;
  224.     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++;
  225.     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++;
  226.     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++;
  227.  
  228.     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++;
  229.     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++;
  230.     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++;
  231.     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++;
  232.     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++;
  233.     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++;
  234.     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++;
  235.     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++;
  236.     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++;
  237.     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++;
  238.  
  239.     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++;
  240.  
  241.     for( j = 0; j < 26; j++ )
  242.     {
  243.         DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  244.     }
  245.  
  246.     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++;
  247.  
  248.     for( j = 0; j < 11; j++ )
  249.     {
  250.         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++;
  251.     }
  252.  
  253.     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++;
  254.     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++;
  255.     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++;
  256.  
  257.  
  258.     set( ltobj, MUIA_NListtree_Quiet, FALSE );
  259. }
  260.  
  261.  
  262.  
  263.  
  264. /*
  265. **    Allocates memory for each entry we create.
  266. */
  267. LONG ASM SAVEDS confunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_ConstructMessage *msg )
  268. {
  269.     struct SampleArray *sa;
  270.  
  271.     /*
  272.     **    Allocate needed piece of memory for the new entry.
  273.     */
  274.     if ( sa = (struct SampleArray *)AllocVec( sizeof( struct SampleArray) + strlen( msg->Name ) + 1, MEMF_CLEAR ) )
  275.     {
  276.         /*
  277.         **    Save the user data field right after the
  278.         **    array structure.
  279.         */
  280.         strcpy( (STRPTR)&sa[1], msg->Name );
  281.         sa->name = (STRPTR)&sa[1];
  282.  
  283.         sa->flags = (UWORD)msg->UserData;
  284.     }
  285.  
  286.     return( (LONG)sa );
  287. }
  288.  
  289.  
  290.  
  291. /*
  292. **    Free memory we just allocated above.
  293. */
  294. LONG ASM SAVEDS desfunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_DestructMessage *msg )
  295. {
  296.     if ( msg->UserData != NULL )
  297.     {
  298.         FreeVec( msg->UserData );
  299.         msg->UserData = NULL;
  300.     }
  301.  
  302.     return( 0 );
  303. }
  304.  
  305.  
  306.  
  307. /*
  308. **    Compare hook function.
  309. */
  310. LONG ASM SAVEDS compfunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_CompareMessage *msg )
  311. {
  312.     return( stricmp( msg->TreeNode1->tn_Name, msg->TreeNode2->tn_Name ) );
  313. }
  314.  
  315.  
  316.  
  317. /*
  318. **    Format the entry data for displaying.
  319. */
  320. LONG ASM SAVEDS dspfunc( REG(a0) struct Hook *hook, REG( a2 ) Object *obj, REG( a1 ) struct MUIP_NListtree_DisplayMessage *msg )
  321. {
  322.     STATIC STRPTR t1 = "\033b\033uNewsgroups", t2 = "\033b\033uFlags", t3 = "subscribed", t4 = "\0", t5 = "\033b\033uCnt";
  323.     STATIC char buf[10];
  324.  
  325.     if ( msg->TreeNode != NULL )
  326.     {
  327.         /*
  328.         **    The user data is a pointer to a SampleArray struct.
  329.         */
  330.         struct SampleArray *a = (struct SampleArray *)msg->TreeNode->tn_User;
  331.  
  332.         sprintf( buf, "%3ld", msg->Array[-1] );
  333.  
  334.         *msg->Array++    = msg->TreeNode->tn_Name;
  335.         *msg->Array++    = ( a->flags & 0x8000 ) ? t3 : t4;
  336.         *msg->Array++    = buf;
  337.     }
  338.     else
  339.     {
  340.         *msg->Array++    = t1;
  341.         *msg->Array++    = t2;
  342.         *msg->Array++    = t5;
  343.     }
  344.  
  345.     return( 0 );
  346. }
  347.  
  348.  
  349.  
  350. /*
  351. **    Insert a new entry which name is given in
  352. **    the string gadget.
  353. */
  354. SAVEDS ASM LONG insertfunc( REG(a2) APTR obj )
  355. {
  356.     STRPTR x;
  357.  
  358.     /*
  359.     **    Get user string.
  360.     */
  361.     get( st_string, MUIA_String_Contents, &x );
  362.  
  363.     /*
  364.     **    Insert the new entry after
  365.     **    the active entry.
  366.     */
  367.     DoMethod( obj, MUIM_NListtree_Insert, x, 0, MUIV_NListtree_Insert_ListNode_Active,
  368.         MUIV_NListtree_Insert_PrevNode_Active, MUIV_NListtree_Insert_Flag_Active );
  369.  
  370.     return( 0 );
  371. }
  372.  
  373.  
  374.  
  375. /*
  376. **    Exchange two entries.
  377. */
  378. SAVEDS ASM LONG exchangefunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  379. {
  380.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  381.     STATIC LONG exchcnt = 0;
  382.     LONG x;
  383.  
  384.     if ( ( exchcnt == 0 ) && ( (ULONG)*para == 42 ) )
  385.     {
  386.         get( obj, MUIA_NListtree_Active, &tn1 );
  387.  
  388.         if ( tn1 != MUIV_NListtree_Active_Off )
  389.         {
  390.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to exchange selected entry with." );
  391.  
  392.             exchcnt++;
  393.         }
  394.     }
  395.  
  396.     else if ( exchcnt == 1 )
  397.     {
  398.         get( obj, MUIA_NListtree_Active, &tn2 );
  399.  
  400.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  401.         {
  402.             struct MUI_NListtree_ListNode *ln1;
  403.  
  404.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  405.             {
  406.                 DoMethod( obj, MUIM_NListtree_Exchange, ln1, tn1, MUIV_NListtree_Exchange_ListNode2_Active, MUIV_NListtree_Exchange_TreeNode2_Active, 0 );
  407.  
  408.                 nnset( tx_info2, MUIA_Text_Contents, "Entries successfully exchanged!" );
  409.             }
  410.             else
  411.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select." );
  412.         }
  413.         else
  414.             nnset( tx_info2, MUIA_Text_Contents, "You should not exchange an entry with itself!" );
  415.  
  416.         exchcnt = 0;
  417.     }
  418.  
  419.     return( 0 );
  420. }
  421.  
  422.  
  423.  
  424. /*
  425. **    Rename the selected entry with the name is given in
  426. **    the string gadget.
  427. */
  428. SAVEDS ASM LONG renamefunc( REG(a2) APTR obj )
  429. {
  430.     struct MUI_NListtree_TreeNode *tn;
  431.     STRPTR x;
  432.  
  433.     /*
  434.     **    Get user string.
  435.     */
  436.     get( st_string, MUIA_String_Contents, &x );
  437.     get( obj, MUIA_NListtree_Active, &tn );
  438.  
  439.     /*
  440.     **    Insert the new entry sorted (compare hook)
  441.     **    into the active list node.
  442.     */
  443.     DoMethod( obj, MUIM_NListtree_Rename, tn,
  444.         x, 0 );
  445.  
  446.     return( 0 );
  447. }
  448.  
  449.  
  450.  
  451. /*
  452. **    Insert a new entry which name is given in
  453. **    the string gadget.
  454. */
  455. SAVEDS ASM LONG movefunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  456. {
  457.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  458.     STATIC LONG movecnt = 0;
  459.     LONG x;
  460.  
  461.     if ( ( movecnt == 0 ) && ( (ULONG)*para == 42 ) )
  462.     {
  463.         get( obj, MUIA_NListtree_Active, &tn1 );
  464.  
  465.         if ( tn1 != MUIV_NListtree_Active_Off )
  466.         {
  467.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to insert after by simple click." );
  468.  
  469.             movecnt++;
  470.         }
  471.     }
  472.  
  473.     else if ( movecnt == 1 )
  474.     {
  475.         get( obj, MUIA_NListtree_Active, &tn2 );
  476.  
  477.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  478.         {
  479.             struct MUI_NListtree_ListNode *ln1;
  480.  
  481.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  482.             {
  483.                 DoMethod( obj, MUIM_NListtree_Move, ln1, tn1, MUIV_NListtree_Move_NewListNode_Active, tn2, 0 );
  484.  
  485.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully moved!" );
  486.             }
  487.             else
  488.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  489.         }
  490.         else
  491.             nnset( tx_info2, MUIA_Text_Contents, "You should not move an entry to itself!" );
  492.  
  493.         movecnt = 0;
  494.     }
  495.  
  496.     return( 0 );
  497. }
  498.  
  499.  
  500. /*
  501. **    Insert a new entry which name is given in
  502. **    the string gadget.
  503. */
  504. SAVEDS ASM LONG copyfunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  505. {
  506.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  507.     STATIC LONG copycnt = 0;
  508.     LONG x;
  509.  
  510.     if ( ( copycnt == 0 ) && ( (ULONG)*para == 42 ) )
  511.     {
  512.         get( obj, MUIA_NListtree_Active, &tn1 );
  513.  
  514.         if ( tn1 != MUIV_NListtree_Active_Off )
  515.         {
  516.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to insert after by simple click." );
  517.  
  518.             copycnt++;
  519.         }
  520.     }
  521.  
  522.     else if ( copycnt == 1 )
  523.     {
  524.         get( obj, MUIA_NListtree_Active, &tn2 );
  525.  
  526.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  527.         {
  528.             struct MUI_NListtree_ListNode *ln1;
  529.  
  530.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  531.             {
  532.                 DoMethod( obj, MUIM_NListtree_Copy, ln1, tn1, MUIV_NListtree_Copy_DestListNode_Active, tn2, 0 );
  533.  
  534.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully copied!" );
  535.             }
  536.             else
  537.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  538.         }
  539.         else
  540.             nnset( tx_info2, MUIA_Text_Contents, "You should not copy an entry to itself!" );
  541.  
  542.         copycnt = 0;
  543.     }
  544.  
  545.     return( 0 );
  546. }
  547.  
  548.  
  549.  
  550. /*
  551. **    Move KeepStructure
  552. */
  553. SAVEDS ASM LONG moveksfunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  554. {
  555.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  556.     STATIC LONG movekscnt = 0;
  557.     LONG x;
  558.  
  559.     if ( ( movekscnt == 0 ) && ( (ULONG)*para == 42 ) )
  560.     {
  561.         get( obj, MUIA_NListtree_Active, &tn1 );
  562.  
  563.         if ( tn1 != MUIV_NListtree_Active_Off )
  564.         {
  565.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to make KeepStructure move with." );
  566.  
  567.             movekscnt++;
  568.         }
  569.     }
  570.  
  571.     else if ( movekscnt == 1 )
  572.     {
  573.         get( obj, MUIA_NListtree_Active, &tn2 );
  574.  
  575.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  576.         {
  577.             struct MUI_NListtree_ListNode *ln1;
  578.  
  579.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  580.             {
  581.                 DoMethod( obj, MUIM_NListtree_Move, ln1, tn1, MUIV_NListtree_Move_NewListNode_Active, tn2, MUIV_NListtree_Move_Flag_KeepStructure );
  582.  
  583.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully moved (structure keeped)" );
  584.             }
  585.             else
  586.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  587.         }
  588.         else
  589.             nnset( tx_info2, MUIA_Text_Contents, "You should not move an entry to itself!" );
  590.  
  591.         movekscnt = 0;
  592.     }
  593.  
  594.     return( 0 );
  595. }
  596.  
  597.  
  598. /*
  599. **    Copy KeepStructure
  600. */
  601. SAVEDS ASM LONG copyksfunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  602. {
  603.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  604.     STATIC LONG copykscnt = 0;
  605.     LONG x;
  606.  
  607.     if ( ( copykscnt == 0 ) && ( (ULONG)*para == 42 ) )
  608.     {
  609.         get( obj, MUIA_NListtree_Active, &tn1 );
  610.  
  611.         if ( tn1 != MUIV_NListtree_Active_Off )
  612.         {
  613.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to make KeepStructure copy with." );
  614.  
  615.             copykscnt++;
  616.         }
  617.     }
  618.  
  619.     else if ( copykscnt == 1 )
  620.     {
  621.         get( obj, MUIA_NListtree_Active, &tn2 );
  622.  
  623.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  624.         {
  625.             struct MUI_NListtree_ListNode *ln1;
  626.  
  627.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  628.             {
  629.                 DoMethod( obj, MUIM_NListtree_Copy, ln1, tn1, MUIV_NListtree_Copy_DestListNode_Active, tn2, MUIV_NListtree_Copy_Flag_KeepStructure );
  630.  
  631.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully copied (structure keeped)" );
  632.             }
  633.             else
  634.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  635.         }
  636.         else
  637.             nnset( tx_info2, MUIA_Text_Contents, "You should not copy an entry to itself!" );
  638.  
  639.         copykscnt = 0;
  640.     }
  641.  
  642.     return( 0 );
  643. }
  644.  
  645.  
  646.  
  647. /*
  648. **    Find the specified tree node by name.
  649. */
  650. SAVEDS ASM LONG findnamefunc( REG(a2) APTR obj )
  651. {
  652.     struct MUI_NListtree_TreeNode *tn;
  653.     char buf[100];
  654.     STRPTR x;
  655.  
  656.     /*
  657.     **    Let us see, which string the user wants to search for...
  658.     */
  659.     get( st_string, MUIA_String_Contents, &x );
  660.  
  661.     /*
  662.     **    Is it somewhere in the tree?
  663.     */
  664.     if ( tn = (struct MUI_NListtree_TreeNode *)DoMethod(obj, MUIM_NListtree_FindName, MUIV_NListtree_FindName_ListNode_Root, x, 0 ) )
  665.     {
  666.         /*
  667.         **    If so, activate it (activation is only done
  668.         **    if entry is visible).
  669.         */
  670.         set( obj, MUIA_NListtree_Active, tn );
  671.     }
  672.     else
  673.     {
  674.         /*
  675.         **    Not found. Inform the user.
  676.         */
  677.         nnset( tx_info1, MUIA_Text_Contents, "NOT found specified node!" );
  678.         nnset( tx_info2, MUIA_Text_Contents, "" );
  679.     }
  680.  
  681.     return( 0 );
  682. }
  683.  
  684.  
  685.  
  686. /*
  687. **    Find the specified tree node by name.
  688. */
  689. SAVEDS ASM LONG getnrfunc( REG(a2) APTR obj )
  690. {
  691.     LONG temp;
  692.  
  693.     temp = DoMethod( obj, MUIM_NListtree_GetNr,
  694.         MUIV_NListtree_GetNr_TreeNode_Active, MUIV_NListtree_GetNr_Flag_CountLevel );
  695.  
  696.     if ( temp == 1 )
  697.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "1 entry in parent node." );
  698.     else
  699.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "%ld entries in parent node.", temp );
  700.  
  701.     return( 0 );
  702. }
  703.  
  704.  
  705. /*
  706. **    Find the specified tree node by name.
  707. */
  708. SAVEDS ASM LONG numselfunc( REG(a2) APTR obj )
  709. {
  710.     LONG temp = 0;
  711.  
  712.     DoMethod( obj, MUIM_NListtree_Select, MUIV_NListtree_Select_All,
  713.         MUIV_NListtree_Select_Ask, 0, &temp );
  714.  
  715.     if ( temp == 1 )
  716.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "1 node selected." );
  717.     else
  718.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "%ld nodes selected.", temp );
  719.  
  720.     return( 0 );
  721. }
  722.  
  723.  
  724.  
  725.  
  726.  
  727. /*
  728. **    Main
  729. */
  730. int main( int argc, STRPTR argv[] )
  731. {
  732.     ULONG signals;
  733.  
  734.  
  735.     /*
  736.     **    Is MUI V19 available?
  737.     */
  738.     if ( MUIMasterBase = OpenLibrary( "muimaster.library", 19 ) )
  739.     {
  740.         /*
  741.         **    Create application object.
  742.         */
  743.         app = ApplicationObject,
  744.             MUIA_Application_Title,            "NListtree-Demo",
  745.             MUIA_Application_Copyright,        "©1999-2000 by Apocalypse Hard- and Software",
  746.             MUIA_Application_Author,        "Carsten Scholling",
  747.             MUIA_Application_Description,    "Demonstration program for MUI class NListtree.mcc",
  748.             MUIA_Application_Base,            "NLISTTREEDEMO",
  749.  
  750.             /*
  751.             **    Build the window.
  752.             */
  753.             SubWindow, window = WindowObject,
  754.                 MUIA_Window_Title,            "NListtree-Demo",
  755.                 MUIA_Window_ID,                MAKE_ID( 'N', 'L', 'T', 'R' ),
  756.                 MUIA_Window_AppWindow,        TRUE,
  757.                 WindowContents,                VGroup,
  758.  
  759.                     /*
  760.                     **    Create a NListview embedded NListtree object
  761.                     */
  762.                     Child, NListviewObject,
  763.                         MUIA_ShortHelp,            "The NListtree object...",
  764.                         MUIA_NListview_NList,    lt_nodes = NListtreeObject,
  765.                             InputListFrame,
  766.                             MUIA_CycleChain,                TRUE,
  767.                             MUIA_NListtree_MultiSelect,        MUIV_NListtree_MultiSelect_Shifted,
  768.                             MUIA_NListtree_DisplayHook,        &dsphook,
  769.                             MUIA_NListtree_ConstructHook,    &conhook,
  770.                             MUIA_NListtree_DestructHook,    &deshook,
  771.                             //MUIA_NListtree_CompareHook,        MUIV_NListtree_CompareHook_LeavesMixed,
  772.                             MUIA_NListtree_CompareHook,        &comphook,
  773.                             MUIA_NListtree_DoubleClick,        MUIV_NListtree_DoubleClick_Tree,
  774.                             MUIA_NListtree_EmptyNodes,        FALSE,
  775.                             MUIA_NListtree_TreeColumn,        0,
  776.                             MUIA_NListtree_DragDropSort,    TRUE,
  777.                             MUIA_NListtree_Title,            TRUE,
  778.                             MUIA_NListtree_Format,            ",,",
  779.                         End,
  780.                     End,
  781.  
  782.                     /*
  783.                     **    Build some controls.
  784.                     */
  785.                     Child, tx_info1 = TextObject,
  786.                         MUIA_Background, MUII_TextBack,
  787.                         TextFrame,
  788.                     End,
  789.  
  790.                     Child, tx_info2 = TextObject,
  791.                         MUIA_Background, MUII_TextBack,
  792.                         TextFrame,
  793.                     End,
  794.  
  795.                     Child, ColGroup( 2 ),
  796.                         Child, FreeKeyLabel( "TreeCol:", 'c' ),
  797.                         Child, sl_treecol    = Slider( 0, 2, 0 ),
  798.                     End,
  799.  
  800.                     Child, HGroup,
  801.                         Child, st_string = StringObject,
  802.                             StringFrame,
  803.                             MUIA_String_MaxLen, 50,
  804.                         End,
  805.                     End,
  806.  
  807.  
  808.                     Child, ColGroup( 4 ),
  809.                         Child, bt_open        = KeyButton( "Open",        'o' ),
  810.                         Child, bt_close        = KeyButton( "Close",        'c' ),
  811.                         Child, bt_expand    = KeyButton( "Expand",        'e' ),
  812.                         Child, bt_collapse    = KeyButton( "Collapse",    'a' ),
  813.  
  814.                         Child, bt_insert    = KeyButton( "Insert",        'i' ),
  815.                         Child, bt_remove    = KeyButton( "Remove",        'r' ),
  816.                         Child, bt_exchange    = KeyButton( "Exchange",    'x' ),
  817.                         Child, bt_rename    = KeyButton( "Rename",        'r' ),
  818.  
  819.                         Child, bt_move        = KeyButton( "Move",        'm' ),
  820.                         Child, bt_copy        = KeyButton( "Copy",        'y' ),
  821.                         Child, bt_moveks    = KeyButton( "Move KS",        'v' ),
  822.                         Child, bt_copyks    = KeyButton( "Copy KS",        'k' ),
  823.  
  824.                         Child, bt_find        = KeyButton( "FindName",    'f' ),
  825.                         Child, bt_parent    = KeyButton( "Parent",        'p' ),
  826.                         Child, bt_sort        = KeyButton( "Sort",        's' ),
  827.                         Child, bt_getnr        = KeyButton( "GetNr",        'n' ),
  828.  
  829.                         Child, bt_redraw    = KeyButton( "Redraw",        'w' ),
  830.                         Child, bt_selected    = KeyButton( "Selected",    'd' ),
  831.                         Child, HVSpace,
  832.                         Child, HVSpace,
  833.                     End,
  834.  
  835.                 End,
  836.  
  837.             End,
  838.         End;
  839.  
  840.  
  841.         if( app )
  842.         {
  843.             /*
  844.             **    generate notifications
  845.             */
  846.             DoMethod( window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  847.                 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  848.  
  849.             /*
  850.             **    open/close/expand/collapse
  851.             */
  852.             DoMethod( bt_open, MUIM_Notify, MUIA_Pressed, FALSE,
  853.                 lt_nodes, 4, MUIM_NListtree_Open, MUIV_NListtree_Open_ListNode_Active, MUIV_NListtree_Open_TreeNode_Active, 0 );
  854.  
  855.             DoMethod( bt_close, MUIM_Notify, MUIA_Pressed, FALSE,
  856.                 lt_nodes, 4, MUIM_NListtree_Close, MUIV_NListtree_Close_ListNode_Active, MUIV_NListtree_Close_TreeNode_Active, 0 );
  857.  
  858.             DoMethod( bt_expand, MUIM_Notify, MUIA_Pressed, FALSE,
  859.                 lt_nodes, 4, MUIM_NListtree_Open, MUIV_NListtree_Open_ListNode_Root, MUIV_NListtree_Open_TreeNode_All, 0 );
  860.  
  861.             DoMethod( bt_collapse, MUIM_Notify, MUIA_Pressed, FALSE,
  862.                 lt_nodes, 4, MUIM_NListtree_Close, MUIV_NListtree_Close_ListNode_Root, MUIV_NListtree_Close_TreeNode_All, 0 );
  863.  
  864.  
  865.  
  866.             /*
  867.             **    insert/remove/exchange/rename
  868.             */
  869.             DoMethod( bt_insert, MUIM_Notify, MUIA_Pressed, FALSE,
  870.                 lt_nodes, 2, MUIM_CallHook, &inserthook );
  871.  
  872.             DoMethod( bt_remove, MUIM_Notify, MUIA_Pressed, FALSE,
  873.                 lt_nodes, 4, MUIM_NListtree_Remove, MUIV_NListtree_Remove_ListNode_Active, MUIV_NListtree_Remove_TreeNode_Active, 0 );
  874.  
  875.             DoMethod( bt_exchange, MUIM_Notify, MUIA_Pressed, FALSE,
  876.                 lt_nodes, 3, MUIM_CallHook, &exchangehook, 42 );
  877.  
  878.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  879.                 lt_nodes, 3, MUIM_CallHook, &exchangehook, 0 );
  880.  
  881.             DoMethod( bt_rename, MUIM_Notify, MUIA_Pressed, FALSE,
  882.                 lt_nodes, 2, MUIM_CallHook, &renamehook );
  883.  
  884.  
  885.             /*
  886.             **    move/copy/moveks/copyks
  887.             */
  888.             DoMethod( bt_move, MUIM_Notify, MUIA_Pressed, FALSE,
  889.                 lt_nodes, 3, MUIM_CallHook, &movehook, 42 );
  890.  
  891.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  892.                 lt_nodes, 3, MUIM_CallHook, &movehook, 0 );
  893.  
  894.             DoMethod( bt_copy, MUIM_Notify, MUIA_Pressed, FALSE,
  895.                 lt_nodes, 3, MUIM_CallHook, ©hook, 42 );
  896.  
  897.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  898.                 lt_nodes, 3, MUIM_CallHook, ©hook, 0 );
  899.  
  900.             DoMethod( bt_moveks, MUIM_Notify, MUIA_Pressed, FALSE,
  901.                 lt_nodes, 3, MUIM_CallHook, &movekshook, 42 );
  902.  
  903.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  904.                 lt_nodes, 3, MUIM_CallHook, &movekshook, 0 );
  905.  
  906.             DoMethod( bt_copyks, MUIM_Notify, MUIA_Pressed, FALSE,
  907.                 lt_nodes, 3, MUIM_CallHook, ©kshook, 42 );
  908.  
  909.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  910.                 lt_nodes, 3, MUIM_CallHook, ©kshook, 0 );
  911.  
  912.  
  913.             /*
  914.             **    find/parent/sort/getnr
  915.             */
  916.             DoMethod( bt_find, MUIM_Notify, MUIA_Pressed, FALSE,
  917.                 lt_nodes, 2, MUIM_CallHook, &findnamehook );
  918.  
  919.             DoMethod( bt_parent, MUIM_Notify, MUIA_Pressed, FALSE,
  920.                 lt_nodes, 3, MUIM_Set, MUIA_NListtree_Active, MUIV_NListtree_Active_Parent );
  921.  
  922.             DoMethod( bt_sort, MUIM_Notify, MUIA_Pressed, FALSE,
  923.                 lt_nodes, 3, MUIM_NListtree_Sort, MUIV_NListtree_Sort_TreeNode_Active, 0 );
  924.  
  925.             DoMethod( bt_getnr, MUIM_Notify, MUIA_Pressed, FALSE,
  926.                 lt_nodes, 2, MUIM_CallHook, &getnrhook );
  927.  
  928.  
  929.             /*
  930.             **    redraw/selected
  931.             */
  932.             DoMethod( bt_redraw, MUIM_Notify, MUIA_Pressed, FALSE,
  933.                 lt_nodes, 3, MUIM_NListtree_Redraw, MUIV_NListtree_Redraw_All );
  934.  
  935.             DoMethod( bt_selected, MUIM_Notify, MUIA_Pressed, FALSE,
  936.                 lt_nodes, 2, MUIM_CallHook, &numselhook );
  937.  
  938.  
  939.             /*
  940.             **    misc
  941.             */
  942.             DoMethod( sl_treecol, MUIM_Notify, MUIA_Slider_Level, MUIV_EveryTime,
  943.                 lt_nodes, 3, MUIM_Set, MUIA_NListtree_TreeColumn, MUIV_TriggerValue );
  944.  
  945.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  946.                 tx_info1, 4, MUIM_SetAsString, MUIA_Text_Contents, "Active node: 0x%08lx", MUIV_TriggerValue );
  947.  
  948.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_ActiveList, MUIV_EveryTime,
  949.                 tx_info2, 4, MUIM_SetAsString, MUIA_Text_Contents, "Active list: 0x%08lx", MUIV_TriggerValue );
  950.  
  951.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_DoubleClick, MUIV_EveryTime,
  952.                 tx_info1, 4, MUIM_SetAsString, MUIA_Text_Contents, "Double clicked on node: 0x%08lx", MUIV_TriggerValue );
  953.  
  954.  
  955.             /*
  956.             **    Open the window
  957.             **
  958.             */
  959.             set( window, MUIA_Window_Open, TRUE );
  960.  
  961.  
  962.             /*
  963.             **    Insert sample nodes
  964.             */
  965.             DrawSampleTree( lt_nodes );
  966.  
  967.  
  968.             /*
  969.             **    Minimal input loop.
  970.             */
  971.             while( DoMethod( app, MUIM_Application_NewInput, &signals ) != MUIV_Application_ReturnID_Quit )
  972.             {
  973.                 if ( signals )
  974.                 {
  975.                     signals = Wait( signals | SIGBREAKF_CTRL_C );
  976.  
  977.                     if ( signals & SIGBREAKF_CTRL_C )
  978.                         break;
  979.                 }
  980.             }
  981.  
  982.             /*
  983.             **    Close the window.
  984.             */
  985.             set( window, MUIA_Window_Open, FALSE );
  986.  
  987.  
  988.             /*
  989.             **    Shutdown
  990.             */
  991.             MUI_DisposeObject( app );
  992.         }
  993.         else
  994.             printf( "Failed to create Application.\n" );
  995.  
  996.  
  997.         CloseLibrary( MUIMasterBase );
  998.     }
  999.  
  1000.     return( 0 );
  1001. }
  1002.  
  1003.  
  1004.