]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkproperty-win32.c
gdk/win32/gdkprivate-win32.h gdk/win32/gdkglobals-win32.c Add more
[~andy/gtk] / gdk / win32 / gdkproperty-win32.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 1998-2002 Tor Lillqvist
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
26  */
27
28 #include <config.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <glib/gprintf.h>
32
33 #include "gdkscreen.h"
34 #include "gdkproperty.h"
35 #include "gdkselection.h"
36 #include "gdkprivate-win32.h"
37
38 GdkAtom
39 gdk_atom_intern (const gchar *atom_name,
40                  gint         only_if_exists)
41 {
42   ATOM win32_atom;
43   GdkAtom retval;
44   static GHashTable *atom_hash = NULL;
45   
46   if (!atom_hash)
47     atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
48
49   retval = g_hash_table_lookup (atom_hash, atom_name);
50   if (!retval)
51     {
52       if (strcmp (atom_name, "PRIMARY") == 0)
53         retval = GDK_SELECTION_PRIMARY;
54       else if (strcmp (atom_name, "SECONDARY") == 0)
55         retval = GDK_SELECTION_SECONDARY;
56       else if (strcmp (atom_name, "CLIPBOARD") == 0)
57         retval = GDK_SELECTION_CLIPBOARD;
58       else if (strcmp (atom_name, "ATOM") == 0)
59         retval = GDK_SELECTION_TYPE_ATOM;
60       else if (strcmp (atom_name, "BITMAP") == 0)
61         retval = GDK_SELECTION_TYPE_BITMAP;
62       else if (strcmp (atom_name, "COLORMAP") == 0)
63         retval = GDK_SELECTION_TYPE_COLORMAP;
64       else if (strcmp (atom_name, "DRAWABLE") == 0)
65         retval = GDK_SELECTION_TYPE_DRAWABLE;
66       else if (strcmp (atom_name, "INTEGER") == 0)
67         retval = GDK_SELECTION_TYPE_INTEGER;
68       else if (strcmp (atom_name, "PIXMAP") == 0)
69         retval = GDK_SELECTION_TYPE_PIXMAP;
70       else if (strcmp (atom_name, "WINDOW") == 0)
71         retval = GDK_SELECTION_TYPE_WINDOW;
72       else if (strcmp (atom_name, "STRING") == 0)
73         retval = GDK_SELECTION_TYPE_STRING;
74       else
75         {
76           win32_atom = GlobalAddAtom (atom_name);
77           retval = GUINT_TO_POINTER ((guint) win32_atom);
78         }
79       g_hash_table_insert (atom_hash, 
80                            g_strdup (atom_name), 
81                            retval);
82     }
83
84   return retval;
85 }
86
87 GdkAtom
88 gdk_atom_intern_static_string (const gchar *atom_name)
89 {
90   /* on X11 this is supposed to save memory. On win32 there seems to be
91    * no way to make a difference ?
92    */
93   return gdk_atom_intern (atom_name, FALSE);
94 }
95
96 gchar *
97 gdk_atom_name (GdkAtom atom)
98 {
99   ATOM win32_atom;
100   gchar name[256];
101
102   if (GDK_SELECTION_PRIMARY == atom) return g_strdup ("PRIMARY");
103   else if (GDK_SELECTION_SECONDARY == atom) return g_strdup ("SECONDARY");
104   else if (GDK_SELECTION_CLIPBOARD == atom) return g_strdup ("CLIPBOARD");
105   else if (GDK_SELECTION_TYPE_ATOM == atom) return g_strdup ("ATOM");
106   else if (GDK_SELECTION_TYPE_BITMAP == atom) return g_strdup ("BITMAP");
107   else if (GDK_SELECTION_TYPE_COLORMAP == atom) return g_strdup ("COLORMAP");
108   else if (GDK_SELECTION_TYPE_DRAWABLE == atom) return g_strdup ("DRAWABLE");
109   else if (GDK_SELECTION_TYPE_INTEGER == atom) return g_strdup ("INTEGER");
110   else if (GDK_SELECTION_TYPE_PIXMAP == atom) return g_strdup ("PIXMAP");
111   else if (GDK_SELECTION_TYPE_WINDOW == atom) return g_strdup ("WINDOW");
112   else if (GDK_SELECTION_TYPE_STRING == atom) return g_strdup ("STRING");
113   
114   win32_atom = GPOINTER_TO_UINT (atom);
115   
116   if (win32_atom < 0xC000)
117     return g_strdup_printf ("#%p", atom);
118   else if (GlobalGetAtomName (win32_atom, name, sizeof (name)) == 0)
119     return NULL;
120   return g_strdup (name);
121 }
122
123 gint
124 gdk_property_get (GdkWindow   *window,
125                   GdkAtom      property,
126                   GdkAtom      type,
127                   gulong       offset,
128                   gulong       length,
129                   gint         pdelete,
130                   GdkAtom     *actual_property_type,
131                   gint        *actual_format_type,
132                   gint        *actual_length,
133                   guchar     **data)
134 {
135   g_return_val_if_fail (window != NULL, FALSE);
136   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
137
138   if (GDK_WINDOW_DESTROYED (window))
139     return FALSE;
140
141   g_warning ("gdk_property_get: Not implemented");
142
143   return FALSE;
144 }
145
146 static gboolean
147 find_common_locale (const guchar  *data,
148                     gint           nelements,
149                     gint           nchars,
150                     LCID          *lcidp,
151                     guchar       **bufp,
152                     gint          *sizep)
153 {
154   static struct {
155     LCID lcid;
156     UINT cp;
157   } locales[] = {
158 #define ENTRY(lang, sublang) \
159  { MAKELCID (MAKELANGID (LANG_##lang, SUBLANG_##sublang), SORT_DEFAULT), 0 }
160     ENTRY (ENGLISH, DEFAULT),
161     ENTRY (POLISH, DEFAULT),
162     ENTRY (CZECH, DEFAULT),
163     ENTRY (LITHUANIAN, DEFAULT),
164     ENTRY (RUSSIAN, DEFAULT),
165     ENTRY (GREEK, DEFAULT),
166     ENTRY (TURKISH, DEFAULT),
167     ENTRY (HEBREW, DEFAULT),
168     ENTRY (ARABIC, DEFAULT),
169     ENTRY (THAI, DEFAULT),
170     ENTRY (JAPANESE, DEFAULT),
171     ENTRY (CHINESE, CHINESE_SIMPLIFIED),
172     ENTRY (CHINESE, CHINESE_TRADITIONAL),
173     ENTRY (KOREAN, DEFAULT),
174 #undef ENTRY
175   };
176
177   static gboolean been_here = FALSE;
178   gint i;
179   wchar_t *wcs;
180
181   /* For each installed locale: Get the locale's default code page,
182    * and store the list of locales and code pages.
183    */
184   if (!been_here)
185     {
186       been_here = TRUE;
187       for (i = 0; i < G_N_ELEMENTS (locales); i++)
188         if (IsValidLocale (locales[i].lcid, LCID_INSTALLED))
189           {
190             gchar buf[10];
191             if (GetLocaleInfo (locales[i].lcid, LOCALE_IDEFAULTANSICODEPAGE,
192                                buf, sizeof (buf)))
193               {
194                 gchar name[100];
195                 locales[i].cp = atoi (buf);
196                 GDK_NOTE (DND, (GetLocaleInfo (locales[i].lcid,
197                                                LOCALE_SENGLANGUAGE,
198                                                name, sizeof (name)),
199                                 g_print ("locale %#lx: %s: CP%d\n",
200                                          (gulong) locales[i].lcid, name,
201                                          locales[i].cp)));
202               }
203           }
204     }
205   
206   /* Allocate bufp big enough to store data in any code page.  Two
207    * bytes for each Unicode char should be enough, Windows code pages
208    * are either single- or double-byte.
209    */
210   *bufp = g_malloc ((nchars+1)*2);
211
212   /* Convert to Windows wide chars into temp buf */
213   wcs = g_utf8_to_utf16 (data, nelements, NULL, NULL, NULL);
214
215   /* For each code page that is the default for an installed locale: */
216   for (i = 0; i < G_N_ELEMENTS (locales); i++)
217     {
218       BOOL used_default;
219       int nbytes;
220
221       if (locales[i].cp == 0)
222         continue;
223
224       /* Convert to that code page into bufp */
225       
226       nbytes = WideCharToMultiByte (locales[i].cp, 0, wcs, -1,
227                                     *bufp, (nchars+1)*2,
228                                     NULL, &used_default);
229
230       if (!used_default)
231         {
232           /* This locale is good for the string */
233           g_free (wcs);
234           *lcidp = locales[i].lcid;
235           *sizep = nbytes;
236           return TRUE;
237         }
238     }
239
240   g_free (*bufp);
241   g_free (wcs);
242
243   return FALSE;
244 }
245
246 void
247 gdk_property_change (GdkWindow    *window,
248                      GdkAtom       property,
249                      GdkAtom       type,
250                      gint          format,
251                      GdkPropMode   mode,
252                      const guchar *data,
253                      gint          nelements)
254 {
255   HGLOBAL hdata, hlcid, hutf8;
256   UINT cf = 0;
257   LCID lcid;
258   LCID *lcidptr;
259   GString *rtf = NULL;
260   gint i, size, nchars;
261   gchar *prop_name, *type_name;
262   guchar *ucptr, *buf = NULL;
263   wchar_t *wcptr;
264   glong wclen;
265   enum { SYSTEM_CODEPAGE, UNICODE_TEXT, SINGLE_LOCALE, RICH_TEXT } method;
266   gboolean ok = TRUE;
267
268   g_return_if_fail (window != NULL);
269   g_return_if_fail (GDK_IS_WINDOW (window));
270
271   if (GDK_WINDOW_DESTROYED (window))
272     return;
273
274   GDK_NOTE (DND,
275             (prop_name = gdk_atom_name (property),
276              type_name = gdk_atom_name (type),
277              g_print ("gdk_property_change: %p %#x (%s) %#x (%s) %s %d*%d bytes: %s\n",
278                       GDK_WINDOW_HWND (window),
279                       (guint) property, prop_name,
280                       (guint) type, type_name,
281                       (mode == GDK_PROP_MODE_REPLACE ? "REPLACE" :
282                        (mode == GDK_PROP_MODE_PREPEND ? "PREPEND" :
283                         (mode == GDK_PROP_MODE_APPEND ? "APPEND" :
284                          "???"))),
285                       format, nelements,
286                       _gdk_win32_data_to_string (data, MIN (10, format*nelements/8))),
287              g_free (prop_name),
288              g_free (type_name)));
289
290   /* We should never come here for these types */
291   g_return_if_fail (type != GDK_TARGET_STRING);
292   g_return_if_fail (type != _text);
293   g_return_if_fail (type != _compound_text);
294   g_return_if_fail (type != _save_targets);
295
296   if (property == _gdk_selection_property
297       && format == 8
298       && mode == GDK_PROP_MODE_REPLACE)
299     {
300       if (type == _utf8_string)
301         {
302           if (!OpenClipboard (GDK_WINDOW_HWND (window)))
303             {
304               WIN32_API_FAILED ("OpenClipboard");
305               return;
306             }
307
308           nchars = g_utf8_strlen (data, nelements);
309
310           /* Check if only ASCII */
311           for (i = 0; i < nelements; i++)
312             if (data[i] >= 0200)
313               break;
314
315           if (i == nelements)
316             {
317               /* If UTF-8 and only ASCII, use CF_TEXT and the data as
318                * such.
319                */
320               method = SYSTEM_CODEPAGE;
321               size = nelements;
322               for (i = 0; i < nelements; i++)
323                 if (data[i] == '\n')
324                   size++;
325               size++;
326               GDK_NOTE (DND, g_print ("... as text: %.40s\n", data));
327             }
328           else if (G_WIN32_IS_NT_BASED ())
329             {
330               /* On NT, use CF_UNICODETEXT if any non-system codepage
331                * char present.
332                */
333               method = UNICODE_TEXT;
334
335               wcptr = g_utf8_to_utf16 (data, nelements, NULL, &wclen, NULL);
336
337               wclen++;          /* Terminating 0 */
338               size = wclen * 2;
339               GDK_NOTE (DND, g_print ("... as Unicode\n"));
340             }
341           else if (find_common_locale (data, nelements, nchars, &lcid, &buf, &size))
342             {
343               /* On Win9x, if all chars are in the default code page
344                * of some installed locale, use CF_TEXT and CF_LOCALE.
345                */
346               method = SINGLE_LOCALE;
347               GDK_NOTE (DND, g_print ("... as text in locale %#lx %d bytes\n",
348                                       (gulong) lcid, size));
349             }
350           else
351             {
352               /* On Win9x, otherwise use RTF */
353
354               const guchar *p = data;
355
356               /* WordPad on XP, at least, doesn't seem to grok \uc0
357                * -encoded Unicode characters. Oh well, use \uc1 then,
358                * with a question mark as the "ANSI" stand-in for each
359                * non-ASCII Unicode character. (WordPad for XP? This
360                * code path is for Win9x! Yes, but I don't have Win9x,
361                * so I use XP to test, using the G_WIN32_PRETEND_WIN9X
362                * environment variable.)
363                */
364               method = RICH_TEXT;
365               rtf = g_string_new ("{\\rtf1\\uc1 ");
366
367               while (p < data + nelements)
368                 {
369                   if (*p == '{' ||
370                       *p == '\\' ||
371                       *p == '}')
372                     {
373                       rtf = g_string_append_c (rtf, '\\');
374                       rtf = g_string_append_c (rtf, *p);
375                       p++;
376                     }
377                   else if (*p < 0200 && *p >= ' ')
378                     {
379                       rtf = g_string_append_c (rtf, *p);
380                       p++;
381                     }
382                   else
383                     {
384                       guchar *q;
385                       gint n;
386                       
387                       rtf = g_string_append (rtf, "\\uNNNNN ?");
388                       rtf->len -= 7; /* five digits a space and a question mark */
389                       q = rtf->str + rtf->len;
390                       n = g_sprintf (q, "%d ?", g_utf8_get_char (p));
391                       g_assert (n <= 7);
392                       rtf->len += n;
393                       
394                       p = g_utf8_next_char (p);
395                     }
396                 }
397               rtf = g_string_append (rtf, "}");
398               size = rtf->len + 1;
399               GDK_NOTE (DND, g_print ("... as RTF: %.40s\n", rtf->str));
400             }
401           
402           if (!(hdata = GlobalAlloc (GMEM_MOVEABLE, size)))
403             {
404               WIN32_API_FAILED ("GlobalAlloc");
405               if (!CloseClipboard ())
406                 WIN32_API_FAILED ("CloseClipboard");
407               if (buf != NULL)
408                 g_free (buf);
409               if (rtf != NULL)
410                 g_string_free (rtf, TRUE);
411               return;
412             }
413
414           ucptr = GlobalLock (hdata);
415
416           switch (method)
417             {
418             case SYSTEM_CODEPAGE:
419               cf = CF_TEXT;
420               for (i = 0; i < nelements; i++)
421                 {
422                   if (data[i] == '\n')
423                     *ucptr++ = '\r';
424                   *ucptr++ = data[i];
425                 }
426               *ucptr++ = '\0';
427               break;
428
429             case UNICODE_TEXT:
430               cf = CF_UNICODETEXT;
431               memmove (ucptr, wcptr, size);
432               g_free (wcptr);
433               break;
434
435             case SINGLE_LOCALE:
436               cf = CF_TEXT;
437               memmove (ucptr, buf, size);
438               g_free (buf);
439
440               /* Set the CF_LOCALE clipboard data, too */
441               if (!(hlcid = GlobalAlloc (GMEM_MOVEABLE, sizeof (LCID))))
442                 WIN32_API_FAILED ("GlobalAlloc"), ok = FALSE;
443               if (ok)
444                 {
445                   lcidptr = GlobalLock (hlcid);
446                   *lcidptr = lcid;
447                   GlobalUnlock (hlcid);
448                   GDK_NOTE (DND, g_print ("... SetClipboardData(CF_LOCALE,%p)\n",
449                                           hlcid));
450                   if (!SetClipboardData (CF_LOCALE, hlcid))
451                     WIN32_API_FAILED ("SetClipboardData(CF_LOCALE)"), ok = FALSE;
452                 }
453               break;
454
455             case RICH_TEXT:
456               cf = _cf_rtf;
457               memmove (ucptr, rtf->str, size);
458               g_string_free (rtf, TRUE);
459
460               /* Set the UTF8_STRING clipboard data, too, for other
461                * GTK+ apps to use (won't bother reading RTF).
462                */
463               if (!(hutf8 = GlobalAlloc (GMEM_MOVEABLE, nelements)))
464                 WIN32_API_FAILED ("GlobalAlloc");
465               else
466                 {
467                   guchar *utf8ptr = GlobalLock (hutf8);
468                   memmove (utf8ptr, data, nelements);
469                   GlobalUnlock (hutf8);
470                   GDK_NOTE (DND, g_print ("... SetClipboardData('UTF8_STRING',%p)\n",
471                                           hutf8));
472                   if (!SetClipboardData (_cf_utf8_string, hutf8))
473                     WIN32_API_FAILED ("SetClipboardData('UTF8_STRING')");
474                 }
475               break;
476
477             default:
478               g_assert_not_reached ();
479             }
480
481           GlobalUnlock (hdata);
482           GDK_NOTE (DND, g_print ("... SetClipboardData(%s,%p)\n",
483                                   _gdk_win32_cf_to_string (cf), hdata));
484           if (ok && !SetClipboardData (cf, hdata))
485             WIN32_API_FAILED ("SetClipboardData"), ok = FALSE;
486       
487           if (!CloseClipboard ())
488             WIN32_API_FAILED ("CloseClipboard");
489         }
490       else
491         {
492           GDK_NOTE (DND, g_print ("... delayed rendering\n"));
493           /* Delayed Rendering. We can't assign hdata to the clipboard
494            * here as type may be "image/png", "image/jpg", etc.  In
495            * this case there's a further conversion afterwards.
496            */
497           _delayed_rendering_data = NULL;
498           if (!(hdata = GlobalAlloc (GMEM_MOVEABLE, nelements > 0 ? nelements : 1)))
499             {
500               WIN32_API_FAILED ("GlobalAlloc");
501               return;
502             }
503           ucptr = GlobalLock (hdata);
504           memcpy (ucptr, data, nelements);
505           GlobalUnlock (hdata);
506           _delayed_rendering_data = hdata;
507         }
508     }
509   else
510     g_warning ("gdk_property_change: General case not implemented");
511 }
512
513 void
514 gdk_property_delete (GdkWindow *window,
515                      GdkAtom    property)
516 {
517   gchar *prop_name;
518
519   g_return_if_fail (window != NULL);
520   g_return_if_fail (GDK_IS_WINDOW (window));
521
522   GDK_NOTE (DND,
523             (prop_name = gdk_atom_name (property),
524              g_print ("gdk_property_delete: %p %#x (%s)\n",
525                       GDK_WINDOW_HWND (window),
526                       (guint) property, prop_name),
527              g_free (prop_name)));
528
529   if (property == _gdk_selection_property)
530     _gdk_selection_property_delete (window);
531   else if (property == _wm_transient_for)
532     gdk_window_set_transient_for (window, _gdk_root);
533   else
534     {
535       prop_name = gdk_atom_name (property);
536       g_warning ("gdk_property_delete: General case (%s) not implemented",
537                  prop_name);
538       g_free (prop_name);
539     }
540 }
541
542 /*
543   for reference copied from gdk/x11/gdkevents-x11.c
544
545   { "Net/DoubleClickTime", "gtk-double-click-time" },
546   { "Net/DoubleClickDistance", "gtk-double-click-distance" },
547   { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
548   { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
549   { "Gtk/ColorPalette", "gtk-color-palette" },
550   { "Gtk/FontName", "gtk-font-name" },
551   { "Gtk/IconSizes", "gtk-icon-sizes" },
552   { "Gtk/KeyThemeName", "gtk-key-theme-name" },
553   { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
554   { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
555   { "Gtk/IMPreeditStyle", "gtk-im-preedit-style" },
556   { "Gtk/IMStatusStyle", "gtk-im-status-style" },
557   { "Net/CursorBlink", "gtk-cursor-blink" },
558   { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
559   { "Net/ThemeName", "gtk-theme-name" },
560   { "Net/IconThemeName", "gtk-icon-theme-name" },
561   { "Gtk/ButtonImages", "gtk-button-images" },
562   { "Gtk/MenuImages", "gtk-menu-images" },
563   { "Xft/Antialias", "gtk-xft-antialias" },
564   { "Xft/Hinting", "gtk-xft-hinting" },
565   { "Xft/HintStyle", "gtk-xft-hintstyle" },
566   { "Xft/RGBA", "gtk-xft-rgba" },
567   { "Xft/DPI", "gtk-xft-dpi" },
568
569   // more spread in gtk sources
570   gtk-entry-select-on-focus
571   gtk-cursor-blink
572   gtk-cursor-blink-time
573   gtk-split-cursor
574
575 */
576 gboolean
577 gdk_screen_get_setting (GdkScreen   *screen,
578                         const gchar *name,
579                         GValue      *value)
580 {
581   g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
582
583   /*
584    * XXX : if these values get changed through the Windoze UI the
585    *       respective gdk_events are not generated yet.
586    */
587   if (strcmp ("gtk-theme-name", name) == 0) 
588     {
589       g_value_set_string (value, "ms-windows");
590     }
591   else if (strcmp ("gtk-double-click-time", name) == 0)
592     {
593       gint i = GetDoubleClickTime ();
594       GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
595       g_value_set_int (value, i);
596       return TRUE;
597     }
598   else if (strcmp ("gtk-double-click-distance", name) == 0)
599     {
600       gint i = MAX(GetSystemMetrics (SM_CXDOUBLECLK), GetSystemMetrics (SM_CYDOUBLECLK));
601       GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
602       g_value_set_int (value, i);
603       return TRUE;
604     }
605   else if (strcmp ("gtk-dnd-drag-threshold", name) == 0)
606     {
607       gint i = MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG));
608       GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
609       g_value_set_int (value, i);
610       return TRUE;
611     }
612   else if (strcmp ("gtk-split-cursor", name) == 0)
613     {
614       GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : FALSE\n", name));
615       g_value_set_boolean (value, FALSE);
616       return TRUE;
617     }
618   else if (strcmp ("gtk-alternative-button-order", name) == 0)
619     {
620       GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : TRUE\n", name));
621       g_value_set_boolean (value, TRUE);
622       return TRUE;
623     }
624 #if 0
625   /*
626    * With 'MS Sans Serif' as windows menu font (default on win98se) you'll get a 
627    * bunch of :
628    *   WARNING **: Couldn't load font "MS Sans Serif 8" falling back to "Sans 8"
629    * at least with testfilechooser (regardless of the bitmap check below)
630    * so just disabling this code seems to be the best we can do --hb
631    */
632   else if (strcmp ("gtk-font-name", name) == 0)
633     {
634       NONCLIENTMETRICS ncm;
635       ncm.cbSize = sizeof(NONCLIENTMETRICS);
636       if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, FALSE))
637         {
638           /* Pango finally uses GetDeviceCaps to scale, we use simple
639            * approximation here.
640            */
641           int nHeight = (0 > ncm.lfMenuFont.lfHeight ? -3*ncm.lfMenuFont.lfHeight/4 : 10);
642           if (OUT_STRING_PRECIS == ncm.lfMenuFont.lfOutPrecision)
643             GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : ignoring bitmap font '%s'\n", 
644                                    name, ncm.lfMenuFont.lfFaceName));
645           else if (ncm.lfMenuFont.lfFaceName && strlen(ncm.lfMenuFont.lfFaceName) > 0 &&
646                    /* Avoid issues like those described in bug #135098 */
647                    g_utf8_validate (ncm.lfMenuFont.lfFaceName, -1, NULL))
648             {
649               char* s = g_strdup_printf ("%s %d", ncm.lfMenuFont.lfFaceName, nHeight);
650               GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : %s\n", name, s));
651               g_value_set_string (value, s);
652
653               g_free(s);
654               return TRUE;
655             }
656         }
657     }
658 #endif
659
660   GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) not handled\n", name));
661   return FALSE;
662 }