2019-02-01 20:06:36 +00:00
|
|
|
#region CPL License
|
|
|
|
/*
|
|
|
|
Nuclex Framework
|
|
|
|
Copyright (C) 2002-2019 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
|
|
|
|
|
2007-12-04 20:54:42 +00:00
|
|
|
using System;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
using Nuclex.Support.Tracking;
|
|
|
|
|
|
|
|
namespace Nuclex.Windows.Forms {
|
|
|
|
|
|
|
|
/// <summary>Tracking bar that can be hosted in a tool strip container</summary>
|
|
|
|
public class ToolStripTrackingBar : ToolStripControlHost {
|
|
|
|
|
|
|
|
/// <summary>Initializes a new tool strip tracking bar</summary>
|
|
|
|
public ToolStripTrackingBar() : base(createTrackingBar()) {
|
|
|
|
hideControlAtRuntime();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Initializes a new tool strip tracking bar with a name</summary>
|
|
|
|
/// <param name="name">Name of the tracking bar control</param>
|
|
|
|
public ToolStripTrackingBar(string name) : base(createTrackingBar(), name) {
|
|
|
|
hideControlAtRuntime();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>The tracking bar control being hosted by the tool strip host</summary>
|
|
|
|
public TrackingBar TrackingBarControl {
|
|
|
|
get { return base.Control as TrackingBar; }
|
|
|
|
}
|
|
|
|
|
2008-12-14 18:06:31 +00:00
|
|
|
/// <summary>Tracks the specified transaction in the tracking bar</summary>
|
|
|
|
/// <param name="transaction">Transaction to be tracked</param>
|
|
|
|
public void Track(Transaction transaction) {
|
|
|
|
TrackingBarControl.Track(transaction);
|
2007-12-04 20:54:42 +00:00
|
|
|
}
|
|
|
|
|
2008-12-14 18:06:31 +00:00
|
|
|
/// <summary>Tracks the specified transaction in the tracking bar</summary>
|
|
|
|
/// <param name="transaction">Transaction to be tracked</param>
|
|
|
|
/// <param name="weight">Weight of this transaction in the total progress</param>
|
|
|
|
public void Track(Transaction transaction, float weight) {
|
|
|
|
TrackingBarControl.Track(transaction, weight);
|
2007-12-04 20:54:42 +00:00
|
|
|
}
|
|
|
|
|
2008-12-14 18:06:31 +00:00
|
|
|
/// <summary>Stops tracking the specified transaction</summary>
|
|
|
|
/// <param name="transaction">Transaction to stop tracking</param>
|
|
|
|
public void Untrack(Transaction transaction) {
|
|
|
|
TrackingBarControl.Untrack(transaction);
|
2007-12-04 20:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Default size of the hosted control</summary>
|
|
|
|
protected override Size DefaultSize {
|
|
|
|
get { return new Size(100, 15); }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Default margin to leave around the control in the tool strip</summary>
|
|
|
|
protected override Padding DefaultMargin {
|
|
|
|
get {
|
2019-02-01 20:06:36 +00:00
|
|
|
if((base.Owner != null) && (base.Owner is StatusStrip)) {
|
2007-12-04 20:54:42 +00:00
|
|
|
return new Padding(1, 3, 1, 3);
|
2019-02-01 20:06:36 +00:00
|
|
|
}
|
2007-12-04 20:54:42 +00:00
|
|
|
|
|
|
|
return new Padding(1, 2, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Creates a new tracking bar</summary>
|
|
|
|
/// <returns>A new tracking bar</returns>
|
|
|
|
private static TrackingBar createTrackingBar() {
|
|
|
|
TrackingBar trackingBar = new TrackingBar();
|
|
|
|
trackingBar.Size = new Size(100, 15);
|
|
|
|
return trackingBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Hides the control during runtime usage</summary>
|
|
|
|
private void hideControlAtRuntime() {
|
|
|
|
TrackingBarControl.VisibleChanged += new EventHandler(trackingBarVisibleChanged);
|
|
|
|
|
|
|
|
LicenseUsageMode usageMode = System.ComponentModel.LicenseManager.UsageMode;
|
2019-02-01 20:06:36 +00:00
|
|
|
if(usageMode == LicenseUsageMode.Runtime) {
|
2007-12-04 20:54:42 +00:00
|
|
|
base.Visible = false;
|
2019-02-01 20:06:36 +00:00
|
|
|
}
|
2007-12-04 20:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Toggles the visibility of the tool strip host when the tracking bar control's
|
|
|
|
/// visibility changes.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">Tracking bar control whose visiblity has changed</param>
|
2008-12-14 18:06:31 +00:00
|
|
|
/// <param name="arguments">Not used</param>
|
|
|
|
private void trackingBarVisibleChanged(object sender, EventArgs arguments) {
|
2007-12-04 20:54:42 +00:00
|
|
|
base.Visible = TrackingBarControl.Visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Nuclex.Windows.Forms
|