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