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

FXTextField.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                         T e x t   F i e l d   W i d g e t                     *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2002 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.38 2002/09/30 13:06:56 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 struct FXTimer;
00035 
00036 
00037 /// Textfield styles
00038 enum {
00039   TEXTFIELD_PASSWD     = 0x00800000,      /// Password mode
00040   TEXTFIELD_INTEGER    = 0x01000000,      /// Integer mode
00041   TEXTFIELD_REAL       = 0x02000000,      /// Real mode
00042   TEXTFIELD_READONLY   = 0x04000000,      /// NOT editable
00043   TEXTFIELD_ENTER_ONLY = 0x08000000,      /// Only callback when enter hit
00044   TEXTFIELD_LIMITED    = 0x10000000,      /// Limit entry to given number of columns
00045   TEXTFIELD_OVERSTRIKE = 0x20000000,      /// Overstrike mode
00046   TEXTFIELD_NORMAL     = FRAME_SUNKEN|FRAME_THICK
00047   };
00048 
00049 
00050 /**
00051 * A text field is a single-line text entry widget.
00052 * The text field widget supports clipboard for cut-and-paste
00053 * operations.
00054 * Text input may be constrained to a certain format; the built-in
00055 * capabilities support integer and real number entry constraints;
00056 * additional constraints on the input may be implemented by intercepting
00057 * the SEL_VERIFY message; a custom handler should examine the tentative
00058 * input string passed as type const FXchar* in the message data, and return
00059 * a value of "0" if the new input is accepted.
00060 * During text entry, the text field sends a SEL_CHANGED message to its target,
00061 * with the message data set to the current text value of type const FXchar*.
00062 * When the text is accepted by hitting ENTER, the SEL_COMMAND message is sent.
00063 */
00064 class FXAPI FXTextField : public FXFrame {
00065   FXDECLARE(FXTextField)
00066 protected:
00067   FXString     contents;                  // Edited text
00068   FXFont      *font;                      // Text font
00069   FXColor      textColor;                 // Text color
00070   FXColor      selbackColor;              // Selected background color
00071   FXColor      seltextColor;              // Selected text color
00072   FXint        cursor;                    // Cursor position
00073   FXint        anchor;                    // Anchor position
00074   FXTimer     *blinker;                   // Blink timer
00075   FXint        columns;                   // Number of columns visible
00076   FXint        shift;                     // Shift amount
00077   FXString     clipped;                   // Clipped text
00078   FXString     help;                      // Help string
00079   FXString     tip;                       // Tooltip
00080 protected:
00081   FXTextField();
00082   FXint index(FXint x) const;
00083   FXint coord(FXint i) const;
00084   virtual void layout();
00085   void drawCursor(FXuint state);
00086   void drawTextRange(FXDCWindow& dc,FXint fm,FXint to);
00087   void drawTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to);
00088   void drawPWDTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to);
00089 private:
00090   FXTextField(const FXTextField&);
00091   FXTextField& operator=(const FXTextField&);
00092 public:
00093   long onPaint(FXObject*,FXSelector,void*);
00094   long onKeyPress(FXObject*,FXSelector,void*);
00095   long onKeyRelease(FXObject*,FXSelector,void*);
00096   long onLeftBtnPress(FXObject*,FXSelector,void*);
00097   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00098   long onMiddleBtnPress(FXObject*,FXSelector,void*);
00099   long onMiddleBtnRelease(FXObject*,FXSelector,void*);
00100   long onVerify(FXObject*,FXSelector,void*);
00101   long onMotion(FXObject*,FXSelector,void*);
00102   long onSelectionLost(FXObject*,FXSelector,void*);
00103   long onSelectionGained(FXObject*,FXSelector,void*);
00104   long onSelectionRequest(FXObject*,FXSelector,void* ptr);
00105   long onClipboardLost(FXObject*,FXSelector,void*);
00106   long onClipboardGained(FXObject*,FXSelector,void*);
00107   long onClipboardRequest(FXObject*,FXSelector,void*);
00108   long onFocusSelf(FXObject*,FXSelector,void*);
00109   long onFocusIn(FXObject*,FXSelector,void*);
00110   long onFocusOut(FXObject*,FXSelector,void*);
00111   long onBlink(FXObject*,FXSelector,void*);
00112   long onAutoScroll(FXObject*,FXSelector,void*);
00113   long onQueryHelp(FXObject*,FXSelector,void*);
00114   long onQueryTip(FXObject*,FXSelector,void*);
00115   long onCmdSetValue(FXObject*,FXSelector,void*);
00116   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00117   long onCmdSetRealValue(FXObject*,FXSelector,void*);
00118   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00119   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00120   long onCmdGetRealValue(FXObject*,FXSelector,void*);
00121   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00122   long onCmdCursorHome(FXObject*,FXSelector,void*);
00123   long onCmdCursorEnd(FXObject*,FXSelector,void*);
00124   long onCmdCursorRight(FXObject*,FXSelector,void*);
00125   long onCmdCursorLeft(FXObject*,FXSelector,void*);
00126   long onCmdMark(FXObject*,FXSelector,void*);
00127   long onCmdExtend(FXObject*,FXSelector,void*);
00128   long onCmdSelectAll(FXObject*,FXSelector,void*);
00129   long onCmdDeselectAll(FXObject*,FXSelector,void*);
00130   long onCmdCutSel(FXObject*,FXSelector,void*);
00131   long onCmdCopySel(FXObject*,FXSelector,void*);
00132   long onCmdPasteSel(FXObject*,FXSelector,void*);
00133   long onCmdDeleteSel(FXObject*,FXSelector,void*);
00134   long onCmdOverstString(FXObject*,FXSelector,void*);
00135   long onCmdInsertString(FXObject*,FXSelector,void*);
00136   long onCmdBackspace(FXObject*,FXSelector,void*);
00137   long onCmdDelete(FXObject*,FXSelector,void*);
00138   long onCmdToggleEditable(FXObject*,FXSelector,void*);
00139   long onUpdToggleEditable(FXObject*,FXSelector,void*);
00140   long onCmdToggleOverstrike(FXObject*,FXSelector,void*);
00141   long onUpdToggleOverstrike(FXObject*,FXSelector,void*);
00142   long onUpdHaveSelection(FXObject*,FXSelector,void*);
00143   long onUpdSelectAll(FXObject*,FXSelector,void*);
00144 public:
00145   enum{
00146     ID_CURSOR_HOME=FXFrame::ID_LAST,
00147     ID_CURSOR_END,
00148     ID_CURSOR_RIGHT,
00149     ID_CURSOR_LEFT,
00150     ID_MARK,
00151     ID_EXTEND,
00152     ID_SELECT_ALL,
00153     ID_DESELECT_ALL,
00154     ID_CUT_SEL,
00155     ID_COPY_SEL,
00156     ID_PASTE_SEL,
00157     ID_DELETE_SEL,
00158     ID_OVERST_STRING,
00159     ID_INSERT_STRING,
00160     ID_BACKSPACE,
00161     ID_DELETE,
00162     ID_TOGGLE_EDITABLE,
00163     ID_TOGGLE_OVERSTRIKE,
00164     ID_BLINK,
00165     ID_LAST
00166     };
00167 public:
00168 
00169   /// Construct text field wide enough to display ncols columns
00170   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);
00171 
00172   /// Create server-side resources
00173   virtual void create();
00174 
00175   /// Enable text field
00176   virtual void enable();
00177 
00178   /// Disable text field
00179   virtual void disable();
00180 
00181   /// Return default width
00182   virtual FXint getDefaultWidth();
00183 
00184   /// Return default height
00185   virtual FXint getDefaultHeight();
00186 
00187   /// Yes, text field may receive focus
00188   virtual FXbool canFocus() const;
00189 
00190   /// Move the focus to this window
00191   virtual void setFocus();
00192 
00193   /// Remove the focus from this window
00194   virtual void killFocus();
00195 
00196   /// Return TRUE if text field may be edited
00197   FXbool isEditable() const;
00198 
00199   /// Change text field editability
00200   void setEditable(FXbool edit=TRUE);
00201 
00202   /// Set cursor position
00203   void setCursorPos(FXint pos);
00204 
00205   /// Return cursor position
00206   FXint getCursorPos() const { return cursor; }
00207 
00208   /// Change anchor position
00209   void setAnchorPos(FXint pos);
00210 
00211   /// Return anchor position
00212   FXint getAnchorPos() const { return anchor; }
00213 
00214   /// Set the text for this label
00215   void setText(const FXString& text);
00216 
00217   /// Get the text for this label
00218   FXString getText() const { return contents; }
00219 
00220   /// Set the text font
00221   void setFont(FXFont* fnt);
00222 
00223   /// Get the text font
00224   FXFont* getFont() const { return font; }
00225 
00226   /// Change text color
00227   void setTextColor(FXColor clr);
00228 
00229   /// Return text color
00230   FXColor getTextColor() const { return textColor; }
00231 
00232   /// Change selected background color
00233   void setSelBackColor(FXColor clr);
00234 
00235   /// Return selected background color
00236   FXColor getSelBackColor() const { return selbackColor; }
00237 
00238   /// Change selected text color
00239   void setSelTextColor(FXColor clr);
00240 
00241   /// Return selected text color
00242   FXColor getSelTextColor() const { return seltextColor; }
00243 
00244   /// Change width of text field in terms of number of columns * `m'
00245   void setNumColumns(FXint cols);
00246 
00247   /// Return number of columns
00248   FXint getNumColumns() const { return columns; }
00249 
00250   /// Change text justification mode
00251   void setJustify(FXuint mode);
00252 
00253   /// Return text justification mode
00254   FXuint getJustify() const;
00255 
00256   /// Set the status line help text for this label
00257   void setHelpText(const FXString& text);
00258 
00259   /// Get the status line help text for this label
00260   const FXString& getHelpText() const { return help; }
00261 
00262   /// Set the tool tip message for this text field
00263   void setTipText(const FXString& text);
00264 
00265   /// Get the tool tip message for this text field
00266   const FXString& getTipText() const { return tip; }
00267 
00268   /// Change text style
00269   void setTextStyle(FXuint style);
00270 
00271   /// Return text style
00272   FXuint getTextStyle() const;
00273 
00274   /// Select all text
00275   FXbool selectAll();
00276 
00277   /// Select len characters starting at given position pos
00278   FXbool setSelection(FXint pos,FXint len);
00279 
00280   /// Extend the selection from the anchor to the given position
00281   FXbool extendSelection(FXint pos);
00282 
00283   /// Unselect the text
00284   FXbool killSelection();
00285 
00286   /// Return TRUE if position pos is selected
00287   FXbool isPosSelected(FXint pos) const;
00288 
00289   /// Return TRUE if position is fully visible
00290   FXbool isPosVisible(FXint pos) const;
00291 
00292   /// Scroll text to make the given position visible
00293   void makePositionVisible(FXint pos);
00294 
00295   /// Save text field to a stream
00296   virtual void save(FXStream& store) const;
00297 
00298   /// Load text field from a stream
00299   virtual void load(FXStream& store);
00300 
00301   /// Destructor
00302   virtual ~FXTextField();
00303   };
00304 
00305 }
00306 
00307 #endif