finalcut/src/include/final/fapplication.h

244 lines
9.4 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fapplication.h - Manages the application events *
* *
* This file is part of the FINAL CUT widget toolkit *
2017-11-04 07:03:53 +01:00
* *
2020-01-20 21:40:00 +01:00
* Copyright 2013-2020 Markus Gans *
2017-11-04 07:03:53 +01:00
* *
* 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 *
2017-11-04 07:03:53 +01:00
* 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 *
2017-11-04 07:03:53 +01:00
* 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
*
*
*
2020-06-11 21:38:33 +02:00
* 1 1
* FApplication -- - - - FLog
* :
* :
* : *
* :- - - - FEvent
* :
* :
* : *
* :- - - - FPoint
* :
* :
* : *
* - - - - FWidget
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FAPPLICATION_H
#define FAPPLICATION_H
2015-05-23 13:35:12 +02: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
#include "final/ftypes.h"
#include "final/fwidget.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
2015-05-23 13:35:12 +02:00
// class forward declaration
class FAccelEvent;
class FCloseEvent;
2020-05-13 23:47:14 +02:00
class FEvent;
class FFocusEvent;
class FKeyEvent;
2020-05-13 23:47:14 +02:00
class FLog;
class FMouseEvent;
class FStartOptions;
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:
2020-05-21 14:53:51 +02:00
// Typedef
typedef std::shared_ptr<FLog> FLogPtr;
2017-09-11 03:06:02 +02:00
// Constructor
2020-06-06 21:10:06 +02:00
FApplication (const int&, char*[]);
// Disable copy constructor
FApplication (const FApplication&) = delete;
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
// Disable copy assignment operator (=)
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;
static FApplication* getApplicationObject();
2020-05-21 14:53:51 +02:00
static FLogPtr& getLog();
2020-05-13 23:47:14 +02:00
// Mutator
2020-05-21 14:53:51 +02:00
static void setLog (const FLogPtr&);
2017-09-11 03:06:02 +02:00
// Inquiry
static bool isQuit();
2017-09-11 03:06:02 +02:00
// Methods
int exec(); // run
2019-10-08 04:37:19 +02:00
int enterLoop();
2020-07-12 15:25:21 +02:00
void exitLoop() const;
2020-06-06 21:10:06 +02:00
static void exit (int = EXIT_SUCCESS);
2020-07-12 15:25:21 +02:00
void quit() const;
2020-04-15 23:17:42 +02:00
static bool sendEvent (FObject*, FEvent*);
void queueEvent (FObject*, FEvent*);
2020-05-21 14:53:51 +02:00
void sendQueuedEvents();
2020-07-12 15:25:21 +02:00
bool eventInQueue() const;
2020-04-15 23:17:42 +02:00
bool removeQueuedEvent (const FObject*);
void initTerminal() override;
static void setDefaultTheme();
static void setDarkTheme();
static void closeConfirmationDialog (FWidget*, FCloseEvent*);
2017-09-11 03:06:02 +02:00
// Callback method
2020-08-12 22:28:02 +02:00
void cb_exitApp (FWidget*) const;
2020-06-06 21:10:06 +02:00
protected:
virtual void processExternalUserEvent();
2017-09-11 03:06:02 +02:00
private:
2018-12-28 22:57:43 +01:00
// Typedefs
2020-05-21 14:53:51 +02:00
typedef std::pair<FObject*, FEvent*> EventPair;
typedef std::deque<EventPair> FEventQueue;
2017-09-11 03:06:02 +02:00
// Methods
void init();
2020-06-07 18:21:59 +02:00
static void setTerminalEncoding (const FString&);
static void setLogFile (const FString&);
static void cmd_options (const int&, char*[]);
static FStartOptions& getStartOptions();
2020-06-06 21:10:06 +02:00
static void showParameterUsage();
void destroyLog();
2020-07-12 15:25:21 +02:00
void findKeyboardWidget() const;
bool isKeyPressed() const;
void keyPressed();
2020-07-12 17:00:16 +02:00
void keyReleased() const;
void escapeKeyPressed() const;
void performKeyboardAction();
2020-07-12 15:25:21 +02:00
void sendEscapeKeyPressEvent() const;
bool sendKeyDownEvent (FWidget*) const;
bool sendKeyPressEvent (FWidget*) const;
bool sendKeyUpEvent (FWidget*) const;
2020-07-12 17:00:16 +02:00
void sendKeyboardAccelerator() const;
void processKeyboardEvent() const;
2020-07-12 15:25:21 +02:00
bool processDialogSwitchAccelerator() const;
bool processAccelerator (const FWidget* const&) const;
bool getMouseEvent() const;
FWidget*& determineClickedWidget();
2020-07-12 15:25:21 +02:00
void unsetMoveSizeMode() const;
void closeDropDown();
void unselectMenubarItems();
2020-07-12 17:00:16 +02:00
void sendMouseEvent() const;
void sendMouseMoveEvent ( const FPoint&
, const FPoint&
2020-07-12 15:25:21 +02:00
, int ) const;
void sendMouseLeftClickEvent ( const FPoint&
, const FPoint&
2020-07-12 15:25:21 +02:00
, int ) const;
void sendMouseRightClickEvent ( const FPoint&
, const FPoint&
2020-07-12 15:25:21 +02:00
, int ) const;
void sendMouseMiddleClickEvent ( const FPoint&
, const FPoint&
2020-07-12 15:25:21 +02:00
, int ) const;
void sendWheelEvent (const FPoint&, const FPoint&) const;
2020-06-06 21:10:06 +02:00
static FWidget* processParameters (const int&, char*[]);
void processMouseEvent();
2020-07-12 17:00:16 +02:00
void processResizeEvent() const;
void processCloseWidget();
2020-07-12 15:25:21 +02:00
void processLogger() const;
bool processNextEvent();
2020-04-15 23:17:42 +02:00
void performTimerAction (FObject*, FEvent*) override;
static bool isEventProcessable (const FObject*, const FEvent*);
2017-09-11 03:06:02 +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
};
2020-08-11 23:04:46 +02:00
// non-member function forward declarations
// implemented in fwidget_functions.cpp
//----------------------------------------------------------------------
FApplication* getFApplication();
2015-05-23 13:35:12 +02:00
// FApplication inline functions
//----------------------------------------------------------------------
2019-10-05 23:20:07 +02:00
inline const FString FApplication::getClassName() const
{ return "FApplication"; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline int FApplication::getArgc() const
2015-05-23 13:35:12 +02:00
{ return app_argc; }
//----------------------------------------------------------------------
inline char** FApplication::getArgv() const
2015-05-23 13:35:12 +02:00
{ return app_argv; }
//----------------------------------------------------------------------
2020-08-12 22:28:02 +02:00
inline void FApplication::cb_exitApp (FWidget* w) const
2020-08-11 23:04:46 +02:00
{ w->close(); }
} // namespace finalcut
2015-05-23 13:35:12 +02:00
#endif // FAPPLICATION_H