/src/libreoffice/vcl/source/control/button.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 | | #include <tools/poly.hxx> |
21 | | |
22 | | #include <vcl/builder.hxx> |
23 | | #include <vcl/cvtgrf.hxx> |
24 | | #include <vcl/image.hxx> |
25 | | #include <vcl/bitmap.hxx> |
26 | | #include <vcl/decoview.hxx> |
27 | | #include <vcl/event.hxx> |
28 | | #include <vcl/svapp.hxx> |
29 | | #include <vcl/settings.hxx> |
30 | | #include <vcl/toolkit/dialog.hxx> |
31 | | #include <vcl/toolkit/fixed.hxx> |
32 | | #include <vcl/toolkit/button.hxx> |
33 | | #include <vcl/salnativewidgets.hxx> |
34 | | #include <vcl/toolkit/edit.hxx> |
35 | | #include <vcl/layout.hxx> |
36 | | #include <vcl/stdtext.hxx> |
37 | | #include <vcl/uitest/uiobject.hxx> |
38 | | |
39 | | #include <accessibility/vclxaccessiblebutton.hxx> |
40 | | #include <accessibility/vclxaccessiblecheckbox.hxx> |
41 | | #include <accessibility/vclxaccessibleradiobutton.hxx> |
42 | | #include <bitmaps.hlst> |
43 | | #include <svdata.hxx> |
44 | | #include <window.h> |
45 | | #include <vclstatuslistener.hxx> |
46 | | #include <osl/diagnose.h> |
47 | | |
48 | | #include <comphelper/base64.hxx> |
49 | | #include <comphelper/dispatchcommand.hxx> |
50 | | #include <comphelper/lok.hxx> |
51 | | #include <officecfg/Office/Common.hxx> |
52 | | #include <boost/property_tree/ptree.hpp> |
53 | | #include <tools/json_writer.hxx> |
54 | | #include <tools/stream.hxx> |
55 | | |
56 | | |
57 | | using namespace css; |
58 | | |
59 | | constexpr auto PUSHBUTTON_VIEW_STYLE = WB_3DLOOK | |
60 | | WB_LEFT | WB_CENTER | WB_RIGHT | |
61 | | WB_TOP | WB_VCENTER | WB_BOTTOM | |
62 | | WB_WORDBREAK | WB_NOLABEL | |
63 | | WB_DEFBUTTON | WB_NOLIGHTBORDER | |
64 | | WB_RECTSTYLE | WB_SMALLSTYLE | |
65 | | WB_TOGGLE; |
66 | | constexpr auto RADIOBUTTON_VIEW_STYLE = WB_3DLOOK | |
67 | | WB_LEFT | WB_CENTER | WB_RIGHT | |
68 | | WB_TOP | WB_VCENTER | WB_BOTTOM | |
69 | | WB_WORDBREAK | WB_NOLABEL; |
70 | | constexpr auto CHECKBOX_VIEW_STYLE = WB_3DLOOK | |
71 | | WB_LEFT | WB_CENTER | WB_RIGHT | |
72 | | WB_TOP | WB_VCENTER | WB_BOTTOM | |
73 | | WB_WORDBREAK | WB_NOLABEL; |
74 | | |
75 | 0 | #define STYLE_RADIOBUTTON_MONO (sal_uInt16(0x0001)) // legacy |
76 | 0 | #define STYLE_CHECKBOX_MONO (sal_uInt16(0x0001)) // legacy |
77 | | |
78 | | class ImplCommonButtonData |
79 | | { |
80 | | public: |
81 | | ImplCommonButtonData(); |
82 | | |
83 | | tools::Rectangle maFocusRect; |
84 | | DrawButtonFlags mnButtonState; |
85 | | bool mbSmallSymbol; |
86 | | bool mbGeneratedTooltip; |
87 | | |
88 | | Image maImage; |
89 | | ImageAlign meImageAlign; |
90 | | SymbolAlign meSymbolAlign; |
91 | | |
92 | | Image maCustomContentImage; |
93 | | |
94 | | /** StatusListener. Updates the button as the slot state changes */ |
95 | | rtl::Reference<VclStatusListener<Button>> mpStatusListener; |
96 | | }; |
97 | | |
98 | 0 | ImplCommonButtonData::ImplCommonButtonData() : mnButtonState(DrawButtonFlags::NONE), |
99 | 0 | mbSmallSymbol(false), mbGeneratedTooltip(false), meImageAlign(ImageAlign::Top), meSymbolAlign(SymbolAlign::LEFT) |
100 | 0 | { |
101 | 0 | } |
102 | | |
103 | | Button::Button( WindowType eType ) : |
104 | 0 | Control( eType ), |
105 | 0 | mpButtonData( std::make_unique<ImplCommonButtonData>() ) |
106 | 0 | { |
107 | 0 | } Unexecuted instantiation: Button::Button(WindowType) Unexecuted instantiation: Button::Button(WindowType) |
108 | | |
109 | | Button::~Button() |
110 | 0 | { |
111 | 0 | disposeOnce(); |
112 | 0 | } |
113 | | |
114 | | void Button::dispose() |
115 | 0 | { |
116 | 0 | if (mpButtonData->mpStatusListener.is()) |
117 | 0 | mpButtonData->mpStatusListener->dispose(); |
118 | 0 | Control::dispose(); |
119 | 0 | } |
120 | | |
121 | | void Button::SetCommandHandler(const OUString& aCommand, const css::uno::Reference<css::frame::XFrame>& rFrame) |
122 | 0 | { |
123 | 0 | maCommand = aCommand; |
124 | 0 | SetClickHdl( LINK( this, Button, dispatchCommandHandler) ); |
125 | |
|
126 | 0 | mpButtonData->mpStatusListener = new VclStatusListener<Button>(this, rFrame, aCommand); |
127 | 0 | mpButtonData->mpStatusListener->startListening(); |
128 | 0 | } |
129 | | |
130 | | void Button::Click() |
131 | 0 | { |
132 | 0 | ImplCallEventListenersAndHandler( VclEventId::ButtonClick, [this] () { maClickHdl.Call(this); } ); |
133 | 0 | } |
134 | | |
135 | | void Button::SetModeImage( const Image& rImage ) |
136 | 0 | { |
137 | 0 | if ( rImage != mpButtonData->maImage ) |
138 | 0 | { |
139 | 0 | mpButtonData->maImage = rImage; |
140 | 0 | StateChanged( StateChangedType::Data ); |
141 | 0 | queue_resize(); |
142 | 0 | } |
143 | 0 | } |
144 | | |
145 | | Image const & Button::GetModeImage( ) const |
146 | 0 | { |
147 | 0 | return mpButtonData->maImage; |
148 | 0 | } |
149 | | |
150 | | bool Button::HasImage() const |
151 | 0 | { |
152 | 0 | return !!(mpButtonData->maImage); |
153 | 0 | } |
154 | | |
155 | | void Button::SetImageAlign( ImageAlign eAlign ) |
156 | 0 | { |
157 | 0 | if ( mpButtonData->meImageAlign != eAlign ) |
158 | 0 | { |
159 | 0 | mpButtonData->meImageAlign = eAlign; |
160 | 0 | StateChanged( StateChangedType::Data ); |
161 | 0 | } |
162 | 0 | } |
163 | | |
164 | | ImageAlign Button::GetImageAlign() const |
165 | 0 | { |
166 | 0 | return mpButtonData->meImageAlign; |
167 | 0 | } |
168 | | |
169 | | void Button::SetCustomButtonImage(const Image& rImage) |
170 | 0 | { |
171 | 0 | if (rImage != mpButtonData->maCustomContentImage) |
172 | 0 | { |
173 | 0 | mpButtonData->maCustomContentImage = rImage; |
174 | 0 | StateChanged( StateChangedType::Data ); |
175 | 0 | } |
176 | 0 | } |
177 | | |
178 | | Image const & Button::GetCustomButtonImage() const |
179 | 0 | { |
180 | 0 | return mpButtonData->maCustomContentImage; |
181 | 0 | } |
182 | | |
183 | | DrawTextFlags Button::ImplGetTextStyle( WinBits nWinStyle, SystemTextColorFlags nSystemTextColorFlags ) const |
184 | 0 | { |
185 | 0 | const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); |
186 | 0 | DrawTextFlags nTextStyle = FixedText::ImplGetTextStyle(nWinStyle & ~WB_DEFBUTTON); |
187 | |
|
188 | 0 | if (!IsEnabled()) |
189 | 0 | nTextStyle |= DrawTextFlags::Disable; |
190 | |
|
191 | 0 | if ((nSystemTextColorFlags & SystemTextColorFlags::Mono) || |
192 | 0 | (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono)) |
193 | 0 | { |
194 | 0 | nTextStyle |= DrawTextFlags::Mono; |
195 | 0 | } |
196 | |
|
197 | 0 | return nTextStyle; |
198 | 0 | } |
199 | | |
200 | | void Button::ImplDrawAlignedImage(OutputDevice* pDev, Point& rPos, |
201 | | Size& rSize, |
202 | | sal_Int32 nImageSep, |
203 | | DrawTextFlags nTextStyle, tools::Rectangle *pSymbolRect, |
204 | | bool bAddImageSep) |
205 | 0 | { |
206 | 0 | OUString aText(GetText()); |
207 | 0 | bool bDrawImage = HasImage(); |
208 | 0 | bool bDrawText = !aText.isEmpty(); |
209 | 0 | bool bHasSymbol = pSymbolRect != nullptr; |
210 | | |
211 | | // No text and no image => nothing to do => return |
212 | 0 | if (!bDrawImage && !bDrawText && !bHasSymbol) |
213 | 0 | return; |
214 | | |
215 | 0 | WinBits nWinStyle = GetStyle(); |
216 | 0 | tools::Rectangle aOutRect( rPos, rSize ); |
217 | 0 | ImageAlign eImageAlign = mpButtonData->meImageAlign; |
218 | 0 | Size aImageSize = mpButtonData->maImage.GetSizePixel(); |
219 | |
|
220 | 0 | aImageSize.setWidth( CalcZoom( aImageSize.Width() ) ); |
221 | 0 | aImageSize.setHeight( CalcZoom( aImageSize.Height() ) ); |
222 | | |
223 | | // Drawing text or symbol only is simple, use style and output rectangle |
224 | 0 | if (bHasSymbol && !bDrawImage && !bDrawText) |
225 | 0 | { |
226 | 0 | *pSymbolRect = aOutRect; |
227 | 0 | return; |
228 | 0 | } |
229 | 0 | else if (bDrawText && !bDrawImage && !bHasSymbol) |
230 | 0 | { |
231 | 0 | aOutRect = DrawControlText(*pDev, aOutRect, aText, nTextStyle, nullptr, nullptr); |
232 | 0 | tools::Rectangle textRect = GetTextRect( |
233 | 0 | tools::Rectangle(Point(), Size(0x7fffffff, 0x7fffffff)), aText, nTextStyle); |
234 | | // If the button text doesn't fit into it, put it into a tooltip (might happen in sidebar) |
235 | 0 | if (GetQuickHelpText()!= aText && mpButtonData->mbGeneratedTooltip) |
236 | 0 | SetQuickHelpText(u""_ustr); |
237 | 0 | if (GetQuickHelpText().isEmpty() && textRect.getOpenWidth() > rSize.getWidth()) |
238 | 0 | { |
239 | 0 | SetQuickHelpText(aText); |
240 | 0 | mpButtonData->mbGeneratedTooltip = true; |
241 | 0 | } |
242 | |
|
243 | 0 | ImplSetFocusRect(aOutRect); |
244 | 0 | rSize = aOutRect.GetSize(); |
245 | 0 | rPos = aOutRect.TopLeft(); |
246 | |
|
247 | 0 | return; |
248 | 0 | } |
249 | | |
250 | | // check for HC mode ( image only! ) |
251 | 0 | Image* pImage = &(mpButtonData->maImage); |
252 | |
|
253 | 0 | Size aTextSize; |
254 | 0 | Size aSymbolSize; |
255 | 0 | Size aDeviceTextSize; |
256 | 0 | Point aImagePos = rPos; |
257 | 0 | Point aTextPos = rPos; |
258 | 0 | tools::Rectangle aUnion(aImagePos, aImageSize); |
259 | 0 | tools::Long nSymbolHeight = 0; |
260 | |
|
261 | 0 | if (bDrawText || bHasSymbol) |
262 | 0 | { |
263 | | // Get the size of the text output area ( the symbol will be drawn in |
264 | | // this area as well, so the symbol rectangle will be calculated here, too ) |
265 | |
|
266 | 0 | tools::Rectangle aRect(Point(), rSize); |
267 | 0 | Size aTSSize; |
268 | |
|
269 | 0 | if (bHasSymbol) |
270 | 0 | { |
271 | 0 | tools::Rectangle aSymbol; |
272 | 0 | if (bDrawText) |
273 | 0 | { |
274 | 0 | nSymbolHeight = pDev->GetTextHeight(); |
275 | 0 | if (mpButtonData->mbSmallSymbol) |
276 | 0 | nSymbolHeight = nSymbolHeight * 3 / 4; |
277 | |
|
278 | 0 | aSymbol = tools::Rectangle(Point(), Size(nSymbolHeight, nSymbolHeight)); |
279 | 0 | ImplCalcSymbolRect(aSymbol); |
280 | 0 | aRect.AdjustLeft(3 * nSymbolHeight / 2 ); |
281 | 0 | aTSSize.setWidth( 3 * nSymbolHeight / 2 ); |
282 | 0 | } |
283 | 0 | else |
284 | 0 | { |
285 | 0 | aSymbol = tools::Rectangle(Point(), rSize); |
286 | 0 | ImplCalcSymbolRect(aSymbol); |
287 | 0 | aTSSize.setWidth( aSymbol.GetWidth() ); |
288 | 0 | } |
289 | 0 | aTSSize.setHeight( aSymbol.GetHeight() ); |
290 | 0 | aSymbolSize = aSymbol.GetSize(); |
291 | 0 | } |
292 | |
|
293 | 0 | if (bDrawText) |
294 | 0 | { |
295 | 0 | if ((eImageAlign == ImageAlign::LeftTop) || |
296 | 0 | (eImageAlign == ImageAlign::Left ) || |
297 | 0 | (eImageAlign == ImageAlign::LeftBottom) || |
298 | 0 | (eImageAlign == ImageAlign::RightTop) || |
299 | 0 | (eImageAlign == ImageAlign::Right) || |
300 | 0 | (eImageAlign == ImageAlign::RightBottom)) |
301 | 0 | { |
302 | 0 | aRect.AdjustRight( -sal_Int32(aImageSize.Width() + nImageSep) ); |
303 | 0 | } |
304 | 0 | else if ((eImageAlign == ImageAlign::TopLeft) || |
305 | 0 | (eImageAlign == ImageAlign::Top) || |
306 | 0 | (eImageAlign == ImageAlign::TopRight) || |
307 | 0 | (eImageAlign == ImageAlign::BottomLeft) || |
308 | 0 | (eImageAlign == ImageAlign::Bottom) || |
309 | 0 | (eImageAlign == ImageAlign::BottomRight)) |
310 | 0 | { |
311 | 0 | aRect.AdjustBottom( -sal_Int32(aImageSize.Height() + nImageSep) ); |
312 | 0 | } |
313 | |
|
314 | 0 | aRect = GetControlTextRect(*pDev, aRect, aText, nTextStyle, &aDeviceTextSize); |
315 | 0 | aTextSize = aRect.GetSize(); |
316 | |
|
317 | 0 | aTSSize.AdjustWidth(aTextSize.Width() ); |
318 | |
|
319 | 0 | if (aTSSize.Height() < aTextSize.Height()) |
320 | 0 | aTSSize.setHeight( aTextSize.Height() ); |
321 | |
|
322 | 0 | if (bAddImageSep && bDrawImage) |
323 | 0 | { |
324 | 0 | tools::Long nDiff = (aImageSize.Height() - aTextSize.Height()) / 3; |
325 | 0 | if (nDiff > 0) |
326 | 0 | nImageSep += nDiff; |
327 | 0 | } |
328 | 0 | } |
329 | |
|
330 | 0 | Size aMax; |
331 | 0 | aMax.setWidth( std::max(aTSSize.Width(), aImageSize.Width()) ); |
332 | 0 | aMax.setHeight( std::max(aTSSize.Height(), aImageSize.Height()) ); |
333 | | |
334 | | // Now calculate the output area for the image and the text according to the image align flags |
335 | |
|
336 | 0 | if ((eImageAlign == ImageAlign::Left) || |
337 | 0 | (eImageAlign == ImageAlign::Right)) |
338 | 0 | { |
339 | 0 | aImagePos.setY( rPos.Y() + (aMax.Height() - aImageSize.Height()) / 2 ); |
340 | 0 | aTextPos.setY( rPos.Y() + (aMax.Height() - aTSSize.Height()) / 2 ); |
341 | 0 | } |
342 | 0 | else if ((eImageAlign == ImageAlign::LeftBottom) || |
343 | 0 | (eImageAlign == ImageAlign::RightBottom)) |
344 | 0 | { |
345 | 0 | aImagePos.setY( rPos.Y() + aMax.Height() - aImageSize.Height() ); |
346 | 0 | aTextPos.setY( rPos.Y() + aMax.Height() - aTSSize.Height() ); |
347 | 0 | } |
348 | 0 | else if ((eImageAlign == ImageAlign::Top) || |
349 | 0 | (eImageAlign == ImageAlign::Bottom)) |
350 | 0 | { |
351 | 0 | aImagePos.setX( rPos.X() + (aMax.Width() - aImageSize.Width()) / 2 ); |
352 | 0 | aTextPos.setX( rPos.X() + (aMax.Width() - aTSSize.Width()) / 2 ); |
353 | 0 | } |
354 | 0 | else if ((eImageAlign == ImageAlign::TopRight) || |
355 | 0 | (eImageAlign == ImageAlign::BottomRight)) |
356 | 0 | { |
357 | 0 | aImagePos.setX( rPos.X() + aMax.Width() - aImageSize.Width() ); |
358 | 0 | aTextPos.setX( rPos.X() + aMax.Width() - aTSSize.Width() ); |
359 | 0 | } |
360 | |
|
361 | 0 | if ((eImageAlign == ImageAlign::LeftTop) || |
362 | 0 | (eImageAlign == ImageAlign::Left) || |
363 | 0 | (eImageAlign == ImageAlign::LeftBottom)) |
364 | 0 | { |
365 | 0 | aTextPos.setX( rPos.X() + aImageSize.Width() + nImageSep ); |
366 | 0 | } |
367 | 0 | else if ((eImageAlign == ImageAlign::RightTop) || |
368 | 0 | (eImageAlign == ImageAlign::Right) || |
369 | 0 | (eImageAlign == ImageAlign::RightBottom)) |
370 | 0 | { |
371 | 0 | aImagePos.setX( rPos.X() + aTSSize.Width() + nImageSep ); |
372 | 0 | } |
373 | 0 | else if ((eImageAlign == ImageAlign::TopLeft) || |
374 | 0 | (eImageAlign == ImageAlign::Top) || |
375 | 0 | (eImageAlign == ImageAlign::TopRight)) |
376 | 0 | { |
377 | 0 | aTextPos.setY( rPos.Y() + aImageSize.Height() + nImageSep ); |
378 | 0 | } |
379 | 0 | else if ((eImageAlign == ImageAlign::BottomLeft) || |
380 | 0 | (eImageAlign == ImageAlign::Bottom) || |
381 | 0 | (eImageAlign == ImageAlign::BottomRight)) |
382 | 0 | { |
383 | 0 | aImagePos.setY( rPos.Y() + aTSSize.Height() + nImageSep ); |
384 | 0 | } |
385 | 0 | else if (eImageAlign == ImageAlign::Center) |
386 | 0 | { |
387 | 0 | aImagePos.setX( rPos.X() + (aMax.Width() - aImageSize.Width()) / 2 ); |
388 | 0 | aImagePos.setY( rPos.Y() + (aMax.Height() - aImageSize.Height()) / 2 ); |
389 | 0 | aTextPos.setX( rPos.X() + (aMax.Width() - aTSSize.Width()) / 2 ); |
390 | 0 | aTextPos.setY( rPos.Y() + (aMax.Height() - aTSSize.Height()) / 2 ); |
391 | 0 | } |
392 | 0 | aUnion = tools::Rectangle(aImagePos, aImageSize); |
393 | 0 | aUnion.Union(tools::Rectangle(aTextPos, aTSSize)); |
394 | 0 | } |
395 | | |
396 | | // Now place the combination of text and image in the output area of the button |
397 | | // according to the window style (WinBits) |
398 | 0 | tools::Long nXOffset = 0; |
399 | 0 | tools::Long nYOffset = 0; |
400 | |
|
401 | 0 | if (nWinStyle & WB_CENTER) |
402 | 0 | { |
403 | 0 | nXOffset = (rSize.Width() - aUnion.GetWidth()) / 2; |
404 | 0 | } |
405 | 0 | else if (nWinStyle & WB_RIGHT) |
406 | 0 | { |
407 | 0 | nXOffset = rSize.Width() - aUnion.GetWidth(); |
408 | 0 | } |
409 | |
|
410 | 0 | if (nWinStyle & WB_VCENTER) |
411 | 0 | { |
412 | 0 | nYOffset = (rSize.Height() - aUnion.GetHeight()) / 2; |
413 | 0 | } |
414 | 0 | else if (nWinStyle & WB_BOTTOM) |
415 | 0 | { |
416 | 0 | nYOffset = rSize.Height() - aUnion.GetHeight(); |
417 | 0 | } |
418 | | |
419 | | // the top left corner should always be visible, so we don't allow negative offsets |
420 | 0 | if (nXOffset < 0) nXOffset = 0; |
421 | 0 | if (nYOffset < 0) nYOffset = 0; |
422 | |
|
423 | 0 | aImagePos.AdjustX(nXOffset ); |
424 | 0 | aImagePos.AdjustY(nYOffset ); |
425 | 0 | aTextPos.AdjustX(nXOffset ); |
426 | 0 | aTextPos.AdjustY(nYOffset ); |
427 | | |
428 | | // set rPos and rSize to the union |
429 | 0 | rSize = aUnion.GetSize(); |
430 | 0 | rPos.AdjustX(nXOffset ); |
431 | 0 | rPos.AdjustY(nYOffset ); |
432 | |
|
433 | 0 | if (bHasSymbol) |
434 | 0 | { |
435 | 0 | if (mpButtonData->meSymbolAlign == SymbolAlign::RIGHT) |
436 | 0 | { |
437 | 0 | Point aRightPos(aTextPos.X() + aTextSize.Width() + aSymbolSize.Width() / 2, aTextPos.Y()); |
438 | 0 | *pSymbolRect = tools::Rectangle(aRightPos, aSymbolSize); |
439 | 0 | } |
440 | 0 | else |
441 | 0 | { |
442 | 0 | *pSymbolRect = tools::Rectangle(aTextPos, aSymbolSize); |
443 | 0 | aTextPos.AdjustX(3 * nSymbolHeight / 2 ); |
444 | 0 | } |
445 | 0 | if (mpButtonData->mbSmallSymbol) |
446 | 0 | { |
447 | 0 | nYOffset = (aUnion.GetHeight() - aSymbolSize.Height()) / 2; |
448 | 0 | pSymbolRect->SetPosY(aTextPos.Y() + nYOffset); |
449 | 0 | } |
450 | 0 | } |
451 | |
|
452 | 0 | DrawImageFlags nStyle = DrawImageFlags::NONE; |
453 | |
|
454 | 0 | if (!IsEnabled()) |
455 | 0 | { |
456 | 0 | nStyle |= DrawImageFlags::Disable; |
457 | 0 | } |
458 | |
|
459 | 0 | if (IsZoom()) |
460 | 0 | pDev->DrawImage(aImagePos, aImageSize, *pImage, nStyle); |
461 | 0 | else |
462 | 0 | pDev->DrawImage(aImagePos, *pImage, nStyle); |
463 | |
|
464 | 0 | if (bDrawText) |
465 | 0 | { |
466 | 0 | const tools::Rectangle aTOutRect(aTextPos, aTextSize); |
467 | 0 | ImplSetFocusRect(aTOutRect); |
468 | 0 | DrawControlText(*pDev, aTOutRect, aText, nTextStyle, nullptr, nullptr, &aDeviceTextSize); |
469 | 0 | } |
470 | 0 | else |
471 | 0 | { |
472 | 0 | ImplSetFocusRect(tools::Rectangle(aImagePos, aImageSize)); |
473 | 0 | } |
474 | 0 | } |
475 | | |
476 | | void Button::ImplSetFocusRect(const tools::Rectangle &rFocusRect) |
477 | 0 | { |
478 | 0 | tools::Rectangle aFocusRect = rFocusRect; |
479 | 0 | tools::Rectangle aOutputRect(Point(), GetOutputSizePixel()); |
480 | |
|
481 | 0 | if (!aFocusRect.IsEmpty()) |
482 | 0 | { |
483 | 0 | aFocusRect.AdjustLeft( -1 ); |
484 | 0 | aFocusRect.AdjustTop( -1 ); |
485 | 0 | aFocusRect.AdjustRight( 1 ); |
486 | 0 | aFocusRect.AdjustBottom( 1 ); |
487 | 0 | } |
488 | |
|
489 | 0 | if (aFocusRect.Left() < aOutputRect.Left()) |
490 | 0 | aFocusRect.SetLeft( aOutputRect.Left() ); |
491 | 0 | if (aFocusRect.Top() < aOutputRect.Top()) |
492 | 0 | aFocusRect.SetTop( aOutputRect.Top() ); |
493 | 0 | if (aFocusRect.Right() > aOutputRect.Right()) |
494 | 0 | aFocusRect.SetRight( aOutputRect.Right() ); |
495 | 0 | if (aFocusRect.Bottom() > aOutputRect.Bottom()) |
496 | 0 | aFocusRect.SetBottom( aOutputRect.Bottom() ); |
497 | |
|
498 | 0 | mpButtonData->maFocusRect = aFocusRect; |
499 | 0 | } |
500 | | |
501 | | const tools::Rectangle& Button::ImplGetFocusRect() const |
502 | 0 | { |
503 | 0 | return mpButtonData->maFocusRect; |
504 | 0 | } |
505 | | |
506 | | DrawButtonFlags& Button::GetButtonState() |
507 | 0 | { |
508 | 0 | return mpButtonData->mnButtonState; |
509 | 0 | } |
510 | | |
511 | | DrawButtonFlags Button::GetButtonState() const |
512 | 0 | { |
513 | 0 | return mpButtonData->mnButtonState; |
514 | 0 | } |
515 | | |
516 | | void Button::ImplSetSymbolAlign( SymbolAlign eAlign ) |
517 | 0 | { |
518 | 0 | if ( mpButtonData->meSymbolAlign != eAlign ) |
519 | 0 | { |
520 | 0 | mpButtonData->meSymbolAlign = eAlign; |
521 | 0 | StateChanged( StateChangedType::Data ); |
522 | 0 | } |
523 | 0 | } |
524 | | |
525 | | void Button::SetSmallSymbol() |
526 | 0 | { |
527 | 0 | mpButtonData->mbSmallSymbol = true; |
528 | 0 | } |
529 | | |
530 | | bool Button::IsSmallSymbol () const |
531 | 0 | { |
532 | 0 | return mpButtonData->mbSmallSymbol; |
533 | 0 | } |
534 | | |
535 | | bool Button::set_property(const OUString &rKey, const OUString &rValue) |
536 | 0 | { |
537 | 0 | if (rKey == "image-position") |
538 | 0 | { |
539 | 0 | ImageAlign eAlign = ImageAlign::Left; |
540 | 0 | if (rValue == "left") |
541 | 0 | eAlign = ImageAlign::Left; |
542 | 0 | else if (rValue == "right") |
543 | 0 | eAlign = ImageAlign::Right; |
544 | 0 | else if (rValue == "top") |
545 | 0 | eAlign = ImageAlign::Top; |
546 | 0 | else if (rValue == "bottom") |
547 | 0 | eAlign = ImageAlign::Bottom; |
548 | 0 | SetImageAlign(eAlign); |
549 | 0 | } |
550 | 0 | else if (rKey == "focus-on-click") |
551 | 0 | { |
552 | 0 | WinBits nBits = GetStyle(); |
553 | 0 | nBits &= ~WB_NOPOINTERFOCUS; |
554 | 0 | if (!toBool(rValue)) |
555 | 0 | nBits |= WB_NOPOINTERFOCUS; |
556 | 0 | SetStyle(nBits); |
557 | 0 | } |
558 | 0 | else |
559 | 0 | return Control::set_property(rKey, rValue); |
560 | 0 | return true; |
561 | 0 | } |
562 | | |
563 | | void Button::statusChanged(const css::frame::FeatureStateEvent& rEvent) |
564 | 0 | { |
565 | 0 | Enable(rEvent.IsEnabled); |
566 | 0 | } |
567 | | |
568 | | FactoryFunction Button::GetUITestFactory() const |
569 | 0 | { |
570 | 0 | return ButtonUIObject::create; |
571 | 0 | } |
572 | | |
573 | | namespace |
574 | | { |
575 | | |
576 | | std::string_view symbolTypeName(SymbolType eSymbolType) |
577 | 0 | { |
578 | 0 | switch (eSymbolType) |
579 | 0 | { |
580 | 0 | case SymbolType::DONTKNOW: return "DONTKNOW"; |
581 | 0 | case SymbolType::IMAGE: return "IMAGE"; |
582 | 0 | case SymbolType::ARROW_UP: return "ARROW_UP"; |
583 | 0 | case SymbolType::ARROW_DOWN: return "ARROW_DOWN"; |
584 | 0 | case SymbolType::ARROW_LEFT: return "ARROW_LEFT"; |
585 | 0 | case SymbolType::ARROW_RIGHT: return "ARROW_RIGHT"; |
586 | 0 | case SymbolType::SPIN_UP: return "SPIN_UP"; |
587 | 0 | case SymbolType::SPIN_DOWN: return "SPIN_DOWN"; |
588 | 0 | case SymbolType::SPIN_LEFT: return "SPIN_LEFT"; |
589 | 0 | case SymbolType::SPIN_RIGHT: return "SPIN_RIGHT"; |
590 | 0 | case SymbolType::FIRST: return "FIRST"; |
591 | 0 | case SymbolType::LAST: return "LAST"; |
592 | 0 | case SymbolType::PREV: return "PREV"; |
593 | 0 | case SymbolType::NEXT: return "NEXT"; |
594 | 0 | case SymbolType::PAGEUP: return "PAGEUP"; |
595 | 0 | case SymbolType::PAGEDOWN: return "PAGEDOWN"; |
596 | 0 | case SymbolType::PLAY: return "PLAY"; |
597 | 0 | case SymbolType::STOP: return "STOP"; |
598 | 0 | case SymbolType::CLOSE: return "CLOSE"; |
599 | 0 | case SymbolType::CHECKMARK: return "CHECKMARK"; |
600 | 0 | case SymbolType::RADIOCHECKMARK: return "RADIOCHECKMARK"; |
601 | 0 | case SymbolType::FLOAT: return "FLOAT"; |
602 | 0 | case SymbolType::DOCK: return "DOCK"; |
603 | 0 | case SymbolType::HIDE: return "HIDE"; |
604 | 0 | case SymbolType::HELP: return "HELP"; |
605 | 0 | case SymbolType::PLUS: return "PLUS"; |
606 | 0 | } |
607 | | |
608 | 0 | return "UNKNOWN"; |
609 | 0 | } |
610 | | |
611 | | } |
612 | | |
613 | | void Button::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) |
614 | 0 | { |
615 | 0 | Control::DumpAsPropertyTree(rJsonWriter); |
616 | 0 | rJsonWriter.put("text", GetText()); |
617 | 0 | if (HasImage()) |
618 | 0 | { |
619 | 0 | SvMemoryStream aOStm(6535, 6535); |
620 | 0 | if(GraphicConverter::Export(aOStm, GetModeImage().GetBitmap(), ConvertDataFormat::PNG) == ERRCODE_NONE) |
621 | 0 | { |
622 | 0 | css::uno::Sequence<sal_Int8> aSeq( static_cast<sal_Int8 const *>(aOStm.GetData()), aOStm.Tell()); |
623 | 0 | OStringBuffer aBuffer("data:image/png;base64,"); |
624 | 0 | ::comphelper::Base64::encode(aBuffer, aSeq); |
625 | 0 | rJsonWriter.put("image", aBuffer); |
626 | 0 | } |
627 | 0 | } |
628 | |
|
629 | 0 | if (GetStyle() & WB_DEFBUTTON) |
630 | 0 | rJsonWriter.put("has_default", true); |
631 | 0 | } |
632 | | |
633 | | void PushButton::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) |
634 | 0 | { |
635 | 0 | Button::DumpAsPropertyTree(rJsonWriter); |
636 | 0 | if (GetSymbol() != SymbolType::DONTKNOW) |
637 | 0 | rJsonWriter.put("symbol", symbolTypeName(GetSymbol())); |
638 | 0 | if (isToggleButton()) |
639 | 0 | rJsonWriter.put("isToggle", true); |
640 | 0 | } |
641 | | |
642 | | IMPL_STATIC_LINK( Button, dispatchCommandHandler, Button*, pButton, void ) |
643 | 0 | { |
644 | 0 | if (pButton == nullptr) |
645 | 0 | return; |
646 | | |
647 | 0 | comphelper::dispatchCommand(pButton->maCommand, uno::Sequence<beans::PropertyValue>()); |
648 | 0 | } |
649 | | |
650 | | void PushButton::ImplInitPushButtonData() |
651 | 0 | { |
652 | 0 | mpWindowImpl->mbPushButton = true; |
653 | |
|
654 | 0 | meSymbol = SymbolType::DONTKNOW; |
655 | 0 | meState = TRISTATE_FALSE; |
656 | 0 | mnDDStyle = PushButtonDropdownStyle::NONE; |
657 | 0 | mbPressed = false; |
658 | 0 | mbIsAction = false; |
659 | 0 | } |
660 | | |
661 | | namespace |
662 | | { |
663 | | vcl::Window* getPreviousSibling(vcl::Window const *pParent) |
664 | 0 | { |
665 | 0 | return pParent ? pParent->GetWindow(GetWindowType::LastChild) : nullptr; |
666 | 0 | } |
667 | | } |
668 | | |
669 | | void PushButton::ImplInit( vcl::Window* pParent, WinBits nStyle ) |
670 | 0 | { |
671 | 0 | nStyle = ImplInitStyle(getPreviousSibling(pParent), nStyle); |
672 | 0 | Button::ImplInit( pParent, nStyle, nullptr ); |
673 | |
|
674 | 0 | if ( nStyle & WB_NOLIGHTBORDER ) |
675 | 0 | GetButtonState() |= DrawButtonFlags::NoLightBorder; |
676 | |
|
677 | 0 | ImplInitSettings( true ); |
678 | 0 | } |
679 | | |
680 | | WinBits PushButton::ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle ) |
681 | 0 | { |
682 | 0 | if ( !(nStyle & WB_NOTABSTOP) ) |
683 | 0 | nStyle |= WB_TABSTOP; |
684 | | |
685 | | // if no alignment is given, default to "vertically centered". This is because since |
686 | | // #i26046#, we respect the vertical alignment flags (previously we didn't completely), |
687 | | // but we of course want to look as before when no vertical alignment is specified |
688 | 0 | if ( ( nStyle & ( WB_TOP | WB_VCENTER | WB_BOTTOM ) ) == 0 ) |
689 | 0 | nStyle |= WB_VCENTER; |
690 | |
|
691 | 0 | if ( !(nStyle & WB_NOGROUP) && |
692 | 0 | (!pPrevWindow || |
693 | 0 | ((pPrevWindow->GetType() != WindowType::PUSHBUTTON ) && |
694 | 0 | (pPrevWindow->GetType() != WindowType::OKBUTTON ) && |
695 | 0 | (pPrevWindow->GetType() != WindowType::CANCELBUTTON) && |
696 | 0 | (pPrevWindow->GetType() != WindowType::HELPBUTTON )) ) ) |
697 | 0 | nStyle |= WB_GROUP; |
698 | 0 | return nStyle; |
699 | 0 | } |
700 | | |
701 | | const vcl::Font& PushButton::GetCanonicalFont( const StyleSettings& _rStyle ) const |
702 | 0 | { |
703 | 0 | return _rStyle.GetPushButtonFont(); |
704 | 0 | } |
705 | | |
706 | | const Color& PushButton::GetCanonicalTextColor( const StyleSettings& _rStyle ) const |
707 | 0 | { |
708 | 0 | return _rStyle.GetButtonTextColor(); |
709 | 0 | } |
710 | | |
711 | | void PushButton::ImplInitSettings( bool bBackground ) |
712 | 0 | { |
713 | 0 | Button::ImplInitSettings(); |
714 | |
|
715 | 0 | if ( !bBackground ) |
716 | 0 | return; |
717 | | |
718 | 0 | SetBackground(); |
719 | | // #i38498#: do not check for GetParent()->IsChildTransparentModeEnabled() |
720 | | // otherwise the formcontrol button will be overdrawn due to ParentClipMode::NoClip |
721 | | // for radio and checkbox this is ok as they should appear transparent in documents |
722 | 0 | if ( IsNativeControlSupported( ControlType::Pushbutton, ControlPart::Entire ) || |
723 | 0 | (GetStyle() & WB_FLATBUTTON) != 0 ) |
724 | 0 | { |
725 | 0 | EnableChildTransparentMode(); |
726 | 0 | SetParentClipMode( ParentClipMode::NoClip ); |
727 | 0 | SetPaintTransparent( true ); |
728 | |
|
729 | 0 | if ((GetStyle() & WB_FLATBUTTON) == 0) |
730 | 0 | mpWindowImpl->mbUseNativeFocus = ImplGetSVData()->maNWFData.mbNoFocusRects; |
731 | 0 | else |
732 | 0 | mpWindowImpl->mbUseNativeFocus = ImplGetSVData()->maNWFData.mbNoFocusRectsForFlatButtons; |
733 | 0 | } |
734 | 0 | else |
735 | 0 | { |
736 | 0 | EnableChildTransparentMode( false ); |
737 | 0 | SetParentClipMode(); |
738 | 0 | SetPaintTransparent( false ); |
739 | 0 | } |
740 | 0 | } |
741 | | |
742 | | void PushButton::ImplDrawPushButtonFrame(vcl::RenderContext& rRenderContext, |
743 | | tools::Rectangle& rRect, DrawButtonFlags nStyle) |
744 | 0 | { |
745 | 0 | if (!(GetStyle() & (WB_RECTSTYLE | WB_SMALLSTYLE))) |
746 | 0 | { |
747 | 0 | StyleSettings aStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); |
748 | 0 | if (IsControlBackground()) |
749 | 0 | aStyleSettings.Set3DColors(GetControlBackground()); |
750 | 0 | } |
751 | |
|
752 | 0 | DecorationView aDecoView(&rRenderContext); |
753 | 0 | if (IsControlBackground()) |
754 | 0 | { |
755 | 0 | AllSettings aSettings = rRenderContext.GetSettings(); |
756 | 0 | AllSettings aOldSettings = aSettings; |
757 | 0 | StyleSettings aStyleSettings = aSettings.GetStyleSettings(); |
758 | 0 | if (nStyle & DrawButtonFlags::Highlight) |
759 | 0 | { |
760 | | // with the custom background, native highlight do nothing, so code below mimic |
761 | | // native highlight by changing luminance |
762 | 0 | Color controlBackgroundColorHighlighted = GetControlBackground(); |
763 | 0 | sal_uInt8 colorLuminance = controlBackgroundColorHighlighted.GetLuminance(); |
764 | 0 | if (colorLuminance < 205) |
765 | 0 | controlBackgroundColorHighlighted.IncreaseLuminance(50); |
766 | 0 | else |
767 | 0 | controlBackgroundColorHighlighted.DecreaseLuminance(50); |
768 | 0 | aStyleSettings.Set3DColors(controlBackgroundColorHighlighted); |
769 | 0 | } |
770 | 0 | else |
771 | 0 | aStyleSettings.Set3DColors(GetControlBackground()); |
772 | 0 | aSettings.SetStyleSettings(aStyleSettings); |
773 | | |
774 | | // Call OutputDevice::SetSettings() explicitly, as rRenderContext may |
775 | | // be a vcl::Window in fact, and vcl::Window::SetSettings() will call |
776 | | // Invalidate(), which is a problem, since we're in Paint(). |
777 | 0 | rRenderContext.OutputDevice::SetSettings(aSettings); |
778 | 0 | rRect = aDecoView.DrawButton(rRect, nStyle); |
779 | 0 | rRenderContext.OutputDevice::SetSettings(aOldSettings); |
780 | 0 | } |
781 | 0 | else |
782 | 0 | rRect = aDecoView.DrawButton(rRect, nStyle); |
783 | 0 | } |
784 | | |
785 | | bool PushButton::ImplHitTestPushButton( vcl::Window const * pDev, |
786 | | const Point& rPos ) |
787 | 0 | { |
788 | 0 | tools::Rectangle aTestRect( Point(), pDev->GetOutputSizePixel() ); |
789 | |
|
790 | 0 | return aTestRect.Contains( rPos ); |
791 | 0 | } |
792 | | |
793 | | DrawTextFlags PushButton::ImplGetTextStyle( SystemTextColorFlags nSystemTextColorFlags ) const |
794 | 0 | { |
795 | 0 | const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); |
796 | |
|
797 | 0 | DrawTextFlags nTextStyle = DrawTextFlags::Mnemonic | DrawTextFlags::MultiLine | DrawTextFlags::EndEllipsis; |
798 | |
|
799 | 0 | if ( ( rStyleSettings.GetOptions() & StyleSettingsOptions::Mono ) || |
800 | 0 | ( nSystemTextColorFlags & SystemTextColorFlags::Mono ) ) |
801 | 0 | nTextStyle |= DrawTextFlags::Mono; |
802 | |
|
803 | 0 | if ( GetStyle() & WB_WORDBREAK ) |
804 | 0 | nTextStyle |= DrawTextFlags::WordBreak; |
805 | 0 | if ( GetStyle() & WB_NOLABEL ) |
806 | 0 | nTextStyle &= ~DrawTextFlags::Mnemonic; |
807 | |
|
808 | 0 | if ( GetStyle() & WB_LEFT ) |
809 | 0 | nTextStyle |= DrawTextFlags::Left; |
810 | 0 | else if ( GetStyle() & WB_RIGHT ) |
811 | 0 | nTextStyle |= DrawTextFlags::Right; |
812 | 0 | else |
813 | 0 | nTextStyle |= DrawTextFlags::Center; |
814 | |
|
815 | 0 | if ( GetStyle() & WB_TOP ) |
816 | 0 | nTextStyle |= DrawTextFlags::Top; |
817 | 0 | else if ( GetStyle() & WB_BOTTOM ) |
818 | 0 | nTextStyle |= DrawTextFlags::Bottom; |
819 | 0 | else |
820 | 0 | nTextStyle |= DrawTextFlags::VCenter; |
821 | |
|
822 | 0 | if ( !IsEnabled() ) |
823 | 0 | nTextStyle |= DrawTextFlags::Disable; |
824 | |
|
825 | 0 | return nTextStyle; |
826 | 0 | } |
827 | | |
828 | | void PushButton::ImplDrawPushButtonContent(OutputDevice *pDev, SystemTextColorFlags nSystemTextColorFlags, |
829 | | const tools::Rectangle &rRect, bool bMenuBtnSep, |
830 | | DrawButtonFlags nButtonFlags) |
831 | 0 | { |
832 | 0 | const StyleSettings &rStyleSettings = GetSettings().GetStyleSettings(); |
833 | 0 | tools::Rectangle aInRect = rRect; |
834 | 0 | Color aColor; |
835 | 0 | DrawTextFlags nTextStyle = ImplGetTextStyle(nSystemTextColorFlags); |
836 | 0 | DrawSymbolFlags nStyle; |
837 | |
|
838 | 0 | if (aInRect.Right() < aInRect.Left() || aInRect.Bottom() < aInRect.Top()) |
839 | 0 | return; |
840 | | |
841 | 0 | auto popIt = pDev->ScopedPush(vcl::PushFlags::CLIPREGION); |
842 | 0 | pDev->IntersectClipRegion(aInRect); |
843 | |
|
844 | 0 | if (nSystemTextColorFlags & SystemTextColorFlags::Mono) |
845 | 0 | aColor = COL_BLACK; |
846 | | |
847 | 0 | else if (IsControlForeground()) |
848 | 0 | aColor = GetControlForeground(); |
849 | | |
850 | | // Button types with possibly different text coloring are flat buttons and regular buttons. Regular buttons may be action |
851 | | // buttons and may have an additional default status. Moreover all buttons may have an additional pressed and rollover |
852 | | // (highlight) status. Pressed buttons are always in rollover status. |
853 | | |
854 | 0 | else if (GetStyle() & WB_FLATBUTTON) |
855 | 0 | if (nButtonFlags & DrawButtonFlags::Pressed) |
856 | 0 | aColor = rStyleSettings.GetFlatButtonPressedRolloverTextColor(); |
857 | 0 | else if (nButtonFlags & DrawButtonFlags::Highlight) |
858 | 0 | aColor = rStyleSettings.GetFlatButtonRolloverTextColor(); |
859 | 0 | else |
860 | 0 | aColor = rStyleSettings.GetFlatButtonTextColor(); |
861 | 0 | else |
862 | 0 | if (isAction() && (nButtonFlags & DrawButtonFlags::Default)) |
863 | 0 | if (nButtonFlags & DrawButtonFlags::Pressed) |
864 | 0 | aColor = rStyleSettings.GetDefaultActionButtonPressedRolloverTextColor(); |
865 | 0 | else if (nButtonFlags & DrawButtonFlags::Highlight) |
866 | 0 | aColor = rStyleSettings.GetDefaultActionButtonRolloverTextColor(); |
867 | 0 | else |
868 | 0 | aColor = rStyleSettings.GetDefaultActionButtonTextColor(); |
869 | 0 | else if (isAction()) |
870 | 0 | if (nButtonFlags & DrawButtonFlags::Pressed) |
871 | 0 | aColor = rStyleSettings.GetActionButtonPressedRolloverTextColor(); |
872 | 0 | else if (nButtonFlags & DrawButtonFlags::Highlight) |
873 | 0 | aColor = rStyleSettings.GetActionButtonRolloverTextColor(); |
874 | 0 | else |
875 | 0 | aColor = rStyleSettings.GetActionButtonTextColor(); |
876 | 0 | else if (nButtonFlags & DrawButtonFlags::Default) |
877 | 0 | if (nButtonFlags & DrawButtonFlags::Pressed) |
878 | 0 | aColor = rStyleSettings.GetDefaultButtonPressedRolloverTextColor(); |
879 | 0 | else if (nButtonFlags & DrawButtonFlags::Highlight) |
880 | 0 | aColor = rStyleSettings.GetDefaultButtonRolloverTextColor(); |
881 | 0 | else |
882 | 0 | aColor = rStyleSettings.GetDefaultButtonTextColor(); |
883 | 0 | else |
884 | 0 | if (nButtonFlags & DrawButtonFlags::Pressed) |
885 | 0 | aColor = rStyleSettings.GetButtonPressedRolloverTextColor(); |
886 | 0 | else if (nButtonFlags & DrawButtonFlags::Highlight) |
887 | 0 | aColor = rStyleSettings.GetButtonRolloverTextColor(); |
888 | 0 | else |
889 | 0 | aColor = rStyleSettings.GetButtonTextColor(); |
890 | |
|
891 | | #if defined(MACOSX) || defined(IOS) |
892 | | // tdf#152486 These are the buttons in infobars where the infobar has a custom |
893 | | // background color and on these platforms the buttons blend with |
894 | | // their background. |
895 | | vcl::Window* pParent = GetParent(); |
896 | | if (pParent->get_id() == "ExtraButton") |
897 | | { |
898 | | while (pParent && !pParent->IsControlBackground()) |
899 | | pParent = pParent->GetParent(); |
900 | | if (pParent) |
901 | | { |
902 | | if (aColor.IsBright() && !pParent->GetControlBackground().IsDark()) |
903 | | aColor = COL_BLACK; |
904 | | } |
905 | | } |
906 | | #endif |
907 | |
|
908 | 0 | pDev->SetTextColor(aColor); |
909 | |
|
910 | 0 | if ( IsEnabled() ) |
911 | 0 | nStyle = DrawSymbolFlags::NONE; |
912 | 0 | else |
913 | 0 | nStyle = DrawSymbolFlags::Disable; |
914 | |
|
915 | 0 | Size aSize = rRect.GetSize(); |
916 | 0 | Point aPos = rRect.TopLeft(); |
917 | |
|
918 | 0 | sal_Int32 nImageSep = 1 + (pDev->GetTextHeight()-10)/2; |
919 | 0 | if( nImageSep < 1 ) |
920 | 0 | nImageSep = 1; |
921 | 0 | if ( mnDDStyle == PushButtonDropdownStyle::MenuButton ) |
922 | 0 | { |
923 | 0 | tools::Long nSeparatorX = 0; |
924 | 0 | tools::Rectangle aSymbolRect = aInRect; |
925 | | |
926 | | // calculate symbol size |
927 | 0 | tools::Long nSymbolSize = pDev->GetTextHeight() / 2 + 1; |
928 | 0 | if (nSymbolSize > aSize.Width() / 2) |
929 | 0 | nSymbolSize = aSize.Width() / 2; |
930 | |
|
931 | 0 | nSeparatorX = aInRect.Right() - 2*nSymbolSize; |
932 | | |
933 | | // tdf#141761 Minimum width should be (1) Pixel, see comment |
934 | | // with same task number above for more info |
935 | 0 | const tools::Long nWidthAdjust(2*nSymbolSize); |
936 | 0 | aSize.setWidth(std::max(static_cast<tools::Long>(1), aSize.getWidth() - nWidthAdjust)); |
937 | | |
938 | | // center symbol rectangle in the separated area |
939 | 0 | aSymbolRect.AdjustRight( -(nSymbolSize/2) ); |
940 | 0 | aSymbolRect.SetLeft( aSymbolRect.Right() - nSymbolSize ); |
941 | |
|
942 | 0 | ImplDrawAlignedImage( pDev, aPos, aSize, nImageSep, |
943 | 0 | nTextStyle, nullptr, true ); |
944 | |
|
945 | 0 | tools::Long nDistance = (aSymbolRect.GetHeight() > 10) ? 2 : 1; |
946 | 0 | DecorationView aDecoView( pDev ); |
947 | 0 | if( bMenuBtnSep && nSeparatorX > 0 ) |
948 | 0 | { |
949 | 0 | Point aStartPt( nSeparatorX, aSymbolRect.Top()+nDistance ); |
950 | 0 | Point aEndPt( nSeparatorX, aSymbolRect.Bottom()-nDistance ); |
951 | 0 | aDecoView.DrawSeparator( aStartPt, aEndPt ); |
952 | 0 | } |
953 | |
|
954 | 0 | aDecoView.DrawSymbol( aSymbolRect, SymbolType::SPIN_DOWN, aColor, nStyle ); |
955 | |
|
956 | 0 | } |
957 | 0 | else |
958 | 0 | { |
959 | 0 | tools::Rectangle aSymbolRect; |
960 | 0 | ImplDrawAlignedImage( pDev, aPos, aSize, nImageSep, |
961 | 0 | nTextStyle, IsSymbol() ? &aSymbolRect : nullptr, true ); |
962 | |
|
963 | 0 | if ( IsSymbol() ) |
964 | 0 | { |
965 | 0 | DecorationView aDecoView( pDev ); |
966 | 0 | aDecoView.DrawSymbol( aSymbolRect, meSymbol, aColor, nStyle ); |
967 | 0 | } |
968 | 0 | } |
969 | 0 | } |
970 | | |
971 | | void PushButton::ImplDrawPushButton(vcl::RenderContext& rRenderContext) |
972 | 0 | { |
973 | 0 | HideFocus(); |
974 | |
|
975 | 0 | DrawButtonFlags nButtonStyle = GetButtonState(); |
976 | 0 | Size aOutSz(GetOutputSizePixel()); |
977 | 0 | tools::Rectangle aRect(Point(), aOutSz); |
978 | 0 | tools::Rectangle aInRect = aRect; |
979 | 0 | bool bNativeOK = false; |
980 | | |
981 | | // adjust style if button should be rendered 'pressed' |
982 | 0 | if (mbPressed) |
983 | 0 | nButtonStyle |= DrawButtonFlags::Pressed; |
984 | |
|
985 | 0 | if (GetStyle() & WB_FLATBUTTON) |
986 | 0 | nButtonStyle |= DrawButtonFlags::Flat; |
987 | | |
988 | | // TODO: move this to Window class or make it a member !!! |
989 | 0 | ControlType aCtrlType = ControlType::Generic; |
990 | 0 | switch(GetParent()->GetType()) |
991 | 0 | { |
992 | 0 | case WindowType::LISTBOX: |
993 | 0 | case WindowType::MULTILISTBOX: |
994 | 0 | case WindowType::TREELISTBOX: |
995 | 0 | aCtrlType = ControlType::Listbox; |
996 | 0 | break; |
997 | | |
998 | 0 | case WindowType::COMBOBOX: |
999 | 0 | case WindowType::PATTERNBOX: |
1000 | 0 | case WindowType::NUMERICBOX: |
1001 | 0 | case WindowType::METRICBOX: |
1002 | 0 | case WindowType::CURRENCYBOX: |
1003 | 0 | case WindowType::DATEBOX: |
1004 | 0 | case WindowType::TIMEBOX: |
1005 | 0 | case WindowType::LONGCURRENCYBOX: |
1006 | 0 | aCtrlType = ControlType::Combobox; |
1007 | 0 | break; |
1008 | 0 | default: |
1009 | 0 | break; |
1010 | 0 | } |
1011 | | |
1012 | 0 | bool bDropDown = (IsSymbol() && (GetSymbol() == SymbolType::SPIN_DOWN) && GetText().isEmpty()); |
1013 | |
|
1014 | 0 | if( bDropDown && (aCtrlType == ControlType::Combobox || aCtrlType == ControlType::Listbox)) |
1015 | 0 | { |
1016 | 0 | if (GetParent()->IsNativeControlSupported(aCtrlType, ControlPart::Entire)) |
1017 | 0 | { |
1018 | | // skip painting if the button was already drawn by the theme |
1019 | 0 | if (aCtrlType == ControlType::Combobox) |
1020 | 0 | { |
1021 | 0 | Edit* pEdit = static_cast<Edit*>(GetParent()); |
1022 | 0 | if (pEdit->ImplUseNativeBorder(rRenderContext, pEdit->GetStyle())) |
1023 | 0 | bNativeOK = true; |
1024 | 0 | } |
1025 | 0 | else if (GetParent()->IsNativeControlSupported(aCtrlType, ControlPart::HasBackgroundTexture)) |
1026 | 0 | { |
1027 | 0 | bNativeOK = true; |
1028 | 0 | } |
1029 | |
|
1030 | 0 | if (!bNativeOK && GetParent()->IsNativeControlSupported(aCtrlType, ControlPart::ButtonDown)) |
1031 | 0 | { |
1032 | | // let the theme draw it, note we then need support |
1033 | | // for ControlType::Listbox/ControlPart::ButtonDown and ControlType::Combobox/ControlPart::ButtonDown |
1034 | |
|
1035 | 0 | ImplControlValue aControlValue; |
1036 | 0 | ControlState nState = ControlState::NONE; |
1037 | |
|
1038 | 0 | if (mbPressed) |
1039 | 0 | nState |= ControlState::PRESSED; |
1040 | 0 | if (GetButtonState() & DrawButtonFlags::Pressed) |
1041 | 0 | nState |= ControlState::PRESSED; |
1042 | 0 | if (HasFocus()) |
1043 | 0 | nState |= ControlState::FOCUSED; |
1044 | 0 | if (GetButtonState() & DrawButtonFlags::Default) |
1045 | 0 | nState |= ControlState::DEFAULT; |
1046 | 0 | if (Window::IsEnabled()) |
1047 | 0 | nState |= ControlState::ENABLED; |
1048 | |
|
1049 | 0 | if (IsMouseOver() && aInRect.Contains(GetPointerPosPixel())) |
1050 | 0 | nState |= ControlState::ROLLOVER; |
1051 | |
|
1052 | 0 | bNativeOK = rRenderContext.DrawNativeControl(aCtrlType, ControlPart::ButtonDown, aInRect, nState, |
1053 | 0 | aControlValue, OUString()); |
1054 | 0 | } |
1055 | 0 | } |
1056 | 0 | } |
1057 | |
|
1058 | 0 | if (bNativeOK) |
1059 | 0 | return; |
1060 | | |
1061 | 0 | bool bRollOver = (IsMouseOver() && aInRect.Contains(GetPointerPosPixel())); |
1062 | 0 | if (bRollOver) |
1063 | 0 | nButtonStyle |= DrawButtonFlags::Highlight; |
1064 | | // tdf#123175 if there is a custom control bg set, draw the button without outsourcing to the NWF |
1065 | 0 | bNativeOK = !IsControlBackground() && rRenderContext.IsNativeControlSupported(ControlType::Pushbutton, ControlPart::Entire); |
1066 | 0 | if (bNativeOK) |
1067 | 0 | { |
1068 | 0 | PushButtonValue aControlValue; |
1069 | 0 | aControlValue.mbIsAction = isAction(); |
1070 | |
|
1071 | 0 | tools::Rectangle aCtrlRegion(aInRect); |
1072 | 0 | ControlState nState = ControlState::NONE; |
1073 | |
|
1074 | 0 | if (mbPressed || IsChecked()) |
1075 | 0 | { |
1076 | 0 | nState |= ControlState::PRESSED; |
1077 | 0 | nButtonStyle |= DrawButtonFlags::Pressed; |
1078 | 0 | } |
1079 | 0 | if (GetButtonState() & DrawButtonFlags::Pressed) |
1080 | 0 | nState |= ControlState::PRESSED; |
1081 | 0 | if (HasFocus()) |
1082 | 0 | nState |= ControlState::FOCUSED; |
1083 | 0 | if (GetButtonState() & DrawButtonFlags::Default) |
1084 | 0 | nState |= ControlState::DEFAULT; |
1085 | 0 | if (Window::IsEnabled()) |
1086 | 0 | nState |= ControlState::ENABLED; |
1087 | |
|
1088 | 0 | if (bRollOver) |
1089 | 0 | { |
1090 | 0 | nButtonStyle |= DrawButtonFlags::Highlight; |
1091 | 0 | nState |= ControlState::ROLLOVER; |
1092 | 0 | } |
1093 | |
|
1094 | 0 | if (GetStyle() & WB_FLATBUTTON) |
1095 | 0 | aControlValue.m_bFlatButton = true; |
1096 | | |
1097 | | // draw frame into invisible window to have aInRect modified correctly |
1098 | | // but do not shift the inner rect for pressed buttons (ie remove DrawButtonFlags::Pressed) |
1099 | | // this assumes the theme has enough visual cues to signalize the button was pressed |
1100 | | //Window aWin( this ); |
1101 | | //ImplDrawPushButtonFrame( &aWin, aInRect, nButtonStyle & ~DrawButtonFlags::Pressed ); |
1102 | | |
1103 | | // looks better this way as symbols were displaced slightly using the above approach |
1104 | 0 | aInRect.AdjustTop(4 ); |
1105 | 0 | aInRect.AdjustBottom( -4 ); |
1106 | 0 | aInRect.AdjustLeft(4 ); |
1107 | 0 | aInRect.AdjustRight( -4 ); |
1108 | | |
1109 | | // prepare single line hint (needed on mac to decide between normal push button and |
1110 | | // rectangular bevel button look) |
1111 | 0 | Size aFontSize(Application::GetSettings().GetStyleSettings().GetPushButtonFont().GetFontSize()); |
1112 | 0 | aFontSize = rRenderContext.LogicToPixel(aFontSize, MapMode(MapUnit::MapPoint)); |
1113 | 0 | Size aInRectSize(rRenderContext.LogicToPixel(Size(aInRect.GetWidth(), aInRect.GetHeight()))); |
1114 | 0 | aControlValue.mbSingleLine = (aInRectSize.Height() < 2 * aFontSize.Height()); |
1115 | |
|
1116 | 0 | if (!aControlValue.m_bFlatButton || (nState & ControlState::ROLLOVER) || (nState & ControlState::PRESSED) |
1117 | 0 | || (HasFocus() && mpWindowImpl->mbUseNativeFocus |
1118 | 0 | && !IsNativeControlSupported(ControlType::Pushbutton, ControlPart::Focus))) |
1119 | 0 | { |
1120 | 0 | bNativeOK = rRenderContext.DrawNativeControl(ControlType::Pushbutton, ControlPart::Entire, aCtrlRegion, nState, |
1121 | 0 | aControlValue, OUString() /*PushButton::GetText()*/); |
1122 | 0 | } |
1123 | 0 | else |
1124 | 0 | { |
1125 | 0 | bNativeOK = true; |
1126 | 0 | } |
1127 | | |
1128 | | // draw content using the same aInRect as non-native VCL would do |
1129 | 0 | ImplDrawPushButtonContent(&rRenderContext, SystemTextColorFlags::NONE, |
1130 | 0 | aInRect, /*bDrawMenuSep*/false, nButtonStyle); |
1131 | |
|
1132 | 0 | if (HasFocus()) |
1133 | 0 | ShowFocus(ImplGetFocusRect()); |
1134 | 0 | } |
1135 | |
|
1136 | 0 | if (bNativeOK) |
1137 | 0 | return; |
1138 | | |
1139 | | // draw PushButtonFrame, aInRect has content size afterwards |
1140 | 0 | if (GetStyle() & WB_FLATBUTTON) |
1141 | 0 | { |
1142 | 0 | tools::Rectangle aTempRect(aInRect); |
1143 | 0 | ImplDrawPushButtonFrame(rRenderContext, aTempRect, nButtonStyle); |
1144 | 0 | aInRect.AdjustLeft(2 ); |
1145 | 0 | aInRect.AdjustTop(2 ); |
1146 | 0 | aInRect.AdjustRight( -2 ); |
1147 | 0 | aInRect.AdjustBottom( -2 ); |
1148 | 0 | } |
1149 | 0 | else |
1150 | 0 | { |
1151 | 0 | ImplDrawPushButtonFrame(rRenderContext, aInRect, nButtonStyle); |
1152 | 0 | } |
1153 | | |
1154 | | // draw content |
1155 | 0 | ImplDrawPushButtonContent(&rRenderContext, SystemTextColorFlags::NONE, aInRect, /*bDrawMenuSep*/false, nButtonStyle); |
1156 | |
|
1157 | 0 | if (HasFocus()) |
1158 | 0 | { |
1159 | 0 | ShowFocus(ImplGetFocusRect()); |
1160 | 0 | } |
1161 | 0 | } |
1162 | | |
1163 | | void PushButton::ImplSetDefButton( bool bSet ) |
1164 | 0 | { |
1165 | 0 | Size aSize( GetSizePixel() ); |
1166 | 0 | Point aPos( GetPosPixel() ); |
1167 | 0 | int dLeft(0), dRight(0), dTop(0), dBottom(0); |
1168 | 0 | bool bSetPos = false; |
1169 | |
|
1170 | 0 | if ( IsNativeControlSupported(ControlType::Pushbutton, ControlPart::Entire) ) |
1171 | 0 | { |
1172 | 0 | tools::Rectangle aBound, aCont; |
1173 | 0 | tools::Rectangle aCtrlRegion( 0, 0, 80, 20 ); // use a constant size to avoid accumulating |
1174 | | // will not work if the theme has dynamic adornment sizes |
1175 | 0 | ImplControlValue aControlValue; |
1176 | | |
1177 | | // get native size of a 'default' button |
1178 | | // and adjust the VCL button if more space for adornment is required |
1179 | 0 | if( GetNativeControlRegion( ControlType::Pushbutton, ControlPart::Entire, aCtrlRegion, |
1180 | 0 | ControlState::DEFAULT|ControlState::ENABLED, |
1181 | 0 | aControlValue, |
1182 | 0 | aBound, aCont ) ) |
1183 | 0 | { |
1184 | 0 | dLeft = aCont.Left() - aBound.Left(); |
1185 | 0 | dTop = aCont.Top() - aBound.Top(); |
1186 | 0 | dRight = aBound.Right() - aCont.Right(); |
1187 | 0 | dBottom = aBound.Bottom() - aCont.Bottom(); |
1188 | 0 | bSetPos = dLeft || dTop || dRight || dBottom; |
1189 | 0 | } |
1190 | 0 | } |
1191 | |
|
1192 | 0 | if ( bSet ) |
1193 | 0 | { |
1194 | 0 | if( !(GetButtonState() & DrawButtonFlags::Default) && bSetPos ) |
1195 | 0 | { |
1196 | | // adjust pos/size when toggling from non-default to default |
1197 | 0 | aPos.Move(-dLeft, -dTop); |
1198 | 0 | aSize.AdjustWidth(dLeft + dRight ); |
1199 | 0 | aSize.AdjustHeight(dTop + dBottom ); |
1200 | 0 | } |
1201 | 0 | GetButtonState() |= DrawButtonFlags::Default; |
1202 | 0 | } |
1203 | 0 | else |
1204 | 0 | { |
1205 | 0 | if( (GetButtonState() & DrawButtonFlags::Default) && bSetPos ) |
1206 | 0 | { |
1207 | | // adjust pos/size when toggling from default to non-default |
1208 | 0 | aPos.Move(dLeft, dTop); |
1209 | 0 | aSize.AdjustWidth( -(dLeft + dRight) ); |
1210 | 0 | aSize.AdjustHeight( -(dTop + dBottom) ); |
1211 | 0 | } |
1212 | 0 | GetButtonState() &= ~DrawButtonFlags::Default; |
1213 | 0 | } |
1214 | 0 | if( bSetPos ) |
1215 | 0 | setPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() ); |
1216 | |
|
1217 | 0 | Invalidate(); |
1218 | 0 | } |
1219 | | |
1220 | | bool PushButton::ImplIsDefButton() const |
1221 | 0 | { |
1222 | 0 | return bool(GetButtonState() & DrawButtonFlags::Default); |
1223 | 0 | } |
1224 | | |
1225 | | PushButton::PushButton( WindowType nType ) : |
1226 | 0 | Button( nType ) |
1227 | 0 | { |
1228 | 0 | ImplInitPushButtonData(); |
1229 | 0 | } Unexecuted instantiation: PushButton::PushButton(WindowType) Unexecuted instantiation: PushButton::PushButton(WindowType) |
1230 | | |
1231 | | PushButton::PushButton( vcl::Window* pParent, WinBits nStyle ) : |
1232 | 0 | Button( WindowType::PUSHBUTTON ) |
1233 | 0 | { |
1234 | 0 | ImplInitPushButtonData(); |
1235 | 0 | ImplInit( pParent, nStyle ); |
1236 | 0 | } Unexecuted instantiation: PushButton::PushButton(vcl::Window*, long) Unexecuted instantiation: PushButton::PushButton(vcl::Window*, long) |
1237 | | |
1238 | | rtl::Reference<comphelper::OAccessible> PushButton::CreateAccessible() |
1239 | 0 | { |
1240 | 0 | return new VCLXAccessibleButton(this); |
1241 | 0 | } |
1242 | | |
1243 | | void PushButton::MouseButtonDown( const MouseEvent& rMEvt ) |
1244 | 0 | { |
1245 | 0 | if ( !(rMEvt.IsLeft() && |
1246 | 0 | ImplHitTestPushButton( this, rMEvt.GetPosPixel() )) ) |
1247 | 0 | return; |
1248 | | |
1249 | 0 | StartTrackingFlags nTrackFlags = StartTrackingFlags::NONE; |
1250 | |
|
1251 | 0 | if ( ( GetStyle() & WB_REPEAT ) && |
1252 | 0 | ! ( GetStyle() & WB_TOGGLE ) ) |
1253 | 0 | nTrackFlags |= StartTrackingFlags::ButtonRepeat; |
1254 | |
|
1255 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
1256 | 0 | Invalidate(); |
1257 | 0 | StartTracking( nTrackFlags ); |
1258 | |
|
1259 | 0 | if ( nTrackFlags & StartTrackingFlags::ButtonRepeat ) |
1260 | 0 | Click(); |
1261 | 0 | } |
1262 | | |
1263 | | void PushButton::Tracking( const TrackingEvent& rTEvt ) |
1264 | 0 | { |
1265 | 0 | if ( rTEvt.IsTrackingEnded() ) |
1266 | 0 | { |
1267 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
1268 | 0 | { |
1269 | 0 | if ( !(GetStyle() & WB_NOPOINTERFOCUS) && !rTEvt.IsTrackingCanceled() ) |
1270 | 0 | GrabFocus(); |
1271 | |
|
1272 | 0 | if ( GetStyle() & WB_TOGGLE ) |
1273 | 0 | { |
1274 | | // Don't toggle, when aborted |
1275 | 0 | if ( !rTEvt.IsTrackingCanceled() ) |
1276 | 0 | { |
1277 | 0 | if ( IsChecked() ) |
1278 | 0 | { |
1279 | 0 | Check( false ); |
1280 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
1281 | 0 | } |
1282 | 0 | else |
1283 | 0 | Check(); |
1284 | 0 | } |
1285 | 0 | } |
1286 | 0 | else |
1287 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
1288 | |
|
1289 | 0 | Invalidate(); |
1290 | | |
1291 | | // do not call Click handler if aborted |
1292 | 0 | if ( !rTEvt.IsTrackingCanceled() ) |
1293 | 0 | { |
1294 | 0 | if ( ! ( GetStyle() & WB_REPEAT ) || ( GetStyle() & WB_TOGGLE ) ) |
1295 | 0 | Click(); |
1296 | 0 | } |
1297 | 0 | } |
1298 | 0 | } |
1299 | 0 | else |
1300 | 0 | { |
1301 | 0 | if ( ImplHitTestPushButton( this, rTEvt.GetMouseEvent().GetPosPixel() ) ) |
1302 | 0 | { |
1303 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
1304 | 0 | { |
1305 | 0 | if ( rTEvt.IsTrackingRepeat() && (GetStyle() & WB_REPEAT) && |
1306 | 0 | ! ( GetStyle() & WB_TOGGLE ) ) |
1307 | 0 | Click(); |
1308 | 0 | } |
1309 | 0 | else |
1310 | 0 | { |
1311 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
1312 | 0 | Invalidate(); |
1313 | 0 | } |
1314 | 0 | } |
1315 | 0 | else |
1316 | 0 | { |
1317 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
1318 | 0 | { |
1319 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
1320 | 0 | Invalidate(); |
1321 | 0 | } |
1322 | 0 | } |
1323 | 0 | } |
1324 | 0 | } |
1325 | | |
1326 | | void PushButton::KeyInput( const KeyEvent& rKEvt ) |
1327 | 0 | { |
1328 | 0 | vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); |
1329 | |
|
1330 | 0 | if ( !aKeyCode.GetModifier() && |
1331 | 0 | ((aKeyCode.GetCode() == KEY_RETURN) || (aKeyCode.GetCode() == KEY_SPACE)) ) |
1332 | 0 | { |
1333 | 0 | if ( !(GetButtonState() & DrawButtonFlags::Pressed) ) |
1334 | 0 | { |
1335 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
1336 | 0 | Invalidate(); |
1337 | 0 | } |
1338 | |
|
1339 | 0 | if ( ( GetStyle() & WB_REPEAT ) && |
1340 | 0 | ! ( GetStyle() & WB_TOGGLE ) ) |
1341 | 0 | Click(); |
1342 | 0 | } |
1343 | 0 | else if ( (GetButtonState() & DrawButtonFlags::Pressed) && (aKeyCode.GetCode() == KEY_ESCAPE) ) |
1344 | 0 | { |
1345 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
1346 | 0 | Invalidate(); |
1347 | 0 | } |
1348 | 0 | else |
1349 | 0 | Button::KeyInput( rKEvt ); |
1350 | 0 | } |
1351 | | |
1352 | | void PushButton::KeyUp( const KeyEvent& rKEvt ) |
1353 | 0 | { |
1354 | 0 | vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); |
1355 | |
|
1356 | 0 | if ( (GetButtonState() & DrawButtonFlags::Pressed) && |
1357 | 0 | ((aKeyCode.GetCode() == KEY_RETURN) || (aKeyCode.GetCode() == KEY_SPACE)) ) |
1358 | 0 | { |
1359 | 0 | if ( GetStyle() & WB_TOGGLE ) |
1360 | 0 | { |
1361 | 0 | if ( IsChecked() ) |
1362 | 0 | { |
1363 | 0 | Check( false ); |
1364 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
1365 | 0 | } |
1366 | 0 | else |
1367 | 0 | Check(); |
1368 | |
|
1369 | 0 | Toggle(); |
1370 | 0 | } |
1371 | 0 | else |
1372 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
1373 | |
|
1374 | 0 | Invalidate(); |
1375 | |
|
1376 | 0 | if ( !( GetStyle() & WB_REPEAT ) || ( GetStyle() & WB_TOGGLE ) ) |
1377 | 0 | Click(); |
1378 | 0 | } |
1379 | 0 | else |
1380 | 0 | Button::KeyUp( rKEvt ); |
1381 | 0 | } |
1382 | | |
1383 | | void PushButton::FillLayoutData() const |
1384 | 0 | { |
1385 | 0 | mxLayoutData.emplace(); |
1386 | 0 | const_cast<PushButton*>(this)->Invalidate(); |
1387 | 0 | } |
1388 | | |
1389 | | void PushButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) |
1390 | 0 | { |
1391 | 0 | const Image& rCustomButtonImage = GetCustomButtonImage(); |
1392 | 0 | if (!!rCustomButtonImage) |
1393 | 0 | { |
1394 | 0 | rRenderContext.DrawImage(Point(0, 0), rCustomButtonImage); |
1395 | 0 | return; |
1396 | 0 | } |
1397 | 0 | ImplDrawPushButton(rRenderContext); |
1398 | 0 | } |
1399 | | |
1400 | | void PushButton::Draw( OutputDevice* pDev, const Point& rPos, |
1401 | | SystemTextColorFlags nFlags ) |
1402 | 0 | { |
1403 | 0 | Point aPos = pDev->LogicToPixel( rPos ); |
1404 | 0 | Size aSize = GetSizePixel(); |
1405 | 0 | tools::Rectangle aRect( aPos, aSize ); |
1406 | 0 | vcl::Font aFont = GetDrawPixelFont( pDev ); |
1407 | |
|
1408 | 0 | auto popIt = pDev->ScopedPush(); |
1409 | 0 | pDev->SetMapMode(); |
1410 | 0 | pDev->SetFont( aFont ); |
1411 | |
|
1412 | 0 | std::optional<StyleSettings> oOrigDevStyleSettings; |
1413 | |
|
1414 | 0 | if ( nFlags & SystemTextColorFlags::Mono ) |
1415 | 0 | { |
1416 | 0 | pDev->SetTextColor( COL_BLACK ); |
1417 | 0 | } |
1418 | 0 | else |
1419 | 0 | { |
1420 | 0 | pDev->SetTextColor( GetTextColor() ); |
1421 | | // DecoView uses the FaceColor... |
1422 | 0 | AllSettings aSettings = pDev->GetSettings(); |
1423 | 0 | StyleSettings aStyleSettings = aSettings.GetStyleSettings(); |
1424 | 0 | oOrigDevStyleSettings = aStyleSettings; |
1425 | 0 | if ( IsControlBackground() ) |
1426 | 0 | aStyleSettings.SetFaceColor( GetControlBackground() ); |
1427 | 0 | else |
1428 | 0 | aStyleSettings.SetFaceColor( GetSettings().GetStyleSettings().GetFaceColor() ); |
1429 | 0 | aSettings.SetStyleSettings( aStyleSettings ); |
1430 | 0 | pDev->OutputDevice::SetSettings( aSettings ); |
1431 | 0 | } |
1432 | 0 | pDev->SetTextFillColor(); |
1433 | |
|
1434 | 0 | DecorationView aDecoView( pDev ); |
1435 | 0 | DrawButtonFlags nButtonStyle = DrawButtonFlags::NONE; |
1436 | 0 | if ( nFlags & SystemTextColorFlags::Mono ) |
1437 | 0 | nButtonStyle |= DrawButtonFlags::Mono; |
1438 | 0 | if ( IsChecked() ) |
1439 | 0 | nButtonStyle |= DrawButtonFlags::Checked; |
1440 | 0 | aRect = aDecoView.DrawButton( aRect, nButtonStyle ); |
1441 | |
|
1442 | 0 | ImplDrawPushButtonContent( pDev, nFlags, aRect, true, nButtonStyle ); |
1443 | | |
1444 | | // restore original settings (which are not affected by Push/Pop) after |
1445 | | // finished drawing |
1446 | 0 | if (oOrigDevStyleSettings) |
1447 | 0 | { |
1448 | 0 | AllSettings aSettings = pDev->GetSettings(); |
1449 | 0 | aSettings.SetStyleSettings(*oOrigDevStyleSettings); |
1450 | 0 | pDev->OutputDevice::SetSettings( aSettings ); |
1451 | 0 | } |
1452 | 0 | } |
1453 | | |
1454 | | void PushButton::Resize() |
1455 | 0 | { |
1456 | 0 | Control::Resize(); |
1457 | 0 | Invalidate(); |
1458 | 0 | } |
1459 | | |
1460 | | void PushButton::GetFocus() |
1461 | 0 | { |
1462 | 0 | ShowFocus( ImplGetFocusRect() ); |
1463 | 0 | SetInputContext( InputContext( GetFont() ) ); |
1464 | 0 | Button::GetFocus(); |
1465 | 0 | } |
1466 | | |
1467 | | void PushButton::LoseFocus() |
1468 | 0 | { |
1469 | 0 | EndSelection(); |
1470 | 0 | HideFocus(); |
1471 | 0 | Button::LoseFocus(); |
1472 | 0 | } |
1473 | | |
1474 | | void PushButton::StateChanged( StateChangedType nType ) |
1475 | 0 | { |
1476 | 0 | Button::StateChanged( nType ); |
1477 | |
|
1478 | 0 | if ( (nType == StateChangedType::Enable) || |
1479 | 0 | (nType == StateChangedType::Text) || |
1480 | 0 | (nType == StateChangedType::Data) || |
1481 | 0 | (nType == StateChangedType::State) || |
1482 | 0 | (nType == StateChangedType::UpdateMode) ) |
1483 | 0 | { |
1484 | 0 | if ( IsReallyVisible() && IsUpdateMode() ) |
1485 | 0 | Invalidate(); |
1486 | 0 | } |
1487 | 0 | else if ( nType == StateChangedType::Style ) |
1488 | 0 | { |
1489 | 0 | SetStyle( ImplInitStyle( GetWindow( GetWindowType::Prev ), GetStyle() ) ); |
1490 | |
|
1491 | 0 | bool bIsDefButton = ( GetStyle() & WB_DEFBUTTON ) != 0; |
1492 | 0 | bool bWasDefButton = ( GetPrevStyle() & WB_DEFBUTTON ) != 0; |
1493 | 0 | if ( bIsDefButton != bWasDefButton ) |
1494 | 0 | ImplSetDefButton( bIsDefButton ); |
1495 | |
|
1496 | 0 | if ( IsReallyVisible() && IsUpdateMode() ) |
1497 | 0 | { |
1498 | 0 | if ( (GetPrevStyle() & PUSHBUTTON_VIEW_STYLE) != |
1499 | 0 | (GetStyle() & PUSHBUTTON_VIEW_STYLE) ) |
1500 | 0 | Invalidate(); |
1501 | 0 | } |
1502 | 0 | } |
1503 | 0 | else if ( (nType == StateChangedType::Zoom) || |
1504 | 0 | (nType == StateChangedType::ControlFont) ) |
1505 | 0 | { |
1506 | 0 | ImplInitSettings( false ); |
1507 | 0 | Invalidate(); |
1508 | 0 | } |
1509 | 0 | else if ( nType == StateChangedType::ControlForeground ) |
1510 | 0 | { |
1511 | 0 | ImplInitSettings( false ); |
1512 | 0 | Invalidate(); |
1513 | 0 | } |
1514 | 0 | else if ( nType == StateChangedType::ControlBackground ) |
1515 | 0 | { |
1516 | 0 | ImplInitSettings( true ); |
1517 | 0 | Invalidate(); |
1518 | 0 | } |
1519 | 0 | } |
1520 | | |
1521 | | void PushButton::DataChanged( const DataChangedEvent& rDCEvt ) |
1522 | 0 | { |
1523 | 0 | Button::DataChanged( rDCEvt ); |
1524 | |
|
1525 | 0 | if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) || |
1526 | 0 | (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) || |
1527 | 0 | ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && |
1528 | 0 | (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) ) |
1529 | 0 | { |
1530 | 0 | ImplInitSettings( true ); |
1531 | 0 | Invalidate(); |
1532 | 0 | } |
1533 | 0 | } |
1534 | | |
1535 | | bool PushButton::PreNotify( NotifyEvent& rNEvt ) |
1536 | 0 | { |
1537 | 0 | if( rNEvt.GetType() == NotifyEventType::MOUSEMOVE ) |
1538 | 0 | { |
1539 | 0 | const MouseEvent* pMouseEvt = rNEvt.GetMouseEvent(); |
1540 | 0 | if( pMouseEvt && (pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow()) ) |
1541 | 0 | { |
1542 | | // trigger redraw as mouse over state has changed |
1543 | | |
1544 | | // TODO: move this to Window class or make it a member !!! |
1545 | 0 | ControlType aCtrlType = ControlType::Generic; |
1546 | 0 | switch( GetParent()->GetType() ) |
1547 | 0 | { |
1548 | 0 | case WindowType::LISTBOX: |
1549 | 0 | case WindowType::MULTILISTBOX: |
1550 | 0 | case WindowType::TREELISTBOX: |
1551 | 0 | aCtrlType = ControlType::Listbox; |
1552 | 0 | break; |
1553 | | |
1554 | 0 | case WindowType::COMBOBOX: |
1555 | 0 | case WindowType::PATTERNBOX: |
1556 | 0 | case WindowType::NUMERICBOX: |
1557 | 0 | case WindowType::METRICBOX: |
1558 | 0 | case WindowType::CURRENCYBOX: |
1559 | 0 | case WindowType::DATEBOX: |
1560 | 0 | case WindowType::TIMEBOX: |
1561 | 0 | case WindowType::LONGCURRENCYBOX: |
1562 | 0 | aCtrlType = ControlType::Combobox; |
1563 | 0 | break; |
1564 | 0 | default: |
1565 | 0 | break; |
1566 | 0 | } |
1567 | | |
1568 | 0 | bool bDropDown = ( IsSymbol() && (GetSymbol()==SymbolType::SPIN_DOWN) && GetText().isEmpty() ); |
1569 | |
|
1570 | 0 | if( bDropDown && GetParent()->IsNativeControlSupported( aCtrlType, ControlPart::Entire) && |
1571 | 0 | !GetParent()->IsNativeControlSupported( aCtrlType, ControlPart::ButtonDown) ) |
1572 | 0 | { |
1573 | 0 | vcl::Window *pBorder = GetParent()->GetWindow( GetWindowType::Border ); |
1574 | 0 | if(aCtrlType == ControlType::Combobox) |
1575 | 0 | { |
1576 | | // only paint the button part to avoid flickering of the combobox text |
1577 | 0 | tools::Rectangle aClipRect( Point(), GetOutputSizePixel() ); |
1578 | 0 | aClipRect.SetPos(pBorder->ScreenToOutputPixel(OutputToScreenPixel(aClipRect.TopLeft()))); |
1579 | 0 | pBorder->Invalidate( aClipRect ); |
1580 | 0 | } |
1581 | 0 | else |
1582 | 0 | { |
1583 | 0 | pBorder->Invalidate( InvalidateFlags::NoErase ); |
1584 | 0 | } |
1585 | 0 | } |
1586 | 0 | else if( (GetStyle() & WB_FLATBUTTON) || |
1587 | 0 | IsNativeControlSupported(ControlType::Pushbutton, ControlPart::Entire) ) |
1588 | 0 | { |
1589 | 0 | Invalidate(); |
1590 | 0 | } |
1591 | 0 | } |
1592 | 0 | } |
1593 | | |
1594 | 0 | return Button::PreNotify(rNEvt); |
1595 | 0 | } |
1596 | | |
1597 | | void PushButton::Toggle() |
1598 | 0 | { |
1599 | 0 | ImplCallEventListenersAndHandler( VclEventId::PushbuttonToggle, nullptr ); |
1600 | 0 | } |
1601 | | |
1602 | | void PushButton::SetSymbol( SymbolType eSymbol ) |
1603 | 0 | { |
1604 | 0 | if ( meSymbol != eSymbol ) |
1605 | 0 | { |
1606 | 0 | meSymbol = eSymbol; |
1607 | 0 | CompatStateChanged( StateChangedType::Data ); |
1608 | 0 | } |
1609 | 0 | } |
1610 | | |
1611 | | void PushButton::SetSymbolAlign( SymbolAlign eAlign ) |
1612 | 0 | { |
1613 | 0 | ImplSetSymbolAlign( eAlign ); |
1614 | 0 | } |
1615 | | |
1616 | | void PushButton::SetDropDown( PushButtonDropdownStyle nStyle ) |
1617 | 0 | { |
1618 | 0 | if ( mnDDStyle != nStyle ) |
1619 | 0 | { |
1620 | 0 | mnDDStyle = nStyle; |
1621 | 0 | CompatStateChanged( StateChangedType::Data ); |
1622 | 0 | } |
1623 | 0 | } |
1624 | | |
1625 | | void PushButton::SetState( TriState eState ) |
1626 | 0 | { |
1627 | 0 | if ( meState == eState ) |
1628 | 0 | return; |
1629 | | |
1630 | 0 | meState = eState; |
1631 | 0 | if ( meState == TRISTATE_FALSE ) |
1632 | 0 | GetButtonState() &= ~DrawButtonFlags(DrawButtonFlags::Checked | DrawButtonFlags::DontKnow); |
1633 | 0 | else if ( meState == TRISTATE_TRUE ) |
1634 | 0 | { |
1635 | 0 | GetButtonState() &= ~DrawButtonFlags::DontKnow; |
1636 | 0 | GetButtonState() |= DrawButtonFlags::Checked; |
1637 | 0 | } |
1638 | 0 | else // TRISTATE_INDET |
1639 | 0 | { |
1640 | 0 | GetButtonState() &= ~DrawButtonFlags::Checked; |
1641 | 0 | GetButtonState() |= DrawButtonFlags::DontKnow; |
1642 | 0 | } |
1643 | |
|
1644 | 0 | CompatStateChanged( StateChangedType::State ); |
1645 | 0 | Toggle(); |
1646 | 0 | } |
1647 | | |
1648 | | void PushButton::statusChanged(const css::frame::FeatureStateEvent& rEvent) |
1649 | 0 | { |
1650 | 0 | Button::statusChanged(rEvent); |
1651 | 0 | if (rEvent.State.has<bool>()) |
1652 | 0 | SetPressed(rEvent.State.get<bool>()); |
1653 | 0 | } |
1654 | | |
1655 | | void PushButton::SetPressed( bool bPressed ) |
1656 | 0 | { |
1657 | 0 | if ( mbPressed != bPressed ) |
1658 | 0 | { |
1659 | 0 | mbPressed = bPressed; |
1660 | 0 | CompatStateChanged( StateChangedType::Data ); |
1661 | 0 | } |
1662 | 0 | } |
1663 | | |
1664 | | void PushButton::EndSelection() |
1665 | 0 | { |
1666 | 0 | EndTracking( TrackingEventFlags::Cancel ); |
1667 | 0 | if ( !isDisposed() && |
1668 | 0 | GetButtonState() & DrawButtonFlags::Pressed ) |
1669 | 0 | { |
1670 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
1671 | 0 | if ( !mbPressed ) |
1672 | 0 | Invalidate(); |
1673 | 0 | } |
1674 | 0 | } |
1675 | | |
1676 | | Size PushButton::CalcMinimumSize() const |
1677 | 0 | { |
1678 | 0 | Size aSize; |
1679 | |
|
1680 | 0 | if ( IsSymbol() ) |
1681 | 0 | { |
1682 | 0 | if ( IsSmallSymbol ()) |
1683 | 0 | aSize = Size( 16, 12 ); |
1684 | 0 | else |
1685 | 0 | aSize = Size( 26, 24 ); |
1686 | 0 | } |
1687 | 0 | else if ( Button::HasImage() ) |
1688 | 0 | aSize = GetModeImage().GetSizePixel(); |
1689 | 0 | if( mnDDStyle == PushButtonDropdownStyle::MenuButton ) |
1690 | 0 | { |
1691 | 0 | tools::Long nSymbolSize = GetTextHeight() / 2 + 1; |
1692 | 0 | aSize.AdjustWidth(2*nSymbolSize ); |
1693 | 0 | } |
1694 | 0 | if (!PushButton::GetText().isEmpty()) |
1695 | 0 | { |
1696 | 0 | Size textSize = GetTextRect( tools::Rectangle( Point(), Size( 0x7fffffff, 0x7fffffff ) ), |
1697 | 0 | PushButton::GetText(), ImplGetTextStyle( SystemTextColorFlags::NONE ) ).GetSize(); |
1698 | |
|
1699 | 0 | tools::Long nTextHeight = textSize.Height() * 1.15; |
1700 | |
|
1701 | 0 | ImageAlign eImageAlign = GetImageAlign(); |
1702 | | // tdf#142337 only considering the simple top/bottom/left/right possibilities |
1703 | 0 | if (eImageAlign == ImageAlign::Top || eImageAlign == ImageAlign::Bottom) |
1704 | 0 | { |
1705 | 0 | aSize.AdjustHeight(nTextHeight); |
1706 | 0 | aSize.setWidth(std::max(aSize.Width(), textSize.Width())); |
1707 | 0 | } |
1708 | 0 | else |
1709 | 0 | { |
1710 | 0 | aSize.AdjustWidth(textSize.Width()); |
1711 | 0 | aSize.setHeight(std::max(aSize.Height(), nTextHeight)); |
1712 | 0 | } |
1713 | 0 | } |
1714 | | |
1715 | | // cf. ImplDrawPushButton ... |
1716 | 0 | if( (GetStyle() & WB_SMALLSTYLE) == 0 ) |
1717 | 0 | { |
1718 | 0 | aSize.AdjustWidth(24 ); |
1719 | 0 | aSize.AdjustHeight(12 ); |
1720 | 0 | } |
1721 | |
|
1722 | 0 | return CalcWindowSize( aSize ); |
1723 | 0 | } |
1724 | | |
1725 | | Size PushButton::GetOptimalSize() const |
1726 | 0 | { |
1727 | 0 | return CalcMinimumSize(); |
1728 | 0 | } |
1729 | | |
1730 | | bool PushButton::set_property(const OUString &rKey, const OUString &rValue) |
1731 | 0 | { |
1732 | 0 | if (rKey == "has-default") |
1733 | 0 | { |
1734 | 0 | WinBits nBits = GetStyle(); |
1735 | 0 | nBits &= ~WB_DEFBUTTON; |
1736 | 0 | if (toBool(rValue)) |
1737 | 0 | nBits |= WB_DEFBUTTON; |
1738 | 0 | SetStyle(nBits); |
1739 | 0 | } |
1740 | 0 | else |
1741 | 0 | return Button::set_property(rKey, rValue); |
1742 | 0 | return true; |
1743 | 0 | } |
1744 | | |
1745 | | void PushButton::ShowFocus(const tools::Rectangle& rRect) |
1746 | 0 | { |
1747 | 0 | if (IsNativeControlSupported(ControlType::Pushbutton, ControlPart::Focus)) |
1748 | 0 | { |
1749 | 0 | PushButtonValue aControlValue; |
1750 | 0 | aControlValue.mbIsAction = isAction(); |
1751 | 0 | tools::Rectangle aInRect(Point(), GetOutputSizePixel()); |
1752 | 0 | GetOutDev()->DrawNativeControl(ControlType::Pushbutton, ControlPart::Focus, aInRect, |
1753 | 0 | ControlState::FOCUSED, aControlValue, OUString()); |
1754 | 0 | } |
1755 | 0 | Button::ShowFocus(rRect); |
1756 | 0 | } |
1757 | | |
1758 | | void OKButton::ImplInit( vcl::Window* pParent, WinBits nStyle ) |
1759 | 0 | { |
1760 | 0 | set_id(u"ok"_ustr); |
1761 | 0 | PushButton::ImplInit( pParent, nStyle ); |
1762 | |
|
1763 | 0 | SetText( GetStandardText( StandardButtonType::OK ) ); |
1764 | 0 | } |
1765 | | |
1766 | | OKButton::OKButton( vcl::Window* pParent, WinBits nStyle ) : |
1767 | 0 | PushButton( WindowType::OKBUTTON ) |
1768 | 0 | { |
1769 | 0 | ImplInit( pParent, nStyle ); |
1770 | 0 | } Unexecuted instantiation: OKButton::OKButton(vcl::Window*, long) Unexecuted instantiation: OKButton::OKButton(vcl::Window*, long) |
1771 | | |
1772 | | void OKButton::Click() |
1773 | 0 | { |
1774 | | // close parent if no link set |
1775 | 0 | if ( !GetClickHdl() ) |
1776 | 0 | { |
1777 | 0 | vcl::Window* pParent = getNonLayoutParent(this); |
1778 | 0 | if ( pParent->IsSystemWindow() ) |
1779 | 0 | { |
1780 | 0 | if ( pParent->IsDialog() ) |
1781 | 0 | { |
1782 | 0 | VclPtr<Dialog> xParent( static_cast<Dialog*>(pParent) ); |
1783 | 0 | if ( xParent->IsInExecute() ) |
1784 | 0 | xParent->EndDialog( RET_OK ); |
1785 | | // prevent recursive calls |
1786 | 0 | else if ( !xParent->IsInClose() ) |
1787 | 0 | { |
1788 | 0 | if ( pParent->GetStyle() & WB_CLOSEABLE ) |
1789 | 0 | xParent->Close(); |
1790 | 0 | } |
1791 | 0 | } |
1792 | 0 | else |
1793 | 0 | { |
1794 | 0 | if ( pParent->GetStyle() & WB_CLOSEABLE ) |
1795 | 0 | static_cast<SystemWindow*>(pParent)->Close(); |
1796 | 0 | } |
1797 | 0 | } |
1798 | 0 | } |
1799 | 0 | else |
1800 | 0 | { |
1801 | 0 | PushButton::Click(); |
1802 | 0 | } |
1803 | 0 | } |
1804 | | |
1805 | | void CancelButton::ImplInit( vcl::Window* pParent, WinBits nStyle ) |
1806 | 0 | { |
1807 | 0 | set_id(u"cancel"_ustr); |
1808 | 0 | PushButton::ImplInit( pParent, nStyle ); |
1809 | |
|
1810 | 0 | SetText( GetStandardText( StandardButtonType::Cancel ) ); |
1811 | 0 | } |
1812 | | |
1813 | | CancelButton::CancelButton( vcl::Window* pParent, WinBits nStyle ) : |
1814 | 0 | PushButton( WindowType::CANCELBUTTON ) |
1815 | 0 | { |
1816 | 0 | ImplInit( pParent, nStyle ); |
1817 | 0 | } Unexecuted instantiation: CancelButton::CancelButton(vcl::Window*, long) Unexecuted instantiation: CancelButton::CancelButton(vcl::Window*, long) |
1818 | | |
1819 | | void CancelButton::Click() |
1820 | 0 | { |
1821 | | // close parent if link not set |
1822 | 0 | if ( !GetClickHdl() ) |
1823 | 0 | { |
1824 | 0 | vcl::Window* pParent = getNonLayoutParent(this); |
1825 | 0 | if ( pParent->IsSystemWindow() ) |
1826 | 0 | { |
1827 | 0 | if ( pParent->IsDialog() ) |
1828 | 0 | { |
1829 | 0 | Dialog* pDialog = static_cast<Dialog*>(pParent); |
1830 | 0 | if (pDialog->IsInExecute()) |
1831 | 0 | pDialog->EndDialog(); |
1832 | | // prevent recursive calls |
1833 | 0 | else if (!pDialog->IsInClose()) |
1834 | 0 | { |
1835 | 0 | if ( pParent->GetStyle() & WB_CLOSEABLE ) |
1836 | 0 | pDialog->Close(); |
1837 | 0 | } |
1838 | 0 | } |
1839 | 0 | else |
1840 | 0 | { |
1841 | 0 | if ( pParent->GetStyle() & WB_CLOSEABLE ) |
1842 | 0 | static_cast<SystemWindow*>(pParent)->Close(); |
1843 | 0 | } |
1844 | 0 | } |
1845 | 0 | } |
1846 | 0 | else |
1847 | 0 | { |
1848 | 0 | PushButton::Click(); |
1849 | 0 | } |
1850 | 0 | } |
1851 | | |
1852 | | CloseButton::CloseButton( vcl::Window* pParent ) |
1853 | 0 | : CancelButton(pParent, 0) |
1854 | 0 | { |
1855 | 0 | SetText( GetStandardText( StandardButtonType::Close ) ); |
1856 | 0 | } Unexecuted instantiation: CloseButton::CloseButton(vcl::Window*) Unexecuted instantiation: CloseButton::CloseButton(vcl::Window*) |
1857 | | |
1858 | | void HelpButton::ImplInit( vcl::Window* pParent, WinBits nStyle ) |
1859 | 0 | { |
1860 | 0 | set_id(u"help"_ustr); |
1861 | 0 | PushButton::ImplInit( pParent, nStyle | WB_NOPOINTERFOCUS ); |
1862 | |
|
1863 | 0 | SetText( GetStandardText( StandardButtonType::Help ) ); |
1864 | 0 | } |
1865 | | |
1866 | | HelpButton::HelpButton( vcl::Window* pParent, WinBits nStyle ) : |
1867 | 0 | PushButton( WindowType::HELPBUTTON ) |
1868 | 0 | { |
1869 | 0 | ImplInit( pParent, nStyle ); |
1870 | 0 | } Unexecuted instantiation: HelpButton::HelpButton(vcl::Window*, long) Unexecuted instantiation: HelpButton::HelpButton(vcl::Window*, long) |
1871 | | |
1872 | | void HelpButton::Click() |
1873 | 0 | { |
1874 | | // trigger help if no link set |
1875 | 0 | if ( !GetClickHdl() ) |
1876 | 0 | { |
1877 | 0 | vcl::Window* pFocusWin = Application::GetFocusWindow(); |
1878 | 0 | if ( !pFocusWin || comphelper::LibreOfficeKit::isActive() ) |
1879 | 0 | pFocusWin = this; |
1880 | |
|
1881 | 0 | HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HelpEventMode::CONTEXT ); |
1882 | 0 | pFocusWin->RequestHelp( aEvt ); |
1883 | 0 | } |
1884 | 0 | PushButton::Click(); |
1885 | 0 | } |
1886 | | |
1887 | | void HelpButton::StateChanged( StateChangedType nStateChange ) |
1888 | 0 | { |
1889 | | // Hide when we have no help URL. |
1890 | 0 | if (comphelper::LibreOfficeKit::isActive() && |
1891 | 0 | officecfg::Office::Common::Help::HelpRootURL::get().isEmpty()) |
1892 | 0 | Hide(); |
1893 | 0 | else |
1894 | 0 | PushButton::StateChanged(nStateChange); |
1895 | 0 | } |
1896 | | |
1897 | | void RadioButton::ImplInitRadioButtonData() |
1898 | 0 | { |
1899 | 0 | mbChecked = false; |
1900 | 0 | mbRadioCheck = true; |
1901 | 0 | mbStateChanged = false; |
1902 | 0 | } |
1903 | | |
1904 | | void RadioButton::ImplInit( vcl::Window* pParent, WinBits nStyle ) |
1905 | 0 | { |
1906 | 0 | nStyle = ImplInitStyle(getPreviousSibling(pParent), nStyle); |
1907 | 0 | Button::ImplInit( pParent, nStyle, nullptr ); |
1908 | |
|
1909 | 0 | ImplInitSettings( true ); |
1910 | 0 | } |
1911 | | |
1912 | | WinBits RadioButton::ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle ) const |
1913 | 0 | { |
1914 | 0 | if ( !(nStyle & WB_NOGROUP) && |
1915 | 0 | (!pPrevWindow || (pPrevWindow->GetType() != WindowType::RADIOBUTTON)) ) |
1916 | 0 | nStyle |= WB_GROUP; |
1917 | 0 | if ( !(nStyle & WB_NOTABSTOP) ) |
1918 | 0 | { |
1919 | 0 | if ( IsChecked() ) |
1920 | 0 | nStyle |= WB_TABSTOP; |
1921 | 0 | else |
1922 | 0 | nStyle &= ~WB_TABSTOP; |
1923 | 0 | } |
1924 | |
|
1925 | 0 | return nStyle; |
1926 | 0 | } |
1927 | | |
1928 | | const vcl::Font& RadioButton::GetCanonicalFont( const StyleSettings& _rStyle ) const |
1929 | 0 | { |
1930 | 0 | return _rStyle.GetRadioCheckFont(); |
1931 | 0 | } |
1932 | | |
1933 | | const Color& RadioButton::GetCanonicalTextColor( const StyleSettings& _rStyle ) const |
1934 | 0 | { |
1935 | 0 | return _rStyle.GetRadioCheckTextColor(); |
1936 | 0 | } |
1937 | | |
1938 | | void RadioButton::ImplInitSettings( bool bBackground ) |
1939 | 0 | { |
1940 | 0 | Button::ImplInitSettings(); |
1941 | |
|
1942 | 0 | if ( !bBackground ) |
1943 | 0 | return; |
1944 | | |
1945 | 0 | vcl::Window* pParent = GetParent(); |
1946 | 0 | if ( !IsControlBackground() && |
1947 | 0 | (pParent->IsChildTransparentModeEnabled() || IsNativeControlSupported( ControlType::Radiobutton, ControlPart::Entire ) ) ) |
1948 | 0 | { |
1949 | 0 | EnableChildTransparentMode(); |
1950 | 0 | SetParentClipMode( ParentClipMode::NoClip ); |
1951 | 0 | SetPaintTransparent( true ); |
1952 | 0 | SetBackground(); |
1953 | 0 | if( IsNativeControlSupported( ControlType::Radiobutton, ControlPart::Entire ) ) |
1954 | 0 | mpWindowImpl->mbUseNativeFocus = ImplGetSVData()->maNWFData.mbNoFocusRects; |
1955 | 0 | } |
1956 | 0 | else |
1957 | 0 | { |
1958 | 0 | EnableChildTransparentMode( false ); |
1959 | 0 | SetParentClipMode(); |
1960 | 0 | SetPaintTransparent( false ); |
1961 | |
|
1962 | 0 | if ( IsControlBackground() ) |
1963 | 0 | SetBackground( GetControlBackground() ); |
1964 | 0 | else |
1965 | 0 | SetBackground( pParent->GetBackground() ); |
1966 | 0 | } |
1967 | 0 | } |
1968 | | |
1969 | | void RadioButton::ImplDrawRadioButtonState(vcl::RenderContext& rRenderContext) |
1970 | 0 | { |
1971 | 0 | bool bNativeOK = false; |
1972 | | |
1973 | | // no native drawing for image radio buttons |
1974 | 0 | if (!maImage && rRenderContext.IsNativeControlSupported(ControlType::Radiobutton, ControlPart::Entire)) |
1975 | 0 | { |
1976 | 0 | ImplControlValue aControlValue( mbChecked ? ButtonValue::On : ButtonValue::Off ); |
1977 | 0 | tools::Rectangle aCtrlRect(maStateRect.TopLeft(), maStateRect.GetSize()); |
1978 | 0 | ControlState nState = ControlState::NONE; |
1979 | |
|
1980 | 0 | if (GetButtonState() & DrawButtonFlags::Pressed) |
1981 | 0 | nState |= ControlState::PRESSED; |
1982 | 0 | if (HasFocus()) |
1983 | 0 | nState |= ControlState::FOCUSED; |
1984 | 0 | if (GetButtonState() & DrawButtonFlags::Default) |
1985 | 0 | nState |= ControlState::DEFAULT; |
1986 | 0 | if (IsEnabled()) |
1987 | 0 | nState |= ControlState::ENABLED; |
1988 | |
|
1989 | 0 | if (IsMouseOver() && maMouseRect.Contains(GetPointerPosPixel())) |
1990 | 0 | nState |= ControlState::ROLLOVER; |
1991 | |
|
1992 | 0 | bNativeOK = rRenderContext.DrawNativeControl(ControlType::Radiobutton, ControlPart::Entire, aCtrlRect, |
1993 | 0 | nState, aControlValue, OUString()); |
1994 | 0 | } |
1995 | |
|
1996 | 0 | if (bNativeOK) |
1997 | 0 | return; |
1998 | | |
1999 | 0 | if (!maImage) |
2000 | 0 | { |
2001 | 0 | DrawButtonFlags nStyle = GetButtonState(); |
2002 | 0 | if (!IsEnabled()) |
2003 | 0 | nStyle |= DrawButtonFlags::Disabled; |
2004 | 0 | if (mbChecked) |
2005 | 0 | nStyle |= DrawButtonFlags::Checked; |
2006 | 0 | Image aImage = GetRadioImage(rRenderContext.GetSettings(), nStyle); |
2007 | 0 | if (IsZoom()) |
2008 | 0 | rRenderContext.DrawImage(maStateRect.TopLeft(), maStateRect.GetSize(), aImage); |
2009 | 0 | else |
2010 | 0 | rRenderContext.DrawImage(maStateRect.TopLeft(), aImage); |
2011 | 0 | } |
2012 | 0 | else |
2013 | 0 | { |
2014 | 0 | HideFocus(); |
2015 | |
|
2016 | 0 | DecorationView aDecoView(&rRenderContext); |
2017 | 0 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); |
2018 | 0 | tools::Rectangle aImageRect = maStateRect; |
2019 | 0 | Size aImageSize = maImage.GetSizePixel(); |
2020 | 0 | bool bEnabled = IsEnabled(); |
2021 | |
|
2022 | 0 | aImageSize.setWidth( CalcZoom(aImageSize.Width()) ); |
2023 | 0 | aImageSize.setHeight( CalcZoom(aImageSize.Height()) ); |
2024 | |
|
2025 | 0 | aImageRect.AdjustLeft( 1 ); |
2026 | 0 | aImageRect.AdjustTop( 1 ); |
2027 | 0 | aImageRect.AdjustRight( -1 ); |
2028 | 0 | aImageRect.AdjustBottom( -1 ); |
2029 | | |
2030 | | // display border and selection status |
2031 | 0 | aImageRect = aDecoView.DrawFrame(aImageRect, DrawFrameStyle::DoubleIn); |
2032 | 0 | if ((GetButtonState() & DrawButtonFlags::Pressed) || !bEnabled) |
2033 | 0 | rRenderContext.SetFillColor( rStyleSettings.GetFaceColor()); |
2034 | 0 | else |
2035 | 0 | rRenderContext.SetFillColor(rStyleSettings.GetFieldColor()); |
2036 | 0 | rRenderContext.SetLineColor(); |
2037 | 0 | rRenderContext.DrawRect(aImageRect); |
2038 | | |
2039 | | // display image |
2040 | 0 | DrawImageFlags nImageStyle = DrawImageFlags::NONE; |
2041 | 0 | if (!bEnabled) |
2042 | 0 | nImageStyle |= DrawImageFlags::Disable; |
2043 | |
|
2044 | 0 | Image* pImage = &maImage; |
2045 | |
|
2046 | 0 | Point aImagePos(aImageRect.TopLeft()); |
2047 | 0 | aImagePos.AdjustX((aImageRect.GetWidth() - aImageSize.Width()) / 2 ); |
2048 | 0 | aImagePos.AdjustY((aImageRect.GetHeight() - aImageSize.Height()) / 2 ); |
2049 | 0 | if (IsZoom()) |
2050 | 0 | rRenderContext.DrawImage(aImagePos, aImageSize, *pImage, nImageStyle); |
2051 | 0 | else |
2052 | 0 | rRenderContext.DrawImage(aImagePos, *pImage, nImageStyle); |
2053 | |
|
2054 | 0 | aImageRect.AdjustLeft( 1 ); |
2055 | 0 | aImageRect.AdjustTop( 1 ); |
2056 | 0 | aImageRect.AdjustRight( -1 ); |
2057 | 0 | aImageRect.AdjustBottom( -1 ); |
2058 | |
|
2059 | 0 | ImplSetFocusRect(aImageRect); |
2060 | |
|
2061 | 0 | if (mbChecked) |
2062 | 0 | { |
2063 | 0 | rRenderContext.SetLineColor(rStyleSettings.GetHighlightColor()); |
2064 | 0 | rRenderContext.SetFillColor(); |
2065 | 0 | if ((aImageSize.Width() >= 20) || (aImageSize.Height() >= 20)) |
2066 | 0 | { |
2067 | 0 | aImageRect.AdjustLeft( 1 ); |
2068 | 0 | aImageRect.AdjustTop( 1 ); |
2069 | 0 | aImageRect.AdjustRight( -1 ); |
2070 | 0 | aImageRect.AdjustBottom( -1 ); |
2071 | 0 | } |
2072 | 0 | rRenderContext.DrawRect(aImageRect); |
2073 | 0 | aImageRect.AdjustLeft( 1 ); |
2074 | 0 | aImageRect.AdjustTop( 1 ); |
2075 | 0 | aImageRect.AdjustRight( -1 ); |
2076 | 0 | aImageRect.AdjustBottom( -1 ); |
2077 | 0 | rRenderContext.DrawRect(aImageRect); |
2078 | 0 | } |
2079 | |
|
2080 | 0 | if (HasFocus()) |
2081 | 0 | ShowFocus(ImplGetFocusRect()); |
2082 | 0 | } |
2083 | 0 | } |
2084 | | |
2085 | | // for drawing RadioButton or CheckButton that has Text and/or Image |
2086 | | void Button::ImplDrawRadioCheck(OutputDevice* pDev, WinBits nWinStyle, SystemTextColorFlags nSystemTextColorFlags, |
2087 | | const Point& rPos, const Size& rSize, |
2088 | | const Size& rImageSize, tools::Rectangle& rStateRect, |
2089 | | tools::Rectangle& rMouseRect) |
2090 | 0 | { |
2091 | 0 | DrawTextFlags nTextStyle = Button::ImplGetTextStyle( nWinStyle, nSystemTextColorFlags ); |
2092 | |
|
2093 | 0 | const tools::Long nImageSep = GetDrawPixel( pDev, ImplGetImageToTextDistance() ); |
2094 | 0 | Size aSize( rSize ); |
2095 | 0 | Point aPos( rPos ); |
2096 | 0 | aPos.AdjustX(rImageSize.Width() + nImageSep ); |
2097 | | |
2098 | | // tdf#141761 Old (convenience?) adjustment of width may lead to empty |
2099 | | // or negative(!) Size, that needs to be avoided. The coordinate context |
2100 | | // is pixel-oriented (all Paints of Controls are, historically), so |
2101 | | // the minimum width should be '1' Pixel. |
2102 | | // Hint: nImageSep is based on Zoom (using Window::CalcZoom) and |
2103 | | // MapModes (using Window::GetDrawPixel) - so potentially a wide range |
2104 | | // of unpredictable values is possible |
2105 | 0 | const tools::Long nWidthAdjust(rImageSize.Width() + nImageSep); |
2106 | 0 | aSize.setWidth(std::max(static_cast<tools::Long>(1), aSize.getWidth() - nWidthAdjust)); |
2107 | | |
2108 | | // if the text rect height is smaller than the height of the image |
2109 | | // then for single lines the default should be centered text |
2110 | 0 | if( (nWinStyle & (WB_TOP|WB_VCENTER|WB_BOTTOM)) == 0 && |
2111 | 0 | (rImageSize.Height() > rSize.Height() || ! (nWinStyle & WB_WORDBREAK) ) ) |
2112 | 0 | { |
2113 | 0 | nTextStyle &= ~DrawTextFlags(DrawTextFlags::Top|DrawTextFlags::Bottom); |
2114 | 0 | nTextStyle |= DrawTextFlags::VCenter; |
2115 | 0 | aSize.setHeight( rImageSize.Height() ); |
2116 | 0 | } |
2117 | |
|
2118 | 0 | ImplDrawAlignedImage( pDev, aPos, aSize, 1, nTextStyle ); |
2119 | |
|
2120 | 0 | rMouseRect = tools::Rectangle( aPos, aSize ); |
2121 | 0 | rMouseRect.SetLeft( rPos.X() ); |
2122 | |
|
2123 | 0 | rStateRect.SetLeft( rPos.X() ); |
2124 | 0 | rStateRect.SetTop( rMouseRect.Top() ); |
2125 | |
|
2126 | 0 | if ( aSize.Height() > rImageSize.Height() ) |
2127 | 0 | rStateRect.AdjustTop(( aSize.Height() - rImageSize.Height() ) / 2 ); |
2128 | 0 | else |
2129 | 0 | { |
2130 | 0 | rStateRect.AdjustTop( -(( rImageSize.Height() - aSize.Height() ) / 2) ); |
2131 | 0 | if( rStateRect.Top() < 0 ) |
2132 | 0 | rStateRect.SetTop( 0 ); |
2133 | 0 | } |
2134 | |
|
2135 | 0 | rStateRect.SetRight( rStateRect.Left()+rImageSize.Width()-1 ); |
2136 | 0 | rStateRect.SetBottom( rStateRect.Top()+rImageSize.Height()-1 ); |
2137 | |
|
2138 | 0 | if ( rStateRect.Bottom() > rMouseRect.Bottom() ) |
2139 | 0 | rMouseRect.SetBottom( rStateRect.Bottom() ); |
2140 | 0 | } |
2141 | | |
2142 | | void RadioButton::ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags, |
2143 | | const Point& rPos, const Size& rSize, |
2144 | | const Size& rImageSize, tools::Rectangle& rStateRect, |
2145 | | tools::Rectangle& rMouseRect ) |
2146 | 0 | { |
2147 | 0 | WinBits nWinStyle = GetStyle(); |
2148 | 0 | OUString aText( GetText() ); |
2149 | |
|
2150 | 0 | auto popIt = pDev->ScopedPush(vcl::PushFlags::CLIPREGION); |
2151 | 0 | pDev->IntersectClipRegion( tools::Rectangle( rPos, rSize ) ); |
2152 | | |
2153 | | // no image radio button |
2154 | 0 | if ( !maImage ) |
2155 | 0 | { |
2156 | 0 | if (!aText.isEmpty() || HasImage()) |
2157 | 0 | { |
2158 | 0 | Button::ImplDrawRadioCheck(pDev, nWinStyle, nSystemTextColorFlags, |
2159 | 0 | rPos, rSize, rImageSize, |
2160 | 0 | rStateRect, rMouseRect); |
2161 | 0 | } |
2162 | 0 | else |
2163 | 0 | { |
2164 | 0 | rStateRect.SetLeft( rPos.X() ); |
2165 | 0 | if ( nWinStyle & WB_VCENTER ) |
2166 | 0 | rStateRect.SetTop( rPos.Y()+((rSize.Height()-rImageSize.Height())/2) ); |
2167 | 0 | else if ( nWinStyle & WB_BOTTOM ) |
2168 | 0 | rStateRect.SetTop( rPos.Y()+rSize.Height()-rImageSize.Height() ); //-1; |
2169 | 0 | else |
2170 | 0 | rStateRect.SetTop( rPos.Y() ); |
2171 | 0 | rStateRect.SetRight( rStateRect.Left()+rImageSize.Width()-1 ); |
2172 | 0 | rStateRect.SetBottom( rStateRect.Top()+rImageSize.Height()-1 ); |
2173 | 0 | rMouseRect = rStateRect; |
2174 | |
|
2175 | 0 | ImplSetFocusRect( rStateRect ); |
2176 | 0 | } |
2177 | 0 | } |
2178 | 0 | else |
2179 | 0 | { |
2180 | 0 | bool bTopImage = (nWinStyle & WB_TOP) != 0; |
2181 | 0 | Size aImageSize = maImage.GetSizePixel(); |
2182 | 0 | tools::Rectangle aImageRect( rPos, rSize ); |
2183 | 0 | tools::Long nTextHeight = pDev->GetTextHeight(); |
2184 | 0 | tools::Long nTextWidth = pDev->GetCtrlTextWidth( aText ); |
2185 | | |
2186 | | // calculate position and sizes |
2187 | 0 | if (!aText.isEmpty()) |
2188 | 0 | { |
2189 | 0 | Size aTmpSize( (aImageSize.Width()+8), (aImageSize.Height()+8) ); |
2190 | 0 | if ( bTopImage ) |
2191 | 0 | { |
2192 | 0 | aImageRect.SetLeft( (rSize.Width()-aTmpSize.Width())/2 ); |
2193 | 0 | aImageRect.SetTop( (rSize.Height()-(aTmpSize.Height()+nTextHeight+6))/2 ); |
2194 | 0 | } |
2195 | 0 | else |
2196 | 0 | aImageRect.SetTop( (rSize.Height()-aTmpSize.Height())/2 ); |
2197 | |
|
2198 | 0 | aImageRect.SetRight( aImageRect.Left()+aTmpSize.Width() ); |
2199 | 0 | aImageRect.SetBottom( aImageRect.Top()+aTmpSize.Height() ); |
2200 | | |
2201 | | // display text |
2202 | 0 | Point aTxtPos = rPos; |
2203 | 0 | if ( bTopImage ) |
2204 | 0 | { |
2205 | 0 | aTxtPos.AdjustX((rSize.Width()-nTextWidth)/2 ); |
2206 | 0 | aTxtPos.AdjustY(aImageRect.Bottom()+6 ); |
2207 | 0 | } |
2208 | 0 | else |
2209 | 0 | { |
2210 | 0 | aTxtPos.AdjustX(aImageRect.Right()+8 ); |
2211 | 0 | aTxtPos.AdjustY((rSize.Height()-nTextHeight)/2 ); |
2212 | 0 | } |
2213 | 0 | pDev->DrawCtrlText( aTxtPos, aText, 0, aText.getLength() ); |
2214 | 0 | } |
2215 | |
|
2216 | 0 | rMouseRect = aImageRect; |
2217 | 0 | rStateRect = aImageRect; |
2218 | 0 | } |
2219 | 0 | } |
2220 | | |
2221 | | void RadioButton::ImplDrawRadioButton(vcl::RenderContext& rRenderContext) |
2222 | 0 | { |
2223 | 0 | HideFocus(); |
2224 | |
|
2225 | 0 | Size aImageSize; |
2226 | 0 | if (!maImage) |
2227 | 0 | aImageSize = ImplGetRadioImageSize(); |
2228 | 0 | else |
2229 | 0 | aImageSize = maImage.GetSizePixel(); |
2230 | |
|
2231 | 0 | aImageSize.setWidth( CalcZoom(aImageSize.Width()) ); |
2232 | 0 | aImageSize.setHeight( CalcZoom(aImageSize.Height()) ); |
2233 | | |
2234 | | // Draw control text |
2235 | 0 | ImplDraw(&rRenderContext, SystemTextColorFlags::NONE, Point(), GetOutputSizePixel(), |
2236 | 0 | aImageSize, maStateRect, maMouseRect); |
2237 | |
|
2238 | 0 | if (!maImage && HasFocus()) |
2239 | 0 | ShowFocus(ImplGetFocusRect()); |
2240 | |
|
2241 | 0 | ImplDrawRadioButtonState(rRenderContext); |
2242 | 0 | } |
2243 | | |
2244 | | void RadioButton::group(RadioButton &rOther) |
2245 | 0 | { |
2246 | 0 | if (&rOther == this) |
2247 | 0 | return; |
2248 | | |
2249 | 0 | if (!m_xGroup) |
2250 | 0 | { |
2251 | 0 | m_xGroup = std::make_shared<std::vector<VclPtr<RadioButton> >>(); |
2252 | 0 | m_xGroup->push_back(this); |
2253 | 0 | } |
2254 | |
|
2255 | 0 | auto aFind = std::find(m_xGroup->begin(), m_xGroup->end(), VclPtr<RadioButton>(&rOther)); |
2256 | 0 | if (aFind == m_xGroup->end()) |
2257 | 0 | { |
2258 | 0 | m_xGroup->push_back(&rOther); |
2259 | |
|
2260 | 0 | if (rOther.m_xGroup) |
2261 | 0 | { |
2262 | 0 | std::vector< VclPtr<RadioButton> > aOthers(rOther.GetRadioButtonGroup(false)); |
2263 | | //make all members of the group share the same button group |
2264 | 0 | for (auto const& elem : aOthers) |
2265 | 0 | { |
2266 | 0 | aFind = std::find(m_xGroup->begin(), m_xGroup->end(), elem); |
2267 | 0 | if (aFind == m_xGroup->end()) |
2268 | 0 | m_xGroup->push_back(elem); |
2269 | 0 | } |
2270 | 0 | } |
2271 | | |
2272 | | //make all members of the group share the same button group |
2273 | 0 | for (VclPtr<RadioButton> const & pButton : *m_xGroup) |
2274 | 0 | { |
2275 | 0 | pButton->m_xGroup = m_xGroup; |
2276 | 0 | } |
2277 | 0 | } |
2278 | | |
2279 | | //if this one is checked, uncheck all the others |
2280 | 0 | if (mbChecked) |
2281 | 0 | ImplUncheckAllOther(); |
2282 | 0 | } |
2283 | | |
2284 | | std::vector< VclPtr<RadioButton> > RadioButton::GetRadioButtonGroup(bool bIncludeThis) const |
2285 | 0 | { |
2286 | 0 | if (m_xGroup) |
2287 | 0 | { |
2288 | 0 | if (bIncludeThis) |
2289 | 0 | return *m_xGroup; |
2290 | 0 | std::vector< VclPtr<RadioButton> > aGroup; |
2291 | 0 | for (VclPtr<RadioButton> const & pRadioButton : *m_xGroup) |
2292 | 0 | { |
2293 | 0 | if (pRadioButton == this) |
2294 | 0 | continue; |
2295 | 0 | aGroup.push_back(pRadioButton); |
2296 | 0 | } |
2297 | 0 | return aGroup; |
2298 | 0 | } |
2299 | | |
2300 | 0 | std::vector<VclPtr<RadioButton>> aGroup; |
2301 | 0 | if (mbUsesExplicitGroup) |
2302 | 0 | return aGroup; |
2303 | | |
2304 | | //old-school |
2305 | | |
2306 | | // go back to first in group; |
2307 | 0 | vcl::Window* pFirst = const_cast<RadioButton*>(this); |
2308 | 0 | while( ( pFirst->GetStyle() & WB_GROUP ) == 0 ) |
2309 | 0 | { |
2310 | 0 | vcl::Window* pWindow = pFirst->GetWindow( GetWindowType::Prev ); |
2311 | 0 | if( pWindow ) |
2312 | 0 | pFirst = pWindow; |
2313 | 0 | else |
2314 | 0 | break; |
2315 | 0 | } |
2316 | | // insert radiobuttons up to next group |
2317 | 0 | do |
2318 | 0 | { |
2319 | 0 | if( pFirst->GetType() == WindowType::RADIOBUTTON ) |
2320 | 0 | { |
2321 | 0 | if( pFirst != this || bIncludeThis ) |
2322 | 0 | aGroup.emplace_back(static_cast<RadioButton*>(pFirst) ); |
2323 | 0 | } |
2324 | 0 | pFirst = pFirst->GetWindow( GetWindowType::Next ); |
2325 | 0 | } while( pFirst && ( ( pFirst->GetStyle() & WB_GROUP ) == 0 ) ); |
2326 | |
|
2327 | 0 | return aGroup; |
2328 | 0 | } |
2329 | | |
2330 | | void RadioButton::ImplUncheckAllOther() |
2331 | 0 | { |
2332 | 0 | mpWindowImpl->mnStyle |= WB_TABSTOP; |
2333 | |
|
2334 | 0 | std::vector<VclPtr<RadioButton> > aGroup(GetRadioButtonGroup(false)); |
2335 | | // iterate over radio button group and checked buttons |
2336 | 0 | for (VclPtr<RadioButton>& pWindow : aGroup) |
2337 | 0 | { |
2338 | 0 | if ( pWindow->IsChecked() ) |
2339 | 0 | { |
2340 | 0 | pWindow->SetState( false ); |
2341 | 0 | if ( pWindow->isDisposed() ) |
2342 | 0 | return; |
2343 | 0 | } |
2344 | | |
2345 | | // not inside if clause to always remove wrongly set WB_TABSTOPS |
2346 | 0 | pWindow->mpWindowImpl->mnStyle &= ~WB_TABSTOP; |
2347 | 0 | } |
2348 | 0 | } |
2349 | | |
2350 | | void RadioButton::ImplCallClick( bool bGrabFocus, GetFocusFlags nFocusFlags ) |
2351 | 0 | { |
2352 | 0 | mbStateChanged = !mbChecked; |
2353 | 0 | mbChecked = true; |
2354 | 0 | mpWindowImpl->mnStyle |= WB_TABSTOP; |
2355 | 0 | Invalidate(); |
2356 | 0 | VclPtr<vcl::Window> xWindow = this; |
2357 | 0 | if ( mbRadioCheck ) |
2358 | 0 | ImplUncheckAllOther(); |
2359 | 0 | if ( xWindow->isDisposed() ) |
2360 | 0 | return; |
2361 | 0 | if ( bGrabFocus ) |
2362 | 0 | ImplGrabFocus( nFocusFlags ); |
2363 | 0 | if ( xWindow->isDisposed() ) |
2364 | 0 | return; |
2365 | 0 | if ( mbStateChanged ) |
2366 | 0 | Toggle(); |
2367 | 0 | if ( xWindow->isDisposed() ) |
2368 | 0 | return; |
2369 | 0 | Click(); |
2370 | 0 | if ( xWindow->isDisposed() ) |
2371 | 0 | return; |
2372 | 0 | mbStateChanged = false; |
2373 | 0 | } |
2374 | | |
2375 | | RadioButton::RadioButton(vcl::Window* pParent, bool bUsesExplicitGroup, WinBits nStyle) |
2376 | 0 | : Button(WindowType::RADIOBUTTON) |
2377 | 0 | , mbUsesExplicitGroup(bUsesExplicitGroup) |
2378 | 0 | { |
2379 | 0 | ImplInitRadioButtonData(); |
2380 | 0 | ImplInit( pParent, nStyle ); |
2381 | 0 | } Unexecuted instantiation: RadioButton::RadioButton(vcl::Window*, bool, long) Unexecuted instantiation: RadioButton::RadioButton(vcl::Window*, bool, long) |
2382 | | |
2383 | | RadioButton::~RadioButton() |
2384 | 0 | { |
2385 | 0 | disposeOnce(); |
2386 | 0 | } |
2387 | | |
2388 | | void RadioButton::dispose() |
2389 | 0 | { |
2390 | 0 | if (m_xGroup) |
2391 | 0 | { |
2392 | 0 | std::erase(*m_xGroup, VclPtr<RadioButton>(this)); |
2393 | 0 | m_xGroup.reset(); |
2394 | 0 | } |
2395 | 0 | Button::dispose(); |
2396 | 0 | } |
2397 | | |
2398 | | rtl::Reference<comphelper::OAccessible> RadioButton::CreateAccessible() |
2399 | 0 | { |
2400 | 0 | return new VCLXAccessibleRadioButton(this); |
2401 | 0 | } |
2402 | | |
2403 | | void RadioButton::MouseButtonDown( const MouseEvent& rMEvt ) |
2404 | 0 | { |
2405 | 0 | if ( rMEvt.IsLeft() && maMouseRect.Contains( rMEvt.GetPosPixel() ) ) |
2406 | 0 | { |
2407 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
2408 | 0 | Invalidate(); |
2409 | 0 | StartTracking(); |
2410 | 0 | return; |
2411 | 0 | } |
2412 | | |
2413 | 0 | Button::MouseButtonDown( rMEvt ); |
2414 | 0 | } |
2415 | | |
2416 | | void RadioButton::Tracking( const TrackingEvent& rTEvt ) |
2417 | 0 | { |
2418 | 0 | if ( rTEvt.IsTrackingEnded() ) |
2419 | 0 | { |
2420 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
2421 | 0 | { |
2422 | 0 | if ( !(GetStyle() & WB_NOPOINTERFOCUS) && !rTEvt.IsTrackingCanceled() ) |
2423 | 0 | GrabFocus(); |
2424 | |
|
2425 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
2426 | | |
2427 | | // do not call click handler if aborted |
2428 | 0 | if ( !rTEvt.IsTrackingCanceled() ) |
2429 | 0 | ImplCallClick(); |
2430 | 0 | else |
2431 | 0 | { |
2432 | 0 | Invalidate(); |
2433 | 0 | } |
2434 | 0 | } |
2435 | 0 | } |
2436 | 0 | else |
2437 | 0 | { |
2438 | 0 | if ( maMouseRect.Contains( rTEvt.GetMouseEvent().GetPosPixel() ) ) |
2439 | 0 | { |
2440 | 0 | if ( !(GetButtonState() & DrawButtonFlags::Pressed) ) |
2441 | 0 | { |
2442 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
2443 | 0 | Invalidate(); |
2444 | 0 | } |
2445 | 0 | } |
2446 | 0 | else |
2447 | 0 | { |
2448 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
2449 | 0 | { |
2450 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
2451 | 0 | Invalidate(); |
2452 | 0 | } |
2453 | 0 | } |
2454 | 0 | } |
2455 | 0 | } |
2456 | | |
2457 | | void RadioButton::KeyInput( const KeyEvent& rKEvt ) |
2458 | 0 | { |
2459 | 0 | vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); |
2460 | |
|
2461 | 0 | if ( !aKeyCode.GetModifier() && (aKeyCode.GetCode() == KEY_SPACE) ) |
2462 | 0 | { |
2463 | 0 | if ( !(GetButtonState() & DrawButtonFlags::Pressed) ) |
2464 | 0 | { |
2465 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
2466 | 0 | Invalidate(); |
2467 | 0 | } |
2468 | 0 | } |
2469 | 0 | else if ( (GetButtonState() & DrawButtonFlags::Pressed) && (aKeyCode.GetCode() == KEY_ESCAPE) ) |
2470 | 0 | { |
2471 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
2472 | 0 | Invalidate(); |
2473 | 0 | } |
2474 | 0 | else |
2475 | 0 | Button::KeyInput( rKEvt ); |
2476 | 0 | } |
2477 | | |
2478 | | void RadioButton::KeyUp( const KeyEvent& rKEvt ) |
2479 | 0 | { |
2480 | 0 | vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); |
2481 | |
|
2482 | 0 | if ( (GetButtonState() & DrawButtonFlags::Pressed) && (aKeyCode.GetCode() == KEY_SPACE) ) |
2483 | 0 | { |
2484 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
2485 | 0 | ImplCallClick(); |
2486 | 0 | } |
2487 | 0 | else |
2488 | 0 | Button::KeyUp( rKEvt ); |
2489 | 0 | } |
2490 | | |
2491 | | void RadioButton::FillLayoutData() const |
2492 | 0 | { |
2493 | 0 | mxLayoutData.emplace(); |
2494 | 0 | const_cast<RadioButton*>(this)->Invalidate(); |
2495 | 0 | } |
2496 | | |
2497 | | void RadioButton::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) |
2498 | 0 | { |
2499 | 0 | ImplDrawRadioButton(rRenderContext); |
2500 | 0 | } |
2501 | | |
2502 | | void RadioButton::Draw( OutputDevice* pDev, const Point& rPos, |
2503 | | SystemTextColorFlags nFlags ) |
2504 | 0 | { |
2505 | 0 | if ( !maImage ) |
2506 | 0 | { |
2507 | 0 | MapMode aResMapMode( MapUnit::Map100thMM ); |
2508 | 0 | Point aPos = pDev->LogicToPixel( rPos ); |
2509 | 0 | Size aSize = GetSizePixel(); |
2510 | 0 | Size aImageSize = pDev->LogicToPixel( Size( 300, 300 ), aResMapMode ); |
2511 | 0 | Size aBrd1Size = pDev->LogicToPixel( Size( 20, 20 ), aResMapMode ); |
2512 | 0 | Size aBrd2Size = pDev->LogicToPixel( Size( 60, 60 ), aResMapMode ); |
2513 | 0 | vcl::Font aFont = GetDrawPixelFont( pDev ); |
2514 | 0 | tools::Rectangle aStateRect; |
2515 | 0 | tools::Rectangle aMouseRect; |
2516 | |
|
2517 | 0 | aImageSize.setWidth( CalcZoom( aImageSize.Width() ) ); |
2518 | 0 | aImageSize.setHeight( CalcZoom( aImageSize.Height() ) ); |
2519 | 0 | aBrd1Size.setWidth( CalcZoom( aBrd1Size.Width() ) ); |
2520 | 0 | aBrd1Size.setHeight( CalcZoom( aBrd1Size.Height() ) ); |
2521 | 0 | aBrd2Size.setWidth( CalcZoom( aBrd2Size.Width() ) ); |
2522 | 0 | aBrd2Size.setHeight( CalcZoom( aBrd2Size.Height() ) ); |
2523 | |
|
2524 | 0 | if ( !aBrd1Size.Width() ) |
2525 | 0 | aBrd1Size.setWidth( 1 ); |
2526 | 0 | if ( !aBrd1Size.Height() ) |
2527 | 0 | aBrd1Size.setHeight( 1 ); |
2528 | 0 | if ( !aBrd2Size.Width() ) |
2529 | 0 | aBrd2Size.setWidth( 1 ); |
2530 | 0 | if ( !aBrd2Size.Height() ) |
2531 | 0 | aBrd2Size.setHeight( 1 ); |
2532 | |
|
2533 | 0 | auto popIt = pDev->ScopedPush(); |
2534 | 0 | pDev->SetMapMode(); |
2535 | 0 | pDev->SetFont( aFont ); |
2536 | 0 | if ( nFlags & SystemTextColorFlags::Mono ) |
2537 | 0 | pDev->SetTextColor( COL_BLACK ); |
2538 | 0 | else |
2539 | 0 | pDev->SetTextColor( GetTextColor() ); |
2540 | 0 | pDev->SetTextFillColor(); |
2541 | |
|
2542 | 0 | ImplDraw( pDev, nFlags, aPos, aSize, |
2543 | 0 | aImageSize, aStateRect, aMouseRect ); |
2544 | |
|
2545 | 0 | Point aCenterPos = aStateRect.Center(); |
2546 | 0 | tools::Long nRadX = aImageSize.Width()/2; |
2547 | 0 | tools::Long nRadY = aImageSize.Height()/2; |
2548 | |
|
2549 | 0 | pDev->SetLineColor(); |
2550 | 0 | pDev->SetFillColor( COL_BLACK ); |
2551 | 0 | pDev->DrawPolygon( tools::Polygon( aCenterPos, nRadX, nRadY ) ); |
2552 | 0 | nRadX -= aBrd1Size.Width(); |
2553 | 0 | nRadY -= aBrd1Size.Height(); |
2554 | 0 | pDev->SetFillColor( COL_WHITE ); |
2555 | 0 | pDev->DrawPolygon( tools::Polygon( aCenterPos, nRadX, nRadY ) ); |
2556 | 0 | if ( mbChecked ) |
2557 | 0 | { |
2558 | 0 | nRadX -= aBrd1Size.Width(); |
2559 | 0 | nRadY -= aBrd1Size.Height(); |
2560 | 0 | if ( !nRadX ) |
2561 | 0 | nRadX = 1; |
2562 | 0 | if ( !nRadY ) |
2563 | 0 | nRadY = 1; |
2564 | 0 | pDev->SetFillColor( COL_BLACK ); |
2565 | 0 | pDev->DrawPolygon( tools::Polygon( aCenterPos, nRadX, nRadY ) ); |
2566 | 0 | } |
2567 | 0 | } |
2568 | 0 | else |
2569 | 0 | { |
2570 | 0 | OSL_FAIL( "RadioButton::Draw() - not implemented for RadioButton with Image" ); |
2571 | 0 | } |
2572 | 0 | } |
2573 | | |
2574 | | void RadioButton::Resize() |
2575 | 0 | { |
2576 | 0 | Control::Resize(); |
2577 | 0 | Invalidate(); |
2578 | 0 | } |
2579 | | |
2580 | | void RadioButton::GetFocus() |
2581 | 0 | { |
2582 | 0 | ShowFocus( ImplGetFocusRect() ); |
2583 | 0 | SetInputContext( InputContext( GetFont() ) ); |
2584 | 0 | Button::GetFocus(); |
2585 | 0 | } |
2586 | | |
2587 | | void RadioButton::LoseFocus() |
2588 | 0 | { |
2589 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
2590 | 0 | { |
2591 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
2592 | 0 | Invalidate(); |
2593 | 0 | } |
2594 | |
|
2595 | 0 | HideFocus(); |
2596 | 0 | Button::LoseFocus(); |
2597 | 0 | } |
2598 | | |
2599 | | void RadioButton::StateChanged( StateChangedType nType ) |
2600 | 0 | { |
2601 | 0 | Button::StateChanged( nType ); |
2602 | |
|
2603 | 0 | if ( nType == StateChangedType::State ) |
2604 | 0 | { |
2605 | 0 | if ( IsReallyVisible() && IsUpdateMode() ) |
2606 | 0 | Invalidate( maStateRect ); |
2607 | 0 | } |
2608 | 0 | else if ( (nType == StateChangedType::Enable) || |
2609 | 0 | (nType == StateChangedType::Text) || |
2610 | 0 | (nType == StateChangedType::Data) || |
2611 | 0 | (nType == StateChangedType::UpdateMode) ) |
2612 | 0 | { |
2613 | 0 | if ( IsUpdateMode() ) |
2614 | 0 | Invalidate(); |
2615 | 0 | } |
2616 | 0 | else if ( nType == StateChangedType::Style ) |
2617 | 0 | { |
2618 | 0 | SetStyle( ImplInitStyle( GetWindow( GetWindowType::Prev ), GetStyle() ) ); |
2619 | |
|
2620 | 0 | if ( (GetPrevStyle() & RADIOBUTTON_VIEW_STYLE) != |
2621 | 0 | (GetStyle() & RADIOBUTTON_VIEW_STYLE) ) |
2622 | 0 | { |
2623 | 0 | if ( IsUpdateMode() ) |
2624 | 0 | Invalidate(); |
2625 | 0 | } |
2626 | 0 | } |
2627 | 0 | else if ( (nType == StateChangedType::Zoom) || |
2628 | 0 | (nType == StateChangedType::ControlFont) ) |
2629 | 0 | { |
2630 | 0 | ImplInitSettings( false ); |
2631 | 0 | Invalidate(); |
2632 | 0 | } |
2633 | 0 | else if ( nType == StateChangedType::ControlForeground ) |
2634 | 0 | { |
2635 | 0 | ImplInitSettings( false ); |
2636 | 0 | Invalidate(); |
2637 | 0 | } |
2638 | 0 | else if ( nType == StateChangedType::ControlBackground ) |
2639 | 0 | { |
2640 | 0 | ImplInitSettings( true ); |
2641 | 0 | Invalidate(); |
2642 | 0 | } |
2643 | 0 | } |
2644 | | |
2645 | | void RadioButton::DataChanged( const DataChangedEvent& rDCEvt ) |
2646 | 0 | { |
2647 | 0 | Button::DataChanged( rDCEvt ); |
2648 | |
|
2649 | 0 | if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) || |
2650 | 0 | (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) || |
2651 | 0 | ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && |
2652 | 0 | (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) ) |
2653 | 0 | { |
2654 | 0 | ImplInitSettings( true ); |
2655 | 0 | Invalidate(); |
2656 | 0 | } |
2657 | 0 | } |
2658 | | |
2659 | | bool RadioButton::PreNotify( NotifyEvent& rNEvt ) |
2660 | 0 | { |
2661 | 0 | if( rNEvt.GetType() == NotifyEventType::MOUSEMOVE ) |
2662 | 0 | { |
2663 | 0 | const MouseEvent* pMouseEvt = rNEvt.GetMouseEvent(); |
2664 | 0 | if( pMouseEvt && !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() ) |
2665 | 0 | { |
2666 | | // trigger redraw if mouse over state has changed |
2667 | 0 | if( IsNativeControlSupported(ControlType::Radiobutton, ControlPart::Entire) ) |
2668 | 0 | { |
2669 | 0 | if (maMouseRect.Contains(GetPointerPosPixel()) != maMouseRect.Contains(GetLastPointerPosPixel()) || |
2670 | 0 | pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) |
2671 | 0 | { |
2672 | 0 | Invalidate( maStateRect ); |
2673 | 0 | } |
2674 | 0 | } |
2675 | 0 | } |
2676 | 0 | } |
2677 | |
|
2678 | 0 | return Button::PreNotify(rNEvt); |
2679 | 0 | } |
2680 | | |
2681 | | void RadioButton::Toggle() |
2682 | 0 | { |
2683 | 0 | ImplCallEventListenersAndHandler( VclEventId::RadiobuttonToggle, [this] () { maToggleHdl.Call(*this); } ); |
2684 | 0 | } |
2685 | | |
2686 | | void RadioButton::SetModeRadioImage( const Image& rImage ) |
2687 | 0 | { |
2688 | 0 | if ( rImage != maImage ) |
2689 | 0 | { |
2690 | 0 | maImage = rImage; |
2691 | 0 | CompatStateChanged( StateChangedType::Data ); |
2692 | 0 | queue_resize(); |
2693 | 0 | } |
2694 | 0 | } |
2695 | | |
2696 | | |
2697 | | void RadioButton::SetState( bool bCheck ) |
2698 | 0 | { |
2699 | | // carry the TabStop flag along correctly |
2700 | 0 | if ( bCheck ) |
2701 | 0 | mpWindowImpl->mnStyle |= WB_TABSTOP; |
2702 | 0 | else |
2703 | 0 | mpWindowImpl->mnStyle &= ~WB_TABSTOP; |
2704 | |
|
2705 | 0 | if ( mbChecked != bCheck ) |
2706 | 0 | { |
2707 | 0 | mbChecked = bCheck; |
2708 | 0 | CompatStateChanged( StateChangedType::State ); |
2709 | 0 | Toggle(); |
2710 | 0 | } |
2711 | 0 | } |
2712 | | |
2713 | | bool RadioButton::set_property(const OUString &rKey, const OUString &rValue) |
2714 | 0 | { |
2715 | 0 | if (rKey == "active") |
2716 | 0 | SetState(toBool(rValue)); |
2717 | 0 | else if (rKey == "image-position") |
2718 | 0 | { |
2719 | 0 | WinBits nBits = GetStyle(); |
2720 | 0 | if (rValue == "left") |
2721 | 0 | { |
2722 | 0 | nBits &= ~(WB_CENTER | WB_RIGHT); |
2723 | 0 | nBits |= WB_LEFT; |
2724 | 0 | } |
2725 | 0 | else if (rValue == "right") |
2726 | 0 | { |
2727 | 0 | nBits &= ~(WB_CENTER | WB_LEFT); |
2728 | 0 | nBits |= WB_RIGHT; |
2729 | 0 | } |
2730 | 0 | else if (rValue == "top") |
2731 | 0 | { |
2732 | 0 | nBits &= ~(WB_VCENTER | WB_BOTTOM); |
2733 | 0 | nBits |= WB_TOP; |
2734 | 0 | } |
2735 | 0 | else if (rValue == "bottom") |
2736 | 0 | { |
2737 | 0 | nBits &= ~(WB_VCENTER | WB_TOP); |
2738 | 0 | nBits |= WB_BOTTOM; |
2739 | 0 | } |
2740 | | //It's rather mad to have to set these bits when there is the other |
2741 | | //image align. Looks like e.g. the radiobuttons etc weren't converted |
2742 | | //over to image align fully. |
2743 | 0 | SetStyle(nBits); |
2744 | | //Deliberate to set the sane ImageAlign property |
2745 | 0 | return Button::set_property(rKey, rValue); |
2746 | 0 | } |
2747 | 0 | else |
2748 | 0 | return Button::set_property(rKey, rValue); |
2749 | 0 | return true; |
2750 | 0 | } |
2751 | | |
2752 | | void RadioButton::Check( bool bCheck ) |
2753 | 0 | { |
2754 | | // TabStop-Flag richtig mitfuehren |
2755 | 0 | if ( bCheck ) |
2756 | 0 | mpWindowImpl->mnStyle |= WB_TABSTOP; |
2757 | 0 | else |
2758 | 0 | mpWindowImpl->mnStyle &= ~WB_TABSTOP; |
2759 | |
|
2760 | 0 | if ( mbChecked == bCheck ) |
2761 | 0 | return; |
2762 | | |
2763 | 0 | mbChecked = bCheck; |
2764 | 0 | VclPtr<vcl::Window> xWindow = this; |
2765 | 0 | CompatStateChanged( StateChangedType::State ); |
2766 | 0 | if ( xWindow->isDisposed() ) |
2767 | 0 | return; |
2768 | 0 | if ( bCheck && mbRadioCheck ) |
2769 | 0 | ImplUncheckAllOther(); |
2770 | 0 | if ( xWindow->isDisposed() ) |
2771 | 0 | return; |
2772 | 0 | Toggle(); |
2773 | 0 | } |
2774 | | |
2775 | | tools::Long Button::ImplGetImageToTextDistance() const |
2776 | 0 | { |
2777 | | // 4 pixels, but take zoom into account, so the text doesn't "jump" relative to surrounding elements, |
2778 | | // which might have been aligned with the text of the check box |
2779 | 0 | return CalcZoom( 4 ); |
2780 | 0 | } |
2781 | | |
2782 | | Size RadioButton::ImplGetRadioImageSize() const |
2783 | 0 | { |
2784 | 0 | Size aSize; |
2785 | 0 | bool bDefaultSize = true; |
2786 | 0 | if( IsNativeControlSupported( ControlType::Radiobutton, ControlPart::Entire ) ) |
2787 | 0 | { |
2788 | 0 | ImplControlValue aControlValue; |
2789 | 0 | tools::Rectangle aCtrlRegion( Point( 0, 0 ), GetSizePixel() ); |
2790 | 0 | tools::Rectangle aBoundingRgn, aContentRgn; |
2791 | | |
2792 | | // get native size of a radio button |
2793 | 0 | if( GetNativeControlRegion( ControlType::Radiobutton, ControlPart::Entire, aCtrlRegion, |
2794 | 0 | ControlState::DEFAULT|ControlState::ENABLED, |
2795 | 0 | aControlValue, |
2796 | 0 | aBoundingRgn, aContentRgn ) ) |
2797 | 0 | { |
2798 | 0 | aSize = aContentRgn.GetSize(); |
2799 | 0 | bDefaultSize = false; |
2800 | 0 | } |
2801 | 0 | } |
2802 | 0 | if( bDefaultSize ) |
2803 | 0 | aSize = GetRadioImage( GetSettings(), DrawButtonFlags::NONE ).GetSizePixel(); |
2804 | 0 | return aSize; |
2805 | 0 | } |
2806 | | |
2807 | | static void LoadThemedImageList(const StyleSettings &rStyleSettings, |
2808 | | std::vector<Image>& rList, const std::vector<OUString> &rResources) |
2809 | 0 | { |
2810 | 0 | Color aColorAry1[6]; |
2811 | 0 | Color aColorAry2[6]; |
2812 | 0 | aColorAry1[0] = Color( 0xC0, 0xC0, 0xC0 ); |
2813 | 0 | aColorAry1[1] = Color( 0xFF, 0xFF, 0x00 ); |
2814 | 0 | aColorAry1[2] = Color( 0xFF, 0xFF, 0xFF ); |
2815 | 0 | aColorAry1[3] = Color( 0x80, 0x80, 0x80 ); |
2816 | 0 | aColorAry1[4] = Color( 0x00, 0x00, 0x00 ); |
2817 | 0 | aColorAry1[5] = Color( 0x00, 0xFF, 0x00 ); |
2818 | 0 | aColorAry2[0] = rStyleSettings.GetFaceColor(); |
2819 | 0 | aColorAry2[1] = rStyleSettings.GetWindowColor(); |
2820 | 0 | aColorAry2[2] = rStyleSettings.GetLightColor(); |
2821 | 0 | aColorAry2[3] = rStyleSettings.GetShadowColor(); |
2822 | 0 | aColorAry2[4] = rStyleSettings.GetDarkShadowColor(); |
2823 | 0 | aColorAry2[5] = rStyleSettings.GetWindowTextColor(); |
2824 | |
|
2825 | 0 | static_assert( sizeof(aColorAry1) == sizeof(aColorAry2), "aColorAry1 must match aColorAry2" ); |
2826 | |
|
2827 | 0 | for (const auto &a : rResources) |
2828 | 0 | { |
2829 | 0 | Bitmap aBmp(a); |
2830 | 0 | aBmp.Replace(aColorAry1, aColorAry2, SAL_N_ELEMENTS(aColorAry1), nullptr); |
2831 | 0 | rList.emplace_back(aBmp); |
2832 | 0 | } |
2833 | 0 | } |
2834 | | |
2835 | | Image RadioButton::GetRadioImage( const AllSettings& rSettings, DrawButtonFlags nFlags ) |
2836 | 0 | { |
2837 | 0 | ImplSVData* pSVData = ImplGetSVData(); |
2838 | 0 | const StyleSettings& rStyleSettings = rSettings.GetStyleSettings(); |
2839 | 0 | sal_uInt16 nStyle = 0; |
2840 | |
|
2841 | 0 | if ( rStyleSettings.GetOptions() & StyleSettingsOptions::Mono ) |
2842 | 0 | nStyle = STYLE_RADIOBUTTON_MONO; |
2843 | |
|
2844 | 0 | if ( pSVData->maCtrlData.maRadioImgList.empty() || |
2845 | 0 | (pSVData->maCtrlData.mnRadioStyle != nStyle) || |
2846 | 0 | (pSVData->maCtrlData.mnLastRadioFColor != rStyleSettings.GetFaceColor()) || |
2847 | 0 | (pSVData->maCtrlData.mnLastRadioWColor != rStyleSettings.GetWindowColor()) || |
2848 | 0 | (pSVData->maCtrlData.mnLastRadioLColor != rStyleSettings.GetLightColor()) ) |
2849 | 0 | { |
2850 | 0 | pSVData->maCtrlData.maRadioImgList.clear(); |
2851 | |
|
2852 | 0 | pSVData->maCtrlData.mnLastRadioFColor = rStyleSettings.GetFaceColor(); |
2853 | 0 | pSVData->maCtrlData.mnLastRadioWColor = rStyleSettings.GetWindowColor(); |
2854 | 0 | pSVData->maCtrlData.mnLastRadioLColor = rStyleSettings.GetLightColor(); |
2855 | |
|
2856 | 0 | std::vector<OUString> aResources; |
2857 | 0 | if (nStyle) |
2858 | 0 | { |
2859 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIOMONO1); |
2860 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIOMONO2); |
2861 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIOMONO3); |
2862 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIOMONO4); |
2863 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIOMONO5); |
2864 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIOMONO6); |
2865 | 0 | } |
2866 | 0 | else |
2867 | 0 | { |
2868 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIO1); |
2869 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIO2); |
2870 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIO3); |
2871 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIO4); |
2872 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIO5); |
2873 | 0 | aResources.emplace_back(SV_RESID_BITMAP_RADIO6); |
2874 | 0 | } |
2875 | 0 | LoadThemedImageList( rStyleSettings, pSVData->maCtrlData.maRadioImgList, aResources); |
2876 | 0 | pSVData->maCtrlData.mnRadioStyle = nStyle; |
2877 | 0 | } |
2878 | |
|
2879 | 0 | sal_uInt16 nIndex; |
2880 | 0 | if ( nFlags & DrawButtonFlags::Disabled ) |
2881 | 0 | { |
2882 | 0 | if ( nFlags & DrawButtonFlags::Checked ) |
2883 | 0 | nIndex = 5; |
2884 | 0 | else |
2885 | 0 | nIndex = 4; |
2886 | 0 | } |
2887 | 0 | else if ( nFlags & DrawButtonFlags::Pressed ) |
2888 | 0 | { |
2889 | 0 | if ( nFlags & DrawButtonFlags::Checked ) |
2890 | 0 | nIndex = 3; |
2891 | 0 | else |
2892 | 0 | nIndex = 2; |
2893 | 0 | } |
2894 | 0 | else |
2895 | 0 | { |
2896 | 0 | if ( nFlags & DrawButtonFlags::Checked ) |
2897 | 0 | nIndex = 1; |
2898 | 0 | else |
2899 | 0 | nIndex = 0; |
2900 | 0 | } |
2901 | 0 | return pSVData->maCtrlData.maRadioImgList[nIndex]; |
2902 | 0 | } |
2903 | | |
2904 | | void RadioButton::ImplAdjustNWFSizes() |
2905 | 0 | { |
2906 | 0 | auto popIt = GetOutDev()->ScopedPush(vcl::PushFlags::MAPMODE); |
2907 | 0 | SetMapMode(MapMode(MapUnit::MapPixel)); |
2908 | |
|
2909 | 0 | ImplControlValue aControlValue; |
2910 | 0 | Size aCurSize( GetSizePixel() ); |
2911 | 0 | tools::Rectangle aCtrlRegion( Point( 0, 0 ), aCurSize ); |
2912 | 0 | tools::Rectangle aBoundingRgn, aContentRgn; |
2913 | | |
2914 | | // get native size of a radiobutton |
2915 | 0 | if( GetNativeControlRegion( ControlType::Radiobutton, ControlPart::Entire, aCtrlRegion, |
2916 | 0 | ControlState::DEFAULT|ControlState::ENABLED, aControlValue, |
2917 | 0 | aBoundingRgn, aContentRgn ) ) |
2918 | 0 | { |
2919 | 0 | Size aSize = aContentRgn.GetSize(); |
2920 | |
|
2921 | 0 | if( aSize.Height() > aCurSize.Height() ) |
2922 | 0 | { |
2923 | 0 | aCurSize.setHeight( aSize.Height() ); |
2924 | 0 | SetSizePixel( aCurSize ); |
2925 | 0 | } |
2926 | 0 | } |
2927 | 0 | } |
2928 | | |
2929 | | Size RadioButton::CalcMinimumSize(tools::Long nMaxWidth) const |
2930 | 0 | { |
2931 | 0 | Size aSize; |
2932 | 0 | if ( !maImage ) |
2933 | 0 | aSize = ImplGetRadioImageSize(); |
2934 | 0 | else |
2935 | 0 | { |
2936 | 0 | aSize = maImage.GetSizePixel(); |
2937 | 0 | aSize.AdjustWidth(8); |
2938 | 0 | aSize.AdjustHeight(8); |
2939 | 0 | } |
2940 | |
|
2941 | 0 | if (Button::HasImage()) |
2942 | 0 | { |
2943 | 0 | Size aImgSize = GetModeImage().GetSizePixel(); |
2944 | 0 | aSize = Size(std::max(aImgSize.Width(), aSize.Width()), |
2945 | 0 | std::max(aImgSize.Height(), aSize.Height())); |
2946 | 0 | } |
2947 | |
|
2948 | 0 | OUString aText = GetText(); |
2949 | 0 | if (!aText.isEmpty()) |
2950 | 0 | { |
2951 | 0 | bool bTopImage = (GetStyle() & WB_TOP) != 0; |
2952 | |
|
2953 | 0 | Size aTextSize = GetTextRect( tools::Rectangle( Point(), Size( nMaxWidth > 0 ? nMaxWidth : 0x7fffffff, 0x7fffffff ) ), |
2954 | 0 | aText, FixedText::ImplGetTextStyle( GetStyle() ) ).GetSize(); |
2955 | |
|
2956 | 0 | aSize.AdjustWidth(2 ); // for focus rect |
2957 | |
|
2958 | 0 | if (!bTopImage) |
2959 | 0 | { |
2960 | 0 | aSize.AdjustWidth(ImplGetImageToTextDistance() ); |
2961 | 0 | aSize.AdjustWidth(aTextSize.Width() ); |
2962 | 0 | if ( aSize.Height() < aTextSize.Height() ) |
2963 | 0 | aSize.setHeight( aTextSize.Height() ); |
2964 | 0 | } |
2965 | 0 | else |
2966 | 0 | { |
2967 | 0 | aSize.AdjustHeight(6 ); |
2968 | 0 | aSize.AdjustHeight(GetTextHeight() ); |
2969 | 0 | if ( aSize.Width() < aTextSize.Width() ) |
2970 | 0 | aSize.setWidth( aTextSize.Width() ); |
2971 | 0 | } |
2972 | 0 | } |
2973 | |
|
2974 | 0 | return CalcWindowSize( aSize ); |
2975 | 0 | } |
2976 | | |
2977 | | Size RadioButton::GetOptimalSize() const |
2978 | 0 | { |
2979 | 0 | return CalcMinimumSize(); |
2980 | 0 | } |
2981 | | |
2982 | | void RadioButton::ShowFocus(const tools::Rectangle& rRect) |
2983 | 0 | { |
2984 | 0 | if (IsNativeControlSupported(ControlType::Radiobutton, ControlPart::Focus)) |
2985 | 0 | { |
2986 | 0 | ImplControlValue aControlValue; |
2987 | 0 | tools::Rectangle aInRect(Point(0, 0), GetSizePixel()); |
2988 | |
|
2989 | 0 | aInRect.SetLeft( rRect.Left() ); // exclude the radio element itself from the focusrect |
2990 | |
|
2991 | 0 | GetOutDev()->DrawNativeControl(ControlType::Radiobutton, ControlPart::Focus, aInRect, |
2992 | 0 | ControlState::FOCUSED, aControlValue, OUString()); |
2993 | 0 | } |
2994 | 0 | Button::ShowFocus(rRect); |
2995 | 0 | } |
2996 | | |
2997 | | void RadioButton::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) |
2998 | 0 | { |
2999 | 0 | Button::DumpAsPropertyTree(rJsonWriter); |
3000 | 0 | rJsonWriter.put("checked", IsChecked()); |
3001 | |
|
3002 | 0 | OUString sGroupId; |
3003 | 0 | std::vector<VclPtr<RadioButton>> aGroup = GetRadioButtonGroup(); |
3004 | 0 | for(const auto& pButton : aGroup) |
3005 | 0 | sGroupId += pButton->get_id(); |
3006 | |
|
3007 | 0 | if (!sGroupId.isEmpty()) |
3008 | 0 | rJsonWriter.put("group", sGroupId); |
3009 | |
|
3010 | 0 | if (!!maImage) |
3011 | 0 | { |
3012 | 0 | SvMemoryStream aOStm(6535, 6535); |
3013 | 0 | if(GraphicConverter::Export(aOStm, maImage.GetBitmap(), ConvertDataFormat::PNG) == ERRCODE_NONE) |
3014 | 0 | { |
3015 | 0 | css::uno::Sequence<sal_Int8> aSeq( static_cast<sal_Int8 const *>(aOStm.GetData()), aOStm.Tell()); |
3016 | 0 | OStringBuffer aBuffer("data:image/png;base64,"); |
3017 | 0 | ::comphelper::Base64::encode(aBuffer, aSeq); |
3018 | 0 | rJsonWriter.put("image", aBuffer); |
3019 | 0 | } |
3020 | 0 | } |
3021 | 0 | } |
3022 | | |
3023 | | FactoryFunction RadioButton::GetUITestFactory() const |
3024 | 0 | { |
3025 | 0 | return RadioButtonUIObject::create; |
3026 | 0 | } |
3027 | | |
3028 | | void CheckBox::ImplInitCheckBoxData() |
3029 | 0 | { |
3030 | 0 | meState = TRISTATE_FALSE; |
3031 | 0 | mbTriState = false; |
3032 | 0 | } |
3033 | | |
3034 | | void CheckBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) |
3035 | 0 | { |
3036 | 0 | nStyle = ImplInitStyle(getPreviousSibling(pParent), nStyle); |
3037 | 0 | Button::ImplInit( pParent, nStyle, nullptr ); |
3038 | |
|
3039 | 0 | ImplInitSettings( true ); |
3040 | 0 | } |
3041 | | |
3042 | | WinBits CheckBox::ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle ) |
3043 | 0 | { |
3044 | 0 | if ( !(nStyle & WB_NOTABSTOP) ) |
3045 | 0 | nStyle |= WB_TABSTOP; |
3046 | 0 | if ( !(nStyle & WB_NOGROUP) && |
3047 | 0 | (!pPrevWindow || (pPrevWindow->GetType() != WindowType::CHECKBOX)) ) |
3048 | 0 | nStyle |= WB_GROUP; |
3049 | 0 | return nStyle; |
3050 | 0 | } |
3051 | | |
3052 | | const vcl::Font& CheckBox::GetCanonicalFont( const StyleSettings& _rStyle ) const |
3053 | 0 | { |
3054 | 0 | return _rStyle.GetRadioCheckFont(); |
3055 | 0 | } |
3056 | | |
3057 | | const Color& CheckBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const |
3058 | 0 | { |
3059 | 0 | return _rStyle.GetRadioCheckTextColor(); |
3060 | 0 | } |
3061 | | |
3062 | | void CheckBox::ImplInitSettings( bool bBackground ) |
3063 | 0 | { |
3064 | 0 | Button::ImplInitSettings(); |
3065 | |
|
3066 | 0 | if ( !bBackground ) |
3067 | 0 | return; |
3068 | | |
3069 | 0 | vcl::Window* pParent = GetParent(); |
3070 | 0 | if ( !IsControlBackground() && |
3071 | 0 | (pParent->IsChildTransparentModeEnabled() || IsNativeControlSupported( ControlType::Checkbox, ControlPart::Entire ) ) ) |
3072 | 0 | { |
3073 | 0 | EnableChildTransparentMode(); |
3074 | 0 | SetParentClipMode( ParentClipMode::NoClip ); |
3075 | 0 | SetPaintTransparent( true ); |
3076 | 0 | SetBackground(); |
3077 | 0 | if( IsNativeControlSupported( ControlType::Checkbox, ControlPart::Entire ) ) |
3078 | 0 | ImplGetWindowImpl()->mbUseNativeFocus = ImplGetSVData()->maNWFData.mbNoFocusRects; |
3079 | 0 | } |
3080 | 0 | else |
3081 | 0 | { |
3082 | 0 | EnableChildTransparentMode( false ); |
3083 | 0 | SetParentClipMode(); |
3084 | 0 | SetPaintTransparent( false ); |
3085 | |
|
3086 | 0 | if ( IsControlBackground() ) |
3087 | 0 | SetBackground( GetControlBackground() ); |
3088 | 0 | else |
3089 | 0 | SetBackground( pParent->GetBackground() ); |
3090 | 0 | } |
3091 | 0 | } |
3092 | | |
3093 | | void CheckBox::ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext) |
3094 | 0 | { |
3095 | 0 | bool bNativeOK = rRenderContext.IsNativeControlSupported(ControlType::Checkbox, ControlPart::Entire); |
3096 | 0 | if (bNativeOK) |
3097 | 0 | { |
3098 | 0 | ImplControlValue aControlValue(meState == TRISTATE_TRUE ? ButtonValue::On : ButtonValue::Off); |
3099 | 0 | tools::Rectangle aCtrlRegion(maStateRect); |
3100 | 0 | ControlState nState = ControlState::NONE; |
3101 | |
|
3102 | 0 | if (HasFocus()) |
3103 | 0 | nState |= ControlState::FOCUSED; |
3104 | 0 | if (GetButtonState() & DrawButtonFlags::Default) |
3105 | 0 | nState |= ControlState::DEFAULT; |
3106 | 0 | if (GetButtonState() & DrawButtonFlags::Pressed) |
3107 | 0 | nState |= ControlState::PRESSED; |
3108 | 0 | if (IsEnabled()) |
3109 | 0 | nState |= ControlState::ENABLED; |
3110 | |
|
3111 | 0 | if (meState == TRISTATE_TRUE) |
3112 | 0 | aControlValue.setTristateVal(ButtonValue::On); |
3113 | 0 | else if (meState == TRISTATE_INDET) |
3114 | 0 | aControlValue.setTristateVal(ButtonValue::Mixed); |
3115 | |
|
3116 | 0 | if (IsMouseOver() && maMouseRect.Contains(GetPointerPosPixel())) |
3117 | 0 | nState |= ControlState::ROLLOVER; |
3118 | |
|
3119 | 0 | bNativeOK = rRenderContext.DrawNativeControl(ControlType::Checkbox, ControlPart::Entire, aCtrlRegion, |
3120 | 0 | nState, aControlValue, OUString()); |
3121 | 0 | } |
3122 | |
|
3123 | 0 | if (bNativeOK) |
3124 | 0 | return; |
3125 | | |
3126 | 0 | DrawButtonFlags nStyle = GetButtonState(); |
3127 | 0 | if (!IsEnabled()) |
3128 | 0 | nStyle |= DrawButtonFlags::Disabled; |
3129 | 0 | if (meState == TRISTATE_INDET) |
3130 | 0 | nStyle |= DrawButtonFlags::DontKnow; |
3131 | 0 | else if (meState == TRISTATE_TRUE) |
3132 | 0 | nStyle |= DrawButtonFlags::Checked; |
3133 | 0 | Image aImage = GetCheckImage(GetSettings(), nStyle); |
3134 | 0 | if (IsZoom()) |
3135 | 0 | rRenderContext.DrawImage(maStateRect.TopLeft(), maStateRect.GetSize(), aImage); |
3136 | 0 | else |
3137 | 0 | rRenderContext.DrawImage(maStateRect.TopLeft(), aImage); |
3138 | 0 | } |
3139 | | |
3140 | | void CheckBox::ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags, |
3141 | | const Point& rPos, const Size& rSize, |
3142 | | const Size& rImageSize, tools::Rectangle& rStateRect, |
3143 | | tools::Rectangle& rMouseRect ) |
3144 | 0 | { |
3145 | 0 | WinBits nWinStyle = GetStyle(); |
3146 | 0 | OUString aText( GetText() ); |
3147 | |
|
3148 | 0 | auto popIt = pDev->ScopedPush(vcl::PushFlags::CLIPREGION | vcl::PushFlags::LINECOLOR); |
3149 | 0 | pDev->IntersectClipRegion( tools::Rectangle( rPos, rSize ) ); |
3150 | |
|
3151 | 0 | if (!aText.isEmpty() || HasImage()) |
3152 | 0 | { |
3153 | 0 | Button::ImplDrawRadioCheck(pDev, nWinStyle, nSystemTextColorFlags, |
3154 | 0 | rPos, rSize, rImageSize, |
3155 | 0 | rStateRect, rMouseRect); |
3156 | 0 | } |
3157 | 0 | else |
3158 | 0 | { |
3159 | 0 | rStateRect.SetLeft( rPos.X() ); |
3160 | 0 | if ( nWinStyle & WB_VCENTER ) |
3161 | 0 | rStateRect.SetTop( rPos.Y()+((rSize.Height()-rImageSize.Height())/2) ); |
3162 | 0 | else if ( nWinStyle & WB_BOTTOM ) |
3163 | 0 | rStateRect.SetTop( rPos.Y()+rSize.Height()-rImageSize.Height() ); |
3164 | 0 | else |
3165 | 0 | rStateRect.SetTop( rPos.Y() ); |
3166 | 0 | rStateRect.SetRight( rStateRect.Left()+rImageSize.Width()-1 ); |
3167 | 0 | rStateRect.SetBottom( rStateRect.Top()+rImageSize.Height()-1 ); |
3168 | | // provide space for focusrect |
3169 | | // note: this assumes that the control's size was adjusted |
3170 | | // accordingly in Get/LoseFocus, so the onscreen position won't change |
3171 | 0 | if( HasFocus() ) |
3172 | 0 | rStateRect.Move( 1, 1 ); |
3173 | 0 | rMouseRect = rStateRect; |
3174 | |
|
3175 | 0 | ImplSetFocusRect( rStateRect ); |
3176 | 0 | } |
3177 | 0 | } |
3178 | | |
3179 | | void CheckBox::ImplDrawCheckBox(vcl::RenderContext& rRenderContext) |
3180 | 0 | { |
3181 | 0 | Size aImageSize = ImplGetCheckImageSize(); |
3182 | 0 | aImageSize.setWidth( CalcZoom( aImageSize.Width() ) ); |
3183 | 0 | aImageSize.setHeight( CalcZoom( aImageSize.Height() ) ); |
3184 | |
|
3185 | 0 | HideFocus(); |
3186 | |
|
3187 | 0 | ImplDraw(&rRenderContext, SystemTextColorFlags::NONE, Point(), GetOutputSizePixel(), |
3188 | 0 | aImageSize, maStateRect, maMouseRect); |
3189 | |
|
3190 | 0 | ImplDrawCheckBoxState(rRenderContext); |
3191 | 0 | if (HasFocus()) |
3192 | 0 | ShowFocus(ImplGetFocusRect()); |
3193 | 0 | } |
3194 | | |
3195 | | void CheckBox::ImplCheck() |
3196 | 0 | { |
3197 | 0 | TriState eNewState; |
3198 | 0 | if ( meState == TRISTATE_FALSE ) |
3199 | 0 | eNewState = TRISTATE_TRUE; |
3200 | 0 | else if ( !mbTriState ) |
3201 | 0 | eNewState = TRISTATE_FALSE; |
3202 | 0 | else if ( meState == TRISTATE_TRUE ) |
3203 | 0 | eNewState = TRISTATE_INDET; |
3204 | 0 | else |
3205 | 0 | eNewState = TRISTATE_FALSE; |
3206 | 0 | meState = eNewState; |
3207 | |
|
3208 | 0 | VclPtr<vcl::Window> xWindow = this; |
3209 | 0 | Invalidate(); |
3210 | 0 | Toggle(); |
3211 | 0 | if ( xWindow->isDisposed() ) |
3212 | 0 | return; |
3213 | 0 | Click(); |
3214 | 0 | } |
3215 | | |
3216 | | CheckBox::CheckBox( vcl::Window* pParent, WinBits nStyle ) : |
3217 | 0 | Button( WindowType::CHECKBOX ) |
3218 | 0 | { |
3219 | 0 | ImplInitCheckBoxData(); |
3220 | 0 | ImplInit( pParent, nStyle ); |
3221 | 0 | } Unexecuted instantiation: CheckBox::CheckBox(vcl::Window*, long) Unexecuted instantiation: CheckBox::CheckBox(vcl::Window*, long) |
3222 | | |
3223 | | rtl::Reference<comphelper::OAccessible> CheckBox::CreateAccessible() |
3224 | 0 | { |
3225 | 0 | return new VCLXAccessibleCheckBox(this); |
3226 | 0 | } |
3227 | | |
3228 | | void CheckBox::MouseButtonDown( const MouseEvent& rMEvt ) |
3229 | 0 | { |
3230 | 0 | if ( rMEvt.IsLeft() && maMouseRect.Contains( rMEvt.GetPosPixel() ) ) |
3231 | 0 | { |
3232 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
3233 | 0 | Invalidate(); |
3234 | 0 | StartTracking(); |
3235 | 0 | return; |
3236 | 0 | } |
3237 | | |
3238 | 0 | Button::MouseButtonDown( rMEvt ); |
3239 | 0 | } |
3240 | | |
3241 | | void CheckBox::Tracking( const TrackingEvent& rTEvt ) |
3242 | 0 | { |
3243 | 0 | if ( rTEvt.IsTrackingEnded() ) |
3244 | 0 | { |
3245 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
3246 | 0 | { |
3247 | 0 | if ( !(GetStyle() & WB_NOPOINTERFOCUS) && !rTEvt.IsTrackingCanceled() ) |
3248 | 0 | GrabFocus(); |
3249 | |
|
3250 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
3251 | | |
3252 | | // do not call click handler if aborted |
3253 | 0 | if ( !rTEvt.IsTrackingCanceled() ) |
3254 | 0 | ImplCheck(); |
3255 | 0 | else |
3256 | 0 | { |
3257 | 0 | Invalidate(); |
3258 | 0 | } |
3259 | 0 | } |
3260 | 0 | } |
3261 | 0 | else |
3262 | 0 | { |
3263 | 0 | if ( maMouseRect.Contains( rTEvt.GetMouseEvent().GetPosPixel() ) ) |
3264 | 0 | { |
3265 | 0 | if ( !(GetButtonState() & DrawButtonFlags::Pressed) ) |
3266 | 0 | { |
3267 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
3268 | 0 | Invalidate(); |
3269 | 0 | } |
3270 | 0 | } |
3271 | 0 | else |
3272 | 0 | { |
3273 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
3274 | 0 | { |
3275 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
3276 | 0 | Invalidate(); |
3277 | 0 | } |
3278 | 0 | } |
3279 | 0 | } |
3280 | 0 | } |
3281 | | |
3282 | | void CheckBox::KeyInput( const KeyEvent& rKEvt ) |
3283 | 0 | { |
3284 | 0 | vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); |
3285 | |
|
3286 | 0 | if ( !aKeyCode.GetModifier() && (aKeyCode.GetCode() == KEY_SPACE) ) |
3287 | 0 | { |
3288 | 0 | if ( !(GetButtonState() & DrawButtonFlags::Pressed) ) |
3289 | 0 | { |
3290 | 0 | GetButtonState() |= DrawButtonFlags::Pressed; |
3291 | 0 | Invalidate(); |
3292 | 0 | } |
3293 | 0 | } |
3294 | 0 | else if ( (GetButtonState() & DrawButtonFlags::Pressed) && (aKeyCode.GetCode() == KEY_ESCAPE) ) |
3295 | 0 | { |
3296 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
3297 | 0 | Invalidate(); |
3298 | 0 | } |
3299 | 0 | else |
3300 | 0 | Button::KeyInput( rKEvt ); |
3301 | 0 | } |
3302 | | |
3303 | | void CheckBox::KeyUp( const KeyEvent& rKEvt ) |
3304 | 0 | { |
3305 | 0 | vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); |
3306 | |
|
3307 | 0 | if ( (GetButtonState() & DrawButtonFlags::Pressed) && (aKeyCode.GetCode() == KEY_SPACE) ) |
3308 | 0 | { |
3309 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
3310 | 0 | ImplCheck(); |
3311 | 0 | } |
3312 | 0 | else |
3313 | 0 | Button::KeyUp( rKEvt ); |
3314 | 0 | } |
3315 | | |
3316 | | void CheckBox::FillLayoutData() const |
3317 | 0 | { |
3318 | 0 | mxLayoutData.emplace(); |
3319 | 0 | const_cast<CheckBox*>(this)->Invalidate(); |
3320 | 0 | } |
3321 | | |
3322 | | void CheckBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) |
3323 | 0 | { |
3324 | 0 | ImplDrawCheckBox(rRenderContext); |
3325 | 0 | } |
3326 | | |
3327 | | void CheckBox::Draw( OutputDevice* pDev, const Point& rPos, |
3328 | | SystemTextColorFlags nFlags ) |
3329 | 0 | { |
3330 | 0 | MapMode aResMapMode( MapUnit::Map100thMM ); |
3331 | 0 | Point aPos = pDev->LogicToPixel( rPos ); |
3332 | 0 | Size aSize = GetSizePixel(); |
3333 | 0 | Size aImageSize = pDev->LogicToPixel( Size( 300, 300 ), aResMapMode ); |
3334 | 0 | Size aBrd1Size = pDev->LogicToPixel( Size( 20, 20 ), aResMapMode ); |
3335 | 0 | Size aBrd2Size = pDev->LogicToPixel( Size( 30, 30 ), aResMapMode ); |
3336 | 0 | tools::Long nCheckWidth = pDev->LogicToPixel( Size( 20, 20 ), aResMapMode ).Width(); |
3337 | 0 | vcl::Font aFont = GetDrawPixelFont( pDev ); |
3338 | 0 | tools::Rectangle aStateRect; |
3339 | 0 | tools::Rectangle aMouseRect; |
3340 | |
|
3341 | 0 | aImageSize.setWidth( CalcZoom( aImageSize.Width() ) ); |
3342 | 0 | aImageSize.setHeight( CalcZoom( aImageSize.Height() ) ); |
3343 | 0 | aBrd1Size.setWidth( CalcZoom( aBrd1Size.Width() ) ); |
3344 | 0 | aBrd1Size.setHeight( CalcZoom( aBrd1Size.Height() ) ); |
3345 | 0 | aBrd2Size.setWidth( CalcZoom( aBrd2Size.Width() ) ); |
3346 | 0 | aBrd2Size.setHeight( CalcZoom( aBrd2Size.Height() ) ); |
3347 | |
|
3348 | 0 | if ( !aBrd1Size.Width() ) |
3349 | 0 | aBrd1Size.setWidth( 1 ); |
3350 | 0 | if ( !aBrd1Size.Height() ) |
3351 | 0 | aBrd1Size.setHeight( 1 ); |
3352 | 0 | if ( !aBrd2Size.Width() ) |
3353 | 0 | aBrd2Size.setWidth( 1 ); |
3354 | 0 | if ( !aBrd2Size.Height() ) |
3355 | 0 | aBrd2Size.setHeight( 1 ); |
3356 | 0 | if ( !nCheckWidth ) |
3357 | 0 | nCheckWidth = 1; |
3358 | |
|
3359 | 0 | auto popIt = pDev->ScopedPush(); |
3360 | 0 | pDev->SetMapMode(); |
3361 | 0 | pDev->SetFont( aFont ); |
3362 | 0 | if ( nFlags & SystemTextColorFlags::Mono ) |
3363 | 0 | pDev->SetTextColor( COL_BLACK ); |
3364 | 0 | else |
3365 | 0 | pDev->SetTextColor( GetTextColor() ); |
3366 | 0 | pDev->SetTextFillColor(); |
3367 | |
|
3368 | 0 | ImplDraw( pDev, nFlags, aPos, aSize, |
3369 | 0 | aImageSize, aStateRect, aMouseRect ); |
3370 | |
|
3371 | 0 | pDev->SetLineColor(); |
3372 | 0 | pDev->SetFillColor( COL_BLACK ); |
3373 | 0 | pDev->DrawRect( aStateRect ); |
3374 | 0 | aStateRect.AdjustLeft(aBrd1Size.Width() ); |
3375 | 0 | aStateRect.AdjustTop(aBrd1Size.Height() ); |
3376 | 0 | aStateRect.AdjustRight( -(aBrd1Size.Width()) ); |
3377 | 0 | aStateRect.AdjustBottom( -(aBrd1Size.Height()) ); |
3378 | 0 | if ( meState == TRISTATE_INDET ) |
3379 | 0 | pDev->SetFillColor( COL_LIGHTGRAY ); |
3380 | 0 | else |
3381 | 0 | pDev->SetFillColor( COL_WHITE ); |
3382 | 0 | pDev->DrawRect( aStateRect ); |
3383 | |
|
3384 | 0 | if ( meState == TRISTATE_TRUE ) |
3385 | 0 | { |
3386 | 0 | aStateRect.AdjustLeft(aBrd2Size.Width() ); |
3387 | 0 | aStateRect.AdjustTop(aBrd2Size.Height() ); |
3388 | 0 | aStateRect.AdjustRight( -(aBrd2Size.Width()) ); |
3389 | 0 | aStateRect.AdjustBottom( -(aBrd2Size.Height()) ); |
3390 | 0 | Point aPos11( aStateRect.TopLeft() ); |
3391 | 0 | Point aPos12( aStateRect.BottomRight() ); |
3392 | 0 | Point aPos21( aStateRect.TopRight() ); |
3393 | 0 | Point aPos22( aStateRect.BottomLeft() ); |
3394 | 0 | Point aTempPos11( aPos11 ); |
3395 | 0 | Point aTempPos12( aPos12 ); |
3396 | 0 | Point aTempPos21( aPos21 ); |
3397 | 0 | Point aTempPos22( aPos22 ); |
3398 | 0 | pDev->SetLineColor( COL_BLACK ); |
3399 | 0 | tools::Long nDX = 0; |
3400 | 0 | for ( tools::Long i = 0; i < nCheckWidth; i++ ) |
3401 | 0 | { |
3402 | 0 | if ( !(i % 2) ) |
3403 | 0 | { |
3404 | 0 | aTempPos11.setX( aPos11.X()+nDX ); |
3405 | 0 | aTempPos12.setX( aPos12.X()+nDX ); |
3406 | 0 | aTempPos21.setX( aPos21.X()+nDX ); |
3407 | 0 | aTempPos22.setX( aPos22.X()+nDX ); |
3408 | 0 | } |
3409 | 0 | else |
3410 | 0 | { |
3411 | 0 | nDX++; |
3412 | 0 | aTempPos11.setX( aPos11.X()-nDX ); |
3413 | 0 | aTempPos12.setX( aPos12.X()-nDX ); |
3414 | 0 | aTempPos21.setX( aPos21.X()-nDX ); |
3415 | 0 | aTempPos22.setX( aPos22.X()-nDX ); |
3416 | 0 | } |
3417 | 0 | pDev->DrawLine( aTempPos11, aTempPos12 ); |
3418 | 0 | pDev->DrawLine( aTempPos21, aTempPos22 ); |
3419 | 0 | } |
3420 | 0 | } |
3421 | 0 | } |
3422 | | |
3423 | | void CheckBox::Resize() |
3424 | 0 | { |
3425 | 0 | Control::Resize(); |
3426 | 0 | Invalidate(); |
3427 | 0 | } |
3428 | | |
3429 | | void CheckBox::GetFocus() |
3430 | 0 | { |
3431 | 0 | if (GetText().isEmpty()) |
3432 | 0 | { |
3433 | | // increase button size to have space for focus rect |
3434 | | // checkboxes without text will draw focusrect around the check |
3435 | | // See CheckBox::ImplDraw() |
3436 | 0 | Point aPos( GetPosPixel() ); |
3437 | 0 | Size aSize( GetSizePixel() ); |
3438 | 0 | aPos.Move(-1,-1); |
3439 | 0 | aSize.AdjustHeight(2 ); |
3440 | 0 | aSize.AdjustWidth(2 ); |
3441 | 0 | setPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() ); |
3442 | 0 | Invalidate(); |
3443 | | // Trigger drawing to initialize the mouse rectangle, otherwise the mouse button down |
3444 | | // handler would ignore the mouse event. |
3445 | 0 | PaintImmediately(); |
3446 | 0 | } |
3447 | 0 | else |
3448 | 0 | ShowFocus( ImplGetFocusRect() ); |
3449 | |
|
3450 | 0 | SetInputContext( InputContext( GetFont() ) ); |
3451 | 0 | Button::GetFocus(); |
3452 | 0 | } |
3453 | | |
3454 | | void CheckBox::LoseFocus() |
3455 | 0 | { |
3456 | 0 | if ( GetButtonState() & DrawButtonFlags::Pressed ) |
3457 | 0 | { |
3458 | 0 | GetButtonState() &= ~DrawButtonFlags::Pressed; |
3459 | 0 | Invalidate(); |
3460 | 0 | } |
3461 | |
|
3462 | 0 | HideFocus(); |
3463 | 0 | Button::LoseFocus(); |
3464 | |
|
3465 | 0 | if (GetText().isEmpty()) |
3466 | 0 | { |
3467 | | // decrease button size again (see GetFocus()) |
3468 | | // checkboxes without text will draw focusrect around the check |
3469 | 0 | Point aPos( GetPosPixel() ); |
3470 | 0 | Size aSize( GetSizePixel() ); |
3471 | 0 | aPos.Move(1,1); |
3472 | 0 | aSize.AdjustHeight( -2 ); |
3473 | 0 | aSize.AdjustWidth( -2 ); |
3474 | 0 | setPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() ); |
3475 | 0 | Invalidate(); |
3476 | 0 | } |
3477 | 0 | } |
3478 | | |
3479 | | void CheckBox::StateChanged( StateChangedType nType ) |
3480 | 0 | { |
3481 | 0 | Button::StateChanged( nType ); |
3482 | |
|
3483 | 0 | if ( nType == StateChangedType::State ) |
3484 | 0 | { |
3485 | 0 | if ( IsReallyVisible() && IsUpdateMode() ) |
3486 | 0 | Invalidate( maStateRect ); |
3487 | 0 | } |
3488 | 0 | else if ( (nType == StateChangedType::Enable) || |
3489 | 0 | (nType == StateChangedType::Text) || |
3490 | 0 | (nType == StateChangedType::Data) || |
3491 | 0 | (nType == StateChangedType::UpdateMode) ) |
3492 | 0 | { |
3493 | 0 | if ( IsUpdateMode() ) |
3494 | 0 | Invalidate(); |
3495 | 0 | } |
3496 | 0 | else if ( nType == StateChangedType::Style ) |
3497 | 0 | { |
3498 | 0 | SetStyle( ImplInitStyle( GetWindow( GetWindowType::Prev ), GetStyle() ) ); |
3499 | |
|
3500 | 0 | if ( (GetPrevStyle() & CHECKBOX_VIEW_STYLE) != |
3501 | 0 | (GetStyle() & CHECKBOX_VIEW_STYLE) ) |
3502 | 0 | { |
3503 | 0 | if ( IsUpdateMode() ) |
3504 | 0 | Invalidate(); |
3505 | 0 | } |
3506 | 0 | } |
3507 | 0 | else if ( (nType == StateChangedType::Zoom) || |
3508 | 0 | (nType == StateChangedType::ControlFont) ) |
3509 | 0 | { |
3510 | 0 | ImplInitSettings( false ); |
3511 | 0 | Invalidate(); |
3512 | 0 | } |
3513 | 0 | else if ( nType == StateChangedType::ControlForeground ) |
3514 | 0 | { |
3515 | 0 | ImplInitSettings( false ); |
3516 | 0 | Invalidate(); |
3517 | 0 | } |
3518 | 0 | else if ( nType == StateChangedType::ControlBackground ) |
3519 | 0 | { |
3520 | 0 | ImplInitSettings( true ); |
3521 | 0 | Invalidate(); |
3522 | 0 | } |
3523 | 0 | } |
3524 | | |
3525 | | void CheckBox::DataChanged( const DataChangedEvent& rDCEvt ) |
3526 | 0 | { |
3527 | 0 | Button::DataChanged( rDCEvt ); |
3528 | |
|
3529 | 0 | if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) || |
3530 | 0 | (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) || |
3531 | 0 | ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && |
3532 | 0 | (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) ) |
3533 | 0 | { |
3534 | 0 | ImplInitSettings( true ); |
3535 | 0 | Invalidate(); |
3536 | 0 | } |
3537 | 0 | } |
3538 | | |
3539 | | bool CheckBox::PreNotify( NotifyEvent& rNEvt ) |
3540 | 0 | { |
3541 | 0 | if( rNEvt.GetType() == NotifyEventType::MOUSEMOVE ) |
3542 | 0 | { |
3543 | 0 | const MouseEvent* pMouseEvt = rNEvt.GetMouseEvent(); |
3544 | 0 | if( pMouseEvt && !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() ) |
3545 | 0 | { |
3546 | | // trigger redraw if mouse over state has changed |
3547 | 0 | if( IsNativeControlSupported(ControlType::Checkbox, ControlPart::Entire) ) |
3548 | 0 | { |
3549 | 0 | if (maMouseRect.Contains(GetPointerPosPixel()) != maMouseRect.Contains(GetLastPointerPosPixel()) || |
3550 | 0 | pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) |
3551 | 0 | { |
3552 | 0 | Invalidate( maStateRect ); |
3553 | 0 | } |
3554 | 0 | } |
3555 | 0 | } |
3556 | 0 | } |
3557 | |
|
3558 | 0 | return Button::PreNotify(rNEvt); |
3559 | 0 | } |
3560 | | |
3561 | | void CheckBox::Toggle() |
3562 | 0 | { |
3563 | 0 | ImplCallEventListenersAndHandler( VclEventId::CheckboxToggle, [this] () { maToggleHdl.Call(*this); } ); |
3564 | 0 | } |
3565 | | |
3566 | | void CheckBox::SetState( TriState eState ) |
3567 | 0 | { |
3568 | 0 | if ( !mbTriState && (eState == TRISTATE_INDET) ) |
3569 | 0 | eState = TRISTATE_FALSE; |
3570 | |
|
3571 | 0 | if ( meState != eState ) |
3572 | 0 | { |
3573 | 0 | meState = eState; |
3574 | 0 | StateChanged( StateChangedType::State ); |
3575 | 0 | Toggle(); |
3576 | 0 | } |
3577 | 0 | } |
3578 | | |
3579 | | bool CheckBox::set_property(const OUString &rKey, const OUString &rValue) |
3580 | 0 | { |
3581 | 0 | if (rKey == "active") |
3582 | 0 | SetState(toBool(rValue) ? TRISTATE_TRUE : TRISTATE_FALSE); |
3583 | 0 | else |
3584 | 0 | return Button::set_property(rKey, rValue); |
3585 | 0 | return true; |
3586 | 0 | } |
3587 | | |
3588 | | void CheckBox::EnableTriState( bool bTriState ) |
3589 | 0 | { |
3590 | 0 | if ( mbTriState != bTriState ) |
3591 | 0 | { |
3592 | 0 | mbTriState = bTriState; |
3593 | |
|
3594 | 0 | if ( !bTriState && (meState == TRISTATE_INDET) ) |
3595 | 0 | SetState( TRISTATE_FALSE ); |
3596 | 0 | } |
3597 | 0 | } |
3598 | | |
3599 | | Size CheckBox::ImplGetCheckImageSize() const |
3600 | 0 | { |
3601 | 0 | Size aSize; |
3602 | 0 | bool bDefaultSize = true; |
3603 | 0 | if( IsNativeControlSupported( ControlType::Checkbox, ControlPart::Entire ) ) |
3604 | 0 | { |
3605 | 0 | ImplControlValue aControlValue; |
3606 | 0 | tools::Rectangle aCtrlRegion( Point( 0, 0 ), GetSizePixel() ); |
3607 | 0 | tools::Rectangle aBoundingRgn, aContentRgn; |
3608 | | |
3609 | | // get native size of a check box |
3610 | 0 | if( GetNativeControlRegion( ControlType::Checkbox, ControlPart::Entire, aCtrlRegion, |
3611 | 0 | ControlState::DEFAULT|ControlState::ENABLED, |
3612 | 0 | aControlValue, |
3613 | 0 | aBoundingRgn, aContentRgn ) ) |
3614 | 0 | { |
3615 | 0 | aSize = aContentRgn.GetSize(); |
3616 | 0 | bDefaultSize = false; |
3617 | 0 | } |
3618 | 0 | } |
3619 | 0 | if( bDefaultSize ) |
3620 | 0 | aSize = GetCheckImage( GetSettings(), DrawButtonFlags::NONE ).GetSizePixel(); |
3621 | 0 | return aSize; |
3622 | 0 | } |
3623 | | |
3624 | | Image CheckBox::GetCheckImage( const AllSettings& rSettings, DrawButtonFlags nFlags ) |
3625 | 0 | { |
3626 | 0 | ImplSVData* pSVData = ImplGetSVData(); |
3627 | 0 | const StyleSettings& rStyleSettings = rSettings.GetStyleSettings(); |
3628 | 0 | sal_uInt16 nStyle = 0; |
3629 | |
|
3630 | 0 | if ( rStyleSettings.GetOptions() & StyleSettingsOptions::Mono ) |
3631 | 0 | nStyle = STYLE_CHECKBOX_MONO; |
3632 | |
|
3633 | 0 | if ( pSVData->maCtrlData.maCheckImgList.empty() || |
3634 | 0 | (pSVData->maCtrlData.mnCheckStyle != nStyle) || |
3635 | 0 | (pSVData->maCtrlData.mnLastCheckFColor != rStyleSettings.GetFaceColor()) || |
3636 | 0 | (pSVData->maCtrlData.mnLastCheckWColor != rStyleSettings.GetWindowColor()) || |
3637 | 0 | (pSVData->maCtrlData.mnLastCheckLColor != rStyleSettings.GetLightColor()) ) |
3638 | 0 | { |
3639 | 0 | pSVData->maCtrlData.maCheckImgList.clear(); |
3640 | |
|
3641 | 0 | pSVData->maCtrlData.mnLastCheckFColor = rStyleSettings.GetFaceColor(); |
3642 | 0 | pSVData->maCtrlData.mnLastCheckWColor = rStyleSettings.GetWindowColor(); |
3643 | 0 | pSVData->maCtrlData.mnLastCheckLColor = rStyleSettings.GetLightColor(); |
3644 | |
|
3645 | 0 | std::vector<OUString> aResources; |
3646 | 0 | if (nStyle) |
3647 | 0 | { |
3648 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO1); |
3649 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO2); |
3650 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO3); |
3651 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO4); |
3652 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO5); |
3653 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO6); |
3654 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO7); |
3655 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO8); |
3656 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECKMONO9); |
3657 | 0 | } |
3658 | 0 | else |
3659 | 0 | { |
3660 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK1); |
3661 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK2); |
3662 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK3); |
3663 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK4); |
3664 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK5); |
3665 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK6); |
3666 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK7); |
3667 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK8); |
3668 | 0 | aResources.emplace_back(SV_RESID_BITMAP_CHECK9); |
3669 | 0 | } |
3670 | 0 | LoadThemedImageList(rStyleSettings, pSVData->maCtrlData.maCheckImgList, aResources); |
3671 | 0 | pSVData->maCtrlData.mnCheckStyle = nStyle; |
3672 | 0 | } |
3673 | |
|
3674 | 0 | sal_uInt16 nIndex; |
3675 | 0 | if ( nFlags & DrawButtonFlags::Disabled ) |
3676 | 0 | { |
3677 | 0 | if ( nFlags & DrawButtonFlags::DontKnow ) |
3678 | 0 | nIndex = 8; |
3679 | 0 | else if ( nFlags & DrawButtonFlags::Checked ) |
3680 | 0 | nIndex = 5; |
3681 | 0 | else |
3682 | 0 | nIndex = 4; |
3683 | 0 | } |
3684 | 0 | else if ( nFlags & DrawButtonFlags::Pressed ) |
3685 | 0 | { |
3686 | 0 | if ( nFlags & DrawButtonFlags::DontKnow ) |
3687 | 0 | nIndex = 7; |
3688 | 0 | else if ( nFlags & DrawButtonFlags::Checked ) |
3689 | 0 | nIndex = 3; |
3690 | 0 | else |
3691 | 0 | nIndex = 2; |
3692 | 0 | } |
3693 | 0 | else |
3694 | 0 | { |
3695 | 0 | if ( nFlags & DrawButtonFlags::DontKnow ) |
3696 | 0 | nIndex = 6; |
3697 | 0 | else if ( nFlags & DrawButtonFlags::Checked ) |
3698 | 0 | nIndex = 1; |
3699 | 0 | else |
3700 | 0 | nIndex = 0; |
3701 | 0 | } |
3702 | 0 | return pSVData->maCtrlData.maCheckImgList[nIndex]; |
3703 | 0 | } |
3704 | | |
3705 | | void CheckBox::ImplAdjustNWFSizes() |
3706 | 0 | { |
3707 | 0 | auto popIt = GetOutDev()->ScopedPush(vcl::PushFlags::MAPMODE); |
3708 | 0 | SetMapMode(MapMode(MapUnit::MapPixel)); |
3709 | |
|
3710 | 0 | ImplControlValue aControlValue; |
3711 | 0 | Size aCurSize( GetSizePixel() ); |
3712 | 0 | tools::Rectangle aCtrlRegion( Point( 0, 0 ), aCurSize ); |
3713 | 0 | tools::Rectangle aBoundingRgn, aContentRgn; |
3714 | | |
3715 | | // get native size of a radiobutton |
3716 | 0 | if( GetNativeControlRegion( ControlType::Checkbox, ControlPart::Entire, aCtrlRegion, |
3717 | 0 | ControlState::DEFAULT|ControlState::ENABLED, aControlValue, |
3718 | 0 | aBoundingRgn, aContentRgn ) ) |
3719 | 0 | { |
3720 | 0 | Size aSize = aContentRgn.GetSize(); |
3721 | |
|
3722 | 0 | if( aSize.Height() > aCurSize.Height() ) |
3723 | 0 | { |
3724 | 0 | aCurSize.setHeight( aSize.Height() ); |
3725 | 0 | SetSizePixel( aCurSize ); |
3726 | 0 | } |
3727 | 0 | } |
3728 | 0 | } |
3729 | | |
3730 | | Size CheckBox::CalcMinimumSize( tools::Long nMaxWidth ) const |
3731 | 0 | { |
3732 | 0 | Size aSize = ImplGetCheckImageSize(); |
3733 | 0 | nMaxWidth -= aSize.Width(); |
3734 | |
|
3735 | 0 | OUString aText = GetText(); |
3736 | 0 | if (!aText.isEmpty()) |
3737 | 0 | { |
3738 | | // subtract what will be added later |
3739 | 0 | nMaxWidth-=2; |
3740 | 0 | nMaxWidth -= ImplGetImageToTextDistance(); |
3741 | |
|
3742 | 0 | Size aTextSize = GetTextRect( tools::Rectangle( Point(), Size( nMaxWidth > 0 ? nMaxWidth : 0x7fffffff, 0x7fffffff ) ), |
3743 | 0 | aText, FixedText::ImplGetTextStyle( GetStyle() ) ).GetSize(); |
3744 | 0 | aSize.AdjustWidth(2 ); // for focus rect |
3745 | 0 | aSize.AdjustWidth(ImplGetImageToTextDistance() ); |
3746 | 0 | aSize.AdjustWidth(aTextSize.Width() ); |
3747 | 0 | if ( aSize.Height() < aTextSize.Height() ) |
3748 | 0 | aSize.setHeight( aTextSize.Height() ); |
3749 | 0 | } |
3750 | 0 | else |
3751 | 0 | { |
3752 | | // is this still correct ? since the checkbox now |
3753 | | // shows a focus rect it should be 2 pixels wider and longer |
3754 | | /* since otherwise the controls in the Writer hang too far up |
3755 | | aSize.Width() += 2; |
3756 | | aSize.Height() += 2; |
3757 | | */ |
3758 | 0 | } |
3759 | |
|
3760 | 0 | return CalcWindowSize( aSize ); |
3761 | 0 | } |
3762 | | |
3763 | | Size CheckBox::GetOptimalSize() const |
3764 | 0 | { |
3765 | 0 | int nWidthRequest(get_width_request()); |
3766 | 0 | return CalcMinimumSize(nWidthRequest != -1 ? nWidthRequest : 0); |
3767 | 0 | } |
3768 | | |
3769 | | void CheckBox::ShowFocus(const tools::Rectangle& rRect) |
3770 | 0 | { |
3771 | 0 | if (IsNativeControlSupported(ControlType::Checkbox, ControlPart::Focus)) |
3772 | 0 | { |
3773 | 0 | ImplControlValue aControlValue; |
3774 | 0 | tools::Rectangle aInRect(Point(0, 0), GetSizePixel()); |
3775 | |
|
3776 | 0 | aInRect.SetLeft( rRect.Left() ); // exclude the checkbox itself from the focusrect |
3777 | |
|
3778 | 0 | GetOutDev()->DrawNativeControl(ControlType::Checkbox, ControlPart::Focus, aInRect, |
3779 | 0 | ControlState::FOCUSED, aControlValue, OUString()); |
3780 | 0 | } |
3781 | 0 | Button::ShowFocus(rRect); |
3782 | 0 | } |
3783 | | |
3784 | | void CheckBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) |
3785 | 0 | { |
3786 | 0 | Button::DumpAsPropertyTree(rJsonWriter); |
3787 | 0 | rJsonWriter.put("checked", IsChecked()); |
3788 | 0 | } |
3789 | | |
3790 | | FactoryFunction CheckBox::GetUITestFactory() const |
3791 | 0 | { |
3792 | 0 | return CheckBoxUIObject::create; |
3793 | 0 | } |
3794 | | |
3795 | | ImageButton::ImageButton( vcl::Window* pParent, WinBits nStyle ) : |
3796 | 0 | PushButton( pParent, nStyle ) |
3797 | 0 | { |
3798 | 0 | ImplInitStyle(); |
3799 | 0 | } Unexecuted instantiation: ImageButton::ImageButton(vcl::Window*, long) Unexecuted instantiation: ImageButton::ImageButton(vcl::Window*, long) |
3800 | | |
3801 | | void ImageButton::ImplInitStyle() |
3802 | 0 | { |
3803 | 0 | WinBits nStyle = GetStyle(); |
3804 | |
|
3805 | 0 | if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) ) |
3806 | 0 | nStyle |= WB_CENTER; |
3807 | |
|
3808 | 0 | if ( ! ( nStyle & ( WB_TOP | WB_BOTTOM ) ) ) |
3809 | 0 | nStyle |= WB_VCENTER; |
3810 | |
|
3811 | 0 | SetStyle( nStyle ); |
3812 | 0 | } |
3813 | | |
3814 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |