]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dcmemory.cpp
Option for variable line heights (MSW and GTK+ sofar)
[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 #include "wx/gtk/dcmemory.h"
15
16 #include <gdk/gdk.h>
17 #include <gtk/gtk.h>
18
19 //-----------------------------------------------------------------------------
20 // wxMemoryDCImpl
21 //-----------------------------------------------------------------------------
22
23 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxWindowDCImpl)
24
25 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
26 : wxWindowDCImpl( owner )
27 {
28 Init();
29 }
30
31 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap)
32 : wxWindowDCImpl( owner )
33 {
34 Init();
35 DoSelect(bitmap);
36 }
37
38 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC *WXUNUSED(dc) )
39 : wxWindowDCImpl( owner )
40 {
41 Init();
42 }
43
44 wxMemoryDCImpl::~wxMemoryDCImpl()
45 {
46 g_object_unref(m_context);
47 }
48
49 void wxMemoryDCImpl::Init()
50 {
51 m_ok = false;
52
53 m_cmap = gtk_widget_get_default_colormap();
54
55 m_context = gdk_pango_context_get();
56 // Note: The Sun customised version of Pango shipping with Solaris 10
57 // crashes if the language is left NULL (see bug 1374114)
58 pango_context_set_language( m_context, gtk_get_default_language() );
59 m_layout = pango_layout_new( m_context );
60 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
61 }
62
63 void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
64 {
65 Destroy();
66
67 m_selected = bitmap;
68 if (m_selected.Ok())
69 {
70 m_gdkwindow = m_selected.GetPixmap();
71
72 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
73
74 SetUpDC( true );
75 }
76 else
77 {
78 m_ok = false;
79 m_gdkwindow = (GdkWindow *) NULL;
80 }
81 }
82
83 void wxMemoryDCImpl::SetPen( const wxPen& penOrig )
84 {
85 wxPen pen( penOrig );
86 if ( m_selected.Ok() &&
87 m_selected.GetDepth() == 1 &&
88 (pen != *wxTRANSPARENT_PEN) )
89 {
90 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
91 }
92
93 wxWindowDCImpl::SetPen( pen );
94 }
95
96 void wxMemoryDCImpl::SetBrush( const wxBrush& brushOrig )
97 {
98 wxBrush brush( brushOrig );
99 if ( m_selected.Ok() &&
100 m_selected.GetDepth() == 1 &&
101 (brush != *wxTRANSPARENT_BRUSH) )
102 {
103 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
104 }
105
106 wxWindowDCImpl::SetBrush( brush );
107 }
108
109 void wxMemoryDCImpl::SetBackground( const wxBrush& brushOrig )
110 {
111 wxBrush brush(brushOrig);
112
113 if ( m_selected.Ok() &&
114 m_selected.GetDepth() == 1 &&
115 (brush != *wxTRANSPARENT_BRUSH) )
116 {
117 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
118 }
119
120 wxWindowDCImpl::SetBackground( brush );
121 }
122
123 void wxMemoryDCImpl::SetTextForeground( const wxColour& col )
124 {
125 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
126 wxWindowDCImpl::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
127 else
128 wxWindowDCImpl::SetTextForeground( col );
129 }
130
131 void wxMemoryDCImpl::SetTextBackground( const wxColour &col )
132 {
133 if (m_selected.Ok() && m_selected.GetDepth() == 1)
134 wxWindowDCImpl::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
135 else
136 wxWindowDCImpl::SetTextBackground( col );
137 }
138
139 void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
140 {
141 if (m_selected.Ok())
142 {
143 if (width) (*width) = m_selected.GetWidth();
144 if (height) (*height) = m_selected.GetHeight();
145 }
146 else
147 {
148 if (width) (*width) = 0;
149 if (height) (*height) = 0;
150 }
151 }
152
153 wxBitmap wxMemoryDCImpl::DoGetAsBitmap(const wxRect *subrect) const
154 {
155 wxBitmap bmp = GetSelectedBitmap();
156 return subrect ? bmp.GetSubBitmap(*subrect) : bmp;
157 }
158
159 const wxBitmap& wxMemoryDCImpl::GetSelectedBitmap() const
160 {
161 return m_selected;
162 }
163
164 wxBitmap& wxMemoryDCImpl::GetSelectedBitmap()
165 {
166 return m_selected;
167 }
168