Added AddGrab, RemoveGrab, IsGrabbed to wxTopLevelWindowGTK

and AddGrabIfNeeded to wxHtmlHelpController, to assist with
showing the help window from a modal dialog.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15880 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2002-06-18 21:46:42 +00:00
parent 68b893338a
commit 5152b0e59a
7 changed files with 158 additions and 22 deletions

View File

@@ -65,6 +65,12 @@ public:
virtual void SetTitle( const wxString &title ); virtual void SetTitle( const wxString &title );
virtual wxString GetTitle() const { return m_title; } virtual wxString GetTitle() const { return m_title; }
// Experimental, to allow help windows to be
// viewable from within modal dialogs
virtual void AddGrab();
virtual void RemoveGrab();
virtual bool IsGrabbed() const { return m_grabbed; }
// implementation from now on // implementation from now on
// -------------------------- // --------------------------
@@ -111,6 +117,9 @@ protected:
// is the frame currently iconized? // is the frame currently iconized?
bool m_isIconized; bool m_isIconized;
// is the frame currently grabbed explicitly
// by the application?
bool m_grabbed;
}; };
#endif // __GTKTOPLEVELH__ #endif // __GTKTOPLEVELH__

View File

@@ -65,6 +65,12 @@ public:
virtual void SetTitle( const wxString &title ); virtual void SetTitle( const wxString &title );
virtual wxString GetTitle() const { return m_title; } virtual wxString GetTitle() const { return m_title; }
// Experimental, to allow help windows to be
// viewable from within modal dialogs
virtual void AddGrab();
virtual void RemoveGrab();
virtual bool IsGrabbed() const { return m_grabbed; }
// implementation from now on // implementation from now on
// -------------------------- // --------------------------
@@ -111,6 +117,9 @@ protected:
// is the frame currently iconized? // is the frame currently iconized?
bool m_isIconized; bool m_isIconized;
// is the frame currently grabbed explicitly
// by the application?
bool m_grabbed;
}; };
#endif // __GTKTOPLEVELH__ #endif // __GTKTOPLEVELH__

View File

@@ -36,26 +36,13 @@ public:
void SetTitleFormat(const wxString& format); void SetTitleFormat(const wxString& format);
void SetTempDir(const wxString& path) { m_helpData.SetTempDir(path); } void SetTempDir(const wxString& path) { m_helpData.SetTempDir(path); }
bool AddBook(const wxString& book, bool show_wait_msg = FALSE); bool AddBook(const wxString& book, bool show_wait_msg = FALSE);
bool Display(const wxString& x)
{ bool Display(const wxString& x);
CreateHelpWindow(); return m_helpFrame->Display(x); bool Display(int id);
} bool DisplayContents();
bool Display(int id) bool DisplayIndex();
{ bool KeywordSearch(const wxString& keyword);
CreateHelpWindow(); return m_helpFrame->Display(id);
}
bool DisplayContents()
{
CreateHelpWindow(); return m_helpFrame->DisplayContents();
}
bool DisplayIndex()
{
CreateHelpWindow(); return m_helpFrame->DisplayIndex();
}
bool KeywordSearch(const wxString& keyword)
{
CreateHelpWindow(); return m_helpFrame->KeywordSearch(keyword);
}
wxHtmlHelpFrame* GetFrame() { return m_helpFrame; } wxHtmlHelpFrame* GetFrame() { return m_helpFrame; }
void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString); void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString);
@@ -94,6 +81,10 @@ public:
void OnCloseFrame(wxCloseEvent& evt); void OnCloseFrame(wxCloseEvent& evt);
// Make the help controller's frame 'modal' if
// needed
void AddGrabIfNeeded();
protected: protected:
virtual wxHtmlHelpFrame* CreateHelpFrame(wxHtmlHelpData *data); virtual wxHtmlHelpFrame* CreateHelpFrame(wxHtmlHelpData *data);

View File

@@ -111,7 +111,8 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX
wxapp_install_idle_handler(); wxapp_install_idle_handler();
if (win->IsEnabled() && if (win->IsEnabled() &&
(g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG))) (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ||
win->IsGrabbed()))
win->Close(); win->Close();
return TRUE; return TRUE;
@@ -302,6 +303,7 @@ void wxTopLevelWindowGTK::Init()
m_fsIsShowing = FALSE; m_fsIsShowing = FALSE;
m_themeEnabled = TRUE; m_themeEnabled = TRUE;
m_gdkDecor = m_gdkFunc = 0; m_gdkDecor = m_gdkFunc = 0;
m_grabbed = FALSE;
} }
bool wxTopLevelWindowGTK::Create( wxWindow *parent, bool wxTopLevelWindowGTK::Create( wxWindow *parent,
@@ -472,6 +474,12 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
wxTopLevelWindowGTK::~wxTopLevelWindowGTK() wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
{ {
if (m_grabbed)
{
wxASSERT_MSG( FALSE, "Window still grabbed");
RemoveGrab();
}
m_isBeingDeleted = TRUE; m_isBeingDeleted = TRUE;
// it may also be GtkScrolledWindow in the case of an MDI child // it may also be GtkScrolledWindow in the case of an MDI child
@@ -869,3 +877,22 @@ void wxTopLevelWindowGTK::SetIconizeState(bool iconize)
} }
} }
void wxTopLevelWindowGTK::AddGrab()
{
if (!m_grabbed)
{
m_grabbed = TRUE;
gtk_grab_add( m_widget );
gtk_main();
gtk_grab_remove( m_widget );
}
}
void wxTopLevelWindowGTK::RemoveGrab()
{
if (m_grabbed)
{
gtk_main_quit();
m_grabbed = FALSE;
}
}

