1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/notebook.mm
3 // Purpose: implementation of wxNotebook
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: notebmac.cpp 55079 2008-08-13 14:56:42Z PC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/notebook.h"
19 #include "wx/string.h"
25 #include "wx/string.h"
26 #include "wx/imaglist.h"
27 #include "wx/osx/private.h"
29 @interface wxNSTabView : NSTabView
34 - (void)setImplementation: (wxWidgetImpl *) theImplementation;
35 - (wxWidgetImpl*) implementation;
38 - (void) setIntValue:(int) v;
42 @implementation wxNSTabView
44 - (void)setImplementation: (wxWidgetImpl *) theImplementation
46 m_impl = theImplementation;
49 - (wxWidgetImpl*) implementation
61 NSTabViewItem* selectedItem = [self selectedTabViewItem];
62 if ( selectedItem == nil )
65 return [self indexOfTabViewItem:selectedItem]+1;
68 - (void) setIntValue:(int) v
70 [self selectTabViewItemAtIndex:(v-1)];
77 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
79 if ( bounds.right <= bounds.left )
80 bounds.right = bounds.left + 100;
81 if ( bounds.bottom <= bounds.top )
82 bounds.bottom = bounds.top + 100;
84 UInt16 tabstyle = kControlTabDirectionNorth;
85 if ( HasFlag(wxBK_LEFT) )
86 tabstyle = kControlTabDirectionWest;
87 else if ( HasFlag( wxBK_RIGHT ) )
88 tabstyle = kControlTabDirectionEast;
89 else if ( HasFlag( wxBK_BOTTOM ) )
90 tabstyle = kControlTabDirectionSouth;
92 ControlTabSize tabsize;
93 switch (GetWindowVariant())
95 case wxWINDOW_VARIANT_MINI:
99 case wxWINDOW_VARIANT_SMALL:
100 tabsize = kControlTabSizeSmall;
104 tabsize = kControlTabSizeLarge;
108 m_peer = new wxMacControl( this );
109 OSStatus err = CreateTabsControl(
110 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
111 tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() );
115 wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
123 NSView* sv = (wxpeer->GetParent()->GetHandle() );
125 NSRect r = wxToNSRect( sv, wxRect( pos, size) );
126 // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
127 /* if ( bounds.right <= bounds.left )
128 bounds.right = bounds.left + 100;
129 if ( bounds.bottom <= bounds.top )
130 bounds.bottom = bounds.top + 100;
133 NSTabViewType tabstyle = NSTopTabsBezelBorder;
134 if ( style & wxBK_LEFT )
135 tabstyle = NSLeftTabsBezelBorder;
136 else if ( style & wxBK_RIGHT )
137 tabstyle = NSRightTabsBezelBorder;
138 else if ( style & wxBK_BOTTOM )
139 tabstyle = NSBottomTabsBezelBorder;
141 wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
143 [v setTabViewType:tabstyle];
144 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
145 [v setImplementation:c];
149 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& notebook)
151 int pcount = notebook.GetPageCount();
152 int cocoacount = [ (wxNSTabView*) m_osxView numberOfTabViewItems ];
154 if ( pcount > cocoacount )
156 for ( int i = cocoacount ; i < pcount ; ++i )
158 NSTabViewItem* item = [[NSTabViewItem alloc] init];
159 [(wxNSTabView*) m_osxView addTabViewItem:item];
163 else if ( pcount < cocoacount )
165 for ( int i = cocoacount -1 ; i >= pcount ; --i )
167 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
168 [(wxNSTabView*) m_osxView removeTabViewItem:item];
172 for ( int i = 0 ; i < pcount ; ++i )
174 wxNotebookPage* page = notebook.GetPage(i);
175 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
176 [item setLabel:wxCFStringRef( page->GetLabel() , notebook.GetFont().GetEncoding() ).AsNSString()];
179 SetMaximum( GetPageCount() ) ;
181 wxNotebookPage *page;
182 ControlTabInfoRecV1 info;
184 const size_t countPages = GetPageCount();
185 for (size_t ii = 0; ii < countPages; ii++)
187 page = (wxNotebookPage*) notebook->GetPage[ii];
188 info.version = kControlTabInfoVersionOne;
189 info.iconSuiteID = 0;
190 wxCFStringRef cflabel( page->GetLabel(), GetFont().GetEncoding() ) ;
191 info.name = cflabel ;
192 SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
194 if ( GetImageList() && GetPageImage(ii) >= 0 )
196 const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ;
199 ControlButtonContentInfo info ;
201 wxMacCreateBitmapButton( &info, bmap ) ;
203 OSStatus err = SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
206 wxFAIL_MSG("Error when setting icon on tab");
209 wxMacReleaseBitmapButton( &info ) ;
212 SetTabEnabled( ii + 1, true ) ;