2
* ===========================================================================
5
* National Center for Biotechnology Information (NCBI)
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
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
24
* ===========================================================================
26
* File Name: smtools.c
28
* Author: Alex Smirnov
30
* Version Creation Date: 8/10/95
37
* --------------------------------------------------------------------------
38
* Date Name Description of modification
39
* ------- ---------- -----------------------------------------------------
42
* ==========================================================================
45
/**************************************************************************/
47
/**************************************************************************/
53
/**************************************************************************/
55
/**************************************************************************/
56
#define INPANEL_COLOR 0
57
#define INPANEL_SHADDING 1
58
#define INPANEL_LTYPE 2
59
#define INIT_FONTSET 6
61
/**************************************************************************/
63
/**************************************************************************/
70
typedef void (*Nlm_InPanelDraw) (Int2 x, Int2 y, Int2 w, Int2 h,
72
typedef void (*Nlm_InPanelChange) (void);
81
Nlm_InPanelChange change;
82
} Nlm_InterPanel, PNTR Nlm_InterPanelPtr;
90
typedef struct s_AddFontList {
91
struct s_AddFontList PNTR next;
93
} Nlm_AddFontList, PNTR Nlm_AddFontListPtr;
95
static void colorDraw (Int2 x,Int2 y,Int2 w,Int2 h,Int2 i,Int2 j);
96
static void shaddingDraw (Int2 x,Int2 y,Int2 w,Int2 h,Int2 i,Int2 j);
97
static void lTypeDraw (Int2 x,Int2 y,Int2 w,Int2 h,Int2 i,Int2 j);
98
static void colorChg (void);
99
static void shaddingChg (void);
100
static void lTypeChg (void);
102
/**************************************************************************/
103
/* STATIC VARIABLE */
104
/**************************************************************************/
105
static Nlm_ToolNode tools[SM_TOOLS_TOTAL];
106
static Nlm_SmToolsProc curProc = NULL;
107
static LisT fontList = NULL;
110
static Nlm_FontSpec fontNames[INIT_FONTSET] = {
111
{"Geneva", 9, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_SWISS},
112
{"Times", 9, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_ROMAN},
113
{"Monaco", 9, STYLE_REGULAR, CHARSET_ANSI, PITCH_FIXED, FAMILY_MODERN},
114
{"Geneva", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_SWISS},
115
{"Times", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_ROMAN},
116
{"Monaco", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_FIXED, FAMILY_MODERN} };
119
static Nlm_FontSpec fontNames[INIT_FONTSET] = {
120
{"Arial", 9, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_SWISS},
121
{"Times", 9, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_ROMAN},
122
{"Courier New", 9, STYLE_REGULAR, CHARSET_ANSI, PITCH_FIXED, FAMILY_MODERN},
123
{"Arial", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_SWISS},
124
{"Times", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_ROMAN},
125
{"Courier New", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_FIXED, FAMILY_MODERN}};
128
static Nlm_FontSpec fontNames[INIT_FONTSET] = {
129
{"helvetica", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_SWISS},
130
{"times", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_ROMAN},
131
{"courier", 12, STYLE_REGULAR, CHARSET_ANSI, PITCH_FIXED, FAMILY_MODERN},
132
{"helvetica", 14, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_SWISS},
133
{"times", 14, STYLE_REGULAR, CHARSET_ANSI, PITCH_VARIABLE, FAMILY_ROMAN},
134
{"courier", 14, STYLE_REGULAR, CHARSET_ANSI, PITCH_FIXED, FAMILY_MODERN}};
137
static Nlm_AddFontListPtr addFontList = NULL;
140
static NLMINTERNALCOLOR theBasicColors[16] = {
141
{128,128,128},{255,255,255},{255,0 ,0 },{0 ,255,0 },
142
{0 ,0 ,255},{255,255,0 },{255,0 ,255},{0 ,255,255},
143
{0 ,0 ,0 },{192,192,192},{128,0 ,0 },{0 ,128,0 },
144
{0 ,0 ,128},{128,128,0 },{128,0 ,128},{0 ,128,128} };
146
static Nlm_InterPanel interPanels [] = {
147
{(PaneL)0, 16, 12, 8, 2, 0, 0, colorDraw, colorChg },
148
{(PaneL)0, 20, 24, 2, 2, 0, 0, shaddingDraw, shaddingChg },
149
{(PaneL)0, 40, 15, 2, 3, 0, 0, lTypeDraw, lTypeChg }
152
/**************************************************************************/
153
/* STATIC FUNCTION */
154
/**************************************************************************/
166
LoadRect ( &rdraw, x, y, x+w, y+h );
167
SelectColor ( theBasicColors[j*8+i].red,
168
theBasicColors[j*8+i].green,
169
theBasicColors[j*8+i].blue );
170
PaintRect ( &rdraw );
172
FrameRect ( &rdraw );
181
i = interPanels[INPANEL_COLOR].cury * 8 +
182
interPanels[INPANEL_COLOR].curx;
183
tools[SM_TOOLS_COLOR].val =
184
((BigScalar)theBasicColors[i].red << 16) |
185
((BigScalar)theBasicColors[i].green << 8) |
186
((BigScalar)theBasicColors[i].blue);
187
if ( curProc != NULL ) curProc (SM_TOOLS_COLOR);
191
/*FCN*/shaddingDraw (
201
LoadRect ( &rdraw, x, y, x+w, y+h );
213
PaintRect ( &rdraw );
214
FrameRect ( &rdraw );
223
i = interPanels[INPANEL_SHADDING].cury * 2 +
224
interPanels[INPANEL_SHADDING].curx;
227
i = SOLID_SHADING; break;
229
i = DARK_SHADING; break;
231
i = MEDIUM_SHADING; break;
235
tools[SM_TOOLS_SHADDING].val = (BigScalar)i;
236
if ( curProc != NULL ) curProc (SM_TOOLS_SHADDING);
250
pt1.x = x+1 ; pt2.x = x+w-2;
251
pt1.y = pt2.y = y + h/2;
265
WidePen ( 2 ); break;
268
WidePen ( 3 ); break;
271
WidePen ( 4 ); break;
273
DrawLine ( pt1, pt2 );
282
i = interPanels[INPANEL_LTYPE].curx * 3 +
283
interPanels[INPANEL_LTYPE].cury;
286
i = 0x100 | SOLID_LINE; break;
288
i = 0x100 | DOTTED_LINE; break;
290
i = 0x100 | DASHED_LINE; break;
292
i = 0x200 | SOLID_LINE; break;
294
i = 0x300 | SOLID_LINE; break;
296
i = 0x400 | SOLID_LINE; break;
298
tools[SM_TOOLS_LTYPE].val = (BigScalar)i;
299
if ( curProc != NULL ) curProc (SM_TOOLS_LTYPE);
303
/*FCN*/InPanelCursor (
304
Nlm_InterPanelPtr pInfo,
310
if ( pInfo->curx >= 0 ){
315
x = rpPtr->left + pInfo->curx*(pInfo->width+4);
316
y = rpPtr->top + pInfo->cury*(pInfo->height+4),
317
LoadRect ( &rdraw, x, y,
318
x+pInfo->width+4, y+pInfo->height+4 );
319
FrameRect ( &rdraw );
325
/*FCN*/InPanelClick (
330
Nlm_InterPanelPtr pInfo;
334
pInfo = &(interPanels[0]);
335
while ( pInfo->p != p ) pInfo++;
336
Nlm_ObjectRect (p, &rp);
339
x /= pInfo->width + 4;
340
y /= pInfo->height + 4;
341
if ( (x < 0) || (y < 0) ||
342
(x >= pInfo->x) || (y >= pInfo->y) ||
343
((pInfo->curx == x) && (pInfo->cury == y)) ) return;
344
InPanelCursor ( pInfo, &rp );
347
InPanelCursor ( pInfo, &rp );
349
} /* End of InPanelClick() */
355
Nlm_InterPanelPtr pInfo;
360
pInfo = &(interPanels[0]);
361
while ( pInfo->p != p ) pInfo++;
362
for ( i=0; i<pInfo->x; i++ ){
363
for ( j=0; j<pInfo->y; j++ ){
364
pInfo->draw ( rp.left + 2 + i*(pInfo->width+4),
365
rp.top + 2 + j*(pInfo->height+4),
366
pInfo->width, pInfo->height,
370
InPanelCursor( pInfo, &rp );
375
Nlm_InterPanelPtr pInfo,
382
if ( (curx != pInfo->curx) || (cury != pInfo->cury) ){
384
tmpPort = SavePort (pInfo->p);
386
ObjectRect ( pInfo->p, &rp);
387
InPanelCursor ( pInfo, &rp );
390
InPanelCursor ( pInfo, &rp );
391
RestorePort (tmpPort);
398
Nlm_InterPanelPtr pInfo
400
SetGroupMargins (g, 10, 10 );
401
pInfo->p = SimplePanel ( g, pInfo->x * (pInfo->width + 4),
402
pInfo->y * (pInfo->height + 4),
404
SetPanelClick ( pInfo->p, InPanelClick, NULL, NULL, NULL );
405
} /* End of InPanel () */
408
/*FCN*/Nlm_FontList (
411
Nlm_AddFontListPtr addFontPtr;
415
Nlm_Boolean upd = FALSE;
416
Nlm_Char fullFontName[64];
418
val = Nlm_GetValue (lst) - 1;
419
if ( (val >= 0) && (tools[SM_TOOLS_FONT].val != (BigScalar)NULL) ){
421
fsp = *((Nlm_FontSpecPtr)tools[SM_TOOLS_FONT].val);
423
if ( Nlm_ChooseFont ( &fsp, CFF_READ_FSP, NULL) ) {
425
fsp.name[FONT_NAME_SIZE-1] = 0;
426
*((Nlm_FontSpecPtr)tools[SM_TOOLS_FONT].val) = fsp;
427
for ( i=0; i<INIT_FONTSET; i++ ){
428
if ( Nlm_EqualFontSpec ( &fsp, &(fontNames[i]) ) ) break;
430
if ( i == INIT_FONTSET ){
431
addFontPtr = addFontList;
432
while ( addFontPtr != NULL ) {
433
if ( Nlm_EqualFontSpec ( &fsp, &(addFontPtr->fsp) ) ) break;
434
addFontPtr = addFontPtr->next;
436
if ( addFontPtr == NULL ){
437
sprintf ( fullFontName, "%s %d ", fsp.name, fsp.size );
438
if ( fsp.style & STYLE_BOLD ) StringCat ( fullFontName, "b" );
439
if ( fsp.style & STYLE_ITALIC ) StringCat ( fullFontName, "i" );
440
if ( fsp.style & STYLE_UNDERLINE ) StringCat ( fullFontName, "u" );
441
ListItem ( lst, fullFontName );
442
addFontPtr = addFontList;
443
if ( addFontPtr == NULL ) {
444
addFontList = addFontPtr = MemNew ( sizeof(Nlm_AddFontList) );
446
while ( addFontPtr->next != NULL ) addFontPtr = addFontPtr->next;
447
addFontPtr->next = MemNew ( sizeof(Nlm_AddFontList) );
448
addFontPtr = addFontPtr->next;
450
addFontPtr->next = NULL;
451
addFontPtr->fsp = fsp;
458
} else if ( val <= INIT_FONTSET ) {
459
*((Nlm_FontSpecPtr)tools[SM_TOOLS_FONT].val) = fontNames[val-1];
463
addFontPtr = addFontList;
465
addFontPtr = addFontPtr->next;
468
*((Nlm_FontSpecPtr)tools[SM_TOOLS_FONT].val) = addFontPtr->fsp;
471
if ( upd && (curProc != NULL) ) curProc ( SM_TOOLS_FONT );
476
/*FCN*/OnCustomColor (
482
color = (Uint4)tools[SM_TOOLS_COLOR].val;
483
r = (Uint1)(color >> 16 ) & 0xFF;
484
g = (Uint1)(color >> 8 ) & 0xFF;;
485
b = (Uint1)color & 0xFF;
487
if ( Nlm_ChooseColorDialog ( &r,&g,&b, TRUE ) ){
489
tools[SM_TOOLS_COLOR].val = (BigScalar)
490
(((Uint4)r << 16) | ((Uint4)g << 8) | (Uint4)b);
491
InPanelSet ( &(interPanels[INPANEL_COLOR]), -1, 0 );
492
if ( curProc != NULL ) curProc (SM_TOOLS_COLOR);
498
/**************************************************************************/
499
/* GLOBAL FUNCTIONS */
500
/**************************************************************************/
502
/*FCN*/Nlm_CtreateToolsSM (
507
Nlm_Char fullFontName[32];
509
g1 = HiddenGroup ( w, 4, 1, NULL );
510
SetGroupSpacing (g1, 10, 0);
511
tools[SM_TOOLS_COLOR].g = NormalGroup ( g1 ,-1, 2,"Color", systemFont, NULL);
512
InPanel ( tools[SM_TOOLS_COLOR].g, &(interPanels[INPANEL_COLOR]) );
513
AlignObjects ( ALIGN_CENTER,
514
(HANDLE)PushButton ( tools[SM_TOOLS_COLOR].g, "Other...", OnCustomColor ),
515
(HANDLE)interPanels[INPANEL_COLOR].p, NULL);
517
tools[SM_TOOLS_SHADDING].g =
518
NormalGroup ( g1 ,1, 1,"Shading", systemFont, NULL);
519
InPanel ( tools[SM_TOOLS_SHADDING].g, &(interPanels[INPANEL_SHADDING]));
521
tools[SM_TOOLS_LTYPE].g =
522
NormalGroup ( g1 ,1, 1,"Line Type", systemFont, NULL);
523
InPanel ( tools[SM_TOOLS_LTYPE].g, &(interPanels[INPANEL_LTYPE]) );
525
tools[SM_TOOLS_FONT].g =
526
NormalGroup ( g1 ,1, 1,"Font", systemFont, NULL);
528
fontList = SingleList ( tools[SM_TOOLS_FONT].g, 12, 4, Nlm_FontList );
530
fontList = SingleList ( tools[SM_TOOLS_FONT].g, 8, 4, Nlm_FontList );
532
ListItem ( fontList, "Other..." );
533
for ( i=0; i<INIT_FONTSET; i++ ) {
534
sprintf ( fullFontName, "%s %d", fontNames[i].name, fontNames[i].size );
535
ListItem ( fontList, fullFontName );
537
Nlm_ShowToolsSM ( 0 );
542
/*FCN*/Nlm_SetToolsCallbackSM (
549
/*FCN*/Nlm_SetToolDefaultSM (
553
tools[tool].val = val;
557
/*FCN*/Nlm_GetToolValueSM (
560
return tools[tool].val;
564
/*FCN*/Nlm_ShowToolsSM (
567
Nlm_FontSpecPtr valfsp;
568
Nlm_AddFontListPtr addFontPtr;
571
NLMINTERNALCOLOR color;
573
if ( show_tools & SM_SHTOOLS_COLOR ){
574
Enable (tools[SM_TOOLS_COLOR].g);
575
val = (Int4)tools[SM_TOOLS_COLOR].val;
576
color.red = (Uint1)((val>>16)&0xFF);
577
color.green = (Uint1)((val>>8)&0xFF);
578
color.blue = (Uint1)(val&0xFF);
579
for ( cury=0; cury<2; cury++ ){
580
for ( curx=0; curx<8; curx++ ){
582
if ( (color.red == theBasicColors[i].red) &&
583
(color.green == theBasicColors[i].green) &&
584
(color.blue == theBasicColors[i].blue)) break;
586
if ( curx != 8 ) break;
588
if ( cury == 2 ) curx = -1;
589
InPanelSet ( &(interPanels[INPANEL_COLOR]), curx, cury );
590
} else Disable (tools[SM_TOOLS_COLOR].g);
591
if ( show_tools & SM_SHTOOLS_SHADDING ){
592
Enable (tools[SM_TOOLS_SHADDING].g);
593
val = (Int4)tools[SM_TOOLS_SHADDING].val;
596
curx = 1; cury = 0; break;
598
curx = 0; cury = 1; break;
600
curx = 1; cury = 1; break;
604
InPanelSet ( &(interPanels[INPANEL_SHADDING]), curx, cury );
605
} else Disable (tools[SM_TOOLS_SHADDING].g);
606
if ( show_tools & SM_SHTOOLS_LTYPE ){
607
Enable (tools[SM_TOOLS_LTYPE].g);
608
val = (Int4)tools[SM_TOOLS_LTYPE].val;
610
case (0x100 | DOTTED_LINE):
611
curx = 0; cury = 1; break;
612
case (0x100 | DASHED_LINE):
613
curx = 0; cury = 2; break;
614
case (0x200 | SOLID_LINE):
615
curx = 1; cury = 0; break;
616
case (0x300 | SOLID_LINE):
617
curx = 1; cury = 1; break;
618
case (0x400 | SOLID_LINE):
619
curx = 1; cury = 2; break;
623
InPanelSet ( &(interPanels[INPANEL_LTYPE]), curx, cury );
624
} else Disable (tools[SM_TOOLS_LTYPE].g);
625
if ( show_tools & SM_SHTOOLS_FONT ){
626
Hide(tools[SM_TOOLS_FONT].g);
627
Enable (tools[SM_TOOLS_FONT].g);
628
valfsp = (Nlm_FontSpecPtr)tools[SM_TOOLS_FONT].val;
630
if ( valfsp != NULL ) {
631
for ( i=0; i<INIT_FONTSET; i++ ){
632
if ( EqualFontSpec ( valfsp, &(fontNames[i])) ){
636
if ( i == INIT_FONTSET ){
637
addFontPtr = addFontList;
638
while ( addFontPtr != NULL ) {
639
if ( Nlm_EqualFontSpec ( valfsp, &(addFontPtr->fsp) ) ) break;
640
addFontPtr = addFontPtr->next;
643
if ( addFontPtr == NULL ) i = -1;
647
SetValue(fontList, i);
648
Show(tools[SM_TOOLS_FONT].g);
649
} else Disable (tools[SM_TOOLS_FONT].g);