From d45a7d1c1b307607eaa24a26204cc716e6a6978c Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Thu, 4 Dec 2014 14:17:20 -0500 Subject: [PATCH] Clicking a text field now selects it as if you had tabbed into it --- osx/dialogxml/dialog.cpp | 17 ++++++++++++++++- osx/dialogxml/dialog.h | 1 + osx/dialogxml/field.cpp | 7 +++++++ osx/dialogxml/field.h | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/osx/dialogxml/dialog.cpp b/osx/dialogxml/dialog.cpp index c53aa1716..30e2d0515 100644 --- a/osx/dialogxml/dialog.cpp +++ b/osx/dialogxml/dialog.cpp @@ -909,8 +909,10 @@ void cDialog::run(){ std::string itemHit = ""; dialogNotToast = true; // Focus the first text field, if there is one - if(!tabOrder.empty()) + if(!tabOrder.empty()) { tabOrder[0].second->triggerFocusHandler(*this, tabOrder[0].first, false); + currentFocus = tabOrder[0].first; + } win.create(sf::VideoMode(winRect.width(), winRect.height()), "Dialog", sf::Style::Titlebar); win.setActive(); win.setVisible(true); @@ -1131,6 +1133,19 @@ bool cDialog::toast(bool triggerFocus){ return true; } +bool cDialog::setFocus(cTextField* newFocus, bool force) { + if(!force) { + if(!this->getControl(currentFocus).triggerFocusHandler(*this, currentFocus, true)) return false; + } + auto iter = find_if(controls.begin(), controls.end(), [newFocus](std::pair p){ + return p.second == newFocus; + }); + if(iter == controls.end()) return false; + if(!force && !newFocus->triggerFocusHandler(*this, iter->first, false)) return false; + currentFocus = iter->first; + return true; +} + void cDialog::attachClickHandlers(click_callback_t handler, std::vector controls) { cDialog& me = *this; for(std::string control : controls) { diff --git a/osx/dialogxml/dialog.h b/osx/dialogxml/dialog.h index 92a47d972..b54000876 100644 --- a/osx/dialogxml/dialog.h +++ b/osx/dialogxml/dialog.h @@ -61,6 +61,7 @@ public: void setDefTextClr(sf::Color clr); void setDefBtn(std::string defBtn); sf::Color getDefTextClr(); + bool setFocus(cTextField* newFocus, bool force = false); // Setting force = true skips focus handlers bool toast(bool triggerFocus); cControl& getControl(std::string id); cControl& operator[](std::string id); diff --git a/osx/dialogxml/field.cpp b/osx/dialogxml/field.cpp index 2143c2b39..f0e309152 100644 --- a/osx/dialogxml/field.cpp +++ b/osx/dialogxml/field.cpp @@ -29,6 +29,13 @@ bool cTextField::triggerFocusHandler(cDialog& me, std::string id, bool losingFoc return passed; } +bool cTextField::handleClick(location) { + // TODO: Set the insertion point, handle selection, etc + if(parent && !parent->setFocus(this)) return true; + haveFocus = true; + return true; +} + void cTextField::setFormat(eFormat prop, short) throw(xUnsupportedProp){ throw xUnsupportedProp(prop); } diff --git a/osx/dialogxml/field.h b/osx/dialogxml/field.h index 2e8d59366..ab629b2d8 100644 --- a/osx/dialogxml/field.h +++ b/osx/dialogxml/field.h @@ -22,6 +22,7 @@ public: void attachClickHandler(click_callback_t f) throw(xHandlerNotSupported); void attachFocusHandler(focus_callback_t f) throw(); bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus); + bool handleClick(location where); void setFormat(eFormat prop, short val) throw(xUnsupportedProp); short getFormat(eFormat prop) throw(xUnsupportedProp); void setColour(sf::Color clr) throw(xUnsupportedProp);