summaryrefslogtreecommitdiff
path: root/sw/source/uibase/sidebar/PageFormatPanel.cxx
diff options
context:
space:
mode:
authorSusobhan Ghosh <susobhang70@gmail.com>2016-05-26 21:05:14 +0530
committerKatarina Behrens <Katarina.Behrens@cib.de>2016-06-14 08:08:27 +0000
commit656513d15116a3c6feeadc6a3353a304e0b3ef2b (patch)
tree61eaceb4a3cc21f772a1d30c1e31c5e1dd9ed138 /sw/source/uibase/sidebar/PageFormatPanel.cxx
parent7f878db51569b3af66b5a5df4d078ddf77e3d173 (diff)
tdf#83830: Moved margin preset control to Format Panel
Added new margin presets. Change-Id: I65927ebfaf61515cedd76bb85e0a6d543fc16b89 Reviewed-on: https://gerrit.libreoffice.org/25520 Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de> Tested-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'sw/source/uibase/sidebar/PageFormatPanel.cxx')
-rw-r--r--sw/source/uibase/sidebar/PageFormatPanel.cxx152
1 files changed, 151 insertions, 1 deletions
diff --git a/sw/source/uibase/sidebar/PageFormatPanel.cxx b/sw/source/uibase/sidebar/PageFormatPanel.cxx
index 824473883c0e..5bf359dc69e1 100644
--- a/sw/source/uibase/sidebar/PageFormatPanel.cxx
+++ b/sw/source/uibase/sidebar/PageFormatPanel.cxx
@@ -25,6 +25,7 @@
#include <svx/dlgutil.hxx>
#include <svx/rulritem.hxx>
#include "PageFormatPanel.hxx"
+#include "PageMarginUtils.hxx"
#include <sfx2/sidebar/ControlFactory.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/bindings.hxx>
@@ -61,15 +62,22 @@ PageFormatPanel::PageFormatPanel(
maPaperSizeController(SID_ATTR_PAGE_SIZE, *pBindings, *this),
maPaperOrientationController(SID_ATTR_PAGE, *pBindings, *this),
maMetricController(SID_ATTR_METRIC, *pBindings,*this),
+ maSwPageLRControl(SID_ATTR_PAGE_LRSPACE, *pBindings, *this),
+ maSwPageULControl(SID_ATTR_PAGE_ULSPACE, *pBindings, *this),
mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ),
+ mpPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ),
+ mpPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ),
meFUnit(GetModuleFieldUnit()),
meLastFUnit(GetModuleFieldUnit()),
- meUnit()
+ meUnit(),
+ aCustomEntry()
{
get(mpPaperSizeBox, "papersize");
get(mpPaperWidth, "paperwidth");
get(mpPaperHeight, "paperheight");
get(mpPaperOrientation, "paperorientation");
+ get(mpMarginSelectBox, "marginLB");
+ get(mpCustomEntry, "customlabel");
Initialize();
}
@@ -84,10 +92,16 @@ void PageFormatPanel::dispose()
mpPaperWidth.disposeAndClear();
mpPaperHeight.disposeAndClear();
mpPaperOrientation.disposeAndClear();
+ mpMarginSelectBox.disposeAndClear();
+ mpCustomEntry.clear();
maMetricController.dispose();
maPaperOrientationController.dispose();
maPaperSizeController.dispose();
+ maSwPageLRControl.dispose();
+ maSwPageULControl.dispose();
+ mpPageULMarginItem.reset();
+ mpPageLRMarginItem.reset();
mpPageItem.reset();
PanelLayout::dispose();
@@ -100,6 +114,7 @@ void PageFormatPanel::Initialize()
meUnit = maPaperSizeController.GetCoreMetric();
SetFieldUnit( *mpPaperWidth, meFUnit );
SetFieldUnit( *mpPaperHeight, meFUnit );
+ aCustomEntry = mpCustomEntry->GetText();
const SvtOptionsDrawinglayer aDrawinglayerOpt;
mpPaperWidth->SetMax(mpPaperWidth->Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FUNIT_CM);
@@ -111,10 +126,15 @@ void PageFormatPanel::Initialize()
mpPaperOrientation->SetSelectHdl( LINK(this, PageFormatPanel, PaperFormatModifyHdl ));
mpPaperHeight->SetModifyHdl( LINK(this, PageFormatPanel, PaperSizeModifyHdl ));
mpPaperWidth->SetModifyHdl( LINK(this, PageFormatPanel, PaperSizeModifyHdl ));
+ mpMarginSelectBox->SetSelectHdl( LINK(this, PageFormatPanel, PaperModifyMarginHdl));
mpBindings->Update(SID_ATTR_METRIC);
mpBindings->Update(SID_ATTR_PAGE);
mpBindings->Update(SID_ATTR_PAGE_SIZE);
+ mpBindings->Update( SID_ATTR_PAGE_LRSPACE );
+ mpBindings->Update( SID_ATTR_PAGE_ULSPACE );
+
+ UpdateMarginBox();
}
void PageFormatPanel::NotifyItemUpdate(
@@ -172,6 +192,26 @@ void PageFormatPanel::NotifyItemUpdate(
}
}
break;
+ case SID_ATTR_PAGE_LRSPACE:
+ {
+ if ( eState >= SfxItemState::DEFAULT &&
+ pState && dynamic_cast< const SvxLongLRSpaceItem *>( pState ) != nullptr )
+ {
+ mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
+ UpdateMarginBox();
+ }
+ }
+ break;
+ case SID_ATTR_PAGE_ULSPACE:
+ {
+ if ( eState >= SfxItemState::DEFAULT &&
+ pState && dynamic_cast< const SvxLongULSpaceItem *>( pState ) != nullptr )
+ {
+ mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
+ UpdateMarginBox();
+ }
+ }
+ break;
default:
break;
}
@@ -197,6 +237,51 @@ IMPL_LINK_NOARG_TYPED(PageFormatPanel, PaperSizeModifyHdl, Edit&, void)
mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem });
}
+IMPL_LINK_NOARG_TYPED(PageFormatPanel, PaperModifyMarginHdl, ListBox&, void)
+{
+ bool bMirrored = false;
+ bool bApplyNewPageMargins = true;
+ switch ( mpMarginSelectBox->GetSelectEntryPos() )
+ {
+ case 0:
+ SetNarrow(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
+ break;
+ case 1:
+ SetModerate(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
+ break;
+ case 2:
+ SetNormal075(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
+ break;
+ case 3:
+ SetNormal100(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
+ break;
+ case 4:
+ SetNormal125(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
+ break;
+ case 5:
+ SetWide(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
+ break;
+ case 6:
+ SetMirrored(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
+ break;
+ default:
+ bApplyNewPageMargins = false;
+ break;
+ }
+
+ if(bApplyNewPageMargins)
+ {
+ ExecuteMarginLRChange( mnPageLeftMargin, mnPageRightMargin );
+ ExecuteMarginULChange( mnPageTopMargin, mnPageBottomMargin );
+ if(bMirrored != (mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR))
+ {
+ mpPageItem->SetPageUsage( bMirrored ? SVX_PAGE_MIRROR : SVX_PAGE_ALL );
+ mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE,
+ SfxCallMode::RECORD, { mpPageItem.get() });
+ }
+ }
+}
+
FieldUnit PageFormatPanel::GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState )
{
FieldUnit eUnit = FUNIT_NONE;
@@ -228,6 +313,71 @@ FieldUnit PageFormatPanel::GetCurrentUnit( SfxItemState eState, const SfxPoolIte
return eUnit;
}
+void PageFormatPanel::ExecuteMarginLRChange( const long nPageLeftMargin, const long nPageRightMargin )
+{
+ mpPageLRMarginItem->SetLeft( nPageLeftMargin );
+ mpPageLRMarginItem->SetRight( nPageRightMargin );
+ mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, SfxCallMode::RECORD, { mpPageLRMarginItem.get() });
+}
+
+void PageFormatPanel::ExecuteMarginULChange(const long nPageTopMargin, const long nPageBottomMargin)
+{
+ mpPageULMarginItem->SetUpper( nPageTopMargin );
+ mpPageULMarginItem->SetLower( nPageBottomMargin );
+ mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, SfxCallMode::RECORD, { mpPageULMarginItem.get() });
+}
+
+void PageFormatPanel::UpdateMarginBox()
+{
+ mnPageLeftMargin = mpPageLRMarginItem->GetLeft();
+ mnPageRightMargin = mpPageLRMarginItem->GetRight();
+ mnPageTopMargin = mpPageULMarginItem->GetUpper();
+ mnPageBottomMargin = mpPageULMarginItem->GetLower();
+
+ bool bMirrored = (mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR);
+ if( IsNarrow(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) )
+ {
+ mpMarginSelectBox->SelectEntryPos(0);
+ mpMarginSelectBox->RemoveEntry(aCustomEntry);
+ }
+ else if( IsModerate(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) )
+ {
+ mpMarginSelectBox->SelectEntryPos(1);
+ mpMarginSelectBox->RemoveEntry(aCustomEntry);
+ }
+ else if( IsNormal075(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) )
+ {
+ mpMarginSelectBox->SelectEntryPos(2);
+ mpMarginSelectBox->RemoveEntry(aCustomEntry);
+ }
+ else if( IsNormal100(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) )
+ {
+ mpMarginSelectBox->SelectEntryPos(3);
+ mpMarginSelectBox->RemoveEntry(aCustomEntry);
+ }
+ else if( IsNormal125(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) )
+ {
+ mpMarginSelectBox->SelectEntryPos(4);
+ mpMarginSelectBox->RemoveEntry(aCustomEntry);
+ }
+ else if( IsWide(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) )
+ {
+ mpMarginSelectBox->SelectEntryPos(5);
+ mpMarginSelectBox->RemoveEntry(aCustomEntry);
+ }
+ else if( IsMirrored(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored) )
+ {
+ mpMarginSelectBox->SelectEntryPos(6);
+ mpMarginSelectBox->RemoveEntry(aCustomEntry);
+ }
+ else
+ {
+ if(mpMarginSelectBox->GetEntryPos(aCustomEntry) == LISTBOX_ENTRY_NOTFOUND)
+ mpMarginSelectBox->InsertEntry(aCustomEntry);
+ mpMarginSelectBox->SelectEntry(aCustomEntry);
+ }
+}
+
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */