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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
/**
* @file llchatitemscontainer.cpp
* @brief chat history scrolling panel implementation
*
* $LicenseInfo:firstyear=2009&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 "llchatitemscontainerctrl.h"
#include "lltextbox.h"
#include "llchatmsgbox.h"
#include "llavatariconctrl.h"
#include "llcommandhandler.h"
#include "llfloaterreg.h"
#include "lllocalcliprect.h"
#include "lltrans.h"
#include "llfloaterimnearbychat.h"
#include "llviewercontrol.h"
#include "llagentdata.h"
#include "llslurl.h"
static const S32 msg_left_offset = 10;
static const S32 msg_right_offset = 10;
static const S32 msg_height_pad = 5;
//*******************************************************************************************************************
// LLObjectHandler
//*******************************************************************************************************************
// handle secondlife:///app/object/<ID>/inspect SLURLs
class LLObjectHandler : public LLCommandHandler
{
public:
LLObjectHandler() : LLCommandHandler("object", UNTRUSTED_BLOCK) { }
bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
{
if (params.size() < 2) return false;
LLUUID object_id;
if (!object_id.set(params[0], FALSE))
{
return false;
}
const std::string verb = params[1].asString();
if (verb == "inspect")
{
LLFloaterReg::showInstance("inspect_object", LLSD().with("object_id", object_id));
return true;
}
return false;
}
};
LLObjectHandler gObjectHandler;
//*******************************************************************************************************************
//LLFloaterIMNearbyChatToastPanel
//*******************************************************************************************************************
LLFloaterIMNearbyChatToastPanel* LLFloaterIMNearbyChatToastPanel::createInstance()
{
LLFloaterIMNearbyChatToastPanel* item = new LLFloaterIMNearbyChatToastPanel();
item->buildFromFile("panel_chat_item.xml");
item->setFollows(FOLLOWS_NONE);
return item;
}
void LLFloaterIMNearbyChatToastPanel::reshape (S32 width, S32 height, BOOL called_from_parent )
{
LLPanel::reshape(width, height,called_from_parent);
// reshape() may be called from LLView::initFromParams() before the children are created.
// We call findChild() instead of getChild() here to avoid creating dummy controls.
LLUICtrl* msg_text = findChild<LLUICtrl>("msg_text", false);
LLUICtrl* icon = findChild<LLUICtrl>("avatar_icon", false);
if (!msg_text || !icon)
{
return;
}
LLRect msg_text_rect = msg_text->getRect();
LLRect avatar_rect = icon->getRect();
avatar_rect.setLeftTopAndSize(2,height-2,avatar_rect.getWidth(),avatar_rect.getHeight());
icon->setRect(avatar_rect);
msg_text_rect.setLeftTopAndSize( avatar_rect.mRight + msg_left_offset,
height - msg_height_pad,
width - avatar_rect.mRight - msg_left_offset - msg_right_offset,
height - 2*msg_height_pad);
msg_text->reshape( msg_text_rect.getWidth(), msg_text_rect.getHeight(), 1);
msg_text->setRect(msg_text_rect);
}
BOOL LLFloaterIMNearbyChatToastPanel::postBuild()
{
return LLPanel::postBuild();
}
void LLFloaterIMNearbyChatToastPanel::addMessage(LLSD& notification)
{
std::string messageText = notification["message"].asString(); // UTF-8 line of text
LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
std::string color_name = notification["text_color"].asString();
LLColor4 textColor = LLUIColorTable::instance().getColor(color_name);
textColor.mV[VALPHA] =notification["color_alpha"].asReal();
S32 font_size = notification["font_size"].asInteger();
LLFontGL* messageFont;
switch(font_size)
{
case 0: messageFont = LLFontGL::getFontSansSerifSmall(); break;
default:
case 1: messageFont = LLFontGL::getFontSansSerif(); break;
case 2: messageFont = LLFontGL::getFontSansSerifBig(); break;
}
//append text
{
LLStyle::Params style_params;
style_params.color(textColor);
std::string font_name = LLFontGL::nameFromFont(messageFont);
std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
style_params.font.name(font_name);
style_params.font.size(font_style_size);
int chat_type = notification["chat_type"].asInteger();
if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC)
{
style_params.font.style = "ITALIC";
}
else if( chat_type == CHAT_TYPE_SHOUT)
{
style_params.font.style = "BOLD";
}
else if( chat_type == CHAT_TYPE_WHISPER)
{
style_params.font.style = "ITALIC";
}
msg_text->appendText(messageText, TRUE, style_params);
}
snapToMessageHeight();
}
void LLFloaterIMNearbyChatToastPanel::init(LLSD& notification)
{
std::string messageText = notification["message"].asString(); // UTF-8 line of text
std::string fromName = notification["from"].asString(); // agent or object name
mFromID = notification["from_id"].asUUID(); // agent id or object id
mFromName = fromName;
int sType = notification["source"].asInteger();
mSourceType = (EChatSourceType)sType;
std::string color_name = notification["text_color"].asString();
LLColor4 textColor = LLUIColorTable::instance().getColor(color_name);
textColor.mV[VALPHA] =notification["color_alpha"].asReal();
S32 font_size = notification["font_size"].asInteger();
LLFontGL* messageFont;
switch(font_size)
{
case 0: messageFont = LLFontGL::getFontSansSerifSmall(); break;
default:
case 1: messageFont = LLFontGL::getFontSansSerif(); break;
case 2: messageFont = LLFontGL::getFontSansSerifBig(); break;
}
LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
msg_text->setText(std::string(""));
if ( notification["chat_style"].asInteger() != CHAT_STYLE_IRC )
{
std::string str_sender;
str_sender = fromName;
str_sender+=" ";
//append sender name
if (mSourceType == CHAT_SOURCE_AGENT || mSourceType == CHAT_SOURCE_OBJECT)
{
LLStyle::Params style_params_name;
LLColor4 user_name_color = LLUIColorTable::instance().getColor("HTMLLinkColor");
style_params_name.color(user_name_color);
std::string font_name = LLFontGL::nameFromFont(messageFont);
std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
style_params_name.font.name(font_name);
style_params_name.font.size(font_style_size);
style_params_name.link_href = notification["sender_slurl"].asString();
style_params_name.is_link = true;
msg_text->appendText(str_sender, FALSE, style_params_name);
}
else
{
msg_text->appendText(str_sender, false);
}
}
//append text
{
LLStyle::Params style_params;
style_params.color(textColor);
std::string font_name = LLFontGL::nameFromFont(messageFont);
std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
style_params.font.name(font_name);
style_params.font.size(font_style_size);
int chat_type = notification["chat_type"].asInteger();
if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC)
{
style_params.font.style = "ITALIC";
}
else if( chat_type == CHAT_TYPE_SHOUT)
{
style_params.font.style = "BOLD";
}
else if( chat_type == CHAT_TYPE_WHISPER)
{
style_params.font.style = "ITALIC";
}
msg_text->appendText(messageText, FALSE, style_params);
}
snapToMessageHeight();
mIsDirty = true;//will set Avatar Icon in draw
}
void LLFloaterIMNearbyChatToastPanel::snapToMessageHeight ()
{
LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false);
S32 new_height = llmax (text_box->getTextPixelHeight() + 2*text_box->getVPad() + 2*msg_height_pad, 25);
LLRect panel_rect = getRect();
panel_rect.setLeftTopAndSize( panel_rect.mLeft, panel_rect.mTop, panel_rect.getWidth(), new_height);
reshape( getRect().getWidth(), getRect().getHeight(), 1);
setRect(panel_rect);
}
void LLFloaterIMNearbyChatToastPanel::onMouseLeave (S32 x, S32 y, MASK mask)
{
}
void LLFloaterIMNearbyChatToastPanel::onMouseEnter (S32 x, S32 y, MASK mask)
{
if(mSourceType != CHAT_SOURCE_AGENT)
return;
}
BOOL LLFloaterIMNearbyChatToastPanel::handleMouseDown (S32 x, S32 y, MASK mask)
{
return LLPanel::handleMouseDown(x,y,mask);
}
BOOL LLFloaterIMNearbyChatToastPanel::handleMouseUp (S32 x, S32 y, MASK mask)
{
/*
fix for request EXT-4780
leaving this commented since I don't remember why ew block those messages...
if(mSourceType != CHAT_SOURCE_AGENT)
return LLPanel::handleMouseUp(x,y,mask);
*/
LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false);
S32 local_x = x - text_box->getRect().mLeft;
S32 local_y = y - text_box->getRect().mBottom;
//if text_box process mouse up (ussually this is click on url) - we didn't show nearby_chat.
if (text_box->pointInView(local_x, local_y) )
{
if (text_box->handleMouseUp(local_x,local_y,mask) == TRUE)
return TRUE;
else
{
LLFloaterReg::toggleInstanceOrBringToFront("nearby_chat");
return FALSE;
}
}
LLFloaterReg::toggleInstanceOrBringToFront("nearby_chat");
return LLPanel::handleMouseUp(x,y,mask);
}
void LLFloaterIMNearbyChatToastPanel::setHeaderVisibility(EShowItemHeader e)
{
LLUICtrl* icon = getChild<LLUICtrl>("avatar_icon", false);
if(icon)
icon->setVisible(e == CHATITEMHEADER_SHOW_ONLY_ICON || e==CHATITEMHEADER_SHOW_BOTH);
}
bool LLFloaterIMNearbyChatToastPanel::canAddText ()
{
LLChatMsgBox* msg_text = findChild<LLChatMsgBox>("msg_text");
if(!msg_text)
return false;
return msg_text->getLineCount()<10;
}
BOOL LLFloaterIMNearbyChatToastPanel::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
LLUICtrl* avatar_icon = getChild<LLUICtrl>("avatar_icon", false);
S32 local_x = x - avatar_icon->getRect().mLeft;
S32 local_y = y - avatar_icon->getRect().mBottom;
//eat message for avatar icon if msg was from object
if(avatar_icon->pointInView(local_x, local_y) && mSourceType != CHAT_SOURCE_AGENT)
return TRUE;
return LLPanel::handleRightMouseDown(x,y,mask);
}
void LLFloaterIMNearbyChatToastPanel::draw()
{
LLPanel::draw();
if(mIsDirty)
{
LLAvatarIconCtrl* icon = getChild<LLAvatarIconCtrl>("avatar_icon", false);
if(icon)
{
icon->setDrawTooltip(mSourceType == CHAT_SOURCE_AGENT);
if(mSourceType == CHAT_SOURCE_OBJECT)
icon->setValue(LLSD("OBJECT_Icon"));
else if(mSourceType == CHAT_SOURCE_SYSTEM)
icon->setValue(LLSD("SL_Logo"));
else if(mSourceType == CHAT_SOURCE_AGENT)
icon->setValue(mFromID);
else if(!mFromID.isNull())
icon->setValue(mFromID);
}
mIsDirty = false;
}
}
|