[Aptitude-devel] r3127 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Wed, 27 Apr 2005 03:00:23 +0000
Author: dburrows
Date: Wed Apr 27 03:00:20 2005
New Revision: 3127
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/vs_label.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_label.h
Log:
Add support for fragments to the vs_label.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Wed Apr 27 03:00:20 2005
@@ -1,5 +1,10 @@
2005-04-26 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/vs_label.cc, src/vscreen/vs_label.h:
+
+ Make labels use fragments internally. IMPORTANT: this means
+ that implicit interpretation of \n and \t no longer works...
+
* src/apt_options.cc:
Use FILL appropriately so the buttons at the bottom of the
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_label.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_label.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_label.cc Wed Apr 27 03:00:20 2005
@@ -1,6 +1,8 @@
// vs_label.cc
#include "vs_label.h"
+
+#include "fragment_cache.h"
#include "vscreen.h"
#include <config/colors.h>
@@ -9,15 +11,25 @@
using namespace std;
+vs_label::vs_label(fragment *f)
+{
+ txt=new fragment_cache(f);
+}
+
vs_label::vs_label(string _txt, int _attr)
- :txt(_txt), mysize(0, 0), mysize_stale(true), attr(_attr)
+ :txt(new fragment_cache(text_fragment(_txt, _attr)))
{
- set_bg(attr);
+ set_bg(_attr);
}
vs_label::vs_label(string _txt)
- :txt(_txt), mysize(0, 0), mysize_stale(true), attr(get_color("DefaultWidgetBackground"))
+ :txt(new fragment_cache(text_fragment(_txt)))
+{
+}
+
+vs_label::~vs_label()
{
+ delete txt;
}
bool vs_label::get_cursorvisible()
@@ -30,83 +42,29 @@
return point(0,0);
}
-void vs_label::set_text(string _txt)
+void vs_label::set_text(string _txt, int attr)
{
- txt=_txt;
- mysize_stale=true;
+ txt=new fragment_cache(text_fragment(_txt, attr));
// Our size might have changed, so re-layout the screen.
vscreen_queuelayout();
}
void vs_label::paint()
{
- erase();
-
- int x=0, y=0;
-
- for(string::size_type i=0; i<txt.size(); i++)
- {
- switch(txt[i])
- {
- case '\n':
- y++;
- x=0;
- break;
- case '\t':
- x+=8-(x%8);
- break;
- default:
- mvaddch(y, x, (unsigned char) txt[i]);
- x++;
- break;
- }
- }
-}
-
-void vs_label::update_size()
-{
- if(!mysize_stale)
- return;
-
- int maxx=0, maxy=1, curx=0, cury=1;
-
- for(string::size_type i=0; i<txt.size(); i++)
- {
- switch(txt[i])
- {
- case '\n':
- cury++;
- curx=0;
- break;
- case '\t':
- curx+=8-(curx%8);
- break;
- default:
- curx++;
- break;
- }
-
- maxx=max<int>(curx, maxx);
- maxy=max<int>(cury, maxy);
- }
+ fragment_contents lines=txt->layout(getmaxx(), getmaxx());
- mysize_stale=false;
-
- mysize=size(maxx, maxy);
+ for(size_t i=0; i<lines.size() && i<(unsigned) getmaxy(); ++i)
+ mvaddnstr(i, 0, lines[i], lines[i].size());
}
int vs_label::width_request()
{
- update_size();
-
- return mysize.w;
+ return txt->max_width(0, 0);
}
int vs_label::height_request(int width)
{
- update_size();
-
- return mysize.h;
+ return txt->layout(width, width).size();
}
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_label.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_label.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_label.h Wed Apr 27 03:00:20 2005
@@ -1,29 +1,21 @@
// vs_label.h -*-c++-*-
-//
-// A very simple text display, sans wordwrap, scrolling, etc.
#ifndef VS_LABEL_H
#define VS_LABEL_H
#include "vscreen_widget.h"
+class fragment;
+class fragment_cache;
+
class vs_label:public vscreen_widget
{
- std::string txt;
-
- /** Caches the dimensions of txt. */
- size mysize;
-
- /** If \b true, the size cache needs to be updated. */
- bool mysize_stale;
-
- int attr;
-
- /** Update mysize if necessary. */
- void update_size();
+ fragment_cache *txt;
public:
+ vs_label(fragment *f);
vs_label(std::string _txt, int attr);
vs_label(std::string _txt);
+ ~vs_label();
bool get_cursorvisible();
point get_cursorloc();
@@ -35,7 +27,8 @@
int height_request(int width);
void paint();
- void set_text(std::string _txt);
+ void set_text(std::string _txt, int attr);
+ void set_text(fragment *f);
};
class vs_transientlabel:public vs_label