FINAL CUT
fmenubar.h
1 /***********************************************************************
2 * fmenubar.h - Widget FMenuBar *
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  * ▕ FWindow ▏ ▕ FMenuList ▏- - - -▕ FMenuItem ▏
40  * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏
41  * ▲ ▲
42  * │ │
43  * └─────┬─────┘
44  * │
45  * ▕▔▔▔▔▔▔▔▔▔▔▏
46  * ▕ FMenuBar ▏
47  * ▕▁▁▁▁▁▁▁▁▁▁▏
48  */
49 
50 #ifndef FMENUBAR_H
51 #define FMENUBAR_H
52 
53 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
54  #error "Only <final/final.h> can be included directly."
55 #endif
56 
57 #include "final/menu/fmenulist.h"
58 #include "final/widget/fwindow.h"
59 
60 namespace finalcut
61 {
62 
63 // class forward declaration
64 class FMenu;
65 
66 //----------------------------------------------------------------------
67 // class FMenuBar
68 //----------------------------------------------------------------------
69 
70 class FMenuBar : public FWindow
71  , public FMenuList
72 {
73  public:
74  // Using-declaration
75  using FWidget::addAccelerator;
76 
77  // Constructor
78  explicit FMenuBar (FWidget* = nullptr);
79 
80  // Destructor
81  ~FMenuBar() override;
82 
83  // Accessors
84  auto getClassName() const -> FString override;
85 
86  // Methods
87  void resetColors() override;
88  void resetMenu();
89  void hide() override;
90  void adjustSize() override;
91 
92  // Event handlers
93  void onKeyPress (FKeyEvent*) override;
94  void onMouseDown (FMouseEvent*) override;
95  void onMouseUp (FMouseEvent*) override;
96  void onMouseMove (FMouseEvent*) override;
97  void onAccel (FAccelEvent*) override;
98 
99  // Callback methods
100  void cb_itemDeactivated (const FMenuItem*) const;
101 
102  private:
103  struct menuText
104  {
105  FString text;
106  std::size_t startpos;
107  std::size_t hotkeypos;
108  bool no_underline;
109  };
110 
111  // Constants
112  static constexpr auto NOT_SET = static_cast<std::size_t>(-1);
113 
114  // Inquiry
115  auto isMenu (const FMenuItem*) const -> bool;
116 
117  // Methods
118  void init();
119  void calculateDimensions() const;
120  void selectItem_PostProcessing (FMenuItem*) override;
121  auto hotkeyMenu (FKeyEvent*&) -> bool;
122  void draw() override;
123  void drawItems();
124  void drawItem (FMenuItem*, std::size_t&);
125  void setLineAttributes (const FMenuItem*);
126  void setCursorToHotkeyPosition (FMenuItem*, std::size_t) const;
127  void drawMenuText (menuText&);
128  void drawEllipsis (const menuText&, std::size_t);
129  void drawLeadingSpace (std::size_t&);
130  void drawTrailingSpace (std::size_t&);
131  void adjustItems() const;
132  void openMenu (const FMenuItem*);
133  auto activateMenu (const FMenuItem*) -> bool;
134  auto clickItem (FMenuItem*) -> bool;
135  void unselectMenuItem (FMenuItem*);
136  void selectMenuItem (FMenuItem*);
137  auto isClickOnMenuEntry (const FMouseEvent*, const FMenuItem*) const -> bool;
138  void mouseDownOverList (const FMouseEvent*);
139  void mouseUpOverList (const FMouseEvent*);
140  void mouseMoveOverList (const FMouseEvent&);
141  void passEventToMenu (const FMouseEvent&) const;
142  void leaveMenuBar();
143 
144  // Data members
145  std::size_t screenWidth{80};
146  bool mouse_down{false};
147  bool drop_down{false};
148  bool focus_changed{false};
149 
150  // Friend classes
151  friend class FMenu;
152  friend class FMenuItem;
153 };
154 
155 
156 // FMenuBar inline functions
157 //----------------------------------------------------------------------
158 inline auto FMenuBar::getClassName() const -> FString
159 { return "FMenuBar"; }
160 
161 //----------------------------------------------------------------------
162 inline auto FMenuBar::isMenu (const FMenuItem* mi) const -> bool
163 { return mi->hasMenu(); }
164 
165 } // namespace finalcut
166 
167 #endif // FMENUBAR_H
Definition: fwindow.h:67
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: fstring.h:79
Definition: fwidget.h:129
Definition: fevent.h:220
Definition: fevent.h:124