From: Julian Smart <julian@anthemion.co.uk>
Date: Mon, 14 Jul 2003 08:41:08 +0000 (+0000)
Subject: Rationalised OnIdle
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/955a919785b76a1826e6b8d55f696a0dfb62a318

Rationalised OnIdle


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21948 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/include/wx/app.h b/include/wx/app.h
index 0850ae3b72..35d9b5d06e 100644
--- a/include/wx/app.h
+++ b/include/wx/app.h
@@ -381,16 +381,13 @@ public:
         // it should return TRUE if more idle events are needed, FALSE if not
     virtual bool ProcessIdle() ;
 
-#if 0
-        // Send idle event to all top-level windows.
-        // Returns TRUE if more idle time is requested.
-    virtual bool SendIdleEvents();
-#endif
-
         // Send idle event to window and all subwindows
         // Returns TRUE if more idle time is requested.
     virtual bool SendIdleEvents(wxWindow* win, wxIdleEvent& event);
 
+        // Perform standard OnIdle behaviour: call from port's OnIdle
+    void OnIdle(wxIdleEvent& event);
+
 
     // top level window functions
     // --------------------------
diff --git a/include/wx/cocoa/app.h b/include/wx/cocoa/app.h
index 02bf4fa5b0..ac4078563f 100644
--- a/include/wx/cocoa/app.h
+++ b/include/wx/cocoa/app.h
@@ -53,9 +53,6 @@ public:
     virtual bool Yield(bool onlyIfNeeded = FALSE);
     virtual void WakeUpIdle() { CocoaRequestIdle(); }
     
-    /* Idle Processing */
-    void OnIdle(wxIdleEvent& event);
-
     virtual bool Initialize(int& argc, wxChar **argv);
     virtual void CleanUp();
     virtual bool CallOnInit();
diff --git a/include/wx/gtk/app.h b/include/wx/gtk/app.h
index 9b6143d198..fc603dafb7 100644
--- a/include/wx/gtk/app.h
+++ b/include/wx/gtk/app.h
@@ -52,9 +52,6 @@ public:
     virtual bool Yield(bool onlyIfNeeded = FALSE);
     virtual void WakeUpIdle();
 
-    // implementation only from now on
-    void OnIdle( wxIdleEvent &event );
-
     virtual bool Initialize(int& argc, wxChar **argv);
     virtual void CleanUp();
 
diff --git a/include/wx/gtk1/app.h b/include/wx/gtk1/app.h
index 9b6143d198..fc603dafb7 100644
--- a/include/wx/gtk1/app.h
+++ b/include/wx/gtk1/app.h
@@ -52,9 +52,6 @@ public:
     virtual bool Yield(bool onlyIfNeeded = FALSE);
     virtual void WakeUpIdle();
 
-    // implementation only from now on
-    void OnIdle( wxIdleEvent &event );
-
     virtual bool Initialize(int& argc, wxChar **argv);
     virtual void CleanUp();
 
diff --git a/include/wx/mgl/app.h b/include/wx/mgl/app.h
index 27cf02da75..e3bb8a3b38 100644
--- a/include/wx/mgl/app.h
+++ b/include/wx/mgl/app.h
@@ -48,9 +48,6 @@ public:
     virtual bool Pending();
     virtual void Dispatch();
 
-    // implementation only from now on
-    void OnIdle(wxIdleEvent &event);
-
     virtual bool Initialize(int& argc, wxChar **argv);
     virtual void CleanUp();
 
diff --git a/include/wx/motif/app.h b/include/wx/motif/app.h
index 79674e4f89..9a2526a1f1 100644
--- a/include/wx/motif/app.h
+++ b/include/wx/motif/app.h
@@ -66,8 +66,6 @@ public:
     // implementation from now on
     // --------------------------
     
-    void OnIdle(wxIdleEvent& event);
-    
 protected:
     bool                  m_showOnInit;
     
diff --git a/include/wx/x11/app.h b/include/wx/x11/app.h
index 71a56be26a..d1de31870d 100644
--- a/include/wx/x11/app.h
+++ b/include/wx/x11/app.h
@@ -66,8 +66,6 @@ public:
     // implementation from now on
     // --------------------------
     
-    void OnIdle(wxIdleEvent& event);
-    
     // Processes an X event.
     virtual bool ProcessXEvent(WXEvent* event);
     
diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm
index 71704b5e28..e264d8a408 100644
--- a/src/cocoa/app.mm
+++ b/src/cocoa/app.mm
@@ -134,7 +134,7 @@ void wxApp::Exit()
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
-    EVT_IDLE(wxApp::OnIdle)
+    EVT_IDLE(wxAppBase::OnIdle)
 //    EVT_END_SESSION(wxApp::OnEndSession)
 //    EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
 END_EVENT_TABLE()
@@ -278,37 +278,6 @@ void wxApp::Dispatch()
 {
 }
 
-void wxApp::OnIdle(wxIdleEvent& event)
-{
-    wxLogDebug("wxApp::OnIdle");
-#if 0
-   static bool s_inOnIdle = FALSE;
-
-    // Avoid recursion (via ProcessEvent default case)
-    if ( s_inOnIdle )
-        return;
-    s_inOnIdle = TRUE;
-#endif
-
-
-    DeletePendingObjects();
-
-    // flush the logged messages if any
-    wxLog *pLog = wxLog::GetActiveTarget();
-    if ( pLog != NULL && pLog->HasPendingMessages() )
-        pLog->Flush();
-
-#if 0
-    // Send OnIdle events to all windows
-    bool needMore = SendIdleEvents();
-
-    if (needMore)
-      event.RequestMore(TRUE);
-
-    s_inOnIdle = FALSE;
-#endif
-}
-
 // Yield to other processes
 
 bool wxApp::Yield(bool onlyIfNeeded)
diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp
index 8fa4b91bd4..164642f0f5 100644
--- a/src/common/appcmn.cpp
+++ b/src/common/appcmn.cpp
@@ -232,25 +232,6 @@ bool wxAppBase::ProcessIdle()
     return needMore;
 }
 
-#if 0
-// Send idle event to all top-level windows
-bool wxAppBase::SendIdleEvents()
-{
-    bool needMore = FALSE;
-
-    wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
-    while (node)
-    {
-        wxWindow* win = node->GetData();
-        if (SendIdleEvents(win))
-            needMore = TRUE;
-        node = node->GetNext();
-    }
-
-    return needMore;
-}
-#endif
-
 // Send idle event to window and all subwindows
 bool wxAppBase::SendIdleEvents(wxWindow* win, wxIdleEvent& event)
 {
@@ -279,6 +260,26 @@ bool wxAppBase::SendIdleEvents(wxWindow* win, wxIdleEvent& event)
     return needMore;
 }
 
+void wxAppBase::OnIdle(wxIdleEvent& event)
+{
+    // If there are pending events, we must process them: pending events
+    // are either events to the threads other than main or events posted
+    // with wxPostEvent() functions
+    // GRG: I have moved this here so that all pending events are processed
+    //   before starting to delete any objects. This behaves better (in
+    //   particular, wrt wxPostEvent) and is coherent with wxGTK's current
+    //   behaviour. Changed Feb/2000 before 2.1.14
+    ProcessPendingEvents();
+
+    // 'Garbage' collection of windows deleted with Close().
+    DeletePendingObjects();
+
+#if wxUSE_LOG
+    // flush the logged messages if any
+    wxLog::FlushActive();
+#endif // wxUSE_LOG
+
+}
 
 // ----------------------------------------------------------------------------
 // wxGUIAppTraitsBase
diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp
index 3235c6fbe5..7df0bb49a2 100644
--- a/src/gtk/app.cpp
+++ b/src/gtk/app.cpp
@@ -390,7 +390,7 @@ GtkWidget* wxGetRootWindow()
 IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
-    EVT_IDLE(wxApp::OnIdle)
+    EVT_IDLE(wxAppBase::OnIdle)
 END_EVENT_TABLE()
 
 wxApp::wxApp()
@@ -534,35 +534,6 @@ GdkVisual *wxApp::GetGdkVisual()
     return visual;
 }
 
