summaryrefslogtreecommitdiff
path: root/indra/llui/llaccordionctrltab.cpp
blob: 0db2dca6155cabca4628c1b1128b0dd06487e245 (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
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
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
/** 
 * @file LLAccordionCtrlTab.cpp
 * @brief Collapsible control 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 "llaccordionctrltab.h"

#include "lllocalcliprect.h"
#include "llscrollbar.h"
#include "lltextbox.h"
#include "lluictrl.h"
#include "lluitextutil.h"

static const std::string DD_BUTTON_NAME = "dd_button";
static const std::string DD_TEXTBOX_NAME = "dd_textbox";
static const std::string DD_HEADER_NAME = "dd_header";

static const S32 HEADER_HEIGHT = 20;
static const S32 HEADER_IMAGE_LEFT_OFFSET = 5;
static const S32 HEADER_TEXT_LEFT_OFFSET = 30;
static const F32 AUTO_OPEN_TIME = 1.f;
static const S32 VERTICAL_MULTIPLE = 16;
static const S32 PARENT_BORDER_MARGIN = 5;

static LLDefaultChildRegistry::Register<LLAccordionCtrlTab> t1("accordion_tab");

class LLAccordionCtrlTab::LLAccordionCtrlTabHeader : public LLUICtrl
{
public:
	friend class LLUICtrlFactory;

	struct Params : public LLInitParam::Block<Params, LLAccordionCtrlTab::Params>
	{
		Params();
	};

	LLAccordionCtrlTabHeader(const LLAccordionCtrlTabHeader::Params& p);
	
	virtual ~LLAccordionCtrlTabHeader();

	virtual void draw();

	virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);

	virtual BOOL postBuild();

	std::string getTitle();
	void	setTitle(const std::string& title, const std::string& hl);

	virtual void onMouseEnter(S32 x, S32 y, MASK mask);
	virtual void onMouseLeave(S32 x, S32 y, MASK mask);
	virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
	virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
								   EDragAndDropType cargo_type,
								   void* cargo_data,
								   EAcceptance* accept,
								   std::string& tooltip_msg);
private:

	LLTextBox* mHeaderTextbox;

	// Overlay images (arrows)
	LLPointer<LLUIImage> mImageCollapsed;
	LLPointer<LLUIImage> mImageExpanded;
	LLPointer<LLUIImage> mImageCollapsedPressed;
	LLPointer<LLUIImage> mImageExpandedPressed;

	// Background images
	LLPointer<LLUIImage> mImageHeader;
	LLPointer<LLUIImage> mImageHeaderOver;
	LLPointer<LLUIImage> mImageHeaderPressed;
	LLPointer<LLUIImage> mImageHeaderFocused;

	LLUIColor mHeaderBGColor;

	bool mNeedsHighlight;

	LLFrameTimer mAutoOpenTimer;
};

LLAccordionCtrlTab::LLAccordionCtrlTabHeader::Params::Params()
{
}

LLAccordionCtrlTab::LLAccordionCtrlTabHeader::LLAccordionCtrlTabHeader(
	const LLAccordionCtrlTabHeader::Params& p)
: LLUICtrl(p)
, mHeaderBGColor(p.header_bg_color())
,mNeedsHighlight(false),
	mImageCollapsed(p.header_collapse_img),
	mImageCollapsedPressed(p.header_collapse_img_pressed),
	mImageExpanded(p.header_expand_img),
	mImageExpandedPressed(p.header_expand_img_pressed),
	mImageHeader(p.header_image),
	mImageHeaderOver(p.header_image_over),
	mImageHeaderPressed(p.header_image_pressed),
	mImageHeaderFocused(p.header_image_focused)
{
	LLTextBox::Params textboxParams;
	textboxParams.name(DD_TEXTBOX_NAME);
	textboxParams.initial_value(p.title());
	textboxParams.text_color(p.header_text_color());
	textboxParams.follows.flags(FOLLOWS_NONE);
	textboxParams.font( p.font() );
	textboxParams.font_shadow(LLFontGL::NO_SHADOW);
	textboxParams.use_ellipses = true;
	textboxParams.bg_visible = false;
	textboxParams.mouse_opaque = false;
	mHeaderTextbox = LLUICtrlFactory::create<LLTextBox>(textboxParams);
	addChild(mHeaderTextbox);
}

LLAccordionCtrlTab::LLAccordionCtrlTabHeader::~LLAccordionCtrlTabHeader()
{
}

BOOL LLAccordionCtrlTab::LLAccordionCtrlTabHeader::postBuild()
{
	return TRUE;
}

std::string LLAccordionCtrlTab::LLAccordionCtrlTabHeader::getTitle()
{
	if(mHeaderTextbox)
	{
		return mHeaderTextbox->getText();
	}
	else
	{
		return LLStringUtil::null;
	}
}

void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::setTitle(const std::string& title, const std::string& hl)
{
	if(mHeaderTextbox)
	{
		LLTextUtil::textboxSetHighlightedVal(
			mHeaderTextbox,
			LLStyle::Params(),
			title,
			hl);
	}
}

void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::draw()
{
	S32 width = getRect().getWidth();
	S32 height = getRect().getHeight();

	gl_rect_2d(0,0,width - 1 ,height - 1,mHeaderBGColor.get(),true);

	LLAccordionCtrlTab* parent = dynamic_cast<LLAccordionCtrlTab*>(getParent());
	bool collapsible = (parent && parent->getCollapsible());
	bool expanded = (parent && parent->getDisplayChildren());

	// Handle overlay images, if needed
	// Only show green "focus" background image if the accordion is open,
	// because the user's mental model of focus is that it goes away after
	// the accordion is closed.
	if (getParent()->hasFocus()
		/*&& !(collapsible && !expanded)*/ // WHY??
		)
	{
		mImageHeaderFocused->draw(0,0,width,height);
	}
	else
	{
		mImageHeader->draw(0,0,width,height);
	}

	if(mNeedsHighlight)
	{
		mImageHeaderOver->draw(0,0,width,height);
	}
	

	if(collapsible)
	{
		LLPointer<LLUIImage> overlay_image;
		if(expanded)
		{
			overlay_image = mImageExpanded;
		}
		else
		{
			overlay_image = mImageCollapsed;
		}
		overlay_image->draw(HEADER_IMAGE_LEFT_OFFSET,
							(height - overlay_image->getHeight()) / 2);
	}
	
	LLUICtrl::draw();
}

