Font work.
[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 #ifdef __GNUG__
11 #pragma implementation "dcmemory.h"
12 #endif
13
14 #include "wx/dcmemory.h"
15
16 #include <gdk/gdk.h>
17 #include <gtk/gtk.h>
18
19 //-----------------------------------------------------------------------------
20 // wxMemoryDC
21 //-----------------------------------------------------------------------------
22
23 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC)
24
25 wxMemoryDC::wxMemoryDC() : wxWindowDC()
26 {
27 m_ok = FALSE;
28
29 m_cmap = gtk_widget_get_default_colormap();
30
31 #ifdef __WXGTK20__
32 m_context = gdk_pango_context_get();
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 m_layout = pango_layout_new( m_context );
48 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
49 #endif
50 }
51
52 wxMemoryDC::~wxMemoryDC()
53 {
54 }
55
56 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
57 {
58 Destroy();
59 m_selected = bitmap;
60 if (m_selected.Ok())
61 {
62 if (m_selected.GetPixmap())
63 {
64 m_window = m_selected.GetPixmap();
65 }
66 else
67 {
68 m_window = m_selected.GetBitmap();
69 }
70
71 m_isMemDC = TRUE;
72
73 SetUpDC();
74 }
75 else
76 {
77 m_ok = FALSE;
78 m_window = (GdkWindow *) NULL;
79 }
80 }
81
82 void wxMemoryDC::SetPen( const wxPen &pen )
83 {
84 if (m_selected.Ok() && m_selected.GetBitmap() && (*wxTRANSPARENT_PEN != pen))
85 {
86 if (*wxWHITE_PEN == pen)
87 wxWindowDC::SetPen( *wxBLACK_PEN );
88 else
89 wxWindowDC::SetPen( *wxWHITE_PEN );
90 }
91 else
92 {
93 wxWindowDC::SetPen( pen );
94 }
95 }
96
97 void wxMemoryDC::SetBrush( const wxBrush &brush )
98 {
99 if (m_selected.Ok() && m_selected.GetBitmap() && (*wxTRANSPARENT_BRUSH != brush))
100 {
101 if (*wxWHITE_BRUSH == brush)
102 wxWindowDC::SetBrush( *wxBLACK_BRUSH );
103 else
104 wxWindowDC::SetBrush( *wxWHITE_BRUSH );
105 }
106 else
107 {
108 wxWindowDC::SetBrush( brush );
109 }
110 }
111
112 void wxMemoryDC::SetTextForeground( const wxColour &col )
113 {
114 if (m_selected.Ok() && m_selected.GetBitmap())
115 {
116 if (col == *wxWHITE)
117 wxWindowDC::SetTextForeground( *wxBLACK );
118 else
119 wxWindowDC::SetTextForeground( *wxWHITE );
120 }
121 else
122 {
123 wxWindowDC::SetTextForeground( col );
124 }
125 }
126
127 void wxMemoryDC::SetTextBackground( const wxColour &col )
128 {
129 if (m_selected.Ok() && m_selected.GetBitmap())
130 {
131 if (col == *wxWHITE)
132 wxWindowDC::SetTextBackground( *wxBLACK );
133 else
134 wxWindowDC::SetTextBackground( *wxWHITE );
135 }
136 else
137 {
138 wxWindowDC::SetTextBackground( col );
139 }
140 }
141
142 void wxMemoryDC::DoGetSize( int *width, int *height ) const
143 {
144 if (m_selected.Ok())
145 {
146 if (width) (*width) = m_selected.GetWidth();
147 if (height) (*height) = m_selected.GetHeight();
148 }
149 else
150 {
151 if (width) (*width) = 0;
152 if (height) (*height) = 0;
153 }
154 }
155
156