source: trunk/dll/presparm.c@ 881

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

CopyPresParams now copies menu colors

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1
2/***********************************************************************
3
4 $Id: presparm.c 881 2007-11-30 00:47:02Z 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, PP_MENUFOREGROUNDCOLOR,
330 PP_MENUBACKGROUNDCOLOR};
331
332 for (x=0; x < 8; x++) {
333 cbRetLen = WinQueryPresParam(source,
334 AttrName[x],
335 0,
336 &AttrFound,
337 sizeof(AttrValue),
338 &AttrValue, 0);
339 //printf("%s %x\n", AttrValue, source); fflush(stdout);
340 //printf("%x\n", AttrValue); fflush(stdout);
341 if (cbRetLen)
342 WinSetPresParam(target, AttrName[x], cbRetLen, (PVOID) AttrValue);
343 } //for
344}
345
346VOID SetPresParams(HWND hwnd, RGB2 * back, RGB2 * fore, RGB2 * border,
347 CHAR * font)
348{
349 if (font)
350 WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(font) + 1, (PVOID) font);
351 if (back)
352 WinSetPresParam(hwnd, PP_BACKGROUNDCOLOR, sizeof(RGB2), (PVOID) back);
353 if (fore)
354 WinSetPresParam(hwnd, PP_FOREGROUNDCOLOR, sizeof(RGB2), (PVOID) fore);
355 if (border)
356 WinSetPresParam(hwnd, PP_BORDERCOLOR, sizeof(RGB2), (PVOID) border);
357}
358
359VOID IfNoParam(HWND hwnd, CHAR * keyroot, ULONG size, PVOID attrvalue)
360{
361 ULONG fsize = 0;
362 CHAR s[81];
363
364 sprintf(s, "%s", keyroot);
365 if (!PrfQueryProfileSize(fmprof, appname, s, &fsize) || !fsize)
366 WinSetPresParam(hwnd, PP_FONTNAMESIZE, size, (PVOID) attrvalue);
367}
368
369VOID PresParamChanged(HWND hwnd, CHAR * keyroot, MPARAM mp1, MPARAM mp2)
370{
371 ULONG AttrFound, AttrValue[64], cbRetLen;
372
373 cbRetLen = WinQueryPresParam(hwnd, (ULONG) mp1, 0, &AttrFound,
374 (ULONG) sizeof(AttrValue), &AttrValue, 0);
375 if (cbRetLen) {
376
377 CHAR s[133];
378
379 *s = 0;
380 switch (AttrFound) {
381 case PP_BACKGROUNDCOLOR:
382 sprintf(s, "%s.Backgroundcolor", keyroot);
383 break;
384 case PP_FOREGROUNDCOLOR:
385 sprintf(s, "%s.Foregroundcolor", keyroot);
386 break;
387 case PP_HILITEBACKGROUNDCOLOR:
388 sprintf(s, "%s.Hilitebackgroundcolor", keyroot);
389 break;
390 case PP_HILITEFOREGROUNDCOLOR:
391 sprintf(s, "%s.Hiliteforegroundcolor", keyroot);
392 break;
393 case PP_BORDERCOLOR:
394 sprintf(s, "%s.Bordercolor", keyroot);
395 break;
396 case PP_FONTNAMESIZE:
397 sprintf(s, "%s.Fontnamesize", keyroot);
398 break;
399 default:
400 break;
401 }
402 if (*s)
403 PrfWriteProfileData(fmprof, appname, s, (PVOID) AttrValue, cbRetLen);
404 }
405}
406
407VOID RestorePresParams(HWND hwnd, CHAR * keyroot)
408{
409 CHAR s[81];
410 ULONG AttrValue[64], size;
411
412 size = sizeof(AttrValue);
413 sprintf(s, "%s.Backgroundcolor", keyroot);
414 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
415 && size)
416 WinSetPresParam(hwnd, PP_BACKGROUNDCOLOR, size, (PVOID) AttrValue);
417 size = sizeof(AttrValue);
418 sprintf(s, "%s.Foregroundcolor", keyroot);
419 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
420 && size)
421 WinSetPresParam(hwnd, PP_FOREGROUNDCOLOR, size, (PVOID) AttrValue);
422 size = sizeof(AttrValue);
423 sprintf(s, "%s.Hilitebackgroundcolor", keyroot);
424 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
425 && size)
426 WinSetPresParam(hwnd, PP_HILITEBACKGROUNDCOLOR, size, (PVOID) AttrValue);
427 size = sizeof(AttrValue);
428 sprintf(s, "%s.Hiliteforegroundcolor", keyroot);
429 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
430 && size)
431 WinSetPresParam(hwnd, PP_HILITEFOREGROUNDCOLOR, size, (PVOID) AttrValue);
432 size = sizeof(AttrValue);
433 sprintf(s, "%s.Bordercolor", keyroot);
434 if (PrfQueryProfileData(fmprof, appname, s, (PVOID) AttrValue, &size)
435 && size)
436 WinSetPresParam(hwnd, PP_BORDERCOLOR, size, (PVOID) AttrValue);
437 size = sizeof(AttrValue);
438 sprintf(s, "%s.Fontnamesize", keyroot);
439 if (PrfQueryProfileData(fmprof,
440 appname, s, (PVOID) AttrValue, &size) && size)
441 WinSetPresParam(hwnd, PP_FONTNAMESIZE, size, (PVOID) AttrValue);
442}
443
444#pragma alloc_text(PRESPARAM,CopyPresParams,SetPresParams,IfNoParam)
445#pragma alloc_text(PRESPARAM,PresParamChanged,RestorePresParams)
446#pragma alloc_text(PRESPARAM,StoreWndPresParams)
Note: See TracBrowser for help on using the repository browser.