]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcmemory.cpp
derive wxMask from wxMaskBase
[wxWidgets.git] / src / gtk / dcmemory.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
f38924e8 2// Name: src/gtk/dcmemory.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
6f65e337 5// RCS-ID: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/dcmemory.h"
888dde65 14#include "wx/gtk/dcmemory.h"
c801d85f 15
071a2d78
RR
16#include <gdk/gdk.h>
17#include <gtk/gtk.h>
83624f79 18
c801d85f 19//-----------------------------------------------------------------------------
888dde65 20// wxMemoryDCImpl
c801d85f
KB
21//-----------------------------------------------------------------------------
22
888dde65 23IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxWindowDCImpl)
ab171e95 24
03647350 25wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
888dde65 26 : wxWindowDCImpl( owner )
03647350
VZ
27{
28 Init();
ab171e95 29}
c801d85f 30
03647350 31wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap)
888dde65 32 : wxWindowDCImpl( owner )
03647350
VZ
33{
34 Init();
35 DoSelect(bitmap);
ab171e95 36}
72cdf4c9 37
888dde65
RR
38wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC *WXUNUSED(dc) )
39 : wxWindowDCImpl( owner )
ab171e95
RR
40{
41 Init();
42}
c801d85f 43
888dde65 44wxMemoryDCImpl::~wxMemoryDCImpl()
c801d85f 45{
42c60e74 46 g_object_unref(m_context);
ff7b1510 47}
c801d85f 48
888dde65 49void wxMemoryDCImpl::Init()
ab171e95
RR
50{
51 m_ok = false;
52
53 m_cmap = gtk_widget_get_default_colormap();
54
55 m_context = gdk_pango_context_get();
56 // Note: The Sun customised version of Pango shipping with Solaris 10
57 // crashes if the language is left NULL (see bug 1374114)
58 pango_context_set_language( m_context, gtk_get_default_language() );
59 m_layout = pango_layout_new( m_context );
60 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
61}
62
888dde65 63void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
c801d85f 64{
3d2d8da1 65 Destroy();
fea35690 66
4bc67cc5
RR
67 m_selected = bitmap;
68 if (m_selected.Ok())
6f65e337 69 {
888dde65 70 m_gdkwindow = m_selected.GetPixmap();
72cdf4c9 71
7452aff5 72 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
7452aff5 73
ab171e95 74 SetUpDC( true );
6f65e337
JS
75 }
76 else
72cdf4c9 77 {
f38924e8 78 m_ok = false;
d3b9f782 79 m_gdkwindow = NULL;
6f65e337 80 }
ff7b1510 81}
c801d85f 82
888dde65 83void wxMemoryDCImpl::SetPen( const wxPen& penOrig )
41fbc841 84{
8ab40c52
VZ
85 wxPen pen( penOrig );
86 if ( m_selected.Ok() &&
b85229d1 87 m_selected.GetDepth() == 1 &&
8ab40c52 88 (pen != *wxTRANSPARENT_PEN) )
41fbc841 89 {
8ab40c52 90 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 91 }
8ab40c52 92
888dde65 93 wxWindowDCImpl::SetPen( pen );
41fbc841
RR
94}
95
888dde65 96void wxMemoryDCImpl::SetBrush( const wxBrush& brushOrig )
41fbc841 97{
8ab40c52
VZ
98 wxBrush brush( brushOrig );
99 if ( m_selected.Ok() &&
b85229d1 100 m_selected.GetDepth() == 1 &&
8ab40c52 101 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 102 {
8ab40c52 103 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 104 }
8ab40c52 105
888dde65 106 wxWindowDCImpl::SetBrush( brush );
8ab40c52
VZ
107}
108
888dde65 109void wxMemoryDCImpl::SetBackground( const wxBrush& brushOrig )
8ab40c52
VZ
110{
111 wxBrush brush(brushOrig);
112
113 if ( m_selected.Ok() &&
b85229d1 114 m_selected.GetDepth() == 1 &&
8ab40c52 115 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 116 {
8ab40c52 117 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 118 }
8ab40c52 119
888dde65 120 wxWindowDCImpl::SetBackground( brush );
41fbc841
RR
121}
122
888dde65 123void wxMemoryDCImpl::SetTextForeground( const wxColour& col )
41fbc841 124{
b85229d1 125 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
888dde65 126 wxWindowDCImpl::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 127 else
888dde65 128 wxWindowDCImpl::SetTextForeground( col );
41fbc841
RR
129}
130
888dde65 131void wxMemoryDCImpl::SetTextBackground( const wxColour &col )
41fbc841 132{
b85229d1 133 if (m_selected.Ok() && m_selected.GetDepth() == 1)
888dde65 134 wxWindowDCImpl::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 135 else
888dde65 136 wxWindowDCImpl::SetTextBackground( col );
41fbc841
RR
137}
138
888dde65 139void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
c801d85f 140{
4bc67cc5
RR
141 if (m_selected.Ok())
142 {
143 if (width) (*width) = m_selected.GetWidth();
144 if (height) (*height) = m_selected.GetHeight();
145 }
146 else
147 {
148 if (width) (*width) = 0;
149 if (height) (*height) = 0;
150 }
ff7b1510 151}
ab171e95 152
888dde65 153wxBitmap wxMemoryDCImpl::DoGetAsBitmap(const wxRect *subrect) const
ab171e95
RR
154{
155 wxBitmap bmp = GetSelectedBitmap();
156 return subrect ? bmp.GetSubBitmap(*subrect) : bmp;
157}
158
888dde65 159const wxBitmap& wxMemoryDCImpl::GetSelectedBitmap() const
ab171e95
RR
160{
161 return m_selected;
162}
163
888dde65 164wxBitmap& wxMemoryDCImpl::GetSelectedBitmap()
ab171e95
RR
165{
166 return m_selected;
167}
168