1 /*   smdlg1.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:  smdlg1.c
27 *
28 * Author:  Alex Smirnov
29 *
30 * Version Creation Date:   8/10/95
31 *
32 * $Revision: 6.0 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: smdlg1.c,v $
39 * Revision 6.0  1997/08/25 18:24:48  madden
40 * Revision changed to 6.0
41 *
42 * Revision 5.1  1997/04/03 20:00:43  vakatov
43 * Added "Max. number of alignments:" input textfield and linked that
44 * to the StyleMgr MSM_ALIGNMENT | MSM_NOSUBCLASS | MSM_SCALE parameter
45 *
46 *
47 * ==========================================================================
48 */
49 
50 /**************************************************************************/
51 /* INCLUDE */
52 /**************************************************************************/
53 #include <vibrant.h>
54 #include <picture.h>
55 #include <fstyle.h>
56 #include <fstylep.h>
57 
58 /**************************************************************************/
59 /* DEFINES */
60 /**************************************************************************/
61 #define SM_PANEL_H    20
62 #define SM_PANEL_W    300
63 #define LINE_PANEL_H  16
64 #define LINE_PANEL_W  250
65 
66 /**************************************************************************/
67 /* TYPEDEFS */
68 /**************************************************************************/
69 
70 /**************************************************************************/
71 /* STATIC VARIABLE */
72 /**************************************************************************/
73 static PaneL  linePanel;
74 static ButtoN bStackGene;
75 static ButtoN bHistory;
76 static ButtoN bSegments;
77 
78 static TexT   spaceText;
79 static TexT   lableLenText;
80 static TexT   endScale;
81 static TexT   maxNAlign;
82 
83 static PaneL  exPanel;
84 static Int2   activColor = 0;
85 
86 /**************************************************************************/
87 /* STATIC FUNCTION */
88 /**************************************************************************/
89 static void
TopStyleCheck(ButtoN b)90 /*FCN*/TopStyleCheck (
91   ButtoN b
92 ){
93   BigScalar val = 0;
94 
95   if ( GetStatus (bStackGene) ) val |= MSM_STACKGENE;
96   if ( GetStatus (bHistory) ) val |= MSM_HISTORY;
97   if ( GetStatus (bSegments) ) val |= MSM_SEGMENTS;
98   Nlm_SetMuskCParamEd( MSM_TOPSTYLE,MSM_NOSUBCLASS,MSM_STYLE,val );
99 }
100 
101 static void
SetIntDialogTitle(TexT t)102 /*FCN*/SetIntDialogTitle (
103   TexT t
104 ){
105   Nlm_Char cValue[64];
106   long     iValue;
107   Int2     pClass, pSubclass, pType;
108 
109   if (t == spaceText) {
110     pClass    = MSM_TOPSTYLE;
111     pSubclass = MSM_SPACE;
112     pType     = MSM_HEIGHT;
113   }
114   else if (t == lableLenText) {
115     pClass    = MSM_TOPSTYLE;
116     pSubclass = MSM_LABEL;
117     pType     = MSM_NUM;
118   }
119   else if (t == endScale) {
120     pClass    = MSM_TOPSTYLE;
121     pSubclass = MSM_ENDS;
122     pType     = MSM_SCALE;
123   }
124   else if (t == maxNAlign) {
125     pClass    = MSM_ALIGNMENT;
126     pSubclass = MSM_NOSUBCLASS;
127     pType     = MSM_SCALE;
128   }
129   else
130     {
131       ASSERT ( FALSE );
132       return;
133     }
134 
135   iValue = (long)Nlm_GetMuskCParamEd(pClass, pSubclass, pType);
136   sprintf(cValue, "%ld", iValue);
137   SetTitle(t, cValue);
138 }
139 
140 
141 static void
TextDialog(TexT t)142 /*FCN*/TextDialog (
143   TexT t
144 ){
145   Nlm_Char cValue[64];
146   Nlm_Char PNTR cValuePtr;
147   long     iValue = -1;
148   Int4     cMax;
149   Int2     pClass, pSubclass, pType;
150   Int2     update = 0;
151 
152   if (t == spaceText) {
153     cMax      = 50;
154     pClass    = MSM_TOPSTYLE;
155     pSubclass = MSM_SPACE;
156     pType     = MSM_HEIGHT;
157   }
158   else if (t == lableLenText) {
159     cMax      = 100;
160     pClass    = MSM_TOPSTYLE;
161     pSubclass = MSM_LABEL;
162     pType     = MSM_NUM;
163   }
164   else if (t == endScale) {
165     cMax      = 10000;
166     pClass    = MSM_TOPSTYLE;
167     pSubclass = MSM_ENDS;
168     pType     = MSM_SCALE;
169   }
170   else if (t == maxNAlign) {
171     cMax      = INT4_MAX;
172     pClass    = MSM_ALIGNMENT;
173     pSubclass = MSM_NOSUBCLASS;
174     pType     = MSM_SCALE;
175   }
176   else
177     {
178       ASSERT ( FALSE );
179       return;
180     }
181 
182   Nlm_GetTitle( t, cValue, 64 );
183   cValue[63] = '\0';
184   for ( cValuePtr = cValue; IS_DIGIT(*cValuePtr); cValuePtr++ );
185   if ( *cValuePtr != '\0' ) {
186     *cValuePtr = 0;
187     update = 1;
188   }
189   sscanf ( cValue, "%ld", &iValue );
190   if ( (iValue < 0) || (cValue[0]==0) ) {
191     iValue = 0;
192     update = 2;
193   }
194   if ( (cValue[0] == '0') && (cValue[1] != 0) ){
195     iValue = 0;
196     update = 1;
197   }
198   if ( iValue > cMax ) {
199     iValue = cMax ;
200     update = 1;
201   }
202   if ( update == 2 ){
203     Nlm_SetTitle ( t, "" );
204   } else if ( update ) {
205     sprintf ( cValue, "%ld", iValue );
206     SetTitle ( t, cValue );
207   }
208 
209   Nlm_SetMuskCParamEd(pClass, pSubclass, pType, (BigScalar)iValue);
210 }
211 
212 
213 static void
AlignmentStyle(GrouP g)214 /*FCN*/AlignmentStyle (
215  GrouP g
216 ){
217   BigScalar val;
218 
219   switch ( GetValue (g) ){
220     case 1: val = MSM_SEQHIST; break;
221     case 2: val = MSM_MPAIR; break;
222     case 3: val = MSM_MDIM; break;
223     default: val = MSM_FIXED;
224   }
225   Nlm_SetMuskCParamEd( MSM_ALIGNMENT,MSM_NOSUBCLASS,MSM_STYLE,val );
226 }
227 
228 static void
LablesOn(GrouP g)229 /*FCN*/LablesOn (
230  GrouP g
231 ){
232   BigScalar val;
233 
234   switch ( GetValue (g) ){
235     case 1: val = MSM_LABEL_TOP; break;
236     case 2: val = MSM_LABEL_BOTTOM; break;
237     case 3: val = MSM_LABEL_LEFT; break;
238     default: val = MSM_LABEL_RIGHT;
239   }
240   Nlm_SetMuskCParamEd( MSM_TOPSTYLE,MSM_LABEL,MSM_STYLE,val);
241 }
242 
243 static void
LinePanelDraw(PaneL p)244 /*FCN*/LinePanelDraw (
245   PaneL p
246 ){
247   Int4      val;
248   RecT      rp;
249   PoinT     pt1, pt2;
250 
251   ObjectRect ( p, &rp );
252   pt1.x = rp.left;
253   pt2.x = rp.right;
254   pt1.y = pt2.y = (rp.top+rp.bottom)/2;
255   val = (Int4)Nlm_GetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_PENWIDTH);
256   WidePen ( (Int1)val );
257   val = (Int4)Nlm_GetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_LTYPE);
258   switch ( val ){
259     case DOTTED_LINE:
260       Dotted(); break;
261     case DASHED_LINE:
262       Dashed(); break;
263     default:
264       Solid();
265   }
266   val = (Int4)Nlm_GetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_COLOR);
267   SelectColor ( (Uint1)((val>>16)&0xFF), (Uint1)((val>>8)&0xFF),
268                 (Uint1)(val&0xFF) );
269   DrawLine ( pt1, pt2 );
270 }
271 
272 static void
ExPanelDrawCursor(void)273 /*FCN*/ExPanelDrawCursor (
274   void
275 ){
276   RecT rp;
277   RecT rDraw;
278   Int4 numColor;
279   Int2 w;
280 
281   numColor = (Int4)Nlm_GetMuskCParamEd(MSM_CCOLOR,MSM_NOSUBCLASS,MSM_NUM);
282   ObjectRect ( exPanel, &rp );
283   w = (rp.right - rp.left)/numColor;
284   LoadRect ( &rDraw, rp.left + w*activColor, rp.top,
285                        rp.left + w*(activColor+1), rp.bottom );
286   Solid();
287   Black();
288   WidePen(1);
289   InvertMode();
290   FrameRect ( &rDraw );
291   CopyMode();
292 }
293 
294 static void
ExPanelDraw(PaneL p)295 /*FCN*/ExPanelDraw (
296   PaneL p
297 ){
298   Int4 val;
299   RecT rp;
300   RecT rDraw;
301   Int4 numColor;
302   Int2 i, w;
303 
304   numColor = (Int4)Nlm_GetMuskCParamEd(MSM_CCOLOR,MSM_NOSUBCLASS,MSM_NUM);
305   ObjectRect ( p, &rp );
306   w = (rp.right - rp.left)/numColor;
307   Solid();
308   for ( i=0; i<numColor; i++ ){
309     LoadRect ( &rDraw, rp.left + w*i + 2, rp.top + 4,
310                        rp.left + w*(i+1) - 2, rp.bottom - 4 );
311     val = (Int4)Nlm_GetMuskCParamEd(MSM_CCOLOR,i+1,MSM_COLOR);
312     SelectColor ( (Uint1)((val>>16)&0xFF), (Uint1)((val>>8)&0xFF),
313                   (Uint1)(val&0xFF) );
314     PaintRect ( &rDraw );
315   }
316   ExPanelDrawCursor();
317 }
318 
319 static void
ExPanelClick(PaneL p,Nlm_PoinT pt)320 /*FCN*/ExPanelClick (
321   PaneL p,
322   Nlm_PoinT pt
323 ){
324   Int4      numColor;
325   Nlm_RecT  rp;
326   Int2      i, w;
327 
328   numColor = (Int4)Nlm_GetMuskCParamEd(MSM_CCOLOR,MSM_NOSUBCLASS,MSM_NUM);
329   ObjectRect (p, &rp);
330   w = (rp.right - rp.left)/numColor;
331   i = (pt.x - rp.left)/w;
332   ExPanelDrawCursor();
333   activColor = i;
334   ExPanelDrawCursor();
335   Nlm_SetToolDefaultSM  ( SM_TOOLS_COLOR,
336                           Nlm_GetMuskCParamEd(MSM_CCOLOR,i+1,MSM_COLOR));
337   Nlm_ShowToolsSM (SM_SHTOOLS_COLOR);
338 }
339 
340 static void
OnPeriod(GrouP g)341 /*FCN*/OnPeriod(
342   GrouP g
343 ){
344   RecT rp;
345   Int4 numColor;
346 
347   numColor = GetValue (g) + 1;
348   Nlm_SetMuskCParamEd(MSM_CCOLOR,MSM_NOSUBCLASS,MSM_NUM,(BigScalar)numColor);
349   activColor = 0;
350   ObjectRect ( exPanel, &rp );
351   Select (exPanel);  /* needed for Motif version - JK */
352   ResetClip();
353   InvalRect ( &rp );
354   Nlm_SetToolDefaultSM  ( SM_TOOLS_COLOR,
355                           Nlm_GetMuskCParamEd(MSM_CCOLOR,1,MSM_COLOR));
356   Nlm_ShowToolsSM (SM_SHTOOLS_COLOR);
357 }
358 
359 /**************************************************************************/
360 /* GLOBAL FUNCTIONS */
361 /**************************************************************************/
362 GrouP
Nlm_CreateDlgCommon(GrouP gTop)363 /*FCN*/Nlm_CreateDlgCommon (
364   GrouP gTop
365 ){
366   Int4     val;
367   GrouP    g, g1, g2, g3, g4 ;
368   PrompT   prompt;
369 
370   g = HiddenGroup ( gTop, -1, 0, NULL);
371   SetGroupSpacing ( g, 10, 15 );
372   g1 = HiddenGroup ( g, 2, 1, NULL );
373   SetGroupSpacing ( g1, 10, 1 );
374   g2 = HiddenGroup ( g1, 1, 2, NULL );
375 
376   g3 = NormalGroup ( g2, 3, 1, "Show", systemFont, NULL );
377   val = (Int4)Nlm_GetMuskCParamEd( MSM_TOPSTYLE,MSM_NOSUBCLASS,MSM_STYLE );
378   bStackGene = CheckBox ( g3, "Stack Gene", TopStyleCheck );
379   if ( val & MSM_STACKGENE ) SetStatus ( bStackGene, TRUE );
380   bHistory = CheckBox ( g3, "History", TopStyleCheck );
381   if ( val & MSM_HISTORY ) SetStatus ( bHistory, TRUE );
382   bSegments = CheckBox ( g3, "Segments", TopStyleCheck );
383   if ( val & MSM_SEGMENTS ) SetStatus ( bSegments, TRUE );
384 
385   g3 = HiddenGroup(g2, 2, 3, NULL);
386   SetGroupMargins(g3, 1, 10);
387   prompt = StaticPrompt(g3, "Space between lines : ", 0, 0, systemFont, 'l');
388   spaceText = DialogText(g3, "20", 5, TextDialog);
389   AlignObjects(ALIGN_MIDDLE, (HANDLE)prompt, (HANDLE)spaceText, NULL);
390   SetIntDialogTitle( spaceText );
391 
392   prompt = StaticPrompt(g3, "Maximum label length : ", 0, 0, systemFont, 'l');
393   lableLenText = DialogText(g3, "20", 5, TextDialog);
394   AlignObjects(ALIGN_MIDDLE, (HANDLE)prompt, (HANDLE)lableLenText, NULL);
395   SetIntDialogTitle( lableLenText );
396 
397   prompt = StaticPrompt(g3, "Show ends if scale > : ", 0, 0, systemFont, 'l');
398   endScale = DialogText(g3, "100", 5, TextDialog);
399   AlignObjects(ALIGN_MIDDLE, (HANDLE)prompt, (HANDLE)endScale, NULL);
400   SetIntDialogTitle( endScale );
401 
402   prompt = StaticPrompt(g3, "Max. N-of-Alignments : ", 0, 0, systemFont, 'l');
403   val = (Int4)Nlm_GetMuskCParamEd(MSM_ALIGNMENT, MSM_NOSUBCLASS, MSM_SCALE);
404   maxNAlign = DialogText(g3, " ", 5, TextDialog);
405   AlignObjects(ALIGN_MIDDLE, (HANDLE)prompt, (HANDLE)maxNAlign, NULL);
406   SetIntDialogTitle( maxNAlign );
407 
408   g2 = HiddenGroup ( g1, 2, 1, NULL );
409   SetGroupSpacing ( g2, 10, 1 );
410   g3 = NormalGroup ( g2, 1, 4, "Alignment style", systemFont, AlignmentStyle );
411   RadioButton ( g3, "Seq History" );
412   RadioButton ( g3, "MPair" );
413   RadioButton ( g3, "MDim" );
414   RadioButton ( g3, "Fixed" );
415   val = (Int4)Nlm_GetMuskCParamEd( MSM_ALIGNMENT, MSM_NOSUBCLASS,MSM_STYLE );
416   switch ( val ) {
417     case MSM_SEQHIST:
418       SetValue ( g3, 1 ); break;
419     case MSM_MPAIR:
420       SetValue ( g3, 2 ); break;
421     case MSM_MDIM:
422       SetValue ( g3, 3 ); break;
423     default:
424       SetValue ( g3, 4 );
425   }
426   g4 = NormalGroup ( g2, 1, 4, "Labels on", systemFont, LablesOn );
427   RadioButton ( g4, "Top" );
428   RadioButton ( g4, "Bottom" );
429   RadioButton ( g4, "Left" );
430   RadioButton ( g4, "Right" );
431   val = (Int4)Nlm_GetMuskCParamEd( MSM_TOPSTYLE,MSM_LABEL,MSM_STYLE );
432   switch ( val ) {
433     case MSM_LABEL_TOP:
434       SetValue ( g4, 1 ); break;
435     case MSM_LABEL_BOTTOM:
436       SetValue ( g4, 2 ); break;
437     case MSM_LABEL_LEFT:
438       SetValue ( g4, 3 ); break;
439     default:
440       SetValue ( g4, 4 );
441   }
442   AlignObjects ( ALIGN_MIDDLE, (HANDLE)g1, (HANDLE)g3, (HANDLE)g4, NULL );
443   g2 = HiddenGroup ( g, -2, 1, NULL );
444   StaticPrompt ( g2, "Alignment lines:   ", 0, 0, systemFont, 'l');
445   linePanel = SimplePanel ( g2, LINE_PANEL_W, LINE_PANEL_H, LinePanelDraw );
446   AlignObjects ( ALIGN_CENTER, (HANDLE)g1, (HANDLE)g2, NULL );
447   return g;
448 }
449 
450 void
Nlm_ToolDlgCommon(Int2 tools)451 /*FCN*/Nlm_ToolDlgCommon (
452   Int2 tools
453 ){
454   BigScalar val;
455   RecT      rp;
456 
457   Select (linePanel);  /* needed for Motif version - JK */
458   ResetClip();
459   switch ( tools ){
460     case SM_TOOLS_COLOR:
461       val = Nlm_GetToolValueSM (SM_TOOLS_COLOR);
462       Nlm_SetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_COLOR,val);
463       break;
464     case SM_TOOLS_LTYPE:
465       val = Nlm_GetToolValueSM (SM_TOOLS_LTYPE);
466       Nlm_SetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_LTYPE, val&0xFF );
467       Nlm_SetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_PENWIDTH, (val>>8)&0xFF );
468   }
469   ObjectRect ( linePanel, &rp );
470   InvalRect ( &rp );
471 }
472 
Nlm_SetTDefCommon(void)473 void  Nlm_SetTDefCommon (
474   void
475 ){
476   Nlm_SetToolDefaultSM  ( SM_TOOLS_COLOR,
477     Nlm_GetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_COLOR));
478   Nlm_SetToolDefaultSM  ( SM_TOOLS_LTYPE,
479     (Nlm_GetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_PENWIDTH) << 8) |
480     Nlm_GetMuskCParamEd(MSM_ALIGNMENT,MSM_ALINE,MSM_LTYPE) );
481   Nlm_ShowToolsSM ( SM_SHTOOLS_COLOR | SM_SHTOOLS_LTYPE );
482 }
483 
484 GrouP
Nlm_CreateDlgCColor(GrouP gTop)485 /*FCN*/Nlm_CreateDlgCColor (
486   GrouP gTop
487 ){
488   Int4     numColor;
489   GrouP    g, g1, g2;
490 
491   g = HiddenGroup ( gTop, -2,1, NULL);
492   SetGroupSpacing ( g, 10,1 );
493   SetGroupMargins  ( g, 20,10 );
494   numColor = (Int4)Nlm_GetMuskCParamEd(MSM_CCOLOR,MSM_NOSUBCLASS,MSM_NUM);
495   if ( (numColor <= 1)||(numColor >6) ) {
496     numColor = 2;
497     Nlm_SetMuskCParamEd(MSM_CCOLOR,MSM_NOSUBCLASS,MSM_NUM,(BigScalar)numColor);
498   }
499   g2 = HiddenGroup ( g, 1,2, NULL);
500   StaticPrompt ( g2, "Cycle colors: ", 0, 0, systemFont, 'l');
501   exPanel = SimplePanel ( g2, SM_PANEL_W, SM_PANEL_H, ExPanelDraw );
502   SetPanelClick ( exPanel, ExPanelClick, NULL, NULL, NULL );
503   g1 = NormalGroup ( g, 1, 5, "Period", systemFont, OnPeriod );
504   SetGroupMargins ( g1, 10, 1 );
505   RadioButton ( g1,"2" );
506   RadioButton ( g1,"3" );
507   RadioButton ( g1,"4" );
508   RadioButton ( g1,"5" );
509   RadioButton ( g1,"6" );
510   SetValue ( g1, numColor-1 );
511   AlignObjects ( ALIGN_MIDDLE, (HANDLE)g1, (HANDLE)g2, NULL );
512   return g;
513 }
514 
515 void
Nlm_ToolDlgCColor(Int2 tools)516 /*FCN*/Nlm_ToolDlgCColor (
517   Int2 tools
518 ){
519   Int4   val;
520   Int4   numColor;
521   WindoW tmpPort;
522   RecT   rp;
523   RecT   rDraw;
524   Int2   w;
525 
526   ResetClip();
527   tmpPort = SavePort (exPanel);
528   Select ( exPanel);
529   numColor = (Int4)Nlm_GetMuskCParamEd(MSM_CCOLOR,MSM_NOSUBCLASS,MSM_NUM);
530   ObjectRect ( exPanel, &rp );
531   w = (rp.right - rp.left)/numColor;
532   Solid();
533   LoadRect ( &rDraw, rp.left + w*activColor + 2, rp.top + 4,
534              rp.left + w*(activColor+1) - 2, rp.bottom - 4 );
535   val = (Int4)Nlm_GetToolValueSM (SM_TOOLS_COLOR);
536   Nlm_SetMuskCParamEd(MSM_CCOLOR,activColor+1,MSM_COLOR,(BigScalar)val);
537   SelectColor ( (Uint1)((val>>16)&0xFF), (Uint1)((val>>8)&0xFF),
538                 (Uint1)(val&0xFF) );
539   PaintRect ( &rDraw );
540   RestorePort ( tmpPort );
541 }
542 
Nlm_SetTDefCColor(void)543 void  Nlm_SetTDefCColor (
544   void
545 ){
546   Nlm_SetToolDefaultSM  ( SM_TOOLS_COLOR,
547     Nlm_GetMuskCParamEd(MSM_CCOLOR,activColor+1,MSM_COLOR));
548   Nlm_ShowToolsSM ( SM_SHTOOLS_COLOR );
549 }
550 
551 /* END */
552