]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/notebmac.cpp
Merge in from trunk r68626 - r68683
[wxWidgets.git] / src / osx / carbon / notebmac.cpp
CommitLineData
489468fe 1///////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/notebmac.cpp
489468fe
SC
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"
524c47aa 27#include "wx/osx/private.h"
489468fe
SC
28
29
30// check that the page index is valid
31#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
32
03647350
VZ
33wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
34 wxWindowMac* parent,
35 wxWindowID WXUNUSED(id),
36 const wxPoint& pos,
524c47aa 37 const wxSize& size,
03647350 38 long style,
a4fec5b4 39 long WXUNUSED(extraStyle))
489468fe 40{
524c47aa 41 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
489468fe
SC
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;
524c47aa 49 if ( style & wxBK_LEFT )
489468fe 50 tabstyle = kControlTabDirectionWest;
524c47aa 51 else if ( style & wxBK_RIGHT )
489468fe 52 tabstyle = kControlTabDirectionEast;
524c47aa 53 else if ( style & wxBK_BOTTOM )
489468fe
SC
54 tabstyle = kControlTabDirectionSouth;
55
56 ControlTabSize tabsize;
524c47aa 57 switch (wxpeer->GetWindowVariant())
489468fe
SC
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
524c47aa 72 wxMacControl* peer = new wxMacControl( wxpeer );
489468fe
SC
73 OSStatus err = CreateTabsControl(
74 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
524c47aa 75 tabsize, tabstyle, 0, NULL, peer->GetControlRefAddr() );
489468fe
SC
76 verify_noerr( err );
77
524c47aa 78 return peer;
489468fe
SC
79}
80
489468fe 81
489468fe 82
489468fe 83
489468fe 84
524c47aa 85/*
489468fe
SC
86int 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 ;
22756322 100 OSStatus err = HIViewGetPartHit( GetPeer()->GetControlRef(), &hipoint, &outPart );
489468fe 101
22756322 102 int max = GetPeer()->GetMaximum() ;
489468fe
SC
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 ..
22756322 108 int val = GetPeer()->GetValue() ;
489468fe
SC
109 int maxval = max ;
110 if ( max == 1 )
111 {
22756322 112 GetPeer()->SetMaximum( 2 ) ;
489468fe
SC
113 maxval = 2 ;
114 }
115
116 if ( val == 1 )
22756322 117 GetPeer()->SetValue( maxval ) ;
489468fe 118 else
22756322 119 GetPeer()->SetValue( 1 ) ;
489468fe 120
22756322 121 err = HIViewGetPartHit( GetPeer()->GetControlRef(), &hipoint, &outPart );
489468fe 122
22756322 123 GetPeer()->SetValue( val ) ;
489468fe 124 if ( max == 1 )
22756322 125 GetPeer()->SetMaximum( 1 ) ;
489468fe
SC
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}
524c47aa 144*/
489468fe
SC
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//
524c47aa
SC
151
152void wxMacControl::SetupTabs( const wxNotebook& notebook)
489468fe 153{
524c47aa
SC
154 const size_t countPages = notebook.GetPageCount();
155 SetMaximum( countPages ) ;
489468fe
SC
156
157 wxNotebookPage *page;
158 ControlTabInfoRecV1 info;
159
489468fe
SC
160 for (size_t ii = 0; ii < countPages; ii++)
161 {
524c47aa 162 page = (wxNotebookPage*) notebook.GetPage(ii);
489468fe
SC
163 info.version = kControlTabInfoVersionOne;
164 info.iconSuiteID = 0;
524c47aa 165 wxCFStringRef cflabel( page->GetLabel(), page->GetFont().GetEncoding() ) ;
489468fe 166 info.name = cflabel ;
524c47aa 167 SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
489468fe 168
524c47aa 169 if ( notebook.GetImageList() && notebook.GetPageImage(ii) >= 0 )
489468fe 170 {
524c47aa 171 const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( ii ) ) ;
a1b806b9 172 if ( bmap.IsOk() )
489468fe
SC
173 {
174 ControlButtonContentInfo info ;
175
176 wxMacCreateBitmapButton( &info, bmap ) ;
177
524c47aa 178 OSStatus err = SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
489468fe
SC
179 if ( err != noErr )
180 {
181 wxFAIL_MSG("Error when setting icon on tab");
182 }
183
184 wxMacReleaseBitmapButton( &info ) ;
185 }
186 }
524c47aa 187 SetTabEnabled( ii + 1, true ) ;
489468fe 188 }
489468fe
SC
189}
190
191#endif