[Aptitude-svn-commit] r3465 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Sun, 26 Jun 2005 17:30:53 +0000
Author: dburrows
Date: Sun Jun 26 17:30:51 2005
New Revision: 3465
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.h
Log:
Convert the line-editor to use wide characters.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sun Jun 26 17:30:51 2005
@@ -1,5 +1,11 @@
2005-06-26 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/vs_editline.cc, src/vscreen/vs_editline.h:
+
+ Convert the public interface of the line-editor to wide
+ characters. (this is important since it's the main interface
+ for string input at the moment)
+
* src/vscreen/transcode.h:
Add inline convenience functions to "directly" go from
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.cc Sun Jun 26 17:30:51 2005
@@ -3,8 +3,10 @@
// Copyright 2000 Daniel Burrows
#include "vs_editline.h"
-#include "config/keybindings.h"
+
#include "config/colors.h"
+#include "config/keybindings.h"
+#include "transcode.h"
#include "vscreen.h"
#include <sigc++/functors/mem_fun.h>
@@ -15,7 +17,24 @@
vs_editline::vs_editline(string _prompt, string _text,
history_list *_history)
- :vscreen_widget(),prompt(_prompt), text(_text), curloc(_text.size()),
+ :vscreen_widget(), curloc(_text.size()),
+ startloc(0), desired_size(-1), history(_history),
+ history_loc(0), using_history(false)
+{
+ // Just spew a partial/null string if errors happen for now.
+ transcode(_prompt.c_str(), prompt);
+ transcode(_text.c_str(), text);
+
+ set_bg_style(get_style("EditLine"));
+
+ // This ensures that the cursor is set to the right location when the
+ // widget is displayed or resized:
+ do_layout.connect(sigc::mem_fun(*this, &vs_editline::normalize_cursor));
+}
+
+vs_editline::vs_editline(wstring _prompt, wstring _text,
+ history_list *_history)
+ :vscreen_widget(), prompt(_prompt), text(_text), curloc(_text.size()),
startloc(0), desired_size(-1), history(_history),
history_loc(0), using_history(false)
{
@@ -28,7 +47,21 @@
vs_editline::vs_editline(int maxlength, const string &_prompt,
const string &_text, history_list *_history)
- :vscreen_widget(),prompt(_prompt), text(_text), curloc(0),
+ :vscreen_widget(), curloc(0),
+ startloc(0), desired_size(maxlength), history(_history), history_loc(0),
+ using_history(false)
+{
+ // As above, ignore errors.
+ transcode(_prompt, prompt);
+ transcode(_text, text);
+
+ set_bg_style(get_style("EditLine"));
+ do_layout.connect(sigc::mem_fun(*this, &vs_editline::normalize_cursor));
+}
+
+vs_editline::vs_editline(int maxlength, const wstring &_prompt,
+ const wstring &_text, history_list *_history)
+ :vscreen_widget(), prompt(_prompt), text(_text), curloc(0),
startloc(0), desired_size(maxlength), history(_history), history_loc(0),
using_history(false)
{
@@ -42,7 +75,7 @@
if(get_width()<0)
return;
- string::size_type w=(string::size_type) get_width();
+ wstring::size_type w=(wstring::size_type) get_width();
if(prompt.size()+text.size()+1<w)
startloc=0;
@@ -94,7 +127,7 @@
{
text.erase(--curloc, 1);
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
}
else
@@ -110,7 +143,7 @@
{
text.erase(curloc, 1);
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
}
else
@@ -124,7 +157,7 @@
{
// I create a new string here because otherwise modifications to
// "text" are seen by the widgets! (grr, sigc++)
- entered(string(text));
+ entered(wstring(text));
return true;
}
else if(bindings->key_matches(ch, "Left"))
@@ -176,7 +209,7 @@
{
text.erase(curloc);
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
return true;
}
@@ -185,7 +218,7 @@
text.erase(0, curloc);
curloc=0;
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
return true;
}
@@ -210,7 +243,7 @@
curloc=text.size();
startloc=0;
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
return true;
@@ -225,11 +258,11 @@
using_history=false;
history_loc=0;
text=pre_history_text;
- pre_history_text="";
+ pre_history_text=L"";
curloc=text.size();
startloc=0;
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
// FIXME: store the pre-history edit and restore that.
@@ -243,7 +276,7 @@
curloc=text.size();
startloc=0;
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
return true;
@@ -259,7 +292,7 @@
{
text.insert(curloc++, 1, (char) ch);
normalize_cursor();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
return true;
}
@@ -269,14 +302,14 @@
{
int width=getmaxx();
- string todisp(prompt+text, startloc, width);
+ wstring todisp(prompt+text, startloc, width);
- mvaddstr(0, 0, todisp.c_str());
+ mvaddstr(0, 0, todisp);
}
void vs_editline::dispatch_mouse(short id, int x, int y, int z, mmask_t bstate)
{
- string::size_type mouseloc=x+startloc;
+ wstring::size_type mouseloc=x+startloc;
if(mouseloc>=prompt.size())
{
@@ -293,7 +326,7 @@
vscreen_update();
}
-void vs_editline::add_to_history(std::string s,
+void vs_editline::add_to_history(std::wstring s,
history_list *lst)
{
assert(lst);
@@ -302,7 +335,7 @@
lst->push_back(s);
}
-void vs_editline::add_to_history(std::string s)
+void vs_editline::add_to_history(std::wstring s)
{
if(history)
add_to_history(s, history);
@@ -310,20 +343,27 @@
void vs_editline::reset_history()
{
- pre_history_text="";
+ pre_history_text=L"";
using_history=false;
history_loc=0;
}
-void vs_editline::set_text(string _text)
+void vs_editline::set_text(wstring _text)
{
text=_text;
if(curloc>text.size())
curloc=text.size();
- text_changed(string(text));
+ text_changed(wstring(text));
vscreen_update();
}
+void vs_editline::set_text(string _text)
+{
+ wstring wtext;
+ if(transcode(_text, wtext))
+ set_text(wtext);
+}
+
void vs_editline::init_bindings()
{
bindings=new keybindings(&global_bindings);
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_editline.h Sun Jun 26 17:30:51 2005
@@ -16,16 +16,16 @@
class vs_editline:public vscreen_widget
{
public:
- typedef std::vector<std::string> history_list;
+ typedef std::vector<std::wstring> history_list;
private:
- std::string prompt;
- std::string text;
+ std::wstring prompt;
+ std::wstring text;
- std::string pre_history_text;
+ std::wstring pre_history_text;
// Used as a "virtual" history entry.
- std::string::size_type curloc, startloc;
+ std::wstring::size_type curloc, startloc;
int desired_size;
@@ -41,8 +41,17 @@
protected:
bool handle_char(chtype ch);
public:
+ vs_editline(std::wstring _prompt, std::wstring _text=L"",
+ history_list *history=NULL);
+
+ /** Transcodes its input strings from the system charset. */
vs_editline(std::string _prompt, std::string _text="",
history_list *history=NULL);
+
+ vs_editline(int maxlength, const std::wstring &_prompt,
+ const std::wstring &_text=L"", history_list *history=NULL);
+
+ /** Transcodes its input strings from the system charset. */
vs_editline(int maxlength, const std::string &_prompt,
const std::string &_text="", history_list *history=NULL);
@@ -50,12 +59,17 @@
void paint(const style &st);
void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
- sigc::signal1<void, std::string> entered;
+ sigc::signal1<void, std::wstring> entered;
// Called when the user presses Enter to confirm the text
- sigc::signal1<void, std::string> text_changed;
+ sigc::signal1<void, std::wstring> text_changed;
// Called when the text is altered.
- std::string get_text() {return text;}
+ std::wstring get_text() {return text;}
+ void set_text(std::wstring _text);
+
+ /** Decodes the given multibyte string, and sets the current text
+ * of this edit-line to it.
+ */
void set_text(std::string _text);
bool get_cursorvisible();
@@ -64,11 +78,11 @@
int width_request();
int height_request(int height);
- static void add_to_history(std::string s,
+ static void add_to_history(std::wstring s,
history_list *history);
// Appends the string to the end of the history list (convenience routine)
- void add_to_history(std::string s);
+ void add_to_history(std::wstring s);
void reset_history();
static keybindings *bindings;