FINAL CUT
fwidget.h
1 /***********************************************************************
2 * fwidget.h - Intermediate base class for all widget objects *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2015-2026 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  * ▕▔▔▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▔▔▔▔▔▏
34  * ▕ FWidget ▏-┬- - - -▕ FStatusBar ▏
35  * ▕▁▁▁▁▁▁▁▁▁▏ : ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
36  * :
37  * : 1▕▔▔▔▔▔▔▔▔▔▔▏
38  * :- - - -▕ FMenuBar ▏
39  * : ▕▁▁▁▁▁▁▁▁▁▁▏
40  *
41  * : 1▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
42  * :- - - -▕ FWidgetColors ▏
43  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
44  * :
45  * : *▕▔▔▔▔▔▔▔▔▔▏
46  * :- - - -▕ FString ▏
47  * : ▕▁▁▁▁▁▁▁▁▁▏
48  * :
49  * : *▕▔▔▔▔▔▔▔▔▏
50  * :- - - -▕ FEvent ▏
51  * : ▕▁▁▁▁▁▁▁▁▏
52  * :
53  * : *▕▔▔▔▔▔▔▔▔▔▔▔▏
54  * :- - - -▕ FKeyEvent ▏
55  * : ▕▁▁▁▁▁▁▁▁▁▁▁▏
56  * :
57  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
58  * :- - - -▕ FMouseEvent ▏
59  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
60  * :
61  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
62  * :- - - -▕ FWheelEvent ▏
63  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
64  * :
65  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
66  * :- - - -▕ FFocusEvent ▏
67  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
68  * :
69  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
70  * :- - - -▕ FAccelEvent ▏
71  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
72  * :
73  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
74  * :- - - -▕ FResizeEvent ▏
75  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
76  * :
77  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▏
78  * :- - - -▕ FShowEvent ▏
79  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
80  * :
81  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▏
82  * :- - - -▕ FHideEvent ▏
83  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
84  * :
85  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
86  * └- - - -▕ FCloseEvent ▏
87  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
88  */
89 
90 #ifndef FWIDGET_H
91 #define FWIDGET_H
92 
93 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
94  #error "Only <final/final.h> can be included directly."
95 #endif
96 
97 #include <functional>
98 #include <memory>
99 #include <unordered_map>
100 #include <utility>
101 #include <vector>
102 
103 #include "final/fobject.h"
104 #include "final/ftypes.h"
105 #include "final/fwidget_flags.h"
106 #include "final/fwidget_functions.h"
107 #include "final/output/foutput.h"
108 #include "final/util/fcallback.h"
109 #include "final/util/fpoint.h"
110 #include "final/util/frect.h"
111 #include "final/util/fsize.h"
112 #include "final/vterm/fvterm.h"
113 
114 namespace finalcut
115 {
116 
117 // class forward declaration
118 class FMenuBar;
119 class FRect;
120 class FResizeEvent;
121 class FSize;
122 class FStatusBar;
123 class FWidgetColors;
124 
125 //----------------------------------------------------------------------
126 // class FWidget
127 //----------------------------------------------------------------------
128 
129 class FWidget : public FVTerm
130  , public FObject
131 {
132  public:
134  {
135  alignas(8) FKey key;
136  FWidget* object;
137  };
138 
139  // Using-declarations
140  using FVTerm::setColor;
141  using FVTerm::print;
142  using FWidgetList = std::vector<FWidget*>;
143  using FAcceleratorList = std::vector<FAccelerator>;
144 
145  // Constructor
146  explicit FWidget (FWidget* = nullptr);
147 
148  // Destructor
149  ~FWidget() override;
150 
151  // Accessors
152  auto getClassName() const -> FString override;
153  auto getRootWidget() const -> FWidget*;
154  auto getParentWidget() const -> FWidget*;
155  static auto getMainWidget() -> FWidget*&;
156  static auto getActiveWindow() -> FWidget*&;
157  static auto getFocusWidget() -> FWidget*&;
158  static auto getClickedWidget() -> FWidget*&;
159  static auto getOpenMenu() -> FWidget*&;
160  static auto getMoveResizeWidget() -> FWidget*&;
161  static auto getMenuBar() -> FMenuBar*;
162  static auto getStatusBar() -> FStatusBar*;
163  static auto getColorTheme() -> std::shared_ptr<FWidgetColors>&;
164  auto getAcceleratorList() const & -> const FAcceleratorList&;
165  auto getStatusBarMessage() const -> FString;
166  auto getForegroundColor() const noexcept -> FColor; // get the primary
167  auto getBackgroundColor() const noexcept -> FColor; // widget colors
168  auto doubleFlatLine_ref (Side) -> std::vector<bool>&;
169  // Positioning and sizes accessors...
170  auto getX() const -> int;
171  auto getY() const -> int;
172  auto getPos() const -> FPoint;
173  auto getTermX() const -> int;
174  auto getTermY() const -> int;
175  auto getTermPos() const -> FPoint;
176  auto getWidth() const -> std::size_t;
177  auto getHeight() const -> std::size_t;
178  auto getSize() const -> FSize;
179  auto getTopPadding() const noexcept -> int;
180  auto getLeftPadding() const noexcept -> int;
181  auto getBottomPadding() const noexcept -> int;
182  auto getRightPadding() const noexcept -> int;
183  auto getClientWidth() const -> std::size_t;
184  auto getClientHeight() const -> std::size_t;
185  auto getClientSize() const -> FSize;
186  auto getMaxWidth() const -> std::size_t;
187  auto getMaxHeight() const -> std::size_t;
188  auto getShadow() const & -> const FSize&;
189  auto getGeometry() const & -> const FRect&;
190  auto getGeometryWithShadow() & -> const FRect&;
191  auto getTermGeometry() & -> const FRect&;
192  auto getTermGeometryWithShadow() & -> const FRect&;
193  auto getDesktopWidth() const -> std::size_t;
194  auto getDesktopHeight() const -> std::size_t;
195  auto getFlags() const & -> const FWidgetFlags&;
196  auto getCursorPos() const -> FPoint;
197  auto getPrintPos() -> FPoint;
198 
199  // Mutators
200  static void setMainWidget (FWidget*);
201  static void setFocusWidget (FWidget*);
202  static void setClickedWidget (FWidget*);
203  static void setMoveSizeWidget (FWidget*);
204  static void setActiveWindow (FWidget*);
205  static void setOpenMenu (FWidget*);
206  template <typename ClassT>
207  static void setColorTheme();
208  auto setAcceleratorList() & -> FAcceleratorList&;
209  virtual void setStatusBarMessage (const FString&);
210  void setVisible (bool = true);
211  void unsetVisible();
212  virtual void setEnable (bool = true);
213  virtual void unsetEnable();
214  virtual void setDisable();
215  virtual void setVisibleCursor (bool = true); // input cursor visibility
216  virtual void unsetVisibleCursor(); // for the widget
217  virtual auto setFocus ( bool = true
218  , FocusTypes = FocusTypes::DefiniteWidget) -> bool;
219  virtual auto unsetFocus() -> bool;
220  void setFocusable (bool = true);
221  void unsetFocusable();
222  auto ignorePadding (bool = true) -> bool; // ignore padding from
223  auto acceptPadding() -> bool; // the parent widget
224  virtual void setForegroundColor (FColor);
225  virtual void setBackgroundColor (FColor);
226  virtual void resetColors();
227  void useParentWidgetColor();
228  void setColor() const;
229  auto setFlags() & -> FWidgetFlags&;
230  // Positioning and sizes mutators...
231  virtual void setX (int, bool = true);
232  virtual void setY (int, bool = true);
233  virtual void setPos (const FPoint&, bool = true);
234  virtual void setWidth (std::size_t, bool = true);
235  virtual void setHeight (std::size_t, bool = true);
236  virtual void setSize (const FSize&, bool = true);
237  void setTopPadding (int, bool = true);
238  void setLeftPadding (int, bool = true);
239  void setBottomPadding (int, bool = true);
240  void setRightPadding (int, bool = true);
241  void setTerminalSize (const FSize&) const;
242  virtual void setGeometry (const FRect&, bool = true);
243  virtual void setGeometry (const FPoint&, const FSize&, bool = true);
244  virtual void setShadowSize (const FSize&);
245  void setMinimumWidth (std::size_t);
246  void setMinimumHeight (std::size_t);
247  void setMinimumSize (const FSize&);
248  void setMaximumWidth (std::size_t);
249  void setMaximumHeight (std::size_t);
250  void setMaximumSize (const FSize&);
251  void setFixedSize (const FSize&);
252  virtual auto setCursorPos (const FPoint&) -> bool;
253  void unsetCursorPos();
254  virtual void setPrintPos (const FPoint&);
255  void setMergingBorder (Side, bool = true);
256  void unsetMergingBorder (Side);
257  void setMergingBorder (Side, int, bool = true);
258  void unsetMergingBorder (Side, int);
259 
260  // Predicates
261  auto isRootWidget() const -> bool;
262  auto isWindowWidget() const -> bool;
263  auto isDialogWidget() const -> bool;
264  auto isMenuWidget() const -> bool;
265  auto isVisible() const -> bool;
266  auto isShown() const -> bool;
267  auto isHidden() const -> bool;
268  auto isEnabled() const -> bool;
269  auto hasVisibleCursor() const -> bool;
270  auto hasFocus() const -> bool;
271  auto acceptFocus() const -> bool; // is focusable
272  auto isPaddingIgnored() const -> bool;
273 
274  // Methods
275  auto childWidgetAt (const FPoint&) & -> FWidget*;
276  auto numOfFocusableChildren() & -> int;
277  virtual auto close() -> bool;
278  void clearStatusBarMessage();
279  template <typename... Args>
280  void addCallback (FString&&, Args&&...) & noexcept;
281  template <typename... Args>
282  void delCallback (Args&&...) & noexcept;
283  void emitCallback (const FString&) const &;
284  void addAccelerator (FKey) &;
285  virtual void addAccelerator (FKey, FWidget*) &;
286  void delAccelerator () &;
287  virtual void delAccelerator (FWidget*) &;
288  virtual void flushChanges();
289  virtual void redraw();
290  virtual void resize();
291  virtual void show();
292  virtual void hide();
293  virtual auto focusNextChild() -> bool; // Change child...
294  virtual auto focusPrevChild() -> bool; // ...focus
295  virtual auto focusFirstChild() & -> bool;
296  virtual auto focusLastChild() & -> bool;
297  auto termToWidgetPos (const FPoint&) const -> FPoint;
298  void print (const FPoint&) override;
299  virtual void move (const FPoint&);
300  virtual void drawBorder();
301  static void quit();
302 
303  protected:
304  // Accessor
305  auto getPrintRegion() -> FTermRegion* override;
306  static auto getModalDialogCounter() -> uInt;
307  static auto getDialogList() -> FWidgetList*&;
308  static auto getAlwaysOnTopList() -> FWidgetList*&;
309  static auto getWidgetCloseList() -> FWidgetList*&;
310  void addPreprocessingHandler ( const FVTerm*
311  , FPreprocessingFunction&& ) override;
312  void delPreprocessingHandler (const FVTerm*) override;
313 
314  // Predicate
315  auto isChildPrintRegion() const -> bool;
316 
317  // Mutators
318  virtual void setStatusBar (FStatusBar*);
319  virtual void setMenuBar (FMenuBar*);
320  static auto setModalDialogCounter() -> uInt&;
321  void setParentOffset();
322  void setTermOffset();
323  void setTermOffsetWithPadding();
324 
325  // Methods
326  void initTerminal() override;
327  void initDesktop();
328  virtual void initLayout();
329  virtual void adjustSize();
330  void adjustSizeGlobal();
331  void hideRegion (const FSize&);
332 
333  // Event handlers
334  auto event (FEvent*) -> bool override;
335  virtual void onKeyPress (FKeyEvent*);
336  virtual void onKeyUp (FKeyEvent*);
337  virtual void onKeyDown (FKeyEvent*);
338  virtual void onMouseDown (FMouseEvent*);
339  virtual void onMouseUp (FMouseEvent*);
340  virtual void onMouseDoubleClick (FMouseEvent*);
341  virtual void onWheel (FWheelEvent*);
342  virtual void onMouseMove (FMouseEvent*);
343  virtual void onFocusIn (FFocusEvent*);
344  virtual void onFocusOut (FFocusEvent*);
345  virtual void onChildFocusIn (FFocusEvent*);
346  virtual void onChildFocusOut (FFocusEvent*);
347  virtual void onTermFocusIn (FFocusEvent*);
348  virtual void onTermFocusOut (FFocusEvent*);
349  virtual void onFailAtChildFocus (FFocusEvent*);
350  virtual void onAccel (FAccelEvent*);
351  virtual void onResize (FResizeEvent*);
352  virtual void onShow (FShowEvent*);
353  virtual void onHide (FHideEvent*);
354  virtual void onClose (FCloseEvent*);
355 
356  private:
357  // Using-declaration
358  using EventHandler = std::function<void(FEvent*)>;
359  using EventMap = std::unordered_map<Event, EventHandler, EnumHash<Event>>;
360 
361  struct WidgetSizeHints
362  {
363  WidgetSizeHints() = default;
364  ~WidgetSizeHints() = default;
365 
366  inline void setMinimum (const FSize& s)
367  {
368  min_width = s.getWidth();
369  min_height = s.getHeight();
370  }
371 
372  inline void setMaximum (const FSize& s)
373  {
374  max_width = s.getWidth();
375  max_height = s.getHeight();
376  }
377 
378  std::size_t min_width{0};
379  std::size_t min_height{0};
380  std::size_t max_width{INT_MAX};
381  std::size_t max_height{INT_MAX};
382  };
383 
384  struct MergingBorderMask
385  {
386  MergingBorderMask() = default;
387  ~MergingBorderMask() = default;
388 
389  inline void setWidth (std::size_t width)
390  {
391  if ( top.size() == width && bottom.size() == width )
392  return;
393 
394  top.resize (width, false);
395  bottom.resize (width, false);
396  }
397 
398  inline void setHeight (std::size_t height)
399  {
400  if ( right.size() == height && left.size() == height )
401  return;
402 
403  right.resize (height, false);
404  left.resize (height, false);
405  }
406 
407  inline void setSize (std::size_t width, std::size_t height)
408  {
409  setWidth (width);
410  setHeight (height);
411  }
412 
413  std::vector<bool> top{};
414  std::vector<bool> right{};
415  std::vector<bool> bottom{};
416  std::vector<bool> left{};
417  };
418 
419  struct WidgetPadding
420  {
421  WidgetPadding() = default;
422  ~WidgetPadding() = default;
423 
424  int top{0};
425  int left{0};
426  int bottom{0};
427  int right{0};
428  };
429 
430  // Methods
431  void determineDesktopSize();
432  void mapEventFunctions();
433  void mapKeyEvents();
434  void mapMouseEvents();
435  void mapFocusEvents();
436  void mapWidgetEvents();
437  void initRootWidget();
438  void initWidgetLayout();
439  void initDesktopOnShown() const;
440  void finish();
441  void startShow();
442  void finalizeShow() const;
443  void showChildWidgets();
444  void moveLeftIfNotEnoughSpace();
445  void moveUpIfNotEnoughSpace();
446  void reduceWidthIfNotEnoughSpace();
447  void reduceHeightIfNotEnoughSpace();
448  void insufficientSpaceAdjust();
449  void KeyPressEvent (FKeyEvent*);
450  void KeyDownEvent (FKeyEvent*);
451  void emitWheelCallback (const FWheelEvent*) const;
452  void setWindowFocus (bool = true);
453  auto searchForwardForWidget ( const FWidget*
454  , const FWidget*) const -> FObjectList::const_iterator;
455  auto searchBackwardsForWidget ( const FWidget*
456  , const FWidget* ) const -> FObjectList::const_reverse_iterator;
457  auto isViewable() const -> bool;
458  auto canReceiveFocus (const FWidget*) const -> bool;
459  void setFocusOnThisWidget (FocusTypes);
460  auto sendFailAtChildFocusEvent (FWidget*, FocusTypes) const -> bool;
461  auto sendFocusOutEvent (FWidget*, FocusTypes) const -> bool;
462  auto sendFocusInEvent (FWidget*, FocusTypes) const -> bool;
463  void processDestroy() const;
464  virtual void draw();
465  void drawWindows() const;
466  void drawChildren();
467  void adjustWidget();
468  void adjustSizeWithinRegion (FRect&) const;
469  void adjustChildWidgetSizes();
470  void setWindowOffset();
471  void setWidgetOffset (const FWidget*);
472  void setClientOffset();
473  static auto isDefaultTheme() -> bool;
474  static void initColorTheme();
475  void removeQueuedEvent() const;
476  void setStatusBarText (bool = true) const;
477 
478  // Data members
479  struct FWidgetFlags flags{};
480  FPoint widget_cursor_position{-1, -1};
481  WidgetSizeHints size_hints{};
482  MergingBorderMask merging_border_mask{};
483  WidgetPadding padding{};
484 
485  // widget size
486  FRect wsize{1, 1, 1, 1};
487  FRect adjust_wsize{1, 1, 1, 1};
488  FRect adjust_wsize_term{};
489  FRect adjust_wsize_shadow{};
490  FRect adjust_wsize_term_shadow{};
491  // widget offset
492  FRect woffset{};
493  // offset of the widget client region
494  FRect wclient_offset{};
495  // widget shadow size (on the right and bottom side)
496  FSize wshadow{0, 0};
497 
498  // default widget foreground and background color
499  FColor foreground_color{FColor::Default};
500  FColor background_color{FColor::Default};
501  FString status_bar_message{};
502  FAcceleratorList accelerator_list{};
503  EventMap event_map{};
504  FCallback callback_impl{};
505 
506  static FStatusBar* status_bar;
507  static FMenuBar* menu_bar;
508  static FWidget* main_widget;
509  static FWidget* active_window;
510  static FWidget* focus_widget;
511  static FWidget* clicked_widget;
512  static FWidget* open_menu;
513  static FWidget* move_resize_widget;
514  static FWidget* first_shown_widget;
515  static FWidget* redraw_root_widget;
516  static FWidgetList* dialog_list;
517  static FWidgetList* always_on_top_list;
518  static FWidgetList* close_widget_list;
519  static uInt modal_dialog_counter;
520  static bool dont_raise_window;
521  static bool init_terminal;
522  static bool init_desktop;
523 
524  // Friend functions
525  friend struct GenericBoxData;
526  friend struct GenericBlockShadowData;
527  friend void detectTerminalSize();
528  friend void drawShadow (FWidget*);
529  friend void drawTransparentShadow (FWidget*);
530  friend void drawGenericBox (FWidget*, const FRect&, const std::array<wchar_t, 8>&);
531  friend void drawGenericBlockShadow (FWidget*, const std::array<FChar, 4>&);
532  friend void drawVerticalFlatBorder (FWidget*);
533  friend void drawHorizontalFlatBorder (FWidget*);
534  friend void clearVerticalFlatBorder (FWidget*);
535  friend void clearHorizontalFlatBorder (FWidget*);
536 };
537 
538 
539 // FWidget inline functions
540 //----------------------------------------------------------------------
541 inline auto FWidget::getClassName() const -> FString
542 { return "FWidget"; }
543 
544 //----------------------------------------------------------------------
545 inline auto FWidget::getMainWidget() -> FWidget*&
546 { return main_widget; }
547 
548 //----------------------------------------------------------------------
549 inline auto FWidget::getActiveWindow() -> FWidget*& // returns active FWindow object
550 { return active_window; }
551 
552 //----------------------------------------------------------------------
553 inline auto FWidget::getFocusWidget() -> FWidget*&
554 { return focus_widget; }
555 
556 //----------------------------------------------------------------------
557 inline auto FWidget::getClickedWidget() -> FWidget*&
558 { return clicked_widget; }
559 
560 //----------------------------------------------------------------------
561 inline auto FWidget::getOpenMenu() -> FWidget*&
562 { return open_menu; }
563 
564 //----------------------------------------------------------------------
565 inline auto FWidget::getMoveResizeWidget() -> FWidget*&
566 { return move_resize_widget; }
567 
568 //----------------------------------------------------------------------
569 inline auto FWidget::getMenuBar() -> FMenuBar*
570 { return menu_bar; }
571 
572 //----------------------------------------------------------------------
573 inline auto FWidget::getStatusBar() -> FStatusBar*
574 { return status_bar; }
575 
576 //----------------------------------------------------------------------
577 inline auto FWidget::getAcceleratorList() const & -> const FAcceleratorList&
578 { return accelerator_list; }
579 
580 //----------------------------------------------------------------------
581 inline auto FWidget::setAcceleratorList() & -> FAcceleratorList&
582 { return accelerator_list; }
583 
584 //----------------------------------------------------------------------
585 inline auto FWidget::getStatusBarMessage() const -> FString
586 { return status_bar_message; }
587 
588 //----------------------------------------------------------------------
589 inline auto FWidget::getForegroundColor() const noexcept -> FColor
590 { return foreground_color; }
591 
592 //----------------------------------------------------------------------
593 inline auto FWidget::getBackgroundColor() const noexcept -> FColor
594 { return background_color; }
595 
596 //----------------------------------------------------------------------
597 inline auto FWidget::getX() const -> int // x-position relative to the widget
598 { return adjust_wsize.getX(); }
599 
600 //----------------------------------------------------------------------
601 inline auto FWidget::getY() const -> int // y-position relative to the widget
602 { return adjust_wsize.getY(); }
603 
604 //----------------------------------------------------------------------
605 inline auto FWidget::getPos() const -> FPoint // position relative to the widget
606 {
607  const FPoint& pos = adjust_wsize.getPos(); // initialize pos
608  return pos;
609 }
610 
611 //----------------------------------------------------------------------
612 inline auto FWidget::getTermX() const -> int // x-position on terminal
613 { return woffset.getX1() + adjust_wsize.getX(); }
614 
615 //----------------------------------------------------------------------
616 inline auto FWidget::getTermY() const -> int // y-position on terminal
617 { return woffset.getY1() + adjust_wsize.getY(); }
618 
619 //----------------------------------------------------------------------
620 inline auto FWidget::getTermPos() const -> FPoint // position on terminal
621 { return {getTermX(), getTermY()}; }
622 
623 //----------------------------------------------------------------------
624 inline auto FWidget::getWidth() const -> std::size_t
625 { return adjust_wsize.getWidth(); }
626 
627 //----------------------------------------------------------------------
628 inline auto FWidget::getHeight() const -> std::size_t
629 { return adjust_wsize.getHeight(); }
630 
631 //----------------------------------------------------------------------
632 inline auto FWidget::getSize() const -> FSize
633 {
634  const FSize& size = adjust_wsize.getSize(); // initialize size
635  return size;
636 }
637 
638 //----------------------------------------------------------------------
639 inline auto FWidget::getTopPadding() const noexcept -> int
640 { return padding.top; }
641 
642 //----------------------------------------------------------------------
643 inline auto FWidget::getLeftPadding() const noexcept -> int
644 { return padding.left; }
645 
646 //----------------------------------------------------------------------
647 inline auto FWidget::getBottomPadding() const noexcept -> int
648 { return padding.bottom; }
649 
650 //----------------------------------------------------------------------
651 inline auto FWidget::getRightPadding() const noexcept -> int
652 { return padding.right; }
653 
654 //----------------------------------------------------------------------
655 inline auto FWidget::getClientWidth() const -> std::size_t
656 { return wclient_offset.getWidth(); }
657 
658 //----------------------------------------------------------------------
659 inline auto FWidget::getClientHeight() const -> std::size_t
660 { return wclient_offset.getHeight(); }
661 
662 //----------------------------------------------------------------------
663 inline auto FWidget::getClientSize() const -> FSize
664 {
665  const FSize& size = wclient_offset.getSize(); // initialize size
666  return size;
667 }
668 
669 //----------------------------------------------------------------------
670 inline auto FWidget::getMaxWidth() const -> std::size_t
671 { return woffset.getWidth(); }
672 
673 //----------------------------------------------------------------------
674 inline auto FWidget::getMaxHeight() const -> std::size_t
675 { return woffset.getHeight(); }
676 
677 //----------------------------------------------------------------------
678 inline auto FWidget::getShadow() const & -> const FSize&
679 { return wshadow; }
680 
681 //----------------------------------------------------------------------
682 inline auto FWidget::getGeometry() const & -> const FRect&
683 { return adjust_wsize; }
684 
685 //----------------------------------------------------------------------
686 inline auto FWidget::getGeometryWithShadow() & -> const FRect&
687 {
688  adjust_wsize_shadow.setCoordinates
689  (
690  adjust_wsize.x1_ref(),
691  adjust_wsize.y1_ref(),
692  adjust_wsize.x2_ref() + int(wshadow.width_ref()),
693  adjust_wsize.y2_ref() + int(wshadow.height_ref())
694  );
695 
696  return adjust_wsize_shadow;
697 }
698 
699 //----------------------------------------------------------------------
700 inline auto FWidget::getTermGeometry() & -> const FRect&
701 {
702  adjust_wsize_term.setCoordinates
703  (
704  adjust_wsize.x1_ref() + woffset.x1_ref(),
705  adjust_wsize.y1_ref() + woffset.y1_ref(),
706  adjust_wsize.x2_ref() + woffset.x1_ref(),
707  adjust_wsize.y2_ref() + woffset.y1_ref()
708  );
709 
710  return adjust_wsize_term;
711 }
712 
713 //----------------------------------------------------------------------
714 inline auto FWidget::getTermGeometryWithShadow() & -> const FRect&
715 {
716  adjust_wsize_term_shadow.setCoordinates
717  (
718  adjust_wsize.x1_ref() + woffset.x1_ref(),
719  adjust_wsize.y1_ref() + woffset.y1_ref(),
720  adjust_wsize.x2_ref() + woffset.x1_ref() + int(wshadow.width_ref()),
721  adjust_wsize.y2_ref() + woffset.y1_ref() + int(wshadow.height_ref())
722  );
723 
724  return adjust_wsize_term_shadow;
725 }
726 
727 //----------------------------------------------------------------------
728 inline auto FWidget::getDesktopWidth() const -> std::size_t
729 { return FVTerm::getFOutput()->getColumnNumber(); }
730 
731 //----------------------------------------------------------------------
732 inline auto FWidget::getDesktopHeight() const -> std::size_t
733 { return FVTerm::getFOutput()->getLineNumber(); }
734 
735 //----------------------------------------------------------------------
736 inline auto FWidget::getFlags() const & -> const FWidgetFlags&
737 { return flags; }
738 
739 //----------------------------------------------------------------------
740 inline auto FWidget::getCursorPos() const -> FPoint
741 { return widget_cursor_position; }
742 
743 //----------------------------------------------------------------------
744 inline void FWidget::setActiveWindow (FWidget* obj)
745 { active_window = obj; }
746 
747 //----------------------------------------------------------------------
748 inline void FWidget::setFocusWidget (FWidget* obj)
749 { focus_widget = obj; }
750 
751 //----------------------------------------------------------------------
752 inline void FWidget::setClickedWidget (FWidget* obj)
753 { clicked_widget = obj; }
754 
755 //----------------------------------------------------------------------
756 inline void FWidget::setOpenMenu (FWidget* obj)
757 { open_menu = obj; }
758 
759 //----------------------------------------------------------------------
760 template <typename ClassT>
761 inline void FWidget::setColorTheme()
762 {
763  getColorTheme() = std::make_shared<ClassT>();
764 }
765 
766 //----------------------------------------------------------------------
767 inline void FWidget::setMoveSizeWidget (FWidget* obj)
768 { move_resize_widget = obj; }
769 
770 //----------------------------------------------------------------------
771 inline void FWidget::setStatusBarMessage (const FString& msg)
772 { status_bar_message = msg; }
773 
774 //----------------------------------------------------------------------
775 inline void FWidget::unsetVisible()
776 { setVisible(false); }
777 
778 //----------------------------------------------------------------------
779 inline void FWidget::unsetEnable()
780 { setEnable(false); }
781 
782 //----------------------------------------------------------------------
783 inline void FWidget::setDisable()
784 { setEnable(false); }
785 
786 //----------------------------------------------------------------------
787 inline void FWidget::setVisibleCursor (bool enable)
788 { flags.visibility.visible_cursor = enable; }
789 
790 //----------------------------------------------------------------------
791 inline void FWidget::unsetVisibleCursor()
792 { setVisibleCursor(false); }
793 
794 //----------------------------------------------------------------------
795 inline auto FWidget::unsetFocus() -> bool
796 { return setFocus(false, FocusTypes::DefiniteWidget); }
797 
798 //----------------------------------------------------------------------
799 inline void FWidget::setFocusable (bool enable)
800 { flags.focus.focusable = enable; }
801 
802 //----------------------------------------------------------------------
803 inline void FWidget::unsetFocusable()
804 { flags.focus.focusable = false; }
805 
806 //----------------------------------------------------------------------
807 inline auto FWidget::ignorePadding (bool enable) -> bool
808 { return (flags.feature.ignore_padding = enable); }
809 
810 //----------------------------------------------------------------------
811 inline auto FWidget::acceptPadding() -> bool
812 { return (flags.feature.ignore_padding = false); }
813 
814 //----------------------------------------------------------------------
815 inline void FWidget::setForegroundColor (FColor color)
816 {
817  // valid colors -1..255
818  if ( color == FColor::Default || (color >> 8) == FColor::Black )
819  foreground_color = color;
820 }
821 
822 //----------------------------------------------------------------------
823 inline void FWidget::setBackgroundColor (FColor color)
824 {
825  // valid colors -1..255
826  if ( color == FColor::Default || (color >> 8) == FColor::Black )
827  background_color = color;
828 }
829 
830 //----------------------------------------------------------------------
831 inline auto FWidget::setFlags() & -> FWidgetFlags&
832 {
833  // Gives direct access to the widget flags
834  return flags;
835 }
836 
837 //----------------------------------------------------------------------
838 inline void FWidget::setGeometry (const FRect& box, bool adjust)
839 {
840  setGeometry (box.getPos(), box.getSize(), adjust);
841 }
842 
843 //----------------------------------------------------------------------
844 inline void FWidget::setShadowSize (const FSize& size)
845 {
846  // width = right shadow / height = bottom shadow
847  wshadow.setSize (size);
848 }
849 
850 //----------------------------------------------------------------------
851 inline void FWidget::setMinimumWidth (std::size_t min_width)
852 { size_hints.setMinimum (FSize(min_width, size_hints.min_height)); }
853 
854 //----------------------------------------------------------------------
855 inline void FWidget::setMinimumHeight (std::size_t min_height)
856 { size_hints.setMinimum (FSize(size_hints.min_width, min_height)); }
857 
858 //----------------------------------------------------------------------
859 inline void FWidget::setMinimumSize (const FSize& size)
860 {
861  // Sets the lower size limit to which the widget can be resized
862  size_hints.setMinimum (size);
863 }
864 
865 //----------------------------------------------------------------------
866 inline void FWidget::setMaximumWidth (std::size_t max_width)
867 { size_hints.setMaximum (FSize(max_width, size_hints.max_height)); }
868 
869 //----------------------------------------------------------------------
870 inline void FWidget::setMaximumHeight (std::size_t max_height)
871 { size_hints.setMaximum (FSize(size_hints.max_width, max_height)); }
872 
873 //----------------------------------------------------------------------
874 inline void FWidget::setMaximumSize (const FSize& size)
875 {
876  // Sets the upper size limit to which the widget can be resized
877  size_hints.setMaximum (size);
878 }
879 
880 //----------------------------------------------------------------------
881 inline void FWidget::setFixedSize (const FSize& size)
882 {
883  // Sets the minimum and maximum size limit to fixed sizes to prevent
884  // the widget resizing
885  size_hints.setMinimum (size);
886  size_hints.setMaximum (size);
887 }
888 
889 //----------------------------------------------------------------------
890 inline void FWidget::unsetCursorPos()
891 { setCursorPos ({-1, -1}); }
892 
893 //----------------------------------------------------------------------
894 inline void FWidget::unsetMergingBorder (Side side)
895 { setMergingBorder(side, false); }
896 
897 //----------------------------------------------------------------------
898 inline void FWidget::unsetMergingBorder (Side side, int pos)
899 { setMergingBorder(side, pos, false); }
900 
901 //----------------------------------------------------------------------
902 inline auto FWidget::isRootWidget() const -> bool
903 { return (! hasParent()); }
904 
905 //----------------------------------------------------------------------
906 inline auto FWidget::isVisible() const -> bool
907 { return flags.visibility.visible; }
908 
909 //----------------------------------------------------------------------
910 inline auto FWidget::isShown() const -> bool
911 { return flags.visibility.shown; }
912 
913 //----------------------------------------------------------------------
914 inline auto FWidget::isHidden() const -> bool
915 { return flags.visibility.hidden; }
916 
917 //----------------------------------------------------------------------
918 inline auto FWidget::isWindowWidget() const -> bool
919 { return flags.type.window_widget; }
920 
921 //----------------------------------------------------------------------
922 inline auto FWidget::isDialogWidget() const -> bool
923 { return flags.type.dialog_widget; }
924 
925 //----------------------------------------------------------------------
926 inline auto FWidget::isMenuWidget() const -> bool
927 { return flags.type.menu_widget; }
928 
929 //----------------------------------------------------------------------
930 inline auto FWidget::isEnabled() const -> bool
931 { return flags.feature.active; }
932 
933 //----------------------------------------------------------------------
934 inline auto FWidget::hasVisibleCursor() const -> bool
935 { return flags.visibility.visible_cursor; }
936 
937 //----------------------------------------------------------------------
938 inline auto FWidget::hasFocus() const -> bool
939 { return flags.focus.focus; }
940 
941 //----------------------------------------------------------------------
942 inline auto FWidget::acceptFocus() const -> bool // is focusable
943 { return flags.focus.focusable; }
944 
945 //----------------------------------------------------------------------
946 inline auto FWidget::isPaddingIgnored() const -> bool
947 { return flags.feature.ignore_padding; }
948 
949 //----------------------------------------------------------------------
950 inline void FWidget::clearStatusBarMessage()
951 { status_bar_message.clear(); }
952 
953 //----------------------------------------------------------------------
954 template <typename... Args>
955 inline void FWidget::addCallback (FString&& cb_signal, Args&&... args) & noexcept
956 {
957  callback_impl.addCallback (std::move(cb_signal), std::forward<Args>(args)...);
958 }
959 
960 //----------------------------------------------------------------------
961 template <typename... Args>
962 inline void FWidget::delCallback (Args&&... args) & noexcept
963 {
964  callback_impl.delCallback(std::forward<Args>(args)...);
965 }
966 
967 //----------------------------------------------------------------------
968 inline void FWidget::emitCallback (const FString& emit_signal) const &
969 {
970  callback_impl.emitCallback(emit_signal);
971 }
972 
973 //----------------------------------------------------------------------
974 inline void FWidget::addAccelerator (FKey key) &
975 { addAccelerator (key, this); }
976 
977 //----------------------------------------------------------------------
978 inline void FWidget::delAccelerator() &
979 { delAccelerator(this); }
980 
981 //----------------------------------------------------------------------
982 inline auto FWidget::termToWidgetPos (const FPoint& tPos) const -> FPoint
983 {
984  return { tPos.getX() + 1 - woffset.getX1() - adjust_wsize.getX()
985  , tPos.getY() + 1 - woffset.getY1() - adjust_wsize.getY() };
986 }
987 
988 //----------------------------------------------------------------------
989 inline void FWidget::print (const FPoint& pos)
990 {
991  setPrintPos (pos);
992 }
993 
994 //----------------------------------------------------------------------
995 inline void FWidget::drawBorder()
996 {
997  finalcut::drawBorder (this, FRect(FPoint{1, 1}, getSize()));
998 }
999 
1000 //----------------------------------------------------------------------
1001 inline auto FWidget::getModalDialogCounter() -> uInt
1002 { return modal_dialog_counter; }
1003 
1004 //----------------------------------------------------------------------
1005 inline auto FWidget::getDialogList() -> FWidgetList*&
1006 { return dialog_list; }
1007 
1008 //----------------------------------------------------------------------
1009 inline auto FWidget::getAlwaysOnTopList() -> FWidgetList*&
1010 { return always_on_top_list; }
1011 
1012 //----------------------------------------------------------------------
1013 inline auto FWidget::getWidgetCloseList() -> FWidgetList*&
1014 { return close_widget_list; }
1015 
1016 //----------------------------------------------------------------------
1017 inline auto FWidget::setModalDialogCounter() -> uInt&
1018 { return modal_dialog_counter; }
1019 
1020 //----------------------------------------------------------------------
1021 inline void FWidget::processDestroy() const
1022 { emitCallback("destroy"); }
1023 
1024 
1025 // Non-member elements for NewFont
1026 //----------------------------------------------------------------------
1027 constexpr wchar_t NF_menu_button[]
1028 {
1029  wchar_t(UniChar::NF_rev_menu_button1),
1030  wchar_t(UniChar::NF_rev_menu_button2),
1031  wchar_t(UniChar::NF_rev_menu_button3),
1032  '\0'
1033 };
1034 
1035 constexpr wchar_t NF_button_up[]
1036 {
1037  wchar_t(UniChar::NF_rev_up_pointing_triangle1),
1038  wchar_t(UniChar::NF_rev_up_pointing_triangle2),
1039  '\0'
1040 };
1041 
1042 constexpr wchar_t NF_button_down[]
1043 {
1044  wchar_t(UniChar::NF_rev_down_pointing_triangle1),
1045  wchar_t(UniChar::NF_rev_down_pointing_triangle2),
1046  '\0'
1047 };
1048 
1049 constexpr wchar_t NF_button_arrow_up[]
1050 {
1051  wchar_t(UniChar::NF_rev_up_arrow1),
1052  wchar_t(UniChar::NF_rev_up_arrow2),
1053  '\0'
1054 };
1055 
1056 constexpr wchar_t NF_button_arrow_down[]
1057 {
1058  wchar_t(UniChar::NF_rev_down_arrow1),
1059  wchar_t(UniChar::NF_rev_down_arrow2),
1060  '\0'
1061 };
1062 
1063 constexpr wchar_t NF_button_arrow_left[]
1064 {
1065  wchar_t(UniChar::NF_rev_left_arrow1),
1066  wchar_t(UniChar::NF_rev_left_arrow2),
1067  '\0'
1068 };
1069 
1070 constexpr wchar_t NF_button_arrow_right[]
1071 {
1072  wchar_t(UniChar::NF_rev_right_arrow1),
1073  wchar_t(UniChar::NF_rev_right_arrow2),
1074  '\0'
1075 };
1076 
1077 constexpr wchar_t NF_Drive[]
1078 {
1079  wchar_t(UniChar::NF_shadow_box_left),
1080  wchar_t(UniChar::NF_shadow_box_middle),
1081  wchar_t(UniChar::NF_shadow_box_hdd),
1082  wchar_t(UniChar::NF_shadow_box_right),
1083  '\0'
1084 };
1085 
1086 constexpr wchar_t NF_CD_ROM[]
1087 {
1088  wchar_t(UniChar::NF_shadow_box_left),
1089  wchar_t(UniChar::NF_shadow_box_middle),
1090  wchar_t(UniChar::NF_shadow_box_cd),
1091  wchar_t(UniChar::NF_shadow_box_right),
1092  '\0'
1093 };
1094 
1095 constexpr wchar_t NF_Net_Drive[]
1096 {
1097  wchar_t(UniChar::NF_shadow_box_left),
1098  wchar_t(UniChar::NF_shadow_box_middle),
1099  wchar_t(UniChar::NF_shadow_box_net),
1100  wchar_t(UniChar::NF_shadow_box_right),
1101  '\0'
1102 };
1103 
1104 constexpr wchar_t CHECKBOX[]
1105 {
1106  wchar_t(UniChar::NF_shadow_box_left),
1107  wchar_t(UniChar::NF_shadow_box_middle),
1108  wchar_t(UniChar::NF_shadow_box_right),
1109  '\0'
1110 };
1111 
1112 constexpr wchar_t CHECKBOX_ON[]
1113 {
1114  wchar_t(UniChar::NF_shadow_box_left),
1115  wchar_t(UniChar::NF_shadow_box_checked),
1116  wchar_t(UniChar::NF_shadow_box_right),
1117  '\0'
1118 };
1119 
1120 constexpr wchar_t RADIO_BUTTON[]
1121 {
1122  wchar_t(UniChar::NF_radio_button1),
1123  wchar_t(UniChar::NF_radio_button2),
1124  wchar_t(UniChar::NF_radio_button3),
1125  '\0'
1126 };
1127 
1128 constexpr wchar_t CHECKED_RADIO_BUTTON[]
1129 {
1130  wchar_t(UniChar::NF_radio_button1),
1131  wchar_t(UniChar::NF_radio_button2_checked),
1132  wchar_t(UniChar::NF_radio_button3),
1133  '\0'
1134 };
1135 
1136 } // namespace finalcut
1137 
1138 #endif // FWIDGET_H
Definition: fwidget_flags.h:102
Definition: fvterm.h:441
Definition: fevent.h:253
Definition: fevent.h:207
Definition: fstatusbar.h:187
Definition: fevent.h:144
Definition: fwidget_functions.cpp:928
Definition: frect.h:56
Definition: fmenubar.h:70
Definition: fvterm.h:97
Definition: fcallback.h:85
Definition: fevent.h:293
Definition: fevent.h:182
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fevent.h:271
Definition: fsize.h:55
Definition: fobject.h:79
Definition: fwidget.h:133
Definition: fstring.h:82
Definition: fevent.h:101
Definition: fevent.h:282
Definition: fwidget.h:129
Definition: fwidget_functions.cpp:577
Definition: fevent.h:231
Definition: fevent.h:124