Style.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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. private int styles;
  67. private int stylesTraked;
  68. internal StateBag viewstate;
  69. private FontInfo fontinfo;
  70. private bool tracking;
  71. bool _isSharedViewState;
  72. #if NET_2_0
  73. private 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. viewstate["BorderStyle"] = value;
  160. SetBit ((int) Styles.BorderStyle);
  161. }
  162. }
  163. #if !NET_2_0
  164. [Bindable(true)]
  165. #endif
  166. [DefaultValue(typeof (Unit), "")]
  167. [NotifyParentProperty(true)]
  168. [WebSysDescription ("")]
  169. [WebCategory ("Appearance")]
  170. public Unit BorderWidth
  171. {
  172. get
  173. {
  174. if (!CheckBit ((int) Styles.BorderWidth))
  175. {
  176. return Unit.Empty;
  177. }
  178. return (Unit)viewstate["BorderWidth"];
  179. }
  180. set
  181. {
  182. if (value.Value < 0)
  183. {
  184. throw new ArgumentOutOfRangeException("Value", value.Value, "BorderWidth must not be negative");
  185. }
  186. viewstate["BorderWidth"] = value;
  187. SetBit ((int) Styles.BorderWidth);
  188. }
  189. }
  190. [DefaultValue("")]
  191. [NotifyParentProperty(true)]
  192. [WebSysDescription ("")]
  193. [WebCategory ("Appearance")]
  194. public string CssClass
  195. {
  196. get
  197. {
  198. if (!CheckBit ((int) Styles.CssClass))
  199. {
  200. return string.Empty;
  201. }
  202. return (string)viewstate["CssClass"];
  203. }
  204. set
  205. {
  206. viewstate["CssClass"] = value;
  207. SetBit ((int) Styles.CssClass);
  208. }
  209. }
  210. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  211. [NotifyParentProperty(true)]
  212. [WebSysDescription ("")]
  213. [WebCategory ("Appearance")]
  214. public FontInfo Font
  215. {
  216. get
  217. {
  218. if (fontinfo == null)
  219. {
  220. fontinfo = new FontInfo(this);
  221. }
  222. return fontinfo;
  223. }
  224. }
  225. #if !NET_2_0
  226. [Bindable(true)]
  227. #endif
  228. [DefaultValue(typeof (Color), "")]
  229. [NotifyParentProperty(true)]
  230. [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
  231. [WebSysDescription ("")]
  232. [WebCategory ("Appearance")]
  233. public Color ForeColor
  234. {
  235. get
  236. {
  237. if (!CheckBit ((int) Styles.ForeColor))
  238. {
  239. return Color.Empty;
  240. }
  241. return (Color)viewstate["ForeColor"];
  242. }
  243. set
  244. {
  245. viewstate["ForeColor"] = value;
  246. SetBit ((int) Styles.ForeColor);
  247. }
  248. }
  249. #if !NET_2_0
  250. [Bindable(true)]
  251. #endif
  252. [DefaultValue(typeof (Unit), "")]
  253. [NotifyParentProperty(true)]
  254. [WebSysDescription ("")]
  255. [WebCategory ("Appearance")]
  256. public Unit Height
  257. {
  258. get
  259. {
  260. if (!CheckBit ((int) Styles.Height))
  261. {
  262. return Unit.Empty;
  263. }
  264. return (Unit)viewstate["Height"];
  265. }
  266. set
  267. {
  268. if (value.Value < 0)
  269. {
  270. throw new ArgumentOutOfRangeException("Value", value.Value, "Height must not be negative");
  271. }
  272. viewstate["Height"] = value;
  273. SetBit ((int) Styles.Height);
  274. }
  275. }
  276. #if !NET_2_0
  277. [Bindable(true)]
  278. #endif
  279. [DefaultValue(typeof (Unit), "")]
  280. [NotifyParentProperty(true)]
  281. [WebSysDescription ("")]
  282. [WebCategory ("Appearance")]
  283. public Unit Width
  284. {
  285. get
  286. {
  287. if (!CheckBit ((int) Styles.Width))
  288. {
  289. return Unit.Empty;
  290. }
  291. return (Unit)viewstate["Width"];
  292. }
  293. set
  294. {
  295. if (value.Value < 0)
  296. {
  297. throw new ArgumentOutOfRangeException("Value", value.Value, "Width must not be negative");
  298. }
  299. viewstate["Width"] = value;
  300. SetBit ((int) Styles.Width);
  301. }
  302. }
  303. #endregion // Public Instance Properties
  304. #region Protected Instance Properties
  305. #if NET_2_0
  306. [Browsable (false)]
  307. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  308. public virtual bool IsEmpty
  309. #else
  310. protected internal virtual bool IsEmpty
  311. #endif
  312. {
  313. get
  314. {
  315. #if NET_2_0
  316. return (styles == 0 && RegisteredCssClass.Length == 0);
  317. #else
  318. return (styles == 0);
  319. #endif
  320. }
  321. }
  322. protected bool IsTrackingViewState
  323. {
  324. get
  325. {
  326. return tracking;
  327. }
  328. }
  329. [Browsable(false)]
  330. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  331. protected internal StateBag ViewState
  332. {
  333. get
  334. {
  335. return viewstate;
  336. }
  337. }
  338. #endregion // Protected Instance Properties
  339. #region Internal Instance Properties
  340. internal bool AlwaysRenderTextDecoration
  341. {
  342. get
  343. {
  344. if (viewstate["AlwaysRenderTextDecoration"] == null)
  345. return false;
  346. return (bool)viewstate["AlwaysRenderTextDecoration"];
  347. }
  348. set
  349. {
  350. viewstate["AlwaysRenderTextDecoration"] = value;
  351. }
  352. }
  353. #endregion // Internal Instance Properties
  354. #region Public Instance Methods
  355. public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
  356. {
  357. AddAttributesToRender(writer, null);
  358. }
  359. public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
  360. {
  361. #if NET_2_0
  362. if (RegisteredCssClass.Length > 0) {
  363. if (CssClass.Length > 0)
  364. writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass + " " + RegisteredCssClass);
  365. else
  366. writer.AddAttribute (HtmlTextWriterAttribute.Class, RegisteredCssClass);
  367. }
  368. else
  369. #endif
  370. {
  371. if (CssClass.Length > 0)
  372. writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass);
  373. #if NET_2_0
  374. CssStyleCollection col = new CssStyleCollection ();
  375. FillStyleAttributes (col, owner);
  376. foreach (string key in col.Keys) {
  377. writer.AddStyleAttribute (key, col [key]);
  378. }
  379. #else
  380. WriteStyleAttributes (writer);
  381. #endif
  382. }
  383. }
  384. #if ONLY_1_1
  385. void WriteStyleAttributes (HtmlTextWriter writer)
  386. {
  387. string s;
  388. Color color;
  389. BorderStyle bs;
  390. Unit u;
  391. if (CheckBit ((int) Styles.BackColor)) {
  392. color = (Color)viewstate["BackColor"];
  393. if (!color.IsEmpty)
  394. writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  395. }
  396. if (CheckBit ((int) Styles.BorderColor)) {
  397. color = (Color)viewstate["BorderColor"];
  398. if (!color.IsEmpty)
  399. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  400. }
  401. bool have_width = false;
  402. if (CheckBit ((int) Styles.BorderWidth)) {
  403. u = (Unit)viewstate["BorderWidth"];
  404. if (!u.IsEmpty) {
  405. if (u.Value > 0)
  406. have_width = true;
  407. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
  408. }
  409. }
  410. if (CheckBit ((int) Styles.BorderStyle)) {
  411. bs = (BorderStyle)viewstate["BorderStyle"];
  412. if (bs != BorderStyle.NotSet)
  413. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
  414. else {
  415. if (CheckBit ((int) Styles.BorderWidth))
  416. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  417. }
  418. } else if (have_width) {
  419. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  420. }
  421. if (CheckBit ((int) Styles.ForeColor)) {
  422. color = (Color)viewstate["ForeColor"];
  423. if (!color.IsEmpty)
  424. writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  425. }
  426. if (CheckBit ((int) Styles.Height)) {
  427. u = (Unit)viewstate["Height"];
  428. if (!u.IsEmpty)
  429. writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
  430. }
  431. if (CheckBit ((int) Styles.Width)) {
  432. u = (Unit)viewstate["Width"];
  433. if (!u.IsEmpty)
  434. writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
  435. }
  436. if (CheckBit ((int) Style.Styles.FontAll)) {
  437. // Fonts are a bit weird
  438. if (fontinfo.Name != string.Empty) {
  439. s = fontinfo.Names[0];
  440. for (int i = 1; i < fontinfo.Names.Length; i++)
  441. s += "," + fontinfo.Names[i];
  442. writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
  443. }
  444. if (fontinfo.Bold)
  445. writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
  446. if (fontinfo.Italic)
  447. writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
  448. if (!fontinfo.Size.IsEmpty)
  449. writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
  450. // These styles are munged into a attribute decoration
  451. s = string.Empty;
  452. if (fontinfo.Overline)
  453. s += "overline ";
  454. if (fontinfo.Strikeout)
  455. s += "line-through ";
  456. if (fontinfo.Underline)
  457. s += "underline ";
  458. s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
  459. if (s != "")
  460. writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
  461. }
  462. }
  463. #endif
  464. #if NET_2_0
  465. protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
  466. {
  467. Color color;
  468. BorderStyle bs;
  469. Unit u;
  470. if (CheckBit ((int) Styles.BackColor))
  471. {
  472. color = (Color)viewstate["BackColor"];
  473. if (!color.IsEmpty)
  474. attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  475. }
  476. if (CheckBit ((int) Styles.BorderColor))
  477. {
  478. color = (Color)viewstate["BorderColor"];
  479. if (!color.IsEmpty)
  480. attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  481. }
  482. bool have_width = false;
  483. if (CheckBit ((int) Styles.BorderWidth)) {
  484. u = (Unit) viewstate ["BorderWidth"];
  485. if (!u.IsEmpty) {
  486. if (u.Value > 0)
  487. have_width = true;
  488. attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString ());
  489. }
  490. }
  491. if (CheckBit ((int) Styles.BorderStyle)) {
  492. bs = (BorderStyle) viewstate ["BorderStyle"];
  493. if (bs != BorderStyle.NotSet)
  494. attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString ());
  495. else if (have_width)
  496. attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
  497. }
  498. else if (have_width) {
  499. attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
  500. }
  501. if (CheckBit ((int) Styles.ForeColor))
  502. {
  503. color = (Color)viewstate["ForeColor"];
  504. if (!color.IsEmpty)
  505. attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  506. }
  507. if (CheckBit ((int) Styles.Height))
  508. {
  509. u = (Unit)viewstate["Height"];
  510. if (!u.IsEmpty)
  511. attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
  512. }
  513. if (CheckBit ((int) Styles.Width))
  514. {
  515. u = (Unit)viewstate["Width"];
  516. if (!u.IsEmpty)
  517. attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
  518. }
  519. Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
  520. }
  521. #endif
  522. public virtual void CopyFrom(Style s)
  523. {
  524. if ((s == null) || s.IsEmpty)
  525. {
  526. return;
  527. }
  528. if (s.fontinfo != null)
  529. {
  530. Font.CopyFrom(s.fontinfo);
  531. }
  532. if ((s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
  533. {
  534. this.BackColor = s.BackColor;
  535. }
  536. if ((s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty))
  537. {
  538. this.BorderColor = s.BorderColor;
  539. }
  540. if ((s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
  541. {
  542. this.BorderStyle = s.BorderStyle;
  543. }
  544. if ((s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
  545. {
  546. this.BorderWidth = s.BorderWidth;
  547. }
  548. if ((s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
  549. {
  550. this.CssClass = s.CssClass;
  551. }
  552. if ((s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
  553. {
  554. this.ForeColor = s.ForeColor;
  555. }
  556. if ((s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
  557. {
  558. this.Height = s.Height;
  559. }
  560. if ((s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
  561. {
  562. this.Width = s.Width;
  563. }
  564. }
  565. public virtual void MergeWith(Style s)
  566. {
  567. if ((s == null) || (s.IsEmpty))
  568. {
  569. return;
  570. }
  571. if (s.fontinfo != null)
  572. {
  573. Font.MergeWith(s.fontinfo);
  574. }
  575. if ((!CheckBit ((int) Styles.BackColor)) && (s.CheckBit ((int) Styles.BackColor)) && (s.BackColor != Color.Empty))
  576. {
  577. this.BackColor = s.BackColor;
  578. }
  579. if ((!CheckBit ((int) Styles.BorderColor)) && (s.CheckBit ((int) Styles.BorderColor)) && (s.BorderColor != Color.Empty))
  580. {
  581. this.BorderColor = s.BorderColor;
  582. }
  583. if ((!CheckBit ((int) Styles.BorderStyle)) && (s.CheckBit ((int) Styles.BorderStyle)) && (s.BorderStyle != BorderStyle.NotSet))
  584. {
  585. this.BorderStyle = s.BorderStyle;
  586. }
  587. if ((!CheckBit ((int) Styles.BorderWidth)) && (s.CheckBit ((int) Styles.BorderWidth)) && (!s.BorderWidth.IsEmpty))
  588. {
  589. this.BorderWidth = s.BorderWidth;
  590. }
  591. if ((!CheckBit ((int) Styles.CssClass)) && (s.CheckBit ((int) Styles.CssClass)) && (s.CssClass != string.Empty))
  592. {
  593. this.CssClass = s.CssClass;
  594. }
  595. if ((!CheckBit ((int) Styles.ForeColor)) && (s.CheckBit ((int) Styles.ForeColor)) && (s.ForeColor != Color.Empty))
  596. {
  597. this.ForeColor = s.ForeColor;
  598. }
  599. if ((!CheckBit ((int) Styles.Height)) && (s.CheckBit ((int) Styles.Height)) && (!s.Height.IsEmpty))
  600. {
  601. this.Height = s.Height;
  602. }
  603. if ((!CheckBit ((int) Styles.Width)) && (s.CheckBit ((int) Styles.Width)) && (!s.Width.IsEmpty))
  604. {
  605. this.Width = s.Width;
  606. }
  607. }
  608. /*
  609. internal void Print ()
  610. {
  611. Console.WriteLine ("BackColor: {0}", BackColor);
  612. Console.WriteLine ("BorderColor: {0}", BorderColor);
  613. Console.WriteLine ("BorderStyle: {0}", BorderStyle);
  614. Console.WriteLine ("BorderWidth: {0}", BorderWidth);
  615. Console.WriteLine ("CssClass: {0}", CssClass);
  616. Console.WriteLine ("ForeColor: {0}", ForeColor);
  617. Console.WriteLine ("Height: {0}", Height);
  618. Console.WriteLine ("Width: {0}", Width);
  619. }
  620. */
  621. public virtual void Reset()
  622. {
  623. viewstate.Remove("BackColor");
  624. viewstate.Remove("BorderColor");
  625. viewstate.Remove("BorderStyle");
  626. viewstate.Remove("BorderWidth");
  627. viewstate.Remove("CssClass");
  628. viewstate.Remove("ForeColor");
  629. viewstate.Remove("Height");
  630. viewstate.Remove("Width");
  631. if (fontinfo != null)
  632. {
  633. fontinfo.Reset();
  634. }
  635. styles = 0;
  636. viewstate.Remove (BitStateKey);
  637. stylesTraked = 0;
  638. }
  639. #if ONLY_1_1
  640. public override string ToString()
  641. {
  642. return string.Empty;
  643. }
  644. #endif
  645. #endregion // Public Instance Methods
  646. #region Protected Instance Methods
  647. protected internal void LoadViewState(object state)
  648. {
  649. viewstate.LoadViewState(state);
  650. LoadBitState ();
  651. }
  652. protected internal virtual object SaveViewState ()
  653. {
  654. SaveBitState ();
  655. if (_isSharedViewState)
  656. return null;
  657. return viewstate.SaveViewState ();
  658. }
  659. internal void SaveBitState ()
  660. {
  661. if (stylesTraked != 0)
  662. viewstate [BitStateKey] = stylesTraked;
  663. }
  664. internal void LoadBitState () {
  665. if (viewstate [BitStateKey] == null)
  666. return;
  667. int bit = (int) viewstate [BitStateKey];
  668. styles |= bit;
  669. stylesTraked |= bit;
  670. }
  671. protected internal virtual void SetBit( int bit )
  672. {
  673. styles |= bit;
  674. if (tracking)
  675. stylesTraked |= bit;
  676. }
  677. internal void RemoveBit (int bit) {
  678. styles &= ~bit;
  679. if (tracking) {
  680. stylesTraked &= ~bit;
  681. if (stylesTraked == 0)
  682. viewstate.Remove (BitStateKey);
  683. }
  684. }
  685. internal bool CheckBit (int bit) {
  686. return (styles & bit) != 0;
  687. }
  688. protected internal virtual void TrackViewState ()
  689. {
  690. tracking = true;
  691. viewstate.TrackViewState();
  692. }
  693. #endregion // Protected Instance Methods
  694. #region IStateManager Properties & Methods
  695. void IStateManager.LoadViewState(object state)
  696. {
  697. LoadViewState(state);
  698. }
  699. object IStateManager.SaveViewState()
  700. {
  701. return SaveViewState();
  702. }
  703. void IStateManager.TrackViewState()
  704. {
  705. TrackViewState();
  706. }
  707. bool IStateManager.IsTrackingViewState
  708. {
  709. get
  710. {
  711. return this.IsTrackingViewState;
  712. }
  713. }
  714. #endregion // IStateManager Properties & Methods
  715. #if NET_2_0
  716. internal void SetRegisteredCssClass (string name)
  717. {
  718. registered_class = name;
  719. }
  720. public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
  721. {
  722. CssStyleCollection col = new CssStyleCollection ();
  723. FillStyleAttributes (col, resolver);
  724. return col;
  725. }
  726. [EditorBrowsable(EditorBrowsableState.Advanced)]
  727. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  728. [Browsable(false)]
  729. public string RegisteredCssClass {
  730. get {
  731. if (registered_class == null)
  732. registered_class = String.Empty;
  733. return registered_class;
  734. }
  735. }
  736. internal void CopyTextStylesFrom (Style source) {
  737. // Used primary for TreeView and Menu
  738. if (source.CheckBit ((int) Styles.ForeColor)) {
  739. ForeColor = source.ForeColor;
  740. }
  741. if (source.CheckBit((int) Styles.FontAll)) {
  742. Font.CopyFrom (source.Font);
  743. }
  744. }
  745. internal void RemoveTextStyles () {
  746. ForeColor = Color.Empty;
  747. fontinfo = null;
  748. }
  749. internal void AddCssClass (string cssClass) {
  750. if (String.IsNullOrEmpty (cssClass))
  751. return;
  752. if (CssClass.Length > 0)
  753. CssClass += " ";
  754. CssClass += cssClass;
  755. }
  756. public void SetDirty ()
  757. {
  758. if (viewstate != null)
  759. viewstate.SetDirty (true);
  760. stylesTraked = styles;
  761. }
  762. #endif
  763. }
  764. }