1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/notebmac.cpp
3 // Purpose: implementation of wxNotebook
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/notebook.h"
19 #include "wx/string.h"
25 #include "wx/string.h"
26 #include "wx/imaglist.h"
27 #include "wx/osx/private.h"
30 // check that the page index is valid
31 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
33 wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
35 wxWindowID WXUNUSED(id),
39 long WXUNUSED(extraStyle))
41 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
43 if ( bounds.right <= bounds.left )
44 bounds.right = bounds.left + 100;
45 if ( bounds.bottom <= bounds.top )
46 bounds.bottom = bounds.top + 100;
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;
56 ControlTabSize tabsize;
57 switch (wxpeer->GetWindowVariant())
59 case wxWINDOW_VARIANT_MINI:
63 case wxWINDOW_VARIANT_SMALL:
64 tabsize = kControlTabSizeSmall;
68 tabsize = kControlTabSizeLarge;
72 wxMacControl* peer = new wxMacControl( wxpeer );
73 OSStatus err = CreateTabsControl(
74 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
75 tabsize, tabstyle, 0, NULL, peer->GetControlRefAddr() );
86 int wxNotebook::HitTest(const wxPoint& pt, long * flags) const
88 int resultV = wxNOT_FOUND;
90 const int countPages = GetPageCount();
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() ;
98 HIPoint hipoint= { adjustedPt.x , adjustedPt.y } ;
99 HIViewPartCode outPart = 0 ;
100 OSStatus err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart );
102 int max = m_peer->GetMaximum() ;
103 if ( outPart == 0 && max > 0 )
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
108 int val = m_peer->GetValue() ;
112 m_peer->SetMaximum( 2 ) ;
117 m_peer->SetValue( maxval ) ;
119 m_peer->SetValue( 1 ) ;
121 err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart );
123 m_peer->SetValue( val ) ;
125 m_peer->SetMaximum( 1 ) ;
128 if ( outPart >= 1 && outPart <= countPages )
129 resultV = outPart - 1 ;
135 // we cannot differentiate better
137 *flags |= wxBK_HITTEST_ONLABEL;
139 *flags |= wxBK_HITTEST_NOWHERE;
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.
152 void wxMacControl::SetupTabs( const wxNotebook& notebook)
154 const size_t countPages = notebook.GetPageCount();
155 SetMaximum( countPages ) ;
157 wxNotebookPage *page;
158 ControlTabInfoRecV1 info;
160 for (size_t ii = 0; ii < countPages; ii++)
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 ) ;
169 if ( notebook.GetImageList() && notebook.GetPageImage(ii) >= 0 )
171 const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( ii ) ) ;
174 ControlButtonContentInfo info ;
176 wxMacCreateBitmapButton( &info, bmap ) ;
178 OSStatus err = SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
181 wxFAIL_MSG("Error when setting icon on tab");
184 wxMacReleaseBitmapButton( &info ) ;
187 SetTabEnabled( ii + 1, true ) ;