blob: 7eecb265eb9ad5bd23b6b02e2ac3ceac14ae4a7f [file] [log] [blame]
/*******************************************************************************
* You may amend and distribute as you like, but don't remove this header!
*
* EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
* See http://www.codeplex.com/EPPlus for details.
*
* Copyright (C) 2011 Jan Källman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
* If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
*
* All code and executables are provided "as is" with no warranty either express or implied.
* The author accepts no liability for any damage or loss of business that this product may cause.
*
* Code change notes:
*
* Author Change Date
* ******************************************************************************
* Jan Källman Initial Release 2010-06-01
* Jan Källman License changed GPL-->LGPL 2011-12-16
*******************************************************************************/
using System.Collections.Immutable;
using System.Xml;
namespace OfficeOpenXml.Drawing.Vml;
/// <summary>
/// Drawing object used for comments
/// </summary>
public class ExcelVmlDrawingComment : ExcelVmlDrawingBase, IRangeId {
protected override ImmutableArray<string> SchemaNodeOrder { get; } = [
"fill",
"stroke",
"shadow",
"path",
"textbox",
"ClientData",
"MoveWithCells",
"SizeWithCells",
"Anchor",
"Locked",
"AutoFill",
"LockText",
"TextHAlign",
"TextVAlign",
"Row",
"Column",
"Visible",
];
internal ExcelVmlDrawingComment(XmlNode topNode, ExcelRangeBase range, XmlNamespaceManager ns)
: base(topNode, ns) {
Range = range;
}
internal ExcelRangeBase Range { get; set; }
/// <summary>
/// Address in the worksheet
/// </summary>
public string Address => Range.Address;
private const string _verticalAlignmentPath = "x:ClientData/x:TextVAlign";
/// <summary>
/// Vertical alignment for text
/// </summary>
public eTextAlignVerticalVml VerticalAlignment {
get {
switch (GetXmlNodeString(_verticalAlignmentPath)) {
case "Center":
return eTextAlignVerticalVml.Center;
case "Bottom":
return eTextAlignVerticalVml.Bottom;
default:
return eTextAlignVerticalVml.Top;
}
}
set {
switch (value) {
case eTextAlignVerticalVml.Center:
SetXmlNodeString(_verticalAlignmentPath, "Center");
break;
case eTextAlignVerticalVml.Bottom:
SetXmlNodeString(_verticalAlignmentPath, "Bottom");
break;
default:
DeleteNode(_verticalAlignmentPath);
break;
}
}
}
private const string _horizontalAlignmentPath = "x:ClientData/x:TextHAlign";
/// <summary>
/// Horizontal alignment for text
/// </summary>
public eTextAlignHorizontalVml HorizontalAlignment {
get {
switch (GetXmlNodeString(_horizontalAlignmentPath)) {
case "Center":
return eTextAlignHorizontalVml.Center;
case "Right":
return eTextAlignHorizontalVml.Right;
default:
return eTextAlignHorizontalVml.Left;
}
}
set {
switch (value) {
case eTextAlignHorizontalVml.Center:
SetXmlNodeString(_horizontalAlignmentPath, "Center");
break;
case eTextAlignHorizontalVml.Right:
SetXmlNodeString(_horizontalAlignmentPath, "Right");
break;
default:
DeleteNode(_horizontalAlignmentPath);
break;
}
}
}
private const string _visiblePath = "x:ClientData/x:Visible";
/// <summary>
/// If the drawing object is visible.
/// </summary>
public bool Visible {
get => (TopNode.SelectSingleNode(_visiblePath, NameSpaceManager) != null);
set {
if (value) {
CreateNode(_visiblePath);
Style = SetStyle(Style, "visibility", "visible");
} else {
DeleteNode(_visiblePath);
Style = SetStyle(Style, "visibility", "hidden");
}
}
}
private const string _textboxStylePath = "v:textbox/@style";
/// <summary>
/// Autofits the drawingobject
/// </summary>
public bool AutoFit {
get {
GetStyle(GetXmlNodeString(_textboxStylePath), "mso-fit-shape-to-text", out var value);
return value == "t";
}
set =>
SetXmlNodeString(
_textboxStylePath,
SetStyle(GetXmlNodeString(_textboxStylePath), "mso-fit-shape-to-text", value ? "t" : ""));
}
private const string _lockedPath = "x:ClientData/x:Locked";
/// <summary>
/// If the object is locked when the sheet is protected
/// </summary>
public bool Locked {
get => GetXmlNodeBool(_lockedPath, false);
set => SetXmlNodeBool(_lockedPath, value, false);
}
private const string _lockTextPath = "x:ClientData/x:LockText";
/// <summary>
/// Specifies that the object's text is locked
/// </summary>
public bool LockText {
get => GetXmlNodeBool(_lockTextPath, false);
set => SetXmlNodeBool(_lockTextPath, value, false);
}
private ExcelVmlDrawingPosition _from;
/// <summary>
/// From position. For comments only when Visible=true.
/// </summary>
public ExcelVmlDrawingPosition From {
get {
if (_from == null) {
_from = new(
NameSpaceManager,
TopNode.SelectSingleNode("x:ClientData", NameSpaceManager),
0);
}
return _from;
}
}
private ExcelVmlDrawingPosition _to;
/// <summary>
/// To position. For comments only when Visible=true.
/// </summary>
public ExcelVmlDrawingPosition To {
get {
if (_to == null) {
_to = new(NameSpaceManager, TopNode.SelectSingleNode("x:ClientData", NameSpaceManager), 4);
}
return _to;
}
}
private const string _stylePath = "@style";
internal string Style {
get => GetXmlNodeString(_stylePath);
set => SetXmlNodeString(_stylePath, value);
}
ulong IRangeId.RangeID {
get => ExcelCellBase.GetCellId(Range.Worksheet.SheetID, Range.Start.Row, Range.Start.Column);
set {}
}
}