source: trunk/dll/presparm.c@ 356

Last change on this file since 356 was 356, checked in by root, 19 years ago

Check more run time errors

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.5 KB
Line 
1
2/***********************************************************************
3
4 $Id: presparm.c 356 2006-07-26 19:58:37Z root $
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,
65 QPF_NOINHERIT);
66 if(pparam->cb) { /* was the param found? */
67 ppresparams->cb += 12L; /* used 12 bytes */
68 pparam = (PPARAM)(((ULONG)pparam) + 12L); /* advance 12 bytes to next memory location */
69 }
70
71 /* background color -- takes 12 bytes */
72 pparam->cb = WinQueryPresParam(hwnd,
73 PP_BACKGROUNDCOLOR,
74 PP_BACKGROUNDCOLORINDEX,
75 &pparam->id,
76 sizeof(LONG),
77 (PVOID)pparam->ab,
78 QPF_NOINHERIT);
79 if(pparam->cb) {
80 ppresparams->cb += 12L;
81 pparam = (PPARAM)(((ULONG)pparam) + 12L);
82 }
83
84 /* hilited foreground color -- takes 12 bytes */
85 pparam->cb = WinQueryPresParam(hwnd,
86 PP_HILITEFOREGROUNDCOLOR,
87 PP_HILITEFOREGROUNDCOLORINDEX,
88 &pparam->id,
89 sizeof(LONG),
90 (PVOID)pparam->ab,
91 QPF_NOINHERIT);
92 if(pparam->cb) {
93 ppresparams->cb += 12L;
94 pparam = (PPARAM)(((ULONG)pparam) + 12L);
95 }
96
97 /* hilited background color -- takes 12 bytes */
98 pparam->cb = WinQueryPresParam(hwnd,
99 PP_HILITEBACKGROUNDCOLOR,
100 PP_HILITEBACKGROUNDCOLORINDEX,
101 &pparam->id,
102 sizeof(LONG),
103 (PVOID)pparam->ab,
104 QPF_NOINHERIT);
105 if(pparam->cb) {
106 ppresparams->cb += 12L;
107 pparam = (PPARAM)(((ULONG)pparam) + 12L);
108 }
109
110 /* disabled foreground color -- takes 12 bytes */
111 pparam->cb = WinQueryPresParam(hwnd,
112 PP_DISABLEDFOREGROUNDCOLOR,
113 PP_DISABLEDFOREGROUNDCOLORINDEX,
114 &pparam->id,
115 sizeof(LONG),
116 (PVOID)pparam->ab,
117 QPF_NOINHERIT);
118 if(pparam->cb) {
119 ppresparams->cb += 12L;
120 pparam = (PPARAM)(((ULONG)pparam) + 12L);
121 }
122
123 /* disabled background color -- takes 12 bytes */
124 pparam->cb = WinQueryPresParam(hwnd,
125 PP_DISABLEDBACKGROUNDCOLOR,
126 PP_DISABLEDBACKGROUNDCOLORINDEX,
127 &pparam->id,
128 sizeof(LONG),
129 (PVOID)pparam->ab,
130 QPF_NOINHERIT);
131 if(pparam->cb) {
132 ppresparams->cb += 12L;
133 pparam = (PPARAM)(((ULONG)pparam) + 12L);
134 }
135
136 /* border color -- takes 12 bytes */
137 pparam->cb = WinQueryPresParam(hwnd,
138 PP_BORDERCOLOR,
139 PP_BORDERCOLORINDEX,
140 &pparam->id,
141 sizeof(LONG),
142 (PVOID)pparam->ab,
143 QPF_NOINHERIT);
144 if(pparam->cb) {
145 ppresparams->cb += 12L;
146 pparam = (PPARAM)(((ULONG)pparam) + 12L);
147 }
148
149 /* font name & size -- maximum 44 bytes (32 for face name, 4 for point size) + 8 for data */
150 pparam->cb = WinQueryPresParam(hwnd,
151 PP_FONTNAMESIZE,
152 0L,
153 &pparam->id,
154 36L,
155 (PVOID)pparam->ab,
156 QPF_NOINHERIT);
157 if(pparam->cb) {
158 ppresparams->cb += (pparam->cb + 8L);
159 pparam = (PPARAM)(((ULONG)pparam) + pparam->cb + 8L);
160 }
161
162 /* active color -- takes 12 bytes */
163 pparam->cb = WinQueryPresParam(hwnd,
164 PP_ACTIVECOLOR,
165 PP_ACTIVECOLORINDEX,
166 &pparam->id,
167 sizeof(LONG),
168 (PVOID)pparam->ab,
169 QPF_NOINHERIT);
170 if(pparam->cb) {
171 ppresparams->cb += 12L;
172 pparam = (PPARAM)(((ULONG)pparam) + 12L);
173 }
174
175 /* inactive color -- takes 12 bytes */
176 pparam->cb = WinQueryPresParam(hwnd,
177 PP_INACTIVECOLOR,
178 PP_INACTIVECOLORINDEX,
179 &pparam->id,
180 sizeof(LONG),
181 (PVOID)pparam->ab,
182 QPF_NOINHERIT);
183 if(pparam->cb) {
184 ppresparams->cb += 12L;
185 pparam = (PPARAM)(((ULONG)pparam) + 12L);
186 }
187
188 /* active text foreground color -- takes 12 bytes */
189 pparam->cb = WinQueryPresParam(hwnd,
190 PP_ACTIVETEXTFGNDCOLOR,
191 PP_ACTIVETEXTFGNDCOLORINDEX,
192 &pparam->id,
193 sizeof(LONG),
194 (PVOID)pparam->ab,
195 QPF_NOINHERIT | QPF_PURERGBCOLOR);
196 if(pparam->cb) {
197 ppresparams->cb += 12L;
198 pparam = (PPARAM)(((ULONG)pparam) + 12L);
199 }
200
201 /* active text background color -- takes 12 bytes */
202 pparam->cb = WinQueryPresParam(hwnd,
203 PP_ACTIVETEXTBGNDCOLOR,
204 PP_ACTIVETEXTBGNDCOLORINDEX,
205 &pparam->id,
206 sizeof(LONG),
207 (PVOID)pparam->ab,
208 QPF_NOINHERIT | QPF_PURERGBCOLOR);
209 if(pparam->cb) {
210 ppresparams->cb += 12L;
211 pparam = (PPARAM)(((ULONG)pparam) + 12L);
212 }
213
214 /* inactive text foreground color -- takes 12 bytes */
215 pparam->cb = WinQueryPresParam(hwnd,
216 PP_INACTIVETEXTFGNDCOLOR,
217 PP_INACTIVETEXTFGNDCOLORINDEX,
218 &pparam->id,
219 sizeof(LONG),
220 (PVOID)pparam->ab,
221 QPF_NOINHERIT | QPF_PURERGBCOLOR);
222 if(pparam->cb) {
223 ppresparams->cb += 12L;
224 pparam = (PPARAM)(((ULONG)pparam) + 12L);
225 }
226
227 /* inactive text background color -- takes 12 bytes */
228 pparam->cb = WinQueryPresParam(hwnd,
229 PP_INACTIVETEXTBGNDCOLOR,
230 PP_INACTIVETEXTBGNDCOLORINDEX,
231 &pparam->id,
232 sizeof(LONG),
233 (PVOID)pparam->ab,
234 QPF_NOINHERIT | QPF_PURERGBCOLOR);
235 if(pparam->cb) {
236 ppresparams->cb += 12L;
237 pparam = (PPARAM)(((ULONG)pparam) + 12L);
238 }
239
240 /* shadow color -- takes 12 bytes */
241 pparam->cb = WinQueryPresParam(hwnd,
242 PP_SHADOW, 0L,
243 &pparam->id,
244 sizeof(LONG),
245 (PVOID)pparam->ab,
246 QPF_NOINHERIT);
247 if(pparam->cb) {
248 ppresparams->cb += 12L;
249 pparam = (PPARAM)(((ULONG)pparam) + 12L);
250 }
251
252 /* menu foreground color -- takes 12 bytes */
253 pparam->cb = WinQueryPresParam(hwnd,
254 PP_MENUFOREGROUNDCOLOR,
255 PP_MENUFOREGROUNDCOLORINDEX,
256 &pparam->id,
257 sizeof(LONG),
258 (PVOID)pparam->ab,
259 QPF_NOINHERIT);
260 if(pparam->cb) {
261 ppresparams->cb += 12L;
262 pparam = (PPARAM)(((ULONG)pparam) + 12L);
263 }
264
265 /* menu background color -- takes 12 bytes */
266 pparam->cb = WinQueryPresParam(hwnd,
267 PP_MENUBACKGROUNDCOLOR,
268 PP_MENUBACKGROUNDCOLORINDEX,
269 &pparam->id,
270 sizeof(LONG),
271 (PVOID)pparam->ab,
272 QPF_NOINHERIT);
273 if(pparam->cb) {
274 ppresparams->cb += 12L;
275 pparam = (PPARAM)(((ULONG)pparam) + 12L);
276 }
277
278 /* menu hilite foreground color -- takes 12 bytes */
279 pparam->cb = WinQueryPresParam(hwnd,
280 PP_MENUHILITEFGNDCOLOR,
281 PP_MENUHILITEFGNDCOLORINDEX,
282 &pparam->id,
283 sizeof(LONG),
284 (PVOID)pparam->ab,
285 QPF_NOINHERIT);
286 if(pparam->cb) {
287 ppresparams->cb += 12L;
288 pparam = (PPARAM)(((ULONG)pparam) + 12L);
289 }
290
291 /* menu hilite background color -- takes 12 bytes */
292 pparam->cb = WinQueryPresParam(hwnd,
293 PP_MENUHILITEBGNDCOLOR,
294 PP_MENUHILITEBGNDCOLORINDEX,
295 &pparam->id,
296 sizeof(LONG),
297 (PVOID)pparam->ab,
298 QPF_NOINHERIT);
299 if(pparam->cb) {
300 ppresparams->cb += 12L;
301 pparam = (PPARAM)(((ULONG)pparam) + 12L);
302 }
303
304 /* menu disabled foreground color -- takes 12 bytes */
305 pparam->cb = WinQueryPresParam(hwnd,
306 PP_MENUDISABLEDFGNDCOLOR,
307 PP_MENUDISABLEDFGNDCOLORINDEX,
308 &pparam->id,
309 sizeof(LONG),
310 (PVOID)pparam->ab,
311 QPF_NOINHERIT);
312 if(pparam->cb) {
313 ppresparams->cb += 12L;
314 pparam = (PPARAM)(((ULONG)pparam) + 12L);
315 }
316
317 /* menu disabled background color -- takes 12 bytes */
318 pparam->cb = WinQueryPresParam(hwnd,
319 PP_MENUDISABLEDBGNDCOLOR,
320 PP_MENUDISABLEDBGNDCOLORINDEX,
321 &pparam->id,
322 sizeof(LONG),
323 (PVOID)pparam->ab,
324 QPF_NOINHERIT);
325 if(pparam->cb) {
326 ppresparams->cb += 12L;
327 pparam = (PPARAM)(((ULONG)pparam) + 12L);
328 }
329
330 if(ppresparams->cb)
331 PrfWriteProfileData(prof,
332 appname,
333 tagname,
334 ppresparams,
335 ppresparams->cb + 4L);
336
337 free(ppresparams);
338}
339
340#endif // NEVER
341
342
343VOID CopyPresParams (HWND target,HWND source)
344{
345 /*
346 * Copy presentation parameters of interest to us from one window
347 * to another
348 */
349
350 ULONG AttrFound, AttrValue[64], cbRetLen, x = 0L,
351 AttrName[] = {PP_FONTNAMESIZE, PP_BACKGROUNDCOLOR,
352 PP_FOREGROUNDCOLOR, PP_HILITEBACKGROUNDCOLOR,
353 PP_HILITEFOREGROUNDCOLOR, PP_BORDERCOLOR,
354 0L};
355
356 while(AttrName[x]) {
357 cbRetLen = WinQueryPresParam(source,
358 AttrName[x],
359 0,
360 &AttrFound,
361 (ULONG)sizeof(AttrValue),
362 &AttrValue,0);
363 if(cbRetLen)
364 WinSetPresParam(target,
365 AttrName[x],
366 cbRetLen,
367 (PVOID)AttrValue);
368 x++;
369 }
370}
371
372
373VOID SetPresParams (HWND hwnd,RGB2 *back,RGB2 *fore,RGB2 *border,CHAR *font)
374{
375 if(font)
376 WinSetPresParam(hwnd,
377 PP_FONTNAMESIZE,
378 strlen(font) + 1L,
379 (PVOID)font);
380 if(back)
381 WinSetPresParam(hwnd,
382 PP_BACKGROUNDCOLOR,
383 sizeof(RGB2),
384 (PVOID)back);
385 if(fore)
386 WinSetPresParam(hwnd,
387 PP_FOREGROUNDCOLOR,
388 sizeof(RGB2),
389 (PVOID)fore);
390 if(border)
391 WinSetPresParam(hwnd,
392 PP_BORDERCOLOR,
393 sizeof(RGB2),
394 (PVOID)border);
395}
396
397
398VOID IfNoParam(HWND hwnd,CHAR *keyroot,ULONG size,PVOID attrvalue)
399{
400 ULONG fsize = 0L;
401 CHAR s[81];
402
403 sprintf(s,
404 "%s",
405 keyroot);
406 if(!PrfQueryProfileSize(fmprof,
407 appname,
408 s,
409 &fsize) ||
410 !fsize)
411 WinSetPresParam(hwnd,
412 PP_FONTNAMESIZE,
413 size,
414 (PVOID)attrvalue);
415}
416
417
418VOID PresParamChanged (HWND hwnd,CHAR *keyroot,MPARAM mp1,MPARAM mp2)
419{
420 ULONG AttrFound,AttrValue[64],cbRetLen;
421
422 cbRetLen = WinQueryPresParam(hwnd,(ULONG)mp1,0,&AttrFound,
423 (ULONG)sizeof(AttrValue),
424 &AttrValue,0);
425 if(cbRetLen) {
426
427 CHAR s[133];
428
429 *s = 0;
430 switch(AttrFound) {
431 case PP_BACKGROUNDCOLOR:
432 sprintf(s,"%s.Backgroundcolor",keyroot);
433 break;
434 case PP_FOREGROUNDCOLOR:
435 sprintf(s,"%s.Foregroundcolor",keyroot);
436 break;
437 case PP_HILITEBACKGROUNDCOLOR:
438 sprintf(s,"%s.Hilitebackgroundcolor",keyroot);
439 break;
440 case PP_HILITEFOREGROUNDCOLOR:
441 sprintf(s,"%s.Hiliteforegroundcolor",keyroot);
442 break;
443 case PP_BORDERCOLOR:
444 sprintf(s,"%s.Bordercolor",keyroot);
445 break;
446 case PP_FONTNAMESIZE:
447 sprintf(s,"%s.Fontnamesize",keyroot);
448 break;
449 default:
450 break;
451 }
452 if(*s)
453 PrfWriteProfileData(fmprof,appname,s,(PVOID)AttrValue,cbRetLen);
454 }
455}
456
457
458VOID RestorePresParams (HWND hwnd,CHAR *keyroot)
459{
460 CHAR s[81];
461 ULONG AttrValue[64],size;
462
463 size = sizeof(AttrValue);
464 sprintf(s,"%s.Backgroundcolor",keyroot);
465 if(PrfQueryProfileData(fmprof,appname,s,(PVOID)AttrValue,&size) && size)
466 WinSetPresParam(hwnd,PP_BACKGROUNDCOLOR,size,(PVOID)AttrValue);
467 size = sizeof(AttrValue);
468 sprintf(s,"%s.Foregroundcolor",keyroot);
469 if(PrfQueryProfileData(fmprof,appname,s,(PVOID)AttrValue,&size) && size)
470 WinSetPresParam(hwnd,PP_FOREGROUNDCOLOR,size,(PVOID)AttrValue);
471 size = sizeof(AttrValue);
472 sprintf(s,"%s.Hilitebackgroundcolor",keyroot);
473 if(PrfQueryProfileData(fmprof,appname,s,(PVOID)AttrValue,&size) && size)
474 WinSetPresParam(hwnd,PP_HILITEBACKGROUNDCOLOR,size,(PVOID)AttrValue);
475 size = sizeof(AttrValue);
476 sprintf(s,"%s.Hiliteforegroundcolor",keyroot);
477 if(PrfQueryProfileData(fmprof,appname,s,(PVOID)AttrValue,&size) && size)
478 WinSetPresParam(hwnd,PP_HILITEFOREGROUNDCOLOR,size,(PVOID)AttrValue);
479 size = sizeof(AttrValue);
480 sprintf(s,"%s.Bordercolor",keyroot);
481 if(PrfQueryProfileData(fmprof,appname,s,(PVOID)AttrValue,&size) && size)
482 WinSetPresParam(hwnd,PP_BORDERCOLOR,size,(PVOID)AttrValue);
483 size = sizeof(AttrValue);
484 sprintf(s,"%s.Fontnamesize",keyroot);
485 if(PrfQueryProfileData(fmprof,
486 appname,
487 s,
488 (PVOID)AttrValue,
489 &size) &&
490 size)
491 WinSetPresParam(hwnd,
492 PP_FONTNAMESIZE,
493 size,
494 (PVOID)AttrValue);
495}
Note: See TracBrowser for help on using the repository browser.