summaryrefslogtreecommitdiff
path: root/src/guichan/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/guichan/widgets')
-rw-r--r--src/guichan/widgets/checkbox.cpp10
-rw-r--r--src/guichan/widgets/listbox.cpp47
-rw-r--r--src/guichan/widgets/radiobutton.cpp11
-rw-r--r--src/guichan/widgets/slider.cpp34
-rw-r--r--src/guichan/widgets/tabbedarea.cpp29
-rw-r--r--src/guichan/widgets/textbox.cpp146
6 files changed, 6 insertions, 271 deletions
diff --git a/src/guichan/widgets/checkbox.cpp b/src/guichan/widgets/checkbox.cpp
index c7ec3e1e0..413f8e6af 100644
--- a/src/guichan/widgets/checkbox.cpp
+++ b/src/guichan/widgets/checkbox.cpp
@@ -99,16 +99,8 @@ namespace gcn
mCaption = caption;
}
- void CheckBox::keyPressed(KeyEvent& keyEvent)
+ void CheckBox::keyPressed(KeyEvent& keyEvent A_UNUSED)
{
- Key key = keyEvent.getKey();
-
- if (key.getValue() == Key::ENTER ||
- key.getValue() == Key::SPACE)
- {
- toggleSelected();
- keyEvent.consume();
- }
}
void CheckBox::mouseClicked(MouseEvent& mouseEvent)
diff --git a/src/guichan/widgets/listbox.cpp b/src/guichan/widgets/listbox.cpp
index 5760025c2..3152890bc 100644
--- a/src/guichan/widgets/listbox.cpp
+++ b/src/guichan/widgets/listbox.cpp
@@ -189,53 +189,8 @@ namespace gcn
distributeValueChangedEvent();
}
- void ListBox::keyPressed(KeyEvent& keyEvent)
+ void ListBox::keyPressed(KeyEvent& keyEvent A_UNUSED)
{
- Key key = keyEvent.getKey();
-
- if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
- {
- distributeActionEvent();
- keyEvent.consume();
- }
- else if (key.getValue() == Key::UP)
- {
- setSelected(mSelected - 1);
-
- if (mSelected == -1)
- {
- if (mWrappingEnabled)
- setSelected(getListModel()->getNumberOfElements() - 1);
- else
- setSelected(0);
- }
-
- keyEvent.consume();
- }
- else if (key.getValue() == Key::DOWN)
- {
- if (mWrappingEnabled
- && getSelected() == getListModel()->getNumberOfElements() - 1)
- {
- setSelected(0);
- }
- else
- {
- setSelected(getSelected() + 1);
- }
-
- keyEvent.consume();
- }
- else if (key.getValue() == Key::HOME)
- {
- setSelected(0);
- keyEvent.consume();
- }
- else if (key.getValue() == Key::END)
- {
- setSelected(getListModel()->getNumberOfElements() - 1);
- keyEvent.consume();
- }
}
void ListBox::mousePressed(MouseEvent& mouseEvent)
diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp
index 7d0391cbe..7811ea558 100644
--- a/src/guichan/widgets/radiobutton.cpp
+++ b/src/guichan/widgets/radiobutton.cpp
@@ -128,17 +128,8 @@ namespace gcn
mCaption = caption;
}
- void RadioButton::keyPressed(KeyEvent& keyEvent)
+ void RadioButton::keyPressed(KeyEvent& keyEvent A_UNUSED)
{
- Key key = keyEvent.getKey();
-
- if (key.getValue() == Key::ENTER ||
- key.getValue() == Key::SPACE)
- {
- setSelected(true);
- distributeActionEvent();
- keyEvent.consume();
- }
}
void RadioButton::mouseClicked(MouseEvent& mouseEvent)
diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp
index 36f067eab..d7e8084cc 100644
--- a/src/guichan/widgets/slider.cpp
+++ b/src/guichan/widgets/slider.cpp
@@ -191,40 +191,8 @@ namespace gcn
mMarkerLength = length;
}
- void Slider::keyPressed(KeyEvent& keyEvent)
+ void Slider::keyPressed(KeyEvent& keyEvent A_UNUSED)
{
- Key key = keyEvent.getKey();
-
- if (getOrientation() == HORIZONTAL)
- {
- if (key.getValue() == Key::RIGHT)
- {
- setValue(getValue() + getStepLength());
- distributeActionEvent();
- keyEvent.consume();
- }
- else if (key.getValue() == Key::LEFT)
- {
- setValue(getValue() - getStepLength());
- distributeActionEvent();
- keyEvent.consume();
- }
- }
- else
- {
- if (key.getValue() == Key::UP)
- {
- setValue(getValue() + getStepLength());
- distributeActionEvent();
- keyEvent.consume();
- }
- else if (key.getValue() == Key::DOWN)
- {
- setValue(getValue() - getStepLength());
- distributeActionEvent();
- keyEvent.consume();
- }
- }
}
void Slider::setOrientation(Slider::Orientation orientation)
diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp
index 3e7178548..fb6619bed 100644
--- a/src/guichan/widgets/tabbedarea.cpp
+++ b/src/guichan/widgets/tabbedarea.cpp
@@ -298,35 +298,8 @@ namespace gcn
adjustSize();
}
- void TabbedArea::keyPressed(KeyEvent& keyEvent)
+ void TabbedArea::keyPressed(KeyEvent& keyEvent A_UNUSED)
{
- if (keyEvent.isConsumed() || !isFocused())
- return;
-
- if (keyEvent.getKey().getValue() == Key::LEFT)
- {
- int index = getSelectedTabIndex();
- index--;
-
- if (index < 0)
- return;
- else
- setSelectedTab(mTabs[index].first);
-
- keyEvent.consume();
- }
- else if (keyEvent.getKey().getValue() == Key::RIGHT)
- {
- int index = getSelectedTabIndex();
- index++;
-
- if (index >= static_cast<int>(mTabs.size()))
- return;
- else
- setSelectedTab(mTabs[index].first);
-
- keyEvent.consume();
- }
}
void TabbedArea::death(const Event& event)
diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp
index da7edaac7..44fb5d718 100644
--- a/src/guichan/widgets/textbox.cpp
+++ b/src/guichan/widgets/textbox.cpp
@@ -168,152 +168,8 @@ namespace gcn
mouseEvent.consume();
}
- void TextBox::keyPressed(KeyEvent& keyEvent)
+ void TextBox::keyPressed(KeyEvent& keyEvent A_UNUSED)
{
- Key key = keyEvent.getKey();
-
- if (key.getValue() == Key::LEFT)
- {
- --mCaretColumn;
- if (mCaretColumn < 0)
- {
- --mCaretRow;
-
- if (mCaretRow < 0)
- {
- mCaretRow = 0;
- mCaretColumn = 0;
- }
- else
- {
- mCaretColumn = mTextRows[mCaretRow].size();
- }
- }
- }
- else if (key.getValue() == Key::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;
- }
- }
- }
- else if (key.getValue() == Key::DOWN)
- {
- setCaretRow(mCaretRow + 1);
- }
- else if (key.getValue() == Key::UP)
- {
- setCaretRow(mCaretRow - 1);
- }
- else if (key.getValue() == Key::HOME)
- {
- mCaretColumn = 0;
- }
- else if (key.getValue() == Key::END)
- {
- mCaretColumn = mTextRows[mCaretRow].size();
- }
- else if (key.getValue() == 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() == Key::BACKSPACE
- && mCaretColumn != 0
- && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
- --mCaretColumn;
- }
- else if (key.getValue() == 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() == Key::DELETE
- && mCaretColumn < static_cast<int>(
- mTextRows[mCaretRow].size()) && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn, 1);
- }
- else if (key.getValue() == 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() == Key::PAGE_UP)
- {
- Widget* par = getParent();
-
- if (par)
- {
- int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow -= rowsPerPage;
-
- if (mCaretRow < 0)
- mCaretRow = 0;
- }
- }
- else if (key.getValue() == Key::PAGE_DOWN)
- {
- Widget* par = getParent();
-
- if (par)
- {
- int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow += rowsPerPage;
-
- if (mCaretRow >= static_cast<int>(mTextRows.size()))
- mCaretRow = mTextRows.size() - 1;
- }
- }
- else if (key.getValue() == 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();
-
- keyEvent.consume();
}
void TextBox::adjustSize()