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