master
richard 2010-02-05 11:34:49 -08:00
commit df3da77fa9
40 changed files with 498 additions and 368 deletions

View File

@ -90,6 +90,7 @@ set(llui_SOURCE_FILES
lltextbox.cpp
lltexteditor.cpp
lltextparser.cpp
lltextvalidate.cpp
lltransutil.cpp
lltoggleablemenu.cpp
lltooltip.cpp
@ -182,6 +183,7 @@ set(llui_HEADER_FILES
lltextbox.h
lltexteditor.h
lltextparser.h
lltextvalidate.h
lltoggleablemenu.h
lltooltip.h
lltransutil.h

View File

@ -83,19 +83,6 @@ template class LLLineEditor* LLView::getChild<class LLLineEditor>(
// Member functions
//
void LLLineEditor::PrevalidateNamedFuncs::declareValues()
{
declare("ascii", LLLineEditor::prevalidateASCII);
declare("float", LLLineEditor::prevalidateFloat);
declare("int", LLLineEditor::prevalidateInt);
declare("positive_s32", LLLineEditor::prevalidatePositiveS32);
declare("non_negative_s32", LLLineEditor::prevalidateNonNegativeS32);
declare("alpha_num", LLLineEditor::prevalidateAlphaNum);
declare("alpha_num_space", LLLineEditor::prevalidateAlphaNumSpace);
declare("ascii_printable_no_pipe", LLLineEditor::prevalidateASCIIPrintableNoPipe);
declare("ascii_printable_no_space", LLLineEditor::prevalidateASCIIPrintableNoSpace);
}
LLLineEditor::Params::Params()
: max_length_bytes("max_length", 254),
keystroke_callback("keystroke_callback"),
@ -1984,51 +1971,12 @@ void LLLineEditor::setRect(const LLRect& rect)
}
}
void LLLineEditor::setPrevalidate(LLLinePrevalidateFunc func)
void LLLineEditor::setPrevalidate(LLTextValidate::validate_func_t func)
{
mPrevalidateFunc = func;
updateAllowingLanguageInput();
}
// Limits what characters can be used to [1234567890.-] with [-] only valid in the first position.
// Does NOT ensure that the string is a well-formed number--that's the job of post-validation--for
// the simple reasons that intermediate states may be invalid even if the final result is valid.
//
// static
BOOL LLLineEditor::prevalidateFloat(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
BOOL success = TRUE;
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
if( 0 < len )
{
// May be a comma or period, depending on the locale
llwchar decimal_point = (llwchar)LLResMgr::getInstance()->getDecimalPoint();
S32 i = 0;
// First character can be a negative sign
if( '-' == trimmed[0] )
{
i++;
}
for( ; i < len; i++ )
{
if( (decimal_point != trimmed[i] ) && !LLStringOps::isDigit( trimmed[i] ) )
{
success = FALSE;
break;
}
}
}
return success;
}
// static
BOOL LLLineEditor::postvalidateFloat(const std::string &str)
{
@ -2088,223 +2036,6 @@ BOOL LLLineEditor::postvalidateFloat(const std::string &str)
return success;
}
// Limits what characters can be used to [1234567890-] with [-] only valid in the first position.
// Does NOT ensure that the string is a well-formed number--that's the job of post-validation--for
// the simple reasons that intermediate states may be invalid even if the final result is valid.
//
// static
BOOL LLLineEditor::prevalidateInt(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
BOOL success = TRUE;
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
if( 0 < len )
{
S32 i = 0;
// First character can be a negative sign
if( '-' == trimmed[0] )
{
i++;
}
for( ; i < len; i++ )
{
if( !LLStringOps::isDigit( trimmed[i] ) )
{
success = FALSE;
break;
}
}
}
return success;
}
// static
BOOL LLLineEditor::prevalidatePositiveS32(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
BOOL success = TRUE;
if(0 < len)
{
if(('-' == trimmed[0]) || ('0' == trimmed[0]))
{
success = FALSE;
}
S32 i = 0;
while(success && (i < len))
{
if(!LLStringOps::isDigit(trimmed[i++]))
{
success = FALSE;
}
}
}
if (success)
{
S32 val = strtol(wstring_to_utf8str(trimmed).c_str(), NULL, 10);
if (val <= 0)
{
success = FALSE;
}
}
return success;
}
BOOL LLLineEditor::prevalidateNonNegativeS32(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
BOOL success = TRUE;
if(0 < len)
{
if('-' == trimmed[0])
{
success = FALSE;
}
S32 i = 0;
while(success && (i < len))
{
if(!LLStringOps::isDigit(trimmed[i++]))
{
success = FALSE;
}
}
}
if (success)
{
S32 val = strtol(wstring_to_utf8str(trimmed).c_str(), NULL, 10);
if (val < 0)
{
success = FALSE;
}
}
return success;
}
BOOL LLLineEditor::prevalidateAlphaNum(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
BOOL rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
if( !LLStringOps::isAlnum((char)str[len]) )
{
rv = FALSE;
break;
}
}
return rv;
}
// static
BOOL LLLineEditor::prevalidateAlphaNumSpace(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
BOOL rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
if(!(LLStringOps::isAlnum((char)str[len]) || (' ' == str[len])))
{
rv = FALSE;
break;
}
}
return rv;
}
// Used for most names of things stored on the server, due to old file-formats
// that used the pipe (|) for multiline text storage. Examples include
// inventory item names, parcel names, object names, etc.
// static
BOOL LLLineEditor::prevalidateASCIIPrintableNoPipe(const LLWString &str)
{
BOOL rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
llwchar wc = str[len];
if (wc < 0x20
|| wc > 0x7f
|| wc == '|')
{
rv = FALSE;
break;
}
if(!(wc == ' '
|| LLStringOps::isAlnum((char)wc)
|| LLStringOps::isPunct((char)wc) ) )
{
rv = FALSE;
break;
}
}
return rv;
}
// Used for avatar names
// static
BOOL LLLineEditor::prevalidateASCIIPrintableNoSpace(const LLWString &str)
{
BOOL rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
llwchar wc = str[len];
if (wc < 0x20
|| wc > 0x7f
|| LLStringOps::isSpace(wc))
{
rv = FALSE;
break;
}
if( !(LLStringOps::isAlnum((char)str[len]) ||
LLStringOps::isPunct((char)str[len]) ) )
{
rv = FALSE;
break;
}
}
return rv;
}
// static
BOOL LLLineEditor::prevalidateASCII(const LLWString &str)
{
BOOL rv = TRUE;
S32 len = str.length();
while(len--)
{
if (str[len] < 0x20 || str[len] > 0x7f)
{
rv = FALSE;
break;
}
}
return rv;
}
void LLLineEditor::onMouseCaptureLost()
{
endSelection();

View File

@ -51,27 +51,18 @@
#include "llviewborder.h"
#include "llpreeditor.h"
#include <boost/function.hpp>
#include "lltextvalidate.h"
class LLFontGL;
class LLLineEditorRollback;
class LLButton;
class LLContextMenu;
typedef boost::function<BOOL (const LLWString &wstr)> LLLinePrevalidateFunc;
class LLLineEditor
: public LLUICtrl, public LLEditMenuHandler, protected LLPreeditor
{
public:
struct PrevalidateNamedFuncs
: public LLInitParam::TypeValuesHelper<LLLinePrevalidateFunc, PrevalidateNamedFuncs>
{
static void declareValues();
};
typedef boost::function<void (LLLineEditor* caller)> keystroke_callback_t;
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
@ -81,7 +72,7 @@ public:
Optional<keystroke_callback_t> keystroke_callback;
Optional<LLLinePrevalidateFunc, PrevalidateNamedFuncs> prevalidate_callback;
Optional<LLTextValidate::validate_func_t, LLTextValidate::ValidateTextNamedFuncs> prevalidate_callback;
Optional<LLViewBorder::Params> border;
@ -236,17 +227,7 @@ public:
void setTextPadding(S32 left, S32 right);
// Prevalidation controls which keystrokes can affect the editor
void setPrevalidate( LLLinePrevalidateFunc func );
static BOOL prevalidateFloat(const LLWString &str );
static BOOL prevalidateInt(const LLWString &str );
static BOOL prevalidatePositiveS32(const LLWString &str);
static BOOL prevalidateNonNegativeS32(const LLWString &str);
static BOOL prevalidateAlphaNum(const LLWString &str );
static BOOL prevalidateAlphaNumSpace(const LLWString &str );
static BOOL prevalidateASCIIPrintableNoPipe(const LLWString &str);
static BOOL prevalidateASCIIPrintableNoSpace(const LLWString &str);
static BOOL prevalidateASCII(const LLWString &str);
void setPrevalidate( LLTextValidate::validate_func_t func );
static BOOL postvalidateFloat(const std::string &str);
// line history support:
@ -326,7 +307,7 @@ protected:
S32 mLastSelectionStart;
S32 mLastSelectionEnd;
LLLinePrevalidateFunc mPrevalidateFunc;
LLTextValidate::validate_func_t mPrevalidateFunc;
LLFrameTimer mKeystrokeTimer;
LLTimer mTripleClickTimer;

View File

@ -138,7 +138,7 @@ LLMultiSliderCtrl::LLMultiSliderCtrl(const LLMultiSliderCtrl::Params& p)
params.font(p.font);
params.max_length_bytes(MAX_STRING_LENGTH);
params.commit_callback.function(LLMultiSliderCtrl::onEditorCommit);
params.prevalidate_callback(&LLLineEditor::prevalidateFloat);
params.prevalidate_callback(&LLTextValidate::validateFloat);
params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM);
mEditor = LLUICtrlFactory::create<LLLineEditor> (params);
mEditor->setFocusReceivedCallback( boost::bind(LLMultiSliderCtrl::onEditorGainFocus, _1, this) );

View File

@ -936,7 +936,7 @@ LLPanel *LLPanel::childGetVisiblePanelWithHelp()
return ::childGetVisiblePanelWithHelp(this);
}
void LLPanel::childSetPrevalidate(const std::string& id, BOOL (*func)(const LLWString &) )
void LLPanel::childSetPrevalidate(const std::string& id, bool (*func)(const LLWString &) )
{
LLLineEditor* child = findChild<LLLineEditor>(id);
if (child)

View File

@ -226,7 +226,7 @@ public:
std::string childGetText(const std::string& id) const { return childGetValue(id).asString(); }
// LLLineEditor
void childSetPrevalidate(const std::string& id, BOOL (*func)(const LLWString &) );
void childSetPrevalidate(const std::string& id, bool (*func)(const LLWString &) );
// LLButton
void childSetAction(const std::string& id, boost::function<void(void*)> function, void* value = NULL);

View File

@ -141,7 +141,7 @@ LLSliderCtrl::LLSliderCtrl(const LLSliderCtrl::Params& p)
line_p.rect.setIfNotProvided(text_rect);
line_p.font.setIfNotProvided(p.font);
line_p.commit_callback.function(&LLSliderCtrl::onEditorCommit);
line_p.prevalidate_callback(&LLLineEditor::prevalidateFloat);
line_p.prevalidate_callback(&LLTextValidate::validateFloat);
mEditor = LLUICtrlFactory::create<LLLineEditor>(line_p);
mEditor->setFocusReceivedCallback( boost::bind(&LLSliderCtrl::onEditorGainFocus, _1, this ));

View File

@ -127,7 +127,7 @@ 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);
params.prevalidate_callback(&LLTextValidate::validateFloat);
params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM);
mEditor = LLUICtrlFactory::create<LLLineEditor> (params);
mEditor->setFocusReceivedCallback( boost::bind(&LLSpinCtrl::onEditorGainFocus, _1, this ));

