]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcmemory.cpp
Commited Bryan Petty's blind fix patch.
[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
KB
13#include "wx/dcmemory.h"
14
071a2d78
RR
15#include <gdk/gdk.h>
16#include <gtk/gtk.h>
83624f79 17
c801d85f
KB
18//-----------------------------------------------------------------------------
19// wxMemoryDC
20//-----------------------------------------------------------------------------
21
ec758a20 22IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC)
c801d85f 23
4bc67cc5 24wxMemoryDC::wxMemoryDC() : wxWindowDC()
c801d85f 25{
f38924e8 26 m_ok = false;
72cdf4c9 27
4bc67cc5 28 m_cmap = gtk_widget_get_default_colormap();
3d257b8d 29
cfcc3932 30 m_context = gdk_pango_context_get();
e90d93d1
MW
31 // Note: The Sun customised version of Pango shipping with Solaris 10
32 // crashes if the language is left NULL (see bug 1374114)
203b65dd 33 pango_context_set_language( m_context, gtk_get_default_language() );
cfcc3932
RR
34 m_layout = pango_layout_new( m_context );
35 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
ff7b1510 36}
c801d85f 37
72cdf4c9 38wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
ec758a20 39 : wxWindowDC()
c801d85f 40{
f38924e8 41 m_ok = false;
72cdf4c9 42
4bc67cc5 43 m_cmap = gtk_widget_get_default_colormap();
3d257b8d 44
cfcc3932 45 m_context = gdk_pango_context_get();
203b65dd 46 pango_context_set_language( m_context, gtk_get_default_language() );
cfcc3932
RR
47 m_layout = pango_layout_new( m_context );
48 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
ff7b1510 49}
c801d85f 50
4bc67cc5 51wxMemoryDC::~wxMemoryDC()
c801d85f 52{
42c60e74 53 g_object_unref(m_context);
ff7b1510 54}
c801d85f
KB
55
56void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
57{
3d2d8da1 58 Destroy();
4bc67cc5
RR
59 m_selected = bitmap;
60 if (m_selected.Ok())
6f65e337 61 {
b85229d1 62 m_window = m_selected.GetPixmap();
72cdf4c9 63
7452aff5 64 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
7452aff5 65
f38924e8 66 m_isMemDC = true;
809934d2
RR
67
68 SetUpDC();
6f65e337
JS
69 }
70 else
72cdf4c9 71 {
f38924e8 72 m_ok = false;
4bc67cc5 73 m_window = (GdkWindow *) NULL;
6f65e337 74 }
ff7b1510 75}
c801d85f 76
8ab40c52 77void wxMemoryDC::SetPen( const wxPen& penOrig )
41fbc841 78{
8ab40c52
VZ
79 wxPen pen( penOrig );
80 if ( m_selected.Ok() &&
b85229d1 81 m_selected.GetDepth() == 1 &&
8ab40c52 82 (pen != *wxTRANSPARENT_PEN) )
41fbc841 83 {
8ab40c52 84 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 85 }
8ab40c52
VZ
86
87 wxWindowDC::SetPen( pen );
41fbc841
RR
88}
89
8ab40c52 90void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
41fbc841 91{
8ab40c52
VZ
92 wxBrush brush( brushOrig );
93 if ( m_selected.Ok() &&
b85229d1 94 m_selected.GetDepth() == 1 &&
8ab40c52 95 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 96 {
8ab40c52 97 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 98 }
8ab40c52
VZ
99
100 wxWindowDC::SetBrush( brush );
101}
102
3d257b8d 103void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
8ab40c52
VZ
104{
105 wxBrush brush(brushOrig);
106
107 if ( m_selected.Ok() &&
b85229d1 108 m_selected.GetDepth() == 1 &&
8ab40c52 109 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 110 {
8ab40c52 111 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 112 }
8ab40c52
VZ
113
114 wxWindowDC::SetBackground( brush );
41fbc841
RR
115}
116
8ab40c52 117void wxMemoryDC::SetTextForeground( const wxColour& col )
41fbc841 118{
b85229d1 119 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
41fbc841 120 {
8ab40c52 121 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841
RR
122 }
123 else
124 {
125 wxWindowDC::SetTextForeground( col );
126 }
127}
128
129void wxMemoryDC::SetTextBackground( const wxColour &col )
130{
b85229d1 131 if (m_selected.Ok() && m_selected.GetDepth() == 1)
41fbc841 132 {
8ab40c52 133 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841
RR
134 }
135 else
136 {
137 wxWindowDC::SetTextBackground( col );
138 }
139}
140
4e4ea166 141void wxMemoryDC::DoGetSize( int *width, int *height ) const
c801d85f 142{
4bc67cc5
RR
143 if (m_selected.Ok())
144 {
145 if (width) (*width) = m_selected.GetWidth();
146 if (height) (*height) = m_selected.GetHeight();
147 }
148 else
149 {
150 if (width) (*width) = 0;
151 if (height) (*height) = 0;
152 }
ff7b1510 153}