]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/nonownedwnd.cpp
Change wxNotebook selection before sending page changed event in wxMSW.
[wxWidgets.git] / src / osx / carbon / nonownedwnd.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/nonownedwnd.cpp
489468fe
SC
3// Purpose: implementation of wxNonOwnedWindow
4// Author: Stefan Csomor
5// Created: 2008-03-24
b5b208a1 6// RCS-ID: $Id$
489468fe
SC
7// Copyright: (c) Stefan Csomor 2008
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifndef WX_PRECOMP
15 #include "wx/app.h"
16#endif // WX_PRECOMP
17
18#include "wx/hashmap.h"
19#include "wx/evtloop.h"
20#include "wx/tooltip.h"
21#include "wx/nonownedwnd.h"
22
1f0c8f31 23#include "wx/osx/private.h"
489468fe
SC
24#include "wx/settings.h"
25#include "wx/frame.h"
26
27#if wxUSE_SYSTEM_OPTIONS
28 #include "wx/sysopt.h"
29#endif
30
524c47aa
SC
31// ============================================================================
32// wxNonOwnedWindow implementation
33// ============================================================================
b2680ced 34
e185a681
SC
35// unified title and toolbar constant - not in Tiger headers, so we duplicate it here
36#define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
37
b2680ced
SC
38IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl , wxNonOwnedWindowImpl )
39
b2680ced
SC
40WXWindow wxNonOwnedWindowCarbonImpl::GetWXWindow() const
41{
42 return (WXWindow) m_macWindow;
43}
44void wxNonOwnedWindowCarbonImpl::Raise()
45{
46 ::SelectWindow( m_macWindow ) ;
47}
48
49void wxNonOwnedWindowCarbonImpl::Lower()
50{
51 ::SendBehind( m_macWindow , NULL ) ;
52}
53
dbc7ceb9
KO
54void wxNonOwnedWindowCarbonImpl::ShowWithoutActivating()
55{
56 bool plainTransition = true;
57
58#if wxUSE_SYSTEM_OPTIONS
59 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) )
60 plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ;
61#endif
62
63 if ( plainTransition )
64 ::ShowWindow( (WindowRef)m_macWindow );
65 else
66 ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL );
67}
68
b2680ced
SC
69bool wxNonOwnedWindowCarbonImpl::Show(bool show)
70{
71 bool plainTransition = true;
72
73#if wxUSE_SYSTEM_OPTIONS
74 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) )
75 plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ;
76#endif
77
78 if (show)
79 {
dbc7ceb9 80 ShowWithoutActivating();
b2680ced 81 ::SelectWindow( (WindowRef)m_macWindow ) ;
b2680ced
SC
82 }
83 else
84 {
85#if wxOSX_USE_CARBON
86 if ( plainTransition )
87 ::HideWindow( (WindowRef)m_macWindow );
88 else
89 ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL );
90#endif
91 }
92 return true;
93}
94
95void wxNonOwnedWindowCarbonImpl::Update()
96{
97 HIWindowFlush(m_macWindow) ;
98}
99
100bool wxNonOwnedWindowCarbonImpl::SetTransparent(wxByte alpha)
101{
102 OSStatus result = SetWindowAlpha((WindowRef)m_macWindow, (CGFloat)((alpha)/255.0));
103 return result == noErr;
104}
105
106bool wxNonOwnedWindowCarbonImpl::SetBackgroundColour(const wxColour& col )
107{
108 if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)) )
109 {
110 SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ;
4d949e7f
SC
111 m_wxPeer->SetBackgroundStyle(wxBG_STYLE_SYSTEM);
112 // call directly if object is not yet completely constructed
113 if ( m_wxPeer->GetNonOwnedPeer() == NULL )
114 SetBackgroundStyle(wxBG_STYLE_SYSTEM);
b2680ced
SC
115 }
116 else if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)) )
117 {
118 SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ;
4d949e7f
SC
119 m_wxPeer->SetBackgroundStyle(wxBG_STYLE_SYSTEM);
120 // call directly if object is not yet completely constructed
121 if ( m_wxPeer->GetNonOwnedPeer() == NULL )
122 SetBackgroundStyle(wxBG_STYLE_SYSTEM);
b2680ced
SC
123 }
124 return true;
125}
126
127void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle )
128{
129 if ( m_macWindow != NULL )
130 {
131 bool metal = exStyle & wxFRAME_EX_METAL ;
132
133 if ( MacGetMetalAppearance() != metal )
134 {
135 if ( MacGetUnifiedAppearance() )
136 MacSetUnifiedAppearance( !metal ) ;
137
138 MacSetMetalAppearance( metal ) ;
139 }
140 }
141}
142
143bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style)
03647350 144{
b2680ced
SC
145 if ( style == wxBG_STYLE_TRANSPARENT )
146 {
147 OSStatus err = HIWindowChangeFeatures( m_macWindow, 0, kWindowIsOpaque );
148 verify_noerr( err );
149 err = ReshapeCustomWindow( m_macWindow );
52cda80e
SC
150 verify_noerr( err );
151 }
b2680ced
SC
152
153 return true ;
154}
155
156bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
157{
158 return true;
159}
160
161void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left , int &top , int &width , int &height ) const
162{
163 Rect content, structure ;
164
165 GetWindowBounds( m_macWindow, kWindowStructureRgn , &structure ) ;
166 GetWindowBounds( m_macWindow, kWindowContentRgn , &content ) ;
167
168 left = content.left - structure.left ;
169 top = content.top - structure.top ;
170 width = content.right - content.left ;
171 height = content.bottom - content.top ;
172}
173
174void wxNonOwnedWindowCarbonImpl::MoveWindow(int x, int y, int width, int height)
175{
176 Rect bounds = { y , x , y + height , x + width } ;
177 verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
178}
179
180void wxNonOwnedWindowCarbonImpl::GetPosition( int &x, int &y ) const
181{
182 Rect bounds ;
183
184 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
185
186 x = bounds.left ;
187 y = bounds.top ;
188}
189
190void wxNonOwnedWindowCarbonImpl::GetSize( int &width, int &height ) const
191{
192 Rect bounds ;
193
194 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
195
196 width = bounds.right - bounds.left ;
197 height = bounds.bottom - bounds.top ;
198}
199
200bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
201{
202 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ;
203}
204
205void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
206{
207 ChangeWindowAttributes( m_macWindow, attributesToSet, attributesToClear ) ;
208}
209
210wxUint32 wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
211{
212 UInt32 attr = 0 ;
213 GetWindowAttributes( m_macWindow, &attr ) ;
214 return attr ;
215}
216
217void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set )
218{
219 if ( MacGetUnifiedAppearance() )
220 MacSetUnifiedAppearance( false ) ;
221
222 MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
223 set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
224}
225
226bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
227{
228 return MacGetWindowAttributes() & kWindowMetalAttribute ;
229}
230
231void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set )
232{
233 if ( MacGetMetalAppearance() )
234 MacSetMetalAppearance( false ) ;
235
236 MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes ,
237 set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ;
238
239 // For some reason, Tiger uses white as the background color for this appearance,
4c51a665 240 // while most apps using it use the typical striped background. Restore that behaviour
b2680ced
SC
241 // for wx.
242 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
243 // though)
03647350 244 // since when creating the peering is not yet completely set-up we call both setters
4c51a665 245 // explicitly
b2680ced 246 m_wxPeer->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ;
524c47aa 247 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ;
b2680ced 248}
489468fe 249
489468fe
SC
250
251// ----------------------------------------------------------------------------
252// globals
253// ----------------------------------------------------------------------------
254
255static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param);
256
52cda80e 257void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent );
b2680ced 258
489468fe
SC
259// ---------------------------------------------------------------------------
260// Carbon Events
261// ---------------------------------------------------------------------------
262
263static const EventTypeSpec eventList[] =
264{
265 // TODO: remove control related event like key and mouse (except for WindowLeave events)
266
267 { kEventClassKeyboard, kEventRawKeyDown } ,
268 { kEventClassKeyboard, kEventRawKeyRepeat } ,
269 { kEventClassKeyboard, kEventRawKeyUp } ,
270 { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
271
272 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
273 { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
274
275 { kEventClassWindow , kEventWindowShown } ,
276 { kEventClassWindow , kEventWindowActivated } ,
277 { kEventClassWindow , kEventWindowDeactivated } ,
278 { kEventClassWindow , kEventWindowBoundsChanging } ,
279 { kEventClassWindow , kEventWindowBoundsChanged } ,
280 { kEventClassWindow , kEventWindowClose } ,
281 { kEventClassWindow , kEventWindowGetRegion } ,
282
283 // we have to catch these events on the toplevel window level,
284 // as controls don't get the raw mouse events anymore
285
286 { kEventClassMouse , kEventMouseDown } ,
287 { kEventClassMouse , kEventMouseUp } ,
288 { kEventClassMouse , kEventMouseWheelMoved } ,
289 { kEventClassMouse , kEventMouseMoved } ,
290 { kEventClassMouse , kEventMouseDragged } ,
291} ;
292
293static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
294{
295 OSStatus result = eventNotHandledErr ;
296 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
297 // FindFocus does not return the actual focus window, but the enclosing window
298 wxWindow* focus = wxWindow::DoFindFocus();
299 if ( focus == NULL )
b2680ced 300 focus = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL ;
489468fe
SC
301
302 unsigned char charCode ;
303 wxChar uniChar[2] ;
304 uniChar[0] = 0;
305 uniChar[1] = 0;
306
307 UInt32 keyCode ;
308 UInt32 modifiers ;
309 Point point ;
310 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
311
312#if wxUSE_UNICODE
313 ByteCount dataSize = 0 ;
314 if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr )
315 {
316 UniChar buf[2] ;
317 int numChars = dataSize / sizeof( UniChar) + 1;
318
319 UniChar* charBuf = buf ;
320
321 if ( numChars * 2 > 4 )
322 charBuf = new UniChar[ numChars ] ;
323 GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
324 charBuf[ numChars - 1 ] = 0;
325
489468fe
SC
326 wxMBConvUTF16 converter ;
327 converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ;
489468fe
SC
328
329 if ( numChars * 2 > 4 )
330 delete[] charBuf ;
331 }
b7db3788 332#endif // wxUSE_UNICODE
489468fe
SC
333
334 GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode );
335 GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
336 GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers );
337 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point );
338
339 UInt32 message = (keyCode << 8) + charCode;
340 switch ( GetEventKind( event ) )
341 {
342 case kEventRawKeyRepeat :
343 case kEventRawKeyDown :
344 {
345 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
346 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
347 wxTheApp->MacSetCurrentEvent( event , handler ) ;
348 if ( /* focus && */ wxTheApp->MacSendKeyDownEvent(
349 focus , message , modifiers , when , point.h , point.v , uniChar[0] ) )
350 {
351 result = noErr ;
352 }
353 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
354 }
355 break ;
356
357 case kEventRawKeyUp :
358 if ( /* focus && */ wxTheApp->MacSendKeyUpEvent(
359 focus , message , modifiers , when , point.h , point.v , uniChar[0] ) )
360 {
361 result = noErr ;
362 }
363 break ;
364
365 case kEventRawKeyModifiersChanged :
366 {
367 wxKeyEvent event(wxEVT_KEY_DOWN);
368
369 event.m_shiftDown = modifiers & shiftKey;
370 event.m_controlDown = modifiers & controlKey;
371 event.m_altDown = modifiers & optionKey;
372 event.m_metaDown = modifiers & cmdKey;
373 event.m_x = point.h;
374 event.m_y = point.v;
375
376#if wxUSE_UNICODE
377 event.m_uniChar = uniChar[0] ;
378#endif
379
380 event.SetTimestamp(when);
381 event.SetEventObject(focus);
382
383 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & controlKey )
384 {
385 event.m_keyCode = WXK_CONTROL ;
386 event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
387 focus->HandleWindowEvent( event ) ;
388 }
389 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & shiftKey )
390 {
391 event.m_keyCode = WXK_SHIFT ;
392 event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
393 focus->HandleWindowEvent( event ) ;
394 }
395 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & optionKey )
396 {
397 event.m_keyCode = WXK_ALT ;
398 event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
399 focus->HandleWindowEvent( event ) ;
400 }
401 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & cmdKey )
402 {
403 event.m_keyCode = WXK_COMMAND ;
404 event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
405 focus->HandleWindowEvent( event ) ;
406 }
407
408 wxApp::s_lastModifiers = modifiers ;
409 }
410 break ;
411
412 default:
413 break;
414 }
415
416 return result ;
417}
418
419// we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
420// for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
421// mouse down at all
422//
423// This handler can also be called from app level where data (ie target window) may be null or a non wx window
424
489468fe
SC
425EventMouseButton g_lastButton = 0 ;
426bool g_lastButtonWasFakeRight = false ;
427
428void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
429{
430 UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ;
431 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
432
433 // these parameters are not given for all events
434 EventMouseButton button = 0 ;
435 UInt32 clickCount = 0 ;
436 UInt32 mouseChord = 0;
437
438 cEvent.GetParameter<EventMouseButton>( kEventParamMouseButton, typeMouseButton , &button ) ;
439 cEvent.GetParameter<UInt32>( kEventParamClickCount, typeUInt32 , &clickCount ) ;
440 // the chord is the state of the buttons pressed currently
441 cEvent.GetParameter<UInt32>( kEventParamMouseChord, typeUInt32 , &mouseChord ) ;
442
443 wxevent.m_x = screenMouseLocation.h;
444 wxevent.m_y = screenMouseLocation.v;
445 wxevent.m_shiftDown = modifiers & shiftKey;
446 wxevent.m_controlDown = modifiers & controlKey;
447 wxevent.m_altDown = modifiers & optionKey;
448 wxevent.m_metaDown = modifiers & cmdKey;
449 wxevent.m_clickCount = clickCount;
450 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
451
452 // a control click is interpreted as a right click
453 bool thisButtonIsFakeRight = false ;
454 if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
455 {
456 button = kEventMouseButtonSecondary ;
457 thisButtonIsFakeRight = true ;
458 }
459
460 // otherwise we report double clicks by connecting a left click with a ctrl-left click
461 if ( clickCount > 1 && button != g_lastButton )
462 clickCount = 1 ;
463
464 // we must make sure that our synthetic 'right' button corresponds in
465 // mouse down, moved and mouse up, and does not deliver a right down and left up
466
467 if ( cEvent.GetKind() == kEventMouseDown )
468 {
469 g_lastButton = button ;
470 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
471 }
472
473 if ( button == 0 )
474 {
475 g_lastButton = 0 ;
476 g_lastButtonWasFakeRight = false ;
477 }
478 else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight )
479 button = g_lastButton ;
480
481 // Adjust the chord mask to remove the primary button and add the
482 // secondary button. It is possible that the secondary button is
483 // already pressed, e.g. on a mouse connected to a laptop, but this
484 // possibility is ignored here:
485 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
486 mouseChord = ((mouseChord & ~1U) | 2U);
487
488 if(mouseChord & 1U)
489 wxevent.m_leftDown = true ;
490 if(mouseChord & 2U)
491 wxevent.m_rightDown = true ;
492 if(mouseChord & 4U)
493 wxevent.m_middleDown = true ;
494
495 // translate into wx types
496 switch ( cEvent.GetKind() )
497 {
498 case kEventMouseDown :
499 switch ( button )
500 {
501 case kEventMouseButtonPrimary :
502 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
503 break ;
504
505 case kEventMouseButtonSecondary :
506 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
507 break ;
508
509 case kEventMouseButtonTertiary :
510 wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
511 break ;
512
513 default:
514 break ;
515 }
516 break ;
517
518 case kEventMouseUp :
519 switch ( button )
520 {
521 case kEventMouseButtonPrimary :
522 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
523 break ;
524
525 case kEventMouseButtonSecondary :
526 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
527 break ;
528
529 case kEventMouseButtonTertiary :
530 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
531 break ;
532
533 default:
534 break ;
535 }
536 break ;
bdb5b32a
SC
537 // TODO http://developer.apple.com/qa/qa2005/qa1453.html
538 // add declaration for 10.4 and change to kEventMouseScroll
539 case kEventMouseWheelMoved :
489468fe
SC
540 {
541 wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
542
543 EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
544 SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeSInt32) ;
545
546 wxevent.m_wheelRotation = delta;
547 wxevent.m_wheelDelta = 1;
548 wxevent.m_linesPerAction = 1;
549 if ( axis == kEventMouseWheelAxisX )
550 wxevent.m_wheelAxis = 1;
551 }
552 break ;
553
554 case kEventMouseEntered :
555 case kEventMouseExited :
556 case kEventMouseDragged :
557 case kEventMouseMoved :
558 wxevent.SetEventType( wxEVT_MOTION ) ;
559 break;
560 default :
561 break ;
562 }
563}
564
565#define NEW_CAPTURE_HANDLING 1
566
567pascal OSStatus
568wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler),
569 EventRef event,
570 void *data)
571{
b2680ced 572 wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL ;
489468fe
SC
573
574 OSStatus result = eventNotHandledErr ;
575
576 wxMacCarbonEvent cEvent( event ) ;
577
578 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
579 Point windowMouseLocation = screenMouseLocation ;
580
581 WindowRef window = NULL;
582 short windowPart = ::FindWindow(screenMouseLocation, &window);
583
584 wxWindow* currentMouseWindow = NULL ;
585 ControlRef control = NULL ;
586
587#if NEW_CAPTURE_HANDLING
588 if ( wxApp::s_captureWindow )
589 {
590 window = (WindowRef) wxApp::s_captureWindow->MacGetTopLevelWindowRef() ;
591 windowPart = inContent ;
592 }
593#endif
594
595 if ( window )
596 {
b2680ced 597 QDGlobalToLocalPoint( GetWindowPort( window ), &windowMouseLocation );
489468fe
SC
598
599 if ( wxApp::s_captureWindow
600#if !NEW_CAPTURE_HANDLING
601 && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent
602#endif
603 )
604 {
605 currentMouseWindow = wxApp::s_captureWindow ;
606 }
607 else if ( (IsWindowActive(window) && windowPart == inContent) )
608 {
609 ControlPartCode part ;
610 control = FindControlUnderMouse( windowMouseLocation , window , &part ) ;
611 // if there is no control below the mouse position, send the event to the toplevel window itself
612 if ( control == 0 )
613 {
b2680ced 614 currentMouseWindow = (wxWindow*) toplevelWindow ;
489468fe
SC
615 }
616 else
617 {
b2680ced 618 currentMouseWindow = (wxWindow*) wxFindWindowFromWXWidget( (WXWidget) control ) ;
489468fe
SC
619#ifndef __WXUNIVERSAL__
620 if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved )
621 {
622#if wxUSE_TOOLBAR
623 // for wxToolBar to function we have to send certaint events to it
624 // instead of its children (wxToolBarTools)
625 ControlRef parent ;
626 GetSuperControl(control, &parent );
f742eaaf
RR
627 wxWindow *wxparent = (wxWindow*) wxFindWindowFromWXWidget((WXWidget) parent ) ;
628 if ( wxparent && wxparent->IsKindOf( CLASSINFO( wxToolBar ) ) )
629 currentMouseWindow = wxparent ;
489468fe
SC
630#endif
631 }
632#endif
633 }
634
635 // disabled windows must not get any input messages
636 if ( currentMouseWindow && !currentMouseWindow->MacIsReallyEnabled() )
637 currentMouseWindow = NULL;
638 }
639 }
640
641 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
642 SetupMouseEvent( wxevent , cEvent ) ;
643
644 // handle all enter / leave events
645
646 if ( currentMouseWindow != g_MacLastWindow )
647 {
648 if ( g_MacLastWindow )
649 {
650 wxMouseEvent eventleave(wxevent);
651 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
652 g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
653 eventleave.SetEventObject( g_MacLastWindow ) ;
654 wxevent.SetId( g_MacLastWindow->GetId() ) ;
655
656#if wxUSE_TOOLTIPS
657 wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
658#endif
659
660 g_MacLastWindow->HandleWindowEvent(eventleave);
661 }
662
663 if ( currentMouseWindow )
664 {
665 wxMouseEvent evententer(wxevent);
666 evententer.SetEventType( wxEVT_ENTER_WINDOW );
667 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
668 evententer.SetEventObject( currentMouseWindow ) ;
669 wxevent.SetId( currentMouseWindow->GetId() ) ;
670
671#if wxUSE_TOOLTIPS
672 wxToolTip::RelayEvent( currentMouseWindow , evententer );
673#endif
674
675 currentMouseWindow->HandleWindowEvent(evententer);
676 }
677
678 g_MacLastWindow = currentMouseWindow ;
679 }
680
681 if ( windowPart == inMenuBar )
682 {
683 // special case menu bar, as we are having a low-level runloop we must do it ourselves
684 if ( cEvent.GetKind() == kEventMouseDown )
685 {
686 ::MenuSelect( screenMouseLocation ) ;
687 ::HiliteMenu(0);
688 result = noErr ;
689 }
03647350 690 }
524c47aa
SC
691 else if ( window && windowPart == inProxyIcon )
692 {
693 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
694 if ( cEvent.GetKind() == kEventMouseDown )
695 {
696 if ( ::TrackWindowProxyDrag( window, screenMouseLocation ) != errUserWantsToDragWindow )
697 {
698 // TODO Track change of file path and report back
699 result = noErr ;
700 }
701 }
489468fe
SC
702 }
703 else if ( currentMouseWindow )
704 {
705 wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent();
706
707 currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
708
709 wxevent.SetEventObject( currentMouseWindow ) ;
710 wxevent.SetId( currentMouseWindow->GetId() ) ;
711
712 // make tooltips current
713
714#if wxUSE_TOOLTIPS
715 if ( wxevent.GetEventType() == wxEVT_MOTION )
716 wxToolTip::RelayEvent( currentMouseWindow , wxevent );
717#endif
718
719 if ( currentMouseWindow->HandleWindowEvent(wxevent) )
720 {
20d88ec6
VZ
721 if ( currentMouseWindowParent &&
722 !currentMouseWindowParent->GetChildren().Member(currentMouseWindow) )
489468fe
SC
723 currentMouseWindow = NULL;
724
725 result = noErr;
726 }
727 else
728 {
729 // if the user code did _not_ handle the event, then perform the
730 // default processing
731 if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
732 {
733 // ... that is set focus to this window
734 if (currentMouseWindow->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow)
735 currentMouseWindow->SetFocus();
736 }
737 }
738
739 if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow )
740 {
741 wxApp::s_captureWindow = NULL ;
742 // update cursor ?
743 }
744
745 // update cursor
746
747 wxWindow* cursorTarget = currentMouseWindow ;
748 wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
03647350 749
489468fe
SC
750 extern wxCursor gGlobalCursor;
751
752 if (!gGlobalCursor.IsOk())
753 {
754 while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
755 {
756 cursorTarget = cursorTarget->GetParent() ;
757 if ( cursorTarget )
758 cursorPoint += cursorTarget->GetPosition();
759 }
760 }
761
762 }
763 else // currentMouseWindow == NULL
764 {
f742eaaf
RR
765 if (toplevelWindow && !control)
766 {
767 extern wxCursor gGlobalCursor;
768 if (!gGlobalCursor.IsOk())
769 {
770 // update cursor when over toolbar and titlebar etc.
fc1e45d9 771 wxSTANDARD_CURSOR->MacInstall() ;
f742eaaf
RR
772 }
773 }
03647350 774
489468fe
SC
775 // don't mess with controls we don't know about
776 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
777 // so we try sending them the correct control directly
778 if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control )
779 {
780 EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
781 Point clickLocation = windowMouseLocation ;
782
783 HIPoint hiPoint ;
784 hiPoint.x = clickLocation.h ;
785 hiPoint.y = clickLocation.v ;
786 HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ;
787 clickLocation.h = (int)hiPoint.x ;
788 clickLocation.v = (int)hiPoint.y ;
789
790 HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ;
791 result = noErr ;
792 }
793 }
794
795 return result ;
796}
797
798static pascal OSStatus
799wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler),
800 EventRef event,
801 void *data)
802{
803 OSStatus result = eventNotHandledErr ;
804
805 wxMacCarbonEvent cEvent( event ) ;
806
807 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
b2680ced 808 wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL;
489468fe
SC
809
810 switch ( GetEventKind( event ) )
811 {
812 case kEventWindowActivated :
813 {
524c47aa 814 toplevelWindow->HandleActivated( cEvent.GetTicks() , true) ;
489468fe
SC
815 // we still sending an eventNotHandledErr in order to allow for default processing
816 }
817 break ;
818
819 case kEventWindowDeactivated :
820 {
524c47aa 821 toplevelWindow->HandleActivated( cEvent.GetTicks() , false) ;
489468fe
SC
822 // we still sending an eventNotHandledErr in order to allow for default processing
823 }
824 break ;
825
826 case kEventWindowShown :
827 toplevelWindow->Refresh() ;
828 result = noErr ;
829 break ;
830
831 case kEventWindowClose :
832 toplevelWindow->Close() ;
833 result = noErr ;
834 break ;
835
836 case kEventWindowBoundsChanged :
837 {
838 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes, typeUInt32) ;
839 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
840 wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ;
841 if ( attributes & kWindowBoundsChangeSizeChanged )
842 {
524c47aa 843 toplevelWindow->HandleResized(cEvent.GetTicks() ) ;
489468fe
SC
844 }
845
846 if ( attributes & kWindowBoundsChangeOriginChanged )
847 {
524c47aa 848 toplevelWindow->HandleMoved(cEvent.GetTicks() ) ;
489468fe
SC
849 }
850
851 result = noErr ;
852 }
853 break ;
854
855 case kEventWindowBoundsChanging :
856 {
857 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
858 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
859
860 if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) )
861 {
862 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
f71d8b3d
SC
863 int left , top , width , height ;
864 // structure width
865 int swidth, sheight;
866
867 toplevelWindow->GetNonOwnedPeer()->GetContentArea(left, top, width, height);
868 toplevelWindow->GetNonOwnedPeer()->GetSize(swidth, sheight);
869 int deltawidth = swidth - width;
870 int deltaheight = sheight - height;
524c47aa 871 wxRect adjustR(
489468fe
SC
872 newRect.left - left,
873 newRect.top - top,
f71d8b3d
SC
874 newRect.right - newRect.left + deltawidth,
875 newRect.bottom - newRect.top + deltaheight ) ;
489468fe 876
524c47aa 877 toplevelWindow->HandleResizing( cEvent.GetTicks(), &adjustR );
03647350
VZ
878
879 const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + top + adjustR.height - deltaheight ,
f71d8b3d 880 adjustR.x + left + adjustR.width - deltawidth } ;
489468fe
SC
881 if ( !EqualRect( &newRect , &adjustedRect ) )
882 cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ;
489468fe
SC
883 }
884
885 result = noErr ;
886 }
887 break ;
888
889 case kEventWindowGetRegion :
890 {
891 if ( toplevelWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
892 {
893 WindowRegionCode windowRegionCode ;
894
895 // Fetch the region code that is being queried
896 GetEventParameter( event,
897 kEventParamWindowRegionCode,
898 typeWindowRegionCode, NULL,
899 sizeof windowRegionCode, NULL,
900 &windowRegionCode ) ;
901
902 // If it is the opaque region code then set the
903 // region to empty and return noErr to stop event
904 // propagation
905 if ( windowRegionCode == kWindowOpaqueRgn ) {
906 RgnHandle region;
907 GetEventParameter( event,
908 kEventParamRgnHandle,
909 typeQDRgnHandle, NULL,
910 sizeof region, NULL,
911 &region) ;
912 SetEmptyRgn(region) ;
913 result = noErr ;
914 }
915 }
916 }
917 break ;
918
919 default :
920 break ;
921 }
922
923 return result ;
924}
925
926// mix this in from window.cpp
927pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
928
52cda80e 929static pascal OSStatus wxNonOwnedEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
489468fe
SC
930{
931 OSStatus result = eventNotHandledErr ;
932
933 switch ( GetEventClass( event ) )
934 {
935 case kEventClassTextInput :
524c47aa
SC
936 {
937 // TODO remove as soon as all events are on implementation classes only
938 wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL;
939
940 result = wxMacUnicodeTextEventHandler( handler, event , toplevelWindow ) ;
941 }
489468fe
SC
942 break ;
943
944 case kEventClassKeyboard :
945 result = KeyboardEventHandler( handler, event , data ) ;
946 break ;
947
948 case kEventClassWindow :
949 result = wxNonOwnedWindowEventHandler( handler, event , data ) ;
950 break ;
951
952 case kEventClassMouse :
953 result = wxMacTopLevelMouseEventHandler( handler, event , data ) ;
954 break ;
955
956 default :
957 break ;
958 }
959
960 return result ;
961}
962
963DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler )
964
965// ---------------------------------------------------------------------------
b2680ced
SC
966// Support functions for shaped windows, based on Apple's CustomWindow sample at
967// http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
489468fe
SC
968// ---------------------------------------------------------------------------
969
b2680ced
SC
970static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
971{
972 GetWindowPortBounds(window, inRect);
973 Point pt = { inRect->top ,inRect->left };
974 QDLocalToGlobalPoint( GetWindowPort( window ), &pt );
975 inRect->bottom += pt.v - inRect->top;
976 inRect->right += pt.h - inRect->left;
977 inRect->top = pt.v;
978 inRect->left = pt.h;
979}
489468fe 980
b2680ced
SC
981static SInt32 wxShapedMacWindowGetFeatures(WindowRef WXUNUSED(window), SInt32 param)
982{
983 /*------------------------------------------------------
984 Define which options your custom window supports.
985 --------------------------------------------------------*/
986 //just enable everything for our demo
987 *(OptionBits*)param =
988 //kWindowCanGrow |
989 //kWindowCanZoom |
990 kWindowCanCollapse |
991 //kWindowCanGetWindowRegion |
992 //kWindowHasTitleBar |
993 //kWindowSupportsDragHilite |
994 kWindowCanDrawInCurrentPort |
995 //kWindowCanMeasureTitle |
996 kWindowWantsDisposeAtProcessDeath |
997 kWindowSupportsGetGrowImageRegion |
998 kWindowDefSupportsColorGrafPort;
489468fe 999
b2680ced
SC
1000 return 1;
1001}
489468fe 1002
b2680ced
SC
1003// The content region is left as a rectangle matching the window size, this is
1004// so the origin in the paint event, and etc. still matches what the
1005// programmer expects.
1006static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn)
489468fe 1007{
b2680ced
SC
1008 SetEmptyRgn(rgn);
1009 wxNonOwnedWindow* win = wxNonOwnedWindow::GetFromWXWindow((WXWindow)window);
1010 if (win)
1011 {
1012 Rect r ;
1013 wxShapedMacWindowGetPos( window, &r ) ;
1014 RectRgn( rgn , &r ) ;
1015 }
489468fe
SC
1016}
1017
b2680ced
SC
1018// The structure region is set to the shape given to the SetShape method.
1019static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
489468fe 1020{
b2680ced 1021 RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window);
489468fe 1022
b2680ced
SC
1023 SetEmptyRgn(rgn);
1024 if (cachedRegion)
1025 {
1026 Rect windowRect;
1027 wxShapedMacWindowGetPos(window, &windowRect); // how big is the window
1028 CopyRgn(cachedRegion, rgn); // make a copy of our cached region
1029 OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
1030 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1031 }
489468fe
SC
1032}
1033
b2680ced 1034static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param)
489468fe 1035{
b2680ced
SC
1036 GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param;
1037
1038 if (rgnRec == NULL)
1039 return paramErr;
1040
1041 switch (rgnRec->regionCode)
489468fe 1042 {
b2680ced
SC
1043 case kWindowStructureRgn:
1044 wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
489468fe 1045 break;
489468fe 1046
b2680ced
SC
1047 case kWindowContentRgn:
1048 wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
1049 break;
489468fe 1050
b2680ced
SC
1051 default:
1052 SetEmptyRgn(rgnRec->winRgn);
1053 break;
1054 }
489468fe 1055
b2680ced 1056 return noErr;
489468fe
SC
1057}
1058
b2680ced
SC
1059// Determine the region of the window which was hit
1060//
1061static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param)
489468fe 1062{
b2680ced
SC
1063 Point hitPoint;
1064 static RgnHandle tempRgn = NULL;
489468fe 1065
b2680ced
SC
1066 if (tempRgn == NULL)
1067 tempRgn = NewRgn();
1068
1069 // get the point clicked
1070 SetPt( &hitPoint, LoWord(param), HiWord(param) );
1071
1072 // Mac OS 8.5 or later
1073 wxShapedMacWindowStructureRegion(window, tempRgn);
1074 if (PtInRgn( hitPoint, tempRgn )) //in window content region?
1075 return wInContent;
1076
1077 // no significant area was hit
1078 return wNoHit;
489468fe
SC
1079}
1080
b2680ced 1081static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode), WindowRef window, SInt16 message, SInt32 param)
489468fe 1082{
b2680ced
SC
1083 switch (message)
1084 {
1085 case kWindowMsgHitTest:
1086 return wxShapedMacWindowHitTest(window, param);
489468fe 1087
b2680ced
SC
1088 case kWindowMsgGetFeatures:
1089 return wxShapedMacWindowGetFeatures(window, param);
489468fe 1090
b2680ced
SC
1091 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1092 case kWindowMsgGetRegion:
1093 return wxShapedMacWindowGetRegion(window, param);
489468fe 1094
b2680ced
SC
1095 default:
1096 break;
1097 }
489468fe 1098
b2680ced
SC
1099 return 0;
1100}
489468fe 1101
b2680ced 1102// implementation
489468fe 1103
b2680ced
SC
1104typedef struct
1105{
1106 wxPoint m_position ;
1107 wxSize m_size ;
1108 bool m_wasResizable ;
1109} FullScreenData ;
489468fe 1110
b2680ced
SC
1111wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1112{
1113}
489468fe 1114
b2680ced
SC
1115wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow* nonownedwnd) : wxNonOwnedWindowImpl( nonownedwnd)
1116{
1117 m_macEventHandler = NULL;
1118 m_macWindow = NULL;
1119 m_macFullScreenData = NULL ;
489468fe
SC
1120}
1121
b2680ced 1122wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
489468fe 1123{
489468fe
SC
1124#if wxUSE_TOOLTIPS
1125 wxToolTip::NotifyWindowDelete(m_macWindow) ;
1126#endif
489468fe
SC
1127
1128 if ( m_macEventHandler )
1129 {
1130 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
1131 m_macEventHandler = NULL ;
1132 }
1133
17e2694c 1134 if ( m_macWindow && !m_wxPeer->IsNativeWindowWrapper())
b2680ced 1135 DisposeWindow( m_macWindow );
489468fe 1136
b2680ced
SC
1137 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
1138 delete data ;
1139 m_macFullScreenData = NULL ;
1140
1141 m_macWindow = NULL;
1142
1143}
1144
0aaa6ace 1145void wxNonOwnedWindowCarbonImpl::WillBeDestroyed()
03647350 1146{
524c47aa
SC
1147 if ( m_macEventHandler )
1148 {
1149 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
1150 m_macEventHandler = NULL ;
1151 }
b2680ced 1152}
489468fe 1153
52cda80e 1154static void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref)
489468fe
SC
1155{
1156 InstallWindowEventHandler(window, GetwxNonOwnedEventHandlerUPP(),
1157 GetEventTypeCount(eventList), eventList, ref, handler );
1158}
1159
b2680ced
SC
1160bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion& region)
1161{
1162 // Make a copy of the region
1163 RgnHandle shapeRegion = NewRgn();
1164 HIShapeGetAsQDRgn( region.GetWXHRGN(), shapeRegion );
1165
1166 // Dispose of any shape region we may already have
1167 RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef) m_wxPeer->GetWXWindow() );
1168 if ( oldRgn )
1169 DisposeRgn(oldRgn);
1170
1171 // Save the region so we can use it later
1172 SetWRefCon((WindowRef) m_wxPeer->GetWXWindow(), (URefCon)shapeRegion);
1173
1174 // inform the window manager that the window has changed shape
1175 ReshapeCustomWindow((WindowRef) m_wxPeer->GetWXWindow());
1176
1177 return true;
1178}
1179
1180
1181void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
489468fe
SC
1182{
1183 if ( m_macEventHandler != NULL )
1184 {
1185 verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ;
1186 }
1187 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this);
1188}
1189
b2680ced 1190void wxNonOwnedWindowCarbonImpl::Create(
ea85e5e0 1191 wxWindow* WXUNUSED(parent),
17e2694c 1192 WXWindow nativeWindow )
489468fe 1193{
17e2694c
SC
1194 m_macWindow = nativeWindow;
1195}
b2680ced 1196
17e2694c
SC
1197void wxNonOwnedWindowCarbonImpl::Create(
1198 wxWindow* parent,
1199 const wxPoint& pos,
1200 const wxSize& size,
1201 long style, long extraStyle,
1202 const wxString& WXUNUSED(name) )
1203{
ea85e5e0 1204
489468fe 1205 OSStatus err = noErr ;
b2680ced 1206 Rect theBoundsRect;
ea85e5e0 1207
489468fe
SC
1208 int x = (int)pos.x;
1209 int y = (int)pos.y;
ea85e5e0 1210
b2680ced
SC
1211 int w = size.x;
1212 int h = size.y;
ea85e5e0 1213
489468fe 1214 ::SetRect(&theBoundsRect, x, y , x + w, y + h);
ea85e5e0 1215
489468fe
SC
1216 // translate the window attributes in the appropriate window class and attributes
1217 WindowClass wclass = 0;
1218 WindowAttributes attr = kWindowNoAttributes ;
1219 WindowGroupRef group = NULL ;
1220 bool activationScopeSet = false;
1221 WindowActivationScope activationScope = kWindowActivationScopeNone;
ea85e5e0 1222
b2680ced 1223 if ( style & wxFRAME_TOOL_WINDOW )
489468fe
SC
1224 {
1225 if (
b2680ced
SC
1226 ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
1227 ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) ||
7282b067 1228 ( style & wxTINY_CAPTION)
489468fe
SC
1229 )
1230 {
b2680ced 1231 if ( ( style & wxSTAY_ON_TOP ) )
489468fe
SC
1232 wclass = kUtilityWindowClass;
1233 else
1234 wclass = kFloatingWindowClass ;
ea85e5e0 1235
7282b067 1236 if ( ( style & wxTINY_CAPTION) )
489468fe
SC
1237 attr |= kWindowSideTitlebarAttribute ;
1238 }
1239 else
1240 {
8f3864f7 1241 if ( style & wxNO_BORDER )
b12a7313
KO
1242 {
1243 wclass = kSimpleWindowClass ;
1244 }
1245 else
1246 {
1247 wclass = kPlainWindowClass ;
1248 }
489468fe
SC
1249 activationScopeSet = true;
1250 activationScope = kWindowActivationScopeNone;
1251 }
1252 }
b2680ced 1253 else if ( ( style & wxPOPUP_WINDOW ) )
489468fe 1254 {
b2680ced 1255 if ( ( style & wxBORDER_NONE ) )
489468fe
SC
1256 {
1257 wclass = kHelpWindowClass ; // has no border
1258 attr |= kWindowNoShadowAttribute;
1259 }
1260 else
1261 {
1262 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
1263 }
1264 group = GetWindowGroupOfClass(kFloatingWindowClass) ;
1265 // make sure we don't deactivate something
1266 activationScopeSet = true;
1267 activationScope = kWindowActivationScopeNone;
1268 }
b2680ced 1269 else if ( ( style & wxCAPTION ) )
489468fe
SC
1270 {
1271 wclass = kDocumentWindowClass ;
1272 attr |= kWindowInWindowMenuAttribute ;
1273 }
b2680ced 1274 else if ( ( style & wxFRAME_DRAWER ) )
489468fe
SC
1275 {
1276 wclass = kDrawerWindowClass;
1277 }
1278 else
1279 {
b2680ced
SC
1280 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
1281 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
489468fe
SC
1282 {
1283 wclass = kDocumentWindowClass ;
1284 }
b2680ced 1285 else if ( ( style & wxNO_BORDER ) )
489468fe
SC
1286 {
1287 wclass = kSimpleWindowClass ;
1288 }
1289 else
1290 {
1291 wclass = kPlainWindowClass ;
1292 }
1293 }
ea85e5e0 1294
489468fe
SC
1295 if ( wclass != kPlainWindowClass )
1296 {
b2680ced 1297 if ( ( style & wxMINIMIZE_BOX ) )
489468fe 1298 attr |= kWindowCollapseBoxAttribute ;
ea85e5e0 1299
b2680ced 1300 if ( ( style & wxMAXIMIZE_BOX ) )
489468fe 1301 attr |= kWindowFullZoomAttribute ;
ea85e5e0 1302
b2680ced 1303 if ( ( style & wxRESIZE_BORDER ) )
489468fe 1304 attr |= kWindowResizableAttribute ;
ea85e5e0 1305
b2680ced 1306 if ( ( style & wxCLOSE_BOX) )
489468fe
SC
1307 attr |= kWindowCloseBoxAttribute ;
1308 }
1309 attr |= kWindowLiveResizeAttribute;
ea85e5e0 1310
b2680ced 1311 if ( ( style &wxSTAY_ON_TOP) )
489468fe 1312 group = GetWindowGroupOfClass(kUtilityWindowClass) ;
ea85e5e0 1313
b2680ced 1314 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) )
489468fe 1315 group = GetWindowGroupOfClass(kFloatingWindowClass) ;
ea85e5e0 1316
489468fe
SC
1317 if ( group == NULL && parent != NULL )
1318 {
1319 WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef();
1320 if( parenttlw )
1321 group = GetWindowGroupParent( GetWindowGroup( parenttlw ) );
1322 }
ea85e5e0 1323
489468fe 1324 attr |= kWindowCompositingAttribute;
292e5e1f 1325#if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
489468fe
SC
1326 attr |= kWindowFrameworkScaledAttribute;
1327#endif
ea85e5e0 1328
b2680ced 1329 if ( ( style &wxFRAME_SHAPED) )
489468fe
SC
1330 {
1331 WindowDefSpec customWindowDefSpec;
1332 customWindowDefSpec.defType = kWindowDefProcPtr;
1333 customWindowDefSpec.u.defProc =
1334#ifdef __LP64__
17e2694c 1335 (WindowDefUPP) wxShapedMacWindowDef;
489468fe 1336#else
17e2694c 1337 NewWindowDefUPP(wxShapedMacWindowDef);
489468fe
SC
1338#endif
1339 err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
17e2694c
SC
1340 attr, &theBoundsRect,
1341 (WindowRef*) &m_macWindow);
489468fe
SC
1342 }
1343 else
1344 {
1345 err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
1346 }
ea85e5e0 1347
489468fe
SC
1348 if ( err == noErr && m_macWindow != NULL && group != NULL )
1349 SetWindowGroup( (WindowRef) m_macWindow , group ) ;
ea85e5e0 1350
489468fe 1351 wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
ea85e5e0 1352
489468fe 1353 // setup a separate group for each window, so that overlays can be handled easily
ea85e5e0 1354
489468fe
SC
1355 WindowGroupRef overlaygroup = NULL;
1356 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup ));
1357 verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow )));
1358 verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup ));
ea85e5e0 1359
489468fe
SC
1360 if ( activationScopeSet )
1361 {
1362 verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope ));
1363 }
ea85e5e0 1364
489468fe
SC
1365 // the create commands are only for content rect,
1366 // so we have to set the size again as structure bounds
b2680ced 1367 SetWindowBounds( m_macWindow , kWindowStructureRgn , &theBoundsRect ) ;
ea85e5e0 1368
489468fe
SC
1369 // Causes the inner part of the window not to be metal
1370 // if the style is used before window creation.
1371#if 0 // TARGET_API_MAC_OSX
1372 if ( m_macUsesCompositing && m_macWindow != NULL )
1373 {
1374 if ( GetExtraStyle() & wxFRAME_EX_METAL )
1375 MacSetMetalAppearance( true ) ;
1376 }
1377#endif
ea85e5e0 1378
489468fe
SC
1379 if ( m_macWindow != NULL )
1380 {
1381 MacSetUnifiedAppearance( true ) ;
1382 }
ea85e5e0 1383
489468fe 1384 HIViewRef growBoxRef = 0 ;
b2680ced 1385 err = HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef );
489468fe
SC
1386 if ( err == noErr && growBoxRef != 0 )
1387 HIGrowBoxViewSetTransparent( growBoxRef, true ) ;
ea85e5e0 1388
489468fe 1389 // the frame window event handler
b2680ced 1390 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow) ) ;
489468fe 1391 MacInstallTopLevelWindowEventHandler() ;
ea85e5e0 1392
b2680ced
SC
1393 if ( extraStyle & wxFRAME_EX_METAL)
1394 MacSetMetalAppearance(true);
ea85e5e0 1395
b2680ced 1396 if ( ( style &wxFRAME_SHAPED) )
489468fe
SC
1397 {
1398 // default shape matches the window size
1399 wxRegion rgn( 0, 0, w, h );
1400 SetShape( rgn );
1401 }
489468fe
SC
1402}
1403
b2680ced 1404bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show,
489468fe
SC
1405 wxShowEffect effect,
1406 unsigned timeout)
1407{
489468fe
SC
1408 WindowTransitionEffect transition = 0 ;
1409 switch( effect )
1410 {
1411 case wxSHOW_EFFECT_ROLL_TO_LEFT:
1412 case wxSHOW_EFFECT_ROLL_TO_RIGHT:
1413 case wxSHOW_EFFECT_ROLL_TO_TOP:
1414 case wxSHOW_EFFECT_ROLL_TO_BOTTOM:
1415 case wxSHOW_EFFECT_SLIDE_TO_LEFT:
1416 case wxSHOW_EFFECT_SLIDE_TO_RIGHT:
1417 case wxSHOW_EFFECT_SLIDE_TO_TOP:
1418 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM:
1419 transition = kWindowGenieTransitionEffect;
1420 break;
1421 case wxSHOW_EFFECT_BLEND:
1422 transition = kWindowFadeTransitionEffect;
1423 break;
1424 case wxSHOW_EFFECT_EXPAND:
1425 // having sheets would be fine, but this might lead to a repositioning
1426#if 0
1427 if ( GetParent() )
1428 transition = kWindowSheetTransitionEffect;
1429 else
1430#endif
1431 transition = kWindowZoomTransitionEffect;
1432 break;
1433
b43914a8
VZ
1434 case wxSHOW_EFFECT_NONE:
1435 // wxNonOwnedWindow is supposed to call Show() itself in this case
1436 wxFAIL_MSG( "ShowWithEffect() shouldn't be called" );
1437 return false;
1438
489468fe
SC
1439 case wxSHOW_EFFECT_MAX:
1440 wxFAIL_MSG( "invalid effect flag" );
1441 return false;
1442 }
1443
1444 TransitionWindowOptions options;
1445 options.version = 0;
1446 options.duration = timeout / 1000.0;
b2680ced 1447 options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) m_wxPeer->GetParent()->MacGetTopLevelWindowRef() :0;
489468fe
SC
1448 options.userData = 0;
1449
1450 wxSize size = wxGetDisplaySize();
b2680ced
SC
1451 Rect bounds;
1452 GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds );
1453 CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top );
489468fe 1454
b2680ced
SC
1455 switch ( effect )
1456 {
1457 case wxSHOW_EFFECT_ROLL_TO_RIGHT:
1458 case wxSHOW_EFFECT_SLIDE_TO_RIGHT:
1459 hiBounds.origin.x = 0;
1460 hiBounds.size.width = 0;
1461 break;
489468fe 1462
b2680ced
SC
1463 case wxSHOW_EFFECT_ROLL_TO_LEFT:
1464 case wxSHOW_EFFECT_SLIDE_TO_LEFT:
1465 hiBounds.origin.x = size.x;
1466 hiBounds.size.width = 0;
1467 break;
489468fe 1468
b2680ced
SC
1469 case wxSHOW_EFFECT_ROLL_TO_TOP:
1470 case wxSHOW_EFFECT_SLIDE_TO_TOP:
1471 hiBounds.origin.y = size.y;
1472 hiBounds.size.height = 0;
1473 break;
489468fe 1474
b2680ced
SC
1475 case wxSHOW_EFFECT_ROLL_TO_BOTTOM:
1476 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM:
1477 hiBounds.origin.y = 0;
1478 hiBounds.size.height = 0;
1479 break;
489468fe 1480
b2680ced
SC
1481 default:
1482 break; // direction doesn't make sense
1483 }
489468fe 1484
b2680ced
SC
1485 ::TransitionWindowWithOptions
1486 (
1487 (WindowRef)m_macWindow,
1488 transition,
1489 show ? kWindowShowTransitionAction : kWindowHideTransitionAction,
1490 transition == kWindowGenieTransitionEffect ? &hiBounds : NULL,
1491 false,
1492 &options
1493 );
489468fe 1494
b2680ced
SC
1495 if ( show )
1496 {
1497 ::SelectWindow( (WindowRef)m_macWindow ) ;
1498 }
489468fe 1499
b2680ced 1500 return true;
489468fe
SC
1501}
1502
03647350 1503void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
489468fe 1504{
b2680ced 1505 SetWindowTitleWithCFString( m_macWindow , wxCFStringRef( title , encoding ) ) ;
489468fe 1506}
03647350 1507
b2680ced 1508bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
489468fe 1509{
b2680ced 1510 return IsWindowInStandardState( m_macWindow , NULL , NULL ) ;
489468fe 1511}
03647350 1512
b2680ced 1513bool wxNonOwnedWindowCarbonImpl::IsIconized() const
489468fe 1514{
b2680ced 1515 return IsWindowCollapsed((WindowRef)GetWXWindow() ) ;
489468fe 1516}
03647350 1517
b2680ced 1518void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize )
489468fe 1519{
b2680ced
SC
1520 if ( IsWindowCollapsable( m_macWindow ) )
1521 CollapseWindow( m_macWindow , iconize ) ;
489468fe 1522}
03647350 1523
b2680ced 1524void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize)
489468fe 1525{
b2680ced
SC
1526 Point idealSize = { 0 , 0 } ;
1527 if ( maximize )
1528 {
1529#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1530 HIRect bounds ;
1531 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
1532 &bounds);
1533 idealSize.h = bounds.size.width;
1534 idealSize.v = bounds.size.height;
1535#else
1536 Rect rect ;
1537 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ;
1538 idealSize.h = rect.right - rect.left ;
1539 idealSize.v = rect.bottom - rect.top ;
1540#endif
1541 }
1542 ZoomWindowIdeal( (WindowRef)GetWXWindow() , maximize ? inZoomOut : inZoomIn , &idealSize ) ;
489468fe 1543}
03647350 1544
b2680ced 1545bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
489468fe 1546{
b2680ced 1547 return m_macFullScreenData != NULL ;
489468fe 1548}
03647350 1549
b2680ced 1550bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show, long style)
489468fe 1551{
b2680ced 1552 if ( show )
489468fe 1553 {
b2680ced
SC
1554 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
1555 delete data ;
1556 data = new FullScreenData() ;
1557
1558 m_macFullScreenData = data ;
1559 data->m_position = m_wxPeer->GetPosition() ;
1560 data->m_size = m_wxPeer->GetSize() ;
1561#if wxOSX_USE_CARBON
1562 WindowAttributes attr = 0;
1563 GetWindowAttributes((WindowRef) GetWXWindow(), &attr);
1564 data->m_wasResizable = attr & kWindowResizableAttribute;
1565 if ( style & wxFULLSCREEN_NOMENUBAR )
1566 HideMenuBar() ;
1567#endif
489468fe 1568
b2680ced 1569 wxRect client = wxGetClientDisplayRect() ;
489468fe 1570
b4afc5ec 1571 int left, top, width, height ;
b2680ced 1572 int x, y, w, h ;
489468fe 1573
b2680ced
SC
1574 x = client.x ;
1575 y = client.y ;
1576 w = client.width ;
1577 h = client.height ;
489468fe 1578
b4afc5ec
SC
1579 GetContentArea( left, top, width, height ) ;
1580 int outerwidth, outerheight;
1581 GetSize( outerwidth, outerheight );
489468fe 1582
b2680ced
SC
1583 if ( style & wxFULLSCREEN_NOCAPTION )
1584 {
1585 y -= top ;
1586 h += top ;
b4afc5ec 1587 // avoid adding the caption twice to the height
03647350 1588 outerheight -= top;
b2680ced 1589 }
489468fe 1590
b2680ced
SC
1591 if ( style & wxFULLSCREEN_NOBORDER )
1592 {
1593 x -= left ;
b4afc5ec
SC
1594 w += outerwidth - width;
1595 h += outerheight - height;
b2680ced 1596 }
489468fe 1597
b2680ced
SC
1598 if ( style & wxFULLSCREEN_NOTOOLBAR )
1599 {
1600 // TODO
1601 }
489468fe 1602
b2680ced
SC
1603 if ( style & wxFULLSCREEN_NOSTATUSBAR )
1604 {
1605 // TODO
1606 }
489468fe 1607
b2680ced
SC
1608 m_wxPeer->SetSize( x , y , w, h ) ;
1609 if ( data->m_wasResizable )
1610 {
1611#if wxOSX_USE_CARBON
1612 ChangeWindowAttributes( (WindowRef) GetWXWindow() , kWindowNoAttributes , kWindowResizableAttribute ) ;
1613#endif
1614 }
1615 }
1616 else if ( m_macFullScreenData != NULL )
489468fe 1617 {
b2680ced
SC
1618 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
1619#if wxOSX_USE_CARBON
1620 ShowMenuBar() ;
1621 if ( data->m_wasResizable )
1622 ChangeWindowAttributes( (WindowRef) GetWXWindow() , kWindowResizableAttribute , kWindowNoAttributes ) ;
1623#endif
1624 m_wxPeer->SetPosition( data->m_position ) ;
1625 m_wxPeer->SetSize( data->m_size ) ;
1626
1627 delete data ;
1628 m_macFullScreenData = NULL ;
489468fe 1629 }
b2680ced
SC
1630
1631 return true;
489468fe
SC
1632}
1633
b2680ced
SC
1634// Attracts the users attention to this window if the application is
1635// inactive (should be called when a background event occurs)
489468fe 1636
b2680ced
SC
1637static pascal void wxMacNMResponse( NMRecPtr ptr )
1638{
1639 NMRemove( ptr ) ;
1640 DisposePtr( (Ptr)ptr ) ;
489468fe
SC
1641}
1642
b2680ced 1643void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags))
489468fe 1644{
b2680ced 1645 NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
489468fe 1646
b2680ced
SC
1647 memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
1648 notificationRequest->qType = nmType ;
1649 notificationRequest->nmMark = 1 ;
1650 notificationRequest->nmIcon = 0 ;
1651 notificationRequest->nmSound = 0 ;
1652 notificationRequest->nmStr = NULL ;
1653 notificationRequest->nmResp = wxMacNMResponse ;
489468fe 1654
b2680ced 1655 verify_noerr( NMInstall( notificationRequest ) ) ;
489468fe
SC
1656}
1657
b2680ced 1658void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x, int *y )
489468fe 1659{
b2680ced
SC
1660 HIPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
1661 HIViewRef contentView ;
1662 // TODO check toolbar offset
1663 HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ;
1664 HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView );
1665 if ( x )
8f2a8de6 1666 *x = (int)p.x;
b2680ced 1667 if ( y )
8f2a8de6 1668 *y = (int)p.y;
489468fe
SC
1669}
1670
b2680ced 1671void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y )
489468fe 1672{
b2680ced
SC
1673 HIPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
1674 HIViewRef contentView ;
1675 // TODO check toolbar offset
1676 HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ;
1677 HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL );
1678 if ( x )
8f2a8de6 1679 *x = (int)p.x;
b2680ced 1680 if ( y )
8f2a8de6 1681 *y = (int)p.y;
489468fe 1682}
524c47aa 1683
dbc7ceb9
KO
1684bool wxNonOwnedWindowCarbonImpl::IsActive()
1685{
1686 return ActiveNonFloatingWindow() == m_macWindow;
1687}
1688
524c47aa
SC
1689wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
1690 long style, long extraStyle, const wxString& name )
1691{
1692 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCarbonImpl( wxpeer );
1693 now->Create( parent, pos, size, style , extraStyle, name );
1694 return now;
1695}
17e2694c
SC
1696
1697wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow )
1698{
1699 wxNonOwnedWindowCarbonImpl* now = new wxNonOwnedWindowCarbonImpl( wxpeer );
1700 now->Create( parent, nativeWindow );
1701 return now;
1702}
1703