Work on an input field.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@272 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-13 21:47:26 +00:00
parent aec27deaeb
commit 73b1c58f4c
19 changed files with 313 additions and 25 deletions
+3 -1
View File
@@ -4,6 +4,8 @@ libsub_input_a_SOURCES = \
bindings.cc \
bindings.h \
manager.cc \
manager.h
manager.h \
text_input.cc \
text_input.h
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
+4
View File
@@ -6,6 +6,7 @@
#include "manager.h"
#include "bindings.h"
#include "text_input.h"
namespace input {
@@ -21,6 +22,9 @@ Manager::erase(Bindings* b) {
void
Manager::pressed(int key) {
if (m_textInput != NULL && m_textInput->pressed(key))
return;
std::find_if(begin(), end(), std::bind2nd(std::mem_fun(&Bindings::pressed), key));
}
+8
View File
@@ -6,6 +6,7 @@
namespace input {
class Bindings;
class TextInput;
class Manager : private std::list<Bindings*> {
public:
@@ -24,11 +25,18 @@ public:
using Base::push_back;
using Base::push_front;
Manager() : m_textInput(NULL) {}
void erase(Bindings* b);
void pressed(int key);
void set_text_input(TextInput* input = NULL) { m_textInput = input; }
// Slot for unreacted keys.
private:
TextInput* m_textInput;
};
}
+79
View File
@@ -0,0 +1,79 @@
#include "config.h"
#include <ncurses.h>
#include "text_input.h"
#include <sstream>
namespace input {
bool
TextInput::pressed(int key) {
if (m_alt) {
m_alt = false;
switch (key) {
case 'p':
Base::insert(m_pos, "M^p");
break;
default:
return false;
}
} else if (key >= 0x20 && key < 0x7F) {
Base::insert(m_pos++, 1, key);
} else {
switch (key) {
case KEY_BACKSPACE:
if (m_pos != 0)
Base::erase(--m_pos, 1);
break;
case KEY_DC:
if (m_pos != size())
Base::erase(m_pos, 1);
break;
case KEY_LEFT:
case 0x10:
if (m_pos != 0)
--m_pos;
break;
case KEY_RIGHT:
case 0x0E:
if (m_pos != size())
++m_pos;
break;
default:
return false;
}
}
m_slotDirty();
return true;
// Testcode.
// if (key == KEY_ENTER || key == '\n')
// return false;
// std::stringstream str;
// str << "\\x" << std::hex << key;
// Base::insert(m_pos, str.str());
// m_pos += str.str().length();
// return true;
}
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef RTORRENT_INPUT_TEXT_INPUT_H
#define RTORRENT_INPUT_TEXT_INPUT_H
#include <string>
#include <sigc++/slot.h>
namespace input {
class TextInput : private std::string {
public:
typedef std::string Base;
typedef sigc::slot0<void> SlotDirty;
using Base::c_str;
using Base::empty;
using Base::size;
TextInput() : m_pos(0), m_alt(false) {}
size_type get_pos() { return m_pos; }
bool pressed(int key);
void clear() { m_pos = 0; m_alt = false; Base::clear(); }
void slot_dirty(SlotDirty s) { m_slotDirty = s; }
private:
size_type m_pos;
bool m_alt;
SlotDirty m_slotDirty;
};
}
#endif