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