* net/browse-url.el (browse-url): Identify alist with "consp and
[bpt/emacs.git] / src / w32reg.c
CommitLineData
ee78dc32 1/* Emulate the X Resource Manager through the registry.
429ab54e 2 Copyright (C) 1990, 1993, 1994, 2001, 2002, 2003, 2004,
76b6f707 3 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
ee78dc32 4
3b7ad313
EN
5This file is part of GNU Emacs.
6
9ec0b715 7GNU Emacs is free software: you can redistribute it and/or modify
ee78dc32 8it under the terms of the GNU General Public License as published by
9ec0b715
GM
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
ee78dc32 11
3b7ad313 12GNU Emacs is distributed in the hope that it will be useful,
ee78dc32
GV
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
9ec0b715 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
ee78dc32
GV
19
20/* Written by Kevin Gallo */
21
22#include <config.h>
23#include "lisp.h"
24#include "w32term.h"
25#include "blockinput.h"
26
27#include <stdio.h>
28#include <string.h>
29
f79eea00 30#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
ee78dc32 31
3d143690
JR
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" \
32e1c7b1 42 "emacs.scroll-bar.attributeForeground:SystemScrollbar\0"
3d143690
JR
43
44/* Other possibilities for default faces:
45
46 region: Could use SystemHilight, but interferes with our ability to
47 see most syntax highlighting through the region face.
48
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).
52
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.
56
57*/
58
c9029fe5
JB
59static char *
60w32_get_rdb_resource (rdb, resource)
61 char *rdb;
62 char *resource;
63{
64 char *value = rdb;
65 int len = strlen (resource);
66
67 while (*value)
68 {
69 /* Comparison is case-insensitive because registry searches are too. */
70 if ((strnicmp (value, resource, len) == 0) && (value[len] == ':'))
71 return xstrdup (&value[len + 1]);
72
73 value = strchr (value, '\0') + 1;
74 }
75
76 return NULL;
77}
78
8686ac71 79static LPBYTE
fbd6baed 80w32_get_string_resource (name, class, dwexptype)
ee78dc32
GV
81 char *name, *class;
82 DWORD dwexptype;
83{
84 LPBYTE lpvalue = NULL;
85 HKEY hrootkey = NULL;
86 DWORD dwType;
87 DWORD cbData;
88 BOOL ok = FALSE;
49fb6381 89 HKEY hive = HKEY_CURRENT_USER;
177c0ea7 90
49fb6381
AI
91 trykey:
92
ee78dc32 93 BLOCK_INPUT;
177c0ea7 94
49fb6381
AI
95 /* Check both the current user and the local machine to see if we have
96 any resources */
97
98 if (RegOpenKeyEx (hive, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
ee78dc32
GV
99 {
100 char *keyname;
177c0ea7 101
ee78dc32
GV
102 if (RegQueryValueEx (hrootkey, name, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
103 && dwType == dwexptype)
104 {
105 keyname = name;
177c0ea7 106 }
ee78dc32
GV
107 else if (RegQueryValueEx (hrootkey, class, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
108 && dwType == dwexptype)
109 {
110 keyname = class;
111 }
112 else
113 {
114 keyname = NULL;
115 }
177c0ea7 116
ee78dc32
GV
117 ok = (keyname
118 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
119 && RegQueryValueEx (hrootkey, keyname, NULL, NULL, lpvalue, &cbData) == ERROR_SUCCESS);
177c0ea7 120
ee78dc32
GV
121 RegCloseKey (hrootkey);
122 }
177c0ea7 123
ee78dc32 124 UNBLOCK_INPUT;
177c0ea7
JB
125
126 if (!ok)
ee78dc32 127 {
49fb6381
AI
128 if (lpvalue)
129 {
130 xfree (lpvalue);
131 lpvalue = NULL;
132 }
133 if (hive == HKEY_CURRENT_USER)
134 {
135 hive = HKEY_LOCAL_MACHINE;
136 goto trykey;
137 }
3d143690
JR
138
139 /* Check if there are Windows specific defaults defined. */
140 return w32_get_rdb_resource (SYSTEM_DEFAULT_RESOURCES, name);
177c0ea7 141 }
49fb6381 142 return (lpvalue);
ee78dc32
GV
143}
144
145/* Retrieve the string resource specified by NAME with CLASS from
146 database RDB. */
147
148char *
149x_get_string_resource (rdb, name, class)
5a152aa0 150 XrmDatabase rdb;
ee78dc32
GV
151 char *name, *class;
152{
c9029fe5
JB
153 if (rdb)
154 {
155 char *resource;
156
157 if (resource = w32_get_rdb_resource (rdb, name))
158 return resource;
159 if (resource = w32_get_rdb_resource (rdb, class))
160 return resource;
161 }
162
8686ac71
JB
163 if (inhibit_x_resources)
164 /* --quick was passed, so this is a no-op. */
165 return NULL;
166
fbd6baed 167 return (w32_get_string_resource (name, class, REG_SZ));
ee78dc32 168}
ab5796a9
MB
169
170/* arch-tag: 755fce25-42d7-4acb-874f-2fb42336823d
171 (do not change this comment) */