summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-19 23:48:29 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-19 23:48:29 +0300
commit0b7e752bd177c90a05ca752fa31810f9e34c432c (patch)
treedb1809a48faf051af11c94058e8f126c9e9ef1ab /src/gui/widgets
parent23f87c10db7e6b149e9e1f351e1a82516c545df7 (diff)
downloadplus-0b7e752bd177c90a05ca752fa31810f9e34c432c.tar.gz
plus-0b7e752bd177c90a05ca752fa31810f9e34c432c.tar.bz2
plus-0b7e752bd177c90a05ca752fa31810f9e34c432c.tar.xz
plus-0b7e752bd177c90a05ca752fa31810f9e34c432c.zip
Dehardcode keys in gui widgets.
Add new tab with keys settings in input settings tab.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/button.cpp10
-rw-r--r--src/gui/widgets/checkbox.cpp7
-rw-r--r--src/gui/widgets/dropdown.cpp48
-rw-r--r--src/gui/widgets/guitable.cpp18
-rw-r--r--src/gui/widgets/inttextfield.cpp10
-rw-r--r--src/gui/widgets/itemcontainer.cpp35
-rw-r--r--src/gui/widgets/listbox.cpp16
-rw-r--r--src/gui/widgets/radiobutton.cpp7
-rw-r--r--src/gui/widgets/slider.cpp12
-rw-r--r--src/gui/widgets/tabbedarea.cpp19
-rw-r--r--src/gui/widgets/textbox.cpp259
-rw-r--r--src/gui/widgets/textfield.cpp130
12 files changed, 336 insertions, 235 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 88d9311b9..15af963b0 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -26,6 +26,8 @@
#include "configuration.h"
#include "graphics.h"
#include "graphicsvertexes.h"
+#include "keydata.h"
+#include "keyevent.h"
#include "logger.h"
#include "gui/palette.h"
@@ -462,9 +464,9 @@ void Button::setCaption(const std::string& caption)
void Button::keyPressed(gcn::KeyEvent& keyEvent)
{
- gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
- if (key.getValue() == gcn::Key::SPACE)
+ if (action == Input::KEY_GUI_SELECT)
{
mKeyPressed = true;
keyEvent.consume();
@@ -473,9 +475,9 @@ void Button::keyPressed(gcn::KeyEvent& keyEvent)
void Button::keyReleased(gcn::KeyEvent& keyEvent)
{
- gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
- if (key.getValue() == gcn::Key::SPACE && mKeyPressed)
+ if (action == Input::KEY_GUI_SELECT && mKeyPressed)
{
mKeyPressed = false;
if (mStick)
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index f599e7831..133a5da1d 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -25,6 +25,8 @@
#include "client.h"
#include "configuration.h"
#include "graphics.h"
+#include "keydata.h"
+#include "keyevent.h"
#include "gui/palette.h"
#include "gui/theme.h"
@@ -193,10 +195,9 @@ void CheckBox::mouseExited(gcn::MouseEvent& event A_UNUSED)
void CheckBox::keyPressed(gcn::KeyEvent& keyEvent)
{
- gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
- if (key.getValue() == gcn::Key::ENTER ||
- key.getValue() == gcn::Key::SPACE)
+ if (action == Input::KEY_GUI_SELECT)
{
toggleSelected();
keyEvent.consume();
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 91c983f26..5ecfba84d 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -25,6 +25,8 @@
#include "client.h"
#include "configuration.h"
#include "graphics.h"
+#include "keydata.h"
+#include "keyevent.h"
#include "gui/palette.h"
#include "gui/sdlinput.h"
@@ -233,20 +235,38 @@ void DropDown::keyPressed(gcn::KeyEvent& keyEvent)
if (keyEvent.isConsumed())
return;
- gcn::Key key = keyEvent.getKey();
-
- if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
- dropDown();
- else if (key.getValue() == Key::UP)
- setSelected(getSelected() - 1);
- else if (key.getValue() == Key::DOWN)
- setSelected(getSelected() + 1);
- else if (key.getValue() == Key::HOME)
- setSelected(0);
- else if (key.getValue() == Key::END && mListBox->getListModel())
- setSelected(mListBox->getListModel()->getNumberOfElements() - 1);
- else
- return;
+ int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+
+ switch(actionId)
+ {
+ case Input::KEY_GUI_SELECT:
+ case Input::KEY_GUI_SELECT2:
+ dropDown();
+ break;
+
+ case Input::KEY_GUI_UP:
+ setSelected(getSelected() - 1);
+ break;
+
+ case Input::KEY_GUI_DOWN:
+ setSelected(getSelected() + 1);
+ break;
+
+ case Input::KEY_GUI_HOME:
+ setSelected(0);
+ break;
+
+ case Input::KEY_GUI_END:
+ if (mListBox->getListModel())
+ {
+ setSelected(mListBox->getListModel()->
+ getNumberOfElements() - 1);
+ }
+ break;
+
+ default:
+ return;
+ }
keyEvent.consume();
}
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index 6434f5453..910ee1910 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -24,6 +24,8 @@
#include "client.h"
#include "configuration.h"
+#include "keyevent.h"
+#include "keydata.h"
#include "gui/sdlinput.h"
#include "gui/theme.h"
@@ -403,40 +405,40 @@ gcn::Rectangle GuiTable::getChildrenArea()
// -- KeyListener notifications
void GuiTable::keyPressed(gcn::KeyEvent& keyEvent)
{
- gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
- if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
+ if (action == Input::KEY_GUI_SELECT)
{
distributeActionEvent();
keyEvent.consume();
}
- else if (key.getValue() == Key::UP)
+ else if (action == Input::KEY_GUI_UP)
{
setSelectedRow(mSelectedRow - 1);
keyEvent.consume();
}
- else if (key.getValue() == Key::DOWN)
+ else if (action == Input::KEY_GUI_DOWN)
{
setSelectedRow(mSelectedRow + 1);
keyEvent.consume();
}
- else if (key.getValue() == Key::LEFT)
+ else if (action == Input::KEY_GUI_LEFT)
{
setSelectedColumn(mSelectedColumn - 1);
keyEvent.consume();
}
- else if (key.getValue() == Key::RIGHT)
+ else if (action == Input::KEY_GUI_RIGHT)
{
setSelectedColumn(mSelectedColumn + 1);
keyEvent.consume();
}
- else if (key.getValue() == Key::HOME)
+ else if (action == Input::KEY_GUI_HOME)
{
setSelectedRow(0);
setSelectedColumn(0);
keyEvent.consume();
}
- else if (key.getValue() == Key::END && mModel)
+ else if (action == Input::KEY_GUI_END && mModel)
{
setSelectedRow(mModel->getRows() - 1);
setSelectedColumn(mModel->getColumns() - 1);
diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp
index 8a075000b..fbc51ee3d 100644
--- a/src/gui/widgets/inttextfield.cpp
+++ b/src/gui/widgets/inttextfield.cpp
@@ -22,6 +22,9 @@
#include "gui/widgets/inttextfield.h"
+#include "keydata.h"
+#include "keyevent.h"
+
#include "gui/sdlinput.h"
#include "utils/stringutils.h"
@@ -44,10 +47,9 @@ IntTextField::IntTextField(int def, int min, int max,
void IntTextField::keyPressed(gcn::KeyEvent &event)
{
- const gcn::Key &key = event.getKey();
+ int action = static_cast<KeyEvent*>(&event)->getActionId();
- if (key.getValue() == Key::BACKSPACE ||
- key.getValue() == Key::DELETE)
+ if (action == Input::KEY_GUI_DELETE || action == Input::KEY_GUI_BACKSPACE)
{
setText(std::string());
if (mSendAlwaysEvents)
@@ -56,7 +58,7 @@ void IntTextField::keyPressed(gcn::KeyEvent &event)
event.consume();
}
- if (!key.isNumber())
+ if (!event.getKey().isNumber())
return;
TextField::keyPressed(event);
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 6438f5deb..0aabcd297 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -337,45 +337,10 @@ void ItemContainer::hidePopup()
void ItemContainer::keyPressed(gcn::KeyEvent &event A_UNUSED)
{
- /*switch (event.getKey().getValue())
- {
- case Key::LEFT:
- moveHighlight(Left);
- break;
- case Key::RIGHT:
- moveHighlight(Right);
- break;
- case Key::UP:
- moveHighlight(Up);
- break;
- case Key::DOWN:
- moveHighlight(Down);
- break;
- case Key::SPACE:
- keyAction();
- break;
- case Key::LEFT_ALT:
- case Key::RIGHT_ALT:
- mSwapItems = true;
- break;
- case Key::RIGHT_CONTROL:
- mDescItems = true;
- break;
- }*/
}
void ItemContainer::keyReleased(gcn::KeyEvent &event A_UNUSED)
{
- /*switch (event.getKey().getValue())
- {
- case Key::LEFT_ALT:
- case Key::RIGHT_ALT:
- mSwapItems = false;
- break;
- case Key::RIGHT_CONTROL:
- mDescItems = false;
- break;
- }*/
}
void ItemContainer::mousePressed(gcn::MouseEvent &event)
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 2944c5be6..267f2c8cc 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -24,6 +24,8 @@
#include "client.h"
#include "configuration.h"
+#include "keyevent.h"
+#include "keydata.h"
#include "gui/palette.h"
#include "gui/sdlinput.h"
@@ -88,16 +90,16 @@ void ListBox::draw(gcn::Graphics *graphics)
}
}
-void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
+void ListBox::keyPressed(gcn::KeyEvent &keyEvent)
{
- gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
- if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
+ if (action == Input::KEY_GUI_SELECT)
{
distributeActionEvent();
keyEvent.consume();
}
- else if (key.getValue() == Key::UP)
+ else if (action == Input::KEY_GUI_UP)
{
if (getSelected() > 0)
setSelected(mSelected - 1);
@@ -105,7 +107,7 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
setSelected(getListModel()->getNumberOfElements() - 1);
keyEvent.consume();
}
- else if (key.getValue() == Key::DOWN)
+ else if (action == Input::KEY_GUI_DOWN)
{
if (getSelected() < (getListModel()->getNumberOfElements() - 1))
{
@@ -118,12 +120,12 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
}
keyEvent.consume();
}
- else if (key.getValue() == Key::HOME)
+ else if (action == Input::KEY_GUI_HOME)
{
setSelected(0);
keyEvent.consume();
}
- else if (key.getValue() == Key::END && getListModel())
+ else if (action == Input::KEY_GUI_END && getListModel())
{
setSelected(getListModel()->getNumberOfElements() - 1);
keyEvent.consume();
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index 4a9a912b1..e2a3483fc 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -25,6 +25,8 @@
#include "client.h"
#include "configuration.h"
#include "graphics.h"
+#include "keydata.h"
+#include "keyevent.h"
#include "gui/theme.h"
@@ -161,10 +163,9 @@ void RadioButton::mouseExited(gcn::MouseEvent& event A_UNUSED)
void RadioButton::keyPressed(gcn::KeyEvent& keyEvent)
{
- gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
- if (key.getValue() == gcn::Key::ENTER ||
- key.getValue() == gcn::Key::SPACE)
+ if (action == Input::KEY_GUI_SELECT)
{
setSelected(true);
distributeActionEvent();
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
index 24a2a5128..69df4c289 100644
--- a/src/gui/widgets/slider.cpp
+++ b/src/gui/widgets/slider.cpp
@@ -25,6 +25,8 @@
#include "client.h"
#include "configuration.h"
#include "graphics.h"
+#include "keyevent.h"
+#include "keydata.h"
#include "gui/theme.h"
@@ -300,17 +302,17 @@ void Slider::mouseExited(gcn::MouseEvent& event A_UNUSED)
void Slider::keyPressed(gcn::KeyEvent& keyEvent)
{
- gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
if (getOrientation() == HORIZONTAL)
{
- if (key.getValue() == gcn::Key::RIGHT)
+ if (action == Input::KEY_GUI_RIGHT)
{
setValue(getValue() + getStepLength());
distributeActionEvent();
keyEvent.consume();
}
- else if (key.getValue() == gcn::Key::LEFT)
+ else if (action == Input::KEY_GUI_LEFT)
{
setValue(getValue() - getStepLength());
distributeActionEvent();
@@ -319,13 +321,13 @@ void Slider::keyPressed(gcn::KeyEvent& keyEvent)
}
else
{
- if (key.getValue() == gcn::Key::UP)
+ if (action == Input::KEY_GUI_UP)
{
setValue(getValue() + getStepLength());
distributeActionEvent();
keyEvent.consume();
}
- else if (key.getValue() == gcn::Key::DOWN)
+ else if (action == Input::KEY_GUI_DOWN)
{
setValue(getValue() - getStepLength());
distributeActionEvent();
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index bb8ea063b..b24ae32e5 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -22,6 +22,9 @@
#include "gui/widgets/tabbedarea.h"
+#include "keydata.h"
+#include "keyevent.h"
+
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tab.h"
@@ -482,7 +485,9 @@ void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent)
if (keyEvent.isConsumed() || !isFocused())
return;
- if (keyEvent.getKey().getValue() == gcn::Key::LEFT)
+ int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+
+ if (actionId == Input::KEY_GUI_LEFT)
{
int index = getSelectedTabIndex();
index--;
@@ -494,7 +499,7 @@ void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent)
keyEvent.consume();
}
- else if (keyEvent.getKey().getValue() == gcn::Key::RIGHT)
+ else if (actionId == Input::KEY_GUI_RIGHT)
{
int index = getSelectedTabIndex();
index++;
@@ -507,13 +512,3 @@ void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent)
keyEvent.consume();
}
}
-
-/*
-void TabbedArea::moveLeft(gcn::Tab *tab)
-{
-}
-
-void TabbedArea::moveRight(gcn::Tab *tab)
-{
-}
-*/
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index 3f3c9fb9e..b40a7dcb1 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -22,6 +22,9 @@
#include "gui/widgets/textbox.h"
+#include "keydata.h"
+#include "keyevent.h"
+
#include "gui/theme.h"
#include <guichan/font.hpp>
@@ -156,144 +159,176 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
{
gcn::Key key = keyEvent.getKey();
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
- if (key.getValue() == gcn::Key::LEFT)
+ switch (action)
{
- --mCaretColumn;
- if (mCaretColumn < 0)
+ case Input::KEY_GUI_LEFT:
+ {
+ --mCaretColumn;
+ if (mCaretColumn < 0)
+ {
+ --mCaretRow;
+
+ if (mCaretRow < 0)
+ {
+ mCaretRow = 0;
+ mCaretColumn = 0;
+ }
+ else
+ {
+ mCaretColumn = mTextRows[mCaretRow].size();
+ }
+ }
+ break;
+ }
+
+ case Input::KEY_GUI_RIGHT:
+ {
+ ++mCaretColumn;
+ if (mCaretColumn > static_cast<int>(mTextRows[mCaretRow].size()))
+ {
+ ++ mCaretRow;
+
+ if (mCaretRow >= static_cast<int>(mTextRows.size()))
+ {
+ mCaretRow = mTextRows.size() - 1;
+ if (mCaretRow < 0)
+ mCaretRow = 0;
+
+ mCaretColumn = mTextRows[mCaretRow].size();
+ }
+ else
+ {
+ mCaretColumn = 0;
+ }
+ }
+ break;
+ }
+
+ case Input::KEY_GUI_DOWN:
+ {
+ setCaretRow(mCaretRow + 1);
+ break;
+ }
+ case Input::KEY_GUI_UP:
+ {
+ setCaretRow(mCaretRow - 1);
+ break;
+ }
+ case Input::KEY_GUI_HOME:
+ {
+ mCaretColumn = 0;
+ break;
+ }
+ case Input::KEY_GUI_END:
{
- --mCaretRow;
+ mCaretColumn = mTextRows[mCaretRow].size();
+ break;
+ }
- if (mCaretRow < 0)
+ case Input::KEY_GUI_SELECT2:
+ {
+ if (mEditable)
{
- mCaretRow = 0;
+ mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
+ mTextRows[mCaretRow].substr(mCaretColumn,
+ mTextRows[mCaretRow].size() - mCaretColumn));
+ mTextRows[mCaretRow].resize(mCaretColumn);
+ ++mCaretRow;
mCaretColumn = 0;
}
- else
+ break;
+ }
+
+ case Input::KEY_GUI_BACKSPACE:
+ {
+ if (mCaretColumn != 0 && mEditable)
{
- mCaretColumn = mTextRows[mCaretRow].size();
+ mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
+ --mCaretColumn;
}
+ else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable)
+ {
+ mCaretColumn = mTextRows[mCaretRow - 1].size();
+ mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
+ mTextRows.erase(mTextRows.begin() + mCaretRow);
+ --mCaretRow;
+ }
+ break;
}
- }
- else if (key.getValue() == gcn::Key::RIGHT)
- {
- ++mCaretColumn;
- if (mCaretColumn > static_cast<int>(mTextRows[mCaretRow].size()))
+
+ case Input::KEY_GUI_DELETE:
{
- ++ mCaretRow;
+ if (mCaretColumn < static_cast<int>(
+ mTextRows[mCaretRow].size()) && mEditable)
+ {
+ mTextRows[mCaretRow].erase(mCaretColumn, 1);
+ }
+ else if (mCaretColumn == static_cast<int>(
+ mTextRows[mCaretRow].size()) &&
+ mCaretRow < (static_cast<int>(mTextRows.size()) - 1) &&
+ mEditable)
+ {
+ mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
+ mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
+ }
+ break;
+ }
+
+ case Input::KEY_GUI_PAGE_UP:
+ {
+ gcn::Widget* par = getParent();
- if (mCaretRow >= static_cast<int>(mTextRows.size()))
+ if (par)
{
- mCaretRow = mTextRows.size() - 1;
+ int rowsPerPage = par->getChildrenArea().height
+ / getFont()->getHeight();
+ mCaretRow -= rowsPerPage;
+
if (mCaretRow < 0)
mCaretRow = 0;
-
- mCaretColumn = mTextRows[mCaretRow].size();
- }
- else
- {
- mCaretColumn = 0;
}
+ break;
}
- }
- else if (key.getValue() == gcn::Key::DOWN)
- {
- setCaretRow(mCaretRow + 1);
- }
- else if (key.getValue() == gcn::Key::UP)
- {
- setCaretRow(mCaretRow - 1);
- }
- else if (key.getValue() == gcn::Key::HOME)
- {
- mCaretColumn = 0;
- }
- else if (key.getValue() == gcn::Key::END)
- {
- mCaretColumn = mTextRows[mCaretRow].size();
- }
- else if (key.getValue() == gcn::Key::ENTER && mEditable)
- {
- mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
- mTextRows[mCaretRow].substr(mCaretColumn,
- mTextRows[mCaretRow].size() - mCaretColumn));
- mTextRows[mCaretRow].resize(mCaretColumn);
- ++mCaretRow;
- mCaretColumn = 0;
- }
- else if (key.getValue() == gcn::Key::BACKSPACE
- && mCaretColumn != 0
- && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
- --mCaretColumn;
- }
- else if (key.getValue() == gcn::Key::BACKSPACE
- && mCaretColumn == 0
- && mCaretRow != 0
- && mEditable)
- {
- mCaretColumn = mTextRows[mCaretRow - 1].size();
- mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
- mTextRows.erase(mTextRows.begin() + mCaretRow);
- --mCaretRow;
- }
- else if (key.getValue() == gcn::Key::DELETE
- && mCaretColumn < static_cast<int>(
- mTextRows[mCaretRow].size()) && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn, 1);
- }
- else if (key.getValue() == gcn::Key::DELETE
- && mCaretColumn == static_cast<int>(
- mTextRows[mCaretRow].size())
- && mCaretRow < (static_cast<int>(mTextRows.size()) - 1)
- && mEditable)
- {
- mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
- mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
- }
- else if (key.getValue() == gcn::Key::PAGE_UP)
- {
- gcn::Widget* par = getParent();
- if (par)
+ case Input::KEY_GUI_PAGE_DOWN:
{
- int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow -= rowsPerPage;
+ gcn::Widget* par = getParent();
+
+ if (par)
+ {
+ int rowsPerPage = par->getChildrenArea().height
+ / getFont()->getHeight();
+ mCaretRow += rowsPerPage;
- if (mCaretRow < 0)
- mCaretRow = 0;
+ if (mCaretRow >= static_cast<int>(mTextRows.size()))
+ mCaretRow = mTextRows.size() - 1;
+ }
+ break;
}
- }
- else if (key.getValue() == gcn::Key::PAGE_DOWN)
- {
- gcn::Widget* par = getParent();
- if (par)
+ case Input::KEY_GUI_TAB:
{
- int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow += rowsPerPage;
+ if (mEditable)
+ {
+ mTextRows[mCaretRow].insert(mCaretColumn, std::string(" "));
+ mCaretColumn += 4;
+ }
+ break;
+ }
- if (mCaretRow >= static_cast<int>(mTextRows.size()))
- mCaretRow = mTextRows.size() - 1;
+ default:
+ {
+ if (key.isCharacter() && mEditable)
+ {
+ mTextRows[mCaretRow].insert(mCaretColumn,
+ std::string(1, static_cast<char>(key.getValue())));
+ ++ mCaretColumn;
+ }
+ break;
}
}
- else if (key.getValue() == gcn::Key::TAB
- && mEditable)
- {
- mTextRows[mCaretRow].insert(mCaretColumn, std::string(" "));
- mCaretColumn += 4;
- }
- else if (key.isCharacter()
- && mEditable)
- {
- mTextRows[mCaretRow].insert(mCaretColumn,
- std::string(1, static_cast<char>(key.getValue())));
- ++ mCaretColumn;
- }
adjustSize();
scrollToCaret();
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 7892b3c0d..99cc93fd1 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -25,6 +25,8 @@
#include "client.h"
#include "configuration.h"
#include "graphics.h"
+#include "keyevent.h"
+#include "keydata.h"
#include "logger.h"
#include "gui/palette.h"
@@ -241,10 +243,10 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
if (val != 22)
mLastEventPaste = 0;
+ bool consumed(false);
switch (val)
{
case 2: // Ctrl+b
- case Key::LEFT:
{
while (mCaretPosition > 0)
{
@@ -252,10 +254,11 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
if ((mText[mCaretPosition] & 192) != 128)
break;
}
- } break;
+ consumed = true;
+ break;
+ }
case 6: // Ctrl+f
- case Key::RIGHT:
{
unsigned sz = static_cast<unsigned>(mText.size());
while (mCaretPosition < sz)
@@ -267,10 +270,11 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
break;
}
}
- } break;
+ consumed = true;
+ break;
+ }
case 4: // Ctrl+d
- case Key::DELETE:
{
unsigned sz = static_cast<unsigned>(mText.size());
while (mCaretPosition < sz)
@@ -283,41 +287,24 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
break;
}
}
- } break;
+ consumed = true;
+ break;
+ }
case 8: // Ctrl+h
- case Key::BACKSPACE:
deleteCharLeft(mText, &mCaretPosition);
- break;
-
- case Key::ENTER:
- distributeActionEvent();
- keyEvent.consume();
- fixScroll();
- return;
-
- case Key::HOME:
- mCaretPosition = 0;
- break;
-
- case Key::END:
- mCaretPosition = static_cast<unsigned>(mText.size());
- break;
-
- case Key::TAB:
- if (mLoseFocusOnTab)
- return;
+ consumed = true;
break;
case 5: // Ctrl+e
mCaretPosition = mText.size();
+ consumed = true;
break;
case 11: // Ctrl+k
mText = mText.substr(0, mCaretPosition);
+ consumed = true;
break;
-// case 16: // Ctrl+p
-// break;
case 21: // Ctrl+u
if (mCaretPosition > 0)
@@ -325,10 +312,12 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
mText = mText.substr(mCaretPosition);
mCaretPosition = 0;
}
+ consumed = true;
break;
case 3:
handleCopy();
+ consumed = true;
break;
case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v
@@ -337,6 +326,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
break;
handlePaste();
mLastEventPaste = cur_time + 2;
+ consumed = true;
break;
case 23: // Ctrl+w
@@ -349,6 +339,90 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
break;
}
}
+ consumed = true;
+ break;
+
+ default:
+ break;
+ }
+
+ if (consumed)
+ {
+ if (mSendAlwaysEvents)
+ distributeActionEvent();
+
+ keyEvent.consume();
+ fixScroll();
+ return;
+ }
+
+ int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+
+ switch (action)
+ {
+ case Input::KEY_GUI_LEFT:
+ {
+ while (mCaretPosition > 0)
+ {
+ --mCaretPosition;
+ if ((mText[mCaretPosition] & 192) != 128)
+ break;
+ }
+ break;
+ }
+
+ case Input::KEY_GUI_RIGHT:
+ {
+ unsigned sz = static_cast<unsigned>(mText.size());
+ while (mCaretPosition < sz)
+ {
+ ++mCaretPosition;
+ if (mCaretPosition == sz ||
+ (mText[mCaretPosition] & 192) != 128)
+ {
+ break;
+ }
+ }
+ break;
+ }
+
+ case Input::KEY_GUI_DELETE:
+ {
+ unsigned sz = static_cast<unsigned>(mText.size());
+ while (mCaretPosition < sz)
+ {
+ --sz;
+ mText.erase(mCaretPosition, 1);
+ if (mCaretPosition == sz ||
+ (mText[mCaretPosition] & 192) != 128)
+ {
+ break;
+ }
+ }
+ break;
+ }
+
+ case Input::KEY_GUI_BACKSPACE:
+ deleteCharLeft(mText, &mCaretPosition);
+ break;
+
+ case Input::KEY_GUI_SELECT2:
+ distributeActionEvent();
+ keyEvent.consume();
+ fixScroll();
+ return;
+
+ case Input::KEY_GUI_HOME:
+ mCaretPosition = 0;
+ break;
+
+ case Input::KEY_GUI_END:
+ mCaretPosition = static_cast<unsigned>(mText.size());
+ break;
+
+ case Input::KEY_GUI_TAB:
+ if (mLoseFocusOnTab)
+ return;
break;
default: