home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xdbx / part04 / signs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  11.2 KB  |  394 lines

  1. /*****************************************************************************
  2.  *
  3.  *  xdbx - X Window System interface to the dbx debugger
  4.  *
  5.  *  Copyright 1989 The University of Texas at Austin
  6.  *  Copyright 1990 Microelectronics and Computer Technology Corporation
  7.  *
  8.  *  Permission to use, copy, modify, and distribute this software and its
  9.  *  documentation for any purpose and without fee is hereby granted,
  10.  *  provided that the above copyright notice appear in all copies and that
  11.  *  both that copyright notice and this permission notice appear in
  12.  *  supporting documentation, and that the name of The University of Texas
  13.  *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  14.  *  used in advertising or publicity pertaining to distribution of
  15.  *  the software without specific, written prior permission.  The
  16.  *  University of Texas and MCC makes no representations about the 
  17.  *  suitability of this software for any purpose.  It is provided "as is" 
  18.  *  without express or implied warranty.
  19.  *
  20.  *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  21.  *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22.  *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  23.  *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  24.  *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  25.  *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  26.  *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  *
  28.  *  Author:      Po Cheung
  29.  *  Created:       March 10, 1989
  30.  *
  31.  *****************************************************************************/
  32.  
  33. /*  signs.c
  34.  *
  35.  *  This file contains all the routines for the creation and manipulation of 
  36.  *  symbols used in xdbx.  There are 3 different signs:
  37.  *    arrow  - a solid right arrow to indicate the current execution point.
  38.  *    updown - an outlined right arrow to indicate position in stack trace.
  39.  *    stop   - a stop hand symbol to indicate a breakpoint is set.
  40.  *    bomb  - a bomb symbol to indicate the point of segmentation fault.
  41.  *
  42.  *  To display a sign on a given line in the source window, it is first
  43.  *  created and mapped.  To undisplay it, the sign is unmapped.  It can
  44.  *  be mapped again when the sign is needed.  Note that the sign is never
  45.  *  moved, so that there can be as many signs created (but not mapped) as
  46.  *  the number of lines in the source window.
  47.  *  For arrow and updown, there can be at most one of each mapped at a time.
  48.  *  For stop, there can be more than one mapped at the same time.
  49.  */
  50.  
  51. #include "global.h"
  52. #include "bitmaps.h"
  53.  
  54. #define MAXSTOPS        256             /* max number of stops */
  55. #define MAXSIGNS        256             /* max number of signs */
  56. #define OFFSET            2                 /* offset for displaying signs */
  57.  
  58. typedef struct {
  59.     Widget      w;
  60.     Boolean     mapped;
  61. } ArrowSign;
  62.  
  63. typedef struct {
  64.     Widget      w;
  65.     Boolean     mapped;
  66. } UpdownSign;
  67.  
  68. typedef struct {
  69.     Widget      w;
  70.     Boolean     mapped;
  71. } StopSign;
  72.  
  73. typedef struct {
  74.     Widget      w;
  75.     Boolean     mapped;
  76. } BombSign;
  77.  
  78. static ArrowSign     arrowsign[MAXSIGNS];
  79. static UpdownSign     updownsign[MAXSIGNS];
  80. static StopSign        stopsign[MAXSIGNS];
  81. static BombSign     bombsign[MAXSIGNS];
  82.  
  83. Arrow         arrow;
  84. Updown         updown;
  85. Stops        stops[MAXSTOPS];    /* array of stops */
  86. Bomb         bomb;
  87. Cardinal    nstops;            /* number of stops */
  88.  
  89. /* Initialize data structures */
  90.  
  91. void signs_init()
  92. {
  93.     int i;
  94.  
  95.     for (i=0; i<MAXSIGNS; i++) {
  96.     arrowsign[i].w = NULL;
  97.     arrowsign[i].mapped = FALSE;
  98.     }
  99.     for (i=0; i<MAXSIGNS; i++) {
  100.     stopsign[i].w = NULL;
  101.     stopsign[i].mapped = FALSE;
  102.     }
  103.     arrow.i = 0;
  104.     arrow.line = 0;
  105.     strcpy(arrow.file, "");
  106.     updown.i = 0;
  107.     updown.line = 0;
  108.     strcpy(updown.file, "");
  109.     nstops = 0;
  110.     bomb.i = 0;
  111.     bomb.line = 0;
  112.     strcpy(bomb.file, "");
  113. }
  114.  
  115.  
  116. /*  Create an arrow symbol, updown symbol or stop symbol:
  117.  *    calculate the position of the symbol based on i, the number of lines
  118.  *    from the top line.
  119.  *    create the pixmap of the symbol
  120.  *    display the symbol as a bitmap in a label widget.
  121.  */
  122. static Widget CreateSign(parent, sign, i)
  123.     Widget    parent;
  124.     char    *sign;
  125.     Cardinal     i;
  126. {
  127.     TextWidget     ctx = (TextWidget) sourceWindow;
  128.     Arg     args[15];
  129.     Cardinal     n;
  130.     Dimension     source_height, height, width; 
  131.     char    *bits;
  132.     Pixel       fg, bg;
  133.     int     horizDistance, vertDistance, height_per_line;
  134.     int         screen;
  135.     Dimension    vbar_width = 0;
  136.     Dimension    border_width = 0;
  137.  
  138.     if (displayedFile == NULL) return NULL;
  139.  
  140.     /* Get height and background pixel values of parent window */
  141.     n = 0;
  142.     XtSetArg(args[n], XtNheight, &source_height);            n++;
  143.     XtSetArg(args[n], XtNbackground, &bg);                n++;
  144.     XtGetValues(parent, args, n);
  145.  
  146.     height_per_line = source_height/displayedFile->lines;
  147.     vertDistance = OFFSET + (i * height_per_line); 
  148.  
  149.     screen = DefaultScreen(display);
  150.  
  151.     if (sign && !strcmp(sign, "arrow")) {
  152.     bits = arrow_bits;
  153.     width = arrow_width;
  154.     height = arrow_height;
  155.     horizDistance = 0;
  156.     fg = app_resources.arrow_color;
  157.     }
  158.     else if (sign && !strcmp(sign, "updown")) {
  159.     bits = updown_bits;
  160.     width = updown_width;
  161.     height = updown_height;
  162.     horizDistance = 0;
  163.     fg = app_resources.updown_color;
  164.     }
  165.     else if (sign && !strcmp(sign, "stop")) {
  166.     bits = stop_bits;
  167.     width = stop_width;
  168.     height = stop_height;
  169.     horizDistance = arrow_width;
  170.     fg = app_resources.stop_color;
  171.     }
  172.     else if (sign && !strcmp(sign, "bomb")) {
  173.     bits = bomb_bits;
  174.     width = bomb_width;
  175.     height = bomb_height;
  176.     horizDistance = 0;
  177.     fg = app_resources.bomb_color;
  178.     };
  179.  
  180.     if( ctx->text.vbar != NULL )
  181.     {
  182.         n = 0;
  183.         XtSetArg(args[n], XtNwidth, &vbar_width);             n++;
  184.         XtSetArg(args[n], XtNborderWidth, &border_width);        n++;
  185.         XtGetValues(ctx->text.vbar, args, n);
  186.         vbar_width += (border_width * 2);
  187.     }
  188.     
  189.     n = 0;
  190.     XtSetArg(args[n], XtNborderWidth, 0);                n++;
  191.     XtSetArg(args[n], XtNwidth, (XtArgVal) width);            n++;
  192.     XtSetArg(args[n], XtNheight, (XtArgVal) height);            n++;
  193.     XtSetArg(args[n], XtNresize, (XtArgVal) False);            n++;
  194.     XtSetArg(args[n], XtNmappedWhenManaged, (XtArgVal) False);        n++;
  195.     XtSetArg(args[n], XtNbitmap, XCreatePixmapFromBitmapData (
  196.         display, DefaultRootWindow(display), bits, width, height,
  197.         fg, bg, DefaultDepth(display, screen)));            n++;
  198.  
  199.     XtSetArg(args[n], XtNfromVert, (XtArgVal) NULL);            n++;
  200.     XtSetArg(args[n], XtNfromHoriz, (XtArgVal) NULL);            n++;
  201.     XtSetArg(args[n], XtNhorizDistance, (XtArgVal) horizDistance+vbar_width);
  202.                                     n++;
  203.     XtSetArg(args[n], XtNvertDistance, (XtArgVal) vertDistance);    n++;
  204.     XtSetArg(args[n], XtNtop, (XtArgVal) XawChainTop);            n++;
  205.     XtSetArg(args[n], XtNleft, (XtArgVal) XawChainLeft);        n++;
  206.     XtSetArg(args[n], XtNbottom, (XtArgVal) XawChainTop);        n++;
  207.     XtSetArg(args[n], XtNright, (XtArgVal) XawChainLeft);        n++;
  208.  
  209.     return XtCreateManagedWidget(sign, labelWidgetClass, parent, args, n);
  210. }
  211.  
  212. /*
  213.  *  Given a line number, displays a stop sign if that line is viewable.
  214.  *  If the stop widget for that line does not exist, create one and map it.
  215.  *  If the stop widget exists but not mapped, map it.
  216.  */
  217. void DisplayStop(file, line)
  218. FileRec *file;
  219. int    line;
  220. {
  221.     Cardinal i;
  222.  
  223.     if (line >= file->topline && line <= file->bottomline) {
  224.     i = line - file->topline;
  225.     if (stopsign[i].w == NULL) {    /* widget does not exist */
  226.         stopsign[i].w = CreateSign(sourceForm, "stop", i);
  227.         XtMapWidget(stopsign[i].w);
  228.         stopsign[i].mapped = 1;
  229.     }
  230.     else if (!stopsign[i].mapped) { /* widget not mapped */
  231.         XtMapWidget(stopsign[i].w);
  232.         stopsign[i].mapped = 1;
  233.     }
  234.     }
  235. }
  236.  
  237. /*
  238.  *  Unmap all stop signs and then display only those stops that are viewable.
  239.  */
  240. void UpdateStops(file)
  241. FileRec *file;
  242. {
  243.     Cardinal i;
  244.     int     line;
  245.  
  246.     if (file == NULL) return;
  247.     for (i=0; i<file->lines; i++)
  248.     if (stopsign[i].w && stopsign[i].mapped) {
  249.         XtUnmapWidget(stopsign[i].w);
  250.         stopsign[i].mapped = 0;
  251.     }
  252.  
  253.     for (i=1; i<=nstops; i++)
  254.     if (stops[i].file && !strcmp(stops[i].file, file->pathname) &&
  255.         (line=stops[i].line) && line >= file->topline &&
  256.         line <= file->bottomline) {
  257.         DisplayStop(file, line);
  258.     }
  259. }
  260.  
  261. /*
  262.  * Given a line number, unmap the stop sign associated with that line.
  263.  */
  264. void RemoveStop(line)
  265. int line;
  266. {
  267.     Cardinal i;
  268.  
  269.     if (displayedFile && line >= displayedFile->topline && 
  270.              line <= displayedFile->bottomline) {
  271.     i = line - displayedFile->topline;
  272.     if (stopsign[i].w && stopsign[i].mapped) {
  273.         XtUnmapWidget(stopsign[i].w);
  274.         stopsign[i].mapped = 0;
  275.     }
  276.     }
  277. }
  278.  
  279. void ClearStops()
  280. {
  281.     int i;
  282.  
  283.     for (i=1; i<=nstops; i++) {
  284.     stops[i].file = NULL;
  285.     stops[i].line = 0;
  286.     }
  287. }
  288.  
  289. /*  Unmap the current arrow sign.
  290.  *  Display a new arrow sign if it is viewable.
  291.  */
  292. void UpdateArrow(file)
  293. FileRec *file;
  294. {
  295.     Cardinal i;
  296.     int         line;
  297.  
  298.     if (file == NULL) return;
  299.     i = arrow.i;
  300.     if (i>=0 && i<file->lines)
  301.     if (arrowsign[i].w && arrowsign[i].mapped) {
  302.         XtUnmapWidget(arrowsign[i].w);
  303.         arrowsign[i].mapped = 0;
  304.     }
  305.     line = arrow.line;
  306.     if (arrow.file && !strcmp(arrow.file, file->pathname) &&
  307.         line >= file->topline && line <= file->bottomline) {
  308.         i = line - file->topline;
  309.     arrow.i = i;
  310.     if (arrowsign[i].w == NULL) {
  311.         arrowsign[i].w = CreateSign(sourceForm, "arrow", i);
  312.         XtMapWidget(arrowsign[i].w);
  313.         arrowsign[i].mapped = TRUE;
  314.     }
  315.     else if (!arrowsign[i].mapped) {
  316.         XtMapWidget(arrowsign[i].w);
  317.         arrowsign[i].mapped = TRUE;
  318.     }
  319.     }
  320. }
  321.  
  322.  
  323. /*  If the new updown is on the same line as the arrow, remove the updown.
  324.  *  Unmap current updown sign.
  325.  *  Display the updown if it is viewable.
  326.  */
  327. void UpdateUpdown(file)
  328. FileRec *file;
  329. {
  330.     Cardinal i;
  331.     int         line;
  332.  
  333.     if (file == NULL) return;
  334.     if (updown.file && !strcmp(updown.file, arrow.file) && 
  335.     !strcmp(updown.func, arrow.func)) {
  336.     updown.line = 0;
  337.     strcpy(updown.file, "");
  338.     }
  339.     i = updown.i;
  340.     if (i>=0 && i<file->lines)
  341.     if (updownsign[i].w && updownsign[i].mapped) {
  342.         XtUnmapWidget(updownsign[i].w);
  343.         updownsign[i].mapped = 0;
  344.     }
  345.     line = updown.line;
  346.     if (updown.file && !strcmp(updown.file, file->pathname) &&
  347.         line >= file->topline && line <= file->bottomline) {
  348.         i = line - file->topline;
  349.     updown.i = i;
  350.     if (updownsign[i].w == NULL) {
  351.         updownsign[i].w = CreateSign(sourceForm, "updown", i);
  352.         XtMapWidget(updownsign[i].w);
  353.         updownsign[i].mapped = TRUE;
  354.     }
  355.     else if (!updownsign[i].mapped) {
  356.         XtMapWidget(updownsign[i].w);
  357.         updownsign[i].mapped = TRUE;
  358.     }
  359.     }
  360. }
  361.  
  362. /*  Unmap the current bomb sign, if any.
  363.  *  Display a new bomb sign.
  364.  */
  365. void UpdateBomb(file)
  366. FileRec *file;
  367. {
  368.     Cardinal i;
  369.     int         line;
  370.  
  371.     if (file == NULL) return;
  372.     i = bomb.i;
  373.     if (i>=0 && i<file->lines)
  374.     if (bombsign[i].w && bombsign[i].mapped) {
  375.         XtUnmapWidget(bombsign[i].w);
  376.         bombsign[i].mapped = 0;
  377.     }
  378.     line = bomb.line;
  379.     if (bomb.file && !strcmp(bomb.file, file->pathname) &&
  380.         line >= file->topline && line <= file->bottomline) {
  381.         i = line - file->topline;
  382.     bomb.i = i;
  383.     if (bombsign[i].w == NULL) {
  384.         bombsign[i].w = CreateSign(sourceForm, "bomb", i);
  385.         XtMapWidget(bombsign[i].w);
  386.         bombsign[i].mapped = TRUE;
  387.     }
  388.     else if (!bombsign[i].mapped) {
  389.         XtMapWidget(bombsign[i].w);
  390.         bombsign[i].mapped = TRUE;
  391.     }
  392.     }
  393. }
  394.