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