X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fd76aa8d8ae3d8b702b7155ce15c1a927257f1fc..bf60426831535738b1b784629f08e9dd00bf9ecc:/src/mac/window.cpp diff --git a/src/mac/window.cpp b/src/mac/window.cpp index bc83a282a2..cf5a48692c 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -197,6 +197,17 @@ bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, { wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); +#if wxUSE_STATBOX + // wxGTK doesn't allow to create controls with static box as the parent so + // this will result in a crash when the program is ported to wxGTK - warn + // about it + // + // the correct solution is to create the controls as siblings of the + // static box + wxASSERT_MSG( !wxDynamicCast(parent, wxStaticBox), + _T("wxStaticBox can't be used as a window parent!") ); +#endif // wxUSE_STATBOX + if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) return FALSE; @@ -227,24 +238,32 @@ void wxWindowMac::SetFocus() { if (gFocusWindow ) { - #if wxUSE_CARET +#if wxUSE_CARET // Deal with caret if ( gFocusWindow->m_caret ) { gFocusWindow->m_caret->OnKillFocus(); } - #endif // wxUSE_CARET - #ifndef __WXUNIVERSAL__ +#endif // wxUSE_CARET +#ifndef __WXUNIVERSAL__ wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; if ( control && control->GetMacControl() ) { UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ; control->MacRedrawControl() ; } - #endif - wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); - event.SetEventObject(gFocusWindow); - gFocusWindow->GetEventHandler()->ProcessEvent(event) ; +#endif + // Without testing the window id, for some reason + // a kill focus event can still be sent to + // the control just being focussed. + int thisId = this->m_windowId; + int gFocusWindowId = gFocusWindow->m_windowId; + if (gFocusWindowId != thisId) + { + wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); + event.SetEventObject(gFocusWindow); + gFocusWindow->GetEventHandler()->ProcessEvent(event) ; + } } gFocusWindow = this ; { @@ -353,7 +372,17 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) ::InsertMenu( (MenuHandle) menu->GetHMenu() , -1 ) ; long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; - menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; + if ( HiWord(menuResult) != 0 ) + { + MenuCommand id ; + GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; + + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id ); + event.m_timeStamp = TickCount() ; + event.SetEventObject(this->GetEventHandler()); + event.SetInt( id ); + GetEventHandler()->ProcessEvent(event); + } ::DeleteMenu( menu->MacGetMenuId() ) ; menu->SetInvokingWindow(NULL); @@ -381,9 +410,9 @@ void wxWindowMac::DoScreenToClient(int *x, int *y) const MacRootWindowToWindow( x , y ) ; if ( x ) - x -= MacGetLeftBorderSize() ; + *x -= MacGetLeftBorderSize() ; if ( y ) - y -= MacGetTopBorderSize() ; + *y -= MacGetTopBorderSize() ; } void wxWindowMac::DoClientToScreen(int *x, int *y) const @@ -391,9 +420,9 @@ void wxWindowMac::DoClientToScreen(int *x, int *y) const WindowRef window = (WindowRef) MacGetRootWindow() ; if ( x ) - x += MacGetLeftBorderSize() ; + *x += MacGetLeftBorderSize() ; if ( y ) - y += MacGetTopBorderSize() ; + *y += MacGetTopBorderSize() ; MacWindowToRootWindow( x , y ) ; @@ -595,7 +624,35 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) { // erase former position - Refresh() ; + bool partialRepaint = false ; + + if ( HasFlag(wxNO_FULL_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() ; + 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 ) ; + DisposeRgn(oldRgn) ; + DisposeRgn(newRgn) ; + DisposeRgn(diffRgn) ; + } + } + + if ( !partialRepaint ) + Refresh() ; m_x = actualX ; m_y = actualY ; @@ -607,7 +664,8 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) MacUpdateDimensions() ; // erase new position - Refresh() ; + if ( !partialRepaint ) + Refresh() ; if ( doMove ) wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified @@ -747,13 +805,13 @@ bool wxWindowMac::Show(bool show) void wxWindowMac::MacSuperShown( bool show ) { - wxNode *node = GetChildren().First(); + wxWindowListNode *node = GetChildren().GetFirst(); while ( node ) { - wxWindowMac *child = (wxWindowMac *)node->Data(); + wxWindowMac *child = (wxWindowMac *)node->GetData(); if ( child->m_isShown ) child->MacSuperShown( show ) ; - node = node->Next(); + node = node->GetNext(); } } @@ -765,13 +823,13 @@ void wxWindowMac::MacSuperEnabled( bool enabled ) // because unter MacOSX the frames are drawn with an addXXX mode) // the borders area } - wxNode *node = GetChildren().First(); + wxWindowListNode *node = GetChildren().GetFirst(); while ( node ) { - wxWindowMac *child = (wxWindowMac *)node->Data(); + wxWindowMac *child = (wxWindowMac *)node->GetData(); if ( child->m_isShown ) child->MacSuperEnabled( enabled ) ; - node = node->Next(); + node = node->GetNext(); } } @@ -1200,9 +1258,9 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) DisposeRgn( updateRgn ) ; } - for (wxNode *node = GetChildren().First(); node; node = node->Next()) + for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) { - wxWindowMac *child = (wxWindowMac*)node->Data(); + wxWindowMac *child = (wxWindowMac*)node->GetData(); if (child == m_vScrollBar) continue; if (child == m_hScrollBar) continue; if (child->IsTopLevel()) continue; @@ -1274,13 +1332,13 @@ void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event) wxObject* wxWindowMac::GetChild(int number) const { // Return a pointer to the Nth object in the Panel - wxNode *node = GetChildren().First(); + wxNode *node = GetChildren().GetFirst(); int n = number; while (node && n--) - node = node->Next(); + node = node->GetNext(); if ( node ) { - wxObject *obj = (wxObject *)node->Data(); + wxObject *obj = (wxObject *)node->GetData(); return(obj); } else @@ -1396,9 +1454,9 @@ bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** newPoint.y -= m_y; } - for (wxNode *node = GetChildren().First(); node; node = node->Next()) + for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) { - wxWindowMac *child = (wxWindowMac*)node->Data(); + wxWindowMac *child = (wxWindowMac*)node->GetData(); // added the m_isShown test --dmazzoni if ( child->MacGetRootWindow() == window && child->m_isShown ) { @@ -1439,7 +1497,6 @@ bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMa return FALSE ; } -extern int wxBusyCursorCount ; static wxWindow *gs_lastWhich = NULL; bool wxWindowMac::MacSetupCursor( const wxPoint& pt) @@ -1502,9 +1559,9 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) int x = event.m_x ; int y = event.m_y ; - for (wxNode *node = GetChildren().First(); node; node = node->Next()) + for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) { - wxWindowMac *child = (wxWindowMac*)node->Data(); + wxWindowMac *child = (wxWindowMac*)node->GetData(); if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() ) { if (child->MacDispatchMouseEvent(event)) @@ -1600,6 +1657,7 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling { RgnHandle visRgn = NewRgn() ; RgnHandle tempRgn = NewRgn() ; + RgnHandle tempStaticBoxRgn = NewRgn() ; SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ; @@ -1609,8 +1667,8 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling int borderTop = 14 ; int borderOther = 4 ; - SetRectRgn( tempRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; - DiffRgn( visRgn , tempRgn , visRgn ) ; + SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; + DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ; } if ( !IsTopLevel() ) @@ -1626,8 +1684,8 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling SetRectRgn( tempRgn , x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , - x + size.x - parent->MacGetLeftBorderSize() - parent->MacGetRightBorderSize(), - y + size.y - parent->MacGetTopBorderSize() - parent->MacGetBottomBorderSize()) ; + x + size.x - parent->MacGetRightBorderSize(), + y + size.y - parent->MacGetBottomBorderSize()) ; SectRgn( visRgn , tempRgn , visRgn ) ; if ( parent->IsTopLevel() ) @@ -1639,13 +1697,21 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling { if ( GetWindowStyle() & wxCLIP_CHILDREN ) { - for (wxNode *node = GetChildren().First(); node; node = node->Next()) + for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) { - wxWindowMac *child = (wxWindowMac*)node->Data(); + wxWindowMac *child = (wxWindowMac*)node->GetData(); if ( !child->IsTopLevel() && child->IsShown() ) { SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; + if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) ) + { + int borderTop = 14 ; + int borderOther = 4 ; + + SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ; + DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; + } DiffRgn( visRgn , tempRgn , visRgn ) ; } } @@ -1654,9 +1720,9 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() ) { bool thisWindowThrough = false ; - for (wxNode *node = GetParent()->GetChildren().First(); node; node = node->Next()) + for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext()) { - wxWindowMac *sibling = (wxWindowMac*)node->Data(); + wxWindowMac *sibling = (wxWindowMac*)node->GetData(); if ( sibling == this ) { thisWindowThrough = true ; @@ -1670,6 +1736,14 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling if ( !sibling->IsTopLevel() && sibling->IsShown() ) { SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ; + if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) ) + { + int borderTop = 14 ; + int borderOther = 4 ; + + SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ; + DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; + } DiffRgn( visRgn , tempRgn , visRgn ) ; } } @@ -1678,6 +1752,7 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling m_macVisibleRegion = visRgn ; DisposeRgn( visRgn ) ; DisposeRgn( tempRgn ) ; + DisposeRgn( tempStaticBoxRgn ) ; return m_macVisibleRegion ; } @@ -1709,7 +1784,8 @@ void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) if ( erase && !EmptyRgn(ownUpdateRgn) ) { wxWindowDC dc(this); - dc.SetClippingRegion(wxRegion(ownUpdateRgn)); + if (!EmptyRgn(ownUpdateRgn)) + dc.SetClippingRegion(wxRegion(ownUpdateRgn)); wxEraseEvent eevent( GetId(), &dc ); eevent.SetEventObject( this ); GetEventHandler()->ProcessEvent( eevent ); @@ -1731,11 +1807,11 @@ void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively RgnHandle childupdate = NewRgn() ; - for (wxNode *node = GetChildren().First(); node; node = node->Next()) + for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) { // calculate the update region for the child windows by intersecting the window rectangle with our own // passed in update region and then offset it to be client-wise window coordinates again - wxWindowMac *child = (wxWindowMac*)node->Data(); + wxWindowMac *child = (wxWindowMac*)node->GetData(); SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; SectRgn( childupdate , updatergn , childupdate ) ; OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; @@ -1892,12 +1968,12 @@ void wxWindowMac::MacSuperChangedPosition() { // only window-absolute structures have to be moved i.e. controls - wxNode *node = GetChildren().First(); + wxWindowListNode *node = GetChildren().GetFirst(); while ( node ) { - wxWindowMac *child = (wxWindowMac *)node->Data(); + wxWindowMac *child = (wxWindowMac *)node->GetData(); child->MacSuperChangedPosition() ; - node = node->Next(); + node = node->GetNext(); } } @@ -1905,12 +1981,12 @@ void wxWindowMac::MacTopLevelWindowChangedPosition() { // only screen-absolute structures have to be moved i.e. glcanvas - wxNode *node = GetChildren().First(); + wxWindowListNode *node = GetChildren().GetFirst(); while ( node ) { - wxWindowMac *child = (wxWindowMac *)node->Data(); + wxWindowMac *child = (wxWindowMac *)node->GetData(); child->MacTopLevelWindowChangedPosition() ; - node = node->Next(); + node = node->GetNext(); } } long wxWindowMac::MacGetLeftBorderSize( ) const