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