debian/tmp/usr/include/KWWidgets/vtkKWSpinBox.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Module:    vtkKWSpinBox.h,v
00004 
00005   Copyright (c) Kitware, Inc.
00006   All rights reserved.
00007   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 // .NAME vtkKWSpinBox - SpinBox
00015 // .SECTION Description
00016 // A widget with up and down arrow controls and direct text editing.
00017 // Typically used with integer fields that users increment by 1 (or
00018 // decrement) by clicking on the arrows.
00019 // .SECTION Thanks
00020 // This work is part of the National Alliance for Medical Image
00021 // Computing (NAMIC), funded by the National Institutes of Health
00022 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
00023 // Information on the National Centers for Biomedical Computing
00024 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
00025 
00026 #ifndef __vtkKWSpinBox_h
00027 #define __vtkKWSpinBox_h
00028 
00029 #include "vtkKWCoreWidget.h"
00030 
00031 class vtkKWMenu;
00032 
00033 class KWWidgets_EXPORT vtkKWSpinBox : public vtkKWCoreWidget
00034 {
00035 public:
00036   static vtkKWSpinBox* New();
00037   vtkTypeRevisionMacro(vtkKWSpinBox,vtkKWCoreWidget);
00038   void PrintSelf(ostream& os, vtkIndent indent);
00039 
00040   // Description:
00041   // Set the range. Default to [0, 10]
00042   virtual void SetRange(double from, double to);
00043 
00044   // Description:
00045   // Set the increment value. Default to 1.
00046   virtual void SetIncrement(double increment);
00047   virtual double GetIncrement();
00048 
00049   // Description:
00050   // Set/Get the current value.
00051   virtual void SetValue(double value);
00052   virtual double GetValue();
00053 
00054   // Description:
00055   // Set/Get the string used to format the value.
00056   // Specifies an alternate format to use when setting the string value when
00057   // using the range. This must be a format specifier of the
00058   // form %<pad>.<pad>f, as it will format a floating-point number.
00059   virtual void SetValueFormat(const char *format);
00060   virtual const char* GetValueFormat();
00061 
00062   // Description:
00063   // Set/Get the wrap. If on, values at edges of range wrap around to the
00064   // other side of the range when clicking on the up/down arrows.
00065   virtual void SetWrap(int wrap);
00066   virtual int GetWrap();
00067   vtkBooleanMacro(Wrap, int);
00068 
00069   // Description:
00070   // Restrict the value to a given type (integer, double, or no restriction).
00071   // Note: checks against RestrictValue are performed before ValidationCommand.
00072   //BTX
00073   enum
00074   {
00075     RestrictNone = 0,
00076     RestrictInteger,
00077     RestrictDouble
00078   };
00079   //ETX
00080   vtkGetMacro(RestrictValue, int);
00081   virtual void SetRestrictValue(int);
00082   virtual void SetRestrictValueToInteger();
00083   virtual void SetRestrictValueToDouble();
00084   virtual void SetRestrictValueToNone();
00085 
00086   // Description:
00087   // Specifies a command to associate with this step. This command can
00088   // be used to validate the contents of the widget.
00089   // Note: checks against RestrictValue are performed before ValidationCommand.
00090   // The 'object' argument is the object that will have the method called on
00091   // it. The 'method' argument is the name of the method to be called and any
00092   // arguments in string form. If the object is NULL, the method is still
00093   // evaluated as a simple command. 
00094   // This command should return 1 if the contents is valid, 0 otherwise.
00095   // The following parameters are also passed to the command:
00096   // - current value: const char*
00097   virtual void SetValidationCommand(vtkObject *object, const char *method);
00098   virtual int InvokeValidationCommand(const char *value);
00099 
00100   // Description:
00101   // Set/Get the width of the spinbox in number of characters.
00102   virtual void SetWidth(int);
00103   virtual int GetWidth();
00104 
00105   // Description:
00106   // Set/Get the background color of the widget.
00107   virtual void GetBackgroundColor(double *r, double *g, double *b);
00108   virtual double* GetBackgroundColor();
00109   virtual void SetBackgroundColor(double r, double g, double b);
00110   virtual void SetBackgroundColor(double rgb[3])
00111     { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
00112   
00113   // Description:
00114   // Set/Get the foreground color of the widget.
00115   virtual void GetForegroundColor(double *r, double *g, double *b);
00116   virtual double* GetForegroundColor();
00117   virtual void SetForegroundColor(double r, double g, double b);
00118   virtual void SetForegroundColor(double rgb[3])
00119     { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); };
00120 
00121   // Description:
00122   // Set/Get the background color of the widget when it is disabled.
00123   virtual void GetDisabledBackgroundColor(double *r, double *g, double *b);
00124   virtual double* GetDisabledBackgroundColor();
00125   virtual void SetDisabledBackgroundColor(double r, double g, double b);
00126   virtual void SetDisabledBackgroundColor(double rgb[3])
00127     { this->SetDisabledBackgroundColor(rgb[0], rgb[1], rgb[2]); };
00128   
00129   // Description:
00130   // Set/Get the foreground color of the widget when it is disabled.
00131   virtual void GetDisabledForegroundColor(double *r, double *g, double *b);
00132   virtual double* GetDisabledForegroundColor();
00133   virtual void SetDisabledForegroundColor(double r, double g, double b);
00134   virtual void SetDisabledForegroundColor(double rgb[3])
00135     { this->SetDisabledForegroundColor(rgb[0], rgb[1], rgb[2]); };
00136 
00137   // Description:
00138   // Set/Get the background color of the widget when it is read-only.
00139   virtual void GetReadOnlyBackgroundColor(double *r, double *g, double *b);
00140   virtual double* GetReadOnlyBackgroundColor();
00141   virtual void SetReadOnlyBackgroundColor(double r, double g, double b);
00142   virtual void SetReadOnlyBackgroundColor(double rgb[3])
00143     { this->SetReadOnlyBackgroundColor(rgb[0], rgb[1], rgb[2]); };
00144   
00145   // Description:
00146   // Set/Get the background color of the spin-buttons.
00147   virtual void GetButtonBackgroundColor(double *r, double *g, double *b);
00148   virtual double* GetButtonBackgroundColor();
00149   virtual void SetButtonBackgroundColor(double r, double g, double b);
00150   virtual void SetButtonBackgroundColor(double rgb[3])
00151     { this->SetButtonBackgroundColor(rgb[0], rgb[1], rgb[2]); };
00152   
00153   // Description:
00154   // Set/Get the highlight thickness, a non-negative value indicating the
00155   // width of the highlight rectangle to draw around the outside of the
00156   // widget when it has the input focus.
00157   virtual void SetHighlightThickness(int);
00158   virtual int GetHighlightThickness();
00159   
00160   // Description:
00161   // Set/Get the active background color of the widget. An element
00162   // (a widget or portion of a widget) is active if the mouse cursor is
00163   // positioned over the element and pressing a mouse button will cause some
00164   // action to occur.
00165   virtual void GetActiveBackgroundColor(double *r, double *g, double *b);
00166   virtual double* GetActiveBackgroundColor();
00167   virtual void SetActiveBackgroundColor(double r, double g, double b);
00168   virtual void SetActiveBackgroundColor(double rgb[3])
00169     { this->SetActiveBackgroundColor(rgb[0], rgb[1], rgb[2]); };
00170   
00171   // Description:
00172   // Set/Get the border width, a non-negative value indicating the width of
00173   // the 3-D border to draw around the outside of the widget (if such a border
00174   // is being drawn; the Relief option typically determines this).
00175   virtual void SetBorderWidth(int);
00176   virtual int GetBorderWidth();
00177   
00178   // Description:
00179   // Set/Get the 3-D effect desired for the widget. 
00180   // The value indicates how the interior of the widget should appear
00181   // relative to its exterior. 
00182   // Valid constants can be found in vtkKWOptions::ReliefType.
00183   virtual void SetRelief(int);
00184   virtual int GetRelief();
00185   virtual void SetReliefToRaised();
00186   virtual void SetReliefToSunken();
00187   virtual void SetReliefToFlat();
00188   virtual void SetReliefToRidge();
00189   virtual void SetReliefToSolid();
00190   virtual void SetReliefToGroove();
00191 
00192   // Description:
00193   // Specifies the font to use when drawing text inside the widget. 
00194   // You can use predefined font names (e.g. 'system'), or you can specify
00195   // a set of font attributes with a platform-independent name, for example,
00196   // 'times 12 bold'. In this example, the font is specified with a three
00197   // element list: the first element is the font family, the second is the
00198   // size, the third is a list of style parameters (normal, bold, roman, 
00199   // italic, underline, overstrike). Example: 'times 12 {bold italic}'.
00200   // The Times, Courier and Helvetica font families are guaranteed to exist
00201   // and will be matched to the corresponding (closest) font on your system.
00202   // If you are familiar with the X font names specification, you can also
00203   // describe the font that way (say, '*times-medium-r-*-*-12*').
00204   virtual void SetFont(const char *font);
00205   virtual const char* GetFont();
00206 
00207   // Description:
00208   // Specifies whether or not a selection in the widget should also be the X
00209   // selection. If the selection is exported, then selecting in the widget
00210   // deselects the current X selection, selecting outside the widget deselects
00211   // any widget selection, and the widget will respond to selection retrieval
00212   // requests when it has a selection.  
00213   virtual void SetExportSelection(int);
00214   virtual int GetExportSelection();
00215   vtkBooleanMacro(ExportSelection, int);
00216 
00217   // Description:
00218   // Specifies a command to associate with the widget. This command is 
00219   // typically invoked when the return key is pressed, or the focus is lost,
00220   // as specified by the CommandTrigger variable. It is also invoked when
00221   // the spinbuttons are pressed.
00222   // The 'object' argument is the object that will have the method called on
00223   // it. The 'method' argument is the name of the method to be called and any
00224   // arguments in string form. If the object is NULL, the method is still
00225   // evaluated as a simple command. 
00226   // The following parameters are also passed to the command:
00227   // - the current value: int (if Increment is integer); double otherwise
00228   //   Note: the 'int' signature is for convenience, so that the command can
00229   //   be set to a callback accepting 'int'. In doubt, implement the callback
00230   //   using a 'double' signature that will accept both 'int' and 'double'.
00231   virtual void SetCommand(vtkObject *object, const char *method);
00232   virtual void InvokeCommand(double value);
00233 
00234   // Description:
00235   // Specify when Command should be invoked. Default to losing focus and
00236   // return key.
00237   //BTX
00238   enum
00239   {
00240     TriggerOnFocusOut  = 1,
00241     TriggerOnReturnKey = 2,
00242     TriggerOnAnyChange = 4
00243   };
00244   //ETX
00245   vtkGetMacro(CommandTrigger, int);
00246   virtual void SetCommandTrigger(int);
00247   virtual void SetCommandTriggerToReturnKeyAndFocusOut();
00248   virtual void SetCommandTriggerToAnyChange();
00249 
00250   // Description:
00251   // Events. The SpinBoxValueChangedEvent is triggered when the widget value
00252   // is changed. It is similar in concept to the 'Command' callback but can be
00253   // used by multiple listeners/observers at a time.
00254   // Important: since there is no way to robustly find out when the user
00255   // is done inputing characters in the text entry part of the spinbox, the 
00256   // SpinBoxValueChangedEvent event is also generated when <Return> is pressed,
00257   // or the spinbox widget is losing focus (i.e. the user clicked outside the
00258   // text field).
00259   // The following parameters are also passed as client data:
00260   // - the current value: double
00261   //BTX
00262   enum
00263   {
00264     SpinBoxValueChangedEvent = 10000
00265   };
00266   //ETX
00267 
00268   // Description:
00269   // Update the "enable" state of the object and its internal parts.
00270   // Depending on different Ivars (this->Enabled, the application's 
00271   // Limited Edition Mode, etc.), the "enable" state of the object is updated
00272   // and propagated to its internal parts/subwidgets. This will, for example,
00273   // enable/disable parts of the widget UI, enable/disable the visibility
00274   // of 3D widgets, etc.
00275   virtual void UpdateEnableState();
00276 
00277   // Description:
00278   // Callbacks. Internal, do not use.
00279   virtual void ValueCallback();
00280   virtual int ValidationCallback(const char *value);
00281   virtual void TracedVariableChangedCallback(
00282     const char *, const char *, const char *);
00283   virtual void RightClickCallback(int x, int y);
00284 
00285 protected:
00286   vtkKWSpinBox();
00287   ~vtkKWSpinBox();
00288 
00289   // Description:
00290   // Create the widget.
00291   virtual void CreateWidget();
00292 
00293   int RestrictValue;
00294   int CommandTrigger;
00295 
00296   char *Command;
00297   char *ValidationCommand;
00298 
00299   vtkKWMenu *ContextMenu;
00300 
00301   // Description:
00302   // Populate the context menu
00303   virtual void PopulateContextMenu(vtkKWMenu*);
00304 
00305   // Description:
00306   // Configure.
00307   virtual void Configure();
00308   virtual void ConfigureValidation();
00309 
00310 private:
00311   vtkKWSpinBox(const vtkKWSpinBox&); // Not implemented
00312   void operator=(const vtkKWSpinBox&); // Not implemented
00313 };
00314 
00315 #endif