gdkproperty-win32.c 19.5 KB
Newer Older
1
2
/* GDK - The GIMP Drawing Kit
 * 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
8
9
10
11
12
 * 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
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
17
18
19
20
21
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
22
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23
24
25
26
27
 * 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/. 
 */

28
#include <config.h>
29
#include <string.h>
30
#include <stdlib.h>
31
#include <glib/gprintf.h>
32

33
#include "gdkscreen.h"
34
35
#include "gdkproperty.h"
#include "gdkselection.h"
36
#include "gdkprivate-win32.h"
37
38
39
40
41

GdkAtom
gdk_atom_intern (const gchar *atom_name,
		 gint         only_if_exists)
{
42
  ATOM win32_atom;
43
44
45
46
47
48
  GdkAtom retval;
  static GHashTable *atom_hash = NULL;
  
  if (!atom_hash)
    atom_hash = g_hash_table_new (g_str_hash, g_str_equal);

49
  retval = g_hash_table_lookup (atom_hash, atom_name);
50
51
52
53
54
55
  if (!retval)
    {
      if (strcmp (atom_name, "PRIMARY") == 0)
	retval = GDK_SELECTION_PRIMARY;
      else if (strcmp (atom_name, "SECONDARY") == 0)
	retval = GDK_SELECTION_SECONDARY;
56
57
      else if (strcmp (atom_name, "CLIPBOARD") == 0)
	retval = GDK_SELECTION_CLIPBOARD;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
      else if (strcmp (atom_name, "ATOM") == 0)
	retval = GDK_SELECTION_TYPE_ATOM;
      else if (strcmp (atom_name, "BITMAP") == 0)
	retval = GDK_SELECTION_TYPE_BITMAP;
      else if (strcmp (atom_name, "COLORMAP") == 0)
	retval = GDK_SELECTION_TYPE_COLORMAP;
      else if (strcmp (atom_name, "DRAWABLE") == 0)
	retval = GDK_SELECTION_TYPE_DRAWABLE;
      else if (strcmp (atom_name, "INTEGER") == 0)
	retval = GDK_SELECTION_TYPE_INTEGER;
      else if (strcmp (atom_name, "PIXMAP") == 0)
	retval = GDK_SELECTION_TYPE_PIXMAP;
      else if (strcmp (atom_name, "WINDOW") == 0)
	retval = GDK_SELECTION_TYPE_WINDOW;
      else if (strcmp (atom_name, "STRING") == 0)
	retval = GDK_SELECTION_TYPE_STRING;
      else
	{
76
	  win32_atom = GlobalAddAtom (atom_name);
77
	  retval = GUINT_TO_POINTER ((guint) win32_atom);
78
	}
79
80
81
      g_hash_table_insert (atom_hash, 
			   g_strdup (atom_name), 
			   retval);
82
83
84
85
86
    }

  return retval;
}

87
88
89
90
91
92
93
94
95
GdkAtom
gdk_atom_intern_static_string (const gchar *atom_name)
{
  /* on X11 this is supposed to save memory. On win32 there seems to be
   * no way to make a difference ?
   */
  return gdk_atom_intern (atom_name, FALSE);
}

96
97
98
gchar *
gdk_atom_name (GdkAtom atom)
{
99
  ATOM win32_atom;
100
  gchar name[256];
101

Hans Breuer's avatar
Hans Breuer committed
102
103
104
105
106
107
108
109
110
111
112
  if (GDK_SELECTION_PRIMARY == atom) return g_strdup ("PRIMARY");
  else if (GDK_SELECTION_SECONDARY == atom) return g_strdup ("SECONDARY");
  else if (GDK_SELECTION_CLIPBOARD == atom) return g_strdup ("CLIPBOARD");
  else if (GDK_SELECTION_TYPE_ATOM == atom) return g_strdup ("ATOM");
  else if (GDK_SELECTION_TYPE_BITMAP == atom) return g_strdup ("BITMAP");
  else if (GDK_SELECTION_TYPE_COLORMAP == atom) return g_strdup ("COLORMAP");
  else if (GDK_SELECTION_TYPE_DRAWABLE == atom) return g_strdup ("DRAWABLE");
  else if (GDK_SELECTION_TYPE_INTEGER == atom) return g_strdup ("INTEGER");
  else if (GDK_SELECTION_TYPE_PIXMAP == atom) return g_strdup ("PIXMAP");
  else if (GDK_SELECTION_TYPE_WINDOW == atom) return g_strdup ("WINDOW");
  else if (GDK_SELECTION_TYPE_STRING == atom) return g_strdup ("STRING");
113
114
115
116
  
  win32_atom = GPOINTER_TO_UINT (atom);
  
  if (win32_atom < 0xC000)
117
    return g_strdup_printf ("#%p", atom);
118
  else if (GlobalGetAtomName (win32_atom, name, sizeof (name)) == 0)
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    return NULL;
  return g_strdup (name);
}

