libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCLogView.cc
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:       NCLogView.cc
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #define  YUILogComponent "ncurses"
00026 #include <yui/YUILog.h>
00027 #include "NCLogView.h"
00028 
00029 
00030 NCLogView::NCLogView( YWidget * parent,
00031                       const std::string & nlabel,
00032                       int visibleLines,
00033                       int maxLines )
00034         : YLogView( parent, nlabel, visibleLines, maxLines )
00035         , NCPadWidget( parent )
00036 {
00037     yuiDebug() << std::endl;
00038     defsze = wsze( visibleLines, 5 ) + 2;
00039     setLabel( nlabel );
00040 }
00041 
00042 
00043 NCLogView::~NCLogView()
00044 {
00045     yuiDebug() << std::endl;
00046 }
00047 
00048 
00049 int NCLogView::preferredWidth()
00050 {
00051     defsze.W = ( 5 > labelWidth() ? 5 : labelWidth() ) + 2;
00052     return wGetDefsze().W;
00053 }
00054 
00055 
00056 int NCLogView::preferredHeight()
00057 {
00058     return wGetDefsze().H;
00059 }
00060 
00061 
00062 void NCLogView::setEnabled( bool do_bv )
00063 {
00064     NCWidget::setEnabled( do_bv );
00065     YLogView::setEnabled( do_bv );
00066 }
00067 
00068 
00069 void NCLogView::setSize( int newwidth, int newheight )
00070 {
00071     wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
00072 }
00073 
00074 
00075 void NCLogView::setLabel( const std::string & nlabel )
00076 {
00077     YLogView::setLabel( nlabel );
00078     NCPadWidget::setLabel( NCstring( nlabel ) );
00079 }
00080 
00081 
00082 void NCLogView::displayLogText( const std::string & ntext )
00083 {
00084     DelPad();
00085     text = NCtext( NCstring( ntext ), Columns() );
00086     Redraw();
00087 }
00088 
00089 
00090 void NCLogView::wRedraw()
00091 {
00092     if ( !win )
00093         return;
00094 
00095     bool initial = ( !myPad() || !myPad()->Destwin() );
00096 
00097     if ( myPad() )
00098         myPad()->bkgd( listStyle().item.plain );
00099 
00100     NCPadWidget::wRedraw();
00101 
00102     if ( initial )
00103         myPad()->ScrlTo( wpos( text.Lines(), 0 ) );
00104 }
00105 
00106 
00107 void NCLogView::wRecoded()
00108 {
00109     DelPad();
00110     wRedraw();
00111 }
00112 
00113 
00114 NCursesEvent NCLogView::wHandleInput( wint_t key )
00115 {
00116     handleInput( key );
00117     return NCursesEvent::none;
00118 }
00119 
00120 
00121 NCPad * NCLogView::CreatePad()
00122 {
00123     wsze psze( defPadSze() );
00124     NCPad * npad = new NCPad( psze.H, psze.W, *this );
00125     npad->bkgd( listStyle().item.plain );
00126     return npad;
00127 }
00128 
00129 
00130 void NCLogView::DrawPad()
00131 {
00132     // maximal value for lines is 32000!
00133     unsigned int maxLines = 20000;
00134     unsigned int skipLines = 0;
00135     unsigned int lines = text.Lines();
00136     unsigned int cl = 0;
00137 
00138     if ( lines > maxLines )
00139     {
00140         skipLines = lines - maxLines;
00141         lines = maxLines;
00142     }
00143 
00144     AdjustPad( wsze( lines, Columns() ) );
00145 
00146     for ( NCtext::const_iterator line = text.begin(); line != text.end(); ++line )
00147     {
00148         if ( skipLines == 0 )
00149         {
00150             myPad()->move( cl++, 0 );
00151             std::wstring cline = ( *line ).str();
00152             myPad()->addwstr( cline.c_str() );
00153         }
00154         else
00155         {
00156             skipLines--;
00157         }
00158     }
00159 }
00160 
 All Classes Functions Variables