textedit.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 */
29 
30 
31 #pragma once
32 
33 #include "../api_gui.h"
34 #include "../gui_component.h"
35 
36 namespace clan
37 {
40 
41 class TextEdit_Impl;
42 
44 class CL_API_GUI TextEdit : public GUIComponent
45 {
48 
49 public:
53  TextEdit(GUIComponent *parent);
54 
55  virtual ~TextEdit();
56 
60 
61 public:
63 
67  static TextEdit *get_named_item(GUIComponent *reference_component, const std::string &id);
68 
72  bool is_read_only() const;
73 
77  bool is_lowercase() const;
78 
82  bool is_uppercase() const;
83 
87  int get_max_length() const;
88 
92  std::string get_text() const;
93 
97  int get_line_count() const;
98 
102  std::string get_line_text(int line) const;
103 
107  std::string get_selection() const;
108 
112  int get_selection_start() const;
113 
117  int get_selection_length() const;
118 
122  int get_cursor_pos() const;
123 
127  int get_cursor_line_number() const;
128 
130  int get_total_height();
131 
135 
136 public:
137  void set_select_all_on_focus_gain(bool enable);
138 
140  void select_all();
141 
145  void set_read_only(bool enable = true);
146 
150  void set_lowercase(bool enable = true);
151 
155  void set_uppercase(bool enable = true);
156 
160  void set_max_length(int length);
161 
165  void set_text(const std::string &text);
166 
170  void add_text(const std::string &text);
171 
176  void set_selection(int pos, int length);
177 
179  void clear_selection();
180 
184  void set_cursor_pos(int pos);
185 
187  void delete_selected_text();
188 
190  void set_input_mask(const std::string &mask);
191 
193  void set_cursor_drawing_enabled(bool enable);
194 
198 
199 public:
200  Callback_v1<InputEvent &> &func_before_edit_changed();
201 
202  Callback_v1<InputEvent &> &func_after_edit_changed();
203 
207  Callback_v0 &func_selection_changed();
208 
210  Callback_v0 &func_focus_gained();
211 
213  Callback_v0 &func_focus_lost();
214 
218  Callback_v0 &func_enter_pressed();
219 
223 
224 private:
225  std::shared_ptr<TextEdit_Impl> impl;
227 };
228 
229 }
230 
GUI base component class.
Definition: gui_component.h:80
GUIComponent * get_named_item(const std::string &id)
Find child component with the specified component ID name.
Callback_v1.
Definition: callback_v1.h:156
Text edit component.
Definition: textedit.h:44
Callback_v0.
Definition: callback_v0.h:152