Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / window / legacyaccessibility.cxx
blob376d0d08af6ffec71918aa2c29d87fb791c6723f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <window.h>
23 #include "dlgctrl.hxx"
25 using namespace ::com::sun::star;
28 static vcl::Window* ImplGetLabelFor( vcl::Window* pFrameWindow, WindowType nMyType, vcl::Window* pLabel, sal_Unicode nAccel )
30 vcl::Window* pWindow = nullptr;
32 if( nMyType == WindowType::FIXEDTEXT ||
33 nMyType == WindowType::FIXEDLINE ||
34 nMyType == WindowType::GROUPBOX )
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 )
48 // find the accelerated window
49 pWindow = ::ImplFindAccelWindow( pFrameWindow,
50 nIndex,
51 nAccel,
52 nFormStart,
53 nFormEnd,
54 false );
56 else
58 // find the next control; if that is a fixed text
59 // fixed line or group box, then return NULL
60 while( nIndex < nFormEnd )
62 nIndex++;
63 vcl::Window* pSWindow = ::ImplGetChildWindow( pFrameWindow,
64 nIndex,
65 nIndex,
66 false );
67 if( pSWindow && isVisibleInLayout(pSWindow) && ! (pSWindow->GetStyle() & WB_NOLABEL) )
69 WindowType nType = pSWindow->GetType();
70 if( nType != WindowType::FIXEDTEXT &&
71 nType != WindowType::FIXEDLINE &&
72 nType != WindowType::GROUPBOX )
74 pWindow = pSWindow;
76 else if( bThisIsAGroupControl && ( nType == WindowType::FIXEDTEXT ) )
78 pWindow = pSWindow;
80 break;
86 return pWindow;
89 namespace vcl {
91 Window* Window::getLegacyNonLayoutAccessibleRelationLabelFor() const
93 Window* pFrameWindow = ImplGetFrameWindow();
95 WinBits nFrameStyle = pFrameWindow->GetStyle();
96 if( ! ( nFrameStyle & WB_DIALOGCONTROL )
97 || ( nFrameStyle & WB_NODIALOGCONTROL )
99 return nullptr;
101 sal_Unicode nAccel = getAccel( GetText() );
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;
109 static Window* ImplGetLabeledBy( Window* pFrameWindow, WindowType nMyType, Window* pLabeled )
111 Window* pWindow = nullptr;
112 if ( (nMyType != WindowType::GROUPBOX) && (nMyType != WindowType::FIXEDLINE) )
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
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 )
129 if( nMyType == WindowType::PUSHBUTTON ||
130 nMyType == WindowType::HELPBUTTON ||
131 nMyType == WindowType::OKBUTTON ||
132 nMyType == WindowType::CANCELBUTTON )
134 nFormStart = nIndex-1;
136 for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- )
138 sal_uInt16 nFoundIndex = 0;
139 pSWindow = ::ImplGetChildWindow( pFrameWindow,
140 nSearchIndex,
141 nFoundIndex,
142 false );
143 if( pSWindow && isVisibleInLayout(pSWindow) && !(pSWindow->GetStyle() & WB_NOLABEL) )
145 WindowType nType = pSWindow->GetType();
146 if ( nType == WindowType::FIXEDTEXT ||
147 nType == WindowType::FIXEDLINE ||
148 nType == WindowType::GROUPBOX )
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;
156 if( nFoundIndex > nSearchIndex || nSearchIndex == 0 )
157 break;
161 return pWindow;
164 Window* Window::getLegacyNonLayoutAccessibleRelationLabeledBy() const
166 Window* pFrameWindow = ImplGetFrameWindow();
168 // #i62723#, #104191# checkboxes and radiobuttons are not supposed to have labels
169 if( GetType() == WindowType::CHECKBOX || GetType() == WindowType::RADIOBUTTON )
170 return nullptr;
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.
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) );
182 return pWindow;
185 Window* Window::getLegacyNonLayoutAccessibleRelationMemberOf() const
187 Window* pWindow = nullptr;
188 Window* pFrameWindow = GetParent();
189 if ( !pFrameWindow )
191 pFrameWindow = ImplGetFrameWindow();
193 // if( ! ( GetType() == WindowType::FIXEDTEXT ||
194 if( !( GetType() == WindowType::FIXEDLINE ||
195 GetType() == WindowType::GROUPBOX ) )
197 // search for a control that makes member of this window
198 // it is considered the last fixed line or group box
199 // that comes before this control; with the exception of push buttons
200 // which are labeled only if the fixed line or group box
201 // is directly before the control
202 // get form start and form end and index of this control
203 sal_uInt16 nIndex, nFormStart, nFormEnd;
204 Window* pSWindow = ::ImplFindDlgCtrlWindow( pFrameWindow,
205 const_cast<Window*>(this),
206 nIndex,
207 nFormStart,
208 nFormEnd );
209 if( pSWindow && nIndex != nFormStart )
211 if( GetType() == WindowType::PUSHBUTTON ||
212 GetType() == WindowType::HELPBUTTON ||
213 GetType() == WindowType::OKBUTTON ||
214 GetType() == WindowType::CANCELBUTTON )
216 nFormStart = nIndex-1;
218 for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- )
220 sal_uInt16 nFoundIndex = 0;
221 pSWindow = ::ImplGetChildWindow( pFrameWindow,
222 nSearchIndex,
223 nFoundIndex,
224 false );
225 if( pSWindow && pSWindow->IsVisible() &&
226 ( pSWindow->GetType() == WindowType::FIXEDLINE ||
227 pSWindow->GetType() == WindowType::GROUPBOX ) )
229 pWindow = pSWindow;
230 break;
232 if( nFoundIndex > nSearchIndex || nSearchIndex == 0 )
233 break;
237 return pWindow;
240 } /* namespace vcl */
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */