]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dcmemory.cpp
Small code cleanup
[wxWidgets.git] / src / gtk1 / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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 void wxMemoryDC::Init()
25 {
26 m_ok = false;
27
28 m_cmap = gtk_widget_get_default_colormap();
29 }
30
31 wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
32 : wxWindowDC()
33 {
34 Init();
35 }
36
37 wxMemoryDC::~wxMemoryDC()
38 {
39 }
40
41 void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
42 {
43 Destroy();
44
45 m_selected = bitmap;
46 if (m_selected.Ok())
47 {
48 if (m_selected.GetPixmap())
49 {
50 m_window = m_selected.GetPixmap();
51 }
52 else
53 {
54 m_window = m_selected.GetBitmap();
55 }
56
57 m_isMemDC = true;
58
59 SetUpDC();
60 }
61 else
62 {
63 m_ok = false;
64 m_window = (GdkWindow *) NULL;
65 }
66 }
67
68 void wxMemoryDC::SetPen( const wxPen& penOrig )
69 {
70 wxPen pen( penOrig );
71 if ( m_selected.Ok() &&
72 m_selected.GetBitmap() &&
73 (pen != *wxTRANSPARENT_PEN) )
74 {
75 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
76 }
77
78 wxWindowDC::SetPen( pen );
79 }
80
81 void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
82 {
83 wxBrush brush( brushOrig );
84 if ( m_selected.Ok() &&
85 m_selected.GetBitmap() &&
86 (brush != *wxTRANSPARENT_BRUSH) )
87 {
88 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
89 }
90
91 wxWindowDC::SetBrush( brush );
92 }
93
94 void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
95 {
96 wxBrush brush(brushOrig);
97
98 if ( m_selected.Ok() &&
99 m_selected.GetBitmap() &&
100 (brush != *wxTRANSPARENT_BRUSH) )
101 {
102 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
103 }
104
105 wxWindowDC::SetBackground( brush );
106 }
107
108 void wxMemoryDC::SetTextForeground( const wxColour& col )
109 {
110 if ( m_selected.Ok() && m_selected.GetBitmap() )
111 {
112 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
113 }
114 else
115 {
116 wxWindowDC::SetTextForeground( col );
117 }
118 }
119
120 void wxMemoryDC::SetTextBackground( const wxColour &col )
121 {
122 if (m_selected.Ok() && m_selected.GetBitmap())
123 {
124 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
125 }
126 else
127 {
128 wxWindowDC::SetTextBackground( col );
129 }
130 }
131
132 void wxMemoryDC::DoGetSize( int *width, int *height ) const
133 {
134 if (m_selected.Ok())
135 {
136 if (width) (*width) = m_selected.GetWidth();
137 if (height) (*height) = m_selected.GetHeight();
138 }
139 else
140 {
141 if (width) (*width) = 0;
142 if (height) (*height) = 0;
143 }
144 }