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

📄 uma.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:

int 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() ;
pascal QDGlobalsPtr GetQDGlobalsPtr()
{
    return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
}

#endif

void UMAShowWatchCursor()
{
    OSErr err = noErr;

    CursHandle watchFob = GetCursor(watchCursor);

    if (watchFob == NULL)
    {
        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 manager

GrafPtr 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 additions

void UMASetControlTitle( ControlRef 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( ControlRef inControl )
{
#if TARGET_API_MAC_OSX
    ::ActivateControl( inControl ) ;

#else
    // 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), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
        }
    }
#endif
}

void UMAMoveControl( ControlRef inControl , short x , short y )
{
#if TARGET_API_MAC_OSX
    ::MoveControl( inControl , x , y ) ;

#else
    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) ) ;
    }
#endif
}

void UMASizeControl( ControlRef inControl , short x , short y )
{
#if TARGET_API_MAC_OSX
    ::SizeControl( inControl , x , y ) ;

#else
    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) ) ;
    }
#endif
}

void UMADeactivateControl( ControlRef inControl )
{
#if TARGET_API_MAC_OSX
    ::DeactivateControl( inControl ) ;

#else
    // 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), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
    }
#endif
}

// shows the control and adds the region to the update region
void UMAShowControl( ControlRef inControl )
{
    SetControlVisibility( inControl , true , false ) ;
    Rect ctrlBounds ;
    InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
}

// hides the control and adds the region to the update region
void UMAHideControl( ControlRef inControl )
{
    SetControlVisibility( inControl , false , false ) ;
    Rect ctrlBounds ;
    InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
}

// keyboard focus
OSErr UMASetKeyboardFocus( WindowPtr inWindow,
                                 ControlRef inControl,
                                 ControlFocusPart inPart )
{
    OSErr err = noErr;
    GrafPtr port ;

    GetPort( &port ) ;
    SetPortWindowPort( inWindow ) ;

    err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
    SetPort( port ) ;

    return err ;
}

bool UMAIsWindowFloating( WindowRef inWindow )
{
    WindowClass cl ;

    GetWindowClass( inWindow , &cl ) ;
    return cl == kFloatingWindowClass ;
}

bool UMAIsWindowModal( WindowRef inWindow )
{
    WindowClass cl ;

    GetWindowClass( inWindow , &cl ) ;
    return cl < kFloatingWindowClass ;
}

// others

void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
{
    if ( inWindowRef )
    {
//        bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
//        if ( inActivate != isHighlighted )

        GrafPtr port ;
        GetPort( &port ) ;
        SetPortWindowPort( inWindowRef ) ;
        HiliteWindow( inWindowRef , inActivate ) ;
        ControlRef 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_CARBON
static OSStatus helpMenuStatus = noErr ;
static MenuItemIndex firstCustomItemIndex = 0 ;
#endif

OSStatus 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 == noErr )
        err = PutScrapFlavor( scrap, type , 0, size, data );
#endif

    return err ;
}

Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds )
{
    GetControlBounds( theControl , bounds ) ;

#if TARGET_API_MAC_OSX
    WindowRef tlwref = GetControlOwner( theControl ) ;

    wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
    if ( tlwwx != NULL && tlwwx->MacUsesCompositing() )
    {
        ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ;
        HIPoint hiPoint = CGPointMake( 0 , 0 ) ;
        HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ;
        OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ;
    }
#endif

    return bounds ;
}

#endif  // wxUSE_GUI

#if wxUSE_BASE

static 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 + -