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
ImplGetLabelFor(vcl::Window * pFrameWindow,WindowType nMyType,vcl::Window * pLabel,sal_Unicode nAccel)28 static 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();
70 if( nType != WindowType::FIXEDTEXT &&
71 nType != WindowType::FIXEDLINE &&
72 nType != WindowType::GROUPBOX )
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
89 namespace vcl {
90
getLegacyNonLayoutAccessibleRelationLabelFor() const91 Window* Window::getLegacyNonLayoutAccessibleRelationLabelFor() const
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
ImplGetLabeledBy(Window * pFrameWindow,WindowType nMyType,Window * pLabeled)109 static 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();
146 if ( nType == WindowType::FIXEDTEXT ||
147 nType == WindowType::FIXEDLINE ||
148 nType == WindowType::GROUPBOX )
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
getLegacyNonLayoutAccessibleRelationLabeledBy() const164 Window* Window::getLegacyNonLayoutAccessibleRelationLabeledBy() const
165 {
166 Window* pFrameWindow = ImplGetFrameWindow();
167
168 // #i62723#, #104191# checkboxes and radiobuttons are not supposed to have labels
169 if( GetType() == WindowType::CHECKBOX || GetType() == WindowType::RADIOBUTTON )
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
getLegacyNonLayoutAccessibleRelationMemberOf() const185 Window* Window::getLegacyNonLayoutAccessibleRelationMemberOf() const
186 {
187 Window* pWindow = nullptr;
188 Window* pFrameWindow = GetParent();
189 if ( !pFrameWindow )
190 {
191 pFrameWindow = ImplGetFrameWindow();
192 }
193 // if( ! ( GetType() == WindowType::FIXEDTEXT ||
194 if( GetType() != WindowType::FIXEDLINE && GetType() != WindowType::GROUPBOX )
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 {
210 if( GetType() == WindowType::PUSHBUTTON ||
211 GetType() == WindowType::HELPBUTTON ||
212 GetType() == WindowType::OKBUTTON ||
213 GetType() == WindowType::CANCELBUTTON )
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: */
242