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

📄 utils.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        src/mac/classic/utils.cpp// Purpose:     Various utilities// Author:      Stefan Csomor// Modified by:// Created:     1998-01-01// RCS-ID:      $Id: utils.cpp,v 1.17 2006/08/13 22:43:30 VZ Exp $// Copyright:   (c) Stefan Csomor// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////#include "wx/wxprec.h"#include "wx/utils.h"#ifndef WX_PRECOMP    #include "wx/intl.h"    #include "wx/app.h"    #if wxUSE_GUI        #include "wx/font.h"    #endif#endif#include "wx/apptrait.h"#if wxUSE_GUI    #include "wx/mac/uma.h"#endif#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#ifdef __DARWIN__#  include "MoreFilesX.h"#else#  include "MoreFiles.h"#  include "MoreFilesExtras.h"#endif#ifndef __DARWIN__#include <Threads.h>#include <Sound.h>#endif#include <ATSUnicode.h>#include <TextCommon.h>#include <TextEncodingConverter.h>#include  "wx/mac/private.h"  // includes mac headers#if defined(__MWERKS__) && wxUSE_UNICODE    #include <wtime.h>#endif#if wxUSE_BASE// our OS version is the same in non GUI and GUI caseswxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn){    long theSystem;    Gestalt(gestaltSystemVersion, &theSystem);    if ( majorVsn != NULL )        *majorVsn = (theSystem >> 8);    if ( minorVsn != NULL )        *minorVsn = (theSystem & 0xFF);#if defined( __DARWIN__ )    return wxOS_MAC_OSX_DARWIN;#else    return wxOS_MAC_OS;#endif}#ifndef __DARWIN__// defined in unix/utilsunx.cpp for Mac OS X// get full hostname (with domain name if possible)bool wxGetFullHostName(wxChar *buf, int maxSize){    return wxGetHostName(buf, maxSize);}// Get hostname only (without domain name)bool wxGetHostName(wxChar *buf, int maxSize){    // Gets Chooser name of user by examining a System resource.    const short kComputerNameID = -16413;    short oldResFile = CurResFile() ;    UseResFile(0);    StringHandle chooserName = (StringHandle)::GetString(kComputerNameID);    UseResFile(oldResFile);    if (chooserName && *chooserName)    {        HLock( (Handle) chooserName ) ;        wxString name = wxMacMakeStringFromPascal( *chooserName ) ;        HUnlock( (Handle) chooserName ) ;        ReleaseResource( (Handle) chooserName ) ;        wxStrncpy( buf , name , maxSize - 1 ) ;    }    else        buf[0] = 0 ;    return true;}// Get user ID e.g. jacsbool wxGetUserId(wxChar *buf, int maxSize){  return wxGetUserName( buf , maxSize ) ;}const wxChar* wxGetHomeDir(wxString *pstr){    *pstr = wxMacFindFolder(  (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;    return pstr->c_str() ;}// Get user name e.g. Stefan Csomorbool wxGetUserName(wxChar *buf, int maxSize){    // Gets Chooser name of user by examining a System resource.    const short kChooserNameID = -16096;    short oldResFile = CurResFile() ;    UseResFile(0);    StringHandle chooserName = (StringHandle)::GetString(kChooserNameID);    UseResFile(oldResFile);    if (chooserName && *chooserName)    {        HLock( (Handle) chooserName ) ;        wxString name = wxMacMakeStringFromPascal( *chooserName ) ;        HUnlock( (Handle) chooserName ) ;        ReleaseResource( (Handle) chooserName ) ;        wxStrncpy( buf , name , maxSize - 1 ) ;    }    else        buf[0] = 0 ;    return true;}int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags){    // TODO    return 0;}WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value){    // TODO : under classic there is no environement support, under X yes    return false ;}// set the env var name to the given value, return true on successWXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value){    // TODO : under classic there is no environement support, under X yes    return false ;}//// Execute a program in an Interactive Shell//bool wxShell(const wxString& command){    // TODO    return false;}// Shutdown or reboot the PCbool wxShutdown(wxShutdownFlags wFlags){    // TODO    return false;}// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)wxMemorySize wxGetFreeMemory(){    return (wxMemorySize)FreeMem() ;}void wxUsleep(unsigned long milliseconds){    clock_t start = clock() ;    do    {        YieldToAnyThread() ;    } while( clock() - start < milliseconds /  1000.0 * CLOCKS_PER_SEC ) ;}void wxSleep(int nSecs){    wxUsleep(1000*nSecs);}// Consume all events until no more leftvoid wxFlushEvents(){}#endif // !__DARWIN__// Emit a beeeeeepvoid wxBell(){    SysBeep(30);}#endif // wxUSE_BASE#if wxUSE_GUIwxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const{    // We suppose that toolkit version is the same as OS version under Mac    wxGetOsVersion(verMaj, verMin);    return wxPORT_MAC;}// Reading and writing resources (eg WIN.INI, .Xdefaults)#if wxUSE_RESOURCESbool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file){    // TODO    return false;}bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file){    wxString buf;    buf.Printf(wxT("%.4f"), value);    return wxWriteResource(section, entry, buf, file);}bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file){    wxString buf;    buf.Printf(wxT("%ld"), value);    return wxWriteResource(section, entry, buf, file);}bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file){    wxString buf;    buf.Printf(wxT("%d"), value);    return wxWriteResource(section, entry, buf, file);}bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file){    // TODO    return false;}bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file){    char *s = NULL;    bool succ = wxGetResource(section, entry, (char **)&s, file);    if (succ)    {        *value = (float)strtod(s, NULL);        delete[] s;        return true;    }    else return false;}bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file){    char *s = NULL;    bool succ = wxGetResource(section, entry, (char **)&s, file);    if (succ)    {        *value = strtol(s, NULL, 10);        delete[] s;        return true;    }    else return false;}bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file){    char *s = NULL;    bool succ = wxGetResource(section, entry, (char **)&s, file);    if (succ)    {        *value = (int)strtol(s, NULL, 10);        delete[] s;        return true;    }    else return false;}#endif // wxUSE_RESOURCESint gs_wxBusyCursorCount = 0;extern wxCursor    gMacCurrentCursor ;wxCursor        gMacStoredActiveCursor ;// Set the cursor to the busy cursor for all windowsvoid wxBeginBusyCursor(const wxCursor *cursor){    if (gs_wxBusyCursorCount++ == 0)    {        gMacStoredActiveCursor = gMacCurrentCursor ;        cursor->MacInstall() ;    }    //else: nothing to do, already set}// Restore cursor to normalvoid wxEndBusyCursor(){    wxCHECK_RET( gs_wxBusyCursorCount > 0,        wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );    if (--gs_wxBusyCursorCount == 0)    {        gMacStoredActiveCursor.MacInstall() ;        gMacStoredActiveCursor = wxNullCursor ;    }}// true if we're between the above two callsbool wxIsBusy(){    return (gs_wxBusyCursorCount > 0);}#endif // wxUSE_GUI#if wxUSE_BASEwxString wxMacFindFolderNoSeparator( short        vol,              OSType       folderType,              Boolean      createFolder){    short    vRefNum  ;    long     dirID ;    wxString strDir ;    if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)    {        FSSpec file ;        if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )        {            strDir = wxMacFSSpec2MacFilename( &file );        }    }    return strDir ;}wxString wxMacFindFolder( short        vol,              OSType       folderType,              Boolean      createFolder){    return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH;}#endif // wxUSE_BASE#if wxUSE_GUI// Check whether this window wants to process messages, e.g. Stop button// in long calculations.bool wxCheckForInterrupt(wxWindow *wnd){    // TODO    return false;}void wxGetMousePosition( int* x, int* y ){    Point pt ;    GetMouse( &pt ) ;    LocalToGlobal( &pt ) ;    *x = pt.h ;    *y = pt.v ;};// Return true if we have a colour displaybool wxColourDisplay(){    return true;}// Returns depth of screenint wxDisplayDepth(){    Rect globRect ;    SetRect(&globRect, -32760, -32760, 32760, 32760);    GDHandle    theMaxDevice;    int theDepth = 8;    theMaxDevice = GetMaxDevice(&globRect);    if (theMaxDevice != nil)        theDepth = (**(**theMaxDevice).gdPMap).pixelSize;    return theDepth ;}// Get size of displayvoid wxDisplaySize(int *width, int *height){    BitMap screenBits;    GetQDGlobalsScreenBits( &screenBits );    if (width != NULL) {        *width = screenBits.bounds.right - screenBits.bounds.left  ;    }    if (height != NULL) {        *height = screenBits.bounds.bottom - screenBits.bounds.top ;    }}void wxDisplaySizeMM(int *width, int *height){    wxDisplaySize(width, height);    // on mac 72 is fixed (at least now ;-)    float cvPt2Mm = 25.4 / 72;    if (width != NULL) {        *width = int( *width * cvPt2Mm );    }    if (height != NULL) {        *height = int( *height * cvPt2Mm );    }}void wxClientDisplayRect(int *x, int *y, int *width, int *height){#if TARGET_CARBON    Rect r ;    GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ;    if ( x )        *x = r.left ;    if ( y )        *y = r.top ;    if ( width )        *width = r.right - r.left ;    if ( height )        *height = r.bottom - r.top ;#else    BitMap screenBits;    GetQDGlobalsScreenBits( &screenBits );

⌨️ 快捷键说明

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