From 3a4093ccc30f07c987896d05a5c2d2620e62d0d0 Mon Sep 17 00:00:00 2001 From: Siana Gearz Date: Sun, 6 Feb 2011 18:38:51 +0100 Subject: [PATCH] llTextBox, patch from Henri --- indra/newview/llnotify.cpp | 51 ++++++++++++++++--- indra/newview/llnotify.h | 3 ++ indra/newview/llviewermessage.cpp | 34 ++++++++++++- .../skins/default/xui/en-us/notifications.xml | 1 - 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/indra/newview/llnotify.cpp b/indra/newview/llnotify.cpp index b69d164b0..b80c840fe 100644 --- a/indra/newview/llnotify.cpp +++ b/indra/newview/llnotify.cpp @@ -139,10 +139,11 @@ LLNotifyBox::LLNotifyBox(LLNotificationPtr notification, mNumOptions(0), mNumButtons(0), mAddedDefaultBtn(FALSE), - mLayoutScriptDialog(layout_script_dialog) + mLayoutScriptDialog(layout_script_dialog), + mUserInputBox(NULL) { - // clicking on a button does not steal current focus - setIsChrome(TRUE); + std::string edit_text_name; + std::string edit_text_contents; // class init { @@ -174,8 +175,10 @@ LLNotifyBox::LLNotifyBox(LLNotificationPtr notification, mNumOptions = form->getNumElements(); + bool is_textbox = form->getElement("message").isDefined(); + LLRect rect = mIsTip ? getNotifyTipRect(mMessage) - : getNotifyRect(mNumOptions, layout_script_dialog, mIsCaution); + : getNotifyRect(is_textbox ? 10 : mNumOptions, layout_script_dialog, mIsCaution); setRect(rect); setFollows(mIsTip ? (FOLLOWS_BOTTOM|FOLLOWS_RIGHT) : (FOLLOWS_TOP|FOLLOWS_RIGHT)); setBackgroundVisible(FALSE); @@ -303,12 +306,42 @@ LLNotifyBox::LLNotifyBox(LLNotificationPtr notification, { LLSD form_element = form->getElement(i); - if (form_element["type"].asString() != "button") + std::string element_type = form_element["type"].asString(); + if (element_type == "button") { - continue; + addButton(form_element["name"].asString(), form_element["text"].asString(), TRUE, form_element["default"].asBoolean()); + } + else if (element_type == "input") + { + edit_text_contents = form_element["value"].asString(); + edit_text_name = form_element["name"].asString(); + } } - addButton(form_element["name"].asString(), form_element["text"].asString(), TRUE, form_element["default"].asBoolean()); + if (is_textbox) + { + S32 button_rows = (layout_script_dialog) ? 2 : 1; + + LLRect input_rect; + input_rect.setOriginAndSize(x, BOTTOM_PAD + button_rows * (BTN_HEIGHT + VPAD), + 3 * 80 + 4 * HPAD, button_rows * (BTN_HEIGHT + VPAD) + BTN_HEIGHT); + + mUserInputBox = new LLTextEditor(edit_text_name, input_rect, 254, + edit_text_contents, sFont, FALSE); + mUserInputBox->setBorderVisible(TRUE); + mUserInputBox->setTakesNonScrollClicks(TRUE); + mUserInputBox->setHideScrollbarForShortDocs(TRUE); + mUserInputBox->setWordWrap(TRUE); + mUserInputBox->setTabsToNextField(FALSE); + mUserInputBox->setCommitOnFocusLost(FALSE); + mUserInputBox->setAcceptCallingCardNames(FALSE); + mUserInputBox->setHandleEditKeysDirectly(TRUE); + + addChild(mUserInputBox, -1); + } + else + { + setIsChrome(TRUE); } if (mNumButtons == 0) @@ -739,6 +772,10 @@ void LLNotifyBox::onClickButton(void* data) { response[button_name] = true; } + if (self->mUserInputBox) + { + response[self->mUserInputBox->getName()] = self->mUserInputBox->getValue(); + } self->mNotification->respond(response); } diff --git a/indra/newview/llnotify.h b/indra/newview/llnotify.h index 0e290464e..15b5a7302 100644 --- a/indra/newview/llnotify.h +++ b/indra/newview/llnotify.h @@ -41,6 +41,7 @@ class LLButton; class LLNotifyBoxTemplate; +class LLTextEditor; // NotifyBox - for notifications that require a response from the user. class LLNotifyBox : @@ -103,6 +104,8 @@ private: protected: std::string mMessage; + LLTextEditor *mUserInputBox; + LLNotificationPtr mNotification; BOOL mIsTip; BOOL mIsCaution; // is this a caution notification? diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index 914408fac..f4bc1b9ed 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -6252,6 +6252,10 @@ bool callback_script_dialog(const LLSD& notification, const LLSD& response) // Didn't click "Ignore" if (button_idx != -1) { + if (notification["payload"].has("textbox")) + { + button = response["message"].asString(); + } LLMessageSystem* msg = gMessageSystem; msg->newMessage("ScriptDialogReply"); msg->nextBlock("AgentData"); @@ -6307,12 +6311,30 @@ void process_script_dialog(LLMessageSystem* msg, void**) } LLNotificationForm form; - for (i = 0; i < button_count; i++) + std::string firstbutton; + msg->getString("Buttons", "ButtonLabel", firstbutton, 0); + form.addElement("button", std::string(firstbutton)); + bool is_text_box = false; + std::string default_text; + if (firstbutton == "!!llTextBox!!") + { + is_text_box = true; + for (i = 1; i < button_count; i++) + { + std::string tdesc; + msg->getString("Buttons", "ButtonLabel", tdesc, i); + default_text += tdesc; + } + } + else + { + for (i = 1; i < button_count; i++) { std::string tdesc; msg->getString("Buttons", "ButtonLabel", tdesc, i); form.addElement("button", std::string(tdesc)); } + } LLSD args; args["TITLE"] = title; @@ -6325,9 +6347,19 @@ void process_script_dialog(LLMessageSystem* msg, void**) { args["FIRST"] = first_name; args["LAST"] = last_name; + + if (is_text_box) + { + args["DEFAULT"] = default_text; + payload["textbox"] = "true"; + LLNotifications::instance().add("ScriptTextBoxDialog", args, payload, callback_script_dialog); + } + else + { notification = LLNotifications::instance().add( LLNotification::Params("ScriptDialog").substitutions(args).payload(payload).form_elements(form.asLLSD())); } + } else { args["GROUPNAME"] = last_name; diff --git a/indra/newview/skins/default/xui/en-us/notifications.xml b/indra/newview/skins/default/xui/en-us/notifications.xml index ed1ec7940..33d13ef76 100644 --- a/indra/newview/skins/default/xui/en-us/notifications.xml +++ b/indra/newview/skins/default/xui/en-us/notifications.xml @@ -6268,7 +6268,6 @@ Grant this request? [MESSAGE]
- [DEFAULT]