1 /* Emulate the X Resource Manager through the registry.
2 Copyright (C) 1990, 1993-1994, 2001-2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 /* Written by Kevin Gallo */
24 #include "blockinput.h"
28 #define REG_ROOT "SOFTWARE\\GNU\\Emacs"
30 /* Default system colors from the Display Control Panel settings. */
31 #define SYSTEM_DEFAULT_RESOURCES \
32 "emacs.foreground:SystemWindowText\0" \
33 "emacs.background:SystemWindow\0" \
34 "emacs.tooltip.attributeForeground:SystemInfoText\0" \
35 "emacs.tooltip.attributeBackground:SystemInfoWindow\0" \
36 "emacs.tool-bar.attributeForeground:SystemButtonText\0" \
37 "emacs.tool-bar.attributeBackground:SystemButtonFace\0" \
38 "emacs.menu.attributeForeground:SystemMenuText\0" \
39 "emacs.menu.attributeBackground:SystemMenu\0" \
40 "emacs.scroll-bar.attributeForeground:SystemScrollbar\0"
42 /* Other possibilities for default faces:
44 region: Could use SystemHilight, but interferes with our ability to
45 see most syntax highlighting through the region face.
47 modeline: Could use System(In)ActiveTitle, gradient versions (not
48 supported on 95 and NT), but modeline is more like a status bar
49 really (which don't appear to be configurable in Windows).
51 highlight: Could use SystemHotTrackingColor, but it is not supported
52 on Windows 95 or NT, and other apps only seem to use it for menus
58 w32_get_rdb_resource (char *rdb
, char *resource
)
61 int len
= strlen (resource
);
65 /* Comparison is case-insensitive because registry searches are too. */
66 if ((strnicmp (value
, resource
, len
) == 0) && (value
[len
] == ':'))
67 return xstrdup (&value
[len
+ 1]);
69 value
= strchr (value
, '\0') + 1;
76 w32_get_string_resource (char *name
, char *class, DWORD dwexptype
)
78 LPBYTE lpvalue
= NULL
;
83 HKEY hive
= HKEY_CURRENT_USER
;
89 /* Check both the current user and the local machine to see if we have
92 if (RegOpenKeyEx (hive
, REG_ROOT
, 0, KEY_READ
, &hrootkey
) == ERROR_SUCCESS
)
96 if (RegQueryValueEx (hrootkey
, name
, NULL
, &dwType
, NULL
, &cbData
) == ERROR_SUCCESS
97 && dwType
== dwexptype
)
101 else if (RegQueryValueEx (hrootkey
, class, NULL
, &dwType
, NULL
, &cbData
) == ERROR_SUCCESS
102 && dwType
== dwexptype
)
112 && (lpvalue
= xmalloc (cbData
)) != NULL
113 && RegQueryValueEx (hrootkey
, keyname
, NULL
, NULL
, lpvalue
, &cbData
) == ERROR_SUCCESS
);
115 RegCloseKey (hrootkey
);
127 if (hive
== HKEY_CURRENT_USER
)
129 hive
= HKEY_LOCAL_MACHINE
;
133 /* Check if there are Windows specific defaults defined. */
134 return w32_get_rdb_resource (SYSTEM_DEFAULT_RESOURCES
, name
);
139 /* Retrieve the string resource specified by NAME with CLASS from
143 x_get_string_resource (XrmDatabase rdb
, char *name
, char *class)
149 if ((resource
= w32_get_rdb_resource (rdb
, name
)))
151 if ((resource
= w32_get_rdb_resource (rdb
, class)))
155 if (inhibit_x_resources
)
156 /* --quick was passed, so this is a no-op. */
159 return w32_get_string_resource (name
, class, REG_SZ
);