Fixed event queue in FApplication
This commit is contained in:
parent
5a60794b85
commit
f20e036a9e
|
@ -1,3 +1,6 @@
|
|||
2020-05-21 Markus Gans <guru.mail@muenster.de>
|
||||
* Fixed the event queue in FApplication
|
||||
|
||||
2020-05-16 Markus Gans <guru.mail@muenster.de>
|
||||
* More direct access to the static FTerm functions
|
||||
|
||||
|
|
|
@ -115,9 +115,6 @@ finalcut::FString EventDialog::getMouseButtonName (int btn_state)
|
|||
|
||||
case finalcut::fc::MiddleButton:
|
||||
return "middle";
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
|
|
|
@ -100,6 +100,9 @@ FApplication::FApplication ( const int& _argc
|
|||
FApplication::~FApplication() // destructor
|
||||
{
|
||||
app_object = nullptr;
|
||||
|
||||
if ( eventInQueue() )
|
||||
event_queue.clear();
|
||||
}
|
||||
|
||||
|
||||
|
@ -111,15 +114,15 @@ FApplication* FApplication::getApplicationObject()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
std::shared_ptr<FLog>& FApplication::getLog()
|
||||
FApplication::FLogPtr& FApplication::getLog()
|
||||
{
|
||||
// Global logger object
|
||||
static std::shared_ptr<FLog> logger = std::make_shared<FLogger>();
|
||||
static FLogPtr logger(std::make_shared<FLogger>());
|
||||
return logger;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::setLog (const std::shared_ptr<FLog>& logger)
|
||||
void FApplication::setLog (const FLogPtr& logger)
|
||||
{
|
||||
getLog() = logger;
|
||||
}
|
||||
|
@ -183,25 +186,27 @@ void FApplication::quit()
|
|||
//----------------------------------------------------------------------
|
||||
bool FApplication::sendEvent (FObject* receiver, FEvent* event )
|
||||
{
|
||||
if ( quit_now || app_exit_loop || ! receiver )
|
||||
if ( quit_now || app_exit_loop || ! (bool(receiver) && bool(event)) )
|
||||
return false;
|
||||
|
||||
if ( ! isEventProcessable (receiver, event) )
|
||||
return false;
|
||||
|
||||
// Sends the event event directly to receiver
|
||||
return receiver->event(event);
|
||||
bool ret = receiver->event(event);
|
||||
event->send = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::queueEvent (FObject* receiver, FEvent* event)
|
||||
{
|
||||
if ( ! receiver )
|
||||
if ( ! (bool(receiver) && bool(event)) )
|
||||
return;
|
||||
|
||||
// queue this event
|
||||
eventPair send_event (receiver, std::make_shared<FEvent>(*event));
|
||||
event_queue.push_back(send_event);
|
||||
event->queued = true;
|
||||
event_queue.emplace_back (receiver, event);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -209,8 +214,9 @@ void FApplication::sendQueuedEvents()
|
|||
{
|
||||
while ( eventInQueue() )
|
||||
{
|
||||
sendEvent( event_queue.front().first,
|
||||
event_queue.front().second.get() );
|
||||
const EventPair& event_pair = event_queue.front();
|
||||
event_pair.second->queued = false;
|
||||
sendEvent(event_pair.first, event_pair.second);
|
||||
event_queue.pop_front();
|
||||
}
|
||||
}
|
||||
|
@ -1170,7 +1176,7 @@ bool FApplication::isEventProcessable (const FObject* receiver, const FEvent* ev
|
|||
&& ! window->getFlags().modal
|
||||
&& ! window->isMenuWidget() )
|
||||
{
|
||||
switch ( uInt(event->type()) )
|
||||
switch ( uInt(event->getType()) )
|
||||
{
|
||||
case fc::KeyPress_Event:
|
||||
case fc::KeyUp_Event:
|
||||
|
@ -1194,8 +1200,8 @@ bool FApplication::isEventProcessable (const FObject* receiver, const FEvent* ev
|
|||
}
|
||||
|
||||
// Throw away mouse events for disabled widgets
|
||||
if ( event->type() >= fc::MouseDown_Event
|
||||
&& event->type() <= fc::MouseMove_Event
|
||||
if ( event->getType() >= fc::MouseDown_Event
|
||||
&& event->getType() <= fc::MouseMove_Event
|
||||
&& ! widget->isEnabled() )
|
||||
return false;
|
||||
|
||||
|
|
|
@ -36,9 +36,17 @@ FEvent::FEvent (fc::events ev_type) // constructor
|
|||
{ }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
fc::events FEvent::type() const
|
||||
fc::events FEvent::getType() const
|
||||
{ return t; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FEvent::isQueued() const
|
||||
{ return queued; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FEvent::wasSent() const
|
||||
{ return send; }
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// class FKeyEvent
|
||||
|
@ -193,13 +201,13 @@ FFocusEvent::~FFocusEvent() // destructor
|
|||
//----------------------------------------------------------------------
|
||||
bool FFocusEvent::gotFocus() const
|
||||
{
|
||||
return ( type() == fc::FocusIn_Event );
|
||||
return ( getType() == fc::FocusIn_Event );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FFocusEvent::lostFocus() const
|
||||
{
|
||||
return ( type() == fc::FocusOut_Event );
|
||||
return ( getType() == fc::FocusOut_Event );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -191,11 +191,11 @@ bool FObject::event (FEvent* ev)
|
|||
{
|
||||
// Receives events on this object
|
||||
|
||||
if ( ev->type() == fc::Timer_Event )
|
||||
if ( ev->getType() == fc::Timer_Event )
|
||||
{
|
||||
onTimer ( static_cast<FTimerEvent*>(ev) );
|
||||
}
|
||||
else if ( ev->type() == fc::User_Event )
|
||||
else if ( ev->getType() == fc::User_Event )
|
||||
{
|
||||
onUserEvent ( static_cast<FUserEvent*>(ev) );
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@
|
|||
#include "final/ftermfreebsd.h"
|
||||
#include "final/ftypes.h"
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
|
||||
#define initCheck(ret_value) \
|
||||
if ( ! isInitialized() ) \
|
||||
{ \
|
||||
warnNotInitialized(); \
|
||||
return ret_value; \
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace finalcut
|
||||
{
|
||||
|
|
|
@ -26,12 +26,14 @@
|
|||
#include "final/fterm.h"
|
||||
#include "final/ftermopenbsd.h"
|
||||
|
||||
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
|
||||
#define initCheck(ret_value) \
|
||||
if ( ! isInitialized() ) \
|
||||
{ \
|
||||
warnNotInitialized(); \
|
||||
return ret_value; \
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace finalcut
|
||||
{
|
||||
|
|
|
@ -1386,7 +1386,7 @@ inline bool FVTerm::reallocateTextArea ( FTermArea* area
|
|||
}
|
||||
catch (const std::bad_alloc&)
|
||||
{
|
||||
badAllocFunctionOutput ("FLineChanges[height] or FChar[size]");
|
||||
badAllocOutput ("FLineChanges[height] or FChar[size]");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1407,7 +1407,7 @@ inline bool FVTerm::reallocateTextArea (FTermArea* area, std::size_t size)
|
|||
}
|
||||
catch (const std::bad_alloc&)
|
||||
{
|
||||
badAllocFunctionOutput ("FChar[size]");
|
||||
badAllocOutput ("FChar[size]");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1895,7 +1895,7 @@ const FChar FVTerm::getOverlappedCharacter (const FPoint& pos, FVTerm* obj)
|
|||
// Gets the overlapped character for a given position
|
||||
return getCharacter (overlapped_character, pos, obj);
|
||||
}
|
||||
|
||||
#include <unistd.h>
|
||||
//----------------------------------------------------------------------
|
||||
void FVTerm::init (bool disable_alt_screen)
|
||||
{
|
||||
|
|
|
@ -1515,7 +1515,7 @@ bool FWidget::focusPrevChild()
|
|||
//----------------------------------------------------------------------
|
||||
bool FWidget::event (FEvent* ev)
|
||||
{
|
||||
switch ( uInt(ev->type()) )
|
||||
switch ( uInt(ev->getType()) )
|
||||
{
|
||||
case fc::KeyPress_Event:
|
||||
KeyPressEvent (static_cast<FKeyEvent*>(ev));
|
||||
|
|
|
@ -786,7 +786,7 @@ void FWindow::adjustSize()
|
|||
//----------------------------------------------------------------------
|
||||
bool FWindow::event (FEvent* ev)
|
||||
{
|
||||
switch ( uInt(ev->type()) )
|
||||
switch ( uInt(ev->getType()) )
|
||||
{
|
||||
case fc::WindowActive_Event:
|
||||
onWindowActive (ev);
|
||||
|
|
|
@ -90,6 +90,9 @@ class FObject;
|
|||
class FApplication : public FWidget
|
||||
{
|
||||
public:
|
||||
// Typedef
|
||||
typedef std::shared_ptr<FLog> FLogPtr;
|
||||
|
||||
// Constructor
|
||||
FApplication (const int&, char*[], bool = false);
|
||||
|
||||
|
@ -107,10 +110,10 @@ class FApplication : public FWidget
|
|||
int getArgc() const;
|
||||
char** getArgv() const;
|
||||
static FApplication* getApplicationObject();
|
||||
static std::shared_ptr<FLog>& getLog();
|
||||
static FLogPtr& getLog();
|
||||
|
||||
// Mutator
|
||||
static void setLog (const std::shared_ptr<FLog>&);
|
||||
static void setLog (const FLogPtr&);
|
||||
|
||||
// Inquiry
|
||||
static bool isQuit();
|
||||
|
@ -123,7 +126,7 @@ class FApplication : public FWidget
|
|||
void quit();
|
||||
static bool sendEvent (FObject*, FEvent*);
|
||||
void queueEvent (FObject*, FEvent*);
|
||||
void sendQueuedEvents ();
|
||||
void sendQueuedEvents();
|
||||
bool eventInQueue();
|
||||
bool removeQueuedEvent (const FObject*);
|
||||
static FWidget* processParameters (const int&, char*[]);
|
||||
|
@ -139,8 +142,8 @@ class FApplication : public FWidget
|
|||
|
||||
private:
|
||||
// Typedefs
|
||||
typedef std::pair<FObject*, std::shared_ptr<FEvent> > eventPair;
|
||||
typedef std::deque<eventPair> FEventQueue;
|
||||
typedef std::pair<FObject*, FEvent*> EventPair;
|
||||
typedef std::deque<EventPair> FEventQueue;
|
||||
|
||||
// Methods
|
||||
void init (uInt64, uInt64);
|
||||
|
|
|
@ -99,10 +99,18 @@ class FEvent // event base class
|
|||
public:
|
||||
FEvent() = default;
|
||||
explicit FEvent(fc::events);
|
||||
fc::events type() const;
|
||||
fc::events getType() const;
|
||||
bool isQueued() const;
|
||||
bool wasSent() const;
|
||||
|
||||
private:
|
||||
// Data members
|
||||
fc::events t{fc::None_Event};
|
||||
bool queued{false};
|
||||
bool send{false};
|
||||
|
||||
// Friend class
|
||||
friend class FApplication;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ void initScrollbar ( FScrollbarPtr& bar
|
|||
}
|
||||
catch (const std::bad_alloc&)
|
||||
{
|
||||
badAllocFunctionOutput ("FScrollbar");
|
||||
badAllocOutput ("FScrollbar");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,23 +37,14 @@
|
|||
|
||||
#define null nullptr
|
||||
|
||||
#define badAllocFunctionOutput(object_name) \
|
||||
*FApplication::getLog() << FLog::Error \
|
||||
<< "Not enough memory to alloc " \
|
||||
<< (object_name) \
|
||||
<< " in " \
|
||||
#define badAllocOutput(object_name) \
|
||||
*FApplication::getLog() << FLog::Error \
|
||||
<< __FILE__ << ":" << __LINE__ \
|
||||
<< ": Not enough memory to alloc " \
|
||||
<< (object_name) \
|
||||
<< " in " \
|
||||
<< __func__ << std::endl;
|
||||
|
||||
#define badAllocOutput(object_name) \
|
||||
*FApplication::getLog() << FLog::Error \
|
||||
<< "Not enough memory to alloc " \
|
||||
<< (object_name) \
|
||||
<< " in " \
|
||||
<< getClassName() \
|
||||
<< "::" \
|
||||
<< __func__ << std::endl;
|
||||
|
||||
//F_METHOD_CALLBACK
|
||||
namespace
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue