Skip to content

Commit

Permalink
Work around 32768 lines limit in ncurses table. (bnc #550733)
Browse files Browse the repository at this point in the history
svn path=/branches/SuSE-Linux-11_2-Branch/ncurses/; revision=60145
  • Loading branch information
mlandres committed Dec 18, 2009
1 parent 04d3c4c commit 8b520ae
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 16 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.18.10
2.18.11
6 changes: 6 additions & 0 deletions package/yast2-ncurses.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Dec 18 11:46:34 CET 2009 - ma@suse.de

- Work around 32768 lines limit in ncurses table. (bnc #550733)
- V 2.18.11

-------------------------------------------------------------------
Thu May 28 11:28:12 CEST 2009 - gs@suse.de

Expand Down
60 changes: 55 additions & 5 deletions src/NCPad.cc
Expand Up @@ -20,6 +20,29 @@
#include <YUILog.h>
#include "NCPad.h"

///////////////////////////////////////////////////////////////////

// PAD_PAGESIZE needs to be large enough to feed any destwin. We
// get in throuble here if the terminal has more than 1024 lines.
#define PAD_PAGESIZE 1024

// Maximum height of the NCursesPad (e.g. in case it can't hold more
// than 32768 lines). Larger pads need to page.
//#define MAX_PAD_HEIGHT 100
#define MAX_PAD_HEIGHT NCursesWindow::maxcoord()


NCPad::NCPad( int lines, int cols, const NCWidget & p )
: NCursesPad( lines > MAX_PAD_HEIGHT ? PAD_PAGESIZE : lines, cols )
, _vheight( lines > MAX_PAD_HEIGHT ? lines : 0 )
, parw( p )
, destwin ( 0 )
, maxdpos ( 0 )
, maxspos ( 0 )
, dclear ( false )
, dirty ( false )
{}


void NCPad::Destwin( NCursesWindow * dwin )
{
Expand All @@ -29,9 +52,9 @@ void NCPad::Destwin( NCursesWindow * dwin )

if ( destwin )
{
wsze mysze( maxy() + 1, maxx() + 1 );
wsze mysze( vheight(), width() );

drect = wrect( 0, wsze( destwin->maxy() + 1, destwin->maxx() + 1 ) );
drect = wrect( 0, wsze( destwin->height(), destwin->width() ) );
srect = wrect( 0, wsze::min( mysze, drect.Sze ) );
maxdpos = drect.Pos + srect.Sze - 1;
maxspos = mysze - srect.Sze;
Expand All @@ -52,15 +75,27 @@ void NCPad::resize( wsze nsze )
{
SetPadSize( nsze ); // might be enlarged by NCPadWidget if redirected

if ( nsze.H != height()
if ( nsze.H != vheight()
|| nsze.W != width() )
{
NCursesWindow * odest = Destwin();

if ( odest )
Destwin( 0 );

if ( nsze.H > MAX_PAD_HEIGHT )
{
yuiDebug() << "TRUCNATE PAD: " << nsze.H << " > " << MAX_PAD_HEIGHT << endl;
NCursesPad::resize( PAD_PAGESIZE, nsze.W );
_vheight = nsze.H;
}
else
{
NCursesPad::resize( nsze.H, nsze.W );
_vheight = 0;
}

yuiDebug() << "Pageing ?: " << pageing() << endl;

if ( odest )
Destwin( odest );
Expand Down Expand Up @@ -89,13 +124,28 @@ int NCPad::update()

updateScrollHint();

if ( ! pageing() )
{
return copywin( *destwin,
srect.Pos.L, srect.Pos.C,
drect.Pos.L, drect.Pos.C,
maxdpos.L, maxdpos.C,
false );
}

// Here: Table is pageing, so we must prepare the visible lines
// on the Pad before we're copying them to the destwin:
wsze lSze( 1, width() );
for ( unsigned i = 0; i <= maxdpos.L; ++i )
{
directDraw( *this, wrect( wpos( i, 0 ), lSze ), srect.Pos.L+i );
}
return copywin( *destwin,
0, srect.Pos.C,
drect.Pos.L, drect.Pos.C,
maxdpos.L, maxdpos.C,
false );
}
return OK;
}

Expand Down Expand Up @@ -128,7 +178,7 @@ bool NCPad::handleInput( wint_t key )
break;

case KEY_HOME:
ScrlUp( maxy() );
ScrlUp( vheight() );
break;

case KEY_DOWN:
Expand All @@ -140,7 +190,7 @@ bool NCPad::handleInput( wint_t key )
break;

case KEY_END:
ScrlDown( maxy() );
ScrlDown( vheight() );
break;

case KEY_LEFT:
Expand Down
44 changes: 34 additions & 10 deletions src/NCPad.h
Expand Up @@ -86,6 +86,23 @@ class NCScrollHint : protected NCSchrollCB

class NCPad : public NCursesPad, public NCScrollHint
{
private:

/** The real height in case the NCursesPad is truncated, otherwise \c 0.
*
* \note Don't use _vheight directly, but \ref vheight.
*
* Up to ncurses5, ncurses uses \c short for window dimensions (can't hold
* more than 32768 lines). If \ref resize truncated the window, the real
* size is in \ref _vheight. Longer lists need to be paged.
*
* \todo Once all NCPad based types are able to page, \a maxPadHeight could be
* set to e.g \c 1024 to avoid bigger widgets in memory. Currently just
* \ref NCTablePad supports paging. If paging is \c ON, all content lines are
* written via \ref directDraw. Without pageing \ref DoRedraw is reponsible for this.
*/
int _vheight;

protected:

const NCWidget & parw;
Expand All @@ -99,6 +116,11 @@ class NCPad : public NCursesPad, public NCScrollHint
bool dclear;
bool dirty;

/** The (virtual) height of the Pad (even if truncated). */
int vheight() const { return _vheight ? _vheight : height(); }

/** Whether the Pad is truncated (we're pageing). */
bool pageing() const { return _vheight; }

virtual int dirtyPad() { dirty = false; return setpos( CurPos() ); }

Expand All @@ -111,18 +133,20 @@ class NCPad : public NCursesPad, public NCScrollHint

virtual void updateScrollHint();

public:
/** Directly draw a table item at a specific location.
*
* \ref update usually copies the visible table content from the
* \ref NCursesPad to \ref destwin. In case the \ref NCursesPad
* is truncated, the visible lines are prepared immediately before
* they are written to \ref destwin
* .
* \see \ref _vheight.
*/
virtual void directDraw( NCursesWindow & w, const wrect at, unsigned lineno ) {}

NCPad( int lines, int cols, const NCWidget & p )
: NCursesPad( lines, cols )
, parw( p )
, destwin( 0 )
, maxdpos( 0 )
, maxspos( 0 )
, dclear( false )
, dirty( false )
{}
public:

NCPad( int lines, int cols, const NCWidget & p );
virtual ~NCPad() {}

public:
Expand Down
18 changes: 18 additions & 0 deletions src/NCTablePad.cc
Expand Up @@ -207,11 +207,15 @@ int NCTablePad::DoRedraw()

wsze lSze( 1, width() );

if ( ! pageing() )
{
for ( unsigned l = 0; l < Lines(); ++l )
{
Items[l]->DrawAt( *this, wrect( wpos( l, 0 ), lSze ),
ItemStyle, (( unsigned )citem.L == l ) );
}
}
// else: item drawing requested via directDraw

if ( Headpad.width() != width() )
Headpad.resize( 1, width() );
Expand All @@ -230,6 +234,16 @@ int NCTablePad::DoRedraw()



void NCTablePad::directDraw( NCursesWindow & w, const wrect at, unsigned lineno )
{
if ( lineno < Lines() )
Items[lineno]->DrawAt( w, at, ItemStyle, ((unsigned)citem.L == lineno) );
else
yuiWarning() << "Illegal Lineno " << lineno << " (" << Lines() << ")" << endl;
}



int NCTablePad::setpos( const wpos & newpos )
{
if ( !Lines() )
Expand Down Expand Up @@ -265,6 +279,8 @@ int NCTablePad::setpos( const wpos & newpos )
return DoRedraw();
}

if ( ! pageing() )
{
// adjust only
if ( citem.L != oitem )
{
Expand All @@ -275,6 +291,8 @@ int NCTablePad::setpos( const wpos & newpos )
Items[citem.L]->DrawAt( *this, wrect( wpos( citem.L, 0 ), wsze( 1, width() ) ),

ItemStyle, true );
}
// else: item drawing requested via directDraw

if ( srect.Pos.C != opos )
SendHead();
Expand Down
2 changes: 2 additions & 0 deletions src/NCTablePad.h
Expand Up @@ -163,6 +163,8 @@ class NCTablePad : public NCPad
virtual int DoRedraw();
virtual void updateScrollHint();

virtual void directDraw( NCursesWindow & w, const wrect at, unsigned lineno );

public:

NCTablePad( int lines, int cols, const NCWidget & p );
Expand Down
6 changes: 6 additions & 0 deletions src/ncursesw.h
Expand Up @@ -24,6 +24,7 @@
#include <ncursesw/etip.h>
#include <cstdio>
#include <cstdarg>
#include <climits>
#include "position.h"

#include <ncursesw/curses.h>
Expand Down Expand Up @@ -887,6 +888,9 @@ inline void UNDEF( bkgdset )( chtype ch ) { bkgdset( ch ); }
#define bkgdset UNDEF(bkgdset)
#endif

template <class _Tp> inline int ncursesMaxCoord() { return INT_MAX; }
template <> inline int ncursesMaxCoord<short>() { return SHRT_MAX; }

/**
* @short C++ class for windows.
*/
Expand Down Expand Up @@ -1084,6 +1088,8 @@ class NCursesWindow
*/
int maxy() const { return getmaxy(w) == ERR ? ERR : getmaxy(w)-1; }

/** Ncurses up to ncurses5 internally uses \c short. */
static int maxcoord() { return ncursesMaxCoord<NCURSES_SIZE_T>(); }

wsze size() const { return wsze( height(), width() ); }

Expand Down

0 comments on commit 8b520ae

Please sign in to comment.