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