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