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"
35 #include "unstable/nsITreeSelection.h"
36 #include "unstable/nsITreeColumns.h"
37 #include "unstable/nsIBoxObject.h"
38 #include "unstable/nsIArray.h"
39 #include "unstable/nsArrayUtils.h"
41 /* Project includes */
42 #include <abstract/storage/aaISession.h>
43 #include "aaTreeView.h"
45 aaTreeView::aaTreeView()
49 aaTreeView::~aaTreeView()
53 NS_IMPL_ISUPPORTS2(aaTreeView
,
58 aaTreeView::GetRowCount(PRInt32
*aRowCount
)
60 NS_ENSURE_ARG_POINTER(aRowCount
);
65 return mDataSet
->GetLength((PRUint32
*) aRowCount
);
69 aaTreeView::GetSelection(nsITreeSelection
* *aSelection
)
71 NS_ENSURE_ARG_POINTER( aSelection
);
72 NS_IF_ADDREF(*aSelection
= mSelection
);
76 aaTreeView::SetSelection(nsITreeSelection
* aSelection
)
78 mSelection
= aSelection
;
84 aaTreeView::GetRowProperties(PRInt32 index
, nsISupportsArray
*properties
)
86 return NS_ERROR_NOT_IMPLEMENTED
;
90 aaTreeView::GetCellProperties(PRInt32 row
, nsITreeColumn
*col
, nsISupportsArray
*properties
)
92 return NS_ERROR_NOT_IMPLEMENTED
;
96 aaTreeView::GetColumnProperties(nsITreeColumn
*col
, nsISupportsArray
*properties
)
98 return NS_ERROR_NOT_IMPLEMENTED
;
102 aaTreeView::IsContainer(PRInt32 index
, PRBool
*_retval
)
104 NS_ENSURE_ARG_POINTER(_retval
);
110 aaTreeView::IsContainerOpen(PRInt32 index
, PRBool
*_retval
)
112 return NS_ERROR_NOT_IMPLEMENTED
;
116 aaTreeView::IsContainerEmpty(PRInt32 index
, PRBool
*_retval
)
118 return NS_ERROR_NOT_IMPLEMENTED
;
122 aaTreeView::IsSeparator(PRInt32 index
, PRBool
*_retval
)
124 NS_ENSURE_ARG_POINTER(_retval
);
130 aaTreeView::IsSorted(PRBool
*_retval
)
132 return NS_ERROR_NOT_IMPLEMENTED
;
136 aaTreeView::CanDrop(PRInt32 index
, PRInt32 orientation
, PRBool
*_retval
)
138 return NS_ERROR_NOT_IMPLEMENTED
;
142 aaTreeView::Drop(PRInt32 row
, PRInt32 orientation
)
144 return NS_ERROR_NOT_IMPLEMENTED
;
148 aaTreeView::GetParentIndex(PRInt32 rowIndex
, PRInt32
*_retval
)
150 return NS_ERROR_NOT_IMPLEMENTED
;
154 aaTreeView::HasNextSibling(PRInt32 rowIndex
, PRInt32 afterIndex
, PRBool
*_retval
)
156 NS_ENSURE_ARG_POINTER(_retval
);
159 rv
= GetRowCount(&count
);
160 NS_ENSURE_SUCCESS(rv
, rv
);
161 if (rowIndex
== afterIndex
&& rowIndex
< count
) {
170 aaTreeView::GetLevel(PRInt32 index
, PRInt32
*_retval
)
172 NS_ENSURE_ARG_POINTER(_retval
);
178 aaTreeView::GetImageSrc(PRInt32 row
, nsITreeColumn
*col
, nsAString
& _retval
)
180 return NS_ERROR_NOT_IMPLEMENTED
;
184 aaTreeView::GetProgressMode(PRInt32 row
, nsITreeColumn
*col
, PRInt32
*_retval
)
186 return NS_ERROR_NOT_IMPLEMENTED
;
190 aaTreeView::GetCellValue(PRInt32 row
, nsITreeColumn
*col
, nsAString
& _retval
)
192 return NS_ERROR_NOT_IMPLEMENTED
;
196 aaTreeView::GetCellText(PRInt32 row
, nsITreeColumn
*col
, nsAString
& _retval
)
199 * There may be a bug in <tree> implementation. This function is
200 * occasionally called after mTree is detached by SetTree(nsnull);
202 NS_ENSURE_TRUE(mDataSet
, NS_ERROR_NOT_INITIALIZED
);
203 NS_ENSURE_TRUE(row
>= 0, NS_ERROR_INVALID_ARG
);
204 return doGetCellText(row
, col
, _retval
);
208 aaTreeView::SetTree(nsITreeBoxObject
*tree
)
215 aaTreeView::ToggleOpenState(PRInt32 index
)
217 return NS_ERROR_NOT_IMPLEMENTED
;
221 aaTreeView::CycleHeader(nsITreeColumn
*col
)
223 return NS_ERROR_NOT_IMPLEMENTED
;
227 aaTreeView::SelectionChanged()
233 aaTreeView::CycleCell(PRInt32 row
, nsITreeColumn
*col
)
235 return NS_ERROR_NOT_IMPLEMENTED
;
239 aaTreeView::IsEditable(PRInt32 row
, nsITreeColumn
*col
, PRBool
*_retval
)
241 return NS_ERROR_NOT_IMPLEMENTED
;
245 aaTreeView::IsSelectable(PRInt32 row
, nsITreeColumn
*col
, PRBool
*_retval
)
247 NS_ENSURE_ARG_POINTER(_retval
);
253 aaTreeView::SetCellValue(PRInt32 row
, nsITreeColumn
*col
, const nsAString
& value
)
255 return NS_ERROR_NOT_IMPLEMENTED
;
259 aaTreeView::SetCellText(PRInt32 row
, nsITreeColumn
*col
, const nsAString
& value
)
261 return NS_ERROR_NOT_IMPLEMENTED
;
265 aaTreeView::PerformAction(const PRUnichar
*action
)
267 return NS_ERROR_NOT_IMPLEMENTED
;
271 aaTreeView::PerformActionOnRow(const PRUnichar
*action
, PRInt32 row
)
273 return NS_ERROR_NOT_IMPLEMENTED
;
277 aaTreeView::PerformActionOnCell(const PRUnichar
*action
, PRInt32 row
, nsITreeColumn
*col
)
279 return NS_ERROR_NOT_IMPLEMENTED
;
282 /* aaIDataTreeView */
284 aaTreeView::GetDataSet(nsIArray
** aDataSet
)
286 NS_ENSURE_ARG_POINTER(aDataSet
);
287 NS_IF_ADDREF(*aDataSet
= mDataSet
);
291 aaTreeView::SetDataSet(nsIArray
* aDataSet
)
295 GetRowCount(&oldCount
);
296 mTree
->RowCountChanged(0, - oldCount
);
299 if ((mDataSet
= aDataSet
) && mTree
) {
301 GetRowCount(&newCount
);
302 mTree
->RowCountChanged(0, newCount
);
308 /* Private methods */
310 aaTreeView::InitArray(nsIDOMDocument
*doc
)
313 nsCOMPtr
<nsIDOMElement
> docEl
;
314 rv
= doc
->GetDocumentElement(getter_AddRefs( docEl
));
315 NS_ENSURE_SUCCESS(rv
, rv
);
317 nsCOMPtr
<nsIDOMXULElement
> xulEl(do_QueryInterface(docEl
, &rv
));
318 NS_ENSURE_SUCCESS(rv
, rv
);
320 nsCOMPtr
<nsIBoxObject
> box
;
321 rv
= xulEl
->GetBoxObject(getter_AddRefs( box
));
322 NS_ENSURE_SUCCESS(rv
, rv
);
324 return box
->GetPropertyAsSupports((const PRUnichar
*)L
"array",
325 getter_AddRefs( mDataSet
));