void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::reshape(S32 width, S32 height, BOOL called_from_parent /* = TRUE */)
{
	S32 header_height = mHeaderTextbox->getTextPixelHeight();

	LLRect textboxRect(HEADER_TEXT_LEFT_OFFSET,(height+header_height)/2 ,width,(height-header_height)/2);
	mHeaderTextbox->reshape(textboxRect.getWidth(), textboxRect.getHeight());
	mHeaderTextbox->setRect(textboxRect);
}

void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::onMouseEnter(S32 x, S32 y, MASK mask)
{
	LLUICtrl::onMouseEnter(x, y, mask);
	mNeedsHighlight = true;
}
void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::onMouseLeave(S32 x, S32 y, MASK mask)
{
	LLUICtrl::onMouseLeave(x, y, mask);
	mNeedsHighlight = false;
	mAutoOpenTimer.stop();
}
BOOL LLAccordionCtrlTab::LLAccordionCtrlTabHeader::handleKey(KEY key, MASK mask, BOOL called_from_parent)
{
	if ( ( key == KEY_LEFT || key == KEY_RIGHT) && mask == MASK_NONE)
	{
		return getParent()->handleKey(key, mask, called_from_parent);
	}
	return LLUICtrl::handleKey(key, mask, called_from_parent);
}
BOOL LLAccordionCtrlTab::LLAccordionCtrlTabHeader::handleDragAndDrop(S32 x, S32 y, MASK mask,
																	 BOOL drop,
																	 EDragAndDropType cargo_type,
																	 void* cargo_data,
																	 EAcceptance* accept,
																	 std::string& tooltip_msg)
{
	LLAccordionCtrlTab* parent = dynamic_cast<LLAccordionCtrlTab*>(getParent());

	if ( parent && !parent->getDisplayChildren() && parent->getCollapsible() && parent->canOpenClose() )
	{
		if (mAutoOpenTimer.getStarted())
		{
			if (mAutoOpenTimer.getElapsedTimeF32() > AUTO_OPEN_TIME)
			{
				parent->changeOpenClose(false);
				mAutoOpenTimer.stop();
				return TRUE;
			}
		}
		else
			mAutoOpenTimer.start();
	}

	return LLUICtrl::handleDragAndDrop(x, y, mask, drop, cargo_type,
									   cargo_data, accept, tooltip_msg);
}
LLAccordionCtrlTab::Params::Params()
	: title("title")
	,display_children("expanded", true)
	,header_height("header_height", HEADER_HEIGHT),
	min_width("min_width", 0),
	min_height("min_height", 0)
	,collapsible("collapsible", true)
	,header_bg_color("header_bg_color")
	,dropdown_bg_color("dropdown_bg_color")
	,header_visible("header_visible",true)
	,padding_left("padding_left",2)
	,padding_right("padding_right",2)
	,padding_top("padding_top",2)
	,padding_bottom("padding_bottom",2)
	,header_expand_img("header_expand_img")
	,header_expand_img_pressed("header_expand_img_pressed")
	,header_collapse_img("header_collapse_img")
	,header_collapse_img_pressed("header_collapse_img_pressed")
	,header_image("header_image")
	,header_image_over("header_image_over")
	,header_image_pressed("header_image_pressed")
	,header_image_focused("header_image_focused")
	,header_text_color("header_text_color")
	,fit_panel("fit_panel",true)
{
	mouse_opaque(false);
}

LLAccordionCtrlTab::LLAccordionCtrlTab(const LLAccordionCtrlTab::Params&p)
	: LLUICtrl(p)
	,mDisplayChildren(p.display_children)
	,mCollapsible(p.collapsible)
	,mExpandedHeight(0)
	,mDropdownBGColor(p.dropdown_bg_color())
	,mHeaderVisible(p.header_visible)
	,mPaddingLeft(p.padding_left)
	,mPaddingRight(p.padding_right)
	,mPaddingTop(p.padding_top)
	,mPaddingBottom(p.padding_bottom)
	,mCanOpenClose(true)
	,mFitPanel(p.fit_panel)
	,mContainerPanel(NULL)
	,mScrollbar(NULL)
{
	mStoredOpenCloseState = false;
	mWasStateStored = false;
	
	mDropdownBGColor = LLColor4::white;
	LLAccordionCtrlTabHeader::Params headerParams;
	headerParams.name(DD_HEADER_NAME);
	headerParams.title(p.title);
	mHeader = LLUICtrlFactory::create<LLAccordionCtrlTabHeader>(headerParams);
	addChild(mHeader, 1);

	reshape(100, 200,FALSE);
}

LLAccordionCtrlTab::~LLAccordionCtrlTab()
{
}


void LLAccordionCtrlTab::setDisplayChildren(bool display)
{
	mDisplayChildren = display;
	LLRect rect = getRect();

	rect.mBottom = rect.mTop - (getDisplayChildren() ? 
		mExpandedHeight : HEADER_HEIGHT);
	setRect(rect);

	if(mContainerPanel)
		mContainerPanel->setVisible(getDisplayChildren());

	if(mDisplayChildren)
	{
		adjustContainerPanel();
	}
	else
	{
		if(mScrollbar)
			mScrollbar->setVisible(false);
	}

}

void LLAccordionCtrlTab::reshape(S32 width, S32 height, BOOL called_from_parent /* = TRUE */)
{
	LLRect headerRect;

	headerRect.setLeftTopAndSize(
		0,height,width,HEADER_HEIGHT);
	mHeader->setRect(headerRect);
	mHeader->reshape(headerRect.getWidth(), headerRect.getHeight());

	if(!mDisplayChildren)
		return;

	LLRect childRect;

	childRect.setLeftTopAndSize(
		getPaddingLeft(),
		height - getHeaderHeight() - getPaddingTop(),
		width - getPaddingLeft() - getPaddingRight(), 
		height - getHeaderHeight() - getPaddingTop() - getPaddingBottom() );

	adjustContainerPanel(childRect);
}

