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