📄 window.cpp
字号:
{
WindowRef window = (WindowRef) MacGetRootWindow() ;
if ( x )
*x += MacGetLeftBorderSize() ;
if ( y )
*y += MacGetTopBorderSize() ;
MacWindowToRootWindow( x , y ) ;
Point localwhere = { 0,0 };
if(x) localwhere.h = * x ;
if(y) localwhere.v = * y ;
GrafPtr port ;
::GetPort( &port ) ;
::SetPort( UMAGetWindowPort( window ) ) ;
::LocalToGlobal( &localwhere ) ;
::SetPort( port ) ;
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
{
wxPoint origin = GetClientAreaOrigin() ;
MacRootWindowToWindow( x , y ) ;
if(x) *x -= origin.x ;
if(y) *y -= origin.y ;
}
void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
{
if ( !IsTopLevel() )
{
if(x) *x += m_x ;
if(y) *y += m_y ;
GetParent()->MacWindowToRootWindow( x , y ) ;
}
}
void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
{
if ( !IsTopLevel() )
{
if(x) *x -= m_x ;
if(y) *y -= m_y ;
GetParent()->MacRootWindowToWindow( x , y ) ;
}
}
bool wxWindowMac::SetCursor(const wxCursor& cursor)
{
if (m_cursor == cursor)
return false;
if (wxNullCursor == cursor)
{
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"));
Point pt ;
wxWindowMac *mouseWin ;
GetMouse( &pt ) ;
// Change the cursor NOW if we're within the correct window
if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
{
if ( mouseWin == this && !wxIsBusy() )
{
m_cursor.MacInstall() ;
}
}
return true ;
}
// Get size *available for subwindows* i.e. excluding menu bar etc.
void wxWindowMac::DoGetClientSize(int *x, int *y) const
{
int ww, hh;
ww = m_width ;
hh = m_height ;
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_TOOLTIPS
void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
{
wxWindowBase::DoSetToolTip(tooltip);
if ( m_tooltip )
m_tooltip->SetWindow(this);
}
#endif // wxUSE_TOOLTIPS
void 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/height
void 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
// smaller
wxPoint 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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -