1 | /* edit.cc |
1 | /* edit.cc |
2 | * This file is part of NDK++ library |
2 | * This file is part of NDK++ library |
3 | * Copyright (c) 2003,2004 by Stanislav Ievlev |
3 | * Copyright (c) 2003,2004 by Stanislav Ievlev |
4 | * |
4 | * |
5 | * This file is covered by the GNU Library General Public License, |
5 | * This file is covered by the GNU Library General Public License, |
6 | * which should be included with libndk++ as the file COPYING. |
6 | * which should be included with libndk as the file COPYING. |
7 | */ |
7 | */ |
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; |
… | |
… | |
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 | { |
… | |
… | |
77 | break; |
76 | break; |
78 | default: |
77 | default: |
79 | break; |
78 | break; |
80 | } |
79 | } |
81 | |
80 | |
|
|
81 | if (begin_ > out.length ()) |
|
|
82 | begin_ = out.length (); |
|
|
83 | |
82 | label::draw (out, begin_); /* and draw */ |
84 | label::draw (out, begin_); /* and draw */ |
83 | set_cursor (); /* and finally update cursor position */ |
85 | set_cursor (); /* and finally update cursor position */ |
84 | ncurses::pen (*this).commit (); /* commit changes to the screen */ |
86 | pen (*this).commit (); /* commit changes to the screen */ |
85 | } |
87 | } |
86 | |
88 | |
87 | ndk::event::result |
89 | ndk::event::result |
88 | edit::at_system (event const &ev) |
90 | edit::at_system (event const &ev) |
89 | { |
91 | { |
… | |
… | |
91 | |
93 | |
92 | if (!ev.sender_) |
94 | if (!ev.sender_) |
93 | { |
95 | { |
94 | if (engine::enter_focus == ev.type_) |
96 | if (engine::enter_focus == ev.type_) |
95 | { |
97 | { |
96 | app ().cursor_on (); |
98 | app->cursor_on (); |
97 | set_cursor (); /* only set cursor position, don't need full redraw */ |
99 | set_cursor (); /* only set cursor position, don't need full redraw */ |
98 | res = event::accepted; |
100 | res = event::accepted; |
99 | } |
101 | } |
100 | else if (engine::leave_focus == ev.type_) |
102 | else if (engine::leave_focus == ev.type_) |
101 | { |
103 | { |
102 | app ().cursor_off (); |
104 | app->cursor_off (); |
103 | res = event::accepted; |
105 | res = event::accepted; |
104 | } |
106 | } |
105 | } |
107 | } |
106 | return res; |
108 | return res; |
107 | } |
109 | } |
… | |
… | |
214 | |
216 | |
215 | void |
217 | void |
216 | edit::set_cursor () |
218 | edit::set_cursor () |
217 | { |
219 | { |
218 | /* always move to zero position in no_echo mode */ |
220 | /* always move to zero position in no_echo mode */ |
219 | return_unless (ncurses::pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0)); |
221 | return_unless (pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0)); |
220 | ncurses::pen (*this).commit (); |
222 | pen (*this).commit (); |
221 | } |
223 | } |
222 | |
224 | |
223 | void |
225 | void |
224 | edit::insert (int pos, char sym) |
226 | edit::insert (int pos, char sym) |
225 | { |
227 | { |