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

📄 window.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    while ( node )
    {
        wxWindowMac *child = (wxWindowMac *)node->GetData();
        if ( child->m_isShown )
            child->MacSuperEnabled( enabled ) ;
        node = node->GetNext();
    }
}

bool wxWindowMac::MacIsReallyShown() const
{
    if ( m_isShown && (m_parent != NULL && !IsTopLevel() ) ) {
        return m_parent->MacIsReallyShown();
    }
    return m_isShown;
/*
    bool status = m_isShown ;
    wxWindowMac * win = this ;
    while ( status && win->m_parent != NULL )
    {
        win = win->m_parent ;
        status = win->m_isShown ;
    }
    return status ;
*/
}

int wxWindowMac::GetCharHeight() const
{
    wxClientDC dc ( (wxWindowMac*)this ) ;
    return dc.GetCharHeight() ;
}

int wxWindowMac::GetCharWidth() const
{
    wxClientDC dc ( (wxWindowMac*)this ) ;
    return dc.GetCharWidth() ;
}

void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
                           int *descent, int *externalLeading, const wxFont *theFont ) const
{
    const wxFont *fontToUse = theFont;
    if ( !fontToUse )
        fontToUse = &m_font;

    wxClientDC dc( (wxWindowMac*) this ) ;
    long lx,ly,ld,le ;
    dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
    if ( externalLeading )
        *externalLeading = le ;
    if ( descent )
        *descent = ld ;
    if ( x )
        *x = lx ;
    if ( y )
        *y = ly ;
}

/*
 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
 * we always intersect with the entire window, not only with the client area
 */

void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
{
    if ( MacGetTopLevelWindow() == NULL )
        return ;

    if ( !MacIsReallyShown() )
        return ;

     wxPoint client = GetClientAreaOrigin();
    int x1 = -client.x;
    int y1 = -client.y;
    int x2 = m_width - client.x;
    int y2 = m_height - client.y;

    if (IsKindOf( CLASSINFO(wxButton)))
    {
        // buttons have an "aura"
        y1 -= 5;
        x1 -= 5;
        y2 += 5;
        x2 += 5;
    }

    Rect clientrect = { y1, x1, y2, x2 };

    if ( rect )
    {
        Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
        SectRect( &clientrect , &r , &clientrect ) ;
    }

    if ( !EmptyRect( &clientrect ) )
    {
      int top = 0 , left = 0 ;

      MacClientToRootWindow( &left , &top ) ;
      OffsetRect( &clientrect , left , top ) ;

      MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
    }
}

wxWindowMac *wxGetActiveWindow()
{
    // actually this is a windows-only concept
    return NULL;
}

// Coordinates relative to the window
void wxWindowMac::WarpPointer (int x_pos, int y_pos)
{
    // We really don't move the mouse programmatically under Mac.
}

const wxBrush& wxWindowMac::MacGetBackgroundBrush()
{
    if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
    {
        m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ;
    }
    else if (  m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
    {
        // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
        // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
        // either a non gray background color or a non control window

        WindowRef window = (WindowRef) MacGetRootWindow() ;

        wxWindowMac* parent = GetParent() ;
        while( parent )
        {
            if ( parent->MacGetRootWindow() != (WXWindow) window )
            {
                // we are in a different window on the mac system
                parent = NULL ;
                break ;
            }

            {
                if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE )
                    && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
                {
                    // if we have any other colours in the hierarchy
                    m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ;
                    break ;
                }
                // if we have the normal colours in the hierarchy but another control etc. -> use it's background
                if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
                {
                    Rect extent = { 0 , 0 , 0 , 0 } ;
                    int x , y ;
                    x = y = 0 ;
                    wxSize size = parent->GetSize() ;
                    parent->MacClientToRootWindow( &x , &y ) ;
                    extent.left = x ;
                    extent.top = y ;
                    extent.top-- ;
                    extent.right = x + size.x ;
                    extent.bottom = y + size.y ;
                    m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive
                    break ;
                }
            }
            parent = parent->GetParent() ;
        }
        if ( !parent )
        {
            m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive
        }
    }
    else
    {
        m_macBackgroundBrush.SetColour( m_backgroundColour ) ;
    }

    return m_macBackgroundBrush ;
}

void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
{
    event.GetDC()->Clear() ;
}

void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
{
    wxWindowDC dc(this) ;
    wxMacPortSetter helper(&dc) ;

    MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
}

int wxWindowMac::GetScrollPos(int orient) const
{
    if ( orient == wxHORIZONTAL )
    {
       if ( m_hScrollBar )
           return m_hScrollBar->GetThumbPosition() ;
    }
    else
    {
       if ( m_vScrollBar )
           return m_vScrollBar->GetThumbPosition() ;
    }
    return 0;
}

// This now returns the whole range, not just the number
// of positions that we can scroll.
int wxWindowMac::GetScrollRange(int orient) const
{
    if ( orient == wxHORIZONTAL )
    {
       if ( m_hScrollBar )
           return m_hScrollBar->GetRange() ;
    }
    else
    {
       if ( m_vScrollBar )
           return m_vScrollBar->GetRange() ;
    }
    return 0;
}

int wxWindowMac::GetScrollThumb(int orient) const
{
    if ( orient == wxHORIZONTAL )
    {
       if ( m_hScrollBar )
           return m_hScrollBar->GetThumbSize() ;
    }
    else
    {
       if ( m_vScrollBar )
           return m_vScrollBar->GetThumbSize() ;
    }
    return 0;
}

void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
{
    if ( orient == wxHORIZONTAL )
    {
       if ( m_hScrollBar )
           m_hScrollBar->SetThumbPosition( pos ) ;
    }
    else
    {
       if ( m_vScrollBar )
           m_vScrollBar->SetThumbPosition( pos ) ;
    }
}

void wxWindowMac::MacPaintBorders( int left , int top )
{
    if( IsTopLevel() )
        return ;

    int major,minor;
    wxGetOsVersion( &major, &minor );

    RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
    RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;

    RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
    RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
    // OS X has lighter border edges than classic:
    if (major >= 10)
    {
        darkShadow.red      = 0x8E8E;
        darkShadow.green    = 0x8E8E;
        darkShadow.blue     = 0x8E8E;
        lightShadow.red     = 0xBDBD;
        lightShadow.green   = 0xBDBD;
        lightShadow.blue    = 0xBDBD;
    }

    PenNormal() ;

    if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
    {
#if wxMAC_USE_THEME_BORDER
        Rect rect = { top , left , m_height + top , m_width + left } ;
        SInt32 border = 0 ;
        /*
        GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
        InsetRect( &rect , border , border );
        DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
        */

        DrawThemePrimaryGroup(&rect  ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
#else
        bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
        RGBForeColor( &face );
        MoveTo( left + 0 , top + m_height - 2 );
        LineTo( left + 0 , top + 0 );
        LineTo( left + m_width - 2 , top + 0 );

        MoveTo( left + 2 , top + m_height - 3 );
        LineTo( left + m_width - 3 , top + m_height - 3 );
        LineTo( left + m_width - 3 , top + 2 );

        RGBForeColor( sunken ? &face : &darkShadow );
        MoveTo( left + 0 , top + m_height - 1 );
        LineTo( left + m_width - 1 , top + m_height - 1 );
        LineTo( left + m_width - 1 , top + 0 );

        RGBForeColor( sunken ? &lightShadow : &white );
        MoveTo( left + 1 , top + m_height - 3 );
        LineTo( left + 1, top + 1 );
        LineTo( left + m_width - 3 , top + 1 );

        RGBForeColor( sunken ? &white : &lightShadow );
        MoveTo( left + 1 , top + m_height - 2 );
        LineTo( left + m_width - 2 , top + m_height - 2 );
        LineTo( left + m_width - 2 , top + 1 );

        RGBForeColor( sunken ? &darkShadow : &face );
        MoveTo( left + 2 , top + m_height - 4 );
        LineTo( left + 2 , top + 2 );
        LineTo( left + m_width - 4 , top + 2 );
#endif
    }
    else if (HasFlag(wxSIMPLE_BORDER))
    {
        Rect rect = { top , left , m_height + top , m_width + left } ;
        RGBForeColor( &darkShadow ) ;
        FrameRect( &rect ) ;
    }
}

void wxWindowMac::RemoveChild( wxWindowBase *child )
{
    if ( child == m_hScrollBar )
        m_hScrollBar = NULL ;
    if ( child == m_vScrollBar )
        m_vScrollBar = NULL ;

    wxWindowBase::RemoveChild( child ) ;
}

// New function that will replace some of the above.
void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
    int range, bool refresh)
{
    if ( orient == wxHORIZONTAL )
    {
        if ( m_hScrollBar )
        {
            if ( range == 0 || thumbVisible >= range )
            {
                if ( m_hScrollBar->IsShown() )
                    m_hScrollBar->Show(false) ;
            }
            else
            {
                if ( !m_hScrollBar->IsShown() )
                    m_hScrollBar->Show(true) ;
                m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
            }
        }
    }
    else
    {
        if ( m_vScrollBar )
        {
            if ( range == 0 || thumbVisible >= range )
            {
                if ( m_vScrollBar->IsShown() )
                    m_vScrollBar->Show(false) ;
            }
            else
            {
                if ( !m_vScrollBar->IsShown() )
                    m_vScrollBar->Show(true) ;
                m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
            }
        }
    }
    MacRepositionScrollBars() ;
}

// Does a physical scroll
void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
{
    if( dx == 0 && dy ==0 )
        return ;


    {
        wxClientDC dc(this) ;
        wxMacPortSetter helper(&dc) ;

        int width , height ;
        GetClientSize( &width , &height ) ;

        Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ;
        RgnHandle updateRgn = NewRgn() ;
        ClipRect( &scrollrect ) ;
        if ( rect )
        {
            Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
                dc.XLOG2DEVMAC(rect->x + rect->width) } ;
            SectRect( &scrollrect , &r , &scrollrect ) ;
        }
        ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
        // we also have to scroll the update rgn in this rectangle
        // in order not to loose updates
        WindowRef rootWindow = (WindowRef) MacGetRootWindow() ;
        RgnHandle formerUpdateRgn = NewRgn() ;
        RgnHandle scrollRgn = NewRgn() ;
        RectRgn( scrollRgn , &scrollrect ) ;
        GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
        Point pt = {0,0} ;
        LocalToGlobal( &pt ) ;
        OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
        SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;

⌨️ 快捷键说明

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