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