diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 6587f97bd9..ffe1ac2e5d 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -551,8 +551,6 @@ private: wxCocoaOutlineDataSource* m_DataSource; wxCocoaOutlineView* m_OutlineView; - - bool m_removeIndentIfNecessary; }; #endif // _WX_DATAVIEWCTRL_COCOOA_H_ diff --git a/src/generic/treelist.cpp b/src/generic/treelist.cpp index f68d74e42d..6c599100ae 100644 --- a/src/generic/treelist.cpp +++ b/src/generic/treelist.cpp @@ -482,6 +482,13 @@ wxTreeListModel::InsertItem(Node* parent, { // Not flat any more, this is a second level child. m_isFlat = false; + + // This is a hack needed to work around wxOSX wxDataViewCtrl + // implementation which removes the indent if it thinks that the model + // is flat. We need to re-add the indent back if it turns out that it + // isn't flat, in fact. + wxDataViewCtrl* const dvc = m_treelist->GetDataView(); + dvc->SetIndent(dvc->GetIndent()); } wxScopedPtr diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 9b0207eb92..c48c9c976e 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2033,8 +2033,7 @@ wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer, [[NSScrollView alloc] initWithFrame:wxOSXGetFrameForControl(peer,pos,size)] ), m_DataSource(NULL), - m_OutlineView([[wxCocoaOutlineView alloc] init]), - m_removeIndentIfNecessary(false) + m_OutlineView([[wxCocoaOutlineView alloc] init]) { // initialize scrollview (the outline view is part of a scrollview): NSScrollView* scrollview = (NSScrollView*) GetWXWidget(); @@ -2408,11 +2407,13 @@ bool wxCocoaDataViewControl::AssociateModel(wxDataViewModel* model) m_DataSource = NULL; [m_OutlineView setDataSource:m_DataSource]; // if there is a data source the data is immediately going to be requested - // Set this to true to check if we need to remove the indent in the next - // OnSize() call: we can't do it directly here because the model might not - // be fully initialized yet and so might not know whether it has any items - // with children or not. - m_removeIndentIfNecessary = true; + // By default, the first column is indented to leave enough place for the + // expanders, but this looks bad if there are no expanders, so don't use + // indent in this case. + if ( model && model->IsListModel() ) + { + DoSetIndent(0); + } return true; } @@ -2577,21 +2578,6 @@ void wxCocoaDataViewControl::SetRowHeight(const wxDataViewItem& WXUNUSED(item), void wxCocoaDataViewControl::OnSize() { - if ( m_removeIndentIfNecessary ) - { - m_removeIndentIfNecessary = false; - - const wxDataViewModel* const model = GetDataViewCtrl()->GetModel(); - - // By default, the first column is indented to leave enough place for the - // expanders, but this looks bad if there are no expanders, so don't use - // indent in this case. - if ( model && model->IsListModel() ) - { - DoSetIndent(0); - } - } - if ([m_OutlineView numberOfColumns] == 1) [m_OutlineView sizeLastColumnToFit]; } diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index de48514a23..2c2c3e48a6 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -769,6 +769,30 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve } } +static void SetDrawingEnabledIfFrozenRecursive(wxWidgetCocoaImpl *impl, bool enable) +{ + if (!impl->GetWXPeer()) + return; + + if (impl->GetWXPeer()->IsFrozen()) + impl->SetDrawingEnabled(enable); + + for ( wxWindowList::iterator i = impl->GetWXPeer()->GetChildren().begin(); + i != impl->GetWXPeer()->GetChildren().end(); + ++i ) + { + wxWindow *child = *i; + if ( child->IsTopLevel() || !child->IsFrozen() ) + continue; + + // Skip any user panes as they'll handle this themselves + if ( !child->GetPeer() || child->GetPeer()->IsUserPane() ) + continue; + + SetDrawingEnabledIfFrozenRecursive((wxWidgetCocoaImpl *)child->GetPeer(), enable); + } +} + @implementation wxNSView + (void)initialize @@ -887,6 +911,24 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve return [super hitTest:aPoint]; } +- (void) viewWillMoveToWindow:(NSWindow *)newWindow +{ + wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl*) wxWidgetImpl::FindFromWXWidget( self ); + if (viewimpl) + SetDrawingEnabledIfFrozenRecursive(viewimpl, true); + + [super viewWillMoveToWindow:newWindow]; +} + +- (void) viewDidMoveToWindow +{ + wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl*) wxWidgetImpl::FindFromWXWidget( self ); + if (viewimpl) + SetDrawingEnabledIfFrozenRecursive(viewimpl, false); + + [super viewDidMoveToWindow]; +} + @end // wxNSView // We need to adopt NSTextInputClient protocol in order to interpretKeyEvents: to work. @@ -2487,7 +2529,7 @@ void wxWidgetCocoaImpl::Init() wxWidgetCocoaImpl::~wxWidgetCocoaImpl() { if ( GetWXPeer() && GetWXPeer()->IsFrozen() ) - [[m_osxView window] enableFlushWindow]; + SetDrawingEnabled(true); RemoveAssociations( this ); @@ -3035,6 +3077,10 @@ void wxWidgetCocoaImpl::SetDropTarget(wxDropTarget* target) void wxWidgetCocoaImpl::RemoveFromParent() { + // User panes will be thawed in the removeFromSuperview call below + if (!IsUserPane() && m_wxPeer->IsFrozen()) + SetDrawingEnabled(true); + [m_osxView removeFromSuperview]; } @@ -3044,8 +3090,9 @@ void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent ) wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; [container addSubview:m_osxView]; - if( m_wxPeer->IsFrozen() ) - [[m_osxView window] disableFlushWindow]; + // User panes will be frozen elsewhere + if( m_wxPeer->IsFrozen() && !IsUserPane() ) + SetDrawingEnabled(false); } void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &col ) @@ -3694,6 +3741,9 @@ void wxWidgetCocoaImpl::SetFlipped(bool flipped) void wxWidgetCocoaImpl::SetDrawingEnabled(bool enabled) { + if ( [m_osxView window] == nil ) + return; + if ( enabled ) { [[m_osxView window] enableFlushWindow]; diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 16bec10892..52d161b17b 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -49,8 +49,7 @@ class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData friend class WXDLLIMPEXP_FWD_CORE wxIcon; friend class WXDLLIMPEXP_FWD_CORE wxCursor; public: - wxBitmapRefData(int width , int height , int depth, double logicalscale); - wxBitmapRefData(int width , int height , int depth); + wxBitmapRefData(int width , int height , int depth, double logicalscale = 1.0); wxBitmapRefData(CGContextRef context); wxBitmapRefData(CGImageRef image, double scale); wxBitmapRefData(); @@ -106,8 +105,7 @@ public: int GetBytesPerRow() const { return m_bytesPerRow; } private : - bool Create(int width , int height , int depth); - bool Create(int width , int height , int depth, double logicalScale); + bool Create(int width , int height , int depth, double logicalscale); bool Create( CGImageRef image, double scale ); bool Create( CGContextRef bitmapcontext); void Init(); @@ -269,13 +267,7 @@ wxBitmapRefData::wxBitmapRefData() Init() ; } -wxBitmapRefData::wxBitmapRefData( int w , int h , int d ) -{ - Init() ; - Create( w , h , d ) ; -} - -wxBitmapRefData::wxBitmapRefData(int w , int h , int d, double logicalscale) +wxBitmapRefData::wxBitmapRefData( int w , int h , int d , double logicalscale) { Init() ; Create( w , h , d, logicalscale ) ; @@ -370,11 +362,12 @@ bool wxBitmapRefData::Create(CGContextRef context) return m_ok ; } -bool wxBitmapRefData::Create( int w , int h , int d ) +bool wxBitmapRefData::Create( int w , int h , int d, double logicalscale ) { m_width = wxMax(1, w); m_height = wxMax(1, h); m_depth = d ; + m_scaleFactor = logicalscale; m_hBitmap = NULL ; m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ; @@ -395,12 +388,6 @@ bool wxBitmapRefData::Create( int w , int h , int d ) return m_ok ; } -bool wxBitmapRefData::Create( int w , int h , int d, double logicalScale ) -{ - m_scaleFactor = logicalScale; - return Create(w*logicalScale,h*logicalScale,d); -} - void wxBitmapRefData::UseAlpha( bool use ) { if ( m_hasAlpha == use ) @@ -1125,7 +1112,7 @@ bool wxBitmap::CreateScaled(int w, int h, int d, double logicalScale) if ( d < 0 ) d = wxDisplayDepth() ; - m_refData = new wxBitmapRefData( w , h , d, logicalScale ); + m_refData = new wxBitmapRefData( w*logicalScale , h*logicalScale , d, logicalScale ); return M_BITMAPDATA->IsOk() ; } @@ -1220,7 +1207,7 @@ wxBitmap::wxBitmap(const wxImage& image, int depth, double scale) wxBitmapRefData* bitmapRefData; - m_refData = bitmapRefData = new wxBitmapRefData( width/scale, height/scale, depth, scale) ; + m_refData = bitmapRefData = new wxBitmapRefData( width, height, depth, scale) ; if ( bitmapRefData->IsOk()) { diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index c725ef8d57..5928260429 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -1638,6 +1638,15 @@ void wxWindowMac::RemoveChild( wxWindowBase *child ) if ( child == m_growBox ) m_growBox = NULL ; #endif + if (!child->IsBeingDeleted() && !child->IsTopLevel()) + { + // Must be removed prior to RemoveChild and next AddChild call + // Otherwise the next AddChild may freeze the wrong window + wxWindowMac *mac = (wxWindowMac *)child; + if (mac->GetPeer() && mac->GetPeer()->IsOk()) + mac->GetPeer()->RemoveFromParent(); + } + wxWindowBase::RemoveChild( child ) ; } @@ -2458,10 +2467,9 @@ bool wxWindowMac::Reparent(wxWindowBase *newParentBase) if ( !wxWindowBase::Reparent(newParent) ) return false; - GetPeer()->RemoveFromParent(); GetPeer()->Embed( GetParent()->GetPeer() ); - MacChildAdded(); + GetParent()->MacChildAdded(); return true; } diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index a18796220a..deaacadbfe 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -490,9 +490,10 @@ void ScintillaWX::NotifyParent(SCNotification scn) { // a side effect that the AutoComp will also not be destroyed when switching // to another window, but I think that is okay. void ScintillaWX::CancelModes() { - if (! focusEvent) + if (! focusEvent) { AutoCompleteCancel(); - ct.CallTipCancel(); + ct.CallTipCancel(); + } Editor::CancelModes(); }