1 /*   vibextra.c
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *            National Center for Biotechnology Information (NCBI)
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government do not place any restriction on its use or reproduction.
13 *  We would, however, appreciate having the NCBI and the author cited in
14 *  any work or product based on this material
15 *
16 *  Although all reasonable efforts have been taken to ensure the accuracy
17 *  and reliability of the software and data, the NLM and the U.S.
18 *  Government do not and cannot warrant the performance or results that
19 *  may be obtained by using this software or data. The NLM and the U.S.
20 *  Government disclaim all warranties, express or implied, including
21 *  warranties of performance, merchantability or fitness for any particular
22 *  purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name:  vibextra.c
27 *
28 * Author:  Jonathan Kans, Alex Smirnov
29 *
30 * Version Creation Date:   3/9/93
31 *
32 * $Revision: 6.3 $
33 *
34 * File Description:
35 *       Vibrant miscellaneous extensions
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * Date     Name        Description of modification
40 * -------  ----------  -----------------------------------------------------
41 *
42 *
43 * $Log: vibextra.c,v $
44 * Revision 6.3  2008/04/25 15:54:01  kans
45 * trivial changes for compatibility with MinGW cross-compiler - allows building Windows executable on Macintosh
46 *
47 * Revision 6.2  2001/03/19 19:15:17  juran
48 * Change "for (...);" to "for (...) ;" (added space before semicolon) to silence trying-to-be-helpful compiler warning.
49 *
50 * Revision 6.1  1997/11/26 21:30:14  vakatov
51 * Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
52 *
53 * Revision 6.0  1997/08/25 18:56:53  madden
54 * Revision changed to 6.0
55 *
56 * Revision 5.2  1996/10/28 19:33:47  vakatov
57 * [WIN_MOTIF]  Use Nlm_VibrantDefaultColormap() instead of the display
58 * default colormap everywhere in the color handling code.
59 * Made a lot of type castings to get rid of all compiler warnings.
60 *
61  * Revision 5.1  1996/07/25  19:48:09  vakatov
62  * [WIN_X]  Added #VOID_PIXEL to serve as the tmpColorPixel's void value
63  *
64  * Revision 5.0  1996/05/28  13:45:08  ostell
65  * Set to revision 5.0
66  *
67  * Revision 4.2  1996/04/24  21:20:45  vakatov
68  * Nlm_ChooseColorDialog(): Nlm_WaitForCondition() to wait for the modal
69  * dialog finishing
70  *
71  * Revision 4.1  1996/02/27  16:31:13  kans
72  * subclass folder tabs to allow SetValue (but with 0, not 1, as first value)
73  *
74  * Revision 4.0  1995/07/26  13:51:04  ostell
75  * force revision to 4.0
76  *
77  * Revision 1.20  1995/05/20  18:27:38  kans
78  * replaced ; accidentally removed when log message was added
79  *
80  * Revision 1.19  1995/05/17  15:15:14  kans
81  * added Log line
82  *
83 *
84 * ==========================================================================
85 */
86 
87 #include <vibtypes.h>
88 #include <vibprocs.h>
89 #include <vibincld.h>
90 #include <ncbiport.h>
91 
92 #ifdef WIN_MSWIN
93 #include<commdlg.h>
94 /*
95 #include<colordlg.h>
96 */
97 #endif
98 
99 #ifdef VAR_ARGS
100 #include <varargs.h>
101 #else
102 #include <stdarg.h>
103 #endif
104 
105 typedef  struct  Nlm_repeatdata {
106   Nlm_Handle       title;
107   Nlm_RptClckProc  action;
108 } Nlm_RepeatData;
109 
110 typedef struct Nlm_switchdata {
111   Nlm_Int2         max;
112   Nlm_Int2         val;
113   Nlm_Boolean      text;
114   Nlm_Boolean      vert;
115   Nlm_Boolean      upActv;
116   Nlm_Boolean      dnActv;
117   Nlm_SwtChngProc  actn;
118 } Nlm_SwitchData;
119 
120 typedef  struct  Nlm_icondata {
121   Nlm_IcnChngProc  inval;
122   Nlm_Int2         value;
123   Nlm_Boolean      status;
124   Nlm_Handle       title;
125 } Nlm_IconData;
126 
127 static Nlm_GphPrcsPtr  gphprcsptr = NULL;
128 
129 static Nlm_GphPrcsPtr  repeatProcs;
130 static Nlm_GphPrcsPtr  switchProcs;
131 static Nlm_GphPrcsPtr  iconProcs;
132 
133 extern Nlm_GphPrcsPtr  Nlm_folderTabProcs;
134 Nlm_GphPrcsPtr  Nlm_folderTabProcs = NULL;
135 
136 static Nlm_Boolean     inRepeatButton;
137 
138 static Nlm_Uint1 upFillArrow [] = {
139   0x10, 0x38, 0x38, 0x7C, 0x7C, 0xFE, 0xFE, 0x00
140 };
141 
142 static Nlm_Uint1 downFillArrow [] = {
143   0xFE, 0xFE, 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x00
144 };
145 
146 static Nlm_Uint1 leftFillArrow [] = {
147   0x06, 0x1E, 0x7E, 0xFE, 0x7E, 0x1E, 0x06, 0x00
148 };
149 
150 static Nlm_Uint1 rightFillArrow [] = {
151   0xC0, 0xF0, 0xFC, 0xFE, 0xFC, 0xF0, 0xC0, 0x00
152 };
153 
154 static Nlm_Uint1 upOpenArrow [] = {
155   0x10, 0x28, 0x28, 0x44, 0x44, 0x82, 0xFE, 0x00
156 };
157 
158 static Nlm_Uint1 downOpenArrow [] = {
159   0xFE, 0x82, 0x44, 0x44, 0x28, 0x28, 0x10, 0x00
160 };
161 
162 static Nlm_Uint1 leftOpenArrow [] = {
163   0x06, 0x1A, 0x62, 0x82, 0x62, 0x1A, 0x06, 0x00
164 };
165 
166 static Nlm_Uint1 rightOpenArrow [] = {
167   0xC0, 0xB0, 0x8C, 0x82, 0x8C, 0xB0, 0xC0, 0x00
168 };
169 
170 #ifdef VAR_ARGS
171 extern void CDECL Nlm_AlignObjects (align, va_alist)
172 int align;
173 va_dcl
174 #else
175 extern void CDECL Nlm_AlignObjects (int align, ...)
176 #endif
177 
178 {
179   va_list     args;
180   Nlm_Int2    delta;
181   Nlm_Int2    maxX;
182   Nlm_Int2    maxY;
183   Nlm_Int2    minX;
184   Nlm_Int2    minY;
185   Nlm_Handle  obj;
186   Nlm_RecT    r;
187 
188 #ifdef VAR_ARGS
189   va_start (args);
190 #else
191   va_start (args, align);
192 #endif
193   minX = 0;
194   minY = 0;
195   maxX = 0;
196   maxY = 0;
197   obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
198   while (obj != NULL) {
199     Nlm_GetPosition (obj, &r);
200     minX = MAX (minX, r.left);
201     minY = MAX (minY, r.top);
202     maxX = MAX (maxX, r.right);
203     maxY = MAX (maxY, r.bottom);
204     obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
205   }
206   va_end(args);
207 
208 #ifdef VAR_ARGS
209   va_start (args);
210 #else
211   va_start (args, align);
212 #endif
213   obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
214   while (obj != NULL) {
215     Nlm_GetPosition (obj, &r);
216     switch (align) {
217       case ALIGN_LEFT:
218         if (r.left < minX) {
219           r.left = minX;
220           Nlm_SetPosition (obj, &r);
221           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
222         }
223         break;
224       case ALIGN_RIGHT:
225         if (r.right < maxX) {
226           r.right = maxX;
227           Nlm_SetPosition (obj, &r);
228           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
229         }
230         break;
231       case ALIGN_CENTER:
232         delta = maxX - r.right;
233         if (delta > 0) {
234           Nlm_OffsetRect (&r, (Nlm_Int2)(delta/2), 0);
235           Nlm_SetPosition (obj, &r);
236           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
237         }
238         break;
239       case ALIGN_JUSTIFY:
240         if (r.left < minX || r.right < maxX) {
241           r.left = minX;
242           r.right = maxX;
243           Nlm_SetPosition (obj, &r);
244           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
245         }
246         break;
247       case ALIGN_UPPER:
248         if (r.top < minY) {
249           r.top = minY;
250           Nlm_SetPosition (obj, &r);
251           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
252         }
253         break;
254       case ALIGN_LOWER:
255         if (r.bottom < maxY) {
256           r.bottom = maxY;
257           Nlm_SetPosition (obj, &r);
258           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
259         }
260         break;
261       case ALIGN_MIDDLE:
262         delta = maxY - r.bottom;
263         if (delta > 0) {
264           Nlm_OffsetRect (&r, 0, (Nlm_Int2)(delta/2));
265           Nlm_SetPosition (obj, &r);
266           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
267         }
268         break;
269       case ALIGN_VERTICAL:
270         if (r.top < minY || r.bottom < maxY) {
271           r.top = minY;
272           r.bottom = maxY;
273           Nlm_SetPosition (obj, &r);
274           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
275         }
276         break;
277       default:
278         break;
279     }
280     obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
281   }
282   va_end(args);
283 }
284 
Nlm_DrawSwitchProc(Nlm_PaneL s)285 static void Nlm_DrawSwitchProc (Nlm_PaneL s)
286 
287 {
288   Nlm_RecT        dn;
289   Nlm_SwitchData  extra;
290   Nlm_Int2        mid;
291   Nlm_RecT        r;
292   Nlm_Char        str [32];
293   Nlm_RecT        tx;
294   Nlm_RecT        up;
295 
296   Nlm_GetPanelExtra (s, &extra);
297   Nlm_ObjectRect (s, &r);
298   if (extra.text && extra.max > 0 && extra.val > 0) {
299     sprintf (str, "%d/%d", (int) extra.val, (int) extra.max);
300     Nlm_SelectFont (Nlm_programFont);
301     if (extra.vert) {
302       Nlm_LoadRect (&tx, (Nlm_Int2)(r.left  +  1), (Nlm_Int2)(r.top    + 1),
303                          (Nlm_Int2)(r.right - 11), (Nlm_Int2)(r.bottom - 1));
304     } else {
305       Nlm_LoadRect (&tx, (Nlm_Int2)(r.left  +  1), (Nlm_Int2)(r.top    + 1),
306                          (Nlm_Int2)(r.right - 20), (Nlm_Int2)(r.bottom - 1));
307     }
308     Nlm_DrawString (&tx, str, 'r', FALSE);
309     Nlm_SelectFont (Nlm_systemFont);
310   }
311   Nlm_FrameRect (&r);
312   if (extra.vert) {
313     Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.top + 2),
314                        (Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.top + 9));
315     if (extra.upActv) {
316       Nlm_CopyBits (&up, upFillArrow);
317     } else {
318       Nlm_CopyBits (&up, upOpenArrow);
319     }
320   } else {
321     mid = (r.top + r.bottom) / 2;
322     Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(mid - 3),
323                        (Nlm_Int2)(r.right - 2), (Nlm_Int2)(mid + 4));
324     if (extra.upActv) {
325       Nlm_CopyBits (&up, rightFillArrow);
326     } else {
327       Nlm_CopyBits (&up, rightOpenArrow);
328     }
329   }
330   if (extra.vert) {
331     Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.bottom - 9),
332                        (Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.bottom - 2));
333     if (extra.dnActv) {
334       Nlm_CopyBits (&dn, downFillArrow);
335     } else {
336       Nlm_CopyBits (&dn, downOpenArrow);
337     }
338   } else {
339     mid = (r.top + r.bottom) / 2;
340     Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 18), (Nlm_Int2)(mid - 3),
341                        (Nlm_Int2)(r.right - 11), (Nlm_Int2)(mid + 4));
342     if (extra.dnActv) {
343       Nlm_CopyBits (&dn, leftFillArrow);
344     } else {
345       Nlm_CopyBits (&dn, leftOpenArrow);
346     }
347   }
348 }
349 
Nlm_SwitchClickProc(Nlm_PaneL s,Nlm_PoinT pt)350 static void Nlm_SwitchClickProc (Nlm_PaneL s, Nlm_PoinT pt)
351 
352 {
353   Nlm_RecT        dn;
354   Nlm_SwitchData  extra;
355   Nlm_Int2        mid;
356   Nlm_RecT        r;
357   Nlm_RecT        up;
358 
359   Nlm_GetPanelExtra (s, &extra);
360   Nlm_ObjectRect (s, &r);
361   if (extra.vert) {
362     Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.top + 2),
363                        (Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.top + 9));
364     Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.bottom - 9),
365                        (Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.bottom - 2));
366   } else {
367     mid = (r.top + r.bottom) / 2;
368     Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(mid - 3),
369                        (Nlm_Int2)(r.right - 2), (Nlm_Int2)(mid + 4));
370     Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 18), (Nlm_Int2)(mid - 3),
371                        (Nlm_Int2)(r.right - 11), (Nlm_Int2)(mid + 4));
372   }
373   if (Nlm_PtInRect (pt, &up)) {
374     if (extra.val < extra.max) {
375       Nlm_DoSetValue ((Nlm_GraphiC) s, (Nlm_Int2)(extra.val + 1), FALSE);
376       if (extra.actn != NULL) {
377         extra.actn ((Nlm_SwitcH) s, (Nlm_Int2)(extra.val + 1), extra.val);
378       }
379     }
380   } else if (Nlm_PtInRect (pt, &dn)) {
381     if (extra.val > 1) {
382       Nlm_DoSetValue ((Nlm_GraphiC) s, (Nlm_Int2)(extra.val - 1), FALSE);
383       if (extra.actn != NULL) {
384         extra.actn ((Nlm_SwitcH) s, (Nlm_Int2)(extra.val - 1), extra.val);
385       }
386     }
387   }
388 }
389 
Nlm_CommonSwitch(Nlm_GrouP prnt,Nlm_Boolean text,Nlm_Boolean vert,Nlm_SwtChngProc actn)390 static Nlm_SwitcH Nlm_CommonSwitch (Nlm_GrouP prnt, Nlm_Boolean text,
391                                     Nlm_Boolean vert, Nlm_SwtChngProc actn)
392 
393 {
394   Nlm_SwitchData  extra;
395   Nlm_Int2        height;
396   Nlm_PaneL       s;
397   Nlm_Int2        width;
398 
399   s = NULL;
400   if (prnt != NULL) {
401     Nlm_SelectFont (Nlm_programFont);
402     if (vert) {
403       height = 20;
404       width = 11;
405     } else {
406       height = 11;
407       width = 20;
408     }
409     if (text) {
410       width += Nlm_StringWidth ("99/99") + 4;
411       height = MAX (height, Nlm_LineHeight () + 2);
412     }
413     Nlm_SelectFont (Nlm_systemFont);
414     s = Nlm_AutonomousPanel (prnt, width, height, Nlm_DrawSwitchProc, NULL,
415                              NULL, sizeof (Nlm_SwitchData), NULL, switchProcs);
416     if (s != NULL) {
417       Nlm_SetPanelClick (s, Nlm_SwitchClickProc, NULL, NULL, NULL);
418       Nlm_MemSet ((Nlm_VoidPtr) (&extra), 0, sizeof (Nlm_SwitchData));
419       extra.max = 0;
420       extra.val = 0;
421       extra.text = text;
422       extra.vert = vert;
423       extra.upActv = FALSE;
424       extra.dnActv = FALSE;
425       extra.actn = actn;
426       Nlm_SetPanelExtra (s, &extra);
427     }
428   }
429   return (Nlm_SwitcH) s;
430 }
431 
Nlm_UpDownSwitch(Nlm_GrouP prnt,Nlm_Boolean text,Nlm_SwtChngProc actn)432 extern Nlm_SwitcH Nlm_UpDownSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
433 
434 {
435   return Nlm_CommonSwitch (prnt, text, TRUE, actn);
436 }
437 
Nlm_LeftRightSwitch(Nlm_GrouP prnt,Nlm_Boolean text,Nlm_SwtChngProc actn)438 extern Nlm_SwitcH Nlm_LeftRightSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
439 
440 {
441   return Nlm_CommonSwitch (prnt, text, FALSE, actn);
442 }
443 
Nlm_UpdateSwitch(Nlm_SwitcH s)444 static void Nlm_UpdateSwitch (Nlm_SwitcH s)
445 
446 {
447   Nlm_RecT        dn;
448   Nlm_SwitchData  extra;
449   Nlm_Int2        mid;
450   Nlm_RecT        r;
451   Nlm_RecT        tx;
452   Nlm_RecT        up;
453 
454   Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
455   if (Nlm_Visible (s) && Nlm_AllParentsVisible (s)) {
456     Nlm_ObjectRect (s, &r);
457     if (extra.vert) {
458       Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.top + 2),
459                          (Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.top + 9));
460       Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.bottom - 9),
461                          (Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.bottom - 2));
462     } else {
463       mid = (r.top + r.bottom) / 2;
464       Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(mid - 3),
465                          (Nlm_Int2)(r.right - 2), (Nlm_Int2)(mid + 4));
466       Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 18), (Nlm_Int2)(mid - 3),
467                          (Nlm_Int2)(r.right - 11), (Nlm_Int2)(mid + 4));
468     }
469     Nlm_Select (s);
470     if (extra.upActv != (Nlm_Boolean) (extra.val < extra.max)) {
471       Nlm_InsetRect (&up, -1, -1);
472       Nlm_InvalRect (&up);
473     }
474     if (extra.dnActv != (Nlm_Boolean) (extra.val > 1)) {
475       Nlm_InsetRect (&dn, -1, -1);
476       Nlm_InvalRect (&dn);
477     }
478     if (extra.text) {
479       if (extra.vert) {
480         Nlm_LoadRect (&tx, (Nlm_Int2)(r.left  +  1), (Nlm_Int2)(r.top    + 1),
481                            (Nlm_Int2)(r.right - 10), (Nlm_Int2)(r.bottom - 1));
482       } else {
483         Nlm_LoadRect (&tx, (Nlm_Int2)(r.left  +  1), (Nlm_Int2)(r.top + 1),
484                            (Nlm_Int2)(r.right - 19), (Nlm_Int2)(r.bottom - 1));
485       }
486       Nlm_InvalRect (&tx);
487     }
488   }
489   extra.upActv = (Nlm_Boolean) (extra.val < extra.max);
490   extra.dnActv = (Nlm_Boolean) (extra.val > 1);
491   Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
492 }
493 
Nlm_SetSwitchValue(Nlm_GraphiC s,Nlm_Int2 value,Nlm_Boolean savePort)494 static void Nlm_SetSwitchValue (Nlm_GraphiC s, Nlm_Int2 value, Nlm_Boolean savePort)
495 
496 {
497   Nlm_SwitchData  extra;
498   Nlm_Int2        oldval;
499   Nlm_WindoW      tempPort;
500 
501   tempPort = Nlm_SavePortIfNeeded (s, savePort);
502   if (s != NULL) {
503     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
504     oldval = extra.val;
505     extra.val = value;
506     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
507     if (oldval != value) {
508       Nlm_UpdateSwitch ((Nlm_SwitcH) s);
509     }
510   }
511   Nlm_RestorePort (tempPort);
512 }
513 
Nlm_GetSwitchValue(Nlm_GraphiC s)514 static Nlm_Int2 Nlm_GetSwitchValue (Nlm_GraphiC s)
515 
516 {
517   Nlm_SwitchData  extra;
518   Nlm_Int2        value;
519 
520   value = 0;
521   if (s != NULL) {
522     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
523     value = extra.val;
524   }
525   return value;
526 }
527 
Nlm_SetSwitchMax(Nlm_SwitcH s,Nlm_Int2 max)528 extern void Nlm_SetSwitchMax (Nlm_SwitcH s, Nlm_Int2 max)
529 
530 {
531   Nlm_SwitchData  extra;
532   Nlm_Int2        oldmax;
533   Nlm_WindoW      tempPort;
534 
535   tempPort = Nlm_SavePort (s);
536   if (s != NULL) {
537     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
538     oldmax = extra.max;
539     extra.max = max;
540     if (max == 0) {
541       extra.val = 0;
542     }
543     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
544     if (oldmax != max) {
545       Nlm_UpdateSwitch (s);
546     }
547   }
548   Nlm_RestorePort (tempPort);
549 }
550 
Nlm_GetSwitchMax(Nlm_SwitcH s)551 extern Nlm_Int2 Nlm_GetSwitchMax (Nlm_SwitcH s)
552 
553 {
554   Nlm_SwitchData  extra;
555   Nlm_Int2        max;
556 
557   max = 0;
558   if (s != NULL) {
559     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
560     max = extra.max;
561   }
562   return max;
563 }
564 
Nlm_SetSwitchParams(Nlm_SwitcH s,Nlm_Int2 value,Nlm_Int2 max)565 extern void Nlm_SetSwitchParams (Nlm_SwitcH s, Nlm_Int2 value, Nlm_Int2 max)
566 
567 {
568   Nlm_SwitchData  extra;
569   Nlm_Int2        oldmax;
570   Nlm_Int2        oldval;
571   Nlm_WindoW      tempPort;
572 
573   tempPort = Nlm_SavePort (s);
574   if (s != NULL) {
575     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
576     oldmax = extra.max;
577     extra.max = max;
578     if (value > max) {
579       value = max;
580     }
581     oldval = extra.val;
582     extra.val = value;
583     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
584     if (oldval != value || oldmax != max) {
585       Nlm_UpdateSwitch (s);
586     }
587   }
588   Nlm_RestorePort (tempPort);
589 }
590 
Nlm_DoRepeatAction(Nlm_RepeaT rb,Nlm_PoinT pt)591 static void Nlm_DoRepeatAction (Nlm_RepeaT rb, Nlm_PoinT pt)
592 
593 {
594   Nlm_RptClckProc  actn;
595   Nlm_RepeatData   rdata;
596 
597   Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
598   actn = rdata.action;
599   if (actn != NULL) {
600     actn (rb, pt);
601   }
602 }
603 
Nlm_RepeatClick(Nlm_PaneL rb,Nlm_PoinT pt)604 static void Nlm_RepeatClick (Nlm_PaneL rb, Nlm_PoinT pt)
605 
606 {
607   Nlm_RecT  r;
608 
609   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
610   if (Nlm_PtInRect (pt, &r)) {
611     inRepeatButton = TRUE;
612     Nlm_InsetRect (&r, 2, 2);
613     Nlm_InvertRect (&r);
614     Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
615   }
616 }
617 
Nlm_RepeatPress(Nlm_PaneL rb,Nlm_PoinT pt)618 static void Nlm_RepeatPress (Nlm_PaneL rb, Nlm_PoinT pt)
619 
620 {
621   Nlm_RecT  r;
622 
623   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
624   if (Nlm_PtInRect (pt, &r)) {
625     if (! inRepeatButton) {
626       inRepeatButton = TRUE;
627       Nlm_InsetRect (&r, 2, 2);
628       Nlm_InvertRect (&r);
629     }
630     Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
631   } else if (inRepeatButton) {
632     inRepeatButton = FALSE;
633     Nlm_InsetRect (&r, 2, 2);
634     Nlm_InvertRect (&r);
635   }
636 }
637 
Nlm_RepeatRelease(Nlm_PaneL rb,Nlm_PoinT pt)638 static void Nlm_RepeatRelease (Nlm_PaneL rb, Nlm_PoinT pt)
639 
640 {
641   Nlm_RecT  r;
642 
643   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
644   if (inRepeatButton) {
645     inRepeatButton = FALSE;
646     Nlm_InsetRect (&r, 2, 2);
647     Nlm_InvertRect (&r);
648   }
649 }
650 
Nlm_DrawRepeat(Nlm_PaneL rb)651 static void Nlm_DrawRepeat (Nlm_PaneL rb)
652 
653 {
654   Nlm_Handle      h;
655   Nlm_RecT        r;
656   Nlm_RepeatData  rdata;
657   Nlm_Char        str [64];
658 
659   if (Nlm_GetVisible ((Nlm_GraphiC) rb) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) rb)) {
660     Nlm_GetRect ((Nlm_GraphiC) rb, &r);
661     Nlm_FrameRect (&r);
662     Nlm_InsetRect (&r, 1, 1);
663     Nlm_FrameRect (&r);
664     Nlm_InsetRect (&r, 1, 1);
665     Nlm_GetPanelExtra (rb, &rdata);
666     h = rdata.title;
667     if (h != NULL) {
668       Nlm_SelectFont (Nlm_systemFont);
669       Nlm_GetString (h, str, sizeof (str));
670       if (Nlm_StringLen (str) > 0) {
671         Nlm_DrawString (&r, str, 'c', FALSE);
672       }
673     }
674   }
675 }
676 
Nlm_SetRepeatTitle(Nlm_GraphiC rb,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)677 static void Nlm_SetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
678                                 Nlm_CharPtr title, Nlm_Boolean savePort)
679 
680 {
681   Nlm_Handle      h;
682   Nlm_RecT        r;
683   Nlm_RepeatData  rdata;
684   Nlm_WindoW      tempPort;
685 
686   tempPort = Nlm_SavePortIfNeeded (rb, savePort);
687   Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
688   h = rdata.title;
689   h = Nlm_SetString (h, title);
690   rdata.title = h;
691   Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
692   if (Nlm_GetVisible (rb) && Nlm_GetAllParentsVisible (rb)) {
693     Nlm_GetRect (rb, &r);
694     Nlm_InvalRect (&r);
695   }
696   Nlm_RestorePort (tempPort);
697 }
698 
Nlm_GetRepeatTitle(Nlm_GraphiC rb,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)699 static void Nlm_GetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
700                                 Nlm_CharPtr title, size_t maxsize)
701 
702 {
703   Nlm_Handle      h;
704   Nlm_RepeatData  rdata;
705 
706   if (title != NULL) {
707     Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
708     h = rdata.title;
709     Nlm_GetString (h, title, maxsize);
710   }
711 }
712 
Nlm_ResetRepeat(Nlm_PaneL rb)713 static void Nlm_ResetRepeat (Nlm_PaneL rb)
714 
715 {
716   Nlm_RepeatData  rdata;
717 
718   Nlm_GetPanelExtra (rb, &rdata);
719   if (rdata.title != NULL) {
720     rdata.title = Nlm_HandFree (rdata.title);
721   }
722   Nlm_SetPanelExtra (rb, &rdata);
723 }
724 
Nlm_RepeatButton(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_RptClckProc actn)725 extern Nlm_RepeaT Nlm_RepeatButton (Nlm_GrouP prnt, Nlm_CharPtr title,
726                                     Nlm_RptClckProc actn)
727 
728 {
729   Nlm_RepeaT      rb;
730   Nlm_RepeatData  rdata;
731   Nlm_Int2        vbounds;
732   Nlm_Int2        width;
733 
734   rb = NULL;
735   if (prnt != NULL) {
736     Nlm_SelectFont (Nlm_systemFont);
737     width = Nlm_StringWidth (title);
738 #ifdef WIN_MAC
739     vbounds = 2;
740 #endif
741 #ifdef WIN_MSWIN
742     vbounds = 4;
743 #endif
744 #ifdef WIN_MOTIF
745     vbounds = 2;
746 #endif
747     rb = (Nlm_RepeaT) Nlm_AutonomousPanel (prnt,
748       (Nlm_Int2)(width + 8), (Nlm_Int2)(Nlm_stdLineHeight + vbounds*2),
749       Nlm_DrawRepeat, NULL, NULL,
750       sizeof (Nlm_RepeatData), Nlm_ResetRepeat, repeatProcs);
751     if (rb != NULL) {
752       Nlm_SetPanelClick ((Nlm_PaneL) rb, Nlm_RepeatClick, NULL,
753                          Nlm_RepeatPress, Nlm_RepeatRelease);
754       rdata.title = NULL;
755       rdata.action = actn;
756       Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
757       Nlm_SetRepeatTitle ((Nlm_GraphiC) rb, 0, title, FALSE);
758     }
759   }
760   return rb;
761 }
762 
Nlm_SetIconValue(Nlm_GraphiC i,Nlm_Int2 value,Nlm_Boolean savePort)763 static void Nlm_SetIconValue (Nlm_GraphiC i, Nlm_Int2 value, Nlm_Boolean savePort)
764 
765 {
766   Nlm_IconData  extra;
767   Nlm_Int2      oldval;
768   Nlm_RecT      r;
769   Nlm_WindoW    tempPort;
770 
771   tempPort = Nlm_SavePortIfNeeded (i, savePort);
772   if (i != NULL) {
773     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
774     oldval = extra.value;
775     extra.value = value;
776     Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
777     if (oldval != value) {
778       if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
779         Nlm_Select (i);
780         if (extra.inval != NULL) {
781           extra.inval ((Nlm_IcoN) i, value, oldval);
782         } else {
783           Nlm_ObjectRect (i, &r);
784           Nlm_InsetRect (&r, -1, -1);
785           Nlm_InvalRect (&r);
786         }
787       }
788     }
789   }
790   Nlm_RestorePort (tempPort);
791 }
792 
Nlm_GetIconValue(Nlm_GraphiC i)793 static Nlm_Int2 Nlm_GetIconValue (Nlm_GraphiC i)
794 
795 {
796   Nlm_IconData  extra;
797   Nlm_Int2      value;
798 
799   value = 0;
800   if (i != NULL) {
801     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
802     value = extra.value;
803   }
804   return value;
805 }
806 
Nlm_SetIconStatus(Nlm_GraphiC i,Nlm_Int2 item,Nlm_Boolean set,Nlm_Boolean savePort)807 static void Nlm_SetIconStatus (Nlm_GraphiC i, Nlm_Int2 item,
808                                Nlm_Boolean set, Nlm_Boolean savePort)
809 
810 {
811   Nlm_IconData  extra;
812   Nlm_Boolean   oldstat;
813   Nlm_RecT      r;
814   Nlm_WindoW    tempPort;
815 
816   tempPort = Nlm_SavePortIfNeeded (i, savePort);
817   if (i != NULL) {
818     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
819     oldstat = extra.status;
820     extra.status = set;
821     Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
822     if (oldstat != set) {
823       if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
824         Nlm_Select (i);
825         if (extra.inval != NULL) {
826           extra.inval ((Nlm_IcoN) i, extra.value, extra.value);
827         } else {
828           Nlm_ObjectRect (i, &r);
829           Nlm_InsetRect (&r, -1, -1);
830           Nlm_InvalRect (&r);
831         }
832       }
833     }
834   }
835   Nlm_RestorePort (tempPort);
836 }
837 
Nlm_GetIconStatus(Nlm_GraphiC i,Nlm_Int2 item)838 static Nlm_Boolean Nlm_GetIconStatus (Nlm_GraphiC i, Nlm_Int2 item)
839 
840 {
841   Nlm_IconData  extra;
842   Nlm_Boolean   status;
843 
844   status = 0;
845   if (i != NULL) {
846     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
847     status = extra.status;
848   }
849   return status;
850 }
851 
Nlm_SetIconTitle(Nlm_GraphiC i,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)852 static void Nlm_SetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
853                               Nlm_CharPtr title, Nlm_Boolean savePort)
854 
855 {
856   Nlm_IconData  extra;
857   Nlm_Handle    h;
858   Nlm_RecT      r;
859   Nlm_WindoW    tempPort;
860 
861   tempPort = Nlm_SavePortIfNeeded (i, savePort);
862   Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
863   h = extra.title;
864   h = Nlm_SetString (h, title);
865   extra.title = h;
866   Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
867   if (Nlm_GetVisible (i) && Nlm_GetAllParentsVisible (i)) {
868     Nlm_GetRect (i, &r);
869     Nlm_InvalRect (&r);
870   }
871   Nlm_RestorePort (tempPort);
872 }
873 
Nlm_GetIconTitle(Nlm_GraphiC i,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)874 static void Nlm_GetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
875                               Nlm_CharPtr title, size_t maxsize)
876 
877 {
878   Nlm_IconData  extra;
879   Nlm_Handle    h;
880 
881   if (title != NULL) {
882     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
883     h = extra.title;
884     Nlm_GetString (h, title, maxsize);
885   }
886 }
887 
Nlm_ResetIcon(Nlm_PaneL i)888 static void Nlm_ResetIcon (Nlm_PaneL i)
889 
890 {
891   Nlm_IconData  extra;
892 
893   Nlm_GetPanelExtra (i, &extra);
894   if (extra.title != NULL) {
895     extra.title = Nlm_HandFree (extra.title);
896   }
897   Nlm_SetPanelExtra (i, &extra);
898 }
899 
Nlm_IconButton(Nlm_GrouP prnt,Nlm_Int2 pixwidth,Nlm_Int2 pixheight,Nlm_IcnActnProc draw,Nlm_IcnChngProc inval,Nlm_IcnClckProc click,Nlm_IcnClckProc drag,Nlm_IcnClckProc hold,Nlm_IcnClckProc release)900 extern Nlm_IcoN Nlm_IconButton (Nlm_GrouP prnt, Nlm_Int2 pixwidth, Nlm_Int2 pixheight,
901                                 Nlm_IcnActnProc draw, Nlm_IcnChngProc inval,
902                                 Nlm_IcnClckProc click, Nlm_IcnClckProc drag,
903                                 Nlm_IcnClckProc hold, Nlm_IcnClckProc release)
904 
905 {
906   Nlm_IcoN      ic;
907   Nlm_IconData  idata;
908 
909   ic = NULL;
910   if (prnt != NULL) {
911     Nlm_SelectFont (Nlm_systemFont);
912     ic = (Nlm_IcoN) Nlm_AutonomousPanel (prnt, pixwidth, pixheight,
913                                          (Nlm_PnlActnProc) draw, NULL, NULL,
914                                          sizeof (Nlm_IconData), Nlm_ResetIcon,
915                                          iconProcs);
916     if (ic != NULL) {
917       Nlm_SetPanelClick ((Nlm_PaneL) ic, (Nlm_PnlClckProc) click, (Nlm_PnlClckProc) drag,
918                          (Nlm_PnlClckProc) hold, (Nlm_PnlClckProc) release);
919       idata.inval = inval;
920       idata.value = 0;
921       idata.status = FALSE;
922       idata.title = NULL;
923       Nlm_SetPanelExtra ((Nlm_PaneL) ic, &idata);
924     }
925   }
926   return ic;
927 }
928 
929 extern void Nlm_SetFolderTabValue (Nlm_GraphiC a, Nlm_Int2 value, Nlm_Boolean savePort);
930 extern void Nlm_SetFolderTabSubclass (Nlm_GrouP g);
Nlm_SetFolderTabSubclass(Nlm_GrouP g)931 extern void Nlm_SetFolderTabSubclass (Nlm_GrouP g)
932 
933 {
934   Nlm_GraphicData  gdata;
935 
936   if (Nlm_folderTabProcs != NULL) {
937     Nlm_folderTabProcs->setValue = Nlm_SetFolderTabValue;
938     Nlm_GetGraphicData ((Nlm_GraphiC) g, &gdata);
939     Nlm_folderTabProcs->ancestor = gdata.classptr;
940     gdata.classptr = Nlm_folderTabProcs;
941     Nlm_SetGraphicData ((Nlm_GraphiC) g, &gdata);
942   }
943 }
944 
Nlm_FreeExtras(void)945 extern void Nlm_FreeExtras (void)
946 
947 {
948   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
949 }
950 
Nlm_InitExtras(void)951 extern void Nlm_InitExtras (void)
952 
953 {
954   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 4);
955 
956   repeatProcs = &(gphprcsptr [0]);
957   repeatProcs->setTitle = Nlm_SetRepeatTitle;
958   repeatProcs->getTitle = Nlm_GetRepeatTitle;
959 
960   switchProcs = &(gphprcsptr [1]);
961   switchProcs->setValue = Nlm_SetSwitchValue;
962   switchProcs->getValue = Nlm_GetSwitchValue;
963 
964   iconProcs = &(gphprcsptr [2]);
965   iconProcs->setValue = Nlm_SetIconValue;
966   iconProcs->getValue = Nlm_GetIconValue;
967   iconProcs->setStatus = Nlm_SetIconStatus;
968   iconProcs->getStatus = Nlm_GetIconStatus;
969   iconProcs->setTitle = Nlm_SetIconTitle;
970   iconProcs->getTitle = Nlm_GetIconTitle;
971 
972   Nlm_folderTabProcs = &(gphprcsptr [3]);
973 }
974 
975 /* ---------------------- Start ------------------------- */
976 /* --------------------MS-Windows------------------------ */
977 #ifdef WIN_MSWIN
978 
979 extern HWND Nlm_currentHWnd;
980 
981 static DWORD win_CustomColors[16];
982 
Nlm_ChooseColorDialog(Nlm_Uint1 PNTR redptr,Nlm_Uint1 PNTR greenptr,Nlm_Uint1 PNTR blueptr,Nlm_Boolean Initial)983 extern Nlm_Boolean Nlm_ChooseColorDialog (
984        Nlm_Uint1 PNTR redptr,
985        Nlm_Uint1 PNTR greenptr,
986        Nlm_Uint1 PNTR blueptr,
987        Nlm_Boolean Initial ){
988   CHOOSECOLOR chc;
989   Nlm_Boolean res;
990 
991   chc.lStructSize = sizeof (CHOOSECOLOR);
992   chc.hwndOwner = Nlm_currentHWnd;
993   chc.lpCustColors = win_CustomColors;
994   chc.Flags = CC_FULLOPEN;
995   if ( Initial ) {
996     chc.Flags |= CC_RGBINIT;
997     chc.rgbResult = RGB ( *redptr, *greenptr, *blueptr );
998   }
999   res = (Nlm_Boolean)ChooseColor ( &chc );
1000   if ( res ){
1001     if ( redptr != NULL ) *redptr = GetRValue (chc.rgbResult);
1002     if ( greenptr != NULL ) *greenptr = GetGValue (chc.rgbResult);
1003     if ( blueptr != NULL ) *blueptr = GetBValue (chc.rgbResult);
1004   }
1005   return res;
1006 }
1007 /* ---------------------End MS-Windows--------------------- */
1008 #else
1009 /* --------------------- Non MS-Window -------------------- */
1010 /* --------------------- Defines -------------------------- */
1011 /* Sizes */
1012 #define NLM_CHCOLOR_BOXW   26
1013 #define NLM_CHCOLOR_BOXH   20
1014 #define NLM_CHCOLOR_SHLW   180
1015 #define NLM_CHCOLOR_SHLH   20
1016 #define NLM_CHCOLOR_PTRH   10
1017 #define NLM_CHCOLOR_PTRW   16
1018 #define NLM_CHCOLOR_PTRW2  8
1019 #define NLM_CHCOLOR_EXW    160
1020 #define NLM_CHCOLOR_EXH    40
1021 /* Owners */
1022 #define NLM_CHCOLOR_OBC    0
1023 #define NLM_CHCOLOR_OCC    1
1024 #define NLM_CHCOLOR_OSP    2
1025 #define NLM_CHCOLOR_OST    3
1026 #define NLM_CHCOLOR_OHP    4
1027 #define NLM_CHCOLOR_OHT    5
1028 #define NLM_CHCOLOR_OLP    6
1029 #define NLM_CHCOLOR_OLT    7
1030 #define NLM_CHCOLOR_ORT    8
1031 #define NLM_CHCOLOR_OGT    9
1032 #define NLM_CHCOLOR_OBT    10
1033 
1034 /* --------------------- Typedefs ------------------------- */
1035 
1036 typedef struct {
1037   Nlm_Uint1  red;
1038   Nlm_Uint1  green;
1039   Nlm_Uint1  blue;
1040 } NLMINTERNALCOLOR;
1041 
1042 /* -------------------Global variable---------------------- */
1043 
1044 #ifdef WIN_X
1045 extern Display      *Nlm_currentXDisplay;
1046 extern int          Nlm_currentXScreen;
1047 extern Window       Nlm_currentXWindow;
1048 extern GC           Nlm_currentXGC;
1049 extern Nlm_Uint4    Nlm_XbackColor;
1050 extern Nlm_Uint4    Nlm_XforeColor;
1051 extern Nlm_Int2     Nlm_XOffset;
1052 extern Nlm_Int2     Nlm_YOffset;
1053 extern Nlm_RegioN   Nlm_clpRgn;
1054 extern Nlm_Boolean  Nlm_hasColor;
1055 #endif
1056 
1057 /* -------------------Static variable---------------------- */
1058 
1059 static Nlm_Boolean  colorDlgUp;
1060 static Nlm_Boolean  colorDlgOK;
1061 static Nlm_PaneL    pBasicColor;
1062 static Nlm_PaneL    pCustomColor;
1063 static Nlm_PaneL    pSColor;
1064 static Nlm_PaneL    pSPtrColor;
1065 static Nlm_PaneL    pHColor;
1066 static Nlm_PaneL    pHPtrColor;
1067 static Nlm_PaneL    pLColor;
1068 static Nlm_PaneL    pLPtrColor;
1069 static Nlm_PaneL    pRetColor;
1070 static Nlm_TexT     tColorRed;
1071 static Nlm_TexT     tColorGreen;
1072 static Nlm_TexT     tColorBlue;
1073 static Nlm_TexT     tColorHue;
1074 static Nlm_TexT     tColorSat;
1075 static Nlm_TexT     tColorLum;
1076 static Nlm_Int2     stColorRGB[3];
1077 static Nlm_Int2     stColorHSL[3];
1078 static Nlm_Int2     stColorCurCustom;
1079 static Nlm_Int2     stColorModel;
1080 #ifdef WIN_X
1081 #define VOID_PIXEL ((unsigned long)(-1))
1082 static unsigned long tmpColorPixel = VOID_PIXEL;
1083 #endif
1084 
1085 static NLMINTERNALCOLOR theCustomColors[16];
1086 
1087 static NLMINTERNALCOLOR theBasicColors[48] = {
1088 {255,128,128},{255,255,232},{128,255,128},{0,255,128},
1089 {128,255,255},{0,128,255},  {255,128,192},{255,128,255},
1090 {255,0,0},    {255,255,128},{128,255,0},  {0,255,64},
1091 {0,255,255},  {0,128,192},  {128,128,192},{255,0,255},
1092 {128,64,64},  {255,255,0},  {0,255,0},    {0,128,128},
1093 {0,64,128},   {128,128,255},{128,0,64},   {255,0,128},
1094 {128,0,0},    {255,128,0},  {0,128,0},    {0,128,64},
1095 {0,0,255},    {0,0,160},    {128,0,128},  {128,0,255},
1096 {64,0,0},     {128,64,0},   {0,64,0},     {0,64,64,},
1097 {0,0,128},    {0,0,64},     {64,0,64},    {64,0,128},
1098 {0,0,0},      {128,128,0},  {128,128,64}, {128,128,128},
1099 {64,128,128}, {192,192,192},{130,130,130},{255,255,255} };
1100 
1101 static Nlm_Uint1 thePointer[] = {   /*16 X 10*/
1102 0x01, 0x80, 0x03, 0xC0, 0x07, 0xE0,
1103 0x0F, 0xF0, 0x1F, 0xF8, 0x3F, 0xFC,
1104 0x7F, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
1105 0xFF, 0xFF };
1106 
1107 
1108 /* ----------------Utility functions ---------------------- */
Nlm_SafeSetTitleExtra(Nlm_Handle a,Nlm_CharPtr title)1109 static void Nlm_SafeSetTitleExtra (Nlm_Handle a, Nlm_CharPtr title)
1110 
1111 {
1112   Nlm_Char  str [256];
1113 
1114   Nlm_GetTitle (a, str, sizeof (str));
1115   if (Nlm_StringCmp (title, str) != 0) {
1116     Nlm_SetTitle (a, title);
1117   }
1118 }
1119 
Nlm_GetColorVal(Nlm_TexT t)1120 static int Nlm_GetColorVal ( Nlm_TexT t ) {
1121   Nlm_Char cValue[64];
1122   Nlm_Char PNTR cValuePtr;
1123   int      iValue = -1;
1124   int      update = 0;
1125 
1126   Nlm_GetTitle( t, cValue, 64 );
1127   cValue[63] = 0;
1128   for ( cValuePtr = cValue; IS_DIGIT(*cValuePtr); cValuePtr++ ) ;
1129   if ( *cValuePtr != '\0' ) {
1130     *cValuePtr = 0;
1131     update = 1;
1132   }
1133   sscanf ( cValue, "%d", &iValue );
1134   if ( iValue <= 0 ) {
1135     iValue = 0;
1136     update = 2;
1137   }
1138   if ( iValue > 255 ) {
1139     iValue = 255 ;
1140     update = 1;
1141   }
1142   if ( update ==2 ){
1143     Nlm_SetTitle ( t, "" );
1144   } else if ( update ) {
1145     sprintf ( cValue, "%d", iValue );
1146     Nlm_SafeSetTitleExtra ( t, cValue );
1147   }
1148   return iValue;
1149 }
1150 
Nlm_HSL2RGB(Nlm_Int2 PNTR rgb,Nlm_Int2 PNTR hsl)1151 static void Nlm_HSL2RGB ( Nlm_Int2 PNTR rgb, Nlm_Int2 PNTR hsl ){
1152   int      i, min;
1153   double   maxVal, minVal;
1154   double   sumDoub, difDoub;
1155 
1156   /* S = (maxRGB-minRGB)/(maxRGB+minRGB)*256 */
1157   /* L = (maxRGB+minRGB)/2 */
1158   /* H = (maxRGB-minRGB)/(maxRGB+midRGB-2*minRGB)*(256/3) + C */
1159   sumDoub = (double)hsl[2] * 2;
1160   difDoub = (double)hsl[1] * sumDoub / 256.0;
1161   maxVal = (sumDoub + difDoub) / 2.0;
1162   if ( maxVal > 255 ) maxVal = 255;
1163   minVal = sumDoub - maxVal;
1164   if ( (double)hsl[0] > (256.0*2.0/3.0) ) {
1165     min = 1; difDoub = (double)hsl[0] - (256.0*2.0/3.0);
1166   } else if ( (double)hsl[0] > (256.0*1.0/3.0) ){
1167     min = 0; difDoub = (double)hsl[0] - (256.0*1.0/3.0);
1168   } else {
1169     min = 2; difDoub = (double)hsl[0];
1170   }
1171   rgb[min] = (Nlm_Int2)minVal;
1172   difDoub *= 3.0/256.0;
1173   if ( difDoub < 0.5 ){
1174     i = min + 1; if ( i > 2 ) i=0;
1175     rgb[i] = (Nlm_Int2)maxVal;
1176     i++; if ( i > 2 ) i=0;
1177     difDoub = 1.0 - difDoub;
1178   }else{
1179     i = min - 1; if ( i < 0 ) i=2;
1180     rgb[i] = (Nlm_Int2)maxVal;
1181     i --; if ( i < 0 ) i=2;
1182   }
1183   if ( (maxVal-minVal) < 1.0E-12 ) {
1184     rgb[i] = (Nlm_Int2)minVal;
1185   } else {
1186     rgb[i] = (Nlm_Int2)((maxVal-minVal)/difDoub - maxVal + 2*minVal);
1187   }
1188 }
1189 
Nlm_RGB2HSL(Nlm_Int2 PNTR hsl,Nlm_Int2 PNTR rgb)1190 static void Nlm_RGB2HSL ( Nlm_Int2 PNTR hsl, Nlm_Int2 PNTR rgb ){
1191   int      i, min;
1192   double   maxVal, minVal;
1193   double   sumDoub, difDoub;
1194 
1195   /* S = (maxRGB-minRGB)/(maxRGB+minRGB)*256 */
1196   /* L = (maxRGB+minRGB)/2 */
1197   /* H = (maxRGB-minRGB)/(maxRGB+midRGB-2*minRGB)*(256/3) + C */
1198   maxVal = -1;
1199   minVal = 256;
1200   for ( i=0; i<3; i++ ){
1201     if ( rgb[i] < minVal ) {
1202       minVal = (double)rgb[i];
1203       min = i;
1204     }
1205     if ( rgb[i] > maxVal ) maxVal = (double)rgb[i];
1206   }
1207   sumDoub = minVal + maxVal;
1208   difDoub = maxVal - minVal;
1209   if ( sumDoub < 1.0E-10 ) hsl[1] = 255;
1210   else hsl[1] = (Nlm_Int2)( difDoub * 256.0/sumDoub );
1211   if ( hsl[1] > 255 ) hsl[1] = 255;
1212   hsl[2] = (Nlm_Int2)(sumDoub/ 2.0);
1213   if ( hsl[2] > 255 ) hsl[2] = 255;
1214   if ( (rgb[0] == rgb[1]) && (rgb[0] == rgb[2]) ) hsl[0] = 0;
1215   else {
1216     i = (min + 1); if ( i > 2 ) i=0;
1217     difDoub = (double)rgb[i] - minVal;
1218     sumDoub = (double)rgb[i];
1219     i++; if ( i > 2 ) i=0;
1220     sumDoub += (double)rgb[i] - 2*minVal;
1221     i = min + 1; if ( i > 2 ) i=0;
1222     hsl[0] = (Nlm_Int2)( 256.0/3.0 *((double)i + (1.0-difDoub/sumDoub)) );
1223     hsl[0] += 1;
1224     if ( hsl[0] > 255 ) hsl[0] = 0;
1225   }
1226 }
1227 
Nlm_UpdColorPanel(Nlm_PaneL p)1228 static void Nlm_UpdColorPanel ( Nlm_PaneL p ){
1229   Nlm_RecT   rp;
1230   Nlm_WindoW tmpPort;
1231 
1232   tmpPort = Nlm_SavePort (p);
1233   Nlm_ObjectRect (p, &rp);
1234   Nlm_Select (p);
1235   Nlm_InvalRect ( &rp );
1236   Nlm_RestorePort (tmpPort);
1237 }
1238 
Nlm_UpdColorText(Nlm_TexT t,Nlm_Int2 iVal)1239 static void Nlm_UpdColorText ( Nlm_TexT t, Nlm_Int2 iVal ){
1240   Nlm_Char cValue[64];
1241 
1242   sprintf ( cValue, "%d", iVal );
1243   Nlm_SafeSetTitleExtra ( t, cValue );
1244 }
1245 
Nlm_DrawColorPtr(Nlm_Int2 x,Nlm_Int2 y)1246 static void Nlm_DrawColorPtr ( Nlm_Int2 x, Nlm_Int2 y ){
1247   Nlm_RecT r;
1248 
1249   Nlm_LoadRect ( &r, x-NLM_CHCOLOR_PTRW2, y,
1250                      x+NLM_CHCOLOR_PTRW2, y+NLM_CHCOLOR_PTRH );
1251   Nlm_CopyBits ( &r, (Nlm_VoidPtr)thePointer );
1252 }
1253 
1254 /* -------------------Draw functions ---------------------- */
1255 
Nlm_BasicColorDraw(Nlm_PaneL p)1256 static void Nlm_BasicColorDraw ( Nlm_PaneL p ){
1257   int        x, y, xx, yy;
1258   Nlm_RecT   rp;
1259   Nlm_RecT   rdraw;
1260 
1261   Nlm_ObjectRect (pBasicColor, &rp);
1262   for ( y=0; y<6; y++ ){
1263     for ( x=0; x<8; x++ ){
1264       xx = rp.left + x*NLM_CHCOLOR_BOXW;
1265       yy = rp.top + y*NLM_CHCOLOR_BOXH;
1266       Nlm_LoadRect ( &rdraw, xx + 2, yy + 2,
1267                      xx + NLM_CHCOLOR_BOXW - 2, yy + NLM_CHCOLOR_BOXH - 2 );
1268       Nlm_FrameRect ( &rdraw );
1269     }
1270   }
1271   for ( y=0; y<6; y++ ){
1272     for ( x=0; x<8; x++ ){
1273       xx = rp.left + x*NLM_CHCOLOR_BOXW;
1274       yy = rp.top + y*NLM_CHCOLOR_BOXH;
1275       Nlm_LoadRect ( &rdraw, xx + 3, yy + 3,
1276                      xx + NLM_CHCOLOR_BOXW - 3, yy + NLM_CHCOLOR_BOXH - 3 );
1277       Nlm_SelectColor ( theBasicColors[y*8+x].red,
1278                         theBasicColors[y*8+x].green,
1279                         theBasicColors[y*8+x].blue );
1280       Nlm_PaintRect ( &rdraw );
1281     }
1282   }
1283 }
1284 
Nlm_CustomColorDraw(Nlm_PaneL p)1285 static void Nlm_CustomColorDraw ( Nlm_PaneL p ){
1286   int      x,y,xx,yy;
1287   Nlm_RecT rp;
1288   Nlm_RecT rdraw;
1289 
1290   Nlm_ObjectRect (pCustomColor, &rp);
1291   if ( p != NULL ){
1292     y = stColorCurCustom / 8;
1293     x = stColorCurCustom - y*8;
1294     xx = rp.left + x*NLM_CHCOLOR_BOXW;
1295     yy = rp.top + y*NLM_CHCOLOR_BOXH;
1296     Nlm_LoadRect ( &rdraw, xx, yy,
1297                    xx + NLM_CHCOLOR_BOXW, yy + NLM_CHCOLOR_BOXH );
1298     Nlm_InvertMode();
1299     Nlm_FrameRect ( &rdraw );
1300     Nlm_CopyMode();
1301   }
1302   for ( x=0; x<8; x++ ){
1303     for ( y=0; y<2; y++ ){
1304       xx = rp.left + x*NLM_CHCOLOR_BOXW;
1305       yy = rp.top + y*NLM_CHCOLOR_BOXH;
1306       Nlm_LoadRect ( &rdraw, xx + 2, yy + 2,
1307                      xx + NLM_CHCOLOR_BOXW - 2, yy + NLM_CHCOLOR_BOXH - 2 );
1308       Nlm_FrameRect ( &rdraw );
1309     }
1310   }
1311   for ( x=0; x<8; x++ ){
1312     for ( y=0; y<2; y++ ){
1313       xx = rp.left + x*NLM_CHCOLOR_BOXW;
1314       yy = rp.top + y*NLM_CHCOLOR_BOXH;
1315       Nlm_LoadRect ( &rdraw, xx + 3, yy + 3,
1316                      xx + NLM_CHCOLOR_BOXW - 3, yy + NLM_CHCOLOR_BOXH - 3 );
1317       Nlm_SelectColor ( theCustomColors[y*8+x].red,
1318                         theCustomColors[y*8+x].green,
1319                         theCustomColors[y*8+x].blue );
1320       Nlm_PaintRect ( &rdraw );
1321     }
1322   }
1323 }
1324 
Nlm_HColorDraw(Nlm_PaneL p)1325 static void Nlm_HColorDraw ( Nlm_PaneL p ){
1326   Nlm_RecT rp;
1327   int      i;
1328   int      x0, y0, xcur;
1329 
1330   Nlm_ObjectRect (pHColor, &rp);
1331   rp.left += NLM_CHCOLOR_PTRW2;
1332   rp.right -= NLM_CHCOLOR_PTRW2;
1333   Nlm_FrameRect ( &rp );
1334   x0 = xcur = rp.left + 1;
1335   y0 = rp.top + 1;
1336   if ( stColorModel == 1 ) {
1337     for ( i=0; i<6; i++ ){
1338       Nlm_LoadRect ( &rp, xcur, y0,
1339           x0 + (NLM_CHCOLOR_SHLW*(i+1))/18, y0+NLM_CHCOLOR_SHLH-2);
1340       Nlm_SelectColor ( (Nlm_Uint1)(255-(i*255)/6),
1341                         (Nlm_Uint1)((i*255)/6), 0 );
1342       xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/18;
1343       Nlm_PaintRect ( &rp );
1344     }
1345     for ( i=0; i<6; i++ ){
1346       Nlm_LoadRect ( &rp, xcur, y0,
1347           x0 + (NLM_CHCOLOR_SHLW*(i+7))/18, y0+NLM_CHCOLOR_SHLH-2);
1348       Nlm_SelectColor ( 0, (Nlm_Uint1)(255-(i*255)/6),
1349                         (Nlm_Uint1)((i*255)/6) );
1350       xcur = x0 + (NLM_CHCOLOR_SHLW*(i+7))/18;
1351       Nlm_PaintRect ( &rp );
1352     }
1353     for ( i=0; i<6; i++ ){
1354       if ( i == 5 ) {
1355         Nlm_LoadRect ( &rp, xcur, y0,
1356             x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
1357       } else {
1358         Nlm_LoadRect ( &rp, xcur, y0,
1359             x0 + (NLM_CHCOLOR_SHLW*(i+13))/18, y0+NLM_CHCOLOR_SHLH-2);
1360       }
1361       Nlm_SelectColor ( (Nlm_Uint1)((i*255)/6), 0,
1362                         (Nlm_Uint1)(255-(i*255)/6) );
1363       xcur = x0 + (NLM_CHCOLOR_SHLW*(i+13))/18;
1364       Nlm_PaintRect ( &rp );
1365     }
1366   } else {
1367     for ( i=0; i<6; i++ ){
1368       if ( i == 5 ){
1369         Nlm_LoadRect ( &rp, xcur, y0,
1370             x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
1371       } else {
1372         Nlm_LoadRect ( &rp, xcur, y0,
1373             x0 + (NLM_CHCOLOR_SHLW*(i+1))/6, y0+NLM_CHCOLOR_SHLH-2);
1374       }
1375       Nlm_SelectColor ( (Nlm_Uint1)(((i+1)*255)/7), 0, 0 );
1376       xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/6;
1377       Nlm_PaintRect ( &rp );
1378     }
1379   }
1380 }
1381 
Nlm_HPtrColorDraw(Nlm_PaneL p)1382 static void Nlm_HPtrColorDraw ( Nlm_PaneL p ){
1383   Nlm_RecT rp;
1384   Nlm_Int2 val;
1385 
1386   Nlm_ObjectRect (pHPtrColor, &rp);
1387   if ( stColorModel == 1 ) {
1388     val = stColorHSL[0];
1389   } else {
1390     val = stColorRGB[0];
1391   }
1392   Nlm_DrawColorPtr ( rp.left + NLM_CHCOLOR_PTRW2 +
1393     (Nlm_Int2)((long)val*(long)NLM_CHCOLOR_SHLW/(long)256),
1394     rp.top );
1395 }
1396 
Nlm_SColorDraw(Nlm_PaneL p)1397 static void Nlm_SColorDraw ( Nlm_PaneL p ){
1398   Nlm_RecT rp;
1399   int      i;
1400   int      x0, y0, xcur;
1401 
1402   Nlm_ObjectRect (pSColor, &rp);
1403   rp.left += NLM_CHCOLOR_PTRW2;
1404   rp.right -= NLM_CHCOLOR_PTRW2;
1405   Nlm_FrameRect ( &rp );
1406   x0 = xcur = rp.left + 1;
1407   y0 = rp.top + 1;
1408   for ( i=0; i<6; i++ ){
1409     if ( i == 5 ){
1410       Nlm_LoadRect ( &rp, xcur, y0,
1411           x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
1412     } else {
1413       Nlm_LoadRect ( &rp, xcur, y0,
1414           x0 + (NLM_CHCOLOR_SHLW*(i+1))/6, y0+NLM_CHCOLOR_SHLH-2);
1415     }
1416     if ( stColorModel == 1 ) {
1417       Nlm_SelectColor ( (Nlm_Uint1)(((7-i)*255)/10),
1418                         (Nlm_Uint1)((255*(14+i)/21)),
1419                         (Nlm_Uint1)(((7-i)*255)/10) );
1420     } else {
1421       Nlm_SelectColor ( 0, (Nlm_Uint1)(((i+1)*255)/7), 0 );
1422     }
1423     xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/6;
1424     Nlm_PaintRect ( &rp );
1425   }
1426 }
1427 
Nlm_SPtrColorDraw(Nlm_PaneL p)1428 static void Nlm_SPtrColorDraw ( Nlm_PaneL p ){
1429   Nlm_RecT rp;
1430   Nlm_Int2 val;
1431 
1432   Nlm_ObjectRect (pSPtrColor, &rp);
1433   if ( stColorModel == 1 ) {
1434     val = stColorHSL[1];
1435   } else {
1436     val = stColorRGB[1];
1437   }
1438   Nlm_DrawColorPtr ( rp.left + NLM_CHCOLOR_PTRW2 +
1439     (Nlm_Int2)((long)val*(long)NLM_CHCOLOR_SHLW/(long)256),
1440     rp.top );
1441 }
1442 
Nlm_LColorDraw(Nlm_PaneL p)1443 static void Nlm_LColorDraw ( Nlm_PaneL p ){
1444   Nlm_RecT rp;
1445   int      i;
1446   int      x0, y0, xcur;
1447 
1448   Nlm_ObjectRect (pLColor, &rp);
1449   rp.left += NLM_CHCOLOR_PTRW2;
1450   rp.right -= NLM_CHCOLOR_PTRW2;
1451   Nlm_FrameRect ( &rp );
1452   x0 = xcur = rp.left + 1;
1453   y0 = rp.top + 1;
1454   if ( stColorModel == 1 ) {
1455     for ( i=0; i<8; i++ ){
1456       if ( i == 7 ){
1457         Nlm_LoadRect ( &rp, xcur, y0,
1458             x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
1459       } else {
1460         Nlm_LoadRect ( &rp, xcur, y0,
1461             x0 + (NLM_CHCOLOR_SHLW*(i+1))/8, y0+NLM_CHCOLOR_SHLH-2);
1462       }
1463       Nlm_SelectColor ( (Nlm_Uint1)((i*255)/7),
1464                         (Nlm_Uint1)((i*255)/7),
1465                         (Nlm_Uint1)((i*255)/7) );
1466       xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/8;
1467       Nlm_PaintRect ( &rp );
1468     }
1469   } else {
1470     for ( i=0; i<6; i++ ){
1471       if ( i == 5 ){
1472         Nlm_LoadRect ( &rp, xcur, y0,
1473             x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
1474       } else {
1475         Nlm_LoadRect ( &rp, xcur, y0,
1476             x0 + (NLM_CHCOLOR_SHLW*(i+1))/6, y0+NLM_CHCOLOR_SHLH-2);
1477       }
1478       Nlm_SelectColor ( 0, 0, (Nlm_Uint1)(((i+1)*255)/7) );
1479       xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/6;
1480       Nlm_PaintRect ( &rp );
1481     }
1482   }
1483 }
1484 
Nlm_LPtrColorDraw(Nlm_PaneL p)1485 static void Nlm_LPtrColorDraw ( Nlm_PaneL p ){
1486   Nlm_RecT rp;
1487   Nlm_Int2 val;
1488 
1489   Nlm_ObjectRect (pLPtrColor, &rp);
1490   if ( stColorModel == 1 ) {
1491     val = stColorHSL[2];
1492   } else {
1493     val = stColorRGB[2];
1494   }
1495   Nlm_DrawColorPtr ( rp.left + NLM_CHCOLOR_PTRW2 +
1496     (Nlm_Int2)((long)val*(long)NLM_CHCOLOR_SHLW/(long)256),
1497     rp.top );
1498 }
1499 
Nlm_SelectDynColor(Nlm_Uint1 red,Nlm_Uint1 green,Nlm_Uint1 blue)1500 static void Nlm_SelectDynColor (Nlm_Uint1 red,
1501                                 Nlm_Uint1 green,
1502                                 Nlm_Uint1 blue) {
1503 #ifdef WIN_X
1504   if (Nlm_hasColor  &&  (tmpColorPixel != VOID_PIXEL))
1505     {
1506       Nlm_Uint2 rd = (Nlm_Uint2)red;
1507       Nlm_Uint2 gn = (Nlm_Uint2)green;
1508       Nlm_Uint2 bl = (Nlm_Uint2)blue;
1509       XColor xcolor;
1510       xcolor.red   = rd << 8 | rd;
1511       xcolor.green = gn << 8 | gn;
1512       xcolor.blue  = bl << 8 | bl;
1513       xcolor.pixel = tmpColorPixel;
1514       xcolor.flags = DoRed|DoGreen|DoBlue;
1515       XStoreColor(Nlm_currentXDisplay,  Nlm_VibrantDefaultColormap(), &xcolor);
1516       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, tmpColorPixel);
1517     }
1518   else
1519     Nlm_SelectColor(red, green, blue);
1520 #else
1521   Nlm_SelectColor(red, green, blue);
1522 #endif
1523 }
1524 
Nlm_RetColorDraw(Nlm_PaneL p)1525 static void Nlm_RetColorDraw ( Nlm_PaneL p ){
1526   Nlm_RecT  rp;
1527 
1528   Nlm_ObjectRect (pRetColor, &rp);
1529   Nlm_FrameRect ( &rp );
1530   Nlm_InsetRect ( &rp, 1, 1 );
1531   Nlm_SelectDynColor ( (Nlm_Uint1)stColorRGB[0],
1532                        (Nlm_Uint1)stColorRGB[1],
1533                        (Nlm_Uint1)stColorRGB[2] );
1534   Nlm_PaintRect ( &rp );
1535 }
1536 
1537 /* -------------------Button callbacks--------------------- */
1538 
Nlm_OKChooseColor(Nlm_ButtoN bn)1539 static void Nlm_OKChooseColor ( Nlm_ButtoN bn ){
1540   colorDlgUp = FALSE;
1541   colorDlgOK = TRUE;
1542 }
1543 
Nlm_CancelChooseColor(Nlm_ButtoN bn)1544 static void Nlm_CancelChooseColor ( Nlm_ButtoN bn ){
1545   colorDlgUp = FALSE;
1546 }
1547 
Nlm_SaveCustomColor(Nlm_ButtoN bn)1548 static void Nlm_SaveCustomColor ( Nlm_ButtoN bn ){
1549   Nlm_WindoW tmpPort;
1550 
1551   theCustomColors[stColorCurCustom].red = (Nlm_Uint1)stColorRGB[0];
1552   theCustomColors[stColorCurCustom].green = (Nlm_Uint1)stColorRGB[1];
1553   theCustomColors[stColorCurCustom].blue = (Nlm_Uint1)stColorRGB[2];
1554   tmpPort = Nlm_SavePort (pCustomColor);
1555   Nlm_Select (pCustomColor);
1556   Nlm_CustomColorDraw ( NULL );
1557   Nlm_RestorePort (tmpPort);
1558 }
1559 
1560 /* -------------------Update dialog------------------------ */
Nlm_UpdateColorDialog(Nlm_Int2 owner)1561 static void Nlm_UpdateColorDialog ( Nlm_Int2 owner ){
1562   Nlm_WindoW tmpPort;
1563 
1564   Nlm_ResetClip ();
1565   switch ( owner ){
1566     case NLM_CHCOLOR_OSP:
1567     case NLM_CHCOLOR_OHP:
1568     case NLM_CHCOLOR_OLP:
1569       if ( stColorModel == 1 ) {
1570         Nlm_HSL2RGB ( stColorRGB, stColorHSL );
1571       } else {
1572         Nlm_RGB2HSL ( stColorHSL, stColorRGB );
1573       }
1574       break;
1575     case NLM_CHCOLOR_OST:
1576     case NLM_CHCOLOR_OHT:
1577     case NLM_CHCOLOR_OLT:
1578       Nlm_HSL2RGB ( stColorRGB, stColorHSL );
1579       break;
1580     default:
1581       Nlm_RGB2HSL ( stColorHSL, stColorRGB );
1582   }
1583   tmpPort = Nlm_SavePort (pRetColor);
1584   Nlm_Select (pRetColor);
1585   Nlm_RetColorDraw ( pRetColor );
1586   Nlm_RestorePort (tmpPort);
1587   switch ( owner ){
1588     case NLM_CHCOLOR_OHP:
1589     case NLM_CHCOLOR_OHT:
1590     case NLM_CHCOLOR_OLP:
1591     case NLM_CHCOLOR_OLT:
1592       break;
1593     default:
1594       Nlm_UpdColorPanel ( pSPtrColor );
1595   }
1596   switch ( owner ){
1597     case NLM_CHCOLOR_OSP:
1598     case NLM_CHCOLOR_OST:
1599     case NLM_CHCOLOR_OLP:
1600     case NLM_CHCOLOR_OLT:
1601       break;
1602     default:
1603       Nlm_UpdColorPanel ( pHPtrColor );
1604   }
1605   switch ( owner ){
1606     case NLM_CHCOLOR_OSP:
1607     case NLM_CHCOLOR_OST:
1608     case NLM_CHCOLOR_OHP:
1609     case NLM_CHCOLOR_OHT:
1610       break;
1611     default:
1612       Nlm_UpdColorPanel ( pLPtrColor );
1613   }
1614   if ( owner != NLM_CHCOLOR_OHT ) Nlm_UpdColorText ( tColorHue, stColorHSL[0] );
1615   if ( owner != NLM_CHCOLOR_OST ) Nlm_UpdColorText ( tColorSat, stColorHSL[1] );
1616   if ( owner != NLM_CHCOLOR_OLT ) Nlm_UpdColorText ( tColorLum, stColorHSL[2] );
1617   if ( owner != NLM_CHCOLOR_ORT ) Nlm_UpdColorText ( tColorRed, stColorRGB[0] );
1618   if ( owner != NLM_CHCOLOR_OGT ) Nlm_UpdColorText ( tColorGreen, stColorRGB[1] );
1619   if ( owner != NLM_CHCOLOR_OBT ) Nlm_UpdColorText ( tColorBlue, stColorRGB[2] );
1620 }
1621 
1622 /* -------------------Text callbacks----------------------- */
1623 
Nlm_EditColorRGB(Nlm_TexT t)1624 static void Nlm_EditColorRGB ( Nlm_TexT t ){
1625   int      ival;
1626   Nlm_Int2 owner;
1627 
1628   ival = Nlm_GetColorVal ( t );
1629   if ( t == tColorRed ){
1630     stColorRGB[0] = ival;
1631     owner = NLM_CHCOLOR_ORT;
1632   } else if ( t == tColorGreen ){
1633     stColorRGB[1] = ival;
1634     owner = NLM_CHCOLOR_OGT;
1635   } else {
1636     stColorRGB[2] = ival;
1637     owner = NLM_CHCOLOR_OBT;
1638   }
1639   Nlm_UpdateColorDialog (owner);
1640 }
1641 
Nlm_EditColorHSL(Nlm_TexT t)1642 static void Nlm_EditColorHSL ( Nlm_TexT t ){
1643   int      ival;
1644   Nlm_Int2 owner;
1645 
1646   ival = Nlm_GetColorVal ( t );
1647   if ( t == tColorHue ){
1648     stColorHSL[0] = ival;
1649     owner = NLM_CHCOLOR_OHT;
1650   } else if ( t == tColorSat ){
1651     stColorHSL[1] = ival;
1652     owner = NLM_CHCOLOR_OST;
1653   } else {
1654     stColorHSL[2] = ival;
1655     owner = NLM_CHCOLOR_OLT;
1656   }
1657   Nlm_UpdateColorDialog (owner);
1658 }
1659 
1660 /* -------------------Click callback----------------------- */
1661 
Nlm_BasicColorClick(Nlm_PaneL p,Nlm_PoinT pt)1662 static void Nlm_BasicColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
1663   Nlm_RecT   rp;
1664   int        colorNum;
1665 
1666   Nlm_ObjectRect (pBasicColor, &rp);
1667   pt.x -= rp.left;
1668   pt.y -= rp.top;
1669   pt.x /= NLM_CHCOLOR_BOXW;
1670   pt.y /= NLM_CHCOLOR_BOXH;
1671   colorNum = pt.y*8+pt.x;
1672   if ( (colorNum >= 0) && (colorNum < 48) ){
1673      stColorRGB[0] = theBasicColors[colorNum].red;
1674      stColorRGB[1] = theBasicColors[colorNum].green;
1675      stColorRGB[2] = theBasicColors[colorNum].blue;
1676      Nlm_UpdateColorDialog(NLM_CHCOLOR_OBC);
1677   }
1678 }
1679 
Nlm_CustomColorClick(Nlm_PaneL p,Nlm_PoinT pt)1680 static void Nlm_CustomColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
1681   Nlm_RecT   rp;
1682   Nlm_RecT   rdraw;
1683   int        colorNum,i,x,y;
1684 
1685   Nlm_ObjectRect (pCustomColor, &rp);
1686   pt.x -= rp.left;
1687   pt.y -= rp.top;
1688   pt.x /= NLM_CHCOLOR_BOXW;
1689   pt.y /= NLM_CHCOLOR_BOXH;
1690   colorNum = pt.y*8+pt.x;
1691   if ( (colorNum >= 0) && (colorNum < 16) ){
1692      stColorRGB[0] = theCustomColors[colorNum].red;
1693      stColorRGB[1] = theCustomColors[colorNum].green;
1694      stColorRGB[2] = theCustomColors[colorNum].blue;
1695      Nlm_InvertMode();
1696      for ( i=0;i<2;i++){
1697        y = stColorCurCustom / 8;
1698        x = stColorCurCustom - y*8;
1699        x = rp.left + x*NLM_CHCOLOR_BOXW;
1700        y = rp.top + y*NLM_CHCOLOR_BOXH;
1701        Nlm_LoadRect ( &rdraw, x, y,
1702                       x + NLM_CHCOLOR_BOXW, y + NLM_CHCOLOR_BOXH );
1703        Nlm_FrameRect ( &rdraw );
1704        stColorCurCustom = colorNum;
1705      }
1706      Nlm_CopyMode();
1707      Nlm_UpdateColorDialog (NLM_CHCOLOR_OCC);
1708   }
1709 }
1710 
Nlm_HColorClick(Nlm_PaneL p,Nlm_PoinT pt)1711 static void Nlm_HColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
1712   Nlm_RecT   rp;
1713   Nlm_Int2   val;
1714 
1715   Nlm_ObjectRect (pHColor, &rp);
1716   pt.x -= rp.left + NLM_CHCOLOR_PTRW2;
1717   if ( (pt.x >= 0) && (pt.x <= NLM_CHCOLOR_SHLW) ){
1718     val = (Nlm_Int2)(((long)pt.x * (long)256)/(long)NLM_CHCOLOR_SHLW);
1719     if ( val > 255 ) val = 255;
1720     if ( stColorModel == 1 ) {
1721       stColorHSL[0] = val;
1722     } else {
1723       stColorRGB[0] = val;
1724     }
1725     Nlm_UpdateColorDialog (NLM_CHCOLOR_OHP);
1726   }
1727 }
1728 
Nlm_SColorClick(Nlm_PaneL p,Nlm_PoinT pt)1729 static void Nlm_SColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
1730   Nlm_RecT   rp;
1731   Nlm_Int2   val;
1732 
1733   Nlm_ObjectRect (pSColor, &rp);
1734   pt.x -= rp.left + NLM_CHCOLOR_PTRW2;
1735   if ( (pt.x >= 0) && (pt.x <= NLM_CHCOLOR_SHLW) ){
1736     val = (Nlm_Int2)(((long)pt.x * (long)256)/(long)NLM_CHCOLOR_SHLW);
1737     if ( val > 255 ) val = 255;
1738     if ( stColorModel == 1 ) {
1739       stColorHSL[1] = val;
1740     } else {
1741       stColorRGB[1] = val;
1742     }
1743     Nlm_UpdateColorDialog (NLM_CHCOLOR_OSP);
1744   }
1745 }
1746 
Nlm_LColorClick(Nlm_PaneL p,Nlm_PoinT pt)1747 static void Nlm_LColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
1748   Nlm_RecT   rp;
1749   Nlm_Int2   val;
1750 
1751   Nlm_ObjectRect (pLColor, &rp);
1752   pt.x -= rp.left + NLM_CHCOLOR_PTRW2;
1753   if ( (pt.x >= 0) && (pt.x <= NLM_CHCOLOR_SHLW) ){
1754     val = (Nlm_Int2)(((long)pt.x * (long)256)/(long)NLM_CHCOLOR_SHLW);
1755     if ( val > 255 ) val = 255;
1756     if ( stColorModel == 1 ) {
1757       stColorHSL[2] = val;
1758     } else {
1759       stColorRGB[2] = val;
1760     }
1761     Nlm_UpdateColorDialog (NLM_CHCOLOR_OLP);
1762   }
1763 }
1764 
1765 /* ---------------Radio Button callback-------------------- */
1766 
Nlm_ChangeColorModel(Nlm_GrouP g)1767 static void Nlm_ChangeColorModel ( Nlm_GrouP g ){
1768   Nlm_RecT   rp;
1769   Nlm_PaneL  p[6];
1770   Nlm_Int2   i;
1771   Nlm_WindoW tmpPort;
1772 
1773   if ( Nlm_GetValue(g) != stColorModel ){
1774     stColorModel = Nlm_GetValue(g);
1775     p[0] = pSColor;
1776     p[1] = pSPtrColor;
1777     p[2] = pHColor;
1778     p[3] = pHPtrColor;
1779     p[4] = pLColor;
1780     p[5] = pLPtrColor;
1781     for (i=0; i<6; i++ ) {
1782       Nlm_ObjectRect (p[i], &rp);
1783       tmpPort = Nlm_SavePort (p[i]);
1784       Nlm_Select (p[i]);
1785       Nlm_InvalRect (&rp);
1786       Nlm_RestorePort (tmpPort);
1787     }
1788   }
1789 }
1790 
1791 /* ---------------Main dialog function--------------------- */
1792 
Nlm_ChooseColorDialog(Nlm_Uint1 PNTR redptr,Nlm_Uint1 PNTR greenptr,Nlm_Uint1 PNTR blueptr,Nlm_Boolean Initial)1793 extern Nlm_Boolean Nlm_ChooseColorDialog (
1794        Nlm_Uint1 PNTR redptr,Nlm_Uint1 PNTR greenptr, Nlm_Uint1 PNTR blueptr,
1795        Nlm_Boolean Initial ){
1796   Nlm_WindoW w;
1797   Nlm_GrouP  gw, gleft, gright, g, gtmp;
1798 #ifdef WIN_X
1799   unsigned long  plane_masks[1];
1800 #endif
1801 
1802   w = Nlm_MovableModalWindow (-50, -20, -20, -20, "Color", NULL);
1803   gw = Nlm_HiddenGroup (w, 2,0, NULL);
1804   Nlm_SetGroupMargins (gw, 1, 1);
1805   Nlm_SetGroupSpacing (gw, 10, 1);
1806   gleft = Nlm_HiddenGroup (gw, 1, 0, NULL);
1807   Nlm_SetGroupSpacing (gleft, 1, 10 );
1808   Nlm_StaticPrompt (gleft, " Basic colors:", 0, 0, Nlm_systemFont, 'l');
1809   pBasicColor = Nlm_SimplePanel ( gleft, NLM_CHCOLOR_BOXW * 8,
1810                                   NLM_CHCOLOR_BOXH * 6, Nlm_BasicColorDraw );
1811   Nlm_SetPanelClick ( pBasicColor, Nlm_BasicColorClick, NULL, NULL, NULL );
1812   Nlm_StaticPrompt (gleft, " Custom colors:", 0, 0, Nlm_systemFont, 'l');
1813   pCustomColor = Nlm_SimplePanel ( gleft, NLM_CHCOLOR_BOXW * 8,
1814                                    NLM_CHCOLOR_BOXH * 2, Nlm_CustomColorDraw );
1815   Nlm_SetPanelClick ( pCustomColor, Nlm_CustomColorClick, NULL, NULL, NULL );
1816   pRetColor = Nlm_SimplePanel ( gleft, NLM_CHCOLOR_EXW,
1817                                 NLM_CHCOLOR_EXH, Nlm_RetColorDraw );
1818   gright = Nlm_HiddenGroup (gw, 1, 0, NULL);
1819   Nlm_SetGroupSpacing (gright, 1, 1);
1820   g = Nlm_HiddenGroup (gright, 2, 0, Nlm_ChangeColorModel );
1821   Nlm_SetGroupMargins (g, 20, 0);
1822   Nlm_RadioButton ( g, "HSL" );
1823   Nlm_RadioButton ( g, "RGB" );
1824   Nlm_SetValue(g,1);
1825   stColorModel = 1;
1826   g = Nlm_HiddenGroup (gright, 1, 0, NULL);
1827   Nlm_SetGroupMargins (g, 1, 20);
1828   Nlm_SetGroupSpacing (g, 5, 10);
1829   gtmp = Nlm_HiddenGroup (g, 1, 0, NULL);
1830   Nlm_SetGroupSpacing (gtmp, 0, 0);
1831   pHColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
1832                               NLM_CHCOLOR_SHLH, Nlm_HColorDraw );
1833   Nlm_SetPanelClick ( pHColor, Nlm_HColorClick, Nlm_HColorClick, NULL, NULL );
1834   pHPtrColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
1835                                  NLM_CHCOLOR_PTRH, Nlm_HPtrColorDraw );
1836   Nlm_SetPanelClick ( pHPtrColor, Nlm_HColorClick, Nlm_HColorClick, NULL, NULL );
1837   Nlm_AlignObjects (ALIGN_CENTER, (Nlm_HANDLE)pHColor,
1838                                   (Nlm_HANDLE)pHPtrColor, NULL);
1839   gtmp = Nlm_HiddenGroup (g, 1, 0, NULL);
1840   Nlm_SetGroupSpacing (gtmp, 0, 0);
1841   pSColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
1842                               NLM_CHCOLOR_SHLH, Nlm_SColorDraw );
1843   Nlm_SetPanelClick ( pSColor, Nlm_SColorClick, Nlm_SColorClick, NULL, NULL );
1844   pSPtrColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
1845                                  NLM_CHCOLOR_PTRH, Nlm_SPtrColorDraw );
1846   Nlm_SetPanelClick ( pSPtrColor, Nlm_SColorClick, Nlm_SColorClick, NULL, NULL );
1847   Nlm_AlignObjects (ALIGN_CENTER, (Nlm_HANDLE)pSColor,
1848                                   (Nlm_HANDLE)pSPtrColor, NULL );
1849   gtmp = Nlm_HiddenGroup (g, 1, 0, NULL);
1850   Nlm_SetGroupSpacing (gtmp, 0, 0);
1851   pLColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
1852                               NLM_CHCOLOR_SHLH, Nlm_LColorDraw );
1853   Nlm_SetPanelClick ( pLColor, Nlm_LColorClick, Nlm_LColorClick, NULL, NULL );
1854   pLPtrColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
1855                                  NLM_CHCOLOR_PTRH, Nlm_LPtrColorDraw );
1856   Nlm_SetPanelClick ( pLPtrColor, Nlm_LColorClick, Nlm_LColorClick, NULL, NULL );
1857   Nlm_AlignObjects (ALIGN_CENTER, (Nlm_HANDLE)pLColor,
1858                                   (Nlm_HANDLE)pLPtrColor, NULL);
1859   g = Nlm_HiddenGroup (gright, 2, 0, NULL);
1860   Nlm_SetGroupMargins (g, 10, 2);
1861   gtmp = Nlm_HiddenGroup (g, 2, 0, NULL);
1862   Nlm_StaticPrompt (gtmp, "Hue:", 0, 0, Nlm_systemFont, 'r');
1863   tColorHue = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorHSL );
1864   Nlm_StaticPrompt (gtmp, "Sat:", 0, 0, Nlm_systemFont, 'r');
1865   tColorSat = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorHSL );
1866   Nlm_StaticPrompt (gtmp, "Lum:", 0, 0, Nlm_systemFont, 'r');
1867   tColorLum = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorHSL );
1868   gtmp = Nlm_HiddenGroup (g, 2, 0, NULL);
1869   Nlm_StaticPrompt (gtmp, "Red:", 0, 0, Nlm_systemFont, 'r');
1870   tColorRed = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorRGB );
1871   Nlm_StaticPrompt (gtmp, "Green:", 0, 0, Nlm_systemFont, 'r');
1872   tColorGreen = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorRGB );
1873   Nlm_StaticPrompt (gtmp, "Blue:", 0, 0, Nlm_systemFont, 'r');
1874   tColorBlue = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorRGB );
1875   g = Nlm_HiddenGroup (w, 3,0, NULL);
1876   Nlm_SetGroupSpacing (g, 15, 1);
1877   Nlm_SetGroupMargins (g, 60,1);
1878   Nlm_DefaultButton (g, "   OK   ", Nlm_OKChooseColor );
1879   Nlm_PushButton (g, "Cancel", Nlm_CancelChooseColor );
1880   Nlm_PushButton (g, "Save Custom Color", Nlm_SaveCustomColor );
1881 /*  Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE); */
1882   Nlm_RealizeWindow (w);
1883   Nlm_UpdateColorDialog (NLM_CHCOLOR_OBC);
1884   Nlm_Show ((Nlm_GraphiC) w);
1885   Nlm_ArrowCursor ();
1886   colorDlgUp = TRUE;
1887   colorDlgOK = FALSE;
1888 #ifdef WIN_X
1889   if (tmpColorPixel == VOID_PIXEL  &&
1890       Nlm_currentXDisplay != NULL  &&
1891       XAllocColorCells(Nlm_currentXDisplay,
1892                        Nlm_VibrantDefaultColormap(),
1893                        FALSE, plane_masks, 0, &tmpColorPixel, 1) == 0)
1894     {
1895       tmpColorPixel = VOID_PIXEL;
1896     }
1897 #endif
1898   Nlm_WaitForCondition( colorDlgUp );
1899   Nlm_ProcessAnEvent ();
1900 /*  Nlm_DoRemove ((Nlm_GraphiC) w, TRUE); */
1901   Nlm_Remove ((Nlm_GraphiC) w);
1902   if ( colorDlgOK ){
1903     *redptr = (Nlm_Uint1)stColorRGB[0];
1904     *greenptr = (Nlm_Uint1)stColorRGB[1];
1905     *blueptr = (Nlm_Uint1)stColorRGB[2];
1906     return TRUE;
1907   }
1908   return FALSE;
1909 }
1910 
1911 #endif
1912 /* -------------------End Non MS-Window ------------------- */
1913 
1914