-void wxApp::OnIdle( wxIdleEvent &event )
-{
-    static bool s_inOnIdle = FALSE;
-
-    // Avoid recursion (via ProcessEvent default case)
-    if (s_inOnIdle)
-        return;
-
-    s_inOnIdle = TRUE;
-
-    // Resend in the main thread events which have been prepared in other
-    // threads
-    ProcessPendingEvents();
-
-    // 'Garbage' collection of windows deleted with Close()
-    DeletePendingObjects();
-
-    // Now done in ProcessIdle()
-#if 0
-    // Send OnIdle events to all windows
-    bool needMore = SendIdleEvents();
-
-    if (needMore)
-        event.RequestMore(TRUE);
-#endif
-
-    s_inOnIdle = FALSE;
-}
-
 int wxApp::MainLoop()
 {
     gtk_main();
diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp
index 3235c6fbe5..7df0bb49a2 100644
--- a/src/gtk1/app.cpp
+++ b/src/gtk1/app.cpp
@@ -390,7 +390,7 @@ GtkWidget* wxGetRootWindow()
 IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
-    EVT_IDLE(wxApp::OnIdle)
+    EVT_IDLE(wxAppBase::OnIdle)
 END_EVENT_TABLE()
 
 wxApp::wxApp()
@@ -534,35 +534,6 @@ GdkVisual *wxApp::GetGdkVisual()
     return visual;
 }
 
-void wxApp::OnIdle( wxIdleEvent &event )
-{
-    static bool s_inOnIdle = FALSE;
-
-    // Avoid recursion (via ProcessEvent default case)
-    if (s_inOnIdle)
-        return;
-
-    s_inOnIdle = TRUE;
-
-    // Resend in the main thread events which have been prepared in other
-    // threads
-    ProcessPendingEvents();
-
-    // 'Garbage' collection of windows deleted with Close()
-    DeletePendingObjects();
-
-    // Now done in ProcessIdle()
-#if 0
-    // Send OnIdle events to all windows
-    bool needMore = SendIdleEvents();
-
-    if (needMore)
-        event.RequestMore(TRUE);
-#endif
-
-    s_inOnIdle = FALSE;
-}
-
 int wxApp::MainLoop()
 {
     gtk_main();
diff --git a/src/mac/app.cpp b/src/mac/app.cpp
index 324f39baed..58ee11d265 100644
--- a/src/mac/app.cpp
+++ b/src/mac/app.cpp
@@ -1025,35 +1025,13 @@ void wxApp::Dispatch()
 
 void wxApp::OnIdle(wxIdleEvent& event)
 {
-    // Avoid recursion (via ProcessEvent default case)
-    if ( s_inOnIdle )
-        return;
-
-  s_inOnIdle = TRUE;
-
-  // 'Garbage' collection of windows deleted with Close().
-  DeletePendingObjects();
-
-  // flush the logged messages if any
-  wxLog *pLog = wxLog::GetActiveTarget();
-  if ( pLog != NULL && pLog->HasPendingMessages() )
-    pLog->Flush();
-
-    // Now done in ProcessIdle()
-#if 0
-  // Send OnIdle events to all windows
-  bool needMore = SendIdleEvents();
-
-  if (needMore)
-    event.RequestMore(TRUE);
-#endif
-
+    wxAppBase::OnIdle(event);
+    
     // If they are pending events, we must process them: pending events are
     // either events to the threads other than main or events posted with
     // wxPostEvent() functions
     wxMacProcessNotifierAndPendingEvents();
 
-  s_inOnIdle = FALSE;
   if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
     wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
 }
diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp
index 324f39baed..58ee11d265 100644
--- a/src/mac/carbon/app.cpp
+++ b/src/mac/carbon/app.cpp
@@ -1025,35 +1025,13 @@ void wxApp::Dispatch()
 
 void wxApp::OnIdle(wxIdleEvent& event)
 {
-    // Avoid recursion (via ProcessEvent default case)
-    if ( s_inOnIdle )
-        return;
-
-  s_inOnIdle = TRUE;
-
-  // 'Garbage' collection of windows deleted with Close().
-  DeletePendingObjects();
-
-  // flush the logged messages if any
-  wxLog *pLog = wxLog::GetActiveTarget();
-  if ( pLog != NULL && pLog->HasPendingMessages() )
-    pLog->Flush();
-
-    // Now done in ProcessIdle()
-#if 0
-  // Send OnIdle events to all windows
-  bool needMore = SendIdleEvents();
-
-  if (needMore)
-    event.RequestMore(TRUE);
-#endif
-
+    wxAppBase::OnIdle(event);
+    
     // If they are pending events, we must process them: pending events are
     // either events to the threads other than main or events posted with
     // wxPostEvent() functions
     wxMacProcessNotifierAndPendingEvents();
 
-  s_inOnIdle = FALSE;
   if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
     wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
 }
diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp
index 2c505d83c2..d7126b0fcc 100644
--- a/src/mgl/app.cpp
+++ b/src/mgl/app.cpp
@@ -204,7 +204,7 @@ static void wxDestroyMGL_WM()
 IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
-    EVT_IDLE(wxApp::OnIdle)
+    EVT_IDLE(wxAppBase::OnIdle)
 END_EVENT_TABLE()
 
 
@@ -272,38 +272,6 @@ bool wxApp::OnInitGui()
     return TRUE;
 }
 
