summaryrefslogtreecommitdiff
path: root/indra/llui/llscrollbar.cpp
blob: 92a80c73fe1881c0f3a1c80ce331d72c22c274f5 (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
/** 
 * @file llscrollbar.cpp
 * @brief Scrollbar UI widget
 *
 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "linden_common.h"

#include "llscrollbar.h"

#include "llmath.h"
#include "lltimer.h"
#include "v3color.h"

#include "llbutton.h"
#include "llcriticaldamp.h"
#include "llkeyboard.h"
#include "llui.h"
#include "llfocusmgr.h"
#include "llwindow.h"
#include "llcontrol.h"
#include "llrender.h"
#include "lluictrlfactory.h"

static LLDefaultChildRegistry::Register<LLScrollbar> register_scrollbar("scroll_bar");

LLScrollbar::Params::Params()
:	orientation ("orientation", HORIZONTAL),
	doc_size ("doc_size", 0),
	doc_pos ("doc_pos", 0),
	page_size ("page_size", 0),
	step_size ("step_size", 1),
	thumb_image_vertical("thumb_image_vertical"),
	thumb_image_horizontal("thumb_image_horizontal"),
	track_image_vertical("track_image_vertical"),
	track_image_horizontal("track_image_horizontal"),
	track_color("track_color"),
	thumb_color("thumb_color"),
	thickness("thickness"),
	up_button("up_button"),
	down_button("down_button"),
	left_button("left_button"),
	right_button("right_button"),
	bg_visible("bg_visible", false),
	bg_color("bg_color", LLColor4::black)
{}

LLScrollbar::LLScrollbar(const Params & p)
:		LLUICtrl(p),
		mChangeCallback( p.change_callback() ),
		mOrientation( p.orientation ),
		mDocSize( p.doc_size ),
		mDocPos( p.doc_pos ),
		mPageSize( p.page_size ),
		mStepSize( p.step_size ),
		mDocChanged(FALSE),
		mDragStartX( 0 ),
		mDragStartY( 0 ),
		mHoverGlowStrength(0.15f),
		mCurGlowStrength(0.f),
		mTrackColor( p.track_color() ),
		mThumbColor ( p.thumb_color() ),
		mThumbImageV(p.thumb_image_vertical),
		mThumbImageH(p.thumb_image_horizontal),
		mTrackImageV(p.track_image_vertical),
		mTrackImageH(p.track_image_horizontal),
		mThickness(p.thickness.isProvided() ? p.thickness : LLUI::sSettingGroups["config"]->getS32("UIScrollbarSize")),
		mBGVisible(p.bg_visible),
		mBGColor(p.bg_color)
{
	updateThumbRect();
	
	// Page up and page down buttons
	LLRect line_up_rect;
	LLRect line_down_rect;

	if( VERTICAL == mOrientation )
	{
		line_up_rect.setLeftTopAndSize( 0, getRect().getHeight(), mThickness, mThickness );
		line_down_rect.setOriginAndSize( 0, 0, mThickness, mThickness );
	}
	else // HORIZONTAL
	{
		line_up_rect.setOriginAndSize( 0, 0, mThickness, mThickness );
		line_down_rect.setOriginAndSize( getRect().getWidth() - mThickness, 0, mThickness, mThickness );
	}

	LLButton::Params up_btn(mOrientation == VERTICAL ? p.up_button : p.left_button);
	up_btn.name(std::string("Line Up"));
	up_btn.rect(line_up_rect);
	up_btn.click_callback.function(boost::bind(&LLScrollbar::onLineUpBtnPressed, this, _2));
	up_btn.mouse_held_callback.function(boost::bind(&LLScrollbar::onLineUpBtnPressed, this, _2));
	up_btn.tab_stop(false);
	up_btn.follows.flags = (mOrientation == VERTICAL ? (FOLLOWS_RIGHT | FOLLOWS_TOP) : (FOLLOWS_LEFT | FOLLOWS_BOTTOM));

	addChild(LLUICtrlFactory::create<LLButton>(up_btn));

	LLButton::Params down_btn(mOrientation == VERTICAL ? p.down_button : p.right_button);
	down_btn.name(std::string("Line Down"));
	down_btn.rect(line_down_rect);
	down_btn.follows.flags(FOLLOWS_RIGHT|FOLLOWS_BOTTOM);
	down_btn.click_callback.function(boost::bind(&LLScrollbar::onLineDownBtnPressed, this, _2));
	down_btn.mouse_held_callback.function(boost::bind(&LLScrollbar::onLineDownBtnPressed, this, _2));
	down_btn.tab_stop(false);

	addChild(LLUICtrlFactory::create<LLButton>(down_btn));
}


LLScrollbar::~LLScrollbar()
{
	// Children buttons killed by parent class
}

void LLScrollbar::setDocParams( S32 size, S32 pos )
{
	mDocSize = size;
	setDocPos(pos);
	mDocChanged = TRUE;

	updateThumbRect();
}

// returns true if document position really changed
bool LLScrollbar::setDocPos(S32 pos, BOOL update_thumb)
{
	pos = llclamp(pos, 0, getDocPosMax());
	if (pos != mDocPos)
	{
		mDocPos = pos;
		mDocChanged = TRUE;

		if( mChangeCallback )
		{
			mChangeCallback( mDocPos, this );
		}

		if( update_thumb )
		{
			updateThumbRect();
		}
		return true;
	}
	return false;
}

void LLScrollbar::setDocSize(S32 size)
{
	if (size != mDocSize)
	{
		mDocSize = size;
		setDocPos(mDocPos);
		mDocChanged = TRUE;

		updateThumbRect();
	}
}

void LLScrollbar::setPageSize( S32 page_size )
{
	if (page_size != mPageSize)
	{
		mPageSize = page_size;
		setDocPos(mDocPos);
		mDocChanged = TRUE;

		updateThumbRect();
	}
}

BOOL LLScrollbar::isAtBeginning()
{
	return mDocPos == 0;
}

BOOL LLScrollbar::isAtEnd()
{
	return mDocPos == getDocPosMax();
}


void LLScrollbar::updateThumbRect()
{
//	llassert( 0 <= mDocSize );
//	llassert( 0 <= mDocPos && mDocPos <= getDocPosMax() );
	
	const S32 THUMB_MIN_LENGTH = 16;

	S32 window_length = (mOrientation == LLScrollbar::HORIZONTAL) ? getRect().getWidth() : getRect().getHeight();
	S32 thumb_bg_length = llmax(0, window_length - 2 * mThickness);
	S32 visible_lines = llmin( mDocSize, mPageSize );
	S32 thumb_length = mDocSize ? llmin(llmax( visible_lines * thumb_bg_length / mDocSize, THUMB_MIN_LENGTH), thumb_bg_length) : thumb_bg_length;

	S32 variable_lines = mDocSize - visible_lines;

	if( mOrientation == LLScrollbar::VERTICAL )
	{ 
		S32 thumb_start_max = thumb_bg_length + mThickness;
		S32 thumb_start_min = mThickness + THUMB_MIN_LENGTH;
		S32 thumb_start = variable_lines ? llmin( llmax(thumb_start_max - (mDocPos * (thumb_bg_length - thumb_length)) / variable_lines, thumb_start_min), thumb_start_max ) : thumb_start_max;

		mThumbRect.mLeft =  0;
		mThumbRect.mTop = thumb_start;
		mThumbRect.mRight = mThickness;
		mThumbRect.mBottom = thumb_start - thumb_length;
	}
	else
	{
		// Horizontal
		S32 thumb_start_max = thumb_bg_length + mThickness - thumb_length;
		S32 thumb_start_min = mThickness;
		S32 thumb_start = variable_lines ? llmin(llmax( thumb_start_min + (mDocPos * (thumb_bg_length - thumb_length)) / variable_lines, thumb_start_min), thumb_start_max ) : thumb_start_min;
	
		mThumbRect.mLeft = thumb_start;
		mThumbRect.mTop = mThickness;
		mThumbRect.mRight = thumb_start + thumb_length;
		mThumbRect.mBottom = 0;
	}
}

BOOL LLScrollbar::handleMouseDown(S32 x, S32 y, MASK mask)
{
	// Check children first
	BOOL handled_by_child = LLView::childrenHandleMouseDown(x, y, mask) != NULL;
	if( !handled_by_child )
	{
		if( mThumbRect.pointInRect(x,y) )
		{
			// Start dragging the thumb
			// No handler needed for focus lost since this clas has no state that depends on it.
			gFocusMgr.setMouseCapture( this );  
			mDragStartX = x;
			mDragStartY = y;
			mOrigRect.mTop = mThumbRect.mTop;
			mOrigRect.mBottom = mThumbRect.mBottom;
			mOrigRect.mLeft = mThumbRect.mLeft;
			mOrigRect.mRight = mThumbRect.mRight;
			mLastDelta = 0;
		}
		else
		{
			if( 
				( (LLScrollbar::VERTICAL == mOrientation) && (mThumbRect.mTop < y) ) ||
				( (LLScrollbar::HORIZONTAL == mOrientation) && (x < mThumbRect.mLeft) )
			)
			{
				// Page up
				pageUp(0);
			}
			else
			if(
				( (LLScrollbar::VERTICAL == mOrientation) && (y < mThumbRect.mBottom) ) ||
				( (LLScrollbar::HORIZONTAL == mOrientation) && (mThumbRect.mRight < x) )
			)
			{
				// Page down
				pageDown(0);
			}
		}
	}

	return TRUE;
}


BOOL LLScrollbar::handleHover(S32 x, S32 y, MASK mask)
{
	// Note: we don't bother sending the event to the children (the arrow buttons)
	// because they'll capture the mouse whenever they need hover events.
	
	BOOL handled = FALSE;
	if( hasMouseCapture() )
	{
		S32 height = getRect().getHeight();
		S32 width = getRect().getWidth();

		if( VERTICAL == mOrientation )
		{
//			S32 old_pos = mThumbRect.mTop;

			S32 delta_pixels = y - mDragStartY;
			if( mOrigRect.mBottom + delta_pixels < mThickness )
			{
				delta_pixels = mThickness - mOrigRect.mBottom - 1;
			}
			else
			if( mOrigRect.mTop + delta_pixels > height - mThickness )
			{
				delta_pixels = height - mThickness - mOrigRect.mTop + 1;
			}

			mThumbRect.mTop = mOrigRect.mTop + delta_pixels;
			mThumbRect.mBottom = mOrigRect.mBottom + delta_pixels;

			S32 thumb_length = mThumbRect.getHeight();
			S32 thumb_track_length = height - 2 * mThickness;


			if( delta_pixels != mLastDelta || mDocChanged)
			{	
				// Note: delta_pixels increases as you go up.  mDocPos increases down (line 0 is at the top of the page).
				S32 usable_track_length = thumb_track_length - thumb_length;
				if( 0 < usable_track_length )
				{
					S32 variable_lines = getDocPosMax();
					S32 pos = mThumbRect.mTop;
					F32 ratio = F32(pos - mThickness - thumb_length) / usable_track_length;	
	
					S32 new_pos = llclamp( S32(variable_lines - ratio * variable_lines + 0.5f), 0, variable_lines );
					// Note: we do not call updateThumbRect() here.  Instead we let the thumb and the document go slightly
					// out of sync (less than a line's worth) to make the thumb feel responsive.
					changeLine( new_pos - mDocPos, FALSE );
				}
			}

			mLastDelta = delta_pixels;
		
		}
		else
		{
			// Horizontal
//			S32 old_pos = mThumbRect.mLeft;

			S32 delta_pixels = x - mDragStartX;

			if( mOrigRect.mLeft + delta_pixels < mThickness )
			{
				delta_pixels = mThickness - mOrigRect.mLeft - 1;
			}
			else
			if( mOrigRect.mRight + delta_pixels > width - mThickness )
			{
				delta_pixels = width - mThickness - mOrigRect.mRight + 1;
			}

			mThumbRect.mLeft = mOrigRect.mLeft + delta_pixels;
			mThumbRect.mRight = mOrigRect.mRight + delta_pixels;
			
			S32 thumb_length = mThumbRect.getWidth();
			S32 thumb_track_length = width - 2 * mThickness;

			if( delta_pixels != mLastDelta || mDocChanged)
			{	
				// Note: delta_pixels increases as you go up.  mDocPos increases down (line 0 is at the top of the page).
				S32 usable_track_length = thumb_track_length - thumb_length;
				if( 0 < usable_track_length )
				{
					S32 variable_lines = getDocPosMax();
					S32 pos = mThumbRect.mLeft;
					F32 ratio = F32(pos - mThickness) / usable_track_length;	
	
					S32 new_pos = llclamp( S32(ratio * variable_lines + 0.5f), 0, variable_lines);
	
					// Note: we do not call updateThumbRect() here.  Instead we let the thumb and the document go slightly
					// out of sync (less than a line's worth) to make the thumb feel responsive.
					changeLine( new_pos - mDocPos, FALSE );
				}
			}

			mLastDelta = delta_pixels;
		}

		getWindow()->setCursor(UI_CURSOR_ARROW);
		lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl;		
		handled = TRUE;
	}
	else
	{
		handled = childrenHandleHover( x, y, mask ) != NULL;
	}

	// Opaque
	if( !handled )
	{
		getWindow()->setCursor(UI_CURSOR_ARROW);
		lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)"  << llendl;		
		handled = TRUE;
	}

	mDocChanged = FALSE;
	return handled;
} // end handleHover


BOOL LLScrollbar::handleScrollWheel(S32 x, S32 y, S32 clicks)
{
	BOOL handled = changeLine( clicks * mStepSize, TRUE );
	return handled;
}

BOOL LLScrollbar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
									EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string &tooltip_msg)
{
	// enable this to get drag and drop to control scrollbars
	//if (!drop)
	//{
	//	//TODO: refactor this
	//	S32 variable_lines = getDocPosMax();
	//	S32 pos = (VERTICAL == mOrientation) ? y : x;
	//	S32 thumb_length = (VERTICAL == mOrientation) ? mThumbRect.getHeight() : mThumbRect.getWidth();
	//	S32 thumb_track_length = (VERTICAL == mOrientation) ? (getRect().getHeight() - 2 * SCROLLBAR_SIZE) : (getRect().getWidth() - 2 * SCROLLBAR_SIZE);
	//	S32 usable_track_length = thumb_track_length - thumb_length;
	//	F32 ratio = (VERTICAL == mOrientation) ? F32(pos - SCROLLBAR_SIZE - thumb_length) / usable_track_length
	//		: F32(pos - SCROLLBAR_SIZE) / usable_track_length;	
	//	S32 new_pos = (VERTICAL == mOrientation) ? llclamp( S32(variable_lines - ratio * variable_lines + 0.5f), 0, variable_lines )
	//		: llclamp( S32(ratio * variable_lines + 0.5f), 0, variable_lines );
	//	changeLine( new_pos - mDocPos, TRUE );
	//}
	//return TRUE;
	return FALSE;
}

BOOL LLScrollbar::handleMouseUp(S32 x, S32 y, MASK mask)
{
	BOOL handled = FALSE;
	if( hasMouseCapture() )
	{
		gFocusMgr.setMouseCapture( NULL );
		handled = TRUE;
	}
	else
	{
		// Opaque, so don't just check children	
		handled = LLView::handleMouseUp( x, y, mask );
	}

	return handled;
}

BOOL LLScrollbar::handleDoubleClick(S32 x, S32 y, MASK mask)
{
	// just treat a double click as a second click
	return handleMouseDown(x, y, mask);
}


void LLScrollbar::reshape(S32 width, S32 height, BOOL called_from_parent)
{
	if (width == getRect().getWidth() && height == getRect().getHeight()) return;
	LLView::reshape( width, height, called_from_parent );
	LLButton* up_button = getChild<LLButton>("Line Up");
	LLButton* down_button = getChild<LLButton>("Line Down");

	if (mOrientation == VERTICAL)
	{
		up_button->reshape(up_button->getRect().getWidth(), llmin(getRect().getHeight() / 2, mThickness));
		down_button->reshape(down_button->getRect().getWidth(), llmin(getRect().getHeight() / 2, mThickness));
		up_button->setOrigin(up_button->getRect().mLeft, getRect().getHeight() - up_button->getRect().getHeight());
	}
	else
	{
		up_button->reshape(llmin(getRect().getWidth() / 2, mThickness), up_button->getRect().getHeight());
		down_button->reshape(llmin(getRect().getWidth() / 2, mThickness), down_button->getRect().getHeight());
		down_button->setOrigin(getRect().getWidth() - down_button->getRect().getWidth(), down_button->getRect().mBottom);
	}
	updateThumbRect();
}


void LLScrollbar::draw()
{
	if (!getRect().isValid()) return;

	if(mBGVisible)
	{
		gl_rect_2d(getLocalRect(), mBGColor.get(), TRUE);
	}

	S32 local_mouse_x;
	S32 local_mouse_y;
	LLUI::getMousePositionLocal(this, &local_mouse_x, &local_mouse_y);
	BOOL other_captor = gFocusMgr.getMouseCapture() && gFocusMgr.getMouseCapture() != this;
	BOOL hovered = getEnabled() && !other_captor && (hasMouseCapture() || mThumbRect.pointInRect(local_mouse_x, local_mouse_y));
	if (hovered)
	{
		mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLSmoothInterpolation::getInterpolant(0.05f));
	}
	else
	{
		mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLSmoothInterpolation::getInterpolant(0.05f));
	}

	// Draw background and thumb.
	if (   ( mOrientation == VERTICAL&&(mThumbImageV.isNull() || mThumbImageH.isNull()) ) 
		|| (mOrientation == HORIZONTAL&&(mTrackImageH.isNull() || mTrackImageV.isNull()) ))
	{
		gl_rect_2d(mOrientation == HORIZONTAL ? mThickness : 0, 
		mOrientation == VERTICAL ? getRect().getHeight() - 2 * mThickness : getRect().getHeight(),
		mOrientation == HORIZONTAL ? getRect().getWidth() - 2 * mThickness : getRect().getWidth(), 
		mOrientation == VERTICAL ? mThickness : 0, mTrackColor.get(), TRUE);

		gl_rect_2d(mThumbRect, mThumbColor.get(), TRUE);

	}
	else
	{
		// Thumb
		LLRect outline_rect = mThumbRect;
		outline_rect.stretch(2);
		// Background
		
		if(mOrientation == HORIZONTAL)
		{
			mTrackImageH->drawSolid(mThickness								//S32 x
								   , 0										//S32 y
								   , getRect().getWidth() - 2 * mThickness  //S32 width
								   , getRect().getHeight()					//S32 height
								   , mTrackColor.get());                    //const LLColor4& color
			
			if (gFocusMgr.getKeyboardFocus() == this)
			{
				mTrackImageH->draw(outline_rect, gFocusMgr.getFocusColor());
			}
			
			mThumbImageH->draw(mThumbRect, mThumbColor.get());
			if (mCurGlowStrength > 0.01f)
			{
				gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
				mThumbImageH->drawSolid(mThumbRect, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength));
				gGL.setSceneBlendType(LLRender::BT_ALPHA);
			}
			
		}
		else if(mOrientation == VERTICAL)
		{
			mTrackImageV->drawSolid(  0										//S32 x
								   , mThickness								//S32 y
								   , getRect().getWidth()					//S32 width
								   , getRect().getHeight() - 2 * mThickness	//S32 height
								   , mTrackColor.get());                    //const LLColor4& color
			if (gFocusMgr.getKeyboardFocus() == this)
			{
				mTrackImageV->draw(outline_rect, gFocusMgr.getFocusColor());
			}
			
			mThumbImageV->draw(mThumbRect, mThumbColor.get());
			if (mCurGlowStrength > 0.01f)
			{
				gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
				mThumbImageV->drawSolid(mThumbRect, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength));
				gGL.setSceneBlendType(LLRender::BT_ALPHA);
			}
		}
	}

	// Draw children
	LLView::draw();
} // end draw


bool LLScrollbar::changeLine( S32 delta, BOOL update_thumb )
{
	return setDocPos(mDocPos + delta, update_thumb);
}

void LLScrollbar::setValue(const LLSD& value) 
{ 
	setDocPos((S32) value.asInteger());
}


BOOL LLScrollbar::handleKeyHere(KEY key, MASK mask)
{
	BOOL handled = FALSE;

	switch( key )
	{
	case KEY_HOME:
		setDocPos( 0 );
		handled = TRUE;
		break;
	
	case KEY_END:
		setDocPos( getDocPosMax() );
		handled = TRUE;
		break;
	
	case KEY_DOWN:
		setDocPos( getDocPos() + mStepSize );
		handled = TRUE;
		break;
	
	case KEY_UP:
		setDocPos( getDocPos() - mStepSize );
		handled = TRUE;
		break;

	case KEY_PAGE_DOWN:
		pageDown(1);
		break;

	case KEY_PAGE_UP:
		pageUp(1);
		break;
	}

	return handled;
}

void LLScrollbar::pageUp(S32 overlap)
{
	if (mDocSize > mPageSize)
	{
		changeLine( -(mPageSize - overlap), TRUE );
	}
}

void LLScrollbar::pageDown(S32 overlap)
{
	if (mDocSize > mPageSize)
	{
		changeLine( mPageSize - overlap, TRUE );
	}
}

void LLScrollbar::onLineUpBtnPressed( const LLSD& data )
{
	changeLine( -mStepSize, TRUE );
}

void LLScrollbar::onLineDownBtnPressed( const LLSD& data )
{
	changeLine( mStepSize, TRUE );
}