LibreOffice Module vcl (master)  1
toolkit/button.hxx
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 #pragma once
20 
21 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
22 #error "don't use this in new code"
23 #endif
24 
25 #include <vcl/button.hxx>
26 
28 {
29 protected:
31 private:
32  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
33 
34  OKButton (const OKButton &) = delete;
35  OKButton & operator= (const OKButton &) = delete;
36 
37 public:
38  explicit OKButton( vcl::Window* pParent, WinBits nStyle = WB_DEFBUTTON );
39 
40  virtual void Click() override;
41 };
42 
44 {
45 protected:
47 private:
48  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
49 
50  CancelButton (const CancelButton &) = delete;
51  CancelButton & operator= (const CancelButton &) = delete;
52 
53 public:
54  explicit CancelButton( vcl::Window* pParent, WinBits nStyle = 0 );
55 
56  virtual void Click() override;
57 };
58 
59 class CloseButton final : public CancelButton
60 {
61 public:
62  explicit CloseButton(vcl::Window* pParent, WinBits nStyle = 0);
63 };
64 
66 {
67 protected:
69 private:
70  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
71 
72  HelpButton( const HelpButton & ) = delete;
73  HelpButton & operator= ( const HelpButton & ) = delete;
74 
75  virtual void StateChanged( StateChangedType nStateChange ) override;
76 
77 public:
78  explicit HelpButton( vcl::Window* pParent, WinBits nStyle = 0 );
79 
80  virtual void Click() override;
81 };
82 
84 {
85 private:
89  bool mbTriState;
91  SAL_DLLPRIVATE void ImplInitCheckBoxData();
92  SAL_DLLPRIVATE static WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle );
93  SAL_DLLPRIVATE void ImplInitSettings( bool bBackground );
94  SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags,
95  const Point& rPos, const Size& rSize,
96  const Size& rImageSize, tools::Rectangle& rStateRect,
97  tools::Rectangle& rMouseRect );
98  SAL_DLLPRIVATE void ImplDrawCheckBox(vcl::RenderContext& rRenderContext );
99  SAL_DLLPRIVATE long ImplGetImageToTextDistance() const;
100  SAL_DLLPRIVATE Size ImplGetCheckImageSize() const;
101 
102  CheckBox(const CheckBox &) = delete;
103  CheckBox& operator= (const CheckBox &) = delete;
104 
105 protected:
107  using Window::ImplInit;
108  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
109  virtual void FillLayoutData() const override;
110  virtual const vcl::Font& GetCanonicalFont( const StyleSettings& _rStyle ) const override;
111  virtual const Color& GetCanonicalTextColor( const StyleSettings& _rStyle ) const override;
112  void ImplAdjustNWFSizes() override;
113 
114  virtual void ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext);
115  SAL_DLLPRIVATE const tools::Rectangle& GetStateRect() const { return maStateRect; }
116  SAL_DLLPRIVATE const tools::Rectangle& GetMouseRect() const { return maMouseRect; }
117 
118 public:
119  SAL_DLLPRIVATE void ImplCheck();
120 public:
121  explicit CheckBox( vcl::Window* pParent, WinBits nStyle = 0 );
122 
123  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
124  virtual void Tracking( const TrackingEvent& rTEvt ) override;
125  virtual void KeyInput( const KeyEvent& rKEvt ) override;
126  virtual void KeyUp( const KeyEvent& rKEvt ) override;
127  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
128  virtual void Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags ) override;
129  virtual void Resize() override;
130  virtual void GetFocus() override;
131  virtual void LoseFocus() override;
132  virtual void StateChanged( StateChangedType nType ) override;
133  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
134  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
135 
136  void Toggle();
137 
138  void SetState( TriState eState );
139  TriState GetState() const { return meState; }
140 
141  void Check( bool bCheck = true )
142  {
143  SetState( bCheck ? TRISTATE_TRUE : TRISTATE_FALSE );
144  }
145 
146  bool IsChecked() const
147  {
148  return (GetState() == TRISTATE_TRUE);
149  }
150 
151  void EnableTriState( bool bTriState = true );
152  bool IsTriStateEnabled() const { return mbTriState; }
153 
154  static Image GetCheckImage( const AllSettings& rSettings, DrawButtonFlags nFlags );
155 
156  Size CalcMinimumSize( long nMaxWidth = 0 ) const;
157  virtual Size GetOptimalSize() const override;
158 
159  void SetToggleHdl( const Link<CheckBox&,void>& rLink ) { maToggleHdl = rLink; }
160 
161  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
162  virtual void ShowFocus(const tools::Rectangle& rRect) override;
163 
165  void DumpAsPropertyTree(tools::JsonWriter&) override;
166 
167  virtual FactoryFunction GetUITestFactory() const override;
168 };
169 
171 {
172 protected:
174 
175 private:
176  SAL_DLLPRIVATE void ImplInitStyle();
177 
178  ImageButton( const ImageButton & ) = delete;
179  ImageButton & operator= ( const ImageButton & ) = delete;
180 
181 public:
182  ImageButton( vcl::Window* pParent, WinBits nStyle = 0 );
183 };
184 
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Rectangle maStateRect
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:414
virtual void ImplAdjustNWFSizes()
Definition: window3.cxx:38
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
Link< CheckBox &, void > maToggleHdl
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
SAL_DLLPRIVATE const tools::Rectangle & GetStateRect() const
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
tools::Rectangle maMouseRect
DrawButtonFlags
Definition: decoview.hxx:68
virtual bool set_property(const OString &rKey, const OUString &rValue) override
Definition: button.cxx:518
virtual const Color & GetCanonicalTextColor(const StyleSettings &_rStyle) const
Definition: ctrl.cxx:413
TRISTATE_TRUE
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: button.cxx:590
StateChangedType
Definition: window.hxx:310
sal_Int64 WinBits
WinBits const WB_DEFBUTTON
virtual void Tracking(const TrackingEvent &rTEvt)
Definition: window.cxx:1927
virtual void Click()
Definition: button.cxx:122
TriState GetState() const
PushButton & operator=(const PushButton &)=delete
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
DrawFlags
Definition: window.hxx:353
bool IsTriStateEnabled() const
virtual FactoryFunction GetUITestFactory() const override
Definition: button.cxx:551
TRISTATE_FALSE
CloseButton(vcl::Window *pParent, WinBits nStyle=0)
Definition: button.cxx:1719
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
bool IsChecked() const
virtual void Draw(::OutputDevice *pDev, const Point &rPos, DrawFlags nFlags)
Definition: window.cxx:1824
void SetToggleHdl(const Link< CheckBox &, void > &rLink)
Button & operator=(const Button &)=delete
TriState meState
static SAL_DLLPRIVATE WinBits ImplInitStyle(const vcl::Window *pPrevWindow, WinBits nStyle)
Definition: button.cxx:601
void Check(bool bCheck=true)
virtual void LoseFocus()
Definition: window.cxx:1850
virtual void ShowFocus(const tools::Rectangle &rRect)
Definition: window2.cxx:49
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1800
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:936
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
virtual void StateChanged(StateChangedType nType) override
Definition: button.cxx:1354
virtual void Resize() override
Definition: ctrl.cxx:74
virtual void GetFocus()
Definition: window.cxx:1836
virtual const vcl::Font & GetCanonicalFont(const StyleSettings &_rStyle) const
Definition: ctrl.cxx:408
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:556
Definition: image.hxx:40
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1019
virtual void KeyUp(const KeyEvent &rKEvt)
Definition: window.cxx:1817
SAL_DLLPRIVATE const tools::Rectangle & GetMouseRect() const
void ImplInitSettings()
Definition: ctrl.cxx:428
TriState
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35