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