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
|
//------------------------------------------------------------------------------
// <copyright file="ListItemsPage.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
// using System.Web.UI.Design.Util;
using System.Web.UI.MobileControls;
using System.Web.UI.Design.MobileControls.Util;
using Button = System.Windows.Forms.Button;
using Label = System.Windows.Forms.Label;
using TextBox = System.Windows.Forms.TextBox;
using CheckBox = System.Windows.Forms.CheckBox;
using TreeView = System.Windows.Forms.TreeView;
/// <summary>
/// The Items page for the List control.
/// </summary>
/// <internalonly/>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[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.")]
internal sealed class ListItemsPage : ListComponentEditorPage
{
private IListDesigner _listDesigner;
private CheckBox _itemsAsLinksCheckBox;
private TextBox _txtValue;
private CheckBox _ckbSelected;
private bool _isBaseControlList;
public ListItemsPage()
{
TreeViewTitle = SR.GetString(SR.ListItemsPage_ItemCaption);
AddButtonTitle = SR.GetString(SR.ListItemsPage_NewItemCaption);
DefaultName = SR.GetString(SR.ListItemsPage_DefaultItemText);
}
protected override String HelpKeyword
{
get
{
if (_isBaseControlList)
{
return "net.Mobile.ListProperties.Items";
}
else
{
return "net.Mobile.SelectionListProperties.Items";
}
}
}
protected override bool FilterIllegalName()
{
return false;
}
protected override String GetNewName()
{
return SR.GetString(SR.ListItemsPage_DefaultItemText);
}
protected override void InitForm()
{
Debug.Assert(GetBaseControl() != null);
_isBaseControlList = (GetBaseControl() is List);
this._listDesigner = (IListDesigner)GetBaseDesigner();
Y = (_isBaseControlList ? 52 : 24);
base.InitForm();
this.Text = SR.GetString(SR.ListItemsPage_Title);
this.CommitOnDeactivate = true;
this.Icon = new Icon(
typeof(System.Web.UI.Design.MobileControls.MobileControlDesigner),
"Items.ico"
);
this.Size = new Size(382, 220);
if (_isBaseControlList)
{
_itemsAsLinksCheckBox = new CheckBox();
_itemsAsLinksCheckBox.SetBounds(4, 4, 370, 16);
_itemsAsLinksCheckBox.Text = SR.GetString(SR.ListItemsPage_ItemsAsLinksCaption);
_itemsAsLinksCheckBox.FlatStyle = FlatStyle.System;
_itemsAsLinksCheckBox.CheckedChanged += new EventHandler(this.OnSetPageDirty);
_itemsAsLinksCheckBox.TabIndex = 0;
}
GroupLabel grplblItemList = new GroupLabel();
grplblItemList.SetBounds(4, _isBaseControlList ? 32 : 4, 372, LabelHeight);
grplblItemList.Text = SR.GetString(SR.ListItemsPage_ItemListGroupLabel);
grplblItemList.TabIndex = 1;
grplblItemList.TabStop = false;
TreeList.TabIndex = 2;
Label lblValue = new Label();
lblValue.SetBounds(X, Y, 134, LabelHeight);
lblValue.Text = SR.GetString(SR.ListItemsPage_ItemValueCaption);
lblValue.TabStop = false;
lblValue.TabIndex = Index;
Y += LabelHeight;
_txtValue = new TextBox();
_txtValue.SetBounds(X, Y, 134, CmbHeight);
_txtValue.TextChanged += new EventHandler(this.OnPropertyChanged);
_txtValue.TabIndex = Index + 1;
this.Controls.AddRange(new Control[]
{
grplblItemList,
lblValue,
_txtValue
});
if (_isBaseControlList)
{
this.Controls.Add(_itemsAsLinksCheckBox);
}
else
{
Y += CellSpace;
_ckbSelected = new CheckBox();
_ckbSelected.SetBounds(X, Y, 134, LabelHeight);
_ckbSelected.FlatStyle = System.Windows.Forms.FlatStyle.System;
_ckbSelected.Text = SR.GetString(SR.ListItemsPage_ItemSelectedCaption);
_ckbSelected.CheckedChanged += new EventHandler(this.OnPropertyChanged);
_ckbSelected.TabIndex = Index + 2;
this.Controls.Add(_ckbSelected);
}
}
protected override void InitPage()
{
base.InitPage();
if (_isBaseControlList)
{
List list = (List)GetBaseControl();
_itemsAsLinksCheckBox.Checked = list.ItemsAsLinks;
}
else
{
_ckbSelected.Checked = false;
}
_txtValue.Text = String.Empty;
}
protected override void LoadItems()
{
using (new LoadingModeResource(this))
{
foreach (MobileListItem item in _listDesigner.Items)
{
ItemTreeNode newNode = new ItemTreeNode(item);
TreeList.TvList.Nodes.Add(newNode);
}
}
}
protected override void LoadItemProperties()
{
using (new LoadingModeResource(this))
{
if (CurrentNode != null)
{
ItemTreeNode currentItemNode = (ItemTreeNode)CurrentNode;
_txtValue.Text = currentItemNode.Value;
if (!_isBaseControlList)
{
_ckbSelected.Checked = currentItemNode.Selected;
}
}
else
{
_txtValue.Text = String.Empty;
if (!_isBaseControlList)
{
_ckbSelected.Checked = false;
}
}
}
}
protected override void OnAfterLabelEdit(Object source, NodeLabelEditEventArgs e)
{
base.OnAfterLabelEdit(source, e);
if (!((ItemTreeNode)CurrentNode).ValueSet)
{
_txtValue.Text = ((ItemTreeNode)CurrentNode).Value = CurrentNode.Name;
}
}
protected override void OnClickAddButton(Object source, EventArgs e)
{
if (IsLoading())
{
return;
}
ItemTreeNode newNode = new ItemTreeNode(GetNewName());
TreeList.TvList.Nodes.Add(newNode);
TreeList.TvList.SelectedNode = newNode;
CurrentNode = newNode;
newNode.Dirty = true;
newNode.BeginEdit();
LoadItemProperties();
SetDirty();
}
private void OnSetPageDirty(Object source, EventArgs e)
{
if (IsLoading())
{
return;
}
SetDirty();
}
protected override void OnPropertyChanged(Object source, EventArgs e)
{
// This means there are no fields yet. Do nothing
if (CurrentNode == null || IsLoading())
{
return;
}
if (source is TextBox)
{
((ItemTreeNode)CurrentNode).Value = _txtValue.Text;
}
else
{
Debug.Assert(!_isBaseControlList);
((ItemTreeNode)CurrentNode).Selected = _ckbSelected.Checked;
}
SetDirty();
CurrentNode.Dirty = true;
}
protected override void SaveComponent()
{
// Delegate to base implementation first!
// This will properly close ListTreeNode editing mode.
base.SaveComponent();
_listDesigner.Items.Clear();
foreach (ItemTreeNode itemNode in TreeList.TvList.Nodes)
{
if (itemNode.Dirty)
{
itemNode.RuntimeItem.Text = itemNode.Text;
itemNode.RuntimeItem.Value = itemNode.Value;
if (!_isBaseControlList)
{
itemNode.RuntimeItem.Selected = itemNode.Selected;
}
}
_listDesigner.Items.Add(itemNode.RuntimeItem);
}
if (_isBaseControlList)
{
List list = (List)GetBaseControl();
list.ItemsAsLinks = _itemsAsLinksCheckBox.Checked;
TypeDescriptor.Refresh(list);
}
else
{
SelectionList selectionList = (SelectionList)GetBaseControl();
TypeDescriptor.Refresh(selectionList);
}
}
protected override void UpdateControlsEnabling()
{
if (TreeList.TvList.SelectedNode == null)
{
TreeList.TvList.Enabled = _txtValue.Enabled = false;
_txtValue.Text = String.Empty;
}
else
{
TreeList.TvList.Enabled = _txtValue.Enabled = true;
}
if (!_isBaseControlList)
{
SelectionList selectionListControl = (SelectionList) GetBaseControl();
if (TreeList.TvList.SelectedNode == null)
{
_ckbSelected.Enabled = false;
_ckbSelected.Checked = false;
}
else
{
_ckbSelected.Enabled = true;
}
}
}
/// <summary>
/// Internal object used to store all items properties
/// </summary>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
private class ItemTreeNode : ListTreeNode
{
private MobileListItem _runtimeItem;
private String _value;
private bool _selected;
private bool _valueSet = false;
/// <summary>
/// </summary>
internal ItemTreeNode(String itemText) : base(itemText)
{
this._runtimeItem = new MobileListItem();
this._value = null;
this._selected = false;
}
/// <summary>
/// </summary>
internal ItemTreeNode(MobileListItem runtimeItem) : base(runtimeItem.Text)
{
Debug.Assert(runtimeItem != null, "runtimeItem is null");
_valueSet = true;
this._runtimeItem = runtimeItem;
this._value = _runtimeItem.Value;
this._selected = _runtimeItem.Selected;
}
internal MobileListItem RuntimeItem
{
get
{
return _runtimeItem;
}
}
internal String Value
{
get
{
return _value;
}
set
{
_value = value;
_valueSet = true;
}
}
internal bool Selected
{
get
{
return _selected;
}
set
{
_selected = value;
}
}
internal bool ValueSet
{
get
{
return _valueSet;
}
}
}
}
}
|