~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gdk/win32/gdkgc-win32.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GDK - The GIMP Drawing Kit
 
2
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 
3
 * Copyright (C) 1998-2004 Tor Lillqvist
 
4
 * Copyright (C) 2000-2004 Hans Breuer
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the
 
18
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
19
 * Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
/*
 
23
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
 
24
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 
25
 * files for a list of changes.  These files are distributed with
 
26
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 
27
 */
 
28
 
 
29
#define LINE_ATTRIBUTES (GDK_GC_LINE_WIDTH|GDK_GC_LINE_STYLE| \
 
30
                         GDK_GC_CAP_STYLE|GDK_GC_JOIN_STYLE)
 
31
 
 
32
#include <config.h>
 
33
#include <string.h>
 
34
 
 
35
#include "gdkgc.h"
 
36
#include "gdkfont.h"
 
37
#include "gdkpixmap.h"
 
38
#include "gdkregion-generic.h"
 
39
#include "gdkprivate-win32.h"
 
40
 
 
41
static void gdk_win32_gc_get_values (GdkGC           *gc,
 
42
                                     GdkGCValues     *values);
 
43
static void gdk_win32_gc_set_values (GdkGC           *gc,
 
44
                                     GdkGCValues     *values,
 
45
                                     GdkGCValuesMask  values_mask);
 
46
static void gdk_win32_gc_set_dashes (GdkGC           *gc,
 
47
                                     gint             dash_offset,
 
48
                                     gint8            dash_list[],
 
49
                                     gint             n);
 
50
 
 
51
static void gdk_gc_win32_class_init (GdkGCWin32Class *klass);
 
52
static void gdk_gc_win32_finalize   (GObject         *object);
 
53
 
 
54
static gpointer parent_class = NULL;
 
55
 
 
56
GType
 
57
_gdk_gc_win32_get_type (void)
 
58
{
 
59
  static GType object_type = 0;
 
60
 
 
61
  if (!object_type)
 
62
    {
 
63
      static const GTypeInfo object_info =
 
64
      {
 
65
        sizeof (GdkGCWin32Class),
 
66
        (GBaseInitFunc) NULL,
 
67
        (GBaseFinalizeFunc) NULL,
 
68
        (GClassInitFunc) gdk_gc_win32_class_init,
 
69
        NULL,           /* class_finalize */
 
70
        NULL,           /* class_data */
 
71
        sizeof (GdkGCWin32),
 
72
        0,              /* n_preallocs */
 
73
        (GInstanceInitFunc) NULL,
 
74
      };
 
75
      
 
76
      object_type = g_type_register_static (GDK_TYPE_GC,
 
77
                                            "GdkGCWin32",
 
78
                                            &object_info, 0);
 
79
    }
 
80
  
 
81
  return object_type;
 
82
}
 
83
 
 
84
static void
 
85
gdk_gc_win32_class_init (GdkGCWin32Class *klass)
 
86
{
 
87
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
88
  GdkGCClass *gc_class = GDK_GC_CLASS (klass);
 
89
  
 
90
  parent_class = g_type_class_peek_parent (klass);
 
91
 
 
92
  object_class->finalize = gdk_gc_win32_finalize;
 
93
 
 
94
  gc_class->get_values = gdk_win32_gc_get_values;
 
95
  gc_class->set_values = gdk_win32_gc_set_values;
 
96
  gc_class->set_dashes = gdk_win32_gc_set_dashes;
 
97
}
 
98
 
 
99
static void
 
100
gdk_gc_win32_finalize (GObject *object)
 
101
{
 
102
  GdkGCWin32 *win32_gc = GDK_GC_WIN32 (object);
 
103
  
 
104
  if (win32_gc->hcliprgn != NULL)
 
105
    DeleteObject (win32_gc->hcliprgn);
 
106
  
 
107
  if (win32_gc->values_mask & GDK_GC_FONT)
 
108
    gdk_font_unref (win32_gc->font);
 
109
  
 
110
  if (win32_gc->pen_dashes)
 
111
    g_free (win32_gc->pen_dashes);
 
112
  
 
113
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
114
}
 
115
 
 
116
static void
 
117
fixup_pen (GdkGCWin32 *win32_gc)
 
118
{
 
119
  win32_gc->pen_style = 0;
 
120
 
 
121
  /* First look at GDK width and end cap style, set GDI pen type and
 
122
   * end cap.
 
123
   */
 
124
  if (win32_gc->pen_width == 0 &&
 
125
      win32_gc->cap_style == GDK_CAP_NOT_LAST)
 
126
    {
 
127
      /* Use a cosmetic pen, always width 1 */
 
128
      win32_gc->pen_style |= PS_COSMETIC;
 
129
    }
 
130
  else if (win32_gc->pen_width <= 1 &&
 
131
           win32_gc->cap_style == GDK_CAP_BUTT)
 
132
    {
 
133
      /* For 1 pixel wide lines PS_ENDCAP_ROUND means draw both ends,
 
134
       * even for one pixel length lines. But if we are drawing dashed
 
135
       * lines we can't use PS_ENDCAP_ROUND.
 
136
       */
 
137
      if (win32_gc->line_style == GDK_LINE_SOLID)
 
138
        win32_gc->pen_style |= PS_GEOMETRIC | PS_ENDCAP_ROUND;
 
139
      else
 
140
        win32_gc->pen_style |= PS_GEOMETRIC | PS_ENDCAP_FLAT;
 
141
    }
 
142
  else
 
143
    {
 
144
      win32_gc->pen_style |= PS_GEOMETRIC;
 
145
      switch (win32_gc->cap_style)
 
146
        {
 
147
        /* For non-zero-width lines X11's CapNotLast works like CapButt */
 
148
        case GDK_CAP_NOT_LAST:
 
149
        case GDK_CAP_BUTT:
 
150
          win32_gc->pen_style |= PS_ENDCAP_FLAT;
 
151
          break;
 
152
        case GDK_CAP_ROUND:
 
153
          win32_gc->pen_style |= PS_ENDCAP_ROUND;
 
154
          break;
 
155
        case GDK_CAP_PROJECTING:
 
156
          win32_gc->pen_style |= PS_ENDCAP_SQUARE;
 
157
          break;
 
158
        }
 
159
    }
 
160
 
 
161
  /* Next look at GDK line style, set GDI pen style attribute */
 
162
  switch (win32_gc->line_style)
 
163
    {
 
164
    case GDK_LINE_SOLID:
 
165
      win32_gc->pen_style |= PS_SOLID;
 
166
      break;
 
167
    case GDK_LINE_ON_OFF_DASH:
 
168
    case GDK_LINE_DOUBLE_DASH:
 
169
      if (win32_gc->pen_dashes == NULL)
 
170
        {
 
171
          win32_gc->pen_dashes = g_new (DWORD, 1);
 
172
          win32_gc->pen_dashes[0] = 4;
 
173
          win32_gc->pen_num_dashes = 1;
 
174
        }
 
175
      if (G_WIN32_IS_NT_BASED ())
 
176
        {
 
177
          if (!(win32_gc->pen_style & PS_TYPE_MASK) == PS_GEOMETRIC &&
 
178
              win32_gc->pen_dashes[0] == 1 &&
 
179
              (win32_gc->pen_num_dashes == 1 ||
 
180
               (win32_gc->pen_num_dashes == 2 && win32_gc->pen_dashes[0] == 1)))
 
181
            win32_gc->pen_style |= PS_ALTERNATE;
 
182
          else
 
183
            win32_gc->pen_style |= PS_USERSTYLE;
 
184
        }
 
185
      else
 
186
        {
 
187
          /* Render "short" on-off dashes drawn with R2_COPYPEN and a
 
188
           * cosmetic pen using PS_DOT
 
189
           */
 
190
          if (win32_gc->line_style == GDK_LINE_ON_OFF_DASH &&
 
191
              win32_gc->rop2 == R2_COPYPEN &&
 
192
              (win32_gc->pen_style & PS_TYPE_MASK) == PS_COSMETIC &&
 
193
              win32_gc->pen_dashes[0] <= 2 &&
 
194
              (win32_gc->pen_num_dashes == 1 ||
 
195
               (win32_gc->pen_num_dashes == 2 && win32_gc->pen_dashes[1] <= 2)))
 
196
            win32_gc->pen_style |= PS_DOT;
 
197
          else
 
198
            /* Otherwise render opaque lines solid, horizontal or
 
199
             * vertical ones will be dashed manually, see
 
200
             * gdkdrawable-win32.c.
 
201
             */
 
202
            win32_gc->pen_style |= PS_SOLID;
 
203
        }
 
204
     break;
 
205
    }
 
206
 
 
207
  /* Last, for if the GDI pen is geometric, set the join attribute */
 
208
  if ((win32_gc->pen_style & PS_TYPE_MASK) == PS_GEOMETRIC)
 
209
    {
 
210
      switch (win32_gc->join_style)
 
211
        {
 
212
        case GDK_JOIN_MITER:
 
213
          win32_gc->pen_style |= PS_JOIN_MITER;
 
214
          break;
 
215
        case GDK_JOIN_ROUND:
 
216
          win32_gc->pen_style |= PS_JOIN_ROUND;
 
217
          break;
 
218
        case GDK_JOIN_BEVEL:
 
219
          win32_gc->pen_style |= PS_JOIN_BEVEL;
 
220
          break;
 
221
        }
 
222
    }
 
223
}
 
224
 
 
225
static void
 
226
gdk_win32_gc_values_to_win32values (GdkGCValues    *values,
 
227
                                    GdkGCValuesMask mask,
 
228
                                    GdkGCWin32     *win32_gc)
 
229
{                                   
 
230
  char *s = "";
 
231
 
 
232
  GDK_NOTE (GC, g_print ("{"));
 
233
 
 
234
  if (mask & GDK_GC_FOREGROUND)
 
235
    {
 
236
      win32_gc->values_mask |= GDK_GC_FOREGROUND;
 
237
      GDK_NOTE (GC, (g_print ("fg=%.06x",
 
238
                              _gdk_gc_get_fg_pixel (&win32_gc->parent_instance)),
 
239
                     s = ","));
 
240
    }
 
241
  
 
242
  if (mask & GDK_GC_BACKGROUND)
 
243
    {
 
244
      win32_gc->values_mask |= GDK_GC_BACKGROUND;
 
245
      GDK_NOTE (GC, (g_print ("%sbg=%.06x", s,
 
246
                              _gdk_gc_get_bg_pixel (&win32_gc->parent_instance)),
 
247
                     s = ","));
 
248
    }
 
249
 
 
250
  if ((mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT
 
251
                               || values->font->type == GDK_FONT_FONTSET))
 
252
    {
 
253
      if (win32_gc->font != NULL)
 
254
        gdk_font_unref (win32_gc->font);
 
255
      win32_gc->font = values->font;
 
256
      if (win32_gc->font != NULL)
 
257
        {
 
258
          gdk_font_ref (win32_gc->font);
 
259
          win32_gc->values_mask |= GDK_GC_FONT;
 
260
          GDK_NOTE (GC, (g_print ("%sfont=%p", s, win32_gc->font),
 
261
                         s = ","));
 
262
        }
 
263
      else
 
264
        {
 
265
          win32_gc->values_mask &= ~GDK_GC_FONT;
 
266
          GDK_NOTE (GC, (g_print ("%sfont=NULL", s),
 
267
                         s = ","));
 
268
        }
 
269
    }
 
270
 
 
271
  if (mask & GDK_GC_FUNCTION)
 
272
    {
 
273
      GDK_NOTE (GC, (g_print ("%srop2=", s),
 
274
                     s = ","));
 
275
      switch (values->function)
 
276
        {
 
277
#define CASE(x,y) case GDK_##x: win32_gc->rop2 = R2_##y; GDK_NOTE (GC, g_print (#y)); break
 
278
        CASE (COPY, COPYPEN);
 
279
        CASE (INVERT, NOT);
 
280
        CASE (XOR, XORPEN);
 
281
        CASE (CLEAR, BLACK);
 
282
        CASE (AND, MASKPEN);
 
283
        CASE (AND_REVERSE, MASKPENNOT);
 
284
        CASE (AND_INVERT, MASKNOTPEN);
 
285
        CASE (NOOP, NOP);
 
286
        CASE (OR, MERGEPEN);
 
287
        CASE (EQUIV, NOTXORPEN);
 
288
        CASE (OR_REVERSE, MERGEPENNOT);
 
289
        CASE (COPY_INVERT, NOTCOPYPEN);
 
290
        CASE (OR_INVERT, MERGENOTPEN);
 
291
        CASE (NAND, NOTMASKPEN);
 
292
        CASE (NOR, NOTMERGEPEN);
 
293
        CASE (SET, WHITE);
 
294
#undef CASE
 
295
        }
 
296
      win32_gc->values_mask |= GDK_GC_FUNCTION;
 
297
    }
 
298
 
 
299
  if (mask & GDK_GC_FILL)
 
300
    {
 
301
      win32_gc->values_mask |= GDK_GC_FILL;
 
302
      GDK_NOTE (GC, (g_print ("%sfill=%s", s,
 
303
                              _gdk_win32_fill_style_to_string (values->fill)),
 
304
                     s = ","));
 
305
    }
 
306
 
 
307
  if (mask & GDK_GC_TILE)
 
308
    {
 
309
      if (values->tile != NULL)
 
310
        {
 
311
          win32_gc->values_mask |= GDK_GC_TILE;
 
312
          GDK_NOTE (GC,
 
313
                    (g_print ("%stile=%p", s,
 
314
                              GDK_PIXMAP_HBITMAP (values->tile)),
 
315
                     s = ","));
 
316
        }
 
317
      else
 
318
        {
 
319
          win32_gc->values_mask &= ~GDK_GC_TILE;
 
320
          GDK_NOTE (GC, (g_print ("%stile=NULL", s),
 
321
                         s = ","));
 
322
        }
 
323
    }
 
324
 
 
325
  if (mask & GDK_GC_STIPPLE)
 
326
    {
 
327
      if (values->stipple != NULL)
 
328
        {
 
329
          win32_gc->values_mask |= GDK_GC_STIPPLE;
 
330
          GDK_NOTE (GC,
 
331
                    (g_print ("%sstipple=%p", s,
 
332
                              GDK_PIXMAP_HBITMAP (values->stipple)),
 
333
                     s = ","));
 
334
        }
 
335
      else
 
336
        {
 
337
          win32_gc->values_mask &= ~GDK_GC_STIPPLE;
 
338
          GDK_NOTE (GC, (g_print ("%sstipple=NULL", s),
 
339
                         s = ","));
 
340
        }
 
341
    }
 
342
 
 
343
  if (mask & GDK_GC_CLIP_MASK)
 
344
    {
 
345
      if (win32_gc->hcliprgn != NULL)
 
346
        DeleteObject (win32_gc->hcliprgn);
 
347
 
 
348
      if (values->clip_mask != NULL)
 
349
        {
 
350
          win32_gc->hcliprgn = _gdk_win32_bitmap_to_hrgn (values->clip_mask);
 
351
          win32_gc->values_mask |= GDK_GC_CLIP_MASK;
 
352
        }
 
353
      else
 
354
        {
 
355
          win32_gc->hcliprgn = NULL;
 
356
          win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
 
357
        }
 
358
      GDK_NOTE (GC, (g_print ("%sclip=%p", s, win32_gc->hcliprgn),
 
359
                     s = ","));
 
360
    }
 
361
 
 
362
  if (mask & GDK_GC_SUBWINDOW)
 
363
    {
 
364
      win32_gc->subwindow_mode = values->subwindow_mode;
 
365
      win32_gc->values_mask |= GDK_GC_SUBWINDOW;
 
366
      GDK_NOTE (GC, (g_print ("%ssubw=%d", s, win32_gc->subwindow_mode),
 
367
                     s = ","));
 
368
    }
 
369
 
 
370
  if (mask & GDK_GC_TS_X_ORIGIN)
 
371
    {
 
372
      win32_gc->values_mask |= GDK_GC_TS_X_ORIGIN;
 
373
      GDK_NOTE (GC, (g_print ("%sts_x=%d", s, values->ts_x_origin),
 
374
                     s = ","));
 
375
    }
 
376
 
 
377
  if (mask & GDK_GC_TS_Y_ORIGIN)
 
378
    {
 
379
      win32_gc->values_mask |= GDK_GC_TS_Y_ORIGIN;
 
380
      GDK_NOTE (GC, (g_print ("%sts_y=%d", s, values->ts_y_origin),
 
381
                     s = ","));
 
382
    }
 
383
 
 
384
  if (mask & GDK_GC_CLIP_X_ORIGIN)
 
385
    {
 
386
      win32_gc->values_mask |= GDK_GC_CLIP_X_ORIGIN;
 
387
      GDK_NOTE (GC, (g_print ("%sclip_x=%d", s, values->clip_x_origin),
 
388
                     s = ","));
 
389
    }
 
390
 
 
391
  if (mask & GDK_GC_CLIP_Y_ORIGIN)
 
392
    {
 
393
      win32_gc->values_mask |= GDK_GC_CLIP_Y_ORIGIN;
 
394
      GDK_NOTE (GC, (g_print ("%sclip_y=%d", s, values->clip_y_origin),
 
395
                     s = ","));
 
396
    }
 
397
 
 
398
  if (mask & GDK_GC_EXPOSURES)
 
399
    {
 
400
      win32_gc->graphics_exposures = values->graphics_exposures;
 
401
      win32_gc->values_mask |= GDK_GC_EXPOSURES;
 
402
      GDK_NOTE (GC, (g_print ("%sexp=%d", s, win32_gc->graphics_exposures),
 
403
                     s = ","));
 
404
    }
 
405
 
 
406
  if (mask & GDK_GC_LINE_WIDTH)
 
407
    {
 
408
      win32_gc->pen_width = values->line_width;
 
409
      win32_gc->values_mask |= GDK_GC_LINE_WIDTH;
 
410
      GDK_NOTE (GC, (g_print ("%spw=%d", s, win32_gc->pen_width),
 
411
                     s = ","));
 
412
    }
 
413
 
 
414
  if (mask & GDK_GC_LINE_STYLE)
 
415
    {
 
416
      win32_gc->line_style = values->line_style;
 
417
      win32_gc->values_mask |= GDK_GC_LINE_STYLE;
 
418
    }
 
419
 
 
420
  if (mask & GDK_GC_CAP_STYLE)
 
421
    {
 
422
      win32_gc->cap_style = values->cap_style;
 
423
      win32_gc->values_mask |= GDK_GC_CAP_STYLE;
 
424
    }
 
425
 
 
426
  if (mask & GDK_GC_JOIN_STYLE)
 
427
    {
 
428
      win32_gc->join_style = values->join_style;
 
429
      win32_gc->values_mask |= GDK_GC_JOIN_STYLE;
 
430
    }
 
431
 
 
432
  if (mask & (GDK_GC_LINE_WIDTH|GDK_GC_LINE_STYLE|GDK_GC_CAP_STYLE|GDK_GC_JOIN_STYLE))
 
433
    {
 
434
      fixup_pen (win32_gc);
 
435
      GDK_NOTE (GC, (g_print ("%sps|=PS_STYLE_%s|PS_ENDCAP_%s|PS_JOIN_%s", s,
 
436
                              _gdk_win32_psstyle_to_string (win32_gc->pen_style),
 
437
                              _gdk_win32_psendcap_to_string (win32_gc->pen_style),
 
438
                              _gdk_win32_psjoin_to_string (win32_gc->pen_style)),
 
439
                     s = ","));
 
440
    }
 
441
 
 
442
  GDK_NOTE (GC, g_print ("} mask=(%s)", _gdk_win32_gcvalues_mask_to_string (win32_gc->values_mask)));
 
443
}
 
444
 
 
445
GdkGC*
 
446
_gdk_win32_gc_new (GdkDrawable    *drawable,
 
447
                   GdkGCValues    *values,
 
448
                   GdkGCValuesMask values_mask)
 
449
{
 
450
  GdkGC *gc;
 
451
  GdkGCWin32 *win32_gc;
 
452
 
 
453
  /* NOTICE that the drawable here has to be the impl drawable,
 
454
   * not the publically-visible drawables.
 
455
   */
 
456
  g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable), NULL);
 
457
 
 
458
  gc = g_object_new (_gdk_gc_win32_get_type (), NULL);
 
459
  win32_gc = GDK_GC_WIN32 (gc);
 
460
 
 
461
  _gdk_gc_init (gc, drawable, values, values_mask);
 
462
 
 
463
  win32_gc->hcliprgn = NULL;
 
464
 
 
465
  win32_gc->font = NULL;
 
466
  win32_gc->rop2 = R2_COPYPEN;
 
467
  win32_gc->subwindow_mode = GDK_CLIP_BY_CHILDREN;
 
468
  win32_gc->graphics_exposures = TRUE;
 
469
  win32_gc->pen_width = 0;
 
470
  /* Don't get confused by the PS_ENDCAP_ROUND. For narrow GDI pens
 
471
   * (width == 1), PS_GEOMETRIC|PS_ENDCAP_ROUND works like X11's
 
472
   * CapButt.
 
473
   */
 
