Ejemplo n.º 1
0
bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
{
    wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
                 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));

#if TARGET_CARBON
    // 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;
#else
    return FALSE;
#endif
}
Ejemplo n.º 2
0
OSStatus MakeWindowTransparent(WindowRef aWindowRef)
{
    OSStatus status = paramErr;
    require(aWindowRef != NULL, paramErr);

    // is the window compositing or not?
    WindowAttributes attributes;
    status = GetWindowAttributes(aWindowRef, &attributes);
    require_noerr(status, GetWindowAttributes);

    /*	if (attributes & kWindowCompositingAttribute)
    	{
    		// it is compositing so we intercept the kEventWindowGetRegion event to be able to specify an empty opaque region
    		EventTypeSpec wCompositingEvents = { kEventClassWindow, kEventWindowGetRegion };
    		status = InstallWindowEventHandler(aWindowRef, TransparentWindowHandler, 1, &wCompositingEvents, aWindowRef, NULL);
    		require_noerr(status, InstallWindowEventHandler);

    		HIViewRef contentView;
    		status = HIViewFindByID(HIViewGetRoot(aWindowRef), kHIViewWindowContentID, &contentView);
    		require_noerr(status, HIViewFindByID);

    		// and we intercept the kEventControlDraw event of our content view so that we can make it transparent
    		EventTypeSpec cCompositingEvents = { kEventClassControl, kEventControlDraw };
    		status = InstallControlEventHandler(contentView, TransparentWindowHandler, 1, &cCompositingEvents, contentView, NULL);
    		require_noerr(status, InstallControlEventHandler);
    	}
    	else*/
    {
        // it is non-compositing so we intercept the kEventWindowGetRegion event to be able to specify an empty opaque region
        // and we intercept the kEventWindowDrawContent event of our window so that we can make it transparent
        EventTypeSpec wNonCompositingEvents[] =
        {
            { kEventClassWindow, kEventWindowGetRegion },
            { kEventClassWindow, kEventWindowDrawContent }
        };
        status = InstallWindowEventHandler(aWindowRef, TransparentWindowHandler, GetEventTypeCount(wNonCompositingEvents), wNonCompositingEvents, aWindowRef, NULL);
        require_noerr(status, InstallWindowEventHandler);
    }

    // telling the HIToolbox that our window is not opaque so that we will be asked for the opaque region
    UInt32 features;
    status = GetWindowFeatures(aWindowRef, &features);
    require_noerr(status, GetWindowFeatures);
    if ( ( features & kWindowIsOpaque ) != 0 )
    {
        status = HIWindowChangeFeatures(aWindowRef, 0, kWindowIsOpaque);
        require_noerr(status, HIWindowChangeFeatures);
    }

    // force opaque shape to be recalculated
    status = ReshapeCustomWindow(aWindowRef);
    require_noerr(status, ReshapeCustomWindow);

    // ensure that HIToolbox doesn't use standard shadow style, which defeats custom opaque shape
    status = SetWindowAlpha(aWindowRef, 0.999);
    require_noerr(status, SetWindowAlpha);

SetWindowAlpha:
ReshapeCustomWindow:
HIWindowChangeFeatures:
GetWindowFeatures:
InstallControlEventHandler:
HIViewFindByID:
InstallWindowEventHandler:
GetWindowAttributes:
paramErr:

    return status;
}
Ejemplo n.º 3
0
bool wxSkinWindow::SetShape(const wxRegion& region)
{
	
#if defined(__WXMSW__) && !defined(__WXWINCE__)
	// The empty region signifies that the shape should be removed from the
    // window.
    if ( region.IsEmpty() )
    {
        if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
        {
            wxLogLastError(_T("SetWindowRgn"));
            return false;
        }
        return true;
    }

    DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
    RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
    ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
    HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
    delete[] (char*) rgnData;
   
    RECT rect;
    DWORD dwStyle =   ::GetWindowLong(GetHwnd(), GWL_STYLE);
    DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
    ::GetClientRect(GetHwnd(), &rect);
    ::AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
    ::OffsetRgn(hrgn, -rect.left, -rect.top);

    if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
    {
        wxLogLastError(_T("SetWindowRgn"));
        return false;
    }
    return true;
#elif defined(__WXMAC__)
	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)GetHandle() );
    if ( oldRgn )
        DisposeRgn(oldRgn);

    // Save the region so we can use it later
    SetWRefCon((WindowRef)GetHandle(), (SInt32)shapeRegion);

    // Tell the window manager that the window has changed shape
    ReshapeCustomWindow((WindowRef)GetHandle());
    return true;
#elif defined(__WXGTK__)
	if(region.IsEmpty())
	{
		if(m_wxwindow && !GTK_WIDGET_NO_WINDOW(m_wxwindow))
			gtk_widget_shape_combine_mask(m_wxwindow,NULL,0,0);
		if(m_widget && !GTK_WIDGET_NO_WINDOW(m_widget))
			gtk_widget_shape_combine_mask(m_widget,NULL,0,0);
	}
	else
	{	wxBitmap bmp = region.ConvertToBitmap();
		bmp.SetMask(new wxMask(bmp, *wxBLACK));
		GdkBitmap* mask = bmp.GetMask()->GetBitmap();

		if(m_wxwindow && !GTK_WIDGET_NO_WINDOW(m_wxwindow))
			gtk_widget_shape_combine_mask(m_wxwindow,mask,0,0);
		if(m_widget && !GTK_WIDGET_NO_WINDOW(m_widget))
			gtk_widget_shape_combine_mask(m_widget,mask,0,0);
	}
	return true;
#else
	return false;
#endif
}