OPT MODULE OPT EXPORT OPT PREPROCESS /* * BGUI Tree List View Class * * = C Copyright 1999 Manuel Lemos. * = C Copyright 1996-1999 Nick Christie. * All Rights Reserved. * */ MODULE 'intuition/classes', 'intuition/classusr', 'intuition/imageclass', 'intuition/gadgetclass', 'intuition/cghooks', 'intuition/screens', 'graphics/rastport', 'graphics/gfx', 'intuition/intuition', 'utility/tagitem' /************************************************************************ *************************** TREEVIEW CLASS **************************** ************************************************************************* * * NAME * * Class: treeviewclass [private] * SuperClass: groupclass [BGUI, public] * * * FUNCTION * * This is a BGUI gadget class that can display data with a hierarchical * or tree-like OBJECTure. In general appearance, it looks like a BGUI * listview, in fact, it currently uses a listview for basic control * and display purposes. * * The name of each member of the tree is displayed appropriately indented, * with a small box next to it containing a plus sign if the children of * the member have been expanded, a minus sign if not. By clicking on the * box, the user can expand or contract the child list. * * Like the BGUI listview, the treeview's native datatype for its * members is a C-style string. However, hooks are provided to allow * any type of data to be added to the tree. * * * NEW METHODS * * * * * CHANGED METHODS * * * * ATTRIBUTES * * TV_??? -- = ULONG = ISG-- * * * * EXTERNAL REQUIREMENTS * * Client must open these libraries: intuition.library V37+, * utility.library V37+ and bgui.library V40+ and provide their * base pointers. * * *************************************************************************/ /************************************************************************ ************************* PUBLIC DEFINITIONS ************************** ************************************************************************/ /* * Tags for class attributes */ CONST TAG_TVA_BASE = TAG_USER + $12340000 CONST TVA_ResourceHook = TAG_TVA_BASE+1 /* = I---- */ CONST TVA_DisplayHook = TAG_TVA_BASE+2 /* = I---- */ CONST TVA_CompareHook = TAG_TVA_BASE+3 /* = I---- */ CONST TVA_ExpandHook = TAG_TVA_BASE+4 /* = I---- */ CONST TVA_ImageStyle = TAG_TVA_BASE+5 /* = I---- */ CONST TVA_LineStyle = TAG_TVA_BASE+6 /* = I---- */ CONST TVA_ExpandedImage = TAG_TVA_BASE+7 /* = I---- */ CONST TVA_ContractedImage = TAG_TVA_BASE+8 /* = I---- */ CONST TVA_LeftAlignImage = TAG_TVA_BASE+9 /* = I---- */ CONST TVA_NoLeafImage = TAG_TVA_BASE+10 /* = I---- */ CONST TVA_CopyEntries = TAG_TVA_BASE+11 /* = I---- */ CONST TVA_Entry = TAG_TVA_BASE+20 /* = ---N- */ CONST TVA_Parent = TAG_TVA_BASE+21 /* = ---N- */ CONST TVA_Moved = TAG_TVA_BASE+22 /* = ---N- */ CONST TVA_NumEntries = TAG_TVA_BASE+30 /* = --G-- */ CONST TVA_LastClicked = TAG_TVA_BASE+31 /* = --G-- */ CONST TVA_ViewBounds = TAG_TVA_BASE+32 /* = --G-- */ CONST TVA_Indentation = TAG_TVA_BASE+40 /* = ISG-- */ CONST TVA_Top = TAG_TVA_BASE+41 /* = -SG-- */ /* * Tags for class methods */ CONST TAG_TVM_BASE = TAG_TVA_BASE+512 CONST TVM_INSERT = TAG_TVM_BASE+1 CONST TVM_REMOVE = TAG_TVM_BASE+2 CONST TVM_REPLACE = TAG_TVM_BASE+3 CONST TVM_MOVE = TAG_TVM_BASE+4 CONST TVM_GETENTRY = TAG_TVM_BASE+5 CONST TVM_SELECT = TAG_TVM_BASE+6 CONST TVM_VISIBLE = TAG_TVM_BASE+7 CONST TVM_EXPAND = TAG_TVM_BASE+8 CONST TVM_CLEAR = TAG_TVM_BASE+9 CONST TVM_LOCK = TAG_TVM_BASE+10 CONST TVM_UNLOCK = TAG_TVM_BASE+11 CONST TVM_SORT = TAG_TVM_BASE+12 CONST TVM_REDRAW = TAG_TVM_BASE+13 CONST TVM_REFRESH = TAG_TVM_BASE+14 CONST TVM_REBUILD = TAG_TVM_BASE+15 /* debug only! */ /* * Values for TVA_ImageStyle: */ CONST TVIS_BOX = 0 CONST TVIS_ARROW = 1 /* * Values for TVA_LineStyle: */ CONST TVLS_NONE = 0 CONST TVLS_DOTS = 1 CONST TVLS_DASH = 2 CONST TVLS_SOLID = 3 /* * Message OBJECTure for TVM_INSERT, TVM_MOVE: */ OBJECT tvInsert methodID:LONG /* TVM_INSERT, TVM_MOVE */ gInfo:PTR TO gadgetinfo /* GadgetInfo */ entry:PTR TO LONG /* entry to insert OR move */ relation:PTR TO LONG /* parent OR sibling entry */ where:LONG /* see below */ flags:LONG /* see below */ ENDOBJECT /* * Message OBJECTure for TVM_REPLACE */ OBJECT tvReplace methodID:LONG /* TVM_REPLACE */ gInfo:PTR TO gadgetinfo /* GadgetInfo */ newEntry:PTR TO LONG /* entry to replace with */ oldEntry:PTR TO LONG /* entry to replace */ where:LONG /* see below */ flags:LONG /* see below */ ENDOBJECT /* * Message OBJECTure for TVM_GETENTRY: */ OBJECT tvGet methodID:LONG /* TVM_GET */ entry:PTR TO LONG /* parent OR sibling, etc */ which:LONG /* see below */ flags:LONG /* see below */ ENDOBJECT /* * Message OBJECTure for TVM_REMOVE, TVM_SELECT, * TVM_VISIBLE, TVM_EXPAND: */ OBJECT tvEntry methodID:LONG /* TVM_REMOVE, etc */ gInfo:PTR TO gadgetinfo /* GadgetInfo */ entry:PTR TO LONG /* entry, parent OR sibling, etc */ which:LONG /* see below */ flags:LONG /* see below */ ENDOBJECT /* * Message OBJECTure for TVM_LOCK consists of only the MethodID. */ /* * Message OBJECTure for TVM_SORT, TVM_REDRAW, TVM_REFRESH, * TVM_CLEAR and TVM_UNLOCK: */ OBJECT tvCommand methodID:LONG /* method ID value */ gInfo:PTR TO gadgetinfo /* GadgetInfo */ ENDOBJECT /* * Special values for any pointer to an existing entry: */ CONST TV_ROOT = 0 /* dummy root entry */ CONST TV_SELECTED = 1 /* first selected entry */ /* * For internal use only */ CONST TVWC_ENTRY = 0 CONST TVWC_PARENT = $10000 CONST TVWC_CHILD = $20000 CONST TVWC_SIB = $30000 CONST TVWC_TREE = $40000 CONST TVWC_MASK = $70000 CONST TVWS_FIRST = 1 CONST TVWS_LAST = 2 CONST TVWS_NEXT = 3 CONST TVWS_PREV = 4 CONST TVWS_PGUP = 5 CONST TVWS_PGDN = 6 CONST TVWS_SORT = 7 CONST TVWS_ALL = 8 CONST TVWS_TREE = 9 CONST TVWS_MASK = 15 /* * Values for tv?_Which and tv?_Where: * * Key: I = insert, R = remove, P = replace, M = move, G = get, * S = select, V = visible, E = expand */ CONST TVW_ENTRY = TVWC_ENTRY /* specified entry only = R,P,G,S,V,E */ CONST TVW_PARENT = TVWC_PARENT /* parent of entry = R,P,G,S,V,E */ CONST TVW_CHILD_FIRST = TVWC_CHILD OR TVWS_FIRST /* first child of entry = I,R,P,M,G,S,V,E */ CONST TVW_CHILD_LAST = TVWC_CHILD OR TVWS_LAST /* last child of entry = I,R,P,M,G,S,V,E */ CONST TVW_CHILD_SORTED = TVWC_CHILD OR TVWS_SORT /* child of entry, sorted = I,P,M */ CONST TVW_CHILD_ALL = TVWC_CHILD OR TVWS_ALL /* all children of entry = R,P,S,E */ CONST TVW_CHILD_TREE = TVWC_CHILD OR TVWS_TREE /* all children, recursively = S,E */ CONST TVW_SIBLING_FIRST = TVWC_SIB OR TVWS_FIRST /* first sibling of entry = I,R,P,M,G,S,V,E */ CONST TVW_SIBLING_LAST = TVWC_SIB OR TVWS_LAST /* last sibling of entry = I,R,P,M,G,S,V,E */ CONST TVW_SIBLING_NEXT = TVWC_SIB OR TVWS_NEXT /* next sibling of entry = I,R,P,M,G,S,V,E */ CONST TVW_SIBLING_PREV = TVWC_SIB OR TVWS_PREV /* prev. sibling of entry = I,R,P,M,G,S,V,E */ CONST TVW_SIBLING_SORTED = TVWC_SIB OR TVWS_SORT /* sibling of entry, sorted = I,P,M */ CONST TVW_SIBLING_ALL = TVWC_SIB OR TVWS_ALL /* entry AND all siblings = R,P,S,E */ CONST TVW_SIBLING_TREE = TVWC_SIB OR TVWS_TREE /* entry, siblings AND all children recursively = S,E */ CONST TVW_TREE_FIRST = TVWC_TREE OR TVWS_FIRST /* first in tree, entry ignored = R,G,S,V,E */ CONST TVW_TREE_LAST = TVWC_TREE OR TVWS_LAST /* last in tree, entry ignored = R,G,S,V,E */ CONST TVW_TREE_NEXT = TVWC_TREE OR TVWS_NEXT /* next in tree from entry = R,G,S,V,E */ CONST TVW_TREE_PREV = TVWC_TREE OR TVWS_PREV /* prev. in tree from entry = R,G,S,V,E */ CONST TVW_TREE_PAGE_UP = TVWC_TREE OR TVWS_PGDN /* page up in tree from entry = G,S,V,E */ CONST TVW_TREE_PAGE_DOWN = TVWC_TREE OR TVWS_PGUP /* page down in tree from entry = G,S,V,E */ /* * Bits for tv?_Flags: */ CONST TVF_ALL = 0 /* dummy flag FOR all entries */ CONST TVF_SELECTED = 1 /* affect only selected entries = R,P,G,V,E */ CONST TVF_VISIBLE = 2 /* affect only visible entries = R,P,G,E */ CONST TVF_SELECT = $100 /* select entry = I,P,M,V,E */ CONST TVF_DESELECT = $200 /* deselect entry = P,M,S,V,E */ CONST TVF_MULTISELECT = $400 /* multi-select entry = with TVF_SELECT */ CONST TVF_MAKEVISIBLE = $800 /* make entry visible = I,P,M,S,E */ CONST TVF_EXPAND = $1000 /* expand entry = I,P,M,S,V */ CONST TVF_CONTRACT = $2000 /* contract entry = P,M,S,V,E */ CONST TVF_TOGGLE = $4000 /* toggle selection/expansion = S,E */ CONST TVF_USER_ACTION = $40000000 /* private */ CONST TVF_INTERNAL = $80000000 /* private */ /* * The TV_ResourceHook is called as follows: * * rc = hookFunc= REG= A0 OBJECT Hook *hook, * REG= A2 Object *tv_object, * REG= A1 OBJECT tvResource *message ; * * On make, return a pointer to the entry to be added, or NULL. * On kill, return 0. */ OBJECT tvResource command:INT /* whether to make OR kill */ entry:PTR TO LONG /* entry to be added OR removed */ ENDOBJECT /* * TV_ResourceHook commands in tvr_Command */ CONST TVRC_MAKE = 1 /* Build the entry. */ CONST TVRC_KILL = 2 /* Kill the entry. */ /* * The TV_DisplayHook is called as follows: * * rc = hookFunc= REG= A0 OBJECT Hook *hook, * REG= A2 Object *tv_object, * REG= A1 OBJECT tvRender *message ; * * If your hook completes all rendering, return 0. If you wish * the treeview to render a string, return the string, which * may have BGUI-style formatting sequences embedded in it. */ OBJECT tvRender rPort:PTR TO rastport /* rastport to render in */ drawInfo:PTR TO drawinfo /* all you need to render */ bounds:rectangle /* bounds to render in */ entry:PTR TO LONG /* entry to render */ state:INT /* see below */ flags:INT /* see below */ ENDOBJECT /* * Rendering states in lvr_State */ CONST TVRS_NORMAL = 0 /* normal, enabled state */ CONST TVRS_SELECTED = 1 /* selected AND enabled */ CONST TVRS_NORMAL_DISABLED = 2 /* normal disabled state */ CONST TVRS_SELECTED_DISABLED = 3 /* selected AND disabled */ /* * Flag bits in lvr_Flags */ CONST TVRF_EXPANDED = 1 /* entry is expanded */ /* * The TV_CompareHook is called as follows: * * rc = hookFunc= REG= A0 OBJECT Hook *hook, * REG= A2 Object *tv_object, * REG= A1 OBJECT tvCompare *message ; * * Your hook must return -1 when entry A should come before entry B, 0 when * entry A is equal to entry B and 1 when entry A should come after entry B. */ OBJECT tvCompare entryA:PTR TO LONG /* first entry */ entryB:PTR TO LONG /* second entry */ ENDOBJECT /* * The TV_ExpandHook is called as follows: * * rc = hookFunc= (REG= A0 OBJECT Hook *hook, * REG= A2 Object *tv_object, * REG= A1 OBJECT tvExpand *message) ; * * Your hook should return non-zero if the expansion or contraction * is to go ahead, zero if it should be cancelled. * * Important: Your hook may *not* invoke any methods on the treeview. */ OBJECT tvExpand command:INT /* whether to expand OR contract */ entry:PTR TO LONG /* entry to be expanded/contracted */ flags:LONG /* see below */ ENDOBJECT /* * tvExpand commands in tve_Command */ CONST TVEC_EXPAND = 1 /* entry is to be expanded */ CONST TVEC_CONTRACT = 2 /* entry is to be contracted */ /* * Flag bits in tve_Flags */ CONST TVEF_USER_ACTION = 1 /* hook called due to user action */