]>
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 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
c801d85f KB |
13 | #include "wx/dcmemory.h" |
14 | ||
071a2d78 RR |
15 | #include <gdk/gdk.h> |
16 | #include <gtk/gtk.h> | |
83624f79 | 17 | |
c801d85f KB |
18 | //----------------------------------------------------------------------------- |
19 | // wxMemoryDC | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
ec758a20 | 22 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC) |
c801d85f | 23 | |
4bc67cc5 | 24 | wxMemoryDC::wxMemoryDC() : wxWindowDC() |
c801d85f | 25 | { |
4bc67cc5 | 26 | m_ok = FALSE; |
72cdf4c9 | 27 | |
4bc67cc5 | 28 | m_cmap = gtk_widget_get_default_colormap(); |
3d257b8d | 29 | |
cfcc3932 | 30 | m_context = gdk_pango_context_get(); |
e90d93d1 MW |
31 | // Note: The Sun customised version of Pango shipping with Solaris 10 |
32 | // crashes if the language is left NULL (see bug 1374114) | |
203b65dd | 33 | pango_context_set_language( m_context, gtk_get_default_language() ); |
cfcc3932 RR |
34 | m_layout = pango_layout_new( m_context ); |
35 | m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) ); | |
ff7b1510 | 36 | } |
c801d85f | 37 | |
72cdf4c9 | 38 | wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) ) |
ec758a20 | 39 | : wxWindowDC() |
c801d85f | 40 | { |
4bc67cc5 | 41 | m_ok = FALSE; |
72cdf4c9 | 42 | |
4bc67cc5 | 43 | m_cmap = gtk_widget_get_default_colormap(); |
3d257b8d | 44 | |
cfcc3932 | 45 | m_context = gdk_pango_context_get(); |
203b65dd | 46 | pango_context_set_language( m_context, gtk_get_default_language() ); |
cfcc3932 RR |
47 | m_layout = pango_layout_new( m_context ); |
48 | m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) ); | |
ff7b1510 | 49 | } |
c801d85f | 50 | |
4bc67cc5 | 51 | wxMemoryDC::~wxMemoryDC() |
c801d85f | 52 | { |
42c60e74 | 53 | g_object_unref(m_context); |
ff7b1510 | 54 | } |
c801d85f KB |
55 | |
56 | void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) | |
57 | { | |
3d2d8da1 | 58 | Destroy(); |
4bc67cc5 RR |
59 | m_selected = bitmap; |
60 | if (m_selected.Ok()) | |
6f65e337 | 61 | { |
4bc67cc5 RR |
62 | if (m_selected.GetPixmap()) |
63 | { | |
64 | m_window = m_selected.GetPixmap(); | |
65 | } | |
66 | else | |
67 | { | |
68 | m_window = m_selected.GetBitmap(); | |
69 | } | |
72cdf4c9 | 70 | |
7452aff5 | 71 | m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap); |
7452aff5 | 72 | |
4bc67cc5 | 73 | m_isMemDC = TRUE; |
809934d2 RR |
74 | |
75 | SetUpDC(); | |
6f65e337 JS |
76 | } |
77 | else | |
72cdf4c9 | 78 | { |
4bc67cc5 RR |
79 | m_ok = FALSE; |
80 | m_window = (GdkWindow *) NULL; | |
6f65e337 | 81 | } |
ff7b1510 | 82 | } |
c801d85f | 83 | |
8ab40c52 | 84 | void wxMemoryDC::SetPen( const wxPen& penOrig ) |
41fbc841 | 85 | { |
8ab40c52 VZ |
86 | wxPen pen( penOrig ); |
87 | if ( m_selected.Ok() && | |
88 | m_selected.GetBitmap() && | |
89 | (pen != *wxTRANSPARENT_PEN) ) | |
41fbc841 | 90 | { |
8ab40c52 | 91 | pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); |
41fbc841 | 92 | } |
8ab40c52 VZ |
93 | |
94 | wxWindowDC::SetPen( pen ); | |
41fbc841 RR |
95 | } |
96 | ||
8ab40c52 | 97 | void wxMemoryDC::SetBrush( const wxBrush& brushOrig ) |
41fbc841 | 98 | { |
8ab40c52 VZ |
99 | wxBrush brush( brushOrig ); |
100 | if ( m_selected.Ok() && | |
101 | m_selected.GetBitmap() && | |
102 | (brush != *wxTRANSPARENT_BRUSH) ) | |
41fbc841 | 103 | { |
8ab40c52 | 104 | brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE); |
41fbc841 | 105 | } |
8ab40c52 VZ |
106 | |
107 | wxWindowDC::SetBrush( brush ); | |
108 | } | |
109 | ||
3d257b8d | 110 | void wxMemoryDC::SetBackground( const wxBrush& brushOrig ) |
8ab40c52 VZ |
111 | { |
112 | wxBrush brush(brushOrig); | |
113 | ||
114 | if ( m_selected.Ok() && | |
115 | m_selected.GetBitmap() && | |
116 | (brush != *wxTRANSPARENT_BRUSH) ) | |
41fbc841 | 117 | { |
8ab40c52 | 118 | brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); |
41fbc841 | 119 | } |
8ab40c52 VZ |
120 | |
121 | wxWindowDC::SetBackground( brush ); | |
41fbc841 RR |
122 | } |
123 | ||
8ab40c52 | 124 | void wxMemoryDC::SetTextForeground( const wxColour& col ) |
41fbc841 | 125 | { |
8ab40c52 | 126 | if ( m_selected.Ok() && m_selected.GetBitmap() ) |
41fbc841 | 127 | { |
8ab40c52 | 128 | wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE); |
41fbc841 RR |
129 | } |
130 | else | |
131 | { | |
132 | wxWindowDC::SetTextForeground( col ); | |
133 | } | |
134 | } | |
135 | ||
136 | void wxMemoryDC::SetTextBackground( const wxColour &col ) | |
137 | { | |
138 | if (m_selected.Ok() && m_selected.GetBitmap()) | |
139 | { | |
8ab40c52 | 140 | wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE ); |
41fbc841 RR |
141 | } |
142 | else | |
143 | { | |
144 | wxWindowDC::SetTextBackground( col ); | |
145 | } | |
146 | } | |
147 | ||
4e4ea166 | 148 | void wxMemoryDC::DoGetSize( int *width, int *height ) const |
c801d85f | 149 | { |
4bc67cc5 RR |
150 | if (m_selected.Ok()) |
151 | { | |
152 | if (width) (*width) = m_selected.GetWidth(); | |
153 | if (height) (*height) = m_selected.GetHeight(); | |
154 | } | |
155 | else | |
156 | { | |
157 | if (width) (*width) = 0; | |
158 | if (height) (*height) = 0; | |
159 | } | |
ff7b1510 | 160 | } |
c801d85f KB |
161 | |
162 |