1 /* $Id$ $Revision$ */ 2 /* vim:set shiftwidth=4 ts=8: */ 3 4 /************************************************************************* 5 * Copyright (c) 2011 AT&T Intellectual Property 6 * All rights reserved. This program and the accompanying materials 7 * are made available under the terms of the Eclipse Public License v1.0 8 * which accompanies this distribution, and is available at 9 * http://www.eclipse.org/legal/epl-v10.html 10 * 11 * Contributors: See CVS logs. Details at http://www.graphviz.org/ 12 *************************************************************************/ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /* Lefteris Koutsofios - AT&T Labs Research */ 19 20 #ifndef _G_H 21 #define _G_H 22 #ifdef FEATURE_X11 23 #include <X11/Intrinsic.h> 24 #include <X11/StringDefs.h> 25 #include <X11/Shell.h> 26 #include <X11/cursorfont.h> 27 #include <X11/Xaw/Viewport.h> 28 #include <X11/Xaw/Text.h> 29 #include <X11/Xaw/AsciiText.h> 30 #include <X11/Xaw/Command.h> 31 #include <X11/Xaw/Dialog.h> 32 #include <X11/Xaw/SimpleMenu.h> 33 #include <X11/Xaw/SmeBSB.h> 34 #include <X11/Xmu/CurUtil.h> 35 #ifdef FEATURE_GMAP 36 #ifdef FEATURE_MESAGL 37 #include <GL/GLwDrawA.h> 38 #else 39 #include <X11/GLw/GLwDrawA.h> 40 #endif 41 #include <Performer/pf.h> 42 #endif 43 #endif 44 45 /* general coordinate structures */ 46 47 typedef struct Gxy_t { 48 double x, y; 49 } Gxy_t; 50 typedef Gxy_t Gpoint_t; 51 typedef Gxy_t Gsize_t; 52 typedef struct Grect_t { 53 Gxy_t o, c; 54 } Grect_t; 55 56 /* textline structure */ 57 typedef struct Gtextline_t { 58 char *p; 59 int n, j; 60 int w, h; 61 } Gtextline_t; 62 63 /* Color structure */ 64 65 typedef struct Gcolor_t { 66 int index; 67 int r, g, b; 68 } Gcolor_t; 69 #define G_MAXCOLORS 256 70 71 /* event structures */ 72 73 /* event consumption modes */ 74 #define G_ONEEVENT 0 75 #define G_MANYEVENTS 1 76 77 /* event types and main structure */ 78 #define G_MOUSE 0 79 #define G_KEYBD 1 80 81 #define G_DOWN 0 82 #define G_UP 1 83 #define G_MOVE 2 84 #define G_LEFT 0 85 #define G_MIDDLE 1 86 #define G_RIGHT 2 87 #define G_BUTTON3 3 88 #define G_BUTTON4 4 89 typedef struct Gevent_t { 90 int type; 91 int wi; 92 int code; 93 int data; 94 Gpoint_t p; 95 } Gevent_t; 96 97 /* Widgets */ 98 99 /* minimum widget sizes */ 100 #define MINVWSIZE 100 101 #define MINTWSIZE 40 102 #define MINBWSIZE 40 103 #define MINLWSIZE 25 104 #define MINAWSIZE 25 105 #define MINSWSIZE 40 106 #define MINCWSIZE 100 107 #define MINPWSIZE 100 108 109 /* gfx attributes for the [p]canvas widget */ 110 111 /* drawing styles */ 112 #define G_SOLID 0 113 #define G_DASHED 1 114 #define G_DOTTED 2 115 #define G_LONGDASHED 3 116 #define G_SHORTDASHED 4 117 118 /* drawing modes */ 119 #ifdef FEATURE_X11 120 #define G_SRC GXcopy 121 #define G_XOR GXxor 122 #else 123 #ifdef FEATURE_WIN32 124 #define G_SRC R2_COPYPEN 125 #define G_XOR R2_NOT 126 #else 127 #define G_SRC 0 128 #define G_XOR 1 129 #endif 130 #endif 131 132 /* gfx attributes and the attribute structure */ 133 #define G_GATTRCOLOR 1 134 #define G_GATTRWIDTH 2 135 #define G_GATTRMODE 4 136 #define G_GATTRFILL 8 137 #define G_GATTRSTYLE 16 138 139 typedef struct Ggattr_t { 140 int flags; 141 int color; 142 int width; 143 int mode; 144 int fill; 145 int style; 146 } Ggattr_t; 147 148 /* widget attributes structures */ 149 150 #define G_ATTRTYPEINT 0 151 #define G_ATTRTYPELONG 1 152 #define G_ATTRTYPEFLOAT 2 153 #define G_ATTRTYPEDOUBLE 3 154 #define G_ATTRTYPETEXT 4 155 #define G_ATTRTYPEPOINT 5 156 #define G_ATTRTYPESIZE 6 157 #define G_ATTRTYPERECT 7 158 #define G_ATTRTYPECOLOR 8 159 #define G_ATTRTYPEFUNC 9 160 #define G_ATTRTYPEULONG 10 161 162 typedef struct Gwattrmap_t { 163 int id; 164 int type; 165 char *name; 166 } Gwattrmap_t; 167 typedef struct Gwattr_t { 168 int id; 169 union { 170 int i; 171 long l; 172 float f; 173 double d; 174 char *t; 175 Gpoint_t p; 176 Gsize_t s; 177 Grect_t r; 178 Gcolor_t c; 179 void *func; 180 uint64_t u; 181 } u; 182 } Gwattr_t; 183 typedef struct Gwlist_t { 184 int wid; 185 char *wname; 186 int *attrid; 187 } Gwlist_t; 188 189 /* attribute ids */ 190 #define G_ATTRORIGIN 0 191 #define G_ATTRSIZE 1 192 #define G_ATTRBORDERWIDTH 2 193 #define G_ATTRNAME 3 194 #define G_ATTRTEXT 4 195 #define G_ATTRAPPENDTEXT 5 196 #define G_ATTRSELECTION 6 197 #define G_ATTRCURSOR 7 198 #define G_ATTRMODE 8 199 #define G_ATTRLAYOUT 9 200 #define G_ATTRZORDER 10 201 #define G_ATTRCOLOR 11 202 #define G_ATTRVIEWPORT 12 203 #define G_ATTRWINDOW 13 204 #define G_ATTRWINDOWID 14 205 #define G_ATTRCHILDCENTER 15 206 #define G_ATTRNEWLINECB 16 207 #define G_ATTRRESIZECB 17 208 #define G_ATTRBUTTONCB 18 209 #define G_ATTREVENTCB 19 210 #define G_ATTRUSERDATA 20 211 212 /* array widget structs */ 213 typedef struct Gawcarray_t { 214 #ifdef FEATURE_X11 215 Widget w; 216 #else 217 #ifdef FEATURE_WIN32 218 HWND w; 219 #else 220 int w; 221 #endif 222 #endif 223 int flag; 224 int ox, oy, sx, sy, bs; 225 } Gawcarray_t; 226 #define AWCARRAYINCR 10 227 #define AWCARRAYSIZE sizeof (Gawcarray_t) 228 229 #define G_AWHARRAY 1 230 #define G_AWVARRAY 2 231 typedef struct Gawdata_t { 232 int type; 233 int sx, sy; 234 Gawcarray_t *carray; 235 int cj, cn; 236 #ifdef FEATURE_WIN32 237 int batchmode, working; 238 #endif 239 } Gawdata_t; 240 241 /* query widget macros */ 242 #define G_QWSTRING 1 /* string query */ 243 #define G_QWFILE 2 /* file query */ 244 #define G_QWCHOICE 3 /* choose 1 query */ 245 #define G_QWMODES 3 /* total number of modes */ 246 247 /* widget callbacks */ 248 typedef void (*Gtwnewlinecb) (int, char *); 249 typedef void (*Gbuttoncb) (int, void *); 250 typedef void (*Glabelcb) (Gevent_t *); 251 typedef void (*Gcanvascb) (Gevent_t *); 252 typedef void (*Gawordercb) (void *, Gawdata_t *); 253 typedef void (*Gawcoordscb) (int, Gawdata_t *); 254 typedef void (*Gviewcb) (Gevent_t *); 255 256 #define G_ARRAYWIDGET 0 257 #define G_BUTTONWIDGET 1 258 #define G_CANVASWIDGET 2 259 #define G_LABELWIDGET 3 260 #define G_MENUWIDGET 4 261 #define G_PCANVASWIDGET 5 262 #define G_QUERYWIDGET 6 263 #define G_SCROLLWIDGET 7 264 #define G_TEXTWIDGET 8 265 #define G_VIEWWIDGET 9 266 #define G_WTYPESIZE 10 267 268 /* predefined widgets */ 269 270 /* --- array --- */ 271 typedef struct Gaw_t { 272 Gawcoordscb func; 273 int mode; 274 #ifdef FEATURE_WIN32 275 Gawdata_t data; 276 #endif 277 } Gaw_t; 278 #define AWSIZE sizeof (Gaw_t) 279 280 /* --- button --- */ 281 typedef struct Gbw_t { 282 Gbuttoncb func; 283 } Gbw_t; 284 #define BWSIZE sizeof (Gbw_t) 285 286 /* --- canvas --- */ 287 typedef struct Gcw_t { 288 int needredraw; 289 int buttonsdown; 290 char bstate[5]; 291 struct Gcwcolor_t { 292 int inuse; 293 #ifdef FEATURE_X11 294 XColor color; 295 #else 296 #ifdef FEATURE_WIN32 297 PALETTEENTRY color; 298 #endif 299 #endif 300 } colors[G_MAXCOLORS]; 301 char allocedcolor[2]; 302 Ggattr_t gattr, defgattr; 303 Grect_t wrect; 304 Gsize_t vsize; 305 Grect_t clip; 306 Gcanvascb func; 307 #ifdef FEATURE_X11 308 Window window; 309 Colormap cmap; 310 GC gc; 311 Pixmap grays[17]; 312 XFontStruct *font; 313 #else 314 #ifdef FEATURE_WIN32 315 HPALETTE cmap; 316 HDC gc; 317 HBRUSH grays[17]; 318 HFONT font; 319 int ncolor; 320 #endif 321 #endif 322 #ifdef FEATURE_GMAP 323 int gmapmode; 324 #endif 325 } Gcw_t; 326 #define CWSIZE sizeof (Gcw_t) 327 328 /* --- label --- */ 329 typedef struct Glw_t { 330 Glabelcb func; 331 } Glw_t; 332 #define LWSIZE sizeof (Glw_t) 333 334 /* --- menu --- */ 335 typedef struct Gmw_t { 336 long count; 337 } Gmw_t; 338 #define MWSIZE sizeof (Gmw_t) 339 340 /* --- postscript --- */ 341 typedef struct Gpw_t { 342 #ifdef FEATURE_X11 343 FILE *fp; 344 struct Gpwcolor_t { 345 int inuse; 346 int r, g, b; 347 double nr, ng, nb; 348 } colors[G_MAXCOLORS]; 349 Ggattr_t gattr, defgattr; 350 Grect_t wrect; 351 Gsize_t vsize; 352 #else 353 #ifdef FEATURE_WIN32 354 struct Gpwcolor_t { 355 int inuse; 356 PALETTEENTRY color; 357 } colors[G_MAXCOLORS]; 358 Ggattr_t gattr, defgattr; 359 Grect_t wrect; 360 Gsize_t vsize; 361 HPALETTE cmap; 362 HDC gc; 363 HBRUSH grays[17]; 364 HFONT font; 365 int ncolor, mode; 366 #else 367 int dummy; 368 #endif 369 #endif 370 } Gpw_t; 371 #define PWSIZE sizeof (Gpw_t) 372 373 /* --- query --- */ 374 typedef struct Gqw_t { 375 #ifdef FEATURE_X11 376 Widget w; 377 #else 378 #ifdef FEATURE_WIN32 379 HWND w; 380 #endif 381 #endif 382 int mode; 383 int state, button; 384 } Gqw_t; 385 #define QWSIZE sizeof (Gqw_t) 386 387 /* --- scroll --- */ 388 typedef struct Gsw_t { 389 int dummy; 390 } Gsw_t; 391 #define SWSIZE sizeof (Gsw_t) 392 393 /* --- text --- */ 394 typedef struct Gtw_t { 395 Gtwnewlinecb func; 396 } Gtw_t; 397 #define TWSIZE sizeof (Gtw_t) 398 399 /* --- view --- */ 400 typedef struct Gvw_t { 401 Gviewcb func; 402 int closing; 403 } Gvw_t; 404 #define VWSIZE sizeof (Gvw_t) 405 406 /* the main widget structure */ 407 typedef struct Gwidget_t { 408 int type; 409 int inuse; 410 int pwi; 411 #ifdef FEATURE_X11 412 Widget w; 413 #else 414 #ifdef FEATURE_WIN32 415 HWND w; 416 #else 417 int w; 418 #endif 419 #endif 420 union { 421 Gaw_t *a; 422 Gbw_t *b; 423 Gcw_t *c; 424 Glw_t *l; 425 Gmw_t *m; 426 Gpw_t *p; 427 Gqw_t *q; 428 Gsw_t *s; 429 Gtw_t *t; 430 Gvw_t *v; 431 } u; 432 uint64_t udata; 433 } Gwidget_t; 434 #define WIDGETINCR 20 435 #define WIDGETSIZE sizeof (Gwidget_t) 436 437 /* bitmap data structure */ 438 typedef struct Gbitmap_t { 439 int inuse; 440 int canvas; 441 int ctype; /* type of canvas, eg. G_CANVASWIDGET */ 442 Gsize_t size; 443 Gsize_t scale; 444 union { 445 struct { 446 #ifdef FEATURE_X11 447 Pixmap orig, scaled; 448 #else 449 #ifdef FEATURE_WIN32 450 HBITMAP orig, scaled; 451 #else 452 int dummy; 453 #endif 454 #endif 455 } bmap; 456 unsigned char *bits; 457 } u; 458 } Gbitmap_t; 459 460 extern Gbitmap_t *Gbitmaps; 461 extern int Gbitmapn; 462 463 /* global array of widgets */ 464 extern Gwidget_t *Gwidgets; 465 extern int Gwidgetn; 466 467 extern Gwlist_t Gwlist[]; 468 extern Gwattrmap_t Gwattrmap[]; 469 470 extern char *Gdefaultfont; 471 extern int Gneedredraw; 472 extern int Gbuttonsdown; 473 extern int Gerrflag; 474 extern char *Gpscanvasname; 475 476 extern int Gxfd; 477 478 #ifdef FEATURE_WIN32 479 extern int Gnocallbacks; 480 #endif 481 482 /* functions returning an int 483 return -1 if there's an error and 484 also set the Gerrno variable 485 486 the rendering functions may return +1 487 if the graphical object is completely hidden 488 */ 489 int Ginit (void); 490 int Gterm (void); 491 int Gcreatewidget (int, int, int, Gwattr_t *); 492 int Gsetwidgetattr (int, int, Gwattr_t *); 493 int Ggetwidgetattr (int, int, Gwattr_t *); 494 int Gdestroywidget (int); 495 int Gqueryask (int, char *, char *, char *, int); 496 int Gmenuaddentries (int, int, char **); 497 int Gmenudisplay (int, int); 498 int Gsync (void); 499 int Gresetbstate (int); 500 int Gcanvasclear (int); 501 int Gsetgfxattr (int, Ggattr_t *); 502 int Ggetgfxattr (int, Ggattr_t *); 503 int Garrow (int, Gpoint_t, Gpoint_t, Ggattr_t *); 504 int Gline (int, Gpoint_t, Gpoint_t, Ggattr_t *); 505 int Gbox (int, Grect_t, Ggattr_t *); 506 int Gpolygon (int, int, Gpoint_t *, Ggattr_t *); 507 int Gsplinegon (int, int, Gpoint_t *, Ggattr_t *); 508 int Garc (int, Gpoint_t, Gsize_t, double, double, Ggattr_t *); 509 int Gtext (int, char *, Gpoint_t, char *, double, char *, Ggattr_t *); 510 int Ggettextsize (int, char *, char *, double, Gsize_t *); 511 int Gcreatebitmap (int, Gsize_t); 512 int Gdestroybitmap (int); 513 int Greadbitmap (int, FILE *); 514 int Gwritebitmap (FILE *, int); 515 int Gbitblt (int, Gpoint_t, Grect_t, int, char *, Ggattr_t *); 516 int Ggetmousecoords (int, Gpoint_t *, int *); 517 518 int Gprocessevents (int, int); 519 520 int Gaworder (Gwidget_t *, void *, Gawordercb); 521 int Gawsetmode (Gwidget_t *, int); 522 int Gawgetmode (Gwidget_t *); 523 void Gawdefcoordscb (int, Gawdata_t *); 524 525 Gwidget_t *newwidget (int); 526 Gwidget_t *findwidget (uint64_t, int); 527 Gbitmap_t *newbitmap (void); 528 void Gerr (char *, int, int, ...); 529 530 /* error messages */ 531 #define G_ERRBADATTRID 1 532 #define G_ERRBADATTRVALUE 2 533 #define G_ERRBADCOLORINDEX 3 534 #define G_ERRBADPARENTWIDGETID 4 535 #define G_ERRBADWIDGETID 5 536 #define G_ERRBADWIDGETTYPE 6 537 #define G_ERRCANNOTCREATEWIDGET 7 538 #define G_ERRCANNOTGETATTR 8 539 #define G_ERRCANNOTOPENFILE 9 540 #define G_ERRCANNOTSETATTR1 10 541 #define G_ERRCANNOTSETATTR2 11 542 #define G_ERRINITFAILED 12 543 #define G_ERRNOCHILDWIDGET 13 544 #define G_ERRNOPARENTWIDGET 14 545 #define G_ERRNOSUCHCURSOR 15 546 #define G_ERRNOTACANVAS 16 547 #define G_ERRNOTIMPLEMENTED 17 548 #define G_ERRNOTSUPPORTED 18 549 #define G_ERRBADBITMAPID 19 550 #define G_ERRCANNOTCREATEBITMAP 20 551 #define G_ERRNOBITMAP 21 552 #define G_ERRCANNOTREADBITMAP 22 553 554 extern int Gerrno; 555 #endif /* _G_H */ 556 557 #ifdef __cplusplus 558 } 559 #endif 560 561