source: trunk/dll/presparm.c@ 877

Last change on this file since 877 was 877, checked in by Gregg Young, 18 years ago

Cleaned up actual fix for drop down menu fonts and colors not matching.

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