]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcmemory.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
6f65e337 | 5 | // RCS-ID: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 | 10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c801d85f KB |
11 | #pragma implementation "dcmemory.h" |
12 | #endif | |
13 | ||
14f355c2 VS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
c801d85f KB |
17 | #include "wx/dcmemory.h" |
18 | ||
071a2d78 RR |
19 | #include <gdk/gdk.h> |
20 | #include <gtk/gtk.h> | |
83624f79 | 21 | |
c801d85f KB |
22 | //----------------------------------------------------------------------------- |
23 | // wxMemoryDC | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
ec758a20 | 26 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC) |
c801d85f | 27 | |
4bc67cc5 | 28 | wxMemoryDC::wxMemoryDC() : wxWindowDC() |
c801d85f | 29 | { |
4bc67cc5 | 30 | m_ok = FALSE; |
72cdf4c9 | 31 | |
4bc67cc5 | 32 | m_cmap = gtk_widget_get_default_colormap(); |
cfcc3932 RR |
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 | |
ff7b1510 | 39 | } |
c801d85f | 40 | |
72cdf4c9 | 41 | wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) ) |
ec758a20 | 42 | : wxWindowDC() |
c801d85f | 43 | { |
4bc67cc5 | 44 | m_ok = FALSE; |
72cdf4c9 | 45 | |
4bc67cc5 | 46 | m_cmap = gtk_widget_get_default_colormap(); |
cfcc3932 RR |
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 | |
ff7b1510 | 53 | } |
c801d85f | 54 | |
4bc67cc5 | 55 | wxMemoryDC::~wxMemoryDC() |
c801d85f | 56 | { |
ff7b1510 | 57 | } |
c801d85f KB |
58 | |
59 | void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) | |
60 | { | |
3d2d8da1 | 61 | Destroy(); |
4bc67cc5 RR |
62 | m_selected = bitmap; |
63 | if (m_selected.Ok()) | |
6f65e337 | 64 | { |
4bc67cc5 RR |
65 | if (m_selected.GetPixmap()) |
66 | { | |
67 | m_window = m_selected.GetPixmap(); | |
68 | } | |
69 | else | |
70 | { | |
71 | m_window = m_selected.GetBitmap(); | |
72 | } | |
72cdf4c9 | 73 | |
7452aff5 VS |
74 | #ifdef __WXGTK20__ |
75 | m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap); | |
76 | #endif | |
77 | ||
4bc67cc5 | 78 | m_isMemDC = TRUE; |
809934d2 RR |
79 | |
80 | SetUpDC(); | |
6f65e337 JS |
81 | } |
82 | else | |
72cdf4c9 | 83 | { |
4bc67cc5 RR |
84 | m_ok = FALSE; |
85 | m_window = (GdkWindow *) NULL; | |
6f65e337 | 86 | } |
ff7b1510 | 87 | } |
c801d85f | 88 | |
8ab40c52 | 89 | void wxMemoryDC::SetPen( const wxPen& penOrig ) |
41fbc841 | 90 | { |
8ab40c52 VZ |
91 | wxPen pen( penOrig ); |
92 | if ( m_selected.Ok() && | |
93 | m_selected.GetBitmap() && | |
94 | (pen != *wxTRANSPARENT_PEN) ) | |
41fbc841 | 95 | { |
8ab40c52 | 96 | pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); |
41fbc841 | 97 | } |
8ab40c52 VZ |
98 | |
99 | wxWindowDC::SetPen( pen ); | |
41fbc841 RR |
100 | } |
101 | ||
8ab40c52 | 102 | void wxMemoryDC::SetBrush( const wxBrush& brushOrig ) |
41fbc841 | 103 | { |
8ab40c52 VZ |
104 | wxBrush brush( brushOrig ); |
105 | if ( m_selected.Ok() && | |
106 | m_selected.GetBitmap() && | |
107 | (brush != *wxTRANSPARENT_BRUSH) ) | |
41fbc841 | 108 | { |
8ab40c52 | 109 | brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE); |
41fbc841 | 110 | } |
8ab40c52 VZ |
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) ) | |
41fbc841 | 122 | { |
8ab40c52 | 123 | brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); |
41fbc841 | 124 | } |
8ab40c52 VZ |
125 | |
126 | wxWindowDC::SetBackground( brush ); | |
41fbc841 RR |
127 | } |
128 | ||
8ab40c52 | 129 | void wxMemoryDC::SetTextForeground( const wxColour& col ) |
41fbc841 | 130 | { |
8ab40c52 | 131 | if ( m_selected.Ok() && m_selected.GetBitmap() ) |
41fbc841 | 132 | { |
8ab40c52 | 133 | wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE); |
41fbc841 RR |
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 | { | |
8ab40c52 | 145 | wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE ); |
41fbc841 RR |
146 | } |
147 | else | |
148 | { | |
149 | wxWindowDC::SetTextBackground( col ); | |
150 | } | |
151 | } | |
152 | ||
4e4ea166 | 153 | void wxMemoryDC::DoGetSize( int *width, int *height ) const |
c801d85f | 154 | { |
4bc67cc5 RR |
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 | } | |
ff7b1510 | 165 | } |
c801d85f KB |
166 | |
167 |