diff options
Diffstat (limited to '')
-rw-r--r-- | sd/source/ui/app/optsitem.cxx | 1405 | ||||
-rw-r--r-- | sd/source/ui/app/sddll.cxx | 274 | ||||
-rw-r--r-- | sd/source/ui/app/sdmod.cxx | 216 | ||||
-rw-r--r-- | sd/source/ui/app/sdmod1.cxx | 630 | ||||
-rw-r--r-- | sd/source/ui/app/sdmod2.cxx | 816 | ||||
-rw-r--r-- | sd/source/ui/app/sdpopup.cxx | 300 | ||||
-rw-r--r-- | sd/source/ui/app/sdxfer.cxx | 820 | ||||
-rw-r--r-- | sd/source/ui/app/tmplctrl.cxx | 139 |
8 files changed, 4600 insertions, 0 deletions
diff --git a/sd/source/ui/app/optsitem.cxx b/sd/source/ui/app/optsitem.cxx new file mode 100644 index 000000000..b247a7e02 --- /dev/null +++ b/sd/source/ui/app/optsitem.cxx @@ -0,0 +1,1405 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <o3tl/any.hxx> +#include <svx/svdmodel.hxx> +#include <svx/svxids.hrc> +#include <tools/debug.hxx> +#include <tools/helpers.hxx> +#include <unotools/localedatawrapper.hxx> +#include <unotools/syslocale.hxx> + +#include <optsitem.hxx> +#include <FrameView.hxx> +#include <sdattr.hrc> + +using namespace ::utl; +using namespace ::com::sun::star::uno; + +template< class T > static T getSafeValue( const Any& rAny ) +{ + T value = T(); + bool bOk = (rAny >>= value); + + DBG_ASSERT( bOk, "SdOptionsItem, wrong type from configuration!" ); + + return value; +} + + +SdOptionsItem::SdOptionsItem( const SdOptionsGeneric& rParent, const OUString& rSubTree ) : + ConfigItem ( rSubTree ), + mrParent ( rParent ) +{ +} + +SdOptionsItem::~SdOptionsItem() +{ +} + +void SdOptionsItem::ImplCommit() +{ + if( IsModified() ) + mrParent.Commit( *this ); +}; + +void SdOptionsItem::Notify( const css::uno::Sequence<OUString>& ) +{} + +Sequence< Any > SdOptionsItem::GetProperties( const Sequence< OUString >& rNames ) +{ + return ConfigItem::GetProperties( rNames ); +} + +bool SdOptionsItem::PutProperties( const Sequence< OUString >& rNames, const Sequence< Any>& rValues ) +{ + return ConfigItem::PutProperties( rNames, rValues ); +} + +SdOptionsGeneric::SdOptionsGeneric(bool bImpress, const OUString& rSubTree) + : maSubTree(rSubTree) + , mbImpress(bImpress) + , mbInit(rSubTree.isEmpty()) + , mbEnableModify(false) +{ +} + +SdOptionsGeneric::SdOptionsGeneric(SdOptionsGeneric const & rSource) +{ + operator=(rSource); +} + +SdOptionsGeneric& SdOptionsGeneric::operator=(SdOptionsGeneric const & rSource) +{ + if (this != &rSource) + { + maSubTree = rSource.maSubTree; + mpCfgItem.reset(rSource.mpCfgItem ? new SdOptionsItem(*rSource.mpCfgItem) : nullptr ); + mbImpress = rSource.mbImpress; + mbInit = rSource.mbInit; + mbEnableModify = rSource.mbEnableModify; + } + return *this; +} + +void SdOptionsGeneric::Init() const +{ + if( mbInit ) + return; + + SdOptionsGeneric* pThis = const_cast<SdOptionsGeneric*>(this); + + if( !mpCfgItem ) + pThis->mpCfgItem.reset( new SdOptionsItem( *this, maSubTree ) ); + + const Sequence< OUString > aNames( GetPropertyNames() ); + const Sequence< Any > aValues = mpCfgItem->GetProperties( aNames ); + + if( aNames.hasElements() && ( aValues.getLength() == aNames.getLength() ) ) + { + const Any* pValues = aValues.getConstArray(); + + pThis->EnableModify( false ); + pThis->mbInit = pThis->ReadData( pValues ); + pThis->EnableModify( true ); + } + else + pThis->mbInit = true; +} + +SdOptionsGeneric::~SdOptionsGeneric() +{ +} + +void SdOptionsGeneric::Commit( SdOptionsItem& rCfgItem ) const +{ + const Sequence< OUString > aNames( GetPropertyNames() ); + Sequence< Any > aValues( aNames.getLength() ); + + if( aNames.hasElements() ) + { + if( WriteData( aValues.getArray() ) ) + rCfgItem.PutProperties( aNames, aValues ); + else + { + OSL_FAIL( "PutProperties failed" ); + } + } +} + +Sequence< OUString > SdOptionsGeneric::GetPropertyNames() const +{ + sal_uLong nCount; + const char** ppPropNames; + + GetPropNameArray( ppPropNames, nCount ); + + Sequence< OUString > aNames( nCount ); + OUString* pNames = aNames.getArray(); + + for( sal_uLong i = 0; i < nCount; i++ ) + pNames[ i ] = OUString::createFromAscii( ppPropNames[ i ] ); + + return aNames; +} + +void SdOptionsGeneric::Store() +{ + if( mpCfgItem ) + mpCfgItem->Commit(); +} + +bool SdOptionsGeneric::isMetricSystem() +{ + SvtSysLocale aSysLocale; + MeasurementSystem eSys = aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum(); + + return ( eSys == MeasurementSystem::Metric ); +} + +/************************************************************************* +|* +|* SdOptionsLayout +|* +\************************************************************************/ + +SdOptionsLayout::SdOptionsLayout(bool bImpress, bool bUseConfig) : + SdOptionsGeneric( bImpress, bUseConfig ? + ( bImpress ? + OUString( "Office.Impress/Layout" ) : + OUString( "Office.Draw/Layout" ) ) : + OUString() ), + bRuler( true ), + bMoveOutline( true ), + bDragStripes( false ), + bHandlesBezier( false ), + bHelplines( true ), + nMetric(static_cast<sal_uInt16>(isMetricSystem() ? FieldUnit::CM : FieldUnit::INCH)), + nDefTab( 1250 ) +{ + EnableModify( true ); +} + +bool SdOptionsLayout::operator==( const SdOptionsLayout& rOpt ) const +{ + return( IsRulerVisible() == rOpt.IsRulerVisible() && + IsMoveOutline() == rOpt.IsMoveOutline() && + IsDragStripes() == rOpt.IsDragStripes() && + IsHandlesBezier() == rOpt.IsHandlesBezier() && + IsHelplines() == rOpt.IsHelplines() && + GetMetric() == rOpt.GetMetric() && + GetDefTab() == rOpt.GetDefTab() ); +} + +void SdOptionsLayout::GetPropNameArray( const char**& ppNames, sal_uLong& rCount ) const +{ + if( isMetricSystem() ) + { + static const char* aPropNamesMetric[] = + { + "Display/Ruler", + "Display/Bezier", + "Display/Contour", + "Display/Guide", + "Display/Helpline", + "Other/MeasureUnit/Metric", + "Other/TabStop/Metric" + }; + ppNames = aPropNamesMetric; + rCount = SAL_N_ELEMENTS(aPropNamesMetric); + } + else + { + static const char* aPropNamesNonMetric[] = + { + "Display/Ruler", + "Display/Bezier", + "Display/Contour", + "Display/Guide", + "Display/Helpline", + "Other/MeasureUnit/NonMetric", + "Other/TabStop/NonMetric" + }; + ppNames = aPropNamesNonMetric; + rCount = SAL_N_ELEMENTS(aPropNamesNonMetric); + } +} + +bool SdOptionsLayout::ReadData( const Any* pValues ) +{ + if( pValues[0].hasValue() ) SetRulerVisible( *o3tl::doAccess<bool>(pValues[ 0 ]) ); + if( pValues[1].hasValue() ) SetHandlesBezier( *o3tl::doAccess<bool>(pValues[ 1 ]) ); + if( pValues[2].hasValue() ) SetMoveOutline( *o3tl::doAccess<bool>(pValues[ 2 ]) ); + if( pValues[3].hasValue() ) SetDragStripes( *o3tl::doAccess<bool>(pValues[ 3 ]) ); + if( pValues[4].hasValue() ) SetHelplines( *o3tl::doAccess<bool>(pValues[ 4 ]) ); + if( pValues[5].hasValue() ) SetMetric( static_cast<sal_uInt16>(*o3tl::doAccess<sal_Int32>(pValues[ 5 ])) ); + if( pValues[6].hasValue() ) SetDefTab( static_cast<sal_uInt16>(*o3tl::doAccess<sal_Int32>(pValues[ 6 ])) ); + + return true; +} + +bool SdOptionsLayout::WriteData( Any* pValues ) const +{ + pValues[ 0 ] <<= IsRulerVisible(); + pValues[ 1 ] <<= IsHandlesBezier(); + pValues[ 2 ] <<= IsMoveOutline(); + pValues[ 3 ] <<= IsDragStripes(); + pValues[ 4 ] <<= IsHelplines(); + pValues[ 5 ] <<= static_cast<sal_Int32>(GetMetric()); + pValues[ 6 ] <<= static_cast<sal_Int32>(GetDefTab()); + + return true; +} + +/************************************************************************* +|* +|* SdOptionsLayoutItem +|* +\************************************************************************/ + +SdOptionsLayoutItem::SdOptionsLayoutItem() +: SfxPoolItem ( ATTR_OPTIONS_LAYOUT ) +, maOptionsLayout ( false, false ) +{ +} + +SdOptionsLayoutItem::SdOptionsLayoutItem( SdOptions const * pOpts, ::sd::FrameView const * pView ) +: SfxPoolItem ( ATTR_OPTIONS_LAYOUT ) +, maOptionsLayout ( false, false ) +{ + if( pOpts ) + { + maOptionsLayout.SetMetric( pOpts->GetMetric() ); + maOptionsLayout.SetDefTab( pOpts->GetDefTab() ); + } + + if( pView ) + { + maOptionsLayout.SetRulerVisible( pView->HasRuler() ); + maOptionsLayout.SetMoveOutline( !pView->IsNoDragXorPolys() ); + maOptionsLayout.SetDragStripes( pView->IsDragStripes() ); + maOptionsLayout.SetHandlesBezier( pView->IsPlusHandlesAlwaysVisible() ); + maOptionsLayout.SetHelplines( pView->IsHlplVisible() ); + } + else if( pOpts ) + { + maOptionsLayout.SetRulerVisible( pOpts->IsRulerVisible() ); + maOptionsLayout.SetMoveOutline( pOpts->IsMoveOutline() ); + maOptionsLayout.SetDragStripes( pOpts->IsDragStripes() ); + maOptionsLayout.SetHandlesBezier( pOpts->IsHandlesBezier() ); + maOptionsLayout.SetHelplines( pOpts->IsHelplines() ); + } +} + +SdOptionsLayoutItem* SdOptionsLayoutItem::Clone( SfxItemPool* ) const +{ + return new SdOptionsLayoutItem( *this ); +} + +bool SdOptionsLayoutItem::operator==( const SfxPoolItem& rAttr ) const +{ + assert(SfxPoolItem::operator==(rAttr)); + return maOptionsLayout == static_cast<const SdOptionsLayoutItem&>(rAttr).maOptionsLayout; +} + +void SdOptionsLayoutItem::SetOptions( SdOptions* pOpts ) const +{ + if( pOpts ) + { + pOpts->SetRulerVisible( maOptionsLayout.IsRulerVisible() ); + pOpts->SetMoveOutline( maOptionsLayout.IsMoveOutline() ); + pOpts->SetDragStripes( maOptionsLayout.IsDragStripes() ); + pOpts->SetHandlesBezier( maOptionsLayout.IsHandlesBezier() ); + pOpts->SetHelplines( maOptionsLayout.IsHelplines() ); + pOpts->SetMetric( maOptionsLayout.GetMetric() ); + pOpts->SetDefTab( maOptionsLayout.GetDefTab() ); + } +} + +/************************************************************************* +|* +|* SdOptionsContents +|* +\************************************************************************/ + +SdOptionsContents::SdOptionsContents(bool bImpress) : + SdOptionsGeneric( bImpress, bImpress ? + OUString( "Office.Impress/Content" ) : + OUString( "Office.Draw/Content" ) ) +{ + EnableModify( true ); +} + +bool SdOptionsContents::operator==(const SdOptionsContents&) const +{ + return true; +} + +void SdOptionsContents::GetPropNameArray( const char**& ppNames, sal_uLong& rCount ) const +{ + static const char* aPropNames[] = + { + "Display/PicturePlaceholder", + "Display/ContourMode", + "Display/LineContour", + "Display/TextPlaceholder" + }; + + rCount = SAL_N_ELEMENTS(aPropNames); + ppNames = aPropNames; +} + +bool SdOptionsContents::ReadData(const Any*) +{ + return true; +} + +bool SdOptionsContents::WriteData( Any* pValues ) const +{ + //#i80528# no draft anymore + pValues[ 0 ] <<= false; + pValues[ 1 ] <<= false; + pValues[ 2 ] <<= false; + pValues[ 3 ] <<= false; + + return true; +} +/************************************************************************* +|* +|* SdOptionsMisc +|* +\************************************************************************/ + +SdOptionsMisc::SdOptionsMisc( bool bImpress, bool bUseConfig ) : + SdOptionsGeneric( bImpress, bUseConfig ? + ( bImpress ? + OUString( "Office.Impress/Misc" ) : + OUString( "Office.Draw/Misc" ) ) : + OUString() ), + nDefaultObjectSizeWidth(8000), + nDefaultObjectSizeHeight(5000), + bStartWithTemplate( false ), + bMarkedHitMovesAlways( true ), + bMoveOnlyDragging( false ), + bCrookNoContortion( false ), + bQuickEdit( IsImpress() ), + bMasterPageCache( true ), + bDragWithCopy( false ), + bPickThrough( true ), + bDoubleClickTextEdit( true ), + bClickChangeRotation( false ), + bEnableSdremote( false ), + bEnablePresenterScreen( true), + bSolidDragging( true ), + bSummationOfParagraphs( false ), + bTabBarVisible( true ), + bShowUndoDeleteWarning( true ), + bSlideshowRespectZOrder( true ), + bShowComments( true ), + bPreviewNewEffects( true ), + bPreviewChangedEffects( false ), + bPreviewTransitions( true ), + mnDisplay( 0 ), + mnPenColor( 0xff0000 ), + mnPenWidth( 150.0 ), + + // The default for 6.1-and-above documents is to use printer-independent + // formatting. + mnPrinterIndependentLayout (1) +{ + EnableModify( true ); +} + +bool SdOptionsMisc::operator==( const SdOptionsMisc& rOpt ) const +{ + return( IsStartWithTemplate() == rOpt.IsStartWithTemplate() && + IsMarkedHitMovesAlways() == rOpt.IsMarkedHitMovesAlways() && + IsMoveOnlyDragging() == rOpt.IsMoveOnlyDragging() && + IsCrookNoContortion() == rOpt.IsCrookNoContortion() && + IsQuickEdit() == rOpt.IsQuickEdit() && + IsMasterPagePaintCaching() == rOpt.IsMasterPagePaintCaching() && + IsDragWithCopy() == rOpt.IsDragWithCopy() && + IsPickThrough() == rOpt.IsPickThrough() && + IsDoubleClickTextEdit() == rOpt.IsDoubleClickTextEdit() && + IsClickChangeRotation() == rOpt.IsClickChangeRotation() && + IsEnableSdremote() == rOpt.IsEnableSdremote() && + IsEnablePresenterScreen() == rOpt.IsEnablePresenterScreen()&& + IsSummationOfParagraphs() == rOpt.IsSummationOfParagraphs() && + IsTabBarVisible() == rOpt.IsTabBarVisible() && + IsSolidDragging() == rOpt.IsSolidDragging() && + IsShowUndoDeleteWarning() == rOpt.IsShowUndoDeleteWarning() && + IsSlideshowRespectZOrder() == rOpt.IsSlideshowRespectZOrder() && + GetPrinterIndependentLayout() == rOpt.GetPrinterIndependentLayout() && + GetDefaultObjectSizeWidth() == rOpt.GetDefaultObjectSizeWidth() && + GetDefaultObjectSizeHeight() == rOpt.GetDefaultObjectSizeHeight() && + + IsPreviewNewEffects() == rOpt.IsPreviewNewEffects() && + IsPreviewChangedEffects() == rOpt.IsPreviewChangedEffects() && + IsPreviewTransitions() == rOpt.IsPreviewTransitions() && + GetDisplay() == rOpt.GetDisplay() && + IsShowComments() == rOpt.IsShowComments() && + GetPresentationPenColor() == rOpt.GetPresentationPenColor() && + GetPresentationPenWidth() == rOpt.GetPresentationPenWidth() + ); +} + +void SdOptionsMisc::GetPropNameArray( const char**& ppNames, sal_uLong& rCount ) const +{ + static const char* aPropNames[] = + { + "ObjectMoveable", + "NoDistort", + "TextObject/QuickEditing", + "BackgroundCache", + "CopyWhileMoving", + "TextObject/Selectable", + "DclickTextedit", + "RotateClick", + "Preview", + "ModifyWithAttributes", + "DefaultObjectSize/Width", + "DefaultObjectSize/Height", + + "Compatibility/PrinterIndependentLayout", + + "ShowComments", + + // just for impress + "NewDoc/AutoPilot", + "Compatibility/AddBetween", + "ShowUndoDeleteWarning", + "SlideshowRespectZOrder", + + "PreviewNewEffects", + "PreviewChangedEffects", + "PreviewTransitions", + + "Display", + + "PenColor", + "PenWidth", + "Start/EnableSdremote", + "Start/EnablePresenterScreen", + "TabBarVisible" + }; + + rCount = ( IsImpress() ? SAL_N_ELEMENTS(aPropNames) : 14 ); + ppNames = aPropNames; +} + +bool SdOptionsMisc::ReadData( const Any* pValues ) +{ + if( pValues[0].hasValue() ) SetMarkedHitMovesAlways( *o3tl::doAccess<bool>(pValues[ 0 ]) ); + if( pValues[1].hasValue() ) SetCrookNoContortion( *o3tl::doAccess<bool>(pValues[ 1 ]) ); + if( pValues[2].hasValue() ) SetQuickEdit( *o3tl::doAccess<bool>(pValues[ 2 ]) ); + if( pValues[3].hasValue() ) SetMasterPagePaintCaching( *o3tl::doAccess<bool>(pValues[ 3 ]) ); + if( pValues[4].hasValue() ) SetDragWithCopy( *o3tl::doAccess<bool>(pValues[ 4 ]) ); + if( pValues[5].hasValue() ) SetPickThrough( *o3tl::doAccess<bool>(pValues[ 5 ]) ); + if( pValues[6].hasValue() ) SetDoubleClickTextEdit( *o3tl::doAccess<bool>(pValues[ 6 ]) ); + if( pValues[7].hasValue() ) SetClickChangeRotation( *o3tl::doAccess<bool>(pValues[ 7 ]) ); + if( pValues[9].hasValue() ) SetSolidDragging( *o3tl::doAccess<bool>(pValues[ 9 ]) ); + if( pValues[10].hasValue() ) SetDefaultObjectSizeWidth( *o3tl::doAccess<sal_uInt32>(pValues[ 10 ]) ); + if( pValues[11].hasValue() ) SetDefaultObjectSizeHeight( *o3tl::doAccess<sal_uInt32>(pValues[ 11 ]) ); + if( pValues[12].hasValue() ) SetPrinterIndependentLayout( *o3tl::doAccess<sal_uInt16>(pValues[ 12 ]) ); + + if( pValues[13].hasValue() ) + SetShowComments( *o3tl::doAccess<bool>(pValues[ 13 ]) ); + + // just for Impress + if (IsImpress()) + { + if( pValues[14].hasValue() ) + SetStartWithTemplate( *o3tl::doAccess<bool>(pValues[ 14 ]) ); + if( pValues[15].hasValue() ) + SetSummationOfParagraphs( *o3tl::doAccess<bool>(pValues[ 15 ]) ); + if( pValues[16].hasValue() ) + SetShowUndoDeleteWarning( *o3tl::doAccess<bool>(pValues[ 16 ]) ); + + if( pValues[17].hasValue() ) + SetSlideshowRespectZOrder(*o3tl::doAccess<bool>(pValues[ 17 ])); + + if( pValues[18].hasValue() ) + SetPreviewNewEffects(*o3tl::doAccess<bool>(pValues[ 18 ])); + + if( pValues[19].hasValue() ) + SetPreviewChangedEffects(*o3tl::doAccess<bool>(pValues[ 19 ])); + + if( pValues[20].hasValue() ) + SetPreviewTransitions(*o3tl::doAccess<bool>(pValues[ 20 ])); + + if( pValues[21].hasValue() ) + SetDisplay(*o3tl::doAccess<sal_Int32>(pValues[ 21 ])); + + if( pValues[22].hasValue() ) + SetPresentationPenColor( getSafeValue< sal_Int32 >( pValues[ 22 ] ) ); + + if( pValues[23].hasValue() ) + SetPresentationPenWidth( getSafeValue< double >( pValues[ 23 ] ) ); + + if( pValues[24].hasValue() ) + SetEnableSdremote( *o3tl::doAccess<bool>(pValues[ 24 ]) ); + + if( pValues[25].hasValue() ) + SetEnablePresenterScreen( *o3tl::doAccess<bool>(pValues[ 25 ]) ); + + if( pValues[26].hasValue() ) { + SetTabBarVisible( *o3tl::doAccess<bool>(pValues[ 26 ]) ); + } + } + + return true; +} + +bool SdOptionsMisc::WriteData( Any* pValues ) const +{ + pValues[ 0 ] <<= IsMarkedHitMovesAlways(); + pValues[ 1 ] <<= IsCrookNoContortion(); + pValues[ 2 ] <<= IsQuickEdit(); + pValues[ 3 ] <<= IsMasterPagePaintCaching(); + pValues[ 4 ] <<= IsDragWithCopy(); + pValues[ 5 ] <<= IsPickThrough(); + pValues[ 6 ] <<= IsDoubleClickTextEdit(); + pValues[ 7 ] <<= IsClickChangeRotation(); + // The preview is not supported anymore. Use a dummy value. + pValues[ 8 ] <<= double(0);// GetPreviewQuality(); + pValues[ 9 ] <<= IsSolidDragging(); + pValues[ 10 ] <<= GetDefaultObjectSizeWidth(); + pValues[ 11 ] <<= GetDefaultObjectSizeHeight(); + pValues[ 12 ] <<= GetPrinterIndependentLayout(); + pValues[ 13 ] <<= IsShowComments(); + + // just for Impress + if (IsImpress()) + { + pValues[ 14 ] <<= IsStartWithTemplate(); + pValues[ 15 ] <<= IsSummationOfParagraphs(); + pValues[ 16 ] <<= IsShowUndoDeleteWarning(); + pValues[ 17 ] <<= IsSlideshowRespectZOrder(); + + pValues[ 18 ] <<= IsPreviewNewEffects(); + pValues[ 19 ] <<= IsPreviewChangedEffects(); + pValues[ 20 ] <<= IsPreviewTransitions(); + + pValues[ 21 ] <<= GetDisplay(); + + pValues[ 22 ] <<= GetPresentationPenColor(); + pValues[ 23 ] <<= GetPresentationPenWidth(); + pValues[ 24 ] <<= IsEnableSdremote(); + pValues[ 25 ] <<= IsEnablePresenterScreen(); + pValues[ 26 ] <<= IsTabBarVisible(); + } + + return true; +} + +/************************************************************************* +|* +|* SdOptionsMiscItem +|* +\************************************************************************/ + +SdOptionsMiscItem::SdOptionsMiscItem() +: SfxPoolItem ( ATTR_OPTIONS_MISC ) +, maOptionsMisc ( false, false ) +{ +} + +SdOptionsMiscItem::SdOptionsMiscItem( SdOptions const * pOpts, ::sd::FrameView const * pView ) +: SfxPoolItem ( ATTR_OPTIONS_MISC ) +, maOptionsMisc ( false, false ) +{ + if( pOpts ) + { + maOptionsMisc.SetStartWithTemplate( pOpts->IsStartWithTemplate() ); + maOptionsMisc.SetEnableSdremote( pOpts->IsEnableSdremote() ); + maOptionsMisc.SetEnablePresenterScreen( pOpts->IsEnablePresenterScreen() ); + maOptionsMisc.SetSummationOfParagraphs( pOpts->IsSummationOfParagraphs() ); + maOptionsMisc.SetTabBarVisible( pOpts->IsTabBarVisible() ); + maOptionsMisc.SetShowUndoDeleteWarning( pOpts->IsShowUndoDeleteWarning() ); + maOptionsMisc.SetPrinterIndependentLayout( pOpts->GetPrinterIndependentLayout() ); + maOptionsMisc.SetDefaultObjectSizeWidth( pOpts->GetDefaultObjectSizeWidth() ); + maOptionsMisc.SetDefaultObjectSizeHeight( pOpts->GetDefaultObjectSizeHeight() ); + + maOptionsMisc.SetPreviewNewEffects(pOpts->IsPreviewNewEffects()); + maOptionsMisc.SetPreviewChangedEffects(pOpts->IsPreviewChangedEffects()); + maOptionsMisc.SetPreviewTransitions(pOpts->IsPreviewTransitions()); + + maOptionsMisc.SetDisplay(pOpts->GetDisplay()); + maOptionsMisc.SetShowComments( pOpts->IsShowComments() ); + + maOptionsMisc.SetPresentationPenColor(pOpts->GetPresentationPenColor() ); + maOptionsMisc.SetPresentationPenWidth(pOpts->GetPresentationPenWidth() ); + } + + if( pView ) + { + maOptionsMisc.SetMarkedHitMovesAlways( pView->IsMarkedHitMovesAlways() ); + maOptionsMisc.SetMoveOnlyDragging( pView->IsMoveOnlyDragging() ); + maOptionsMisc.SetCrookNoContortion( pView->IsCrookNoContortion() ); + maOptionsMisc.SetQuickEdit( pView->IsQuickEdit() ); + + // #i26631# + maOptionsMisc.SetMasterPagePaintCaching( pView->IsMasterPagePaintCaching() ); + + maOptionsMisc.SetDragWithCopy( pView->IsDragWithCopy() ); + maOptionsMisc.SetPickThrough( pView->GetModel()->IsPickThroughTransparentTextFrames() ); + maOptionsMisc.SetDoubleClickTextEdit( pView->IsDoubleClickTextEdit() ); + maOptionsMisc.SetClickChangeRotation( pView->IsClickChangeRotation() ); + maOptionsMisc.SetSolidDragging( pView->IsSolidDragging() ); + } + else if( pOpts ) + { + maOptionsMisc.SetMarkedHitMovesAlways( pOpts->IsMarkedHitMovesAlways() ); + maOptionsMisc.SetMoveOnlyDragging( pOpts->IsMoveOnlyDragging() ); + maOptionsMisc.SetCrookNoContortion( pOpts->IsCrookNoContortion() ); + maOptionsMisc.SetQuickEdit( pOpts->IsQuickEdit() ); + maOptionsMisc.SetMasterPagePaintCaching( pOpts->IsMasterPagePaintCaching() ); + maOptionsMisc.SetDragWithCopy( pOpts->IsDragWithCopy() ); + maOptionsMisc.SetPickThrough( pOpts->IsPickThrough() ); + maOptionsMisc.SetDoubleClickTextEdit( pOpts->IsDoubleClickTextEdit() ); + maOptionsMisc.SetClickChangeRotation( pOpts->IsClickChangeRotation() ); + maOptionsMisc.SetSolidDragging( pOpts->IsSolidDragging() ); + } +} + +SdOptionsMiscItem* SdOptionsMiscItem::Clone( SfxItemPool* ) const +{ + return new SdOptionsMiscItem( *this ); +} + +bool SdOptionsMiscItem::operator==( const SfxPoolItem& rAttr ) const +{ + assert(SfxPoolItem::operator==(rAttr)); + return maOptionsMisc == static_cast<const SdOptionsMiscItem&>(rAttr).maOptionsMisc; +} + +void SdOptionsMiscItem::SetOptions( SdOptions* pOpts ) const +{ + if( !pOpts ) + return; + + pOpts->SetStartWithTemplate( maOptionsMisc.IsStartWithTemplate() ); + pOpts->SetMarkedHitMovesAlways( maOptionsMisc.IsMarkedHitMovesAlways() ); + pOpts->SetMoveOnlyDragging( maOptionsMisc.IsMoveOnlyDragging() ); + pOpts->SetCrookNoContortion( maOptionsMisc.IsCrookNoContortion() ); + pOpts->SetQuickEdit( maOptionsMisc.IsQuickEdit() ); + pOpts->SetMasterPagePaintCaching( maOptionsMisc.IsMasterPagePaintCaching() ); + pOpts->SetDragWithCopy( maOptionsMisc.IsDragWithCopy() ); + pOpts->SetPickThrough( maOptionsMisc.IsPickThrough() ); + pOpts->SetDoubleClickTextEdit( maOptionsMisc.IsDoubleClickTextEdit() ); + pOpts->SetClickChangeRotation( maOptionsMisc.IsClickChangeRotation() ); + pOpts->SetEnableSdremote( maOptionsMisc.IsEnableSdremote() ); + pOpts->SetEnablePresenterScreen( maOptionsMisc.IsEnablePresenterScreen() ); + pOpts->SetSummationOfParagraphs( maOptionsMisc.IsSummationOfParagraphs() ); + pOpts->SetTabBarVisible( maOptionsMisc.IsTabBarVisible() ); + + pOpts->SetSolidDragging( maOptionsMisc.IsSolidDragging() ); + pOpts->SetShowUndoDeleteWarning( maOptionsMisc.IsShowUndoDeleteWarning() ); + pOpts->SetPrinterIndependentLayout( maOptionsMisc.GetPrinterIndependentLayout() ); + pOpts->SetShowComments( maOptionsMisc.IsShowComments() ); + pOpts->SetDefaultObjectSizeWidth( maOptionsMisc.GetDefaultObjectSizeWidth() ); + pOpts->SetDefaultObjectSizeHeight( maOptionsMisc.GetDefaultObjectSizeHeight() ); + + pOpts->SetPreviewNewEffects( maOptionsMisc.IsPreviewNewEffects() ); + pOpts->SetPreviewChangedEffects( maOptionsMisc.IsPreviewChangedEffects() ); + pOpts->SetPreviewTransitions( maOptionsMisc.IsPreviewTransitions() ); + + pOpts->SetDisplay( maOptionsMisc.GetDisplay() ); + + pOpts->SetPresentationPenColor( maOptionsMisc.GetPresentationPenColor() ); + pOpts->SetPresentationPenWidth( maOptionsMisc.GetPresentationPenWidth() ); +} + +/************************************************************************* +|* +|* SdOptionsSnap +|* +\************************************************************************/ + +SdOptionsSnap::SdOptionsSnap( bool bImpress, bool bUseConfig ) : + SdOptionsGeneric( bImpress, bUseConfig ? + ( bImpress ? + OUString( "Office.Impress/Snap" ) : + OUString( "Office.Draw/Snap" ) ) : + OUString() ), + bSnapHelplines( true ), + bSnapBorder( true ), + bSnapFrame( false ), + bSnapPoints( false ), + bOrtho( false ), + bBigOrtho( true ), + bRotate( false ), + nSnapArea( 5 ), + nAngle( 1500 ), + nBezAngle( 1500 ) + +{ + EnableModify( true ); +} + +bool SdOptionsSnap::operator==( const SdOptionsSnap& rOpt ) const +{ + return( IsSnapHelplines() == rOpt.IsSnapHelplines() && + IsSnapBorder() == rOpt.IsSnapBorder() && + IsSnapFrame() == rOpt.IsSnapFrame() && + IsSnapPoints() == rOpt.IsSnapPoints() && + IsOrtho() == rOpt.IsOrtho() && + IsBigOrtho() == rOpt.IsBigOrtho() && + IsRotate() == rOpt.IsRotate() && + GetSnapArea() == rOpt.GetSnapArea() && + GetAngle() == rOpt.GetAngle() && + GetEliminatePolyPointLimitAngle() == rOpt.GetEliminatePolyPointLimitAngle() ); +} + +void SdOptionsSnap::GetPropNameArray( const char**& ppNames, sal_uLong& rCount ) const +{ + static const char* aPropNames[] = + { + "Object/SnapLine", + "Object/PageMargin", + "Object/ObjectFrame", + "Object/ObjectPoint", + "Position/CreatingMoving", + "Position/ExtendEdges", + "Position/Rotating", + "Object/Range", + "Position/RotatingValue", + "Position/PointReduction" + }; + + rCount = SAL_N_ELEMENTS(aPropNames); + ppNames = aPropNames; +} + +bool SdOptionsSnap::ReadData( const Any* pValues ) +{ + if( pValues[0].hasValue() ) SetSnapHelplines( *o3tl::doAccess<bool>(pValues[ 0 ]) ); + if( pValues[1].hasValue() ) SetSnapBorder( *o3tl::doAccess<bool>(pValues[ 1 ]) ); + if( pValues[2].hasValue() ) SetSnapFrame( *o3tl::doAccess<bool>(pValues[ 2 ]) ); + if( pValues[3].hasValue() ) SetSnapPoints( *o3tl::doAccess<bool>(pValues[ 3 ]) ); + if( pValues[4].hasValue() ) SetOrtho( *o3tl::doAccess<bool>(pValues[ 4 ]) ); + if( pValues[5].hasValue() ) SetBigOrtho( *o3tl::doAccess<bool>(pValues[ 5 ]) ); + if( pValues[6].hasValue() ) SetRotate( *o3tl::doAccess<bool>(pValues[ 6 ]) ); + if( pValues[7].hasValue() ) SetSnapArea( static_cast<sal_Int16>(*o3tl::doAccess<sal_Int32>(pValues[ 7 ])) ); + if( pValues[8].hasValue() ) SetAngle( static_cast<sal_Int16>(*o3tl::doAccess<sal_Int32>(pValues[ 8 ])) ); + if( pValues[9].hasValue() ) SetEliminatePolyPointLimitAngle( static_cast<sal_Int16>(*o3tl::doAccess<sal_Int32>(pValues[ 9 ])) ); + + return true; +} + +bool SdOptionsSnap::WriteData( Any* pValues ) const +{ + pValues[ 0 ] <<= IsSnapHelplines(); + pValues[ 1 ] <<= IsSnapBorder(); + pValues[ 2 ] <<= IsSnapFrame(); + pValues[ 3 ] <<= IsSnapPoints(); + pValues[ 4 ] <<= IsOrtho(); + pValues[ 5 ] <<= IsBigOrtho(); + pValues[ 6 ] <<= IsRotate(); + pValues[ 7 ] <<= static_cast<sal_Int32>(GetSnapArea()); + pValues[ 8 ] <<= static_cast<sal_Int32>(GetAngle()); + pValues[ 9 ] <<= static_cast<sal_Int32>(GetEliminatePolyPointLimitAngle()); + + return true; +} + +/************************************************************************* +|* +|* SdOptionsSnapItem +|* +\************************************************************************/ + +SdOptionsSnapItem::SdOptionsSnapItem() +: SfxPoolItem ( ATTR_OPTIONS_SNAP ) +, maOptionsSnap ( false, false ) +{ +} + +SdOptionsSnapItem::SdOptionsSnapItem( SdOptions const * pOpts, ::sd::FrameView const * pView ) +: SfxPoolItem ( ATTR_OPTIONS_SNAP ) +, maOptionsSnap ( false, false ) +{ + if( pView ) + { + maOptionsSnap.SetSnapHelplines( pView->IsHlplSnap() ); + maOptionsSnap.SetSnapBorder( pView->IsBordSnap() ); + maOptionsSnap.SetSnapFrame( pView->IsOFrmSnap() ); + maOptionsSnap.SetSnapPoints( pView->IsOPntSnap() ); + maOptionsSnap.SetOrtho( pView->IsOrtho() ); + maOptionsSnap.SetBigOrtho( pView->IsBigOrtho() ); + maOptionsSnap.SetRotate( pView->IsAngleSnapEnabled() ); + maOptionsSnap.SetSnapArea( pView->GetSnapMagneticPixel() ); + maOptionsSnap.SetAngle( static_cast<sal_Int16>(pView->GetSnapAngle()) ); + maOptionsSnap.SetEliminatePolyPointLimitAngle( static_cast<sal_Int16>(pView->GetEliminatePolyPointLimitAngle()) ); + } + else if( pOpts ) + { + maOptionsSnap.SetSnapHelplines( pOpts->IsSnapHelplines() ); + maOptionsSnap.SetSnapBorder( pOpts->IsSnapBorder() ); + maOptionsSnap.SetSnapFrame( pOpts->IsSnapFrame() ); + maOptionsSnap.SetSnapPoints( pOpts->IsSnapPoints() ); + maOptionsSnap.SetOrtho( pOpts->IsOrtho() ); + maOptionsSnap.SetBigOrtho( pOpts->IsBigOrtho() ); + maOptionsSnap.SetRotate( pOpts->IsRotate() ); + maOptionsSnap.SetSnapArea( pOpts->GetSnapArea() ); + maOptionsSnap.SetAngle( pOpts->GetAngle() ); + maOptionsSnap.SetEliminatePolyPointLimitAngle( pOpts->GetEliminatePolyPointLimitAngle() ); + } +} + +SdOptionsSnapItem* SdOptionsSnapItem::Clone( SfxItemPool* ) const +{ + return new SdOptionsSnapItem( *this ); +} + +bool SdOptionsSnapItem::operator==( const SfxPoolItem& rAttr ) const +{ + assert(SfxPoolItem::operator==(rAttr)); + return maOptionsSnap == static_cast<const SdOptionsSnapItem&>(rAttr).maOptionsSnap; +} + +void SdOptionsSnapItem::SetOptions( SdOptions* pOpts ) const +{ + if( !pOpts ) + return; + + pOpts->SetSnapHelplines( maOptionsSnap.IsSnapHelplines() ); + pOpts->SetSnapBorder( maOptionsSnap.IsSnapBorder() ); + pOpts->SetSnapFrame( maOptionsSnap.IsSnapFrame() ); + pOpts->SetSnapPoints( maOptionsSnap.IsSnapPoints() ); + pOpts->SetOrtho( maOptionsSnap.IsOrtho() ); + pOpts->SetBigOrtho( maOptionsSnap.IsBigOrtho() ); + pOpts->SetRotate( maOptionsSnap.IsRotate() ); + pOpts->SetSnapArea( maOptionsSnap.GetSnapArea() ); + pOpts->SetAngle( maOptionsSnap.GetAngle() ); + pOpts->SetEliminatePolyPointLimitAngle( maOptionsSnap.GetEliminatePolyPointLimitAngle() ); +} + +/************************************************************************* +|* +|* SdOptionsZoom +|* +\************************************************************************/ + +SdOptionsZoom::SdOptionsZoom( bool bImpress ) : + SdOptionsGeneric( bImpress, bImpress ? + OUString() : + OUString("Office.Draw/Zoom") ), + nX( 1 ), + nY( 1 ) + +{ + EnableModify( true ); +} + +void SdOptionsZoom::GetPropNameArray( const char**& ppNames, sal_uLong& rCount ) const +{ + static const char* aPropNames[] = + { + "ScaleX", + "ScaleY" + }; + + rCount = !IsImpress() ? SAL_N_ELEMENTS(aPropNames) : 0; + ppNames = aPropNames; +} + +bool SdOptionsZoom::ReadData( const Any* pValues ) +{ + sal_Int32 x = 1, y = 1; + + if( pValues[0].hasValue() ) x = *o3tl::doAccess<sal_Int32>(pValues[ 0 ]); + if( pValues[1].hasValue() ) y = *o3tl::doAccess<sal_Int32>(pValues[ 1 ]); + + SetScale( x, y ); + + return true; +} + +bool SdOptionsZoom::WriteData( Any* pValues ) const +{ + sal_Int32 x, y; + + GetScale( x, y ); + + pValues[ 0 ] <<= x; + pValues[ 1 ] <<= y; + + return true; +} + +/************************************************************************* +|* +|* SdOptionsGrid +|* +\************************************************************************/ + +SdOptionsGrid::SdOptionsGrid(bool bImpress) : + SdOptionsGeneric( bImpress, + bImpress ? + OUString( "Office.Impress/Grid" ) : + OUString( "Office.Draw/Grid" ) + ) +{ + EnableModify( false ); + SetDefaults(); + EnableModify( true ); +} + +SdOptionsGrid::~SdOptionsGrid() +{ +} + +void SdOptionsGrid::SetDefaults() +{ + const sal_uInt32 nVal = 1000; + + SetFieldDivisionX( nVal ); + SetFieldDivisionY( nVal ); + SetFieldDrawX( nVal ); + SetFieldDrawY( nVal ); + SetFieldSnapX( nVal ); + SetFieldSnapY( nVal ); + SetUseGridSnap( false ); + SetSynchronize( true ); + SetGridVisible( false ); + SetEqualGrid( true ); +} + +void SdOptionsGrid::GetPropNameArray( const char**& ppNames, sal_uLong& rCount ) const +{ + if( isMetricSystem() ) + { + static const char* aPropNamesMetric[] = + { + "Resolution/XAxis/Metric", + "Resolution/YAxis/Metric", + "Subdivision/XAxis", + "Subdivision/YAxis", + "SnapGrid/XAxis/Metric", + "SnapGrid/YAxis/Metric", + "Option/SnapToGrid", + "Option/Synchronize", + "Option/VisibleGrid", + "SnapGrid/Size" + }; + ppNames = aPropNamesMetric; + rCount = SAL_N_ELEMENTS(aPropNamesMetric); + } + else + { + static const char* aPropNamesNonMetric[] = + { + "Resolution/XAxis/NonMetric", + "Resolution/YAxis/NonMetric", + "Subdivision/XAxis", + "Subdivision/YAxis", + "SnapGrid/XAxis/NonMetric", + "SnapGrid/YAxis/NonMetric", + "Option/SnapToGrid", + "Option/Synchronize", + "Option/VisibleGrid", + "SnapGrid/Size" + }; + ppNames = aPropNamesNonMetric; + rCount = SAL_N_ELEMENTS(aPropNamesNonMetric); + } +} + +bool SdOptionsGrid::ReadData( const Any* pValues ) +{ + if( pValues[0].hasValue() ) SetFieldDrawX( *o3tl::doAccess<sal_Int32>(pValues[ 0 ]) ); + if( pValues[1].hasValue() ) SetFieldDrawY( *o3tl::doAccess<sal_Int32>(pValues[ 1 ]) ); + + if( pValues[2].hasValue() ) + { + const sal_uInt32 nDivX = FRound( *o3tl::doAccess<double>(pValues[ 2 ]) ); + SetFieldDivisionX( SvxOptionsGrid::GetFieldDrawX() / ( nDivX + 1 ) ); + } + + if( pValues[3].hasValue() ) + { + const sal_uInt32 nDivY = FRound( *o3tl::doAccess<double>(pValues[ 3 ]) ); + SetFieldDivisionY( SvxOptionsGrid::GetFieldDrawY() / ( nDivY + 1 ) ); + } + + if( pValues[4].hasValue() ) SetFieldSnapX( *o3tl::doAccess<sal_Int32>(pValues[ 4 ]) ); + if( pValues[5].hasValue() ) SetFieldSnapY( *o3tl::doAccess<sal_Int32>(pValues[ 5 ]) ); + if( pValues[6].hasValue() ) SetUseGridSnap( *o3tl::doAccess<bool>(pValues[ 6 ]) ); + if( pValues[7].hasValue() ) SetSynchronize( *o3tl::doAccess<bool>(pValues[ 7 ]) ); + if( pValues[8].hasValue() ) SetGridVisible( *o3tl::doAccess<bool>(pValues[ 8 ]) ); + if( pValues[9].hasValue() ) SetEqualGrid( *o3tl::doAccess<bool>(pValues[ 9 ]) ); + + return true; +} + +bool SdOptionsGrid::WriteData( Any* pValues ) const +{ + pValues[ 0 ] <<= static_cast<sal_Int32>(GetFieldDrawX()); + pValues[ 1 ] <<= static_cast<sal_Int32>(GetFieldDrawY()); + pValues[ 2 ] <<= ( GetFieldDivisionX() ? ( static_cast<double>(GetFieldDrawX()) / GetFieldDivisionX() - 1.0 ) : double(0) ); + pValues[ 3 ] <<= ( GetFieldDivisionY() ? ( static_cast<double>(GetFieldDrawY()) / GetFieldDivisionY() - 1.0 ) : double(0) ); + pValues[ 4 ] <<= static_cast<sal_Int32>(GetFieldSnapX()); + pValues[ 5 ] <<= static_cast<sal_Int32>(GetFieldSnapY()); + pValues[ 6 ] <<= IsUseGridSnap(); + pValues[ 7 ] <<= IsSynchronize(); + pValues[ 8 ] <<= IsGridVisible(); + pValues[ 9 ] <<= IsEqualGrid(); + + return true; +} + +/************************************************************************* +|* +|* SdOptionsGridItem +|* +\************************************************************************/ + +SdOptionsGridItem::SdOptionsGridItem( SdOptions const * pOpts ) : + SvxGridItem( SID_ATTR_GRID_OPTIONS ) +{ + SetSynchronize( pOpts->IsSynchronize() ); + SetEqualGrid( pOpts->IsEqualGrid() ); + + SetFieldDrawX( pOpts->GetFieldDrawX() ); + SetFieldDrawY( pOpts->GetFieldDrawY() ); + SetFieldDivisionX( pOpts->GetFieldDivisionX() ? ( pOpts->GetFieldDrawX() / pOpts->GetFieldDivisionX() - 1 ) : 0 ); + SetFieldDivisionY( pOpts->GetFieldDivisionY() ? ( pOpts->GetFieldDrawY() / pOpts->GetFieldDivisionY() - 1 ) : 0 ); + SetFieldSnapX( pOpts->GetFieldSnapX() ); + SetFieldSnapY( pOpts->GetFieldSnapY() ); + SetUseGridSnap( pOpts->IsUseGridSnap() ); + SetGridVisible( pOpts->IsGridVisible() ); +} + +void SdOptionsGridItem::SetOptions( SdOptions* pOpts ) const +{ + pOpts->SetFieldDrawX( GetFieldDrawX() ); + pOpts->SetFieldDivisionX( GetFieldDrawX() / ( GetFieldDivisionX() + 1 ) ); + pOpts->SetFieldDrawY( GetFieldDrawY() ); + pOpts->SetFieldDivisionY( GetFieldDrawY() / ( GetFieldDivisionY() + 1 ) ); + pOpts->SetFieldSnapX( GetFieldSnapX() ); + pOpts->SetFieldSnapY( GetFieldSnapY() ); + pOpts->SetUseGridSnap( GetUseGridSnap() ); + pOpts->SetSynchronize( GetSynchronize() ); + pOpts->SetGridVisible( GetGridVisible() ); + pOpts->SetEqualGrid( GetEqualGrid() ); +} + +/************************************************************************* +|* +|* SdOptionsPrint +|* +\************************************************************************/ + +SdOptionsPrint::SdOptionsPrint( bool bImpress, bool bUseConfig ) : + SdOptionsGeneric( bImpress, bUseConfig ? + ( bImpress ? + OUString( "Office.Impress/Print" ) : + OUString( "Office.Draw/Print" ) ) : + OUString() ), + bDraw( true ), + bNotes( false ), + bHandout( false ), + bOutline( false ), + bDate( false ), + bTime( false ), + bPagename( false ), + bHiddenPages( true ), + bPagesize( false ), + bPagetile( false ), + bWarningPrinter( true ), + bWarningSize( false ), + bWarningOrientation( false ), + bBooklet( false ), + bFront( true ), + bBack( true ), + bCutPage( false ), + bPaperbin( false ), + mbHandoutHorizontal( true ), + mnHandoutPages( 6 ), + nQuality( 0 ) +{ + EnableModify( true ); +} + +bool SdOptionsPrint::operator==( const SdOptionsPrint& rOpt ) const +{ + return( IsDraw() == rOpt.IsDraw() && + IsNotes() == rOpt.IsNotes() && + IsHandout() == rOpt.IsHandout() && + IsOutline() == rOpt.IsOutline() && + IsDate() == rOpt.IsDate() && + IsTime() == rOpt.IsTime() && + IsPagename() == rOpt.IsPagename() && + IsHiddenPages() == rOpt.IsHiddenPages() && + IsPagesize() == rOpt.IsPagesize() && + IsPagetile() == rOpt.IsPagetile() && + IsWarningPrinter() == rOpt.IsWarningPrinter() && + IsWarningSize() == rOpt.IsWarningSize() && + IsWarningOrientation() == rOpt.IsWarningOrientation() && + IsBooklet() == rOpt.IsBooklet() && + IsFrontPage() == rOpt.IsFrontPage() && + IsBackPage() == rOpt.IsBackPage() && + IsCutPage() == rOpt.IsCutPage() && + IsPaperbin() == rOpt.IsPaperbin() && + GetOutputQuality() == rOpt.GetOutputQuality() && + IsHandoutHorizontal() == rOpt.IsHandoutHorizontal() && + GetHandoutPages() == rOpt.GetHandoutPages() ); +} + +void SdOptionsPrint::GetPropNameArray( const char**& ppNames, sal_uLong& rCount ) const +{ + if (IsImpress()) + { + static const char* aImpressPropNames[] = + { + "Other/Date", + "Other/Time", + "Other/PageName", + "Other/HiddenPage", + "Page/PageSize", + "Page/PageTile", + // bWarningPrinter + // bWarningSize + // bWarningOrientation + "Page/Booklet", + "Page/BookletFront", + "Page/BookletBack", + // bCutPage + "Other/FromPrinterSetup", + "Other/Quality", + "Content/Presentation", + "Content/Note", + "Content/Handout", + "Content/Outline", + "Other/HandoutHorizontal", + "Other/PagesPerHandout" + }; + rCount = SAL_N_ELEMENTS(aImpressPropNames); + ppNames = aImpressPropNames; + } + else + { + static const char* aDrawPropNames[] = + { + "Other/Date", + "Other/Time", + "Other/PageName", + "Other/HiddenPage", + "Page/PageSize", + "Page/PageTile", + // bWarningPrinter + // bWarningSize + // bWarningOrientation + "Page/Booklet", + "Page/BookletFront", + "Page/BookletBack", + // bCutPage + "Other/FromPrinterSetup", + "Other/Quality", + "Content/Drawing", + }; + rCount = SAL_N_ELEMENTS(aDrawPropNames); + ppNames = aDrawPropNames; + } +} + +bool SdOptionsPrint::ReadData( const Any* pValues ) +{ + if( pValues[0].hasValue() ) SetDate( *o3tl::doAccess<bool>(pValues[ 0 ]) ); + if( pValues[1].hasValue() ) SetTime( *o3tl::doAccess<bool>(pValues[ 1 ]) ); + if( pValues[2].hasValue() ) SetPagename( *o3tl::doAccess<bool>(pValues[ 2 ]) ); + if( pValues[3].hasValue() ) SetHiddenPages( *o3tl::doAccess<bool>(pValues[ 3 ]) ); + if( pValues[4].hasValue() ) SetPagesize( *o3tl::doAccess<bool>(pValues[ 4 ]) ); + if( pValues[5].hasValue() ) SetPagetile( *o3tl::doAccess<bool>(pValues[ 5 ]) ); + if( pValues[6].hasValue() ) SetBooklet( *o3tl::doAccess<bool>(pValues[ 6 ]) ); + if( pValues[7].hasValue() ) SetFrontPage( *o3tl::doAccess<bool>(pValues[ 7 ]) ); + if( pValues[8].hasValue() ) SetBackPage( *o3tl::doAccess<bool>(pValues[ 8 ]) ); + if( pValues[9].hasValue() ) SetPaperbin( *o3tl::doAccess<bool>(pValues[ 9 ]) ); + if( pValues[10].hasValue() ) SetOutputQuality( static_cast<sal_uInt16>(*o3tl::doAccess<sal_Int32>(pValues[ 10 ])) ); + if( pValues[11].hasValue() ) SetDraw( *o3tl::doAccess<bool>(pValues[ 11 ]) ); + + // just for impress + if (IsImpress()) + { + if( pValues[12].hasValue() ) SetNotes( *o3tl::doAccess<bool>(pValues[ 12 ]) ); + if( pValues[13].hasValue() ) SetHandout( *o3tl::doAccess<bool>(pValues[ 13 ]) ); + if( pValues[14].hasValue() ) SetOutline( *o3tl::doAccess<bool>(pValues[ 14 ]) ); + if( pValues[15].hasValue() ) SetHandoutHorizontal( *o3tl::doAccess<bool>(pValues[15]) ); + if( pValues[16].hasValue() ) SetHandoutPages( static_cast<sal_uInt16>(*o3tl::doAccess<sal_Int32>(pValues[16])) ); + } + + return true; +} + +bool SdOptionsPrint::WriteData( Any* pValues ) const +{ + pValues[ 0 ] <<= IsDate(); + pValues[ 1 ] <<= IsTime(); + pValues[ 2 ] <<= IsPagename(); + pValues[ 3 ] <<= IsHiddenPages(); + pValues[ 4 ] <<= IsPagesize(); + pValues[ 5 ] <<= IsPagetile(); + pValues[ 6 ] <<= IsBooklet(); + pValues[ 7 ] <<= IsFrontPage(); + pValues[ 8 ] <<= IsBackPage(); + pValues[ 9 ] <<= IsPaperbin(); + pValues[ 10 ] <<= static_cast<sal_Int32>(GetOutputQuality()); + pValues[ 11 ] <<= IsDraw(); + + // just for impress + if (IsImpress()) + { + pValues[ 12 ] <<= IsNotes(); + pValues[ 13 ] <<= IsHandout(); + pValues[ 14 ] <<= IsOutline(); + pValues[ 15 ] <<= IsHandoutHorizontal(); + pValues[ 16 ] <<= GetHandoutPages(); + } + + return true; +} + +/************************************************************************* +|* +|* SdOptionsPrintItem +|* +\************************************************************************/ + +SdOptionsPrintItem::SdOptionsPrintItem() +: SfxPoolItem ( ATTR_OPTIONS_PRINT ) +, maOptionsPrint ( false, false ) +{ +} + +SdOptionsPrintItem::SdOptionsPrintItem( SdOptions const * pOpts ) +: SfxPoolItem ( ATTR_OPTIONS_PRINT ) +, maOptionsPrint ( false, false ) +{ + if( !pOpts ) + return; + + maOptionsPrint.SetDraw( pOpts->IsDraw() ); + maOptionsPrint.SetNotes( pOpts->IsNotes() ); + maOptionsPrint.SetHandout( pOpts->IsHandout() ); + maOptionsPrint.SetOutline( pOpts->IsOutline() ); + maOptionsPrint.SetDate( pOpts->IsDate() ); + maOptionsPrint.SetTime( pOpts->IsTime() ); + maOptionsPrint.SetPagename( pOpts->IsPagename() ); + maOptionsPrint.SetHiddenPages( pOpts->IsHiddenPages() ); + maOptionsPrint.SetPagesize( pOpts->IsPagesize() ); + maOptionsPrint.SetPagetile( pOpts->IsPagetile() ); + maOptionsPrint.SetWarningPrinter( pOpts->IsWarningPrinter() ); + maOptionsPrint.SetWarningSize( pOpts->IsWarningSize() ); + maOptionsPrint.SetWarningOrientation( pOpts->IsWarningOrientation() ); + maOptionsPrint.SetBooklet( pOpts->IsBooklet() ); + maOptionsPrint.SetFrontPage( pOpts->IsFrontPage() ); + maOptionsPrint.SetBackPage( pOpts->IsBackPage() ); + maOptionsPrint.SetCutPage( pOpts->IsCutPage() ); + maOptionsPrint.SetPaperbin( pOpts->IsPaperbin() ); + maOptionsPrint.SetOutputQuality( pOpts->GetOutputQuality() ); +} + +SdOptionsPrintItem* SdOptionsPrintItem::Clone( SfxItemPool* ) const +{ + return new SdOptionsPrintItem( *this ); +} + +bool SdOptionsPrintItem::operator==( const SfxPoolItem& rAttr ) const +{ + assert(SfxPoolItem::operator==(rAttr)); + return maOptionsPrint == static_cast<const SdOptionsPrintItem&>(rAttr).maOptionsPrint; +} + +void SdOptionsPrintItem::SetOptions( SdOptions* pOpts ) const +{ + if( !pOpts ) + return; + + pOpts->SetDraw( maOptionsPrint.IsDraw() ); + pOpts->SetNotes( maOptionsPrint.IsNotes() ); + pOpts->SetHandout( maOptionsPrint.IsHandout() ); + pOpts->SetOutline( maOptionsPrint.IsOutline() ); + pOpts->SetDate( maOptionsPrint.IsDate() ); + pOpts->SetTime( maOptionsPrint.IsTime() ); + pOpts->SetPagename( maOptionsPrint.IsPagename() ); + pOpts->SetHiddenPages( maOptionsPrint.IsHiddenPages() ); + pOpts->SetPagesize( maOptionsPrint.IsPagesize() ); + pOpts->SetPagetile( maOptionsPrint.IsPagetile() ); + pOpts->SetWarningPrinter( maOptionsPrint.IsWarningPrinter() ); + pOpts->SetWarningSize( maOptionsPrint.IsWarningSize() ); + pOpts->SetWarningOrientation( maOptionsPrint.IsWarningOrientation() ); + pOpts->SetBooklet( maOptionsPrint.IsBooklet() ); + pOpts->SetFrontPage( maOptionsPrint.IsFrontPage() ); + pOpts->SetBackPage( maOptionsPrint.IsBackPage() ); + pOpts->SetCutPage( maOptionsPrint.IsCutPage() ); + pOpts->SetPaperbin( maOptionsPrint.IsPaperbin() ); + pOpts->SetOutputQuality( maOptionsPrint.GetOutputQuality() ); +} + +/************************************************************************* +|* +|* SdOptions +|* +\************************************************************************/ + +SdOptions::SdOptions(bool bImpress) : + SdOptionsLayout( bImpress, true ), + SdOptionsContents( bImpress ), + SdOptionsMisc( bImpress, true ), + SdOptionsSnap( bImpress, true ), + SdOptionsZoom( bImpress ), + SdOptionsGrid( bImpress ), + SdOptionsPrint( bImpress, true ) +{ +} + +SdOptions::~SdOptions() +{ +} + +void SdOptions::StoreConfig() +{ + SdOptionsLayout::Store(); + SdOptionsContents::Store(); + SdOptionsMisc::Store(); + SdOptionsSnap::Store(); + SdOptionsZoom::Store(); + SdOptionsGrid::Store(); + SdOptionsPrint::Store(); +} + +sal_Int32 SdOptionsMisc::GetDisplay() const +{ + Init(); + return mnDisplay; +} + +void SdOptionsMisc::SetDisplay( sal_Int32 nDisplay ) +{ + if( mnDisplay != nDisplay ) + { + OptionsChanged(); + mnDisplay = nDisplay; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/app/sddll.cxx b/sd/source/ui/app/sddll.cxx new file mode 100644 index 000000000..bb52a9722 --- /dev/null +++ b/sd/source/ui/app/sddll.cxx @@ -0,0 +1,274 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_features.h> + +#include <avmedia/mediaplayer.hxx> +#include <avmedia/mediatoolbox.hxx> +#include <unotools/configmgr.hxx> +#include <unotools/moduleoptions.hxx> +#include <svx/fmobjfac.hxx> +#include <svx/objfac3d.hxx> +#include <vcl/svapp.hxx> + +#include <registerinterfaces.hxx> +#include <sddll.hxx> +#include <app.hrc> +#include <AnimationChildWindow.hxx> +#include <BezierObjectBar.hxx> +#include <diactrl.hxx> +#include <DrawDocShell.hxx> +#include <FactoryIds.hxx> +#include <gluectrl.hxx> +#include <GraphicDocShell.hxx> +#include <GraphicObjectBar.hxx> +#include <GraphicViewShell.hxx> +#include <GraphicViewShellBase.hxx> +#include <ImpressViewShellBase.hxx> +#include <PresentationViewShell.hxx> +#include <PresentationViewShellBase.hxx> +#include <MediaObjectBar.hxx> +#include <NavigatorChildWindow.hxx> +#include <OutlineViewShell.hxx> +#include <OutlineViewShellBase.hxx> +#include <PaneChildWindows.hxx> +#include <SpellDialogChildWindow.hxx> +#include <SlideSorterViewShell.hxx> +#include <SlideSorterViewShellBase.hxx> +#include <SdShapeTypes.hxx> +#include <TextObjectBar.hxx> +#include <tmplctrl.hxx> + +#include <svx/svxids.hrc> +#include <svx/bmpmask.hxx> +#include <svx/clipboardctl.hxx> +#include <svx/f3dchild.hxx> +#include <svx/fillctrl.hxx> +#include <svx/fontwork.hxx> +#include <svx/formatpaintbrushctrl.hxx> +#include <svx/ParaLineSpacingPopup.hxx> +#include <svx/TextCharacterSpacingPopup.hxx> +#include <svx/TextUnderlinePopup.hxx> +#include <svx/grafctrl.hxx> +#include <svx/hyperdlg.hxx> +#include <svx/imapdlg.hxx> +#include <svx/layctrl.hxx> +#include <svx/lboxctrl.hxx> +#include <svx/linectrl.hxx> +#include <svx/modctrl.hxx> +#include <svx/pszctrl.hxx> +#include <svx/srchdlg.hxx> +#include <svx/SvxColorChildWindow.hxx> +#include <svx/tbcontrl.hxx> +#include <svx/verttexttbxctrl.hxx> +#include <svx/xmlsecctrl.hxx> +#include <svx/zoomctrl.hxx> +#include <svx/zoomsliderctrl.hxx> +#include <svx/tbxctl.hxx> +#include <sfx2/emojipopup.hxx> +#include <sfx2/charmappopup.hxx> +#include <sfx2/sidebar/SidebarChildWindow.hxx> +#include <comphelper/lok.hxx> +#include <sdabstdlg.hxx> +#include <sdfilter.hxx> +#include <sdmod.hxx> + +using namespace ::com::sun::star; + +// Register all Factories +void SdDLL::RegisterFactorys() +{ + if (utl::ConfigManager::IsFuzzing() || SvtModuleOptions().IsImpress()) + { + ::sd::ImpressViewShellBase::RegisterFactory ( + ::sd::IMPRESS_FACTORY_ID); + ::sd::SlideSorterViewShellBase::RegisterFactory ( + ::sd::SLIDE_SORTER_FACTORY_ID); + ::sd::OutlineViewShellBase::RegisterFactory ( + ::sd::OUTLINE_FACTORY_ID); + ::sd::PresentationViewShellBase::RegisterFactory ( + ::sd::PRESENTATION_FACTORY_ID); + } + if (!utl::ConfigManager::IsFuzzing() && SvtModuleOptions().IsDraw()) + { + ::sd::GraphicViewShellBase::RegisterFactory (::sd::DRAW_FACTORY_ID); + } +} + +// Register all Interfaces + +void SdDLL::RegisterInterfaces(SdModule* pMod) +{ + // Module + SdModule::RegisterInterface(pMod); + + // View shell base. + ::sd::ViewShellBase::RegisterInterface(pMod); + + // DocShells + ::sd::DrawDocShell::RegisterInterface(pMod); + ::sd::GraphicDocShell::RegisterInterface(pMod); + + // Impress ViewShells + ::sd::DrawViewShell::RegisterInterface(pMod); + ::sd::OutlineViewShell::RegisterInterface(pMod); + ::sd::PresentationViewShell::RegisterInterface(pMod); + + // Draw ViewShell + ::sd::GraphicViewShell::RegisterInterface(pMod); + + // Impress ObjectShells + ::sd::BezierObjectBar::RegisterInterface(pMod); + ::sd::TextObjectBar::RegisterInterface(pMod); + ::sd::GraphicObjectBar::RegisterInterface(pMod); + + // Media ObjectShell + ::sd::MediaObjectBar::RegisterInterface(pMod); + + // Table ObjectShell + ::sd::ui::table::RegisterInterfaces(pMod); + + // View shells for the side panes. + ::sd::slidesorter::SlideSorterViewShell::RegisterInterface (pMod); +} + +// Register all Controllers + +void SdDLL::RegisterControllers(SdModule* pMod) +{ + SdTbxCtlDiaPages::RegisterControl( SID_PAGES_PER_ROW, pMod ); + SdTbxCtlGlueEscDir::RegisterControl( SID_GLUE_ESCDIR, pMod ); + + ::sd::AnimationChildWindow::RegisterChildWindow(false, pMod); + ::sd::NavigatorChildWindow::RegisterChildWindowContext( static_cast<sal_uInt16>(::sd::DrawViewShell::GetInterfaceId()), pMod ); + ::sd::NavigatorChildWindow::RegisterChildWindowContext( static_cast<sal_uInt16>(::sd::GraphicViewShell::GetInterfaceId()), pMod ); + + Svx3DChildWindow::RegisterChildWindow(false, pMod); + SvxFontWorkChildWindow::RegisterChildWindow(false, pMod); + SvxColorChildWindow::RegisterChildWindow(false, pMod, SfxChildWindowFlags::TASK); + SvxSearchDialogWrapper::RegisterChildWindow(false, pMod); + SvxBmpMaskChildWindow::RegisterChildWindow(false, pMod); + SvxIMapDlgChildWindow::RegisterChildWindow(false, pMod); + SvxHlinkDlgWrapper::RegisterChildWindow(false, pMod); + ::sd::SpellDialogChildWindow::RegisterChildWindow( + false, pMod, comphelper::LibreOfficeKit::isActive() ? SfxChildWindowFlags::NEVERCLONE + : SfxChildWindowFlags::NONE); +#if HAVE_FEATURE_AVMEDIA + ::avmedia::MediaPlayer::RegisterChildWindow(false, pMod); +#endif + ::sd::LeftPaneImpressChildWindow::RegisterChildWindow(false, pMod); + ::sd::LeftPaneDrawChildWindow::RegisterChildWindow(false, pMod); + ::sfx2::sidebar::SidebarChildWindow::RegisterChildWindow(false, pMod); + + SvxFillToolBoxControl::RegisterControl(0, pMod); + SvxLineWidthToolBoxControl::RegisterControl(0, pMod); + + SvxGrafModeToolBoxControl::RegisterControl( SID_ATTR_GRAF_MODE, pMod ); + SvxGrafRedToolBoxControl::RegisterControl( SID_ATTR_GRAF_RED, pMod ); + SvxGrafGreenToolBoxControl::RegisterControl( SID_ATTR_GRAF_GREEN, pMod ); + SvxGrafBlueToolBoxControl::RegisterControl( SID_ATTR_GRAF_BLUE, pMod ); + SvxGrafLuminanceToolBoxControl::RegisterControl( SID_ATTR_GRAF_LUMINANCE, pMod ); + SvxGrafContrastToolBoxControl::RegisterControl( SID_ATTR_GRAF_CONTRAST, pMod ); + SvxGrafGammaToolBoxControl::RegisterControl( SID_ATTR_GRAF_GAMMA, pMod ); + SvxGrafTransparenceToolBoxControl::RegisterControl( SID_ATTR_GRAF_TRANSPARENCE, pMod ); + + // register StatusBarControls + SvxZoomPageStatusBarControl::RegisterControl( SID_ZOOM_ENTIRE_PAGE, pMod ); + SvxZoomStatusBarControl::RegisterControl( SID_ATTR_ZOOM, pMod ); + SvxPosSizeStatusBarControl::RegisterControl( SID_ATTR_SIZE, pMod ); + SvxModifyControl::RegisterControl( SID_DOC_MODIFIED, pMod ); + SvxZoomSliderControl::RegisterControl( SID_ATTR_ZOOMSLIDER, pMod ); + + svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod ); + + SvxClipBoardControl::RegisterControl( SID_PASTE, pMod ); + SvxClipBoardControl::RegisterControl( SID_PASTE_UNFORMATTED, pMod ); + +#if HAVE_FEATURE_AVMEDIA + ::avmedia::MediaToolBoxControl::RegisterControl( SID_AVMEDIA_TOOLBOX, pMod ); +#endif + XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE, pMod ); + SdTemplateControl::RegisterControl( SID_STATUS_LAYOUT, pMod ); + SvxTbxCtlDraw::RegisterControl(SID_INSERT_DRAW, pMod ); +} + +void SdDLL::Init() +{ + if ( SfxApplication::GetModule(SfxToolsModule::Draw) ) // Module already active + return; + + SfxObjectFactory* pDrawFact = nullptr; + SfxObjectFactory* pImpressFact = nullptr; + + if (utl::ConfigManager::IsFuzzing() || SvtModuleOptions().IsImpress()) + pImpressFact = &::sd::DrawDocShell::Factory(); + + if (!utl::ConfigManager::IsFuzzing() && SvtModuleOptions().IsDraw()) + pDrawFact = &::sd::GraphicDocShell::Factory(); + + auto pUniqueModule = std::make_unique<SdModule>(pImpressFact, pDrawFact); + SdModule* pModule = pUniqueModule.get(); + SfxApplication::SetModule(SfxToolsModule::Draw, std::move(pUniqueModule)); + + if (!utl::ConfigManager::IsFuzzing() && SvtModuleOptions().IsImpress()) + { + // Register the Impress shape types in order to make the shapes accessible. + ::accessibility::RegisterImpressShapeTypes (); + ::sd::DrawDocShell::Factory().SetDocumentServiceName( "com.sun.star.presentation.PresentationDocument" ); + } + + if (!utl::ConfigManager::IsFuzzing() && SvtModuleOptions().IsDraw()) + { + ::sd::GraphicDocShell::Factory().SetDocumentServiceName( "com.sun.star.drawing.DrawingDocument" ); + } + + // register your view-factories here + RegisterFactorys(); + + // register your shell-interfaces here + RegisterInterfaces(pModule); + + // register your controllers here + RegisterControllers(pModule); + + // register 3D-object-factory + E3dObjFactory(); + + // register css::form::component::Form-Object-Factory + FmFormObjFactory(); + + // register your exotic remote controls here +#ifdef ENABLE_SDREMOTE + if (!utl::ConfigManager::IsFuzzing() && !Application::IsHeadlessModeEnabled()) + RegisterRemotes(); +#endif +} + +#ifndef DISABLE_DYNLOADING + +extern "C" SAL_DLLPUBLIC_EXPORT +void lok_preload_hook() +{ + SdFilter::Preload(); + SdAbstractDialogFactory::Create(); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/app/sdmod.cxx b/sd/source/ui/app/sdmod.cxx new file mode 100644 index 000000000..27fea87ae --- /dev/null +++ b/sd/source/ui/app/sdmod.cxx @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <unotools/pathoptions.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/resmgr.hxx> +#include <tools/urlobj.hxx> +#include <vcl/virdev.hxx> +#include <vcl/svapp.hxx> +#include <svl/intitem.hxx> +#include <sfx2/msg.hxx> +#include <sfx2/objface.hxx> +#include <svl/zforlist.hxx> +#include <comphelper/processfactory.hxx> +#include <svtools/ehdl.hxx> + +#include <svx/svxids.hrc> +#include <svl/srchitem.hxx> +#include <svx/svxerr.hxx> + +#include <svtools/colorcfg.hxx> + +#include <sdmod.hxx> +#include <sdresid.hxx> +#include <optsitem.hxx> +#include <DrawDocShell.hxx> +#include <drawdoc.hxx> +#include <errhdl.hrc> + +#define ShellClass_SdModule +#include <sdslots.hxx> + +SFX_IMPL_INTERFACE(SdModule, SfxModule) + +void SdModule::InitInterface_Impl() +{ + GetStaticInterface()->RegisterStatusBar(StatusBarId::DrawStatusBar); +} + +// Ctor +SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 ) +: SfxModule("sd", {pFact1, pFact2}), + pTransferClip(nullptr), + pTransferDrag(nullptr), + pTransferSelection(nullptr), + pImpressOptions(nullptr), + pDrawOptions(nullptr), + bWaterCan(false), + mbEventListenerAdded(false), + mpColorConfig(new svtools::ColorConfig) +{ + SetName( "StarDraw" ); // Do not translate! + pSearchItem.reset( new SvxSearchItem(SID_SEARCH_ITEM) ); + pSearchItem->SetAppFlag(SvxSearchApp::DRAW); + StartListening( *SfxGetpApp() ); + SvxErrorHandler::ensure(); + mpErrorHdl.reset( new SfxErrorHandler(RID_SD_ERRHDL, ErrCodeArea::Sd, ErrCodeArea::Sd, GetResLocale()) ); + + // Create a new ref device and (by calling SetReferenceDevice()) + // set its resolution to 600 DPI. This leads to a visually better + // formatting of text in small sizes (6 point and below.) + mpVirtualRefDevice.reset(VclPtr<VirtualDevice>::Create()); + mpVirtualRefDevice->SetMapMode(MapMode(MapUnit::Map100thMM)); + mpVirtualRefDevice->SetReferenceDevice ( VirtualDevice::RefDevMode::Dpi600 ); +} + +OUString SdResId(const char* pId) +{ + return Translate::get(pId, SD_MOD()->GetResLocale()); +} + +OUString SdResId(const char* pId, int nCardinality) +{ + return Translate::nget(pId, nCardinality, SD_MOD()->GetResLocale()); +} + +// Dtor +SdModule::~SdModule() +{ + pSearchItem.reset(); + pNumberFormatter.reset(); + + if (mbEventListenerAdded) + { + Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) ); + } + + mpErrorHdl.reset(); + mpVirtualRefDevice.disposeAndClear(); +} + +void SdModule::SetSearchItem(std::unique_ptr<SvxSearchItem> pItem) +{ + pSearchItem = std::move(pItem); +} + +/// get notifications +void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint ) +{ + if( rHint.GetId() == SfxHintId::Deinitializing ) + { + delete pImpressOptions; + pImpressOptions = nullptr; + delete pDrawOptions; + pDrawOptions = nullptr; + } +} + +/// Return options +SdOptions* SdModule::GetSdOptions(DocumentType eDocType) +{ + SdOptions* pOptions = nullptr; + + if (eDocType == DocumentType::Draw) + { + if (!pDrawOptions) + pDrawOptions = new SdOptions(false); + + pOptions = pDrawOptions; + } + else if (eDocType == DocumentType::Impress) + { + if (!pImpressOptions) + pImpressOptions = new SdOptions(true); + + pOptions = pImpressOptions; + } + if( pOptions ) + { + sal_uInt16 nMetric = pOptions->GetMetric(); + + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + SdDrawDocument* pDoc = nullptr; + if (pDocSh) + pDoc = pDocSh->GetDoc(); + + if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() ) + PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) ); + } + + return pOptions; +} + +/** + * Open and return option stream for internal options; + * if the stream is opened for reading but does not exist, an 'empty' + * RefObject is returned + */ +tools::SvRef<SotStorageStream> SdModule::GetOptionStream( const OUString& rOptionName, + SdOptionStreamMode eMode ) +{ + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + tools::SvRef<SotStorageStream> xStm; + + if( pDocSh ) + { + DocumentType eType = pDocSh->GetDoc()->GetDocumentType(); + + if( !xOptionStorage.is() ) + { + INetURLObject aURL( SvtPathOptions().GetUserConfigPath() ); + + aURL.Append( "drawing.cfg" ); + + std::unique_ptr<SvStream> pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE ); + + if( pStm ) + xOptionStorage = new SotStorage( pStm.release(), true ); + } + + OUString aStmName; + + if( DocumentType::Draw == eType ) + aStmName = "Draw_"; + else + aStmName = "Impress_"; + + aStmName += rOptionName; + + if( SdOptionStreamMode::Store == eMode || xOptionStorage->IsContained( aStmName ) ) + xStm = xOptionStorage->OpenSotStream( aStmName ); + } + + return xStm; +} + +SvNumberFormatter* SdModule::GetNumberFormatter() +{ + if( !pNumberFormatter ) + pNumberFormatter.reset( new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM ) ); + + return pNumberFormatter.get(); +} + +svtools::ColorConfig& SdModule::GetColorConfig() +{ + return *mpColorConfig; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/app/sdmod1.cxx b/sd/source/ui/app/sdmod1.cxx new file mode 100644 index 000000000..ea9d4b695 --- /dev/null +++ b/sd/source/ui/app/sdmod1.cxx @@ -0,0 +1,630 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <svl/lckbitem.hxx> +#include <svl/intitem.hxx> +#include <sfx2/frame.hxx> +#include <sfx2/viewfrm.hxx> +#include <unotools/moduleoptions.hxx> +#include <framework/FrameworkHelper.hxx> + +#include <vcl/commandevent.hxx> +#include <vcl/svapp.hxx> +#include <vcl/errinf.hxx> +#include <editeng/langitem.hxx> +#include <vcl/weld.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/request.hxx> +#include <sfx2/templatedlg.hxx> +#include <editeng/eeitem.hxx> + +#include <svx/svxids.hrc> +#include <strings.hrc> + +#include <sdmod.hxx> +#include <pres.hxx> +#include <optsitem.hxx> +#include <ViewShell.hxx> +#include <DrawDocShell.hxx> +#include <drawdoc.hxx> +#include <sdresid.hxx> +#include <OutlineView.hxx> +#include <OutlineViewShell.hxx> +#include <ViewShellBase.hxx> +#include <FactoryIds.hxx> +#include <memory> +#include <slideshow.hxx> + +using ::sd::framework::FrameworkHelper; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::frame::XFrame; + +namespace { + +class OutlineToImpressFinalizer final +{ +public: + OutlineToImpressFinalizer ( + ::sd::ViewShellBase& rBase, + SdDrawDocument& rDocument, + SvLockBytes const & rBytes); + void operator() (bool bEventSeen); +private: + ::sd::ViewShellBase& mrBase; + SdDrawDocument& mrDocument; + std::shared_ptr<SvMemoryStream> mpStream; +}; + +} //end of anonymous namespace + +void SdModule::Execute(SfxRequest& rReq) +{ + const SfxItemSet* pSet = rReq.GetArgs(); + sal_uLong nSlotId = rReq.GetSlot(); + + switch ( nSlotId ) + { + case SID_NEWDOC: + { + SfxGetpApp()->ExecuteSlot(rReq, SfxGetpApp()->GetInterface()); + } + break; + + case SID_AUTOSPELL_CHECK: + { + // automatic spell checker + const SfxPoolItem* pItem; + if( pSet && SfxItemState::SET == pSet->GetItemState( + SID_AUTOSPELL_CHECK, false, &pItem ) ) + { + bool bOnlineSpelling = static_cast<const SfxBoolItem*>( pItem )->GetValue(); + // save at document: + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if( pDocSh ) + { + SdDrawDocument* pDoc = pDocSh->GetDoc(); + pDoc->SetOnlineSpell( bOnlineSpelling ); + } + } + } + break; + + case SID_ATTR_METRIC: + { + const SfxPoolItem* pItem; + if ( pSet && SfxItemState::SET == pSet->GetItemState( SID_ATTR_METRIC, true, &pItem ) ) + { + FieldUnit eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); + switch( eUnit ) + { + case FieldUnit::MM: // only the units which are also in the dialog + case FieldUnit::CM: + case FieldUnit::INCH: + case FieldUnit::PICA: + case FieldUnit::POINT: + { + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if(pDocSh) + { + DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType(); + + PutItem( *pItem ); + SdOptions* pOptions = GetSdOptions( eDocType ); + if(pOptions) + pOptions->SetMetric( static_cast<sal_uInt16>(eUnit) ); + rReq.Done(); + } + } + break; + default: + break; + } + } + + } + break; + + case SID_ATTR_LANGUAGE: + case SID_ATTR_CHAR_CJK_LANGUAGE: + case SID_ATTR_CHAR_CTL_LANGUAGE: + { + const SfxPoolItem* pItem; + if( pSet && + ( + SfxItemState::SET == pSet->GetItemState(SID_ATTR_LANGUAGE, false, &pItem ) || + SfxItemState::SET == pSet->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE, false, &pItem ) || + SfxItemState::SET == pSet->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE, false, &pItem ) + ) + ) + { + // save at the document: + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if ( pDocSh ) + { + LanguageType eLanguage = static_cast<const SvxLanguageItem*>(pItem)->GetValue(); + SdDrawDocument* pDoc = pDocSh->GetDoc(); + + if( nSlotId == SID_ATTR_CHAR_CJK_LANGUAGE ) + pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CJK ); + else if( nSlotId == SID_ATTR_CHAR_CTL_LANGUAGE ) + pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CTL ); + else + pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE ); + + if( pDoc->GetOnlineSpell() ) + { + pDoc->StopOnlineSpelling(); + pDoc->StartOnlineSpelling(); + } + } + } + } + break; + + case SID_NEWSD: + { + SfxFrame* pFrame = ExecuteNewDocument( rReq ); + // if a frame was created, set it as return value + if(pFrame) + rReq.SetReturnValue(SfxFrameItem(0, pFrame)); + } + + break; + + case SID_OPENHYPERLINK: + case SID_OPENDOC: + { + bool bIntercept = false; + ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if (pDocShell) + { + ::sd::ViewShell* pViewShell = pDocShell->GetViewShell(); + if (pViewShell) + { + if( sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ) ) + { + // Prevent documents from opening while the slide + // show is running, except when this request comes + // from a shape interaction. + if (rReq.GetArgs() == nullptr) + { + bIntercept = true; + } + } + } + } + + if (!bIntercept) + { + SfxGetpApp()->ExecuteSlot(rReq, SfxGetpApp()->GetInterface()); + } + else + { + std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(nullptr, + VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_CANT_PERFORM_IN_LIVEMODE))); + + xErrorBox->run(); + + const SfxLinkItem* pLinkItem = rReq.GetArg<SfxLinkItem>(SID_DONELINK); + if( pLinkItem ) + pLinkItem->GetValue().Call( nullptr ); + } + } + break; + + case SID_OUTLINE_TO_IMPRESS: + OutlineToImpress (rReq); + break; + + default: + break; + } +} + +bool SdModule::OutlineToImpress(SfxRequest const & rRequest) +{ + const SfxItemSet* pSet = rRequest.GetArgs(); + + if (pSet) + { + SvLockBytes* pBytes = static_cast<const SfxLockBytesItem&>(pSet->Get(SID_OUTLINE_TO_IMPRESS)).GetValue(); + + if (pBytes) + { + SfxObjectShellLock xDocShell; + ::sd::DrawDocShell* pDocSh; + xDocShell = pDocSh = new ::sd::DrawDocShell( + SfxObjectCreateMode::STANDARD, false, DocumentType::Impress); + + pDocSh->DoInitNew(); + SdDrawDocument* pDoc = pDocSh->GetDoc(); + if(pDoc) + { + pDoc->CreateFirstPages(); + pDoc->StopWorkStartupDelay(); + } + + const SfxFrameItem* pFrmItem = rRequest.GetArg<SfxFrameItem>(SID_DOCFRAME); + SfxViewFrame::LoadDocumentIntoFrame( *pDocSh, pFrmItem, ::sd::OUTLINE_FACTORY_ID ); + + ::sd::ViewShell* pViewSh = pDocSh->GetViewShell(); + + if (pViewSh && pDoc) + { + // AutoLayouts have to be finished + pDoc->StopWorkStartupDelay(); + + SfxViewFrame* pViewFrame = pViewSh->GetViewFrame(); + + // When the view frame has not been just created we have + // to switch synchronously to the outline view. + // (Otherwise the request will be ignored anyway.) + ::sd::ViewShellBase* pBase + = dynamic_cast< ::sd::ViewShellBase*>(pViewFrame->GetViewShell()); + if (pBase != nullptr) + { + std::shared_ptr<FrameworkHelper> pHelper ( + FrameworkHelper::Instance(*pBase)); + pHelper->RequestView( + FrameworkHelper::msOutlineViewURL, + FrameworkHelper::msCenterPaneURL); + + pHelper->RunOnResourceActivation( + FrameworkHelper::CreateResourceId( + FrameworkHelper::msOutlineViewURL, + FrameworkHelper::msCenterPaneURL), + OutlineToImpressFinalizer(*pBase, *pDoc, *pBytes)); + } + } + } + } + + return rRequest.IsDone(); +} + +void SdModule::GetState(SfxItemSet& rItemSet) +{ + if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_METRIC ) ) + { + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if(pDocSh) + { + DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType(); + + SdOptions* pOptions = GetSdOptions(eDocType); + rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, pOptions->GetMetric() ) ); + } + } + + // state of SID_OPENDOC is determined by the base class + if (rItemSet.GetItemState(SID_OPENDOC) != SfxItemState::UNKNOWN) + { + const SfxPoolItem* pItem = SfxGetpApp()->GetSlotState(SID_OPENDOC, SfxGetpApp()->GetInterface()); + if (pItem) + rItemSet.Put(*pItem); + } + + // state of SID_OPENHYPERLINK is determined by the base class + if (rItemSet.GetItemState(SID_OPENHYPERLINK) != SfxItemState::UNKNOWN) + { + const SfxPoolItem* pItem = SfxGetpApp()->GetSlotState(SID_OPENHYPERLINK, SfxGetpApp()->GetInterface()); + if (pItem) + rItemSet.Put(*pItem); + } + + if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_AUTOSPELL_CHECK ) ) + { + ::sd::DrawDocShell* pDocSh = + dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if( pDocSh ) + { + SdDrawDocument* pDoc = pDocSh->GetDoc(); + rItemSet.Put( SfxBoolItem( SID_AUTOSPELL_CHECK, pDoc->GetOnlineSpell() ) ); + } + } + + if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_LANGUAGE ) ) + { + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if( pDocSh ) + rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE ) ); + } + + if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE ) ) + { + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if( pDocSh ) + rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CJK ), SID_ATTR_CHAR_CJK_LANGUAGE ) ); + } + + if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE ) ) + { + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if( pDocSh ) + rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CTL ), SID_ATTR_CHAR_CTL_LANGUAGE ) ); + } + + if ( mbEventListenerAdded ) + return; + + ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if( pDocShell ) // Impress or Draw ? + { + ::sd::ViewShell* pViewShell = pDocShell->GetViewShell(); + + if( pViewShell && (pDocShell->GetDocumentType() == DocumentType::Impress) ) + { + // add our event listener as soon as possible + Application::AddEventListener( LINK( this, SdModule, EventListenerHdl ) ); + mbEventListenerAdded = true; + } + } +} + +IMPL_STATIC_LINK( SdModule, EventListenerHdl, VclSimpleEvent&, rSimpleEvent, void ) +{ + if( !((rSimpleEvent.GetId() == VclEventId::WindowCommand) && static_cast<VclWindowEvent*>(&rSimpleEvent)->GetData()) ) + return; + + const CommandEvent& rEvent = *static_cast<const CommandEvent*>(static_cast<VclWindowEvent*>(&rSimpleEvent)->GetData()); + + if( rEvent.GetCommand() != CommandEventId::Media ) + return; + + CommandMediaData* pMediaData = rEvent.GetMediaData(); + pMediaData->SetPassThroughToOS(false); + switch (pMediaData->GetMediaId()) + { + case MediaCommand::Play: + { + ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + if( pDocShell ) // Impress or Draw ? + { + ::sd::ViewShell* pViewShell = pDocShell->GetViewShell(); + + // #i97925# start the presentation if and only if an Impress document is focused + if( pViewShell && (pDocShell->GetDocumentType() == DocumentType::Impress) ) + pViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_PRESENTATION ); + } + break; + } + default: + pMediaData->SetPassThroughToOS(true); + break; + } +} + + +SfxFrame* SdModule::CreateFromTemplate(const OUString& rTemplatePath, const Reference<XFrame>& i_rFrame, + const bool bReplaceable) +{ + SfxFrame* pFrame = nullptr; + + SfxObjectShellLock xDocShell; + + std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet( SfxGetpApp()->GetPool() )); + pSet->Put( SfxBoolItem( SID_TEMPLATE, true ) ); + + ErrCode lErr = SfxGetpApp()->LoadTemplate( xDocShell, rTemplatePath, std::move(pSet) ); + + SfxObjectShell* pDocShell = xDocShell; + + if( lErr ) + { + ErrorHandler::HandleError(lErr); + } + else if( pDocShell ) + { + if (pDocShell->GetMedium() && pDocShell->GetMedium()->GetItemSet()) + pDocShell->GetMedium()->GetItemSet()->Put(SfxBoolItem(SID_REPLACEABLE, bReplaceable)); + SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pDocShell, i_rFrame ); + OSL_ENSURE( pViewFrame, "SdModule::CreateFromTemplate: no view frame - was the document really loaded?" ); + pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr; + } + + return pFrame; + +} + +SfxFrame* SdModule::ExecuteNewDocument( SfxRequest const & rReq ) +{ + SfxFrame* pFrame = nullptr; + if ( SvtModuleOptions().IsImpress() ) + { + Reference< XFrame > xTargetFrame; + const SfxUnoFrameItem* pFrmItem = rReq.GetArg<SfxUnoFrameItem>(SID_FILLFRAME); + if ( pFrmItem ) + xTargetFrame = pFrmItem->GetFrame(); + + SdOptions* pOpt = GetSdOptions(DocumentType::Impress); + bool bStartWithTemplate = pOpt->IsStartWithTemplate(); + + bool bNewDocDirect = rReq.GetSlot() == SID_NEWSD; + + if( bNewDocDirect ) + { + //we start without wizard + + //check whether we should load a template document + const OUString aServiceName( "com.sun.star.presentation.PresentationDocument" ); + OUString aStandardTemplate( SfxObjectFactory::GetStandardTemplate( aServiceName ) ); + + if( !aStandardTemplate.isEmpty() ) + { + //load a template document + pFrame = CreateFromTemplate(aStandardTemplate, xTargetFrame, true); + } + else + { + //create an empty document + pFrame = CreateEmptyDocument( xTargetFrame ); + } + } + + if(bStartWithTemplate) + { + //Launch TemplateSelectionDialog + vcl::Window* pTopLevel = SfxGetpApp()->GetTopWindow(); + SfxTemplateSelectionDlg aTemplDlg(pTopLevel ? pTopLevel->GetFrameWeld() : nullptr); + aTemplDlg.run(); + + //check to disable the dialog + pOpt->SetStartWithTemplate( aTemplDlg.IsStartWithTemplate() ); + + //pFrame is loaded with the desired template + if (!aTemplDlg.getTemplatePath().isEmpty()) + pFrame = CreateFromTemplate(aTemplDlg.getTemplatePath(), xTargetFrame, false); + } + } + + return pFrame; +} + +SfxFrame* SdModule::CreateEmptyDocument( const Reference< XFrame >& i_rFrame ) +{ + SfxFrame* pFrame = nullptr; + + SfxObjectShellLock xDocShell; + ::sd::DrawDocShell* pNewDocSh; + xDocShell = pNewDocSh = new ::sd::DrawDocShell(SfxObjectCreateMode::STANDARD,false,DocumentType::Impress); + pNewDocSh->DoInitNew(); + SdDrawDocument* pDoc = pNewDocSh->GetDoc(); + if (pDoc) + { + pDoc->CreateFirstPages(); + pDoc->StopWorkStartupDelay(); + } + if (pNewDocSh->GetMedium() && pNewDocSh->GetMedium()->GetItemSet()) + pNewDocSh->GetMedium()->GetItemSet()->Put(SfxBoolItem(SID_REPLACEABLE, true)); + + SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pNewDocSh, i_rFrame ); + OSL_ENSURE( pViewFrame, "SdModule::CreateEmptyDocument: no view frame - was the document really loaded?" ); + pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr; + + return pFrame; +} + +//===== OutlineToImpressFinalize ============================================== + +namespace { + +OutlineToImpressFinalizer::OutlineToImpressFinalizer ( + ::sd::ViewShellBase& rBase, + SdDrawDocument& rDocument, + SvLockBytes const & rBytes) + : mrBase(rBase), + mrDocument(rDocument), + mpStream() +{ + // The given stream has a lifetime shorter than this new + // OutlineToImpressFinalizer object. Therefore a local copy of the + // stream is created. + const SvStream* pStream (rBytes.GetStream()); + if (pStream == nullptr) + return; + + // Create a memory stream and prepare to fill it with the content of + // the original stream. + mpStream = std::make_shared<SvMemoryStream>(); + static const std::size_t nBufferSize = 4096; + ::std::unique_ptr<sal_Int8[]> pBuffer (new sal_Int8[nBufferSize]); + + sal_uInt64 nReadPosition(0); + bool bLoop (true); + while (bLoop) + { + // Read the next part of the original stream. + std::size_t nReadByteCount (0); + const ErrCode nErrorCode ( + rBytes.ReadAt( + nReadPosition, + pBuffer.get(), + nBufferSize, + &nReadByteCount)); + + // Check the error code and stop copying the stream data when an + // error has occurred. + if (nErrorCode == ERRCODE_NONE) + { + if (nReadByteCount == 0) + bLoop = false; + } + else if (nErrorCode == ERRCODE_IO_PENDING) + ; + else + { + bLoop = false; + nReadByteCount = 0; + } + + // Append the read bytes to the end of the memory stream. + if (nReadByteCount > 0) + { + mpStream->WriteBytes(pBuffer.get(), nReadByteCount); + nReadPosition += nReadByteCount; + } + } + + // Rewind the memory stream so that in the operator() method its + // content is properly read. + mpStream->Seek(STREAM_SEEK_TO_BEGIN); +} + +void OutlineToImpressFinalizer::operator() (bool) +{ + // Fetch the new outline view shell. + ::sd::OutlineViewShell* pOutlineShell + = dynamic_cast<sd::OutlineViewShell*>(FrameworkHelper::Instance(mrBase)->GetViewShell(FrameworkHelper::msCenterPaneURL).get()); + + if (pOutlineShell != nullptr && mpStream != nullptr) + { + sd::OutlineView* pView = static_cast<sd::OutlineView*>(pOutlineShell->GetView()); + // mba: the stream can't contain any relative URLs, because we don't + // have any information about a BaseURL! + pOutlineShell->ReadRtf(*mpStream); + + // Call UpdatePreview once for every slide to resync the + // document with the outliner of the OutlineViewShell. + sal_uInt16 nPageCount (mrDocument.GetSdPageCount(PageKind::Standard)); + for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++) + { + SdPage* pPage = mrDocument.GetSdPage(nIndex, PageKind::Standard); + // Make the page the actual page so that the + // following UpdatePreview() call accesses the + // correct paragraphs. + pView->SetActualPage(pPage); + pOutlineShell->UpdatePreview(pPage); + } + // Select the first slide. + SdPage* pPage = mrDocument.GetSdPage(0, PageKind::Standard); + pView->SetActualPage(pPage); + pOutlineShell->UpdatePreview(pPage); + } + + // Undo-Stack needs to be cleared, else the user may remove the + // only drawpage and this is a state we cannot handle ATM. + ::sd::DrawDocShell* pDocShell = mrDocument.GetDocSh(); + if( pDocShell ) + pDocShell->ClearUndoBuffer(); +} + +} // end of anonymous namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx new file mode 100644 index 000000000..b94015b94 --- /dev/null +++ b/sd/source/ui/app/sdmod2.cxx @@ -0,0 +1,816 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <editeng/flditem.hxx> +#include <editeng/CustomPropertyField.hxx> +#include <sfx2/printer.hxx> +#include <sfx2/styfitem.hxx> +#include <svl/inethist.hxx> +#include <svl/poolitem.hxx> +#include <svl/flagitem.hxx> +#include <unotools/useroptions.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/docfile.hxx> + +#include <editeng/measfld.hxx> +#include <editeng/editstat.hxx> + +#include <svx/svxids.hrc> +#include <svx/dialogs.hrc> +#include <svx/svdotext.hxx> + +#include <sfx2/sfxdlg.hxx> + +#include <sdmod.hxx> +#include <app.hrc> +#include <family.hrc> +#include <strings.hrc> +#include <sdattr.hrc> + +#include <bitmaps.hlst> +#include <ViewShell.hxx> +#include <FrameView.hxx> +#include <optsitem.hxx> +#include <DrawDocShell.hxx> +#include <drawdoc.hxx> +#include <Outliner.hxx> +#include <sdresid.hxx> +#include <pres.hxx> +#include <OutlineViewShell.hxx> +#include <OutlineView.hxx> +#include <ViewShellBase.hxx> +#include <sdpage.hxx> +#include <sdabstdlg.hxx> +#include <svl/intitem.hxx> + +/** retrieves the page that is currently painted. This will only be the master page + if the current drawn view only shows the master page*/ +static SdPage* GetCurrentPage( sd::ViewShell const * pViewSh, EditFieldInfo const * pInfo, bool& bMasterView ) +{ + if( !pInfo ) + return nullptr; + + bMasterView = false; + SdPage* pPage = dynamic_cast< SdPage* >( pInfo->GetSdrPage() ); + SdrOutliner* pOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() ); + + // special case, someone already set the current page on the EditFieldInfo + // This is used from the svx::UnoGraphicsExporter f.e. + if( pPage ) + { + bMasterView = false; + return pPage; + } + + // first try to check if we are inside the outline view + sd::OutlineView* pSdView = nullptr; + if( auto pOutlineViewShell = dynamic_cast<const sd::OutlineViewShell* >(pViewSh) ) + pSdView = static_cast<sd::OutlineView*>(pOutlineViewShell->GetView()); + + if (pSdView != nullptr && (pOutliner == &pSdView->GetOutliner())) + { + // outline mode + int nPgNum = 0; + Outliner& rOutl = pSdView->GetOutliner(); + long nPos = pInfo->GetPara(); + sal_Int32 nParaPos = 0; + + for( Paragraph* pPara = rOutl.GetParagraph( 0 ); pPara && nPos >= 0; pPara = rOutl.GetParagraph( ++nParaPos ), nPos-- ) + { + if( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) ) + nPgNum++; + } + + pPage = pViewSh->GetDoc()->GetSdPage( static_cast<sal_uInt16>(nPgNum), PageKind::Standard ); + } + else + { + // draw mode, slide mode and preview. Get the processed page from the outliner + if(pOutliner) + { + pPage = dynamic_cast< SdPage* >(const_cast< SdrPage* >(pOutliner->getVisualizedPage())); + } + + // The path using GetPaintingPageView() and GetCurrentPaintingDisplayInfo() + // is no longer needed. I debugged and checked all usages of PageNumber decompositions + // which all use the new possibility of setting the visualized page at the SdrOutliner. + + // if all else failed, geht the current page from the object that is + // currently formatted from the document + if(!pPage) + { + const SdrTextObj* pTextObj = (pViewSh && pViewSh->GetDoc()) ? pViewSh->GetDoc()->GetFormattingTextObj() : nullptr; + + if( pTextObj ) + { + pPage = dynamic_cast< SdPage* >( pTextObj->getSdrPageFromSdrObject() ); + } + } + + if(pPage) + { + bMasterView = pPage->IsMasterPage(); + } + } + + return pPage; +} + +/** + * Link for CalcFieldValue of Outliners + */ +IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, pInfo, void) +{ + if (!pInfo) + return; + + const SvxFieldData* pField = pInfo->GetField().GetField(); + ::sd::DrawDocShell* pDocShell = nullptr; + SdDrawDocument* pDoc = nullptr; + + SdrOutliner* pSdrOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() ); + if( pSdrOutliner ) + { + const SdrTextObj* pTextObj = pSdrOutliner->GetTextObj(); + + if( pTextObj ) + pDoc = dynamic_cast< SdDrawDocument* >( &pTextObj->getSdrModelFromSdrObject() ); + + if( pDoc ) + pDocShell = pDoc->GetDocSh(); + } + + if( !pDocShell ) + pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + + const SvxDateField* pDateField = nullptr; + const SvxExtTimeField* pExtTimeField = nullptr; + const SvxExtFileField* pExtFileField = nullptr; + const SvxAuthorField* pAuthorField = nullptr; + const SvxURLField* pURLField = nullptr; + + const editeng::CustomPropertyField* pCustomPropertyField = nullptr; + + if( (pDateField = dynamic_cast< const SvxDateField* >(pField)) != nullptr ) + { + LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() ); + pInfo->SetRepresentation( pDateField->GetFormatted( *GetNumberFormatter(), eLang ) ); + } + else if( (pExtTimeField = dynamic_cast< const SvxExtTimeField *>(pField)) != nullptr ) + { + LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() ); + pInfo->SetRepresentation( pExtTimeField->GetFormatted( *GetNumberFormatter(), eLang ) ); + } + else if( (pExtFileField = dynamic_cast< const SvxExtFileField * >(pField)) != nullptr ) + { + if( pDocShell && (pExtFileField->GetType() != SvxFileType::Fix) ) + { + OUString aName; + if( pDocShell->HasName() ) + aName = pDocShell->GetMedium()->GetName(); + else + aName = pDocShell->GetName(); + + const_cast< SvxExtFileField* >(pExtFileField)->SetFile( aName ); + } + pInfo->SetRepresentation( pExtFileField->GetFormatted() ); + + } + else if( (pAuthorField = dynamic_cast< const SvxAuthorField* >( pField )) != nullptr ) + { + if( pAuthorField->GetType() != SvxAuthorType::Fix ) + { + SvtUserOptions aUserOptions; + SvxAuthorField aAuthorField( + aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID(), + pAuthorField->GetType(), pAuthorField->GetFormat() ); + + *const_cast< SvxAuthorField* >(pAuthorField) = aAuthorField; + } + pInfo->SetRepresentation( pAuthorField->GetFormatted() ); + + } + else if( dynamic_cast< const SvxPageField* >(pField) ) + { + OUString aRepresentation(" "); + + ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr; + if(pViewSh == nullptr) + { + ::sd::ViewShellBase* pBase = dynamic_cast< ::sd::ViewShellBase *>( SfxViewShell::Current() ); + if(pBase) + pViewSh = pBase->GetMainViewShell().get(); + } + if( !pDoc && pViewSh ) + pDoc = pViewSh->GetDoc(); + + bool bMasterView; + SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView ); + + if( pPage && pDoc && !bMasterView ) + { + int nPgNum; + + if( (pPage->GetPageKind() == PageKind::Handout) && pViewSh ) + { + nPgNum = pViewSh->GetPrintedHandoutPageNum(); + } + else + { + nPgNum = (pPage->GetPageNum() - 1) / 2 + 1; + } + aRepresentation = pDoc->CreatePageNumValue(static_cast<sal_uInt16>(nPgNum)); + } + else + aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_NUMBER); + + pInfo->SetRepresentation( aRepresentation ); + } + else if( dynamic_cast< const SvxPageTitleField* >(pField) ) + { + OUString aRepresentation(" "); + + ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr; + if(pViewSh == nullptr) + { + ::sd::ViewShellBase* pBase = dynamic_cast< ::sd::ViewShellBase *>( SfxViewShell::Current() ); + if(pBase) + pViewSh = pBase->GetMainViewShell().get(); + } + if( !pDoc && pViewSh ) + pDoc = pViewSh->GetDoc(); + + bool bMasterView; + SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView ); + + if( pPage && pDoc && !bMasterView ) + { + aRepresentation = pPage->GetName(); + } + else + { + DocumentType eDocType = pDoc ? pDoc->GetDocumentType() : DocumentType::Impress; + aRepresentation = ( ( eDocType == DocumentType::Impress ) + ? SdResId(STR_FIELD_PLACEHOLDER_SLIDENAME) + : SdResId(STR_FIELD_PLACEHOLDER_PAGENAME) ); + } + + pInfo->SetRepresentation( aRepresentation ); + } + else if( dynamic_cast< const SvxPagesField* >(pField) ) + { + OUString aRepresentation(" "); + + ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr; + if(pViewSh == nullptr) + { + ::sd::ViewShellBase* pBase = dynamic_cast< ::sd::ViewShellBase *>( SfxViewShell::Current() ); + if(pBase) + pViewSh = pBase->GetMainViewShell().get(); + } + if( !pDoc && pViewSh ) + pDoc = pViewSh->GetDoc(); + + bool bMasterView; + SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView ); + + sal_uInt16 nPageCount = 0; + + if( !bMasterView ) + { + if( pPage && (pPage->GetPageKind() == PageKind::Handout) && pViewSh ) + { + nPageCount = pViewSh->GetPrintedHandoutPageCount(); + } + else if( pDoc ) + { + nPageCount = pDoc->GetActiveSdPageCount(); + } + } + + if( nPageCount > 0 ) + aRepresentation = pDoc->CreatePageNumValue(nPageCount); + else + aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_COUNT); + + pInfo->SetRepresentation( aRepresentation ); + } + else if( (pURLField = dynamic_cast< const SvxURLField* >(pField)) != nullptr ) + { + switch ( pURLField->GetFormat() ) + { + case SvxURLFormat::AppDefault: //!!! adjustable at App??? + case SvxURLFormat::Repr: + pInfo->SetRepresentation( pURLField->GetRepresentation() ); + break; + + case SvxURLFormat::Url: + pInfo->SetRepresentation( pURLField->GetURL() ); + break; + } + + const OUString& aURL = pURLField->GetURL(); + + svtools::ColorConfig aConfig; + svtools::ColorConfigEntry eEntry = + INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS; + pInfo->SetTextColor( aConfig.GetColorValue(eEntry).nColor ); + } + else if ( dynamic_cast< const SdrMeasureField* >(pField)) + { + pInfo->SetFieldColor(std::optional<Color>()); // clear the field color + } + else if ((pCustomPropertyField = dynamic_cast<const editeng::CustomPropertyField*>(pField)) != nullptr) + { + try + { + if (SfxObjectShell::Current() && SfxObjectShell::Current()->IsLoadingFinished()) + { + auto pNonConstCustomPropertyField = const_cast<editeng::CustomPropertyField*>(pCustomPropertyField); + OUString sCurrent = pNonConstCustomPropertyField->GetFormatted(SfxObjectShell::Current()->getDocProperties()); + pInfo->SetRepresentation(sCurrent); + } + else + pInfo->SetRepresentation(pCustomPropertyField->GetCurrentPresentation()); + } + catch (...) + { + pInfo->SetRepresentation(pCustomPropertyField->GetCurrentPresentation()); + } + } + else + { + OUString aRepresentation; + + bool bHeaderField = dynamic_cast< const SvxHeaderField* >( pField ) != nullptr; + bool bFooterField = !bHeaderField && (dynamic_cast< const SvxFooterField* >( pField ) != nullptr ); + bool bDateTimeField = !bHeaderField && !bFooterField && (dynamic_cast< const SvxDateTimeField* >( pField ) != nullptr); + + if( bHeaderField || bFooterField || bDateTimeField ) + { + sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr; + bool bMasterView = false; + SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView ); + + if( (pPage == nullptr) || bMasterView ) + { + if( bHeaderField ) + aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_HEADER); + else if (bFooterField ) + aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_FOOTER); + else if (bDateTimeField ) + aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_DATETIME); + } + else + { + const sd::HeaderFooterSettings &rSettings = pPage->getHeaderFooterSettings(); + + if( bHeaderField ) + { + aRepresentation = rSettings.maHeaderText; + } + else if( bFooterField ) + { + aRepresentation = rSettings.maFooterText; + } + else if( bDateTimeField ) + { + if( rSettings.mbDateTimeIsFixed ) + { + aRepresentation = rSettings.maDateTimeText; + } + else + { + DateTime aDateTime( DateTime::SYSTEM ); + LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() ); + aRepresentation = SvxDateTimeField::GetFormatted( aDateTime, aDateTime, + rSettings.meDateFormat, rSettings.meTimeFormat, *GetNumberFormatter(), eLang ); + } + } + } + } + else + { + OSL_FAIL("sd::SdModule::CalcFieldValueHdl(), unknown field type!"); + } + + if( aRepresentation.isEmpty() ) // TODO: Edit engine doesn't handle empty fields? + aRepresentation = " "; + pInfo->SetRepresentation( aRepresentation ); + } +} + +/** + * virtual methods for option dialog + */ +std::unique_ptr<SfxItemSet> SdModule::CreateItemSet( sal_uInt16 nSlot ) +{ + ::sd::FrameView* pFrameView = nullptr; + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + SdDrawDocument* pDoc = nullptr; + + // Here we set the DocType of the option dialog (not document!) + DocumentType eDocType = DocumentType::Impress; + if( nSlot == SID_SD_GRAPHIC_OPTIONS ) + eDocType = DocumentType::Draw; + + if (pDocSh) + { + pDoc = pDocSh->GetDoc(); + + // If the option dialog is identical to the document type, + // we can pass the FrameView too: + if( pDoc && eDocType == pDoc->GetDocumentType() ) + pFrameView = pDocSh->GetFrameView(); + + ::sd::ViewShell* pViewShell = pDocSh->GetViewShell(); + if (pViewShell != nullptr) + pViewShell->WriteFrameViewData(); + } + + SdOptions* pOptions = GetSdOptions(eDocType); + + // Pool has by default MapUnit Twips (Awgh!) + SfxItemPool& rPool = GetPool(); + rPool.SetDefaultMetric( MapUnit::Map100thMM ); + + auto pRet = std::make_unique<SfxItemSet>( + rPool, + svl::Items< + SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS, + SID_ATTR_METRIC, SID_ATTR_METRIC, + SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP, + ATTR_OPTIONS_LAYOUT, ATTR_OPTIONS_SCALE_END>{}); + + // TP_OPTIONS_LAYOUT: + pRet->Put( SdOptionsLayoutItem( pOptions, pFrameView ) ); + + sal_uInt16 nDefTab = 0; + if( pFrameView) + nDefTab = pDoc->GetDefaultTabulator(); + else + nDefTab = pOptions->GetDefTab(); + pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, nDefTab ) ); + + FieldUnit nMetric = FieldUnit(0xffff); + if( pFrameView) + nMetric = pDoc->GetUIUnit(); + else + nMetric = static_cast<FieldUnit>(pOptions->GetMetric()); + + if( nMetric == FieldUnit(0xffff) ) + nMetric = GetFieldUnit(); + + pRet->Put( SfxUInt16Item( SID_ATTR_METRIC, static_cast<sal_uInt16>(nMetric) ) ); + + // TP_OPTIONS_MISC: + SdOptionsMiscItem aSdOptionsMiscItem( pOptions, pFrameView ); + if ( pFrameView ) + { + aSdOptionsMiscItem.GetOptionsMisc().SetSummationOfParagraphs( pDoc->IsSummationOfParagraphs() ); + aSdOptionsMiscItem.GetOptionsMisc().SetPrinterIndependentLayout ( + static_cast<sal_uInt16>(pDoc->GetPrinterIndependentLayout())); + } + pRet->Put( aSdOptionsMiscItem ); + + // TP_OPTIONS_SNAP: + pRet->Put( SdOptionsSnapItem( pOptions, pFrameView ) ); + + // TP_SCALE: + sal_uInt32 nW = 10; + sal_uInt32 nH = 10; + sal_Int32 nX; + sal_Int32 nY; + if( pDocSh ) + { + SdrPage* pPage = pDoc->GetSdPage(0, PageKind::Standard); + Size aSize(pPage->GetSize()); + nW = aSize.Width(); + nH = aSize.Height(); + } + + if(pFrameView) + { + const Fraction& rFraction = pDoc->GetUIScale(); + nX=rFraction.GetNumerator(); + nY=rFraction.GetDenominator(); + } + else + { + // Get options from configuration file + pOptions->GetScale( nX, nY ); + } + + pRet->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) ); + pRet->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) ); + pRet->Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_WIDTH, nW ) ); + pRet->Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_HEIGHT, nH ) ); + + // TP_OPTIONS_PRINT: + pRet->Put( SdOptionsPrintItem( pOptions ) ); + + // RID_SVXPAGE_GRID: + pRet->Put( SdOptionsGridItem( pOptions ) ); + + return pRet; +} +void SdModule::ApplyItemSet( sal_uInt16 nSlot, const SfxItemSet& rSet ) +{ + const SfxPoolItem* pItem = nullptr; + bool bNewDefTab = false; + bool bNewPrintOptions = false; + bool bMiscOptions = false; + + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + SdDrawDocument* pDoc = nullptr; + // Here we set the DocType of the option dialog (not document!) + DocumentType eDocType = DocumentType::Impress; + if( nSlot == SID_SD_GRAPHIC_OPTIONS ) + eDocType = DocumentType::Draw; + + ::sd::ViewShell* pViewShell = nullptr; + + if (pDocSh) + { + pDoc = pDocSh->GetDoc(); + + pViewShell = pDocSh->GetViewShell(); + if (pViewShell != nullptr) + pViewShell->WriteFrameViewData(); + } + SdOptions* pOptions = GetSdOptions(eDocType); + // Grid + if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , + false, &pItem )) + { + const SdOptionsGridItem* pGridItem = static_cast<const SdOptionsGridItem*>(pItem); + pGridItem->SetOptions( pOptions ); + } + + // Layout + const SdOptionsLayoutItem* pLayoutItem = nullptr; + if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_LAYOUT, + false, reinterpret_cast<const SfxPoolItem**>(&pLayoutItem) )) + { + pLayoutItem->SetOptions( pOptions ); + } + + // Metric + if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_METRIC, false, &pItem ) ) + { + if( pDoc && eDocType == pDoc->GetDocumentType() ) + PutItem( *pItem ); + pOptions->SetMetric( static_cast<const SfxUInt16Item*>( pItem )->GetValue() ); + } + sal_uInt16 nDefTab = pOptions->GetDefTab(); + // Default-Tabulator + if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_DEFTABSTOP, false, &pItem ) ) + { + nDefTab = static_cast<const SfxUInt16Item*>( pItem )->GetValue(); + pOptions->SetDefTab( nDefTab ); + + bNewDefTab = true; + } + + // Scale + if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_SCALE_X, false, &pItem ) ) + { + sal_Int32 nX = static_cast<const SfxInt32Item*>( pItem )->GetValue(); + if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_SCALE_Y, false, &pItem ) ) + { + sal_Int32 nY = static_cast<const SfxInt32Item*>( pItem )->GetValue(); + pOptions->SetScale( nX, nY ); + + // Apply to document only if doc type match + if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() ) + { + pDoc->SetUIScale( Fraction( nX, nY ) ); + if( pViewShell ) + pViewShell->SetRuler( pViewShell->HasRuler() ); + } + } + } + + // Misc + const SdOptionsMiscItem* pMiscItem = nullptr; + if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_MISC, + false, reinterpret_cast<const SfxPoolItem**>(&pMiscItem) )) + { + pMiscItem->SetOptions( pOptions ); + bMiscOptions = true; + } + + // Snap + const SdOptionsSnapItem* pSnapItem = nullptr; + if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_SNAP, + false, reinterpret_cast<const SfxPoolItem**>(&pSnapItem) )) + { + pSnapItem->SetOptions( pOptions ); + } + + SfxItemSet aPrintSet( GetPool(), + svl::Items<SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN, + SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC, + ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT>{} ); + + // Print + const SdOptionsPrintItem* pPrintItem = nullptr; + if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_PRINT, + false, reinterpret_cast<const SfxPoolItem**>(&pPrintItem) )) + { + pPrintItem->SetOptions( pOptions ); + + // set PrintOptionsSet + SdOptionsPrintItem aPrintItem( pOptions ); + SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC ); + SfxPrinterChangeFlags nFlags = + (aPrintItem.GetOptionsPrint().IsWarningSize() ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE) | + (aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE); + aFlagItem.SetValue( static_cast<int>(nFlags) ); + + aPrintSet.Put( aPrintItem ); + aPrintSet.Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) ); + aPrintSet.Put( aFlagItem ); + + bNewPrintOptions = true; + } + + // Only if also the document type matches... + if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() ) + { + if( bNewPrintOptions ) + { + pDocSh->GetPrinter(true)->SetOptions( aPrintSet ); + } + + // set DefTab at Model + if( bNewDefTab ) + { + SdDrawDocument* pDocument = pDocSh->GetDoc(); + pDocument->SetDefaultTabulator( nDefTab ); + + SdOutliner* pOutl = pDocument->GetOutliner( false ); + if( pOutl ) + pOutl->SetDefTab( nDefTab ); + + SdOutliner* pInternalOutl = pDocument->GetInternalOutliner( false ); + if( pInternalOutl ) + pInternalOutl->SetDefTab( nDefTab ); + } + if ( bMiscOptions ) + { + pDoc->SetSummationOfParagraphs( pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() ); + EEControlBits nSum = pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() ? EEControlBits::ULSPACESUMMATION : EEControlBits::NONE; + EEControlBits nCntrl; + + SdDrawDocument* pDocument = pDocSh->GetDoc(); + SdrOutliner& rOutl = pDocument->GetDrawOutliner(); + nCntrl = rOutl.GetControlWord() &~ EEControlBits::ULSPACESUMMATION; + rOutl.SetControlWord( nCntrl | nSum ); + SdOutliner* pOutl = pDocument->GetOutliner( false ); + if( pOutl ) + { + nCntrl = pOutl->GetControlWord() &~ EEControlBits::ULSPACESUMMATION; + pOutl->SetControlWord( nCntrl | nSum ); + } + pOutl = pDocument->GetInternalOutliner( false ); + if( pOutl ) + { + nCntrl = pOutl->GetControlWord() &~ EEControlBits::ULSPACESUMMATION; + pOutl->SetControlWord( nCntrl | nSum ); + } + + // Set printer independent layout mode. + if( pDoc->GetPrinterIndependentLayout() != pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout() ) + pDoc->SetPrinterIndependentLayout (pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout()); + } + } + + pOptions->StoreConfig(); + + // Only if also the document type matches... + if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() ) + { + FieldUnit eUIUnit = static_cast<FieldUnit>(pOptions->GetMetric()); + pDoc->SetUIUnit(eUIUnit); + + if (pViewShell) + { + // make sure no one is in text edit mode, cause there + // are some pointers remembered else (!) + if(pViewShell->GetView()) + pViewShell->GetView()->SdrEndTextEdit(); + + ::sd::FrameView* pFrame = pViewShell->GetFrameView(); + pFrame->Update(pOptions); + pViewShell->ReadFrameViewData(pFrame); + pViewShell->SetUIUnit(eUIUnit); + pViewShell->SetDefTabHRuler( nDefTab ); + } + } + + if( pViewShell && pViewShell->GetViewFrame() ) + pViewShell->GetViewFrame()->GetBindings().InvalidateAll( true ); +} + +std::unique_ptr<SfxTabPage> SdModule::CreateTabPage( sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet ) +{ + std::unique_ptr<SfxTabPage> xRet; + SfxAllItemSet aSet(*(rSet.GetPool())); + SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); + + switch(nId) + { + case SID_SD_TP_CONTENTS: + case SID_SI_TP_CONTENTS: + { + ::CreateTabPage fnCreatePage = pFact->GetSdOptionsContentsTabPageCreatorFunc(); + if( fnCreatePage ) + xRet = (*fnCreatePage)( pPage, pController, &rSet ); + } + break; + case SID_SD_TP_SNAP: + case SID_SI_TP_SNAP: + { + ::CreateTabPage fnCreatePage = pFact->GetSdOptionsSnapTabPageCreatorFunc(); + if( fnCreatePage ) + xRet = (*fnCreatePage)( pPage, pController, &rSet ); + } + break; + case SID_SD_TP_PRINT: + case SID_SI_TP_PRINT: + { + ::CreateTabPage fnCreatePage = pFact->GetSdPrintOptionsTabPageCreatorFunc(); + if( fnCreatePage ) + { + xRet = (*fnCreatePage)( pPage, pController, &rSet ); + if(SID_SD_TP_PRINT == nId) + aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE)); + xRet->PageCreated(aSet); + } + } + break; + case SID_SI_TP_MISC: + case SID_SD_TP_MISC: + { + ::CreateTabPage fnCreatePage = pFact->GetSdOptionsMiscTabPageCreatorFunc(); + if( fnCreatePage ) + { + xRet = (*fnCreatePage)( pPage, pController, &rSet ); + if(SID_SD_TP_MISC == nId) + aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE)); + else + aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_IMPRESS_MODE)); + xRet->PageCreated(aSet); + } + } + break; + case RID_SVXPAGE_TEXTANIMATION : + { + SfxAbstractDialogFactory* pSfxFact = SfxAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pSfxFact->GetTabPageCreatorFunc( nId ); + if ( fnCreatePage ) + xRet = (*fnCreatePage)( pPage, pController, &rSet ); + } + break; + } + DBG_ASSERT( xRet, "SdModule::CreateTabPage(): no valid ID for TabPage!" ); + + return xRet; +} + +std::unique_ptr<SfxStyleFamilies> SdModule::CreateStyleFamilies() +{ + std::unique_ptr<SfxStyleFamilies> pStyleFamilies(new SfxStyleFamilies); + + pStyleFamilies->emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Para, + SdResId(STR_GRAPHICS_STYLE_FAMILY), + BMP_STYLES_FAMILY_GRAPHICS, + RID_GRAPHICSTYLEFAMILY, SD_MOD()->GetResLocale())); + + pStyleFamilies->emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Pseudo, + SdResId(STR_PRESENTATIONS_STYLE_FAMILY), + BMP_STYLES_FAMILY_PRESENTATIONS, + RID_PRESENTATIONSTYLEFAMILY, SD_MOD()->GetResLocale())); + + return pStyleFamilies; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/app/sdpopup.cxx b/sd/source/ui/app/sdpopup.cxx new file mode 100644 index 000000000..eeadaef35 --- /dev/null +++ b/sd/source/ui/app/sdpopup.cxx @@ -0,0 +1,300 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <editeng/flditem.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/docfile.hxx> +#include <unotools/useroptions.hxx> + +#include <strings.hrc> +#include <sdpopup.hxx> +#include <sdresid.hxx> +#include <sdmod.hxx> +#include <DrawDocShell.hxx> + +/* + * Popup menu for editing of field command + */ +SdFieldPopup::SdFieldPopup( const SvxFieldData* pInField, LanguageType eLanguage ) : + PopupMenu (), + pField ( pInField ) +{ + Fill( eLanguage ); +} + +SdFieldPopup::~SdFieldPopup() +{ +} + +void SdFieldPopup::Fill( LanguageType eLanguage ) +{ + sal_uInt16 nID = 1; + MenuItemBits nStyle = MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK; + InsertItem( nID++, SdResId( STR_FIX ), nStyle ); + InsertItem( nID++, SdResId( STR_VAR ), nStyle ); + InsertSeparator(); + + if( dynamic_cast< const SvxDateField *>( pField ) != nullptr ) + { + const SvxDateField* pDateField = static_cast<const SvxDateField*>( pField ); + SvxDateField aDateField( *pDateField ); + + if( pDateField->GetType() == SvxDateType::Fix ) + CheckItem( 1 ); + else + CheckItem( 2 ); + + //SvxDateFormat::AppDefault, // is not used + //SvxDateFormat::System, // is not used + InsertItem( nID++, SdResId( STR_STANDARD_SMALL ), nStyle ); + InsertItem( nID++, SdResId( STR_STANDARD_BIG ), nStyle ); + + SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter(); + aDateField.SetFormat( SvxDateFormat::A ); // 13.02.96 + InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aDateField.SetFormat( SvxDateFormat::B ); // 13.02.1996 + InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aDateField.SetFormat( SvxDateFormat::C ); // 13.Feb 1996 + InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + + aDateField.SetFormat( SvxDateFormat::D ); // 13.Februar 1996 + InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aDateField.SetFormat( SvxDateFormat::E ); // Die, 13.Februar 1996 + InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aDateField.SetFormat( SvxDateFormat::F ); // Dienstag, 13.Februar 1996 + InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + + CheckItem( static_cast<sal_uInt16>( pDateField->GetFormat() ) + 1 ); // - 2 + 3 ! + } + else if( dynamic_cast< const SvxExtTimeField *>( pField ) != nullptr ) + { + const SvxExtTimeField* pTimeField = static_cast<const SvxExtTimeField*>( pField ); + SvxExtTimeField aTimeField( *pTimeField ); + + if( pTimeField->GetType() == SvxTimeType::Fix ) + CheckItem( 1 ); + else + CheckItem( 2 ); + + //SvxTimeFormat::AppDefault, // is not used + //SvxTimeFormat::System, // is not used + InsertItem( nID++, SdResId( STR_STANDARD_NORMAL ), nStyle ); + + SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter(); + aTimeField.SetFormat( SvxTimeFormat::HH24_MM ); // 13:49 + InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS ); // 13:49:38 + InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS_00 ); // 13:49:38.78 + InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + + aTimeField.SetFormat( SvxTimeFormat::HH12_MM ); // 01:49 + InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS ); // 01:49:38 + InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS_00 ); // 01:49:38.78 + InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); + //SvxTimeFormat::HH12_MM_AMPM, // 01:49 PM + //SvxTimeFormat::HH12_MM_SS_AMPM, // 01:49:38 PM + //SvxTimeFormat::HH12_MM_SS_00_AMPM // 01:49:38.78 PM + + CheckItem( static_cast<sal_uInt16>( pTimeField->GetFormat() ) + 1 ); // - 2 + 3 ! + } + else if( dynamic_cast< const SvxExtFileField *>( pField ) != nullptr ) + { + const SvxExtFileField* pFileField = static_cast<const SvxExtFileField*>(pField); + //SvxExtFileField aFileField( *pFileField ); + + if( pFileField->GetType() == SvxFileType::Fix ) + CheckItem( 1 ); + else + CheckItem( 2 ); + + InsertItem( nID++, SdResId( STR_FILEFORMAT_NAME_EXT ), nStyle ); + InsertItem( nID++, SdResId( STR_FILEFORMAT_FULLPATH ), nStyle ); + InsertItem( nID++, SdResId( STR_FILEFORMAT_PATH ), nStyle ); + InsertItem( nID++, SdResId( STR_FILEFORMAT_NAME ), nStyle ); + + CheckItem( static_cast<sal_uInt16>( pFileField->GetFormat() ) + 3 ); + } + else if( dynamic_cast< const SvxAuthorField *>( pField ) != nullptr ) + { + const SvxAuthorField* pAuthorField = static_cast<const SvxAuthorField*>(pField); + SvxAuthorField aAuthorField( *pAuthorField ); + + if( pAuthorField->GetType() == SvxAuthorType::Fix ) + CheckItem( 1 ); + else + CheckItem( 2 ); + + for( sal_uInt16 i = 0; i < 4; i++ ) + { + aAuthorField.SetFormat( static_cast<SvxAuthorFormat>(i) ); + InsertItem( nID++, aAuthorField.GetFormatted(), nStyle ); + } + CheckItem( static_cast<sal_uInt16>( pAuthorField->GetFormat() ) + 3 ); + } +} + +/** + * Returns a new field, owned by caller. + * Returns NULL if nothing changed. + */ +SvxFieldData* SdFieldPopup::GetField() +{ + SvxFieldData* pNewField = nullptr; + sal_uInt16 nCount = GetItemCount(); + + if( dynamic_cast< const SvxDateField *>( pField ) != nullptr ) + { + const SvxDateField* pDateField = static_cast<const SvxDateField*>(pField); + SvxDateType eType; + SvxDateFormat eFormat; + sal_uInt16 i; + + if( IsItemChecked( 1 ) ) + eType = SvxDateType::Fix; + else + eType = SvxDateType::Var; + + for( i = 3; i <= nCount; i++ ) + { + if( IsItemChecked( i ) ) + break; + } + eFormat = static_cast<SvxDateFormat>( i - 1 ); + + if( pDateField->GetFormat() != eFormat || + pDateField->GetType() != eType ) + { + pNewField = new SvxDateField( *pDateField ); + static_cast<SvxDateField*>( pNewField )->SetType( eType ); + static_cast<SvxDateField*>( pNewField )->SetFormat( eFormat ); + + if( (pDateField->GetType() == SvxDateType::Var) && (eType == SvxDateType::Fix) ) + { + Date aDate( Date::SYSTEM ); + static_cast<SvxDateField*>( pNewField )->SetFixDate( aDate ); + } + } + } + else if( dynamic_cast< const SvxExtTimeField *>( pField ) != nullptr ) + { + const SvxExtTimeField* pTimeField = static_cast<const SvxExtTimeField*>(pField); + SvxTimeType eType; + SvxTimeFormat eFormat; + sal_uInt16 i; + + if( IsItemChecked( 1 ) ) + eType = SvxTimeType::Fix; + else + eType = SvxTimeType::Var; + + for( i = 3; i <= nCount; i++ ) + { + if( IsItemChecked( i ) ) + break; + } + eFormat = static_cast<SvxTimeFormat>( i - 1 ); + + if( pTimeField->GetFormat() != eFormat || + pTimeField->GetType() != eType ) + { + pNewField = new SvxExtTimeField( *pTimeField ); + static_cast<SvxExtTimeField*>( pNewField )->SetType( eType ); + static_cast<SvxExtTimeField*>( pNewField )->SetFormat( eFormat ); + + if( (pTimeField->GetType() == SvxTimeType::Var) && (eType == SvxTimeType::Fix) ) + { + tools::Time aTime( tools::Time::SYSTEM ); + static_cast<SvxExtTimeField*>( pNewField )->SetFixTime( aTime ); + } + + } + } + else if( dynamic_cast< const SvxExtFileField *>( pField ) != nullptr ) + { + const SvxExtFileField* pFileField = static_cast<const SvxExtFileField*>(pField); + SvxFileType eType; + SvxFileFormat eFormat; + sal_uInt16 i; + + if( IsItemChecked( 1 ) ) + eType = SvxFileType::Fix; + else + eType = SvxFileType::Var; + + for( i = 3; i <= nCount; i++ ) + { + if( IsItemChecked( i ) ) + break; + } + eFormat = static_cast<SvxFileFormat>( i - 3 ); + + if( pFileField->GetFormat() != eFormat || + pFileField->GetType() != eType ) + { + ::sd::DrawDocShell* pDocSh = dynamic_cast<::sd::DrawDocShell* >( SfxObjectShell::Current() ); + + if( pDocSh ) + { + OUString aName; + if( pDocSh->HasName() ) + aName = pDocSh->GetMedium()->GetName(); + + // Get current filename, not the one stored in the old field + pNewField = new SvxExtFileField( aName ); + static_cast<SvxExtFileField*>( pNewField )->SetType( eType ); + static_cast<SvxExtFileField*>( pNewField )->SetFormat( eFormat ); + } + } + } + else if( dynamic_cast< const SvxAuthorField *>( pField ) != nullptr ) + { + const SvxAuthorField* pAuthorField = static_cast<const SvxAuthorField*>(pField); + SvxAuthorType eType; + SvxAuthorFormat eFormat; + sal_uInt16 i; + + if( IsItemChecked( 1 ) ) + eType = SvxAuthorType::Fix; + else + eType = SvxAuthorType::Var; + + for( i = 3; i <= nCount; i++ ) + { + if( IsItemChecked( i ) ) + break; + } + eFormat = static_cast<SvxAuthorFormat>( i - 3 ); + + if( pAuthorField->GetFormat() != eFormat || + pAuthorField->GetType() != eType ) + { + // Get current state of address, not the old one + SvtUserOptions aUserOptions; + pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() ); + static_cast<SvxAuthorField*>( pNewField )->SetType( eType ); + static_cast<SvxAuthorField*>( pNewField )->SetFormat( eFormat ); + } + } + return pNewField; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/app/sdxfer.cxx b/sd/source/ui/app/sdxfer.cxx new file mode 100644 index 000000000..9ce97f817 --- /dev/null +++ b/sd/source/ui/app/sdxfer.cxx @@ -0,0 +1,820 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <com/sun/star/embed/XEmbeddedObject.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/XEmbedPersist.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <comphelper/fileformat.h> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/tempfile.hxx> +#include <editeng/flditem.hxx> +#include <svx/svdpagv.hxx> +#include <svx/svdoole2.hxx> +#include <svx/svdograf.hxx> +#include <svx/svdotext.hxx> +#include <editeng/outlobj.hxx> +#include <sot/storage.hxx> +#include <editeng/editobj.hxx> +#include <svx/fmglob.hxx> +#include <svx/svdouno.hxx> +#include <svx/ImageMapInfo.hxx> +#include <sot/formats.hxx> +#include <svl/urlbmk.hxx> + +#include <com/sun/star/form/FormButtonType.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <unotools/streamwrap.hxx> + +#include <svx/svdotable.hxx> +#include <svx/unomodel.hxx> +#include <svx/svditer.hxx> +#include <sfx2/docfile.hxx> +#include <comphelper/storagehelper.hxx> +#include <comphelper/servicehelper.hxx> +#include <svtools/embedtransfer.hxx> +#include <DrawDocShell.hxx> +#include <View.hxx> +#include <sdmod.hxx> +#include <sdpage.hxx> +#include <drawdoc.hxx> +#include <stlpool.hxx> +#include <sdxfer.hxx> +#include <unomodel.hxx> +#include <vcl/virdev.hxx> +#include <vcl/svapp.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::datatransfer; +using namespace ::com::sun::star::datatransfer::clipboard; + +constexpr sal_uInt32 SDTRANSFER_OBJECTTYPE_DRAWMODEL = 1; +constexpr sal_uInt32 SDTRANSFER_OBJECTTYPE_DRAWOLE = 2; + +SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, bool bInitOnGetData ) +: mpPageDocShell( nullptr ) +, mpSdView( pWorkView ) +, mpSdViewIntern( pWorkView ) +, mpSdDrawDocument( nullptr ) +, mpSdDrawDocumentIntern( nullptr ) +, mpSourceDoc( pSrcDoc ) +, mpVDev( nullptr ) +, mbInternalMove( false ) +, mbOwnDocument( false ) +, mbOwnView( false ) +, mbLateInit( bInitOnGetData ) +, mbPageTransferable( false ) +, mbPageTransferablePersistent( false ) +, maUserData() +{ + if( mpSourceDoc ) + StartListening( *mpSourceDoc ); + + if( pWorkView ) + StartListening( *pWorkView ); + + if( !mbLateInit ) + CreateData(); +} + +SdTransferable::~SdTransferable() +{ + SolarMutexGuard g; + + if( mpSourceDoc ) + EndListening( *mpSourceDoc ); + + if( mpSdView ) + EndListening( *const_cast< sd::View *>( mpSdView) ); + + ObjectReleased(); + + if( mbOwnView ) + delete mpSdViewIntern; + + mpOLEDataHelper.reset(); + + if( maDocShellRef.is() ) + { + SfxObjectShell* pObj = maDocShellRef.get(); + ::sd::DrawDocShell* pDocSh = static_cast< ::sd::DrawDocShell*>(pObj); + pDocSh->DoClose(); + } + + maDocShellRef.clear(); + + if( mbOwnDocument ) + delete mpSdDrawDocumentIntern; + + mpGraphic.reset(); + mpBookmark.reset(); + mpImageMap.reset(); + + mpVDev.disposeAndClear(); + mpObjDesc.reset(); + + //call explicitly at end of dtor to be covered by above SolarMutex + maUserData.clear(); +} + +void SdTransferable::CreateObjectReplacement( SdrObject* pObj ) +{ + if( pObj ) + { + mpOLEDataHelper.reset(); + mpGraphic.reset(); + mpBookmark.reset(); + mpImageMap.reset(); + + if( nullptr!= dynamic_cast< const SdrOle2Obj* >( pObj ) ) + { + try + { + uno::Reference < embed::XEmbeddedObject > xObj = static_cast< SdrOle2Obj* >( pObj )->GetObjRef(); + uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY ); + if( xObj.is() && xPersist.is() && xPersist->hasEntry() ) + { + mpOLEDataHelper.reset( new TransferableDataHelper( new SvEmbedTransferHelper( xObj, static_cast< SdrOle2Obj* >( pObj )->GetGraphic(), static_cast< SdrOle2Obj* >( pObj )->GetAspect() ) ) ); + + // TODO/LATER: the standalone handling of the graphic should not be used any more in future + // The EmbedDataHelper should bring the graphic in future + const Graphic* pObjGr = static_cast< SdrOle2Obj* >( pObj )->GetGraphic(); + if ( pObjGr ) + mpGraphic.reset( new Graphic( *pObjGr ) ); + } + } + catch( uno::Exception& ) + {} + } + else if( dynamic_cast< const SdrGrafObj *>( pObj ) != nullptr && (mpSourceDoc && !SdDrawDocument::GetAnimationInfo( pObj )) ) + { + mpGraphic.reset( new Graphic( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() ) ); + } + else if( pObj->IsUnoObj() && SdrInventor::FmForm == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == sal_uInt16(OBJ_FM_BUTTON) ) ) + { + SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( pObj ); + + if (SdrInventor::FmForm == pUnoCtrl->GetObjInventor()) + { + const Reference< css::awt::XControlModel >& xControlModel( pUnoCtrl->GetUnoControlModel() ); + + if( !xControlModel.is() ) + return; + + Reference< css::beans::XPropertySet > xPropSet( xControlModel, UNO_QUERY ); + + if( !xPropSet.is() ) + return; + + css::form::FormButtonType eButtonType; + Any aTmp( xPropSet->getPropertyValue( "ButtonType" ) ); + + if( aTmp >>= eButtonType ) + { + OUString aLabel, aURL; + + xPropSet->getPropertyValue( "Label" ) >>= aLabel; + xPropSet->getPropertyValue( "TargetURL" ) >>= aURL; + + mpBookmark.reset( new INetBookmark( aURL, aLabel ) ); + } + } + } + else if( dynamic_cast< const SdrTextObj *>( pObj ) != nullptr ) + { + const OutlinerParaObject* pPara; + + if( (pPara = static_cast< SdrTextObj* >( pObj )->GetOutlinerParaObject()) != nullptr ) + { + const SvxFieldItem* pField; + + if( (pField = pPara->GetTextObject().GetField()) != nullptr ) + { + const SvxFieldData* pData = pField->GetField(); + + if( auto pURL = dynamic_cast< const SvxURLField *>( pData ) ) + { + // #i63399# This special code identifies TextFrames which have just a URL + // as content and directly add this to the clipboard, probably to avoid adding + // an unnecessary DrawObject to the target where paste may take place. This is + // wanted only for SdrObjects with no fill and no line, else it is necessary to + // use the whole SdrObect. Test here for Line/FillStyle and take shortcut only + // when both are unused + if(!pObj->HasFillStyle() && !pObj->HasLineStyle()) + { + mpBookmark.reset( new INetBookmark( pURL->GetURL(), pURL->GetRepresentation() ) ); + } + } + } + } + } + + SvxIMapInfo* pInfo = SvxIMapInfo::GetIMapInfo( pObj ); + + if( pInfo ) + mpImageMap.reset( new ImageMap( pInfo->GetImageMap() ) ); + } +} + +void SdTransferable::CreateData() +{ + if( mpSdDrawDocument && !mpSdViewIntern ) + { + mbOwnView = true; + + SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PageKind::Standard); + + if( pPage && 1 == pPage->GetObjCount() ) + CreateObjectReplacement( pPage->GetObj( 0 ) ); + + mpVDev = VclPtr<VirtualDevice>::Create( *Application::GetDefaultDevice() ); + mpVDev->SetMapMode( MapMode( mpSdDrawDocumentIntern->GetScaleUnit(), Point(), mpSdDrawDocumentIntern->GetScaleFraction(), mpSdDrawDocumentIntern->GetScaleFraction() ) ); + mpSdViewIntern = new ::sd::View( *mpSdDrawDocumentIntern, mpVDev ); + mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern ); + mpSdViewIntern->hideMarkHandles(); + SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage); + mpSdViewIntern->MarkAllObj(pPageView); + } + else if( mpSdView && !mpSdDrawDocumentIntern ) + { + const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList(); + + if( rMarkList.GetMarkCount() == 1 ) + CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() ); + + if( mpSourceDoc ) + mpSourceDoc->CreatingDataObj(this); + mpSdDrawDocumentIntern = static_cast<SdDrawDocument*>( mpSdView->CreateMarkedObjModel().release() ); + if( mpSourceDoc ) + mpSourceDoc->CreatingDataObj(nullptr); + + if( !maDocShellRef.is() && mpSdDrawDocumentIntern->GetDocSh() ) + maDocShellRef = mpSdDrawDocumentIntern->GetDocSh(); + + if( !maDocShellRef.is() ) + { + OSL_FAIL( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" ); + mbOwnDocument = true; + } + + // Use dimension of source page + SdrPageView* pPgView = mpSdView->GetSdrPageView(); + SdPage* pOldPage = static_cast<SdPage*>( pPgView->GetPage() ); + SdrModel* pOldModel = mpSdView->GetModel(); + SdStyleSheetPool* pOldStylePool = static_cast<SdStyleSheetPool*>( pOldModel->GetStyleSheetPool() ); + SdStyleSheetPool* pNewStylePool = static_cast<SdStyleSheetPool*>( mpSdDrawDocumentIntern->GetStyleSheetPool() ); + SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PageKind::Standard ); + OUString aOldLayoutName( pOldPage->GetLayoutName() ); + + pPage->SetSize( pOldPage->GetSize() ); + pPage->SetLayoutName( aOldLayoutName ); + pNewStylePool->CopyGraphicSheets( *pOldStylePool ); + pNewStylePool->CopyCellSheets( *pOldStylePool ); + pNewStylePool->CopyTableStyles( *pOldStylePool ); + sal_Int32 nPos = aOldLayoutName.indexOf( SD_LT_SEPARATOR ); + if( nPos != -1 ) + aOldLayoutName = aOldLayoutName.copy( 0, nPos ); + StyleSheetCopyResultVector aCreatedSheets; + pNewStylePool->CopyLayoutSheets( aOldLayoutName, *pOldStylePool, aCreatedSheets ); + } + + // set VisArea and adjust objects if necessary + if( maVisArea.IsEmpty() && + mpSdDrawDocumentIntern && mpSdViewIntern && + mpSdDrawDocumentIntern->GetPageCount() ) + { + SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PageKind::Standard ); + + if( 1 == mpSdDrawDocumentIntern->GetPageCount() ) + { + // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get + // fat lines correctly + maVisArea = mpSdViewIntern->GetAllMarkedBoundRect(); + Point aOrigin( maVisArea.TopLeft() ); + Size aVector( -aOrigin.X(), -aOrigin.Y() ); + + for( size_t nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; ++nObj ) + { + SdrObject* pObj = pPage->GetObj( nObj ); + pObj->NbcMove( aVector ); + } + } + else + maVisArea.SetSize( pPage->GetSize() ); + + // output is at the zero point + maVisArea.SetPos( Point() ); + } +} + +static bool lcl_HasOnlyControls( SdrModel* pModel ) +{ + bool bOnlyControls = false; // default if there are no objects + + if ( pModel ) + { + SdrPage* pPage = pModel->GetPage(0); + if (pPage) + { + SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups ); + SdrObject* pObj = aIter.Next(); + if ( pObj ) + { + bOnlyControls = true; // only set if there are any objects at all + while ( pObj ) + { + if (dynamic_cast< const SdrUnoObj *>( pObj ) == nullptr) + { + bOnlyControls = false; + break; + } + pObj = aIter.Next(); + } + } + } + } + + return bOnlyControls; +} + +static bool lcl_HasOnlyOneTable( SdrModel* pModel ) +{ + if ( pModel ) + { + SdrPage* pPage = pModel->GetPage(0); + if (pPage && pPage->GetObjCount() == 1 ) + { + if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != nullptr ) + return true; + } + } + return false; +} + +void SdTransferable::AddSupportedFormats() +{ + if( !mbPageTransferable || mbPageTransferablePersistent ) + { + if( !mbLateInit ) + CreateData(); + + if( mpObjDesc ) + AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ); + + if( mpOLEDataHelper ) + { + AddFormat( SotClipboardFormatId::EMBED_SOURCE ); + + DataFlavorExVector aVector( mpOLEDataHelper->GetDataFlavorExVector() ); + + for( const auto& rItem : aVector ) + AddFormat( rItem ); + } + else if( mpGraphic ) + { + // #i25616# + AddFormat( SotClipboardFormatId::DRAWING ); + + AddFormat( SotClipboardFormatId::SVXB ); + + if( mpGraphic->GetType() == GraphicType::Bitmap ) + { + AddFormat( SotClipboardFormatId::PNG ); + AddFormat( SotClipboardFormatId::BITMAP ); + AddFormat( SotClipboardFormatId::GDIMETAFILE ); + } + else + { + AddFormat( SotClipboardFormatId::GDIMETAFILE ); + AddFormat( SotClipboardFormatId::PNG ); + AddFormat( SotClipboardFormatId::BITMAP ); + } + } + else if( mpBookmark ) + { + AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ); + AddFormat( SotClipboardFormatId::STRING ); + } + else + { + AddFormat( SotClipboardFormatId::EMBED_SOURCE ); + AddFormat( SotClipboardFormatId::DRAWING ); + if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) ) + { + AddFormat( SotClipboardFormatId::GDIMETAFILE ); + AddFormat( SotClipboardFormatId::PNG ); + AddFormat( SotClipboardFormatId::BITMAP ); + } + + if( lcl_HasOnlyOneTable( mpSdDrawDocument ) ) { + AddFormat( SotClipboardFormatId::RTF ); + AddFormat( SotClipboardFormatId::RICHTEXT ); + } + } + + if( mpImageMap ) + AddFormat( SotClipboardFormatId::SVIM ); + } +} + +bool SdTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDoc ) +{ + if (SD_MOD()==nullptr) + return false; + + SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor ); + bool bOK = false; + + CreateData(); + + if( nFormat == SotClipboardFormatId::RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) ) + { + bOK = SetTableRTF( mpSdDrawDocument ); + } + else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) ) + { + // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling + if( nFormat == SotClipboardFormatId::GDIMETAFILE && mpGraphic ) + bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile() ); + else + bOK = SetAny( mpOLEDataHelper->GetAny(rFlavor, rDestDoc) ); + } + else if( HasFormat( nFormat ) ) + { + if( ( nFormat == SotClipboardFormatId::LINKSRCDESCRIPTOR || nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR ) && mpObjDesc ) + { + bOK = SetTransferableObjectDescriptor( *mpObjDesc ); + } + else if( nFormat == SotClipboardFormatId::DRAWING ) + { + SfxObjectShellRef aOldRef( maDocShellRef ); + + maDocShellRef.clear(); + + if( mpSdViewIntern ) + { + SdDrawDocument& rInternDoc = mpSdViewIntern->GetDoc(); + rInternDoc.CreatingDataObj(this); + SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->CreateMarkedObjModel().release() ); + rInternDoc.CreatingDataObj(nullptr); + + bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor ); + + if( maDocShellRef.is() ) + { + maDocShellRef->DoClose(); + } + else + { + delete pDoc; + } + } + + maDocShellRef = aOldRef; + } + else if( nFormat == SotClipboardFormatId::GDIMETAFILE ) + { + if (mpSdViewIntern) + { + const bool bToggleOnlineSpell = mpSdDrawDocumentIntern && mpSdDrawDocumentIntern->GetOnlineSpell(); + if (bToggleOnlineSpell) + mpSdDrawDocumentIntern->SetOnlineSpell(false); + bOK = SetGDIMetaFile( mpSdViewIntern->GetMarkedObjMetaFile( true ) ); + if (bToggleOnlineSpell) + mpSdDrawDocumentIntern->SetOnlineSpell(true); + } + } + else if( SotClipboardFormatId::BITMAP == nFormat || SotClipboardFormatId::PNG == nFormat ) + { + if (mpSdViewIntern) + { + const bool bToggleOnlineSpell = mpSdDrawDocumentIntern && mpSdDrawDocumentIntern->GetOnlineSpell(); + if (bToggleOnlineSpell) + mpSdDrawDocumentIntern->SetOnlineSpell(false); + bOK = SetBitmapEx( mpSdViewIntern->GetMarkedObjBitmapEx(true), rFlavor ); + if (bToggleOnlineSpell) + mpSdDrawDocumentIntern->SetOnlineSpell(true); + } + } + else if( ( nFormat == SotClipboardFormatId::STRING ) && mpBookmark ) + { + bOK = SetString( mpBookmark->GetURL(), rFlavor ); + } + else if( ( nFormat == SotClipboardFormatId::SVXB ) && mpGraphic ) + { + bOK = SetGraphic( *mpGraphic ); + } + else if( ( nFormat == SotClipboardFormatId::SVIM ) && mpImageMap ) + { + bOK = SetImageMap( *mpImageMap ); + } + else if( mpBookmark ) + { + bOK = SetINetBookmark( *mpBookmark, rFlavor ); + } + else if( nFormat == SotClipboardFormatId::EMBED_SOURCE ) + { + if( mpSdDrawDocumentIntern ) + { + if( !maDocShellRef.is() ) + { + maDocShellRef = new ::sd::DrawDocShell( + mpSdDrawDocumentIntern, + SfxObjectCreateMode::EMBEDDED, + true, + mpSdDrawDocumentIntern->GetDocumentType()); + mbOwnDocument = false; + maDocShellRef->DoInitNew(); + } + + maDocShellRef->SetVisArea( maVisArea ); + bOK = SetObject( maDocShellRef.get(), SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor ); + } + } + } + + return bOK; +} + +bool SdTransferable::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& ) +{ + bool bRet = false; + + switch( nObjectType ) + { + case SDTRANSFER_OBJECTTYPE_DRAWMODEL: + { + try + { + static const bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != nullptr ); + SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(pObject); + if ( !bDontBurnInStyleSheet ) + pDoc->BurnInStyleSheetAttributes(); + rxOStm->SetBufferSize( 16348 ); + + Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, true ) ); + pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) ); + + { + css::uno::Reference<css::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) ); + if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DocumentType::Impress) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) ) + rxOStm->Commit(); + } + + xComponent->dispose(); + bRet = ( rxOStm->GetError() == ERRCODE_NONE ); + } + catch( Exception& ) + { + OSL_FAIL( "sd::SdTransferable::WriteObject(), exception caught!" ); + bRet = false; + } + } + break; + + case SDTRANSFER_OBJECTTYPE_DRAWOLE: + { + SfxObjectShell* pEmbObj = static_cast<SfxObjectShell*>(pObject); + ::utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + + try + { + uno::Reference< embed::XStorage > xWorkStore = + ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE ); + + // write document storage + pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false ); + // mba: no relative URLs for clipboard! + SfxMedium aMedium( xWorkStore, OUString() ); + pEmbObj->DoSaveObjectAs( aMedium, false ); + pEmbObj->DoSaveCompleted(); + + uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY ); + if ( xTransact.is() ) + xTransact->commit(); + + std::unique_ptr<SvStream> pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ ); + if( pSrcStm ) + { + rxOStm->SetBufferSize( 0xff00 ); + rxOStm->WriteStream( *pSrcStm ); + pSrcStm.reset(); + } + + bRet = true; + rxOStm->Commit(); + } + catch ( Exception& ) + {} + } + + break; + + default: + break; + } + + return bRet; +} + +void SdTransferable::DragFinished( sal_Int8 nDropAction ) +{ + if( mpSdView ) + const_cast< ::sd::View* >(mpSdView)->DragFinished( nDropAction ); +} + +void SdTransferable::ObjectReleased() +{ + if( this == SD_MOD()->pTransferClip ) + SD_MOD()->pTransferClip = nullptr; + + if( this == SD_MOD()->pTransferDrag ) + SD_MOD()->pTransferDrag = nullptr; + + if( this == SD_MOD()->pTransferSelection ) + SD_MOD()->pTransferSelection = nullptr; +} + +void SdTransferable::SetObjectDescriptor( std::unique_ptr<TransferableObjectDescriptor> pObjDesc ) +{ + mpObjDesc = std::move(pObjDesc); + PrepareOLE( *mpObjDesc ); +} + +void SdTransferable::SetPageBookmarks( const std::vector<OUString> &rPageBookmarks, bool bPersistent ) +{ + if( mpSourceDoc ) + { + if( mpSdViewIntern ) + mpSdViewIntern->HideSdrPage(); + + mpSdDrawDocument->ClearModel(false); + + mpPageDocShell = nullptr; + + maPageBookmarks.clear(); + + if( bPersistent ) + { + mpSdDrawDocument->CreateFirstPages(mpSourceDoc); + mpSdDrawDocument->InsertBookmarkAsPage( rPageBookmarks, nullptr, false, true, 1, true, + mpSourceDoc->GetDocSh(), true, true, false ); + } + else + { + mpPageDocShell = mpSourceDoc->GetDocSh(); + maPageBookmarks = rPageBookmarks; + } + + if( mpSdViewIntern ) + { + SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PageKind::Standard ); + + if( pPage ) + { + mpSdViewIntern->MarkAllObj( mpSdViewIntern->ShowSdrPage( pPage ) ); + } + } + + // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ), + // don't offer any formats => it's just for internal purposes + mbPageTransferable = true; + mbPageTransferablePersistent = bPersistent; + } +} + +sal_Int64 SAL_CALL SdTransferable::getSomething( const css::uno::Sequence< sal_Int8 >& rId ) +{ + sal_Int64 nRet; + + if( isUnoTunnelId<SdTransferable>(rId) ) + { + nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); + } + else + { + nRet = 0; + } + + return nRet; +} + +void SdTransferable::AddUserData (const std::shared_ptr<UserData>& rpData) +{ + maUserData.push_back(rpData); +} + +sal_Int32 SdTransferable::GetUserDataCount() const +{ + return maUserData.size(); +} + +std::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const +{ + if (nIndex>=0 && nIndex<sal_Int32(maUserData.size())) + return maUserData[nIndex]; + else + return std::shared_ptr<UserData>(); +} + +namespace +{ + class theSdTransferableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSdTransferableUnoTunnelId > {}; +} + +const css::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId() +{ + return theSdTransferableUnoTunnelId::get().getSeq(); +} + +SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw() +{ + try + { + Reference< css::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW ); + return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) ); + } + catch( const css::uno::Exception& ) + { + } + return nullptr; +} + +void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +{ + if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint) + { + const SdrHint* pSdrHint = static_cast< const SdrHint* >( &rHint ); + if( SdrHintKind::ModelCleared == pSdrHint->GetKind() ) + { + EndListening(*mpSourceDoc); + mpSourceDoc = nullptr; + } + } + else + { + if( rHint.GetId() == SfxHintId::Dying ) + { + if( &rBC == mpSourceDoc ) + mpSourceDoc = nullptr; + if( &rBC == mpSdViewIntern ) + mpSdViewIntern = nullptr; + if( &rBC == mpSdView ) + mpSdView = nullptr; + } + } +} + +void SdTransferable::SetView(const ::sd::View* pView) +{ + if (mpSdView) + EndListening(*const_cast<sd::View*>(mpSdView)); + mpSdView = pView; + if (mpSdView) + StartListening(*const_cast<sd::View*>(mpSdView)); +} + +bool SdTransferable::SetTableRTF( SdDrawDocument* pModel ) +{ + if ( pModel ) + { + SdrPage* pPage = pModel->GetPage(0); + if (pPage && pPage->GetObjCount() == 1 ) + { + sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ); + if( pTableObj ) + { + SvMemoryStream aMemStm( 65535, 65535 ); + sdr::table::ExportAsRTF( aMemStm, *pTableObj ); + return SetAny( Any( Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.TellEnd() ) ) ); + } + } + } + + return false; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/app/tmplctrl.cxx b/sd/source/ui/app/tmplctrl.cxx new file mode 100644 index 000000000..fd9d27da3 --- /dev/null +++ b/sd/source/ui/app/tmplctrl.cxx @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <vcl/commandevent.hxx> +#include <vcl/menu.hxx> +#include <vcl/status.hxx> +#include <svl/stritem.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/viewfrm.hxx> + +#include <tmplctrl.hxx> +#include <ViewShellBase.hxx> +#include <drawdoc.hxx> +#include <sdpage.hxx> +#include <sdattr.hrc> +#include <app.hrc> +#include <sdresid.hxx> +#include <strings.hrc> + +SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem ); + +// class SdTemplatePopup_Impl -------------------------------------------------- + +namespace { + +class SdTemplatePopup_Impl : public PopupMenu +{ +public: + SdTemplatePopup_Impl(); + + sal_uInt16 GetCurId() const { return nCurId; } + +private: + sal_uInt16 nCurId; + + virtual void Select() override; +}; + +} + +SdTemplatePopup_Impl::SdTemplatePopup_Impl() : + PopupMenu(), + nCurId(USHRT_MAX) +{ +} + +void SdTemplatePopup_Impl::Select() +{ + nCurId = GetCurItemId(); +} + +// class SdTemplateControl ------------------------------------------ + +SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId, + sal_uInt16 _nId, + StatusBar& rStb ) : + SfxStatusBarControl( _nSlotId, _nId, rStb ) +{ + GetStatusBar().SetQuickHelpText(GetId(), SdResId(STR_STATUSBAR_MASTERPAGE)); +} + +SdTemplateControl::~SdTemplateControl() +{ +} + +void SdTemplateControl::StateChanged( + sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) +{ + if( eState != SfxItemState::DEFAULT || pState->IsVoidItem() ) + GetStatusBar().SetItemText( GetId(), OUString() ); + else if ( auto pStringItem = dynamic_cast< const SfxStringItem *>( pState ) ) + { + msTemplate = pStringItem->GetValue(); + GetStatusBar().SetItemText( GetId(), msTemplate ); + } +} + +void SdTemplateControl::Paint( const UserDrawEvent& ) +{ +} + +void SdTemplateControl::Command( const CommandEvent& rCEvt ) +{ + if ( !(rCEvt.GetCommand() == CommandEventId::ContextMenu && !GetStatusBar().GetItemText( GetId() ).isEmpty()) ) + return; + + SfxViewFrame* pViewFrame = SfxViewFrame::Current(); + + sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame ); + if( !pViewShellBase ) + return; + + SdDrawDocument* pDoc = pViewShellBase->GetDocument(); + if( !pDoc ) + return; + + ScopedVclPtrInstance<SdTemplatePopup_Impl> aPop; + { + const sal_uInt16 nMasterCount = pDoc->GetMasterSdPageCount(PageKind::Standard); + + sal_uInt16 nCount = 0; + for( sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage ) + { + SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PageKind::Standard); + if( pMaster ) + aPop->InsertItem( ++nCount, pMaster->GetName() ); + } + aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); + + sal_uInt16 nCurrId = aPop->GetCurId()-1; + if( nCurrId < nMasterCount ) + { + SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PageKind::Standard); + SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() ); + pViewFrame->GetDispatcher()->ExecuteList( + SID_PRESENTATION_LAYOUT, SfxCallMode::SLOT, { &aStyle }); + pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT); + pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |