sbFilterTreeSelection.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #include "sbSelectionListUtils.h"
28 #include "sbFilterTreeSelection.h"
30 
32  nsITreeSelection)
33 
34 sbFilterTreeSelection::sbFilterTreeSelection(nsITreeSelection* aTreeSelection,
35  sbLocalDatabaseTreeView* aTreeView) :
36  mTreeSelection(aTreeSelection),
37  mTreeView(aTreeView)
38 {
39  NS_ASSERTION(aTreeSelection, "Null passed to ctor");
40 }
41 
42 NS_IMETHODIMP
43 sbFilterTreeSelection::GetTree(nsITreeBoxObject** aTree)
44 {
45  return mTreeSelection->GetTree(aTree);
46 }
47 NS_IMETHODIMP
48 sbFilterTreeSelection::SetTree(nsITreeBoxObject* aTree)
49 {
50  return mTreeSelection->SetTree(aTree);
51 }
52 
53 NS_IMETHODIMP
54 sbFilterTreeSelection::GetSingle(PRBool* aSingle)
55 {
56  return mTreeSelection->GetSingle(aSingle);
57 }
58 
59 NS_IMETHODIMP
60 sbFilterTreeSelection::GetCount(PRInt32* aCount)
61 {
62  return mTreeSelection->GetCount(aCount);
63 }
64 
65 NS_IMETHODIMP
66 sbFilterTreeSelection::IsSelected(PRInt32 index, PRBool* _retval)
67 {
68  return mTreeSelection->IsSelected(index, _retval);
69 }
70 
71 NS_IMETHODIMP
72 sbFilterTreeSelection::Select(PRInt32 index)
73 {
74  sbAutoSuppressSelectionEvents suppress(mTreeSelection);
75 
76  nsresult rv = mTreeSelection->Select(index);
77  NS_ENSURE_SUCCESS(rv, rv);
78 
79  rv = CheckIsSelectAll();
80  NS_ENSURE_SUCCESS(rv, rv);
81 
82  return NS_OK;
83 }
84 
85 NS_IMETHODIMP
86 sbFilterTreeSelection::TimedSelect(PRInt32 index, PRInt32 delay)
87 {
88  nsresult rv = mTreeSelection->TimedSelect(index, delay);
89  NS_ENSURE_SUCCESS(rv, rv);
90 
91  rv = CheckIsSelectAll();
92  NS_ENSURE_SUCCESS(rv, rv);
93 
94  return NS_OK;
95 }
96 
97 NS_IMETHODIMP
98 sbFilterTreeSelection::ToggleSelect(PRInt32 index)
99 {
100  sbAutoSuppressSelectionEvents suppress(mTreeSelection);
101 
102  nsresult rv = mTreeSelection->ToggleSelect(index);
103  NS_ENSURE_SUCCESS(rv, rv);
104 
105  rv = CheckIsSelectAll();
106  NS_ENSURE_SUCCESS(rv, rv);
107 
108  return NS_OK;
109 }
110 
111 NS_IMETHODIMP
112 sbFilterTreeSelection::RangedSelect(PRInt32 startIndex,
113  PRInt32 endIndex,
114  PRBool augment)
115 {
116  sbAutoSuppressSelectionEvents suppress(mTreeSelection);
117 
118  nsresult rv = mTreeSelection->RangedSelect(startIndex, endIndex, augment);
119  NS_ENSURE_SUCCESS(rv, rv);
120 
121  rv = CheckIsSelectAll();
122  NS_ENSURE_SUCCESS(rv, rv);
123 
124  return NS_OK;
125 }
126 
127 NS_IMETHODIMP
128 sbFilterTreeSelection::ClearRange(PRInt32 startIndex,
129  PRInt32 endIndex)
130 {
131  sbAutoSuppressSelectionEvents suppress(mTreeSelection);
132 
133  nsresult rv = mTreeSelection->ClearRange(startIndex, endIndex);
134  NS_ENSURE_SUCCESS(rv, rv);
135 
136  rv = CheckIsSelectAll();
137  NS_ENSURE_SUCCESS(rv, rv);
138 
139  return NS_OK;
140 }
141 
142 NS_IMETHODIMP
143 sbFilterTreeSelection::ClearSelection()
144 {
145  sbAutoSuppressSelectionEvents suppress(mTreeSelection);
146 
147  nsresult rv = mTreeSelection->ClearSelection();
148  NS_ENSURE_SUCCESS(rv, rv);
149 
150  rv = CheckIsSelectAll();
151  NS_ENSURE_SUCCESS(rv, rv);
152 
153  return NS_OK;
154 }
155 
156 NS_IMETHODIMP
157 sbFilterTreeSelection::InvertSelection()
158 {
159  return NS_ERROR_NOT_IMPLEMENTED;
160 }
161 
162 NS_IMETHODIMP
163 sbFilterTreeSelection::SelectAll()
164 {
165  sbAutoSuppressSelectionEvents suppress(mTreeSelection);
166 
167  nsresult rv = mTreeSelection->Select(0);
168  NS_ENSURE_SUCCESS(rv, rv);
169 
170  rv = CheckIsSelectAll();
171  NS_ENSURE_SUCCESS(rv, rv);
172 
173  return NS_OK;
174 }
175 
176 NS_IMETHODIMP
177 sbFilterTreeSelection::GetRangeCount(PRInt32* _retval)
178 {
179  return mTreeSelection->GetRangeCount(_retval);
180 }
181 
182 NS_IMETHODIMP
183 sbFilterTreeSelection::GetRangeAt(PRInt32 i,
184  PRInt32* min,
185  PRInt32* max)
186 {
187  return mTreeSelection->GetRangeAt(i, min, max);
188 }
189 
190 NS_IMETHODIMP
191 sbFilterTreeSelection::InvalidateSelection()
192 {
193  return mTreeSelection->InvalidateSelection();
194 }
195 
196 NS_IMETHODIMP
197 sbFilterTreeSelection::AdjustSelection(PRInt32 index, PRInt32 count)
198 {
199  nsresult rv;
200 
201  sbAutoSuppressSelectionEvents suppress(mTreeSelection);
202 
203  // if index is 0 or count is -1, there is no need to pass
204  // the call to the selection object
205  if (index != 0 && count != -1) {
206  rv = mTreeSelection->AdjustSelection(index, count);
207  NS_ENSURE_SUCCESS(rv, rv);
208  }
209 
210  rv = CheckIsSelectAll();
211  NS_ENSURE_SUCCESS(rv, rv);
212 
213  return NS_OK;
214 }
215 
216 NS_IMETHODIMP
217 sbFilterTreeSelection::GetSelectEventsSuppressed(PRBool* aSelectEventsSuppressed)
218 {
219  return mTreeSelection->GetSelectEventsSuppressed(aSelectEventsSuppressed);
220 }
221 NS_IMETHODIMP
222 sbFilterTreeSelection::SetSelectEventsSuppressed(PRBool aSelectEventsSuppressed)
223 {
224  return mTreeSelection->SetSelectEventsSuppressed(aSelectEventsSuppressed);
225 }
226 
227 NS_IMETHODIMP
228 sbFilterTreeSelection::GetCurrentIndex(PRInt32* aCurrentIndex)
229 {
230  return mTreeSelection->GetCurrentIndex(aCurrentIndex);
231 }
232 NS_IMETHODIMP
233 sbFilterTreeSelection::SetCurrentIndex(PRInt32 aCurrentIndex)
234 {
235  return mTreeSelection->SetCurrentIndex(aCurrentIndex);
236 }
237 
238 NS_IMETHODIMP
239 sbFilterTreeSelection::GetCurrentColumn(nsITreeColumn** aCurrentColumn)
240 {
241  return mTreeSelection->GetCurrentColumn(aCurrentColumn);
242 }
243 NS_IMETHODIMP
244 sbFilterTreeSelection::SetCurrentColumn(nsITreeColumn* aCurrentColumn)
245 {
246  return mTreeSelection->SetCurrentColumn(aCurrentColumn);
247 }
248 
249 NS_IMETHODIMP
250 sbFilterTreeSelection::GetShiftSelectPivot(PRInt32* aShiftSelectPivot)
251 {
252  return mTreeSelection->GetShiftSelectPivot(aShiftSelectPivot);
253 }
254 
255 nsresult
256 sbFilterTreeSelection::CheckIsSelectAll()
257 {
258  nsresult rv;
259 
260  PRInt32 rowCount;
261  rv = mTreeView->GetRowCount(&rowCount);
262  NS_ENSURE_SUCCESS(rv, rv);
263 
264  PRInt32 selectedCount;
265  rv = mTreeSelection->GetCount(&selectedCount);
266  NS_ENSURE_SUCCESS(rv, rv);
267 
268  PRBool isAllRowSelected;
269  rv = mTreeSelection->IsSelected(0, &isAllRowSelected);
270  NS_ENSURE_SUCCESS(rv, rv);
271 
272  // We are select all if:
273  // - The "all" row is selected
274  // - If nothing is selected
275  // - All rows are selected
276  // Note that having all rows selected except for the "all" row is not
277  // considered an "all" selection because it does not include items that
278  // have no value for the filtered property.
279  PRBool isSelectAll =
280  isAllRowSelected ||
281  selectedCount == 0 ||
282  selectedCount == rowCount;
283 
284  if (isSelectAll) {
285  // Note that all callers should have supressed selection
286  rv = mTreeSelection->Select(0);
287  NS_ENSURE_SUCCESS(rv, rv);
288  }
289 
290  mTreeView->SetSelectionIsAll(isSelectAll);
291 
292  return NS_OK;
293 }
return NS_OK
NS_IMPL_ISUPPORTS1(sbFilterTreeSelection, nsITreeSelection) sbFilterTreeSelection
var count
Definition: test_bug7406.js:32
restoreHistoryPrecursor aCount
#define min(a, b)
_getSelectedPageStyle s i
Autocompleter Select