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