#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
extern wxList *wxWinMacWindowList;
extern wxList *wxWinMacControlList;
+static bool s_inYield = FALSE;
+
wxApp *wxTheApp = NULL;
#if !USE_SHARED_LIBRARY
pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
+pascal OSErr AEHandlePreferences( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
}
+pascal OSErr AEHandlePreferences( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
+{
+ // GD: UNUSED wxApp* app = (wxApp*) refcon ;
+
+ wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
+ wxMenu* menu = NULL ;
+ wxMenuItem* item = NULL ;
+ if ( mbar )
+ {
+ item = mbar->FindItem( wxApp::s_macPreferencesMenuItemId , &menu ) ;
+ }
+ if ( item != NULL && menu != NULL && mbar != NULL )
+ menu->SendEvent( wxApp::s_macPreferencesMenuItemId , -1 ) ;
+ return noErr ;
+}
+
// 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()
theModule = NSModuleForSymbol(theSymbol);
theLibPath = NSLibraryNameForModule(theModule);
+ wxLogDebug( wxT("wxMac library installation name is '%s'"),
+ theLibPath );
+
// allocate copy to replace .dylib.* extension with .rsrc
theResPath = strdup(theLibPath);
if (theResPath != NULL) {
// overwrite extension with ".rsrc"
strcpy(theExt, ".rsrc");
- wxLogDebug( theResPath );
+ wxLogDebug( wxT("wxMac resources file name is '%s'"),
+ theResPath );
theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false);
if (theErr != noErr) {
theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false);
}
- // free duplicated resource file path
- free(theResPath);
-
// open the resource file
if (theErr == noErr) {
theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
&gSharedLibraryResource);
}
+ if (theErr != noErr) {
+ wxLogDebug( wxT("unable to open wxMac resource file '%s'"),
+ theResPath );
+ }
+
+ // free duplicated resource file path
+ free(theResPath);
}
}
#endif /* __DARWIN__ */
int wxApp::MainLoop()
{
- m_keepGoing = TRUE;
+ m_keepGoing = TRUE;
- while (m_keepGoing)
- {
- MacDoOneEvent() ;
- }
+#if TARGET_CARBON
+ if ( UMAGetSystemVersion() >= 0x1000 )
+ {
+ if ( s_macPreferencesMenuItemId )
+ {
+ EnableMenuCommand( NULL , kHICommandPreferences ) ;
+ AEInstallEventHandler( kCoreEventClass , kAEShowPreferences ,
+ NewAEEventHandlerUPP(AEHandlePreferences) ,
+ (long) wxTheApp , FALSE ) ;
+ }
+ }
+#endif
+ while (m_keepGoing)
+ {
+ MacDoOneEvent() ;
+ }
- return 0;
+ return 0;
}
// Returns TRUE if more time is needed.
bool wxApp::Yield(bool onlyIfNeeded)
{
- static bool s_inYield = FALSE;
-
if (s_inYield)
{
if ( !onlyIfNeeded )
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 ;