summaryrefslogtreecommitdiff
path: root/indra/llui/llaccordionctrl.cpp
blob: d0c73fbfbce62a6ca5742a3f4bceb6561fa49634 (plain)
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
/** 
 * @file llaccordionctrl.cpp
 * @brief Accordion panel  implementation
 *
 * $LicenseInfo:firstyear=2009&license=viewergpl$
 * 
 * Copyright (c) 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 "linden_common.h"

#include "llaccordionctrl.h"
#include "llaccordionctrltab.h"

#include "lluictrlfactory.h" // builds floaters from XML

#include "llwindow.h"
#include "llfocusmgr.h"
#include "lllocalcliprect.h"

#include "boost/bind.hpp"

static const S32 DRAGGER_BAR_MARGIN = 4;
static const S32 DRAGGER_BAR_HEIGHT = 5;
static const S32 BORDER_MARGIN = 2;
static const S32 PARENT_BORDER_MARGIN = 5;

static const S32 panel_delta = DRAGGER_BAR_MARGIN;  // Distanse between two panels 

static const S32 HORIZONTAL_MULTIPLE = 8;
static const S32 VERTICAL_MULTIPLE = 16;
static const F32 MIN_AUTO_SCROLL_RATE = 120.f;
static const F32 MAX_AUTO_SCROLL_RATE = 500.f;
static const F32 AUTO_SCROLL_RATE_ACCEL = 120.f;


// LLAccordionCtrl =================================================================|

static LLDefaultChildRegistry::Register<LLAccordionCtrl>	t2("accordion");


LLAccordionCtrl::LLAccordionCtrl(const Params& params):LLPanel(params)
 , mFitParent(params.fit_parent)
 , mAutoScrolling( false )
 , mAutoScrollRate( 0.f )
{
  mSingleExpansion = params.single_expansion;
	if(mFitParent && !mSingleExpansion)
	{
		llinfos << "fit_parent works best when combined with single_expansion" << llendl;
	}
}

LLAccordionCtrl::LLAccordionCtrl() : LLPanel()
 , mAutoScrolling( false )
 , mAutoScrollRate( 0.f )
{
	mSingleExpansion = false;
	mFitParent = false;
	LLUICtrlFactory::getInstance()->buildPanel(this, "accordion_parent.xml");	
}

//---------------------------------------------------------------------------------
void LLAccordionCtrl::draw()
{
	if (mAutoScrolling)
	{
		// add acceleration to autoscroll
		mAutoScrollRate = llmin(mAutoScrollRate + (LLFrameTimer::getFrameDeltaTimeF32() * AUTO_SCROLL_RATE_ACCEL), MAX_AUTO_SCROLL_RATE);
	}
	else
	{
		// reset to minimum for next time
		mAutoScrollRate = MIN_AUTO_SCROLL_RATE;
	}
	// clear this flag to be set on next call to autoScroll
	mAutoScrolling = false;

	LLRect local_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
	
	LLLocalClipRect clip(local_rect);
	
	LLPanel::draw();
}


//---------------------------------------------------------------------------------
BOOL LLAccordionCtrl::postBuild()
{
	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);

	LLRect scroll_rect;
	scroll_rect.setOriginAndSize( 
		getRect().getWidth() - scrollbar_size,
		1,
		scrollbar_size,
		getRect().getHeight() - 1);
	

	LLScrollbar::Params sbparams;
	sbparams.name("scrollable vertical");
	sbparams.rect(scroll_rect);
	sbparams.orientation(LLScrollbar::VERTICAL);
	sbparams.doc_size(mInnerRect.getHeight());
	sbparams.doc_pos(0);
	sbparams.page_size(mInnerRect.getHeight());
	sbparams.step_size(VERTICAL_MULTIPLE);
	sbparams.follows.flags(FOLLOWS_RIGHT | FOLLOWS_TOP | FOLLOWS_BOTTOM);
	sbparams.change_callback(boost::bind(&LLAccordionCtrl::onScrollPosChangeCallback, this, _1, _2));
	
	mScrollbar = LLUICtrlFactory::create<LLScrollbar> (sbparams);
	LLView::addChild( mScrollbar );
	mScrollbar->setVisible( false );
	mScrollbar->setFollowsRight();
	mScrollbar->setFollowsTop();
	mScrollbar->setFollowsBottom();

	//if it was created from xml...
	std::vector<LLUICtrl*> accordion_tabs;
	for(child_list_const_iter_t it = getChildList()->begin(); 
		getChildList()->end() != it; ++it)
	{
		LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(*it);
		if(accordion_tab == NULL)
			continue;
		if(std::find(mAccordionTabs.begin(),mAccordionTabs.end(),accordion_tab) == mAccordionTabs.end())
		{
			accordion_tabs.push_back(accordion_tab);
		}
	}

	for(std::vector<LLUICtrl*>::reverse_iterator it = accordion_tabs.rbegin();it!=accordion_tabs.rend();++it)
		addCollapsibleCtrl(*it);

	arrange	();

	if(mSingleExpansion)
	{
		if(!mAccordionTabs[0]->getDisplayChildren())
			mAccordionTabs[0]->setDisplayChildren(true);
		for(size_t i=1;i<mAccordionTabs.size();++i)
		{
			if(mAccordionTabs[i]->getDisplayChildren())
				mAccordionTabs[i]->setDisplayChildren(false);
		}
	}

	return TRUE;
}


//---------------------------------------------------------------------------------
LLAccordionCtrl::~LLAccordionCtrl()
{
  mAccordionTabs.clear();
}

//---------------------------------------------------------------------------------

void LLAccordionCtrl::reshape(S32 width, S32 height, BOOL called_from_parent)
{
	// adjust our rectangle
	LLRect rcLocal = getRect();
	rcLocal.mRight = rcLocal.mLeft + width;
	rcLocal.mTop = rcLocal.mBottom + height;

	setRect(rcLocal);

	arrange();
}

//---------------------------------------------------------------------------------
BOOL LLAccordionCtrl::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
	return LLPanel::handleRightMouseDown(x, y, mask);
}

//---------------------------------------------------------------------------------
void LLAccordionCtrl::shiftAccordionTabs(S16 panel_num, S32 delta)
{
	for(size_t i = panel_num; i < mAccordionTabs.size(); i++ )
	{
		ctrlShiftVertical(mAccordionTabs[i],delta);
	}	
}


//---------------------------------------------------------------------------------
void LLAccordionCtrl::onCollapseCtrlCloseOpen(S16 panel_num) 
{
	if(mSingleExpansion)
	{
		for(size_t i=0;i<mAccordionTabs.size();++i)
		{
			if(i==panel_num)
				continue;
			if(mAccordionTabs[i]->getDisplayChildren())
				mAccordionTabs[i]->setDisplayChildren(false);
		}

	}
	arrange();
}

void LLAccordionCtrl::show_hide_scrollbar(S32 width, S32 height)
{
	calcRecuiredHeight();
	if(getRecuiredHeight() > height )
		showScrollbar(width,height);
	else
		hideScrollbar(width,height);
}

void	LLAccordionCtrl::showScrollbar(S32 width, S32 height)
{
	bool was_visible = mScrollbar->getVisible();

	mScrollbar->setVisible(true);
	
	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);

	ctrlSetLeftTopAndSize(mScrollbar
		,width-scrollbar_size - PARENT_BORDER_MARGIN/2
		,height-PARENT_BORDER_MARGIN
		,scrollbar_size
		,height-2*PARENT_BORDER_MARGIN);
	
	mScrollbar->setPageSize(height);
	mScrollbar->setDocParams(mInnerRect.getHeight(),mScrollbar->getDocPos());

	if(was_visible)
	{
		S32 scroll_pos = llmin(mScrollbar->getDocPos(), getRecuiredHeight() - height - 1);
		mScrollbar->setDocPos(scroll_pos);
	}
}

void	LLAccordionCtrl::hideScrollbar( S32 width, S32 height )
{
	if(mScrollbar->getVisible() == false)
		return;
	mScrollbar->setVisible(false);

	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);

	S32 panel_width = width - 2*BORDER_MARGIN;

	//reshape all accordeons and shift all draggers
	for(size_t i=0;i<mAccordionTabs.size();++i)
	{
		LLRect panel_rect = mAccordionTabs[i]->getRect();
		ctrlSetLeftTopAndSize(mAccordionTabs[i],panel_rect.mLeft,panel_rect.mTop,panel_width,panel_rect.getHeight());
	}

	mScrollbar->setDocPos(0);

	if(mAccordionTabs.size()>0)
	{
		S32 panel_top = height - BORDER_MARGIN;		  // Top coordinate of the first panel
		S32 diff = panel_top - mAccordionTabs[0]->getRect().mTop;
		shiftAccordionTabs(0,diff);
	}
}


//---------------------------------------------------------------------------------
S32 LLAccordionCtrl::calcRecuiredHeight()
{
	S32 rec_height = 0;
	
	std::vector<LLAccordionCtrlTab*>::iterator panel;
	for(panel=mAccordionTabs.begin(); panel!=mAccordionTabs.end(); ++panel)
	{
		LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(*panel);
		if(accordion_tab && accordion_tab->getVisible())
		{
			rec_height += accordion_tab->getRect().getHeight();
		}
	}

	mInnerRect.setLeftTopAndSize(0,rec_height + BORDER_MARGIN*2,getRect().getWidth(),rec_height + BORDER_MARGIN);

	return mInnerRect.getHeight();
}

//---------------------------------------------------------------------------------
void LLAccordionCtrl::ctrlSetLeftTopAndSize(LLView* panel, S32 left, S32 top, S32 width, S32 height)
{
	if(!panel)
		return;
	LLRect panel_rect = panel->getRect();
	panel_rect.setLeftTopAndSize( left, top, width, height);
	panel->reshape( width, height, 1);
	panel->setRect(panel_rect);
}

void LLAccordionCtrl::ctrlShiftVertical(LLView* panel,S32 delta)
{
	if(!panel)
		return;
	panel->translate(0,delta);
}

//---------------------------------------------------------------------------------

void LLAccordionCtrl::addCollapsibleCtrl(LLView* view)
{
	LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(view);
	if(!accordion_tab)
		return;
	if(std::find(getChildList()->begin(),getChildList()->end(),accordion_tab) == getChildList()->end())
		addChild(accordion_tab);
	mAccordionTabs.push_back(accordion_tab);
	
	accordion_tab->setDropDownStateChangedCallback( boost::bind(&LLAccordionCtrl::onCollapseCtrlCloseOpen, this, mAccordionTabs.size() - 1) );

}


void LLAccordionCtrl::arrange()
{
	if( mAccordionTabs.size() == 0)
	{
		//We do not arrange if we do not have what should be arranged
		return;
	}

	//Calculate params	
	S32 panel_left = BORDER_MARGIN;	  // Margin from left side of Splitter
	S32 panel_top = getRect().getHeight() - BORDER_MARGIN;		  // Top coordinate of the first panel
	S32 panel_width = getRect().getWidth() - 4;		  // Top coordinate of the first panel

	
	if(mAccordionTabs.size() == 1)
	{
		LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(mAccordionTabs[0]);
		
		LLRect panel_rect = accordion_tab->getRect();
		
		S32 panel_height = getRect().getHeight() - 2*BORDER_MARGIN;

		ctrlSetLeftTopAndSize(accordion_tab,panel_rect.mLeft,panel_top,panel_width,panel_height);
		
		show_hide_scrollbar(getRect().getWidth(),getRect().getHeight());
		return;

	}

	for(size_t i = 0; i < mAccordionTabs.size(); i++ )
	{
		LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(mAccordionTabs[i]);
		
		if(accordion_tab->getVisible() == false) //skip hidden accordion tabs
			continue;
		
		if(!accordion_tab->isExpanded() )
		{
			ctrlSetLeftTopAndSize(mAccordionTabs[i], panel_left, panel_top, panel_width, accordion_tab->getRect().getHeight());
			panel_top-=mAccordionTabs[i]->getRect().getHeight();
		}
		else
		{
			S32 panel_height = accordion_tab->getRect().getHeight();
			
			if(mFitParent)
			{
				// all expanded tabs will have equal height
				panel_height = calcExpandedTabHeight(i, panel_top);
				ctrlSetLeftTopAndSize(accordion_tab, panel_left, panel_top, panel_width, panel_height);

				// try to make accordion tab fit accordion view height.
				// Accordion View should implement getRequiredRect() and provide valid height
				S32 optimal_height = accordion_tab->getAccordionView()->getRequiredRect().getHeight();
				optimal_height += accordion_tab->getHeaderHeight() + 2 * BORDER_MARGIN;
				if(optimal_height < panel_height)
				{
					panel_height = optimal_height;
				}

				// minimum tab height is equal to header height
				if(mAccordionTabs[i]->getHeaderHeight() > panel_height)
				{
					panel_height = mAccordionTabs[i]->getHeaderHeight();
				}
			}
			
			ctrlSetLeftTopAndSize(mAccordionTabs[i], panel_left, panel_top, panel_width, panel_height);
			panel_top-=panel_height;
			
		}
	}	

	show_hide_scrollbar(getRect().getWidth(),getRect().getHeight());

	updateLayout(getRect().getWidth(),getRect().getHeight());

}

//---------------------------------------------------------------------------------

BOOL LLAccordionCtrl::handleScrollWheel		( S32 x, S32 y, S32 clicks )
{
	if(LLPanel::handleScrollWheel(x,y,clicks))
		return TRUE;
	if( mScrollbar->getVisible() && mScrollbar->handleScrollWheel( 0, 0, clicks ) )
		return TRUE;
	return false;

}

BOOL LLAccordionCtrl::handleKeyHere			(KEY key, MASK mask)
{
	if( mScrollbar->getVisible() && mScrollbar->handleKeyHere( key,mask ) )
		return TRUE;
	return LLPanel::handleKeyHere(key,mask);
}

BOOL LLAccordionCtrl::handleDragAndDrop		(S32 x, S32 y, MASK mask,
											 BOOL drop,
											 EDragAndDropType cargo_type,
											 void* cargo_data,
											 EAcceptance* accept,
											 std::string& tooltip_msg)
{
	// Scroll folder view if needed.  Never accepts a drag or drop.
	*accept = ACCEPT_NO;
	BOOL handled = autoScroll(x, y);

	if( !handled )
	{
		handled = childrenHandleDragAndDrop(x, y, mask, drop, cargo_type,
											cargo_data, accept, tooltip_msg) != NULL;
	}
	return TRUE;
}

BOOL LLAccordionCtrl::autoScroll		(S32 x, S32 y)
{
	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);

	bool scrolling = false;
	if( mScrollbar->getVisible() )
	{
		LLRect rect_local( 0, getRect().getHeight(), getRect().getWidth() - scrollbar_size, 0 );
		LLRect screen_local_extents;

		// clip rect against root view
		screenRectToLocal(getRootView()->getLocalRect(), &screen_local_extents);
		rect_local.intersectWith(screen_local_extents);

		// autoscroll region should take up no more than one third of visible scroller area
		S32 auto_scroll_region_height = llmin(rect_local.getHeight() / 3, 10);
		S32 auto_scroll_speed = llround(mAutoScrollRate * LLFrameTimer::getFrameDeltaTimeF32());

		LLRect bottom_scroll_rect = screen_local_extents;
		bottom_scroll_rect.mTop = rect_local.mBottom + auto_scroll_region_height;
		if( bottom_scroll_rect.pointInRect( x, y ) && (mScrollbar->getDocPos() < mScrollbar->getDocPosMax()) )
		{
			mScrollbar->setDocPos( mScrollbar->getDocPos() + auto_scroll_speed );
			mAutoScrolling = true;
			scrolling = true;
		}

		LLRect top_scroll_rect = screen_local_extents;
		top_scroll_rect.mBottom = rect_local.mTop - auto_scroll_region_height;
		if( top_scroll_rect.pointInRect( x, y ) && (mScrollbar->getDocPos() > 0) )
		{
			mScrollbar->setDocPos( mScrollbar->getDocPos() - auto_scroll_speed );
			mAutoScrolling = true;
			scrolling = true;
		}
	}
	return scrolling;
}

void	LLAccordionCtrl::updateLayout	(S32 width, S32 height)
{
	S32 panel_top = height - BORDER_MARGIN ;
	if(mScrollbar->getVisible())
		panel_top+=mScrollbar->getDocPos();

	S32 panel_width = width - 2*BORDER_MARGIN;

	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
	if(mScrollbar->getVisible())
		panel_width-=scrollbar_size;

	//set sizes for first panels and dragbars
	for(size_t i=0;i<mAccordionTabs.size();++i)
	{
		if(!mAccordionTabs[i]->getVisible())
			continue;
		LLRect panel_rect = mAccordionTabs[i]->getRect();
		ctrlSetLeftTopAndSize(mAccordionTabs[i],panel_rect.mLeft,panel_top,panel_width,panel_rect.getHeight());
		panel_top-=panel_rect.getHeight();
	}
}

void	LLAccordionCtrl::onScrollPosChangeCallback(S32, LLScrollbar*)
{
	updateLayout(getRect().getWidth(),getRect().getHeight());
}
void	LLAccordionCtrl::onOpen		(const LLSD& key)
{
	for(size_t i=0;i<mAccordionTabs.size();++i)
	{
		LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(mAccordionTabs[i]);
		LLPanel* panel = dynamic_cast<LLPanel*>(accordion_tab->getAccordionView());
		if(panel!=NULL)
		{
			panel->onOpen(key);
		}
	}
}
S32	LLAccordionCtrl::notifyParent(const LLSD& info)
{
	if(info.has("action"))
	{
		std::string str_action = info["action"];
		if(str_action == "size_changes")
		{
			//
			arrange();
			return 1;
		}
		else if(str_action == "select_next")
		{
			for(size_t i=0;i<mAccordionTabs.size();++i)
			{
				LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(mAccordionTabs[i]);
				if(accordion_tab->hasFocus())
				{
					while(++i<mAccordionTabs.size())
					{
						if(mAccordionTabs[i]->getVisible())
							break;
					}
					if(i<mAccordionTabs.size())
					{
						accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(mAccordionTabs[i]);
						accordion_tab->notify(LLSD().with("action","select_first"));
						return 1;
					}
					break;
				}
			}
			return 0;
		}
		else if(str_action == "select_prev")
		{
			for(size_t i=0;i<mAccordionTabs.size();++i)
			{
				LLAccordionCtrlTab* accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(mAccordionTabs[i]);
				if(accordion_tab->hasFocus() && i>0)
				{
					while(i>0)
					{
						if(mAccordionTabs[--i]->getVisible())
							break;
					}
					
					accordion_tab = dynamic_cast<LLAccordionCtrlTab*>(mAccordionTabs[i]);
					accordion_tab->notify(LLSD().with("action","select_last"));
					return 1;
				}
			}
			return 0;
		}
	}
	else if (info.has("scrollToShowRect"))
	{
		LLRect screen_rc, local_rc;
		screen_rc.setValue(info["scrollToShowRect"]);
		screenRectToLocal(screen_rc, &local_rc);

		// Translate to parent coordinatess to check if we are in visible rectangle
		local_rc.translate( getRect().mLeft, getRect().mBottom );

		if ( !getRect().contains (local_rc) )
		{
			// Back to local coords and calculate position for scroller
			S32 bottom = mScrollbar->getDocPos() - local_rc.mBottom + getRect().mBottom;
			S32 top = mScrollbar->getDocPos() - local_rc.mTop + getRect().mTop;

			S32 scroll_pos = llclamp(mScrollbar->getDocPos(),
									 bottom, // min vertical scroll
									 top); // max vertical scroll 

			mScrollbar->setDocPos( scroll_pos );
		}
		return 1;
	}
	return LLPanel::notifyParent(info);
}
void	LLAccordionCtrl::reset		()
{
	if(mScrollbar)
		mScrollbar->setDocPos(0);
}

S32 LLAccordionCtrl::calcExpandedTabHeight(S32 tab_index /* = 0 */, S32 available_height /* = 0 */)
{
	if(tab_index < 0)
	{
		return available_height;
	}

	S32 collapsed_tabs_height = 0;
	S32 num_expanded = 0;

	for(size_t n = tab_index; n < mAccordionTabs.size(); ++n)
	{
		if(!mAccordionTabs[n]->isExpanded())
		{
			collapsed_tabs_height += mAccordionTabs[n]->getHeaderHeight();
		}
		else
		{
			++num_expanded;
		}
	}

	if(0 == num_expanded)
	{
		return available_height;
	}

	S32 expanded_tab_height = available_height - collapsed_tabs_height - BORDER_MARGIN; // top BORDER_MARGIN is added in arrange(), here we add bottom BORDER_MARGIN
	expanded_tab_height /= num_expanded;
	return expanded_tab_height;
}