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