summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-05-19 00:18:15 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2017-05-19 19:24:05 +0200
commit48906a5e899e517af76e04afb5659232b336e206 (patch)
tree3e6159253675799bbed9948164f78510ddef86ab /sw/source
parenta3f9f03f52c2134058dff87eb1528a19450c566c (diff)
Watermark: extended configuration
* it is possible to set font family, color, angle and transparency Change-Id: Idea2fb9ee748394bb3d706fa790e109238584cdb Reviewed-on: https://gerrit.libreoffice.org/37793 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/edit/edfcol.cxx64
-rw-r--r--sw/source/uibase/app/docsh2.cxx16
-rw-r--r--sw/source/uibase/app/docst.cxx5
-rw-r--r--sw/source/uibase/dialog/watermarkdialog.cxx46
-rw-r--r--sw/source/uibase/inc/watermarkdialog.hxx7
5 files changed, 114 insertions, 24 deletions
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 024278e9971f..97129c354583 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -229,7 +229,9 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli
}
}
- SetWatermark(aWatermark);
+ SfxWatermarkItem aWatermarkItem;
+ aWatermarkItem.SetText(aWatermark);
+ SetWatermark(aWatermarkItem);
}
if (bFooterIsNeeded)
@@ -260,7 +262,7 @@ SfxWatermarkItem SwEditShell::GetWatermark()
{
SwDocShell* pDocShell = GetDoc()->GetDocShell();
if (!pDocShell)
- return SfxWatermarkItem(SID_WATERMARK, "");
+ return SfxWatermarkItem();
uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
@@ -286,14 +288,30 @@ SfxWatermarkItem SwEditShell::GetWatermark()
if (xWatermark.is())
{
+ SfxWatermarkItem aItem;
uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY);
- return SfxWatermarkItem(SID_WATERMARK, xTextRange->getString());
+ uno::Reference<beans::XPropertySet> xPropertySet(xWatermark, uno::UNO_QUERY);
+ sal_uInt32 nColor;
+ sal_Int16 nTransparency;
+ OUString aFont;
+
+ aItem.SetText(xTextRange->getString());
+
+ if (xPropertySet->getPropertyValue(UNO_NAME_CHAR_FONT_NAME) >>= aFont)
+ aItem.SetFont(aFont);
+ if (xPropertySet->getPropertyValue(UNO_NAME_FILLCOLOR) >>= nColor)
+ aItem.SetColor(nColor);
+ // TODO: aItem.SetAngle(nAngle);
+ if (xPropertySet->getPropertyValue(UNO_NAME_FILL_TRANSPARENCE) >>= nTransparency)
+ aItem.SetTransparency(nTransparency);
+
+ return aItem;
}
}
- return SfxWatermarkItem(SID_WATERMARK, "");
+ return SfxWatermarkItem();
}
-void SwEditShell::SetWatermark(const OUString& rWatermark)
+void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark)
{
SwDocShell* pDocShell = GetDoc()->GetDocShell();
if (!pDocShell)
@@ -326,12 +344,26 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
static const OUString sWatermark = SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCWATERMARK();
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark);
- bool bDeleteWatermark = rWatermark.isEmpty();
+ bool bDeleteWatermark = rWatermark.GetText().isEmpty();
if (xWatermark.is())
{
+ sal_uInt32 nColor = 0xc0c0c0;
+ sal_Int16 nTransparency = 50;
+ OUString aFont = "";
+
+ uno::Reference<beans::XPropertySet> xPropertySet(xWatermark, uno::UNO_QUERY);
+ xPropertySet->getPropertyValue(UNO_NAME_CHAR_FONT_NAME) >>= aFont;
+ xPropertySet->getPropertyValue(UNO_NAME_FILLCOLOR) >>= nColor;
+ // TODO: Angle
+ xPropertySet->getPropertyValue(UNO_NAME_FILL_TRANSPARENCE) >>= nTransparency;
+
// If the header already contains a watermark, see if it its text is up to date.
uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY);
- if (xTextRange->getString() != rWatermark || bDeleteWatermark)
+ if (xTextRange->getString() != rWatermark.GetText()
+ || aFont != rWatermark.GetFont()
+ || nColor != rWatermark.GetColor()
+ || nTransparency != rWatermark.GetTransparency()
+ || bDeleteWatermark)
{
// No: delete it and we'll insert a replacement.
uno::Reference<lang::XComponent> xComponent(xWatermark, uno::UNO_QUERY);
@@ -342,12 +374,18 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
if (!xWatermark.is() && !bDeleteWatermark)
{
+ OUString sFont = rWatermark.GetFont();
+ sal_Int16 nAngle = rWatermark.GetAngle();
+ sal_Int16 nTransparency = rWatermark.GetTransparency();
+ sal_uInt32 nColor = rWatermark.GetColor();
+
// Calc the ratio.
double fRatio = 0;
OutputDevice* pOut = Application::GetDefaultDevice();
vcl::Font aFont(pOut->GetFont());
+ aFont.SetFamilyName(sFont);
fRatio = aFont.GetFontSize().Height();
- fRatio /= pOut->GetTextWidth(rWatermark);
+ fRatio /= pOut->GetTextWidth(rWatermark.GetText());
// Calc the size.
sal_Int32 nWidth = 0;
@@ -378,7 +416,7 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
basegfx::B2DHomMatrix aTransformation;
aTransformation.identity();
aTransformation.scale(nWidth, nHeight);
- aTransformation.rotate(F_PI180 * -45);
+ aTransformation.rotate(F_PI180 * -1 * nAngle);
drawing::HomogenMatrix3 aMatrix;
aMatrix.Line1.Column1 = aTransformation.get(0, 0);
aMatrix.Line1.Column2 = aTransformation.get(0, 1);
@@ -397,9 +435,9 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
// The remaining properties have to be set after the shape is inserted: do that in one batch to avoid flickering.
uno::Reference<document::XActionLockable> xLockable(xShape, uno::UNO_QUERY);
xLockable->addActionLock();
- xPropertySet->setPropertyValue(UNO_NAME_FILLCOLOR, uno::makeAny(static_cast<sal_Int32>(0xc0c0c0)));
+ xPropertySet->setPropertyValue(UNO_NAME_FILLCOLOR, uno::makeAny(static_cast<sal_Int32>(nColor)));
xPropertySet->setPropertyValue(UNO_NAME_FILLSTYLE, uno::makeAny(drawing::FillStyle_SOLID));
- xPropertySet->setPropertyValue(UNO_NAME_FILL_TRANSPARENCE, uno::makeAny(static_cast<sal_Int16>(50)));
+ xPropertySet->setPropertyValue(UNO_NAME_FILL_TRANSPARENCE, uno::makeAny(nTransparency));
xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT_RELATION, uno::makeAny(static_cast<sal_Int16>(text::RelOrientation::PAGE_PRINT_AREA)));
xPropertySet->setPropertyValue(UNO_NAME_LINESTYLE, uno::makeAny(drawing::LineStyle_NONE));
xPropertySet->setPropertyValue(UNO_NAME_OPAQUE, uno::makeAny(false));
@@ -409,13 +447,13 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEWIDTH, uno::makeAny(nWidth));
xPropertySet->setPropertyValue(UNO_NAME_TEXT_WRAP, uno::makeAny(text::WrapTextMode_THROUGH));
xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT_RELATION, uno::makeAny(static_cast<sal_Int16>(text::RelOrientation::PAGE_PRINT_AREA)));
- xPropertySet->setPropertyValue(UNO_NAME_CHAR_FONT_NAME, uno::makeAny(OUString("Liberation Sans")));
+ xPropertySet->setPropertyValue(UNO_NAME_CHAR_FONT_NAME, uno::makeAny(sFont));
xPropertySet->setPropertyValue("Transformation", uno::makeAny(aMatrix));
xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::HoriOrientation::CENTER)));
xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::VertOrientation::CENTER)));
uno::Reference<text::XTextRange> xTextRange(xShape, uno::UNO_QUERY);
- xTextRange->setString(rWatermark);
+ xTextRange->setString(rWatermark.GetText());
uno::Reference<drawing::XEnhancedCustomShapeDefaulter> xDefaulter(xShape, uno::UNO_QUERY);
xDefaulter->createCustomShapeDefaults("fontwork-plain-text");
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index 767ddcff9929..4cb22e077ef8 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -56,6 +56,7 @@
#include <svx/fmshell.hxx>
#include <sfx2/linkmgr.hxx>
#include <sfx2/classificationhelper.hxx>
+#include <sfx2/watermarkitem.hxx>
#include <svtools/htmlcfg.hxx>
#include <svx/ofaitem.hxx>
@@ -1163,8 +1164,19 @@ void SwDocShell::Execute(SfxRequest& rReq)
{
if (pArgs && pArgs->GetItemState( SID_WATERMARK, false, &pItem ) == SfxItemState::SET)
{
- OUString aText = static_cast<const SfxStringItem*>( pItem )->GetValue();
- pSh->SetWatermark( aText );
+ SfxWatermarkItem aItem;
+ aItem.SetText( static_cast<const SfxStringItem*>( pItem )->GetValue() );
+
+ if ( pArgs->GetItemState( SID_WATERMARK_FONT, false, &pItem ) == SfxItemState::SET )
+ aItem.SetFont( static_cast<const SfxStringItem*>( pItem )->GetValue() );
+ if ( pArgs->GetItemState( SID_WATERMARK_ANGLE, false, &pItem ) == SfxItemState::SET )
+ aItem.SetAngle( static_cast<const SfxInt16Item*>( pItem )->GetValue() );
+ if ( pArgs->GetItemState( SID_WATERMARK_TRANSPARENCY, false, &pItem ) == SfxItemState::SET )
+ aItem.SetTransparency( static_cast<const SfxInt16Item*>( pItem )->GetValue() );
+ if ( pArgs->GetItemState( SID_WATERMARK_COLOR, false, &pItem ) == SfxItemState::SET )
+ aItem.SetColor( static_cast<const SfxUInt32Item*>( pItem )->GetValue() );
+
+ pSh->SetWatermark( aItem );
}
else
{
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 16fed3f39afd..8193e0416964 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -276,10 +276,9 @@ void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
break;
case SID_WATERMARK:
{
+ SfxWatermarkItem aItem = pSh->GetWatermark();
if( pSh )
- rSet.Put(pSh->GetWatermark());
-
- rSet.InvalidateItem(nWhich);
+ rSet.Put(aItem);
}
break;
default:
diff --git a/sw/source/uibase/dialog/watermarkdialog.cxx b/sw/source/uibase/dialog/watermarkdialog.cxx
index bcc6077e9d03..1246eabce4cc 100644
--- a/sw/source/uibase/dialog/watermarkdialog.cxx
+++ b/sw/source/uibase/dialog/watermarkdialog.cxx
@@ -10,11 +10,14 @@
#include <watermarkdialog.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/dispatchcommand.hxx>
+#include <editeng/editids.hrc>
+#include <editeng/flstitem.hxx>
#include <sfx2/sfxsids.hrc>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <svl/eitem.hxx>
#include <sfx2/watermarkitem.hxx>
+#include <svtools/ctrltool.hxx>
SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindings )
: ModelessDialog( pParent, "WatermarkDialog", "modules/swriter/ui/watermarkdialog.ui" )
@@ -24,9 +27,10 @@ SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindin
get( m_pEnableWatermarkCB, "EnableWatermarkCB" );
get( m_pTextInput, "TextInput" );
get( m_pOKButton, "ok" );
-
- m_pEnableWatermarkCB->SetClickHdl( LINK( this, SwWatermarkDialog, CheckBoxHdl ) );
- m_pOKButton->SetClickHdl( LINK( this, SwWatermarkDialog, OKButtonHdl ) );
+ get( m_pFont, "FontBox" );
+ get( m_pAngle, "Angle" );
+ get( m_pTransparency, "Transparency" );
+ get( m_pColor, "Color" );
InitFields();
Update();
@@ -39,6 +43,10 @@ SwWatermarkDialog::~SwWatermarkDialog()
void SwWatermarkDialog::dispose()
{
+ m_pFont.clear();
+ m_pAngle.clear();
+ m_pTransparency.clear();
+ m_pColor.clear();
m_pTextGrid.clear();
m_pEnableWatermarkCB.clear();
m_pTextInput.clear();
@@ -49,14 +57,36 @@ void SwWatermarkDialog::dispose()
void SwWatermarkDialog::InitFields()
{
+ // Update font list
+ SfxObjectShell* pDocSh = SfxObjectShell::Current();
+ const SfxPoolItem* pFontItem;
+ const FontList* pFontList = nullptr;
+
+ if ( pDocSh && ( ( pFontItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ) ) != nullptr ) )
+ pFontList = static_cast<const SvxFontListItem*>( pFontItem )->GetFontList();
+
+ if(!pFontList)
+ pFontList = new FontList(Application::GetDefaultDevice(), nullptr);
+
+ m_pFont->Fill( pFontList );
+
+ m_pEnableWatermarkCB->SetClickHdl( LINK( this, SwWatermarkDialog, CheckBoxHdl ) );
+ m_pOKButton->SetClickHdl( LINK( this, SwWatermarkDialog, OKButtonHdl ) );
+
+ // Get watermark properties
const SfxPoolItem* pItem;
SfxItemState eState = m_rBindings.GetDispatcher()->QueryState( SID_WATERMARK, pItem );
- if( eState >= SfxItemState::DEFAULT && pItem )
+ if( eState >= SfxItemState::DEFAULT && pItem && pItem->Which() == SID_WATERMARK)
{
- OUString sText = static_cast<const SfxWatermarkItem*>( pItem )->GetText();
+ const SfxWatermarkItem* pWatermark = static_cast<const SfxWatermarkItem*>( pItem );
+ OUString sText = pWatermark->GetText();
m_pEnableWatermarkCB->Check( !sText.isEmpty() );
m_pTextInput->SetText( sText );
+ m_pFont->SelectEntryPos( m_pFont->GetEntryPos( pWatermark->GetFont() ) );
+ m_pAngle->SetValue( pWatermark->GetAngle() );
+ m_pColor->SelectEntry( pWatermark->GetColor() );
+ m_pTransparency->SetValue( pWatermark->GetTransparency() );
}
}
@@ -81,7 +111,11 @@ IMPL_LINK_NOARG( SwWatermarkDialog, OKButtonHdl, Button*, void )
css::uno::Sequence<css::beans::PropertyValue> aPropertyValues( comphelper::InitPropertySequence(
{
- { "Text", css::uno::makeAny( sText ) }
+ { "Text", css::uno::makeAny( sText ) },
+ { "Font", css::uno::makeAny( m_pFont->GetSelectEntry() ) },
+ { "Angle", css::uno::makeAny( static_cast<sal_Int16>( m_pAngle->GetValue() ) ) },
+ { "Transparency", css::uno::makeAny( static_cast<sal_Int16>( m_pTransparency->GetValue() ) ) },
+ { "Color", css::uno::makeAny( static_cast<sal_uInt32>( m_pColor->GetSelectEntryColor().GetRGBColor() ) ) }
} ) );
comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues );
diff --git a/sw/source/uibase/inc/watermarkdialog.hxx b/sw/source/uibase/inc/watermarkdialog.hxx
index e1a60b96637d..7f59fe0a2bb7 100644
--- a/sw/source/uibase/inc/watermarkdialog.hxx
+++ b/sw/source/uibase/inc/watermarkdialog.hxx
@@ -10,7 +10,10 @@
#define INCLUDED_SW_SOURCE_UIBASE_INC_WATERMARKDIALOG_HXX
#include <sfx2/bindings.hxx>
+#include <vcl/field.hxx>
#include <vcl/layout.hxx>
+#include <svtools/ctrlbox.hxx>
+#include <svx/colorbox.hxx>
class SwWatermarkDialog : public ModelessDialog
{
@@ -32,6 +35,10 @@ private:
VclPtr<CheckBox> m_pEnableWatermarkCB;
VclPtr<Edit> m_pTextInput;
VclPtr<PushButton> m_pOKButton;
+ VclPtr<FontNameBox> m_pFont;
+ VclPtr<NumericField> m_pAngle;
+ VclPtr<NumericField> m_pTransparency;
+ VclPtr<SvxColorListBox> m_pColor;
};
#endif