]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/event.cpp
[ 1492053 ] Add wxVListBox style callbacks to wxOwnerDrawnComboBox.
[wxWidgets.git] / src / common / event.cpp
index 7597499232985719077b41fe35dad7bd35e7354e..f33787b099836b33c03f6254018659d59f4ea421 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        event.cpp
+// Name:        src/common/event.cpp
 // Purpose:     Event classes
 // Author:      Julian Smart
 // Modified by:
 // Purpose:     Event classes
 // Author:      Julian Smart
 // Modified by:
     #pragma hdrstop
 #endif
 
     #pragma hdrstop
 #endif
 
+#include "wx/event.h"
+
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
-    #include "wx/defs.h"
-    #include "wx/app.h"
     #include "wx/list.h"
     #include "wx/list.h"
+    #include "wx/app.h"
+    #include "wx/utils.h"
 
     #if wxUSE_GUI
         #include "wx/control.h"
 
     #if wxUSE_GUI
         #include "wx/control.h"
-        #include "wx/utils.h"
         #include "wx/dc.h"
         #include "wx/textctrl.h"
         #include "wx/dc.h"
         #include "wx/textctrl.h"
+        #include "wx/validate.h"
     #endif // wxUSE_GUI
 #endif
 
     #endif // wxUSE_GUI
 #endif
 
-#include "wx/event.h"
 #include "wx/module.h"
 
 #include "wx/module.h"
 
-#if wxUSE_GUI
-    #include "wx/validate.h"
-#if wxUSE_STOPWATCH
+#if wxUSE_GUI && wxUSE_STOPWATCH
     #include "wx/stopwatch.h"
     #include "wx/stopwatch.h"
-#endif
-#endif // wxUSE_GUI
+#endif // wxUSE_GUI && wxUSE_STOPWATCH
 
 // ----------------------------------------------------------------------------
 // wxWin macros
 
 // ----------------------------------------------------------------------------
 // wxWin macros
@@ -92,6 +90,7 @@
     IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
+    IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent, wxCommandEvent)
 #endif // wxUSE_GUI
 
 #if wxUSE_BASE
 #endif // wxUSE_GUI
 
 #if wxUSE_BASE
@@ -288,6 +287,11 @@ DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM)
 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
 
 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
 
+// Clipboard events
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_COPY)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_CUT)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_PASTE)
+
 // Generic command events
 // Note: a click is a higher-level event than button down/up
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
 // Generic command events
 // Note: a click is a higher-level event than button down/up
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
@@ -737,10 +741,12 @@ wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
 #endif
 }
 
 #endif
 }
 
+#if WXWIN_COMPATIBILITY_2_6
 long wxKeyEvent::KeyCode() const
 {
     return m_keyCode;
 }
 long wxKeyEvent::KeyCode() const
 {
     return m_keyCode;
 }
+#endif // WXWIN_COMPATIBILITY_2_6
 
 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
 {
 
 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
 {
@@ -760,6 +766,23 @@ wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
     SetEventObject(win);
 }
 
     SetEventObject(win);
 }
 
+// ----------------------------------------------------------------------------
+// wxHelpEvent
+// ----------------------------------------------------------------------------
+
+/* static */
+wxHelpEvent::Origin wxHelpEvent::GuessOrigin(Origin origin)
+{
+    if ( origin == Origin_Unknown )
+    {
+        // assume that the event comes from the help button if it's not from
+        // keyboard and that pressing F1 always results in the help event
+        origin = wxGetKeyState(WXK_F1) ? Origin_Keyboard : Origin_HelpButton;
+    }
+
+    return origin;
+}
+
 #endif // wxUSE_GUI
 
 
 #endif // wxUSE_GUI
 
 
@@ -1023,6 +1046,8 @@ wxEvtHandler::~wxEvtHandler()
         delete m_dynamicEvents;
     };
 
         delete m_dynamicEvents;
     };
 
+    if (m_pendingEvents)
+        m_pendingEvents->DeleteContents(true);
     delete m_pendingEvents;
 
 #if wxUSE_THREADS
     delete m_pendingEvents;
 
 #if wxUSE_THREADS
@@ -1084,10 +1109,7 @@ void wxEvtHandler::AddPendingEvent(wxEvent& event)
     wxENTER_CRIT_SECT( Lock() );
 
     if ( !m_pendingEvents )
     wxENTER_CRIT_SECT( Lock() );
 
     if ( !m_pendingEvents )
-    {
       m_pendingEvents = new wxList;
       m_pendingEvents = new wxList;
-      m_pendingEvents->DeleteContents(true);
-    }
 
     m_pendingEvents->Append(eventCopy);
 
 
     m_pendingEvents->Append(eventCopy);
 
@@ -1129,15 +1151,19 @@ void wxEvtHandler::ProcessPendingEvents()
     {
         wxEvent *event = (wxEvent *)node->GetData();
 
     {
         wxEvent *event = (wxEvent *)node->GetData();
 
+        // It's importan we remove event from list before processing it.
+        // Else a nested event loop, for example from a modal dialog, might
+        // process the same event again.
+        m_pendingEvents->Erase(node);
+
         wxLEAVE_CRIT_SECT( Lock() );
 
         ProcessEvent(*event);
         wxLEAVE_CRIT_SECT( Lock() );
 
         ProcessEvent(*event);
+        delete event;
 
         wxENTER_CRIT_SECT( Lock() );
 
 
         wxENTER_CRIT_SECT( Lock() );
 
-        m_pendingEvents->Erase(node);
-
-        if ( !--n )
+        if ( --n == 0 )
             break;
     }
 
             break;
     }
 
@@ -1342,6 +1368,10 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
         wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
 
         wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
 
+        // get next node before (maybe) calling the event handler as it could
+        // call Disconnect() invalidating the current node
+        node = node->GetNext();
+
         if ((event.GetEventType() == entry->m_eventType) && (entry->m_fn != 0))
         {
             wxEvtHandler *handler =
         if ((event.GetEventType() == entry->m_eventType) && (entry->m_fn != 0))
         {
             wxEvtHandler *handler =
@@ -1356,8 +1386,6 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
                 return true;
             }
         }
                 return true;
             }
         }
-
-        node = node->GetNext();
     }
 
     return false;
     }
 
     return false;