+ // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
+ wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
+
+ switch ( GetEventKind( event ) )
+ {
+ case kEventWindowActivated :
+ {
+ toplevelWindow->MacActivate( cEvent.GetTicks() , true) ;
+ wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId());
+ wxevent.SetTimestamp( cEvent.GetTicks() ) ;
+ wxevent.SetEventObject(toplevelWindow);
+ toplevelWindow->HandleWindowEvent(wxevent);
+ // we still sending an eventNotHandledErr in order to allow for default processing
+ }
+ break ;
+
+ case kEventWindowDeactivated :
+ {
+ toplevelWindow->MacActivate(cEvent.GetTicks() , false) ;
+ wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId());
+ wxevent.SetTimestamp( cEvent.GetTicks() ) ;
+ wxevent.SetEventObject(toplevelWindow);
+ toplevelWindow->HandleWindowEvent(wxevent);
+ // we still sending an eventNotHandledErr in order to allow for default processing
+ }
+ break ;
+
+ case kEventWindowShown :
+ toplevelWindow->Refresh() ;
+ result = noErr ;
+ break ;
+
+ case kEventWindowClose :
+ toplevelWindow->Close() ;
+ result = noErr ;
+ break ;
+
+ case kEventWindowBoundsChanged :
+ {
+ UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes, typeUInt32) ;
+ Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
+ wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ;
+ if ( attributes & kWindowBoundsChangeSizeChanged )
+ {
+#ifndef __WXUNIVERSAL__
+ // according to the other ports we handle this within the OS level
+ // resize event, not within a wxSizeEvent
+ wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ;
+ if ( frame )
+ {
+ frame->PositionBars();
+ }
+#endif
+ wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ;
+ event.SetEventObject( toplevelWindow ) ;
+
+ toplevelWindow->HandleWindowEvent(event) ;
+ toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
+ }
+
+ if ( attributes & kWindowBoundsChangeOriginChanged )
+ {
+ wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ;
+ event.SetEventObject( toplevelWindow ) ;
+ toplevelWindow->HandleWindowEvent(event) ;
+ }
+
+ result = noErr ;
+ }
+ break ;
+
+ case kEventWindowBoundsChanging :
+ {
+ UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
+ Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
+
+ if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) )
+ {
+ // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
+ int left , top , right , bottom ;
+ toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ;
+
+ wxRect r(
+ newRect.left - left,
+ newRect.top - top,
+ newRect.right - newRect.left + left + right,
+ newRect.bottom - newRect.top + top + bottom ) ;
+
+ // this is a EVT_SIZING not a EVT_SIZE type !
+ wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ;
+ wxevent.SetEventObject( toplevelWindow ) ;
+ wxRect adjustR = r ;
+ if ( toplevelWindow->HandleWindowEvent(wxevent) )
+ adjustR = wxevent.GetRect() ;
+
+ if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() )
+ adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ;
+ if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() )
+ adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ;
+ if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() )
+ adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ;
+ if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() )
+ adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ;
+ const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ;
+ if ( !EqualRect( &newRect , &adjustedRect ) )
+ cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ;
+ toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
+ }
+
+ result = noErr ;
+ }
+ break ;
+
+ case kEventWindowGetRegion :
+ {
+ if ( toplevelWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
+ {
+ WindowRegionCode windowRegionCode ;
+
+ // Fetch the region code that is being queried
+ GetEventParameter( event,
+ kEventParamWindowRegionCode,
+ typeWindowRegionCode, NULL,
+ sizeof windowRegionCode, NULL,
+ &windowRegionCode ) ;
+
+ // If it is the opaque region code then set the
+ // region to empty and return noErr to stop event
+ // propagation
+ if ( windowRegionCode == kWindowOpaqueRgn ) {
+ RgnHandle region;
+ GetEventParameter( event,
+ kEventParamRgnHandle,
+ typeQDRgnHandle, NULL,
+ sizeof region, NULL,
+ ®ion) ;
+ SetEmptyRgn(region) ;
+ result = noErr ;
+ }
+ }
+ }
+ break ;
+
+ default :
+ break ;
+ }
+
+ return result ;
+}
+
+// mix this in from window.cpp
+pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
+
+pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ switch ( GetEventClass( event ) )
+ {
+ case kEventClassTextInput :
+ result = wxMacUnicodeTextEventHandler( handler, event , data ) ;
+ break ;
+
+ case kEventClassKeyboard :
+ result = KeyboardEventHandler( handler, event , data ) ;
+ break ;
+
+ case kEventClassWindow :
+ result = wxMacTopLevelWindowEventHandler( handler, event , data ) ;
+ break ;
+
+ case kEventClassMouse :
+ result = wxMacTopLevelMouseEventHandler( handler, event , data ) ;
+ break ;
+
+ default :
+ break ;
+ }
+
+ return result ;
+}
+
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler )
+
+// ---------------------------------------------------------------------------
+// wxWindowMac utility functions
+// ---------------------------------------------------------------------------
+
+// Find an item given the Macintosh Window Reference
+
+WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap);
+
+static MacWindowMap wxWinMacWindowList;
+
+wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
+{
+ MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
+
+ return (node == wxWinMacWindowList.end()) ? NULL : node->second;
+}
+
+void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ;
+void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
+{
+ // adding NULL WindowRef is (first) surely a result of an error and
+ // nothing else :-)
+ wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
+
+ wxWinMacWindowList[inWindowRef] = win;
+}
+
+void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ;
+void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
+{
+ MacWindowMap::iterator it;
+ for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it )
+ {
+ if ( it->second == win )
+ {
+ wxWinMacWindowList.erase(it);
+ break;
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxTopLevelWindowMac creation
+// ----------------------------------------------------------------------------
+
+wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
+
+typedef struct
+{
+ wxPoint m_position ;
+ wxSize m_size ;
+ bool m_wasResizable ;
+} FullScreenData ;
+
+void wxTopLevelWindowMac::Init()
+{
+ m_iconized =
+ m_maximizeOnShow = false;
+ m_macWindow = NULL ;
+
+ m_macEventHandler = NULL ;
+ m_macFullScreenData = NULL ;
+}
+
+wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef )
+{
+ m_macWindow = windowRef ;
+}
+
+wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter()
+{
+ DisposeWindow( (WindowRef) m_macWindow ) ;
+}
+
+bool wxTopLevelWindowMac::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& title,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString& name)
+{
+ // init our fields
+ Init();
+
+ m_windowStyle = style;
+
+ SetName( name );
+
+ m_windowId = id == -1 ? NewControlId() : id;
+ wxWindow::SetLabel( title ) ;
+
+ DoMacCreateRealWindow( parent, title, pos , size , style , name ) ;
+
+ SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ));
+
+ if (GetExtraStyle() & wxFRAME_EX_METAL)
+ MacSetMetalAppearance(true);
+
+ wxTopLevelWindows.Append(this);
+
+ if ( parent )
+ parent->AddChild(this);
+
+ return true;
+}
+
+wxTopLevelWindowMac::~wxTopLevelWindowMac()
+{
+ if ( m_macWindow )