]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/dcmemory.cpp
Second part of #15224 fix: AddRows, AddColumns (dghart)
[wxWidgets.git] / src / gtk / dcmemory.cpp
... / ...
CommitLineData
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
20IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxWindowDCImpl)
21
22wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
23 : wxWindowDCImpl( owner )
24{
25 Init();
26}
27
28wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap)
29 : wxWindowDCImpl( owner )
30{
31 Init();
32 DoSelect(bitmap);
33}
34
35wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC *WXUNUSED(dc) )
36 : wxWindowDCImpl( owner )
37{
38 Init();
39}
40
41wxMemoryDCImpl::~wxMemoryDCImpl()
42{
43 g_object_unref(m_context);
44}
45
46void 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
60void 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
80void 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
93void 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
106void 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
120void 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
128void 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
136void 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
150wxBitmap wxMemoryDCImpl::DoGetAsBitmap(const wxRect *subrect) const
151{
152 wxBitmap bmp = GetSelectedBitmap();
153 return subrect ? bmp.GetSubBitmap(*subrect) : bmp;
154}
155
156const wxBitmap& wxMemoryDCImpl::GetSelectedBitmap() const
157{
158 return m_selected;
159}
160
161wxBitmap& wxMemoryDCImpl::GetSelectedBitmap()
162{
163 return m_selected;
164}
165
166void* wxMemoryDCImpl::GetHandle() const
167{
168 const wxBitmap& bmp = GetSelectedBitmap();
169 return bmp.GetPixmap();
170}