]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcmemory.cpp
[ 1577675 ] Fix for GTK warnings in wxNotebook::DoRemovePage
[wxWidgets.git] / src / gtk / dcmemory.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
f38924e8 2// Name: src/gtk/dcmemory.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
6f65e337 5// RCS-ID: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f
KB
13#include "wx/dcmemory.h"
14
071a2d78
RR
15#include <gdk/gdk.h>
16#include <gtk/gtk.h>
83624f79 17
c801d85f
KB
18//-----------------------------------------------------------------------------
19// wxMemoryDC
20//-----------------------------------------------------------------------------
21
ec758a20 22IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC)
c801d85f 23
432efcb0
RD
24wxMemoryDC::wxMemoryDC( const wxBitmap& bitmap )
25 : wxWindowDC()
c801d85f 26{
f38924e8 27 m_ok = false;
72cdf4c9 28
4bc67cc5 29 m_cmap = gtk_widget_get_default_colormap();
3d257b8d 30
cfcc3932 31 m_context = gdk_pango_context_get();
e90d93d1
MW
32 // Note: The Sun customised version of Pango shipping with Solaris 10
33 // crashes if the language is left NULL (see bug 1374114)
203b65dd 34 pango_context_set_language( m_context, gtk_get_default_language() );
cfcc3932
RR
35 m_layout = pango_layout_new( m_context );
36 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
432efcb0
RD
37
38 if ( bitmap.IsOk() )
39 SelectObject(bitmap);
ff7b1510 40}
c801d85f 41
72cdf4c9 42wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
ec758a20 43 : wxWindowDC()
c801d85f 44{
f38924e8 45 m_ok = false;
72cdf4c9 46
4bc67cc5 47 m_cmap = gtk_widget_get_default_colormap();
3d257b8d 48
cfcc3932 49 m_context = gdk_pango_context_get();
203b65dd 50 pango_context_set_language( m_context, gtk_get_default_language() );
cfcc3932
RR
51 m_layout = pango_layout_new( m_context );
52 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
ff7b1510 53}
c801d85f 54
4bc67cc5 55wxMemoryDC::~wxMemoryDC()
c801d85f 56{
42c60e74 57 g_object_unref(m_context);
ff7b1510 58}
c801d85f
KB
59
60void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
61{
3d2d8da1 62 Destroy();
4bc67cc5
RR
63 m_selected = bitmap;
64 if (m_selected.Ok())
6f65e337 65 {
b85229d1 66 m_window = m_selected.GetPixmap();
72cdf4c9 67
7452aff5 68 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
7452aff5 69
f38924e8 70 m_isMemDC = true;
809934d2
RR
71
72 SetUpDC();
6f65e337
JS
73 }
74 else
72cdf4c9 75 {
f38924e8 76 m_ok = false;
4bc67cc5 77 m_window = (GdkWindow *) NULL;
6f65e337 78 }
ff7b1510 79}
c801d85f 80
8ab40c52 81void wxMemoryDC::SetPen( const wxPen& penOrig )
41fbc841 82{
8ab40c52
VZ
83 wxPen pen( penOrig );
84 if ( m_selected.Ok() &&
b85229d1 85 m_selected.GetDepth() == 1 &&
8ab40c52 86 (pen != *wxTRANSPARENT_PEN) )
41fbc841 87 {
8ab40c52 88 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 89 }
8ab40c52
VZ
90
91 wxWindowDC::SetPen( pen );
41fbc841
RR
92}
93
8ab40c52 94void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
41fbc841 95{
8ab40c52
VZ
96 wxBrush brush( brushOrig );
97 if ( m_selected.Ok() &&
b85229d1 98 m_selected.GetDepth() == 1 &&
8ab40c52 99 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 100 {
8ab40c52 101 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 102 }
8ab40c52
VZ
103
104 wxWindowDC::SetBrush( brush );
105}
106
3d257b8d 107void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
8ab40c52
VZ
108{
109 wxBrush brush(brushOrig);
110
111 if ( m_selected.Ok() &&
b85229d1 112 m_selected.GetDepth() == 1 &&
8ab40c52 113 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 114 {
8ab40c52 115 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 116 }
8ab40c52
VZ
117
118 wxWindowDC::SetBackground( brush );
41fbc841
RR
119}
120
8ab40c52 121void wxMemoryDC::SetTextForeground( const wxColour& col )
41fbc841 122{
b85229d1 123 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
41fbc841 124 {
8ab40c52 125 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841
RR
126 }
127 else
128 {
129 wxWindowDC::SetTextForeground( col );
130 }
131}
132
133void wxMemoryDC::SetTextBackground( const wxColour &col )
134{
b85229d1 135 if (m_selected.Ok() && m_selected.GetDepth() == 1)
41fbc841 136 {
8ab40c52 137 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841
RR
138 }
139 else
140 {
141 wxWindowDC::SetTextBackground( col );
142 }
143}
144
4e4ea166 145void wxMemoryDC::DoGetSize( int *width, int *height ) const
c801d85f 146{
4bc67cc5
RR
147 if (m_selected.Ok())
148 {
149 if (width) (*width) = m_selected.GetWidth();
150 if (height) (*height) = m_selected.GetHeight();
151 }
152 else
153 {
154 if (width) (*width) = 0;
155 if (height) (*height) = 0;
156 }
ff7b1510 157}