Style.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  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. [Flags]
  44. internal enum Styles
  45. {
  46. None = 0,
  47. BackColor = 0x00000001,
  48. BorderColor = 0x00000002,
  49. BorderStyle = 0x00000004,
  50. BorderWidth = 0x00000008,
  51. CssClass = 0x00000010,
  52. Font = 0x00000020,
  53. ForeColor = 0x00000040,
  54. Height = 0x00000080,
  55. Width = 0x00000100,
  56. // from TableStyle (which doesn't override IsEmpty)
  57. BackImageUrl = 0x00000200,
  58. CellPadding = 0x00000400,
  59. CellSpacing = 0x00000800,
  60. GridLines = 0x00001000,
  61. HorizontalAlign = 0x00002000,
  62. // from TableItemStyle (which doesn't override IsEmpty neither)
  63. VerticalAlign = 0x00004000,
  64. Wrap = 0x00008000,
  65. // from DataGridPagerStyle (and, once again, no IsEmpty override)
  66. Mode = 0x00010000,
  67. NextPageText = 0x00020000,
  68. PageButtonCount = 0x00040000,
  69. Position = 0x00080000,
  70. PrevPageText = 0x00100000,
  71. Visible = 0x00200000
  72. }
  73. #region Fields
  74. internal Styles styles;
  75. internal StateBag viewstate;
  76. private FontInfo fontinfo;
  77. private bool tracking;
  78. #if NET_2_0
  79. private string registered_class;
  80. #endif
  81. #endregion // Fields
  82. #region Public Constructors
  83. public Style() : this(new StateBag())
  84. {
  85. }
  86. public Style(System.Web.UI.StateBag bag)
  87. {
  88. if (bag != null) {
  89. viewstate = bag;
  90. } else {
  91. viewstate = new StateBag();
  92. }
  93. tracking = false;
  94. }
  95. #endregion // Public Constructors
  96. #region Public Instance Properties
  97. #if !NET_2_0
  98. [Bindable(true)]
  99. #endif
  100. [DefaultValue(typeof (Color), "")]
  101. [NotifyParentProperty(true)]
  102. [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
  103. [WebSysDescription ("")]
  104. [WebCategory ("Appearance")]
  105. public Color BackColor
  106. {
  107. get
  108. {
  109. if ((styles & Styles.BackColor) == 0)
  110. {
  111. return Color.Empty;
  112. }
  113. return (Color)viewstate["BackColor"];
  114. }
  115. set
  116. {
  117. viewstate["BackColor"] = value;
  118. styles |= Styles.BackColor;
  119. }
  120. }
  121. #if !NET_2_0
  122. [Bindable(true)]
  123. #endif
  124. [DefaultValue(typeof (Color), "")]
  125. [NotifyParentProperty(true)]
  126. [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
  127. [WebSysDescription ("")]
  128. [WebCategory ("Appearance")]
  129. public Color BorderColor
  130. {
  131. get
  132. {
  133. if ((styles & Styles.BorderColor) == 0)
  134. {
  135. return Color.Empty;
  136. }
  137. return (Color)viewstate["BorderColor"];
  138. }
  139. set
  140. {
  141. viewstate["BorderColor"] = value;
  142. styles |= Styles.BorderColor;
  143. }
  144. }
  145. #if !NET_2_0
  146. [Bindable(true)]
  147. #endif
  148. [DefaultValue(BorderStyle.NotSet)]
  149. [NotifyParentProperty(true)]
  150. [WebSysDescription ("")]
  151. [WebCategory ("Appearance")]
  152. public BorderStyle BorderStyle
  153. {
  154. get
  155. {
  156. if ((styles & Styles.BorderStyle) == 0)
  157. {
  158. return BorderStyle.NotSet;
  159. }
  160. return (BorderStyle)viewstate["BorderStyle"];
  161. }
  162. set
  163. {
  164. viewstate["BorderStyle"] = value;
  165. styles |= Styles.BorderStyle;
  166. }
  167. }
  168. #if !NET_2_0
  169. [Bindable(true)]
  170. #endif
  171. [DefaultValue(typeof (Unit), "")]
  172. [NotifyParentProperty(true)]
  173. [WebSysDescription ("")]
  174. [WebCategory ("Appearance")]
  175. public Unit BorderWidth
  176. {
  177. get
  178. {
  179. if ((styles & Styles.BorderWidth) == 0)
  180. {
  181. return Unit.Empty;
  182. }
  183. return (Unit)viewstate["BorderWidth"];
  184. }
  185. set
  186. {
  187. if (value.Value < 0)
  188. {
  189. throw new ArgumentOutOfRangeException("Value", value.Value, "BorderWidth must not be negative");
  190. }
  191. viewstate["BorderWidth"] = value;
  192. styles |= Styles.BorderWidth;
  193. }
  194. }
  195. [DefaultValue("")]
  196. [NotifyParentProperty(true)]
  197. [WebSysDescription ("")]
  198. [WebCategory ("Appearance")]
  199. public string CssClass
  200. {
  201. get
  202. {
  203. if ((styles & Styles.CssClass) == 0)
  204. {
  205. return string.Empty;
  206. }
  207. return (string)viewstate["CssClass"];
  208. }
  209. set
  210. {
  211. viewstate["CssClass"] = value;
  212. styles |= 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 ((styles & Styles.ForeColor) == 0)
  243. {
  244. return Color.Empty;
  245. }
  246. return (Color)viewstate["ForeColor"];
  247. }
  248. set
  249. {
  250. viewstate["ForeColor"] = value;
  251. styles |= 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 ((styles & Styles.Height) == 0)
  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. styles |= 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 ((styles & Styles.Width) == 0)
  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. styles |= 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 && (fontinfo == null || fontinfo.IsEmpty) && RegisteredCssClass.Length == 0);
  322. #else
  323. return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty));
  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. if (CssClass.Length > 0)
  369. writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass + " " + RegisteredCssClass);
  370. else
  371. writer.AddAttribute (HtmlTextWriterAttribute.Class, RegisteredCssClass);
  372. }
  373. else
  374. #endif
  375. {
  376. if (CssClass.Length > 0)
  377. writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass);
  378. WriteStyleAttributes (writer);
  379. }
  380. }
  381. void WriteStyleAttributes (HtmlTextWriter writer)
  382. {
  383. #if NET_2_0
  384. CssStyleCollection col = new CssStyleCollection (new StateBag ());
  385. FillStyleAttributes (col, null);
  386. foreach (string key in col.Keys) {
  387. writer.AddStyleAttribute (key, col [key]);
  388. }
  389. #else
  390. string s;
  391. Color color;
  392. BorderStyle bs;
  393. Unit u;
  394. if ((styles & Styles.BackColor) != 0) {
  395. color = (Color)viewstate["BackColor"];
  396. if (!color.IsEmpty)
  397. writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  398. }
  399. if ((styles & Styles.BorderColor) != 0) {
  400. color = (Color)viewstate["BorderColor"];
  401. if (!color.IsEmpty)
  402. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  403. }
  404. bool have_width = false;
  405. if ((styles & Styles.BorderWidth) != 0) {
  406. u = (Unit)viewstate["BorderWidth"];
  407. if (!u.IsEmpty) {
  408. if (u.Value > 0)
  409. have_width = true;
  410. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
  411. }
  412. }
  413. if ((styles & Styles.BorderStyle) != 0) {
  414. bs = (BorderStyle)viewstate["BorderStyle"];
  415. if (bs != BorderStyle.NotSet)
  416. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
  417. else {
  418. if ((styles & Styles.BorderWidth) != 0)
  419. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  420. }
  421. } else if (have_width) {
  422. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  423. }
  424. if ((styles & Styles.ForeColor) != 0) {
  425. color = (Color)viewstate["ForeColor"];
  426. if (!color.IsEmpty)
  427. writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  428. }
  429. if ((styles & Styles.Height) != 0) {
  430. u = (Unit)viewstate["Height"];
  431. if (!u.IsEmpty)
  432. writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
  433. }
  434. if ((styles & Styles.Width) != 0) {
  435. u = (Unit)viewstate["Width"];
  436. if (!u.IsEmpty)
  437. writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
  438. }
  439. if (!Font.IsEmpty) {
  440. // Fonts are a bit weird
  441. if (fontinfo.Name != string.Empty) {
  442. s = fontinfo.Names[0];
  443. for (int i = 1; i < fontinfo.Names.Length; i++)
  444. s += "," + fontinfo.Names[i];
  445. writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
  446. }
  447. if (fontinfo.Bold)
  448. writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
  449. if (fontinfo.Italic)
  450. writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
  451. if (!fontinfo.Size.IsEmpty)
  452. writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
  453. // These styles are munged into a attribute decoration
  454. s = string.Empty;
  455. if (fontinfo.Overline)
  456. s += "overline ";
  457. if (fontinfo.Strikeout)
  458. s += "line-through ";
  459. if (fontinfo.Underline)
  460. s += "underline ";
  461. s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
  462. if (s != "")
  463. writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
  464. }
  465. #endif
  466. }
  467. #if NET_2_0
  468. void FillStyleAttributes (CssStyleCollection attributes)
  469. {
  470. Color color;
  471. BorderStyle bs;
  472. Unit u;
  473. if ((styles & Styles.BackColor) != 0)
  474. {
  475. color = (Color)viewstate["BackColor"];
  476. if (!color.IsEmpty)
  477. attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  478. }
  479. if ((styles & Styles.BorderColor) != 0)
  480. {
  481. color = (Color)viewstate["BorderColor"];
  482. if (!color.IsEmpty)
  483. attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  484. }
  485. bool have_width = false;
  486. if ((styles & Styles.BorderWidth) != 0) {
  487. u = (Unit) viewstate ["BorderWidth"];
  488. if (!u.IsEmpty) {
  489. if (u.Value > 0)
  490. have_width = true;
  491. attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString ());
  492. }
  493. }
  494. if ((styles & Styles.BorderStyle) != 0) {
  495. bs = (BorderStyle) viewstate ["BorderStyle"];
  496. if (bs != BorderStyle.NotSet)
  497. attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString ());
  498. else if (have_width)
  499. attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
  500. }
  501. else if (have_width) {
  502. attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
  503. }
  504. if ((styles & Styles.ForeColor) != 0)
  505. {
  506. color = (Color)viewstate["ForeColor"];
  507. if (!color.IsEmpty)
  508. attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  509. }
  510. if ((styles & Styles.Height) != 0)
  511. {
  512. u = (Unit)viewstate["Height"];
  513. if (!u.IsEmpty)
  514. attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
  515. }
  516. if ((styles & Styles.Width) != 0)
  517. {
  518. u = (Unit)viewstate["Width"];
  519. if (!u.IsEmpty)
  520. attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
  521. }
  522. Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
  523. }
  524. #endif
  525. public virtual void CopyFrom(Style s)
  526. {
  527. if ((s == null) || s.IsEmpty)
  528. {
  529. return;
  530. }
  531. if (s.fontinfo != null)
  532. {
  533. Font.CopyFrom(s.fontinfo);
  534. }
  535. if (((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
  536. {
  537. this.BackColor = s.BackColor;
  538. }
  539. if (((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
  540. {
  541. this.BorderColor = s.BorderColor;
  542. }
  543. if (((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
  544. {
  545. this.BorderStyle = s.BorderStyle;
  546. }
  547. if (((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty))
  548. {
  549. this.BorderWidth = s.BorderWidth;
  550. }
  551. if (((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
  552. {
  553. this.CssClass = s.CssClass;
  554. }
  555. if (((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
  556. {
  557. this.ForeColor = s.ForeColor;
  558. }
  559. if (((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty))
  560. {
  561. this.Height = s.Height;
  562. }
  563. if (((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty))
  564. {
  565. this.Width = s.Width;
  566. }
  567. }
  568. public virtual void MergeWith(Style s)
  569. {
  570. if ((s == null) || (s.IsEmpty))
  571. {
  572. return;
  573. }
  574. if (s.fontinfo != null)
  575. {
  576. Font.MergeWith(s.fontinfo);
  577. }
  578. if (((styles & Styles.BackColor) == 0) && ((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
  579. {
  580. this.BackColor = s.BackColor;
  581. }
  582. if (((styles & Styles.BorderColor) == 0) && ((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
  583. {
  584. this.BorderColor = s.BorderColor;
  585. }
  586. if (((styles & Styles.BorderStyle) == 0) && ((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
  587. {
  588. this.BorderStyle = s.BorderStyle;
  589. }
  590. if (((styles & Styles.BorderWidth) == 0) && ((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty))
  591. {
  592. this.BorderWidth = s.BorderWidth;
  593. }
  594. if (((styles & Styles.CssClass) == 0) && ((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
  595. {
  596. this.CssClass = s.CssClass;
  597. }
  598. if (((styles & Styles.ForeColor) == 0) && ((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
  599. {
  600. this.ForeColor = s.ForeColor;
  601. }
  602. if (((styles & Styles.Height) == 0) && ((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty))
  603. {
  604. this.Height = s.Height;
  605. }
  606. if (((styles & Styles.Width) == 0) && ((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty))
  607. {
  608. this.Width = s.Width;
  609. }
  610. }
  611. /*
  612. internal void Print ()
  613. {
  614. Console.WriteLine ("BackColor: {0}", BackColor);
  615. Console.WriteLine ("BorderColor: {0}", BorderColor);
  616. Console.WriteLine ("BorderStyle: {0}", BorderStyle);
  617. Console.WriteLine ("BorderWidth: {0}", BorderWidth);
  618. Console.WriteLine ("CssClass: {0}", CssClass);
  619. Console.WriteLine ("ForeColor: {0}", ForeColor);
  620. Console.WriteLine ("Height: {0}", Height);
  621. Console.WriteLine ("Width: {0}", Width);
  622. }
  623. */
  624. public virtual void Reset()
  625. {
  626. viewstate.Remove("BackColor");
  627. viewstate.Remove("BorderColor");
  628. viewstate.Remove("BorderStyle");
  629. viewstate.Remove("BorderWidth");
  630. viewstate.Remove("CssClass");
  631. viewstate.Remove("ForeColor");
  632. viewstate.Remove("Height");
  633. viewstate.Remove("Width");
  634. if (fontinfo != null)
  635. {
  636. fontinfo.Reset();
  637. }
  638. styles = Styles.None;
  639. }
  640. #if ONLY_1_1
  641. public override string ToString()
  642. {
  643. return string.Empty;
  644. }
  645. #endif
  646. #endregion // Public Instance Methods
  647. #region Protected Instance Methods
  648. protected internal void LoadViewState(object state)
  649. {
  650. viewstate.LoadViewState(state);
  651. // Update our style
  652. this.styles = Styles.None;
  653. if (viewstate["BackColor"] != null)
  654. {
  655. styles |= Styles.BackColor;
  656. }
  657. if (viewstate["BorderColor"] != null)
  658. {
  659. styles |= Styles.BorderColor;
  660. }
  661. if (viewstate["BorderStyle"] != null)
  662. {
  663. styles |= Styles.BorderStyle;
  664. }
  665. if (viewstate["BorderWidth"] != null)
  666. {
  667. styles |= Styles.BorderWidth;
  668. }
  669. if (viewstate["CssClass"] != null)
  670. {
  671. styles |= Styles.CssClass;
  672. }
  673. if (viewstate["ForeColor"] != null)
  674. {
  675. styles |= Styles.ForeColor;
  676. }
  677. if (viewstate["Height"] != null)
  678. {
  679. styles |= Styles.Height;
  680. }
  681. if (viewstate["Width"] != null)
  682. {
  683. styles |= Styles.Width;
  684. }
  685. Font.LoadViewState();
  686. LoadViewStateInternal();
  687. }
  688. internal virtual void LoadViewStateInternal()
  689. {
  690. // Override me
  691. }
  692. protected internal virtual object SaveViewState ()
  693. {
  694. if (styles != Styles.None || !Font.IsEmpty)
  695. {
  696. return viewstate.SaveViewState();
  697. }
  698. return null;
  699. }
  700. [MonoTODO]
  701. protected internal virtual void SetBit( int bit )
  702. {
  703. throw new NotImplementedException();
  704. }
  705. protected internal virtual void TrackViewState()
  706. {
  707. tracking = true;
  708. viewstate.TrackViewState();
  709. }
  710. #endregion // Protected Instance Methods
  711. #region IStateManager Properties & Methods
  712. void IStateManager.LoadViewState(object state)
  713. {
  714. LoadViewState(state);
  715. }
  716. object IStateManager.SaveViewState()
  717. {
  718. return SaveViewState();
  719. }
  720. void IStateManager.TrackViewState()
  721. {
  722. TrackViewState();
  723. }
  724. bool IStateManager.IsTrackingViewState
  725. {
  726. get
  727. {
  728. return this.IsTrackingViewState;
  729. }
  730. }
  731. #endregion // IStateManager Properties & Methods
  732. #if NET_2_0
  733. protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
  734. {
  735. FillStyleAttributes (attributes);
  736. }
  737. internal void SetRegisteredCssClass (string name)
  738. {
  739. registered_class = name;
  740. }
  741. public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
  742. {
  743. CssStyleCollection col = new CssStyleCollection (new StateBag ());
  744. FillStyleAttributes (col, resolver);
  745. return col;
  746. }
  747. [MonoTODO]
  748. [EditorBrowsable(EditorBrowsableState.Advanced)]
  749. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  750. [Browsable(false)]
  751. public string RegisteredCssClass {
  752. get {
  753. if (registered_class == null)
  754. registered_class = String.Empty;
  755. return registered_class;
  756. }
  757. }
  758. internal virtual void CopyTextStylesFrom (Style source)
  759. {
  760. // Need to ask lluis if we need fonts, too
  761. if ((styles & Styles.ForeColor) != 0) {
  762. ForeColor = source.ForeColor;
  763. }
  764. if ((styles & Styles.BackColor) != 0) {
  765. BackColor = source.BackColor;
  766. }
  767. }
  768. public void SetDirty ()
  769. {
  770. if (viewstate != null)
  771. viewstate.SetDirty (true);
  772. }
  773. #endif
  774. }
  775. }