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

View File

@ -1,6 +1,7 @@
using Acacia.Native; using Acacia.Native;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -10,8 +11,15 @@ using System.Windows.Forms;
namespace Acacia.Controls 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 #region Components
private KTextBox _edit; private KTextBox _edit;
@ -22,6 +30,7 @@ namespace Acacia.Controls
public KAbstractComboBox() public KAbstractComboBox()
{ {
AutoSize = true;
SetupRenderer(); SetupRenderer();
_edit = new KTextBox(); _edit = new KTextBox();
@ -262,10 +271,11 @@ namespace Acacia.Controls
_state = new KVisualStateTracker<State>(this, State.Normal, State.Disabled); _state = new KVisualStateTracker<State>(this, State.Normal, State.Disabled);
_state.Root.WithHot(State.Hot); _state.Root.WithHot(State.Hot);
_state.Root.WithFocus(State.Hot); _state.Root.WithFocus(State.Pressed);
_stateButton = _state.Root.AddPart().WithPressed(State.Pressed); _stateButton = _state.Root.AddPart().WithPressed(State.Pressed);
_stateButton.Clicked += Button_Clicked; _stateButton.Clicked += Button_Clicked;
_stateButton.WithFocus(State.Hot);
// TODO if (enableVisualStyles && Application.RenderWithVisualStyles) // TODO if (enableVisualStyles && Application.RenderWithVisualStyles)
} }
@ -273,6 +283,7 @@ namespace Acacia.Controls
protected override void OnPaint(PaintEventArgs e) protected override void OnPaint(PaintEventArgs e)
{ {
_style[COMBOBOXPARTS.CP_BORDER]?.DrawBackground(e.Graphics, _state.Root.State, ClientRectangle); _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); _style[COMBOBOXPARTS.CP_DROPDOWNBUTTON]?.DrawBackground(e.Graphics, _stateButton.State, _stateButton.Rectangle);
} }

View File

@ -41,28 +41,61 @@ namespace Acacia.Controls
this._parent = parent; this._parent = parent;
} }
public StateTypeId State protected enum RawStateId
{
Disabled,
Normal,
Pressed,
Hot,
Focused
}
protected RawStateId RawState
{ {
get get
{ {
if (_parent != null && !_mouseOver) if (_parent != null && !_mouseOver)
{ return _parent.RawState;
return _parent.State;
}
if (!_tracker._control.Enabled) if (!_tracker._control.Enabled)
{ return RawStateId.Disabled;
return DisabledState;
}
if (_focused && FocusedState.HasValue) if (_focused)
return FocusedState.Value; return RawStateId.Focused;
if (_mouseOver && _mousePressed) if (_mouseOver && _mousePressed)
return _pressedState.Value; return RawStateId.Pressed;
if (_mouseOver && HotState.HasValue) if (_mouseOver)
return HotState.Value; 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; 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() private void Invalidate()
{ {
_tracker.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) internal void MouseDown(object sender, MouseEventArgs e)
{ {
if (_pressedState != null && e.Button.HasFlag(MouseButtons.Left)) if (_pressedState != null && e.Button.HasFlag(MouseButtons.Left))
@ -257,11 +268,38 @@ namespace Acacia.Controls
return this; 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) public Part WithFocus(StateTypeId? focusState)
{ {
this._focusState = focusState; this._focusState = focusState;
return this; return this;
} }
#endregion
} }
private readonly Control _control; private readonly Control _control;