Use named shapes for redaction

Change-Id: Ibb55bd503d264b618c3fbebfdbcf3fe9958c6783
Reviewed-on: https://gerrit.libreoffice.org/68031
Tested-by: Jenkins
Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com>
This commit is contained in:
Muhammet Kara
2019-02-19 23:41:57 +03:00
parent 12a59a1f29
commit 98384e98e5
9 changed files with 53 additions and 46 deletions

View File

@@ -416,7 +416,9 @@ class SfxDocumentInfoItem;
#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 + 808
// Used for redaction
#define SID_SHAPE_NAME (SID_SFX_START + 808)
// FREE: SID_SFX_START + 809 // FREE: SID_SFX_START + 809
// FREE: SID_SFX_START + 810 // FREE: SID_SFX_START + 810
#define SID_ASYNCHRON (SID_SFX_START + 811) #define SID_ASYNCHRON (SID_SFX_START + 811)

View File

@@ -2082,7 +2082,7 @@
<value>1</value> <value>1</value>
</prop> </prop>
</node> </node>
<node oor:name=".uno:Rect?FillTransparence:short=50&amp;FillColor:string=COL_GRAY7&amp;LineStyle:short=0&amp;IsSticky:bool=true" oor:op="replace"> <node oor:name=".uno:Rect?FillTransparence:short=50&amp;FillColor:string=COL_GRAY7&amp;LineStyle:short=0&amp;IsSticky:bool=true&amp;ShapeName:string=RectangleRedactionShape" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string"> <prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Rectangle</value> <value xml:lang="en-US">Rectangle</value>
</prop> </prop>
@@ -4746,7 +4746,7 @@
<value>1</value> <value>1</value>
</prop> </prop>
</node> </node>
<node oor:name=".uno:Freeline_Unfilled?Transparence:short=50&amp;Color:string=COL_GRAY7&amp;Width:short=500&amp;IsSticky:bool=true" oor:op="replace"> <node oor:name=".uno:Freeline_Unfilled?Transparence:short=50&amp;Color:string=COL_GRAY7&amp;Width:short=500&amp;IsSticky:bool=true&amp;ShapeName:string=FreeformRedactionShape" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string"> <prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Freeform</value> <value xml:lang="en-US">Freeform</value>
</prop> </prop>

View File

