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