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