comparison ext/guichan-0.8.1/include/guichan/widgets/textbox.hpp @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /* _______ __ __ __ ______ __ __ _______ __ __
2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8 *
9 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
10 *
11 *
12 * Per Larsson a.k.a finalman
13 * Olof Naessén a.k.a jansem/yakslem
14 *
15 * Visit: http://guichan.sourceforge.net
16 *
17 * License: (BSD)
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 * 3. Neither the name of Guichan nor the names of its contributors may
28 * be used to endorse or promote products derived from this software
29 * without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
37 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 #ifndef GCN_TEXTBOX_HPP
45 #define GCN_TEXTBOX_HPP
46
47 #include <ctime>
48 #include <string>
49 #include <vector>
50
51 #include "guichan/keylistener.hpp"
52 #include "guichan/mouselistener.hpp"
53 #include "guichan/platform.hpp"
54 #include "guichan/widget.hpp"
55
56 namespace gcn
57 {
58 /**
59 * An implementation of a text box where a user can enter text that contains of many lines.
60 */
61 class GCN_CORE_DECLSPEC TextBox:
62 public Widget,
63 public MouseListener,
64 public KeyListener
65 {
66 public:
67 /**
68 * Constructor.
69 */
70 TextBox();
71
72 /**
73 * Constructor.
74 *
75 * @param text The default text of the text box.
76 */
77 TextBox(const std::string& text);
78
79 /**
80 * Sets the text of the text box.
81 *
82 * @param text The text of the text box.
83 * @see getText
84 */
85 void setText(const std::string& text);
86
87 /**
88 * Gets the text of the text box.
89 *
90 * @return The text of the text box.
91 * @see setText
92 */
93 std::string getText() const;
94
95 /**
96 * Gets a certain row from the text.
97 *
98 * @param row The number of the row to get from the text.
99 * @return A row from the text of the text box.
100 * @see setTextRow
101 */
102 const std::string& getTextRow(int row) const;
103
104 /**
105 * Sets the text of a certain row of the text.
106 *
107 * @param row The number of the row to set in the text.
108 * @param text The text to set in the given row number.
109 * @see getTextRow
110 */
111 void setTextRow(int row, const std::string& text);
112
113 /**
114 * Gets the number of rows in the text.
115 *
116 * @return The number of rows in the text.
117 */
118 unsigned int getNumberOfRows() const;
119
120 /**
121 * Gets the caret position in the text.
122 *
123 * @return The caret position in the text.
124 * @see setCaretPosition
125 */
126 unsigned int getCaretPosition() const;
127
128 /**
129 * Sets the position of the caret in the text.
130 *
131 * @param position the positon of the caret.
132 * @see getCaretPosition
133 */
134 void setCaretPosition(unsigned int position);
135
136 /**
137 * Gets the row number where the caret is currently located.
138 *
139 * @return The row number where the caret is currently located.
140 * @see setCaretRow
141 */
142 unsigned int getCaretRow() const;
143
144 /**
145 * Sets the row where the caret should be currently located.
146 *
147 * @param The row where the caret should be currently located.
148 * @see getCaretRow
149 */
150 void setCaretRow(int row);
151
152 /**
153 * Gets the column where the caret is currently located.
154 *
155 * @return The column where the caret is currently located.
156 * @see setCaretColumn
157 */
158 unsigned int getCaretColumn() const;
159
160 /**
161 * Sets the column where the caret should be currently located.
162 *
163 * @param The column where the caret should be currently located.
164 * @see getCaretColumn
165 */
166 void setCaretColumn(int column);
167
168 /**
169 * Sets the row and the column where the caret should be curretly
170 * located.
171 *
172 * @param row The row where the caret should be currently located.
173 * @param column The column where the caret should be currently located.
174 * @see getCaretRow, getCaretColumn
175 */
176 void setCaretRowColumn(int row, int column);
177
178 /**
179 * Scrolls the text to the caret if the text box is in a scroll area.
180 *
181 * @see ScrollArea
182 */
183 virtual void scrollToCaret();
184
185 /**
186 * Checks if the text box is editable.
187 *
188 * @return True it the text box is editable, false otherwise.
189 * @see setEditable
190 */
191 bool isEditable() const;
192
193 /**
194 * Sets the text box to be editable or not.
195 *
196 * @param editable True if the text box should be editable, false otherwise.
197 */
198 void setEditable(bool editable);
199
200 /**
201 * Adds a row of text to the end of the text.
202 *
203 * @param row The row to add.
204 */
205 virtual void addRow(const std::string row);
206
207 /**
208 * Checks if the text box is opaque. An opaque text box will draw
209 * it's background and it's text. A non opaque text box only draw it's
210 * text making it transparent.
211 *
212 * @return True if the text box is opaque, false otherwise.
213 * @see setOpaque
214 */
215 bool isOpaque();
216
217 /**
218 * Sets the text box to be opaque or not. An opaque text box will draw
219 * it's background and it's text. A non opaque text box only draw it's
220 * text making it transparent.
221 *
222 * @param opaque True if the text box should be opaque, false otherwise.
223 * @see isOpaque
224 */
225 void setOpaque(bool opaque);
226
227
228 // Inherited from Widget
229
230 virtual void draw(Graphics* graphics);
231
232 virtual void fontChanged();
233
234
235 // Inherited from KeyListener
236
237 virtual void keyPressed(KeyEvent& keyEvent);
238
239
240 // Inherited from MouseListener
241
242 virtual void mousePressed(MouseEvent& mouseEvent);
243
244 virtual void mouseDragged(MouseEvent& mouseEvent);
245
246 protected:
247 /**
248 * Draws the caret. Overloaded this method if you want to
249 * change the style of the caret.
250 *
251 * @param graphics a Graphics object to draw with.
252 * @param x the x position.
253 * @param y the y position.
254 */
255 virtual void drawCaret(Graphics* graphics, int x, int y);
256
257 /**
258 * Adjusts the text box's size to fit the text.
259 */
260 virtual void adjustSize();
261
262 /**
263 * Holds all the rows of the text.
264 */
265 std::vector<std::string> mTextRows;
266
267 /**
268 * Holds the current column of the caret.
269 */
270 int mCaretColumn;
271
272 /**
273 * Holds the current row of the caret.
274 */
275 int mCaretRow;
276
277 /**
278 * True if the text box is editable, false otherwise.
279 */
280 bool mEditable;
281
282 /**
283 * True if the text box is editable, false otherwise.
284 */
285 bool mOpaque;
286 };
287 }
288
289 #endif // end GCN_TEXTBOX_HPP