home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tkisrc04.zip / tk / os2 / tkUtil.c < prev    next >
C/C++ Source or Header  |  1998-08-07  |  5KB  |  147 lines

  1. /* 
  2.  * tkUtil.c --
  3.  *
  4.  *    This file contains miscellaneous utility procedures that
  5.  *    are used by the rest of Tk, such as a procedure for drawing
  6.  *    a focus highlight.
  7.  *
  8.  * Copyright (c) 1994 The Regents of the University of California.
  9.  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
  10.  *
  11.  * See the file "license.terms" for information on usage and redistribution
  12.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  *
  14.  * SCCS: @(#) tkUtil.c 1.7 96/02/15 18:53:04
  15.  */
  16. #include "tk.h"
  17. #include "tkPort.h"
  18.  
  19. /*
  20.  *----------------------------------------------------------------------
  21.  *
  22.  * Tk_DrawFocusHighlight --
  23.  *
  24.  *    This procedure draws a rectangular ring around the outside of
  25.  *    a widget to indicate that it has received the input focus.
  26.  *
  27.  * Results:
  28.  *    None.
  29.  *
  30.  * Side effects:
  31.  *    A rectangle "width" pixels wide is drawn in "drawable",
  32.  *    corresponding to the outer area of "tkwin".
  33.  *
  34.  *----------------------------------------------------------------------
  35.  */
  36.  
  37. void
  38. Tk_DrawFocusHighlight(tkwin, gc, width, drawable)
  39.     Tk_Window tkwin;        /* Window whose focus highlight ring is
  40.                  * to be drawn. */
  41.     GC gc;            /* Graphics context to use for drawing
  42.                  * the highlight ring. */
  43.     int width;            /* Width of the highlight ring, in pixels. */
  44.     Drawable drawable;        /* Where to draw the ring (typically a
  45.                  * pixmap for double buffering). */
  46. {
  47.     XRectangle rects[4];
  48.  
  49.     rects[0].x = 0;
  50.     rects[0].y = 0;
  51.     rects[0].width = Tk_Width(tkwin);
  52.     rects[0].height = width;
  53.     rects[1].x = 0;
  54.     rects[1].y = Tk_Height(tkwin) - width;
  55.     rects[1].width = Tk_Width(tkwin);
  56.     rects[1].height = width;
  57.     rects[2].x = 0;
  58.     rects[2].y = width;
  59.     rects[2].width = width;
  60.     rects[2].height = Tk_Height(tkwin) - 2*width;
  61.     rects[3].x = Tk_Width(tkwin) - width;
  62.     rects[3].y = width;
  63.     rects[3].width = width;
  64.     rects[3].height = rects[2].height;
  65.     XFillRectangles(Tk_Display(tkwin), drawable, gc, rects, 4);
  66. }
  67.  
  68. /*
  69.  *----------------------------------------------------------------------
  70.  *
  71.  * Tk_GetScrollInfo --
  72.  *
  73.  *    This procedure is invoked to parse "xview" and "yview"
  74.  *    scrolling commands for widgets using the new scrolling
  75.  *    command syntax ("moveto" or "scroll" options).
  76.  *
  77.  * Results:
  78.  *    The return value is either TK_SCROLL_MOVETO, TK_SCROLL_PAGES,
  79.  *    TK_SCROLL_UNITS, or TK_SCROLL_ERROR.  This indicates whether
  80.  *    the command was successfully parsed and what form the command
  81.  *    took.  If TK_SCROLL_MOVETO, *dblPtr is filled in with the
  82.  *    desired position;  if TK_SCROLL_PAGES or TK_SCROLL_UNITS,
  83.  *    *intPtr is filled in with the number of lines to move (may be
  84.  *    negative);  if TK_SCROLL_ERROR, interp->result contains an
  85.  *    error message.
  86.  *
  87.  * Side effects:
  88.  *    None.
  89.  *
  90.  *----------------------------------------------------------------------
  91.  */
  92.  
  93. int
  94. Tk_GetScrollInfo(interp, argc, argv, dblPtr, intPtr)
  95.     Tcl_Interp *interp;            /* Used for error reporting. */
  96.     int argc;                /* # arguments for command. */
  97.     char **argv;            /* Arguments for command. */
  98.     double *dblPtr;            /* Filled in with argument "moveto"
  99.                      * option, if any. */
  100.     int *intPtr;            /* Filled in with number of pages
  101.                      * or lines to scroll, if any. */
  102. {
  103.     int c;
  104.     size_t length;
  105.  
  106.     length = strlen(argv[2]);
  107.     c = argv[2][0];
  108.     if ((c == 'm') && (strncmp(argv[2], "moveto", length) == 0)) {
  109.     if (argc != 4) {
  110.         Tcl_AppendResult(interp, "wrong # args: should be \"",
  111.             argv[0], " ", argv[1], " moveto fraction\"",
  112.             (char *) NULL);
  113.         return TK_SCROLL_ERROR;
  114.     }
  115.     if (Tcl_GetDouble(interp, argv[3], dblPtr) != TCL_OK) {
  116.         return TK_SCROLL_ERROR;
  117.     }
  118.     return TK_SCROLL_MOVETO;
  119.     } else if ((c == 's')
  120.         && (strncmp(argv[2], "scroll", length) == 0)) {
  121.     if (argc != 5) {
  122.         Tcl_AppendResult(interp, "wrong # args: should be \"",
  123.             argv[0], " ", argv[1], " scroll number units|pages\"",
  124.             (char *) NULL);
  125.         return TK_SCROLL_ERROR;
  126.     }
  127.     if (Tcl_GetInt(interp, argv[3], intPtr) != TCL_OK) {
  128.         return TK_SCROLL_ERROR;
  129.     }
  130.     length = strlen(argv[4]);
  131.     c = argv[4][0];
  132.     if ((c == 'p') && (strncmp(argv[4], "pages", length) == 0)) {
  133.         return TK_SCROLL_PAGES;
  134.     } else if ((c == 'u')
  135.         && (strncmp(argv[4], "units", length) == 0)) {
  136.         return TK_SCROLL_UNITS;
  137.     } else {
  138.         Tcl_AppendResult(interp, "bad argument \"", argv[4],
  139.             "\": must be units or pages", (char *) NULL);
  140.         return TK_SCROLL_ERROR;
  141.     }
  142.     }
  143.     Tcl_AppendResult(interp, "unknown option \"", argv[2],
  144.         "\": must be moveto or scroll", (char *) NULL);
  145.     return TK_SCROLL_ERROR;
  146. }
  147.