aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui
diff options
context:
space:
mode:
authorMcCabe Maxsted2009-01-12 02:17:03 -0700
committerMcCabe Maxsted2009-01-12 02:17:03 -0700
commitdd99e2a6b5054927bba83d44a7a03bc365c28a77 (patch)
tree7f94ef4010b3bef22d8c481d8c700cfb1219ffe5 /linden/indra/llui
parentWind disabled by default, ambient wind muting fixed, added debug setting 'Mut... (diff)
downloadmeta-impy-dd99e2a6b5054927bba83d44a7a03bc365c28a77.zip
meta-impy-dd99e2a6b5054927bba83d44a7a03bc365c28a77.tar.gz
meta-impy-dd99e2a6b5054927bba83d44a7a03bc365c28a77.tar.bz2
meta-impy-dd99e2a6b5054927bba83d44a7a03bc365c28a77.tar.xz
Applied Aimee's patch for doing simple math in the build editor
Diffstat (limited to 'linden/indra/llui')
-rw-r--r--linden/indra/llui/lllineeditor.cpp33
-rw-r--r--linden/indra/llui/lllineeditor.h4
-rw-r--r--linden/indra/llui/llspinctrl.cpp17
3 files changed, 47 insertions, 7 deletions
diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp
index 12d1929..9c8ee94 100644
--- a/linden/indra/llui/lllineeditor.cpp
+++ b/linden/indra/llui/lllineeditor.cpp
@@ -41,6 +41,7 @@
41#include "llgl.h" 41#include "llgl.h"
42#include "lltimer.h" 42#include "lltimer.h"
43 43
44#include "llcalc.h"
44//#include "llclipboard.h" 45//#include "llclipboard.h"
45#include "llcontrol.h" 46#include "llcontrol.h"
46#include "llbutton.h" 47#include "llbutton.h"
@@ -129,6 +130,7 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect,
129 mDrawAsterixes( FALSE ), 130 mDrawAsterixes( FALSE ),
130 mHandleEditKeysDirectly( FALSE ), 131 mHandleEditKeysDirectly( FALSE ),
131 mSelectAllonFocusReceived( FALSE ), 132 mSelectAllonFocusReceived( FALSE ),
133 mSelectAllonCommit( TRUE ),
132 mPassDelete(FALSE), 134 mPassDelete(FALSE),
133 mReadOnly(FALSE), 135 mReadOnly(FALSE),
134 mImage( sImage ), 136 mImage( sImage ),
@@ -226,7 +228,10 @@ void LLLineEditor::onCommit()
226 updateHistory(); 228 updateHistory();
227 229
228 LLUICtrl::onCommit(); 230 LLUICtrl::onCommit();
229 selectAll(); 231
232 // Selection on commit needs to be turned off when evaluating maths
233 // expressions, to allow indication of the error position
234 if (mSelectAllonCommit) selectAll();
230} 235}
231 236
232 237
@@ -2082,6 +2087,32 @@ BOOL LLLineEditor::prevalidateASCII(const LLWString &str)
2082 return rv; 2087 return rv;
2083} 2088}
2084 2089
2090BOOL LLLineEditor::evaluateFloat()
2091{
2092 bool success;
2093 F32 result = 0.f;
2094 std::string expr = getText();
2095
2096 success = LLCalc::getInstance()->evalString(expr, result);
2097
2098 if (!success)
2099 {
2100 // Move the cursor to near the error on failure
2101 setCursor(LLCalc::getInstance()->getLastErrorPos());
2102 // *TODO: Translated error message indicating the type of error? Select error text?
2103 }
2104 else
2105 {
2106 // Replace the expression with the result
2107 std::ostringstream result_str;
2108 result_str << result;
2109 setText(result_str.str());
2110 selectAll();
2111 }
2112
2113 return success;
2114}
2115
2085void LLLineEditor::onMouseCaptureLost() 2116void LLLineEditor::onMouseCaptureLost()
2086{ 2117{
2087 endSelection(); 2118 endSelection();
diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h
index 09a240b..6738151 100644
--- a/linden/indra/llui/lllineeditor.h
+++ b/linden/indra/llui/lllineeditor.h
@@ -188,6 +188,7 @@ public:
188 188
189 void setHandleEditKeysDirectly( BOOL b ) { mHandleEditKeysDirectly = b; } 189 void setHandleEditKeysDirectly( BOOL b ) { mHandleEditKeysDirectly = b; }
190 void setSelectAllonFocusReceived(BOOL b); 190 void setSelectAllonFocusReceived(BOOL b);
191 void setSelectAllonCommit(BOOL b) { mSelectAllonCommit = b; }
191 192
192 void setKeystrokeCallback(void (*keystroke_callback)(LLLineEditor* caller, void* user_data)); 193 void setKeystrokeCallback(void (*keystroke_callback)(LLLineEditor* caller, void* user_data));
193 194
@@ -208,6 +209,8 @@ public:
208 static BOOL prevalidateASCII(const LLWString &str); 209 static BOOL prevalidateASCII(const LLWString &str);
209 210
210 static BOOL postvalidateFloat(const std::string &str); 211 static BOOL postvalidateFloat(const std::string &str);
212
213 BOOL evaluateFloat();
211 214
212 // line history support: 215 // line history support:
213 void setEnableLineHistory( BOOL enabled ) { mHaveHistory = enabled; } // switches line history on or off 216 void setEnableLineHistory( BOOL enabled ) { mHaveHistory = enabled; } // switches line history on or off
@@ -297,6 +300,7 @@ protected:
297 300
298 BOOL mHandleEditKeysDirectly; // If true, the standard edit keys (Ctrl-X, Delete, etc,) are handled here instead of routed by the menu system 301 BOOL mHandleEditKeysDirectly; // If true, the standard edit keys (Ctrl-X, Delete, etc,) are handled here instead of routed by the menu system
299 BOOL mSelectAllonFocusReceived; 302 BOOL mSelectAllonFocusReceived;
303 BOOL mSelectAllonCommit;
300 BOOL mPassDelete; 304 BOOL mPassDelete;
301 305
302 BOOL mReadOnly; 306 BOOL mReadOnly;
diff --git a/linden/indra/llui/llspinctrl.cpp b/linden/indra/llui/llspinctrl.cpp
index a106af4..b12d095 100644
--- a/linden/indra/llui/llspinctrl.cpp
+++ b/linden/indra/llui/llspinctrl.cpp
@@ -49,7 +49,7 @@
49#include "llfocusmgr.h" 49#include "llfocusmgr.h"
50#include "llresmgr.h" 50#include "llresmgr.h"
51 51
52const U32 MAX_STRING_LENGTH = 32; 52const U32 MAX_STRING_LENGTH = 255;
53 53
54static LLRegisterWidget<LLSpinCtrl> r2("spinner"); 54static LLRegisterWidget<LLSpinCtrl> r2("spinner");
55 55
@@ -123,7 +123,7 @@ LLSpinCtrl::LLSpinCtrl( const std::string& name, const LLRect& rect, const std::
123 mEditor = new LLLineEditor( std::string("SpinCtrl Editor"), editor_rect, LLStringUtil::null, font, 123 mEditor = new LLLineEditor( std::string("SpinCtrl Editor"), editor_rect, LLStringUtil::null, font,
124 MAX_STRING_LENGTH, 124 MAX_STRING_LENGTH,
125 &LLSpinCtrl::onEditorCommit, NULL, NULL, this, 125 &LLSpinCtrl::onEditorCommit, NULL, NULL, this,
126 &LLLineEditor::prevalidateFloat ); 126 &LLLineEditor::prevalidateASCII );
127 mEditor->setFollowsLeft(); 127 mEditor->setFollowsLeft();
128 mEditor->setFollowsBottom(); 128 mEditor->setFollowsBottom();
129 mEditor->setFocusReceivedCallback( &LLSpinCtrl::onEditorGainFocus, this ); 129 mEditor->setFocusReceivedCallback( &LLSpinCtrl::onEditorGainFocus, this );
@@ -132,6 +132,7 @@ LLSpinCtrl::LLSpinCtrl( const std::string& name, const LLRect& rect, const std::
132 // it's easier to understand 132 // it's easier to understand
133 //mEditor->setSelectAllonFocusReceived(TRUE); 133 //mEditor->setSelectAllonFocusReceived(TRUE);
134 mEditor->setIgnoreTab(TRUE); 134 mEditor->setIgnoreTab(TRUE);
135 mEditor->setSelectAllonCommit(FALSE);
135 addChild(mEditor); 136 addChild(mEditor);
136 137
137 updateEditor(); 138 updateEditor();
@@ -292,9 +293,10 @@ void LLSpinCtrl::onEditorCommit( LLUICtrl* caller, void *userdata )
292 LLSpinCtrl* self = (LLSpinCtrl*) userdata; 293 LLSpinCtrl* self = (LLSpinCtrl*) userdata;
293 llassert( caller == self->mEditor ); 294 llassert( caller == self->mEditor );
294 295
295 std::string text = self->mEditor->getText(); 296 if( self->mEditor->evaluateFloat() )
296 if( LLLineEditor::postvalidateFloat( text ) )
297 { 297 {
298 std::string text = self->mEditor->getText();
299
298 LLLocale locale(LLLocale::USER_LOCALE); 300 LLLocale locale(LLLocale::USER_LOCALE);
299 F32 val = (F32) atof(text.c_str()); 301 F32 val = (F32) atof(text.c_str());
300 302
@@ -322,9 +324,12 @@ void LLSpinCtrl::onEditorCommit( LLUICtrl* caller, void *userdata )
322 success = TRUE; 324 success = TRUE;
323 } 325 }
324 } 326 }
325 self->updateEditor();
326 327
327 if( !success ) 328 if( success )
329 {
330 self->updateEditor();
331 }
332 else
328 { 333 {
329 self->reportInvalidData(); 334 self->reportInvalidData();
330 } 335 }