📄 window.cpp
字号:
brush.SetColour( newCol ) ;
MacSetBackgroundBrush( brush ) ;
MacUpdateControlFont() ;
return true ;
}
void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
{
m_macBackgroundBrush = brush ;
m_peer->SetBackground( brush ) ;
}
bool wxWindowMac::MacCanFocus() const
{
// TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
// CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
// but the value range is nowhere documented
Boolean keyExistsAndHasValidFormat ;
CFIndex fullKeyboardAccess = CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat );
if ( keyExistsAndHasValidFormat && fullKeyboardAccess > 0 )
{
return true ;
}
else
{
UInt32 features = 0 ;
m_peer->GetFeatures( &features ) ;
return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
}
}
void wxWindowMac::SetFocus()
{
if ( !AcceptsFocus() )
return ;
wxWindow* former = FindFocus() ;
if ( former == this )
return ;
// as we cannot rely on the control features to find out whether we are in full keyboard mode,
// we can only leave in case of an error
OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
if ( err == errCouldntSetFocus )
return ;
SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() );
#if !TARGET_API_MAC_OSX
// emulate carbon events when running under CarbonLib where they are not natively available
if ( former )
{
EventRef evRef = NULL ;
err = MacCreateEvent(
NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
kEventAttributeUserEvent , &evRef );
verify_noerr( err );
wxMacCarbonEvent cEvent( evRef ) ;
cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
wxMacWindowEventHandler( NULL , evRef , former ) ;
ReleaseEvent( evRef ) ;
}
// send new focus event
{
EventRef evRef = NULL ;
err = MacCreateEvent(
NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
kEventAttributeUserEvent , &evRef );
verify_noerr( err );
wxMacCarbonEvent cEvent( evRef ) ;
cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
wxMacWindowEventHandler( NULL , evRef , this ) ;
ReleaseEvent( evRef ) ;
}
#endif
}
void wxWindowMac::DoCaptureMouse()
{
wxApp::s_captureWindow = this ;
}
wxWindow * wxWindowBase::GetCapture()
{
return wxApp::s_captureWindow ;
}
void wxWindowMac::DoReleaseMouse()
{
wxApp::s_captureWindow = NULL ;
}
#if wxUSE_DRAG_AND_DROP
void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
{
if ( m_dropTarget != NULL )
delete m_dropTarget;
m_dropTarget = pDropTarget;
if ( m_dropTarget != NULL )
{
// TODO:
}
}
#endif
// Old-style File Manager Drag & Drop
void wxWindowMac::DragAcceptFiles(bool accept)
{
// TODO:
}
// Returns the size of the native control. In the case of the toplevel window
// this is the content area root control
void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
int& w, int& h) const
{
wxFAIL_MSG( wxT("Not currently supported") ) ;
}
// From a wx position / size calculate the appropriate size of the native control
bool wxWindowMac::MacGetBoundsForControl(
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 ) ;
bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ;
if ( !isCompositing )
GetParent()->MacWindowToRootWindow( &x , &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 parent
void 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 ;
QDGlobalToLocalPoint( GetWindowPort( 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 ;
QDLocalToGlobalPoint( GetWindowPort( 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -