]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/notebook.mm
add parentheses for && inside || to fix g++ 4.3 warning
[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 @interface wxNSTabView : NSTabView
30 {
31 wxWidgetImpl* m_impl;
32 }
33
34 - (void)setImplementation: (wxWidgetImpl *) theImplementation;
35 - (wxWidgetImpl*) implementation;
36 - (BOOL) isFlipped;
37 - (int) intValue;
38 - (void) setIntValue:(int) v;
39
40 @end
41
42 @implementation wxNSTabView
43
44 - (void)setImplementation: (wxWidgetImpl *) theImplementation
45 {
46 m_impl = theImplementation;
47 }
48
49 - (wxWidgetImpl*) implementation
50 {
51 return m_impl;
52 }
53
54 - (BOOL) isFlipped
55 {
56 return YES;
57 }
58
59 - (int) intValue
60 {
61 NSTabViewItem* selectedItem = [self selectedTabViewItem];
62 if ( selectedItem == nil )
63 return 0;
64 else
65 return [self indexOfTabViewItem:selectedItem]+1;
66 }
67
68 - (void) setIntValue:(int) v
69 {
70 [self selectTabViewItemAtIndex:(v-1)];
71 }
72
73 @end
74
75 /*
76 #if 0
77 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
78
79 if ( bounds.right <= bounds.left )
80 bounds.right = bounds.left + 100;
81 if ( bounds.bottom <= bounds.top )
82 bounds.bottom = bounds.top + 100;
83
84 UInt16 tabstyle = kControlTabDirectionNorth;
85 if ( HasFlag(wxBK_LEFT) )
86 tabstyle = kControlTabDirectionWest;
87 else if ( HasFlag( wxBK_RIGHT ) )
88 tabstyle = kControlTabDirectionEast;
89 else if ( HasFlag( wxBK_BOTTOM ) )
90 tabstyle = kControlTabDirectionSouth;
91
92 ControlTabSize tabsize;
93 switch (GetWindowVariant())
94 {
95 case wxWINDOW_VARIANT_MINI:
96 tabsize = 3 ;
97 break;
98
99 case wxWINDOW_VARIANT_SMALL:
100 tabsize = kControlTabSizeSmall;
101 break;
102
103 default:
104 tabsize = kControlTabSizeLarge;
105 break;
106 }
107
108 m_peer = new wxMacControl( this );
109 OSStatus err = CreateTabsControl(
110 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
111 tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() );
112 verify_noerr( err );
113 #endif
114 */
115 wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
116 wxWindowMac* parent,
117 wxWindowID id,
118 const wxPoint& pos,
119 const wxSize& size,
120 long style,
121 long extraStyle)
122 {
123 NSView* sv = (wxpeer->GetParent()->GetHandle() );
124
125 NSRect r = wxToNSRect( sv, wxRect( pos, size) );
126 // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
127 /* if ( bounds.right <= bounds.left )
128 bounds.right = bounds.left + 100;
129 if ( bounds.bottom <= bounds.top )
130 bounds.bottom = bounds.top + 100;
131 */
132
133 NSTabViewType tabstyle = NSTopTabsBezelBorder;
134 if ( style & wxBK_LEFT )
135 tabstyle = NSLeftTabsBezelBorder;
136 else if ( style & wxBK_RIGHT )
137 tabstyle = NSRightTabsBezelBorder;
138 else if ( style & wxBK_BOTTOM )
139 tabstyle = NSBottomTabsBezelBorder;
140
141 wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
142 [sv addSubview:v];
143 [v setTabViewType:tabstyle];
144 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
145 [v setImplementation:c];
146 return c;
147 }
148
149 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& notebook)
150 {
151 int pcount = notebook.GetPageCount();
152 int cocoacount = [ (wxNSTabView*) m_osxView numberOfTabViewItems ];
153
154 if ( pcount > cocoacount )
155 {
156 for ( int i = cocoacount ; i < pcount ; ++i )
157 {
158 NSTabViewItem* item = [[NSTabViewItem alloc] init];
159 [(wxNSTabView*) m_osxView addTabViewItem:item];
160 [item release];
161 }
162 }
163 else if ( pcount < cocoacount )
164 {
165 for ( int i = cocoacount -1 ; i >= pcount ; --i )
166 {
167 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
168 [(wxNSTabView*) m_osxView removeTabViewItem:item];
169 }
170 }
171
172 for ( int i = 0 ; i < pcount ; ++i )
173 {
174 wxNotebookPage* page = notebook.GetPage(i);
175 NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
176 [item setLabel:wxCFStringRef( page->GetLabel() , notebook.GetFont().GetEncoding() ).AsNSString()];
177 }
178 /*
179 SetMaximum( GetPageCount() ) ;
180
181 wxNotebookPage *page;
182 ControlTabInfoRecV1 info;
183
184 const size_t countPages = GetPageCount();
185 for (size_t ii = 0; ii < countPages; ii++)
186 {
187 page = (wxNotebookPage*) notebook->GetPage[ii];
188 info.version = kControlTabInfoVersionOne;
189 info.iconSuiteID = 0;
190 wxCFStringRef cflabel( page->GetLabel(), GetFont().GetEncoding() ) ;
191 info.name = cflabel ;
192 SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
193
194 if ( GetImageList() && GetPageImage(ii) >= 0 )
195 {
196 const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ;
197 if ( bmap.Ok() )
198 {
199 ControlButtonContentInfo info ;
200
201 wxMacCreateBitmapButton( &info, bmap ) ;
202
203 OSStatus err = SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
204 if ( err != noErr )
205 {
206 wxFAIL_MSG("Error when setting icon on tab");
207 }
208
209 wxMacReleaseBitmapButton( &info ) ;
210 }
211 }
212 SetTabEnabled( ii + 1, true ) ;
213 }
214 */
215 }
216
217 #endif