View File

@ -237,6 +237,7 @@ private:
///////////////////////////////////////////////////////////////////
LLTextEditor::Params::Params()
: default_text("default_text"),
prevalidate_callback("prevalidate_callback"),
embedded_items("embedded_items", false),
ignore_tab("ignore_tab", true),
handle_edit_keys_directly("handle_edit_keys_directly", false),
@ -244,7 +245,9 @@ LLTextEditor::Params::Params()
default_color("default_color"),
commit_on_focus_lost("commit_on_focus_lost", false),
show_context_menu("show_context_menu")
{}
{
addSynonym(prevalidate_callback, "text_type");
}
LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) :
LLTextBase(p),
@ -259,6 +262,7 @@ LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) :
mMouseDownX(0),
mMouseDownY(0),
mTabsToNextField(p.ignore_tab),
mPrevalidateFunc(p.prevalidate_callback()),
mContextMenu(NULL),
mShowContextMenu(p.show_context_menu)
{
@ -320,6 +324,17 @@ LLTextEditor::~LLTextEditor()
void LLTextEditor::setText(const LLStringExplicit &utf8str, const LLStyle::Params& input_params)
{
// validate incoming text if necessary
if (mPrevalidateFunc)
{
LLWString test_text = utf8str_to_wstring(utf8str);
if (!mPrevalidateFunc(test_text))
{
// not valid text, nothing to do
return;
}
}
blockUndo();
deselect();
@ -911,6 +926,21 @@ S32 LLTextEditor::execute( TextCmd* cmd )
// Push the new command is now on the top (front) of the undo stack.
mUndoStack.push_front(cmd);
mLastCmd = cmd;
bool need_to_rollback = mPrevalidateFunc
&& !mPrevalidateFunc(getViewModel()->getDisplay());
if (need_to_rollback)
{
// get rid of this last command and clean up undo stack
undo();
// remove any evidence of this command from redo history
mUndoStack.pop_front();
delete cmd;
// failure, nothing changed
delta = 0;
}
}
else
{
@ -1034,7 +1064,21 @@ S32 LLTextEditor::addChar(S32 pos, llwchar wc)
if (mLastCmd && mLastCmd->canExtend(pos))
{
S32 delta = 0;
if (mPrevalidateFunc)
{
// get a copy of current text contents
LLWString test_string(getViewModel()->getDisplay());
// modify text contents as if this addChar succeeded
llassert(pos <= (S32)test_string.size());
test_string.insert(pos, 1, wc);
if (!mPrevalidateFunc( test_string))
{
return 0;
}
}
mLastCmd->extendAndExecute(this, pos, wc, &delta);
return delta;
}
else

View File

@ -44,6 +44,7 @@
#include "lldarray.h"
#include "llviewborder.h" // for params
#include "lltextbase.h"
#include "lltextvalidate.h"
#include "llpreeditor.h"
#include "llcontrol.h"
@ -63,6 +64,7 @@ public:
struct Params : public LLInitParam::Block<Params, LLTextBase::Params>
{
Optional<std::string> default_text;
Optional<LLTextValidate::validate_func_t, LLTextValidate::ValidateTextNamedFuncs> prevalidate_callback;
Optional<bool> embedded_items,
ignore_tab,
@ -334,6 +336,7 @@ private:
LLCoordGL mLastIMEPosition; // Last position of the IME editor
keystroke_signal_t mKeystrokeSignal;
LLTextValidate::validate_func_t mPrevalidateFunc;
LLContextMenu* mContextMenu;
}; // end class LLTextEditor

View File

@ -0,0 +1,302 @@
/**
* @file lltextvalidate.cpp
* @brief Text validation helper functions
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-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$
*/
// Text editor widget to let users enter a single line.
#include "linden_common.h"
#include "lltextvalidate.h"
#include "llresmgr.h" // for LLLocale
namespace LLTextValidate
{
void ValidateTextNamedFuncs::declareValues()
{
declare("ascii", validateASCII);
declare("float", validateFloat);
declare("int", validateInt);
declare("positive_s32", validatePositiveS32);
declare("non_negative_s32", validateNonNegativeS32);
declare("alpha_num", validateAlphaNum);
declare("alpha_num_space", validateAlphaNumSpace);
declare("ascii_printable_no_pipe", validateASCIIPrintableNoPipe);
declare("ascii_printable_no_space", validateASCIIPrintableNoSpace);
}
// Limits what characters can be used to [1234567890.-] with [-] only valid in the first position.
// Does NOT ensure that the string is a well-formed number--that's the job of post-validation--for
// the simple reasons that intermediate states may be invalid even if the final result is valid.
//
bool validateFloat(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
bool success = TRUE;
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
if( 0 < len )
{
// May be a comma or period, depending on the locale
llwchar decimal_point = (llwchar)LLResMgr::getInstance()->getDecimalPoint();
S32 i = 0;
// First character can be a negative sign
if( '-' == trimmed[0] )
{
i++;
}
for( ; i < len; i++ )
{
if( (decimal_point != trimmed[i] ) && !LLStringOps::isDigit( trimmed[i] ) )
{
success = FALSE;
break;
}
}
}
return success;
}
// Limits what characters can be used to [1234567890-] with [-] only valid in the first position.
// Does NOT ensure that the string is a well-formed number--that's the job of post-validation--for
// the simple reasons that intermediate states may be invalid even if the final result is valid.
//
bool validateInt(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
bool success = TRUE;
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
if( 0 < len )
{
S32 i = 0;
// First character can be a negative sign
if( '-' == trimmed[0] )
{
i++;
}
for( ; i < len; i++ )
{
if( !LLStringOps::isDigit( trimmed[i] ) )
{
success = FALSE;
break;
}
}
}
return success;
}
bool validatePositiveS32(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
bool success = TRUE;
if(0 < len)
{
if(('-' == trimmed[0]) || ('0' == trimmed[0]))
{
success = FALSE;
}
S32 i = 0;
while(success && (i < len))
{
if(!LLStringOps::isDigit(trimmed[i++]))
{
success = FALSE;
}
}
}
if (success)
{
S32 val = strtol(wstring_to_utf8str(trimmed).c_str(), NULL, 10);
if (val <= 0)
{
success = FALSE;
}
}
return success;
}
bool validateNonNegativeS32(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
LLWString trimmed = str;
LLWStringUtil::trim(trimmed);
S32 len = trimmed.length();
bool success = TRUE;
if(0 < len)
{
if('-' == trimmed[0])
{
success = FALSE;
}
S32 i = 0;
while(success && (i < len))
{
if(!LLStringOps::isDigit(trimmed[i++]))
{
success = FALSE;
}
}
}
if (success)
{
S32 val = strtol(wstring_to_utf8str(trimmed).c_str(), NULL, 10);
if (val < 0)
{
success = FALSE;
}
}
return success;
}
bool validateAlphaNum(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
bool rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
if( !LLStringOps::isAlnum((char)str[len]) )
{
rv = FALSE;
break;
}
}
return rv;
}
bool validateAlphaNumSpace(const LLWString &str)
{
LLLocale locale(LLLocale::USER_LOCALE);
bool rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
if(!(LLStringOps::isAlnum((char)str[len]) || (' ' == str[len])))
{
rv = FALSE;
break;
}
}
return rv;
}
// Used for most names of things stored on the server, due to old file-formats
// that used the pipe (|) for multiline text storage. Examples include
// inventory item names, parcel names, object names, etc.
bool validateASCIIPrintableNoPipe(const LLWString &str)
{
bool rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
llwchar wc = str[len];
if (wc < 0x20
|| wc > 0x7f
|| wc == '|')
{
rv = FALSE;
break;
}
if(!(wc == ' '
|| LLStringOps::isAlnum((char)wc)
|| LLStringOps::isPunct((char)wc) ) )
{
rv = FALSE;
break;
}
}
return rv;
}
// Used for avatar names
bool validateASCIIPrintableNoSpace(const LLWString &str)
{
bool rv = TRUE;
S32 len = str.length();
if(len == 0) return rv;
while(len--)
{
llwchar wc = str[len];
if (wc < 0x20
|| wc > 0x7f
|| LLStringOps::isSpace(wc))
{
rv = FALSE;
break;
}
if( !(LLStringOps::isAlnum((char)str[len]) ||
LLStringOps::isPunct((char)str[len]) ) )
{
rv = FALSE;
break;
}
}
return rv;
}
bool validateASCII(const LLWString &str)
{
bool rv = TRUE;
S32 len = str.length();
while(len--)
{
if (str[len] < 0x20 || str[len] > 0x7f)
{
rv = FALSE;
break;
}
}
return rv;
}
}

