diff --git a/ChangeLog b/ChangeLog index bacf0b09..3172fb40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-05-21 Markus Gans + * Fixed the event queue in FApplication + 2020-05-16 Markus Gans * More direct access to the static FTerm functions diff --git a/examples/event-log.cpp b/examples/event-log.cpp index 6f565b3d..fe827de9 100644 --- a/examples/event-log.cpp +++ b/examples/event-log.cpp @@ -115,9 +115,6 @@ finalcut::FString EventDialog::getMouseButtonName (int btn_state) case finalcut::fc::MiddleButton: return "middle"; - - default: - return "unknown"; } return "unknown"; diff --git a/src/fapplication.cpp b/src/fapplication.cpp index f88abec5..f75baa35 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -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& FApplication::getLog() +FApplication::FLogPtr& FApplication::getLog() { // Global logger object - static std::shared_ptr logger = std::make_shared(); + static FLogPtr logger(std::make_shared()); return logger; } //---------------------------------------------------------------------- -void FApplication::setLog (const std::shared_ptr& 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(*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; diff --git a/src/fevent.cpp b/src/fevent.cpp index 8c85e612..b79c068a 100644 --- a/src/fevent.cpp +++ b/src/fevent.cpp @@ -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 ); } //---------------------------------------------------------------------- diff --git a/src/fobject.cpp b/src/fobject.cpp index b93f8a1a..8006056d 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -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(ev) ); } - else if ( ev->type() == fc::User_Event ) + else if ( ev->getType() == fc::User_Event ) { onUserEvent ( static_cast(ev) ); } diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index d6067980..324af019 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -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 { diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index 661c0375..e8e2499a 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -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 { diff --git a/src/fvterm.cpp b/src/fvterm.cpp index f884926b..4d5bac52 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -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 //---------------------------------------------------------------------- void FVTerm::init (bool disable_alt_screen) { diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 265e26e3..3fd5de25 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -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(ev)); diff --git a/src/fwindow.cpp b/src/fwindow.cpp index df63dd9c..f3ce0f02 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -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); diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index fc51e84c..94483c7c 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -90,6 +90,9 @@ class FObject; class FApplication : public FWidget { public: + // Typedef + typedef std::shared_ptr 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& getLog(); + static FLogPtr& getLog(); // Mutator - static void setLog (const std::shared_ptr&); + 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 > eventPair; - typedef std::deque FEventQueue; + typedef std::pair EventPair; + typedef std::deque FEventQueue; // Methods void init (uInt64, uInt64); diff --git a/src/include/final/fevent.h b/src/include/final/fevent.h index eeb0acca..0e33d66a 100644 --- a/src/include/final/fevent.h +++ b/src/include/final/fevent.h @@ -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; }; diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index 81fdec34..164afe8f 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -184,7 +184,7 @@ void initScrollbar ( FScrollbarPtr& bar } catch (const std::bad_alloc&) { - badAllocFunctionOutput ("FScrollbar"); + badAllocOutput ("FScrollbar"); return; } diff --git a/src/include/final/ftypes.h b/src/include/final/ftypes.h index f20ad667..ff35a9ec 100644 --- a/src/include/final/ftypes.h +++ b/src/include/final/ftypes.h @@ -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 {