⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        src/mac/carbon/app.cpp// Purpose:     wxApp// Author:      Stefan Csomor// Modified by:// Created:     1998-01-01// RCS-ID:      $Id: app.cpp,v 1.228 2006/12/10 13:08:42 SC Exp $// Copyright:   (c) Stefan Csomor// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////#include "wx/wxprec.h"#include "wx/app.h"#ifndef WX_PRECOMP    #include "wx/intl.h"    #include "wx/log.h"    #include "wx/utils.h"    #include "wx/window.h"    #include "wx/frame.h"    #include "wx/dc.h"    #include "wx/button.h"    #include "wx/menu.h"    #include "wx/pen.h"    #include "wx/brush.h"    #include "wx/palette.h"    #include "wx/icon.h"    #include "wx/cursor.h"    #include "wx/dialog.h"    #include "wx/msgdlg.h"    #include "wx/textctrl.h"    #include "wx/memory.h"    #include "wx/gdicmn.h"    #include "wx/module.h"#endif#include "wx/tooltip.h"#include "wx/docview.h"#include "wx/filename.h"#include "wx/link.h"#include <string.h>// mac#ifndef __DARWIN__    #if __option(profile)        #include <profiler.h>    #endif#endif// #include "apprsrc.h"#include "wx/mac/uma.h"#include "wx/mac/macnotfy.h"#ifdef __DARWIN__#  include <CoreServices/CoreServices.h>#  if defined(WXMAKINGDLL_CORE)#    include <mach-o/dyld.h>#  endif#else#  include <Sound.h>#  include <Threads.h>#  include <ToolUtils.h>#  include <DiskInit.h>#  include <Devices.h>#endif// Keep linker from discarding wxStockGDIMacwxFORCE_LINK_MODULE(gdiobj)// statics for implementationstatic bool s_inYield = false;static bool s_inReceiveEvent = false ;static EventTime sleepTime = kEventDurationNoWait ;IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)    EVT_IDLE(wxApp::OnIdle)    EVT_END_SESSION(wxApp::OnEndSession)    EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)END_EVENT_TABLE()// platform specific static variablesstatic const short kwxMacAppleMenuId = 1 ;wxWindow* wxApp::s_captureWindow = NULL ;long      wxApp::s_lastModifiers = 0 ;long      wxApp::s_macAboutMenuItemId = wxID_ABOUT ;long      wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ;long      wxApp::s_macExitMenuItemId = wxID_EXIT ;wxString  wxApp::s_macHelpMenuTitleName = wxT("&Help") ;bool      wxApp::sm_isEmbedded = false; // Normally we're not a plugin//----------------------------------------------------------------------// Core Apple Event Support//----------------------------------------------------------------------pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , SRefCon refcon ) ;pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , SRefCon refcon ) ;pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , SRefCon refcon ) ;pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , SRefCon refcon ) ;pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , SRefCon refcon ) ;pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , SRefCon WXUNUSED(refcon) ){    return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;}pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , SRefCon WXUNUSED(refcon) ){    return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;}pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , SRefCon WXUNUSED(refcon) ){    return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;}pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , SRefCon WXUNUSED(refcon) ){    return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;}pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , SRefCon WXUNUSED(refcon) ){    return wxTheApp->MacHandleAERApp( (AppleEvent*) event , reply) ;}// AEODoc Calls MacOpenFile on each of the files passedshort wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply)){    AEDescList docList;    AEKeyword keywd;    DescType returnedType;    Size actualSize;    long itemsInList;    OSErr err;    short i;    err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);    if (err != noErr)        return err;    err = AECountItems(&docList, &itemsInList);    if (err != noErr)        return err;    ProcessSerialNumber PSN ;    PSN.highLongOfPSN = 0 ;    PSN.lowLongOfPSN = kCurrentProcess ;    SetFrontProcess( &PSN ) ;    wxString fName ;    FSRef theRef ;    for (i = 1; i <= itemsInList; i++)    {        AEGetNthPtr(            &docList, i, typeFSRef, &keywd, &returnedType,            (Ptr)&theRef, sizeof(theRef), &actualSize);        fName = wxMacFSRefToPath( &theRef ) ;        MacOpenFile(fName);    }    return noErr;}// AEPDoc Calls MacPrintFile on each of the files passedshort wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply)){    AEDescList docList;    AEKeyword keywd;    DescType returnedType;    Size actualSize;    long itemsInList;    OSErr err;    short i;    err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);    if (err != noErr)        return err;    err = AECountItems(&docList, &itemsInList);    if (err != noErr)        return err;    ProcessSerialNumber PSN ;    PSN.highLongOfPSN = 0 ;    PSN.lowLongOfPSN = kCurrentProcess ;    SetFrontProcess( &PSN ) ;    wxString fName ;    FSRef theRef ;    for (i = 1; i <= itemsInList; i++)    {        AEGetNthPtr(            &docList, i, typeFSRef, &keywd, &returnedType,            (Ptr)&theRef, sizeof(theRef), &actualSize);        fName = wxMacFSRefToPath( &theRef ) ;        MacPrintFile(fName);    }    return noErr;}// AEOApp calls MacNewFileshort wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)){    MacNewFile() ;    return noErr ;}// AEQuit attempts to quit the applicationshort wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)){    wxWindow* win = GetTopWindow() ;    if ( win )    {        wxCommandEvent exitEvent(wxEVT_COMMAND_MENU_SELECTED, s_macExitMenuItemId);        if (!win->ProcessEvent(exitEvent))            win->Close(true) ;    }    else    {        ExitMainLoop() ;    }    return noErr ;}// AEROApp calls MacReopenAppshort wxApp::MacHandleAERApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)){    MacReopenApp() ;    return noErr ;}//----------------------------------------------------------------------// Support Routines linking the Mac...File Calls to the Document Manager//----------------------------------------------------------------------void wxApp::MacOpenFile(const wxString & fileName ){#if wxUSE_DOC_VIEW_ARCHITECTURE    wxDocManager* dm = wxDocManager::GetDocumentManager() ;    if ( dm )        dm->CreateDocument(fileName , wxDOC_SILENT ) ;#endif}void wxApp::MacPrintFile(const wxString & fileName ){#if wxUSE_DOC_VIEW_ARCHITECTURE#if wxUSE_PRINTING_ARCHITECTURE    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) ;            }        }    }#endif //print#endif //docview}void wxApp::MacNewFile(){}void wxApp::MacReopenApp(){    // HIG says :    // if there is no open window -> create a new one    // if all windows are hidden -> show the first    // if some windows are not hidden -> do nothing    wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();    if ( node == NULL )    {        MacNewFile() ;    }    else    {        wxTopLevelWindow* firstIconized = NULL ;        while (node)        {            wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData();            if ( !win->IsIconized() )            {                firstIconized = NULL ;                break ;            }            else            {                if ( firstIconized == NULL )                    firstIconized = win ;            }            node = node->GetNext();        }        if ( firstIconized )            firstIconized->Iconize( false ) ;    }}//----------------------------------------------------------------------// Macintosh CommandID support - converting between native and wx IDs//----------------------------------------------------------------------// if no native match they just return the passed-in idstruct IdPair{    UInt32 macId ;    int wxId ;} ;IdPair gCommandIds [] ={    { kHICommandCut ,           wxID_CUT } ,    { kHICommandCopy ,          wxID_COPY } ,    { kHICommandPaste ,         wxID_PASTE } ,    { kHICommandSelectAll ,     wxID_SELECTALL } ,    { kHICommandClear ,         wxID_CLEAR } ,    { kHICommandUndo ,          wxID_UNDO } ,    { kHICommandRedo ,          wxID_REDO } ,} ;int wxMacCommandToId( UInt32 macCommandId ){    int wxid = 0 ;    switch ( macCommandId )    {        case kHICommandPreferences :            wxid = wxApp::s_macPreferencesMenuItemId ;            break ;        case kHICommandQuit :            wxid = wxApp::s_macExitMenuItemId ;            break ;        case kHICommandAbout :            wxid = wxApp::s_macAboutMenuItemId ;            break ;        default :            {                for ( size_t i = 0 ; i < WXSIZEOF(gCommandIds) ; ++i )                {                    if ( gCommandIds[i].macId == macCommandId )                    {                        wxid = gCommandIds[i].wxId ;                        break ;                    }                }            }            break ;    }    if ( wxid == 0 )        wxid = (int) macCommandId ;    return wxid ;}UInt32 wxIdToMacCommand( int wxId ){    UInt32 macId = 0 ;    if ( wxId == wxApp::s_macPreferencesMenuItemId )        macId = kHICommandPreferences ;    else if (wxId == wxApp::s_macExitMenuItemId)        macId = kHICommandQuit ;    else if (wxId == wxApp::s_macAboutMenuItemId)        macId = kHICommandAbout ;    else    {        for ( size_t i = 0 ; i < WXSIZEOF(gCommandIds) ; ++i )        {            if ( gCommandIds[i].wxId == wxId )            {                macId = gCommandIds[i].macId ;                break ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -