LibreOffice Module vcl (master) 1
legacyaccessibility.cxx
Go to the documentation of this file.
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
25using namespace ::com::sun::star;
26
27
28static vcl::Window* ImplGetLabelFor( vcl::Window* pFrameWindow, WindowType nMyType, vcl::Window* pLabel, sal_Unicode nAccel )
29{
30 vcl::Window* pWindow = nullptr;
31
32 if( nMyType == WindowType::FIXEDTEXT ||
33 nMyType == WindowType::FIXEDLINE ||
34 nMyType == WindowType::GROUPBOX )
35 {
36 // #i100833# MT 2010/02: Group box and fixed lines can also label a fixed text.
37 // See tools/options/print for example.
38 bool bThisIsAGroupControl = (nMyType == WindowType::GROUPBOX) || (nMyType == WindowType::FIXEDLINE);
39 // get index, form start and form end
40 sal_uInt16 nIndex=0, nFormStart=0, nFormEnd=0;
41 ::ImplFindDlgCtrlWindow( pFrameWindow,
42 pLabel,
43 nIndex,
44 nFormStart,
45 nFormEnd );
46 if( nAccel )
47 {
48 // find the accelerated window
49 pWindow = ::ImplFindAccelWindow( pFrameWindow,
50 nIndex,
51 nAccel,
52 nFormStart,
53 nFormEnd,
54 false );
55 }
56 else
57 {
58 // find the next control; if that is a fixed text
59 // fixed line or group box, then return NULL
60 while( nIndex < nFormEnd )
61 {
62 nIndex++;
63 vcl::Window* pSWindow = ::ImplGetChildWindow( pFrameWindow,
64 nIndex,
65 nIndex,
66 false );
67 if( pSWindow && isVisibleInLayout(pSWindow) && ! (pSWindow->GetStyle() & WB_NOLABEL) )
68 {
69 WindowType nType = pSWindow->GetType();
73 {
74 pWindow = pSWindow;
75 }
76 else if( bThisIsAGroupControl && ( nType == WindowType::FIXEDTEXT ) )
77 {
78 pWindow = pSWindow;
79 }
80 break;
81 }
82 }
83 }
84 }
85
86 return pWindow;
87}
88
89namespace vcl {
90
92{
93 Window* pFrameWindow = ImplGetFrameWindow();
94
95 WinBits nFrameStyle = pFrameWindow->GetStyle();
96 if( ! ( nFrameStyle & WB_DIALOGCONTROL )
97 || ( nFrameStyle & WB_NODIALOGCONTROL )
98 )
99 return nullptr;
100
101 sal_Unicode nAccel = getAccel( GetText() );
102
103 Window* pWindow = ImplGetLabelFor( pFrameWindow, GetType(), const_cast<Window*>(this), nAccel );
104 if( ! pWindow && mpWindowImpl->mpRealParent )
105 pWindow = ImplGetLabelFor( mpWindowImpl->mpRealParent, GetType(), const_cast<Window*>(this), nAccel );
106 return pWindow;
107}
108
109static Window* ImplGetLabeledBy( Window* pFrameWindow, WindowType nMyType, Window* pLabeled )
110{
111 Window* pWindow = nullptr;
112 if ( (nMyType != WindowType::GROUPBOX) && (nMyType != WindowType::FIXEDLINE) )
113 {
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 sal_uInt16 nIndex, nFormStart, nFormEnd;
122 Window* pSWindow = ::ImplFindDlgCtrlWindow( pFrameWindow,
123 pLabeled,
124 nIndex,
125 nFormStart,
126 nFormEnd );
127 if( pSWindow && nIndex != nFormStart )
128 {
129 if( nMyType == WindowType::PUSHBUTTON ||
130 nMyType == WindowType::HELPBUTTON ||
131 nMyType == WindowType::OKBUTTON ||
132 nMyType == WindowType::CANCELBUTTON )
133 {
134 nFormStart = nIndex-1;
135 }
136 for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- )
137 {
138 sal_uInt16 nFoundIndex = 0;
139 pSWindow = ::ImplGetChildWindow( pFrameWindow,
140 nSearchIndex,
141 nFoundIndex,
142 false );
143 if( pSWindow && isVisibleInLayout(pSWindow) && !(pSWindow->GetStyle() & WB_NOLABEL) )
144 {
145 WindowType nType = pSWindow->GetType();
149 {
150 // a fixed text can't be labelled by a fixed text.
151 if ( ( nMyType != WindowType::FIXEDTEXT ) || ( nType != WindowType::FIXEDTEXT ) )
152 pWindow = pSWindow;
153 break;
154 }
155 }
156 if( nFoundIndex > nSearchIndex || nSearchIndex == 0 )
157 break;
158 }
159 }
160 }
161 return pWindow;
162}
163
165{
166 Window* pFrameWindow = ImplGetFrameWindow();
167
168 // #i62723#, #104191# checkboxes and radiobuttons are not supposed to have labels
170 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 Window* pWindow = ImplGetLabeledBy( pFrameWindow, GetType(), const_cast<Window*>(this) );
179 if( ! pWindow && mpWindowImpl->mpRealParent )
180 pWindow = ImplGetLabeledBy( mpWindowImpl->mpRealParent, GetType(), const_cast<Window*>(this) );
181
182 return pWindow;
183}
184
186{
187 Window* pWindow = nullptr;
188 Window* pFrameWindow = GetParent();
189 if ( !pFrameWindow )
190 {
191 pFrameWindow = ImplGetFrameWindow();
192 }
193 // if( ! ( GetType() == WindowType::FIXEDTEXT ||
195 {
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 sal_uInt16 nIndex, nFormStart, nFormEnd;
203 Window* pSWindow = ::ImplFindDlgCtrlWindow( pFrameWindow,
204 const_cast<Window*>(this),
205 nIndex,
206 nFormStart,
207 nFormEnd );
208 if( pSWindow && nIndex != nFormStart )
209 {
214 {
215 nFormStart = nIndex-1;
216 }
217 for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- )
218 {
219 sal_uInt16 nFoundIndex = 0;
220 pSWindow = ::ImplGetChildWindow( pFrameWindow,
221 nSearchIndex,
222 nFoundIndex,
223 false );
224 if( pSWindow && pSWindow->IsVisible() &&
225 ( pSWindow->GetType() == WindowType::FIXEDLINE ||
226 pSWindow->GetType() == WindowType::GROUPBOX ) )
227 {
228 pWindow = pSWindow;
229 break;
230 }
231 if( nFoundIndex > nSearchIndex || nSearchIndex == 0 )
232 break;
233 }
234 }
235 }
236 return pWindow;
237}
238
239} /* namespace vcl */
240
241/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE vcl::Window * ImplFindDlgCtrlWindow(vcl::Window *pWindow)
Definition: dlgctrl.cxx:1102
vcl::Window * GetParent() const
Definition: window2.cxx:1121
WindowType GetType() const
Definition: window2.cxx:998
SAL_DLLPRIVATE vcl::Window * getLegacyNonLayoutAccessibleRelationLabeledBy() const
SAL_DLLPRIVATE vcl::Window * getLegacyNonLayoutAccessibleRelationMemberOf() const
WinBits GetStyle() const
Definition: window2.cxx:977
std::unique_ptr< WindowImpl > mpWindowImpl
Definition: window.hxx:484
bool IsVisible() const
Definition: window2.cxx:1126
virtual OUString GetText() const
Definition: window.cxx:3060
SAL_DLLPRIVATE vcl::Window * ImplGetFrameWindow() const
Definition: window2.cxx:925
SAL_DLLPRIVATE vcl::Window * getLegacyNonLayoutAccessibleRelationLabelFor() const
sal_Unicode getAccel(const OUString &rStr)
Definition: dlgctrl.cxx:1144
vcl::Window * ImplFindAccelWindow(vcl::Window *pParent, sal_uInt16 &rIndex, sal_Unicode cCharCode, sal_uInt16 nFormStart, sal_uInt16 nFormEnd, bool bCheckEnable)
Definition: dlgctrl.cxx:419
vcl::Window * ImplGetChildWindow(vcl::Window *pParent, sal_uInt16 n, sal_uInt16 &nIndex, bool bTestEnable)
Definition: dlgctrl.cxx:146
vcl::Window * ImplFindDlgCtrlWindow(vcl::Window *pParent, vcl::Window *pWindow, sal_uInt16 &rIndex, sal_uInt16 &rFormStart, sal_uInt16 &rFormEnd)
Definition: dlgctrl.cxx:327
sal_Int32 nIndex
bool isVisibleInLayout(const vcl::Window *pWindow)
Definition: layout.cxx:2897
static vcl::Window * ImplGetLabelFor(vcl::Window *pFrameWindow, WindowType nMyType, vcl::Window *pLabel, sal_Unicode nAccel)
static Window * ImplGetLabeledBy(Window *pFrameWindow, WindowType nMyType, Window *pLabeled)
QPRO_FUNC_TYPE nType
sal_uInt16 sal_Unicode
sal_Int64 WinBits
Definition: wintypes.hxx:109
WinBits const WB_DIALOGCONTROL
Definition: wintypes.hxx:113
WindowType
Definition: wintypes.hxx:27
WinBits const WB_NOLABEL
Definition: wintypes.hxx:157
WinBits const WB_NODIALOGCONTROL
Definition: wintypes.hxx:114