Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXTextField.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                         T e x t   F i e l d   W i d g e t                     *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXTextField.h,v 1.62 2006/01/22 17:58:11 fox Exp $                       *
00023 ********************************************************************************/
00024 #ifndef FXTEXTFIELD_H
00025 #define FXTEXTFIELD_H
00026 
00027 #ifndef FXFRAME_H
00028 #include "FXFrame.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /// Textfield styles
00035 enum {
00036   TEXTFIELD_PASSWD     = 0x00080000,    /// Password mode
00037   TEXTFIELD_INTEGER    = 0x00100000,    /// Integer mode
00038   TEXTFIELD_REAL       = 0x00200000,    /// Real mode
00039   TEXTFIELD_READONLY   = 0x00400000,    /// NOT editable
00040   TEXTFIELD_ENTER_ONLY = 0x00800000,    /// Only callback when enter hit
00041   TEXTFIELD_LIMITED    = 0x01000000,    /// Limit entry to given number of columns
00042   TEXTFIELD_OVERSTRIKE = 0x02000000,    /// Overstrike mode
00043   TEXTFIELD_AUTOGRAY   = 0x04000000,    /// Automatically gray out text field when not updated
00044   TEXTFIELD_AUTOHIDE   = 0x08000000,    /// Automatically hide text field when not updated
00045   TEXTFIELD_NORMAL     = FRAME_SUNKEN|FRAME_THICK
00046   };
00047 
00048 
00049 /**
00050 * A text field is a single-line text entry widget.
00051 * The text field widget supports clipboard for cut-and-paste
00052 * operations.
00053 * Text input may be constrained to a certain format; the built-in
00054 * capabilities support integer and real number entry constraints;
00055 * additional constraints on the input may be implemented by intercepting
00056 * the SEL_VERIFY message; a custom handler should examine the tentative
00057 * input string passed as type const FXchar* in the message data, and return
00058 * a value of "0" if the new input is accepted.
00059 * During text entry, the text field sends a SEL_CHANGED message to its target,
00060 * with the message data set to the current text value of type const FXchar*.
00061 * When the text is accepted by hitting ENTER, the SEL_COMMAND message is sent.
00062 * The text field also sends SEL_COMMAND when the focus moves to another control.
00063 * TEXTFIELD_ENTER_ONLY can be passed to suppress this feature. Typically, this
00064 * flag is used in dialogs that close when ENTER is hit in a text field.
00065 */
00066 class FXAPI FXTextField : public FXFrame {
00067   FXDECLARE(FXTextField)
00068 protected:
00069   FXString      contents;       // Edited text
00070   const FXchar *delimiters;     // Set of delimiters
00071   FXFont       *font;           // Text font
00072   FXColor       textColor;      // Text color
00073   FXColor       selbackColor;   // Selected background color
00074   FXColor       seltextColor;   // Selected text color
00075   FXColor       cursorColor;    // Color of the Cursor
00076   FXint         cursor;         // Cursor position
00077   FXint         anchor;         // Anchor position
00078   FXint         columns;        // Number of columns visible
00079   FXint         shift;          // Shift amount
00080   FXString      clipped;        // Clipped text
00081   FXString      help;           // Help string
00082   FXString      tip;            // Tooltip
00083 protected:
00084   FXTextField();
00085   FXint index(FXint x) const;
00086   FXint coord(FXint i) const;
00087   void drawCursor(FXuint state);
00088   void drawTextRange(FXDCWindow& dc,FXint fm,FXint to);
00089   void drawTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to);
00090   void drawPWDTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to);
00091   FXint rightWord(FXint pos) const;
00092   FXint leftWord(FXint pos) const;
00093   FXint wordStart(FXint pos) const;
00094   FXint wordEnd(FXint pos) const;
00095 private:
00096   FXTextField(const FXTextField&);
00097   FXTextField& operator=(const FXTextField&);
00098 public:
00099   long onPaint(FXObject*,FXSelector,void*);
00100   long onUpdate(FXObject*,FXSelector,void*);
00101   long onKeyPress(FXObject*,FXSelector,void*);
00102   long onKeyRelease(FXObject*,FXSelector,void*);
00103   long onLeftBtnPress(FXObject*,FXSelector,void*);
00104   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00105   long onMiddleBtnPress(FXObject*,FXSelector,void*);
00106   long onMiddleBtnRelease(FXObject*,FXSelector,void*);
00107   long onVerify(FXObject*,FXSelector,void*);
00108   long onMotion(FXObject*,FXSelector,void*);
00109   long onSelectionLost(FXObject*,FXSelector,void*);
00110   long onSelectionGained(FXObject*,FXSelector,void*);
00111   long onSelectionRequest(FXObject*,FXSelector,void* ptr);
00112   long onClipboardLost(FXObject*,FXSelector,void*);
00113   long onClipboardGained(FXObject*,FXSelector,void*);
00114   long onClipboardRequest(FXObject*,FXSelector,void*);
00115   long onFocusSelf(FXObject*,FXSelector,void*);
00116   long onFocusIn(FXObject*,FXSelector,void*);
00117   long onFocusOut(FXObject*,FXSelector,void*);
00118   long onBlink(FXObject*,FXSelector,void*);
00119   long onAutoScroll(FXObject*,FXSelector,void*);
00120   long onCmdSetValue(FXObject*,FXSelector,void*);
00121   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00122   long onCmdSetRealValue(FXObject*,FXSelector,void*);
00123   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00124   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00125   long onCmdGetRealValue(FXObject*,FXSelector,void*);
00126   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00127   long onCmdCursorHome(FXObject*,FXSelector,void*);
00128   long onCmdCursorEnd(FXObject*,FXSelector,void*);
00129   long onCmdCursorRight(FXObject*,FXSelector,void*);
00130   long onCmdCursorLeft(FXObject*,FXSelector,void*);
00131   long onCmdCursorWordLeft(FXObject*,FXSelector,void*);
00132   long onCmdCursorWordRight(FXObject*,FXSelector,void*);
00133   long onCmdCursorWordStart(FXObject*,FXSelector,void*);
00134   long onCmdCursorWordEnd(FXObject*,FXSelector,void*);
00135   long onCmdMark(FXObject*,FXSelector,void*);
00136   long onCmdExtend(FXObject*,FXSelector,void*);
00137   long onCmdSelectAll(FXObject*,FXSelector,void*);
00138   long onCmdDeselectAll(FXObject*,FXSelector,void*);
00139   long onCmdCutSel(FXObject*,FXSelector,void*);
00140   long onCmdCopySel(FXObject*,FXSelector,void*);
00141   long onCmdPasteSel(FXObject*,FXSelector,void*);
00142   long onCmdPasteMiddle(FXObject*,FXSelector,void*);
00143   long onCmdDeleteSel(FXObject*,FXSelector,void*);
00144   long onCmdDeleteAll(FXObject*,FXSelector,void*);
00145   long onCmdOverstString(FXObject*,FXSelector,void*);
00146   long onCmdInsertString(FXObject*,FXSelector,void*);
00147   long onCmdBackspace(FXObject*,FXSelector,void*);
00148   long onCmdDelete(FXObject*,FXSelector,void*);
00149   long onCmdToggleEditable(FXObject*,FXSelector,void*);
00150   long onUpdToggleEditable(FXObject*,FXSelector,void*);
00151   long onCmdToggleOverstrike(FXObject*,FXSelector,void*);
00152   long onUpdToggleOverstrike(FXObject*,FXSelector,void*);
00153   long onUpdHaveSelection(FXObject*,FXSelector,void*);
00154   long onUpdSelectAll(FXObject*,FXSelector,void*);
00155   long onCmdSetHelp(FXObject*,FXSelector,void*);
00156   long onCmdGetHelp(FXObject*,FXSelector,void*);
00157   long onCmdSetTip(FXObject*,FXSelector,void*);
00158   long onCmdGetTip(FXObject*,FXSelector,void*);
00159   long onQueryHelp(FXObject*,FXSelector,void*);
00160   long onQueryTip(FXObject*,FXSelector,void*);
00161 public:
00162 
00163   /// Default text delimiters
00164   static const FXchar textDelimiters[];
00165 
00166 public:
00167 
00168   enum{
00169     ID_CURSOR_HOME=FXFrame::ID_LAST,
00170     ID_CURSOR_END,
00171     ID_CURSOR_RIGHT,
00172     ID_CURSOR_LEFT,
00173     ID_CURSOR_WORD_LEFT,
00174     ID_CURSOR_WORD_RIGHT,
00175     ID_CURSOR_WORD_START,
00176     ID_CURSOR_WORD_END,
00177     ID_MARK,
00178     ID_EXTEND,
00179     ID_SELECT_ALL,
00180     ID_DESELECT_ALL,
00181     ID_CUT_SEL,
00182     ID_COPY_SEL,
00183     ID_PASTE_SEL,
00184     ID_PASTE_MIDDLE,
00185     ID_DELETE_SEL,
00186     ID_DELETE_ALL,
00187     ID_OVERST_STRING,
00188     ID_INSERT_STRING,
00189     ID_BACKSPACE,
00190     ID_DELETE,
00191     ID_TOGGLE_EDITABLE,
00192     ID_TOGGLE_OVERSTRIKE,
00193     ID_BLINK,
00194     ID_LAST
00195     };
00196 
00197 public:
00198 
00199   /// Construct text field wide enough to display ncols columns
00200   FXTextField(FXComposite* p,FXint ncols,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=TEXTFIELD_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
00201 
00202   /// Create server-side resources
00203   virtual void create();
00204 
00205   /// Perform layout
00206   virtual void layout();
00207 
00208   /// Enable text field
00209   virtual void enable();
00210 
00211   /// Disable text field
00212   virtual void disable();
00213 
00214   /// Return default width
00215   virtual FXint getDefaultWidth();
00216 
00217   /// Return default height
00218   virtual FXint getDefaultHeight();
00219 
00220   /// Yes, text field may receive focus
00221   virtual bool canFocus() const;
00222 
00223   /// Move the focus to this window
00224   virtual void setFocus();
00225 
00226   /// Remove the focus from this window
00227   virtual void killFocus();
00228 
00229   /// Set editable mode
00230   void setEditable(FXbool edit=TRUE);
00231 
00232   /// Return TRUE if text field may be edited
00233   FXbool isEditable() const;
00234 
00235   /// Set overstrike mode
00236   void setOverstrike(FXbool over=TRUE);
00237 
00238   /// Return TRUE if overstrike mode in effect
00239   FXbool isOverstrike() const;
00240 
00241   /// Set cursor position
00242   void setCursorPos(FXint pos);
00243 
00244   /// Return cursor position
00245   FXint getCursorPos() const { return cursor; }
00246 
00247   /// Change anchor position
00248   void setAnchorPos(FXint pos);
00249 
00250   /// Return anchor position
00251   FXint getAnchorPos() const { return anchor; }
00252 
00253   /// Change the text and move cursor to end
00254   void setText(const FXString& text,FXbool notify=FALSE);
00255 
00256   /// Get the text for this label
00257   FXString getText() const { return contents; }
00258 
00259   /// Set the text font
00260   void setFont(FXFont* fnt);
00261 
00262   /// Get the text font
00263   FXFont* getFont() const { return font; }
00264 
00265   /// Change text color
00266   void setTextColor(FXColor clr);
00267 
00268   /// Return text color
00269   FXColor getTextColor() const { return textColor; }
00270 
00271   /// Change selected background color
00272   void setSelBackColor(FXColor clr);
00273 
00274   /// Return selected background color
00275   FXColor getSelBackColor() const { return selbackColor; }
00276 
00277   /// Change selected text color
00278   void setSelTextColor(FXColor clr);
00279 
00280   /// Return selected text color
00281   FXColor getSelTextColor() const { return seltextColor; }
00282 
00283   /// Changes the cursor color
00284   void setCursorColor(FXColor clr);
00285 
00286   /// Return the cursor color
00287   FXColor getCursorColor() const { return cursorColor; }
00288 
00289   /**
00290   * Change the default width of the text field in terms of a number
00291   * of columns times the width of the numeral '8'.
00292   */
00293   void setNumColumns(FXint cols);
00294 
00295   /// Return number of columns
00296   FXint getNumColumns() const { return columns; }
00297 
00298   /**
00299   * Change text justification mode. The justify mode is a combination of
00300   * horizontal justification (JUSTIFY_LEFT, JUSTIFY_RIGHT, or JUSTIFY_CENTER_X),
00301   * and vertical justification (JUSTIFY_TOP, JUSTIFY_BOTTOM, JUSTIFY_CENTER_Y).
00302   * Note that JUSTIFY_CENTER_X can not be set from the constructor since by
00303   * default text fields are left-justified.
00304   */
00305   void setJustify(FXuint mode);
00306 
00307   /// Return text justification mode
00308   FXuint getJustify() const;
00309 
00310   /// Change word delimiters
00311   void setDelimiters(const FXchar* delims=textDelimiters){ delimiters=delims; }
00312 
00313   /// Return word delimiters
00314   const FXchar* getDelimiters() const { return delimiters; }
00315 
00316   /// Set the status line help text for this label
00317   void setHelpText(const FXString& text){ help=text; }
00318 
00319   /// Get the status line help text for this label
00320   const FXString& getHelpText() const { return help; }
00321 
00322   /// Set the tool tip message for this text field
00323   void setTipText(const FXString& text){ tip=text; }
00324 
00325   /// Get the tool tip message for this text field
00326   const FXString& getTipText() const { return tip; }
00327 
00328   /// Change text style
00329   void setTextStyle(FXuint style);
00330 
00331   /// Return text style
00332   FXuint getTextStyle() const;
00333 
00334   /// Select all text
00335   FXbool selectAll();
00336 
00337   /// Select len characters starting at given position pos
00338   FXbool setSelection(FXint pos,FXint len);
00339 
00340   /// Extend the selection from the anchor to the given position
00341   FXbool extendSelection(FXint pos);
00342 
00343   /// Unselect the text
00344   FXbool killSelection();
00345 
00346   /// Return TRUE if position pos is selected
00347   FXbool isPosSelected(FXint pos) const;
00348 
00349   /// Return TRUE if position is fully visible
00350   FXbool isPosVisible(FXint pos) const;
00351 
00352   /// Scroll text to make the given position visible
00353   void makePositionVisible(FXint pos);
00354 
00355   /// Save text field to a stream
00356   virtual void save(FXStream& store) const;
00357 
00358   /// Load text field from a stream
00359   virtual void load(FXStream& store);
00360 
00361   /// Destructor
00362   virtual ~FXTextField();
00363   };
00364 
00365 }
00366 
00367 #endif

Copyright © 1997-2005 Jeroen van der Zijp