ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/application.cpp
Revision: 1.7
Committed: Sun Oct 24 20:31:50 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +6 -6 lines
Log Message:
use EV and plain sockets instead of asio

File Contents

# Content
1 /* application.cc
2 * This file is part of NDK++ library
3 * Copyright (c) 2003,2004 by Stanislav Ievlev
4 *
5 * This file is covered by the GNU Library General Public License,
6 * which should be included with libndk as the file COPYING.
7 */
8
9 #include <ndk/application.hh>
10
11 #include <ndk/color.hh>
12 #include <ndk/keymap.hh>
13 #include <ndk/palette.hh>
14 #include <ndk/panel.hh>
15
16 #include <term.h>
17
18 #include <clocale>
19
20 using ndk::application;
21
22 namespace std
23 {
24 template<>
25 size_t
26 hash<ndk::colors::type>::operator () (ndk::colors::type type) const
27 {
28 return hash<int> () (type);
29 }
30 }
31
32 application *ndk::app;
33
34 application::application ()
35 {
36 /*
37 * init ncurses enviroment
38 * We use newterm/delscreen instead of initscr to reduce number of memory leaks
39 */
40 char const *name;
41
42 if ((name = getenv ("TERM")) == NULL || !*name)
43 name = "unknown";
44 screen_ = newterm (const_cast<char *> (name), stdout, stdin);
45
46 if (!screen_)
47 throw std::runtime_error ("newterm failed");
48
49 def_prog_mode ();
50 return_unless (cbreak () == OK);
51 return_unless (noecho () == OK);
52 return_unless (nonl () == OK);
53 return_unless (notimeout (stdscr, true) == OK);
54
55 if ((has_colors_ = ::has_colors ()))
56 return_unless (start_color () == OK);
57
58 mousemask (ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, nullptr);
59 cursor_off (); /* turn off cursor, by default */
60
61 enable_keypad (stdscr);
62 }
63
64 static void
65 init_color_pairs ()
66 {
67 for (short fg = 0; fg < 8; fg++)
68 for (short bg = 0; bg < 8; bg++)
69 return_unless (init_pair (fg * 8 + bg + 1, fg, bg) == OK);
70 }
71
72 void
73 application::init_palette ()
74 {
75 init_color_pairs ();
76
77 palette::obj_type &p = palette::instance ();
78
79 p.insert ({ colors::button_default, { COLOR_WHITE, COLOR_BLACK } });
80 p.insert ({ colors::label, { COLOR_WHITE, COLOR_BLACK } });
81 p.insert ({ colors::panel, { COLOR_WHITE, COLOR_BLACK } });
82 p.insert ({ colors::title, { COLOR_WHITE, COLOR_BLUE, WA_BOLD } });
83 p.insert ({ colors::frame1, { COLOR_WHITE, COLOR_BLUE, WA_BOLD } });
84 p.insert ({ colors::frame2, { COLOR_WHITE, COLOR_BLACK } });
85 p.insert ({ colors::button_focused, { COLOR_BLACK, COLOR_WHITE } });
86 p.insert ({ colors::button_selected, { COLOR_WHITE, COLOR_WHITE, WA_BOLD } });
87 p.insert ({ colors::minibutton, { COLOR_WHITE, COLOR_BLACK } });
88 p.insert ({ colors::edit_active, { COLOR_WHITE, COLOR_BLACK, WA_BOLD } });
89 p.insert ({ colors::edit_inactive, { COLOR_WHITE, COLOR_BLACK } });
90 }
91
92 application::~application ()
93 {
94 endwin ();
95 delscreen (screen_);
96 }
97
98 int
99 application::width () const
100 {
101 return COLS;
102 }
103
104 int
105 application::height () const
106 {
107 return LINES;
108 }
109
110 void
111 application::cursor_on ()
112 {
113 /* first try to made cursor super visible, otherwise made it normal */
114 curs_set (cursor_visible ? 2 : 1);
115 }
116
117 void
118 application::cursor_off ()
119 {
120 curs_set (0); /* turn on cursor */
121 }
122
123 ndk::engine *
124 application::events ()
125 {
126 return &events_;
127 }
128
129 void
130 application::update ()
131 {
132 events_.update ();
133 }
134
135 void
136 application::process (int ch)
137 {
138 events_.process (ch);
139 }
140
141 void
142 application::in_focus (panel &other)
143 {
144 events_.in_focus (other.events ());
145 }
146
147 void
148 application::enable_keypad (WINDOW *win)
149 {
150 if (!has_keymap ())
151 return_unless (keypad (win, true) == OK);
152 }