1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/notebmac.cpp
3 // Purpose: implementation of wxNotebook
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/notebook.h"
18 #include "wx/string.h"
24 #include "wx/string.h"
25 #include "wx/imaglist.h"
26 #include "wx/osx/private.h"
29 // check that the page index is valid
30 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
32 class wxCarbonTabView
: public wxMacControl
35 wxCarbonTabView( wxWindowMac
* peer
) : wxMacControl(peer
)
39 // Added by Mark Newsam
40 // When a page is added or deleted to the notebook this function updates
41 // information held in the control so that it matches the order
42 // the user would expect.
44 void SetupTabs( const wxNotebook
& notebook
)
46 const size_t countPages
= notebook
.GetPageCount();
47 SetMaximum( countPages
) ;
50 ControlTabInfoRecV1 info
;
52 for (size_t ii
= 0; ii
< countPages
; ii
++)
54 page
= (wxNotebookPage
*) notebook
.GetPage(ii
);
55 info
.version
= kControlTabInfoVersionOne
;
57 wxCFStringRef
cflabel( page
->GetLabel(), page
->GetFont().GetEncoding() ) ;
59 SetData
<ControlTabInfoRecV1
>( ii
+ 1, kControlTabInfoTag
, &info
) ;
61 if ( notebook
.GetImageList() && notebook
.GetPageImage(ii
) >= 0 )
63 const wxBitmap bmap
= notebook
.GetImageList()->GetBitmap( notebook
.GetPageImage( ii
) ) ;
66 ControlButtonContentInfo info
;
68 wxMacCreateBitmapButton( &info
, bmap
) ;
70 OSStatus err
= SetData
<ControlButtonContentInfo
>( ii
+ 1, kControlTabImageContentTag
, &info
);
73 wxFAIL_MSG("Error when setting icon on tab");
76 wxMacReleaseBitmapButton( &info
) ;
79 SetTabEnabled( ii
+ 1, true ) ;
83 int TabHitTest(const wxPoint
& pt
, long* flags
)
85 int resultV
= wxNOT_FOUND
;
87 wxNotebook
*notebookpeer
= wxDynamicCast( GetWXPeer() , wxNotebook
);
88 if ( NULL
== notebookpeer
)
91 const int countPages
= notebookpeer
->GetPageCount();
93 // we have to convert from Client to Window relative coordinates
94 wxPoint adjustedPt
= pt
+ GetWXPeer()->GetClientAreaOrigin();
95 // and now to HIView native ones
96 adjustedPt
.x
-= GetWXPeer()->MacGetLeftBorderSize() ;
97 adjustedPt
.y
-= GetWXPeer()->MacGetTopBorderSize() ;
99 HIPoint hipoint
= { adjustedPt
.x
, adjustedPt
.y
} ;
100 HIViewPartCode outPart
= 0 ;
101 OSStatus err
= HIViewGetPartHit( GetControlRef(), &hipoint
, &outPart
);
103 int max
= GetMaximum() ;
104 if ( outPart
== 0 && max
> 0 )
106 // this is a hack, as unfortunately a hit on an already selected tab returns 0,
107 // so we have to go some extra miles to make sure we select something different
109 int val
= GetValue() ;
122 err
= HIViewGetPartHit( GetControlRef(), &hipoint
, &outPart
);
129 if ( outPart
>= 1 && outPart
<= countPages
)
130 resultV
= outPart
- 1 ;
136 // we cannot differentiate better
138 *flags
|= wxBK_HITTEST_ONLABEL
;
140 *flags
|= wxBK_HITTEST_NOWHERE
;
149 wxWidgetImplType
* wxWidgetImpl::CreateTabView( wxWindowMac
* wxpeer
,
151 wxWindowID
WXUNUSED(id
),
155 long WXUNUSED(extraStyle
))
157 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
);
159 if ( bounds
.right
<= bounds
.left
)
160 bounds
.right
= bounds
.left
+ 100;
161 if ( bounds
.bottom
<= bounds
.top
)
162 bounds
.bottom
= bounds
.top
+ 100;
164 UInt16 tabstyle
= kControlTabDirectionNorth
;
165 if ( style
& wxBK_LEFT
)
166 tabstyle
= kControlTabDirectionWest
;
167 else if ( style
& wxBK_RIGHT
)
168 tabstyle
= kControlTabDirectionEast
;
169 else if ( style
& wxBK_BOTTOM
)
170 tabstyle
= kControlTabDirectionSouth
;
172 ControlTabSize tabsize
;
173 switch (wxpeer
->GetWindowVariant())
175 case wxWINDOW_VARIANT_MINI
:
179 case wxWINDOW_VARIANT_SMALL
:
180 tabsize
= kControlTabSizeSmall
;
184 tabsize
= kControlTabSizeLarge
;
188 wxMacControl
* peer
= new wxCarbonTabView( wxpeer
);
190 OSStatus err
= CreateTabsControl(
191 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
192 tabsize
, tabstyle
, 0, NULL
, peer
->GetControlRefAddr() );