]> git.saurik.com Git - wxWidgets.git/commitdiff
Added AddGrab, RemoveGrab, IsGrabbed to wxTopLevelWindowGTK
authorJulian Smart <julian@anthemion.co.uk>
Tue, 18 Jun 2002 21:46:42 +0000 (21:46 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 18 Jun 2002 21:46:42 +0000 (21:46 +0000)
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
include/wx/gtk1/toplevel.h
include/wx/html/helpctrl.h
src/gtk/toplevel.cpp
src/gtk1/toplevel.cpp
src/html/helpctrl.cpp
src/html/helpfrm.cpp

index 2cc960a242a5b94fb6f83ed248ae3e80a0013ea2..29fdcd5f5cab51f0448c3cc1d004a92b2488a9cc 100644 (file)
@@ -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__
index 2cc960a242a5b94fb6f83ed248ae3e80a0013ea2..29fdcd5f5cab51f0448c3cc1d004a92b2488a9cc 100644 (file)
@@ -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__
index 2106893a9d8e70a4f638d83436b9edf05df3da64..cd1efd1aee248ea98ea33139ae1c8f37792471e8 100644 (file)
@@ -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);
 
index 591e545e7c929f900685459c02f39adccce304e7..0edae9fb0ee0ac288c6472c3d09c9e5e42a9db18 100644 (file)
@@ -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;
+    }
+}
index 591e545e7c929f900685459c02f39adccce304e7..0edae9fb0ee0ac288c6472c3d09c9e5e42a9db18 100644 (file)
@@ -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;
+    }
+}
index 9933bbbf554db874c5ec154dd47103b9411ab695..21a80600ec9193bc07bec0e3429a7dd7985aad32 100644 (file)
@@ -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
 
index 07096d4c71357173b7b4478f2b4e93850de98469..765dc8c452784545a0f79fac81a8c5942255785b 100644 (file)
@@ -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)