[app] Display 'transaction.value' after completion (bug #25)
[abstract.git] / view / aaTreeView.cpp
blob2953f0863adaf82680de7458ce30f0e95d6891dc
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: */
3 /*
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>
24 #include "nsCOMPtr.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"
36 /* Unfrozen API */
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()
49 :mFlags(0)
53 aaTreeView::~aaTreeView()
57 NS_IMPL_ISUPPORTS2(aaTreeView,
58 aaIDataTreeView,
59 nsITreeView)
61 NS_IMETHODIMP
62 aaTreeView::GetRowCount(PRInt32 *aRowCount)
64 NS_ENSURE_ARG_POINTER(aRowCount);
65 *aRowCount = 0;
66 if (! mDataSet)
67 return NS_OK;
69 return mDataSet->GetLength((PRUint32 *) aRowCount);
72 NS_IMETHODIMP
73 aaTreeView::GetSelection(nsITreeSelection * *aSelection)
75 NS_ENSURE_ARG_POINTER( aSelection );
76 NS_IF_ADDREF(*aSelection = mSelection);
77 return NS_OK;
79 NS_IMETHODIMP
80 aaTreeView::SetSelection(nsITreeSelection * aSelection)
82 mSelection = aSelection;
84 return NS_OK;
87 NS_IMETHODIMP
88 aaTreeView::GetRowProperties(PRInt32 index, nsISupportsArray *properties)
90 return NS_ERROR_NOT_IMPLEMENTED;
93 NS_IMETHODIMP
94 aaTreeView::GetCellProperties(PRInt32 row, nsITreeColumn *col, nsISupportsArray *properties)
96 return NS_ERROR_NOT_IMPLEMENTED;
99 NS_IMETHODIMP
100 aaTreeView::GetColumnProperties(nsITreeColumn *col, nsISupportsArray *properties)
102 return NS_ERROR_NOT_IMPLEMENTED;
105 NS_IMETHODIMP
106 aaTreeView::IsContainer(PRInt32 index, PRBool *_retval)
108 NS_ENSURE_ARG_POINTER(_retval);
109 *_retval = PR_FALSE;
110 return NS_OK;
113 NS_IMETHODIMP
114 aaTreeView::IsContainerOpen(PRInt32 index, PRBool *_retval)
116 return NS_ERROR_NOT_IMPLEMENTED;
119 NS_IMETHODIMP
120 aaTreeView::IsContainerEmpty(PRInt32 index, PRBool *_retval)
122 return NS_ERROR_NOT_IMPLEMENTED;
125 NS_IMETHODIMP
126 aaTreeView::IsSeparator(PRInt32 index, PRBool *_retval)
128 NS_ENSURE_ARG_POINTER(_retval);
129 *_retval = PR_FALSE;
130 return NS_OK;
133 NS_IMETHODIMP
134 aaTreeView::IsSorted(PRBool *_retval)
136 return NS_ERROR_NOT_IMPLEMENTED;
139 NS_IMETHODIMP
140 aaTreeView::CanDrop(PRInt32 index, PRInt32 orientation, PRBool *_retval)
142 return NS_ERROR_NOT_IMPLEMENTED;
145 NS_IMETHODIMP
146 aaTreeView::Drop(PRInt32 row, PRInt32 orientation)
148 return NS_ERROR_NOT_IMPLEMENTED;
151 NS_IMETHODIMP
152 aaTreeView::GetParentIndex(PRInt32 rowIndex, PRInt32 *_retval)
154 return NS_ERROR_NOT_IMPLEMENTED;
157 NS_IMETHODIMP
158 aaTreeView::HasNextSibling(PRInt32 rowIndex, PRInt32 afterIndex, PRBool *_retval)
160 NS_ENSURE_ARG_POINTER(_retval);
161 nsresult rv;
162 PRInt32 count;
163 rv = GetRowCount(&count);
164 NS_ENSURE_SUCCESS(rv, rv);
165 if (rowIndex == afterIndex && rowIndex < count) {
166 *_retval = PR_TRUE;
167 } else {
168 *_retval = PR_FALSE;
170 return NS_OK;
173 NS_IMETHODIMP
174 aaTreeView::GetLevel(PRInt32 index, PRInt32 *_retval)
176 NS_ENSURE_ARG_POINTER(_retval);
177 *_retval = 0;
178 return NS_OK;
181 NS_IMETHODIMP
182 aaTreeView::GetImageSrc(PRInt32 row, nsITreeColumn *col, nsAString & _retval)
184 return NS_ERROR_NOT_IMPLEMENTED;
187 NS_IMETHODIMP
188 aaTreeView::GetProgressMode(PRInt32 row, nsITreeColumn *col, PRInt32 *_retval)
190 return NS_ERROR_NOT_IMPLEMENTED;
193 NS_IMETHODIMP
194 aaTreeView::GetCellValue(PRInt32 row, nsITreeColumn *col, nsAString & _retval)
196 return NS_ERROR_NOT_IMPLEMENTED;
199 NS_IMETHODIMP
200 aaTreeView::GetCellText(PRInt32 row, nsITreeColumn *col, nsAString & _retval)
202 /**
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);
211 NS_IMETHODIMP
212 aaTreeView::SetTree(nsITreeBoxObject *tree)
214 mTree = tree;
215 return NS_OK;
218 NS_IMETHODIMP
219 aaTreeView::ToggleOpenState(PRInt32 index)
221 return NS_ERROR_NOT_IMPLEMENTED;
224 NS_IMETHODIMP
225 aaTreeView::CycleHeader(nsITreeColumn *col)
227 return NS_ERROR_NOT_IMPLEMENTED;
230 NS_IMETHODIMP
231 aaTreeView::SelectionChanged()
233 return NS_OK;
236 NS_IMETHODIMP
237 aaTreeView::CycleCell(PRInt32 row, nsITreeColumn *col)
239 return NS_ERROR_NOT_IMPLEMENTED;
242 NS_IMETHODIMP
243 aaTreeView::IsEditable(PRInt32 row, nsITreeColumn *col, PRBool *_retval)
245 return NS_ERROR_NOT_IMPLEMENTED;
248 NS_IMETHODIMP
249 aaTreeView::IsSelectable(PRInt32 row, nsITreeColumn *col, PRBool *_retval)
251 NS_ENSURE_ARG_POINTER(_retval);
252 *_retval = PR_TRUE;
253 return NS_OK;
256 NS_IMETHODIMP
257 aaTreeView::SetCellValue(PRInt32 row, nsITreeColumn *col, const nsAString & value)
259 return NS_ERROR_NOT_IMPLEMENTED;
262 NS_IMETHODIMP
263 aaTreeView::SetCellText(PRInt32 row, nsITreeColumn *col, const nsAString & value)
265 return NS_ERROR_NOT_IMPLEMENTED;
268 NS_IMETHODIMP
269 aaTreeView::PerformAction(const PRUnichar *action)
271 return NS_ERROR_NOT_IMPLEMENTED;
274 NS_IMETHODIMP
275 aaTreeView::PerformActionOnRow(const PRUnichar *action, PRInt32 row)
277 return NS_ERROR_NOT_IMPLEMENTED;
280 NS_IMETHODIMP
281 aaTreeView::PerformActionOnCell(const PRUnichar *action, PRInt32 row, nsITreeColumn *col)
283 return NS_ERROR_NOT_IMPLEMENTED;
286 /* aaIDataTreeView */
287 NS_IMETHODIMP
288 aaTreeView::GetDataSet(aaILoadQuery ** aDataSet)
290 NS_ENSURE_ARG_POINTER(aDataSet);
291 NS_IF_ADDREF(*aDataSet = mDataSet);
292 return NS_OK;
294 NS_IMETHODIMP
295 aaTreeView::SetDataSet(aaILoadQuery * aDataSet)
297 mDataSet = aDataSet;
298 return NS_OK;
301 NS_IMETHODIMP
302 aaTreeView::Update()
304 nsresult rv;
305 NS_ENSURE_TRUE(mDataSet, NS_ERROR_NOT_INITIALIZED);
307 if (mTree) {
308 PRInt32 oldCount;
309 GetRowCount(&oldCount);
310 mTree->RowCountChanged(0, - oldCount);
313 rv = mDataSet->Load();
314 NS_ENSURE_SUCCESS(rv, rv);
316 if (mTree) {
317 PRInt32 newCount;
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);
327 return NS_OK;
330 NS_IMETHODIMP
331 aaTreeView::GetFlags(PRUint32 *aFlags)
333 NS_ENSURE_ARG_POINTER(aFlags);
334 *aFlags = mFlags;
335 return NS_OK;
337 NS_IMETHODIMP
338 aaTreeView::SetFlags(PRUint32 aFlags)
340 PRBool needUpdate = (aFlags != mFlags);
341 mFlags = aFlags;
342 if (NS_LIKELY( needUpdate && mTree )) {
343 mTree->Invalidate();
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);
349 return NS_OK;
352 /* Protected methods */
353 PRInt32
354 aaTreeView::getColumnIndex(nsITreeColumn *col, PRUint32 colPtrSz)
356 nsresult rv;
357 NS_ENSURE_TRUE(col, -1);
359 PRInt32 ci;
360 rv = col->GetIndex(&ci);
361 NS_ENSURE_SUCCESS(rv, -1);
363 NS_ENSURE_TRUE(ci >= 0 && ci < (PRInt32) (colPtrSz / sizeof(int *)), -1);
365 return ci;