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