@@ -56,7 +56,8 @@ namespace sd {
/*//Extra attributes coming from parameters /*//Extra attributes coming from parameters
sal_uInt16 mnTransparence; // Default: 0 sal_uInt16 mnTransparence; // Default: 0
OUString msColor; // Default: "" OUString msColor; // Default: ""
sal_uInt16 mnWidth; // Default: 0*/ sal_uInt16 mnWidth; // Default: 0
OUString msShapeName; // Default: ""*/
FuConstructBezierPolygon::FuConstructBezierPolygon ( FuConstructBezierPolygon::FuConstructBezierPolygon (
ViewShell* pViewSh, ViewShell* pViewSh,
::sd::Window* pWin, ::sd::Window* pWin,
@@ -114,9 +115,13 @@ void FuConstructBezierPolygon::DoExecute( SfxRequest& rReq )
if (nSlotId != SID_DRAW_FREELINE_NOFILL) if (nSlotId != SID_DRAW_FREELINE_NOFILL)
return; return;
// This piece is only relevant for SID_DRAW_FREELINE_NOFILL
// Adding this note for the future because the if-block gets auto-flattened
// by loplugins
const SfxUInt16Item* pTransparence = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1); const SfxUInt16Item* pTransparence = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
const SfxStringItem* pColor = rReq.GetArg<SfxStringItem>(FN_PARAM_2); const SfxStringItem* pColor = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
const SfxUInt16Item* pWidth = rReq.GetArg<SfxUInt16Item>(FN_PARAM_3); const SfxUInt16Item* pWidth = rReq.GetArg<SfxUInt16Item>(FN_PARAM_3);
const SfxStringItem* pShapeName = rReq.GetArg<SfxStringItem>(SID_SHAPE_NAME);
if (pTransparence && pTransparence->GetValue() > 0) if (pTransparence && pTransparence->GetValue() > 0)
{ {
@@ -130,6 +135,11 @@ void FuConstructBezierPolygon::DoExecute( SfxRequest& rReq )
{ {
mnWidth = pWidth->GetValue(); mnWidth = pWidth->GetValue();
} }
if (pShapeName && !pShapeName->GetValue().isEmpty())
{
msShapeName = pShapeName->GetValue();
}
// End of the SID_DRAW_FREELINE_NOFILL block
} }
bool FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt) bool FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt)
@@ -174,7 +184,7 @@ bool FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt)
{ {
SfxItemSet aAttr(mpDoc->GetPool()); SfxItemSet aAttr(mpDoc->GetPool());
SetStyleSheet(aAttr, pObj); SetStyleSheet(aAttr, pObj);
SetAttributes(aAttr); SetAttributes(aAttr, pObj);
pObj->SetMergedItemSet(aAttr); pObj->SetMergedItemSet(aAttr);
} }
} }
@@ -352,7 +362,7 @@ Color strToColor(const OUString& sColor)
} }
} }
void FuConstructBezierPolygon::SetAttributes(SfxItemSet& rAttr) void FuConstructBezierPolygon::SetAttributes(SfxItemSet& rAttr, SdrObject *pObj)
{ {
if (nSlotId == SID_DRAW_FREELINE_NOFILL) if (nSlotId == SID_DRAW_FREELINE_NOFILL)
{ {
@@ -362,6 +372,8 @@ void FuConstructBezierPolygon::SetAttributes(SfxItemSet& rAttr)
rAttr.Put(XLineColorItem(OUString(), strToColor(msColor))); rAttr.Put(XLineColorItem(OUString(), strToColor(msColor)));
if (mnWidth > 0) if (mnWidth > 0)
rAttr.Put(XLineWidthItem(mnWidth)); rAttr.Put(XLineWidthItem(mnWidth));
if (!msShapeName.isEmpty())
pObj->SetName(msShapeName);
} }
} }

View File

@@ -156,6 +156,7 @@ void FuConstructRectangle::DoExecute( SfxRequest& rReq )
const SfxUInt16Item* pFillTransparence = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1); const SfxUInt16Item* pFillTransparence = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
const SfxStringItem* pFillColor = rReq.GetArg<SfxStringItem>(FN_PARAM_2); const SfxStringItem* pFillColor = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
const SfxUInt16Item* pLineStyle = rReq.GetArg<SfxUInt16Item>(FN_PARAM_3); const SfxUInt16Item* pLineStyle = rReq.GetArg<SfxUInt16Item>(FN_PARAM_3);
const SfxStringItem* pShapeName = rReq.GetArg<SfxStringItem>(SID_SHAPE_NAME);
if (pFillTransparence && pFillTransparence->GetValue() > 0) if (pFillTransparence && pFillTransparence->GetValue() > 0)
{ {
@@ -169,6 +170,10 @@ void FuConstructRectangle::DoExecute( SfxRequest& rReq )
{ {
mnLineStyle = pLineStyle->GetValue(); mnLineStyle = pLineStyle->GetValue();
} }
if (pShapeName && !pShapeName->GetValue().isEmpty())
{
msShapeName = pShapeName->GetValue();
}
if (!pMouseStartX || !pMouseStartY || !pMouseEndX || !pMouseEndY) if (!pMouseStartX || !pMouseStartY || !pMouseEndX || !pMouseEndY)
break; break;
@@ -565,6 +570,8 @@ void FuConstructRectangle::SetAttributes(SfxItemSet& rAttr, SdrObject* pObj)
rAttr.Put(XFillTransparenceItem(mnFillTransparence)); rAttr.Put(XFillTransparenceItem(mnFillTransparence));
if (!msFillColor.isEmpty()) if (!msFillColor.isEmpty())
rAttr.Put(XFillColorItem(OUString(), strToColor(msFillColor))); rAttr.Put(XFillColorItem(OUString(), strToColor(msFillColor)));
if (!msShapeName.isEmpty())
pObj->SetName(msShapeName);
switch(mnLineStyle) switch(mnLineStyle)
{ {

View File

@@ -50,7 +50,7 @@ public:
/** /**
* set attribute for the object to be created * set attribute for the object to be created
*/ */
void SetAttributes(SfxItemSet& rAttr); void SetAttributes(SfxItemSet& rAttr, SdrObject* pObj);
virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle) override; virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle) override;
@@ -69,6 +69,7 @@ private:
sal_uInt16 mnTransparence; // Default: 0 sal_uInt16 mnTransparence; // Default: 0
OUString msColor; // Default: "" OUString msColor; // Default: ""
sal_uInt16 mnWidth; // Default: 0 sal_uInt16 mnWidth; // Default: 0
OUString msShapeName; // Default: ""
}; };
} // end of namespace sd } // end of namespace sd

