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