NCBI C Toolkit Cross Reference

C/desktop/fstyle.c


  1 /*   fstyle.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:  fstyle.c
 27 *
 28 * Author:  Sergei Egorov, Alex Smirnov
 29 *
 30 * Version Creation Date:   9/23/94
 31 *
 32 * $Revision: 6.1 $
 33 *
 34 * File Description: 
 35 *
 36 * Modifications:  
 37 * --------------------------------------------------------------------------
 38 * $Log: fstyle.c,v $
 39 * Revision 6.1  2000/09/07 21:44:51  shavirin
 40 * Fixed bug when function Nlm_InitMuskStyles() called more, than 1 time.
 41 *
 42 * Revision 6.0  1997/08/25 18:22:01  madden
 43 * Revision changed to 6.0
 44 *
 45 * Revision 5.3  1997/04/03 19:54:31  vakatov
 46 * Added MSM_M_SCALE(max. number of alignments) for MSM_ALIGNMENT|MSM_NOSUBCLASS
 47 *
 48 *
 49 * ==========================================================================
 50 */
 51 
 52 /**************************************************************************/
 53 /* INCLUDE */
 54 /**************************************************************************/
 55 #include <vibrant.h>
 56 #include <picture.h> 
 57 #include <fstyle.h> 
 58 #include <fstylep.h> 
 59 
 60 /**************************************************************************/
 61 /* DEFINES */
 62 /**************************************************************************/
 63 #define MSM_TOTAL_SUBCLASSES   (MSM_TOTAL_CLASSES*MSM_SUBCLASSES_NUM)
 64 #define MSM_TOTAL_SUBCLASSES_R (MSM_TOTAL_CLASSES_R*MSM_SUBCLASSES_NUM)
 65 #define MSM_INDEX_OFFSET       (MSM_TOTAL_NOTPOS-1)
 66 #define MSM_BUFFER_SIZE        128
 67 #define MSM_CP_INDEX(i)        ((i+MSM_INDEX_OFFSET)*MSM_SUBCLASSES_NUM)
 68 
 69 /* Parameter types: */
 70 #define MSM_M_TRUEFALSE  0x1
 71 #define MSM_M_COLOR      0x2
 72 #define MSM_M_LTYPE      0x4
 73 #define MSM_M_SHADING    0x8
 74 #define MSM_M_PENWIDTH   0x10
 75 #define MSM_M_NUM        0x20
 76 #define MSM_M_STYLE      0x40
 77 #define MSM_M_FONT       0x80
 78 #define MSM_M_HEIGHT     0x100
 79 #define MSM_M_SCALE      0x200
 80 #define MSM_M_STRING     0x4000
 81 
 82 #define DEF_ENDS_SCALE   100
 83 #define DEF_MAXALIGN      50
 84 
 85 /**************************************************************************/
 86 /* TYPEDEFS */
 87 /**************************************************************************/
 88 typedef struct msmparams {
 89   CharPtr str;
 90   Int4    height;
 91   Int4    scale;
 92   Int4    style;
 93   Int4    color;
 94   FonT    font;
 95   Int2    num;
 96   Int1    ltype;
 97   Int1    shading;
 98   Int1    penwidth;
 99   Boolean truefalse;
100 } Nlm_MsmParams, PNTR Nlm_MsmParamsPtr;
101 
102 typedef struct msmmember {
103   struct msmmember PNTR next;
104   Char                  name[64];
105 } Nlm_MsmMember, PNTR Nlm_MsmMemberPtr;
106 
107 typedef struct {
108   Int2  tclass;
109   Int2  subclass;
110   Int2  musk;
111 } Nlm_MsmToLoad, PNTR Nlm_MsmToLoadPtr;
112 
113 typedef struct msmfont {
114   struct msmfont PNTR next;
115   Nlm_FontSpec        fontspec;
116   FonT                fnt;
117   Int2                fontnum;
118   Int2                size;
119   Boolean             newfont;
120 } Nlm_MsmFont, PNTR Nlm_MsmFontPtr;
121 
122 /**************************************************************************/
123 /* GLOBAL VARIABLE */
124 /**************************************************************************/
125 CharPtr mSM_allfeatureNames[] =
126 {
127 /*  0 */
128 "",       "GENE", "ORG",  "CDS",  "PROT",
129 "preRNA", "mRNA", "tRNA", "rRNA", "snRNA",
130 /* 10 */
131 "scRNA",  "otherRNA",   "PUB",      "SEQ",         "IMP",
132 "allele", "attenuator", "C_region", "CAAT_signal", "Imp_CDS",
133 /* 20 */
134 "conflict",  "D_loop", "D_segment", "enhancer",   "exon",
135 "GC_signal", "iDNA",   "intron",    "J_segment",  "LTR",
136 /* 30 */
137 "mat_peptide", "misc_binding", "misc_difference", "misc_feature","misc_recomb",
138 "misc_RNA",    "misc_signal",  "misc_structure",  "modified_base", "mutation",
139 /* 40 */
140 "N_region",    "old_sequence", "polyA_signal",  "polyA_site", "precursor_RNA", 
141 "prim_transcript", "primer_bind", "promoter", "protein_bind", "RBS",
142 /* 50 */
143 "repeat_region", "repeat_unit", "rep_origin",  "S_region", "satellite",
144 "sig_peptide",   "source",      "stem_loop",   "STS",      "TATA_signal",
145 /* 60 */
146 "terminator", "transit_peptide", "unsure", "V_region", "V_segment",
147 "variation",  "virion",          "3clip",  "3UTR",     "5clip",
148 /* 70 */
149 "5UTR",    "10_signal", "35_signal", "site_ref", "REGION", 
150 "COMMENT", "BOND",      "SITE",      "RSITE",    "USER",
151 /* 80 */
152 "TXINIT", "NUM",        "PSEC_STR",       "NON_STD_RESIDUE", "HET",
153 "BIOSRC", "preprotein", "mat_peptide_aa", "sig_peptide_aa","transit_peptide_aa"
154 };
155 
156 /**************************************************************************/
157 /* STATIC VARIABLE */
158 /**************************************************************************/
159 static Int2 featDefOrder[] =
160 {      /*  0   1   2   3   4   5   6   7   8   9 */
161 /*  0 */   0,  3,  0,  1,  1,  1,  2,  2,  3,  4,
162 /* 10 */   5,  0,  6,  7,  8,  9, 10, 11, 12,  0,
163 /* 20 */  13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
164 /* 30 */   0, 23, 24, 25, 26, 27, 28,  0, 29, 30,
165 /* 40 */  31, 32, 33, 34, 35, 36,  0, 37, 38, 39,
166 /* 50 */  40, 41, 42, 43, 44,  0,  0, 45, 46, 47,
167 /* 60 */  48,  0, 49, 50, 51, 52, 53, 54, 55, 56,
168 /* 70 */  57, 58, 59,  0, 60, 61, 62, 63, 64, 65,
169 /* 80 */  66, 67, 68, 69, 70, 71,  2,  3,  4,  5
170 };
171 
172 /* Names */
173 static CharPtr fileBaseName   = "nlmstman";
174 static CharPtr styleListName  = "SYSTEM";
175 static CharPtr fontTotalName  = "fonts";
176 static CharPtr styleTotalName = "styles";
177 static CharPtr fontName       = "name";
178 static CharPtr fontSizeName   = "size";
179 static CharPtr fontStyleName  = "style";
180 static CharPtr fontCharSetName= "charset";
181 static CharPtr fontPitchName  = "pitch";
182 static CharPtr fontFamilyName = "family";
183 static CharPtr empStr         = "";
184 
185 static Nlm_MsmToLoad tpLoad[] = {
186 { MSM_EXTRA_BOTH,    MSM_SEGMENT,   MSM_M_COLOR | MSM_M_SHADING |
187                                     MSM_M_STYLE | MSM_M_HEIGHT},
188 { MSM_EXTRA_BOTH,    MSM_SEG_BORD,  MSM_M_TRUEFALSE | MSM_M_COLOR | 
189                                     MSM_M_LTYPE | MSM_M_PENWIDTH },
190 { MSM_EXTRA_BOTH,    MSM_FGAP,      MSM_M_COLOR | MSM_M_LTYPE |
191                                     MSM_M_STYLE },
192 { MSM_EXTRA_BOTH,    MSM_FLABEL,    MSM_M_COLOR | MSM_M_STYLE |
193                                     MSM_M_FONT },
194 { MSM_EXTRA_MEDLINE, MSM_SEGMENT,   MSM_M_COLOR | MSM_M_SHADING |
195                                     MSM_M_STYLE | MSM_M_HEIGHT},
196 { MSM_EXTRA_MEDLINE, MSM_SEG_BORD,  MSM_M_TRUEFALSE | MSM_M_COLOR | 
197                                     MSM_M_LTYPE | MSM_M_PENWIDTH },
198 { MSM_EXTRA_MEDLINE, MSM_FGAP,      MSM_M_COLOR | MSM_M_LTYPE |
199                                     MSM_M_STYLE },
200 { MSM_EXTRA_MEDLINE, MSM_FLABEL,    MSM_M_COLOR | MSM_M_STYLE |
201                                     MSM_M_FONT },
202 { MSM_EXTRA_GENBANK, MSM_SEGMENT,   MSM_M_COLOR | MSM_M_SHADING |
203                                     MSM_M_STYLE | MSM_M_HEIGHT},
204 { MSM_EXTRA_GENBANK, MSM_SEG_BORD,  MSM_M_TRUEFALSE | MSM_M_COLOR | 
205                                     MSM_M_LTYPE | MSM_M_PENWIDTH },
206 { MSM_EXTRA_GENBANK, MSM_FGAP,      MSM_M_COLOR | MSM_M_LTYPE |
207                                     MSM_M_STYLE },
208 { MSM_EXTRA_GENBANK, MSM_FLABEL,    MSM_M_COLOR | MSM_M_STYLE |
209                                     MSM_M_FONT },
210 { MSM_EXTRA_GENBANK, MSM_NOSUBCLASS, MSM_M_COLOR | MSM_M_FONT },
211 { MSM_SEQUENCE,      MSM_SEGMENT,    MSM_M_COLOR | MSM_M_SHADING |
212                                      MSM_M_STYLE | MSM_M_HEIGHT },
213 { MSM_SEQUENCE,      MSM_SEG_BORD,   MSM_M_TRUEFALSE | MSM_M_COLOR | 
214                                      MSM_M_LTYPE | MSM_M_PENWIDTH },
215 { MSM_SEQUENCE,      MSM_SLABEL,     MSM_M_COLOR | MSM_M_STYLE |
216                                      MSM_M_FONT },
217 { MSM_CCOLOR,        MSM_NOSUBCLASS, MSM_M_NUM },
218 { MSM_ALIGNMENT,     MSM_NOSUBCLASS, MSM_M_STYLE | MSM_M_SCALE },
219 { MSM_ALIGNMENT,     MSM_ALINE,      MSM_M_COLOR | MSM_M_LTYPE | 
220                                      MSM_M_PENWIDTH },
221 { MSM_GROUPS,        MSM_NOSUBCLASS, MSM_M_TRUEFALSE | MSM_M_COLOR | 
222                                      MSM_M_NUM | MSM_M_FONT },
223 { MSM_TOPSTYLE,      MSM_NOSUBCLASS, MSM_M_STYLE },
224 { MSM_TOPSTYLE,      MSM_SPACE,      MSM_M_HEIGHT },
225 { MSM_TOPSTYLE,      MSM_ENDS,       MSM_M_SCALE},
226 { MSM_TOPSTYLE,      MSM_LABEL,      MSM_M_STYLE | MSM_M_NUM},
227 { 1, 0, 0 }
228 };
229 
230 static Nlm_MsmToLoad featureLoad[] = {
231 { 1, MSM_SEGMENT,   MSM_M_COLOR | MSM_M_SHADING | MSM_M_LTYPE |
232                     MSM_M_STYLE | MSM_M_HEIGHT | MSM_M_PENWIDTH },
233 { 1, MSM_SEG_BORD,  MSM_M_TRUEFALSE | MSM_M_COLOR | 
234                     MSM_M_LTYPE | MSM_M_PENWIDTH },
235 { 1, MSM_FGAP,      MSM_M_COLOR | MSM_M_LTYPE |
236                     MSM_M_PENWIDTH | MSM_M_STYLE },
237 { 1, MSM_FLABEL,    MSM_M_COLOR | MSM_M_STYLE |
238                     MSM_M_FONT },
239 { 1, MSM_FGROUP,    MSM_NUM },
240 { 1, MSM_FORDER,    MSM_NUM },
241 { 0,0,0 }
242 };
243 
244 static Boolean           msmInit = FALSE;
245 static Int2              msmCurrent;
246 static Nlm_MsmMember     allStyles;
247 static Int2              totalStyles;
248 static Nlm_MsmFontPtr    allFonts;
249 static Int2              totalFonts;
250 static Nlm_MsmParams     cpStatic[MSM_TOTAL_SUBCLASSES];
251 static Nlm_MsmParamsPtr  cpEdit;
252 static Int2              msmEdit;
253 static Int2              programLineHeight;
254 
255 /**************************************************************************/
256 /* STATIC FUNCTION */
257 /**************************************************************************/
258 
259 /**************************************************************************
260 * Nlm_GetIntAppParam()
261 *   Get integer configuration parameter
262 **************************************************************************/
263 static Int4
264 /*FCN*/Nlm_GetIntAppParam ( 
265   CharPtr fBase,                       /* file base (I) */
266   CharPtr sectionName,                 /* section (I) */
267   CharPtr pName,                       /* parameter name (I) */
268   Int4    defVal                       /* default value */
269 ){
270   long lval;
271   Int2 i;
272   Char buf[32];
273 
274   i = GetAppParam ( fBase, sectionName, pName, empStr, buf, 31 );
275   if ( i == 0 ) return defVal;
276   buf[i] = 0;
277   sscanf ( buf, "%ld", &lval );
278   return (Int4)lval;
279 } /* End of Nlm_GetIntAppParam() */
280 
281 /**************************************************************************
282 * Nlm_SetIntAppParam()
283 *   Set integer configuration parameter
284 **************************************************************************/
285 static void
286 /*FCN*/Nlm_SetIntAppParam ( 
287   CharPtr fBase,                       /* file base (I) */
288   CharPtr sectionName,                 /* section (I) */
289   CharPtr pName,                       /* parameter name (I) */
290   Int4    val                          /* value */
291 ){
292   Char buf[32];
293 
294   sprintf ( buf, "%ld", (long)val );
295   SetAppParam ( fBase, sectionName, pName, &(buf[0]) );
296 } /* End of Nlm_SetIntAppParam() */
297 
298 /**************************************************************************
299 * Nlm_LoadDefMuskStyle()
300 *   loads default style into cpCur
301 **************************************************************************/
302 static void 
303 /*FCN*/Nlm_LoadDefMuskStyle ( 
304   Nlm_MsmParamsPtr cpCur               /* style (O) */
305 ){
306   Int2             i;
307   Nlm_MsmParamsPtr cptr;
308 
309   for (i = 0;  i < MSM_TOTAL_SUBCLASSES;  i++)
310     MemFree( cpCur[i].str );
311 
312   MemSet ( cpCur, 0, sizeof(Nlm_MsmParams)*MSM_TOTAL_SUBCLASSES );
313   cptr = &(cpCur[MSM_CP_INDEX(MSM_TOPSTYLE)]);
314 
315   cptr[MSM_NOSUBCLASS].style = MSM_HISTORY|MSM_SEGMENTS;
316   cptr[MSM_SPACE].height = 10;
317   cptr[MSM_ENDS].scale = DEF_ENDS_SCALE;
318   cptr[MSM_LABEL].num = 32;
319 
320   cptr = &(cpCur[MSM_CP_INDEX(MSM_GROUPS)]);
321 
322   cptr[MSM_NOSUBCLASS].num = 3;
323   cptr[MSM_NOSUBCLASS].font = Nlm_programFont;
324   cptr[MSM_NOSUBCLASS].height = programLineHeight;
325   cptr[1].num = 1;
326   cptr[1].str = StringSave ( "GENE-mRNA-CDS" );   /*NEED FIX*/
327   cptr[2].num = 2;
328   cptr[2].str = StringSave ( "PROTEINs" );  /*NEED FIX*/
329   cptr[3].num = 3;
330   cptr[3].str = StringSave ( "Other features" );  /*NEED FIX*/
331 
332   cptr = &(cpCur[MSM_CP_INDEX(MSM_ALIGNMENT)]);
333 
334   cptr[MSM_NOSUBCLASS].style = MSM_SEQHIST;
335   cptr[MSM_NOSUBCLASS].scale = DEF_MAXALIGN;
336   cptr[MSM_ALINE].ltype = SOLID_LINE;
337   cptr[MSM_ALINE].penwidth = 1;
338   cptr[MSM_ALINE].color = 0xFF00;
339 
340   cptr = &(cpCur[MSM_CP_INDEX(MSM_CCOLOR)]);
341 
342   cptr[MSM_NOSUBCLASS].num = 4;
343   cptr[1].color = 0xFF0000;
344   cptr[2].color = 0;
345   cptr[3].color = 0xFF;
346   cptr[4].color = 0xFF00FF;
347 
348   cptr = &(cpCur[MSM_CP_INDEX(MSM_SEQUENCE)]);
349 
350   cptr[MSM_SEGMENT].shading = SOLID_SHADING;
351   cptr[MSM_SEGMENT].style = MSM_SEG_BOX;
352   cptr[MSM_SEGMENT].height = 10;
353   cptr[MSM_SEGMENT].color = 0;
354   cptr[MSM_SEG_BORD].truefalse = FALSE;
355   cptr[MSM_SEG_BORD].ltype = SOLID_LINE;
356   cptr[MSM_SEG_BORD].penwidth = 1;
357   cptr[MSM_SEG_BORD].color = 0;
358   cptr[MSM_SLABEL].style = PRINTID_FASTA_SHORT;
359   cptr[MSM_SLABEL].font = Nlm_programFont;
360   cptr[MSM_SLABEL].height = programLineHeight;
361 
362   for(i = MSM_EXTRA_GENBANK; i>= MSM_EXTRA_BOTH; --i) {
363 
364     cptr = &(cpCur[MSM_CP_INDEX(i)]);
365 
366     cptr[MSM_SEGMENT].shading = SOLID_SHADING;
367     cptr[MSM_SEGMENT].style = MSM_SEG_BOX|MSM_SEG_SHOWORIENT;
368     cptr[MSM_SEGMENT].height = 8;
369     cptr[MSM_SEG_BORD].truefalse = FALSE;
370     cptr[MSM_SEG_BORD].ltype = SOLID_LINE;
371     cptr[MSM_SEG_BORD].penwidth = 1;
372     cptr[MSM_FGAP].ltype = SOLID_LINE;
373     cptr[MSM_FGAP].penwidth = 1;
374     cptr[MSM_FGAP].style = MSM_GAP_LINE;
375     cptr[MSM_FLABEL].style = MSM_LABEL_CONTENT;
376     cptr[MSM_FLABEL].font = Nlm_programFont;
377     cptr[MSM_FLABEL].color = 0xFF00FF;
378     cptr[MSM_FLABEL].height = programLineHeight;
379   }
380 
381   for ( i=1; i<=MSM_TOTAL_POSITIVE; i++ ){
382 
383     cptr = &(cpCur[MSM_CP_INDEX(i)]);
384 
385     cptr[MSM_SEGMENT].shading = SOLID_SHADING;
386     cptr[MSM_SEGMENT].style = MSM_SEG_BOX|MSM_SEG_SHOWORIENT;
387     cptr[MSM_SEGMENT].height = 8;
388     cptr[MSM_SEG_BORD].truefalse = FALSE;
389     cptr[MSM_SEG_BORD].ltype = SOLID_LINE;
390     cptr[MSM_SEG_BORD].penwidth = 1;
391     cptr[MSM_FGAP].ltype = SOLID_LINE;
392     cptr[MSM_FGAP].penwidth = 1;
393     cptr[MSM_FGAP].style = MSM_GAP_LINE;
394     cptr[MSM_FLABEL].style = MSM_LABEL_CONTENT;
395     cptr[MSM_FLABEL].font = Nlm_programFont;
396     cptr[MSM_FLABEL].height = programLineHeight;
397     cptr[MSM_FGROUP].num = 3;
398     cptr[MSM_FORDER].num = featDefOrder[i];
399   }
400 
401   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_CDS)]);
402   cptr[MSM_SEGMENT].color = 0xFF00FF;
403   cptr[MSM_FGROUP].num = 1;
404   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_mRNA)]);
405   cptr[MSM_SEGMENT].color = 0xFF;
406   cptr[MSM_FGROUP].num = 1;
407   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_GENE)]);
408   cptr[MSM_FGROUP].num = 1;
409 
410   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_PROT)]);
411   cptr[MSM_FGROUP].num = 2;
412   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_preprotein)]);
413   cptr[MSM_FGROUP].num = 2;
414   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_mat_peptide_aa)]);
415   cptr[MSM_FGROUP].num = 2;
416   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_sig_peptide_aa)]);
417   cptr[MSM_FGROUP].num = 2;
418   cptr = &(cpCur[MSM_CP_INDEX(FEATDEF_transit_peptide_aa)]);
419   cptr[MSM_FGROUP].num = 2;
420 
421 }  /* End of Nlm_LoadDefMuskStyle() */
422 
423 /**************************************************************************
424 * Nlm_GetLoadedMuskFont()
425 *   returns hande of loaded font or NULL if not found
426 **************************************************************************/
427 static FonT
428 /*FCN*/Nlm_GetLoadedMuskFont ( 
429   Int2     fnum,                       /* Font number (I)*/
430   Int2Ptr  fsize                       /* Font size (O) */
431 ){
432   Nlm_MsmFontPtr p;
433 
434   p = allFonts;
435   while ( p != NULL ){
436     if ( fnum == p->fontnum ) {
437       if ( fsize != NULL ) *fsize = p->size;
438       return p->fnt;
439     }
440     p = p->next;
441   }
442   return NULL;
443 } /* End of Nlm_GetLoadedMuskFont() */
444 
445 /**************************************************************************
446 * Nlm_FreeAllFont()
447 *   frees all font resourses
448 **************************************************************************/
449 static void
450 /*FCN*/Nlm_FreeAllFont ( 
451   void
452 ){
453   Nlm_MsmFontPtr p1, p2;
454 
455   p1 = allFonts;
456   while ( p1 != NULL ){
457     p2 = p1->next;
458     if ( p1->fnt != Nlm_programFont ) p1->fnt = Nlm_DeleteFont ( p1->fnt );
459     MemFree ( p1 );
460     p1 = p2;
461   }
462 } /* End of Nlm_FreeAllFont() */
463 
464 /**************************************************************************
465 * Nlm_GetMuskFont()
466 *   returns font hande
467 **************************************************************************/
468 static FonT 
469 /*FCN*/Nlm_GetMuskFont (
470   Int2    fnum,                        /* Font number (I) */
471   Int2Ptr fsize                        /* Font size (O) */
472 ){
473   Nlm_FontSpec fsp;
474   FonT         fnt;
475   Int2         i;
476   Char         sectionName[64];
477   Char         buf[FONT_NAME_SIZE+1];
478 
479   fnt = Nlm_GetLoadedMuskFont (fnum, fsize);
480   if ( fnt == NULL ){
481     sprintf ( sectionName, "SYSTEMFONT:%d", (int)fnum );
482     i = GetAppParam ( fileBaseName, sectionName, fontName, empStr, buf, 
483                       FONT_NAME_SIZE );
484     if ( i == 0 ) {
485       *fsize = programLineHeight;
486       return NULL;
487     }
488     buf[i] = 0;
489     StringCpy ( fsp.name, buf );
490     fsp.size = (Int2)Nlm_GetIntAppParam(fileBaseName, sectionName,
491                                         fontSizeName, 12 );
492     fsp.style = (Uint1)Nlm_GetIntAppParam(fileBaseName, sectionName,
493                                         fontStyleName, STYLE_REGULAR );
494     fsp.charset = (Uint1)Nlm_GetIntAppParam(fileBaseName, sectionName,
495                                         fontCharSetName, CHARSET_NULL );
496     fsp.pitch = (Uint1)Nlm_GetIntAppParam(fileBaseName, sectionName,
497                                         fontPitchName, PITCH_NULL );
498     fsp.family = (Uint1)Nlm_GetIntAppParam(fileBaseName, sectionName,
499                                         fontFamilyName, FAMILY_ROMAN );
500     fnt = Nlm_LoadMuskFont ( &fsp, fnum, fsize );
501   }
502   return fnt;
503 } /* End of Nlm_GetMuskFont() */
504 
505 /**************************************************************************
506 * Nlm_SaveFonts()
507 *   save new font resourses
508 **************************************************************************/
509 static void
510 /*FCN*/Nlm_SaveFonts ( 
511   void
512 ){
513   Nlm_MsmFontPtr p;
514   Char           sectionName[64];
515   Boolean        oldCacheVal;
516 
517   oldCacheVal = CacheAppParam(TRUE);
518 
519   p = allFonts;
520   while ( p != NULL ){
521     if ( p->newfont ) {
522       sprintf ( sectionName, "SYSTEMFONT:%d", (int)p->fontnum );
523       SetAppParam ( fileBaseName, sectionName, fontName, p->fontspec.name ); 
524       Nlm_SetIntAppParam ( fileBaseName, sectionName, fontSizeName, 
525                     (Int4)p->fontspec.size ); 
526       Nlm_SetIntAppParam ( fileBaseName, sectionName, fontStyleName,
527                     (Int4)p->fontspec.style ); 
528       Nlm_SetIntAppParam ( fileBaseName, sectionName, fontCharSetName, 
529                     (Int4)p->fontspec.charset ); 
530       Nlm_SetIntAppParam ( fileBaseName, sectionName, fontPitchName, 
531                     (Int4)p->fontspec.pitch ); 
532       Nlm_SetIntAppParam ( fileBaseName, sectionName, fontFamilyName, 
533                     (Int4)p->fontspec.family ); 
534       p->newfont = FALSE;
535     }
536     p = p->next;
537   }
538   Nlm_SetIntAppParam ( fileBaseName, styleListName, fontTotalName, 
539                   (Int4)totalFonts ); 
540   CacheAppParam(oldCacheVal);
541 } /* End of Nlm_SaveFonts() */
542 
543 /**************************************************************************
544 * Nlm_GetFontNumber()
545 *   returns number of font
546 **************************************************************************/
547 static Int2
548 /*FCN*/ Nlm_GetFontNumber (
549   FonT  fnt                            /* font handle (I) */
550 ){
551   Nlm_MsmFontPtr p;
552 
553   p = allFonts;
554   while ( p != NULL ){
555     if ( p->fnt == fnt ) return p->fontnum;
556     p = p->next;
557   }
558   return 0;
559 } /* End of Nlm_GetFontNumber () */
560 
561 /**************************************************************************
562 * Nlm_Uint1ToStr()
563 *   convert Uint1 to string
564 **************************************************************************/
565 static void 
566 /*FCN*/ Nlm_Uint1ToStr (
567   CharPtr str,                         /* string (O) */
568   Uint1   val                          /* value (I) */
569 ){
570   *str++ = ((val>>4)&0xF) + 'A';
571   *str   = (val&0xF) + 'A';
572 } /*End of Nlm_Uint1ToStr() */
573 
574 /**************************************************************************
575 * Nlm_Uint2ToStr()
576 *   convert Uint2 to string
577 **************************************************************************/
578 static void 
579 /*FCN*/ Nlm_Uint2ToStr (
580   CharPtr str,                         /* string (O) */
581   Uint2   val                          /* value (I) */
582 ){
583   *str++ = ((val>>12)&0xF) + 'A';
584   *str++ = ((val>>8)&0xF) + 'A';
585   *str++ = ((val>>4)&0xF) + 'A';
586   *str   = (val&0xF) + 'A';
587 } /*End of Nlm_Uint2ToStr()*/
588 
589 /**************************************************************************
590 * Nlm_Uint4ToStr()
591 *   convert Uint4 to string
592 **************************************************************************/
593 static void 
594 /*FCN*/ Nlm_Uint4ToStr (
595   CharPtr str,                         /* string (O) */
596   Uint4   val                          /* value (I) */
597 ){
598   *str++ = (Char)((val>>28)&0xF) + 'A';
599   *str++ = (Char)((val>>24)&0xF) + 'A';
600   *str++ = (Char)((val>>20)&0xF) + 'A';
601   *str++ = (Char)((val>>16)&0xF) + 'A';
602   *str++ = (Char)((val>>12)&0xF) + 'A';
603   *str++ = (Char)((val>>8)&0xF) + 'A';
604   *str++ = (Char)((val>>4)&0xF) + 'A';
605   *str   = (Char)(val&0xF) + 'A';
606 } /*End of Nlm_Uint2ToStr()*/
607 
608 /**************************************************************************
609 * Nlm_StrToUint1()
610 *   convert string to Uint1
611 **************************************************************************/
612 static Uint1
613 /*FCN*/ Nlm_StrToUint1 (
614   CharPtr str                          /* string (I) */
615 ){
616   Uint1 val;
617 
618   val = (Uint1)(*str++ - 'A')<<4;
619   val |= (Uint1)(*str - 'A');
620   return val;
621 } /*End of Nlm_StrToUint1()*/
622 
623 /**************************************************************************
624 * Nlm_StrToUint2()
625 *   convert string to Uint2
626 **************************************************************************/
627 static Uint2
628 /*FCN*/ Nlm_StrToUint2 (
629   CharPtr str                          /* string (I) */
630 ){
631   Uint2 val;
632 
633   val = (Uint2)(*str++ - 'A')<<12;
634   val |= (Uint2)(*str++ - 'A')<<8;
635   val |= (Uint2)(*str++ - 'A')<<4;
636   val |= (Uint2)(*str - 'A');
637   return val;
638 } /*End of Nlm_StrToUint2()*/
639 
640 /**************************************************************************
641 * Nlm_StrToUint4()
642 *   convert string to Uint4
643 **************************************************************************/
644 static Uint4
645 /*FCN*/ Nlm_StrToUint4 (
646   CharPtr str                          /* string (I) */
647 ){
648   Uint4 val;
649 
650   val  = (Uint4)(*str++ - 'A')<<28;
651   val |= (Uint4)(*str++ - 'A')<<24;
652   val |= (Uint4)(*str++ - 'A')<<20;
653   val |= (Uint4)(*str++ - 'A')<<16;
654   val |= (Uint4)(*str++ - 'A')<<12;
655   val |= (Uint4)(*str++ - 'A')<<8;
656   val |= (Uint4)(*str++ - 'A')<<4;
657   val |= (Uint4)(*str - 'A');
658   return val;
659 } /*End of Nlm_StrToUint4()*/
660 
661 /**************************************************************************
662 * Nlm_LoadMuskSubClass()
663 *   loads subclass information from config file
664 **************************************************************************/
665 static void 
666 /*FCN*/LoadMuskSubClass ( 
667   CharPtr          name,               /* style name (I) */
668   Int2             classNum,           /* class number (I) */
669   Int2             subclassNum,        /* subclass number (I) */
670   Nlm_MsmParamsPtr p                   /* pointer to parameters (O) */
671 ){
672   CharPtr cPtr;
673   Int2    i;
674   Int2    fspec;
675   Char    buf[MSM_BUFFER_SIZE+1];
676   Char    pName[9];
677 
678   Nlm_Uint2ToStr ( &(pName[0]), classNum );
679   Nlm_Uint2ToStr ( &(pName[4]), subclassNum );
680   pName[8] = 0;
681   i = GetAppParam ( fileBaseName, name, pName, empStr, buf, 
682                     MSM_BUFFER_SIZE );
683   if ( i >= 4 ){
684     buf[i] = 0;
685     cPtr = buf;
686     i = Nlm_StrToUint2 (cPtr); cPtr += 4;
687     if ( i & MSM_M_TRUEFALSE )
688       {p->truefalse = (Boolean)Nlm_StrToUint1 (cPtr); cPtr += 2;}
689     if ( i & MSM_M_COLOR )
690       {p->color = (Int4)Nlm_StrToUint4 (cPtr); cPtr += 8;}
691     if ( i & MSM_M_LTYPE )
692       {p->ltype = (Int1)Nlm_StrToUint1 (cPtr); cPtr += 2;}
693     if ( i & MSM_M_SHADING )
694       {p->shading = (Int1)Nlm_StrToUint1 (cPtr); cPtr += 2;}
695     if ( i & MSM_M_PENWIDTH )
696       {p->penwidth = (Int1)Nlm_StrToUint1 (cPtr); cPtr += 2;}
697     if ( i & MSM_M_NUM )
698       {p->num = (Int2)Nlm_StrToUint2 (cPtr); cPtr += 4;}
699     if ( i & MSM_M_STYLE )
700       {p->style = (Int4)Nlm_StrToUint4 (cPtr); cPtr += 8;}
701     if ( i & MSM_M_FONT ) {
702       fspec = (Int2)Nlm_StrToUint2 (cPtr); cPtr += 4;
703       if ( fspec > 0 ){
704         p->font = Nlm_GetMuskFont ( fspec, &fspec );
705         p->height = (Int4)fspec;
706       }
707     }
708     if ( i & MSM_M_HEIGHT )
709       {p->height = (Int4)Nlm_StrToUint4 (cPtr); cPtr += 8;}
710     if ( i & MSM_M_SCALE )
711       {p->scale = (Int4)Nlm_StrToUint4 (cPtr); cPtr += 8;}
712     if ( i & MSM_M_STRING ) {
713       MemFree( p->str );
714       p->str = StringSave( cPtr );
715     }
716   }
717 } /* End of Nlm_LoadMuskSubClass() */
718 
719 /**************************************************************************
720 * Nlm_SaveMuskSubClass()
721 *   save subclass information into config file
722 **************************************************************************/
723 static void 
724 /*FCN*/SaveMuskSubClass ( 
725   CharPtr          name,               /* style name (I) */
726   Int2             classNum,           /* class number (I) */
727   Int2             subclassNum,        /* subclass number (I) */
728   Nlm_MsmParamsPtr p,                  /* pointer to parameters (I) */
729   Nlm_MsmParamsPtr pdef                /* pointer to default parameters (I) */
730 ){
731   CharPtr cPtr;
732   Uint2   musk;
733   Char    buf[MSM_BUFFER_SIZE+1];
734   Char    pName[9];
735 
736   Nlm_Uint2ToStr ( &(pName[0]), classNum );
737   Nlm_Uint2ToStr ( &(pName[4]), subclassNum );
738   pName[8] = 0;
739   musk = 0;
740   if ( (p->str != NULL) || (pdef->str != NULL) ){
741     if ( (p->str == NULL) || (pdef->str == NULL) ||
742          StringCmp ( p->str, pdef->str ) ) musk |= MSM_M_STRING;
743   }
744   if ( pdef->font != NULL ){
745     if ( pdef->font != p->font ) musk |= MSM_M_FONT;
746   } else if (p->height != pdef->height) musk |= MSM_M_HEIGHT;
747   if ( p->scale != pdef->scale ) musk |= MSM_M_SCALE;
748   if ( p->style != pdef->style ) musk |= MSM_M_STYLE;
749   if ( p->color != pdef->color ) musk |= MSM_M_COLOR;
750   if ( p->num != pdef->num ) musk |= MSM_M_NUM;
751   if ( p->ltype != pdef->ltype ) musk |= MSM_M_LTYPE;
752   if ( p->shading != pdef->shading ) musk |= MSM_M_SHADING;
753   if ( p->penwidth != pdef->penwidth ) musk |= MSM_M_PENWIDTH;
754   if ( p->truefalse != pdef->truefalse ) musk |= MSM_M_TRUEFALSE;
755   if ( musk == 0 ){
756     SetAppParam ( fileBaseName, name, pName, NULL );
757     return;
758   }
759   cPtr = buf;
760   Nlm_Uint2ToStr (cPtr, musk); cPtr += 4;
761   if ( musk & MSM_M_TRUEFALSE ){
762     Nlm_Uint1ToStr (cPtr, p->truefalse ); cPtr += 2;}
763   if ( musk & MSM_M_COLOR ){
764     Nlm_Uint4ToStr (cPtr, p->color ); cPtr += 8;}
765   if ( musk & MSM_M_LTYPE ){
766     Nlm_Uint1ToStr (cPtr, p->ltype ); cPtr += 2;}
767   if ( musk & MSM_M_SHADING ){
768     Nlm_Uint1ToStr (cPtr, p->shading ); cPtr += 2;}
769   if ( musk & MSM_M_PENWIDTH ){
770     Nlm_Uint1ToStr (cPtr, p->penwidth ); cPtr += 2;}
771   if ( musk & MSM_M_NUM ){
772     Nlm_Uint2ToStr (cPtr, p->num ); cPtr += 4;}
773   if ( musk & MSM_M_STYLE ){
774     Nlm_Uint4ToStr (cPtr, p->style ); cPtr += 8;}
775   if ( musk & MSM_M_FONT ){
776     Nlm_Uint2ToStr (cPtr, Nlm_GetFontNumber(p->font)); cPtr += 4;}
777   if ( musk & MSM_M_HEIGHT ){
778     Nlm_Uint4ToStr (cPtr, p->height ); cPtr += 8;}
779   if ( musk & MSM_M_SCALE ){
780     Nlm_Uint4ToStr (cPtr, p->scale ); cPtr += 8;}
781   if ( musk & MSM_M_STRING ){
782     StringCpy ( cPtr, p->str ); cPtr+=StringLen(p->str);}
783   *cPtr = 0;
784   SetAppParam ( fileBaseName, name, pName, buf );
785 } /* End of Nlm_SaveMuskSubClass() */
786 
787 /**************************************************************************
788 * Nlm_LoadNamedMuskStyle()
789 *   loads style information from config file
790 **************************************************************************/
791 static void 
792 /*FCN*/Nlm_LoadNamedMuskStyle ( 
793   CharPtr          name,               /* style name (I) */
794   Nlm_MsmParamsPtr cpCur               /* style (O) */
795 ){
796   Nlm_MsmParamsPtr cPtr;
797   Nlm_MsmToLoadPtr muskPtr;
798   Int2             total;
799   Int2             i;
800 
801   muskPtr = &(tpLoad[0]);
802   while ( muskPtr->tclass <= 0 ){
803     cPtr = &(cpCur[MSM_CP_INDEX(muskPtr->tclass) + muskPtr->subclass]);
804     LoadMuskSubClass ( name, muskPtr->tclass, muskPtr->subclass,
805                        cPtr );
806     muskPtr++;
807   }
808   total = cpCur[MSM_CP_INDEX(MSM_CCOLOR)+MSM_NOSUBCLASS].num;
809   cPtr = &(cpCur[MSM_CP_INDEX(MSM_CCOLOR) + 1]);
810   for ( i=1; i<=total; i++ ){
811     LoadMuskSubClass ( name, MSM_CCOLOR, i, cPtr++ );
812   }
813   total = cpCur[MSM_CP_INDEX(MSM_GROUPS)+MSM_NOSUBCLASS].num;
814   cPtr = &(cpCur[MSM_CP_INDEX(MSM_GROUPS) + 1]);
815   if ( total >= MSM_SUBCLASSES_NUM ) total = MSM_SUBCLASSES_NUM-1;
816   for ( i=1; i<=total; i++ ){
817     LoadMuskSubClass ( name, MSM_GROUPS, i, cPtr++ );
818   }
819   for ( i=1; i<=MSM_TOTAL_POSITIVE; i++ ){
820     muskPtr = &(featureLoad[0]);
821     while ( muskPtr->tclass > 0 ){
822       cPtr = &(cpCur[MSM_CP_INDEX(i) + muskPtr->subclass]);
823       LoadMuskSubClass ( name, i, muskPtr->subclass, cPtr );
824       muskPtr++;
825     }
826   }
827 } /* End of Nlm_LoadNamedMuskStyle() */
828 
829 /**************************************************************************
830 * Nlm_SaveNamedMuskStyle()
831 *   save style information into config file
832 **************************************************************************/
833 static void 
834 /*FCN*/Nlm_SaveNamedMuskStyle ( 
835   CharPtr          name,               /* style name (I) */
836   Nlm_MsmParamsPtr cpCur,              /* style (I) */
837   Nlm_MsmParamsPtr cpDefCur            /* default style (I) */
838 ){
839   Nlm_MsmParamsPtr cPtr;
840   Nlm_MsmParamsPtr cDefPtr;
841   Nlm_MsmToLoadPtr muskPtr;
842   Int2             total;
843   Int2             i;
844   Boolean          oldCacheVal;
845 
846   oldCacheVal = CacheAppParam(TRUE);
847   muskPtr = &(tpLoad[0]);
848   while ( muskPtr->tclass <= 0 ){
849     i = MSM_CP_INDEX(muskPtr->tclass) + muskPtr->subclass;
850     cPtr = &(cpCur[i]); cDefPtr = &(cpDefCur[i]);
851     SaveMuskSubClass ( name, muskPtr->tclass, muskPtr->subclass,
852                        cPtr, cDefPtr );
853     muskPtr++;
854   }
855   total = cpCur[MSM_CP_INDEX(MSM_CCOLOR)+MSM_NOSUBCLASS].num;
856   i = MSM_CP_INDEX(MSM_CCOLOR) + 1;
857   cPtr = &(cpCur[i]); cDefPtr = &(cpDefCur[i]);
858   for ( i=1; i<=total; i++ ){
859     SaveMuskSubClass ( name, MSM_CCOLOR, i, cPtr++, cDefPtr++ );
860   }
861   total = cpCur[MSM_CP_INDEX(MSM_GROUPS)+MSM_NOSUBCLASS].num;
862   i = MSM_CP_INDEX(MSM_GROUPS) + 1;
863   cPtr = &(cpCur[i]); cDefPtr = &(cpDefCur[i]);
864   if ( total >= MSM_SUBCLASSES_NUM ) total = MSM_SUBCLASSES_NUM-1;
865   for ( i=1; i<=total; i++ ){
866     SaveMuskSubClass ( name, MSM_GROUPS, i, cPtr++, cDefPtr++ );
867   }
868   for ( total=1; total<=MSM_TOTAL_POSITIVE; total++ ){
869     muskPtr = &(featureLoad[0]);
870     while ( muskPtr->tclass > 0 ){
871       i = MSM_CP_INDEX(total) + muskPtr->subclass;
872       cPtr = &(cpCur[i]); cDefPtr = &(cpDefCur[i]);
873       SaveMuskSubClass ( name, total, muskPtr->subclass, cPtr, cDefPtr );
874       muskPtr++;
875     }
876   }
877   CacheAppParam(oldCacheVal);
878 } /* End of Nlm_SaveNamedMuskStyle() */
879 
880 /**************************************************************************
881 * Nlm_GetMuskCP()
882 *   get the conf param
883 **************************************************************************/
884 static BigScalar
885 /*FCN*/Nlm_GetMuskCP ( 
886   Nlm_MsmParamsPtr style,              /* style (I) */
887   Int2 p_class,                        /* class (I) */
888   Int2 p_subclass,                     /* subclass (I) */
889   Int2 p_type                          /* type (I) */
890 ){
891   BigScalar retval = 0;
892   Int2      index;
893 
894   if ( (p_class > -MSM_TOTAL_NOTPOS) && (p_class <= MSM_TOTAL_POSITIVE_R) ){
895     index = (p_class + MSM_INDEX_OFFSET)*MSM_SUBCLASSES_NUM;
896   } else return retval;
897   if ( (p_subclass >= 0) && (p_subclass < MSM_SUBCLASSES_NUM) ){
898     index += p_subclass;
899   } else return retval;
900   switch ( p_type ){
901     case MSM_TRUEFALSE:
902       retval = (BigScalar)style[index].truefalse; break;
903     case MSM_COLOR:
904       retval = (BigScalar)style[index].color; break;
905     case MSM_LTYPE:
906       retval = (BigScalar)style[index].ltype; break;
907     case MSM_SHADING:
908       retval = (BigScalar)style[index].shading; break;
909     case MSM_PENWIDTH:
910       retval = (BigScalar)style[index].penwidth; break;
911     case MSM_NUM:
912       retval = (BigScalar)style[index].num; break;
913     case MSM_STYLE:
914       retval = (BigScalar)style[index].style; break;
915     case MSM_FONT:
916       retval = (BigScalar)style[index].font; 
917       if ( retval == (BigScalar)NULL ) retval = (BigScalar)Nlm_programFont;
918       break;
919     case MSM_HEIGHT:
920       retval = (BigScalar)style[index].height; break;
921     case MSM_STRING:
922       retval = (BigScalar)style[index].str; break;
923     case MSM_SCALE:
924       retval = (BigScalar)style[index].scale; break;
925   }
926   return retval;
927 } /* End of Nlm_GetMuskCP() */
928 
929 /**************************************************************************
930 * Nlm_GetStylePtr()
931 *   return pointer to style member
932 **************************************************************************/
933 static Nlm_MsmMemberPtr
934 /*FCN*/Nlm_GetStylePtr ( 
935   Int2 styleNum                        /* style number (I) */
936 ){
937   Nlm_MsmMemberPtr list;
938   Int2             i;
939 
940   list = &allStyles;
941   for ( i=0; i<styleNum; i++ ){
942     if ( list == NULL ) break;
943     list = list->next;
944   }
945   return list;
946 } /* End of Nlm_GetStylePtr () */
947 
948 /**************************************************************************
949 * Nlm_GetStyleNum()
950 *   return style number
951 **************************************************************************/
952 static Int2
953 /*FCN*/Nlm_GetStyleNum ( 
954   CharPtr styleName                    /* style number (I) */
955 ){
956   Nlm_MsmMemberPtr list;
957   Int2             i;
958 
959   list = &allStyles;
960   i = 0;
961   while ( list != NULL ) {
962     if ( StringCmp ( list->name, styleName ) == 0 ) return i;
963     i++;
964     list = list->next;
965   }
966   return -1;
967 } /* End of Nlm_GetStyleNum () */
968 
969 /**************************************************************************/
970 /* GLOBAL FUNCTIONS */
971 /**************************************************************************/
972 
973 /**************************************************************************
974 * Nlm_LoadMuskFont()
975 *   returns hande of loaded font
976 **************************************************************************/
977 FonT
978 /*FCN*/Nlm_LoadMuskFont ( 
979   Nlm_FontSpecPtr fsp,                 /* Pointer to FontSpec (I) */
980   Int2            fnum,                /* font number (0 - new) (I) */
981   Int2Ptr         fsize                /* font size (O) */
982 ){
983   Nlm_MsmFontPtr p;
984 
985   if ( fnum == 0 ) {
986     p = allFonts;
987     while ( p != NULL ){
988       if ( Nlm_EqualFontSpec ( fsp, &(p->fontspec) ) ) {
989         if ( fsize != NULL ) *fsize = p->size;
990         return p->fnt;
991       }
992       p = p->next;
993     }
994   }
995   p = MemNew (sizeof(Nlm_MsmFont));
996   p->fnt = Nlm_CreateFont (fsp);
997   if ( p->fnt == NULL ) p->fnt = Nlm_programFont;
998   p->fontspec = *fsp;
999   if ( fnum ){
1000     p->fontnum = fnum;
1001   } else {
1002     totalFonts++;
1003     p->fontnum = totalFonts;
1004     p->newfont = TRUE;
1005   }
1006   p->next = allFonts;
1007   allFonts = p;
1008   SelectFont ( p->fnt );
1009   p->size = Nlm_LineHeight();
1010   if ( fsize != NULL ) *fsize = p->size;
1011   return p->fnt;
1012 } /* End of Nlm_LoadMuskFont() */
1013 
1014 /**************************************************************************
1015 * Nlm_InitMuskStyles()
1016 *   init the system
1017 **************************************************************************/
1018 void LIBCALL
1019 /*FCN*/Nlm_InitMuskStyles ( 
1020   void
1021 ){
1022   Nlm_MsmMemberPtr cp;
1023   Int2             i,j;
1024   Char             buf1[MSM_BUFFER_SIZE+1];
1025   Char             buf2[32];
1026 
1027   if ( !msmInit ){
1028     SelectFont ( Nlm_programFont );
1029     programLineHeight = Nlm_stdLineHeight;
1030     SelectFont ( Nlm_systemFont );
1031     Nlm_LoadDefMuskStyle( &(cpStatic[0]) );
1032     totalStyles = Nlm_GetIntAppParam ( fileBaseName, styleListName, 
1033                                    styleTotalName, 1 ); 
1034     totalFonts = Nlm_GetIntAppParam ( fileBaseName, styleListName, 
1035                                    fontTotalName, 0 ); 
1036     StringCpy ( allStyles.name, styleListName );
1037     allStyles.next = NULL;
1038     cp = &allStyles;
1039     for ( i=1; i<totalStyles; i++ ){
1040       sprintf ( buf2, "STYLE%d", i );
1041       j = GetAppParam ( fileBaseName, styleListName, buf2, empStr, buf1, 
1042                         MSM_BUFFER_SIZE);
1043       if ( j == 0 ) break;
1044       if ( j > 63 ) j = 63;
1045       buf1[j] = 0;
1046       cp->next = MemNew ( sizeof(Nlm_MsmMember) );
1047       cp = cp->next;
1048       cp->next = NULL;
1049       StringCpy ( cp->name, buf1 );
1050     }
1051     msmCurrent = 0;
1052     allFonts = NULL;
1053     cpEdit = NULL;
1054     msmEdit = -1;
1055     msmInit = TRUE;
1056   }
1057 }  /* End of Nlm_InitMuskStyles () */
1058 
1059 /**************************************************************************
1060 * Nlm_ExitMuskStyles()
1061 *   free all resourses
1062 **************************************************************************/
1063 void LIBCALL
1064 /*FCN*/Nlm_ExitMuskStyles ( void )
1065 {
1066     Nlm_MsmMemberPtr cp, cpold;
1067     Nlm_Int2         i;
1068     
1069     for (i=0; i<MSM_TOTAL_SUBCLASSES; i++){
1070         if ( cpStatic[i].str != NULL ) MemFree (cpStatic[i].str);
1071         cpStatic[i].str = NULL;
1072     }
1073 
1074     cpold = allStyles.next;
1075     while ( cpold != NULL ){
1076         cp = cpold->next;
1077         MemFree ( cpold );
1078         cpold = cp;
1079     }
1080     allStyles.next = NULL;
1081     Nlm_FreeAllFont();
1082     msmInit = FALSE;
1083 }  /* End of Nlm_ExitMuskStyles() */
1084 
1085 /**************************************************************************
1086 * Nlm_GetMuskCParam()
1087 *   return configuration parameter
1088 **************************************************************************/
1089 BigScalar 
1090 /*FCN*/Nlm_GetMuskCParam ( 
1091   Int2 p_class,                        /* class (I) */
1092   Int2 p_subclass,                     /* subclass (I) */
1093   Int2 p_type                          /* type (I) */
1094 ){
1095   if ( p_class <= MSM_TOTAL_POSITIVE ){
1096     return Nlm_GetMuskCP(cpStatic, p_class, p_subclass, p_type );
1097   }
1098   return (BigScalar)0;
1099 } /* End of GetMuskCParam() */
1100 
1101 /**************************************************************************
1102 * Nlm_GetMuskTotalSt()
1103 *   return total number of styles
1104 **************************************************************************/
1105 Int2 
1106 /*FCN*/Nlm_GetMuskTotalSt ( 
1107   void
1108 ){
1109   return totalStyles;
1110 } /* End of Nlm_GetMuskTotalSt() */
1111 
1112 /**************************************************************************
1113 * Nlm_GetMuskStyleName()
1114 *   return the style name
1115 **************************************************************************/
1116 CharPtr 
1117 /*FCN*/Nlm_GetMuskStyleName ( 
1118   Int2 styleNum                        /* style number (I) */
1119 ){
1120   Nlm_MsmMemberPtr p;
1121   CharPtr          name = NULL;
1122 
1123   if ( !msmInit ) Nlm_InitMuskStyles ();
1124   p = Nlm_GetStylePtr(styleNum);
1125   if ( p != NULL ){
1126     name = &(p->name[0]);
1127   }
1128   return name;
1129 } /* End of Nlm_GetMuskStyleName () */
1130 
1131 /**************************************************************************
1132 * Nlm_GetMuskCurrentSt()
1133 *   return the current style number
1134 **************************************************************************/
1135 Int2 
1136 /*FCN*/Nlm_GetMuskCurrentSt ( 
1137   void
1138 ){
1139   if ( !msmInit ) Nlm_InitMuskStyles ();
1140   return msmCurrent;
1141 } /* End of Nlm_GetMuskCurrentSt () */
1142 
1143 /**************************************************************************
1144 * Nlm_SetMuskCurrentSt()
1145 *   sets the current style number
1146 **************************************************************************/
1147 void 
1148 /*FCN*/Nlm_SetMuskCurrentSt ( 
1149   CharPtr name                         /* style number (I) */
1150 ){
1151   Nlm_MsmMemberPtr m;
1152   Int2             styleNum;
1153 
1154   if ( !msmInit ) Nlm_InitMuskStyles ();
1155   styleNum = Nlm_GetStyleNum ( name );
1156   if ( (styleNum != msmCurrent)&&(styleNum >= 0) ){
1157     Nlm_LoadDefMuskStyle( &(cpStatic[0]) );
1158     if ( styleNum != 0 ){
1159       m = Nlm_GetStylePtr ( styleNum );
1160       Nlm_LoadNamedMuskStyle ( &(m->name[0]), &(cpStatic[0]) );
1161     }
1162     msmCurrent = styleNum;
1163   }
1164 }  /* End of Nlm_SetMuskCurrentSt() */
1165 
1166 /**************************************************************************
1167 * Nlm_CopyMuskStyle()
1168 *   copy style
1169 **************************************************************************/
1170 Nlm_Int2
1171 /*FCN*/Nlm_CopyMuskStyle ( 
1172   Nlm_CharPtr name,                    /* name of new style (I) */
1173   Nlm_Int2    styleNum                 /* src style */
1174 ){
1175   Nlm_MsmParamsPtr cpCur;
1176   Nlm_MsmParamsPtr cpDefCur;
1177   Nlm_MsmMemberPtr list;
1178   Nlm_Int2         i;
1179   Char             buf[32];
1180 
1181   if ( !msmInit ) Nlm_InitMuskStyles ();
1182   if ( Nlm_GetMuskStyleName ( styleNum ) == NULL ) return -1;
1183   if ( (name == NULL) || (*name == 0) || (StringLen(name)) > 63 ) return -1;
1184   if ( Nlm_GetStyleNum ( name ) != -1 ) return -1;
1185   cpCur = MemNew ( MSM_TOTAL_SUBCLASSES * sizeof(Nlm_MsmParams) );
1186   cpDefCur = MemNew ( MSM_TOTAL_SUBCLASSES * sizeof(Nlm_MsmParams) );
1187   Nlm_LoadDefMuskStyle( cpCur );
1188   Nlm_LoadDefMuskStyle( cpDefCur );
1189   if ( styleNum != 0 ){
1190     list = Nlm_GetStylePtr ( styleNum );
1191     if ( list != NULL )  Nlm_LoadNamedMuskStyle (list->name, cpCur);
1192   }
1193   list = &(allStyles);
1194   while ( list->next != NULL ){
1195     list = list->next;
1196   }
1197   list->next = MemNew(sizeof(Nlm_MsmMember));
1198   list = list->next;
1199   StringCpy ( list->name, name );
1200   list->next = NULL;
1201   Nlm_SaveNamedMuskStyle ( name, cpCur, cpDefCur );
1202   for (i=0; i<MSM_TOTAL_SUBCLASSES; i++){
1203     if ( cpCur[i].str != NULL ) MemFree (cpCur[i].str);
1204     if ( cpDefCur[i].str != NULL ) MemFree (cpDefCur[i].str);
1205   }
1206   MemFree ( cpCur );
1207   MemFree ( cpDefCur );
1208   sprintf ( buf, "STYLE%d", totalStyles );
1209   SetAppParam ( fileBaseName, styleListName, buf, name );
1210   totalStyles++;
1211   Nlm_SetIntAppParam ( fileBaseName, styleListName, styleTotalName, 
1212                        totalStyles);
1213   return totalStyles-1;
1214 } /* End of Nlm_CopyMuskStyle () */
1215 
1216 /**************************************************************************
1217 * Nlm_DeleteMuskStyle()
1218 *   delete style
1219 **************************************************************************/
1220 Boolean
1221 /*FCN*/Nlm_DeleteMuskStyle(
1222   Nlm_Int2 styleNum                    /* style number (I) */
1223 ){
1224   Nlm_MsmParamsPtr cpDefCur;
1225   Nlm_MsmMemberPtr mPtr, mPtrD;
1226   CharPtr          name;
1227   Int2             i;
1228   Char             buf[32];
1229 
1230   if ( !msmInit ) Nlm_InitMuskStyles ();
1231   if ( (styleNum <= 0) || (styleNum == msmCurrent) ) return FALSE;
1232   name = Nlm_GetMuskStyleName ( styleNum );
1233   if ( name == NULL ) return FALSE;
1234   cpDefCur = MemNew ( MSM_TOTAL_SUBCLASSES * sizeof(Nlm_MsmParams) );
1235   Nlm_LoadDefMuskStyle( cpDefCur );
1236   Nlm_SaveNamedMuskStyle ( name, cpDefCur, cpDefCur );
1237   SetAppParam ( fileBaseName, name, NULL, NULL );
1238   for ( i = styleNum; i<totalStyles; i++ ){
1239     name = Nlm_GetMuskStyleName ( i+1 );
1240     sprintf ( buf, "STYLE%d", i );
1241     SetAppParam ( fileBaseName, styleListName, buf, name );
1242   }
1243   if ( msmCurrent > styleNum ) msmCurrent--;
1244   totalStyles--;
1245   Nlm_SetIntAppParam ( fileBaseName, styleListName, styleTotalName, 
1246                        totalStyles);
1247   mPtr = &(allStyles);
1248   for ( i=1; i<styleNum; i++ ){
1249     mPtr = mPtr->next;
1250   }
1251   mPtrD = mPtr->next;
1252   mPtr->next = mPtrD->next;
1253   MemFree ( mPtrD );
1254   MemFree ( cpDefCur );
1255   return TRUE;
1256 } /* End of Nlm_DeleteMuskStyle() */
1257 
1258 /**************************************************************************
1259 * Nlm_EditMuskStyle()
1260 *   edit the style
1261 **************************************************************************/
1262 Boolean 
1263 /*FCN*/Nlm_EditMuskStyle (
1264   Nlm_Int2 styleNum                    /* style number (I) */
1265 ){
1266   CharPtr name;
1267 
1268   if ( !msmInit ) Nlm_InitMuskStyles ();
1269   if ( (styleNum <= 0) || (cpEdit != NULL) ) return FALSE;
1270   name = Nlm_GetMuskStyleName ( styleNum );
1271   if ( name == NULL ) return FALSE;
1272   msmEdit = styleNum;
1273   cpEdit = MemNew ( MSM_TOTAL_SUBCLASSES_R * sizeof(Nlm_MsmParams) );
1274   Nlm_LoadDefMuskStyle( cpEdit );
1275   Nlm_LoadNamedMuskStyle ( name, cpEdit );
1276   return TRUE;
1277 }  /* End of Nlm_EditMuskStyle() */
1278 
1279 /**************************************************************************
1280 * Nlm_Nlm_SetMuskCParamEd()
1281 *   set config parameter
1282 **************************************************************************/
1283 void 
1284 /*FCN*/Nlm_SetMuskCParamEd ( 
1285   Nlm_Int2  p_class,                   /* class (I) */
1286   Nlm_Int2  p_subclass,                /* subclass (I) */
1287   Nlm_Int2  p_type,                    /* type (I) */
1288   BigScalar value                      /* value (I) */
1289 ){
1290   Nlm_Int2 index;
1291 
1292   if ( (p_class > -MSM_TOTAL_NOTPOS) && (p_class <= MSM_TOTAL_POSITIVE_R) ){
1293     index = (p_class + MSM_INDEX_OFFSET)*MSM_SUBCLASSES_NUM;
1294   } else return;
1295   if ( (p_subclass >= 0) && (p_subclass < MSM_SUBCLASSES_NUM) ){
1296     index += p_subclass;
1297   } else return;
1298   switch ( p_type ){
1299     case MSM_TRUEFALSE:
1300       cpEdit[index].truefalse = (Nlm_Boolean)value; break;
1301     case MSM_COLOR:
1302       cpEdit[index].color = (Nlm_Int4)value; break;
1303     case MSM_LTYPE:
1304       cpEdit[index].ltype = (Nlm_Int1)value; break;
1305     case MSM_SHADING:
1306       cpEdit[index].shading = (Nlm_Int1)value; break;
1307     case MSM_PENWIDTH:
1308       cpEdit[index].penwidth = (Nlm_Int1)value; break;
1309     case MSM_NUM:
1310       cpEdit[index].num = (Nlm_Int2)value; break;
1311     case MSM_STYLE:
1312       cpEdit[index].style = (Nlm_Int4)value; break;
1313     case MSM_FONT:
1314       cpEdit[index].font = (Nlm_FonT)value; break;
1315     case MSM_HEIGHT:
1316       cpEdit[index].height = (Nlm_Int4)value; break;
1317     case MSM_STRING:
1318       if ( cpEdit[index].str != NULL ) MemFree(cpEdit[index].str);
1319       cpEdit[index].str = NULL;
1320       if ( (Nlm_CharPtr)value != NULL ) {
1321         cpEdit[index].str = StringSave((Nlm_CharPtr)value);
1322       }
1323       break;
1324     case MSM_SCALE:
1325       cpEdit[index].scale = (Nlm_Int4)value; break;
1326   }
1327 } /* End of Nlm_SetMuskCParam() */
1328 
1329 /**************************************************************************
1330 * Nlm_GetMuskCParamEd()
1331 *   return configuration parameter
1332 **************************************************************************/
1333 BigScalar 
1334 /*FCN*/Nlm_GetMuskCParamEd ( 
1335   Int2 p_class,                        /* class (I) */
1336   Int2 p_subclass,                     /* subclass (I) */
1337   Int2 p_type                          /* type (I) */
1338 ){
1339   return Nlm_GetMuskCP(cpEdit, p_class, p_subclass, p_type );
1340 } /* End of GetMuskCParamEd() */
1341 
1342 /**************************************************************************
1343 * Nlm_FreeMuskStyleEd()
1344 *   end of edit session
1345 **************************************************************************/
1346 void
1347 /*FCN*/Nlm_FreeMuskStyleEd (
1348   Boolean save
1349 ){
1350   Nlm_MsmParamsPtr cpDefCur;
1351   Nlm_Int2         i;
1352 
1353   if ( cpEdit == NULL ) return;
1354   Nlm_SaveFonts();
1355   if ( save ) {
1356     cpDefCur = MemNew ( MSM_TOTAL_SUBCLASSES * sizeof(Nlm_MsmParams) );
1357     Nlm_LoadDefMuskStyle( cpDefCur );
1358     Nlm_SaveNamedMuskStyle ( Nlm_GetMuskStyleName(msmEdit), cpEdit, cpDefCur );
1359     if ( msmEdit == msmCurrent ){
1360       for (i=0; i<MSM_TOTAL_SUBCLASSES; i++){
1361         if ( cpStatic[i].str != NULL ) MemFree (cpStatic[i].str);
1362       }
1363       MemCopy ( &(cpStatic[0]), cpEdit, 
1364                 MSM_TOTAL_SUBCLASSES * sizeof(Nlm_MsmParams) );
1365       for (i=0; i<MSM_TOTAL_SUBCLASSES_R; i++){
1366         cpEdit[i].str = NULL;
1367       }
1368     }
1369     for (i=0; i<MSM_TOTAL_SUBCLASSES; i++){
1370       if ( cpDefCur[i].str != NULL ) MemFree (cpDefCur[i].str);
1371     }
1372     MemFree ( cpDefCur );
1373   }
1374   for (i=0; i<MSM_TOTAL_SUBCLASSES_R; i++){
1375     if ( cpEdit[i].str != NULL ) MemFree (cpEdit[i].str);
1376   }
1377   MemFree ( cpEdit );
1378   cpEdit = NULL;
1379   msmEdit = -1;
1380 } /*End of Nlm_FreeMuskStyleEd () */
1381 
1382 /* END */
1383 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.