PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/AODL/Document/Styles/ListStyle.cs

https://bitbucket.org/chrisc/aodl
C# | 158 lines | 50 code | 12 blank | 96 comment | 1 complexity | b10ed16e09dcd602925cbe0286c36f9c 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.Xml.Linq;
  23. using AODL.Document.Styles.Properties;
  24. namespace AODL.Document.Styles
  25. {
  26. /// <summary>
  27. /// Represent the ListStyle for a List.
  28. /// </summary>
  29. public class ListStyle : AbstractStyle
  30. {
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="ListStyle"/> class.
  33. /// </summary>
  34. /// <param name="document">The document.</param>
  35. /// <param name="node">The node.</param>
  36. public ListStyle(IDocument document, XElement node)
  37. {
  38. Document = document;
  39. Node = node;
  40. ListlevelStyles = new ListLevelStyleCollection();
  41. }
  42. /// <summary>
  43. /// Create a new ListStyle object.
  44. /// </summary>
  45. /// <param name="document">The docuemnt</param>
  46. /// <param name="styleName">The style name</param>
  47. public ListStyle(IDocument document, string styleName)
  48. {
  49. Document = document;
  50. Node = new XElement(Ns.Text + "tab");
  51. PropertyCollection = new IPropertyCollection();
  52. PropertyCollection.Inserted += PropertyCollection_Inserted;
  53. PropertyCollection.Removed += PropertyCollection_Removed;
  54. // this.Document.Styles.Add(this);
  55. ListlevelStyles = new ListLevelStyleCollection();
  56. StyleName = styleName;
  57. }
  58. /// <summary>
  59. /// The ListLevelStyles which belongs to this object.
  60. /// </summary>
  61. public ListLevelStyleCollection ListlevelStyles { get; set; }
  62. /// <summary>
  63. /// Add all possible ListLevelStyle objects automatically.
  64. /// Throws exception, if there are already ListLevelStyles
  65. /// which could'nt removed.
  66. /// </summary>
  67. /// <param name="typ">The Liststyle bullet, numbered, ..s</param>
  68. public void AutomaticAddListLevelStyles(ListStyles typ)
  69. {
  70. Node.RemoveNodes();
  71. ListlevelStyles.Clear();
  72. for (int i = 1; i <= 10; i++)
  73. {
  74. ListLevelStyle style = new ListLevelStyle(Document, this, typ, i);
  75. ListlevelStyles.Add(style);
  76. //this.Document.Styles.Add(style);
  77. }
  78. foreach (ListLevelStyle lls in ListlevelStyles)
  79. Node.Add(lls.Node);
  80. }
  81. /// <summary>
  82. /// Properties the collection_ inserted.
  83. /// </summary>
  84. /// <param name="index">The index.</param>
  85. /// <param name="value">The value.</param>
  86. private void PropertyCollection_Inserted(int index, object value)
  87. {
  88. Node.Add(((IProperty) value).Node);
  89. }
  90. /// <summary>
  91. /// Properties the collection_ removed.
  92. /// </summary>
  93. /// <param name="index">The index.</param>
  94. /// <param name="value">The value.</param>
  95. private static void PropertyCollection_Removed(int index, object value)
  96. {
  97. ((IProperty) value).Node.Remove();
  98. }
  99. }
  100. /// <summary>
  101. /// Represent the different kinds of lis styles.
  102. /// </summary>
  103. public enum ListStyles
  104. {
  105. /// <summary>
  106. /// Numbered list
  107. /// </summary>
  108. Number,
  109. /// <summary>
  110. /// Bullet list
  111. /// </summary>
  112. Bullet
  113. }
  114. }
  115. /*
  116. * $Log: ListStyle.cs,v $
  117. * Revision 1.2 2008/04/29 15:39:54 mt
  118. * new copyright header
  119. *
  120. * Revision 1.1 2007/02/25 08:58:49 larsbehr
  121. * initial checkin, import from Sourceforge.net to OpenOffice.org
  122. *
  123. * Revision 1.3 2006/02/21 19:34:56 larsbm
  124. * - Fixed Bug text that contains a xml tag will be imported as UnknowText and not correct displayed if document is exported as HTML.
  125. * - Fixed Bug [ 1436080 ] Common styles
  126. *
  127. * Revision 1.2 2006/01/29 18:52:51 larsbm
  128. * - Added support for common styles (style templates in OpenOffice)
  129. * - Draw TextBox import and export
  130. * - DrawTextBox html export
  131. *
  132. * Revision 1.1 2006/01/29 11:28:23 larsbm
  133. * - Changes for the new version. 1.2. see next changelog for details
  134. *
  135. * Revision 1.2 2005/12/12 19:39:17 larsbm
  136. * - Added Paragraph Header
  137. * - Added Table Row Header
  138. * - Fixed some bugs
  139. * - better whitespace handling
  140. * - Implmemenation of HTML Exporter
  141. *
  142. * Revision 1.1 2005/10/09 15:52:47 larsbm
  143. * - Changed some design at the paragraph usage
  144. * - add list support
  145. *
  146. */