FINAL CUT
fevent.h
1 /***********************************************************************
2 * fevent.h - Base event class of widgets *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2014-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  * ▕ FEvent ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏
29  * ▲
30  * │
31  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▏
32  * ├─────▏FKeyEvent ▏
33  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▏
34  * │
35  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
36  * ├─────▏FMouseEvent ▏
37  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
38  * │
39  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
40  * ├─────▏FWheelEvent ▏
41  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
42  * │
43  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
44  * ├─────▏FFocusEvent ▏
45  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
46  * │
47  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
48  * ├─────▏FAccelEvent ▏
49  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
50  * │
51  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
52  * ├─────▏FResizeEvent ▏
53  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
54  * │
55  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▏
56  * ├─────▏FShowEvent ▏
57  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
58  * │
59  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▏
60  * ├─────▏FHideEvent ▏
61  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
62  * │
63  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
64  * ├─────▏FCloseEvent ▏
65  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
66  * │
67  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
68  * ├─────▏FTimerEvent ▏
69  * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
70  * │
71  * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▏
72  * └─────▏FUserEvent ▏- - - -▕ FData ▏
73  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▏
74  */
75 
76 #ifndef FEVENT_H
77 #define FEVENT_H
78 
79 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
80  #error "Only <final/final.h> can be included directly."
81 #endif
82 
83 #include <memory>
84 #include <utility>
85 
86 #include "final/fc.h"
87 #include "final/ftypes.h"
88 #include "final/util/fdata.h"
89 #include "final/util/fpoint.h"
90 
91 namespace finalcut
92 {
93 
94 // class forward declaration
95 class FPoint;
96 
97 //----------------------------------------------------------------------
98 // class FEvent
99 //----------------------------------------------------------------------
100 
101 class FEvent // event base class
102 {
103  public:
104  explicit FEvent(Event);
105  auto getType() const noexcept -> Event;
106  auto isQueued() const noexcept -> bool;
107  auto wasSent() const noexcept -> bool;
108 
109  private:
110  friend void setSend (FEvent&, bool);
111  friend void setQueued (FEvent&, bool);
112 
113  // Data members
114  Event t{Event::None};
115  bool queued{false};
116  bool send{false};
117 };
118 
119 
120 //----------------------------------------------------------------------
121 // class FKeyEvent
122 //----------------------------------------------------------------------
123 
124 class FKeyEvent : public FEvent // keyboard event
125 {
126  public:
127  FKeyEvent (Event, FKey);
128 
129  auto key() const noexcept -> FKey;
130  auto isAccepted() const noexcept -> bool;
131  void accept() noexcept;
132  void ignore() noexcept;
133 
134  private:
135  FKey k{};
136  bool accpt{false}; // reject by default
137 };
138 
139 
140 //----------------------------------------------------------------------
141 // class FMouseEvent
142 //----------------------------------------------------------------------
143 
144 class FMouseEvent : public FEvent // mouse event
145 {
146  public:
147  FMouseEvent (Event, const FPoint&, const FPoint&, MouseButton);
148  FMouseEvent (Event, const FPoint&, MouseButton);
149 
150  auto getPos() const noexcept -> const FPoint&;
151  auto getTermPos() const noexcept -> const FPoint&;
152  auto getX() const noexcept -> int;
153  auto getY() const noexcept -> int;
154  auto getTermX() const noexcept -> int;
155  auto getTermY() const noexcept -> int;
156  auto getButton() const noexcept -> MouseButton;
157  void setPos (const FPoint&) noexcept;
158  void setTermPos (const FPoint&) noexcept;
159 
160  private:
161  FPoint p{};
162  FPoint tp{};
163  MouseButton b{};
164 };
165 
166 //----------------------------------------------------------------------
167 // Help function - GCC 16.1 compile fix - GitHub issues #165
168 #if defined(__GNUC__)
169 __attribute__((noinline))
170 #endif
171 inline auto makeMouseMovementEvent ( const FPoint& p
172  , const FPoint& g
173  , MouseButton b ) -> std::shared_ptr<FMouseEvent>
174 {
175  return std::make_shared<FMouseEvent>(Event::MouseMove, p, g, b);
176 }
177 
178 //----------------------------------------------------------------------
179 // class FWheelEvent
180 //----------------------------------------------------------------------
181 
182 class FWheelEvent : public FEvent // wheel event
183 {
184  public:
185  FWheelEvent (Event, const FPoint&, MouseWheel);
186  FWheelEvent (Event, const FPoint&, const FPoint&, MouseWheel);
187 
188  auto getPos() const noexcept -> const FPoint&;
189  auto getTermPos() const noexcept -> const FPoint&;
190  auto getX() const noexcept -> int;
191  auto getY() const noexcept -> int;
192  auto getTermX() const noexcept -> int;
193  auto getTermY() const noexcept -> int;
194  auto getWheel() const noexcept -> MouseWheel;
195 
196  private:
197  FPoint p{};
198  FPoint tp{};
199  MouseWheel w{MouseWheel::None};
200 };
201 
202 
203 //----------------------------------------------------------------------
204 // class FFocusEvent
205 //----------------------------------------------------------------------
206 
207 class FFocusEvent : public FEvent // focus event
208 {
209  public:
210  explicit FFocusEvent (Event);
211 
212  auto gotFocus() const noexcept -> bool;
213  auto lostFocus() const noexcept -> bool;
214  auto getFocusType() const noexcept -> FocusTypes;
215  void setFocusType (FocusTypes) noexcept;
216  auto isAccepted() const noexcept -> bool;
217  void accept() noexcept;
218  void ignore() noexcept;
219 
220  private:
221  bool accpt{true}; // accept by default
222  FocusTypes focus_type{FocusTypes::DefiniteWidget};
223 };
224 
225 
226 //----------------------------------------------------------------------
227 // class FAccelEvent
228 //----------------------------------------------------------------------
229 class FWidget; // class forward declaration
230 
231 class FAccelEvent : public FEvent // focus event
232 {
233  public:
234  FAccelEvent (Event, FWidget*);
235  FAccelEvent (const FAccelEvent&) = delete;
236  auto operator = (const FAccelEvent&) -> FAccelEvent& = delete;
237 
238  auto focusedWidget() const noexcept -> FWidget*;
239  auto isAccepted() const noexcept -> bool;
240  void accept() noexcept;
241  void ignore() noexcept;
242 
243  private:
244  bool accpt{false}; // reject by default
245  FWidget* focus_widget{};
246 };
247 
248 
249 //----------------------------------------------------------------------
250 // class FResizeEvent
251 //----------------------------------------------------------------------
252 
253 class FResizeEvent : public FEvent // resize event
254 {
255  public:
256  explicit FResizeEvent (Event);
257 
258  auto isAccepted() const noexcept -> bool;
259  void accept() noexcept;
260  void ignore() noexcept;
261 
262  private:
263  bool accpt{false}; // reject by default
264 };
265 
266 
267 //----------------------------------------------------------------------
268 // class FShowEvent
269 //----------------------------------------------------------------------
270 
271 class FShowEvent : public FEvent // show event
272 {
273  public:
274  explicit FShowEvent (Event);
275 };
276 
277 
278 //----------------------------------------------------------------------
279 // class FHideEvent
280 //----------------------------------------------------------------------
281 
282 class FHideEvent : public FEvent // hide event
283 {
284  public:
285  explicit FHideEvent (Event);
286 };
287 
288 
289 //----------------------------------------------------------------------
290 // class FCloseEvent
291 //----------------------------------------------------------------------
292 
293 class FCloseEvent : public FEvent // close event
294 {
295  public:
296  explicit FCloseEvent(Event);
297 
298  auto isAccepted() const noexcept -> bool;
299  void accept() noexcept;
300  void ignore() noexcept;
301 
302  private:
303  bool accpt{false}; // reject by default
304 };
305 
306 
307 //----------------------------------------------------------------------
308 // class FTimerEvent
309 //----------------------------------------------------------------------
310 
311 class FTimerEvent : public FEvent // timer event
312 {
313  public:
314  FTimerEvent (Event, int);
315 
316  auto getTimerId() const noexcept -> int;
317 
318  private:
319  int id{0};
320 };
321 
322 
323 //----------------------------------------------------------------------
324 // class FUserEvent
325 //----------------------------------------------------------------------
326 
327 class FUserEvent : public FEvent // user event
328 {
329  public:
330  FUserEvent (Event, int);
331 
332  auto getUserId() const noexcept -> int;
333  template <typename T>
334  auto getFDataObject() const noexcept -> FData<T>&&;
335  template <typename T>
336  auto getData() const noexcept -> clean_fdata_t<T>&;
337  template <typename T>
338  void setFDataObject (T&&) noexcept;
339  template <typename T>
340  void setData (T&&) noexcept;
341 
342  private:
343  // Using-declaration
344  using FDataAccessPtr = std::shared_ptr<FDataAccess>;
345 
346  // Data members
347  int uid{0};
348  FDataAccessPtr data_pointer{nullptr};
349 };
350 
351 //----------------------------------------------------------------------
352 template <typename T>
353 inline auto FUserEvent::getFDataObject() const noexcept -> FData<T>&&
354 {
355  return static_cast<FData<T>&&>(*data_pointer);
356 }
357 
358 //----------------------------------------------------------------------
359 template <typename T>
360 inline auto FUserEvent::getData() const noexcept -> clean_fdata_t<T>&
361 {
362  return static_cast<FData<clean_fdata_t<T>>&>(*data_pointer).get();
363 }
364 
365 //----------------------------------------------------------------------
366 template <typename T>
367 inline void FUserEvent::setFDataObject (T&& fdata) noexcept
368 {
369  data_pointer.reset(&(std::forward<T>(fdata)));
370 }
371 
372 //----------------------------------------------------------------------
373 template <typename T>
374 inline void FUserEvent::setData (T&& data) noexcept
375 {
376  data_pointer = makeFData(std::forward<T>(data));
377 }
378 
379 } // namespace finalcut
380 
381 #endif // FEVENT_H
Definition: fevent.h:253
Definition: fevent.h:207
Definition: fevent.h:144
Definition: fevent.h:311
Definition: fevent.h:293
Definition: fevent.h:182
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fevent.h:271
Definition: fevent.h:327
Definition: fevent.h:101
Definition: fevent.h:282
Definition: fdata.h:55
Definition: fwidget.h:129
Definition: fevent.h:231
Definition: fevent.h:124