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