]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
GTK+ doesn't like slider with min=max values
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/mac/carbon/dcclient.cpp
e9576ca5 3// Purpose: wxClientDC class
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e4db172a 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
e9576ca5 14#include "wx/dcclient.h"
e4db172a
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/log.h"
cdccdfab 18 #include "wx/window.h"
f38924e8 19 #include "wx/dcmemory.h"
9eddec69 20 #include "wx/settings.h"
1832043f 21 #include "wx/toplevel.h"
18680f86 22 #include "wx/math.h"
b3a44e05 23 #include "wx/region.h"
e4db172a
WS
24#endif
25
8acd14d1 26#include "wx/graphics.h"
c64c9cd3 27#include "wx/rawbmp.h"
76a5e5d2 28#include "wx/mac/private.h"
e9576ca5
SC
29
30//-----------------------------------------------------------------------------
31// constants
32//-----------------------------------------------------------------------------
33
e9576ca5
SC
34//-----------------------------------------------------------------------------
35// wxPaintDC
36//-----------------------------------------------------------------------------
37
e9576ca5
SC
38IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
39IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
40IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
e9576ca5
SC
41
42/*
43 * wxWindowDC
44 */
45
d497dca4 46#include "wx/mac/uma.h"
be346c26
SC
47#include "wx/notebook.h"
48#include "wx/tabctrl.h"
e4db172a 49
be346c26 50
be346c26 51
e4db172a 52wxWindowDC::wxWindowDC()
e9576ca5 53{
1be0560e 54 m_window = NULL ;
1f2b627a 55 m_release = false;
519cb848 56}
e9576ca5 57
e4db172a 58wxWindowDC::wxWindowDC(wxWindow *window)
519cb848 59{
1be0560e 60 m_window = window ;
9f391ae1
SC
61 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
62 if (!rootwindow)
63 return;
9b2eab52 64
eb1a7cf9
DS
65 m_ok = true ;
66
4130e414 67 m_window->GetSize( &m_width , &m_height);
a2d6d210
VZ
68 CGContextRef cg = (CGContextRef) window->MacGetCGContextRef();
69 m_release = false;
4130e414 70 if ( cg == NULL )
a2d6d210
VZ
71 {
72 SetGraphicsContext( wxGraphicsContext::Create( window ) ) ;
a2d6d210
VZ
73 }
74 else
75 {
76 CGContextSaveGState( cg );
77 m_release = true ;
8a438f46 78 // make sure the context is having its origin at the wx-window coordinates of the
a2d6d210
VZ
79 // view (read at the top of window.cpp about the differences)
80 if ( window->MacGetLeftBorderSize() != 0 || window->MacGetTopBorderSize() != 0 )
81 CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
82
83 SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
84 }
a2d6d210 85 SetClippingRegion( 0 , 0 , m_width , m_height ) ;
e1673e52 86
a01d9a25 87 SetBackground(wxBrush(window->GetBackgroundColour(),wxSOLID));
9b2eab52 88
20b69855 89 SetFont( window->GetFont() ) ;
519cb848 90}
e9576ca5 91
2f1ae414 92wxWindowDC::~wxWindowDC()
e9576ca5 93{
35ee7124 94 if ( m_release )
a2d6d210 95 {
35ee7124
SC
96 // this must not necessarily be the current context, we must restore the state of the
97 // cg we started with above (before the CGContextTranslateCTM call)
a2d6d210
VZ
98 CGContextRef cg = (CGContextRef) m_window->MacGetCGContextRef();
99 CGContextRestoreGState(cg);
a2d6d210 100 }
519cb848 101}
e9576ca5 102
1be0560e
SC
103void wxWindowDC::DoGetSize( int* width, int* height ) const
104{
a2d6d210
VZ
105 if ( width )
106 *width = m_width;
107 if ( height )
108 *height = m_height;
1be0560e
SC
109}
110
b2d123f1 111wxBitmap wxWindowDC::DoGetAsBitmap(const wxRect *subrect) const
c64c9cd3 112{
90b0f5fc
KO
113 // wxScreenDC is derived from wxWindowDC, so a screen dc will
114 // call this method when a Blit is performed with it as a source.
115 if (!m_window)
116 return wxNullBitmap;
31c1cbc7 117
1bd568fa
SC
118#ifdef __LP64__
119 return wxNullBitmap;
120#else
8a438f46 121 ControlRef handle = (ControlRef) m_window->GetHandle();
c64c9cd3
KO
122 if ( !handle )
123 return wxNullBitmap;
1bd568fa 124
8a438f46 125 HIRect rect;
c64c9cd3
KO
126 CGImageRef image;
127 CGContextRef context;
128 void* data;
8a438f46 129
c64c9cd3 130 size_t bytesPerRow;
8a438f46 131
c64c9cd3 132 HIViewCreateOffscreenImage( handle, 0, &rect, &image);
8a438f46
VZ
133
134
135 int width = subrect != NULL ? subrect->width : (int)rect.size.width;
136 int height = subrect != NULL ? subrect->height : (int)rect.size.height ;
137
c64c9cd3
KO
138 bytesPerRow = ( ( width * 8 * 4 + 7 ) / 8 );
139
140 data = calloc( 1, bytesPerRow * height );
141 context = CGBitmapContextCreate( data, width, height, 8, bytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst );
8a438f46 142
b2d123f1
SC
143 if ( subrect )
144 rect = CGRectOffset( rect, -subrect->x, -subrect->y ) ;
c64c9cd3
KO
145 CGContextDrawImage( context, rect, image );
146
8a438f46 147 unsigned char* buffer = (unsigned char*) data;
c64c9cd3
KO
148 wxBitmap bmp = wxBitmap(width, height, 32);
149 wxAlphaPixelData pixData(bmp, wxPoint(0,0), wxSize(width, height));
8a438f46 150
c64c9cd3
KO
151 wxAlphaPixelData::Iterator p(pixData);
152 for (int y=0; y<height; y++) {
153 wxAlphaPixelData::Iterator rowStart = p;
154 for (int x=0; x<width; x++) {
155 unsigned char a = buffer[3];
156 p.Red() = a; buffer++;
157 p.Green() = a; buffer++;
158 p.Blue() = a; buffer++;
159 p.Alpha() = a; buffer++;
8a438f46 160 ++p;
c64c9cd3
KO
161 }
162 p = rowStart;
163 p.OffsetY(pixData, 1);
164 }
8a438f46 165
c64c9cd3 166 return bmp;
1bd568fa 167#endif
c64c9cd3
KO
168}
169
519cb848
SC
170/*
171 * wxClientDC
172 */
e9576ca5 173
2f1ae414 174wxClientDC::wxClientDC()
e9576ca5 175{
1be0560e 176 m_window = NULL ;
e9576ca5
SC
177}
178
4130e414 179wxClientDC::wxClientDC(wxWindow *window) :
a2d6d210 180 wxWindowDC( window )
4130e414 181{
6239ee05 182 wxCHECK_RET( window, _T("invalid window in wxClientDC") );
4130e414 183 wxPoint origin = window->GetClientAreaOrigin() ;
4130e414 184 m_window->GetClientSize( &m_width , &m_height);
a2d6d210
VZ
185 SetDeviceOrigin( origin.x, origin.y );
186 SetClippingRegion( 0 , 0 , m_width , m_height ) ;
4130e414 187}
e9576ca5 188
2f1ae414 189wxClientDC::~wxClientDC()
e9576ca5 190{
e9576ca5
SC
191}
192
519cb848
SC
193/*
194 * wxPaintDC
195 */
e9576ca5 196
2f1ae414 197wxPaintDC::wxPaintDC()
e9576ca5 198{
1be0560e 199 m_window = NULL ;
e9576ca5
SC
200}
201
4130e414 202wxPaintDC::wxPaintDC(wxWindow *window) :
a2d6d210 203 wxWindowDC( window )
4130e414
SC
204{
205 wxPoint origin = window->GetClientAreaOrigin() ;
4130e414 206 m_window->GetClientSize( &m_width , &m_height);
a2d6d210
VZ
207 SetDeviceOrigin( origin.x, origin.y );
208 SetClippingRegion( 0 , 0 , m_width , m_height ) ;
4130e414 209}
e9576ca5 210
519cb848 211wxPaintDC::~wxPaintDC()
e9576ca5 212{
519cb848 213}