PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/AODL/Document/Forms/Controls/ODFGrid.cs

https://bitbucket.org/chrisc/aodl
C# | 189 lines | 108 code | 19 blank | 62 comment | 8 complexity | 14f981500300c53982e071a99734936a 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.Content;
  24. namespace AODL.Document.Forms.Controls
  25. {
  26. public class ODFGrid : ODFFormControl
  27. {
  28. /// <summary>
  29. /// Creates an ODFGrid
  30. /// </summary>
  31. /// <param name="parentForm">Parent form that the control belongs to</param>
  32. /// <param name="contentCollection">Collection of content where the control will be referenced</param>
  33. /// <param name="id">Control ID. Please specify a unique ID!</param>
  34. public ODFGrid(ODFForm parentForm, ContentCollection contentCollection, string id)
  35. : base(parentForm, contentCollection, id)
  36. {
  37. Columns = new ODFGridColumnCollection();
  38. RestoreColumnEvents();
  39. }
  40. /// <summary>
  41. /// Creates an ODFGrid
  42. /// </summary>
  43. /// <param name="parentForm">Parent form that the control belongs to</param>
  44. /// <param name="contentCollection">Collection of content where the control will be referenced</param>
  45. /// <param name="id">Control ID. Please specify a unique ID!</param>
  46. /// <param name="x">X coordinate of the control in ODF format (eg. "1cm", "15mm", 3.2cm" etc)</param>
  47. /// <param name="y">Y coordinate of the control in ODF format (eg. "1cm", "15mm", 3.2cm" etc)</param>
  48. /// <param name="width">Width of the control in ODF format (eg. "1cm", "15mm", 3.2cm" etc)</param>
  49. /// <param name="height">Height of the control in ODF format (eg. "1cm", "15mm", 3.2cm" etc)</param>
  50. public ODFGrid(ODFForm parentForm, ContentCollection contentCollection, string id, string x, string y,
  51. string width, string height) : base(parentForm, contentCollection, id, x, y, width, height)
  52. {
  53. Columns = new ODFGridColumnCollection();
  54. RestoreColumnEvents();
  55. }
  56. public ODFGrid(ODFForm parentForm, XElement node) : base(parentForm, node)
  57. {
  58. Columns = new ODFGridColumnCollection();
  59. RestoreColumnEvents();
  60. }
  61. /// <summary>
  62. /// The collection of the ODFGridColumns (each column stand for a list box element)
  63. /// </summary>
  64. public ODFGridColumnCollection Columns { get; set; }
  65. public override string Type
  66. {
  67. get { return "grid"; }
  68. }
  69. /// <summary>
  70. /// Specifies whether or not a control can accept user input
  71. /// </summary>
  72. public bool? Disabled
  73. {
  74. get { return (bool?) Node.Attribute(Ns.Form + "disabled"); }
  75. set { Node.SetAttributeValue(Ns.Form + "disabled", value); }
  76. }
  77. /// <summary>
  78. /// Contains additional information about a control.
  79. /// </summary>
  80. public string Title
  81. {
  82. get { return (string) Node.Attribute(Ns.Form + "title"); }
  83. set { Node.SetAttributeValue(Ns.Form + "title", value); }
  84. }
  85. /// <summary>
  86. /// Specifies the tabbing navigation order of a control within a form
  87. /// </summary>
  88. public int TabIndex
  89. {
  90. get { return (int) Node.Attribute(Ns.Form + "tab-index"); }
  91. set { Node.SetAttributeValue(Ns.Form + "tab-index", value); }
  92. }
  93. /// <summary>
  94. /// Specifies whether or not a control is included in the tabbing
  95. /// navigation order
  96. /// </summary>
  97. public bool? TabStop
  98. {
  99. get { return (bool?) Node.Attribute(Ns.Form + "tab-stop"); }
  100. set { Node.SetAttributeValue(Ns.Form + "tab-stop", value); }
  101. }
  102. /// <summary>
  103. /// Specifies whether or not a control is printed when a user prints
  104. /// the document in which the control is contained
  105. /// </summary>
  106. public bool? Printable
  107. {
  108. get { return (bool?) Node.Attribute(Ns.Form + "printable"); }
  109. set { Node.SetAttributeValue(Ns.Form + "printable", value); }
  110. }
  111. public void SuppressColumnEvents()
  112. {
  113. Columns.Inserted -= ColumnCollection_Inserted;
  114. Columns.Removed -= ColumnCollection_Removed;
  115. }
  116. public void RestoreColumnEvents()
  117. {
  118. Columns.Inserted += ColumnCollection_Inserted;
  119. Columns.Removed += ColumnCollection_Removed;
  120. }
  121. private void ColumnCollection_Inserted(int index, object value)
  122. {
  123. ODFGridColumn col = (ODFGridColumn) value;
  124. Node.Add(col.Node);
  125. }
  126. private static void ColumnCollection_Removed(int index, object value)
  127. {
  128. ODFGridColumn col = value as ODFGridColumn;
  129. if (col != null)
  130. col.Node.Remove();
  131. }
  132. /// <summary>
  133. /// Looks for a specified column by its value
  134. /// </summary>
  135. /// <param name="name">column value</param>
  136. /// <returns></returns>
  137. public ODFGridColumn GetColumnByName(string name)
  138. {
  139. foreach (ODFGridColumn col in Columns)
  140. {
  141. if (col.Name == name)
  142. {
  143. return col;
  144. }
  145. }
  146. return null;
  147. }
  148. public void FixColumnCollection()
  149. {
  150. Columns.Clear();
  151. SuppressColumnEvents();
  152. foreach (XElement nodeChild in Node.Elements())
  153. {
  154. if (nodeChild.Name == Ns.Form + "column" && nodeChild.Parent == Node)
  155. {
  156. ODFGridColumn sp = new ODFGridColumn(_document, nodeChild);
  157. Columns.Add(sp);
  158. }
  159. }
  160. RestoreColumnEvents();
  161. }
  162. protected override void CreateBasicNode()
  163. {
  164. XElement xe = new XElement(Ns.Form + "grid");
  165. Node.Add(xe);
  166. Node = xe;
  167. ControlImplementation = "ooo:com.sun.star.form.component.GridControl";
  168. }
  169. }
  170. }