lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 7f264d6 3/4: Make TopWindow() return a wxTopL


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 7f264d6 3/4: Make TopWindow() return a wxTopLevelWindow
Date: Fri, 9 Mar 2018 20:39:55 -0500 (EST)

branch: master
commit 7f264d682f228ce50a6acb90943607e281603484
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Make TopWindow() return a wxTopLevelWindow
    
    See:
      https://lists.nongnu.org/archive/html/lmi/2018-03/msg00041.html
---
 single_choice_popup_menu.cpp |  4 ++--
 single_choice_popup_menu.hpp |  6 +++---
 wx_utility.cpp               | 17 ++++++++++++++---
 wx_utility.hpp               |  3 ++-
 4 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/single_choice_popup_menu.cpp b/single_choice_popup_menu.cpp
index ff53fb5..380074d 100644
--- a/single_choice_popup_menu.cpp
+++ b/single_choice_popup_menu.cpp
@@ -24,12 +24,12 @@
 #include "single_choice_popup_menu.hpp"
 
 #include <wx/evtloop.h>
-#include <wx/window.h>
+#include <wx/toplevel.h>
 
 SingleChoicePopupMenu::SingleChoicePopupMenu
     (wxArrayString const& choices
     ,wxString const&      title
-    ,wxWindow&            parent
+    ,wxTopLevelWindow&    parent
     )
     :parent_(parent)
 {
diff --git a/single_choice_popup_menu.hpp b/single_choice_popup_menu.hpp
index ea9aeff..ce0c91a 100644
--- a/single_choice_popup_menu.hpp
+++ b/single_choice_popup_menu.hpp
@@ -24,7 +24,7 @@
 
 #include "config.hpp"
 
-#include "wx_utility.hpp"
+#include "wx_utility.hpp"               // TopWindow()
 
 #include <wx/arrstr.h>                  // wxArrayString
 #include <wx/menu.h>
@@ -41,14 +41,14 @@ class SingleChoicePopupMenu
     SingleChoicePopupMenu
         (wxArrayString const& choices
         ,wxString const&      title  = wxEmptyString
-        ,wxWindow&            parent = TopWindow()
+        ,wxTopLevelWindow&    parent = TopWindow()
         );
 
     int Choose();
 
   private:
     wxMenu menu_;
-    wxWindow& parent_;
+    wxTopLevelWindow& parent_;
 };
 
 #endif // single_choice_popup_menu_hpp
diff --git a/wx_utility.cpp b/wx_utility.cpp
index 626ec5a..087478c 100644
--- a/wx_utility.cpp
+++ b/wx_utility.cpp
@@ -37,6 +37,7 @@
 #include <wx/clipbrd.h>
 #include <wx/datetime.h>
 #include <wx/msgdlg.h>
+#include <wx/toplevel.h>
 #include <wx/utils.h>                   // wxSafeYield()
 #include <wx/window.h>
 
@@ -280,16 +281,26 @@ wxApp& TheApp()
 }
 
 /// Safe cover function for wxApp::GetTopWindow(): throws if null.
+///
+/// If GetTopWindow() returns nullptr, then wx is probably starting up
+/// or shutting down; therefore, diagnostics are displayed through a
+/// mechanism that should work even in such circumstances.
 
-wxWindow& TopWindow()
+wxTopLevelWindow& TopWindow()
 {
     wxWindow* w = TheApp().GetTopWindow();
     if(!w)
         {
-        safely_show_message("Top window not found.");
+        safely_show_message("No top window found.");
+        throw 0;
+        }
+    wxTopLevelWindow* t = dynamic_cast<wxTopLevelWindow*>(w);
+    if(!t)
+        {
+        safely_show_message("Top window is not a wxTopLevelWindow.");
         throw 0;
         }
-    return *w;
+    return *t;
 }
 
 /// Convert a filename to an NTBS std::string, throwing upon failure.
diff --git a/wx_utility.hpp b/wx_utility.hpp
index 9f36529..52f50b8 100644
--- a/wx_utility.hpp
+++ b/wx_utility.hpp
@@ -38,6 +38,7 @@ class LMI_SO_FWD_DECL calendar_date;
 class WXDLLIMPEXP_FWD_CORE wxApp;
 class WXDLLIMPEXP_FWD_CORE wxBookCtrlBase;
 class WXDLLIMPEXP_FWD_CORE wxDateTime;
+class WXDLLIMPEXP_FWD_CORE wxTopLevelWindow;
 class WXDLLIMPEXP_FWD_CORE wxWindow;
 class jdn_t;
 
@@ -135,7 +136,7 @@ std::vector<wxWindow*> Lineage(wxWindow const*);
 std::string NameLabelId(wxWindow const*);
 
 wxApp& TheApp();
-wxWindow& TopWindow();
+wxTopLevelWindow& TopWindow();
 
 std::string ValidateAndConvertFilename(wxString const&);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]