ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/src/backend/ndk/edit.cpp
(Generate patch)

Comparing deliantra/dclient/src/backend/ndk/edit.cpp (file contents):
Revision 1.2 by sf-pippijn, Mon Oct 18 14:11:48 2010 UTC vs.
Revision 1.7 by sf-pippijn, Fri Jan 21 21:49:37 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines