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.1 by sf-pippijn, Sun Oct 17 08:15:08 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/pen.hh> 13#include <ndk/pen.hh>
14 14
15#include <cctype> 15#include <cctype>
16 16
17 17
18using ndk::edit; 18using ndk::edit;
19 19
20edit::edit (const std::string &str, panel *parent, bool accept) 20edit::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
36void 36void
37edit::set_text (const std::string &str) 37edit::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
50void 50void
51edit::change_color () 51edit::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
61void 60void
62edit::draw () 61edit::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
87ndk::event::result 89ndk::event::result
88edit::at_system (const event &ev) 90edit::at_system (event const &ev)
89{ 91{
90 event::result res = event::ignored; 92 event::result res = event::ignored;
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}
108 110
109ndk::event::result 111ndk::event::result
110edit::at_keyboard (const keyboard &ev) 112edit::at_keyboard (keyboard const &ev)
111{ 113{
112 event::result res = event::ignored; 114 event::result res = event::ignored;
113 unsigned int pos = current_; 115 unsigned int pos = current_;
114 116
115 switch (ev.code ()) 117 switch (ev.code ())
214 216
215void 217void
216edit::set_cursor () 218edit::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 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
223void 225void
224edit::insert (int pos, char sym) 226edit::insert (int pos, char sym)
225{ 227{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines