summaryrefslogtreecommitdiffstats
path: root/cui/source/tabpages/border.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'cui/source/tabpages/border.cxx')
-rw-r--r--cui/source/tabpages/border.cxx132
1 files changed, 86 insertions, 46 deletions
diff --git a/cui/source/tabpages/border.cxx b/cui/source/tabpages/border.cxx
index 725ab44da0ee..ccb94fe46854 100644
--- a/cui/source/tabpages/border.cxx
+++ b/cui/source/tabpages/border.cxx
@@ -78,22 +78,19 @@ const WhichRangesContainer SvxBorderTabPage::pRanges(
namespace
{
-int lcl_twipsToPt(sal_Int64 nTwips)
+constexpr int twipsToPt100(sal_Int64 nTwips)
{
- return vcl::ConvertDoubleValue(nTwips, 0, FieldUnit::TWIP, MapUnit::MapPoint) * 100;
+ return o3tl::convert(nTwips * 100, o3tl::Length::twip, o3tl::Length::pt);
}
+constexpr int s_LineWidths[] = { twipsToPt100(SvxBorderLineWidth::Hairline),
+ twipsToPt100(SvxBorderLineWidth::VeryThin),
+ twipsToPt100(SvxBorderLineWidth::Thin),
+ twipsToPt100(SvxBorderLineWidth::Medium),
+ twipsToPt100(SvxBorderLineWidth::Thick),
+ twipsToPt100(SvxBorderLineWidth::ExtraThick),
+ -1 };
}
-const std::vector<int> SvxBorderTabPage::m_aLineWidths = {
- lcl_twipsToPt(SvxBorderLineWidth::Hairline),
- lcl_twipsToPt(SvxBorderLineWidth::VeryThin),
- lcl_twipsToPt(SvxBorderLineWidth::Thin),
- lcl_twipsToPt(SvxBorderLineWidth::Medium),
- lcl_twipsToPt(SvxBorderLineWidth::Thick),
- lcl_twipsToPt(SvxBorderLineWidth::ExtraThick),
- -1
-};
-
static void lcl_SetDecimalDigitsTo1(weld::MetricSpinButton& rField)
{
auto nMin = rField.denormalize(rField.get_min(FieldUnit::TWIP));
@@ -421,19 +418,16 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, weld::DialogControlle
is needed across various functions... */
mbUseMarginItem = rCoreAttrs.GetItemState(GetWhich(SID_ATTR_ALIGN_MARGIN)) != SfxItemState::UNKNOWN;
- const SfxPoolItem* pItem = nullptr;
- if (rCoreAttrs.HasItem(SID_ATTR_BORDER_STYLES, &pItem))
+ if (const SfxIntegerListItem* p = rCoreAttrs.GetItemIfSet(SID_ATTR_BORDER_STYLES))
{
- const SfxIntegerListItem* p = static_cast<const SfxIntegerListItem*>(pItem);
std::vector<sal_Int32> aUsedStyles = p->GetList();
for (int aUsedStyle : aUsedStyles)
maUsedBorderStyles.insert(static_cast<SvxBorderLineStyle>(aUsedStyle));
}
- if (rCoreAttrs.HasItem(SID_ATTR_BORDER_DEFAULT_WIDTH, &pItem))
+ if (const SfxInt64Item* p = rCoreAttrs.GetItemIfSet(SID_ATTR_BORDER_DEFAULT_WIDTH))
{
// The caller specifies default line width. Honor it.
- const SfxInt64Item* p = static_cast<const SfxInt64Item*>(pItem);
SetLineWidth(p->GetValue());
}
@@ -546,6 +540,7 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, weld::DialogControlle
SetLineWidth(m_xLineWidthMF->get_value(FieldUnit::NONE));
// connections
+ const SfxPoolItem* pItem = nullptr;
if (rCoreAttrs.HasItem(GetWhich(SID_ATTR_PARA_GRABBAG), &pItem))
{
const SfxGrabBagItem* pGrabBag = static_cast<const SfxGrabBagItem*>(pItem);
@@ -576,8 +571,7 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, weld::DialogControlle
// checkbox "Merge adjacent line styles" only visible for Writer dialog format.table
m_xMergeAdjacentBordersCB->hide();
- SfxObjectShell* pDocSh = SfxObjectShell::Current();
- if (pDocSh)
+ if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
{
Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
if ( xSI.is() )
@@ -640,7 +634,7 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
if (m_aFrameSel.IsBorderEnabled(svx::FrameBorderType::TLBR))
{
- sal_uInt16 nBorderDiagId = pPool->GetWhich(SID_ATTR_BORDER_DIAG_TLBR);
+ sal_uInt16 nBorderDiagId = pPool->GetWhichIDFromSlotID(SID_ATTR_BORDER_DIAG_TLBR);
if (const SvxLineItem* pLineItem = static_cast<const SvxLineItem*>(rSet->GetItem(nBorderDiagId)))
m_aFrameSel.ShowBorder(svx::FrameBorderType::TLBR, pLineItem->GetLine());
else
@@ -649,7 +643,7 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
if (m_aFrameSel.IsBorderEnabled(svx::FrameBorderType::BLTR))
{
- sal_uInt16 nBorderDiagId = pPool->GetWhich(SID_ATTR_BORDER_DIAG_BLTR);
+ sal_uInt16 nBorderDiagId = pPool->GetWhichIDFromSlotID(SID_ATTR_BORDER_DIAG_BLTR);
if (const SvxLineItem* pLineItem = static_cast<const SvxLineItem*>(rSet->GetItem(nBorderDiagId)))
m_aFrameSel.ShowBorder(svx::FrameBorderType::BLTR, pLineItem->GetLine());
else
@@ -658,7 +652,7 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
if (m_xShadowControls)
{
- sal_uInt16 nShadowId = pPool->GetWhich(mnShadowSlot);
+ sal_uInt16 nShadowId = pPool->GetWhichIDFromSlotID(mnShadowSlot);
const SfxPoolItem* pItem = rSet->GetItem(nShadowId);
if (pItem)
m_xShadowControls->SetControlValue(*static_cast<const SvxShadowItem*>(pItem));
@@ -668,7 +662,7 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
if (m_xMarginControls)
{
- sal_uInt16 nAlignMarginId = pPool->GetWhich(SID_ATTR_ALIGN_MARGIN);
+ sal_uInt16 nAlignMarginId = pPool->GetWhichIDFromSlotID(SID_ATTR_ALIGN_MARGIN);
const SfxPoolItem* pItem = rSet->GetItem(nAlignMarginId);
if (pItem)
m_xMarginControls->SetControlValue(*static_cast<const SvxMarginItem*>(pItem));
@@ -676,7 +670,7 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
m_xMarginControls->SetControlDontKnow();
}
- sal_uInt16 nMergeAdjacentBordersId = pPool->GetWhich(SID_SW_COLLAPSING_BORDERS);
+ sal_uInt16 nMergeAdjacentBordersId = pPool->GetWhichIDFromSlotID(SID_SW_COLLAPSING_BORDERS);
const SfxBoolItem *pMergeAdjacentBorders = static_cast<const SfxBoolItem*>(rSet->GetItem(nMergeAdjacentBordersId));
if (!pMergeAdjacentBorders)
m_xMergeAdjacentBordersCB->set_state(TRISTATE_INDET);
@@ -684,7 +678,7 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
m_xMergeAdjacentBordersCB->set_active(pMergeAdjacentBorders->GetValue());
m_xMergeAdjacentBordersCB->save_state();
- sal_uInt16 nMergeWithNextId = pPool->GetWhich(SID_ATTR_BORDER_CONNECT);
+ sal_uInt16 nMergeWithNextId = pPool->GetWhichIDFromSlotID(SID_ATTR_BORDER_CONNECT);
const SfxBoolItem *pMergeWithNext = static_cast<const SfxBoolItem*>(rSet->GetItem(nMergeWithNextId));
if (!pMergeWithNext)
m_xMergeWithNextCB->set_state(TRISTATE_INDET);
@@ -845,13 +839,15 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
SelStyleHdl_Impl(*m_xLbLineStyle);
}
- const SfxPoolItem* pItem;
- SfxObjectShell* pShell;
- if(SfxItemState::SET == rSet->GetItemState(SID_HTML_MODE, false, &pItem) ||
- ( nullptr != (pShell = SfxObjectShell::Current()) &&
- nullptr != (pItem = pShell->GetItem(SID_HTML_MODE))))
+ const SfxUInt16Item* pHtmlModeItem = rSet->GetItemIfSet(SID_HTML_MODE, false);
+ if(!pHtmlModeItem)
{
- sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+ if (SfxObjectShell* pShell = SfxObjectShell::Current())
+ pHtmlModeItem = pShell->GetItem(SID_HTML_MODE);
+ }
+ if(pHtmlModeItem)
+ {
+ sal_uInt16 nHtmlMode = pHtmlModeItem->GetValue();
if(nHtmlMode & HTMLMODE_ON)
{
// there are no shadows in Html-mode and only complete borders
@@ -957,7 +953,7 @@ bool SvxBorderTabPage::FillItemSet( SfxItemSet* rCoreAttrs )
auto nState = m_xMergeAdjacentBordersCB->get_state();
if (nState == TRISTATE_INDET)
{
- sal_uInt16 nMergeAdjacentBordersId = pPool->GetWhich(SID_SW_COLLAPSING_BORDERS);
+ sal_uInt16 nMergeAdjacentBordersId = pPool->GetWhichIDFromSlotID(SID_SW_COLLAPSING_BORDERS);
rCoreAttrs->ClearItem(nMergeAdjacentBordersId);
}
else
@@ -977,7 +973,7 @@ bool SvxBorderTabPage::FillItemSet( SfxItemSet* rCoreAttrs )
auto nState = m_xMergeWithNextCB->get_state();
if (nState == TRISTATE_INDET)
{
- sal_uInt16 nMergeWithNextId = pPool->GetWhich(SID_ATTR_BORDER_CONNECT);
+ sal_uInt16 nMergeWithNextId = pPool->GetWhichIDFromSlotID(SID_ATTR_BORDER_CONNECT);
rCoreAttrs->ClearItem(nMergeWithNextId);
}
else
@@ -994,7 +990,7 @@ bool SvxBorderTabPage::FillItemSet( SfxItemSet* rCoreAttrs )
bool bPut = true;
sal_uInt16 nBoxWhich = GetWhich( mnBoxSlot );
- sal_uInt16 nBoxInfoWhich = pPool->GetWhich( SID_ATTR_BORDER_INNER, false );
+ sal_uInt16 nBoxInfoWhich = pPool->GetWhichIDFromSlotID( SID_ATTR_BORDER_INNER, false );
const SfxItemSet& rOldSet = GetItemSet();
SvxBoxItem aBoxItem ( nBoxWhich );
SvxBoxInfoItem aBoxInfoItem ( nBoxInfoWhich );
@@ -1235,15 +1231,19 @@ IMPL_LINK_NOARG(SvxBorderTabPage, SelSdwHdl_Impl, ValueSet*, void)
IMPL_LINK(SvxBorderTabPage, SelColHdl_Impl, ColorListBox&, rColorBox, void)
{
- Color aColor = rColorBox.GetSelectEntryColor();
- m_aFrameSel.SetColorToSelection(aColor);
+ NamedColor aNamedColor = rColorBox.GetSelectedEntry();
+ m_aFrameSel.SetColorToSelection(aNamedColor.m_aColor, aNamedColor.getComplexColor());
}
IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthLBHdl_Impl, weld::ComboBox&, void)
{
sal_Int32 nPos = m_xLineWidthLB->get_active();
+ sal_Int32 nRemovedType = 0;
+ if (m_xLineWidthLB->get_values_changed_from_saved()) {
+ nRemovedType = std::size(s_LineWidths) - m_xLineWidthLB->get_count();
+ }
- SetLineWidth(m_aLineWidths[nPos]);
+ SetLineWidth(s_LineWidths[nPos + nRemovedType], nRemovedType);
// Call the spinner handler to trigger all related modifications
ModifyWidthMFHdl_Impl(*m_xLineWidthMF);
@@ -1252,6 +1252,13 @@ IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthLBHdl_Impl, weld::ComboBox&, void)
IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthMFHdl_Impl, weld::MetricSpinButton&, void)
{
sal_Int64 nVal = m_xLineWidthMF->get_value(FieldUnit::NONE);
+
+ // for DOUBLE_THIN line style we cannot allow thinner line width then 1.10pt
+ if (m_xLbLineStyle->GetSelectEntryStyle() == SvxBorderLineStyle::DOUBLE_THIN)
+ m_xLineWidthMF->set_min(110, FieldUnit::NONE);
+ else
+ m_xLineWidthMF->set_min(5, FieldUnit::NONE);
+
nVal = static_cast<sal_Int64>(vcl::ConvertDoubleValue(
nVal,
m_xLineWidthMF->get_digits(),
@@ -1265,6 +1272,13 @@ IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthMFHdl_Impl, weld::MetricSpinButton&
IMPL_LINK_NOARG(SvxBorderTabPage, SelStyleHdl_Impl, SvtLineListBox&, void)
{
sal_Int64 nOldWidth = m_xLineWidthMF->get_value(FieldUnit::NONE);
+
+ // for DOUBLE_THIN line style we cannot allow thinner line width then 1.10pt
+ if (m_xLbLineStyle->GetSelectEntryStyle() == SvxBorderLineStyle::DOUBLE_THIN)
+ m_xLineWidthMF->set_min(110, FieldUnit::NONE);
+ else
+ m_xLineWidthMF->set_min(5, FieldUnit::NONE);
+
nOldWidth = static_cast<sal_Int64>(vcl::ConvertDoubleValue(
nOldWidth,
m_xLineWidthMF->get_digits(),
@@ -1276,7 +1290,14 @@ IMPL_LINK_NOARG(SvxBorderTabPage, SelStyleHdl_Impl, SvtLineListBox&, void)
// auto change line-width if it doesn't correspond to minimal value
// let's change only in case when user has not changed the line-width into some custom value
- const sal_Int64 nNewWidth = (nOldMinWidth == nOldWidth)? nNewMinWidth : nOldWidth;
+ sal_Int64 nNewWidth = (nOldMinWidth == nOldWidth) ? nNewMinWidth : nOldWidth;
+
+ // if we had selected a predefined border width under SvxBorderLineWidth::Medium set the Medium as default
+ // otherwise if we had a custom border width under 1.10pt then set the spinner to the maximum allowed value for double border styles
+ bool bNewDoubleHairline = m_xLbLineStyle->GetSelectEntryStyle() == SvxBorderLineStyle::DOUBLE_THIN && !m_xLineWidthMF->get_visible() &&
+ (nOldWidth == SvxBorderLineWidth::Hairline || nOldWidth == SvxBorderLineWidth::VeryThin || nOldWidth == SvxBorderLineWidth::Thin);
+ if (bNewDoubleHairline && nNewWidth < SvxBorderLineWidth::Medium)
+ nNewWidth = SvxBorderLineWidth::Medium;
// set value inside edit box
if (nOldWidth != nNewWidth)
@@ -1289,6 +1310,26 @@ IMPL_LINK_NOARG(SvxBorderTabPage, SelStyleHdl_Impl, SvtLineListBox&, void)
SetLineWidth(nNewWidthPt);
}
+ if (m_xLbLineStyle->GetSelectEntryStyle() == SvxBorderLineStyle::DOUBLE_THIN)
+ {
+ for (size_t i = 0; i < 3; i++)
+ {
+ m_xLineWidthLB->save_values_by_id(OUString::number(i));
+ m_xLineWidthLB->remove_id(OUString::number(i));
+ }
+ if (m_xLineWidthLB->get_active_id().isEmpty())
+ m_xLineWidthLB->set_active_id("3");
+ }
+ else
+ {
+ if (m_xLineWidthLB->get_values_changed_from_saved())
+ {
+ for (size_t i = 0; i < 3; i++)
+ m_xLineWidthLB->append(i, OUString::number(i), m_xLineWidthLB->get_saved_values(i));
+ m_xLineWidthLB->removeSavedValues();
+ }
+ }
+
// set value inside style box
m_aFrameSel.SetStyleToSelection( nNewWidth,
m_xLbLineStyle->GetSelectEntryStyle() );
@@ -1413,24 +1454,23 @@ void SvxBorderTabPage::FillValueSets()
FillShadowVS();
}
-void SvxBorderTabPage::SetLineWidth( sal_Int64 nWidth )
+void SvxBorderTabPage::SetLineWidth( sal_Int64 nWidth, sal_Int32 nRemovedType )
{
if ( nWidth >= 0 )
m_xLineWidthMF->set_value( nWidth, FieldUnit::POINT );
- auto it = std::find_if( m_aLineWidths.begin(), m_aLineWidths.end(),
- [nWidth](const int val) -> bool { return val == nWidth; } );
+ auto it = std::find( std::begin(s_LineWidths), std::end(s_LineWidths), nWidth );
- if ( it != m_aLineWidths.end() && *it >= 0 )
+ if ( it != std::end(s_LineWidths) && *it >= 0 )
{
// Select predefined value in combobox
m_xLineWidthMF->hide();
- m_xLineWidthLB->set_active(std::distance(m_aLineWidths.begin(), it));
+ m_xLineWidthLB->set_active(std::distance(std::begin(s_LineWidths), it) - nRemovedType);
}
else
{
// This is not one of predefined values. Show spinner
- m_xLineWidthLB->set_active(m_aLineWidths.size()-1);
+ m_xLineWidthLB->set_active(std::size(s_LineWidths) - nRemovedType -1);
m_xLineWidthMF->show();
}
}
@@ -1477,7 +1517,7 @@ void SvxBorderTabPage::FillLineListBox_Impl()
m_xLbLineStyle->SetSourceUnit( FieldUnit::TWIP );
- for (size_t i = 0; i < SAL_N_ELEMENTS(aLines); ++i)
+ for (size_t i = 0; i < std::size(aLines); ++i)
{
if (!IsBorderLineStyleAllowed(aLines[i].mnStyle))
continue;
@@ -1602,7 +1642,7 @@ void SvxBorderTabPage::UpdateRemoveAdjCellBorderCB( sal_uInt16 nPreset )
// Check if current selection involves deletion of at least one border
bool bBorderDeletionReq = false;
- for ( size_t i=0; i < SAL_N_ELEMENTS( eTypes1 ); ++i )
+ for ( size_t i=0; i < std::size( eTypes1 ); ++i )
{
if( pOldBoxItem->GetLine( eTypes2[i] ) || !( pOldBoxInfoItem->IsValid( eTypes1[i].second ) ) )
{