00001 /* 00002 ClanGUI, copyrights by various people. Have a look in the CREDITS file. 00003 00004 This sourcecode is distributed using the Library GNU Public Licence, 00005 version 2 or (at your option) any later version. Please read LICENSE 00006 for details. 00007 */ 00008 00010 00011 #ifndef header_inputbox 00012 #define header_inputbox 00013 00014 #include "component.h" 00015 00016 class CL_InputBox : public CL_Component 00017 //: Inputbox component 00018 { 00020 public: 00021 CL_InputBox( 00022 const CL_ComponentOptions &options, 00023 CL_Component *parent, 00024 CL_StyleManager *style = NULL); 00025 00026 CL_InputBox( 00027 const CL_Rect &pos, 00028 const std::string &text, 00029 CL_Component *parent, 00030 CL_StyleManager *style = NULL); 00031 00032 virtual ~CL_InputBox(); 00033 00035 public: 00036 const std::string &get_text() const; 00037 //: Returns the inputfield text. 00038 00039 int get_length() const; 00040 //: Returns the length of the inputfield text. 00041 00042 const std::string &get_marked_text() const; 00043 //: Returns the marked text from the inputfield. 00044 00045 bool has_marked_text() const; 00046 //: Returns true if part of the text has been marked by the user. 00047 00048 int get_selection_start() const; 00049 //: Returns the position where the selection starts. 00050 00051 int get_selection_length() const; 00052 //: Returns the length of current selection. 00053 00054 int get_max_length() const; 00055 //: Returns the maximum permitted length of the text. 00056 00057 bool in_password_mode() const; 00058 //: Returns true if password mode is enabled, false othewise. 00059 00060 bool is_read_only() const; 00061 //: Returns whether the inputfield is read-only. 00062 00063 int get_cursor_position() const; 00064 //: Returns the current cursor position. 00065 00066 bool is_edited() const; 00067 //: Returns true if the contents has been edited. 00068 00070 public: 00071 void set_text(const std::string &text); 00072 //: Sets the line edit text to text, clears the selection and moves the cursor to the end of the line. 00073 // If necessary the text is truncated to get_max_length(). 00074 00075 void set_max_length(int length); 00076 //: Set the maximum length of the text in the editor. 00077 00078 void set_password_mode(bool enable = true); 00079 //: If enable is true, display asterisks instead of the characters actually entered. 00080 00081 void set_read_only(bool enable = true); 00082 //: Enables or disables read-only mode. 00083 00084 void select_all(); 00085 //: Selects all text, and moves the cursor to the end. 00086 00087 void deselect(); 00088 //: Deselects all text (i.e. removes marking) and leaves the cursor at the current position. 00089 00090 void set_selection(int start, int length); 00091 //: Sets the marked area at start and be length characters long. 00092 00093 void set_cursor_position(int pos); 00094 //: Sets the cursor position to pos. 00095 00096 void clear(); 00097 //: Syntactic sugar for set_text(""). 00098 00099 void backspace(); 00100 //: Deletes the character to the left of the text cursor and moves the cursor one position to the left. 00101 // If a text has been marked, the cursor will be put at the beginning of the marked text and the marked text will be removed. 00102 00103 void del(); 00104 //: Deletes the character on the right side of the text cursor. 00105 // If a text has been marked, the cursor will be put at the beginning of the marked text and the marked text will be removed. 00106 00107 void cut(); 00108 //: Cut the selected text if any. 00109 00110 void move_cursor(int delta, bool mark = false); 00111 //: Moves the cursor position. 00112 // If delta is positive, the cursor is moved forward. 00113 // If delta is negative, the cursor is moved backward. 00114 // If mark is true, the text is marked. 00115 00116 void move_cursor_word(int delta, bool mark = false); 00117 //: Moves the cursor by word. 00118 // If delta is positive, the cursor is moved forward. 00119 // If delta is negative, the cursor is moved backward. 00120 // If mark is true, the text is marked. 00121 00122 void home(bool mark = false); 00123 //: Moves the text cursor to the left end of the line. 00124 // If mark is true, text will be marked towards the first position 00125 // If mark is false, any marked text will be unmarked if the cursor is moved. 00126 00127 void end(bool mark = false); 00128 //: Moves the text cursor to the right end of the line. 00129 // If mark is true, text will be marked towards the last position 00130 // If mark is false, any marked text will be unmarked if the cursor is moved. 00131 00132 void set_edited(bool on = true); 00133 //: Sets the edited flag to on. 00134 // The edited flag is changed to true whenever the user changes its contents. 00135 00137 public: 00138 CL_Signal_v1<const std::string &> &sig_changed(); 00139 //: This signal is emitted whenever text is changed in the inputfield. 00141 00142 CL_Signal_v1<const std::string &> &sig_return_pressed(); 00143 //: This signal is emitted when enter is pressed in the inputfield. 00145 00147 private: 00148 CL_InputBox(const CL_InputBox ©) : CL_Component(NULL, NULL) { return; } // disallow copy construction. 00149 class CL_InputBox_Generic *impl; 00150 }; 00151 00152 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001