cocoa implementation for overlay
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63937 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
6e3f8e61a9
commit
13f0c85aa4
56
include/wx/osx/cocoa/private/overlay.h
Normal file
56
include/wx/osx/cocoa/private/overlay.h
Normal file
@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/osx/cocoa/private/overlay.h
|
||||
// Purpose: wxOverlayImpl declaration
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 2006-10-20
|
||||
// RCS-ID: $Id: overlay.h 61724 2009-08-21 10:41:26Z VZ $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_OSX_COCOA_PRIVATE_OVERLAY_H_
|
||||
#define _WX_OSX_COCOA_PRIVATE_OVERLAY_H_
|
||||
|
||||
#include "wx/osx/private.h"
|
||||
#include "wx/toplevel.h"
|
||||
#include "wx/graphics.h"
|
||||
|
||||
class wxOverlayImpl
|
||||
{
|
||||
public:
|
||||
wxOverlayImpl() ;
|
||||
~wxOverlayImpl() ;
|
||||
|
||||
|
||||
// clears the overlay without restoring the former state
|
||||
// to be done eg when the window content has been changed and repainted
|
||||
void Reset();
|
||||
|
||||
// returns true if it has been setup
|
||||
bool IsOk();
|
||||
|
||||
void Init( wxDC* dc, int x , int y , int width , int height );
|
||||
|
||||
void BeginDrawing( wxDC* dc);
|
||||
|
||||
void EndDrawing( wxDC* dc);
|
||||
|
||||
void Clear( wxDC* dc);
|
||||
|
||||
private:
|
||||
void CreateOverlayWindow();
|
||||
|
||||
WXWindow m_overlayWindow;
|
||||
WXWindow m_overlayParentWindow;
|
||||
CGContextRef m_overlayContext ;
|
||||
// we store the window in case we would have to issue a Refresh()
|
||||
wxWindow* m_window ;
|
||||
|
||||
int m_x ;
|
||||
int m_y ;
|
||||
int m_width ;
|
||||
int m_height ;
|
||||
} ;
|
||||
|
||||
#endif // _WX_MAC_CARBON_PRIVATE_OVERLAY_H_
|
193
src/osx/cocoa/overlay.mm
Normal file
193
src/osx/cocoa/overlay.mm
Normal file
@ -0,0 +1,193 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/osx/cocoa/overlay.mm
|
||||
// Purpose: common wxOverlay code
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 2006-10-20
|
||||
// RCS-ID: $Id: overlay.cpp 55419 2008-09-02 16:53:23Z SC $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/overlay.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dcclient.h"
|
||||
#endif
|
||||
|
||||
#include "wx/dcgraph.h"
|
||||
|
||||
#include "wx/private/overlay.h"
|
||||
|
||||
#ifdef wxHAS_NATIVE_OVERLAY
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxOverlayImpl::wxOverlayImpl()
|
||||
{
|
||||
m_window = NULL ;
|
||||
m_overlayContext = NULL ;
|
||||
m_overlayWindow = NULL ;
|
||||
}
|
||||
|
||||
wxOverlayImpl::~wxOverlayImpl()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
bool wxOverlayImpl::IsOk()
|
||||
{
|
||||
return m_overlayWindow != NULL ;
|
||||
}
|
||||
|
||||
void wxOverlayImpl::CreateOverlayWindow()
|
||||
{
|
||||
if ( m_window )
|
||||
{
|
||||
m_overlayParentWindow = m_window->MacGetTopLevelWindowRef();
|
||||
[m_overlayParentWindow makeKeyAndOrderFront:nil];
|
||||
|
||||
NSView* view = m_window->GetHandle();
|
||||
|
||||
NSPoint viewOriginBase, viewOriginScreen;
|
||||
viewOriginBase = [view convertPoint:NSMakePoint(0, 0) toView:nil];
|
||||
viewOriginScreen = [m_overlayParentWindow convertBaseToScreen:viewOriginBase];
|
||||
|
||||
NSSize viewSize = [view frame].size;
|
||||
if ( [view isFlipped] )
|
||||
viewOriginScreen.y -= viewSize.height;
|
||||
|
||||
m_overlayWindow=[[NSWindow alloc] initWithContentRect:NSMakeRect(viewOriginScreen.x,viewOriginScreen.y,
|
||||
viewSize.width,
|
||||
viewSize.height)
|
||||
styleMask:NSBorderlessWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
|
||||
[m_overlayParentWindow addChildWindow:m_overlayWindow ordered:NSWindowAbove];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_overlayParentWindow = NULL ;
|
||||
CGRect cgbounds ;
|
||||
cgbounds = CGDisplayBounds(CGMainDisplayID());
|
||||
|
||||
m_overlayWindow=[[NSWindow alloc] initWithContentRect:NSMakeRect(cgbounds.origin.x,cgbounds.origin.y,
|
||||
cgbounds.size.width,
|
||||
cgbounds.size.height)
|
||||
styleMask:NSBorderlessWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
}
|
||||
[m_overlayWindow setOpaque:NO];
|
||||
[m_overlayWindow setHasShadow:YES];
|
||||
[m_overlayWindow setIgnoresMouseEvents:YES];
|
||||
[m_overlayWindow setAlphaValue:0.5];
|
||||
|
||||
[m_overlayWindow orderFront:nil];
|
||||
}
|
||||
|
||||
void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height )
|
||||
{
|
||||
wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
|
||||
|
||||
m_window = dc->GetWindow();
|
||||
m_x = x ;
|
||||
m_y = y ;
|
||||
if ( dc->IsKindOf( CLASSINFO( wxClientDC ) ))
|
||||
{
|
||||
wxPoint origin = m_window->GetClientAreaOrigin();
|
||||
m_x += origin.x;
|
||||
m_y += origin.y;
|
||||
}
|
||||
m_width = width ;
|
||||
m_height = height ;
|
||||
|
||||
CreateOverlayWindow();
|
||||
wxASSERT_MSG( m_overlayWindow != NULL , _("Couldn't create the overlay window") );
|
||||
m_overlayContext = (CGContextRef) [[m_overlayWindow graphicsContext] graphicsPort];
|
||||
wxASSERT_MSG( m_overlayContext != NULL , _("Couldn't init the context on the overlay window") );
|
||||
|
||||
int ySize = 0;
|
||||
if ( m_window )
|
||||
{
|
||||
NSView* view = m_window->GetHandle();
|
||||
NSSize viewSize = [view frame].size;
|
||||
ySize = viewSize.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
CGRect cgbounds ;
|
||||
cgbounds = CGDisplayBounds(CGMainDisplayID());
|
||||
ySize = cgbounds.size.height;
|
||||
|
||||
|
||||
|
||||
}
|
||||
CGContextTranslateCTM( m_overlayContext, 0, ySize );
|
||||
CGContextScaleCTM( m_overlayContext, 1, -1 );
|
||||
CGContextTranslateCTM( m_overlayContext, -m_x , -m_y );
|
||||
}
|
||||
|
||||
void wxOverlayImpl::BeginDrawing( wxDC* dc)
|
||||
{
|
||||
wxDCImpl *impl = dc->GetImpl();
|
||||
wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
|
||||
if (win_impl)
|
||||
{
|
||||
win_impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
|
||||
dc->SetClippingRegion( m_x , m_y , m_width , m_height ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void wxOverlayImpl::EndDrawing( wxDC* dc)
|
||||
{
|
||||
wxDCImpl *impl = dc->GetImpl();
|
||||
wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
|
||||
if (win_impl)
|
||||
win_impl->SetGraphicsContext(NULL);
|
||||
|
||||
CGContextFlush( m_overlayContext );
|
||||
}
|
||||
|
||||
void wxOverlayImpl::Clear(wxDC* WXUNUSED(dc))
|
||||
{
|
||||
wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
|
||||
CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
|
||||
CGContextClearRect( m_overlayContext, box );
|
||||
}
|
||||
|
||||
void wxOverlayImpl::Reset()
|
||||
{
|
||||
if ( m_overlayContext )
|
||||
{
|
||||
m_overlayContext = NULL ;
|
||||
}
|
||||
|
||||
// todo : don't dispose, only hide and reposition on next run
|
||||
if (m_overlayWindow)
|
||||
{
|
||||
[m_overlayParentWindow removeChildWindow:m_overlayWindow];
|
||||
[m_overlayWindow release];
|
||||
m_overlayWindow = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxHAS_NATIVE_OVERLAY
|
Loading…
Reference in New Issue
Block a user