… | |
… | |
8 | #include <ndk++/application.hh> |
8 | #include <ndk++/application.hh> |
9 | #include <ndk++/edit.hh> |
9 | #include <ndk++/edit.hh> |
10 | #include <ndk++/packer.hh> |
10 | #include <ndk++/packer.hh> |
11 | #include <ndk++/palette.hh> |
11 | #include <ndk++/palette.hh> |
12 | |
12 | |
13 | #include <ncurses/pen.hh> |
13 | #include <ndk++/pen.hh> |
14 | |
14 | |
15 | #include <cctype> |
15 | #include <cctype> |
16 | |
16 | |
17 | |
17 | |
18 | using ndk::edit; |
18 | using ndk::edit; |
19 | |
19 | |
20 | edit::edit (const std::string &str, panel *parent, bool accept) |
20 | edit::edit (std::string const &str, panel *parent, bool accept) |
21 | : button (str, parent, accept) |
21 | : button (str, parent, accept) |
22 | , current_ (0) |
22 | , current_ (0) |
23 | , begin_ (0) |
23 | , begin_ (0) |
24 | , mode_ (normal) |
24 | , mode_ (normal) |
25 | { |
25 | { |
… | |
… | |
32 | { |
32 | { |
33 | button::resize (size, 1); |
33 | button::resize (size, 1); |
34 | } |
34 | } |
35 | |
35 | |
36 | void |
36 | void |
37 | edit::set_text (const std::string &str) |
37 | edit::set_text (std::string const &str) |
38 | { |
38 | { |
39 | label::set_text (str); |
39 | label::set_text (str); |
40 | current_ = text_.length (); |
40 | current_ = text_.length (); |
41 | draw (); |
41 | draw (); |
42 | } |
42 | } |
… | |
… | |
48 | } |
48 | } |
49 | |
49 | |
50 | void |
50 | void |
51 | edit::change_color () |
51 | edit::change_color () |
52 | { |
52 | { |
53 | ncurses::pen (*this).set_color (palette::instance () |
53 | pen (*this).set_color (palette::instance ().find ( |
54 | [ |
|
|
55 | state_ == engine::enter_focus |
54 | state_ == engine::enter_focus |
56 | ? colors::edit_active |
55 | ? colors::edit_active |
57 | : colors::edit_inactive |
56 | : colors::edit_inactive |
58 | ]); |
57 | )->second); |
59 | } |
58 | } |
60 | |
59 | |
61 | void |
60 | void |
62 | edit::draw () |
61 | edit::draw () |
63 | { |
62 | { |
… | |
… | |
79 | break; |
78 | break; |
80 | } |
79 | } |
81 | |
80 | |
82 | label::draw (out, begin_); /* and draw */ |
81 | label::draw (out, begin_); /* and draw */ |
83 | set_cursor (); /* and finally update cursor position */ |
82 | set_cursor (); /* and finally update cursor position */ |
84 | ncurses::pen (*this).commit (); /* commit changes to the screen */ |
83 | pen (*this).commit (); /* commit changes to the screen */ |
85 | } |
84 | } |
86 | |
85 | |
87 | ndk::event::result |
86 | ndk::event::result |
88 | edit::at_system (const event &ev) |
87 | edit::at_system (event const &ev) |
89 | { |
88 | { |
90 | event::result res = event::ignored; |
89 | event::result res = event::ignored; |
91 | |
90 | |
92 | if (!ev.sender_) |
91 | if (!ev.sender_) |
93 | { |
92 | { |
94 | if (engine::enter_focus == ev.type_) |
93 | if (engine::enter_focus == ev.type_) |
95 | { |
94 | { |
96 | app ().cursor_on (); |
95 | app->cursor_on (); |
97 | set_cursor (); /* only set cursor position, don't need full redraw */ |
96 | set_cursor (); /* only set cursor position, don't need full redraw */ |
98 | res = event::accepted; |
97 | res = event::accepted; |
99 | } |
98 | } |
100 | else if (engine::leave_focus == ev.type_) |
99 | else if (engine::leave_focus == ev.type_) |
101 | { |
100 | { |
102 | app ().cursor_off (); |
101 | app->cursor_off (); |
103 | res = event::accepted; |
102 | res = event::accepted; |
104 | } |
103 | } |
105 | } |
104 | } |
106 | return res; |
105 | return res; |
107 | } |
106 | } |
108 | |
107 | |
109 | ndk::event::result |
108 | ndk::event::result |
110 | edit::at_keyboard (const keyboard &ev) |
109 | edit::at_keyboard (keyboard const &ev) |
111 | { |
110 | { |
112 | event::result res = event::ignored; |
111 | event::result res = event::ignored; |
113 | unsigned int pos = current_; |
112 | unsigned int pos = current_; |
114 | |
113 | |
115 | switch (ev.code ()) |
114 | switch (ev.code ()) |
… | |
… | |
214 | |
213 | |
215 | void |
214 | void |
216 | edit::set_cursor () |
215 | edit::set_cursor () |
217 | { |
216 | { |
218 | /* always move to zero position in no_echo mode */ |
217 | /* always move to zero position in no_echo mode */ |
219 | ncurses::pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0); |
218 | return_unless (pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0)); |
220 | ncurses::pen (*this).commit (); |
219 | pen (*this).commit (); |
221 | } |
220 | } |
222 | |
221 | |
223 | void |
222 | void |
224 | edit::insert (int pos, char sym) |
223 | edit::insert (int pos, char sym) |
225 | { |
224 | { |