PageRenderTime 294ms CodeModel.GetById 101ms app.highlight 10ms RepoModel.GetById 131ms app.codeStats 0ms

/indra/newview/lltoastscripttextbox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 121 lines | 69 code | 21 blank | 31 comment | 3 complexity | a94dc456a1e1e3f500130e717a758d70 MD5 | raw file
  1/**
  2 * @file lltoastscripttextbox.cpp
  3 * @brief Panel for script llTextBox dialogs
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "lltoastscripttextbox.h"
 30
 31#include "llfocusmgr.h"
 32
 33#include "llbutton.h"
 34#include "llnotifications.h"
 35#include "llviewertexteditor.h"
 36
 37#include "llavatarnamecache.h"
 38#include "lluiconstants.h"
 39#include "llui.h"
 40#include "llviewercontrol.h"
 41#include "lltrans.h"
 42#include "llstyle.h"
 43
 44#include "llglheaders.h"
 45#include "llagent.h"
 46
 47const S32 LLToastScriptTextbox::DEFAULT_MESSAGE_MAX_LINE_COUNT= 7;
 48
 49LLToastScriptTextbox::LLToastScriptTextbox(const LLNotificationPtr& notification)
 50:	LLToastPanel(notification)
 51{
 52	buildFromFile( "panel_notify_textbox.xml");
 53
 54	LLTextEditor* text_editorp = getChild<LLTextEditor>("text_editor_box");
 55	text_editorp->setValue(notification->getMessage());
 56
 57	getChild<LLButton>("ignore_btn")->setClickedCallback(boost::bind(&LLToastScriptTextbox::onClickIgnore, this));
 58
 59	const LLSD& payload = notification->getPayload();
 60
 61	//message body
 62	const std::string& message = payload["message"].asString();
 63
 64	LLViewerTextEditor* pMessageText = getChild<LLViewerTextEditor>("message");
 65	pMessageText->clear();
 66
 67	LLStyle::Params style;
 68	style.font = pMessageText->getDefaultFont();
 69	pMessageText->appendText(message, TRUE, style);
 70
 71	//submit button
 72	LLButton* pSubmitBtn = getChild<LLButton>("btn_submit");
 73	pSubmitBtn->setClickedCallback((boost::bind(&LLToastScriptTextbox::onClickSubmit, this)));
 74	setDefaultBtn(pSubmitBtn);
 75
 76	S32 maxLinesCount;
 77	std::istringstream ss( getString("message_max_lines_count") );
 78	if (!(ss >> maxLinesCount))
 79	{
 80		maxLinesCount = DEFAULT_MESSAGE_MAX_LINE_COUNT;
 81	}
 82	//snapToMessageHeight(pMessageText, maxLinesCount);
 83}
 84
 85// virtual
 86LLToastScriptTextbox::~LLToastScriptTextbox()
 87{
 88}
 89
 90void LLToastScriptTextbox::close()
 91{
 92	die();
 93}
 94
 95#include "lllslconstants.h"
 96void LLToastScriptTextbox::onClickSubmit()
 97{
 98	LLViewerTextEditor* pMessageText = getChild<LLViewerTextEditor>("message");
 99
100	if (pMessageText)
101	{
102		LLSD response = mNotification->getResponseTemplate();
103		response[TEXTBOX_MAGIC_TOKEN] = pMessageText->getText();
104		if (response[TEXTBOX_MAGIC_TOKEN].asString().empty())
105		{
106			// so we can distinguish between a successfully
107			// submitted blank textbox, and an ignored toast
108			response[TEXTBOX_MAGIC_TOKEN] = true;
109		}
110		mNotification->respond(response);
111		close();
112		llwarns << response << llendl;
113	}
114}
115
116void LLToastScriptTextbox::onClickIgnore()
117{
118	LLSD response = mNotification->getResponseTemplate();
119	mNotification->respond(response);
120	close();
121}