summaryrefslogtreecommitdiff
path: root/indra/llui/llspinctrl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/llspinctrl.cpp')
-rw-r--r--indra/llui/llspinctrl.cpp183
1 files changed, 95 insertions, 88 deletions
diff --git a/indra/llui/llspinctrl.cpp b/indra/llui/llspinctrl.cpp
index 72329a4b32..9decfa0b25 100644
--- a/indra/llui/llspinctrl.cpp
+++ b/indra/llui/llspinctrl.cpp
@@ -2,31 +2,25 @@
* @file llspinctrl.cpp
* @brief LLSpinCtrl base class
*
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2009, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2001&license=viewerlgpl$
* 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
+ * 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.
*
- * 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
+ * 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.
*
- * 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.
+ * 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
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -45,7 +39,6 @@
#include "lltextbox.h"
#include "llkeyboard.h"
#include "llmath.h"
-#include "audioengine.h"
#include "llcontrol.h"
#include "llfocusmgr.h"
#include "llresmgr.h"
@@ -53,14 +46,16 @@
const U32 MAX_STRING_LENGTH = 32;
-static LLDefaultWidgetRegistry::Register<LLSpinCtrl> r2("spinner");
+static LLDefaultChildRegistry::Register<LLSpinCtrl> r2("spinner");
LLSpinCtrl::Params::Params()
: label_width("label_width"),
decimal_digits("decimal_digits"),
allow_text_entry("allow_text_entry", true),
text_enabled_color("text_enabled_color"),
- text_disabled_color("text_disabled_color")
+ text_disabled_color("text_disabled_color"),
+ up_button("up_button"),
+ down_button("down_button")
{}
LLSpinCtrl::LLSpinCtrl(const LLSpinCtrl::Params& p)
@@ -74,10 +69,8 @@ LLSpinCtrl::LLSpinCtrl(const LLSpinCtrl::Params& p)
static LLUICachedControl<S32> spinctrl_spacing ("UISpinctrlSpacing", 0);
static LLUICachedControl<S32> spinctrl_btn_width ("UISpinctrlBtnWidth", 0);
static LLUICachedControl<S32> spinctrl_btn_height ("UISpinctrlBtnHeight", 0);
- S32 top = getRect().getHeight();
- S32 bottom = top - 2 * spinctrl_btn_height;
- S32 centered_top = top;
- S32 centered_bottom = bottom;
+ S32 centered_top = getRect().getHeight();
+ S32 centered_bottom = getRect().getHeight() - 2 * spinctrl_btn_height;
S32 btn_left = 0;
// reserve space for spinner
S32 label_width = llclamp(p.label_width(), 0, llmax(0, getRect().getWidth() - 40));
@@ -89,7 +82,7 @@ LLSpinCtrl::LLSpinCtrl(const LLSpinCtrl::Params& p)
LLTextBox::Params params;
params.name("SpinCtrl Label");
params.rect(label_rect);
- params.text(p.label);
+ params.initial_value(p.label());
if (p.font.isProvided())
{
params.font(p.font);
@@ -103,38 +96,18 @@ LLSpinCtrl::LLSpinCtrl(const LLSpinCtrl::Params& p)
S32 btn_right = btn_left + spinctrl_btn_width;
// Spin buttons
- LLButton::Params up_button_params;
- up_button_params.name(std::string("SpinCtrl Up"));
- up_button_params.rect
- .left(btn_left)
- .top(top)
- .right(btn_right)
- .height(spinctrl_btn_height);
- up_button_params.follows.flags(FOLLOWS_LEFT|FOLLOWS_BOTTOM);
- up_button_params.image_unselected.name("spin_up_out_blue.tga");
- up_button_params.image_selected.name("spin_up_in_blue.tga");
+ LLButton::Params up_button_params(p.up_button);
+ up_button_params.rect = LLRect(btn_left, getRect().getHeight(), btn_right, getRect().getHeight() - spinctrl_btn_height);
up_button_params.click_callback.function(boost::bind(&LLSpinCtrl::onUpBtn, this, _2));
up_button_params.mouse_held_callback.function(boost::bind(&LLSpinCtrl::onUpBtn, this, _2));
- up_button_params.tab_stop(false);
mUpBtn = LLUICtrlFactory::create<LLButton>(up_button_params);
addChild(mUpBtn);
- LLRect down_rect( btn_left, top - spinctrl_btn_height, btn_right, bottom );
-
- LLButton::Params down_button_params;
- down_button_params.name(std::string("SpinCtrl Down"));
- down_button_params.rect
- .left(btn_left)
- .right(btn_right)
- .bottom(bottom)
- .height(spinctrl_btn_height);
- down_button_params.follows.flags(FOLLOWS_LEFT|FOLLOWS_BOTTOM);
- down_button_params.image_unselected.name("spin_down_out_blue.tga");
- down_button_params.image_selected.name("spin_down_in_blue.tga");
+ LLButton::Params down_button_params(p.down_button);
+ down_button_params.rect = LLRect(btn_left, getRect().getHeight() - spinctrl_btn_height, btn_right, getRect().getHeight() - 2 * spinctrl_btn_height);
down_button_params.click_callback.function(boost::bind(&LLSpinCtrl::onDownBtn, this, _2));
down_button_params.mouse_held_callback.function(boost::bind(&LLSpinCtrl::onDownBtn, this, _2));
- down_button_params.tab_stop(false);
mDownBtn = LLUICtrlFactory::create<LLButton>(down_button_params);
addChild(mDownBtn);
@@ -148,10 +121,19 @@ LLSpinCtrl::LLSpinCtrl(const LLSpinCtrl::Params& p)
}
params.max_length_bytes(MAX_STRING_LENGTH);
params.commit_callback.function((boost::bind(&LLSpinCtrl::onEditorCommit, this, _2)));
- params.prevalidate_callback(&LLLineEditor::prevalidateFloat);
+
+ if( mPrecision>0 )//should accept float numbers
+ {
+ params.prevalidate_callback(&LLTextValidate::validateFloat);
+ }
+ else //should accept int numbers
+ {
+ params.prevalidate_callback(&LLTextValidate::validateInt);
+ }
+
params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM);
mEditor = LLUICtrlFactory::create<LLLineEditor> (params);
- mEditor->setFocusReceivedCallback( &LLSpinCtrl::onEditorGainFocus, this );
+ mEditor->setFocusReceivedCallback( boost::bind(&LLSpinCtrl::onEditorGainFocus, _1, this ));
//RN: this seems to be a BAD IDEA, as it makes the editor behavior different when it has focus
// than when it doesn't. Instead, if you always have to double click to select all the text,
// it's easier to understand
@@ -183,23 +165,33 @@ void LLSpinCtrl::onUpBtn( const LLSD& data )
{
if( getEnabled() )
{
- // use getValue()/setValue() to force reload from/to control
- F32 val = (F32)getValue().asReal() + mIncrement;
- val = clamp_precision(val, mPrecision);
- val = llmin( val, mMaxValue );
-
- F32 saved_val = (F32)getValue().asReal();
- setValue(val);
- if( !mValidateSignal( this, val ) )
+ std::string text = mEditor->getText();
+ if( LLLineEditor::postvalidateFloat( text ) )
{
- setValue( saved_val );
- reportInvalidData();
- updateEditor();
- return;
- }
+
+ LLLocale locale(LLLocale::USER_LOCALE);
+ F32 cur_val = (F32) atof(text.c_str());
+
+ // use getValue()/setValue() to force reload from/to control
+ F32 val = cur_val + mIncrement;
+ val = clamp_precision(val, mPrecision);
+ val = llmin( val, mMaxValue );
+ if (val < mMinValue) val = mMinValue;
+ if (val > mMaxValue) val = mMaxValue;
+
+ F32 saved_val = (F32)getValue().asReal();
+ setValue(val);
+ if( mValidateSignal && !(*mValidateSignal)( this, val ) )
+ {
+ setValue( saved_val );
+ reportInvalidData();
+ updateEditor();
+ return;
+ }
updateEditor();
onCommit();
+ }
}
}
@@ -207,22 +199,33 @@ void LLSpinCtrl::onDownBtn( const LLSD& data )
{
if( getEnabled() )
{
- F32 val = (F32)getValue().asReal() - mIncrement;
- val = clamp_precision(val, mPrecision);
- val = llmax( val, mMinValue );
-
- F32 saved_val = (F32)getValue().asReal();
- setValue(val);
- if( !mValidateSignal( this, val ) )
+ std::string text = mEditor->getText();
+ if( LLLineEditor::postvalidateFloat( text ) )
{
- setValue( saved_val );
- reportInvalidData();
+
+ LLLocale locale(LLLocale::USER_LOCALE);
+ F32 cur_val = (F32) atof(text.c_str());
+
+ F32 val = cur_val - mIncrement;
+ val = clamp_precision(val, mPrecision);
+ val = llmax( val, mMinValue );
+
+ if (val < mMinValue) val = mMinValue;
+ if (val > mMaxValue) val = mMaxValue;
+
+ F32 saved_val = (F32)getValue().asReal();
+ setValue(val);
+ if( mValidateSignal && !(*mValidateSignal)( this, val ) )
+ {
+ setValue( saved_val );
+ reportInvalidData();
+ updateEditor();
+ return;
+ }
+
updateEditor();
- return;
+ onCommit();
}
-
- updateEditor();
- onCommit();
}
}
@@ -270,13 +273,19 @@ void LLSpinCtrl::clear()
mbHasBeenSet = FALSE;
}
-
+void LLSpinCtrl::updateLabelColor()
+{
+ if( mLabelBox )
+ {
+ mLabelBox->setColor( getEnabled() ? mTextEnabledColor.get() : mTextDisabledColor.get() );
+ }
+}
void LLSpinCtrl::updateEditor()
{
LLLocale locale(LLLocale::USER_LOCALE);
- // Don't display very small negative values as -0.000
+ // Don't display very small negative valu es as -0.000
F32 displayed_value = clamp_precision((F32)getValue().asReal(), mPrecision);
// if( S32( displayed_value * pow( 10, mPrecision ) ) == 0 )
@@ -304,7 +313,7 @@ void LLSpinCtrl::onEditorCommit( const LLSD& data )
F32 saved_val = getValueF32();
setValue(val);
- if( mValidateSignal( this, val ) )
+ if( !mValidateSignal || (*mValidateSignal)( this, val ) )
{
success = TRUE;
onCommit();
@@ -339,10 +348,7 @@ void LLSpinCtrl::setEnabled(BOOL b)
{
LLView::setEnabled( b );
mEditor->setEnabled( b );
- if( mLabelBox )
- {
- mLabelBox->setColor( b ? mTextEnabledColor.get() : mTextDisabledColor.get() );
- }
+ updateLabelColor();
}
@@ -390,6 +396,7 @@ void LLSpinCtrl::setLabel(const LLStringExplicit& label)
{
llwarns << "Attempting to set label on LLSpinCtrl constructed without one " << getName() << llendl;
}
+ updateLabelColor();
}
void LLSpinCtrl::setAllowEdit(BOOL allow_edit)