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