]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dcmemory.cpp
Sometimes, m_x and m_y don't reflect the true position of the window,
[wxWidgets.git] / src / gtk / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/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() : wxWindowDC()
25 {
26 m_ok = false;
27
28 m_cmap = gtk_widget_get_default_colormap();
29
30 m_context = gdk_pango_context_get();
31 // Note: The Sun customised version of Pango shipping with Solaris 10
32 // crashes if the language is left NULL (see bug 1374114)
33 pango_context_set_language( m_context, gtk_get_default_language() );
34 m_layout = pango_layout_new( m_context );
35 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
36 }
37
38 wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
39 : wxWindowDC()
40 {
41 m_ok = false;
42
43 m_cmap = gtk_widget_get_default_colormap();
44
45 m_context = gdk_pango_context_get();
46 pango_context_set_language( m_context, gtk_get_default_language() );
47 m_layout = pango_layout_new( m_context );
48 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
49 }
50
51 wxMemoryDC::~wxMemoryDC()
52 {
53 g_object_unref(m_context);
54 }
55
56 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
57 {
58 Destroy();
59 m_selected = bitmap;
60 if (m_selected.Ok())
61 {
62 m_window = m_selected.GetPixmap();
63
64 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
65
66 m_isMemDC = true;
67
68 SetUpDC();
69 }
70 else
71 {
72 m_ok = false;
73 m_window = (GdkWindow *) NULL;
74 }
75 }
76
77 void wxMemoryDC::SetPen( const wxPen& penOrig )
78 {
79 wxPen pen( penOrig );
80 if ( m_selected.Ok() &&
81 m_selected.GetDepth() == 1 &&
82 (pen != *wxTRANSPARENT_PEN) )
83 {
84 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
85 }
86
87 wxWindowDC::SetPen( pen );
88 }
89
90 void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
91 {
92 wxBrush brush( brushOrig );
93 if ( m_selected.Ok() &&
94 m_selected.GetDepth() == 1 &&
95 (brush != *wxTRANSPARENT_BRUSH) )
96 {
97 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
98 }
99
100 wxWindowDC::SetBrush( brush );
101 }
102
103 void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
104 {
105 wxBrush brush(brushOrig);
106
107 if ( m_selected.Ok() &&
108 m_selected.GetDepth() == 1 &&
109 (brush != *wxTRANSPARENT_BRUSH) )
110 {
111 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
112 }
113
114 wxWindowDC::SetBackground( brush );
115 }
116
117 void wxMemoryDC::SetTextForeground( const wxColour& col )
118 {
119 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
120 {
121 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
122 }
123 else
124 {
125 wxWindowDC::SetTextForeground( col );
126 }
127 }
128
129 void wxMemoryDC::SetTextBackground( const wxColour &col )
130 {
131 if (m_selected.Ok() && m_selected.GetDepth() == 1)
132 {
133 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
134 }
135 else
136 {
137 wxWindowDC::SetTextBackground( col );
138 }
139 }
140
141 void wxMemoryDC::DoGetSize( int *width, int *height ) const
142 {
143 if (m_selected.Ok())
144 {
145 if (width) (*width) = m_selected.GetWidth();
146 if (height) (*height) = m_selected.GetHeight();
147 }
148 else
149 {
150 if (width) (*width) = 0;
151 if (height) (*height) = 0;
152 }
153 }