]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/gtk/dcclient.cpp |
6de4336e | 3 | // Purpose: wxWindowDCImpl implementation |
c801d85f | 4 | // Author: Robert Roebling |
6c9a19aa | 5 | // Copyright: (c) 1998 Robert Roebling, Chris Breeze |
65571936 | 6 | // Licence: wxWindows licence |
c801d85f KB |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
14f355c2 VS |
9 | // For compilers that support precompilation, includes "wx.h". |
10 | #include "wx/wxprec.h" | |
11 | ||
d6afc2c8 | 12 | #include "wx/gtk/dcclient.h" |
e4db172a WS |
13 | |
14 | #ifndef WX_PRECOMP | |
772b3767 | 15 | #include "wx/window.h" |
e4db172a | 16 | #include "wx/log.h" |
f38924e8 | 17 | #include "wx/dcmemory.h" |
d6afc2c8 | 18 | #include "wx/math.h" |
155ecd4c | 19 | #include "wx/image.h" |
02761f6c | 20 | #include "wx/module.h" |
e4db172a WS |
21 | #endif |
22 | ||
db16cab4 | 23 | #include "wx/fontutil.h" |
e5131165 | 24 | |
a3669332 | 25 | #include "wx/gtk/private.h" |
f3d74739 | 26 | #include "wx/gtk/private/object.h" |
8cd79b7a | 27 | #include "wx/private/textmeasure.h" |
c801d85f | 28 | |
809934d2 RR |
29 | //----------------------------------------------------------------------------- |
30 | // local defines | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
eb7637b5 RR |
33 | #define XLOG2DEV(x) LogicalToDeviceX(x) |
34 | #define XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
35 | #define YLOG2DEV(y) LogicalToDeviceY(y) | |
36 | #define YLOG2DEVREL(y) LogicalToDeviceYRel(y) | |
37 | ||
e1208c31 | 38 | #define USE_PAINT_REGION 1 |
809934d2 | 39 | |
c801d85f KB |
40 | //----------------------------------------------------------------------------- |
41 | // local data | |
42 | //----------------------------------------------------------------------------- | |
43 | ||
44 | #include "bdiag.xbm" | |
45 | #include "fdiag.xbm" | |
46 | #include "cdiag.xbm" | |
47 | #include "horiz.xbm" | |
48 | #include "verti.xbm" | |
49 | #include "cross.xbm" | |
c801d85f | 50 | |
04ee05f9 | 51 | static GdkPixmap* hatches[wxBRUSHSTYLE_LAST_HATCH - wxBRUSHSTYLE_FIRST_HATCH + 1]; |
c801d85f KB |
52 | |
53 | //----------------------------------------------------------------------------- | |
54 | // constants | |
55 | //----------------------------------------------------------------------------- | |
56 | ||
d6afc2c8 | 57 | static const double RAD2DEG = 180.0 / M_PI; |
c801d85f | 58 | |
9a8c7620 VZ |
59 | // ---------------------------------------------------------------------------- |
60 | // private functions | |
61 | // ---------------------------------------------------------------------------- | |
62 | ||
63 | static inline double dmax(double a, double b) { return a > b ? a : b; } | |
64 | static inline double dmin(double a, double b) { return a < b ? a : b; } | |
65 | ||
f7732fa5 PC |
66 | static GdkPixmap* GetHatch(int style) |
67 | { | |
04ee05f9 PC |
68 | wxASSERT(style >= wxBRUSHSTYLE_FIRST_HATCH && style <= wxBRUSHSTYLE_LAST_HATCH); |
69 | const int i = style - wxBRUSHSTYLE_FIRST_HATCH; | |
f7732fa5 PC |
70 | if (hatches[i] == NULL) |
71 | { | |
1780a38b VZ |
72 | // This macro creates a bitmap from an XBM file included above. Notice |
73 | // the need for the cast because gdk_bitmap_create_from_data() doesn't | |
74 | // accept unsigned data but the arrays in XBM need to be unsigned to | |
75 | // avoid warnings (and even errors in C+0x mode) from g++. | |
76 | #define CREATE_FROM_XBM_DATA(name) \ | |
77 | gdk_bitmap_create_from_data \ | |
78 | ( \ | |
79 | NULL, \ | |
80 | reinterpret_cast<gchar *>(name ## _bits), \ | |
81 | name ## _width, \ | |
82 | name ## _height \ | |
83 | ) | |
84 | ||
f7732fa5 PC |
85 | switch (style) |
86 | { | |
04ee05f9 | 87 | case wxBRUSHSTYLE_BDIAGONAL_HATCH: |
1780a38b | 88 | hatches[i] = CREATE_FROM_XBM_DATA(bdiag); |
f7732fa5 | 89 | break; |
04ee05f9 | 90 | case wxBRUSHSTYLE_CROSSDIAG_HATCH: |
1780a38b | 91 | hatches[i] = CREATE_FROM_XBM_DATA(cdiag); |
f7732fa5 | 92 | break; |
04ee05f9 | 93 | case wxBRUSHSTYLE_CROSS_HATCH: |
1780a38b | 94 | hatches[i] = CREATE_FROM_XBM_DATA(cross); |
f7732fa5 | 95 | break; |
04ee05f9 | 96 | case wxBRUSHSTYLE_FDIAGONAL_HATCH: |
1780a38b | 97 | hatches[i] = CREATE_FROM_XBM_DATA(fdiag); |
f7732fa5 | 98 | break; |
04ee05f9 | 99 | case wxBRUSHSTYLE_HORIZONTAL_HATCH: |
1780a38b | 100 | hatches[i] = CREATE_FROM_XBM_DATA(horiz); |
f7732fa5 | 101 | break; |
04ee05f9 | 102 | case wxBRUSHSTYLE_VERTICAL_HATCH: |
1780a38b | 103 | hatches[i] = CREATE_FROM_XBM_DATA(verti); |
f7732fa5 PC |
104 | break; |
105 | } | |
1780a38b VZ |
106 | |
107 | #undef CREATE_FROM_XBM_DATA | |
f7732fa5 PC |
108 | } |
109 | return hatches[i]; | |
110 | } | |
111 | ||
3d2d8da1 RR |
112 | //----------------------------------------------------------------------------- |
113 | // Implement Pool of Graphic contexts. Creating them takes too much time. | |
114 | //----------------------------------------------------------------------------- | |
115 | ||
0e09f76e RR |
116 | enum wxPoolGCType |
117 | { | |
118 | wxGC_ERROR = 0, | |
119 | wxTEXT_MONO, | |
120 | wxBG_MONO, | |
121 | wxPEN_MONO, | |
122 | wxBRUSH_MONO, | |
123 | wxTEXT_COLOUR, | |
124 | wxBG_COLOUR, | |
125 | wxPEN_COLOUR, | |
f6bcfd97 BP |
126 | wxBRUSH_COLOUR, |
127 | wxTEXT_SCREEN, | |
128 | wxBG_SCREEN, | |
129 | wxPEN_SCREEN, | |
14421681 VZ |
130 | wxBRUSH_SCREEN, |
131 | wxTEXT_COLOUR_ALPHA, | |
132 | wxBG_COLOUR_ALPHA, | |
133 | wxPEN_COLOUR_ALPHA, | |
134 | wxBRUSH_COLOUR_ALPHA | |
0e09f76e RR |
135 | }; |
136 | ||
3d2d8da1 RR |
137 | struct wxGC |
138 | { | |
0e09f76e RR |
139 | GdkGC *m_gc; |
140 | wxPoolGCType m_type; | |
141 | bool m_used; | |
3d2d8da1 RR |
142 | }; |
143 | ||
696f36b7 JS |
144 | #define GC_POOL_ALLOC_SIZE 100 |
145 | ||
146 | static int wxGCPoolSize = 0; | |
147 | ||
148 | static wxGC *wxGCPool = NULL; | |
3d2d8da1 RR |
149 | |
150 | static void wxInitGCPool() | |
151 | { | |
696f36b7 JS |
152 | // This really could wait until the first call to |
153 | // wxGetPoolGC, but we will make the first allocation | |
154 | // now when other initialization is being performed. | |
ab9d0a8c | 155 | |
696f36b7 JS |
156 | // Set initial pool size. |
157 | wxGCPoolSize = GC_POOL_ALLOC_SIZE; | |
ab9d0a8c | 158 | |
696f36b7 JS |
159 | // Allocate initial pool. |
160 | wxGCPool = (wxGC *)malloc(wxGCPoolSize * sizeof(wxGC)); | |
161 | if (wxGCPool == NULL) | |
162 | { | |
163 | // If we cannot malloc, then fail with error | |
164 | // when debug is enabled. If debug is not enabled, | |
165 | // the problem will eventually get caught | |
551b5391 | 166 | // in wxGetPoolGC. |
696f36b7 JS |
167 | wxFAIL_MSG( wxT("Cannot allocate GC pool") ); |
168 | return; | |
169 | } | |
ab9d0a8c | 170 | |
696f36b7 JS |
171 | // Zero initial pool. |
172 | memset(wxGCPool, 0, wxGCPoolSize * sizeof(wxGC)); | |
3d2d8da1 RR |
173 | } |
174 | ||
175 | static void wxCleanUpGCPool() | |
176 | { | |
f6116855 | 177 | for (int i = 0; i < wxGCPoolSize; i++) |
3d2d8da1 RR |
178 | { |
179 | if (wxGCPool[i].m_gc) | |
3fe39b0c | 180 | g_object_unref (wxGCPool[i].m_gc); |
3d2d8da1 | 181 | } |
696f36b7 JS |
182 | |
183 | free(wxGCPool); | |
184 | wxGCPool = NULL; | |
185 | wxGCPoolSize = 0; | |
3d2d8da1 RR |
186 | } |
187 | ||
0e09f76e | 188 | static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) |
3d2d8da1 | 189 | { |
696f36b7 | 190 | wxGC *pptr; |
ab9d0a8c | 191 | |
696f36b7 JS |
192 | // Look for an available GC. |
193 | for (int i = 0; i < wxGCPoolSize; i++) | |
3d2d8da1 RR |
194 | { |
195 | if (!wxGCPool[i].m_gc) | |
196 | { | |
197 | wxGCPool[i].m_gc = gdk_gc_new( window ); | |
198 | gdk_gc_set_exposures( wxGCPool[i].m_gc, FALSE ); | |
0e09f76e | 199 | wxGCPool[i].m_type = type; |
ab9d0a8c | 200 | wxGCPool[i].m_used = false; |
3d2d8da1 | 201 | } |
0e09f76e | 202 | if ((!wxGCPool[i].m_used) && (wxGCPool[i].m_type == type)) |
3d2d8da1 | 203 | { |
ab9d0a8c | 204 | wxGCPool[i].m_used = true; |
3d2d8da1 RR |
205 | return wxGCPool[i].m_gc; |
206 | } | |
207 | } | |
5f170f33 | 208 | |
696f36b7 JS |
209 | // We did not find an available GC. |
210 | // We need to grow the GC pool. | |
211 | pptr = (wxGC *)realloc(wxGCPool, | |
551b5391 | 212 | (wxGCPoolSize + GC_POOL_ALLOC_SIZE)*sizeof(wxGC)); |
696f36b7 JS |
213 | if (pptr != NULL) |
214 | { | |
215 | // Initialize newly allocated pool. | |
216 | wxGCPool = pptr; | |
551b5391 RR |
217 | memset(&wxGCPool[wxGCPoolSize], 0, |
218 | GC_POOL_ALLOC_SIZE*sizeof(wxGC)); | |
ab9d0a8c WS |
219 | |
220 | // Initialize entry we will return. | |
696f36b7 JS |
221 | wxGCPool[wxGCPoolSize].m_gc = gdk_gc_new( window ); |
222 | gdk_gc_set_exposures( wxGCPool[wxGCPoolSize].m_gc, FALSE ); | |
223 | wxGCPool[wxGCPoolSize].m_type = type; | |
ab9d0a8c WS |
224 | wxGCPool[wxGCPoolSize].m_used = true; |
225 | ||
696f36b7 JS |
226 | // Set new value of pool size. |
227 | wxGCPoolSize += GC_POOL_ALLOC_SIZE; | |
ab9d0a8c | 228 | |
696f36b7 JS |
229 | // Return newly allocated entry. |
230 | return wxGCPool[wxGCPoolSize-GC_POOL_ALLOC_SIZE].m_gc; | |
231 | } | |
ab9d0a8c | 232 | |
696f36b7 | 233 | // The realloc failed. Fall through to error. |
3d2d8da1 | 234 | wxFAIL_MSG( wxT("No GC available") ); |
5f170f33 | 235 | |
d3b9f782 | 236 | return NULL; |
3d2d8da1 RR |
237 | } |
238 | ||
239 | static void wxFreePoolGC( GdkGC *gc ) | |
240 | { | |
696f36b7 | 241 | for (int i = 0; i < wxGCPoolSize; i++) |
3d2d8da1 RR |
242 | { |
243 | if (wxGCPool[i].m_gc == gc) | |
244 | { | |
ab9d0a8c | 245 | wxGCPool[i].m_used = false; |
3d2d8da1 RR |
246 | return; |
247 | } | |
248 | } | |
5f170f33 | 249 | |
3d2d8da1 RR |
250 | wxFAIL_MSG( wxT("Wrong GC") ); |
251 | } | |
252 | ||
c801d85f | 253 | //----------------------------------------------------------------------------- |
ec758a20 | 254 | // wxWindowDC |
c801d85f KB |
255 | //----------------------------------------------------------------------------- |
256 | ||
888dde65 | 257 | IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxGTKDCImpl) |
c801d85f | 258 | |
888dde65 RR |
259 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner ) : |
260 | wxGTKDCImpl( owner ) | |
c801d85f | 261 | { |
d3b9f782 VZ |
262 | m_gdkwindow = NULL; |
263 | m_penGC = NULL; | |
264 | m_brushGC = NULL; | |
265 | m_textGC = NULL; | |
266 | m_bgGC = NULL; | |
267 | m_cmap = NULL; | |
ab9d0a8c | 268 | m_isScreenDC = false; |
d3b9f782 VZ |
269 | m_context = NULL; |
270 | m_layout = NULL; | |
271 | m_fontdesc = NULL; | |
903f689b | 272 | } |
c801d85f | 273 | |
888dde65 RR |
274 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window ) : |
275 | wxGTKDCImpl( owner ) | |
c801d85f | 276 | { |
3cd0b8c5 RR |
277 | wxASSERT_MSG( window, wxT("DC needs a window") ); |
278 | ||
d3b9f782 VZ |
279 | m_gdkwindow = NULL; |
280 | m_penGC = NULL; | |
281 | m_brushGC = NULL; | |
282 | m_textGC = NULL; | |
283 | m_bgGC = NULL; | |
284 | m_cmap = NULL; | |
ab9d0a8c | 285 | m_isScreenDC = false; |
3b245d60 | 286 | m_font = window->GetFont(); |
7d5af6fa | 287 | |
a2053b27 | 288 | GtkWidget *widget = window->m_wxwindow; |
f089940f | 289 | m_gdkwindow = window->GTKGetDrawingWindow(); |
7d5af6fa | 290 | |
cfcc3932 | 291 | // Some controls don't have m_wxwindow - like wxStaticBox, but the user |
b666ade7 | 292 | // code should still be able to create wxClientDCs for them |
b7f1f77f VZ |
293 | if ( !widget ) |
294 | { | |
b666ade7 PC |
295 | widget = window->m_widget; |
296 | ||
297 | wxCHECK_RET(widget, "DC needs a widget"); | |
b7f1f77f | 298 | |
f089940f | 299 | m_gdkwindow = widget->window; |
fc9ab22a | 300 | if (!gtk_widget_get_has_window(widget)) |
b666ade7 PC |
301 | SetDeviceLocalOrigin(widget->allocation.x, widget->allocation.y); |
302 | } | |
7d5af6fa | 303 | |
496e7ec6 | 304 | m_context = window->GTKGetPangoDefaultContext(); |
cfcc3932 RR |
305 | m_layout = pango_layout_new( m_context ); |
306 | m_fontdesc = pango_font_description_copy( widget->style->font_desc ); | |
8943b403 | 307 | |
cfcc3932 | 308 | // Window not realized ? |
888dde65 | 309 | if (!m_gdkwindow) |
1e133b7d | 310 | { |
cfcc3932 | 311 | // Don't report problems as per MSW. |
ab9d0a8c | 312 | m_ok = true; |
7d5af6fa VZ |
313 | |
314 | return; | |
1e133b7d | 315 | } |
7d5af6fa | 316 | |
b666ade7 | 317 | m_cmap = gtk_widget_get_colormap(widget); |
7d5af6fa | 318 | |
265898fd | 319 | SetUpDC(); |
bbbbe360 RR |
320 | |
321 | /* this must be done after SetUpDC, bacause SetUpDC calls the | |
322 | repective SetBrush, SetPen, SetBackground etc functions | |
323 | to set up the DC. SetBackground call m_owner->SetBackground | |
324 | and this might not be desired as the standard dc background | |
325 | is white whereas a window might assume gray to be the | |
326 | standard (as e.g. wxStatusBar) */ | |
7d5af6fa | 327 | |
888dde65 | 328 | m_window = window; |
f4322df6 | 329 | |
89efaf2b | 330 | if (m_window && m_window->m_wxwindow && |
888dde65 | 331 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) |
847dfdb4 | 332 | { |
5713b349 | 333 | // reverse sense |
847dfdb4 | 334 | m_signX = -1; |
807a572e | 335 | |
5713b349 | 336 | // origin in the upper right corner |
888dde65 | 337 | m_deviceOriginX = m_window->GetClientSize().x; |
847dfdb4 | 338 | } |
903f689b | 339 | } |
c801d85f | 340 | |
888dde65 | 341 | wxWindowDCImpl::~wxWindowDCImpl() |
c801d85f | 342 | { |
265898fd | 343 | Destroy(); |
ab9d0a8c | 344 | |
cfcc3932 | 345 | if (m_layout) |
3fe39b0c | 346 | g_object_unref (m_layout); |
cfcc3932 RR |
347 | if (m_fontdesc) |
348 | pango_font_description_free( m_fontdesc ); | |
903f689b | 349 | } |
c801d85f | 350 | |
888dde65 | 351 | void wxWindowDCImpl::SetUpDC( bool isMemDC ) |
809934d2 | 352 | { |
ab9d0a8c | 353 | m_ok = true; |
5f170f33 | 354 | |
809934d2 | 355 | wxASSERT_MSG( !m_penGC, wxT("GCs already created") ); |
5f170f33 | 356 | |
ab171e95 RR |
357 | bool done = false; |
358 | ||
888dde65 | 359 | if ((isMemDC) && (GetSelectedBitmap().IsOk())) |
809934d2 | 360 | { |
888dde65 | 361 | if (GetSelectedBitmap().GetDepth() == 1) |
ab171e95 | 362 | { |
888dde65 RR |
363 | m_penGC = wxGetPoolGC( m_gdkwindow, wxPEN_MONO ); |
364 | m_brushGC = wxGetPoolGC( m_gdkwindow, wxBRUSH_MONO ); | |
365 | m_textGC = wxGetPoolGC( m_gdkwindow, wxTEXT_MONO ); | |
366 | m_bgGC = wxGetPoolGC( m_gdkwindow, wxBG_MONO ); | |
ab171e95 RR |
367 | done = true; |
368 | } | |
809934d2 | 369 | } |
ab171e95 RR |
370 | |
371 | if (!done) | |
89efaf2b | 372 | { |
ab171e95 RR |
373 | if (m_isScreenDC) |
374 | { | |
888dde65 RR |
375 | m_penGC = wxGetPoolGC( m_gdkwindow, wxPEN_SCREEN ); |
376 | m_brushGC = wxGetPoolGC( m_gdkwindow, wxBRUSH_SCREEN ); | |
377 | m_textGC = wxGetPoolGC( m_gdkwindow, wxTEXT_SCREEN ); | |
378 | m_bgGC = wxGetPoolGC( m_gdkwindow, wxBG_SCREEN ); | |
ab171e95 | 379 | } |
8e98dabc PC |
380 | #if GTK_CHECK_VERSION(2,12,0) |
381 | // gdk_screen_get_rgba_colormap was added in 2.8, but this code is for | |
382 | // compositing which requires 2.12 | |
383 | else if (gtk_check_version(2,12,0) == NULL && | |
384 | m_cmap == gdk_screen_get_rgba_colormap(gdk_colormap_get_screen(m_cmap))) | |
14421681 VZ |
385 | { |
386 | m_penGC = wxGetPoolGC( m_gdkwindow, wxPEN_COLOUR_ALPHA ); | |
387 | m_brushGC = wxGetPoolGC( m_gdkwindow, wxBRUSH_COLOUR_ALPHA ); | |
388 | m_textGC = wxGetPoolGC( m_gdkwindow, wxTEXT_COLOUR_ALPHA ); | |
389 | m_bgGC = wxGetPoolGC( m_gdkwindow, wxBG_COLOUR_ALPHA ); | |
390 | } | |
8e98dabc | 391 | #endif |
ab171e95 RR |
392 | else |
393 | { | |
888dde65 RR |
394 | m_penGC = wxGetPoolGC( m_gdkwindow, wxPEN_COLOUR ); |
395 | m_brushGC = wxGetPoolGC( m_gdkwindow, wxBRUSH_COLOUR ); | |
396 | m_textGC = wxGetPoolGC( m_gdkwindow, wxTEXT_COLOUR ); | |
397 | m_bgGC = wxGetPoolGC( m_gdkwindow, wxBG_COLOUR ); | |
ab171e95 | 398 | } |
809934d2 RR |
399 | } |
400 | ||
401 | /* background colour */ | |
402 | m_backgroundBrush = *wxWHITE_BRUSH; | |
403 | m_backgroundBrush.GetColour().CalcPixel( m_cmap ); | |
c6685317 | 404 | const GdkColor *bg_col = m_backgroundBrush.GetColour().GetColor(); |
809934d2 RR |
405 | |
406 | /* m_textGC */ | |
407 | m_textForegroundColour.CalcPixel( m_cmap ); | |
408 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
409 | ||
410 | m_textBackgroundColour.CalcPixel( m_cmap ); | |
411 | gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); | |
412 | ||
413 | gdk_gc_set_fill( m_textGC, GDK_SOLID ); | |
f4322df6 | 414 | |
4ba1c184 | 415 | gdk_gc_set_colormap( m_textGC, m_cmap ); |
809934d2 RR |
416 | |
417 | /* m_penGC */ | |
418 | m_pen.GetColour().CalcPixel( m_cmap ); | |
419 | gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() ); | |
420 | gdk_gc_set_background( m_penGC, bg_col ); | |
5f170f33 | 421 | |
809934d2 | 422 | gdk_gc_set_line_attributes( m_penGC, 0, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_ROUND ); |
5f170f33 | 423 | |
809934d2 RR |
424 | /* m_brushGC */ |
425 | m_brush.GetColour().CalcPixel( m_cmap ); | |
426 | gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() ); | |
427 | gdk_gc_set_background( m_brushGC, bg_col ); | |
5f170f33 | 428 | |
809934d2 | 429 | gdk_gc_set_fill( m_brushGC, GDK_SOLID ); |
5f170f33 | 430 | |
809934d2 RR |
431 | /* m_bgGC */ |
432 | gdk_gc_set_background( m_bgGC, bg_col ); | |
433 | gdk_gc_set_foreground( m_bgGC, bg_col ); | |
434 | ||
435 | gdk_gc_set_fill( m_bgGC, GDK_SOLID ); | |
5f170f33 | 436 | |
809934d2 RR |
437 | /* ROPs */ |
438 | gdk_gc_set_function( m_textGC, GDK_COPY ); | |
439 | gdk_gc_set_function( m_brushGC, GDK_COPY ); | |
440 | gdk_gc_set_function( m_penGC, GDK_COPY ); | |
5f170f33 | 441 | |
809934d2 | 442 | /* clipping */ |
d3b9f782 VZ |
443 | gdk_gc_set_clip_rectangle( m_penGC, NULL ); |
444 | gdk_gc_set_clip_rectangle( m_brushGC, NULL ); | |
445 | gdk_gc_set_clip_rectangle( m_textGC, NULL ); | |
446 | gdk_gc_set_clip_rectangle( m_bgGC, NULL ); | |
809934d2 RR |
447 | } |
448 | ||
888dde65 | 449 | void wxWindowDCImpl::DoGetSize( int* width, int* height ) const |
376aa62a | 450 | { |
9a83f860 | 451 | wxCHECK_RET( m_window, wxT("GetSize() doesn't work without window") ); |
376aa62a | 452 | |
888dde65 | 453 | m_window->GetSize(width, height); |
376aa62a VZ |
454 | } |
455 | ||
888dde65 | 456 | bool wxWindowDCImpl::DoFloodFill(wxCoord x, wxCoord y, |
89efaf2b | 457 | const wxColour& col, wxFloodFillStyle style) |
06cf7c08 | 458 | { |
c0521644 VZ |
459 | #if wxUSE_IMAGE |
460 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, | |
89efaf2b | 461 | const wxColour & col, wxFloodFillStyle style); |
c0521644 | 462 | |
ab171e95 | 463 | return wxDoFloodFill( GetOwner(), x, y, col, style); |
c0521644 | 464 | #else |
8d22935d VZ |
465 | wxUnusedVar(x); |
466 | wxUnusedVar(y); | |
467 | wxUnusedVar(col); | |
468 | wxUnusedVar(style); | |
469 | ||
c0521644 VZ |
470 | return false; |
471 | #endif | |
903f689b | 472 | } |
c801d85f | 473 | |
888dde65 | 474 | bool wxWindowDCImpl::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const |
c801d85f | 475 | { |
e7f83ccc PC |
476 | GdkImage* image = NULL; |
477 | if (m_gdkwindow) | |
478 | { | |
479 | const int x = LogicalToDeviceX(x1); | |
480 | const int y = LogicalToDeviceY(y1); | |
481 | wxRect rect; | |
482 | gdk_drawable_get_size(m_gdkwindow, &rect.width, &rect.height); | |
483 | if (rect.Contains(x, y)) | |
484 | image = gdk_drawable_get_image(m_gdkwindow, x, y, 1, 1); | |
485 | } | |
486 | if (image == NULL) | |
487 | { | |
488 | *col = wxColour(); | |
489 | return false; | |
490 | } | |
491 | GdkColormap* colormap = gdk_image_get_colormap(image); | |
492 | const unsigned pixel = gdk_image_get_pixel(image, 0, 0); | |
493 | if (colormap == NULL) | |
494 | *col = pixel ? m_textForegroundColour : m_textBackgroundColour; | |
495 | else | |
496 | { | |
497 | GdkColor c; | |
498 | gdk_colormap_query_color(colormap, pixel, &c); | |
499 | col->Set(c.red >> 8, c.green >> 8, c.blue >> 8); | |
500 | } | |
501 | g_object_unref(image); | |
ab9d0a8c | 502 | return true; |
903f689b | 503 | } |
c801d85f | 504 | |
888dde65 | 505 | void wxWindowDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
c801d85f | 506 | { |
ab171e95 | 507 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
89efaf2b | 508 | |
e6777e65 | 509 | if ( m_pen.IsNonTransparent() ) |
265898fd | 510 | { |
888dde65 RR |
511 | if (m_gdkwindow) |
512 | gdk_draw_line( m_gdkwindow, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) ); | |
7d5af6fa | 513 | |
ed880dd4 RR |
514 | CalcBoundingBox(x1, y1); |
515 | CalcBoundingBox(x2, y2); | |
265898fd | 516 | } |
903f689b | 517 | } |
c801d85f | 518 | |
888dde65 | 519 | void wxWindowDCImpl::DoCrossHair( wxCoord x, wxCoord y ) |
c801d85f | 520 | { |
ab171e95 | 521 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 522 | |
e6777e65 | 523 | if ( m_pen.IsNonTransparent() ) |
265898fd RR |
524 | { |
525 | int w = 0; | |
526 | int h = 0; | |
ab171e95 | 527 | GetOwner()->GetSize( &w, &h ); |
72cdf4c9 VZ |
528 | wxCoord xx = XLOG2DEV(x); |
529 | wxCoord yy = YLOG2DEV(y); | |
888dde65 | 530 | if (m_gdkwindow) |
7d5af6fa | 531 | { |
888dde65 RR |
532 | gdk_draw_line( m_gdkwindow, m_penGC, 0, yy, XLOG2DEVREL(w), yy ); |
533 | gdk_draw_line( m_gdkwindow, m_penGC, xx, 0, xx, YLOG2DEVREL(h) ); | |
7d5af6fa | 534 | } |
265898fd | 535 | } |
903f689b | 536 | } |
c801d85f | 537 | |
ea3a345f PC |
538 | void wxWindowDCImpl::DrawingSetup(GdkGC*& gc, bool& originChanged) |
539 | { | |
540 | gc = m_brushGC; | |
541 | GdkPixmap* pixmap = NULL; | |
542 | const int style = m_brush.GetStyle(); | |
543 | ||
04ee05f9 | 544 | if (style == wxBRUSHSTYLE_STIPPLE || style == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE) |
ea3a345f PC |
545 | { |
546 | const wxBitmap* stipple = m_brush.GetStipple(); | |
547 | if (stipple->IsOk()) | |
548 | { | |
04ee05f9 | 549 | if (style == wxBRUSHSTYLE_STIPPLE) |
ea3a345f PC |
550 | pixmap = stipple->GetPixmap(); |
551 | else if (stipple->GetMask()) | |
552 | { | |
553 | pixmap = stipple->GetPixmap(); | |
554 | gc = m_textGC; | |
555 | } | |
556 | } | |
557 | } | |
558 | else if (m_brush.IsHatch()) | |
559 | { | |
560 | pixmap = GetHatch(style); | |
561 | } | |
562 | ||
563 | int origin_x = 0; | |
564 | int origin_y = 0; | |
565 | if (pixmap) | |
566 | { | |
567 | int w, h; | |
568 | gdk_drawable_get_size(pixmap, &w, &h); | |
569 | origin_x = m_deviceOriginX % w; | |
570 | origin_y = m_deviceOriginY % h; | |
571 | } | |
572 | ||
573 | originChanged = origin_x || origin_y; | |
574 | if (originChanged) | |
575 | gdk_gc_set_ts_origin(gc, origin_x, origin_y); | |
576 | } | |
577 | ||
888dde65 | 578 | void wxWindowDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, |
72cdf4c9 | 579 | wxCoord xc, wxCoord yc ) |
c801d85f | 580 | { |
ab171e95 | 581 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 582 | |
72cdf4c9 VZ |
583 | wxCoord xx1 = XLOG2DEV(x1); |
584 | wxCoord yy1 = YLOG2DEV(y1); | |
585 | wxCoord xx2 = XLOG2DEV(x2); | |
586 | wxCoord yy2 = YLOG2DEV(y2); | |
587 | wxCoord xxc = XLOG2DEV(xc); | |
588 | wxCoord yyc = YLOG2DEV(yc); | |
7d5af6fa | 589 | double dx = xx1 - xxc; |
265898fd | 590 | double dy = yy1 - yyc; |
de87c353 | 591 | double radius = sqrt((double)(dx*dx+dy*dy)); |
72cdf4c9 | 592 | wxCoord r = (wxCoord)radius; |
265898fd RR |
593 | double radius1, radius2; |
594 | ||
7d5af6fa | 595 | if (xx1 == xx2 && yy1 == yy2) |
265898fd RR |
596 | { |
597 | radius1 = 0.0; | |
598 | radius2 = 360.0; | |
7d5af6fa | 599 | } |
c77a6796 | 600 | else if ( wxIsNullDouble(radius) ) |
265898fd | 601 | { |
c77a6796 VZ |
602 | radius1 = |
603 | radius2 = 0.0; | |
7d5af6fa VZ |
604 | } |
605 | else | |
265898fd RR |
606 | { |
607 | radius1 = (xx1 - xxc == 0) ? | |
b0e0d661 VZ |
608 | (yy1 - yyc < 0) ? 90.0 : -90.0 : |
609 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
265898fd | 610 | radius2 = (xx2 - xxc == 0) ? |
b0e0d661 VZ |
611 | (yy2 - yyc < 0) ? 90.0 : -90.0 : |
612 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
265898fd | 613 | } |
72cdf4c9 VZ |
614 | wxCoord alpha1 = wxCoord(radius1 * 64.0); |
615 | wxCoord alpha2 = wxCoord((radius2 - radius1) * 64.0); | |
265898fd RR |
616 | while (alpha2 <= 0) alpha2 += 360*64; |
617 | while (alpha1 > 360*64) alpha1 -= 360*64; | |
618 | ||
888dde65 | 619 | if (m_gdkwindow) |
6db90681 | 620 | { |
e6777e65 | 621 | if ( m_brush.IsNonTransparent() ) |
e9f88d04 | 622 | { |
ea3a345f PC |
623 | GdkGC* gc; |
624 | bool originChanged; | |
625 | DrawingSetup(gc, originChanged); | |
626 | ||
627 | gdk_draw_arc(m_gdkwindow, gc, true, xxc-r, yyc-r, 2*r, 2*r, alpha1, alpha2); | |
628 | ||
629 | if (originChanged) | |
630 | gdk_gc_set_ts_origin(gc, 0, 0); | |
e9f88d04 | 631 | } |
7d5af6fa | 632 | |
e6777e65 | 633 | if ( m_pen.IsNonTransparent() ) |
3d0c4d2e | 634 | { |
888dde65 | 635 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
f469b27c | 636 | |
e6777e65 | 637 | if ( m_brush.IsNonTransparent() && (alpha2 - alpha1 != 360*64) ) |
9707fd13 | 638 | { |
888dde65 RR |
639 | gdk_draw_line( m_gdkwindow, m_penGC, xx1, yy1, xxc, yyc ); |
640 | gdk_draw_line( m_gdkwindow, m_penGC, xxc, yyc, xx2, yy2 ); | |
9707fd13 | 641 | } |
3d0c4d2e | 642 | } |
6db90681 | 643 | } |
7d5af6fa | 644 | |
265898fd RR |
645 | CalcBoundingBox (x1, y1); |
646 | CalcBoundingBox (x2, y2); | |
903f689b | 647 | } |
c801d85f | 648 | |
888dde65 | 649 | void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double sa, double ea ) |
c801d85f | 650 | { |
ab171e95 | 651 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 652 | |
72cdf4c9 VZ |
653 | wxCoord xx = XLOG2DEV(x); |
654 | wxCoord yy = YLOG2DEV(y); | |
655 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
656 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
7d5af6fa | 657 | |
265898fd RR |
658 | // CMB: handle -ve width and/or height |
659 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
660 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
7d5af6fa | 661 | |
888dde65 | 662 | if (m_gdkwindow) |
6db90681 | 663 | { |
72cdf4c9 | 664 | wxCoord start = wxCoord(sa * 64.0); |
3d0c4d2e | 665 | wxCoord end = wxCoord((ea-sa) * 64.0); |
7d5af6fa | 666 | |
e6777e65 | 667 | if ( m_brush.IsNonTransparent() ) |
e9f88d04 | 668 | { |
ea3a345f PC |
669 | GdkGC* gc; |
670 | bool originChanged; | |
671 | DrawingSetup(gc, originChanged); | |
672 | ||
673 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, ww, hh, start, end); | |
674 | ||
675 | if (originChanged) | |
676 | gdk_gc_set_ts_origin(gc, 0, 0); | |
e9f88d04 | 677 | } |
7d5af6fa | 678 | |
e6777e65 | 679 | if ( m_pen.IsNonTransparent() ) |
888dde65 | 680 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, ww, hh, start, end ); |
6db90681 | 681 | } |
7d5af6fa | 682 | |
265898fd RR |
683 | CalcBoundingBox (x, y); |
684 | CalcBoundingBox (x + width, y + height); | |
903f689b | 685 | } |
c801d85f | 686 | |
888dde65 | 687 | void wxWindowDCImpl::DoDrawPoint( wxCoord x, wxCoord y ) |
c801d85f | 688 | { |
ab171e95 | 689 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 690 | |
e6777e65 | 691 | if ( m_pen.IsNonTransparent() && m_gdkwindow ) |
888dde65 | 692 | gdk_draw_point( m_gdkwindow, m_penGC, XLOG2DEV(x), YLOG2DEV(y) ); |
7d5af6fa | 693 | |
265898fd | 694 | CalcBoundingBox (x, y); |
903f689b | 695 | } |
c801d85f | 696 | |
4787c92d | 697 | void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset ) |
c801d85f | 698 | { |
ab171e95 | 699 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 700 | |
265898fd | 701 | if (n <= 0) return; |
7d5af6fa | 702 | |
e6777e65 VZ |
703 | if ( m_pen.IsTransparent() ) |
704 | return; | |
705 | ||
e90411c2 | 706 | //Check, if scaling is necessary |
280831d5 PC |
707 | const bool doScale = |
708 | xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10; | |
e90411c2 | 709 | |
280831d5 | 710 | // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other |
4787c92d PC |
711 | const GdkPoint* gpts = reinterpret_cast<const GdkPoint*>(points); |
712 | GdkPoint* gpts_alloc = NULL; | |
e90411c2 | 713 | |
280831d5 | 714 | if (doScale) |
4787c92d PC |
715 | { |
716 | gpts_alloc = new GdkPoint[n]; | |
717 | gpts = gpts_alloc; | |
718 | } | |
7d5af6fa | 719 | |
ab9d0a8c | 720 | for (int i = 0; i < n; i++) |
265898fd | 721 | { |
280831d5 PC |
722 | if (doScale) |
723 | { | |
4787c92d PC |
724 | gpts_alloc[i].x = XLOG2DEV(points[i].x + xoffset); |
725 | gpts_alloc[i].y = YLOG2DEV(points[i].y + yoffset); | |
e90411c2 | 726 | } |
280831d5 | 727 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); |
e90411c2 | 728 | } |
6eb37239 | 729 | |
888dde65 | 730 | if (m_gdkwindow) |
8f48176b | 731 | gdk_draw_lines( m_gdkwindow, m_penGC, (GdkPoint*) gpts, n); |
6eb37239 | 732 | |
4787c92d | 733 | delete[] gpts_alloc; |
903f689b | 734 | } |
c801d85f | 735 | |
4787c92d | 736 | void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], |
89efaf2b FM |
737 | wxCoord xoffset, wxCoord yoffset, |
738 | wxPolygonFillMode WXUNUSED(fillStyle) ) | |
cf7a7e13 | 739 | { |
ab171e95 | 740 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 741 | |
4bc67cc5 | 742 | if (n <= 0) return; |
7d5af6fa | 743 | |
e90411c2 | 744 | //Check, if scaling is necessary |
280831d5 PC |
745 | const bool doScale = |
746 | xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10; | |
e90411c2 | 747 | |
280831d5 | 748 | // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other |
4787c92d PC |
749 | const GdkPoint* gdkpoints = reinterpret_cast<const GdkPoint*>(points); |
750 | GdkPoint* gdkpoints_alloc = NULL; | |
e90411c2 | 751 | |
280831d5 | 752 | if (doScale) |
4787c92d PC |
753 | { |
754 | gdkpoints_alloc = new GdkPoint[n]; | |
755 | gdkpoints = gdkpoints_alloc; | |
756 | } | |
e90411c2 | 757 | |
265898fd RR |
758 | int i; |
759 | for (i = 0 ; i < n ; i++) | |
760 | { | |
280831d5 PC |
761 | if (doScale) |
762 | { | |
4787c92d PC |
763 | gdkpoints_alloc[i].x = XLOG2DEV(points[i].x + xoffset); |
764 | gdkpoints_alloc[i].y = YLOG2DEV(points[i].y + yoffset); | |
e90411c2 | 765 | } |
280831d5 | 766 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); |
e90411c2 | 767 | } |
7d5af6fa | 768 | |
888dde65 | 769 | if (m_gdkwindow) |
72174350 | 770 | { |
e6777e65 | 771 | if ( m_brush.IsNonTransparent() ) |
72174350 | 772 | { |
ea3a345f PC |
773 | GdkGC* gc; |
774 | bool originChanged; | |
775 | DrawingSetup(gc, originChanged); | |
776 | ||
8f48176b | 777 | gdk_draw_polygon(m_gdkwindow, gc, true, (GdkPoint*) gdkpoints, n); |
ea3a345f PC |
778 | |
779 | if (originChanged) | |
780 | gdk_gc_set_ts_origin(gc, 0, 0); | |
72174350 | 781 | } |
7d5af6fa | 782 | |
e6777e65 | 783 | if ( m_pen.IsNonTransparent() ) |
b0e0d661 | 784 | { |
bb56b0a8 | 785 | /* |
e1208c31 RR |
786 | for (i = 0 ; i < n ; i++) |
787 | { | |
888dde65 | 788 | gdk_draw_line( m_gdkwindow, m_penGC, |
e1208c31 RR |
789 | gdkpoints[i%n].x, |
790 | gdkpoints[i%n].y, | |
791 | gdkpoints[(i+1)%n].x, | |
792 | gdkpoints[(i+1)%n].y); | |
793 | } | |
bb56b0a8 | 794 | */ |
8f48176b | 795 | gdk_draw_polygon( m_gdkwindow, m_penGC, FALSE, (GdkPoint*) gdkpoints, n ); |
ab9d0a8c | 796 | |
265898fd | 797 | } |
6db90681 | 798 | } |
7d5af6fa | 799 | |
4787c92d | 800 | delete[] gdkpoints_alloc; |
903f689b | 801 | } |
c801d85f | 802 | |
888dde65 | 803 | void wxWindowDCImpl::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 804 | { |
ab171e95 | 805 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
c801d85f | 806 | |
72cdf4c9 VZ |
807 | wxCoord xx = XLOG2DEV(x); |
808 | wxCoord yy = YLOG2DEV(y); | |
809 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
810 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
7d5af6fa | 811 | |
265898fd RR |
812 | // CMB: draw nothing if transformed w or h is 0 |
813 | if (ww == 0 || hh == 0) return; | |
6f65e337 | 814 | |
265898fd RR |
815 | // CMB: handle -ve width and/or height |
816 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
817 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
6f65e337 | 818 | |
888dde65 | 819 | if (m_gdkwindow) |
6db90681 | 820 | { |
e6777e65 | 821 | if ( m_brush.IsNonTransparent() ) |
72174350 | 822 | { |
ea3a345f PC |
823 | GdkGC* gc; |
824 | bool originChanged; | |
825 | DrawingSetup(gc, originChanged); | |
826 | ||
827 | gdk_draw_rectangle(m_gdkwindow, gc, true, xx, yy, ww, hh); | |
828 | ||
829 | if (originChanged) | |
830 | gdk_gc_set_ts_origin(gc, 0, 0); | |
72174350 | 831 | } |
e1208c31 | 832 | |
e6777e65 | 833 | if ( m_pen.IsNonTransparent() ) |
3b5bf828 | 834 | { |
3b5bf828 | 835 | if ((m_pen.GetWidth() == 2) && (m_pen.GetCap() == wxCAP_ROUND) && |
04ee05f9 | 836 | (m_pen.GetJoin() == wxJOIN_ROUND) && (m_pen.GetStyle() == wxPENSTYLE_SOLID)) |
3b5bf828 RR |
837 | { |
838 | // Use 2 1-line rects instead | |
839 | gdk_gc_set_line_attributes( m_penGC, 1, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND ); | |
840 | ||
841 | if (m_signX == -1) | |
842 | { | |
843 | // Different for RTL | |
888dde65 RR |
844 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx+1, yy, ww-2, hh-2 ); |
845 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx, yy-1, ww, hh ); | |
3b5bf828 RR |
846 | } |
847 | else | |
848 | { | |
888dde65 RR |
849 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx, yy, ww-2, hh-2 ); |
850 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx-1, yy-1, ww, hh ); | |
3b5bf828 | 851 | } |
f4322df6 | 852 | |
3b5bf828 RR |
853 | // reset |
854 | gdk_gc_set_line_attributes( m_penGC, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND ); | |
855 | } | |
856 | else | |
3b5bf828 RR |
857 | { |
858 | // Just use X11 for other cases | |
888dde65 | 859 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); |
3b5bf828 RR |
860 | } |
861 | } | |
6db90681 | 862 | } |
7d5af6fa | 863 | |
265898fd RR |
864 | CalcBoundingBox( x, y ); |
865 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 866 | } |
c801d85f | 867 | |
888dde65 | 868 | void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius ) |
c801d85f | 869 | { |
ab171e95 | 870 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 871 | |
265898fd | 872 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); |
7d5af6fa | 873 | |
72cdf4c9 VZ |
874 | wxCoord xx = XLOG2DEV(x); |
875 | wxCoord yy = YLOG2DEV(y); | |
876 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
877 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
878 | wxCoord rr = XLOG2DEVREL((wxCoord)radius); | |
265898fd RR |
879 | |
880 | // CMB: handle -ve width and/or height | |
881 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
882 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
883 | ||
884 | // CMB: if radius is zero use DrawRectangle() instead to avoid | |
885 | // X drawing errors with small radii | |
886 | if (rr == 0) | |
887 | { | |
ab171e95 | 888 | DoDrawRectangle( x, y, width, height ); |
265898fd RR |
889 | return; |
890 | } | |
891 | ||
892 | // CMB: draw nothing if transformed w or h is 0 | |
893 | if (ww == 0 || hh == 0) return; | |
894 | ||
895 | // CMB: adjust size if outline is drawn otherwise the result is | |
896 | // 1 pixel too wide and high | |
e6777e65 | 897 | if ( m_pen.IsNonTransparent() ) |
265898fd RR |
898 | { |
899 | ww--; | |
900 | hh--; | |
901 | } | |
902 | ||
888dde65 | 903 | if (m_gdkwindow) |
265898fd | 904 | { |
6db90681 RR |
905 | // CMB: ensure dd is not larger than rectangle otherwise we |
906 | // get an hour glass shape | |
72cdf4c9 | 907 | wxCoord dd = 2 * rr; |
6db90681 RR |
908 | if (dd > ww) dd = ww; |
909 | if (dd > hh) dd = hh; | |
910 | rr = dd / 2; | |
911 | ||
e6777e65 | 912 | if ( m_brush.IsNonTransparent() ) |
6db90681 | 913 | { |
ea3a345f PC |
914 | GdkGC* gc; |
915 | bool originChanged; | |
916 | DrawingSetup(gc, originChanged); | |
917 | ||
918 | gdk_draw_rectangle(m_gdkwindow, gc, true, xx+rr, yy, ww-dd+1, hh); | |
919 | gdk_draw_rectangle(m_gdkwindow, gc, true, xx, yy+rr, ww, hh-dd+1); | |
920 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, dd, dd, 90*64, 90*64); | |
921 | gdk_draw_arc(m_gdkwindow, gc, true, xx+ww-dd, yy, dd, dd, 0, 90*64); | |
922 | gdk_draw_arc(m_gdkwindow, gc, true, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64); | |
923 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy+hh-dd, dd, dd, 180*64, 90*64); | |
924 | ||
925 | if (originChanged) | |
926 | gdk_gc_set_ts_origin(gc, 0, 0); | |
6db90681 | 927 | } |
7d5af6fa | 928 | |
e6777e65 | 929 | if ( m_pen.IsNonTransparent() ) |
7d5af6fa | 930 | { |
888dde65 RR |
931 | gdk_draw_line( m_gdkwindow, m_penGC, xx+rr+1, yy, xx+ww-rr, yy ); |
932 | gdk_draw_line( m_gdkwindow, m_penGC, xx+rr+1, yy+hh, xx+ww-rr, yy+hh ); | |
933 | gdk_draw_line( m_gdkwindow, m_penGC, xx, yy+rr+1, xx, yy+hh-rr ); | |
934 | gdk_draw_line( m_gdkwindow, m_penGC, xx+ww, yy+rr+1, xx+ww, yy+hh-rr ); | |
935 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 ); | |
936 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); | |
937 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); | |
938 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 ); | |
7d5af6fa | 939 | } |
265898fd | 940 | } |
7d5af6fa | 941 | |
265898fd RR |
942 | // this ignores the radius |
943 | CalcBoundingBox( x, y ); | |
944 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 945 | } |
c801d85f | 946 | |
888dde65 | 947 | void wxWindowDCImpl::DoDrawEllipse( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 948 | { |
ab171e95 | 949 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 950 | |
72cdf4c9 VZ |
951 | wxCoord xx = XLOG2DEV(x); |
952 | wxCoord yy = YLOG2DEV(y); | |
953 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
954 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
6f65e337 | 955 | |
265898fd RR |
956 | // CMB: handle -ve width and/or height |
957 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
958 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
7d5af6fa | 959 | |
888dde65 | 960 | if (m_gdkwindow) |
6db90681 | 961 | { |
e6777e65 | 962 | if ( m_brush.IsNonTransparent() ) |
a56fcaaf | 963 | { |
ea3a345f PC |
964 | GdkGC* gc; |
965 | bool originChanged; | |
966 | DrawingSetup(gc, originChanged); | |
967 | ||
c11bdf68 VZ |
968 | // If the pen is transparent pen we increase the size |
969 | // for better compatibility with other platforms. | |
e0564c1c | 970 | if (m_pen.IsTransparent()) |
c11bdf68 VZ |
971 | { |
972 | ++ww; | |
973 | ++hh; | |
974 | } | |
975 | ||
ea3a345f PC |
976 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, ww, hh, 0, 360*64); |
977 | ||
978 | if (originChanged) | |
979 | gdk_gc_set_ts_origin(gc, 0, 0); | |
a56fcaaf | 980 | } |
7d5af6fa | 981 | |
e6777e65 | 982 | if ( m_pen.IsNonTransparent() ) |
c11bdf68 | 983 | gdk_draw_arc( m_gdkwindow, m_penGC, false, xx, yy, ww, hh, 0, 360*64 ); |
6db90681 | 984 | } |
7d5af6fa | 985 | |
44856297 | 986 | CalcBoundingBox( x, y ); |
265898fd | 987 | CalcBoundingBox( x + width, y + height ); |
903f689b | 988 | } |
c801d85f | 989 | |
888dde65 | 990 | void wxWindowDCImpl::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) |
c801d85f | 991 | { |
b0e0d661 | 992 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why |
ab9d0a8c | 993 | DoDrawBitmap( (const wxBitmap&)icon, x, y, true ); |
903f689b | 994 | } |
c801d85f | 995 | |
eb6ee8ab | 996 | // scale a pixbuf |
02cecc4d PC |
997 | static GdkPixbuf* |
998 | Scale(GdkPixbuf* pixbuf, int dst_w, int dst_h, double sx, double sy) | |
98d8a7ec | 999 | { |
02cecc4d PC |
1000 | GdkPixbuf* pixbuf_scaled = gdk_pixbuf_new( |
1001 | GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha(pixbuf), 8, dst_w, dst_h); | |
1002 | gdk_pixbuf_scale(pixbuf, pixbuf_scaled, | |
1003 | 0, 0, dst_w, dst_h, 0, 0, sx, sy, GDK_INTERP_NEAREST); | |
02cecc4d PC |
1004 | return pixbuf_scaled; |
1005 | } | |
98d8a7ec | 1006 | |
eb6ee8ab | 1007 | // scale part of a pixmap using pixbuf scaling |
02cecc4d PC |
1008 | static GdkPixbuf* |
1009 | Scale(GdkPixmap* pixmap, int x, int y, int w, int h, int dst_w, int dst_h, double sx, double sy) | |
1010 | { | |
1011 | GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable( | |
1012 | NULL, pixmap, NULL, x, y, 0, 0, w, h); | |
eb6ee8ab PC |
1013 | GdkPixbuf* pixbuf2 = Scale(pixbuf, dst_w, dst_h, sx, sy); |
1014 | g_object_unref(pixbuf); | |
1015 | return pixbuf2; | |
98d8a7ec VZ |
1016 | } |
1017 | ||
eb6ee8ab | 1018 | // scale part of a mask pixmap |
02cecc4d PC |
1019 | static GdkPixmap* |
1020 | ScaleMask(GdkPixmap* mask, int x, int y, int w, int h, int dst_w, int dst_h, double sx, double sy) | |
98d8a7ec | 1021 | { |
02cecc4d PC |
1022 | GdkPixbuf* pixbuf = Scale(mask, x, y, w, h, dst_w, dst_h, sx, sy); |
1023 | ||
1024 | // convert black and white pixbuf back to a mono pixmap | |
1025 | const unsigned out_rowstride = (dst_w + 7) / 8; | |
1026 | const size_t data_size = out_rowstride * size_t(dst_h); | |
1027 | char* data = new char[data_size]; | |
1028 | char* out = data; | |
1029 | const guchar* row = gdk_pixbuf_get_pixels(pixbuf); | |
1030 | const int rowstride = gdk_pixbuf_get_rowstride(pixbuf); | |
1031 | memset(data, 0, data_size); | |
1032 | for (int j = 0; j < dst_h; j++, row += rowstride, out += out_rowstride) | |
1033 | { | |
1034 | const guchar* in = row; | |
1035 | for (int i = 0; i < dst_w; i++, in += 3) | |
1036 | if (*in) | |
1037 | out[i >> 3] |= 1 << (i & 7); | |
1038 | } | |
1039 | g_object_unref(pixbuf); | |
1040 | GdkPixmap* pixmap = gdk_bitmap_create_from_data(mask, data, dst_w, dst_h); | |
1041 | delete[] data; | |
02cecc4d | 1042 | return pixmap; |
98d8a7ec VZ |
1043 | } |
1044 | ||
02cecc4d | 1045 | // Make a new mask from part of a mask and a clip region. |
02cecc4d | 1046 | static GdkPixmap* |
a909ef16 | 1047 | ClipMask(GdkPixmap* mask, GdkRegion* clipRegion, int x, int y, int dst_x, int dst_y, int w, int h) |
98d8a7ec | 1048 | { |
02cecc4d PC |
1049 | GdkGCValues gcValues; |
1050 | gcValues.foreground.pixel = 0; | |
1051 | GdkGC* gc = gdk_gc_new_with_values(mask, &gcValues, GDK_GC_FOREGROUND); | |
1052 | GdkPixmap* pixmap = gdk_pixmap_new(mask, w, h, 1); | |
1053 | // clear new mask, so clipped areas will be masked | |
1054 | gdk_draw_rectangle(pixmap, gc, true, 0, 0, w, h); | |
1055 | gdk_gc_set_clip_region(gc, clipRegion); | |
1056 | gdk_gc_set_clip_origin(gc, -dst_x, -dst_y); | |
1057 | // draw old mask onto new one, with clip | |
1058 | gdk_draw_drawable(pixmap, gc, mask, x, y, 0, 0, w, h); | |
1059 | g_object_unref(gc); | |
02cecc4d | 1060 | return pixmap; |
98d8a7ec VZ |
1061 | } |
1062 | ||
02cecc4d PC |
1063 | // make a color pixmap from part of a mono one, using text fg/bg colors |
1064 | GdkPixmap* | |
1065 | wxWindowDCImpl::MonoToColor(GdkPixmap* monoPixmap, int x, int y, int w, int h) const | |
98d8a7ec | 1066 | { |
02cecc4d PC |
1067 | GdkPixmap* pixmap = gdk_pixmap_new(m_gdkwindow, w, h, -1); |
1068 | GdkGCValues gcValues; | |
1069 | gcValues.foreground.pixel = m_textForegroundColour.GetColor()->pixel; | |
1070 | gcValues.background.pixel = m_textBackgroundColour.GetColor()->pixel; | |
1071 | gcValues.stipple = monoPixmap; | |
1072 | gcValues.fill = GDK_OPAQUE_STIPPLED; | |
1073 | gcValues.ts_x_origin = -x; | |
1074 | gcValues.ts_y_origin = -y; | |
1075 | GdkGC* gc = gdk_gc_new_with_values(pixmap, &gcValues, GdkGCValuesMask( | |
1076 | GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_STIPPLE | GDK_GC_FILL | | |
1077 | GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN)); | |
1078 | gdk_draw_rectangle(pixmap, gc, true, 0, 0, w, h); | |
1079 | g_object_unref(gc); | |
1080 | return pixmap; | |
98d8a7ec VZ |
1081 | } |
1082 | ||
888dde65 | 1083 | void wxWindowDCImpl::DoDrawBitmap( const wxBitmap &bitmap, |
72cdf4c9 | 1084 | wxCoord x, wxCoord y, |
b0e0d661 | 1085 | bool useMask ) |
4bc67cc5 | 1086 | { |
ab171e95 | 1087 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
ab171e95 | 1088 | wxCHECK_RET( bitmap.IsOk(), wxT("invalid bitmap") ); |
7d5af6fa | 1089 | |
02cecc4d | 1090 | if (!m_gdkwindow) return; |
f4322df6 | 1091 | |
02cecc4d PC |
1092 | const int w = bitmap.GetWidth(); |
1093 | const int h = bitmap.GetHeight(); | |
7d5af6fa | 1094 | |
15b85007 VZ |
1095 | // notice that as the bitmap is not drawn upside down (or right to left) |
1096 | // even if the corresponding axis direction is inversed, we need to take it | |
1097 | // into account when calculating its bounding box | |
02cecc4d | 1098 | CalcBoundingBox(x, y); |
15b85007 | 1099 | CalcBoundingBox(x + m_signX*w, y + m_signY*h); |
7d5af6fa | 1100 | |
02cecc4d PC |
1101 | // device coords |
1102 | int xx = LogicalToDeviceX(x); | |
1103 | const int yy = LogicalToDeviceY(y); | |
1104 | const int ww = LogicalToDeviceXRel(w); | |
1105 | const int hh = LogicalToDeviceYRel(h); | |
7d5af6fa | 1106 | |
6226d1e9 PC |
1107 | if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) |
1108 | xx -= ww; | |
1109 | ||
a909ef16 | 1110 | GdkRegion* const clipRegion = m_currentClippingRegion.GetRegion(); |
02cecc4d PC |
1111 | // determine clip region overlap |
1112 | int overlap = wxInRegion; | |
1113 | if (clipRegion) | |
1114 | { | |
1115 | overlap = m_currentClippingRegion.Contains(xx, yy, ww, hh); | |
1116 | if (overlap == wxOutRegion) | |
1117 | return; | |
1118 | } | |
7d5af6fa | 1119 | |
02cecc4d PC |
1120 | const bool isScaled = ww != w || hh != h; |
1121 | const bool hasAlpha = bitmap.HasAlpha(); | |
1122 | GdkGC* const use_gc = m_penGC; | |
ab9d0a8c | 1123 | |
02cecc4d PC |
1124 | GdkPixmap* mask = NULL; |
1125 | // mask does not work when drawing a pixbuf with alpha | |
1126 | if (useMask && !hasAlpha) | |
1127 | { | |
1128 | wxMask* m = bitmap.GetMask(); | |
1129 | if (m) | |
5ca21fe7 | 1130 | mask = *m; |
02cecc4d | 1131 | } |
c92374f0 VZ |
1132 | |
1133 | GdkPixmap* mask_new = NULL; | |
02cecc4d | 1134 | if (mask) |
d90c9596 | 1135 | { |
02cecc4d | 1136 | if (isScaled) |
eb6ee8ab | 1137 | { |
02cecc4d | 1138 | mask = ScaleMask(mask, 0, 0, w, h, ww, hh, m_scaleX, m_scaleY); |
eb6ee8ab PC |
1139 | mask_new = mask; |
1140 | } | |
02cecc4d | 1141 | if (overlap == wxPartRegion) |
82ea63e6 | 1142 | { |
02cecc4d PC |
1143 | // need a new mask that also masks the clipped area, |
1144 | // because gc can't have both a mask and a clip region | |
1145 | mask = ClipMask(mask, clipRegion, 0, 0, xx, yy, ww, hh); | |
eb6ee8ab PC |
1146 | if (mask_new) |
1147 | g_object_unref(mask_new); | |
1148 | mask_new = mask; | |
d90c9596 | 1149 | } |
280831d5 PC |
1150 | gdk_gc_set_clip_mask(use_gc, mask); |
1151 | gdk_gc_set_clip_origin(use_gc, xx, yy); | |
d90c9596 | 1152 | } |
7d5af6fa | 1153 | |
02cecc4d PC |
1154 | // determine whether to use pixmap or pixbuf |
1155 | GdkPixmap* pixmap = NULL; | |
eb6ee8ab | 1156 | GdkPixmap* pixmap_new = NULL; |
02cecc4d | 1157 | GdkPixbuf* pixbuf = NULL; |
eb6ee8ab | 1158 | GdkPixbuf* pixbuf_new = NULL; |
02cecc4d PC |
1159 | if (bitmap.HasPixmap()) |
1160 | pixmap = bitmap.GetPixmap(); | |
1161 | if (pixmap && gdk_drawable_get_depth(pixmap) == 1) | |
d90c9596 | 1162 | { |
d4ca3c5d PC |
1163 | if (gdk_drawable_get_depth(m_gdkwindow) != 1) |
1164 | { | |
1165 | // convert mono pixmap to color using text fg/bg colors | |
1166 | pixmap = MonoToColor(pixmap, 0, 0, w, h); | |
1167 | pixmap_new = pixmap; | |
1168 | } | |
02cecc4d PC |
1169 | } |
1170 | else if (hasAlpha || pixmap == NULL) | |
02cecc4d | 1171 | pixbuf = bitmap.GetPixbuf(); |
02cecc4d PC |
1172 | |
1173 | if (isScaled) | |
1174 | { | |
1175 | if (pixbuf) | |
1176 | pixbuf = Scale(pixbuf, ww, hh, m_scaleX, m_scaleY); | |
feac7937 | 1177 | else |
02cecc4d | 1178 | pixbuf = Scale(pixmap, 0, 0, w, h, ww, hh, m_scaleX, m_scaleY); |
eb6ee8ab PC |
1179 | |
1180 | pixbuf_new = pixbuf; | |
02cecc4d PC |
1181 | } |
1182 | ||
1183 | if (pixbuf) | |
1184 | { | |
1185 | gdk_draw_pixbuf(m_gdkwindow, use_gc, pixbuf, | |
1186 | 0, 0, xx, yy, ww, hh, GDK_RGB_DITHER_NORMAL, 0, 0); | |
02cecc4d PC |
1187 | } |
1188 | else | |
1189 | { | |
1190 | gdk_draw_drawable(m_gdkwindow, use_gc, pixmap, 0, 0, xx, yy, ww, hh); | |
d90c9596 | 1191 | } |
72174350 | 1192 | |
eb6ee8ab PC |
1193 | if (pixbuf_new) |
1194 | g_object_unref(pixbuf_new); | |
1195 | if (pixmap_new) | |
1196 | g_object_unref(pixmap_new); | |
02cecc4d | 1197 | if (mask) |
c92374f0 | 1198 | { |
02cecc4d | 1199 | gdk_gc_set_clip_region(use_gc, clipRegion); |
c92374f0 VZ |
1200 | |
1201 | // Notice that we can only release the mask now, we can't do it before | |
1202 | // the calls to gdk_draw_xxx() above as they crash with X error with | |
1203 | // GTK+ up to 2.20.1 (i.e. it works with 2.20 but is known to not work | |
1204 | // with 2.16.1 and below). | |
1205 | if (mask_new) | |
1206 | g_object_unref(mask_new); | |
1207 | } | |
463c1fa1 RR |
1208 | } |
1209 | ||
888dde65 | 1210 | bool wxWindowDCImpl::DoBlit( wxCoord xdest, wxCoord ydest, |
1e6feb95 VZ |
1211 | wxCoord width, wxCoord height, |
1212 | wxDC *source, | |
1213 | wxCoord xsrc, wxCoord ysrc, | |
89efaf2b | 1214 | wxRasterOperationMode logical_func, |
0cbff120 JS |
1215 | bool useMask, |
1216 | wxCoord xsrcMask, wxCoord ysrcMask ) | |
c801d85f | 1217 | { |
ab171e95 | 1218 | wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") ); |
ab9d0a8c | 1219 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
7d5af6fa | 1220 | |
888dde65 | 1221 | if (!m_gdkwindow) return false; |
7d5af6fa | 1222 | |
02cecc4d PC |
1223 | GdkDrawable* srcDrawable = NULL; |
1224 | GdkPixmap* mask = NULL; | |
1225 | wxMemoryDC* memDC = wxDynamicCast(source, wxMemoryDC); | |
1226 | if (memDC) | |
e19a8aea | 1227 | { |
02cecc4d PC |
1228 | const wxBitmap& bitmap = memDC->GetSelectedBitmap(); |
1229 | if (!bitmap.IsOk()) | |
e19a8aea | 1230 | return false; |
02cecc4d PC |
1231 | srcDrawable = bitmap.GetPixmap(); |
1232 | if (useMask) | |
1233 | { | |
1234 | wxMask* m = bitmap.GetMask(); | |
1235 | if (m) | |
5ca21fe7 | 1236 | mask = *m; |
02cecc4d | 1237 | } |
e19a8aea | 1238 | } |
02cecc4d | 1239 | else |
0cbff120 | 1240 | { |
02cecc4d PC |
1241 | wxDCImpl* impl = source->GetImpl(); |
1242 | wxWindowDCImpl* gtk_impl = wxDynamicCast(impl, wxWindowDCImpl); | |
1243 | if (gtk_impl) | |
1244 | srcDrawable = gtk_impl->GetGDKWindow(); | |
1245 | if (srcDrawable == NULL) | |
1246 | return false; | |
0cbff120 JS |
1247 | } |
1248 | ||
02cecc4d PC |
1249 | CalcBoundingBox(xdest, ydest); |
1250 | CalcBoundingBox(xdest + width, ydest + height); | |
1251 | ||
1252 | // source device coords | |
1253 | int src_x = source->LogicalToDeviceX(xsrc); | |
1254 | int src_y = source->LogicalToDeviceY(ysrc); | |
1255 | int src_w = source->LogicalToDeviceXRel(width); | |
1256 | int src_h = source->LogicalToDeviceYRel(height); | |
1257 | ||
1258 | // Clip source rect to source dc. | |
1259 | // Only necessary when scaling, to avoid GDK errors when | |
1260 | // converting to pixbuf, but no harm in always doing it. | |
1261 | // If source rect changes, it also changes the dest rect. | |
1262 | wxRect clip; | |
1263 | gdk_drawable_get_size(srcDrawable, &clip.width, &clip.height); | |
1264 | clip.Intersect(wxRect(src_x, src_y, src_w, src_h)); | |
1265 | if (src_w != clip.width || src_h != clip.height) | |
6e13c196 | 1266 | { |
02cecc4d PC |
1267 | if (clip.width == 0) |
1268 | return true; | |
1269 | ||
1270 | src_w = clip.width; | |
1271 | src_h = clip.height; | |
1272 | width = source->DeviceToLogicalXRel(src_w); | |
1273 | height = source->DeviceToLogicalYRel(src_h); | |
1274 | if (src_x != clip.x || src_y != clip.y) | |
b0e0d661 | 1275 | { |
02cecc4d PC |
1276 | xdest += source->DeviceToLogicalXRel(clip.x - src_x); |
1277 | ydest += source->DeviceToLogicalYRel(clip.y - src_y); | |
1278 | src_x = clip.x; | |
1279 | src_y = clip.y; | |
b0e0d661 | 1280 | } |
6e13c196 | 1281 | } |
7d5af6fa | 1282 | |
02cecc4d PC |
1283 | // destination device coords |
1284 | const int dst_x = LogicalToDeviceX(xdest); | |
1285 | const int dst_y = LogicalToDeviceY(ydest); | |
1286 | const int dst_w = LogicalToDeviceXRel(width); | |
1287 | const int dst_h = LogicalToDeviceYRel(height); | |
3d2d8da1 | 1288 | |
a909ef16 | 1289 | GdkRegion* const clipRegion = m_currentClippingRegion.GetRegion(); |
02cecc4d PC |
1290 | // determine dest clip region overlap |
1291 | int overlap = wxInRegion; | |
1292 | if (clipRegion) | |
6f65e337 | 1293 | { |
02cecc4d PC |
1294 | overlap = m_currentClippingRegion.Contains(dst_x, dst_y, dst_w, dst_h); |
1295 | if (overlap == wxOutRegion) | |
1296 | return true; | |
1297 | } | |
ab9d0a8c | 1298 | |
02cecc4d PC |
1299 | const bool isScaled = src_w != dst_w || src_h != dst_h; |
1300 | double scale_x = 0; | |
1301 | double scale_y = 0; | |
1302 | if (isScaled) | |
1303 | { | |
1304 | // get source to dest scale | |
1305 | double usx, usy, lsx, lsy; | |
1306 | source->GetUserScale(&usx, &usy); | |
1307 | source->GetLogicalScale(&lsx, &lsy); | |
1308 | scale_x = m_scaleX / (usx * lsx); | |
1309 | scale_y = m_scaleY / (usy * lsy); | |
1310 | } | |
d90c9596 | 1311 | |
02cecc4d | 1312 | GdkGC* const use_gc = m_penGC; |
7d5af6fa | 1313 | |
02cecc4d PC |
1314 | if (mask) |
1315 | { | |
02cecc4d PC |
1316 | int srcMask_x = src_x; |
1317 | int srcMask_y = src_y; | |
1318 | if (xsrcMask != -1 || ysrcMask != -1) | |
d90c9596 | 1319 | { |
02cecc4d PC |
1320 | srcMask_x = source->LogicalToDeviceX(xsrcMask); |
1321 | srcMask_y = source->LogicalToDeviceY(ysrcMask); | |
d90c9596 | 1322 | } |
eb6ee8ab | 1323 | GdkPixmap* mask_new = NULL; |
02cecc4d | 1324 | if (isScaled) |
d90c9596 | 1325 | { |
02cecc4d PC |
1326 | mask = ScaleMask(mask, srcMask_x, srcMask_y, |
1327 | src_w, src_h, dst_w, dst_h, scale_x, scale_y); | |
eb6ee8ab | 1328 | mask_new = mask; |
02cecc4d PC |
1329 | srcMask_x = 0; |
1330 | srcMask_y = 0; | |
d90c9596 | 1331 | } |
02cecc4d | 1332 | if (overlap == wxPartRegion) |
6e13c196 | 1333 | { |
02cecc4d PC |
1334 | // need a new mask that also masks the clipped area, |
1335 | // because gc can't have both a mask and a clip region | |
1336 | mask = ClipMask(mask, clipRegion, | |
1337 | srcMask_x, srcMask_y, dst_x, dst_y, dst_w, dst_h); | |
eb6ee8ab PC |
1338 | if (mask_new) |
1339 | g_object_unref(mask_new); | |
1340 | mask_new = mask; | |
02cecc4d PC |
1341 | srcMask_x = 0; |
1342 | srcMask_y = 0; | |
265898fd | 1343 | } |
02cecc4d PC |
1344 | gdk_gc_set_clip_mask(use_gc, mask); |
1345 | gdk_gc_set_clip_origin(use_gc, dst_x - srcMask_x, dst_y - srcMask_y); | |
eb6ee8ab PC |
1346 | if (mask_new) |
1347 | g_object_unref(mask_new); | |
6f65e337 | 1348 | } |
02cecc4d PC |
1349 | |
1350 | GdkPixmap* pixmap = NULL; | |
d4ca3c5d PC |
1351 | if (gdk_drawable_get_depth(srcDrawable) == 1 && |
1352 | (gdk_drawable_get_depth(m_gdkwindow) != 1 || isScaled)) | |
6e13c196 | 1353 | { |
02cecc4d PC |
1354 | // Convert mono pixmap to color using text fg/bg colors. |
1355 | // Scaling/drawing is simpler if this is done first. | |
1356 | pixmap = MonoToColor(srcDrawable, src_x, src_y, src_w, src_h); | |
1357 | srcDrawable = pixmap; | |
1358 | src_x = 0; | |
1359 | src_y = 0; | |
1360 | } | |
f4322df6 | 1361 | |
89efaf2b | 1362 | const wxRasterOperationMode logical_func_save = m_logicalFunction; |
02cecc4d PC |
1363 | SetLogicalFunction(logical_func); |
1364 | if (memDC == NULL) | |
1365 | gdk_gc_set_subwindow(use_gc, GDK_INCLUDE_INFERIORS); | |
1366 | ||
1367 | if (isScaled) | |
1368 | { | |
1369 | GdkPixbuf* pixbuf = Scale(srcDrawable, | |
1370 | src_x, src_y, src_w, src_h, dst_w, dst_h, scale_x, scale_y); | |
1371 | gdk_draw_pixbuf(m_gdkwindow, use_gc, pixbuf, | |
1372 | 0, 0, dst_x, dst_y, dst_w, dst_h, GDK_RGB_DITHER_NONE, 0, 0); | |
1373 | g_object_unref(pixbuf); | |
1374 | } | |
1375 | else | |
1376 | { | |
1377 | gdk_draw_drawable(m_gdkwindow, use_gc, srcDrawable, | |
1378 | src_x, src_y, dst_x, dst_y, dst_w, dst_h); | |
6e13c196 | 1379 | } |
c801d85f | 1380 | |
02cecc4d PC |
1381 | SetLogicalFunction(logical_func_save); |
1382 | if (memDC == NULL) | |
1383 | gdk_gc_set_subwindow(use_gc, GDK_CLIP_BY_CHILDREN); | |
ab9d0a8c | 1384 | |
02cecc4d PC |
1385 | if (pixmap) |
1386 | g_object_unref(pixmap); | |
1387 | if (mask) | |
02cecc4d | 1388 | gdk_gc_set_clip_region(use_gc, clipRegion); |
eb6ee8ab | 1389 | |
ab9d0a8c | 1390 | return true; |
903f689b | 1391 | } |
c801d85f | 1392 | |
2dcf60da VZ |
1393 | void wxWindowDCImpl::DoDrawText(const wxString& text, |
1394 | wxCoord xLogical, | |
1395 | wxCoord yLogical) | |
c801d85f | 1396 | { |
be1f9024 | 1397 | DoDrawRotatedText(text, xLogical, yLogical, 0); |
903f689b | 1398 | } |
c801d85f | 1399 | |
be1f9024 | 1400 | void wxWindowDCImpl::DoDrawRotatedText(const wxString& text, int xLogical, int yLogical, double angle) |
95724b1a | 1401 | { |
888dde65 | 1402 | if (!m_gdkwindow || text.empty()) |
1c2d839f PC |
1403 | return; |
1404 | ||
ab171e95 | 1405 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
1c2d839f | 1406 | |
c49ba211 PC |
1407 | pango_layout_set_text(m_layout, wxGTK_CONV(text), -1); |
1408 | const bool setAttrs = m_font.GTKSetPangoAttrs(m_layout); | |
e1bd1db2 | 1409 | |
c49ba211 PC |
1410 | const GdkColor* bg_col = NULL; |
1411 | if (m_backgroundMode == wxBRUSHSTYLE_SOLID) | |
1412 | bg_col = m_textBackgroundColour.GetColor(); | |
e1bd1db2 | 1413 | |
c49ba211 | 1414 | PangoMatrix matrix = PANGO_MATRIX_INIT; |
3e5a70b5 PC |
1415 | if (!wxIsSameDouble(m_scaleX, 1) || !wxIsSameDouble(m_scaleY, 1) || !wxIsNullDouble(angle)) |
1416 | { | |
1417 | pango_matrix_scale(&matrix, m_scaleX, m_scaleY); | |
1418 | pango_matrix_rotate(&matrix, angle); | |
1419 | pango_context_set_matrix(m_context, &matrix); | |
1420 | pango_layout_context_changed(m_layout); | |
1421 | } | |
c49ba211 | 1422 | |
be1f9024 PC |
1423 | int w, h; |
1424 | pango_layout_get_pixel_size(m_layout, &w, &h); | |
e1bd1db2 | 1425 | |
be1f9024 PC |
1426 | int x = LogicalToDeviceX(xLogical); |
1427 | int y = LogicalToDeviceY(yLogical); | |
1428 | if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) | |
1429 | x -= LogicalToDeviceXRel(w); | |
c49ba211 | 1430 | |
be1f9024 PC |
1431 | if (wxIsNullDouble(angle)) |
1432 | { | |
1433 | CalcBoundingBox(xLogical, yLogical); | |
1434 | CalcBoundingBox(xLogical + w, yLogical + h); | |
1435 | } | |
1436 | else | |
1437 | { | |
1438 | // To be compatible with MSW, the rotation axis must be in the old | |
1439 | // top-left corner. | |
1440 | // Calculate the vertices of the rotated rectangle containing the text, | |
1441 | // relative to the old top-left vertex. | |
1442 | // the rectangle vertices are counted clockwise with the first one | |
1443 | // being at (0, 0) | |
1444 | double x2 = w * matrix.xx; | |
1445 | double y2 = w * matrix.yx; | |
1446 | double x4 = h * matrix.xy; | |
1447 | double y4 = h * matrix.yy; | |
1448 | double x3 = x4 + x2; | |
1449 | double y3 = y4 + y2; | |
1450 | // Then we calculate max and min of the rotated rectangle. | |
1451 | wxCoord maxX = (wxCoord)(dmax(dmax(0, x2), dmax(x3, x4)) + 0.5), | |
1452 | maxY = (wxCoord)(dmax(dmax(0, y2), dmax(y3, y4)) + 0.5), | |
1453 | minX = (wxCoord)(dmin(dmin(0, x2), dmin(x3, x4)) - 0.5), | |
1454 | minY = (wxCoord)(dmin(dmin(0, y2), dmin(y3, y4)) - 0.5); | |
1455 | x += minX; | |
1456 | y += minY; | |
1457 | CalcBoundingBox(DeviceToLogicalX(x), DeviceToLogicalY(y)); | |
1458 | CalcBoundingBox(DeviceToLogicalX(x + maxX - minX), DeviceToLogicalY(y + maxY - minY)); | |
1459 | } | |
1460 | ||
1461 | gdk_draw_layout_with_colors(m_gdkwindow, m_textGC, x, y, m_layout, NULL, bg_col); | |
e1bd1db2 | 1462 | |
be1f9024 PC |
1463 | pango_context_set_matrix(m_context, NULL); |
1464 | if (setAttrs) | |
1465 | pango_layout_set_attributes(m_layout, NULL); | |
95724b1a VZ |
1466 | } |
1467 | ||
888dde65 | 1468 | void wxWindowDCImpl::DoGetTextExtent(const wxString &string, |
72cdf4c9 VZ |
1469 | wxCoord *width, wxCoord *height, |
1470 | wxCoord *descent, wxCoord *externalLeading, | |
c94f845b | 1471 | const wxFont *theFont) const |
c801d85f | 1472 | { |
8cd79b7a VZ |
1473 | // ensure we work with a valid font |
1474 | const wxFont *fontToUse; | |
ab171e95 | 1475 | if ( !theFont || !theFont->IsOk() ) |
8cd79b7a VZ |
1476 | fontToUse = &m_font; |
1477 | else | |
1478 | fontToUse = theFont; | |
ab9d0a8c | 1479 | |
8cd79b7a | 1480 | wxCHECK_RET( fontToUse->IsOk(), wxT("invalid font") ); |
ab9d0a8c | 1481 | |
8cd79b7a VZ |
1482 | wxTextMeasure txm(GetOwner(), fontToUse); |
1483 | txm.GetTextExtent(string, width, height, descent, externalLeading); | |
903f689b | 1484 | } |
c801d85f | 1485 | |
1f91072f | 1486 | |
888dde65 | 1487 | bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString& text, |
1f91072f VZ |
1488 | wxArrayInt& widths) const |
1489 | { | |
8cd79b7a | 1490 | wxCHECK_MSG( m_font.IsOk(), false, wxT("Invalid font") ); |
1f91072f | 1491 | |
8cd79b7a VZ |
1492 | wxTextMeasure txm(GetOwner(), &m_font); |
1493 | return txm.GetPartialTextExtents(text, widths, m_scaleX); | |
1f91072f VZ |
1494 | } |
1495 | ||
1496 | ||
888dde65 | 1497 | wxCoord wxWindowDCImpl::GetCharWidth() const |
c801d85f | 1498 | { |
cfcc3932 | 1499 | pango_layout_set_text( m_layout, "H", 1 ); |
ace35c62 RR |
1500 | int w; |
1501 | pango_layout_get_pixel_size( m_layout, &w, NULL ); | |
2b5f62a0 | 1502 | return w; |
903f689b | 1503 | } |
c801d85f | 1504 | |
888dde65 | 1505 | wxCoord wxWindowDCImpl::GetCharHeight() const |
c801d85f | 1506 | { |
a8c5e1a9 | 1507 | PangoFontMetrics *metrics = pango_context_get_metrics (m_context, m_fontdesc, pango_context_get_language(m_context)); |
9a83f860 | 1508 | wxCHECK_MSG( metrics, -1, wxT("failed to get pango font metrics") ); |
2e61f681 VZ |
1509 | |
1510 | wxCoord h = PANGO_PIXELS (pango_font_metrics_get_descent (metrics) + | |
b5791cc7 | 1511 | pango_font_metrics_get_ascent (metrics)); |
2e61f681 VZ |
1512 | pango_font_metrics_unref (metrics); |
1513 | return h; | |
903f689b | 1514 | } |
c801d85f | 1515 | |
888dde65 | 1516 | void wxWindowDCImpl::Clear() |
c801d85f | 1517 | { |
ab171e95 | 1518 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1519 | |
888dde65 | 1520 | if (!m_gdkwindow) return; |
7d5af6fa | 1521 | |
f60e7fdd | 1522 | int width,height; |
ab171e95 | 1523 | DoGetSize( &width, &height ); |
888dde65 | 1524 | gdk_draw_rectangle( m_gdkwindow, m_bgGC, TRUE, 0, 0, width, height ); |
903f689b | 1525 | } |
c801d85f | 1526 | |
888dde65 | 1527 | void wxWindowDCImpl::SetFont( const wxFont &font ) |
c801d85f | 1528 | { |
265898fd | 1529 | m_font = font; |
ab9d0a8c | 1530 | |
ab171e95 | 1531 | if (m_font.IsOk()) |
2b5f62a0 | 1532 | { |
cfcc3932 RR |
1533 | if (m_fontdesc) |
1534 | pango_font_description_free( m_fontdesc ); | |
ab9d0a8c | 1535 | |
cfcc3932 | 1536 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
ab9d0a8c WS |
1537 | |
1538 | ||
888dde65 | 1539 | if (m_window) |
77416abd | 1540 | { |
cfcc3932 | 1541 | PangoContext *oldContext = m_context; |
ab9d0a8c | 1542 | |
496e7ec6 | 1543 | m_context = m_window->GTKGetPangoDefaultContext(); |
ab9d0a8c | 1544 | |
cfcc3932 RR |
1545 | // If we switch back/forth between different contexts |
1546 | // we also have to create a new layout. I think so, | |
ab9d0a8c | 1547 | // at least, and it doesn't hurt to do it. |
cfcc3932 RR |
1548 | if (oldContext != m_context) |
1549 | { | |
1550 | if (m_layout) | |
3fe39b0c | 1551 | g_object_unref (m_layout); |
ab9d0a8c | 1552 | |
cfcc3932 RR |
1553 | m_layout = pango_layout_new( m_context ); |
1554 | } | |
77416abd | 1555 | } |
ab9d0a8c | 1556 | |
cfcc3932 | 1557 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
2b5f62a0 | 1558 | } |
903f689b | 1559 | } |
c801d85f | 1560 | |
888dde65 | 1561 | void wxWindowDCImpl::SetPen( const wxPen &pen ) |
c801d85f | 1562 | { |
ab171e95 | 1563 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1564 | |
265898fd | 1565 | if (m_pen == pen) return; |
7d5af6fa | 1566 | |
265898fd | 1567 | m_pen = pen; |
7d5af6fa | 1568 | |
ab171e95 | 1569 | if (!m_pen.IsOk()) return; |
7d5af6fa | 1570 | |
888dde65 | 1571 | if (!m_gdkwindow) return; |
7d5af6fa | 1572 | |
265898fd | 1573 | gint width = m_pen.GetWidth(); |
265898fd RR |
1574 | if (width <= 0) |
1575 | { | |
112c5086 | 1576 | // CMB: if width is non-zero scale it with the dc |
265898fd RR |
1577 | width = 1; |
1578 | } | |
1579 | else | |
1580 | { | |
1581 | // X doesn't allow different width in x and y and so we take | |
1582 | // the average | |
503f414e VZ |
1583 | double w = 0.5 + |
1584 | ( fabs((double) XLOG2DEVREL(width)) + | |
1585 | fabs((double) YLOG2DEVREL(width)) ) / 2.0; | |
265898fd | 1586 | width = (int)w; |
375fc5a9 VZ |
1587 | if ( !width ) |
1588 | { | |
1589 | // width can't be 0 or an internal GTK error occurs inside | |
1590 | // gdk_gc_set_dashes() below | |
1591 | width = 1; | |
1592 | } | |
265898fd | 1593 | } |
7d5af6fa | 1594 | |
2eca425d RL |
1595 | static const wxGTKDash dotted[] = {1, 1}; |
1596 | static const wxGTKDash short_dashed[] = {2, 2}; | |
1597 | static const wxGTKDash wxCoord_dashed[] = {2, 4}; | |
1598 | static const wxGTKDash dotted_dashed[] = {3, 3, 1, 3}; | |
7d5af6fa | 1599 | |
112c5086 RR |
1600 | // We express dash pattern in pen width unit, so we are |
1601 | // independent of zoom factor and so on... | |
1602 | int req_nb_dash; | |
2eca425d | 1603 | const wxGTKDash *req_dash; |
7d5af6fa | 1604 | |
86d58c90 | 1605 | GdkLineStyle lineStyle = GDK_LINE_ON_OFF_DASH; |
265898fd RR |
1606 | switch (m_pen.GetStyle()) |
1607 | { | |
04ee05f9 | 1608 | case wxPENSTYLE_USER_DASH: |
112c5086 | 1609 | req_nb_dash = m_pen.GetDashCount(); |
2eca425d | 1610 | req_dash = (wxGTKDash*)m_pen.GetDash(); |
112c5086 | 1611 | break; |
04ee05f9 | 1612 | case wxPENSTYLE_DOT: |
112c5086 RR |
1613 | req_nb_dash = 2; |
1614 | req_dash = dotted; | |
7d5af6fa | 1615 | break; |
04ee05f9 | 1616 | case wxPENSTYLE_LONG_DASH: |
112c5086 | 1617 | req_nb_dash = 2; |
72cdf4c9 | 1618 | req_dash = wxCoord_dashed; |
7d5af6fa | 1619 | break; |
04ee05f9 | 1620 | case wxPENSTYLE_SHORT_DASH: |
112c5086 RR |
1621 | req_nb_dash = 2; |
1622 | req_dash = short_dashed; | |
7d5af6fa | 1623 | break; |
04ee05f9 | 1624 | case wxPENSTYLE_DOT_DASH: |
112c5086 RR |
1625 | req_nb_dash = 4; |
1626 | req_dash = dotted_dashed; | |
7d5af6fa | 1627 | break; |
7d5af6fa | 1628 | |
04ee05f9 PC |
1629 | case wxPENSTYLE_TRANSPARENT: |
1630 | case wxPENSTYLE_STIPPLE_MASK_OPAQUE: | |
1631 | case wxPENSTYLE_STIPPLE: | |
1632 | case wxPENSTYLE_SOLID: | |
7d5af6fa | 1633 | default: |
7d5af6fa | 1634 | lineStyle = GDK_LINE_SOLID; |
d3b9f782 | 1635 | req_dash = NULL; |
112c5086 | 1636 | req_nb_dash = 0; |
7d5af6fa | 1637 | break; |
265898fd | 1638 | } |
7d5af6fa | 1639 | |
112c5086 RR |
1640 | if (req_dash && req_nb_dash) |
1641 | { | |
2eca425d | 1642 | wxGTKDash *real_req_dash = new wxGTKDash[req_nb_dash]; |
112c5086 RR |
1643 | if (real_req_dash) |
1644 | { | |
1645 | for (int i = 0; i < req_nb_dash; i++) | |
1646 | real_req_dash[i] = req_dash[i] * width; | |
2eca425d | 1647 | gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash ); |
112c5086 RR |
1648 | delete[] real_req_dash; |
1649 | } | |
1650 | else | |
1651 | { | |
1652 | // No Memory. We use non-scaled dash pattern... | |
2eca425d | 1653 | gdk_gc_set_dashes( m_penGC, 0, (wxGTKDash*)req_dash, req_nb_dash ); |
112c5086 RR |
1654 | } |
1655 | } | |
7d5af6fa | 1656 | |
265898fd RR |
1657 | GdkCapStyle capStyle = GDK_CAP_ROUND; |
1658 | switch (m_pen.GetCap()) | |
1659 | { | |
265898fd RR |
1660 | case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; } |
1661 | case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; } | |
d4aa3a4b RR |
1662 | case wxCAP_ROUND: |
1663 | default: | |
d4aa3a4b RR |
1664 | if (width <= 1) |
1665 | { | |
1666 | width = 0; | |
1667 | capStyle = GDK_CAP_NOT_LAST; | |
1668 | } | |
72174350 | 1669 | break; |
265898fd | 1670 | } |
7d5af6fa | 1671 | |
265898fd RR |
1672 | GdkJoinStyle joinStyle = GDK_JOIN_ROUND; |
1673 | switch (m_pen.GetJoin()) | |
1674 | { | |
1675 | case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; } | |
265898fd | 1676 | case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; } |
d4aa3a4b RR |
1677 | case wxJOIN_ROUND: |
1678 | default: { joinStyle = GDK_JOIN_ROUND; break; } | |
265898fd | 1679 | } |
7d5af6fa | 1680 | |
265898fd | 1681 | gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle ); |
7d5af6fa | 1682 | |
265898fd RR |
1683 | m_pen.GetColour().CalcPixel( m_cmap ); |
1684 | gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() ); | |
903f689b | 1685 | } |
c801d85f | 1686 | |
888dde65 | 1687 | void wxWindowDCImpl::SetBrush( const wxBrush &brush ) |
c801d85f | 1688 | { |
ab171e95 | 1689 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1690 | |
265898fd | 1691 | if (m_brush == brush) return; |
7d5af6fa | 1692 | |
265898fd | 1693 | m_brush = brush; |
7d5af6fa | 1694 | |
ab171e95 | 1695 | if (!m_brush.IsOk()) return; |
7d5af6fa | 1696 | |
888dde65 | 1697 | if (!m_gdkwindow) return; |
7d5af6fa | 1698 | |
265898fd RR |
1699 | m_brush.GetColour().CalcPixel( m_cmap ); |
1700 | gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() ); | |
7d5af6fa | 1701 | |
956dbab1 | 1702 | gdk_gc_set_fill( m_brushGC, GDK_SOLID ); |
7d5af6fa | 1703 | |
04ee05f9 | 1704 | if ((m_brush.GetStyle() == wxBRUSHSTYLE_STIPPLE) && (m_brush.GetStipple()->IsOk())) |
265898fd | 1705 | { |
b85229d1 | 1706 | if (m_brush.GetStipple()->GetDepth() != 1) |
7d5af6fa | 1707 | { |
956dbab1 | 1708 | gdk_gc_set_fill( m_brushGC, GDK_TILED ); |
cd25b18c | 1709 | gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() ); |
7d5af6fa | 1710 | } |
b0e0d661 | 1711 | else |
7d5af6fa | 1712 | { |
956dbab1 | 1713 | gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); |
b85229d1 | 1714 | gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() ); |
7d5af6fa | 1715 | } |
265898fd | 1716 | } |
7d5af6fa | 1717 | |
04ee05f9 | 1718 | if ((m_brush.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) |
de2d2cdc | 1719 | { |
e1208c31 | 1720 | gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); |
5ca21fe7 | 1721 | gdk_gc_set_stipple( m_textGC, *m_brush.GetStipple()->GetMask() ); |
de2d2cdc VZ |
1722 | } |
1723 | ||
ab9d0a8c | 1724 | if (m_brush.IsHatch()) |
265898fd | 1725 | { |
956dbab1 | 1726 | gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); |
f7732fa5 | 1727 | gdk_gc_set_stipple(m_brushGC, GetHatch(m_brush.GetStyle())); |
265898fd | 1728 | } |
903f689b | 1729 | } |
c801d85f | 1730 | |
888dde65 | 1731 | void wxWindowDCImpl::SetBackground( const wxBrush &brush ) |
46dc76ba | 1732 | { |
bbbbe360 RR |
1733 | /* CMB 21/7/98: Added SetBackground. Sets background brush |
1734 | * for Clear() and bg colour for shapes filled with cross-hatch brush */ | |
7d5af6fa | 1735 | |
ab171e95 | 1736 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1737 | |
265898fd | 1738 | if (m_backgroundBrush == brush) return; |
7d5af6fa | 1739 | |
265898fd | 1740 | m_backgroundBrush = brush; |
7d5af6fa | 1741 | |
ab171e95 | 1742 | if (!m_backgroundBrush.IsOk()) return; |
7d5af6fa | 1743 | |
888dde65 | 1744 | if (!m_gdkwindow) return; |
7d5af6fa | 1745 | |
86d58c90 PC |
1746 | wxColor color = m_backgroundBrush.GetColour(); |
1747 | color.CalcPixel(m_cmap); | |
1748 | const GdkColor* gdkColor = color.GetColor(); | |
1749 | gdk_gc_set_background(m_brushGC, gdkColor); | |
1750 | gdk_gc_set_background(m_penGC, gdkColor); | |
1751 | gdk_gc_set_background(m_bgGC, gdkColor); | |
1752 | gdk_gc_set_foreground(m_bgGC, gdkColor); | |
1753 | ||
3417c2cd RR |
1754 | |
1755 | gdk_gc_set_fill( m_bgGC, GDK_SOLID ); | |
7d5af6fa | 1756 | |
04ee05f9 | 1757 | if (m_backgroundBrush.GetStyle() == wxBRUSHSTYLE_STIPPLE) |
265898fd | 1758 | { |
86d58c90 PC |
1759 | const wxBitmap* stipple = m_backgroundBrush.GetStipple(); |
1760 | if (stipple->IsOk()) | |
7d5af6fa | 1761 | { |
86d58c90 PC |
1762 | if (stipple->GetDepth() != 1) |
1763 | { | |
1764 | gdk_gc_set_fill(m_bgGC, GDK_TILED); | |
1765 | gdk_gc_set_tile(m_bgGC, stipple->GetPixmap()); | |
1766 | } | |
1767 | else | |
1768 | { | |
1769 | gdk_gc_set_fill(m_bgGC, GDK_STIPPLED); | |
1770 | gdk_gc_set_stipple(m_bgGC, stipple->GetPixmap()); | |
1771 | } | |
7d5af6fa | 1772 | } |
265898fd | 1773 | } |
86d58c90 | 1774 | else if (m_backgroundBrush.IsHatch()) |
265898fd | 1775 | { |
3417c2cd | 1776 | gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); |
f7732fa5 | 1777 | gdk_gc_set_stipple(m_bgGC, GetHatch(m_backgroundBrush.GetStyle())); |
bbbbe360 | 1778 | } |
903f689b | 1779 | } |
46dc76ba | 1780 | |
89efaf2b | 1781 | void wxWindowDCImpl::SetLogicalFunction( wxRasterOperationMode function ) |
c801d85f | 1782 | { |
ab171e95 | 1783 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1784 | |
72174350 VZ |
1785 | if (m_logicalFunction == function) |
1786 | return; | |
1787 | ||
1788 | // VZ: shouldn't this be a CHECK? | |
888dde65 | 1789 | if (!m_gdkwindow) |
72174350 | 1790 | return; |
01eaf507 | 1791 | |
2b5f62a0 | 1792 | GdkFunction mode; |
265898fd RR |
1793 | switch (function) |
1794 | { | |
3c679789 RR |
1795 | case wxXOR: mode = GDK_XOR; break; |
1796 | case wxINVERT: mode = GDK_INVERT; break; | |
3c679789 RR |
1797 | case wxOR_REVERSE: mode = GDK_OR_REVERSE; break; |
1798 | case wxAND_REVERSE: mode = GDK_AND_REVERSE; break; | |
1799 | case wxCLEAR: mode = GDK_CLEAR; break; | |
1800 | case wxSET: mode = GDK_SET; break; | |
1801 | case wxOR_INVERT: mode = GDK_OR_INVERT; break; | |
1802 | case wxAND: mode = GDK_AND; break; | |
1803 | case wxOR: mode = GDK_OR; break; | |
1804 | case wxEQUIV: mode = GDK_EQUIV; break; | |
1805 | case wxNAND: mode = GDK_NAND; break; | |
1806 | case wxAND_INVERT: mode = GDK_AND_INVERT; break; | |
7d5af6fa VZ |
1807 | case wxCOPY: mode = GDK_COPY; break; |
1808 | case wxNO_OP: mode = GDK_NOOP; break; | |
1809 | case wxSRC_INVERT: mode = GDK_COPY_INVERT; break; | |
8e69bf8e | 1810 | case wxNOR: mode = GDK_NOR; break; |
657a8a35 VZ |
1811 | default: |
1812 | wxFAIL_MSG("unknown mode"); | |
1813 | return; | |
265898fd | 1814 | } |
7d5af6fa | 1815 | |
265898fd | 1816 | m_logicalFunction = function; |
7d5af6fa | 1817 | |
265898fd RR |
1818 | gdk_gc_set_function( m_penGC, mode ); |
1819 | gdk_gc_set_function( m_brushGC, mode ); | |
72174350 VZ |
1820 | |
1821 | // to stay compatible with wxMSW, we don't apply ROPs to the text | |
3d2d8da1 RR |
1822 | // operations (i.e. DrawText/DrawRotatedText). |
1823 | // True, but mono-bitmaps use the m_textGC and they use ROPs as well. | |
1824 | gdk_gc_set_function( m_textGC, mode ); | |
903f689b | 1825 | } |
c801d85f | 1826 | |
888dde65 | 1827 | void wxWindowDCImpl::SetTextForeground( const wxColour &col ) |
c801d85f | 1828 | { |
ab171e95 | 1829 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1830 | |
71ec83d2 VZ |
1831 | // don't set m_textForegroundColour to an invalid colour as we'd crash |
1832 | // later then (we use m_textForegroundColour.GetColor() without checking | |
1833 | // in a few places) | |
ab171e95 | 1834 | if ( !col.IsOk() || (m_textForegroundColour == col) ) |
71ec83d2 | 1835 | return; |
7d5af6fa | 1836 | |
265898fd | 1837 | m_textForegroundColour = col; |
7d5af6fa | 1838 | |
888dde65 | 1839 | if ( m_gdkwindow ) |
71ec83d2 VZ |
1840 | { |
1841 | m_textForegroundColour.CalcPixel( m_cmap ); | |
1842 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
1843 | } | |
903f689b | 1844 | } |
c801d85f | 1845 | |
888dde65 | 1846 | void wxWindowDCImpl::SetTextBackground( const wxColour &col ) |
c801d85f | 1847 | { |
ab171e95 | 1848 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1849 | |
71ec83d2 | 1850 | // same as above |
ab171e95 | 1851 | if ( !col.IsOk() || (m_textBackgroundColour == col) ) |
71ec83d2 | 1852 | return; |
7d5af6fa | 1853 | |
265898fd | 1854 | m_textBackgroundColour = col; |
7d5af6fa | 1855 | |
888dde65 | 1856 | if ( m_gdkwindow ) |
71ec83d2 VZ |
1857 | { |
1858 | m_textBackgroundColour.CalcPixel( m_cmap ); | |
1859 | gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); | |
1860 | } | |
903f689b | 1861 | } |
c801d85f | 1862 | |
888dde65 | 1863 | void wxWindowDCImpl::SetBackgroundMode( int mode ) |
c801d85f | 1864 | { |
ab171e95 | 1865 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1866 | |
265898fd | 1867 | m_backgroundMode = mode; |
903f689b | 1868 | } |
c801d85f | 1869 | |
888dde65 | 1870 | void wxWindowDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) ) |
c801d85f | 1871 | { |
888dde65 | 1872 | wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") ); |
903f689b | 1873 | } |
c801d85f | 1874 | |
888dde65 | 1875 | void wxWindowDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 1876 | { |
ab171e95 | 1877 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1878 | |
888dde65 | 1879 | if (!m_gdkwindow) return; |
7d5af6fa | 1880 | |
3d2d8da1 | 1881 | wxRect rect; |
265898fd RR |
1882 | rect.x = XLOG2DEV(x); |
1883 | rect.y = YLOG2DEV(y); | |
1884 | rect.width = XLOG2DEVREL(width); | |
1885 | rect.height = YLOG2DEVREL(height); | |
5f170f33 | 1886 | |
89efaf2b | 1887 | if (m_window && m_window->m_wxwindow && |
888dde65 | 1888 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) |
49e74855 RR |
1889 | { |
1890 | rect.x -= rect.width; | |
1891 | } | |
1892 | ||
98d8a7ec | 1893 | DoSetDeviceClippingRegion(wxRegion(rect)); |
903f689b | 1894 | } |
c801d85f | 1895 | |
fdaad94e | 1896 | void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion ®ion ) |
463c1fa1 | 1897 | { |
ab171e95 | 1898 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1899 | |
463c1fa1 RR |
1900 | if (region.Empty()) |
1901 | { | |
1902 | DestroyClippingRegion(); | |
1903 | return; | |
1904 | } | |
7d5af6fa | 1905 | |
888dde65 | 1906 | if (!m_gdkwindow) return; |
5f170f33 | 1907 | |
e1208c31 | 1908 | if (!m_currentClippingRegion.IsNull()) |
993f97ee RR |
1909 | m_currentClippingRegion.Intersect( region ); |
1910 | else | |
1911 | m_currentClippingRegion.Union( region ); | |
5f170f33 VZ |
1912 | |
1913 | #if USE_PAINT_REGION | |
e1208c31 | 1914 | if (!m_paintClippingRegion.IsNull()) |
3d2d8da1 | 1915 | m_currentClippingRegion.Intersect( m_paintClippingRegion ); |
809934d2 | 1916 | #endif |
3d2d8da1 | 1917 | |
ee8dbe63 RL |
1918 | wxCoord xx, yy, ww, hh; |
1919 | m_currentClippingRegion.GetBox( xx, yy, ww, hh ); | |
888dde65 | 1920 | wxGTKDCImpl::DoSetClippingRegion( xx, yy, ww, hh ); |
ee8dbe63 | 1921 | |
86d58c90 PC |
1922 | GdkRegion* gdkRegion = m_currentClippingRegion.GetRegion(); |
1923 | gdk_gc_set_clip_region(m_penGC, gdkRegion); | |
1924 | gdk_gc_set_clip_region(m_brushGC, gdkRegion); | |
1925 | gdk_gc_set_clip_region(m_textGC, gdkRegion); | |
1926 | gdk_gc_set_clip_region(m_bgGC, gdkRegion); | |
463c1fa1 RR |
1927 | } |
1928 | ||
888dde65 | 1929 | void wxWindowDCImpl::DestroyClippingRegion() |
c801d85f | 1930 | { |
ab171e95 | 1931 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1932 | |
888dde65 | 1933 | wxDCImpl::DestroyClippingRegion(); |
7d5af6fa | 1934 | |
3d2d8da1 | 1935 | m_currentClippingRegion.Clear(); |
5f170f33 VZ |
1936 | |
1937 | #if USE_PAINT_REGION | |
3d2d8da1 RR |
1938 | if (!m_paintClippingRegion.IsEmpty()) |
1939 | m_currentClippingRegion.Union( m_paintClippingRegion ); | |
993f97ee | 1940 | #endif |
3d2d8da1 | 1941 | |
888dde65 | 1942 | if (!m_gdkwindow) return; |
7d5af6fa | 1943 | |
86d58c90 PC |
1944 | GdkRegion* gdkRegion = NULL; |
1945 | if (!m_currentClippingRegion.IsEmpty()) | |
1946 | gdkRegion = m_currentClippingRegion.GetRegion(); | |
1947 | ||
1948 | gdk_gc_set_clip_region(m_penGC, gdkRegion); | |
1949 | gdk_gc_set_clip_region(m_brushGC, gdkRegion); | |
1950 | gdk_gc_set_clip_region(m_textGC, gdkRegion); | |
1951 | gdk_gc_set_clip_region(m_bgGC, gdkRegion); | |
903f689b | 1952 | } |
c801d85f | 1953 | |
888dde65 | 1954 | void wxWindowDCImpl::Destroy() |
dbf858b5 | 1955 | { |
3d2d8da1 | 1956 | if (m_penGC) wxFreePoolGC( m_penGC ); |
d3b9f782 | 1957 | m_penGC = NULL; |
3d2d8da1 | 1958 | if (m_brushGC) wxFreePoolGC( m_brushGC ); |
d3b9f782 | 1959 | m_brushGC = NULL; |
3d2d8da1 | 1960 | if (m_textGC) wxFreePoolGC( m_textGC ); |
d3b9f782 | 1961 | m_textGC = NULL; |
3d2d8da1 | 1962 | if (m_bgGC) wxFreePoolGC( m_bgGC ); |
d3b9f782 | 1963 | m_bgGC = NULL; |
dbf858b5 RR |
1964 | } |
1965 | ||
888dde65 | 1966 | void wxWindowDCImpl::SetDeviceOrigin( wxCoord x, wxCoord y ) |
847dfdb4 RR |
1967 | { |
1968 | m_deviceOriginX = x; | |
1969 | m_deviceOriginY = y; | |
f4322df6 | 1970 | |
847dfdb4 RR |
1971 | ComputeScaleAndOrigin(); |
1972 | } | |
1973 | ||
888dde65 | 1974 | void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
847dfdb4 RR |
1975 | { |
1976 | m_signX = (xLeftRight ? 1 : -1); | |
1977 | m_signY = (yBottomUp ? -1 : 1); | |
f4322df6 | 1978 | |
89efaf2b | 1979 | if (m_window && m_window->m_wxwindow && |
888dde65 | 1980 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) |
f4322df6 VZ |
1981 | m_signX = -m_signX; |
1982 | ||
847dfdb4 RR |
1983 | ComputeScaleAndOrigin(); |
1984 | } | |
1985 | ||
888dde65 | 1986 | void wxWindowDCImpl::ComputeScaleAndOrigin() |
238d735d | 1987 | { |
c77a6796 | 1988 | const wxRealPoint origScale(m_scaleX, m_scaleY); |
238d735d | 1989 | |
888dde65 | 1990 | wxDCImpl::ComputeScaleAndOrigin(); |
238d735d | 1991 | |
b0ad146a | 1992 | // if scale has changed call SetPen to recalculate the line width |
ab171e95 | 1993 | if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.IsOk() ) |
238d735d | 1994 | { |
c77a6796 VZ |
1995 | // this is a bit artificial, but we need to force wxDC to think the pen |
1996 | // has changed | |
0a164d4c WS |
1997 | wxPen pen = m_pen; |
1998 | m_pen = wxNullPen; | |
1999 | SetPen( pen ); | |
2000 | } | |
238d735d RR |
2001 | } |
2002 | ||
b0e0d661 | 2003 | // Resolution in pixels per logical inch |
888dde65 | 2004 | wxSize wxWindowDCImpl::GetPPI() const |
b0e0d661 | 2005 | { |
7a5e6267 | 2006 | return wxSize( (int) (m_mm_to_pix_x * 25.4 + 0.5), (int) (m_mm_to_pix_y * 25.4 + 0.5)); |
b0e0d661 VZ |
2007 | } |
2008 | ||
888dde65 | 2009 | int wxWindowDCImpl::GetDepth() const |
c801d85f | 2010 | { |
888dde65 | 2011 | return gdk_drawable_get_depth(m_gdkwindow); |
903f689b | 2012 | } |
c801d85f | 2013 | |
ab171e95 | 2014 | //----------------------------------------------------------------------------- |
888dde65 | 2015 | // wxClientDCImpl |
ab171e95 RR |
2016 | //----------------------------------------------------------------------------- |
2017 | ||
888dde65 | 2018 | IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl) |
ab171e95 | 2019 | |
888dde65 RR |
2020 | wxClientDCImpl::wxClientDCImpl( wxDC *owner ) |
2021 | : wxWindowDCImpl( owner ) | |
ab171e95 RR |
2022 | { |
2023 | } | |
2024 | ||
888dde65 RR |
2025 | wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *win ) |
2026 | : wxWindowDCImpl( owner, win ) | |
ab171e95 | 2027 | { |
9a83f860 | 2028 | wxCHECK_RET( win, wxT("NULL window in wxClientDCImpl::wxClientDC") ); |
ab171e95 RR |
2029 | |
2030 | #ifdef __WXUNIVERSAL__ | |
2031 | wxPoint ptOrigin = win->GetClientAreaOrigin(); | |
2032 | SetDeviceOrigin(ptOrigin.x, ptOrigin.y); | |
2033 | wxSize size = win->GetClientSize(); | |
6267c3ea | 2034 | DoSetClippingRegion(0, 0, size.x, size.y); |
89efaf2b | 2035 | #endif |
888dde65 | 2036 | // __WXUNIVERSAL__ |
ab171e95 RR |
2037 | } |
2038 | ||
888dde65 | 2039 | void wxClientDCImpl::DoGetSize(int *width, int *height) const |
ab171e95 | 2040 | { |
9a83f860 | 2041 | wxCHECK_RET( m_window, wxT("GetSize() doesn't work without window") ); |
ab171e95 | 2042 | |
76274efd | 2043 | m_window->GetClientSize(width, height); |
ab171e95 RR |
2044 | } |
2045 | ||
ec758a20 | 2046 | //----------------------------------------------------------------------------- |
888dde65 | 2047 | // wxPaintDCImpl |
ec758a20 RR |
2048 | //----------------------------------------------------------------------------- |
2049 | ||
888dde65 | 2050 | IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxClientDCImpl) |
ec758a20 | 2051 | |
2cfddfe7 JS |
2052 | // Limit the paint region to the window size. Sometimes |
2053 | // the paint region is too big, and this risks X11 errors | |
2054 | static void wxLimitRegionToSize(wxRegion& region, const wxSize& sz) | |
2055 | { | |
2056 | wxRect originalRect = region.GetBox(); | |
2057 | wxRect rect(originalRect); | |
2058 | if (rect.width + rect.x > sz.x) | |
2059 | rect.width = sz.x - rect.x; | |
2060 | if (rect.height + rect.y > sz.y) | |
2061 | rect.height = sz.y - rect.y; | |
2062 | if (rect != originalRect) | |
2063 | { | |
2064 | region = wxRegion(rect); | |
2065 | wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"), | |
2066 | originalRect.x, originalRect.y, originalRect.width, originalRect.height, | |
2067 | rect.x, rect.y, rect.width, rect.height); | |
2068 | } | |
2069 | } | |
2070 | ||
888dde65 RR |
2071 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner ) |
2072 | : wxClientDCImpl( owner ) | |
ab171e95 RR |
2073 | { |
2074 | } | |
2075 | ||
888dde65 RR |
2076 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *win ) |
2077 | : wxClientDCImpl( owner, win ) | |
ec758a20 | 2078 | { |
b6fa52db RR |
2079 | #if USE_PAINT_REGION |
2080 | if (!win->m_clipPaintRegion) | |
2081 | return; | |
f469b27c | 2082 | |
2cfddfe7 | 2083 | wxSize sz = win->GetSize(); |
bcb614b3 | 2084 | m_paintClippingRegion = win->m_nativeUpdateRegion; |
2cfddfe7 | 2085 | wxLimitRegionToSize(m_paintClippingRegion, sz); |
ab9d0a8c | 2086 | |
5f170f33 VZ |
2087 | GdkRegion *region = m_paintClippingRegion.GetRegion(); |
2088 | if ( region ) | |
2089 | { | |
823faac3 | 2090 | m_currentClippingRegion.Union( m_paintClippingRegion ); |
2cfddfe7 JS |
2091 | wxLimitRegionToSize(m_currentClippingRegion, sz); |
2092 | ||
2093 | if (sz.x <= 0 || sz.y <= 0) | |
2094 | return ; | |
5f170f33 | 2095 | |
823faac3 JS |
2096 | gdk_gc_set_clip_region( m_penGC, region ); |
2097 | gdk_gc_set_clip_region( m_brushGC, region ); | |
2098 | gdk_gc_set_clip_region( m_textGC, region ); | |
2099 | gdk_gc_set_clip_region( m_bgGC, region ); | |
5f170f33 | 2100 | } |
89efaf2b | 2101 | #endif |
ec758a20 RR |
2102 | } |
2103 | ||
3d2d8da1 RR |
2104 | // ---------------------------------------------------------------------------- |
2105 | // wxDCModule | |
2106 | // ---------------------------------------------------------------------------- | |
2107 | ||
2108 | class wxDCModule : public wxModule | |
2109 | { | |
2110 | public: | |
2111 | bool OnInit(); | |
2112 | void OnExit(); | |
2113 | ||
2114 | private: | |
2115 | DECLARE_DYNAMIC_CLASS(wxDCModule) | |
2116 | }; | |
2117 | ||
2118 | IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule) | |
2119 | ||
2120 | bool wxDCModule::OnInit() | |
2121 | { | |
2122 | wxInitGCPool(); | |
ab9d0a8c | 2123 | return true; |
3d2d8da1 RR |
2124 | } |
2125 | ||
2126 | void wxDCModule::OnExit() | |
2127 | { | |
2128 | wxCleanUpGCPool(); | |
f7732fa5 | 2129 | |
04ee05f9 | 2130 | for (int i = wxBRUSHSTYLE_LAST_HATCH - wxBRUSHSTYLE_FIRST_HATCH; i--; ) |
f7732fa5 PC |
2131 | { |
2132 | if (hatches[i]) | |
2133 | g_object_unref(hatches[i]); | |
2134 | } | |
3d2d8da1 | 2135 | } |