Style.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Authors:
  23. // Peter Bartok ([email protected])
  24. //
  25. //
  26. // COMPLETE
  27. namespace System.Windows.Forms.RTF {
  28. internal class Style {
  29. #region Local Variables
  30. public const int NoStyleNum = 222;
  31. public const int NormalStyleNum = 0;
  32. private string name;
  33. private StyleType type;
  34. private bool additive;
  35. private int num;
  36. private int based_on;
  37. private int next_par;
  38. private int se_list;
  39. private bool expanding;
  40. private StyleElement elements;
  41. private Style next;
  42. #endregion Local Variables
  43. #region Constructors
  44. public Style(RTF rtf) {
  45. num = -1;
  46. type = StyleType.Paragraph;
  47. based_on = NoStyleNum;
  48. next_par = -1;
  49. lock (rtf) {
  50. if (rtf.Styles == null) {
  51. rtf.Styles = this;
  52. } else {
  53. Style s = rtf.Styles;
  54. while (s.next != null)
  55. s = s.next;
  56. s.next = this;
  57. }
  58. }
  59. }
  60. #endregion // Constructors
  61. #region Properties
  62. public string Name {
  63. get {
  64. return name;
  65. }
  66. set {
  67. name = value;
  68. }
  69. }
  70. public StyleType Type {
  71. get {
  72. return type;
  73. }
  74. set {
  75. type = value;
  76. }
  77. }
  78. public bool Additive {
  79. get {
  80. return additive;
  81. }
  82. set {
  83. additive = value;
  84. }
  85. }
  86. public int BasedOn {
  87. get {
  88. return based_on;
  89. }
  90. set {
  91. based_on = value;
  92. }
  93. }
  94. public StyleElement Elements {
  95. get {
  96. return elements;
  97. }
  98. set {
  99. elements = value;
  100. }
  101. }
  102. public bool Expanding {
  103. get {
  104. return expanding;
  105. }
  106. set {
  107. expanding = value;
  108. }
  109. }
  110. public int NextPar {
  111. get {
  112. return next_par;
  113. }
  114. set {
  115. next_par = value;
  116. }
  117. }
  118. public int Num {
  119. get {
  120. return num;
  121. }
  122. set {
  123. num = value;
  124. }
  125. }
  126. #endregion // Properties
  127. #region Methods
  128. public void Expand(RTF rtf) {
  129. StyleElement se;
  130. if (num == -1) {
  131. return;
  132. }
  133. if (expanding) {
  134. throw new Exception("Recursive style expansion");
  135. }
  136. expanding = true;
  137. if (num != based_on) {
  138. rtf.SetToken(TokenClass.Control, Major.ParAttr, Minor.StyleNum, based_on, "\\s");
  139. rtf.RouteToken();
  140. }
  141. se = elements;
  142. while (se != null) {
  143. rtf.TokenClass = se.TokenClass;
  144. rtf.Major = se.Major;
  145. rtf.Minor = se.Minor;
  146. rtf.Param = se.Param;
  147. rtf.Text = se.Text;
  148. rtf.RouteToken();
  149. }
  150. expanding = false;
  151. }
  152. static public Style GetStyle(RTF rtf, int style_number) {
  153. Style s;
  154. lock (rtf) {
  155. s = GetStyle(rtf.Styles, style_number);
  156. }
  157. return s;
  158. }
  159. static public Style GetStyle(Style start, int style_number) {
  160. Style s;
  161. if (style_number == -1) {
  162. return start;
  163. }
  164. s = start;
  165. while ((s != null) && (s.num != style_number)) {
  166. s = s.next;
  167. }
  168. return s;
  169. }
  170. #endregion // Methods
  171. }
  172. }