]>
Commit | Line | Data |
---|---|---|
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 | #ifdef __WXGTK20__ | |
58 | g_object_unref(m_context); | |
59 | #endif | |
60 | } | |
61 | ||
62 | void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) | |
63 | { | |
64 | Destroy(); | |
65 | m_selected = bitmap; | |
66 | if (m_selected.Ok()) | |
67 | { | |
68 | if (m_selected.GetPixmap()) | |
69 | { | |
70 | m_window = m_selected.GetPixmap(); | |
71 | } | |
72 | else | |
73 | { | |
74 | m_window = m_selected.GetBitmap(); | |
75 | } | |
76 | ||
77 | #ifdef __WXGTK20__ | |
78 | m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap); | |
79 | #endif | |
80 | ||
81 | m_isMemDC = TRUE; | |
82 | ||
83 | SetUpDC(); | |
84 | } | |
85 | else | |
86 | { | |
87 | m_ok = FALSE; | |
88 | m_window = (GdkWindow *) NULL; | |
89 | } | |
90 | } | |
91 | ||
92 | void wxMemoryDC::SetPen( const wxPen& penOrig ) | |
93 | { | |
94 | wxPen pen( penOrig ); | |
95 | if ( m_selected.Ok() && | |
96 | m_selected.GetBitmap() && | |
97 | (pen != *wxTRANSPARENT_PEN) ) | |
98 | { | |
99 | pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); | |
100 | } | |
101 | ||
102 | wxWindowDC::SetPen( pen ); | |
103 | } | |
104 | ||
105 | void wxMemoryDC::SetBrush( const wxBrush& brushOrig ) | |
106 | { | |
107 | wxBrush brush( brushOrig ); | |
108 | if ( m_selected.Ok() && | |
109 | m_selected.GetBitmap() && | |
110 | (brush != *wxTRANSPARENT_BRUSH) ) | |
111 | { | |
112 | brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE); | |
113 | } | |
114 | ||
115 | wxWindowDC::SetBrush( brush ); | |
116 | } | |
117 | ||
118 | void wxMemoryDC::SetBackground( const wxBrush& brushOrig ) | |
119 | { | |
120 | wxBrush brush(brushOrig); | |
121 | ||
122 | if ( m_selected.Ok() && | |
123 | m_selected.GetBitmap() && | |
124 | (brush != *wxTRANSPARENT_BRUSH) ) | |
125 | { | |
126 | brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); | |
127 | } | |
128 | ||
129 | wxWindowDC::SetBackground( brush ); | |
130 | } | |
131 | ||
132 | void wxMemoryDC::SetTextForeground( const wxColour& col ) | |
133 | { | |
134 | if ( m_selected.Ok() && m_selected.GetBitmap() ) | |
135 | { | |
136 | wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE); | |
137 | } | |
138 | else | |
139 | { | |
140 | wxWindowDC::SetTextForeground( col ); | |
141 | } | |
142 | } | |
143 | ||
144 | void wxMemoryDC::SetTextBackground( const wxColour &col ) | |
145 | { | |
146 | if (m_selected.Ok() && m_selected.GetBitmap()) | |
147 | { | |
148 | wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE ); | |
149 | } | |
150 | else | |
151 | { | |
152 | wxWindowDC::SetTextBackground( col ); | |
153 | } | |
154 | } | |
155 | ||
156 | void wxMemoryDC::DoGetSize( int *width, int *height ) const | |
157 | { | |
158 | if (m_selected.Ok()) | |
159 | { | |
160 | if (width) (*width) = m_selected.GetWidth(); | |
161 | if (height) (*height) = m_selected.GetHeight(); | |
162 | } | |
163 | else | |
164 | { | |
165 | if (width) (*width) = 0; | |
166 | if (height) (*height) = 0; | |
167 | } | |
168 | } | |
169 | ||
170 |