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