Re-add support for icons to Mac wxDataViewCheckIconTextRenderer

Icons were not supported any longer since the switch to the native
implementation in 235e61c311.

Restore them now by using text attachments (thanks to Scott B for the
idea). The vertical alignment is still not right, but it's better than
nothing.

See #17473.
This commit is contained in:
Vadim Zeitlin
2019-12-15 19:18:07 +01:00
parent 334ff40716
commit 7fa1afafc2

View File

@@ -3426,7 +3426,46 @@ bool wxDataViewCheckIconTextRenderer::MacRender()
break;
}
[cell setIntValue:nativecbvalue];
[cell setTitle:wxCFStringRef(checkIconText.GetText()).AsNSString()];
const wxCFStringRef textString(checkIconText.GetText());
const wxIcon& icon = checkIconText.GetIcon();
if ( icon.IsOk() )
{
NSTextAttachmentCell* const attachmentCell =
[[NSTextAttachmentCell 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];
[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;
}