X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f033830e257227dc73225809de2326db0093e5fe..60372b0d54379701d62edf5595a7dc25c48330e1:/src/osx/cocoa/notebook.mm diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index 297650a554..ff4e70b7c7 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 /////////////////////////////////////////////////////////////////////////////// @@ -26,52 +26,165 @@ #include "wx/imaglist.h" #include "wx/osx/private.h" -@interface wxNSTabView : NSTabView +// +// controller +// + +@interface wxTabViewController : NSObject wxOSX_10_6_AND_LATER() { - wxWidgetImpl* m_impl; } -- (void)setImplementation: (wxWidgetImpl *) theImplementation; -- (wxWidgetImpl*) implementation; -- (BOOL) isFlipped; -- (int) intValue; -- (void) setIntValue:(int) v; +- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem; +- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem; @end -@implementation wxNSTabView - -- (void)setImplementation: (wxWidgetImpl *) theImplementation +@interface wxNSTabView : NSTabView { - m_impl = theImplementation; } -- (wxWidgetImpl*) implementation +@end + +@implementation wxTabViewController + +- (id) init { - return m_impl; + self = [super init]; + return self; } -- (BOOL) isFlipped +- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem { + wxUnusedVar(tabViewItem); + wxNSTabView* view = (wxNSTabView*) tabView; + wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view ); + + if ( viewimpl ) + { + // wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer(); + } return YES; } -- (int) intValue +- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem { - NSTabViewItem* selectedItem = [self selectedTabViewItem]; - if ( selectedItem == nil ) - return 0; - else - return [self indexOfTabViewItem:selectedItem]+1; + wxUnusedVar(tabViewItem); + wxNSTabView* view = (wxNSTabView*) tabView; + wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view ); + if ( viewimpl ) + { + wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer(); + wxpeer->OSXHandleClicked(0); + } } -- (void) setIntValue:(int) v +@end + +@implementation wxNSTabView + ++ (void)initialize { - [self selectTabViewItemAtIndex:(v-1)]; + static BOOL initialized = NO; + if (!initialized) + { + initialized = YES; + wxOSXCocoaClassAddWXMethods( self ); + } } @end +class wxCocoaTabView : public wxWidgetCocoaImpl +{ +public: + wxCocoaTabView( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w) + { + } + + void GetContentArea( int &left , int &top , int &width , int &height ) const + { + wxNSTabView* slf = (wxNSTabView*) m_osxView; + NSRect r = [slf contentRect]; + left = (int)r.origin.x; + top = (int)r.origin.y; + width = (int)r.size.width; + height = (int)r.size.height; + } + + void SetValue( wxInt32 value ) + { + wxNSTabView* slf = (wxNSTabView*) m_osxView; + // avoid 'changed' events when setting the tab programmatically + wxTabViewController* controller = [slf delegate]; + [slf setDelegate:nil]; + [slf selectTabViewItemAtIndex:(value-1)]; + [slf setDelegate:controller]; + } + + wxInt32 GetValue() const + { + wxNSTabView* slf = (wxNSTabView*) m_osxView; + NSTabViewItem* selectedItem = [slf selectedTabViewItem]; + if ( selectedItem == nil ) + return 0; + else + return [slf indexOfTabViewItem:selectedItem]+1; + } + + void SetMaximum( wxInt32 maximum ) + { + wxNSTabView* slf = (wxNSTabView*) m_osxView; + int cocoacount = [slf numberOfTabViewItems ]; + // 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 ) + { + NSTabViewItem* item = [[NSTabViewItem alloc] init]; + [slf addTabViewItem:item]; + [item release]; + } + } + else if ( maximum < cocoacount ) + { + for ( int i = cocoacount -1 ; i >= maximum ; --i ) + { + NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]; + [slf removeTabViewItem:item]; + } + } + [slf setDelegate:controller]; + } + + void SetupTabs( const wxNotebook& notebook) + { + int pcount = notebook.GetPageCount(); + + SetMaximum( pcount ); + + for ( int i = 0 ; i < pcount ; ++i ) + { + wxNotebookPage* page = notebook.GetPage(i); + NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]; + [item setView:page->GetHandle() ]; + wxCFStringRef cf( page->GetLabel() , notebook.GetFont().GetEncoding() ); + [item setLabel:cf.AsNSString()]; + if ( notebook.GetImageList() && notebook.GetPageImage(i) >= 0 ) + { + const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ; + if ( bmap.IsOk() ) + { + // TODO how to set an image on a tab + } + } + } + } +}; + + /* #if 0 Rect bounds = wxMacGetBoundsForControl( this, pos, size ); @@ -108,110 +221,38 @@ 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 */ -wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer, - wxWindowMac* parent, - wxWindowID id, - const wxPoint& pos, +wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), + const wxPoint& pos, const wxSize& size, - long style, - long extraStyle) + long style, + long WXUNUSED(extraStyle)) { - NSView* sv = (wxpeer->GetParent()->GetHandle() ); - - NSRect r = wxToNSRect( sv, wxRect( pos, size) ); - // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ; - /* if ( bounds.right <= bounds.left ) - bounds.right = bounds.left + 100; - if ( bounds.bottom <= bounds.top ) - bounds.bottom = bounds.top + 100; - */ - + static wxTabViewController* controller = NULL; + + if ( !controller ) + controller =[[wxTabViewController alloc] init]; + + NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; + NSTabViewType tabstyle = NSTopTabsBezelBorder; - if ( style & wxBK_LEFT ) + if ( style & wxBK_LEFT ) tabstyle = NSLeftTabsBezelBorder; else if ( style & wxBK_RIGHT ) tabstyle = NSRightTabsBezelBorder; else if ( style & wxBK_BOTTOM ) tabstyle = NSBottomTabsBezelBorder; - + wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r]; - [sv addSubview:v]; [v setTabViewType:tabstyle]; - wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); - [v setImplementation:c]; + wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v ); + [v setDelegate: controller]; return c; } -void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& notebook) -{ - int pcount = notebook.GetPageCount(); - int cocoacount = [ (wxNSTabView*) m_osxView numberOfTabViewItems ]; - - if ( pcount > cocoacount ) - { - for ( int i = cocoacount ; i < pcount ; ++i ) - { - NSTabViewItem* item = [[NSTabViewItem alloc] init]; - [(wxNSTabView*) m_osxView addTabViewItem:item]; - [item release]; - } - } - else if ( pcount < cocoacount ) - { - for ( int i = cocoacount -1 ; i >= pcount ; --i ) - { - NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]; - [(wxNSTabView*) m_osxView removeTabViewItem:item]; - } - } - - for ( int i = 0 ; i < pcount ; ++i ) - { - wxNotebookPage* page = notebook.GetPage(i); - NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]; - [item setLabel:wxCFStringRef( page->GetLabel() , notebook.GetFont().GetEncoding() ).AsNSString()]; - } -/* - SetMaximum( GetPageCount() ) ; - - wxNotebookPage *page; - ControlTabInfoRecV1 info; - - const size_t countPages = GetPageCount(); - for (size_t ii = 0; ii < countPages; ii++) - { - page = (wxNotebookPage*) notebook->GetPage[ii]; - info.version = kControlTabInfoVersionOne; - info.iconSuiteID = 0; - wxCFStringRef cflabel( page->GetLabel(), GetFont().GetEncoding() ) ; - info.name = cflabel ; - SetData( ii + 1, kControlTabInfoTag, &info ) ; - - if ( GetImageList() && GetPageImage(ii) >= 0 ) - { - const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ; - if ( bmap.Ok() ) - { - ControlButtonContentInfo info ; - - wxMacCreateBitmapButton( &info, bmap ) ; - - OSStatus err = SetData( ii + 1, kControlTabImageContentTag, &info ); - if ( err != noErr ) - { - wxFAIL_MSG("Error when setting icon on tab"); - } - - wxMacReleaseBitmapButton( &info ) ; - } - } - SetTabEnabled( ii + 1, true ) ; - } -*/ -} - #endif