Implement image support for wxNotebook pages in wxOSX/Cocoa.
This currently doesn't work correctly for left/right orientations but at least it does work for the default top (and also bottom) one. Closes #12754. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72807 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -603,6 +603,7 @@ wxMSW:
|
||||
wxOSX:
|
||||
|
||||
- Fix pages range in the print dialog (Auria).
|
||||
- Implement image support in wxNotebook for wxOSX/Cocoa (Malcolm MacLeod).
|
||||
|
||||
|
||||
2.9.4: (released 2012-07-09)
|
||||
|
@@ -94,6 +94,84 @@
|
||||
|
||||
@end
|
||||
|
||||
// ========================================================================
|
||||
// WXCTabViewImageItem
|
||||
// ========================================================================
|
||||
@interface WXCTabViewImageItem : NSTabViewItem
|
||||
{
|
||||
NSImage *m_image;
|
||||
}
|
||||
- (id)init;
|
||||
- (void)dealloc;
|
||||
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel;
|
||||
- (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect;
|
||||
- (NSImage*)image;
|
||||
- (void)setImage:(NSImage*)image;
|
||||
@end // interface WXCTabViewImageItem : NSTabViewItem
|
||||
|
||||
|
||||
@implementation WXCTabViewImageItem : NSTabViewItem
|
||||
- (id)init
|
||||
{
|
||||
m_image = nil;
|
||||
return [super initWithIdentifier:nil];
|
||||
}
|
||||
- (void)dealloc
|
||||
{
|
||||
[m_image release];
|
||||
[super dealloc];
|
||||
}
|
||||
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
|
||||
{
|
||||
NSSize labelSize = [super sizeOfLabel:shouldTruncateLabel];
|
||||
if(!m_image)
|
||||
return labelSize;
|
||||
NSSize imageSize = [m_image size];
|
||||
// scale image size
|
||||
if(imageSize.height > labelSize.height)
|
||||
{
|
||||
imageSize.width *= labelSize.height/imageSize.height;
|
||||
imageSize.height *= labelSize.height/imageSize.height;
|
||||
[m_image setScalesWhenResized:YES];
|
||||
[m_image setSize: imageSize];
|
||||
}
|
||||
labelSize.width += imageSize.width;
|
||||
return labelSize;
|
||||
}
|
||||
- (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
|
||||
{
|
||||
if(m_image)
|
||||
{
|
||||
NSSize imageSize = [m_image size];
|
||||
[m_image compositeToPoint:NSMakePoint(tabRect.origin.x,
|
||||
tabRect.origin.y+imageSize.height)
|
||||
operation:NSCompositeSourceOver];
|
||||
tabRect.size.width -= imageSize.width;
|
||||
tabRect.origin.x += imageSize.width;
|
||||
}
|
||||
[super drawLabel:shouldTruncateLabel inRect:tabRect];
|
||||
}
|
||||
- (NSImage*)image
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
- (void)setImage:(NSImage*)image
|
||||
{
|
||||
[image retain];
|
||||
[m_image release];
|
||||
m_image = image;
|
||||
if(!m_image)
|
||||
return;
|
||||
[[NSPasteboard generalPasteboard]
|
||||
declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]
|
||||
owner:nil];
|
||||
[[NSPasteboard generalPasteboard]
|
||||
setData:[m_image TIFFRepresentation]
|
||||
forType:NSTIFFPboardType];
|
||||
}
|
||||
@end // implementation WXCTabViewImageItem : NSTabViewItem
|
||||
|
||||
|
||||
class wxCocoaTabView : public wxWidgetCocoaImpl
|
||||
{
|
||||
public:
|
||||
@@ -143,7 +221,7 @@ public:
|
||||
{
|
||||
for ( int i = cocoacount ; i < maximum ; ++i )
|
||||
{
|
||||
NSTabViewItem* item = [[NSTabViewItem alloc] init];
|
||||
NSTabViewItem* item = [[WXCTabViewImageItem alloc] init];
|
||||
[slf addTabViewItem:item];
|
||||
[item release];
|
||||
}
|
||||
@@ -177,7 +255,7 @@ public:
|
||||
const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ;
|
||||
if ( bmap.IsOk() )
|
||||
{
|
||||
// TODO how to set an image on a tab
|
||||
[(WXCTabViewImageItem*) item setImage: bmap.GetNSImage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user