+
+ return true ;
+}
+
+// TODO: switch to structure bounds -
+// we are still using coordinates of the content view
+//
+void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
+{
+ Rect content, structure ;
+
+ GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ;
+ GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ;
+
+ left = content.left - structure.left ;
+ top = content.top - structure.top ;
+ right = structure.right - content.right ;
+ bottom = structure.bottom - content.bottom ;
+}
+
+void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
+{
+ m_cachedClippedRectValid = false ;
+ Rect bounds = { y , x , y + height , x + width } ;
+ verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
+ wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
+}
+
+void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const
+{
+ Rect bounds ;
+
+ verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
+
+ if (x)
+ *x = bounds.left ;
+ if (y)
+ *y = bounds.top ;
+}
+
+void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const
+{
+ Rect bounds ;
+
+ verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
+
+ if (width)
+ *width = bounds.right - bounds.left ;
+ if (height)
+ *height = bounds.bottom - bounds.top ;
+}
+
+void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const
+{
+ Rect bounds ;
+
+ verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ;
+
+ if (width)
+ *width = bounds.right - bounds.left ;
+ if (height)
+ *height = bounds.bottom - bounds.top ;
+}
+
+void wxTopLevelWindowMac::DoCentre(int dir)
+{
+ if ( m_macWindow != 0 )
+ wxTopLevelWindowBase::DoCentre(dir);
+}
+
+void wxTopLevelWindowMac::MacSetMetalAppearance( bool set )
+{
+ if ( MacGetUnifiedAppearance() )
+ MacSetUnifiedAppearance( false ) ;
+
+ MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
+ set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
+}
+
+bool wxTopLevelWindowMac::MacGetMetalAppearance() const
+{
+ return MacGetWindowAttributes() & kWindowMetalAttribute ;
+}
+
+void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set )
+{
+ if ( MacGetMetalAppearance() )
+ MacSetMetalAppearance( false ) ;
+
+ MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes ,
+ set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ;
+
+ // For some reason, Tiger uses white as the background color for this appearance,
+ // while most apps using it use the typical striped background. Restore that behavior
+ // for wx.
+ // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
+ // though)
+ SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ;
+}
+
+bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
+{
+ return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ;
+}
+
+void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
+{
+ ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ;
+}
+
+wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const
+{
+ UInt32 attr = 0 ;
+ GetWindowAttributes( (WindowRef) m_macWindow, &attr ) ;
+
+ return attr ;
+}
+
+void wxTopLevelWindowMac::MacPerformUpdates()
+{
+ // for composited windows this also triggers a redraw of all
+ // invalid views in the window
+ HIWindowFlush((WindowRef) m_macWindow) ;
+}
+
+// Attracts the users attention to this window if the application is
+// inactive (should be called when a background event occurs)
+
+static pascal void wxMacNMResponse( NMRecPtr ptr )
+{
+ NMRemove( ptr ) ;
+ DisposePtr( (Ptr)ptr ) ;
+}
+
+void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags))
+{
+ NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
+ static wxMacNMUPP nmupp( wxMacNMResponse );
+
+ memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
+ notificationRequest->qType = nmType ;
+ notificationRequest->nmMark = 1 ;
+ notificationRequest->nmIcon = 0 ;
+ notificationRequest->nmSound = 0 ;
+ notificationRequest->nmStr = NULL ;
+ notificationRequest->nmResp = nmupp ;
+
+ verify_noerr( NMInstall( notificationRequest ) ) ;
+}
+
+// ---------------------------------------------------------------------------
+// Shape implementation
+// ---------------------------------------------------------------------------
+
+
+bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
+{
+ wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
+ _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
+
+ // The empty region signifies that the shape
+ // should be removed from the window.
+ if ( region.IsEmpty() )
+ {
+ wxSize sz = GetClientSize();
+ wxRegion rgn(0, 0, sz.x, sz.y);
+ if ( rgn.IsEmpty() )
+ return false ;
+ else
+ return SetShape(rgn);
+ }
+
+ // Make a copy of the region
+ RgnHandle shapeRegion = NewRgn();
+ HIShapeGetAsQDRgn( region.GetWXHRGN(), shapeRegion );
+
+ // Dispose of any shape region we may already have
+ RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() );
+ if ( oldRgn )
+ DisposeRgn(oldRgn);
+
+ // Save the region so we can use it later
+ SetWRefCon((WindowRef)MacGetWindowRef(), (URefCon)shapeRegion);
+
+ // inform the window manager that the window has changed shape
+ ReshapeCustomWindow((WindowRef)MacGetWindowRef());
+
+ return true;
+}
+
+// ---------------------------------------------------------------------------
+// Support functions for shaped windows, based on Apple's CustomWindow sample at
+// http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
+// ---------------------------------------------------------------------------
+
+static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
+{
+ GetWindowPortBounds(window, inRect);
+ Point pt = { inRect->top ,inRect->left };
+ wxMacLocalToGlobal( window, &pt ) ;
+ inRect->bottom += pt.v - inRect->top;
+ inRect->right += pt.h - inRect->left;
+ inRect->top = pt.v;
+ inRect->left = pt.h;
+}
+
+static SInt32 wxShapedMacWindowGetFeatures(WindowRef WXUNUSED(window), SInt32 param)
+{
+ /*------------------------------------------------------
+ Define which options your custom window supports.
+ --------------------------------------------------------*/
+ //just enable everything for our demo
+ *(OptionBits*)param =
+ //kWindowCanGrow |
+ //kWindowCanZoom |
+ kWindowCanCollapse |
+ //kWindowCanGetWindowRegion |
+ //kWindowHasTitleBar |
+ //kWindowSupportsDragHilite |
+ kWindowCanDrawInCurrentPort |
+ //kWindowCanMeasureTitle |
+ kWindowWantsDisposeAtProcessDeath |
+ kWindowSupportsGetGrowImageRegion |
+ kWindowDefSupportsColorGrafPort;
+
+ return 1;
+}
+
+// The content region is left as a rectangle matching the window size, this is
+// so the origin in the paint event, and etc. still matches what the
+// programmer expects.
+static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn)
+{
+ SetEmptyRgn(rgn);
+ wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window);
+ if (win)
+ {
+ Rect r ;
+ wxShapedMacWindowGetPos( window, &r ) ;
+ RectRgn( rgn , &r ) ;
+ }
+}
+
+// The structure region is set to the shape given to the SetShape method.
+static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
+{
+ RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window);
+
+ SetEmptyRgn(rgn);
+ if (cachedRegion)
+ {
+ Rect windowRect;
+ wxShapedMacWindowGetPos(window, &windowRect); // how big is the window
+ CopyRgn(cachedRegion, rgn); // make a copy of our cached region
+ OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
+ //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
+ }
+}
+
+static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param)
+{
+ GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param;
+
+ if (rgnRec == NULL)
+ return paramErr;
+
+ switch (rgnRec->regionCode)
+ {
+ case kWindowStructureRgn:
+ wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
+ break;
+
+ case kWindowContentRgn:
+ wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
+ break;
+
+ default:
+ SetEmptyRgn(rgnRec->winRgn);
+ break;
+ }
+
+ return noErr;
+}
+
+// Determine the region of the window which was hit
+//
+static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param)
+{
+ Point hitPoint;
+ static RgnHandle tempRgn = NULL;
+
+ if (tempRgn == NULL)
+ tempRgn = NewRgn();
+
+ // get the point clicked
+ SetPt( &hitPoint, LoWord(param), HiWord(param) );
+
+ // Mac OS 8.5 or later
+ wxShapedMacWindowStructureRegion(window, tempRgn);
+ if (PtInRgn( hitPoint, tempRgn )) //in window content region?
+ return wInContent;
+
+ // no significant area was hit
+ return wNoHit;
+}
+
+static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode), WindowRef window, SInt16 message, SInt32 param)
+{
+ switch (message)
+ {
+ case kWindowMsgHitTest:
+ return wxShapedMacWindowHitTest(window, param);
+
+ case kWindowMsgGetFeatures:
+ return wxShapedMacWindowGetFeatures(window, param);
+
+ // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
+ case kWindowMsgGetRegion:
+ return wxShapedMacWindowGetRegion(window, param);
+
+ default:
+ break;
+ }
+
+ return 0;