source: trunk/dll/presparm.c@ 551

Last change on this file since 551 was 551, checked in by Gregg Young, 19 years ago

Indentation cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
Line 
1
2/***********************************************************************
3
4 $Id: presparm.c 551 2007-02-28 01:33:51Z gyoung $
5
6 Edit presentation parameters
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2006 Steven H.Levine
10
11 22 Jul 06 SHL Check more run time errors
12
13***********************************************************************/
14
15#define INCL_DOS
16#define INCL_WIN
17#define INCL_GPI
18#include <os2.h>
19
20#include <stdarg.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <ctype.h>
25
26#include "fm3dll.h"
27
28static PSZ pszSrcFile = __FILE__;
29
30#pragma alloc_text(PRESPARAM,CopyPresParams,SetPresParams,IfNoParam)
31#pragma alloc_text(PRESPARAM,PresParamChanged,RestorePresParams)
32#pragma alloc_text(PRESPARAM,StoreWndPresParams)
33
34#ifdef NEVER
35/*
36 * this routine will fill a buffer with all defined window pres params
37 * the PRESPARAMS structure returned is suitable to be passed as
38 * pPresParams ie. WinCreateWindow(,,,,,,,,,,,, PVOID pPresParams)
39 */
40VOID StoreWndPresParams(HWND hwnd, CHAR * tagname, HINI prof)
41{
42 PARAM *pparam;
43 PRESPARAMS *ppresparams;
44
45 if (!tagname || !*tagname || !prof)
46 return;
47 /* setup memory access */
48 ppresparams = (PRESPARAMS *) xmalloc(PP_MAXBUF, pszSrcFile, __LINE__);
49 if (!ppresparams)
50 return;
51 ppresparams->cb = 0L; /* no entries yet */
52 pparam = ppresparams->aparam; /* cast structure onto memory */
53
54 /*
55 * query every possible presentation parameter...
56 */
57
58 /* foreground color -- takes 12 bytes */
59 pparam->cb = WinQueryPresParam(hwnd,
60 PP_FOREGROUNDCOLOR,
61 PP_FOREGROUNDCOLORINDEX,
62 &pparam->id,
63 sizeof(LONG),
64 (PVOID) pparam->ab, QPF_NOINHERIT);
65 if (pparam->cb) { /* was the param found? */
66 ppresparams->cb += 12L; /* used 12 bytes */
67 pparam = (PPARAM) (((ULONG) pparam) + 12L); /* advance 12 bytes to next memory location */
68 }
69
70 /* background color -- takes 12 bytes */
71 pparam->cb = WinQueryPresParam(hwnd,
72 PP_BACKGROUNDCOLOR,
73 PP_BACKGROUNDCOLORINDEX,
74 &pparam->id,
75 sizeof(LONG),
76 (PVOID) pparam->ab, QPF_NOINHERIT);
77 if (pparam->cb) {
78 ppresparams->cb += 12L;
79 pparam = (PPARAM) (((ULONG) pparam) + 12L);
80 }
81
82 /* hilited foreground color -- takes 12 bytes */
83 pparam->cb = WinQueryPresParam(hwnd,
84 PP_HILITEFOREGROUNDCOLOR,
85 PP_HILITEFOREGROUNDCOLORINDEX,
86 &pparam->id,
87 sizeof(LONG),
88 (PVOID) pparam->ab, QPF_NOINHERIT);
89 if (pparam->cb) {
90 ppresparams->cb += 12L;
91 pparam = (PPARAM) (((ULONG) pparam) + 12L);
92 }
93
94 /* hilited background color -- takes 12 bytes */
95 pparam->cb = WinQueryPresParam(hwnd,
96 PP_HILITEBACKGROUNDCOLOR,
97 PP_HILITEBACKGROUNDCOLORINDEX,
98 &pparam->id,
99 sizeof(LONG),
100 (PVOID) pparam->ab, QPF_NOINHERIT);
101 if (pparam->cb) {
102 ppresparams->cb += 12L;
103 pparam = (PPARAM) (((ULONG) pparam) + 12L);
104 }
105
106 /* disabled foreground color -- takes 12 bytes */
107 pparam->cb = WinQueryPresParam(hwnd,
108 PP_DISABLEDFOREGROUNDCOLOR,
109 PP_DISABLEDFOREGROUNDCOLORINDEX,
110 &pparam->id,
111 sizeof(LONG),
112 (PVOID) pparam->ab, QPF_NOINHERIT);
113 if (pparam->cb) {
114 ppresparams->cb += 12L;
115 pparam = (PPARAM) (((ULONG) pparam) + 12L);
116 }
117
118 /* disabled background color -- takes 12 bytes */
119 pparam->cb = WinQueryPresParam(hwnd,
120 PP_DISABLEDBACKGROUNDCOLOR,
121 PP_DISABLEDBACKGROUNDCOLORINDEX,
122 &pparam->id,
123 sizeof(LONG),
124 (PVOID) pparam->ab, QPF_NOINHERIT);
125 if (pparam->cb) {
126 ppresparams->cb += 12L;
127 pparam = (PPARAM) (((ULONG) pparam) + 12L);
128 }
129
130 /* border color -- takes 12 bytes */
131 pparam->cb = WinQueryPresParam(hwnd,
132 PP_BORDERCOLOR,
133 PP_BORDERCOLORINDEX,
134 &pparam->id,
135 sizeof(LONG),
136 (PVOID) pparam->ab, QPF_NOINHERIT);
137 if (pparam->cb) {
138 ppresparams->cb += 12L;
139 pparam = (PPARAM) (((ULONG) pparam) + 12L);
140 }
141
142 /* font name & size -- maximum 44 bytes (32 for face name, 4 for point size) + 8 for data */
143 pparam->cb = WinQueryPresParam(hwnd,
144 PP_FONTNAMESIZE,
145 0L,
146 &pparam->id,
147 36L, (PVOID) pparam->ab, QPF_NOINHERIT);
148 if (pparam->cb) {
149 ppresparams->cb += (pparam->cb + 8L);
150 pparam = (PPARAM) (((ULONG) pparam) + pparam->cb + 8L);
151 }
152
153 /* active color -- takes 12 bytes */
154 pparam->cb = WinQueryPresParam(hwnd,
155 PP_ACTIVECOLOR,
156 PP_ACTIVECOLORINDEX,
157 &pparam->id,
158 sizeof(LONG),
159 (PVOID) pparam->ab, QPF_NOINHERIT);
160 if (pparam->cb) {
161 ppresparams->cb += 12L;
162 pparam = (PPARAM) (((ULONG) pparam) + 12L);
163 }
164
165 /* inactive color -- takes 12 bytes */
166 pparam->cb = WinQueryPresParam(hwnd,
167 PP_INACTIVECOLOR,
168 PP_INACTIVECOLORINDEX,
169 &pparam->id,
170 sizeof(LONG),
171 (PVOID) pparam->ab, QPF_NOINHERIT);
172 if (pparam->cb) {
173 ppresparams->cb += 12L;
174 pparam = (PPARAM) (((ULONG) pparam) + 12L);
175 }
176
177 /* active text foreground color -- takes 12 bytes */
178 pparam->cb = WinQueryPresParam(hwnd,
179 PP_ACTIVETEXTFGNDCOLOR,
180 PP_ACTIVETEXTFGNDCOLORINDEX,
181 &pparam->id,
182 sizeof(LONG),
183 (PVOID) pparam->ab,
184 QPF_NOINHERIT | QPF_PURERGBCOLOR);
185 if (pparam->cb) {
186 ppresparams->cb += 12L;
187 pparam = (PPARAM) (((ULONG) pparam) + 12L);
188 }
189
190 /* active text background color -- takes 12 bytes */
191 pparam->cb = WinQueryPresParam(hwnd,
192 PP_ACTIVETEXTBGNDCOLOR,
193 PP_ACTIVETEXTBGNDCOLORINDEX,
194 &pparam->id,
195 sizeof(LONG),
196 (PVOID) pparam->ab,
197 QPF_NOINHERIT | QPF_PURERGBCOLOR);
198 if (pparam->cb) {
199 ppresparams->cb += 12L;
200 pparam = (PPARAM) (((ULONG) pparam) + 12L);
201 }
202
203 /* inactive text foreground color -- takes 12 bytes */
204 pparam->cb = WinQueryPresParam(hwnd,
205 PP_INACTIVETEXTFGNDCOLOR,
206 PP_INACTIVETEXTFGNDCOLORINDEX,
207 &pparam->id,
208 sizeof(LONG),
209 (PVOID) pparam->ab,
210 QPF_NOINHERIT | QPF_PURERGBCOLOR);
211 if (pparam->cb) {
212 ppresparams->cb += 12L;
213 pparam = (PPARAM) (((ULONG) pparam) + 12L);
214 }
215
216 /* inactive text background color -- takes 12 bytes */
217 pparam->cb = WinQueryPresParam(hwnd,
218 PP_INACTIVETEXTBGNDCOLOR,
219 PP_INACTIVETEXTBGNDCOLORINDEX,
220 &pparam->id,
221 sizeof(LONG),
222 (PVOID) pparam->ab,
223 QPF_NOINHERIT | QPF_PURERGBCOLOR);
224 if (pparam->cb) {
225 ppresparams->cb += 12L;
226 pparam = (PPARAM) (((ULONG) pparam) + 12L);
227 }
228
229 /* shadow color -- takes 12 bytes */
230 pparam->cb = WinQueryPresParam(hwnd,
231 PP_SHADOW, 0L,
232 &pparam->id,
233 sizeof(LONG),
234 (PVOID) pparam->ab, QPF_NOINHERIT);
235 if (pparam->cb) {
236 ppresparams->cb += 12L;
237 pparam = (PPARAM) (((ULONG) pparam) + 12L);
238 }
239
240 /* menu foreground color -- takes 12 bytes */
241 pparam->cb = WinQueryPresParam(hwnd,
242 PP_MENUFOREGROUNDCOLOR,
243 PP_MENUFOREGROUNDCOLORINDEX,
244 &pparam->id,
245 sizeof(LONG),
246 (PVOID) pparam->ab, QPF_NOINHERIT);
247 if (pparam->cb) {
248 ppresparams->cb += 12L;
249 pparam = (PPARAM) (((ULONG) pparam) + 12L);
250 }
251
252 /* menu background color -- takes 12 bytes */
253 pparam->cb = WinQueryPresParam(hwnd,
254 PP_MENUBACKGROUNDCOLOR,
255 PP_MENUBACKGROUNDCOLORINDEX,
256 &pparam->id,
257 sizeof(LONG),
258 (PVOID) pparam->ab, QPF_NOINHERIT);
259 if (pparam->cb) {
260 ppresparams->cb += 12L;
261 pparam = (PPARAM) (((ULONG) pparam) + 12L);
262 }
263
264 /* menu hilite foreground color -- takes 12 bytes */
265 pparam->cb = WinQueryPresParam(hwnd,
266 PP_MENUHILITEFGNDCOLOR,
267 PP_MENUHILITEFGNDCOLORINDEX,
268 &pparam->id,
269 sizeof(LONG),
270 (PVOID) pparam->ab, QPF_NOINHERIT);
271 if (pparam->cb) {
272 ppresparams->cb += 12L;
273 pparam = (PPARAM) (((ULONG) pparam) + 12L);
274 }
275
276 /* menu hilite background color -- takes 12 bytes */
277 pparam->cb = WinQueryPresParam(hwnd,
278 PP_MENUHILITEBGNDCOLOR,
279 PP_MENUHILITEBGNDCOLORINDEX,
280 &pparam->id,
281 sizeof(LONG),
282 (PVOID) pparam->ab, QPF_NOINHERIT);
283 if (pparam->cb) {
284 ppresparams->cb += 12L;
285 pparam = (PPARAM) (((ULONG) pparam) + 12L);
286 }
287
288 /* menu disabled foreground color -- takes 12 bytes */
289 pparam->cb = WinQueryPresParam(hwnd,
290 PP_MENUDISABLEDFGNDCOLOR,
291 PP_MENUDISABLEDFGNDCOLORINDEX,
292 &pparam->id,
293 sizeof(LONG),
294 (PVOID) pparam->ab, QPF_NOINHERIT);
295 if (pparam->cb) {
296 ppresparams->cb += 12L;
297 pparam = (PPARAM) (((ULONG) pparam) + 12L);
298 }
299
300 /* menu disabled background color -- takes 12 bytes */
301 pparam->cb = WinQueryPresParam(hwnd,
302 PP_MENUDISABLEDBGNDCOLOR,
303 PP_MENUDISABLEDBGNDCOLORINDEX,
304 &pparam->id,
305 sizeof(LONG),
306 (PVOID) pparam->ab, QPF_NOINHERIT);
307 if (pparam->cb) {
308 ppresparams->cb += 12L;
309 pparam = (PPARAM) (((ULONG) pparam) + 12L);
310 }
311
312 if (ppresparams->cb)
313 PrfWriteProfileData(prof,
314 appname, tagname, ppresparams, ppresparams->cb + 4L);
315
316 free(ppresparams);
317}
318
319#endif // NEVER
320
321VOID CopyPresParams(HWND target, HWND source)
322{
323 /*
324 * Copy presentation parameters of interest to us from one window
325 * to another
326 */
327
328 ULONG AttrFound, AttrValue[64], cbRetLen, x = 0L,
329 AttrName[] = { PP_FONTNAMESIZE, PP_BACKGROUNDCOLOR,
330 PP_FOREGROUNDCOLOR, PP_HILITEBACKGROUNDCOLOR,
331 PP_HILITEFOREGROUNDCOLOR, PP_BORDERCOLOR,
332 0L
333 };
334
335 while (AttrName[x]) {
336 cbRetLen = WinQueryPresParam(source,
337 AttrName[x],
338 0,
339 &AttrFound,
340 (ULONG) sizeof(AttrValue), &AttrValue, 0);
341 if (cbRetLen)
342 WinSetPresParam(target, AttrName[x], cbRetLen, (PVOID) AttrValue);
343 x++;
344 }
345}
346
347VOID SetPresParams(HWND hwnd, RGB2 * back, RGB2 * fore, RGB2 * border,
348 CHAR * font)
349{
350 if (font)
351 WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(font) + 1L, (PVOID) font);
352 if (back)
353 WinSetPresParam(hwnd, PP_BACKGROUNDCOLOR, sizeof(RGB2), (PVOID) back);
354 if (fore)
355 WinSetPresParam(hwnd, PP_FOREGROUNDCOLOR, sizeof(RGB2), (PVOID) fore);
356 if (border)
357 WinSetPresParam(hwnd, PP_BORDERCOLOR, sizeof(RGB2), (PVOID) border);
358}
359
360VOID IfNoParam(HWND hwnd, CHAR * keyroot, ULONG size, PVOID attrvalue)
361{
362 ULONG fsize = 0L;
363 CHAR s[81];
364
365 sprintf(s, "%s", keyroot);
366 if (!PrfQueryProfileSize(fmprof, appname, s, &fsize) || !fsize)
367 WinSetPresParam(hwnd, PP_FONTNAMESIZE, size, (PVOID) attrvalue);
368}
369
370VOID PresParamChanged(HWND hwnd, CHAR * keyroot, MPARAM mp1, MPARAM mp2)
371{
372 ULONG AttrFound, AttrValue[64], cbRetLen;
373
374 cbRetLen = WinQueryPresParam(hwnd, (ULONG) mp1, 0, &AttrFound,
375 (ULONG) sizeof(AttrValue), &AttrValue, 0);
376 if (cbRetLen) {
377
378 CHAR s[133];
379
380 *s = 0;
381 switch (AttrFound) {
382 case PP_BACKGROUNDCOLOR:
383 sprintf(s, "%s.Backgroundcolor", keyroot);
384 break;
385 case PP_FOREGROUNDCOLOR:
386 sprintf(s, "%s.Foregroundcolor", keyroot);
387 break;
388 case PP_HILITEBACKGROUNDCOLOR:
389 sprintf(s, "%s.Hilitebackgroundcolor", keyroot);
390 break;
391 case PP_HILITEFOREGROUNDCOLOR:
392 sprintf(s, "%s.Hiliteforegroundcolor", keyroot);
393 break;
394 case PP_BORDERCOLOR:
395 sprintf(s, "%s.Bordercolor", keyroot);
396 break;
397 case PP_FONTNAMESIZE:
398 sprintf(s, "%s.Fontnamesize", keyroot);
399 break;
400 default:
401 break;
402 }
403 if (*s)
404 PrfWriteProfileData(fmprof, appname, s, (PVOID) AttrValue, cbRetLen);
405 }
406}
407
408VOID RestorePresParams(HWND hwnd, CHAR * keyroot)
409{
410 CHAR s[81];
411 ULONG AttrValue[64], size;
412
413 size = sizeof(AttrValue);
414 sprintf(s, "%s.Backgroundcolor", keyroot);
415 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
416 && size)
417 WinSetPresParam(hwnd, PP_BACKGROUNDCOLOR, size, (PVOID) AttrValue);
418 size = sizeof(AttrValue);
419 sprintf(s, "%s.Foregroundcolor", keyroot);
420 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
421 && size)
422 WinSetPresParam(hwnd, PP_FOREGROUNDCOLOR, size, (PVOID) AttrValue);
423 size = sizeof(AttrValue);
424 sprintf(s, "%s.Hilitebackgroundcolor", keyroot);
425 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
426 && size)
427 WinSetPresParam(hwnd, PP_HILITEBACKGROUNDCOLOR, size, (PVOID) AttrValue);
428 size = sizeof(AttrValue);
429 sprintf(s, "%s.Hiliteforegroundcolor", keyroot);
430 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
431 && size)
432 WinSetPresParam(hwnd, PP_HILITEFOREGROUNDCOLOR, size, (PVOID) AttrValue);
433 size = sizeof(AttrValue);
434 sprintf(s, "%s.Bordercolor", keyroot);
435 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
436 && size)
437 WinSetPresParam(hwnd, PP_BORDERCOLOR, size, (PVOID) AttrValue);
438 size = sizeof(AttrValue);
439 sprintf(s, "%s.Fontnamesize", keyroot);
440 if (PrfQueryProfileData(fmprof,
441 appname, s, (PVOID) AttrValue, &size) && size)
442 WinSetPresParam(hwnd, PP_FONTNAMESIZE, size, (PVOID) AttrValue);
443}
Note: See TracBrowser for help on using the repository browser.