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