From 738a6daa7100da30cfadb1f8303ac020faa811c0 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 10 Jan 2003 17:56:24 +0000 Subject: [PATCH] routing all apple events to the document manager instance if present, fully supporting launch by document double click, print by draging the document onto the printer icon git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18669 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/app.cpp | 41 +++++++++++++++++++++++++++++++++++++---- src/mac/carbon/app.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 51980c7564..29dc8af328 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -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 ; diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 51980c7564..29dc8af328 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -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 ; -- 2.47.2