From 6e5d8181b830694a90bba7ad5651fa0b726e4a75 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 30 Dec 2012 16:00:06 +0300 Subject: Add popup menu for text fields. This menu allow copy/paste text to/from clipboard. --- src/gui/widgets/browserbox.h | 3 +++ src/gui/widgets/textfield.cpp | 11 +++++++++++ src/gui/widgets/textfield.h | 10 ++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 2f0313c37..fad731e5a 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -211,6 +211,9 @@ class BrowserBox final : public gcn::Widget, std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED; + int getPadding() const A_WARN_UNUSED + { return mPadding; } + private: int calcHeight() A_WARN_UNUSED; diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 260b0fe57..3a6212b79 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -27,6 +27,7 @@ #include "keyevent.h" #include "gui/sdlinput.h" +#include "gui/viewport.h" #include "resources/image.h" @@ -515,3 +516,13 @@ void TextField::fontChanged() { fixScroll(); } + +void TextField::mousePressed(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) + { + if (viewport) + viewport->showTextFieldPopup(this); + } + else gcn::TextField::mousePressed(mouseEvent); +} diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 34ca88b4a..9220f3dd7 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -115,6 +115,12 @@ class TextField : public gcn::TextField, void setCaretPosition(unsigned int position); + void mousePressed(gcn::MouseEvent &mouseEvent) override; + + void handlePaste(); + + void handleCopy() const; + protected: void drawCaret(gcn::Graphics* graphics, int x) override; @@ -127,10 +133,6 @@ class TextField : public gcn::TextField, static Skin *mSkin; private: - void handlePaste(); - - void handleCopy() const; - static int instances; static float mAlpha; static ImageRect skin; -- cgit v1.2.3-70-g09d2