474
  win32_gc->pen_style = PS_GEOMETRIC|PS_ENDCAP_ROUND|PS_JOIN_MITER;
 
475
  win32_gc->line_style = GDK_LINE_SOLID;
 
476
  win32_gc->cap_style = GDK_CAP_BUTT;
 
477
  win32_gc->join_style = GDK_JOIN_MITER;
 
478
  win32_gc->pen_dashes = NULL;
 
479
  win32_gc->pen_num_dashes = 0;
 
480
  win32_gc->pen_dash_offset = 0;
 
481
  win32_gc->pen_hbrbg = NULL;
 
482
 
 
483
  win32_gc->values_mask = GDK_GC_FUNCTION | GDK_GC_FILL;
 
484
 
 
485
  GDK_NOTE (GC, g_print ("_gdk_win32_gc_new: %p: ", win32_gc));
 
486
  gdk_win32_gc_values_to_win32values (values, values_mask, win32_gc);
 
487
  GDK_NOTE (GC, g_print ("\n"));
 
488
 
 
489
  win32_gc->hdc = NULL;
 
490
 
 
491
  return gc;
 
492
}
 
493
 
 
494
static void
 
495
gdk_win32_gc_get_values (GdkGC       *gc,
 
496
                         GdkGCValues *values)
 
497
{
 
498
  GdkGCWin32 *win32_gc = GDK_GC_WIN32 (gc);
 
499
 
 
500
  values->foreground.pixel = _gdk_gc_get_fg_pixel (gc);
 
501
  values->background.pixel = _gdk_gc_get_bg_pixel (gc);
 
502
  values->font = win32_gc->font;
 
503
 
 
504
  switch (win32_gc->rop2)
 
505
    {
 
506
    case R2_COPYPEN:
 
507
      values->function = GDK_COPY; break;
 
508
    case R2_NOT:
 
509
      values->function = GDK_INVERT; break;
 
510
    case R2_XORPEN:
 
511
      values->function = GDK_XOR; break;
 
512
    case R2_BLACK:
 
513
      values->function = GDK_CLEAR; break;
 
514
    case R2_MASKPEN:
 
515
      values->function = GDK_AND; break;
 
516
    case R2_MASKPENNOT:
 
517
      values->function = GDK_AND_REVERSE; break;
 
518
    case R2_MASKNOTPEN:
 
519
      values->function = GDK_AND_INVERT; break;
 
520
    case R2_NOP:
 
521
      values->function = GDK_NOOP; break;
 
522
    case R2_MERGEPEN:
 
523
      values->function = GDK_OR; break;
 
524
    case R2_NOTXORPEN:
 
525
      values->function = GDK_EQUIV; break;
 
526
    case R2_MERGEPENNOT:
 
527
      values->function = GDK_OR_REVERSE; break;
 
528
    case R2_NOTCOPYPEN:
 
529
      values->function = GDK_COPY_INVERT; break;
 
530
    case R2_MERGENOTPEN:
 
531
      values->function = GDK_OR_INVERT; break;
 
532
    case R2_NOTMASKPEN:
 
533
      values->function = GDK_NAND; break;
 
534
    case R2_NOTMERGEPEN:
 
535
      values->function = GDK_NOR; break;
 
536
    case R2_WHITE:
 
537
      values->function = GDK_SET; break;
 
538
    }
 
539
 
 
540
  values->fill = _gdk_gc_get_fill (gc);
 
541
  values->tile = _gdk_gc_get_tile (gc);
 
542
  values->stipple = _gdk_gc_get_stipple (gc);
 
543
 
 
544
  /* Also the X11 backend always returns a NULL clip_mask */
 
545
  values->clip_mask = NULL;
 
546
 
 
547
  values->subwindow_mode = win32_gc->subwindow_mode;
 
548
  values->ts_x_origin = win32_gc->parent_instance.ts_x_origin;
 
549
  values->ts_y_origin = win32_gc->parent_instance.ts_y_origin;
 
550
  values->clip_x_origin = win32_gc->parent_instance.clip_x_origin;
 
551
  values->clip_y_origin = win32_gc->parent_instance.clip_y_origin;
 
552
  values->graphics_exposures = win32_gc->graphics_exposures;
 
553
  values->line_width = win32_gc->pen_width;
 
554
  
 
555
  values->line_style = win32_gc->line_style;
 
556
  values->cap_style = win32_gc->cap_style;
 
557
  values->join_style = win32_gc->join_style;
 
558
}
 
559
 
 
560
static void
 
561
gdk_win32_gc_set_values (GdkGC           *gc,
 
562
                         GdkGCValues     *values,
 
563
                         GdkGCValuesMask  mask)
 
564
{
 
565
  g_return_if_fail (GDK_IS_GC (gc));
 
566
 
 
567
  GDK_NOTE (GC, g_print ("gdk_win32_gc_set_values: %p: ", GDK_GC_WIN32 (gc)));
 
568
  gdk_win32_gc_values_to_win32values (values, mask, GDK_GC_WIN32 (gc));
 
569
  GDK_NOTE (GC, g_print ("\n"));
 
570
}
 
571
 
 
572
static void
 
573
gdk_win32_gc_set_dashes (GdkGC *gc,
 
574
                         gint   dash_offset,
 
575
                         gint8  dash_list[],
 
576
                         gint   n)
 
577
{
 
578
  GdkGCWin32 *win32_gc;
 
579
  int i;
 
580
 
 
581
  g_return_if_fail (GDK_IS_GC (gc));
 
582
  g_return_if_fail (dash_list != NULL);
 
583
 
 
584
  win32_gc = GDK_GC_WIN32 (gc);
 
585
 
 
586
  win32_gc->pen_num_dashes = n;
 
587
  g_free (win32_gc->pen_dashes);
 
588
  win32_gc->pen_dashes = g_new (DWORD, n);
 
589
  for (i = 0; i < n; i++)
 
590
    win32_gc->pen_dashes[i] = dash_list[i];
 
591
  win32_gc->pen_dash_offset = dash_offset;
 
592
  fixup_pen (win32_gc);
 
593
}
 
594
 
 
595
void
 
596
_gdk_windowing_gc_set_clip_region (GdkGC          *gc,
 
597
                                   GdkRegion *region)
 
598
{
 
599
  GdkGCWin32 *win32_gc = GDK_GC_WIN32 (gc);
 
600
 
 
601
  if (win32_gc->hcliprgn)
 
602
    DeleteObject (win32_gc->hcliprgn);
 
603
 
 
604
  if (region)
 
605
    {
 
606
      GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: %p: %s\n",
 
607
                             win32_gc,
 
608
                             _gdk_win32_gdkregion_to_string (region)));
 
