1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
|
/*-------------------------------------------------------------------------*/
/* Copyright (c) 2002 Tim Edwards, Johns Hopkins University */
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/* Spun off from xcircuit.c 10/4/98 in the hopes of expanding it sometime. */
/*-------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include "Xw/Xw.h"
#include "Xw/Form.h"
#include "Xw/WorkSpace.h"
#include "Xw/MenuBtn.h"
/*-------------------------------------------------------------------------*/
/* Local includes */
/*-------------------------------------------------------------------------*/
#include "colordefs.h"
#include "xcircuit.h"
#include "menudep.h"
/*----------------------------------------------------------------------*/
/* Function prototype declarations */
/*----------------------------------------------------------------------*/
#include "prototypes.h"
/*-------------------------------------------------------------------------*/
/* Global Variable definitions */
/*-------------------------------------------------------------------------*/
extern Display *dpy;
extern Window win;
extern GC hgc;
extern Clientdata areastruct;
extern ApplicationData appdata;
extern int *appcolors;
extern Widget top;
extern short popups;
extern Widget menuwidgets[];
extern char *function_names[NUM_FUNCTIONS];
Pixmap helppix = (Pixmap)NULL; /* For help window */
Dimension helpwidth, helpheight, hheight;
int helptop;
short help_up;
/*-----------------------------------------*/
/* Print help list into a pixmap */
/* Return width and height of map through */
/* global variables helpwidth, helpheight. */
/*-----------------------------------------*/
typedef struct {
int function;
char *text;
} helpstruct;
void printhelppix(Widget w)
{
static char *helptitle = "Macro Key Binding Summary:";
static helpstruct helptext[] = {
{ XCF_Start, "Start"},
{ XCF_Finish, "Finish"},
{ XCF_Cancel, "Cancel"},
{ XCF_Zoom_In, "Zoom in 3/2"},
{ XCF_Zoom_Out, "Zoom out 3/2"},
{ XCF_Pan, "Pan to center"},
{ XCF_Pan_Up, "Half-page pan Up"},
{ XCF_Pan_Down, "Half-page pan Down"},
{ XCF_Pan_Right, "Half-page pan Right"},
{ XCF_Pan_Left, "Half-page pan Left"},
{ XCF_Double_Snap, "Double snap-to spacing"},
{ XCF_Halve_Snap, "Halve snap-to spacing"},
{ XCF_Next_Library, "Go To Next Library"},
{ XCF_Push, "Push object"},
{ XCF_Pop, "Pop object"},
{ XCF_Redraw, "Refresh screen"},
{ XCF_Page, "Go To Page"},
{ XCF_Write, "Popup Output dialog"},
#ifdef HAVE_PYTHON
{ XCF_Prompt, "Python Command entry"},
#else
{ XCF_Prompt, "Command entry"},
#endif
{ XCF_Exit, "Quit XCircuit"},
{ XCF_SPACER, NULL},
{ XCF_Wire, "Begin Polygon"},
{ XCF_Box, "Begin Box"},
{ XCF_Arc, "Begin Arc"},
{ XCF_Text, "Begin Text"},
{ XCF_Spline, "Begin Spline"},
{ XCF_Select_Save, "Make object"},
{ XCF_Join, "Join elements (make path)"},
{ XCF_Unjoin, "Un-join elements"},
{ XCF_Dot, "Place a dot"},
{ XCF_SPACER, NULL},
{ XCF_Delete, "Delete"},
{ XCF_Undelete, "Undelete"},
{ XCF_Select, "Select"},
{ XCF_Unselect, "Deselect"},
{ XCF_Copy, "Copy"},
{ XCF_Edit, "Edit"},
{ XCF_SPACER, NULL},
{ XCF_Rotate, "Rotate"},
{ XCF_Flip_X, "Flip horizontally"},
{ XCF_Flip_Y, "Flip vertically"},
{ XCF_Snap, "Snap to grid"},
{ XCF_Attach, "Attach to"},
{ XCF_Dashed, "Dashed line style"},
{ XCF_Dotted, "Dotted line style"},
{ XCF_Solid, "Solid line style"},
{ XCF_SPACER, NULL},
{ XCF_Justify, "Text Justification"},
{ XCF_Superscript, "Text Superscript"},
{ XCF_Subscript, "Text Subscript"},
{ XCF_Nextfont, "Toggle text font"},
{ XCF_Boldfont, "Begin Bold text"},
{ XCF_Italicfont, "Begin Italic text"},
{ XCF_Normalfont, "Resume normal text"},
{ XCF_ISO_Encoding, "Begin Latin-1 encoding"},
{ XCF_Overline, "Begin text overline"},
{ XCF_Underline, "Begin text underline"},
{ XCF_Parameter, "Insert parameter"},
{ XCF_Halfspace, "Insert half-space"},
{ XCF_Quarterspace, "Insert quarter-space"},
{ XCF_Return_Char, "Insert return character"},
{ XCF_Special, "Insert special character"},
{ XCF_TabStop, "Set tab stop"},
{ XCF_TabForward, "Forward tab"},
{ XCF_TabBackward, "Backward tab"},
{ XCF_Text_Home, "Go to label beginning"},
{ XCF_Text_End, "Go to label end"},
{ XCF_Text_Left, "Move left one position"},
{ XCF_Text_Right, "Move right one position"},
{ XCF_Text_Delete, "Delete character(s)"},
{ XCF_Text_Return, "End text edit"},
{ XCF_SPACER, NULL},
{ XCF_Library_Edit, "Library name edit"},
{ XCF_Library_Move, "Library move object/page"},
{ XCF_Library_Delete, "Library object delete"},
{ XCF_Library_Hide, "Library hide object"},
{ XCF_Library_Duplicate, "Library copy object"},
#ifdef SCHEMA
{ XCF_SPACER, NULL},
{ XCF_Pin_Label, "Make Pin Label"},
{ XCF_Info_Label, "Make Info Label"},
{ XCF_Swap, "Go to Symbol or Schematic"},
{ XCF_Connectivity, "See net connectivity"},
{ XCF_Sim, "Generate Sim netlist"},
{ XCF_SPICE, "Generate SPICE netlist"},
{ XCF_SPICEflat, "Generate flattened SPICE"},
{ XCF_PCB, "Generate PCB netlist"},
#endif
{ XCF_ENDDATA, NULL},
};
XGCValues values;
Window hwin = XtWindow(w);
Dimension htmp, vtmp, lineheight, mwidth;
int i, j, t1, t2, dum, numlines;
XCharStruct csdum;
char *bindings, *bptr, *cptr;
/* Set up the GC for drawing to the help window pixmap */
if (hgc == NULL) {
values.foreground = FOREGROUND;
values.background = BACKGROUND;
values.font = appdata.helpfont->fid;
hgc = XCreateGC(dpy, hwin, GCForeground | GCBackground | GCFont, &values);
}
/* Determine the dimensions of the help text */
mwidth = helpwidth = lineheight = numlines = 0;
for (i = 0; helptext[i].function != XCF_ENDDATA; i++) {
if (helptext[i].function == XCF_SPACER) continue;
htmp = XTextWidth(appdata.helpfont, helptext[i].text, strlen(helptext[i].text));
if (htmp > mwidth) mwidth = htmp;
XTextExtents(appdata.helpfont, helptext[i].text, strlen(helptext[i].text),
&dum, &t1, &t2, &csdum);
vtmp = t1 + t2 + 5;
if (vtmp > lineheight) lineheight = vtmp;
bindings = binding_to_string(-1, helptext[i].function);
/* Limit list to three key bindings per line */
bptr = bindings;
while (bptr != NULL) {
cptr = bptr;
for (j = 0; j < 3; j++) {
cptr = strchr(cptr + 1, ',');
if (cptr == NULL) break;
}
if (cptr != NULL) *(++cptr) = '\0';
htmp = XTextWidth(appdata.helpfont, bptr, strlen(bptr));
if (htmp > helpwidth) helpwidth = htmp;
XTextExtents(appdata.helpfont, bptr, strlen(bptr),
&dum, &t1, &t2, &csdum);
vtmp = t1 + t2 + 5;
if (vtmp > lineheight) lineheight = vtmp;
numlines++;
if (cptr == NULL) break;
bptr = cptr + 1;
}
free(bindings);
}
XTextExtents(appdata.helpfont, helptitle, strlen(helptitle), &dum, &t1,
&t2, &csdum);
t1 += t2;
helpwidth += mwidth + 15;
helpheight = lineheight * numlines + 15 + t1; /* full height of help text */
if (helppix != (Pixmap)NULL) {
Wprintf("Error: Help window not cancelled?");
return;
}
helppix = XCreatePixmap(dpy, hwin, helpwidth, helpheight,
DefaultDepthOfScreen(XtScreen(w)));
XSetForeground(dpy, hgc, FOREGROUND);
XFillRectangle(dpy, helppix, hgc, 0, 0, helpwidth, helpheight);
XSetForeground(dpy, hgc, BACKGROUND);
XDrawString(dpy, helppix, hgc, (helpwidth - XTextWidth(appdata.helpfont,
helptitle, strlen(helptitle))) >> 1, t1 + 2, helptitle, strlen(helptitle));
vtmp = lineheight + 15;
for (i = 0; helptext[i].function != XCF_ENDDATA; i++) {
if (helptext[i].function == XCF_SPACER) continue;
XDrawString(dpy, helppix, hgc, 7, vtmp, helptext[i].text,
strlen(helptext[i].text));
bindings = binding_to_string(-1, helptext[i].function);
bptr = bindings;
while (bptr != NULL) {
cptr = bptr;
for (j = 0; j < 3; j++) {
cptr = strchr(cptr + 1, ',');
if (cptr == NULL) break;
}
if (cptr != NULL) *(++cptr) = '\0';
XDrawString(dpy, helppix, hgc, 7 + mwidth, vtmp, bptr, strlen(bptr));
vtmp += lineheight;
if (cptr == NULL) break;
bptr = cptr + 1;
}
free(bindings);
}
XSetForeground(dpy, hgc, AUXCOLOR);
XDrawLine(dpy, helppix, hgc, 0, t1 + 7, helpwidth, t1 + 7);
}
/*-----------------------------------------*/
/* Create the help popup window */
/*-----------------------------------------*/
void starthelp(Widget button, caddr_t clientdata, caddr_t calldata)
{
Arg wargs[8];
Widget popup, cancelbutton, hspace, help2;
short n = 0;
popupstruct *okaystruct;
buttonsave *savebutton = (buttonsave *)malloc(sizeof(buttonsave));
Dimension areawidth, bwidth, pheight;
Position xpos, ypos;
u_int xmax, ymax;
if (help_up) return; /* no multiple help windows */
/* for positioning the help window outside of the xcircuit */
/* window, get information about the display width and height */
/* and the xcircuit window. */
/* The "- 50" leaves space for the Windows-95-type title bar that */
/* runs across the bottom of the screen in some window managers */
/* (specifically, fvwm95 which is the default for RedHat Linux) */
xmax = DisplayWidth(dpy, DefaultScreen(dpy)) - 100;
ymax = DisplayHeight(dpy, DefaultScreen(dpy)) - 50;
XtnSetArg(XtNwidth, &areawidth);
XtGetValues(areastruct.area, wargs, n); n = 0;
XtTranslateCoords(areastruct.area, (Position) (areawidth + 10), -50,
&xpos, &ypos);
/* Always direct the call to the main menu button. */
button = OptionsHelpButton;
getgeneric(savebutton, button, starthelp, NULL);
/* Generate the pixmap and write the help text to it */
if (helppix == (Pixmap)NULL) printhelppix(button);
/* Use the pixmap size to size the help window */
if (xpos + helpwidth > xmax) xpos = xmax - helpwidth - 4;
if (ypos + helpheight > ymax) ypos = ymax - helpheight - 4;
if (ypos < 4) ypos = 4;
XtnSetArg(XtNx, xpos);
XtnSetArg(XtNy, ypos);
popup = XtCreatePopupShell("help", transientShellWidgetClass,
button, wargs, n); n = 0;
popups++;
help_up = True;
helptop = 0;
XtnSetArg(XtNwidth, helpwidth);
XtnSetArg(XtNyResizable, True);
XtnSetArg(XtNxResizable, False);
help2 = XtCreateManagedWidget("help2", XwformWidgetClass,
popup, wargs, n); n = 0;
XtnSetArg(XtNfont, appdata.xcfont);
cancelbutton = XtCreateManagedWidget("Dismiss", XwmenuButtonWidgetClass,
help2, wargs, n); n = 0;
XtnSetArg(XtNyRefWidget, cancelbutton);
XtnSetArg(XtNyAddHeight, True);
XtnSetArg(XtNyAttachBottom, True);
XtnSetArg(XtNborderWidth, 0);
XtnSetArg(XtNheight, helpheight);
XtnSetArg(XtNwidth, helpwidth);
XtnSetArg(XtNxAttachRight, True);
hspace = XtCreateManagedWidget("HSpace", XwworkSpaceWidgetClass,
help2, wargs, n); n = 0;
okaystruct = (popupstruct *) malloc(sizeof(popupstruct));
okaystruct->buttonptr = savebutton;
okaystruct->popup = popup;
okaystruct->filter = NULL;
XtPopup(popup, XtGrabNone);
/* reposition the "Dismiss" button to center */
XtSetArg(wargs[0], XtNwidth, &bwidth);
XtGetValues(cancelbutton, wargs, 1);
XtnSetArg(XtNx, ((helpwidth - bwidth) >> 1));
XtSetValues(cancelbutton, wargs, n); n = 0;
/* Check for total size of window compared to computer screen */
/* and add simple button-click callback if necessary. */
XtSetArg(wargs[0], XtNheight, &pheight);
XtGetValues(help2, wargs, 1);
if (pheight > (ymax - 8)) {
XtnSetArg(XtNheight, helpheight - (pheight - ymax) - 8);
XtSetValues(hspace, wargs, n); n = 0;
XtnSetArg(XtNheight, ymax - 8);
XtSetValues(help2, wargs, n);
XtSetValues(popup, wargs, n); n = 0;
XtAddEventHandler(hspace, ButtonMotionMask, False,
(XtEventHandler)simplescroll, NULL);
}
/* Expose and End callbacks */
XtAddCallback(cancelbutton, XtNselect, (XtCallbackProc)destroypopup, okaystruct);
XtAddCallback(hspace, XtNexpose, (XtCallbackProc)printhelp, popup);
}
/*----------------------------------------------*/
/* Very simple scroll mechanism (grab-and-pan) */
/*----------------------------------------------*/
void simplescroll(Widget hspace, caddr_t clientdata, XMotionEvent *event)
{
Window hwin = XtWindow(hspace);
if (event->y != areastruct.save.y) {
helptop += (int)(event->y - areastruct.save.y);
if (helptop < 0) helptop = 0;
else if (helptop > helpheight - hheight) helptop = helpheight - hheight;
}
areastruct.save.y = event->y;
/* Draw the pixmap to the window */
XCopyArea(dpy, helppix, hwin, hgc, 0, helptop - 5, helpwidth, helpheight,
0, 0);
}
/*----------------------------------------------*/
/* Expose callback for the help window */
/*----------------------------------------------*/
void printhelp(Widget hspace, caddr_t clientdata, caddr_t calldata)
{
Arg wargs[1];
Window hwin = XtWindow(hspace);
XEvent discard;
XtSetArg(wargs[0], XtNheight, &hheight);
XtGetValues(hspace, wargs, 1);
/* Draw the pixmap to the window */
XCopyArea(dpy, helppix, hwin, hgc, 0, helptop - 5, helpwidth, helpheight,
0, 0);
/* flush out multiple expose events */
while (XCheckWindowEvent(dpy, hwin, ExposureMask, &discard) == True);
}
/*-------------------------------------------------------------------------*/
|