build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / window / legacyaccessibility.cxx
blob1cddcab062019f3af6ed7984c73012bfcd1ed5cb
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 .
20 #include <tools/debug.hxx>
22 #include <svdata.hxx>
24 #include <dlgctrl.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/fixed.hxx>
27 #include <vcl/layout.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/tabpage.hxx>
30 #include <vcl/tabctrl.hxx>
31 #include <vcl/tabdlg.hxx>
32 #include <vcl/button.hxx>
33 #include <vcl/settings.hxx>
34 #include <vcl/unohelp.hxx>
36 #include <com/sun/star/i18n/XCharacterClassification.hpp>
38 using namespace ::com::sun::star;
41 static vcl::Window* ImplGetLabelFor( vcl::Window* pFrameWindow, WindowType nMyType, vcl::Window* pLabel, sal_Unicode nAccel )
43 vcl::Window* pWindow = nullptr;
45 if( nMyType == WINDOW_FIXEDTEXT ||
46 nMyType == WINDOW_FIXEDLINE ||
47 nMyType == WINDOW_GROUPBOX )
49 // #i100833# MT 2010/02: Group box and fixed lines can also label a fixed text.
50 // See tools/options/print for example.
51 bool bThisIsAGroupControl = (nMyType == WINDOW_GROUPBOX) || (nMyType == WINDOW_FIXEDLINE);
52 // get index, form start and form end
53 sal_uInt16 nIndex=0, nFormStart=0, nFormEnd=0;
54 ::ImplFindDlgCtrlWindow( pFrameWindow,
55 pLabel,
56 nIndex,
57 nFormStart,
58 nFormEnd );
59 if( nAccel )
61 // find the accelerated window
62 pWindow = ::ImplFindAccelWindow( pFrameWindow,
63 nIndex,
64 nAccel,
65 nFormStart,
66 nFormEnd,
67 false );
69 else
71 // find the next control; if that is a fixed text
72 // fixed line or group box, then return NULL
73 while( nIndex < nFormEnd )
75 nIndex++;
76 vcl::Window* pSWindow = ::ImplGetChildWindow( pFrameWindow,
77 nIndex,
78 nIndex,
79 false );
80 if( pSWindow && isVisibleInLayout(pSWindow) && ! (pSWindow->GetStyle() & WB_NOLABEL) )
82 WindowType nType = pSWindow->GetType();
83 if( nType != WINDOW_FIXEDTEXT &&
84 nType != WINDOW_FIXEDLINE &&
85 nType != WINDOW_GROUPBOX )
87 pWindow = pSWindow;
89 else if( bThisIsAGroupControl && ( nType == WINDOW_FIXEDTEXT ) )
91 pWindow = pSWindow;
93 break;
99 return pWindow;
102 namespace vcl {
104 Window* Window::getLegacyNonLayoutAccessibleRelationLabelFor() const
106 Window* pWindow = nullptr;
107 Window* pFrameWindow = ImplGetFrameWindow();
109 WinBits nFrameStyle = pFrameWindow->GetStyle();
110 if( ! ( nFrameStyle & WB_DIALOGCONTROL )
111 || ( nFrameStyle & WB_NODIALOGCONTROL )
113 return nullptr;
115 if ( mpWindowImpl->mpRealParent )
116 pWindow = mpWindowImpl->mpRealParent->GetParentLabelFor( this );
118 if( pWindow )
119 return pWindow;
121 sal_Unicode nAccel = getAccel( GetText() );
123 pWindow = ImplGetLabelFor( pFrameWindow, GetType(), const_cast<Window*>(this), nAccel );
124 if( ! pWindow && mpWindowImpl->mpRealParent )
125 pWindow = ImplGetLabelFor( mpWindowImpl->mpRealParent, GetType(), const_cast<Window*>(this), nAccel );
126 return pWindow;
129 static Window* ImplGetLabeledBy( Window* pFrameWindow, WindowType nMyType, Window* pLabeled )
131 Window* pWindow = nullptr;
132 if ( (nMyType != WINDOW_GROUPBOX) && (nMyType != WINDOW_FIXEDLINE) )
134 // search for a control that labels this window
135 // a label is considered the last fixed text, fixed line or group box
136 // that comes before this control; with the exception of push buttons
137 // which are labeled only if the fixed text, fixed line or group box
138 // is directly before the control
140 // get form start and form end and index of this control
141 sal_uInt16 nIndex, nFormStart, nFormEnd;
142 Window* pSWindow = ::ImplFindDlgCtrlWindow( pFrameWindow,
143 pLabeled,
144 nIndex,
145 nFormStart,
146 nFormEnd );
147 if( pSWindow && nIndex != nFormStart )
149 if( nMyType == WINDOW_PUSHBUTTON ||
150 nMyType == WINDOW_HELPBUTTON ||
151 nMyType == WINDOW_OKBUTTON ||
152 nMyType == WINDOW_CANCELBUTTON )
154 nFormStart = nIndex-1;
156 for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- )
158 sal_uInt16 nFoundIndex = 0;
159 pSWindow = ::ImplGetChildWindow( pFrameWindow,
160 nSearchIndex,
161 nFoundIndex,
162 false );
163 if( pSWindow && isVisibleInLayout(pSWindow) && !(pSWindow->GetStyle() & WB_NOLABEL) )
165 WindowType nType = pSWindow->GetType();
166 if ( ( nType == WINDOW_FIXEDTEXT ||
167 nType == WINDOW_FIXEDLINE ||
168 nType == WINDOW_GROUPBOX ) )
170 // a fixed text can't be labeld by a fixed text.
171 if ( ( nMyType != WINDOW_FIXEDTEXT ) || ( nType != WINDOW_FIXEDTEXT ) )
172 pWindow = pSWindow;
173 break;
176 if( nFoundIndex > nSearchIndex || nSearchIndex == 0 )
177 break;
181 return pWindow;
184 Window* Window::getLegacyNonLayoutAccessibleRelationLabeledBy() const
186 Window* pWindow = nullptr;
187 Window* pFrameWindow = ImplGetFrameWindow();
189 if ( mpWindowImpl->mpRealParent )
191 pWindow = mpWindowImpl->mpRealParent->GetParentLabeledBy( this );
193 if( pWindow )
194 return pWindow;
197 // #i62723#, #104191# checkboxes and radiobuttons are not supposed to have labels
198 if( GetType() == WINDOW_CHECKBOX || GetType() == WINDOW_RADIOBUTTON )
199 return nullptr;
201 // if( ! ( GetType() == WINDOW_FIXEDTEXT ||
202 // GetType() == WINDOW_FIXEDLINE ||
203 // GetType() == WINDOW_GROUPBOX ) )
204 // #i100833# MT 2010/02: Group box and fixed lines can also label a fixed text.
205 // See tools/options/print for example.
207 pWindow = ImplGetLabeledBy( pFrameWindow, GetType(), const_cast<Window*>(this) );
208 if( ! pWindow && mpWindowImpl->mpRealParent )
209 pWindow = ImplGetLabeledBy( mpWindowImpl->mpRealParent, GetType(), const_cast<Window*>(this) );
211 return pWindow;
214 Window* Window::getLegacyNonLayoutAccessibleRelationMemberOf() const
216 Window* pWindow = nullptr;
217 Window* pFrameWindow = GetParent();
218 if ( !pFrameWindow )
220 pFrameWindow = ImplGetFrameWindow();
222 // if( ! ( GetType() == WINDOW_FIXEDTEXT ||
223 if( !( GetType() == WINDOW_FIXEDLINE ||
224 GetType() == WINDOW_GROUPBOX ) )
226 // search for a control that makes member of this window
227 // it is considered the last fixed line or group box
228 // that comes before this control; with the exception of push buttons
229 // which are labeled only if the fixed line or group box
230 // is directly before the control
231 // get form start and form end and index of this control
232 sal_uInt16 nIndex, nFormStart, nFormEnd;
233 Window* pSWindow = ::ImplFindDlgCtrlWindow( pFrameWindow,
234 const_cast<Window*>(this),
235 nIndex,
236 nFormStart,
237 nFormEnd );
238 if( pSWindow && nIndex != nFormStart )
240 if( GetType() == WINDOW_PUSHBUTTON ||
241 GetType() == WINDOW_HELPBUTTON ||
242 GetType() == WINDOW_OKBUTTON ||
243 GetType() == WINDOW_CANCELBUTTON )
245 nFormStart = nIndex-1;
247 for( sal_uInt16 nSearchIndex = nIndex-1; nSearchIndex >= nFormStart; nSearchIndex-- )
249 sal_uInt16 nFoundIndex = 0;
250 pSWindow = ::ImplGetChildWindow( pFrameWindow,
251 nSearchIndex,
252 nFoundIndex,
253 false );
254 if( pSWindow && pSWindow->IsVisible() &&
255 ( pSWindow->GetType() == WINDOW_FIXEDLINE ||
256 pSWindow->GetType() == WINDOW_GROUPBOX ) )
258 pWindow = pSWindow;
259 break;
261 if( nFoundIndex > nSearchIndex || nSearchIndex == 0 )
262 break;
266 return pWindow;
269 } /* namespace vcl */
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */