FINAL CUT
fstatusbar.h
1 /***********************************************************************
2 * fstatusbar.h - Widget FStatusBar and FStatusKey *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2014-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  * ├────────────────────┐
39  * │ │
40  * ▕▔▔▔▔▔▔▔▔▔▏ │
41  * ▕ FWindow ▏ │
42  * ▕▁▁▁▁▁▁▁▁▁▏ │
43  * ▲ │
44  * │ │
45  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▏
46  * ▕ FStatusBar ▏- - - -▕ FStatusKey ▏
47  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
48  */
49 
50 #ifndef FSTATUSBAR_H
51 #define FSTATUSBAR_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 <memory>
58 #include <vector>
59 
60 #include "final/fwidget.h"
61 #include "final/widget/fwindow.h"
62 
63 namespace finalcut
64 {
65 
66 // class forward declaration
67 class FStatusBar;
68 
69 //----------------------------------------------------------------------
70 // class FStatusKey
71 //----------------------------------------------------------------------
72 
73 class FStatusKey : public FWidget
74 {
75  public:
76  // Using-declaration
77  using FWidget::delAccelerator;
78 
79  // Constructors
80  explicit FStatusKey (FWidget* = nullptr);
81  FStatusKey (FKey, FString&&, FWidget* = nullptr);
82 
83  // Disable copy constructor
84  FStatusKey (const FStatusKey&) = delete;
85 
86  // Disable move constructor
87  FStatusKey (FStatusKey&&) noexcept = delete;
88 
89  // Destructor
90  ~FStatusKey() override;
91 
92  // Disable copy assignment operator (=)
93  auto operator = (const FStatusKey&) -> FStatusKey& = delete;
94 
95  // Disable move assignment operator (=)
96  auto operator = (FStatusKey&&) noexcept -> FStatusKey& = delete;
97 
98  // Accessors
99  auto getClassName() const -> FString override;
100  virtual auto getKey() const noexcept -> FKey;
101  virtual auto getText() const -> FString;
102 
103  // Mutators
104  void setKey (FKey) noexcept;
105  void setText (const FString&);
106  void setActive();
107  void unsetActive() noexcept;
108  void setMouseFocus (bool = true);
109  void unsetMouseFocus();
110 
111  // Inquiry
112  auto isActivated() const noexcept -> bool;
113  auto hasMouseFocus() const noexcept -> bool;
114 
115  // Event handler
116  void onAccel (FAccelEvent*) override;
117 
118  private:
119  // Methods
120  void init();
121  void processActivate() const;
122  auto getConnectedStatusbar() const -> FStatusBar*;
123  void setConnectedStatusbar (FStatusBar*);
124 
125  // Data members
126  FString text{};
127  FStatusBar* bar{nullptr};
128  FKey key{};
129  bool active{false};
130  bool mouse_focus{false};
131 
132  // Friend class
133  friend class FStatusBar;
134 };
135 
136 
137 // FStatusKey inline functions
138 //----------------------------------------------------------------------
139 inline auto FStatusKey::getClassName() const -> FString
140 { return "FStatusKey"; }
141 
142 //----------------------------------------------------------------------
143 inline auto FStatusKey::getKey() const noexcept -> FKey
144 { return key; }
145 
146 //----------------------------------------------------------------------
147 inline auto FStatusKey::getText() const -> FString
148 { return text; }
149 
150 //----------------------------------------------------------------------
151 inline void FStatusKey::setKey (FKey k) noexcept
152 { key = k; }
153 
154 //----------------------------------------------------------------------
155 inline void FStatusKey::setText (const FString& txt)
156 { text.setString(txt); }
157 
158 //----------------------------------------------------------------------
159 inline void FStatusKey::unsetActive() noexcept
160 { active = false; }
161 
162 //----------------------------------------------------------------------
163 inline void FStatusKey::unsetMouseFocus()
164 { setMouseFocus(false); }
165 
166 //----------------------------------------------------------------------
167 inline auto FStatusKey::isActivated() const noexcept -> bool
168 { return active; }
169 
170 //----------------------------------------------------------------------
171 inline auto FStatusKey::hasMouseFocus() const noexcept -> bool
172 { return mouse_focus; }
173 
174 //----------------------------------------------------------------------
175 inline auto FStatusKey::getConnectedStatusbar() const -> FStatusBar*
176 { return bar; }
177 
178 //----------------------------------------------------------------------
179 inline void FStatusKey::setConnectedStatusbar (FStatusBar* sb)
180 { bar = sb; }
181 
182 
183 //----------------------------------------------------------------------
184 // class FStatusBar
185 //----------------------------------------------------------------------
186 
187 class FStatusBar : public FWindow
188 {
189  public:
190  // Using-declaration
191  using FWidget::delAccelerator;
192 
193  // Constructor
194  explicit FStatusBar (FWidget* = nullptr);
195 
196  // Destructor
197  ~FStatusBar() override;
198 
199  // Accessors
200  auto getClassName() const -> FString override;
201  auto getStatusKey (int) const -> FStatusKey*;
202  auto getMessage() const -> FString;
203  auto getCount() const -> std::size_t;
204 
205  // Mutators
206  void activateKey (int);
207  void deactivateKey (int);
208  void setMessage (const FString&);
209  void resetColors() override;
210 
211  // Inquiries
212  auto isActivated (int) const -> bool;
213  auto hasActivatedKey() const -> bool;
214 
215  // Methods
216  void hide() override;
217  void drawMessage();
218  void clearMessage();
219  void insert (FStatusKey*);
220  void remove (FStatusKey*);
221  void remove (int);
222  void clear();
223  void adjustSize() override;
224 
225  // Event handlers
226  void onMouseDown (FMouseEvent*) override;
227  void onMouseUp (FMouseEvent*) override;
228  void onMouseMove (FMouseEvent*) override;
229 
230  // Callback method
231  void cb_statuskey_activated (const FStatusKey*);
232 
233  private:
234  // Using-declaration
235  using FKeyList = std::vector<FStatusKey*>;
236 
237  // Methods
238  void init();
239  auto getKeyNameWidth (const FStatusKey*) const -> int;
240  auto getKeyTextWidth (const FStatusKey*) const -> int;
241  void draw() override;
242  void drawKeys();
243  void drawKey (FKeyList::const_iterator);
244  void drawKeySeparator (FKeyList::const_iterator);
245  void drawActiveKey (FKeyList::const_iterator);
246  void drawHotKeyName (FKeyList::const_iterator, const FColorPair);
247  auto canPrintLeftActiveKeySeparator (FKeyList::const_iterator) const -> bool;
248  auto canPrintKeySeparator (FKeyList::const_iterator) const -> bool;
249  auto canDrawMessage() const -> bool;
250  auto isLastActiveFocus() const -> bool;
251  auto isClickInsideRange (const FMouseEvent*, const int, const int) const -> bool;
252  void setStatusBarColor() const;
253  void nonLeftButtonClick();
254  void leftButtonClick (const FMouseEvent*);
255  void printMessageWithEllipsis (std::size_t);
256  void printPaddingSpaces (int);
257 
258  // Data members
259  FKeyList key_list{};
260  FString text{""};
261  std::size_t screenWidth{80};
262  int keyname_len{0};
263  int x{-1};
264  int x_msg{-1};
265  bool mouse_down{};
266 };
267 
268 
269 // FStatusBar inline functions
270 //----------------------------------------------------------------------
271 inline auto FStatusBar::getClassName() const -> FString
272 { return "FStatusBar"; }
273 
274 //----------------------------------------------------------------------
275 inline auto FStatusBar::getStatusKey (int index) const -> FStatusKey*
276 { return key_list[uInt(index - 1)]; }
277 
278 //----------------------------------------------------------------------
279 inline auto FStatusBar::getCount() const -> std::size_t
280 { return key_list.size(); }
281 
282 //----------------------------------------------------------------------
283 inline void FStatusBar::activateKey (int index)
284 { key_list[uInt(index - 1)]->setActive(); }
285 
286 //----------------------------------------------------------------------
287 inline void FStatusBar::deactivateKey (int index)
288 { key_list[uInt(index - 1)]->unsetActive(); }
289 
290 //----------------------------------------------------------------------
291 inline auto FStatusBar::isActivated(int index) const -> bool
292 { return key_list[uInt(index - 1)]->isActivated(); }
293 
294 //----------------------------------------------------------------------
295 inline auto FStatusBar::getMessage() const -> FString
296 { return text; }
297 
298 //----------------------------------------------------------------------
299 inline void FStatusBar::clearMessage()
300 { text.clear(); }
301 
302 } // namespace finalcut
303 
304 #endif // FSTATUSBAR_H
Definition: fwindow.h:67
Definition: fstatusbar.h:187
Definition: fevent.h:144
Definition: class_template.cpp:25
Definition: fstatusbar.h:73
Definition: fstring.h:79
Definition: fwidget.h:129
Definition: fcolorpair.h:49
Definition: fevent.h:220