609
 
 
610
      win32_gc->hcliprgn = _gdk_win32_gdkregion_to_hrgn (region, 0, 0);
 
611
      win32_gc->values_mask |= GDK_GC_CLIP_MASK;
 
612
    }
 
613
  else
 
614
    {
 
615
      GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: NULL\n"));
 
616
 
 
617
      win32_gc->hcliprgn = NULL;
 
618
      win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
 
619
    }
 
620
 
 
621
  gc->clip_x_origin = 0;
 
622
  gc->clip_y_origin = 0;
 
623
  
 
624
  win32_gc->values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
 
625
}
 
626
 
 
627
void
 
628
_gdk_windowing_gc_copy (GdkGC *dst_gc,
 
629
                        GdkGC *src_gc)
 
630
{
 
631
  GdkGCWin32 *dst_win32_gc = GDK_GC_WIN32 (dst_gc);
 
632
  GdkGCWin32 *src_win32_gc = GDK_GC_WIN32 (src_gc);
 
633
 
 
634
  GDK_NOTE (GC, g_print ("gdk_gc_copy: %p := %p\n", dst_win32_gc, src_win32_gc));
 
635
 
 
636
  if (dst_win32_gc->hcliprgn != NULL)
 
637
    DeleteObject (dst_win32_gc->hcliprgn);
 
638
 
 
639
  if (dst_win32_gc->font != NULL)
 
640
    gdk_font_unref (dst_win32_gc->font);
 
641
 
 
642
  if (dst_win32_gc->pen_dashes)
 
643
    g_free (dst_win32_gc->pen_dashes);
 
644
  
 
645
  dst_win32_gc->hcliprgn = src_win32_gc->hcliprgn;
 
646
  if (dst_win32_gc->hcliprgn)
 
647
    {
 
648
      /* create a new region, to copy to */
 
649
      dst_win32_gc->hcliprgn = CreateRectRgn (0,0,1,1);
 
650
      /* overwrite from source */
 
651
      CombineRgn (dst_win32_gc->hcliprgn, src_win32_gc->hcliprgn,
 
652
                  NULL, RGN_COPY);
 
653
    }
 
654
 
 
655
  dst_win32_gc->values_mask = src_win32_gc->values_mask; 
 
656
  dst_win32_gc->font = src_win32_gc->font;
 
657
  if (dst_win32_gc->font != NULL)
 
658
    gdk_font_ref (dst_win32_gc->font);
 
659
 
 
660
  dst_win32_gc->rop2 = src_win32_gc->rop2;
 
661
 
 
662
  dst_win32_gc->subwindow_mode = src_win32_gc->subwindow_mode;
 
663
  dst_win32_gc->graphics_exposures = src_win32_gc->graphics_exposures;
 
664
  dst_win32_gc->pen_width = src_win32_gc->pen_width;
 
665
  dst_win32_gc->pen_style = src_win32_gc->pen_style;
 
666
  dst_win32_gc->line_style = src_win32_gc->line_style;
 
667
  dst_win32_gc->cap_style = src_win32_gc->cap_style;
 
668
  dst_win32_gc->join_style = src_win32_gc->join_style;
 
669
  if (src_win32_gc->pen_dashes)
 
670
    dst_win32_gc->pen_dashes = g_memdup (src_win32_gc->pen_dashes, 
 
671
                                         sizeof (DWORD) * src_win32_gc->pen_num_dashes);
 
672
  else
 
673
    dst_win32_gc->pen_dashes = NULL;
 
674
  dst_win32_gc->pen_num_dashes = src_win32_gc->pen_num_dashes;
 
675
  dst_win32_gc->pen_dash_offset = src_win32_gc->pen_dash_offset;
 
676
 
 
677
 
 
678
  dst_win32_gc->hdc = NULL;
 
679
  dst_win32_gc->saved_dc = FALSE;
 
680
  dst_win32_gc->holdpal = NULL;
 
681
  dst_win32_gc->pen_hbrbg = NULL;
 
682
}
 
683
 
 
684
GdkScreen *  
 
685
gdk_gc_get_screen (GdkGC *gc)
 
686
{
 
687
  g_return_val_if_fail (GDK_IS_GC_WIN32 (gc), NULL);
 
688
  
 
689
  return _gdk_screen;
 
690
}
 
691
 
 
692
static guint bitmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
 
693
 
 
694
COLORREF
 
695
_gdk_win32_colormap_color (GdkColormap *colormap,
 
696
                           gulong       pixel)
 
697
{
 
698
  const GdkVisual *visual;
 
699
  GdkColormapPrivateWin32 *colormap_private;
 
700
  guchar r, g, b;
 
701
 
 
702
  if (colormap == NULL)
 
703
    return DIBINDEX (pixel & 1);
 
704
 
 
705
  colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
 
706
 
 
707
  g_assert (colormap_private != NULL);
 
708
 
 
709
  visual = colormap->visual;
 
710
  switch (visual->type)
 
711
    {
 
712
    case GDK_VISUAL_GRAYSCALE:
 
713
    case GDK_VISUAL_PSEUDO_COLOR:
 
714
    case GDK_VISUAL_STATIC_COLOR:
 
715
      return PALETTEINDEX (pixel);
 
716
 
 
717
    case GDK_VISUAL_TRUE_COLOR:
 
718
      r = (pixel & visual->red_mask) >> visual->red_shift;
 
719
      r = (r * 255) / bitmask[visual->red_prec];
 
720
      g = (pixel & visual->green_mask) >> visual->green_shift;
 
721
      g = (g * 255) / bitmask[visual->green_prec];
 
722
      b = (pixel & visual->blue_mask) >> visual->blue_shift;
 
723
      b = (b * 255) / bitmask[visual->blue_prec];
 
724
      return RGB (r, g, b);
 
725
 
 
726
    default:
 
727
      g_assert_not_reached ();
 
728
      return 0;
 
729
    }
 
730
}
 
731
 
 
732
gboolean
 
733
predraw (GdkGC       *gc,
 
734
         GdkColormap *colormap)
 
735
{
 
736
  GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
 
737
  GdkColormapPrivateWin32 *colormap_private;
 
738
  gint k;
 
739
  gboolean ok = TRUE;
 
740
 
 
741
  if (colormap &&
 
742
      (colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
 
743
       colormap->visual->type == GDK_VISUAL_STATIC_COLOR))
 
744
    {
 
745
      colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
 
746
 
 
747
      g_assert (colormap_private != NULL);
 
748
 
 
749
      if (!(win32_gc->holdpal = SelectPalette (win32_gc->hdc, colormap_private->hpal, FALSE)))
 
750
        WIN32_GDI_FAILED ("SelectPalette"), ok = FALSE;
 
751
      else if ((k = RealizePalette (win32_gc->hdc)) == GDI_ERROR)
 
752
        WIN32_GDI_FAILED ("RealizePalette"), ok = FALSE;
 
753
      else if (k > 0)
 
754
        GDK_NOTE (COLORMAP, g_print ("predraw: realized %p: %d colors\n",
 
755
                                     colormap_private->hpal, k));
 
756
    }
 
757
 
 
758
  return ok;
 
759
}
 
