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,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (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                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXTextField.h,v 1.87 2009/01/06 13:07:28 fox Exp $                       *
00022 ********************************************************************************/
00023 #ifndef FXTEXTFIELD_H
00024 #define FXTEXTFIELD_H
00025 
00026 #ifndef FXFRAME_H
00027 #include "FXFrame.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 /// Textfield styles
00034 enum {
00035   TEXTFIELD_PASSWD     = 0x00080000,    /// Password mode
00036   TEXTFIELD_INTEGER    = 0x00100000,    /// Integer mode
00037   TEXTFIELD_REAL       = 0x00200000,    /// Real mode
00038   TEXTFIELD_READONLY   = 0x00400000,    /// NOT editable
00039   TEXTFIELD_ENTER_ONLY = 0x00800000,    /// Only callback when enter hit
00040   TEXTFIELD_LIMITED    = 0x01000000,    /// Limit entry to given number of columns
00041   TEXTFIELD_OVERSTRIKE = 0x02000000,    /// Overstrike mode
00042   TEXTFIELD_AUTOGRAY   = 0x04000000,    /// Automatically gray out text field when not updated
00043   TEXTFIELD_AUTOHIDE   = 0x08000000,    /// Automatically hide text field when not updated
00044   TEXTFIELD_NORMAL     = FRAME_SUNKEN|FRAME_THICK
00045   };
00046 
00047 
00048 /**
00049 * A text field is a single-line text entry widget.
00050 * The text field widget supports clipboard for cut-and-paste
00051 * operations.
00052 * Text input may be constrained to a certain format; the built-in
00053 * capabilities support integer and real number entry constraints;
00054 * additional constraints on the input may be implemented by intercepting
00055 * the SEL_VERIFY message; a custom handler should examine the tentative
00056 * input string passed as type const FXchar* in the message data, and return
00057 * a value of "0" if the new input is accepted.
00058 * During text entry, the text field sends a SEL_CHANGED message to its target,
00059 * with the message data set to the current text value of type const FXchar*.
00060 * When the text is accepted by hitting ENTER, the SEL_COMMAND message is sent.
00061 * The text field also sends SEL_COMMAND when the focus moves to another control.
00062 * TEXTFIELD_ENTER_ONLY can be passed to suppress this feature. Typically, this
00063 * flag is used in dialogs that close when ENTER is hit in a text field.
00064 */
00065 class FXAPI FXTextField : public FXFrame {
00066   FXDECLARE(FXTextField)
00067 protected:
00068   FXString      contents;       // Edited text
00069   const FXchar *delimiters;     // Set of delimiters
00070   FXFont       *font;           // Text font
00071   FXColor       textColor;      // Text color
00072   FXColor       selbackColor;   // Selected background color
00073   FXColor       seltextColor;   // Selected text color
00074   FXColor       cursorColor;    // Color of the Cursor
00075   FXint         cursor;         // Cursor position
00076   FXint         anchor;         // Anchor position
00077   FXint         columns;        // Number of columns visible
00078   FXint         shift;          // Shift amount
00079   FXString      clipped;        // Clipped text
00080   FXString      help;           // Help string
00081   FXString      tip;            // Tooltip
00082 protected:
00083   FXTextField();
00084   FXint index(FXint x) const;
00085   FXint coord(FXint i) const;
00086   FXint leftWord(FXint pos) const;
00087   FXint rightWord(FXint pos) const;
00088   FXint wordStart(FXint pos) const;
00089   FXint wordEnd(FXint pos) const;
00090   void drawCursor(FXuint state);
00091   void paintCursor(FXDCWindow& dc) const;
00092   void eraseCursor(FXDCWindow& dc) const;
00093   void drawTextRange(FXDCWindow& dc,FXint fm,FXint to) const;
00094   void drawTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to) const;
00095   void drawPWDTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to) const;
00096   void moveCursor(FXint pos);
00097   void moveCursorAndSelect(FXint pos);
00098   void enterText(const FXString& text,FXbool notify);
00099   FXbool deletePendingSelection(FXbool notify);
00100 private:
00101   FXTextField(const FXTextField&);
00102   FXTextField& operator=(const FXTextField&);
00103 public:
00104   long onPaint(FXObject*,FXSelector,void*);
00105   long onUpdate(FXObject*,FXSelector,void*);
00106   long onBlink(FXObject*,FXSelector,void*);
00107   long onFocusIn(FXObject*,FXSelector,void*);
00108   long onFocusOut(FXObject*,FXSelector,void*);
00109   long onFocusSelf(FXObject*,FXSelector,void*);
00110   long onMotion(FXObject*,FXSelector,void*);
00111   long onAutoScroll(FXObject*,FXSelector,void*);
00112   long onLeftBtnPress(FXObject*,FXSelector,void*);
00113   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00114   long onMiddleBtnPress(FXObject*,FXSelector,void*);
00115   long onMiddleBtnRelease(FXObject*,FXSelector,void*);
00116   long onKeyPress(FXObject*,FXSelector,void*);
00117   long onKeyRelease(FXObject*,FXSelector,void*);
00118   long onVerify(FXObject*,FXSelector,void*);
00119   long onSelectionLost(FXObject*,FXSelector,void*);
00120   long onSelectionGained(FXObject*,FXSelector,void*);
00121   long onSelectionRequest(FXObject*,FXSelector,void* ptr);
00122   long onClipboardLost(FXObject*,FXSelector,void*);
00123   long onClipboardGained(FXObject*,FXSelector,void*);
00124   long onClipboardRequest(FXObject*,FXSelector,void*);
00125   long onCmdSetTip(FXObject*,FXSelector,void*);
00126   long onCmdGetTip(FXObject*,FXSelector,void*);
00127   long onCmdSetHelp(FXObject*,FXSelector,void*);
00128   long onCmdGetHelp(FXObject*,FXSelector,void*);
00129   long onQueryTip(FXObject*,FXSelector,void*);
00130   long onQueryHelp(FXObject*,FXSelector,void*);
00131   long onUpdIsEditable(FXObject*,FXSelector,void*);
00132   long onUpdHaveSelection(FXObject*,FXSelector,void*);
00133   long onUpdHaveEditableSelection(FXObject*,FXSelector,void*);
00134 
00135   // Value access
00136   long onCmdSetValue(FXObject*,FXSelector,void*);
00137   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00138   long onCmdSetLongValue(FXObject*,FXSelector,void*);
00139   long onCmdSetRealValue(FXObject*,FXSelector,void*);
00140   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00141   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00142   long onCmdGetLongValue(FXObject*,FXSelector,void*);
00143   long onCmdGetRealValue(FXObject*,FXSelector,void*);
00144   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00145 
00146   // Cursor movement
00147   long onCmdCursorHome(FXObject*,FXSelector,void*);
00148   long onCmdCursorEnd(FXObject*,FXSelector,void*);
00149   long onCmdCursorRight(FXObject*,FXSelector,void*);
00150   long onCmdCursorLeft(FXObject*,FXSelector,void*);
00151   long onCmdCursorWordLeft(FXObject*,FXSelector,void*);
00152   long onCmdCursorWordRight(FXObject*,FXSelector,void*);
00153   long onCmdCursorShiftHome(FXObject*,FXSelector,void*);
00154   long onCmdCursorShiftEnd(FXObject*,FXSelector,void*);
00155   long onCmdCursorShiftRight(FXObject*,FXSelector,void*);
00156   long onCmdCursorShiftLeft(FXObject*,FXSelector,void*);
00157   long onCmdCursorShiftWordLeft(FXObject*,FXSelector,void*);
00158   long onCmdCursorShiftWordRight(FXObject*,FXSelector,void*);
00159 
00160   // Inserting
00161   long onCmdInsertString(FXObject*,FXSelector,void*);
00162   long onIMEStart(FXObject*,FXSelector,void*);
00163 
00164   // Manipulation Selection
00165   long onCmdCutSel(FXObject*,FXSelector,void*);
00166   long onCmdCopySel(FXObject*,FXSelector,void*);
00167   long onCmdPasteSel(FXObject*,FXSelector,void*);
00168   long onCmdDeleteSel(FXObject*,FXSelector,void*);
00169   long onCmdReplaceSel(FXObject*,FXSelector,void*);
00170   long onCmdPasteMiddle(FXObject*,FXSelector,void*);
00171   long onCmdSelectAll(FXObject*,FXSelector,void*);
00172   long onCmdDeselectAll(FXObject*,FXSelector,void*);
00173 
00174   // Deletion
00175   long onCmdBackspace(FXObject*,FXSelector,void*);
00176   long onCmdBackspaceWord(FXObject*,FXSelector,void*);
00177   long onCmdBackspaceBol(FXObject*,FXSelector,void*);
00178   long onCmdDelete(FXObject*,FXSelector,void*);
00179   long onCmdDeleteWord(FXObject*,FXSelector,void*);
00180   long onCmdDeleteEol(FXObject*,FXSelector,void*);
00181   long onCmdDeleteAll(FXObject*,FXSelector,void*);
00182 
00183   // Control commands
00184   long onCmdToggleEditable(FXObject*,FXSelector,void*);
00185   long onUpdToggleEditable(FXObject*,FXSelector,void*);
00186   long onCmdToggleOverstrike(FXObject*,FXSelector,void*);
00187   long onUpdToggleOverstrike(FXObject*,FXSelector,void*);
00188 public:
00189 
00190   /// Default text delimiters
00191   static const FXchar textDelimiters[];
00192 
00193 public:
00194 
00195   enum{
00196     ID_CURSOR_HOME=FXFrame::ID_LAST,
00197     ID_CURSOR_END,
00198     ID_CURSOR_RIGHT,
00199     ID_CURSOR_LEFT,
00200     ID_CURSOR_WORD_LEFT,
00201     ID_CURSOR_WORD_RIGHT,
00202     ID_CURSOR_SHIFT_HOME,
00203     ID_CURSOR_SHIFT_END,
00204     ID_CURSOR_SHIFT_LEFT,
00205     ID_CURSOR_SHIFT_RIGHT,
00206     ID_CURSOR_SHIFT_WORD_LEFT,
00207     ID_CURSOR_SHIFT_WORD_RIGHT,
00208     ID_SELECT_ALL,
00209     ID_DESELECT_ALL,
00210     ID_CUT_SEL,
00211     ID_COPY_SEL,
00212     ID_DELETE_SEL,
00213     ID_REPLACE_SEL,
00214     ID_PASTE_SEL,
00215     ID_PASTE_MIDDLE,
00216     ID_INSERT_STRING,
00217     ID_BACKSPACE,
00218     ID_BACKSPACE_WORD,
00219     ID_BACKSPACE_BOL,
00220     ID_DELETE,
00221     ID_DELETE_WORD,
00222     ID_DELETE_EOL,
00223     ID_DELETE_ALL,
00224     ID_TOGGLE_EDITABLE,
00225     ID_TOGGLE_OVERSTRIKE,
00226     ID_BLINK,
00227     ID_LAST
00228     };
00229 
00230 public:
00231 
00232   /// Construct text field wide enough to display ncols columns
00233   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);
00234 
00235   /// Create server-side resources
00236   virtual void create();
00237 
00238   /// Perform layout
00239   virtual void layout();
00240 
00241   /// Enable text field
00242   virtual void enable();
00243 
00244   /// Disable text field
00245   virtual void disable();
00246 
00247   /// Return default width
00248   virtual FXint getDefaultWidth();
00249 
00250   /// Return default height
00251   virtual FXint getDefaultHeight();
00252 
00253   /// Yes, text field may receive focus
00254   virtual FXbool canFocus() const;
00255 
00256   /// Move the focus to this window
00257   virtual void setFocus();
00258 
00259   /// Remove the focus from this window
00260   virtual void killFocus();
00261 
00262   /// Change the default width in terms of visible columns
00263   void setNumColumns(FXint cols);
00264 
00265   /// Return number of visible columns
00266   FXint getNumColumns() const { return columns; }
00267 
00268   /// Get entire text
00269   FXString getText() const { return contents; }
00270 
00271   /// Get selected text
00272   FXString getSelectedText() const;
00273 
00274   /// Change the text and move cursor to end
00275   void setText(const FXString& text,FXbool notify=false);
00276 
00277   /// Replace range of bytes with text
00278   void replaceText(FXint pos,FXint m,const FXString& text,FXbool notify=false);
00279 
00280   /// Append text at the end
00281   void appendText(const FXString& text,FXbool notify=false);
00282 
00283   /// Insert text at position
00284   void insertText(FXint pos,const FXString& text,FXbool notify=false);
00285 
00286   /// Remove range of text
00287   void removeText(FXint pos,FXint m,FXbool notify=false);
00288 
00289   /// Select all text
00290   FXbool selectAll();
00291 
00292   /// Select len characters starting at given position pos
00293   FXbool setSelection(FXint pos,FXint len);
00294 
00295   /// Extend the selection from the anchor to the given position
00296   FXbool extendSelection(FXint pos);
00297 
00298   /// Copy primary selection to clipboard
00299   FXbool copySelection();
00300 
00301   /// Cut primary selection to clipboard
00302   FXbool cutSelection(FXbool notify=false);
00303 
00304   /// Delete primary selection
00305   FXbool deleteSelection(FXbool notify=false);
00306 
00307   /// Replace primary selection by other text
00308   FXbool replaceSelection(const FXString& text,FXbool notify=false);
00309 
00310   /// Paste primary selection
00311   FXbool pasteSelection(FXbool notify=false);
00312 
00313   /// Paste clipboard
00314   FXbool pasteClipboard(FXbool notify=false);
00315 
00316   /// Unselect the text
00317   FXbool killSelection();
00318 
00319   /// Return true if position pos is selected
00320   FXbool isPosSelected(FXint pos) const;
00321 
00322   /// Return true if position is fully visible
00323   FXbool isPosVisible(FXint pos) const;
00324 
00325   /// Scroll text to make the given position visible
00326   void makePositionVisible(FXint pos);
00327 
00328    /// Set cursor position
00329   void setCursorPos(FXint pos);
00330 
00331   /// Return cursor position
00332   FXint getCursorPos() const { return cursor; }
00333 
00334   /// Change anchor position
00335   void setAnchorPos(FXint pos);
00336 
00337   /// Return anchor position
00338   FXint getAnchorPos() const { return anchor; }
00339 
00340  /// Set editable mode
00341   void setEditable(FXbool edit=true);
00342 
00343   /// Return true if text field may be edited
00344   FXbool isEditable() const;
00345 
00346   /// Set overstrike mode
00347   void setOverstrike(FXbool over=true);
00348 
00349   /// Return true if overstrike mode in effect
00350   FXbool isOverstrike() const;
00351 
00352   /**
00353   * Change text justification mode. The justify mode is a combination of
00354   * horizontal justification (JUSTIFY_LEFT, JUSTIFY_RIGHT, or JUSTIFY_CENTER_X),
00355   * and vertical justification (JUSTIFY_TOP, JUSTIFY_BOTTOM, JUSTIFY_CENTER_Y).
00356   * Note that JUSTIFY_CENTER_X can not be set from the constructor since by
00357   * default text fields are left-justified.
00358   */
00359   void setJustify(FXuint mode);
00360 
00361   /// Return text justification mode
00362   FXuint getJustify() const;
00363 
00364   /// Change word delimiters
00365   void setDelimiters(const FXchar* delims=textDelimiters){ delimiters=delims; }
00366 
00367   /// Return word delimiters
00368   const FXchar* getDelimiters() const { return delimiters; }
00369 
00370   /// Change text style
00371   void setTextStyle(FXuint style);
00372 
00373   /// Return text style
00374   FXuint getTextStyle() const;
00375 
00376   /// Set the text font
00377   void setFont(FXFont* fnt);
00378 
00379   /// Get the text font
00380   FXFont* getFont() const { return font; }
00381 
00382   /// Change text color
00383   void setTextColor(FXColor clr);
00384 
00385   /// Return text color
00386   FXColor getTextColor() const { return textColor; }
00387 
00388   /// Change selected background color
00389   void setSelBackColor(FXColor clr);
00390 
00391   /// Return selected background color
00392   FXColor getSelBackColor() const { return selbackColor; }
00393 
00394   /// Change selected text color
00395   void setSelTextColor(FXColor clr);
00396 
00397   /// Return selected text color
00398   FXColor getSelTextColor() const { return seltextColor; }
00399 
00400   /// Changes the cursor color
00401   void setCursorColor(FXColor clr);
00402 
00403   /// Return the cursor color
00404   FXColor getCursorColor() const { return cursorColor; }
00405 
00406   /// Set the status line help text for this label
00407   void setHelpText(const FXString& text){ help=text; }
00408 
00409   /// Get the status line help text for this label
00410   const FXString& getHelpText() const { return help; }
00411 
00412   /// Set the tool tip message for this text field
00413   void setTipText(const FXString& text){ tip=text; }
00414 
00415   /// Get the tool tip message for this text field
00416   const FXString& getTipText() const { return tip; }
00417 
00418   /// Save text field to a stream
00419   virtual void save(FXStream& store) const;
00420 
00421   /// Load text field from a stream
00422   virtual void load(FXStream& store);
00423 
00424   /// Destructor
00425   virtual ~FXTextField();
00426   };
00427 
00428 }
00429 
00430 #endif

Copyright © 1997-2009 Jeroen van der Zijp