Commit 80a402a3 authored by Dick Hollenbeck's avatar Dick Hollenbeck

wx 2.8 now builds, but the quasi-modal support seems broken on 2.8. Wanted...

wx 2.8 now builds, but the quasi-modal support seems broken on 2.8.  Wanted others to be able to build at least.
parent a2227a75
...@@ -153,6 +153,8 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent ) ...@@ -153,6 +153,8 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
bool EDA_BASE_FRAME::Enable( bool enable ) bool EDA_BASE_FRAME::Enable( bool enable )
{ {
// so we can do logging of this state change:
#if defined(DEBUG) #if defined(DEBUG)
const char* type_id = typeid( *this ).name(); const char* type_id = typeid( *this ).name();
printf( "wxFrame %s: %s\n", type_id, enable ? "enabled" : "disabled" ); printf( "wxFrame %s: %s\n", type_id, enable ? "enabled" : "disabled" );
......
...@@ -130,6 +130,8 @@ bool DIALOG_SHIM::Show( bool show ) ...@@ -130,6 +130,8 @@ bool DIALOG_SHIM::Show( bool show )
bool DIALOG_SHIM::Enable( bool enable ) bool DIALOG_SHIM::Enable( bool enable )
{ {
// so we can do logging of this state change:
#if defined(DEBUG) #if defined(DEBUG)
const char* type_id = typeid( *this ).name(); const char* type_id = typeid( *this ).name();
printf( "wxDialog %s: %s\n", type_id, enable ? "enabled" : "disabled" ); printf( "wxDialog %s: %s\n", type_id, enable ? "enabled" : "disabled" );
...@@ -139,6 +141,73 @@ bool DIALOG_SHIM::Enable( bool enable ) ...@@ -139,6 +141,73 @@ bool DIALOG_SHIM::Enable( bool enable )
} }
#if !wxCHECK_VERSION( 2, 9, 4 )
wxWindow* DIALOG_SHIM::CheckIfCanBeUsedAsParent( wxWindow* parent ) const
{
if ( !parent )
return NULL;
extern WXDLLIMPEXP_DATA_BASE(wxList) wxPendingDelete;
if ( wxPendingDelete.Member(parent) || parent->IsBeingDeleted() )
{
// this window is being deleted and we shouldn't create any children
// under it
return NULL;
}
if ( parent->GetExtraStyle() & wxWS_EX_TRANSIENT )
{
// this window is not being deleted yet but it's going to disappear
// soon so still don't parent this window under it
return NULL;
}
if ( !parent->IsShownOnScreen() )
{
// using hidden parent won't work correctly neither
return NULL;
}
// FIXME-VC6: this compiler requires an explicit const cast or it fails
// with error C2446
if ( const_cast<const wxWindow *>(parent) == this )
{
// not sure if this can really happen but it doesn't hurt to guard
// against this clearly invalid situation
return NULL;
}
return parent;
}
wxWindow* DIALOG_SHIM::GetParentForModalDialog(wxWindow *parent, long style) const
{
// creating a parent-less modal dialog will result (under e.g. wxGTK2)
// in an unfocused dialog, so try to find a valid parent for it unless we
// were explicitly asked not to
if ( style & wxDIALOG_NO_PARENT )
return NULL;
// first try the given parent
if ( parent )
parent = CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent));
// then the currently active window
if ( !parent )
parent = CheckIfCanBeUsedAsParent(
wxGetTopLevelParent(wxGetActiveWindow()));
// and finally the application main window
if ( !parent )
parent = CheckIfCanBeUsedAsParent(wxTheApp->GetTopWindow());
return parent;
}
#endif
int DIALOG_SHIM::ShowQuasiModal() int DIALOG_SHIM::ShowQuasiModal()
{ {
// toggle a window's "enable" status to disabled, then enabled on exit. // toggle a window's "enable" status to disabled, then enabled on exit.
...@@ -147,7 +216,14 @@ int DIALOG_SHIM::ShowQuasiModal() ...@@ -147,7 +216,14 @@ int DIALOG_SHIM::ShowQuasiModal()
{ {
wxWindow* m_win; wxWindow* m_win;
ENABLE_DISABLE( wxWindow* aWindow ) : m_win( aWindow ) { if( m_win ) m_win->Disable(); } ENABLE_DISABLE( wxWindow* aWindow ) : m_win( aWindow ) { if( m_win ) m_win->Disable(); }
~ENABLE_DISABLE() { if( m_win ) m_win->Enable(); } ~ENABLE_DISABLE()
{
if( m_win )
{
m_win->Enable();
m_win->SetFocus(); // let's focus back on the parent window
}
}
}; };
// This is an exception safe way to zero a pointer before returning. // This is an exception safe way to zero a pointer before returning.
...@@ -168,7 +244,7 @@ int DIALOG_SHIM::ShowQuasiModal() ...@@ -168,7 +244,7 @@ int DIALOG_SHIM::ShowQuasiModal()
if( win ) if( win )
win->ReleaseMouse(); win->ReleaseMouse();
wxWindow* parent = GetParentForModalDialog(); wxWindow* parent = GetParentForModalDialog( GetParent(), GetWindowStyle() );
ENABLE_DISABLE toggle( parent ); ENABLE_DISABLE toggle( parent );
...@@ -176,16 +252,13 @@ int DIALOG_SHIM::ShowQuasiModal() ...@@ -176,16 +252,13 @@ int DIALOG_SHIM::ShowQuasiModal()
m_qmodal_showing = true; m_qmodal_showing = true;
wxGUIEventLoop event_loop; WX_EVENT_LOOP event_loop;
wxEventLoopActivator event_loop_stacker( &event_loop ); wxEventLoopActivator event_loop_stacker( &event_loop );
m_qmodal_loop = &event_loop; m_qmodal_loop = &event_loop;
event_loop.Run(); event_loop.Run();
if( toggle.m_win ) // let's focus back on the parent window
toggle.m_win->SetFocus();
return GetReturnCode(); return GetReturnCode();
} }
...@@ -233,7 +306,7 @@ static bool findWindowRecursively( const wxWindowList& children, const wxWindow* ...@@ -233,7 +306,7 @@ static bool findWindowRecursively( const wxWindowList& children, const wxWindow*
} }
static bool findWindowReursively( const wxWindow* topmost, const wxWindow* wanted ) static bool findWindowRecursively( const wxWindow* topmost, const wxWindow* wanted )
{ {
// wanted may be NULL and that is ok. // wanted may be NULL and that is ok.
......
...@@ -100,7 +100,7 @@ bool KIWAY_PLAYER::ShowModal( wxString* aResult ) ...@@ -100,7 +100,7 @@ bool KIWAY_PLAYER::ShowModal( wxString* aResult )
Show( true ); Show( true );
wxGUIEventLoop event_loop; WX_EVENT_LOOP event_loop;
wxEventLoopActivator event_loop_stacker( &event_loop ); wxEventLoopActivator event_loop_stacker( &event_loop );
m_modal_loop = &event_loop; m_modal_loop = &event_loop;
......
...@@ -35,6 +35,14 @@ ...@@ -35,6 +35,14 @@
#define DLGSHIM_USE_SETFOCUS 0 #define DLGSHIM_USE_SETFOCUS 0
#endif #endif
#if wxCHECK_VERSION( 2, 9, 4 )
#define WX_EVENT_LOOP wxGUIEventLoop
#else
#define WX_EVENT_LOOP wxEventLoop
#endif
class WX_EVENT_LOOP;
/** /**
* Class DIALOG_SHIM * Class DIALOG_SHIM
...@@ -69,10 +77,16 @@ public: ...@@ -69,10 +77,16 @@ public:
bool Enable( bool enable ); // override wxDialog::Enable virtual bool Enable( bool enable ); // override wxDialog::Enable virtual
protected: protected:
#if !wxCHECK_VERSION( 2, 9, 4 )
wxWindow* CheckIfCanBeUsedAsParent( wxWindow* parent ) const;
wxWindow* GetParentForModalDialog( wxWindow *parent, long style ) const;
#endif
std::string m_hash_key; // alternate for class_map when classname re-used. std::string m_hash_key; // alternate for class_map when classname re-used.
// variables for quasi-modal behavior support, only used by a few derivatives. // variables for quasi-modal behavior support, only used by a few derivatives.
wxGUIEventLoop* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal and dismissed WX_EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal and dismissed
bool m_qmodal_showing; bool m_qmodal_showing;
......
...@@ -87,7 +87,15 @@ private: ...@@ -87,7 +87,15 @@ private:
class KIWAY_EXPRESS; class KIWAY_EXPRESS;
class wxGUIEventLoop;
#if wxCHECK_VERSION( 2, 9, 4 )
#define WX_EVENT_LOOP wxGUIEventLoop
#else
#define WX_EVENT_LOOP wxEventLoop
#endif
class WX_EVENT_LOOP;
/** /**
* Class KIWAY_PLAYER * Class KIWAY_PLAYER
...@@ -219,7 +227,7 @@ protected: ...@@ -219,7 +227,7 @@ protected:
// variables for modal behavior support, only used by a few derivatives. // variables for modal behavior support, only used by a few derivatives.
bool m_modal; // true if frame is intended to be modal, not modeless bool m_modal; // true if frame is intended to be modal, not modeless
wxGUIEventLoop* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed WX_EVENT_LOOP* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed
wxString m_modal_string; wxString m_modal_string;
bool m_modal_ret_val; // true if a selection was made bool m_modal_ret_val; // true if a selection was made
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment