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