KWWidgets
vtkKWTkUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWTkUtilities.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWTkUtilities - class that supports basic Tk functions
15 // .SECTION Description
16 // vtkKWTkUtilities provides methods to perform common Tk operations.
17 
18 #ifndef __vtkKWTkUtilities_h
19 #define __vtkKWTkUtilities_h
20 
21 #include "vtkObject.h"
22 #include "vtkKWWidgets.h" // Needed for export symbols directives
23 
24 // This has to be here because on HP varargs are included in
25 // tcl.h and they have different prototypes for va_start so
26 // the build fails. Defining HAS_STDARG prevents that.
27 
28 #if defined(__hpux) && !defined(HAS_STDARG)
29 #define HAS_STDARG
30 #endif
31 
32 #include <stdarg.h> // Needed for "va_list" argument of EstimateFormatLength.
33 
34 class vtkKWWidget;
35 class vtkKWCoreWidget;
36 class vtkKWApplication;
37 class vtkKWIcon;
38 class vtkRenderWindow;
39 struct Tcl_Interp;
40 
41 class KWWidgets_EXPORT vtkKWTkUtilities : public vtkObject
42 {
43 public:
44  static vtkKWTkUtilities* New();
45  vtkTypeRevisionMacro(vtkKWTkUtilities,vtkObject);
46  void PrintSelf(ostream& os, vtkIndent indent);
47 
48  // Description:
49  // Return the Tcl name of a VTK object
50  static const char* GetTclNameFromPointer(
51  Tcl_Interp *interp, vtkObject *obj);
52  static const char* GetTclNameFromPointer(
53  vtkKWApplication *app, vtkObject *obj);
54 
55  // Description:
56  // Evaluate a Tcl string. The string is passed to printf() first (as format
57  // specifier) along with the remaining arguments.
58  // The second prototype can be used by similar variable arguments method: it
59  // needs to walk through the var_args list twice though. The only
60  // portable way to do this is to pass two copies of the list's start
61  // pointer.
62  // Convenience methods are provided to specify a vtkKWApplication
63  // instead of the Tcl interpreter.
64  // Return a pointer to the Tcl interpreter result buffer.
65  //BTX
66  static const char* EvaluateString(
67  Tcl_Interp *interp, const char *format, ...);
68  static const char* EvaluateString(
69  vtkKWApplication *app, const char *format, ...);
70  //ETX
71  static const char* EvaluateStringFromArgs(
72  Tcl_Interp *interp, const char *format,
73  va_list var_args1, va_list var_args2);
74  static const char* EvaluateStringFromArgs(
75  vtkKWApplication *app, const char *format,
76  va_list var_args1, va_list var_args2);
77  static const char* EvaluateSimpleString(
78  Tcl_Interp *interp, const char *str);
79  static const char* EvaluateSimpleString(
80  vtkKWApplication *app, const char *str);
81 
82  // Description:
83  // Evaluate a Tcl string that was encoded in a buffer using zlib
84  // and/or base64.
85  static const char* EvaluateEncodedString(
86  Tcl_Interp *interp,
87  const unsigned char *buffer,
88  unsigned long length,
89  unsigned long decoded_length);
90 
91  // Description:
92  // Create a Tcl callback command.
93  // The 'command' argument is a pointer to the command to be created.
94  // The 'object' argument is the object that will have the method called on
95  // it. The 'method' argument is the name of the method to be called and any
96  // arguments in string form. If the object is NULL, the method is still
97  // evaluated as a simple command.
98  // Note that 'command' is allocated automatically using the 'new'
99  // operator. If it is not NULL, it is deallocated first using 'delete []'.
100  static void CreateObjectMethodCommand(
101  vtkKWApplication *app,
102  char **command, vtkObject *object, const char *method);
103  static void CreateObjectMethodCommand(
104  Tcl_Interp *interp,
105  char **command, vtkObject *object, const char *method);
106 
107  // Description:
108  // Get the RGB components that correspond to 'color' (say, #223344)
109  // in the widget given by 'widget' (say, .foo.bar). Color may be specified
110  // in any of the forms acceptable for a Tk color option.
111  // A convenience method is provided to query a vtkKWWidget directly.
112  static void GetRGBColor(Tcl_Interp *interp,
113  const char *widget,
114  const char *color,
115  double *r, double *g, double *b);
116  static void GetRGBColor(vtkKWWidget *widget,
117  const char *color,
118  double *r, double *g, double *b);
119 
120  // Description:
121  // Get the RGB components that correspond to the color 'option'
122  // (say -bg, -fg, etc.) of the widget given by 'widget' (say, .foo.bar).
123  // A convenience method is provided to query a vtkKWWidget directly.
124  static void GetOptionColor(Tcl_Interp *interp,
125  const char *widget,
126  const char *option,
127  double *r, double *g, double *b);
128  static void GetOptionColor(vtkKWWidget *widget,
129  const char *option,
130  double *r, double *g, double *b);
131  static double* GetOptionColor(vtkKWWidget *widget,
132  const char *option);
133 
134  // Description:
135  // Get the RGB components that correspond to the default color 'option'
136  // (say the default value for -bg, -fg, etc.) of the widget given by
137  // 'widget' (say, .foo.bar).
138  // A convenience method is provided to query a vtkKWWidget directly.
139  static void GetDefaultOptionColor(Tcl_Interp *interp,
140  const char *widget,
141  const char *option,
142  double *r, double *g, double *b);
143  static void GetDefaultOptionColor(vtkKWWidget *widget,
144  const char *option,
145  double *r, double *g, double *b);
146  static double* GetDefaultOptionColor(vtkKWWidget *widget,
147  const char *option);
148 
149  // Description:
150  // Set the RGB components of the color 'option'
151  // (say -bg, -fg, etc.) of the widget given by 'widget' (say, .foo.bar).
152  // A convenience method is provided to query a vtkKWWidget directly.
153  static void SetOptionColor(Tcl_Interp *interp,
154  const char *widget,
155  const char *option,
156  double r, double g, double b);
157  static void SetOptionColor(vtkKWWidget *widget,
158  const char *option,
159  double r, double g, double b);
160 
161  // Description:
162  // Query user for color using a Tk color dialog
163  // Return 1 on success, 0 otherwise.
164  static int QueryUserForColor(vtkKWApplication *app,
165  vtkKWWidget *dialog_parent,
166  const char *dialog_title,
167  double in_r, double in_g, double in_b,
168  double *out_r, double *out_g, double *out_b);
169 
170  // Description:
171  // Get the geometry of a widget given by 'widget' (say, .foo.bar).
172  // The geometry is the width, height and position of the widget.
173  // Any of them can be a NULL pointer, they will be safely ignored.
174  // Return 1 on success, 0 otherwise.
175  // A convenience method is provided to query a vtkKWWidget directly.
176  static int GetGeometry(Tcl_Interp *interp,
177  const char *widget,
178  int *width, int *height, int *x, int *y);
179  static int GetGeometry(vtkKWWidget *widget,
180  int *width, int *height, int *x, int *y);
181 
182  // Description:
183  // Check if a pair of screen coordinates (x, y) are within the area defined
184  // by the widget given by 'widget' (say, .foo.bar).
185  // Return 1 if inside, 0 otherwise.
186  // A convenience method is provided to query a vtkKWWidget directly.
187  // ContainsCoordinatesForSpecificType will check if 'widget' is of a
188  // specific type (or a subclass of that type), and if not will inspect
189  // its children. It will return the widget that contains the coordinates
190  // or NULL if not found.
191  static int ContainsCoordinates(Tcl_Interp *interp,
192  const char *widget,
193  int x, int y);
194  static int ContainsCoordinates(vtkKWWidget *widget,
195  int x, int y);
196  static vtkKWWidget* ContainsCoordinatesForSpecificType(
197  vtkKWWidget *widget, int x, int y, const char *classname);
198 
199  // Description:
200  // Update a Tk photo given by its name 'photo_name' using pixels stored in
201  // 'pixels' and structured as a 'width' x 'height' x 'pixel_size' (number
202  // of bytes per pixel, 3 for RGB for example).
203  // If 'buffer_length' is 0, compute it automatically by multiplying
204  // 'pixel_size', 'width' and 'height' together.
205  // If UPDATE_PHOTO_OPTION_FLIP_V is set in 'update_option', flip the image
206  // buffer vertically.
207  // A convenience method is provided to specify the vtkKWApplication this
208  // photo belongs to, instead of the Tcl interpreter.
209  // Return 1 on success, 0 otherwise.
210  //BTX
211  enum
212  {
213  UpdatePhotoOptionFlipVertical = 1
214  };
215  //ETX
216  static int UpdatePhoto(Tcl_Interp *interp,
217  const char *photo_name,
218  const unsigned char *pixels,
219  int width, int height,
220  int pixel_size,
221  unsigned long buffer_length = 0,
222  int update_options = 0);
223  static int UpdatePhoto(vtkKWApplication *app,
224  const char *photo_name,
225  const unsigned char *pixels,
226  int width, int height,
227  int pixel_size,
228  unsigned long buffer_length = 0,
229  int update_options = 0);
230 
231  // Description:
232  // Update a Tk photo given by its name 'photo_name' using pixels stored in
233  // the icon 'icon'.
234  static int UpdatePhotoFromIcon(vtkKWApplication *app,
235  const char *photo_name,
236  vtkKWIcon *icon,
237  int update_options = 0);
238  static int UpdatePhotoFromPredefinedIcon(vtkKWApplication *app,
239  const char *photo_name,
240  int icon_index,
241  int update_options = 0);
242 
243  // Description:
244  // Update a Tk photo given by its name 'photo_name' using pixels stored in
245  // 'pixels' and structured as a 'width' x 'height' x 'pixel_size' (number
246  // of bytes per pixel, 3 for RGB for example).
247  // If a file 'file_name'.png is found in 'directory' or
248  // 'directory/Resources' then an attempt is made to update the photo using
249  // this file. If no file is found, the remaining parameters are used
250  // to update the photo by calling UpdatePhoto().
251  // As a convenience, if 'photo_name' is NULL, 'file_name' is used instead.
252  // Note that only the PNG file format is supported so far (do not provide
253  // the .png extension to 'file_name').
254  // Return 1 on success, 0 otherwise.
255  // A convenience method is provided to specify the vtkKWApplication this
256  // photo belongs to, instead of the Tcl interpreter.
257  static int UpdateOrLoadPhoto(Tcl_Interp *interp,
258  const char *photo_name,
259  const char *file_name,
260  const char *directory,
261  const unsigned char *pixels,
262  int width, int height,
263  int pixel_size,
264  unsigned long buffer_length = 0);
265  static int UpdateOrLoadPhoto(vtkKWApplication *app,
266  const char *photo_name,
267  const char *file_name,
268  const char *directory,
269  const unsigned char *pixels,
270  int width, int height,
271  int pixel_size,
272  unsigned long buffer_length = 0);
273 
274  // Description:
275  // Specifies an image to display in a widget. Typically, if the image
276  // is specified then it overrides other options that specify a bitmap or
277  // textual value to display in the widget.
278  // Set the image option using pixel data. The parameters are the same
279  // as the one used in UpdatePhoto().
280  // An image is created and associated to the Tk -image option or
281  // image_option if not NULL (ex: -selectimage).
282  static void SetImageOptionToPixels(
283  vtkKWCoreWidget *widget,
284  const unsigned char *pixels,
285  int width, int height,
286  int pixel_size = 4,
287  unsigned long buffer_length = 0,
288  const char *image_option = 0);
289 
290  // Description:
291  // Query if a Tk photo given by its name 'photo_name' exists.
292  // A convenience method is provided to specify the vtkKWApplication this
293  // photo belongs to, instead of the Tcl interpreter.
294  static int FindPhoto(Tcl_Interp *interp, const char *photo_name);
295  static int FindPhoto(vtkKWApplication *app, const char *photo_name);
296 
297  // Description:
298  // Get the height of a Tk photo given by its name 'photo_name'.
299  // If the photo does not exist, return 0 and issue a warning.
300  // A convenience method is provided to specify the vtkKWApplication this
301  // photo belongs to, instead of the Tcl interpreter.
302  // A convenience method is provided to specify a vtkKWWidget this photo
303  // has been assigned to using the -image Tk option.
304  static int GetPhotoHeight(Tcl_Interp *interp, const char *photo_name);
305  static int GetPhotoHeight(vtkKWApplication *app, const char *photo_name);
306  static int GetPhotoHeight(vtkKWWidget *widget);
307 
308  // Description:
309  // Get the width of a Tk photo given by its name 'photo_name'.
310  // If the photo does not exist, return 0 and issue a warning.
311  // A convenience method is provided to specify the vtkKWApplication this
312  // photo belongs to, instead of the Tcl interpreter.
313  static int GetPhotoWidth(Tcl_Interp *interp, const char *photo_name);
314  static int GetPhotoWidth(vtkKWApplication *app, const char *photo_name);
315 
316  // Description:
317  // Change the weight attribute of a Tk font specification given by 'font'.
318  // The new font specification is copied to 'new_font'.
319  // It is up to the caller to allocate enough space in 'new_font'.
320  // Return 1 on success, 0 otherwise.
321  static int ChangeFontWeightToBold(
322  Tcl_Interp *interp, const char *font, char *new_font);
323  static int ChangeFontWeightToNormal(
324  Tcl_Interp *interp, const char *font, char *new_font);
325 
326  // Description:
327  // Change the weight attribute of a 'widget' -font option.
328  // A convenience method is provided to query a vtkKWWidget directly.
329  // Return 1 on success, 0 otherwise.
330  static int ChangeFontWeightToBold(Tcl_Interp *interp, const char *widget);
331  static int ChangeFontWeightToBold(vtkKWWidget *widget);
332  static int ChangeFontWeightToNormal(Tcl_Interp *interp, const char *widget);
333  static int ChangeFontWeightToNormal(vtkKWWidget *widget);
334 
335  // Description:
336  // Change the slant attribute of a Tk font specification given by 'font'.
337  // The new font specification is copied to 'new_font'.
338  // It is up to the caller to allocate enough space in 'new_font'.
339  // Return 1 on success, 0 otherwise.
340  static int ChangeFontSlantToItalic(
341  Tcl_Interp *interp, const char *font, char *new_font);
342  static int ChangeFontSlantToRoman(
343  Tcl_Interp *interp, const char *font, char *new_font);
344 
345  // Description:
346  // Change the slant attribute of a 'widget' -font option.
347  // A convenience method is provided to query a vtkKWWidget directly.
348  // Return 1 on success, 0 otherwise.
349  static int ChangeFontSlantToItalic(Tcl_Interp *interp, const char *widget);
350  static int ChangeFontSlantToItalic(vtkKWWidget *widget);
351  static int ChangeFontSlantToRoman(Tcl_Interp *interp, const char *widget);
352  static int ChangeFontSlantToRoman(vtkKWWidget *widget);
353 
354  // Description:
355  // Change the size attribute of a Tk font specification given by 'font'.
356  // The new font specification is copied to 'new_font'.
357  // It is up to the caller to allocate enough space in 'new_font'.
358  // Return 1 on success, 0 otherwise.
359  static int ChangeFontSize(
360  Tcl_Interp *interp, const char *font, int new_size, char *new_font);
361 
362  // Description:
363  // Change the size attribute of a 'widget' -font option.
364  // A convenience method is provided to query a vtkKWWidget directly.
365  // Return 1 on success, 0 otherwise.
366  static int ChangeFontSize(
367  Tcl_Interp *interp, const char *widget, int new_size);
368  static int ChangeFontSize(vtkKWWidget *widget, int new_size);
369 
370  // Description:
371  // Get the real actual font (i.e. its list of attributes) given a font,
372  // font name, or incomplete font specification.
373  // It is up to the caller to allocate enough space in 'real_font'.
374  // Return 1 on success, 0 otherwise.
375  static int GetRealActualFont(
376  Tcl_Interp *interp, const char *font, char *real_font);
377 
378  // Description:
379  // Get the amount of space the string txt when displayed in widget (using
380  // the default widget's -font parameter). Store the result in 'w'.
381  // Return 1 on success, 0 otherwise.
382  static int GetFontMeasure(vtkKWWidget *widget, const char *txt, int *w);
383 
384  // Description:
385  // Get the number of colums and rows defined in the grid layout of
386  // the widget given by 'widget' (say, .foo.bar).
387  // A convenience method is provided to query a vtkKWWidget directly.
388  // Return 1 on success, 0 otherwise.
389  static int GetGridSize(Tcl_Interp *interp,
390  const char *widget,
391  int *nb_of_cols,
392  int *nb_of_rows);
393  static int GetGridSize(vtkKWWidget *widget,
394  int *nb_of_cols,
395  int *nb_of_rows);
396 
397  // Description:
398  // Get the grid position (column, row) of the widget given by 'widget'
399  // (say, .foo.bar).
400  // We assume that the current widget layout is a Tk grid.
401  // A convenience method is provided to query a vtkKWWidget directly.
402  // Return 1 on success, 0 otherwise.
403  static int GetWidgetPositionInGrid(Tcl_Interp *interp,
404  const char *widget,
405  int *col,
406  int *row);
407  static int GetWidgetPositionInGrid(vtkKWWidget *widget,
408  int *col,
409  int *row);
410 
411  // Description:
412  // Get the bounding box size (width, height) of the slaves packed in the
413  // widget given by 'widget' (say, .foo.bar), i.e. the largest width
414  // and height of the slaves packed in the widget, including padding options.
415  // We assume that the current widget layout is a Tk pack.
416  // A convenience method is provided to query a vtkKWWidget directly.
417  // Return 1 on success, 0 otherwise.
418  static int GetSlavesBoundingBoxInPack(Tcl_Interp *interp,
419  const char *widget,
420  int *width,
421  int *height);
422  static int GetSlavesBoundingBoxInPack(vtkKWWidget *widget,
423  int *width,
424  int *height);
425 
426  // Description:
427  // Get the horizontal position 'x' in pixels of a slave widget given by
428  // 'slave' (say .foo.bar.sl) in the widget given by 'widget' (say .foo.bar).
429  // This can be used in case 'winfo x' does not work because the widget
430  // has not been mapped yet.
431  // We assume that the current widget layout is a Tk pack.
432  // A convenience method is provided to query vtkKWWidget(s) directly.
433  // Return 1 on success, 0 otherwise.
434  static int GetSlaveHorizontalPositionInPack(Tcl_Interp *interp,
435  const char *widget,
436  const char *slave,
437  int *x);
438  static int GetSlaveHorizontalPositionInPack(vtkKWWidget *widget,
439  vtkKWWidget *slave,
440  int *x);
441 
442  // Description:
443  // Get the padding values of the widget given by 'widget' (say .foo.bar)
444  // in its layout.
445  // We assume that the current widget layout is a Tk pack.
446  // Return 1 on success, 0 otherwise.
447  static int GetWidgetPaddingInPack(Tcl_Interp *interp,
448  const char *widget,
449  int *ipadx,
450  int *ipady,
451  int *padx,
452  int *pady);
453 
454  // Description:
455  // Get the container a widget given by 'widget' (say .foo.bar) is packed in.
456  // This is similar to the Tk -in pack option.
457  // Write the container widget name to the output stream 'in'.
458  // We assume that the current widget layout is a Tk pack.
459  // A convenience method is provided to query a vtkKWWidget directly.
460  // Return 1 on success, 0 otherwise.
461  static int GetMasterInPack(Tcl_Interp *interp,
462  const char *widget,
463  ostream &in);
464  static int GetMasterInPack(vtkKWWidget *widget,
465  ostream &in);
466 
467  // Description:
468  // Get the column widths of a grid (i.e. a master widget that has been grid).
469  // If 'allocate' is true, the resulting array (col_widths) is allocated
470  // by the function to match the number of columns.
471  // The function iterates over cells to request the width of
472  // each slave (winfo reqwidth).
473  static int GetGridColumnWidths(Tcl_Interp *interp,
474  const char *widget,
475  int *nb_of_cols,
476  int **col_widths,
477  int allocate = 0);
478 
479  // Description:
480  // Synchronize the columns minimum size of different widgets that have
481  // been grid. If 'factors' is non-null, it is used as an array of
482  // multiplication factor to apply to each column minimum size.
483  // If 'weights' is non-null, it is used as an array of weight
484  // to apply to each column through columnconfigure -weight.
485  static int SynchroniseGridsColumnMinimumSize(Tcl_Interp *interp,
486  int nb_of_widgets,
487  const char **widgets,
488  const float *factors = 0,
489  const int *weights = 0);
490 
491  // Description:
492  // Synchronize the width of a set of labels given by an array
493  // of 'nb_of_widgets' widgets stored in 'widgets'. The maximum size of
494  // the labels is found and assigned to each label.
495  // Additionally it will apply the 'options' to/ each widget (if any).
496  // A convenience method is provided to specify the vtkKWApplication these
497  // widgets belongs to, instead of the Tcl interpreter.
498  // Return 1 on success, 0 otherwise.
499  static int SynchroniseLabelsMaximumWidth(Tcl_Interp *interp,
500  int nb_of_widgets,
501  const char **widgets,
502  const char *options = 0);
503  static int SynchroniseLabelsMaximumWidth(vtkKWApplication *app,
504  int nb_of_widgets,
505  const char **widgets,
506  const char *options = 0);
507 
508  // Description:
509  // Store the slaves packed in the widget given by 'widget' (say, .foo.bar)
510  // in the array 'slaves'. This array is allocated automatically.
511  // We assume that the current widget layout is a Tk pack.
512  // A convenience method is provided to query a vtkKWWidget directly.
513  // Return the number of slaves.
514  static int GetSlavesInPack(Tcl_Interp *interp,
515  const char *widget,
516  char ***slaves);
517  static int GetSlavesInPack(vtkKWWidget *widget,
518  char ***slaves);
519 
520  // Description:
521  // Browse all the slaves of the widget given by 'widget' (say, .foo.bar)
522  // and store the slave packed before 'slave' in 'previous_slave', and the
523  // slave packed after 'slave' in 'next_slave'
524  // We assume that the current widget layout is a Tk pack.
525  // A convenience method is provided to query a vtkKWWidget directly.
526  // Return 1 if 'slave' was found, 0 otherwise
527  static int GetPreviousAndNextSlaveInPack(Tcl_Interp *interp,
528  const char *widget,
529  const char *slave,
530  ostream &previous_slave,
531  ostream &next_slave);
532  static int GetPreviousAndNextSlaveInPack(vtkKWWidget *widget,
533  vtkKWWidget *slave,
534  ostream &previous_slave,
535  ostream &next_slave);
536  // Description:
537  // Take screendump of the widget given by 'widget' (say, .foo.bar) and store
538  // it into a png file given by 'fname'.
539  // A convenience method is provided to query a vtkKWWidget directly.
540  // Return 1 on success, 0 otherwise.
541  static int TakeScreenDump(Tcl_Interp *interp,
542  const char *wname,
543  const char *fname,
544  int top = 0, int bottom = 0,
545  int left = 0, int right = 0);
546  static int TakeScreenDump(vtkKWWidget *widget,
547  const char *fname,
548  int top = 0, int bottom = 0,
549  int left = 0, int right = 0);
550 
551  // Description:
552  // Set widget's toplevel mouse cursor.
553  // Provide a NULL or empty cursor to reset it to default.
554  static int SetTopLevelMouseCursor(Tcl_Interp *interp,
555  const char *widget,
556  const char *cursor);
557  static int SetTopLevelMouseCursor(vtkKWWidget *widget,
558  const char *cursor);
559 
560  // Description:
561  // Return 1 if window is a toplevel, 0 otherwise
562  static int IsTopLevel(Tcl_Interp *interp,
563  const char *widget);
564  static int IsTopLevel(vtkKWWidget *widget);
565 
566  // Description:
567  // Withdraw toplevel
568  static void WithdrawTopLevel(Tcl_Interp *interp,
569  const char *widget);
570  static void WithdrawTopLevel(vtkKWWidget *widget);
571 
572  // Description:
573  // If a Tcl script file is currently being evaluated (i.e. there is a call
574  // to Tcl_EvalFile active or there is an active invocation of the source
575  // command), then this command returns the name of the innermost file
576  // being processed.
577  static const char *GetCurrentScript(Tcl_Interp *interp);
578  static const char *GetCurrentScript(vtkKWApplication *app);
579 
580  // Description:
581  // Create a timer handler, i.e. arranges for a command to be executed
582  // exactly once 'ms' milliseconds later, or when the application is idle,
583  // i.e. the next time the event loop is entered and there are no events to
584  // process.
585  // The 'object' argument is the object that will have the method called on
586  // it. The 'method' argument is the name of the method to be called and any
587  // arguments in string form. If the object is NULL, the method is still
588  // evaluated as a simple command.
589  // Returns a string identifier that can be used to cancel the timer.
590  static const char* CreateTimerHandler(
591  Tcl_Interp *interp,
592  unsigned long ms,
593  vtkObject *object, const char *method);
594  static const char* CreateTimerHandler(
595  vtkKWApplication *app,
596  unsigned long ms,
597  vtkObject *object, const char *method);
598  static const char* CreateIdleTimerHandler(
599  Tcl_Interp *interp,
600  vtkObject *object, const char *method);
601  static const char* CreateIdleTimerHandler(
602  vtkKWApplication *app,
603  vtkObject *object, const char *method);
604 
605  // Description:
606  // Cancel one or all event handlers, i.e. cancel all delayed command that
607  // were registered using the 'after' command or CreateTimerHandler methods.
608  static void CancelTimerHandler(Tcl_Interp *interp, const char *id);
609  static void CancelTimerHandler(vtkKWApplication *app, const char *id);
610  static void CancelAllTimerHandlers(Tcl_Interp *interp);
611  static void CancelAllTimerHandlers(vtkKWApplication *app);
612 
613  // Description:
614  // Rings the bell on the display of the application's main window
615  static void Bell(Tcl_Interp *interp);
616  static void Bell(vtkKWApplication *app);
617 
618  // Description:
619  // Process/update pending events. This command is used to bring the
620  // application "up to date" by entering the event loop repeatedly until
621  // all pending events (including idle callbacks) have been processed.
622  static void ProcessPendingEvents(Tcl_Interp *interp);
623  static void ProcessPendingEvents(vtkKWApplication *app);
624 
625  // Description:
626  // Process/update idle tasks. This causes operations that are normally
627  // deferred, such as display updates and window layout calculations, to be
628  // performed immediately.
629  static void ProcessIdleTasks(Tcl_Interp *interp);
630  static void ProcessIdleTasks(vtkKWApplication *app);
631 
632  // Description:
633  // Check for pending interaction events, i.e. mouse button up/down, window
634  // being dragged/resized/moved, paint, window activation, etc.
635  // On Unix, one needs to pass a vtkRenderWindow (on Win32, NULL is fine)
636  // Return 1 if events are pending, 0 otherwise
637  static int CheckForPendingInteractionEvents(vtkRenderWindow *win);
638 
639  // Description:
640  // Get the coordinates of the mouse pointer in the screen widget is in.
641  // Return 1 on success, 0 otherwise.
642  static int GetMousePointerCoordinates(
643  Tcl_Interp *interp, const char *widget, int *x, int *y);
644  static int GetMousePointerCoordinates(
645  vtkKWWidget *widget, int *x, int *y);
646 
647  // Description:
648  // Get the coordinates of the upper-left corner of widget in its screen.
649  // Return 1 on success, 0 otherwise.
650  static int GetWidgetCoordinates(
651  Tcl_Interp *interp, const char *widget, int *x, int *y);
652  static int GetWidgetCoordinates(
653  vtkKWWidget *widget, int *x, int *y);
654 
655  // Description:
656  // Get the relative coordinates of the upper-left corner of widget in its
657  // widget's parent.
658  // Return 1 on success, 0 otherwise.
659  static int GetWidgetRelativeCoordinates(
660  Tcl_Interp *interp, const char *widget, int *x, int *y);
661  static int GetWidgetRelativeCoordinates(
662  vtkKWWidget *widget, int *x, int *y);
663 
664  // Description:
665  // Get the width and height of widget in its screen.
666  // When a window is first created its width will be 1 pixel; the width will
667  // eventually be changed by a geometry manager to fulfill the window's needs.
668  // If you need the true width immediately after creating a widget, invoke
669  // ProcessPendingEvents to force the geometry manager to arrange it, or use
670  // GetWidgetRequestedSize to get the window's requested size instead of its
671  // actual size.
672  // Return 1 on success, 0 otherwise.
673  static int GetWidgetSize(
674  Tcl_Interp *interp, const char *widget, int *w, int *h);
675  static int GetWidgetSize(
676  vtkKWWidget *widget, int *w, int *h);
677 
678  // Description:
679  // Get the requested width and height of widget in its screen.
680  // This is the value used by window's geometry manager to compute its
681  // geometry.
682  // Return 1 on success, 0 otherwise.
683  static int GetWidgetRequestedSize(
684  Tcl_Interp *interp, const char *widget, int *w, int *h);
685  static int GetWidgetRequestedSize(
686  vtkKWWidget *widget, int *w, int *h);
687 
688  // Description:
689  // Get the widget class (i.e. Tk type).
690  static const char* GetWidgetClass(
691  Tcl_Interp *interp, const char *widget);
692  static const char* GetWidgetClass(
693  vtkKWWidget *widget);
694 
695  // Description:
696  // Get the width and height (in pixels) of the screen the widget is in.
697  // Return 1 on success, 0 otherwise.
698  static int GetScreenSize(
699  Tcl_Interp *interp, const char *widget, int *w, int *h);
700  static int GetScreenSize(
701  vtkKWWidget *widget, int *w, int *h);
702 
703  // Description:
704  // Get windowing system.
705  // Returns the current Tk windowing system, one of x11 (X11-based),
706  // win32 (MS Windows), classic (Mac OS Classic), or aqua (Mac OS X Aqua).
707  static const char* GetWindowingSystem(vtkKWApplication *app);
708  static const char* GetWindowingSystem(Tcl_Interp *interp);
709 
710 protected:
713 
714  //BTX
715  //ETX
716 
717  static int ChangeFontWeight(
718  Tcl_Interp *interp, const char *widget, int bold);
719  static int ChangeFontWeight(
720  Tcl_Interp *interp, const char *font, int bold, char *new_font);
721  static int ChangeFontSlant(
722  Tcl_Interp *interp, const char *widget, int italic);
723  static int ChangeFontSlant(
724  Tcl_Interp *interp, const char *font, int italic, char *new_font);
725 
726  static const char* EvaluateStringFromArgsInternal(
727  Tcl_Interp *interp, vtkObject *obj, const char *format,
728  va_list var_args1, va_list var_args2);
729  static const char* EvaluateSimpleStringInternal(
730  Tcl_Interp *interp, vtkObject *obj, const char *str);
731 
732 private:
733  vtkKWTkUtilities(const vtkKWTkUtilities&); // Not implemented
734  void operator=(const vtkKWTkUtilities&); // Not implemented
735 };
736 
737 #endif
738