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
|
//------------------------------------------------------------------------------
// <copyright file="DeclarativeCatalogPart.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.WebControls.WebParts {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
using System.Web.Security;
using System.Web.Util;
/// <devdoc>
/// </devdoc>
[
Designer("System.Web.UI.Design.WebControls.WebParts.DeclarativeCatalogPartDesigner, " + AssemblyRef.SystemDesign),
]
public sealed class DeclarativeCatalogPart : CatalogPart {
private ITemplate _webPartsTemplate;
private WebPartDescriptionCollection _descriptions;
private string _webPartsListUserControlPath;
[
WebSysDefaultValue(SR.DeclarativeCatalogPart_PartTitle),
]
public override string Title {
get {
string s = (string)ViewState["Title"];
return (s != null) ? s : SR.GetString(SR.DeclarativeCatalogPart_PartTitle);
}
set {
ViewState["Title"] = value;
}
}
[
DefaultValue(""),
Editor("System.Web.UI.Design.UserControlFileEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
Themeable(false),
UrlProperty(),
WebCategory("Behavior"),
WebSysDescription(SR.DeclarativeCatlaogPart_WebPartsListUserControlPath),
]
public string WebPartsListUserControlPath {
get {
return (_webPartsListUserControlPath != null) ? _webPartsListUserControlPath : String.Empty;
}
set {
_webPartsListUserControlPath = value;
// Reset the collection of available web parts so it will be recreated
_descriptions = null;
}
}
/// <devdoc>
/// I don't know any reason this should be a single-instance template.
/// </devdoc>
[
Browsable(false),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(DeclarativeCatalogPart)),
// NOT single-instance template for now
]
public ITemplate WebPartsTemplate {
get {
return _webPartsTemplate;
}
set {
_webPartsTemplate = value;
// Reset the collection of available web parts so it will be recreated
_descriptions = null;
}
}
private void AddControlToDescriptions(Control control, ArrayList descriptions) {
WebPart webPart = control as WebPart;
if ((webPart == null) && !(control is LiteralControl)) {
// Fix for DesignMode
if (WebPartManager != null) {
webPart = WebPartManager.CreateWebPart(control);
}
else {
webPart = WebPartManager.CreateWebPartStatic(control);
}
}
// Fix for DesignMode
if (webPart != null && (WebPartManager == null || WebPartManager.IsAuthorized(webPart))) {
WebPartDescription description = new WebPartDescription(webPart);
descriptions.Add(description);
}
}
public override WebPartDescriptionCollection GetAvailableWebPartDescriptions() {
if (_descriptions == null) {
LoadAvailableWebParts();
}
return _descriptions;
}
public override WebPart GetWebPart(WebPartDescription description) {
if (description == null) {
throw new ArgumentNullException("description");
}
WebPartDescriptionCollection webPartDescriptions = GetAvailableWebPartDescriptions();
if (!webPartDescriptions.Contains(description)) {
throw new ArgumentException(SR.GetString(SR.CatalogPart_UnknownDescription), "description");
}
return description.WebPart;
}
private void LoadAvailableWebParts() {
ArrayList descriptions = new ArrayList();
if (WebPartsTemplate != null) {
Control container = new NonParentingControl();
WebPartsTemplate.InstantiateIn(container);
if (container.HasControls()) {
// Copy container.Controls to a temporary array, since adding the control to the
// descriptions may cause it to be reparented to a GenericWebPart, which would
// modify the container.Controls collection.
Control[] controls = new Control[container.Controls.Count];
container.Controls.CopyTo(controls, 0);
foreach (Control control in controls) {
AddControlToDescriptions(control, descriptions);
}
}
}
string webPartsListUserControlPath = WebPartsListUserControlPath;
if (!String.IsNullOrEmpty(webPartsListUserControlPath) && !DesignMode) {
// Page.LoadControl() throws a null ref exception at design-time
Control userControl = Page.LoadControl(webPartsListUserControlPath);
if (userControl != null && userControl.HasControls()) {
// Copy userControl.Controls to a temporary array, since adding the control to the
// descriptions may cause it to be reparented to a GenericWebPart, which would
// modify the userControl.Controls collection.
Control[] controls = new Control[userControl.Controls.Count];
userControl.Controls.CopyTo(controls, 0);
foreach (Control control in controls) {
AddControlToDescriptions(control, descriptions);
}
}
}
_descriptions = new WebPartDescriptionCollection(descriptions);
}
// Override Render to render nothing by default, since the CatalogPartChrome renders the
// AvailableWebParts. A CatalogPart only needs to render something if it wants
// additional rendering above the AvailableWebParts.
protected internal override void Render(HtmlTextWriter writer) {
}
#region Overriden to hide in the designer (VSWhidbey 353577)
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override string AccessKey {
get { return base.AccessKey; }
set { base.AccessKey = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override Color BackColor {
get { return base.BackColor; }
set { base.BackColor = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override string BackImageUrl {
get { return base.BackImageUrl; }
set { base.BackImageUrl = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override Color BorderColor {
get { return base.BorderColor; }
set { base.BorderColor = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override BorderStyle BorderStyle {
get { return base.BorderStyle; }
set { base.BorderStyle = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override Unit BorderWidth {
get { return base.BorderWidth; }
set { base.BorderWidth = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false), CssClassProperty()]
public override string CssClass {
get { return base.CssClass; }
set { base.CssClass = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override string DefaultButton {
get { return base.DefaultButton; }
set { base.DefaultButton = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override ContentDirection Direction {
get { return base.Direction; }
set { base.Direction = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override bool Enabled {
get { return base.Enabled; }
set { base.Enabled = value; }
}
[Browsable(false), DefaultValue(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override bool EnableTheming {
get { return false; }
set { throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name)); }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override FontInfo Font {
get { return base.Font; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override Color ForeColor {
get { return base.ForeColor; }
set { base.ForeColor = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override string GroupingText {
get { return base.GroupingText; }
set { base.GroupingText = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override Unit Height {
get { return base.Height; }
set { base.Height = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override HorizontalAlign HorizontalAlign {
get { return base.HorizontalAlign; }
set { base.HorizontalAlign = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override ScrollBars ScrollBars {
get { return base.ScrollBars; }
set { base.ScrollBars = value; }
}
[Browsable(false), DefaultValue(""), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override string SkinID {
get { return String.Empty; }
set { throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name)); }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override short TabIndex {
get { return base.TabIndex; }
set { base.TabIndex = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override string ToolTip {
get { return base.ToolTip; }
set { base.ToolTip = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override bool Visible {
get { return base.Visible; }
set { base.Visible = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override Unit Width {
get { return base.Width; }
set { base.Width = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
public override bool Wrap {
get { return base.Wrap; }
set { base.Wrap = value; }
}
#endregion
}
}
|