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