gint
gdk_property_get (GdkWindow   *window,
		  GdkAtom      property,
		  GdkAtom      type,
		  gulong       offset,
		  gulong       length,
		  gint         pdelete,
		  GdkAtom     *actual_property_type,
		  gint        *actual_format_type,
		  gint        *actual_length,
		  guchar     **data)
{
135
  g_return_val_if_fail (window != NULL, FALSE);
136
  g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
137

Tor Lillqvist's avatar
Tor Lillqvist committed
138
  if (GDK_WINDOW_DESTROYED (window))
139
140
    return FALSE;

141
142
143
144
145
  g_warning ("gdk_property_get: Not implemented");

  return FALSE;
}

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
static gboolean
find_common_locale (const guchar  *data,
		    gint           nelements,
		    gint           nchars,
		    LCID          *lcidp,
		    guchar       **bufp,
		    gint          *sizep)
{
  static struct {
    LCID lcid;
    UINT cp;
  } locales[] = {
#define ENTRY(lang, sublang) \
 { MAKELCID (MAKELANGID (LANG_##lang, SUBLANG_##sublang), SORT_DEFAULT), 0 }
    ENTRY (ENGLISH, DEFAULT),
    ENTRY (POLISH, DEFAULT),
    ENTRY (CZECH, DEFAULT),
    ENTRY (LITHUANIAN, DEFAULT),
    ENTRY (RUSSIAN, DEFAULT),
    ENTRY (GREEK, DEFAULT),
    ENTRY (TURKISH, DEFAULT),
    ENTRY (HEBREW, DEFAULT),
    ENTRY (ARABIC, DEFAULT),
    ENTRY (THAI, DEFAULT),
    ENTRY (JAPANESE, DEFAULT),
    ENTRY (CHINESE, CHINESE_SIMPLIFIED),
    ENTRY (CHINESE, CHINESE_TRADITIONAL),
    ENTRY (KOREAN, DEFAULT),
#undef ENTRY
  };

  static gboolean been_here = FALSE;
  gint i;
  wchar_t *wcs;

  /* For each installed locale: Get the locale's default code page,
   * and store the list of locales and code pages.
   */
  if (!been_here)
    {
      been_here = TRUE;
      for (i = 0; i < G_N_ELEMENTS (locales); i++)
	if (IsValidLocale (locales[i].lcid, LCID_INSTALLED))
	  {
	    gchar buf[10];
	    if (GetLocaleInfo (locales[i].lcid, LOCALE_IDEFAULTANSICODEPAGE,
			       buf, sizeof (buf)))
	      {
		gchar name[100];
		locales[i].cp = atoi (buf);
		GDK_NOTE (DND, (GetLocaleInfo (locales[i].lcid,
					       LOCALE_SENGLANGUAGE,
					       name, sizeof (name)),
				g_print ("locale %#lx: %s: CP%d\n",
					 (gulong) locales[i].lcid, name,
					 locales[i].cp)));
	      }
	  }
    }
  
  /* Allocate bufp big enough to store data in any code page.  Two
   * bytes for each Unicode char should be enough, Windows code pages
   * are either single- or double-byte.
   */
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

  /* For each code page that is the default for an installed locale: */
  for (i = 0; i < G_N_ELEMENTS (locales); i++)
    {
      BOOL used_default;
      int nbytes;

      if (locales[i].cp == 0)
	continue;

      /* Convert to that code page into bufp */
      
      nbytes = WideCharToMultiByte (locales[i].cp, 0, wcs, -1,
				    *bufp, (nchars+1)*2,
				    NULL, &used_default);

      if (!used_default)
	{
	  /* This locale is good for the string */
	  g_free (wcs);
	  *lcidp = locales[i].lcid;
	  *sizep = nbytes;
	  return TRUE;
	}
    }

  g_free (*bufp);
  g_free (wcs);

  return FALSE;
}

246
void
247
248
249
250
251
252
253
gdk_property_change (GdkWindow    *window,
		     GdkAtom       property,
		     GdkAtom       type,
		     gint          format,
		     GdkPropMode   mode,
		     const guchar *data,
		     gint          nelements)
254
{
255
256
257
258
259
260
  HGLOBAL hdata, hlcid, hutf8;
  UINT cf = 0;
  LCID lcid;
  LCID *lcidptr;
  GString *rtf = NULL;
  gint i, size, nchars;
261
  gchar *prop_name, *type_name;
262
263
  guchar *ucptr, *buf = NULL;
  wchar_t *wcptr;
264
265
  glong wclen;
  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

Tor Lillqvist's avatar
Tor Lillqvist committed
271
  if (GDK_WINDOW_DESTROYED (window))
272
273
    return;

274
  GDK_NOTE (DND,
275
276
	    (prop_name = gdk_atom_name (property),
	     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
280
		      (guint) property, prop_name,
		      (guint) type, type_name,
281
282
283
284
		      (mode == GDK_PROP_MODE_REPLACE ? "REPLACE" :
		       (mode == GDK_PROP_MODE_PREPEND ? "PREPEND" :
			(mode == GDK_PROP_MODE_APPEND ? "APPEND" :
			 "???"))),
285
286
		      format, nelements,
		      _gdk_win32_data_to_string (data, MIN (10, format*nelements/8))),
287
288
289
	     g_free (prop_name),
	     g_free (type_name)));

290
291
292
293
294
295
  /* We should never come here for these types */
  g_return_if_fail (type != GDK_TARGET_STRING);
  g_return_if_fail (type != _text);
  g_return_if_fail (type != _compound_text);
  g_return_if_fail (type != _save_targets);

296
  if (property == _gdk_selection_property
297
298
299
      && format == 8
      && mode == GDK_PROP_MODE_REPLACE)
    {
300
      if (type == _utf8_string)
301
	{
302
303
304
305
306
	  if (!OpenClipboard (GDK_WINDOW_HWND (window)))
	    {
	      WIN32_API_FAILED ("OpenClipboard");
	      return;
	    }
307

308
	  nchars = g_utf8_strlen (data, nelements);
309

310
311
312
313
314
	  /* Check if only ASCII */
	  for (i = 0; i < nelements; i++)
	    if (data[i] >= 0200)
	      break;

315
316
	  if (i == nelements)
	    {
317
318
	      /* If UTF-8 and only ASCII, use CF_TEXT and the data as
	       * such.
319
320
321
322
323
324
	       */
	      method = SYSTEM_CODEPAGE;
	      size = nelements;
	      for (i = 0; i < nelements; i++)
		if (data[i] == '\n')
		  size++;
325
	      size++;
326
327
328
329
330
331
332
333
	      GDK_NOTE (DND, g_print ("... as text: %.40s\n", data));
	    }
	  else if (G_WIN32_IS_NT_BASED ())
	    {
	      /* On NT, use CF_UNICODETEXT if any non-system codepage
	       * char present.
	       */
	      method = UNICODE_TEXT;
334

335
	      wcptr = g_utf8_to_utf16 (data, nelements, NULL, &wclen, NULL);
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
	      wclen++;		/* Terminating 0 */
	      size = wclen * 2;
	      GDK_NOTE (DND, g_print ("... as Unicode\n"));
	    }
	  else if (find_common_locale (data, nelements, nchars, &lcid, &buf, &size))
	    {
	      /* On Win9x, if all chars are in the default code page
	       * of some installed locale, use CF_TEXT and CF_LOCALE.
	       */
	      method = SINGLE_LOCALE;
	      GDK_NOTE (DND, g_print ("... as text in locale %#lx %d bytes\n",
				      (gulong) lcid, size));
	    }
	  else
	    {
	      /* On Win9x, otherwise use RTF */

	      const guchar *p = data;

356
357
358
359
360
361
362
363
	      /* WordPad on XP, at least, doesn't seem to grok \uc0
	       * -encoded Unicode characters. Oh well, use \uc1 then,
	       * with a question mark as the "ANSI" stand-in for each
	       * non-ASCII Unicode character. (WordPad for XP? This
	       * code path is for Win9x! Yes, but I don't have Win9x,
	       * so I use XP to test, using the G_WIN32_PRETEND_WIN9X
	       * environment variable.)
	       */
364
	      method = RICH_TEXT;
365
	      rtf = g_string_new ("{\\rtf1\\uc1 ");
366

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
	      while (p < data + nelements)
		{
		  if (*p == '{' ||
		      *p == '\\' ||
		      *p == '}')
		    {
		      rtf = g_string_append_c (rtf, '\\');
		      rtf = g_string_append_c (rtf, *p);
		      p++;
		    }
		  else if (*p < 0200 && *p >= ' ')
		    {
		      rtf = g_string_append_c (rtf, *p);
		      p++;
		    }
		  else
		    {
		      guchar *q;
		      gint n;
		      
387
388
		      rtf = g_string_append (rtf, "\\uNNNNN ?");
		      rtf->len -= 7; /* five digits a space and a question mark */
389
		      q = rtf->str + rtf->len;
390
391
		      n = g_sprintf (q, "%d ?", g_utf8_get_char (p));
		      g_assert (n <= 7);
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
		      rtf->len += n;
		      
		      p = g_utf8_next_char (p);
		    }
		}
	      rtf = g_string_append (rtf, "}");
	      size = rtf->len + 1;
	      GDK_NOTE (DND, g_print ("... as RTF: %.40s\n", rtf->str));
	    }
	  
	  if (!(hdata = GlobalAlloc (GMEM_MOVEABLE, size)))
	    {
	      WIN32_API_FAILED ("GlobalAlloc");
	      if (!CloseClipboard ())
		WIN32_API_FAILED ("CloseClipboard");
	      if (buf != NULL)
		g_free (buf);
	      if (rtf != NULL)
		g_string_free (rtf, TRUE);
	      return;
	    }
413

414
	  ucptr = GlobalLock (hdata);
415

416
	  switch (method)
417
	    {
418
419
420
	    case SYSTEM_CODEPAGE:
	      cf = CF_TEXT;
	      for (i = 0; i < nelements; i++)
421
		{
422
423
424
		  if (data[i] == '\n')
		    *ucptr++ = '\r';
		  *ucptr++ = data[i];
425
		}
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
	      *ucptr++ = '\0';
	      break;

	    case UNICODE_TEXT:
	      cf = CF_UNICODETEXT;
	      memmove (ucptr, wcptr, size);
	      g_free (wcptr);
	      break;

	    case SINGLE_LOCALE:
	      cf = CF_TEXT;
	      memmove (ucptr, buf, size);
	      g_free (buf);

	      /* Set the CF_LOCALE clipboard data, too */
	      if (!(hlcid = GlobalAlloc (GMEM_MOVEABLE, sizeof (LCID))))
		WIN32_API_FAILED ("GlobalAlloc"), ok = FALSE;
	      if (ok)
444
		{
445
446
447
		  lcidptr = GlobalLock (hlcid);
		  *lcidptr = lcid;
		  GlobalUnlock (hlcid);
448
449
		  GDK_NOTE (DND, g_print ("... SetClipboardData(CF_LOCALE,%p)\n",
					  hlcid));
450
		  if (!SetClipboardData (CF_LOCALE, hlcid))
451
		    WIN32_API_FAILED ("SetClipboardData(CF_LOCALE)"), ok = FALSE;
452
		}
453
454
455
456
457
458
459
460
461
462
463
464
	      break;

	    case RICH_TEXT:
	      cf = _cf_rtf;
	      memmove (ucptr, rtf->str, size);
	      g_string_free (rtf, TRUE);

	      /* Set the UTF8_STRING clipboard data, too, for other
	       * GTK+ apps to use (won't bother reading RTF).
	       */
	      if (!(hutf8 = GlobalAlloc (GMEM_MOVEABLE, nelements)))
		WIN32_API_FAILED ("GlobalAlloc");
465
466
	      else
		{
467
468
469
		  guchar *utf8ptr = GlobalLock (hutf8);
		  memmove (utf8ptr, data, nelements);
		  GlobalUnlock (hutf8);
470
471
		  GDK_NOTE (DND, g_print ("... SetClipboardData('UTF8_STRING',%p)\n",
					  hutf8));
472
		  if (!SetClipboardData (_cf_utf8_string, hutf8))
473
		    WIN32_API_FAILED ("SetClipboardData('UTF8_STRING')");
474
		}
475
476
477
478
	      break;

	    default:
	      g_assert_not_reached ();
479
	    }
480
481

	  GlobalUnlock (hdata);
482
483
	  GDK_NOTE (DND, g_print ("... SetClipboardData(%s,%p)\n",
				  _gdk_win32_cf_to_string (cf), hdata));
484
485
486
	  if (ok && !SetClipboardData (cf, hdata))
	    WIN32_API_FAILED ("SetClipboardData"), ok = FALSE;
      
487
488
489
	  if (!CloseClipboard ())
	    WIN32_API_FAILED ("CloseClipboard");
	}
490
491
      else
        {
492
	  GDK_NOTE (DND, g_print ("... delayed rendering\n"));
493
494
495
	  /* Delayed Rendering. We can't assign hdata to the clipboard
	   * here as type may be "image/png", "image/jpg", etc.  In
	   * this case there's a further conversion afterwards.
496
	   */
497
498
	  _delayed_rendering_data = NULL;
	  if (!(hdata = GlobalAlloc (GMEM_MOVEABLE, nelements > 0 ? nelements : 1)))
499
	    {
500
501
	      WIN32_API_FAILED ("GlobalAlloc");
	      return;
502
	    }
503
504
505
506
	  ucptr = GlobalLock (hdata);
	  memcpy (ucptr, data, nelements);
	  GlobalUnlock (hdata);
	  _delayed_rendering_data = hdata;
507
508
509
510
511
512
513
514
515
516
	}
    }
  else
    g_warning ("gdk_property_change: General case not implemented");
}

void
gdk_property_delete (GdkWindow *window,
		     GdkAtom    property)
{
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
525
	     g_print ("gdk_property_delete: %p %#x (%s)\n",
		      GDK_WINDOW_HWND (window),
526
		      (guint) property, prop_name),
527
528
	     g_free (prop_name)));

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
536
537
538
539
    {
      prop_name = gdk_atom_name (property);
      g_warning ("gdk_property_delete: General case (%s) not implemented",
		 prop_name);
      g_free (prop_name);
    }
540
}
Hans Breuer's avatar
updated    
Hans Breuer committed
541

