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