4
#include <X11/cursorfont.h>
5
#include <X11/Intrinsic.h>
7
#include <X11/StringDefs.h>
8
#include <X11/Xaw/Form.h>
9
#include <X11/Xaw/Label.h>
19
#include "libCalCom.h"
24
#define max(a,b) ((a) > (b) ? (a) : (b))
26
/* Table of messages known by xmetanet */
28
static void quitter_appli_msgact();
30
static void erreur_message_msgact();
32
static actions_messages tb_messages[]={
33
{ID_GeCI,MSG_QUITTER_APPLI,NBP_QUITTER_APPLI,quitter_appli_msgact},
34
{NULL,MSG_DISTRIB_LISTE_ELMNT,NBP_DISTRIB_LISTE_ELMNT,GetMsg},
35
{NULL,NULL,0,erreur_message_msgact}};
37
static void clock_tic();
39
static void PrintUsage();
41
extern void CreateMenus();
42
extern void InitMetanet();
43
extern void MakeDraw();
44
extern void GetFonts();
45
extern XFontStruct *FontSelect();
47
char metanetName[MAXNAM];
48
char *Version = "3.0.3";
64
int arrowLength = ARROWLENGTH;
65
int arrowWidth = ARROWWIDTH;
66
int bezierDy = BEZIERDY;
77
Pixel color[NUMCOLORS];
78
Dimension draw_height;
85
static XtResource app_resources[] = {
86
{"color0", "Color0", XtRPixel, sizeof(Pixel),
87
XtOffset(RESPTR, color[0]), XtRString, (caddr_t) "black"},
88
{"color1","Color1", XtRPixel, sizeof(Pixel),
89
XtOffset(RESPTR, color[1]), XtRString, (caddr_t) "navyblue"},
90
{"color2","Color2", XtRPixel, sizeof(Pixel),
91
XtOffset(RESPTR, color[2]), XtRString, (caddr_t) "blue"},
92
{"color3","Color3", XtRPixel, sizeof(Pixel),
93
XtOffset(RESPTR, color[3]), XtRString, (caddr_t) "skyblue"},
94
{"color4","Color4", XtRPixel, sizeof(Pixel),
95
XtOffset(RESPTR, color[4]), XtRString, (caddr_t) "aquamarine"},
96
{"color5","Color5", XtRPixel, sizeof(Pixel),
97
XtOffset(RESPTR, color[5]), XtRString, (caddr_t) "forestgreen"},
98
{"color6","Color6", XtRPixel, sizeof(Pixel),
99
XtOffset(RESPTR, color[6]), XtRString, (caddr_t) "green"},
100
{"color7","Color7", XtRPixel, sizeof(Pixel),
101
XtOffset(RESPTR, color[7]), XtRString, (caddr_t) "lightcyan"},
102
{"color8","Color8", XtRPixel, sizeof(Pixel),
103
XtOffset(RESPTR, color[8]), XtRString, (caddr_t) "cyan"},
104
{"color9","Color9", XtRPixel, sizeof(Pixel),
105
XtOffset(RESPTR, color[9]), XtRString, (caddr_t) "orange"},
106
{"color10","Color10", XtRPixel, sizeof(Pixel),
107
XtOffset(RESPTR, color[10]), XtRString, (caddr_t) "red"},
108
{"color11","Color11", XtRPixel, sizeof(Pixel),
109
XtOffset(RESPTR, color[11]), XtRString, (caddr_t) "magenta"},
110
{"color12","Color12", XtRPixel, sizeof(Pixel),
111
XtOffset(RESPTR, color[12]), XtRString, (caddr_t) "violet"},
112
{"color13","Color13", XtRPixel, sizeof(Pixel),
113
XtOffset(RESPTR, color[13]), XtRString, (caddr_t) "yellow"},
114
{"color14","Color14", XtRPixel, sizeof(Pixel),
115
XtOffset(RESPTR, color[14]), XtRString, (caddr_t) "gold"},
116
{"color15","Color15", XtRPixel, sizeof(Pixel),
117
XtOffset(RESPTR, color[15]), XtRString, (caddr_t) "beige"},
118
{"color16","Color16", XtRPixel, sizeof(Pixel),
119
XtOffset(RESPTR, color[16]), XtRString, (caddr_t) "white"},
120
{"drawHeight", "DrawHeight", XtRDimension, sizeof(Dimension),
121
XtOffset(RESPTR, draw_height), XtRImmediate, (caddr_t) DRAWHEIGHT},
122
{"drawWidth", "DrawWidth", XtRDimension, sizeof(Dimension),
123
XtOffset(RESPTR, draw_width), XtRImmediate, (caddr_t) DRAWWIDTH},
124
{"geometry", "Geometry", XtRString, sizeof(String),
125
XtOffset(RESPTR, geometry), NULL,NULL},
128
Widget toplevel, frame, metanetMenu, drawViewport, metanetDraw;
132
XtAppContext app_con;
134
void Destroyed(widget, closure, callData)
147
char title[2 * MAXNAM];
148
char icon[2 * MAXNAM];
153
sprintf(title,"%s Window %d",metanetName,theWindow);
154
sprintf(icon,"Net %d",theWindow);
156
sprintf(title,"%s",metanetName);
157
strcpy(icon,"Metanet");
162
sprintf(title,"%s Window %d Graph name: %s",
163
metanetName,theWindow,theGraph->name);
164
sprintf(icon,"Net %d",theWindow);
166
sprintf(title,"%s Graph name: %s",metanetName,theGraph->name);
167
strcpy(icon,"Metanet");
173
XtSetArg(args[iargs], XtNtitle, title); iargs++;
174
XtSetArg(args[iargs], XtNiconName, icon); iargs++;
175
XtSetValues(toplevel,args,iargs);
178
static String fallback_resources[] = {NULL,NULL};
186
extern void ActionWhenDownMove3();
187
extern void ActionWhenExpose();
188
extern void ActionWhenLeave();
189
extern void ActionWhenPress1();
190
extern void ActionWhenPress3();
191
extern void ActionWhenRelease3();
192
extern void ActionWhenReturn();
193
static XtActionsRec actionTable[] = {
194
{"ActionWhenDownMove3", (XtActionProc) ActionWhenDownMove3},
195
{"ActionWhenExpose", (XtActionProc) ActionWhenExpose},
196
{"ActionWhenLeave", (XtActionProc) ActionWhenLeave},
197
{"ActionWhenPress1", (XtActionProc) ActionWhenPress1},
198
{"ActionWhenPress3", (XtActionProc) ActionWhenPress3},
199
{"ActionWhenRelease3", (XtActionProc) ActionWhenRelease3},
200
{"ActionWhenReturn", (XtActionProc) ActionWhenReturn}
202
GC gc, gc_clear, gc_xor;
207
XFontStruct *fontstruct;
208
XColor x_fg_color,x_bg_color;
215
static char metanetgeom[200];
216
XSetWindowAttributes attributes;
218
unsigned int max_width,max_height;
219
int geom_x, geom_y, dw, dh;
220
XSizeHints sizehints;
224
/* Is xmetanet called by Scilab? */
226
igeci = find("-pipes",argc,argv);
228
init_messages(tb_messages, atoi(argv[igeci+1]),atoi(argv[igeci+2]));
230
for (i = igeci; i < argc - 3 ; i++) {
231
if (argv[i+3] != NULL) argv[i] = argv[i+3];
238
/* Parse arguments when called by Scilab */
241
sscanf(argv[2],"%d",&theWindow);
243
sscanf(argv[4],"%d",&dw);
244
sscanf(argv[5],"%d",&dh);
251
metaWidth = IMETAWIDTH;
252
metaHeight = IMETAHEIGHT;
254
metaWidth = METAWIDTH;
255
metaHeight = METAHEIGHT;
258
/* Fallback ressources */
260
sprintf(metanetgeom,"Metanet.geometry:+%d+%d",
261
X + DX * theWindow,Y + DY * theWindow);
262
fallback_resources[0]=metanetgeom;
264
/* Toplevel widget */
266
toplevel = XtAppInitialize(&app_con, (String)"Metanet", NULL, 0,
267
(int*)&argc, (String*)argv,
268
fallback_resources, NULL, 0);
271
XtGetApplicationResources(toplevel, &the_res, app_resources,
272
XtNumber(app_resources), NULL, 0);
274
if (dw == 0 && dh == 0) {
275
drawWidth = the_res.draw_width;
276
drawHeight = the_res.draw_height;
281
/* Minimum 100 x 100 for Metanet draw */
282
drawWidth = max(drawWidth,100);
283
drawHeight = max(drawHeight,100);
285
XParseGeometry(the_res.geometry,
286
&geom_x, &geom_y, &metaWidth, &metaHeight);
288
/* Parse xmetanet arguments */
293
if (!strcmp(argv[1],"-usage") || !strcmp(argv[1],"-help")) {
297
if (!strcmp(argv[1],"-version")) {
298
printf("Version %s\n",Version);
302
if (argc % 2 == 1) iniG = 0;
303
else iniG = argv[argc-1];
304
for (i = 1; i < argc - 1; i++) {
305
if (!strcmp(argv[i++],"-scale")) {
306
if (sscanf(argv[i],"%g",&v) > 0)
307
if (v > 0) iniS = (double)v;
310
fprintf(stderr,"Bad arguments\n");
318
XtAppAddTimeOut (app_con,
320
(XtTimerCallbackProc) clock_tic,
321
(XtPointer)toplevel) ;
324
XtAppAddActions(app_con,actionTable,XtNumber(actionTable));
326
sprintf(metanetName,"Metanet %s",Version);
330
dpy = XtDisplay(toplevel);
332
screen = DefaultScreen(dpy);
334
/* Dimension of xmetanet window */
336
dpyWidth = DisplayWidth(dpy,screen);
337
dpyHeight = DisplayHeight(dpy,screen);
339
max_width = (int)(dpyWidth * 0.8);
340
max_height = (int)(dpyHeight * 0.8);
342
if (max_width < metaWidth) metaWidth = max_width;
343
if (max_height < metaHeight) metaHeight = max_height;
346
XtSetArg( args[iargs], XtNheight, metaHeight); iargs++;
347
XtSetArg( args[iargs], XtNwidth, metaWidth); iargs++;
348
XtSetArg( args[iargs], XtNx, X); iargs++;
349
XtSetArg( args[iargs], XtNy, Y); iargs++;
350
XtSetArg( args[iargs], XtNdefaultDistance, 0); iargs++;
351
frame = XtCreateManagedWidget( "form", formWidgetClass, toplevel,
353
XtAddCallback(frame, XtNdestroyCallback, (XtCallbackProc)Destroyed, NULL );
355
if ((fontstruct = XLoadQueryFont(dpy, METAFONT)) == NULL) {
356
fprintf(stderr,"Font %s is unknown\n",METAFONT);
357
fprintf(stderr,"I'll use font: fixed\n");
358
if ((fontstruct = XLoadQueryFont(dpy, "fixed")) == NULL) {
359
fprintf(stderr,"Unknown font: fixed\n");
364
theG.metafont = fontstruct;
366
if ((fontstruct = XLoadQueryFont(dpy, HELPFONT)) == NULL) {
367
fprintf(stderr,"Font %s is unknown\n",HELPFONT);
368
fprintf(stderr,"I'll use font: fixed\n");
369
if ((fontstruct = XLoadQueryFont(dpy, "fixed")) == NULL) {
370
fprintf(stderr,"Unknown font: fixed\n");
375
theG.helpfont = fontstruct;
380
XtRealizeWidget(toplevel);
382
d = XtWindow(metanetDraw);
384
attributes.backing_store = Always;
385
XChangeWindowAttributes(dpy,d,CWBackingStore,&attributes);
387
/* Window Manager size hints */
388
sizehints.flags = PMinSize | USPosition | PPosition;
389
sizehints.x = X + DX * theWindow;
390
sizehints.y = Y + DY * theWindow;
391
sizehints.min_width = MINWIDTH;
392
sizehints.min_height = MINHEIGHT;
393
XSetNormalHints(dpy,XtWindow(toplevel),&sizehints);
395
/* get color pixels */
396
for (i = 0; i < NUMCOLORS - 2; i++) Colors[i+1] = the_res.color[i];
398
/* get foreground and background pixels and colors */
399
XtSetArg(args[0],XtNlabel,"");
400
look = XtCreateWidget("look", labelWidgetClass, toplevel, args, 1);
402
XtSetArg(args[0],XtNforeground, &x_fg_color.pixel);
403
XtSetArg(args[1],XtNbackground, &x_bg_color.pixel);
404
XtGetValues(look,args,2);
405
fg = x_fg_color.pixel;
406
bg = x_bg_color.pixel;
408
Colors[NUMCOLORS-1] = bg;
410
XtDestroyWidget(look);
414
fontstruct = FontSelect(DRAWFONTSIZE);
415
gcv.font = fontstruct->fid;
419
gcv.function = GXcopy;
420
gc = XCreateGC(dpy,d,
421
(GCFont | GCForeground | GCBackground | GCFunction),&gcv);
426
gcv.function = GXcopy;
427
gc_clear = XCreateGC(dpy,d,
428
(GCFont | GCForeground | GCBackground | GCFunction),
432
gcv.foreground = fg ^ bg;
434
gcv.function = GXxor;
436
gc_xor = XCreateGC(dpy,d,(GCForeground | GCBackground | GCFunction),&gcv);
438
XDefineCursor(dpy,d,XCreateFontCursor(dpy,XC_draft_small));
444
theG.gc_clear = gc_clear;
445
theG.gc_xor = gc_xor;
446
theG.drawfont = fontstruct;
451
InitMetanet(iniG,iniS);
453
XtMapWidget(toplevel);
455
XtAppMainLoop(app_con);
460
static void clock_tic(client_data,id)
461
XtPointer client_data;
465
XtAppAddTimeOut (app_con,
467
(XtTimerCallbackProc) clock_tic,
468
(XtPointer)toplevel);
471
static void erreur_message_msgact(message)
474
fprintf(stderr, "Message recu incorrect !!!\n");
475
envoyer_message_parametres_var(ID_GeCI, MSG_FIN_APPLI, NULL);
479
static void quitter_appli_msgact(message)
485
static int find(s,n,t)
492
if (!strcmp(s,t[i])) return(i);
496
static void PrintUsage()
498
printf("Usage: xmetanet [OPTION]... GRAPH_FILE");
503
XtUnmapWidget(toplevel);
507
void GetMetanetGeometry(x,y,w,h)
510
Window root,parent,*children;
511
unsigned int nchildren;
512
XWindowAttributes war;
513
XQueryTree(theG.dpy,XtWindow(toplevel),&root,&parent,&children,&nchildren);
514
if (parent != root) XGetWindowAttributes(theG.dpy,parent,&war);
515
else XGetWindowAttributes(theG.dpy,XtWindow(toplevel),&war);
516
*h = war.height; *w = war.width; *x = war.x; *y = war.y;