542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
/*
  for reference copied from gdk/x11/gdkevents-x11.c

  { "Net/DoubleClickTime", "gtk-double-click-time" },
  { "Net/DoubleClickDistance", "gtk-double-click-distance" },
  { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
  { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
  { "Gtk/ColorPalette", "gtk-color-palette" },
  { "Gtk/FontName", "gtk-font-name" },
  { "Gtk/IconSizes", "gtk-icon-sizes" },
  { "Gtk/KeyThemeName", "gtk-key-theme-name" },
  { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
  { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
  { "Gtk/IMPreeditStyle", "gtk-im-preedit-style" },
  { "Gtk/IMStatusStyle", "gtk-im-status-style" },
  { "Net/CursorBlink", "gtk-cursor-blink" },
  { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
  { "Net/ThemeName", "gtk-theme-name" },
  { "Net/IconThemeName", "gtk-icon-theme-name" },
  { "Gtk/ButtonImages", "gtk-button-images" },
  { "Gtk/MenuImages", "gtk-menu-images" },
  { "Xft/Antialias", "gtk-xft-antialias" },
  { "Xft/Hinting", "gtk-xft-hinting" },
  { "Xft/HintStyle", "gtk-xft-hintstyle" },
  { "Xft/RGBA", "gtk-xft-rgba" },
  { "Xft/DPI", "gtk-xft-dpi" },

  // more spread in gtk sources
  gtk-entry-select-on-focus
  gtk-cursor-blink
  gtk-cursor-blink-time
  gtk-split-cursor

*/
Hans Breuer's avatar
updated    
Hans Breuer committed
576
gboolean
577
578
579
gdk_screen_get_setting (GdkScreen   *screen,
                        const gchar *name,
                        GValue      *value)