760
 
 
761
static GdkDrawableImplWin32 *
 
762
get_impl_drawable (GdkDrawable *drawable)
 
763
{
 
764
  if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
 
765
    return GDK_DRAWABLE_IMPL_WIN32(drawable);
 
766
  else if (GDK_IS_WINDOW (drawable))
 
767
    return GDK_DRAWABLE_IMPL_WIN32 ((GDK_WINDOW_OBJECT (drawable))->impl);
 
768
  else if (GDK_IS_PIXMAP (drawable))
 
769
    return GDK_DRAWABLE_IMPL_WIN32 ((GDK_PIXMAP_OBJECT (drawable))->impl);
 
770
  else
 
771
    g_assert_not_reached ();
 
772
 
 
773
  return NULL;
 
774
}
 
775
 
 
776
/**
 
777
 * gdk_win32_hdc_get:
 
778
 * @drawable: destination #GdkDrawable
 
779
 * @gc: #GdkGC to use for drawing on @drawable
 
780
 * @usage: mask indicating what properties needs to be set up
 
781
 *
 
782
 * Allocates a Windows device context handle (HDC) for drawing into
 
783
 * @drawable, and sets it up appropriately according to @usage.
 
784
 *
 
785
 * Each #GdkGC can at one time have only one HDC associated with it.
 
786
 *
 
787
 * The following flags in @mask are handled:
 
788
 *
 
789
 * If %GDK_GC_FOREGROUND is set in @mask, a solid brush of the
 
790
 * foreground color in @gc is selected into the HDC. The text color of
 
791
 * the HDC is also set. If the @drawable has a palette (256-color
 
792
 * mode), the palette is selected and realized.
 
793
 *
 
794
 * If any of the line attribute flags (%GDK_GC_LINE_WIDTH,
 
795
 * %GDK_GC_LINE_STYLE, %GDK_GC_CAP_STYLE and %GDK_GC_JOIN_STYLE) is
 
796
 * set in @mask, a solid pen of the foreground color and appropriate
 
797
 * width and stule is created and selected into the HDC. Note that the
 
798
 * dash properties are not completely implemented.
 
799
 *
 
800
 * If the %GDK_GC_FONT flag is set, the background mix mode is set to
 
801
 * %TRANSPARENT. and the text alignment is set to
 
802
 * %TA_BASELINE|%TA_LEFT. Note that no font gets selected into the HDC
 
803
 * by this function.
 
804
 *
 
805
 * Some things are done regardless of @mask: If the function in @gc is
 
806
 * any other than %GDK_COPY, the raster operation of the HDC is
 
807
 * set. If @gc has a clip mask, the clip region of the HDC is set.
 
808
 *
 
809
 * Note that the fill style, tile, stipple, and tile and stipple
 
810
 * origins in the @gc are ignored by this function. (In general, tiles
 
811
 * and stipples can't be implemented directly on Win32; you need to do
 
812
 * multiple pass drawing and blitting to implement tiles or
 
813
 * stipples. GDK does just that when you call the GDK drawing
 
814
 * functions with a GC that asks for tiles or stipples.)
 
815
 *
 
816
 * When the HDC is no longer used, it should be released by calling
 
817
 * <function>gdk_win32_hdc_release()</function> with the same
 
818
 * parameters.
 
819
 *
 
820
 * If you modify the HDC by calling <function>SelectObject</function>
 
821
 * you should undo those modifications before calling
 
822
 * <function>gdk_win32_hdc_release()</function>.
 
823
 *
 
824
 * Return value: The HDC.
 
825
 **/
 
826
HDC
 
827
gdk_win32_hdc_get (GdkDrawable    *drawable,
 
828
                   GdkGC          *gc,
 
829
                   GdkGCValuesMask usage)
 
830
{
 
831
  GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
 
832
  GdkDrawableImplWin32 *impl = NULL;
 
833
  gboolean ok = TRUE;
 
834
  COLORREF fg = RGB (0, 0, 0), bg = RGB (255, 255, 255);
 
835
  HPEN hpen;
 
836
  HBRUSH hbr;
 
837
 
 
838
  g_assert (win32_gc->hdc == NULL);
 
839
 
 
840
  impl = get_impl_drawable (drawable);
 
841
  
 
842
  win32_gc->hdc = _gdk_win32_drawable_acquire_dc (GDK_DRAWABLE (impl));
 
843
  ok = win32_gc->hdc != NULL;
 
844
 
 
845
  if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
 
846
    WIN32_GDI_FAILED ("SaveDC"), ok = FALSE;
 
847
      
 
848
  if (ok && (usage & (GDK_GC_FOREGROUND | GDK_GC_BACKGROUND)))
 
849
      ok = predraw (gc, impl->colormap);
 
850
 
 
851
  if (ok && (usage & GDK_GC_FOREGROUND))
 
852
    {
 
853
      fg = _gdk_win32_colormap_color (impl->colormap, _gdk_gc_get_fg_pixel (gc));
 
854
      if ((hbr = CreateSolidBrush (fg)) == NULL)
 
855
        WIN32_GDI_FAILED ("CreateSolidBrush"), ok = FALSE;
 
856
 
 
857
      if (ok && SelectObject (win32_gc->hdc, hbr) == NULL)
 
858
        WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
 
859
 
 
860
      if (ok && SetTextColor (win32_gc->hdc, fg) == CLR_INVALID)
 
861
        WIN32_GDI_FAILED ("SetTextColor"), ok = FALSE;
 
862
    }
 
863
 
 
864
  if (ok && (usage & LINE_ATTRIBUTES))
 
865
    {
 
866
      /* For drawing GDK_LINE_DOUBLE_DASH */
 
867
      if ((usage & GDK_GC_BACKGROUND) && win32_gc->line_style == GDK_LINE_DOUBLE_DASH)
 
868
        {
 
869
          bg = _gdk_win32_colormap_color (impl->colormap, _gdk_gc_get_bg_pixel (gc));
 
870
          if ((win32_gc->pen_hbrbg = CreateSolidBrush (bg)) == NULL)
 
871
            WIN32_GDI_FAILED ("CreateSolidBrush"), ok = FALSE;
 
872
        }
 
873
 
 
874
      if (ok)
 
875
        {
 
876
          LOGBRUSH logbrush;
 
877
          DWORD style_count = 0;
 
878
          const DWORD *style = NULL;
 
879
 
 
880
          /* Create and select pen */
 
881
          logbrush.lbStyle = BS_SOLID;
 
882
          logbrush.lbColor = fg;
 
883
          logbrush.lbHatch = 0;
 
884
 
 
885
          if ((win32_gc->pen_style & PS_STYLE_MASK) == PS_USERSTYLE)
 
886
            {
 
887
              style_count = win32_gc->pen_num_dashes;
 
888
              style = win32_gc->pen_dashes;
 
889
            }
 
890
 
 
891
          if ((hpen = ExtCreatePen (win32_gc->pen_style,
 
892
                                    MAX (win32_gc->pen_width, 1),
 
893
                                    &logbrush, 
 
894
                                    style_count, style)) == NULL)
 
895
            WIN32_GDI_FAILED ("ExtCreatePen"), ok = FALSE;
 
896
          
 
897
          if (ok && SelectObject (win32_gc->hdc, hpen) == NULL)
 
898
            WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
 
899
        }
 
900
    }
 
901
 
 
902
  if (ok && (usage & GDK_GC_FONT))
 
903
    {
 
904
      if (SetBkMode (win32_gc->hdc, TRANSPARENT) == 0)
 
905
        WIN32_GDI_FAILED ("SetBkMode"), ok = FALSE;
 
906
  
 
907
      if (ok && SetTextAlign (win32_gc->hdc, TA_BASELINE|TA_LEFT|TA_NOUPDATECP) == GDI_ERROR)
 
908
        WIN32_GDI_FAILED ("SetTextAlign"), ok = FALSE;
 
909
    }
 
910
  
 
911
  if (ok && win32_gc->rop2 != R2_COPYPEN)
 
912
    if (SetROP2 (win32_gc->hdc, win32_gc->rop2) == 0)
 
913
      WIN32_GDI_FAILED ("SetROP2"), ok = FALSE;
 
914
 
 
915
  if (ok &&
 
916
      (win32_gc->values_mask & GDK_GC_CLIP_MASK) &&
 
917
      win32_gc->hcliprgn != NULL)
 
918
    {
 
919
      if (SelectClipRgn (win32_gc->hdc, win32_gc->hcliprgn) == ERROR)
 
920
        WIN32_API_FAILED ("SelectClipRgn"), ok = FALSE;
 
921
 
 
922
      if (ok && win32_gc->values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN) &&
 
923
          OffsetClipRgn (win32_gc->hdc,
 
924
            win32_gc->values_mask & GDK_GC_CLIP_X_ORIGIN ? gc->clip_x_origin : 0,
 
925
            win32_gc->values_mask & GDK_GC_CLIP_Y_ORIGIN ? gc->clip_y_origin : 0) == ERROR)
 
926
        WIN32_API_FAILED ("OffsetClipRgn"), ok = FALSE;
 
927
    }
 