View File

@ -0,0 +1,63 @@
/**
* @file lltextbase.h
* @author Martin Reddy
* @brief The base class of text box/editor, providing Url handling support
*
* $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$
*/
#ifndef LL_LLTEXTVALIDATE_H
#define LL_LLTEXTVALIDATE_H
#include "llstring.h"
#include "llinitparam.h"
#include <boost/function.hpp>
namespace LLTextValidate
{
typedef boost::function<BOOL (const LLWString &wstr)> validate_func_t;
struct ValidateTextNamedFuncs
: public LLInitParam::TypeValuesHelper<validate_func_t, ValidateTextNamedFuncs>
{
static void declareValues();
};
bool validateFloat(const LLWString &str );
bool validateInt(const LLWString &str );
bool validatePositiveS32(const LLWString &str);
bool validateNonNegativeS32(const LLWString &str);
bool validateAlphaNum(const LLWString &str );
bool validateAlphaNumSpace(const LLWString &str );
bool validateASCIIPrintableNoPipe(const LLWString &str);
bool validateASCIIPrintableNoSpace(const LLWString &str);
bool validateASCII(const LLWString &str);
}
#endif

View File

@ -129,7 +129,8 @@ private:
class LLInspector : public LLToolTip
{
public:
struct Params : public LLInitParam::Block<Params, LLToolTip::Params> {};
struct Params : public LLInitParam::Block<Params, LLToolTip::Params>
{};
};
class LLToolTipMgr : public LLSingleton<LLToolTipMgr>