-void wxApp::OnIdle(wxIdleEvent &event)
-{
-    static bool s_inOnIdle = FALSE;
-
-    /* Avoid recursion (via ProcessEvent default case) */
-    if (s_inOnIdle)
-        return;
-
-    s_inOnIdle = TRUE;
-
-    /* Resend in the main thread events which have been prepared in other
-       threads */
-    ProcessPendingEvents();
-
-    // 'Garbage' collection of windows deleted with Close().
-    DeletePendingObjects();
-
-#if wxUSE_LOG
-    // flush the logged messages if any
-    wxLog::FlushActive();
-#endif // wxUSE_LOG
-
-    // Now done in ProcessIdle()
-#if 0
-    // Send OnIdle events to all windows
-    if ( SendIdleEvents() )
-        event.RequestMore(TRUE);
-#endif
-
-    s_inOnIdle = FALSE;
-}
-
 int wxApp::MainLoop()
 {
     int rt;
diff --git a/src/motif/app.cpp b/src/motif/app.cpp
index c01b74f67c..e5381193b1 100644
--- a/src/motif/app.cpp
+++ b/src/motif/app.cpp
@@ -71,7 +71,7 @@ wxHashTable *wxWidgetHashTable = NULL;
 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
-    EVT_IDLE(wxApp::OnIdle)
+    EVT_IDLE(wxAppBase::OnIdle)
 END_EVENT_TABLE()
 
 #ifdef __WXDEBUG__
@@ -203,48 +203,6 @@ void wxApp::HandlePropertyChange(WXEvent *event)
     XtDispatchEvent((XEvent*) event); /* let Motif do the work */
 }
 
-void wxApp::OnIdle(wxIdleEvent& event)
-{
-    static bool inOnIdle = FALSE;
-
-    // Avoid recursion (via ProcessEvent default case)
-    if (inOnIdle)
-        return;
-
-    inOnIdle = TRUE;
-
-    // If there are pending events, we must process them: pending events
-    // are either events to the threads other than main or events posted
-    // with wxPostEvent() functions
-    // GRG: I have moved this here so that all pending events are processed
-    //   before starting to delete any objects. This behaves better (in
-    //   particular, wrt wxPostEvent) and is coherent with wxGTK's current
-    //   behaviour. Also removed the '#if wxUSE_THREADS' around it.
-    //  Changed Mar/2000 before 2.1.14
-
-    // Flush pending events.
-    ProcessPendingEvents();
-
-    // 'Garbage' collection of windows deleted with Close().
-    DeletePendingObjects();
-
-    // flush the logged messages if any
-    wxLog *pLog = wxLog::GetActiveTarget();
-    if ( pLog != NULL && pLog->HasPendingMessages() )
-        pLog->Flush();
-
-    // Now done in ProcessIdle()
-#if 0
-    // Send OnIdle events to all windows
-    bool needMore = SendIdleEvents();
-
-    if (needMore)
-        event.RequestMore(TRUE);
-#endif
-
-    inOnIdle = FALSE;
-}
-
 static char *fallbackResources[] = {
     "*menuBar.marginHeight: 0",
     "*menuBar.shadowThickness: 1",
diff --git a/src/msw/app.cpp b/src/msw/app.cpp
index 79153ef858..03551b3c17 100644
--- a/src/msw/app.cpp
+++ b/src/msw/app.cpp
@@ -802,23 +802,8 @@ void wxApp::OnIdle(wxIdleEvent& event)
         return;
 
     wxIsInOnIdleFlag = TRUE;
-
-    // If there are pending events, we must process them: pending events
-    // are either events to the threads other than main or events posted
-    // with wxPostEvent() functions
-    // GRG: I have moved this here so that all pending events are processed
-    //   before starting to delete any objects. This behaves better (in
-    //   particular, wrt wxPostEvent) and is coherent with wxGTK's current
-    //   behaviour. Changed Feb/2000 before 2.1.14
-    ProcessPendingEvents();
-
-    // 'Garbage' collection of windows deleted with Close().
-    DeletePendingObjects();
-
-#if wxUSE_LOG
-    // flush the logged messages if any
-    wxLog::FlushActive();
-#endif // wxUSE_LOG
+    
+    wxAppBase::OnIdle(event);
 
 #if wxUSE_DC_CACHEING
     // automated DC cache management: clear the cached DCs and bitmap
@@ -828,17 +813,6 @@ void wxApp::OnIdle(wxIdleEvent& event)
         wxDC::ClearCache();
 #endif // wxUSE_DC_CACHEING
 
-    // Now done in ProcessIdle()
-#if 0
-    // Send OnIdle events to all windows
-    if ( SendIdleEvents() )
-    {
-        // SendIdleEvents() returns TRUE if at least one window requested more
-        // idle events
-        event.RequestMore(TRUE);
-    }
-#endif
-
     wxIsInOnIdleFlag = FALSE;
 }
 
