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-2022 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 -> Event;
106  auto isQueued() const -> bool;
107  auto wasSent() const -> 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 -> FKey;
130  auto isAccepted() const -> bool;
131  void accept();
132  void ignore();
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 & -> const FPoint&;
151  auto getTermPos() const & -> const FPoint&;
152  auto getX() const -> int;
153  auto getY() const -> int;
154  auto getTermX() const -> int;
155  auto getTermY() const -> int;
156  auto getButton() const -> MouseButton;
157  void setPos (const FPoint&);
158  void setTermPos (const FPoint&);
159 
160  private:
161  FPoint p{};
162  FPoint tp{};
163  MouseButton b{};
164 };
165 
166 
167 //----------------------------------------------------------------------
168 // class FWheelEvent
169 //----------------------------------------------------------------------
170 
171 class FWheelEvent : public FEvent // wheel event
172 {
173  public:
174  FWheelEvent (Event, const FPoint&, MouseWheel);
175  FWheelEvent (Event, const FPoint&, const FPoint&, MouseWheel);
176 
177  auto getPos() const & -> const FPoint&;
178  auto getTermPos() const & -> const FPoint&;
179  auto getX() const -> int;
180  auto getY() const -> int;
181  auto getTermX() const -> int;
182  auto getTermY() const -> int;
183  auto getWheel() const -> MouseWheel;
184 
185  private:
186  FPoint p{};
187  FPoint tp{};
188  MouseWheel w{MouseWheel::None};
189 };
190 
191 
192 //----------------------------------------------------------------------
193 // class FFocusEvent
194 //----------------------------------------------------------------------
195 
196 class FFocusEvent : public FEvent // focus event
197 {
198  public:
199  explicit FFocusEvent (Event);
200 
201  auto gotFocus() const -> bool;
202  auto lostFocus() const -> bool;
203  auto getFocusType() const -> FocusTypes;
204  void setFocusType (FocusTypes);
205  auto isAccepted() const -> bool;
206  void accept();
207  void ignore();
208 
209  private:
210  bool accpt{true}; // accept by default
211  FocusTypes focus_type{FocusTypes::DefiniteWidget};
212 };
213 
214 
215 //----------------------------------------------------------------------
216 // class FAccelEvent
217 //----------------------------------------------------------------------
218 class FWidget; // class forward declaration
219 
220 class FAccelEvent : public FEvent // focus event
221 {
222  public:
223  FAccelEvent (Event, FWidget*);
224  FAccelEvent (const FAccelEvent&) = delete;
225  auto operator = (const FAccelEvent&) -> FAccelEvent& = delete;
226 
227  auto focusedWidget() const -> FWidget*;
228  auto isAccepted() const -> bool;
229  void accept();
230  void ignore();
231 
232  private:
233  bool accpt{false}; // reject by default
234  FWidget* focus_widget{};
235 };
236 
237 
238 //----------------------------------------------------------------------
239 // class FResizeEvent
240 //----------------------------------------------------------------------
241 
242 class FResizeEvent : public FEvent // resize event
243 {
244  public:
245  explicit FResizeEvent (Event);
246 
247  auto isAccepted() const -> bool;
248  void accept();
249  void ignore();
250 
251  private:
252  bool accpt{false}; // reject by default
253 };
254 
255 
256 //----------------------------------------------------------------------
257 // class FShowEvent
258 //----------------------------------------------------------------------
259 
260 class FShowEvent : public FEvent // show event
261 {
262  public:
263  explicit FShowEvent (Event);
264 };
265 
266 
267 //----------------------------------------------------------------------
268 // class FHideEvent
269 //----------------------------------------------------------------------
270 
271 class FHideEvent : public FEvent // hide event
272 {
273  public:
274  explicit FHideEvent (Event);
275 };
276 
277 
278 //----------------------------------------------------------------------
279 // class FCloseEvent
280 //----------------------------------------------------------------------
281 
282 class FCloseEvent : public FEvent // close event
283 {
284  public:
285  explicit FCloseEvent(Event);
286 
287  auto isAccepted() const -> bool;
288  void accept();
289  void ignore();
290 
291  private:
292  bool accpt{false}; // reject by default
293 };
294 
295 
296 //----------------------------------------------------------------------
297 // class FTimerEvent
298 //----------------------------------------------------------------------
299 
300 class FTimerEvent : public FEvent // timer event
301 {
302  public:
303  FTimerEvent (Event, int);
304 
305  auto getTimerId() const -> int;
306 
307  private:
308  int id{0};
309 };
310 
311 
312 //----------------------------------------------------------------------
313 // class FUserEvent
314 //----------------------------------------------------------------------
315 
316 class FUserEvent : public FEvent // user event
317 {
318  public:
319  FUserEvent (Event, int);
320 
321  auto getUserId() const -> int;
322  template <typename T>
323  auto getFDataObject() const -> FData<T>&&;
324  template <typename T>
325  auto getData() const -> clean_fdata_t<T>&;
326  template <typename T>
327  void setFDataObject (T&&);
328  template <typename T>
329  void setData (T&&);
330 
331  private:
332  // Using-declaration
333  using FDataAccessPtr = std::shared_ptr<FDataAccess>;
334 
335  // Data members
336  int uid{0};
337  FDataAccessPtr data_pointer{nullptr};
338 };
339 
340 //----------------------------------------------------------------------
341 template <typename T>
342 inline auto FUserEvent::getFDataObject() const -> FData<T>&&
343 {
344  return static_cast<FData<T>&&>(*data_pointer);
345 }
346 
347 //----------------------------------------------------------------------
348 template <typename T>
349 inline auto FUserEvent::getData() const -> clean_fdata_t<T>&
350 {
351  return static_cast<FData<clean_fdata_t<T>>&>(*data_pointer).get();
352 }
353 
354 //----------------------------------------------------------------------
355 template <typename T>
356 inline void FUserEvent::setFDataObject (T&& fdata)
357 {
358  data_pointer.reset(&(std::forward<T>(fdata)));
359 }
360 
361 //----------------------------------------------------------------------
362 template <typename T>
363 inline void FUserEvent::setData (T&& data)
364 {
365  data_pointer.reset(makeFData(std::forward<T>(data)));
366 }
367 
368 } // namespace finalcut
369 
370 #endif // FEVENT_H
Definition: fevent.h:242
Definition: fevent.h:196
Definition: fevent.h:144
Definition: fevent.h:300
Definition: fevent.h:282
Definition: fevent.h:171
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fevent.h:260
Definition: fevent.h:316
Definition: fevent.h:101
Definition: fevent.h:271
Definition: fdata.h:51
Definition: fwidget.h:129
Definition: fevent.h:220
Definition: fevent.h:124