+// ---------------------------------------------------------------------------
+// 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
+// ---------------------------------------------------------------------------
+
+#if TARGET_CARBON
+
+static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
+{
+ GetWindowPortBounds(window, inRect);
+ Point pt = {inRect->left, inRect->top};
+ SetPort((GrafPtr) GetWindowPort(window));
+ LocalToGlobal(&pt);
+ inRect->top = pt.v;
+ inRect->left = pt.h;
+ inRect->bottom += pt.v;
+ inRect->right += pt.h;
+}
+
+
+static SInt32 wxShapedMacWindowGetFeatures(WindowRef 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|
+ kWindowSupportsSetGrowImageRegion|
+ 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)
+ {
+ wxRect r = win->GetRect();
+ SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
+ }
+}
+
+// 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;
+
+ switch(rgnRec->regionCode)
+ {
+ case kWindowStructureRgn:
+ wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
+ break;
+ case kWindowContentRgn:
+ wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
+ break;
+ default:
+ SetEmptyRgn(rgnRec->winRgn);
+ } //switch
+
+ return noErr;
+}
+
+
+static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param)
+{
+ /*------------------------------------------------------
+ Determine the region of the window which was hit
+ --------------------------------------------------------*/
+ Point hitPoint;
+ static RgnHandle tempRgn=nil;
+
+ if(!tempRgn)
+ tempRgn=NewRgn();
+
+ SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked
+
+ //Mac OS 8.5 or later
+ wxShapedMacWindowStructureRegion(window, tempRgn);
+ if (PtInRgn(hitPoint, tempRgn)) //in window content region?
+ return wInContent;
+
+ return wNoHit;//no significant area was hit.
+}
+
+
+static pascal long wxShapedMacWindowDef(short 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);
+ }
+
+ return 0;
+}
+
+#endif
+// ---------------------------------------------------------------------------
+