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