]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dcmemory.cpp
Separated out book control sizing code
[wxWidgets.git] / src / gtk / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 wxMemoryDC::wxMemoryDC() : wxWindowDC()
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 m_ok = FALSE;
42
43 m_cmap = gtk_widget_get_default_colormap();
44
45 m_context = gdk_pango_context_get();
46 pango_context_set_language( m_context, gtk_get_default_language() );
47 m_layout = pango_layout_new( m_context );
48 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
49 }
50
51 wxMemoryDC::~wxMemoryDC()
52 {
53 g_object_unref(m_context);
54 }
55
56 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
57 {
58 Destroy();
59 m_selected = bitmap;
60 if (m_selected.Ok())
61 {
62 if (m_selected.GetPixmap())
63 {
64 m_window = m_selected.GetPixmap();
65 }
66 else
67 {
68 m_window = m_selected.GetBitmap();
69 }
70
71 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
72
73 m_isMemDC = TRUE;
74
75 SetUpDC();
76 }
77 else
78 {
79 m_ok = FALSE;
80 m_window = (GdkWindow *) NULL;
81 }
82 }
83
84 void wxMemoryDC::SetPen( const wxPen& penOrig )
85 {
86 wxPen pen( penOrig );
87 if ( m_selected.Ok() &&
88 m_selected.GetBitmap() &&
89 (pen != *wxTRANSPARENT_PEN) )
90 {
91 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
92 }
93
94 wxWindowDC::SetPen( pen );
95 }
96
97 void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
98 {
99 wxBrush brush( brushOrig );
100 if ( m_selected.Ok() &&
101 m_selected.GetBitmap() &&
102 (brush != *wxTRANSPARENT_BRUSH) )
103 {
104 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
105 }
106
107 wxWindowDC::SetBrush( brush );
108 }
109
110 void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
111 {
112 wxBrush brush(brushOrig);
113
114 if ( m_selected.Ok() &&
115 m_selected.GetBitmap() &&
116 (brush != *wxTRANSPARENT_BRUSH) )
117 {
118 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
119 }
120
121 wxWindowDC::SetBackground( brush );
122 }
123
124 void wxMemoryDC::SetTextForeground( const wxColour& col )
125 {
126 if ( m_selected.Ok() && m_selected.GetBitmap() )
127 {
128 wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
129 }
130 else
131 {
132 wxWindowDC::SetTextForeground( col );
133 }
134 }
135
136 void wxMemoryDC::SetTextBackground( const wxColour &col )
137 {
138 if (m_selected.Ok() && m_selected.GetBitmap())
139 {
140 wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
141 }
142 else
143 {
144 wxWindowDC::SetTextBackground( col );
145 }
146 }
147
148 void wxMemoryDC::DoGetSize( int *width, int *height ) const
149 {
150 if (m_selected.Ok())
151 {
152 if (width) (*width) = m_selected.GetWidth();
153 if (height) (*height) = m_selected.GetHeight();
154 }
155 else
156 {
157 if (width) (*width) = 0;
158 if (height) (*height) = 0;
159 }
160 }
161
162