libyui-ncurses  2.44.1
 All Classes Functions Variables
NCLogView.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: NCLogView.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCLogView.h"
28 
29 
30 NCLogView::NCLogView( YWidget * parent,
31  const std::string & nlabel,
32  int visibleLines,
33  int maxLines )
34  : YLogView( parent, nlabel, visibleLines, maxLines )
35  , NCPadWidget( parent )
36 {
37  yuiDebug() << std::endl;
38  defsze = wsze( visibleLines, 5 ) + 2;
39  setLabel( nlabel );
40 }
41 
42 
43 NCLogView::~NCLogView()
44 {
45  yuiDebug() << std::endl;
46 }
47 
48 
49 int NCLogView::preferredWidth()
50 {
51  defsze.W = ( 5 > labelWidth() ? 5 : labelWidth() ) + 2;
52  return wGetDefsze().W;
53 }
54 
55 
56 int NCLogView::preferredHeight()
57 {
58  return wGetDefsze().H;
59 }
60 
61 
62 void NCLogView::setEnabled( bool do_bv )
63 {
64  NCWidget::setEnabled( do_bv );
65  YLogView::setEnabled( do_bv );
66 }
67 
68 
69 void NCLogView::setSize( int newwidth, int newheight )
70 {
71  wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
72 }
73 
74 
75 void NCLogView::setLabel( const std::string & nlabel )
76 {
77  YLogView::setLabel( nlabel );
78  NCPadWidget::setLabel( NCstring( nlabel ) );
79 }
80 
81 
82 void NCLogView::displayLogText( const std::string & ntext )
83 {
84  DelPad();
85  text = NCtext( NCstring( ntext ), Columns() );
86  Redraw();
87 }
88 
89 
90 void NCLogView::wRedraw()
91 {
92  if ( !win )
93  return;
94 
95  bool initial = ( !myPad() || !myPad()->Destwin() );
96 
97  if ( myPad() )
98  myPad()->bkgd( listStyle().item.plain );
99 
100  NCPadWidget::wRedraw();
101 
102  if ( initial )
103  myPad()->ScrlTo( wpos( text.Lines(), 0 ) );
104 }
105 
106 
107 void NCLogView::wRecoded()
108 {
109  DelPad();
110  wRedraw();
111 }
112 
113 
114 NCursesEvent NCLogView::wHandleInput( wint_t key )
115 {
116  handleInput( key );
117  return NCursesEvent::none;
118 }
119 
120 
121 NCPad * NCLogView::CreatePad()
122 {
123  wsze psze( defPadSze() );
124  NCPad * npad = new NCPad( psze.H, psze.W, *this );
125  npad->bkgd( listStyle().item.plain );
126  return npad;
127 }
128 
129 
130 void NCLogView::DrawPad()
131 {
132  // maximal value for lines is 32000!
133  unsigned int maxLines = 20000;
134  unsigned int skipLines = 0;
135  unsigned int lines = text.Lines();
136  unsigned int cl = 0;
137 
138  if ( lines > maxLines )
139  {
140  skipLines = lines - maxLines;
141  lines = maxLines;
142  }
143 
144  AdjustPad( wsze( lines, Columns() ) );
145 
146  for ( NCtext::const_iterator line = text.begin(); line != text.end(); ++line )
147  {
148  if ( skipLines == 0 )
149  {
150  myPad()->move( cl++, 0 );
151  std::wstring cline = ( *line ).str();
152  myPad()->addwstr( cline.c_str() );
153  }
154  else
155  {
156  skipLines--;
157  }
158  }
159 }
160 
Definition: NCtext.h:37
int bkgd(const chtype ch)
Definition: ncursesw.h:1443
Definition: NCPad.h:93
Definition: position.h:109
int addwstr(const wchar_t *str, int n=-1)
Definition: ncursesw.cc:123
virtual NCPad * myPad() const
Definition: NCPadWidget.h:62
virtual void setEnabled(bool do_bv)
Definition: NCLogView.cc:62
int move(int y, int x)
Definition: ncursesw.h:1155
virtual void setEnabled(bool do_bv)=0
Definition: NCWidget.cc:391
Definition: position.h:154