]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dcmemory.cpp
Should return wxImage not bool
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "dcmemory.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #include "wx/dcmemory.h"
18
19 #include <gdk/gdk.h>
20 #include <gtk/gtk.h>
21
22 //-----------------------------------------------------------------------------
23 // wxMemoryDC
24 //-----------------------------------------------------------------------------
25
26 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC)
27
28 wxMemoryDC::wxMemoryDC() : wxWindowDC()
29 {
30 m_ok = FALSE;
31
32 m_cmap = gtk_widget_get_default_colormap();
33
34 #ifdef __WXGTK20__
35 m_context = gdk_pango_context_get();
36 m_layout = pango_layout_new( m_context );
37 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
38 #endif
39 }
40
41 wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
42 : wxWindowDC()
43 {
44 m_ok = FALSE;
45
46 m_cmap = gtk_widget_get_default_colormap();
47
48 #ifdef __WXGTK20__
49 m_context = gdk_pango_context_get();
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 }
58
59 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
60 {
61 Destroy();
62 m_selected = bitmap;
63 if (m_selected.Ok())
64 {
65 if (m_selected.GetPixmap())
66 {
67 m_window = m_selected.GetPixmap();
68 }
69 else
70 {
71 m_window = m_selected.GetBitmap();
72 }
73
74 #ifdef __WXGTK20__
75 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
76 #endif
77
78 m_isMemDC = TRUE;
79
80 SetUpDC();
81 }
82 else
83 {
84 m_ok = FALSE;
85 m_window = (GdkWindow *) NULL;
86 }
87 }
88
89 void wxMemoryDC::SetPen( const wxPen& penOrig )
90 {
91 wxPen pen( penOrig );
92 if ( m_selected.Ok() &&
93 m_selected.GetBitmap() &&
94 (pen != *wxTRANSPARENT_PEN) )
95 {
96 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
97 }
98
99 wxWindowDC::SetPen( pen );
100 }
101
102 void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
103 {
104 wxBrush brush( brushOrig );
105 if ( m_selected.Ok() &&
106 m_selected.GetBitmap() &&
107 (brush != *wxTRANSPARENT_BRUSH) )
108 {
109 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
110 }
111
112 wxWindowDC::SetBrush( brush );
113 }
114
115 void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
116 {
117 wxBrush brush(brushOrig);
118
119 if ( m_selected.Ok() &&
120 m_selected.GetBitmap() &&
121 (brush != *wxTRANSPARENT_BRUSH) )
122 {
123 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
124 }
125
126 wxWindowDC::SetBackground( brush );
127 }
128
129 void wxMemoryDC::SetTextForeground( const wxColour& col )
130 {
131 if ( m_selected.Ok() && m_selected.GetBitmap() )
132 {
133 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
134 }
135 else
136 {
137 wxWindowDC::SetTextForeground( col );
138 }
139 }
140
141 void wxMemoryDC::SetTextBackground( const wxColour &col )
142 {
143 if (m_selected.Ok() && m_selected.GetBitmap())
144 {
145 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
146 }
147 else
148 {
149 wxWindowDC::SetTextBackground( col );
150 }
151 }
152
153 void wxMemoryDC::DoGetSize( int *width, int *height ) const
154 {
155 if (m_selected.Ok())
156 {
157 if (width) (*width) = m_selected.GetWidth();
158 if (height) (*height) = m_selected.GetHeight();
159 }
160 else
161 {
162 if (width) (*width) = 0;
163 if (height) (*height) = 0;
164 }
165 }
166
167