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