]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fb5246be | 2 | // Name: src/mac/carbon/window.cpp |
e766c8a9 | 3 | // Purpose: wxWindowMac |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
5fde6fcc | 14 | #include "wx/window.h" |
e4db172a WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/log.h" | |
670f9935 | 18 | #include "wx/app.h" |
de6185e2 | 19 | #include "wx/utils.h" |
8e609c82 | 20 | #include "wx/panel.h" |
76b49cf4 | 21 | #include "wx/frame.h" |
da80ae71 | 22 | #include "wx/dc.h" |
ed4b0fdc | 23 | #include "wx/dcclient.h" |
f1e01716 | 24 | #include "wx/button.h" |
3b3dc801 | 25 | #include "wx/menu.h" |
fdf565fe | 26 | #include "wx/dialog.h" |
9eddec69 | 27 | #include "wx/settings.h" |
246c5004 | 28 | #include "wx/msgdlg.h" |
851dee09 | 29 | #include "wx/scrolbar.h" |
876cd6f7 | 30 | #include "wx/statbox.h" |
fec9cc08 | 31 | #include "wx/textctrl.h" |
4e3e485b | 32 | #include "wx/toolbar.h" |
ed2fbeb8 | 33 | #include "wx/layout.h" |
3304646d | 34 | #include "wx/statusbr.h" |
25466131 | 35 | #include "wx/menuitem.h" |
ed9a7a63 KO |
36 | #include "wx/treectrl.h" |
37 | #include "wx/listctrl.h" | |
e4db172a WS |
38 | #endif |
39 | ||
2f1ae414 | 40 | #include "wx/tooltip.h" |
4ac219f6 | 41 | #include "wx/spinctrl.h" |
467e3168 | 42 | #include "wx/geometry.h" |
e9576ca5 | 43 | |
c1cef60b CE |
44 | #if wxUSE_LISTCTRL |
45 | #include "wx/listctrl.h" | |
46 | #endif | |
47 | ||
48 | #if wxUSE_TREECTRL | |
49 | #include "wx/treectrl.h" | |
50 | #endif | |
51 | ||
7c551d95 SC |
52 | #if wxUSE_CARET |
53 | #include "wx/caret.h" | |
e15f0a5e | 54 | #endif |
7c551d95 | 55 | |
b46dde27 DS |
56 | #if wxUSE_DRAG_AND_DROP |
57 | #include "wx/dnd.h" | |
58 | #endif | |
519cb848 | 59 | |
d497dca4 | 60 | #include "wx/mac/uma.h" |
898d9035 | 61 | |
b46dde27 DS |
62 | #define MAC_SCROLLBAR_SIZE 15 |
63 | #define MAC_SMALL_SCROLLBAR_SIZE 11 | |
64 | ||
66a09d47 SC |
65 | #ifndef __DARWIN__ |
66 | #include <Windows.h> | |
67 | #include <ToolUtils.h> | |
1d879215 DS |
68 | #include <Scrap.h> |
69 | #include <MacTextEditor.h> | |
66a09d47 | 70 | #endif |
519cb848 | 71 | |
41218df1 | 72 | #if TARGET_API_MAC_OSX |
facd6764 | 73 | #ifndef __HIVIEW__ |
8b573fb8 | 74 | #include <HIToolbox/HIView.h> |
facd6764 | 75 | #endif |
41218df1 | 76 | #endif |
facd6764 | 77 | |
e9576ca5 SC |
78 | #include <string.h> |
79 | ||
fc0daf84 SC |
80 | #ifdef __WXUNIVERSAL__ |
81 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) | |
898d9035 | 82 | #else |
fc0daf84 | 83 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) |
898d9035 | 84 | #endif |
fc0daf84 | 85 | |
fc0daf84 | 86 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) |
facd6764 SC |
87 | EVT_NC_PAINT(wxWindowMac::OnNcPaint) |
88 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) | |
ff3795ee SC |
89 | #if TARGET_API_MAC_OSX |
90 | EVT_PAINT(wxWindowMac::OnPaint) | |
91 | #endif | |
5ca0d812 SC |
92 | EVT_SET_FOCUS(wxWindowMac::OnSetFocus) |
93 | EVT_KILL_FOCUS(wxWindowMac::OnSetFocus) | |
facd6764 | 94 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) |
e9576ca5 SC |
95 | END_EVENT_TABLE() |
96 | ||
94abc21f SC |
97 | #define wxMAC_DEBUG_REDRAW 0 |
98 | #ifndef wxMAC_DEBUG_REDRAW | |
99 | #define wxMAC_DEBUG_REDRAW 0 | |
100 | #endif | |
101 | ||
42ef83fa SC |
102 | // --------------------------------------------------------------------------- |
103 | // Utility Routines to move between different coordinate systems | |
104 | // --------------------------------------------------------------------------- | |
105 | ||
106 | /* | |
107 | * Right now we have the following setup : | |
108 | * a border that is not part of the native control is always outside the | |
109 | * control's border (otherwise we loose all native intelligence, future ways | |
110 | * may be to have a second embedding control responsible for drawing borders | |
111 | * and backgrounds eventually) | |
112 | * so all this border calculations have to be taken into account when calling | |
113 | * native methods or getting native oriented data | |
114 | * so we have three coordinate systems here | |
115 | * wx client coordinates | |
116 | * wx window coordinates (including window frames) | |
117 | * native coordinates | |
118 | */ | |
8b573fb8 | 119 | |
42ef83fa SC |
120 | // |
121 | // originating from native control | |
122 | // | |
123 | ||
124 | ||
125 | void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle ) | |
126 | { | |
8b573fb8 | 127 | OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
128 | } |
129 | ||
130 | void wxMacNativeToWindow( const wxWindow* window , Rect *rect ) | |
131 | { | |
8b573fb8 | 132 | OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
133 | } |
134 | ||
135 | // | |
136 | // directed towards native control | |
137 | // | |
138 | ||
139 | void wxMacWindowToNative( const wxWindow* window , RgnHandle handle ) | |
140 | { | |
8b573fb8 | 141 | OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); |
42ef83fa SC |
142 | } |
143 | ||
144 | void wxMacWindowToNative( const wxWindow* window , Rect *rect ) | |
145 | { | |
8b573fb8 | 146 | OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
147 | } |
148 | ||
facd6764 SC |
149 | // --------------------------------------------------------------------------- |
150 | // Carbon Events | |
151 | // --------------------------------------------------------------------------- | |
8b573fb8 | 152 | |
f1d527c1 SC |
153 | #if TARGET_API_MAC_OSX |
154 | ||
8b573fb8 | 155 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3 |
898d9035 DS |
156 | enum |
157 | { | |
158 | kEventControlVisibilityChanged = 157 | |
c2697b87 SC |
159 | }; |
160 | #endif | |
161 | ||
f1d527c1 SC |
162 | #endif |
163 | ||
facd6764 SC |
164 | static const EventTypeSpec eventList[] = |
165 | { | |
e3aeade0 SC |
166 | { kEventClassCommand, kEventProcessCommand } , |
167 | { kEventClassCommand, kEventCommandUpdateStatus } , | |
b46dde27 | 168 | |
e9a4bf7d | 169 | { kEventClassControl , kEventControlGetClickActivation } , |
f1d527c1 | 170 | { kEventClassControl , kEventControlHit } , |
898d9035 | 171 | |
980ee83f SC |
172 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , |
173 | { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } , | |
b46dde27 | 174 | |
73fe67bd | 175 | { kEventClassControl , kEventControlDraw } , |
cdef0334 | 176 | #if TARGET_API_MAC_OSX |
73fe67bd SC |
177 | { kEventClassControl , kEventControlVisibilityChanged } , |
178 | { kEventClassControl , kEventControlEnabledStateChanged } , | |
179 | { kEventClassControl , kEventControlHiliteChanged } , | |
ed9a7a63 KO |
180 | |
181 | { kEventClassControl , kEventControlActivate } , | |
182 | { kEventClassControl , kEventControlDeactivate } , | |
cdef0334 | 183 | #endif |
f1d527c1 | 184 | { kEventClassControl , kEventControlSetFocusPart } , |
8b573fb8 VZ |
185 | |
186 | { kEventClassService , kEventServiceGetTypes }, | |
187 | { kEventClassService , kEventServiceCopy }, | |
188 | { kEventClassService , kEventServicePaste }, | |
189 | ||
898d9035 DS |
190 | // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only |
191 | // { kEventClassControl , kEventControlBoundsChanged } , | |
facd6764 SC |
192 | } ; |
193 | ||
194 | static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
195 | { | |
196 | OSStatus result = eventNotHandledErr ; | |
197 | ||
198 | wxMacCarbonEvent cEvent( event ) ; | |
8b573fb8 | 199 | |
facd6764 SC |
200 | ControlRef controlRef ; |
201 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
202 | ||
203 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
204 | ||
898d9035 | 205 | switch ( GetEventKind( event ) ) |
facd6764 | 206 | { |
f1d527c1 | 207 | #if TARGET_API_MAC_OSX |
facd6764 SC |
208 | case kEventControlDraw : |
209 | { | |
1e8cde71 | 210 | RgnHandle updateRgn = NULL ; |
055a486b | 211 | RgnHandle allocatedRgn = NULL ; |
1e8cde71 | 212 | wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; |
898d9035 | 213 | |
76c7012c | 214 | if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr ) |
1e8cde71 SC |
215 | { |
216 | updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; | |
217 | } | |
055a486b SC |
218 | else |
219 | { | |
a9b456ff | 220 | if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 ) |
055a486b | 221 | { |
a9b456ff | 222 | // as this update region is in native window locals we must adapt it to wx window local |
055a486b SC |
223 | allocatedRgn = NewRgn() ; |
224 | CopyRgn( updateRgn , allocatedRgn ) ; | |
898d9035 | 225 | |
42ef83fa SC |
226 | // hide the given region by the new region that must be shifted |
227 | wxMacNativeToWindow( thisWindow , allocatedRgn ) ; | |
902725ee | 228 | updateRgn = allocatedRgn ; |
e6616741 | 229 | } |
055a486b | 230 | } |
e15f0a5e | 231 | |
e6616741 SC |
232 | Rect rgnBounds ; |
233 | GetRegionBounds( updateRgn , &rgnBounds ) ; | |
898d9035 | 234 | |
1f1c8bd4 | 235 | #if wxMAC_DEBUG_REDRAW |
facd6764 SC |
236 | if ( thisWindow->MacIsUserPane() ) |
237 | { | |
bcbd6987 SC |
238 | static float color = 0.5 ; |
239 | static channel = 0 ; | |
898d9035 DS |
240 | HIRect bounds; |
241 | CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ; | |
242 | ||
243 | HIViewGetBounds( controlRef, &bounds ); | |
8b573fb8 VZ |
244 | CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 , |
245 | channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 ); | |
246 | CGContextFillRect( cgContext, bounds ); | |
247 | color += 0.1 ; | |
248 | if ( color > 0.9 ) | |
249 | { | |
250 | color = 0.5 ; | |
251 | channel++ ; | |
252 | if ( channel == 3 ) | |
253 | channel = 0 ; | |
254 | } | |
facd6764 | 255 | } |
20b69855 | 256 | #endif |
898d9035 | 257 | |
c79aad8b | 258 | { |
20b69855 | 259 | #if wxMAC_USE_CORE_GRAPHICS |
e6616741 | 260 | bool created = false ; |
8523a5f5 | 261 | CGContextRef cgContext = NULL ; |
a9b456ff SC |
262 | OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ; |
263 | wxASSERT_MSG( err == noErr , wxT("Unable to retrieve CGContextRef") ) ; | |
c79aad8b | 264 | thisWindow->MacSetCGContextRef( cgContext ) ; |
898d9035 | 265 | |
e6616741 SC |
266 | { |
267 | wxMacCGContextStateSaver sg( cgContext ) ; | |
a9b456ff SC |
268 | float alpha = 1.0 ; |
269 | { | |
270 | wxWindow* iter = thisWindow ; | |
89954433 | 271 | while ( iter ) |
a9b456ff SC |
272 | { |
273 | alpha *= (float) iter->GetTransparent()/255.0 ; | |
274 | if ( iter->IsTopLevel() ) | |
275 | iter = NULL ; | |
276 | else | |
277 | iter = iter->GetParent() ; | |
278 | } | |
279 | } | |
280 | CGContextSetAlpha( cgContext , alpha ) ; | |
4488a1d3 VZ |
281 | |
282 | if ( thisWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) | |
283 | { | |
284 | HIRect bounds; | |
285 | HIViewGetBounds( controlRef, &bounds ); | |
286 | CGContextClearRect( cgContext, bounds ); | |
287 | } | |
288 | ||
289 | ||
facd6764 | 290 | #endif |
e6616741 SC |
291 | if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) |
292 | result = noErr ; | |
898d9035 | 293 | |
20b69855 | 294 | #if wxMAC_USE_CORE_GRAPHICS |
e6616741 SC |
295 | thisWindow->MacSetCGContextRef( NULL ) ; |
296 | } | |
898d9035 | 297 | |
e6616741 | 298 | if ( created ) |
e6616741 | 299 | CGContextRelease( cgContext ) ; |
20b69855 | 300 | #endif |
c79aad8b | 301 | } |
e15f0a5e | 302 | |
055a486b SC |
303 | if ( allocatedRgn ) |
304 | DisposeRgn( allocatedRgn ) ; | |
facd6764 SC |
305 | } |
306 | break ; | |
e15f0a5e | 307 | |
73fe67bd | 308 | case kEventControlVisibilityChanged : |
e15f0a5e | 309 | thisWindow->MacVisibilityChanged() ; |
73fe67bd | 310 | break ; |
e15f0a5e | 311 | |
73fe67bd | 312 | case kEventControlEnabledStateChanged : |
e15f0a5e | 313 | thisWindow->MacEnabledStateChanged() ; |
73fe67bd | 314 | break ; |
e15f0a5e | 315 | |
73fe67bd | 316 | case kEventControlHiliteChanged : |
e15f0a5e | 317 | thisWindow->MacHiliteChanged() ; |
73fe67bd | 318 | break ; |
89954433 | 319 | |
ed9a7a63 KO |
320 | case kEventControlActivate : |
321 | case kEventControlDeactivate : | |
0b8055d2 VZ |
322 | // FIXME: we should have a virtual function for this! |
323 | #if wxUSE_TREECTRL | |
324 | if ( thisWindow->IsKindOf( CLASSINFO( wxTreeCtrl ) ) ) | |
ed9a7a63 | 325 | thisWindow->Refresh(); |
6449b3a8 | 326 | #endif |
0b8055d2 VZ |
327 | #if wxUSE_LISTCTRL |
328 | if ( thisWindow->IsKindOf( CLASSINFO( wxListCtrl ) ) ) | |
329 | thisWindow->Refresh(); | |
330 | #endif | |
331 | break ; | |
332 | #endif // TARGET_API_MAC_OSX | |
e15f0a5e | 333 | |
6449b3a8 | 334 | // we emulate this event under Carbon CFM |
f1d527c1 SC |
335 | case kEventControlSetFocusPart : |
336 | { | |
337 | Boolean focusEverything = false ; | |
338 | ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode ); | |
898d9035 | 339 | |
6449b3a8 | 340 | #ifdef __WXMAC_OSX__ |
f1d527c1 SC |
341 | if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr ) |
342 | { | |
343 | } | |
6449b3a8 | 344 | #endif |
e15f0a5e | 345 | |
6a74af89 VZ |
346 | if ( thisWindow->MacIsUserPane() ) |
347 | result = noErr ; | |
348 | ||
f1d527c1 SC |
349 | if ( controlPart == kControlFocusNoPart ) |
350 | { | |
e15f0a5e | 351 | #if wxUSE_CARET |
f1d527c1 | 352 | if ( thisWindow->GetCaret() ) |
f1d527c1 | 353 | thisWindow->GetCaret()->OnKillFocus(); |
e15f0a5e DS |
354 | #endif |
355 | ||
92b6cd62 | 356 | static bool inKillFocusEvent = false ; |
898d9035 | 357 | |
92b6cd62 SC |
358 | if ( !inKillFocusEvent ) |
359 | { | |
360 | inKillFocusEvent = true ; | |
361 | wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); | |
362 | event.SetEventObject(thisWindow); | |
363 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
364 | inKillFocusEvent = false ; | |
365 | } | |
f1d527c1 SC |
366 | } |
367 | else | |
368 | { | |
369 | // panel wants to track the window which was the last to have focus in it | |
370 | wxChildFocusEvent eventFocus(thisWindow); | |
371 | thisWindow->GetEventHandler()->ProcessEvent(eventFocus); | |
8b573fb8 | 372 | |
e15f0a5e | 373 | #if wxUSE_CARET |
f1d527c1 | 374 | if ( thisWindow->GetCaret() ) |
f1d527c1 | 375 | thisWindow->GetCaret()->OnSetFocus(); |
e15f0a5e | 376 | #endif |
f1d527c1 SC |
377 | |
378 | wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); | |
379 | event.SetEventObject(thisWindow); | |
380 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
381 | } | |
382 | } | |
383 | break ; | |
e15f0a5e | 384 | |
f1d527c1 | 385 | case kEventControlHit : |
e15f0a5e | 386 | result = thisWindow->MacControlHit( handler , event ) ; |
f1d527c1 | 387 | break ; |
e15f0a5e | 388 | |
e9a4bf7d SC |
389 | case kEventControlGetClickActivation : |
390 | { | |
391 | // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise) | |
392 | WindowRef owner = cEvent.GetParameter<WindowRef>(kEventParamWindowRef); | |
393 | if ( !IsWindowActive(owner) ) | |
394 | { | |
395 | cEvent.SetParameter(kEventParamClickActivation,(UInt32) kActivateAndIgnoreClick) ; | |
396 | result = noErr ; | |
397 | } | |
398 | } | |
399 | break ; | |
400 | ||
facd6764 SC |
401 | default : |
402 | break ; | |
403 | } | |
e15f0a5e | 404 | |
facd6764 SC |
405 | return result ; |
406 | } | |
407 | ||
89954433 VZ |
408 | static pascal OSStatus |
409 | wxMacWindowServiceEventHandler(EventHandlerCallRef WXUNUSED(handler), | |
410 | EventRef event, | |
411 | void *data) | |
e4727773 SC |
412 | { |
413 | OSStatus result = eventNotHandledErr ; | |
414 | ||
415 | wxMacCarbonEvent cEvent( event ) ; | |
8b573fb8 | 416 | |
e4727773 SC |
417 | ControlRef controlRef ; |
418 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
419 | wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ; | |
420 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
421 | ||
e15f0a5e | 422 | switch ( GetEventKind( event ) ) |
e4727773 SC |
423 | { |
424 | case kEventServiceGetTypes : | |
e15f0a5e | 425 | if ( textCtrl ) |
e4727773 SC |
426 | { |
427 | long from, to ; | |
428 | textCtrl->GetSelection( &from , &to ) ; | |
429 | ||
8b573fb8 | 430 | CFMutableArrayRef copyTypes = 0 , pasteTypes = 0; |
e15f0a5e | 431 | if ( from != to ) |
e4727773 SC |
432 | copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ; |
433 | if ( textCtrl->IsEditable() ) | |
434 | pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ; | |
8b573fb8 | 435 | |
898d9035 | 436 | static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt', 'PICT', 'MooV', 'AIFF' */ }; |
e4727773 SC |
437 | for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i ) |
438 | { | |
439 | CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]); | |
440 | if ( typestring ) | |
441 | { | |
442 | if ( copyTypes ) | |
898d9035 | 443 | CFArrayAppendValue(copyTypes, typestring) ; |
e4727773 | 444 | if ( pasteTypes ) |
898d9035 | 445 | CFArrayAppendValue(pasteTypes, typestring) ; |
e15f0a5e | 446 | |
e4727773 SC |
447 | CFRelease( typestring ) ; |
448 | } | |
449 | } | |
e15f0a5e | 450 | |
e4727773 SC |
451 | result = noErr ; |
452 | } | |
453 | break ; | |
e15f0a5e | 454 | |
e4727773 SC |
455 | case kEventServiceCopy : |
456 | if ( textCtrl ) | |
457 | { | |
458 | long from, to ; | |
e15f0a5e | 459 | |
e4727773 SC |
460 | textCtrl->GetSelection( &from , &to ) ; |
461 | wxString val = textCtrl->GetValue() ; | |
462 | val = val.Mid( from , to - from ) ; | |
463 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
464 | verify_noerr( ClearScrap( &scrapRef ) ) ; | |
fb5246be | 465 | verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.length() , val.c_str() ) ) ; |
e4727773 SC |
466 | result = noErr ; |
467 | } | |
468 | break ; | |
e15f0a5e | 469 | |
e4727773 SC |
470 | case kEventServicePaste : |
471 | if ( textCtrl ) | |
472 | { | |
473 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
474 | Size textSize, pastedSize ; | |
898d9035 | 475 | verify_noerr( GetScrapFlavorSize(scrapRef, kTXNTextData, &textSize) ) ; |
e4727773 SC |
476 | textSize++ ; |
477 | char *content = new char[textSize] ; | |
898d9035 DS |
478 | GetScrapFlavorData(scrapRef, kTXNTextData, &pastedSize, content ); |
479 | content[textSize - 1] = 0 ; | |
e15f0a5e | 480 | |
8ef4d6e2 | 481 | #if wxUSE_UNICODE |
58603178 | 482 | textCtrl->WriteText( wxString( content , wxConvLocal ) ); |
8ef4d6e2 | 483 | #else |
e4727773 | 484 | textCtrl->WriteText( wxString( content ) ) ; |
8ef4d6e2 | 485 | #endif |
e15f0a5e | 486 | |
e4727773 SC |
487 | delete[] content ; |
488 | result = noErr ; | |
489 | } | |
490 | break ; | |
e15f0a5e DS |
491 | |
492 | default: | |
493 | break ; | |
e4727773 | 494 | } |
8b573fb8 | 495 | |
e4727773 | 496 | return result ; |
8b573fb8 | 497 | } |
e4727773 | 498 | |
980ee83f SC |
499 | pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
500 | { | |
501 | OSStatus result = eventNotHandledErr ; | |
502 | wxWindowMac* focus = (wxWindowMac*) data ; | |
b46dde27 | 503 | |
980ee83f SC |
504 | wchar_t* uniChars = NULL ; |
505 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
b46dde27 | 506 | |
75b32421 | 507 | UniChar* charBuf = NULL; |
4f74e0d1 | 508 | ByteCount dataSize = 0 ; |
980ee83f SC |
509 | int numChars = 0 ; |
510 | UniChar buf[2] ; | |
511 | if ( GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr ) | |
512 | { | |
3281bf67 | 513 | numChars = dataSize / sizeof( UniChar) + 1; |
980ee83f | 514 | charBuf = buf ; |
b46dde27 | 515 | |
6d49e4bb | 516 | if ( (size_t) numChars * 2 > sizeof(buf) ) |
980ee83f SC |
517 | charBuf = new UniChar[ numChars ] ; |
518 | else | |
519 | charBuf = buf ; | |
b46dde27 | 520 | |
980ee83f SC |
521 | uniChars = new wchar_t[ numChars ] ; |
522 | GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; | |
e4db172a | 523 | charBuf[ numChars - 1 ] = 0; |
980ee83f | 524 | #if SIZEOF_WCHAR_T == 2 |
cdef0334 | 525 | uniChars = (wchar_t*) charBuf ; |
5ca930b1 | 526 | /* memcpy( uniChars , charBuf , numChars * 2 ) ;*/ // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...) |
980ee83f SC |
527 | #else |
528 | // the resulting string will never have more chars than the utf16 version, so this is safe | |
529 | wxMBConvUTF16 converter ; | |
530 | numChars = converter.MB2WC( uniChars , (const char*)charBuf , numChars ) ; | |
531 | #endif | |
532 | } | |
b46dde27 | 533 | |
980ee83f SC |
534 | switch ( GetEventKind( event ) ) |
535 | { | |
536 | case kEventTextInputUpdateActiveInputArea : | |
537 | { | |
538 | // An IME input event may return several characters, but we need to send one char at a time to | |
539 | // EVT_CHAR | |
540 | for (int pos=0 ; pos < numChars ; pos++) | |
541 | { | |
980ee83f SC |
542 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; |
543 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
544 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
b46dde27 | 545 | |
5ca930b1 VZ |
546 | UInt32 message = uniChars[pos] < 128 ? (char)uniChars[pos] : '?'; |
547 | /* | |
548 | NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent | |
549 | multiple times to update the active range during inline input, so this handler will often receive | |
550 | uncommited text, which should usually not trigger side effects. It might be a good idea to check the | |
551 | kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h). | |
552 | On the other hand, it can be useful for some applications to react to uncommitted text (for example, | |
553 | to update a status display), as long as it does not disrupt the inline input session. Ideally, wx | |
554 | should add new event types to support advanced text input. For now, I would keep things as they are. | |
89954433 | 555 | |
5ca930b1 | 556 | However, the code that was being used caused additional problems: |
980ee83f | 557 | UInt32 message = (0 << 8) + ((char)uniChars[pos] ); |
5ca930b1 VZ |
558 | Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline |
559 | input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji | |
560 | for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB | |
561 | (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D | |
562 | (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress. | |
563 | Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only | |
564 | overlap with Unicode within the (7-bit) ASCII range. | |
565 | But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks | |
566 | for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII | |
567 | characters as they are and replaces the rest with '?', ensuring that update events are triggered. | |
568 | It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but | |
569 | I don't have time to look into that right now. | |
570 | -- CL | |
571 | */ | |
980ee83f SC |
572 | if ( wxTheApp->MacSendCharEvent( |
573 | focus , message , 0 , when , 0 , 0 , uniChars[pos] ) ) | |
574 | { | |
575 | result = noErr ; | |
576 | } | |
b46dde27 | 577 | |
980ee83f SC |
578 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; |
579 | } | |
580 | } | |
581 | break ; | |
582 | case kEventTextInputUnicodeForKeyEvent : | |
583 | { | |
584 | UInt32 keyCode, modifiers ; | |
585 | Point point ; | |
586 | EventRef rawEvent ; | |
587 | unsigned char charCode ; | |
588 | ||
589 | GetEventParameter( event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(rawEvent), NULL, &rawEvent ) ; | |
590 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode ); | |
591 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
592 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers ); | |
593 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point ); | |
b46dde27 | 594 | |
980ee83f | 595 | UInt32 message = (keyCode << 8) + charCode; |
aa44b55d | 596 | |
980ee83f SC |
597 | // An IME input event may return several characters, but we need to send one char at a time to |
598 | // EVT_CHAR | |
599 | for (int pos=0 ; pos < numChars ; pos++) | |
600 | { | |
980ee83f SC |
601 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; |
602 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
603 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
b46dde27 | 604 | |
980ee83f SC |
605 | if ( wxTheApp->MacSendCharEvent( |
606 | focus , message , modifiers , when , point.h , point.v , uniChars[pos] ) ) | |
607 | { | |
608 | result = noErr ; | |
609 | } | |
b46dde27 | 610 | |
980ee83f SC |
611 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; |
612 | } | |
613 | } | |
614 | break; | |
615 | default: | |
616 | break ; | |
617 | } | |
b46dde27 DS |
618 | |
619 | delete [] uniChars ; | |
980ee83f | 620 | if ( charBuf != buf ) |
b46dde27 | 621 | delete [] charBuf ; |
2e91d506 | 622 | |
980ee83f | 623 | return result ; |
980ee83f SC |
624 | } |
625 | ||
89954433 VZ |
626 | static pascal OSStatus |
627 | wxMacWindowCommandEventHandler(EventHandlerCallRef WXUNUSED(handler), | |
628 | EventRef event, | |
629 | void *data) | |
e3aeade0 SC |
630 | { |
631 | OSStatus result = eventNotHandledErr ; | |
632 | wxWindowMac* focus = (wxWindowMac*) data ; | |
b46dde27 | 633 | |
e3aeade0 | 634 | HICommand command ; |
b46dde27 | 635 | |
e3aeade0 SC |
636 | wxMacCarbonEvent cEvent( event ) ; |
637 | cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ; | |
b46dde27 | 638 | |
e3aeade0 SC |
639 | wxMenuItem* item = NULL ; |
640 | wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ; | |
641 | int id = wxMacCommandToId( command.commandID ) ; | |
b46dde27 | 642 | |
e3aeade0 SC |
643 | if ( item ) |
644 | { | |
645 | wxASSERT( itemMenu != NULL ) ; | |
b46dde27 | 646 | |
e3aeade0 SC |
647 | switch ( cEvent.GetKind() ) |
648 | { | |
649 | case kEventProcessCommand : | |
650 | { | |
651 | if (item->IsCheckable()) | |
652 | item->Check( !item->IsChecked() ) ; | |
b46dde27 | 653 | |
e3aeade0 SC |
654 | if ( itemMenu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ) |
655 | result = noErr ; | |
656 | else | |
657 | { | |
658 | wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , id); | |
659 | event.SetEventObject(focus); | |
660 | event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); | |
b46dde27 | 661 | |
e3aeade0 SC |
662 | if ( focus->GetEventHandler()->ProcessEvent(event) ) |
663 | result = noErr ; | |
664 | } | |
665 | } | |
666 | break ; | |
b46dde27 | 667 | |
e3aeade0 SC |
668 | case kEventCommandUpdateStatus: |
669 | { | |
670 | wxUpdateUIEvent event(id); | |
671 | event.SetEventObject( itemMenu ); | |
b46dde27 | 672 | |
e3aeade0 | 673 | bool processed = false; |
b46dde27 | 674 | |
e3aeade0 SC |
675 | // Try the menu's event handler |
676 | { | |
677 | wxEvtHandler *handler = itemMenu->GetEventHandler(); | |
678 | if ( handler ) | |
679 | processed = handler->ProcessEvent(event); | |
680 | } | |
b46dde27 | 681 | |
e3aeade0 SC |
682 | // Try the window the menu was popped up from |
683 | // (and up through the hierarchy) | |
684 | if ( !processed ) | |
685 | { | |
686 | const wxMenuBase *menu = itemMenu; | |
687 | while ( menu ) | |
688 | { | |
689 | wxWindow *win = menu->GetInvokingWindow(); | |
690 | if ( win ) | |
691 | { | |
692 | processed = win->GetEventHandler()->ProcessEvent(event); | |
693 | break; | |
694 | } | |
b46dde27 | 695 | |
e3aeade0 SC |
696 | menu = menu->GetParent(); |
697 | } | |
698 | } | |
b46dde27 | 699 | |
e3aeade0 SC |
700 | if ( !processed ) |
701 | { | |
702 | processed = focus->GetEventHandler()->ProcessEvent(event); | |
703 | } | |
b46dde27 | 704 | |
e3aeade0 SC |
705 | if ( processed ) |
706 | { | |
707 | // if anything changed, update the changed attribute | |
708 | if (event.GetSetText()) | |
709 | itemMenu->SetLabel(id, event.GetText()); | |
710 | if (event.GetSetChecked()) | |
711 | itemMenu->Check(id, event.GetChecked()); | |
712 | if (event.GetSetEnabled()) | |
713 | itemMenu->Enable(id, event.GetEnabled()); | |
b46dde27 | 714 | |
e3aeade0 SC |
715 | result = noErr ; |
716 | } | |
717 | } | |
718 | break ; | |
b46dde27 | 719 | |
e3aeade0 SC |
720 | default : |
721 | break ; | |
722 | } | |
723 | } | |
724 | return result ; | |
725 | } | |
726 | ||
facd6764 SC |
727 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
728 | { | |
af6b7b80 SC |
729 | EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; |
730 | EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
731 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
facd6764 SC |
732 | OSStatus result = eventNotHandledErr ; |
733 | ||
734 | switch ( GetEventClass( event ) ) | |
735 | { | |
e3aeade0 SC |
736 | case kEventClassCommand : |
737 | result = wxMacWindowCommandEventHandler( handler , event , data ) ; | |
738 | break ; | |
739 | ||
facd6764 SC |
740 | case kEventClassControl : |
741 | result = wxMacWindowControlEventHandler( handler, event, data ) ; | |
742 | break ; | |
e15f0a5e | 743 | |
e4727773 SC |
744 | case kEventClassService : |
745 | result = wxMacWindowServiceEventHandler( handler, event , data ) ; | |
902725ee | 746 | break ; |
e15f0a5e | 747 | |
980ee83f SC |
748 | case kEventClassTextInput : |
749 | result = wxMacUnicodeTextEventHandler( handler , event , data ) ; | |
750 | break ; | |
b46dde27 | 751 | |
facd6764 SC |
752 | default : |
753 | break ; | |
754 | } | |
e15f0a5e | 755 | |
af6b7b80 | 756 | wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ; |
e15f0a5e | 757 | |
facd6764 SC |
758 | return result ; |
759 | } | |
760 | ||
761 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
762 | ||
20b69855 SC |
763 | #if !TARGET_API_MAC_OSX |
764 | ||
facd6764 SC |
765 | // --------------------------------------------------------------------------- |
766 | // UserPane events for non OSX builds | |
767 | // --------------------------------------------------------------------------- | |
8b573fb8 | 768 | |
facd6764 SC |
769 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) |
770 | { | |
771 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
772 | if ( win ) |
773 | win->MacControlUserPaneDrawProc(part) ; | |
facd6764 | 774 | } |
1f1c8bd4 | 775 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP , wxMacControlUserPaneDrawProc ) ; |
facd6764 SC |
776 | |
777 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) | |
778 | { | |
779 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
780 | if ( win ) |
781 | return win->MacControlUserPaneHitTestProc(where.h , where.v) ; | |
782 | else | |
783 | return kControlNoPart ; | |
facd6764 | 784 | } |
1f1c8bd4 | 785 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP , wxMacControlUserPaneHitTestProc ) ; |
facd6764 SC |
786 | |
787 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) | |
788 | { | |
789 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
790 | if ( win ) |
791 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; | |
792 | else | |
793 | return kControlNoPart ; | |
facd6764 | 794 | } |
1f1c8bd4 | 795 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP , wxMacControlUserPaneTrackingProc ) ; |
facd6764 SC |
796 | |
797 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
798 | { | |
799 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
800 | if ( win ) |
801 | win->MacControlUserPaneIdleProc() ; | |
facd6764 | 802 | } |
1f1c8bd4 | 803 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP , wxMacControlUserPaneIdleProc ) ; |
facd6764 SC |
804 | |
805 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
806 | { | |
807 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
808 | if ( win ) |
809 | return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; | |
810 | else | |
811 | return kControlNoPart ; | |
facd6764 | 812 | } |
1f1c8bd4 | 813 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP , wxMacControlUserPaneKeyDownProc ) ; |
facd6764 SC |
814 | |
815 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
816 | { | |
817 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
818 | if ( win ) |
819 | win->MacControlUserPaneActivateProc(activating) ; | |
facd6764 | 820 | } |
1f1c8bd4 | 821 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP , wxMacControlUserPaneActivateProc ) ; |
facd6764 SC |
822 | |
823 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
824 | { | |
825 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
826 | if ( win ) |
827 | return win->MacControlUserPaneFocusProc(action) ; | |
828 | else | |
829 | return kControlNoPart ; | |
facd6764 | 830 | } |
1f1c8bd4 | 831 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP , wxMacControlUserPaneFocusProc ) ; |
facd6764 SC |
832 | |
833 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) | |
834 | { | |
835 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
836 | if ( win ) |
837 | win->MacControlUserPaneBackgroundProc(info) ; | |
facd6764 | 838 | } |
1f1c8bd4 | 839 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP , wxMacControlUserPaneBackgroundProc ) ; |
facd6764 | 840 | |
8b573fb8 | 841 | void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part) |
facd6764 | 842 | { |
e15f0a5e | 843 | int x = 0 , y = 0; |
bcbd6987 SC |
844 | RgnHandle rgn = NewRgn() ; |
845 | GetClip( rgn ) ; | |
8523a5f5 | 846 | MacWindowToRootWindow( &x, &y ) ; |
d35bd499 | 847 | OffsetRgn( rgn , -x , -y ) ; |
bcbd6987 SC |
848 | wxMacWindowStateSaver sv( this ) ; |
849 | SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ; | |
850 | MacDoRedraw( rgn , 0 ) ; | |
851 | DisposeRgn( rgn ) ; | |
facd6764 SC |
852 | } |
853 | ||
8b573fb8 | 854 | wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
facd6764 SC |
855 | { |
856 | return kControlNoPart ; | |
857 | } | |
858 | ||
8b573fb8 | 859 | wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) |
facd6764 SC |
860 | { |
861 | return kControlNoPart ; | |
862 | } | |
863 | ||
8b573fb8 | 864 | void wxWindowMac::MacControlUserPaneIdleProc() |
facd6764 SC |
865 | { |
866 | } | |
867 | ||
8b573fb8 | 868 | wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
facd6764 SC |
869 | { |
870 | return kControlNoPart ; | |
871 | } | |
872 | ||
8b573fb8 | 873 | void wxWindowMac::MacControlUserPaneActivateProc(bool activating) |
facd6764 SC |
874 | { |
875 | } | |
876 | ||
8b573fb8 | 877 | wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action) |
facd6764 | 878 | { |
fb5246be WS |
879 | if ( AcceptsFocus() ) |
880 | return 1 ; | |
881 | else | |
882 | return kControlNoPart ; | |
facd6764 SC |
883 | } |
884 | ||
8b573fb8 | 885 | void wxWindowMac::MacControlUserPaneBackgroundProc(void* info) |
facd6764 SC |
886 | { |
887 | } | |
888 | ||
20b69855 SC |
889 | #endif |
890 | ||
1f1c8bd4 SC |
891 | // --------------------------------------------------------------------------- |
892 | // Scrollbar Tracking for all | |
893 | // --------------------------------------------------------------------------- | |
894 | ||
895 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ; | |
896 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) | |
897 | { | |
898 | if ( partCode != 0) | |
899 | { | |
900 | wxWindow* wx = wxFindControlFromMacControl( control ) ; | |
901 | if ( wx ) | |
1f1c8bd4 | 902 | wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ; |
1f1c8bd4 SC |
903 | } |
904 | } | |
905 | wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ; | |
906 | ||
e7549107 SC |
907 | // =========================================================================== |
908 | // implementation | |
909 | // =========================================================================== | |
910 | ||
71f2fb52 RN |
911 | WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap); |
912 | ||
913 | static MacControlMap wxWinMacControlList; | |
914 | ||
915 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) | |
916 | { | |
917 | MacControlMap::iterator node = wxWinMacControlList.find(inControl); | |
918 | ||
919 | return (node == wxWinMacControlList.end()) ? NULL : node->second; | |
920 | } | |
921 | ||
922 | void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control) | |
923 | { | |
924 | // adding NULL ControlRef is (first) surely a result of an error and | |
925 | // (secondly) breaks native event processing | |
926 | wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
927 | ||
928 | wxWinMacControlList[inControl] = control; | |
929 | } | |
930 | ||
931 | void wxRemoveMacControlAssociation(wxWindow *control) | |
932 | { | |
933 | // iterate over all the elements in the class | |
a8683134 SC |
934 | // is the iterator stable ? as we might have two associations pointing to the same wxWindow |
935 | // we should go on... | |
936 | ||
937 | bool found = true ; | |
e15f0a5e | 938 | while ( found ) |
71f2fb52 | 939 | { |
a8683134 SC |
940 | found = false ; |
941 | MacControlMap::iterator it; | |
942 | for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) | |
71f2fb52 | 943 | { |
a8683134 SC |
944 | if ( it->second == control ) |
945 | { | |
946 | wxWinMacControlList.erase(it); | |
947 | found = true ; | |
948 | break; | |
949 | } | |
71f2fb52 RN |
950 | } |
951 | } | |
952 | } | |
facd6764 | 953 | |
e7549107 | 954 | // ---------------------------------------------------------------------------- |
facd6764 | 955 | // constructors and such |
e7549107 SC |
956 | // ---------------------------------------------------------------------------- |
957 | ||
94f9b1f0 | 958 | wxWindowMac::wxWindowMac() |
8b573fb8 VZ |
959 | { |
960 | Init(); | |
94f9b1f0 SC |
961 | } |
962 | ||
963 | wxWindowMac::wxWindowMac(wxWindowMac *parent, | |
964 | wxWindowID id, | |
965 | const wxPoint& pos , | |
966 | const wxSize& size , | |
967 | long style , | |
968 | const wxString& name ) | |
969 | { | |
970 | Init(); | |
971 | Create(parent, id, pos, size, style, name); | |
972 | } | |
973 | ||
e766c8a9 | 974 | void wxWindowMac::Init() |
519cb848 | 975 | { |
21fd5529 | 976 | m_peer = NULL ; |
79392158 | 977 | m_frozenness = 0 ; |
a9b456ff | 978 | m_macAlpha = 255 ; |
898d9035 | 979 | |
e15f0a5e DS |
980 | #if wxMAC_USE_CORE_GRAPHICS |
981 | m_cgContextRef = NULL ; | |
982 | #endif | |
983 | ||
e7549107 | 984 | // as all windows are created with WS_VISIBLE style... |
902725ee | 985 | m_isShown = true; |
e7549107 | 986 | |
6264b550 RR |
987 | m_hScrollBar = NULL ; |
988 | m_vScrollBar = NULL ; | |
c1142003 VZ |
989 | m_hScrollBarAlwaysShown = false; |
990 | m_vScrollBarAlwaysShown = false; | |
991 | ||
facd6764 SC |
992 | m_macBackgroundBrush = wxNullBrush ; |
993 | ||
902725ee | 994 | m_macIsUserPane = true; |
8adc196b | 995 | m_clipChildren = false ; |
5c840e5b | 996 | m_cachedClippedRectValid = false ; |
e15f0a5e | 997 | |
c6f9fb05 SC |
998 | // we need a valid font for the encodings |
999 | wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
e9576ca5 SC |
1000 | } |
1001 | ||
e766c8a9 | 1002 | wxWindowMac::~wxWindowMac() |
e9576ca5 | 1003 | { |
7de59551 RD |
1004 | SendDestroyEvent(); |
1005 | ||
902725ee | 1006 | m_isBeingDeleted = true; |
6ed71b4f | 1007 | |
6449b3a8 | 1008 | MacInvalidateBorders() ; |
7ebf5540 | 1009 | |
d4380aaf SC |
1010 | #ifndef __WXUNIVERSAL__ |
1011 | // VS: make sure there's no wxFrame with last focus set to us: | |
1012 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
1013 | { | |
1014 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
1015 | if ( frame ) | |
1016 | { | |
1017 | if ( frame->GetLastFocus() == this ) | |
d4380aaf | 1018 | frame->SetLastFocus((wxWindow*)NULL); |
d4380aaf SC |
1019 | break; |
1020 | } | |
1021 | } | |
b46dde27 | 1022 | #endif |
8b573fb8 VZ |
1023 | |
1024 | // destroy children before destroying this window itself | |
1025 | DestroyChildren(); | |
1026 | ||
facd6764 SC |
1027 | // wxRemoveMacControlAssociation( this ) ; |
1028 | // If we delete an item, we should initialize the parent panel, | |
1029 | // because it could now be invalid. | |
6c20e8f8 VZ |
1030 | wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); |
1031 | if ( tlw ) | |
facd6764 | 1032 | { |
6c20e8f8 VZ |
1033 | if ( tlw->GetDefaultItem() == (wxButton*) this) |
1034 | tlw->SetDefaultItem(NULL); | |
facd6764 | 1035 | } |
e15f0a5e | 1036 | |
21fd5529 | 1037 | if ( m_peer && m_peer->Ok() ) |
facd6764 SC |
1038 | { |
1039 | // in case the callback might be called during destruction | |
1040 | wxRemoveMacControlAssociation( this) ; | |
229f6270 | 1041 | ::RemoveEventHandler( (EventHandlerRef ) m_macControlEventHandler ) ; |
5ca0d812 SC |
1042 | // we currently are not using this hook |
1043 | // ::SetControlColorProc( *m_peer , NULL ) ; | |
1044 | m_peer->Dispose() ; | |
facd6764 | 1045 | } |
d4380aaf | 1046 | |
facd6764 | 1047 | if ( g_MacLastWindow == this ) |
facd6764 | 1048 | g_MacLastWindow = NULL ; |
7de59551 | 1049 | |
fd76aa8d SC |
1050 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; |
1051 | if ( frame ) | |
1052 | { | |
e40298d5 JS |
1053 | if ( frame->GetLastFocus() == this ) |
1054 | frame->SetLastFocus( NULL ) ; | |
fd76aa8d | 1055 | } |
e7549107 | 1056 | |
42683dfb SC |
1057 | // delete our drop target if we've got one |
1058 | #if wxUSE_DRAG_AND_DROP | |
1059 | if ( m_dropTarget != NULL ) | |
1060 | { | |
1061 | delete m_dropTarget; | |
1062 | m_dropTarget = NULL; | |
1063 | } | |
e15f0a5e DS |
1064 | #endif |
1065 | ||
21fd5529 SC |
1066 | delete m_peer ; |
1067 | } | |
1068 | ||
8b573fb8 VZ |
1069 | WXWidget wxWindowMac::GetHandle() const |
1070 | { | |
1071 | return (WXWidget) m_peer->GetControlRef() ; | |
e9576ca5 SC |
1072 | } |
1073 | ||
5ca0d812 | 1074 | void wxWindowMac::MacInstallEventHandler( WXWidget control ) |
facd6764 | 1075 | { |
898d9035 DS |
1076 | wxAssociateControlWithMacControl( (ControlRef) control , this ) ; |
1077 | InstallControlEventHandler( (ControlRef)control , GetwxMacWindowEventHandlerUPP(), | |
8b573fb8 | 1078 | GetEventTypeCount(eventList), eventList, this, |
facd6764 | 1079 | (EventHandlerRef *)&m_macControlEventHandler); |
e15f0a5e | 1080 | |
4a63451b SC |
1081 | #if !TARGET_API_MAC_OSX |
1082 | if ( (ControlRef) control == m_peer->GetControlRef() ) | |
1083 | { | |
898d9035 DS |
1084 | m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl, kControlUserPaneDrawProcTag, GetwxMacControlUserPaneDrawProc()) ; |
1085 | m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl, kControlUserPaneHitTestProcTag, GetwxMacControlUserPaneHitTestProc()) ; | |
1086 | m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl, kControlUserPaneTrackingProcTag, GetwxMacControlUserPaneTrackingProc()) ; | |
1087 | m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl, kControlUserPaneIdleProcTag, GetwxMacControlUserPaneIdleProc()) ; | |
1088 | m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl, kControlUserPaneKeyDownProcTag, GetwxMacControlUserPaneKeyDownProc()) ; | |
1089 | m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl, kControlUserPaneActivateProcTag, GetwxMacControlUserPaneActivateProc()) ; | |
1090 | m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl, kControlUserPaneFocusProcTag, GetwxMacControlUserPaneFocusProc()) ; | |
1091 | m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl, kControlUserPaneBackgroundProcTag, GetwxMacControlUserPaneBackgroundProc()) ; | |
4a63451b SC |
1092 | } |
1093 | #endif | |
facd6764 SC |
1094 | } |
1095 | ||
e9576ca5 | 1096 | // Constructor |
58603178 DS |
1097 | bool wxWindowMac::Create(wxWindowMac *parent, |
1098 | wxWindowID id, | |
1099 | const wxPoint& pos, | |
1100 | const wxSize& size, | |
1101 | long style, | |
1102 | const wxString& name) | |
e9576ca5 | 1103 | { |
902725ee | 1104 | wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") ); |
e9576ca5 | 1105 | |
e7549107 | 1106 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
902725ee | 1107 | return false; |
e9576ca5 | 1108 | |
facd6764 | 1109 | m_windowVariant = parent->GetWindowVariant() ; |
8b573fb8 | 1110 | |
facd6764 SC |
1111 | if ( m_macIsUserPane ) |
1112 | { | |
1113 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
8b573fb8 | 1114 | |
ebe86b1e | 1115 | UInt32 features = 0 |
8b573fb8 | 1116 | | kControlSupportsEmbedding |
1f1c8bd4 SC |
1117 | | kControlSupportsLiveFeedback |
1118 | | kControlGetsFocusOnClick | |
8b573fb8 VZ |
1119 | // | kControlHasSpecialBackground |
1120 | // | kControlSupportsCalcBestRect | |
1f1c8bd4 | 1121 | | kControlHandlesTracking |
8b573fb8 | 1122 | | kControlSupportsFocus |
1f1c8bd4 | 1123 | | kControlWantsActivate |
58603178 | 1124 | | kControlWantsIdle ; |
ebe86b1e | 1125 | |
6449b3a8 | 1126 | m_peer = new wxMacControl(this) ; |
58603178 DS |
1127 | OSStatus err =::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); |
1128 | verify_noerr( err ); | |
8b573fb8 | 1129 | |
898d9035 | 1130 | MacPostControlCreate(pos, size) ; |
facd6764 | 1131 | } |
898d9035 | 1132 | |
e766c8a9 | 1133 | #ifndef __WXUNIVERSAL__ |
14c9cbdb | 1134 | // Don't give scrollbars to wxControls unless they ask for them |
58603178 DS |
1135 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) |
1136 | || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL)))) | |
6264b550 RR |
1137 | { |
1138 | MacCreateScrollBars( style ) ; | |
1139 | } | |
e766c8a9 | 1140 | #endif |
3dfafdb9 RD |
1141 | |
1142 | wxWindowCreateEvent event(this); | |
7e4a196e | 1143 | GetEventHandler()->AddPendingEvent(event); |
3dfafdb9 | 1144 | |
902725ee | 1145 | return true; |
e9576ca5 SC |
1146 | } |
1147 | ||
902725ee | 1148 | void wxWindowMac::MacChildAdded() |
08422003 SC |
1149 | { |
1150 | if ( m_vScrollBar ) | |
08422003 | 1151 | m_vScrollBar->Raise() ; |
08422003 | 1152 | if ( m_hScrollBar ) |
08422003 | 1153 | m_hScrollBar->Raise() ; |
08422003 SC |
1154 | } |
1155 | ||
89954433 | 1156 | void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size) |
facd6764 | 1157 | { |
21fd5529 | 1158 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; |
facd6764 | 1159 | |
4f74e0d1 | 1160 | m_peer->SetReference( (URefCon) this ) ; |
58603178 | 1161 | GetParent()->AddChild( this ); |
facd6764 | 1162 | |
5ca0d812 | 1163 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); |
facd6764 SC |
1164 | |
1165 | ControlRef container = (ControlRef) GetParent()->GetHandle() ; | |
1166 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; | |
5ca0d812 | 1167 | ::EmbedControl( m_peer->GetControlRef() , container ) ; |
08422003 | 1168 | GetParent()->MacChildAdded() ; |
facd6764 SC |
1169 | |
1170 | // adjust font, controlsize etc | |
1171 | DoSetWindowVariant( m_windowVariant ) ; | |
1172 | ||
32cd189d | 1173 | m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ; |
facd6764 | 1174 | |
facd6764 | 1175 | if (!m_macIsUserPane) |
170acdc9 | 1176 | SetInitialSize(size); |
facd6764 SC |
1177 | |
1178 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
facd6764 SC |
1179 | } |
1180 | ||
1181 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
1182 | { | |
23176131 JS |
1183 | // Don't assert, in case we set the window variant before |
1184 | // the window is created | |
21fd5529 | 1185 | // wxASSERT( m_peer->Ok() ) ; |
facd6764 | 1186 | |
23176131 JS |
1187 | m_windowVariant = variant ; |
1188 | ||
21fd5529 | 1189 | if (m_peer == NULL || !m_peer->Ok()) |
23176131 | 1190 | return; |
facd6764 | 1191 | |
8b573fb8 | 1192 | ControlSize size ; |
facd6764 SC |
1193 | ThemeFontID themeFont = kThemeSystemFont ; |
1194 | ||
1195 | // we will get that from the settings later | |
8b573fb8 | 1196 | // and make this NORMAL later, but first |
facd6764 | 1197 | // we have a few calculations that we must fix |
8b573fb8 | 1198 | |
facd6764 SC |
1199 | switch ( variant ) |
1200 | { | |
1201 | case wxWINDOW_VARIANT_NORMAL : | |
8b573fb8 VZ |
1202 | size = kControlSizeNormal; |
1203 | themeFont = kThemeSystemFont ; | |
facd6764 | 1204 | break ; |
e15f0a5e | 1205 | |
facd6764 | 1206 | case wxWINDOW_VARIANT_SMALL : |
8b573fb8 VZ |
1207 | size = kControlSizeSmall; |
1208 | themeFont = kThemeSmallSystemFont ; | |
facd6764 | 1209 | break ; |
e15f0a5e | 1210 | |
facd6764 SC |
1211 | case wxWINDOW_VARIANT_MINI : |
1212 | if (UMAGetSystemVersion() >= 0x1030 ) | |
1213 | { | |
8b573fb8 VZ |
1214 | // not always defined in the headers |
1215 | size = 3 ; | |
1216 | themeFont = 109 ; | |
facd6764 SC |
1217 | } |
1218 | else | |
1219 | { | |
8b573fb8 VZ |
1220 | size = kControlSizeSmall; |
1221 | themeFont = kThemeSmallSystemFont ; | |
facd6764 SC |
1222 | } |
1223 | break ; | |
e15f0a5e | 1224 | |
facd6764 | 1225 | case wxWINDOW_VARIANT_LARGE : |
8b573fb8 VZ |
1226 | size = kControlSizeLarge; |
1227 | themeFont = kThemeSystemFont ; | |
facd6764 | 1228 | break ; |
e15f0a5e | 1229 | |
facd6764 SC |
1230 | default: |
1231 | wxFAIL_MSG(_T("unexpected window variant")); | |
1232 | break ; | |
1233 | } | |
e15f0a5e | 1234 | |
898d9035 | 1235 | m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ; |
facd6764 SC |
1236 | |
1237 | wxFont font ; | |
1238 | font.MacCreateThemeFont( themeFont ) ; | |
1239 | SetFont( font ) ; | |
1240 | } | |
1241 | ||
8b573fb8 | 1242 | void wxWindowMac::MacUpdateControlFont() |
facd6764 | 1243 | { |
ac99838a | 1244 | m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; |
8b573fb8 | 1245 | Refresh() ; |
facd6764 SC |
1246 | } |
1247 | ||
1248 | bool wxWindowMac::SetFont(const wxFont& font) | |
1249 | { | |
58603178 | 1250 | bool retval = wxWindowBase::SetFont( font ); |
8b573fb8 | 1251 | |
facd6764 | 1252 | MacUpdateControlFont() ; |
8b573fb8 | 1253 | |
facd6764 SC |
1254 | return retval; |
1255 | } | |
1256 | ||
1257 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
1258 | { | |
58603178 | 1259 | bool retval = wxWindowBase::SetForegroundColour( col ); |
8b573fb8 | 1260 | |
898d9035 | 1261 | if (retval) |
58603178 | 1262 | MacUpdateControlFont(); |
8b573fb8 | 1263 | |
898d9035 | 1264 | return retval; |
facd6764 SC |
1265 | } |
1266 | ||
1267 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
1268 | { | |
1269 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
1270 | return false ; | |
1271 | ||
1272 | wxBrush brush ; | |
b52acd03 | 1273 | wxColour newCol(GetBackgroundColour()); |
58603178 | 1274 | |
26af4dbd | 1275 | if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ) |
facd6764 | 1276 | brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; |
58603178 | 1277 | else if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) ) |
8b573fb8 | 1278 | brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; |
facd6764 | 1279 | else |
b52acd03 | 1280 | brush.SetColour( newCol ) ; |
e15f0a5e | 1281 | |
facd6764 | 1282 | MacSetBackgroundBrush( brush ) ; |
db7a550b | 1283 | MacUpdateControlFont() ; |
8b573fb8 | 1284 | |
facd6764 SC |
1285 | return true ; |
1286 | } | |
1287 | ||
7ea087b7 SC |
1288 | void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
1289 | { | |
1290 | m_macBackgroundBrush = brush ; | |
1291 | m_peer->SetBackground( brush ) ; | |
1292 | } | |
facd6764 SC |
1293 | |
1294 | bool wxWindowMac::MacCanFocus() const | |
1295 | { | |
90b4f7b5 | 1296 | // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so |
2e91d506 DS |
1297 | // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning, |
1298 | // but the value range is nowhere documented | |
90b4f7b5 | 1299 | Boolean keyExistsAndHasValidFormat ; |
2e91d506 DS |
1300 | CFIndex fullKeyboardAccess = CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) , |
1301 | kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat ); | |
1302 | ||
90b4f7b5 | 1303 | if ( keyExistsAndHasValidFormat && fullKeyboardAccess > 0 ) |
2e91d506 | 1304 | { |
90b4f7b5 | 1305 | return true ; |
2e91d506 | 1306 | } |
90b4f7b5 SC |
1307 | else |
1308 | { | |
1309 | UInt32 features = 0 ; | |
1310 | m_peer->GetFeatures( &features ) ; | |
1311 | ||
1312 | return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; | |
1313 | } | |
facd6764 SC |
1314 | } |
1315 | ||
e766c8a9 | 1316 | void wxWindowMac::SetFocus() |
e9576ca5 | 1317 | { |
e15f0a5e | 1318 | if ( !AcceptsFocus() ) |
7d0cfe71 SC |
1319 | return ; |
1320 | ||
e15f0a5e DS |
1321 | wxWindow* former = FindFocus() ; |
1322 | if ( former == this ) | |
1323 | return ; | |
1324 | ||
1325 | // as we cannot rely on the control features to find out whether we are in full keyboard mode, | |
1326 | // we can only leave in case of an error | |
1327 | OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; | |
1328 | if ( err == errCouldntSetFocus ) | |
1329 | return ; | |
1330 | ||
e15f0a5e | 1331 | SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() ); |
f1d527c1 SC |
1332 | |
1333 | #if !TARGET_API_MAC_OSX | |
e15f0a5e DS |
1334 | // emulate carbon events when running under CarbonLib where they are not natively available |
1335 | if ( former ) | |
1336 | { | |
1337 | EventRef evRef = NULL ; | |
58603178 DS |
1338 | |
1339 | err = MacCreateEvent( | |
1340 | NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , | |
1341 | kEventAttributeUserEvent , &evRef ); | |
1342 | verify_noerr( err ); | |
f1d527c1 | 1343 | |
e15f0a5e DS |
1344 | wxMacCarbonEvent cEvent( evRef ) ; |
1345 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; | |
1346 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; | |
8b573fb8 | 1347 | |
e15f0a5e | 1348 | wxMacWindowEventHandler( NULL , evRef , former ) ; |
58603178 | 1349 | ReleaseEvent( evRef ) ; |
e15f0a5e | 1350 | } |
f1d527c1 | 1351 | |
e15f0a5e DS |
1352 | // send new focus event |
1353 | { | |
1354 | EventRef evRef = NULL ; | |
58603178 DS |
1355 | |
1356 | err = MacCreateEvent( | |
1357 | NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , | |
1358 | kEventAttributeUserEvent , &evRef ); | |
1359 | verify_noerr( err ); | |
8b573fb8 | 1360 | |
e15f0a5e DS |
1361 | wxMacCarbonEvent cEvent( evRef ) ; |
1362 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ; | |
1363 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; | |
1364 | ||
1365 | wxMacWindowEventHandler( NULL , evRef , this ) ; | |
58603178 | 1366 | ReleaseEvent( evRef ) ; |
6264b550 | 1367 | } |
e15f0a5e | 1368 | #endif |
e9576ca5 SC |
1369 | } |
1370 | ||
4116c221 | 1371 | void wxWindowMac::DoCaptureMouse() |
e9576ca5 | 1372 | { |
2a1f999f | 1373 | wxApp::s_captureWindow = this ; |
e9576ca5 SC |
1374 | } |
1375 | ||
2e91d506 | 1376 | wxWindow * wxWindowBase::GetCapture() |
90b959ae | 1377 | { |
2a1f999f | 1378 | return wxApp::s_captureWindow ; |
90b959ae SC |
1379 | } |
1380 | ||
4116c221 | 1381 | void wxWindowMac::DoReleaseMouse() |
e9576ca5 | 1382 | { |
2a1f999f | 1383 | wxApp::s_captureWindow = NULL ; |
e9576ca5 SC |
1384 | } |
1385 | ||
e15f0a5e | 1386 | #if wxUSE_DRAG_AND_DROP |
e9576ca5 | 1387 | |
e766c8a9 | 1388 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) |
e9576ca5 | 1389 | { |
e15f0a5e | 1390 | if ( m_dropTarget != NULL ) |
e40298d5 | 1391 | delete m_dropTarget; |
6ed71b4f | 1392 | |
e40298d5 | 1393 | m_dropTarget = pDropTarget; |
e15f0a5e | 1394 | if ( m_dropTarget != NULL ) |
e40298d5 | 1395 | { |
58603178 | 1396 | // TODO: |
e40298d5 | 1397 | } |
e9576ca5 SC |
1398 | } |
1399 | ||
1400 | #endif | |
1401 | ||
2e91d506 | 1402 | // Old-style File Manager Drag & Drop |
89954433 | 1403 | void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept)) |
e9576ca5 | 1404 | { |
58603178 | 1405 | // TODO: |
e9576ca5 SC |
1406 | } |
1407 | ||
055a486b SC |
1408 | // Returns the size of the native control. In the case of the toplevel window |
1409 | // this is the content area root control | |
1410 | ||
89954433 VZ |
1411 | void wxWindowMac::MacGetPositionAndSizeFromControl(int& WXUNUSED(x), |
1412 | int& WXUNUSED(y), | |
1413 | int& WXUNUSED(w), | |
1414 | int& WXUNUSED(h)) const | |
e9576ca5 | 1415 | { |
898d9035 | 1416 | wxFAIL_MSG( wxT("Not currently supported") ) ; |
e9576ca5 SC |
1417 | } |
1418 | ||
055a486b | 1419 | // From a wx position / size calculate the appropriate size of the native control |
8b573fb8 | 1420 | |
898d9035 DS |
1421 | bool wxWindowMac::MacGetBoundsForControl( |
1422 | const wxPoint& pos, | |
1423 | const wxSize& size, | |
1424 | int& x, int& y, | |
1425 | int& w, int& h , bool adjustOrigin ) const | |
51abe921 | 1426 | { |
5ca0d812 | 1427 | // the desired size, minus the border pixels gives the correct size of the control |
facd6764 SC |
1428 | x = (int)pos.x; |
1429 | y = (int)pos.y; | |
58603178 DS |
1430 | |
1431 | // TODO: the default calls may be used as soon as PostCreateControl Is moved here | |
898d9035 DS |
1432 | w = wxMax(size.x, 0) ; // WidthDefault( size.x ); |
1433 | h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ; | |
789ae0cf | 1434 | |
5ca0d812 SC |
1435 | x += MacGetLeftBorderSize() ; |
1436 | y += MacGetTopBorderSize() ; | |
1437 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1438 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
8b573fb8 | 1439 | |
79392158 SC |
1440 | if ( adjustOrigin ) |
1441 | AdjustForParentClientOrigin( x , y ) ; | |
789ae0cf | 1442 | |
7ebf5540 | 1443 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border |
789ae0cf | 1444 | if ( !GetParent()->IsTopLevel() ) |
7ebf5540 SC |
1445 | { |
1446 | x -= GetParent()->MacGetLeftBorderSize() ; | |
1447 | y -= GetParent()->MacGetTopBorderSize() ; | |
1448 | } | |
789ae0cf | 1449 | |
facd6764 SC |
1450 | return true ; |
1451 | } | |
1452 | ||
42ef83fa | 1453 | // Get window size (not client size) |
facd6764 SC |
1454 | void wxWindowMac::DoGetSize(int *x, int *y) const |
1455 | { | |
1f1c8bd4 SC |
1456 | Rect bounds ; |
1457 | m_peer->GetRect( &bounds ) ; | |
8b573fb8 | 1458 | |
e15f0a5e DS |
1459 | if (x) |
1460 | *x = bounds.right - bounds.left + MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1461 | if (y) | |
1462 | *y = bounds.bottom - bounds.top + MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
facd6764 SC |
1463 | } |
1464 | ||
42ef83fa | 1465 | // get the position of the bounds of this window in client coordinates of its parent |
facd6764 SC |
1466 | void wxWindowMac::DoGetPosition(int *x, int *y) const |
1467 | { | |
1f1c8bd4 SC |
1468 | Rect bounds ; |
1469 | m_peer->GetRect( &bounds ) ; | |
902725ee | 1470 | |
1f1c8bd4 SC |
1471 | int x1 = bounds.left ; |
1472 | int y1 = bounds.top ; | |
789ae0cf | 1473 | |
bc2b0c1b SC |
1474 | // get the wx window position from the native one |
1475 | x1 -= MacGetLeftBorderSize() ; | |
1476 | y1 -= MacGetTopBorderSize() ; | |
1477 | ||
facd6764 | 1478 | if ( !IsTopLevel() ) |
2b5f62a0 | 1479 | { |
facd6764 SC |
1480 | wxWindow *parent = GetParent(); |
1481 | if ( parent ) | |
8950f7cc | 1482 | { |
e15f0a5e DS |
1483 | // we must first adjust it to be in window coordinates of the parent, |
1484 | // as otherwise it gets lost by the ClientAreaOrigin fix | |
1a02aff9 SC |
1485 | x1 += parent->MacGetLeftBorderSize() ; |
1486 | y1 += parent->MacGetTopBorderSize() ; | |
e15f0a5e | 1487 | |
1a02aff9 | 1488 | // and now to client coordinates |
facd6764 SC |
1489 | wxPoint pt(parent->GetClientAreaOrigin()); |
1490 | x1 -= pt.x ; | |
1491 | y1 -= pt.y ; | |
6ed71b4f | 1492 | } |
2b5f62a0 | 1493 | } |
e15f0a5e DS |
1494 | |
1495 | if (x) | |
1496 | *x = x1 ; | |
1497 | if (y) | |
1498 | *y = y1 ; | |
facd6764 | 1499 | } |
51abe921 | 1500 | |
e766c8a9 | 1501 | void wxWindowMac::DoScreenToClient(int *x, int *y) const |
e9576ca5 | 1502 | { |
facd6764 | 1503 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
58603178 | 1504 | wxCHECK_RET( window , wxT("TopLevel Window missing") ) ; |
8b573fb8 | 1505 | |
58603178 | 1506 | Point localwhere = { 0, 0 } ; |
519cb848 | 1507 | |
58603178 DS |
1508 | if (x) |
1509 | localwhere.h = *x ; | |
1510 | if (y) | |
1511 | localwhere.v = *y ; | |
8b573fb8 | 1512 | |
4f74e0d1 | 1513 | wxMacGlobalToLocal( window , &localwhere ) ; |
6ed71b4f | 1514 | |
58603178 DS |
1515 | if (x) |
1516 | *x = localwhere.h ; | |
1517 | if (y) | |
1518 | *y = localwhere.v ; | |
e15f0a5e | 1519 | |
2078220e | 1520 | MacRootWindowToWindow( x , y ) ; |
8b573fb8 | 1521 | |
facd6764 | 1522 | wxPoint origin = GetClientAreaOrigin() ; |
e15f0a5e DS |
1523 | if (x) |
1524 | *x -= origin.x ; | |
1525 | if (y) | |
1526 | *y -= origin.y ; | |
e9576ca5 SC |
1527 | } |
1528 | ||
e766c8a9 | 1529 | void wxWindowMac::DoClientToScreen(int *x, int *y) const |
e9576ca5 | 1530 | { |
facd6764 | 1531 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
8523a5f5 | 1532 | wxCHECK_RET( window , wxT("TopLevel window missing") ) ; |
14c9cbdb | 1533 | |
facd6764 | 1534 | wxPoint origin = GetClientAreaOrigin() ; |
e15f0a5e DS |
1535 | if (x) |
1536 | *x += origin.x ; | |
1537 | if (y) | |
1538 | *y += origin.y ; | |
14c9cbdb | 1539 | |
2078220e | 1540 | MacWindowToRootWindow( x , y ) ; |
14c9cbdb | 1541 | |
58603178 DS |
1542 | Point localwhere = { 0, 0 }; |
1543 | if (x) | |
1544 | localwhere.h = *x ; | |
1545 | if (y) | |
1546 | localwhere.v = *y ; | |
e15f0a5e | 1547 | |
4f74e0d1 | 1548 | wxMacLocalToGlobal( window, &localwhere ) ; |
e15f0a5e | 1549 | |
58603178 DS |
1550 | if (x) |
1551 | *x = localwhere.h ; | |
1552 | if (y) | |
1553 | *y = localwhere.v ; | |
519cb848 SC |
1554 | } |
1555 | ||
e766c8a9 | 1556 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const |
519cb848 | 1557 | { |
1c310985 | 1558 | wxPoint origin = GetClientAreaOrigin() ; |
e15f0a5e DS |
1559 | if (x) |
1560 | *x += origin.x ; | |
1561 | if (y) | |
1562 | *y += origin.y ; | |
14c9cbdb | 1563 | |
1c310985 SC |
1564 | MacWindowToRootWindow( x , y ) ; |
1565 | } | |
1566 | ||
1567 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
1568 | { | |
1c310985 | 1569 | MacRootWindowToWindow( x , y ) ; |
facd6764 SC |
1570 | |
1571 | wxPoint origin = GetClientAreaOrigin() ; | |
e15f0a5e DS |
1572 | if (x) |
1573 | *x -= origin.x ; | |
1574 | if (y) | |
1575 | *y -= origin.y ; | |
1c310985 SC |
1576 | } |
1577 | ||
1578 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
1579 | { | |
5ca0d812 | 1580 | wxPoint pt ; |
58603178 | 1581 | |
e15f0a5e DS |
1582 | if (x) |
1583 | pt.x = *x ; | |
1584 | if (y) | |
1585 | pt.y = *y ; | |
facd6764 | 1586 | |
125c7984 | 1587 | if ( !IsTopLevel() ) |
5437ff47 RD |
1588 | { |
1589 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1590 | if (top) | |
5ca0d812 SC |
1591 | { |
1592 | pt.x -= MacGetLeftBorderSize() ; | |
1593 | pt.y -= MacGetTopBorderSize() ; | |
1594 | wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; | |
1595 | } | |
5437ff47 | 1596 | } |
8b573fb8 | 1597 | |
e15f0a5e DS |
1598 | if (x) |
1599 | *x = (int) pt.x ; | |
1600 | if (y) | |
1601 | *y = (int) pt.y ; | |
facd6764 SC |
1602 | } |
1603 | ||
1604 | void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const | |
1605 | { | |
1606 | int x1 , y1 ; | |
e15f0a5e DS |
1607 | |
1608 | if (x) | |
1609 | x1 = *x ; | |
1610 | if (y) | |
1611 | y1 = *y ; | |
1612 | ||
facd6764 | 1613 | MacWindowToRootWindow( &x1 , &y1 ) ; |
e15f0a5e DS |
1614 | |
1615 | if (x) | |
1616 | *x = x1 ; | |
1617 | if (y) | |
1618 | *y = y1 ; | |
519cb848 SC |
1619 | } |
1620 | ||
1c310985 | 1621 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const |
519cb848 | 1622 | { |
5ca0d812 | 1623 | wxPoint pt ; |
e15f0a5e DS |
1624 | |
1625 | if (x) | |
1626 | pt.x = *x ; | |
1627 | if (y) | |
1628 | pt.y = *y ; | |
facd6764 | 1629 | |
125c7984 | 1630 | if ( !IsTopLevel() ) |
5ca0d812 | 1631 | { |
5c840e5b SC |
1632 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); |
1633 | if (top) | |
1634 | { | |
1635 | wxMacControl::Convert( &pt , top->m_peer , m_peer ) ; | |
1636 | pt.x += MacGetLeftBorderSize() ; | |
1637 | pt.y += MacGetTopBorderSize() ; | |
1638 | } | |
5ca0d812 | 1639 | } |
8b573fb8 | 1640 | |
e15f0a5e DS |
1641 | if (x) |
1642 | *x = (int) pt.x ; | |
1643 | if (y) | |
1644 | *y = (int) pt.y ; | |
e9576ca5 SC |
1645 | } |
1646 | ||
facd6764 | 1647 | void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const |
e9576ca5 | 1648 | { |
facd6764 | 1649 | int x1 , y1 ; |
e15f0a5e DS |
1650 | |
1651 | if (x) | |
1652 | x1 = *x ; | |
1653 | if (y) | |
1654 | y1 = *y ; | |
1655 | ||
facd6764 | 1656 | MacRootWindowToWindow( &x1 , &y1 ) ; |
e15f0a5e DS |
1657 | |
1658 | if (x) | |
1659 | *x = x1 ; | |
1660 | if (y) | |
1661 | *y = y1 ; | |
facd6764 | 1662 | } |
6ed71b4f | 1663 | |
29281095 SC |
1664 | void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1665 | { | |
1666 | RgnHandle rgn = NewRgn() ; | |
898d9035 | 1667 | |
5ca0d812 | 1668 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
29281095 | 1669 | { |
898d9035 DS |
1670 | Rect structure, content ; |
1671 | ||
29281095 | 1672 | GetRegionBounds( rgn , &content ) ; |
1f1c8bd4 SC |
1673 | m_peer->GetRect( &structure ) ; |
1674 | OffsetRect( &structure, -structure.left , -structure.top ) ; | |
902725ee | 1675 | |
1f1c8bd4 | 1676 | left = content.left - structure.left ; |
898d9035 | 1677 | top = content.top - structure.top ; |
1f1c8bd4 SC |
1678 | right = structure.right - content.right ; |
1679 | bottom = structure.bottom - content.bottom ; | |
29281095 SC |
1680 | } |
1681 | else | |
1682 | { | |
1f1c8bd4 | 1683 | left = top = right = bottom = 0 ; |
29281095 | 1684 | } |
898d9035 | 1685 | |
7596e51d | 1686 | DisposeRgn( rgn ) ; |
29281095 SC |
1687 | } |
1688 | ||
facd6764 SC |
1689 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const |
1690 | { | |
1691 | wxSize sizeTotal = size; | |
1692 | ||
1693 | RgnHandle rgn = NewRgn() ; | |
5ca0d812 | 1694 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
6618870d | 1695 | { |
898d9035 | 1696 | Rect content, structure ; |
facd6764 | 1697 | GetRegionBounds( rgn , &content ) ; |
1f1c8bd4 | 1698 | m_peer->GetRect( &structure ) ; |
898d9035 | 1699 | |
1f1c8bd4 | 1700 | // structure is in parent coordinates, but we only need width and height, so it's ok |
6ed71b4f | 1701 | |
1f1c8bd4 | 1702 | sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; |
8523a5f5 | 1703 | sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top) ; |
1f1c8bd4 | 1704 | } |
898d9035 | 1705 | |
1f1c8bd4 | 1706 | DisposeRgn( rgn ) ; |
6ed71b4f | 1707 | |
e15f0a5e DS |
1708 | sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; |
1709 | sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
6ed71b4f | 1710 | |
facd6764 | 1711 | return sizeTotal; |
e9576ca5 SC |
1712 | } |
1713 | ||
e9576ca5 | 1714 | // Get size *available for subwindows* i.e. excluding menu bar etc. |
e15f0a5e | 1715 | void wxWindowMac::DoGetClientSize( int *x, int *y ) const |
e9576ca5 | 1716 | { |
9453cf2b | 1717 | int ww, hh; |
6ed71b4f | 1718 | |
facd6764 SC |
1719 | RgnHandle rgn = NewRgn() ; |
1720 | Rect content ; | |
5ca0d812 | 1721 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
facd6764 | 1722 | GetRegionBounds( rgn , &content ) ; |
facd6764 | 1723 | else |
5ca0d812 | 1724 | m_peer->GetRect( &content ) ; |
7596e51d | 1725 | DisposeRgn( rgn ) ; |
789ae0cf | 1726 | |
facd6764 SC |
1727 | ww = content.right - content.left ; |
1728 | hh = content.bottom - content.top ; | |
6ed71b4f | 1729 | |
db7a550b | 1730 | if (m_hScrollBar && m_hScrollBar->IsShown() ) |
e905b636 | 1731 | hh -= m_hScrollBar->GetSize().y ; |
e15f0a5e | 1732 | |
db7a550b | 1733 | if (m_vScrollBar && m_vScrollBar->IsShown() ) |
e905b636 | 1734 | ww -= m_vScrollBar->GetSize().x ; |
e15f0a5e DS |
1735 | |
1736 | if (x) | |
1737 | *x = ww; | |
1738 | if (y) | |
1739 | *y = hh; | |
facd6764 SC |
1740 | } |
1741 | ||
1742 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
1743 | { | |
a3ab1c18 | 1744 | if (m_cursor.IsSameAs(cursor)) |
902725ee | 1745 | return false; |
facd6764 | 1746 | |
2e573683 | 1747 | if (!cursor.IsOk()) |
facd6764 SC |
1748 | { |
1749 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
902725ee | 1750 | return false ; |
facd6764 SC |
1751 | } |
1752 | else | |
1753 | { | |
1754 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
902725ee | 1755 | return false ; |
facd6764 SC |
1756 | } |
1757 | ||
1758 | wxASSERT_MSG( m_cursor.Ok(), | |
1759 | wxT("cursor must be valid after call to the base version")); | |
8b573fb8 | 1760 | |
2d1760d3 | 1761 | wxWindowMac *mouseWin = 0 ; |
facd6764 | 1762 | { |
789ae0cf SC |
1763 | wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ; |
1764 | WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ; | |
4f74e0d1 SC |
1765 | |
1766 | ControlPartCode part ; | |
1767 | ControlRef control ; | |
1768 | Point pt ; | |
1769 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 | |
1770 | HIPoint hiPoint ; | |
1771 | HIGetMousePosition(kHICoordSpaceWindow, window, &hiPoint); | |
1772 | pt.h = hiPoint.x; | |
1773 | pt.v = hiPoint.y; | |
89954433 | 1774 | #else |
2d1760d3 SC |
1775 | CGrafPtr savePort ; |
1776 | Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; | |
8b573fb8 | 1777 | |
58603178 DS |
1778 | // TODO: If we ever get a GetCurrentEvent... replacement |
1779 | // for the mouse position, use it... | |
8b573fb8 | 1780 | |
58603178 DS |
1781 | |
1782 | GetMouse( &pt ) ; | |
4f74e0d1 | 1783 | #endif |
789ae0cf | 1784 | control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ; |
2d1760d3 SC |
1785 | if ( control ) |
1786 | mouseWin = wxFindControlFromMacControl( control ) ; | |
8b573fb8 | 1787 | |
4f74e0d1 SC |
1788 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 |
1789 | if ( swapped ) | |
2d1760d3 | 1790 | QDSwapPort( savePort , NULL ) ; |
4f74e0d1 | 1791 | #endif |
facd6764 | 1792 | } |
2d1760d3 SC |
1793 | |
1794 | if ( mouseWin == this && !wxIsBusy() ) | |
facd6764 | 1795 | m_cursor.MacInstall() ; |
facd6764 | 1796 | |
902725ee | 1797 | return true ; |
519cb848 SC |
1798 | } |
1799 | ||
facd6764 SC |
1800 | #if wxUSE_MENUS |
1801 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
1802 | { | |
1803 | menu->SetInvokingWindow(this); | |
1804 | menu->UpdateUI(); | |
8b573fb8 | 1805 | |
851dee09 | 1806 | if ( x == wxDefaultCoord && y == wxDefaultCoord ) |
971562cb VS |
1807 | { |
1808 | wxPoint mouse = wxGetMousePosition(); | |
898d9035 DS |
1809 | x = mouse.x; |
1810 | y = mouse.y; | |
971562cb VS |
1811 | } |
1812 | else | |
1813 | { | |
1814 | ClientToScreen( &x , &y ) ; | |
1815 | } | |
facd6764 SC |
1816 | |
1817 | menu->MacBeforeDisplay( true ) ; | |
898d9035 | 1818 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ; |
facd6764 SC |
1819 | if ( HiWord(menuResult) != 0 ) |
1820 | { | |
e8027adb SC |
1821 | MenuCommand macid; |
1822 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); | |
b46dde27 DS |
1823 | int id = wxMacCommandToId( macid ); |
1824 | wxMenuItem* item = NULL ; | |
facd6764 | 1825 | wxMenu* realmenu ; |
58603178 | 1826 | item = menu->FindItem( id, &realmenu ) ; |
e8027adb SC |
1827 | if ( item ) |
1828 | { | |
1829 | if (item->IsCheckable()) | |
1830 | item->Check( !item->IsChecked() ) ; | |
e15f0a5e | 1831 | |
e8027adb SC |
1832 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; |
1833 | } | |
facd6764 | 1834 | } |
facd6764 | 1835 | |
898d9035 | 1836 | menu->MacAfterDisplay( true ) ; |
8523a5f5 | 1837 | menu->SetInvokingWindow( NULL ); |
facd6764 | 1838 | |
902725ee | 1839 | return true; |
facd6764 SC |
1840 | } |
1841 | #endif | |
51abe921 SC |
1842 | |
1843 | // ---------------------------------------------------------------------------- | |
1844 | // tooltips | |
1845 | // ---------------------------------------------------------------------------- | |
1846 | ||
1847 | #if wxUSE_TOOLTIPS | |
1848 | ||
e766c8a9 | 1849 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) |
51abe921 SC |
1850 | { |
1851 | wxWindowBase::DoSetToolTip(tooltip); | |
6ed71b4f | 1852 | |
6264b550 RR |
1853 | if ( m_tooltip ) |
1854 | m_tooltip->SetWindow(this); | |
51abe921 SC |
1855 | } |
1856 | ||
898d9035 | 1857 | #endif |
51abe921 | 1858 | |
902725ee | 1859 | void wxWindowMac::MacInvalidateBorders() |
6449b3a8 SC |
1860 | { |
1861 | if ( m_peer == NULL ) | |
1862 | return ; | |
1863 | ||
1864 | bool vis = MacIsReallyShown() ; | |
1865 | if ( !vis ) | |
1866 | return ; | |
902725ee | 1867 | |
6449b3a8 SC |
1868 | int outerBorder = MacGetLeftBorderSize() ; |
1869 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
1870 | outerBorder += 4 ; | |
1871 | ||
1872 | if ( outerBorder == 0 ) | |
1873 | return ; | |
902725ee WS |
1874 | |
1875 | // now we know that we have something to do at all | |
6449b3a8 SC |
1876 | |
1877 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
58603178 DS |
1878 | RgnHandle updateInner , updateOuter; |
1879 | Rect rect ; | |
6449b3a8 SC |
1880 | |
1881 | // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon | |
58603178 DS |
1882 | updateInner = NewRgn() ; |
1883 | updateOuter = NewRgn() ; | |
1884 | ||
6449b3a8 | 1885 | m_peer->GetRect( &rect ) ; |
898d9035 | 1886 | RectRgn( updateInner, &rect ) ; |
6449b3a8 | 1887 | InsetRect( &rect , -outerBorder , -outerBorder ) ; |
898d9035 DS |
1888 | RectRgn( updateOuter, &rect ) ; |
1889 | DiffRgn( updateOuter, updateInner , updateOuter ) ; | |
e15f0a5e | 1890 | |
6449b3a8 | 1891 | #ifdef __WXMAC_OSX__ |
1f1c8bd4 | 1892 | GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ; |
6449b3a8 SC |
1893 | #else |
1894 | WindowRef tlw = (WindowRef) MacGetTopLevelWindowRef() ; | |
1895 | if ( tlw ) | |
1896 | InvalWindowRgn( tlw , updateOuter ) ; | |
1897 | #endif | |
e15f0a5e | 1898 | |
58603178 DS |
1899 | DisposeRgn( updateOuter ) ; |
1900 | DisposeRgn( updateInner ) ; | |
6449b3a8 SC |
1901 | } |
1902 | ||
e766c8a9 | 1903 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) |
51abe921 | 1904 | { |
db7a550b | 1905 | // this is never called for a toplevel window, so we know we have a parent |
facd6764 | 1906 | int former_x , former_y , former_w, former_h ; |
db7a550b SC |
1907 | |
1908 | // Get true coordinates of former position | |
facd6764 SC |
1909 | DoGetPosition( &former_x , &former_y ) ; |
1910 | DoGetSize( &former_w , &former_h ) ; | |
db7a550b SC |
1911 | |
1912 | wxWindow *parent = GetParent(); | |
1913 | if ( parent ) | |
1914 | { | |
1915 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1916 | former_x += pt.x ; | |
1917 | former_y += pt.y ; | |
1918 | } | |
6ed71b4f | 1919 | |
29ee02df SC |
1920 | int actualWidth = width ; |
1921 | int actualHeight = height ; | |
e40298d5 JS |
1922 | int actualX = x; |
1923 | int actualY = y; | |
6ed71b4f | 1924 | |
14c9cbdb | 1925 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) |
6264b550 | 1926 | actualWidth = m_minWidth; |
14c9cbdb | 1927 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
6264b550 | 1928 | actualHeight = m_minHeight; |
14c9cbdb | 1929 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
6264b550 | 1930 | actualWidth = m_maxWidth; |
14c9cbdb | 1931 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
902725ee | 1932 | actualHeight = m_maxHeight; |
6ed71b4f | 1933 | |
898d9035 | 1934 | bool doMove = false, doResize = false ; |
6ed71b4f | 1935 | |
6264b550 | 1936 | if ( actualX != former_x || actualY != former_y ) |
6264b550 | 1937 | doMove = true ; |
e15f0a5e | 1938 | |
6264b550 | 1939 | if ( actualWidth != former_w || actualHeight != former_h ) |
6264b550 | 1940 | doResize = true ; |
6ed71b4f | 1941 | |
6264b550 RR |
1942 | if ( doMove || doResize ) |
1943 | { | |
902725ee | 1944 | // as the borders are drawn outside the native control, we adjust now |
1f1c8bd4 | 1945 | |
902725ee WS |
1946 | wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ), |
1947 | wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) , | |
1f1c8bd4 SC |
1948 | actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; |
1949 | ||
1950 | Rect r ; | |
1951 | wxMacRectToNative( &bounds , &r ) ; | |
1952 | ||
1953 | if ( !GetParent()->IsTopLevel() ) | |
1f1c8bd4 | 1954 | wxMacWindowToNative( GetParent() , &r ) ; |
8b573fb8 | 1955 | |
6449b3a8 | 1956 | MacInvalidateBorders() ; |
902725ee | 1957 | |
5c840e5b | 1958 | m_cachedClippedRectValid = false ; |
8b573fb8 | 1959 | m_peer->SetRect( &r ) ; |
902725ee | 1960 | |
e905b636 | 1961 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
91ae6e3a | 1962 | |
6449b3a8 SC |
1963 | MacInvalidateBorders() ; |
1964 | ||
6264b550 RR |
1965 | MacRepositionScrollBars() ; |
1966 | if ( doMove ) | |
1967 | { | |
898d9035 | 1968 | wxPoint point(actualX, actualY); |
6264b550 RR |
1969 | wxMoveEvent event(point, m_windowId); |
1970 | event.SetEventObject(this); | |
1971 | GetEventHandler()->ProcessEvent(event) ; | |
1972 | } | |
e15f0a5e | 1973 | |
6264b550 RR |
1974 | if ( doResize ) |
1975 | { | |
e40298d5 | 1976 | MacRepositionScrollBars() ; |
facd6764 | 1977 | wxSize size(actualWidth, actualHeight); |
e40298d5 JS |
1978 | wxSizeEvent event(size, m_windowId); |
1979 | event.SetEventObject(this); | |
1980 | GetEventHandler()->ProcessEvent(event); | |
6264b550 RR |
1981 | } |
1982 | } | |
954fc50b SC |
1983 | } |
1984 | ||
facd6764 SC |
1985 | wxSize wxWindowMac::DoGetBestSize() const |
1986 | { | |
eb69d46e SC |
1987 | if ( m_macIsUserPane || IsTopLevel() ) |
1988 | return wxWindowBase::DoGetBestSize() ; | |
8b573fb8 | 1989 | |
facd6764 | 1990 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
facd6764 | 1991 | int bestWidth, bestHeight ; |
facd6764 | 1992 | |
898d9035 | 1993 | m_peer->GetBestRect( &bestsize ) ; |
facd6764 SC |
1994 | if ( EmptyRect( &bestsize ) ) |
1995 | { | |
898d9035 DS |
1996 | bestsize.left = |
1997 | bestsize.top = 0 ; | |
1998 | bestsize.right = | |
facd6764 | 1999 | bestsize.bottom = 16 ; |
898d9035 | 2000 | |
facd6764 SC |
2001 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) |
2002 | { | |
2003 | bestsize.bottom = 16 ; | |
2004 | } | |
902725ee | 2005 | #if wxUSE_SPINBTN |
facd6764 SC |
2006 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) |
2007 | { | |
8b573fb8 | 2008 | bestsize.bottom = 24 ; |
facd6764 | 2009 | } |
898d9035 | 2010 | #endif |
facd6764 SC |
2011 | else |
2012 | { | |
8b573fb8 | 2013 | // return wxWindowBase::DoGetBestSize() ; |
facd6764 SC |
2014 | } |
2015 | } | |
2016 | ||
2017 | bestWidth = bestsize.right - bestsize.left ; | |
2018 | bestHeight = bestsize.bottom - bestsize.top ; | |
2019 | if ( bestHeight < 10 ) | |
2020 | bestHeight = 13 ; | |
8b573fb8 | 2021 | |
facd6764 SC |
2022 | return wxSize(bestWidth, bestHeight); |
2023 | } | |
2024 | ||
954fc50b SC |
2025 | // set the size of the window: if the dimensions are positive, just use them, |
2026 | // but if any of them is equal to -1, it means that we must find the value for | |
2027 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
2028 | // which case -1 is a valid value for x and y) | |
2029 | // | |
2030 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
2031 | // the width/height to best suit our contents, otherwise we reuse the current | |
2032 | // width/height | |
2033 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
2034 | { | |
2035 | // get the current size and position... | |
2036 | int currentX, currentY; | |
898d9035 | 2037 | int currentW, currentH; |
6ed71b4f | 2038 | |
898d9035 | 2039 | GetPosition(¤tX, ¤tY); |
954fc50b | 2040 | GetSize(¤tW, ¤tH); |
6ed71b4f | 2041 | |
954fc50b SC |
2042 | // ... and don't do anything (avoiding flicker) if it's already ok |
2043 | if ( x == currentX && y == currentY && | |
769ac869 | 2044 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) |
954fc50b | 2045 | { |
e15f0a5e | 2046 | // TODO: REMOVE |
6264b550 | 2047 | MacRepositionScrollBars() ; // we might have a real position shift |
898d9035 | 2048 | |
954fc50b SC |
2049 | return; |
2050 | } | |
6ed71b4f | 2051 | |
58603178 DS |
2052 | if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
2053 | { | |
2054 | if ( x == wxDefaultCoord ) | |
2055 | x = currentX; | |
2056 | if ( y == wxDefaultCoord ) | |
2057 | y = currentY; | |
2058 | } | |
6ed71b4f | 2059 | |
58603178 | 2060 | AdjustForParentClientOrigin( x, y, sizeFlags ); |
6ed71b4f | 2061 | |
3dee36ae WS |
2062 | wxSize size = wxDefaultSize; |
2063 | if ( width == wxDefaultCoord ) | |
954fc50b SC |
2064 | { |
2065 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
2066 | { | |
2067 | size = DoGetBestSize(); | |
2068 | width = size.x; | |
2069 | } | |
2070 | else | |
2071 | { | |
2072 | // just take the current one | |
2073 | width = currentW; | |
2074 | } | |
2075 | } | |
6ed71b4f | 2076 | |
3dee36ae | 2077 | if ( height == wxDefaultCoord ) |
954fc50b SC |
2078 | { |
2079 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
2080 | { | |
3dee36ae | 2081 | if ( size.x == wxDefaultCoord ) |
954fc50b | 2082 | size = DoGetBestSize(); |
898d9035 | 2083 | // else: already called DoGetBestSize() above |
6ed71b4f | 2084 | |
954fc50b SC |
2085 | height = size.y; |
2086 | } | |
2087 | else | |
2088 | { | |
2089 | // just take the current one | |
2090 | height = currentH; | |
2091 | } | |
2092 | } | |
6ed71b4f | 2093 | |
58603178 | 2094 | DoMoveWindow( x, y, width, height ); |
e9576ca5 | 2095 | } |
519cb848 | 2096 | |
e766c8a9 | 2097 | wxPoint wxWindowMac::GetClientAreaOrigin() const |
e9576ca5 | 2098 | { |
facd6764 SC |
2099 | RgnHandle rgn = NewRgn() ; |
2100 | Rect content ; | |
04d4e684 | 2101 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
21638402 SC |
2102 | { |
2103 | GetRegionBounds( rgn , &content ) ; | |
2104 | } | |
2105 | else | |
2106 | { | |
898d9035 DS |
2107 | content.left = |
2108 | content.top = 0 ; | |
21638402 | 2109 | } |
898d9035 | 2110 | |
facd6764 | 2111 | DisposeRgn( rgn ) ; |
e15f0a5e DS |
2112 | |
2113 | return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() ); | |
facd6764 SC |
2114 | } |
2115 | ||
2116 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
2117 | { | |
d0dec992 | 2118 | if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord ) |
facd6764 SC |
2119 | { |
2120 | int currentclientwidth , currentclientheight ; | |
2121 | int currentwidth , currentheight ; | |
2122 | ||
2123 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
2124 | GetSize( ¤twidth , ¤theight ) ; | |
2125 | ||
3dee36ae | 2126 | DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth , |
facd6764 SC |
2127 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; |
2128 | } | |
e9576ca5 SC |
2129 | } |
2130 | ||
fb5246be | 2131 | void wxWindowMac::SetLabel(const wxString& title) |
e9576ca5 | 2132 | { |
32cd189d | 2133 | m_label = wxStripMenuCodes(title, wxStrip_Mnemonics) ; |
facd6764 | 2134 | |
21fd5529 | 2135 | if ( m_peer && m_peer->Ok() ) |
fb5246be | 2136 | m_peer->SetLabel( m_label ) ; |
e15f0a5e | 2137 | |
facd6764 | 2138 | Refresh() ; |
519cb848 SC |
2139 | } |
2140 | ||
fb5246be | 2141 | wxString wxWindowMac::GetLabel() const |
519cb848 | 2142 | { |
ed60b502 | 2143 | return m_label ; |
519cb848 SC |
2144 | } |
2145 | ||
8ab50549 SC |
2146 | bool wxWindowMac::Show(bool show) |
2147 | { | |
542f604f | 2148 | bool former = MacIsReallyShown() ; |
8ab50549 | 2149 | if ( !wxWindowBase::Show(show) ) |
902725ee | 2150 | return false; |
8b573fb8 | 2151 | |
58603178 | 2152 | // TODO: use visibilityChanged Carbon Event for OSX |
2c899c20 | 2153 | if ( m_peer ) |
2c899c20 | 2154 | m_peer->SetVisibility( show , true ) ; |
e15f0a5e | 2155 | |
542f604f SC |
2156 | if ( former != MacIsReallyShown() ) |
2157 | MacPropagateVisibilityChanged() ; | |
898d9035 | 2158 | |
902725ee | 2159 | return true; |
8ab50549 SC |
2160 | } |
2161 | ||
47a8a4d5 | 2162 | void wxWindowMac::DoEnable(bool enable) |
8ab50549 | 2163 | { |
5ca0d812 | 2164 | m_peer->Enable( enable ) ; |
8ab50549 SC |
2165 | } |
2166 | ||
8b573fb8 | 2167 | // |
8ab50549 SC |
2168 | // status change propagations (will be not necessary for OSX later ) |
2169 | // | |
2170 | ||
facd6764 SC |
2171 | void wxWindowMac::MacPropagateVisibilityChanged() |
2172 | { | |
73fe67bd | 2173 | #if !TARGET_API_MAC_OSX |
facd6764 | 2174 | MacVisibilityChanged() ; |
8b573fb8 | 2175 | |
e15f0a5e | 2176 | wxWindowMac *child; |
71f2fb52 | 2177 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
facd6764 SC |
2178 | while ( node ) |
2179 | { | |
e15f0a5e | 2180 | child = node->GetData(); |
facd6764 | 2181 | if ( child->IsShown() ) |
e15f0a5e DS |
2182 | child->MacPropagateVisibilityChanged() ; |
2183 | ||
facd6764 SC |
2184 | node = node->GetNext(); |
2185 | } | |
73fe67bd | 2186 | #endif |
facd6764 SC |
2187 | } |
2188 | ||
89954433 | 2189 | void wxWindowMac::OnEnabled(bool WXUNUSED(enabled)) |
e9576ca5 | 2190 | { |
73fe67bd | 2191 | #if !TARGET_API_MAC_OSX |
8ab50549 | 2192 | MacEnabledStateChanged() ; |
73fe67bd | 2193 | #endif |
8ab50549 SC |
2194 | } |
2195 | ||
e15f0a5e | 2196 | void wxWindowMac::MacPropagateHiliteChanged() |
8ab50549 | 2197 | { |
73fe67bd | 2198 | #if !TARGET_API_MAC_OSX |
8ab50549 | 2199 | MacHiliteChanged() ; |
8b573fb8 | 2200 | |
e15f0a5e | 2201 | wxWindowMac *child; |
71f2fb52 | 2202 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
8ab50549 SC |
2203 | while ( node ) |
2204 | { | |
e15f0a5e | 2205 | child = node->GetData(); |
898d9035 | 2206 | if (child /* && child->IsEnabled() */) |
8ab50549 | 2207 | child->MacPropagateHiliteChanged() ; |
e15f0a5e | 2208 | |
8ab50549 SC |
2209 | node = node->GetNext(); |
2210 | } | |
73fe67bd | 2211 | #endif |
8ab50549 SC |
2212 | } |
2213 | ||
2214 | // | |
2215 | // status change notifications | |
8b573fb8 | 2216 | // |
8ab50549 | 2217 | |
8b573fb8 | 2218 | void wxWindowMac::MacVisibilityChanged() |
8ab50549 SC |
2219 | { |
2220 | } | |
2221 | ||
8b573fb8 | 2222 | void wxWindowMac::MacHiliteChanged() |
8ab50549 SC |
2223 | { |
2224 | } | |
2225 | ||
8b573fb8 | 2226 | void wxWindowMac::MacEnabledStateChanged() |
8ab50549 | 2227 | { |
facd6764 | 2228 | } |
e7549107 | 2229 | |
8ab50549 SC |
2230 | // |
2231 | // status queries on the inherited window's state | |
2232 | // | |
2233 | ||
8b573fb8 | 2234 | bool wxWindowMac::MacIsReallyShown() |
facd6764 SC |
2235 | { |
2236 | // only under OSX the visibility of the TLW is taken into account | |
66ffb23b SC |
2237 | if ( m_isBeingDeleted ) |
2238 | return false ; | |
902725ee | 2239 | |
facd6764 | 2240 | #if TARGET_API_MAC_OSX |
aa522e33 SC |
2241 | if ( m_peer && m_peer->Ok() ) |
2242 | return m_peer->IsVisible(); | |
2243 | #endif | |
e15f0a5e | 2244 | |
facd6764 | 2245 | wxWindow* win = this ; |
898d9035 | 2246 | while ( win->IsShown() ) |
facd6764 SC |
2247 | { |
2248 | if ( win->IsTopLevel() ) | |
2249 | return true ; | |
8b573fb8 | 2250 | |
facd6764 SC |
2251 | win = win->GetParent() ; |
2252 | if ( win == NULL ) | |
2253 | return true ; | |
e15f0a5e | 2254 | } |
8b573fb8 | 2255 | |
facd6764 | 2256 | return false ; |
facd6764 | 2257 | } |
4241baae | 2258 | |
8b573fb8 | 2259 | bool wxWindowMac::MacIsReallyEnabled() |
facd6764 | 2260 | { |
5ca0d812 | 2261 | return m_peer->IsEnabled() ; |
facd6764 SC |
2262 | } |
2263 | ||
8b573fb8 | 2264 | bool wxWindowMac::MacIsReallyHilited() |
c809f3be | 2265 | { |
5ca0d812 | 2266 | return m_peer->IsActive(); |
c809f3be SC |
2267 | } |
2268 | ||
8b573fb8 | 2269 | void wxWindowMac::MacFlashInvalidAreas() |
002c9672 SC |
2270 | { |
2271 | #if TARGET_API_MAC_OSX | |
2272 | HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ; | |
2273 | #endif | |
2274 | } | |
2275 | ||
e766c8a9 | 2276 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 2277 | { |
e15f0a5e DS |
2278 | wxClientDC dc( (wxWindowMac*)this ) ; |
2279 | ||
6264b550 | 2280 | return dc.GetCharHeight() ; |
e9576ca5 SC |
2281 | } |
2282 | ||
e766c8a9 | 2283 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 2284 | { |
e15f0a5e DS |
2285 | wxClientDC dc( (wxWindowMac*)this ) ; |
2286 | ||
6264b550 | 2287 | return dc.GetCharWidth() ; |
e9576ca5 SC |
2288 | } |
2289 | ||
e766c8a9 | 2290 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 2291 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 2292 | { |
e7549107 SC |
2293 | const wxFont *fontToUse = theFont; |
2294 | if ( !fontToUse ) | |
2295 | fontToUse = &m_font; | |
14c9cbdb | 2296 | |
e766c8a9 | 2297 | wxClientDC dc( (wxWindowMac*) this ) ; |
659863d8 | 2298 | wxCoord lx,ly,ld,le ; |
5fde6fcc | 2299 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 2300 | if ( externalLeading ) |
6264b550 | 2301 | *externalLeading = le ; |
2f1ae414 | 2302 | if ( descent ) |
6264b550 | 2303 | *descent = ld ; |
2f1ae414 | 2304 | if ( x ) |
6264b550 | 2305 | *x = lx ; |
2f1ae414 | 2306 | if ( y ) |
6264b550 | 2307 | *y = ly ; |
e9576ca5 SC |
2308 | } |
2309 | ||
0a67a93b | 2310 | /* |
14c9cbdb | 2311 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect |
1c310985 SC |
2312 | * we always intersect with the entire window, not only with the client area |
2313 | */ | |
14c9cbdb | 2314 | |
89954433 | 2315 | void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) |
e9576ca5 | 2316 | { |
065ab451 SC |
2317 | if ( m_peer == NULL ) |
2318 | return ; | |
8b573fb8 | 2319 | |
1f1c8bd4 SC |
2320 | if ( !MacIsReallyShown() ) |
2321 | return ; | |
789ae0cf | 2322 | |
1f1c8bd4 | 2323 | if ( rect ) |
1e8cde71 | 2324 | { |
1f1c8bd4 | 2325 | Rect r ; |
898d9035 | 2326 | |
1f1c8bd4 SC |
2327 | wxMacRectToNative( rect , &r ) ; |
2328 | m_peer->SetNeedsDisplay( &r ) ; | |
facd6764 | 2329 | } |
1f1c8bd4 | 2330 | else |
9a456218 | 2331 | { |
1f1c8bd4 | 2332 | m_peer->SetNeedsDisplay() ; |
e9576ca5 | 2333 | } |
facd6764 SC |
2334 | } |
2335 | ||
79392158 SC |
2336 | void wxWindowMac::Freeze() |
2337 | { | |
2338 | #if TARGET_API_MAC_OSX | |
2339 | if ( !m_frozenness++ ) | |
2340 | { | |
52ef5c3c RD |
2341 | if ( m_peer && m_peer->Ok() ) |
2342 | m_peer->SetDrawingEnabled( false ) ; | |
79392158 SC |
2343 | } |
2344 | #endif | |
2345 | } | |
2346 | ||
2347 | void wxWindowMac::Thaw() | |
2348 | { | |
2349 | #if TARGET_API_MAC_OSX | |
898d9035 | 2350 | wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") ); |
79392158 SC |
2351 | |
2352 | if ( !--m_frozenness ) | |
2353 | { | |
52ef5c3c RD |
2354 | if ( m_peer && m_peer->Ok() ) |
2355 | { | |
2356 | m_peer->SetDrawingEnabled( true ) ; | |
2357 | m_peer->InvalidateWithChildren() ; | |
2358 | } | |
79392158 SC |
2359 | } |
2360 | #endif | |
2361 | } | |
2362 | ||
fd39f7a8 RD |
2363 | bool wxWindowMac::IsFrozen() const |
2364 | { | |
2365 | return m_frozenness != 0; | |
2366 | } | |
2367 | ||
e766c8a9 | 2368 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 2369 | { |
519cb848 | 2370 | // actually this is a windows-only concept |
e9576ca5 SC |
2371 | return NULL; |
2372 | } | |
2373 | ||
e9576ca5 | 2374 | // Coordinates relative to the window |
89954433 | 2375 | void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos)) |
e9576ca5 | 2376 | { |
e40298d5 | 2377 | // We really don't move the mouse programmatically under Mac. |
e9576ca5 SC |
2378 | } |
2379 | ||
facd6764 | 2380 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) |
e9576ca5 | 2381 | { |
3dee36ae WS |
2382 | if ( MacGetTopLevelWindow() == NULL ) |
2383 | return ; | |
898d9035 | 2384 | |
be346c26 | 2385 | #if TARGET_API_MAC_OSX |
4488a1d3 VZ |
2386 | if ( !m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT |
2387 | || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) | |
94abc21f | 2388 | { |
facd6764 | 2389 | event.Skip() ; |
94abc21f SC |
2390 | } |
2391 | else | |
be346c26 | 2392 | #endif |
7ebf5540 | 2393 | { |
8b573fb8 | 2394 | event.GetDC()->Clear() ; |
7ebf5540 | 2395 | } |
1c310985 SC |
2396 | } |
2397 | ||
2398 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
2399 | { | |
af6b7b80 | 2400 | event.Skip() ; |
e9576ca5 SC |
2401 | } |
2402 | ||
e766c8a9 | 2403 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 2404 | { |
1c310985 SC |
2405 | if ( orient == wxHORIZONTAL ) |
2406 | { | |
2407 | if ( m_hScrollBar ) | |
2408 | return m_hScrollBar->GetThumbPosition() ; | |
2409 | } | |
2410 | else | |
2411 | { | |
2412 | if ( m_vScrollBar ) | |
2413 | return m_vScrollBar->GetThumbPosition() ; | |
2414 | } | |
e15f0a5e | 2415 | |
e9576ca5 SC |
2416 | return 0; |
2417 | } | |
2418 | ||
2419 | // This now returns the whole range, not just the number | |
2420 | // of positions that we can scroll. | |
e766c8a9 | 2421 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 2422 | { |
1c310985 SC |
2423 | if ( orient == wxHORIZONTAL ) |
2424 | { | |
2425 | if ( m_hScrollBar ) | |
2426 | return m_hScrollBar->GetRange() ; | |
2427 | } | |
2428 | else | |
2429 | { | |
2430 | if ( m_vScrollBar ) | |
2431 | return m_vScrollBar->GetRange() ; | |
2432 | } | |
e15f0a5e | 2433 | |
e9576ca5 SC |
2434 | return 0; |
2435 | } | |
2436 | ||
e766c8a9 | 2437 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 2438 | { |
1c310985 SC |
2439 | if ( orient == wxHORIZONTAL ) |
2440 | { | |
2441 | if ( m_hScrollBar ) | |
2442 | return m_hScrollBar->GetThumbSize() ; | |
2443 | } | |
2444 | else | |
2445 | { | |
2446 | if ( m_vScrollBar ) | |
2447 | return m_vScrollBar->GetThumbSize() ; | |
2448 | } | |
e15f0a5e | 2449 | |
e9576ca5 SC |
2450 | return 0; |
2451 | } | |
2452 | ||
89954433 | 2453 | void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) |
e9576ca5 | 2454 | { |
1c310985 | 2455 | if ( orient == wxHORIZONTAL ) |
6264b550 | 2456 | { |
1c310985 SC |
2457 | if ( m_hScrollBar ) |
2458 | m_hScrollBar->SetThumbPosition( pos ) ; | |
6264b550 RR |
2459 | } |
2460 | else | |
2461 | { | |
1c310985 SC |
2462 | if ( m_vScrollBar ) |
2463 | m_vScrollBar->SetThumbPosition( pos ) ; | |
6264b550 | 2464 | } |
2f1ae414 SC |
2465 | } |
2466 | ||
c1142003 VZ |
2467 | void |
2468 | wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag) | |
2469 | { | |
2470 | bool needVisibilityUpdate = false; | |
2471 | ||
2472 | if ( m_hScrollBarAlwaysShown != hflag ) | |
2473 | { | |
2474 | m_hScrollBarAlwaysShown = hflag; | |
2475 | needVisibilityUpdate = true; | |
2476 | } | |
2477 | ||
2478 | if ( m_vScrollBarAlwaysShown != vflag ) | |
2479 | { | |
2480 | m_vScrollBarAlwaysShown = vflag; | |
2481 | needVisibilityUpdate = true; | |
2482 | } | |
2483 | ||
2484 | if ( needVisibilityUpdate ) | |
2485 | DoUpdateScrollbarVisibility(); | |
2486 | } | |
c79aad8b SC |
2487 | // |
2488 | // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef | |
2489 | // our own window origin is at leftOrigin/rightOrigin | |
2490 | // | |
2491 | ||
89954433 | 2492 | void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) ) |
2f1ae414 | 2493 | { |
e15f0a5e | 2494 | if ( IsTopLevel() ) |
6264b550 | 2495 | return ; |
8b573fb8 | 2496 | |
fd926bcc | 2497 | Rect rect ; |
c79aad8b | 2498 | bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ; |
e15f0a5e | 2499 | bool hasBothScrollbars = (m_hScrollBar && m_hScrollBar->IsShown()) && (m_vScrollBar && m_vScrollBar->IsShown()) ; |
c79aad8b | 2500 | |
8f39b6c4 | 2501 | // back to the surrounding frame rectangle |
58603178 | 2502 | m_peer->GetRect( &rect ) ; |
8f39b6c4 | 2503 | InsetRect( &rect, -1 , -1 ) ; |
fd926bcc | 2504 | |
89954433 | 2505 | #if wxMAC_USE_CORE_GRAPHICS |
c79aad8b | 2506 | { |
8f39b6c4 SC |
2507 | CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , |
2508 | rect.bottom - rect.top ) ; | |
2509 | ||
c79aad8b | 2510 | HIThemeFrameDrawInfo info ; |
58603178 | 2511 | memset( &info, 0 , sizeof(info) ) ; |
902725ee | 2512 | |
c79aad8b SC |
2513 | info.version = 0 ; |
2514 | info.kind = 0 ; | |
2515 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2516 | info.isFocused = hasFocus ; | |
c79aad8b SC |
2517 | |
2518 | CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; | |
2519 | wxASSERT( cgContext ) ; | |
902725ee | 2520 | |
e15f0a5e | 2521 | if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) |
c79aad8b | 2522 | { |
c79aad8b | 2523 | info.kind = kHIThemeFrameTextFieldSquare ; |
8f39b6c4 | 2524 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; |
c79aad8b | 2525 | } |
e15f0a5e | 2526 | else if ( HasFlag(wxSIMPLE_BORDER) ) |
c79aad8b | 2527 | { |
c79aad8b | 2528 | info.kind = kHIThemeFrameListBox ; |
c79aad8b SC |
2529 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; |
2530 | } | |
2531 | else if ( hasFocus ) | |
2532 | { | |
c79aad8b SC |
2533 | HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; |
2534 | } | |
902725ee | 2535 | |
c79aad8b SC |
2536 | m_peer->GetRect( &rect ) ; |
2537 | if ( hasBothScrollbars ) | |
2538 | { | |
c79aad8b | 2539 | int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ; |
8f39b6c4 SC |
2540 | CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; |
2541 | CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; | |
902725ee | 2542 | HIThemeGrowBoxDrawInfo info ; |
e15f0a5e | 2543 | memset( &info, 0, sizeof(info) ) ; |
c79aad8b SC |
2544 | info.version = 0 ; |
2545 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2546 | info.kind = kHIThemeGrowBoxKindNone ; | |
2547 | info.size = kHIThemeGrowBoxSizeNormal ; | |
2548 | info.direction = kThemeGrowRight | kThemeGrowDown ; | |
2549 | HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; | |
2550 | } | |
2551 | } | |
4f74e0d1 | 2552 | #else |
fd926bcc SC |
2553 | { |
2554 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
e15f0a5e | 2555 | if ( top ) |
fd926bcc | 2556 | { |
e15f0a5e | 2557 | wxPoint pt(0, 0) ; |
fd926bcc | 2558 | wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; |
1f1c8bd4 | 2559 | OffsetRect( &rect , pt.x , pt.y ) ; |
fd926bcc | 2560 | } |
8b573fb8 | 2561 | |
e15f0a5e DS |
2562 | if ( HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) |
2563 | DrawThemeEditTextFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ; | |
2564 | else if ( HasFlag(wxSIMPLE_BORDER) ) | |
2565 | DrawThemeListBoxFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ; | |
902725ee | 2566 | |
c79aad8b | 2567 | if ( hasFocus ) |
8f39b6c4 | 2568 | DrawThemeFocusRect( &rect , true ) ; |
8f39b6c4 | 2569 | |
c79aad8b SC |
2570 | if ( hasBothScrollbars ) |
2571 | { | |
902725ee | 2572 | // GetThemeStandaloneGrowBoxBounds |
e15f0a5e | 2573 | // DrawThemeStandaloneNoGrowBox |
c79aad8b | 2574 | } |
eec462f8 | 2575 | } |
4f74e0d1 | 2576 | #endif |
8208e181 SC |
2577 | } |
2578 | ||
abda5788 SC |
2579 | void wxWindowMac::RemoveChild( wxWindowBase *child ) |
2580 | { | |
2581 | if ( child == m_hScrollBar ) | |
2582 | m_hScrollBar = NULL ; | |
2583 | if ( child == m_vScrollBar ) | |
2584 | m_vScrollBar = NULL ; | |
14c9cbdb | 2585 | |
abda5788 SC |
2586 | wxWindowBase::RemoveChild( child ) ; |
2587 | } | |
2588 | ||
c1142003 | 2589 | void wxWindowMac::DoUpdateScrollbarVisibility() |
e9576ca5 | 2590 | { |
42cc0b31 | 2591 | bool triggerSizeEvent = false; |
58603178 | 2592 | |
c1142003 | 2593 | if ( m_hScrollBar ) |
e40298d5 | 2594 | { |
c1142003 | 2595 | bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded(); |
e15f0a5e | 2596 | |
c1142003 VZ |
2597 | if ( m_hScrollBar->IsShown() != showHScrollBar ) |
2598 | { | |
2599 | m_hScrollBar->Show( showHScrollBar ); | |
2600 | triggerSizeEvent = true; | |
6264b550 | 2601 | } |
e40298d5 | 2602 | } |
c1142003 VZ |
2603 | |
2604 | if ( m_vScrollBar) | |
e40298d5 | 2605 | { |
c1142003 | 2606 | bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded(); |
e15f0a5e | 2607 | |
c1142003 VZ |
2608 | if ( m_vScrollBar->IsShown() != showVScrollBar ) |
2609 | { | |
2610 | m_vScrollBar->Show( showVScrollBar ) ; | |
2611 | triggerSizeEvent = true; | |
6264b550 | 2612 | } |
e40298d5 | 2613 | } |
e15f0a5e | 2614 | |
e40298d5 | 2615 | MacRepositionScrollBars() ; |
42cc0b31 SC |
2616 | if ( triggerSizeEvent ) |
2617 | { | |
2618 | wxSizeEvent event(GetSize(), m_windowId); | |
2619 | event.SetEventObject(this); | |
2620 | GetEventHandler()->ProcessEvent(event); | |
2621 | } | |
e9576ca5 SC |
2622 | } |
2623 | ||
c1142003 VZ |
2624 | // New function that will replace some of the above. |
2625 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumb, | |
2626 | int range, bool refresh) | |
2627 | { | |
2628 | if ( orient == wxHORIZONTAL && m_hScrollBar ) | |
2629 | m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); | |
2630 | else if ( orient == wxVERTICAL && m_vScrollBar ) | |
2631 | m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); | |
2632 | ||
2633 | DoUpdateScrollbarVisibility(); | |
2634 | } | |
2635 | ||
e9576ca5 | 2636 | // Does a physical scroll |
e766c8a9 | 2637 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 2638 | { |
898d9035 | 2639 | if ( dx == 0 && dy == 0 ) |
ba87f54c | 2640 | return ; |
8b573fb8 | 2641 | |
3dee36ae WS |
2642 | int width , height ; |
2643 | GetClientSize( &width , &height ) ; | |
e15f0a5e | 2644 | |
902725ee | 2645 | { |
002c9672 | 2646 | // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control |
8b573fb8 | 2647 | // area is scrolled, this does not occur if width and height are 2 pixels less, |
58603178 | 2648 | // TODO: write optimal workaround |
898d9035 | 2649 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; |
8b573fb8 | 2650 | if ( rect ) |
5ca0d812 | 2651 | scrollrect.Intersect( *rect ) ; |
e15f0a5e | 2652 | |
5ca0d812 | 2653 | if ( m_peer->GetNeedsDisplay() ) |
002c9672 | 2654 | { |
58603178 | 2655 | // because HIViewScrollRect does not scroll the already invalidated area we have two options: |
8dd37b03 | 2656 | // in case there is already a pending redraw on that area |
002c9672 SC |
2657 | // either immediate redraw or full invalidate |
2658 | #if 1 | |
2659 | // is the better overall solution, as it does not slow down scrolling | |
1f1c8bd4 | 2660 | m_peer->SetNeedsDisplay() ; |
002c9672 | 2661 | #else |
8b573fb8 | 2662 | // this would be the preferred version for fast drawing controls |
92346151 | 2663 | |
f474cc8c | 2664 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
a9b456ff | 2665 | if ( UMAGetSystemVersion() >= 0x1030 ) |
42ef83fa | 2666 | HIViewRender(m_peer->GetControlRef()) ; |
f474cc8c SC |
2667 | else |
2668 | #endif | |
2669 | Update() ; | |
002c9672 SC |
2670 | #endif |
2671 | } | |
e15f0a5e | 2672 | |
84e5d27d SC |
2673 | // as the native control might be not a 0/0 wx window coordinates, we have to offset |
2674 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
898d9035 | 2675 | m_peer->ScrollRect( &scrollrect , dx , dy ) ; |
92346151 | 2676 | |
92346151 | 2677 | #if 0 |
902725ee | 2678 | // this would be the preferred version for fast drawing controls |
4f74e0d1 | 2679 | HIViewRender(m_peer->GetControlRef()) ; |
92346151 | 2680 | #endif |
902725ee | 2681 | } |
6ed71b4f | 2682 | |
e15f0a5e DS |
2683 | wxWindowMac *child; |
2684 | int x, y, w, h; | |
71f2fb52 | 2685 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 2686 | { |
e15f0a5e DS |
2687 | child = node->GetData(); |
2688 | if (child == NULL) | |
2689 | continue; | |
2690 | if (child == m_vScrollBar) | |
2691 | continue; | |
2692 | if (child == m_hScrollBar) | |
2693 | continue; | |
2694 | if (child->IsTopLevel()) | |
2695 | continue; | |
6ed71b4f | 2696 | |
6264b550 | 2697 | child->GetPosition( &x, &y ); |
6264b550 | 2698 | child->GetSize( &w, &h ); |
00f55394 SC |
2699 | if (rect) |
2700 | { | |
e15f0a5e DS |
2701 | wxRect rc( x, y, w, h ); |
2702 | if (rect->Intersects( rc )) | |
8d1547ef | 2703 | child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); |
00f55394 SC |
2704 | } |
2705 | else | |
2706 | { | |
8d1547ef | 2707 | child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); |
8b573fb8 | 2708 | } |
6264b550 | 2709 | } |
e9576ca5 SC |
2710 | } |
2711 | ||
e15f0a5e | 2712 | void wxWindowMac::MacOnScroll( wxScrollEvent &event ) |
7c74e7fe | 2713 | { |
687706f5 | 2714 | if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) |
6264b550 RR |
2715 | { |
2716 | wxScrollWinEvent wevent; | |
2717 | wevent.SetPosition(event.GetPosition()); | |
2718 | wevent.SetOrientation(event.GetOrientation()); | |
687706f5 KH |
2719 | wevent.SetEventObject(this); |
2720 | ||
2721 | if (event.GetEventType() == wxEVT_SCROLL_TOP) | |
2722 | wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); | |
2723 | else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) | |
2724 | wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); | |
2725 | else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) | |
2726 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); | |
2727 | else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) | |
2728 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); | |
2729 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) | |
2730 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); | |
2731 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) | |
2732 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); | |
2733 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) | |
2734 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); | |
2735 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) | |
2736 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); | |
6ed71b4f VZ |
2737 | |
2738 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
2739 | } |
2740 | } | |
2741 | ||
e9576ca5 | 2742 | // Get the window with the focus |
0fe02759 | 2743 | wxWindowMac *wxWindowBase::DoFindFocus() |
e9576ca5 | 2744 | { |
f1d527c1 SC |
2745 | ControlRef control ; |
2746 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2747 | return wxFindControlFromMacControl( control ) ; | |
519cb848 SC |
2748 | } |
2749 | ||
e15f0a5e | 2750 | void wxWindowMac::OnSetFocus( wxFocusEvent& event ) |
7810c95b SC |
2751 | { |
2752 | // panel wants to track the window which was the last to have focus in it, | |
2753 | // so we want to set ourselves as the window which last had focus | |
2754 | // | |
dac390e9 | 2755 | // notice that it's also important to do it upwards the tree because |
7810c95b SC |
2756 | // otherwise when the top level panel gets focus, it won't set it back to |
2757 | // us, but to some other sibling | |
6ed71b4f | 2758 | |
dac390e9 | 2759 | // CS: don't know if this is still needed: |
c1fb8167 SC |
2760 | //wxChildFocusEvent eventFocus(this); |
2761 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b | 2762 | |
5ca0d812 SC |
2763 | if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) |
2764 | { | |
dac390e9 DS |
2765 | #if wxMAC_USE_CORE_GRAPHICS |
2766 | GetParent()->Refresh() ; | |
2767 | #else | |
788e118f | 2768 | wxMacWindowStateSaver sv( this ) ; |
6449b3a8 | 2769 | Rect rect ; |
dac390e9 | 2770 | |
6449b3a8 | 2771 | m_peer->GetRect( &rect ) ; |
8d1547ef | 2772 |