]> git.tdb.fi Git - libs/gltk.git/blob - source/entry.h
Add some editing functions to Entry
[libs/gltk.git] / source / entry.h
1 #ifndef MSP_GLTK_ENTRY_H_
2 #define MSP_GLTK_ENTRY_H_
3
4 #include "container.h"
5 #include "text.h"
6 #include "widget.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 class VSlider;
12
13 /**
14 Text entry field.
15
16 Special parts:
17
18   text    The current text of the widget.  Graphics are ignored.
19   cursor  Indicates the current input position.  Fill_x is ignored.
20   slider  A vertical slider for multiline entries.
21 */
22 class Entry: virtual public Widget, private Container
23 {
24 public:
25         class Loader: public DataFile::DerivedObjectLoader<Entry, Widget::Loader>
26         {
27         public:
28                 Loader(Entry &);
29
30         private:
31                 void multiline(bool);
32         };
33
34         // Deprecated
35         sigc::signal<void> signal_enter;
36
37 private:
38         Text text;
39         bool multiline;
40         unsigned edit_width;
41         unsigned edit_height;
42         unsigned edit_pos;
43         unsigned first_row;
44         unsigned visible_rows;
45         const Part *text_part;
46         VSlider *slider;
47         bool got_key_press;
48         bool cursor_blink;
49         bool selection_active;
50         unsigned selection_pos;
51
52 public:
53         Entry(const std::string & = std::string());
54
55         virtual const char *get_class() const { return "entry"; }
56
57 private:
58         virtual void autosize_special(const Part &, Geometry &) const;
59
60 public:
61         void set_text(const std::string &);
62         void insert(unsigned, const std::string &);
63         void erase(unsigned, unsigned);
64         const std::string &get_text() const { return text.get(); }
65
66         void set_edit_position(unsigned);
67         unsigned get_edit_position() const { return edit_pos; }
68         bool get_selection(unsigned &, unsigned &) const;
69
70         /** Sets the minimum size of the editing area, in characters and rows.  This
71         only affects autosizing. */
72         void set_edit_size(unsigned w, unsigned h);
73
74         void set_multiline(bool);
75         bool is_multiline() const { return multiline; }
76
77 private:
78         virtual void rebuild_special(const Part &);
79         virtual void render_special(const Part &, GL::Renderer &) const;
80
81 public:
82         virtual void touch_press(int, int, unsigned);
83         virtual bool key_press(unsigned, unsigned);
84         virtual bool character(wchar_t);
85         virtual void focus_in();
86         virtual void focus_out();
87         virtual bool navigate(Navigation);
88         virtual void animate(const Time::TimeDelta &);
89 private:
90         virtual void on_geometry_change();
91         virtual void on_style_change();
92
93         void move_edit_position(Navigation, bool);
94         void set_edit_position(unsigned, bool);
95         void erase_selection();
96         void check_cursor_blink();
97         void check_view_range();
98         void slider_value_changed(double);
99 };
100
101 } // namespace GLtk
102 } // namespace Msp
103
104 #endif
105