X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c8fdb345a0467b910260af935353b360bfcbd4f0..7c60222510bc5e197b12f153c4bf05db66cb0f4a:/src/osx/cocoa/notebook.mm diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index bba36f5d94..86820dc0ea 100644 --- a/src/osx/cocoa/notebook.mm +++ b/src/osx/cocoa/notebook.mm @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: notebmac.cpp 55079 2008-08-13 14:56:42Z PC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -49,7 +49,7 @@ - (id) init { - [super init]; + self = [super init]; return self; } @@ -66,8 +66,7 @@ return YES; } -- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem; - +- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem { wxUnusedVar(tabViewItem); wxNSTabView* view = (wxNSTabView*) tabView; @@ -95,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: @@ -144,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]; } @@ -176,13 +253,35 @@ public: if ( notebook.GetImageList() && notebook.GetPageImage(i) >= 0 ) { const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ; - if ( bmap.Ok() ) + if ( bmap.IsOk() ) { - // TODO how to set an image on a tab + [(WXCTabViewImageItem*) item setImage: bmap.GetNSImage()]; } } } } + + int TabHitTest(const wxPoint & pt, long* flags) + { + int retval = wxNOT_FOUND; + + NSPoint nspt = wxToNSPoint( m_osxView, pt ); + + wxNSTabView* slf = (wxNSTabView*) m_osxView; + + NSTabViewItem* hitItem = [slf tabViewItemAtPoint:nspt]; + + if (!hitItem) { + if ( flags ) + *flags = wxBK_HITTEST_NOWHERE; + } else { + retval = [slf indexOfTabViewItem:hitItem]; + if ( flags ) + *flags = wxBK_HITTEST_ONLABEL; + } + + return retval; + } }; @@ -222,7 +321,7 @@ public: m_peer = new wxMacControl( this ); OSStatus err = CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, - tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() ); + tabsize, tabstyle, 0, NULL, GetPeer()->GetControlRefAddr() ); verify_noerr( err ); #endif */