PCL
Button.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/Button.h - Released 2024-05-07T15:27:32Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Button_h
53 #define __PCL_Button_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/Control.h>
62 #include <pcl/Bitmap.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
80 namespace CheckState
81 {
82  enum value_type
83  {
84  Unchecked, // the item is not checked
85  Checked, // the item is checked
86  ThirdState // the check box is in its 'third state'
87  };
88 }
89 
90 // ----------------------------------------------------------------------------
91 
99 class PCL_CLASS Button : public Control
100 {
101 public:
102 
107  using check_state = CheckState::value_type;
108 
112  ~Button() override
113  {
114  }
115 
119  String Text() const;
120 
124  void SetText( const String& );
125 
130  Bitmap Icon() const;
131 
136  void SetIcon( const Bitmap& );
137 
142  void GetIconSize( int& width, int& height ) const;
143 
147  int IconWidth() const
148  {
149  int width, dum; GetIconSize( width, dum ); return width;
150  }
151 
155  int IconHeight() const
156  {
157  int dum, height; GetIconSize( dum, height ); return height;
158  }
159 
164  void SetIconSize( int width, int height );
165 
168  void SetIconSize( int size )
169  {
170  SetIconSize( size, size );
171  }
172 
175  void GetScaledIconSize( int& width, int& height ) const
176  {
177  GetIconSize( width, height ); width = PhysicalPixelsToLogical( width ); height = PhysicalPixelsToLogical( height );
178  }
179 
182  int ScaledIconWidth() const
183  {
184  int width, dum; GetIconSize( width, dum ); return PhysicalPixelsToLogical( width );
185  }
186 
189  int ScaledIconHeight() const
190  {
191  int dum, height; GetIconSize( dum, height ); return PhysicalPixelsToLogical( height );
192  }
193 
196  void SetScaledIconSize( int width, int height )
197  {
198  SetIconSize( LogicalPixelsToPhysical( width ), LogicalPixelsToPhysical( height ) );
199  }
200 
203  void SetScaledIconSize( int size )
204  {
205  size = LogicalPixelsToPhysical( size );
206  SetIconSize( size, size );
207  }
208 
215  virtual bool IsPushable() const = 0;
216 
220  bool IsPushed() const;
221 
225  void SetPushed( bool = true );
226 
230  void Push()
231  {
232  SetPushed( true );
233  }
234 
238  void Unpush()
239  {
240  SetPushed( false );
241  }
242 
249  virtual bool IsCheckable() const = 0;
250 
254  bool IsChecked() const;
255 
259  void SetChecked( bool = true );
260 
264  void Check()
265  {
266  SetChecked( true );
267  }
268 
272  void Uncheck()
273  {
274  SetChecked( false );
275  }
276 
281  check_state State() const;
282 
287  void SetState( check_state );
288 
289  // -------------------------------------------------------------------------
290  // Event handlers
291  //
292  // void OnClick( Button& sender, bool checked );
293  // void OnPress( Button& sender );
294  // void OnRelease( Button& sender );
295  // void OnCheck( Button& sender, Button::check_state state );
296 
313  using click_event_handler = void (Control::*)( Button& sender, bool checked );
314 
325  using press_event_handler = void (Control::*)( Button& sender );
326 
339  using check_event_handler = void (Control::*)( Button& sender, Button::check_state state );
340 
352  void OnClick( click_event_handler handler, Control& receiver );
353 
365  void OnPress( press_event_handler handler, Control& receiver );
366 
378  void OnRelease( press_event_handler handler, Control& receiver );
379 
391  void OnCheck( check_event_handler handler, Control& receiver );
392 
393 private:
394 
395  struct EventHandlers
396  {
397  click_event_handler onClick = nullptr;
398  press_event_handler onPress = nullptr;
399  press_event_handler onRelease = nullptr;
400  check_event_handler onCheck = nullptr;
401 
402  EventHandlers() = default;
403  EventHandlers( const EventHandlers& ) = default;
404  EventHandlers& operator =( const EventHandlers& ) = default;
405  };
406 
407  AutoPointer<EventHandlers> m_handlers;
408 
409 protected:
410 
414  Button( void* h ) : Control( h )
415  {
416  }
417 
418  friend class ButtonEventDispatcher;
419 };
420 
421 // ----------------------------------------------------------------------------
422 
423 } // pcl
424 
425 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
426 
427 #endif // __PCL_Button_h
428 
429 // ----------------------------------------------------------------------------
430 // EOF pcl/Button.h - Released 2024-05-07T15:27:32Z
Client-side interface to a PixInsight Bitmap object.
Definition: Bitmap.h:204
Abstract base class for all client-side interfaces to PixInsight button controls.
Definition: Button.h:100
~Button() override
Definition: Button.h:112
int IconWidth() const
Definition: Button.h:147
void Uncheck()
Definition: Button.h:272
Bitmap Icon() const
virtual bool IsCheckable() const =0
void GetIconSize(int &width, int &height) const
void SetChecked(bool=true)
int ScaledIconWidth() const
Definition: Button.h:182
void SetIconSize(int size)
Definition: Button.h:168
String Text() const
int IconHeight() const
Definition: Button.h:155
void SetText(const String &)
virtual bool IsPushable() const =0
void Unpush()
Definition: Button.h:238
void Check()
Definition: Button.h:264
bool IsPushed() const
void SetScaledIconSize(int width, int height)
Definition: Button.h:196
bool IsChecked() const
void SetIconSize(int width, int height)
void SetPushed(bool=true)
void Push()
Definition: Button.h:230
void GetScaledIconSize(int &width, int &height) const
Definition: Button.h:175
int ScaledIconHeight() const
Definition: Button.h:189
void SetScaledIconSize(int size)
Definition: Button.h:203
check_state State() const
void SetState(check_state)
void SetIcon(const Bitmap &)
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
Unicode (UTF-16) string.
Definition: String.h:8113
void(Control::*)(Button &sender, bool checked) click_event_handler
Definition: Button.h:313
void(Control::*)(Button &sender, Button::check_state state) check_event_handler
Definition: Button.h:339
void OnRelease(press_event_handler handler, Control &receiver)
void OnCheck(check_event_handler handler, Control &receiver)
void OnPress(press_event_handler handler, Control &receiver)
void OnClick(click_event_handler handler, Control &receiver)
void(Control::*)(Button &sender) press_event_handler
Definition: Button.h:325
PCL root namespace.
Definition: AbstractImage.h:77