📄 uma.cpp
字号:
void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry ){ MacInsertMenuItem( menu , "\pA" , item) ; UMASetMenuItemText(menu, item+1 , title , encoding ); UMASetMenuItemShortcut( menu , item+1 , entry ) ;}// quickdraw#if !TARGET_CARBONint gPrOpenCounter = 0 ;OSStatus UMAPrOpen(){ OSErr err = noErr ; ++gPrOpenCounter ; if ( gPrOpenCounter == 1 ) { PrOpen() ; err = PrError() ; wxASSERT( err == noErr ) ; } return err ;}OSStatus UMAPrClose(){ OSErr err = noErr ; wxASSERT( gPrOpenCounter >= 1 ) ; if ( gPrOpenCounter == 1 ) { PrClose() ; err = PrError() ; wxASSERT( err == noErr ) ; } --gPrOpenCounter ; return err ;}pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;pascal QDGlobalsPtr GetQDGlobalsPtr (void){ return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);}#endifvoid UMAShowWatchCursor(){ OSErr err = noErr; CursHandle watchFob = GetCursor (watchCursor); if (!watchFob) err = nilHandleErr; else { #if TARGET_CARBON// Cursor preservedArrow;// GetQDGlobalsArrow (&preservedArrow);// SetQDGlobalsArrow (*watchFob);// InitCursor ( );// SetQDGlobalsArrow (&preservedArrow); SetCursor (*watchFob); #else SetCursor (*watchFob); #endif }}void UMAShowArrowCursor(){#if TARGET_CARBON Cursor arrow; SetCursor (GetQDGlobalsArrow (&arrow));#else SetCursor (&(qd.arrow));#endif}// window managerGrafPtr UMAGetWindowPort( WindowRef inWindowRef ){ wxASSERT( inWindowRef != NULL ) ;#if TARGET_CARBON return (GrafPtr) GetWindowPort( inWindowRef ) ;#else return (GrafPtr) inWindowRef ;#endif}void UMADisposeWindow( WindowRef inWindowRef ){ wxASSERT( inWindowRef != NULL ) ; DisposeWindow( inWindowRef ) ;}void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding){#if TARGET_CARBON SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;#else Str255 ptitle ; wxMacStringToPascal( title , ptitle ) ; SetWTitle( inWindowRef , ptitle ) ;#endif}// appearance additionsvoid UMASetControlTitle( ControlHandle inControl , const wxString& title , wxFontEncoding encoding){#if TARGET_CARBON SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;#else Str255 ptitle ; wxMacStringToPascal( title , ptitle ) ; SetControlTitle( inControl , ptitle ) ;#endif}void UMAActivateControl( ControlHandle inControl ){ // we have to add the control after again to the update rgn // otherwise updates get lost if ( !IsControlActive( inControl ) ) { bool visible = IsControlVisible( inControl ) ; if ( visible ) SetControlVisibility( inControl , false , false ) ; ::ActivateControl( inControl ) ; if ( visible ) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } }}void UMADrawControl( ControlHandle inControl ){ WindowRef theWindow = GetControlOwner(inControl) ; wxMacPortStateHelper help( (GrafPtr) GetWindowPort(theWindow) ) ; RgnHandle updateRgn = NewRgn() ; GetWindowUpdateRgn( theWindow , updateRgn ) ; Point zero = { 0 , 0 } ; LocalToGlobal( &zero ) ; OffsetRgn( updateRgn , -zero.h , -zero.v ) ; ::DrawControlInCurrentPort( inControl ) ; InvalWindowRgn( theWindow, updateRgn) ; DisposeRgn( updateRgn ) ;}void UMAMoveControl( ControlHandle inControl , short x , short y ){ bool visible = IsControlVisible( inControl ) ; if ( visible ) { SetControlVisibility( inControl , false , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } ::MoveControl( inControl , x , y ) ; if ( visible ) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; }}void UMASizeControl( ControlHandle inControl , short x , short y ){ bool visible = IsControlVisible( inControl ) ; if ( visible ) { SetControlVisibility( inControl , false , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } ::SizeControl( inControl , x , y ) ; if ( visible ) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; }}void UMADeactivateControl( ControlHandle inControl ){ // we have to add the control after again to the update rgn // otherwise updates get lost bool visible = IsControlVisible( inControl ) ; if ( visible ) SetControlVisibility( inControl , false , false ) ; ::DeactivateControl( inControl ) ; if ( visible ) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; }}// shows the control and adds the region to the update regionvoid UMAShowControl (ControlHandle inControl){ SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;}// shows the control and adds the region to the update regionvoid UMAHideControl (ControlHandle inControl){ SetControlVisibility( inControl , false , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;}// keyboard focusOSErr UMASetKeyboardFocus (WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart){ OSErr err = noErr; GrafPtr port ; GetPort( &port ) ; SetPortWindowPort( inWindow ) ; err = SetKeyboardFocus( inWindow , inControl , inPart ) ; SetPort( port ) ; return err ;}// eventsvoid UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ){ wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) inWindow) ) ; RgnHandle updateRgn = NewRgn() ; GetWindowUpdateRgn( inWindow , updateRgn ) ; Point zero = { 0 , 0 } ; LocalToGlobal( &zero ) ; OffsetRgn( updateRgn , -zero.h , -zero.v ) ; UpdateControls( inWindow , inRgn ) ; InvalWindowRgn( inWindow, updateRgn) ; DisposeRgn( updateRgn ) ;}bool UMAIsWindowFloating( WindowRef inWindow ){ WindowClass cl ; GetWindowClass( inWindow , &cl ) ; return cl == kFloatingWindowClass ;}bool UMAIsWindowModal( WindowRef inWindow ){ WindowClass cl ; GetWindowClass( inWindow , &cl ) ; return cl < kFloatingWindowClass ;}// othersvoid UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ){ if ( inWindowRef ) {// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;// if ( inActivate != isHightlited ) GrafPtr port ; GetPort( &port ) ; SetPortWindowPort( inWindowRef ) ; HiliteWindow( inWindowRef , inActivate ) ; ControlHandle control = NULL ; ::GetRootControl( inWindowRef , & control ) ; if ( control ) { if ( inActivate ) UMAActivateControl( control ) ; else UMADeactivateControl( control ) ; } SetPort( port ) ; }}OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ){ return ::DrawThemePlacard( inRect , inState ) ;}#if !TARGET_CARBONstatic OSStatus helpMenuStatus = noErr ;static MenuItemIndex firstCustomItemIndex = 0 ;#endifOSStatus UMAGetHelpMenu( MenuRef * outHelpMenu, MenuItemIndex * outFirstCustomItemIndex){#if TARGET_CARBON return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;#else MenuRef helpMenuHandle ; helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) { firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; } if ( outFirstCustomItemIndex ) { *outFirstCustomItemIndex = firstCustomItemIndex ; } *outHelpMenu = helpMenuHandle ; return helpMenuStatus ;#endif}wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport){ m_clip = NULL ; Setup( newport ) ;}wxMacPortStateHelper::wxMacPortStateHelper(){ m_clip = NULL ;}void wxMacPortStateHelper::Setup( GrafPtr newport ){ GetPort( &m_oldPort ) ; SetPort( newport ) ; SetOrigin(0,0); wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ; m_clip = NewRgn() ; GetClip( m_clip ); m_textFont = GetPortTextFont( (CGrafPtr) newport); m_textSize = GetPortTextSize( (CGrafPtr) newport); m_textStyle = GetPortTextFace( (CGrafPtr) newport); m_textMode = GetPortTextMode( (CGrafPtr) newport); GetThemeDrawingState( &m_drawingState ) ; m_currentPort = newport ;}void wxMacPortStateHelper::Clear(){ if ( m_clip ) { DisposeRgn( m_clip ) ; DisposeThemeDrawingState( m_drawingState ) ; m_clip = NULL ; }}wxMacPortStateHelper::~wxMacPortStateHelper(){ if ( m_clip ) { SetPort( m_currentPort ) ; SetClip( m_clip ) ; DisposeRgn( m_clip ) ; TextFont( m_textFont ); TextSize( m_textSize ); TextFace( m_textStyle ); TextMode( m_textMode ); SetThemeDrawingState( m_drawingState , true ) ; SetPort( m_oldPort ) ; }}OSStatus UMAPutScrap( Size size , OSType type , void *data ){ OSStatus err = noErr ;#if !TARGET_CARBON err = PutScrap( size , type , data ) ;#else ScrapRef scrap; err = GetCurrentScrap (&scrap); if ( !err ) { err = PutScrapFlavor (scrap, type , 0, size, data); }#endif return err ;}#endif // wxUSE_GUI#if wxUSE_BASEstatic bool sUMASystemInitialized = false ;bool UMASystemIsInitialized(){ return sUMASystemInitialized ;}void UMASetSystemIsInitialized(bool val){ sUMASystemInitialized = val;}#endif // wxUSE_BASE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -