gnus-util.el (gnus-macroexpand-all): Fix last change.
[emacs.git] / src / w32reg.c
blob5c02dd376c72c44eea68e4bea0372b5d65beef6b
1 /* Emulate the X Resource Manager through the registry.
2 Copyright (C) 1990, 1993, 1994, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* Written by Kevin Gallo */
22 #include <config.h>
23 #include <setjmp.h>
24 #include "lisp.h"
25 #include "w32term.h"
26 #include "blockinput.h"
28 #include <stdio.h>
30 #define REG_ROOT "SOFTWARE\\GNU\\Emacs"
32 /* Default system colors from the Display Control Panel settings. */
33 #define SYSTEM_DEFAULT_RESOURCES \
34 "emacs.foreground:SystemWindowText\0" \
35 "emacs.background:SystemWindow\0" \
36 "emacs.tooltip.attributeForeground:SystemInfoText\0" \
37 "emacs.tooltip.attributeBackground:SystemInfoWindow\0" \
38 "emacs.tool-bar.attributeForeground:SystemButtonText\0" \
39 "emacs.tool-bar.attributeBackground:SystemButtonFace\0" \
40 "emacs.menu.attributeForeground:SystemMenuText\0" \
41 "emacs.menu.attributeBackground:SystemMenu\0" \
42 "emacs.scroll-bar.attributeForeground:SystemScrollbar\0"
44 /* Other possibilities for default faces:
46 region: Could use SystemHilight, but interferes with our ability to
47 see most syntax highlighting through the region face.
49 modeline: Could use System(In)ActiveTitle, gradient versions (not
50 supported on 95 and NT), but modeline is more like a status bar
51 really (which don't appear to be configurable in Windows).
53 highlight: Could use SystemHotTrackingColor, but it is not supported
54 on Windows 95 or NT, and other apps only seem to use it for menus
55 anyway.
59 static char *
60 w32_get_rdb_resource (char *rdb, char *resource)
62 char *value = rdb;
63 int len = strlen (resource);
65 while (*value)
67 /* Comparison is case-insensitive because registry searches are too. */
68 if ((strnicmp (value, resource, len) == 0) && (value[len] == ':'))
69 return xstrdup (&value[len + 1]);
71 value = strchr (value, '\0') + 1;
74 return NULL;
77 static LPBYTE
78 w32_get_string_resource (char *name, char *class, DWORD dwexptype)
80 LPBYTE lpvalue = NULL;
81 HKEY hrootkey = NULL;
82 DWORD dwType;
83 DWORD cbData;
84 BOOL ok = FALSE;
85 HKEY hive = HKEY_CURRENT_USER;
87 trykey:
89 BLOCK_INPUT;
91 /* Check both the current user and the local machine to see if we have
92 any resources */
94 if (RegOpenKeyEx (hive, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
96 char *keyname;
98 if (RegQueryValueEx (hrootkey, name, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
99 && dwType == dwexptype)
101 keyname = name;
103 else if (RegQueryValueEx (hrootkey, class, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
104 && dwType == dwexptype)
106 keyname = class;
108 else
110 keyname = NULL;
113 ok = (keyname
114 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
115 && RegQueryValueEx (hrootkey, keyname, NULL, NULL, lpvalue, &cbData) == ERROR_SUCCESS);
117 RegCloseKey (hrootkey);
120 UNBLOCK_INPUT;
122 if (!ok)
124 if (lpvalue)
126 xfree (lpvalue);
127 lpvalue = NULL;
129 if (hive == HKEY_CURRENT_USER)
131 hive = HKEY_LOCAL_MACHINE;
132 goto trykey;
135 /* Check if there are Windows specific defaults defined. */
136 return w32_get_rdb_resource (SYSTEM_DEFAULT_RESOURCES, name);
138 return (lpvalue);
141 /* Retrieve the string resource specified by NAME with CLASS from
142 database RDB. */
144 char *
145 x_get_string_resource (XrmDatabase rdb, char *name, char *class)
147 if (rdb)
149 char *resource;
151 if (resource = w32_get_rdb_resource (rdb, name))
152 return resource;
153 if (resource = w32_get_rdb_resource (rdb, class))
154 return resource;
157 if (inhibit_x_resources)
158 /* --quick was passed, so this is a no-op. */
159 return NULL;
161 return (w32_get_string_resource (name, class, REG_SZ));
164 /* arch-tag: 755fce25-42d7-4acb-874f-2fb42336823d
165 (do not change this comment) */