git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57637
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
14 files changed:
// with _extreme_ care or, better, don't use at all!
virtual bool Yield(bool onlyIfNeeded = false) = 0;
// with _extreme_ care or, better, don't use at all!
virtual bool Yield(bool onlyIfNeeded = false) = 0;
+ // returns true if the main thread is inside a Yield() call
+ bool IsYielding() const
+ { return m_isInsideYield; }
+
// this virtual function is called in the GUI mode when the application
// becomes idle and normally just sends wxIdleEvent to all interested
// parties
// this virtual function is called in the GUI mode when the application
// becomes idle and normally just sends wxIdleEvent to all interested
// parties
// does any of our windows have focus?
bool m_isActive;
// does any of our windows have focus?
bool m_isActive;
DECLARE_NO_COPY_CLASS(wxAppBase)
};
DECLARE_NO_COPY_CLASS(wxAppBase)
};
*/
static bool IsMainLoopRunning();
*/
static bool IsMainLoopRunning();
+ /**
+ Returns @true if called from inside Yield().
+ */
+ bool IsYielding() const;
+
/**
Process all pending events; it is necessary to call this function to
process posted events.
/**
Process all pending events; it is necessary to call this function to
process posted events.
user to perform actions which are not compatible with the current task.
Disabling menu items or whole menus during processing can avoid unwanted
reentrance of code: see ::wxSafeYield for a better function.
user to perform actions which are not compatible with the current task.
Disabling menu items or whole menus during processing can avoid unwanted
reentrance of code: see ::wxSafeYield for a better function.
+ You can avoid unwanted reentrancies also using IsYielding().
Note that Yield() will not flush the message logs. This is intentional as
calling Yield() is usually done to quickly update the screen and popping up
Note that Yield() will not flush the message logs. This is intentional as
calling Yield() is usually done to quickly update the screen and popping up
// Yield to other processes
bool wxApp::Yield(bool onlyIfNeeded)
{
// Yield to other processes
bool wxApp::Yield(bool onlyIfNeeded)
{
- // MT-FIXME
- static bool s_inYield = false;
-
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
// normally result in message boxes popping up &c
wxLog::Suspend();
#endif // wxUSE_LOG
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
// normally result in message boxes popping up &c
wxLog::Suspend();
#endif // wxUSE_LOG
+ m_isInsideYield = true;
// Run the event loop until it is out of events
while(1)
// Run the event loop until it is out of events
while(1)
wxLog::Resume();
#endif // wxUSE_LOG
wxLog::Resume();
#endif // wxUSE_LOG
+ m_isInsideYield = false;
+ m_isInsideYield = false;
+
// We don't want to exit the app if the user code shows a dialog from its
// OnInit() -- but this is what would happen if we set m_exitOnFrameDelete
// to Yes initially as this dialog would be the last top level window.
// We don't want to exit the app if the user code shows a dialog from its
// OnInit() -- but this is what would happen if we set m_exitOnFrameDelete
// to Yes initially as this dialog would be the last top level window.
return true; // can't process events from other threads
#endif // wxUSE_THREADS
return true; // can't process events from other threads
#endif // wxUSE_THREADS
- static bool s_inYield = false;
-
- if ( s_inYield )
+ m_isInsideYield = true;
#if wxUSE_LOG
wxLog::Suspend();
#if wxUSE_LOG
wxLog::Suspend();
wxLog::Resume();
#endif // wxUSE_LOG
wxLog::Resume();
#endif // wxUSE_LOG
+ m_isInsideYield = false;
// wxYield
//-----------------------------------------------------------------------------
// wxYield
//-----------------------------------------------------------------------------
-// not static because used by textctrl.cpp
-//
-// MT-FIXME
-bool wxIsInsideYield = false;
-
bool wxApp::Yield(bool onlyIfNeeded)
{
bool wxApp::Yield(bool onlyIfNeeded)
{
}
#endif // wxUSE_THREADS
}
#endif // wxUSE_THREADS
- wxIsInsideYield = true;
+ m_isInsideYield = true;
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
- wxIsInsideYield = false;
+ m_isInsideYield = false;
// wxYield
//-----------------------------------------------------------------------------
// wxYield
//-----------------------------------------------------------------------------
-// not static because used by textctrl.cpp
-//
-// MT-FIXME
-bool wxIsInsideYield = false;
-
bool wxApp::Yield(bool onlyIfNeeded)
{
bool wxApp::Yield(bool onlyIfNeeded)
{
}
#endif // wxUSE_THREADS
}
#endif // wxUSE_THREADS
- wxIsInsideYield = true;
+ m_isInsideYield = true;
// We need to remove idle callbacks or the loop will
// never finish.
// We need to remove idle callbacks or the loop will
// never finish.
- wxIsInsideYield = false;
+ m_isInsideYield = false;
// which implicitly calls wxYield()) so we override GtkText::draw() and simply
// don't do anything if we're inside wxYield()
// which implicitly calls wxYield()) so we override GtkText::draw() and simply
// don't do anything if we're inside wxYield()
-extern bool wxIsInsideYield;
-
extern "C" {
typedef void (*GtkDrawCallback)(GtkWidget *widget, GdkRectangle *rect);
}
extern "C" {
typedef void (*GtkDrawCallback)(GtkWidget *widget, GdkRectangle *rect);
}
extern "C" {
static void wxgtk_text_draw( GtkWidget *widget, GdkRectangle *rect)
{
extern "C" {
static void wxgtk_text_draw( GtkWidget *widget, GdkRectangle *rect)
{
- if ( !wxIsInsideYield )
+ if ( !wxTheApp->IsYielding() )
{
wxCHECK_RET( gs_gtk_text_draw != wxgtk_text_draw,
_T("infinite recursion in wxgtk_text_draw aborted") );
{
wxCHECK_RET( gs_gtk_text_draw != wxgtk_text_draw,
_T("infinite recursion in wxgtk_text_draw aborted") );
// wxYield
//-----------------------------------------------------------------------------
// wxYield
//-----------------------------------------------------------------------------
-static bool gs_inYield = false;
-
bool wxApp::Yield(bool onlyIfNeeded)
{
bool wxApp::Yield(bool onlyIfNeeded)
{
}
#endif // wxUSE_THREADS
}
#endif // wxUSE_THREADS
+ m_isInsideYield = true;
+ m_isInsideYield = false;
bool wxApp::Yield(bool onlyIfNeeded)
{
bool wxApp::Yield(bool onlyIfNeeded)
{
- static bool s_inYield = false;
-
- if ( s_inYield )
+ m_isInsideYield = true;
wxEventLoopGuarantor dummyLoopIfNeeded;
while (wxTheApp && wxTheApp->Pending())
wxTheApp->Dispatch();
wxEventLoopGuarantor dummyLoopIfNeeded;
while (wxTheApp && wxTheApp->Pending())
wxTheApp->Dispatch();
+ m_isInsideYield = false;
bool wxApp::Yield(bool onlyIfNeeded)
{
bool wxApp::Yield(bool onlyIfNeeded)
{
- // MT-FIXME
- static bool s_inYield = false;
-
- if ( s_inYield )
}
// set the flag and don't forget to reset it before returning
}
// set the flag and don't forget to reset it before returning
- s_inYield = true;
- wxON_BLOCK_EXIT_SET(s_inYield, false);
+ m_isInsideYield = true;
+ wxON_BLOCK_EXIT_SET(m_isInsideYield, false);
//
bool wxApp::Yield(bool onlyIfNeeded)
{
//
bool wxApp::Yield(bool onlyIfNeeded)
{
- static bool s_inYield = false;
-
- if ( s_inYield )
+ m_isInsideYield = true;
//
// We want to go back to the main message loop
//
// We want to go back to the main message loop
if (!wxTheApp->Dispatch())
break;
}
if (!wxTheApp->Dispatch())
break;
}
//
// If they are pending events, we must process them.
//
//
// If they are pending events, we must process them.
//
wxTheApp->ProcessPendingEvents();
HandleSockets();
wxTheApp->ProcessPendingEvents();
HandleSockets();
//
// Let the logs be flashed again
//
wxLog::Resume();
//
// Let the logs be flashed again
//
wxLog::Resume();
+ m_isInsideYield = false;
+
return true;
} // end of wxYield
return true;
} // end of wxYield
if (err != noErr)
return err;
if (err != noErr)
return err;
- url[actualSize] = '\0'; // Terminate the C string
+ url[actualSize] = '\0'; // Terminate the C string
ProcessSerialNumber PSN ;
PSN.highLongOfPSN = 0 ;
ProcessSerialNumber PSN ;
PSN.highLongOfPSN = 0 ;
// make sure we don't show 'virtual toplevel windows' like wxTaskBarIconWindow
if ( firstHidden == NULL && ( wxDynamicCast( win, wxFrame ) || wxDynamicCast( win, wxDialog ) ) )
firstHidden = win ;
// make sure we don't show 'virtual toplevel windows' like wxTaskBarIconWindow
if ( firstHidden == NULL && ( wxDynamicCast( win, wxFrame ) || wxDynamicCast( win, wxDialog ) ) )
firstHidden = win ;
else if ( win->IsIconized() )
else if ( win->IsIconized() )
if ( firstIconized == NULL )
firstIconized = win ;
}
if ( firstIconized == NULL )
firstIconized = win ;
}
// is it part of the application or the Help menu, then look for the id directly
if ( ( GetMenuHandle( kwxMacAppleMenuId ) != NULL && command.menu.menuRef == GetMenuHandle( kwxMacAppleMenuId ) ) ||
// is it part of the application or the Help menu, then look for the id directly
if ( ( GetMenuHandle( kwxMacAppleMenuId ) != NULL && command.menu.menuRef == GetMenuHandle( kwxMacAppleMenuId ) ) ||
- ( helpMenuHandle != NULL && command.menu.menuRef == helpMenuHandle ) ||
+ ( helpMenuHandle != NULL && command.menu.menuRef == helpMenuHandle ) ||
wxMenuBar::MacGetWindowMenuHMenu() != NULL && command.menu.menuRef == wxMenuBar::MacGetWindowMenuHMenu() )
{
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
wxMenuBar::MacGetWindowMenuHMenu() != NULL && command.menu.menuRef == wxMenuBar::MacGetWindowMenuHMenu() )
{
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
case kEventMenuTargetItem:
{
HICommand command ;
case kEventMenuTargetItem:
{
HICommand command ;
command.menu.menuRef = menuRef;
command.menu.menuItemIndex = cEvent.GetParameter<MenuItemIndex>(kEventParamMenuItemIndex,typeMenuItemIndex) ;
command.commandID = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
command.menu.menuRef = menuRef;
command.menu.menuItemIndex = cEvent.GetParameter<MenuItemIndex>(kEventParamMenuItemIndex,typeMenuItemIndex) ;
command.commandID = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
if ( !wxMacInitCocoa() )
return false;
if ( !wxMacInitCocoa() )
return false;
}
#endif // wxUSE_THREADS
}
#endif // wxUSE_THREADS
- static bool s_inYield = false;
-
- if (s_inYield)
+ m_isInsideYield = true;
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
while ( loop->Pending() )
loop->Dispatch();
}
while ( loop->Pending() )
loop->Dispatch();
}
// it's necessary to call ProcessIdle() to update the frames sizes which
// might have been changed (it also will update other things set from
// OnUpdateUI() which is a nice (and desired) side effect)
while ( ProcessIdle() ) {}
// it's necessary to call ProcessIdle() to update the frames sizes which
// might have been changed (it also will update other things set from
// OnUpdateUI() which is a nice (and desired) side effect)
while ( ProcessIdle() ) {}
#if wxUSE_LOG
wxLog::Resume();
#endif // wxUSE_LOG
#if wxUSE_LOG
wxLog::Resume();
#endif // wxUSE_LOG
+ m_isInsideYield = false;
{
keyval = (keyval - '0') + WXK_NUMPAD0;
}
{
keyval = (keyval - '0') + WXK_NUMPAD0;
}
- else if (keycode >= 65 && keycode <= 81)
+ else if (keycode >= 65 && keycode <= 81)
{
switch (keycode)
{
case 76 :
keyval = WXK_NUMPAD_ENTER;
break;
{
switch (keycode)
{
case 76 :
keyval = WXK_NUMPAD_ENTER;
break;
case 81:
keyval = WXK_NUMPAD_EQUAL;
break;
case 81:
keyval = WXK_NUMPAD_EQUAL;
break;
case 67:
keyval = WXK_NUMPAD_MULTIPLY;
break;
case 67:
keyval = WXK_NUMPAD_MULTIPLY;
break;
case 75:
keyval = WXK_NUMPAD_DIVIDE;
break;
case 75:
keyval = WXK_NUMPAD_DIVIDE;
break;
case 78:
keyval = WXK_NUMPAD_SUBTRACT;
break;
case 78:
keyval = WXK_NUMPAD_SUBTRACT;
break;
case 69:
keyval = WXK_NUMPAD_ADD;
break;
case 69:
keyval = WXK_NUMPAD_ADD;
break;
case 65:
keyval = WXK_NUMPAD_DECIMAL;
break;
case 65:
keyval = WXK_NUMPAD_DECIMAL;
break;
event.m_shiftDown = modifiers & shiftKey;
event.m_controlDown = modifiers & controlKey;
event.m_altDown = modifiers & optionKey;
event.m_shiftDown = modifiers & shiftKey;
event.m_controlDown = modifiers & controlKey;
event.m_altDown = modifiers & optionKey;
HICommand command;
memset( &command, 0 , sizeof(command) );
command.commandID = kHICommandHide ;
HICommand command;
memset( &command, 0 , sizeof(command) );
command.commandID = kHICommandHide ;
- event.SetParameter<HICommand>(kEventParamDirectObject, command );
+ event.SetParameter<HICommand>(kEventParamDirectObject, command );
SendEventToApplication( event );
#endif
}
SendEventToApplication( event );
#endif
}
int i;
for (i = 0; i < 2; i++)
{
int i;
for (i = 0; i < 2; i++)
{
- static bool s_inYield = false;
-
- if ( s_inYield )
+ m_isInsideYield = true;
// Make sure we have an event loop object,
// or Pending/Dispatch will fail
// Make sure we have an event loop object,
// or Pending/Dispatch will fail
- wxEventLoopGuarantor dummyLoopIfNeeded;
+ wxEventLoopGuarantor dummyLoopIfNeeded;
+
// Call dispatch at least once so that sockets
// can be tested
wxTheApp->Dispatch();
// Call dispatch at least once so that sockets
// can be tested
wxTheApp->Dispatch();
+ m_isInsideYield = false;