Hans Breuer's avatar
updated    
Hans Breuer committed
580
{
581
  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
582

Hans Breuer's avatar
updated    
Hans Breuer committed
583
584
585
586
  /*
   * XXX : if these values get changed through the Windoze UI the
   *       respective gdk_events are not generated yet.
   */
587
588
589
590
591
  if (strcmp ("gtk-theme-name", name) == 0) 
    {
      g_value_set_string (value, "ms-windows");
    }
  else if (strcmp ("gtk-double-click-time", name) == 0)
Hans Breuer's avatar
updated    
Hans Breuer committed
592
    {
593
594
595
      gint i = GetDoubleClickTime ();
      GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
      g_value_set_int (value, i);
Hans Breuer's avatar
updated    
Hans Breuer committed
596
597
      return TRUE;
    }
598
  else if (strcmp ("gtk-double-click-distance", name) == 0)
Hans Breuer's avatar
updated    
Hans Breuer committed
599
    {
600
601
602
      gint i = MAX(GetSystemMetrics (SM_CXDOUBLECLK), GetSystemMetrics (SM_CYDOUBLECLK));
      GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
      g_value_set_int (value, i);
Hans Breuer's avatar
updated    
Hans Breuer committed
603
604
      return TRUE;
    }
605
606
607
608
609
610
611
612
613
614
615
616
617
  else if (strcmp ("gtk-dnd-drag-threshold", name) == 0)
    {
      gint i = MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG));
      GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
      g_value_set_int (value, i);
      return TRUE;
    }
  else if (strcmp ("gtk-split-cursor", name) == 0)
    {
      GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : FALSE\n", name));
      g_value_set_boolean (value, FALSE);
      return TRUE;
    }
618
619
620
621
622
623
  else if (strcmp ("gtk-alternative-button-order", name) == 0)
    {
      GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : TRUE\n", name));
      g_value_set_boolean (value, TRUE);
      return TRUE;
    }
624
625
626
627
628
629
630
631
632
633
634
635
636
637
#if 0
  /*
   * With 'MS Sans Serif' as windows menu font (default on win98se) you'll get a 
   * bunch of :
   *   WARNING **: Couldn't load font "MS Sans Serif 8" falling back to "Sans 8"
   * at least with testfilechooser (regardless of the bitmap check below)
   * so just disabling this code seems to be the best we can do --hb
   */
  else if (strcmp ("gtk-font-name", name) == 0)
    {
      NONCLIENTMETRICS ncm;
      ncm.cbSize = sizeof(NONCLIENTMETRICS);
      if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, FALSE))
        {
638
639
640
          /* Pango finally uses GetDeviceCaps to scale, we use simple
	   * approximation here.
	   */
641
642
643
644
645
          int nHeight = (0 > ncm.lfMenuFont.lfHeight ? -3*ncm.lfMenuFont.lfHeight/4 : 10);
          if (OUT_STRING_PRECIS == ncm.lfMenuFont.lfOutPrecision)
            GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : ignoring bitmap font '%s'\n", 
                                   name, ncm.lfMenuFont.lfFaceName));
          else if (ncm.lfMenuFont.lfFaceName && strlen(ncm.lfMenuFont.lfFaceName) > 0 &&
646
                   /* Avoid issues like those described in bug #135098 */
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
                   g_utf8_validate (ncm.lfMenuFont.lfFaceName, -1, NULL))
            {
              char* s = g_strdup_printf ("%s %d", ncm.lfMenuFont.lfFaceName, nHeight);
              GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : %s\n", name, s));
              g_value_set_string (value, s);

              g_free(s);
              return TRUE;
            }
        }
    }
#endif

  GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) not handled\n", name));
  return FALSE;
662
}