2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fapplication.h - Manages the application events *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-01-14 21:53:45 +01:00
|
|
|
* Copyright 2013-2018 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
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FTerm ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
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>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fevent.h"
|
|
|
|
#include "final/fwidget.h"
|
|
|
|
#include "final/fwindow.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FApplication
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FApplication : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
FApplication (const int&, char*[], bool = false);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
virtual ~FApplication();
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
const char* getClassName() const;
|
|
|
|
int getArgc() const;
|
|
|
|
char** getArgv() const;
|
|
|
|
FWidget* getMainWidget() const;
|
|
|
|
FWidget* getFocusWidget() const;
|
|
|
|
|
|
|
|
// Mutator
|
|
|
|
void setMainWidget (FWidget*);
|
|
|
|
|
|
|
|
// Inquiry
|
|
|
|
static bool isQuit();
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
int exec(); // run
|
|
|
|
int enter_loop();
|
|
|
|
void exit_loop();
|
|
|
|
static void exit (int = 0);
|
|
|
|
void quit();
|
|
|
|
static bool sendEvent (const FObject*, const FEvent*);
|
|
|
|
static void queueEvent (const FObject*, const FEvent*);
|
|
|
|
static void sendQueuedEvents ();
|
|
|
|
static bool eventInQueue();
|
2017-09-19 06:18:03 +02:00
|
|
|
static bool removeQueuedEvent (const FObject*);
|
2017-11-18 02:34:41 +01:00
|
|
|
static FWidget* processParameters (const int&, char*[]);
|
2017-12-10 15:36:02 +01:00
|
|
|
static void showParameterUsage ()
|
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
__attribute__((noreturn))
|
|
|
|
#endif
|
|
|
|
;
|
2017-10-30 20:56:00 +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
|
|
|
|
void cb_exitApp (FWidget*, data_ptr);
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
|
|
|
// Typedefs and Enumerations
|
|
|
|
typedef std::pair<const FObject*, const FEvent*> eventPair;
|
|
|
|
typedef std::deque<eventPair> eventQueue;
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
static const int NEED_MORE_DATA = -1; // parseKeyString return value
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Disable copy constructor
|
|
|
|
FApplication (const FApplication&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
FApplication& operator = (const FApplication&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Methods
|
2018-01-28 19:54:52 +01:00
|
|
|
void init (long, long);
|
2017-11-18 02:34:41 +01:00
|
|
|
static void cmd_options (const int&, char*[]);
|
2017-09-11 03:06:02 +02:00
|
|
|
bool KeyPressed();
|
|
|
|
ssize_t readKey();
|
2017-12-05 23:55:12 +01:00
|
|
|
FWidget* findKeyboardWidget();
|
|
|
|
bool getKeyPressedState();
|
|
|
|
void keyboardBufferTimeout (FWidget*);
|
2018-01-28 19:54:52 +01:00
|
|
|
void parseKeyPuffer (FWidget*);
|
|
|
|
void performKeyboardAction (FWidget*);
|
2017-12-05 23:55:12 +01:00
|
|
|
void sendEscapeKeyPressEvent (FWidget*);
|
|
|
|
bool sendKeyDownEvent (FWidget*);
|
|
|
|
bool sendKeyPressEvent (FWidget*);
|
|
|
|
bool sendKeyUpEvent (FWidget*);
|
|
|
|
void sendKeyboardAccelerator();
|
2017-09-11 03:06:02 +02:00
|
|
|
void processKeyboardEvent();
|
|
|
|
bool processDialogSwitchAccelerator();
|
|
|
|
bool processAccelerator (const FWidget*&);
|
2017-12-05 01:03:59 +01:00
|
|
|
bool getMouseEvent();
|
|
|
|
FWidget*& determineClickedWidget();
|
|
|
|
void unsetMoveSizeMode();
|
|
|
|
void closeOpenMenu();
|
|
|
|
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&);
|
2017-09-11 03:06:02 +02:00
|
|
|
void processMouseEvent();
|
|
|
|
void processResizeEvent();
|
|
|
|
int processTimerEvent();
|
|
|
|
void processCloseWidget();
|
|
|
|
bool processNextEvent();
|
|
|
|
|
|
|
|
// Data Members
|
|
|
|
int app_argc;
|
|
|
|
char** app_argv;
|
|
|
|
int key;
|
|
|
|
char k_buf[1024];
|
|
|
|
char fifo_buf[512];
|
|
|
|
int fifo_offset;
|
|
|
|
bool fifo_in_use;
|
|
|
|
int fifo_buf_size;
|
|
|
|
long key_timeout;
|
|
|
|
long dblclick_interval;
|
|
|
|
struct timeval time_keypressed;
|
2018-01-28 19:54:52 +01:00
|
|
|
static FMouseControl* mouse;
|
2017-09-11 03:06:02 +02:00
|
|
|
static eventQueue* event_queue;
|
|
|
|
static int quit_code;
|
|
|
|
static bool quit_now;
|
|
|
|
static int loop_level;
|
|
|
|
static bool process_timer_event;
|
|
|
|
static FWidget* move_size_widget;
|
|
|
|
static FWidget* main_widget;
|
|
|
|
static FWidget* active_window;
|
|
|
|
static FWidget* focus_widget;
|
|
|
|
static FWidget* clicked_widget;
|
|
|
|
static FWidget* open_menu;
|
|
|
|
|
|
|
|
// Friend functions from FWidget
|
|
|
|
friend FWidget* FWidget::getMainWidget();
|
|
|
|
friend FWidget* FWidget::getFocusWidget() const;
|
|
|
|
friend void FWidget::setFocusWidget (FWidget*);
|
|
|
|
friend FWidget* FWidget::getClickedWidget();
|
|
|
|
friend void FWidget::setClickedWidget (FWidget*);
|
|
|
|
friend FWidget* FWidget::getMoveSizeWidget();
|
|
|
|
friend void FWidget::setMoveSizeWidget (FWidget*);
|
|
|
|
friend FWidget* FWidget::getOpenMenu();
|
|
|
|
friend void FWidget::setOpenMenu (FWidget*);
|
|
|
|
|
|
|
|
// Friend functions from FWindow
|
|
|
|
friend bool FWindow::activateWindow (bool);
|
|
|
|
friend FWindow* FWindow::getActiveWindow();
|
|
|
|
friend void FWindow::unsetActiveWindow();
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FApplication inline functions
|
2015-10-03 01:45:13 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FApplication::getClassName() const
|
|
|
|
{ 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; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline FWidget* FApplication::getMainWidget() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return main_widget; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline FWidget* FApplication::getFocusWidget() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return focus_widget; }
|
|
|
|
|
2017-10-29 18:27:38 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FApplication::cb_exitApp (FWidget*, data_ptr)
|
|
|
|
{ close(); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FAPPLICATION_H
|