/[dtapublic]/projs/dtats/trunk/shared_source/c_tk_base_7_5_w_mods/tkscrollbar.c
ViewVC logotype

Diff of /projs/dtats/trunk/shared_source/c_tk_base_7_5_w_mods/tkscrollbar.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 69 by dashley, Sat Nov 5 10:54:17 2016 UTC revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
1  /* $Header$ */  /* $Header$ */
2    
3  /*  /*
4   * tkScrollbar.c --   * tkScrollbar.c --
5   *   *
6   *      This module implements a scrollbar widgets for the Tk   *      This module implements a scrollbar widgets for the Tk
7   *      toolkit.  A scrollbar displays a slider and two arrows;   *      toolkit.  A scrollbar displays a slider and two arrows;
8   *      mouse clicks on features within the scrollbar cause   *      mouse clicks on features within the scrollbar cause
9   *      scrolling commands to be invoked.   *      scrolling commands to be invoked.
10   *   *
11   * Copyright (c) 1990-1994 The Regents of the University of California.   * Copyright (c) 1990-1994 The Regents of the University of California.
12   * Copyright (c) 1994-1997 Sun Microsystems, Inc.   * Copyright (c) 1994-1997 Sun Microsystems, Inc.
13   *   *
14   * See the file "license.terms" for information on usage and redistribution   * See the file "license.terms" for information on usage and redistribution
15   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16   *   *
17   * RCS: @(#) $Id: tkscrollbar.c,v 1.1.1.1 2001/06/13 05:07:52 dtashley Exp $   * RCS: @(#) $Id: tkscrollbar.c,v 1.1.1.1 2001/06/13 05:07:52 dtashley Exp $
18   */   */
19    
20  #include "tkPort.h"  #include "tkPort.h"
21  #include "tkScrollbar.h"  #include "tkScrollbar.h"
22  #include "default.h"  #include "default.h"
23    
24  /*  /*
25   * Custom option for handling "-orient"   * Custom option for handling "-orient"
26   */   */
27    
28  static Tk_CustomOption orientOption = {  static Tk_CustomOption orientOption = {
29      (Tk_OptionParseProc *) TkOrientParseProc,      (Tk_OptionParseProc *) TkOrientParseProc,
30      TkOrientPrintProc,      TkOrientPrintProc,
31      (ClientData) NULL      (ClientData) NULL
32  };  };
33    
34  /*  /*
35   * Information used for argv parsing.   * Information used for argv parsing.
36   */   */
37    
38  Tk_ConfigSpec tkpScrollbarConfigSpecs[] = {  Tk_ConfigSpec tkpScrollbarConfigSpecs[] = {
39      {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",      {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",
40          DEF_SCROLLBAR_ACTIVE_BG_COLOR, Tk_Offset(TkScrollbar, activeBorder),          DEF_SCROLLBAR_ACTIVE_BG_COLOR, Tk_Offset(TkScrollbar, activeBorder),
41          TK_CONFIG_COLOR_ONLY},          TK_CONFIG_COLOR_ONLY},
42      {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",      {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",
43          DEF_SCROLLBAR_ACTIVE_BG_MONO, Tk_Offset(TkScrollbar, activeBorder),          DEF_SCROLLBAR_ACTIVE_BG_MONO, Tk_Offset(TkScrollbar, activeBorder),
44          TK_CONFIG_MONO_ONLY},          TK_CONFIG_MONO_ONLY},
45      {TK_CONFIG_RELIEF, "-activerelief", "activeRelief", "Relief",      {TK_CONFIG_RELIEF, "-activerelief", "activeRelief", "Relief",
46          DEF_SCROLLBAR_ACTIVE_RELIEF, Tk_Offset(TkScrollbar, activeRelief), 0},          DEF_SCROLLBAR_ACTIVE_RELIEF, Tk_Offset(TkScrollbar, activeRelief), 0},
47      {TK_CONFIG_BORDER, "-background", "background", "Background",      {TK_CONFIG_BORDER, "-background", "background", "Background",
48          DEF_SCROLLBAR_BG_COLOR, Tk_Offset(TkScrollbar, bgBorder),          DEF_SCROLLBAR_BG_COLOR, Tk_Offset(TkScrollbar, bgBorder),
49          TK_CONFIG_COLOR_ONLY},          TK_CONFIG_COLOR_ONLY},
50      {TK_CONFIG_BORDER, "-background", "background", "Background",      {TK_CONFIG_BORDER, "-background", "background", "Background",
51          DEF_SCROLLBAR_BG_MONO, Tk_Offset(TkScrollbar, bgBorder),          DEF_SCROLLBAR_BG_MONO, Tk_Offset(TkScrollbar, bgBorder),
52          TK_CONFIG_MONO_ONLY},          TK_CONFIG_MONO_ONLY},
53      {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,      {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,
54          (char *) NULL, 0, 0},          (char *) NULL, 0, 0},
55      {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,      {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
56          (char *) NULL, 0, 0},          (char *) NULL, 0, 0},
57      {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",      {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
58          DEF_SCROLLBAR_BORDER_WIDTH, Tk_Offset(TkScrollbar, borderWidth), 0},          DEF_SCROLLBAR_BORDER_WIDTH, Tk_Offset(TkScrollbar, borderWidth), 0},
59      {TK_CONFIG_STRING, "-command", "command", "Command",      {TK_CONFIG_STRING, "-command", "command", "Command",
60          DEF_SCROLLBAR_COMMAND, Tk_Offset(TkScrollbar, command),          DEF_SCROLLBAR_COMMAND, Tk_Offset(TkScrollbar, command),
61          TK_CONFIG_NULL_OK},          TK_CONFIG_NULL_OK},
62      {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",      {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
63          DEF_SCROLLBAR_CURSOR, Tk_Offset(TkScrollbar, cursor), TK_CONFIG_NULL_OK},          DEF_SCROLLBAR_CURSOR, Tk_Offset(TkScrollbar, cursor), TK_CONFIG_NULL_OK},
64      {TK_CONFIG_PIXELS, "-elementborderwidth", "elementBorderWidth",      {TK_CONFIG_PIXELS, "-elementborderwidth", "elementBorderWidth",
65          "BorderWidth", DEF_SCROLLBAR_EL_BORDER_WIDTH,          "BorderWidth", DEF_SCROLLBAR_EL_BORDER_WIDTH,
66          Tk_Offset(TkScrollbar, elementBorderWidth), 0},          Tk_Offset(TkScrollbar, elementBorderWidth), 0},
67      {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",      {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
68          "HighlightBackground", DEF_SCROLLBAR_HIGHLIGHT_BG,          "HighlightBackground", DEF_SCROLLBAR_HIGHLIGHT_BG,
69          Tk_Offset(TkScrollbar, highlightBgColorPtr), 0},          Tk_Offset(TkScrollbar, highlightBgColorPtr), 0},
70      {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",      {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
71          DEF_SCROLLBAR_HIGHLIGHT,          DEF_SCROLLBAR_HIGHLIGHT,
72          Tk_Offset(TkScrollbar, highlightColorPtr), 0},          Tk_Offset(TkScrollbar, highlightColorPtr), 0},
73      {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",      {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
74          "HighlightThickness",          "HighlightThickness",
75          DEF_SCROLLBAR_HIGHLIGHT_WIDTH, Tk_Offset(TkScrollbar, highlightWidth), 0},          DEF_SCROLLBAR_HIGHLIGHT_WIDTH, Tk_Offset(TkScrollbar, highlightWidth), 0},
76      {TK_CONFIG_BOOLEAN, "-jump", "jump", "Jump",      {TK_CONFIG_BOOLEAN, "-jump", "jump", "Jump",
77          DEF_SCROLLBAR_JUMP, Tk_Offset(TkScrollbar, jump), 0},          DEF_SCROLLBAR_JUMP, Tk_Offset(TkScrollbar, jump), 0},
78      {TK_CONFIG_CUSTOM, "-orient", "orient", "Orient",      {TK_CONFIG_CUSTOM, "-orient", "orient", "Orient",
79          DEF_SCROLLBAR_ORIENT, Tk_Offset(TkScrollbar, vertical), 0,          DEF_SCROLLBAR_ORIENT, Tk_Offset(TkScrollbar, vertical), 0,
80          &orientOption},          &orientOption},
81      {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",      {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
82          DEF_SCROLLBAR_RELIEF, Tk_Offset(TkScrollbar, relief), 0},          DEF_SCROLLBAR_RELIEF, Tk_Offset(TkScrollbar, relief), 0},
83      {TK_CONFIG_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",      {TK_CONFIG_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",
84          DEF_SCROLLBAR_REPEAT_DELAY, Tk_Offset(TkScrollbar, repeatDelay), 0},          DEF_SCROLLBAR_REPEAT_DELAY, Tk_Offset(TkScrollbar, repeatDelay), 0},
85      {TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",      {TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",
86          DEF_SCROLLBAR_REPEAT_INTERVAL, Tk_Offset(TkScrollbar, repeatInterval), 0},          DEF_SCROLLBAR_REPEAT_INTERVAL, Tk_Offset(TkScrollbar, repeatInterval), 0},
87      {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",      {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
88          DEF_SCROLLBAR_TAKE_FOCUS, Tk_Offset(TkScrollbar, takeFocus),          DEF_SCROLLBAR_TAKE_FOCUS, Tk_Offset(TkScrollbar, takeFocus),
89          TK_CONFIG_NULL_OK},          TK_CONFIG_NULL_OK},
90      {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",      {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",
91          DEF_SCROLLBAR_TROUGH_COLOR, Tk_Offset(TkScrollbar, troughColorPtr),          DEF_SCROLLBAR_TROUGH_COLOR, Tk_Offset(TkScrollbar, troughColorPtr),
92          TK_CONFIG_COLOR_ONLY},          TK_CONFIG_COLOR_ONLY},
93      {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",      {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",
94          DEF_SCROLLBAR_TROUGH_MONO, Tk_Offset(TkScrollbar, troughColorPtr),          DEF_SCROLLBAR_TROUGH_MONO, Tk_Offset(TkScrollbar, troughColorPtr),
95          TK_CONFIG_MONO_ONLY},          TK_CONFIG_MONO_ONLY},
96      {TK_CONFIG_PIXELS, "-width", "width", "Width",      {TK_CONFIG_PIXELS, "-width", "width", "Width",
97          DEF_SCROLLBAR_WIDTH, Tk_Offset(TkScrollbar, width), 0},          DEF_SCROLLBAR_WIDTH, Tk_Offset(TkScrollbar, width), 0},
98      {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,      {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
99          (char *) NULL, 0, 0}          (char *) NULL, 0, 0}
100  };  };
101    
102  /*  /*
103   * Forward declarations for procedures defined later in this file:   * Forward declarations for procedures defined later in this file:
104   */   */
105    
106  static int              ConfigureScrollbar _ANSI_ARGS_((Tcl_Interp *interp,  static int              ConfigureScrollbar _ANSI_ARGS_((Tcl_Interp *interp,
107                              TkScrollbar *scrollPtr, int argc, char **argv,                              TkScrollbar *scrollPtr, int argc, char **argv,
108                              int flags));                              int flags));
109  static void             ScrollbarCmdDeletedProc _ANSI_ARGS_((  static void             ScrollbarCmdDeletedProc _ANSI_ARGS_((
110                              ClientData clientData));                              ClientData clientData));
111  static int              ScrollbarWidgetCmd _ANSI_ARGS_((ClientData clientData,  static int              ScrollbarWidgetCmd _ANSI_ARGS_((ClientData clientData,
112                              Tcl_Interp *, int argc, char **argv));                              Tcl_Interp *, int argc, char **argv));
113    
114  /*  /*
115   *--------------------------------------------------------------   *--------------------------------------------------------------
116   *   *
117   * Tk_ScrollbarCmd --   * Tk_ScrollbarCmd --
118   *   *
119   *      This procedure is invoked to process the "scrollbar" Tcl   *      This procedure is invoked to process the "scrollbar" Tcl
120   *      command.  See the user documentation for details on what   *      command.  See the user documentation for details on what
121   *      it does.   *      it does.
122   *   *
123   * Results:   * Results:
124   *      A standard Tcl result.   *      A standard Tcl result.
125   *   *
126   * Side effects:   * Side effects:
127   *      See the user documentation.   *      See the user documentation.
128   *   *
129   *--------------------------------------------------------------   *--------------------------------------------------------------
130   */   */
131    
132  int  int
133  Tk_ScrollbarCmd(clientData, interp, argc, argv)  Tk_ScrollbarCmd(clientData, interp, argc, argv)
134      ClientData clientData;      /* Main window associated with      ClientData clientData;      /* Main window associated with
135                                   * interpreter. */                                   * interpreter. */
136      Tcl_Interp *interp;         /* Current interpreter. */      Tcl_Interp *interp;         /* Current interpreter. */
137      int argc;                   /* Number of arguments. */      int argc;                   /* Number of arguments. */
138      char **argv;                /* Argument strings. */      char **argv;                /* Argument strings. */
139  {  {
140      Tk_Window tkwin = (Tk_Window) clientData;      Tk_Window tkwin = (Tk_Window) clientData;
141      register TkScrollbar *scrollPtr;      register TkScrollbar *scrollPtr;
142      Tk_Window new;      Tk_Window new;
143    
144      if (argc < 2) {      if (argc < 2) {
145          Tcl_AppendResult(interp, "wrong # args: should be \"",          Tcl_AppendResult(interp, "wrong # args: should be \"",
146                  argv[0], " pathName ?options?\"", (char *) NULL);                  argv[0], " pathName ?options?\"", (char *) NULL);
147          return TCL_ERROR;          return TCL_ERROR;
148      }      }
149    
150      new = Tk_CreateWindowFromPath(interp, tkwin, argv[1], (char *) NULL);      new = Tk_CreateWindowFromPath(interp, tkwin, argv[1], (char *) NULL);
151      if (new == NULL) {      if (new == NULL) {
152          return TCL_ERROR;          return TCL_ERROR;
153      }      }
154    
155      Tk_SetClass(new, "Scrollbar");      Tk_SetClass(new, "Scrollbar");
156      scrollPtr = TkpCreateScrollbar(new);      scrollPtr = TkpCreateScrollbar(new);
157    
158      TkSetClassProcs(new, &tkpScrollbarProcs, (ClientData) scrollPtr);      TkSetClassProcs(new, &tkpScrollbarProcs, (ClientData) scrollPtr);
159    
160      /*      /*
161       * Initialize fields that won't be initialized by ConfigureScrollbar,       * Initialize fields that won't be initialized by ConfigureScrollbar,
162       * or which ConfigureScrollbar expects to have reasonable values       * or which ConfigureScrollbar expects to have reasonable values
163       * (e.g. resource pointers).       * (e.g. resource pointers).
164       */       */
165    
166      scrollPtr->tkwin = new;      scrollPtr->tkwin = new;
167      scrollPtr->display = Tk_Display(new);      scrollPtr->display = Tk_Display(new);
168      scrollPtr->interp = interp;      scrollPtr->interp = interp;
169      scrollPtr->widgetCmd = Tcl_CreateCommand(interp,      scrollPtr->widgetCmd = Tcl_CreateCommand(interp,
170              Tk_PathName(scrollPtr->tkwin), ScrollbarWidgetCmd,              Tk_PathName(scrollPtr->tkwin), ScrollbarWidgetCmd,
171              (ClientData) scrollPtr, ScrollbarCmdDeletedProc);              (ClientData) scrollPtr, ScrollbarCmdDeletedProc);
172      scrollPtr->vertical = 0;      scrollPtr->vertical = 0;
173      scrollPtr->width = 0;      scrollPtr->width = 0;
174      scrollPtr->command = NULL;      scrollPtr->command = NULL;
175      scrollPtr->commandSize = 0;      scrollPtr->commandSize = 0;
176      scrollPtr->repeatDelay = 0;      scrollPtr->repeatDelay = 0;
177      scrollPtr->repeatInterval = 0;      scrollPtr->repeatInterval = 0;
178      scrollPtr->borderWidth = 0;      scrollPtr->borderWidth = 0;
179      scrollPtr->bgBorder = NULL;      scrollPtr->bgBorder = NULL;
180      scrollPtr->activeBorder = NULL;      scrollPtr->activeBorder = NULL;
181      scrollPtr->troughColorPtr = NULL;      scrollPtr->troughColorPtr = NULL;
182      scrollPtr->relief = TK_RELIEF_FLAT;      scrollPtr->relief = TK_RELIEF_FLAT;
183      scrollPtr->highlightWidth = 0;      scrollPtr->highlightWidth = 0;
184      scrollPtr->highlightBgColorPtr = NULL;      scrollPtr->highlightBgColorPtr = NULL;
185      scrollPtr->highlightColorPtr = NULL;      scrollPtr->highlightColorPtr = NULL;
186      scrollPtr->inset = 0;      scrollPtr->inset = 0;
187      scrollPtr->elementBorderWidth = -1;      scrollPtr->elementBorderWidth = -1;
188      scrollPtr->arrowLength = 0;      scrollPtr->arrowLength = 0;
189      scrollPtr->sliderFirst = 0;      scrollPtr->sliderFirst = 0;
190      scrollPtr->sliderLast = 0;      scrollPtr->sliderLast = 0;
191      scrollPtr->activeField = 0;      scrollPtr->activeField = 0;
192      scrollPtr->activeRelief = TK_RELIEF_RAISED;      scrollPtr->activeRelief = TK_RELIEF_RAISED;
193      scrollPtr->totalUnits = 0;      scrollPtr->totalUnits = 0;
194      scrollPtr->windowUnits = 0;      scrollPtr->windowUnits = 0;
195      scrollPtr->firstUnit = 0;      scrollPtr->firstUnit = 0;
196      scrollPtr->lastUnit = 0;      scrollPtr->lastUnit = 0;
197      scrollPtr->firstFraction = 0.0;      scrollPtr->firstFraction = 0.0;
198      scrollPtr->lastFraction = 0.0;      scrollPtr->lastFraction = 0.0;
199      scrollPtr->cursor = None;      scrollPtr->cursor = None;
200      scrollPtr->takeFocus = NULL;      scrollPtr->takeFocus = NULL;
201      scrollPtr->flags = 0;      scrollPtr->flags = 0;
202    
203      if (ConfigureScrollbar(interp, scrollPtr, argc-2, argv+2, 0) != TCL_OK) {      if (ConfigureScrollbar(interp, scrollPtr, argc-2, argv+2, 0) != TCL_OK) {
204          Tk_DestroyWindow(scrollPtr->tkwin);          Tk_DestroyWindow(scrollPtr->tkwin);
205          return TCL_ERROR;          return TCL_ERROR;
206      }      }
207    
208      Tcl_SetResult(interp, Tk_PathName(scrollPtr->tkwin), TCL_STATIC);      Tcl_SetResult(interp, Tk_PathName(scrollPtr->tkwin), TCL_STATIC);
209      return TCL_OK;      return TCL_OK;
210  }  }
211    
212  /*  /*
213   *--------------------------------------------------------------   *--------------------------------------------------------------
214   *   *
215   * ScrollbarWidgetCmd --   * ScrollbarWidgetCmd --
216   *   *
217   *      This procedure is invoked to process the Tcl command   *      This procedure is invoked to process the Tcl command
218   *      that corresponds to a widget managed by this module.   *      that corresponds to a widget managed by this module.
219   *      See the user documentation for details on what it does.   *      See the user documentation for details on what it does.
220   *   *
221   * Results:   * Results:
222   *      A standard Tcl result.   *      A standard Tcl result.
223   *   *
224   * Side effects:   * Side effects:
225   *      See the user documentation.   *      See the user documentation.
226   *   *
227   *--------------------------------------------------------------   *--------------------------------------------------------------
228   */   */
229    
230  static int  static int
231  ScrollbarWidgetCmd(clientData, interp, argc, argv)  ScrollbarWidgetCmd(clientData, interp, argc, argv)
232      ClientData clientData;      /* Information about scrollbar      ClientData clientData;      /* Information about scrollbar
233                                           * widget. */                                           * widget. */
234      Tcl_Interp *interp;                 /* Current interpreter. */      Tcl_Interp *interp;                 /* Current interpreter. */
235      int argc;                           /* Number of arguments. */      int argc;                           /* Number of arguments. */
236      char **argv;                        /* Argument strings. */      char **argv;                        /* Argument strings. */
237  {  {
238      register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;      register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
239      int result = TCL_OK;      int result = TCL_OK;
240      size_t length;      size_t length;
241      int c;      int c;
242    
243      if (argc < 2) {      if (argc < 2) {
244          Tcl_AppendResult(interp, "wrong # args: should be \"",          Tcl_AppendResult(interp, "wrong # args: should be \"",
245                  argv[0], " option ?arg arg ...?\"", (char *) NULL);                  argv[0], " option ?arg arg ...?\"", (char *) NULL);
246          return TCL_ERROR;          return TCL_ERROR;
247      }      }
248      Tcl_Preserve((ClientData) scrollPtr);      Tcl_Preserve((ClientData) scrollPtr);
249      c = argv[1][0];      c = argv[1][0];
250      length = strlen(argv[1]);      length = strlen(argv[1]);
251      if ((c == 'a') && (strncmp(argv[1], "activate", length) == 0)) {      if ((c == 'a') && (strncmp(argv[1], "activate", length) == 0)) {
252          int oldActiveField;          int oldActiveField;
253          if (argc == 2) {          if (argc == 2) {
254              switch (scrollPtr->activeField) {              switch (scrollPtr->activeField) {
255                  case TOP_ARROW:                  case TOP_ARROW:
256                      Tcl_SetResult(interp, "arrow1", TCL_STATIC);                      Tcl_SetResult(interp, "arrow1", TCL_STATIC);
257                      break;                      break;
258                  case SLIDER:                  case SLIDER:
259                      Tcl_SetResult(interp, "slider", TCL_STATIC);                      Tcl_SetResult(interp, "slider", TCL_STATIC);
260                      break;                      break;
261                  case BOTTOM_ARROW:                  case BOTTOM_ARROW:
262                      Tcl_SetResult(interp, "arrow2", TCL_STATIC);                      Tcl_SetResult(interp, "arrow2", TCL_STATIC);
263                      break;                      break;
264              }              }
265              goto done;              goto done;
266          }          }
267          if (argc != 3) {          if (argc != 3) {
268              Tcl_AppendResult(interp, "wrong # args: should be \"",              Tcl_AppendResult(interp, "wrong # args: should be \"",
269                      argv[0], " activate element\"", (char *) NULL);                      argv[0], " activate element\"", (char *) NULL);
270              goto error;              goto error;
271          }          }
272          c = argv[2][0];          c = argv[2][0];
273          length = strlen(argv[2]);          length = strlen(argv[2]);
274          oldActiveField = scrollPtr->activeField;          oldActiveField = scrollPtr->activeField;
275          if ((c == 'a') && (strcmp(argv[2], "arrow1") == 0)) {          if ((c == 'a') && (strcmp(argv[2], "arrow1") == 0)) {
276              scrollPtr->activeField = TOP_ARROW;              scrollPtr->activeField = TOP_ARROW;
277          } else if ((c == 'a') && (strcmp(argv[2], "arrow2") == 0)) {          } else if ((c == 'a') && (strcmp(argv[2], "arrow2") == 0)) {
278              scrollPtr->activeField = BOTTOM_ARROW;              scrollPtr->activeField = BOTTOM_ARROW;
279          } else if ((c == 's') && (strncmp(argv[2], "slider", length) == 0)) {          } else if ((c == 's') && (strncmp(argv[2], "slider", length) == 0)) {
280              scrollPtr->activeField = SLIDER;              scrollPtr->activeField = SLIDER;
281          } else {          } else {
282              scrollPtr->activeField = OUTSIDE;              scrollPtr->activeField = OUTSIDE;
283          }          }
284          if (oldActiveField != scrollPtr->activeField) {          if (oldActiveField != scrollPtr->activeField) {
285              TkScrollbarEventuallyRedraw(scrollPtr);              TkScrollbarEventuallyRedraw(scrollPtr);
286          }          }
287      } else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)      } else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)
288              && (length >= 2)) {              && (length >= 2)) {
289          if (argc != 3) {          if (argc != 3) {
290              Tcl_AppendResult(interp, "wrong # args: should be \"",              Tcl_AppendResult(interp, "wrong # args: should be \"",
291                      argv[0], " cget option\"",                      argv[0], " cget option\"",
292                      (char *) NULL);                      (char *) NULL);
293              goto error;              goto error;
294          }          }
295          result = Tk_ConfigureValue(interp, scrollPtr->tkwin,          result = Tk_ConfigureValue(interp, scrollPtr->tkwin,
296                  tkpScrollbarConfigSpecs, (char *) scrollPtr, argv[2], 0);                  tkpScrollbarConfigSpecs, (char *) scrollPtr, argv[2], 0);
297      } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)      } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
298              && (length >= 2)) {              && (length >= 2)) {
299          if (argc == 2) {          if (argc == 2) {
300              result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,              result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
301                      tkpScrollbarConfigSpecs, (char *) scrollPtr,                      tkpScrollbarConfigSpecs, (char *) scrollPtr,
302                      (char *) NULL, 0);                      (char *) NULL, 0);
303          } else if (argc == 3) {          } else if (argc == 3) {
304              result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,              result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
305                      tkpScrollbarConfigSpecs, (char *) scrollPtr, argv[2], 0);                      tkpScrollbarConfigSpecs, (char *) scrollPtr, argv[2], 0);
306          } else {          } else {
307              result = ConfigureScrollbar(interp, scrollPtr, argc-2, argv+2,              result = ConfigureScrollbar(interp, scrollPtr, argc-2, argv+2,
308                      TK_CONFIG_ARGV_ONLY);                      TK_CONFIG_ARGV_ONLY);
309          }          }
310      } else if ((c == 'd') && (strncmp(argv[1], "delta", length) == 0)) {      } else if ((c == 'd') && (strncmp(argv[1], "delta", length) == 0)) {
311          int xDelta, yDelta, pixels, length;          int xDelta, yDelta, pixels, length;
312          double fraction;          double fraction;
313          char buf[TCL_DOUBLE_SPACE];          char buf[TCL_DOUBLE_SPACE];
314    
315          if (argc != 4) {          if (argc != 4) {
316              Tcl_AppendResult(interp, "wrong # args: should be \"",              Tcl_AppendResult(interp, "wrong # args: should be \"",
317                      argv[0], " delta xDelta yDelta\"", (char *) NULL);                      argv[0], " delta xDelta yDelta\"", (char *) NULL);
318              goto error;              goto error;
319          }          }
320          if ((Tcl_GetInt(interp, argv[2], &xDelta) != TCL_OK)          if ((Tcl_GetInt(interp, argv[2], &xDelta) != TCL_OK)
321                  || (Tcl_GetInt(interp, argv[3], &yDelta) != TCL_OK)) {                  || (Tcl_GetInt(interp, argv[3], &yDelta) != TCL_OK)) {
322              goto error;              goto error;
323          }          }
324          if (scrollPtr->vertical) {          if (scrollPtr->vertical) {
325              pixels = yDelta;              pixels = yDelta;
326              length = Tk_Height(scrollPtr->tkwin) - 1              length = Tk_Height(scrollPtr->tkwin) - 1
327                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);
328          } else {          } else {
329              pixels = xDelta;              pixels = xDelta;
330              length = Tk_Width(scrollPtr->tkwin) - 1              length = Tk_Width(scrollPtr->tkwin) - 1
331                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);
332          }          }
333          if (length == 0) {          if (length == 0) {
334              fraction = 0.0;              fraction = 0.0;
335          } else {          } else {
336              fraction = ((double) pixels / (double) length);              fraction = ((double) pixels / (double) length);
337          }          }
338          sprintf(buf, "%g", fraction);          sprintf(buf, "%g", fraction);
339          Tcl_SetResult(interp, buf, TCL_VOLATILE);          Tcl_SetResult(interp, buf, TCL_VOLATILE);
340      } else if ((c == 'f') && (strncmp(argv[1], "fraction", length) == 0)) {      } else if ((c == 'f') && (strncmp(argv[1], "fraction", length) == 0)) {
341          int x, y, pos, length;          int x, y, pos, length;
342          double fraction;          double fraction;
343          char buf[TCL_DOUBLE_SPACE];          char buf[TCL_DOUBLE_SPACE];
344    
345          if (argc != 4) {          if (argc != 4) {
346              Tcl_AppendResult(interp, "wrong # args: should be \"",              Tcl_AppendResult(interp, "wrong # args: should be \"",
347                      argv[0], " fraction x y\"", (char *) NULL);                      argv[0], " fraction x y\"", (char *) NULL);
348              goto error;              goto error;
349          }          }
350          if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)          if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)
351                  || (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) {                  || (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) {
352              goto error;              goto error;
353          }          }
354          if (scrollPtr->vertical) {          if (scrollPtr->vertical) {
355              pos = y - (scrollPtr->arrowLength + scrollPtr->inset);              pos = y - (scrollPtr->arrowLength + scrollPtr->inset);
356              length = Tk_Height(scrollPtr->tkwin) - 1              length = Tk_Height(scrollPtr->tkwin) - 1
357                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);
358          } else {          } else {
359              pos = x - (scrollPtr->arrowLength + scrollPtr->inset);              pos = x - (scrollPtr->arrowLength + scrollPtr->inset);
360              length = Tk_Width(scrollPtr->tkwin) - 1              length = Tk_Width(scrollPtr->tkwin) - 1
361                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);                      - 2*(scrollPtr->arrowLength + scrollPtr->inset);
362          }          }
363          if (length == 0) {          if (length == 0) {
364              fraction = 0.0;              fraction = 0.0;
365          } else {          } else {
366              fraction = ((double) pos / (double) length);              fraction = ((double) pos / (double) length);
367          }          }
368          if (fraction < 0) {          if (fraction < 0) {
369              fraction = 0;              fraction = 0;
370          } else if (fraction > 1.0) {          } else if (fraction > 1.0) {
371              fraction = 1.0;              fraction = 1.0;
372          }          }
373          sprintf(buf, "%g", fraction);          sprintf(buf, "%g", fraction);
374          Tcl_SetResult(interp, buf, TCL_VOLATILE);          Tcl_SetResult(interp, buf, TCL_VOLATILE);
375      } else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) {      } else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) {
376          if (argc != 2) {          if (argc != 2) {
377              Tcl_AppendResult(interp, "wrong # args: should be \"",              Tcl_AppendResult(interp, "wrong # args: should be \"",
378                      argv[0], " get\"", (char *) NULL);                      argv[0], " get\"", (char *) NULL);
379              goto error;              goto error;
380          }          }
381          if (scrollPtr->flags & NEW_STYLE_COMMANDS) {          if (scrollPtr->flags & NEW_STYLE_COMMANDS) {
382              char first[TCL_DOUBLE_SPACE], last[TCL_DOUBLE_SPACE];              char first[TCL_DOUBLE_SPACE], last[TCL_DOUBLE_SPACE];
383    
384              Tcl_PrintDouble(interp, scrollPtr->firstFraction, first);              Tcl_PrintDouble(interp, scrollPtr->firstFraction, first);
385              Tcl_PrintDouble(interp, scrollPtr->lastFraction, last);              Tcl_PrintDouble(interp, scrollPtr->lastFraction, last);
386              Tcl_AppendResult(interp, first, " ", last, (char *) NULL);              Tcl_AppendResult(interp, first, " ", last, (char *) NULL);
387          } else {          } else {
388              char buf[TCL_INTEGER_SPACE * 4];              char buf[TCL_INTEGER_SPACE * 4];
389    
390              sprintf(buf, "%d %d %d %d", scrollPtr->totalUnits,              sprintf(buf, "%d %d %d %d", scrollPtr->totalUnits,
391                      scrollPtr->windowUnits, scrollPtr->firstUnit,                      scrollPtr->windowUnits, scrollPtr->firstUnit,
392                      scrollPtr->lastUnit);                      scrollPtr->lastUnit);
393              Tcl_SetResult(interp, buf, TCL_VOLATILE);              Tcl_SetResult(interp, buf, TCL_VOLATILE);
394          }          }
395      } else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) {      } else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) {
396          int x, y, thing;          int x, y, thing;
397    
398          if (argc != 4) {          if (argc != 4) {
399              Tcl_AppendResult(interp, "wrong # args: should be \"",              Tcl_AppendResult(interp, "wrong # args: should be \"",
400                      argv[0], " identify x y\"", (char *) NULL);                      argv[0], " identify x y\"", (char *) NULL);
401              goto error;              goto error;
402          }          }
403          if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)          if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)
404                  || (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) {                  || (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) {
405              goto error;              goto error;
406          }          }
407          thing = TkpScrollbarPosition(scrollPtr, x,y);          thing = TkpScrollbarPosition(scrollPtr, x,y);
408          switch (thing) {          switch (thing) {
409              case TOP_ARROW:              case TOP_ARROW:
410                  Tcl_SetResult(interp, "arrow1", TCL_STATIC);                  Tcl_SetResult(interp, "arrow1", TCL_STATIC);
411                  break;                  break;
412              case TOP_GAP:              case TOP_GAP:
413                  Tcl_SetResult(interp, "trough1", TCL_STATIC);                  Tcl_SetResult(interp, "trough1", TCL_STATIC);
414                  break;                  break;
415              case SLIDER:              case SLIDER:
416                  Tcl_SetResult(interp, "slider", TCL_STATIC);                  Tcl_SetResult(interp, "slider", TCL_STATIC);
417                  break;                  break;
418              case BOTTOM_GAP:              case BOTTOM_GAP:
419                  Tcl_SetResult(interp, "trough2", TCL_STATIC);                  Tcl_SetResult(interp, "trough2", TCL_STATIC);
420                  break;                  break;
421              case BOTTOM_ARROW:              case BOTTOM_ARROW:
422                  Tcl_SetResult(interp, "arrow2", TCL_STATIC);                  Tcl_SetResult(interp, "arrow2", TCL_STATIC);
423                  break;                  break;
424          }          }
425      } else if ((c == 's') && (strncmp(argv[1], "set", length) == 0)) {      } else if ((c == 's') && (strncmp(argv[1], "set", length) == 0)) {
426          int totalUnits, windowUnits, firstUnit, lastUnit;          int totalUnits, windowUnits, firstUnit, lastUnit;
427    
428          if (argc == 4) {          if (argc == 4) {
429              double first, last;              double first, last;
430    
431              if (Tcl_GetDouble(interp, argv[2], &first) != TCL_OK) {              if (Tcl_GetDouble(interp, argv[2], &first) != TCL_OK) {
432                  goto error;                  goto error;
433              }              }
434              if (Tcl_GetDouble(interp, argv[3], &last) != TCL_OK) {              if (Tcl_GetDouble(interp, argv[3], &last) != TCL_OK) {
435                  goto error;                  goto error;
436              }              }
437              if (first < 0) {              if (first < 0) {
438                  scrollPtr->firstFraction = 0;                  scrollPtr->firstFraction = 0;
439              } else if (first > 1.0) {              } else if (first > 1.0) {
440                  scrollPtr->firstFraction = 1.0;                  scrollPtr->firstFraction = 1.0;
441              } else {              } else {
442                  scrollPtr->firstFraction = first;                  scrollPtr->firstFraction = first;
443              }              }
444              if (last < scrollPtr->firstFraction) {              if (last < scrollPtr->firstFraction) {
445                  scrollPtr->lastFraction = scrollPtr->firstFraction;                  scrollPtr->lastFraction = scrollPtr->firstFraction;
446              } else if (last > 1.0) {              } else if (last > 1.0) {
447                  scrollPtr->lastFraction = 1.0;                  scrollPtr->lastFraction = 1.0;
448              } else {              } else {
449                  scrollPtr->lastFraction = last;                  scrollPtr->lastFraction = last;
450              }              }
451              scrollPtr->flags |= NEW_STYLE_COMMANDS;              scrollPtr->flags |= NEW_STYLE_COMMANDS;
452          } else if (argc == 6) {          } else if (argc == 6) {
453              if (Tcl_GetInt(interp, argv[2], &totalUnits) != TCL_OK) {              if (Tcl_GetInt(interp, argv[2], &totalUnits) != TCL_OK) {
454                  goto error;                  goto error;
455              }              }
456              if (totalUnits < 0) {              if (totalUnits < 0) {
457                  totalUnits = 0;                  totalUnits = 0;
458              }              }
459              if (Tcl_GetInt(interp, argv[3], &windowUnits) != TCL_OK) {              if (Tcl_GetInt(interp, argv[3], &windowUnits) != TCL_OK) {
460                  goto error;                  goto error;
461              }              }
462              if (windowUnits < 0) {              if (windowUnits < 0) {
463                  windowUnits = 0;                  windowUnits = 0;
464              }              }
465              if (Tcl_GetInt(interp, argv[4], &firstUnit) != TCL_OK) {              if (Tcl_GetInt(interp, argv[4], &firstUnit) != TCL_OK) {
466                  goto error;                  goto error;
467              }              }
468              if (Tcl_GetInt(interp, argv[5], &lastUnit) != TCL_OK) {              if (Tcl_GetInt(interp, argv[5], &lastUnit) != TCL_OK) {
469                  goto error;                  goto error;
470              }              }
471              if (totalUnits > 0) {              if (totalUnits > 0) {
472                  if (lastUnit < firstUnit) {                  if (lastUnit < firstUnit) {
473                      lastUnit = firstUnit;                      lastUnit = firstUnit;
474                  }                  }
475              } else {              } else {
476                  firstUnit = lastUnit = 0;                  firstUnit = lastUnit = 0;
477              }              }
478              scrollPtr->totalUnits = totalUnits;              scrollPtr->totalUnits = totalUnits;
479              scrollPtr->windowUnits = windowUnits;              scrollPtr->windowUnits = windowUnits;
480              scrollPtr->firstUnit = firstUnit;              scrollPtr->firstUnit = firstUnit;
481              scrollPtr->lastUnit = lastUnit;              scrollPtr->lastUnit = lastUnit;
482              if (scrollPtr->totalUnits == 0) {              if (scrollPtr->totalUnits == 0) {
483                  scrollPtr->firstFraction = 0.0;                  scrollPtr->firstFraction = 0.0;
484                  scrollPtr->lastFraction = 1.0;                  scrollPtr->lastFraction = 1.0;
485              } else {              } else {
486                  scrollPtr->firstFraction = ((double) firstUnit)/totalUnits;                  scrollPtr->firstFraction = ((double) firstUnit)/totalUnits;
487                  scrollPtr->lastFraction = ((double) (lastUnit+1))/totalUnits;                  scrollPtr->lastFraction = ((double) (lastUnit+1))/totalUnits;
488              }              }
489              scrollPtr->flags &= ~NEW_STYLE_COMMANDS;              scrollPtr->flags &= ~NEW_STYLE_COMMANDS;
490          } else {          } else {
491              Tcl_AppendResult(interp, "wrong # args: should be \"",              Tcl_AppendResult(interp, "wrong # args: should be \"",
492                      argv[0], " set firstFraction lastFraction\" or \"",                      argv[0], " set firstFraction lastFraction\" or \"",
493                      argv[0],                      argv[0],
494                      " set totalUnits windowUnits firstUnit lastUnit\"",                      " set totalUnits windowUnits firstUnit lastUnit\"",
495                      (char *) NULL);                      (char *) NULL);
496              goto error;              goto error;
497          }          }
498          TkpComputeScrollbarGeometry(scrollPtr);          TkpComputeScrollbarGeometry(scrollPtr);
499          TkScrollbarEventuallyRedraw(scrollPtr);          TkScrollbarEventuallyRedraw(scrollPtr);
500      } else {      } else {
501          Tcl_AppendResult(interp, "bad option \"", argv[1],          Tcl_AppendResult(interp, "bad option \"", argv[1],
502                  "\": must be activate, cget, configure, delta, fraction, ",                  "\": must be activate, cget, configure, delta, fraction, ",
503                  "get, identify, or set", (char *) NULL);                  "get, identify, or set", (char *) NULL);
504          goto error;          goto error;
505      }      }
506      done:      done:
507      Tcl_Release((ClientData) scrollPtr);      Tcl_Release((ClientData) scrollPtr);
508      return result;      return result;
509    
510      error:      error:
511      Tcl_Release((ClientData) scrollPtr);      Tcl_Release((ClientData) scrollPtr);
512      return TCL_ERROR;      return TCL_ERROR;
513  }  }
514    
515  /*  /*
516   *----------------------------------------------------------------------   *----------------------------------------------------------------------
517   *   *
518   * ConfigureScrollbar --   * ConfigureScrollbar --
519   *   *
520   *      This procedure is called to process an argv/argc list, plus   *      This procedure is called to process an argv/argc list, plus
521   *      the Tk option database, in order to configure (or   *      the Tk option database, in order to configure (or
522   *      reconfigure) a scrollbar widget.   *      reconfigure) a scrollbar widget.
523   *   *
524   * Results:   * Results:
525   *      The return value is a standard Tcl result.  If TCL_ERROR is   *      The return value is a standard Tcl result.  If TCL_ERROR is
526   *      returned, then the interp's result contains an error message.   *      returned, then the interp's result contains an error message.
527   *   *
528   * Side effects:   * Side effects:
529   *      Configuration information, such as colors, border width,   *      Configuration information, such as colors, border width,
530   *      etc. get set for scrollPtr;  old resources get freed,   *      etc. get set for scrollPtr;  old resources get freed,
531   *      if there were any.   *      if there were any.
532   *   *
533   *----------------------------------------------------------------------   *----------------------------------------------------------------------
534   */   */
535    
536  static int  static int
537  ConfigureScrollbar(interp, scrollPtr, argc, argv, flags)  ConfigureScrollbar(interp, scrollPtr, argc, argv, flags)
538      Tcl_Interp *interp;                 /* Used for error reporting. */      Tcl_Interp *interp;                 /* Used for error reporting. */
539      register TkScrollbar *scrollPtr;    /* Information about widget;  may or      register TkScrollbar *scrollPtr;    /* Information about widget;  may or
540                                           * may not already have values for                                           * may not already have values for
541                                           * some fields. */                                           * some fields. */
542      int argc;                           /* Number of valid entries in argv. */      int argc;                           /* Number of valid entries in argv. */
543      char **argv;                        /* Arguments. */      char **argv;                        /* Arguments. */
544      int flags;                          /* Flags to pass to      int flags;                          /* Flags to pass to
545                                           * Tk_ConfigureWidget. */                                           * Tk_ConfigureWidget. */
546  {  {
547      if (Tk_ConfigureWidget(interp, scrollPtr->tkwin, tkpScrollbarConfigSpecs,      if (Tk_ConfigureWidget(interp, scrollPtr->tkwin, tkpScrollbarConfigSpecs,
548              argc, argv, (char *) scrollPtr, flags) != TCL_OK) {              argc, argv, (char *) scrollPtr, flags) != TCL_OK) {
549          return TCL_ERROR;          return TCL_ERROR;
550      }      }
551    
552      /*      /*
553       * A few options need special processing, such as setting the       * A few options need special processing, such as setting the
554       * background from a 3-D border.       * background from a 3-D border.
555       */       */
556    
557      if (scrollPtr->command != NULL) {      if (scrollPtr->command != NULL) {
558          scrollPtr->commandSize = strlen(scrollPtr->command);          scrollPtr->commandSize = strlen(scrollPtr->command);
559      } else {      } else {
560          scrollPtr->commandSize = 0;          scrollPtr->commandSize = 0;
561      }      }
562    
563      /*      /*
564       * Configure platform specific options.       * Configure platform specific options.
565       */       */
566    
567      TkpConfigureScrollbar(scrollPtr);      TkpConfigureScrollbar(scrollPtr);
568    
569      /*      /*
570       * Register the desired geometry for the window (leave enough space       * Register the desired geometry for the window (leave enough space
571       * for the two arrows plus a minimum-size slider, plus border around       * for the two arrows plus a minimum-size slider, plus border around
572       * the whole window, if any).  Then arrange for the window to be       * the whole window, if any).  Then arrange for the window to be
573       * redisplayed.       * redisplayed.
574       */       */
575    
576      TkpComputeScrollbarGeometry(scrollPtr);      TkpComputeScrollbarGeometry(scrollPtr);
577      TkScrollbarEventuallyRedraw(scrollPtr);      TkScrollbarEventuallyRedraw(scrollPtr);
578      return TCL_OK;      return TCL_OK;
579  }  }
580    
581  /*  /*
582   *--------------------------------------------------------------   *--------------------------------------------------------------
583   *   *
584   * TkScrollbarEventProc --   * TkScrollbarEventProc --
585   *   *
586   *      This procedure is invoked by the Tk dispatcher for various   *      This procedure is invoked by the Tk dispatcher for various
587   *      events on scrollbars.   *      events on scrollbars.
588   *   *
589   * Results:   * Results:
590   *      None.   *      None.
591   *   *
592   * Side effects:   * Side effects:
593   *      When the window gets deleted, internal structures get   *      When the window gets deleted, internal structures get
594   *      cleaned up.  When it gets exposed, it is redisplayed.   *      cleaned up.  When it gets exposed, it is redisplayed.
595   *   *
596   *--------------------------------------------------------------   *--------------------------------------------------------------
597   */   */
598    
599  void  void
600  TkScrollbarEventProc(clientData, eventPtr)  TkScrollbarEventProc(clientData, eventPtr)
601      ClientData clientData;      /* Information about window. */      ClientData clientData;      /* Information about window. */
602      XEvent *eventPtr;           /* Information about event. */      XEvent *eventPtr;           /* Information about event. */
603  {  {
604      TkScrollbar *scrollPtr = (TkScrollbar *) clientData;      TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
605    
606      if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {      if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
607          TkScrollbarEventuallyRedraw(scrollPtr);          TkScrollbarEventuallyRedraw(scrollPtr);
608      } else if (eventPtr->type == DestroyNotify) {      } else if (eventPtr->type == DestroyNotify) {
609          TkpDestroyScrollbar(scrollPtr);          TkpDestroyScrollbar(scrollPtr);
610          if (scrollPtr->tkwin != NULL) {          if (scrollPtr->tkwin != NULL) {
611              scrollPtr->tkwin = NULL;              scrollPtr->tkwin = NULL;
612              Tcl_DeleteCommandFromToken(scrollPtr->interp,              Tcl_DeleteCommandFromToken(scrollPtr->interp,
613                      scrollPtr->widgetCmd);                      scrollPtr->widgetCmd);
614          }          }
615          if (scrollPtr->flags & REDRAW_PENDING) {          if (scrollPtr->flags & REDRAW_PENDING) {
616              Tcl_CancelIdleCall(TkpDisplayScrollbar, (ClientData) scrollPtr);              Tcl_CancelIdleCall(TkpDisplayScrollbar, (ClientData) scrollPtr);
617          }          }
618          /*          /*
619           * Free up all the stuff that requires special handling, then           * Free up all the stuff that requires special handling, then
620           * let Tk_FreeOptions handle all the standard option-related           * let Tk_FreeOptions handle all the standard option-related
621           * stuff.           * stuff.
622           */           */
623                    
624          Tk_FreeOptions(tkpScrollbarConfigSpecs, (char *) scrollPtr,          Tk_FreeOptions(tkpScrollbarConfigSpecs, (char *) scrollPtr,
625                  scrollPtr->display, 0);                  scrollPtr->display, 0);
626          Tcl_EventuallyFree((ClientData) scrollPtr, TCL_DYNAMIC);          Tcl_EventuallyFree((ClientData) scrollPtr, TCL_DYNAMIC);
627      } else if (eventPtr->type == ConfigureNotify) {      } else if (eventPtr->type == ConfigureNotify) {
628          TkpComputeScrollbarGeometry(scrollPtr);          TkpComputeScrollbarGeometry(scrollPtr);
629          TkScrollbarEventuallyRedraw(scrollPtr);          TkScrollbarEventuallyRedraw(scrollPtr);
630      } else if (eventPtr->type == FocusIn) {      } else if (eventPtr->type == FocusIn) {
631          if (eventPtr->xfocus.detail != NotifyInferior) {          if (eventPtr->xfocus.detail != NotifyInferior) {
632              scrollPtr->flags |= GOT_FOCUS;              scrollPtr->flags |= GOT_FOCUS;
633              if (scrollPtr->highlightWidth > 0) {              if (scrollPtr->highlightWidth > 0) {
634                  TkScrollbarEventuallyRedraw(scrollPtr);                  TkScrollbarEventuallyRedraw(scrollPtr);
635              }              }
636          }          }
637      } else if (eventPtr->type == FocusOut) {      } else if (eventPtr->type == FocusOut) {
638          if (eventPtr->xfocus.detail != NotifyInferior) {          if (eventPtr->xfocus.detail != NotifyInferior) {
639              scrollPtr->flags &= ~GOT_FOCUS;              scrollPtr->flags &= ~GOT_FOCUS;
640              if (scrollPtr->highlightWidth > 0) {              if (scrollPtr->highlightWidth > 0) {
641                  TkScrollbarEventuallyRedraw(scrollPtr);                  TkScrollbarEventuallyRedraw(scrollPtr);
642              }              }
643          }          }
644      }      }
645  }  }
646    
647  /*  /*
648   *----------------------------------------------------------------------   *----------------------------------------------------------------------
649   *   *
650   * ScrollbarCmdDeletedProc --   * ScrollbarCmdDeletedProc --
651   *   *
652   *      This procedure is invoked when a widget command is deleted.  If   *      This procedure is invoked when a widget command is deleted.  If
653   *      the widget isn't already in the process of being destroyed,   *      the widget isn't already in the process of being destroyed,
654   *      this command destroys it.   *      this command destroys it.
655   *   *
656   * Results:   * Results:
657   *      None.   *      None.
658   *   *
659   * Side effects:   * Side effects:
660   *      The widget is destroyed.   *      The widget is destroyed.
661   *   *
662   *----------------------------------------------------------------------   *----------------------------------------------------------------------
663   */   */
664    
665  static void  static void
666  ScrollbarCmdDeletedProc(clientData)  ScrollbarCmdDeletedProc(clientData)
667      ClientData clientData;      /* Pointer to widget record for widget. */      ClientData clientData;      /* Pointer to widget record for widget. */
668  {  {
669      TkScrollbar *scrollPtr = (TkScrollbar *) clientData;      TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
670      Tk_Window tkwin = scrollPtr->tkwin;      Tk_Window tkwin = scrollPtr->tkwin;
671    
672      /*      /*
673       * This procedure could be invoked either because the window was       * This procedure could be invoked either because the window was
674       * destroyed and the command was then deleted (in which case tkwin       * destroyed and the command was then deleted (in which case tkwin
675       * is NULL) or because the command was deleted, and then this procedure       * is NULL) or because the command was deleted, and then this procedure
676       * destroys the widget.       * destroys the widget.
677       */       */
678    
679      if (tkwin != NULL) {      if (tkwin != NULL) {
680          scrollPtr->tkwin = NULL;          scrollPtr->tkwin = NULL;
681          Tk_DestroyWindow(tkwin);          Tk_DestroyWindow(tkwin);
682      }      }
683  }  }
684    
685  /*  /*
686   *--------------------------------------------------------------   *--------------------------------------------------------------
687   *   *
688   * TkScrollbarEventuallyRedraw --   * TkScrollbarEventuallyRedraw --
689   *   *
690   *      Arrange for one or more of the fields of a scrollbar   *      Arrange for one or more of the fields of a scrollbar
691   *      to be redrawn.   *      to be redrawn.
692   *   *
693   * Results:   * Results:
694   *      None.   *      None.
695   *   *
696   * Side effects:   * Side effects:
697   *      None.   *      None.
698   *   *
699   *--------------------------------------------------------------   *--------------------------------------------------------------
700   */   */
701    
702  void  void
703  TkScrollbarEventuallyRedraw(scrollPtr)  TkScrollbarEventuallyRedraw(scrollPtr)
704      register TkScrollbar *scrollPtr;    /* Information about widget. */      register TkScrollbar *scrollPtr;    /* Information about widget. */
705  {  {
706      if ((scrollPtr->tkwin == NULL) || (!Tk_IsMapped(scrollPtr->tkwin))) {      if ((scrollPtr->tkwin == NULL) || (!Tk_IsMapped(scrollPtr->tkwin))) {
707          return;          return;
708      }      }
709      if ((scrollPtr->flags & REDRAW_PENDING) == 0) {      if ((scrollPtr->flags & REDRAW_PENDING) == 0) {
710          Tcl_DoWhenIdle(TkpDisplayScrollbar, (ClientData) scrollPtr);          Tcl_DoWhenIdle(TkpDisplayScrollbar, (ClientData) scrollPtr);
711          scrollPtr->flags |= REDRAW_PENDING;          scrollPtr->flags |= REDRAW_PENDING;
712      }      }
713  }  }
714    
715  /* End of tkscrollbar.c */  /* End of tkscrollbar.c */

Legend:
Removed from v.69  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25