FINAL CUT
fbuttongroup.h
1 /***********************************************************************
2 * fbuttongroup.h - The FButtonGroup widget organizes FToggleButton *
3 * widgets in a group. *
4 * *
5 * This file is part of the FINAL CUT widget toolkit *
6 * *
7 * Copyright 2014-2024 Markus Gans *
8 * *
9 * FINAL CUT is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU Lesser General Public License as *
11 * published by the Free Software Foundation; either version 3 of *
12 * the License, or (at your option) any later version. *
13 * *
14 * FINAL CUT is distributed in the hope that it will be useful, but *
15 * WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU Lesser General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU Lesser General Public *
20 * License along with this program. If not, see *
21 * <http://www.gnu.org/licenses/>. *
22 ***********************************************************************/
23 
24 /* Inheritance diagram
25  * ═══════════════════
26  *
27  * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
28  * ▕ FVTerm ▏ ▕ FObject ▏
29  * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
30  * ▲ ▲
31  * │ │
32  * └─────┬─────┘
33  * │
34  * ▕▔▔▔▔▔▔▔▔▔▏
35  * ▕ FWidget ▏
36  * ▕▁▁▁▁▁▁▁▁▁▏
37  * ▲
38  * │
39  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
40  * ▕ FButtonGroup ▏
41  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
42  */
43 
44 #ifndef FBUTTONGROUP_H
45 #define FBUTTONGROUP_H
46 
47 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
48  #error "Only <final/final.h> can be included directly."
49 #endif
50 
51 #include "final/fwidgetcolors.h"
52 #include "final/widget/fscrollview.h"
53 
54 namespace finalcut
55 {
56 
57 // class forward declaration
58 class FToggleButton;
59 
60 //----------------------------------------------------------------------
61 // class FButtonGroup
62 //----------------------------------------------------------------------
63 
64 class FButtonGroup : public FScrollView
65 {
66  public:
67  // Constructors
68  explicit FButtonGroup (FWidget* = nullptr);
69  explicit FButtonGroup (const FString&, FWidget* = nullptr);
70 
71  // Destructor
72  ~FButtonGroup() override;
73 
74  // Accessor
75  auto getClassName() const -> FString override;
76  auto getButton (int) const -> FToggleButton*;
77  auto getFocusedButton() const -> FToggleButton*;
78  auto getCheckedButton() const -> FToggleButton*;
79  auto getCount() const -> std::size_t;
80 
81  // Mutator
82  void setEnable (bool = true) override;
83  void unsetEnable() override;
84  void setDisable() override;
85 
86  // Inquiries
87  auto isChecked (int) const -> bool;
88  auto hasFocusedButton() const -> bool;
89  auto hasCheckedButton() const -> bool;
90 
91  // Methods
92  void hide() override;
93  void insert (FToggleButton*);
94  void remove (FToggleButton*);
95  void checkScrollSize (const FToggleButton*);
96  void checkScrollSize (const FRect&);
97 
98  // Event handlers
99  void onMouseDown (FMouseEvent*) override;
100  void onAccel (FAccelEvent*) override;
101  void onFocusIn (FFocusEvent*) override;
102  void onChildFocusOut (FFocusEvent*) override;
103 
104  protected:
105  // Methods
106  void draw() override;
107 
108  private:
109  // Constants
110  static constexpr auto NOT_SET = static_cast<std::size_t>(-1);
111 
112  // Inquiries
113  auto isRadioButton (const FToggleButton*) const -> bool;
114 
115  // Methods
116  void init();
117  auto directFocusCheckedRadioButton (FToggleButton*) const -> bool;
118  auto directFocusRadioButton() const -> bool;
119  void directFocus();
120  auto getCheckedRadioButton() -> FToggleButton*;
121  template <typename UnaryPredicate>
122  auto findButtonIf (UnaryPredicate) const -> FToggleButton*;
123  auto needToUncheck (const FToggleButton*, const FToggleButton*) const -> bool;
124 
125  // Callback method
126  void cb_buttonToggled (const FToggleButton*) const;
127 
128  // Data members
129  FString text{};
130  FObjectList buttonlist{};
131 };
132 
133 // FButtonGroup inline functions
134 //----------------------------------------------------------------------
135 inline auto FButtonGroup::getClassName() const -> FString
136 { return "FButtonGroup"; }
137 
138 //----------------------------------------------------------------------
139 inline void FButtonGroup::unsetEnable()
140 { setEnable(false); }
141 
142 //----------------------------------------------------------------------
143 inline void FButtonGroup::setDisable()
144 { setEnable(false); }
145 
146 //----------------------------------------------------------------------
147 inline auto FButtonGroup::getCount() const -> std::size_t
148 { return buttonlist.size(); }
149 
150 
151 } // namespace finalcut
152 
153 #endif // FBUTTONGROUP_H
Definition: fevent.h:196
Definition: fevent.h:144
Definition: frect.h:56
Definition: class_template.cpp:25
Definition: fscrollview.h:67
Definition: fstring.h:79
Definition: fbuttongroup.h:64
Definition: fwidget.h:129
Definition: fevent.h:220
Definition: ftogglebutton.h:62