]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcmemory.cpp
Upport hint window improvement using custom GTK+ code
[wxWidgets.git] / src / gtk / dcmemory.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
f38924e8 2// Name: src/gtk/dcmemory.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
6f65e337 5// RCS-ID: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f
KB
13#include "wx/dcmemory.h"
14
071a2d78
RR
15#include <gdk/gdk.h>
16#include <gtk/gtk.h>
83624f79 17
c801d85f
KB
18//-----------------------------------------------------------------------------
19// wxMemoryDC
20//-----------------------------------------------------------------------------
21
ab171e95
RR
22#if wxUSE_NEW_DC
23IMPLEMENT_ABSTRACT_CLASS(wxGTKMemoryImplDC, wxGTKWindowImplDC)
24#else
25IMPLEMENT_ABSTRACT_CLASS(wxMemoryDC,wxWindowDC)
26#endif
27
28#if wxUSE_NEW_DC
29wxGTKMemoryImplDC::wxGTKMemoryImplDC( wxMemoryDC *owner )
30 : wxGTKWindowImplDC( owner )
31{
32 Init();
33}
c801d85f 34
ab171e95
RR
35wxGTKMemoryImplDC::wxGTKMemoryImplDC( wxMemoryDC *owner, wxBitmap& bitmap)
36 : wxGTKWindowImplDC( owner )
37{
38 Init();
39 owner->SelectObject(bitmap);
40}
72cdf4c9 41
ab171e95
RR
42wxGTKMemoryImplDC::wxGTKMemoryImplDC( wxMemoryDC *owner, wxDC *WXUNUSED(dc) )
43 : wxGTKWindowImplDC( owner )
44{
45 Init();
46}
47#else
48wxMemoryDC::wxMemoryDC()
49{
50 Init();
51}
3d257b8d 52
ab171e95
RR
53wxMemoryDC::wxMemoryDC(wxBitmap& bitmap)
54{
55 Init();
56 SelectObject(bitmap);
ff7b1510 57}
c801d85f 58
72cdf4c9 59wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
ec758a20 60 : wxWindowDC()
c801d85f 61{
fea35690 62 Init();
ff7b1510 63}
ab171e95 64#endif
c801d85f 65
ab171e95 66wxGTKMemoryImplDC::~wxGTKMemoryImplDC()
c801d85f 67{
42c60e74 68 g_object_unref(m_context);
ff7b1510 69}
c801d85f 70
ab171e95
RR
71void wxGTKMemoryImplDC::Init()
72{
73 m_ok = false;
74
75 m_cmap = gtk_widget_get_default_colormap();
76
77 m_context = gdk_pango_context_get();
78 // Note: The Sun customised version of Pango shipping with Solaris 10
79 // crashes if the language is left NULL (see bug 1374114)
80 pango_context_set_language( m_context, gtk_get_default_language() );
81 m_layout = pango_layout_new( m_context );
82 m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) );
83}
84
85void wxGTKMemoryImplDC::DoSelect( const wxBitmap& bitmap )
c801d85f 86{
3d2d8da1 87 Destroy();
fea35690 88
4bc67cc5
RR
89 m_selected = bitmap;
90 if (m_selected.Ok())
6f65e337 91 {
b85229d1 92 m_window = m_selected.GetPixmap();
72cdf4c9 93
7452aff5 94 m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
7452aff5 95
ab171e95 96 SetUpDC( true );
6f65e337
JS
97 }
98 else
72cdf4c9 99 {
f38924e8 100 m_ok = false;
4bc67cc5 101 m_window = (GdkWindow *) NULL;
6f65e337 102 }
ff7b1510 103}
c801d85f 104
ab171e95 105void wxGTKMemoryImplDC::SetPen( const wxPen& penOrig )
41fbc841 106{
8ab40c52
VZ
107 wxPen pen( penOrig );
108 if ( m_selected.Ok() &&
b85229d1 109 m_selected.GetDepth() == 1 &&
8ab40c52 110 (pen != *wxTRANSPARENT_PEN) )
41fbc841 111 {
8ab40c52 112 pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 113 }
8ab40c52 114
ab171e95 115 wxGTKWindowImplDC::SetPen( pen );
41fbc841
RR
116}
117
ab171e95 118void wxGTKMemoryImplDC::SetBrush( const wxBrush& brushOrig )
41fbc841 119{
8ab40c52
VZ
120 wxBrush brush( brushOrig );
121 if ( m_selected.Ok() &&
b85229d1 122 m_selected.GetDepth() == 1 &&
8ab40c52 123 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 124 {
8ab40c52 125 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841 126 }
8ab40c52 127
ab171e95 128 wxGTKWindowImplDC::SetBrush( brush );
8ab40c52
VZ
129}
130
ab171e95 131void wxGTKMemoryImplDC::SetBackground( const wxBrush& brushOrig )
8ab40c52
VZ
132{
133 wxBrush brush(brushOrig);
134
135 if ( m_selected.Ok() &&
b85229d1 136 m_selected.GetDepth() == 1 &&
8ab40c52 137 (brush != *wxTRANSPARENT_BRUSH) )
41fbc841 138 {
8ab40c52 139 brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841 140 }
8ab40c52 141
ab171e95 142 wxGTKWindowImplDC::SetBackground( brush );
41fbc841
RR
143}
144
ab171e95 145void wxGTKMemoryImplDC::SetTextForeground( const wxColour& col )
41fbc841 146{
b85229d1 147 if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
41fbc841 148 {
ab171e95 149 wxGTKWindowImplDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
41fbc841
RR
150 }
151 else
152 {
ab171e95 153 wxGTKWindowImplDC::SetTextForeground( col );
41fbc841
RR
154 }
155}
156
ab171e95 157void wxGTKMemoryImplDC::SetTextBackground( const wxColour &col )
41fbc841 158{
b85229d1 159 if (m_selected.Ok() && m_selected.GetDepth() == 1)
41fbc841 160 {
ab171e95 161 wxGTKWindowImplDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
41fbc841
RR
162 }
163 else
164 {
ab171e95 165 wxGTKWindowImplDC::SetTextBackground( col );
41fbc841
RR
166 }
167}
168
ab171e95 169void wxGTKMemoryImplDC::DoGetSize( int *width, int *height ) const
c801d85f 170{
4bc67cc5
RR
171 if (m_selected.Ok())
172 {
173 if (width) (*width) = m_selected.GetWidth();
174 if (height) (*height) = m_selected.GetHeight();
175 }
176 else
177 {
178 if (width) (*width) = 0;
179 if (height) (*height) = 0;
180 }
ff7b1510 181}
ab171e95
RR
182
183wxBitmap wxGTKMemoryImplDC::DoGetAsBitmap(const wxRect *subrect) const
184{
185 wxBitmap bmp = GetSelectedBitmap();
186 return subrect ? bmp.GetSubBitmap(*subrect) : bmp;
187}
188
189const wxBitmap& wxGTKMemoryImplDC::DoGetSelectedBitmap() const
190{
191 return m_selected;
192}
193
194wxBitmap& wxGTKMemoryImplDC::DoGetSelectedBitmap()
195{
196 return m_selected;
197}
198