]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/notebook.mm
Fixed bug: wxPropertyGridInterface::SetPropertyReadOnly() with wxPG_DONT_RECURSE...
[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 }
45
46 @end
47
48 @implementation wxTabViewController
49
50 - (id) init
51 {
52 [super init];
53 return self;
54 }
55
56 - (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
57 {
58 wxUnusedVar(tabViewItem);
59 wxNSTabView* view = (wxNSTabView*) tabView;
60 wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
61
62 if ( viewimpl )
63 {
64 // wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
65 }
66 return YES;
67 }
68
69 - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
70
71 {
72 wxUnusedVar(tabViewItem);
73 wxNSTabView* view = (wxNSTabView*) tabView;
74 wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
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 + (void)initialize
87 {
88 static BOOL initialized = NO;
89 if (!initialized)
90 {
91 initialized = YES;
92 wxOSXCocoaClassAddWXMethods( self );
93 }
94 }
95
96 @end
97
98 class wxCocoaTabView : public wxWidgetCocoaImpl
99 {
100 public:
101 wxCocoaTabView( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
102 {
103 }
104
105 void GetContentArea( int &left , int &top , int &width , int &height ) const
106 {
107 wxNSTabView* slf = (wxNSTabView*) m_osxView;
108 NSRect r = [slf contentRect];
109 left = r.origin.x;
110 top = r.origin.y;
111 width = r.size.width;
112 height = r.size.height;
113 }
114
115 void SetValue( wxInt32 value )
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 }
124
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 }
134
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];
142
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();
166
167 SetMaximum( pcount );
168
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
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 */
229 wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
230 wxWindowMac* WXUNUSED(parent),
231 wxWindowID WXUNUSED(id),
232 const wxPoint& pos,
233 const wxSize& size,
234 long style,
235 long WXUNUSED(extraStyle))
236 {
237 static wxTabViewController* controller = NULL;
238
239 if ( !controller )
240 controller =[[wxTabViewController alloc] init];
241
242 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
243
244 NSTabViewType tabstyle = NSTopTabsBezelBorder;
245 if ( style & wxBK_LEFT )
246 tabstyle = NSLeftTabsBezelBorder;
247 else if ( style & wxBK_RIGHT )
248 tabstyle = NSRightTabsBezelBorder;
249 else if ( style & wxBK_BOTTOM )
250 tabstyle = NSBottomTabsBezelBorder;
251
252 wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
253 [v setTabViewType:tabstyle];
254 wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
255 [v setDelegate: controller];
256 return c;
257 }
258
259 #endif