aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lltextbox.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llui/lltextbox.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/llui/lltextbox.cpp')
-rw-r--r--linden/indra/llui/lltextbox.cpp124
1 files changed, 58 insertions, 66 deletions
diff --git a/linden/indra/llui/lltextbox.cpp b/linden/indra/llui/lltextbox.cpp
index 1422e0a..9ad7849 100644
--- a/linden/indra/llui/lltextbox.cpp
+++ b/linden/indra/llui/lltextbox.cpp
@@ -30,21 +30,14 @@
30 */ 30 */
31 31
32#include "linden_common.h" 32#include "linden_common.h"
33
34#include "lltextbox.h" 33#include "lltextbox.h"
35
36#include "llerror.h"
37#include "llgl.h"
38#include "llui.h"
39#include "lluictrlfactory.h" 34#include "lluictrlfactory.h"
40#include "llcontrol.h"
41#include "llfocusmgr.h" 35#include "llfocusmgr.h"
42#include "llstl.h"
43#include <boost/tokenizer.hpp>
44 36
45LLTextBox::LLTextBox(const LLString& name, const LLRect& rect, const LLString& text, 37LLTextBox::LLTextBox(const LLString& name, const LLRect& rect, const LLString& text,
46 const LLFontGL* font, BOOL mouse_opaque) 38 const LLFontGL* font, BOOL mouse_opaque)
47: LLUICtrl(name, rect, mouse_opaque, NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP ), 39: LLUICtrl(name, rect, mouse_opaque, NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP ),
40 mFontGL(font ? font : LLFontGL::sSansSerifSmall),
48 mTextColor( LLUI::sColorsGroup->getColor( "LabelTextColor" ) ), 41 mTextColor( LLUI::sColorsGroup->getColor( "LabelTextColor" ) ),
49 mDisabledColor( LLUI::sColorsGroup->getColor( "LabelDisabledColor" ) ), 42 mDisabledColor( LLUI::sColorsGroup->getColor( "LabelDisabledColor" ) ),
50 mBackgroundColor( LLUI::sColorsGroup->getColor( "DefaultBackgroundColor" ) ), 43 mBackgroundColor( LLUI::sColorsGroup->getColor( "DefaultBackgroundColor" ) ),
@@ -64,9 +57,7 @@ LLTextBox::LLTextBox(const LLString& name, const LLRect& rect, const LLString& t
64 mClickedCallback(NULL), 57 mClickedCallback(NULL),
65 mCallbackUserData(NULL) 58 mCallbackUserData(NULL)
66{ 59{
67 // TomY TODO Nuke this eventually 60 setText( text );
68 setText( !text.empty() ? text : name );
69 mFontGL = font ? font : LLFontGL::sSansSerifSmall;
70 setTabStop(FALSE); 61 setTabStop(FALSE);
71} 62}
72 63
@@ -93,25 +84,54 @@ LLTextBox::LLTextBox(const LLString& name, const LLString& text, F32 max_width,
93 mClickedCallback(NULL), 84 mClickedCallback(NULL),
94 mCallbackUserData(NULL) 85 mCallbackUserData(NULL)
95{ 86{
96 setWrappedText(!text.empty() ? text : name, max_width); 87 setWrappedText(text, max_width);
97 reshapeToFitText(); 88 reshapeToFitText();
98 setTabStop(FALSE); 89 setTabStop(FALSE);
99} 90}
100 91
101LLTextBox::~LLTextBox() 92LLTextBox::LLTextBox(const LLString& name_and_label, const LLRect& rect) :
102{ 93 LLUICtrl(name_and_label, rect, TRUE, NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP),
103} 94 mFontGL(LLFontGL::sSansSerifSmall),
104 95 mTextColor(LLUI::sColorsGroup->getColor("LabelTextColor")),
105// virtual 96 mDisabledColor(LLUI::sColorsGroup->getColor("LabelDisabledColor")),
106EWidgetType LLTextBox::getWidgetType() const 97 mBackgroundColor(LLUI::sColorsGroup->getColor("DefaultBackgroundColor")),
98 mBorderColor(LLUI::sColorsGroup->getColor("DefaultHighlightLight")),
99 mBackgroundVisible(FALSE),
100 mBorderVisible(FALSE),
101 mFontStyle(LLFontGL::DROP_SHADOW_SOFT),
102 mBorderDropShadowVisible(FALSE),
103 mHPad(0),
104 mVPad(0),
105 mHAlign(LLFontGL::LEFT),
106 mVAlign( LLFontGL::TOP ),
107 mClickedCallback(NULL),
108 mCallbackUserData(NULL)
107{ 109{
108 return WIDGET_TYPE_TEXT_BOX; 110 setText( name_and_label );
111 setTabStop(FALSE);
109} 112}
110 113
111// virtual 114LLTextBox::LLTextBox(const LLString& name_and_label) :
112LLString LLTextBox::getWidgetTag() const 115 LLUICtrl(name_and_label, LLRect(0, 0, 1, 1), TRUE, NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP),
116 mFontGL(LLFontGL::sSansSerifSmall),
117 mTextColor(LLUI::sColorsGroup->getColor("LabelTextColor")),
118 mDisabledColor(LLUI::sColorsGroup->getColor("LabelDisabledColor")),
119 mBackgroundColor(LLUI::sColorsGroup->getColor("DefaultBackgroundColor")),
120 mBorderColor(LLUI::sColorsGroup->getColor("DefaultHighlightLight")),
121 mBackgroundVisible(FALSE),
122 mBorderVisible(FALSE),
123 mFontStyle(LLFontGL::DROP_SHADOW_SOFT),
124 mBorderDropShadowVisible(FALSE),
125 mHPad(0),
126 mVPad(0),
127 mHAlign(LLFontGL::LEFT),
128 mVAlign( LLFontGL::TOP ),
129 mClickedCallback(NULL),
130 mCallbackUserData(NULL)
113{ 131{
114 return LL_TEXT_BOX_TAG; 132 setWrappedText(name_and_label);
133 reshapeToFitText();
134 setTabStop(FALSE);
115} 135}
116 136
117BOOL LLTextBox::handleMouseDown(S32 x, S32 y, MASK mask) 137BOOL LLTextBox::handleMouseDown(S32 x, S32 y, MASK mask)
@@ -127,7 +147,7 @@ BOOL LLTextBox::handleMouseDown(S32 x, S32 y, MASK mask)
127 // Route future Mouse messages here preemptively. (Release on mouse up.) 147 // Route future Mouse messages here preemptively. (Release on mouse up.)
128 gFocusMgr.setMouseCapture( this ); 148 gFocusMgr.setMouseCapture( this );
129 149
130 if (mSoundFlags & MOUSE_DOWN) 150 if (getSoundFlags() & MOUSE_DOWN)
131 { 151 {
132 make_ui_sound("UISndClick"); 152 make_ui_sound("UISndClick");
133 } 153 }
@@ -153,7 +173,7 @@ BOOL LLTextBox::handleMouseUp(S32 x, S32 y, MASK mask)
153 // Release the mouse 173 // Release the mouse
154 gFocusMgr.setMouseCapture( NULL ); 174 gFocusMgr.setMouseCapture( NULL );
155 175
156 if (mSoundFlags & MOUSE_UP) 176 if (getSoundFlags() & MOUSE_UP)
157 { 177 {
158 make_ui_sound("UISndClickRelease"); 178 make_ui_sound("UISndClickRelease");
159 } 179 }
@@ -294,16 +314,6 @@ S32 LLTextBox::getTextPixelHeight()
294} 314}
295 315
296 316
297void LLTextBox::setValue(const LLSD& value )
298{
299 setText(value.asString());
300}
301
302LLSD LLTextBox::getValue() const
303{
304 return LLSD(getText());
305}
306
307BOOL LLTextBox::setTextArg( const LLString& key, const LLStringExplicit& text ) 317BOOL LLTextBox::setTextArg( const LLString& key, const LLStringExplicit& text )
308{ 318{
309 mText.setArg(key, text); 319 mText.setArg(key, text);
@@ -324,13 +334,13 @@ void LLTextBox::draw()
324 { 334 {
325 static LLColor4 color_drop_shadow = LLUI::sColorsGroup->getColor("ColorDropShadow"); 335 static LLColor4 color_drop_shadow = LLUI::sColorsGroup->getColor("ColorDropShadow");
326 static S32 drop_shadow_tooltip = LLUI::sConfigGroup->getS32("DropShadowTooltip"); 336 static S32 drop_shadow_tooltip = LLUI::sConfigGroup->getS32("DropShadowTooltip");
327 gl_drop_shadow(0, mRect.getHeight(), mRect.getWidth(), 0, 337 gl_drop_shadow(0, getRect().getHeight(), getRect().getWidth(), 0,
328 color_drop_shadow, drop_shadow_tooltip); 338 color_drop_shadow, drop_shadow_tooltip);
329 } 339 }
330 340
331 if (mBackgroundVisible) 341 if (mBackgroundVisible)
332 { 342 {
333 LLRect r( 0, mRect.getHeight(), mRect.getWidth(), 0 ); 343 LLRect r( 0, getRect().getHeight(), getRect().getWidth(), 0 );
334 gl_rect_2d( r, mBackgroundColor ); 344 gl_rect_2d( r, mBackgroundColor );
335 } 345 }
336 346
@@ -341,14 +351,14 @@ void LLTextBox::draw()
341 text_x = mHPad; 351 text_x = mHPad;
342 break; 352 break;
343 case LLFontGL::HCENTER: 353 case LLFontGL::HCENTER:
344 text_x = mRect.getWidth() / 2; 354 text_x = getRect().getWidth() / 2;
345 break; 355 break;
346 case LLFontGL::RIGHT: 356 case LLFontGL::RIGHT:
347 text_x = mRect.getWidth() - mHPad; 357 text_x = getRect().getWidth() - mHPad;
348 break; 358 break;
349 } 359 }
350 360
351 S32 text_y = mRect.getHeight() - mVPad; 361 S32 text_y = getRect().getHeight() - mVPad;
352 362
353 if ( getEnabled() ) 363 if ( getEnabled() )
354 { 364 {
@@ -360,7 +370,6 @@ void LLTextBox::draw()
360 { 370 {
361 drawText( text_x, text_y, mTextColor ); 371 drawText( text_x, text_y, mTextColor );
362 } 372 }
363
364 } 373 }
365 else 374 else
366 { 375 {
@@ -385,7 +394,14 @@ void LLTextBox::reshape(S32 width, S32 height, BOOL called_from_parent)
385 394
386void LLTextBox::drawText( S32 x, S32 y, const LLColor4& color ) 395void LLTextBox::drawText( S32 x, S32 y, const LLColor4& color )
387{ 396{
388 if( !mLineLengthList.empty() ) 397 if( mLineLengthList.empty() )
398 {
399 mFontGL->render(mText.getWString(), 0, (F32)x, (F32)y, color,
400 mHAlign, mVAlign,
401 mFontStyle,
402 S32_MAX, getRect().getWidth(), NULL, TRUE, mUseEllipses);
403 }
404 else
389 { 405 {
390 S32 cur_pos = 0; 406 S32 cur_pos = 0;
391 for (std::vector<S32>::iterator iter = mLineLengthList.begin(); 407 for (std::vector<S32>::iterator iter = mLineLengthList.begin();
@@ -395,21 +411,13 @@ void LLTextBox::drawText( S32 x, S32 y, const LLColor4& color )
395 mFontGL->render(mText.getWString(), cur_pos, (F32)x, (F32)y, color, 411 mFontGL->render(mText.getWString(), cur_pos, (F32)x, (F32)y, color,
396 mHAlign, mVAlign, 412 mHAlign, mVAlign,
397 mFontStyle, 413 mFontStyle,
398 line_length, mRect.getWidth(), NULL, TRUE, mUseEllipses ); 414 line_length, getRect().getWidth(), NULL, TRUE, mUseEllipses );
399 cur_pos += line_length + 1; 415 cur_pos += line_length + 1;
400 y -= llfloor(mFontGL->getLineHeight()); 416 y -= llfloor(mFontGL->getLineHeight());
401 } 417 }
402 } 418 }
403 else
404 {
405 mFontGL->render(mText.getWString(), 0, (F32)x, (F32)y, color,
406 mHAlign, mVAlign,
407 mFontStyle,
408 S32_MAX, mRect.getWidth(), NULL, TRUE, mUseEllipses);
409 }
410} 419}
411 420
412
413void LLTextBox::reshapeToFitText() 421void LLTextBox::reshapeToFitText()
414{ 422{
415 S32 width = getTextPixelWidth(); 423 S32 width = getTextPixelWidth();
@@ -423,28 +431,19 @@ LLXMLNodePtr LLTextBox::getXML(bool save_children) const
423 LLXMLNodePtr node = LLUICtrl::getXML(); 431 LLXMLNodePtr node = LLUICtrl::getXML();
424 432
425 // Attributes 433 // Attributes
426
427 node->createChild("font", TRUE)->setStringValue(LLFontGL::nameFromFont(mFontGL)); 434 node->createChild("font", TRUE)->setStringValue(LLFontGL::nameFromFont(mFontGL));
428
429 node->createChild("halign", TRUE)->setStringValue(LLFontGL::nameFromHAlign(mHAlign)); 435 node->createChild("halign", TRUE)->setStringValue(LLFontGL::nameFromHAlign(mHAlign));
430
431 addColorXML(node, mTextColor, "text_color", "LabelTextColor"); 436 addColorXML(node, mTextColor, "text_color", "LabelTextColor");
432 addColorXML(node, mDisabledColor, "disabled_color", "LabelDisabledColor"); 437 addColorXML(node, mDisabledColor, "disabled_color", "LabelDisabledColor");
433 addColorXML(node, mBackgroundColor, "bg_color", "DefaultBackgroundColor"); 438 addColorXML(node, mBackgroundColor, "bg_color", "DefaultBackgroundColor");
434 addColorXML(node, mBorderColor, "border_color", "DefaultHighlightLight"); 439 addColorXML(node, mBorderColor, "border_color", "DefaultHighlightLight");
435
436 node->createChild("bg_visible", TRUE)->setBoolValue(mBackgroundVisible); 440 node->createChild("bg_visible", TRUE)->setBoolValue(mBackgroundVisible);
437
438 node->createChild("border_visible", TRUE)->setBoolValue(mBorderVisible); 441 node->createChild("border_visible", TRUE)->setBoolValue(mBorderVisible);
439
440 node->createChild("border_drop_shadow_visible", TRUE)->setBoolValue(mBorderDropShadowVisible); 442 node->createChild("border_drop_shadow_visible", TRUE)->setBoolValue(mBorderDropShadowVisible);
441
442 node->createChild("h_pad", TRUE)->setIntValue(mHPad); 443 node->createChild("h_pad", TRUE)->setIntValue(mHPad);
443
444 node->createChild("v_pad", TRUE)->setIntValue(mVPad); 444 node->createChild("v_pad", TRUE)->setIntValue(mVPad);
445 445
446 // Contents 446 // Contents
447
448 node->setStringValue(mText); 447 node->setStringValue(mText);
449 448
450 return node; 449 return node;
@@ -459,12 +458,6 @@ LLView* LLTextBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *f
459 458
460 LLString text = node->getTextContents(); 459 LLString text = node->getTextContents();
461 460
462 // TomY Yes I know this is a hack, but insert a space to make a blank text field
463 if (text == "")
464 {
465 text = " ";
466 }
467
468 LLTextBox* text_box = new LLTextBox(name, 461 LLTextBox* text_box = new LLTextBox(name,
469 LLRect(), 462 LLRect(),
470 text, 463 text,
@@ -510,6 +503,5 @@ LLView* LLTextBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *f
510 text_box->setHoverActive(hover_active); 503 text_box->setHoverActive(hover_active);
511 } 504 }
512 505
513
514 return text_box; 506 return text_box;
515} 507}