FINAL CUT
fwindow.h
1 /***********************************************************************
2 * fwindow.h - Intermediate base class for all window 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  * ▕▔▔▔▔▔▔▔▔▔▏
34  * ▕ FWidget ▏
35  * ▕▁▁▁▁▁▁▁▁▁▏
36  * ▲
37  * │
38  * ▕▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▏
39  * ▕ FWindow ▏-┬- - - -▕ FEvent ▏
40  * ▕▁▁▁▁▁▁▁▁▁▏ : ▕▁▁▁▁▁▁▁▁▏
41  * :
42  * : *▕▔▔▔▔▔▔▔▔▏
43  * :- - - -▕ FPoint ▏
44  * : ▕▁▁▁▁▁▁▁▁▏
45  * :
46  * : *▕▔▔▔▔▔▔▔▔▔▏
47  * └- - - -▕ FWidget ▏
48  * ▕▁▁▁▁▁▁▁▁▁▏
49  */
50 
51 #ifndef FWINDOW_H
52 #define FWINDOW_H
53 
54 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
55  #error "Only <final/final.h> can be included directly."
56 #endif
57 
58 #include "final/fwidget.h"
59 
60 namespace finalcut
61 {
62 
63 //----------------------------------------------------------------------
64 // class FWindow
65 //----------------------------------------------------------------------
66 
67 class FWindow : public FWidget
68 {
69  public:
70  // Using-declaration
71  using FWidget::setGeometry;
72 
73  // Constructor
74  explicit FWindow (FWidget* = nullptr);
75 
76  // Disable copy constructor
77  FWindow (const FWindow&) = delete;
78 
79  // Disable move constructor
80  FWindow (FWindow&&) noexcept = delete;
81 
82  // Destructor
83  ~FWindow () override;
84 
85  // Disable copy assignment operator (=)
86  auto operator = (const FWindow&) -> FWindow& = delete;
87 
88  // Disable move assignment operator (=)
89  auto operator = (FWindow&&) noexcept -> FWindow& = delete;
90 
91  // Accessors
92  auto getClassName() const -> FString override;
93  template<typename WidgetT>
94  static auto getWindowWidget (WidgetT*) -> FWindow*;
95  template<typename WidgetT>
96  static auto getWindowWidget (WidgetT*, const FWidgetFlags&) -> FWindow*;
97  template<typename WidgetT>
98  static auto getWindowLayer (WidgetT*) -> int;
99  auto getWindowFocusWidget() const -> FWidget*;
100 
101  // Mutators
102  void setWindowWidget (bool = true);
103  void unsetWindowWidget();
104  static void setActiveWindow (FWindow*);
105  void setWindowFocusWidget (FWidget*);
106  auto activateWindow (bool = true) -> bool;
107  void unsetActiveWindow() const;
108  auto deactivateWindow() -> bool;
109  virtual void setResizable (bool = true);
110  void unsetResizable();
111  virtual void setMinimizable (bool = true);
112  void unsetMinimizable();
113  void setTransparentShadow (bool = true);
114  void unsetTransparentShadow();
115  void setShadow (bool = true);
116  void unsetShadow();
117  void setAlwaysOnTop (bool = true);
118  void unsetAlwaysOnTop();
119 
120  // Predicates
121  auto isZoomed() const noexcept -> bool;
122  auto isMinimized() const -> bool;
123  auto isWindowActive() const noexcept -> bool;
124  auto isWindowHidden() const -> bool;
125  auto isResizable() const -> bool;
126  auto isMinimizable() const -> bool;
127  auto isAlwaysOnTop() const -> bool;
128  auto hasTransparentShadow() const -> bool;
129  auto hasShadow() const -> bool;
130 
131  // Methods
132  void drawBorder() override;
133  void show() override;
134  void hide() override;
135  void setX (int, bool = true) override;
136  void setY (int, bool = true) override;
137  void setPos (const FPoint&, bool = true) override;
138  void setWidth (std::size_t, bool = true) override;
139  void setHeight (std::size_t, bool = true) override;
140  void setSize (const FSize&, bool = true) override;
141  void setGeometry ( const FPoint&, const FSize&
142  , bool = true ) override;
143  void move (const FPoint&) override;
144  static auto getWindowWidgetAt (const FPoint&) -> FWindow*;
145  static auto getWindowWidgetAt (int, int) -> FWindow*;
146  static void addWindow (FWidget*);
147  static void delWindow (const FWidget*);
148  static void swapWindow (const FWidget*, const FWidget*);
149  static auto raiseWindow (FWidget*) -> bool;
150  auto raiseWindow() -> bool;
151  static auto lowerWindow (FWidget*) -> bool;
152  auto lowerWindow() -> bool;
153  virtual auto zoomWindow() -> bool;
154  virtual auto minimizeWindow() -> bool;
155  static void switchToPrevWindow (const FWidget*);
156  static auto activatePrevWindow() -> bool;
157  void setShadowSize (const FSize&) override;
158 
159  protected:
160  // Method
161  void adjustSize() override;
162 
163  // Mutator
164  static void setPreviousWindow (FWindow*);
165 
166  // Event handlers
167  auto event (FEvent*) -> bool override;
168  virtual void onWindowActive (FEvent*);
169  virtual void onWindowInactive (FEvent*);
170  virtual void onWindowRaised (FEvent*);
171  virtual void onWindowLowered (FEvent*);
172 
173  private:
174  // Methods
175  void createVWin() noexcept;
176  static auto getVisibleTermGeometry (FWindow*) -> FRect;
177  static void deleteFromAlwaysOnTopList (const FWidget*);
178  static void processAlwaysOnTop();
179  static auto getWindowWidgetImpl (FWidget*) -> FWindow*;
180  static auto getWindowWidgetImpl (FWidget*, const FWidgetFlags&) -> FWindow*;
181  static auto getWindowLayerImpl (FWidget*) -> int;
182  static void activateTopWindow (const FWindow*);
183  static auto isWindowActivatable (const FWindow*, const FWindow*) -> bool;
184  static void reactivateWindow (FWindow*);
185 
186  // Data members
187  FWidget* win_focus_widget{nullptr};
188  FRect normalGeometry{};
189  static FWindow* previous_window;
190  bool window_active{false};
191  bool zoomed{false};
192 };
193 
194 // non-member function forward declarations
195 //----------------------------------------------------------------------
196 class FMouseData; // class forward declaration
197 void closeDropDownMouseHandler (const FMouseData&);
198 void closeDropDown (const FWidget*, const FPoint&);
199 void unselectMenubarItemsMouseHandler (const FMouseData&);
200 void unselectMenubarItems (const FWidget*, const FPoint&);
201 
202 // FWindow inline functions
203 //----------------------------------------------------------------------
204 inline auto FWindow::getClassName() const -> FString
205 { return "FWindow"; }
206 
207 //----------------------------------------------------------------------
208 template<typename WidgetT>
209 inline auto FWindow::getWindowWidget (WidgetT* obj) -> FWindow*
210 {
211  return getWindowWidgetImpl (static_cast<FWidget*>(obj));
212 }
213 
214 //----------------------------------------------------------------------
215 template<typename WidgetT>
216 inline auto FWindow::getWindowWidget (WidgetT* obj, const FWidgetFlags& search_flags) -> FWindow*
217 {
218  return getWindowWidgetImpl (static_cast<FWidget*>(obj), search_flags);
219 }
220 
221 //----------------------------------------------------------------------
222 template<typename WidgetT>
223 inline auto FWindow::getWindowLayer (WidgetT* obj) -> int
224 {
225  return getWindowLayerImpl (static_cast<FWidget*>(obj));
226 }
227 
228 //----------------------------------------------------------------------
229 inline void FWindow::unsetWindowWidget()
230 { setWindowWidget(false); }
231 
232 //----------------------------------------------------------------------
233 inline auto FWindow::deactivateWindow() -> bool
234 { return activateWindow(false); }
235 
236 //----------------------------------------------------------------------
237 inline void FWindow::unsetResizable()
238 { setResizable(false); }
239 
240 //----------------------------------------------------------------------
241 inline void FWindow::unsetMinimizable()
242 { setMinimizable(false); }
243 
244 //----------------------------------------------------------------------
245 inline void FWindow::unsetTransparentShadow()
246 { setTransparentShadow(false); }
247 
248 //----------------------------------------------------------------------
249 inline void FWindow::unsetShadow()
250 { setShadow(false); }
251 
252 //----------------------------------------------------------------------
253 inline void FWindow::unsetAlwaysOnTop()
254 { setAlwaysOnTop(false); }
255 
256 //----------------------------------------------------------------------
257 inline auto FWindow::isZoomed() const noexcept -> bool
258 { return zoomed; }
259 
260 //----------------------------------------------------------------------
261 inline auto FWindow::isWindowActive() const noexcept -> bool
262 { return window_active; }
263 
264 //----------------------------------------------------------------------
265 inline auto FWindow::isResizable() const -> bool
266 { return getFlags().feature.resizable; }
267 
268 //----------------------------------------------------------------------
269 inline auto FWindow::isMinimizable() const -> bool
270 { return getFlags().feature.minimizable; }
271 
272 //----------------------------------------------------------------------
273 inline auto FWindow::isAlwaysOnTop() const -> bool
274 { return getFlags().visibility.always_on_top; }
275 
276 //----------------------------------------------------------------------
277 inline auto FWindow::hasTransparentShadow() const -> bool
278 { return getFlags().shadow.trans_shadow; }
279 
280 //----------------------------------------------------------------------
281 inline auto FWindow::hasShadow() const -> bool
282 { return getFlags().shadow.shadow; }
283 
284 //----------------------------------------------------------------------
285 inline auto FWindow::getWindowWidgetAt (const FPoint& pos) -> FWindow*
286 { return getWindowWidgetAt (pos.getX(), pos.getY()); }
287 
288 //----------------------------------------------------------------------
289 inline auto FWindow::raiseWindow() -> bool
290 { return raiseWindow(this); }
291 
292 //----------------------------------------------------------------------
293 inline auto FWindow::lowerWindow() -> bool
294 { return lowerWindow(this); }
295 
296 //----------------------------------------------------------------------
297 inline void FWindow::setPreviousWindow (FWindow* w)
298 { previous_window = w; }
299 
300 } // namespace finalcut
301 
302 #endif // FWINDOW_H
Definition: fwidget_flags.h:102
Definition: fwindow.h:67
Definition: frect.h:56
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fsize.h:55
Definition: fmouse.h:92
Definition: fstring.h:82
Definition: fevent.h:101
Definition: fwidget.h:129