Shaped window support for wxMac, plus a wxSTAY_ON_TOP fix from Egon
<e_lub@yahoo.com> wxMac requires knowledge before Create that SetShape will be called so I also added the wxFRAME_SHAPED style flag. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20383 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -56,6 +56,8 @@ you should use
|
|||||||
{\tt wxDEFAULT\_FRAME\_STYLE \& (wxMINIMIZE\_BOX | wxMAXIMIZE\_BOX)} for the
|
{\tt wxDEFAULT\_FRAME\_STYLE \& (wxMINIMIZE\_BOX | wxMAXIMIZE\_BOX)} for the
|
||||||
frames having this style (the dialogs don't have minimize nor maximize box by
|
frames having this style (the dialogs don't have minimize nor maximize box by
|
||||||
default)}
|
default)}
|
||||||
|
\twocolitem{\windowstyle{wxFRAME\_SHAPED}}{Windows with this style are
|
||||||
|
allowed to have their shape changed with the \helpref{SetShape}{wxframesetshape} method.}
|
||||||
\end{twocollist}
|
\end{twocollist}
|
||||||
|
|
||||||
The default frame style is for normal, resizeable frames. To create a frame
|
The default frame style is for normal, resizeable frames. To create a frame
|
||||||
|
@@ -1023,6 +1023,7 @@ enum wxBorder
|
|||||||
#define wxFRAME_NO_TASKBAR 0x0002 // No taskbar button (MSW only)
|
#define wxFRAME_NO_TASKBAR 0x0002 // No taskbar button (MSW only)
|
||||||
#define wxFRAME_TOOL_WINDOW 0x0004 // No taskbar button, no system menu
|
#define wxFRAME_TOOL_WINDOW 0x0004 // No taskbar button, no system menu
|
||||||
#define wxFRAME_FLOAT_ON_PARENT 0x0008 // Always above its parent
|
#define wxFRAME_FLOAT_ON_PARENT 0x0008 // Always above its parent
|
||||||
|
#define wxFRAME_SHAPED 0x0010 // Create a window that is able to be shaped
|
||||||
|
|
||||||
// deprecated versions defined for compatibility reasons
|
// deprecated versions defined for compatibility reasons
|
||||||
#define wxRESIZE_BOX wxMAXIMIZE_BOX
|
#define wxRESIZE_BOX wxMAXIMIZE_BOX
|
||||||
|
@@ -39,6 +39,7 @@
|
|||||||
#include "wx/menu.h"
|
#include "wx/menu.h"
|
||||||
#include "wx/layout.h"
|
#include "wx/layout.h"
|
||||||
#include "wx/msgdlg.h"
|
#include "wx/msgdlg.h"
|
||||||
|
#include "wx/image.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dcclient.h"
|
#include "wx/dcclient.h"
|
||||||
@@ -134,6 +135,7 @@ bool MyApp::OnInit()
|
|||||||
// Create the main application window
|
// Create the main application window
|
||||||
ShapedFrame *frame = new ShapedFrame();
|
ShapedFrame *frame = new ShapedFrame();
|
||||||
frame->Show(TRUE);
|
frame->Show(TRUE);
|
||||||
|
SetTopWindow(frame);
|
||||||
|
|
||||||
// success: wxApp::OnRun() will be called which will enter the main message
|
// success: wxApp::OnRun() will be called which will enter the main message
|
||||||
// loop and the application will run. If we returned FALSE here, the
|
// loop and the application will run. If we returned FALSE here, the
|
||||||
@@ -148,19 +150,28 @@ bool MyApp::OnInit()
|
|||||||
// frame constructor
|
// frame constructor
|
||||||
ShapedFrame::ShapedFrame()
|
ShapedFrame::ShapedFrame()
|
||||||
: wxFrame((wxFrame *)NULL, -1, wxEmptyString,
|
: wxFrame((wxFrame *)NULL, -1, wxEmptyString,
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxSize(100, 100), //wxDefaultSize,
|
||||||
wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR)
|
0
|
||||||
|
| wxFRAME_SHAPED
|
||||||
|
| wxSIMPLE_BORDER
|
||||||
|
| wxFRAME_NO_TASKBAR
|
||||||
|
| wxSTAY_ON_TOP
|
||||||
|
)
|
||||||
{
|
{
|
||||||
m_hasShape = FALSE;
|
m_hasShape = FALSE;
|
||||||
m_bmp = wxBitmap("star.png", wxBITMAP_TYPE_PNG);
|
m_bmp = wxBitmap("star.png", wxBITMAP_TYPE_PNG);
|
||||||
SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));
|
SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));
|
||||||
#if wxUSE_TOOLTIP
|
#ifndef __WXMAC__
|
||||||
|
// On wxMac the tooltip gets clipped by the window shape, YUCK!!
|
||||||
|
#if wxUSE_TOOLTOP
|
||||||
SetToolTip(wxT("Right-click to exit"));
|
SetToolTip(wxT("Right-click to exit"));
|
||||||
#endif
|
#endif
|
||||||
#ifdef __WXMSW__
|
#endif
|
||||||
|
#ifndef __WXGTK__
|
||||||
// On wxGTK we can't do this yet because the window hasn't been created
|
// On wxGTK we can't do this yet because the window hasn't been created
|
||||||
// yet so we wait until the EVT_WINDOW_CREATE event happens. On wxMSW it
|
// yet so we wait until the EVT_WINDOW_CREATE event happens. On wxMSW and
|
||||||
// has been created so we set the shape now.
|
// wxMac the window has been created at this point so we go ahead and set
|
||||||
|
// the shape now.
|
||||||
SetWindowShape();
|
SetWindowShape();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -186,6 +197,7 @@ void ShapedFrame::OnDoubleClick(wxMouseEvent& evt)
|
|||||||
void ShapedFrame::OnLeftDown(wxMouseEvent& evt)
|
void ShapedFrame::OnLeftDown(wxMouseEvent& evt)
|
||||||
{
|
{
|
||||||
CaptureMouse();
|
CaptureMouse();
|
||||||
|
//printf("Mouse captured\n");
|
||||||
wxPoint pos = ClientToScreen(evt.GetPosition());
|
wxPoint pos = ClientToScreen(evt.GetPosition());
|
||||||
wxPoint origin = GetPosition();
|
wxPoint origin = GetPosition();
|
||||||
int dx = pos.x - origin.x;
|
int dx = pos.x - origin.x;
|
||||||
@@ -196,14 +208,19 @@ void ShapedFrame::OnLeftDown(wxMouseEvent& evt)
|
|||||||
void ShapedFrame::OnLeftUp(wxMouseEvent& evt)
|
void ShapedFrame::OnLeftUp(wxMouseEvent& evt)
|
||||||
{
|
{
|
||||||
if (HasCapture())
|
if (HasCapture())
|
||||||
|
{
|
||||||
ReleaseMouse();
|
ReleaseMouse();
|
||||||
|
//printf("Mouse released\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapedFrame::OnMouseMove(wxMouseEvent& evt)
|
void ShapedFrame::OnMouseMove(wxMouseEvent& evt)
|
||||||
{
|
{
|
||||||
|
wxPoint pt = evt.GetPosition();
|
||||||
|
//printf("x:%d y:%d\n", pt.x, pt.y);
|
||||||
if (evt.Dragging() && evt.LeftIsDown())
|
if (evt.Dragging() && evt.LeftIsDown())
|
||||||
{
|
{
|
||||||
wxPoint pos = ClientToScreen(evt.GetPosition());
|
wxPoint pos = ClientToScreen(pt);
|
||||||
Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y));
|
Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1002,6 +1002,9 @@ static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region)
|
|||||||
|
|
||||||
bool wxTopLevelWindowGTK::SetShape(const wxRegion& region)
|
bool wxTopLevelWindowGTK::SetShape(const wxRegion& region)
|
||||||
{
|
{
|
||||||
|
wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
|
||||||
|
_T("Shaped windows must be created with the wxFRAME_SHAPED style."));
|
||||||
|
|
||||||
GdkWindow *window = NULL;
|
GdkWindow *window = NULL;
|
||||||
if (m_wxwindow)
|
if (m_wxwindow)
|
||||||
{
|
{
|
||||||
|
@@ -1002,6 +1002,9 @@ static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region)
|
|||||||
|
|
||||||
bool wxTopLevelWindowGTK::SetShape(const wxRegion& region)
|
bool wxTopLevelWindowGTK::SetShape(const wxRegion& region)
|
||||||
{
|
{
|
||||||
|
wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
|
||||||
|
_T("Shaped windows must be created with the wxFRAME_SHAPED style."));
|
||||||
|
|
||||||
GdkWindow *window = NULL;
|
GdkWindow *window = NULL;
|
||||||
if (m_wxwindow)
|
if (m_wxwindow)
|
||||||
{
|
{
|
||||||
|
@@ -1399,6 +1399,7 @@ void wxApp::MacSuspend( bool convertClipboard )
|
|||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
|
wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
|
||||||
|
if (!win->HasFlag(wxSTAY_ON_TOP))
|
||||||
win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
|
win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
|
||||||
|
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
|
@@ -1399,6 +1399,7 @@ void wxApp::MacSuspend( bool convertClipboard )
|
|||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
|
wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
|
||||||
|
if (!win->HasFlag(wxSTAY_ON_TOP))
|
||||||
win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
|
win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
|
||||||
|
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
|
@@ -59,6 +59,9 @@ wxWindowList wxModelessWindows;
|
|||||||
static Point gs_lastWhere;
|
static Point gs_lastWhere;
|
||||||
static long gs_lastWhen = 0;
|
static long gs_lastWhen = 0;
|
||||||
|
|
||||||
|
|
||||||
|
static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param);
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxTopLevelWindowMac implementation
|
// wxTopLevelWindowMac implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -590,7 +593,24 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
|
|||||||
attr |= kWindowCloseBoxAttribute ;
|
attr |= kWindowCloseBoxAttribute ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HasFlag(wxSTAY_ON_TOP))
|
||||||
|
wclass = kUtilityWindowClass;
|
||||||
|
|
||||||
|
if ( HasFlag(wxFRAME_SHAPED) )
|
||||||
|
{
|
||||||
|
WindowDefSpec customWindowDefSpec;
|
||||||
|
customWindowDefSpec.defType = kWindowDefProcPtr;
|
||||||
|
customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef);
|
||||||
|
|
||||||
|
::CreateCustomWindow( &customWindowDefSpec, wclass,
|
||||||
|
attr, &theBoundsRect,
|
||||||
|
(WindowRef*) &m_macWindow);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
|
::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
|
||||||
|
}
|
||||||
|
|
||||||
wxAssociateWinWithMacWindow( m_macWindow , this ) ;
|
wxAssociateWinWithMacWindow( m_macWindow , this ) ;
|
||||||
UMASetWTitle( (WindowRef)m_macWindow , title ) ;
|
UMASetWTitle( (WindowRef)m_macWindow , title ) ;
|
||||||
::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
|
::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
|
||||||
@@ -600,6 +620,14 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
|
|||||||
GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
|
GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
|
||||||
#endif
|
#endif
|
||||||
m_macFocus = NULL ;
|
m_macFocus = NULL ;
|
||||||
|
|
||||||
|
|
||||||
|
if ( HasFlag(wxFRAME_SHAPED) )
|
||||||
|
{
|
||||||
|
// default shape matches the window size
|
||||||
|
wxRegion rgn(0, 0, m_width, m_height);
|
||||||
|
SetShape(rgn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
|
void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
|
||||||
@@ -1035,7 +1063,169 @@ void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackgro
|
|||||||
SetPort( formerPort ) ;
|
SetPort( formerPort ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
|
bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
|
||||||
{
|
{
|
||||||
return FALSE;
|
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);
|
||||||
|
return SetShape(rgn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a copy of the region
|
||||||
|
RgnHandle shapeRegion = NewRgn();
|
||||||
|
CopyRgn( (RgnHandle)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(), (SInt32)shapeRegion);
|
||||||
|
|
||||||
|
// Tell 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->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
@@ -59,6 +59,9 @@ wxWindowList wxModelessWindows;
|
|||||||
static Point gs_lastWhere;
|
static Point gs_lastWhere;
|
||||||
static long gs_lastWhen = 0;
|
static long gs_lastWhen = 0;
|
||||||
|
|
||||||
|
|
||||||
|
static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param);
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxTopLevelWindowMac implementation
|
// wxTopLevelWindowMac implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -590,7 +593,24 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
|
|||||||
attr |= kWindowCloseBoxAttribute ;
|
attr |= kWindowCloseBoxAttribute ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HasFlag(wxSTAY_ON_TOP))
|
||||||
|
wclass = kUtilityWindowClass;
|
||||||
|
|
||||||
|
if ( HasFlag(wxFRAME_SHAPED) )
|
||||||
|
{
|
||||||
|
WindowDefSpec customWindowDefSpec;
|
||||||
|
customWindowDefSpec.defType = kWindowDefProcPtr;
|
||||||
|
customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef);
|
||||||
|
|
||||||
|
::CreateCustomWindow( &customWindowDefSpec, wclass,
|
||||||
|
attr, &theBoundsRect,
|
||||||
|
(WindowRef*) &m_macWindow);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
|
::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
|
||||||
|
}
|
||||||
|
|
||||||
wxAssociateWinWithMacWindow( m_macWindow , this ) ;
|
wxAssociateWinWithMacWindow( m_macWindow , this ) ;
|
||||||
UMASetWTitle( (WindowRef)m_macWindow , title ) ;
|
UMASetWTitle( (WindowRef)m_macWindow , title ) ;
|
||||||
::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
|
::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
|
||||||
@@ -600,6 +620,14 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
|
|||||||
GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
|
GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
|
||||||
#endif
|
#endif
|
||||||
m_macFocus = NULL ;
|
m_macFocus = NULL ;
|
||||||
|
|
||||||
|
|
||||||
|
if ( HasFlag(wxFRAME_SHAPED) )
|
||||||
|
{
|
||||||
|
// default shape matches the window size
|
||||||
|
wxRegion rgn(0, 0, m_width, m_height);
|
||||||
|
SetShape(rgn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
|
void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
|
||||||
@@ -1035,7 +1063,169 @@ void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackgro
|
|||||||
SetPort( formerPort ) ;
|
SetPort( formerPort ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
|
bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
|
||||||
{
|
{
|
||||||
return FALSE;
|
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);
|
||||||
|
return SetShape(rgn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a copy of the region
|
||||||
|
RgnHandle shapeRegion = NewRgn();
|
||||||
|
CopyRgn( (RgnHandle)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(), (SInt32)shapeRegion);
|
||||||
|
|
||||||
|
// Tell 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->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
@@ -760,6 +760,9 @@ bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)
|
|||||||
|
|
||||||
bool wxTopLevelWindowMSW::SetShape(const wxRegion& region)
|
bool wxTopLevelWindowMSW::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
|
// The empty region signifies that the shape should be removed from the
|
||||||
// window.
|
// window.
|
||||||
if ( region.IsEmpty() )
|
if ( region.IsEmpty() )
|
||||||
|
Reference in New Issue
Block a user