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-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 ▏-┬- - - -▕ 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 getWindowLayer (WidgetT*) -> int;
97  auto getWindowFocusWidget() const -> FWidget*;
98 
99  // Mutators
100  void setWindowWidget (bool = true);
101  void unsetWindowWidget();
102  static void setActiveWindow (FWindow*);
103  void setWindowFocusWidget (FWidget*);
104  auto activateWindow (bool = true) -> bool;
105  void unsetActiveWindow() const;
106  auto deactivateWindow() -> bool;
107  virtual void setResizeable (bool = true);
108  void unsetResizeable();
109  virtual void setMinimizable (bool = true);
110  void unsetMinimizable();
111  void setTransparentShadow (bool = true);
112  void unsetTransparentShadow();
113  void setShadow (bool = true);
114  void unsetShadow();
115  void setAlwaysOnTop (bool = true);
116  void unsetAlwaysOnTop();
117 
118  // Inquiries
119  auto isZoomed() const noexcept -> bool;
120  auto isMinimized() const -> bool;
121  auto isWindowActive() const noexcept -> bool;
122  auto isWindowHidden() const -> bool;
123  auto isResizeable() const -> bool;
124  auto isMinimizable() const -> bool;
125  auto isAlwaysOnTop() const -> bool;
126  auto hasTransparentShadow() const -> bool;
127  auto hasShadow() const -> bool;
128 
129  // Methods
130  void drawBorder() override;
131  void show() override;
132  void hide() override;
133  void setX (int, bool = true) override;
134  void setY (int, bool = true) override;
135  void setPos (const FPoint&, bool = true) override;
136  void setWidth (std::size_t, bool = true) override;
137  void setHeight (std::size_t, bool = true) override;
138  void setSize (const FSize&, bool = true) override;
139  void setGeometry ( const FPoint&, const FSize&
140  , bool = true ) override;
141  void move (const FPoint&) override;
142  static auto getWindowWidgetAt (const FPoint&) -> FWindow*;
143  static auto getWindowWidgetAt (int, int) -> FWindow*;
144  static void addWindow (FWidget*);
145  static void delWindow (const FWidget*);
146  static void swapWindow (const FWidget*, const FWidget*);
147  static auto raiseWindow (FWidget*) -> bool;
148  auto raiseWindow() -> bool;
149  static auto lowerWindow (FWidget*) -> bool;
150  auto lowerWindow() -> bool;
151  virtual auto zoomWindow() -> bool;
152  virtual auto minimizeWindow() -> bool;
153  static void switchToPrevWindow (const FWidget*);
154  static auto activatePrevWindow() -> bool;
155  void setShadowSize (const FSize&) override;
156 
157  protected:
158  // Method
159  void adjustSize() override;
160 
161  // Mutator
162  static void setPreviousWindow (FWindow*);
163 
164  // Event handlers
165  auto event (FEvent*) -> bool override;
166  virtual void onWindowActive (FEvent*);
167  virtual void onWindowInactive (FEvent*);
168  virtual void onWindowRaised (FEvent*);
169  virtual void onWindowLowered (FEvent*);
170 
171  private:
172  // Methods
173  void createVWin() noexcept;
174  static auto getVisibleTermGeometry (FWindow*) -> FRect;
175  static void deleteFromAlwaysOnTopList (const FWidget*);
176  static void processAlwaysOnTop();
177  static auto getWindowWidgetImpl (FWidget*) -> FWindow*;
178  static auto getWindowLayerImpl (FWidget*) -> int;
179  static void activateTopWindow (const FWindow*);
180  static auto isWindowActivatable (const FWindow*, const FWindow*) -> bool;
181  static void reactivateWindow (FWindow*);
182 
183  // Data members
184  FWidget* win_focus_widget{nullptr};
185  FRect normalGeometry{};
186  static FWindow* previous_window;
187  bool window_active{false};
188  bool zoomed{false};
189 };
190 
191 // non-member function forward declarations
192 //----------------------------------------------------------------------
193 class FMouseData; // class forward declaration
194 void closeDropDownMouseHandler (const FMouseData&);
195 void closeDropDown (const FWidget*, const FPoint&);
196 void unselectMenubarItemsMouseHandler (const FMouseData&);
197 void unselectMenubarItems (const FWidget*, const FPoint&);
198 
199 // FWindow inline functions
200 //----------------------------------------------------------------------
201 inline auto FWindow::getClassName() const -> FString
202 { return "FWindow"; }
203 
204 //----------------------------------------------------------------------
205 
206 template<typename WidgetT>
207 inline auto FWindow::getWindowWidget (WidgetT* obj) -> FWindow*
208 {
209  return getWindowWidgetImpl (static_cast<FWidget*>(obj));
210 }
211 
212 //----------------------------------------------------------------------
213 template<typename WidgetT>
214 inline auto FWindow::getWindowLayer (WidgetT* obj) -> int
215 {
216  return getWindowLayerImpl (static_cast<FWidget*>(obj));
217 }
218 
219 //----------------------------------------------------------------------
220 inline void FWindow::unsetWindowWidget()
221 { setWindowWidget(false); }
222 
223 //----------------------------------------------------------------------
224 inline auto FWindow::deactivateWindow() -> bool
225 { return activateWindow(false); }
226 
227 //----------------------------------------------------------------------
228 inline void FWindow::unsetResizeable()
229 { setResizeable(false); }
230 
231 //----------------------------------------------------------------------
232 inline void FWindow::unsetMinimizable()
233 { setMinimizable(false); }
234 
235 //----------------------------------------------------------------------
236 inline void FWindow::unsetTransparentShadow()
237 { setTransparentShadow(false); }
238 
239 //----------------------------------------------------------------------
240 inline void FWindow::unsetShadow()
241 { setShadow(false); }
242 
243 //----------------------------------------------------------------------
244 inline void FWindow::unsetAlwaysOnTop()
245 { setAlwaysOnTop(false); }
246 
247 //----------------------------------------------------------------------
248 inline auto FWindow::isZoomed() const noexcept -> bool
249 { return zoomed; }
250 
251 //----------------------------------------------------------------------
252 inline auto FWindow::isWindowActive() const noexcept -> bool
253 { return window_active; }
254 
255 //----------------------------------------------------------------------
256 inline auto FWindow::isResizeable() const -> bool
257 { return getFlags().feature.resizeable; }
258 
259 //----------------------------------------------------------------------
260 inline auto FWindow::isMinimizable() const -> bool
261 { return getFlags().feature.minimizable; }
262 
263 //----------------------------------------------------------------------
264 inline auto FWindow::isAlwaysOnTop() const -> bool
265 { return getFlags().visibility.always_on_top; }
266 
267 //----------------------------------------------------------------------
268 inline auto FWindow::hasTransparentShadow() const -> bool
269 { return getFlags().shadow.trans_shadow; }
270 
271 //----------------------------------------------------------------------
272 inline auto FWindow::hasShadow() const -> bool
273 { return getFlags().shadow.shadow; }
274 
275 //----------------------------------------------------------------------
276 inline auto FWindow::getWindowWidgetAt (const FPoint& pos) -> FWindow*
277 { return getWindowWidgetAt (pos.getX(), pos.getY()); }
278 
279 //----------------------------------------------------------------------
280 inline auto FWindow::raiseWindow() -> bool
281 { return raiseWindow(this); }
282 
283 //----------------------------------------------------------------------
284 inline auto FWindow::lowerWindow() -> bool
285 { return lowerWindow(this); }
286 
287 //----------------------------------------------------------------------
288 inline void FWindow::setPreviousWindow (FWindow* w)
289 { previous_window = w; }
290 
291 } // namespace finalcut
292 
293 #endif // FWINDOW_H
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:79
Definition: fevent.h:101
Definition: fwidget.h:129