diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-10-05 10:32:10 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-10-05 10:32:10 -0400 |
commit | 35c75a3c2f07c9662893af50789fd21586ccc88c (patch) | |
tree | 71aa09abceca6e8326884a0c70c73e9a859b3b8d /sc | |
parent | 52dc6590c55a2edd17afd252789cc5606a594c4f (diff) |
Ported calc-formula-variable-sep-config-check-sc.diff from ooo-build.
This code handles situations where the formula arg separator is in
conflict with the locale specific decimal and/or thousand separators.
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/docoptio.hxx | 3 | ||||
-rw-r--r-- | sc/inc/globstr.hrc | 4 | ||||
-rw-r--r-- | sc/source/core/tool/docoptio.cxx | 97 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh6.cxx | 71 | ||||
-rw-r--r-- | sc/source/ui/docshell/makefile.mk | 1 | ||||
-rw-r--r-- | sc/source/ui/inc/docsh.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/src/globstr.src | 4 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 1 |
8 files changed, 132 insertions, 51 deletions
diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx index d9efdf01d0e5..3e751e598af6 100644 --- a/sc/inc/docoptio.hxx +++ b/sc/inc/docoptio.hxx @@ -117,7 +117,8 @@ public: void SetFormulaSepArrayCol(const ::rtl::OUString& rSep) { aFormulaSepArrayCol = rSep; } ::rtl::OUString GetFormulaSepArrayCol() const { return aFormulaSepArrayCol; } - const LocaleDataWrapper& GetLocaleDataWrapper() const; + void ResetFormulaSeparators(); + static const LocaleDataWrapper& GetLocaleDataWrapper(); }; diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc index 4639c028a464..bc3094424d69 100644 --- a/sc/inc/globstr.hrc +++ b/sc/inc/globstr.hrc @@ -578,7 +578,9 @@ #define STR_UNDO_INSERT_CURRENT_DATE 440 #define STR_UNDO_INSERT_CURRENT_TIME 441 -#define STR_COUNT 442 +#define STR_OPTIONS_WARN_SEPARATORS 442 + +#define STR_COUNT 443 #endif diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx index 71c6c4ec6dfe..4f8b9a0df406 100644 --- a/sc/source/core/tool/docoptio.cxx +++ b/sc/source/core/tool/docoptio.cxx @@ -137,63 +137,62 @@ void ScDocOptions::ResetDocOptions() bFormulaRegexEnabled= TRUE; eFormulaGrammar = ::formula::FormulaGrammar::GRAM_NATIVE; - do - { - const Locale& rLocale = *ScGlobal::GetLocale(); - const OUString& rLang = rLocale.Language; - if (rLang.equalsAscii("ru")) - // Don't do automatic guess for these languages, and fall back to - // the old separator set. - break; - - const LocaleDataWrapper& rLocaleData = GetLocaleDataWrapper(); - const OUString& rDecSep = rLocaleData.getNumDecimalSep(); - const OUString& rListSep = rLocaleData.getListSep(); - - if (!rDecSep.getLength() || !rListSep.getLength()) - // Something is wrong. Stick with the default separators. - break; - - sal_Unicode cDecSep = rDecSep.getStr()[0]; - sal_Unicode cListSep = rListSep.getStr()[0]; - - // Excel by default uses system's list separator as the parameter - // separator, which in English locales is a comma. However, OOo's list - // separator value is set to ';' for all English locales. Because of this - // discrepancy, we will hardcode the separator value here, for now. - if (cDecSep == sal_Unicode('.')) - cListSep = sal_Unicode(','); - - // Special case for de_CH locale. - if (rLocale.Language.equalsAsciiL("de", 2) && rLocale.Country.equalsAsciiL("CH", 2)) - cListSep = sal_Unicode(';'); + ResetFormulaSeparators(); +} - // by default, the parameter separator equals the locale-specific - // list separator. - aFormulaSepArg = OUString(cListSep); +void ScDocOptions::ResetFormulaSeparators() +{ + // Defaults to the old separator values. + aFormulaSepArg = OUString::createFromAscii(";"); + aFormulaSepArrayCol = OUString::createFromAscii(";"); + aFormulaSepArrayRow = OUString::createFromAscii("|"); - if (cDecSep == cListSep && cDecSep != sal_Unicode(';')) - // if the decimal and list separators are equal, set the - // parameter separator to be ';', unless they are both - // semicolon in which case don't change the decimal separator. - aFormulaSepArg = OUString::createFromAscii(";"); + const Locale& rLocale = *ScGlobal::GetLocale(); + const OUString& rLang = rLocale.Language; + if (rLang.equalsAscii("ru")) + // Don't do automatic guess for these languages, and fall back to + // the old separator set. + return; - aFormulaSepArrayCol = OUString::createFromAscii(","); - if (cDecSep == sal_Unicode(',')) - aFormulaSepArrayCol = OUString::createFromAscii("."); - aFormulaSepArrayRow = OUString::createFromAscii(";"); + const LocaleDataWrapper& rLocaleData = GetLocaleDataWrapper(); + const OUString& rDecSep = rLocaleData.getNumDecimalSep(); + const OUString& rListSep = rLocaleData.getListSep(); + if (!rDecSep.getLength() || !rListSep.getLength()) + // Something is wrong. Stick with the default separators. return; - } - while (false); - // Defaults to the old separator values. - aFormulaSepArg = OUString::createFromAscii(";"); - aFormulaSepArrayCol = OUString::createFromAscii(";"); - aFormulaSepArrayRow = OUString::createFromAscii("|"); + sal_Unicode cDecSep = rDecSep.getStr()[0]; + sal_Unicode cListSep = rListSep.getStr()[0]; + + // Excel by default uses system's list separator as the parameter + // separator, which in English locales is a comma. However, OOo's list + // separator value is set to ';' for all English locales. Because of this + // discrepancy, we will hardcode the separator value here, for now. + if (cDecSep == sal_Unicode('.')) + cListSep = sal_Unicode(','); + + // Special case for de_CH locale. + if (rLocale.Language.equalsAsciiL("de", 2) && rLocale.Country.equalsAsciiL("CH", 2)) + cListSep = sal_Unicode(';'); + + // by default, the parameter separator equals the locale-specific + // list separator. + aFormulaSepArg = OUString(cListSep); + + if (cDecSep == cListSep && cDecSep != sal_Unicode(';')) + // if the decimal and list separators are equal, set the + // parameter separator to be ';', unless they are both + // semicolon in which case don't change the decimal separator. + aFormulaSepArg = OUString::createFromAscii(";"); + + aFormulaSepArrayCol = OUString::createFromAscii(","); + if (cDecSep == sal_Unicode(',')) + aFormulaSepArrayCol = OUString::createFromAscii("."); + aFormulaSepArrayRow = OUString::createFromAscii(";"); } -const LocaleDataWrapper& ScDocOptions::GetLocaleDataWrapper() const +const LocaleDataWrapper& ScDocOptions::GetLocaleDataWrapper() { return *ScGlobal::pLocaleData; } diff --git a/sc/source/ui/docshell/docsh6.cxx b/sc/source/ui/docshell/docsh6.cxx index 93ac54726781..332811365814 100644 --- a/sc/source/ui/docshell/docsh6.cxx +++ b/sc/source/ui/docshell/docsh6.cxx @@ -51,6 +51,31 @@ #include "tabvwsh.hxx" #include "tablink.hxx" #include "collect.hxx" +#include "docoptio.hxx" +#include "globstr.hrc" +#include "scmod.hxx" + +#include "formula/FormulaCompiler.hxx" +#include "comphelper/processfactory.hxx" +#include "vcl/msgbox.hxx" + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> + +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::container::XNameAccess; +using ::com::sun::star::util::XChangesBatch; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::rtl::OUString; + +namespace { struct ScStylePair { @@ -58,6 +83,12 @@ struct ScStylePair SfxStyleSheetBase *pDest; }; +inline OUString C2U(const char* s) +{ + return OUString::createFromAscii(s); +} + +} // STATIC DATA ----------------------------------------------------------- @@ -457,4 +488,44 @@ BOOL ScDocShell::ReloadTabLinks() return TRUE; //! Fehler erkennen } +void ScDocShell::CheckConfigOptions() +{ + if (IsConfigOptionsChecked()) + // no need to check repeatedly. + return; + + OUString aDecSep = ScGlobal::GetpLocaleData()->getNumDecimalSep(); + + ScModule* pScMod = SC_MOD(); + const ScDocOptions& rOpt = pScMod->GetDocOptions(); + OUString aSepArg = rOpt.GetFormulaSepArg(); + OUString aSepArrRow = rOpt.GetFormulaSepArrayRow(); + OUString aSepArrCol = rOpt.GetFormulaSepArrayCol(); + + if (aDecSep == aSepArg || aDecSep == aSepArrRow || aDecSep == aSepArrCol) + { + // One of arg separators conflicts with the current decimal + // separator. Reset them to default. + ScDocOptions aNew = rOpt; + aNew.ResetFormulaSeparators(); + aDocument.SetDocOptions(aNew); + pScMod->SetDocOptions(aNew); + + // Launch a nice warning dialog to let the users know of this change. + ScTabViewShell* pViewShell = GetBestViewShell(); + if (pViewShell) + { + Window* pParent = pViewShell->GetFrameWin(); + InfoBox aBox(pParent, ScGlobal::GetRscString(STR_OPTIONS_WARN_SEPARATORS)); + aBox.Execute(); + } + + // For now, this is the only option setting that could launch info + // dialog. But in the future we may want to implement a nicer + // dialog to display a list of warnings in case we have several + // pieces of information to display. + } + + SetConfigOptionsChecked(true); +} diff --git a/sc/source/ui/docshell/makefile.mk b/sc/source/ui/docshell/makefile.mk index 99a7495b6b49..dcfd0429bd50 100644 --- a/sc/source/ui/docshell/makefile.mk +++ b/sc/source/ui/docshell/makefile.mk @@ -98,6 +98,7 @@ EXCEPTIONSFILES= \ $(SLO)$/docsh.obj \ $(SLO)$/docsh3.obj \ $(SLO)$/docsh4.obj \ + $(SLO)$/docsh6.obj \ $(SLO)$/docsh8.obj \ $(SLO)$/externalrefmgr.obj \ $(SLO)$/dbdocimp.obj \ diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index bae92e1c0cad..5c3d33ccb374 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -323,6 +323,8 @@ public: void UpdateLinks(); // Link-Eintraege aktuallisieren BOOL ReloadTabLinks(); // Links ausfuehren (Inhalt aktualisieren) + virtual void CheckConfigOptions(); + void PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos ); void PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src index 2fd50d5f97f3..6f0b1f1fd789 100644 --- a/sc/source/ui/src/globstr.src +++ b/sc/source/ui/src/globstr.src @@ -1738,6 +1738,10 @@ Resource RID_GLOBSTR { Text [ en-US ] = "DataPilot table needs at least two rows of data to create or refresh." ; }; + String STR_OPTIONS_WARN_SEPARATORS + { + Text [ en-US ] = "Because the current formula separator settings conflict with the locale, the formula separators have been reset to their default values."; + }; String STR_UNDO_INSERT_CURRENT_DATE { Text [ en-US ] = "Insert Current Date"; diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 6c4f557a4453..67ea292086ed 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -4592,6 +4592,7 @@ void __EXPORT ScGridWindow::GetFocus() // auf dem Mac } + pViewData->GetDocShell()->CheckConfigOptions(); Window::GetFocus(); } |