928
  else if (ok)
 
929
    SelectClipRgn (win32_gc->hdc, NULL);
 
930
 
 
931
  GDK_NOTE (GC, (g_print ("gdk_win32_hdc_get: %p (%s): ",
 
932
                          win32_gc, _gdk_win32_gcvalues_mask_to_string (usage)),
 
933
                 _gdk_win32_print_dc (win32_gc->hdc)));
 
934
 
 
935
  return win32_gc->hdc;
 
936
}
 
937
 
 
938
/**
 
939
 * gdk_win32_hdc_release:
 
940
 * @drawable: destination #GdkDrawable
 
941
 * @gc: #GdkGC to use for drawing on @drawable
 
942
 * @usage: mask indicating what properties were set up
 
943
 *
 
944
 * This function deallocates the Windows device context allocated by
 
945
 * <funcion>gdk_win32_hdc_get()</function>. It should be called with
 
946
 * the same parameters.
 
947
 **/
 
948
void
 
949
gdk_win32_hdc_release (GdkDrawable    *drawable,
 
950
                       GdkGC          *gc,
 
951
                       GdkGCValuesMask usage)
 
952
{
 
953
  GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
 
954
  GdkDrawableImplWin32 *impl = NULL;
 
955
  HGDIOBJ hpen = NULL;
 
956
  HGDIOBJ hbr = NULL;
 
957
 
 
958
  GDK_NOTE (GC, g_print ("gdk_win32_hdc_release: %p: %p (%s)\n",
 
959
                         win32_gc, win32_gc->hdc,
 
960
                         _gdk_win32_gcvalues_mask_to_string (usage)));
 
961
 
 
962
  impl = get_impl_drawable (drawable);
 
963
 
 
964
  if (win32_gc->holdpal != NULL)
 
965
    {
 
966
      gint k;
 
967
      
 
968
      if (!SelectPalette (win32_gc->hdc, win32_gc->holdpal, FALSE))
 
969
        WIN32_GDI_FAILED ("SelectPalette");
 
970
      else if ((k = RealizePalette (win32_gc->hdc)) == GDI_ERROR)
 
971
        WIN32_GDI_FAILED ("RealizePalette");
 
972
      else if (k > 0)
 
973
        GDK_NOTE (COLORMAP, g_print ("gdk_win32_hdc_release: realized %p: %d colors\n",
 
974
                                     win32_gc->holdpal, k));
 
975
      win32_gc->holdpal = NULL;
 
976
    }
 
977
 
 
978
  if (usage & LINE_ATTRIBUTES)
 
979
    if ((hpen = GetCurrentObject (win32_gc->hdc, OBJ_PEN)) == NULL)
 
980
      WIN32_GDI_FAILED ("GetCurrentObject");
 
981
  
 
982
  if (usage & GDK_GC_FOREGROUND)
 
983
    if ((hbr = GetCurrentObject (win32_gc->hdc, OBJ_BRUSH)) == NULL)
 
984
      WIN32_GDI_FAILED ("GetCurrentObject");
 
985
 
 
986
  GDI_CALL (RestoreDC, (win32_gc->hdc, win32_gc->saved_dc));
 
987
 
 
988
  _gdk_win32_drawable_release_dc (GDK_DRAWABLE (impl));
 
989
 
 
990
  if (hpen != NULL)
 
991
    GDI_CALL (DeleteObject, (hpen));
 
992
  
 
993
  if (hbr != NULL)
 
994
    GDI_CALL (DeleteObject, (hbr));
 
995
 
 
996
  if (win32_gc->pen_hbrbg != NULL)
 
997
    GDI_CALL (DeleteObject, (win32_gc->pen_hbrbg));
 
998
 
 
999
  win32_gc->hdc = NULL;
 
1000
}
 
1001
 
 
1002
/* This function originally from Jean-Edouard Lachand-Robert, and
 
1003
 * available at www.codeguru.com. Simplified for our needs, not sure
 
1004
 * how much of the original code left any longer. Now handles just
 
1005
 * one-bit deep bitmaps (in Window parlance, ie those that GDK calls
 
1006
 * bitmaps (and not pixmaps), with zero pixels being transparent.
 
1007
 */
 
1008
 
 
1009
/* _gdk_win32_bitmap_to_hrgn : Create a region from the
 
1010
 * "non-transparent" pixels of a bitmap.
 
1011
 */
 
1012
 
 
1013
HRGN
 
1014
_gdk_win32_bitmap_to_hrgn (GdkPixmap *pixmap)
 
