From e2517b8ebcdf4eba4a8a619500f65fc28b70af11 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Fri, 9 Jan 2015 13:11:20 +0200 Subject: [PATCH] Fix html submit button value that is included with form data (issue #226) --- code/nel/include/nel/gui/ctrl_base.h | 8 ++++ code/nel/include/nel/gui/group_html.h | 6 ++- code/nel/src/gui/ctrl_base_button.cpp | 5 +++ code/nel/src/gui/group_html.cpp | 37 ++++++++++++++++--- .../src/interface_v3/action_handler_help.cpp | 7 +++- 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_base.h b/code/nel/include/nel/gui/ctrl_base.h index 71e6cad56..3b522e114 100644 --- a/code/nel/include/nel/gui/ctrl_base.h +++ b/code/nel/include/nel/gui/ctrl_base.h @@ -50,6 +50,8 @@ namespace NLGUI // see interface.txt for meaning of auto _ToolTipParentPosRef= Hotspot_TTAuto; _ToolTipPosRef= Hotspot_TTAuto; + _EventX = 0; + _EventY = 0; resizer = false; } @@ -70,6 +72,9 @@ namespace NLGUI bool handleEvent (const NLGUI::CEventDescriptor &event); + sint32 getEventX() { return _EventX; } + sint32 getEventY() { return _EventY; } + virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; } /// Debug @@ -181,6 +186,9 @@ namespace NLGUI static std::map< std::string, std::map< std::string, std::string > > AHCache; bool resizer; + + sint32 _EventX; + sint32 _EventY; }; } diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index 21d609af3..333800760 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -107,7 +107,7 @@ namespace NLGUI void refresh(); // submit form - void submitForm (uint formId, const char *submitButtonName); + void submitForm (uint formId, const char *submitButtonType, const char *submitButtonName, const char *submitButtonValue, sint32 x, sint32 y); // Browse error void browseError (const char *msg); @@ -328,7 +328,11 @@ namespace NLGUI bool _BrowseNextTime; bool _PostNextTime; uint _PostFormId; + std::string _PostFormSubmitType; std::string _PostFormSubmitButton; + std::string _PostFormSubmitValue; + sint32 _PostFormSubmitX; + sint32 _PostFormSubmitY; // Browsing.. bool _Browsing; diff --git a/code/nel/src/gui/ctrl_base_button.cpp b/code/nel/src/gui/ctrl_base_button.cpp index 4f118cd51..673ea906d 100644 --- a/code/nel/src/gui/ctrl_base_button.cpp +++ b/code/nel/src/gui/ctrl_base_button.cpp @@ -701,6 +701,11 @@ namespace NLGUI //pIM->submitEvent ("button_click:"+getId()); } */ + + // top-right corner is EventX=0, EventY=0 + _EventX = eventDesc.getX() - _XReal; + _EventY = (_YReal + _HReal) - eventDesc.getY(); + runLeftClickAction(); if (CWidgetManager::getInstance()->getCapturePointerLeft() == NULL) return true; // event handler may release cpature from this object (if it is removed for example) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index dd7eebdef..656e36ca8 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1217,7 +1217,7 @@ namespace NLGUI normal = value[MY_HTML_INPUT_SRC]; // Action handler parameters : "name=group_html_id|form=id_of_the_form|submit_button=button_name" - string param = "name=" + getId() + "|form=" + toString (_Forms.size()-1) + "|submit_button=" + name; + string param = "name=" + getId() + "|form=" + toString (_Forms.size()-1) + "|submit_button=" + name + "|submit_button_type=image"; // Add the ctrl button addButton (CCtrlButton::PushButton, name, normal, pushed.empty()?normal:pushed, over, @@ -1241,7 +1241,15 @@ namespace NLGUI text = value[MY_HTML_INPUT_VALUE]; // Action handler parameters : "name=group_html_id|form=id_of_the_form|submit_button=button_name" - string param = "name=" + getId() + "|form=" + toString (_Forms.size()-1) + "|submit_button=" + name; + string param = "name=" + getId() + "|form=" + toString (_Forms.size()-1) + "|submit_button=" + name + "|submit_button_type=submit"; + if (text.size() > 0) + { + // escape AH param separator + string tmp = text; + while(NLMISC::strFindReplace(tmp, "|", "|")) + ; + param = param + "|submit_button_value=" + tmp; + } // Add the ctrl button if (!_Paragraph) @@ -3638,14 +3646,18 @@ namespace NLGUI // *************************************************************************** - void CGroupHTML::submitForm (uint formId, const char *submitButtonName) + void CGroupHTML::submitForm (uint formId, const char *submitButtonType, const char *submitButtonName, const char *submitButtonValue, sint32 x, sint32 y) { // Form id valid ? if (formId < _Forms.size()) { _PostNextTime = true; _PostFormId = formId; + _PostFormSubmitType = submitButtonType; _PostFormSubmitButton = submitButtonName; + _PostFormSubmitValue = submitButtonValue; + _PostFormSubmitX = x; + _PostFormSubmitY = y; } } @@ -3918,9 +3930,22 @@ namespace NLGUI } } - // Add the button coordinates - HTParseFormInput(formfields, (_PostFormSubmitButton + "_x=0").c_str()); - HTParseFormInput(formfields, (_PostFormSubmitButton + "_y=0").c_str()); + if (_PostFormSubmitType == "image") + { + // Add the button coordinates + if (_PostFormSubmitButton.find_first_of("[") == string::npos) + { + HTParseFormInput(formfields, (_PostFormSubmitButton + "_x=" + NLMISC::toString(_PostFormSubmitX)).c_str()); + HTParseFormInput(formfields, (_PostFormSubmitButton + "_y=" + NLMISC::toString(_PostFormSubmitY)).c_str()); + } + else + { + HTParseFormInput(formfields, (_PostFormSubmitButton + "=" + NLMISC::toString(_PostFormSubmitX)).c_str()); + HTParseFormInput(formfields, (_PostFormSubmitButton + "=" + NLMISC::toString(_PostFormSubmitY)).c_str()); + } + } + else + HTParseFormInput(formfields, (_PostFormSubmitButton + "=" + _PostFormSubmitValue).c_str()); // Add custom params addHTTPPostParams(formfields, _TrustedDomain); diff --git a/code/ryzom/client/src/interface_v3/action_handler_help.cpp b/code/ryzom/client/src/interface_v3/action_handler_help.cpp index a8d1059ea..ed2b34ce3 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_help.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_help.cpp @@ -1117,6 +1117,11 @@ class CHandlerHTMLSubmitForm : public IActionHandler fromString(getParam (sParams, "form"), form); string submit_button = getParam (sParams, "submit_button"); + string type = getParam (sParams, "submit_button_type"); + string value = getParam (sParams, "submit_button_value"); + + sint32 x = pCaller->getEventX(); + sint32 y = pCaller->getEventY(); CInterfaceElement *element = CWidgetManager::getInstance()->getElementFromId(container); { @@ -1125,7 +1130,7 @@ class CHandlerHTMLSubmitForm : public IActionHandler if (groupHtml) { // Submit the form the url - groupHtml->submitForm (form, submit_button.c_str ()); + groupHtml->submitForm (form, type.c_str(), submit_button.c_str(), value.c_str(), x, y); } } }