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