KWWidgets
vtkKWText.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWText.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 vtkKWText - a multi-line text entry widget
15 // .SECTION Description
16 // A simple widget used for collecting keyboard input from the user. This
17 // widget provides support for multi-line input.
18 // Use vtkKWTextWithScrollbars if you need scrollbars.
19 // .SECTION See Also
20 // vtkKWTextWithScrollbars
21 
22 #ifndef __vtkKWText_h
23 #define __vtkKWText_h
24 
25 #include "vtkKWCoreWidget.h"
26 
27 class vtkKWTextInternals;
28 
30 {
31 public:
32  static vtkKWText* New();
33  vtkTypeRevisionMacro(vtkKWText,vtkKWCoreWidget);
34  void PrintSelf(ostream& os, vtkIndent indent);
35 
36  // Description:
37  // Set/Get the value of the text. AppendText() can also be used
38  // to add text at the end. If a tag is provided, it will be used to
39  // tag the corresponding text.
40  virtual char *GetText();
41  virtual void SetText(const char *);
42  virtual void SetText(const char *, const char *tag);
43  virtual void AppendText(const char *);
44  virtual void AppendText(const char *, const char *tag);
45 
46  // Description:
47  // Set/Get if this text is read-only. Default is Off.
48  virtual void SetReadOnly(int val);
49  vtkGetMacro(ReadOnly, int);
50  vtkBooleanMacro(ReadOnly, int);
51 
52  // Description:
53  // Set/Get if quick formatting is enabled.
54  // In this mode, strings can be tagged using markers:
55  // ** : bold (ex: this is **bold**)
56  // ~~ : italic (ex: this is ~~italic~~)
57  // __ : underline (ex: this is __underline__)
58  virtual void SetQuickFormatting(int);
59  vtkGetMacro(QuickFormatting, int);
60  vtkBooleanMacro(QuickFormatting, int);
61 
62  // Description:
63  // Set/Get the width/height, in characters.
64  virtual void SetWidth(int);
65  virtual int GetWidth();
66  virtual void SetHeight(int);
67  virtual int GetHeight();
68 
69  // Description:
70  // Set/Get the background color of the widget.
71  virtual void GetBackgroundColor(double *r, double *g, double *b);
72  virtual double* GetBackgroundColor();
73  virtual void SetBackgroundColor(double r, double g, double b);
74  virtual void SetBackgroundColor(double rgb[3])
75  { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
76 
77  // Description:
78  // Set/Get the foreground color of the widget.
79  virtual void GetForegroundColor(double *r, double *g, double *b);
80  virtual double* GetForegroundColor();
81  virtual void SetForegroundColor(double r, double g, double b);
82  virtual void SetForegroundColor(double rgb[3])
83  { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); };
84 
85  // Description:
86  // Set/Get the highlight thickness, a non-negative value indicating the
87  // width of the highlight rectangle to draw around the outside of the
88  // widget when it has the input focus.
89  virtual void SetHighlightThickness(int);
90  virtual int GetHighlightThickness();
91 
92  // Description:
93  // Set/Get the border width, a non-negative value indicating the width of
94  // the 3-D border to draw around the outside of the widget (if such a border
95  // is being drawn; the Relief option typically determines this).
96  virtual void SetBorderWidth(int);
97  virtual int GetBorderWidth();
98 
99  // Description:
100  // Set/Get the 3-D effect desired for the widget.
101  // The value indicates how the interior of the widget should appear
102  // relative to its exterior.
103  // Valid constants can be found in vtkKWOptions::ReliefType.
104  virtual void SetRelief(int);
105  virtual int GetRelief();
106  virtual void SetReliefToRaised();
107  virtual void SetReliefToSunken();
108  virtual void SetReliefToFlat();
109  virtual void SetReliefToRidge();
110  virtual void SetReliefToSolid();
111  virtual void SetReliefToGroove();
112 
113  // Description:
114  // Specifies the font to use when drawing text inside the widget.
115  // You can use predefined font names (e.g. 'system'), or you can specify
116  // a set of font attributes with a platform-independent name, for example,
117  // 'times 12 bold'. In this example, the font is specified with a three
118  // element list: the first element is the font family, the second is the
119  // size, the third is a list of style parameters (normal, bold, roman,
120  // italic, underline, overstrike). Example: 'times 12 {bold italic}'.
121  // The Times, Courier and Helvetica font families are guaranteed to exist
122  // and will be matched to the corresponding (closest) font on your system.
123  // If you are familiar with the X font names specification, you can also
124  // describe the font that way (say, '*times-medium-r-*-*-12*').
125  virtual void SetFont(const char *font);
126  virtual const char* GetFont();
127 
128  // Description:
129  // Set/Get the padding that will be applied around each widget (in pixels).
130  // Specifies a non-negative value indicating how much extra space to request
131  // for the widget in the X and Y-direction. When computing how large a
132  // window it needs, the widget will add this amount to the width it would
133  // normally need (as determined by the width of the things displayed
134  // in the widget); if the geometry manager can satisfy this request, the
135  // widget will end up with extra internal space around what it displays
136  // inside.
137  virtual void SetPadX(int);
138  virtual int GetPadX();
139  virtual void SetPadY(int);
140  virtual int GetPadY();
141 
142  // Description:
143  // Set the wrap mode.
144  virtual void SetWrapToNone();
145  virtual void SetWrapToWord();
146  virtual void SetWrapToChar();
147 
148  // Description:
149  // Add a tag matcher. Whenever a regular expression 'regexp' is matched
150  // it will be tagged with 'tag'.
151  virtual void AddTagMatcher(const char *regexp, const char *tag);
152 
153  // Description:
154  // Set the resize-to-grid flag.
155  // Specifies a boolean value that determines whether this widget controls
156  // the resizing grid for its top-level window. This option is typically
157  // used in text widgets, where the information in the widget has a natural
158  // size (the size of a character) and it makes sense for the window's
159  // dimensions to be integral numbers of these units. These natural window
160  // sizes form a grid. If the setGrid option is set to true then the widget
161  // will communicate with the window manager so that when the user
162  // interactively resizes the top-level window that contains the widget,
163  // the dimensions of the window will be displayed to the user in grid units
164  // and the window size will be constrained to integral numbers of grid units.
165  vtkBooleanMacro(ResizeToGrid, int);
166  virtual void SetResizeToGrid(int);
167  virtual int GetResizeToGrid();
168 
169  // Description:
170  // Adjusts the view in the widget so that the character at the end is
171  // completely visible.
172  virtual void SeeEnd();
173 
174  // Description:
175  // Specifies a command to associate with the widget. This command is
176  // typically invoked when the return key is pressed, or the focus is lost,
177  // as specified by the CommandTrigger variable.
178  // The 'object' argument is the object that will have the method called on
179  // it. The 'method' argument is the name of the method to be called and any
180  // arguments in string form. If the object is NULL, the method is still
181  // evaluated as a simple command.
182  // The following parameters are also passed to the command:
183  // - current value: const char*
184  virtual void SetCommand(vtkObject *object, const char *method);
185  virtual void InvokeCommand(const char *value);
186 
187  // Description:
188  // Specify when Command should be invoked. Default to losing focus and
189  // return key.
190  //BTX
191  enum
192  {
193  TriggerOnFocusOut = 1,
194  TriggerOnReturnKey = 2,
195  TriggerOnAnyChange = 4
196  };
197  //ETX
198  vtkGetMacro(CommandTrigger, int);
199  virtual void SetCommandTrigger(int);
200  virtual void SetCommandTriggerToReturnKeyAndFocusOut();
201  virtual void SetCommandTriggerToAnyChange();
202 
203  // Description:
204  // Set/Get the modified flag. Each time the text is modified, this flag
205  // is set to true. Note that if CommandTrigger is set to AnyChange, each
206  // time the text is modified, the flag is reset to false so that the
207  // <<Modified>> event can be caught by the next change.
208  virtual int GetModifiedFlag();
209  virtual void SetModifiedFlag(int);
210 
211  // Description:
212  // Update the "enable" state of the object and its internal parts.
213  // Depending on different Ivars (this->Enabled, the application's
214  // Limited Edition Mode, etc.), the "enable" state of the object is updated
215  // and propagated to its internal parts/subwidgets. This will, for example,
216  // enable/disable parts of the widget UI, enable/disable the visibility
217  // of 3D widgets, etc.
218  virtual void UpdateEnableState();
219 
220  // Description:
221  // Some constants
222  //BTX
223  static const char *MarkerBold;
224  static const char *MarkerItalic;
225  static const char *MarkerUnderline;
226  static const char *TagBold;
227  static const char *TagItalic;
228  static const char *TagUnderline;
229  static const char *TagFgNavy;
230  static const char *TagFgRed;
231  static const char *TagFgBlue;
232  static const char *TagFgDarkGreen;
233  //ETX
234 
235  // Description:
236  // Callbacks. Internal, do not use.
237  virtual void ValueCallback();
238 
239 protected:
240  vtkKWText();
241  ~vtkKWText();
242 
243  // Description:
244  // Create the widget.
245  virtual void CreateWidget();
246 
247  // Description:
248  // Configure.
249  virtual void Configure(int disable = 0);
250 
251  int ReadOnly;
252  int QuickFormatting;
253  int CommandTrigger;
254 
255  char *Command;
256 
257  //BTX
258  // PIMPL Encapsulation for STL containers
259  vtkKWTextInternals *Internals;
260  //ETX
261 
262  virtual void AppendTextInternalTagging(const char *, const char *tag);
263  virtual void AppendTextInternal(const char *, const char *tag);
264 
265 private:
266 
267  char *InternalTextString;
268  vtkGetStringMacro(InternalTextString);
269  vtkSetStringMacro(InternalTextString);
270 
271  vtkKWText(const vtkKWText&); // Not implemented
272  void operator=(const vtkKWText&); // Not implemented
273 };
274 
275 #endif