Enable SDL_TEXTINPUT events only when a text input widget currently has key focus

pull/16/head
scrawl 12 years ago
parent bc6d5de1f4
commit 03682184c6

@ -264,6 +264,8 @@ namespace MWBase
virtual void changePointer (const std::string& name) = 0; virtual void changePointer (const std::string& name) = 0;
virtual const Translation::Storage& getTranslationDataStorage() const = 0; virtual const Translation::Storage& getTranslationDataStorage() const = 0;
virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0;
}; };
} }

@ -407,7 +407,7 @@ namespace MWGui
getWidget(mEditName, "EditName"); getWidget(mEditName, "EditName");
// Make sure the edit box has focus // Make sure the edit box has focus
MyGUI::InputManager::getInstance().setKeyFocusWidget(mEditName); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mEditName);
MyGUI::Button* descriptionButton; MyGUI::Button* descriptionButton;
getWidget(descriptionButton, "DescriptionButton"); getWidget(descriptionButton, "DescriptionButton");
@ -866,7 +866,7 @@ namespace MWGui
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sInputMenu1", "")); okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sInputMenu1", ""));
// Make sure the edit box has focus // Make sure the edit box has focus
MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
} }
DescriptionDialog::~DescriptionDialog() DescriptionDialog::~DescriptionDialog()

@ -5,6 +5,7 @@
#include "../mwscript/extensions.hpp" #include "../mwscript/extensions.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
namespace MWGui namespace MWGui
{ {
@ -131,16 +132,12 @@ namespace MWGui
// Give keyboard focus to the combo box whenever the console is // Give keyboard focus to the combo box whenever the console is
// turned on // turned on
MyGUI::InputManager::getInstance().setKeyFocusWidget(command); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command);
} }
void Console::disable() void Console::disable()
{ {
setVisible(false); setVisible(false);
// Remove keyboard focus from the console input whenever the
// console is turned off
MyGUI::InputManager::getInstance().setKeyFocusWidget(NULL);
} }
void Console::setFont(const std::string &fntName) void Console::setFont(const std::string &fntName)
@ -415,7 +412,7 @@ namespace MWGui
setTitle("#{sConsoleTitle}"); setTitle("#{sConsoleTitle}");
mPtr = MWWorld::Ptr(); mPtr = MWWorld::Ptr();
} }
MyGUI::InputManager::getInstance().setKeyFocusWidget(command); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command);
} }
void Console::onReferenceUnavailable() void Console::onReferenceUnavailable()

@ -2,6 +2,9 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
namespace MWGui namespace MWGui
{ {
CountDialog::CountDialog() : CountDialog::CountDialog() :
@ -40,7 +43,7 @@ namespace MWGui
mMainWidget->getHeight()); mMainWidget->getHeight());
// by default, the text edit field has the focus of the keyboard // by default, the text edit field has the focus of the keyboard
MyGUI::InputManager::getInstance().setKeyFocusWidget(mItemEdit); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mItemEdit);
mSlider->setScrollPosition(maxCount-1); mSlider->setScrollPosition(maxCount-1);
mItemEdit->setCaption(boost::lexical_cast<std::string>(maxCount)); mItemEdit->setCaption(boost::lexical_cast<std::string>(maxCount));

@ -20,7 +20,7 @@ namespace MWGui
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
// Make sure the edit box has focus // Make sure the edit box has focus
MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
} }
void TextInputDialog::setNextButtonShow(bool shown) void TextInputDialog::setNextButtonShow(bool shown)
@ -43,7 +43,7 @@ namespace MWGui
{ {
WindowModal::open(); WindowModal::open();
// Make sure the edit box has focus // Make sure the edit box has focus
MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
} }
// widget controls // widget controls
@ -53,7 +53,7 @@ namespace MWGui
if (mTextEdit->getCaption() == "") if (mTextEdit->getCaption() == "")
{ {
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}"); MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
MyGUI::InputManager::getInstance ().setKeyFocusWidget (mTextEdit); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);
} }
else else
eventDone(this); eventDone(this);
@ -64,7 +64,7 @@ namespace MWGui
if (mTextEdit->getCaption() == "") if (mTextEdit->getCaption() == "")
{ {
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}"); MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
MyGUI::InputManager::getInstance ().setKeyFocusWidget (mTextEdit); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);
} }
else else
eventDone(this); eventDone(this);

@ -225,6 +225,8 @@ namespace MWGui
MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange); MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange);
MyGUI::InputManager::getInstance().eventChangeKeyFocus += MyGUI::newDelegate(this, &WindowManager::onKeyFocusChanged);
setUseHardwareCursors(mUseHardwareCursors); setUseHardwareCursors(mUseHardwareCursors);
onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer()); onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer());
mCursorManager->cursorVisibilityChange(false); mCursorManager->cursorVisibilityChange(false);
@ -360,7 +362,7 @@ namespace MWGui
mToolTips->enterGuiMode(); mToolTips->enterGuiMode();
if (gameMode) if (gameMode)
MyGUI::InputManager::getInstance ().setKeyFocusWidget (NULL); setKeyFocusWidget (NULL);
setMinimapVisibility((mAllowed & GW_Map) && !mMap->pinned()); setMinimapVisibility((mAllowed & GW_Map) && !mMap->pinned());
setWeaponVisibility((mAllowed & GW_Inventory) && !mInventoryWindow->pinned()); setWeaponVisibility((mAllowed & GW_Inventory) && !mInventoryWindow->pinned());
@ -1299,4 +1301,21 @@ namespace MWGui
mInventoryWindow->updatePlayer(); mInventoryWindow->updatePlayer();
} }
void WindowManager::setKeyFocusWidget(MyGUI::Widget *widget)
{
if (widget == NULL)
MyGUI::InputManager::getInstance().resetKeyFocusWidget();
else
MyGUI::InputManager::getInstance().setKeyFocusWidget(widget);
onKeyFocusChanged(widget);
}
void WindowManager::onKeyFocusChanged(MyGUI::Widget *widget)
{
if (widget && widget->castType<MyGUI::EditBox>(false))
SDL_StartTextInput();
else
SDL_StopTextInput();
}
} }

@ -98,6 +98,8 @@ namespace MWGui
*/ */
virtual void update(); virtual void update();
virtual void setKeyFocusWidget (MyGUI::Widget* widget);
virtual void setNewGame(bool newgame); virtual void setNewGame(bool newgame);
virtual void pushGuiMode(GuiMode mode); virtual void pushGuiMode(GuiMode mode);
@ -353,6 +355,7 @@ namespace MWGui
void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result); void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result);
void onCursorChange(const std::string& name); void onCursorChange(const std::string& name);
void onKeyFocusChanged(MyGUI::Widget* widget);
}; };
} }

@ -30,9 +30,6 @@ namespace SFO
mMouseInWindow(true) mMouseInWindow(true)
{ {
_setupOISKeys(); _setupOISKeys();
// FIXME: text input should only be enabled when a text input widget currently has focus
SDL_StartTextInput();
} }
InputWrapper::~InputWrapper() InputWrapper::~InputWrapper()
@ -40,8 +37,6 @@ namespace SFO
if(mSDLWindow != NULL && mOwnWindow) if(mSDLWindow != NULL && mOwnWindow)
SDL_DestroyWindow(mSDLWindow); SDL_DestroyWindow(mSDLWindow);
mSDLWindow = NULL; mSDLWindow = NULL;
SDL_StopTextInput();
} }
void InputWrapper::capture() void InputWrapper::capture()

Loading…
Cancel
Save