LibreOffice Module vcl (master)  1
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 
20 #ifndef INCLUDED_VCL_BUTTON_HXX
21 #define INCLUDED_VCL_BUTTON_HXX
22 
23 #include <tools/solar.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/image.hxx>
26 #include <vcl/ctrl.hxx>
27 #include <vcl/vclenum.hxx>
28 #include <memory>
29 #include <vector>
30 
31 namespace com::sun::star::frame { struct FeatureStateEvent; }
32 template <class T> class VclPtr;
33 
34 class Color;
36 enum class DrawButtonFlags;
37 
39 {
40 private:
41  std::unique_ptr<ImplCommonButtonData> mpButtonData;
43 
45  OUString maCommand;
46 
47  Button (const Button &) = delete;
48  Button & operator= (const Button &) = delete;
49 public:
50  SAL_DLLPRIVATE DrawTextFlags ImplGetTextStyle( WinBits nWinStyle, DrawFlags nDrawFlags );
51  SAL_DLLPRIVATE void ImplDrawAlignedImage(OutputDevice* pDev, Point& rPos, Size& rSize,
52  sal_uLong nImageSep,
53  DrawTextFlags nTextStyle, tools::Rectangle *pSymbolRect=nullptr, bool bAddImageSep = false );
54  SAL_DLLPRIVATE void ImplSetFocusRect( const tools::Rectangle &rFocusRect );
55  SAL_DLLPRIVATE const tools::Rectangle& ImplGetFocusRect() const;
56  SAL_DLLPRIVATE void ImplSetSymbolAlign( SymbolAlign eAlign );
58  SAL_DLLPRIVATE tools::Long ImplGetSeparatorX() const;
59  SAL_DLLPRIVATE void ImplSetSeparatorX( tools::Long nX );
60 
61 protected:
62  explicit Button( WindowType nType );
63 
64 public:
65  virtual ~Button() override;
66  virtual void dispose() override;
67 
68  virtual void Click();
69 
70  void SetClickHdl( const Link<Button*,void>& rLink ) { maClickHdl = rLink; }
71  const Link<Button*,void>& GetClickHdl() const { return maClickHdl; }
72 
74  void SetCommandHandler(const OUString& aCommand);
75  OUString const & GetCommand() const { return maCommand; }
76 
77  void SetModeImage( const Image& rImage );
78  Image const & GetModeImage( ) const;
79  bool HasImage() const;
80  void SetImageAlign( ImageAlign eAlign );
81  ImageAlign GetImageAlign() const;
82  DrawButtonFlags GetButtonState() const;
83  DrawButtonFlags& GetButtonState();
84 
85 
86  bool IsSmallSymbol() const;
87  void SetSmallSymbol();
88  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
89 
91  virtual void statusChanged(const css::frame::FeatureStateEvent& rEvent);
92 
93  virtual FactoryFunction GetUITestFactory() const override;
94 
95  virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
96 
97 protected:
98 
100  DECL_STATIC_LINK(Button, dispatchCommandHandler, Button*, void);
101 };
102 
104 {
105  NONE = 0x0000,
106  MenuButton = 0x0002, //visual down arrow
107  SplitMenuButton = 0x0003, //visual down arrow and separator line
108 };
109 
111 {
112 public:
113  SAL_DLLPRIVATE void ImplSetDefButton( bool bSet );
114  SAL_DLLPRIVATE void ImplDrawPushButtonFrame(vcl::RenderContext& rRenderContext, tools::Rectangle& rRect, DrawButtonFlags nStyle);
115  SAL_DLLPRIVATE static bool ImplHitTestPushButton(vcl::Window const * pDev, const Point& rPos);
116  SAL_DLLPRIVATE bool ImplIsDefButton() const;
117 
118  explicit PushButton( vcl::Window* pParent, WinBits nStyle = 0 );
119 
120  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
121  virtual void Tracking( const TrackingEvent& rTEvt ) override;
122  virtual void KeyInput( const KeyEvent& rKEvt ) override;
123  virtual void KeyUp( const KeyEvent& rKEvt ) override;
124  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
125  virtual void Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags ) override;
126  virtual void Resize() override;
127  virtual void GetFocus() override;
128  virtual void LoseFocus() override;
129  virtual void StateChanged( StateChangedType nType ) override;
130  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
131  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
132 
133  void Toggle();
134 
135  void SetSymbol( SymbolType eSymbol );
136  SymbolType GetSymbol() const { return meSymbol; }
137  void SetSymbolAlign( SymbolAlign eAlign );
138 
139  void SetDropDown( PushButtonDropdownStyle nStyle );
140 
141  void SetState( TriState eState );
142  TriState GetState() const { return meState; }
143  virtual void statusChanged(const css::frame::FeatureStateEvent& rEvent) override;
144 
145  void Check( bool bCheck = true );
146  bool IsChecked() const;
147 
148  void SetPressed( bool bPressed );
149  bool IsPressed() const { return mbPressed; }
150 
151  void EndSelection();
152 
153  Size CalcMinimumSize() const;
154  virtual Size GetOptimalSize() const override;
155 
156  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
157  virtual void ShowFocus(const tools::Rectangle& rRect) override;
158 
159  void setAction(bool bIsAction)
160  {
161  mbIsAction = bIsAction;
162  }
163 
164  bool isAction() const
165  {
166  return mbIsAction;
167  }
168 
169 protected:
172 
173  SAL_DLLPRIVATE void ImplInitPushButtonData();
174  SAL_DLLPRIVATE static WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle );
175  SAL_DLLPRIVATE void ImplInitSettings( bool bBackground );
176  SAL_DLLPRIVATE void ImplDrawPushButtonContent(OutputDevice* pDev, DrawFlags nDrawFlags,
177  const tools::Rectangle& rRect, bool bMenuBtnSep,
178  DrawButtonFlags nButtonFlags);
179  SAL_DLLPRIVATE void ImplDrawPushButton(vcl::RenderContext& rRenderContext);
181  SAL_DLLPRIVATE DrawTextFlags ImplGetTextStyle( DrawFlags nDrawFlags ) const;
182  SAL_DLLPRIVATE bool IsSymbol() const { return ( (meSymbol != SymbolType::DONTKNOW) && (meSymbol != SymbolType::IMAGE) ); }
183 
184  PushButton( const PushButton & ) = delete;
185  PushButton& operator=( const PushButton & )
186  = delete;
187 
188  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
189 
191  using Window::ImplInit;
192 
193  explicit PushButton( WindowType nType );
194 
195  virtual void FillLayoutData() const override;
196  virtual const vcl::Font&
197  GetCanonicalFont( const StyleSettings& _rStyle ) const override;
198  virtual const Color&
199  GetCanonicalTextColor( const StyleSettings& _rStyle ) const override;
200 
201 private:
204  bool mbPressed;
206 };
207 
208 inline void PushButton::Check( bool bCheck )
209 {
210  SetState( bCheck ? TRISTATE_TRUE : TRISTATE_FALSE );
211 }
212 
213 inline bool PushButton::IsChecked() const
214 {
215  return (GetState() == TRISTATE_TRUE);
216 }
217 
218 #endif // INCLUDED_VCL_BUTTON_HXX
219 
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbIsAction
Definition: button.hxx:205
TriState meState
Definition: button.hxx:203
bool mbIsActive
Definition: button.hxx:171
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3918
void SetClickHdl(const Link< Button *, void > &rLink)
Definition: button.hxx:70
ImageAlign
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:414
void Check(bool bCheck=true)
Definition: button.hxx:208
SymbolAlign
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:32
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
long Long
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
PushButtonDropdownStyle
Definition: button.hxx:103
DrawButtonFlags
Definition: decoview.hxx:53
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
void setAction(bool bIsAction)
Definition: button.hxx:159
StateChangedType
Definition: window.hxx:317
TriState GetState() const
Definition: button.hxx:142
sal_Int64 WinBits
virtual void DumpAsPropertyTree(tools::JsonWriter &)
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: window.cxx:3330
SymbolType
Definition: vclenum.hxx:73
OUString maCommand
Command URL (like .uno:Save) in case the button should handle it.
Definition: button.hxx:45
virtual void Tracking(const TrackingEvent &rTEvt)
Definition: window.cxx:1931
Link< Button *, void > maClickHdl
Definition: button.hxx:42
bool isAction() const
Definition: button.hxx:164
SAL_DLLPRIVATE DrawTextFlags ImplGetTextStyle(WinBits nWinStyle, DrawFlags nDrawFlags)
Definition: button.cxx:171
SymbolType meSymbol
Definition: button.hxx:202
PushButtonDropdownStyle mnDDStyle
Definition: button.hxx:170
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
DrawFlags
Definition: window.hxx:360
bool IsChecked() const
Definition: button.hxx:213
Control & operator=(const Control &)=delete
std::unique_ptr< ImplCommonButtonData > mpButtonData
Definition: button.hxx:41
TRISTATE_FALSE
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
virtual void Draw(::OutputDevice *pDev, const Point &rPos, DrawFlags nFlags)
Definition: window.cxx:1828
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
Button & operator=(const Button &)=delete
DrawTextFlags
Definition: outdev.hxx:142
virtual bool set_property(const OString &rKey, const OUString &rValue)
Definition: window2.cxx:1445
virtual void LoseFocus()
Definition: window.cxx:1854
virtual void ShowFocus(const tools::Rectangle &rRect)
Definition: window2.cxx:49
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1804
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:937
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
virtual void Resize() override
Definition: ctrl.cxx:74
WindowType
Definition: ctrl.hxx:33
virtual void GetFocus()
Definition: window.cxx:1840
virtual const vcl::Font & GetCanonicalFont(const StyleSettings &_rStyle) const
Definition: ctrl.cxx:408
Definition: image.hxx:39
void SetState(TriState eState)
Definition: button.cxx:1514
QPRO_FUNC_TYPE nType
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1021
SAL_DLLPRIVATE bool IsSymbol() const
Definition: button.hxx:182
virtual void KeyUp(const KeyEvent &rKEvt)
Definition: window.cxx:1821
OUString const & GetCommand() const
Definition: button.hxx:75
void ImplInitSettings()
Definition: ctrl.cxx:428
virtual void statusChanged(const css::frame::FeatureStateEvent &rEvent)
Sets the button state according to the FeatureStateEvent emitted by a Uno state change.
Definition: button.cxx:546
bool IsPressed() const
Definition: button.hxx:149
bool mbPressed
Definition: button.hxx:204
TriState
SymbolType GetSymbol() const
Definition: button.hxx:136
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
const Link< Button *, void > & GetClickHdl() const
Definition: button.hxx:71