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