ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/application.cpp
Revision: 1.4
Committed: Tue Oct 19 09:45:08 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.3: +81 -22 lines
Log Message:
- use wchar_t for single characters (glyphs and line drawing)
- merge ncurses and ndk wrappers
- simplify colour caching

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.4 void
66     application::init_palette ()
67     {
68 sf-pippijn 1.1 palette::obj_type &p = palette::instance ();
69    
70 sf-pippijn 1.4 p.insert ({ colors::button_default, { COLOR_WHITE, COLOR_BLACK } });
71     p.insert ({ colors::label, { COLOR_WHITE, COLOR_BLACK } });
72     p.insert ({ colors::panel, { COLOR_WHITE, COLOR_BLACK } });
73     p.insert ({ colors::title, { COLOR_WHITE, COLOR_BLUE, WA_BOLD } });
74     p.insert ({ colors::frame1, { COLOR_WHITE, COLOR_BLUE, WA_BOLD } });
75     p.insert ({ colors::frame2, { COLOR_WHITE, COLOR_BLACK } });
76     p.insert ({ colors::button_focused, { COLOR_BLACK, COLOR_WHITE } });
77     p.insert ({ colors::button_selected, { COLOR_WHITE, COLOR_WHITE, WA_BOLD } });
78     p.insert ({ colors::minibutton, { COLOR_WHITE, COLOR_BLACK } });
79     p.insert ({ colors::edit_active, { COLOR_WHITE, COLOR_BLACK, WA_BOLD } });
80     p.insert ({ colors::edit_inactive, { COLOR_WHITE, COLOR_BLACK } });
81     }
82    
83     application::~application ()
84     {
85     endwin ();
86     delscreen (screen_);
87     }
88 sf-pippijn 1.1
89 sf-pippijn 1.4 int
90     application::width () const
91     {
92     return COLS;
93     }
94    
95     int
96     application::height () const
97     {
98     return LINES;
99     }
100    
101     void
102     application::cursor_on ()
103     {
104     /* first try to made cursor super visible, otherwise made it normal */
105     curs_set (cursor_visible ? 2 : 1);
106     }
107    
108     void
109     application::cursor_off ()
110     {
111     curs_set (0); /* turn on cursor */
112 sf-pippijn 1.1 }
113    
114     ndk::engine *
115     application::events ()
116     {
117     return &events_;
118     }
119    
120     void
121     application::update ()
122     {
123     events_.update ();
124     }
125    
126     void
127     application::process (int ch)
128     {
129     events_.process (ch);
130     }
131    
132     void
133     application::in_focus (panel &other)
134     {
135     events_.in_focus (other.events ());
136     }