]> git.tdb.fi Git - libs/gltk.git/blob - source/entry.h
Add a signal for selection changes in 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         sigc::signal<void, unsigned> signal_edit_position_changed;
35         sigc::signal<void, unsigned> signal_scroll_position_changed;
36         sigc::signal<void, unsigned, unsigned> signal_selection_changed;
37         sigc::signal<void, const std::string &> signal_text_changed;
38
39         // Deprecated
40         sigc::signal<void> signal_enter;
41
42 private:
43         Text text;
44         bool multiline;
45         unsigned edit_width;
46         unsigned edit_height;
47         unsigned edit_pos;
48         unsigned first_row;
49         unsigned visible_rows;
50         const Part *text_part;
51         VSlider *slider;
52         bool got_key_press;
53         bool cursor_blink;
54         bool selection_active;
55         unsigned selection_pos;
56
57 public:
58         Entry(const std::string & = std::string());
59
60         virtual const char *get_class() const { return "entry"; }
61
62 private:
63         virtual void autosize_special(const Part &, Geometry &) const;
64
65 public:
66         void set_text(const std::string &);
67         void insert(unsigned, const std::string &);
68         void erase(unsigned, unsigned);
69         const std::string &get_text() const { return text.get(); }
70
71         void set_edit_position(unsigned p) { set_edit_position(p, false); }
72         unsigned get_edit_position() const { return edit_pos; }
73         unsigned get_scroll_position() const { return first_row; }
74         unsigned get_visible_rows() const { return visible_rows; }
75         bool get_selection(unsigned &, unsigned &) const;
76         void translate_position(unsigned, unsigned &, unsigned &) const;
77         unsigned translate_position(unsigned, unsigned) const;
78
79         /** Sets the minimum size of the editing area, in characters and rows.  This
80         only affects autosizing. */
81         void set_edit_size(unsigned w, unsigned h);
82
83         void set_multiline(bool);
84         bool is_multiline() const { return multiline; }
85
86 private:
87         virtual void rebuild_special(const Part &);
88         virtual void render_special(const Part &, GL::Renderer &) const;
89
90 public:
91         virtual void touch_press(int, int, unsigned);
92         virtual bool key_press(unsigned, unsigned);
93         virtual bool character(wchar_t);
94         virtual void focus_in();
95         virtual void focus_out();
96         virtual bool navigate(Navigation);
97         virtual void animate(const Time::TimeDelta &);
98 private:
99         virtual void on_size_change();
100         virtual void on_style_change();
101
102         void move_edit_position(Navigation, bool);
103         void adjust_edit_position_for_change(unsigned, int);
104         void set_edit_position(unsigned, bool);
105         void erase_selection(bool);
106         void check_cursor_blink();
107         void check_view_range();
108         void slider_value_changed(double);
109 };
110
111 } // namespace GLtk
112 } // namespace Msp
113
114 #endif
115