Kaydet (Commit) 48906a5e authored tarafından Szymon Kłos's avatar Szymon Kłos

Watermark: extended configuration

* it is possible to set font family,
  color, angle and transparency

Change-Id: Idea2fb9ee748394bb3d706fa790e109238584cdb
Reviewed-on: https://gerrit.libreoffice.org/37793Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarSzymon Kłos <szymon.klos@collabora.com>
üst a3f9f03f
...@@ -330,7 +330,10 @@ ...@@ -330,7 +330,10 @@
#define SID_INSERT_FLOATINGFRAME (SID_SFX_START + 563) #define SID_INSERT_FLOATINGFRAME (SID_SFX_START + 563)
#define SID_CLASSIFICATION_APPLY (SID_SFX_START + 672) #define SID_CLASSIFICATION_APPLY (SID_SFX_START + 672)
#define SID_WATERMARK (SID_SFX_START + 676) #define SID_WATERMARK (SID_SFX_START + 676)
// FREE (SID_SFX_START + 677) #define SID_WATERMARK_FONT (SID_SFX_START + 677)
#define SID_WATERMARK_TRANSPARENCY (SID_SFX_START + 805)
#define SID_WATERMARK_COLOR (SID_SFX_START + 806)
#define SID_WATERMARK_ANGLE (SID_SFX_START + 807)
#define SID_HYPERLINK_DIALOG (SID_SFX_START + 678) #define SID_HYPERLINK_DIALOG (SID_SFX_START + 678)
...@@ -394,9 +397,6 @@ ...@@ -394,9 +397,6 @@
#define SID_PASTE_ONLY_TEXT (SID_SFX_START + 802) #define SID_PASTE_ONLY_TEXT (SID_SFX_START + 802)
#define SID_PASTE_ONLY_FORMULA (SID_SFX_START + 803) #define SID_PASTE_ONLY_FORMULA (SID_SFX_START + 803)
#define SID_PASTE_ONLY_VALUE (SID_SFX_START + 804) #define SID_PASTE_ONLY_VALUE (SID_SFX_START + 804)
// FREE: SID_SFX_START + 805
// FREE: SID_SFX_START + 806
// FREE: SID_SFX_START + 807
// FREE: SID_SFX_START + 808 // FREE: SID_SFX_START + 808
// FREE: SID_SFX_START + 809 // FREE: SID_SFX_START + 809
// FREE: SID_SFX_START + 810 // FREE: SID_SFX_START + 810
......
...@@ -17,17 +17,29 @@ class SFX2_DLLPUBLIC SfxWatermarkItem: public SfxPoolItem ...@@ -17,17 +17,29 @@ class SFX2_DLLPUBLIC SfxWatermarkItem: public SfxPoolItem
public: public:
static SfxPoolItem* CreateDefault(); static SfxPoolItem* CreateDefault();
SfxWatermarkItem(); SfxWatermarkItem();
SfxWatermarkItem( sal_uInt16 nWhich, const OUString &rText );
SfxWatermarkItem( const SfxWatermarkItem& ); SfxWatermarkItem( const SfxWatermarkItem& );
virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const override; virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const override;
virtual bool operator==( const SfxPoolItem& ) const override; virtual bool operator==( const SfxPoolItem& ) const override;
virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override; virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
const OUString& GetText() const { return m_aText; } const OUString GetText() const { return m_aText; }
void SetText(const OUString& aText) { m_aText = aText; }
const OUString GetFont() const { return m_aFont; }
void SetFont(const OUString& aFont) { m_aFont = aFont; }
sal_Int16 GetAngle() const { return m_nAngle; }
void SetAngle(const sal_Int16 nAngle) { m_nAngle = nAngle; }
sal_Int16 GetTransparency() const { return m_nTransparency; }
void SetTransparency(const sal_Int16 nTransparency) { m_nTransparency = nTransparency; }
sal_uInt32 GetColor() const { return m_nColor; }
void SetColor(const sal_uInt32 nColor) { m_nColor = nColor; }
private: private:
OUString m_aText; OUString m_aText;
OUString m_aFont;
sal_Int16 m_nAngle;
sal_Int16 m_nTransparency;
sal_uInt32 m_nColor;
}; };
#endif #endif
......
...@@ -4268,7 +4268,10 @@ SfxVoidItem ClassificationApply SID_CLASSIFICATION_APPLY ...@@ -4268,7 +4268,10 @@ SfxVoidItem ClassificationApply SID_CLASSIFICATION_APPLY
] ]
SfxWatermarkItem Watermark SID_WATERMARK SfxWatermarkItem Watermark SID_WATERMARK
(SfxStringItem Text SID_WATERMARK) (SfxStringItem Text SID_WATERMARK, SfxStringItem Font SID_WATERMARK_FONT,
SfxInt16Item Angle SID_WATERMARK_ANGLE, SfxInt16Item Transparency SID_WATERMARK_TRANSPARENCY,
SfxUInt32Item Color SID_WATERMARK_COLOR
)
[ [
AutoUpdate = FALSE, AutoUpdate = FALSE,
FastCall = FALSE, FastCall = FALSE,
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
SfxWatermarkItem::SfxWatermarkItem() SfxWatermarkItem::SfxWatermarkItem()
: SfxPoolItem( SID_WATERMARK ) : SfxPoolItem( SID_WATERMARK )
, m_aText( "" ) , m_aText( "" )
, m_aFont( "Liberation Sans" )
, m_nAngle( 45 )
, m_nTransparency( 50 )
, m_nColor( 0xc0c0c0 )
{ {
} }
...@@ -21,22 +25,24 @@ SfxPoolItem* SfxWatermarkItem::CreateDefault() ...@@ -21,22 +25,24 @@ SfxPoolItem* SfxWatermarkItem::CreateDefault()
return new SfxWatermarkItem(); return new SfxWatermarkItem();
} }
SfxWatermarkItem::SfxWatermarkItem( sal_uInt16 nWhichId, const OUString& rText )
: SfxPoolItem( nWhichId )
, m_aText( rText )
{
}
SfxWatermarkItem::SfxWatermarkItem( const SfxWatermarkItem& rCopy ) SfxWatermarkItem::SfxWatermarkItem( const SfxWatermarkItem& rCopy )
: SfxPoolItem( rCopy ) : SfxPoolItem( rCopy )
, m_aText( rCopy.m_aText ) , m_aText( rCopy.m_aText )
, m_aFont( rCopy.m_aFont )
, m_nAngle( rCopy.m_nAngle )
, m_nTransparency( rCopy.m_nTransparency )
, m_nColor( rCopy.m_nColor )
{ {
} }
bool SfxWatermarkItem::operator==( const SfxPoolItem& rCmp ) const bool SfxWatermarkItem::operator==( const SfxPoolItem& rCmp ) const
{ {
return ( SfxPoolItem::operator==( rCmp ) && return ( SfxPoolItem::operator==( rCmp ) &&
m_aText == static_cast<const SfxWatermarkItem&>(rCmp).m_aText ); m_aText == static_cast<const SfxWatermarkItem&>(rCmp).m_aText &&
m_aFont == static_cast<const SfxWatermarkItem&>(rCmp).m_aFont &&
m_nAngle == static_cast<const SfxWatermarkItem&>(rCmp).m_nAngle &&
m_nTransparency == static_cast<const SfxWatermarkItem&>(rCmp).m_nTransparency &&
m_nColor == static_cast<const SfxWatermarkItem&>(rCmp).m_nColor );
} }
SfxPoolItem* SfxWatermarkItem::Clone( SfxItemPool *) const SfxPoolItem* SfxWatermarkItem::Clone( SfxItemPool *) const
...@@ -47,6 +53,10 @@ SfxPoolItem* SfxWatermarkItem::Clone( SfxItemPool *) const ...@@ -47,6 +53,10 @@ SfxPoolItem* SfxWatermarkItem::Clone( SfxItemPool *) const
bool SfxWatermarkItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const bool SfxWatermarkItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
{ {
rVal <<= m_aText; rVal <<= m_aText;
rVal <<= m_aFont;
rVal <<= m_nAngle;
rVal <<= m_nTransparency;
rVal <<= m_nColor;
return true; return true;
} }
...@@ -58,6 +68,10 @@ bool SfxWatermarkItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberI ...@@ -58,6 +68,10 @@ bool SfxWatermarkItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberI
if ( rVal >>= aText ) if ( rVal >>= aText )
{ {
m_aText = aText; m_aText = aText;
rVal >>= m_aFont;
rVal >>= m_nAngle;
rVal >>= m_nTransparency;
rVal >>= m_nColor;
return true; return true;
} }
......
...@@ -368,7 +368,7 @@ public: ...@@ -368,7 +368,7 @@ public:
void SetClassification(const OUString& rName, SfxClassificationPolicyType eType); void SetClassification(const OUString& rName, SfxClassificationPolicyType eType);
SfxWatermarkItem GetWatermark(); SfxWatermarkItem GetWatermark();
void SetWatermark(const OUString& rText); void SetWatermark(const SfxWatermarkItem& rText);
void Insert2(SwField&, const bool bForceExpandHints); void Insert2(SwField&, const bool bForceExpandHints);
......
...@@ -229,7 +229,9 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli ...@@ -229,7 +229,9 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli
} }
} }
SetWatermark(aWatermark); SfxWatermarkItem aWatermarkItem;
aWatermarkItem.SetText(aWatermark);
SetWatermark(aWatermarkItem);
} }
if (bFooterIsNeeded) if (bFooterIsNeeded)
...@@ -260,7 +262,7 @@ SfxWatermarkItem SwEditShell::GetWatermark() ...@@ -260,7 +262,7 @@ SfxWatermarkItem SwEditShell::GetWatermark()
{ {
SwDocShell* pDocShell = GetDoc()->GetDocShell(); SwDocShell* pDocShell = GetDoc()->GetDocShell();
if (!pDocShell) if (!pDocShell)
return SfxWatermarkItem(SID_WATERMARK, ""); return SfxWatermarkItem();
uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel(); uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY); uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
...@@ -286,14 +288,30 @@ SfxWatermarkItem SwEditShell::GetWatermark() ...@@ -286,14 +288,30 @@ SfxWatermarkItem SwEditShell::GetWatermark()
if (xWatermark.is()) if (xWatermark.is())
{ {
SfxWatermarkItem aItem;
uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY); 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(); SwDocShell* pDocShell = GetDoc()->GetDocShell();
if (!pDocShell) if (!pDocShell)
...@@ -326,12 +344,26 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) ...@@ -326,12 +344,26 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
static const OUString sWatermark = SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCWATERMARK(); static const OUString sWatermark = SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCWATERMARK();
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark); uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark);
bool bDeleteWatermark = rWatermark.isEmpty(); bool bDeleteWatermark = rWatermark.GetText().isEmpty();
if (xWatermark.is()) 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. // 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); 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. // No: delete it and we'll insert a replacement.
uno::Reference<lang::XComponent> xComponent(xWatermark, uno::UNO_QUERY); uno::Reference<lang::XComponent> xComponent(xWatermark, uno::UNO_QUERY);
...@@ -342,12 +374,18 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) ...@@ -342,12 +374,18 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
if (!xWatermark.is() && !bDeleteWatermark) 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. // Calc the ratio.
double fRatio = 0; double fRatio = 0;
OutputDevice* pOut = Application::GetDefaultDevice(); OutputDevice* pOut = Application::GetDefaultDevice();
vcl::Font aFont(pOut->GetFont()); vcl::Font aFont(pOut->GetFont());
aFont.SetFamilyName(sFont);
fRatio = aFont.GetFontSize().Height(); fRatio = aFont.GetFontSize().Height();
fRatio /= pOut->GetTextWidth(rWatermark); fRatio /= pOut->GetTextWidth(rWatermark.GetText());
// Calc the size. // Calc the size.
sal_Int32 nWidth = 0; sal_Int32 nWidth = 0;
...@@ -378,7 +416,7 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) ...@@ -378,7 +416,7 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
basegfx::B2DHomMatrix aTransformation; basegfx::B2DHomMatrix aTransformation;
aTransformation.identity(); aTransformation.identity();
aTransformation.scale(nWidth, nHeight); aTransformation.scale(nWidth, nHeight);
aTransformation.rotate(F_PI180 * -45); aTransformation.rotate(F_PI180 * -1 * nAngle);
drawing::HomogenMatrix3 aMatrix; drawing::HomogenMatrix3 aMatrix;
aMatrix.Line1.Column1 = aTransformation.get(0, 0); aMatrix.Line1.Column1 = aTransformation.get(0, 0);
aMatrix.Line1.Column2 = aTransformation.get(0, 1); aMatrix.Line1.Column2 = aTransformation.get(0, 1);
...@@ -397,9 +435,9 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) ...@@ -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. // 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); uno::Reference<document::XActionLockable> xLockable(xShape, uno::UNO_QUERY);
xLockable->addActionLock(); 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_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_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_LINESTYLE, uno::makeAny(drawing::LineStyle_NONE));
xPropertySet->setPropertyValue(UNO_NAME_OPAQUE, uno::makeAny(false)); xPropertySet->setPropertyValue(UNO_NAME_OPAQUE, uno::makeAny(false));
...@@ -409,13 +447,13 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) ...@@ -409,13 +447,13 @@ void SwEditShell::SetWatermark(const OUString& rWatermark)
xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEWIDTH, uno::makeAny(nWidth)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEWIDTH, uno::makeAny(nWidth));
xPropertySet->setPropertyValue(UNO_NAME_TEXT_WRAP, uno::makeAny(text::WrapTextMode_THROUGH)); 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_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("Transformation", uno::makeAny(aMatrix));
xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::HoriOrientation::CENTER))); 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))); xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::VertOrientation::CENTER)));
uno::Reference<text::XTextRange> xTextRange(xShape, uno::UNO_QUERY); 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); uno::Reference<drawing::XEnhancedCustomShapeDefaulter> xDefaulter(xShape, uno::UNO_QUERY);
xDefaulter->createCustomShapeDefaults("fontwork-plain-text"); xDefaulter->createCustomShapeDefaults("fontwork-plain-text");
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <svx/fmshell.hxx> #include <svx/fmshell.hxx>
#include <sfx2/linkmgr.hxx> #include <sfx2/linkmgr.hxx>
#include <sfx2/classificationhelper.hxx> #include <sfx2/classificationhelper.hxx>
#include <sfx2/watermarkitem.hxx>
#include <svtools/htmlcfg.hxx> #include <svtools/htmlcfg.hxx>
#include <svx/ofaitem.hxx> #include <svx/ofaitem.hxx>
...@@ -1163,8 +1164,19 @@ void SwDocShell::Execute(SfxRequest& rReq) ...@@ -1163,8 +1164,19 @@ void SwDocShell::Execute(SfxRequest& rReq)
{ {
if (pArgs && pArgs->GetItemState( SID_WATERMARK, false, &pItem ) == SfxItemState::SET) if (pArgs && pArgs->GetItemState( SID_WATERMARK, false, &pItem ) == SfxItemState::SET)
{ {
OUString aText = static_cast<const SfxStringItem*>( pItem )->GetValue(); SfxWatermarkItem aItem;
pSh->SetWatermark( aText ); 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 else
{ {
......
...@@ -276,10 +276,9 @@ void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh) ...@@ -276,10 +276,9 @@ void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
break; break;
case SID_WATERMARK: case SID_WATERMARK:
{ {
SfxWatermarkItem aItem = pSh->GetWatermark();
if( pSh ) if( pSh )
rSet.Put(pSh->GetWatermark()); rSet.Put(aItem);
rSet.InvalidateItem(nWhich);
} }
break; break;
default: default:
......
...@@ -10,11 +10,14 @@ ...@@ -10,11 +10,14 @@
#include <watermarkdialog.hxx> #include <watermarkdialog.hxx>
#include <comphelper/propertysequence.hxx> #include <comphelper/propertysequence.hxx>
#include <comphelper/dispatchcommand.hxx> #include <comphelper/dispatchcommand.hxx>
#include <editeng/editids.hrc>
#include <editeng/flstitem.hxx>
#include <sfx2/sfxsids.hrc> #include <sfx2/sfxsids.hrc>
#include <sfx2/bindings.hxx> #include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx> #include <sfx2/dispatch.hxx>
#include <svl/eitem.hxx> #include <svl/eitem.hxx>
#include <sfx2/watermarkitem.hxx> #include <sfx2/watermarkitem.hxx>
#include <svtools/ctrltool.hxx>
SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindings ) SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindings )
: ModelessDialog( pParent, "WatermarkDialog", "modules/swriter/ui/watermarkdialog.ui" ) : ModelessDialog( pParent, "WatermarkDialog", "modules/swriter/ui/watermarkdialog.ui" )
...@@ -24,9 +27,10 @@ SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindin ...@@ -24,9 +27,10 @@ SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindin
get( m_pEnableWatermarkCB, "EnableWatermarkCB" ); get( m_pEnableWatermarkCB, "EnableWatermarkCB" );
get( m_pTextInput, "TextInput" ); get( m_pTextInput, "TextInput" );
get( m_pOKButton, "ok" ); get( m_pOKButton, "ok" );
get( m_pFont, "FontBox" );
m_pEnableWatermarkCB->SetClickHdl( LINK( this, SwWatermarkDialog, CheckBoxHdl ) ); get( m_pAngle, "Angle" );
m_pOKButton->SetClickHdl( LINK( this, SwWatermarkDialog, OKButtonHdl ) ); get( m_pTransparency, "Transparency" );
get( m_pColor, "Color" );
InitFields(); InitFields();
Update(); Update();
...@@ -39,6 +43,10 @@ SwWatermarkDialog::~SwWatermarkDialog() ...@@ -39,6 +43,10 @@ SwWatermarkDialog::~SwWatermarkDialog()
void SwWatermarkDialog::dispose() void SwWatermarkDialog::dispose()
{ {
m_pFont.clear();
m_pAngle.clear();
m_pTransparency.clear();
m_pColor.clear();
m_pTextGrid.clear(); m_pTextGrid.clear();
m_pEnableWatermarkCB.clear(); m_pEnableWatermarkCB.clear();
m_pTextInput.clear(); m_pTextInput.clear();
...@@ -49,14 +57,36 @@ void SwWatermarkDialog::dispose() ...@@ -49,14 +57,36 @@ void SwWatermarkDialog::dispose()
void SwWatermarkDialog::InitFields() 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; const SfxPoolItem* pItem;
SfxItemState eState = m_rBindings.GetDispatcher()->QueryState( SID_WATERMARK, 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_pEnableWatermarkCB->Check( !sText.isEmpty() );
m_pTextInput->SetText( sText ); 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 ) ...@@ -81,7 +111,11 @@ IMPL_LINK_NOARG( SwWatermarkDialog, OKButtonHdl, Button*, void )
css::uno::Sequence<css::beans::PropertyValue> aPropertyValues( comphelper::InitPropertySequence( 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 ); comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues );
......
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
#define INCLUDED_SW_SOURCE_UIBASE_INC_WATERMARKDIALOG_HXX #define INCLUDED_SW_SOURCE_UIBASE_INC_WATERMARKDIALOG_HXX
#include <sfx2/bindings.hxx> #include <sfx2/bindings.hxx>
#include <vcl/field.hxx>
#include <vcl/layout.hxx> #include <vcl/layout.hxx>
#include <svtools/ctrlbox.hxx>
#include <svx/colorbox.hxx>
class SwWatermarkDialog : public ModelessDialog class SwWatermarkDialog : public ModelessDialog
{ {
...@@ -32,6 +35,10 @@ private: ...@@ -32,6 +35,10 @@ private:
VclPtr<CheckBox> m_pEnableWatermarkCB; VclPtr<CheckBox> m_pEnableWatermarkCB;
VclPtr<Edit> m_pTextInput; VclPtr<Edit> m_pTextInput;
VclPtr<PushButton> m_pOKButton; VclPtr<PushButton> m_pOKButton;
VclPtr<FontNameBox> m_pFont;
VclPtr<NumericField> m_pAngle;
VclPtr<NumericField> m_pTransparency;
VclPtr<SvxColorListBox> m_pColor;
}; };
#endif #endif
......
...@@ -2,6 +2,17 @@ ...@@ -2,6 +2,17 @@
<!-- Generated with glade 3.20.0 --> <!-- Generated with glade 3.20.0 -->
<interface> <interface>
<requires lib="gtk+" version="3.0"/> <requires lib="gtk+" version="3.0"/>
<requires lib="LibreOffice" version="1.0"/>
<object class="GtkAdjustment" id="angle_adj">
<property name="upper">359</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="transparenct_adj">
<property name="upper">100</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkDialog" id="WatermarkDialog"> <object class="GtkDialog" id="WatermarkDialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">6</property> <property name="border_width">6</property>
...@@ -86,6 +97,7 @@ ...@@ -86,6 +97,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Text</property> <property name="label" translatable="yes">Text</property>
<property name="xalign">0</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -103,6 +115,97 @@ ...@@ -103,6 +115,97 @@
<property name="top_attach">0</property> <property name="top_attach">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="svtlo-FontNameBox" id="FontBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="FontLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Font</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="AngleLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Angle</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="TransparencyLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Transparency</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ColorLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Color</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="Angle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">angle_adj</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="Transparency">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">transparenct_adj</property>
<property name="value">50</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="svxcorelo-SvxColorListBox" id="Color">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
...@@ -124,10 +227,4 @@ ...@@ -124,10 +227,4 @@
<action-widget response="0">cancel</action-widget> <action-widget response="0">cancel</action-widget>
</action-widgets> </action-widgets>
</object> </object>
<object class="GtkTextBuffer" id="textbuffer1">
<property name="text" translatable="yes">You did not specify a new name for the attachment.</property>
</object>
<object class="GtkTextBuffer" id="textbuffer2">
<property name="text" translatable="yes">If you would like to provide one, please type it now.</property>
</object>
</interface> </interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment