]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/carbon/nonownedwnd.cpp
move notebook event definition to common code
[wxWidgets.git] / src / osx / carbon / nonownedwnd.cpp
... / ...
CommitLineData
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
42wxWindow* 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
53WX_DECLARE_HASH_MAP(WXWindow, wxNonOwnedWindow*, wxPointerHash, wxPointerEqual, MacWindowMap);
54
55static MacWindowMap wxWinMacWindowList;
56
57wxNonOwnedWindow *wxFindWindowFromWXWindow(WXWindow inWindowRef)
58{
59 MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
60
61 return (node == wxWinMacWindowList.end()) ? NULL : node->second;
62}
63
64void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win) ;
65void 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
74void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win) ;
75void 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
88wxNonOwnedWindow* wxNonOwnedWindow::GetFromWXWindow( WXWindow win )
89{
90 return wxFindWindowFromWXWindow( win );
91}
92
93// ----------------------------------------------------------------------------
94// wxNonOwnedWindow creation
95// ----------------------------------------------------------------------------
96
97IMPLEMENT_ABSTRACT_CLASS( wxNonOwnedWindowImpl , wxObject )
98
99wxNonOwnedWindow *wxNonOwnedWindow::s_macDeactivateWindow = NULL;
100
101void wxNonOwnedWindow::Init()
102{
103 m_nowpeer = NULL;
104}
105
106bool 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
170wxNonOwnedWindow::~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
185bool 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
200bool 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
209wxPoint 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
216bool 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
229void wxNonOwnedWindow::Raise()
230{
231 m_nowpeer->Raise();
232}
233
234// Lower the window to the bottom of the Z order
235void wxNonOwnedWindow::Lower()
236{
237 m_nowpeer->Lower();
238}
239
240void 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
252void 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
262bool 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
281bool wxNonOwnedWindow::SetTransparent(wxByte alpha)
282{
283 return m_nowpeer->SetTransparent(alpha);
284}
285
286
287bool wxNonOwnedWindow::CanSetTransparent()
288{
289 return m_nowpeer->CanSetTransparent();
290}
291
292
293void 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
304bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style)
305{
306 if ( !wxWindow::SetBackgroundStyle(style) )
307 return false ;
308
309 return m_nowpeer->SetBackgroundStyle(style);
310}
311
312void 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
320void 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
331void 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
343void 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
355void wxNonOwnedWindow::Update()
356{
357 m_nowpeer->Update();
358}
359
360WXWindow wxNonOwnedWindow::GetWXWindow() const
361{
362 return m_nowpeer ? m_nowpeer->GetWXWindow() : NULL;
363}
364
365// ---------------------------------------------------------------------------
366// Shape implementation
367// ---------------------------------------------------------------------------
368
369
370bool 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
396IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl , wxNonOwnedWindowImpl )
397
398
399WXWindow wxNonOwnedWindowCarbonImpl::GetWXWindow() const
400{
401 return (WXWindow) m_macWindow;
402}
403void wxNonOwnedWindowCarbonImpl::Raise()
404{
405 ::SelectWindow( m_macWindow ) ;
406}
407
408void wxNonOwnedWindowCarbonImpl::Lower()
409{
410 ::SendBehind( m_macWindow , NULL ) ;
411}
412
413bool 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
445void wxNonOwnedWindowCarbonImpl::Update()
446{
447 HIWindowFlush(m_macWindow) ;
448}
449
450bool wxNonOwnedWindowCarbonImpl::SetTransparent(wxByte alpha)
451{
452 OSStatus result = SetWindowAlpha((WindowRef)m_macWindow, (CGFloat)((alpha)/255.0));
453 return result == noErr;
454}
455
456bool 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
471void 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
487bool 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
500bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
501{
502 return true;
503}
504
505void 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
518void 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
524void 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
534void 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
544bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
545{
546 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ;
547}
548
549void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
550{
551 ChangeWindowAttributes( m_macWindow, attributesToSet, attributesToClear ) ;
552}
553
554wxUint32 wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
555{
556 UInt32 attr = 0 ;
557 GetWindowAttributes( m_macWindow, &attr ) ;
558 return attr ;
559}
560
561void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set )
562{
563 if ( MacGetUnifiedAppearance() )
564 MacSetUnifiedAppearance( false ) ;
565
566 MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
567 set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
568}
569
570bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
571{
572 return MacGetWindowAttributes() & kWindowMetalAttribute ;
573}
574
575void 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
596static 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
609static 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
639static 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
775EventMouseButton g_lastButton = 0 ;
776bool g_lastButtonWasFakeRight = false ;
777
778void 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
916pascal OSStatus
917wxMacTopLevelMouseEventHandler(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
1125static pascal OSStatus
1126wxNonOwnedWindowEventHandler(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
1286pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
1287
1288pascal 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
1317DEFINE_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
1324static 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
1335static 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.
1360static 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.
1373static 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
1388static 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//
1415static 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
1435static 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
1458typedef struct
1459{
1460 wxPoint m_position ;
1461 wxSize m_size ;
1462 bool m_wasResizable ;
1463} FullScreenData ;
1464
1465wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1466{
1467}
1468
1469wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow* nonownedwnd) : wxNonOwnedWindowImpl( nonownedwnd)
1470{
1471 m_macEventHandler = NULL;
1472 m_macWindow = NULL;
1473 m_macFullScreenData = NULL ;
1474}
1475
1476wxNonOwnedWindowCarbonImpl::~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
1499void wxNonOwnedWindowCarbonImpl::Destroy()
1500{
1501 wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ) ;
1502}
1503
1504void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref)
1505{
1506 InstallWindowEventHandler(window, GetwxNonOwnedEventHandlerUPP(),
1507 GetEventTypeCount(eventList), eventList, ref, handler );
1508}
1509
1510bool 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
1531void 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
1540void 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 wclass = kPlainWindowClass ;
1585 activationScopeSet = true;
1586 activationScope = kWindowActivationScopeNone;
1587 }
1588 }
1589 else if ( ( style & wxPOPUP_WINDOW ) )
1590 {
1591 if ( ( style & wxBORDER_NONE ) )
1592 {
1593 wclass = kHelpWindowClass ; // has no border
1594 attr |= kWindowNoShadowAttribute;
1595 }
1596 else
1597 {
1598 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
1599 }
1600 group = GetWindowGroupOfClass(kFloatingWindowClass) ;
1601 // make sure we don't deactivate something
1602 activationScopeSet = true;
1603 activationScope = kWindowActivationScopeNone;
1604 }
1605 else if ( ( style & wxCAPTION ) )
1606 {
1607 wclass = kDocumentWindowClass ;
1608 attr |= kWindowInWindowMenuAttribute ;
1609 }
1610 else if ( ( style & wxFRAME_DRAWER ) )
1611 {
1612 wclass = kDrawerWindowClass;
1613 }
1614 else
1615 {
1616 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
1617 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
1618 {
1619 wclass = kDocumentWindowClass ;
1620 }
1621 else if ( ( style & wxNO_BORDER ) )
1622 {
1623 wclass = kSimpleWindowClass ;
1624 }
1625 else
1626 {
1627 wclass = kPlainWindowClass ;
1628 }
1629 }
1630
1631 if ( wclass != kPlainWindowClass )
1632 {
1633 if ( ( style & wxMINIMIZE_BOX ) )
1634 attr |= kWindowCollapseBoxAttribute ;
1635
1636 if ( ( style & wxMAXIMIZE_BOX ) )
1637 attr |= kWindowFullZoomAttribute ;
1638
1639 if ( ( style & wxRESIZE_BORDER ) )
1640 attr |= kWindowResizableAttribute ;
1641
1642 if ( ( style & wxCLOSE_BOX) )
1643 attr |= kWindowCloseBoxAttribute ;
1644 }
1645 attr |= kWindowLiveResizeAttribute;
1646
1647 if ( ( style &wxSTAY_ON_TOP) )
1648 group = GetWindowGroupOfClass(kUtilityWindowClass) ;
1649
1650 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) )
1651 group = GetWindowGroupOfClass(kFloatingWindowClass) ;
1652
1653 if ( group == NULL && parent != NULL )
1654 {
1655 WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef();
1656 if( parenttlw )
1657 group = GetWindowGroupParent( GetWindowGroup( parenttlw ) );
1658 }
1659
1660 attr |= kWindowCompositingAttribute;
1661#if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1662 attr |= kWindowFrameworkScaledAttribute;
1663#endif
1664
1665 if ( ( style &wxFRAME_SHAPED) )
1666 {
1667 WindowDefSpec customWindowDefSpec;
1668 customWindowDefSpec.defType = kWindowDefProcPtr;
1669 customWindowDefSpec.u.defProc =
1670#ifdef __LP64__
1671 (WindowDefUPP) wxShapedMacWindowDef;
1672#else
1673 NewWindowDefUPP(wxShapedMacWindowDef);
1674#endif
1675 err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
1676 attr, &theBoundsRect,
1677 (WindowRef*) &m_macWindow);
1678 }
1679 else
1680 {
1681 err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
1682 }
1683
1684 if ( err == noErr && m_macWindow != NULL && group != NULL )
1685 SetWindowGroup( (WindowRef) m_macWindow , group ) ;
1686
1687 wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
1688
1689 // setup a separate group for each window, so that overlays can be handled easily
1690
1691 WindowGroupRef overlaygroup = NULL;
1692 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup ));
1693 verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow )));
1694 verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup ));
1695
1696 if ( activationScopeSet )
1697 {
1698 verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope ));
1699 }
1700
1701 // the create commands are only for content rect,
1702 // so we have to set the size again as structure bounds
1703 SetWindowBounds( m_macWindow , kWindowStructureRgn , &theBoundsRect ) ;
1704
1705 // Causes the inner part of the window not to be metal
1706 // if the style is used before window creation.
1707#if 0 // TARGET_API_MAC_OSX
1708 if ( m_macUsesCompositing && m_macWindow != NULL )
1709 {
1710 if ( GetExtraStyle() & wxFRAME_EX_METAL )
1711 MacSetMetalAppearance( true ) ;
1712 }
1713#endif
1714
1715 if ( m_macWindow != NULL )
1716 {
1717 MacSetUnifiedAppearance( true ) ;
1718 }
1719
1720 HIViewRef growBoxRef = 0 ;
1721 err = HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef );
1722 if ( err == noErr && growBoxRef != 0 )
1723 HIGrowBoxViewSetTransparent( growBoxRef, true ) ;
1724
1725 // the frame window event handler
1726 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow) ) ;
1727 MacInstallTopLevelWindowEventHandler() ;
1728
1729 if ( extraStyle & wxFRAME_EX_METAL)
1730 MacSetMetalAppearance(true);
1731
1732 if ( ( style &wxFRAME_SHAPED) )
1733 {
1734 // default shape matches the window size
1735 wxRegion rgn( 0, 0, w, h );
1736 SetShape( rgn );
1737 }
1738}
1739
1740bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show,
1741 wxShowEffect effect,
1742 unsigned timeout)
1743{
1744 WindowTransitionEffect transition = 0 ;
1745 switch( effect )
1746 {
1747 case wxSHOW_EFFECT_ROLL_TO_LEFT:
1748 case wxSHOW_EFFECT_ROLL_TO_RIGHT:
1749 case wxSHOW_EFFECT_ROLL_TO_TOP:
1750 case wxSHOW_EFFECT_ROLL_TO_BOTTOM:
1751 case wxSHOW_EFFECT_SLIDE_TO_LEFT:
1752 case wxSHOW_EFFECT_SLIDE_TO_RIGHT:
1753 case wxSHOW_EFFECT_SLIDE_TO_TOP:
1754 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM:
1755 transition = kWindowGenieTransitionEffect;
1756 break;
1757 case wxSHOW_EFFECT_BLEND:
1758 transition = kWindowFadeTransitionEffect;
1759 break;
1760 case wxSHOW_EFFECT_EXPAND:
1761 // having sheets would be fine, but this might lead to a repositioning
1762#if 0
1763 if ( GetParent() )
1764 transition = kWindowSheetTransitionEffect;
1765 else
1766#endif
1767 transition = kWindowZoomTransitionEffect;
1768 break;
1769
1770 case wxSHOW_EFFECT_MAX:
1771 wxFAIL_MSG( "invalid effect flag" );
1772 return false;
1773 }
1774
1775 TransitionWindowOptions options;
1776 options.version = 0;
1777 options.duration = timeout / 1000.0;
1778 options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) m_wxPeer->GetParent()->MacGetTopLevelWindowRef() :0;
1779 options.userData = 0;
1780
1781 wxSize size = wxGetDisplaySize();
1782 Rect bounds;
1783 GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds );
1784 CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top );
1785
1786 switch ( effect )
1787 {
1788 case wxSHOW_EFFECT_ROLL_TO_RIGHT:
1789 case wxSHOW_EFFECT_SLIDE_TO_RIGHT:
1790 hiBounds.origin.x = 0;
1791 hiBounds.size.width = 0;
1792 break;
1793
1794 case wxSHOW_EFFECT_ROLL_TO_LEFT:
1795 case wxSHOW_EFFECT_SLIDE_TO_LEFT:
1796 hiBounds.origin.x = size.x;
1797 hiBounds.size.width = 0;
1798 break;
1799
1800 case wxSHOW_EFFECT_ROLL_TO_TOP:
1801 case wxSHOW_EFFECT_SLIDE_TO_TOP:
1802 hiBounds.origin.y = size.y;
1803 hiBounds.size.height = 0;
1804 break;
1805
1806 case wxSHOW_EFFECT_ROLL_TO_BOTTOM:
1807 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM:
1808 hiBounds.origin.y = 0;
1809 hiBounds.size.height = 0;
1810 break;
1811
1812 default:
1813 break; // direction doesn't make sense
1814 }
1815
1816 ::TransitionWindowWithOptions
1817 (
1818 (WindowRef)m_macWindow,
1819 transition,
1820 show ? kWindowShowTransitionAction : kWindowHideTransitionAction,
1821 transition == kWindowGenieTransitionEffect ? &hiBounds : NULL,
1822 false,
1823 &options
1824 );
1825
1826 if ( show )
1827 {
1828 ::SelectWindow( (WindowRef)m_macWindow ) ;
1829 }
1830
1831 return true;
1832}
1833
1834void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
1835{
1836 SetWindowTitleWithCFString( m_macWindow , wxCFStringRef( title , encoding ) ) ;
1837}
1838
1839bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1840{
1841 return IsWindowInStandardState( m_macWindow , NULL , NULL ) ;
1842}
1843
1844bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1845{
1846 return IsWindowCollapsed((WindowRef)GetWXWindow() ) ;
1847}
1848
1849void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize )
1850{
1851 if ( IsWindowCollapsable( m_macWindow ) )
1852 CollapseWindow( m_macWindow , iconize ) ;
1853}
1854
1855void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize)
1856{
1857 Point idealSize = { 0 , 0 } ;
1858 if ( maximize )
1859 {
1860#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1861 HIRect bounds ;
1862 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
1863 &bounds);
1864 idealSize.h = bounds.size.width;
1865 idealSize.v = bounds.size.height;
1866#else
1867 Rect rect ;
1868 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ;
1869 idealSize.h = rect.right - rect.left ;
1870 idealSize.v = rect.bottom - rect.top ;
1871#endif
1872 }
1873 ZoomWindowIdeal( (WindowRef)GetWXWindow() , maximize ? inZoomOut : inZoomIn , &idealSize ) ;
1874}
1875
1876bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1877{
1878 return m_macFullScreenData != NULL ;
1879}
1880
1881bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show, long style)
1882{
1883 if ( show )
1884 {
1885 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
1886 delete data ;
1887 data = new FullScreenData() ;
1888
1889 m_macFullScreenData = data ;
1890 data->m_position = m_wxPeer->GetPosition() ;
1891 data->m_size = m_wxPeer->GetSize() ;
1892#if wxOSX_USE_CARBON
1893 WindowAttributes attr = 0;
1894 GetWindowAttributes((WindowRef) GetWXWindow(), &attr);
1895 data->m_wasResizable = attr & kWindowResizableAttribute;
1896 if ( style & wxFULLSCREEN_NOMENUBAR )
1897 HideMenuBar() ;
1898#endif
1899
1900 wxRect client = wxGetClientDisplayRect() ;
1901
1902 int left , top , right , bottom ;
1903 int x, y, w, h ;
1904
1905 x = client.x ;
1906 y = client.y ;
1907 w = client.width ;
1908 h = client.height ;
1909
1910 GetContentArea( left , top , right , bottom ) ;
1911
1912 if ( style & wxFULLSCREEN_NOCAPTION )
1913 {
1914 y -= top ;
1915 h += top ;
1916 }
1917
1918 if ( style & wxFULLSCREEN_NOBORDER )
1919 {
1920 x -= left ;
1921 w += left + right ;
1922 h += bottom ;
1923 }
1924
1925 if ( style & wxFULLSCREEN_NOTOOLBAR )
1926 {
1927 // TODO
1928 }
1929
1930 if ( style & wxFULLSCREEN_NOSTATUSBAR )
1931 {
1932 // TODO
1933 }
1934
1935 m_wxPeer->SetSize( x , y , w, h ) ;
1936 if ( data->m_wasResizable )
1937 {
1938#if wxOSX_USE_CARBON
1939 ChangeWindowAttributes( (WindowRef) GetWXWindow() , kWindowNoAttributes , kWindowResizableAttribute ) ;
1940#endif
1941 }
1942 }
1943 else if ( m_macFullScreenData != NULL )
1944 {
1945 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
1946#if wxOSX_USE_CARBON
1947 ShowMenuBar() ;
1948 if ( data->m_wasResizable )
1949 ChangeWindowAttributes( (WindowRef) GetWXWindow() , kWindowResizableAttribute , kWindowNoAttributes ) ;
1950#endif
1951 m_wxPeer->SetPosition( data->m_position ) ;
1952 m_wxPeer->SetSize( data->m_size ) ;
1953
1954 delete data ;
1955 m_macFullScreenData = NULL ;
1956 }
1957
1958 return true;
1959}
1960
1961// Attracts the users attention to this window if the application is
1962// inactive (should be called when a background event occurs)
1963
1964static pascal void wxMacNMResponse( NMRecPtr ptr )
1965{
1966 NMRemove( ptr ) ;
1967 DisposePtr( (Ptr)ptr ) ;
1968}
1969
1970void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags))
1971{
1972 NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
1973
1974 memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
1975 notificationRequest->qType = nmType ;
1976 notificationRequest->nmMark = 1 ;
1977 notificationRequest->nmIcon = 0 ;
1978 notificationRequest->nmSound = 0 ;
1979 notificationRequest->nmStr = NULL ;
1980 notificationRequest->nmResp = wxMacNMResponse ;
1981
1982 verify_noerr( NMInstall( notificationRequest ) ) ;
1983}
1984
1985void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x, int *y )
1986{
1987 HIPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
1988 HIViewRef contentView ;
1989 // TODO check toolbar offset
1990 HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ;
1991 HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView );
1992 if ( x )
1993 *x = p.x;
1994 if ( y )
1995 *y = p.y;
1996}
1997
1998void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y )
1999{
2000 HIPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
2001 HIViewRef contentView ;
2002 // TODO check toolbar offset
2003 HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ;
2004 HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL );
2005 if ( x )
2006 *x = p.x;
2007 if ( y )
2008 *y = p.y;
2009}
2010#endif // wxOSX_USE_CARBON