libyui-ncurses
2.44.1
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: ncursesp.cc 00020 00021 Author: Michael Andres <ma@suse.de> 00022 00023 /-*/ 00024 00025 /**************************************************************************** 00026 * Copyright (c) 1998 Free Software Foundation, Inc. * 00027 * * 00028 * Permission is hereby granted, free of charge, to any person obtaining a * 00029 * copy of this software and associated documentation files (the * 00030 * "Software"), to deal in the Software without restriction, including * 00031 * without limitation the rights to use, copy, modify, merge, publish, * 00032 * distribute, distribute with modifications, sublicense, and/or sell * 00033 * copies of the Software, and to permit persons to whom the Software is * 00034 * furnished to do so, subject to the following conditions: * 00035 * * 00036 * The above copyright notice and this permission notice shall be included * 00037 * in all copies or substantial portions of the Software. * 00038 * * 00039 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 00040 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 00041 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 00042 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 00043 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 00044 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 00045 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 00046 * * 00047 * Except as contained in this notice, the name(s) of the above copyright * 00048 * holders shall not be used in advertising or otherwise to promote the * 00049 * sale, use or other dealings in this Software without prior written * 00050 * authorization. * 00051 ****************************************************************************/ 00052 00053 /**************************************************************************** 00054 * Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1993,1997 * 00055 ****************************************************************************/ 00056 00057 #include <string.h> 00058 #include <iostream> 00059 00060 #include "ncursesp.h" 00061 00062 00063 NCursesPanel* NCursesPanel::dummy = ( NCursesPanel* )0; 00064 00065 void NCursesPanel::init() 00066 { 00067 p = ::new_panel( w ); 00068 00069 if ( !p ) 00070 OnError( ERR ); 00071 00072 UserHook* hook = new UserHook; 00073 00074 hook->m_user = NULL; 00075 00076 hook->m_back = this; 00077 00078 hook->m_owner = p; 00079 00080 ::set_panel_userptr( p, ( void * )hook ); 00081 } 00082 00083 NCursesPanel::~NCursesPanel() 00084 { 00085 UserHook* hook = ( UserHook* )::panel_userptr( p ); 00086 assert( hook && hook->m_back == this && hook->m_owner == p ); 00087 delete hook; 00088 ::del_panel( p ); 00089 ::update_panels(); 00090 ::doupdate(); 00091 } 00092 00093 void 00094 NCursesPanel::redraw() 00095 { 00096 PANEL *pan; 00097 00098 pan = ::panel_above( NULL ); 00099 00100 while ( pan ) 00101 { 00102 ::touchwin( panel_window( pan ) ); 00103 pan = ::panel_above( pan ); 00104 } 00105 00106 ::update_panels(); 00107 00108 ::doupdate(); 00109 } 00110 00111 int 00112 NCursesPanel::refresh() 00113 { 00114 ::update_panels(); 00115 return ::doupdate(); 00116 } 00117 00118 int 00119 NCursesPanel::noutrefresh() 00120 { 00121 ::update_panels(); 00122 return OK; 00123 } 00124 00125 void 00126 NCursesPanel::boldframe( const char *title, const char* btitle ) 00127 { 00128 standout(); 00129 frame( title, btitle ); 00130 standend(); 00131 } 00132 00133 void 00134 NCursesPanel::frame( const char *title, const char *btitle ) 00135 { 00136 int err = OK; 00137 00138 if ( !title && !btitle ) 00139 { 00140 err = box(); 00141 } 00142 else 00143 { 00144 err = box(); 00145 00146 if ( err == OK ) 00147 label( title, btitle ); 00148 } 00149 00150 OnError( err ); 00151 } 00152 00153 void 00154 NCursesPanel::label( const char *tLabel, const char *bLabel ) 00155 { 00156 if ( tLabel ) 00157 centertext( 0, tLabel ); 00158 00159 if ( bLabel ) 00160 centertext( maxy(), bLabel ); 00161 } 00162 00163 void 00164 NCursesPanel::centertext( int row, const char *label ) 00165 { 00166 if ( label ) 00167 { 00168 int x = ( maxx() - strlen( label ) ) / 2; 00169 00170 if ( x < 0 ) 00171 x = 0; 00172 00173 OnError( addstr( row, x, label, width() ) ); 00174 } 00175 } 00176 00177 00178 00179 int NCursesPanel::transparent( int y, int x ) 00180 { 00181 if ( hidden() 00182 || y < 0 || maxy() < y 00183 || x < 0 || maxx() < x ) 00184 { 00185 return ERR; 00186 } 00187 00188 int ay = begy() + y; 00189 00190 int ax = begx() + x; 00191 00192 for ( PANEL * sp = ::panel_below( p ); 1; sp = ::panel_below( sp ) ) 00193 { 00194 WINDOW * sw = ( sp ? ::panel_window( sp ) : ::stdscr ); 00195 00196 if ( sw ) 00197 { 00198 int dy = ay - sw->_begy; 00199 00200 if ( 0 <= dy && dy <= sw->_maxy ) 00201 { 00202 int dx = ax - sw->_begx; 00203 00204 if ( 0 <= dx && dx <= sw->_maxx ) 00205 { 00206 return addch( y, x, ::mvwinch( sw, dy, dx ) ); 00207 } 00208 } 00209 } 00210 00211 if ( !sp ) 00212 break; 00213 } 00214 00215 return ERR; 00216 } 00217 00218 00219 std::ostream & operator<<( std::ostream & Stream, const NCursesPanel * Obj_Cv ) 00220 { 00221 if ( Obj_Cv ) 00222 return Stream << *Obj_Cv; 00223 00224 return Stream << "(NoNCPan)"; 00225 } 00226 00227 00228 std::ostream & operator<<( std::ostream & Stream, const NCursesPanel & Obj_Cv ) 00229 { 00230 return Stream << "NCPan(" << Obj_Cv.p << ')'; 00231 } 00232