[Aptitude-devel] r3020 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Thu, 21 Apr 2005 01:57:01 +0000
Author: dburrows
Date: Thu Apr 21 01:56:57 2005
New Revision: 3020
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
branches/aptitude-0.3/aptitude/src/vscreen/fragment.h
branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc
Log:
Add support for hard-wrapping text.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Apr 21 01:56:57 2005
@@ -1,5 +1,10 @@
2005-04-20 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/fragment.cc, src/vscreen/fragment.h, src/vscreen/testvscreen.cc:
+
+ Add a "hardwrapbox" which wraps lines hard to the fragment's
+ width (rather than doing word-wrapping).
+
* src/generic/problemresolver/model.tex:
Add some discussion of the theoretical basis for the new problem
Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc Thu Apr 21 01:56:57 2005
@@ -571,6 +571,71 @@
fragment *fillbox(fragment *contents) {return new _fillbox(contents);}
+class _hardwrapbox:public fragment_container
+{
+ fragment *contents;
+
+public:
+ _hardwrapbox(fragment *_contents):contents(_contents) {}
+
+ ~_hardwrapbox() {delete contents;}
+
+ fragment_contents layout(size_t w)
+ {
+ if(w==0)
+ return fragment_contents();
+
+ fragment_contents rval, lines=contents->layout(w);
+
+ for(fragment_contents::const_iterator i=lines.begin();
+ i!=lines.end(); ++i)
+ {
+ if(i->empty())
+ rval.push_back(chstring(""));
+ else
+ {
+ chstring s=*i;
+ chstring::size_type start=0;
+
+ while(s.size()-start>w)
+ {
+ rval.push_back(chstring(s, start, w));
+ start+=w;
+ }
+
+ if(start<s.size())
+ rval.push_back(chstring(s, start));
+ }
+ }
+
+ rval.set_final_nl(true);
+
+ return rval;
+ }
+
+ void set_attr(int attr) { contents->set_attr(attr); }
+
+ size_t calc_max_width() const
+ {
+ return contents->max_width();
+ }
+
+ size_t calc_trailing_width() const
+ {
+ return 0;
+ }
+
+ bool calc_final_newline() const
+ {
+ return true;
+ }
+};
+
+fragment *hardwrapbox(fragment *contents)
+{
+ return new _hardwrapbox(contents);
+}
+
class _clipbox:public fragment_container
{
public:
Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.h Thu Apr 21 01:56:57 2005
@@ -176,6 +176,19 @@
*/
fragment *fillbox(fragment *contents);
+/** Create a hardwrapbox.
+ *
+ * Each line of the fragment inside the box will be hard-wrapped
+ * to the current width.
+ *
+ * The contents of a wrapbox always have final_nl=\b true.
+ *
+ * \param contents the contents of the hardwrapbox
+ *
+ * \return the new hardwrapbox
+ */
+fragment *hardwrapbox(fragment *contents);
+
/** Create a clipbox.
*
* Each line of the fragment placed inside the clipbox will be
Modified: branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc Thu Apr 21 01:56:57 2005
@@ -335,6 +335,10 @@
text_fragment("Mind", A_BOLD),
text_fragment("dead", A_BOLD))));
+ v.push_back(newline_fragment());
+
+ v.push_back(hardwrapbox(fragf("The mention of Marley's funeral brings me back to the point I started from. There is no doubt that Marley was dead. This must be distinctly understood, or nothing wonderful can come of the story I am going to relate. If we were not perfectly convinced that Hamlet's Father died before the play began, there would be nothing more remarkable in his taking a stroll at night, in an easterly wind, upon his own ramparts, than there would be in any other middle-aged gentleman rashly turning out after dark in a breezy spot -- say Saint Paul's Churchyard for instance -- literally to astonish his son's weak mind.")));
+
vs_text_layout *l=new vs_text_layout(sequence_fragment(v));
vs_scrollbar *s=new vs_scrollbar(vs_scrollbar::VERTICAL);
l->location_changed.connect(sigc::mem_fun(*s, &vs_scrollbar::set_slider));