File: Style.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (846 lines) | stat: -rw-r--r-- 29,738 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
//------------------------------------------------------------------------------
// <copyright file="Style.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Diagnostics;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.Design.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using WebCtrlStyle = System.Web.UI.WebControls.Style;
using System.Security.Permissions;

namespace System.Web.UI.MobileControls
{

    /*
     * Mobile Style class.
     * This class can be used to define external styles that can be referenced by other controls.
     */
    /// <include file='doc\Style.uex' path='docs/doc[@for="Style"]/*' />
    [
        ControlBuilderAttribute(typeof(MobileControlBuilder)),
        TypeConverterAttribute(typeof(ExpandableObjectConverter))
    ]
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    public class Style : IParserAccessor, ITemplateable, IStateManager, ICloneable
    {
        //  registers styles and retrieves keys used for storing properties in internal hashtable
        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.AlignmentKey"]/*' />
        public static readonly Object
            AlignmentKey = RegisterStyle("Alignment", typeof(Alignment)    , System.Web.UI.MobileControls.Alignment.NotSet, true),
            WrappingKey  = RegisterStyle("Wrapping" , typeof(Wrapping)     , System.Web.UI.MobileControls.Wrapping.NotSet , true),
            BoldKey      = RegisterStyle("Bold",      typeof(BooleanOption), BooleanOption.NotSet, true),
            ItalicKey    = RegisterStyle("Italic",    typeof(BooleanOption), BooleanOption.NotSet, true),
            FontSizeKey  = RegisterStyle("FontSize" , typeof(FontSize)     , System.Web.UI.MobileControls.FontSize.NotSet , true),
            FontNameKey  = RegisterStyle("FontName" , typeof(String)       , String.Empty    , true),
            ForeColorKey = RegisterStyle("ForeColor", typeof(Color)        , Color.Empty     , true),
            BackColorKey = RegisterStyle("BackColor", typeof(Color)        , Color.Empty     , false);

        private bool _marked = false;       //  used by IStateManager
        private MobileControl _control;     //  containing control
        private Style _referredStyle;       //  referred style
        private bool _checkedStyleReference;//  referred style is valid.
        private StateBag _state;            //  name => object pairs
        private DeviceSpecific _deviceSpecific;
        private FontInfo _font;
        private Style _cachedParentStyle;

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.Style"]/*' />
        public Style()
        {
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.Clone"]/*' />
        public object Clone()
        {
            Style clone = new Style();
            foreach(String key in State.Keys)
            {
                clone.State[key] = State[key];
            }
            clone._control = _control;
            return clone;
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.ApplyTo"]/*' />
        public void ApplyTo(WebControl control)
        {
            control.Font.Name = (String)this[FontNameKey, true];
            switch ((FontSize)this[FontSizeKey, true])
            {
                case FontSize.Small:
                    control.Font.Size = FontUnit.Small;
                    break;
                case FontSize.Large:
                    control.Font.Size = FontUnit.Large;
                    break;
                default:
                    control.Font.Size = FontUnit.Medium;
                    break;
            }
            control.Font.Bold   = ((BooleanOption)this[BoldKey, true]) == BooleanOption.True;
            control.Font.Italic = ((BooleanOption)this[ItalicKey, true]) == BooleanOption.True;
            control.ForeColor   = (Color)this[ForeColorKey, true];
            control.BackColor   = (Color)this[BackColorKey, true];
        }

        internal void ApplyTo(WebCtrlStyle style)
        {
            style.Font.Bold     = ((BooleanOption)this[BoldKey, true]) == BooleanOption.True;
            style.Font.Italic   = ((BooleanOption)this[ItalicKey, true]) == BooleanOption.True;
            style.Font.Name     = (String)this[FontNameKey, true];
            style.ForeColor     = (Color)this[ForeColorKey, true];
            style.BackColor     = (Color)this[BackColorKey, true];

            switch ((FontSize)this[FontSizeKey, true])
            {
                case FontSize.Large :
                    style.Font.Size = FontUnit.Larger;
                    break;

                case FontSize.Small :
                    style.Font.Size = FontUnit.Smaller;
                    break;

                default :
                    break;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.State"]/*' />
        protected internal StateBag State
        {
            get
            {
                if (_state == null)
                {
                    _state = new StateBag();
                    if (((IStateManager)this).IsTrackingViewState)
                    {
                        ((IStateManager)_state).TrackViewState();
                    }
                }

                return _state;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.IStateManager.IsTrackingViewState"]/*' />
        /// <internalonly/>
        protected bool IsTrackingViewState
        {
            get
            {
                return _marked;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.IStateManager.TrackViewState"]/*' />
        /// <internalonly/>
        protected void TrackViewState()
        {
            _marked = true;
            if (_state != null)
            {
                ((IStateManager)_state).TrackViewState();
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.IStateManager.SaveViewState"]/*' />
        /// <internalonly/>
        protected Object SaveViewState()
        {
            return _state != null ? ((IStateManager)_state).SaveViewState() : null;
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.IStateManager.LoadViewState"]/*' />
        /// <internalonly/>
        protected void LoadViewState(Object state)
        {
            if (state != null)
            {
                // mark _referredStyle as dirty to force reload from viewstate.
                Refresh();
                
                ((IStateManager)State).LoadViewState(state);
            }
        }

        internal void SetDirty()
        {
            // VSWHIDBEY 236464. The bag needs to be set dirty not individual items.
            State.SetDirty(true);
/*            
            foreach (StateItem item in State.Values)
            {
                item.IsDirty = true;
            }
*/
        }

        internal void Refresh()
        {
            _referredStyle = null;
            _checkedStyleReference = false;
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.Control"]/*' />
        [
            Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public MobileControl Control
        {
            get
            {
                return _control;
            }
        }

        internal void SetControl(MobileControl control)
        {
            _control = control;
            _cachedParentStyle = null;
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.Name"]/*' />
        [
            Browsable(false),
            DefaultValue(""),
            MobileSysDescription(SR.Style_Name),
            NotifyParentProperty(true),
        ]
        public String Name
        {
            get
            {
                String name = (String)State["Name"];
                return name != null ? name : String.Empty;
            }
            set
            {
                State["Name"] = value;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.StyleReference"]/*' />
        [
            Bindable(false),
            DefaultValue(null),
            MobileCategory(SR.Category_Appearance),
            MobileSysDescription(SR.Style_Reference),
            NotifyParentProperty(true),
            TypeConverter(typeof(System.Web.UI.Design.MobileControls.Converters.StyleReferenceConverter)),
        ]
        public virtual String StyleReference
        {
            get
            {
                return (String)State["StyleReference"];
            }
            set
            {
                State["StyleReference"] = value;
                Refresh();      // mark referred style as dirty
            }
        }

        [
            Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        internal Style ReferredStyle
        {
            get
            {
                if (_checkedStyleReference)
                {
                    return _referredStyle;
                }

                _checkedStyleReference = true;
                String reference = StyleReference;

                if (String.IsNullOrEmpty(reference))
                {
                    _referredStyle = null;
                    return null;
                }

                Debug.Assert(_referredStyle == null ||
                             String.Equals(reference, _referredStyle.Name, StringComparison.OrdinalIgnoreCase), 
                             "Inconsistency in style names - _referredStyle must be dirty.");
                
                if (_referredStyle == null)
                {
                    // Look in the stylesheet in the nearest templated control
                    TemplateControl nearestTemplatedControl =
                        _control.FindContainingTemplateControl();

                    StyleSheet stylesheet = null;
                    MobilePage mobilePage = nearestTemplatedControl as MobilePage;
                    if (mobilePage != null)
                    {
                        stylesheet = mobilePage.StyleSheet;
                    }
                    else
                    {
                        MobileUserControl mobileUserControl =
                            nearestTemplatedControl as MobileUserControl;
                        if (mobileUserControl != null)
                        {
                            stylesheet = mobileUserControl.StyleSheet;

                            // If stylesheet is in mobileUserControl at designtime, 
                            // simply use the one in MobilePage
                            if (_control.MobilePage.DesignMode)
                            {
                                Debug.Assert(stylesheet == StyleSheet.Default);
                                stylesheet = _control.MobilePage.StyleSheet;
                            }
                        }

                        // Stylesheets won't be recognized in regular user
                        // controls.
                    }

                    if (stylesheet != null)
                    {
                        // when page does not contain StyleSheet
                        // controls, Default stylesheet will search twice. 
                        _referredStyle = stylesheet[reference];
                    }

                    if (_referredStyle == null)
                    {
                        // built in styles
                        _referredStyle = StyleSheet.Default[reference];

                        // No exceptions in Designer, will handle differently.
                        if (_referredStyle == null && !_control.MobilePage.DesignMode)
                        {
                            String exceptionResource;
                            if (nearestTemplatedControl is UserControl &&
                                !(nearestTemplatedControl is MobileUserControl))
                            {
                                // Throw a specific error message in this case
                                exceptionResource =
                                    SR.Style_StyleNotFoundOnGenericUserControl;
                            }
                            else
                            {
                                exceptionResource =
                                    SR.Style_StyleNotFound;
                            }
                                
                            throw new Exception(SR.GetString(exceptionResource,
                                                             reference)); 
                        }
                    }
                }

                return _referredStyle;
            }
        }

        //  late bound method for accessing style properties
        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.this"]/*' />
        public Object this[Object key]
        {
            get
            {
                return GetValue((Property)key, false, true, null);
            }
            set
            {
                Property property = (Property)key;
                Object defaultValue = property.DefaultValue;
                State[property.Name] = defaultValue.Equals(value) ? null : value;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.this1"]/*' />
        public Object this[Object key, bool inherit]
        {
            get
            {
                return GetValue((Property)key, inherit, true, null);
            }
        }

        private Object GetValue(Property property, bool inherit, bool returnDefault, Hashtable stylesEncountered)
        {
            //  try to retrieve from internal value
            Object value = State[property.Name];

            if (value == null)
            {
                //  else retrieve from style reference
                if (inherit)
                {
                    Style style = this.ReferredStyle;
                    if (style != null)
                    {
                        if (stylesEncountered == null)
                        {
                            stylesEncountered = new Hashtable(); 
                        }

                        if (stylesEncountered.ContainsKey(style))
                        {
                            if (_control.MobilePage != null && _control.MobilePage.DesignMode)
                            {
                                return property.DefaultValue;
                            }
                            else
                            {
                                throw new Exception(SR.GetString(SR.Style_CircularReference, this.Name));
                            }
                        }
                        stylesEncountered[style] = true;
                        value = style.GetValue(property, inherit, false, stylesEncountered);
                    }
                }

                if (value == null)
                {
                    //  else retrieve from control ancestor
                    if (inherit && property.Inherit && _control != null)
                    {
                        Style parentStyle = null;
                        if (_cachedParentStyle == null)
                        {
                            if (_control.Parent is MobileControl)
                            {
                                parentStyle = ((MobileControl)_control.Parent).Style;
                                _cachedParentStyle = parentStyle;
                            }
                            // DeviceSpecific is treated as control at design time, however, we need to get
                            // the styles from devicespecific's parent.
                            else if (_control.MobilePage != null &&
                                _control.MobilePage.DesignMode && 
                                _control.Parent is DeviceSpecific &&
                                _control.Parent.Parent is MobileControl)
                            {
                                parentStyle = ((MobileControl)_control.Parent.Parent).Style;
                            }
                            else if(!(_control is Form))
                            {
                                Control _tempControl = _control.Parent;
                                while(!(_tempControl is MobileControl) && (_tempControl != null))
                                {
                                    _tempControl = _tempControl.Parent;
                                }
                                if(_tempControl != null)
                                {
                                    parentStyle = ((MobileControl)_tempControl).Style;
                                }
                            }
                        }
                        else
                        {
                            parentStyle = _cachedParentStyle;
                        }

                        if (parentStyle != null)
                        {
                            value = parentStyle.GetValue(property, inherit, false, null);
                        }
                    }

                    //  else retrieve default value
                    if (value == null && returnDefault)
                    {
                        value = property.DefaultValue;
                    }
                }
            }
            return value;
        }

        internal void InvalidateParentStyle()
        {
            _cachedParentStyle = null;
        }

        ////////////////////////////////////////////////////////////////////////////
        //  BEGIN STYLES
        ////////////////////////////////////////////////////////////////////////////

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.Font"]/*' />
        [
            DefaultValue(null),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
            MobileCategory(SR.Category_Appearance),
            MobileSysDescription(SR.Style_Font),
            NotifyParentProperty(true)
        ]
        public FontInfo Font
        {
            get
            {
                if (_font == null)
                {
                    _font = new FontInfo(this);
                }
                return _font;
            }
        }

        // FontSize and FontName internal
        // we still need these methods on style due to their inheritance and
        // persistence behavior, they're referenced from FontInfo.cs.
        // 


        [
            Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        internal String FontName
        {
            get
            {
                return (String)this[FontNameKey];
            }
            set
            {
                this[FontNameKey] = value;
            }
        }

        [
            Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        internal BooleanOption Bold
        {
            get
            {
                return (BooleanOption)this[BoldKey];
            }
            set
            {
                this[BoldKey] = value;
            }
        }

        [
            Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        internal BooleanOption Italic
        {
            get
            {
                return (BooleanOption)this[ItalicKey];
            }
            set
            {
                this[ItalicKey] = value;
            }
        }

        [
            Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        internal FontSize FontSize
        {
            get
            {
                return (FontSize)this[FontSizeKey];
            }
            set
            {
                this[FontSizeKey] = value;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.Alignment"]/*' />
        [
            Bindable(true),
            DefaultValue(Alignment.NotSet),
            MobileCategory(SR.Category_Appearance),
            MobileSysDescription(SR.Style_Alignment),
            NotifyParentProperty(true),
        ]
        public Alignment Alignment
        {
            get
            {
                return (Alignment)this[AlignmentKey];
            }
            set
            {
                this[AlignmentKey] = value;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.Wrapping"]/*' />
        [
            Bindable(true),
            DefaultValue(Wrapping.NotSet),
            MobileCategory(SR.Category_Appearance),
            MobileSysDescription(SR.Style_Wrapping),
            NotifyParentProperty(true),
        ]
        public Wrapping Wrapping
        {
            get
            {
                return (Wrapping)this[WrappingKey];
            }
            set
            {
                this[WrappingKey] = value;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.ForeColor"]/*' />
        [
            Bindable(true),
            DefaultValue(typeof(Color), ""),
            MobileCategory(SR.Category_Appearance),
            MobileSysDescription(SR.Style_ForeColor),
            NotifyParentProperty(true),
            TypeConverterAttribute(typeof(WebColorConverter)),
        ]
        public Color ForeColor
        {
            get
            {
                return (Color)this[ForeColorKey];
            }
            set
            {
                this[ForeColorKey] = value;
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.BackColor"]/*' />
        [
            Bindable(true),
            DefaultValue(typeof(Color), ""),
            MobileCategory(SR.Category_Appearance),
            MobileSysDescription(SR.Style_BackColor),
            NotifyParentProperty(true),
            TypeConverterAttribute(typeof(WebColorConverter))
        ]
        public Color BackColor
        {
            get
            {
                return (Color)this[BackColorKey];
            }
            set
            {
                this[BackColorKey] = value;
            }
        }

        /////////////////////////////////////////////////////////////////////////
        //  TEMPLATES SUPPORT
        /////////////////////////////////////////////////////////////////////////


        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.IParserAccessor.AddParsedSubObject"]/*' />
        /// <internalonly/>
        protected void AddParsedSubObject(Object o)
        {
            if (o is DeviceSpecific)
            {
                if (DeviceSpecific != null)
                {
                    throw new Exception(
                        SR.GetString(SR.MobileControl_NoMultipleDeviceSpecifics));
                }
                DeviceSpecific = (DeviceSpecific)o;

                // This code works by assuming that the time this
                // method is called, that Control has not yet been
                // set.  Thus, we set the DeviceSpecific's parent
                // control when the Control itself is set.  If Control
                // != null here, then we won't get that opportunity. 
                Debug.Assert(Control == null);
            }
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.IsTemplated"]/*' />
        [
            Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public bool IsTemplated
        {
            get
            {
                return IsTemplatedInternal(null);
            }
        }

        internal bool IsTemplatedInternal(Hashtable stylesEncountered)
        {
            if (_deviceSpecific != null && _deviceSpecific.HasTemplates)
            {
                return true;
            }

            Style referredStyle = ReferredStyle;
            if (referredStyle == null)
            {
                return false;
            }

            if (stylesEncountered == null)
            {
                stylesEncountered = new Hashtable(); 
            }
            if (stylesEncountered.ContainsKey(referredStyle))
            {
                if (_control.MobilePage != null && _control.MobilePage.DesignMode)
                {
                    return false;
                }
                else
                {
                    throw new Exception(SR.GetString(SR.Style_CircularReference, this.Name));
                }
            }
            // referredStyle != null
            stylesEncountered[referredStyle] = true;
            return referredStyle.IsTemplatedInternal(stylesEncountered);
        }

        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.GetTemplate"]/*' />
        public ITemplate GetTemplate(String templateName)
        {
            return GetTemplateInternal(templateName, null);
        }

        internal ITemplate GetTemplateInternal(String templateName, Hashtable stylesEncountered)
        {
            ITemplate t = null;
            if (_deviceSpecific != null)
            {
                t = (ITemplate)_deviceSpecific.GetTemplate (templateName);
            }

            Style referredStyle = ReferredStyle;
            if (t == null && referredStyle != null)
            {
                // Check for cyclical style references.
                if (stylesEncountered == null)
                {
                    stylesEncountered = new Hashtable ();
                }
                if (stylesEncountered.ContainsKey(referredStyle))
                {
                    if (_control.MobilePage != null && _control.MobilePage.DesignMode)
                    {
                        return null;
                    }
                    else
                    {
                        throw new Exception(SR.GetString(SR.Style_CircularReference, this.Name));
                    }
                }

                // No cycle detected.
                stylesEncountered[referredStyle] = true;                
                t = referredStyle.GetTemplateInternal(templateName, stylesEncountered);
            }

            return t;
        }

        // Design-time only property
        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.DeviceSpecific"]/*' />
        [
            Browsable(false),
            PersistenceMode(PersistenceMode.InnerProperty)
        ]
        public DeviceSpecific DeviceSpecific
        {
            get
            {
                return _deviceSpecific;
            }
            set
            {
                _deviceSpecific = value;
                if (null != value)
                {
                    value.SetOwner(this);
                }
            }
        }

        //  registers a new type of style and returns the KEY for accessing it
        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.RegisterStyle"]/*' />
        public static Object RegisterStyle(String name, Type type, Object defaultValue, bool inherit)
        {
            return new Property(name, type, defaultValue, inherit);
        }

        class Property
        {
            public String Name;
            public Type   Type;
            public Object DefaultValue;
            public bool   Inherit;        // can be inherited from parent?

            public Property(String name, Type type, Object defaultValue, bool inherit)
            {
                this.Name = name;
                this.Type = type;
                this.DefaultValue = defaultValue;
                this.Inherit = inherit;
            }
        }

        #region Implementation of IStateManager
        /// <internalonly/>
        bool IStateManager.IsTrackingViewState {
            get {
                return IsTrackingViewState;
            }
        }

        /// <internalonly/>
        void IStateManager.LoadViewState(object state) {
            LoadViewState(state);
        }

        /// <internalonly/>
        void IStateManager.TrackViewState() {
            TrackViewState();
        }

        /// <internalonly/>
        object IStateManager.SaveViewState() {
            return SaveViewState();
        }
        #endregion

        #region IParserAccessor implementation
        void IParserAccessor.AddParsedSubObject(Object o) {
            AddParsedSubObject(o);
        }
        #endregion
    }
}