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

📄 window.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            return true;        if (event.GetEventType() == wxEVT_RIGHT_UP)            return true;    }    GetEventHandler()->ProcessEvent( event ) ;    return true;}wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ){    if ( m_tooltip )    {        return m_tooltip->GetTip() ;    }    return wxEmptyString ;}void wxWindowMac::Update(){    wxRegion visRgn = MacGetVisibleRegion( false ) ;    int top = 0 , left = 0 ;    MacWindowToRootWindow( &left , &top ) ;    WindowRef rootWindow = (WindowRef) MacGetRootWindow() ;    RgnHandle updateRgn = NewRgn() ;    // getting the update region in macos local coordinates    GetWindowUpdateRgn( rootWindow , updateRgn ) ;    GrafPtr     port ;    ::GetPort( &port ) ;    ::SetPort( UMAGetWindowPort( rootWindow ) ) ;    Point pt = {0,0} ;    LocalToGlobal( &pt ) ;    ::SetPort( port ) ;    OffsetRgn( updateRgn , -pt.h , -pt.v ) ;    // translate to window local coordinates    OffsetRgn( updateRgn , -left , -top ) ;    SectRgn( updateRgn , (RgnHandle) visRgn.GetWXHRGN() , updateRgn ) ;    MacRedraw( updateRgn , 0 , true ) ;    // for flushing and validating we need macos-local coordinates again    OffsetRgn( updateRgn , left , top ) ;#if TARGET_API_MAC_CARBON    if ( QDIsPortBuffered( GetWindowPort( rootWindow ) ) )    {        QDFlushPortBuffer( GetWindowPort( rootWindow ) , updateRgn ) ;    }#endif    ValidWindowRgn( rootWindow , updateRgn ) ;    DisposeRgn( updateRgn ) ;}wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const{    wxTopLevelWindowMac* win = NULL ;    WindowRef window = (WindowRef) MacGetRootWindow() ;    if ( window )    {        win = wxFindWinFromMacWindow( (WXWindow) window ) ;    }    return win ;}const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings ){    RgnHandle visRgn = NewRgn() ;    RgnHandle tempRgn = NewRgn() ;    RgnHandle tempStaticBoxRgn = NewRgn() ;    if ( MacIsReallyShown() )    {        SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ;        //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox        if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )        {            int borderTop = 14 ;            int borderOther = 4 ;            if ( UMAGetSystemVersion() >= 0x1030 )                borderTop += 2 ;            SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ;            DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ;        }        if ( !IsTopLevel() )        {            wxWindow* parent = GetParent() ;            while( parent )            {                wxSize size = parent->GetSize() ;                int x , y ;                x = y = 0 ;                parent->MacWindowToRootWindow( &x, &y ) ;                MacRootWindowToWindow( &x , &y ) ;                SetRectRgn( tempRgn ,                    x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,                    x + size.x - parent->MacGetRightBorderSize(),                    y + size.y - parent->MacGetBottomBorderSize()) ;                SectRgn( visRgn , tempRgn , visRgn ) ;                if ( parent->IsTopLevel() )                    break ;                parent = parent->GetParent() ;            }        }        if ( respectChildrenAndSiblings )        {            if ( GetWindowStyle() & wxCLIP_CHILDREN )            {                for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())                {                    wxWindowMac *child = node->GetData();                    if ( !child->IsTopLevel() && child->IsShown() )                    {                        SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width ,  child->m_y + child->m_height ) ;                        if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) )                        {                            int borderTop = 14 ;                            int borderOther = 4 ;                            if ( UMAGetSystemVersion() >= 0x1030 )                                borderTop += 2 ;                            SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ;                            DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;                        }                        DiffRgn( visRgn , tempRgn , visRgn ) ;                    }                }            }            if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() )            {                bool thisWindowThrough = false ;                for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext())                {                    wxWindowMac *sibling = node->GetData();                    if ( sibling == this )                    {                        thisWindowThrough = true ;                        continue ;                    }                    if( !thisWindowThrough )                    {                        continue ;                    }                    if ( !sibling->IsTopLevel() && sibling->IsShown() )                    {                        SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x ,  sibling->m_y + sibling->m_height - m_y ) ;                        if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) )                        {                            int borderTop = 14 ;                            int borderOther = 4 ;                            if ( UMAGetSystemVersion() >= 0x1030 )                                borderTop += 2 ;                            SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ;                            DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;                        }                        DiffRgn( visRgn , tempRgn , visRgn ) ;                    }                }            }        }    }    m_macVisibleRegion = visRgn ;    DisposeRgn( visRgn ) ;    DisposeRgn( tempRgn ) ;    DisposeRgn( tempStaticBoxRgn ) ;    return m_macVisibleRegion ;}void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase){    RgnHandle updatergn = (RgnHandle) updatergnr ;    // updatergn is always already clipped to our boundaries    // it is in window coordinates, not in client coordinates    WindowRef window = (WindowRef) MacGetRootWindow() ;    {        // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates        RgnHandle ownUpdateRgn = NewRgn() ;        CopyRgn( updatergn , ownUpdateRgn ) ;        SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;        // newupdate is the update region in client coordinates        RgnHandle newupdate = NewRgn() ;        wxSize point = GetClientSize() ;        wxPoint origin = GetClientAreaOrigin() ;        SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;        SectRgn( newupdate , ownUpdateRgn , newupdate ) ;        OffsetRgn( newupdate , -origin.x , -origin.y ) ;        m_updateRegion = newupdate ;        DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion        if ( erase && !EmptyRgn(ownUpdateRgn) )        {            wxWindowDC dc(this);            if (!EmptyRgn(ownUpdateRgn))                dc.SetClippingRegion(wxRegion(ownUpdateRgn));            wxEraseEvent eevent( GetId(), &dc );            eevent.SetEventObject( this );            GetEventHandler()->ProcessEvent( eevent );            wxNcPaintEvent eventNc( GetId() );            eventNc.SetEventObject( this );            GetEventHandler()->ProcessEvent( eventNc );        }        DisposeRgn( ownUpdateRgn ) ;        if ( !m_updateRegion.Empty() )        {            wxWindowList hiddenWindows ;            for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())            {                wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ;                if ( child && child->MacGetRootWindow() == (WXWindow) window && child->IsShown() && child->GetMacControl() )                {                    SetControlVisibility( (ControlHandle) child->GetMacControl() , false , false ) ;                    hiddenWindows.Append( child ) ;                }            }            wxPaintEvent event;            event.SetTimestamp(time);            event.SetEventObject(this);            GetEventHandler()->ProcessEvent(event);            for (wxWindowListNode *node = hiddenWindows.GetFirst(); node; node = node->GetNext())            {                wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ;                if ( child && child->GetMacControl() )                {                    SetControlVisibility( (ControlHandle) child->GetMacControl() , true , false ) ;                }            }        }    }    // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively    RgnHandle childupdate = NewRgn() ;    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())    {        // calculate the update region for the child windows by intersecting the window rectangle with our own        // passed in update region and then offset it to be client-wise window coordinates again        wxWindowMac *child = node->GetData();        SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width ,  child->m_y + child->m_height ) ;        SectRgn( childupdate , updatergn , childupdate ) ;        OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;        if ( child->MacGetRootWindow() == (WXWindow) window && child->IsShown() && !EmptyRgn( childupdate ) )        {            // because dialogs may also be children            child->MacRedraw( childupdate , time , erase ) ;        }    }    DisposeRgn( childupdate ) ;    // eventually a draw grow box here}WXWindow wxWindowMac::MacGetRootWindow() const{    wxWindowMac *iter = (wxWindowMac*)this ;    while( iter )    {        if ( iter->IsTopLevel() )            return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;        iter = iter->GetParent() ;    }    wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;    return NULL ;}void wxWindowMac::MacCreateScrollBars( long style ){    wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;    bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;    int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;    int width, height ;    GetClientSize( &width , &height ) ;    wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;    wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;    wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;    wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;    m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,        vSize , wxVERTICAL);    if ( style & wxVSCROLL )    {    }    else    {        m_vScrollBar->Show(false) ;    }    m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,        hSize , wxHORIZONTAL);    if ( style  & wxHSCROLL )    {    }    else    {        m_hScrollBar->Show(false) ;    }    // because the create does not take into account the client area origin    MacRepositionScrollBars() ; // we might have a real position shift}void wxWindowMac::MacRepositionScrollBars(){    bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;    int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;    // get real client area    int width = m_width ;    int height = m_height ;    width -= MacGetLeftBorderSize() + MacGetRightBorderSize();    height -= MacGetTopBorderSize() + MacGetBottomBorderSize();    wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;    wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;    wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;    wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;    int x = 0 ;    int y = 0 ;    int w = m_width ;    int h = m_height ;    MacClientToRootWindow( &x , &y ) ;    MacClientToRootWindow( &w , &h ) ;    wxWindowMac *iter = (wxWindowMac*)this ;    int totW = 10000 , totH = 10000;    while( iter )    {        if ( iter->IsTopLevel() )        {            totW = iter->m_width ;            totH = iter->m_height ;            break ;        }        iter = iter->GetParent() ;    }    if ( x == 0 )    {        hPoint.x = -1 ;        hSize.x += 1 ;    }    if ( y == 0 )    {        vPoint.y = -1 ;        vSize.y += 1 ;    }    if ( w-x >= totW )    {        hSize.x += 1 ;        vPoint.x += 1 ;    }    if ( h-y >= totH )    {        vSize.y += 1 ;        hPoint.y += 1 ;    }    if ( m_vScrollBar )    {        m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);    }    if ( m_hScrollBar )    {        m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);    }}bool wxWindowMac::AcceptsFocus() const{    return MacCanFocus() && wxWindowBase::AcceptsFocus();}WXWidget wxWindowMac::MacGetContainerForEmbedding(){    return GetParent()->MacGetContainerForEmbedding() ;}void wxWindowMac::MacSuperChangedPosition(){    // only window-absolute structures have to be moved i.e. controls    wxWindowListNode *node = GetChildren().GetFirst();    while ( node )    {        wxWindowMac *child = node->GetData();        child->MacSuperChangedPosition() ;        node = node->GetNext();    }}void wxWindowMac::MacTopLevelWindowChangedPosition(){    // only screen-absolute structures have to be moved i.e. glcanvas    wxWindowListNode *node = GetChildren().GetFirst();    while ( node )    {        wxWindowMac *child = node->GetData();        child->MacTopLevelWindowChangedPosition() ;        node = node->GetNext();    }}long wxWindowMac::MacGetLeftBorderSize( ) const{    if( IsTopLevel() )        return 0 ;    if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )    {        SInt32 border = 3 ;#if wxMAC_USE_THEME_BORDER#if TARGET_CARBON          GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;#endif#endif          return border ;    }    else if (  m_windowStyle &wxDOUBLE_BORDER)    {          SInt32 border = 3 ;#if wxMAC_USE_THEME_BORDER#if TARGET_CARBON          GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;#endif#endif          return border ;    }    else if (m_windowStyle &wxSIMPLE_BORDER)    {        return 1 ;    }    return 0 ;}long wxWindowMac::MacGetRightBorderSize( ) const{    // they are all symmetric in mac themes    return MacGetLeftBorderSize() ;}long wxWindowMac::MacGetTopBorderSize( ) const{    // they are all symmetric in mac themes    return MacGetLeftBorderSize() ;}long wxWindowMac::MacGetBottomBorderSize( ) const{    // they are all symmetric in mac themes    return MacGetLeftBorderSize() ;}long wxWindowMac::MacRemoveBordersFromStyle( long style ){    return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;}// Find the wxWindowMac at the current mouse position, returning the mouse// position.wxWindowMac* wxFindWindowAtPointer(wxPoint& pt){    pt = wxGetMousePosition();    wxWindowMac* found = wxFindWindowAtPoint(pt);    return found;}// Get the current mouse position.wxPoint wxGetMousePosition(){    int x, y;    wxGetMousePosition(& x, & y);    return wxPoint(x, y);}void wxWindowMac::OnMouseEvent( wxMouseEvent &event ){    if ( event.GetEventType() == wxEVT_RIGHT_DOWN )    {        // copied from wxGTK : CS        // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN        // except that:        //        // (a) it's a command event and so is propagated to the parent        // (b) under MSW it can be generated from kbd too        // (c) it uses screen coords (because of (a))        wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,                                  this->GetId(),                                  this->ClientToScreen(event.GetPosition()));        if ( ! GetEventHandler()->ProcessEvent(evtCtx) )            event.Skip() ;    }    else    {        event.Skip() ;    }}

⌨️ 快捷键说明

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