View File

@ -262,7 +262,7 @@ public:
mSourceType = CHAT_SOURCE_SYSTEM;
}
LLTextEditor* userName = getChild<LLTextEditor>("user_name");
LLTextBox* userName = getChild<LLTextBox>("user_name");
userName->setReadOnlyColor(style_params.readonly_color());
userName->setColor(style_params.color());
@ -300,7 +300,7 @@ public:
/*virtual*/ void draw()
{
LLTextEditor* user_name = getChild<LLTextEditor>("user_name");
LLTextBox* user_name = getChild<LLTextBox>("user_name");
LLTextBox* time_box = getChild<LLTextBox>("time_box");
LLRect user_name_rect = user_name->getRect();

View File

@ -426,7 +426,7 @@ void LLCurrencyUIManager::Impl::prepare()
LLLineEditor* lindenAmount = mPanel.getChild<LLLineEditor>("currency_amt");
if (lindenAmount)
{
lindenAmount->setPrevalidate(LLLineEditor::prevalidateNonNegativeS32);
lindenAmount->setPrevalidate(LLTextValidate::validateNonNegativeS32);
lindenAmount->setKeystrokeCallback(onCurrencyKey, this);
}
}

View File

@ -65,7 +65,7 @@ public:
LLPanelCameraZoom();
/* virtual */ BOOL postBuild();
/* virtual */ void onOpen(const LLSD& key);
/* virtual */ void draw();
protected:
void onZoomPlusHeldDown();
@ -73,7 +73,6 @@ protected:
void onSliderValueChanged();
private:
F32 mSavedSliderVal;
LLButton* mPlusBtn;
LLButton* mMinusBtn;
LLSlider* mSlider;
@ -88,8 +87,7 @@ static LLRegisterPanelClassWrapper<LLPanelCameraZoom> t_camera_zoom_panel("camer
LLPanelCameraZoom::LLPanelCameraZoom()
: mPlusBtn( NULL ),
mMinusBtn( NULL ),
mSlider( NULL ),
mSavedSliderVal(0.f)
mSlider( NULL )
{
mCommitCallbackRegistrar.add("Zoom.minus", boost::bind(&LLPanelCameraZoom::onZoomPlusHeldDown, this));
mCommitCallbackRegistrar.add("Zoom.plus", boost::bind(&LLPanelCameraZoom::onZoomMinusHeldDown, this));
@ -101,16 +99,13 @@ BOOL LLPanelCameraZoom::postBuild()
mPlusBtn = getChild <LLButton> ("zoom_plus_btn");
mMinusBtn = getChild <LLButton> ("zoom_minus_btn");
mSlider = getChild <LLSlider> ("zoom_slider");
mSlider->setMinValue(.0f);
mSlider->setMaxValue(8.f);
return LLPanel::postBuild();
}
void LLPanelCameraZoom::onOpen(const LLSD& key)
void LLPanelCameraZoom::draw()
{
LLVector3d to_focus = gAgent.getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin()) - gAgent.calcFocusPositionTargetGlobal();
mSavedSliderVal = 8.f - (F32)to_focus.magVec(); // maximum minus current
mSlider->setValue( mSavedSliderVal );
mSlider->setValue(gAgent.getCameraZoomFraction());
LLPanel::draw();
}
void LLPanelCameraZoom::onZoomPlusHeldDown()
@ -135,13 +130,8 @@ void LLPanelCameraZoom::onZoomMinusHeldDown()
void LLPanelCameraZoom::onSliderValueChanged()
{
F32 val = mSlider->getValueF32();
F32 rate = val - mSavedSliderVal;
gAgent.unlockView();
gAgent.cameraOrbitIn(rate);
mSavedSliderVal = val;
F32 zoom_level = mSlider->getValueF32();
gAgent.setCameraZoomFraction(zoom_level);
}
void activate_camera_tool()

