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