]> git.tdb.fi Git - libs/gltk.git/blob - source/entry.h
1594c68d8e7bb883eebdb04362a6b4db552fa26f
[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         sigc::signal<void> signal_enter;
26
27 private:
28         Text text;
29         bool multiline;
30         unsigned edit_width;
31         unsigned edit_height;
32         unsigned edit_pos;
33         unsigned first_row;
34         unsigned visible_rows;
35         const Part *text_part;
36         VSlider *slider;
37         bool got_key_press;
38
39 public:
40         Entry(const std::string & = std::string());
41
42         virtual const char *get_class() const { return "entry"; }
43
44 private:
45         virtual void autosize_special(const Part &, Geometry &);
46
47 public:
48         void set_text(const std::string &);
49         const std::string &get_text() const { return text.get(); }
50
51         /** Sets the minimum size of the editing area, in characters and rows.  This
52         only affects autosizing. */
53         void set_edit_size(unsigned w, unsigned h);
54
55         void set_multiline(bool);
56         bool is_multiline() const { return multiline; }
57
58 private:
59         virtual void rebuild_special(const Part &);
60         virtual void render_special(const Part &, GL::Renderer &) const;
61
62 public:
63         virtual void key_press(unsigned, unsigned);
64         virtual void character(wchar_t);
65         virtual void focus_out();
66 private:
67         virtual void on_geometry_change();
68         virtual void on_style_change();
69
70         void set_edit_position(unsigned);
71         void reposition_slider();
72         void check_view_range();
73         void slider_value_changed(double);
74 };
75
76 } // namespace GLtk
77 } // namespace Msp
78
79 #endif
80