File: fapplication.h

package info (click to toggle)
finalcut 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: cpp: 90,264; makefile: 546; sh: 412
file content (274 lines) | stat: -rw-r--r-- 10,790 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/***********************************************************************
* fapplication.h - Manages the application events                      *
*                                                                      *
* This file is part of the FINAL CUT widget toolkit                    *
*                                                                      *
* Copyright 2013-2023 Markus Gans                                      *
*                                                                      *
* FINAL CUT is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU Lesser General Public License as       *
* published by the Free Software Foundation; either version 3 of       *
* the License, or (at your option) any later version.                  *
*                                                                      *
* FINAL CUT is distributed in the hope that it will be useful, but     *
* WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
* GNU Lesser General Public License for more details.                  *
*                                                                      *
* You should have received a copy of the GNU Lesser General Public     *
* License along with this program.  If not, see                        *
* <http://www.gnu.org/licenses/>.                                      *
***********************************************************************/

/*  Inheritance diagram
 *  ═══════════════════
 *
 * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
 * ▕ FVTerm  ▏ ▕ FObject ▏
 * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
 *      ▲           ▲
 *      │           │
 *      └─────┬─────┘
 *            │
 *       ▕▔▔▔▔▔▔▔▔▔▏
 *       ▕ FWidget ▏
 *       ▕▁▁▁▁▁▁▁▁▁▏
 *            ▲
 *            │
 *     ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏1       1▕▔▔▔▔▔▔▏
 *     ▕ FApplication ▏-┬- - - -▕ FLog ▏
 *     ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ :       ▕▁▁▁▁▁▁▏
 *                      :
 *                      :      *▕▔▔▔▔▔▔▔▔▏
 *                      :- - - -▕ FEvent ▏
 *                      :       ▕▁▁▁▁▁▁▁▁▏
 *                      :
 *                      :      *▕▔▔▔▔▔▔▔▔▏
 *                      :- - - -▕ FPoint ▏
 *                      :       ▕▁▁▁▁▁▁▁▁▏
 *                      :
 *                      :      *▕▔▔▔▔▔▔▔▔▔▏
 *                      └- - - -▕ FWidget ▏
 *                              ▕▁▁▁▁▁▁▁▁▁▏
 */

#ifndef FAPPLICATION_H
#define FAPPLICATION_H

#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
  #error "Only <final/final.h> can be included directly."
#endif

#include <getopt.h>
#include <deque>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "final/ftypes.h"
#include "final/fwidget.h"

namespace finalcut
{

// class forward declaration
class FAccelEvent;
class FCloseEvent;
class FEvent;
class FFocusEvent;
class FKeyEvent;
class FLog;
class FMouseData;
class FMouseEvent;
class FStartOptions;
class FTimerEvent;
class FWheelEvent;
class FMouseControl;
class FPoint;
class FObject;

//----------------------------------------------------------------------
// class FApplication
//----------------------------------------------------------------------

class FApplication : public FWidget
{
  public:
    // Typedef
    using FLogPtr = std::shared_ptr<FLog>;
    using Args = std::vector<std::string>;
    using FMouseHandler = std::function<void(FMouseData)>;

    // Constructor
    FApplication (const int&, char*[]);

    // Disable copy constructor
    FApplication (const FApplication&) = delete;

    // Disable move constructor
    FApplication (FApplication&&) noexcept = delete;

    // Destructor
    ~FApplication() override;

    // Disable copy assignment operator (=)
    auto operator = (const FApplication&) -> FApplication& = delete;

    // Disable move assignment operator (=)
    auto operator = (FApplication&&) noexcept -> FApplication& = delete;

    // Accessors
    auto         getClassName() const -> FString override;
    auto         getArgs() const -> Args;
    static auto  getApplicationObject() -> FApplication*;
    static auto  getKeyboardWidget() -> FWidget*;
    static auto  getLog() -> FLogPtr&;

    // Mutator
    static void  setLog (const FLogPtr&);

    // Inquiry
    static auto  isQuit() -> bool;

    // Methods
#if defined(UNIT_TEST)
    static void  start();  // Simulates application start
#endif
    auto         exec() -> int;  // run
    auto         enterLoop() -> int;
    void         exitLoop() const;
    static void  exit (int = EXIT_SUCCESS);
    void         quit() const;
    static auto  sendEvent (FObject*, FEvent*) -> bool;
    void         queueEvent (FObject*, FEvent*);
    void         sendQueuedEvents();
    auto         eventInQueue() const -> bool;
    auto         removeQueuedEvent (const FObject*) -> bool;
    void         registerMouseHandler (const FMouseHandler&);
    void         initTerminal() override;
    static void  setDefaultTheme();
    static void  setDarkTheme();
    static void  setLogFile (const FString&);
    static void  setKeyboardWidget (FWidget*);
    static void  closeConfirmationDialog (FWidget*, FCloseEvent*);