1015
{
 
1016
  HRGN hRgn = NULL;
 
1017
  HRGN h;
 
1018
  DWORD maxRects;
 
1019
  RGNDATA *pData;
 
1020
  guchar *bits;
 
1021
  gint width, height, bpl;
 
1022
  guchar *p;
 
1023
  gint x, y;
 
1024
 
 
1025
  g_assert (GDK_PIXMAP_OBJECT(pixmap)->depth == 1);
 
1026
 
 
1027
  bits = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->bits;
 
1028
  width = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->width;
 
1029
  height = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->height;
 
1030
  bpl = ((width - 1)/32 + 1)*4;
 
1031
 
 
1032
  /* For better performances, we will use the ExtCreateRegion()
 
1033
   * function to create the region. This function take a RGNDATA
 
1034
   * structure on entry. We will add rectangles by amount of
 
1035
   * ALLOC_UNIT number in this structure.
 
1036
   */
 
1037
  #define ALLOC_UNIT  100
 
1038
  maxRects = ALLOC_UNIT;
 
1039
 
 
1040
  pData = g_malloc (sizeof (RGNDATAHEADER) + (sizeof (RECT) * maxRects));
 
1041
  pData->rdh.dwSize = sizeof (RGNDATAHEADER);
 
1042
  pData->rdh.iType = RDH_RECTANGLES;
 
1043
  pData->rdh.nCount = pData->rdh.nRgnSize = 0;
 
1044
  SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
 
1045
 
 
1046
  for (y = 0; y < height; y++)
 
1047
    {
 
1048
      /* Scan each bitmap row from left to right*/
 
1049
      p = (guchar *) bits + y * bpl;
 
1050
      for (x = 0; x < width; x++)
 
1051
        {
 
1052
          /* Search for a continuous range of "non transparent pixels"*/
 
1053
          gint x0 = x;
 
1054
          while (x < width)
 
1055
            {
 
1056
              if ((((p[x/8])>>(7-(x%8)))&1) == 0)
 
1057
                /* This pixel is "transparent"*/
 
1058
                break;
 
1059
              x++;
 
1060
            }
 
1061
          
 
1062
          if (x > x0)
 
1063
            {
 
1064
              RECT *pr;
 
1065
              /* Add the pixels (x0, y) to (x, y+1) as a new rectangle
 
1066
               * in the region
 
1067
               */
 
1068
              if (pData->rdh.nCount >= maxRects)
 
1069
                {
 
1070
                  maxRects += ALLOC_UNIT;
 
1071
                  pData = g_realloc (pData, sizeof(RGNDATAHEADER)
 
1072
                                     + (sizeof(RECT) * maxRects));
 
1073
                }
 
1074
              pr = (RECT *) &pData->Buffer;
 
1075
              SetRect (&pr[pData->rdh.nCount], x0, y, x, y+1);
 
1076
              if (x0 < pData->rdh.rcBound.left)
 
1077
                pData->rdh.rcBound.left = x0;
 
1078
              if (y < pData->rdh.rcBound.top)
 
1079
                pData->rdh.rcBound.top = y;
 
1080
              if (x > pData->rdh.rcBound.right)
 
1081
                pData->rdh.rcBound.right = x;
 
1082
              if (y+1 > pData->rdh.rcBound.bottom)
 
1083
                pData->rdh.rcBound.bottom = y+1;
 
1084
              pData->rdh.nCount++;
 
1085
              
 
1086
              /* On Windows98, ExtCreateRegion() may fail if the
 
1087
               * number of rectangles is too large (ie: >
 
1088
               * 4000). Therefore, we have to create the region by
 
1089
               * multiple steps.
 
1090
               */
 
1091
              if (pData->rdh.nCount == 2000)
 
1092
                {
 
1093
                  HRGN h = ExtCreateRegion (NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
 
1094
                  if (hRgn)
 
1095
                    {
 
1096
                      CombineRgn(hRgn, hRgn, h, RGN_OR);
 
1097
                      DeleteObject(h);
 
1098
                    }
 
1099
                  else
 
1100
                    hRgn = h;
 
1101
                  pData->rdh.nCount = 0;
 
1102
                  SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
 
1103
                }
 
1104
            }
 
1105
        }
 
1106
    }
 
1107
  
 
1108
  /* Create or extend the region with the remaining rectangles*/
 
1109
  h = ExtCreateRegion (NULL, sizeof (RGNDATAHEADER)
 
1110
                       + (sizeof (RECT) * maxRects), pData);
 
1111
  if (hRgn)
 
1112
    {
 
1113
      CombineRgn (hRgn, hRgn, h, RGN_OR);
 
1114
      DeleteObject (h);
 
1115
    }
 
1116
  else
 
1117
    hRgn = h;
 
1118
 
 
1119
  /* Clean up*/
 
1120
  g_free (pData);
 
1121
 
 
1122
  return hRgn;
 
1123
}
 
1124
 
 
1125
HRGN
 
1126
_gdk_win32_gdkregion_to_hrgn (GdkRegion *region,
 
1127
                              gint       x_origin,
 
1128
                              gint       y_origin)
 
1129
{
 
1130
  HRGN hrgn;
 
1131
  RGNDATA *rgndata;
 
1132
  RECT *rect;
 
1133
  GdkRegionBox *boxes = region->rects;
 
1134
  guint nbytes =
 
1135
    sizeof (RGNDATAHEADER) + (sizeof (RECT) * region->numRects);
 
1136
  int i;
 
1137
 
 
1138
  rgndata = g_malloc (nbytes);
 
1139
  rgndata->rdh.dwSize = sizeof (RGNDATAHEADER);
 
1140
  rgndata->rdh.iType = RDH_RECTANGLES;
 
1141
  rgndata->rdh.nCount = rgndata->rdh.nRgnSize = 0;
 
1142
  SetRect (&rgndata->rdh.rcBound,
 
1143
           G_MAXLONG, G_MAXLONG, G_MINLONG, G_MINLONG);
 
1144
 
 
1145
  for (i = 0; i < region->numRects; i++)
 
1146
    {
 
1147
      rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++;
 
1148
 
 
1149
      rect->left = boxes[i].x1 + x_origin;
 
1150
      rect->right = boxes[i].x2 + x_origin;
 
1151
      rect->top = boxes[i].y1 + y_origin;
 
1152
      rect->bottom = boxes[i].y2 + y_origin;
 
1153
 
 
1154
      if (rect->left < rgndata->rdh.rcBound.left)
 
1155
        rgndata->rdh.rcBound.left = rect->left;
 
1156
      if (rect->right > rgndata->rdh.rcBound.right)
 
1157
        rgndata->rdh.rcBound.right = rect->right;
 
1158
      if (rect->top < rgndata->rdh.rcBound.top)
 
1159
        rgndata->rdh.rcBound.top = rect->top;
 
1160
      if (rect->bottom > rgndata->rdh.rcBound.bottom)
 
1161
        rgndata->rdh.rcBound.bottom = rect->bottom;
 
1162
    }
 
1163
  if ((hrgn = ExtCreateRegion (NULL, nbytes, rgndata)) == NULL)
 
1164
    WIN32_API_FAILED ("ExtCreateRegion");
 
1165
 
 
1166
  g_free (rgndata);
 
1167
 
 
1168
  return (hrgn);
 
1169
}