PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/AODL/Document/Styles/ListLevelStyle.cs

https://bitbucket.org/chrisc/aodl
C# | 210 lines | 102 code | 15 blank | 93 comment | 9 complexity | 2bd25a4ba54e5f5ed86b9c258a79024e MD5 | raw file
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  4. *
  5. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Use is subject to license terms.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  10. * use this file except in compliance with the License. You may obtain a copy
  11. * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
  12. * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. *
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. ************************************************************************/
  22. using System;
  23. using System.Xml.Linq;
  24. using AODL.Document.Styles.Properties;
  25. namespace AODL.Document.Styles
  26. {
  27. /// <summary>
  28. /// Represent the list level style.
  29. /// </summary>
  30. public class ListLevelStyle : AbstractStyle
  31. {
  32. /// <summary>
  33. /// Initializes a new instance of the <see cref="ListLevelStyle"/> class.
  34. /// </summary>
  35. /// <param name="document">The document.</param>
  36. /// <param name="style">The style.</param>
  37. /// <param name="typ">The typ.</param>
  38. /// <param name="level">The level.</param>
  39. public ListLevelStyle(IDocument document, ListStyle style, ListStyles typ, int level)
  40. {
  41. Document = document;
  42. ListStyle = style;
  43. InitStandards();
  44. NewXmlNode(typ, level);
  45. AddListLevel(level);
  46. }
  47. /// <summary>
  48. /// The ListStyle to this object belongs.
  49. /// </summary>
  50. public ListStyle ListStyle { get; set; }
  51. /// <summary>
  52. /// Gets or sets the text properties.
  53. /// </summary>
  54. /// <value>The text properties.</value>
  55. public ListLevelProperties ListLevelProperties
  56. {
  57. get
  58. {
  59. foreach (IProperty property in PropertyCollection)
  60. if (property is ListLevelProperties)
  61. return (ListLevelProperties) property;
  62. ListLevelProperties listLevelProperties = new ListLevelProperties(this);
  63. PropertyCollection.Add(listLevelProperties);
  64. return listLevelProperties;
  65. }
  66. set
  67. {
  68. if (PropertyCollection.Contains(value))
  69. PropertyCollection.Remove(value);
  70. PropertyCollection.Add(value);
  71. }
  72. }
  73. /// <summary>
  74. /// Gets or sets the text properties.
  75. /// </summary>
  76. /// <value>The text properties.</value>
  77. public TextProperties TextProperties
  78. {
  79. get
  80. {
  81. foreach (IProperty property in PropertyCollection)
  82. if (property is TextProperties)
  83. return (TextProperties) property;
  84. TextProperties textProperties = new TextProperties(this);
  85. PropertyCollection.Add(textProperties);
  86. return textProperties;
  87. }
  88. set
  89. {
  90. if (PropertyCollection.Contains(value))
  91. PropertyCollection.Remove(value);
  92. PropertyCollection.Add(value);
  93. }
  94. }
  95. /// <summary>
  96. /// Inits the standards.
  97. /// </summary>
  98. private void InitStandards()
  99. {
  100. PropertyCollection = new IPropertyCollection();
  101. PropertyCollection.Inserted += PropertyCollection_Inserted;
  102. PropertyCollection.Removed += PropertyCollection_Removed;
  103. // this.Document.Styles.Add(this);
  104. }
  105. /// <summary>
  106. /// Adds the list level.
  107. /// </summary>
  108. private void AddListLevel(int level)
  109. {
  110. ListLevelProperties = new ListLevelProperties(this);
  111. double spacebefore = 0.635;
  112. spacebefore *= level;
  113. string space = spacebefore.ToString().Replace(",", ".") + "cm";
  114. const string minlabelwidth = "0.635cm";
  115. ListLevelProperties.MinLabelWidth = minlabelwidth;
  116. ListLevelProperties.SpaceBefore = space;
  117. }
  118. /// <summary>
  119. /// Create the XElement that represent the Style element.
  120. /// </summary>
  121. /// <param name="typ">The style name.</param>
  122. /// <param name="level">The level number which represent this style.</param>
  123. private void NewXmlNode(ListStyles typ, int level)
  124. {
  125. if (typ == ListStyles.Bullet)
  126. {
  127. Node = new XElement(Ns.Text + "list-level-style-bullet");
  128. Node.SetAttributeValue(Ns.Text + "style-name", "Bullet_20_Symbols");
  129. Node.SetAttributeValue(Ns.Text + "bullet-char", "\u2022");
  130. AddTextPropertie();
  131. }
  132. else if (typ == ListStyles.Number)
  133. {
  134. Node = new XElement(Ns.Text + "list-level-style-number");
  135. Node.SetAttributeValue(Ns.Text + "style-name", "Numbering_20_Symbols");
  136. Node.SetAttributeValue(Ns.Style + "num-format", "1");
  137. }
  138. else
  139. throw new Exception("Unknown ListStyles typ");
  140. Node.SetAttributeValue(Ns.Text + "level", level.ToString());
  141. Node.SetAttributeValue(Ns.Style + "num-suffix", ".");
  142. }
  143. /// <summary>
  144. /// Add the TextPropertie, necessary if the list is a bullet list.
  145. /// </summary>
  146. private void AddTextPropertie()
  147. {
  148. TextProperties = new TextProperties(this) {FontName = "StarSymbol"};
  149. }
  150. /// <summary>
  151. /// Properties the collection_ inserted.
  152. /// </summary>
  153. /// <param name="index">The index.</param>
  154. /// <param name="value">The value.</param>
  155. private void PropertyCollection_Inserted(int index, object value)
  156. {
  157. Node.Add(((IProperty) value).Node);
  158. }
  159. /// <summary>
  160. /// Properties the collection_ removed.
  161. /// </summary>
  162. /// <param name="index">The index.</param>
  163. /// <param name="value">The value.</param>
  164. private static void PropertyCollection_Removed(int index, object value)
  165. {
  166. ((IProperty) value).Node.Remove();
  167. }
  168. }
  169. }
  170. /*
  171. * $Log: ListLevelStyle.cs,v $
  172. * Revision 1.2 2008/04/29 15:39:54 mt
  173. * new copyright header
  174. *
  175. * Revision 1.1 2007/02/25 08:58:48 larsbehr
  176. * initial checkin, import from Sourceforge.net to OpenOffice.org
  177. *
  178. * Revision 1.2 2006/01/29 18:52:51 larsbm
  179. * - Added support for common styles (style templates in OpenOffice)
  180. * - Draw TextBox import and export
  181. * - DrawTextBox html export
  182. *
  183. * Revision 1.1 2006/01/29 11:28:23 larsbm
  184. * - Changes for the new version. 1.2. see next changelog for details
  185. *
  186. * Revision 1.2 2005/11/20 17:31:20 larsbm
  187. * - added suport for XLinks, TabStopStyles
  188. * - First experimental of loading dcuments
  189. * - load and save via importer and exporter interfaces
  190. *
  191. * Revision 1.1 2005/10/09 15:52:47 larsbm
  192. * - Changed some design at the paragraph usage
  193. * - add list support
  194. *
  195. */