📄 window.cpp
字号:
ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) { int x1 = 0 ; int y1 = 0 ; int w = m_width ; int h = m_height ; MacClientToRootWindow( &x1 , &y1 ) ; 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 (m_hScrollBar && m_hScrollBar->IsShown() ) { hh -= MAC_SCROLLBAR_SIZE; if ( h-y1 >= totH ) { hh += 1 ; } } if (m_vScrollBar && m_vScrollBar->IsShown() ) { ww -= MAC_SCROLLBAR_SIZE; if ( w-x1 >= totW ) { ww += 1 ; } } } if(x) *x = ww; if(y) *y = hh;}// ----------------------------------------------------------------------------// tooltips// ----------------------------------------------------------------------------#if wxUSE_TOOLTIPSvoid wxWindowMac::DoSetToolTip(wxToolTip *tooltip){ wxWindowBase::DoSetToolTip(tooltip); if ( m_tooltip ) m_tooltip->SetWindow(this);}#endif // wxUSE_TOOLTIPSvoid wxWindowMac::DoMoveWindow(int x, int y, int width, int height){ int former_x = m_x ; int former_y = m_y ; int former_w = m_width ; int former_h = m_height ; int actualWidth = width; int actualHeight = height; int actualX = x; int actualY = y; if ((m_minWidth != -1) && (actualWidth < m_minWidth)) actualWidth = m_minWidth; if ((m_minHeight != -1) && (actualHeight < m_minHeight)) actualHeight = m_minHeight; if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) actualWidth = m_maxWidth; if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) actualHeight = m_maxHeight; bool doMove = false ; bool doResize = false ; if ( actualX != former_x || actualY != former_y ) { doMove = true ; } if ( actualWidth != former_w || actualHeight != former_h ) { doResize = true ; } if ( doMove || doResize ) { // erase former position bool partialRepaint = false ; if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) { wxPoint oldPos( m_x , m_y ) ; wxPoint newPos( actualX , actualY ) ; MacWindowToRootWindow( &oldPos.x , &oldPos.y ) ; MacWindowToRootWindow( &newPos.x , &newPos.y ) ; if ( oldPos == newPos ) { partialRepaint = true ; RgnHandle oldRgn,newRgn,diffRgn ; oldRgn = NewRgn() ; newRgn = NewRgn() ; diffRgn = NewRgn() ; // invalidate the differences between the old and the new area SetRectRgn(oldRgn , oldPos.x , oldPos.y , oldPos.x + m_width , oldPos.y + m_height ) ; SetRectRgn(newRgn , newPos.x , newPos.y , newPos.x + actualWidth , newPos.y + actualHeight ) ; DiffRgn( newRgn , oldRgn , diffRgn ) ; InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; DiffRgn( oldRgn , newRgn , diffRgn ) ; InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really // changing pixels... if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 || MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 ) { RgnHandle innerOldRgn, innerNewRgn ; innerOldRgn = NewRgn() ; innerNewRgn = NewRgn() ; SetRectRgn(innerOldRgn , oldPos.x + MacGetLeftBorderSize() , oldPos.y + MacGetTopBorderSize() , oldPos.x + m_width - MacGetRightBorderSize() , oldPos.y + m_height - MacGetBottomBorderSize() ) ; DiffRgn( oldRgn , innerOldRgn , diffRgn ) ; InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; SetRectRgn(innerNewRgn , newPos.x + MacGetLeftBorderSize() , newPos.y + MacGetTopBorderSize() , newPos.x + actualWidth - MacGetRightBorderSize() , newPos.y + actualHeight - MacGetBottomBorderSize() ) ; DiffRgn( newRgn , innerNewRgn , diffRgn ) ; InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; DisposeRgn( innerOldRgn ) ; DisposeRgn( innerNewRgn ) ; } DisposeRgn(oldRgn) ; DisposeRgn(newRgn) ; DisposeRgn(diffRgn) ; } } if ( !partialRepaint ) Refresh() ; m_x = actualX ; m_y = actualY ; m_width = actualWidth ; m_height = actualHeight ; // update any low-level frame-relative positions MacUpdateDimensions() ; // erase new position if ( !partialRepaint ) Refresh() ; if ( doMove ) wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified MacRepositionScrollBars() ; if ( doMove ) { wxPoint point(m_x, m_y); wxMoveEvent event(point, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event) ; } if ( doResize ) { MacRepositionScrollBars() ; wxSize size(m_width, m_height); wxSizeEvent event(size, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } }}// set the size of the window: if the dimensions are positive, just use them,// but if any of them is equal to -1, it means that we must find the value for// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in// which case -1 is a valid value for x and y)//// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate// the width/height to best suit our contents, otherwise we reuse the current// width/heightvoid wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags){ // get the current size and position... int currentX, currentY; GetPosition(¤tX, ¤tY); int currentW,currentH; GetSize(¤tW, ¤tH); // ... and don't do anything (avoiding flicker) if it's already ok if ( x == currentX && y == currentY && width == currentW && height == currentH ) { MacRepositionScrollBars() ; // we might have a real position shift return; } if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) x = currentX; if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) y = currentY; AdjustForParentClientOrigin(x, y, sizeFlags); wxSize size(-1, -1); if ( width == -1 ) { if ( sizeFlags & wxSIZE_AUTO_WIDTH ) { size = DoGetBestSize(); width = size.x; } else { // just take the current one width = currentW; } } if ( height == -1 ) { if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) { if ( size.x == -1 ) { size = DoGetBestSize(); } //else: already called DoGetBestSize() above height = size.y; } else { // just take the current one height = currentH; } } DoMoveWindow(x, y, width, height);}// For implementation purposes - sometimes decorations make the client area// smallerwxPoint wxWindowMac::GetClientAreaOrigin() const{ return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );}void wxWindowMac::SetLabel(const wxString& label){ m_label = label ;}wxString wxWindowMac::GetLabel() const{ return m_label ;}bool wxWindowMac::Show(bool show){ if ( !wxWindowBase::Show(show) ) return false; MacSuperShown( show ) ; Refresh() ; return true;}void wxWindowMac::MacSuperShown( bool show ){ wxWindowListNode *node = GetChildren().GetFirst(); while ( node ) { wxWindowMac *child = node->GetData(); if ( child->m_isShown ) child->MacSuperShown( show ) ; node = node->GetNext(); }}void wxWindowMac::MacSuperEnabled( bool enabled ){ if ( !IsTopLevel() ) { // to be absolutely correct we'd have to invalidate (with eraseBkground // because unter MacOSX the frames are drawn with an addXXX mode) // the borders area } wxWindowListNode *node = GetChildren().GetFirst(); 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 windowvoid 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -