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