OSDN Git Service

Work around the wxWidgets bug where wxDocument::Close() is called twice. Fix the...
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Sat, 24 Apr 2010 15:31:32 +0000 (15:31 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Sat, 24 Apr 2010 15:31:32 +0000 (15:31 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@31 a2be9bc6-48de-4e38-9406-05402d4bc13c

wxSources/MoleculeView.cpp
wxSources/MyApp.cpp
wxSources/MyApp.h
wxSources/MyDocument.cpp

index 1075e73..2edfb82 100755 (executable)
@@ -371,8 +371,8 @@ MoleculeView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
 bool
 MoleculeView::OnClose(bool deleteWindow)
 {
-       if (!GetDocument()->Close())
-               return false;
+//     if (!GetDocument()->Close())
+//             return false;
 
        //  Dispose relationship between MainView and Molecule
        MainView_setMolecule(mview, NULL);
index e23c41f..932011f 100755 (executable)
@@ -59,6 +59,8 @@
 
 #if defined(__WXMAC__)
 #include <CoreFoundation/CoreFoundation.h>
+#undef T_DATA
+#include <Carbon/Carbon.h>
 #endif
 
 #pragma mark ====== MyApp ======
@@ -79,6 +81,9 @@ BEGIN_EVENT_TABLE(MyApp, wxApp)
 //     EVT_MENU(myMenuID_ReadParameters, MyApp::OnReadParameters)
        EVT_MENU(myMenuID_ViewGlobalParameters, MyApp::OnViewGlobalParameters)
        EVT_MENU(myMenuID_ViewParameterFilesList, MyApp::OnViewParameterFilesList)
+#if defined(__WXMAC__)
+       EVT_ACTIVATE(MyApp::OnActivate)
+#endif
        EVT_END_PROCESS(-1, MyApp::OnEndProcess)
 END_EVENT_TABLE()
 
@@ -211,6 +216,7 @@ bool MyApp::OnInit(void)
 
 #if defined(__WXMAC__)
        frame->Move(-10000, -10000);  //  Set invisible
+       frame->Show(false);
 #else
        frame->Show(true);
 #endif
@@ -742,6 +748,16 @@ MyApp::OnExecuteScript(wxCommandEvent &event)
        dialog->Destroy();
 }
 
+void
+MyApp::OnActivate(wxActivateEvent &event)
+{
+#if defined(__WXMAC__)
+       MyFrame *frame = GetMainFrame();
+       frame->Show(false);  /*  Sometimes this "parent" frame gets visible and screw up the menus  */
+#endif
+       event.Skip();
+}
+
 wxString
 MyApp::DefaultSettingsPath()
 {
@@ -946,6 +962,14 @@ MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
   wxDocMDIParentFrame(manager, frame, wxID_ANY, title, pos, size, type, _T("myFrame"))
 {
        editMenu = (wxMenu *) NULL;
+#if defined(__WXMAC__)
+       /*  Avoid this "dummy" top-level window to appear in the window menu.
+           It should not happen because MyApp::OnActivate() tries to hide this window,
+           but this is still here just in case.  */
+       OSStatus sts;
+       sts = ChangeWindowAttributes((WindowRef)m_macWindow, 0, kWindowInWindowMenuAttribute);
+/*     printf("m_macWindow = %p, status = %d\n", m_macWindow, (int)sts); */
+#endif
 }
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
index 7344f35..4a7f5c4 100755 (executable)
@@ -148,6 +148,8 @@ class MyApp: public wxApp
        void OnEndProcess(wxProcessEvent &event);
        int CallSubProcess(const char *cmdline, const char *procname);
 
+       void OnActivate(wxActivateEvent &event);
+
        MyListCtrl *GetGlobalParameterListCtrl();
 #if __WXMAC__
        virtual void MacNewFile();
index 0b7adf9..04f617c 100755 (executable)
@@ -408,7 +408,7 @@ MyDocument::Close()
                MyAppCallback_errorMessageBox("%s is running: please stop it before closing", msg);
                return false;
        }
-       return true;
+       return wxDocument::Close();
 }
 
 void