Merge branch 'mac-dvc-check-icons'
Add back support for icons to Mac wxDataViewCheckIconTextRenderer OSX. See https://github.com/wxWidgets/wxWidgets/pull/1680
This commit is contained in:
@@ -833,24 +833,21 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
|
|||||||
m_list_model = new MyListModel;
|
m_list_model = new MyListModel;
|
||||||
m_ctrl[Page_List]->AssociateModel( m_list_model.get() );
|
m_ctrl[Page_List]->AssociateModel( m_list_model.get() );
|
||||||
|
|
||||||
m_ctrl[Page_List]->AppendToggleColumn(L"\u2714",
|
wxDataViewColumn* const colCheckIconText = new wxDataViewColumn
|
||||||
MyListModel::Col_Toggle,
|
(
|
||||||
wxDATAVIEW_CELL_ACTIVATABLE,
|
L"\u2714 + icon + text",
|
||||||
wxCOL_WIDTH_AUTOSIZE);
|
new wxDataViewCheckIconTextRenderer(),
|
||||||
|
MyListModel::Col_ToggleIconText,
|
||||||
|
wxCOL_WIDTH_AUTOSIZE
|
||||||
|
);
|
||||||
|
m_ctrl[Page_List]->AppendColumn(colCheckIconText);
|
||||||
|
|
||||||
// the various columns
|
|
||||||
m_ctrl[Page_List]->AppendTextColumn("editable string",
|
m_ctrl[Page_List]->AppendTextColumn("editable string",
|
||||||
MyListModel::Col_EditableText,
|
MyListModel::Col_EditableText,
|
||||||
wxDATAVIEW_CELL_EDITABLE,
|
wxDATAVIEW_CELL_EDITABLE,
|
||||||
wxCOL_WIDTH_AUTOSIZE,
|
wxCOL_WIDTH_AUTOSIZE,
|
||||||
wxALIGN_NOT,
|
wxALIGN_NOT,
|
||||||
wxDATAVIEW_COL_SORTABLE);
|
wxDATAVIEW_COL_SORTABLE);
|
||||||
m_ctrl[Page_List]->AppendIconTextColumn("icon",
|
|
||||||
MyListModel::Col_IconText,
|
|
||||||
wxDATAVIEW_CELL_EDITABLE,
|
|
||||||
wxCOL_WIDTH_AUTOSIZE,
|
|
||||||
wxALIGN_NOT,
|
|
||||||
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE);
|
|
||||||
|
|
||||||
m_ctrl[Page_List]->AppendDateColumn("date",
|
m_ctrl[Page_List]->AppendDateColumn("date",
|
||||||
MyListModel::Col_Date);
|
MyListModel::Col_Date);
|
||||||
|
@@ -437,13 +437,6 @@ void MyListModel::GetValueByRow( wxVariant &variant,
|
|||||||
{
|
{
|
||||||
switch ( col )
|
switch ( col )
|
||||||
{
|
{
|
||||||
case Col_Toggle:
|
|
||||||
if (row >= m_toggleColValues.size())
|
|
||||||
variant = false;
|
|
||||||
else
|
|
||||||
variant = m_toggleColValues[row];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Col_EditableText:
|
case Col_EditableText:
|
||||||
if (row >= m_textColValues.GetCount())
|
if (row >= m_textColValues.GetCount())
|
||||||
variant = wxString::Format( "virtual row %d", row );
|
variant = wxString::Format( "virtual row %d", row );
|
||||||
@@ -451,15 +444,22 @@ void MyListModel::GetValueByRow( wxVariant &variant,
|
|||||||
variant = m_textColValues[ row ];
|
variant = m_textColValues[ row ];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Col_IconText:
|
case Col_ToggleIconText:
|
||||||
{
|
{
|
||||||
wxString text;
|
wxString text;
|
||||||
|
wxCheckBoxState state;
|
||||||
if ( row >= m_iconColValues.GetCount() )
|
if ( row >= m_iconColValues.GetCount() )
|
||||||
|
{
|
||||||
text = "virtual icon";
|
text = "virtual icon";
|
||||||
|
state = wxCHK_UNDETERMINED;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
text = m_iconColValues[row];
|
text = m_iconColValues[row];
|
||||||
|
state = m_toggleColValues[row] ? wxCHK_CHECKED : wxCHK_UNCHECKED;
|
||||||
|
}
|
||||||
|
|
||||||
variant << wxDataViewIconText(text, m_icon[row % 2]);
|
variant << wxDataViewCheckIconText(text, m_icon[row % 2], state);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -505,9 +505,6 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
|
|||||||
{
|
{
|
||||||
switch ( col )
|
switch ( col )
|
||||||
{
|
{
|
||||||
case Col_Toggle:
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case Col_EditableText:
|
case Col_EditableText:
|
||||||
case Col_Date:
|
case Col_Date:
|
||||||
if (row < m_toggleColValues.size())
|
if (row < m_toggleColValues.size())
|
||||||
@@ -521,7 +518,7 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case Col_IconText:
|
case Col_ToggleIconText:
|
||||||
if ( !(row % 2) )
|
if ( !(row % 2) )
|
||||||
return false;
|
return false;
|
||||||
attr.SetColour(*wxYELLOW);
|
attr.SetColour(*wxYELLOW);
|
||||||
@@ -578,15 +575,8 @@ bool MyListModel::SetValueByRow( const wxVariant &variant,
|
|||||||
{
|
{
|
||||||
switch ( col )
|
switch ( col )
|
||||||
{
|
{
|
||||||
case Col_Toggle:
|
|
||||||
if (row >= m_toggleColValues.size())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_toggleColValues[row] = variant.GetBool();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case Col_EditableText:
|
case Col_EditableText:
|
||||||
case Col_IconText:
|
case Col_ToggleIconText:
|
||||||
if (row >= m_textColValues.GetCount())
|
if (row >= m_textColValues.GetCount())
|
||||||
{
|
{
|
||||||
// the item is not in the range of the items
|
// the item is not in the range of the items
|
||||||
@@ -600,11 +590,13 @@ bool MyListModel::SetValueByRow( const wxVariant &variant,
|
|||||||
{
|
{
|
||||||
m_textColValues[row] = variant.GetString();
|
m_textColValues[row] = variant.GetString();
|
||||||
}
|
}
|
||||||
else // col == Col_IconText
|
else // col == Col_ToggleIconText
|
||||||
{
|
{
|
||||||
wxDataViewIconText iconText;
|
wxDataViewCheckIconText checkIconText;
|
||||||
iconText << variant;
|
checkIconText << variant;
|
||||||
m_iconColValues[row] = iconText.GetText();
|
m_toggleColValues[row] =
|
||||||
|
checkIconText.GetCheckedState() == wxCHK_CHECKED;
|
||||||
|
m_iconColValues[row] = checkIconText.GetText();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@@ -208,9 +208,8 @@ class MyListModel: public wxDataViewVirtualListModel
|
|||||||
public:
|
public:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
Col_Toggle,
|
Col_ToggleIconText,
|
||||||
Col_EditableText,
|
Col_EditableText,
|
||||||
Col_IconText,
|
|
||||||
Col_Date,
|
Col_Date,
|
||||||
Col_TextWithAttr,
|
Col_TextWithAttr,
|
||||||
Col_Custom,
|
Col_Custom,
|
||||||
@@ -236,11 +235,8 @@ public:
|
|||||||
|
|
||||||
virtual wxString GetColumnType( unsigned int col ) const wxOVERRIDE
|
virtual wxString GetColumnType( unsigned int col ) const wxOVERRIDE
|
||||||
{
|
{
|
||||||
if (col == Col_Toggle)
|
if (col == Col_ToggleIconText)
|
||||||
return "bool";
|
return wxDataViewCheckIconTextRenderer::GetDefaultType();
|
||||||
|
|
||||||
if (col == Col_IconText)
|
|
||||||
return "wxDataViewIconText";
|
|
||||||
|
|
||||||
return "string";
|
return "string";
|
||||||
}
|
}
|
||||||
|
@@ -3404,6 +3404,25 @@ void wxDataViewCheckIconTextRenderer::Allow3rdStateForUser(bool allow)
|
|||||||
m_allow3rdStateForUser = allow;
|
m_allow3rdStateForUser = allow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface wxNSTextAttachmentCellWithBaseline : NSTextAttachmentCell
|
||||||
|
{
|
||||||
|
NSPoint _offset;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation wxNSTextAttachmentCellWithBaseline
|
||||||
|
|
||||||
|
- (void) setCellBaselineOffset:(NSPoint) offset
|
||||||
|
{
|
||||||
|
_offset=offset;
|
||||||
|
}
|
||||||
|
- (NSPoint)cellBaselineOffset
|
||||||
|
{
|
||||||
|
return _offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
bool wxDataViewCheckIconTextRenderer::MacRender()
|
bool wxDataViewCheckIconTextRenderer::MacRender()
|
||||||
{
|
{
|
||||||
wxDataViewCheckIconText checkIconText;
|
wxDataViewCheckIconText checkIconText;
|
||||||
@@ -3426,7 +3445,48 @@ bool wxDataViewCheckIconTextRenderer::MacRender()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
[cell setIntValue:nativecbvalue];
|
[cell setIntValue:nativecbvalue];
|
||||||
[cell setTitle:wxCFStringRef(checkIconText.GetText()).AsNSString()];
|
|
||||||
|
const wxCFStringRef textString(checkIconText.GetText());
|
||||||
|
|
||||||
|
const wxIcon& icon = checkIconText.GetIcon();
|
||||||
|
if ( icon.IsOk() )
|
||||||
|
{
|
||||||
|
wxNSTextAttachmentCellWithBaseline* const attachmentCell =
|
||||||
|
[[wxNSTextAttachmentCellWithBaseline alloc] initImageCell: icon.GetNSImage()];
|
||||||
|
NSTextAttachment* const attachment = [NSTextAttachment new];
|
||||||
|
[attachment setAttachmentCell: attachmentCell];
|
||||||
|
|
||||||
|
// Note: this string is released by the autorelease pool and must not
|
||||||
|
// be released manually below.
|
||||||
|
NSAttributedString* const iconString =
|
||||||
|
[NSAttributedString attributedStringWithAttachment: attachment];
|
||||||
|
|
||||||
|
NSAttributedString* const separatorString =
|
||||||
|
[[NSAttributedString alloc] initWithString: @" "];
|
||||||
|
|
||||||
|
NSAttributedString* const textAttrString =
|
||||||
|
[[NSAttributedString alloc] initWithString: textString.AsNSString()];
|
||||||
|
|
||||||
|
NSMutableAttributedString* const fullString =
|
||||||
|
[NSMutableAttributedString new];
|
||||||
|
[attachmentCell setCellBaselineOffset: NSMakePoint(0.0, -5.0)];
|
||||||
|
|
||||||
|
[fullString appendAttributedString: iconString];
|
||||||
|
[fullString appendAttributedString: separatorString];
|
||||||
|
[fullString appendAttributedString: textAttrString];
|
||||||
|
|
||||||
|
[cell setAttributedTitle: fullString];
|
||||||
|
|
||||||
|
[fullString release];
|
||||||
|
[separatorString release];
|
||||||
|
[textAttrString release];
|
||||||
|
[attachment release];
|
||||||
|
[attachmentCell release];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[cell setTitle: textString.AsNSString()];
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user