📄 window.cpp
字号:
const wxPoint& pos, const wxSize& size, int& x, int& y, int& w, int& h , bool adjustOrigin ) const{ // the desired size, minus the border pixels gives the correct size of the control x = (int)pos.x; y = (int)pos.y; // TODO: the default calls may be used as soon as PostCreateControl Is moved here w = wxMax(size.x, 0) ; // WidthDefault( size.x ); h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ; x += MacGetLeftBorderSize() ; y += MacGetTopBorderSize() ; w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; if ( adjustOrigin ) AdjustForParentClientOrigin( x , y ) ; // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border if ( !GetParent()->IsTopLevel() ) { x -= GetParent()->MacGetLeftBorderSize() ; y -= GetParent()->MacGetTopBorderSize() ; } return true ;}// Get window size (not client size)void wxWindowMac::DoGetSize(int *x, int *y) const{ Rect bounds ; m_peer->GetRect( &bounds ) ; if (x) *x = bounds.right - bounds.left + MacGetLeftBorderSize() + MacGetRightBorderSize() ; if (y) *y = bounds.bottom - bounds.top + MacGetTopBorderSize() + MacGetBottomBorderSize() ;}// get the position of the bounds of this window in client coordinates of its parentvoid wxWindowMac::DoGetPosition(int *x, int *y) const{ Rect bounds ; m_peer->GetRect( &bounds ) ; int x1 = bounds.left ; int y1 = bounds.top ; // get the wx window position from the native one x1 -= MacGetLeftBorderSize() ; y1 -= MacGetTopBorderSize() ; if ( !IsTopLevel() ) { wxWindow *parent = GetParent(); if ( parent ) { // we must first adjust it to be in window coordinates of the parent, // as otherwise it gets lost by the ClientAreaOrigin fix x1 += parent->MacGetLeftBorderSize() ; y1 += parent->MacGetTopBorderSize() ; // and now to client coordinates wxPoint pt(parent->GetClientAreaOrigin()); x1 -= pt.x ; y1 -= pt.y ; } } if (x) *x = x1 ; if (y) *y = y1 ;}void wxWindowMac::DoScreenToClient(int *x, int *y) const{ WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; wxCHECK_RET( window , wxT("TopLevel Window missing") ) ; Point localwhere = { 0, 0 } ; if (x) localwhere.h = *x ; if (y) localwhere.v = *y ; wxMacGlobalToLocal( window , &localwhere ) ; if (x) *x = localwhere.h ; if (y) *y = localwhere.v ; MacRootWindowToWindow( x , y ) ; wxPoint origin = GetClientAreaOrigin() ; if (x) *x -= origin.x ; if (y) *y -= origin.y ;}void wxWindowMac::DoClientToScreen(int *x, int *y) const{ WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; wxCHECK_RET( window , wxT("TopLevel window missing") ) ; wxPoint origin = GetClientAreaOrigin() ; if (x) *x += origin.x ; if (y) *y += origin.y ; MacWindowToRootWindow( x , y ) ; Point localwhere = { 0, 0 }; if (x) localwhere.h = *x ; if (y) localwhere.v = *y ; wxMacLocalToGlobal( window, &localwhere ) ; if (x) *x = localwhere.h ; if (y) *y = localwhere.v ;}void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const{ wxPoint origin = GetClientAreaOrigin() ; if (x) *x += origin.x ; if (y) *y += origin.y ; MacWindowToRootWindow( x , y ) ;}void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const{ MacRootWindowToWindow( x , y ) ; wxPoint origin = GetClientAreaOrigin() ; if (x) *x -= origin.x ; if (y) *y -= origin.y ;}void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const{ wxPoint pt ; if (x) pt.x = *x ; if (y) pt.y = *y ; if ( !IsTopLevel() ) { wxTopLevelWindowMac* top = MacGetTopLevelWindow(); if (top) { pt.x -= MacGetLeftBorderSize() ; pt.y -= MacGetTopBorderSize() ; wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; } } if (x) *x = (int) pt.x ; if (y) *y = (int) pt.y ;}void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const{ int x1 , y1 ; if (x) x1 = *x ; if (y) y1 = *y ; MacWindowToRootWindow( &x1 , &y1 ) ; if (x) *x = x1 ; if (y) *y = y1 ;}void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const{ wxPoint pt ; if (x) pt.x = *x ; if (y) pt.y = *y ; if ( !IsTopLevel() ) { wxTopLevelWindowMac* top = MacGetTopLevelWindow(); if (top) { wxMacControl::Convert( &pt , top->m_peer , m_peer ) ; pt.x += MacGetLeftBorderSize() ; pt.y += MacGetTopBorderSize() ; } } if (x) *x = (int) pt.x ; if (y) *y = (int) pt.y ;}void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const{ int x1 , y1 ; if (x) x1 = *x ; if (y) y1 = *y ; MacRootWindowToWindow( &x1 , &y1 ) ; if (x) *x = x1 ; if (y) *y = y1 ;}void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ){ RgnHandle rgn = NewRgn() ; if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) { Rect structure, content ; GetRegionBounds( rgn , &content ) ; m_peer->GetRect( &structure ) ; OffsetRect( &structure, -structure.left , -structure.top ) ; left = content.left - structure.left ; top = content.top - structure.top ; right = structure.right - content.right ; bottom = structure.bottom - content.bottom ; } else { left = top = right = bottom = 0 ; } DisposeRgn( rgn ) ;}wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const{ wxSize sizeTotal = size; RgnHandle rgn = NewRgn() ; if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) { Rect content, structure ; GetRegionBounds( rgn , &content ) ; m_peer->GetRect( &structure ) ; // structure is in parent coordinates, but we only need width and height, so it's ok sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top) ; } DisposeRgn( rgn ) ; sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; return sizeTotal;}// Get size *available for subwindows* i.e. excluding menu bar etc.void wxWindowMac::DoGetClientSize( int *x, int *y ) const{ int ww, hh; RgnHandle rgn = NewRgn() ; Rect content ; if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) GetRegionBounds( rgn , &content ) ; else m_peer->GetRect( &content ) ; DisposeRgn( rgn ) ; ww = content.right - content.left ; hh = content.bottom - content.top ; if (m_hScrollBar && m_hScrollBar->IsShown() ) hh -= m_hScrollBar->GetSize().y ; if (m_vScrollBar && m_vScrollBar->IsShown() ) ww -= m_vScrollBar->GetSize().x ; if (x) *x = ww; if (y) *y = hh;}bool wxWindowMac::SetCursor(const wxCursor& cursor){ if (m_cursor.IsSameAs(cursor)) return false; if (!cursor.IsOk()) { if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) return false ; } else { if ( ! wxWindowBase::SetCursor( cursor ) ) return false ; } wxASSERT_MSG( m_cursor.Ok(), wxT("cursor must be valid after call to the base version")); wxWindowMac *mouseWin = 0 ; { wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ; WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ; ControlPartCode part ; ControlRef control ; Point pt ; #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 HIPoint hiPoint ; HIGetMousePosition(kHICoordSpaceWindow, window, &hiPoint); pt.h = hiPoint.x; pt.v = hiPoint.y; #else CGrafPtr savePort ; Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; // TODO: If we ever get a GetCurrentEvent... replacement // for the mouse position, use it... GetMouse( &pt ) ;#endif control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ; if ( control ) mouseWin = wxFindControlFromMacControl( control ) ;#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 if ( swapped ) QDSwapPort( savePort , NULL ) ;#endif } if ( mouseWin == this && !wxIsBusy() ) m_cursor.MacInstall() ; return true ;}#if wxUSE_MENUSbool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y){ menu->SetInvokingWindow(this); menu->UpdateUI(); if ( x == wxDefaultCoord && y == wxDefaultCoord ) { wxPoint mouse = wxGetMousePosition(); x = mouse.x; y = mouse.y; } else { ClientToScreen( &x , &y ) ; } menu->MacBeforeDisplay( true ) ; long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ; if ( HiWord(menuResult) != 0 ) { MenuCommand macid; GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); int id = wxMacCommandToId( macid ); wxMenuItem* item = NULL ; wxMenu* realmenu ; item = menu->FindItem( id, &realmenu ) ; if ( item ) { if (item->IsCheckable()) item->Check( !item->IsChecked() ) ; menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; } } menu->MacAfterDisplay( true ) ; menu->SetInvokingWindow( NULL ); return true;}#endif// ----------------------------------------------------------------------------// tooltips// ----------------------------------------------------------------------------#if wxUSE_TOOLTIPSvoid wxWindowMac::DoSetToolTip(wxToolTip *tooltip){ wxWindowBase::DoSetToolTip(tooltip); if ( m_tooltip ) m_tooltip->SetWindow(this);}#endifvoid wxWindowMac::MacInvalidateBorders(){ if ( m_peer == NULL ) return ; bool vis = MacIsReallyShown() ; if ( !vis ) return ; int outerBorder = MacGetLeftBorderSize() ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -