svx: change NamedColor be a struct instead of std::pair

Change-Id: Ice1625e8cae8da859ea8a940b3f8e40f6f9d7037
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152235
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2023-05-25 03:58:52 +02:00
committed by Tomaž Vajngerl
parent 68c4d1ca20
commit 8e87f1f2ff
11 changed files with 52 additions and 38 deletions
@@ -101,7 +101,7 @@ namespace
void lcl_selectColor(ColorListBox& rListBox, const Color& rColor)
{
rListBox.SetNoSelection();
rListBox.SelectEntry(std::make_pair(rColor, lcl_makeColorName(rColor)));
rListBox.SelectEntry({rColor, lcl_makeColorName(rColor)});
}
::chart::LightSource lcl_getLightSourceFromProperties(
+1 -1
View File
@@ -245,7 +245,7 @@ bool SvxHatchTabPage::FillItemSet( SfxItemSet* rSet )
if (m_xCbBackgroundColor->get_active())
{
NamedColor aColor = m_xLbBackgroundColor->GetSelectedEntry();
rSet->Put(XFillColorItem(aColor.second, aColor.first));
rSet->Put(XFillColorItem(aColor.m_aName, aColor.m_aColor));
}
return true;
}
+2 -2
View File
@@ -457,7 +457,7 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
if (m_xLbColor->IsValueChangedFromSaved())
{
NamedColor aColor = m_xLbColor->GetSelectedEntry();
XLineColorItem aItem(aColor.second, aColor.first);
XLineColorItem aItem(aColor.m_aName, aColor.m_aColor);
pOld = GetOldItem( *rAttrs, XATTR_LINECOLOR );
if ( !pOld || !( *static_cast<const XLineColorItem*>(pOld) == aItem ) )
{
@@ -759,7 +759,7 @@ void SvxLineTabPage::FillXLSet_Impl()
m_rXLSet.Put( XLineWidthItem( GetCoreValue( *m_xMtrLineWidth, m_ePoolUnit ) ) );
NamedColor aColor = m_xLbColor->GetSelectedEntry();
m_rXLSet.Put(XLineColorItem(aColor.second, aColor.first));
m_rXLSet.Put(XLineColorItem(aColor.m_aName, aColor.m_aColor));
// Centered line end
if( m_xTsbCenterStart->get_state() == TRISTATE_TRUE )
+13 -1
View File
@@ -29,10 +29,22 @@
class SvxColorValueSet;
typedef std::pair<Color, OUString> NamedColor;
struct SVXCORE_DLLPUBLIC NamedColor
{
Color m_aColor;
OUString m_aName;
NamedColor() = default;
NamedColor(Color const& rColor, OUString const& rName)
: m_aColor(rColor)
, m_aName(rName)
{}
};
namespace svx
{
/// A color with an optional name and other theming-related properties.
struct SVXCORE_DLLPUBLIC NamedThemedColor
{
+1 -1
View File
@@ -200,7 +200,7 @@ IMPL_LINK(Condition, OnConditionAction, weld::Button&, rClickedButton, void)
void Condition::ApplyCommand( sal_uInt16 _nCommandId, const NamedColor& rNamedColor )
{
m_rAction.applyCommand( m_nCondIndex, _nCommandId, rNamedColor.first );
m_rAction.applyCommand(m_nCondIndex, _nCommandId, rNamedColor.m_aColor);
}
IMPL_LINK_NOARG( Condition, OnTypeSelected, weld::ComboBox&, void )
+2 -2
View File
@@ -193,9 +193,9 @@ void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );
NamedColor aColor = m_xLbStartColor->GetSelectedEntry();
rOutAttrs.Put(XColorItem(ATTR_COPY_START_COLOR, aColor.second, aColor.first));
rOutAttrs.Put(XColorItem(ATTR_COPY_START_COLOR, aColor.m_aName, aColor.m_aColor));
aColor = m_xLbEndColor->GetSelectedEntry();
rOutAttrs.Put(XColorItem(ATTR_COPY_END_COLOR, aColor.second, aColor.first));
rOutAttrs.Put(XColorItem(ATTR_COPY_END_COLOR, aColor.m_aName, aColor.m_aColor));
}
/**
+1 -1
View File
@@ -2736,7 +2736,7 @@ namespace
void Svx3DWin::LBSelectColor( ColorListBox* pLb, const Color& rColor )
{
pLb->SetNoSelection();
pLb->SelectEntry(std::make_pair(rColor, lcl_makeColorName(rColor)));
pLb->SelectEntry({rColor, lcl_makeColorName(rColor)});
}
void Svx3DWin::UpdatePreview()
+4 -4
View File
@@ -45,7 +45,7 @@ void PaletteASE::LoadColorSet(SvxColorValueSet& rColorSet)
int nIx = 1;
for (const auto& rColor : maColors)
{
rColorSet.InsertItem(nIx, rColor.first, rColor.second);
rColorSet.InsertItem(nIx, rColor.m_aColor, rColor.m_aName);
++nIx;
}
}
@@ -211,7 +211,7 @@ void PaletteGPL::LoadColorSet(SvxColorValueSet& rColorSet)
int nIx = 1;
for (const auto& rColor : maColors)
{
rColorSet.InsertItem(nIx, rColor.first, rColor.second);
rColorSet.InsertItem(nIx, rColor.m_aColor, rColor.m_aName);
++nIx;
}
}
@@ -384,8 +384,8 @@ NamedColor NamedThemedColor::ToNamedColor() const { return { m_aColor, m_aName }
NamedThemedColor NamedThemedColor::FromNamedColor(const NamedColor& rNamedColor)
{
NamedThemedColor aColor;
aColor.m_aColor = rNamedColor.first;
aColor.m_aName = rNamedColor.second;
aColor.m_aColor = rNamedColor.m_aColor;
aColor.m_aName = rNamedColor.m_aName;
return aColor;
}
}
+7 -7
View File
@@ -52,11 +52,11 @@ namespace
{
// Luminance modulation for the 6 effect presets.
// 10000 is the default.
sal_Int16 g_aLumMods[] = { 10000, 2000, 4000, 6000, 7500, 5000 };
constexpr const std::array<sal_Int16, 6> g_aLumMods = { 10000, 2000, 4000, 6000, 7500, 5000 };
// Luminance offset for the 6 effect presets.
// 0 is the default.
sal_Int16 g_aLumOffs[] = { 0, 8000, 6000, 4000, 0, 0 };
constexpr const std::array<sal_Int16, 6> g_aLumOffs = { 0, 8000, 6000, 4000, 0, 0 };
}
PaletteManager::PaletteManager() :
@@ -365,7 +365,7 @@ void PaletteManager::AddRecentColor(const Color& rRecentColor, const OUString& r
{
auto itColor = std::find_if(maRecentColors.begin(),
maRecentColors.end(),
[rRecentColor] (const NamedColor &a) { return a.first == rRecentColor; });
[rRecentColor] (const NamedColor &aColor) { return aColor.m_aColor == rRecentColor; });
// if recent color to be added is already in list, remove it
if( itColor != maRecentColors.end() )
maRecentColors.erase( itColor );
@@ -373,7 +373,7 @@ void PaletteManager::AddRecentColor(const Color& rRecentColor, const OUString& r
if (maRecentColors.size() == mnMaxRecentColors)
maRecentColors.pop_back();
if (bFront)
maRecentColors.push_front(std::make_pair(rRecentColor, rName));
maRecentColors.emplace_front(rRecentColor, rName);
else
maRecentColors.emplace_back(rRecentColor, rName);
css::uno::Sequence< sal_Int32 > aColorList(maRecentColors.size());
@@ -382,8 +382,8 @@ void PaletteManager::AddRecentColor(const Color& rRecentColor, const OUString& r
auto aColorNameListRange = asNonConstRange(aColorNameList);
for (size_t i = 0; i < maRecentColors.size(); ++i)
{
aColorListRange[i] = static_cast<sal_Int32>(maRecentColors[i].first);
aColorNameListRange[i] = maRecentColors[i].second;
aColorListRange[i] = static_cast<sal_Int32>(maRecentColors[i].m_aColor);
aColorNameListRange[i] = maRecentColors[i].m_aName;
}
std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
officecfg::Office::Common::UserColors::RecentColor::set(aColorList, batch);
@@ -413,7 +413,7 @@ void PaletteManager::PopupColorPicker(weld::Window* pParent, const OUString& aCo
{
Color aLastColor = m_pColorDlg->GetColor();
OUString sColorName = "#" + aLastColor.AsRGBHexString().toAsciiUpperCase();
NamedColor aNamedColor = std::make_pair(aLastColor, sColorName);
NamedColor aNamedColor(aLastColor, sColorName);
if (mpBtnUpdater)
mpBtnUpdater->Update(aNamedColor);
AddRecentColor(aLastColor, sColorName);
+18 -16
View File
@@ -2153,7 +2153,7 @@ NamedColor ColorWindow::GetSelectEntryColor(ValueSet const * pColorSet)
{
Color aColor = pColorSet->GetItemColor(pColorSet->GetSelectedItemId());
OUString sColorName = pColorSet->GetItemText(pColorSet->GetSelectedItemId());
return std::make_pair(aColor, sColorName);
return { aColor, sColorName };
}
namespace
@@ -2192,13 +2192,15 @@ namespace
break;
}
return std::make_pair(aColor, sColorName);
return {aColor, sColorName};
}
NamedColor GetNoneColor()
{
return std::make_pair(COL_NONE_COLOR, comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE)
: SvxResId(RID_SVXSTR_NONE));
OUString aName = comphelper::LibreOfficeKit::isActive()
? SvxResId(RID_SVXSTR_INVISIBLE)
: SvxResId(RID_SVXSTR_NONE);
return { COL_NONE_COLOR, aName };
}
}
@@ -2219,7 +2221,7 @@ IMPL_LINK(ColorWindow, SelectHdl, ValueSet*, pColorSet, void)
if (pColorSet != mxRecentColorSet.get())
{
mxPaletteManager->AddRecentColor(aNamedColor.first, aNamedColor.second);
mxPaletteManager->AddRecentColor(aNamedColor.m_aColor, aNamedColor.m_aName);
if (!maMenuButton.get_active())
mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
}
@@ -2282,7 +2284,7 @@ IMPL_LINK(ColorWindow, AutoColorClickHdl, weld::Button&, rButton, void)
IMPL_LINK_NOARG(ColorWindow, OpenPickerClickHdl, weld::Button&, void)
{
// copy before set_inactive
auto nColor = GetSelectEntryColor().first;
auto nColor = GetSelectEntryColor().m_aColor;
auto pParentWindow = maTopLevelParentFunction();
OUString sCommand = maCommand;
std::shared_ptr<PaletteManager> xPaletteManager(mxPaletteManager);
@@ -2342,7 +2344,7 @@ void ColorWindow::SelectEntry(const NamedColor& rNamedColor)
{
SetNoSelection();
const Color &rColor = rNamedColor.first;
const Color &rColor = rNamedColor.m_aColor;
if (mxButtonAutoColor->get_visible() && (rColor == COL_TRANSPARENT || rColor == COL_AUTO))
{
@@ -2366,7 +2368,7 @@ void ColorWindow::SelectEntry(const NamedColor& rNamedColor)
// whole recently used
if (!bFoundColor)
{
const OUString& rColorName = rNamedColor.second;
const OUString& rColorName = rNamedColor.m_aName;
mxPaletteManager->AddRecentColor(rColor, rColorName, false);
mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
SelectValueSetEntry(mxRecentColorSet.get(), rColor);
@@ -2376,7 +2378,7 @@ void ColorWindow::SelectEntry(const NamedColor& rNamedColor)
void ColorWindow::SelectEntry(const Color& rColor)
{
OUString sColorName = "#" + rColor.AsRGBHexString().toAsciiUpperCase();
ColorWindow::SelectEntry(std::make_pair(rColor, sColorName));
ColorWindow::SelectEntry({rColor, sColorName});
}
ColorStatus::ColorStatus() :
@@ -4358,9 +4360,9 @@ void ColorListBox::createColorWindow()
void ColorListBox::SelectEntry(const NamedColor& rColor)
{
if (o3tl::trim(rColor.second).empty())
if (o3tl::trim(rColor.m_aName).empty())
{
SelectEntry(rColor.first);
SelectEntry(rColor.m_aColor);
return;
}
ColorWindow* pColorWindow = getColorWindow();
@@ -4400,7 +4402,7 @@ int ColorListBox::CalcBestWidthRequest()
if (nColorTextWidth > nMaxStandardColorTextWidth)
{
nMaxStandardColorTextWidth = nColorTextWidth;
aLongestColor.second = rEntry.GetName();
aLongestColor.m_aName = rEntry.GetName();
}
}
ShowPreview(aLongestColor);
@@ -4421,7 +4423,7 @@ void ColorListBox::ShowPreview(const NamedColor &rColor)
ScopedVclPtrInstance<VirtualDevice> xDevice;
xDevice->SetOutputSize(aImageSize);
const tools::Rectangle aRect(Point(0, 0), aImageSize);
if (m_bShowNoneButton && rColor.first == COL_NONE_COLOR)
if (m_bShowNoneButton && rColor.m_aColor == COL_NONE_COLOR)
{
const Color aW(COL_WHITE);
const Color aG(0xef, 0xef, 0xef);
@@ -4432,17 +4434,17 @@ void ColorListBox::ShowPreview(const NamedColor &rColor)
}
else
{
if (rColor.first == COL_AUTO)
if (rColor.m_aColor == COL_AUTO)
xDevice->SetFillColor(m_aAutoDisplayColor);
else
xDevice->SetFillColor(rColor.first);
xDevice->SetFillColor(rColor.m_aColor);
}
xDevice->SetLineColor(rStyleSettings.GetDisableColor());
xDevice->DrawRect(aRect);
m_xButton->set_image(xDevice.get());
m_xButton->set_label(rColor.second);
m_xButton->set_label(rColor.m_aName);
}
MenuOrToolMenuButton::MenuOrToolMenuButton(weld::MenuButton* pMenuButton)
+2 -2
View File
@@ -137,11 +137,11 @@ namespace svx
void ToolboxButtonColorUpdaterBase::Update(const NamedColor &rNamedColor)
{
Update(rNamedColor.first);
Update(rNamedColor.m_aColor);
if (!mbWideButton)
{
// Also show the current color as QuickHelpText
OUString colorSuffix = OUString(" (%1)").replaceFirst("%1", rNamedColor.second);
OUString colorSuffix = OUString(" (%1)").replaceFirst("%1", rNamedColor.m_aName);
OUString colorHelpText = maCommandLabel + colorSuffix;
SetQuickHelpText(colorHelpText);