📄 window.cpp
字号:
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 focus
wxWindowMac *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 correctly
void 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 order
void wxWindowMac::Raise()
{
}
// Lower the window to the bottom of the Z order
void 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)
return true;
if (event.GetEventType() == wxEVT_RIGHT_UP)
return true;
}
GetEventHandler()->ProcessEvent( event ) ;
return true;
}
wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
{
if ( m_tooltip )
{
return m_tooltip->GetTip() ;
}
return wxEmptyString ;
}
void wxWindowMac::Update()
{
wxRegion visRgn = MacGetVisibleRegion( false ) ;
int top = 0 , left = 0 ;
MacWindowToRootWindow( &left , &top ) ;
WindowRef rootWindow = (WindowRef) MacGetRootWindow() ;
RgnHandle updateRgn = NewRgn() ;
// getting the update region in macos local coordinates
GetWindowUpdateRgn( rootWindow , updateRgn ) ;
GrafPtr port ;
::GetPort( &port ) ;
::SetPort( UMAGetWindowPort( rootWindow ) ) ;
Point pt = {0,0} ;
LocalToGlobal( &pt ) ;
::SetPort( port ) ;
OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
// translate to window local coordinates
OffsetRgn( updateRgn , -left , -top ) ;
SectRgn( updateRgn , (RgnHandle) visRgn.GetWXHRGN() , updateRgn ) ;
MacRedraw( updateRgn , 0 , true ) ;
// for flushing and validating we need macos-local coordinates again
OffsetRgn( updateRgn , left , top ) ;
#if TARGET_API_MAC_CARBON
if ( QDIsPortBuffered( GetWindowPort( rootWindow ) ) )
{
QDFlushPortBuffer( GetWindowPort( rootWindow ) , updateRgn ) ;
}
#endif
ValidWindowRgn( rootWindow , updateRgn ) ;
DisposeRgn( updateRgn ) ;
}
wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
{
wxTopLevelWindowMac* win = NULL ;
WindowRef window = (WindowRef) MacGetRootWindow() ;
if ( window )
{
win = wxFindWinFromMacWindow( (WXWindow) window ) ;
}
return win ;
}
const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings )
{
RgnHandle visRgn = NewRgn() ;
RgnHandle tempRgn = NewRgn() ;
RgnHandle tempStaticBoxRgn = NewRgn() ;
if ( MacIsReallyShown() )
{
SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ;
//TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
{
int borderTop = 14 ;
int borderOther = 4 ;
if ( UMAGetSystemVersion() >= 0x1030 )
borderTop += 2 ;
SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ;
DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ;
}
if ( !IsTopLevel() )
{
wxWindow* parent = GetParent() ;
while( parent )
{
wxSize size = parent->GetSize() ;
int x , y ;
x = y = 0 ;
parent->MacWindowToRootWindow( &x, &y ) ;
MacRootWindowToWindow( &x , &y ) ;
SetRectRgn( tempRgn ,
x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
x + size.x - parent->MacGetRightBorderSize(),
y + size.y - parent->MacGetBottomBorderSize()) ;
SectRgn( visRgn , tempRgn , visRgn ) ;
if ( parent->IsTopLevel() )
break ;
parent = parent->GetParent() ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -