home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / BGUI / bgui_e / sources / emodules / bgui / bgui_treeview.e < prev   
Encoding:
Text File  |  1999-08-28  |  12.6 KB  |  388 lines

  1. OPT MODULE
  2. OPT EXPORT
  3. OPT PREPROCESS
  4.  
  5. /*
  6.  * BGUI Tree List View Class
  7.  *
  8.  * = C Copyright 1999 Manuel Lemos.
  9.  * = C Copyright 1996-1999 Nick Christie.
  10.  * All Rights Reserved.
  11.  *
  12.  */
  13.  
  14. MODULE  'intuition/classes', 'intuition/classusr', 'intuition/imageclass',
  15.         'intuition/gadgetclass', 'intuition/cghooks', 'intuition/screens',
  16.         'graphics/rastport', 'graphics/gfx', 'intuition/intuition',
  17.         'utility/tagitem'
  18.  
  19. /************************************************************************
  20. ***************************  TREEVIEW CLASS  ****************************
  21. *************************************************************************
  22. *
  23. * NAME
  24. *
  25. * Class:        treeviewclass [private]
  26. * SuperClass:   groupclass [BGUI, public]
  27. *
  28. *
  29. * FUNCTION
  30. *
  31. * This is a BGUI gadget class that can display data with a hierarchical
  32. * or tree-like OBJECTure. In general appearance, it looks like a BGUI
  33. * listview, in fact, it currently uses a listview for basic control
  34. * and display purposes.
  35. *
  36. * The name of each member of the tree is displayed appropriately indented,
  37. * with a small box next to it containing a plus sign if the children of
  38. * the member have been expanded, a minus sign if not. By clicking on the
  39. * box, the user can expand or contract the child list.
  40. *
  41. * Like the BGUI listview, the treeview's native datatype for its
  42. * members is a C-style string. However, hooks are provided to allow
  43. * any type of data to be added to the tree.
  44. *
  45. *
  46. * NEW METHODS
  47. *
  48. *
  49. *
  50. *
  51. * CHANGED METHODS
  52. *
  53. *
  54. *
  55. * ATTRIBUTES
  56. *
  57. * TV_??? -- = ULONG             = ISG--
  58. *
  59. *
  60. *
  61. * EXTERNAL REQUIREMENTS
  62. *
  63. * Client must open these libraries: intuition.library V37+,
  64. * utility.library V37+ and bgui.library V40+ and provide their
  65. * base pointers.
  66. *
  67. *
  68. *************************************************************************/
  69.  
  70. /************************************************************************
  71. *************************  PUBLIC DEFINITIONS  **************************
  72. ************************************************************************/
  73.  
  74. /*
  75.  * Tags for class attributes
  76.  */
  77.  
  78. CONST TAG_TVA_BASE        = TAG_USER + $12340000
  79.  
  80. CONST TVA_ResourceHook    = TAG_TVA_BASE+1    /* = I---- */
  81. CONST TVA_DisplayHook     = TAG_TVA_BASE+2    /* = I---- */
  82. CONST TVA_CompareHook     = TAG_TVA_BASE+3    /* = I---- */
  83. CONST TVA_ExpandHook      = TAG_TVA_BASE+4    /* = I---- */
  84. CONST TVA_ImageStyle      = TAG_TVA_BASE+5    /* = I---- */
  85. CONST TVA_LineStyle       = TAG_TVA_BASE+6    /* = I---- */
  86. CONST TVA_ExpandedImage   = TAG_TVA_BASE+7    /* = I---- */
  87. CONST TVA_ContractedImage = TAG_TVA_BASE+8    /* = I---- */
  88. CONST TVA_LeftAlignImage  = TAG_TVA_BASE+9    /* = I---- */
  89. CONST TVA_NoLeafImage     = TAG_TVA_BASE+10   /* = I---- */
  90. CONST TVA_CopyEntries     = TAG_TVA_BASE+11   /* = I---- */
  91. CONST TVA_Entry           = TAG_TVA_BASE+20   /* = ---N- */
  92. CONST TVA_Parent          = TAG_TVA_BASE+21   /* = ---N- */
  93. CONST TVA_Moved           = TAG_TVA_BASE+22   /* = ---N- */
  94. CONST TVA_NumEntries      = TAG_TVA_BASE+30   /* = --G-- */
  95. CONST TVA_LastClicked     = TAG_TVA_BASE+31   /* = --G-- */
  96. CONST TVA_ViewBounds      = TAG_TVA_BASE+32   /* = --G-- */
  97. CONST TVA_Indentation     = TAG_TVA_BASE+40   /* = ISG-- */
  98. CONST TVA_Top             = TAG_TVA_BASE+41   /* = -SG-- */
  99.  
  100. /*
  101.  * Tags for class methods
  102.  */
  103.  
  104. CONST TAG_TVM_BASE        = TAG_TVA_BASE+512
  105.  
  106. CONST TVM_INSERT          = TAG_TVM_BASE+1
  107. CONST TVM_REMOVE          = TAG_TVM_BASE+2
  108. CONST TVM_REPLACE         = TAG_TVM_BASE+3
  109. CONST TVM_MOVE            = TAG_TVM_BASE+4
  110. CONST TVM_GETENTRY        = TAG_TVM_BASE+5
  111. CONST TVM_SELECT          = TAG_TVM_BASE+6
  112. CONST TVM_VISIBLE         = TAG_TVM_BASE+7
  113. CONST TVM_EXPAND          = TAG_TVM_BASE+8
  114. CONST TVM_CLEAR           = TAG_TVM_BASE+9
  115. CONST TVM_LOCK            = TAG_TVM_BASE+10
  116. CONST TVM_UNLOCK          = TAG_TVM_BASE+11
  117. CONST TVM_SORT            = TAG_TVM_BASE+12
  118. CONST TVM_REDRAW          = TAG_TVM_BASE+13
  119. CONST TVM_REFRESH         = TAG_TVM_BASE+14
  120. CONST TVM_REBUILD         = TAG_TVM_BASE+15       /* debug only! */
  121.  
  122. /*
  123.  * Values for TVA_ImageStyle:
  124.  */
  125.  
  126. CONST TVIS_BOX            = 0
  127. CONST TVIS_ARROW          = 1
  128.  
  129. /*
  130.  * Values for TVA_LineStyle:
  131.  */
  132.  
  133. CONST TVLS_NONE           = 0
  134. CONST TVLS_DOTS           = 1
  135. CONST TVLS_DASH           = 2
  136. CONST TVLS_SOLID          = 3
  137.  
  138. /*
  139.  * Message OBJECTure for TVM_INSERT, TVM_MOVE:
  140.  */
  141.  
  142. OBJECT tvInsert
  143.     methodID:LONG               /* TVM_INSERT, TVM_MOVE */
  144.     gInfo:PTR TO gadgetinfo     /* GadgetInfo */
  145.     entry:PTR TO LONG           /* entry to insert OR move */
  146.     relation:PTR TO LONG        /* parent OR sibling entry */
  147.     where:LONG                  /* see below */
  148.     flags:LONG                  /* see below */
  149. ENDOBJECT
  150.  
  151. /*
  152.  * Message OBJECTure for TVM_REPLACE
  153.  */
  154.  
  155. OBJECT tvReplace
  156.     methodID:LONG               /* TVM_REPLACE */
  157.     gInfo:PTR TO gadgetinfo     /* GadgetInfo */
  158.     newEntry:PTR TO LONG        /* entry to replace with */
  159.     oldEntry:PTR TO LONG        /* entry to replace */
  160.     where:LONG                  /* see below */
  161.     flags:LONG                  /* see below */
  162. ENDOBJECT
  163.  
  164. /*
  165.  * Message OBJECTure for TVM_GETENTRY:
  166.  */
  167.  
  168. OBJECT tvGet
  169.     methodID:LONG               /* TVM_GET */
  170.     entry:PTR TO LONG           /* parent OR sibling, etc */
  171.     which:LONG                  /* see below */
  172.     flags:LONG                  /* see below */
  173. ENDOBJECT
  174.  
  175. /*
  176.  * Message OBJECTure for TVM_REMOVE, TVM_SELECT,
  177.  * TVM_VISIBLE, TVM_EXPAND:
  178.  */
  179.  
  180. OBJECT tvEntry
  181.     methodID:LONG               /* TVM_REMOVE, etc */
  182.     gInfo:PTR TO gadgetinfo     /* GadgetInfo */
  183.     entry:PTR TO LONG           /* entry, parent OR sibling, etc */
  184.     which:LONG                  /* see below */
  185.     flags:LONG                  /* see below */
  186. ENDOBJECT
  187.  
  188. /*
  189.  * Message OBJECTure for TVM_LOCK consists of only the MethodID.
  190.  */
  191.  
  192. /*
  193.  * Message OBJECTure for TVM_SORT, TVM_REDRAW, TVM_REFRESH,
  194.  * TVM_CLEAR and TVM_UNLOCK:
  195.  */
  196.  
  197. OBJECT tvCommand
  198.     methodID:LONG               /* method ID value */
  199.     gInfo:PTR TO gadgetinfo     /* GadgetInfo */
  200. ENDOBJECT
  201.  
  202. /*
  203.  * Special values for any pointer to an existing entry:
  204.  */
  205.  
  206. CONST TV_ROOT         = 0     /* dummy root entry */
  207. CONST TV_SELECTED     = 1     /* first selected entry */
  208.  
  209. /*
  210.  * For internal use only
  211.  */
  212.  
  213. CONST TVWC_ENTRY          = 0
  214. CONST TVWC_PARENT         = $10000
  215. CONST TVWC_CHILD          = $20000
  216. CONST TVWC_SIB            = $30000
  217. CONST TVWC_TREE           = $40000
  218. CONST TVWC_MASK           = $70000
  219.  
  220. CONST TVWS_FIRST          = 1
  221. CONST TVWS_LAST           = 2
  222. CONST TVWS_NEXT           = 3
  223. CONST TVWS_PREV           = 4
  224. CONST TVWS_PGUP           = 5
  225. CONST TVWS_PGDN           = 6
  226. CONST TVWS_SORT           = 7
  227. CONST TVWS_ALL            = 8
  228. CONST TVWS_TREE           = 9
  229. CONST TVWS_MASK           = 15
  230.  
  231. /*
  232.  * Values for tv?_Which and tv?_Where:
  233.  *
  234.  * Key: I = insert, R = remove, P = replace, M = move, G = get,
  235.  *      S = select, V = visible, E = expand
  236.  */
  237.  
  238. CONST TVW_ENTRY           = TVWC_ENTRY            /* specified entry only = R,P,G,S,V,E */
  239. CONST TVW_PARENT          = TVWC_PARENT           /* parent of entry = R,P,G,S,V,E */
  240. CONST TVW_CHILD_FIRST     = TVWC_CHILD OR TVWS_FIRST /* first child of entry = I,R,P,M,G,S,V,E */
  241. CONST TVW_CHILD_LAST      = TVWC_CHILD OR TVWS_LAST  /* last child of entry = I,R,P,M,G,S,V,E */
  242. CONST TVW_CHILD_SORTED    = TVWC_CHILD OR TVWS_SORT  /* child of entry, sorted = I,P,M */
  243. CONST TVW_CHILD_ALL       = TVWC_CHILD OR TVWS_ALL   /* all children of entry = R,P,S,E */
  244. CONST TVW_CHILD_TREE      = TVWC_CHILD OR TVWS_TREE  /* all children, recursively = S,E */
  245. CONST TVW_SIBLING_FIRST   = TVWC_SIB OR TVWS_FIRST   /* first sibling of entry = I,R,P,M,G,S,V,E */
  246. CONST TVW_SIBLING_LAST    = TVWC_SIB OR TVWS_LAST    /* last sibling of entry = I,R,P,M,G,S,V,E */
  247. CONST TVW_SIBLING_NEXT    = TVWC_SIB OR TVWS_NEXT    /* next sibling of entry = I,R,P,M,G,S,V,E */
  248. CONST TVW_SIBLING_PREV    = TVWC_SIB OR TVWS_PREV    /* prev. sibling of entry = I,R,P,M,G,S,V,E */
  249. CONST TVW_SIBLING_SORTED  = TVWC_SIB OR TVWS_SORT    /* sibling of entry, sorted = I,P,M */
  250. CONST TVW_SIBLING_ALL     = TVWC_SIB OR TVWS_ALL     /* entry AND all siblings = R,P,S,E */
  251. CONST TVW_SIBLING_TREE    = TVWC_SIB OR TVWS_TREE    /* entry, siblings AND all children recursively = S,E */
  252. CONST TVW_TREE_FIRST      = TVWC_TREE OR TVWS_FIRST  /* first in tree, entry ignored = R,G,S,V,E */
  253. CONST TVW_TREE_LAST       = TVWC_TREE OR TVWS_LAST   /* last in tree, entry ignored = R,G,S,V,E */
  254. CONST TVW_TREE_NEXT       = TVWC_TREE OR TVWS_NEXT   /* next in tree from entry = R,G,S,V,E */
  255. CONST TVW_TREE_PREV       = TVWC_TREE OR TVWS_PREV   /* prev. in tree from entry = R,G,S,V,E */
  256. CONST TVW_TREE_PAGE_UP    = TVWC_TREE OR TVWS_PGDN   /* page up in tree from entry = G,S,V,E */
  257. CONST TVW_TREE_PAGE_DOWN  = TVWC_TREE OR TVWS_PGUP   /* page down in tree from entry = G,S,V,E */
  258.  
  259. /*
  260.  * Bits for tv?_Flags:
  261.  */
  262.  
  263. CONST TVF_ALL             = 0          /* dummy flag FOR all entries */
  264. CONST TVF_SELECTED        = 1          /* affect only selected entries = R,P,G,V,E */
  265. CONST TVF_VISIBLE         = 2          /* affect only visible entries = R,P,G,E */
  266.  
  267. CONST TVF_SELECT          = $100        /* select entry = I,P,M,V,E */
  268. CONST TVF_DESELECT        = $200        /* deselect entry = P,M,S,V,E */
  269. CONST TVF_MULTISELECT     = $400        /* multi-select entry = with TVF_SELECT */
  270. CONST TVF_MAKEVISIBLE     = $800        /* make entry visible = I,P,M,S,E */
  271. CONST TVF_EXPAND          = $1000       /* expand entry = I,P,M,S,V */
  272. CONST TVF_CONTRACT        = $2000       /* contract entry = P,M,S,V,E */
  273. CONST TVF_TOGGLE          = $4000       /* toggle selection/expansion = S,E */
  274.  
  275. CONST TVF_USER_ACTION     = $40000000    /* private */
  276. CONST TVF_INTERNAL        = $80000000    /* private */
  277.  
  278. /*
  279.  * The TV_ResourceHook is called as follows:
  280.  *
  281.  * rc = hookFunc=  REG= A0 OBJECT Hook *hook,
  282.  *                REG= A2 Object *tv_object,
  283.  *                REG= A1 OBJECT tvResource *message ;
  284.  *
  285.  * On make, return a pointer to the entry to be added, or NULL.
  286.  * On kill, return 0.
  287.  */
  288.  
  289. OBJECT tvResource
  290.     command:INT                 /* whether to make OR kill */
  291.     entry:PTR TO LONG           /* entry to be added OR removed */
  292. ENDOBJECT
  293.  
  294. /*
  295.  * TV_ResourceHook commands in tvr_Command
  296.  */
  297.  
  298. CONST TVRC_MAKE       = 1               /* Build the entry. */
  299. CONST TVRC_KILL       = 2               /* Kill the entry.  */
  300.  
  301. /*
  302.  * The TV_DisplayHook is called as follows:
  303.  *
  304.  * rc = hookFunc=  REG= A0 OBJECT Hook *hook,
  305.  *                REG= A2 Object *tv_object,
  306.  *                REG= A1 OBJECT tvRender *message ;
  307.  *
  308.  * If your hook completes all rendering, return 0. If you wish
  309.  * the treeview to render a string, return the string, which
  310.  * may have BGUI-style formatting sequences embedded in it.
  311.  */
  312.  
  313. OBJECT tvRender
  314.     rPort:PTR TO rastport           /* rastport to render in */
  315.     drawInfo:PTR TO drawinfo        /* all you need to render */
  316.     bounds:rectangle                /* bounds to render in */
  317.     entry:PTR TO LONG               /* entry to render */
  318.     state:INT                       /* see below */
  319.     flags:INT                       /* see below */
  320. ENDOBJECT
  321.  
  322. /*
  323.  * Rendering states in lvr_State
  324.  */
  325.  
  326. CONST TVRS_NORMAL             = 0       /* normal, enabled state */
  327. CONST TVRS_SELECTED           = 1       /* selected AND enabled */
  328. CONST TVRS_NORMAL_DISABLED    = 2       /* normal disabled state */
  329. CONST TVRS_SELECTED_DISABLED  = 3       /* selected AND disabled */
  330.  
  331. /*
  332.  * Flag bits in lvr_Flags
  333.  */
  334.  
  335. CONST TVRF_EXPANDED       = 1     /* entry is expanded */
  336.  
  337. /*
  338.  * The TV_CompareHook is called as follows:
  339.  *
  340.  * rc = hookFunc=  REG= A0 OBJECT Hook *hook,
  341.  *                REG= A2 Object *tv_object,
  342.  *                REG= A1 OBJECT tvCompare *message ;
  343.  *
  344.  * Your hook must return -1 when entry A should come before entry B, 0 when
  345.  * entry A is equal to entry B and 1 when entry A should come after entry B.
  346.  */
  347.  
  348. OBJECT tvCompare
  349.     entryA:PTR TO LONG         /* first entry */
  350.     entryB:PTR TO LONG         /* second entry */
  351. ENDOBJECT
  352.  
  353. /*
  354.  * The TV_ExpandHook is called as follows:
  355.  *
  356.  * rc = hookFunc=  (REG= A0 OBJECT Hook *hook,
  357.  *                REG= A2 Object *tv_object,
  358.  *                REG= A1 OBJECT tvExpand *message) ;
  359.  *
  360.  * Your hook should return non-zero if the expansion or contraction
  361.  * is to go ahead, zero if it should be cancelled.
  362.  *
  363.  * Important: Your hook may *not* invoke any methods on the treeview.
  364.  */
  365.  
  366. OBJECT tvExpand
  367.     command:INT                 /* whether to expand OR contract */
  368.     entry:PTR TO LONG           /* entry to be expanded/contracted */
  369.     flags:LONG                  /* see below */
  370. ENDOBJECT
  371.  
  372. /*
  373.  * tvExpand commands in tve_Command
  374.  */
  375.  
  376. CONST TVEC_EXPAND         = 1           /* entry is to be expanded */
  377. CONST TVEC_CONTRACT       = 2           /* entry is to be contracted */
  378.  
  379. /*
  380.  * Flag bits in tve_Flags
  381.  */
  382.  
  383. CONST TVEF_USER_ACTION    = 1     /* hook called due to user action */
  384.  
  385.  
  386.  
  387.  
  388.