source: trunk/src/kernel32/conprop2.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 10.8 KB
RevLine 
[5308]1/* $Id: conprop2.cpp,v 1.7 2001-03-13 18:45:33 sandervl Exp $ */
[1476]2
3/*
4 * Win32 Console API Translation for OS/2
5 *
6 * 1998/03/06 Patrick Haller (haller@zebra.fh-weingarten.de)
7 *
8 * @(#) conprop.cpp 1.0.0 1998/03/06 PH Start from scratch
9 */
10
11
12/*****************************************************************************
13 * Remark *
14 *****************************************************************************
15
16 - save / load properties from EAs
17
18 */
19
20
21/*****************************************************************************
22 * Includes *
23 *****************************************************************************/
24
25#include <odin.h>
26#include <odinwrap.h>
27#include <os2sel.h>
28
29#define INCL_GPI
30#define INCL_WIN
31#define INCL_DOSMEMMGR
32#define INCL_DOSSEMAPHORES
33#define INCL_DOSERRORS
34#define INCL_DOSPROCESS
35#define INCL_DOSMODULEMGR
36#define INCL_VIO
37#define INCL_AVIO
38#include <os2wrap.h> //Odin32 OS/2 api wrappers
39
40#include <win32type.h>
[2984]41#include <win32api.h>
[1476]42#include <misc.h>
43#include <stdio.h>
44
45#include "console.h"
46#include "console2.h"
47#include "conprop.h"
48
[2802]49#define DBG_LOCALLOG DBG_conprop2
50#include "dbglocal.h"
[1476]51
[2802]52
[1476]53ODINDEBUGCHANNEL(KERNEL32-CONPROP2)
54
55/*****************************************************************************
56 * Defines *
57 *****************************************************************************/
58
59/*****************************************************************************
[1477]60 * Name : iQueryModuleKeyName
61 * Funktion : determine name of key to store the console properties for
62 * this process
63 * Parameter :
64 * Variablen :
65 * Ergebnis :
66 * Bemerkung :
67 *
68 * Autor : Patrick Haller [1998/06/13 23:20]
69 *****************************************************************************/
70
71static DWORD iQueryModuleKeyName(LPSTR lpstrProcessName,
72 DWORD dwProcessNameLength)
73{
74 // Note: one might want to scan the string and replace illegal characters
75 // or use a module name only instead of the fully qualified path!
76 return(GetModuleFileNameA(NULL,
77 lpstrProcessName,
78 dwProcessNameLength));
79}
80
81
82/*****************************************************************************
[1476]83 * Name : APIRET EXPENTRY ConsolePropertyDefault
84 * Funktion : load default options
85 * Parameter : PICONSOLEOPTIONS pConsoleOptions
86 * Variablen :
87 * Ergebnis : APIRET
88 * Bemerkung :
89 *
90 * Autor : Patrick Haller [1998/06/13 23:20]
91 *****************************************************************************/
92
93DWORD ConsolePropertyDefault(PICONSOLEOPTIONS pConsoleOptions)
94{
95 /*************************************
96 * Initialize Console Window Options *
97 *************************************/
98
99 pConsoleOptions->fTerminateAutomatically = FALSE;
100 pConsoleOptions->fSpeakerEnabled = TRUE;
101 pConsoleOptions->fSetWindowPosition = FALSE;
102 pConsoleOptions->coordDefaultPosition.X = 0;
103 pConsoleOptions->coordDefaultPosition.Y = 0;
104 pConsoleOptions->coordDefaultSize.X = 80;
105 pConsoleOptions->coordDefaultSize.Y = 25;
106 pConsoleOptions->fQuickInsert = FALSE;
107 pConsoleOptions->fInsertMode = FALSE;
108 pConsoleOptions->fMouseActions = FALSE;
109 pConsoleOptions->fToolbarActive = FALSE;
110 pConsoleOptions->ucDefaultAttribute = 0x0007; /* 07 = grey on black */
111 pConsoleOptions->ulTabSize = 8; /* tabulator size */
112 pConsoleOptions->ulUpdateLimit = 8; /* scroll max. n lines */
113
114 /* priority settings for message thread */
115 pConsoleOptions->ulConsoleThreadPriorityClass = PRTYC_REGULAR;
116 pConsoleOptions->ulConsoleThreadPriorityDelta = +10;
117
118 pConsoleOptions->ucCursorDivisor = 10; /* timer divisor for blinking */
119
120 return NO_ERROR;
121}
122
123
124/*****************************************************************************
125 * Name : APIRET EXPENTRY ConsolePropertyLoad
126 * Funktion : load properties from registry
127 * Parameter : PICONSOLEOPTIONS pConsoleOptions
128 * Variablen :
129 * Ergebnis : APIRET
130 * Bemerkung :
131 *
132 * Autor : Patrick Haller [1998/06/13 23:20]
133 *****************************************************************************/
134
135DWORD ConsolePropertyLoad(PICONSOLEOPTIONS pConsoleOptions)
136{
[1478]137 dprintf (("KERNEL32: Console:ConsolePropertyLoad(%08xh)\n",
[1476]138 pConsoleOptions));
139
140 // HKEY_CURRENT_USER/SOFTWARE/ODIN/ConsoleProperties/<process name>/<option name>
[2984]141 LONG lRes = ERROR_SUCCESS_W;
[1476]142 HKEY hkConsole;
143 char szKey[256];
144 char szProcessName[256];
145 DWORD dwRes;
146 DWORD dwSize;
147 DWORD dwType;
148
149 // query process's name
[1477]150 dwRes = iQueryModuleKeyName((LPSTR)&szProcessName,
151 sizeof(szProcessName));
[1476]152 if (dwRes == 0)
153 {
154 dprintf(("KERNEL32: ConProp: ConsolePropertyLoad: GetModuleFileName failed\n"));
155 lRes = ERROR_INVALID_PARAMETER;
156 }
157 else
158 {
159 // open process key
160 sprintf (szKey,
161 "Software\\ODIN\\ConsoleProperties\\%s",
162 szProcessName);
163
[2984]164 lRes = RegOpenKeyExA(HKEY_CURRENT_USER,
[1476]165 szKey,
166 0,
167 KEY_ALL_ACCESS,
168 &hkConsole);
169 }
170
171 // try to open DEFAULT
[2984]172 if (lRes != ERROR_SUCCESS_W)
173 lRes = RegOpenKeyExA(HKEY_CURRENT_USER,
[1476]174 "Software\\ODIN\\ConsoleProperties\\DEFAULT",
175 0,
176 KEY_ALL_ACCESS,
177 &hkConsole);
178
179 // now it's time to retrieve information
[2984]180 if (lRes != ERROR_SUCCESS_W)
[1476]181 {
182 // load hardcoded defaults instead
183 ConsolePropertyDefault(pConsoleOptions);
184 return ERROR_INVALID_PARAMETER;
185 }
186
187
188 // OK, finally retrieve tokens
189#define REGQUERYVALUE(name,var) \
190 dwSize = sizeof(pConsoleOptions->var); \
[2984]191 lRes = RegQueryValueExA(hkConsole, name, NULL, &dwType, \
[1476]192 (LPBYTE)&pConsoleOptions->var, &dwSize);
193
194 REGQUERYVALUE("AutomaticTermination", fTerminateAutomatically)
195 REGQUERYVALUE("Speaker", fSpeakerEnabled)
196 REGQUERYVALUE("SpeakerDuration", ulSpeakerDuration)
197 REGQUERYVALUE("SpeakerFrequency", ulSpeakerFrequency)
198 REGQUERYVALUE("UpdateLimit", ulUpdateLimit)
199 REGQUERYVALUE("SetWindowPosition", fSetWindowPosition)
200 REGQUERYVALUE("DefaultPosition_x", coordDefaultPosition.X)
201 REGQUERYVALUE("DefaultPosition_y", coordDefaultPosition.Y)
202 REGQUERYVALUE("DefaultSize_x", coordDefaultSize.X)
203 REGQUERYVALUE("DefaultSize_y", coordDefaultSize.Y)
204 REGQUERYVALUE("BufferSize_x", coordBufferSize.X)
205 REGQUERYVALUE("BufferSize_y", coordBufferSize.Y)
206 REGQUERYVALUE("QuickInsert", fQuickInsert)
207 REGQUERYVALUE("InsertMode", fInsertMode)
208 REGQUERYVALUE("MouseActions", fMouseActions)
209 REGQUERYVALUE("Toolbar", fToolbarActive)
210 REGQUERYVALUE("TabSize", ulTabSize)
211 REGQUERYVALUE("DefaultAttribute", ucDefaultAttribute)
212 REGQUERYVALUE("CursorDivisor", ucCursorDivisor)
213 REGQUERYVALUE("ConsolePriorityClass", ulConsoleThreadPriorityClass)
214 REGQUERYVALUE("ConsolePriorityDelta", ulConsoleThreadPriorityDelta)
215 REGQUERYVALUE("ApplicationPriorityClass", ulAppThreadPriorityClass)
216 REGQUERYVALUE("ApplicationPriorityDelta", ulAppThreadPriorityDelta)
217#undef REGQUERYVALUE
218
[2984]219 RegCloseKey(hkConsole);
[1476]220
221 return (NO_ERROR);
222}
223
224
225
226/*****************************************************************************
227 * Name : APIRET EXPENTRY ConsolePropertySave
228 * Funktion : save properties from registry
229 * Parameter : PICONSOLEOPTIONS pConsoleOptions
230 * Variablen :
231 * Ergebnis : APIRET
232 * Bemerkung :
233 *
234 * Autor : Patrick Haller [1998/06/13 23:20]
235 *****************************************************************************/
236
237DWORD ConsolePropertySave(PICONSOLEOPTIONS pConsoleOptions)
238{
[1478]239 dprintf (("KERNEL32: Console:ConsolePropertySave(%08xh)\n",
[1476]240 pConsoleOptions));
241
[1477]242 // HKEY_CURRENT_USER/SOFTWARE/ODIN/ConsoleProperties/<process name>/<option name>
[2984]243 LONG lRes = ERROR_SUCCESS_W;
[1477]244 HKEY hkConsole;
245 char szKey[256];
246 char szProcessName[256];
247 DWORD dwRes;
248 DWORD dwSize;
249 DWORD dwType;
250 DWORD dwDisposition = 0;
251
252 // query process's name
253 dwRes = iQueryModuleKeyName((LPSTR)&szProcessName,
254 sizeof(szProcessName));
255 if (dwRes == 0)
256 {
257 dprintf(("KERNEL32: ConProp: ConsolePropertyLoad: GetModuleFileName failed\n"));
258 lRes = ERROR_INVALID_PARAMETER;
259 }
260 else
261 {
262 // open process key
263 sprintf (szKey,
264 "Software\\ODIN\\ConsoleProperties\\%s",
265 szProcessName);
266
[2984]267 lRes = RegCreateKeyExA(HKEY_CURRENT_USER,
[1477]268 szKey,
269 0,
[21916]270 NULL,
[1477]271 0,
272 KEY_ALL_ACCESS,
273 NULL,
274 &hkConsole,
275 &dwDisposition);
[2984]276 if (lRes != ERROR_SUCCESS_W)
[1477]277 return lRes;
278 }
279
280
281#define REGSAVEVALUE(name,var) \
[2984]282 lRes = RegSetValueExA(hkConsole, name, 0, REG_DWORD, \
[21916]283 (const BYTE *)&pConsoleOptions->var, sizeof(pConsoleOptions->var));
[1477]284
285 REGSAVEVALUE("AutomaticTermination", fTerminateAutomatically)
286 REGSAVEVALUE("Speaker", fSpeakerEnabled)
287 REGSAVEVALUE("SpeakerDuration", ulSpeakerDuration)
288 REGSAVEVALUE("SpeakerFrequency", ulSpeakerFrequency)
289 REGSAVEVALUE("UpdateLimit", ulUpdateLimit)
290 REGSAVEVALUE("SetWindowPosition", fSetWindowPosition)
291 REGSAVEVALUE("DefaultPosition_x", coordDefaultPosition.X)
292 REGSAVEVALUE("DefaultPosition_y", coordDefaultPosition.Y)
293 REGSAVEVALUE("DefaultSize_x", coordDefaultSize.X)
294 REGSAVEVALUE("DefaultSize_y", coordDefaultSize.Y)
295 REGSAVEVALUE("BufferSize_x", coordBufferSize.X)
296 REGSAVEVALUE("BufferSize_y", coordBufferSize.Y)
297 REGSAVEVALUE("QuickInsert", fQuickInsert)
298 REGSAVEVALUE("InsertMode", fInsertMode)
299 REGSAVEVALUE("MouseActions", fMouseActions)
300 REGSAVEVALUE("Toolbar", fToolbarActive)
301 REGSAVEVALUE("TabSize", ulTabSize)
302 REGSAVEVALUE("DefaultAttribute", ucDefaultAttribute)
303 REGSAVEVALUE("CursorDivisor", ucCursorDivisor)
304 REGSAVEVALUE("ConsolePriorityClass", ulConsoleThreadPriorityClass)
305 REGSAVEVALUE("ConsolePriorityDelta", ulConsoleThreadPriorityDelta)
306 REGSAVEVALUE("ApplicationPriorityClass", ulAppThreadPriorityClass)
307 REGSAVEVALUE("ApplicationPriorityDelta", ulAppThreadPriorityDelta)
308#undef REGSAVEVALUE
309
[2984]310 RegCloseKey(hkConsole);
[1477]311
[1476]312 return (NO_ERROR);
[1477]313
[1476]314}
315
Note: See TracBrowser for help on using the repository browser.