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