[de] Implement setting custom content colors from plugin

This commit is contained in:
Ilya Kirillov
2025-02-08 01:59:55 +03:00
parent 33b4ddf239
commit b85fae586d
7 changed files with 161 additions and 25 deletions

View File

@ -2328,6 +2328,8 @@
window['AscDFH'].historyitem_SdtPr_ComplexFormPr = window['AscDFH'].historyitem_type_SdtPr | 24;
window['AscDFH'].historyitem_SdtPr_OForm = window['AscDFH'].historyitem_type_SdtPr | 25;
window['AscDFH'].historyitem_SdtPr_DataBinding = window['AscDFH'].historyitem_type_SdtPr | 26;
window['AscDFH'].historyitem_SdtPr_ShdColor = window['AscDFH'].historyitem_type_SdtPr | 27;
window['AscDFH'].historyitem_SdtPr_BorderColor = window['AscDFH'].historyitem_type_SdtPr | 28;
//------------------------------------------------------------------------------------------------------------------
// Типы изменений в классе CSdtPr
//------------------------------------------------------------------------------------------------------------------

View File

@ -1267,10 +1267,36 @@ CSdtBase.prototype.getShdColor = function()
{
return this.Pr.ShdColor;
};
/**
* @param color {?AscWord.CDocumentColorA}
*/
CSdtBase.prototype.setShdColor = function(color)
{
if (!color)
color = undefined;
if ((!color && !this.Pr.ShdColor) || (color && this.Pr.ShdColor && color.isEqual(this.Pr.ShdColor)))
return;
AscCommon.AddAndExecuteChange(new CChangesSdtPrShdColor(this, this.Pr.ShdColor, color));
};
/**
* @return {?AscWord.CDocumentColorA}
*/
CSdtBase.prototype.getBorderColor = function()
{
return this.Pr.BorderColor;
};
};
/**
* @param color {?AscWord.CDocumentColorA}
*/
CSdtBase.prototype.setBorderColor = function(color)
{
if (!color)
color = undefined;
if ((!color && !this.Pr.BorderColor) || (color && this.Pr.BorderColor && color.isEqual(this.Pr.BorderColor)))
return;
AscCommon.AddAndExecuteChange(new CChangesSdtPrBorderColor(this, this.Pr.BorderColor, color));
};

View File

@ -73,8 +73,8 @@ function CSdtPr()
this.OForm = undefined;
this.BorderColor = new AscWord.CDocumentColorA(Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0);
this.ShdColor = new AscWord.CDocumentColorA(Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0);
this.BorderColor = undefined;//new AscWord.CDocumentColorA(Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0);
this.ShdColor = undefined;//new AscWord.CDocumentColorA(Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0);
}
CSdtPr.prototype.Copy = function()
@ -458,6 +458,9 @@ function CContentControlPr(nType)
this.PlaceholderText = undefined;
this.FormPr = undefined;
this.BorderColor = undefined;
this.ShdColor = undefined;
}
CContentControlPr.prototype.GetEventObject = function()
{
@ -493,6 +496,12 @@ CContentControlPr.prototype.FillFromObject = function(oPr)
if (undefined !== oPr.PlaceholderText)
this.PlaceholderText = oPr.PlaceholderText;
if (undefined !== oPr.ShdColor)
this.ShdColor = AscWord.CDocumentColorA.fromObjectRgba(oPr.ShdColor);
if (undefined !== oPr.BorderColor)
this.BorderColor = AscWord.CDocumentColorA.fromObjectRgba(oPr.BorderColor);
};
CContentControlPr.prototype.FillFromContentControl = function(oContentControl)
{
@ -552,6 +561,12 @@ CContentControlPr.prototype.FillFromContentControl = function(oContentControl)
if (oContentControl.IsSignatureForm())
this.FormPr.SetRequired(true);
}
if (oContentControl.getShdColor())
this.ShdColor = oContentControl.getShdColor().getAscColor();
if (oContentControl.getBorderColor())
this.BorderColor = oContentControl.getBorderColor().getAscColor();
};
CContentControlPr.prototype.SetToContentControl = function(oContentControl)
{
@ -665,6 +680,12 @@ CContentControlPr.prototype.SetToContentControl = function(oContentControl)
if (undefined !== this.ComplexFormPr)
oContentControl.SetComplexFormPr(this.ComplexFormPr);
if (this.ShdColor)
oContentControl.setShdColor(AscWord.CDocumentColorA.fromObjectRgba(this.ShdColor));
if (this.BorderColor)
oContentControl.setBorderColor(AscWord.CDocumentColorA.fromObjectRgba(this.BorderColor));
};
CContentControlPr.prototype.SetFormPrToContentControl = function(contentControl)
{

View File

@ -58,6 +58,8 @@ AscDFH.changesFactory[AscDFH.historyitem_SdtPr_PictureFormPr] = CChangesSdtPr
AscDFH.changesFactory[AscDFH.historyitem_SdtPr_ComplexFormPr] = CChangesSdtPrComplexFormPr;
AscDFH.changesFactory[AscDFH.historyitem_SdtPr_OForm] = CChangesSdtPrOForm;
AscDFH.changesFactory[AscDFH.historyitem_SdtPr_DataBinding] = CChangesSdtPrDataBinding;
AscDFH.changesFactory[AscDFH.historyitem_SdtPr_ShdColor] = CChangesSdtPrShdColor;
AscDFH.changesFactory[AscDFH.historyitem_SdtPr_BorderColor] = CChangesSdtPrBorderColor;
//----------------------------------------------------------------------------------------------------------------------
// Карта зависимости изменений
//----------------------------------------------------------------------------------------------------------------------
@ -138,6 +140,12 @@ AscDFH.changesRelationMap[AscDFH.historyitem_SdtPr_PictureFormPr] = [
AscDFH.changesRelationMap[AscDFH.historyitem_SdtPr_ComplexFormPr] = [
AscDFH.historyitem_SdtPr_ComplexFormPr
];
AscDFH.changesRelationMap[AscDFH.historyitem_SdtPr_ShdColor] = [
AscDFH.historyitem_SdtPr_ShdColor
];
AscDFH.changesRelationMap[AscDFH.historyitem_SdtPr_BorderColor] = [
AscDFH.historyitem_SdtPr_BorderColor
];
function private_SdtPrChangesCheckLock(lockData)
{
@ -842,3 +850,51 @@ CChangesSdtPrOForm.prototype.private_SetValue = function(Value)
this.Class.Pr.OForm = oValue;
};
CChangesSdtPrOForm.prototype.CheckLock = private_SdtPrChangesCheckLock;
/**
* @constructor
* @extends {AscDFH.CChangesBaseObjectProperty}
*/
function CChangesSdtPrShdColor(Class, Old, New)
{
AscDFH.CChangesBaseObjectProperty.call(this, Class, Old, New);
}
CChangesSdtPrShdColor.prototype = Object.create(AscDFH.CChangesBaseObjectProperty.prototype);
CChangesSdtPrShdColor.prototype.constructor = CChangesSdtPrShdColor;
CChangesSdtPrShdColor.prototype.Type = AscDFH.historyitem_SdtPr_ShdColor;
CChangesSdtPrShdColor.prototype.private_SetValue = function(value)
{
this.Class.Pr.ShdColor = value;
};
CChangesSdtPrShdColor.prototype.private_CreateObject = function()
{
return new AscWord.CDocumentColorA();
};
CChangesSdtPrShdColor.prototype.IsNeedRecalculate = function()
{
return false;
};
CChangesSdtPrShdColor.prototype.CheckLock = private_SdtPrChangesCheckLock;
/**
* @constructor
* @extends {AscDFH.CChangesBaseObjectProperty}
*/
function CChangesSdtPrBorderColor(Class, Old, New)
{
AscDFH.CChangesBaseObjectProperty.call(this, Class, Old, New);
}
CChangesSdtPrBorderColor.prototype = Object.create(AscDFH.CChangesBaseObjectProperty.prototype);
CChangesSdtPrBorderColor.prototype.constructor = CChangesSdtPrBorderColor;
CChangesSdtPrBorderColor.prototype.Type = AscDFH.historyitem_SdtPr_BorderColor;
CChangesSdtPrBorderColor.prototype.private_SetValue = function(value)
{
this.Class.Pr.BorderColor = value;
};
CChangesSdtPrBorderColor.prototype.private_CreateObject = function()
{
return new AscWord.CDocumentColorA();
};
CChangesSdtPrBorderColor.prototype.IsNeedRecalculate = function()
{
return false;
};
CChangesSdtPrBorderColor.prototype.CheckLock = private_SdtPrChangesCheckLock;

View File

@ -9600,6 +9600,13 @@ AscWord.CDocumentColor = CDocumentColor;
this.b = color.b;
this.a = color.a;
};
/**
* @return {Asc.asc_CColor}
*/
CDocumentColorA.prototype.getAscColor = function()
{
return new Asc.asc_CColor(this.r, this.g, this.b, this.a);
};
CDocumentColorA.prototype.SetFromHexColor = function(val)
{
if (AscFormat.mapPrstColor[val])

View File

@ -567,14 +567,19 @@
};
LogicDocument.SetDocumentMargin(oMargins);
}
if (undefined !== _current["Props"]["Appearance"])
_content_control_pr.Appearance = _current["Props"]["Appearance"];
if (undefined !== _current["Props"]["Color"])
_content_control_pr.Color = new Asc.asc_CColor(_current["Props"]["Color"]["R"], _current["Props"]["Color"]["G"], _current["Props"]["Color"]["B"]);
if (undefined !== _current["Props"]["ShdColor"])
_content_control_pr.ShdColor = new Asc.asc_CColor(_current["Props"]["ShdColor"]["R"], _current["Props"]["ShdColor"]["G"], _current["Props"]["ShdColor"]["B"], _current["Props"]["ShdColor"]["A"]);
if (undefined !== _current["Props"]["BorderColor"])
_content_control_pr.BorderColor = new Asc.asc_CColor(_current["Props"]["BorderColor"]["R"], _current["Props"]["BorderColor"]["G"], _current["Props"]["BorderColor"]["B"], _current["Props"]["BorderColor"]["A"]);
if (null === _blockStd)
{
let curPara = LogicDocument.GetCurrentParagraph();
@ -736,7 +741,13 @@
if (undefined !== _current["Props"]["Color"])
_content_control_pr.Color = new Asc.asc_CColor(_current["Props"]["Color"]["R"], _current["Props"]["Color"]["G"], _current["Props"]["Color"]["B"]);
if (undefined !== _current["Props"]["ShdColor"])
_content_control_pr.ShdColor = new Asc.asc_CColor(_current["Props"]["ShdColor"]["R"], _current["Props"]["ShdColor"]["G"], _current["Props"]["ShdColor"]["B"], _current["Props"]["ShdColor"]["A"]);
if (undefined !== _current["Props"]["BorderColor"])
_content_control_pr.BorderColor = new Asc.asc_CColor(_current["Props"]["BorderColor"]["R"], _current["Props"]["BorderColor"]["G"], _current["Props"]["BorderColor"]["B"], _current["Props"]["BorderColor"]["A"]);
_blockStd.SetContentControlPr(_content_control_pr);
LogicDocument.Recalculate();

View File

@ -79,22 +79,29 @@
* @property {string} Url - A link to the shared file (can be replaced with the *Script* parameter).
* @see office-js-api/Examples/Plugins/{Editor}/Enumeration/ContentControlPropertiesAndContent.js
*/
/**
* @typedef {Object} ContentControlProperties
/**
* @typedef {Object} Color
* @property {number} Color.R - Red color component value.
* @property {number} Color.G - Green color component value.
* @property {number} Color.B - Blue color component value.
* @property {number} Color.A - Alpha color component value.
*/
/**
* @typedef {Object} ContentControlProperties
* The content control properties.
* @property {string} Id - A unique identifier of the content control. It can be used to search for a certain content control and make reference to it in the code.
* @property {string} Tag - A tag assigned to the content control. The same tag can be assigned to several content controls so that it is possible to make reference to them in the code.
* @property {ContentControlLock} Lock - A value that defines if it is possible to delete and/or edit the content control or not.
* @property {string} InternalId - A unique internal identifier of the content control.
* @property {string} Id - A unique identifier of the content control. It can be used to search for a certain content control and make reference to it in the code.
* @property {string} Tag - A tag assigned to the content control. The same tag can be assigned to several content controls so that it is possible to make reference to them in the code.
* @property {ContentControlLock} Lock - A value that defines if it is possible to delete and/or edit the content control or not.
* @property {string} InternalId - A unique internal identifier of the content control.
* @property {string} Alias - The alias attribute.
* @property {string} PlaceHolderText - The content control placeholder text.
* @property {number} Appearance - Defines if the content control is shown as the bounding box (**1**) or not (**2**).
* @property {object} Color - The color for the current content control in the RGB format.
* @property {number} Color.R - Red color component value.
* @property {number} Color.G - Green color component value.
* @property {number} Color.B - Blue color component value.
* @see office-js-api/Examples/Plugins/{Editor}/Enumeration/ContentControlProperties.js
* @property {number} Appearance - Defines if the content control is shown as the bounding box (**1**) or not (**2**).
* @property {Color} Color - The color for the current content control in the RGB format.
* @property {Color} ShdColor - The background color for the current content control in the RGBA format.
* @property {Color} BorderColor - The border color for the current content control in the RGBA format.
* @see office-js-api/Examples/Plugins/{Editor}/Enumeration/ContentControlProperties.js
*/
/**
@ -1287,20 +1294,26 @@
if (commonPr)
{
resultPr = new AscCommon.CContentControlPr();
resultPr.Id = commonPr["Id"];
resultPr.Tag = commonPr["Tag"];
resultPr.Lock = commonPr["Lock"];
resultPr.Alias = commonPr["Alias"];
if (undefined !== commonPr["Appearance"])
resultPr.Appearance = commonPr["Appearance"];
if (undefined !== commonPr["Color"])
resultPr.Color = new Asc.asc_CColor(commonPr["Color"]["R"], commonPr["Color"]["G"], commonPr["Color"]["B"]);
if (undefined !== commonPr["PlaceHolderText"])
resultPr.SetPlaceholderText(commonPr["PlaceHolderText"]);
if (undefined !== commonPr["ShdColor"])
resultPr.ShdColor = new Asc.asc_CColor(commonPr["ShdColor"]["R"], commonPr["ShdColor"]["G"], commonPr["ShdColor"]["B"], commonPr["ShdColor"]["A"]);
if (undefined !== commonPr["BorderColor"])
resultPr.BorderColor = new Asc.asc_CColor(commonPr["BorderColor"]["R"], commonPr["BorderColor"]["G"], commonPr["BorderColor"]["B"], commonPr["BorderColor"]["A"]);
}
return resultPr;