Style.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #if RTF_LIB
  29. public
  30. #else
  31. internal
  32. #endif
  33. class Style {
  34. #region Local Variables
  35. public const int NoStyleNum = 222;
  36. public const int NormalStyleNum = 0;
  37. private string name;
  38. private StyleType type;
  39. private bool additive;
  40. private int num;
  41. private int based_on;
  42. private int next_par;
  43. private bool expanding;
  44. private StyleElement elements;
  45. private Style next;
  46. #endregion Local Variables
  47. #region Constructors
  48. public Style(RTF rtf) {
  49. num = -1;
  50. type = StyleType.Paragraph;
  51. based_on = NoStyleNum;
  52. next_par = -1;
  53. lock (rtf) {
  54. if (rtf.Styles == null) {
  55. rtf.Styles = this;
  56. } else {
  57. Style s = rtf.Styles;
  58. while (s.next != null)
  59. s = s.next;
  60. s.next = this;
  61. }
  62. }
  63. }
  64. #endregion // Constructors
  65. #region Properties
  66. public string Name {
  67. get {
  68. return name;
  69. }
  70. set {
  71. name = value;
  72. }
  73. }
  74. public StyleType Type {
  75. get {
  76. return type;
  77. }
  78. set {
  79. type = value;
  80. }
  81. }
  82. public bool Additive {
  83. get {
  84. return additive;
  85. }
  86. set {
  87. additive = value;
  88. }
  89. }
  90. public int BasedOn {
  91. get {
  92. return based_on;
  93. }
  94. set {
  95. based_on = value;
  96. }
  97. }
  98. public StyleElement Elements {
  99. get {
  100. return elements;
  101. }
  102. set {
  103. elements = value;
  104. }
  105. }
  106. public bool Expanding {
  107. get {
  108. return expanding;
  109. }
  110. set {
  111. expanding = value;
  112. }
  113. }
  114. public int NextPar {
  115. get {
  116. return next_par;
  117. }
  118. set {
  119. next_par = value;
  120. }
  121. }
  122. public int Num {
  123. get {
  124. return num;
  125. }
  126. set {
  127. num = value;
  128. }
  129. }
  130. #endregion // Properties
  131. #region Methods
  132. public void Expand(RTF rtf) {
  133. StyleElement se;
  134. if (num == -1) {
  135. return;
  136. }
  137. if (expanding) {
  138. throw new Exception("Recursive style expansion");
  139. }
  140. expanding = true;
  141. if (num != based_on) {
  142. rtf.SetToken(TokenClass.Control, Major.ParAttr, Minor.StyleNum, based_on, "\\s");
  143. rtf.RouteToken();
  144. }
  145. se = elements;
  146. while (se != null) {
  147. rtf.TokenClass = se.TokenClass;
  148. rtf.Major = se.Major;
  149. rtf.Minor = se.Minor;
  150. rtf.Param = se.Param;
  151. rtf.Text = se.Text;
  152. rtf.RouteToken();
  153. }
  154. expanding = false;
  155. }
  156. static public Style GetStyle(RTF rtf, int style_number) {
  157. Style s;
  158. lock (rtf) {
  159. s = GetStyle(rtf.Styles, style_number);
  160. }
  161. return s;
  162. }
  163. static public Style GetStyle(Style start, int style_number) {
  164. Style s;
  165. if (style_number == -1) {
  166. return start;
  167. }
  168. s = start;
  169. while ((s != null) && (s.num != style_number)) {
  170. s = s.next;
  171. }
  172. return s;
  173. }
  174. #endregion // Methods
  175. }
  176. }