4 * BGUI Tree List View class
6 * (C) Copyright 1999 Manuel Lemos.
7 * (C) Copyright 1996-1999 Nick Christie.
11 * Revision 42.5 2004/06/20 12:24:32 verhaegs
12 * Use REGFUNC macro's in BGUI source code, not AROS_UFH
14 * Revision 42.4 2004/06/16 20:16:49 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.3 2003/01/18 19:10:20 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.2 2000/07/09 03:05:09 bergers
21 * Makes the gadgets compilable.
23 * Revision 42.1 2000/05/15 19:29:08 stegerg
24 * replacements for REG macro
26 * Revision 42.0 2000/05/09 22:21:35 mlemos
27 * Bumped to revision 42.0 before handing BGUI to AROS team
29 * Revision 41.11 2000/05/09 20:35:20 mlemos
30 * Bumped to revision 41.11
32 * Revision 1.2 2000/05/09 20:00:20 mlemos
33 * Merged with the branch Manuel_Lemos_fixes.
35 * Revision 1.1.2.2 1999/05/31 01:12:43 mlemos
36 * Made the method functions take the arguments in the apropriate registers.
38 * Revision 1.1.2.1 1999/02/21 04:07:34 mlemos
39 * Nick Christie sources.
45 /************************************************************************
46 *********************** TREEVIEW CLASS: EXPAND ************************
47 ************************************************************************/
49 /************************************************************************
50 ****************************** INCLUDES *******************************
51 ************************************************************************/
53 #include "TreeViewPrivate.h"
56 /************************************************************************
57 ************************** LOCAL DEFINITIONS **************************
58 ************************************************************************/
61 /************************************************************************
62 ************************* EXTERNAL REFERENCES *************************
63 ************************************************************************/
66 * Functions from TVUtil are listed in TVUtil.h
69 /************************************************************************
70 ***************************** PROTOTYPES ******************************
71 ************************************************************************/
73 /************************************************************************
74 ***************************** LOCAL DATA ******************************
75 ************************************************************************/
78 /************************************************************************
79 ***************************** TV_EXPAND() *****************************
80 *************************************************************************
81 * Expand or contract one or more entries in the treeview. In the message
82 * structure for this method, the user supplies a reference to an entry,
83 * a code to indicate which entries to affect and some flags that allow
84 * further operations, eg. making an entry visible. This method returns
85 * non-zero if successful, zero on failure.
87 * Special values allowed for the reference entry are:
88 * TV_ROOT to represent the root of the tree (a dummy entry).
89 * TV_SELECTED for the (first) currently selected entry.
91 * If the relation entry is TV_SELECTED, but no entry is currently
92 * selected, nothing is done and zero is returned.
94 * Permitted values for the relationship code are as follows:
95 * TVW_ENTRY specified entry only
96 * TVW_PARENT parent of entry
97 * TVW_CHILD_FIRST first child of entry
98 * TVW_CHILD_LAST last child of entry
99 * TVW_CHILD_ALL all children of entry
100 * TVW_CHILD_TREE all children, recursively
101 * TVW_SIBLING_FIRST first sibling of entry
102 * TVW_SIBLING_LAST last sibling of entry
103 * TVW_SIBLING_NEXT next sibling of entry
104 * TVW_SIBLING_PREV prev. sibling of entry
105 * TVW_SIBLING_ALL entry and all siblings
106 * TVW_SIBLING_TREE entry, siblings and all children recursively
107 * TVW_TREE_NEXT next in tree from entry
108 * TVW_TREE_PREV prev. in tree from entry
109 * TVW_TREE_PAGE_UP page up in tree from entry
110 * TVW_TREE_PAGE_DOWN page down in tree from entry
112 * If the relation entry is TV_ROOT, only the TVW_CHILD_??? codes are
113 * permitted. To expand or contract all entries in the treeview,
114 * pass TV_ROOT as the reference entry and TVW_CHILD_TREE as the code.
116 * Permitted bits for the flags parameter are:
117 * TVF_SELECTED affect only selected entries
118 * TVF_VISIBLE affect only visible entries
119 * TVF_SELECT select entry
120 * TVF_DESELECT deselect entry
121 * TVF_MULTISELECT multi-select entry (with TVF_SELECT)
122 * TVF_MAKEVISIBLE make entry visible
123 * TVF_EXPAND expand entry (not required)
124 * TVF_CONTRACT contract entry
125 * TVF_TOGGLE toggle expand/contract
127 * The entry will be displayed in the treeview only if all its parents
128 * are expanded, or the flag TVF_MAKEVISIBLE is used. In that case,
129 * parents will be expanded as required to bring the new entry into view.
131 *************************************************************************/
133 //ASM ULONG TV_Expand(REG(a0) Class *cl,REG(a2) Object *obj,REG(a1) struct tvEntry *tve)
134 METHOD(TV_Expand
, struct tvEntry
*, tve
)
136 struct tvExpand tvexp
;
141 ULONG lvflags
,tnflags
;
146 TV_DebugDumpMethod((Msg
) tve
);
148 tv
= (TVData
*) INST_DATA(cl
,obj
);
152 memset(&tva
,0,sizeof(tva
));
153 refreshmethod
= TVM_REDRAW
;
156 * Find each treenode corresponding to this tvEntry.
159 while((tn
= TV_MatchNextEntry(tv
,tve
->tve_Entry
,tve
->tve_Which
,tve
->tve_Flags
,&tva
)))
162 * Find it's position in the listview (~0 if not displayed)
165 pos
= TV_TreeNodeToIndex(tv
,tn
);
168 * See if we are required to expand, contract or toggle the
169 * entry, and whether that's a change from the current state.
172 if (tve
->tve_Flags
& TVF_TOGGLE
)
174 tnflags
= tn
->tn_Flags
^ TNF_EXPANDED
;
177 else if ((tve
->tve_Flags
& TVF_CONTRACT
) && (tn
->tn_Flags
& TNF_EXPANDED
))
179 tnflags
= tn
->tn_Flags
& ~TNF_EXPANDED
;
182 else if (!(tn
->tn_Flags
& TNF_EXPANDED
))
184 tnflags
= tn
->tn_Flags
| TNF_EXPANDED
;
190 if (chg
) /* yes, it's a change of state */
193 * Confirm the change with the user's expand hook
196 tvexp
.tve_Command
= tnflags
& TNF_EXPANDED
? TVEC_EXPAND
: TVEC_CONTRACT
;
197 tvexp
.tve_Entry
= tve
->tve_Entry
;
199 if (tve
->tve_Flags
& TVF_USER_ACTION
)
200 tvexp
.tve_Flags
= TVEF_USER_ACTION
;
202 if (CallHookPkt(tv
->tv_ExpandHook
,tv
->tv_TreeView
,&tvexp
))
205 * Set the new state in the node
208 tn
->tn_Flags
= tnflags
;
209 rc
= tnflags
& TNF_EXPANDED
? 1 : ~0;
212 * See if the node has children and if it's displayed
213 * in the listview. If not, we don't have to insert
214 * its children in the listview.
217 if (HasChildren(tn
) && (pos
!= ~0))
219 if (rc
== 1) /* expand node */
222 * Insert each child, recursively, into the
223 * listview at incrementing position after
224 * the parent node that we expanded.
227 cn
= FirstChildOf(tn
);
229 depth
= TV_TreeNodeDepth(cn
);
234 ok
= (BOOL
) DoMethod(tv
->tv_Listview
,LVM_INSERTSINGLE
,
235 NULL
,pos
,cn
,lvflags
);
237 cn
= TV_GetNextTreeNode(cn
,TVF_VISIBLE
,depth
,~0);
240 else /* contract node */
243 * Remove each child, recursively, from the listview
246 cn
= FirstChildOf(tn
);
247 depth
= TV_TreeNodeDepth(cn
);
251 DoMethod(tv
->tv_Listview
,LVM_REMENTRY
,NULL
,cn
);
252 cn
= TV_GetNextTreeNode(cn
,TVF_VISIBLE
,depth
,~0);
257 * We will want the listview to refresh completely
258 * because we have inserted/removed entries
261 refreshmethod
= TVM_REFRESH
;
263 } /* endif node has children and is displayed */
266 * User wants us to make the expanded entry visible?
269 if (tve
->tve_Flags
& TVF_MAKEVISIBLE
)
270 DoMethod(obj
,TVM_VISIBLE
,NULL
,tn
,TVW_ENTRY
,TVF_INTERNAL
);
273 * User wants us to select the expanded entry, as well?
276 if (tve
->tve_Flags
& (TVF_SELECT
|TVF_DESELECT
))
277 DoMethod(obj
,TVM_SELECT
,NULL
,tn
,TVW_ENTRY
,TVF_INTERNAL
|
278 (tve
->tve_Flags
& (TVF_MULTISELECT
| TVF_DESELECT
)));
280 } /* endif expandhook return true */
282 } /* endif expand flag changed */
284 } /* endwhile match another entry */
289 * Refresh the listview:
293 DoMethod(obj
,refreshmethod
,tve
->tve_GInfo
);