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