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