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
|
/**
* @file lltabcontainervertical.cpp
* @brief LLTabContainerVertical base class
*
* Copyright (c) 2001-2007, 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://secondlife.com/developers/opensource/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://secondlife.com/developers/opensource/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.
*/
// Fear my script-fu!
#include "linden_common.h"
#include "lltabcontainervertical.h"
#include "llfocusmgr.h"
#include "llfontgl.h"
#include "llgl.h"
#include "llbutton.h"
#include "llrect.h"
#include "llpanel.h"
#include "llresmgr.h"
#include "llkeyboard.h"
#include "llui.h"
#include "lltextbox.h"
#include "llcontrol.h"
#include "llcriticaldamp.h"
#include "llglheaders.h"
LLTabContainerVertical::LLTabContainerVertical(
const LLString& name, const LLRect& rect,
void(*close_callback)(void*), void* callback_userdata,
U32 tab_width, BOOL bordered)
:
LLTabContainerCommon(name, rect, LEFT, close_callback, callback_userdata, bordered),
mTabWidth(tab_width),
mUpArrowBtn(NULL),
mDownArrowBtn(NULL)
{
initButtons();
}
LLTabContainerVertical::LLTabContainerVertical(
const LLString& name, const LLString& rect_control,
void(*close_callback)(void*), void* callback_userdata,
U32 tab_width, BOOL bordered)
:
LLTabContainerCommon(name, rect_control, LEFT, close_callback, callback_userdata, bordered),
mTabWidth(tab_width)
{
initButtons();
}
// Called from all constructors
void LLTabContainerVertical::initButtons()
{
// Hack:
if (mRect.getHeight() == 0 || mUpArrowBtn)
{
return; // Don't have a rect yet or already got called
}
LLString out_id;
LLString in_id;
//S32 arrow_fudge = 1; // match new art better
// Left and right scroll arrows (for when there are too many tabs to show all at once).
S32 btn_top = mRect.getHeight();
S32 btn_top_lower = mRect.mBottom+TABCNTRV_ARROW_BTN_SIZE;
LLRect up_arrow_btn_rect;
up_arrow_btn_rect.setLeftTopAndSize( mTabWidth/2 , btn_top, TABCNTRV_ARROW_BTN_SIZE, TABCNTRV_ARROW_BTN_SIZE );
LLRect down_arrow_btn_rect;
down_arrow_btn_rect.setLeftTopAndSize( mTabWidth/2 , btn_top_lower, TABCNTRV_ARROW_BTN_SIZE, TABCNTRV_ARROW_BTN_SIZE );
out_id = "UIImgBtnScrollUpOutUUID";
in_id = "UIImgBtnScrollUpInUUID";
mUpArrowBtn = new LLButton(
"Up Arrow", up_arrow_btn_rect,
out_id, in_id, "",
&onPrevBtn, this, NULL );
mUpArrowBtn->setHeldDownCallback(onPrevBtnHeld);
mUpArrowBtn->setSaveToXML(false);
mUpArrowBtn->setFollowsTop();
mUpArrowBtn->setFollowsLeft();
mUpArrowBtn->setTabStop(FALSE);
addChild(mUpArrowBtn);
out_id = "UIImgBtnScrollDownOutUUID";
in_id = "UIImgBtnScrollDownInUUID";
mDownArrowBtn = new LLButton(
"Down Arrow", down_arrow_btn_rect,
out_id, in_id, "",
&onNextBtn, this, NULL );
mDownArrowBtn->setHeldDownCallback(onNextBtnHeld);
mDownArrowBtn->setSaveToXML(false);
mDownArrowBtn->setFollowsBottom();
mDownArrowBtn->setFollowsLeft();
mDownArrowBtn->setTabStop(FALSE);
addChild(mDownArrowBtn);
// set default tab group to be panel contents
mDefaultTabGroup = 1;
}
LLTabContainerVertical::~LLTabContainerVertical()
{ }
void LLTabContainerVertical::addTabPanel(LLPanel* child, const LLString& label,
BOOL select,
void (*on_tab_clicked)(void*, bool), void* userdata,
S32 indent,
BOOL placeholder, eInsertionPoint insertion_point)
{
if (child->getParent() == this)
{
// already a child of mine
return;
}
const LLFontGL* font = gResMgr->getRes( LLFONT_SANSSERIF );
// Store the original label for possible xml export.
child->setLabel(label);
// Replace long label with truncated version (e.g., "FooBa...")
LLString trimmed_label = label;
LLString::trim(trimmed_label);
// Tab panel
S32 tab_panel_top;
S32 tab_panel_bottom;
tab_panel_top = mRect.getHeight()
- mTopBorderHeight
- (BTN_HEIGHT - TABCNTRV_BUTTON_PANEL_OVERLAP);
tab_panel_bottom = LLPANEL_BORDER_WIDTH;
LLRect tab_panel_rect(
mTabWidth + (LLPANEL_BORDER_WIDTH * 2) + TABCNTRV_PAD,
mRect.getHeight() - LLPANEL_BORDER_WIDTH,
mRect.getWidth() - LLPANEL_BORDER_WIDTH,
LLPANEL_BORDER_WIDTH);
child->setFollowsAll();
child->translate( tab_panel_rect.mLeft - child->getRect().mLeft, tab_panel_rect.mBottom - child->getRect().mBottom);
child->reshape( tab_panel_rect.getWidth(), tab_panel_rect.getHeight(), TRUE );
child->setBackgroundVisible( FALSE ); // No need to overdraw
child->setVisible( FALSE ); // Will be made visible when selected
// Tab button
LLRect btn_rect;
btn_rect.setLeftTopAndSize(
TABCNTRV_PAD + LLPANEL_BORDER_WIDTH + 2, // JC - Fudge factor
(mRect.getHeight() - mTopBorderHeight - LLPANEL_BORDER_WIDTH - 1) - ((BTN_HEIGHT + TABCNTRV_PAD) * mTabList.size()),
mTabWidth,
BTN_HEIGHT);
if (!placeholder)
{
LLButton *btn = new LLButton("vert tab button",
btn_rect,
"tab_left.tga",
"tab_left_selected.tga",
"",
&LLTabContainerVertical::onTabBtn, NULL,
font,
trimmed_label, trimmed_label);
btn->setSaveToXML(false);
btn->setFixedBorder(16, 16);
btn->setScaleImage(TRUE);
btn->setHAlign(LLFontGL::LEFT);
btn->setFollows(FOLLOWS_TOP | FOLLOWS_LEFT);
btn->setTabStop(FALSE);
if (indent)
{
btn->setLeftHPad(indent);
}
LLTabTuple* tuple = new LLTabTuple( this, child, btn, on_tab_clicked, userdata );
insertTuple( tuple, insertion_point );
btn->setCallbackUserData( tuple );
addChild( btn, 0 );
addChild(child, 1);
if( select )
{
selectTab( mTabList.size()-1 );
}
}
else
{
btn_rect.translate(0, -LLBUTTON_V_PAD-2);
LLString box_label = trimmed_label;
LLTextBox* text = new LLTextBox(box_label, btn_rect, box_label, font);
text->setSaveToXML(false);
addChild( text, 0 );
LLButton* btn = new LLButton("", LLRect(0,0,0,0));
btn->setSaveToXML(false);
addChild(btn, 0);
addChild(child, 1);
LLTabTuple* tuple = new LLTabTuple( this, child, btn, on_tab_clicked, userdata, text );
insertTuple( tuple, insertion_point );
}
updateMaxScrollPos();
}
void LLTabContainerVertical::removeTabPanel(LLPanel* child)
{
LLTabContainerCommon::removeTabPanel(child);
// Fix-up button sizes
S32 tab_count = 0;
for(std::vector<LLTabTuple*>::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
{
LLTabTuple* tuple = *iter;
LLRect rect;
rect.setLeftTopAndSize(TABCNTRV_PAD + LLPANEL_BORDER_WIDTH + 2, // JC - Fudge factor
(mRect.getHeight() - LLPANEL_BORDER_WIDTH - 1) - ((BTN_HEIGHT + TABCNTRV_PAD) * (tab_count)),
mTabWidth,
BTN_HEIGHT);
if (tuple->mPlaceholderText)
{
tuple->mPlaceholderText->setRect(rect);
}
else
{
tuple->mButton->setRect(rect);
}
tab_count++;
}
}
void LLTabContainerVertical::updateMaxScrollPos()
{
S32 tab_total_height = (BTN_HEIGHT + TABCNTRV_PAD) * mTabList.size();
S32 available_height = mRect.getHeight() - mTopBorderHeight;
if( tab_total_height > available_height )
{
S32 available_height_with_arrows = mRect.getHeight() - 2*(TABCNTRV_ARROW_BTN_SIZE + 3*TABCNTRV_PAD);
S32 additional_needed = tab_total_height - available_height_with_arrows;
mMaxScrollPos = S32( ceil(additional_needed / float(BTN_HEIGHT) ) );
}
else
{
mMaxScrollPos = 0;
mScrollPos = 0;
}
if (mScrollPos > mMaxScrollPos)
{
mScrollPos = mMaxScrollPos;
}
}
void LLTabContainerVertical::commitHoveredButton(S32 x, S32 y)
{
if (hasMouseCapture())
{
for(std::vector<LLTabTuple*>::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
{
LLTabTuple* tuple = *iter;
tuple->mButton->setVisible( TRUE );
S32 local_x = x - tuple->mButton->getRect().mLeft;
S32 local_y = y - tuple->mButton->getRect().mBottom;
if (tuple->mButton->pointInView(local_x, local_y) && tuple->mButton->getEnabled() && !tuple->mTabPanel->getVisible())
{
tuple->mButton->onCommit();
}
}
}
}
BOOL LLTabContainerVertical::selectTab(S32 which)
{
if (which >= (S32)mTabList.size()) return FALSE;
if (which < 0) return FALSE;
//if( gFocusMgr.childHasKeyboardFocus( this ) )
//{
// gFocusMgr.setKeyboardFocus( NULL, NULL );
//}
LLTabTuple* selected_tuple = mTabList[which];
if (!selected_tuple)
{
return FALSE;
}
BOOL is_visible = FALSE;
if (which != mCurrentTabIdx)
{
mCurrentTabIdx = which;
S32 i = 0;
for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
{
LLTabTuple* tuple = *iter;
BOOL is_selected = ( tuple == selected_tuple );
tuple->mTabPanel->setVisible( is_selected );
// tuple->mTabPanel->setFocus(is_selected); // not clear that we want to do this here.
tuple->mButton->setToggleState( is_selected );
// RN: this limits tab-stops to active button only, which would require arrow keys to switch tabs
tuple->mButton->setTabStop( is_selected );
if( is_selected )
{
// Make sure tab is within scroll
S32 num_visible = mTabList.size() - mMaxScrollPos;
if( i >= mScrollPos && i <= mScrollPos + num_visible)
{
mCurrentTabIdx = which;
is_visible = TRUE;
}
else
{
is_visible = FALSE;
}
}
i++;
}
if( selected_tuple->mOnChangeCallback )
{
selected_tuple->mOnChangeCallback( selected_tuple->mUserData, false );
}
}
if(mCurrentTabIdx >= 0)
{
LLTabTuple* tuple = mTabList[mCurrentTabIdx];
tuple->mTabPanel->setVisible( TRUE );
tuple->mButton->setToggleState( TRUE );
}
return is_visible;
}
void LLTabContainerVertical::draw()
{
S32 target_pixel_scroll = mScrollPos * (BTN_HEIGHT + TABCNTRV_PAD);
mScrollPosPixels = (S32)lerp((F32)mScrollPosPixels, (F32)target_pixel_scroll, LLCriticalDamp::getInterpolant(0.08f));
if( getVisible() )
{
BOOL has_scroll_arrows = (mMaxScrollPos > 0) || (mScrollPosPixels > 0);
mUpArrowBtn->setVisible( has_scroll_arrows );
mDownArrowBtn->setVisible( has_scroll_arrows );
// Set the topmost position of the tab buttons.
S32 top = mRect.getHeight() - mTopBorderHeight - LLPANEL_BORDER_WIDTH - 1 - (has_scroll_arrows ? TABCNTRV_ARROW_BTN_SIZE : 0);
top += mScrollPosPixels;
// Hide all the buttons
for(std::vector<LLTabTuple*>::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
{
LLTabTuple* tuple = *iter;
tuple->mButton->setVisible( FALSE );
}
LLPanel::draw();
// Show all the buttons
for(std::vector<LLTabTuple*>::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
{
LLTabTuple* tuple = *iter;
tuple->mButton->setVisible( TRUE );
}
// Draw some of the buttons...
{
LLRect clip_rect = getLocalRect();
if (has_scroll_arrows)
{
// ...but clip them.
clip_rect.mBottom = mDownArrowBtn->getRect().mTop + 3*TABCNTRV_PAD;
clip_rect.mTop = mUpArrowBtn->getRect().mBottom - 3*TABCNTRV_PAD;
}
LLLocalClipRect clip(clip_rect);
//S32 max_scroll_visible = mTabList.size() - mMaxScrollPos + mScrollPos;
S32 idx = 0;
for(std::vector<LLTabTuple*>::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
{
LLTabTuple* tuple = *iter;
tuple->mButton->translate( 0 , top - tuple->mButton->getRect().mTop);
top -= BTN_HEIGHT + TABCNTRV_PAD;
LLUI::pushMatrix();
{
LLUI::translate((F32)tuple->mButton->getRect().mLeft, (F32)tuple->mButton->getRect().mBottom, 0.f);
tuple->mButton->draw();
}
LLUI::popMatrix();
idx++;
}
if( has_scroll_arrows )
{
// Redraw the arrows so that they appears on top.
glPushMatrix();
glTranslatef((F32)mUpArrowBtn->getRect().mLeft, (F32)mUpArrowBtn->getRect().mBottom, 0.f);
mUpArrowBtn->draw();
glPopMatrix();
glPushMatrix();
glTranslatef((F32)mDownArrowBtn->getRect().mLeft, (F32)mDownArrowBtn->getRect().mBottom, 0.f);
mDownArrowBtn->draw();
glPopMatrix();
}
}
}
}
BOOL LLTabContainerVertical::handleMouseDown( S32 x, S32 y, MASK mask )
{
BOOL handled = FALSE;
BOOL has_scroll_arrows = (mMaxScrollPos > 0);
if (has_scroll_arrows)
{
if (mUpArrowBtn->getRect().pointInRect(x, y))
{
S32 local_x = x - mUpArrowBtn->getRect().mLeft;
S32 local_y = y - mUpArrowBtn->getRect().mBottom;
handled = mUpArrowBtn->handleMouseDown(local_x, local_y, mask);
}
else if (mDownArrowBtn->getRect().pointInRect(x, y))
{
S32 local_x = x - mDownArrowBtn->getRect().mLeft;
S32 local_y = y - mDownArrowBtn->getRect().mBottom;
handled = mDownArrowBtn->handleMouseDown(local_x, local_y, mask);
}
}
if (!handled)
{
handled = LLPanel::handleMouseDown( x, y, mask );
}
if (mTabList.size() > 0)
{
LLTabTuple* firsttuple = mTabList[0];
LLRect tab_rect(firsttuple->mButton->getRect().mLeft,
has_scroll_arrows ? mUpArrowBtn->getRect().mBottom - TABCNTRV_PAD : mUpArrowBtn->getRect().mTop,
firsttuple->mButton->getRect().mRight,
has_scroll_arrows ? mDownArrowBtn->getRect().mTop + TABCNTRV_PAD : mDownArrowBtn->getRect().mBottom );
if( tab_rect.pointInRect( x, y ) )
{
LLButton* tab_button = mTabList[getCurrentPanelIndex()]->mButton;
gFocusMgr.setMouseCapture(this);
gFocusMgr.setKeyboardFocus(tab_button, NULL);
}
}
return handled;
}
BOOL LLTabContainerVertical::handleHover( S32 x, S32 y, MASK mask )
{
BOOL handled = FALSE;
BOOL has_scroll_arrows = (mMaxScrollPos > 0);
if (has_scroll_arrows)
{
if (mUpArrowBtn->getRect().pointInRect(x, y))
{
S32 local_x = x - mUpArrowBtn->getRect().mLeft;
S32 local_y = y - mUpArrowBtn->getRect().mBottom;
handled = mUpArrowBtn->handleHover(local_x, local_y, mask);
}
else if (mDownArrowBtn->getRect().pointInRect(x, y))
{
S32 local_x = x - mDownArrowBtn->getRect().mLeft;
S32 local_y = y - mDownArrowBtn->getRect().mBottom;
handled = mDownArrowBtn->handleHover(local_x, local_y, mask);
}
}
if (!handled)
{
handled = LLPanel::handleHover(x, y, mask);
}
commitHoveredButton(x, y);
return handled;
}
BOOL LLTabContainerVertical::handleMouseUp( S32 x, S32 y, MASK mask )
{
BOOL handled = FALSE;
BOOL has_scroll_arrows = (mMaxScrollPos > 0);
if (has_scroll_arrows)
{
if (mUpArrowBtn->getRect().pointInRect(x, y))
{
S32 local_x = x - mUpArrowBtn->getRect().mLeft;
S32 local_y = y - mUpArrowBtn->getRect().mBottom;
handled = mUpArrowBtn->handleMouseUp(local_x, local_y, mask);
}
else if (mDownArrowBtn->getRect().pointInRect(x, y))
{
S32 local_x = x - mDownArrowBtn->getRect().mLeft;
S32 local_y = y - mDownArrowBtn->getRect().mBottom;
handled = mDownArrowBtn->handleMouseUp(local_x, local_y, mask);
}
}
if (!handled)
{
handled = LLPanel::handleMouseUp( x, y, mask );
}
commitHoveredButton(x, y);
LLPanel* cur_panel = getCurrentPanel();
if (hasMouseCapture())
{
if (cur_panel)
{
if (!cur_panel->focusFirstItem(FALSE))
{
mTabList[getCurrentPanelIndex()]->mButton->setFocus(TRUE);
}
}
gFocusMgr.setMouseCapture(NULL);
}
return handled;
}
BOOL LLTabContainerVertical::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent)
{
BOOL handled = FALSE;
if (getEnabled())
{
if (key == KEY_LEFT && mask == MASK_ALT)
{
selectPrevTab();
handled = TRUE;
}
else if (key == KEY_RIGHT && mask == MASK_ALT)
{
selectNextTab();
handled = TRUE;
}
// focus is on button
if (!handled && !gFocusMgr.childHasKeyboardFocus(getCurrentPanel()))
{
switch(key)
{
case KEY_UP:
selectPrevTab();
handled = TRUE;
break;
case KEY_DOWN:
selectNextTab();
handled = TRUE;
break;
case KEY_LEFT:
handled = TRUE;
break;
case KEY_RIGHT:
if (getTabPosition() == LEFT && getCurrentPanel())
{
getCurrentPanel()->setFocus(TRUE);
}
handled = TRUE;
break;
default:
break;
}
}
}
return handled;
}
// virtual
LLXMLNodePtr LLTabContainerVertical::getXML(bool save_children) const
{
LLXMLNodePtr node = LLTabContainerCommon::getXML();
// TomY TODO Is this redundant or will it be used later?
node->createChild("tab_position", TRUE)->setStringValue("left");
return node;
}
|