55 #ifndef FAPPLICATION_H 56 #define FAPPLICATION_H 58 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 59 #error "Only <final/final.h> can be included directly." 66 #include <unordered_map> 70 #include "final/ftypes.h" 71 #include "final/fwidget.h" 100 using FLogPtr = std::shared_ptr<FLog>;
101 using Args = std::vector<std::string>;
102 using FMouseHandler = std::function<void(FMouseData)>;
123 auto getClassName()
const ->
FString override;
124 auto getArgs()
const -> Args;
126 static auto getKeyboardWidget() ->
FWidget*;
127 static auto getLog() -> FLogPtr&;
130 static void setLog (
const FLogPtr&);
133 static auto isQuit() -> bool;
136 #if defined(UNIT_TEST) 140 auto enterLoop() -> int;
141 void exitLoop()
const;
142 static void exit (
int = EXIT_SUCCESS);
146 void sendQueuedEvents();
147 auto eventInQueue()
const -> bool;
148 auto removeQueuedEvent (
const FObject*) -> bool;
149 void registerMouseHandler (
const FMouseHandler&);
150 void initTerminal()
override;
151 static void setDefaultTheme();
152 static void setDarkTheme();
153 static void setLogFile (
const FString&);
154 static void setKeyboardWidget (
FWidget*);
158 void cb_exitApp (
FWidget*)
const;
161 virtual void processExternalUserEvent();
165 using CmdOption =
struct option;
166 using EventPair = std::pair<FObject*, FEvent*>;
167 using FEventQueue = std::deque<EventPair>;
168 using FMouseHandlerList = std::vector<FMouseHandler>;
169 using CmdMap = std::unordered_map<int, std::function<void(char*)>>;
173 static void setTerminalEncoding (
const FString&);
174 static auto getLongOptions() ->
const std::vector<struct option>&;
175 static void setCmdOptionsMap (CmdMap&);
176 static void cmdOptions (
const Args&);
178 static void showParameterUsage();
180 void findKeyboardWidget()
const;
181 auto isKeyPressed (uInt64 = 0U)
const -> bool;
183 void keyReleased()
const;
184 void escapeKeyPressed()
const;
185 void mouseTracking()
const;
186 void performKeyboardAction();
187 void performMouseAction()
const;
189 void sendEscapeKeyPressEvent()
const;
190 auto sendKeyDownEvent (
FWidget*)
const -> bool;
191 auto sendKeyPressEvent (
FWidget*)
const -> bool;
192 auto sendKeyUpEvent (
FWidget*)
const -> bool;
193 void sendKeyboardAccelerator();
194 auto hasDataInQueue()
const -> bool;
195 void queuingKeyboardInput()
const;
196 void queuingMouseInput()
const;
197 void processKeyboardEvent()
const;
198 void processMouseEvent()
const;
199 void processInput()
const;
200 auto processDialogSwitchAccelerator()
const -> bool;
201 auto processAccelerator (
const FWidget&)
const -> bool;
202 void processTerminalFocus (
const FKey&);
203 static void determineClickedWidget (
const FMouseData&);
204 static void determineWheelWidget (
const FMouseData&);
205 static auto isNonActivatingMouseEvent (
const FMouseData&) -> bool;
206 static auto isWheelEvent (
const FMouseData&) -> bool;
207 static void unsetMoveResizeMode (
const FMouseData&);
208 void sendMouseEvent (
const FMouseData&)
const;
209 void sendMouseWheelEvent (
const FMouseData&)
const;
213 , MouseButton )
const;
214 void sendMouseLeftClickEvent (
const FMouseData&
217 , MouseButton )
const;
218 void sendMouseRightClickEvent (
const FMouseData&
221 , MouseButton )
const;
222 void sendMouseMiddleClickEvent (
const FMouseData&
225 , MouseButton )
const;
229 static auto processParameters (
const Args&) ->
FWidget*;
230 void processResizeEvent();
231 void processCloseWidget();
232 void processDialogResizeMove()
const;
233 void processLogger()
const;
234 auto processNextEvent() -> bool;
236 auto hasTerminalResized() -> bool;
237 static auto isEventProcessable (
FObject*,
const FEvent*) -> bool;
238 static auto isNextEventTimeout() -> bool;
242 uInt64 key_timeout{100
'000}; // 100 ms 243 uInt64 dblclick_interval{500'000};
244 std::streambuf* default_clog_rdbuf{std::clog.rdbuf()};
245 FEventQueue event_queue{};
246 FMouseHandlerList mouse_handler_list{};
247 bool has_terminal_resized{
false};
248 static uInt64 next_event_wait;
249 static TimeValue time_last_event;
250 static int loop_level;
251 static int quit_code;
252 static bool quit_now;
253 static FWidget* clicked_widget;
255 static FWidget* keyboard_widget;
266 inline auto FApplication::getClassName()
const ->
FString 267 {
return "FApplication"; }
270 inline auto FApplication::getArgs()
const -> Args
274 inline void FApplication::cb_exitApp (
FWidget* w)
const 279 #endif // FAPPLICATION_H Definition: fapplication.h:96
Definition: class_template.cpp:25
Definition: fstartoptions.h:52