lok: calc - send other views our selection in their co-ordinates.
[LibreOffice.git] / include / vcl / button.hxx
blobbe4ccb334a6b93e7d315fc86b615b6eb0826a30f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_BUTTON_HXX
21 #define INCLUDED_VCL_BUTTON_HXX
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>
31 namespace com { namespace sun { namespace star { namespace frame { struct FeatureStateEvent; } } } }
32 template <class T> class VclPtr;
34 class Color;
35 class ImplCommonButtonData;
36 enum class DrawButtonFlags;
38 class VCL_DLLPUBLIC Button : public Control
40 private:
41 std::unique_ptr<ImplCommonButtonData> mpButtonData;
42 Link<Button*,void> maClickHdl;
44 /// Command URL (like .uno:Save) in case the button should handle it.
45 OUString maCommand;
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 );
57 /// The x-coordinate of the vertical separator line, use in MenuButton subclass only.
58 SAL_DLLPRIVATE long ImplGetSeparatorX() const;
59 SAL_DLLPRIVATE void ImplSetSeparatorX( long nX );
61 protected:
62 explicit Button( WindowType nType );
64 public:
65 virtual ~Button() override;
66 virtual void dispose() override;
68 virtual void Click();
70 void SetClickHdl( const Link<Button*,void>& rLink ) { maClickHdl = rLink; }
71 const Link<Button*,void>& GetClickHdl() const { return maClickHdl; }
73 /// Setup handler for UNO commands so that commands like .uno:Something are handled automagically by this button.
74 void SetCommandHandler(const OUString& aCommand);
75 OUString const & GetCommand() const { return maCommand; }
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();
86 bool IsSmallSymbol() const;
87 void SetSmallSymbol();
88 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
90 /// Sets the button state according to the FeatureStateEvent emitted by a Uno state change.
91 virtual void statusChanged(const css::frame::FeatureStateEvent& rEvent);
93 virtual FactoryFunction GetUITestFactory() const override;
95 virtual boost::property_tree::ptree DumpAsPropertyTree() override;
97 protected:
99 /// Handler for click, in case we want the button to handle uno commands (.uno:Something).
100 DECL_STATIC_LINK(Button, dispatchCommandHandler, Button*, void);
103 enum class PushButtonDropdownStyle
105 NONE = 0x0000,
106 MenuButton = 0x0002, //visual down arrow
107 SplitMenuButton = 0x0003, //visual down arrow and separator line
110 class VCL_DLLPUBLIC PushButton : public Button
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;
118 explicit PushButton( vcl::Window* pParent, WinBits nStyle = 0 );
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, const Size& rSize, 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;
133 void Toggle();
135 void SetSymbol( SymbolType eSymbol );
136 SymbolType GetSymbol() const { return meSymbol; }
137 void SetSymbolAlign( SymbolAlign eAlign );
139 void SetDropDown( PushButtonDropdownStyle nStyle );
141 void SetState( TriState eState );
142 TriState GetState() const { return meState; }
143 virtual void statusChanged(const css::frame::FeatureStateEvent& rEvent) override;
145 void Check( bool bCheck = true );
146 bool IsChecked() const;
148 void SetPressed( bool bPressed );
149 bool IsPressed() const { return mbPressed; }
151 void EndSelection();
153 Size CalcMinimumSize() const;
154 virtual Size GetOptimalSize() const override;
156 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
157 virtual void ShowFocus(const tools::Rectangle& rRect) override;
159 void setAction(bool bIsAction)
161 mbIsAction = bIsAction;
164 bool isAction() const
166 return mbIsAction;
169 protected:
170 PushButtonDropdownStyle mnDDStyle;
171 bool mbIsActive;
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);
180 using Button::ImplGetTextStyle;
181 SAL_DLLPRIVATE DrawTextFlags ImplGetTextStyle( DrawFlags nDrawFlags ) const;
182 SAL_DLLPRIVATE bool IsSymbol() const { return ( (meSymbol != SymbolType::DONTKNOW) && (meSymbol != SymbolType::IMAGE) ); }
184 PushButton( const PushButton & ) = delete;
185 PushButton& operator=( const PushButton & )
186 = delete;
188 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
190 using Control::ImplInitSettings;
191 using Window::ImplInit;
193 explicit PushButton( WindowType nType );
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;
201 private:
202 SymbolType meSymbol;
203 TriState meState;
204 bool mbPressed;
205 bool mbIsAction;
208 inline void PushButton::Check( bool bCheck )
210 SetState( bCheck ? TRISTATE_TRUE : TRISTATE_FALSE );
213 inline bool PushButton::IsChecked() const
215 return (GetState() == TRISTATE_TRUE);
218 class VCL_DLLPUBLIC OKButton : public PushButton
220 protected:
221 using PushButton::ImplInit;
222 private:
223 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
225 OKButton (const OKButton &) = delete;
226 OKButton & operator= (const OKButton &) = delete;
228 public:
229 explicit OKButton( vcl::Window* pParent, WinBits nStyle = WB_DEFBUTTON );
231 virtual void Click() override;
234 class VCL_DLLPUBLIC CancelButton : public PushButton
236 protected:
237 using PushButton::ImplInit;
238 private:
239 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
241 CancelButton (const CancelButton &) = delete;
242 CancelButton & operator= (const CancelButton &) = delete;
244 public:
245 explicit CancelButton( vcl::Window* pParent, WinBits nStyle = 0 );
247 virtual void Click() override;
250 class CloseButton final : public CancelButton
252 public:
253 explicit CloseButton(vcl::Window* pParent, WinBits nStyle = 0);
256 class VCL_DLLPUBLIC HelpButton : public PushButton
258 protected:
259 using PushButton::ImplInit;
260 private:
261 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
263 HelpButton( const HelpButton & ) = delete;
264 HelpButton & operator= ( const HelpButton & ) = delete;
266 virtual void StateChanged( StateChangedType nStateChange ) override;
268 public:
269 explicit HelpButton( vcl::Window* pParent, WinBits nStyle = 0 );
271 virtual void Click() override;
274 class VCL_DLLPUBLIC RadioButton : public Button
276 private:
277 friend class VclBuilder;
279 std::shared_ptr< std::vector< VclPtr< RadioButton > > > m_xGroup;
280 tools::Rectangle maStateRect;
281 tools::Rectangle maMouseRect;
282 Image maImage;
283 bool mbChecked;
284 bool mbRadioCheck;
285 bool mbStateChanged;
286 Link<RadioButton&,void> maToggleHdl;
287 SAL_DLLPRIVATE void ImplInitRadioButtonData();
288 SAL_DLLPRIVATE WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle );
289 SAL_DLLPRIVATE void ImplInitSettings( bool bBackground );
290 SAL_DLLPRIVATE void ImplDrawRadioButtonState(vcl::RenderContext& rRenderContext);
291 SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags,
292 const Point& rPos, const Size& rSize,
293 const Size& rImageSize, tools::Rectangle& rStateRect,
294 tools::Rectangle& rMouseRect );
295 SAL_DLLPRIVATE void ImplDrawRadioButton(vcl::RenderContext& rRenderContext );
296 SAL_DLLPRIVATE void ImplUncheckAllOther( const bool bSetStyle = true);
297 SAL_DLLPRIVATE Size ImplGetRadioImageSize() const;
298 SAL_DLLPRIVATE long ImplGetImageToTextDistance() const;
300 RadioButton(const RadioButton &) = delete;
301 RadioButton& operator= (const RadioButton &) = delete;
303 protected:
304 using Control::ImplInitSettings;
305 using Window::ImplInit;
306 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
308 public:
309 SAL_DLLPRIVATE void ImplCallClick( bool bGrabFocus = false, GetFocusFlags nFocusFlags = GetFocusFlags::NONE );
310 SAL_DLLPRIVATE void ImplSetMinimumNWFSize();
312 protected:
313 virtual void FillLayoutData() const override;
314 virtual const vcl::Font&
315 GetCanonicalFont( const StyleSettings& _rStyle ) const override;
316 virtual const Color&
317 GetCanonicalTextColor( const StyleSettings& _rStyle ) const override;
319 public:
320 explicit RadioButton( vcl::Window* pParent, WinBits nWinStyle = 0 );
321 virtual ~RadioButton() override;
322 virtual void dispose() override;
324 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
325 virtual void Tracking( const TrackingEvent& rTEvt ) override;
326 virtual void KeyInput( const KeyEvent& rKEvt ) override;
327 virtual void KeyUp( const KeyEvent& rKEvt ) override;
328 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
329 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
330 virtual void Resize() override;
331 virtual void GetFocus() override;
332 virtual void LoseFocus() override;
333 virtual void StateChanged( StateChangedType nType ) override;
334 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
335 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
337 void Toggle();
339 bool IsStateChanged() const { return mbStateChanged; }
341 void EnableRadioCheck( bool bRadioCheck ) { mbRadioCheck = bRadioCheck; }
342 bool IsRadioCheckEnabled() const { return mbRadioCheck; }
344 void SetModeRadioImage( const Image& rImage );
346 void SetState( bool bCheck );
347 void Check( bool bCheck = true );
348 bool IsChecked() const { return mbChecked; }
350 static Image GetRadioImage( const AllSettings& rSettings, DrawButtonFlags nFlags );
352 Size CalcMinimumSize() const;
353 virtual Size GetOptimalSize() const override;
355 void SetToggleHdl( const Link<RadioButton&,void>& rLink ) { maToggleHdl = rLink; }
357 /** GetRadioButtonGroup returns a list of pointers to <code>RadioButton</code>s in the same group.
359 The pointers in the returned list are valid at the time call returns. However rescheduling
360 or giving up the SolarMutex may mean events get executed that lead to the pointers getting
361 invalid.
363 @param bIncludeThis
364 defines whether <code>this</code> is contained in the returned list
366 @return
367 on return contains the <code>RadioButton</code>s
368 in the same group as this <code>RadioButton</code>.
370 std::vector<VclPtr<RadioButton> > GetRadioButtonGroup(bool bIncludeThis = true) const;
372 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
375 * Group this RadioButton with another
377 void group(RadioButton &rOther);
378 virtual void ShowFocus(const tools::Rectangle& rRect) override;
380 /// Button hes additional stuff that we need to dump too.
381 boost::property_tree::ptree DumpAsPropertyTree() override;
383 virtual FactoryFunction GetUITestFactory() const override;
386 class VCL_DLLPUBLIC CheckBox : public Button
388 private:
389 tools::Rectangle maStateRect;
390 tools::Rectangle maMouseRect;
391 TriState meState;
392 TriState meSaveValue;
393 bool mbTriState;
394 Link<CheckBox&,void> maToggleHdl;
395 // when mbLegacyNoTextAlign is set then the old behaviour where
396 // the WB_LEFT, WB_RIGHT & WB_CENTER affect the image placement
397 // occurs, otherwise the image ( checkbox box ) is placed
398 // to the left or right ( depending on RTL or LTR settings )
399 bool mbLegacyNoTextAlign;
400 SAL_DLLPRIVATE void ImplInitCheckBoxData();
401 SAL_DLLPRIVATE static WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle );
402 SAL_DLLPRIVATE void ImplInitSettings( bool bBackground );
403 SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags,
404 const Point& rPos, const Size& rSize,
405 const Size& rImageSize, tools::Rectangle& rStateRect,
406 tools::Rectangle& rMouseRect );
407 SAL_DLLPRIVATE void ImplDrawCheckBox(vcl::RenderContext& rRenderContext );
408 SAL_DLLPRIVATE long ImplGetImageToTextDistance() const;
409 SAL_DLLPRIVATE Size ImplGetCheckImageSize() const;
411 CheckBox(const CheckBox &) = delete;
412 CheckBox& operator= (const CheckBox &) = delete;
414 protected:
415 using Control::ImplInitSettings;
416 using Window::ImplInit;
417 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
418 virtual void FillLayoutData() const override;
419 virtual const vcl::Font& GetCanonicalFont( const StyleSettings& _rStyle ) const override;
420 virtual const Color& GetCanonicalTextColor( const StyleSettings& _rStyle ) const override;
422 virtual void ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext);
423 SAL_DLLPRIVATE const tools::Rectangle& GetStateRect() const { return maStateRect; }
424 SAL_DLLPRIVATE const tools::Rectangle& GetMouseRect() const { return maMouseRect; }
426 public:
427 SAL_DLLPRIVATE void ImplCheck();
428 SAL_DLLPRIVATE void ImplSetMinimumNWFSize();
429 public:
430 explicit CheckBox( vcl::Window* pParent, WinBits nStyle = 0 );
432 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
433 virtual void Tracking( const TrackingEvent& rTEvt ) override;
434 virtual void KeyInput( const KeyEvent& rKEvt ) override;
435 virtual void KeyUp( const KeyEvent& rKEvt ) override;
436 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
437 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
438 virtual void Resize() override;
439 virtual void GetFocus() override;
440 virtual void LoseFocus() override;
441 virtual void StateChanged( StateChangedType nType ) override;
442 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
443 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
445 void Toggle();
447 void SetState( TriState eState );
448 TriState GetState() const { return meState; }
450 void Check( bool bCheck = true );
451 bool IsChecked() const;
453 void EnableTriState( bool bTriState = true );
454 bool IsTriStateEnabled() const { return mbTriState; }
456 void SaveValue() { meSaveValue = GetState(); }
457 TriState GetSavedValue() const { return meSaveValue; }
458 bool IsValueChangedFromSaved() const { return meSaveValue != GetState(); }
460 static Image GetCheckImage( const AllSettings& rSettings, DrawButtonFlags nFlags );
462 Size CalcMinimumSize( long nMaxWidth = 0 ) const;
463 virtual Size GetOptimalSize() const override;
465 void SetToggleHdl( const Link<CheckBox&,void>& rLink ) { maToggleHdl = rLink; }
466 void SetLegacyNoTextAlign( bool bVal ) { mbLegacyNoTextAlign = bVal; }
468 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
469 virtual void ShowFocus(const tools::Rectangle& rRect) override;
471 /// Button hes additional stuff that we need to dump too.
472 boost::property_tree::ptree DumpAsPropertyTree() override;
474 virtual FactoryFunction GetUITestFactory() const override;
477 inline void CheckBox::Check( bool bCheck )
479 SetState( bCheck ? TRISTATE_TRUE : TRISTATE_FALSE );
482 inline bool CheckBox::IsChecked() const
484 return (GetState() == TRISTATE_TRUE);
487 class VCL_DLLPUBLIC ImageButton final : public PushButton
489 protected:
490 using PushButton::ImplInitStyle;
492 private:
493 SAL_DLLPRIVATE void ImplInitStyle();
495 ImageButton( const ImageButton & ) = delete;
496 ImageButton & operator= ( const ImageButton & ) = delete;
498 public:
499 ImageButton( vcl::Window* pParent, WinBits nStyle = 0 );
502 class VCL_DLLPUBLIC ImageRadioButton : public RadioButton
504 ImageRadioButton( const ImageRadioButton & ) = delete;
505 ImageRadioButton & operator= ( const ImageRadioButton & ) = delete;
507 public:
508 explicit ImageRadioButton( vcl::Window* pParent );
511 class VCL_DLLPUBLIC TriStateBox final : public CheckBox
513 TriStateBox( const TriStateBox & ) = delete;
514 TriStateBox & operator= ( const TriStateBox & ) = delete;
516 public:
517 explicit TriStateBox( vcl::Window* pParent, WinBits nStyle );
520 class DisclosureButton final : public CheckBox
522 virtual void ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext) override;
524 public:
525 explicit DisclosureButton( vcl::Window* pParent );
527 virtual void KeyInput( const KeyEvent& rKEvt ) override;
530 #endif // INCLUDED_VCL_BUTTON_HXX
532 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */