Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * T e x t F i e l d W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2004 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.51 2004/02/08 17:17:34 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 */ 00063 class FXAPI FXTextField : public FXFrame { 00064 FXDECLARE(FXTextField) 00065 protected: 00066 FXString contents; // Edited text 00067 const FXchar *delimiters; // Set of delimiters 00068 FXFont *font; // Text font 00069 FXColor textColor; // Text color 00070 FXColor selbackColor; // Selected background color 00071 FXColor seltextColor; // Selected text color 00072 FXColor cursorColor; // Color of the Cursor 00073 FXint cursor; // Cursor position 00074 FXint anchor; // Anchor position 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 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 FXint rightWord(FXint pos) const; 00089 FXint leftWord(FXint pos) const; 00090 FXint wordStart(FXint pos) const; 00091 FXint wordEnd(FXint pos) const; 00092 private: 00093 FXTextField(const FXTextField&); 00094 FXTextField& operator=(const FXTextField&); 00095 public: 00096 long onPaint(FXObject*,FXSelector,void*); 00097 long onUpdate(FXObject*,FXSelector,void*); 00098 long onKeyPress(FXObject*,FXSelector,void*); 00099 long onKeyRelease(FXObject*,FXSelector,void*); 00100 long onLeftBtnPress(FXObject*,FXSelector,void*); 00101 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00102 long onMiddleBtnPress(FXObject*,FXSelector,void*); 00103 long onMiddleBtnRelease(FXObject*,FXSelector,void*); 00104 long onVerify(FXObject*,FXSelector,void*); 00105 long onMotion(FXObject*,FXSelector,void*); 00106 long onSelectionLost(FXObject*,FXSelector,void*); 00107 long onSelectionGained(FXObject*,FXSelector,void*); 00108 long onSelectionRequest(FXObject*,FXSelector,void* ptr); 00109 long onClipboardLost(FXObject*,FXSelector,void*); 00110 long onClipboardGained(FXObject*,FXSelector,void*); 00111 long onClipboardRequest(FXObject*,FXSelector,void*); 00112 long onFocusSelf(FXObject*,FXSelector,void*); 00113 long onFocusIn(FXObject*,FXSelector,void*); 00114 long onFocusOut(FXObject*,FXSelector,void*); 00115 long onBlink(FXObject*,FXSelector,void*); 00116 long onAutoScroll(FXObject*,FXSelector,void*); 00117 long onCmdSetValue(FXObject*,FXSelector,void*); 00118 long onCmdSetIntValue(FXObject*,FXSelector,void*); 00119 long onCmdSetRealValue(FXObject*,FXSelector,void*); 00120 long onCmdSetStringValue(FXObject*,FXSelector,void*); 00121 long onCmdGetIntValue(FXObject*,FXSelector,void*); 00122 long onCmdGetRealValue(FXObject*,FXSelector,void*); 00123 long onCmdGetStringValue(FXObject*,FXSelector,void*); 00124 long onCmdCursorHome(FXObject*,FXSelector,void*); 00125 long onCmdCursorEnd(FXObject*,FXSelector,void*); 00126 long onCmdCursorRight(FXObject*,FXSelector,void*); 00127 long onCmdCursorLeft(FXObject*,FXSelector,void*); 00128 long onCmdCursorWordLeft(FXObject*,FXSelector,void*); 00129 long onCmdCursorWordRight(FXObject*,FXSelector,void*); 00130 long onCmdCursorWordStart(FXObject*,FXSelector,void*); 00131 long onCmdCursorWordEnd(FXObject*,FXSelector,void*); 00132 long onCmdMark(FXObject*,FXSelector,void*); 00133 long onCmdExtend(FXObject*,FXSelector,void*); 00134 long onCmdSelectAll(FXObject*,FXSelector,void*); 00135 long onCmdDeselectAll(FXObject*,FXSelector,void*); 00136 long onCmdCutSel(FXObject*,FXSelector,void*); 00137 long onCmdCopySel(FXObject*,FXSelector,void*); 00138 long onCmdPasteSel(FXObject*,FXSelector,void*); 00139 long onCmdDeleteSel(FXObject*,FXSelector,void*); 00140 long onCmdDeleteAll(FXObject*,FXSelector,void*); 00141 long onCmdOverstString(FXObject*,FXSelector,void*); 00142 long onCmdInsertString(FXObject*,FXSelector,void*); 00143 long onCmdBackspace(FXObject*,FXSelector,void*); 00144 long onCmdDelete(FXObject*,FXSelector,void*); 00145 long onCmdToggleEditable(FXObject*,FXSelector,void*); 00146 long onUpdToggleEditable(FXObject*,FXSelector,void*); 00147 long onCmdToggleOverstrike(FXObject*,FXSelector,void*); 00148 long onUpdToggleOverstrike(FXObject*,FXSelector,void*); 00149 long onUpdHaveSelection(FXObject*,FXSelector,void*); 00150 long onUpdSelectAll(FXObject*,FXSelector,void*); 00151 long onCmdSetHelp(FXObject*,FXSelector,void*); 00152 long onCmdGetHelp(FXObject*,FXSelector,void*); 00153 long onCmdSetTip(FXObject*,FXSelector,void*); 00154 long onCmdGetTip(FXObject*,FXSelector,void*); 00155 long onQueryHelp(FXObject*,FXSelector,void*); 00156 long onQueryTip(FXObject*,FXSelector,void*); 00157 public: 00158 00159 /// Default text delimiters 00160 static const FXchar textDelimiters[]; 00161 00162 public: 00163 00164 enum{ 00165 ID_CURSOR_HOME=FXFrame::ID_LAST, 00166 ID_CURSOR_END, 00167 ID_CURSOR_RIGHT, 00168 ID_CURSOR_LEFT, 00169 ID_CURSOR_WORD_LEFT, 00170 ID_CURSOR_WORD_RIGHT, 00171 ID_CURSOR_WORD_START, 00172 ID_CURSOR_WORD_END, 00173 ID_MARK, 00174 ID_EXTEND, 00175 ID_SELECT_ALL, 00176 ID_DESELECT_ALL, 00177 ID_CUT_SEL, 00178 ID_COPY_SEL, 00179 ID_PASTE_SEL, 00180 ID_DELETE_SEL, 00181 ID_DELETE_ALL, 00182 ID_OVERST_STRING, 00183 ID_INSERT_STRING, 00184 ID_BACKSPACE, 00185 ID_DELETE, 00186 ID_TOGGLE_EDITABLE, 00187 ID_TOGGLE_OVERSTRIKE, 00188 ID_BLINK, 00189 ID_LAST 00190 }; 00191 00192 public: 00193 00194 /// Construct text field wide enough to display ncols columns 00195 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); 00196 00197 /// Create server-side resources 00198 virtual void create(); 00199 00200 /// Perform layout 00201 virtual void layout(); 00202 00203 /// Enable text field 00204 virtual void enable(); 00205 00206 /// Disable text field 00207 virtual void disable(); 00208 00209 /// Return default width 00210 virtual FXint getDefaultWidth(); 00211 00212 /// Return default height 00213 virtual FXint getDefaultHeight(); 00214 00215 /// Yes, text field may receive focus 00216 virtual FXbool canFocus() const; 00217 00218 /// Move the focus to this window 00219 virtual void setFocus(); 00220 00221 /// Remove the focus from this window 00222 virtual void killFocus(); 00223 00224 /// Return TRUE if text field may be edited 00225 FXbool isEditable() const; 00226 00227 /// Change text field editability 00228 void setEditable(FXbool edit=TRUE); 00229 00230 /// Set cursor position 00231 void setCursorPos(FXint pos); 00232 00233 /// Return cursor position 00234 FXint getCursorPos() const { return cursor; } 00235 00236 /// Change anchor position 00237 void setAnchorPos(FXint pos); 00238 00239 /// Return anchor position 00240 FXint getAnchorPos() const { return anchor; } 00241 00242 /// Set the text for this label 00243 void setText(const FXString& text); 00244 00245 /// Get the text for this label 00246 FXString getText() const { return contents; } 00247 00248 /// Set the text font 00249 void setFont(FXFont* fnt); 00250 00251 /// Get the text font 00252 FXFont* getFont() const { return font; } 00253 00254 /// Change text color 00255 void setTextColor(FXColor clr); 00256 00257 /// Return text color 00258 FXColor getTextColor() const { return textColor; } 00259 00260 /// Change selected background color 00261 void setSelBackColor(FXColor clr); 00262 00263 /// Return selected background color 00264 FXColor getSelBackColor() const { return selbackColor; } 00265 00266 /// Change selected text color 00267 void setSelTextColor(FXColor clr); 00268 00269 /// Return selected text color 00270 FXColor getSelTextColor() const { return seltextColor; } 00271 00272 /// Changes the cursor color 00273 void setCursorColor(FXColor clr); 00274 00275 /// Return the cursor color 00276 FXColor getCursorColor() const { return cursorColor; } 00277 00278 /// Change width of text field in terms of number of columns * `m' 00279 void setNumColumns(FXint cols); 00280 00281 /// Return number of columns 00282 FXint getNumColumns() const { return columns; } 00283 00284 /// Change text justification mode 00285 void setJustify(FXuint mode); 00286 00287 /// Return text justification mode 00288 FXuint getJustify() const; 00289 00290 /// Change word delimiters 00291 void setDelimiters(const FXchar* delims=textDelimiters){ delimiters=delims; } 00292 00293 /// Return word delimiters 00294 const FXchar* getDelimiters() const { return delimiters; } 00295 00296 /// Set the status line help text for this label 00297 void setHelpText(const FXString& text); 00298 00299 /// Get the status line help text for this label 00300 FXString getHelpText() const { return help; } 00301 00302 /// Set the tool tip message for this text field 00303 void setTipText(const FXString& text); 00304 00305 /// Get the tool tip message for this text field 00306 FXString getTipText() const { return tip; } 00307 00308 /// Change text style 00309 void setTextStyle(FXuint style); 00310 00311 /// Return text style 00312 FXuint getTextStyle() const; 00313 00314 /// Select all text 00315 FXbool selectAll(); 00316 00317 /// Select len characters starting at given position pos 00318 FXbool setSelection(FXint pos,FXint len); 00319 00320 /// Extend the selection from the anchor to the given position 00321 FXbool extendSelection(FXint pos); 00322 00323 /// Unselect the text 00324 FXbool killSelection(); 00325 00326 /// Return TRUE if position pos is selected 00327 FXbool isPosSelected(FXint pos) const; 00328 00329 /// Return TRUE if position is fully visible 00330 FXbool isPosVisible(FXint pos) const; 00331 00332 /// Scroll text to make the given position visible 00333 void makePositionVisible(FXint pos); 00334 00335 /// Save text field to a stream 00336 virtual void save(FXStream& store) const; 00337 00338 /// Load text field from a stream 00339 virtual void load(FXStream& store); 00340 00341 /// Destructor 00342 virtual ~FXTextField(); 00343 }; 00344 00345 } 00346 00347 #endif
Copyright © 1997-2004 Jeroen van der Zijp |