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
|
//
// System.Web.UI.WebControls.SiteMapPath.cs
//
// Authors:
// Lluis Sanchez Gual (lluis@novell.com)
//
// (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
namespace System.Web.UI.WebControls
{
[Designer ("System.Web.UI.Design.WebControls.SiteMapPathDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
public class SiteMapPath: CompositeControl
{
SiteMapProvider provider;
Style currentNodeStyle;
Style nodeStyle;
Style pathSeparatorStyle;
Style rootNodeStyle;
ITemplate currentNodeTemplate;
ITemplate nodeTemplate;
ITemplate pathSeparatorTemplate;
ITemplate rootNodeTemplate;
static readonly object ItemCreatedEvent = new object();
static readonly object ItemDataBoundEvent = new object();
public event SiteMapNodeItemEventHandler ItemCreated {
add { Events.AddHandler (ItemCreatedEvent, value); }
remove { Events.RemoveHandler (ItemCreatedEvent, value); }
}
public event SiteMapNodeItemEventHandler ItemDataBound {
add { Events.AddHandler (ItemDataBoundEvent, value); }
remove { Events.RemoveHandler (ItemDataBoundEvent, value); }
}
protected virtual void OnItemCreated (SiteMapNodeItemEventArgs e)
{
if (Events != null) {
SiteMapNodeItemEventHandler eh = (SiteMapNodeItemEventHandler) Events [ItemCreatedEvent];
if (eh != null) eh (this, e);
}
}
protected virtual void OnItemDataBound (SiteMapNodeItemEventArgs e)
{
if (Events != null) {
SiteMapNodeItemEventHandler eh = (SiteMapNodeItemEventHandler) Events [ItemDataBoundEvent];
if (eh != null) eh (this, e);
}
}
[DefaultValueAttribute (null)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
[NotifyParentPropertyAttribute (true)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
public Style CurrentNodeStyle {
get {
if (currentNodeStyle == null) {
currentNodeStyle = new Style ();
if (IsTrackingViewState)
((IStateManager)currentNodeStyle).TrackViewState ();
}
return currentNodeStyle;
}
}
[DefaultValue (null)]
[TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Browsable (false)]
public virtual ITemplate CurrentNodeTemplate {
get { return currentNodeTemplate; }
set { currentNodeTemplate = value; UpdateControls (); }
}
[DefaultValueAttribute (null)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
[NotifyParentPropertyAttribute (true)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
public Style NodeStyle {
get {
if (nodeStyle == null) {
nodeStyle = new Style ();
if (IsTrackingViewState)
((IStateManager)nodeStyle).TrackViewState ();
}
return nodeStyle;
}
}
[DefaultValue (null)]
[TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Browsable (false)]
public virtual ITemplate NodeTemplate {
get { return nodeTemplate; }
set { nodeTemplate = value; UpdateControls (); }
}
[DefaultValueAttribute (-1)]
[ThemeableAttribute (false)]
public virtual int ParentLevelsDisplayed {
get { return ViewState.GetInt ("ParentLevelsDisplayed", -1); }
set {
if (value < -1) throw new ArgumentOutOfRangeException ("value");
ViewState ["ParentLevelsDisplayed"] = value;
UpdateControls ();
}
}
[DefaultValueAttribute (PathDirection.RootToCurrent)]
public virtual PathDirection PathDirection {
get { return (PathDirection)ViewState.GetInt ("PathDirection", (int)PathDirection.RootToCurrent); }
set {
if (value != PathDirection.RootToCurrent && value != PathDirection.CurrentToRoot)
throw new ArgumentOutOfRangeException ("value");
ViewState ["PathDirection"] = value;
UpdateControls ();
}
}
[DefaultValueAttribute (" > ")]
[LocalizableAttribute (true)]
public virtual string PathSeparator {
get { return ViewState.GetString ("PathSeparator", " > "); }
set {
ViewState ["PathSeparator"] = value;
UpdateControls ();
}
}
[DefaultValueAttribute (null)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
[NotifyParentPropertyAttribute (true)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
public Style PathSeparatorStyle {
get {
if (pathSeparatorStyle == null) {
pathSeparatorStyle = new Style ();
if (IsTrackingViewState)
((IStateManager)pathSeparatorStyle).TrackViewState ();
}
return pathSeparatorStyle;
}
}
[DefaultValue (null)]
[TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Browsable (false)]
public virtual ITemplate PathSeparatorTemplate {
get { return pathSeparatorTemplate; }
set { pathSeparatorTemplate = value; UpdateControls (); }
}
[BrowsableAttribute (false)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
public SiteMapProvider Provider {
get {
if (provider == null) {
if (this.SiteMapProvider.Length == 0) {
provider = SiteMap.Provider;
if (provider == null)
throw new HttpException ("There is no default provider configured for the site.");
} else {
provider = SiteMap.Providers [this.SiteMapProvider];
if (provider == null)
throw new HttpException ("SiteMap provider '" + this.SiteMapProvider + "' not found.");
}
}
return provider;
}
set {
provider = value;
UpdateControls ();
}
}
[DefaultValueAttribute (false)]
public virtual bool RenderCurrentNodeAsLink {
get { return ViewState.GetBool ("RenderCurrentNodeAsLink", false); }
set {
ViewState ["RenderCurrentNodeAsLink"] = value;
UpdateControls ();
}
}
[DefaultValueAttribute (null)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
[NotifyParentPropertyAttribute (true)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
public Style RootNodeStyle {
get {
if (rootNodeStyle == null) {
rootNodeStyle = new Style ();
if (IsTrackingViewState)
((IStateManager)rootNodeStyle).TrackViewState ();
}
return rootNodeStyle;
}
}
[DefaultValue (null)]
[TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Browsable (false)]
public virtual ITemplate RootNodeTemplate {
get { return rootNodeTemplate; }
set { rootNodeTemplate = value; UpdateControls (); }
}
[DefaultValueAttribute (true)]
[ThemeableAttribute (false)]
public virtual bool ShowToolTips {
get { return ViewState.GetBool ("ShowToolTips", true); }
set {
ViewState ["ShowToolTips"] = value;
UpdateControls ();
}
}
[DefaultValueAttribute ("")]
[ThemeableAttribute (false)]
public virtual string SiteMapProvider {
get { return ViewState.GetString ("SiteMapProvider", ""); }
set {
ViewState ["SiteMapProvider"] = value;
UpdateControls ();
}
}
[Localizable (true)]
public virtual string SkipLinkText
{
get { return ViewState.GetString ("SkipLinkText", "Skip Navigation Links"); }
set { ViewState["SkipLinkText"] = value; }
}
void UpdateControls ()
{
ChildControlsCreated = false;
}
public override void DataBind ()
{
base.DataBind ();
/* the child controls get bound in
* base.DataBind */
foreach (Control c in Controls) {
if (c is SiteMapNodeItem) {
SiteMapNodeItem it = (SiteMapNodeItem)c;
OnItemDataBound (new SiteMapNodeItemEventArgs (it));
}
}
}
protected internal override void CreateChildControls ()
{
Controls.Clear ();
CreateControlHierarchy ();
DataBind ();
}
protected virtual void CreateControlHierarchy ()
{
ArrayList nodes = new ArrayList ();
SiteMapNode node = Provider.CurrentNode;
if (node == null) return;
int levels = ParentLevelsDisplayed != -1 ? ParentLevelsDisplayed + 1 : int.MaxValue;
while (node != null && levels > 0) {
if (nodes.Count > 0) {
SiteMapNodeItem sep = new SiteMapNodeItem (nodes.Count, SiteMapNodeItemType.PathSeparator);
InitializeItem (sep);
SiteMapNodeItemEventArgs sargs = new SiteMapNodeItemEventArgs (sep);
OnItemCreated (sargs);
nodes.Add (sep);
}
SiteMapNodeItemType nt;
if (nodes.Count == 0)
nt = SiteMapNodeItemType.Current;
else if (node.ParentNode == null)
nt = SiteMapNodeItemType.Root;
else
nt = SiteMapNodeItemType.Parent;
SiteMapNodeItem it = new SiteMapNodeItem (nodes.Count, nt);
it.SiteMapNode = node;
InitializeItem (it);
SiteMapNodeItemEventArgs args = new SiteMapNodeItemEventArgs (it);
OnItemCreated (args);
nodes.Add (it);
node = node.ParentNode;
levels--;
}
if (PathDirection == PathDirection.RootToCurrent) {
for (int n=nodes.Count - 1; n>=0; n--)
Controls.Add ((Control)nodes[n]);
} else {
for (int n=0; n<nodes.Count; n++)
Controls.Add ((Control)nodes[n]);
}
}
protected virtual void InitializeItem (SiteMapNodeItem item)
{
switch (item.ItemType) {
case SiteMapNodeItemType.Root:
if (RootNodeTemplate != null) {
item.ApplyStyle (NodeStyle);
item.ApplyStyle (RootNodeStyle);
RootNodeTemplate.InstantiateIn (item);
}
else if (NodeTemplate != null) {
item.ApplyStyle (NodeStyle);
item.ApplyStyle (RootNodeStyle);
NodeTemplate.InstantiateIn (item);
}
else {
WebControl c = CreateHyperLink (item);
c.ApplyStyle (NodeStyle);
c.ApplyStyle (RootNodeStyle);
item.Controls.Add (c);
}
break;
case SiteMapNodeItemType.Current:
if (CurrentNodeTemplate != null) {
item.ApplyStyle (NodeStyle);
item.ApplyStyle (CurrentNodeStyle);
CurrentNodeTemplate.InstantiateIn (item);
}
else if (NodeTemplate != null) {
item.ApplyStyle (NodeStyle);
item.ApplyStyle (CurrentNodeStyle);
NodeTemplate.InstantiateIn (item);
} else if (RenderCurrentNodeAsLink) {
HyperLink c = CreateHyperLink (item);
c.ApplyStyle (NodeStyle);
c.ApplyStyle (CurrentNodeStyle);
item.Controls.Add (c);
} else {
Literal c = CreateLiteral (item);
item.ApplyStyle (NodeStyle);
item.ApplyStyle (CurrentNodeStyle);
item.Controls.Add (c);
}
break;
case SiteMapNodeItemType.Parent:
if (NodeTemplate != null) {
item.ApplyStyle (NodeStyle);
NodeTemplate.InstantiateIn (item);
}
else {
WebControl c = CreateHyperLink (item);
c.ApplyStyle (NodeStyle);
item.Controls.Add (c);
}
break;
case SiteMapNodeItemType.PathSeparator:
if (PathSeparatorTemplate != null) {
item.ApplyStyle (PathSeparatorStyle);
PathSeparatorTemplate.InstantiateIn (item);
} else {
Literal h = new Literal ();
h.Text = HttpUtility.HtmlEncode (PathSeparator);
item.ApplyStyle (PathSeparatorStyle);
item.Controls.Add (h);
}
break;
}
}
HyperLink CreateHyperLink (SiteMapNodeItem item)
{
HyperLink h = new HyperLink ();
h.Text = item.SiteMapNode.Title;
h.NavigateUrl = item.SiteMapNode.Url;
if (ShowToolTips)
h.ToolTip = item.SiteMapNode.Description;
return h;
}
Literal CreateLiteral (SiteMapNodeItem item)
{
Literal h = new Literal ();
h.Text = item.SiteMapNode.Title;
return h;
}
protected override void LoadViewState (object savedState)
{
if (savedState == null) {
base.LoadViewState (null);
return;
}
object[] states = (object[]) savedState;
base.LoadViewState (states [0]);
if (states[1] != null) ((IStateManager)CurrentNodeStyle).LoadViewState (states[1]);
if (states[2] != null) ((IStateManager)NodeStyle).LoadViewState (states[2]);
if (states[3] != null) ((IStateManager)PathSeparatorStyle).LoadViewState (states[3]);
if (states[4] != null) ((IStateManager)RootNodeStyle).LoadViewState (states[4]);
}
[MonoTODO ("why override?")]
protected override void OnDataBinding (EventArgs e)
{
base.OnDataBinding (e);
}
[MonoTODO ("why override?")]
protected internal override void Render (HtmlTextWriter w)
{
base.Render (w);
}
protected internal override void RenderContents (HtmlTextWriter w)
{
string skip_id = ClientID + "_SkipLink";
string altText = SkipLinkText;
bool needAnchor = !String.IsNullOrEmpty (altText);
if (needAnchor) {
// Anchor start
w.AddAttribute (HtmlTextWriterAttribute.Href, "#" + skip_id);
w.RenderBeginTag (HtmlTextWriterTag.A);
// Image
w.AddAttribute (HtmlTextWriterAttribute.Alt, altText);
w.AddAttribute (HtmlTextWriterAttribute.Height, "0");
w.AddAttribute (HtmlTextWriterAttribute.Width, "0");
w.AddAttribute (HtmlTextWriterAttribute.Src, Page.ClientScript.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif"));
w.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, "0px");
w.RenderBeginTag (HtmlTextWriterTag.Img);
w.RenderEndTag ();
w.RenderEndTag ();
}
base.RenderContents (w);
if (needAnchor) {
w.AddAttribute(HtmlTextWriterAttribute.Id, skip_id);
w.RenderBeginTag(HtmlTextWriterTag.A);
w.RenderEndTag();
}
}
protected override object SaveViewState ()
{
object[] state = new object [5];
state [0] = base.SaveViewState ();
if (currentNodeStyle != null) state [1] = ((IStateManager)currentNodeStyle).SaveViewState ();
if (nodeStyle != null) state [2] = ((IStateManager)nodeStyle).SaveViewState ();
if (pathSeparatorStyle != null) state [3] = ((IStateManager)pathSeparatorStyle).SaveViewState ();
if (rootNodeStyle != null) state [4] = ((IStateManager)rootNodeStyle).SaveViewState ();
for (int n=0; n<state.Length; n++)
if (state [n] != null) return state;
return null;
}
protected override void TrackViewState ()
{
base.TrackViewState();
if (currentNodeStyle != null) ((IStateManager)currentNodeStyle).TrackViewState();
if (nodeStyle != null) ((IStateManager)nodeStyle).TrackViewState();
if (pathSeparatorStyle != null) ((IStateManager)pathSeparatorStyle).TrackViewState();
if (rootNodeStyle != null) ((IStateManager)rootNodeStyle).TrackViewState();
}
}
}
#endif
|