]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/gtk/dcclient.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
6f65e337 | 5 | // RCS-ID: $Id$ |
6c9a19aa | 6 | // Copyright: (c) 1998 Robert Roebling, Chris Breeze |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
d02af7bb JJ |
13 | #ifdef __VMS |
14 | #define XCopyPlane XCOPYPLANE | |
15 | #endif | |
16 | ||
888dde65 | 17 | #include "wx/dc.h" |
c801d85f | 18 | #include "wx/dcclient.h" |
e4db172a WS |
19 | |
20 | #ifndef WX_PRECOMP | |
772b3767 | 21 | #include "wx/window.h" |
e4db172a | 22 | #include "wx/log.h" |
f38924e8 | 23 | #include "wx/dcmemory.h" |
18680f86 | 24 | #include "wx/math.h" // for floating-point functions |
155ecd4c | 25 | #include "wx/image.h" |
02761f6c | 26 | #include "wx/module.h" |
e4db172a WS |
27 | #endif |
28 | ||
db16cab4 | 29 | #include "wx/fontutil.h" |
5713b349 | 30 | #include "wx/scrolwin.h" |
e5131165 | 31 | |
a3669332 | 32 | #include "wx/gtk/private.h" |
c801d85f | 33 | |
993f97ee | 34 | #include <gdk/gdkx.h> |
83624f79 | 35 | |
809934d2 RR |
36 | //----------------------------------------------------------------------------- |
37 | // local defines | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
eb7637b5 RR |
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 | ||
e1208c31 | 45 | #define USE_PAINT_REGION 1 |
809934d2 | 46 | |
c801d85f KB |
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 | ||
3ca6a5f0 BP |
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 | ||
c801d85f | 63 | static GdkPixmap *hatches[num_hatches]; |
c67daf87 | 64 | static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; |
c801d85f | 65 | |
c2fa61e8 | 66 | extern GtkWidget *wxGetRootWindow(); |
3d2d8da1 | 67 | |
c801d85f KB |
68 | //----------------------------------------------------------------------------- |
69 | // constants | |
70 | //----------------------------------------------------------------------------- | |
71 | ||
95724b1a | 72 | const double RAD2DEG = 180.0 / M_PI; |
c801d85f | 73 | |
9a8c7620 VZ |
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 | ||
6f65e337 JS |
83 | //----------------------------------------------------------------------------- |
84 | // temporary implementation of the missing GDK function | |
85 | //----------------------------------------------------------------------------- | |
b0e0d661 | 86 | |
6f65e337 | 87 | #include "gdk/gdkprivate.h" |
b0e0d661 | 88 | |
9be3f755 | 89 | static |
1e6feb95 VZ |
90 | void gdk_wx_draw_bitmap(GdkDrawable *drawable, |
91 | GdkGC *gc, | |
92 | GdkDrawable *src, | |
93 | gint xsrc, | |
e4161a2a | 94 | gint ysrc) |
6f65e337 | 95 | { |
17a1ebd1 VZ |
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") ); | |
ab9d0a8c | 99 | |
d90c9596 | 100 | gint src_width, src_height; |
8943b403 | 101 | gdk_drawable_get_size(src, &src_width, &src_height); |
265898fd | 102 | |
8943b403 OK |
103 | XCopyPlane( GDK_WINDOW_XDISPLAY(drawable), |
104 | GDK_WINDOW_XID(src), | |
105 | GDK_WINDOW_XID(drawable), | |
106 | GDK_GC_XGC(gc), | |
107 | xsrc, ysrc, | |
e4161a2a | 108 | src_width, src_height, |
d90c9596 | 109 | 0, 0, |
8943b403 | 110 | 1 ); |
6f65e337 JS |
111 | } |
112 | ||
3d2d8da1 RR |
113 | //----------------------------------------------------------------------------- |
114 | // Implement Pool of Graphic contexts. Creating them takes too much time. | |
115 | //----------------------------------------------------------------------------- | |
116 | ||
0e09f76e RR |
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, | |
f6bcfd97 BP |
127 | wxBRUSH_COLOUR, |
128 | wxTEXT_SCREEN, | |
129 | wxBG_SCREEN, | |
130 | wxPEN_SCREEN, | |
131 | wxBRUSH_SCREEN | |
0e09f76e RR |
132 | }; |
133 | ||
3d2d8da1 RR |
134 | struct wxGC |
135 | { | |
0e09f76e RR |
136 | GdkGC *m_gc; |
137 | wxPoolGCType m_type; | |
138 | bool m_used; | |
3d2d8da1 RR |
139 | }; |
140 | ||
696f36b7 JS |
141 | #define GC_POOL_ALLOC_SIZE 100 |
142 | ||
143 | static int wxGCPoolSize = 0; | |
144 | ||
145 | static wxGC *wxGCPool = NULL; | |
3d2d8da1 RR |
146 | |
147 | static void wxInitGCPool() | |
148 | { | |
696f36b7 JS |
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. | |
ab9d0a8c | 152 | |
696f36b7 JS |
153 | // Set initial pool size. |
154 | wxGCPoolSize = GC_POOL_ALLOC_SIZE; | |
ab9d0a8c | 155 | |
696f36b7 JS |
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 | |
551b5391 | 163 | // in wxGetPoolGC. |
696f36b7 JS |
164 | wxFAIL_MSG( wxT("Cannot allocate GC pool") ); |
165 | return; | |
166 | } | |
ab9d0a8c | 167 | |
696f36b7 JS |
168 | // Zero initial pool. |
169 | memset(wxGCPool, 0, wxGCPoolSize * sizeof(wxGC)); | |
3d2d8da1 RR |
170 | } |
171 | ||
172 | static void wxCleanUpGCPool() | |
173 | { | |
f6116855 | 174 | for (int i = 0; i < wxGCPoolSize; i++) |
3d2d8da1 RR |
175 | { |
176 | if (wxGCPool[i].m_gc) | |
3fe39b0c | 177 | g_object_unref (wxGCPool[i].m_gc); |
3d2d8da1 | 178 | } |
696f36b7 JS |
179 | |
180 | free(wxGCPool); | |
181 | wxGCPool = NULL; | |
182 | wxGCPoolSize = 0; | |
3d2d8da1 RR |
183 | } |
184 | ||
0e09f76e | 185 | static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) |
3d2d8da1 | 186 | { |
696f36b7 | 187 | wxGC *pptr; |
ab9d0a8c | 188 | |
696f36b7 JS |
189 | // Look for an available GC. |
190 | for (int i = 0; i < wxGCPoolSize; i++) | |
3d2d8da1 RR |
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 ); | |
0e09f76e | 196 | wxGCPool[i].m_type = type; |
ab9d0a8c | 197 | wxGCPool[i].m_used = false; |
3d2d8da1 | 198 | } |
0e09f76e | 199 | if ((!wxGCPool[i].m_used) && (wxGCPool[i].m_type == type)) |
3d2d8da1 | 200 | { |
ab9d0a8c | 201 | wxGCPool[i].m_used = true; |
3d2d8da1 RR |
202 | return wxGCPool[i].m_gc; |
203 | } | |
204 | } | |
5f170f33 | 205 | |
696f36b7 JS |
206 | // We did not find an available GC. |
207 | // We need to grow the GC pool. | |
208 | pptr = (wxGC *)realloc(wxGCPool, | |
551b5391 | 209 | (wxGCPoolSize + GC_POOL_ALLOC_SIZE)*sizeof(wxGC)); |
696f36b7 JS |
210 | if (pptr != NULL) |
211 | { | |
212 | // Initialize newly allocated pool. | |
213 | wxGCPool = pptr; | |
551b5391 RR |
214 | memset(&wxGCPool[wxGCPoolSize], 0, |
215 | GC_POOL_ALLOC_SIZE*sizeof(wxGC)); | |
ab9d0a8c WS |
216 | |
217 | // Initialize entry we will return. | |
696f36b7 JS |
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; | |
ab9d0a8c WS |
221 | wxGCPool[wxGCPoolSize].m_used = true; |
222 | ||
696f36b7 JS |
223 | // Set new value of pool size. |
224 | wxGCPoolSize += GC_POOL_ALLOC_SIZE; | |
ab9d0a8c | 225 | |
696f36b7 JS |
226 | // Return newly allocated entry. |
227 | return wxGCPool[wxGCPoolSize-GC_POOL_ALLOC_SIZE].m_gc; | |
228 | } | |
ab9d0a8c | 229 | |
696f36b7 | 230 | // The realloc failed. Fall through to error. |
3d2d8da1 | 231 | wxFAIL_MSG( wxT("No GC available") ); |
5f170f33 | 232 | |
3d2d8da1 RR |
233 | return (GdkGC*) NULL; |
234 | } | |
235 | ||
236 | static void wxFreePoolGC( GdkGC *gc ) | |
237 | { | |
696f36b7 | 238 | for (int i = 0; i < wxGCPoolSize; i++) |
3d2d8da1 RR |
239 | { |
240 | if (wxGCPool[i].m_gc == gc) | |
241 | { | |
ab9d0a8c | 242 | wxGCPool[i].m_used = false; |
3d2d8da1 RR |
243 | return; |
244 | } | |
245 | } | |
5f170f33 | 246 | |
3d2d8da1 RR |
247 | wxFAIL_MSG( wxT("Wrong GC") ); |
248 | } | |
249 | ||
c801d85f | 250 | //----------------------------------------------------------------------------- |
ec758a20 | 251 | // wxWindowDC |
c801d85f KB |
252 | //----------------------------------------------------------------------------- |
253 | ||
888dde65 | 254 | IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxGTKDCImpl) |
c801d85f | 255 | |
888dde65 RR |
256 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner ) : |
257 | wxGTKDCImpl( owner ) | |
c801d85f | 258 | { |
888dde65 | 259 | m_gdkwindow = (GdkWindow*) NULL; |
265898fd RR |
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; | |
ab9d0a8c | 265 | m_isScreenDC = false; |
8943b403 | 266 | m_context = (PangoContext *)NULL; |
cfcc3932 | 267 | m_layout = (PangoLayout *)NULL; |
8943b403 | 268 | m_fontdesc = (PangoFontDescription *)NULL; |
903f689b | 269 | } |
c801d85f | 270 | |
888dde65 RR |
271 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window ) : |
272 | wxGTKDCImpl( owner ) | |
c801d85f | 273 | { |
3cd0b8c5 RR |
274 | wxASSERT_MSG( window, wxT("DC needs a window") ); |
275 | ||
888dde65 | 276 | m_gdkwindow = (GdkWindow*) NULL; |
265898fd RR |
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; | |
ab9d0a8c | 282 | m_isScreenDC = false; |
3b245d60 | 283 | m_font = window->GetFont(); |
7d5af6fa | 284 | |
a2053b27 | 285 | GtkWidget *widget = window->m_wxwindow; |
7d5af6fa | 286 | |
cfcc3932 | 287 | // Some controls don't have m_wxwindow - like wxStaticBox, but the user |
b7f1f77f | 288 | // code should still be able to create wxClientDCs for them, so we will |
cfcc3932 | 289 | // use the parent window here then. |
b7f1f77f VZ |
290 | if ( !widget ) |
291 | { | |
292 | window = window->GetParent(); | |
293 | widget = window->m_wxwindow; | |
294 | } | |
295 | ||
223d09f6 | 296 | wxASSERT_MSG( widget, wxT("DC needs a widget") ); |
7d5af6fa | 297 | |
2b5f62a0 | 298 | m_context = window->GtkGetPangoDefaultContext(); |
cfcc3932 RR |
299 | m_layout = pango_layout_new( m_context ); |
300 | m_fontdesc = pango_font_description_copy( widget->style->font_desc ); | |
8943b403 | 301 | |
888dde65 | 302 | m_gdkwindow = widget->window; |
7d5af6fa | 303 | |
cfcc3932 | 304 | // Window not realized ? |
888dde65 | 305 | if (!m_gdkwindow) |
1e133b7d | 306 | { |
cfcc3932 | 307 | // Don't report problems as per MSW. |
ab9d0a8c | 308 | m_ok = true; |
7d5af6fa VZ |
309 | |
310 | return; | |
1e133b7d | 311 | } |
7d5af6fa | 312 | |
b7f1f77f | 313 | m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); |
7d5af6fa | 314 | |
265898fd | 315 | SetUpDC(); |
bbbbe360 RR |
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) */ | |
7d5af6fa | 323 | |
888dde65 | 324 | m_window = window; |
f4322df6 | 325 | |
888dde65 RR |
326 | if (m_window && m_window->m_wxwindow && |
327 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) | |
847dfdb4 | 328 | { |
5713b349 | 329 | // reverse sense |
847dfdb4 | 330 | m_signX = -1; |
807a572e | 331 | |
5713b349 | 332 | // origin in the upper right corner |
888dde65 | 333 | m_deviceOriginX = m_window->GetClientSize().x; |
847dfdb4 | 334 | } |
903f689b | 335 | } |
c801d85f | 336 | |
888dde65 | 337 | wxWindowDCImpl::~wxWindowDCImpl() |
c801d85f | 338 | { |
265898fd | 339 | Destroy(); |
ab9d0a8c | 340 | |
cfcc3932 | 341 | if (m_layout) |
3fe39b0c | 342 | g_object_unref (m_layout); |
cfcc3932 RR |
343 | if (m_fontdesc) |
344 | pango_font_description_free( m_fontdesc ); | |
903f689b | 345 | } |
c801d85f | 346 | |
888dde65 | 347 | void wxWindowDCImpl::SetUpDC( bool isMemDC ) |
809934d2 | 348 | { |
ab9d0a8c | 349 | m_ok = true; |
5f170f33 | 350 | |
809934d2 | 351 | wxASSERT_MSG( !m_penGC, wxT("GCs already created") ); |
5f170f33 | 352 | |
ab171e95 RR |
353 | bool done = false; |
354 | ||
888dde65 | 355 | if ((isMemDC) && (GetSelectedBitmap().IsOk())) |
809934d2 | 356 | { |
888dde65 | 357 | if (GetSelectedBitmap().GetDepth() == 1) |
ab171e95 | 358 | { |
888dde65 RR |
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 ); | |
ab171e95 RR |
363 | done = true; |
364 | } | |
809934d2 | 365 | } |
ab171e95 RR |
366 | |
367 | if (!done) | |
368 | { | |
369 | if (m_isScreenDC) | |
370 | { | |
888dde65 RR |
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 ); | |
ab171e95 RR |
375 | } |
376 | else | |
377 | { | |
888dde65 RR |
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 ); | |
ab171e95 | 382 | } |
809934d2 RR |
383 | } |
384 | ||
385 | /* background colour */ | |
386 | m_backgroundBrush = *wxWHITE_BRUSH; | |
387 | m_backgroundBrush.GetColour().CalcPixel( m_cmap ); | |
c6685317 | 388 | const GdkColor *bg_col = m_backgroundBrush.GetColour().GetColor(); |
809934d2 RR |
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 ); | |
f4322df6 | 398 | |
4ba1c184 | 399 | gdk_gc_set_colormap( m_textGC, m_cmap ); |
809934d2 RR |
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 ); | |
5f170f33 | 405 | |
809934d2 | 406 | gdk_gc_set_line_attributes( m_penGC, 0, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_ROUND ); |
5f170f33 | 407 | |
809934d2 RR |
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 ); | |
5f170f33 | 412 | |
809934d2 | 413 | gdk_gc_set_fill( m_brushGC, GDK_SOLID ); |
5f170f33 | 414 | |
809934d2 RR |
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 ); | |
5f170f33 | 420 | |
809934d2 RR |
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 ); | |
5f170f33 | 425 | |
809934d2 RR |
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 | ||
888dde65 | 444 | void wxWindowDCImpl::DoGetSize( int* width, int* height ) const |
376aa62a | 445 | { |
888dde65 | 446 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); |
376aa62a | 447 | |
888dde65 | 448 | m_window->GetSize(width, height); |
376aa62a VZ |
449 | } |
450 | ||
888dde65 | 451 | bool wxWindowDCImpl::DoFloodFill(wxCoord x, wxCoord y, |
06cf7c08 VS |
452 | const wxColour& col, int style) |
453 | { | |
c0521644 VZ |
454 | #if wxUSE_IMAGE |
455 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, | |
456 | const wxColour & col, int style); | |
457 | ||
ab171e95 | 458 | return wxDoFloodFill( GetOwner(), x, y, col, style); |
c0521644 | 459 | #else |
8d22935d VZ |
460 | wxUnusedVar(x); |
461 | wxUnusedVar(y); | |
462 | wxUnusedVar(col); | |
463 | wxUnusedVar(style); | |
464 | ||
c0521644 VZ |
465 | return false; |
466 | #endif | |
903f689b | 467 | } |
c801d85f | 468 | |
888dde65 | 469 | bool wxWindowDCImpl::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const |
c801d85f | 470 | { |
c0521644 | 471 | #if wxUSE_IMAGE |
dc1efb1d JS |
472 | // Generic (and therefore rather inefficient) method. |
473 | // Could be improved. | |
474 | wxMemoryDC memdc; | |
475 | wxBitmap bitmap(1, 1); | |
476 | memdc.SelectObject(bitmap); | |
888dde65 | 477 | memdc.Blit(0, 0, 1, 1, GetOwner(), x1, y1); |
dc1efb1d | 478 | memdc.SelectObject(wxNullBitmap); |
c2fa61e8 | 479 | |
368d59f0 | 480 | wxImage image = bitmap.ConvertToImage(); |
dc1efb1d | 481 | col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0)); |
ab9d0a8c | 482 | return true; |
c0521644 | 483 | #else // !wxUSE_IMAGE |
8d22935d VZ |
484 | wxUnusedVar(x1); |
485 | wxUnusedVar(y1); | |
486 | wxUnusedVar(col); | |
487 | ||
c0521644 VZ |
488 | return false; |
489 | #endif // wxUSE_IMAGE/!wxUSE_IMAGE | |
903f689b | 490 | } |
c801d85f | 491 | |
888dde65 | 492 | void wxWindowDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
c801d85f | 493 | { |
ab171e95 | 494 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 495 | |
265898fd RR |
496 | if (m_pen.GetStyle() != wxTRANSPARENT) |
497 | { | |
888dde65 RR |
498 | if (m_gdkwindow) |
499 | gdk_draw_line( m_gdkwindow, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) ); | |
7d5af6fa | 500 | |
ed880dd4 RR |
501 | CalcBoundingBox(x1, y1); |
502 | CalcBoundingBox(x2, y2); | |
265898fd | 503 | } |
903f689b | 504 | } |
c801d85f | 505 | |
888dde65 | 506 | void wxWindowDCImpl::DoCrossHair( wxCoord x, wxCoord y ) |
c801d85f | 507 | { |
ab171e95 | 508 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 509 | |
265898fd RR |
510 | if (m_pen.GetStyle() != wxTRANSPARENT) |
511 | { | |
512 | int w = 0; | |
513 | int h = 0; | |
ab171e95 | 514 | GetOwner()->GetSize( &w, &h ); |
72cdf4c9 VZ |
515 | wxCoord xx = XLOG2DEV(x); |
516 | wxCoord yy = YLOG2DEV(y); | |
888dde65 | 517 | if (m_gdkwindow) |
7d5af6fa | 518 | { |
888dde65 RR |
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) ); | |
7d5af6fa | 521 | } |
265898fd | 522 | } |
903f689b | 523 | } |
c801d85f | 524 | |
888dde65 | 525 | void wxWindowDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, |
72cdf4c9 | 526 | wxCoord xc, wxCoord yc ) |
c801d85f | 527 | { |
ab171e95 | 528 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 529 | |
72cdf4c9 VZ |
530 | wxCoord xx1 = XLOG2DEV(x1); |
531 | wxCoord yy1 = YLOG2DEV(y1); | |
532 | wxCoord xx2 = XLOG2DEV(x2); | |
533 | wxCoord yy2 = YLOG2DEV(y2); | |
534 | wxCoord xxc = XLOG2DEV(xc); | |
535 | wxCoord yyc = YLOG2DEV(yc); | |
7d5af6fa | 536 | double dx = xx1 - xxc; |
265898fd | 537 | double dy = yy1 - yyc; |
de87c353 | 538 | double radius = sqrt((double)(dx*dx+dy*dy)); |
72cdf4c9 | 539 | wxCoord r = (wxCoord)radius; |
265898fd RR |
540 | double radius1, radius2; |
541 | ||
7d5af6fa | 542 | if (xx1 == xx2 && yy1 == yy2) |
265898fd RR |
543 | { |
544 | radius1 = 0.0; | |
545 | radius2 = 360.0; | |
7d5af6fa | 546 | } |
c77a6796 | 547 | else if ( wxIsNullDouble(radius) ) |
265898fd | 548 | { |
c77a6796 VZ |
549 | radius1 = |
550 | radius2 = 0.0; | |
7d5af6fa VZ |
551 | } |
552 | else | |
265898fd RR |
553 | { |
554 | radius1 = (xx1 - xxc == 0) ? | |
b0e0d661 VZ |
555 | (yy1 - yyc < 0) ? 90.0 : -90.0 : |
556 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
265898fd | 557 | radius2 = (xx2 - xxc == 0) ? |
b0e0d661 VZ |
558 | (yy2 - yyc < 0) ? 90.0 : -90.0 : |
559 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
265898fd | 560 | } |
72cdf4c9 VZ |
561 | wxCoord alpha1 = wxCoord(radius1 * 64.0); |
562 | wxCoord alpha2 = wxCoord((radius2 - radius1) * 64.0); | |
265898fd RR |
563 | while (alpha2 <= 0) alpha2 += 360*64; |
564 | while (alpha1 > 360*64) alpha1 -= 360*64; | |
565 | ||
888dde65 | 566 | if (m_gdkwindow) |
6db90681 RR |
567 | { |
568 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
e9f88d04 VZ |
569 | { |
570 | if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) | |
571 | { | |
572 | gdk_gc_set_ts_origin( m_textGC, | |
573 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
574 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); | |
888dde65 | 575 | gdk_draw_arc( m_gdkwindow, m_textGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
e9f88d04 VZ |
576 | gdk_gc_set_ts_origin( m_textGC, 0, 0 ); |
577 | } else | |
3ca6a5f0 BP |
578 | if (IS_15_PIX_HATCH(m_brush.GetStyle())) |
579 | { | |
580 | gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 ); | |
888dde65 | 581 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
3ca6a5f0 BP |
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 ); | |
888dde65 | 587 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
3ca6a5f0 BP |
588 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
589 | } else | |
e9f88d04 VZ |
590 | if (m_brush.GetStyle() == wxSTIPPLE) |
591 | { | |
592 | gdk_gc_set_ts_origin( m_brushGC, | |
593 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
594 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); | |
888dde65 | 595 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
e9f88d04 VZ |
596 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
597 | } | |
598 | else | |
599 | { | |
888dde65 | 600 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
e9f88d04 VZ |
601 | } |
602 | } | |
7d5af6fa | 603 | |
6db90681 | 604 | if (m_pen.GetStyle() != wxTRANSPARENT) |
3d0c4d2e | 605 | { |
888dde65 | 606 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); |
f469b27c | 607 | |
9707fd13 RR |
608 | if ((m_brush.GetStyle() != wxTRANSPARENT) && (alpha2 - alpha1 != 360*64)) |
609 | { | |
888dde65 RR |
610 | gdk_draw_line( m_gdkwindow, m_penGC, xx1, yy1, xxc, yyc ); |
611 | gdk_draw_line( m_gdkwindow, m_penGC, xxc, yyc, xx2, yy2 ); | |
9707fd13 | 612 | } |
3d0c4d2e | 613 | } |
6db90681 | 614 | } |
7d5af6fa | 615 | |
265898fd RR |
616 | CalcBoundingBox (x1, y1); |
617 | CalcBoundingBox (x2, y2); | |
903f689b | 618 | } |
c801d85f | 619 | |
888dde65 | 620 | void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double sa, double ea ) |
c801d85f | 621 | { |
ab171e95 | 622 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 623 | |
72cdf4c9 VZ |
624 | wxCoord xx = XLOG2DEV(x); |
625 | wxCoord yy = YLOG2DEV(y); | |
626 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
627 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
7d5af6fa | 628 | |
265898fd RR |
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; } | |
7d5af6fa | 632 | |
888dde65 | 633 | if (m_gdkwindow) |
6db90681 | 634 | { |
72cdf4c9 | 635 | wxCoord start = wxCoord(sa * 64.0); |
3d0c4d2e | 636 | wxCoord end = wxCoord((ea-sa) * 64.0); |
7d5af6fa | 637 | |
6db90681 | 638 | if (m_brush.GetStyle() != wxTRANSPARENT) |
e9f88d04 VZ |
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() ); | |
888dde65 | 645 | gdk_draw_arc( m_gdkwindow, m_textGC, TRUE, xx, yy, ww, hh, start, end ); |
e9f88d04 VZ |
646 | gdk_gc_set_ts_origin( m_textGC, 0, 0 ); |
647 | } else | |
3ca6a5f0 BP |
648 | if (IS_15_PIX_HATCH(m_brush.GetStyle())) |
649 | { | |
650 | gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 ); | |
888dde65 | 651 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); |
3ca6a5f0 BP |
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 ); | |
888dde65 | 657 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); |
3ca6a5f0 BP |
658 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
659 | } else | |
e9f88d04 VZ |
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() ); | |
888dde65 | 665 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); |
e9f88d04 VZ |
666 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
667 | } | |
668 | else | |
669 | { | |
888dde65 | 670 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); |
e9f88d04 VZ |
671 | } |
672 | } | |
7d5af6fa | 673 | |
6db90681 | 674 | if (m_pen.GetStyle() != wxTRANSPARENT) |
888dde65 | 675 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, ww, hh, start, end ); |
6db90681 | 676 | } |
7d5af6fa | 677 | |
265898fd RR |
678 | CalcBoundingBox (x, y); |
679 | CalcBoundingBox (x + width, y + height); | |
903f689b | 680 | } |
c801d85f | 681 | |
888dde65 | 682 | void wxWindowDCImpl::DoDrawPoint( wxCoord x, wxCoord y ) |
c801d85f | 683 | { |
ab171e95 | 684 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 685 | |
888dde65 RR |
686 | if ((m_pen.GetStyle() != wxTRANSPARENT) && m_gdkwindow) |
687 | gdk_draw_point( m_gdkwindow, m_penGC, XLOG2DEV(x), YLOG2DEV(y) ); | |
7d5af6fa | 688 | |
265898fd | 689 | CalcBoundingBox (x, y); |
903f689b | 690 | } |
c801d85f | 691 | |
888dde65 | 692 | void wxWindowDCImpl::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset ) |
c801d85f | 693 | { |
ab171e95 | 694 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 695 | |
265898fd RR |
696 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
697 | if (n <= 0) return; | |
7d5af6fa | 698 | |
e90411c2 | 699 | //Check, if scaling is necessary |
280831d5 PC |
700 | const bool doScale = |
701 | xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10; | |
e90411c2 | 702 | |
280831d5 PC |
703 | // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other |
704 | GdkPoint* gpts = reinterpret_cast<GdkPoint*>(points); | |
e90411c2 | 705 | |
280831d5 | 706 | if (doScale) |
e90411c2 | 707 | gpts = new GdkPoint[n]; |
7d5af6fa | 708 | |
ab9d0a8c | 709 | for (int i = 0; i < n; i++) |
265898fd | 710 | { |
280831d5 PC |
711 | if (doScale) |
712 | { | |
713 | gpts[i].x = XLOG2DEV(points[i].x + xoffset); | |
714 | gpts[i].y = YLOG2DEV(points[i].y + yoffset); | |
e90411c2 | 715 | } |
280831d5 | 716 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); |
e90411c2 | 717 | } |
6eb37239 | 718 | |
888dde65 RR |
719 | if (m_gdkwindow) |
720 | gdk_draw_lines( m_gdkwindow, m_penGC, gpts, n); | |
6eb37239 | 721 | |
e90411c2 | 722 | if (doScale) |
280831d5 | 723 | delete[] gpts; |
903f689b | 724 | } |
c801d85f | 725 | |
888dde65 | 726 | void wxWindowDCImpl::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int WXUNUSED(fillStyle) ) |
cf7a7e13 | 727 | { |
ab171e95 | 728 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 729 | |
4bc67cc5 | 730 | if (n <= 0) return; |
7d5af6fa | 731 | |
e90411c2 | 732 | //Check, if scaling is necessary |
280831d5 PC |
733 | const bool doScale = |
734 | xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10; | |
e90411c2 | 735 | |
280831d5 PC |
736 | // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other |
737 | GdkPoint* gdkpoints = reinterpret_cast<GdkPoint*>(points); | |
e90411c2 | 738 | |
280831d5 PC |
739 | if (doScale) |
740 | gdkpoints = new GdkPoint[n]; | |
e90411c2 | 741 | |
265898fd RR |
742 | int i; |
743 | for (i = 0 ; i < n ; i++) | |
744 | { | |
280831d5 PC |
745 | if (doScale) |
746 | { | |
747 | gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset); | |
748 | gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset); | |
e90411c2 | 749 | } |
280831d5 | 750 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); |
e90411c2 | 751 | } |
7d5af6fa | 752 | |
888dde65 | 753 | if (m_gdkwindow) |
72174350 | 754 | { |
e1208c31 | 755 | if (m_brush.GetStyle() != wxTRANSPARENT) |
72174350 | 756 | { |
e1208c31 RR |
757 | if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) |
758 | { | |
5f170f33 VZ |
759 | gdk_gc_set_ts_origin( m_textGC, |
760 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
e1208c31 | 761 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 | 762 | gdk_draw_polygon( m_gdkwindow, m_textGC, TRUE, gdkpoints, n ); |
e1208c31 RR |
763 | gdk_gc_set_ts_origin( m_textGC, 0, 0 ); |
764 | } else | |
3ca6a5f0 BP |
765 | if (IS_15_PIX_HATCH(m_brush.GetStyle())) |
766 | { | |
767 | gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 ); | |
888dde65 | 768 | gdk_draw_polygon( m_gdkwindow, m_brushGC, TRUE, gdkpoints, n ); |
3ca6a5f0 BP |
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 ); | |
888dde65 | 774 | gdk_draw_polygon( m_gdkwindow, m_brushGC, TRUE, gdkpoints, n ); |
3ca6a5f0 BP |
775 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
776 | } else | |
e1208c31 RR |
777 | if (m_brush.GetStyle() == wxSTIPPLE) |
778 | { | |
5f170f33 VZ |
779 | gdk_gc_set_ts_origin( m_brushGC, |
780 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
e1208c31 | 781 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 | 782 | gdk_draw_polygon( m_gdkwindow, m_brushGC, TRUE, gdkpoints, n ); |
e1208c31 RR |
783 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
784 | } | |
785 | else | |
786 | { | |
888dde65 | 787 | gdk_draw_polygon( m_gdkwindow, m_brushGC, TRUE, gdkpoints, n ); |
e1208c31 | 788 | } |
72174350 | 789 | } |
7d5af6fa | 790 | |
e1208c31 | 791 | if (m_pen.GetStyle() != wxTRANSPARENT) |
b0e0d661 | 792 | { |
bb56b0a8 | 793 | /* |
e1208c31 RR |
794 | for (i = 0 ; i < n ; i++) |
795 | { | |
888dde65 | 796 | gdk_draw_line( m_gdkwindow, m_penGC, |
e1208c31 RR |
797 | gdkpoints[i%n].x, |
798 | gdkpoints[i%n].y, | |
799 | gdkpoints[(i+1)%n].x, | |
800 | gdkpoints[(i+1)%n].y); | |
801 | } | |
bb56b0a8 | 802 | */ |
888dde65 | 803 | gdk_draw_polygon( m_gdkwindow, m_penGC, FALSE, gdkpoints, n ); |
ab9d0a8c | 804 | |
265898fd | 805 | } |
6db90681 | 806 | } |
7d5af6fa | 807 | |
e90411c2 | 808 | if (doScale) |
280831d5 | 809 | delete[] gdkpoints; |
903f689b | 810 | } |
c801d85f | 811 | |
888dde65 | 812 | void wxWindowDCImpl::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 813 | { |
ab171e95 | 814 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
c801d85f | 815 | |
72cdf4c9 VZ |
816 | wxCoord xx = XLOG2DEV(x); |
817 | wxCoord yy = YLOG2DEV(y); | |
818 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
819 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
7d5af6fa | 820 | |
265898fd RR |
821 | // CMB: draw nothing if transformed w or h is 0 |
822 | if (ww == 0 || hh == 0) return; | |
6f65e337 | 823 | |
265898fd RR |
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; } | |
6f65e337 | 827 | |
888dde65 | 828 | if (m_gdkwindow) |
6db90681 | 829 | { |
e1208c31 | 830 | if (m_brush.GetStyle() != wxTRANSPARENT) |
72174350 | 831 | { |
e1208c31 RR |
832 | if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) |
833 | { | |
5f170f33 VZ |
834 | gdk_gc_set_ts_origin( m_textGC, |
835 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
e1208c31 | 836 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 | 837 | gdk_draw_rectangle( m_gdkwindow, m_textGC, TRUE, xx, yy, ww, hh ); |
e1208c31 | 838 | gdk_gc_set_ts_origin( m_textGC, 0, 0 ); |
3ca6a5f0 BP |
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 ); | |
888dde65 | 843 | gdk_draw_rectangle( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh ); |
3ca6a5f0 BP |
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 ); | |
888dde65 | 849 | gdk_draw_rectangle( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh ); |
3ca6a5f0 BP |
850 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
851 | } else | |
852 | if (m_brush.GetStyle() == wxSTIPPLE) | |
e1208c31 | 853 | { |
5f170f33 VZ |
854 | gdk_gc_set_ts_origin( m_brushGC, |
855 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
e1208c31 | 856 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 | 857 | gdk_draw_rectangle( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh ); |
e1208c31 RR |
858 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
859 | } | |
860 | else | |
861 | { | |
888dde65 | 862 | gdk_draw_rectangle( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh ); |
e1208c31 | 863 | } |
72174350 | 864 | } |
e1208c31 RR |
865 | |
866 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
3b5bf828 RR |
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 | |
888dde65 RR |
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 ); | |
3b5bf828 RR |
880 | } |
881 | else | |
882 | { | |
888dde65 RR |
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 ); | |
3b5bf828 | 885 | } |
f4322df6 | 886 | |
3b5bf828 RR |
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 | |
888dde65 | 894 | gdk_draw_rectangle( m_gdkwindow, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); |
3b5bf828 RR |
895 | } |
896 | } | |
6db90681 | 897 | } |
7d5af6fa | 898 | |
265898fd RR |
899 | CalcBoundingBox( x, y ); |
900 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 901 | } |
c801d85f | 902 | |
888dde65 | 903 | void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius ) |
c801d85f | 904 | { |
ab171e95 | 905 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 906 | |
265898fd | 907 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); |
7d5af6fa | 908 | |
72cdf4c9 VZ |
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); | |
265898fd RR |
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 | { | |
ab171e95 | 923 | DoDrawRectangle( x, y, width, height ); |
265898fd RR |
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 | ||
888dde65 | 938 | if (m_gdkwindow) |
265898fd | 939 | { |
6db90681 RR |
940 | // CMB: ensure dd is not larger than rectangle otherwise we |
941 | // get an hour glass shape | |
72cdf4c9 | 942 | wxCoord dd = 2 * rr; |
6db90681 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 | { | |
a56fcaaf RR |
949 | if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) |
950 | { | |
5f170f33 VZ |
951 | gdk_gc_set_ts_origin( m_textGC, |
952 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
a56fcaaf | 953 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 RR |
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 ); | |
a56fcaaf | 960 | gdk_gc_set_ts_origin( m_textGC, 0, 0 ); |
3ca6a5f0 BP |
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 ); | |
888dde65 RR |
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 ); | |
3ca6a5f0 BP |
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 ); | |
888dde65 RR |
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 ); | |
3ca6a5f0 BP |
982 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
983 | } else | |
984 | if (m_brush.GetStyle() == wxSTIPPLE) | |
a56fcaaf | 985 | { |
5f170f33 VZ |
986 | gdk_gc_set_ts_origin( m_brushGC, |
987 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
a56fcaaf | 988 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 RR |
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 ); | |
a56fcaaf RR |
995 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
996 | } | |
997 | else | |
998 | { | |
888dde65 RR |
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 ); | |
a56fcaaf | 1005 | } |
6db90681 | 1006 | } |
7d5af6fa | 1007 | |
6db90681 | 1008 | if (m_pen.GetStyle() != wxTRANSPARENT) |
7d5af6fa | 1009 | { |
888dde65 RR |
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 ); | |
7d5af6fa | 1018 | } |
265898fd | 1019 | } |
7d5af6fa | 1020 | |
265898fd RR |
1021 | // this ignores the radius |
1022 | CalcBoundingBox( x, y ); | |
1023 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 1024 | } |
c801d85f | 1025 | |
888dde65 | 1026 | void wxWindowDCImpl::DoDrawEllipse( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 1027 | { |
ab171e95 | 1028 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1029 | |
72cdf4c9 VZ |
1030 | wxCoord xx = XLOG2DEV(x); |
1031 | wxCoord yy = YLOG2DEV(y); | |
1032 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
1033 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
6f65e337 | 1034 | |
265898fd RR |
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; } | |
7d5af6fa | 1038 | |
888dde65 | 1039 | if (m_gdkwindow) |
6db90681 RR |
1040 | { |
1041 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
a56fcaaf RR |
1042 | { |
1043 | if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) | |
1044 | { | |
5f170f33 VZ |
1045 | gdk_gc_set_ts_origin( m_textGC, |
1046 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
a56fcaaf | 1047 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 | 1048 | gdk_draw_arc( m_gdkwindow, m_textGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); |
a56fcaaf | 1049 | gdk_gc_set_ts_origin( m_textGC, 0, 0 ); |
3ca6a5f0 BP |
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 ); | |
888dde65 | 1054 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); |
3ca6a5f0 BP |
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 ); | |
888dde65 | 1060 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); |
3ca6a5f0 BP |
1061 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
1062 | } else | |
1063 | if (m_brush.GetStyle() == wxSTIPPLE) | |
a56fcaaf | 1064 | { |
5f170f33 VZ |
1065 | gdk_gc_set_ts_origin( m_brushGC, |
1066 | m_deviceOriginX % m_brush.GetStipple()->GetWidth(), | |
a56fcaaf | 1067 | m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); |
888dde65 | 1068 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); |
a56fcaaf RR |
1069 | gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); |
1070 | } | |
1071 | else | |
1072 | { | |
888dde65 | 1073 | gdk_draw_arc( m_gdkwindow, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); |
a56fcaaf RR |
1074 | } |
1075 | } | |
7d5af6fa | 1076 | |
6db90681 | 1077 | if (m_pen.GetStyle() != wxTRANSPARENT) |
888dde65 | 1078 | gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 ); |
6db90681 | 1079 | } |
7d5af6fa | 1080 | |
44856297 | 1081 | CalcBoundingBox( x, y ); |
265898fd | 1082 | CalcBoundingBox( x + width, y + height ); |
903f689b | 1083 | } |
c801d85f | 1084 | |
888dde65 | 1085 | void wxWindowDCImpl::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) |
c801d85f | 1086 | { |
b0e0d661 | 1087 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why |
ab9d0a8c | 1088 | DoDrawBitmap( (const wxBitmap&)icon, x, y, true ); |
903f689b | 1089 | } |
c801d85f | 1090 | |
888dde65 | 1091 | void wxWindowDCImpl::DoDrawBitmap( const wxBitmap &bitmap, |
72cdf4c9 | 1092 | wxCoord x, wxCoord y, |
b0e0d661 | 1093 | bool useMask ) |
4bc67cc5 | 1094 | { |
ab171e95 | 1095 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1096 | |
ab171e95 | 1097 | wxCHECK_RET( bitmap.IsOk(), wxT("invalid bitmap") ); |
7d5af6fa | 1098 | |
b85229d1 | 1099 | bool is_mono = bitmap.GetDepth() == 1; |
82ea63e6 | 1100 | |
d90c9596 | 1101 | // scale/translate size and position |
265898fd RR |
1102 | int xx = XLOG2DEV(x); |
1103 | int yy = YLOG2DEV(y); | |
7d5af6fa | 1104 | |
4bc67cc5 RR |
1105 | int w = bitmap.GetWidth(); |
1106 | int h = bitmap.GetHeight(); | |
f4322df6 | 1107 | |
888dde65 | 1108 | if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) |
847dfdb4 | 1109 | xx -= w; |
f4322df6 | 1110 | |
6453876e RR |
1111 | CalcBoundingBox( x, y ); |
1112 | CalcBoundingBox( x + w, y + h ); | |
7d5af6fa | 1113 | |
888dde65 | 1114 | if (!m_gdkwindow) return; |
7d5af6fa | 1115 | |
4bc67cc5 RR |
1116 | int ww = XLOG2DEVREL(w); |
1117 | int hh = YLOG2DEVREL(h); | |
7d5af6fa | 1118 | |
d90c9596 | 1119 | // compare to current clipping region |
e1208c31 | 1120 | if (!m_currentClippingRegion.IsNull()) |
3d2d8da1 RR |
1121 | { |
1122 | wxRegion tmp( xx,yy,ww,hh ); | |
1123 | tmp.Intersect( m_currentClippingRegion ); | |
1124 | if (tmp.IsEmpty()) | |
1125 | return; | |
1126 | } | |
5f170f33 | 1127 | |
ab9d0a8c | 1128 | // scale bitmap if required |
d90c9596 | 1129 | wxBitmap use_bitmap = bitmap; |
4bc67cc5 | 1130 | if ((w != ww) || (h != hh)) |
d90c9596 | 1131 | use_bitmap = use_bitmap.Rescale( 0, 0, ww, hh, ww, hh ); |
ab9d0a8c | 1132 | |
d90c9596 | 1133 | // apply mask if any |
463c1fa1 | 1134 | GdkBitmap *mask = (GdkBitmap *) NULL; |
280831d5 PC |
1135 | if (useMask && use_bitmap.GetMask()) |
1136 | mask = use_bitmap.GetMask()->GetBitmap(); | |
1137 | ||
1138 | GdkGC* use_gc = is_mono ? m_textGC : m_penGC; | |
7d5af6fa | 1139 | |
d90c9596 | 1140 | GdkBitmap *new_mask = (GdkBitmap*) NULL; |
ab9d0a8c | 1141 | |
280831d5 | 1142 | if (mask != NULL) |
d90c9596 RR |
1143 | { |
1144 | if (!m_currentClippingRegion.IsNull()) | |
82ea63e6 | 1145 | { |
d90c9596 RR |
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 ); | |
280831d5 | 1161 | mask = new_mask; |
3fe39b0c | 1162 | g_object_unref (gc); |
d90c9596 | 1163 | } |
ab9d0a8c | 1164 | |
280831d5 PC |
1165 | gdk_gc_set_clip_mask(use_gc, mask); |
1166 | gdk_gc_set_clip_origin(use_gc, xx, yy); | |
d90c9596 | 1167 | } |
7d5af6fa | 1168 | |
d90c9596 RR |
1169 | // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For |
1170 | // drawing a mono-bitmap (XBitmap) we use the current text GC | |
82ea63e6 | 1171 | if (is_mono) |
d90c9596 | 1172 | { |
4e115ed2 VZ |
1173 | GdkPixmap *bitmap2 = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, -1 ); |
1174 | GdkGC *gc = gdk_gc_new( bitmap2 ); | |
d90c9596 RR |
1175 | gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() ); |
1176 | gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() ); | |
e4161a2a | 1177 | gdk_wx_draw_bitmap(bitmap2, gc, use_bitmap.GetPixmap(), 0, 0); |
ab9d0a8c | 1178 | |
888dde65 | 1179 | gdk_draw_drawable(m_gdkwindow, use_gc, bitmap2, 0, 0, xx, yy, -1, -1); |
ab9d0a8c | 1180 | |
3fe39b0c MR |
1181 | g_object_unref (bitmap2); |
1182 | g_object_unref (gc); | |
d90c9596 | 1183 | } |
82ea63e6 | 1184 | else |
d90c9596 | 1185 | { |
ff654490 | 1186 | if (use_bitmap.HasPixbuf()) |
feac7937 | 1187 | { |
888dde65 | 1188 | gdk_draw_pixbuf(m_gdkwindow, use_gc, |
feac7937 VS |
1189 | use_bitmap.GetPixbuf(), |
1190 | 0, 0, xx, yy, -1, -1, | |
1191 | GDK_RGB_DITHER_NORMAL, xx, yy); | |
1192 | } | |
1193 | else | |
feac7937 | 1194 | { |
888dde65 | 1195 | gdk_draw_drawable(m_gdkwindow, use_gc, |
15f0ad70 MR |
1196 | use_bitmap.GetPixmap(), |
1197 | 0, 0, xx, yy, -1, -1); | |
feac7937 | 1198 | } |
d90c9596 | 1199 | } |
72174350 | 1200 | |
d90c9596 | 1201 | // remove mask again if any |
280831d5 | 1202 | if (mask != NULL) |
463c1fa1 | 1203 | { |
280831d5 PC |
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); | |
463c1fa1 | 1210 | } |
463c1fa1 RR |
1211 | } |
1212 | ||
888dde65 | 1213 | bool wxWindowDCImpl::DoBlit( wxCoord xdest, wxCoord ydest, |
1e6feb95 VZ |
1214 | wxCoord width, wxCoord height, |
1215 | wxDC *source, | |
1216 | wxCoord xsrc, wxCoord ysrc, | |
1217 | int logical_func, | |
0cbff120 JS |
1218 | bool useMask, |
1219 | wxCoord xsrcMask, wxCoord ysrcMask ) | |
c801d85f | 1220 | { |
ab171e95 | 1221 | wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") ); |
7d5af6fa | 1222 | |
ab9d0a8c | 1223 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
7d5af6fa | 1224 | |
888dde65 | 1225 | if (!m_gdkwindow) return false; |
7d5af6fa | 1226 | |
1e6feb95 | 1227 | // transform the source DC coords to the device ones |
772b3767 PC |
1228 | xsrc = source->LogicalToDeviceX(xsrc); |
1229 | ysrc = source->LogicalToDeviceY(ysrc); | |
1e6feb95 | 1230 | |
e19a8aea | 1231 | wxBitmap selected; |
f98bd6d6 | 1232 | wxMemoryDC *memDC = wxDynamicCast(source, wxMemoryDC); |
e19a8aea VZ |
1233 | if ( memDC ) |
1234 | { | |
1235 | selected = memDC->GetSelectedBitmap(); | |
1236 | if ( !selected.IsOk() ) | |
1237 | return false; | |
1238 | } | |
f4322df6 | 1239 | |
ab9d0a8c WS |
1240 | bool use_bitmap_method = false; |
1241 | bool is_mono = false; | |
7d5af6fa | 1242 | |
0cbff120 JS |
1243 | if (xsrcMask == -1 && ysrcMask == -1) |
1244 | { | |
d90c9596 RR |
1245 | xsrcMask = xsrc; |
1246 | ysrcMask = ysrc; | |
0cbff120 JS |
1247 | } |
1248 | ||
ab171e95 | 1249 | if (selected.IsOk()) |
6e13c196 | 1250 | { |
f98bd6d6 | 1251 | is_mono = (selected.GetDepth() == 1); |
d90c9596 RR |
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 | |
7d5af6fa | 1258 | |
f98bd6d6 | 1259 | if (useMask && (selected.GetMask())) |
b0e0d661 | 1260 | { |
d90c9596 RR |
1261 | // we HAVE TO use the direct way for memory dcs |
1262 | // that have mask since the XCopyArea doesn't know | |
1263 | // about masks | |
ab9d0a8c | 1264 | use_bitmap_method = true; |
b0e0d661 | 1265 | } |
d90c9596 | 1266 | else if (is_mono) |
b0e0d661 | 1267 | { |
d90c9596 RR |
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 | |
ab9d0a8c | 1271 | use_bitmap_method = true; |
b0e0d661 VZ |
1272 | } |
1273 | else if ((xsrc == 0) && (ysrc == 0) && | |
f98bd6d6 RD |
1274 | (width == selected.GetWidth()) && |
1275 | (height == selected.GetHeight())) | |
b0e0d661 | 1276 | { |
d90c9596 RR |
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 | |
ab9d0a8c | 1281 | use_bitmap_method = true; |
b0e0d661 | 1282 | } |
6e13c196 | 1283 | } |
7d5af6fa | 1284 | |
265898fd RR |
1285 | CalcBoundingBox( xdest, ydest ); |
1286 | CalcBoundingBox( xdest + width, ydest + height ); | |
7d5af6fa | 1287 | |
d90c9596 | 1288 | // scale/translate size and position |
3d2d8da1 RR |
1289 | wxCoord xx = XLOG2DEV(xdest); |
1290 | wxCoord yy = YLOG2DEV(ydest); | |
1291 | ||
1292 | wxCoord ww = XLOG2DEVREL(width); | |
1293 | wxCoord hh = YLOG2DEVREL(height); | |
1294 | ||
d90c9596 | 1295 | // compare to current clipping region |
e1208c31 | 1296 | if (!m_currentClippingRegion.IsNull()) |
3d2d8da1 RR |
1297 | { |
1298 | wxRegion tmp( xx,yy,ww,hh ); | |
1299 | tmp.Intersect( m_currentClippingRegion ); | |
1300 | if (tmp.IsEmpty()) | |
ab9d0a8c | 1301 | return true; |
3d2d8da1 RR |
1302 | } |
1303 | ||
4bc67cc5 RR |
1304 | int old_logical_func = m_logicalFunction; |
1305 | SetLogicalFunction( logical_func ); | |
5f170f33 | 1306 | |
6e13c196 | 1307 | if (use_bitmap_method) |
6f65e337 | 1308 | { |
d90c9596 | 1309 | // scale/translate bitmap size |
f98bd6d6 RD |
1310 | wxCoord bm_width = selected.GetWidth(); |
1311 | wxCoord bm_height = selected.GetHeight(); | |
7d5af6fa | 1312 | |
551b5391 RR |
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; | |
ab9d0a8c | 1321 | |
d90c9596 RR |
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 | ||
72cdf4c9 VZ |
1328 | wxCoord bm_ww = XLOG2DEVREL( bm_width ); |
1329 | wxCoord bm_hh = YLOG2DEVREL( bm_height ); | |
7d5af6fa | 1330 | |
551b5391 | 1331 | // Scale bitmap if required |
f98bd6d6 RD |
1332 | wxBitmap use_bitmap = selected; |
1333 | if ((selected.GetWidth()!= bm_ww) || ( selected.GetHeight()!= bm_hh)) | |
6e13c196 | 1334 | { |
551b5391 RR |
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 ); | |
93da796d RR |
1339 | if (!m_currentClippingRegion.IsNull()) |
1340 | tmp.Intersect( m_currentClippingRegion ); | |
551b5391 | 1341 | tmp.GetBox(cx,cy,cw,ch); |
ab9d0a8c | 1342 | |
551b5391 | 1343 | // Scale and clipped bitmap |
f98bd6d6 | 1344 | use_bitmap = selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh); |
6e13c196 | 1345 | } |
7d5af6fa | 1346 | |
d90c9596 | 1347 | // apply mask if any |
6e13c196 | 1348 | GdkBitmap *mask = (GdkBitmap *) NULL; |
280831d5 PC |
1349 | if (useMask && use_bitmap.GetMask()) |
1350 | mask = use_bitmap.GetMask()->GetBitmap(); | |
1351 | ||
1352 | GdkGC* use_gc = is_mono ? m_textGC : m_penGC; | |
7d5af6fa | 1353 | |
d90c9596 | 1354 | GdkBitmap *new_mask = (GdkBitmap*) NULL; |
ab9d0a8c | 1355 | |
280831d5 | 1356 | if (mask != NULL) |
6e13c196 | 1357 | { |
e1208c31 | 1358 | if (!m_currentClippingRegion.IsNull()) |
3d2d8da1 RR |
1359 | { |
1360 | GdkColor col; | |
c2fa61e8 | 1361 | new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, 1 ); |
3d2d8da1 RR |
1362 | GdkGC *gc = gdk_gc_new( new_mask ); |
1363 | col.pixel = 0; | |
1364 | gdk_gc_set_foreground( gc, &col ); | |
b7a49654 | 1365 | gdk_gc_set_ts_origin( gc, -xsrcMask, -ysrcMask); |
3d2d8da1 RR |
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() ); | |
d90c9596 RR |
1372 | // was: gdk_gc_set_clip_origin( gc, -xx, -yy ); |
1373 | gdk_gc_set_clip_origin( gc, -cx, -cy ); | |
3d2d8da1 RR |
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 ); | |
280831d5 | 1377 | mask = new_mask; |
3fe39b0c | 1378 | g_object_unref (gc); |
3d2d8da1 | 1379 | } |
d90c9596 | 1380 | |
280831d5 PC |
1381 | gdk_gc_set_clip_mask(use_gc, mask); |
1382 | if (new_mask != NULL) | |
1383 | gdk_gc_set_clip_origin(use_gc, cx, cy); | |
82ea63e6 | 1384 | else |
280831d5 | 1385 | gdk_gc_set_clip_origin(use_gc, cx - xsrcMask, cy - ysrcMask); |
6e13c196 | 1386 | } |
7d5af6fa | 1387 | |
d90c9596 RR |
1388 | // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For |
1389 | // drawing a mono-bitmap (XBitmap) we use the current text GC | |
5f170f33 | 1390 | |
82ea63e6 | 1391 | if (is_mono) |
d90c9596 | 1392 | { |
d90c9596 RR |
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() ); | |
e4161a2a | 1397 | gdk_wx_draw_bitmap(bitmap, gc, use_bitmap.GetPixmap(), 0, 0); |
ab9d0a8c | 1398 | |
888dde65 | 1399 | gdk_draw_drawable(m_gdkwindow, use_gc, bitmap, xsrc, ysrc, cx, cy, cw, ch); |
ab9d0a8c | 1400 | |
3fe39b0c MR |
1401 | g_object_unref (bitmap); |
1402 | g_object_unref (gc); | |
d90c9596 | 1403 | } |
82ea63e6 | 1404 | else |
d90c9596 | 1405 | { |
888dde65 RR |
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); | |
d90c9596 | 1408 | } |
82ea63e6 | 1409 | |
d90c9596 | 1410 | // remove mask again if any |
280831d5 | 1411 | if (mask != NULL) |
6e13c196 | 1412 | { |
280831d5 PC |
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()); | |
265898fd | 1417 | } |
ab9d0a8c | 1418 | |
d90c9596 | 1419 | if (new_mask) |
3fe39b0c | 1420 | g_object_unref (new_mask); |
6f65e337 | 1421 | } |
d90c9596 | 1422 | else // use_bitmap_method |
6e13c196 | 1423 | { |
ab171e95 | 1424 | if (selected.IsOk() && ((width != ww) || (height != hh))) |
b0e0d661 | 1425 | { |
d90c9596 RR |
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); | |
ab9d0a8c WS |
1431 | |
1432 | // rescale bitmap | |
f98bd6d6 | 1433 | wxBitmap bitmap = selected.Rescale( cx-xx, cy-yy, cw, ch, ww, hh ); |
7d5af6fa | 1434 | |
d90c9596 | 1435 | // draw scaled bitmap |
888dde65 RR |
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 ); | |
b0e0d661 VZ |
1438 | } |
1439 | else | |
1440 | { | |
ab9d0a8c | 1441 | // No scaling and not a memory dc with a mask either |
ab171e95 RR |
1442 | #if wxUSE_NEW_DC |
1443 | GdkWindow* window = NULL; | |
888dde65 RR |
1444 | wxDCImpl *impl = source->GetImpl(); |
1445 | wxWindowDCImpl *gtk_impl = wxDynamicCast(impl, wxWindowDCImpl); | |
ab171e95 RR |
1446 | if (gtk_impl) |
1447 | window = gtk_impl->GetGDKWindow(); | |
1448 | #else | |
f98bd6d6 | 1449 | GdkWindow* window = source->GetGDKWindow(); |
ab171e95 | 1450 | #endif |
f98bd6d6 RD |
1451 | if ( !window ) |
1452 | return false; | |
f4322df6 | 1453 | |
d90c9596 | 1454 | // copy including child window contents |
a56fcaaf | 1455 | gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); |
888dde65 | 1456 | gdk_draw_drawable( m_gdkwindow, m_penGC, |
f98bd6d6 | 1457 | window, |
15f0ad70 MR |
1458 | xsrc, ysrc, xx, yy, |
1459 | width, height ); | |
a56fcaaf | 1460 | gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); |
b0e0d661 | 1461 | } |
6e13c196 | 1462 | } |
c801d85f | 1463 | |
4bc67cc5 | 1464 | SetLogicalFunction( old_logical_func ); |
ab9d0a8c WS |
1465 | |
1466 | return true; | |
903f689b | 1467 | } |
c801d85f | 1468 | |
888dde65 | 1469 | void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) |
c801d85f | 1470 | { |
ab171e95 | 1471 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
18a2fa37 | 1472 | |
888dde65 | 1473 | if (!m_gdkwindow) return; |
ab9d0a8c | 1474 | |
2b5f62a0 | 1475 | if (text.empty()) return; |
7d5af6fa | 1476 | |
265898fd RR |
1477 | x = XLOG2DEV(x); |
1478 | y = YLOG2DEV(y); | |
18a2fa37 | 1479 | |
cfcc3932 | 1480 | wxCHECK_RET( m_context, wxT("no Pango context") ); |
61850501 | 1481 | wxCHECK_RET( m_layout, wxT("no Pango layout") ); |
cfcc3932 | 1482 | wxCHECK_RET( m_fontdesc, wxT("no Pango font description") ); |
e4da1035 | 1483 | |
24bbbfb1 RR |
1484 | gdk_pango_context_set_colormap( m_context, m_cmap ); |
1485 | ||
ab171e95 | 1486 | bool underlined = m_font.IsOk() && m_font.GetUnderlined(); |
1dbeee57 | 1487 | |
a3669332 VZ |
1488 | const wxCharBuffer data = wxGTK_CONV( text ); |
1489 | if ( !data ) | |
7706daf3 | 1490 | return; |
67a083dd RR |
1491 | size_t datalen = strlen(data); |
1492 | ||
5f4d1820 VZ |
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; | |
67a083dd RR |
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 | } | |
ab9d0a8c | 1531 | |
1dbeee57 VS |
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); | |
67a083dd RR |
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 | ||
1dbeee57 VS |
1555 | pango_layout_set_attributes(m_layout, attrs); |
1556 | pango_attr_list_unref(attrs); | |
1557 | } | |
e4da1035 | 1558 | |
76b20467 | 1559 | int w,h; |
fa499247 RR |
1560 | |
1561 | if (fabs(m_scaleY - 1.0) > 0.00001) | |
e4da1035 RR |
1562 | { |
1563 | // If there is a user or actually any scale applied to | |
1564 | // the device context, scale the font. | |
ab9d0a8c | 1565 | |
e4da1035 RR |
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 ); | |
ab9d0a8c | 1571 | |
e4da1035 RR |
1572 | // actually apply scaled font |
1573 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
ab9d0a8c | 1574 | |
76b20467 VS |
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()); | |
888dde65 | 1579 | gdk_draw_rectangle(m_gdkwindow, m_textGC, TRUE, x, y, w, h); |
76b20467 VS |
1580 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); |
1581 | } | |
ab9d0a8c | 1582 | |
e4da1035 | 1583 | // Draw layout. |
888dde65 RR |
1584 | if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) |
1585 | gdk_draw_layout( m_gdkwindow, m_textGC, x-w, y, m_layout ); | |
847dfdb4 | 1586 | else |
888dde65 | 1587 | gdk_draw_layout( m_gdkwindow, m_textGC, x, y, m_layout ); |
ab9d0a8c | 1588 | |
e4da1035 RR |
1589 | // reset unscaled size |
1590 | pango_font_description_set_size( m_fontdesc, oldSize ); | |
ab9d0a8c | 1591 | |
61850501 | 1592 | // actually apply unscaled font |
e4da1035 RR |
1593 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1594 | } | |
1595 | else | |
1596 | { | |
76b20467 VS |
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()); | |
888dde65 | 1601 | gdk_draw_rectangle(m_gdkwindow, m_textGC, TRUE, x, y, w, h); |
76b20467 VS |
1602 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); |
1603 | } | |
f4322df6 | 1604 | |
76b20467 | 1605 | // Draw layout. |
888dde65 RR |
1606 | if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) |
1607 | gdk_draw_layout( m_gdkwindow, m_textGC, x-w, y, m_layout ); | |
847dfdb4 | 1608 | else |
888dde65 | 1609 | gdk_draw_layout( m_gdkwindow, m_textGC, x, y, m_layout ); |
8943b403 | 1610 | } |
1dbeee57 VS |
1611 | |
1612 | if (underlined) | |
1613 | { | |
1614 | // undo underline attributes setting: | |
1615 | pango_layout_set_attributes(m_layout, NULL); | |
1616 | } | |
ab9d0a8c | 1617 | |
2b5f62a0 VZ |
1618 | wxCoord width = w; |
1619 | wxCoord height = h; | |
ab9d0a8c | 1620 | |
8943b403 OK |
1621 | width = wxCoord(width / m_scaleX); |
1622 | height = wxCoord(height / m_scaleY); | |
1623 | CalcBoundingBox (x + width, y + height); | |
265898fd | 1624 | CalcBoundingBox (x, y); |
67a083dd RR |
1625 | |
1626 | if (hackstring) | |
1627 | free(hackstring); | |
903f689b | 1628 | } |
c801d85f | 1629 | |
bf47e398 RD |
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 | ||
888dde65 | 1635 | void wxWindowDCImpl::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle ) |
95724b1a | 1636 | { |
c0521644 | 1637 | #if wxUSE_IMAGE |
888dde65 | 1638 | if (!m_gdkwindow || text.empty()) |
1c2d839f PC |
1639 | return; |
1640 | ||
ab171e95 | 1641 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
1c2d839f | 1642 | |
c77a6796 | 1643 | if ( wxIsNullDouble(angle) ) |
95724b1a | 1644 | { |
ab171e95 | 1645 | DoDrawText(text, x, y); |
95724b1a VZ |
1646 | return; |
1647 | } | |
1648 | ||
bf47e398 RD |
1649 | wxCoord w; |
1650 | wxCoord h; | |
1651 | ||
68567a96 | 1652 | // TODO: implement later without GdkFont for GTK 2.0 |
ab171e95 | 1653 | DoGetTextExtent(text, &w, &h, NULL,NULL, &m_font); |
ab9d0a8c | 1654 | |
9a8c7620 VZ |
1655 | // draw the string normally |
1656 | wxBitmap src(w, h); | |
95724b1a VZ |
1657 | wxMemoryDC dc; |
1658 | dc.SelectObject(src); | |
1659 | dc.SetFont(GetFont()); | |
f1c72f0c | 1660 | dc.SetBackground(*wxBLACK_BRUSH); |
95724b1a VZ |
1661 | dc.SetBrush(*wxBLACK_BRUSH); |
1662 | dc.Clear(); | |
f1c72f0c | 1663 | dc.SetTextForeground( *wxWHITE ); |
95724b1a | 1664 | dc.DrawText(text, 0, 0); |
9a8c7620 | 1665 | dc.SelectObject(wxNullBitmap); |
95724b1a VZ |
1666 | |
1667 | // Calculate the size of the rotated bounding box. | |
9a8c7620 VZ |
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; | |
ab9d0a8c | 1680 | |
72174350 | 1681 | // calc max and min |
9a8c7620 VZ |
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 | ||
72174350 | 1687 | |
f1c72f0c | 1688 | wxImage image = src.ConvertToImage(); |
9a8c7620 | 1689 | |
f1c72f0c RR |
1690 | image.ConvertColourToAlpha( m_textForegroundColour.Red(), |
1691 | m_textForegroundColour.Green(), | |
1692 | m_textForegroundColour.Blue() ); | |
1693 | image = image.Rotate( rad, wxPoint(0,0) ); | |
ab9d0a8c | 1694 | |
1d65e535 RR |
1695 | int i_angle = (int) angle; |
1696 | i_angle = i_angle % 360; | |
c2cb80c8 KH |
1697 | if (i_angle < 0) |
1698 | i_angle += 360; | |
1d65e535 RR |
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(); | |
ab9d0a8c | 1705 | |
1d65e535 RR |
1706 | if ((i_angle >= 0) && (i_angle < 90)) |
1707 | yoffset -= (int)( cos(rad)*h ); | |
1708 | if ((i_angle >= 90) && (i_angle < 180)) | |
ab9d0a8c | 1709 | xoffset -= (int)( sin(rad)*h ); |
1d65e535 RR |
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 ); | |
ab9d0a8c | 1714 | |
1d65e535 RR |
1715 | int i_x = x - xoffset; |
1716 | int i_y = y - yoffset; | |
ab9d0a8c | 1717 | |
f1c72f0c | 1718 | src = image; |
1d65e535 | 1719 | DoDrawBitmap( src, i_x, i_y, true ); |
9a8c7620 | 1720 | |
95724b1a | 1721 | |
9a8c7620 VZ |
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 | { | |
888dde65 | 1727 | gdk_draw_line( m_gdkwindow, m_textGC, |
9a8c7620 VZ |
1728 | XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent), |
1729 | XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent)); | |
1730 | } | |
1731 | #endif // 0 | |
1732 | ||
9a8c7620 VZ |
1733 | // update the bounding box |
1734 | CalcBoundingBox(x + minX, y + minY); | |
1735 | CalcBoundingBox(x + maxX, y + maxY); | |
8d22935d VZ |
1736 | #else // !wxUSE_IMAGE |
1737 | wxUnusedVar(text); | |
1738 | wxUnusedVar(x); | |
1739 | wxUnusedVar(y); | |
1740 | wxUnusedVar(angle); | |
1741 | #endif // wxUSE_IMAGE/!wxUSE_IMAGE | |
95724b1a VZ |
1742 | } |
1743 | ||
888dde65 | 1744 | void wxWindowDCImpl::DoGetTextExtent(const wxString &string, |
72cdf4c9 VZ |
1745 | wxCoord *width, wxCoord *height, |
1746 | wxCoord *descent, wxCoord *externalLeading, | |
c94f845b | 1747 | const wxFont *theFont) const |
c801d85f | 1748 | { |
b1f0abe4 VZ |
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 | ||
ab9d0a8c | 1758 | if (string.empty()) |
48d011c8 | 1759 | return; |
ab9d0a8c | 1760 | |
bf5752a4 | 1761 | // ensure that theFont is always non-NULL |
ab171e95 | 1762 | if ( !theFont || !theFont->IsOk() ) |
bf5752a4 VZ |
1763 | theFont = wx_const_cast(wxFont *, &m_font); |
1764 | ||
1765 | // and use it if it's valid | |
ab171e95 | 1766 | if ( theFont->IsOk() ) |
bf5752a4 VZ |
1767 | { |
1768 | pango_layout_set_font_description | |
1769 | ( | |
1770 | m_layout, | |
1771 | theFont->GetNativeFontInfo()->description | |
1772 | ); | |
1773 | } | |
ab9d0a8c | 1774 | |
2b5f62a0 | 1775 | // Set layout's text |
bf5752a4 | 1776 | const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, *theFont); |
a1e101d0 VZ |
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) ); | |
ab9d0a8c | 1784 | |
48d011c8 RR |
1785 | if (descent) |
1786 | { | |
ace35c62 RR |
1787 | int h; |
1788 | pango_layout_get_pixel_size( m_layout, width, &h ); | |
f69e2009 VS |
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); | |
ace35c62 RR |
1793 | |
1794 | if (height) | |
1795 | *height = (wxCoord) h; | |
1796 | } | |
1797 | else | |
1798 | { | |
1799 | pango_layout_get_pixel_size( m_layout, width, height ); | |
48d011c8 | 1800 | } |
ab9d0a8c | 1801 | |
cfcc3932 | 1802 | // Reset old font description |
6fbe4b24 | 1803 | if (theFont->IsOk()) |
cfcc3932 | 1804 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
903f689b | 1805 | } |
c801d85f | 1806 | |
1f91072f | 1807 | |
888dde65 | 1808 | bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString& text, |
1f91072f VZ |
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) ); | |
f4322df6 | 1828 | |
1f91072f VZ |
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); | |
1f91072f VZ |
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 | ||
888dde65 | 1851 | wxCoord wxWindowDCImpl::GetCharWidth() const |
c801d85f | 1852 | { |
cfcc3932 | 1853 | pango_layout_set_text( m_layout, "H", 1 ); |
ace35c62 RR |
1854 | int w; |
1855 | pango_layout_get_pixel_size( m_layout, &w, NULL ); | |
2b5f62a0 | 1856 | return w; |
903f689b | 1857 | } |
c801d85f | 1858 | |
888dde65 | 1859 | wxCoord wxWindowDCImpl::GetCharHeight() const |
c801d85f | 1860 | { |
a8c5e1a9 | 1861 | PangoFontMetrics *metrics = pango_context_get_metrics (m_context, m_fontdesc, pango_context_get_language(m_context)); |
2e61f681 VZ |
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; | |
903f689b | 1868 | } |
c801d85f | 1869 | |
888dde65 | 1870 | void wxWindowDCImpl::Clear() |
c801d85f | 1871 | { |
ab171e95 | 1872 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1873 | |
888dde65 | 1874 | if (!m_gdkwindow) return; |
7d5af6fa | 1875 | |
f60e7fdd | 1876 | int width,height; |
ab171e95 | 1877 | DoGetSize( &width, &height ); |
888dde65 | 1878 | gdk_draw_rectangle( m_gdkwindow, m_bgGC, TRUE, 0, 0, width, height ); |
903f689b | 1879 | } |
c801d85f | 1880 | |
888dde65 | 1881 | void wxWindowDCImpl::SetFont( const wxFont &font ) |
c801d85f | 1882 | { |
265898fd | 1883 | m_font = font; |
ab9d0a8c | 1884 | |
ab171e95 | 1885 | if (m_font.IsOk()) |
2b5f62a0 | 1886 | { |
cfcc3932 RR |
1887 | if (m_fontdesc) |
1888 | pango_font_description_free( m_fontdesc ); | |
ab9d0a8c | 1889 | |
cfcc3932 | 1890 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
ab9d0a8c WS |
1891 | |
1892 | ||
888dde65 | 1893 | if (m_window) |
77416abd | 1894 | { |
cfcc3932 | 1895 | PangoContext *oldContext = m_context; |
ab9d0a8c | 1896 | |
888dde65 | 1897 | m_context = m_window->GtkGetPangoDefaultContext(); |
ab9d0a8c | 1898 | |
cfcc3932 RR |
1899 | // If we switch back/forth between different contexts |
1900 | // we also have to create a new layout. I think so, | |
ab9d0a8c | 1901 | // at least, and it doesn't hurt to do it. |
cfcc3932 RR |
1902 | if (oldContext != m_context) |
1903 | { | |
1904 | if (m_layout) | |
3fe39b0c | 1905 | g_object_unref (m_layout); |
ab9d0a8c | 1906 | |
cfcc3932 RR |
1907 | m_layout = pango_layout_new( m_context ); |
1908 | } | |
77416abd | 1909 | } |
ab9d0a8c | 1910 | |
cfcc3932 | 1911 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
2b5f62a0 | 1912 | } |
903f689b | 1913 | } |
c801d85f | 1914 | |
888dde65 | 1915 | void wxWindowDCImpl::SetPen( const wxPen &pen ) |
c801d85f | 1916 | { |
ab171e95 | 1917 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 1918 | |
265898fd | 1919 | if (m_pen == pen) return; |
7d5af6fa | 1920 | |
265898fd | 1921 | m_pen = pen; |
7d5af6fa | 1922 | |
ab171e95 | 1923 | if (!m_pen.IsOk()) return; |
7d5af6fa | 1924 | |
888dde65 | 1925 | if (!m_gdkwindow) return; |
7d5af6fa | 1926 | |
265898fd | 1927 | gint width = m_pen.GetWidth(); |
265898fd RR |
1928 | if (width <= 0) |
1929 | { | |
112c5086 | 1930 | // CMB: if width is non-zero scale it with the dc |
265898fd RR |
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 | |
503f414e VZ |
1937 | double w = 0.5 + |
1938 | ( fabs((double) XLOG2DEVREL(width)) + | |
1939 | fabs((double) YLOG2DEVREL(width)) ) / 2.0; | |
265898fd | 1940 | width = (int)w; |
375fc5a9 VZ |
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 | } | |
265898fd | 1947 | } |
7d5af6fa | 1948 | |
2eca425d RL |
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}; | |
7d5af6fa | 1953 | |
112c5086 RR |
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; | |
2eca425d | 1957 | const wxGTKDash *req_dash; |
7d5af6fa | 1958 | |
265898fd RR |
1959 | GdkLineStyle lineStyle = GDK_LINE_SOLID; |
1960 | switch (m_pen.GetStyle()) | |
1961 | { | |
112c5086 | 1962 | case wxUSER_DASH: |
7d5af6fa VZ |
1963 | { |
1964 | lineStyle = GDK_LINE_ON_OFF_DASH; | |
112c5086 | 1965 | req_nb_dash = m_pen.GetDashCount(); |
2eca425d | 1966 | req_dash = (wxGTKDash*)m_pen.GetDash(); |
112c5086 | 1967 | break; |
7d5af6fa VZ |
1968 | } |
1969 | case wxDOT: | |
1970 | { | |
1971 | lineStyle = GDK_LINE_ON_OFF_DASH; | |
112c5086 RR |
1972 | req_nb_dash = 2; |
1973 | req_dash = dotted; | |
7d5af6fa VZ |
1974 | break; |
1975 | } | |
1976 | case wxLONG_DASH: | |
1977 | { | |
1978 | lineStyle = GDK_LINE_ON_OFF_DASH; | |
112c5086 | 1979 | req_nb_dash = 2; |
72cdf4c9 | 1980 | req_dash = wxCoord_dashed; |
7d5af6fa VZ |
1981 | break; |
1982 | } | |
1983 | case wxSHORT_DASH: | |
1984 | { | |
1985 | lineStyle = GDK_LINE_ON_OFF_DASH; | |
112c5086 RR |
1986 | req_nb_dash = 2; |
1987 | req_dash = short_dashed; | |
7d5af6fa VZ |
1988 | break; |
1989 | } | |
1990 | case wxDOT_DASH: | |
1991 | { | |
1992 | // lineStyle = GDK_LINE_DOUBLE_DASH; | |
1993 | lineStyle = GDK_LINE_ON_OFF_DASH; | |
112c5086 RR |
1994 | req_nb_dash = 4; |
1995 | req_dash = dotted_dashed; | |
7d5af6fa VZ |
1996 | break; |
1997 | } | |
1998 | ||
1999 | case wxTRANSPARENT: | |
72174350 | 2000 | case wxSTIPPLE_MASK_OPAQUE: |
7d5af6fa VZ |
2001 | case wxSTIPPLE: |
2002 | case wxSOLID: | |
2003 | default: | |
2004 | { | |
2005 | lineStyle = GDK_LINE_SOLID; | |
2eca425d | 2006 | req_dash = (wxGTKDash*)NULL; |
112c5086 | 2007 | req_nb_dash = 0; |
7d5af6fa VZ |
2008 | break; |
2009 | } | |
265898fd | 2010 | } |
7d5af6fa | 2011 | |
112c5086 RR |
2012 | if (req_dash && req_nb_dash) |
2013 | { | |
2eca425d | 2014 | wxGTKDash *real_req_dash = new wxGTKDash[req_nb_dash]; |
112c5086 RR |
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; | |
2eca425d | 2019 | gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash ); |
112c5086 RR |
2020 | delete[] real_req_dash; |
2021 | } | |
2022 | else | |
2023 | { | |
2024 | // No Memory. We use non-scaled dash pattern... | |
2eca425d | 2025 | gdk_gc_set_dashes( m_penGC, 0, (wxGTKDash*)req_dash, req_nb_dash ); |
112c5086 RR |
2026 | } |
2027 | } | |
7d5af6fa | 2028 | |
265898fd RR |
2029 | GdkCapStyle capStyle = GDK_CAP_ROUND; |
2030 | switch (m_pen.GetCap()) | |
2031 | { | |
265898fd RR |
2032 | case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; } |
2033 | case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; } | |
d4aa3a4b RR |
2034 | case wxCAP_ROUND: |
2035 | default: | |
72174350 | 2036 | { |
d4aa3a4b RR |
2037 | if (width <= 1) |
2038 | { | |
2039 | width = 0; | |
2040 | capStyle = GDK_CAP_NOT_LAST; | |
2041 | } | |
2042 | else | |
2043 | { | |
2044 | capStyle = GDK_CAP_ROUND; | |
2045 | } | |
72174350 | 2046 | break; |
d4aa3a4b | 2047 | } |
265898fd | 2048 | } |
7d5af6fa | 2049 | |
265898fd RR |
2050 | GdkJoinStyle joinStyle = GDK_JOIN_ROUND; |
2051 | switch (m_pen.GetJoin()) | |
2052 | { | |
2053 | case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; } | |
265898fd | 2054 | case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; } |
d4aa3a4b RR |
2055 | case wxJOIN_ROUND: |
2056 | default: { joinStyle = GDK_JOIN_ROUND; break; } | |
265898fd | 2057 | } |
7d5af6fa | 2058 | |
265898fd | 2059 | gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle ); |
7d5af6fa | 2060 | |
265898fd RR |
2061 | m_pen.GetColour().CalcPixel( m_cmap ); |
2062 | gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() ); | |
903f689b | 2063 | } |
c801d85f | 2064 | |
888dde65 | 2065 | void wxWindowDCImpl::SetBrush( const wxBrush &brush ) |
c801d85f | 2066 | { |
ab171e95 | 2067 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2068 | |
265898fd | 2069 | if (m_brush == brush) return; |
7d5af6fa | 2070 | |
265898fd | 2071 | m_brush = brush; |
7d5af6fa | 2072 | |
ab171e95 | 2073 | if (!m_brush.IsOk()) return; |
7d5af6fa | 2074 | |
888dde65 | 2075 | if (!m_gdkwindow) return; |
7d5af6fa | 2076 | |
265898fd RR |
2077 | m_brush.GetColour().CalcPixel( m_cmap ); |
2078 | gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() ); | |
7d5af6fa | 2079 | |
956dbab1 | 2080 | gdk_gc_set_fill( m_brushGC, GDK_SOLID ); |
7d5af6fa | 2081 | |
ab171e95 | 2082 | if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->IsOk())) |
265898fd | 2083 | { |
b85229d1 | 2084 | if (m_brush.GetStipple()->GetDepth() != 1) |
7d5af6fa | 2085 | { |
956dbab1 | 2086 | gdk_gc_set_fill( m_brushGC, GDK_TILED ); |
cd25b18c | 2087 | gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() ); |
7d5af6fa | 2088 | } |
b0e0d661 | 2089 | else |
7d5af6fa | 2090 | { |
956dbab1 | 2091 | gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); |
b85229d1 | 2092 | gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() ); |
7d5af6fa | 2093 | } |
265898fd | 2094 | } |
7d5af6fa | 2095 | |
de2d2cdc VZ |
2096 | if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) |
2097 | { | |
e1208c31 RR |
2098 | gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); |
2099 | gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); | |
de2d2cdc VZ |
2100 | } |
2101 | ||
ab9d0a8c | 2102 | if (m_brush.IsHatch()) |
265898fd | 2103 | { |
956dbab1 | 2104 | gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); |
265898fd RR |
2105 | int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH; |
2106 | gdk_gc_set_stipple( m_brushGC, hatches[num] ); | |
2107 | } | |
903f689b | 2108 | } |
c801d85f | 2109 | |
888dde65 | 2110 | void wxWindowDCImpl::SetBackground( const wxBrush &brush ) |
46dc76ba | 2111 | { |
bbbbe360 RR |
2112 | /* CMB 21/7/98: Added SetBackground. Sets background brush |
2113 | * for Clear() and bg colour for shapes filled with cross-hatch brush */ | |
7d5af6fa | 2114 | |
ab171e95 | 2115 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2116 | |
265898fd | 2117 | if (m_backgroundBrush == brush) return; |
7d5af6fa | 2118 | |
265898fd | 2119 | m_backgroundBrush = brush; |
7d5af6fa | 2120 | |
ab171e95 | 2121 | if (!m_backgroundBrush.IsOk()) return; |
7d5af6fa | 2122 | |
888dde65 | 2123 | if (!m_gdkwindow) return; |
7d5af6fa | 2124 | |
265898fd RR |
2125 | m_backgroundBrush.GetColour().CalcPixel( m_cmap ); |
2126 | gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() ); | |
a802c3a1 | 2127 | gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() ); |
031b2a7b | 2128 | gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); |
265898fd | 2129 | gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); |
3417c2cd RR |
2130 | |
2131 | gdk_gc_set_fill( m_bgGC, GDK_SOLID ); | |
7d5af6fa | 2132 | |
ab171e95 | 2133 | if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->IsOk())) |
265898fd | 2134 | { |
b85229d1 | 2135 | if (m_backgroundBrush.GetStipple()->GetDepth() != 1) |
7d5af6fa | 2136 | { |
3417c2cd | 2137 | gdk_gc_set_fill( m_bgGC, GDK_TILED ); |
fd128b0c | 2138 | gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() ); |
7d5af6fa | 2139 | } |
cd25b18c | 2140 | else |
7d5af6fa | 2141 | { |
3417c2cd | 2142 | gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); |
b85229d1 | 2143 | gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() ); |
7d5af6fa | 2144 | } |
265898fd | 2145 | } |
7d5af6fa | 2146 | |
ab9d0a8c | 2147 | if (m_backgroundBrush.IsHatch()) |
265898fd | 2148 | { |
3417c2cd | 2149 | gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); |
265898fd RR |
2150 | int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH; |
2151 | gdk_gc_set_stipple( m_bgGC, hatches[num] ); | |
bbbbe360 | 2152 | } |
903f689b | 2153 | } |
46dc76ba | 2154 | |
888dde65 | 2155 | void wxWindowDCImpl::SetLogicalFunction( int function ) |
c801d85f | 2156 | { |
ab171e95 | 2157 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2158 | |
72174350 VZ |
2159 | if (m_logicalFunction == function) |
2160 | return; | |
2161 | ||
2162 | // VZ: shouldn't this be a CHECK? | |
888dde65 | 2163 | if (!m_gdkwindow) |
72174350 | 2164 | return; |
01eaf507 | 2165 | |
2b5f62a0 | 2166 | GdkFunction mode; |
265898fd RR |
2167 | switch (function) |
2168 | { | |
3c679789 RR |
2169 | case wxXOR: mode = GDK_XOR; break; |
2170 | case wxINVERT: mode = GDK_INVERT; break; | |
3c679789 RR |
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; | |
7d5af6fa VZ |
2181 | case wxCOPY: mode = GDK_COPY; break; |
2182 | case wxNO_OP: mode = GDK_NOOP; break; | |
2183 | case wxSRC_INVERT: mode = GDK_COPY_INVERT; break; | |
72174350 | 2184 | |
2d52841d RR |
2185 | // unsupported by GTK |
2186 | case wxNOR: mode = GDK_COPY; break; | |
01eaf507 | 2187 | default: |
223d09f6 | 2188 | wxFAIL_MSG( wxT("unsupported logical function") ); |
2b5f62a0 | 2189 | mode = GDK_COPY; |
265898fd | 2190 | } |
7d5af6fa | 2191 | |
265898fd | 2192 | m_logicalFunction = function; |
7d5af6fa | 2193 | |
265898fd RR |
2194 | gdk_gc_set_function( m_penGC, mode ); |
2195 | gdk_gc_set_function( m_brushGC, mode ); | |
72174350 VZ |
2196 | |
2197 | // to stay compatible with wxMSW, we don't apply ROPs to the text | |
3d2d8da1 RR |
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 ); | |
903f689b | 2201 | } |
c801d85f | 2202 | |
888dde65 | 2203 | void wxWindowDCImpl::SetTextForeground( const wxColour &col ) |
c801d85f | 2204 | { |
ab171e95 | 2205 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2206 | |
71ec83d2 VZ |
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) | |
ab171e95 | 2210 | if ( !col.IsOk() || (m_textForegroundColour == col) ) |
71ec83d2 | 2211 | return; |
7d5af6fa | 2212 | |
265898fd | 2213 | m_textForegroundColour = col; |
7d5af6fa | 2214 | |
888dde65 | 2215 | if ( m_gdkwindow ) |
71ec83d2 VZ |
2216 | { |
2217 | m_textForegroundColour.CalcPixel( m_cmap ); | |
2218 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
2219 | } | |
903f689b | 2220 | } |
c801d85f | 2221 | |
888dde65 | 2222 | void wxWindowDCImpl::SetTextBackground( const wxColour &col ) |
c801d85f | 2223 | { |
ab171e95 | 2224 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2225 | |
71ec83d2 | 2226 | // same as above |
ab171e95 | 2227 | if ( !col.IsOk() || (m_textBackgroundColour == col) ) |
71ec83d2 | 2228 | return; |
7d5af6fa | 2229 | |
265898fd | 2230 | m_textBackgroundColour = col; |
7d5af6fa | 2231 | |
888dde65 | 2232 | if ( m_gdkwindow ) |
71ec83d2 VZ |
2233 | { |
2234 | m_textBackgroundColour.CalcPixel( m_cmap ); | |
2235 | gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); | |
2236 | } | |
903f689b | 2237 | } |
c801d85f | 2238 | |
888dde65 | 2239 | void wxWindowDCImpl::SetBackgroundMode( int mode ) |
c801d85f | 2240 | { |
ab171e95 | 2241 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2242 | |
265898fd | 2243 | m_backgroundMode = mode; |
46dc76ba | 2244 | |
888dde65 | 2245 | if (!m_gdkwindow) return; |
7d5af6fa | 2246 | |
265898fd RR |
2247 | // CMB 21/7/98: fill style of cross-hatch brushes is affected by |
2248 | // transparent/solid background mode | |
7d5af6fa | 2249 | |
265898fd RR |
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 | } | |
903f689b | 2255 | } |
c801d85f | 2256 | |
888dde65 | 2257 | void wxWindowDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) ) |
c801d85f | 2258 | { |
888dde65 | 2259 | wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") ); |
903f689b | 2260 | } |
c801d85f | 2261 | |
888dde65 | 2262 | void wxWindowDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 2263 | { |
ab171e95 | 2264 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2265 | |
888dde65 | 2266 | if (!m_gdkwindow) return; |
7d5af6fa | 2267 | |
3d2d8da1 | 2268 | wxRect rect; |
265898fd RR |
2269 | rect.x = XLOG2DEV(x); |
2270 | rect.y = YLOG2DEV(y); | |
2271 | rect.width = XLOG2DEVREL(width); | |
2272 | rect.height = YLOG2DEVREL(height); | |
5f170f33 | 2273 | |
888dde65 RR |
2274 | if (m_window && m_window->m_wxwindow && |
2275 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) | |
49e74855 RR |
2276 | { |
2277 | rect.x -= rect.width; | |
2278 | } | |
2279 | ||
e1208c31 | 2280 | if (!m_currentClippingRegion.IsNull()) |
993f97ee RR |
2281 | m_currentClippingRegion.Intersect( rect ); |
2282 | else | |
2283 | m_currentClippingRegion.Union( rect ); | |
5f170f33 VZ |
2284 | |
2285 | #if USE_PAINT_REGION | |
e1208c31 | 2286 | if (!m_paintClippingRegion.IsNull()) |
3d2d8da1 | 2287 | m_currentClippingRegion.Intersect( m_paintClippingRegion ); |
809934d2 | 2288 | #endif |
3d2d8da1 | 2289 | |
ee8dbe63 RL |
2290 | wxCoord xx, yy, ww, hh; |
2291 | m_currentClippingRegion.GetBox( xx, yy, ww, hh ); | |
ab171e95 | 2292 | #if wxUSE_NEW_DC |
888dde65 | 2293 | wxGTKDCImpl::DoSetClippingRegion( xx, yy, ww, hh ); |
ab171e95 | 2294 | #else |
ee8dbe63 | 2295 | wxDC::DoSetClippingRegion( xx, yy, ww, hh ); |
ab171e95 | 2296 | #endif |
ee8dbe63 | 2297 | |
3d2d8da1 RR |
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() ); | |
903f689b | 2302 | } |
c801d85f | 2303 | |
888dde65 | 2304 | void wxWindowDCImpl::DoSetClippingRegionAsRegion( const wxRegion ®ion ) |
463c1fa1 | 2305 | { |
ab171e95 | 2306 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2307 | |
463c1fa1 RR |
2308 | if (region.Empty()) |
2309 | { | |
2310 | DestroyClippingRegion(); | |
2311 | return; | |
2312 | } | |
7d5af6fa | 2313 | |
888dde65 | 2314 | if (!m_gdkwindow) return; |
5f170f33 | 2315 | |
e1208c31 | 2316 | if (!m_currentClippingRegion.IsNull()) |
993f97ee RR |
2317 | m_currentClippingRegion.Intersect( region ); |
2318 | else | |
2319 | m_currentClippingRegion.Union( region ); | |
5f170f33 VZ |
2320 | |
2321 | #if USE_PAINT_REGION | |
e1208c31 | 2322 | if (!m_paintClippingRegion.IsNull()) |
3d2d8da1 | 2323 | m_currentClippingRegion.Intersect( m_paintClippingRegion ); |
809934d2 | 2324 | #endif |
3d2d8da1 | 2325 | |
ee8dbe63 RL |
2326 | wxCoord xx, yy, ww, hh; |
2327 | m_currentClippingRegion.GetBox( xx, yy, ww, hh ); | |
ab171e95 | 2328 | #if wxUSE_NEW_DC |
888dde65 | 2329 | wxGTKDCImpl::DoSetClippingRegion( xx, yy, ww, hh ); |
ab171e95 | 2330 | #else |
ee8dbe63 | 2331 | wxDC::DoSetClippingRegion( xx, yy, ww, hh ); |
ab171e95 | 2332 | #endif |
ee8dbe63 | 2333 | |
3d2d8da1 RR |
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() ); | |
463c1fa1 RR |
2338 | } |
2339 | ||
888dde65 | 2340 | void wxWindowDCImpl::DestroyClippingRegion() |
c801d85f | 2341 | { |
ab171e95 | 2342 | wxCHECK_RET( IsOk(), wxT("invalid window dc") ); |
7d5af6fa | 2343 | |
ab171e95 | 2344 | #if wxUSE_NEW_DC |
888dde65 | 2345 | wxDCImpl::DestroyClippingRegion(); |
ab171e95 | 2346 | #else |
265898fd | 2347 | wxDC::DestroyClippingRegion(); |
ab171e95 | 2348 | #endif |
7d5af6fa | 2349 | |
3d2d8da1 | 2350 | m_currentClippingRegion.Clear(); |
5f170f33 VZ |
2351 | |
2352 | #if USE_PAINT_REGION | |
3d2d8da1 RR |
2353 | if (!m_paintClippingRegion.IsEmpty()) |
2354 | m_currentClippingRegion.Union( m_paintClippingRegion ); | |
993f97ee | 2355 | #endif |
3d2d8da1 | 2356 | |
888dde65 | 2357 | if (!m_gdkwindow) return; |
7d5af6fa | 2358 | |
3d2d8da1 RR |
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 | } | |
903f689b | 2373 | } |
c801d85f | 2374 | |
888dde65 | 2375 | void wxWindowDCImpl::Destroy() |
dbf858b5 | 2376 | { |
3d2d8da1 | 2377 | if (m_penGC) wxFreePoolGC( m_penGC ); |
265898fd | 2378 | m_penGC = (GdkGC*) NULL; |
3d2d8da1 | 2379 | if (m_brushGC) wxFreePoolGC( m_brushGC ); |
265898fd | 2380 | m_brushGC = (GdkGC*) NULL; |
3d2d8da1 | 2381 | if (m_textGC) wxFreePoolGC( m_textGC ); |
265898fd | 2382 | m_textGC = (GdkGC*) NULL; |
3d2d8da1 | 2383 | if (m_bgGC) wxFreePoolGC( m_bgGC ); |
265898fd | 2384 | m_bgGC = (GdkGC*) NULL; |
dbf858b5 RR |
2385 | } |
2386 | ||
888dde65 | 2387 | void wxWindowDCImpl::SetDeviceOrigin( wxCoord x, wxCoord y ) |
847dfdb4 RR |
2388 | { |
2389 | m_deviceOriginX = x; | |
2390 | m_deviceOriginY = y; | |
f4322df6 | 2391 | |
847dfdb4 RR |
2392 | ComputeScaleAndOrigin(); |
2393 | } | |
2394 | ||
888dde65 | 2395 | void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
847dfdb4 RR |
2396 | { |
2397 | m_signX = (xLeftRight ? 1 : -1); | |
2398 | m_signY = (yBottomUp ? -1 : 1); | |
f4322df6 | 2399 | |
888dde65 RR |
2400 | if (m_window && m_window->m_wxwindow && |
2401 | (m_window->GetLayoutDirection() == wxLayout_RightToLeft)) | |
f4322df6 VZ |
2402 | m_signX = -m_signX; |
2403 | ||
847dfdb4 RR |
2404 | ComputeScaleAndOrigin(); |
2405 | } | |
2406 | ||
888dde65 | 2407 | void wxWindowDCImpl::ComputeScaleAndOrigin() |
238d735d | 2408 | { |
c77a6796 | 2409 | const wxRealPoint origScale(m_scaleX, m_scaleY); |
238d735d | 2410 | |
ab171e95 | 2411 | #if wxUSE_NEW_DC |
888dde65 | 2412 | wxDCImpl::ComputeScaleAndOrigin(); |
ab171e95 | 2413 | #else |
238d735d | 2414 | wxDC::ComputeScaleAndOrigin(); |
ab171e95 | 2415 | #endif |
238d735d | 2416 | |
c77a6796 | 2417 | // if scale has changed call SetPen to recalulate the line width |
ab171e95 | 2418 | if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.IsOk() ) |
238d735d | 2419 | { |
c77a6796 VZ |
2420 | // this is a bit artificial, but we need to force wxDC to think the pen |
2421 | // has changed | |
0a164d4c WS |
2422 | wxPen pen = m_pen; |
2423 | m_pen = wxNullPen; | |
2424 | SetPen( pen ); | |
2425 | } | |
238d735d RR |
2426 | } |
2427 | ||
b0e0d661 | 2428 | // Resolution in pixels per logical inch |
888dde65 | 2429 | wxSize wxWindowDCImpl::GetPPI() const |
b0e0d661 | 2430 | { |
7a5e6267 | 2431 | return wxSize( (int) (m_mm_to_pix_x * 25.4 + 0.5), (int) (m_mm_to_pix_y * 25.4 + 0.5)); |
b0e0d661 VZ |
2432 | } |
2433 | ||
888dde65 | 2434 | int wxWindowDCImpl::GetDepth() const |
c801d85f | 2435 | { |
888dde65 | 2436 | return gdk_drawable_get_depth(m_gdkwindow); |
903f689b | 2437 | } |
c801d85f | 2438 | |
ec758a20 | 2439 | |
ab171e95 | 2440 | //----------------------------------------------------------------------------- |
888dde65 | 2441 | // wxClientDCImpl |
ab171e95 RR |
2442 | //----------------------------------------------------------------------------- |
2443 | ||
888dde65 | 2444 | IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl) |
ab171e95 | 2445 | |
888dde65 RR |
2446 | wxClientDCImpl::wxClientDCImpl( wxDC *owner ) |
2447 | : wxWindowDCImpl( owner ) | |
ab171e95 RR |
2448 | { |
2449 | } | |
2450 | ||
888dde65 RR |
2451 | wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *win ) |
2452 | : wxWindowDCImpl( owner, win ) | |
ab171e95 | 2453 | { |
888dde65 | 2454 | wxCHECK_RET( win, _T("NULL window in wxClientDCImpl::wxClientDC") ); |
ab171e95 RR |
2455 | |
2456 | #ifdef __WXUNIVERSAL__ | |
2457 | wxPoint ptOrigin = win->GetClientAreaOrigin(); | |
2458 | SetDeviceOrigin(ptOrigin.x, ptOrigin.y); | |
2459 | wxSize size = win->GetClientSize(); | |
6267c3ea | 2460 | DoSetClippingRegion(0, 0, size.x, size.y); |
888dde65 RR |
2461 | #endif |
2462 | // __WXUNIVERSAL__ | |
ab171e95 RR |
2463 | } |
2464 | ||
888dde65 | 2465 | void wxClientDCImpl::DoGetSize(int *width, int *height) const |
ab171e95 | 2466 | { |
888dde65 | 2467 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); |
ab171e95 | 2468 | |
888dde65 | 2469 | m_window->GetClientSize( width, height ); |
ab171e95 RR |
2470 | } |
2471 | ||
ec758a20 | 2472 | //----------------------------------------------------------------------------- |
888dde65 | 2473 | // wxPaintDCImpl |
ec758a20 RR |
2474 | //----------------------------------------------------------------------------- |
2475 | ||
888dde65 | 2476 | IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxClientDCImpl) |
ec758a20 | 2477 | |
2cfddfe7 JS |
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 | ||
888dde65 RR |
2497 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner ) |
2498 | : wxClientDCImpl( owner ) | |
ab171e95 RR |
2499 | { |
2500 | } | |
2501 | ||
888dde65 RR |
2502 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *win ) |
2503 | : wxClientDCImpl( owner, win ) | |
ec758a20 | 2504 | { |
b6fa52db RR |
2505 | #if USE_PAINT_REGION |
2506 | if (!win->m_clipPaintRegion) | |
2507 | return; | |
f469b27c | 2508 | |
2cfddfe7 | 2509 | wxSize sz = win->GetSize(); |
bcb614b3 | 2510 | m_paintClippingRegion = win->m_nativeUpdateRegion; |
2cfddfe7 | 2511 | wxLimitRegionToSize(m_paintClippingRegion, sz); |
ab9d0a8c | 2512 | |
5f170f33 VZ |
2513 | GdkRegion *region = m_paintClippingRegion.GetRegion(); |
2514 | if ( region ) | |
2515 | { | |
823faac3 | 2516 | m_currentClippingRegion.Union( m_paintClippingRegion ); |
2cfddfe7 JS |
2517 | wxLimitRegionToSize(m_currentClippingRegion, sz); |
2518 | ||
2519 | if (sz.x <= 0 || sz.y <= 0) | |
2520 | return ; | |
5f170f33 | 2521 | |
823faac3 JS |
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 ); | |
5f170f33 | 2526 | } |
888dde65 | 2527 | #endif |
ec758a20 RR |
2528 | } |
2529 | ||
3d2d8da1 RR |
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(); | |
ab9d0a8c | 2549 | return true; |
3d2d8da1 RR |
2550 | } |
2551 | ||
2552 | void wxDCModule::OnExit() | |
2553 | { | |
2554 | wxCleanUpGCPool(); | |
2555 | } |