1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/**
* @file lltoastscriptquestion.cpp
*
* $LicenseInfo:firstyear=2010&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2012, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llbutton.h"
#include "llnotifications.h"
#include "lltoastscriptquestion.h"
const int LEFT_PAD = 10;
const int BUTTON_HEIGHT = 27;
const int MAX_LINES_COUNT = 50;
LLToastScriptQuestion::LLToastScriptQuestion(const LLNotificationPtr& notification)
:
LLToastPanel(notification)
{
buildFromFile("panel_script_question_toast.xml", true);
}
bool LLToastScriptQuestion::postBuild()
{
createButtons();
LLTextBox* mMessage = getChild<LLTextBox>("top_info_message");
LLTextBox* mFooter = getChild<LLTextBox>("bottom_info_message");
mMessage->setValue(mNotification->getMessage());
mFooter->setValue(mNotification->getFooter());
snapToMessageHeight();
return true;
}
// virtual
void LLToastScriptQuestion::setFocus(bool b)
{
LLToastPanel::setFocus(b);
// toast can fade out and disappear with focus ON, so reset to default anyway
LLButton* dfbutton = getDefaultButton();
if (dfbutton && dfbutton->getVisible() && dfbutton->getEnabled())
{
dfbutton->setFocus(b);
}
}
void LLToastScriptQuestion::snapToMessageHeight()
{
LLTextBox* mMessage = getChild<LLTextBox>("top_info_message");
LLTextBox* mFooter = getChild<LLTextBox>("bottom_info_message");
if (!mMessage || !mFooter)
{
return;
}
if (mMessage->getVisible() && mFooter->getVisible())
{
S32 heightDelta = 0;
S32 maxTextHeight = (mMessage->getFont()->getLineHeight() * MAX_LINES_COUNT)
+ (mFooter->getFont()->getLineHeight() * MAX_LINES_COUNT);
LLRect messageRect = mMessage->getRect();
LLRect footerRect = mFooter->getRect();
S32 oldTextHeight = messageRect.getHeight() + footerRect.getHeight();
S32 requiredTextHeight = mMessage->getTextBoundingRect().getHeight() + mFooter->getTextBoundingRect().getHeight();
S32 newTextHeight = llmin(requiredTextHeight, maxTextHeight);
heightDelta = newTextHeight - oldTextHeight - heightDelta;
reshape( getRect().getWidth(), llmax(getRect().getHeight() + heightDelta, MIN_PANEL_HEIGHT));
}
}
void LLToastScriptQuestion::createButtons()
{
LLNotificationFormPtr form = mNotification->getForm();
int num_elements = form->getNumElements();
int buttons_width = 0;
for (int i = 0; i < num_elements; ++i)
{
LLSD form_element = form->getElement(i);
if ("button" == form_element["type"].asString())
{
LLButton::Params p;
const LLFontGL* font = LLFontGL::getFontSansSerif();
p.name(form_element["name"].asString());
p.label(form_element["text"].asString());
p.layout("topleft");
p.font(font);
p.rect.height(BUTTON_HEIGHT);
p.click_callback.function(boost::bind(&LLToastScriptQuestion::onButtonClicked, this, form_element["name"].asString()));
p.rect.left = LEFT_PAD;
p.rect.width = font->getWidth(form_element["text"].asString());
p.auto_resize = true;
p.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM);
p.image_color(LLUIColorTable::instance().getColor("ButtonCautionImageColor"));
p.image_color_disabled(LLUIColorTable::instance().getColor("ButtonCautionImageColor"));
LLButton* button = LLUICtrlFactory::create<LLButton>(p);
button->autoResize();
getChild<LLPanel>("buttons_panel")->addChild(button);
LLRect rect = button->getRect();
rect.setLeftTopAndSize(buttons_width, rect.mTop, rect.getWidth(), rect.getHeight());
button->setRect(rect);
buttons_width += rect.getWidth() + LEFT_PAD;
if (form_element.has("default") && form_element["default"].asBoolean())
{
button->setFocus(true);
setDefaultBtn(button);
}
}
}
}
void LLToastScriptQuestion::onButtonClicked(std::string btn_name)
{
LLSD response = mNotification->getResponseTemplate();
response[btn_name] = true;
mNotification->respond(response);
}
|