libt3widget
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules
textfield.h
1 /* Copyright (C) 2011-2013 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_WIDGET_TEXTFIELD_H
15 #define T3_WIDGET_TEXTFIELD_H
16 
17 #include <string>
18 
19 #include <t3widget/widgets/widget.h>
20 #include <t3widget/textline.h>
21 #include <t3widget/contentlist.h>
22 #include <t3widget/widgets/smartlabel.h>
23 #include <t3widget/widgets/listpane.h>
24 
25 namespace t3_widget {
26 
27 class T3_WIDGET_API text_field_t : public widget_t, public center_component_t, public focus_widget_t, public bad_draw_recheck_t
28 {
29  private:
30  class T3_WIDGET_LOCAL drop_down_list_t;
31  struct T3_WIDGET_LOCAL implementation_t {
32  int pos,
33  screen_pos,
34  leftcol,
35  selection_start_pos,
36  selection_end_pos;
38  selection_mode_t selection_mode;
39  bool focus,
40  in_drop_down_list,
46  dont_select_on_focus,
50  edited;
51 
52  cleanup_ptr<text_line_t>::t line;
53  const key_t *filter_keys;
54  size_t filter_keys_size;
55  bool filter_keys_accept;
57  smart_label_t *label;
59  cleanup_ptr<drop_down_list_t>::t drop_down_list;
60 
61  implementation_t(void) : pos(0),
62  screen_pos(0),
63  leftcol(0),
64  focus(false),
65  in_drop_down_list(false),
66  dont_select_on_focus(false),
67  edited(false),
68  line(new text_line_t()),
69  filter_keys(NULL),
70  label(NULL),
71  drop_down_list(NULL)
72  {}
73  };
74  pimpl_ptr<implementation_t>::t impl;
75 
77  void reset_selection(void);
79  void set_selection(key_t key);
81  void delete_selection(bool save_to_copy_buffer);
83  void ensure_cursor_on_screen(void);
84 
86  void set_selection_end(bool update_primary = true);
87 
88  protected:
89  bool has_focus(void) const;
90 
91  public:
92  text_field_t(void);
93  virtual bool process_key(key_t key);
94  virtual bool set_size(optint height, optint width);
95  virtual void update_contents(void);
96  virtual void set_focus(focus_t _focus);
97  virtual void show(void);
98  virtual void hide(void);
100  void set_text(const std::string *text);
102  void set_text(const char *text);
104  void set_text(const char *text, size_t size);
106  void set_autocomplete(string_list_base_t *_completions);
112  void set_key_filter(key_t *keys, size_t nr_of_keys, bool accept);
114  const std::string *get_text(void) const;
120  void set_label(smart_label_t *_label);
121  virtual bool is_hotkey(key_t key);
122 
123  virtual void bad_draw_recheck(void);
124  virtual bool process_mouse_event(mouse_event_t event);
125 
126  T3_WIDGET_SIGNAL(activate, void);
127 };
128 
130 class T3_WIDGET_LOCAL text_field_t::drop_down_list_t : public popup_t {
131  private:
132  text_field_t *field;
134  cleanup_ptr<filtered_list_base_t>::t completions;
135  list_pane_t *list_pane;
136 
137  void update_list_pane(void);
138  void item_activated(void);
139  void selection_changed(void);
140  public:
142  virtual bool process_key(key_t key);
143  virtual void set_position(optint top, optint left);
144  virtual bool set_size(optint height, optint width);
145  virtual void update_contents(void);
146  virtual void set_focus(focus_t focus) ;
147  virtual void show(void);
148  virtual void hide(void);
149  virtual bool process_mouse_event(mouse_event_t key);
150 
152  void update_view(void);
154  void set_autocomplete(string_list_base_t *completions);
156  bool empty(void);
157 };
158 
159 }; // namespace
160 #endif
Base class for widgets that need handle user text and draw differently based on the t3_win_can_draw f...
Definition: interfaces.h:167
The t3_widget namespace is contains all classes, functions and global variables in the libt3widget li...
Definition: autocompleter.cc:18
Definition: listpane.h:22
Definition: smartlabel.h:38
Base class for components which need to center dialogs.
Definition: interfaces.h:109
long key_t
Integer type holding a single key symbol.
Definition: key.h:24
Definition: textline.h:36
Definition: textfield.h:27
Base class for dialogs.
Definition: popup.h:22
Base class for widgets.
Definition: widget.h:24
Base class for widgets that take focus.
Definition: widget.h:76
Abstract base class for string and file lists, but not for filtered lists.
Definition: contentlist.h:46
Class defining values with a separate validity check.
Definition: util.h:29
Drop-down list implementation for text_field_t.
Definition: textfield.h:130
Structure holding the relevant elements of a mouse event.
Definition: mouse.h:23