Added focused visual style to combobox

This commit is contained in:
Patrick Simpson 2017-06-21 09:11:33 +02:00
parent 03e27943f6
commit 7b67b64e07
3 changed files with 88 additions and 39 deletions

View File

@ -208,7 +208,7 @@
<Compile Include="Config.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Controls\KAbstractComboBox.cs">
<SubType>UserControl</SubType>
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\KAnimator.cs">
<SubType>Component</SubType>
@ -224,7 +224,7 @@
</Compile>
<Compile Include="Controls\KCheckManager.cs" />
<Compile Include="Controls\KComboBox.cs">
<SubType>UserControl</SubType>
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\KCopyLabel.cs">
<SubType>Component</SubType>
@ -416,7 +416,7 @@
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UI\GABLookupControl.cs">
<SubType>UserControl</SubType>
<SubType>Component</SubType>
</Compile>
<Compile Include="UI\GABLookupControl.Designer.cs">
<DependentUpon>GABLookupControl.cs</DependentUpon>

View File

@ -1,6 +1,7 @@
using Acacia.Native;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
@ -10,8 +11,15 @@ using System.Windows.Forms;
namespace Acacia.Controls
{
public abstract class KAbstractComboBox : UserControl, IMessageFilter
public abstract class KAbstractComboBox : ContainerControl, IMessageFilter
{
#region Properties
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
override public bool AutoSize { get { return base.AutoSize; } set { base.AutoSize = value; } }
#endregion
#region Components
private KTextBox _edit;
@ -22,6 +30,7 @@ namespace Acacia.Controls
public KAbstractComboBox()
{
AutoSize = true;
SetupRenderer();
_edit = new KTextBox();
@ -262,10 +271,11 @@ namespace Acacia.Controls
_state = new KVisualStateTracker<State>(this, State.Normal, State.Disabled);
_state.Root.WithHot(State.Hot);
_state.Root.WithFocus(State.Hot);
_state.Root.WithFocus(State.Pressed);
_stateButton = _state.Root.AddPart().WithPressed(State.Pressed);
_stateButton.Clicked += Button_Clicked;
_stateButton.WithFocus(State.Hot);
// TODO if (enableVisualStyles && Application.RenderWithVisualStyles)
}
@ -273,6 +283,7 @@ namespace Acacia.Controls
protected override void OnPaint(PaintEventArgs e)
{
_style[COMBOBOXPARTS.CP_BORDER]?.DrawBackground(e.Graphics, _state.Root.State, ClientRectangle);
System.Diagnostics.Trace.WriteLine(string.Format("BUTTON: {0}", _stateButton.State));
_style[COMBOBOXPARTS.CP_DROPDOWNBUTTON]?.DrawBackground(e.Graphics, _stateButton.State, _stateButton.Rectangle);
}

View File

@ -41,28 +41,61 @@ namespace Acacia.Controls
this._parent = parent;
}
public StateTypeId State
protected enum RawStateId
{
Disabled,
Normal,
Pressed,
Hot,
Focused
}
protected RawStateId RawState
{
get
{
if (_parent != null && !_mouseOver)
{
return _parent.State;
}
return _parent.RawState;
if (!_tracker._control.Enabled)
{
return DisabledState;
}
return RawStateId.Disabled;
if (_focused && FocusedState.HasValue)
return FocusedState.Value;
if (_focused)
return RawStateId.Focused;
if (_mouseOver && _mousePressed)
return _pressedState.Value;
return RawStateId.Pressed;
if (_mouseOver && HotState.HasValue)
return HotState.Value;
if (_mouseOver)
return RawStateId.Hot;
return RawStateId.Normal;
}
}
public StateTypeId State
{
get
{
switch(RawState)
{
case RawStateId.Disabled:
return DisabledState;
case RawStateId.Focused:
if (FocusedState.HasValue)
return FocusedState.Value;
if (HotState.HasValue)
return HotState.Value;
break;
case RawStateId.Hot:
if (HotState.HasValue)
return HotState.Value;
break;
case RawStateId.Pressed:
if (_pressedState.HasValue)
return _pressedState.Value;
break;
}
return NormalState;
}
@ -157,34 +190,12 @@ namespace Acacia.Controls
}
}
private bool Focused
{
get { return _focused; }
set
{
if (_focused != value)
{
_focused = value;
Invalidate();
}
}
}
private void Invalidate()
{
_tracker.Invalidate();
}
internal void GotFocus(object sender, EventArgs e)
{
Focused = true;
}
internal void LostFocus(object sender, EventArgs e)
{
Focused = false;
}
internal void MouseDown(object sender, MouseEventArgs e)
{
if (_pressedState != null && e.Button.HasFlag(MouseButtons.Left))
@ -257,11 +268,38 @@ namespace Acacia.Controls
return this;
}
#region Focused
private bool Focused
{
get { return _focused; }
set
{
if (_focused != value)
{
_focused = value;
Invalidate();
}
}
}
internal void GotFocus(object sender, EventArgs e)
{
Focused = true;
}
internal void LostFocus(object sender, EventArgs e)
{
Focused = false;
}
public Part WithFocus(StateTypeId? focusState)
{
this._focusState = focusState;
return this;
}
#endregion
}
private readonly Control _control;