X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4f6bcb8390bd9a059f3cb4177e2fd661845294da..fc684792c6b050fbfeabbea92e302bc3469d7489:/src/osx/window_osx.cpp diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index f9016f4511..ec1375142e 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -93,6 +93,82 @@ END_EVENT_TABLE() // implementation // =========================================================================== +// the grow box has to be implemented as an inactive window, so that nothing can direct +// the focus to it + +class WXDLLIMPEXP_CORE wxBlindPlateWindow : public wxWindow +{ +public: + wxBlindPlateWindow() { Init(); } + + // Old-style constructor (no default values for coordinates to avoid + // ambiguity with the new one) + wxBlindPlateWindow(wxWindow *parent, + int x, int y, int width, int height, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr) + { + Init(); + + Create(parent, wxID_ANY, wxPoint(x, y), wxSize(width, height), style, name); + } + + // Constructor + wxBlindPlateWindow(wxWindow *parent, + wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr) + { + Init(); + + Create(parent, winid, pos, size, style, name); + } + + // Pseudo ctor + bool Create(wxWindow *parent, + wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr) + { + if ( !wxWindow::Create(parent, winid, pos, size, style, name) ) + return false; + + // so that non-solid background renders correctly under GTK+: + SetThemeEnabled(true); + return true; + } + + virtual ~wxBlindPlateWindow(); + + virtual bool AcceptsFocus() const + { + return false; + } + +protected: + // common part of all ctors + void Init() + { + } + + DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow) + DECLARE_EVENT_TABLE() +}; + +wxBlindPlateWindow::~wxBlindPlateWindow() +{ +} + +IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow, wxWindow) + +BEGIN_EVENT_TABLE(wxBlindPlateWindow, wxWindow) +END_EVENT_TABLE() + + // ---------------------------------------------------------------------------- // constructors and such // ---------------------------------------------------------------------------- @@ -131,6 +207,7 @@ void wxWindowMac::Init() m_macIsUserPane = true; m_clipChildren = false ; m_cachedClippedRectValid = false ; + m_isNativeWindowWrapper = false; } wxWindowMac::~wxWindowMac() @@ -180,11 +257,7 @@ wxWindowMac::~wxWindowMac() // delete our drop target if we've got one #if wxUSE_DRAG_AND_DROP - if ( m_dropTarget != NULL ) - { - delete m_dropTarget; - m_dropTarget = NULL; - } + wxDELETE(m_dropTarget); #endif delete m_peer ; @@ -338,36 +411,33 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) m_peer->SetData(kControlEntireControl, kControlSizeTag, &size ) ; #endif - wxFont font ; - - wxOSXSystemFont systemFont = wxOSX_SYSTEM_FONT_NORMAL ; switch ( variant ) { case wxWINDOW_VARIANT_NORMAL : - systemFont = wxOSX_SYSTEM_FONT_NORMAL ; + static wxFont sysNormal(wxOSX_SYSTEM_FONT_NORMAL); + SetFont(sysNormal) ; break ; case wxWINDOW_VARIANT_SMALL : - systemFont = wxOSX_SYSTEM_FONT_SMALL ; + static wxFont sysSmall(wxOSX_SYSTEM_FONT_SMALL); + SetFont(sysSmall) ; break ; case wxWINDOW_VARIANT_MINI : - systemFont = wxOSX_SYSTEM_FONT_MINI ; + static wxFont sysMini(wxOSX_SYSTEM_FONT_MINI); + SetFont(sysMini) ; break ; case wxWINDOW_VARIANT_LARGE : - systemFont = wxOSX_SYSTEM_FONT_NORMAL ; + static wxFont sysLarge(wxOSX_SYSTEM_FONT_NORMAL); + SetFont(sysLarge) ; break ; default: wxFAIL_MSG(wxT("unexpected window variant")); break ; } - - font.CreateSystemFont( systemFont ) ; - - SetFont( font ) ; } void wxWindowMac::MacUpdateControlFont() @@ -399,8 +469,26 @@ bool wxWindowMac::SetForegroundColour(const wxColour& col ) return retval; } +bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style) +{ + if ( !wxWindowBase::SetBackgroundStyle(style) ) + return false; + + if ( m_peer ) + m_peer->SetBackgroundStyle(style); + return true; +} + bool wxWindowMac::SetBackgroundColour(const wxColour& col ) { + if (m_growBox) + { + if ( m_backgroundColour.Ok() ) + m_growBox->SetBackgroundColour(m_backgroundColour); + else + m_growBox->SetBackgroundColour(*wxWHITE); + } + if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) return false ; @@ -717,7 +805,6 @@ bool wxWindowMac::SetCursor(const wxCursor& cursor) bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) { #ifndef __WXUNIVERSAL__ - menu->SetInvokingWindow((wxWindow*)this); menu->UpdateUI(); if ( x == wxDefaultCoord && y == wxDefaultCoord ) @@ -731,7 +818,6 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) ClientToScreen( &x , &y ) ; } menu->GetPeer()->PopUp(this, x, y); - menu->SetInvokingWindow( NULL ); return true; #else // actually this shouldn't be called, because universal is having its own implementation @@ -752,6 +838,9 @@ void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) if ( m_tooltip ) m_tooltip->SetWindow(this); + + if (m_peer) + m_peer->SetToolTip(tooltip); } #endif @@ -897,22 +986,20 @@ wxSize wxWindowMac::DoGetBestSize() const r.width = r.height = 16 ; - if ( 0 ) - { - } #if wxUSE_SCROLLBAR - else if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) + if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) { r.height = 16 ; } + else #endif #if wxUSE_SPINBTN - else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) + if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) { r.height = 24 ; } -#endif else +#endif { // return wxWindowBase::DoGetBestSize() ; } @@ -1060,11 +1147,17 @@ bool wxWindowMac::Show(bool show) if ( m_peer ) m_peer->SetVisibility( show ) ; - wxShowEvent eventShow(GetId(), show); - eventShow.SetEventObject(this); - - HandleWindowEvent(eventShow); - +#ifdef __WXOSX_IPHONE__ + // only when there's no native event support + if ( !IsTopLevel() ) +#endif + { + wxShowEvent eventShow(GetId(), show); + eventShow.SetEventObject(this); + + HandleWindowEvent(eventShow); + } + return true; } @@ -1082,6 +1175,7 @@ bool wxWindowMac::OSXShowWithEffect(bool show, void wxWindowMac::DoEnable(bool enable) { m_peer->Enable( enable ) ; + MacInvalidateBorders(); } // @@ -1491,6 +1585,12 @@ void wxWindowMac::SetScrollbar(int orient, int pos, int thumb, int range, bool refresh) { #if wxUSE_SCROLLBAR + // Updating scrollbars when window is being deleted is useless and + // currently results in asserts in client-to-screen coordinates conversion + // code which is used by DoUpdateScrollbarVisibility() so just skip it. + if ( m_isBeingDeleted ) + return; + if ( orient == wxHORIZONTAL && m_hScrollBar ) m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); else if ( orient == wxVERTICAL && m_vScrollBar ) @@ -1526,17 +1626,13 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) child = node->GetData(); if (child == NULL) continue; -#if wxUSE_SCROLLBAR - if (child == m_vScrollBar) - continue; - if (child == m_hScrollBar) - continue; - if (child == m_growBox) - continue; -#endif + if (child->IsTopLevel()) continue; + if ( !IsClientAreaChild(child) ) + continue; + child->GetPosition( &x, &y ); child->GetSize( &w, &h ); if (rect) @@ -1847,6 +1943,7 @@ bool wxWindowMac::MacDoRedraw( long time ) { case wxBG_STYLE_ERASE: case wxBG_STYLE_SYSTEM: + case wxBG_STYLE_COLOUR: { // for the toplevel window this really is the entire area for // all the others only their client area, otherwise they might @@ -1884,7 +1981,8 @@ bool wxWindowMac::MacDoRedraw( long time ) wxFAIL_MSG( "unsupported background style" ); } - MacPaintGrowBox(); + // as this is a full window, shouldn't be necessary anymore + // MacPaintGrowBox(); // calculate a client-origin version of the update rgn and set // m_updateRegion to that @@ -2063,7 +2161,7 @@ void wxWindowMac::MacCreateScrollBars( long style ) wxPoint gPoint(width - scrlsize, height - scrlsize); wxSize gSize(scrlsize, scrlsize); - m_growBox = new wxPanel((wxWindow *)this, wxID_ANY, gPoint, gSize, 0); + m_growBox = new wxBlindPlateWindow((wxWindow *)this, wxID_ANY, gPoint, gSize, 0); } // because the create does not take into account the client area origin @@ -2165,7 +2263,7 @@ void wxWindowMac::MacTopLevelWindowChangedPosition() } } -long wxWindowMac::MacGetLeftBorderSize() const +long wxWindowMac::MacGetWXBorderSize() const { if ( IsTopLevel() ) return 0 ; @@ -2199,22 +2297,65 @@ long wxWindowMac::MacGetLeftBorderSize() const return border ; } +long wxWindowMac::MacGetLeftBorderSize() const +{ + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= left; + } + + return border; +} + + long wxWindowMac::MacGetRightBorderSize() const { - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= right; + } + + return border; } long wxWindowMac::MacGetTopBorderSize() const { - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= top; + } + + return border; } long wxWindowMac::MacGetBottomBorderSize() const { - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= bottom; + } + + return border; } long wxWindowMac::MacRemoveBordersFromStyle( long style ) @@ -2462,6 +2603,7 @@ wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl ) Init(); m_isRootControl = isRootControl; m_wxPeer = peer; + m_shouldSendEvents = true; } wxWidgetImpl::wxWidgetImpl()