]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/cursesapp.cc
ncurses 5.1
[ncurses.git] / c++ / cursesapp.cc
1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3  * Copyright (c) 1998,1999 Free Software Foundation, Inc.                   *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29
30 /****************************************************************************
31  *   Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997                 *
32  ****************************************************************************/
33
34 #include "cursesapp.h"
35 #include "internal.h"
36
37 MODULE_ID("$Id: cursesapp.cc,v 1.6 1999/10/30 23:59:37 tom Exp $")
38
39 void
40 NCursesApplication::init(bool bColors) {
41   if (bColors)
42     NCursesWindow::useColors();
43   
44   if (Root_Window->colors() > 1) {    
45     b_Colors = TRUE;
46     Root_Window->setcolor(1);
47     Root_Window->setpalette(COLOR_YELLOW,COLOR_BLUE);
48     Root_Window->setcolor(2);
49     Root_Window->setpalette(COLOR_CYAN,COLOR_BLUE);
50     Root_Window->setcolor(3);
51     Root_Window->setpalette(COLOR_BLACK,COLOR_BLUE);
52     Root_Window->setcolor(4);
53     Root_Window->setpalette(COLOR_BLACK,COLOR_CYAN);
54     Root_Window->setcolor(5);
55     Root_Window->setpalette(COLOR_BLUE,COLOR_YELLOW);
56     Root_Window->setcolor(6);
57     Root_Window->setpalette(COLOR_BLACK,COLOR_GREEN);
58   }
59   else
60     b_Colors = FALSE;
61
62   Root_Window->bkgd(' '|window_backgrounds());
63 }
64
65 NCursesApplication* NCursesApplication::theApp = 0;
66 NCursesWindow* NCursesApplication::titleWindow = 0;
67 NCursesApplication::SLK_Link* NCursesApplication::slk_stack = 0;
68
69 NCursesApplication::~NCursesApplication() {
70   Soft_Label_Key_Set* S;
71
72   delete titleWindow;
73   while( (S=top()) ) {
74     pop();
75     delete S;
76   }
77   delete Root_Window;
78   ::endwin();
79 }
80
81 int NCursesApplication::rinit(NCursesWindow& w) {
82   titleWindow = &w;
83   return OK;
84 }
85
86 void NCursesApplication::push(Soft_Label_Key_Set& S) {
87   SLK_Link* L = new SLK_Link;
88   assert(L != 0);
89   L->prev = slk_stack;
90   L->SLKs = &S;
91   slk_stack = L;
92   if (Root_Window)
93     S.show();
94 }
95
96 bool NCursesApplication::pop() {
97   if (slk_stack) {
98     SLK_Link* L = slk_stack;
99     slk_stack = slk_stack->prev;
100     delete L;
101     if (Root_Window && top())
102       top()->show();
103   }
104   return (slk_stack ? FALSE : TRUE);
105 }
106
107 Soft_Label_Key_Set* NCursesApplication::top() const {
108   if (slk_stack)
109     return slk_stack->SLKs;
110   else
111     return (Soft_Label_Key_Set*)0;
112 }
113
114 int NCursesApplication::operator()(void) {
115   bool bColors = b_Colors;
116   Soft_Label_Key_Set* S;
117
118   int ts = titlesize();
119   if (ts>0)
120     NCursesWindow::ripoffline(ts,rinit);
121   Soft_Label_Key_Set::Label_Layout fmt = useSLKs();
122   if (fmt!=Soft_Label_Key_Set::None) {    
123     S = new Soft_Label_Key_Set(fmt);
124     assert(S != 0);
125     init_labels(*S);
126   }
127
128   Root_Window = new NCursesWindow(::stdscr);
129   init(bColors);
130
131   if (ts>0)
132     title();
133   if (fmt!=Soft_Label_Key_Set::None) {
134     push(*S);
135   }
136
137   return run();
138 }
139
140 NCursesApplication::NCursesApplication(bool bColors) {
141   b_Colors = bColors;
142   if (theApp)
143     THROW(new NCursesException("Application object already created."));
144   else
145     theApp = this;
146 }