?? gdkgc-win32.c
字號:
/* GDK - The GIMP Drawing Kit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * Copyright (C) 1998-2004 Tor Lillqvist * Copyright (C) 2000-2004 Hans Breuer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */#define LINE_ATTRIBUTES (GDK_GC_LINE_WIDTH|GDK_GC_LINE_STYLE| \ GDK_GC_CAP_STYLE|GDK_GC_JOIN_STYLE)#include <config.h>#include <string.h>#include "gdkgc.h"#include "gdkfont.h"#include "gdkpixmap.h"#include "gdkregion-generic.h"#include "gdkprivate-win32.h"static void gdk_win32_gc_get_values (GdkGC *gc, GdkGCValues *values);static void gdk_win32_gc_set_values (GdkGC *gc, GdkGCValues *values, GdkGCValuesMask values_mask);static void gdk_win32_gc_set_dashes (GdkGC *gc, gint dash_offset, gint8 dash_list[], gint n);static void gdk_gc_win32_class_init (GdkGCWin32Class *klass);static void gdk_gc_win32_finalize (GObject *object);static gpointer parent_class = NULL;GType_gdk_gc_win32_get_type (void){ static GType object_type = 0; if (!object_type) { static const GTypeInfo object_info = { sizeof (GdkGCWin32Class), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gdk_gc_win32_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GdkGCWin32), 0, /* n_preallocs */ (GInstanceInitFunc) NULL, }; object_type = g_type_register_static (GDK_TYPE_GC, "GdkGCWin32", &object_info, 0); } return object_type;}static voidgdk_gc_win32_class_init (GdkGCWin32Class *klass){ GObjectClass *object_class = G_OBJECT_CLASS (klass); GdkGCClass *gc_class = GDK_GC_CLASS (klass); parent_class = g_type_class_peek_parent (klass); object_class->finalize = gdk_gc_win32_finalize; gc_class->get_values = gdk_win32_gc_get_values; gc_class->set_values = gdk_win32_gc_set_values; gc_class->set_dashes = gdk_win32_gc_set_dashes;}static voidgdk_gc_win32_finalize (GObject *object){ GdkGCWin32 *win32_gc = GDK_GC_WIN32 (object); if (win32_gc->hcliprgn != NULL) DeleteObject (win32_gc->hcliprgn); if (win32_gc->values_mask & GDK_GC_FONT) gdk_font_unref (win32_gc->font); if (win32_gc->values_mask & GDK_GC_TILE) g_object_unref (win32_gc->tile); if (win32_gc->values_mask & GDK_GC_STIPPLE) g_object_unref (win32_gc->stipple); if (win32_gc->pen_dashes) g_free (win32_gc->pen_dashes); G_OBJECT_CLASS (parent_class)->finalize (object);}static voidfixup_pen (GdkGCWin32 *win32_gc){ win32_gc->pen_style = 0; /* First look at GDK width and end cap style, set GDI pen type and * end cap. */ if (win32_gc->pen_width == 0 && win32_gc->cap_style == GDK_CAP_NOT_LAST) { /* Use a cosmetic pen, always width 1 */ win32_gc->pen_style |= PS_COSMETIC; } else if (win32_gc->pen_width <= 1 && win32_gc->cap_style == GDK_CAP_BUTT) { /* For 1 pixel wide lines PS_ENDCAP_ROUND means draw both ends, * even for one pixel length lines. But if we are drawing dashed * lines we can't use PS_ENDCAP_ROUND. */ if (win32_gc->line_style == GDK_LINE_SOLID) win32_gc->pen_style |= PS_GEOMETRIC | PS_ENDCAP_ROUND; else win32_gc->pen_style |= PS_GEOMETRIC | PS_ENDCAP_FLAT; } else { win32_gc->pen_style |= PS_GEOMETRIC; switch (win32_gc->cap_style) { /* For non-zero-width lines X11's CapNotLast works like CapButt */ case GDK_CAP_NOT_LAST: case GDK_CAP_BUTT: win32_gc->pen_style |= PS_ENDCAP_FLAT; break; case GDK_CAP_ROUND: win32_gc->pen_style |= PS_ENDCAP_ROUND; break; case GDK_CAP_PROJECTING: win32_gc->pen_style |= PS_ENDCAP_SQUARE; break; } } /* Next look at GDK line style, set GDI pen style attribute */ switch (win32_gc->line_style) { case GDK_LINE_SOLID: win32_gc->pen_style |= PS_SOLID; break; case GDK_LINE_ON_OFF_DASH: case GDK_LINE_DOUBLE_DASH: if (win32_gc->pen_dashes == NULL) { win32_gc->pen_dashes = g_new (DWORD, 1); win32_gc->pen_dashes[0] = 4; win32_gc->pen_num_dashes = 1; } if (G_WIN32_IS_NT_BASED ()) { if (!(win32_gc->pen_style & PS_TYPE_MASK) == PS_GEOMETRIC && win32_gc->pen_dashes[0] == 1 && (win32_gc->pen_num_dashes == 1 || (win32_gc->pen_num_dashes == 2 && win32_gc->pen_dashes[0] == 1))) win32_gc->pen_style |= PS_ALTERNATE; else win32_gc->pen_style |= PS_USERSTYLE; } else { /* Render "short" on-off dashes drawn with R2_COPYPEN and a * cosmetic pen using PS_DOT */ if (win32_gc->line_style == GDK_LINE_ON_OFF_DASH && win32_gc->rop2 == R2_COPYPEN && (win32_gc->pen_style & PS_TYPE_MASK) == PS_COSMETIC && win32_gc->pen_dashes[0] <= 2 && (win32_gc->pen_num_dashes == 1 || (win32_gc->pen_num_dashes == 2 && win32_gc->pen_dashes[1] <= 2))) win32_gc->pen_style |= PS_DOT; else /* Otherwise render opaque lines solid, horizontal or * vertical ones will be dashed manually, see * gdkdrawable-win32.c. */ win32_gc->pen_style |= PS_SOLID; } break; } /* Last, for if the GDI pen is geometric, set the join attribute */ if ((win32_gc->pen_style & PS_TYPE_MASK) == PS_GEOMETRIC) { switch (win32_gc->join_style) { case GDK_JOIN_MITER: win32_gc->pen_style |= PS_JOIN_MITER; break; case GDK_JOIN_ROUND: win32_gc->pen_style |= PS_JOIN_ROUND; break; case GDK_JOIN_BEVEL: win32_gc->pen_style |= PS_JOIN_BEVEL; break; } }}static voidgdk_win32_gc_values_to_win32values (GdkGCValues *values, GdkGCValuesMask mask, GdkGCWin32 *win32_gc){ char *s = ""; gint sw, sh; GDK_NOTE (GC, g_print ("{")); if (mask & GDK_GC_FOREGROUND) { win32_gc->foreground = values->foreground.pixel; win32_gc->values_mask |= GDK_GC_FOREGROUND; GDK_NOTE (GC, (g_print ("fg=%.06lx", win32_gc->foreground), s = ",")); } if (mask & GDK_GC_BACKGROUND) { win32_gc->background = values->background.pixel; win32_gc->values_mask |= GDK_GC_BACKGROUND; GDK_NOTE (GC, (g_print ("%sbg=%.06lx", s, win32_gc->background), s = ",")); } if ((mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT || values->font->type == GDK_FONT_FONTSET)) { if (win32_gc->font != NULL) gdk_font_unref (win32_gc->font); win32_gc->font = values->font; if (win32_gc->font != NULL) { gdk_font_ref (win32_gc->font); win32_gc->values_mask |= GDK_GC_FONT; GDK_NOTE (GC, (g_print ("%sfont=%p", s, win32_gc->font), s = ",")); } else { win32_gc->values_mask &= ~GDK_GC_FONT; GDK_NOTE (GC, (g_print ("%sfont=NULL", s), s = ",")); } } if (mask & GDK_GC_FUNCTION) { GDK_NOTE (GC, (g_print ("%srop2=", s), s = ",")); switch (values->function) {#define CASE(x,y) case GDK_##x: win32_gc->rop2 = R2_##y; GDK_NOTE (GC, g_print (#y)); break CASE (COPY, COPYPEN); CASE (INVERT, NOT); CASE (XOR, XORPEN); CASE (CLEAR, BLACK); CASE (AND, MASKPEN); CASE (AND_REVERSE, MASKPENNOT); CASE (AND_INVERT, MASKNOTPEN); CASE (NOOP, NOP); CASE (OR, MERGEPEN); CASE (EQUIV, NOTXORPEN); CASE (OR_REVERSE, MERGEPENNOT); CASE (COPY_INVERT, NOTCOPYPEN); CASE (OR_INVERT, MERGENOTPEN); CASE (NAND, NOTMASKPEN); CASE (NOR, NOTMERGEPEN); CASE (SET, WHITE);#undef CASE } win32_gc->values_mask |= GDK_GC_FUNCTION; } if (mask & GDK_GC_FILL) { win32_gc->fill_style = values->fill; win32_gc->values_mask |= GDK_GC_FILL; GDK_NOTE (GC, (g_print ("%sfill=%s", s, _gdk_win32_fill_style_to_string (win32_gc->fill_style)), s = ",")); } if (mask & GDK_GC_TILE) { if (win32_gc->tile != NULL) g_object_unref (win32_gc->tile); win32_gc->tile = values->tile; if (win32_gc->tile != NULL) { g_object_ref (win32_gc->tile); win32_gc->values_mask |= GDK_GC_TILE; GDK_NOTE (GC, (g_print ("%stile=%p", s, GDK_PIXMAP_HBITMAP (win32_gc->tile)), s = ",")); } else { win32_gc->values_mask &= ~GDK_GC_TILE; GDK_NOTE (GC, (g_print ("%stile=NULL", s), s = ",")); } } if (mask & GDK_GC_STIPPLE) { if (win32_gc->stipple != NULL) g_object_unref (win32_gc->stipple); win32_gc->stipple = values->stipple; if (win32_gc->stipple != NULL) { gdk_drawable_get_size (win32_gc->stipple, &sw, &sh);#if 0 /* HB: this size limitation is disabled to make radio and check * buttons work. I got the impression from the API docs, that * it shouldn't be necessary at all, but win9x would do the clipping */ if ( (sw != 8 || sh != 8) && !G_WIN32_IS_NT_BASED ()) /* HB: the MSDN says it's a Win95 limitation */ { /* It seems that it *must* be 8x8, at least on my machine. * Thus, tile an 8x8 bitmap with the stipple in case it is * smaller, or simply use just the top left 8x8 in case it is * larger. */ gchar dummy[8]; GdkPixmap *bm = gdk_bitmap_create_from_data (NULL, dummy, 8, 8); GdkGC *gc = gdk_gc_new (bm); gint i, j; i = 0; while (i < 8) { j = 0; while (j < 8) { gdk_draw_drawable (bm, gc, win32_gc->stipple, 0, 0, i, j, sw, sh); j += sh; } i += sw; } win32_gc->stipple = bm; gdk_gc_unref (gc); } else#endif g_object_ref (win32_gc->stipple); win32_gc->values_mask |= GDK_GC_STIPPLE; GDK_NOTE (GC, (g_print ("%sstipple=%p", s, GDK_PIXMAP_HBITMAP (win32_gc->stipple)), s = ",")); } else { win32_gc->values_mask &= ~GDK_GC_STIPPLE; GDK_NOTE (GC, (g_print ("%sstipple=NULL", s), s = ",")); } } if (mask & GDK_GC_CLIP_MASK) { if (win32_gc->hcliprgn != NULL) DeleteObject (win32_gc->hcliprgn); if (values->clip_mask != NULL) { win32_gc->hcliprgn = _gdk_win32_bitmap_to_hrgn (values->clip_mask); win32_gc->values_mask |= GDK_GC_CLIP_MASK; } else { win32_gc->hcliprgn = NULL; win32_gc->values_mask &= ~GDK_GC_CLIP_MASK; } GDK_NOTE (GC, (g_print ("%sclip=%p", s, win32_gc->hcliprgn), s = ",")); } if (mask & GDK_GC_SUBWINDOW) { win32_gc->subwindow_mode = values->subwindow_mode; win32_gc->values_mask |= GDK_GC_SUBWINDOW; GDK_NOTE (GC, (g_print ("%ssubw=%d", s, win32_gc->subwindow_mode), s = ",")); } if (mask & GDK_GC_TS_X_ORIGIN) { win32_gc->values_mask |= GDK_GC_TS_X_ORIGIN; GDK_NOTE (GC, (g_print ("%sts_x=%d", s, values->ts_x_origin), s = ",")); } if (mask & GDK_GC_TS_Y_ORIGIN) { win32_gc->values_mask |= GDK_GC_TS_Y_ORIGIN; GDK_NOTE (GC, (g_print ("%sts_y=%d", s, values->ts_y_origin), s = ",")); } if (mask & GDK_GC_CLIP_X_ORIGIN) { win32_gc->values_mask |= GDK_GC_CLIP_X_ORIGIN; GDK_NOTE (GC, (g_print ("%sclip_x=%d", s, values->clip_x_origin), s = ",")); } if (mask & GDK_GC_CLIP_Y_ORIGIN) { win32_gc->values_mask |= GDK_GC_CLIP_Y_ORIGIN; GDK_NOTE (GC, (g_print ("%sclip_y=%d", s, values->clip_y_origin), s = ",")); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -