]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/notebook.mm
define MIIM_BITMAP &c in wx/msw/missing.h instead of msw/menu.cpp as menuitem.cpp...
[wxWidgets.git] / src / osx / cocoa / notebook.mm
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
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
42 @interface wxNSTabView : NSTabView
43 {
44 WXCOCOAIMPL_COMMON_MEMBERS
45 }
46
47 WXCOCOAIMPL_COMMON_INTERFACE
48
49 @end
50
51 @implementation wxTabViewController
52
53 - (id) init
54 {
55 [super init];
56 return self;
57 }
58
59 - (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
60 {
61 wxNSTabView* view = (wxNSTabView*) tabView;
62 wxWidgetCocoaImpl* viewimpl = [view implementation];
63 if ( viewimpl )
64 {
65 // wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
66 }
67 return YES;
68 }
69
70 - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
71
72 {
73 wxNSTabView* view = (wxNSTabView*) tabView;
74 wxWidgetCocoaImpl* viewimpl = [view implementation];
75 if ( viewimpl )
76 {
77 wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
78 wxpeer->OSXHandleClicked(0);
79 }
80 }
81
82 @end
83
84 @implementation wxNSTabView
85
86 WXCOCOAIMPL_COMMON_IMPLEMENTATION
87
88 @end
89
90 class wxCocoaTabView : public wxWidgetCocoaImpl
91 {
92 public:
93 wxCocoaTabView( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
94 {
95 }
96
97 void GetContentArea( int &left , int &top , int &width , int &height ) const
98 {
99 wxNSTabView* slf = (wxNSTabView*) m_osxView;
100 NSRect r = [slf contentRect];
101 left = r.origin.x;
102 top = r.origin.y;
103 width = r.size.width;
104 height = r.size.height;
105 }
106
107 void SetValue( wxInt32 value )
108 {
109 wxNSTabView* slf = (wxNSTabView*) m_osxView;
110 // avoid 'changed' events when setting the tab programmatically
111 wxTabViewController* controller = [slf delegate];
112 [slf setDelegate:nil];
113 [slf selectTabViewItemAtIndex:(value-1)];
114 [slf setDelegate:controller];
115 }
116
117 wxInt32 GetValue() const
118 {
119 wxNSTabView* slf = (wxNSTabView*) m_osxView;
120 NSTabViewItem* selectedItem = [slf selectedTabViewItem];
121 if ( selectedItem == nil )
122 return 0;
123 else
124 return [slf indexOfTabViewItem:selectedItem]+1;
125 }
126
127 void SetMaximum( wxInt32 maximum )
128 {
129 wxNSTabView* slf = (wxNSTabView*) m_osxView;
130 int cocoacount = [slf numberOfTabViewItems ];
131 // avoid 'changed' events when setting the tab programmatically
132 wxTabViewController* controller = [slf delegate];
133 [slf setDelegate:nil];
134
135 if ( maximum > cocoacount )
136 {
137 for ( int i = cocoacount ; i < maximum ; ++i )
138 {
139 NSTabViewItem* item = [[NSTabViewItem alloc] init];
140 [slf addTabViewItem:item];
141 [item release];
142 }
143 }
144 else if ( maximum < cocoacount )
145 {
146 for ( int i = cocoacount -1 ; i >= maximum ; --i )
147 {
148 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
149 [slf removeTabViewItem:item];
150 }
151 }
152 [slf setDelegate:controller];
153 }
154
155 void SetupTabs( const wxNotebook& notebook)
156 {
157 int pcount = notebook.GetPageCount();
158
159 SetMaximum( pcount );
160
161 for ( int i = 0 ; i < pcount ; ++i )
162 {
163 wxNotebookPage* page = notebook.GetPage(i);
164 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
165 [item setView:page->GetHandle() ];
166 wxCFStringRef cf( page->GetLabel() , notebook.GetFont().GetEncoding() );
167 [item setLabel:cf.AsNSString()];
168 if ( notebook.GetImageList() && notebook.GetPageImage(i) >= 0 )
169 {
170 const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ;
171 if ( bmap.Ok() )
172 {
173 // TODO how to set an image on a tab
174 }
175 }
176 }
177 }
178 };
179
180
181 /*
182 #if 0
183 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
184
185 if ( bounds.right <= bounds.left )
186 bounds.right = bounds.left + 100;
187 if ( bounds.bottom <= bounds.top )
188 bounds.bottom = bounds.top + 100;
189
190 UInt16 tabstyle = kControlTabDirectionNorth;
191 if ( HasFlag(wxBK_LEFT) )
192 tabstyle = kControlTabDirectionWest;
193 else if ( HasFlag( wxBK_RIGHT ) )
194 tabstyle = kControlTabDirectionEast;
195 else if ( HasFlag( wxBK_BOTTOM ) )
196 tabstyle = kControlTabDirectionSouth;
197
198 ControlTabSize tabsize;
199 switch (GetWindowVariant())
200 {
201 case wxWINDOW_VARIANT_MINI:
202 tabsize = 3 ;
203 break;
204
205 case wxWINDOW_VARIANT_SMALL:
206 tabsize = kControlTabSizeSmall;
207 break;
208
209 default:
210 tabsize = kControlTabSizeLarge;
211 break;
212 }
213
214 m_peer = new wxMacControl( this );
215 OSStatus err = CreateTabsControl(
216 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
217 tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() );
218 verify_noerr( err );
219 #endif
220 */
221 wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
222 wxWindowMac* parent,
223 wxWindowID id,
224 const wxPoint& pos,
225 const wxSize& size,
226 long style,
227 long extraStyle)
228 {
229 static wxTabViewController* controller = NULL;
230
231 if ( !controller )
232 controller =[[wxTabViewController alloc] init];
233
234 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
235
236 NSTabViewType tabstyle = NSTopTabsBezelBorder;
237 if ( style & wxBK_LEFT )
238 tabstyle = NSLeftTabsBezelBorder;
239 else if ( style & wxBK_RIGHT )
240 tabstyle = NSRightTabsBezelBorder;
241 else if ( style & wxBK_BOTTOM )
242 tabstyle = NSBottomTabsBezelBorder;
243
244 wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
245 [v setTabViewType:tabstyle];
246 wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
247 [v setImplementation:c];
248 [v setDelegate: controller];
249 return c;
250 }
251
252 #endif