?? gdkmain-win32.c
字號:
/* GDK - The GIMP Drawing Kit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * Copyright (C) 1998-2002 Tor Lillqvist * * 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/. */#include <config.h>#include <glib/gprintf.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <io.h>#include "gdk.h"#include "gdkregion-generic.h"#include "gdkkeysyms.h"#include "gdkinternals.h"#include "gdkintl.h"#include "gdkprivate-win32.h"#include "gdkinput-win32.h"#include <objbase.h>#if defined (__GNUC__) && defined (HAVE_DIMM_H)/* The w32api imm.h clashes a bit with the IE5.5 dimm.h */# define IMEMENUITEMINFOA hidden_IMEMENUITEMINFOA# define IMEMENUITEMINFOW hidden_IMEMENUITEMINFOW#endif#include <imm.h>static gboolean gdk_synchronize = FALSE;static gboolean dummy;GOptionEntry _gdk_windowing_args[] = { { "sync", 0, 0, G_OPTION_ARG_NONE, &gdk_synchronize, /* Description of --sync in --help output */ N_("Don't batch GDI requests"), NULL }, { "no-wintab", 0, 0, G_OPTION_ARG_NONE, &_gdk_input_ignore_wintab, /* Description of --no-wintab in --help output */ N_("Don't use the Wintab API for tablet support"), NULL }, { "ignore-wintab", 0, 0, G_OPTION_ARG_NONE, &_gdk_input_ignore_wintab, /* Description of --ignore-wintab in --help output */ N_("Same as --no-wintab"), NULL }, { "use-wintab", 0, 0, G_OPTION_ARG_NONE, &dummy, /* Description of --use-wintab in --help output */ N_("Do use the Wintab API [default]"), NULL }, { "max-colors", 0, 0, G_OPTION_ARG_INT, &_gdk_max_colors, /* Description of --max-colors=COLORS in --help output */ N_("Size of the palette in 8 bit mode"), /* Placeholder in --max-colors=COLORS in --help output */ N_("COLORS") }, { NULL }};int __stdcallDllMain (HINSTANCE hinstDLL, DWORD dwReason, LPVOID reserved){ _gdk_dll_hinstance = hinstDLL; return TRUE;}void_gdk_windowing_init (void){ gchar buf[10];#ifdef HAVE_WINTAB if (getenv ("GDK_IGNORE_WINTAB") != NULL) _gdk_input_ignore_wintab = TRUE; else if (getenv ("GDK_USE_WINTAB") != NULL) _gdk_input_ignore_wintab = FALSE;#endif if (gdk_synchronize) GdiSetBatchLimit (1); _gdk_app_hmodule = GetModuleHandle (NULL); _gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL); _gdk_root_window = GetDesktopWindow (); _gdk_input_locale = GetKeyboardLayout (0); _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale); GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, buf, sizeof (buf)); _gdk_input_codepage = atoi (buf); GDK_NOTE (EVENTS, g_print ("input_locale:%p, codepage:%d\n", _gdk_input_locale, _gdk_input_codepage)); CoInitialize (NULL); _cf_rtf = RegisterClipboardFormat ("Rich Text Format"); _cf_utf8_string = RegisterClipboardFormat ("UTF8_STRING"); _utf8_string = gdk_atom_intern ("UTF8_STRING", FALSE); _targets = gdk_atom_intern ("TARGETS", FALSE); _text_uri_list = gdk_atom_intern ("text/uri-list", FALSE); _image_bmp = gdk_atom_intern ("image/bmp", FALSE); _local_dnd = gdk_atom_intern ("LocalDndSelection", FALSE); _gdk_win32_dropfiles = gdk_atom_intern ("DROPFILES_DND", FALSE); _gdk_ole2_dnd = gdk_atom_intern ("OLE2_DND", FALSE); _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE); _wm_transient_for = gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE); _gdk_win32_selection_init ();}void_gdk_win32_api_failed (const gchar *where, gint line, const gchar *api){ gchar *msg = g_win32_error_message (GetLastError ()); g_warning ("%s:%d: %s failed: %s", where, line, api, msg); g_free (msg);}void_gdk_other_api_failed (const gchar *where, gint line, const gchar *api){ g_warning ("%s:%d: %s failed", where, line, api);}void_gdk_win32_gdi_failed (const gchar *where, gint line, const gchar *api){ /* On Win9x GDI calls are implemented in 16-bit code and thus * don't set the 32-bit error code, sigh. */ if (G_WIN32_IS_NT_BASED ()) _gdk_win32_api_failed (where, line, api); else _gdk_other_api_failed (where, line, api);}voidgdk_set_use_xshm (gboolean use_xshm){ /* Always on */}gbooleangdk_get_use_xshm (void){ return TRUE;}gintgdk_screen_get_width (GdkScreen *screen){ return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->width;}gintgdk_screen_get_height (GdkScreen *screen){ return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->height;}gintgdk_screen_get_width_mm (GdkScreen *screen){ return (double) gdk_screen_get_width (screen) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSX) * 25.4;}gintgdk_screen_get_height_mm (GdkScreen *screen){ return (double) gdk_screen_get_height (screen) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSY) * 25.4;}void_gdk_windowing_display_set_sm_client_id (GdkDisplay *display, const gchar *sm_client_id){ g_warning("gdk_set_sm_client_id %s", sm_client_id ? sm_client_id : "NULL");}voidgdk_display_beep (GdkDisplay *display){ g_return_if_fail (display == gdk_display_get_default()); Beep(1000, 50);}void_gdk_windowing_exit (void){ _gdk_win32_dnd_exit (); CoUninitialize (); DeleteDC (_gdk_display_hdc); _gdk_display_hdc = NULL;}gchar *gdk_get_display (void){ return g_strdup (gdk_display_get_name (gdk_display_get_default ()));}voidgdk_error_trap_push (void){}gintgdk_error_trap_pop (void){ return 0;}voidgdk_notify_startup_complete (void){}#ifdef G_ENABLE_DEBUG/* * Like g_strdup_printf, but to a static buffer. Return value does not * have to be g_free()d. The buffer is of bounded size and reused * cyclically. Thus the return value is valid only until that part of * the buffer happens to get reused. This doesn't matter as this * function's return value is used in debugging output right after the call, * and the return value isn't used after that. */static gchar *static_printf (const gchar *format, ...){ static gchar buf[10000]; gchar *msg; static gchar *bufp = buf; gchar *retval; va_list args; va_start (args, format); msg = g_strdup_vprintf (format, args); va_end (args); g_assert (strlen (msg) < sizeof (buf)); if (bufp + strlen (msg) + 1 > buf + sizeof (buf)) bufp = buf; retval = bufp; strcpy (bufp, msg); bufp += strlen (msg) + 1; g_free (msg); return retval;}gchar *_gdk_win32_color_to_string (const GdkColor *color){ return static_printf ("(%.04x,%.04x,%.04x):%.06x", color->red, color->green, color->blue, color->pixel);}void_gdk_win32_print_paletteentries (const PALETTEENTRY *pep, const int nentries){ char buf[20]; int i; for (i = 0; i < nentries; i++) g_print (" %3d %02x: %02x %02x %02x%s\n", i, i, pep[i].peRed, pep[i].peGreen, pep[i].peBlue, (pep[i].peFlags == 0 ? "" : (pep[i].peFlags == PC_EXPLICIT ? " PC_EXPLICIT" : (pep[i].peFlags == PC_NOCOLLAPSE ? " PC_NOCOLLAPSE" : (pep[i].peFlags == PC_RESERVED ? " PC_RESERVED" : (g_sprintf (buf, " %d", pep[i].peFlags), buf))))));}void_gdk_win32_print_system_palette (void){ PALETTEENTRY *pe; int k; k = GetSystemPaletteEntries (_gdk_display_hdc, 0, 0, NULL); pe = g_new (PALETTEENTRY, k); k = GetSystemPaletteEntries (_gdk_display_hdc, 0, k, pe); if (!k) g_print ("GetSystemPaletteEntries failed: %s\n", g_win32_error_message (GetLastError ())); else { g_print ("System palette: %d entries\n", k); _gdk_win32_print_paletteentries (pe, k); } g_free (pe);}static gintpalette_size (HPALETTE hpal){ WORD npal = 0; if (!GetObject (hpal, sizeof (npal), &npal)) WIN32_GDI_FAILED ("GetObject (HPALETTE)"); return npal;}void_gdk_win32_print_hpalette (HPALETTE hpal){ PALETTEENTRY *pe; gint n, npal; npal = palette_size (hpal); pe = g_new (PALETTEENTRY, npal); n = GetPaletteEntries (hpal, 0, npal, pe); if (!n) g_print ("HPALETTE %p: GetPaletteEntries failed: %s\n", hpal, g_win32_error_message (GetLastError ())); else { g_print ("HPALETTE %p: %d (%d) entries\n", hpal, n, npal); _gdk_win32_print_paletteentries (pe, n); } g_free (pe);}void_gdk_win32_print_dc (HDC hdc){ HGDIOBJ obj; LOGBRUSH logbrush; EXTLOGPEN extlogpen; HRGN hrgn; RECT rect; int flag; g_print ("%p:\n", hdc); obj = GetCurrentObject (hdc, OBJ_BRUSH); GetObject (obj, sizeof (LOGBRUSH), &logbrush); g_print ("brush: %s color=%06lx hatch=%p\n", _gdk_win32_lbstyle_to_string (logbrush.lbStyle), logbrush.lbColor, (gpointer) logbrush.lbHatch); obj = GetCurrentObject (hdc, OBJ_PEN); GetObject (obj, sizeof (EXTLOGPEN), &extlogpen); g_print ("pen: %s %s %s %s w=%d %s\n", _gdk_win32_pstype_to_string (extlogpen.elpPenStyle), _gdk_win32_psstyle_to_string (extlogpen.elpPenStyle), _gdk_win32_psendcap_to_string (extlogpen.elpPenStyle), _gdk_win32_psjoin_to_string (extlogpen.elpPenStyle), extlogpen.elpWidth, _gdk_win32_lbstyle_to_string (extlogpen.elpBrushStyle)); g_print ("rop2: %s textcolor=%06lx\n", _gdk_win32_rop2_to_string (GetROP2 (hdc)), GetTextColor (hdc)); hrgn = CreateRectRgn (0, 0, 0, 0); if ((flag = GetClipRgn (hdc, hrgn)) == -1) WIN32_API_FAILED ("GetClipRgn"); else if (flag == 0) g_print ("no clip region\n"); else if (flag == 1) { GetRgnBox (hrgn, &rect); g_print ("clip region: %p bbox: %s\n", hrgn, _gdk_win32_rect_to_string (&rect)); } DeleteObject (hrgn);}gchar *_gdk_win32_cap_style_to_string (GdkCapStyle cap_style){ switch (cap_style) {#define CASE(x) case GDK_CAP_##x: return #x CASE (NOT_LAST); CASE (BUTT); CASE (ROUND); CASE (PROJECTING);#undef CASE default: return static_printf ("illegal_%d", cap_style); } /* NOTREACHED */ return NULL;}gchar *_gdk_win32_fill_style_to_string (GdkFill fill){ switch (fill) {#define CASE(x) case GDK_##x: return #x CASE (SOLID); CASE (TILED); CASE (STIPPLED); CASE (OPAQUE_STIPPLED);#undef CASE default: return static_printf ("illegal_%d", fill); } /* NOTREACHED */ return NULL;}gchar *_gdk_win32_function_to_string (GdkFunction function){ switch (function) {#define CASE(x) case GDK_##x: return #x CASE (COPY); CASE (INVERT); CASE (XOR); CASE (CLEAR); CASE (AND); CASE (AND_REVERSE); CASE (AND_INVERT); CASE (NOOP); CASE (OR); CASE (EQUIV); CASE (OR_REVERSE); CASE (COPY_INVERT); CASE (OR_INVERT); CASE (NAND); CASE (SET);#undef CASE default: return static_printf ("illegal_%d", function); } /* NOTREACHED */ return NULL; }gchar *_gdk_win32_join_style_to_string (GdkJoinStyle join_style){ switch (join_style) {#define CASE(x) case GDK_JOIN_##x: return #x CASE (MITER); CASE (ROUND); CASE (BEVEL);#undef CASE default: return static_printf ("illegal_%d", join_style); } /* NOTREACHED */ return NULL; }gchar *_gdk_win32_line_style_to_string (GdkLineStyle line_style){ switch (line_style) {#define CASE(x) case GDK_LINE_##x: return #x CASE(SOLID); CASE(ON_OFF_DASH); CASE(DOUBLE_DASH); #undef CASE default: return static_printf ("illegal_%d", line_style); } /* NOTREACHED */ return NULL; }gchar *_gdk_win32_gcvalues_mask_to_string (GdkGCValuesMask mask){ gchar buf[400]; gchar *bufp = buf; gchar *s = ""; buf[0] = '\0';#define BIT(x) \ if (mask & GDK_GC_##x) \ (bufp += g_sprintf (bufp, "%s" #x, s), s = "|") BIT (FOREGROUND); BIT (BACKGROUND); BIT (FONT); BIT (FUNCTION); BIT (FILL); BIT (TILE); BIT (STIPPLE); BIT (CLIP_MASK); BIT (SUBWINDOW); BIT (TS_X_ORIGIN);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -