summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-04-28 12:37:19 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2021-04-29 11:38:57 +0200
commitb672adaf5a4604aa09322034e4f5c151a4dc1314 (patch)
tree93fbc9dc344e9f5001250d3e30beb799af79f789
parenttdf#116384 only drag hyperlink if user's not currently setting the selection (diff)
downloadcore-b672adaf5a4604aa09322034e4f5c151a4dc1314.tar.gz
core-b672adaf5a4604aa09322034e4f5c151a4dc1314.zip
tdf#135997: make sure that the two lists are same length
This fixes the strange assumption that when searching the two lists (character names and font names) independently, the two found positions will necessarily correspond to each other. Instead, the positions of the match must be the same, which is implemented now. Also the input from configuration is sanitized. Change-Id: I920de7414387e181e11183b8a22776a72b6be419 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114722 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit b6ab5914d8b2fc7041430796890f086f8e3e6369) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114852 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--cui/source/dialogs/cuicharmap.cxx93
-rw-r--r--include/cui/cuicharmap.hxx17
-rw-r--r--sfx2/source/control/charmapcontrol.cxx13
3 files changed, 85 insertions, 38 deletions
diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx
index d674cda9c48f..ed0200c54cc3 100644
--- a/cui/source/dialogs/cuicharmap.cxx
+++ b/cui/source/dialogs/cuicharmap.cxx
@@ -185,7 +185,7 @@ short SvxCharacterMap::run()
if( SvxShowCharSet::getSelectedChar() == ' ')
{
m_xOKBtn->set_sensitive(false);
- setFavButtonState(OUString(), OUString());
+ setFavButtonState(u"", u"");
}
else
{
@@ -235,6 +235,11 @@ void SvxCharacterMap::getRecentCharacterList()
{
maRecentCharFontList.push_back(s);
}
+
+ // tdf#135997: make sure that the two lists are same length
+ const auto nCommonLength = std::min(maRecentCharList.size(), maRecentCharFontList.size());
+ maRecentCharList.resize(nCommonLength);
+ maRecentCharFontList.resize(nCommonLength);
}
@@ -255,11 +260,46 @@ void SvxCharacterMap::getFavCharacterList()
{
maFavCharFontList.push_back(s);
}
+
+ // tdf#135997: make sure that the two lists are same length
+ const auto nCommonLength = std::min(maFavCharList.size(), maFavCharFontList.size());
+ maFavCharList.resize(nCommonLength);
+ maFavCharFontList.resize(nCommonLength);
+}
+
+static std::pair<std::deque<OUString>::const_iterator, std::deque<OUString>::const_iterator>
+findInPair(std::u16string_view str1, const std::deque<OUString>& rContainer1,
+ std::u16string_view str2, const std::deque<OUString>& rContainer2)
+{
+ assert(rContainer1.size() == rContainer2.size());
+
+ if (auto it1 = std::find(rContainer1.begin(), rContainer1.end(), str1);
+ it1 != rContainer1.end())
+ {
+ auto it2 = rContainer2.begin() + (it1 - rContainer1.begin());
+ if (*it2 == str2)
+ return { it1, it2 };
+ }
+ return { rContainer1.end(), rContainer2.end() };
+}
+
+std::pair<std::deque<OUString>::const_iterator, std::deque<OUString>::const_iterator>
+SvxCharacterMap::getRecentChar(std::u16string_view sTitle, std::u16string_view rFont) const
+{
+ return findInPair(sTitle, maRecentCharList, rFont, maRecentCharFontList);
+}
+
+std::pair<std::deque<OUString>::const_iterator, std::deque<OUString>::const_iterator>
+SvxCharacterMap::getFavChar(std::u16string_view sTitle, std::u16string_view rFont) const
+{
+ return findInPair(sTitle, maFavCharList, rFont, maFavCharFontList);
}
void SvxCharacterMap::updateRecentCharControl()
{
+ assert(maRecentCharList.size() == maRecentCharFontList.size());
+
int i = 0;
for ( std::deque< OUString >::iterator it = maRecentCharList.begin(), it2 = maRecentCharFontList.begin();
it != maRecentCharList.end() && it2 != maRecentCharFontList.end();
@@ -281,12 +321,9 @@ void SvxCharacterMap::updateRecentCharControl()
void SvxCharacterMap::updateRecentCharacterList(const OUString& sTitle, const OUString& rFont)
{
- auto itChar = std::find(maRecentCharList.begin(), maRecentCharList.end(), sTitle);
-
- auto itChar2 = std::find(maRecentCharFontList.begin(), maRecentCharFontList.end(), rFont);
-
// if recent char to be added is already in list, remove it
- if( itChar != maRecentCharList.end() && itChar2 != maRecentCharFontList.end() )
+ if( const auto& [itChar, itChar2] = getRecentChar(sTitle, rFont);
+ itChar != maRecentCharList.end() && itChar2 != maRecentCharFontList.end() )
{
maRecentCharList.erase( itChar );
maRecentCharFontList.erase( itChar2);
@@ -321,12 +358,9 @@ void SvxCharacterMap::updateRecentCharacterList(const OUString& sTitle, const OU
void SvxCharacterMap::updateFavCharacterList(const OUString& sTitle, const OUString& rFont)
{
- auto itChar = std::find(maFavCharList.begin(), maFavCharList.end(), sTitle);
-
- auto itChar2 = std::find(maFavCharFontList.begin(), maFavCharFontList.end(), rFont);
-
// if Fav char to be added is already in list, remove it
- if( itChar != maFavCharList.end() && itChar2 != maFavCharFontList.end() )
+ if( const auto& [itChar, itChar2] = getFavChar(sTitle, rFont);
+ itChar != maFavCharList.end() && itChar2 != maFavCharFontList.end() )
{
maFavCharList.erase( itChar );
maFavCharFontList.erase( itChar2);
@@ -359,6 +393,8 @@ void SvxCharacterMap::updateFavCharacterList(const OUString& sTitle, const OUStr
void SvxCharacterMap::updateFavCharControl()
{
+ assert(maFavCharList.size() == maFavCharFontList.size());
+
int i = 0;
for ( std::deque< OUString >::iterator it = maFavCharList.begin(), it2 = maFavCharFontList.begin();
it != maFavCharList.end() && it2 != maFavCharFontList.end();
@@ -380,14 +416,11 @@ void SvxCharacterMap::updateFavCharControl()
m_xSearchSet->getFavCharacterList();
}
-void SvxCharacterMap::deleteFavCharacterFromList(const OUString& sTitle, const OUString& rFont)
+void SvxCharacterMap::deleteFavCharacterFromList(std::u16string_view sTitle, std::u16string_view rFont)
{
- auto itChar = std::find(maFavCharList.begin(), maFavCharList.end(), sTitle);
-
- auto itChar2 = std::find(maFavCharFontList.begin(), maFavCharFontList.end(), rFont);
-
- // if Fav char to be added is already in list, remove it
- if( itChar != maFavCharList.end() && itChar2 != maFavCharFontList.end() )
+ // if Fav char is found, remove it
+ if( const auto& [itChar, itChar2] = getFavChar(sTitle, rFont);
+ itChar != maFavCharList.end() && itChar2 != maFavCharFontList.end() )
{
maFavCharList.erase( itChar );
maFavCharFontList.erase( itChar2);
@@ -529,24 +562,16 @@ void SvxCharacterMap::init()
m_xSearchText->connect_changed(LINK(this, SvxCharacterMap, SearchUpdateHdl));
}
-bool SvxCharacterMap::isFavChar(const OUString& sTitle, const OUString& rFont)
+bool SvxCharacterMap::isFavChar(std::u16string_view sTitle, std::u16string_view rFont)
{
- auto isFavCharTitleExists = std::any_of(maFavCharList.begin(),
- maFavCharList.end(),
- [sTitle] (const OUString & a) { return a == sTitle; });
-
- auto isFavCharFontExists = std::any_of(maFavCharFontList.begin(),
- maFavCharFontList.end(),
- [rFont] (const OUString & a) { return a == rFont; });
-
- // if Fav char to be added is already in list, remove it
- return isFavCharTitleExists && isFavCharFontExists;
+ const auto& [itChar, itFont] = getFavChar(sTitle, rFont);
+ return itChar != maFavCharList.end() && itFont != maFavCharFontList.end();
}
-void SvxCharacterMap::setFavButtonState(const OUString& sTitle, const OUString& rFont)
+void SvxCharacterMap::setFavButtonState(std::u16string_view sTitle, std::u16string_view rFont)
{
- if(sTitle.isEmpty() || rFont.isEmpty())
+ if(sTitle.empty() || rFont.empty())
{
m_xFavouritesBtn->set_sensitive(false);
return;
@@ -747,13 +772,11 @@ IMPL_LINK_NOARG(SvxCharacterMap, SubsetSelectHdl, weld::ComboBox&, void)
IMPL_LINK(SvxCharacterMap, RecentClearClickHdl, SvxCharView*, rView, void)
{
const OUString& sTitle = rView->GetText();
- auto itChar = std::find(maRecentCharList.begin(), maRecentCharList.end(), sTitle);
-
OUString sFont = rView->GetFont().GetFamilyName();
- auto itChar2 = std::find(maRecentCharFontList.begin(), maRecentCharFontList.end(), sFont);
// if recent char to be added is already in list, remove it
- if( itChar != maRecentCharList.end() && itChar2 != maRecentCharFontList.end() )
+ if( const auto& [itChar, itChar2] = getRecentChar(sTitle, sFont);
+ itChar != maRecentCharList.end() && itChar2 != maRecentCharFontList.end() )
{
maRecentCharList.erase( itChar );
maRecentCharFontList.erase( itChar2);
diff --git a/include/cui/cuicharmap.hxx b/include/cui/cuicharmap.hxx
index 4548f7013e87..11e464912a8d 100644
--- a/include/cui/cuicharmap.hxx
+++ b/include/cui/cuicharmap.hxx
@@ -31,6 +31,10 @@
#include <cui/cuidllapi.h>
#include <com/sun/star/frame/XFrame.hpp>
+#include <deque>
+#include <memory>
+#include <utility>
+
using namespace ::com::sun::star;
class SubsetMap;
@@ -165,18 +169,25 @@ public:
void getFavCharacterList(); //gets both Fav char and Fav char font list
void updateFavCharacterList(const OUString& rChar, const OUString& rFont);
- void deleteFavCharacterFromList(const OUString& rChar, const OUString& rFont);
- bool isFavChar(const OUString& sTitle, const OUString& rFont);
+ void deleteFavCharacterFromList(std::u16string_view rChar, std::u16string_view rFont);
+ bool isFavChar(std::u16string_view sTitle, std::u16string_view rFont);
void updateRecentCharControl();
void insertCharToDoc(const OUString& sChar);
void updateFavCharControl();
- void setFavButtonState(const OUString& sTitle, const OUString& rFont);
+ void setFavButtonState(std::u16string_view sTitle, std::u16string_view rFont);
void setCharName(sal_UCS4 nDecimalValue);
void toggleSearchView(bool state);
+
+private:
+ std::pair<std::deque<OUString>::const_iterator, std::deque<OUString>::const_iterator>
+ getRecentChar(std::u16string_view sTitle, std::u16string_view rFont) const;
+
+ std::pair<std::deque<OUString>::const_iterator, std::deque<OUString>::const_iterator>
+ getFavChar(std::u16string_view sTitle, std::u16string_view rFont) const;
};
#endif
diff --git a/sfx2/source/control/charmapcontrol.cxx b/sfx2/source/control/charmapcontrol.cxx
index ce580f1618b7..c2175718fca8 100644
--- a/sfx2/source/control/charmapcontrol.cxx
+++ b/sfx2/source/control/charmapcontrol.cxx
@@ -122,10 +122,17 @@ void SfxCharmapCtrl::getFavCharacterList()
//retrieve recent character font list
css::uno::Sequence< OUString > rFavCharFontList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterFontList::get() );
m_aFavCharFontList.insert( m_aFavCharFontList.end(), rFavCharFontList.begin(), rFavCharFontList.end() );
+
+ // tdf#135997: make sure that the two lists are same length
+ const auto nCommonLength = std::min(m_aFavCharList.size(), m_aFavCharFontList.size());
+ m_aFavCharList.resize(nCommonLength);
+ m_aFavCharFontList.resize(nCommonLength);
}
void SfxCharmapCtrl::updateFavCharControl()
{
+ assert(m_aFavCharList.size() == m_aFavCharFontList.size());
+
int i = 0;
for ( std::deque< OUString >::iterator it = m_aFavCharList.begin(), it2 = m_aFavCharFontList.begin();
it != m_aFavCharList.end() && it2 != m_aFavCharFontList.end();
@@ -154,10 +161,16 @@ void SfxCharmapCtrl::getRecentCharacterList()
//retrieve recent character font list
css::uno::Sequence< OUString > rRecentCharFontList( officecfg::Office::Common::RecentCharacters::RecentCharacterFontList::get() );
m_aRecentCharFontList.insert( m_aRecentCharFontList.end(), rRecentCharFontList.begin(), rRecentCharFontList.end() );
+
+ // tdf#135997: make sure that the two lists are same length
+ const auto nCommonLength = std::min(m_aRecentCharList.size(), m_aRecentCharFontList.size());
+ m_aRecentCharList.resize(nCommonLength);
+ m_aRecentCharFontList.resize(nCommonLength);
}
void SfxCharmapCtrl::updateRecentCharControl()
{
+ assert(m_aRecentCharList.size() == m_aRecentCharFontList.size());
int i = 0;
for ( std::deque< OUString >::iterator it = m_aRecentCharList.begin(), it2 = m_aRecentCharFontList.begin();
it != m_aRecentCharList.end() && it2 != m_aRecentCharFontList.end();