📄 private.h
字号:
/////////////////////////////////////////////////////////////////////////////// Name: wx/mac/carbon/private.h// Purpose: Private declarations: as this header is only included by// wxWidgets itself, it may contain identifiers which don't start// with "wx".// Author: Stefan Csomor// Modified by:// Created: 1998-01-01// RCS-ID: $Id: private.h,v 1.75 2006/12/08 15:01:45 SC Exp $// Copyright: (c) Stefan Csomor// Licence: wxWindows licence/////////////////////////////////////////////////////////////////////////////#ifndef _WX_PRIVATE_H_#define _WX_PRIVATE_H_#include "wx/defs.h"#ifdef __DARWIN__# include <Carbon/Carbon.h>#else# include <Debugging.h># include <Quickdraw.h># include <Appearance.h># include <Folders.h># include <Controls.h># include <ControlDefinitions.h># include <LowMem.h># include <Gestalt.h># include <FixMath.h># include <CoreServices.h>#endif#if UNIVERSAL_INTERFACES_VERSION < 0x0342 #error "please update to Apple's latest universal headers from http://developer.apple.com/sdk/"#endif#ifndef MAC_OS_X_VERSION_10_3 #define MAC_OS_X_VERSION_10_3 1030#endif#ifndef MAC_OS_X_VERSION_10_4 #define MAC_OS_X_VERSION_10_4 1040#endif#ifndef MAC_OS_X_VERSION_10_5 #define MAC_OS_X_VERSION_10_5 1050#endif#ifdef __WXMAC_CARBON__#include "wx/mac/corefoundation/cfstring.h"#endif#ifndef FixedToInt// as macro in FixMath.h for 10.3inline Fixed IntToFixed( int inInt ){ return (((SInt32) inInt) << 16);}inline int FixedToInt( Fixed inFixed ){ return (((SInt32) inFixed) >> 16);}#endif#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5typedef UInt32 URefCon;typedef SInt32 SRefCon;#endif#if wxUSE_GUI#include "wx/listbox.h"#ifndef __LP64__class wxMacPortStateHelper{ DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)public: wxMacPortStateHelper( GrafPtr newport); wxMacPortStateHelper(); ~wxMacPortStateHelper(); void Setup( GrafPtr newport ); void Clear(); bool IsCleared() { return m_clip == NULL; } GrafPtr GetCurrentPort() { return m_currentPort; }private: GrafPtr m_currentPort; GrafPtr m_oldPort; RgnHandle m_clip; ThemeDrawingState m_drawingState; short m_textFont; short m_textSize; short m_textStyle; short m_textMode;};class WXDLLEXPORT wxMacPortSaver{ DECLARE_NO_COPY_CLASS(wxMacPortSaver)public: wxMacPortSaver( GrafPtr port ); ~wxMacPortSaver();private : GrafPtr m_port;};class WXDLLEXPORT wxMacPortSetter{ DECLARE_NO_COPY_CLASS(wxMacPortSetter)public: wxMacPortSetter( const wxDC* dc ); ~wxMacPortSetter();private: wxMacPortStateHelper m_ph; const wxDC* m_dc;};/* Clips to the visible region of a control within the current port */class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver{ DECLARE_NO_COPY_CLASS(wxMacWindowClipper)public: wxMacWindowClipper( const wxWindow* win ); ~wxMacWindowClipper();private: GrafPtr m_newPort; RgnHandle m_formerClip; RgnHandle m_newClip;};class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper{ DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)public: wxMacWindowStateSaver( const wxWindow* win ); ~wxMacWindowStateSaver();private: GrafPtr m_newPort; ThemeDrawingState m_themeDrawingState;};#endif#if wxMAC_USE_CORE_GRAPHICSclass WXDLLEXPORT wxMacCGContextStateSaver{ DECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver)public: wxMacCGContextStateSaver( CGContextRef cg ) { m_cg = cg; CGContextSaveGState( cg ); } ~wxMacCGContextStateSaver() { CGContextRestoreGState( m_cg ); }private: CGContextRef m_cg;};#endif/*class wxMacDrawingHelper{ DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)public: wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ); ~wxMacDrawingHelper(); bool Ok() const { return IsOk(); } bool IsOk() { return m_ok; } void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ); } void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ); } void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ); } const Point& GetOrigin() { return m_origin; }private: Point m_origin; GrafPtr m_formerPort; GrafPtr m_currentPort; PenState m_savedPenState; bool m_ok;};*/// app.hbool wxMacConvertEventToRecord( EventRef event , EventRecord *rec);#endif // wxUSE_GUI// filefn.hWXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec );WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec );// utils.hWXDLLEXPORT wxString wxMacFindFolderNoSeparator(short vRefNum, OSType folderType, Boolean createFolder);WXDLLEXPORT wxString wxMacFindFolder(short vRefNum, OSType folderType, Boolean createFolder);template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ); return 0; }template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle; }template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef; }template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef; }template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef; }template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef; }template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint; }template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle; }template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean; }template<> inline EventParamType wxMacGetEventParamType<SInt16>() { return typeSInt16; }template<> inline EventParamType wxMacGetEventParamType<SInt32>() { return typeSInt32; }template<> inline EventParamType wxMacGetEventParamType<UInt32>() { return typeUInt32; }template<> inline EventParamType wxMacGetEventParamType<RGBColor>() { return typeRGBColor; }#if TARGET_API_MAC_OSXtemplate<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand; }template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint; }template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize; }template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect; }template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr; }#endif#if TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 )template<> inline EventParamType wxMacGetEventParamType<CFDictionaryRef>() { return typeCFDictionaryRef; }#endiftemplate<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection; }template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef; }/* These are ambiguous template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr; } template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus; } template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex; } template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr; } */class wxMacCarbonEvent{public : wxMacCarbonEvent() { m_eventRef = 0; m_release = false; } wxMacCarbonEvent( EventRef event , bool release = false ) { m_eventRef = event; m_release = release; } wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone) { m_eventRef = NULL; verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ); m_release = true; } ~wxMacCarbonEvent() { if ( m_release ) ReleaseEvent( m_eventRef ); } OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone) { verify( (m_eventRef == NULL) || m_release ); if ( m_eventRef && m_release ) { ReleaseEvent( m_eventRef ); m_release = false; m_eventRef = NULL; } OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef); if ( err == noErr ) m_release = true; return err; } OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData); template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data ) { return GetParameter( inName, type , sizeof( T ) , data ); } template <typename T> OSStatus GetParameter( EventParamName inName, T *data ) { return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ); } template <typename T> T GetParameter( EventParamName inName ) { T value; verify_noerr( GetParameter<T>( inName, &value ) ); return value; } template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType ) { T value; verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ); return value; } OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData); template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data ) { return SetParameter( inName, inDesiredType , sizeof( T ) , data ); } template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data ) { return SetParameter<T>( inName, inDesiredType , &data ); } template <typename T> OSStatus SetParameter( EventParamName inName, const T *data ) { return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ); } template <typename T> OSStatus SetParameter( EventParamName inName, const T& data ) { return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ); } UInt32 GetClass() { return ::GetEventClass( m_eventRef ); } UInt32 GetKind() { return ::GetEventKind( m_eventRef ); } EventTime GetTime() { return ::GetEventTime( m_eventRef ); } UInt32 GetTicks() { return EventTimeToTicks( GetTime() ); } OSStatus SetCurrentTime( ) { return ::SetEventTime( m_eventRef , GetCurrentEventTime() ); } OSStatus SetTime( EventTime when ) { return ::SetEventTime( m_eventRef , when ); } operator EventRef () { return m_eventRef; } bool IsValid() { return m_eventRef != 0; }protected : EventRef m_eventRef; bool m_release;};//// helper class for allocating and deallocating Universal Proc Ptrs//template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP{public : wxMacUPP( procType proc ) { m_upp = NULL; m_upp = (*newUPP)( NULL ); } ~wxMacUPP() { if ( m_upp ) disposeUPP( m_upp ); } operator uppType() { return m_upp; }private : uppType m_upp;};typedef wxMacUPP<NMProcPtr,NMUPP,NewNMUPP,DisposeNMUPP> wxMacNMUPP;template <typename refType> class wxMacCFRefHolder{public : wxMacCFRefHolder() : m_ref(NULL) , m_release(false) { } wxMacCFRefHolder( refType ref , bool release = true ) : m_ref(ref) , m_release(release) { } ~wxMacCFRefHolder() { Release(); } void Release() { if ( m_release && m_ref != NULL ) CFRelease( m_ref ); m_ref = NULL; } refType Detach() { refType val = m_ref; m_release = false; m_ref = NULL; return val; } void Set( refType ref , bool release = true ) { Release(); m_release = release; m_ref = ref; } operator refType () const { return m_ref; }private : refType m_ref; bool m_release; DECLARE_NO_COPY_CLASS( wxMacCFRefHolder )};#if wxUSE_GUI/*GWorldPtr wxMacCreateGWorld( int width , int height , int depth );void wxMacDestroyGWorld( GWorldPtr gw );PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL );CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize );void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -