Style.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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 ((styles & Styles.CssClass) != 0)
  367. {
  368. string s = (string)viewstate["CssClass"];
  369. if (s != string.Empty)
  370. writer.AddAttribute (HtmlTextWriterAttribute.Class, s);
  371. }
  372. WriteStyleAttributes (writer);
  373. }
  374. void WriteStyleAttributes (HtmlTextWriter writer)
  375. {
  376. string s;
  377. Color color;
  378. BorderStyle bs;
  379. Unit u;
  380. if ((styles & Styles.BackColor) != 0) {
  381. color = (Color)viewstate["BackColor"];
  382. if (!color.IsEmpty)
  383. writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  384. }
  385. if ((styles & Styles.BorderColor) != 0) {
  386. color = (Color)viewstate["BorderColor"];
  387. if (!color.IsEmpty)
  388. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  389. }
  390. bool have_width = false;
  391. if ((styles & Styles.BorderWidth) != 0) {
  392. u = (Unit)viewstate["BorderWidth"];
  393. if (!u.IsEmpty) {
  394. if (u.Value > 0)
  395. have_width = true;
  396. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
  397. }
  398. }
  399. if ((styles & Styles.BorderStyle) != 0) {
  400. bs = (BorderStyle)viewstate["BorderStyle"];
  401. if (bs != BorderStyle.NotSet)
  402. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
  403. else {
  404. if ((styles & Styles.BorderWidth) != 0)
  405. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  406. }
  407. } else if (have_width) {
  408. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
  409. }
  410. if ((styles & Styles.ForeColor) != 0) {
  411. color = (Color)viewstate["ForeColor"];
  412. if (!color.IsEmpty)
  413. writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  414. }
  415. if ((styles & Styles.Height) != 0) {
  416. u = (Unit)viewstate["Height"];
  417. if (!u.IsEmpty)
  418. writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
  419. }
  420. if ((styles & Styles.Width) != 0) {
  421. u = (Unit)viewstate["Width"];
  422. if (!u.IsEmpty)
  423. writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
  424. }
  425. if (!Font.IsEmpty) {
  426. // Fonts are a bit weird
  427. if (fontinfo.Name != string.Empty) {
  428. s = fontinfo.Names[0];
  429. for (int i = 1; i < fontinfo.Names.Length; i++)
  430. s += "," + fontinfo.Names[i];
  431. writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
  432. }
  433. if (fontinfo.Bold)
  434. writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
  435. if (fontinfo.Italic)
  436. writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
  437. if (!fontinfo.Size.IsEmpty)
  438. writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
  439. // These styles are munged into a attribute decoration
  440. s = string.Empty;
  441. if (fontinfo.Overline)
  442. s += "overline ";
  443. if (fontinfo.Strikeout)
  444. s += "line-through ";
  445. if (fontinfo.Underline)
  446. s += "underline ";
  447. s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
  448. if (s != "")
  449. writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
  450. }
  451. }
  452. void FillStyleAttributes (CssStyleCollection attributes)
  453. {
  454. string s;
  455. Color color;
  456. BorderStyle bs;
  457. Unit u;
  458. if ((styles & Styles.BackColor) != 0)
  459. {
  460. color = (Color)viewstate["BackColor"];
  461. if (!color.IsEmpty)
  462. attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
  463. }
  464. if ((styles & Styles.BorderColor) != 0)
  465. {
  466. color = (Color)viewstate["BorderColor"];
  467. if (!color.IsEmpty)
  468. attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
  469. }
  470. if ((styles & Styles.BorderStyle) != 0)
  471. {
  472. bs = (BorderStyle)viewstate["BorderStyle"];
  473. if (bs != BorderStyle.NotSet)
  474. attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString());
  475. }
  476. if ((styles & Styles.BorderWidth) != 0)
  477. {
  478. u = (Unit)viewstate["BorderWidth"];
  479. if (!u.IsEmpty)
  480. attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString());
  481. }
  482. if ((styles & Styles.ForeColor) != 0)
  483. {
  484. color = (Color)viewstate["ForeColor"];
  485. if (!color.IsEmpty)
  486. attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
  487. }
  488. if ((styles & Styles.Height) != 0)
  489. {
  490. u = (Unit)viewstate["Height"];
  491. if (!u.IsEmpty)
  492. attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
  493. }
  494. if ((styles & Styles.Width) != 0)
  495. {
  496. u = (Unit)viewstate["Width"];
  497. if (!u.IsEmpty)
  498. attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
  499. }
  500. if (!Font.IsEmpty) {
  501. // Fonts are a bit weird
  502. if (fontinfo.Name != string.Empty)
  503. {
  504. s = fontinfo.Names[0];
  505. for (int i = 1; i < fontinfo.Names.Length; i++)
  506. {
  507. s += "," + fontinfo.Names[i];
  508. }
  509. attributes.Add (HtmlTextWriterStyle.FontFamily, s);
  510. }
  511. if (fontinfo.Bold)
  512. {
  513. attributes.Add (HtmlTextWriterStyle.FontWeight, "bold");
  514. }
  515. if (fontinfo.Italic)
  516. {
  517. attributes.Add (HtmlTextWriterStyle.FontStyle, "italic");
  518. }
  519. if (!fontinfo.Size.IsEmpty)
  520. {
  521. attributes.Add (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
  522. }
  523. // These styles are munged into a attribute decoration
  524. s = string.Empty;
  525. if (fontinfo.Overline)
  526. {
  527. s += "overline ";
  528. }
  529. if (fontinfo.Strikeout)
  530. {
  531. s += "line-through ";
  532. }
  533. if (fontinfo.Underline)
  534. {
  535. s += "underline ";
  536. }
  537. s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
  538. if (s != "")
  539. attributes.Add (HtmlTextWriterStyle.TextDecoration, s);
  540. }
  541. }
  542. public virtual void CopyFrom(Style s)
  543. {
  544. if ((s == null) || s.IsEmpty)
  545. {
  546. return;
  547. }
  548. if (s.fontinfo != null)
  549. {
  550. Font.CopyFrom(s.fontinfo);
  551. }
  552. if (((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
  553. {
  554. this.BackColor = s.BackColor;
  555. }
  556. if (((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
  557. {
  558. this.BorderColor = s.BorderColor;
  559. }
  560. if (((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
  561. {
  562. this.BorderStyle = s.BorderStyle;
  563. }
  564. if (((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty))
  565. {
  566. this.BorderWidth = s.BorderWidth;
  567. }
  568. if (((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
  569. {
  570. this.CssClass = s.CssClass;
  571. }
  572. if (((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
  573. {
  574. this.ForeColor = s.ForeColor;
  575. }
  576. if (((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty))
  577. {
  578. this.Height = s.Height;
  579. }
  580. if (((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty))
  581. {
  582. this.Width = s.Width;
  583. }
  584. }
  585. public virtual void MergeWith(Style s)
  586. {
  587. if ((s == null) || (s.IsEmpty))
  588. {
  589. return;
  590. }
  591. if (s.fontinfo != null)
  592. {
  593. Font.MergeWith(s.fontinfo);
  594. }
  595. if (((styles & Styles.BackColor) == 0) && ((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
  596. {
  597. this.BackColor = s.BackColor;
  598. }
  599. if (((styles & Styles.BorderColor) == 0) && ((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
  600. {
  601. this.BorderColor = s.BorderColor;
  602. }
  603. if (((styles & Styles.BorderStyle) == 0) && ((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
  604. {
  605. this.BorderStyle = s.BorderStyle;
  606. }
  607. if (((styles & Styles.BorderWidth) == 0) && ((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty))
  608. {
  609. this.BorderWidth = s.BorderWidth;
  610. }
  611. if (((styles & Styles.CssClass) == 0) && ((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
  612. {
  613. this.CssClass = s.CssClass;
  614. }
  615. if (((styles & Styles.ForeColor) == 0) && ((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
  616. {
  617. this.ForeColor = s.ForeColor;
  618. }
  619. if (((styles & Styles.Height) == 0) && ((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty))
  620. {
  621. this.Height = s.Height;
  622. }
  623. if (((styles & Styles.Width) == 0) && ((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty))
  624. {
  625. this.Width = s.Width;
  626. }
  627. }
  628. /*
  629. internal void Print ()
  630. {
  631. Console.WriteLine ("BackColor: {0}", BackColor);
  632. Console.WriteLine ("BorderColor: {0}", BorderColor);
  633. Console.WriteLine ("BorderStyle: {0}", BorderStyle);
  634. Console.WriteLine ("BorderWidth: {0}", BorderWidth);
  635. Console.WriteLine ("CssClass: {0}", CssClass);
  636. Console.WriteLine ("ForeColor: {0}", ForeColor);
  637. Console.WriteLine ("Height: {0}", Height);
  638. Console.WriteLine ("Width: {0}", Width);
  639. }
  640. */
  641. public virtual void Reset()
  642. {
  643. viewstate.Remove("BackColor");
  644. viewstate.Remove("BorderColor");
  645. viewstate.Remove("BorderStyle");
  646. viewstate.Remove("BorderWidth");
  647. viewstate.Remove("CssClass");
  648. viewstate.Remove("ForeColor");
  649. viewstate.Remove("Height");
  650. viewstate.Remove("Width");
  651. if (fontinfo != null)
  652. {
  653. fontinfo.Reset();
  654. }
  655. styles = Styles.None;
  656. }
  657. #if ONLY_1_1
  658. public override string ToString()
  659. {
  660. return string.Empty;
  661. }
  662. #endif
  663. #endregion // Public Instance Methods
  664. #region Protected Instance Methods
  665. protected internal void LoadViewState(object state)
  666. {
  667. viewstate.LoadViewState(state);
  668. // Update our style
  669. this.styles = Styles.None;
  670. if (viewstate["BackColor"] != null)
  671. {
  672. styles |= Styles.BackColor;
  673. }
  674. if (viewstate["BorderColor"] != null)
  675. {
  676. styles |= Styles.BorderColor;
  677. }
  678. if (viewstate["BorderStyle"] != null)
  679. {
  680. styles |= Styles.BorderStyle;
  681. }
  682. if (viewstate["BorderWidth"] != null)
  683. {
  684. styles |= Styles.BorderWidth;
  685. }
  686. if (viewstate["CssClass"] != null)
  687. {
  688. styles |= Styles.CssClass;
  689. }
  690. if (viewstate["ForeColor"] != null)
  691. {
  692. styles |= Styles.ForeColor;
  693. }
  694. if (viewstate["Height"] != null)
  695. {
  696. styles |= Styles.Height;
  697. }
  698. if (viewstate["Width"] != null)
  699. {
  700. styles |= Styles.Width;
  701. }
  702. Font.LoadViewState();
  703. LoadViewStateInternal();
  704. }
  705. internal virtual void LoadViewStateInternal()
  706. {
  707. // Override me
  708. }
  709. protected internal virtual object SaveViewState ()
  710. {
  711. if (styles != Styles.None || !Font.IsEmpty)
  712. {
  713. return viewstate.SaveViewState();
  714. }
  715. return null;
  716. }
  717. [MonoTODO]
  718. protected internal virtual void SetBit( int bit )
  719. {
  720. throw new NotImplementedException();
  721. }
  722. protected internal virtual void TrackViewState()
  723. {
  724. tracking = true;
  725. viewstate.TrackViewState();
  726. }
  727. #endregion // Protected Instance Methods
  728. #region IStateManager Properties & Methods
  729. void IStateManager.LoadViewState(object state)
  730. {
  731. LoadViewState(state);
  732. }
  733. object IStateManager.SaveViewState()
  734. {
  735. return SaveViewState();
  736. }
  737. void IStateManager.TrackViewState()
  738. {
  739. TrackViewState();
  740. }
  741. bool IStateManager.IsTrackingViewState
  742. {
  743. get
  744. {
  745. return this.IsTrackingViewState;
  746. }
  747. }
  748. #endregion // IStateManager Properties & Methods
  749. #if NET_2_0
  750. protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
  751. {
  752. FillStyleAttributes (attributes);
  753. }
  754. internal void SetRegisteredCssClass (string name)
  755. {
  756. registered_class = name;
  757. }
  758. public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
  759. {
  760. CssStyleCollection col = new CssStyleCollection (new StateBag ());
  761. FillStyleAttributes (col, resolver);
  762. return col;
  763. }
  764. [MonoTODO]
  765. [EditorBrowsable(EditorBrowsableState.Advanced)]
  766. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  767. [Browsable(false)]
  768. public string RegisteredCssClass {
  769. get {
  770. if (registered_class == null)
  771. registered_class = String.Empty;
  772. return registered_class;
  773. }
  774. }
  775. internal virtual void CopyTextStylesFrom (Style source)
  776. {
  777. // Need to ask lluis if we need fonts, too
  778. if ((styles & Styles.ForeColor) != 0) {
  779. ForeColor = source.ForeColor;
  780. }
  781. if ((styles & Styles.BackColor) != 0) {
  782. BackColor = source.BackColor;
  783. }
  784. }
  785. public void SetDirty ()
  786. {
  787. if (viewstate != null)
  788. viewstate.SetDirty (true);
  789. }
  790. #endif
  791. }
  792. }