~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Externals/wxWidgets3/src/osx/carbon/overlay.cpp

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        src/osx/carbon/overlay.cpp
 
3
// Purpose:     common wxOverlay code
 
4
// Author:      Stefan Csomor
 
5
// Modified by:
 
6
// Created:     2006-10-20
 
7
// Copyright:   (c) wxWidgets team
 
8
// Licence:     wxWindows licence
 
9
/////////////////////////////////////////////////////////////////////////////
 
10
 
 
11
// ============================================================================
 
12
// declarations
 
13
// ============================================================================
 
14
 
 
15
// ----------------------------------------------------------------------------
 
16
// headers
 
17
// ----------------------------------------------------------------------------
 
18
 
 
19
// For compilers that support precompilation, includes "wx.h".
 
20
#include "wx/wxprec.h"
 
21
 
 
22
#ifdef __BORLANDC__
 
23
    #pragma hdrstop
 
24
#endif
 
25
 
 
26
#include "wx/overlay.h"
 
27
 
 
28
#ifndef WX_PRECOMP
 
29
    #include "wx/dcclient.h"
 
30
#endif
 
31
 
 
32
#include "wx/private/overlay.h"
 
33
 
 
34
#ifdef wxHAS_NATIVE_OVERLAY
 
35
 
 
36
// ============================================================================
 
37
// implementation
 
38
// ============================================================================
 
39
 
 
40
wxOverlayImpl::wxOverlayImpl()
 
41
{
 
42
    m_window = NULL ;
 
43
    m_overlayContext = NULL ;
 
44
    m_overlayWindow = NULL ;
 
45
}
 
46
 
 
47
wxOverlayImpl::~wxOverlayImpl()
 
48
{
 
49
    Reset();
 
50
}
 
51
 
 
52
bool wxOverlayImpl::IsOk()
 
53
{
 
54
    return m_overlayWindow != NULL ;
 
55
}
 
56
 
 
57
void wxOverlayImpl::MacGetBounds( Rect *bounds )
 
58
{
 
59
    int x, y;
 
60
    x=y=0;
 
61
    m_window->MacWindowToRootWindow( &x , &y ) ;
 
62
    wxNonOwnedWindow* tlw = m_window->MacGetTopLevelWindow();
 
63
    tlw->GetNonOwnedPeer()->WindowToScreen( &x, &y );
 
64
 
 
65
    bounds->top = y+m_y;
 
66
    bounds->left = x+m_x;
 
67
    bounds->bottom = y+m_y+m_height;
 
68
    bounds->right = x+m_x+m_width;
 
69
}
 
70
 
 
71
OSStatus wxOverlayImpl::CreateOverlayWindow()
 
72
{
 
73
    OSStatus err;
 
74
 
 
75
    WindowAttributes overlayAttributes  = kWindowIgnoreClicksAttribute;
 
76
 
 
77
    if ( m_window )
 
78
    {
 
79
        m_overlayParentWindow =(WindowRef) m_window->MacGetTopLevelWindowRef();
 
80
 
 
81
        Rect bounds ;
 
82
        MacGetBounds(&bounds);
 
83
        err  = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
 
84
        if ( err == noErr )
 
85
        {
 
86
            SetWindowGroup( m_overlayWindow, GetWindowGroup(m_overlayParentWindow));    //  Put them in the same group so that their window layers are consistent
 
87
        }
 
88
    }
 
89
    else
 
90
    {
 
91
        m_overlayParentWindow = NULL ;
 
92
        CGRect cgbounds ;
 
93
        cgbounds = CGDisplayBounds(CGMainDisplayID());
 
94
        Rect bounds;
 
95
        bounds.top = (short)cgbounds.origin.y;
 
96
        bounds.left = (short)cgbounds.origin.x;
 
97
        bounds.bottom = (short)(bounds.top + cgbounds.size.height);
 
98
        bounds.right = (short)(bounds.left  + cgbounds.size.width);
 
99
        err  = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
 
100
    }
 
101
    ShowWindow(m_overlayWindow);
 
102
    return err;
 
103
}
 
104
 
 
105
void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height )
 
106
{
 
107
    wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
 
108
 
 
109
    m_window = dc->GetWindow();
 
110
    m_x = x ;
 
111
    m_y = y ;
 
112
    if ( dc->IsKindOf( CLASSINFO( wxClientDC ) ))
 
113
    {
 
114
        wxPoint origin = m_window->GetClientAreaOrigin();
 
115
        m_x += origin.x;
 
116
        m_y += origin.y;
 
117
    }
 
118
    m_width = width ;
 
119
    m_height = height ;
 
120
 
 
121
    OSStatus err = CreateOverlayWindow();
 
122
    wxASSERT_MSG(  err == noErr , _("Couldn't create the overlay window") );
 
123
#ifndef __LP64__
 
124
    err = QDBeginCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
 
125
#endif
 
126
    CGContextTranslateCTM( m_overlayContext, 0, m_height );
 
127
    CGContextScaleCTM( m_overlayContext, 1, -1 );
 
128
    CGContextTranslateCTM( m_overlayContext, -m_x , -m_y );
 
129
    wxASSERT_MSG(  err == noErr , _("Couldn't init the context on the overlay window") );
 
130
}
 
131
 
 
132
void wxOverlayImpl::BeginDrawing( wxDC* dc)
 
133
{
 
134
    wxDCImpl *impl = dc->GetImpl();
 
135
    wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
 
136
    if (win_impl)
 
137
    {
 
138
        win_impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
 
139
        dc->SetClippingRegion( m_x , m_y , m_width , m_height ) ;
 
140
    }
 
141
}
 
142
 
 
143
void wxOverlayImpl::EndDrawing( wxDC* dc)
 
144
{
 
145
    wxDCImpl *impl = dc->GetImpl();
 
146
    wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
 
147
    if (win_impl)
 
148
        win_impl->SetGraphicsContext(NULL);
 
149
 
 
150
    CGContextFlush( m_overlayContext );
 
151
}
 
152
 
 
153
void wxOverlayImpl::Clear(wxDC* WXUNUSED(dc))
 
154
{
 
155
    wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
 
156
    CGRect box  = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
 
157
    CGContextClearRect( m_overlayContext, box );
 
158
}
 
159
 
 
160
void wxOverlayImpl::Reset()
 
161
{
 
162
    if ( m_overlayContext )
 
163
    {
 
164
#ifndef __LP64__
 
165
        OSStatus err = QDEndCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
 
166
        if ( err != noErr )
 
167
        {
 
168
            wxFAIL_MSG("Couldn't end the context on the overlay window");
 
169
        }
 
170
#endif
 
171
        m_overlayContext = NULL ;
 
172
    }
 
173
 
 
174
    // todo : don't dispose, only hide and reposition on next run
 
175
    if (m_overlayWindow)
 
176
    {
 
177
        DisposeWindow(m_overlayWindow);
 
178
        m_overlayWindow = NULL ;
 
179
    }
 
180
}
 
181
 
 
182
#endif // wxHAS_NATIVE_OVERLAY