]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/notebook.mm
Big wxDataViewCtrl renderer classes refactoring.
[wxWidgets.git] / src / osx / cocoa / notebook.mm
CommitLineData
f033830e
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/cocoa/notebook.mm
3// Purpose: implementation of wxNotebook
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id: notebmac.cpp 55079 2008-08-13 14:56:42Z PC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#if wxUSE_NOTEBOOK
15
16#include "wx/notebook.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/string.h"
20 #include "wx/log.h"
21 #include "wx/app.h"
22 #include "wx/image.h"
23#endif
24
25#include "wx/string.h"
26#include "wx/imaglist.h"
27#include "wx/osx/private.h"
28
dbeddfb9
SC
29//
30// controller
31//
32
33@interface wxTabViewController : NSObject
34{
35}
36
37- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem;
38- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
39
40@end
41
f033830e
SC
42@interface wxNSTabView : NSTabView
43{
f033830e
SC
44}
45
f033830e
SC
46@end
47
dbeddfb9 48@implementation wxTabViewController
f033830e 49
dbeddfb9 50- (id) init
f033830e 51{
dbeddfb9
SC
52 [super init];
53 return self;
f033830e
SC
54}
55
dbeddfb9 56- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
f033830e 57{
d8207702 58 wxUnusedVar(tabViewItem);
dbeddfb9 59 wxNSTabView* view = (wxNSTabView*) tabView;
4dd9fdf8
SC
60 wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
61
dbeddfb9
SC
62 if ( viewimpl )
63 {
ffad7b0d 64 // wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
dbeddfb9
SC
65 }
66 return YES;
f033830e
SC
67}
68
dbeddfb9
SC
69- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
70
f033830e 71{
d8207702 72 wxUnusedVar(tabViewItem);
dbeddfb9 73 wxNSTabView* view = (wxNSTabView*) tabView;
4dd9fdf8 74 wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
dbeddfb9
SC
75 if ( viewimpl )
76 {
77 wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
04236b74 78 wxpeer->OSXHandleClicked(0);
dbeddfb9
SC
79 }
80}
81
82@end
83
84@implementation wxNSTabView
85
4dd9fdf8
SC
86+ (void)initialize
87{
88 static BOOL initialized = NO;
03647350 89 if (!initialized)
4dd9fdf8
SC
90 {
91 initialized = YES;
92 wxOSXCocoaClassAddWXMethods( self );
93 }
94}
f033830e
SC
95
96@end
97
dbeddfb9
SC
98class wxCocoaTabView : public wxWidgetCocoaImpl
99{
100public:
101 wxCocoaTabView( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
102 {
103 }
03647350
VZ
104
105 void GetContentArea( int &left , int &top , int &width , int &height ) const
dbeddfb9
SC
106 {
107 wxNSTabView* slf = (wxNSTabView*) m_osxView;
108 NSRect r = [slf contentRect];
e490b0d2
VZ
109 left = (int)r.origin.x;
110 top = (int)r.origin.y;
111 width = (int)r.size.width;
112 height = (int)r.size.height;
dbeddfb9 113 }
03647350
VZ
114
115 void SetValue( wxInt32 value )
dbeddfb9
SC
116 {
117 wxNSTabView* slf = (wxNSTabView*) m_osxView;
118 // avoid 'changed' events when setting the tab programmatically
119 wxTabViewController* controller = [slf delegate];
120 [slf setDelegate:nil];
121 [slf selectTabViewItemAtIndex:(value-1)];
122 [slf setDelegate:controller];
123 }
03647350 124
dbeddfb9
SC
125 wxInt32 GetValue() const
126 {
127 wxNSTabView* slf = (wxNSTabView*) m_osxView;
128 NSTabViewItem* selectedItem = [slf selectedTabViewItem];
129 if ( selectedItem == nil )
130 return 0;
131 else
132 return [slf indexOfTabViewItem:selectedItem]+1;
133 }
03647350 134
dbeddfb9
SC
135 void SetMaximum( wxInt32 maximum )
136 {
137 wxNSTabView* slf = (wxNSTabView*) m_osxView;
138 int cocoacount = [slf numberOfTabViewItems ];
139 // avoid 'changed' events when setting the tab programmatically
140 wxTabViewController* controller = [slf delegate];
141 [slf setDelegate:nil];
03647350 142
dbeddfb9
SC
143 if ( maximum > cocoacount )
144 {
145 for ( int i = cocoacount ; i < maximum ; ++i )
146 {
147 NSTabViewItem* item = [[NSTabViewItem alloc] init];
148 [slf addTabViewItem:item];
149 [item release];
150 }
151 }
152 else if ( maximum < cocoacount )
153 {
154 for ( int i = cocoacount -1 ; i >= maximum ; --i )
155 {
156 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
157 [slf removeTabViewItem:item];
158 }
159 }
160 [slf setDelegate:controller];
161 }
162
163 void SetupTabs( const wxNotebook& notebook)
164 {
165 int pcount = notebook.GetPageCount();
03647350 166
dbeddfb9 167 SetMaximum( pcount );
03647350 168
dbeddfb9
SC
169 for ( int i = 0 ; i < pcount ; ++i )
170 {
171 wxNotebookPage* page = notebook.GetPage(i);
172 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
173 [item setView:page->GetHandle() ];
174 wxCFStringRef cf( page->GetLabel() , notebook.GetFont().GetEncoding() );
175 [item setLabel:cf.AsNSString()];
176 if ( notebook.GetImageList() && notebook.GetPageImage(i) >= 0 )
177 {
178 const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ;
179 if ( bmap.Ok() )
180 {
181 // TODO how to set an image on a tab
182 }
183 }
184 }
185 }
186};
187
188
f033830e
SC
189/*
190#if 0
191 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
192
193 if ( bounds.right <= bounds.left )
194 bounds.right = bounds.left + 100;
195 if ( bounds.bottom <= bounds.top )
196 bounds.bottom = bounds.top + 100;
197
198 UInt16 tabstyle = kControlTabDirectionNorth;
199 if ( HasFlag(wxBK_LEFT) )
200 tabstyle = kControlTabDirectionWest;
201 else if ( HasFlag( wxBK_RIGHT ) )
202 tabstyle = kControlTabDirectionEast;
203 else if ( HasFlag( wxBK_BOTTOM ) )
204 tabstyle = kControlTabDirectionSouth;
205
206 ControlTabSize tabsize;
207 switch (GetWindowVariant())
208 {
209 case wxWINDOW_VARIANT_MINI:
210 tabsize = 3 ;
211 break;
212
213 case wxWINDOW_VARIANT_SMALL:
214 tabsize = kControlTabSizeSmall;
215 break;
216
217 default:
218 tabsize = kControlTabSizeLarge;
219 break;
220 }
221
222 m_peer = new wxMacControl( this );
223 OSStatus err = CreateTabsControl(
224 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
225 tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() );
226 verify_noerr( err );
227#endif
228*/
03647350
VZ
229wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
230 wxWindowMac* WXUNUSED(parent),
231 wxWindowID WXUNUSED(id),
232 const wxPoint& pos,
f033830e 233 const wxSize& size,
03647350 234 long style,
d8207702 235 long WXUNUSED(extraStyle))
f033830e 236{
dbeddfb9
SC
237 static wxTabViewController* controller = NULL;
238
239 if ( !controller )
240 controller =[[wxTabViewController alloc] init];
241
dbeddfb9 242 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
03647350 243
f033830e 244 NSTabViewType tabstyle = NSTopTabsBezelBorder;
dbeddfb9 245 if ( style & wxBK_LEFT )
f033830e
SC
246 tabstyle = NSLeftTabsBezelBorder;
247 else if ( style & wxBK_RIGHT )
248 tabstyle = NSRightTabsBezelBorder;
249 else if ( style & wxBK_BOTTOM )
250 tabstyle = NSBottomTabsBezelBorder;
03647350 251
f033830e 252 wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
f033830e 253 [v setTabViewType:tabstyle];
dbeddfb9 254 wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
dbeddfb9 255 [v setDelegate: controller];
f033830e
SC
256 return c;
257}
258
f033830e 259#endif