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.6 by sf-pippijn, Sun Oct 24 20:31:50 2010 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{
80 break; 78 break;
81 } 79 }
82 80
83 label::draw (out, begin_); /* and draw */ 81 label::draw (out, begin_); /* and draw */
84 set_cursor (); /* and finally update cursor position */ 82 set_cursor (); /* and finally update cursor position */
85 ncurses::pen (*this).commit (); /* commit changes to the screen */ 83 pen (*this).commit (); /* commit changes to the screen */
86} 84}
87 85
88ndk::event::result 86ndk::event::result
89edit::at_system (const event &ev) 87edit::at_system (event const &ev)
90{ 88{
91 event::result res = event::ignored; 89 event::result res = event::ignored;
92 90
93 if (!ev.sender_) 91 if (!ev.sender_)
94 { 92 {
95 if (engine::enter_focus == ev.type_) 93 if (engine::enter_focus == ev.type_)
96 { 94 {
97 app ().cursor_on (); 95 app->cursor_on ();
98 set_cursor (); /* only set cursor position, don't need full redraw */ 96 set_cursor (); /* only set cursor position, don't need full redraw */
99 res = event::accepted; 97 res = event::accepted;
100 } 98 }
101 else if (engine::leave_focus == ev.type_) 99 else if (engine::leave_focus == ev.type_)
102 { 100 {
103 app ().cursor_off (); 101 app->cursor_off ();
104 res = event::accepted; 102 res = event::accepted;
105 } 103 }
106 } 104 }
107 return res; 105 return res;
108} 106}
109 107
110ndk::event::result 108ndk::event::result
111edit::at_keyboard (const keyboard &ev) 109edit::at_keyboard (keyboard const &ev)
112{ 110{
113 event::result res = event::ignored; 111 event::result res = event::ignored;
114 unsigned int pos = current_; 112 unsigned int pos = current_;
115 113
116 switch (ev.code ()) 114 switch (ev.code ())
215 213
216void 214void
217edit::set_cursor () 215edit::set_cursor ()
218{ 216{
219 /* always move to zero position in no_echo mode */ 217 /* always move to zero position in no_echo mode */
220 return_unless (ncurses::pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0)); 218 return_unless (pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0));
221 ncurses::pen (*this).commit (); 219 pen (*this).commit ();
222} 220}
223 221
224void 222void
225edit::insert (int pos, char sym) 223edit::insert (int pos, char sym)
226{ 224{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines