Debian Codegraph @

gdk/win32/gdkproperty-win32.c

raw
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, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
24 */
25
26 #include "config.h"
27 #include <string.h>
28 #include <stdlib.h>
29 #include <glib/gprintf.h>
30 #include <pango/pangowin32.h>
31
32 #include "gdkscreen.h"
33 #include "gdkproperty.h"
34 #include "gdkselection.h"
35 #include "gdkprivate-win32.h"
36 #include "gdkmonitor-win32.h"
37 #include "gdkwin32.h"
38
39 GdkAtom
40 _gdk_win32_display_manager_atom_intern (GdkDisplayManager *manager,
41 const gchar *atom_name,
42 gint only_if_exists)
43 {
44 ATOM win32_atom;
45 GdkAtom retval;
46 static GHashTable *atom_hash = NULL;
47
48 if (!atom_hash)
49 atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
50
51 retval = g_hash_table_lookup (atom_hash, atom_name);
52 if (!retval)
53 {
54 if (strcmp (atom_name, "PRIMARY") == 0)
55 retval = GDK_SELECTION_PRIMARY;
56 else if (strcmp (atom_name, "SECONDARY") == 0)
57 retval = GDK_SELECTION_SECONDARY;
58 else if (strcmp (atom_name, "CLIPBOARD") == 0)
59 retval = GDK_SELECTION_CLIPBOARD;
60 else if (strcmp (atom_name, "ATOM") == 0)
61 retval = GDK_SELECTION_TYPE_ATOM;
62 else if (strcmp (atom_name, "BITMAP") == 0)
63 retval = GDK_SELECTION_TYPE_BITMAP;
64 else if (strcmp (atom_name, "COLORMAP") == 0)
65 retval = GDK_SELECTION_TYPE_COLORMAP;
66 else if (strcmp (atom_name, "DRAWABLE") == 0)
67 retval = GDK_SELECTION_TYPE_DRAWABLE;
68 else if (strcmp (atom_name, "INTEGER") == 0)
69 retval = GDK_SELECTION_TYPE_INTEGER;
70 else if (strcmp (atom_name, "PIXMAP") == 0)
71 retval = GDK_SELECTION_TYPE_PIXMAP;
72 else if (strcmp (atom_name, "WINDOW") == 0)
73 retval = GDK_SELECTION_TYPE_WINDOW;
74 else if (strcmp (atom_name, "STRING") == 0)
75 retval = GDK_SELECTION_TYPE_STRING;
76 else
77 {
78 win32_atom = GlobalAddAtom (atom_name);
79 retval = GUINT_TO_POINTER ((guint) win32_atom);
80 }
81 g_hash_table_insert (atom_hash,
82 g_strdup (atom_name),
83 retval);
84 }
85
86 return retval;
87 }
88
89 gchar *
90 _gdk_win32_display_manager_get_atom_name (GdkDisplayManager *manager,
91 GdkAtom atom)
92 {
93 ATOM win32_atom;
94 gchar name[256];
95
96 if (GDK_NONE == atom) return g_strdup ("<none>");
97 else if (GDK_SELECTION_PRIMARY == atom) return g_strdup ("PRIMARY");
98 else if (GDK_SELECTION_SECONDARY == atom) return g_strdup ("SECONDARY");
99 else if (GDK_SELECTION_CLIPBOARD == atom) return g_strdup ("CLIPBOARD");
100 else if (GDK_SELECTION_TYPE_ATOM == atom) return g_strdup ("ATOM");
101 else if (GDK_SELECTION_TYPE_BITMAP == atom) return g_strdup ("BITMAP");
102 else if (GDK_SELECTION_TYPE_COLORMAP == atom) return g_strdup ("COLORMAP");
103 else if (GDK_SELECTION_TYPE_DRAWABLE == atom) return g_strdup ("DRAWABLE");
104 else if (GDK_SELECTION_TYPE_INTEGER == atom) return g_strdup ("INTEGER");
105 else if (GDK_SELECTION_TYPE_PIXMAP == atom) return g_strdup ("PIXMAP");
106 else if (GDK_SELECTION_TYPE_WINDOW == atom) return g_strdup ("WINDOW");
107 else if (GDK_SELECTION_TYPE_STRING == atom) return g_strdup ("STRING");
108
109 win32_atom = GPOINTER_TO_UINT (atom);
110
111 if (win32_atom < 0xC000)
112 return g_strdup_printf ("#%p", atom);
113 else if (GlobalGetAtomName (win32_atom, name, sizeof (name)) == 0)
114 return NULL;
115 return g_strdup (name);
116 }
117
118 gint
119 _gdk_win32_window_get_property (GdkWindow *window,
120 GdkAtom property,
121 GdkAtom type,
122 gulong offset,
123 gulong length,
124 gint pdelete,
125 GdkAtom *actual_property_type,
126 gint *actual_format_type,
127 gint *actual_length,
128 guchar **data)
129 {
130 g_return_val_if_fail (window != NULL, FALSE);
131 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
132
133 if (GDK_WINDOW_DESTROYED (window))
134 return FALSE;
135
136 g_warning ("gdk_property_get: Not implemented");
137
138 return FALSE;
139 }
140
141 void
142 _gdk_win32_window_change_property (GdkWindow *window,
143 GdkAtom property,
144 GdkAtom type,
145 gint format,
146 GdkPropMode mode,
147 const guchar *data,
148 gint nelements)
149 {
150 GdkWin32Selection *win32_sel = _gdk_win32_selection_get ();
151
152 g_return_if_fail (window != NULL);
153 g_return_if_fail (GDK_IS_WINDOW (window));
154
155 if (GDK_WINDOW_DESTROYED (window))
156 return;
157
158 GDK_NOTE (DND, {
159 gchar *prop_name = gdk_atom_name (property);
160 gchar *type_name = gdk_atom_name (type);
161 gchar *datastring = _gdk_win32_data_to_string (data, MIN (10, format*nelements/8));
162
163 g_print ("gdk_property_change: %p %s %s %s %d*%d bits: %s\n",
164 GDK_WINDOW_HWND (window),
165 prop_name,
166 type_name,
167 (mode == GDK_PROP_MODE_REPLACE ? "REPLACE" :
168 (mode == GDK_PROP_MODE_PREPEND ? "PREPEND" :
169 (mode == GDK_PROP_MODE_APPEND ? "APPEND" :
170 "???"))),
171 format, nelements,
172 datastring);
173 g_free (datastring);
174 g_free (prop_name);
175 g_free (type_name);
176 });
177
178 #ifndef G_DISABLE_CHECKS
179 /* We should never come here for these types */
180 if (G_UNLIKELY (type == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_COMPOUND_TEXT) ||
181 type == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_SAVE_TARGETS)))
182 {
183 g_return_if_fail_warning (G_LOG_DOMAIN,
184 G_STRFUNC,
185 "change_property called with a bad type");
186 return;
187 }
188 #endif
189
190 if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION) ||
191 property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND) ||
192 property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_LOCAL_DND_SELECTION))
193 {
194 _gdk_win32_selection_property_change (win32_sel,
195 window,
196 property,
197 type,
198 format,
199 mode,
200 data,
201 nelements);
202 }
203 else
204 g_warning ("gdk_property_change: General case not implemented");
205 }
206
207 void
208 _gdk_win32_window_delete_property (GdkWindow *window,
209 GdkAtom property)
210 {
211 gchar *prop_name;
212
213 g_return_if_fail (window != NULL);
214 g_return_if_fail (GDK_IS_WINDOW (window));
215
216 GDK_NOTE (DND, {
217 prop_name = gdk_atom_name (property);
218
219 g_print ("gdk_property_delete: %p %s\n",
220 GDK_WINDOW_HWND (window),
221 prop_name);
222 g_free (prop_name);
223 });
224
225 if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION) ||
226 property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND))
227 _gdk_selection_property_delete (window);
228 else if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_WM_TRANSIENT_FOR))
229 {
230 GdkScreen *screen;
231
232 screen = gdk_window_get_screen (window);
233 gdk_window_set_transient_for (window, gdk_screen_get_root_window (screen));
234 }
235 else
236 {
237 prop_name = gdk_atom_name (property);
238 g_warning ("gdk_property_delete: General case (%s) not implemented",
239 prop_name);
240 g_free (prop_name);
241 }
242 }
243
244 static gchar*
245 _get_system_font_name (HDC hdc)
246 {
247 NONCLIENTMETRICSW ncm;
248 PangoFontDescription *font_desc;
249 gchar *result, *font_desc_string;
250 int logpixelsy;
251 gint font_size;
252
253 ncm.cbSize = sizeof(NONCLIENTMETRICSW);
254 if (!SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0))
255 return NULL;
256
257 logpixelsy = GetDeviceCaps (hdc, LOGPIXELSY);
258 font_desc = pango_win32_font_description_from_logfontw (&ncm.lfMessageFont);
259 font_desc_string = pango_font_description_to_string (font_desc);
260 pango_font_description_free (font_desc);
261
262 /* https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogfonta */
263 font_size = -MulDiv (ncm.lfMessageFont.lfHeight, 72, logpixelsy);
264 result = g_strdup_printf ("%s %d", font_desc_string, font_size);
265 g_free (font_desc_string);
266
267 return result;
268 }
269
270 /*
271 For reference, from gdk/x11/gdksettings.c:
272
273 "Net/DoubleClickTime\0" "gtk-double-click-time\0"
274 "Net/DoubleClickDistance\0" "gtk-double-click-distance\0"
275 "Net/DndDragThreshold\0" "gtk-dnd-drag-threshold\0"
276 "Net/CursorBlink\0" "gtk-cursor-blink\0"
277 "Net/CursorBlinkTime\0" "gtk-cursor-blink-time\0"
278 "Net/ThemeName\0" "gtk-theme-name\0"
279 "Net/IconThemeName\0" "gtk-icon-theme-name\0"
280 "Gtk/ColorPalette\0" "gtk-color-palette\0"
281 "Gtk/FontName\0" "gtk-font-name\0"
282 "Gtk/KeyThemeName\0" "gtk-key-theme-name\0"
283 "Gtk/Modules\0" "gtk-modules\0"
284 "Gtk/CursorBlinkTimeout\0" "gtk-cursor-blink-timeout\0"
285 "Gtk/CursorThemeName\0" "gtk-cursor-theme-name\0"
286 "Gtk/CursorThemeSize\0" "gtk-cursor-theme-size\0"
287 "Gtk/ColorScheme\0" "gtk-color-scheme\0"
288 "Gtk/EnableAnimations\0" "gtk-enable-animations\0"
289 "Xft/Antialias\0" "gtk-xft-antialias\0"
290 "Xft/Hinting\0" "gtk-xft-hinting\0"
291 "Xft/HintStyle\0" "gtk-xft-hintstyle\0"
292 "Xft/RGBA\0" "gtk-xft-rgba\0"
293 "Xft/DPI\0" "gtk-xft-dpi\0"
294 "Gtk/EnableAccels\0" "gtk-enable-accels\0"
295 "Gtk/ScrolledWindowPlacement\0" "gtk-scrolled-window-placement\0"
296 "Gtk/IMModule\0" "gtk-im-module\0"
297 "Fontconfig/Timestamp\0" "gtk-fontconfig-timestamp\0"
298 "Net/SoundThemeName\0" "gtk-sound-theme-name\0"
299 "Net/EnableInputFeedbackSounds\0" "gtk-enable-input-feedback-sounds\0"
300 "Net/EnableEventSounds\0" "gtk-enable-event-sounds\0";
301
302 More, from various places in gtk sources:
303
304 gtk-entry-select-on-focus
305 gtk-split-cursor
306
307 */
308 gboolean
309 _gdk_win32_screen_get_setting (GdkScreen *screen,
310 const gchar *name,
311 GValue *value)
312 {
313 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
314
315 /*
316 * XXX : if these values get changed through the Windoze UI the
317 * respective gdk_events are not generated yet.
318 */
319 if (strcmp ("gtk-double-click-time", name) == 0)
320 {
321 gint i = GetDoubleClickTime ();
322 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
323 g_value_set_int (value, i);
324 return TRUE;
325 }
326 else if (strcmp ("gtk-double-click-distance", name) == 0)
327 {
328 gint i = MAX(GetSystemMetrics (SM_CXDOUBLECLK), GetSystemMetrics (SM_CYDOUBLECLK));
329 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
330 g_value_set_int (value, i);
331 return TRUE;
332 }
333 else if (strcmp ("gtk-dnd-drag-threshold", name) == 0)
334 {
335 gint i = MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG));
336 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
337 g_value_set_int (value, i);
338 return TRUE;
339 }
340 else if (strcmp ("gtk-split-cursor", name) == 0)
341 {
342 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : FALSE\n", name));
343 g_value_set_boolean (value, FALSE);
344 return TRUE;
345 }
346 else if (strcmp ("gtk-alternative-button-order", name) == 0)
347 {
348 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : TRUE\n", name));
349 g_value_set_boolean (value, TRUE);
350 return TRUE;
351 }
352 else if (strcmp ("gtk-alternative-sort-arrows", name) == 0)
353 {
354 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : TRUE\n", name));
355 g_value_set_boolean (value, TRUE);
356 return TRUE;
357 }
358 else if (strcmp ("gtk-shell-shows-desktop", name) == 0)
359 {
360 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : TRUE\n", name));
361 g_value_set_boolean (value, TRUE);
362 return TRUE;
363 }
364 else if (strcmp ("gtk-xft-hinting", name) == 0)
365 {
366 GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : 1\n", name));
367 g_value_set_int (value, 1);
368 return TRUE;
369 }
370 else if (strcmp ("gtk-xft-antialias", name) == 0)
371 {
372 BOOL val = TRUE;
373 SystemParametersInfoW (SPI_GETFONTSMOOTHING, 0, &val, 0);
374 g_value_set_int (value, val ? 1 : 0);
375
376 GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : %u\n", name, val));
377 return TRUE;
378 }
379 else if (strcmp ("gtk-xft-hintstyle", name) == 0)
380 {
381 g_value_set_static_string (value, "hintfull");
382 GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : %s\n", name, g_value_get_string (value)));
383 return TRUE;
384 }
385 else if (strcmp ("gtk-xft-rgba", name) == 0)
386 {
387 const gchar *rgb_value;
388 GdkMonitor *monitor;
389 monitor = gdk_display_get_monitor (gdk_display_get_default (), 0);
390 rgb_value = _gdk_win32_monitor_get_pixel_structure (monitor);
391 g_value_set_static_string (value, rgb_value);
392
393 GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : %s\n", name, g_value_get_string (value)));
394 return TRUE;
395 }
396 else if (strcmp ("gtk-font-name", name) == 0)
397 {
398 gchar *font_name = _get_system_font_name (_gdk_display_hdc);
399
400 if (font_name)
401 {
402 /* The pango font fallback list got fixed during 1.43, before that
403 * using anything but "Segoe UI" would lead to a poor glyph coverage */
404 if (pango_version_check (1, 43, 0) != NULL &&
405 g_ascii_strncasecmp (font_name, "Segoe UI", strlen ("Segoe UI")) != 0)
406 {
407 g_free (font_name);
408 return FALSE;
409 }
410
411 GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %s\n", name, font_name));
412 g_value_take_string (value, font_name);
413 return TRUE;
414 }
415 else
416 {
417 g_warning ("gdk_screen_get_setting: Detecting the system font failed");
418 return FALSE;
419 }
420 }
421 else if (strcmp ("gtk-im-module", name) == 0)
422 {
423 if (_gdk_input_locale_is_ime)
424 g_value_set_static_string (value, "ime");
425 else
426 g_value_set_static_string (value, "");
427
428 return TRUE;
429 }
430 else if (strcmp ("gtk-overlay-scrolling", name) == 0)
431 {
432 DWORD val = 0;
433 DWORD sz = sizeof (val);
434 LSTATUS ret = 0;
435
436 ret = RegGetValueW (HKEY_CURRENT_USER, L"Control Panel\\Accessibility", L"DynamicScrollbars", RRF_RT_DWORD, NULL, &val, &sz);
437 if (ret == ERROR_SUCCESS)
438 {
439 g_value_set_boolean (value, val != 0);
440 return TRUE;
441 }
442 }
443
444 return FALSE;
445 }