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