]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/dcmemory.cpp
simplify code so it always returns the same object
[wxWidgets.git] / src / gtk1 / dcmemory.cpp
... / ...
CommitLineData
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/gtk1/dcmemory.h"
14
15#include <gdk/gdk.h>
16#include <gtk/gtk.h>
17
18//-----------------------------------------------------------------------------
19// wxMemoryDCImpl
20//-----------------------------------------------------------------------------
21
22IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxWindowDCImpl)
23
24void wxMemoryDCImpl::Init()
25{
26 m_ok = false;
27
28 m_cmap = gtk_widget_get_default_colormap();
29}
30
31wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC *owner, wxDC *WXUNUSED(dc))
32 : wxWindowDCImpl(owner)
33{
34 Init();
35}
36
37wxMemoryDCImpl::~wxMemoryDCImpl()
38{
39}
40
41void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
42{
43 Destroy();
44
45 m_selected = bitmap;
46 if (m_selected.IsOk())
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 = NULL;
65 }
66}
67
68void wxMemoryDCImpl::SetPen( const wxPen& penOrig )
69{
70 wxPen pen( penOrig );
71 if ( m_selected.IsOk() &&
72 m_selected.GetBitmap() &&
73 (pen != *wxTRANSPARENT_PEN) )
74 {
75 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
76 }
77
78 wxWindowDCImpl::SetPen( pen );
79}
80
81void wxMemoryDCImpl::SetBrush( const wxBrush& brushOrig )
82{
83 wxBrush brush( brushOrig );
84 if ( m_selected.IsOk() &&
85 m_selected.GetBitmap() &&
86 (brush != *wxTRANSPARENT_BRUSH) )
87 {
88 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
89 }
90
91 wxWindowDCImpl::SetBrush( brush );
92}
93
94void wxMemoryDCImpl::SetBackground( const wxBrush& brushOrig )
95{
96 wxBrush brush(brushOrig);
97
98 if ( m_selected.IsOk() &&
99 m_selected.GetBitmap() &&
100 (brush != *wxTRANSPARENT_BRUSH) )
101 {
102 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
103 }
104
105 wxWindowDCImpl::SetBackground( brush );
106}
107
108void wxMemoryDCImpl::SetTextForeground( const wxColour& col )
109{
110 if ( m_selected.IsOk() && m_selected.GetBitmap() )
111 {
112 wxWindowDCImpl::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
113 }
114 else
115 {
116 wxWindowDCImpl::SetTextForeground( col );
117 }
118}
119
120void wxMemoryDCImpl::SetTextBackground( const wxColour &col )
121{
122 if (m_selected.IsOk() && m_selected.GetBitmap())
123 {
124 wxWindowDCImpl::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
125 }
126 else
127 {
128 wxWindowDCImpl::SetTextBackground( col );
129 }
130}
131
132void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
133{
134 if (m_selected.IsOk())
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}