libyui-ncurses  2.44.1
 All Classes Functions Variables
ncursesp.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: ncursesp.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 /****************************************************************************
26  * Copyright (c) 1998 Free Software Foundation, Inc. *
27  * *
28  * Permission is hereby granted, free of charge, to any person obtaining a *
29  * copy of this software and associated documentation files (the *
30  * "Software"), to deal in the Software without restriction, including *
31  * without limitation the rights to use, copy, modify, merge, publish, *
32  * distribute, distribute with modifications, sublicense, and/or sell *
33  * copies of the Software, and to permit persons to whom the Software is *
34  * furnished to do so, subject to the following conditions: *
35  * *
36  * The above copyright notice and this permission notice shall be included *
37  * in all copies or substantial portions of the Software. *
38  * *
39  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
40  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
41  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
42  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
43  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
44  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
45  * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
46  * *
47  * Except as contained in this notice, the name(s) of the above copyright *
48  * holders shall not be used in advertising or otherwise to promote the *
49  * sale, use or other dealings in this Software without prior written *
50  * authorization. *
51  ****************************************************************************/
52 
53 /****************************************************************************
54  * Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1993,1997 *
55  ****************************************************************************/
56 
57 #include <string.h>
58 #include <iostream>
59 
60 #include "ncursesp.h"
61 
62 
63 NCursesPanel* NCursesPanel::dummy = ( NCursesPanel* )0;
64 
65 void NCursesPanel::init()
66 {
67  p = ::new_panel( w );
68 
69  if ( !p )
70  OnError( ERR );
71 
72  UserHook* hook = new UserHook;
73 
74  hook->m_user = NULL;
75 
76  hook->m_back = this;
77 
78  hook->m_owner = p;
79 
80  ::set_panel_userptr( p, ( void * )hook );
81 }
82 
83 NCursesPanel::~NCursesPanel()
84 {
85  UserHook* hook = ( UserHook* )::panel_userptr( p );
86  assert( hook && hook->m_back == this && hook->m_owner == p );
87  delete hook;
88  ::del_panel( p );
89  ::update_panels();
90  ::doupdate();
91 }
92 
93 void
95 {
96  PANEL *pan;
97 
98  pan = ::panel_above( NULL );
99 
100  while ( pan )
101  {
102  ::touchwin( panel_window( pan ) );
103  pan = ::panel_above( pan );
104  }
105 
106  ::update_panels();
107 
108  ::doupdate();
109 }
110 
111 int
113 {
114  ::update_panels();
115  return ::doupdate();
116 }
117 
118 int
120 {
121  ::update_panels();
122  return OK;
123 }
124 
125 void
126 NCursesPanel::boldframe( const char *title, const char* btitle )
127 {
128  standout();
129  frame( title, btitle );
130  standend();
131 }
132 
133 void
134 NCursesPanel::frame( const char *title, const char *btitle )
135 {
136  int err = OK;
137 
138  if ( !title && !btitle )
139  {
140  err = box();
141  }
142  else
143  {
144  err = box();
145 
146  if ( err == OK )
147  label( title, btitle );
148  }
149 
150  OnError( err );
151 }
152 
153 void
154 NCursesPanel::label( const char *tLabel, const char *bLabel )
155 {
156  if ( tLabel )
157  centertext( 0, tLabel );
158 
159  if ( bLabel )
160  centertext( maxy(), bLabel );
161 }
162 
163 void
164 NCursesPanel::centertext( int row, const char *label )
165 {
166  if ( label )
167  {
168  int x = ( maxx() - strlen( label ) ) / 2;
169 
170  if ( x < 0 )
171  x = 0;
172 
173  OnError( addstr( row, x, label, width() ) );
174  }
175 }
176 
177 
178 
179 int NCursesPanel::transparent( int y, int x )
180 {
181  if ( hidden()
182  || y < 0 || maxy() < y
183  || x < 0 || maxx() < x )
184  {
185  return ERR;
186  }
187 
188  int ay = begy() + y;
189 
190  int ax = begx() + x;
191 
192  for ( PANEL * sp = ::panel_below( p ); 1; sp = ::panel_below( sp ) )
193  {
194  WINDOW * sw = ( sp ? ::panel_window( sp ) : ::stdscr );
195 
196  if ( sw )
197  {
198  int dy = ay - sw->_begy;
199 
200  if ( 0 <= dy && dy <= sw->_maxy )
201  {
202  int dx = ax - sw->_begx;
203 
204  if ( 0 <= dx && dx <= sw->_maxx )
205  {
206  return addch( y, x, ::mvwinch( sw, dy, dx ) );
207  }
208  }
209  }
210 
211  if ( !sp )
212  break;
213  }
214 
215  return ERR;
216 }
217 
218 
219 std::ostream & operator<<( std::ostream & Stream, const NCursesPanel * Obj_Cv )
220 {
221  if ( Obj_Cv )
222  return Stream << *Obj_Cv;
223 
224  return Stream << "(NoNCPan)";
225 }
226 
227 
228 std::ostream & operator<<( std::ostream & Stream, const NCursesPanel & Obj_Cv )
229 {
230  return Stream << "NCPan(" << Obj_Cv.p << ')';
231 }
232 
bool hidden() const
Definition: ncursesp.h:200
virtual void label(const char *topLabel, const char *bottomLabel)
Definition: ncursesp.cc:154
static void redraw()
Definition: ncursesp.cc:94
virtual int refresh()
Definition: ncursesp.cc:112
int maxx() const
Definition: ncursesw.h:1090
virtual void centertext(int row, const char *label)
Definition: ncursesp.cc:164
virtual void frame(const char *title=NULL, const char *btitle=NULL)
Definition: ncursesp.cc:134
void OnError(int err) const THROWS(NCursesPanelException)
Definition: ncursesp.h:109
int doupdate()
Definition: ncursesw.h:1646
int standout()
Definition: ncursesw.h:1693
int standend()
Definition: ncursesw.h:1698
int addch(const char ch)
Definition: ncursesw.h:1228
int begy() const
Definition: ncursesw.h:1085
virtual int noutrefresh()
Definition: ncursesp.cc:119
int begx() const
Definition: ncursesw.h:1080
int maxy() const
Definition: ncursesw.h:1095
virtual void boldframe(const char *title=NULL, const char *btitle=NULL)
Definition: ncursesp.cc:126
int touchwin()
Definition: ncursesw.h:1595
int addstr(const char *str, int n=-1)
Definition: ncursesw.h:1276
int width() const
Definition: ncursesw.h:1075
WINDOW * w
Definition: ncursesw.h:947