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