]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/notebook.mm
fixing class
[wxWidgets.git] / src / osx / cocoa / notebook.mm
index b62b66e6f1a8923095391644c658bcbe88386312..c314bc6389e4ec0eeafccc4801a944ea9770fa9d 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
 // 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
 ///////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
@@ -30,7 +30,7 @@
 // controller
 //
 
 // controller
 //
 
-@interface wxTabViewController : NSObject
+@interface wxTabViewController : NSObject wxOSX_10_6_AND_LATER(<NSTabViewDelegate>)
 {
 }
 
 {
 }
 
@@ -49,7 +49,7 @@
 
 - (id) init
 {
 
 - (id) init
 {
-    [super init];
+    self = [super init];
     return self;
 }
 
     return self;
 }
 
@@ -66,8 +66,7 @@
     return YES;
 }
 
     return YES;
 }
 
-- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
-
+- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
 {
     wxUnusedVar(tabViewItem);
     wxNSTabView* view = (wxNSTabView*) tabView;
 {
     wxUnusedVar(tabViewItem);
     wxNSTabView* view = (wxNSTabView*) tabView;
@@ -86,7 +85,7 @@
 + (void)initialize
 {
     static BOOL initialized = NO;
 + (void)initialize
 {
     static BOOL initialized = NO;
-    if (!initialized) 
+    if (!initialized)
     {
         initialized = YES;
         wxOSXCocoaClassAddWXMethods( self );
     {
         initialized = YES;
         wxOSXCocoaClassAddWXMethods( self );
 
 @end
 
 
 @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:
     wxCocoaTabView( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
     {
     }
 class wxCocoaTabView : public wxWidgetCocoaImpl
 {
 public:
     wxCocoaTabView( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
     {
     }
-    
-    void GetContentArea( int &left , int &top , int &width , int &height ) const 
+
+    void GetContentArea( int &left , int &top , int &width , int &height ) const
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
         NSRect r = [slf contentRect];
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
         NSRect r = [slf contentRect];
@@ -111,8 +188,8 @@ public:
         width = (int)r.size.width;
         height = (int)r.size.height;
     }
         width = (int)r.size.width;
         height = (int)r.size.height;
     }
-    
-    void SetValue( wxInt32 value ) 
+
+    void SetValue( wxInt32 value )
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
         // avoid 'changed' events when setting the tab programmatically
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
         // avoid 'changed' events when setting the tab programmatically
@@ -121,7 +198,7 @@ public:
         [slf selectTabViewItemAtIndex:(value-1)];
         [slf setDelegate:controller];
     }
         [slf selectTabViewItemAtIndex:(value-1)];
         [slf setDelegate:controller];
     }
-    
+
     wxInt32 GetValue() const
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
     wxInt32 GetValue() const
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
@@ -131,7 +208,7 @@ public:
         else
             return [slf indexOfTabViewItem:selectedItem]+1;
     }
         else
             return [slf indexOfTabViewItem:selectedItem]+1;
     }
-    
+
     void SetMaximum( wxInt32 maximum )
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
     void SetMaximum( wxInt32 maximum )
     {
         wxNSTabView* slf = (wxNSTabView*) m_osxView;
@@ -139,12 +216,12 @@ public:
         // avoid 'changed' events when setting the tab programmatically
         wxTabViewController* controller = [slf delegate];
         [slf setDelegate:nil];
         // avoid 'changed' events when setting the tab programmatically
         wxTabViewController* controller = [slf delegate];
         [slf setDelegate:nil];
-        
+
         if ( maximum > cocoacount )
         {
             for ( int i = cocoacount ; i < maximum ; ++i )
             {
         if ( maximum > cocoacount )
         {
             for ( int i = cocoacount ; i < maximum ; ++i )
             {
-                NSTabViewItem* item = [[NSTabViewItem alloc] init];
+                NSTabViewItem* item = [[WXCTabViewImageItem alloc] init];
                 [slf addTabViewItem:item];
                 [item release];
             }
                 [slf addTabViewItem:item];
                 [item release];
             }
@@ -163,9 +240,9 @@ public:
     void SetupTabs( const wxNotebook& notebook)
     {
         int pcount = notebook.GetPageCount();
     void SetupTabs( const wxNotebook& notebook)
     {
         int pcount = notebook.GetPageCount();
-        
+
         SetMaximum( pcount );
         SetMaximum( pcount );
-        
+
         for ( int i = 0 ; i < pcount ; ++i )
         {
             wxNotebookPage* page = notebook.GetPage(i);
         for ( int i = 0 ; i < pcount ; ++i )
         {
             wxNotebookPage* page = notebook.GetPage(i);
@@ -176,9 +253,9 @@ public:
             if ( notebook.GetImageList() && notebook.GetPageImage(i) >= 0 )
             {
                 const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ;
             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()];
                 }
             }
         }
                 }
             }
         }
@@ -222,16 +299,16 @@ public:
     m_peer = new wxMacControl( this );
     OSStatus err = CreateTabsControl(
         MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
     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
 */
     verify_noerr( err );
 #endif
 */
-wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer, 
-                                    wxWindowMac* WXUNUSED(parent), 
-                                    wxWindowID WXUNUSED(id), 
-                                    const wxPoint& pos, 
+wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
+                                    wxWindowMac* WXUNUSED(parent),
+                                    wxWindowID WXUNUSED(id),
+                                    const wxPoint& pos,
                                     const wxSize& size,
                                     const wxSize& size,
-                                    long style, 
+                                    long style,
                                     long WXUNUSED(extraStyle))
 {
     static wxTabViewController* controller = NULL;
                                     long WXUNUSED(extraStyle))
 {
     static wxTabViewController* controller = NULL;
@@ -240,7 +317,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
         controller =[[wxTabViewController alloc] init];
 
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
         controller =[[wxTabViewController alloc] init];
 
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
-    
+
     NSTabViewType tabstyle = NSTopTabsBezelBorder;
     if ( style & wxBK_LEFT )
         tabstyle = NSLeftTabsBezelBorder;
     NSTabViewType tabstyle = NSTopTabsBezelBorder;
     if ( style & wxBK_LEFT )
         tabstyle = NSLeftTabsBezelBorder;
@@ -248,7 +325,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
         tabstyle = NSRightTabsBezelBorder;
     else if ( style & wxBK_BOTTOM )
         tabstyle = NSBottomTabsBezelBorder;
         tabstyle = NSRightTabsBezelBorder;
     else if ( style & wxBK_BOTTOM )
         tabstyle = NSBottomTabsBezelBorder;
-    
+
     wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
     [v setTabViewType:tabstyle];
     wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
     wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
     [v setTabViewType:tabstyle];
     wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );