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