]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dcmemory.cpp
Applied patch [ 1331340 ] faster Drawing of Polygons and Polylines
[wxWidgets.git] / src / gtk / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC)
23
24 wxMemoryDC::wxMemoryDC() : wxWindowDC()
25 {
26 m_ok = FALSE;
27
28 m_cmap = gtk_widget_get_default_colormap();
29
30 #ifdef __WXGTK20__
31 m_context = gdk_pango_context_get();
32 // Note: The Sun customised version of Pango shipping with Solaris 10
33 // crashes if the language is left NULL (see bug 1374114)
34 pango_context_set_language( m_context, gtk_get_default_language() );
35 m_layout = pango_layout_new( m_context );
36 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
37 #endif
38 }
39
40 wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
41 : wxWindowDC()
42 {
43 m_ok = FALSE;
44
45 m_cmap = gtk_widget_get_default_colormap();
46
47 #ifdef __WXGTK20__
48 m_context = gdk_pango_context_get();
49 pango_context_set_language( m_context, gtk_get_default_language() );
50 m_layout = pango_layout_new( m_context );
51 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
52 #endif
53 }
54
55 wxMemoryDC::~wxMemoryDC()
56 {
57 #ifdef __WXGTK20__
58 g_object_unref(m_context);
59 #endif
60 }
61
62 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
63 {
64 Destroy();
65 m_selected = bitmap;
66 if (m_selected.Ok())
67 {
68 if (m_selected.GetPixmap())
69 {
70 m_window = m_selected.GetPixmap();
71 }
72 else
73 {
74 m_window = m_selected.GetBitmap();
75 }
76
77 #ifdef __WXGTK20__
78 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
79 #endif
80
81 m_isMemDC = TRUE;
82
83 SetUpDC();
84 }
85 else
86 {
87 m_ok = FALSE;
88 m_window = (GdkWindow *) NULL;
89 }
90 }
91
92 void wxMemoryDC::SetPen( const wxPen& penOrig )
93 {
94 wxPen pen( penOrig );
95 if ( m_selected.Ok() &&
96 m_selected.GetBitmap() &&
97 (pen != *wxTRANSPARENT_PEN) )
98 {
99 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
100 }
101
102 wxWindowDC::SetPen( pen );
103 }
104
105 void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
106 {
107 wxBrush brush( brushOrig );
108 if ( m_selected.Ok() &&
109 m_selected.GetBitmap() &&
110 (brush != *wxTRANSPARENT_BRUSH) )
111 {
112 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
113 }
114
115 wxWindowDC::SetBrush( brush );
116 }
117
118 void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
119 {
120 wxBrush brush(brushOrig);
121
122 if ( m_selected.Ok() &&
123 m_selected.GetBitmap() &&
124 (brush != *wxTRANSPARENT_BRUSH) )
125 {
126 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
127 }
128
129 wxWindowDC::SetBackground( brush );
130 }
131
132 void wxMemoryDC::SetTextForeground( const wxColour& col )
133 {
134 if ( m_selected.Ok() && m_selected.GetBitmap() )
135 {
136 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
137 }
138 else
139 {
140 wxWindowDC::SetTextForeground( col );
141 }
142 }
143
144 void wxMemoryDC::SetTextBackground( const wxColour &col )
145 {
146 if (m_selected.Ok() && m_selected.GetBitmap())
147 {
148 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
149 }
150 else
151 {
152 wxWindowDC::SetTextBackground( col );
153 }
154 }
155
156 void wxMemoryDC::DoGetSize( int *width, int *height ) const
157 {
158 if (m_selected.Ok())
159 {
160 if (width) (*width) = m_selected.GetWidth();
161 if (height) (*height) = m_selected.GetHeight();
162 }
163 else
164 {
165 if (width) (*width) = 0;
166 if (height) (*height) = 0;
167 }
168 }
169
170