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