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