    // Callback method
    void         cb_exitApp (FWidget*) const;

  protected:
    virtual void processExternalUserEvent();

  private:
    // Using-declaration
    using CmdOption = struct option;
    using EventPair = std::pair<FObject*, FEvent*>;
    using FEventQueue = std::deque<EventPair>;
    using FMouseHandlerList = std::vector<FMouseHandler>;
    using CmdMap = std::unordered_map<int, std::function<void(char*)>>;

    // Methods
    void         init();
    static void  setTerminalEncoding (const FString&);
    static auto  getLongOptions() -> const std::vector<struct option>&;
    static void  setCmdOptionsMap (CmdMap&);
    static void  cmdOptions (const Args&);
    static auto  getStartOptions() -> FStartOptions&;
    static void  showParameterUsage();
    void         destroyLog();
    void         findKeyboardWidget() const;
    auto         isKeyPressed(uInt64 = 0U) const -> bool;
    void         keyPressed();
    void         keyReleased() const;
    void         escapeKeyPressed() const;
    void         mouseTracking() const;
    void         performKeyboardAction();
    void         performMouseAction() const;
    void         mouseEvent (const FMouseData&) const;
    void         sendEscapeKeyPressEvent() const;
    auto         sendKeyDownEvent (FWidget*) const -> bool;
    auto         sendKeyPressEvent (FWidget*) const -> bool;
    auto         sendKeyUpEvent (FWidget*) const -> bool;
    void         sendKeyboardAccelerator();
    auto         hasDataInQueue() const -> bool;
    void         queuingKeyboardInput() const;
    void         queuingMouseInput() const;
    void         processKeyboardEvent() const;
    void         processMouseEvent() const;
    void         processInput() const;
    auto         processDialogSwitchAccelerator() const -> bool;
    auto         processAccelerator (const FWidget&) const -> bool;
    void         processTerminalFocus (const FKey&);
    static void  determineClickedWidget (const FMouseData&);
    static void  unsetMoveResizeMode (const FMouseData&);
    void         sendMouseEvent (const FMouseData&) const;
    void         sendMouseMoveEvent ( const FMouseData&
                                    , const FPoint&
                                    , const FPoint&
                                    , MouseButton ) const;
    void         sendMouseLeftClickEvent ( const FMouseData&
                                         , const FPoint&
                                         , const FPoint&
                                         , MouseButton ) const;
    void         sendMouseRightClickEvent ( const FMouseData&
                                          , const FPoint&
                                          , const FPoint&
                                          , MouseButton ) const;
    void         sendMouseMiddleClickEvent ( const FMouseData&
                                           , const FPoint&
                                           , const FPoint&
                                           , MouseButton ) const;
    void         sendWheelEvent ( const FMouseData&
                                , const FPoint&
                                , const FPoint& ) const;
    static auto  processParameters (const Args&) -> FWidget*;
    void         processResizeEvent();
    void         processCloseWidget();
    void         processDialogResizeMove() const;
    void         processLogger() const;
    auto         processNextEvent() -> bool;
    void         performTimerAction (FObject*, FEvent*) override;
    auto         hasTerminalResized() -> bool;
    static auto  isEventProcessable (FObject*, const FEvent*) -> bool;
    static auto  isNextEventTimeout() -> bool;

    // Data members
    Args              app_args{};
    uInt64            key_timeout{100'000};        // 100 ms
    uInt64            dblclick_interval{500'000};  // 500 ms
    std::streambuf*   default_clog_rdbuf{std::clog.rdbuf()};
    FEventQueue       event_queue{};
    FMouseHandlerList mouse_handler_list{};
    bool              has_terminal_resized{false};
    static uInt64     next_event_wait;
    static TimeValue  time_last_event;
    static int        loop_level;
    static int        quit_code;
    static bool       quit_now;
    static FWidget*   clicked_widget;
    static FWidget*   keyboard_widget;
};

// non-member function forward declarations
// implemented in fwidget_functions.cpp
//----------------------------------------------------------------------
auto getFApplication() -> FApplication*;


// FApplication inline functions
//----------------------------------------------------------------------
inline auto FApplication::getClassName() const -> FString
{ return "FApplication"; }

//----------------------------------------------------------------------
inline auto FApplication::getArgs() const -> Args
{ return app_args; }

//----------------------------------------------------------------------
inline void FApplication::cb_exitApp (FWidget* w) const
{ w->close(); }

}  // namespace finalcut

#endif  // FAPPLICATION_H