View File

@@ -111,7 +111,8 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX
wxapp_install_idle_handler(); wxapp_install_idle_handler();
if (win->IsEnabled() && if (win->IsEnabled() &&
(g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG))) (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ||
win->IsGrabbed()))
win->Close(); win->Close();
return TRUE; return TRUE;
@@ -302,6 +303,7 @@ void wxTopLevelWindowGTK::Init()
m_fsIsShowing = FALSE; m_fsIsShowing = FALSE;
m_themeEnabled = TRUE; m_themeEnabled = TRUE;
m_gdkDecor = m_gdkFunc = 0; m_gdkDecor = m_gdkFunc = 0;
m_grabbed = FALSE;
} }
bool wxTopLevelWindowGTK::Create( wxWindow *parent, bool wxTopLevelWindowGTK::Create( wxWindow *parent,
@@ -472,6 +474,12 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
wxTopLevelWindowGTK::~wxTopLevelWindowGTK() wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
{ {
if (m_grabbed)
{
wxASSERT_MSG( FALSE, "Window still grabbed");
RemoveGrab();
}
m_isBeingDeleted = TRUE; m_isBeingDeleted = TRUE;
// it may also be GtkScrolledWindow in the case of an MDI child // it may also be GtkScrolledWindow in the case of an MDI child
@@ -869,3 +877,22 @@ void wxTopLevelWindowGTK::SetIconizeState(bool iconize)
} }
} }
void wxTopLevelWindowGTK::AddGrab()
{
if (!m_grabbed)
{
m_grabbed = TRUE;
gtk_grab_add( m_widget );
gtk_main();
gtk_grab_remove( m_widget );
}
}
void wxTopLevelWindowGTK::RemoveGrab()
{
if (m_grabbed)
{
gtk_main_quit();
m_grabbed = FALSE;
}
}

View File

@@ -251,5 +251,71 @@ bool wxHtmlHelpController::Quit()
return TRUE; return TRUE;
} }
// Make the help controller's frame 'modal' if
// needed
void wxHtmlHelpController::AddGrabIfNeeded()
{
// So far, wxGTK only
#ifdef __WXGTK__
bool needGrab = FALSE;
// Check if there are any modal windows present,
// in which case we need to add a grab.
for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
node;
node = node->GetNext() )
{
wxWindow *win = node->GetData();
wxDialog *dialog = wxDynamicCast(win, wxDialog);
if (dialog && dialog->IsModal())
needGrab = TRUE;
}
if (needGrab && m_helpFrame)
m_helpFrame->AddGrab();
#endif
}
bool wxHtmlHelpController::Display(const wxString& x)
{
CreateHelpWindow();
bool success = m_helpFrame->Display(x);
AddGrabIfNeeded();
return success;
}
bool wxHtmlHelpController::Display(int id)
{
CreateHelpWindow();
bool success = m_helpFrame->Display(id);
AddGrabIfNeeded();
return success;
}
bool wxHtmlHelpController::DisplayContents()
{
CreateHelpWindow();
bool success = m_helpFrame->DisplayContents();
AddGrabIfNeeded();
return success;
}
bool wxHtmlHelpController::DisplayIndex()
{
CreateHelpWindow();
bool success = m_helpFrame->DisplayIndex();
AddGrabIfNeeded();
return success;
}
bool wxHtmlHelpController::KeywordSearch(const wxString& keyword)
{
CreateHelpWindow();
bool success = m_helpFrame->KeywordSearch(keyword);
AddGrabIfNeeded();
return success;
}
#endif // wxUSE_WXHTML_HELP #endif // wxUSE_WXHTML_HELP

View File

@@ -1442,6 +1442,13 @@ void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
GetSize(&m_Cfg.w, &m_Cfg.h); GetSize(&m_Cfg.w, &m_Cfg.h);
GetPosition(&m_Cfg.x, &m_Cfg.y); GetPosition(&m_Cfg.x, &m_Cfg.y);
#ifdef __WXGTK__
if (IsGrabbed())
{
RemoveGrab();
}
#endif
if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter->GetSashPosition(); if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter->GetSashPosition();
if (m_Config) if (m_Config)