sbPlaylistTreeSelection.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 
29 
31  nsITreeSelection)
32 
33 sbPlaylistTreeSelection::sbPlaylistTreeSelection(nsITreeSelection* aTreeSelection,
34  sbIMediaListViewSelection* aViewSelection,
35  sbLocalDatabaseTreeView* aTreeView) :
36  mTreeSelection(aTreeSelection),
37  mViewSelection(aViewSelection),
38  mTreeView(aTreeView),
39  mShiftSelectPivot(-1)
40 {
41  NS_ASSERTION(aTreeSelection && aViewSelection, "Null passed to ctor");
42 }
43 
44 NS_IMETHODIMP
45 sbPlaylistTreeSelection::GetTree(nsITreeBoxObject** aTree)
46 {
47  return mTreeSelection->GetTree(aTree);
48 }
49 NS_IMETHODIMP
50 sbPlaylistTreeSelection::SetTree(nsITreeBoxObject* aTree)
51 {
52  return mTreeSelection->SetTree(aTree);
53 }
54 
55 NS_IMETHODIMP
56 sbPlaylistTreeSelection::GetSingle(PRBool* aSingle)
57 {
58  return mTreeSelection->GetSingle(aSingle);
59 }
60 
61 NS_IMETHODIMP
62 sbPlaylistTreeSelection::GetCount(PRInt32* aCount)
63 {
64  return mViewSelection->GetCount(aCount);
65 }
66 
67 NS_IMETHODIMP
68 sbPlaylistTreeSelection::IsSelected(PRInt32 index, PRBool* _retval)
69 {
70  return mViewSelection->IsIndexSelected(index, _retval);
71 }
72 
73 NS_IMETHODIMP
75 {
76  mShiftSelectPivot = -1;
77  // Update real selection before changing mViewSelection,
78  // some of its listeners might get confused otherwise.
79  nsresult rv = mTreeSelection->Select(index);
80  NS_ENSURE_SUCCESS(rv, rv);
81  rv = mViewSelection->SelectOnly(index);
82  NS_ENSURE_SUCCESS(rv, rv);
83  return NS_OK;
84 }
85 
86 NS_IMETHODIMP
87 sbPlaylistTreeSelection::TimedSelect(PRInt32 index, PRInt32 delay)
88 {
89  mShiftSelectPivot = -1;
90  // Update real selection before changing mViewSelection,
91  // some of its listeners might get confused otherwise.
92  nsresult rv = mTreeSelection->TimedSelect(index, delay);
93  NS_ENSURE_SUCCESS(rv, rv);
94  rv = mViewSelection->TimedSelectOnly(index, delay);
95  NS_ENSURE_SUCCESS(rv, rv);
96  return NS_OK;
97 }
98 
99 NS_IMETHODIMP
100 sbPlaylistTreeSelection::ToggleSelect(PRInt32 index)
101 {
102  mShiftSelectPivot = -1;
103  nsresult rv = mViewSelection->Toggle(index);
104  NS_ENSURE_SUCCESS(rv, rv);
105  rv = mTreeSelection->ToggleSelect(index);
106  NS_ENSURE_SUCCESS(rv, rv);
107  return NS_OK;
108 }
109 
110 NS_IMETHODIMP
111 sbPlaylistTreeSelection::RangedSelect(PRInt32 startIndex,
112  PRInt32 endIndex,
113  PRBool augment)
114 {
115  nsresult rv;
116  sbAutoSelectNotificationsSuppressed autoSelection(mViewSelection);
117 
118  // Save the current index here since we need it later and it may be
119  // changed if we need to clear the selection
120  PRInt32 currentIndex;
121  rv = mViewSelection->GetCurrentIndex(&currentIndex);
122  NS_ENSURE_SUCCESS(rv, rv);
123 
124  if (!augment) {
125  rv = mViewSelection->SelectNone();
126  NS_ENSURE_SUCCESS(rv, rv);
127  rv = mTreeSelection->ClearSelection();
128  NS_ENSURE_SUCCESS(rv, rv);
129  }
130 
131  if (startIndex == -1) {
132  if (mShiftSelectPivot != -1) {
133  startIndex = mShiftSelectPivot;
134  }
135  else {
136  if (currentIndex != -1) {
137  startIndex = currentIndex;
138  }
139  else {
140  startIndex = endIndex;
141  }
142  }
143  }
144 
145  mShiftSelectPivot = startIndex;
146 
147  rv = mViewSelection->SelectRange(startIndex, endIndex);
148  NS_ENSURE_SUCCESS(rv, rv);
149  rv = mTreeSelection->RangedSelect(startIndex, endIndex, PR_TRUE);
150  NS_ENSURE_SUCCESS(rv, rv);
151  return NS_OK;
152 }
153 
154 NS_IMETHODIMP
155 sbPlaylistTreeSelection::ClearRange(PRInt32 startIndex,
156  PRInt32 endIndex)
157 {
158  mShiftSelectPivot = -1;
159  nsresult rv = mViewSelection->ClearRange(startIndex, endIndex);
160  NS_ENSURE_SUCCESS(rv, rv);
161  rv = mTreeSelection->ClearRange(startIndex, endIndex);
162  NS_ENSURE_SUCCESS(rv, rv);
163  return NS_OK;
164 }
165 
166 NS_IMETHODIMP
167 sbPlaylistTreeSelection::ClearSelection()
168 {
169  mShiftSelectPivot = -1;
170  nsresult rv = mViewSelection->SelectNone();
171  NS_ENSURE_SUCCESS(rv, rv);
172  rv = mTreeSelection->ClearSelection();
173  NS_ENSURE_SUCCESS(rv, rv);
174  return NS_OK;
175 }
176 
177 NS_IMETHODIMP
178 sbPlaylistTreeSelection::InvertSelection()
179 {
180  // XXX not implemented by nsTreeSelection either
181  return NS_ERROR_NOT_IMPLEMENTED;
182 }
183 
184 NS_IMETHODIMP
185 sbPlaylistTreeSelection::SelectAll()
186 {
187  mShiftSelectPivot = -1;
188  nsresult rv = mViewSelection->SelectAll();
189  NS_ENSURE_SUCCESS(rv, rv);
190  rv = mTreeSelection->SelectAll();
191  NS_ENSURE_SUCCESS(rv, rv);
192  return NS_OK;
193 }
194 
195 NS_IMETHODIMP
196 sbPlaylistTreeSelection::GetRangeCount(PRInt32* _retval)
197 {
198  return NS_ERROR_NOT_IMPLEMENTED;
199 }
200 
201 NS_IMETHODIMP
202 sbPlaylistTreeSelection::GetRangeAt(PRInt32 i,
203  PRInt32* min,
204  PRInt32* max)
205 {
206  return NS_ERROR_NOT_IMPLEMENTED;
207 }
208 
209 NS_IMETHODIMP
210 sbPlaylistTreeSelection::InvalidateSelection()
211 {
212  return mTreeSelection->InvalidateSelection();
213 }
214 
215 NS_IMETHODIMP
216 sbPlaylistTreeSelection::AdjustSelection(PRInt32 index, PRInt32 count)
217 {
218  nsresult rv;
219  PRInt32 currentIndex;
220  rv = mViewSelection->GetCurrentIndex(&currentIndex);
221  NS_ENSURE_SUCCESS(rv, rv);
222 
223  // adjust current index, if necessary
224  if ((currentIndex != -1) && (index <= currentIndex)) {
225  // if we are deleting and the delete includes the current index, reset it
226  if (count < 0 && (currentIndex <= (index - count -1))) {
227  currentIndex = -1;
228  }
229  else {
230  currentIndex += count;
231  }
232 
233  rv = mViewSelection->SetCurrentIndex(currentIndex);
234  NS_ENSURE_SUCCESS(rv, rv);
235  rv = mTreeSelection->SetCurrentIndex(currentIndex);
236  NS_ENSURE_SUCCESS(rv, rv);
237  }
238 
239  // adjust mShiftSelectPivot, if necessary
240  if ((mShiftSelectPivot != 1) && (index <= mShiftSelectPivot)) {
241  // if we are deleting and the delete includes the shift select pivot, reset it
242  if (count < 0 && (mShiftSelectPivot <= (index - count - 1))) {
243  mShiftSelectPivot = -1;
244  }
245  else {
246  mShiftSelectPivot += count;
247  }
248  }
249 
250  return NS_OK;
251 }
252 
253 NS_IMETHODIMP
254 sbPlaylistTreeSelection::GetSelectEventsSuppressed(PRBool* aSelectEventsSuppressed)
255 {
256  return mTreeSelection->GetSelectEventsSuppressed(aSelectEventsSuppressed);
257 }
258 NS_IMETHODIMP
259 sbPlaylistTreeSelection::SetSelectEventsSuppressed(PRBool aSelectEventsSuppressed)
260 {
261  return mTreeSelection->SetSelectEventsSuppressed(aSelectEventsSuppressed);
262 }
263 
264 NS_IMETHODIMP
265 sbPlaylistTreeSelection::GetCurrentIndex(PRInt32* aCurrentIndex)
266 {
267  return mViewSelection->GetCurrentIndex(aCurrentIndex);
268 }
269 NS_IMETHODIMP
270 sbPlaylistTreeSelection::SetCurrentIndex(PRInt32 aCurrentIndex)
271 {
272  nsresult rv = mViewSelection->SetCurrentIndex(aCurrentIndex);
273  NS_ENSURE_SUCCESS(rv, rv);
274  rv = mTreeSelection->SetCurrentIndex(aCurrentIndex);
275  NS_ENSURE_SUCCESS(rv, rv);
276  return NS_OK;
277 }
278 
279 NS_IMETHODIMP
280 sbPlaylistTreeSelection::GetCurrentColumn(nsITreeColumn** aCurrentColumn)
281 {
282  return mTreeSelection->GetCurrentColumn(aCurrentColumn);
283 }
284 NS_IMETHODIMP
285 sbPlaylistTreeSelection::SetCurrentColumn(nsITreeColumn* aCurrentColumn)
286 {
287  return mTreeSelection->SetCurrentColumn(aCurrentColumn);
288 }
289 
290 NS_IMETHODIMP
291 sbPlaylistTreeSelection::GetShiftSelectPivot(PRInt32* aShiftSelectPivot)
292 {
293  *aShiftSelectPivot = mShiftSelectPivot;
294  return NS_OK;
295 }
return NS_OK
Manage the selection of items within a view. This interface is a subset of nsITreeViewSelection. Note that if you are part of the user interface, you probably want to be calling nsITreeView.selection instead - otherwise things can get subtly out of sync.
Use scope to manage the notifications suppressed flag on the view selection so it does not accidental...
var count
Definition: test_bug7406.js:32
NS_IMPL_ISUPPORTS1(sbPlaylistTreeSelection, nsITreeSelection) sbPlaylistTreeSelection
restoreHistoryPrecursor aCount
#define min(a, b)
_getSelectedPageStyle s i
Autocompleter Select