In debug restore assignment to debugger-old-buffer.
[emacs.git] / src / w32reg.c
blob8a6a3c853b1982eaab69ced04f7c4d13e689d5eb
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 */
21 #include <config.h>
22 #include "lisp.h"
23 #include "w32term.h"
24 #include "blockinput.h"
26 #include <stdio.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
53 anyway.
57 static char *
58 w32_get_rdb_resource (char *rdb, char *resource)
60 char *value = rdb;
61 int len = strlen (resource);
63 while (*value)
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;
72 return NULL;
75 static LPBYTE
76 w32_get_string_resource (char *name, char *class, DWORD dwexptype)
78 LPBYTE lpvalue = NULL;
79 HKEY hrootkey = NULL;
80 DWORD dwType;
81 DWORD cbData;
82 BOOL ok = FALSE;
83 HKEY hive = HKEY_CURRENT_USER;
85 trykey:
87 BLOCK_INPUT;
89 /* Check both the current user and the local machine to see if we have
90 any resources */
92 if (RegOpenKeyEx (hive, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
94 char *keyname;
96 if (RegQueryValueEx (hrootkey, name, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
97 && dwType == dwexptype)
99 keyname = name;
101 else if (RegQueryValueEx (hrootkey, class, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
102 && dwType == dwexptype)
104 keyname = class;
106 else
108 keyname = NULL;
111 ok = (keyname
112 && (lpvalue = xmalloc (cbData)) != NULL
113 && RegQueryValueEx (hrootkey, keyname, NULL, NULL, lpvalue, &cbData) == ERROR_SUCCESS);
115 RegCloseKey (hrootkey);
118 UNBLOCK_INPUT;
120 if (!ok)
122 if (lpvalue)
124 xfree (lpvalue);
125 lpvalue = NULL;
127 if (hive == HKEY_CURRENT_USER)
129 hive = HKEY_LOCAL_MACHINE;
130 goto trykey;
133 /* Check if there are Windows specific defaults defined. */
134 return w32_get_rdb_resource (SYSTEM_DEFAULT_RESOURCES, name);
136 return (lpvalue);
139 /* Retrieve the string resource specified by NAME with CLASS from
140 database RDB. */
142 char *
143 x_get_string_resource (XrmDatabase rdb, char *name, char *class)
145 if (rdb)
147 char *resource;
149 if ((resource = w32_get_rdb_resource (rdb, name)))
150 return resource;
151 if ((resource = w32_get_rdb_resource (rdb, class)))
152 return resource;
155 if (inhibit_x_resources)
156 /* --quick was passed, so this is a no-op. */
157 return NULL;
159 return w32_get_string_resource (name, class, REG_SZ);