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