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