summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaszlo Kis-Adam <dfighter1985@gmail.com>2015-03-20 02:14:38 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-03-28 19:55:30 +0100
commitfd28dea50930797652afbdce6992bea08c56caa0 (patch)
tree22d3c1415447f485c0a50893ae0affc2ffcdbb38
parent78ad5ecd988270f3308fe98cc128ddf832c0c00b (diff)
tdf#42897 Warn the user if string without quote is entered as condition value.
Change-Id: I5b30b608c0192b434ff237513ed7fbbf5af43f11
-rw-r--r--sc/inc/globstr.hrc5
-rw-r--r--sc/source/ui/condformat/condformatdlgentry.cxx80
-rw-r--r--sc/source/ui/inc/condformatdlg.hrc2
-rw-r--r--sc/source/ui/inc/condformatdlgentry.hxx10
-rw-r--r--sc/source/ui/src/condformatdlg.src6
-rw-r--r--sc/source/ui/src/globstr.src8
6 files changed, 89 insertions, 22 deletions
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index eab98cc892bc..9ef50d511db8 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -695,7 +695,10 @@
#define STR_UNDO_CONDFORMAT 531
#define STR_UNDO_FORMULA_TO_VALUE 532
-#define SC_GLOBSTR_STR_COUNT 533 /**< the count of permanently resident strings */
+#define STR_UNQUOTED_STRING 533
+#define STR_ENTER_VALUE 534
+
+#define SC_GLOBSTR_STR_COUNT 535 /**< the count of permanently resident strings */
#endif
diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx b/sc/source/ui/condformat/condformatdlgentry.cxx
index 87c7f4530781..4fd949d78dca 100644
--- a/sc/source/ui/condformat/condformatdlgentry.cxx
+++ b/sc/source/ui/condformat/condformatdlgentry.cxx
@@ -23,9 +23,11 @@
#include <svx/drawitem.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/settings.hxx>
+#include <formula/token.hxx>
#include "tokenarray.hxx"
#include "stlpool.hxx"
#include "tabvwsh.hxx"
+#include "simpleformulacalc.hxx"
#include "colorformat.hxx"
@@ -124,23 +126,6 @@ void ScCondFrmtEntry::Deselect()
SetHeight();
}
-IMPL_LINK(ScCondFrmtEntry, EdModifyHdl, Edit*, pEdit)
-{
- OUString aFormula = pEdit->GetText();
- ScCompiler aComp( mpDoc, maPos );
- aComp.SetGrammar( mpDoc->GetGrammar() );
- boost::scoped_ptr<ScTokenArray> mpCode(aComp.CompileString(aFormula));
- if(mpCode->GetCodeError())
- {
- pEdit->SetControlBackground(COL_LIGHTRED);
- }
- else
- {
- pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
- }
- return 0;
-}
-
//condition
namespace {
@@ -197,6 +182,7 @@ ScConditionFrmtEntry::ScConditionFrmtEntry( vcl::Window* pParent, ScDocument* pD
maLbCondType( this, ScResId( LB_CELLIS_TYPE ) ),
maEdVal1( this, NULL, NULL, ScResId( ED_VAL1 ) ),
maEdVal2( this, NULL, NULL, ScResId( ED_VAL2 ) ),
+ maFtVal( this, ScResId( FT_VAL ) ),
maFtStyle( this, ScResId( FT_STYLE ) ),
maLbStyle( this, ScResId( LB_STYLE ) ),
maWdPreview( this, ScResId( WD_PREVIEW ) ),
@@ -256,8 +242,8 @@ void ScConditionFrmtEntry::Init(ScCondFormatDlg* pDialogParent)
maEdVal1.SetStyle( maEdVal1.GetStyle() | WB_FORCECTRLBACKGROUND );
maEdVal2.SetStyle( maEdVal2.GetStyle() | WB_FORCECTRLBACKGROUND );
- maEdVal1.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
- maEdVal2.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
+ maEdVal1.SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) );
+ maEdVal2.SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) );
FillStyleListBox( mpDoc, maLbStyle );
maLbStyle.SetSelectHdl( LINK( this, ScConditionFrmtEntry, StyleSelectHdl ) );
@@ -283,6 +269,59 @@ ScFormatEntry* ScConditionFrmtEntry::createConditionEntry() const
return pEntry;
}
+IMPL_LINK(ScConditionFrmtEntry, OnEdChanged, Edit*, pEdit)
+{
+ OUString aFormula = pEdit->GetText();
+
+ if( aFormula.isEmpty() )
+ {
+ maFtVal.SetText(ScGlobal::GetRscString(STR_ENTER_VALUE));
+ return 0;
+ }
+
+ ScCompiler aComp( mpDoc, maPos );
+ aComp.SetGrammar( mpDoc->GetGrammar() );
+ boost::scoped_ptr<ScTokenArray> ta(aComp.CompileString(aFormula));
+
+ // Error, warn the user
+ if( ta->GetCodeError() )
+ {
+ pEdit->SetControlBackground(COL_LIGHTRED);
+ maFtVal.SetText(ScGlobal::GetRscString(STR_VALID_DEFERROR));
+ return 0;
+ }
+
+ // Recognized col/row name or string token, warn the user
+ formula::FormulaToken* token = ta->First();
+ formula::StackVar t = token->GetType();
+ OpCode op = token->GetOpCode();
+ if( ( op == ocColRowName ) ||
+ ( ( op == ocBad ) && ( t == formula::svString ) )
+ )
+ {
+ pEdit->SetControlBackground(COL_LIGHTRED);
+ maFtVal.SetText(ScGlobal::GetRscString(STR_UNQUOTED_STRING));
+ return 0;
+ }
+
+ pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
+ maFtVal.SetText("");
+ return 0;
+}
+
+void ScConditionFrmtEntry::Select()
+{
+ maFtVal.Show();
+ ScCondFrmtEntry::Select();
+}
+
+void ScConditionFrmtEntry::Deselect()
+{
+ maFtVal.Hide();
+ ScCondFrmtEntry::Deselect();
+}
+
+
sal_Int32 ScConditionFrmtEntry::ConditionModeToEntryPos( ScConditionMode eMode ) const
{
for ( sal_Int32 i = 0; i < NUM_COND_ENTRIES; ++i )
@@ -994,14 +1033,17 @@ IMPL_LINK_NOARG( ScConditionFrmtEntry, ConditionTypeSelectHdl )
case 0:
maEdVal1.Hide();
maEdVal2.Hide();
+ maFtVal.Hide();
break;
case 1:
maEdVal1.Show();
maEdVal2.Hide();
+ maFtVal.Show();
break;
case 2:
maEdVal1.Show();
maEdVal2.Show();
+ maFtVal.Show();
break;
}
diff --git a/sc/source/ui/inc/condformatdlg.hrc b/sc/source/ui/inc/condformatdlg.hrc
index 5aa27e63be81..af801f5edef3 100644
--- a/sc/source/ui/inc/condformatdlg.hrc
+++ b/sc/source/ui/inc/condformatdlg.hrc
@@ -55,4 +55,6 @@
#define FT_ICON_SET_ENTRY_TEXT 49
#define ED_ICON_SET_ENTRY_VALUE 50
+#define FT_VAL 51
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformatdlgentry.hxx b/sc/source/ui/inc/condformatdlgentry.hxx
index 99b3c7f3fd92..0ed7a5b40717 100644
--- a/sc/source/ui/inc/condformatdlgentry.hxx
+++ b/sc/source/ui/inc/condformatdlgentry.hxx
@@ -59,8 +59,8 @@ protected:
DECL_LINK( EdModifyHdl, Edit* );
- void Select();
- void Deselect();
+ virtual void Select();
+ virtual void Deselect();
virtual OUString GetExpressionString() = 0;
@@ -88,6 +88,7 @@ class ScConditionFrmtEntry : public ScCondFrmtEntry, public SfxListener
ListBox maLbCondType;
formula::RefEdit maEdVal1;
formula::RefEdit maEdVal2;
+ FixedText maFtVal;
FixedText maFtStyle;
ListBox maLbStyle;
SvxFontPrevWindow maWdPreview;
@@ -103,6 +104,7 @@ class ScConditionFrmtEntry : public ScCondFrmtEntry, public SfxListener
void Init(ScCondFormatDlg* pDialogParent);
DECL_LINK( StyleSelectHdl, void* );
DECL_LINK( ConditionTypeSelectHdl, void* );
+ DECL_LINK( OnEdChanged, Edit* );
// Searches the lookup table for the entry position, given condition mode
sal_Int32 ConditionModeToEntryPos( ScConditionMode eMode ) const;
@@ -111,6 +113,10 @@ class ScConditionFrmtEntry : public ScCondFrmtEntry, public SfxListener
// Returns the number of edit fields used for a given condition mode
sal_Int32 GetNumberEditFields( ScConditionMode eMode ) const;
+protected:
+ virtual void Select() SAL_OVERRIDE;
+ virtual void Deselect() SAL_OVERRIDE;
+
public:
ScConditionFrmtEntry( vcl::Window* pParent, ScDocument* pDoc, ScCondFormatDlg* pDialogParent,
const ScAddress& rPos, const ScCondFormatEntry* pFormatEntry = NULL );
diff --git a/sc/source/ui/src/condformatdlg.src b/sc/source/ui/src/condformatdlg.src
index 68e91e943a11..d086dcaf3589 100644
--- a/sc/source/ui/src/condformatdlg.src
+++ b/sc/source/ui/src/condformatdlg.src
@@ -190,6 +190,12 @@ Control RID_COND_ENTRY
Text [ en-US ] = "Example";
Border = TRUE;
};
+ FixedText FT_VAL
+ {
+ Pos = MAP_APPFONT( 5, 48 );
+ Size = MAP_APPFONT( 300, 12 );
+ Text[ en-US ] = "Enter a value!";
+ };
Edit ED_COL_SCALE_MIN
{
Pos = MAP_APPFONT( 5, 48 );
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 94be7b833407..616342b0a60f 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -2081,6 +2081,14 @@ Resource RID_GLOBSTR
{
Text [ en-US ] = "Convert Formula To Value";
};
+ String STR_UNQUOTED_STRING
+ {
+ Text [ en-US ] = "Strings must be quoted, otherwise they might be interpreted as an address or col/row name!";
+ };
+ String STR_ENTER_VALUE
+ {
+ Text[ en-US ] = "Enter a value!";
+ };
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */