]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcmemory.cpp
Fixed wxAtomicInc/Dec() to not use asm/atomic.h header on Linux - it's kernel interna...
[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
fea35690 24void wxMemoryDC::Init()
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{
fea35690 41 Init();
ff7b1510 42}
c801d85f 43
4bc67cc5 44wxMemoryDC::~wxMemoryDC()
c801d85f 45{
42c60e74 46 g_object_unref(m_context);
ff7b1510 47}
c801d85f 48
fea35690 49void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
c801d85f 50{
3d2d8da1 51 Destroy();
fea35690 52
4bc67cc5
RR
53 m_selected = bitmap;
54 if (m_selected.Ok())
6f65e337 55 {
b85229d1 56 m_window = m_selected.GetPixmap();
72cdf4c9 57
7452aff5 58 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
7452aff5 59
f38924e8 60 m_isMemDC = true;
809934d2
RR
61
62 SetUpDC();
6f65e337
JS
63 }
64 else
72cdf4c9 65 {
f38924e8 66 m_ok = false;
4bc67cc5 67 m_window = (GdkWindow *) NULL;
6f65e337 68 }
ff7b1510 69}
c801d85f 70
8ab40c52 71void wxMemoryDC::SetPen( const wxPen& penOrig )
41fbc841 72{
8ab40c52
VZ
73 wxPen pen( penOrig );
74 if ( m_selected.Ok() &&
b85229d1 75 m_selected.GetDepth() == 1 &&
8ab40c52 76 (pen != *wxTRANSPARENT_PEN) )
41fbc841 77 {
8ab40c52 78 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 79 }
8ab40c52
VZ
80
81 wxWindowDC::SetPen( pen );
41fbc841
RR
82}
83
8ab40c52 84void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
41fbc841 85{
8ab40c52
VZ
86 wxBrush brush( brushOrig );
87 if ( m_selected.Ok() &&
b85229d1 88 m_selected.GetDepth() == 1 &&
8ab40c52 89 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 90 {
8ab40c52 91 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 92 }
8ab40c52
VZ
93
94 wxWindowDC::SetBrush( brush );
95}
96
3d257b8d 97void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
8ab40c52
VZ
98{
99 wxBrush brush(brushOrig);
100
101 if ( m_selected.Ok() &&
b85229d1 102 m_selected.GetDepth() == 1 &&
8ab40c52 103 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 104 {
8ab40c52 105 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 106 }
8ab40c52
VZ
107
108 wxWindowDC::SetBackground( brush );
41fbc841
RR
109}
110
8ab40c52 111void wxMemoryDC::SetTextForeground( const wxColour& col )
41fbc841 112{
b85229d1 113 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
41fbc841 114 {
8ab40c52 115 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841
RR
116 }
117 else
118 {
119 wxWindowDC::SetTextForeground( col );
120 }
121}
122
123void wxMemoryDC::SetTextBackground( const wxColour &col )
124{
b85229d1 125 if (m_selected.Ok() && m_selected.GetDepth() == 1)
41fbc841 126 {
8ab40c52 127 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841
RR
128 }
129 else
130 {
131 wxWindowDC::SetTextBackground( col );
132 }
133}
134
4e4ea166 135void wxMemoryDC::DoGetSize( int *width, int *height ) const
c801d85f 136{
4bc67cc5
RR
137 if (m_selected.Ok())
138 {
139 if (width) (*width) = m_selected.GetWidth();
140 if (height) (*height) = m_selected.GetHeight();
141 }
142 else
143 {
144 if (width) (*width) = 0;
145 if (height) (*height) = 0;
146 }
ff7b1510 147}