+ 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 )
+ {
+#if wxUSE_TOOLTIPS
+ wxToolTip::NotifyWindowDelete(m_macWindow) ;
+#endif
+ wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
+ }
+
+ if ( m_macEventHandler )
+ {
+ ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
+ m_macEventHandler = NULL ;
+ }
+
+ wxRemoveMacWindowAssociation( this ) ;
+
+ if ( wxModelessWindows.Find(this) )
+ wxModelessWindows.DeleteObject(this);
+
+ FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
+ delete data ;
+ m_macFullScreenData = NULL ;
+
+ // avoid dangling refs
+ if ( s_macDeactivateWindow == this )
+ s_macDeactivateWindow = NULL;
+}
+
+
+// ----------------------------------------------------------------------------
+// wxTopLevelWindowMac maximize/minimize
+// ----------------------------------------------------------------------------
+
+void wxTopLevelWindowMac::Maximize(bool maximize)
+{
+ Point idealSize = { 0 , 0 } ;
+ if ( maximize )
+ {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ HIRect bounds ;
+ HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
+ &bounds);
+ idealSize.h = bounds.size.width;
+ idealSize.v = bounds.size.height;
+#else
+ Rect rect ;
+ GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ;
+ idealSize.h = rect.right - rect.left ;
+ idealSize.v = rect.bottom - rect.top ;
+#endif
+ }
+ ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ;
+}
+
+bool wxTopLevelWindowMac::IsMaximized() const
+{
+ return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ;
+}
+
+void wxTopLevelWindowMac::Iconize(bool iconize)
+{
+ if ( IsWindowCollapsable( (WindowRef)m_macWindow) )
+ CollapseWindow( (WindowRef)m_macWindow , iconize ) ;
+}
+
+bool wxTopLevelWindowMac::IsIconized() const
+{
+ return IsWindowCollapsed((WindowRef)m_macWindow ) ;
+}
+
+void wxTopLevelWindowMac::Restore()
+{
+ if ( IsMaximized() )
+ Maximize(false);
+ else if ( IsIconized() )
+ Iconize(false);
+}
+
+// ----------------------------------------------------------------------------
+// wxTopLevelWindowMac misc
+// ----------------------------------------------------------------------------
+
+wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const
+{
+ return wxPoint(0, 0) ;
+}
+
+bool wxTopLevelWindowMac::SetBackgroundColour(const wxColour& c )
+{
+ wxColour col = c;
+ if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) )
+ col = wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground));
+ else if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
+ col = wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive));
+
+ if ( !wxTopLevelWindowBase::SetBackgroundColour(col) && m_hasBgCol )
+ return false ;
+
+ if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)) )
+ {
+ SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ;
+ SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+ }
+ else if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)) )
+ {
+ SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ;
+ SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+ }
+ return true;
+}
+
+void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref)
+{
+ InstallWindowEventHandler(window, GetwxMacTopLevelEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, ref, handler );
+}
+
+void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
+{
+ if ( m_macEventHandler != NULL )
+ {
+ verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ;
+ }
+ wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this);
+}
+
+void wxTopLevelWindowMac::MacCreateRealWindow(
+ const wxString& title,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString& name )
+{
+ DoMacCreateRealWindow( NULL, title, pos, size, style, name );
+}
+
+void wxTopLevelWindowMac::DoMacCreateRealWindow(
+ wxWindow* parent,
+ const wxString& title,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString& name )
+{
+ OSStatus err = noErr ;
+ SetName(name);
+ m_windowStyle = style;
+ m_isShown = false;
+
+ // create frame.
+ int x = (int)pos.x;
+ int y = (int)pos.y;
+
+ Rect theBoundsRect;
+ wxRect display = wxGetClientDisplayRect() ;
+
+ if ( x == wxDefaultPosition.x )
+ x = display.x ;
+
+ if ( y == wxDefaultPosition.y )
+ y = display.y ;
+
+ int w = WidthDefault(size.x);
+ int h = HeightDefault(size.y);
+
+ ::SetRect(&theBoundsRect, x, y , x + w, y + h);
+
+ // translate the window attributes in the appropriate window class and attributes
+ WindowClass wclass = 0;
+ WindowAttributes attr = kWindowNoAttributes ;
+ WindowGroupRef group = NULL ;
+ bool activationScopeSet = false;
+ WindowActivationScope activationScope = kWindowActivationScopeNone;
+
+ if ( HasFlag( wxFRAME_TOOL_WINDOW) )
+ {
+ if (
+ HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
+ HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
+ HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
+ )
+ {
+ if ( HasFlag( wxSTAY_ON_TOP ) )
+ wclass = kUtilityWindowClass;
+ else
+ wclass = kFloatingWindowClass ;
+
+ if ( HasFlag(wxTINY_CAPTION_VERT) )
+ attr |= kWindowSideTitlebarAttribute ;
+ }
+ else
+ {
+ wclass = kPlainWindowClass ;
+ activationScopeSet = true;
+ activationScope = kWindowActivationScopeNone;
+ }
+ }
+ else if ( HasFlag( wxPOPUP_WINDOW ) )
+ {
+ // TEMPORARY HACK!
+ // Until we've got a real wxPopupWindow class on wxMac make it a
+ // little easier for wxFrame to be used to emulate it and workaround
+ // the lack of wxPopupWindow.
+ if ( HasFlag( wxBORDER_NONE ) )
+ wclass = kHelpWindowClass ; // has no border