X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f1ae4143271ae63a17e052a1a471d16e9cd8c44..e421922f90186d0619a806d277a0a2182e61b5fb:/src/mac/window.cpp diff --git a/src/mac/window.cpp b/src/mac/window.cpp index 3dd198b369..1dc5b4e6ae 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -15,6 +15,7 @@ #include "wx/setup.h" #include "wx/menu.h" +#include "wx/window.h" #include "wx/dc.h" #include "wx/dcclient.h" #include "wx/utils.h" @@ -23,6 +24,8 @@ #include "wx/layout.h" #include "wx/dialog.h" #include "wx/listbox.h" +#include "wx/scrolbar.h" +#include "wx/statbox.h" #include "wx/button.h" #include "wx/settings.h" #include "wx/msgdlg.h" @@ -30,9 +33,7 @@ #include "wx/notebook.h" #include "wx/tabctrl.h" #include "wx/tooltip.h" -// TODO remove the line below, just for lookup-up convenience CS -#include "wx/mac/window.h" - +#include "wx/statusbr.h" #include "wx/menuitem.h" #include "wx/log.h" @@ -62,7 +63,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_IDLE(wxWindow::OnIdle) -// EVT_SCROLL(wxWindow::OnScroll) + EVT_SET_FOCUS(wxWindow::OnSetFocus) END_EVENT_TABLE() #endif @@ -107,11 +108,15 @@ void wxRemoveMacWindowAssociation(wxWindow *win) // constructors and such // ---------------------------------------------------------------------------- +WindowRef wxWindow::s_macWindowInUpdate = NULL; + void wxWindow::Init() { // generic InitBase(); + m_macEraseOnRedraw = true ; + // MSW specific m_doubleClickAllowed = 0; m_winCaptured = FALSE; @@ -129,6 +134,7 @@ void wxWindow::Init() m_isShown = TRUE; m_macWindowData = NULL ; + m_macEraseOnRedraw = true ; m_x = 0; m_y = 0 ; @@ -146,6 +152,20 @@ void wxWindow::Init() // Destructor wxWindow::~wxWindow() { + // deleting a window while it is shown invalidates the region + if ( IsShown() ) { + wxWindow* iter = this ; + while( iter ) { + if ( iter->m_macWindowData ) + { + Refresh() ; + break ; + } + iter = iter->GetParent() ; + + } + } + m_isBeingDeleted = TRUE; if ( s_lastMouseWindow == this ) @@ -192,7 +212,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, m_width = WidthDefault( size.x ); m_height = HeightDefault( size.y ) ; - if ( ! IsKindOf( CLASSINFO ( wxControl ) ) ) + if ( ! IsKindOf( CLASSINFO ( wxControl ) ) && ! IsKindOf( CLASSINFO( wxStatusBar ) ) ) { MacCreateScrollBars( style ) ; } @@ -202,6 +222,9 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, void wxWindow::SetFocus() { + if ( gFocusWindow == this ) + return ; + if ( AcceptsFocus() ) { if (gFocusWindow ) @@ -404,11 +427,19 @@ void wxWindow::MacRootWindowToClient( int *x , int *y ) const bool wxWindow::SetCursor(const wxCursor& cursor) { - if ( !wxWindowBase::SetCursor(cursor) ) - { - // no change + 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")); @@ -423,7 +454,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor) { if ( mouseWin == this && !wxIsBusy() ) { - cursor.MacInstall() ; + m_cursor.MacInstall() ; } } @@ -437,8 +468,8 @@ void wxWindow::DoGetClientSize(int *x, int *y) const *x = m_width ; *y = m_height ; - *x -= 2 * MacGetBorderSize( ) ; - *y -= 2 * MacGetBorderSize( ) ; + *x -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; + *y -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) { @@ -507,6 +538,14 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height) DoSetSize( x,y, width, height ) ; } +// 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 wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) { @@ -528,11 +567,49 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) actualX = currentX; if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualY = currentY; - if (width == -1) + + wxSize size( -1 , -1 ) ; + + if (width == -1 || height == -1 ) + { + size = DoGetBestSize() ; + } + + if ( width == -1 ) + { + if ( sizeFlags & wxSIZE_AUTO_WIDTH ) + { + actualWidth = size.x ; + if ( actualWidth == -1 ) + actualWidth = 80 ; + } + else + { actualWidth = currentW ; + } + } if (height == -1) + { + if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) + { + actualHeight = size.y ; + if ( actualHeight == -1 ) + actualHeight = 26 ; + } + else + { actualHeight = currentH ; + } + } + 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; if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) { MacRepositionScrollBars() ; // we might have a real position shift @@ -562,13 +639,12 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) else { // erase former position + wxMacDrawingHelper focus( this ) ; + if ( focus.Ok() ) { - wxMacDrawingClientHelper focus( this ) ; - if ( focus.Ok() ) - { - Rect clientrect = { 0 , 0 , m_height , m_width } ; - InvalWindowRect( GetMacRootWindow() , &clientrect ) ; - } + Rect clientrect = { 0 , 0 , m_height , m_width } ; + // ClipRect( &clientrect ) ; + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } m_x = actualX ; @@ -583,7 +659,8 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( doResize ) ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true); - // the OS takes care of invalidating and erasing + // the OS takes care of invalidating and erasing the new area + // we have erased the old one if ( IsKindOf( CLASSINFO( wxFrame ) ) ) { @@ -595,30 +672,35 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) else { // erase new position + { - wxMacDrawingClientHelper focus( this ) ; + wxMacDrawingHelper focus( this ) ; if ( focus.Ok() ) { Rect clientrect = { 0 , 0 , m_height , m_width } ; + // ClipRect( &clientrect ) ; InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } + if ( doMove ) wxWindow::MacSuperChangedPosition() ; // like this only children will be notified } MacRepositionScrollBars() ; if ( doMove ) { - wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); + wxPoint point(m_x, m_y); + wxMoveEvent event(point, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event) ; } if ( doResize ) { - MacRepositionScrollBars() ; - wxSizeEvent event(wxSize(m_width, m_height), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + MacRepositionScrollBars() ; + wxSize size(m_width, m_height); + wxSizeEvent event(size, m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); } } } @@ -627,7 +709,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxPoint wxWindow::GetClientAreaOrigin() const { - return wxPoint(MacGetBorderSize( ) , MacGetBorderSize( ) ); + return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) ); } // Makes an adjustment to the window position (for example, a frame that has @@ -677,7 +759,8 @@ bool wxWindow::Show(bool show) UMASelectWindow( m_macWindowData->m_macWindow ) ; // no need to generate events here, they will get them triggered by macos // actually they should be , but apparently they are not - wxSizeEvent event(wxSize(m_width, m_height), m_windowId); + wxSize size(m_width, m_height); + wxSizeEvent event(size, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } @@ -688,8 +771,6 @@ bool wxWindow::Show(bool show) } MacSuperShown( show ) ; Refresh() ; - if(m_macWindowData) - MacUpdateImmediately() ; return TRUE; } @@ -706,6 +787,24 @@ void wxWindow::MacSuperShown( bool show ) } } +bool wxWindow::MacIsReallyShown() const +{ + if ( m_isShown && (m_parent != NULL) ) { + return m_parent->MacIsReallyShown(); + } + return m_isShown; +/* + bool status = m_isShown ; + wxWindow * win = this ; + while ( status && win->m_parent != NULL ) + { + win = win->m_parent ; + status = win->m_isShown ; + } + return status ; +*/ +} + int wxWindow::GetCharHeight() const { wxClientDC dc ( (wxWindow*)this ) ; @@ -725,9 +824,9 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, if ( !fontToUse ) fontToUse = &m_font; - wxClientDC dc( this ) ; + wxClientDC dc( (wxWindow*) this ) ; long lx,ly,ld,le ; - dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ; + dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; if ( externalLeading ) *externalLeading = le ; if ( descent ) @@ -740,6 +839,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, void wxWindow::MacEraseBackground( Rect *rect ) { +/* WindowRef window = GetMacRootWindow() ; if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) { @@ -807,15 +907,19 @@ void wxWindow::MacEraseBackground( Rect *rect ) } } } +*/ } void wxWindow::Refresh(bool eraseBack, const wxRect *rect) { +// if ( !IsShown() ) +// return ; + wxMacDrawingHelper focus( this ) ; if ( focus.Ok() ) { Rect clientrect = { 0 , 0 , m_height , m_width } ; - ClipRect( &clientrect ) ; + // ClipRect( &clientrect ) ; if ( rect ) { @@ -824,6 +928,10 @@ void wxWindow::Refresh(bool eraseBack, const wxRect *rect) } InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } + if ( !eraseBack ) + m_macEraseOnRedraw = false ; + else + m_macEraseOnRedraw = true ; } // Responds to colour changes: passes event on to children. @@ -999,8 +1107,8 @@ void wxWindow::MacCreateRealWindow( const wxString& title, // translate the window attributes in the appropriate window class and attributes - WindowClass wclass ; - WindowAttributes attr ; + WindowClass wclass = 0; + WindowAttributes attr = kWindowNoAttributes ; if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) ) { @@ -1010,35 +1118,22 @@ void wxWindow::MacCreateRealWindow( const wxString& title, attr |= kWindowSideTitlebarAttribute ; } } - else if ( HasFlag( wxTHICK_FRAME ) ) + else if ( HasFlag( wxCAPTION ) ) { if ( HasFlag( wxDIALOG_MODAL ) ) { wclass = kMovableModalWindowClass ; } - else if ( HasFlag( wxDIALOG_MODELESS ) ) + else { wclass = kDocumentWindowClass ; } - else - { - if ( HasFlag( wxCAPTION ) ) - { - wclass = kDocumentWindowClass ; - } - else - { - wclass = kModalWindowClass ; - } - } } else { wclass = kModalWindowClass ; } - attr = kWindowNoAttributes ; - if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) { attr |= kWindowFullZoomAttribute ; @@ -1064,6 +1159,7 @@ void wxWindow::MacCreateRealWindow( const wxString& title, UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; m_macWindowData->m_macFocus = NULL ; + m_macWindowData->m_macHasReceivedFirstActivate = true ; } void wxWindow::MacPaint( wxPaintEvent &event ) @@ -1200,7 +1296,7 @@ void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, { if ( !m_hScrollBar->IsShown() ) m_hScrollBar->Show(true) ; - m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ; + m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; } } } @@ -1217,7 +1313,7 @@ void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, { if ( !m_vScrollBar->IsShown() ) m_vScrollBar->Show(true) ; - m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ; + m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; } } } @@ -1246,6 +1342,20 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) InvalWindowRgn( GetMacRootWindow() , updateRgn ) ; DisposeRgn( updateRgn ) ; } + + for (wxNode *node = GetChildren().First(); node; node = node->Next()) + { + wxWindow *child = (wxWindow*)node->Data(); + 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 ); + child->SetSize( x+dx, y+dy, w, h ); + } + } void wxWindow::MacOnScroll(wxScrollEvent &event ) @@ -1257,36 +1367,26 @@ void wxWindow::MacOnScroll(wxScrollEvent &event ) wevent.SetOrientation(event.GetOrientation()); wevent.m_eventObject = this; - switch ( event.m_eventType ) - { - case wxEVT_SCROLL_TOP: + if (event.m_eventType == wxEVT_SCROLL_TOP) { wevent.m_eventType = wxEVT_SCROLLWIN_TOP; - break; - - case wxEVT_SCROLL_BOTTOM: + } else + if (event.m_eventType == wxEVT_SCROLL_BOTTOM) { wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; - break; - - case wxEVT_SCROLL_LINEUP: + } else + if (event.m_eventType == wxEVT_SCROLL_LINEUP) { wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; - break; - - case wxEVT_SCROLL_LINEDOWN: + } else + if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) { wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; - break; - - case wxEVT_SCROLL_PAGEUP: + } else + if (event.m_eventType == wxEVT_SCROLL_PAGEUP) { wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; - break; - - case wxEVT_SCROLL_PAGEDOWN: + } else + if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) { wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; - break; - - case wxEVT_SCROLL_THUMBTRACK: + } else + if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) { wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; - break; - } GetEventHandler()->ProcessEvent(wevent); @@ -1341,6 +1441,30 @@ wxObject* wxWindow::GetChild(int number) const } #endif // WXWIN_COMPATIBILITY +void wxWindow::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 + wxWindow *win = this; + while ( win ) + { + wxWindow *parent = win->GetParent(); + wxPanel *panel = wxDynamicCast(parent, wxPanel); + if ( panel ) + { + panel->SetLastFocus(win); + } + + win = parent; + } + + event.Skip(); +} + void wxWindow::Clear() { if ( m_macWindowData ) @@ -1394,13 +1518,19 @@ void wxWindow::OnIdle(wxIdleEvent& event) // Raise the window to the top of the Z order void wxWindow::Raise() { - // TODO + if ( m_macWindowData ) + { + UMABringToFront( m_macWindowData->m_macWindow ) ; + } } // Lower the window to the bottom of the Z order void wxWindow::Lower() { - // TODO + if ( m_macWindowData ) + { + UMASendBehind( m_macWindowData->m_macWindow , NULL ) ; + } } void wxWindow::DoSetClientSize(int width, int height) @@ -1413,8 +1543,8 @@ void wxWindow::DoSetClientSize(int width, int height) if ( height != -1 && m_vScrollBar ) height += MAC_SCROLLBAR_SIZE ; - width += 2 * MacGetBorderSize( ) ; - height += 2 * MacGetBorderSize( ) ; + width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; + height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; DoSetSize( -1 , -1 , width , height ) ; } @@ -1439,7 +1569,8 @@ bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWi for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); - if ( child->GetMacRootWindow() == window ) + // added the m_isShown test --dmazzoni + if ( child->GetMacRootWindow() == window && child->m_isShown ) { if (child->MacGetWindowFromPointSub(newPoint , outWin )) return TRUE; @@ -1458,9 +1589,12 @@ bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** ou { wxPoint point( screenpoint ) ; wxWindow* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + { win->ScreenToClient( point ) ; return win->MacGetWindowFromPointSub( point , outWin ) ; } + } return FALSE ; } @@ -1501,6 +1635,13 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) { m_cursor.MacInstall() ; } + + if ( event.GetEventType() == wxEVT_LEFT_DOWN ) + { + // set focus to this window + if (AcceptsFocus() && FindFocus()!=this) + SetFocus(); + } #if wxUSE_TOOLTIPS if ( event.GetEventType() == wxEVT_MOTION @@ -1576,8 +1717,12 @@ void wxWindow::MacFireMouseEvent( EventRecord *ev ) else event.SetEventType(wxEVT_LEFT_DCLICK ) ; } + lastWhen = 0 ; + } + else + { + lastWhen = ev->when ; } - lastWhen = ev->when ; lastWhere = localwhere ; } @@ -1650,19 +1795,27 @@ void wxWindow::MacMouseMoved( EventRecord *ev , short part) } void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating ) { - wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating); + if ( !m_macWindowData->m_macHasReceivedFirstActivate ) + m_macWindowData->m_macHasReceivedFirstActivate = true ; + + wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); event.m_timeStamp = ev->when ; event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); + Refresh(false) ; UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ; +// MacUpdateImmediately() ; } void wxWindow::MacRedraw( RgnHandle updatergn , long time) { // updatergn is always already clipped to our boundaries WindowRef window = GetMacRootWindow() ; + // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children + RgnHandle ownUpdateRgn = NewRgn() ; + CopyRgn( updatergn , ownUpdateRgn ) ; wxWindow* win = wxFindWinFromMacWindow( window ) ; { wxMacDrawingHelper focus( this ) ; // was client @@ -1727,22 +1880,45 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) { RGBBackColor( &m_backgroundColour.GetPixel()) ; } + // subtract all non transparent children from updatergn + + RgnHandle childarea = NewRgn() ; + for (wxNode *node = GetChildren().First(); node; node = node->Next()) + { + wxWindow *child = (wxWindow*)node->Data(); + // eventually test for transparent windows + if ( child->GetMacRootWindow() == window && child->IsShown() ) + { + if ( child->GetBackgroundColour() != m_backgroundColour && !child->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)child)->GetMacControl() ) + { + SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; + DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ; + } + } + } + DisposeRgn( childarea ) ; + if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() ) eraseBackground = true ; - SetClip( updatergn ) ; - if ( eraseBackground ) - { - EraseRgn( updatergn ) ; - } + SetClip( ownUpdateRgn ) ; + if ( m_macEraseOnRedraw ) { + if ( eraseBackground ) + { + EraseRgn( ownUpdateRgn ) ; + } + } + else { + m_macEraseOnRedraw = true ; + } } - m_macUpdateRgn = updatergn ; { RgnHandle newupdate = NewRgn() ; wxSize point = GetClientSize() ; wxPoint origin = GetClientAreaOrigin() ; + SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; - SectRgn( newupdate , m_macUpdateRgn , newupdate ) ; + SectRgn( newupdate , ownUpdateRgn , newupdate ) ; OffsetRgn( newupdate , -origin.x , -origin.y ) ; m_updateRegion = newupdate ; DisposeRgn( newupdate ) ; @@ -1754,18 +1930,15 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } - { - } - RgnHandle childupdate = NewRgn() ; - + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; - SectRgn( childupdate , m_macUpdateRgn , childupdate ) ; + SectRgn( childupdate , updatergn , childupdate ) ; OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) { @@ -1799,7 +1972,7 @@ void wxWindow::MacUpdateImmediately() GetPortVisibleRegion( GetWindowPort( window ), region ); // if windowshade gives incompatibility , take the follwing out - if ( !EmptyRgn( region ) ) + if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate ) { win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ; } @@ -1830,7 +2003,7 @@ void wxWindow::MacUpdate( EventRecord *ev ) GetPortVisibleRegion( GetWindowPort( window ), region ); // if windowshade gives incompatibility , take the follwing out - if ( !EmptyRgn( region ) ) + if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate ) { MacRedraw( region , ev->when ) ; } @@ -1905,8 +2078,8 @@ void wxWindow::MacRepositionScrollBars() int width = m_width ; int height = m_height ; - width -= 2 * MacGetBorderSize() ; - height -= 2 * MacGetBorderSize() ; + width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); + height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; @@ -2001,56 +2174,6 @@ void wxWindow::MacSuperChangedPosition() node = node->Next(); } } -/* - -bool wxWindow::MacSetupFocusPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; -} - -bool wxWindow::MacSetupFocusClientPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; -} - -bool wxWindow::MacSetupDrawingPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; -} - -bool wxWindow::MacSetupDrawingClientPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; -} -*/ bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win ) { @@ -2181,7 +2304,7 @@ void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, Window SectRect(clipRect, &myClip, clipRect); } -long wxWindow::MacGetBorderSize( ) const +long wxWindow::MacGetLeftBorderSize( ) const { if( m_macWindowData ) return 0 ; @@ -2201,41 +2324,72 @@ long wxWindow::MacGetBorderSize( ) const return 0 ; } -long wxWindow::MacRemoveBordersFromStyle( long style ) +long wxWindow::MacGetRightBorderSize( ) const { - return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; + if( m_macWindowData ) + return 0 ; + + if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) + { + return 3 ; + } + else if ( m_windowStyle &wxDOUBLE_BORDER) + { + return 3 ; + } + else if (m_windowStyle &wxSIMPLE_BORDER) + { + return 3 ; + } + return 0 ; } -/* -wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) + +long wxWindow::MacGetTopBorderSize( ) const { - m_ok = false ; - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - m_currentPort = NULL ; - GetPort( &m_formerPort ) ; - if ( theWindow ) - { - - theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; - m_currentPort = UMAGetWindowPort( window ) ; - theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; - m_ok = true ; - } + if( m_macWindowData ) + return 0 ; + + if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) + { + return 2 ; + } + else if ( m_windowStyle &wxDOUBLE_BORDER) + { + return 2 ; + } + else if (m_windowStyle &wxSIMPLE_BORDER) + { + return 1 ; + } + return 0 ; } - -wxMacFocusHelper::~wxMacFocusHelper() + +long wxWindow::MacGetBottomBorderSize( ) const { - if ( m_ok ) - { - SetPort( m_currentPort ) ; - SetOrigin( 0 , 0 ) ; - } - if ( m_formerPort != m_currentPort ) - SetPort( m_formerPort ) ; + if( m_macWindowData ) + return 0 ; + + if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) + { + return 3 ; + } + else if ( m_windowStyle &wxDOUBLE_BORDER) + { + return 3 ; + } + else if (m_windowStyle &wxSIMPLE_BORDER) + { + return 3 ; + } + return 0 ; } -*/ + +long wxWindow::MacRemoveBordersFromStyle( long style ) +{ + return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; +} + + wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) { m_ok = false ; @@ -2273,38 +2427,6 @@ wxMacDrawingHelper::~wxMacDrawingHelper() if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } -/* -wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow ) -{ - m_ok = false ; - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - m_currentPort = NULL ; - - GetPort( &m_formerPort ) ; - - if ( theWindow ) - { - theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; - m_currentPort = UMAGetWindowPort( window ) ; - theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; - m_ok = true ; - } -} - -wxMacFocusClientHelper::~wxMacFocusClientHelper() -{ - if ( m_ok ) - { - SetPort( m_currentPort ) ; - SetOrigin( 0 , 0 ) ; - } - if ( m_formerPort != m_currentPort ) - SetPort( m_formerPort ) ; -} -*/ wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow ) { @@ -2344,3 +2466,21 @@ wxMacDrawingClientHelper::~wxMacDrawingClientHelper() if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } + +// Find the wxWindow at the current mouse position, returning the mouse +// position. +wxWindow* wxFindWindowAtPointer(wxPoint& pt) +{ + pt = wxGetMousePosition(); + wxWindow* found = wxFindWindowAtPoint(pt); + return found; +} + +// Get the current mouse position. +wxPoint wxGetMousePosition() +{ + int x, y; + wxGetMousePosition(& x, & y); + return wxPoint(x, y); +} +