home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / xdbx / part02 / signs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-14  |  8.6 KB  |  309 lines

  1. /****************************************************************************** 
  2.  *
  3.  *  xdbx - X Window System interface to dbx
  4.  *
  5.  *  Copyright 1989 The University of Texas at Austin
  6.  *
  7.  *  Author:    Po Cheung
  8.  *  Date:    March 10, 1989
  9.  *
  10.  *  Permission to use, copy, modify, and distribute this software and
  11.  *  its documentation for any purpose and without fee is hereby granted,
  12.  *  provided that the above copyright notice appear in all copies and that
  13.  *  both that copyright notice and this permission notice appear in
  14.  *  supporting documentation.  The University of Texas at Austin makes no 
  15.  *  representations about the suitability of this software for any purpose.  
  16.  *  It is provided "as is" without express or implied warranty.
  17.  *
  18.  ******************************************************************************/
  19.  
  20.  
  21. #include "global.h"
  22. #include "arrow.bits"
  23. #include "updown.bits"
  24. #include "stop.bits"
  25.  
  26. /*
  27.  *  This file contains all the routines for the creation and manipulation of 
  28.  *  symbols used in xdbx.  There are 3 different signs:
  29.  *    arrow  - a solid right arrow to indicate the current execution point.
  30.  *    updown - an outlined right arrow to indicate position in stack trace.
  31.  *    stop   - a stop hand symbol to indicate a breakpoint is set.
  32.  *
  33.  *  To display a sign on a given line in the source window, it is first
  34.  *  created and mapped.  To undisplay it, the sign is unmapped.  It can
  35.  *  be mapped again when the sign is needed.  Note that the sign is never
  36.  *  moved, so that there can be as many signs created (but not mapped) as
  37.  *  the number of lines in the source window.
  38.  *  For arrow and updown, there can be at most one of each mapped at a time.
  39.  *  For stop, there can be more than one mapped at the same time.
  40.  */
  41.  
  42. typedef struct {
  43.     Widget      w;
  44.     Boolean     mapped;
  45. } ArrowSign;
  46.  
  47. typedef struct {
  48.     Widget      w;
  49.     Boolean     mapped;
  50. } UpdownSign;
  51.  
  52. typedef struct {
  53.     Widget      w;
  54.     Boolean     mapped;
  55. } StopSign;
  56.  
  57. static ArrowSign     arrowsign[MAXSIGNS];
  58. static UpdownSign     updownsign[MAXSIGNS];
  59. static StopSign        stopsign[MAXSIGNS];
  60.  
  61. Arrow         arrow;
  62. Updown         updown;
  63. Stops        stops[MAXSTOPS];    /* array of stops */
  64. Cardinal    nstops;            /* number of stops */
  65.  
  66. /* Initialize data structures */
  67.  
  68. void signs_init()
  69. {
  70.     int i;
  71.  
  72.     for (i=0; i<MAXSIGNS; i++) {
  73.     arrowsign[i].w = NULL;
  74.     arrowsign[i].mapped = FALSE;
  75.     }
  76.     for (i=0; i<MAXSIGNS; i++) {
  77.     stopsign[i].w = NULL;
  78.     stopsign[i].mapped = FALSE;
  79.     }
  80.     arrow.i = 0;
  81.     arrow.line = 0;
  82.     strcpy(arrow.filename, "");
  83.     updown.i = 0;
  84.     updown.line = 0;
  85.     strcpy(updown.filename, "");
  86.     nstops = 0;
  87. }
  88.  
  89.  
  90. /*  Create an arrow symbol, updown symbol or stop symbol:
  91.  *    calculate the position of the symbol based on i, the number of lines
  92.  *    from the top line.
  93.  *    create the pixmap of the symbol
  94.  *    display the symbol as a bitmap in a label widget.
  95.  */
  96. static Widget CreateSign(parent, sign, i)
  97.     Widget    parent;
  98.     char    *sign;
  99.     Cardinal     i;
  100. {
  101.     TextWidget     ctx = (TextWidget) sourceWindow;
  102.     Arg     args[15];
  103.     Cardinal     n;
  104.     Dimension     source_height, height, width; 
  105.     char    *bits;
  106.     Pixel       fg, bg;
  107.     int     horizDistance, vertDistance, height_per_line;
  108.     Display     *dpy;
  109.     int         screen;
  110.  
  111.     if (displayedFile == NULL) return NULL;
  112.  
  113.     /* Get height and background pixel values of parent window */
  114.     n = 0;
  115.     XtSetArg(args[n], XtNheight, &source_height);            n++;
  116.     XtSetArg(args[n], XtNbackground, &bg);                n++;
  117.     XtGetValues(parent, args, n);
  118.  
  119.     height_per_line = source_height/displayedFile->lines;
  120.     vertDistance = OFFSET + (i * height_per_line); 
  121.  
  122.     dpy = XtDisplay(parent);
  123.     screen = DefaultScreen(dpy);
  124.  
  125.     if (sign && !strcmp(sign, "arrow")) {
  126.     bits = arrow_bits;
  127.     width = arrow_width;
  128.     height = arrow_height;
  129.     horizDistance = 0;
  130.     fg = app_resources.arrowForeground;
  131.     }
  132.     else if (sign && !strcmp(sign, "updown")) {
  133.     bits = updown_bits;
  134.     width = updown_width;
  135.     height = updown_height;
  136.     horizDistance = 0;
  137.     fg = app_resources.updownForeground;
  138.     }
  139.     else if (sign && !strcmp(sign, "stop")) {
  140.     bits = stop_bits;
  141.     width = stop_width;
  142.     height = stop_height;
  143.     horizDistance = arrow_width;
  144.     fg = app_resources.stopForeground;
  145.     };
  146.  
  147.     n = 0;
  148.     XtSetArg(args[n], XtNborderWidth, 0);                n++;
  149.     XtSetArg(args[n], XtNwidth, (XtArgVal) width);            n++;
  150.     XtSetArg(args[n], XtNheight, (XtArgVal) height);            n++;
  151.     XtSetArg(args[n], XtNresize, (XtArgVal) False);            n++;
  152.     XtSetArg(args[n], XtNmappedWhenManaged, (XtArgVal) False);        n++;
  153.     XtSetArg(args[n], XtNbitmap, XCreatePixmapFromBitmapData (
  154.         dpy, DefaultRootWindow(dpy), bits, width, height,
  155.         fg, bg, DefaultDepth(dpy, screen)));                n++;
  156.  
  157.     XtSetArg(args[n], XtNfromVert, (XtArgVal) NULL);            n++;
  158.     XtSetArg(args[n], XtNfromHoriz, (XtArgVal) ctx->text.sbar);        n++;
  159.     XtSetArg(args[n], XtNhorizDistance, (XtArgVal) horizDistance);    n++;
  160.     XtSetArg(args[n], XtNvertDistance, (XtArgVal) vertDistance);    n++;
  161.     XtSetArg(args[n], XtNtop, (XtArgVal) XtChainTop);            n++;
  162.     XtSetArg(args[n], XtNleft, (XtArgVal) XtChainLeft);            n++;
  163.     XtSetArg(args[n], XtNbottom, (XtArgVal) XtChainTop);        n++;
  164.     XtSetArg(args[n], XtNright, (XtArgVal) XtChainLeft);        n++;
  165.  
  166.     return XtCreateManagedWidget(sign, labelWidgetClass, parent, args, n);
  167. }
  168.  
  169. /*
  170.  *  Given a line number, displays a stop sign if that line is viewable.
  171.  *  If the stop widget for that line does not exist, create one and map it.
  172.  *  If the stop widget exists but not mapped, map it.
  173.  */
  174. void DisplayStop(file, line)
  175. FileRec *file;
  176. Line line;
  177. {
  178.     Cardinal i;
  179.  
  180.     if (line >= file->topline && line <= file->bottomline) {
  181.     i = line - file->topline;
  182.     if (stopsign[i].w == NULL) {    /* widget does not exist */
  183.         stopsign[i].w = CreateSign(sourceWidget, "stop", i);
  184.         XtMapWidget(stopsign[i].w);
  185.         stopsign[i].mapped = 1;
  186.     }
  187.     else if (!stopsign[i].mapped) { /* widget not mapped */
  188.         XtMapWidget(stopsign[i].w);
  189.         stopsign[i].mapped = 1;
  190.     }
  191.     }
  192. }
  193.  
  194. /*
  195.  *  Unmap all stop signs and then display only those stops that are viewable.
  196.  */
  197. void UpdateStops(file)
  198. FileRec *file;
  199. {
  200.     Cardinal i;
  201.     Line line;
  202.  
  203.     if (file == NULL) return;
  204.     for (i=0; i<file->lines; i++)
  205.     if (stopsign[i].w && stopsign[i].mapped) {
  206.         XtUnmapWidget(stopsign[i].w);
  207.         stopsign[i].mapped = 0;
  208.     }
  209.  
  210.     for (i=1; i<=nstops; i++)
  211.     if (stops[i].filename && !strcmp(stops[i].filename, file->filename) &&
  212.         (line=stops[i].line) && line >= file->topline &&
  213.         line <= file->bottomline) {
  214.         DisplayStop(file, line);
  215.     }
  216. }
  217.  
  218. /*
  219.  * Given a line number, unmap the stop sign associated with that line.
  220.  */
  221. void RemoveStop(line)
  222. Line line;
  223. {
  224.     Cardinal i;
  225.  
  226.     if (displayedFile && line >= displayedFile->topline && 
  227.              line <= displayedFile->bottomline) {
  228.     i = line - displayedFile->topline;
  229.     if (stopsign[i].w && stopsign[i].mapped) {
  230.         XtUnmapWidget(stopsign[i].w);
  231.         stopsign[i].mapped = 0;
  232.     }
  233.     }
  234. }
  235.  
  236.  
  237. /*  Unmap the current arrow sign.
  238.  *  Display a new arrow sign if it is viewable.
  239.  */
  240. void UpdateArrow(file)
  241. FileRec *file;
  242. {
  243.     Cardinal i;
  244.     Line     line;
  245.  
  246.     if (file == NULL) return;
  247.     i = arrow.i;
  248.     if (i>=0 && i<file->lines)
  249.     if (arrowsign[i].w && arrowsign[i].mapped) {
  250.         XtUnmapWidget(arrowsign[i].w);
  251.         arrowsign[i].mapped = 0;
  252.     }
  253.     line = arrow.line;
  254.     if (arrow.filename && !strcmp(arrow.filename, file->filename) &&
  255.         line >= file->topline && line <= file->bottomline) {
  256.         i = line - file->topline;
  257.     arrow.i = i;
  258.     if (arrowsign[i].w == NULL) {
  259.         arrowsign[i].w = CreateSign(sourceWidget, "arrow", i);
  260.         XtMapWidget(arrowsign[i].w);
  261.         arrowsign[i].mapped = TRUE;
  262.     }
  263.     else if (!arrowsign[i].mapped) {
  264.         XtMapWidget(arrowsign[i].w);
  265.         arrowsign[i].mapped = TRUE;
  266.     }
  267.     }
  268. }
  269.  
  270.  
  271. /*  If the new updown is on the same line as the arrow, remove the updown.
  272.  *  Unmap current updown sign.
  273.  *  Display the updown if it is viewable.
  274.  */
  275. void UpdateUpdown(file)
  276. FileRec *file;
  277. {
  278.     Cardinal i;
  279.     Line     line;
  280.  
  281.     if (file == NULL) return;
  282.     if (updown.filename && !strcmp(updown.filename, arrow.filename) && 
  283.     updown.line == arrow.line) {
  284.     updown.line = 0;
  285.     strcpy(updown.filename, "");
  286.     }
  287.     i = updown.i;
  288.     if (i>=0 && i<file->lines)
  289.     if (updownsign[i].w && updownsign[i].mapped) {
  290.         XtUnmapWidget(updownsign[i].w);
  291.         updownsign[i].mapped = 0;
  292.     }
  293.     line = updown.line;
  294.     if (updown.filename && !strcmp(updown.filename, file->filename) &&
  295.         line >= file->topline && line <= file->bottomline) {
  296.         i = line - file->topline;
  297.     updown.i = i;
  298.     if (updownsign[i].w == NULL) {
  299.         updownsign[i].w = CreateSign(sourceWidget, "updown", i);
  300.         XtMapWidget(updownsign[i].w);
  301.         updownsign[i].mapped = TRUE;
  302.     }
  303.     else if (!updownsign[i].mapped) {
  304.         XtMapWidget(updownsign[i].w);
  305.         updownsign[i].mapped = TRUE;
  306.     }
  307.     }
  308. }
  309.