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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
|
/**
* @file llnotify.cpp
* @brief Non-blocking notification that doesn't take keyboard focus.
*
* $LicenseInfo:firstyear=2003&license=viewergpl$
*
* Copyright (c) 2003-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llnotify.h"
#include "llchat.h"
#include "llfocusmgr.h"
#include "llrender.h"
#include "llbutton.h"
#include "llfocusmgr.h"
#include "llglheaders.h"
#include "lliconctrl.h"
#include "lltextbox.h"
#include "lltexteditor.h"
#include "lluiconstants.h"
#include "llui.h"
#include "llxmlnode.h"
#include "llalertdialog.h"
#include "llviewercontrol.h"
#include "llviewerdisplay.h"
#include "llviewerimagelist.h"
#include "llfloaterchat.h" // for add_chat_history()
#include "lloverlaybar.h" // for gOverlayBar
#include "lluictrlfactory.h"
#include "hippogridmanager.h"
// [RLVa:KB] - Version: 1.23.4
#include "rlvhandler.h"
// [/RLVa:KB]
// Globals
LLNotifyBoxView* gNotifyBoxView = NULL;
const F32 ANIMATION_TIME = 0.333f;
const S32 BOTTOM_PAD = VPAD * 3;
// statics
S32 LLNotifyBox::sNotifyBoxCount = 0;
const LLFontGL* LLNotifyBox::sFont = NULL;
const LLFontGL* LLNotifyBox::sFontSmall = NULL;
std::map<std::string, LLNotifyBox*> LLNotifyBox::sOpenUniqueNotifyBoxes;
//---------------------------------------------------------------------------
// LLNotifyBox
//---------------------------------------------------------------------------
//static
void LLNotifyBox::initClass()
{
LLNotificationChannel::buildChannel("Notifications", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notify"));
LLNotificationChannel::buildChannel("NotificationTips", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "notifytip"));
LLNotifications::instance().getChannel("Notifications")->connectChanged(&LLNotifyBox::onNotification);
LLNotifications::instance().getChannel("NotificationTips")->connectChanged(&LLNotifyBox::onNotification);
}
//static
bool LLNotifyBox::onNotification(const LLSD& notify)
{
LLNotificationPtr notification = LLNotifications::instance().find(notify["id"].asUUID());
if (!notification) return false;
if(notify["sigtype"].asString() == "add" || notify["sigtype"].asString() == "change")
{
//bring existing notification to top
LLNotifyBox* boxp = LLNotifyBox::getInstance(notification->getID());
if (boxp && !boxp->isDead())
{
gNotifyBoxView->showOnly(boxp);
}
else
{
bool is_script_dialog = (notification->getName() == "ScriptDialog" || notification->getName() == "ScriptDialogGroup");
LLNotifyBox* notify_box = new LLNotifyBox(
notification,
is_script_dialog); //layout_script_dialog);
gNotifyBoxView->addChild(notify_box);
}
}
else if (notify["sigtype"].asString() == "delete")
{
LLNotifyBox* boxp = LLNotifyBox::getInstance(notification->getID());
if (boxp && !boxp->isDead())
{
boxp->close();
}
}
return false;
}
//---------------------------------------------------------------------------
LLNotifyBox::LLNotifyBox(LLNotificationPtr notification,
BOOL layout_script_dialog)
: LLPanel(notification->getName(), LLRect(), BORDER_NO),
LLEventTimer(notification->getExpiration() == LLDate()
? LLDate(LLDate::now().secondsSinceEpoch() + (F64)gSavedSettings.getF32("NotifyTipDuration"))
: notification->getExpiration()),
LLInstanceTracker<LLNotifyBox, LLUUID>(notification->getID()),
mNotification(notification),
mIsTip(notification->getType() == "notifytip"),
mAnimating(TRUE),
mNextBtn(NULL),
mNumOptions(0),
mNumButtons(0),
mAddedDefaultBtn(FALSE),
mLayoutScriptDialog(layout_script_dialog)
{
// clicking on a button does not steal current focus
setIsChrome(TRUE);
// class init
if (!sFont)
{
sFont = LLFontGL::getFontSansSerif();
sFontSmall = LLFontGL::getFontSansSerifSmall();
}
// setup paramaters
mMessage = notification->getMessage();
// initialize
setFocusRoot(!mIsTip);
// caution flag can be set explicitly by specifying it in the
// notification payload, or it can be set implicitly if the
// notify xml template specifies that it is a caution
//
// tip-style notification handle 'caution' differently -
// they display the tip in a different color
mIsCaution = notification->getPriority() >= NOTIFICATION_PRIORITY_HIGH;
// Only animate first window
if( gNotifyBoxView->getChildCount() > 0 )
mAnimating = FALSE;
else
mAnimating = TRUE;
LLNotificationFormPtr form(notification->getForm());
mNumOptions = form->getNumElements();
LLRect rect = mIsTip ? getNotifyTipRect(mMessage)
: getNotifyRect(mNumOptions, layout_script_dialog, mIsCaution);
setRect(rect);
setFollows(mIsTip ? (FOLLOWS_BOTTOM|FOLLOWS_RIGHT) : (FOLLOWS_TOP|FOLLOWS_RIGHT));
setBackgroundVisible(FALSE);
setBackgroundOpaque(TRUE);
LLIconCtrl* icon;
LLTextEditor* text;
const S32 TOP = getRect().getHeight() - (mIsTip ? (S32)sFont->getLineHeight() : 32);
const S32 BOTTOM = (S32)sFont->getLineHeight();
S32 x = HPAD + HPAD;
S32 y = TOP;
if (mIsTip)
{
// use the tip notification icon
icon = new LLIconCtrl(std::string("icon"), LLRect(x, y, x+32, TOP-32), std::string("notify_tip_icon.tga"));
}
else if (mIsCaution)
{
// use the caution notification icon
icon = new LLIconCtrl(std::string("icon"), LLRect(x, y, x+32, TOP-32), std::string("notify_caution_icon.tga"));
}
else
{
// use the default notification icon
icon = new LLIconCtrl(std::string("icon"), LLRect(x, y, x+32, TOP-32), std::string("notify_box_icon.tga"));
}
icon->setMouseOpaque(FALSE);
addChild(icon);
x += HPAD + HPAD + 32;
// add a caution textbox at the top of a caution notification
LLTextBox* caution_box = NULL;
if (mIsCaution && !mIsTip)
{
S32 caution_height = ((S32)sFont->getLineHeight() * 2) + VPAD;
caution_box = new LLTextBox(
std::string("caution_box"),
LLRect(x, y, getRect().getWidth() - 2, caution_height),
LLStringUtil::null,
sFont,
FALSE);
caution_box->setFontStyle(LLFontGL::BOLD);
caution_box->setColor(gColors.getColor("NotifyCautionWarnColor"));
static LLColor4* sNotifyCautionBoxColor = rebind_llcontrol<LLColor4>("NotifyCautionBoxColor", &gColors, true);
caution_box->setBackgroundColor((*sNotifyCautionBoxColor));
caution_box->setBorderVisible(FALSE);
caution_box->setWrappedText(notification->getMessage());
addChild(caution_box);
// adjust the vertical position of the next control so that
// it appears below the caution textbox
y = y - caution_height;
}
else
{
const S32 BTN_TOP = BOTTOM_PAD + (((mNumOptions-1+2)/3)) * (BTN_HEIGHT+VPAD);
// Tokenization on \n is handled by LLTextBox
const S32 MAX_LENGTH = 512 + 20 +
DB_FIRST_NAME_BUF_SIZE +
DB_LAST_NAME_BUF_SIZE +
DB_INV_ITEM_NAME_BUF_SIZE; // For script dialogs: add space for title.
text = new LLTextEditor(std::string("box"),
LLRect(x, y, getRect().getWidth()-2, mIsTip ? BOTTOM : BTN_TOP+16),
MAX_LENGTH,
mMessage,
sFont,
FALSE);
text->setWordWrap(TRUE);
text->setTabStop(FALSE);
text->setMouseOpaque(FALSE);
text->setBorderVisible(FALSE);
text->setTakesNonScrollClicks(FALSE);
text->setHideScrollbarForShortDocs(TRUE);
text->setReadOnlyBgColor ( LLColor4::transparent ); // the background color of the box is manually
// rendered under the text box, therefore we want
// the actual text box to be transparent
text->setReadOnlyFgColor ( gColors.getColor("NotifyTextColor") );
text->setEnabled(FALSE); // makes it read-only
text->setTabStop(FALSE); // can't tab to it (may be a problem for scrolling via keyboard)
addChild(text);
}
if (mIsTip)
{
// TODO: Make a separate archive for these.
LLChat chat(mMessage);
chat.mSourceType = CHAT_SOURCE_SYSTEM;
// [RLVa:KB] - Checked: 2009-07-10 (RLVa-1.0.0e) | Added: RLVa-0.2.0b
if (rlv_handler_t::isEnabled())
{
// Notices should already have their contents filtered where necessary
chat.mRlvLocFiltered = chat.mRlvNamesFiltered = TRUE;
}
// [/RLVa:KB]
LLFloaterChat::getInstance(LLSD())->addChatHistory(chat);
}
else
{
LLButton* btn;
btn = new LLButton(std::string("next"),
LLRect(getRect().getWidth()-26, BOTTOM_PAD + 20, getRect().getWidth()-2, BOTTOM_PAD),
std::string("notify_next.png"),
std::string("notify_next.png"),
LLStringUtil::null,
onClickNext,
this,
sFont);
btn->setScaleImage(TRUE);
btn->setToolTip(std::string("Next")); // *TODO: Translate
addChild(btn);
mNextBtn = btn;
for (S32 i = 0; i < mNumOptions; i++)
{
LLSD form_element = form->getElement(i);
if (form_element["type"].asString() != "button")
{
continue;
}
addButton(form_element["name"].asString(), form_element["text"].asString(), TRUE, form_element["default"].asBoolean());
}
if (mNumButtons == 0)
{
addButton("OK", "OK", FALSE, TRUE);
mAddedDefaultBtn = TRUE;
}
sNotifyBoxCount++;
if (sNotifyBoxCount <= 0)
{
llwarns << "A notification was mishandled. sNotifyBoxCount = " << sNotifyBoxCount << llendl;
}
// If this is the only notify box, don't show the next button
if (sNotifyBoxCount == 1
&& mNextBtn)
{
mNextBtn->setVisible(FALSE);
}
}
}
// virtual
LLNotifyBox::~LLNotifyBox()
{
std::for_each(mBtnCallbackData.begin(), mBtnCallbackData.end(), DeletePointer());
}
// virtual
LLButton* LLNotifyBox::addButton(const std::string& name, const std::string& label, BOOL is_option, BOOL is_default)
{
// make caution notification buttons slightly narrower
// so that 3 of them can fit without overlapping the "next" button
S32 btn_width = mIsCaution? 84 : 90;
LLRect btn_rect;
LLButton* btn;
S32 btn_height= BTN_HEIGHT;
const LLFontGL* font = sFont;
S32 ignore_pad = 0;
S32 button_index = mNumButtons;
S32 index = button_index;
S32 x = (HPAD * 4) + 32;
if (mLayoutScriptDialog)
{
// Add two "blank" option spaces, before the "Ignore" button
index = button_index + 2;
if (button_index == 0)
{
// Ignore button is smaller, less wide
btn_height = BTN_HEIGHT_SMALL;
font = sFontSmall;
ignore_pad = 10;
}
}
btn_rect.setOriginAndSize(x + (index % 3) * (btn_width+HPAD+HPAD) + ignore_pad,
BOTTOM_PAD + (index / 3) * (BTN_HEIGHT+VPAD),
btn_width - 2*ignore_pad,
btn_height);
InstanceAndS32* userdata = new InstanceAndS32;
userdata->mSelf = this;
userdata->mButtonName = is_option ? name : "";
mBtnCallbackData.push_back(userdata);
btn = new LLButton(name, btn_rect, "", onClickButton, userdata);
btn->setLabel(label);
btn->setFont(font);
if (mIsCaution)
{
btn->setImageColor(LLUI::sColorsGroup->getColor("ButtonCautionImageColor"));
btn->setDisabledImageColor(LLUI::sColorsGroup->getColor("ButtonCautionImageColor"));
}
addChild(btn, -1);
if (is_default)
{
setDefaultBtn(btn);
}
mNumButtons++;
return btn;
}
BOOL LLNotifyBox::handleMouseUp(S32 x, S32 y, MASK mask)
{
if (mIsTip)
{
mNotification->respond(mNotification->getResponseTemplate(LLNotification::WITH_DEFAULT_BUTTON));
close();
return TRUE;
}
setFocus(TRUE);
return LLPanel::handleMouseUp(x, y, mask);
}
// virtual
BOOL LLNotifyBox::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
if (!mIsTip)
{
moveToBack(true);
return TRUE;
}
return LLPanel::handleRightMouseDown(x, y, mask);
}
// virtual
void LLNotifyBox::draw()
{
// If we are teleporting, stop the timer and restart it when the teleporting completes
if (gTeleportDisplay)
{
mEventTimer.stop();
}
else if (!mEventTimer.getStarted())
{
mEventTimer.start();
}
F32 display_time = mAnimateTimer.getElapsedTimeF32();
if (mAnimating && display_time < ANIMATION_TIME)
{
glMatrixMode(GL_MODELVIEW);
LLUI::pushMatrix();
S32 height = getRect().getHeight();
F32 fraction = display_time / ANIMATION_TIME;
F32 voffset = (1.f - fraction) * height;
if (mIsTip) voffset *= -1.f;
LLUI::translate(0.f, voffset, 0.f);
drawBackground();
LLPanel::draw();
LLUI::popMatrix();
}
else
{
if(mAnimating)
{
mAnimating = FALSE;
if(!mIsTip)
{
// hide everyone behind me once I'm done animating
gNotifyBoxView->showOnly(this);
}
}
drawBackground();
LLPanel::draw();
}
}
void LLNotifyBox::drawBackground() const
{
LLUIImagePtr imagep = LLUI::getUIImage("rounded_square.tga");
if (imagep)
{
gGL.getTexUnit(0)->bind(imagep->getImage());
// set proper background color depending on whether notify box is a caution or not
static LLColor4* sNotifyCautionBoxColor = rebind_llcontrol<LLColor4>("NotifyCautionBoxColor", &gColors, true);
static LLColor4* sNotifyBoxColor = rebind_llcontrol<LLColor4>("NotifyBoxColor", &gColors, true);
LLColor4 color = mIsCaution? (*sNotifyCautionBoxColor) : (*sNotifyBoxColor);
if(gFocusMgr.childHasKeyboardFocus( this ))
{
const S32 focus_width = 2;
color = gColors.getColor("FloaterFocusBorderColor");
gGL.color4fv(color.mV);
gl_segmented_rect_2d_tex(-focus_width, getRect().getHeight() + focus_width,
getRect().getWidth() + focus_width, -focus_width,
imagep->getTextureWidth(), imagep->getTextureHeight(),
16, mIsTip ? ROUNDED_RECT_TOP : ROUNDED_RECT_BOTTOM);
color = gColors.getColor("ColorDropShadow");
gGL.color4fv(color.mV);
gl_segmented_rect_2d_tex(0, getRect().getHeight(), getRect().getWidth(), 0, imagep->getTextureWidth(), imagep->getTextureHeight(), 16, mIsTip ? ROUNDED_RECT_TOP : ROUNDED_RECT_BOTTOM);
if( mIsCaution )
color = (*sNotifyCautionBoxColor);
else
color = (*sNotifyBoxColor);
gGL.color4fv(color.mV);
gl_segmented_rect_2d_tex(1, getRect().getHeight()-1, getRect().getWidth()-1, 1, imagep->getTextureWidth(), imagep->getTextureHeight(), 16, mIsTip ? ROUNDED_RECT_TOP : ROUNDED_RECT_BOTTOM);
}
else
{
gGL.color4fv(color.mV);
gl_segmented_rect_2d_tex(0, getRect().getHeight(), getRect().getWidth(), 0, imagep->getTextureWidth(), imagep->getTextureHeight(), 16, mIsTip ? ROUNDED_RECT_TOP : ROUNDED_RECT_BOTTOM);
}
}
}
void LLNotifyBox::close()
{
BOOL isTipTmp = mIsTip;
if (!mIsTip)
{
sNotifyBoxCount--;
}
die();
if(!isTipTmp)
{
LLNotifyBox * front = gNotifyBoxView->getFirstNontipBox();
if(front)
{
gNotifyBoxView->showOnly(front);
// we're assuming that close is only called by user action (for non-tips),
// so we then give focus to the next close button
if (front->getDefaultButton())
{
front->getDefaultButton()->setFocus(TRUE);
}
gFocusMgr.triggerFocusFlash(); // TODO it's ugly to call this here
}
}
}
void LLNotifyBox::format(std::string& msg, const LLStringUtil::format_map_t& args)
{
LLStringUtil::format_map_t targs = args;
// These sort of things are actually set in llui/llnotifications.cpp
// so that they will affect all notifications, not just boxes.
// targs["[SECOND_LIFE]"] = LLNotifications::instance().getGlobalString("SECOND_LIFE");
// targs["[VIEWER_NAME]"] = LLNotifications::instance().getGlobalString("VIEWER_NAME");
//targs["[GRID_NAME]"] = gHippoGridManager->getConnectedGrid()->getGridName();
//targs["[GRID_SITE]"] = gHippoGridManager->getConnectedGrid()->getWebSite();
//targs["[CURRENCY]"] = gHippoGridManager->getConnectedGrid()->getCurrencySymbol();
LLStringUtil::format(msg, targs);
}
/*virtual*/
BOOL LLNotifyBox::tick()
{
if (mIsTip)
{
close();
}
return FALSE;
}
void LLNotifyBox::setVisible(BOOL visible)
{
// properly set the status of the next button
if(visible && !mIsTip)
{
mNextBtn->setVisible(sNotifyBoxCount > 1);
mNextBtn->setEnabled(sNotifyBoxCount > 1);
}
LLPanel::setVisible(visible);
}
void LLNotifyBox::moveToBack(bool getfocus)
{
// Move this dialog to the back.
gNotifyBoxView->sendChildToBack(this);
if(!mIsTip && mNextBtn)
{
mNextBtn->setVisible(FALSE);
// And enable the next button on the frontmost one, if there is one
if (gNotifyBoxView->getChildCount() > 0)
{
LLNotifyBox* front = gNotifyBoxView->getFirstNontipBox();
if (front)
{
gNotifyBoxView->showOnly(front);
if (getfocus)
{
// if are called from a user interaction
// we give focus to the next next button
if (front->mNextBtn != NULL)
{
front->mNextBtn->setFocus(TRUE);
}
gFocusMgr.triggerFocusFlash(); // TODO: it's ugly to call this here
}
}
}
}
}
// static
LLRect LLNotifyBox::getNotifyRect(S32 num_options, BOOL layout_script_dialog, BOOL is_caution)
{
S32 notify_height = gSavedSettings.getS32("NotifyBoxHeight");
if (is_caution)
{
// make caution-style dialog taller to accomodate extra text,
// as well as causing the accept/decline buttons to be drawn
// in a different position, to help prevent "quick-click-through"
// of many permissions prompts
notify_height = gSavedSettings.getS32("PermissionsCautionNotifyBoxHeight");
}
const S32 NOTIFY_WIDTH = gSavedSettings.getS32("NotifyBoxWidth");
const S32 TOP = gNotifyBoxView->getRect().getHeight();
const S32 RIGHT = gNotifyBoxView->getRect().getWidth();
const S32 LEFT = RIGHT - NOTIFY_WIDTH;
if (num_options < 1)
{
num_options = 1;
}
// Add two "blank" option spaces.
if (layout_script_dialog)
{
num_options += 2;
}
S32 additional_lines = (num_options-1) / 3;
notify_height += additional_lines * (BTN_HEIGHT + VPAD);
return LLRect(LEFT, TOP, RIGHT, TOP-notify_height);
}
// static
LLRect LLNotifyBox::getNotifyTipRect(const std::string &utf8message)
{
S32 line_count = 1;
LLWString message = utf8str_to_wstring(utf8message);
S32 message_len = message.length();
const S32 NOTIFY_WIDTH = gSavedSettings.getS32("NotifyBoxWidth");
// Make room for the icon area.
const S32 text_area_width = NOTIFY_WIDTH - HPAD * 4 - 32;
const llwchar* wchars = message.c_str();
const llwchar* start = wchars;
const llwchar* end;
S32 total_drawn = 0;
BOOL done = FALSE;
do
{
line_count++;
for (end=start; *end != 0 && *end != '\n'; end++)
;
if( *end == 0 )
{
end = wchars + message_len;
done = TRUE;
}
S32 remaining = end - start;
while( remaining )
{
S32 drawn = sFont->maxDrawableChars( start, (F32)text_area_width, remaining, TRUE );
if( 0 == drawn )
{
drawn = 1; // Draw at least one character, even if it doesn't all fit. (avoids an infinite loop)
}
total_drawn += drawn;
start += drawn;
remaining -= drawn;
if( total_drawn < message_len )
{
if( (wchars[ total_drawn ] != '\n') )
{
// wrap because line was too long
line_count++;
}
}
else
{
done = TRUE;
}
}
total_drawn++; // for '\n'
end++;
start = end;
} while( !done );
const S32 MIN_NOTIFY_HEIGHT = 72;
const S32 MAX_NOTIFY_HEIGHT = 600;
S32 notify_height = llceil((F32) (line_count+1) * sFont->getLineHeight());
if(gOverlayBar)
{
notify_height += gOverlayBar->getBoundingRect().mTop;
}
else
{
// *FIX: this is derived from the padding caused by the
// rounded rects, shouldn't be a const here.
notify_height += 10;
}
notify_height += VPAD;
notify_height = llclamp(notify_height, MIN_NOTIFY_HEIGHT, MAX_NOTIFY_HEIGHT);
const S32 RIGHT = gNotifyBoxView->getRect().getWidth();
const S32 LEFT = RIGHT - NOTIFY_WIDTH;
// Make sure it goes slightly offscreen
return LLRect(LEFT, notify_height-1, RIGHT, -1);
}
// static
void LLNotifyBox::onClickButton(void* data)
{
InstanceAndS32* self_and_button = (InstanceAndS32*)data;
LLNotifyBox* self = self_and_button->mSelf;
std::string button_name = self_and_button->mButtonName;
LLSD response = self->mNotification->getResponseTemplate();
if (!self->mAddedDefaultBtn && !button_name.empty())
{
response[button_name] = true;
}
self->mNotification->respond(response);
}
// static
void LLNotifyBox::onClickNext(void* data)
{
LLNotifyBox* self = static_cast<LLNotifyBox*>(data);
self->moveToBack(true);
}
LLNotifyBoxView::LLNotifyBoxView(const std::string& name, const LLRect& rect, BOOL mouse_opaque, U32 follows)
: LLUICtrl(name,rect,mouse_opaque,NULL,NULL,follows)
{
}
LLNotifyBox * LLNotifyBoxView::getFirstNontipBox() const
{
// *TODO: Don't make assumptions like this!
// assumes every child is a notify box
for(child_list_const_iter_t iter = getChildList()->begin();
iter != getChildList()->end();
iter++)
{
// hack! *TODO: Integrate llnotify and llgroupnotify
if(isGroupNotifyBox(*iter))
{
continue;
}
LLNotifyBox* box = (LLNotifyBox*)(*iter);
if(!box->isTip() && !box->isDead())
{
return box;
}
}
return NULL;
}
void LLNotifyBoxView::showOnly(LLView * view)
{
if(view)
{
// assumes that the argument is actually a child
LLNotifyBox * shown = dynamic_cast<LLNotifyBox*>(view);
if(!shown)
{
return ;
}
// make every other notification invisible
for(child_list_const_iter_t iter = getChildList()->begin();
iter != getChildList()->end();
iter++)
{
if(isGroupNotifyBox(*iter))
{
continue;
}
LLNotifyBox * box = (LLNotifyBox*)(*iter);
if(box != view && box->getVisible() && !box->isTip())
{
box->setVisible(FALSE);
}
}
shown->setVisible(TRUE);
sendChildToFront(shown);
}
}
void LLNotifyBoxView::purgeMessagesMatching(const Matcher& matcher)
{
// Make a *copy* of the child list to iterate over
// since we'll be removing items from the real list as we go.
LLView::child_list_t notification_queue(*getChildList());
for(LLView::child_list_iter_t iter = notification_queue.begin();
iter != notification_queue.end();
iter++)
{
if(isGroupNotifyBox(*iter))
{
continue;
}
LLNotifyBox* notification = (LLNotifyBox*)*iter;
if(matcher.matches(notification->getNotification()))
{
removeChild(notification);
}
}
}
bool LLNotifyBoxView::isGroupNotifyBox(const LLView* view) const
{
if (view->getName() == "groupnotify")
{
return TRUE ;
}
return FALSE ;
}
|