[Aptitude-svn-commit] r3525 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Sat, 02 Jul 2005 13:00:42 +0000
Author: dburrows
Date: Sat Jul 2 13:00:40 2005
New Revision: 3525
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_staticitem.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_subtree.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.h
Log:
Convert the vs_treeitem interface to use wide characters everywhere.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sat Jul 2 13:00:40 2005
@@ -1,5 +1,12 @@
2005-07-02 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/testvscreen.cc, src/vscreen/vs_layout_item.cc, src/vscreen/vs_layout_item.h, src/vscreen/vs_staticitem.h, src/vscreen/vs_subtree.h, src/vscreen/vs_tree.cc, src/vscreen/vs_treeitem.cc, src/vscreen/vs_treeitem.h:
+
+ Adjust the treeitem interface to use wide characters; while I'm
+ at it, I removed a bunch of const qualifiers that looked
+ dangerous (const qualifiers on a virtual method are potentially
+ problematic).
+
* src/edit_pkg_hier.cc, src/edit_pkg_hier.h:
Update the package hierarchy editor for wide characters.
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 Sat Jul 2 13:00:40 2005
@@ -84,33 +84,37 @@
class silly_treeitem:public vs_treeitem
{
- string txt;
+ wstring txt;
public:
- silly_treeitem(string _txt):txt(_txt) {}
+ silly_treeitem(const wstring &_txt):txt(_txt) {}
+ silly_treeitem(const string &_txt):txt(transcode(_txt)) {}
void paint(vs_tree *win, int y, bool hierarchical, const style &st)
{
vs_treeitem::paint(win, y, hierarchical, txt);
}
- const char *tag() const {return txt.c_str();}
- const char *label() const {return txt.c_str();}
+ const wchar_t *tag() {return txt.c_str();}
+ const wchar_t *label() {return txt.c_str();}
};
class silly_subtree:public vs_subtree_generic
{
- string txt;
+ wstring txt;
public:
- silly_subtree(bool expanded, string _txt)
+ silly_subtree(bool expanded, const wstring &_txt)
:vs_subtree_generic(expanded), txt(_txt) {}
+ silly_subtree(bool expanded, const string &_txt)
+ :vs_subtree_generic(expanded), txt(transcode(_txt)) {}
+
void paint(vs_tree *win, int y, bool hierarchical, const style &st)
{
vs_subtree_generic::paint(win, y, hierarchical, txt);
}
- const char *tag() const {return txt.c_str();}
- const char *label() const {return txt.c_str();}
+ const wchar_t *tag() {return txt.c_str();}
+ const wchar_t *label() {return txt.c_str();}
};
void do_toggle_hierarchical(vs_tree *tree)
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc Sat Jul 2 13:00:40 2005
@@ -13,8 +13,8 @@
set_depth(parent.get_depth());
}
-const char *vs_layout_item::vs_layout_line::tag() const {return "";}
-const char *vs_layout_item::vs_layout_line::label() const {return "";}
+const wchar_t *vs_layout_item::vs_layout_line::tag() {return L"";}
+const wchar_t *vs_layout_item::vs_layout_line::label() {return L"";}
vs_layout_item::levelref::levelref(const levelref &x)
@@ -48,8 +48,8 @@
}
// These don't need to be defined (?)
-const char *vs_layout_item::tag() const {return "";}
-const char *vs_layout_item::label() const {return "";}
+const wchar_t *vs_layout_item::tag() {return L"";}
+const wchar_t *vs_layout_item::label() {return L"";}
int vs_layout_item::get_normal_attr()
{
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h Sat Jul 2 13:00:40 2005
@@ -35,8 +35,8 @@
void paint(vs_tree *win, int y, bool hierarchical,
const style &st);
- const char *tag() const;
- const char *label() const;
+ const wchar_t *tag();
+ const wchar_t *label();
};
// Assumes that children.size()>0
@@ -60,8 +60,8 @@
public:
vs_layout_item(fragment *f);
- const char *tag() const;
- const char *label() const;
+ const wchar_t *tag();
+ const wchar_t *label();
/** Paints the nth line of this item at the given location in 'win'. */
void paint_line(int n,
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_staticitem.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_staticitem.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_staticitem.h Sat Jul 2 13:00:40 2005
@@ -1,6 +1,6 @@
// vs_staticitem.h -*-c++-*-
//
-// Copyright 2000 Daniel Burrows
+// Copyright 2000, 2001, 2005 Daniel Burrows
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -26,13 +26,13 @@
class vs_staticitem:public vs_treeitem
{
- std::string name,value;
+ std::wstring name,value;
public:
- vs_staticitem(std::string _name, std::string _value)
+ vs_staticitem(std::wstring _name, std::wstring _value)
:vs_treeitem(false),name(_name),value(_value) {}
void paint(vs_tree *win, int y, bool hierarchical);
- const char *tag() const {return value.c_str();}
- const char *label() const {return value.c_str();}
+ const wchar_t *tag() const {return value.c_str();}
+ const wchar_t *label() const {return value.c_str();}
};
#endif
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_subtree.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_subtree.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_subtree.h Sat Jul 2 13:00:40 2005
@@ -96,36 +96,54 @@
}
void paint(vs_tree *win, int y, bool hierarchical,
- const std::string &str, int depth_shift=2)
+ const std::wstring &str, int depth_shift=2)
{
int width, height;
int basex=hierarchical?depth_shift*get_depth():0;
win->getmaxyx(height,width);
win->move(y,0);
- for(int i=0; i<basex && i<width; i++)
- win->addch(' ');
+
+ int x=0;
+ while(x<basex && x<width)
+ {
+ win->add_wch(L' ');
+ x+=wcwidth(L' ');
+ }
if(basex>width)
return;
+ const wchar_t *ws;
if(hierarchical)
- win->addnstr(get_expanded()?"--\\ ":"--- ", width-basex);
+ ws=get_expanded()?L"--\\ ":L"--- ";
else
- win->addnstr("-> ", width-basex);
+ ws=L"-> ";
+
+ while(*ws!=0 && x<width)
+ {
+ win->add_wch(*ws);
+ ++ws;
+ }
- if(basex+(hierarchical?4:3)>width)
+ if(x>=width)
return;
- win->addnstr(str.c_str(), width-(basex+(hierarchical?4:3)));
+ size_t i=0;
+ while(i<str.size() && x<width)
+ {
+ wchar_t ch=str[i];
- int newy,newx;
- win->getyx(newy,newx);
+ win->add_wch(ch);
+ x+=wcwidth(ch);
+ ++i;
+ }
- if(newy==y)
- // Eek! If we overflow on that last addnstr, newy will advance!!
- for( ; newx<width; newx++)
- win->addch(' ');
+ while(x<width)
+ {
+ win->add_wch(L' ');
+ x+=wcwidth(L' ');
+ }
}
void set_depth(int _depth)
@@ -146,7 +164,7 @@
// Adds a new child item at an unspecified location -- you should call sort()
// after adding children or the tree will have an undetermined order. (yes,
// you can deduce the real order. Don't.)
- void sort(const sortpolicy &sort_method)
+ void sort(sortpolicy &sort_method)
{
for(child_iterator i=children.begin(); i!=children.end(); i++)
(*i)->sort(sort_method);
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc Sat Jul 2 13:00:40 2005
@@ -23,6 +23,9 @@
#include "vs_editline.h"
#include "config/keybindings.h"
#include "config/colors.h"
+#include "transcode.h"
+
+#include "../aptitude.h" // For _()
#include <sigc++/functors/ptr_fun.h>
@@ -773,7 +776,7 @@
if(!hierarchical && y<height)
{
- string todisp="";
+ wstring todisp;
// Uh...I'd rather use the iterators to do this..
flat_frame *curr=prev_level;
@@ -782,17 +785,17 @@
if(todisp.empty())
todisp=curr->selected->label()+todisp;
else
- todisp=curr->selected->label()+("::"+todisp);
+ todisp=curr->selected->label()+(L"::"+todisp);
curr=curr->next;
}
if(todisp.empty())
- todisp="TOP LEVEL";
+ todisp=transcode(_("TOP LEVEL"));
while(todisp.size()<(unsigned) width)
- todisp+=" ";
+ todisp+=L" ";
- apply_style(st+get_style("ScreenHeader"));
+ apply_style(st+get_style("Header"));
mvaddnstr(y, 0, todisp.c_str(), width);
++y;
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.cc Sat Jul 2 13:00:40 2005
@@ -14,24 +14,37 @@
}
void vs_treeitem::paint(vs_tree *win, int y, bool hierarchical,
- const string &str, int depth_shift)
+ const wstring &str, int depth_shift)
{
int width, height;
int basex=hierarchical?depth_shift*get_depth():0;
win->getmaxyx(height,width);
win->move(y,0);
- for(int i=0; i<basex && i<width; i++)
- win->addch(' ');
+ int x=0;
- if(basex>width)
- return;
-
- win->addnstr(str.c_str(), width-basex-1);
+ while(x<basex && x<width)
+ {
+ win->add_wch(L' ');
+ x+=wcwidth(L' ');
+ }
- int newy,newx;
- win->getyx(newy,newx);
+ if(x>=width)
+ return;
- for( ; newx<width; newx++)
- win->addch(' ');
+ size_t i=0;
+ while(i<str.size())
+ {
+ wchar_t ch=str[i];
+
+ win->add_wch(ch);
+ x+=wcwidth(ch);
+ ++i;
+ }
+
+ while(x<width)
+ {
+ win->add_wch(L' ');
+ x+=wcwidth(L' ');
+ }
}
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_treeitem.h Sat Jul 2 13:00:40 2005
@@ -131,12 +131,12 @@
* \param st the style with which this item is to be displayed.
*/
void paint(vs_tree *win, int y, bool hierarchical,
- const std::string &str, int depth_shift=2);
+ const std::wstring &str, int depth_shift=2);
- virtual const char *tag() const =0;
+ virtual const wchar_t *tag()=0;
// The tag that this item should be sorted by [for the trivial version of
// the subtree object]
- virtual const char *label() const =0;
+ virtual const wchar_t *label()=0;
// The label to display when this item is "active" in non-hierarchical mode.
int get_depth() {return depth;}
@@ -145,7 +145,7 @@
virtual style get_normal_style() {return style();}
virtual style get_highlight_style() {return get_normal_style()+style_attrs_flip(A_REVERSE);}
- virtual void sort(const sortpolicy &sort_method) {}
+ virtual void sort(sortpolicy &sort_method) {}
// Sorts an item's subtree using the given method.
virtual void sort() {}
@@ -358,8 +358,8 @@
public:
sortpolicy() {}
- virtual bool operator()(const vs_treeitem *item1,
- const vs_treeitem *item2) const=0;
+ virtual bool operator()(vs_treeitem *item1,
+ vs_treeitem *item2)=0;
virtual ~sortpolicy() {}
};
@@ -369,9 +369,9 @@
class tag_sort_policy:public sortpolicy
{
public:
- bool operator()(const vs_treeitem *item1, const vs_treeitem *item2) const
+ bool operator()(vs_treeitem *item1, vs_treeitem *item2)
{
- return (strcmp(item1->tag(), item2->tag())<0);
+ return (wcscmp(item1->tag(), item2->tag())<0);
}
};
@@ -382,14 +382,14 @@
// we can get around that with an inline wrapper:
class sortpolicy_wrapper
{
- const sortpolicy &real_policy;
+ sortpolicy &real_policy;
public:
- sortpolicy_wrapper(const sortpolicy &_real_policy):real_policy(_real_policy)
+ sortpolicy_wrapper(sortpolicy &_real_policy):real_policy(_real_policy)
{
}
- inline bool operator()(const vs_treeitem *item1,
- const vs_treeitem *item2) const
+ inline bool operator()(vs_treeitem *item1,
+ vs_treeitem *item2) const
{
return real_policy(item1, item2);
}