Fix wxTreeListCtrl under wxOSX
Postpone resetting indent in wxOSX wxDataViewCtrl to avoid always removing, and hence never showing the expanders at all, for wxTreeListCtrl whose model starts its life as a list but becomes a tree as soon as any items with children are added to it. By postponing the call to IsListModel() until the next resize, we give the model the time it needs to decide what it's going to be, while still removing the unnecessary indent if there is no need for it. Closes #17409.
This commit is contained in:
@@ -534,6 +534,8 @@ private:
|
|||||||
wxCocoaOutlineDataSource* m_DataSource;
|
wxCocoaOutlineDataSource* m_DataSource;
|
||||||
|
|
||||||
wxCocoaOutlineView* m_OutlineView;
|
wxCocoaOutlineView* m_OutlineView;
|
||||||
|
|
||||||
|
bool m_removeIndentIfNecessary;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_DATAVIEWCTRL_COCOOA_H_
|
#endif // _WX_DATAVIEWCTRL_COCOOA_H_
|
||||||
|
@@ -1939,7 +1939,8 @@ wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer,
|
|||||||
[[NSScrollView alloc] initWithFrame:wxOSXGetFrameForControl(peer,pos,size)]
|
[[NSScrollView alloc] initWithFrame:wxOSXGetFrameForControl(peer,pos,size)]
|
||||||
),
|
),
|
||||||
m_DataSource(NULL),
|
m_DataSource(NULL),
|
||||||
m_OutlineView([[wxCocoaOutlineView alloc] init])
|
m_OutlineView([[wxCocoaOutlineView alloc] init]),
|
||||||
|
m_removeIndentIfNecessary(false)
|
||||||
{
|
{
|
||||||
// initialize scrollview (the outline view is part of a scrollview):
|
// initialize scrollview (the outline view is part of a scrollview):
|
||||||
NSScrollView* scrollview = (NSScrollView*) GetWXWidget();
|
NSScrollView* scrollview = (NSScrollView*) GetWXWidget();
|
||||||
@@ -2289,13 +2290,11 @@ bool wxCocoaDataViewControl::AssociateModel(wxDataViewModel* model)
|
|||||||
m_DataSource = NULL;
|
m_DataSource = NULL;
|
||||||
[m_OutlineView setDataSource:m_DataSource]; // if there is a data source the data is immediately going to be requested
|
[m_OutlineView setDataSource:m_DataSource]; // if there is a data source the data is immediately going to be requested
|
||||||
|
|
||||||
// By default, the first column is indented to leave enough place for the
|
// Set this to true to check if we need to remove the indent in the next
|
||||||
// expanders, but this looks bad if there are no expanders, so don't use
|
// OnSize() call: we can't do it directly here because the model might not
|
||||||
// indent in this case.
|
// be fully initialized yet and so might not know whether it has any items
|
||||||
if ( model && model->IsListModel() )
|
// with children or not.
|
||||||
{
|
m_removeIndentIfNecessary = true;
|
||||||
DoSetIndent(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2460,6 +2459,21 @@ void wxCocoaDataViewControl::SetRowHeight(const wxDataViewItem& WXUNUSED(item),
|
|||||||
|
|
||||||
void wxCocoaDataViewControl::OnSize()
|
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)
|
if ([m_OutlineView numberOfColumns] == 1)
|
||||||
[m_OutlineView sizeLastColumnToFit];
|
[m_OutlineView sizeLastColumnToFit];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user