From 5152b0e59aa09d885deeaa018642e0e96aff92d9 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 18 Jun 2002 21:46:42 +0000 Subject: [PATCH] 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 --- include/wx/gtk/toplevel.h | 9 ++++++ include/wx/gtk1/toplevel.h | 9 ++++++ include/wx/html/helpctrl.h | 31 +++++++----------- src/gtk/toplevel.cpp | 29 ++++++++++++++++- src/gtk1/toplevel.cpp | 29 ++++++++++++++++- src/html/helpctrl.cpp | 66 ++++++++++++++++++++++++++++++++++++++ src/html/helpfrm.cpp | 7 ++++ 7 files changed, 158 insertions(+), 22 deletions(-) diff --git a/include/wx/gtk/toplevel.h b/include/wx/gtk/toplevel.h index 2cc960a242..29fdcd5f5c 100644 --- a/include/wx/gtk/toplevel.h +++ b/include/wx/gtk/toplevel.h @@ -65,6 +65,12 @@ public: virtual void SetTitle( const wxString &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 // -------------------------- @@ -111,6 +117,9 @@ protected: // is the frame currently iconized? bool m_isIconized; + // is the frame currently grabbed explicitly + // by the application? + bool m_grabbed; }; #endif // __GTKTOPLEVELH__ diff --git a/include/wx/gtk1/toplevel.h b/include/wx/gtk1/toplevel.h index 2cc960a242..29fdcd5f5c 100644 --- a/include/wx/gtk1/toplevel.h +++ b/include/wx/gtk1/toplevel.h @@ -65,6 +65,12 @@ public: virtual void SetTitle( const wxString &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 // -------------------------- @@ -111,6 +117,9 @@ protected: // is the frame currently iconized? bool m_isIconized; + // is the frame currently grabbed explicitly + // by the application? + bool m_grabbed; }; #endif // __GTKTOPLEVELH__ diff --git a/include/wx/html/helpctrl.h b/include/wx/html/helpctrl.h index 2106893a9d..cd1efd1aee 100644 --- a/include/wx/html/helpctrl.h +++ b/include/wx/html/helpctrl.h @@ -36,26 +36,13 @@ public: void SetTitleFormat(const wxString& format); void SetTempDir(const wxString& path) { m_helpData.SetTempDir(path); } bool AddBook(const wxString& book, bool show_wait_msg = FALSE); - bool Display(const wxString& x) - { - CreateHelpWindow(); return m_helpFrame->Display(x); - } - bool Display(int id) - { - 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); - } + + bool Display(const wxString& x); + bool Display(int id); + bool DisplayContents(); + bool DisplayIndex(); + bool KeywordSearch(const wxString& keyword); + wxHtmlHelpFrame* GetFrame() { return m_helpFrame; } void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString); @@ -94,6 +81,10 @@ public: void OnCloseFrame(wxCloseEvent& evt); + // Make the help controller's frame 'modal' if + // needed + void AddGrabIfNeeded(); + protected: virtual wxHtmlHelpFrame* CreateHelpFrame(wxHtmlHelpData *data); diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index 591e545e7c..0edae9fb0e 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -111,7 +111,8 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX wxapp_install_idle_handler(); if (win->IsEnabled() && - (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG))) + (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) || + win->IsGrabbed())) win->Close(); return TRUE; @@ -302,6 +303,7 @@ void wxTopLevelWindowGTK::Init() m_fsIsShowing = FALSE; m_themeEnabled = TRUE; m_gdkDecor = m_gdkFunc = 0; + m_grabbed = FALSE; } bool wxTopLevelWindowGTK::Create( wxWindow *parent, @@ -472,6 +474,12 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, wxTopLevelWindowGTK::~wxTopLevelWindowGTK() { + if (m_grabbed) + { + wxASSERT_MSG( FALSE, "Window still grabbed"); + RemoveGrab(); + } + m_isBeingDeleted = TRUE; // 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; + } +} diff --git a/src/gtk1/toplevel.cpp b/src/gtk1/toplevel.cpp index 591e545e7c..0edae9fb0e 100644 --- a/src/gtk1/toplevel.cpp +++ b/src/gtk1/toplevel.cpp @@ -111,7 +111,8 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX wxapp_install_idle_handler(); if (win->IsEnabled() && - (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG))) + (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) || + win->IsGrabbed())) win->Close(); return TRUE; @@ -302,6 +303,7 @@ void wxTopLevelWindowGTK::Init() m_fsIsShowing = FALSE; m_themeEnabled = TRUE; m_gdkDecor = m_gdkFunc = 0; + m_grabbed = FALSE; } bool wxTopLevelWindowGTK::Create( wxWindow *parent, @@ -472,6 +474,12 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, wxTopLevelWindowGTK::~wxTopLevelWindowGTK() { + if (m_grabbed) + { + wxASSERT_MSG( FALSE, "Window still grabbed"); + RemoveGrab(); + } + m_isBeingDeleted = TRUE; // 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; + } +} diff --git a/src/html/helpctrl.cpp b/src/html/helpctrl.cpp index 9933bbbf55..21a80600ec 100644 --- a/src/html/helpctrl.cpp +++ b/src/html/helpctrl.cpp @@ -251,5 +251,71 @@ bool wxHtmlHelpController::Quit() 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 diff --git a/src/html/helpfrm.cpp b/src/html/helpfrm.cpp index 07096d4c71..765dc8c452 100644 --- a/src/html/helpfrm.cpp +++ b/src/html/helpfrm.cpp @@ -1442,6 +1442,13 @@ void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) GetSize(&m_Cfg.w, &m_Cfg.h); 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_Config) -- 2.45.2