2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Controls
|
|
|
|
|
{
|
|
|
|
|
public interface IEnableableComboBoxItem
|
|
|
|
|
{
|
|
|
|
|
bool Enabled { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adding Items which extend IEnableableComboBoxItem will mean that the mouse click
|
|
|
|
|
/// will be disabled on those items where the Enabled value is false
|
|
|
|
|
/// </summary>
|
2013-09-16 11:13:21 +02:00
|
|
|
|
public class EnableableComboBox : NonSelectableComboBox
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
public EnableableComboBox()
|
|
|
|
|
{
|
2016-11-14 15:34:46 +01:00
|
|
|
|
DrawMode = DrawMode.OwnerDrawFixed;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
DropDownStyle = ComboBoxStyle.DropDownList;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-27 17:57:50 +02:00
|
|
|
|
protected override void OnDrawItem(DrawItemEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
int index = e.Index;
|
|
|
|
|
|
2013-09-27 17:57:50 +02:00
|
|
|
|
if (index > -1)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-09-27 17:57:50 +02:00
|
|
|
|
e.DrawBackground();
|
|
|
|
|
|
|
|
|
|
IEnableableComboBoxItem item = Items[index] as IEnableableComboBoxItem;
|
2013-09-26 16:00:29 +02:00
|
|
|
|
Color textColor = SystemColors.ControlText;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-09-26 16:00:29 +02:00
|
|
|
|
//Paint disabled items grey - otherwise leave them black
|
|
|
|
|
if (item != null && !item.Enabled)
|
2013-09-27 17:57:50 +02:00
|
|
|
|
textColor = SystemColors.GrayText;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-09-26 16:00:29 +02:00
|
|
|
|
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
|
|
|
|
|
textColor = SystemColors.HighlightText;
|
|
|
|
|
|
2013-09-27 17:57:50 +02:00
|
|
|
|
Drawing.DrawText(e.Graphics, Items[index].ToString(), Font, e.Bounds.Location, textColor);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-09-27 17:57:50 +02:00
|
|
|
|
base.OnDrawItem(e);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new bool Enabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.Enabled;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Enabled = value;
|
|
|
|
|
BackColor = value ? SystemColors.Window : SystemColors.Control;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-16 11:13:21 +02:00
|
|
|
|
|
|
|
|
|
protected override bool IsItemNonSelectable(object o)
|
|
|
|
|
{
|
|
|
|
|
var item = o as IEnableableComboBoxItem;
|
|
|
|
|
return item != null && !item.Enabled;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|