1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <abstract/aacore.h>
25 #include "nsStringAPI.h"
26 #include "nsEmbedString.h"
27 #include "nsIDOMElement.h"
28 #include "nsIDOMNode.h"
29 #include "nsIDOMDocument.h"
30 #include "unstable/nsIDOMXULElement.h"
31 #include "nsIInterfaceRequestorUtils.h"
32 #include "nsISHistory.h"
33 #include "nsServiceManagerUtils.h"
34 #include "nsIObserverService.h"
37 #include "unstable/nsITreeSelection.h"
38 #include "unstable/nsITreeColumns.h"
39 #include "unstable/nsITreeBoxObject.h"
40 #include "unstable/nsIArray.h"
41 #include "unstable/nsArrayUtils.h"
43 /* Project includes */
44 #include <abstract/storage/aaISession.h>
45 #include <abstract/storage/aaILoadQuery.h>
46 #include "aaTreeView.h"
48 aaTreeView::aaTreeView()
53 aaTreeView::~aaTreeView()
57 NS_IMPL_ISUPPORTS2(aaTreeView
,
62 aaTreeView::GetRowCount(PRInt32
*aRowCount
)
64 NS_ENSURE_ARG_POINTER(aRowCount
);
69 return mDataSet
->GetLength((PRUint32
*) aRowCount
);
73 aaTreeView::GetSelection(nsITreeSelection
* *aSelection
)
75 NS_ENSURE_ARG_POINTER( aSelection
);
76 NS_IF_ADDREF(*aSelection
= mSelection
);
80 aaTreeView::SetSelection(nsITreeSelection
* aSelection
)
82 mSelection
= aSelection
;
88 aaTreeView::GetRowProperties(PRInt32 index
, nsISupportsArray
*properties
)
90 return NS_ERROR_NOT_IMPLEMENTED
;
94 aaTreeView::GetCellProperties(PRInt32 row
, nsITreeColumn
*col
, nsISupportsArray
*properties
)
96 return NS_ERROR_NOT_IMPLEMENTED
;
100 aaTreeView::GetColumnProperties(nsITreeColumn
*col
, nsISupportsArray
*properties
)
102 return NS_ERROR_NOT_IMPLEMENTED
;
106 aaTreeView::IsContainer(PRInt32 index
, PRBool
*_retval
)
108 NS_ENSURE_ARG_POINTER(_retval
);
114 aaTreeView::IsContainerOpen(PRInt32 index
, PRBool
*_retval
)
116 return NS_ERROR_NOT_IMPLEMENTED
;
120 aaTreeView::IsContainerEmpty(PRInt32 index
, PRBool
*_retval
)
122 return NS_ERROR_NOT_IMPLEMENTED
;
126 aaTreeView::IsSeparator(PRInt32 index
, PRBool
*_retval
)
128 NS_ENSURE_ARG_POINTER(_retval
);
134 aaTreeView::IsSorted(PRBool
*_retval
)
136 return NS_ERROR_NOT_IMPLEMENTED
;
140 aaTreeView::CanDrop(PRInt32 index
, PRInt32 orientation
, PRBool
*_retval
)
142 return NS_ERROR_NOT_IMPLEMENTED
;
146 aaTreeView::Drop(PRInt32 row
, PRInt32 orientation
)
148 return NS_ERROR_NOT_IMPLEMENTED
;
152 aaTreeView::GetParentIndex(PRInt32 rowIndex
, PRInt32
*_retval
)
154 return NS_ERROR_NOT_IMPLEMENTED
;
158 aaTreeView::HasNextSibling(PRInt32 rowIndex
, PRInt32 afterIndex
, PRBool
*_retval
)
160 NS_ENSURE_ARG_POINTER(_retval
);
163 rv
= GetRowCount(&count
);
164 NS_ENSURE_SUCCESS(rv
, rv
);
165 if (rowIndex
== afterIndex
&& rowIndex
< count
) {
174 aaTreeView::GetLevel(PRInt32 index
, PRInt32
*_retval
)
176 NS_ENSURE_ARG_POINTER(_retval
);
182 aaTreeView::GetImageSrc(PRInt32 row
, nsITreeColumn
*col
, nsAString
& _retval
)
184 return NS_ERROR_NOT_IMPLEMENTED
;
188 aaTreeView::GetProgressMode(PRInt32 row
, nsITreeColumn
*col
, PRInt32
*_retval
)
190 return NS_ERROR_NOT_IMPLEMENTED
;
194 aaTreeView::GetCellValue(PRInt32 row
, nsITreeColumn
*col
, nsAString
& _retval
)
196 return NS_ERROR_NOT_IMPLEMENTED
;
200 aaTreeView::GetCellText(PRInt32 row
, nsITreeColumn
*col
, nsAString
& _retval
)
203 * There may be a bug in <tree> implementation. This function is
204 * occasionally called after mTree is detached by SetTree(nsnull);
206 NS_ENSURE_TRUE(mDataSet
, NS_ERROR_NOT_INITIALIZED
);
207 NS_ENSURE_TRUE(row
>= 0, NS_ERROR_INVALID_ARG
);
208 return doGetCellText(row
, col
, _retval
);
212 aaTreeView::SetTree(nsITreeBoxObject
*tree
)
219 aaTreeView::ToggleOpenState(PRInt32 index
)
221 return NS_ERROR_NOT_IMPLEMENTED
;
225 aaTreeView::CycleHeader(nsITreeColumn
*col
)
227 return NS_ERROR_NOT_IMPLEMENTED
;
231 aaTreeView::SelectionChanged()
237 aaTreeView::CycleCell(PRInt32 row
, nsITreeColumn
*col
)
239 return NS_ERROR_NOT_IMPLEMENTED
;
243 aaTreeView::IsEditable(PRInt32 row
, nsITreeColumn
*col
, PRBool
*_retval
)
245 return NS_ERROR_NOT_IMPLEMENTED
;
249 aaTreeView::IsSelectable(PRInt32 row
, nsITreeColumn
*col
, PRBool
*_retval
)
251 NS_ENSURE_ARG_POINTER(_retval
);
257 aaTreeView::SetCellValue(PRInt32 row
, nsITreeColumn
*col
, const nsAString
& value
)
259 return NS_ERROR_NOT_IMPLEMENTED
;
263 aaTreeView::SetCellText(PRInt32 row
, nsITreeColumn
*col
, const nsAString
& value
)
265 return NS_ERROR_NOT_IMPLEMENTED
;
269 aaTreeView::PerformAction(const PRUnichar
*action
)
271 return NS_ERROR_NOT_IMPLEMENTED
;
275 aaTreeView::PerformActionOnRow(const PRUnichar
*action
, PRInt32 row
)
277 return NS_ERROR_NOT_IMPLEMENTED
;
281 aaTreeView::PerformActionOnCell(const PRUnichar
*action
, PRInt32 row
, nsITreeColumn
*col
)
283 return NS_ERROR_NOT_IMPLEMENTED
;
286 /* aaIDataTreeView */
288 aaTreeView::GetDataSet(aaILoadQuery
** aDataSet
)
290 NS_ENSURE_ARG_POINTER(aDataSet
);
291 NS_IF_ADDREF(*aDataSet
= mDataSet
);
295 aaTreeView::SetDataSet(aaILoadQuery
* aDataSet
)
305 NS_ENSURE_TRUE(mDataSet
, NS_ERROR_NOT_INITIALIZED
);
309 GetRowCount(&oldCount
);
310 mTree
->RowCountChanged(0, - oldCount
);
313 rv
= mDataSet
->Load();
314 NS_ENSURE_SUCCESS(rv
, rv
);
318 GetRowCount(&newCount
);
319 mTree
->RowCountChanged(0, newCount
);
322 nsCOMPtr
<nsIObserverService
> broadcaster
= do_GetService(
323 "@mozilla.org/observer-service;1");
324 NS_ENSURE_TRUE(broadcaster
, NS_OK
);
325 broadcaster
->NotifyObservers(this, "tree-view-load", nsnull
);
331 aaTreeView::GetFlags(PRUint32
*aFlags
)
333 NS_ENSURE_ARG_POINTER(aFlags
);
338 aaTreeView::SetFlags(PRUint32 aFlags
)
340 PRBool needUpdate
= (aFlags
!= mFlags
);
342 if (NS_LIKELY( needUpdate
&& mTree
)) {
344 nsCOMPtr
<nsIObserverService
> broadcaster
= do_GetService(
345 "@mozilla.org/observer-service;1");
346 NS_ENSURE_TRUE(broadcaster
, NS_OK
);
347 broadcaster
->NotifyObservers(this, "tree-flags-change", nsnull
);
352 /* Protected methods */
354 aaTreeView::getColumnIndex(nsITreeColumn
*col
, PRUint32 colPtrSz
)
357 NS_ENSURE_TRUE(col
, -1);
360 rv
= col
->GetIndex(&ci
);
361 NS_ENSURE_SUCCESS(rv
, -1);
363 NS_ENSURE_TRUE(ci
>= 0 && ci
< (PRInt32
) (colPtrSz
/ sizeof(int *)), -1);