Added wxFrameBase::OnMenuOpen, and wxUSE_IDLEMENUUPDATES in platform.h

Experimental wxUpdateUIEvent::SetUpdateInterval() function to limit
UI update frequency


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21746 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2003-07-07 16:21:44 +00:00
parent f65a450a11
commit 0b30bb0bda
41 changed files with 186 additions and 29 deletions

View File

@@ -1529,6 +1529,20 @@ public:
void Enable(bool enable) { m_enabled = enable; m_setEnabled = TRUE; } void Enable(bool enable) { m_enabled = enable; m_setEnabled = TRUE; }
void SetText(const wxString& text) { m_text = text; m_setText = TRUE; } void SetText(const wxString& text) { m_text = text; m_setText = TRUE; }
// Sets the interval between updates in milliseconds.
// Set to -1 to disable updates, or to 0 to update as frequently as possible.
static void SetUpdateInterval(long updateInterval) { m_updateInterval = updateInterval; }
// Returns the current interval between updates in milliseconds
static long GetUpdateInterval() { return m_updateInterval ; }
// Can we update?
static bool CanUpdate() ;
// Reset the update time to provide a delay until the next
// time we should update
static void ResetUpdateTime() ;
virtual wxEvent *Clone() const { return new wxUpdateUIEvent(*this); } virtual wxEvent *Clone() const { return new wxUpdateUIEvent(*this); }
protected: protected:
@@ -1538,6 +1552,10 @@ protected:
bool m_setText; bool m_setText;
bool m_setChecked; bool m_setChecked;
wxString m_text; wxString m_text;
#if wxUSE_LONGLONG
static wxLongLong m_lastUpdate;
#endif
static long m_updateInterval;
private: private:
DECLARE_DYNAMIC_CLASS(wxUpdateUIEvent) DECLARE_DYNAMIC_CLASS(wxUpdateUIEvent)

View File

@@ -142,6 +142,7 @@ public:
// event handlers // event handlers
void OnIdle(wxIdleEvent& event); void OnIdle(wxIdleEvent& event);
void OnMenuOpen(wxMenuEvent& event);
void OnMenuHighlight(wxMenuEvent& event); void OnMenuHighlight(wxMenuEvent& event);
#if wxUSE_MENUS #if wxUSE_MENUS

View File

@@ -327,5 +327,17 @@
#endif #endif
#endif #endif
/* Choose which method we will use for updating menus
* - in OnIdle, or when we receive a wxEVT_MENU_OPEN event.
* Presently, only Windows and GTK+ support wxEVT_MENU_OPEN.
*/
#ifndef wxUSE_IDLEMENUUPDATES
#if defined(__WXMSW__) || defined(__WXGTK__)
#define wxUSE_IDLEMENUUPDATES 0
#else
#define wxUSE_IDLEMENUUPDATES 1
#endif
#endif
#endif /* _WX_PLATFORM_H_ */ #endif /* _WX_PLATFORM_H_ */

View File

@@ -256,6 +256,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject(this); event.SetEventObject(this);
ProcessEvent(event); ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -44,6 +44,9 @@
#if wxUSE_GUI #if wxUSE_GUI
#include "wx/validate.h" #include "wx/validate.h"
#if wxUSE_STOPWATCH
#include "wx/stopwatch.h"
#endif
#endif // wxUSE_GUI #endif // wxUSE_GUI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -362,6 +365,57 @@ wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
m_isCommandEvent = TRUE; m_isCommandEvent = TRUE;
} }
/*
* UI update events
*/
#if wxUSE_LONGLONG
wxLongLong wxUpdateUIEvent::m_lastUpdate = 0;
#endif
long wxUpdateUIEvent::m_updateInterval = 0;
// Can we update?
bool wxUpdateUIEvent::CanUpdate()
{
if (m_updateInterval == -1)
return FALSE;
else if (m_updateInterval == 0)
return TRUE;
else
{
#if wxUSE_STOPWATCH && wxUSE_LONGLONG
wxLongLong now = wxGetLocalTimeMillis();
if (now > (m_lastUpdate + m_updateInterval))
{
return TRUE;
}
#else
// If we don't have wxStopWatch or wxLongLong, we
// should err on the safe side and update now anyway.
return TRUE;
#endif
}
return FALSE;
}
// Reset the update time to provide a delay until the next
// time we should update
void wxUpdateUIEvent::ResetUpdateTime()
{
#if wxUSE_STOPWATCH && wxUSE_LONGLONG
if (m_updateInterval > 0)
{
wxLongLong now = wxGetLocalTimeMillis();
if (now > (m_lastUpdate + m_updateInterval))
{
m_lastUpdate = now;
}
}
#endif
}
/* /*
* Scroll events * Scroll events
*/ */

View File

@@ -46,7 +46,12 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow) BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow)
#if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
EVT_IDLE(wxFrameBase::OnIdle) EVT_IDLE(wxFrameBase::OnIdle)
#endif
#if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
EVT_MENU_OPEN(wxFrameBase::OnMenuOpen)
#endif
EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight) EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -219,9 +224,17 @@ void wxFrameBase::OnMenuHighlight(wxMenuEvent& event)
void wxFrameBase::OnIdle(wxIdleEvent& WXUNUSED(event) ) void wxFrameBase::OnIdle(wxIdleEvent& WXUNUSED(event) )
{ {
#if wxUSE_MENUS #if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
if (wxUpdateUIEvent::CanUpdate())
DoMenuUpdates();
#endif
}
void wxFrameBase::OnMenuOpen(wxMenuEvent& WXUNUSED(event))
{
#if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
DoMenuUpdates(); DoMenuUpdates();
#endif // wxUSE_MENUS #endif
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -583,7 +583,8 @@ void wxToolBarBase::OnMouseEnter(int id)
void wxToolBarBase::OnIdle(wxIdleEvent& event) void wxToolBarBase::OnIdle(wxIdleEvent& event)
{ {
DoToolbarUpdates(); if (wxUpdateUIEvent::CanUpdate())
DoToolbarUpdates();
event.Skip(); event.Skip();
} }

View File

@@ -550,6 +550,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject( this ); event.SetEventObject( this );
ProcessEvent( event ); ProcessEvent( event );
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -220,7 +220,8 @@ void wxCheckBox::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxCheckBox::DoGetBestSize() const wxSize wxCheckBox::DoGetBestSize() const

View File

@@ -1037,7 +1037,8 @@ void wxListBox::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxListBox::DoGetBestSize() const wxSize wxListBox::DoGetBestSize() const

View File

@@ -239,7 +239,8 @@ void wxRadioButton::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxRadioButton::DoGetBestSize() const wxSize wxRadioButton::DoGetBestSize() const

View File

@@ -673,7 +673,8 @@ void wxToolBar::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
#endif // wxUSE_TOOLBAR_NATIVE #endif // wxUSE_TOOLBAR_NATIVE

View File

@@ -1591,7 +1591,8 @@ void wxTextCtrl::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxTextCtrl::DoGetBestSize() const wxSize wxTextCtrl::DoGetBestSize() const

View File

@@ -166,7 +166,8 @@ void wxToggleButton::OnInternalIdle()
gdk_window_set_cursor(win, cursor.GetCursor()); gdk_window_set_cursor(win, cursor.GetCursor());
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
// wxSize DoGetBestSize() const // wxSize DoGetBestSize() const

View File

@@ -3022,7 +3022,8 @@ void wxWindowGTK::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
void wxWindowGTK::DoGetSize( int *width, int *height ) const void wxWindowGTK::DoGetSize( int *width, int *height ) const

View File

@@ -550,6 +550,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject( this ); event.SetEventObject( this );
ProcessEvent( event ); ProcessEvent( event );
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -220,7 +220,8 @@ void wxCheckBox::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxCheckBox::DoGetBestSize() const wxSize wxCheckBox::DoGetBestSize() const

View File

@@ -1037,7 +1037,8 @@ void wxListBox::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxListBox::DoGetBestSize() const wxSize wxListBox::DoGetBestSize() const

View File

@@ -239,7 +239,8 @@ void wxRadioButton::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxRadioButton::DoGetBestSize() const wxSize wxRadioButton::DoGetBestSize() const

View File

@@ -673,7 +673,8 @@ void wxToolBar::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
#endif // wxUSE_TOOLBAR_NATIVE #endif // wxUSE_TOOLBAR_NATIVE

View File

@@ -1591,7 +1591,8 @@ void wxTextCtrl::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
wxSize wxTextCtrl::DoGetBestSize() const wxSize wxTextCtrl::DoGetBestSize() const

View File

@@ -166,7 +166,8 @@ void wxToggleButton::OnInternalIdle()
gdk_window_set_cursor(win, cursor.GetCursor()); gdk_window_set_cursor(win, cursor.GetCursor());
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
// wxSize DoGetBestSize() const // wxSize DoGetBestSize() const

View File

@@ -3022,7 +3022,8 @@ void wxWindowGTK::OnInternalIdle()
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
void wxWindowGTK::DoGetSize( int *width, int *height ) const void wxWindowGTK::DoGetSize( int *width, int *height ) const

View File

@@ -978,6 +978,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject(this); event.SetEventObject(this);
ProcessEvent(event); ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -978,6 +978,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject(this); event.SetEventObject(this);
ProcessEvent(event); ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -1371,7 +1371,8 @@ void wxWindowMac::OnIdle(wxIdleEvent& event)
{ {
// This calls the UI-update mechanism (querying windows for // This calls the UI-update mechanism (querying windows for
// menu/toolbar/control state information) // menu/toolbar/control state information)
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
// Raise the window to the top of the Z order // Raise the window to the top of the Z order

View File

@@ -1371,7 +1371,8 @@ void wxWindowMac::OnIdle(wxIdleEvent& event)
{ {
// This calls the UI-update mechanism (querying windows for // This calls the UI-update mechanism (querying windows for
// menu/toolbar/control state information) // menu/toolbar/control state information)
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
// Raise the window to the top of the Z order // Raise the window to the top of the Z order

View File

@@ -278,6 +278,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject(this); event.SetEventObject(this);
ProcessEvent(event); ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -99,7 +99,11 @@ bool wxEventLoopImpl::SendIdleEvent()
{ {
wxIdleEvent event; wxIdleEvent event;
return wxTheApp->ProcessEvent(event) && event.MoreRequested(); bool processed = wxTheApp->ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return processed && event.MoreRequested();
} }
// ============================================================================ // ============================================================================

View File

@@ -1278,5 +1278,6 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
void wxWindowMGL::OnIdle(wxIdleEvent& WXUNUSED(event)) void wxWindowMGL::OnIdle(wxIdleEvent& WXUNUSED(event))
{ {
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }

View File

@@ -176,7 +176,11 @@ bool wxApp::ProcessIdle()
{ {
wxIdleEvent event; wxIdleEvent event;
return ProcessEvent(event) && event.MoreRequested(); bool processed = ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return processed && event.MoreRequested();
} }
void wxApp::ExitMainLoop() void wxApp::ExitMainLoop()

View File

@@ -1687,7 +1687,8 @@ void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
{ {
// This calls the UI-update mechanism (querying windows for // This calls the UI-update mechanism (querying windows for
// menu/toolbar/control state information) // menu/toolbar/control state information)
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -691,6 +691,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject(this); event.SetEventObject(this);
ProcessEvent(event); ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -139,7 +139,11 @@ bool wxEventLoopImpl::SendIdleMessage()
{ {
wxIdleEvent event; wxIdleEvent event;
return wxTheApp->ProcessEvent(event) && event.MoreRequested(); bool processed = wxTheApp->ProcessEvent(event) ;
wxUpdateUIEvent::ResetUpdateTime();
return processed && event.MoreRequested();
} }
// ============================================================================ // ============================================================================

View File

@@ -1184,7 +1184,8 @@ void wxWindowMSW::OnIdle(wxIdleEvent& WXUNUSED(event))
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} }
// Set this window to be the child of 'parent'. // Set this window to be the child of 'parent'.

View File

@@ -668,6 +668,7 @@ bool wxApp::ProcessIdle()
vEvent.SetEventObject(this); vEvent.SetEventObject(this);
ProcessEvent(vEvent); ProcessEvent(vEvent);
wxUpdateUIEvent::ResetUpdateTime();
return vEvent.MoreRequested(); return vEvent.MoreRequested();
} // end of wxApp::ProcessIdle } // end of wxApp::ProcessIdle

View File

@@ -140,7 +140,11 @@ bool wxEventLoopImpl::SendIdleMessage()
{ {
wxIdleEvent event; wxIdleEvent event;
return wxTheApp->ProcessEvent(event) && event.MoreRequested(); bool processed = wxTheApp->ProcessEvent(event) ;
wxUpdateUIEvent::ResetUpdateTime();
return processed && event.MoreRequested();
} }
// ============================================================================ // ============================================================================

View File

@@ -1364,7 +1364,8 @@ void wxWindowOS2::OnIdle(
(void)GetEventHandler()->ProcessEvent(rEvent); (void)GetEventHandler()->ProcessEvent(rEvent);
} }
} }
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
} // end of wxWindowOS2::OnIdle } // end of wxWindowOS2::OnIdle
// //

View File

@@ -681,6 +681,8 @@ bool wxApp::ProcessIdle()
event.SetEventObject(this); event.SetEventObject(this);
ProcessEvent(event); ProcessEvent(event);
wxUpdateUIEvent::ResetUpdateTime();
return event.MoreRequested(); return event.MoreRequested();
} }

View File

@@ -338,7 +338,11 @@ bool wxEventLoopImpl::SendIdleEvent()
wxIdleEvent event; wxIdleEvent event;
event.SetEventObject(wxTheApp); event.SetEventObject(wxTheApp);
return wxTheApp->ProcessEvent(event) && event.MoreRequested(); bool processed = wxTheApp->ProcessEvent(event) ;
wxUpdateUIEvent::ResetUpdateTime();
return processed && event.MoreRequested();
} }
// ============================================================================ // ============================================================================

View File

@@ -1287,7 +1287,8 @@ void wxWindowX11::OnInternalIdle()
// This calls the UI-update mechanism (querying windows for // This calls the UI-update mechanism (querying windows for
// menu/toolbar/control state information) // menu/toolbar/control state information)
UpdateWindowUI(); if (wxUpdateUIEvent::CanUpdate())
UpdateWindowUI();
// Set the input focus if couldn't do it before // Set the input focus if couldn't do it before
if (m_needsInputFocus) if (m_needsInputFocus)