Style.cs 18 KB

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