FINAL CUT
fmenuitem.h
1 /***********************************************************************
2 * fmenuitem.h - Widget FMenuItem *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2015-2024 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Inheritance diagram
24  * ═══════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
27  * ▕ FVTerm ▏ ▕ FObject ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
29  * ▲ ▲
30  * │ │
31  * └─────┬─────┘
32  * │
33  * ▕▔▔▔▔▔▔▔▔▔▏
34  * ▕ FWidget ▏
35  * ▕▁▁▁▁▁▁▁▁▁▏
36  * ▲
37  * │
38  * ▕▔▔▔▔▔▔▔▔▔▔▔▏* 1▕▔▔▔▔▔▔▔▏
39  * ▕ FMenuItem ▏-┬- - - -▕ FMenu ▏
40  * ▕▁▁▁▁▁▁▁▁▁▁▁▏ : ▕▁▁▁▁▁▁▁▏
41  * :
42  * : 1▕▔▔▔▔▔▔▔▔▔▔▔▏
43  * └- - - -▕ FMenuList ▏
44  * ▕▁▁▁▁▁▁▁▁▁▁▁▏
45  */
46 
47 #ifndef FMENUITEM_H
48 #define FMENUITEM_H
49 
50 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
51  #error "Only <final/final.h> can be included directly."
52 #endif
53 
54 #include "final/fwidget.h"
55 
56 namespace finalcut
57 {
58 
59 // class forward declaration
60 class FDialog;
61 class FMenu;
62 class FMenuList;
63 
64 //----------------------------------------------------------------------
65 // class FMenuItem
66 //----------------------------------------------------------------------
67 
68 class FMenuItem : public FWidget
69 {
70  public:
71  // Using-declarations
72  using FWidget::addAccelerator;
73  using FWidget::delAccelerator;
74  using FWidget::setEnable;
75 
76  // Constructor
77  explicit FMenuItem (FWidget* = nullptr);
78  explicit FMenuItem (FString&&, FWidget* = nullptr);
79  FMenuItem (FKey, FString&&, FWidget* = nullptr);
80 
81  // Disable copy constructor
82  FMenuItem (const FMenuItem&) = delete;
83 
84  // Disable move constructor
85  FMenuItem (FMenuItem&&) noexcept = delete;
86 
87  // Destructor
88  ~FMenuItem() override;
89 
90  // Disable copy assignment operator (=)
91  auto operator = (const FMenuItem&) -> FMenuItem& = delete;
92 
93  // Disable move assignment operator (=)
94  auto operator = (FMenuItem&&) noexcept -> FMenuItem& = delete;
95  // Accessors
96  auto getClassName() const -> FString override;
97  auto getHotkey() const noexcept -> FKey;
98  auto getMenu() const -> FMenu*;
99  auto getTextLength() const noexcept -> std::size_t;
100  auto getTextWidth() const noexcept -> std::size_t;
101  auto getText() const -> FString;
102 
103  // Mutators
104  void setEnable (bool = true) override;
105  void setSelected();
106  void unsetSelected();
107  void setSeparator();
108  void unsetSeparator();
109  void setCheckable() noexcept;
110  void unsetCheckable() noexcept;
111  void setChecked() noexcept;
112  void unsetChecked() noexcept;
113  void setRadioButton() noexcept;
114  void unsetRadioButton() noexcept;
115  void setMenu (FMenu*);
116  void setText (const FString&);
117 
118  // Inquiries
119  auto isSelected() const -> bool;
120  auto isSeparator() const -> bool;
121  auto isCheckable() const -> bool;
122  auto isChecked() const -> bool;
123  auto isRadioButton() const -> bool;
124  auto hasHotkey() const -> bool;
125  auto hasMenu() const -> bool;
126 
127  // Methods
128  void addAccelerator (FKey, FWidget*) & final;
129  void delAccelerator (FWidget*) & final;
130  void openMenu() const;
131 
132  // Event handlers
133  void onKeyPress (FKeyEvent*) override;
134  void onMouseDoubleClick (FMouseEvent*) override;
135  void onMouseDown (FMouseEvent*) override;
136  void onMouseUp (FMouseEvent*) override;
137  void onMouseMove (FMouseEvent*) override;
138  void onAccel (FAccelEvent*) override;
139  void onFocusIn (FFocusEvent*) override;
140  void onFocusOut (FFocusEvent*) override;
141 
142  protected:
143  // Accessor
144  auto getSuperMenu() const -> FWidget*;
145 
146  // Mutator
147  void setSuperMenu (FWidget*);
148 
149  // Inquiries
150  auto isDialog (const FWidget*) const -> bool;
151  auto isMenuBar (const FWidget*) const -> bool;
152  auto isMenu (const FWidget*) const -> bool;
153 
154  // Method
155  void initLayout() override;
156 
157  private:
158  // Accessor
159  auto getFMenuList (FWidget&) -> FMenuList*;
160 
161  // Methods
162  void init();
163  void calculateTextDimensions();
164  void updateSuperMenuDimensions();
165  void updateMenubarDimensions() const;
166  void processEnable() const;
167  void processDisable() const;
168  void processActivate() const;
169  void processDeactivate() const;
170  void createDialogList (FMenu*) const;
171  template <typename T>
172  void passMouseEvent (T, const FMouseEvent*, Event) const;
173  void resetSelectedItem (const FMenuList*) const;
174 
175  // Callback methods
176  void cb_switchToDialog (FDialog*) const;
177  void cb_destroyDialog (FDialog*);
178 
179  virtual void processClicked();
180 
181  // Data members
182  FString text{};
183  FMenu* menu{nullptr};
184  FWidget* super_menu{nullptr};
185  FDialog* associated_window{nullptr};
186  std::size_t text_length{0};
187  std::size_t text_width{0};
188  FKey accel_key{FKey::None};
189  FKey hotkey{FKey::None};
190  bool selected{false};
191  bool separator{false};
192  bool checkable{false};
193  bool checked{false};
194  bool radio_button{false};
195  bool dialog_index{false};
196 
197  // Friend classes
198  friend class FDialogListMenu;
199  friend class FMenuList;
200  friend class FMenuBar;
201  friend class FMenu;
202 };
203 
204 
205 // FMenuItem inline functions
206 //----------------------------------------------------------------------
207 inline auto FMenuItem::getClassName() const -> FString
208 { return "FMenuItem"; }
209 
210 //----------------------------------------------------------------------
211 inline auto FMenuItem::getHotkey() const noexcept -> FKey
212 { return hotkey; }
213 
214 //----------------------------------------------------------------------
215 inline auto FMenuItem::getMenu() const -> FMenu*
216 { return menu; }
217 
218 //----------------------------------------------------------------------
219 inline auto FMenuItem::getTextLength() const noexcept -> std::size_t
220 { return text_length; }
221 
222 //----------------------------------------------------------------------
223 inline auto FMenuItem::getTextWidth() const noexcept -> std::size_t
224 { return text_width; }
225 
226 //----------------------------------------------------------------------
227 inline auto FMenuItem::getText() const -> FString
228 { return text; }
229 
230 //----------------------------------------------------------------------
231 inline void FMenuItem::setSeparator()
232 {
233  separator = true;
234  unsetFocusable();
235 }
236 
237 //----------------------------------------------------------------------
238 inline void FMenuItem::unsetSeparator()
239 {
240  separator = false;
241  setFocusable();
242 }
243 
244 //----------------------------------------------------------------------
245 inline void FMenuItem::setCheckable() noexcept
246 { checkable = true; }
247 
248 //----------------------------------------------------------------------
249 inline void FMenuItem::unsetCheckable() noexcept
250 { checkable = false; }
251 
252 //----------------------------------------------------------------------
253 inline void FMenuItem::setChecked() noexcept
254 { checked = true; }
255 
256 //----------------------------------------------------------------------
257 inline void FMenuItem::unsetChecked() noexcept
258 { checked = false; }
259 
260 //----------------------------------------------------------------------
261 inline void FMenuItem::setRadioButton() noexcept
262 { radio_button = true; }
263 
264 //----------------------------------------------------------------------
265 inline void FMenuItem::unsetRadioButton() noexcept
266 { radio_button = false; }
267 
268 //----------------------------------------------------------------------
269 inline void FMenuItem::setMenu(FMenu* m)
270 { menu = m; }
271 
272 //----------------------------------------------------------------------
273 inline auto FMenuItem::isSelected() const -> bool
274 { return selected; }
275 
276 //----------------------------------------------------------------------
277 inline auto FMenuItem::isSeparator() const -> bool
278 { return separator; }
279 
280 //----------------------------------------------------------------------
281 inline auto FMenuItem::isCheckable() const -> bool
282 { return checkable; }
283 
284 //----------------------------------------------------------------------
285 inline auto FMenuItem::isChecked() const -> bool
286 { return checked; }
287 
288 //----------------------------------------------------------------------
289 inline auto FMenuItem::isRadioButton() const -> bool
290 { return radio_button; }
291 
292 //----------------------------------------------------------------------
293 inline auto FMenuItem::hasHotkey() const -> bool
294 { return hotkey != FKey::None; }
295 
296 //----------------------------------------------------------------------
297 inline auto FMenuItem::hasMenu() const -> bool
298 { return menu != nullptr; }
299 
300 //----------------------------------------------------------------------
301 inline auto FMenuItem::getSuperMenu() const -> FWidget*
302 { return super_menu; }
303 
304 //----------------------------------------------------------------------
305 inline void FMenuItem::setSuperMenu (FWidget* smenu)
306 { super_menu = smenu; }
307 
308 } // namespace finalcut
309 
310 #endif // FMENUITEM_H
Definition: fevent.h:196
Definition: fmenulist.h:58
Definition: fevent.h:144
Definition: fmenu.h:75
Definition: fmenubar.h:70
Definition: class_template.cpp:25
Definition: fmenuitem.h:68
Definition: fdialoglistmenu.h:70
Definition: fstring.h:79
Definition: fdialog.h:69
Definition: fwidget.h:129
Definition: fevent.h:220
Definition: fevent.h:124