ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/include/ndk/edit.hh
Revision: 1.1
Committed: Sun Oct 24 20:31:42 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Log Message:
use EV and plain sockets instead of asio

File Contents

# User Rev Content
1 sf-pippijn 1.1 /* edit.hh
2     * This file is part of ndk library
3     * Copyright (c) 2003,2004 by Stanislav Ievlev
4     *
5     * This file is covered by the GNU Library General Public License,
6     * which should be included with libndk as the file COPYING.
7     */
8     #ifndef NDK_EDIT_HH__
9     #define NDK_EDIT_HH__
10    
11     #include <vector>
12    
13     #include <ndk/button.hh>
14    
15     namespace ndk
16     {
17     /**
18     * Line Edit widget.
19     * This widget don't made auto resize at draw() as Label or Button,
20     * so you need to set widget size itself using resize()
21     * This widgets inherits from button, 'cause we can insert this widget to the list,
22     * and we need activation/deactivation feature to show/hide cursor
23     */
24     class edit
25     : public button
26     {
27     public:
28     enum echo_mode
29     {
30     /**< possible draw modes of the edit*/
31     normal, /**< display characters as they are entered */
32     password, /**< display asterisks instead of the characters actually entered */
33     no_echo /**< do not display anything */
34     };
35    
36     edit (const std::string &str = "", panel *parent = 0, bool accept = true);
37     void resize (int size); /**< * helper to resize widget only in one direction */
38    
39     /* some edit properties */
40     void set_text (const std::string &str); /**<set text, draw and reset current cursor position */
41     void set_mode (echo_mode mode); /**< set edit's text display mode */
42    
43     std::function<void (std::string)> &on_commit () { return on_commit_; }
44    
45     protected:
46     event::result at_keyboard (const keyboard &ev);
47     virtual void change_color ();
48    
49     private:
50     virtual void draw (); /**< special draw method for edit */
51    
52     std::function<void (std::string)> on_commit_;
53    
54     event::result at_system (const event &ev);
55    
56     bool scroll_right (); /**< scroll viewport to the right */
57     bool scroll_left (); /**< scroll viewport to the left */
58     bool recalibrate (); /**< recalibrate begin_ position */
59     void set_cursor (); /**< move cursor to current position */
60     void insert (int pos, char sym); /**< insert/replace symbol at position */
61     void erase (int pos); /**< erase/replace symbol at position */
62    
63     int current_; /**< current cursor position under string */
64     int begin_; /**< beginning of the string */
65     echo_mode mode_;
66     };
67    
68     class input
69     : public panel
70     {
71     /**< This is a line edit with label */
72     public:
73     input (const std::string &label, panel *parent = 0);
74     void resize (int size);
75    
76     void set_text (const std::string &str);
77     void set_label (const std::string &str);
78     void set_mode (edit::echo_mode mode);
79    
80     const std::string &text () const;
81    
82     std::function<void (std::string)> &on_commit () { return edit_.on_commit (); }
83    
84     private:
85     virtual void draw ();
86    
87     event::result at_system (const event &ev);
88    
89     label label_;
90     edit edit_;
91     };
92     }
93     #endif