forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / bgui / gadgets / TreeView / TVSelect.c
blobc007e75720c260289493dbad6b40a224916bd019
1 /*
2 * @(#) $Header$
4 * BGUI Tree List View class
6 * (C) Copyright 1999 Manuel Lemos.
7 * (C) Copyright 1996-1999 Nick Christie.
8 * All Rights Reserved.
10 * $Log$
11 * Revision 42.2 2004/06/16 20:16:49 verhaegs
12 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
14 * Revision 42.1 2000/05/15 19:29:08 stegerg
15 * replacements for REG macro
17 * Revision 42.0 2000/05/09 22:22:02 mlemos
18 * Bumped to revision 42.0 before handing BGUI to AROS team
20 * Revision 41.11 2000/05/09 20:35:50 mlemos
21 * Bumped to revision 41.11
23 * Revision 1.2 2000/05/09 20:00:46 mlemos
24 * Merged with the branch Manuel_Lemos_fixes.
26 * Revision 1.1.2.2 1999/05/31 01:12:58 mlemos
27 * Made the method functions take the arguments in the apropriate registers.
29 * Revision 1.1.2.1 1999/02/21 04:08:04 mlemos
30 * Nick Christie sources.
36 /************************************************************************
37 *********************** TREEVIEW CLASS: SELECT ************************
38 ************************************************************************/
40 /************************************************************************
41 ****************************** INCLUDES *******************************
42 ************************************************************************/
44 #include "TreeViewPrivate.h"
45 #include "TVUtil.h"
47 /************************************************************************
48 ************************** LOCAL DEFINITIONS **************************
49 ************************************************************************/
52 /************************************************************************
53 ************************* EXTERNAL REFERENCES *************************
54 ************************************************************************/
57 * Functions from TVUtil are listed in TVUtil.h
60 /************************************************************************
61 ***************************** PROTOTYPES ******************************
62 ************************************************************************/
65 /************************************************************************
66 ***************************** LOCAL DATA ******************************
67 ************************************************************************/
70 /************************************************************************
71 ***************************** TV_SELECT() *****************************
72 *************************************************************************
73 * Select or deselect entries in the treeview. In the message structure
74 * for this method, the user supplies a reference to an entry, a code
75 * to indicate which entries to consider, and flags to further alter the
76 * mode of operation. This method selects or deselects the matching
77 * entries and returns the number of entries affected. Only visible
78 * entries may be selected.
80 * Special values allowed for the reference entry are:
81 * TV_ROOT to represent the root of the tree (a dummy entry).
82 * TV_SELECTED for the (first) currently selected entry.
84 * If the relation entry is TV_SELECTED, but no entry is currently
85 * selected, nothing is done and zero is returned.
87 * Permitted values for the relationship code are as follows:
88 * TVW_ENTRY specified entry only
89 * TVW_PARENT parent of entry
90 * TVW_CHILD_FIRST first child of entry
91 * TVW_CHILD_LAST last child of entry
92 * TVW_CHILD_ALL all children of entry
93 * TVW_CHILD_TREE all children, recursively
94 * TVW_SIBLING_FIRST first sibling of entry
95 * TVW_SIBLING_LAST last sibling of entry
96 * TVW_SIBLING_NEXT next sibling of entry
97 * TVW_SIBLING_PREV prev. sibling of entry
98 * TVW_SIBLING_ALL entry and all siblings
99 * TVW_SIBLING_TREE entry, siblings and all children recursively
100 * TVW_TREE_NEXT next in tree from entry
101 * TVW_TREE_PREV prev. in tree from entry
102 * TVW_TREE_PAGE_UP page up in tree from entry
103 * TVW_TREE_PAGE_DOWN page down in tree from entry
105 * If the relation entry is TV_ROOT, only the TVW_CHILD_??? codes are
106 * permitted.
108 * Permitted bits for the flags parameter are:
109 * TVF_DESELECT deselect entry instead of select
110 * TVF_TOGGLE toggle select/deselect
111 * TVF_MULTISELECT multi-(de)select entry
112 * TVF_MAKEVISIBLE make entry visible
113 * TVF_EXPAND expand entry
114 * TVF_CONTRACT contract entry
116 *************************************************************************/
118 METHOD(TV_Select, struct tvEntry *, tve)
120 struct tvAnchor tva;
121 TVData *tv;
122 TNPTR tn;
123 ULONG rc,pos,flags,tnflags,lvattr;
124 BOOL chg;
126 TV_DebugDumpMethod((Msg) tve);
128 tv = (TVData *) INST_DATA(cl,obj);
129 tn = NULL;
130 rc = 0;
131 flags = (tve->tve_Flags | TVF_VISIBLE) & ~TVF_SELECTED;
132 memset(&tva,0,sizeof(tva));
135 * Update the TNF_SELECTED flag of all TreeNodes
136 * by interrogating the listview.
139 TV_UpdateSelected(tv);
142 * Find each treenode corresponding to this tvEntry.
145 while((tn = TV_MatchNextEntry(tv,tve->tve_Entry,tve->tve_Which,flags,&tva)))
148 * User wants us to make the entry visible?
151 if (tve->tve_Flags & TVF_MAKEVISIBLE)
152 DoMethod(obj,TVM_VISIBLE,tve->tve_GInfo,tn,TVW_ENTRY,TVF_INTERNAL);
155 * Find it's position in the listview
158 if ((pos = TV_TreeNodeToIndex(tv,tn)) != ~0)
161 * See if we are required to select, deselect or toggle the
162 * entry, and whether that's a change from the current state.
165 if (flags & TVF_TOGGLE)
167 tnflags = tn->tn_Flags ^ TNF_SELECTED;
168 chg = TRUE;
170 else if ((flags & TVF_DESELECT) && IsSelected(tn))
172 tnflags = tn->tn_Flags & ~TNF_SELECTED;
173 chg = TRUE;
175 else if (!(flags & TVF_DESELECT) && !IsSelected(tn))
177 tnflags = tn->tn_Flags | TNF_SELECTED;
178 chg = TRUE;
180 else
181 chg = FALSE;
183 if (chg) /* yes, it's a change of state */
185 struct TagItem tags[2];
187 rc++; /* one more entry affected */
188 tn->tn_Flags = tnflags;
190 if (IsSelected(tn))
192 switch(flags & (TVF_MAKEVISIBLE|TVF_MULTISELECT))
194 case TVF_MULTISELECT:
195 lvattr = LISTV_SelectMultiNotVisible;
196 break;
198 case TVF_MAKEVISIBLE:
199 lvattr = LISTV_Select;
200 break;
202 case TVF_MAKEVISIBLE|TVF_MULTISELECT:
203 lvattr = LISTV_SelectMulti;
204 break;
206 default:
207 lvattr = LISTV_SelectNotVisible;
208 break;
211 else /* deselect entry */
212 lvattr = LISTV_DeSelect;
214 tags[0].ti_Tag = lvattr; tags[0].ti_Data = pos;
215 tags[1].ti_Tag = TAG_DONE;
216 DoMethod(tv->tv_Listview,OM_SET,tags,tve->tve_GInfo);
218 } /* endif change of state */
221 * User wants us to expand the selected entry, as well?
224 if (tve->tve_Flags & (TVF_EXPAND|TVF_CONTRACT))
225 DoMethod(obj,TVM_EXPAND,tve->tve_GInfo,tn,TVW_ENTRY,
226 TVF_INTERNAL | (tve->tve_Flags & TVF_CONTRACT));
228 } /* endif got pos in listview */
230 } /* endwhile match another entry */
232 return(rc);
234 METHOD_END