make ctrl+v works in lineEdits

master
Eduardo Bart 13 years ago
parent ba8f8b889e
commit 65dca53c0f

@ -25,6 +25,7 @@
#include <framework/global.h> #include <framework/global.h>
//TODO: move the next enums to const.h
enum InputKeyCode { enum InputKeyCode {
KC_UNKNOWN = 0x00, KC_UNKNOWN = 0x00,
KC_ESCAPE = 0x01, KC_ESCAPE = 0x01,
@ -196,6 +197,7 @@ enum PlatformEventType {
EventMouseWheelDown = EventMouseAction | EventMouseWheel | EventDown EventMouseWheelDown = EventMouseAction | EventMouseWheel | EventDown
}; };
//TODO: rework platform events, make more compatible with UI events
struct PlatformEvent { struct PlatformEvent {
int type; int type;
Point mousePos; Point mousePos;

@ -274,8 +274,27 @@ void UILineEdit::setCursorEnabled(bool enable)
update(); update();
} }
void UILineEdit::appendText(std::string text)
{
if(m_cursorPos >= 0) {
// replace characters that are now allowed
boost::replace_all(text, "\n", "");
boost::replace_all(text, "\r", " ");
if(text.length() > 0) {
m_text.insert(m_cursorPos, text);
m_cursorPos += text.length();
blinkCursor();
update();
}
}
}
void UILineEdit::appendCharacter(char c) void UILineEdit::appendCharacter(char c)
{ {
if(c == '\n' || c == '\r')
return;
if(m_cursorPos >= 0) { if(m_cursorPos >= 0) {
std::string tmp; std::string tmp;
tmp = c; tmp = c;
@ -384,6 +403,8 @@ bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
setCursorPos(0); setCursorPos(0);
else if(keyCode == KC_END) // move cursor to last character else if(keyCode == KC_END) // move cursor to last character
setCursorPos(m_text.length()); setCursorPos(m_text.length());
else if(keyCode == KC_V && keyboardModifiers == Fw::KeyboardCtrlModifier)
appendText(g_platform.getClipboardText());
else if(keyCode == KC_TAB) { else if(keyCode == KC_TAB) {
if(UIWidgetPtr parent = getParent()) if(UIWidgetPtr parent = getParent())
parent->focusNextChild(Fw::TabFocusReason); parent->focusNextChild(Fw::TabFocusReason);

@ -41,6 +41,7 @@ public:
void clearText() { setText(""); } void clearText() { setText(""); }
void moveCursor(bool right); void moveCursor(bool right);
void appendText(std::string text);
void appendCharacter(char c); void appendCharacter(char c);
void removeCharacter(bool right); void removeCharacter(bool right);

@ -27,6 +27,9 @@
namespace Otc namespace Otc
{ {
static const char* AppName = "OTClient";
static const char* AppVersion = "0.4.0";
static const char* CipsoftPublicRSA = "1321277432058722840622950990822933849527763264961655079678763618" static const char* CipsoftPublicRSA = "1321277432058722840622950990822933849527763264961655079678763618"
"4334395343554449668205332383339435179772895415509701210392836078" "4334395343554449668205332383339435179772895415509701210392836078"
"6959821132214473291575712138800495033169914814069637740318278150" "6959821132214473291575712138800495033169914814069637740318278150"

@ -46,10 +46,10 @@ void OTClient::init(std::vector<std::string> args)
m_stopping = false; m_stopping = false;
// print client information // print client information
logInfo("OTClient 0.2.0"); logInfo(Otc::AppName, " ", Otc::AppVersion);
// initialize platform related stuff // initialize platform related stuff
g_platform.init(this, "OTClient"); g_platform.init(this, Otc::AppName);
// initialize script environment // initialize script environment
g_lua.init(); g_lua.init();
@ -72,7 +72,7 @@ void OTClient::init(std::vector<std::string> args)
int windowHeight = Fw::fromstring(g_configs.get("window height"), minHeight); int windowHeight = Fw::fromstring(g_configs.get("window height"), minHeight);
bool maximized = Fw::fromstring(g_configs.get("window maximized"), false); bool maximized = Fw::fromstring(g_configs.get("window maximized"), false);
g_platform.createWindow(windowX, windowY, windowWidth, windowHeight, minWidth, minHeight, maximized); g_platform.createWindow(windowX, windowY, windowWidth, windowHeight, minWidth, minHeight, maximized);
g_platform.setWindowTitle("OTClient"); g_platform.setWindowTitle(Otc::AppName);
// initialize graphics // initialize graphics
g_graphics.init(); g_graphics.init();

Loading…
Cancel
Save