void LLAccordionCtrlTab::changeOpenClose(bool is_open)
{
	if(is_open)
		mExpandedHeight = getRect().getHeight();

	setDisplayChildren(!is_open);
	reshape(getRect().getWidth(), getRect().getHeight(), FALSE);
	if (mCommitSignal)
	{
		(*mCommitSignal)(this, getDisplayChildren());
	}
}

BOOL LLAccordionCtrlTab::handleMouseDown(S32 x, S32 y, MASK mask)
{
	if(mCollapsible && mHeaderVisible && mCanOpenClose)
	{
		if(y >= (getRect().getHeight() - HEADER_HEIGHT) )
		{
			LLAccordionCtrlTabHeader* header = getChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);
			header->setFocus(true);
			changeOpenClose(getDisplayChildren());

			//reset stored state
			mWasStateStored = false;
			return TRUE;
		}
	}
	return LLUICtrl::handleMouseDown(x,y,mask);
}

BOOL LLAccordionCtrlTab::handleMouseUp(S32 x, S32 y, MASK mask)
{
	return LLUICtrl::handleMouseUp(x,y,mask);
}

boost::signals2::connection LLAccordionCtrlTab::setDropDownStateChangedCallback(commit_callback_t cb)
{
	return setCommitCallback(cb);
}

bool LLAccordionCtrlTab::addChild(LLView* child, S32 tab_group)
{
	if(DD_HEADER_NAME != child->getName())
	{
		reshape(child->getRect().getWidth() , child->getRect().getHeight() + HEADER_HEIGHT );
		mExpandedHeight = getRect().getHeight();
	}

	bool res = LLUICtrl::addChild(child, tab_group);

	if(DD_HEADER_NAME != child->getName())
	{
		if(!mCollapsible)
			setDisplayChildren(true);
		else
			setDisplayChildren(getDisplayChildren());	
	}

	if (!mContainerPanel)
		mContainerPanel = findContainerView();

	return res;
}

void LLAccordionCtrlTab::setAccordionView(LLView* panel)
{
	addChild(panel,0);
}

std::string LLAccordionCtrlTab::getTitle()
{
	LLAccordionCtrlTabHeader* header = findChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);
	if (header)
	{
		return header->getTitle();
	}
	else
	{
		return LLStringUtil::null;
	}
}

void LLAccordionCtrlTab::setTitle(const std::string& title, const std::string& hl)
{
	LLAccordionCtrlTabHeader* header = findChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);
	if (header)
	{
		header->setTitle(title, hl);
	}
}

boost::signals2::connection LLAccordionCtrlTab::setFocusReceivedCallback(const focus_signal_t::slot_type& cb)
{
	LLAccordionCtrlTabHeader* header = findChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);
	if (header)
	{
		return header->setFocusReceivedCallback(cb);
	}
	return boost::signals2::connection();
}

boost::signals2::connection LLAccordionCtrlTab::setFocusLostCallback(const focus_signal_t::slot_type& cb)
{
	LLAccordionCtrlTabHeader* header = findChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);
	if (header)
	{
		return header->setFocusLostCallback(cb);
	}
	return boost::signals2::connection();
}

LLView*	LLAccordionCtrlTab::findContainerView()
{
	for(child_list_const_iter_t it = getChildList()->begin(); 
		getChildList()->end() != it; ++it)
	{
		LLView* child = *it;
		if(DD_HEADER_NAME == child->getName())
			continue;
		if(!child->getVisible())
			continue;
		return child;
	}
	return NULL;
}


S32 LLAccordionCtrlTab::getHeaderHeight()
{
	return mHeaderVisible?HEADER_HEIGHT:0; 
}

