]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/notebmac.cpp
support for raw ctrl shortcut
[wxWidgets.git] / src / osx / carbon / notebmac.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/notebmac.cpp
3 // Purpose: implementation of wxNotebook
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
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 // check that the page index is valid
31 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
32
33 wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
34 wxWindowMac* parent,
35 wxWindowID WXUNUSED(id),
36 const wxPoint& pos,
37 const wxSize& size,
38 long style,
39 long WXUNUSED(extraStyle))
40 {
41 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
42
43 if ( bounds.right <= bounds.left )
44 bounds.right = bounds.left + 100;
45 if ( bounds.bottom <= bounds.top )
46 bounds.bottom = bounds.top + 100;
47
48 UInt16 tabstyle = kControlTabDirectionNorth;
49 if ( style & wxBK_LEFT )
50 tabstyle = kControlTabDirectionWest;
51 else if ( style & wxBK_RIGHT )
52 tabstyle = kControlTabDirectionEast;
53 else if ( style & wxBK_BOTTOM )
54 tabstyle = kControlTabDirectionSouth;
55
56 ControlTabSize tabsize;
57 switch (wxpeer->GetWindowVariant())
58 {
59 case wxWINDOW_VARIANT_MINI:
60 tabsize = 3 ;
61 break;
62
63 case wxWINDOW_VARIANT_SMALL:
64 tabsize = kControlTabSizeSmall;
65 break;
66
67 default:
68 tabsize = kControlTabSizeLarge;
69 break;
70 }
71
72 wxMacControl* peer = new wxMacControl( wxpeer );
73 OSStatus err = CreateTabsControl(
74 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
75 tabsize, tabstyle, 0, NULL, peer->GetControlRefAddr() );
76 verify_noerr( err );
77
78 return peer;
79 }
80
81
82
83
84
85 /*
86 int wxNotebook::HitTest(const wxPoint& pt, long * flags) const
87 {
88 int resultV = wxNOT_FOUND;
89
90 const int countPages = GetPageCount();
91
92 // we have to convert from Client to Window relative coordinates
93 wxPoint adjustedPt = pt + GetClientAreaOrigin();
94 // and now to HIView native ones
95 adjustedPt.x -= MacGetLeftBorderSize() ;
96 adjustedPt.y -= MacGetTopBorderSize() ;
97
98 HIPoint hipoint= { adjustedPt.x , adjustedPt.y } ;
99 HIViewPartCode outPart = 0 ;
100 OSStatus err = HIViewGetPartHit( GetPeer()->GetControlRef(), &hipoint, &outPart );
101
102 int max = GetPeer()->GetMaximum() ;
103 if ( outPart == 0 && max > 0 )
104 {
105 // this is a hack, as unfortunately a hit on an already selected tab returns 0,
106 // so we have to go some extra miles to make sure we select something different
107 // and try again ..
108 int val = GetPeer()->GetValue() ;
109 int maxval = max ;
110 if ( max == 1 )
111 {
112 GetPeer()->SetMaximum( 2 ) ;
113 maxval = 2 ;
114 }
115
116 if ( val == 1 )
117 GetPeer()->SetValue( maxval ) ;
118 else
119 GetPeer()->SetValue( 1 ) ;
120
121 err = HIViewGetPartHit( GetPeer()->GetControlRef(), &hipoint, &outPart );
122
123 GetPeer()->SetValue( val ) ;
124 if ( max == 1 )
125 GetPeer()->SetMaximum( 1 ) ;
126 }
127
128 if ( outPart >= 1 && outPart <= countPages )
129 resultV = outPart - 1 ;
130
131 if (flags != NULL)
132 {
133 *flags = 0;
134
135 // we cannot differentiate better
136 if (resultV >= 0)
137 *flags |= wxBK_HITTEST_ONLABEL;
138 else
139 *flags |= wxBK_HITTEST_NOWHERE;
140 }
141
142 return resultV;
143 }
144 */
145
146 // Added by Mark Newsam
147 // When a page is added or deleted to the notebook this function updates
148 // information held in the control so that it matches the order
149 // the user would expect.
150 //
151
152 void wxMacControl::SetupTabs( const wxNotebook& notebook)
153 {
154 const size_t countPages = notebook.GetPageCount();
155 SetMaximum( countPages ) ;
156
157 wxNotebookPage *page;
158 ControlTabInfoRecV1 info;
159
160 for (size_t ii = 0; ii < countPages; ii++)
161 {
162 page = (wxNotebookPage*) notebook.GetPage(ii);
163 info.version = kControlTabInfoVersionOne;
164 info.iconSuiteID = 0;
165 wxCFStringRef cflabel( page->GetLabel(), page->GetFont().GetEncoding() ) ;
166 info.name = cflabel ;
167 SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
168
169 if ( notebook.GetImageList() && notebook.GetPageImage(ii) >= 0 )
170 {
171 const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( ii ) ) ;
172 if ( bmap.IsOk() )
173 {
174 ControlButtonContentInfo info ;
175
176 wxMacCreateBitmapButton( &info, bmap ) ;
177
178 OSStatus err = SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
179 if ( err != noErr )
180 {
181 wxFAIL_MSG("Error when setting icon on tab");
182 }
183
184 wxMacReleaseBitmapButton( &info ) ;
185 }
186 }
187 SetTabEnabled( ii + 1, true ) ;
188 }
189 }
190
191 #endif