View File

@@ -38,6 +38,7 @@ private:
sal_uInt16 mnFillTransparence; // Default: 0 sal_uInt16 mnFillTransparence; // Default: 0
OUString msFillColor; // Default: "" OUString msFillColor; // Default: ""
sal_uInt16 mnLineStyle; // Default: SAL_MAX_UINT16 sal_uInt16 mnLineStyle; // Default: SAL_MAX_UINT16
OUString msShapeName; // Default: ""
public: public:

View File

@@ -18,8 +18,8 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink"> <toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink">
<toolbar:toolbaritem xlink:href=".uno:Rect?FillTransparence:short=50&amp;FillColor:string=COL_GRAY7&amp;LineStyle:short=0&amp;IsSticky:bool=true"/> <toolbar:toolbaritem xlink:href=".uno:Rect?FillTransparence:short=50&amp;FillColor:string=COL_GRAY7&amp;LineStyle:short=0&amp;IsSticky:bool=true&amp;ShapeName:string=RectangleRedactionShape"/>
<toolbar:toolbaritem xlink:href=".uno:Freeline_Unfilled?Transparence:short=50&amp;Color:string=COL_GRAY7&amp;Width:short=500&amp;IsSticky:bool=true"/> <toolbar:toolbaritem xlink:href=".uno:Freeline_Unfilled?Transparence:short=50&amp;Color:string=COL_GRAY7&amp;Width:short=500&amp;IsSticky:bool=true&amp;ShapeName:string=FreeformRedactionShape"/>
<toolbar:toolbarseparator/> <toolbar:toolbarseparator/>
<toolbar:toolbaritem xlink:href=".uno:ExportDirectToPDF?IsRedactMode:bool=true"/> <toolbar:toolbaritem xlink:href=".uno:ExportDirectToPDF?IsRedactMode:bool=true"/>
</toolbar:toolbar> </toolbar:toolbar>

View File

@@ -734,46 +734,28 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
if (!xInfo.is()) if (!xInfo.is())
continue; continue;
// Rectangle redaction OUString sShapeName;
if (xInfo->hasPropertyByName("FillTransparence") && xInfo->hasPropertyByName("FillColor")) if (xInfo->hasPropertyByName("Name"))
{ {
uno::Any aAnyTransp = xPropSet->getPropertyValue("FillTransparence"); uno::Any aAnyShapeName = xPropSet->getPropertyValue("Name");
uno::Any aAnyColor = xPropSet->getPropertyValue("FillColor"); aAnyShapeName >>= sShapeName;
}
else
continue;
sal_Int16 nTransp = 0; // Rectangle redaction
Color aColor; if (sShapeName == "RectangleRedactionShape"
const OUString sRectangleName("RectangleRedactionShape"); && xInfo->hasPropertyByName("FillTransparence") && xInfo->hasPropertyByName("FillColor"))
aAnyTransp >>= nTransp;
aAnyColor >>= aColor;
if (nTransp == 50 && aColor == COL_GRAY7)
{ {
xPropSet->setPropertyValue("FillTransparence", css::uno::makeAny(static_cast<sal_Int16>(0))); xPropSet->setPropertyValue("FillTransparence", css::uno::makeAny(static_cast<sal_Int16>(0)));
xPropSet->setPropertyValue("FillColor", css::uno::makeAny(COL_BLACK)); xPropSet->setPropertyValue("FillColor", css::uno::makeAny(COL_BLACK));
xPropSet->setPropertyValue("Name", css::uno::makeAny(sRectangleName));
} }
}
//FIXME: Turn this into an else-if when we have the name-check
// Freeform redaction // Freeform redaction
if (xInfo->hasPropertyByName("LineTransparence") && xInfo->hasPropertyByName("LineColor")) else if (sShapeName == "FreeformRedactionShape"
{ && xInfo->hasPropertyByName("LineTransparence") && xInfo->hasPropertyByName("LineColor"))
uno::Any aAnyTransp = xPropSet->getPropertyValue("LineTransparence");
uno::Any aAnyColor = xPropSet->getPropertyValue("LineColor");
sal_Int16 nTransp = 0;
Color aColor;
const OUString sFreeformName("FreeformRedactionShape");
aAnyTransp >>= nTransp;
aAnyColor >>= aColor;
if (nTransp == 50 && aColor == COL_GRAY7)
{ {
xPropSet->setPropertyValue("LineTransparence", css::uno::makeAny(static_cast<sal_Int16>(0))); xPropSet->setPropertyValue("LineTransparence", css::uno::makeAny(static_cast<sal_Int16>(0)));
xPropSet->setPropertyValue("LineColor", css::uno::makeAny(COL_BLACK)); xPropSet->setPropertyValue("LineColor", css::uno::makeAny(COL_BLACK));
xPropSet->setPropertyValue("Name", css::uno::makeAny(sFreeformName));
}
} }
} }
} }

View File

@@ -3473,7 +3473,8 @@ SfxBoolItem Freeline SID_DRAW_FREELINE
SfxBoolItem Freeline_Unfilled SID_DRAW_FREELINE_NOFILL SfxBoolItem Freeline_Unfilled SID_DRAW_FREELINE_NOFILL
(SfxUInt16Item Transparence FN_PARAM_1, SfxStringItem Color FN_PARAM_2, (SfxUInt16Item Transparence FN_PARAM_1, SfxStringItem Color FN_PARAM_2,
SfxUInt16Item Width FN_PARAM_3, SfxBoolItem IsSticky FN_PARAM_4) SfxUInt16Item Width FN_PARAM_3, SfxBoolItem IsSticky FN_PARAM_4,
SfxStringItem ShapeName SID_SHAPE_NAME)
[ [
AutoUpdate = TRUE, AutoUpdate = TRUE,
FastCall = FALSE, FastCall = FALSE,
@@ -6830,7 +6831,8 @@ SfxBoolItem Rect SID_DRAW_RECT
(SfxUInt32Item MouseStartX ID_VAL_MOUSESTART_X, SfxUInt32Item MouseStartY ID_VAL_MOUSESTART_Y, (SfxUInt32Item MouseStartX ID_VAL_MOUSESTART_X, SfxUInt32Item MouseStartY ID_VAL_MOUSESTART_Y,
SfxUInt32Item MouseEndX ID_VAL_MOUSEEND_X, SfxUInt32Item MouseEndY ID_VAL_MOUSEEND_Y, SfxUInt32Item MouseEndX ID_VAL_MOUSEEND_X, SfxUInt32Item MouseEndY ID_VAL_MOUSEEND_Y,
SfxUInt16Item FillTransparence FN_PARAM_1, SfxStringItem FillColor FN_PARAM_2, SfxUInt16Item FillTransparence FN_PARAM_1, SfxStringItem FillColor FN_PARAM_2,
SfxUInt16Item LineStyle FN_PARAM_3, SfxBoolItem IsSticky FN_PARAM_4) SfxUInt16Item LineStyle FN_PARAM_3, SfxBoolItem IsSticky FN_PARAM_4,
SfxStringItem ShapeName SID_SHAPE_NAME)
[ [
AutoUpdate = TRUE, AutoUpdate = TRUE,
FastCall = FALSE, FastCall = FALSE,