// 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
// does any of our windows have focus?
bool m_isActive;
+ bool m_isInsideYield;
DECLARE_NO_COPY_CLASS(wxAppBase)
};
*/
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.
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
// 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 (s_inYield)
+ if (m_isInsideYield)
{
if ( !onlyIfNeeded )
{
return false;
}
- s_inYield = true;
+ m_isInsideYield = true;
// Run the event loop until it is out of events
while(1)
wxLog::Resume();
#endif // wxUSE_LOG
- s_inYield = false;
+ m_isInsideYield = false;
return true;
}
m_isActive = true;
+ 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.
return true; // can't process events from other threads
#endif // wxUSE_THREADS
- static bool s_inYield = false;
-
- if ( s_inYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
return false;
}
- s_inYield = true;
+ m_isInsideYield = true;
#if wxUSE_LOG
wxLog::Suspend();
wxLog::Resume();
#endif // wxUSE_LOG
- s_inYield = false;
+ m_isInsideYield = false;
return true;
}
// wxYield
//-----------------------------------------------------------------------------
-// not static because used by textctrl.cpp
-//
-// MT-FIXME
-bool wxIsInsideYield = false;
-
bool wxApp::Yield(bool onlyIfNeeded)
{
- if ( wxIsInsideYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
}
#endif // wxUSE_THREADS
- wxIsInsideYield = true;
+ m_isInsideYield = true;
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
wxLog::Resume();
#endif
- wxIsInsideYield = false;
+ m_isInsideYield = false;
return true;
}
// wxYield
//-----------------------------------------------------------------------------
-// not static because used by textctrl.cpp
-//
-// MT-FIXME
-bool wxIsInsideYield = false;
-
bool wxApp::Yield(bool onlyIfNeeded)
{
- if ( wxIsInsideYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
}
#endif // wxUSE_THREADS
- wxIsInsideYield = true;
+ m_isInsideYield = true;
// We need to remove idle callbacks or the loop will
// never finish.
wxLog::Resume();
#endif
- wxIsInsideYield = false;
+ m_isInsideYield = false;
return true;
}
// 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" {
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") );
// wxYield
//-----------------------------------------------------------------------------
-static bool gs_inYield = false;
-
bool wxApp::Yield(bool onlyIfNeeded)
{
- if ( gs_inYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
}
#endif // wxUSE_THREADS
- gs_inYield = true;
+ m_isInsideYield = true;
wxLog::Suspend();
wxLog::Resume();
- gs_inYield = false;
+ m_isInsideYield = false;
return true;
}
bool wxApp::Yield(bool onlyIfNeeded)
{
- static bool s_inYield = false;
-
- if ( s_inYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
return false;
}
- s_inYield = true;
+ m_isInsideYield = true;
wxEventLoopGuarantor dummyLoopIfNeeded;
while (wxTheApp && wxTheApp->Pending())
wxTheApp->Dispatch();
- s_inYield = false;
+ m_isInsideYield = false;
return true;
}
bool wxApp::Yield(bool onlyIfNeeded)
{
- // MT-FIXME
- static bool s_inYield = false;
-
- if ( s_inYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
}
// 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);
#if wxUSE_LOG
//
bool wxApp::Yield(bool onlyIfNeeded)
{
- static bool s_inYield = false;
-
- if ( s_inYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
//
wxLog::Suspend();
- s_inYield = true;
+ m_isInsideYield = true;
//
// We want to go back to the main message loop
if (!wxTheApp->Dispatch())
break;
}
+
//
// If they are pending events, we must process them.
//
wxTheApp->ProcessPendingEvents();
HandleSockets();
+
//
// Let the logs be flashed again
//
wxLog::Resume();
- s_inYield = false;
+ m_isInsideYield = false;
+
return true;
} // end of wxYield
if (err != noErr)
return err;
- url[actualSize] = '\0'; // Terminate the C string
+ url[actualSize] = '\0'; // Terminate the C string
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 ;
- }
+ }
else if ( win->IsIconized() )
- {
+ {
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 ) ) ||
- ( helpMenuHandle != NULL && command.menu.menuRef == helpMenuHandle ) ||
+ ( helpMenuHandle != NULL && command.menu.menuRef == helpMenuHandle ) ||
wxMenuBar::MacGetWindowMenuHMenu() != NULL && command.menu.menuRef == wxMenuBar::MacGetWindowMenuHMenu() )
{
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
case kEventMenuTargetItem:
{
HICommand command ;
-
+
command.menu.menuRef = menuRef;
command.menu.menuItemIndex = cEvent.GetParameter<MenuItemIndex>(kEventParamMenuItemIndex,typeMenuItemIndex) ;
command.commandID = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
if ( !wxMacInitCocoa() )
return false;
-
+
return true;
}
}
#endif // wxUSE_THREADS
- static bool s_inYield = false;
-
- if (s_inYield)
+ if (m_isInsideYield)
{
if ( !onlyIfNeeded )
{
return false;
}
- s_inYield = true;
+ m_isInsideYield = true;
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
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() ) {}
-
+
#if wxUSE_LOG
wxLog::Resume();
#endif // wxUSE_LOG
- s_inYield = false;
+ m_isInsideYield = false;
return true;
}
{
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;
-
+
case 81:
keyval = WXK_NUMPAD_EQUAL;
break;
-
+
case 67:
keyval = WXK_NUMPAD_MULTIPLY;
break;
-
+
case 75:
keyval = WXK_NUMPAD_DIVIDE;
break;
-
+
case 78:
keyval = WXK_NUMPAD_SUBTRACT;
break;
-
+
case 69:
keyval = WXK_NUMPAD_ADD;
break;
-
+
case 65:
keyval = WXK_NUMPAD_DECIMAL;
break;
}
}
}
-
+
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 ;
- event.SetParameter<HICommand>(kEventParamDirectObject, command );
+ event.SetParameter<HICommand>(kEventParamDirectObject, command );
SendEventToApplication( event );
#endif
}
int i;
for (i = 0; i < 2; i++)
{
- static bool s_inYield = false;
-
- if ( s_inYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
return false;
}
- s_inYield = true;
+ m_isInsideYield = true;
// 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();
#endif
ProcessIdle();
- s_inYield = false;
+ m_isInsideYield = false;
}
return true;