(syms_of_ntproc) <w32-get-true-file-attributes>: Doc fix.
[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,
8cabe764 3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
ee78dc32 4
3b7ad313
EN
5This file is part of GNU Emacs.
6
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
684d6f5b 9the Free Software Foundation; either version 3, or (at your option)
ee78dc32
GV
10any later version.
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
3b7ad313 18along with GNU Emacs; see the file COPYING. If not, write to
4fc5845f
LK
19the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA. */
ee78dc32
GV
21
22/* Written by Kevin Gallo */
23
24#include <config.h>
25#include "lisp.h"
26#include "w32term.h"
27#include "blockinput.h"
28
29#include <stdio.h>
30#include <string.h>
31
f79eea00 32#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
ee78dc32 33
3d143690
JR
34/* Default system colors from the Display Control Panel settings. */
35#define SYSTEM_DEFAULT_RESOURCES \
36 "emacs.foreground:SystemWindowText\0" \
37 "emacs.background:SystemWindow\0" \
38 "emacs.tooltip.attributeForeground:SystemInfoText\0" \
39 "emacs.tooltip.attributeBackground:SystemInfoWindow\0" \
40 "emacs.tool-bar.attributeForeground:SystemButtonText\0" \
41 "emacs.tool-bar.attributeBackground:SystemButtonFace\0" \
42 "emacs.menu.attributeForeground:SystemMenuText\0" \
43 "emacs.menu.attributeBackground:SystemMenu\0" \
32e1c7b1 44 "emacs.scroll-bar.attributeForeground:SystemScrollbar\0"
3d143690
JR
45
46/* Other possibilities for default faces:
47
48 region: Could use SystemHilight, but interferes with our ability to
49 see most syntax highlighting through the region face.
50
51 modeline: Could use System(In)ActiveTitle, gradient versions (not
52 supported on 95 and NT), but modeline is more like a status bar
53 really (which don't appear to be configurable in Windows).
54
55 highlight: Could use SystemHotTrackingColor, but it is not supported
56 on Windows 95 or NT, and other apps only seem to use it for menus
57 anyway.
58
59*/
60
c9029fe5
JB
61static char *
62w32_get_rdb_resource (rdb, resource)
63 char *rdb;
64 char *resource;
65{
66 char *value = rdb;
67 int len = strlen (resource);
68
69 while (*value)
70 {
71 /* Comparison is case-insensitive because registry searches are too. */
72 if ((strnicmp (value, resource, len) == 0) && (value[len] == ':'))
73 return xstrdup (&value[len + 1]);
74
75 value = strchr (value, '\0') + 1;
76 }
77
78 return NULL;
79}
80
177c0ea7 81LPBYTE
fbd6baed 82w32_get_string_resource (name, class, dwexptype)
ee78dc32
GV
83 char *name, *class;
84 DWORD dwexptype;
85{
86 LPBYTE lpvalue = NULL;
87 HKEY hrootkey = NULL;
88 DWORD dwType;
89 DWORD cbData;
90 BOOL ok = FALSE;
49fb6381 91 HKEY hive = HKEY_CURRENT_USER;
177c0ea7 92
49fb6381
AI
93 trykey:
94
ee78dc32 95 BLOCK_INPUT;
177c0ea7 96
49fb6381
AI
97 /* Check both the current user and the local machine to see if we have
98 any resources */
99
100 if (RegOpenKeyEx (hive, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
ee78dc32
GV
101 {
102 char *keyname;
177c0ea7 103
ee78dc32
GV
104 if (RegQueryValueEx (hrootkey, name, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
105 && dwType == dwexptype)
106 {
107 keyname = name;
177c0ea7 108 }
ee78dc32
GV
109 else if (RegQueryValueEx (hrootkey, class, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
110 && dwType == dwexptype)
111 {
112 keyname = class;
113 }
114 else
115 {
116 keyname = NULL;
117 }
177c0ea7 118
ee78dc32
GV
119 ok = (keyname
120 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
121 && RegQueryValueEx (hrootkey, keyname, NULL, NULL, lpvalue, &cbData) == ERROR_SUCCESS);
177c0ea7 122
ee78dc32
GV
123 RegCloseKey (hrootkey);
124 }
177c0ea7 125
ee78dc32 126 UNBLOCK_INPUT;
177c0ea7
JB
127
128 if (!ok)
ee78dc32 129 {
49fb6381
AI
130 if (lpvalue)
131 {
132 xfree (lpvalue);
133 lpvalue = NULL;
134 }
135 if (hive == HKEY_CURRENT_USER)
136 {
137 hive = HKEY_LOCAL_MACHINE;
138 goto trykey;
139 }
3d143690
JR
140
141 /* Check if there are Windows specific defaults defined. */
142 return w32_get_rdb_resource (SYSTEM_DEFAULT_RESOURCES, name);
177c0ea7 143 }
49fb6381 144 return (lpvalue);
ee78dc32
GV
145}
146
147/* Retrieve the string resource specified by NAME with CLASS from
148 database RDB. */
149
150char *
151x_get_string_resource (rdb, name, class)
5a152aa0 152 XrmDatabase rdb;
ee78dc32
GV
153 char *name, *class;
154{
c9029fe5
JB
155 if (rdb)
156 {
157 char *resource;
158
159 if (resource = w32_get_rdb_resource (rdb, name))
160 return resource;
161 if (resource = w32_get_rdb_resource (rdb, class))
162 return resource;
163 }
164
fbd6baed 165 return (w32_get_string_resource (name, class, REG_SZ));
ee78dc32 166}
ab5796a9
MB
167
168/* arch-tag: 755fce25-42d7-4acb-874f-2fb42336823d
169 (do not change this comment) */