View File

@ -414,17 +414,17 @@ LLPanelRegionTools::LLPanelRegionTools()
BOOL LLPanelRegionTools::postBuild()
{
getChild<LLLineEditor>("region name")->setKeystrokeCallback(onChangeSimName, this);
childSetPrevalidate("region name", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("estate", &LLLineEditor::prevalidatePositiveS32);
childSetPrevalidate("parentestate", &LLLineEditor::prevalidatePositiveS32);
childSetPrevalidate("region name", &LLTextValidate::validateASCIIPrintableNoPipe);
childSetPrevalidate("estate", &LLTextValidate::validatePositiveS32);
childSetPrevalidate("parentestate", &LLTextValidate::validatePositiveS32);
childDisable("parentestate");
childSetPrevalidate("gridposx", &LLLineEditor::prevalidatePositiveS32);
childSetPrevalidate("gridposx", &LLTextValidate::validatePositiveS32);
childDisable("gridposx");
childSetPrevalidate("gridposy", &LLLineEditor::prevalidatePositiveS32);
childSetPrevalidate("gridposy", &LLTextValidate::validatePositiveS32);
childDisable("gridposy");
childSetPrevalidate("redirectx", &LLLineEditor::prevalidatePositiveS32);
childSetPrevalidate("redirecty", &LLLineEditor::prevalidatePositiveS32);
childSetPrevalidate("redirectx", &LLTextValidate::validatePositiveS32);
childSetPrevalidate("redirecty", &LLTextValidate::validatePositiveS32);
return TRUE;
}

View File

@ -353,7 +353,7 @@ BOOL LLPanelLandGeneral::postBuild()
{
mEditName = getChild<LLLineEditor>("Name");
mEditName->setCommitCallback(onCommitAny, this);
childSetPrevalidate("Name", LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("Name", LLTextValidate::validateASCIIPrintableNoPipe);
mEditDesc = getChild<LLTextEditor>("Description");
mEditDesc->setCommitOnFocusLost(TRUE);
@ -1111,7 +1111,7 @@ BOOL LLPanelLandObjects::postBuild()
mCleanOtherObjectsTime->setFocusLostCallback(boost::bind(onLostFocus, _1, this));
mCleanOtherObjectsTime->setCommitCallback(onCommitClean, this);
childSetPrevalidate("clean other time", LLLineEditor::prevalidateNonNegativeS32);
childSetPrevalidate("clean other time", LLTextValidate::validateNonNegativeS32);
mBtnRefresh = getChild<LLButton>("Refresh List");
mBtnRefresh->setClickedCallback(onClickRefresh, this);

View File

@ -111,7 +111,7 @@ BOOL LLFloaterNameDesc::postBuild()
if (NameEditor)
{
NameEditor->setMaxTextLength(DB_INV_ITEM_NAME_STR_LEN);
NameEditor->setPrevalidate(&LLLineEditor::prevalidateASCIIPrintableNoPipe);
NameEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
}
y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
@ -123,7 +123,7 @@ BOOL LLFloaterNameDesc::postBuild()
if (DescEditor)
{
DescEditor->setMaxTextLength(DB_INV_ITEM_DESC_STR_LEN);
DescEditor->setPrevalidate(&LLLineEditor::prevalidateASCIIPrintableNoPipe);
DescEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
}
y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);

View File

@ -204,7 +204,7 @@ BOOL LLFloaterPay::postBuild()
getChild<LLLineEditor>("amount")->setKeystrokeCallback(&LLFloaterPay::onKeystroke, this);
childSetText("amount", last_amount);
childSetPrevalidate("amount", LLLineEditor::prevalidateNonNegativeS32);
childSetPrevalidate("amount", LLTextValidate::validateNonNegativeS32);
info = new LLGiveMoneyInfo(this, 0);
mCallbackData.push_back(info);

View File

@ -130,9 +130,9 @@ BOOL LLFloaterProperties::postBuild()
{
// build the UI
// item name & description
childSetPrevalidate("LabelItemName",&LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("LabelItemName",&LLTextValidate::validateASCIIPrintableNoPipe);
getChild<LLUICtrl>("LabelItemName")->setCommitCallback(boost::bind(&LLFloaterProperties::onCommitName,this));
childSetPrevalidate("LabelItemDesc",&LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("LabelItemDesc",&LLTextValidate::validateASCIIPrintableNoPipe);
getChild<LLUICtrl>("LabelItemDesc")->setCommitCallback(boost::bind(&LLFloaterProperties:: onCommitDescription, this));
// Creator information
getChild<LLUICtrl>("BtnCreator")->setCommitCallback(boost::bind(&LLFloaterProperties::onClickCreator,this));

View File

@ -163,7 +163,7 @@ BOOL LLFloaterSellLandUI::postBuild()
{
childSetCommitCallback("sell_to", onChangeValue, this);
childSetCommitCallback("price", onChangeValue, this);
childSetPrevalidate("price", LLLineEditor::prevalidateNonNegativeS32);
childSetPrevalidate("price", LLTextValidate::validateNonNegativeS32);
childSetCommitCallback("sell_objects", onChangeValue, this);
childSetAction("sell_to_select_agent", boost::bind( &LLFloaterSellLandUI::doSelectAgent, this));
childSetAction("cancel_btn", doCancel, this);
@ -268,7 +268,7 @@ void LLFloaterSellLandUI::refreshUI()
std::string price_str = childGetValue("price").asString();
bool valid_price = false;
valid_price = (price_str != "") && LLLineEditor::prevalidateNonNegativeS32(utf8str_to_wstring(price_str));
valid_price = (price_str != "") && LLTextValidate::validateNonNegativeS32(utf8str_to_wstring(price_str));
if (valid_price && mParcelActualArea > 0)
{

View File

@ -225,7 +225,7 @@ LLFolderView::LLFolderView(const Params& p)
params.font(getLabelFontForStyle(LLFontGL::NORMAL));
params.max_length_bytes(DB_INV_ITEM_NAME_STR_LEN);
params.commit_callback.function(boost::bind(&LLFolderView::commitRename, this, _2));
params.prevalidate_callback(&LLLineEditor::prevalidateASCIIPrintableNoPipe);
params.prevalidate_callback(&LLTextValidate::validateASCIIPrintableNoPipe);
params.commit_on_focus_lost(true);
params.visible(false);
mRenamer = LLUICtrlFactory::create<LLLineEditor> (params);

View File

@ -242,7 +242,7 @@ BOOL LLPanelClassified::postBuild()
mNameEditor->setCommitOnFocusLost(TRUE);
mNameEditor->setFocusReceivedCallback(boost::bind(focusReceived, _1, this));
mNameEditor->setCommitCallback(onCommitAny, this);
mNameEditor->setPrevalidate( LLLineEditor::prevalidateASCII );
mNameEditor->setPrevalidate( LLTextValidate::validateASCII );
mDescEditor = getChild<LLTextEditor>("desc_editor");
mDescEditor->setCommitOnFocusLost(TRUE);
@ -1072,7 +1072,7 @@ BOOL LLFloaterPriceForListing::postBuild()
LLLineEditor* edit = getChild<LLLineEditor>("price_edit");
if (edit)
{
edit->setPrevalidate(LLLineEditor::prevalidateNonNegativeS32);
edit->setPrevalidate(LLTextValidate::validateNonNegativeS32);
std::string min_price = llformat("%d", MINIMUM_PRICE_FOR_LISTING);
edit->setText(min_price);
edit->selectAll();

View File

@ -214,7 +214,7 @@ void LLPanelGroupGeneral::setupCtrls(LLPanel* panel_group)
}
mFounderName = panel_group->getChild<LLNameBox>("founder_name");
mGroupNameEditor = panel_group->getChild<LLLineEditor>("group_name_editor");
mGroupNameEditor->setPrevalidate( LLLineEditor::prevalidateASCII );
mGroupNameEditor->setPrevalidate( LLTextValidate::validateASCII );
}
// static

View File

@ -213,8 +213,8 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect,
}
#if !USE_VIEWER_AUTH
childSetPrevalidate("first_name_edit", LLLineEditor::prevalidateASCIIPrintableNoSpace);
childSetPrevalidate("last_name_edit", LLLineEditor::prevalidateASCIIPrintableNoSpace);
childSetPrevalidate("first_name_edit", LLTextValidate::validateASCIIPrintableNoSpace);
childSetPrevalidate("last_name_edit", LLTextValidate::validateASCIIPrintableNoSpace);
childSetCommitCallback("password_edit", mungePassword, this);
getChild<LLLineEditor>("password_edit")->setKeystrokeCallback(onPassKey, this);

View File

@ -142,9 +142,9 @@ LLPanelPermissions::LLPanelPermissions() :
BOOL LLPanelPermissions::postBuild()
{
childSetCommitCallback("Object Name",LLPanelPermissions::onCommitName,this);
childSetPrevalidate("Object Name",LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("Object Name",LLTextValidate::validateASCIIPrintableNoPipe);
childSetCommitCallback("Object Description",LLPanelPermissions::onCommitDesc,this);
childSetPrevalidate("Object Description",LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("Object Description",LLTextValidate::validateASCIIPrintableNoPipe);
getChild<LLUICtrl>("button set group")->setCommitCallback(boost::bind(&LLPanelPermissions::onClickGroup,this));

View File

@ -79,7 +79,7 @@ BOOL LLPreviewAnim::postBuild()
childSetAction("Anim audition btn",auditionAnim, this);
childSetCommitCallback("desc", LLPreview::onText, this);
childSetPrevalidate("desc", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("desc", &LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
}

View File

@ -472,7 +472,7 @@ BOOL LLPreviewGesture::postBuild()
edit = getChild<LLLineEditor>("wait_time_editor");
edit->setEnabled(FALSE);
edit->setVisible(FALSE);
edit->setPrevalidate(LLLineEditor::prevalidateFloat);
edit->setPrevalidate(LLTextValidate::validateFloat);
// edit->setKeystrokeCallback(onKeystrokeCommit, this);
edit->setCommitOnFocusLost(TRUE);
edit->setCommitCallback(onCommitWaitTime, this);
@ -504,10 +504,10 @@ BOOL LLPreviewGesture::postBuild()
if (item)
{
childSetText("desc", item->getDescription());
childSetPrevalidate("desc", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("desc", &LLTextValidate::validateASCIIPrintableNoPipe);
childSetText("name", item->getName());
childSetPrevalidate("name", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("name", &LLTextValidate::validateASCIIPrintableNoPipe);
}
return LLPreview::postBuild();

View File

@ -95,7 +95,7 @@ BOOL LLPreviewNotecard::postBuild()
childSetCommitCallback("desc", LLPreview::onText, this);
if (item)
childSetText("desc", item->getDescription());
childSetPrevalidate("desc", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("desc", &LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
}

View File

@ -955,7 +955,7 @@ BOOL LLPreviewLSL::postBuild()
childSetCommitCallback("desc", LLPreview::onText, this);
childSetText("desc", item->getDescription());
childSetPrevalidate("desc", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("desc", &LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
}

View File

@ -75,7 +75,7 @@ BOOL LLPreviewSound::postBuild()
button->setSoundFlags(LLView::SILENT);
childSetCommitCallback("desc", LLPreview::onText, this);
childSetPrevalidate("desc", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("desc", &LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
}

View File

@ -126,7 +126,7 @@ BOOL LLPreviewTexture::postBuild()
{
childSetCommitCallback("desc", LLPreview::onText, this);
childSetText("desc", item->getDescription());
childSetPrevalidate("desc", &LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("desc", &LLTextValidate::validateASCIIPrintableNoPipe);
}
}

View File

@ -109,9 +109,9 @@ BOOL LLSidepanelItemInfo::postBuild()
{
LLSidepanelInventorySubpanel::postBuild();
childSetPrevalidate("LabelItemName",&LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("LabelItemName",&LLTextValidate::validateASCIIPrintableNoPipe);
getChild<LLUICtrl>("LabelItemName")->setCommitCallback(boost::bind(&LLSidepanelItemInfo::onCommitName,this));
childSetPrevalidate("LabelItemDesc",&LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("LabelItemDesc",&LLTextValidate::validateASCIIPrintableNoPipe);
getChild<LLUICtrl>("LabelItemDesc")->setCommitCallback(boost::bind(&LLSidepanelItemInfo:: onCommitDescription, this));
// Creator information
getChild<LLUICtrl>("BtnCreator")->setCommitCallback(boost::bind(&LLSidepanelItemInfo::onClickCreator,this));

View File

@ -104,9 +104,9 @@ BOOL LLSidepanelTaskInfo::postBuild()
mLabelGroupName = getChild<LLNameBox>("Group Name Proxy");
childSetCommitCallback("Object Name", LLSidepanelTaskInfo::onCommitName,this);
childSetPrevalidate("Object Name", LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("Object Name", LLTextValidate::validateASCIIPrintableNoPipe);
childSetCommitCallback("Object Description", LLSidepanelTaskInfo::onCommitDesc,this);
childSetPrevalidate("Object Description", LLLineEditor::prevalidateASCIIPrintableNoPipe);
childSetPrevalidate("Object Description", LLTextValidate::validateASCIIPrintableNoPipe);
getChild<LLUICtrl>("button set group")->setCommitCallback(boost::bind(&LLSidepanelTaskInfo::onClickGroup,this));
childSetCommitCallback("checkbox share with group", &LLSidepanelTaskInfo::onCommitGroupShare,this);
childSetAction("button deed", &LLSidepanelTaskInfo::onClickDeedToGroup,this);

View File

@ -82,6 +82,8 @@
orientation="vertical"
tool_tip="Zoom camera toward focus"
top_pad="0"
min_val="0"
max_val="1"
width="18">
<commit_callback function="Slider.value_changed"/>
</slider_bar>

View File

@ -28,4 +28,17 @@
width="200">
This contains long text and should scroll horizontally to the right
</text_editor>
<text_editor
height="50"
follows="top|left|bottom"
font="SansSerif"
left="10"
name="numeric_text_editor"
tool_tip="text editor for numeric text entry only"
top_pad="10"
text_type="int"
width="200">
This is text that is NOT a number, so shouldn't appear
</text_editor>
</floater>

View File

@ -19,7 +19,7 @@
name="avatar_icon"
top="3"
width="18" />
<text_editor
<text
allow_scroll="false"
v_pad = "7"
read_only = "true"

View File

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!-- See also settings.xml UIFloater* settings for configuration -->
<inspector name="inspector"
bg_opaque_color="DkGray_66"
background_visible="true"
bg_opaque_image="none"
background_opaque="true"
bg_alpha_image="none"
text_color="InspectorTipTextColor"
/>
bg_opaque_color="DkGray_66"
background_visible="true"
bg_opaque_image="none"
background_opaque="true"
bg_alpha_image="none"
mouse_opaque="true"
text_color="InspectorTipTextColor"/>

View File

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!-- See also settings.xml UIFloater* settings for configuration -->
<tool_tip name="tooltip"
max_width="200"
padding="4"
wrap="true"
font="SansSerif"
mouse_opaque="false"
bg_opaque_image="Tooltip"
background_opaque="true"
background_visible="true"
text_color="ToolTipTextColor"
/>
text_color="ToolTipTextColor"/>