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,2005 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.58 2005/01/16 16:06:06 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 onCmdDeleteSel(FXObject*,FXSelector,void*); 00143 long onCmdDeleteAll(FXObject*,FXSelector,void*); 00144 long onCmdOverstString(FXObject*,FXSelector,void*); 00145 long onCmdInsertString(FXObject*,FXSelector,void*); 00146 long onCmdBackspace(FXObject*,FXSelector,void*); 00147 long onCmdDelete(FXObject*,FXSelector,void*); 00148 long onCmdToggleEditable(FXObject*,FXSelector,void*); 00149 long onUpdToggleEditable(FXObject*,FXSelector,void*); 00150 long onCmdToggleOverstrike(FXObject*,FXSelector,void*); 00151 long onUpdToggleOverstrike(FXObject*,FXSelector,void*); 00152 long onUpdHaveSelection(FXObject*,FXSelector,void*); 00153 long onUpdSelectAll(FXObject*,FXSelector,void*); 00154 long onCmdSetHelp(FXObject*,FXSelector,void*); 00155 long onCmdGetHelp(FXObject*,FXSelector,void*); 00156 long onCmdSetTip(FXObject*,FXSelector,void*); 00157 long onCmdGetTip(FXObject*,FXSelector,void*); 00158 long onQueryHelp(FXObject*,FXSelector,void*); 00159 long onQueryTip(FXObject*,FXSelector,void*); 00160 public: 00161 00162 /// Default text delimiters 00163 static const FXchar textDelimiters[]; 00164 00165 public: 00166 00167 enum{ 00168 ID_CURSOR_HOME=FXFrame::ID_LAST, 00169 ID_CURSOR_END, 00170 ID_CURSOR_RIGHT, 00171 ID_CURSOR_LEFT, 00172 ID_CURSOR_WORD_LEFT, 00173 ID_CURSOR_WORD_RIGHT, 00174 ID_CURSOR_WORD_START, 00175 ID_CURSOR_WORD_END, 00176 ID_MARK, 00177 ID_EXTEND, 00178 ID_SELECT_ALL, 00179 ID_DESELECT_ALL, 00180 ID_CUT_SEL, 00181 ID_COPY_SEL, 00182 ID_PASTE_SEL, 00183 ID_DELETE_SEL, 00184 ID_DELETE_ALL, 00185 ID_OVERST_STRING, 00186 ID_INSERT_STRING, 00187 ID_BACKSPACE, 00188 ID_DELETE, 00189 ID_TOGGLE_EDITABLE, 00190 ID_TOGGLE_OVERSTRIKE, 00191 ID_BLINK, 00192 ID_LAST 00193 }; 00194 00195 public: 00196 00197 /// Construct text field wide enough to display ncols columns 00198 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); 00199 00200 /// Create server-side resources 00201 virtual void create(); 00202 00203 /// Perform layout 00204 virtual void layout(); 00205 00206 /// Enable text field 00207 virtual void enable(); 00208 00209 /// Disable text field 00210 virtual void disable(); 00211 00212 /// Return default width 00213 virtual FXint getDefaultWidth(); 00214 00215 /// Return default height 00216 virtual FXint getDefaultHeight(); 00217 00218 /// Yes, text field may receive focus 00219 virtual FXbool canFocus() const; 00220 00221 /// Move the focus to this window 00222 virtual void setFocus(); 00223 00224 /// Remove the focus from this window 00225 virtual void killFocus(); 00226 00227 /// Return TRUE if text field may be edited 00228 FXbool isEditable() const; 00229 00230 /// Change text field editability 00231 void setEditable(FXbool edit=TRUE); 00232 00233 /// Set cursor position 00234 void setCursorPos(FXint pos); 00235 00236 /// Return cursor position 00237 FXint getCursorPos() const { return cursor; } 00238 00239 /// Change anchor position 00240 void setAnchorPos(FXint pos); 00241 00242 /// Return anchor position 00243 FXint getAnchorPos() const { return anchor; } 00244 00245 /// Set the text for this label 00246 void setText(const FXString& text); 00247 00248 /// Get the text for this label 00249 FXString getText() const { return contents; } 00250 00251 /// Set the text font 00252 void setFont(FXFont* fnt); 00253 00254 /// Get the text font 00255 FXFont* getFont() const { return font; } 00256 00257 /// Change text color 00258 void setTextColor(FXColor clr); 00259 00260 /// Return text color 00261 FXColor getTextColor() const { return textColor; } 00262 00263 /// Change selected background color 00264 void setSelBackColor(FXColor clr); 00265 00266 /// Return selected background color 00267 FXColor getSelBackColor() const { return selbackColor; } 00268 00269 /// Change selected text color 00270 void setSelTextColor(FXColor clr); 00271 00272 /// Return selected text color 00273 FXColor getSelTextColor() const { return seltextColor; } 00274 00275 /// Changes the cursor color 00276 void setCursorColor(FXColor clr); 00277 00278 /// Return the cursor color 00279 FXColor getCursorColor() const { return cursorColor; } 00280 00281 /** 00282 * Change the default width of the text field in terms of a number 00283 * of columns times the width of the numeral '8'. 00284 */ 00285 void setNumColumns(FXint cols); 00286 00287 /// Return number of columns 00288 FXint getNumColumns() const { return columns; } 00289 00290 /** 00291 * Change text justification mode. The justify mode is a combination of 00292 * horizontal justification (JUSTIFY_LEFT, JUSTIFY_RIGHT, or JUSTIFY_CENTER_X), 00293 * and vertical justification (JUSTIFY_TOP, JUSTIFY_BOTTOM, JUSTIFY_CENTER_Y). 00294 * Note that JUSTIFY_CENTER_X can not be set from the constructor since by 00295 * default text fields are left-justified. 00296 */ 00297 void setJustify(FXuint mode); 00298 00299 /// Return text justification mode 00300 FXuint getJustify() const; 00301 00302 /// Change word delimiters 00303 void setDelimiters(const FXchar* delims=textDelimiters){ delimiters=delims; } 00304 00305 /// Return word delimiters 00306 const FXchar* getDelimiters() const { return delimiters; } 00307 00308 /// Set the status line help text for this label 00309 void setHelpText(const FXString& text){ help=text; } 00310 00311 /// Get the status line help text for this label 00312 const FXString& getHelpText() const { return help; } 00313 00314 /// Set the tool tip message for this text field 00315 void setTipText(const FXString& text){ tip=text; } 00316 00317 /// Get the tool tip message for this text field 00318 const FXString& getTipText() const { return tip; } 00319 00320 /// Change text style 00321 void setTextStyle(FXuint style); 00322 00323 /// Return text style 00324 FXuint getTextStyle() const; 00325 00326 /// Select all text 00327 FXbool selectAll(); 00328 00329 /// Select len characters starting at given position pos 00330 FXbool setSelection(FXint pos,FXint len); 00331 00332 /// Extend the selection from the anchor to the given position 00333 FXbool extendSelection(FXint pos); 00334 00335 /// Unselect the text 00336 FXbool killSelection(); 00337 00338 /// Return TRUE if position pos is selected 00339 FXbool isPosSelected(FXint pos) const; 00340 00341 /// Return TRUE if position is fully visible 00342 FXbool isPosVisible(FXint pos) const; 00343 00344 /// Scroll text to make the given position visible 00345 void makePositionVisible(FXint pos); 00346 00347 /// Save text field to a stream 00348 virtual void save(FXStream& store) const; 00349 00350 /// Load text field from a stream 00351 virtual void load(FXStream& store); 00352 00353 /// Destructor 00354 virtual ~FXTextField(); 00355 }; 00356 00357 } 00358 00359 #endif

Copyright © 1997-2005 Jeroen van der Zijp