From fba28df77d7e98663d1cf77ac206f8799fce4108 Mon Sep 17 00:00:00 2001 From: pv2k Date: Thu, 11 May 2017 23:49:54 +0530 Subject: Added margin feature to the Draw's SideBar Change-Id: I53b5430d1563fcceae29418fd5907ac42ea856e7 Reviewed-on: https://gerrit.libreoffice.org/37626 Reviewed-by: Katarina Behrens Tested-by: Katarina Behrens --- sd/sdi/_drvwsh.sdi | 10 ++ sd/source/ui/inc/DrawViewShell.hxx | 1 + sd/source/ui/sidebar/SlideBackground.cxx | 153 +++++++++++++++++++- sd/source/ui/sidebar/SlideBackground.hxx | 23 +++ sd/source/ui/view/drviews7.cxx | 96 +++++++++++++ sd/uiconfig/simpress/ui/sidebarslidebackground.ui | 165 ++++++++++++++++++++++ 6 files changed, 447 insertions(+), 1 deletion(-) (limited to 'sd') diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi index 0e9d8eee12e5..833c578eb8f5 100644 --- a/sd/sdi/_drvwsh.sdi +++ b/sd/sdi/_drvwsh.sdi @@ -2603,6 +2603,16 @@ interface DrawView ExecMethod = FuTemporary ; StateMethod = GetPageProperties ; ] + SID_ATTR_PAGE_LRSPACE + [ + ExecMethod = SetPageProperties ; + StateMethod = GetMarginProperties ; + ] + SID_ATTR_PAGE_ULSPACE + [ + ExecMethod = SetPageProperties ; + StateMethod = GetMarginProperties ; + ] SID_ATTR_PAGE_COLOR [ ExecMethod = SetPageProperties ; diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx index 56083d5a2f4d..7a4836f308de 100644 --- a/sd/source/ui/inc/DrawViewShell.hxx +++ b/sd/source/ui/inc/DrawViewShell.hxx @@ -159,6 +159,7 @@ public: void SetPageProperties (SfxRequest& rReq); void GetPageProperties(SfxItemSet& rSet); + void GetMarginProperties(SfxItemSet& rSet); void GetState (SfxItemSet& rSet); void Execute (SfxRequest& rReq); diff --git a/sd/source/ui/sidebar/SlideBackground.cxx b/sd/source/ui/sidebar/SlideBackground.cxx index 3d40c8123648..2c881f2a4acb 100644 --- a/sd/source/ui/sidebar/SlideBackground.cxx +++ b/sd/source/ui/sidebar/SlideBackground.cxx @@ -45,7 +45,7 @@ #include #include "app.hrc" #include -#include +#include #include #include #include @@ -59,16 +59,41 @@ #include #include #include +#include #include #include "EventMultiplexer.hxx" #include "glob.hrc" #include #include +#include +#include +#include + using namespace ::com::sun::star; using ::com::sun::star::uno::Reference; +namespace +{ + FieldUnit lcl_GetFieldUnit() + { + FieldUnit eUnit = FUNIT_CM; + const SfxPoolItem* pItem = nullptr; + SfxItemState eState = SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_METRIC, pItem ); + if ( pItem && eState >= SfxItemState::DEFAULT ) + { + eUnit = (FieldUnit)static_cast( pItem )->GetValue(); + } + else + { + return SfxModule::GetCurrentFieldUnit(); + } + + return eUnit; + } +} + namespace sd { namespace sidebar { enum eFillStyle @@ -91,6 +116,8 @@ SlideBackground::SlideBackground( mrBase( rBase ), maPaperSizeController(SID_ATTR_PAGE_SIZE, *pBindings, *this), maPaperOrientationController(SID_ATTR_PAGE, *pBindings, *this), + maPaperMarginLRController(SID_ATTR_PAGE_LRSPACE, *pBindings, *this), + maPaperMarginULController(SID_ATTR_PAGE_ULSPACE, *pBindings, *this), maBckColorController(SID_ATTR_PAGE_COLOR, *pBindings, *this), maBckGradientController(SID_ATTR_PAGE_GRADIENT, *pBindings, *this), maBckHatchController(SID_ATTR_PAGE_HATCH, *pBindings, *this), @@ -114,6 +141,11 @@ SlideBackground::SlideBackground( maImpressOtherContext(vcl::EnumContext::Application::Impress, vcl::EnumContext::Context::DrawPage), maImpressMasterContext(vcl::EnumContext::Application::Impress, vcl::EnumContext::Context::MasterPage), mbTitle(false), + meFieldUnit(lcl_GetFieldUnit()), + m_nPageLeftMargin(0), + m_nPageRightMargin(0), + m_nPageTopMargin(0), + m_nPageBottomMargin(0), mpBindings(pBindings) { get(mpPaperSizeBox,"paperformat"); @@ -131,6 +163,23 @@ SlideBackground::SlideBackground( get(mpCloseMaster, "closemasterslide"); get(mpEditMaster, "masterslidebutton"); get(mpMasterLabel, "masterlabel"); + get(m_pLeftMarginEdit, "left"); + get(m_pRightMarginEdit, "right"); + get(m_pTopMarginEdit, "top"); + get(m_pBottomMarginEdit, "bottom"); + + const SfxPoolItem* pItem; + const SvxSizeItem* pSize = nullptr; + if ( SfxViewFrame::Current() ) + { + SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_SIZE, pItem ); + pSize = static_cast( pItem ); + m_aPageSize = pSize->GetSize(); + } + SetFieldUnit( *m_pTopMarginEdit, meFieldUnit ); + SetFieldUnit( *m_pBottomMarginEdit, meFieldUnit ); + SetFieldUnit( *m_pLeftMarginEdit, meFieldUnit ); + SetFieldUnit( *m_pRightMarginEdit, meFieldUnit ); addListener(); Initialize(); } @@ -182,6 +231,12 @@ void SlideBackground::Initialize() mpDspMasterBackground->SetClickHdl(LINK(this, SlideBackground, DspBackground)); mpDspMasterObjects->SetClickHdl(LINK(this,SlideBackground, DspObjects)); + //margins + m_pLeftMarginEdit->SetModifyHdl(LINK(this, SlideBackground, ModifyLRMarginHdl)); + m_pRightMarginEdit->SetModifyHdl(LINK(this, SlideBackground, ModifyLRMarginHdl)); + m_pTopMarginEdit->SetModifyHdl(LINK(this, SlideBackground, ModifyULMarginHdl)); + m_pBottomMarginEdit->SetModifyHdl(LINK(this, SlideBackground, ModifyULMarginHdl)); + Update(); } @@ -472,9 +527,16 @@ void SlideBackground::dispose() mpMasterLabel.clear(); mpEditMaster.clear(); mpCloseMaster.clear(); + m_pLeftMarginEdit.clear(); + m_pRightMarginEdit.clear(); + m_pTopMarginEdit.clear(); + m_pBottomMarginEdit.clear(); + m_pContainer.clear(); maPaperSizeController.dispose(); maPaperOrientationController.dispose(); + maPaperMarginLRController.dispose(); + maPaperMarginULController.dispose(); maBckColorController.dispose(); maBckGradientController.dispose(); maBckHatchController.dispose(); @@ -694,6 +756,38 @@ void SlideBackground::NotifyItemUpdate( } break; + case SID_ATTR_PAGE_LRSPACE: + { + const SvxLongLRSpaceItem* pLRItem = nullptr; + if (eState >= SfxItemState::DEFAULT) + { + pLRItem = dynamic_cast(pState); + m_nPageLeftMargin = pLRItem->GetLeft(); + m_nPageRightMargin = pLRItem->GetRight(); + SetFieldUnit(*m_pLeftMarginEdit, meFieldUnit, true); + SetMetricValue(*m_pLeftMarginEdit.get(), m_nPageLeftMargin, meUnit); + SetFieldUnit(*m_pRightMarginEdit, meFieldUnit, true); + SetMetricValue(*m_pRightMarginEdit.get(), m_nPageRightMargin, meUnit); + } + } + break; + + case SID_ATTR_PAGE_ULSPACE: + { + const SvxLongULSpaceItem* pULItem = nullptr; + if (eState >= SfxItemState::DEFAULT) + { + pULItem = dynamic_cast(pState); + m_nPageTopMargin = pULItem->GetUpper(); + m_nPageBottomMargin = pULItem->GetLower(); + SetFieldUnit(*m_pTopMarginEdit, meFieldUnit, true); + SetMetricValue(*m_pTopMarginEdit.get(), m_nPageTopMargin, meUnit); + SetFieldUnit(*m_pBottomMarginEdit, meFieldUnit, true); + SetMetricValue(*m_pBottomMarginEdit.get(), m_nPageBottomMargin, meUnit); + } + } + break; + case SID_DISPLAY_MASTER_BACKGROUND: { const SfxBoolItem* pBoolItem = nullptr; @@ -726,6 +820,33 @@ void SlideBackground::NotifyItemUpdate( } } +void SlideBackground::SetMetricFieldMaxValues( const Size& rPageSize ) +{ + const long nML = m_pLeftMarginEdit->Denormalize( m_pLeftMarginEdit->GetValue( FUNIT_TWIP ) ); + const long nMR = m_pRightMarginEdit->Denormalize( m_pRightMarginEdit->GetValue( FUNIT_TWIP ) ); + const long nMT = m_pTopMarginEdit->Denormalize( m_pTopMarginEdit->GetValue( FUNIT_TWIP ) ); + const long nMB = m_pBottomMarginEdit->Denormalize( m_pBottomMarginEdit->GetValue( FUNIT_TWIP ) ); + + const long nPH = LogicToLogic( rPageSize.Height(), meUnit, MapUnit::MapTwip ); + const long nPW = LogicToLogic( rPageSize.Width(), meUnit, MapUnit::MapTwip ); + + // Left + long nMax = nPW - nMR - MINBODY; + m_pLeftMarginEdit->SetMax( m_pLeftMarginEdit->Normalize( nMax ), FUNIT_TWIP ); + + // Right + nMax = nPW - nML - MINBODY; + m_pRightMarginEdit->SetMax( m_pRightMarginEdit->Normalize( nMax ), FUNIT_TWIP ); + + //Top + nMax = nPH - nMB - MINBODY; + m_pTopMarginEdit->SetMax( m_pTopMarginEdit->Normalize( nMax ), FUNIT_TWIP ); + + //Bottom + nMax = nPH - nMT - MINBODY; + m_pBottomMarginEdit->SetMax( m_pTopMarginEdit->Normalize( nMax ), FUNIT_TWIP ); +} + IMPL_LINK_NOARG(SlideBackground, FillStyleModifyHdl, ListBox&, void) { const eFillStyle nPos = (eFillStyle)mpFillStyle->GetSelectEntryPos(); @@ -906,6 +1027,36 @@ IMPL_LINK_NOARG(SlideBackground, DspObjects, Button*, void) GetBindings()->GetDispatcher()->ExecuteList(SID_DISPLAY_MASTER_OBJECTS, SfxCallMode::RECORD, { &aBoolItem, &aBoolItem }); } +IMPL_LINK_NOARG( SlideBackground, ModifyLRMarginHdl, Edit&, void ) +{ + m_nPageLeftMargin = GetCoreValue( *m_pLeftMarginEdit.get(), meUnit ); + m_nPageRightMargin = GetCoreValue( *m_pRightMarginEdit.get(), meUnit ); + if ( SfxViewFrame::Current() ) + { + std::unique_ptr pPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ); + pPageLRMarginItem->SetLeft( m_nPageLeftMargin ); + pPageLRMarginItem->SetRight( m_nPageRightMargin ); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, SfxCallMode::RECORD, { pPageLRMarginItem.get() } ); + pPageLRMarginItem.reset(); + } + SetMetricFieldMaxValues( m_aPageSize ); +} + +IMPL_LINK_NOARG( SlideBackground, ModifyULMarginHdl, Edit&, void ) +{ + m_nPageTopMargin = GetCoreValue( *m_pTopMarginEdit.get(), meUnit ); + m_nPageBottomMargin = GetCoreValue( *m_pBottomMarginEdit.get(), meUnit ); + if ( SfxViewFrame::Current() ) + { + std::unique_ptr pPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ); + pPageULMarginItem->SetUpper( m_nPageTopMargin ); + pPageULMarginItem->SetLower( m_nPageBottomMargin ); + GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, SfxCallMode::RECORD, { pPageULMarginItem.get() } ); + pPageULMarginItem.reset(); + } + SetMetricFieldMaxValues( m_aPageSize ); +} + }} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/sidebar/SlideBackground.hxx b/sd/source/ui/sidebar/SlideBackground.hxx index 4294027a0b53..20b6a289b691 100644 --- a/sd/source/ui/sidebar/SlideBackground.hxx +++ b/sd/source/ui/sidebar/SlideBackground.hxx @@ -34,7 +34,9 @@ #include #include #include "fupage.hxx" +#include #include +#include #include #include #include @@ -47,6 +49,8 @@ class SvxColorListBox; +static const long MINBODY = 284; + namespace sd { namespace sidebar { class SlideBackground : @@ -89,9 +93,16 @@ private: VclPtr