void LLAccordionCtrlTab::setHeaderVisible(bool value) 
{
	if(mHeaderVisible == value)
		return;
	mHeaderVisible = value;
	if(mHeader)
		mHeader->setVisible(value);
	reshape(getRect().getWidth(), getRect().getHeight(), FALSE);
};

//virtual
BOOL LLAccordionCtrlTab::postBuild()
{
	if(mHeader)
		mHeader->setVisible(mHeaderVisible);
	
	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);

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

	mContainerPanel = findContainerView();

	if(!mFitPanel)
	{
		LLScrollbar::Params sbparams;
		sbparams.name("scrollable vertical");
		sbparams.rect(scroll_rect);
		sbparams.orientation(LLScrollbar::VERTICAL);
		sbparams.doc_size(getRect().getHeight());
		sbparams.doc_pos(0);
		sbparams.page_size(getRect().getHeight());
		sbparams.step_size(VERTICAL_MULTIPLE);
		sbparams.follows.flags(FOLLOWS_RIGHT | FOLLOWS_TOP | FOLLOWS_BOTTOM);
		sbparams.change_callback(boost::bind(&LLAccordionCtrlTab::onScrollPosChangeCallback, this, _1, _2));


		mScrollbar = LLUICtrlFactory::create<LLScrollbar> (sbparams);
		LLView::addChild( mScrollbar );
		mScrollbar->setFollowsRight();
		mScrollbar->setFollowsTop();
		mScrollbar->setFollowsBottom();

		mScrollbar->setVisible(false);
	}

	if(mContainerPanel)
		mContainerPanel->setVisible(mDisplayChildren);

	return LLUICtrl::postBuild();
}
bool	LLAccordionCtrlTab::notifyChildren	(const LLSD& info)
{
	if(info.has("action"))
	{
		std::string str_action = info["action"];
		if(str_action == "store_state")
		{
			storeOpenCloseState();
			return true;
		}
		if(str_action == "restore_state")
		{
			restoreOpenCloseState();
			return true;
		}
	}	
	return LLUICtrl::notifyChildren(info);
}

S32	LLAccordionCtrlTab::notifyParent(const LLSD& info)
{
	if(info.has("action"))
	{
		std::string str_action = info["action"];
		if(str_action == "size_changes")
		{
			//
			S32 height = info["height"];
			height = llmax(height,10) + HEADER_HEIGHT + getPaddingTop() + getPaddingBottom();
			
			mExpandedHeight = height;
			
			if(isExpanded())
			{
				LLRect panel_rect = getRect();
				panel_rect.setLeftTopAndSize( panel_rect.mLeft, panel_rect.mTop, panel_rect.getWidth(), height);
				reshape(getRect().getWidth(),height);
				setRect(panel_rect);
			}
			
			//LLAccordionCtrl should rearrange accodion tab if one of accordion change its size
			if (getParent()) // A parent may not be set if tabs are added dynamically.
				getParent()->notifyParent(info);
			return 1;
		}
		else if(str_action == "select_prev") 
		{
			showAndFocusHeader();
			return 1;
		}
	}
	return LLUICtrl::notifyParent(info);
}

S32 LLAccordionCtrlTab::notify(const LLSD& info)
{
	if(info.has("action"))
	{
		std::string str_action = info["action"];
		if(str_action == "select_first")
		{
			showAndFocusHeader();
			return 1;
		}
		else if( str_action == "select_last" )
		{
			if(getDisplayChildren() == false)
			{
				showAndFocusHeader();
			}
			else
			{
				LLView* view = getAccordionView();
				if(view)
					view->notify(LLSD().with("action","select_last"));
			}
		}
	}
	return 0;
}

BOOL LLAccordionCtrlTab::handleKey(KEY key, MASK mask, BOOL called_from_parent)
{
	LLAccordionCtrlTabHeader* header = getChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);	
	if( !header->hasFocus() )
		return LLUICtrl::handleKey(key, mask, called_from_parent);

	if ( (key == KEY_RETURN )&& mask == MASK_NONE)
	{
		changeOpenClose(getDisplayChildren());
		return TRUE;
	}

	if ( (key == KEY_ADD || key == KEY_RIGHT)&& mask == MASK_NONE)
	{
		if(getDisplayChildren() == false)
		{
			changeOpenClose(getDisplayChildren());
			return TRUE;
		}
	}
	if ( (key == KEY_SUBTRACT || key == KEY_LEFT)&& mask == MASK_NONE)
	{
		if(getDisplayChildren() == true)
		{
			changeOpenClose(getDisplayChildren());
			return TRUE;
		}
	}

	if ( key == KEY_DOWN && mask == MASK_NONE)
	{
		//if collapsed go to the next accordion
		if(getDisplayChildren() == false)
			//we processing notifyParent so let call parent directly
			getParent()->notifyParent(LLSD().with("action","select_next"));
		else
		{
			getAccordionView()->notify(LLSD().with("action","select_first"));
		}
		return TRUE;
	}

	if ( key == KEY_UP && mask == MASK_NONE)
	{
		//go to the previous accordion

		//we processing notifyParent so let call parent directly
		getParent()->notifyParent(LLSD().with("action","select_prev"));
		return TRUE;
	}

	return LLUICtrl::handleKey(key, mask, called_from_parent);
}

void LLAccordionCtrlTab::showAndFocusHeader()
{
	LLAccordionCtrlTabHeader* header = getChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);	
	header->setFocus(true);

	LLRect screen_rc;
	LLRect selected_rc = header->getRect();
	localRectToScreen(selected_rc, &screen_rc);
	notifyParent(LLSD().with("scrollToShowRect",screen_rc.getValue()));

}
void    LLAccordionCtrlTab::storeOpenCloseState()
{
	if(mWasStateStored)
		return;
	mStoredOpenCloseState = getDisplayChildren();
	mWasStateStored = true;
}

void   LLAccordionCtrlTab::restoreOpenCloseState()
{
	if(!mWasStateStored)
		return;
	if(getDisplayChildren() != mStoredOpenCloseState)
	{
		changeOpenClose(getDisplayChildren());
	}
	mWasStateStored = false;
}

void LLAccordionCtrlTab::adjustContainerPanel	()
{
	S32 width = getRect().getWidth();
	S32 height = getRect().getHeight();

	LLRect child_rect;
	child_rect.setLeftTopAndSize(
		getPaddingLeft(),
		height - getHeaderHeight() - getPaddingTop(),
		width - getPaddingLeft() - getPaddingRight(), 
		height - getHeaderHeight() - getPaddingTop() - getPaddingBottom() );

	adjustContainerPanel(child_rect);
}

void LLAccordionCtrlTab::adjustContainerPanel(const LLRect& child_rect)
{
	if(!mContainerPanel)
		return; 

	if(!mFitPanel)
	{
		show_hide_scrollbar(child_rect);
		updateLayout(child_rect);
	}
	else
	{
		mContainerPanel->reshape(child_rect.getWidth(),child_rect.getHeight());
		mContainerPanel->setRect(child_rect);
	}
}

S32 LLAccordionCtrlTab::getChildViewHeight()
{
	if(!mContainerPanel)
		return 0;
	return mContainerPanel->getRect().getHeight();
}

void LLAccordionCtrlTab::show_hide_scrollbar(const LLRect& child_rect)
{
	if(getChildViewHeight() > child_rect.getHeight() )
		showScrollbar(child_rect);
	else
		hideScrollbar(child_rect);
}
void LLAccordionCtrlTab::showScrollbar(const LLRect& child_rect)
{
	if(!mContainerPanel || !mScrollbar)
		return;
	bool was_visible = mScrollbar->getVisible();
	mScrollbar->setVisible(true);
	
	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);

	{
		ctrlSetLeftTopAndSize(mScrollbar,child_rect.getWidth()-scrollbar_size, 
			child_rect.getHeight()-PARENT_BORDER_MARGIN, 
			scrollbar_size, 
			child_rect.getHeight()-2*PARENT_BORDER_MARGIN);
	}

	LLRect orig_rect = mContainerPanel->getRect();

	mScrollbar->setPageSize(child_rect.getHeight());
	mScrollbar->setDocParams(orig_rect.getHeight(),mScrollbar->getDocPos());
	
	if(was_visible)
	{
		S32 scroll_pos = llmin(mScrollbar->getDocPos(), orig_rect.getHeight() - child_rect.getHeight() - 1);
		mScrollbar->setDocPos(scroll_pos);
	}
	else//shrink child panel
	{
		updateLayout(child_rect);
	}
	
}

void	LLAccordionCtrlTab::hideScrollbar( const LLRect& child_rect )
{
	if(!mContainerPanel || !mScrollbar)
		return;

	if(mScrollbar->getVisible() == false)
		return;
	mScrollbar->setVisible(false);
	mScrollbar->setDocPos(0);

	//shrink child panel
	updateLayout(child_rect);
}

void	LLAccordionCtrlTab::onScrollPosChangeCallback(S32, LLScrollbar*)
{
	LLRect child_rect;

	S32 width = getRect().getWidth();
	S32 height = getRect().getHeight();

	child_rect.setLeftTopAndSize(
		getPaddingLeft(),
		height - getHeaderHeight() - getPaddingTop(),
		width - getPaddingLeft() - getPaddingRight(), 
		height - getHeaderHeight() - getPaddingTop() - getPaddingBottom() );

	updateLayout(child_rect);
}

void LLAccordionCtrlTab::drawChild(const LLRect& root_rect,LLView* child)
{
	if (child && child->getVisible() && child->getRect().isValid())
	{
		LLRect screen_rect;
		localRectToScreen(child->getRect(),&screen_rect);
		
		if ( root_rect.overlaps(screen_rect)  && LLUI::sDirtyRect.overlaps(screen_rect))
		{
			glMatrixMode(GL_MODELVIEW);
			LLUI::pushMatrix();
			{
				LLUI::translate((F32)child->getRect().mLeft, (F32)child->getRect().mBottom, 0.f);
				child->draw();

			}
			LLUI::popMatrix();
		}
	}
}

void LLAccordionCtrlTab::draw()
{
	if(mFitPanel)
		LLUICtrl::draw();
	else
	{
		LLRect root_rect = getRootView()->getRect();
		drawChild(root_rect,mHeader);
		drawChild(root_rect,mScrollbar );
		{
			LLRect child_rect;

			S32 width = getRect().getWidth();
			S32 height = getRect().getHeight();

			child_rect.setLeftTopAndSize(
				getPaddingLeft(),
				height - getHeaderHeight() - getPaddingTop(),
				width - getPaddingLeft() - getPaddingRight(), 
				height - getHeaderHeight() - getPaddingTop() - getPaddingBottom() );

			LLLocalClipRect clip(child_rect);
			drawChild(root_rect,mContainerPanel);
		}
	}
}

void	LLAccordionCtrlTab::updateLayout	( const LLRect& child_rect )
{
	LLView*	child = getAccordionView();
	if(!mContainerPanel)
		return;

	S32 panel_top = child_rect.getHeight();
	S32 panel_width = child_rect.getWidth();

	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
	if(mScrollbar->getVisible() != false)
	{
		panel_top+=mScrollbar->getDocPos();
		panel_width-=scrollbar_size;
	}

	//set sizes for first panels and dragbars
	LLRect panel_rect = child->getRect();
	ctrlSetLeftTopAndSize(mContainerPanel,child_rect.mLeft,panel_top,panel_width,panel_rect.getHeight());
}
void LLAccordionCtrlTab::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);
}
BOOL LLAccordionCtrlTab::handleToolTip(S32 x, S32 y, MASK mask)
{
	//header may be not the first child but we need to process it first
	if(y >= (getRect().getHeight() - HEADER_HEIGHT - HEADER_HEIGHT/2) )
	{
		//inside tab header
		//fix for EXT-6619
		return TRUE;
	}
	return LLUICtrl::handleToolTip(x, y, mask);
}