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