]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dcmemory.cpp
replaced FIXME comment left in the last commit with an explanation
[wxWidgets.git] / src / gtk / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dcmemory.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #include "wx/dcmemory.h"
14
15 #include <gdk/gdk.h>
16 #include <gtk/gtk.h>
17
18 //-----------------------------------------------------------------------------
19 // wxMemoryDC
20 //-----------------------------------------------------------------------------
21
22 #if wxUSE_NEW_DC
23 IMPLEMENT_ABSTRACT_CLASS(wxGTKMemoryImplDC, wxGTKWindowImplDC)
24 #else
25 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDC,wxWindowDC)
26 #endif
27
28 #if wxUSE_NEW_DC
29 wxGTKMemoryImplDC::wxGTKMemoryImplDC( wxMemoryDC *owner )
30 : wxGTKWindowImplDC( owner )
31 {
32 Init();
33 }
34
35 wxGTKMemoryImplDC::wxGTKMemoryImplDC( wxMemoryDC *owner, wxBitmap& bitmap)
36 : wxGTKWindowImplDC( owner )
37 {
38 Init();
39 owner->SelectObject(bitmap);
40 }
41
42 wxGTKMemoryImplDC::wxGTKMemoryImplDC( wxMemoryDC *owner, wxDC *WXUNUSED(dc) )
43 : wxGTKWindowImplDC( owner )
44 {
45 Init();
46 }
47 #else
48 wxMemoryDC::wxMemoryDC()
49 {
50 Init();
51 }
52
53 wxMemoryDC::wxMemoryDC(wxBitmap& bitmap)
54 {
55 Init();
56 SelectObject(bitmap);
57 }
58
59 wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
60 : wxWindowDC()
61 {
62 Init();
63 }
64 #endif
65
66 wxGTKMemoryImplDC::~wxGTKMemoryImplDC()
67 {
68 g_object_unref(m_context);
69 }
70
71 void wxGTKMemoryImplDC::Init()
72 {
73 m_ok = false;
74
75 m_cmap = gtk_widget_get_default_colormap();
76
77 m_context = gdk_pango_context_get();
78 // Note: The Sun customised version of Pango shipping with Solaris 10
79 // crashes if the language is left NULL (see bug 1374114)
80 pango_context_set_language( m_context, gtk_get_default_language() );
81 m_layout = pango_layout_new( m_context );
82 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
83 }
84
85 void wxGTKMemoryImplDC::DoSelect( const wxBitmap& bitmap )
86 {
87 Destroy();
88
89 m_selected = bitmap;
90 if (m_selected.Ok())
91 {
92 m_window = m_selected.GetPixmap();
93
94 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
95
96 SetUpDC( true );
97 }
98 else
99 {
100 m_ok = false;
101 m_window = (GdkWindow *) NULL;
102 }
103 }
104
105 void wxGTKMemoryImplDC::SetPen( const wxPen& penOrig )
106 {
107 wxPen pen( penOrig );
108 if ( m_selected.Ok() &&
109 m_selected.GetDepth() == 1 &&
110 (pen != *wxTRANSPARENT_PEN) )
111 {
112 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
113 }
114
115 wxGTKWindowImplDC::SetPen( pen );
116 }
117
118 void wxGTKMemoryImplDC::SetBrush( const wxBrush& brushOrig )
119 {
120 wxBrush brush( brushOrig );
121 if ( m_selected.Ok() &&
122 m_selected.GetDepth() == 1 &&
123 (brush != *wxTRANSPARENT_BRUSH) )
124 {
125 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
126 }
127
128 wxGTKWindowImplDC::SetBrush( brush );
129 }
130
131 void wxGTKMemoryImplDC::SetBackground( const wxBrush& brushOrig )
132 {
133 wxBrush brush(brushOrig);
134
135 if ( m_selected.Ok() &&
136 m_selected.GetDepth() == 1 &&
137 (brush != *wxTRANSPARENT_BRUSH) )
138 {
139 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
140 }
141
142 wxGTKWindowImplDC::SetBackground( brush );
143 }
144
145 void wxGTKMemoryImplDC::SetTextForeground( const wxColour& col )
146 {
147 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
148 {
149 wxGTKWindowImplDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
150 }
151 else
152 {
153 wxGTKWindowImplDC::SetTextForeground( col );
154 }
155 }
156
157 void wxGTKMemoryImplDC::SetTextBackground( const wxColour &col )
158 {
159 if (m_selected.Ok() && m_selected.GetDepth() == 1)
160 {
161 wxGTKWindowImplDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
162 }
163 else
164 {
165 wxGTKWindowImplDC::SetTextBackground( col );
166 }
167 }
168
169 void wxGTKMemoryImplDC::DoGetSize( int *width, int *height ) const
170 {
171 if (m_selected.Ok())
172 {
173 if (width) (*width) = m_selected.GetWidth();
174 if (height) (*height) = m_selected.GetHeight();
175 }
176 else
177 {
178 if (width) (*width) = 0;
179 if (height) (*height) = 0;
180 }
181 }
182
183 wxBitmap wxGTKMemoryImplDC::DoGetAsBitmap(const wxRect *subrect) const
184 {
185 wxBitmap bmp = GetSelectedBitmap();
186 return subrect ? bmp.GetSubBitmap(*subrect) : bmp;
187 }
188
189 const wxBitmap& wxGTKMemoryImplDC::DoGetSelectedBitmap() const
190 {
191 return m_selected;
192 }
193
194 wxBitmap& wxGTKMemoryImplDC::DoGetSelectedBitmap()
195 {
196 return m_selected;
197 }
198