]> git.tdb.fi Git - libs/gltk.git/blob - source/entry.h
Implement autosize() method for most widgets
[libs/gltk.git] / source / entry.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GLTK_ENTRY_H_
9 #define MSP_GLTK_ENTRY_H_
10
11 #include "container.h"
12 #include "text.h"
13 #include "widget.h"
14
15 namespace Msp {
16 namespace GLtk {
17
18 class VSlider;
19
20 /**
21 Text entry field.
22
23 Special parts:
24
25   text    The current text of the widget.  Graphics are ignored.
26   cursor  Indicates the current input position.  Fill_x is ignored.
27   slider  A vertical slider for multiline entries.
28 */
29 class Entry: virtual public Widget, private Container
30 {
31 public:
32         class Loader: public Widget::Loader
33         {
34         public:
35                 Loader(Entry &);
36         };
37
38         sigc::signal<void> signal_enter;
39
40 private:
41         Text text;
42         bool multiline;
43         unsigned edit_pos;
44         unsigned first_row;
45         unsigned visible_rows;
46         const Part *text_part;
47         VSlider *slider;
48
49 public:
50         Entry(const std::string & = std::string());
51
52         virtual const char *get_class() const { return "entry"; }
53
54         virtual void autosize();
55
56         void set_text(const std::string &);
57         const std::string &get_text() const { return text.get(); }
58         void set_multiline(bool);
59         bool is_multiline() const { return multiline; }
60
61 private:
62         virtual void render_special(const Part &) const;
63
64 public:
65         virtual void key_press(unsigned, unsigned, wchar_t);
66 private:
67         virtual void on_geometry_change();
68         virtual void on_style_change();
69
70         void reposition_slider();
71         void check_view_range();
72         void slider_value_changed(double);
73 };
74
75 } // namespace GLtk
76 } // namespace Msp
77
78 #endif
79