Switched ContainerListView to use the new ObservableCollection class for embedded controls instead of its custom collection; updated ProgressReporterForm to match current coding conventions

git-svn-id: file:///srv/devel/repo-conversion/nuwi@27 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2009-04-01 19:38:32 +00:00
parent 112e5993ef
commit 985f2622aa
4 changed files with 23 additions and 160 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion> <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BDC43D2A-7638-412E-976A-E7E115803A27}</ProjectGuid> <ProjectGuid>{BDC43D2A-7638-412E-976A-E7E115803A27}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
@ -79,7 +79,6 @@
<DependentUpon>ContainerListView.cs</DependentUpon> <DependentUpon>ContainerListView.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Source\ContainerListView\ListViewEmbeddedControl.cs" /> <Compile Include="Source\ContainerListView\ListViewEmbeddedControl.cs" />
<Compile Include="Source\ContainerListView\ListViewEmbeddedControlCollection.cs" />
<Compile Include="Source\EmbeddedControlCollection.cs" /> <Compile Include="Source\EmbeddedControlCollection.cs" />
<Compile Include="Source\ProgressReporter\ProgressReporterForm.cs"> <Compile Include="Source\ProgressReporter\ProgressReporterForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>

View File

@ -27,6 +27,8 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Nuclex.Support.Collections;
namespace Nuclex.Windows.Forms { namespace Nuclex.Windows.Forms {
/// <summary>ListView allowing for other controls to be embedded in its cells</summary> /// <summary>ListView allowing for other controls to be embedded in its cells</summary>
@ -44,20 +46,13 @@ namespace Nuclex.Windows.Forms {
public ContainerListView() { public ContainerListView() {
this.embeddedControlClickedDelegate = new EventHandler(embeddedControlClicked); this.embeddedControlClickedDelegate = new EventHandler(embeddedControlClicked);
this.embeddedControls = new ListViewEmbeddedControlCollection(); this.embeddedControls = new ObservableCollection<ListViewEmbeddedControl>();
this.embeddedControls.Added += this.embeddedControls.ItemAdded +=
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>( new EventHandler<ItemEventArgs<ListViewEmbeddedControl>>(embeddedControlAdded);
embeddedControlAdded this.embeddedControls.ItemRemoved +=
); new EventHandler<ItemEventArgs<ListViewEmbeddedControl>>(embeddedControlRemoved);
this.embeddedControls.Clearing += new EventHandler(embeddedControlsClearing);
this.embeddedControls.Removed +=
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>(
embeddedControlRemoved
);
this.embeddedControls.Clearing +=
new EventHandler(embeddedControlsClearing);
InitializeComponent(); InitializeComponent();
@ -88,10 +83,10 @@ namespace Nuclex.Windows.Forms {
/// </param> /// </param>
private void embeddedControlAdded( private void embeddedControlAdded(
object sender, object sender,
ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs arguments ItemEventArgs<ListViewEmbeddedControl> arguments
) { ) {
arguments.EmbeddedControl.Control.Click += this.embeddedControlClickedDelegate; arguments.Item.Control.Click += this.embeddedControlClickedDelegate;
this.Controls.Add(arguments.EmbeddedControl.Control); this.Controls.Add(arguments.Item.Control);
} }
/// <summary>Called when a control gets added to the embedded controls list</summary> /// <summary>Called when a control gets added to the embedded controls list</summary>
@ -101,11 +96,11 @@ namespace Nuclex.Windows.Forms {
/// </param> /// </param>
private void embeddedControlRemoved( private void embeddedControlRemoved(
object sender, object sender,
ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs arguments ItemEventArgs<ListViewEmbeddedControl> arguments
) { ) {
if(this.Controls.Contains(arguments.EmbeddedControl.Control)) { if(this.Controls.Contains(arguments.Item.Control)) {
arguments.EmbeddedControl.Control.Click -= this.embeddedControlClickedDelegate; arguments.Item.Control.Click -= this.embeddedControlClickedDelegate;
this.Controls.Remove(arguments.EmbeddedControl.Control); this.Controls.Remove(arguments.Item.Control);
} }
} }
@ -182,7 +177,7 @@ namespace Nuclex.Windows.Forms {
/// <summary>Event handler for when embedded controls are clicked on</summary> /// <summary>Event handler for when embedded controls are clicked on</summary>
private EventHandler embeddedControlClickedDelegate; private EventHandler embeddedControlClickedDelegate;
/// <summary>Controls being embedded in this ListView</summary> /// <summary>Controls being embedded in this ListView</summary>
private ListViewEmbeddedControlCollection embeddedControls; private ObservableCollection<ListViewEmbeddedControl> embeddedControls;
} }

View File

@ -1,133 +0,0 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Nuclex.Windows.Forms {
/// <summary>Collection of controls embedded in a ListView</summary>
public class ListViewEmbeddedControlCollection : Collection<ListViewEmbeddedControl> {
#region class ListViewEmbeddedControlEventArgs
/// <summary>Arguments class for events that need to pass a control</summary>
public class ListViewEmbeddedControlEventArgs : EventArgs {
/// <summary>Initializes a new event arguments supplier</summary>
/// <param name="embeddedControl">Control to be supplied to the event handler</param>
public ListViewEmbeddedControlEventArgs(ListViewEmbeddedControl embeddedControl) {
this.embeddedControl = embeddedControl;
}
/// <summary>Obtains the control the event arguments are carrying</summary>
public ListViewEmbeddedControl EmbeddedControl {
get { return this.embeddedControl; }
}
/// <summary>Control that's passed to the event handler</summary>
private ListViewEmbeddedControl embeddedControl;
}
#endregion // class ListViewEmbeddedControlEventArgs
/// <summary>Raised when a control has been added to the collection</summary>
public event EventHandler<ListViewEmbeddedControlEventArgs> Added;
/// <summary>Raised when a control is removed from the collection</summary>
public event EventHandler<ListViewEmbeddedControlEventArgs> Removed;
/// <summary>Raised when the collection is about to be cleared</summary>
public event EventHandler Clearing;
/// <summary>Removes all elements from the ListViewEmbeddedControlCollection</summary>
protected override void ClearItems() {
OnClearing();
base.ClearItems();
}
/// <summary>
/// Inserts an element into the ListViewEmbeddedControlCollection at the specified index
/// </summary>
/// <param name="index">
/// The object to insert. The value can be null for reference types
/// </param>
/// <param name="item">The zero-based index at which item should be inserted</param>
protected override void InsertItem(int index, ListViewEmbeddedControl item) {
base.InsertItem(index, item);
OnAdded(item);
}
/// <summary>
/// Removes the element at the specified index of the ListViewEmbeddedControlCollection
/// </summary>
/// <param name="index">The zero-based index of the element to remove</param>
protected override void RemoveItem(int index) {
ListViewEmbeddedControl control = base[index];
base.RemoveItem(index);
OnRemoved(control);
}
/// <summary>Replaces the element at the specified index</summary>
/// <param name="index">
/// The new value for the element at the specified index. The value can be null
/// for reference types
/// </param>
/// <param name="item">The zero-based index of the element to replace</param>
protected override void SetItem(int index, ListViewEmbeddedControl item) {
ListViewEmbeddedControl control = base[index];
base.SetItem(index, item);
OnRemoved(control);
OnAdded(item);
}
/// <summary>Fires the Added event</summary>
/// <param name="embeddedControl">
/// Embedded control that has been added to the collection
/// </param>
protected virtual void OnAdded(ListViewEmbeddedControl embeddedControl) {
if(Added != null)
Added(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
}
/// <summary>Fires the Removed event</summary>
/// <param name="embeddedControl">
/// Embedded control that has been removed from the collection
/// </param>
protected virtual void OnRemoved(ListViewEmbeddedControl embeddedControl) {
if(Removed != null)
Removed(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
}
/// <summary>Fires the Clearing event</summary>
protected virtual void OnClearing() {
if(Clearing != null)
Clearing(this, EventArgs.Empty);
}
}
} // namespace Nuclex.Windows.Forms

View File

@ -78,13 +78,15 @@ namespace Nuclex.Windows.Forms {
} }
/// <summary>Called when the user tries to close the form manually</summary> /// <summary>Called when the user tries to close the form manually</summary>
/// <param name="e">Contains a flag that can be used to abort the close attempt</param> /// <param name="arguments">
protected override void OnClosing(CancelEventArgs e) { /// Contains a flag that can be used to abort the close attempt
base.OnClosing(e); /// </param>
protected override void OnClosing(CancelEventArgs arguments) {
base.OnClosing(arguments);
// Only allow the form to close when the form is ready to close and the // Only allow the form to close when the form is ready to close and the
// transaction being tracked has also finished. // transaction being tracked has also finished.
e.Cancel = (Thread.VolatileRead(ref this.state) < 2); arguments.Cancel = (Thread.VolatileRead(ref this.state) < 2);
} }
/// <summary> /// <summary>