diff --git a/src/os2/app.cpp b/src/os2/app.cpp
index 8af1146ac7..d0c2b5d7ed 100644
--- a/src/os2/app.cpp
+++ b/src/os2/app.cpp
@@ -777,25 +777,8 @@ void wxApp::OnIdle(
         return;
 
     gbInOnIdle = TRUE;
-
-    //
-    // If there are pending events, we must process them: pending events
-    // are either events to the threads other than main or events posted
-    // with wxPostEvent() functions
-    //
-    ProcessPendingEvents();
-
-    //
-    // 'Garbage' collection of windows deleted with Close().
-    //
-    DeletePendingObjects();
-
-#if wxUSE_LOG
-    //
-    // Flush the logged messages if any
-    //
-    wxLog::FlushActive();
-#endif // wxUSE_LOG
+    
+    wxAppBase::OnIdle(event);
 
 #if wxUSE_DC_CACHEING
     // automated DC cache management: clear the cached DCs and bitmap
@@ -807,21 +790,6 @@ void wxApp::OnIdle(
         wxDC::ClearCache();
 #endif // wxUSE_DC_CACHEING
 
-    // Now done in ProcessIdle()
-#if 0
-    //
-    // Send OnIdle events to all windows
-    //
-    if (SendIdleEvents())
-    {
-        //
-        // SendIdleEvents() returns TRUE if at least one window requested more
-        // idle events
-        //
-        rEvent.RequestMore(TRUE);
-    }
-#endif
-
     gbInOnIdle = FALSE;
 } // end of wxApp::OnIdle
 
diff --git a/src/x11/app.cpp b/src/x11/app.cpp
index 4aa78528cc..57612cd474 100644
--- a/src/x11/app.cpp
+++ b/src/x11/app.cpp
@@ -88,7 +88,7 @@ WXDisplay *wxApp::ms_display = NULL;
 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
-    EVT_IDLE(wxApp::OnIdle)
+    EVT_IDLE(wxAppBase::OnIdle)
 END_EVENT_TABLE()
 
 bool wxApp::Initialize(int& argc, wxChar **argv)
@@ -700,35 +700,6 @@ bool wxApp::HandlePropertyChange(WXEvent *event)
     return FALSE;
 }
 
-void wxApp::OnIdle(wxIdleEvent& event)
-{
-    static bool s_inOnIdle = FALSE;
-
-    // Avoid recursion (via ProcessEvent default case)
-    if (s_inOnIdle)
-        return;
-
-    s_inOnIdle = TRUE;
-
-    // Resend in the main thread events which have been prepared in other
-    // threads
-    ProcessPendingEvents();
-
-    // 'Garbage' collection of windows deleted with Close()
-    DeletePendingObjects();
-
-    // Now done in ProcessIdle()
-#if 0
-    // Send OnIdle events to all windows
-    bool needMore = SendIdleEvents();
-
-    if (needMore)
-        event.RequestMore(TRUE);
-#endif
-
-    s_inOnIdle = FALSE;
-}
-
 void wxApp::WakeUpIdle()
 {
     // TODO: use wxMotif implementation?