ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/application.cpp
Revision: 1.5
Committed: Wed Oct 20 08:33:42 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.4: +10 -0 lines
Log Message:
2 glyphs / map space

File Contents

# User Rev Content
1 sf-pippijn 1.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 sf-pippijn 1.4 #include <term.h>
17    
18 sf-pippijn 1.1 #include <clocale>
19    
20     using ndk::application;
21    
22 sf-pippijn 1.4 namespace std
23 sf-pippijn 1.1 {
24 sf-pippijn 1.4 template<>
25     size_t
26     hash<ndk::colors::type>::operator () (ndk::colors::type type) const
27     {
28     return hash<int> () (type);
29     }
30     }
31 sf-pippijn 1.1
32 sf-pippijn 1.4 application *ndk::app;
33 sf-pippijn 1.1
34     application::application ()
35     {
36 sf-pippijn 1.4 /*
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 sf-pippijn 1.1 if (!has_keymap ())
62 sf-pippijn 1.2 return_unless (keypad (stdscr, true) == OK);
63 sf-pippijn 1.4 }
64 sf-pippijn 1.1
65 sf-pippijn 1.5 static void
66     init_color_pairs ()
67     {
68     for (short fg = 0; fg < 8; fg++)
69     for (short bg = 0; bg < 8; bg++)
70     return_unless (init_pair (fg * 8 + bg + 1, fg, bg) == OK);
71     }
72    
73 sf-pippijn 1.4 void
74     application::init_palette ()
75     {
76 sf-pippijn 1.5 init_color_pairs ();
77    
78 sf-pippijn 1.1 palette::obj_type &p = palette::instance ();
79    
80 sf-pippijn 1.4 p.insert ({ colors::button_default, { COLOR_WHITE, COLOR_BLACK } });
81     p.insert ({ colors::label, { COLOR_WHITE, COLOR_BLACK } });
82     p.insert ({ colors::panel, { COLOR_WHITE, COLOR_BLACK } });
83     p.insert ({ colors::title, { COLOR_WHITE, COLOR_BLUE, WA_BOLD } });
84     p.insert ({ colors::frame1, { COLOR_WHITE, COLOR_BLUE, WA_BOLD } });
85     p.insert ({ colors::frame2, { COLOR_WHITE, COLOR_BLACK } });
86     p.insert ({ colors::button_focused, { COLOR_BLACK, COLOR_WHITE } });
87     p.insert ({ colors::button_selected, { COLOR_WHITE, COLOR_WHITE, WA_BOLD } });
88     p.insert ({ colors::minibutton, { COLOR_WHITE, COLOR_BLACK } });
89     p.insert ({ colors::edit_active, { COLOR_WHITE, COLOR_BLACK, WA_BOLD } });
90     p.insert ({ colors::edit_inactive, { COLOR_WHITE, COLOR_BLACK } });
91     }
92    
93     application::~application ()
94     {
95     endwin ();
96     delscreen (screen_);
97     }
98 sf-pippijn 1.1
99 sf-pippijn 1.4 int
100     application::width () const
101     {
102     return COLS;
103     }
104    
105     int
106     application::height () const
107     {
108     return LINES;
109     }
110    
111     void
112     application::cursor_on ()
113     {
114     /* first try to made cursor super visible, otherwise made it normal */
115     curs_set (cursor_visible ? 2 : 1);
116     }
117    
118     void
119     application::cursor_off ()
120     {
121     curs_set (0); /* turn on cursor */
122 sf-pippijn 1.1 }
123    
124     ndk::engine *
125     application::events ()
126     {
127     return &events_;
128     }
129    
130     void
131     application::update ()
132     {
133     events_.update ();
134     }
135    
136     void
137     application::process (int ch)
138     {
139     events_.process (ch);
140     }
141    
142     void
143     application::in_focus (panel &other)
144     {
145     events_.in_focus (other.events ());
146     }