home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume8
/
xfig2.8
/
part10
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-03
|
10KB
|
314 lines
/*
* FIG : Facility for Interactive Generation of figures
*
* Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
* 1st revision : Aug 1985.
*
* %W% %G%
*/
#include "fig.h"
#include "const.h"
#include "version.h"
#include "patchlevel.h"
#include "resources.h"
#include "font.h"
extern int ICON_COLUMN;
extern int CANVAS_HEIGHT, CANVAS_WIDTH;
extern int PANEL_WID, PANEL2_WID;
extern int SIDERULER_WIDTH, SIDERULER_HEIGHT;
extern int TOPRULER_WIDTH, TOPRULER_HEIGHT;
extern (*canvas_rightbut_proc)();
extern set_popupmenu();
extern int cur_areafill;
extern int print_landscape;
extern int size_button;
#include "fig.icon.X"
Pixmap fig_icon;
static char tool_name[100] = " FIG : FACILITY FOR INTERACTIVE GENERATION OF FIGURES ";
static sigwinched();
/************** FIG options ******************/
extern appresStruct appres;
TOOL tool;
char file_header[32] = "#FIG ";
static char *filename = NULL;
static Boolean true = True;
static Boolean false = False;
static int zero = 0;
static XtResource application_resources[] = {
{XtNjustify, XtCJustify, XtRBoolean, sizeof(Boolean),
XtOffset(appresPtr, RHS_PANEL), XtRBoolean, (caddr_t)&false},
{"landscape", XtCOrientation, XtRBoolean, sizeof(Boolean),
XtOffset(appresPtr, landscape), XtRBoolean, (caddr_t)&true},
{"debug", "Debug", XtRBoolean, sizeof(Boolean),
XtOffset(appresPtr, DEBUG), XtRBoolean, (caddr_t)&false},
{"pwidth", XtCWidth, XtRFloat, sizeof(float),
XtOffset(appresPtr, tmp_width), XtRInt, (caddr_t)&zero},
{"pheight", XtCHeight, XtRFloat, sizeof(float),
XtOffset(appresPtr, tmp_height), XtRInt, (caddr_t)&zero},
{XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof(Boolean),
XtOffset(appresPtr, INVERSE), XtRBoolean, (caddr_t)&false},
{"trackCursor", "Track", XtRBoolean, sizeof(Boolean),
XtOffset(appresPtr, TRACKING), XtRBoolean, (caddr_t)&true},
{"inches", "Inches", XtRBoolean, sizeof(Boolean),
XtOffset(appresPtr, INCHES), XtRBoolean, (caddr_t)&true},
{"boldFont", "BoldFont", XtRString, sizeof(char *),
XtOffset(appresPtr, boldFont), XtRString, (caddr_t)NULL},
{"normalFont", "NormalFont", XtRString, sizeof(char *),
XtOffset(appresPtr, normalFont), XtRString, (caddr_t)NULL},
};
static XrmOptionDescRec options[] =
{
{"-right", ".justify", XrmoptionNoArg, "True" },
{"-left", ".justify", XrmoptionNoArg, "False"},
{"-debug", ".debug", XrmoptionNoArg, "True"},
{"-landscape", ".landscape", XrmoptionNoArg, "True"},
{"-Landscape", ".landscape", XrmoptionNoArg, "True"},
{"-portrait", ".landscape", XrmoptionNoArg, "False"},
{"-Portrait", ".landscape", XrmoptionNoArg, "False"},
{"-pwidth", ".pwidth", XrmoptionSepArg, 0},
{"-pheight", ".pheight", XrmoptionSepArg, 0},
{"-inverse", ".reverseVideo", XrmoptionNoArg, "True"},
{"-notrack", ".trackCursor", XrmoptionNoArg, "False"},
{"-track", ".trackCursor", XrmoptionNoArg, "True"},
{"-inches", ".inches", XrmoptionNoArg, "True"},
{"-imperial", ".inches", XrmoptionNoArg, "True"},
{"-centimeters", ".inches", XrmoptionNoArg, "False"},
{"-metric", ".inches", XrmoptionNoArg, "False"},
{"-boldFont", ".boldFont", XrmoptionSepArg, 0},
{"-normalFont", ".normalFont", XrmoptionSepArg, 0},
};
static XtCallbackRec callbacks[] =
{
{ NULL, NULL },
};
static Arg form_args[] =
{
{ XtNcallback, (XtArgVal)callbacks },
{ XtNinput, (XtArgVal) TRUE },
{ XtNdefaultDistance, (XtArgVal) 1 },
};
main(argc,argv)
int argc;
char *argv[];
{
#define NCHILDREN 8
TOOL form, children[NCHILDREN];
Arg tmp_arg[4];
int ichild;
char tstr[10];
XWMHints *wmhints;
char i;
strcat(tool_name, " V. ");
strcat(tool_name, FIG_VERSION);
strcat(tool_name, " Protocol V. ");
strcat(tool_name, PROTOCOL_VERSION);
strcat(tool_name, " Patch Lev. ");
sprintf(tstr,"%d",PATCHLEVEL);
strcat(tool_name, tstr);
strcat(file_header, PROTOCOL_VERSION);
printf("Initializing FIG v%s Protocol v%s (X11 patchlevel %d) ... \n",
FIG_VERSION, PROTOCOL_VERSION, PATCHLEVEL);
tool = XtInitialize("fig", "Fig", options, XtNumber(options),
&argc, argv);
fix_converters();
XtGetApplicationResources(tool, &appres, application_resources,
10, NULL, 0 );
i=1;
while (argc-- > 1)
{
if (*argv[i] != '-') /* search for non - name */
{
filename = argv[i];
break;
}
i++;
}
print_landscape = appres.landscape; /* match print and screen format to start */
tool_d = XtDisplay(tool);
tool_s = XtScreen(tool);
tool_sn = DefaultScreen(tool_d);
/* run synchronously for debugging */
if (appres.DEBUG)
{
XSynchronize(tool_d, 1);
fprintf(stderr,"Debug mode, running synchronously\n");
}
if( CellsOfScreen(tool_s) == 2 && appres.INVERSE )
{
XrmValue value;
XrmDatabase newdb = (XrmDatabase) 0, old;
value.size = sizeof("White");
value.addr = "White";
XrmPutResource(&newdb, "xfig*borderColor", "String",
&value);
value.size = sizeof("White");
value.addr = "White";
XrmPutResource(&newdb, "xfig*foreground", "String",
&value);
value.size = sizeof("Black");
value.addr = "Black";
XrmPutResource(&newdb, "xfig*background", "String",
&value);
old = XtDatabase(tool_d);
XrmMergeDatabases(newdb, &old);
/* now set the tool part, since its already created */
XtSetArg(tmp_arg[0], XtNborderColor,
WhitePixelOfScreen(tool_s));
XtSetArg(tmp_arg[1], XtNforeground,
WhitePixelOfScreen(tool_s));
XtSetArg(tmp_arg[2], XtNbackground,
BlackPixelOfScreen(tool_s));
XtSetValues(tool, tmp_arg, 3);
}
init_font();
gc = DefaultGC(tool_d, tool_sn);
bold_gc = DefaultGC(tool_d, tool_sn);
/* set the roman and bold fonts for the message windows */
XSetFont(tool_d, gc, roman_font->fid);
XSetFont(tool_d, bold_gc, bold_font->fid);
init_cursor();
form = XtCreateManagedWidget("form", formWidgetClass, tool,
form_args, XtNumber(form_args));
if (size_button == 0)
size_button = DEF_PRINTFONTSIZE;
ICON_COLUMN = ICON_COLUMN_PORT;
CANVAS_WIDTH = appres.tmp_width * (appres.INCHES ? PIX_PER_INCH : PIX_PER_CM);
CANVAS_HEIGHT = appres.tmp_height * (appres.INCHES ? PIX_PER_INCH : PIX_PER_CM);
if( CANVAS_WIDTH == 0 )
CANVAS_WIDTH = appres.landscape ? DEF_CANVAS_WIDTH_L : DEF_CANVAS_WIDTH_P;
if( CANVAS_HEIGHT == 0 )
CANVAS_HEIGHT = appres.landscape ? DEF_CANVAS_HEIGHT_L : DEF_CANVAS_HEIGHT_P;
if( (CANVAS_HEIGHT < DEF_CANVAS_HEIGHT_P) ||
(HeightOfScreen(tool_s) < DEF_CANVAS_HEIGHT_P) )
ICON_COLUMN = ICON_COLUMN_LAND;
(void) init_panel(form);
(void) init_topruler(form) ;
(void) init_menu(form); /* command menu */
(void) init_canvas(form);
(void) init_fontmenu(form); /* printer font menu */
(void) init_sideruler(form);
(void) init_msg(form);
(void) init_panel2(form); /* second panel */
(void) init_indicator_panel(form); /* current line size, area fill, etc */
ichild = 0;
children[ichild++] = panel_sw;
children[ichild++] = topruler_sw;
children[ichild++] = psfont; /* shows current printer font name */
children[ichild++] = sideruler_sw; /* side ruler */
children[ichild++] = canvas_sw; /* main drawing canvas */
children[ichild++] = msg_sw; /* message window */
children[ichild++] = panel2_sw; /* lower button panel */
children[ichild++] = ind_box; /* fill/line/radius indicators */
/* until the following XtRealizeWidget() is called, there
are NO windows in existence */
XtManageChildren(children, NCHILDREN);
XtRealizeWidget(tool);
/* Set the input field to true to allow keyboard input */
wmhints = XGetWMHints(tool_d, XtWindow(tool));
wmhints->flags |= InputHint; /* add in input hint */
wmhints->input = True;
XSetWMHints(tool_d, XtWindow(tool),wmhints);
if( appres.RHS_PANEL ) /* side button panel is on right size */
{
XtSetArg(tmp_arg[0], XtNfromHoriz, 0);
XtSetArg(tmp_arg[1], XtNhorizDistance, RULER_WIDTH+2);
XtSetValues(topruler_sw, tmp_arg, 2);
XtSetArg(tmp_arg[0], XtNfromHoriz, 0);
XtSetArg(tmp_arg[1], XtNfromVert, topruler_sw);
XtSetArg(tmp_arg[2], XtNleft, XtChainLeft); /* chain to left of form */
XtSetArg(tmp_arg[3], XtNright, XtChainLeft);
XtSetValues(sideruler_sw, tmp_arg, 4);
XtUnmanageChild(msg_sw);
XtSetArg(tmp_arg[0], XtNfromHoriz, sideruler_sw);
XtSetArg(tmp_arg[1], XtNfromVert, topruler_sw);
XtSetValues(canvas_sw, tmp_arg, 2);
XtManageChild(msg_sw);
/* relocate the side button panel */
XtUnmanageChild(panel_sw);
XtSetArg(tmp_arg[0], XtNfromHoriz, canvas_sw); /* panel right of canvas */
XtSetArg(tmp_arg[1], XtNfromVert, 0);
XtSetArg(tmp_arg[2], XtNleft, XtChainRight); /* chain to right of form */
XtSetArg(tmp_arg[3], XtNright, XtChainRight);
XtSetValues(panel_sw, tmp_arg, 4);
XtManageChild(panel_sw);
/* relocate the indicator panel */
XtUnmanageChild(ind_box);
XtSetArg(tmp_arg[0], XtNfromHoriz, canvas_sw); /* right of canvas */
XtSetArg(tmp_arg[1], XtNleft, XtChainRight); /* chain to right of form */
XtSetArg(tmp_arg[2], XtNright, XtChainRight);
XtSetValues(ind_box, tmp_arg, 3);
XtManageChild(ind_box);
}
fig_icon = XCreateBitmapFromData(tool_d, XtWindow(tool),
fig_bits, fig_width, fig_height);
XtSetArg(tmp_arg[0], XtNtitle, tool_name);
XtSetArg(tmp_arg[1], XtNiconPixmap, fig_icon);
XtSetValues(tool, tmp_arg, 2);
init_gc();
init_fill_pm();
init_fill_gc();
show_fill_color();
#ifndef TFX
show_radius();
#endif
setup_panel();
setup_rulers();
setup_canvas();
setup_msg();
setup_fontmenu(); /* install bitmaps in printer font menu */
printer_select();
show_fontsize();
show_line_thickness();
put_msg("READY");
canvas_rightbut_proc = set_popupmenu;
if (filename != NULL)
edit_file(filename);
(void)signal(SIGINT, SIG_IGN); /* so we don't lose work accidentally */
XtMainLoop();
}