]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/gtk/dcclient.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
6f65e337 | 5 | // RCS-ID: $Id$ |
6c9a19aa | 6 | // Copyright: (c) 1998 Robert Roebling, Chris Breeze |
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 | ||
d02af7bb JJ |
13 | #ifdef __VMS |
14 | #define XCopyPlane XCOPYPLANE | |
15 | #endif | |
16 | ||
d6afc2c8 | 17 | #include "wx/gtk/dcclient.h" |
e4db172a WS |
18 | |
19 | #ifndef WX_PRECOMP | |
772b3767 | 20 | #include "wx/window.h" |
e4db172a | 21 | #include "wx/log.h" |
f38924e8 | 22 | #include "wx/dcmemory.h" |
d6afc2c8 | 23 | #include "wx/math.h" |
155ecd4c | 24 | #include "wx/image.h" |
02761f6c | 25 | #include "wx/module.h" |
e4db172a WS |
26 | #endif |
27 | ||
db16cab4 | 28 | #include "wx/fontutil.h" |
e5131165 | 29 | |
a3669332 | 30 | #include "wx/gtk/private.h" |
f3d74739 | 31 | #include "wx/gtk/private/object.h" |
c801d85f | 32 | |
993f97ee | 33 | #include <gdk/gdkx.h> |
83624f79 | 34 | |
809934d2 RR |
35 | //----------------------------------------------------------------------------- |
36 | // local defines | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
eb7637b5 RR |
39 | #define XLOG2DEV(x) LogicalToDeviceX(x) |
40 | #define XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
41 | #define YLOG2DEV(y) LogicalToDeviceY(y) | |
42 | #define YLOG2DEVREL(y) LogicalToDeviceYRel(y) | |
43 | ||
e1208c31 | 44 | #define USE_PAINT_REGION 1 |
809934d2 | 45 | |
c801d85f KB |
46 | //----------------------------------------------------------------------------- |
47 | // local data | |
48 | //----------------------------------------------------------------------------- | |
49 | ||
50 | #include "bdiag.xbm" | |
51 | #include "fdiag.xbm" | |
52 | #include "cdiag.xbm" | |
53 | #include "horiz.xbm" | |
54 | #include "verti.xbm" | |
55 | #include "cross.xbm" | |
c801d85f | 56 | |
04ee05f9 | 57 | static GdkPixmap* hatches[wxBRUSHSTYLE_LAST_HATCH - wxBRUSHSTYLE_FIRST_HATCH + 1]; |
c801d85f | 58 | |
c2fa61e8 | 59 | extern GtkWidget *wxGetRootWindow(); |
3d2d8da1 | 60 | |
c801d85f KB |
61 | //----------------------------------------------------------------------------- |
62 | // constants | |
63 | //----------------------------------------------------------------------------- | |
64 | ||
d6afc2c8 | 65 | static const double RAD2DEG = 180.0 / M_PI; |
c801d85f | 66 | |
9a8c7620 VZ |
67 | // ---------------------------------------------------------------------------- |
68 | // private functions | |
69 | // ---------------------------------------------------------------------------- | |
70 | ||
71 | static inline double dmax(double a, double b) { return a > b ? a : b; } | |
72 | static inline double dmin(double a, double b) { return a < b ? a : b; } | |
73 | ||
74 | static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } | |
75 | ||
f7732fa5 PC |
76 | static GdkPixmap* GetHatch(int style) |
77 | { | |
04ee05f9 PC |
78 | wxASSERT(style >= wxBRUSHSTYLE_FIRST_HATCH && style <= wxBRUSHSTYLE_LAST_HATCH); |
79 | const int i = style - wxBRUSHSTYLE_FIRST_HATCH; | |
f7732fa5 PC |
80 | if (hatches[i] == NULL) |
81 | { | |
82 | switch (style) | |
83 | { | |
04ee05f9 | 84 | case wxBRUSHSTYLE_BDIAGONAL_HATCH: |
f7732fa5 PC |
85 | hatches[i] = gdk_bitmap_create_from_data(NULL, bdiag_bits, bdiag_width, bdiag_height); |
86 | break; | |
04ee05f9 | 87 | case wxBRUSHSTYLE_CROSSDIAG_HATCH: |
f7732fa5 PC |
88 | hatches[i] = gdk_bitmap_create_from_data(NULL, cdiag_bits, cdiag_width, cdiag_height); |
89 | break; | |
04ee05f9 | 90 | case wxBRUSHSTYLE_CROSS_HATCH: |
f7732fa5 PC |
91 | hatches[i] = gdk_bitmap_create_from_data(NULL, cross_bits, cross_width, cross_height); |
92 | break; | |
04ee05f9 | 93 | case wxBRUSHSTYLE_FDIAGONAL_HATCH: |
f7732fa5 PC |
94 | hatches[i] = gdk_bitmap_create_from_data(NULL, fdiag_bits, fdiag_width, fdiag_height); |
95 | break; | |
04ee05f9 | 96 | case wxBRUSHSTYLE_HORIZONTAL_HATCH: |
f7732fa5 PC |
97 | hatches[i] = gdk_bitmap_create_from_data(NULL, horiz_bits, horiz_width, horiz_height); |
98 | break; | |
04ee05f9 | 99 | case wxBRUSHSTYLE_VERTICAL_HATCH: |
f7732fa5 PC |
100 | hatches[i] = gdk_bitmap_create_from_data(NULL, verti_bits, verti_width, verti_height); |
101 | break; | |
102 | } | |
103 | } | |
104 | return hatches[i]; | |
105 | } | |
106 | ||
6f65e337 JS |
107 | //----------------------------------------------------------------------------- |
108 | // temporary implementation of the missing GDK function | |
109 | //----------------------------------------------------------------------------- | |
b0e0d661 | 110 | |
9be3f755 | 111 | static |
1e6feb95 VZ |
112 | void gdk_wx_draw_bitmap(GdkDrawable *drawable, |
113 | GdkGC *gc, | |
114 | GdkDrawable *src, | |
115 | gint xsrc, | |
e4161a2a | 116 | gint ysrc) |
6f65e337 | 117 | { |
17a1ebd1 VZ |
118 | wxCHECK_RET( drawable, _T("NULL drawable in gdk_wx_draw_bitmap") ); |
119 | wxCHECK_RET( src, _T("NULL src in gdk_wx_draw_bitmap") ); | |
120 | wxCHECK_RET( gc, _T("NULL gc in gdk_wx_draw_bitmap") ); | |
ab9d0a8c | 121 | |
d90c9596 | 122 | gint src_width, src_height; |
8943b403 | 123 | gdk_drawable_get_size(src, &src_width, &src_height); |
265898fd | 124 | |
8943b403 OK |
125 | XCopyPlane( GDK_WINDOW_XDISPLAY(drawable), |
126 | GDK_WINDOW_XID(src), | |
127 | GDK_WINDOW_XID(drawable), | |
128 | GDK_GC_XGC(gc), | |
129 | xsrc, ysrc, | |
e4161a2a | 130 | src_width, src_height, |
d90c9596 | 131 | 0, 0, |
8943b403 | 132 | 1 ); |
6f65e337 JS |
133 | } |
134 | ||
3d2d8da1 RR |
135 | //----------------------------------------------------------------------------- |
136 | // Implement Pool of Graphic contexts. Creating them takes too much time. | |
137 | //----------------------------------------------------------------------------- | |
138 | ||
0e09f76e RR |
139 | enum wxPoolGCType |
140 | { | |
141 | wxGC_ERROR = 0, | |
142 | wxTEXT_MONO, | |
143 | wxBG_MONO, | |
144 | wxPEN_MONO, | |
145 | wxBRUSH_MONO, | |
146 | wxTEXT_COLOUR, | |
147 | wxBG_COLOUR, | |
148 | wxPEN_COLOUR, | |
f6bcfd97 BP |
149 | wxBRUSH_COLOUR, |
150 | wxTEXT_SCREEN, | |
151 | wxBG_SCREEN, | |
152 | wxPEN_SCREEN, | |
153 | wxBRUSH_SCREEN | |
0e09f76e RR |
154 | }; |
155 | ||
3d2d8da1 RR |
156 | struct wxGC |
157 | { | |
0e09f76e RR |
158 | GdkGC *m_gc; |
159 | wxPoolGCType m_type; | |
160 | bool m_used; | |
3d2d8da1 RR |
161 | }; |
162 | ||
696f36b7 JS |
163 | #define GC_POOL_ALLOC_SIZE 100 |
164 | ||
165 | static int wxGCPoolSize = 0; | |
166 | ||
167 | static wxGC *wxGCPool = NULL; | |
3d2d8da1 RR |
168 | |
169 | static void wxInitGCPool() | |
170 | { | |
696f36b7 JS |
171 | // This really could wait until the first call to |
172 | // wxGetPoolGC, but we will make the first allocation | |
173 | // now when other initialization is being performed. | |
ab9d0a8c | 174 | |
696f36b7 JS |
175 | // Set initial pool size. |
176 | wxGCPoolSize = GC_POOL_ALLOC_SIZE; | |
ab9d0a8c | 177 | |
696f36b7 JS |
178 | // Allocate initial pool. |
179 | wxGCPool = (wxGC *)malloc(wxGCPoolSize * sizeof(wxGC)); | |
180 | if (wxGCPool == NULL) | |
181 | { | |
182 | // If we cannot malloc, then fail with error | |
183 | // when debug is enabled. If debug is not enabled, | |
184 | // the problem will eventually get caught | |
551b5391 | 185 | // in wxGetPoolGC. |
696f36b7 JS |
186 | wxFAIL_MSG( wxT("Cannot allocate GC pool") ); |
187 | return; | |
188 | } | |
ab9d0a8c | 189 | |
696f36b7 JS |
190 | // Zero initial pool. |
191 | memset(wxGCPool, 0, wxGCPoolSize * sizeof(wxGC)); | |
3d2d8da1 RR |
192 | } |
193 | ||
194 | static void wxCleanUpGCPool() | |
195 | { | |
f6116855 | 196 | for (int i = 0; i < wxGCPoolSize; i++) |
3d2d8da1 RR |
197 | { |
198 | if (wxGCPool[i].m_gc) | |
3fe39b0c | 199 | g_object_unref (wxGCPool[i].m_gc); |
3d2d8da1 | 200 | } |
696f36b7 JS |
201 | |
202 | free(wxGCPool); | |
203 | wxGCPool = NULL; | |
204 | wxGCPoolSize = 0; | |
3d2d8da1 RR |
205 | } |
206 | ||
0e09f76e | 207 | static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) |
3d2d8da1 | 208 | { |
696f36b7 | 209 | wxGC *pptr; |
ab9d0a8c | 210 | |
696f36b7 JS |
211 | // Look for an available GC. |
212 | for (int i = 0; i < wxGCPoolSize; i++) | |
3d2d8da1 RR |
213 | { |
214 | if (!wxGCPool[i].m_gc) | |
215 | { | |
216 | wxGCPool[i].m_gc = gdk_gc_new( window ); | |
217 | gdk_gc_set_exposures( wxGCPool[i].m_gc, FALSE ); | |
0e09f76e | 218 | wxGCPool[i].m_type = type; |
ab9d0a8c | 219 | wxGCPool[i].m_used = false; |
3d2d8da1 | 220 | } |
0e09f76e | 221 | if ((!wxGCPool[i].m_used) && (wxGCPool[i].m_type == type)) |
3d2d8da1 | 222 | { |
ab9d0a8c | 223 | wxGCPool[i].m_used = true; |
3d2d8da1 RR |
224 | return wxGCPool[i].m_gc; |
225 | } | |
226 | } | |
5f170f33 | 227 | |
696f36b7 JS |
228 | // We did not find an available GC. |
229 | // We need to grow the GC pool. | |
230 | pptr = (wxGC *)realloc(wxGCPool, | |
551b5391 | 231 | (wxGCPoolSize + GC_POOL_ALLOC_SIZE)*sizeof(wxGC)); |
696f36b7 JS |
232 | if (pptr != NULL) |
233 | { | |
234 | // Initialize newly allocated pool. | |
235 | wxGCPool = pptr; | |
551b5391 RR |
236 | memset(&wxGCPool[wxGCPoolSize], 0, |
237 | GC_POOL_ALLOC_SIZE*sizeof(wxGC)); | |
ab9d0a8c WS |
238 | |
239 | // Initialize entry we will return. | |
696f36b7 JS |
240 | wxGCPool[wxGCPoolSize].m_gc = gdk_gc_new( window ); |
241 | gdk_gc_set_exposures( wxGCPool[wxGCPoolSize].m_gc, FALSE ); | |
242 | wxGCPool[wxGCPoolSize].m_type = type; | |
ab9d0a8c WS |
243 | wxGCPool[wxGCPoolSize].m_used = true; |
244 | ||
696f36b7 JS |
245 | // Set new value of pool size. |
246 | wxGCPoolSize += GC_POOL_ALLOC_SIZE; | |
ab9d0a8c | 247 | |
696f36b7 JS |
248 | // Return newly allocated entry. |
249 | return wxGCPool[wxGCPoolSize-GC_POOL_ALLOC_SIZE].m_gc; | |
250 | } | |
ab9d0a8c | 251 | |
696f36b7 | 252 | // The realloc failed. Fall through to error. |
3d2d8da1 | 253 | wxFAIL_MSG( wxT("No GC available") ); |
5f170f33 | 254 | |
3d2d8da1 RR |
255 | return (GdkGC*) NULL; |
256 | } | |
257 | ||
258 | static void wxFreePoolGC( GdkGC *gc ) | |
259 | { | |
696f36b7 | 260 | for (int i = 0; i < wxGCPoolSize; i++) |
3d2d8da1 RR |
261 | { |
262 | if (wxGCPool[i].m_gc == gc) | |
263 | { | |
ab9d0a8c | 264 | wxGCPool[i].m_used = false; |
3d2d8da1 RR |
265 | return; |
266 | } | |
267 | } | |
5f170f33 | 268 | |
3d2d8da1 RR |
269 | wxFAIL_MSG( wxT("Wrong GC") ); |
270 | } | |
271 | ||
c801d85f | 272 | //----------------------------------------------------------------------------- |
ec758a20 | 273 | // wxWindowDC |
c801d85f KB |
274 | //----------------------------------------------------------------------------- |
275 | ||
888dde65 | 276 | IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxGTKDCImpl) |
c801d85f | 277 | |
888dde65 RR |
278 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner ) : |
279 | wxGTKDCImpl( owner ) | |
c801d85f | 280 | { |
888dde65 | 281 | m_gdkwindow = (GdkWindow*) NULL; |
265898fd RR |
282 | m_penGC = (GdkGC *) NULL; |
283 | m_brushGC = (GdkGC *) NULL; | |
284 | m_textGC = (GdkGC *) NULL; | |
285 | m_bgGC = (GdkGC *) NULL; | |
286 | m_cmap = (GdkColormap *) NULL; | |
ab9d0a8c | 287 | m_isScreenDC = false; |
8943b403 | 288 | m_context = (PangoContext *)NULL; |
cfcc3932 | 289 | m_layout = (PangoLayout *)NULL; |
8943b403 | 290 | m_fontdesc = (PangoFontDescription *)NULL; |
903f689b | 291 | } |
c801d85f | 292 | |
888dde65 RR |
293 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window ) : |
294 | wxGTKDCImpl( owner ) | |
c801d85f | 295 | { |
3cd0b8c5 RR |
296 | wxASSERT_MSG( window, wxT("DC needs a window") ); |
297 | ||
888dde65 | 298 | m_gdkwindow = (GdkWindow*) NULL; |
265898fd RR |
299 | m_penGC = (GdkGC *) NULL; |
300 | m_brushGC = (GdkGC *) NULL; | |
301 | m_textGC = (GdkGC *) NULL; | |
302 | m_bgGC = (GdkGC *) NULL; | |
303 | m_cmap = (GdkColormap *) NULL; | |
ab9d0a8c | 304 | m_isScreenDC = false; |
3b245d60 | 305 | m_font = window->GetFont(); |
7d5af6fa | 306 | |
a2053b27 | 307 | GtkWidget *widget = window->m_wxwindow; |
7d5af6fa | 308 | |
cfcc3932 | 309 | // Some controls don't have m_wxwindow - like wxStaticBox, but the user |
b7f1f77f | 310 | // code should still be able to create wxClientDCs for them, so we will |
cfcc3932 | 311 | // use the parent window here then. |
b7f1f77f VZ |
312 | if ( !widget ) |
313 | { | |
314 | window = window->GetParent(); | |
315 | widget = window->m_wxwindow; | |
316 | } | |
317 | ||
223d09f6 | 318 | wxASSERT_MSG( widget, wxT("DC needs a widget") ); |
7d5af6fa | 319 | |
2b5f62a0 | 320 | m_context = window->GtkGetPangoDefaultContext(); |
cfcc3932 RR |
321 | m_layout = pango_layout_new( m_context ); |
322 | m_fontdesc = pango_font_description_copy( widget->style->font_desc ); | |
8943b403 | 323 | |
888dde65 | 324 | m_gdkwindow = widget->window; |
7d5af6fa | 325 | |
cfcc3932 | 326 | // Window not realized ? |
888dde65 | 327 | if (!m_gdkwindow) |
1e133b7d | 328 | { |
cfcc3932 | 329 | // Don't report problems as per MSW. |
ab9d0a8c | 330 | m_ok = true; |
7d5af6fa VZ |
331 | |
332 | return; | |
1e133b7d | 333 | } |
7d5af6fa | 334 | |
b7f1f77f | 335 | m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); |
7d5af6fa | 336 | |
265898fd | 337 | SetUpDC(); |
bbbbe360 RR |
338 | |
339 | /* this must be done after SetUpDC, bacause SetUpDC calls the | |
340 | repective SetBrush, SetPen, SetBackground etc functions | |
341 | to set up the DC. SetBackground call m_owner->SetBackground | |
342 | and this might not be desired as the standard dc background | |
343 | is white whereas a window might assume gray to be the | |
344 | standard (as e.g. wxStatusBar) */ | |
7d5af6fa | 345 | |
888dde65 | 346 | m_window = window; |
f4322df6 | 347 | |
888dde65 RR |
348 | if (m_window && m_window->m_wxwindow && |
349 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) | |
847dfdb4 | 350 | { |
5713b349 | 351 | // reverse sense |
847dfdb4 | 352 | m_signX = -1; |
807a572e | 353 | |
5713b349 | 354 | // origin in the upper right corner |
888dde65 | 355 | m_deviceOriginX = m_window->GetClientSize().x; |
847dfdb4 | 356 | } |
903f689b | 357 | } |
c801d85f | 358 | |
888dde65 | 359 | wxWindowDCImpl::~wxWindowDCImpl() |
c801d85f | 360 | { |
265898fd | 361 | Destroy(); |
ab9d0a8c | 362 | |
cfcc3932 | 363 | if (m_layout) |
3fe39b0c | 364 | g_object_unref (m_layout); |
cfcc3932 RR |
365 | if (m_fontdesc) |
366 | pango_font_description_free( m_fontdesc ); | |
903f689b | 367 | } |
c801d85f | 368 | |
888dde65 | 369 | void wxWindowDCImpl::SetUpDC( bool isMemDC ) |
809934d2 | 370 | { |
ab9d0a8c | 371 | m_ok = true; |
5f170f33 | 372 | |
809934d2 | 373 | wxASSERT_MSG( !m_penGC, wxT("GCs already created") ); |
5f170f33 | 374 | |
ab171e95 RR |
375 | bool done = false; |
376 | ||
888dde65 | 377 | if ((isMemDC) && (GetSelectedBitmap().IsOk())) |
809934d2 | 378 | { |
888dde65 | 379 | if (GetSelectedBitmap().GetDepth() == 1) |
ab171e95 | 380 | { |
888dde65 RR |
381 | m_penGC = wxGetPoolGC( m_gdkwindow, wxPEN_MONO ); |
382 | m_brushGC = wxGetPoolGC( m_gdkwindow, wxBRUSH_MONO ); | |
383 | m_textGC = wxGetPoolGC( m_gdkwindow, wxTEXT_MONO ); | |
384 | m_bgGC = wxGetPoolGC( m_gdkwindow, wxBG_MONO ); | |
ab171e95 RR |
385 | done = true; |
386 | } | |
809934d2 | 387 | } |
ab171e95 RR |
388 | |
389 | if (!done) | |
390 | { | |
391 | if (m_isScreenDC) | |
392 | { | |
888dde65 RR |
393 | m_penGC = wxGetPoolGC( m_gdkwindow, wxPEN_SCREEN ); |
394 | m_brushGC = wxGetPoolGC( m_gdkwindow, wxBRUSH_SCREEN ); | |
395 | m_textGC = wxGetPoolGC( m_gdkwindow, wxTEXT_SCREEN ); | |
396 | m_bgGC = wxGetPoolGC( m_gdkwindow, wxBG_SCREEN ); | |
ab171e95 RR |
397 | } |
398 | else | |
399 | { | |
888dde65 RR |
400 | m_penGC = wxGetPoolGC( m_gdkwindow, wxPEN_COLOUR ); |
401 | m_brushGC = wxGetPoolGC( m_gdkwindow, wxBRUSH_COLOUR ); | |
402 | m_textGC = wxGetPoolGC( m_gdkwindow, wxTEXT_COLOUR ); | |
403 | m_bgGC = wxGetPoolGC( m_gdkwindow, wxBG_COLOUR ); | |
ab171e95 | 404 | } |
809934d2 RR |
405 | } |
406 | ||
407 | /* background colour */ | |
408 | m_backgroundBrush = *wxWHITE_BRUSH; | |
409 | m_backgroundBrush.GetColour().CalcPixel( m_cmap ); | |
c6685317 | 410 | const GdkColor *bg_col = m_backgroundBrush.GetColour().GetColor(); |
809934d2 RR |
411 | |
412 | /* m_textGC */ | |
413 | m_textForegroundColour.CalcPixel( m_cmap ); | |
414 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
415 | ||
416 | m_textBackgroundColour.CalcPixel( m_cmap ); | |
417 | gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); | |
418 | ||
419 | gdk_gc_set_fill( m_textGC, GDK_SOLID ); | |
f4322df6 | 420 | |
4ba1c184 | 421 | gdk_gc_set_colormap( m_textGC, m_cmap ); |
809934d2 RR |
422 | |
423 | /* m_penGC */ | |
424 | m_pen.GetColour().CalcPixel( m_cmap ); | |
425 | gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() ); | |
426 | gdk_gc_set_background( m_penGC, bg_col ); | |
5f170f33 | 427 | |
809934d2 | 428 | gdk_gc_set_line_attributes( m_penGC, 0, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_ROUND ); |
5f170f33 | 429 | |
809934d2 RR |
430 | /* m_brushGC */ |
431 | m_brush.GetColour().CalcPixel( m_cmap ); | |
432 | gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() ); | |
433 | gdk_gc_set_background( m_brushGC, bg_col ); | |
5f170f33 | 434 | |
809934d2 | 435 | gdk_gc_set_fill( m_brushGC, GDK_SOLID ); |
5f170f33 | 436 | |
809934d2 RR |
437 | /* m_bgGC */ |
438 | gdk_gc_set_background( m_bgGC, bg_col ); | |
439 | gdk_gc_set_foreground( m_bgGC, bg_col ); | |
440 | ||
441 | gdk_gc_set_fill( m_bgGC, GDK_SOLID ); | |
5f170f33 | 442 | |
809934d2 RR |
443 | /* ROPs */ |
444 | gdk_gc_set_function( m_textGC, GDK_COPY ); | |
445 | gdk_gc_set_function( m_brushGC, GDK_COPY ); | |
446 | gdk_gc_set_function( m_penGC, GDK_COPY ); | |
5f170f33 | 447 | |
809934d2 RR |
448 | /* clipping */ |
449 | gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL ); | |
450 | gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL ); | |
451 | gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL ); | |
452 | gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL ); | |
809934d2 RR |
453 | } |
454 | ||
888dde65 | 455 | void wxWindowDCImpl::DoGetSize( int* width, int* height ) const |
376aa62a | 456 | { |
888dde65 | 457 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); |
376aa62a | 458 | |
888dde65 | 459 | m_window->GetSize(width, height); |
376aa62a VZ |
460 | } |
461 | ||
888dde65 | 462 | bool wxWindowDCImpl::DoFloodFill(wxCoord x, wxCoord y, |
06cf7c08 VS |
463 | const wxColour& col, int style) |
464 | { | |
c0521644 VZ |
465 | #if wxUSE_IMAGE |
466 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, | |
467 | const wxColour & col, int style); | |
468 | ||
ab171e95 | 469 | return wxDoFloodFill( GetOwner(), x, y, col, style); |
c0521644 | 470 | #else |
8d22935d VZ |
471 | wxUnusedVar(x); |
472 | wxUnusedVar(y); | |
473 | wxUnusedVar(col); | |
474 | wxUnusedVar(style); | |
475 | ||
c0521644 VZ |
476 | return false; |
477 | #endif | |
903f689b | 478 | } |
c801d85f | 479 | |
888dde65 | 480 | bool wxWindowDCImpl::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const |
c801d85f | 481 | { |
c0521644 | 482 | #if wxUSE_IMAGE |
dc1efb1d JS |
483 | // Generic (and therefore rather inefficient) method. |
484 | // Could be improved. | |
485 | wxMemoryDC memdc; | |
486 | wxBitmap bitmap(1, 1); | |
487 | memdc.SelectObject(bitmap); | |
888dde65 | 488 | memdc.Blit(0, 0, 1, 1, GetOwner(), x1, y1); |
dc1efb1d | 489 | memdc.SelectObject(wxNullBitmap); |
c2fa61e8 | 490 | |
368d59f0 | 491 | wxImage image = bitmap.ConvertToImage(); |
dc1efb1d | 492 | col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0)); |
ab9d0a8c | 493 | return true; |
c0521644 | 494 | #else // !wxUSE_IMAGE |
8d22935d VZ |
495 | wxUnusedVar(x1); |
496 | wxUnusedVar(y1); | |
497 | wxUnusedVar(col); | |
498 | ||
c0521644 VZ |
499 | return false; |
500 | #endif // wxUSE_IMAGE/!wxUSE_IMAGE | |
903f689b | 501 | } |
c801d85f | 502 | |
888dde65 | 503 | void wxWindowDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
c801d85f | 504 | { |
ab171e95 | 505 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
d225267e | 506 | |
04ee05f9 | 507 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
265898fd | 508 | { |
888dde65 RR |
509 | if (m_gdkwindow) |
510 | gdk_draw_line( m_gdkwindow, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) ); | |
7d5af6fa | 511 | |
ed880dd4 RR |
512 | CalcBoundingBox(x1, y1); |
513 | CalcBoundingBox(x2, y2); | |
265898fd | 514 | } |
903f689b | 515 | } |
c801d85f | 516 | |
888dde65 | 517 | void wxWindowDCImpl::DoCrossHair( wxCoord x, wxCoord y ) |
c801d85f | 518 | { |
ab171e95 | 519 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 520 | |
04ee05f9 | 521 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
265898fd RR |
522 | { |
523 | int w = 0; | |
524 | int h = 0; | |
ab171e95 | 525 | GetOwner()->GetSize( &w, &h ); |
72cdf4c9 VZ |
526 | wxCoord xx = XLOG2DEV(x); |
527 | wxCoord yy = YLOG2DEV(y); | |
888dde65 | 528 | if (m_gdkwindow) |
7d5af6fa | 529 | { |
888dde65 RR |
530 | gdk_draw_line( m_gdkwindow, m_penGC, 0, yy, XLOG2DEVREL(w), yy ); |
531 | gdk_draw_line( m_gdkwindow, m_penGC, xx, 0, xx, YLOG2DEVREL(h) ); | |
7d5af6fa | 532 | } |
265898fd | 533 | } |
903f689b | 534 | } |
c801d85f | 535 | |
ea3a345f PC |
536 | void wxWindowDCImpl::DrawingSetup(GdkGC*& gc, bool& originChanged) |
537 | { | |
538 | gc = m_brushGC; | |
539 | GdkPixmap* pixmap = NULL; | |
540 | const int style = m_brush.GetStyle(); | |
541 | ||
04ee05f9 | 542 | if (style == wxBRUSHSTYLE_STIPPLE || style == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE) |
ea3a345f PC |
543 | { |
544 | const wxBitmap* stipple = m_brush.GetStipple(); | |
545 | if (stipple->IsOk()) | |
546 | { | |
04ee05f9 | 547 | if (style == wxBRUSHSTYLE_STIPPLE) |
ea3a345f PC |
548 | pixmap = stipple->GetPixmap(); |
549 | else if (stipple->GetMask()) | |
550 | { | |
551 | pixmap = stipple->GetPixmap(); | |
552 | gc = m_textGC; | |
553 | } | |
554 | } | |
555 | } | |
556 | else if (m_brush.IsHatch()) | |
557 | { | |
558 | pixmap = GetHatch(style); | |
559 | } | |
560 | ||
561 | int origin_x = 0; | |
562 | int origin_y = 0; | |
563 | if (pixmap) | |
564 | { | |
565 | int w, h; | |
566 | gdk_drawable_get_size(pixmap, &w, &h); | |
567 | origin_x = m_deviceOriginX % w; | |
568 | origin_y = m_deviceOriginY % h; | |
569 | } | |
570 | ||
571 | originChanged = origin_x || origin_y; | |
572 | if (originChanged) | |
573 | gdk_gc_set_ts_origin(gc, origin_x, origin_y); | |
574 | } | |
575 | ||
888dde65 | 576 | void wxWindowDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, |
72cdf4c9 | 577 | wxCoord xc, wxCoord yc ) |
c801d85f | 578 | { |
ab171e95 | 579 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 580 | |
72cdf4c9 VZ |
581 | wxCoord xx1 = XLOG2DEV(x1); |
582 | wxCoord yy1 = YLOG2DEV(y1); | |
583 | wxCoord xx2 = XLOG2DEV(x2); | |
584 | wxCoord yy2 = YLOG2DEV(y2); | |
585 | wxCoord xxc = XLOG2DEV(xc); | |
586 | wxCoord yyc = YLOG2DEV(yc); | |
7d5af6fa | 587 | double dx = xx1 - xxc; |
265898fd | 588 | double dy = yy1 - yyc; |
de87c353 | 589 | double radius = sqrt((double)(dx*dx+dy*dy)); |
72cdf4c9 | 590 | wxCoord r = (wxCoord)radius; |
265898fd RR |
591 | double radius1, radius2; |
592 | ||
7d5af6fa | 593 | if (xx1 == xx2 && yy1 == yy2) |
265898fd RR |
594 | { |
595 | radius1 = 0.0; | |
596 | radius2 = 360.0; | |
7d5af6fa | 597 | } |
c77a6796 | 598 | else if ( wxIsNullDouble(radius) ) |
265898fd | 599 | { |
c77a6796 VZ |
600 | radius1 = |
601 | radius2 = 0.0; | |
7d5af6fa VZ |
602 | } |
603 | else | |
265898fd RR |
604 | { |
605 | radius1 = (xx1 - xxc == 0) ? | |
b0e0d661 VZ |
606 | (yy1 - yyc < 0) ? 90.0 : -90.0 : |
607 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
265898fd | 608 | radius2 = (xx2 - xxc == 0) ? |
b0e0d661 VZ |
609 | (yy2 - yyc < 0) ? 90.0 : -90.0 : |
610 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
265898fd | 611 | } |
72cdf4c9 VZ |
612 | wxCoord alpha1 = wxCoord(radius1 * 64.0); |
613 | wxCoord alpha2 = wxCoord((radius2 - radius1) * 64.0); | |
265898fd RR |
614 | while (alpha2 <= 0) alpha2 += 360*64; |
615 | while (alpha1 > 360*64) alpha1 -= 360*64; | |
616 | ||
888dde65 | 617 | if (m_gdkwindow) |
6db90681 | 618 | { |
04ee05f9 | 619 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
e9f88d04 | 620 | { |
ea3a345f PC |
621 | GdkGC* gc; |
622 | bool originChanged; | |
623 | DrawingSetup(gc, originChanged); | |
624 | ||
625 | gdk_draw_arc(m_gdkwindow, gc, true, xxc-r, yyc-r, 2*r, 2*r, alpha1, alpha2); | |
626 | ||
627 | if (originChanged) | |
628 | gdk_gc_set_ts_origin(gc, 0, 0); | |
e9f88d04 | 629 | } |
7d5af6fa | 630 | |
04ee05f9 | 631 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
3d0c4d2e | 632 | { |
888dde65 | 633 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
f469b27c | 634 | |
04ee05f9 | 635 | if ((m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) && (alpha2 - alpha1 != 360*64)) |
9707fd13 | 636 | { |
888dde65 RR |
637 | gdk_draw_line( m_gdkwindow, m_penGC, xx1, yy1, xxc, yyc ); |
638 | gdk_draw_line( m_gdkwindow, m_penGC, xxc, yyc, xx2, yy2 ); | |
9707fd13 | 639 | } |
3d0c4d2e | 640 | } |
6db90681 | 641 | } |
7d5af6fa | 642 | |
265898fd RR |
643 | CalcBoundingBox (x1, y1); |
644 | CalcBoundingBox (x2, y2); | |
903f689b | 645 | } |
c801d85f | 646 | |
888dde65 | 647 | void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double sa, double ea ) |
c801d85f | 648 | { |
ab171e95 | 649 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 650 | |
72cdf4c9 VZ |
651 | wxCoord xx = XLOG2DEV(x); |
652 | wxCoord yy = YLOG2DEV(y); | |
653 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
654 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
7d5af6fa | 655 | |
265898fd RR |
656 | // CMB: handle -ve width and/or height |
657 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
658 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
7d5af6fa | 659 | |
888dde65 | 660 | if (m_gdkwindow) |
6db90681 | 661 | { |
72cdf4c9 | 662 | wxCoord start = wxCoord(sa * 64.0); |
3d0c4d2e | 663 | wxCoord end = wxCoord((ea-sa) * 64.0); |
7d5af6fa | 664 | |
04ee05f9 | 665 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
e9f88d04 | 666 | { |
ea3a345f PC |
667 | GdkGC* gc; |
668 | bool originChanged; | |
669 | DrawingSetup(gc, originChanged); | |
670 | ||
671 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, ww, hh, start, end); | |
672 | ||
673 | if (originChanged) | |
674 | gdk_gc_set_ts_origin(gc, 0, 0); | |
e9f88d04 | 675 | } |
7d5af6fa | 676 | |
04ee05f9 | 677 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
888dde65 | 678 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, ww, hh, start, end ); |
6db90681 | 679 | } |
7d5af6fa | 680 | |
265898fd RR |
681 | CalcBoundingBox (x, y); |
682 | CalcBoundingBox (x + width, y + height); | |
903f689b | 683 | } |
c801d85f | 684 | |
888dde65 | 685 | void wxWindowDCImpl::DoDrawPoint( wxCoord x, wxCoord y ) |
c801d85f | 686 | { |
ab171e95 | 687 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 688 | |
04ee05f9 | 689 | if ((m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) && m_gdkwindow) |
888dde65 | 690 | gdk_draw_point( m_gdkwindow, m_penGC, XLOG2DEV(x), YLOG2DEV(y) ); |
7d5af6fa | 691 | |
265898fd | 692 | CalcBoundingBox (x, y); |
903f689b | 693 | } |
c801d85f | 694 | |
888dde65 | 695 | void wxWindowDCImpl::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset ) |
c801d85f | 696 | { |
ab171e95 | 697 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 698 | |
04ee05f9 | 699 | if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return; |
265898fd | 700 | if (n <= 0) return; |
7d5af6fa | 701 | |
e90411c2 | 702 | //Check, if scaling is necessary |
280831d5 PC |
703 | const bool doScale = |
704 | xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10; | |
e90411c2 | 705 | |
280831d5 PC |
706 | // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other |
707 | GdkPoint* gpts = reinterpret_cast<GdkPoint*>(points); | |
e90411c2 | 708 | |
280831d5 | 709 | if (doScale) |
e90411c2 | 710 | gpts = new GdkPoint[n]; |
7d5af6fa | 711 | |
ab9d0a8c | 712 | for (int i = 0; i < n; i++) |
265898fd | 713 | { |
280831d5 PC |
714 | if (doScale) |
715 | { | |
716 | gpts[i].x = XLOG2DEV(points[i].x + xoffset); | |
717 | gpts[i].y = YLOG2DEV(points[i].y + yoffset); | |
e90411c2 | 718 | } |
280831d5 | 719 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); |
e90411c2 | 720 | } |
6eb37239 | 721 | |
888dde65 RR |
722 | if (m_gdkwindow) |
723 | gdk_draw_lines( m_gdkwindow, m_penGC, gpts, n); | |
6eb37239 | 724 | |
e90411c2 | 725 | if (doScale) |
280831d5 | 726 | delete[] gpts; |
903f689b | 727 | } |
c801d85f | 728 | |
888dde65 | 729 | void wxWindowDCImpl::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int WXUNUSED(fillStyle) ) |
cf7a7e13 | 730 | { |
ab171e95 | 731 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 732 | |
4bc67cc5 | 733 | if (n <= 0) return; |
7d5af6fa | 734 | |
e90411c2 | 735 | //Check, if scaling is necessary |
280831d5 PC |
736 | const bool doScale = |
737 | xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10; | |
e90411c2 | 738 | |
280831d5 PC |
739 | // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other |
740 | GdkPoint* gdkpoints = reinterpret_cast<GdkPoint*>(points); | |
e90411c2 | 741 | |
280831d5 PC |
742 | if (doScale) |
743 | gdkpoints = new GdkPoint[n]; | |
e90411c2 | 744 | |
265898fd RR |
745 | int i; |
746 | for (i = 0 ; i < n ; i++) | |
747 | { | |
280831d5 PC |
748 | if (doScale) |
749 | { | |
750 | gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset); | |
751 | gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset); | |
e90411c2 | 752 | } |
280831d5 | 753 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); |
e90411c2 | 754 | } |
7d5af6fa | 755 | |
888dde65 | 756 | if (m_gdkwindow) |
72174350 | 757 | { |
04ee05f9 | 758 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
72174350 | 759 | { |
ea3a345f PC |
760 | GdkGC* gc; |
761 | bool originChanged; | |
762 | DrawingSetup(gc, originChanged); | |
763 | ||
764 | gdk_draw_polygon(m_gdkwindow, gc, true, gdkpoints, n); | |
765 | ||
766 | if (originChanged) | |
767 | gdk_gc_set_ts_origin(gc, 0, 0); | |
72174350 | 768 | } |
7d5af6fa | 769 | |
04ee05f9 | 770 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
b0e0d661 | 771 | { |
bb56b0a8 | 772 | /* |
e1208c31 RR |
773 | for (i = 0 ; i < n ; i++) |
774 | { | |
888dde65 | 775 | gdk_draw_line( m_gdkwindow, m_penGC, |
e1208c31 RR |
776 | gdkpoints[i%n].x, |
777 | gdkpoints[i%n].y, | |
778 | gdkpoints[(i+1)%n].x, | |
779 | gdkpoints[(i+1)%n].y); | |
780 | } | |
bb56b0a8 | 781 | */ |
888dde65 | 782 | gdk_draw_polygon( m_gdkwindow, m_penGC, FALSE, gdkpoints, n ); |
ab9d0a8c | 783 | |
265898fd | 784 | } |
6db90681 | 785 | } |
7d5af6fa | 786 | |
e90411c2 | 787 | if (doScale) |
280831d5 | 788 | delete[] gdkpoints; |
903f689b | 789 | } |
c801d85f | 790 | |
888dde65 | 791 | void wxWindowDCImpl::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 792 | { |
ab171e95 | 793 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
c801d85f | 794 | |
72cdf4c9 VZ |
795 | wxCoord xx = XLOG2DEV(x); |
796 | wxCoord yy = YLOG2DEV(y); | |
797 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
798 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
7d5af6fa | 799 | |
265898fd RR |
800 | // CMB: draw nothing if transformed w or h is 0 |
801 | if (ww == 0 || hh == 0) return; | |
6f65e337 | 802 | |
265898fd RR |
803 | // CMB: handle -ve width and/or height |
804 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
805 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
6f65e337 | 806 | |
888dde65 | 807 | if (m_gdkwindow) |
6db90681 | 808 | { |
04ee05f9 | 809 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
72174350 | 810 | { |
ea3a345f PC |
811 | GdkGC* gc; |
812 | bool originChanged; | |
813 | DrawingSetup(gc, originChanged); | |
814 | ||
815 | gdk_draw_rectangle(m_gdkwindow, gc, true, xx, yy, ww, hh); | |
816 | ||
817 | if (originChanged) | |
818 | gdk_gc_set_ts_origin(gc, 0, 0); | |
72174350 | 819 | } |
e1208c31 | 820 | |
04ee05f9 | 821 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
3b5bf828 RR |
822 | { |
823 | #if 1 | |
824 | if ((m_pen.GetWidth() == 2) && (m_pen.GetCap() == wxCAP_ROUND) && | |
04ee05f9 | 825 | (m_pen.GetJoin() == wxJOIN_ROUND) && (m_pen.GetStyle() == wxPENSTYLE_SOLID)) |
3b5bf828 RR |
826 | { |
827 | // Use 2 1-line rects instead | |
828 | gdk_gc_set_line_attributes( m_penGC, 1, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND ); | |
829 | ||
830 | if (m_signX == -1) | |
831 | { | |
832 | // Different for RTL | |
888dde65 RR |
833 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx+1, yy, ww-2, hh-2 ); |
834 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx, yy-1, ww, hh ); | |
3b5bf828 RR |
835 | } |
836 | else | |
837 | { | |
888dde65 RR |
838 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx, yy, ww-2, hh-2 ); |
839 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx-1, yy-1, ww, hh ); | |
3b5bf828 | 840 | } |
f4322df6 | 841 | |
3b5bf828 RR |
842 | // reset |
843 | gdk_gc_set_line_attributes( m_penGC, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND ); | |
844 | } | |
845 | else | |
846 | #endif | |
847 | { | |
848 | // Just use X11 for other cases | |
888dde65 | 849 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); |
3b5bf828 RR |
850 | } |
851 | } | |
6db90681 | 852 | } |
7d5af6fa | 853 | |
265898fd RR |
854 | CalcBoundingBox( x, y ); |
855 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 856 | } |
c801d85f | 857 | |
888dde65 | 858 | void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius ) |
c801d85f | 859 | { |
ab171e95 | 860 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 861 | |
265898fd | 862 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); |
7d5af6fa | 863 | |
72cdf4c9 VZ |
864 | wxCoord xx = XLOG2DEV(x); |
865 | wxCoord yy = YLOG2DEV(y); | |
866 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
867 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
868 | wxCoord rr = XLOG2DEVREL((wxCoord)radius); | |
265898fd RR |
869 | |
870 | // CMB: handle -ve width and/or height | |
871 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
872 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
873 | ||
874 | // CMB: if radius is zero use DrawRectangle() instead to avoid | |
875 | // X drawing errors with small radii | |
876 | if (rr == 0) | |
877 | { | |
ab171e95 | 878 | DoDrawRectangle( x, y, width, height ); |
265898fd RR |
879 | return; |
880 | } | |
881 | ||
882 | // CMB: draw nothing if transformed w or h is 0 | |
883 | if (ww == 0 || hh == 0) return; | |
884 | ||
885 | // CMB: adjust size if outline is drawn otherwise the result is | |
886 | // 1 pixel too wide and high | |
04ee05f9 | 887 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
265898fd RR |
888 | { |
889 | ww--; | |
890 | hh--; | |
891 | } | |
892 | ||
888dde65 | 893 | if (m_gdkwindow) |
265898fd | 894 | { |
6db90681 RR |
895 | // CMB: ensure dd is not larger than rectangle otherwise we |
896 | // get an hour glass shape | |
72cdf4c9 | 897 | wxCoord dd = 2 * rr; |
6db90681 RR |
898 | if (dd > ww) dd = ww; |
899 | if (dd > hh) dd = hh; | |
900 | rr = dd / 2; | |
901 | ||
04ee05f9 | 902 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
6db90681 | 903 | { |
ea3a345f PC |
904 | GdkGC* gc; |
905 | bool originChanged; | |
906 | DrawingSetup(gc, originChanged); | |
907 | ||
908 | gdk_draw_rectangle(m_gdkwindow, gc, true, xx+rr, yy, ww-dd+1, hh); | |
909 | gdk_draw_rectangle(m_gdkwindow, gc, true, xx, yy+rr, ww, hh-dd+1); | |
910 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, dd, dd, 90*64, 90*64); | |
911 | gdk_draw_arc(m_gdkwindow, gc, true, xx+ww-dd, yy, dd, dd, 0, 90*64); | |
912 | gdk_draw_arc(m_gdkwindow, gc, true, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64); | |
913 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy+hh-dd, dd, dd, 180*64, 90*64); | |
914 | ||
915 | if (originChanged) | |
916 | gdk_gc_set_ts_origin(gc, 0, 0); | |
6db90681 | 917 | } |
7d5af6fa | 918 | |
04ee05f9 | 919 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
7d5af6fa | 920 | { |
888dde65 RR |
921 | gdk_draw_line( m_gdkwindow, m_penGC, xx+rr+1, yy, xx+ww-rr, yy ); |
922 | gdk_draw_line( m_gdkwindow, m_penGC, xx+rr+1, yy+hh, xx+ww-rr, yy+hh ); | |
923 | gdk_draw_line( m_gdkwindow, m_penGC, xx, yy+rr+1, xx, yy+hh-rr ); | |
924 | gdk_draw_line( m_gdkwindow, m_penGC, xx+ww, yy+rr+1, xx+ww, yy+hh-rr ); | |
925 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 ); | |
926 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); | |
927 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); | |
928 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 ); | |
7d5af6fa | 929 | } |
265898fd | 930 | } |
7d5af6fa | 931 | |
265898fd RR |
932 | // this ignores the radius |
933 | CalcBoundingBox( x, y ); | |
934 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 935 | } |
c801d85f | 936 | |
888dde65 | 937 | void wxWindowDCImpl::DoDrawEllipse( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 938 | { |
ab171e95 | 939 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 940 | |
72cdf4c9 VZ |
941 | wxCoord xx = XLOG2DEV(x); |
942 | wxCoord yy = YLOG2DEV(y); | |
943 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
944 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
6f65e337 | 945 | |
265898fd RR |
946 | // CMB: handle -ve width and/or height |
947 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
948 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
7d5af6fa | 949 | |
888dde65 | 950 | if (m_gdkwindow) |
6db90681 | 951 | { |
04ee05f9 | 952 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
a56fcaaf | 953 | { |
ea3a345f PC |
954 | GdkGC* gc; |
955 | bool originChanged; | |
956 | DrawingSetup(gc, originChanged); | |
957 | ||
c11bdf68 VZ |
958 | // If the pen is transparent pen we increase the size |
959 | // for better compatibility with other platforms. | |
960 | if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) | |
961 | { | |
962 | ++ww; | |
963 | ++hh; | |
964 | } | |
965 | ||
ea3a345f PC |
966 | gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, ww, hh, 0, 360*64); |
967 | ||
968 | if (originChanged) | |
969 | gdk_gc_set_ts_origin(gc, 0, 0); | |
a56fcaaf | 970 | } |
7d5af6fa | 971 | |
04ee05f9 | 972 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
c11bdf68 | 973 | gdk_draw_arc( m_gdkwindow, m_penGC, false, xx, yy, ww, hh, 0, 360*64 ); |
6db90681 | 974 | } |
7d5af6fa | 975 | |
44856297 | 976 | CalcBoundingBox( x, y ); |
265898fd | 977 | CalcBoundingBox( x + width, y + height ); |
903f689b | 978 | } |
c801d85f | 979 | |
888dde65 | 980 | void wxWindowDCImpl::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) |
c801d85f | 981 | { |
b0e0d661 | 982 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why |
ab9d0a8c | 983 | DoDrawBitmap( (const wxBitmap&)icon, x, y, true ); |
903f689b | 984 | } |
c801d85f | 985 | |
98d8a7ec VZ |
986 | // compare to current clipping region |
987 | bool wxWindowDCImpl::IsOutsideOfClippingRegion(int x, int y, int w, int h) | |
988 | { | |
989 | if (m_currentClippingRegion.IsNull()) | |
990 | return false; | |
991 | ||
992 | wxRegion region(x, y, w, h); | |
993 | region.Intersect( m_currentClippingRegion ); | |
994 | return region.IsEmpty(); | |
995 | } | |
996 | ||
997 | void wxWindowDCImpl::RemoveClipMask(GdkGC *gc) | |
998 | { | |
999 | gdk_gc_set_clip_mask(gc, NULL); | |
1000 | gdk_gc_set_clip_origin(gc, 0, 0); | |
1001 | if (!m_currentClippingRegion.IsNull()) | |
1002 | gdk_gc_set_clip_region(gc, m_currentClippingRegion.GetRegion()); | |
1003 | } | |
1004 | ||
1005 | // For drawing a mono-bitmap (XBitmap) we use the current text GC | |
1006 | void wxWindowDCImpl::DoDrawMonoBitmap(const wxBitmap& bitmap, | |
1007 | int bmp_w, int bmp_h, | |
1008 | int xsrc, int ysrc, | |
1009 | int xdest, int ydest, | |
1010 | int width, int height) | |
1011 | { | |
f3d74739 VZ |
1012 | wxGtkObject<GdkPixmap> |
1013 | bitmap2(gdk_pixmap_new( wxGetRootWindow()->window, bmp_w, bmp_h, -1 )); | |
1014 | wxGtkObject<GdkGC> gc(gdk_gc_new( bitmap2 )); | |
98d8a7ec VZ |
1015 | gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() ); |
1016 | gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() ); | |
1017 | gdk_wx_draw_bitmap(bitmap2, gc, bitmap.GetPixmap(), 0, 0); | |
1018 | ||
1019 | gdk_draw_drawable(m_gdkwindow, m_textGC, bitmap2, xsrc, ysrc, xdest, ydest, | |
1020 | width, height); | |
98d8a7ec VZ |
1021 | } |
1022 | ||
1023 | // Returns a new mask that is the intersection of the old mask | |
1024 | // and m_currentClippingRegion with proper offsets | |
1025 | GdkBitmap* wxWindowDCImpl::GetClippedMask(GdkBitmap* mask, int w, int h, | |
1026 | int x, int y, | |
1027 | int xsrcMask, int ysrcMask) | |
1028 | { | |
1029 | // create monochrome bitmap that will be used as the new mask | |
1030 | GdkBitmap *new_mask = gdk_pixmap_new( wxGetRootWindow()->window, w, h, 1 ); | |
1031 | ||
1032 | GdkColor c0, c1; | |
1033 | c0.pixel = 0; | |
1034 | c1.pixel = 1; | |
f3d74739 | 1035 | wxGtkObject<GdkGC> gc(gdk_gc_new( new_mask )); |
98d8a7ec VZ |
1036 | |
1037 | // zero-ing new_mask | |
1038 | gdk_gc_set_foreground( gc, &c0 ); | |
1039 | gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, w, h ); | |
1040 | ||
1041 | // clipping region | |
1042 | gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() ); | |
1043 | gdk_gc_set_clip_origin( gc, -x, -y ); | |
1044 | ||
1045 | // copy the old mask to the new_mask in the clip region area | |
1046 | gdk_gc_set_background( gc, &c0 ); | |
1047 | gdk_gc_set_foreground( gc, &c1 ); | |
1048 | gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED ); | |
1049 | gdk_gc_set_ts_origin( gc, -xsrcMask, -ysrcMask ); | |
1050 | gdk_gc_set_stipple( gc, mask ); | |
1051 | gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, w, h ); | |
1052 | ||
98d8a7ec VZ |
1053 | return new_mask; |
1054 | } | |
1055 | ||
888dde65 | 1056 | void wxWindowDCImpl::DoDrawBitmap( const wxBitmap &bitmap, |
72cdf4c9 | 1057 | wxCoord x, wxCoord y, |
b0e0d661 | 1058 | bool useMask ) |
4bc67cc5 | 1059 | { |
ab171e95 | 1060 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1061 | |
ab171e95 | 1062 | wxCHECK_RET( bitmap.IsOk(), wxT("invalid bitmap") ); |
7d5af6fa | 1063 | |
b85229d1 | 1064 | bool is_mono = bitmap.GetDepth() == 1; |
82ea63e6 | 1065 | |
d90c9596 | 1066 | // scale/translate size and position |
265898fd RR |
1067 | int xx = XLOG2DEV(x); |
1068 | int yy = YLOG2DEV(y); | |
7d5af6fa | 1069 | |
4bc67cc5 RR |
1070 | int w = bitmap.GetWidth(); |
1071 | int h = bitmap.GetHeight(); | |
f4322df6 | 1072 | |
888dde65 | 1073 | if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) |
847dfdb4 | 1074 | xx -= w; |
f4322df6 | 1075 | |
6453876e RR |
1076 | CalcBoundingBox( x, y ); |
1077 | CalcBoundingBox( x + w, y + h ); | |
7d5af6fa | 1078 | |
888dde65 | 1079 | if (!m_gdkwindow) return; |
7d5af6fa | 1080 | |
4bc67cc5 RR |
1081 | int ww = XLOG2DEVREL(w); |
1082 | int hh = YLOG2DEVREL(h); | |
7d5af6fa | 1083 | |
98d8a7ec VZ |
1084 | if (IsOutsideOfClippingRegion( xx,yy,ww,hh )) |
1085 | return; | |
5f170f33 | 1086 | |
ab9d0a8c | 1087 | // scale bitmap if required |
d90c9596 | 1088 | wxBitmap use_bitmap = bitmap; |
4bc67cc5 | 1089 | if ((w != ww) || (h != hh)) |
98d8a7ec | 1090 | use_bitmap = use_bitmap.Rescale( 0, 0, w, h, ww, hh ); |
ab9d0a8c | 1091 | |
98d8a7ec | 1092 | // get mask if any |
463c1fa1 | 1093 | GdkBitmap *mask = (GdkBitmap *) NULL; |
280831d5 PC |
1094 | if (useMask && use_bitmap.GetMask()) |
1095 | mask = use_bitmap.GetMask()->GetBitmap(); | |
1096 | ||
98d8a7ec | 1097 | // for drawing a mono-bitmap we use the current text GC |
280831d5 | 1098 | GdkGC* use_gc = is_mono ? m_textGC : m_penGC; |
7d5af6fa | 1099 | |
98d8a7ec | 1100 | bool mask_owned = false; |
ab9d0a8c | 1101 | |
280831d5 | 1102 | if (mask != NULL) |
d90c9596 RR |
1103 | { |
1104 | if (!m_currentClippingRegion.IsNull()) | |
82ea63e6 | 1105 | { |
98d8a7ec VZ |
1106 | mask = GetClippedMask(mask, ww, hh, xx, yy, 0, 0); |
1107 | mask_owned = true; | |
d90c9596 | 1108 | } |
ab9d0a8c | 1109 | |
280831d5 PC |
1110 | gdk_gc_set_clip_mask(use_gc, mask); |
1111 | gdk_gc_set_clip_origin(use_gc, xx, yy); | |
d90c9596 | 1112 | } |
7d5af6fa | 1113 | |
98d8a7ec | 1114 | // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. |
82ea63e6 | 1115 | if (is_mono) |
d90c9596 | 1116 | { |
98d8a7ec | 1117 | DoDrawMonoBitmap(use_bitmap, ww, hh, 0, 0, xx, yy, -1, -1); |
d90c9596 | 1118 | } |
82ea63e6 | 1119 | else |
d90c9596 | 1120 | { |
ff654490 | 1121 | if (use_bitmap.HasPixbuf()) |
feac7937 | 1122 | { |
888dde65 | 1123 | gdk_draw_pixbuf(m_gdkwindow, use_gc, |
feac7937 VS |
1124 | use_bitmap.GetPixbuf(), |
1125 | 0, 0, xx, yy, -1, -1, | |
1126 | GDK_RGB_DITHER_NORMAL, xx, yy); | |
1127 | } | |
1128 | else | |
feac7937 | 1129 | { |
888dde65 | 1130 | gdk_draw_drawable(m_gdkwindow, use_gc, |
15f0ad70 MR |
1131 | use_bitmap.GetPixmap(), |
1132 | 0, 0, xx, yy, -1, -1); | |
feac7937 | 1133 | } |
d90c9596 | 1134 | } |
72174350 | 1135 | |
d90c9596 | 1136 | // remove mask again if any |
280831d5 | 1137 | if (mask != NULL) |
463c1fa1 | 1138 | { |
98d8a7ec VZ |
1139 | RemoveClipMask(use_gc); |
1140 | if (mask_owned) | |
1141 | g_object_unref(mask); | |
463c1fa1 | 1142 | } |
463c1fa1 RR |
1143 | } |
1144 | ||
888dde65 | 1145 | bool wxWindowDCImpl::DoBlit( wxCoord xdest, wxCoord ydest, |
1e6feb95 VZ |
1146 | wxCoord width, wxCoord height, |
1147 | wxDC *source, | |
1148 | wxCoord xsrc, wxCoord ysrc, | |
1149 | int logical_func, | |
0cbff120 JS |
1150 | bool useMask, |
1151 | wxCoord xsrcMask, wxCoord ysrcMask ) | |
c801d85f | 1152 | { |
ab171e95 | 1153 | wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") ); |
7d5af6fa | 1154 | |
ab9d0a8c | 1155 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
7d5af6fa | 1156 | |
888dde65 | 1157 | if (!m_gdkwindow) return false; |
7d5af6fa | 1158 | |
1e6feb95 | 1159 | // transform the source DC coords to the device ones |
772b3767 PC |
1160 | xsrc = source->LogicalToDeviceX(xsrc); |
1161 | ysrc = source->LogicalToDeviceY(ysrc); | |
1e6feb95 | 1162 | |
e19a8aea | 1163 | wxBitmap selected; |
f98bd6d6 | 1164 | wxMemoryDC *memDC = wxDynamicCast(source, wxMemoryDC); |
e19a8aea VZ |
1165 | if ( memDC ) |
1166 | { | |
1167 | selected = memDC->GetSelectedBitmap(); | |
1168 | if ( !selected.IsOk() ) | |
1169 | return false; | |
1170 | } | |
f4322df6 | 1171 | |
ab9d0a8c WS |
1172 | bool use_bitmap_method = false; |
1173 | bool is_mono = false; | |
7d5af6fa | 1174 | |
0cbff120 JS |
1175 | if (xsrcMask == -1 && ysrcMask == -1) |
1176 | { | |
d90c9596 RR |
1177 | xsrcMask = xsrc; |
1178 | ysrcMask = ysrc; | |
0cbff120 JS |
1179 | } |
1180 | ||
ab171e95 | 1181 | if (selected.IsOk()) |
6e13c196 | 1182 | { |
f98bd6d6 | 1183 | is_mono = (selected.GetDepth() == 1); |
d90c9596 RR |
1184 | |
1185 | // we use the "XCopyArea" way to copy a memory dc into | |
1186 | // a different window if the memory dc BOTH | |
1187 | // a) doesn't have any mask or its mask isn't used | |
1188 | // b) it is clipped | |
1189 | // c) is not 1-bit | |
7d5af6fa | 1190 | |
f98bd6d6 | 1191 | if (useMask && (selected.GetMask())) |
b0e0d661 | 1192 | { |
d90c9596 RR |
1193 | // we HAVE TO use the direct way for memory dcs |
1194 | // that have mask since the XCopyArea doesn't know | |
1195 | // about masks | |
ab9d0a8c | 1196 | use_bitmap_method = true; |
b0e0d661 | 1197 | } |
d90c9596 | 1198 | else if (is_mono) |
b0e0d661 | 1199 | { |
d90c9596 RR |
1200 | // we HAVE TO use the direct way for memory dcs |
1201 | // that are bitmaps because XCopyArea doesn't cope | |
1202 | // with different bit depths | |
ab9d0a8c | 1203 | use_bitmap_method = true; |
b0e0d661 VZ |
1204 | } |
1205 | else if ((xsrc == 0) && (ysrc == 0) && | |
f98bd6d6 RD |
1206 | (width == selected.GetWidth()) && |
1207 | (height == selected.GetHeight())) | |
b0e0d661 | 1208 | { |
d90c9596 RR |
1209 | // we SHOULD use the direct way if all of the bitmap |
1210 | // in the memory dc is copied in which case XCopyArea | |
1211 | // wouldn't be able able to boost performace by reducing | |
1212 | // the area to be scaled | |
ab9d0a8c | 1213 | use_bitmap_method = true; |
b0e0d661 | 1214 | } |
6e13c196 | 1215 | } |
7d5af6fa | 1216 | |
265898fd RR |
1217 | CalcBoundingBox( xdest, ydest ); |
1218 | CalcBoundingBox( xdest + width, ydest + height ); | |
7d5af6fa | 1219 | |
d90c9596 | 1220 | // scale/translate size and position |
3d2d8da1 RR |
1221 | wxCoord xx = XLOG2DEV(xdest); |
1222 | wxCoord yy = YLOG2DEV(ydest); | |
1223 | ||
1224 | wxCoord ww = XLOG2DEVREL(width); | |
1225 | wxCoord hh = YLOG2DEVREL(height); | |
1226 | ||
d90c9596 | 1227 | // compare to current clipping region |
98d8a7ec VZ |
1228 | if (IsOutsideOfClippingRegion( xx,yy,ww,hh )) |
1229 | return true; | |
3d2d8da1 | 1230 | |
4bc67cc5 RR |
1231 | int old_logical_func = m_logicalFunction; |
1232 | SetLogicalFunction( logical_func ); | |
5f170f33 | 1233 | |
6e13c196 | 1234 | if (use_bitmap_method) |
6f65e337 | 1235 | { |
d90c9596 | 1236 | // scale/translate bitmap size |
f98bd6d6 RD |
1237 | wxCoord bm_width = selected.GetWidth(); |
1238 | wxCoord bm_height = selected.GetHeight(); | |
7d5af6fa | 1239 | |
551b5391 RR |
1240 | // Get clip coords for the bitmap. If we don't |
1241 | // use wxBitmap::Rescale(), which can clip the | |
1242 | // bitmap, these are the same as the original | |
1243 | // coordinates | |
1244 | wxCoord cx = xx; | |
1245 | wxCoord cy = yy; | |
1246 | wxCoord cw = ww; | |
1247 | wxCoord ch = hh; | |
ab9d0a8c | 1248 | |
d90c9596 RR |
1249 | // interpret userscale of src too |
1250 | double xsc,ysc; | |
1251 | memDC->GetUserScale(&xsc,&ysc); | |
1252 | bm_width = (int) (bm_width / xsc); | |
1253 | bm_height = (int) (bm_height / ysc); | |
1254 | ||
72cdf4c9 VZ |
1255 | wxCoord bm_ww = XLOG2DEVREL( bm_width ); |
1256 | wxCoord bm_hh = YLOG2DEVREL( bm_height ); | |
7d5af6fa | 1257 | |
551b5391 | 1258 | // Scale bitmap if required |
f98bd6d6 RD |
1259 | wxBitmap use_bitmap = selected; |
1260 | if ((selected.GetWidth()!= bm_ww) || ( selected.GetHeight()!= bm_hh)) | |
6e13c196 | 1261 | { |
551b5391 RR |
1262 | // This indicates that the blitting code below will get |
1263 | // a clipped bitmap and therefore needs to move the origin | |
1264 | // accordingly | |
1265 | wxRegion tmp( xx,yy,ww,hh ); | |
93da796d RR |
1266 | if (!m_currentClippingRegion.IsNull()) |
1267 | tmp.Intersect( m_currentClippingRegion ); | |
551b5391 | 1268 | tmp.GetBox(cx,cy,cw,ch); |
ab9d0a8c | 1269 | |
551b5391 | 1270 | // Scale and clipped bitmap |
f98bd6d6 | 1271 | use_bitmap = selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh); |
6e13c196 | 1272 | } |
7d5af6fa | 1273 | |
d90c9596 | 1274 | // apply mask if any |
6e13c196 | 1275 | GdkBitmap *mask = (GdkBitmap *) NULL; |
280831d5 PC |
1276 | if (useMask && use_bitmap.GetMask()) |
1277 | mask = use_bitmap.GetMask()->GetBitmap(); | |
1278 | ||
1279 | GdkGC* use_gc = is_mono ? m_textGC : m_penGC; | |
7d5af6fa | 1280 | |
98d8a7ec | 1281 | bool mask_owned = false; |
ab9d0a8c | 1282 | |
280831d5 | 1283 | if (mask != NULL) |
6e13c196 | 1284 | { |
e1208c31 | 1285 | if (!m_currentClippingRegion.IsNull()) |
3d2d8da1 | 1286 | { |
98d8a7ec VZ |
1287 | mask = GetClippedMask(mask, bm_ww, bm_hh, cx, cy, |
1288 | xsrcMask, ysrcMask); | |
1289 | mask_owned = true; | |
3d2d8da1 | 1290 | } |
d90c9596 | 1291 | |
280831d5 | 1292 | gdk_gc_set_clip_mask(use_gc, mask); |
98d8a7ec | 1293 | if (mask_owned) |
280831d5 | 1294 | gdk_gc_set_clip_origin(use_gc, cx, cy); |
82ea63e6 | 1295 | else |
280831d5 | 1296 | gdk_gc_set_clip_origin(use_gc, cx - xsrcMask, cy - ysrcMask); |
6e13c196 | 1297 | } |
7d5af6fa | 1298 | |
98d8a7ec | 1299 | // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. |
82ea63e6 | 1300 | if (is_mono) |
d90c9596 | 1301 | { |
98d8a7ec VZ |
1302 | DoDrawMonoBitmap(use_bitmap, bm_ww, bm_hh, |
1303 | xsrc, ysrc, cx, cy, cw, ch); | |
d90c9596 | 1304 | } |
82ea63e6 | 1305 | else |
d90c9596 | 1306 | { |
888dde65 RR |
1307 | // was: gdk_draw_drawable( m_gdkwindow, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh ); |
1308 | gdk_draw_drawable(m_gdkwindow, use_gc, use_bitmap.GetPixmap(), xsrc, ysrc, cx, cy, cw, ch); | |
d90c9596 | 1309 | } |
82ea63e6 | 1310 | |
d90c9596 | 1311 | // remove mask again if any |
280831d5 | 1312 | if (mask != NULL) |
6e13c196 | 1313 | { |
98d8a7ec VZ |
1314 | RemoveClipMask(use_gc); |
1315 | if (mask_owned) | |
1316 | g_object_unref (mask); | |
265898fd | 1317 | } |
6f65e337 | 1318 | } |
d90c9596 | 1319 | else // use_bitmap_method |
6e13c196 | 1320 | { |
ab171e95 | 1321 | if (selected.IsOk() && ((width != ww) || (height != hh))) |
b0e0d661 | 1322 | { |
98d8a7ec | 1323 | wxBitmap bitmap = selected.Rescale( xsrc, ysrc, width, height, ww, hh ); |
d90c9596 | 1324 | // draw scaled bitmap |
98d8a7ec | 1325 | gdk_draw_drawable( m_gdkwindow, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 ); |
b0e0d661 VZ |
1326 | } |
1327 | else | |
1328 | { | |
ab9d0a8c | 1329 | // No scaling and not a memory dc with a mask either |
ab171e95 | 1330 | GdkWindow* window = NULL; |
888dde65 RR |
1331 | wxDCImpl *impl = source->GetImpl(); |
1332 | wxWindowDCImpl *gtk_impl = wxDynamicCast(impl, wxWindowDCImpl); | |
ab171e95 RR |
1333 | if (gtk_impl) |
1334 | window = gtk_impl->GetGDKWindow(); | |
f98bd6d6 | 1335 | if ( !window ) |
c21c8158 RR |
1336 | { |
1337 | SetLogicalFunction( old_logical_func ); | |
f98bd6d6 | 1338 | return false; |
c21c8158 | 1339 | } |
f4322df6 | 1340 | |
d90c9596 | 1341 | // copy including child window contents |
a56fcaaf | 1342 | gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); |
888dde65 | 1343 | gdk_draw_drawable( m_gdkwindow, m_penGC, |
f98bd6d6 | 1344 | window, |
15f0ad70 MR |
1345 | xsrc, ysrc, xx, yy, |
1346 | width, height ); | |
a56fcaaf | 1347 | gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); |
b0e0d661 | 1348 | } |
6e13c196 | 1349 | } |
c801d85f | 1350 | |
4bc67cc5 | 1351 | SetLogicalFunction( old_logical_func ); |
ab9d0a8c WS |
1352 | |
1353 | return true; | |
903f689b | 1354 | } |
c801d85f | 1355 | |
888dde65 | 1356 | void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) |
c801d85f | 1357 | { |
ab171e95 | 1358 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
18a2fa37 | 1359 | |
888dde65 | 1360 | if (!m_gdkwindow) return; |
ab9d0a8c | 1361 | |
2b5f62a0 | 1362 | if (text.empty()) return; |
7d5af6fa | 1363 | |
265898fd RR |
1364 | x = XLOG2DEV(x); |
1365 | y = YLOG2DEV(y); | |
18a2fa37 | 1366 | |
cfcc3932 | 1367 | wxCHECK_RET( m_context, wxT("no Pango context") ); |
61850501 | 1368 | wxCHECK_RET( m_layout, wxT("no Pango layout") ); |
cfcc3932 | 1369 | wxCHECK_RET( m_fontdesc, wxT("no Pango font description") ); |
e4da1035 | 1370 | |
5f22e8cc | 1371 | gdk_pango_context_set_colormap( m_context, m_cmap ); // not needed in gtk+ >= 2.6 |
24bbbfb1 | 1372 | |
ab171e95 | 1373 | bool underlined = m_font.IsOk() && m_font.GetUnderlined(); |
1dbeee57 | 1374 | |
d6afc2c8 | 1375 | wxCharBuffer data = wxGTK_CONV(text); |
a3669332 | 1376 | if ( !data ) |
7706daf3 | 1377 | return; |
67a083dd RR |
1378 | size_t datalen = strlen(data); |
1379 | ||
5f4d1820 VZ |
1380 | // in Pango >= 1.16 the "underline of leading/trailing spaces" bug |
1381 | // has been fixed and thus the hack implemented below should never be used | |
1382 | static bool pangoOk = !wx_pango_version_check(1, 16, 0); | |
1383 | ||
1384 | bool needshack = underlined && !pangoOk; | |
67a083dd RR |
1385 | |
1386 | if (needshack) | |
1387 | { | |
1388 | // a PangoLayout which has leading/trailing spaces with underlined font | |
1389 | // is not correctly drawn by this pango version: Pango won't underline the spaces. | |
1390 | // This can be a problem; e.g. wxHTML rendering of underlined text relies on | |
1391 | // this behaviour. To workaround this problem, we use a special hack here | |
1392 | // suggested by pango maintainer Behdad Esfahbod: we prepend and append two | |
1393 | // empty space characters and give them a dummy colour attribute. | |
1394 | // This will force Pango to underline the leading/trailing spaces, too. | |
1395 | ||
d6afc2c8 | 1396 | wxCharBuffer data_tmp(datalen + 6); |
67a083dd | 1397 | // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format |
d6afc2c8 | 1398 | memcpy(data_tmp.data(), "\342\200\214", 3); |
67a083dd | 1399 | // copy the user string |
d6afc2c8 | 1400 | memcpy(data_tmp.data() + 3, data, datalen); |
67a083dd | 1401 | // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format |
d6afc2c8 | 1402 | memcpy(data_tmp.data() + 3 + datalen, "\342\200\214", 3); |
67a083dd | 1403 | |
d6afc2c8 | 1404 | data = data_tmp; |
67a083dd | 1405 | datalen += 6; |
67a083dd | 1406 | } |
ab9d0a8c | 1407 | |
d6afc2c8 PC |
1408 | pango_layout_set_text(m_layout, data, datalen); |
1409 | ||
1dbeee57 VS |
1410 | if (underlined) |
1411 | { | |
1412 | PangoAttrList *attrs = pango_attr_list_new(); | |
1413 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1414 | a->start_index = 0; | |
1415 | a->end_index = datalen; | |
1416 | pango_attr_list_insert(attrs, a); | |
67a083dd RR |
1417 | |
1418 | if (needshack) | |
1419 | { | |
1420 | // dummy colour for the leading space | |
1421 | a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614); | |
1422 | a->start_index = 0; | |
1423 | a->end_index = 1; | |
1424 | pango_attr_list_insert(attrs, a); | |
1425 | ||
1426 | // dummy colour for the trailing space | |
1427 | a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614); | |
1428 | a->start_index = datalen - 1; | |
1429 | a->end_index = datalen; | |
1430 | pango_attr_list_insert(attrs, a); | |
1431 | } | |
1432 | ||
1dbeee57 VS |
1433 | pango_layout_set_attributes(m_layout, attrs); |
1434 | pango_attr_list_unref(attrs); | |
1435 | } | |
e4da1035 | 1436 | |
46142dc9 PC |
1437 | int oldSize = 0; |
1438 | const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001; | |
1439 | if (isScaled) | |
e4da1035 | 1440 | { |
5f22e8cc RR |
1441 | // If there is a user or actually any scale applied to |
1442 | // the device context, scale the font. | |
ab9d0a8c | 1443 | |
5f22e8cc | 1444 | // scale font description |
46142dc9 PC |
1445 | oldSize = pango_font_description_get_size(m_fontdesc); |
1446 | pango_font_description_set_size(m_fontdesc, int(oldSize * m_scaleY)); | |
ab9d0a8c | 1447 | |
5f22e8cc RR |
1448 | // actually apply scaled font |
1449 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
46142dc9 | 1450 | } |
ab9d0a8c | 1451 | |
46142dc9 PC |
1452 | int w, h; |
1453 | pango_layout_get_pixel_size(m_layout, &w, &h); | |
ab9d0a8c | 1454 | |
46142dc9 PC |
1455 | // Draw layout. |
1456 | int x_rtl = x; | |
1457 | if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) | |
1458 | x_rtl -= w; | |
5f22e8cc RR |
1459 | |
1460 | const GdkColor* bg_col = NULL; | |
1461 | if (m_backgroundMode == wxBRUSHSTYLE_SOLID) | |
1462 | bg_col = m_textBackgroundColour.GetColor(); | |
1463 | ||
1464 | gdk_draw_layout_with_colors(m_gdkwindow, m_textGC, x_rtl, y, m_layout, NULL, bg_col); | |
ab9d0a8c | 1465 | |
46142dc9 PC |
1466 | if (isScaled) |
1467 | { | |
e4da1035 RR |
1468 | // reset unscaled size |
1469 | pango_font_description_set_size( m_fontdesc, oldSize ); | |
ab9d0a8c | 1470 | |
61850501 | 1471 | // actually apply unscaled font |
e4da1035 RR |
1472 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1473 | } | |
1dbeee57 VS |
1474 | if (underlined) |
1475 | { | |
1476 | // undo underline attributes setting: | |
1477 | pango_layout_set_attributes(m_layout, NULL); | |
1478 | } | |
ab9d0a8c | 1479 | |
46142dc9 PC |
1480 | CalcBoundingBox(x + int(w / m_scaleX), y + int(h / m_scaleY)); |
1481 | CalcBoundingBox(x, y); | |
903f689b | 1482 | } |
c801d85f | 1483 | |
e1bd1db2 VZ |
1484 | // TODO: When GTK2.6 is required, merge DoDrawText and DoDrawRotatedText to |
1485 | // avoid code duplication | |
888dde65 | 1486 | void wxWindowDCImpl::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle ) |
95724b1a | 1487 | { |
888dde65 | 1488 | if (!m_gdkwindow || text.empty()) |
1c2d839f PC |
1489 | return; |
1490 | ||
ab171e95 | 1491 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
1c2d839f | 1492 | |
e1bd1db2 VZ |
1493 | #if __WXGTK26__ |
1494 | if (!gtk_check_version(2,6,0)) | |
1495 | { | |
1496 | x = XLOG2DEV(x); | |
1497 | y = YLOG2DEV(y); | |
1498 | ||
1499 | pango_layout_set_text(m_layout, wxGTK_CONV(text), -1); | |
1500 | ||
1501 | if (m_font.GetUnderlined()) | |
1502 | { | |
1503 | PangoAttrList *attrs = pango_attr_list_new(); | |
1504 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1505 | pango_attr_list_insert(attrs, a); | |
1506 | pango_layout_set_attributes(m_layout, attrs); | |
1507 | pango_attr_list_unref(attrs); | |
1508 | } | |
1509 | ||
1510 | int oldSize = 0; | |
1511 | const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001; | |
1512 | if (isScaled) | |
1513 | { | |
1514 | //TODO: when Pango >= 1.6 is required, use pango_matrix_scale() | |
1515 | // If there is a user or actually any scale applied to | |
1516 | // the device context, scale the font. | |
1517 | ||
1518 | // scale font description | |
1519 | oldSize = pango_font_description_get_size(m_fontdesc); | |
1520 | pango_font_description_set_size(m_fontdesc, int(oldSize * m_scaleY)); | |
1521 | ||
1522 | // actually apply scaled font | |
1523 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1524 | } | |
1525 | ||
1526 | int w, h; | |
1527 | pango_layout_get_pixel_size(m_layout, &w, &h); | |
1528 | ||
1529 | const GdkColor* bg_col = NULL; | |
1530 | if (m_backgroundMode == wxBRUSHSTYLE_SOLID) | |
1531 | bg_col = m_textBackgroundColour.GetColor(); | |
1532 | ||
1533 | // rotate the text | |
1534 | PangoMatrix matrix = PANGO_MATRIX_INIT; | |
1535 | pango_matrix_rotate (&matrix, angle); | |
1536 | pango_context_set_matrix (m_context, &matrix); | |
1537 | pango_layout_context_changed (m_layout); | |
1538 | ||
1539 | // To be compatible with MSW, the rotation axis must be in the old | |
1540 | // top-left corner. | |
1541 | // Calculate the vertices of the rotated rectangle containing the text, | |
1542 | // relative to the old top-left vertex. | |
1543 | // We could use the matrix for this, but it's simpler with trignonometry. | |
1544 | double rad = DegToRad(angle); | |
1545 | // the rectangle vertices are counted clockwise with the first one | |
1546 | // being at (0, 0) | |
1547 | double x2 = w * cos(rad); | |
1548 | double y2 = -w * sin(rad); // y axis points to the bottom, hence minus | |
1549 | double x4 = h * sin(rad); | |
1550 | double y4 = h * cos(rad); | |
1551 | double x3 = x4 + x2; | |
1552 | double y3 = y4 + y2; | |
1553 | // Then we calculate max and min of the rotated rectangle. | |
1554 | wxCoord maxX = (wxCoord)(dmax(dmax(0, x2), dmax(x3, x4)) + 0.5), | |
1555 | maxY = (wxCoord)(dmax(dmax(0, y2), dmax(y3, y4)) + 0.5), | |
1556 | minX = (wxCoord)(dmin(dmin(0, x2), dmin(x3, x4)) - 0.5), | |
1557 | minY = (wxCoord)(dmin(dmin(0, y2), dmin(y3, y4)) - 0.5); | |
1558 | ||
1559 | gdk_draw_layout_with_colors(m_gdkwindow, m_textGC, x+minX, y+minY, | |
1560 | m_layout, NULL, bg_col); | |
1561 | ||
1562 | if (m_font.GetUnderlined()) | |
1563 | pango_layout_set_attributes(m_layout, NULL); | |
1564 | ||
1565 | // clean up the transformation matrix | |
1566 | pango_context_set_matrix(m_context, NULL); | |
1567 | ||
1568 | if (isScaled) | |
1569 | { | |
1570 | // reset unscaled size | |
1571 | pango_font_description_set_size( m_fontdesc, oldSize ); | |
1572 | ||
1573 | // actually apply unscaled font | |
1574 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1575 | } | |
1576 | ||
1577 | CalcBoundingBox(x+minX, y+minY); | |
1578 | CalcBoundingBox(x+maxX, y+maxY); | |
1579 | } | |
1580 | else | |
1581 | #endif //__WXGTK26__ | |
1582 | { | |
1583 | #if wxUSE_IMAGE | |
c77a6796 | 1584 | if ( wxIsNullDouble(angle) ) |
95724b1a | 1585 | { |
ab171e95 | 1586 | DoDrawText(text, x, y); |
95724b1a VZ |
1587 | return; |
1588 | } | |
1589 | ||
bf47e398 RD |
1590 | wxCoord w; |
1591 | wxCoord h; | |
1592 | ||
68567a96 | 1593 | // TODO: implement later without GdkFont for GTK 2.0 |
ab171e95 | 1594 | DoGetTextExtent(text, &w, &h, NULL,NULL, &m_font); |
ab9d0a8c | 1595 | |
9a8c7620 VZ |
1596 | // draw the string normally |
1597 | wxBitmap src(w, h); | |
95724b1a VZ |
1598 | wxMemoryDC dc; |
1599 | dc.SelectObject(src); | |
1600 | dc.SetFont(GetFont()); | |
f1c72f0c | 1601 | dc.SetBackground(*wxBLACK_BRUSH); |
95724b1a VZ |
1602 | dc.SetBrush(*wxBLACK_BRUSH); |
1603 | dc.Clear(); | |
f1c72f0c | 1604 | dc.SetTextForeground( *wxWHITE ); |
95724b1a | 1605 | dc.DrawText(text, 0, 0); |
9a8c7620 | 1606 | dc.SelectObject(wxNullBitmap); |
95724b1a VZ |
1607 | |
1608 | // Calculate the size of the rotated bounding box. | |
9a8c7620 VZ |
1609 | double rad = DegToRad(angle); |
1610 | double dx = cos(rad), | |
1611 | dy = sin(rad); | |
1612 | ||
1613 | // the rectngle vertices are counted clockwise with the first one being at | |
1614 | // (0, 0) (or, rather, at (x, y)) | |
1615 | double x2 = w*dx, | |
1616 | y2 = -w*dy; // y axis points to the bottom, hence minus | |
1617 | double x4 = h*dy, | |
1618 | y4 = h*dx; | |
1619 | double x3 = x4 + x2, | |
1620 | y3 = y4 + y2; | |
ab9d0a8c | 1621 | |
72174350 | 1622 | // calc max and min |
9a8c7620 VZ |
1623 | wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5), |
1624 | maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5), | |
1625 | minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5), | |
1626 | minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5); | |
1627 | ||
72174350 | 1628 | |
f1c72f0c | 1629 | wxImage image = src.ConvertToImage(); |
9a8c7620 | 1630 | |
f1c72f0c RR |
1631 | image.ConvertColourToAlpha( m_textForegroundColour.Red(), |
1632 | m_textForegroundColour.Green(), | |
1633 | m_textForegroundColour.Blue() ); | |
1634 | image = image.Rotate( rad, wxPoint(0,0) ); | |
ab9d0a8c | 1635 | |
1d65e535 RR |
1636 | int i_angle = (int) angle; |
1637 | i_angle = i_angle % 360; | |
c2cb80c8 KH |
1638 | if (i_angle < 0) |
1639 | i_angle += 360; | |
1d65e535 RR |
1640 | int xoffset = 0; |
1641 | if ((i_angle >= 90.0) && (i_angle < 270.0)) | |
1642 | xoffset = image.GetWidth(); | |
1643 | int yoffset = 0; | |
1644 | if ((i_angle >= 0.0) && (i_angle < 180.0)) | |
1645 | yoffset = image.GetHeight(); | |
ab9d0a8c | 1646 | |
1d65e535 RR |
1647 | if ((i_angle >= 0) && (i_angle < 90)) |
1648 | yoffset -= (int)( cos(rad)*h ); | |
1649 | if ((i_angle >= 90) && (i_angle < 180)) | |
ab9d0a8c | 1650 | xoffset -= (int)( sin(rad)*h ); |
1d65e535 RR |
1651 | if ((i_angle >= 180) && (i_angle < 270)) |
1652 | yoffset -= (int)( cos(rad)*h ); | |
1653 | if ((i_angle >= 270) && (i_angle < 360)) | |
1654 | xoffset -= (int)( sin(rad)*h ); | |
ab9d0a8c | 1655 | |
1d65e535 RR |
1656 | int i_x = x - xoffset; |
1657 | int i_y = y - yoffset; | |
ab9d0a8c | 1658 | |
f1c72f0c | 1659 | src = image; |
1d65e535 | 1660 | DoDrawBitmap( src, i_x, i_y, true ); |
9a8c7620 | 1661 | |
95724b1a | 1662 | |
9a8c7620 VZ |
1663 | // it would be better to draw with non underlined font and draw the line |
1664 | // manually here (it would be more straight...) | |
1665 | #if 0 | |
1666 | if ( m_font.GetUnderlined() ) | |
1667 | { | |
888dde65 | 1668 | gdk_draw_line( m_gdkwindow, m_textGC, |
9a8c7620 VZ |
1669 | XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent), |
1670 | XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent)); | |
1671 | } | |
1672 | #endif // 0 | |
1673 | ||
9a8c7620 VZ |
1674 | // update the bounding box |
1675 | CalcBoundingBox(x + minX, y + minY); | |
1676 | CalcBoundingBox(x + maxX, y + maxY); | |
8d22935d VZ |
1677 | #else // !wxUSE_IMAGE |
1678 | wxUnusedVar(text); | |
1679 | wxUnusedVar(x); | |
1680 | wxUnusedVar(y); | |
1681 | wxUnusedVar(angle); | |
1682 | #endif // wxUSE_IMAGE/!wxUSE_IMAGE | |
e1bd1db2 | 1683 | } |
95724b1a VZ |
1684 | } |
1685 | ||
888dde65 | 1686 | void wxWindowDCImpl::DoGetTextExtent(const wxString &string, |
72cdf4c9 VZ |
1687 | wxCoord *width, wxCoord *height, |
1688 | wxCoord *descent, wxCoord *externalLeading, | |
c94f845b | 1689 | const wxFont *theFont) const |
c801d85f | 1690 | { |
b1f0abe4 VZ |
1691 | if ( width ) |
1692 | *width = 0; | |
1693 | if ( height ) | |
1694 | *height = 0; | |
1695 | if ( descent ) | |
1696 | *descent = 0; | |
1697 | if ( externalLeading ) | |
1698 | *externalLeading = 0; | |
1699 | ||
ab9d0a8c | 1700 | if (string.empty()) |
48d011c8 | 1701 | return; |
ab9d0a8c | 1702 | |
bf5752a4 | 1703 | // ensure that theFont is always non-NULL |
ab171e95 | 1704 | if ( !theFont || !theFont->IsOk() ) |
86d58c90 | 1705 | theFont = &m_font; |
bf5752a4 VZ |
1706 | |
1707 | // and use it if it's valid | |
ab171e95 | 1708 | if ( theFont->IsOk() ) |
bf5752a4 VZ |
1709 | { |
1710 | pango_layout_set_font_description | |
1711 | ( | |
1712 | m_layout, | |
1713 | theFont->GetNativeFontInfo()->description | |
1714 | ); | |
1715 | } | |
ab9d0a8c | 1716 | |
2b5f62a0 | 1717 | // Set layout's text |
bf5752a4 | 1718 | const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, *theFont); |
a1e101d0 VZ |
1719 | if ( !dataUTF8 ) |
1720 | { | |
1721 | // hardly ideal, but what else can we do if conversion failed? | |
1722 | return; | |
1723 | } | |
1724 | ||
86d58c90 | 1725 | pango_layout_set_text(m_layout, dataUTF8, -1); |
ab9d0a8c | 1726 | |
86d58c90 PC |
1727 | int h; |
1728 | pango_layout_get_pixel_size(m_layout, width, &h); | |
48d011c8 RR |
1729 | if (descent) |
1730 | { | |
f69e2009 VS |
1731 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); |
1732 | int baseline = pango_layout_iter_get_baseline(iter); | |
1733 | pango_layout_iter_free(iter); | |
1734 | *descent = h - PANGO_PIXELS(baseline); | |
48d011c8 | 1735 | } |
86d58c90 PC |
1736 | if (height) |
1737 | *height = h; | |
ab9d0a8c | 1738 | |
cfcc3932 | 1739 | // Reset old font description |
6fbe4b24 | 1740 | if (theFont->IsOk()) |
cfcc3932 | 1741 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
903f689b | 1742 | } |
c801d85f | 1743 | |
1f91072f | 1744 | |
888dde65 | 1745 | bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString& text, |
1f91072f VZ |
1746 | wxArrayInt& widths) const |
1747 | { | |
1748 | const size_t len = text.length(); | |
1749 | widths.Empty(); | |
1750 | widths.Add(0, len); | |
1751 | ||
1752 | if (text.empty()) | |
1753 | return true; | |
1754 | ||
1755 | // Set layout's text | |
1756 | const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(text, m_font); | |
1757 | if ( !dataUTF8 ) | |
1758 | { | |
1759 | // hardly ideal, but what else can we do if conversion failed? | |
1760 | wxLogLastError(wxT("DoGetPartialTextExtents")); | |
1761 | return false; | |
1762 | } | |
1763 | ||
86d58c90 | 1764 | pango_layout_set_text(m_layout, dataUTF8, -1); |
f4322df6 | 1765 | |
1f91072f VZ |
1766 | // Calculate the position of each character based on the widths of |
1767 | // the previous characters | |
1768 | ||
1769 | // Code borrowed from Scintilla's PlatGTK | |
1770 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1771 | PangoRectangle pos; | |
1772 | pango_layout_iter_get_cluster_extents(iter, NULL, &pos); | |
1773 | size_t i = 0; | |
1774 | while (pango_layout_iter_next_cluster(iter)) | |
1775 | { | |
1776 | pango_layout_iter_get_cluster_extents(iter, NULL, &pos); | |
1777 | int position = PANGO_PIXELS(pos.x); | |
1f91072f VZ |
1778 | widths[i++] = position; |
1779 | } | |
1780 | while (i < len) | |
1781 | widths[i++] = PANGO_PIXELS(pos.x + pos.width); | |
1782 | pango_layout_iter_free(iter); | |
1783 | ||
1784 | return true; | |
1785 | } | |
1786 | ||
1787 | ||
888dde65 | 1788 | wxCoord wxWindowDCImpl::GetCharWidth() const |
c801d85f | 1789 | { |
cfcc3932 | 1790 | pango_layout_set_text( m_layout, "H", 1 ); |
ace35c62 RR |
1791 | int w; |
1792 | pango_layout_get_pixel_size( m_layout, &w, NULL ); | |
2b5f62a0 | 1793 | return w; |
903f689b | 1794 | } |
c801d85f | 1795 | |
888dde65 | 1796 | wxCoord wxWindowDCImpl::GetCharHeight() const |
c801d85f | 1797 | { |
a8c5e1a9 | 1798 | PangoFontMetrics *metrics = pango_context_get_metrics (m_context, m_fontdesc, pango_context_get_language(m_context)); |
2e61f681 VZ |
1799 | wxCHECK_MSG( metrics, -1, _T("failed to get pango font metrics") ); |
1800 | ||
1801 | wxCoord h = PANGO_PIXELS (pango_font_metrics_get_descent (metrics) + | |
1802 | pango_font_metrics_get_ascent (metrics)); | |
1803 | pango_font_metrics_unref (metrics); | |
1804 | return h; | |
903f689b | 1805 | } |
c801d85f | 1806 | |
888dde65 | 1807 | void wxWindowDCImpl::Clear() |
c801d85f | 1808 | { |
ab171e95 | 1809 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1810 | |
888dde65 | 1811 | if (!m_gdkwindow) return; |
7d5af6fa | 1812 | |
f60e7fdd | 1813 | int width,height; |
ab171e95 | 1814 | DoGetSize( &width, &height ); |
888dde65 | 1815 | gdk_draw_rectangle( m_gdkwindow, m_bgGC, TRUE, 0, 0, width, height ); |
903f689b | 1816 | } |
c801d85f | 1817 | |
888dde65 | 1818 | void wxWindowDCImpl::SetFont( const wxFont &font ) |
c801d85f | 1819 | { |
265898fd | 1820 | m_font = font; |
ab9d0a8c | 1821 | |
ab171e95 | 1822 | if (m_font.IsOk()) |
2b5f62a0 | 1823 | { |
cfcc3932 RR |
1824 | if (m_fontdesc) |
1825 | pango_font_description_free( m_fontdesc ); | |
ab9d0a8c | 1826 | |
cfcc3932 | 1827 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
ab9d0a8c WS |
1828 | |
1829 | ||
888dde65 | 1830 | if (m_window) |
77416abd | 1831 | { |
cfcc3932 | 1832 | PangoContext *oldContext = m_context; |
ab9d0a8c | 1833 | |
888dde65 | 1834 | m_context = m_window->GtkGetPangoDefaultContext(); |
ab9d0a8c | 1835 | |
cfcc3932 RR |
1836 | // If we switch back/forth between different contexts |
1837 | // we also have to create a new layout. I think so, | |
ab9d0a8c | 1838 | // at least, and it doesn't hurt to do it. |
cfcc3932 RR |
1839 | if (oldContext != m_context) |
1840 | { | |
1841 | if (m_layout) | |
3fe39b0c | 1842 | g_object_unref (m_layout); |
ab9d0a8c | 1843 | |
cfcc3932 RR |
1844 | m_layout = pango_layout_new( m_context ); |
1845 | } | |
77416abd | 1846 | } |
ab9d0a8c | 1847 | |
cfcc3932 | 1848 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
2b5f62a0 | 1849 | } |
903f689b | 1850 | } |
c801d85f | 1851 | |
888dde65 | 1852 | void wxWindowDCImpl::SetPen( const wxPen &pen ) |
c801d85f | 1853 | { |
ab171e95 | 1854 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1855 | |
265898fd | 1856 | if (m_pen == pen) return; |
7d5af6fa | 1857 | |
265898fd | 1858 | m_pen = pen; |
7d5af6fa | 1859 | |
ab171e95 | 1860 | if (!m_pen.IsOk()) return; |
7d5af6fa | 1861 | |
888dde65 | 1862 | if (!m_gdkwindow) return; |
7d5af6fa | 1863 | |
265898fd | 1864 | gint width = m_pen.GetWidth(); |
265898fd RR |
1865 | if (width <= 0) |
1866 | { | |
112c5086 | 1867 | // CMB: if width is non-zero scale it with the dc |
265898fd RR |
1868 | width = 1; |
1869 | } | |
1870 | else | |
1871 | { | |
1872 | // X doesn't allow different width in x and y and so we take | |
1873 | // the average | |
503f414e VZ |
1874 | double w = 0.5 + |
1875 | ( fabs((double) XLOG2DEVREL(width)) + | |
1876 | fabs((double) YLOG2DEVREL(width)) ) / 2.0; | |
265898fd | 1877 | width = (int)w; |
375fc5a9 VZ |
1878 | if ( !width ) |
1879 | { | |
1880 | // width can't be 0 or an internal GTK error occurs inside | |
1881 | // gdk_gc_set_dashes() below | |
1882 | width = 1; | |
1883 | } | |
265898fd | 1884 | } |
7d5af6fa | 1885 | |
2eca425d RL |
1886 | static const wxGTKDash dotted[] = {1, 1}; |
1887 | static const wxGTKDash short_dashed[] = {2, 2}; | |
1888 | static const wxGTKDash wxCoord_dashed[] = {2, 4}; | |
1889 | static const wxGTKDash dotted_dashed[] = {3, 3, 1, 3}; | |
7d5af6fa | 1890 | |
112c5086 RR |
1891 | // We express dash pattern in pen width unit, so we are |
1892 | // independent of zoom factor and so on... | |
1893 | int req_nb_dash; | |
2eca425d | 1894 | const wxGTKDash *req_dash; |
7d5af6fa | 1895 | |
86d58c90 | 1896 | GdkLineStyle lineStyle = GDK_LINE_ON_OFF_DASH; |
265898fd RR |
1897 | switch (m_pen.GetStyle()) |
1898 | { | |
04ee05f9 | 1899 | case wxPENSTYLE_USER_DASH: |
112c5086 | 1900 | req_nb_dash = m_pen.GetDashCount(); |
2eca425d | 1901 | req_dash = (wxGTKDash*)m_pen.GetDash(); |
112c5086 | 1902 | break; |
04ee05f9 | 1903 | case wxPENSTYLE_DOT: |
112c5086 RR |
1904 | req_nb_dash = 2; |
1905 | req_dash = dotted; | |
7d5af6fa | 1906 | break; |
04ee05f9 | 1907 | case wxPENSTYLE_LONG_DASH: |
112c5086 | 1908 | req_nb_dash = 2; |
72cdf4c9 | 1909 | req_dash = wxCoord_dashed; |
7d5af6fa | 1910 | break; |
04ee05f9 | 1911 | case wxPENSTYLE_SHORT_DASH: |
112c5086 RR |
1912 | req_nb_dash = 2; |
1913 | req_dash = short_dashed; | |
7d5af6fa | 1914 | break; |
04ee05f9 | 1915 | case wxPENSTYLE_DOT_DASH: |
112c5086 RR |
1916 | req_nb_dash = 4; |
1917 | req_dash = dotted_dashed; | |
7d5af6fa | 1918 | break; |
7d5af6fa | 1919 | |
04ee05f9 PC |
1920 | case wxPENSTYLE_TRANSPARENT: |
1921 | case wxPENSTYLE_STIPPLE_MASK_OPAQUE: | |
1922 | case wxPENSTYLE_STIPPLE: | |
1923 | case wxPENSTYLE_SOLID: | |
7d5af6fa | 1924 | default: |
7d5af6fa | 1925 | lineStyle = GDK_LINE_SOLID; |
2eca425d | 1926 | req_dash = (wxGTKDash*)NULL; |
112c5086 | 1927 | req_nb_dash = 0; |
7d5af6fa | 1928 | break; |
265898fd | 1929 | } |
7d5af6fa | 1930 | |
112c5086 RR |
1931 | if (req_dash && req_nb_dash) |
1932 | { | |
2eca425d | 1933 | wxGTKDash *real_req_dash = new wxGTKDash[req_nb_dash]; |
112c5086 RR |
1934 | if (real_req_dash) |
1935 | { | |
1936 | for (int i = 0; i < req_nb_dash; i++) | |
1937 | real_req_dash[i] = req_dash[i] * width; | |
2eca425d | 1938 | gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash ); |
112c5086 RR |
1939 | delete[] real_req_dash; |
1940 | } | |
1941 | else | |
1942 | { | |
1943 | // No Memory. We use non-scaled dash pattern... | |
2eca425d | 1944 | gdk_gc_set_dashes( m_penGC, 0, (wxGTKDash*)req_dash, req_nb_dash ); |
112c5086 RR |
1945 | } |
1946 | } | |
7d5af6fa | 1947 | |
265898fd RR |
1948 | GdkCapStyle capStyle = GDK_CAP_ROUND; |
1949 | switch (m_pen.GetCap()) | |
1950 | { | |
265898fd RR |
1951 | case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; } |
1952 | case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; } | |
d4aa3a4b RR |
1953 | case wxCAP_ROUND: |
1954 | default: | |
d4aa3a4b RR |
1955 | if (width <= 1) |
1956 | { | |
1957 | width = 0; | |
1958 | capStyle = GDK_CAP_NOT_LAST; | |
1959 | } | |
72174350 | 1960 | break; |
265898fd | 1961 | } |
7d5af6fa | 1962 | |
265898fd RR |
1963 | GdkJoinStyle joinStyle = GDK_JOIN_ROUND; |
1964 | switch (m_pen.GetJoin()) | |
1965 | { | |
1966 | case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; } | |
265898fd | 1967 | case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; } |
d4aa3a4b RR |
1968 | case wxJOIN_ROUND: |
1969 | default: { joinStyle = GDK_JOIN_ROUND; break; } | |
265898fd | 1970 | } |
7d5af6fa | 1971 | |
265898fd | 1972 | gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle ); |
7d5af6fa | 1973 | |
265898fd RR |
1974 | m_pen.GetColour().CalcPixel( m_cmap ); |
1975 | gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() ); | |
903f689b | 1976 | } |
c801d85f | 1977 | |
888dde65 | 1978 | void wxWindowDCImpl::SetBrush( const wxBrush &brush ) |
c801d85f | 1979 | { |
ab171e95 | 1980 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1981 | |
265898fd | 1982 | if (m_brush == brush) return; |
7d5af6fa | 1983 | |
265898fd | 1984 | m_brush = brush; |
7d5af6fa | 1985 | |
ab171e95 | 1986 | if (!m_brush.IsOk()) return; |
7d5af6fa | 1987 | |
888dde65 | 1988 | if (!m_gdkwindow) return; |
7d5af6fa | 1989 | |
265898fd RR |
1990 | m_brush.GetColour().CalcPixel( m_cmap ); |
1991 | gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() ); | |
7d5af6fa | 1992 | |
956dbab1 | 1993 | gdk_gc_set_fill( m_brushGC, GDK_SOLID ); |
7d5af6fa | 1994 | |
04ee05f9 | 1995 | if ((m_brush.GetStyle() == wxBRUSHSTYLE_STIPPLE) && (m_brush.GetStipple()->IsOk())) |
265898fd | 1996 | { |
b85229d1 | 1997 | if (m_brush.GetStipple()->GetDepth() != 1) |
7d5af6fa | 1998 | { |
956dbab1 | 1999 | gdk_gc_set_fill( m_brushGC, GDK_TILED ); |
cd25b18c | 2000 | gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() ); |
7d5af6fa | 2001 | } |
b0e0d661 | 2002 | else |
7d5af6fa | 2003 | { |
956dbab1 | 2004 | gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); |
b85229d1 | 2005 | gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() ); |
7d5af6fa | 2006 | } |
265898fd | 2007 | } |
7d5af6fa | 2008 | |
04ee05f9 | 2009 | if ((m_brush.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) |
de2d2cdc | 2010 | { |
e1208c31 RR |
2011 | gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); |
2012 | gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); | |
de2d2cdc VZ |
2013 | } |
2014 | ||
ab9d0a8c | 2015 | if (m_brush.IsHatch()) |
265898fd | 2016 | { |
956dbab1 | 2017 | gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); |
f7732fa5 | 2018 | gdk_gc_set_stipple(m_brushGC, GetHatch(m_brush.GetStyle())); |
265898fd | 2019 | } |
903f689b | 2020 | } |
c801d85f | 2021 | |
888dde65 | 2022 | void wxWindowDCImpl::SetBackground( const wxBrush &brush ) |
46dc76ba | 2023 | { |
bbbbe360 RR |
2024 | /* CMB 21/7/98: Added SetBackground. Sets background brush |
2025 | * for Clear() and bg colour for shapes filled with cross-hatch brush */ | |
7d5af6fa | 2026 | |
ab171e95 | 2027 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2028 | |
265898fd | 2029 | if (m_backgroundBrush == brush) return; |
7d5af6fa | 2030 | |
265898fd | 2031 | m_backgroundBrush = brush; |
7d5af6fa | 2032 | |
ab171e95 | 2033 | if (!m_backgroundBrush.IsOk()) return; |
7d5af6fa | 2034 | |
888dde65 | 2035 | if (!m_gdkwindow) return; |
7d5af6fa | 2036 | |
86d58c90 PC |
2037 | wxColor color = m_backgroundBrush.GetColour(); |
2038 | color.CalcPixel(m_cmap); | |
2039 | const GdkColor* gdkColor = color.GetColor(); | |
2040 | gdk_gc_set_background(m_brushGC, gdkColor); | |
2041 | gdk_gc_set_background(m_penGC, gdkColor); | |
2042 | gdk_gc_set_background(m_bgGC, gdkColor); | |
2043 | gdk_gc_set_foreground(m_bgGC, gdkColor); | |
2044 | ||
3417c2cd RR |
2045 | |
2046 | gdk_gc_set_fill( m_bgGC, GDK_SOLID ); | |
7d5af6fa | 2047 | |
04ee05f9 | 2048 | if (m_backgroundBrush.GetStyle() == wxBRUSHSTYLE_STIPPLE) |
265898fd | 2049 | { |
86d58c90 PC |
2050 | const wxBitmap* stipple = m_backgroundBrush.GetStipple(); |
2051 | if (stipple->IsOk()) | |
7d5af6fa | 2052 | { |
86d58c90 PC |
2053 | if (stipple->GetDepth() != 1) |
2054 | { | |
2055 | gdk_gc_set_fill(m_bgGC, GDK_TILED); | |
2056 | gdk_gc_set_tile(m_bgGC, stipple->GetPixmap()); | |
2057 | } | |
2058 | else | |
2059 | { | |
2060 | gdk_gc_set_fill(m_bgGC, GDK_STIPPLED); | |
2061 | gdk_gc_set_stipple(m_bgGC, stipple->GetPixmap()); | |
2062 | } | |
7d5af6fa | 2063 | } |
265898fd | 2064 | } |
86d58c90 | 2065 | else if (m_backgroundBrush.IsHatch()) |
265898fd | 2066 | { |
3417c2cd | 2067 | gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); |
f7732fa5 | 2068 | gdk_gc_set_stipple(m_bgGC, GetHatch(m_backgroundBrush.GetStyle())); |
bbbbe360 | 2069 | } |
903f689b | 2070 | } |
46dc76ba | 2071 | |
888dde65 | 2072 | void wxWindowDCImpl::SetLogicalFunction( int function ) |
c801d85f | 2073 | { |
ab171e95 | 2074 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2075 | |
72174350 VZ |
2076 | if (m_logicalFunction == function) |
2077 | return; | |
2078 | ||
2079 | // VZ: shouldn't this be a CHECK? | |
888dde65 | 2080 | if (!m_gdkwindow) |
72174350 | 2081 | return; |
01eaf507 | 2082 | |
2b5f62a0 | 2083 | GdkFunction mode; |
265898fd RR |
2084 | switch (function) |
2085 | { | |
3c679789 RR |
2086 | case wxXOR: mode = GDK_XOR; break; |
2087 | case wxINVERT: mode = GDK_INVERT; break; | |
3c679789 RR |
2088 | case wxOR_REVERSE: mode = GDK_OR_REVERSE; break; |
2089 | case wxAND_REVERSE: mode = GDK_AND_REVERSE; break; | |
2090 | case wxCLEAR: mode = GDK_CLEAR; break; | |
2091 | case wxSET: mode = GDK_SET; break; | |
2092 | case wxOR_INVERT: mode = GDK_OR_INVERT; break; | |
2093 | case wxAND: mode = GDK_AND; break; | |
2094 | case wxOR: mode = GDK_OR; break; | |
2095 | case wxEQUIV: mode = GDK_EQUIV; break; | |
2096 | case wxNAND: mode = GDK_NAND; break; | |
2097 | case wxAND_INVERT: mode = GDK_AND_INVERT; break; | |
7d5af6fa VZ |
2098 | case wxCOPY: mode = GDK_COPY; break; |
2099 | case wxNO_OP: mode = GDK_NOOP; break; | |
2100 | case wxSRC_INVERT: mode = GDK_COPY_INVERT; break; | |
8e69bf8e | 2101 | case wxNOR: mode = GDK_NOR; break; |
01eaf507 | 2102 | default: |
223d09f6 | 2103 | wxFAIL_MSG( wxT("unsupported logical function") ); |
2b5f62a0 | 2104 | mode = GDK_COPY; |
265898fd | 2105 | } |
7d5af6fa | 2106 | |
265898fd | 2107 | m_logicalFunction = function; |
7d5af6fa | 2108 | |
265898fd RR |
2109 | gdk_gc_set_function( m_penGC, mode ); |
2110 | gdk_gc_set_function( m_brushGC, mode ); | |
72174350 VZ |
2111 | |
2112 | // to stay compatible with wxMSW, we don't apply ROPs to the text | |
3d2d8da1 RR |
2113 | // operations (i.e. DrawText/DrawRotatedText). |
2114 | // True, but mono-bitmaps use the m_textGC and they use ROPs as well. | |
2115 | gdk_gc_set_function( m_textGC, mode ); | |
903f689b | 2116 | } |
c801d85f | 2117 | |
888dde65 | 2118 | void wxWindowDCImpl::SetTextForeground( const wxColour &col ) |
c801d85f | 2119 | { |
ab171e95 | 2120 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2121 | |
71ec83d2 VZ |
2122 | // don't set m_textForegroundColour to an invalid colour as we'd crash |
2123 | // later then (we use m_textForegroundColour.GetColor() without checking | |
2124 | // in a few places) | |
ab171e95 | 2125 | if ( !col.IsOk() || (m_textForegroundColour == col) ) |
71ec83d2 | 2126 | return; |
7d5af6fa | 2127 | |
265898fd | 2128 | m_textForegroundColour = col; |
7d5af6fa | 2129 | |
888dde65 | 2130 | if ( m_gdkwindow ) |
71ec83d2 VZ |
2131 | { |
2132 | m_textForegroundColour.CalcPixel( m_cmap ); | |
2133 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
2134 | } | |
903f689b | 2135 | } |
c801d85f | 2136 | |
888dde65 | 2137 | void wxWindowDCImpl::SetTextBackground( const wxColour &col ) |
c801d85f | 2138 | { |
ab171e95 | 2139 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2140 | |
71ec83d2 | 2141 | // same as above |
ab171e95 | 2142 | if ( !col.IsOk() || (m_textBackgroundColour == col) ) |
71ec83d2 | 2143 | return; |
7d5af6fa | 2144 | |
265898fd | 2145 | m_textBackgroundColour = col; |
7d5af6fa | 2146 | |
888dde65 | 2147 | if ( m_gdkwindow ) |
71ec83d2 VZ |
2148 | { |
2149 | m_textBackgroundColour.CalcPixel( m_cmap ); | |
2150 | gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); | |
2151 | } | |
903f689b | 2152 | } |
c801d85f | 2153 | |
888dde65 | 2154 | void wxWindowDCImpl::SetBackgroundMode( int mode ) |
c801d85f | 2155 | { |
ab171e95 | 2156 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2157 | |
265898fd | 2158 | m_backgroundMode = mode; |
903f689b | 2159 | } |
c801d85f | 2160 | |
888dde65 | 2161 | void wxWindowDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) ) |
c801d85f | 2162 | { |
888dde65 | 2163 | wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") ); |
903f689b | 2164 | } |
c801d85f | 2165 | |
888dde65 | 2166 | void wxWindowDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 2167 | { |
ab171e95 | 2168 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2169 | |
888dde65 | 2170 | if (!m_gdkwindow) return; |
7d5af6fa | 2171 | |
3d2d8da1 | 2172 | wxRect rect; |
265898fd RR |
2173 | rect.x = XLOG2DEV(x); |
2174 | rect.y = YLOG2DEV(y); | |
2175 | rect.width = XLOG2DEVREL(width); | |
2176 | rect.height = YLOG2DEVREL(height); | |
5f170f33 | 2177 | |
888dde65 RR |
2178 | if (m_window && m_window->m_wxwindow && |
2179 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) | |
49e74855 RR |
2180 | { |
2181 | rect.x -= rect.width; | |
2182 | } | |
2183 | ||
98d8a7ec | 2184 | DoSetDeviceClippingRegion(wxRegion(rect)); |
903f689b | 2185 | } |
c801d85f | 2186 | |
fdaad94e | 2187 | void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion ®ion ) |
463c1fa1 | 2188 | { |
ab171e95 | 2189 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2190 | |
463c1fa1 RR |
2191 | if (region.Empty()) |
2192 | { | |
2193 | DestroyClippingRegion(); | |
2194 | return; | |
2195 | } | |
7d5af6fa | 2196 | |
888dde65 | 2197 | if (!m_gdkwindow) return; |
5f170f33 | 2198 | |
e1208c31 | 2199 | if (!m_currentClippingRegion.IsNull()) |
993f97ee RR |
2200 | m_currentClippingRegion.Intersect( region ); |
2201 | else | |
2202 | m_currentClippingRegion.Union( region ); | |
5f170f33 VZ |
2203 | |
2204 | #if USE_PAINT_REGION | |
e1208c31 | 2205 | if (!m_paintClippingRegion.IsNull()) |
3d2d8da1 | 2206 | m_currentClippingRegion.Intersect( m_paintClippingRegion ); |
809934d2 | 2207 | #endif |
3d2d8da1 | 2208 | |
ee8dbe63 RL |
2209 | wxCoord xx, yy, ww, hh; |
2210 | m_currentClippingRegion.GetBox( xx, yy, ww, hh ); | |
888dde65 | 2211 | wxGTKDCImpl::DoSetClippingRegion( xx, yy, ww, hh ); |
ee8dbe63 | 2212 | |
86d58c90 PC |
2213 | GdkRegion* gdkRegion = m_currentClippingRegion.GetRegion(); |
2214 | gdk_gc_set_clip_region(m_penGC, gdkRegion); | |
2215 | gdk_gc_set_clip_region(m_brushGC, gdkRegion); | |
2216 | gdk_gc_set_clip_region(m_textGC, gdkRegion); | |
2217 | gdk_gc_set_clip_region(m_bgGC, gdkRegion); | |
463c1fa1 RR |
2218 | } |
2219 | ||
888dde65 | 2220 | void wxWindowDCImpl::DestroyClippingRegion() |
c801d85f | 2221 | { |
ab171e95 | 2222 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2223 | |
888dde65 | 2224 | wxDCImpl::DestroyClippingRegion(); |
7d5af6fa | 2225 | |
3d2d8da1 | 2226 | m_currentClippingRegion.Clear(); |
5f170f33 VZ |
2227 | |
2228 | #if USE_PAINT_REGION | |
3d2d8da1 RR |
2229 | if (!m_paintClippingRegion.IsEmpty()) |
2230 | m_currentClippingRegion.Union( m_paintClippingRegion ); | |
993f97ee | 2231 | #endif |
3d2d8da1 | 2232 | |
888dde65 | 2233 | if (!m_gdkwindow) return; |
7d5af6fa | 2234 | |
86d58c90 PC |
2235 | GdkRegion* gdkRegion = NULL; |
2236 | if (!m_currentClippingRegion.IsEmpty()) | |
2237 | gdkRegion = m_currentClippingRegion.GetRegion(); | |
2238 | ||
2239 | gdk_gc_set_clip_region(m_penGC, gdkRegion); | |
2240 | gdk_gc_set_clip_region(m_brushGC, gdkRegion); | |
2241 | gdk_gc_set_clip_region(m_textGC, gdkRegion); | |
2242 | gdk_gc_set_clip_region(m_bgGC, gdkRegion); | |
903f689b | 2243 | } |
c801d85f | 2244 | |
888dde65 | 2245 | void wxWindowDCImpl::Destroy() |
dbf858b5 | 2246 | { |
3d2d8da1 | 2247 | if (m_penGC) wxFreePoolGC( m_penGC ); |
265898fd | 2248 | m_penGC = (GdkGC*) NULL; |
3d2d8da1 | 2249 | if (m_brushGC) wxFreePoolGC( m_brushGC ); |
265898fd | 2250 | m_brushGC = (GdkGC*) NULL; |
3d2d8da1 | 2251 | if (m_textGC) wxFreePoolGC( m_textGC ); |
265898fd | 2252 | m_textGC = (GdkGC*) NULL; |
3d2d8da1 | 2253 | if (m_bgGC) wxFreePoolGC( m_bgGC ); |
265898fd | 2254 | m_bgGC = (GdkGC*) NULL; |
dbf858b5 RR |
2255 | } |
2256 | ||
888dde65 | 2257 | void wxWindowDCImpl::SetDeviceOrigin( wxCoord x, wxCoord y ) |
847dfdb4 RR |
2258 | { |
2259 | m_deviceOriginX = x; | |
2260 | m_deviceOriginY = y; | |
f4322df6 | 2261 | |
847dfdb4 RR |
2262 | ComputeScaleAndOrigin(); |
2263 | } | |
2264 | ||
888dde65 | 2265 | void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
847dfdb4 RR |
2266 | { |
2267 | m_signX = (xLeftRight ? 1 : -1); | |
2268 | m_signY = (yBottomUp ? -1 : 1); | |
f4322df6 | 2269 | |
888dde65 RR |
2270 | if (m_window && m_window->m_wxwindow && |
2271 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) | |
f4322df6 VZ |
2272 | m_signX = -m_signX; |
2273 | ||
847dfdb4 RR |
2274 | ComputeScaleAndOrigin(); |
2275 | } | |
2276 | ||
888dde65 | 2277 | void wxWindowDCImpl::ComputeScaleAndOrigin() |
238d735d | 2278 | { |
c77a6796 | 2279 | const wxRealPoint origScale(m_scaleX, m_scaleY); |
238d735d | 2280 | |
888dde65 | 2281 | wxDCImpl::ComputeScaleAndOrigin(); |
238d735d | 2282 | |
c77a6796 | 2283 | // if scale has changed call SetPen to recalulate the line width |
ab171e95 | 2284 | if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.IsOk() ) |
238d735d | 2285 | { |
c77a6796 VZ |
2286 | // this is a bit artificial, but we need to force wxDC to think the pen |
2287 | // has changed | |
0a164d4c WS |
2288 | wxPen pen = m_pen; |
2289 | m_pen = wxNullPen; | |
2290 | SetPen( pen ); | |
2291 | } | |
238d735d RR |
2292 | } |
2293 | ||
b0e0d661 | 2294 | // Resolution in pixels per logical inch |
888dde65 | 2295 | wxSize wxWindowDCImpl::GetPPI() const |
b0e0d661 | 2296 | { |
7a5e6267 | 2297 | return wxSize( (int) (m_mm_to_pix_x * 25.4 + 0.5), (int) (m_mm_to_pix_y * 25.4 + 0.5)); |
b0e0d661 VZ |
2298 | } |
2299 | ||
888dde65 | 2300 | int wxWindowDCImpl::GetDepth() const |
c801d85f | 2301 | { |
888dde65 | 2302 | return gdk_drawable_get_depth(m_gdkwindow); |
903f689b | 2303 | } |
c801d85f | 2304 | |
ec758a20 | 2305 | |
ab171e95 | 2306 | //----------------------------------------------------------------------------- |
888dde65 | 2307 | // wxClientDCImpl |
ab171e95 RR |
2308 | //----------------------------------------------------------------------------- |
2309 | ||
888dde65 | 2310 | IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl) |
ab171e95 | 2311 | |
888dde65 RR |
2312 | wxClientDCImpl::wxClientDCImpl( wxDC *owner ) |
2313 | : wxWindowDCImpl( owner ) | |
ab171e95 RR |
2314 | { |
2315 | } | |
2316 | ||
888dde65 RR |
2317 | wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *win ) |
2318 | : wxWindowDCImpl( owner, win ) | |
ab171e95 | 2319 | { |
888dde65 | 2320 | wxCHECK_RET( win, _T("NULL window in wxClientDCImpl::wxClientDC") ); |
ab171e95 RR |
2321 | |
2322 | #ifdef __WXUNIVERSAL__ | |
2323 | wxPoint ptOrigin = win->GetClientAreaOrigin(); | |
2324 | SetDeviceOrigin(ptOrigin.x, ptOrigin.y); | |
2325 | wxSize size = win->GetClientSize(); | |
6267c3ea | 2326 | DoSetClippingRegion(0, 0, size.x, size.y); |
888dde65 RR |
2327 | #endif |
2328 | // __WXUNIVERSAL__ | |
ab171e95 RR |
2329 | } |
2330 | ||
888dde65 | 2331 | void wxClientDCImpl::DoGetSize(int *width, int *height) const |
ab171e95 | 2332 | { |
888dde65 | 2333 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); |
ab171e95 | 2334 | |
888dde65 | 2335 | m_window->GetClientSize( width, height ); |
ab171e95 RR |
2336 | } |
2337 | ||
ec758a20 | 2338 | //----------------------------------------------------------------------------- |
888dde65 | 2339 | // wxPaintDCImpl |
ec758a20 RR |
2340 | //----------------------------------------------------------------------------- |
2341 | ||
888dde65 | 2342 | IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxClientDCImpl) |
ec758a20 | 2343 | |
2cfddfe7 JS |
2344 | // Limit the paint region to the window size. Sometimes |
2345 | // the paint region is too big, and this risks X11 errors | |
2346 | static void wxLimitRegionToSize(wxRegion& region, const wxSize& sz) | |
2347 | { | |
2348 | wxRect originalRect = region.GetBox(); | |
2349 | wxRect rect(originalRect); | |
2350 | if (rect.width + rect.x > sz.x) | |
2351 | rect.width = sz.x - rect.x; | |
2352 | if (rect.height + rect.y > sz.y) | |
2353 | rect.height = sz.y - rect.y; | |
2354 | if (rect != originalRect) | |
2355 | { | |
2356 | region = wxRegion(rect); | |
2357 | wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"), | |
2358 | originalRect.x, originalRect.y, originalRect.width, originalRect.height, | |
2359 | rect.x, rect.y, rect.width, rect.height); | |
2360 | } | |
2361 | } | |
2362 | ||
888dde65 RR |
2363 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner ) |
2364 | : wxClientDCImpl( owner ) | |
ab171e95 RR |
2365 | { |
2366 | } | |
2367 | ||
888dde65 RR |
2368 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *win ) |
2369 | : wxClientDCImpl( owner, win ) | |
ec758a20 | 2370 | { |
b6fa52db RR |
2371 | #if USE_PAINT_REGION |
2372 | if (!win->m_clipPaintRegion) | |
2373 | return; | |
f469b27c | 2374 | |
2cfddfe7 | 2375 | wxSize sz = win->GetSize(); |
bcb614b3 | 2376 | m_paintClippingRegion = win->m_nativeUpdateRegion; |
2cfddfe7 | 2377 | wxLimitRegionToSize(m_paintClippingRegion, sz); |
ab9d0a8c | 2378 | |
5f170f33 VZ |
2379 | GdkRegion *region = m_paintClippingRegion.GetRegion(); |
2380 | if ( region ) | |
2381 | { | |
823faac3 | 2382 | m_currentClippingRegion.Union( m_paintClippingRegion ); |
2cfddfe7 JS |
2383 | wxLimitRegionToSize(m_currentClippingRegion, sz); |
2384 | ||
2385 | if (sz.x <= 0 || sz.y <= 0) | |
2386 | return ; | |
5f170f33 | 2387 | |
823faac3 JS |
2388 | gdk_gc_set_clip_region( m_penGC, region ); |
2389 | gdk_gc_set_clip_region( m_brushGC, region ); | |
2390 | gdk_gc_set_clip_region( m_textGC, region ); | |
2391 | gdk_gc_set_clip_region( m_bgGC, region ); | |
5f170f33 | 2392 | } |
888dde65 | 2393 | #endif |
ec758a20 RR |
2394 | } |
2395 | ||
3d2d8da1 RR |
2396 | // ---------------------------------------------------------------------------- |
2397 | // wxDCModule | |
2398 | // ---------------------------------------------------------------------------- | |
2399 | ||
2400 | class wxDCModule : public wxModule | |
2401 | { | |
2402 | public: | |
2403 | bool OnInit(); | |
2404 | void OnExit(); | |
2405 | ||
2406 | private: | |
2407 | DECLARE_DYNAMIC_CLASS(wxDCModule) | |
2408 | }; | |
2409 | ||
2410 | IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule) | |
2411 | ||
2412 | bool wxDCModule::OnInit() | |
2413 | { | |
2414 | wxInitGCPool(); | |
ab9d0a8c | 2415 | return true; |
3d2d8da1 RR |
2416 | } |
2417 | ||
2418 | void wxDCModule::OnExit() | |
2419 | { | |
2420 | wxCleanUpGCPool(); | |
f7732fa5 | 2421 | |
04ee05f9 | 2422 | for (int i = wxBRUSHSTYLE_LAST_HATCH - wxBRUSHSTYLE_FIRST_HATCH; i--; ) |
f7732fa5 PC |
2423 | { |
2424 | if (hatches[i]) | |
2425 | g_object_unref(hatches[i]); | |
2426 | } | |
3d2d8da1 | 2427 | } |