]> git.saurik.com Git - wxWidgets.git/commitdiff
routing all apple events to the document manager instance if present, fully supportin...
authorStefan Csomor <csomor@advancedconcepts.ch>
Fri, 10 Jan 2003 17:56:24 +0000 (17:56 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Fri, 10 Jan 2003 17:56:24 +0000 (17:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18669 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/app.cpp
src/mac/carbon/app.cpp

index 51980c75643f82f21767340dffb3d5923a1f1a0e..29dc8af328dea24239cefb5c0cb3b664b6bc0315 100644 (file)
@@ -36,6 +36,8 @@
 #include "wx/tooltip.h"
 #include "wx/textctrl.h"
 #include "wx/menu.h"
+#include "wx/docview.h"
+
 #if wxUSE_WX_RESOURCES
 #  include "wx/resource.h"
 #endif
@@ -73,6 +75,8 @@ extern wxList wxPendingDelete;
 extern wxList *wxWinMacWindowList;
 extern wxList *wxWinMacControlList;
 
+static bool s_inYield = FALSE;
+
 wxApp *wxTheApp = NULL;
 
 #if !USE_SHARED_LIBRARY
@@ -136,12 +140,39 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WX
 }
 
 // new virtual public method in wxApp
-void wxApp::MacOpenFile(const wxString & WXUNUSED(fileName) )
+void wxApp::MacOpenFile(const wxString & fileName )
 {
+    wxDocManager* dm = wxDocManager::GetDocumentManager() ;
+    if ( dm )
+        dm->CreateDocument(fileName , wxDOC_SILENT ) ;
 }
 
-void wxApp::MacPrintFile(const wxString & WXUNUSED(fileName) )
+void wxApp::MacPrintFile(const wxString & fileName )
 {
+    wxDocManager* dm = wxDocManager::GetDocumentManager() ;
+    if ( dm )
+    {
+        wxDocument *doc = dm->CreateDocument(fileName , wxDOC_SILENT ) ;
+        if ( doc )
+        {
+            wxView* view = doc->GetFirstView() ;
+            if( view )
+            {
+                wxPrintout *printout = view->OnCreatePrintout();
+                if (printout)
+                {
+                    wxPrinter printer;
+                    printer.Print(view->GetFrame(), printout, TRUE);
+                    delete printout;
+                }
+            }
+            if (doc->Close())
+            {
+                doc->DeleteAllViews();
+                dm->RemoveDocument(doc) ;
+            }
+        }
+    }
 }
 
 void wxApp::MacNewFile()
@@ -1322,8 +1353,6 @@ void wxCYield()
 
 bool wxApp::Yield(bool onlyIfNeeded)
 {
-    static bool s_inYield = FALSE;
-
     if (s_inYield)
     {
         if ( !onlyIfNeeded )
@@ -1560,8 +1589,12 @@ void wxApp::MacHandleOneEvent( WXEVENTREF evr )
 
 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
 {
+    // we must avoid reentrancy problems when processing high level events eg printing
+    bool former = s_inYield ;
+    s_inYield = TRUE ;
     EventRecord* ev = (EventRecord*) evr ;
     ::AEProcessAppleEvent( ev ) ;
+    s_inYield = former ;
 }
 
 bool s_macIsInModalLoop = false ;
index 51980c75643f82f21767340dffb3d5923a1f1a0e..29dc8af328dea24239cefb5c0cb3b664b6bc0315 100644 (file)
@@ -36,6 +36,8 @@
 #include "wx/tooltip.h"
 #include "wx/textctrl.h"
 #include "wx/menu.h"
+#include "wx/docview.h"
+
 #if wxUSE_WX_RESOURCES
 #  include "wx/resource.h"
 #endif
@@ -73,6 +75,8 @@ extern wxList wxPendingDelete;
 extern wxList *wxWinMacWindowList;
 extern wxList *wxWinMacControlList;
 
+static bool s_inYield = FALSE;
+
 wxApp *wxTheApp = NULL;
 
 #if !USE_SHARED_LIBRARY
@@ -136,12 +140,39 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WX
 }
 
 // new virtual public method in wxApp
-void wxApp::MacOpenFile(const wxString & WXUNUSED(fileName) )
+void wxApp::MacOpenFile(const wxString & fileName )
 {
+    wxDocManager* dm = wxDocManager::GetDocumentManager() ;
+    if ( dm )
+        dm->CreateDocument(fileName , wxDOC_SILENT ) ;
 }
 
-void wxApp::MacPrintFile(const wxString & WXUNUSED(fileName) )
+void wxApp::MacPrintFile(const wxString & fileName )
 {
+    wxDocManager* dm = wxDocManager::GetDocumentManager() ;
+    if ( dm )
+    {
+        wxDocument *doc = dm->CreateDocument(fileName , wxDOC_SILENT ) ;
+        if ( doc )
+        {
+            wxView* view = doc->GetFirstView() ;
+            if( view )
+            {
+                wxPrintout *printout = view->OnCreatePrintout();
+                if (printout)
+                {
+                    wxPrinter printer;
+                    printer.Print(view->GetFrame(), printout, TRUE);
+                    delete printout;
+                }
+            }
+            if (doc->Close())
+            {
+                doc->DeleteAllViews();
+                dm->RemoveDocument(doc) ;
+            }
+        }
+    }
 }
 
 void wxApp::MacNewFile()
@@ -1322,8 +1353,6 @@ void wxCYield()
 
 bool wxApp::Yield(bool onlyIfNeeded)
 {
-    static bool s_inYield = FALSE;
-
     if (s_inYield)
     {
         if ( !onlyIfNeeded )
@@ -1560,8 +1589,12 @@ void wxApp::MacHandleOneEvent( WXEVENTREF evr )
 
 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
 {
+    // we must avoid reentrancy problems when processing high level events eg printing
+    bool former = s_inYield ;
+    s_inYield = TRUE ;
     EventRecord* ev = (EventRecord*) evr ;
     ::AEProcessAppleEvent( ev ) ;
+    s_inYield = former ;
 }
 
 bool s_macIsInModalLoop = false ;