PCL
SectionBar.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/SectionBar.h - Released 2024-01-13T15:47:58Z
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_SectionBar_h
53 #define __PCL_SectionBar_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/CheckBox.h>
60 #include <pcl/Control.h>
61 #include <pcl/Label.h>
62 #include <pcl/Sizer.h>
63 #include <pcl/ToolButton.h>
64 
65 namespace pcl
66 {
67 
68 // ----------------------------------------------------------------------------
69 
87 class PCL_CLASS SectionBar : public Control
88 {
89 public:
90 
94  SectionBar( Control& parent = Null() );
95 
99  ~SectionBar() override;
100 
107  const Control& Section() const
108  {
109  return (m_section != nullptr) ? *m_section : Control::Null();
110  }
111 
119  {
120  return (m_section != nullptr) ? *m_section : Control::Null();
121  }
122 
128  void SetSection( Control& );
129 
135  String Title() const
136  {
137  return Title_Label.Text();
138  }
139 
145  void SetTitle( const String& title )
146  {
147  Title_Label.SetText( title );
148  }
149 
155  bool HasTitleCheckBox() const
156  {
157  return !Title_CheckBox.IsNull();
158  }
159 
165  void EnableTitleCheckBox( bool = true );
166 
172  void DisableTitleCheckBox( bool disable = true )
173  {
174  EnableTitleCheckBox( !disable );
175  }
176 
183  bool IsChecked() const
184  {
185  return !Title_CheckBox.IsNull() && Title_CheckBox->IsChecked();
186  }
187 
200  void SetChecked( bool checked = true );
201 
205  void Check()
206  {
207  SetChecked( true );
208  }
209 
213  void Uncheck()
214  {
215  SetChecked( false );
216  }
217 
223  bool IsEnabled() const override
224  {
225  return Title_Label.IsEnabled();
226  }
227 
238  void Enable( bool enabled = true ) override;
239 
251  void SetSectionVisible( bool visible = true );
252 
256  void ShowSection()
257  {
258  SetSectionVisible( true );
259  }
260 
264  void HideSection()
265  {
266  SetSectionVisible( false );
267  }
268 
269  // -------------------------------------------------------------------------
270  // Event handlers
271  //
272  // void OnToggleSection( SectionBar& sender, Control& section, bool start );
273 
298  using section_event_handler = void (Control::*)( SectionBar& sender, Control& section, bool start );
299 
311  void OnToggleSection( section_event_handler handler, Control& receiver );
312 
327  using check_event_handler = void (Control::*)( SectionBar& sender, bool checked );
328 
340  void OnCheck( check_event_handler handler, Control& receiver );
341 
342 private:
343 
344  struct EventHandlers
345  {
346  section_event_handler onToggleSection = nullptr;
347  Control* onToggleSectionReceiver = nullptr;
348 
349  check_event_handler onCheck = nullptr;
350  Control* onCheckReceiver = nullptr;
351 
352  EventHandlers() = default;
353  EventHandlers( const EventHandlers& ) = default;
354  EventHandlers& operator =( const EventHandlers& ) = default;
355  };
356 
357  AutoPointer<EventHandlers> m_handlers;
358  Control* m_section = nullptr;
359 
360  VerticalSizer Global_Sizer;
361  HorizontalSizer Title_Sizer;
362  Label Title_Label;
363  AutoPointer<CheckBox> Title_CheckBox; // non-null for a checkable SectionBar
364  ToolButton Title_ToolButton;
365 
366  void ButtonClick( Button&, bool );
367  void MousePress( Control&, const pcl::Point&, int, unsigned, unsigned );
368  void ControlShow( Control& );
369  void ControlHide( Control& );
370 };
371 
372 // ----------------------------------------------------------------------------
373 
374 } // pcl
375 
376 #endif // __PCL_SectionBar_h
377 
378 // ----------------------------------------------------------------------------
379 // EOF pcl/SectionBar.h - Released 2024-01-13T15:47:58Z
pcl::SectionBar::Check
void Check()
Definition: SectionBar.h:205
pcl::SectionBar::HasTitleCheckBox
bool HasTitleCheckBox() const
Definition: SectionBar.h:155
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::SectionBar::IsChecked
bool IsChecked() const
Definition: SectionBar.h:183
pcl::SectionBar
A control to manage collapsible sections of interface windows and dialogs.
Definition: SectionBar.h:87
pcl::String
Unicode (UTF-16) string.
Definition: String.h:8112
pcl::SectionBar::Uncheck
void Uncheck()
Definition: SectionBar.h:213
pcl::GenericPoint
A generic point in the two-dimensional space.
Definition: Point.h:99
pcl::ToolButton
Client-side interface to a PixInsight ToolButton control.
Definition: ToolButton.h:74
CheckBox.h
pcl::SectionBar::ShowSection
void ShowSection()
Definition: SectionBar.h:256
pcl::VerticalSizer
Client-side interface to a PixInsight vertical sizer.
Definition: Sizer.h:611
pcl::Control::Null
static Control & Null()
pcl::Label
Client-side interface to a PixInsight Label control.
Definition: Label.h:75
pcl::AutoPointer< EventHandlers >
pcl::Button
Abstract base class for all client-side interfaces to PixInsight button controls.
Definition: Button.h:99
pcl::SectionBar::SetTitle
void SetTitle(const String &title)
Definition: SectionBar.h:145
ToolButton.h
pcl::SectionBar::IsEnabled
bool IsEnabled() const override
Definition: SectionBar.h:223
pcl::SectionBar::Section
const Control & Section() const
Definition: SectionBar.h:107
pcl::SectionBar::section_event_handler
void(Control::*)(SectionBar &sender, Control &section, bool start) section_event_handler
Definition: SectionBar.h:298
pcl::SectionBar::check_event_handler
void(Control::*)(SectionBar &sender, bool checked) check_event_handler
Definition: SectionBar.h:327
pcl::HorizontalSizer
Client-side interface to a PixInsight horizontal sizer.
Definition: Sizer.h:579
Sizer.h
pcl::SectionBar::Title
String Title() const
Definition: SectionBar.h:135
Label.h
pcl::Control
Client-side interface to a PixInsight Control object.
Definition: Control.h:125
pcl::SectionBar::HideSection
void HideSection()
Definition: SectionBar.h:264
pcl::SectionBar::DisableTitleCheckBox
void DisableTitleCheckBox(bool disable=true)
Definition: SectionBar.h:172
pcl::SectionBar::Section
Control & Section()
Definition: SectionBar.h:118
Defs.h
Control.h