📄 utils.cpp
字号:
/////////////////////////////////////////////////////////////////////////////// Name: src/mac/carbon/utils.cpp// Purpose: Various utilities// Author: Stefan Csomor// Modified by:// Created: 1998-01-01// RCS-ID: $Id: utils.cpp,v 1.138 2006/12/10 13:18:35 SC 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/toplevel.h" #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>#include "MoreFilesX.h"#ifndef __DARWIN__ #include <Threads.h> #include <Sound.h>#endif#if wxUSE_GUI#if TARGET_API_MAC_OSX #include <CoreServices/CoreServices.h>#else #include <DriverServices.h> #include <Multiprocessing.h>#endif#ifdef __DARWIN__ #include <Carbon/Carbon.h>#else #include <ATSUnicode.h> #include <TextCommon.h> #include <TextEncodingConverter.h>#endif#endif // wxUSE_GUI#include "wx/mac/private.h"#if defined(__MWERKS__) && wxUSE_UNICODE#if __MWERKS__ < 0x4100 || !defined(__DARWIN__) #include <wtime.h>#endif#endif#if wxUSE_BASE// our OS version is the same in non GUI and GUI caseswxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn){ SInt32 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}// ----------------------------------------------------------------------------// debugging support// ----------------------------------------------------------------------------#if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...#ifndef __MetroNubUtils__#include "MetroNubUtils.h"#endif#ifndef __GESTALT__#include <Gestalt.h>#endif#if TARGET_API_MAC_CARBON#include <CodeFragments.h>extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);ProcPtr gCallUniversalProc_Proc = NULL;#endifstatic MetroNubUserEntryBlock* gMetroNubEntry = NULL;static long fRunOnce = false;Boolean IsMetroNubInstalled(){ if (!fRunOnce) { long result, value; fRunOnce = true; gMetroNubEntry = NULL; if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) { // look for MetroNub's Gestalt selector if (Gestalt(kMetroNubUserSignature, &result) == noErr) {#if TARGET_API_MAC_CARBON if (gCallUniversalProc_Proc == NULL) { CFragConnectionID connectionID; Ptr mainAddress; Str255 errorString; ProcPtr symbolAddress; OSErr err; CFragSymbolClass symbolClass; symbolAddress = NULL; err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, &connectionID, &mainAddress, errorString); if (err != noErr) { gCallUniversalProc_Proc = NULL; goto end; } err = FindSymbol(connectionID, "\pCallUniversalProc", (Ptr *) &gCallUniversalProc_Proc, &symbolClass); if (err != noErr) { gCallUniversalProc_Proc = NULL; goto end; } }#endif { MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; // make sure the version of the API is compatible if (block->apiLowVersion <= kMetroNubUserAPIVersion && kMetroNubUserAPIVersion <= block->apiHiVersion) { // success! gMetroNubEntry = block; } } } } }end:#if TARGET_API_MAC_CARBON return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);#else return (gMetroNubEntry != NULL);#endif}Boolean IsMWDebuggerRunning(){ if (IsMetroNubInstalled()) return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); return false;}Boolean AmIBeingMWDebugged(){ if (IsMetroNubInstalled()) return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); return false;}extern bool WXDLLEXPORT wxIsDebuggerRunning(){ return IsMWDebuggerRunning() && AmIBeingMWDebugged();}#elseextern bool WXDLLEXPORT wxIsDebuggerRunning(){ return false;}#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)#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 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 hostname only (without domain name)bool wxGetHostName(wxChar *buf, int maxSize){ // Gets Chooser name of user by examining a System resource. buf[0] = 0; 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 ); } return true;}// Get user name e.g. Stefan Csomorbool wxGetUserName(wxChar *buf, int maxSize){ // Gets Chooser name of user by examining a System resource. buf[0] = 0; 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 ); } 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 Shellbool 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();}#ifndef __DARWIN__void wxMicroSleep(unsigned long microseconds){ AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime()); MPDelayUntil( & wakeup);}void wxMilliSleep(unsigned long milliseconds){ AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime()); MPDelayUntil( & wakeup);}void wxSleep(int nSecs){ wxMilliSleep(1000*nSecs);}#endif// Consume all events until no more leftvoid wxFlushEvents(){}#endif // !__DARWIN__// Emit a beeeeeepvoid wxBell(){#ifndef __LP64__ SysBeep(30);#endif}#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 succ;}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 succ;}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 succ;}#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}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -