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

📄 window.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// 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 scrollvoid 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 ) ;        if ( !EmptyRgn( formerUpdateRgn ) )        {            MacOffsetRgn( formerUpdateRgn , dx , dy ) ;            SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;            InvalWindowRgn(rootWindow  ,  formerUpdateRgn ) ;        }        InvalWindowRgn(rootWindow  ,  updateRgn ) ;        DisposeRgn( updateRgn ) ;        DisposeRgn( formerUpdateRgn ) ;        DisposeRgn( scrollRgn ) ;    }    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())    {        wxWindowMac *child = node->GetData();        if (child == m_vScrollBar) continue;        if (child == m_hScrollBar) continue;        if (child->IsTopLevel()) continue;        int x,y;        child->GetPosition( &x, &y );        int w,h;        child->GetSize( &w, &h );        if (rect)        {            wxRect rc(x,y,w,h);            if (rect->Intersects(rc))                child->SetSize( x+dx, y+dy, w, h );        }        else        {            child->SetSize( x+dx, y+dy, w, h );        }    }    Update() ;}void wxWindowMac::MacOnScroll(wxScrollEvent &event ){    if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )    {        wxScrollWinEvent wevent;        wevent.SetPosition(event.GetPosition());        wevent.SetOrientation(event.GetOrientation());        wevent.SetEventObject(this);        if (event.GetEventType() == wxEVT_SCROLL_TOP)            wevent.SetEventType( wxEVT_SCROLLWIN_TOP );        else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)            wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );        else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)            wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );        else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)            wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );        else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)            wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );        else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)            wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );        else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)            wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );        else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)            wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );        GetEventHandler()->ProcessEvent(wevent);    }}// Get the window with the focuswxWindowMac *wxWindowBase::DoFindFocus(){    return gFocusWindow ;}void wxWindowMac::OnSetFocus(wxFocusEvent& event){    // panel wants to track the window which was the last to have focus in it,    // so we want to set ourselves as the window which last had focus    //    // notice that it's also important to do it upwards the tree becaus    // otherwise when the top level panel gets focus, it won't set it back to    // us, but to some other sibling    // CS:don't know if this is still needed:    //wxChildFocusEvent eventFocus(this);    //(void)GetEventHandler()->ProcessEvent(eventFocus);    event.Skip();}// Setup background and foreground colours correctlyvoid wxWindowMac::SetupColours(){    if ( GetParent() )        SetBackgroundColour(GetParent()->GetBackgroundColour());}void wxWindowMac::OnInternalIdle(){    // This calls the UI-update mechanism (querying windows for    // menu/toolbar/control state information)    if (wxUpdateUIEvent::CanUpdate(this))        UpdateWindowUI(wxUPDATE_UI_FROMIDLE);}// Raise the window to the top of the Z ordervoid wxWindowMac::Raise(){}// Lower the window to the bottom of the Z ordervoid wxWindowMac::Lower(){}void wxWindowMac::DoSetClientSize(int width, int height){    if ( width != -1 || height != -1 )    {        if ( width != -1 && m_vScrollBar )            width += MAC_SCROLLBAR_SIZE ;        if ( height != -1 && m_vScrollBar )            height += MAC_SCROLLBAR_SIZE ;        width += MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ;        height += MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ;        DoSetSize( -1 , -1 , width , height ) ;    }}wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ;bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ){    if ( IsTopLevel() )    {        if ((point.x < 0) || (point.y < 0) ||            (point.x > (m_width)) || (point.y > (m_height)))            return false;    }    else    {        if ((point.x < m_x) || (point.y < m_y) ||            (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))            return false;    }    WindowRef window = (WindowRef) MacGetRootWindow() ;    wxPoint newPoint( point ) ;    if ( !IsTopLevel() )    {        newPoint.x -= m_x;        newPoint.y -= m_y;    }    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())    {        wxWindowMac *child = node->GetData();        // added the m_isShown test --dmazzoni        if ( child->MacGetRootWindow() == (WXWindow) window && child->m_isShown )        {            if (child->MacGetWindowFromPointSub(newPoint , outWin ))                return true;        }    }    *outWin = this ;    return true;}bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ){    WindowRef window ;    Point pt = { screenpoint.y , screenpoint.x } ;    if ( ::FindWindow( pt , &window ) == 3 )    {        wxWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ;        if ( win )        {            // No, this yields the CLIENT are, we need the whole frame. RR.            // point = win->ScreenToClient( point ) ;            GrafPtr     port;            ::GetPort( &port ) ;            ::SetPort( UMAGetWindowPort( window ) ) ;            ::GlobalToLocal( &pt ) ;            ::SetPort( port ) ;            wxPoint point( pt.h, pt.v ) ;            return win->MacGetWindowFromPointSub( point , outWin ) ;        }    }    return false ;}static wxWindow *gs_lastWhich = NULL;bool wxWindowMac::MacSetupCursor( const wxPoint& pt){    // first trigger a set cursor event    wxPoint clientorigin = GetClientAreaOrigin() ;    wxSize clientsize = GetClientSize() ;    wxCursor cursor ;    if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )    {        wxSetCursorEvent event( pt.x , pt.y );        bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);        if ( processedEvtSetCursor && event.HasCursor() )        {            cursor = event.GetCursor() ;        }        else        {            // the test for processedEvtSetCursor is here to prevent using m_cursor            // if the user code caught EVT_SET_CURSOR() and returned nothing from            // it - this is a way to say that our cursor shouldn't be used for this            // point            if ( !processedEvtSetCursor && m_cursor.Ok() )            {                cursor = m_cursor ;            }            if ( wxIsBusy() )            {            }            else            {                if ( !GetParent() )                    cursor = *wxSTANDARD_CURSOR  ;            }        }        if ( cursor.Ok() )            cursor.MacInstall() ;    }    return cursor.Ok() ;}bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event){    if ((event.m_x < m_x) || (event.m_y < m_y) ||        (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))        return false;    if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)        return false ;    WindowRef window = (WindowRef) MacGetRootWindow() ;    event.m_x -= m_x;    event.m_y -= m_y;    int x = event.m_x ;    int y = event.m_y ;    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())    {        wxWindowMac *child = node->GetData();        if ( child->MacGetRootWindow() == (WXWindow) window && child->IsShown() && child->IsEnabled() )        {            if (child->MacDispatchMouseEvent(event))                return true;        }    }    wxWindow* cursorTarget = this ;    wxPoint cursorPoint( x , y ) ;    while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )    {        cursorTarget = cursorTarget->GetParent() ;        if ( cursorTarget )            cursorPoint += cursorTarget->GetPosition() ;    }    event.m_x = x ;    event.m_y = y ;    event.SetEventObject( this ) ;    if ( event.GetEventType() == wxEVT_LEFT_DOWN )    {        // set focus to this window        if (AcceptsFocus() && FindFocus()!=this)            SetFocus();    }#if wxUSE_TOOLTIPS    if ( event.GetEventType() == wxEVT_MOTION        || event.GetEventType() == wxEVT_ENTER_WINDOW        || event.GetEventType() == wxEVT_LEAVE_WINDOW )        wxToolTip::RelayEvent( this , event);#endif // wxUSE_TOOLTIPS    if (gs_lastWhich != this)    {        gs_lastWhich = this;        // Double clicks must always occur on the same window        if (event.GetEventType() == wxEVT_LEFT_DCLICK)            event.SetEventType( wxEVT_LEFT_DOWN );        if (event.GetEventType() == wxEVT_RIGHT_DCLICK)            event.SetEventType( wxEVT_RIGHT_DOWN );        // Same for mouse up events        if (event.GetEventType() == wxEVT_LEFT_UP)

⌨️ 快捷键说明

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