Style.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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 Dennis Bartok ([email protected])
  24. //
  25. //
  26. using System.ComponentModel;
  27. using System.Drawing;
  28. using System.Security.Permissions;
  29. namespace System.Web.UI.WebControls {
  30. // CAS
  31. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  32. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  33. // attributes
  34. #if NET_2_0
  35. // Not until we actually have StyleConverter
  36. // [TypeConverter(typeof(System.Web.UI.WebControls.StyleConverter))]
  37. #else
  38. [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
  39. #endif
  40. [ToolboxItem("")]
  41. public class Style : System.ComponentModel.Component, System.Web.UI.IStateManager
  42. {
  43. internal const string BitStateKey = "_!SB";
  44. [Flags]
  45. public enum Styles
  46. {
  47. BackColor = 0x00000008,
  48. BorderColor = 0x00000010,
  49. BorderStyle = 0x00000040,
  50. BorderWidth = 0x00000020,
  51. CssClass = 0x00000002,
  52. Font = 0x00000001,
  53. ForeColor = 0x00000004,
  54. Height = 0x00000080,
  55. Width = 0x00000100,
  56. FontAll = 0xFE00,
  57. FontBold = 0x800,
  58. FontItalic = 0x1000,
  59. FontNames = 0x200,
  60. FontOverline = 0x4000,
  61. FontSize = 0x400,
  62. FontStrikeout = 0x8000,
  63. FontUnderline = 0x2000
  64. }
  65. #region Fields
  66. int styles;
  67. int stylesTraked;
  68. internal StateBag viewstate;
  69. FontInfo fontinfo;
  70. bool tracking;
  71. bool _isSharedViewState;
  72. #if NET_2_0
  73. string registered_class;
  74. #endif
  75. #endregion // Fields
  76. #region Public Constructors
  77. public Style()
  78. {
  79. viewstate = new StateBag ();
  80. GC.SuppressFinalize (this);
  81. }
  82. public Style(System.Web.UI.StateBag bag)
  83. {
  84. viewstate = bag;
  85. if (viewstate == null)
  86. viewstate = new StateBag ();
  87. _isSharedViewState = true;
  88. GC.SuppressFinalize (this);
  89. }
  90. #endregion // Public Constructors
  91. #region Public Instance Properties
  92. #if !NET_2_0
  93. [Bindable(true)]
  94. #endif
  95. [DefaultValue(typeof (Color), "")]
  96. [NotifyParentProperty(true)]
  97. [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
  98. [WebSysDescription ("")]
  99. [WebCategory ("Appearance")]
  100. public Color BackColor
  101. {
  102. get
  103. {
  104. if (!CheckBit ((int) Styles.BackColor))
  105. {
  106. return Color.Empty;
  107. }
  108. return (Color)viewstate["BackColor"];
  109. }
  110. set
  111. {
  112. viewstate["BackColor"] = value;
  113. SetBit ((int) Styles.BackColor);
  114. }
  115. }
  116. #if !NET_2_0
  117. [Bindable(true)]
  118. #endif
  119. [DefaultValue(typeof (Color), "")]
  120. [NotifyParentProperty(true)]
  121. [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
  122. [WebSysDescription ("")]
  123. [WebCategory ("Appearance")]
  124. public Color BorderColor
  125. {
  126. get
  127. {
  128. if (!CheckBit ((int) Styles.BorderColor))
  129. {
  130. return Color.Empty;
  131. }
  132. return (Color)viewstate["BorderColor"];
  133. }
  134. set
  135. {
  136. viewstate["BorderColor"] = value;
  137. SetBit ((int) Styles.BorderColor);
  138. }
  139. }
  140. #if !NET_2_0
  141. [Bindable(true)]
  142. #endif
  143. [DefaultValue(BorderStyle.NotSet)]
  144. [NotifyParentProperty(true)]
  145. [WebSysDescription ("")]
  146. [WebCategory ("Appearance")]
  147. public BorderStyle BorderStyle
  148. {
  149. get
  150. {
  151. if (!CheckBit ((int) Styles.BorderStyle))
  152. {
  153. return BorderStyle.NotSet;
  154. }
  155. return (BorderStyle)viewstate["BorderStyle"];
  156. }
  157. set
  158. {
  159. if (value < BorderStyle.NotSet || value > BorderStyle.Outset)
  160. throw new ArgumentOutOfRangeException ("value", "The selected value is not one of the BorderStyle enumeration values.");
  161. viewstate["BorderStyle"] = value;
  162. SetBit ((int) Styles.BorderStyle);
  163. }
  164. }
  165. #if !NET_2_0
  166. [Bindable(true)]
  167. #endif
  168. [DefaultValue(typeof (Unit), "")]
  169. [NotifyParentProperty(true)]
  170. [WebSysDescription ("")]
  171. [WebCategory ("Appearance")]
  172. public Unit BorderWidth
  173. {
  174. get
  175. {
  176. if (!CheckBit ((int) Styles.BorderWidth))
  177. {
  178. return Unit.Empty;
  179. }
  180. return (Unit)viewstate["BorderWidth"];
  181. }
  182. set
  183. {
  184. if (value.Value < 0)
  185. {
  186. throw new ArgumentOutOfRangeException("Value", value.Value, "BorderWidth must not be negative");
  187. }
  188. viewstate["BorderWidth"] = value;
  189. SetBit ((int) Styles.BorderWidth);
  190. }
  191. }
  192. [DefaultValue("")]
  193. [NotifyParentProperty(true)]
  194. [WebSysDescription ("")]
  195. [WebCategory ("Appearance")]
  196. public string CssClass
  197. {
  198. get
  199. {
  200. if (!CheckBit ((int) Styles.CssClass))
  201. {
  202. return String.Empty;
  203. }
  204. string ret = viewstate["CssClass"] as string;
  205. if (ret == null)
  206. return String.Empty;
  207. return ret;
  208. }
  209. set
  210. {
  211. viewstate["CssClass"] = value;
  212. SetBit ((int) Styles.CssClass);
  213. }
  214. }
  215. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  216. [NotifyParentProperty(true)]
  217. [WebSysDescription ("")]
  218. [WebCategory ("Appearance")]
  219. public FontInfo Font
  220. {
  221. get
  222. {
  223. if (fontinfo == null)
  224. {
  225. fontinfo = new FontInfo(this);
  226. }
  227. return fontinfo;
  228. }
  229. }
  230. #if !NET_2_0
  231. [Bindable(true)]
  232. #endif
  233. [DefaultValue(typeof (Color), "")]
  234. [NotifyParentProperty(true)]
  235. [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
  236. [WebSysDescription ("")]
  237. [WebCategory ("Appearance")]
  238. public Color ForeColor
  239. {
  240. get
  241. {
  242. if (!CheckBit ((int) Styles.ForeColor))
  243. {
  244. return Color.Empty;
  245. }
  246. return (Color)viewstate["ForeColor"];
  247. }
  248. set
  249. {
  250. viewstate["ForeColor"] = value;
  251. SetBit ((int) Styles.ForeColor);
  252. }
  253. }
  254. #if !NET_2_0
  255. [Bindable(true)]
  256. #endif
  257. [DefaultValue(typeof (Unit), "")]
  258. [NotifyParentProperty(true)]
  259. [WebSysDescription ("")]
  260. [WebCategory ("Appearance")]
  261. public Unit Height
  262. {
  263. get
  264. {
  265. if (!CheckBit ((int) Styles.Height))
  266. {
  267. return Unit.Empty;
  268. }
  269. return (Unit)viewstate["Height"];
  270. }
  271. set
  272. {
  273. if (value.Value < 0)
  274. {
  275. throw new ArgumentOutOfRangeException("Value", value.Value, "Height must not be negative");
  276. }
  277. viewstate["Height"] = value;
  278. SetBit ((int) Styles.Height);
  279. }
  280. }
  281. #if !NET_2_0
  282. [Bindable(true)]
  283. #endif
  284. [DefaultValue(typeof (Unit), "")]
  285. [NotifyParentProperty(true)]
  286. [WebSysDescription ("")]
  287. [WebCategory ("Appearance")]
  288. public Unit Width
  289. {
  290. get
  291. {
  292. if (!CheckBit ((int) Styles.Width))
  293. {
  294. return Unit.Empty;
  295. }
  296. return (Unit)viewstate["Width"];
  297. }
  298. set
  299. {
  300. if (value.Value < 0)
  301. {
  302. throw new ArgumentOutOfRangeException("Value", value.Value, "Width must not be negative");
  303. }
  304. viewstate["Width"] = value;
  305. SetBit ((int) Styles.Width);
  306. }
  307. }
  308. #endregion // Public Instance Properties
  309. #region Protected Instance Properties
  310. #if NET_2_0
  311. [Browsable (false)]
  312. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  313. public virtual bool IsEmpty
  314. #else
  315. protected internal virtual bool IsEmpty
  316. #endif
  317. {
  318. get
  319. {
  320. #if NET_2_0
  321. return (styles == 0 && RegisteredCssClass.Length == 0);
  322. #else
  323. return (styles == 0);
  324. #endif
  325. }
  326. }
  327. protected bool IsTrackingViewState
  328. {
  329. get
  330. {
  331. return tracking;
  332. }
  333. }
  334. [Browsable(false)]
  335. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  336. protected internal StateBag ViewState
  337. {
  338. get
  339. {
  340. return viewstate;
  341. }
  342. }
  343. #endregion // Protected Instance Properties
  344. #region Internal Instance Properties
  345. internal bool AlwaysRenderTextDecoration
  346. {
  347. get
  348. {
  349. if (viewstate["AlwaysRenderTextDecoration"] == null)
  350. return false;
  351. return (bool)viewstate["AlwaysRenderTextDecoration"];
  352. }
  353. set
  354. {
  355. viewstate["AlwaysRenderTextDecoration"] = value;
  356. }
  357. }
  358. #endregion // Internal Instance Properties
  359. #region Public Instance Methods
  360. public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
  361. {
  362. AddAttributesToRender(writer, null);
  363. }
  364. public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
  365. {
  366. #if NET_2_0
  367. if (RegisteredCssClass.Length > 0) {
  368. string cssclass = CssClass;
  369. if (!String.IsNullOrEmpty (cssclass))
  370. writer.AddAttribute (HtmlTextWriterAttribute.Class, cssclass + " " + RegisteredCssClass);
  371. else
  372. writer.AddAttribute (HtmlTextWriterAttribute.Class, RegisteredCssClass);
  373. }
  374. else
  375. #endif
  376. {
  377. string cssclass = CssClass;
  378. if (cssclass != null && cssclass.Length > 0)
  379. writer.AddAttribute (HtmlTextWriterAttribute.Class, cssclass);
  380. #if NET_2_0
  381. CssStyleCollection col = new CssStyleCollection ();
  382. FillStyleAttributes (col, owner);
  383. foreach (string key in col.Keys) {
  384. writer.AddStyleAttribute (key, col [key]);
  385. }
  386. #else
  387. WriteStyleAttributes (writer);
  388. #endif
  389. }
  390. }
  391. #if ONLY_1_1
  392. void WriteStyleAttributes (HtmlTextWriter writer)
  393. {
  394. string s;
  395. Color color;
  396. BorderStyle bs;
  397. Unit u;
  398. if (CheckBit ((int) Styles.BackColor)) {
  399. color = (Color)viewstate["BackColor"];
  400. if (!color.IsEmpty)
  401. writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  402. }
  403. if (CheckBit ((int) Styles.BorderColor)) {
  404. color = (Color)viewstate["BorderColor"];
  405. if (!color.IsEmpty)
  406. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  407. }
  408. bool have_width = false;
  409. if (CheckBit ((int) Styles.BorderWidth)) {
  410. u = (Unit)viewstate["BorderWidth"];
  411. if (!u.IsEmpty) {
  412. if (u.Value > 0)
  413. have_width = true;
  414. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
  415. }
  416. }
  417. if (CheckBit ((int) Styles.BorderStyle)) {
  418. bs = (BorderStyle)viewstate["BorderStyle"];
  419. if (bs != BorderStyle.NotSet)
  420. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
  421. else {
  422. if (CheckBit ((int) Styles.BorderWidth))
  423. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  424. }
  425. } else if (have_width) {
  426. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  427. }
  428. if (CheckBit ((int) Styles.ForeColor)) {
  429. color = (Color)viewstate["ForeColor"];
  430. if (!color.IsEmpty)
  431. writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  432. }
  433. if (CheckBit ((int) Styles.Height)) {
  434. u = (Unit)viewstate["Height"];
  435. if (!u.IsEmpty)
  436. writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
  437. }
  438. if (CheckBit ((int) Styles.Width)) {
  439. u = (Unit)viewstate["Width"];
  440. if (!u.IsEmpty)
  441. writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
  442. }
  443. if (CheckBit ((int) Style.Styles.FontAll)) {
  444. // Fonts are a bit weird
  445. FontInfo font = Font;
  446. if (font.Name != string.Empty) {
  447. s = font.Names[0];
  448. for (int i = 1; i < font.Names.Length; i++)
  449. s += "," + font.Names[i];
  450. writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
  451. }
  452. if (font.Bold)
  453. writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
  454. if (font.Italic)
  455. writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
  456. if (!font.Size.IsEmpty)
  457. writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, font.Size.ToString());
  458. // These styles are munged into a attribute decoration
  459. s = string.Empty;
  460. if (font.Overline)
  461. s += "overline ";
  462. if (font.Strikeout)
  463. s += "line-through ";
  464. if (font.Underline)
  465. s += "underline ";
  466. s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
  467. if (s != "")
  468. writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
  469. }
  470. }
  471. #endif
  472. #if NET_2_0
  473. protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
  474. {
  475. Color color;
  476. BorderStyle bs;
  477. Unit u;
  478. if (CheckBit ((int) Styles.BackColor))
  479. {
  480. color = (Color)viewstate["BackColor"];
  481. if (!color.IsEmpty)
  482. attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  483. }
  484. if (CheckBit ((int) Styles.BorderColor))
  485. {
  486. color = (Color)viewstate["BorderColor"];
  487. if (!color.IsEmpty)
  488. attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  489. }
  490. bool have_width = false;
  491. if (CheckBit ((int) Styles.BorderWidth)) {
  492. u = (Unit) viewstate ["BorderWidth"];
  493. if (!u.IsEmpty) {
  494. if (u.Value > 0)
  495. have_width = true;
  496. attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString ());
  497. }
  498. }
  499. if (CheckBit ((int) Styles.BorderStyle)) {
  500. bs = (BorderStyle) viewstate ["BorderStyle"];
  501. if (bs != BorderStyle.NotSet)
  502. attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString ());
  503. else if (have_width)
  504. attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
  505. }
  506. else if (have_width) {
  507. attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
  508. }
  509. if (CheckBit ((int) Styles.ForeColor))
  510. {
  511. color = (Color)viewstate["ForeColor"];
  512. if (!color.IsEmpty)
  513. attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  514. }
  515. if (CheckBit ((int) Styles.Height))
  516. {
  517. u = (Unit)viewstate["Height"];
  518. if (!u.IsEmpty)
  519. attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
  520. }
  521. if (CheckBit ((int) Styles.Width))
  522. {
  523. u = (Unit)viewstate["Width"];
  524. if (!u.IsEmpty)
  525. attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
  526. }
  527. Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
  528. }
  529. #endif
  530. public virtual void CopyFrom(Style s)
  531. {
  532. if ((s == null) || s.IsEmpty)
  533. {
  534. return;
  535. }
  536. if (s.fontinfo != null)
  537. {
  538. Font.CopyFrom(s.fontinfo);
  539. }
  540. if ((s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
  541. {
  542. this.BackColor = s.BackColor;
  543. }
  544. if ((s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty))
  545. {
  546. this.BorderColor = s.BorderColor;
  547. }
  548. if ((s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
  549. {
  550. this.BorderStyle = s.BorderStyle;
  551. }
  552. if ((s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
  553. {
  554. this.BorderWidth = s.BorderWidth;
  555. }
  556. if ((s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
  557. {
  558. this.CssClass = s.CssClass;
  559. }
  560. if ((s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
  561. {
  562. this.ForeColor = s.ForeColor;
  563. }
  564. if ((s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
  565. {
  566. this.Height = s.Height;
  567. }
  568. if ((s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
  569. {
  570. this.Width = s.Width;
  571. }
  572. }
  573. public virtual void MergeWith(Style s)
  574. {
  575. if ((s == null) || (s.IsEmpty))
  576. {
  577. return;
  578. }
  579. if (s.fontinfo != null)
  580. {
  581. Font.MergeWith(s.fontinfo);
  582. }
  583. if ((!CheckBit ((int) Styles.BackColor)) && (s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
  584. {
  585. this.BackColor = s.BackColor;
  586. }
  587. if ((!CheckBit ((int) Styles.BorderColor)) && (s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty))
  588. {
  589. this.BorderColor = s.BorderColor;
  590. }
  591. if ((!CheckBit ((int) Styles.BorderStyle)) && (s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
  592. {
  593. this.BorderStyle = s.BorderStyle;
  594. }
  595. if ((!CheckBit ((int) Styles.BorderWidth)) && (s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
  596. {
  597. this.BorderWidth = s.BorderWidth;
  598. }
  599. if ((!CheckBit ((int) Styles.CssClass)) && (s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
  600. {
  601. this.CssClass = s.CssClass;
  602. }
  603. if ((!CheckBit ((int) Styles.ForeColor)) && (s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
  604. {
  605. this.ForeColor = s.ForeColor;
  606. }
  607. if ((!CheckBit ((int) Styles.Height)) && (s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
  608. {
  609. this.Height = s.Height;
  610. }
  611. if ((!CheckBit ((int) Styles.Width)) && (s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
  612. {
  613. this.Width = s.Width;
  614. }
  615. }
  616. /*
  617. internal void Print ()
  618. {
  619. Console.WriteLine ("BackColor: {0}", BackColor);
  620. Console.WriteLine ("BorderColor: {0}", BorderColor);
  621. Console.WriteLine ("BorderStyle: {0}", BorderStyle);
  622. Console.WriteLine ("BorderWidth: {0}", BorderWidth);
  623. Console.WriteLine ("CssClass: {0}", CssClass);
  624. Console.WriteLine ("ForeColor: {0}", ForeColor);
  625. Console.WriteLine ("Height: {0}", Height);
  626. Console.WriteLine ("Width: {0}", Width);
  627. }
  628. */
  629. public virtual void Reset()
  630. {
  631. viewstate.Remove("BackColor");
  632. viewstate.Remove("BorderColor");
  633. viewstate.Remove("BorderStyle");
  634. viewstate.Remove("BorderWidth");
  635. viewstate.Remove("CssClass");
  636. viewstate.Remove("ForeColor");
  637. viewstate.Remove("Height");
  638. viewstate.Remove("Width");
  639. if (fontinfo != null)
  640. {
  641. fontinfo.Reset();
  642. }
  643. styles = 0;
  644. viewstate.Remove (BitStateKey);
  645. stylesTraked = 0;
  646. }
  647. #if ONLY_1_1
  648. public override string ToString()
  649. {
  650. return string.Empty;
  651. }
  652. #endif
  653. #endregion // Public Instance Methods
  654. #region Protected Instance Methods
  655. protected internal void LoadViewState(object state)
  656. {
  657. viewstate.LoadViewState(state);
  658. LoadBitState ();
  659. }
  660. protected internal virtual object SaveViewState ()
  661. {
  662. SaveBitState ();
  663. if (_isSharedViewState)
  664. return null;
  665. return viewstate.SaveViewState ();
  666. }
  667. internal void SaveBitState ()
  668. {
  669. if (stylesTraked != 0)
  670. viewstate [BitStateKey] = stylesTraked;
  671. }
  672. internal void LoadBitState () {
  673. if (viewstate [BitStateKey] == null)
  674. return;
  675. int bit = (int) viewstate [BitStateKey];
  676. styles |= bit;
  677. stylesTraked |= bit;
  678. }
  679. protected internal virtual void SetBit( int bit )
  680. {
  681. styles |= bit;
  682. if (tracking)
  683. stylesTraked |= bit;
  684. }
  685. internal void RemoveBit (int bit) {
  686. styles &= ~bit;
  687. if (tracking) {
  688. stylesTraked &= ~bit;
  689. if (stylesTraked == 0)
  690. viewstate.Remove (BitStateKey);
  691. }
  692. }
  693. internal bool CheckBit (int bit) {
  694. return (styles & bit) != 0;
  695. }
  696. protected internal virtual void TrackViewState ()
  697. {
  698. tracking = true;
  699. viewstate.TrackViewState();
  700. }
  701. #endregion // Protected Instance Methods
  702. #region IStateManager Properties & Methods
  703. void IStateManager.LoadViewState(object state)
  704. {
  705. LoadViewState(state);
  706. }
  707. object IStateManager.SaveViewState()
  708. {
  709. return SaveViewState();
  710. }
  711. void IStateManager.TrackViewState()
  712. {
  713. TrackViewState();
  714. }
  715. bool IStateManager.IsTrackingViewState
  716. {
  717. get
  718. {
  719. return this.IsTrackingViewState;
  720. }
  721. }
  722. #endregion // IStateManager Properties & Methods
  723. #if NET_2_0
  724. internal void SetRegisteredCssClass (string name)
  725. {
  726. registered_class = name;
  727. }
  728. public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
  729. {
  730. CssStyleCollection col = new CssStyleCollection ();
  731. FillStyleAttributes (col, resolver);
  732. return col;
  733. }
  734. [EditorBrowsable(EditorBrowsableState.Advanced)]
  735. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  736. [Browsable(false)]
  737. public string RegisteredCssClass {
  738. get {
  739. if (registered_class == null)
  740. registered_class = String.Empty;
  741. return registered_class;
  742. }
  743. }
  744. internal void CopyTextStylesFrom (Style source) {
  745. // Used primary for TreeView and Menu
  746. if (source.CheckBit ((int) Styles.ForeColor)) {
  747. ForeColor = source.ForeColor;
  748. }
  749. if (source.CheckBit((int) Styles.FontAll)) {
  750. Font.CopyFrom (source.Font);
  751. }
  752. }
  753. internal void RemoveTextStyles () {
  754. ForeColor = Color.Empty;
  755. fontinfo = null;
  756. }
  757. internal void AddCssClass (string cssClass) {
  758. if (String.IsNullOrEmpty (cssClass))
  759. return;
  760. if (CssClass.Length > 0)
  761. CssClass += " ";
  762. CssClass += cssClass;
  763. }
  764. public void SetDirty ()
  765. {
  766. if (viewstate != null)
  767. viewstate.SetDirty (true);
  768. stylesTraked = styles;
  769. }
  770. #endif
  771. }
  772. }