From cd56935a177b7d9fd10434afe220fe6c10820f82 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 6 Nov 2014 20:02:22 +0200 Subject: More work on OpenCL whitelist/blacklist UI Change-Id: I526d6652a956be3031ed46ab15eeb333d3f40a7c --- .../registry/schema/org/openoffice/Office/Calc.xcs | 2 +- sc/inc/calcconfig.hxx | 55 ++++++++++++++- sc/source/core/tool/calcconfig.cxx | 20 ++++-- sc/source/core/tool/formulaopt.cxx | 62 ++++++++++++++--- sc/source/ui/optdlg/calcoptionsdlg.cxx | 80 ++++++++++++++++++---- sc/source/ui/optdlg/calcoptionsdlg.hxx | 11 ++- sc/uiconfig/scalc/ui/formulacalculationoptions.ui | 22 ++---- 7 files changed, 199 insertions(+), 53 deletions(-) diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs index 46edbf2171a8..d3c20cf3706e 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs @@ -1401,7 +1401,7 @@ Like OpenCLWhiteList, but for combinations known to be bad. - Windows/*/Intel(R) Corporation/9.17.10.2884;SuperOS/1.0/Big Corp, Inc./2.3\/beta + Windows/*/Intel(R) Corporation/*/9.17.10.2884;SuperOS/*/Big Corp, Inc./Whizz\Grafix/4.2%2Fbeta%3B3 diff --git a/sc/inc/calcconfig.hxx b/sc/inc/calcconfig.hxx index eaaeb3f0f4d1..e051e1db2b38 100644 --- a/sc/inc/calcconfig.hxx +++ b/sc/inc/calcconfig.hxx @@ -41,6 +41,57 @@ struct SC_DLLPUBLIC ScCalcConfig STRING_CONVERSION_LOCALE_DEPENDENT ///< =1+"1.000" may be 2 or 1001 ... =1+"x" gives #VALUE! }; + struct OpenCLImplementationMatcher + { + OUString maOS; + OUString maOSVersion; + OUString maPlatformVendor; + OUString maDevice; + OUString maDriverVersion; + + OpenCLImplementationMatcher() + { + } + + OpenCLImplementationMatcher(const OUString& rOS, + const OUString& rOSVersion, + const OUString& rPlatformVendor, + const OUString& rDevice, + const OUString& rDriverVersion) + : maOS(rOS), + maOSVersion(rOSVersion), + maPlatformVendor(rPlatformVendor), + maDevice(rDevice), + maDriverVersion(rDriverVersion) + { + } + + bool operator==(const OpenCLImplementationMatcher& r) const + { + return maOS == r.maOS && + maOSVersion == r.maOSVersion && + maPlatformVendor == r.maPlatformVendor && + maDevice == r.maDevice && + maDriverVersion == r.maDriverVersion; + } + bool operator!=(const OpenCLImplementationMatcher& r) const + { + return !operator==(r); + } + bool operator<(const OpenCLImplementationMatcher& r) const + { + return (maOS < r.maOS || + (maOS == r.maOS && + (maOSVersion < r.maOSVersion || + (maOSVersion == r.maOSVersion && + (maPlatformVendor < r.maPlatformVendor || + (maPlatformVendor == r.maPlatformVendor && + (maDevice < r.maDevice || + (maDevice == r.maDevice && + (maDriverVersion < r.maDriverVersion))))))))); + } + }; + formula::FormulaGrammar::AddressConvention meStringRefAddressSyntax; StringConversion meStringConversion; bool mbEmptyStringAsZero:1; @@ -52,8 +103,8 @@ struct SC_DLLPUBLIC ScCalcConfig sal_Int32 mnOpenCLMinimumFormulaGroupSize; std::set maOpenCLSubsetOpCodes; - std::set maOpenCLWhiteList; - std::set maOpenCLBlackList; + std::set maOpenCLWhiteList; + std::set maOpenCLBlackList; ScCalcConfig(); diff --git a/sc/source/core/tool/calcconfig.cxx b/sc/source/core/tool/calcconfig.cxx index a56d2fa06d7a..8b7e58afd10d 100644 --- a/sc/source/core/tool/calcconfig.cxx +++ b/sc/source/core/tool/calcconfig.cxx @@ -26,6 +26,8 @@ ScCalcConfig::ScCalcConfig() : mbEmptyStringAsZero(false) { setOpenCLConfigToDefault(); + + // SAL _DEBUG(__FILE__ ":" << __LINE__ << ": ScCalcConfig::ScCalcConfig(): " << *this); } void ScCalcConfig::setOpenCLConfigToDefault() @@ -42,8 +44,8 @@ void ScCalcConfig::setOpenCLConfigToDefault() maOpenCLSubsetOpCodes.insert(ocSum); maOpenCLSubsetOpCodes.insert(ocAverage); maOpenCLSubsetOpCodes.insert(ocSumIfs); - maOpenCLBlackList.insert("Windows/*/Intel(R) Corporation/9.17.10.2884"); - maOpenCLBlackList.insert("SuperOS/1.0/Big Corp, Inc./2.3\\/beta"); + maOpenCLBlackList.insert(OpenCLImplementationMatcher("Windows", "*", "Intel(R) Corporation", "*", "9.17.10.2884")); + maOpenCLBlackList.insert(OpenCLImplementationMatcher("SuperOS", "*", "Big Corp, Inc.", "Whizz\\Grafix", "4.2/beta;3")); } void ScCalcConfig::reset() @@ -82,13 +84,19 @@ bool ScCalcConfig::operator!= (const ScCalcConfig& r) const namespace { -void writeStringSet(std::ostream& rStream, const std::set& rSet) +void writeOpenCLImplementationMatcher(std::ostream& rStream, const std::set& rSet) { for (auto i = rSet.cbegin(); i != rSet.cend(); ++i) { if (i != rSet.cbegin()) rStream << ","; - rStream << (*i).replaceAll(",", "\\,"); + rStream << "{" + "OS=" << (*i).maOS << "," + "OSVersion=" << (*i).maOSVersion << "," + "PlatformVendor=" << (*i).maPlatformVendor << "," + "Device=" << (*i).maDevice << "," + "DriverVersion=" << (*i).maDriverVersion << + "}"; } } @@ -107,10 +115,10 @@ std::ostream& operator<<(std::ostream& rStream, const ScCalcConfig& rConfig) "OpenCLMinimumFormulaGroupSize=" << rConfig.mnOpenCLMinimumFormulaGroupSize << "," "OpenCLSubsetOpCodes={" << ScOpCodeSetToSymbolicString(rConfig.maOpenCLSubsetOpCodes) << "}," "OpenCLWhiteList={"; - writeStringSet(rStream, rConfig.maOpenCLWhiteList); + writeOpenCLImplementationMatcher(rStream, rConfig.maOpenCLWhiteList); rStream << "}," "OpenCLBlackList={"; - writeStringSet(rStream, rConfig.maOpenCLBlackList); + writeOpenCLImplementationMatcher(rStream, rConfig.maOpenCLBlackList); rStream << "}" "}"; return rStream; diff --git a/sc/source/core/tool/formulaopt.cxx b/sc/source/core/tool/formulaopt.cxx index aa2b7a181d37..9661b49dd45a 100644 --- a/sc/source/core/tool/formulaopt.cxx +++ b/sc/source/core/tool/formulaopt.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + #include #include #include @@ -278,26 +280,64 @@ ScFormulaCfg::ScFormulaCfg() : namespace { -css::uno::Sequence StringSetToStringSequence(std::set& rSet) +css::uno::Sequence SetOfOpenCLImplementationMatcherToStringSequence(std::set& rSet) { css::uno::Sequence result(rSet.size()); size_t n(0); for (auto i = rSet.cbegin(); i != rSet.cend(); ++i) { - result[n++] = *i; + result[n++] = + (*i).maOS.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" + + (*i).maOSVersion.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" + + (*i).maPlatformVendor.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" + + (*i).maDevice.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B") + "/" + + (*i).maDriverVersion.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll(";", "%3B"); + } + + return result; +} + +OUString getToken(const OUString& string, sal_Int32& index) +{ + OUString token(string.getToken(0, '/', index)); + OUString result; + sal_Int32 i(0); + sal_Int32 p; + while ((p = token.indexOf('%', i)) >= 0) + { + if (p > i) + result += token.copy(i, p - i); + if (p < token.getLength() - 2) + { + result += OUString(static_cast(token.copy(p+1, 2).toInt32(16))); + i = p + 3; + } + else + { + i = token.getLength(); + } } + result += token.copy(i); return result; } -std::set StringSequenceToStringSet(css::uno::Sequence& rSequence) +std::set StringSequenceToSetOfOpenCLImplementationMatcher(css::uno::Sequence& rSequence) { - std::set result; + std::set result; for (auto i = rSequence.begin(); i != rSequence.end(); ++i) { - result.insert(*i); + ScCalcConfig::OpenCLImplementationMatcher m; + sal_Int32 index(0); + m.maOS = getToken(*i, index); + m.maOSVersion = getToken(*i, index); + m.maPlatformVendor = getToken(*i, index); + m.maDevice = getToken(*i, index); + m.maDriverVersion = getToken(*i, index); + + result.insert(m); } return result; @@ -549,16 +589,16 @@ void ScFormulaCfg::UpdateFromProperties( const Sequence& aNames ) break; case SCFORMULAOPT_OPENCL_WHITELIST: { - css::uno::Sequence sVal = StringSetToStringSequence(GetCalcConfig().maOpenCLWhiteList); + css::uno::Sequence sVal = SetOfOpenCLImplementationMatcherToStringSequence(GetCalcConfig().maOpenCLWhiteList); pValues[nProp] >>= sVal; - GetCalcConfig().maOpenCLWhiteList = StringSequenceToStringSet(sVal); + GetCalcConfig().maOpenCLWhiteList = StringSequenceToSetOfOpenCLImplementationMatcher(sVal); } break; case SCFORMULAOPT_OPENCL_BLACKLIST: { - css::uno::Sequence sVal = StringSetToStringSequence(GetCalcConfig().maOpenCLBlackList); + css::uno::Sequence sVal = SetOfOpenCLImplementationMatcherToStringSequence(GetCalcConfig().maOpenCLBlackList); pValues[nProp] >>= sVal; - GetCalcConfig().maOpenCLBlackList = StringSequenceToStringSet(sVal); + GetCalcConfig().maOpenCLBlackList = StringSequenceToSetOfOpenCLImplementationMatcher(sVal); } break; } @@ -716,13 +756,13 @@ void ScFormulaCfg::Commit() break; case SCFORMULAOPT_OPENCL_WHITELIST: { - css::uno::Sequence sVal = StringSetToStringSequence(GetCalcConfig().maOpenCLWhiteList); + css::uno::Sequence sVal = SetOfOpenCLImplementationMatcherToStringSequence(GetCalcConfig().maOpenCLWhiteList); pValues[nProp] <<= sVal; } break; case SCFORMULAOPT_OPENCL_BLACKLIST: { - css::uno::Sequence sVal = StringSetToStringSequence(GetCalcConfig().maOpenCLBlackList); + css::uno::Sequence sVal = SetOfOpenCLImplementationMatcherToStringSequence(GetCalcConfig().maOpenCLBlackList); pValues[nProp] <<= sVal; } break; diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx index 286cc7fffe1f..9551f1684093 100644 --- a/sc/source/ui/optdlg/calcoptionsdlg.cxx +++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx @@ -143,8 +143,13 @@ ScCalcOptionsDialog::ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfi get(mpBtnFalse, "false"); get(mpSpinButton, "spinbutton"); get(mpEditField, "entry"); - get(mpListGrid, "listgrid"); - get(mpListBox, "listbox"); + get(mpOpenCLWhiteAndBlackListGrid, "listgrid"); + get(mpOpenCLWhiteAndBlackListBox, "listbox"); + get(mpOS, "os"); + get(mpOSVersion, "osversion"); + get(mpPlatformVendor, "platformvendor"); + get(mpDevice, "opencldevice"); + get(mpDriverVersion, "opencldriverversion"); get(mpListEditButton, "listbox-edit"); get(mpListNewButton, "listbox-new"); get(mpListDeleteButton, "listbox-delete"); @@ -158,8 +163,8 @@ ScCalcOptionsDialog::ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfi mpSpinButton->SetModifyHdl(LINK(this, ScCalcOptionsDialog, NumModifiedHdl)); mpEditField->SetModifyHdl(LINK(this, ScCalcOptionsDialog, EditModifiedHdl)); - mpListBox->set_height_request(4* mpListBox->GetTextHeight()); - mpListBox->SetStyle(mpListBox->GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE); + mpOpenCLWhiteAndBlackListBox->set_height_request(4* mpOpenCLWhiteAndBlackListBox->GetTextHeight()); + mpOpenCLWhiteAndBlackListBox->SetStyle(mpOpenCLWhiteAndBlackListBox->GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE); mpOpenclInfoList->set_height_request(4* mpOpenclInfoList->GetTextHeight()); mpOpenclInfoList->SetStyle(mpOpenclInfoList->GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE); @@ -211,6 +216,9 @@ ScCalcOptionsDialog::ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfi mpLbSettings->SetSelectHdl(aLink); mpLbOptionEdit->SetSelectHdl(aLink); + aLink = LINK(this, ScCalcOptionsDialog, OpenCLWhiteAndBlackListSelHdl); + mpOpenCLWhiteAndBlackListBox->SetSelectHdl(aLink); + aLink = LINK(this, ScCalcOptionsDialog, BtnToggleHdl); mpBtnTrue->SetToggleHdl(aLink); // Set handler only to the 'True' button. @@ -325,14 +333,19 @@ void ScCalcOptionsDialog::fillOpenCLList() namespace { -void fillListBox(ListBox* pListBox, const std::set& rSet) +void fillListBox(ListBox* pListBox, const std::set& rSet) { pListBox->SetUpdateMode(false); pListBox->Clear(); for (auto i = rSet.cbegin(); i != rSet.cend(); ++i) { - pListBox->InsertEntry(*i, LISTBOX_APPEND); + pListBox->InsertEntry((*i).maOS + " " + + (*i).maOSVersion + " " + + (*i).maPlatformVendor + " " + + (*i).maDevice + " " + + (*i).maDriverVersion, + LISTBOX_APPEND); } pListBox->SetUpdateMode(true); @@ -405,7 +418,7 @@ void ScCalcOptionsDialog::SelectionChanged() mpBtnFalse->Hide(); mpSpinButton->Hide(); mpEditField->Hide(); - mpListGrid->Hide(); + mpOpenCLWhiteAndBlackListGrid->Hide(); mpLbOptionEdit->Show(); mpOpenclInfoList->GetParent()->Hide(); @@ -440,7 +453,7 @@ void ScCalcOptionsDialog::SelectionChanged() mpBtnFalse->Hide(); mpSpinButton->Hide(); mpEditField->Hide(); - mpListGrid->Hide(); + mpOpenCLWhiteAndBlackListGrid->Hide(); mpLbOptionEdit->Show(); mpOpenclInfoList->GetParent()->Hide(); @@ -478,7 +491,7 @@ void ScCalcOptionsDialog::SelectionChanged() mpBtnFalse->Show(); mpSpinButton->Hide(); mpEditField->Hide(); - mpListGrid->Hide(); + mpOpenCLWhiteAndBlackListGrid->Hide(); bool bValue = false; bool bEnable = true; @@ -555,7 +568,7 @@ void ScCalcOptionsDialog::SelectionChanged() mpBtnFalse->Hide(); mpSpinButton->Show(); mpEditField->Hide(); - mpListGrid->Hide(); + mpOpenCLWhiteAndBlackListGrid->Hide(); mpOpenclInfoList->GetParent()->Hide(); mpFtAnnotation->SetText(maDescOpenCLMinimumFormulaSize); mpSpinButton->SetValue(nValue); @@ -572,7 +585,7 @@ void ScCalcOptionsDialog::SelectionChanged() mpBtnFalse->Hide(); mpSpinButton->Hide(); mpEditField->Show(); - mpListGrid->Hide(); + mpOpenCLWhiteAndBlackListGrid->Hide(); mpOpenclInfoList->GetParent()->Hide(); mpFtAnnotation->SetText(maDescOpenCLSubsetOpCodes); mpEditField->SetText(sValue); @@ -583,23 +596,22 @@ void ScCalcOptionsDialog::SelectionChanged() case CALC_OPTION_OPENCL_WHITELIST: case CALC_OPTION_OPENCL_BLACKLIST: { - // SAL _DEBUG(__FILE__ ":" << __LINE__ << ": " << maConfig); mpLbOptionEdit->Hide(); mpBtnTrue->Hide(); mpBtnFalse->Hide(); mpSpinButton->Hide(); mpEditField->Hide(); - mpListGrid->Show(); + mpOpenCLWhiteAndBlackListGrid->Show(); mpOpenclInfoList->GetParent()->Hide(); if ( nSelectedPos == CALC_OPTION_OPENCL_WHITELIST ) { mpFtAnnotation->SetText(maDescOpenCLWhiteList); - fillListBox(mpListBox, maConfig.maOpenCLWhiteList); + fillListBox(mpOpenCLWhiteAndBlackListBox, maConfig.maOpenCLWhiteList); } else { mpFtAnnotation->SetText(maDescOpenCLBlackList); - fillListBox(mpListBox, maConfig.maOpenCLBlackList); + fillListBox(mpOpenCLWhiteAndBlackListBox, maConfig.maOpenCLBlackList); } } break; @@ -751,6 +763,10 @@ void ScCalcOptionsDialog::EditFieldValueChanged() maConfig.maOpenCLSubsetOpCodes = ScStringToOpCodeSet(sVal); } +void ScCalcOptionsDialog::WhiteAndBlackListSelectionChanged() +{ +} + OUString ScCalcOptionsDialog::toString(formula::FormulaGrammar::AddressConvention eConv) const { switch (eConv) @@ -834,4 +850,38 @@ IMPL_LINK_NOARG(ScCalcOptionsDialog, EditModifiedHdl) return 0; } +namespace { + +template +typename T::iterator nth(T container, int n) +{ + auto i = container.begin(); + while (n && i != container.end()) + { + ++i; + --n; + } + + return i; +} + +} // anonymous namespace + +IMPL_LINK(ScCalcOptionsDialog, OpenCLWhiteAndBlackListSelHdl, Control*, ) +{ + // We know this is called for the mpOpenCLWhiteAndBlackListBox + + std::set + &m(mpLbSettings->GetSelectEntryPos() == CALC_OPTION_OPENCL_WHITELIST ? maConfig.maOpenCLWhiteList : maConfig.maOpenCLBlackList); + sal_uLong n(mpOpenCLWhiteAndBlackListBox->GetSelectEntryPos()); + + mpOS->SetText(nth(m, n)->maOS); + mpOSVersion->SetText(nth(m, n)->maOSVersion); + mpPlatformVendor->SetText(nth(m, n)->maPlatformVendor); + mpDevice->SetText(nth(m, n)->maDevice); + mpDriverVersion->SetText(nth(m, n)->maDriverVersion); + + return 0; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/optdlg/calcoptionsdlg.hxx b/sc/source/ui/optdlg/calcoptionsdlg.hxx index 860f943ce139..a6ad5cd61835 100644 --- a/sc/source/ui/optdlg/calcoptionsdlg.hxx +++ b/sc/source/ui/optdlg/calcoptionsdlg.hxx @@ -40,6 +40,7 @@ public: DECL_LINK( DeviceSelHdl, void* ); DECL_LINK( NumModifiedHdl, void * ); DECL_LINK( EditModifiedHdl, void * ); + DECL_LINK( OpenCLWhiteAndBlackListSelHdl, Control* ); const ScCalcConfig& GetConfig() const { return maConfig;} @@ -52,6 +53,7 @@ private: void SelectedDeviceChanged(); void SpinButtonValueChanged(); void EditFieldValueChanged(); + void WhiteAndBlackListSelectionChanged(); #if HAVE_FEATURE_OPENCL void fillOpenCLList(); #endif @@ -74,8 +76,13 @@ private: RadioButton* mpBtnFalse; NumericField* mpSpinButton; Edit* mpEditField; - VclGrid* mpListGrid; - ListBox* mpListBox; + VclGrid* mpOpenCLWhiteAndBlackListGrid; + ListBox* mpOpenCLWhiteAndBlackListBox; + Edit* mpOS; + Edit* mpOSVersion; + Edit* mpPlatformVendor; + Edit* mpDevice; + Edit* mpDriverVersion; PushButton* mpListEditButton; PushButton* mpListNewButton; PushButton* mpListDeleteButton; diff --git a/sc/uiconfig/scalc/ui/formulacalculationoptions.ui b/sc/uiconfig/scalc/ui/formulacalculationoptions.ui index 959c2b1a2152..513106c6ae23 100644 --- a/sc/uiconfig/scalc/ui/formulacalculationoptions.ui +++ b/sc/uiconfig/scalc/ui/formulacalculationoptions.ui @@ -224,11 +224,9 @@ - + True True - True - True 0 @@ -250,11 +248,9 @@ - + True True - True - True 0 @@ -262,7 +258,7 @@ - + True False 0 @@ -276,11 +272,9 @@ - + True True - True - True 0 @@ -302,11 +296,9 @@ - + True True - True - True 0 @@ -328,11 +320,9 @@ - + True True - True - True 0 -- cgit