/src/libreoffice/vcl/source/window/legacyaccessibility.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
21 | | #include <window.h> |
22 | | |
23 | | #include "dlgctrl.hxx" |
24 | | |
25 | | using namespace ::com::sun::star; |
26 | | |
27 | | |
28 | | static vcl::Window* ImplGetLabelFor(vcl::Window* pFrameWindow, WindowType nMyType, const vcl::Window* pLabel, sal_Unicode nAccel) |
29 | 0 | { |
30 | 0 | vcl::Window* pWindow = nullptr; |
31 | |
|
32 | 0 | if( nMyType == WindowType::FIXEDTEXT || |
33 | 0 | nMyType == WindowType::FIXEDLINE || |
34 | 0 | nMyType == WindowType::GROUPBOX ) |
35 | 0 | { |
36 | | // #i100833# MT 2010/02: Group box and fixed lines can also label a fixed text. |
37 | | // See tools/options/print for example. |
38 | 0 | bool bThisIsAGroupControl = (nMyType == WindowType::GROUPBOX) || (nMyType == WindowType::FIXEDLINE); |
39 | | // get index, form start and form end |
40 | 0 | sal_uInt16 nIndex=0, nFormStart=0, nFormEnd=0; |
41 | 0 | ::ImplFindDlgCtrlWindow( pFrameWindow, |
42 | 0 | pLabel, |
43 | 0 | nIndex, |
44 | 0 | nFormStart, |
45 | 0 | nFormEnd ); |
46 | 0 | if( nAccel ) |
47 | 0 | { |
48 | | // find the accelerated window |
49 | 0 | pWindow = ::ImplFindAccelWindow( pFrameWindow, |
50 | 0 | nIndex, |
51 | 0 | nAccel, |
52 | 0 | nFormStart, |
53 | 0 | nFormEnd, |
54 | 0 | false ); |
55 | 0 | } |
56 | 0 | else |
57 | 0 | { |
58 | | // find the next control; if that is a fixed text |
59 | | // fixed line or group box, then return NULL |
60 | 0 | while( nIndex < nFormEnd ) |
61 | 0 | { |
62 | 0 | nIndex++; |
63 | 0 | vcl::Window* pSWindow = ::ImplGetChildWindow( pFrameWindow, |
64 | 0 | nIndex, |
65 | 0 | nIndex, |
66 | 0 | false ); |
67 | 0 | if( pSWindow && isVisibleInLayout(pSWindow) && ! (pSWindow->GetStyle() & WB_NOLABEL) ) |
68 | 0 | { |
69 | 0 | WindowType eType = pSWindow->GetType(); |
70 | 0 | if( eType != WindowType::FIXEDTEXT && |
71 | 0 | eType != WindowType::FIXEDLINE && |
72 | 0 | eType != WindowType::GROUPBOX ) |
73 | 0 | { |
74 | 0 | pWindow = pSWindow; |
75 | 0 | } |
76 | 0 | else if( bThisIsAGroupControl && ( eType == WindowType::FIXEDTEXT ) ) |
77 | 0 | { |
78 | 0 | pWindow = pSWindow; |
79 | 0 | } |
80 | 0 | break; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | } |
84 | 0 | } |
85 | |
|
86 | 0 | return pWindow; |
87 | 0 | } |
88 | | |
89 | | namespace vcl { |
90 | | |
91 | | Window* Window::getLegacyNonLayoutAccessibleRelationLabelFor() const |
92 | 0 | { |
93 | 0 | Window* pFrameWindow = ImplGetFrameWindow(); |
94 | |
|
95 | 0 | WinBits nFrameStyle = pFrameWindow->GetStyle(); |
96 | 0 | if( ! ( nFrameStyle & WB_DIALOGCONTROL ) |
97 | 0 | || ( nFrameStyle & WB_NODIALOGCONTROL ) |
98 | 0 | ) |
99 | 0 | return nullptr; |
100 | | |
101 | 0 | sal_Unicode nAccel = getAccel( GetText() ); |
102 | |
|
103 | 0 | Window* pWindow = ImplGetLabelFor(pFrameWindow, GetType(), this, nAccel); |
104 | 0 | if( ! pWindow && mpWindowImpl->mpRealParent ) |
105 | 0 | pWindow = ImplGetLabelFor(mpWindowImpl->mpRealParent, GetType(), this, nAccel); |
106 | 0 | return pWindow; |
107 | 0 | } |
108 | | |
109 | | static Window* ImplGetLabeledBy(Window* pFrameWindow, WindowType nMyType, const Window* pLabeled) |
110 | 0 | { |
111 | 0 | Window* pWindow = nullptr; |
112 | 0 | if (pFrameWindow && nMyType != WindowType::GROUPBOX && nMyType != WindowType::FIXEDLINE) |
113 | 0 | { |
114 | | // search for a control that labels this window |
115 | | // a label is considered the last fixed text, fixed line or group box |
116 | | // that comes before this control; with the exception of push buttons |
117 | | // which are labeled only if the fixed text, fixed line or group box |
118 | | // is directly before the control |
119 | | |
120 | | // get form start and form end and index of this control |
121 | 0 | sal_uInt16 nIndex, nFormStart, nFormEnd; |
122 | 0 | Window* pSWindow = ::ImplFindDlgCtrlWindow( pFrameWindow, |
123 | 0 | pLabeled, |
124 | 0 | nIndex, |
125 | 0 | nFormStart, |
126 | 0 | nFormEnd ); |
127 | 0 | if( pSWindow && nIndex != nFormStart ) |
128 | 0 | { |
129 | 0 | if( nMyType == WindowType::PUSHBUTTON || |
130 | 0 | nMyType == WindowType::HELPBUTTON || |
131 | 0 | nMyType == WindowType::OKBUTTON || |
132 | 0 | nMyType == WindowType::CANCELBUTTON ) |
133 | 0 | { |
134 | 0 | nFormStart = nIndex-1; |
135 | 0 | } |
136 | 0 | for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- ) |
137 | 0 | { |
138 | 0 | sal_uInt16 nFoundIndex = 0; |
139 | 0 | pSWindow = ::ImplGetChildWindow( pFrameWindow, |
140 | 0 | nSearchIndex, |
141 | 0 | nFoundIndex, |
142 | 0 | false ); |
143 | 0 | if( pSWindow && isVisibleInLayout(pSWindow) && !(pSWindow->GetStyle() & WB_NOLABEL) ) |
144 | 0 | { |
145 | 0 | WindowType eType = pSWindow->GetType(); |
146 | 0 | if ( eType == WindowType::FIXEDTEXT || |
147 | 0 | eType == WindowType::FIXEDLINE || |
148 | 0 | eType == WindowType::GROUPBOX ) |
149 | 0 | { |
150 | | // a fixed text can't be labelled by a fixed text. |
151 | 0 | if ( ( nMyType != WindowType::FIXEDTEXT ) || ( eType != WindowType::FIXEDTEXT ) ) |
152 | 0 | pWindow = pSWindow; |
153 | 0 | break; |
154 | 0 | } |
155 | 0 | } |
156 | 0 | if( nFoundIndex > nSearchIndex || nSearchIndex == 0 ) |
157 | 0 | break; |
158 | 0 | } |
159 | 0 | } |
160 | 0 | } |
161 | 0 | return pWindow; |
162 | 0 | } |
163 | | |
164 | | Window* Window::getLegacyNonLayoutAccessibleRelationLabeledBy() const |
165 | 0 | { |
166 | 0 | Window* pFrameWindow = ImplGetFrameWindow(); |
167 | | |
168 | | // #i62723#, #104191# checkboxes and radiobuttons are not supposed to have labels |
169 | 0 | if( GetType() == WindowType::CHECKBOX || GetType() == WindowType::RADIOBUTTON ) |
170 | 0 | return nullptr; |
171 | | |
172 | | // if( ! ( GetType() == WindowType::FIXEDTEXT || |
173 | | // GetType() == WindowType::FIXEDLINE || |
174 | | // GetType() == WindowType::GROUPBOX ) ) |
175 | | // #i100833# MT 2010/02: Group box and fixed lines can also label a fixed text. |
176 | | // See tools/options/print for example. |
177 | | |
178 | 0 | Window* pWindow = ImplGetLabeledBy(pFrameWindow, GetType(), this); |
179 | 0 | if( ! pWindow && mpWindowImpl->mpRealParent ) |
180 | 0 | pWindow = ImplGetLabeledBy(mpWindowImpl->mpRealParent, GetType(), this); |
181 | |
|
182 | 0 | return pWindow; |
183 | 0 | } |
184 | | |
185 | | Window* Window::getLegacyNonLayoutAccessibleRelationMemberOf() const |
186 | 0 | { |
187 | 0 | Window* pWindow = nullptr; |
188 | 0 | Window* pFrameWindow = GetParent(); |
189 | 0 | if ( !pFrameWindow ) |
190 | 0 | { |
191 | 0 | pFrameWindow = ImplGetFrameWindow(); |
192 | 0 | } |
193 | | // if( ! ( GetType() == WindowType::FIXEDTEXT || |
194 | 0 | if( GetType() != WindowType::FIXEDLINE && GetType() != WindowType::GROUPBOX ) |
195 | 0 | { |
196 | | // search for a control that makes member of this window |
197 | | // it is considered the last fixed line or group box |
198 | | // that comes before this control; with the exception of push buttons |
199 | | // which are labeled only if the fixed line or group box |
200 | | // is directly before the control |
201 | | // get form start and form end and index of this control |
202 | 0 | sal_uInt16 nIndex, nFormStart, nFormEnd; |
203 | 0 | Window* pSWindow |
204 | 0 | = ::ImplFindDlgCtrlWindow(pFrameWindow, this, nIndex, nFormStart, nFormEnd); |
205 | 0 | if( pSWindow && nIndex != nFormStart ) |
206 | 0 | { |
207 | 0 | if( GetType() == WindowType::PUSHBUTTON || |
208 | 0 | GetType() == WindowType::HELPBUTTON || |
209 | 0 | GetType() == WindowType::OKBUTTON || |
210 | 0 | GetType() == WindowType::CANCELBUTTON ) |
211 | 0 | { |
212 | 0 | nFormStart = nIndex-1; |
213 | 0 | } |
214 | 0 | for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- ) |
215 | 0 | { |
216 | 0 | sal_uInt16 nFoundIndex = 0; |
217 | 0 | pSWindow = ::ImplGetChildWindow( pFrameWindow, |
218 | 0 | nSearchIndex, |
219 | 0 | nFoundIndex, |
220 | 0 | false ); |
221 | 0 | if( pSWindow && pSWindow->IsVisible() && |
222 | 0 | ( pSWindow->GetType() == WindowType::FIXEDLINE || |
223 | 0 | pSWindow->GetType() == WindowType::GROUPBOX ) ) |
224 | 0 | { |
225 | 0 | pWindow = pSWindow; |
226 | 0 | break; |
227 | 0 | } |
228 | 0 | if( nFoundIndex > nSearchIndex || nSearchIndex == 0 ) |
229 | 0 | break; |
230 | 0 | } |
231 | 0 | } |
232 | 0 | } |
233 | 0 | return pWindow; |
234 | 0 | } |
235 | | |
236 | | } /* namespace vcl */ |
237 | | |
238 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |