update credits
[LibreOffice.git] / include / vcl / button.hxx
blob3d330ba17f98c368e444246f1d24f940c92b6a93
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 _SV_BUTTON_HXX
21 #define _SV_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/bitmap.hxx>
28 #include <vcl/salnativewidgets.hxx>
29 #include <rsc/rsc-vcl-shared-types.hxx>
31 #include <vector>
33 class UserDrawEvent;
34 class ImplCommonButtonData;
36 // ----------
37 // - Button -
38 // ----------
40 class VCL_DLLPUBLIC Button : public Control
42 private:
43 ImplCommonButtonData *mpButtonData;
44 Link maClickHdl;
46 // Copy assignment is forbidden and not implemented.
47 SAL_DLLPRIVATE Button (const Button &);
48 SAL_DLLPRIVATE Button & operator= (const Button &);
49 public:
50 SAL_DLLPRIVATE sal_uInt16 ImplGetButtonState() const;
51 SAL_DLLPRIVATE sal_uInt16& ImplGetButtonState();
52 SAL_DLLPRIVATE sal_uInt16 ImplGetTextStyle( OUString& rText, WinBits nWinStyle, sal_uLong nDrawFlags );
53 SAL_DLLPRIVATE void ImplDrawAlignedImage( OutputDevice* pDev, Point& rPos, Size& rSize,
54 sal_Bool bLayout, sal_uLong nImageSep, sal_uLong nDrawFlags,
55 sal_uInt16 nTextStyle, Rectangle *pSymbolRect=NULL, bool bAddImageSep = false );
56 SAL_DLLPRIVATE void ImplSetFocusRect( const Rectangle &rFocusRect );
57 SAL_DLLPRIVATE const Rectangle& ImplGetFocusRect() const;
58 SAL_DLLPRIVATE void ImplSetSymbolAlign( SymbolAlign eAlign );
59 /// The x-coordinate of the vertical separator line, use in MenuButton subclass only.
60 SAL_DLLPRIVATE long ImplGetSeparatorX() const;
61 SAL_DLLPRIVATE void ImplSetSeparatorX( long nX );
63 protected:
64 explicit Button( WindowType nType );
66 public:
67 virtual ~Button();
69 virtual void Click();
71 void SetClickHdl( const Link& rLink ) { maClickHdl = rLink; }
72 const Link& GetClickHdl() const { return maClickHdl; }
74 static OUString GetStandardText( StandardButtonType eButton );
75 static XubString GetStandardHelpText( StandardButtonType eButton );
77 sal_Bool SetModeImage( const Image& rImage );
78 const Image GetModeImage( ) const;
79 sal_Bool HasImage() const;
80 void SetImageAlign( ImageAlign eAlign );
81 ImageAlign GetImageAlign() const;
83 void EnableImageDisplay( sal_Bool bEnable );
84 void EnableTextDisplay( sal_Bool bEnable );
86 void SetFocusRect( const Rectangle& rFocusRect );
87 bool IsSmallSymbol() const;
88 void SetSmallSymbol(bool bSmall = true);
91 // --------------------
92 // - PushButton-Types -
93 // --------------------
95 #define PUSHBUTTON_DROPDOWN_TOOLBOX ((sal_uInt16)0x0001)
96 #define PUSHBUTTON_DROPDOWN_MENUBUTTON ((sal_uInt16)0x0002)
98 // --------------
99 // - PushButton -
100 // --------------
102 class VCL_DLLPUBLIC PushButton : public Button
104 protected:
105 SymbolType meSymbol;
106 TriState meState;
107 TriState meSaveValue;
108 sal_uInt16 mnDDStyle;
109 sal_Bool mbPressed;
110 sal_Bool mbInUserDraw;
111 Link maToggleHdl;
113 SAL_DLLPRIVATE void ImplInitPushButtonData();
114 SAL_DLLPRIVATE WinBits ImplInitStyle( const Window* pPrevWindow, WinBits nStyle );
115 SAL_DLLPRIVATE void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
116 SAL_DLLPRIVATE void ImplDrawPushButtonContent( OutputDevice* pDev, sal_uLong nDrawFlags,
117 const Rectangle& rRect, bool bLayout, bool bMenuBtnSep );
118 SAL_DLLPRIVATE void ImplDrawPushButton( bool bLayout = false );
119 using Button::ImplGetTextStyle;
120 SAL_DLLPRIVATE sal_uInt16 ImplGetTextStyle( sal_uLong nDrawFlags ) const;
121 SAL_DLLPRIVATE sal_Bool IsSymbol() const { return ( (meSymbol != SYMBOL_NOSYMBOL) && (meSymbol != SYMBOL_IMAGE) ); }
122 SAL_DLLPRIVATE sal_Bool IsImage() const { return Button::HasImage(); }
124 // Copy assignment is forbidden and not implemented.
125 SAL_DLLPRIVATE PushButton( const PushButton & );
126 SAL_DLLPRIVATE PushButton& operator=( const PushButton & );
128 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
130 using Control::ImplInitSettings;
131 using Window::ImplInit;
132 public:
133 SAL_DLLPRIVATE void ImplSetDefButton( sal_Bool bSet );
134 SAL_DLLPRIVATE static void ImplDrawPushButtonFrame( Window* pDev, Rectangle& rRect, sal_uInt16 nStyle );
135 SAL_DLLPRIVATE static sal_Bool ImplHitTestPushButton( Window* pDev, const Point& rPos );
136 SAL_DLLPRIVATE sal_Bool ImplIsDefButton() const;
138 protected:
139 explicit PushButton( WindowType nType );
141 virtual void FillLayoutData() const;
142 virtual const Font&
143 GetCanonicalFont( const StyleSettings& _rStyle ) const;
144 virtual const Color&
145 GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
146 public:
147 explicit PushButton( Window* pParent, WinBits nStyle = 0 );
148 explicit PushButton( Window* pParent, const ResId& );
149 virtual ~PushButton();
151 virtual void MouseButtonDown( const MouseEvent& rMEvt );
152 virtual void Tracking( const TrackingEvent& rTEvt );
153 virtual void KeyInput( const KeyEvent& rKEvt );
154 virtual void KeyUp( const KeyEvent& rKEvt );
155 virtual void Paint( const Rectangle& rRect );
156 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
157 virtual void Resize();
158 virtual void GetFocus();
159 virtual void LoseFocus();
160 virtual void StateChanged( StateChangedType nType );
161 virtual void DataChanged( const DataChangedEvent& rDCEvt );
162 virtual long PreNotify( NotifyEvent& rNEvt );
163 virtual void UserDraw( const UserDrawEvent& rUDEvt );
165 virtual void Toggle();
167 void SetSymbol( SymbolType eSymbol );
168 SymbolType GetSymbol() const { return meSymbol; }
169 void SetSymbolAlign( SymbolAlign eAlign );
171 void SetDropDown( sal_uInt16 nStyle );
172 sal_uInt16 GetDropDown() const { return mnDDStyle; }
174 void SetState( TriState eState );
175 TriState GetState() const { return meState; }
177 void Check( sal_Bool bCheck = sal_True );
178 sal_Bool IsChecked() const;
180 void SetPressed( sal_Bool bPressed );
181 sal_Bool IsPressed() const { return mbPressed; }
183 void EndSelection();
185 void SaveValue() { meSaveValue = GetState(); }
186 TriState GetSavedValue() const { return meSaveValue; }
188 Size CalcMinimumSize( long nMaxWidth = 0 ) const;
189 virtual Size GetOptimalSize() const;
191 void SetToggleHdl( const Link& rLink ) { maToggleHdl = rLink; }
192 const Link& GetToggleHdl() const { return maToggleHdl; }
193 virtual bool set_property(const OString &rKey, const OString &rValue);
196 inline void PushButton::Check( sal_Bool bCheck )
198 SetState( (bCheck) ? STATE_CHECK : STATE_NOCHECK );
201 inline sal_Bool PushButton::IsChecked() const
203 return (GetState() == STATE_CHECK);
206 // ------------
207 // - OKButton -
208 // ------------
210 class VCL_DLLPUBLIC OKButton : public PushButton
212 protected:
213 using PushButton::ImplInit;
214 private:
215 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
217 // Copy assignment is forbidden and not implemented.
218 SAL_DLLPRIVATE OKButton (const OKButton &);
219 SAL_DLLPRIVATE OKButton & operator= (const OKButton &);
221 public:
222 explicit OKButton( Window* pParent, WinBits nStyle = WB_DEFBUTTON );
223 explicit OKButton( Window* pParent, const ResId& );
225 virtual void Click();
228 // ----------------
229 // - CancelButton -
230 // ----------------
232 class VCL_DLLPUBLIC CancelButton : public PushButton
234 protected:
235 using PushButton::ImplInit;
236 private:
237 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
239 // Copy assignment is forbidden and not implemented.
240 SAL_DLLPRIVATE CancelButton (const CancelButton &);
241 SAL_DLLPRIVATE CancelButton & operator= (const CancelButton &);
243 public:
244 explicit CancelButton( Window* pParent, WinBits nStyle = 0 );
245 explicit CancelButton( Window* pParent, const ResId& );
247 virtual void Click();
250 class VCL_DLLPUBLIC CloseButton : public CancelButton
252 public:
253 explicit CloseButton(Window* pParent, WinBits nStyle = 0);
257 // --------------
258 // - HelpButton -
259 // --------------
261 class VCL_DLLPUBLIC HelpButton : public PushButton
263 protected:
264 using PushButton::ImplInit;
265 private:
266 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
268 // Copy assignment is forbidden and not implemented.
269 SAL_DLLPRIVATE HelpButton( const HelpButton & );
270 SAL_DLLPRIVATE HelpButton & operator= ( const HelpButton & );
272 public:
273 explicit HelpButton( Window* pParent, WinBits nStyle = 0 );
274 explicit HelpButton( Window* pParent, const ResId& );
276 virtual void Click();
279 // ---------------
280 // - RadioButton -
281 // ---------------
283 class VCL_DLLPUBLIC RadioButton : public Button
285 private:
286 boost::shared_ptr< std::vector<RadioButton*> > m_xGroup;
287 Rectangle maStateRect;
288 Rectangle maMouseRect;
289 Image maImage;
290 sal_Bool mbChecked;
291 sal_Bool mbSaveValue;
292 sal_Bool mbRadioCheck;
293 sal_Bool mbStateChanged;
294 Link maToggleHdl;
295 // when mbLegacyNoTextAlign is set then the old behaviour where
296 // the WB_LEFT, WB_RIGHT & WB_CENTER affect the image placement
297 // occurs, otherwise the image ( radiobutton circle ) is placed
298 // to the left or right ( depending on RTL or LTR settings )
299 bool mbLegacyNoTextAlign;
300 SAL_DLLPRIVATE void ImplInitRadioButtonData();
301 SAL_DLLPRIVATE WinBits ImplInitStyle( const Window* pPrevWindow, WinBits nStyle );
302 SAL_DLLPRIVATE void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
303 SAL_DLLPRIVATE void ImplDrawRadioButtonState();
304 SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
305 const Point& rPos, const Size& rSize,
306 const Size& rImageSize, Rectangle& rStateRect,
307 Rectangle& rMouseRect, bool bLayout = false );
308 SAL_DLLPRIVATE void ImplDrawRadioButton( bool bLayout = false );
309 SAL_DLLPRIVATE void ImplInvalidateOrDrawRadioButtonState();
310 SAL_DLLPRIVATE void ImplUncheckAllOther();
311 SAL_DLLPRIVATE Size ImplGetRadioImageSize() const;
312 SAL_DLLPRIVATE long ImplGetImageToTextDistance() const;
314 // Copy assignment is forbidden and not implemented.
315 SAL_DLLPRIVATE RadioButton(const RadioButton &);
316 SAL_DLLPRIVATE RadioButton& operator= (const RadioButton &);
318 protected:
319 using Control::ImplInitSettings;
320 using Window::ImplInit;
321 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
322 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
324 public:
325 SAL_DLLPRIVATE void ImplCallClick( sal_Bool bGrabFocus = sal_False, sal_uInt16 nFocusFlags = 0 );
326 SAL_DLLPRIVATE void ImplSetMinimumNWFSize();
328 protected:
329 virtual void FillLayoutData() const;
330 virtual const Font&
331 GetCanonicalFont( const StyleSettings& _rStyle ) const;
332 virtual const Color&
333 GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
335 inline void SetMouseRect( const Rectangle& _rMouseRect ) { maMouseRect = _rMouseRect; }
336 inline const Rectangle& GetMouseRect( ) const { return maMouseRect; }
337 inline void SetStateRect( const Rectangle& _rStateRect ) { maStateRect = _rStateRect; }
338 inline const Rectangle& GetStateRect( ) const { return maStateRect; }
340 // draws the radio button (the knob image), in it's current state (pressed/checked)
341 // at the usual location, which can be overridden with SetStateRect
342 void DrawRadioButtonState( );
344 public:
345 explicit RadioButton( Window* pParent, WinBits nWinStyle = 0 );
346 explicit RadioButton( Window* pParent, const ResId& );
347 virtual ~RadioButton();
349 virtual void MouseButtonDown( const MouseEvent& rMEvt );
350 virtual void Tracking( const TrackingEvent& rTEvt );
351 virtual void KeyInput( const KeyEvent& rKEvt );
352 virtual void KeyUp( const KeyEvent& rKEvt );
353 virtual void Paint( const Rectangle& rRect );
354 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
355 virtual void Resize();
356 virtual void GetFocus();
357 virtual void LoseFocus();
358 virtual void StateChanged( StateChangedType nType );
359 virtual void DataChanged( const DataChangedEvent& rDCEvt );
360 virtual long PreNotify( NotifyEvent& rNEvt );
362 virtual void Toggle();
364 sal_Bool IsStateChanged() const { return mbStateChanged; }
366 void EnableRadioCheck( sal_Bool bRadioCheck = sal_True ) { mbRadioCheck = bRadioCheck; }
367 sal_Bool IsRadioCheckEnabled() const { return mbRadioCheck; }
369 sal_Bool SetModeRadioImage( const Image& rImage );
370 const Image& GetModeRadioImage( ) const;
372 void SetState( sal_Bool bCheck );
373 void Check( sal_Bool bCheck = sal_True );
374 sal_Bool IsChecked() const { return mbChecked; }
376 void SaveValue() { mbSaveValue = IsChecked(); }
377 sal_Bool GetSavedValue() const { return mbSaveValue; }
379 static Image GetRadioImage( const AllSettings& rSettings, sal_uInt16 nFlags );
381 Size CalcMinimumSize( long nMaxWidth = 0 ) const;
382 virtual Size GetOptimalSize() const;
384 void SetToggleHdl( const Link& rLink ) { maToggleHdl = rLink; }
385 const Link& GetToggleHdl() const { return maToggleHdl; }
387 /** GetRadioButtonGroup returns a list of pointers to <code>RadioButton</code>s in the same group.
389 The pointers in the returned list are valid at the time call returns. However rescheduling
390 or giving up the SolarMutex may mean events get executed that lead to the pointers getting
391 invalid.
393 @param bIncludeThis
394 defines whether <code>this</code> is contained in the returned list
396 @return
397 on return contains the <code>RadioButton</code>s
398 in the same group as this <code>RadioButton</code>.
400 std::vector<RadioButton*> GetRadioButtonGroup(bool bIncludeThis = true) const;
402 virtual bool set_property(const OString &rKey, const OString &rValue);
405 * Group this RadioButton with another
407 void group(RadioButton &rOther);
410 // ------------
411 // - CheckBox -
412 // ------------
414 class VCL_DLLPUBLIC CheckBox : public Button
416 private:
417 Rectangle maStateRect;
418 Rectangle maMouseRect;
419 TriState meState;
420 TriState meSaveValue;
421 sal_Bool mbTriState;
422 Link maToggleHdl;
423 // when mbLegacyNoTextAlign is set then the old behaviour where
424 // the WB_LEFT, WB_RIGHT & WB_CENTER affect the image placement
425 // occurs, otherwise the image ( checkbox box ) is placed
426 // to the left or right ( depending on RTL or LTR settings )
427 bool mbLegacyNoTextAlign;
428 SAL_DLLPRIVATE void ImplInitCheckBoxData();
429 SAL_DLLPRIVATE WinBits ImplInitStyle( const Window* pPrevWindow, WinBits nStyle );
430 SAL_DLLPRIVATE void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
431 SAL_DLLPRIVATE void ImplInvalidateOrDrawCheckBoxState();
432 SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
433 const Point& rPos, const Size& rSize,
434 const Size& rImageSize, Rectangle& rStateRect,
435 Rectangle& rMouseRect, bool bLayout );
436 SAL_DLLPRIVATE void ImplDrawCheckBox( bool bLayout = false );
437 SAL_DLLPRIVATE long ImplGetImageToTextDistance() const;
438 SAL_DLLPRIVATE Size ImplGetCheckImageSize() const;
440 // Copy assignment is forbidden and not implemented.
441 SAL_DLLPRIVATE CheckBox(const CheckBox &);
442 SAL_DLLPRIVATE CheckBox& operator= (const CheckBox &);
444 protected:
445 using Control::ImplInitSettings;
446 using Window::ImplInit;
447 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
448 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
449 virtual void FillLayoutData() const;
450 virtual const Font& GetCanonicalFont( const StyleSettings& _rStyle ) const;
451 virtual const Color& GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
453 virtual void ImplDrawCheckBoxState();
454 SAL_DLLPRIVATE const Rectangle& GetStateRect() const { return maStateRect; }
455 SAL_DLLPRIVATE const Rectangle& GetMouseRect() const { return maMouseRect; }
457 public:
458 SAL_DLLPRIVATE void ImplCheck();
459 SAL_DLLPRIVATE void ImplSetMinimumNWFSize();
460 public:
461 explicit CheckBox( Window* pParent, WinBits nStyle = 0 );
462 explicit CheckBox( Window* pParent, const ResId& );
464 virtual void MouseButtonDown( const MouseEvent& rMEvt );
465 virtual void Tracking( const TrackingEvent& rTEvt );
466 virtual void KeyInput( const KeyEvent& rKEvt );
467 virtual void KeyUp( const KeyEvent& rKEvt );
468 virtual void Paint( const Rectangle& rRect );
469 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
470 virtual void Resize();
471 virtual void GetFocus();
472 virtual void LoseFocus();
473 virtual void StateChanged( StateChangedType nType );
474 virtual void DataChanged( const DataChangedEvent& rDCEvt );
475 virtual long PreNotify( NotifyEvent& rNEvt );
477 virtual void Toggle();
479 void SetState( TriState eState );
480 TriState GetState() const { return meState; }
482 void Check( sal_Bool bCheck = sal_True );
483 sal_Bool IsChecked() const;
485 void EnableTriState( sal_Bool bTriState = sal_True );
486 sal_Bool IsTriStateEnabled() const { return mbTriState; }
488 void SaveValue() { meSaveValue = GetState(); }
489 TriState GetSavedValue() const { return meSaveValue; }
491 static Image GetCheckImage( const AllSettings& rSettings, sal_uInt16 nFlags );
493 Size CalcMinimumSize( long nMaxWidth = 0 ) const;
494 virtual Size GetOptimalSize() const;
496 void SetToggleHdl( const Link& rLink ) { maToggleHdl = rLink; }
497 const Link& GetToggleHdl() const { return maToggleHdl; }
498 bool IsLegacyNoTextAlign() { return mbLegacyNoTextAlign; }
499 void SetLegacyNoTextAlign( bool bVal ) { mbLegacyNoTextAlign = bVal; }
501 virtual bool set_property(const OString &rKey, const OString &rValue);
504 inline void CheckBox::Check( sal_Bool bCheck )
506 SetState( (bCheck) ? STATE_CHECK : STATE_NOCHECK );
509 inline sal_Bool CheckBox::IsChecked() const
511 return (GetState() == STATE_CHECK);
514 // ---------------------------------
515 // - Control-Layer fuer alten Code -
516 // ---------------------------------
518 class VCL_DLLPUBLIC ImageButton : public PushButton
520 protected:
521 using PushButton::ImplInitStyle;
522 private:
523 SAL_DLLPRIVATE void ImplInitStyle();
525 // Copy assignment is forbidden and not implemented.
526 SAL_DLLPRIVATE ImageButton( const ImageButton & );
527 SAL_DLLPRIVATE ImageButton & operator= ( const ImageButton & );
529 public:
530 ImageButton( Window* pParent, WinBits nStyle = 0 );
531 ImageButton( Window* pParent, const ResId& rResId );
532 ~ImageButton();
535 class VCL_DLLPUBLIC ImageRadioButton : public RadioButton
537 // Copy assignment is forbidden and not implemented.
538 SAL_DLLPRIVATE ImageRadioButton( const ImageRadioButton & );
539 SAL_DLLPRIVATE ImageRadioButton & operator= ( const ImageRadioButton & );
541 public:
542 explicit ImageRadioButton( Window* pParent, WinBits nStyle = 0 );
543 explicit ImageRadioButton( Window* pParent, const ResId& );
544 virtual ~ImageRadioButton();
547 class VCL_DLLPUBLIC TriStateBox : public CheckBox
549 // Copy assignment is forbidden and not implemented.
550 SAL_DLLPRIVATE TriStateBox( const TriStateBox & );
551 SAL_DLLPRIVATE TriStateBox & operator= ( const TriStateBox & );
553 public:
554 explicit TriStateBox( Window* pParent, WinBits nStyle = 0 );
555 explicit TriStateBox( Window* pParent, const ResId& );
556 virtual ~TriStateBox();
559 class VCL_DLLPUBLIC DisclosureButton : public CheckBox
561 protected:
562 SAL_DLLPRIVATE virtual void ImplDrawCheckBoxState();
563 public:
564 explicit DisclosureButton( Window* pParent, WinBits nStyle = 0 );
565 explicit DisclosureButton( Window* pParent, const ResId& rResId );
567 virtual void KeyInput( const KeyEvent& rKEvt );
570 #endif // _SV_BUTTON_HXX
572 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */