/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for Additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ using System.Text; namespace Npoi.Core.DDF { using Npoi.Core.Util; using System; /// /// A simple property is of fixed Length and as a property number in Addition /// to a 32-bit value. Properties that can't be stored in only 32-bits are /// stored as EscherComplexProperty objects. /// @author Glen Stampoultzis (glens at apache.org) /// public class EscherSimpleProperty : EscherProperty { protected int propertyValue; /// /// The id is distinct from the actual property number. The id includes the property number the blip id /// flag and an indicator whether the property is complex or not. /// /// The id. /// The property value. public EscherSimpleProperty(short id, int propertyValue) : base(id) { this.propertyValue = propertyValue; } /// /// Constructs a new escher property. The three parameters are combined to form a property /// id. /// /// The property number. /// if set to true [is complex]. /// if set to true [is blip id]. /// The property value. public EscherSimpleProperty(short propertyNumber, bool isComplex, bool isBlipId, int propertyValue) : base(propertyNumber, isComplex, isBlipId) { this.propertyValue = propertyValue; } /// /// Serialize the simple part of the escher record. /// /// The data. /// The off set. /// the number of bytes Serialized. public override int SerializeSimplePart(byte[] data, int offset) { LittleEndian.PutShort(data, offset, Id); LittleEndian.PutInt(data, offset + 2, propertyValue); return 6; } /// /// Escher properties consist of a simple fixed Length part and a complex variable Length part. /// The fixed Length part is Serialized first. /// /// /// /// public override int SerializeComplexPart(byte[] data, int pos) { return 0; } /// /// Return the 32 bit value of this property. /// /// The property value. public int PropertyValue { get { return propertyValue; } internal set { propertyValue = value; } } /// /// Returns true if one escher property is equal to another. /// /// The o. /// public override bool Equals(Object o) { if (this == o) return true; if (!(o is EscherSimpleProperty)) return false; EscherSimpleProperty escherSimpleProperty = (EscherSimpleProperty)o; if (propertyValue != escherSimpleProperty.propertyValue) return false; if (Id != escherSimpleProperty.Id) return false; return true; } /// /// Serves as a hash function for a particular type. /// /// /// A hash code for the current . /// public override int GetHashCode() { return propertyValue; } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// public override String ToString() { return "propNum: " + PropertyNumber + ", RAW: 0x" + HexDump.ToHex(Id) + ", propName: " + EscherProperties.GetPropertyName(PropertyNumber) + ", complex: " + IsComplex + ", blipId: " + IsBlipId + ", value: " + propertyValue + " (0x" + HexDump.ToHex(propertyValue) + ")"; } public override String ToXml(string tab) { StringBuilder builder = new StringBuilder(); builder.Append(tab).Append("<").Append(GetType().Name).Append(" id=\"0x").Append(HexDump.ToHex(Id)) .Append("\" name=\"").Append(Name).Append("\" blipId=\"") .Append(IsBlipId).Append("\" complex=\"").Append(IsComplex).Append("\" value=\"").Append("0x") .Append(HexDump.ToHex(propertyValue)).Append("\"/>\n"); return builder.ToString(); } } }