Bug 453883, ensure true/false marcos are available, r=joshmoz, sr=jst
[wine-gecko.git] / accessible / src / msaa / nsXULTreeAccessibleWrap.cpp
blobda905c8387df9e8e716523ca6f0d1d8701056051
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Aaron Leventhal
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsXULTreeAccessibleWrap.h"
40 #include "nsTextFormatter.h"
41 #include "nsIFrame.h"
43 // --------------------------------------------------------
44 // nsXULTreeAccessibleWrap
45 // --------------------------------------------------------
47 nsXULTreeAccessibleWrap::nsXULTreeAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
48 nsXULTreeAccessible(aDOMNode, aShell)
52 NS_IMETHODIMP nsXULTreeAccessibleWrap::GetRole(PRUint32 *aRole)
54 NS_ENSURE_STATE(mTree);
56 nsCOMPtr<nsITreeColumns> cols;
57 mTree->GetColumns(getter_AddRefs(cols));
58 nsCOMPtr<nsITreeColumn> primaryCol;
59 if (cols) {
60 cols->GetPrimaryColumn(getter_AddRefs(primaryCol));
62 // No primary column means we're in a list
63 // In fact, history and mail turn off the primary flag when switching to a flat view
64 *aRole = primaryCol ? nsIAccessibleRole::ROLE_OUTLINE :
65 nsIAccessibleRole::ROLE_LIST;
67 return NS_OK;
70 // --------------------------------------------------------
71 // nsXULTreeitemAccessibleWrap Accessible
72 // --------------------------------------------------------
74 nsXULTreeitemAccessibleWrap::nsXULTreeitemAccessibleWrap(nsIAccessible *aParent,
75 nsIDOMNode *aDOMNode,
76 nsIWeakReference *aShell,
77 PRInt32 aRow,
78 nsITreeColumn* aColumn) :
79 nsXULTreeitemAccessible(aParent, aDOMNode, aShell, aRow, aColumn)
83 NS_IMETHODIMP nsXULTreeitemAccessibleWrap::GetRole(PRUint32 *aRole)
85 // No primary column means we're in a list
86 // In fact, history and mail turn off the primary flag when switching to a flat view
87 NS_ENSURE_STATE(mColumn);
88 PRBool isPrimary = PR_FALSE;
89 mColumn->GetPrimary(&isPrimary);
90 *aRole = isPrimary ? nsIAccessibleRole::ROLE_OUTLINEITEM :
91 nsIAccessibleRole::ROLE_LISTITEM;
93 return NS_OK;
96 NS_IMETHODIMP nsXULTreeitemAccessibleWrap::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
98 nsresult rv = nsXULTreeitemAccessible::GetBounds(x, y, width, height);
99 if (NS_FAILED(rv)) {
100 return rv;
102 nsIFrame *frame = GetFrame();
103 if (frame) {
104 // Will subtract first cell's start x from total width
105 PRInt32 cellStartX, cellStartY;
106 NS_ENSURE_STATE(mTree);
107 mTree->GetCoordsForCellItem(mRow, mColumn, EmptyCString(), &cellStartX, &cellStartY, width, height);
108 // Use entire row width, not just key column's width
109 *width = GetPresContext()->AppUnitsToDevPixels(frame->GetRect().width) -
110 cellStartX;
113 return NS_OK;
116 NS_IMETHODIMP
117 nsXULTreeitemAccessibleWrap::GetName(nsAString& aName)
119 NS_ENSURE_STATE(mTree);
120 nsCOMPtr<nsITreeColumns> cols;
121 mTree->GetColumns(getter_AddRefs(cols));
122 if (!cols) {
123 return NS_OK;
125 nsCOMPtr<nsITreeColumn> column;
126 cols->GetFirstColumn(getter_AddRefs(column));
127 while (column) {
128 nsAutoString colText;
129 mTreeView->GetCellText(mRow, column, colText);
130 aName += colText + NS_LITERAL_STRING(" ");
131 nsCOMPtr<nsITreeColumn> nextColumn;
132 column->GetNext(getter_AddRefs(nextColumn));
133 column = nextColumn;
136 return NS_OK;