]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcmemory.cpp
Work around missing mode_t definition with ICC.
[wxWidgets.git] / src / gtk / dcmemory.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
f38924e8 2// Name: src/gtk/dcmemory.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
01111366 5// Copyright: (c) 1998 Robert Roebling
65571936 6// Licence: wxWindows licence
c801d85f
KB
7/////////////////////////////////////////////////////////////////////////////
8
14f355c2
VS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
11
888dde65 12#include "wx/gtk/dcmemory.h"
c801d85f 13
071a2d78 14#include <gtk/gtk.h>
83624f79 15
c801d85f 16//-----------------------------------------------------------------------------
888dde65 17// wxMemoryDCImpl
c801d85f
KB
18//-----------------------------------------------------------------------------
19
888dde65 20IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxWindowDCImpl)
ab171e95 21
03647350 22wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
888dde65 23 : wxWindowDCImpl( owner )
03647350
VZ
24{
25 Init();
ab171e95 26}
c801d85f 27
03647350 28wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap)
888dde65 29 : wxWindowDCImpl( owner )
03647350
VZ
30{
31 Init();
32 DoSelect(bitmap);
ab171e95 33}
72cdf4c9 34
888dde65
RR
35wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC *WXUNUSED(dc) )
36 : wxWindowDCImpl( owner )
ab171e95
RR
37{
38 Init();
39}
c801d85f 40
888dde65 41wxMemoryDCImpl::~wxMemoryDCImpl()
c801d85f 42{
42c60e74 43 g_object_unref(m_context);
ff7b1510 44}
c801d85f 45
888dde65 46void wxMemoryDCImpl::Init()
ab171e95
RR
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
888dde65 60void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
c801d85f 61{
3d2d8da1 62 Destroy();
fea35690 63
4bc67cc5 64 m_selected = bitmap;
a1b806b9 65 if (m_selected.IsOk())
6f65e337 66 {
888dde65 67 m_gdkwindow = m_selected.GetPixmap();
72cdf4c9 68
7452aff5 69 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
7452aff5 70
ab171e95 71 SetUpDC( true );
6f65e337
JS
72 }
73 else
72cdf4c9 74 {
f38924e8 75 m_ok = false;
d3b9f782 76 m_gdkwindow = NULL;
6f65e337 77 }
ff7b1510 78}
c801d85f 79
888dde65 80void wxMemoryDCImpl::SetPen( const wxPen& penOrig )
41fbc841 81{
8ab40c52 82 wxPen pen( penOrig );
a1b806b9 83 if ( m_selected.IsOk() &&
b85229d1 84 m_selected.GetDepth() == 1 &&
8ab40c52 85 (pen != *wxTRANSPARENT_PEN) )
41fbc841 86 {
8ab40c52 87 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 88 }
8ab40c52 89
888dde65 90 wxWindowDCImpl::SetPen( pen );
41fbc841
RR
91}
92
888dde65 93void wxMemoryDCImpl::SetBrush( const wxBrush& brushOrig )
41fbc841 94{
8ab40c52 95 wxBrush brush( brushOrig );
a1b806b9 96 if ( m_selected.IsOk() &&
b85229d1 97 m_selected.GetDepth() == 1 &&
8ab40c52 98 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 99 {
8ab40c52 100 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 101 }
8ab40c52 102
888dde65 103 wxWindowDCImpl::SetBrush( brush );
8ab40c52
VZ
104}
105
888dde65 106void wxMemoryDCImpl::SetBackground( const wxBrush& brushOrig )
8ab40c52
VZ
107{
108 wxBrush brush(brushOrig);
109
a1b806b9 110 if ( m_selected.IsOk() &&
b85229d1 111 m_selected.GetDepth() == 1 &&
8ab40c52 112 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 113 {
8ab40c52 114 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 115 }
8ab40c52 116
888dde65 117 wxWindowDCImpl::SetBackground( brush );
41fbc841
RR
118}
119
888dde65 120void wxMemoryDCImpl::SetTextForeground( const wxColour& col )
41fbc841 121{
a1b806b9 122 if ( m_selected.IsOk() && m_selected.GetDepth() == 1 )
888dde65 123 wxWindowDCImpl::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 124 else
888dde65 125 wxWindowDCImpl::SetTextForeground( col );
41fbc841
RR
126}
127
888dde65 128void wxMemoryDCImpl::SetTextBackground( const wxColour &col )
41fbc841 129{
a1b806b9 130 if (m_selected.IsOk() && m_selected.GetDepth() == 1)
888dde65 131 wxWindowDCImpl::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 132 else
888dde65 133 wxWindowDCImpl::SetTextBackground( col );
41fbc841
RR
134}
135
888dde65 136void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
c801d85f 137{
a1b806b9 138 if (m_selected.IsOk())
4bc67cc5
RR
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 }
ff7b1510 148}
ab171e95 149
888dde65 150wxBitmap wxMemoryDCImpl::DoGetAsBitmap(const wxRect *subrect) const
ab171e95
RR
151{
152 wxBitmap bmp = GetSelectedBitmap();
153 return subrect ? bmp.GetSubBitmap(*subrect) : bmp;
154}
155
888dde65 156const wxBitmap& wxMemoryDCImpl::GetSelectedBitmap() const
ab171e95
RR
157{
158 return m_selected;
159}
160
888dde65 161wxBitmap& wxMemoryDCImpl::GetSelectedBitmap()
ab171e95
RR
162{
163 return m_selected;
164}
165
8e72f2cd
RD
166void* wxMemoryDCImpl::GetHandle() const
167{
168 const wxBitmap& bmp = GetSelectedBitmap();
169 return bmp.GetPixmap();
170}