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