2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fapplication.h - Manages the application events *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-01-20 21:40:00 +01:00
|
|
|
* Copyright 2013-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The 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. *
|
|
|
|
* *
|
|
|
|
* The 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/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Inheritance diagram
|
|
|
|
* ═══════════════════
|
|
|
|
*
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕ FVTerm ▏ ▕ FObject ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲
|
|
|
|
* │ │
|
|
|
|
* └─────┬─────┘
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWidget ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FApplication ▏-┬- - - -▕ FEvent ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ : ▕▁▁▁▁▁▁▁▁▏
|
|
|
|
* :
|
|
|
|
* : *▕▔▔▔▔▔▔▔▔▏
|
|
|
|
* :- - - -▕ FPoint ▏
|
|
|
|
* : ▕▁▁▁▁▁▁▁▁▏
|
|
|
|
* :
|
|
|
|
* : *▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* └- - - -▕ FWidget ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FAPPLICATION_H
|
|
|
|
#define FAPPLICATION_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <deque>
|
2018-12-17 02:06:22 +01:00
|
|
|
#include <memory>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/ftypes.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fwidget.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
// class forward declaration
|
|
|
|
class FEvent;
|
|
|
|
class FAccelEvent;
|
|
|
|
class FCloseEvent;
|
|
|
|
class FFocusEvent;
|
|
|
|
class FKeyEvent;
|
|
|
|
class FMouseEvent;
|
2019-09-28 03:13:06 +02:00
|
|
|
class FStartOptions;
|
2019-07-21 23:31:21 +02:00
|
|
|
class FTimerEvent;
|
|
|
|
class FWheelEvent;
|
|
|
|
class FMouseControl;
|
|
|
|
class FKeyboard;
|
|
|
|
class FPoint;
|
|
|
|
class FObject;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FApplication
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FApplication : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
FApplication (const int&, char*[], bool = false);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FApplication (const FApplication&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-02-19 21:59:13 +01:00
|
|
|
~FApplication() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
FApplication& operator = (const FApplication&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Accessors
|
2019-10-05 23:20:07 +02:00
|
|
|
const FString getClassName() const override;
|
2018-12-31 06:18:39 +01:00
|
|
|
int getArgc() const;
|
|
|
|
char** getArgv() const;
|
2018-12-24 18:11:16 +01:00
|
|
|
static FApplication* getApplicationObject();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Inquiry
|
2018-12-24 18:11:16 +01:00
|
|
|
static bool isQuit();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2018-12-24 18:11:16 +01:00
|
|
|
int exec(); // run
|
2019-10-08 04:37:19 +02:00
|
|
|
int enterLoop();
|
|
|
|
void exitLoop();
|
2018-12-24 18:11:16 +01:00
|
|
|
static void exit (int = 0);
|
|
|
|
void quit();
|
2020-04-15 23:17:42 +02:00
|
|
|
static bool sendEvent (FObject*, FEvent*);
|
|
|
|
void queueEvent (FObject*, FEvent*);
|
|
|
|
void sendQueuedEvents ();
|
|
|
|
bool eventInQueue();
|
|
|
|
bool removeQueuedEvent (const FObject*);
|
2019-09-06 08:21:10 +02:00
|
|
|
static FWidget* processParameters (const int&, char*[]);
|
2018-12-24 18:11:16 +01:00
|
|
|
static void showParameterUsage ()
|
2017-12-10 15:36:02 +01:00
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
__attribute__((noreturn))
|
|
|
|
#endif
|
2020-04-15 23:17:42 +02:00
|
|
|
;
|
2018-12-24 18:11:16 +01:00
|
|
|
static void closeConfirmationDialog (FWidget*, FCloseEvent*);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2017-10-29 18:27:38 +01:00
|
|
|
// Callback method
|
2020-04-13 12:40:11 +02:00
|
|
|
void cb_exitApp (const FWidget*, const FDataPtr);
|
2017-10-29 18:27:38 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
2018-12-28 22:57:43 +01:00
|
|
|
// Typedefs
|
2020-04-15 23:17:42 +02:00
|
|
|
typedef std::pair<FObject*, std::shared_ptr<FEvent> > eventPair;
|
|
|
|
typedef std::deque<eventPair> FEventQueue;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2018-12-28 22:57:43 +01:00
|
|
|
void init (uInt64, uInt64);
|
2019-09-06 08:21:10 +02:00
|
|
|
static void cmd_options (const int&, char*[]);
|
2019-09-28 03:13:06 +02:00
|
|
|
static FStartOptions& getStartOptions();
|
2018-12-24 18:11:16 +01:00
|
|
|
void findKeyboardWidget();
|
2020-05-02 00:07:35 +02:00
|
|
|
bool isKeyPressed() const;
|
2018-12-24 18:11:16 +01:00
|
|
|
void keyPressed();
|
|
|
|
void keyReleased();
|
|
|
|
void escapeKeyPressed();
|
|
|
|
void performKeyboardAction();
|
|
|
|
void sendEscapeKeyPressEvent();
|
2020-04-15 23:17:42 +02:00
|
|
|
bool sendKeyDownEvent (FWidget*);
|
|
|
|
bool sendKeyPressEvent (FWidget*);
|
|
|
|
bool sendKeyUpEvent (FWidget*);
|
2018-12-24 18:11:16 +01:00
|
|
|
void sendKeyboardAccelerator();
|
|
|
|
void processKeyboardEvent();
|
|
|
|
bool processDialogSwitchAccelerator();
|
2020-02-19 21:59:13 +01:00
|
|
|
bool processAccelerator (const FWidget* const&);
|
2018-12-24 18:11:16 +01:00
|
|
|
bool getMouseEvent();
|
|
|
|
FWidget*& determineClickedWidget();
|
|
|
|
void unsetMoveSizeMode();
|
2019-12-16 11:14:24 +01:00
|
|
|
void closeDropDown();
|
2018-12-24 18:11:16 +01:00
|
|
|
void unselectMenubarItems();
|
|
|
|
void sendMouseEvent();
|
|
|
|
void sendMouseMoveEvent ( const FPoint&
|
|
|
|
, const FPoint&
|
|
|
|
, int );
|
|
|
|
void sendMouseLeftClickEvent ( const FPoint&
|
|
|
|
, const FPoint&
|
|
|
|
, int );
|
|
|
|
void sendMouseRightClickEvent ( const FPoint&
|
|
|
|
, const FPoint&
|
|
|
|
, int );
|
|
|
|
void sendMouseMiddleClickEvent ( const FPoint&
|
|
|
|
, const FPoint&
|
|
|
|
, int );
|
|
|
|
void sendWheelEvent (const FPoint&, const FPoint&);
|
|
|
|
void processMouseEvent();
|
|
|
|
void processResizeEvent();
|
|
|
|
void processCloseWidget();
|
|
|
|
bool processNextEvent();
|
2020-04-15 23:17:42 +02:00
|
|
|
void performTimerAction (FObject*, FEvent*) override;
|
2020-04-17 02:49:33 +02:00
|
|
|
static bool isEventProcessable (const FObject*, const FEvent*);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2020-04-15 23:17:42 +02:00
|
|
|
int app_argc{};
|
|
|
|
char** app_argv{};
|
2018-12-28 22:57:43 +01:00
|
|
|
uInt64 key_timeout{100000}; // 100 ms
|
|
|
|
uInt64 dblclick_interval{500000}; // 500 ms
|
2020-04-15 23:17:42 +02:00
|
|
|
FEventQueue event_queue{};
|
2018-12-19 22:04:02 +01:00
|
|
|
static int quit_code;
|
|
|
|
static bool quit_now;
|
|
|
|
static int loop_level;
|
|
|
|
static bool process_timer_event;
|
2020-04-15 23:17:42 +02:00
|
|
|
static FMouseControl* mouse;
|
2018-12-19 22:04:02 +01:00
|
|
|
static FKeyboard* keyboard;
|
|
|
|
static FWidget* keyboard_widget;
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// FApplication inline functions
|
2015-10-03 01:45:13 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-10-05 23:20:07 +02:00
|
|
|
inline const FString FApplication::getClassName() const
|
2015-10-03 01:45:13 +02:00
|
|
|
{ return "FApplication"; }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline int FApplication::getArgc() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return app_argc; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline char** FApplication::getArgv() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return app_argv; }
|
|
|
|
|
2017-10-29 18:27:38 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
inline void FApplication::cb_exitApp (const FWidget*, const FDataPtr)
|
2017-10-29 18:27:38 +01:00
|
|
|
{ close(); }
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FAPPLICATION_H
|