lineedit.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 #include "../../Display/Window/input_event.h"
36 #include "../../Core/Signals/callback_v0.h"
37 #include "../../Core/Signals/callback_v1.h"
38 #include "../../Core/Signals/callback_1.h"
39 
40 namespace clan
41 {
44 
45 class LineEdit_Impl;
46 
48 class CL_API_GUI LineEdit : public GUIComponent
49 {
52 
53 public:
54 
58  LineEdit(GUIComponent *parent);
59 
60  virtual ~LineEdit();
61 
65 
66 public:
67  enum Alignment
68  {
71  align_right
72  };
73 
75 
79  static LineEdit *get_named_item(GUIComponent *reference_component, const std::string &id);
80 
84  Alignment get_alignment() const;
85 
89  bool is_read_only() const;
90 
94  bool is_lowercase() const;
95 
99  bool is_uppercase() const;
100 
104  bool is_password_mode() const;
105 
109  int get_max_length() const;
110 
114  std::string get_text() const;
115 
117  int get_text_int() const;
118 
120  float get_text_float() const;
121 
125  std::string get_selection() const;
126 
130  int get_selection_start() const;
131 
135  int get_selection_length() const;
136 
140  int get_cursor_pos() const;
141 
143  Size get_text_size();
144 
150  Size get_text_size(const std::string &str);
151 
155  float get_preferred_content_width();
156 
160  float get_preferred_content_height(float width);
161 
165 
166 public:
167  void set_select_all_on_focus_gain(bool enable);
168 
170  void select_all();
171 
175  void set_alignment(Alignment alignment);
176 
180  void set_read_only(bool enable = true);
181 
185  void set_lowercase(bool enable = true);
186 
190  void set_uppercase(bool enable = true);
191 
195  void set_password_mode(bool enable = true);
196 
201  void set_numeric_mode(bool enable = true, bool decimals = false);
202 
206  void set_max_length(int length);
207 
211  void set_text(const std::string &text);
212 
216  void set_text(int number);
217 
222  void set_text(float number, int num_decimal_places = 6);
223 
228  void set_selection(int pos, int length);
229 
231  void clear_selection();
232 
236  void set_cursor_pos(int pos);
237 
239  void delete_selected_text();
240 
242  void resize_to_fit(int max_width);
243 
245  void set_input_mask(const std::string &mask);
246 
250  void set_decimal_character(const std::string &decimal_char);
251 
253  void set_cursor_drawing_enabled(bool enable);
254 
258 
259 public:
260  Callback_v1<InputEvent &> &func_before_edit_changed();
261 
262  Callback_v1<InputEvent &> &func_after_edit_changed();
263 
267  Callback_v0 &func_selection_changed();
268 
270  Callback_v0 &func_focus_gained();
271 
273  Callback_v0 &func_focus_lost();
274 
278  Callback_v0 &func_enter_pressed();
279 
283 
284 private:
285  std::shared_ptr<LineEdit_Impl> impl;
287 };
288 
289 }
290 
Definition: lineedit.h:70
GUI base component class.
Definition: gui_component.h:80
Alignment
Definition: lineedit.h:67
GUIComponent * get_named_item(const std::string &id)
Find child component with the specified component ID name.
Callback_v1.
Definition: callback_v1.h:156
Single line edit component.
Definition: lineedit.h:48
2D (width,height) size structure - Integer
Definition: size.h:157
Definition: lineedit.h:69
Callback_v0.
Definition: callback_v0.h:152