Fix scaling of categories dropdown and options dialog (#450)

* Scale height of category checkbox list

* Fix bitmap layout

* Clean up code
This commit is contained in:
David Gardiner 2017-03-12 17:37:12 +10:30 committed by Jon Galloway
parent 9a53062fc9
commit 7f4d51d204
2 changed files with 41 additions and 116 deletions

View File

@ -4,6 +4,7 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Windows.Forms;
using OpenLiveWriter.CoreServices;
using OpenLiveWriter.CoreServices.UI;
@ -128,13 +129,13 @@ namespace OpenLiveWriter.Controls
/// A value which indicates how the BitmapButton should automcatically determine its
/// width.
/// </summary>
private bool autoSizeWidth = false;
private bool autoSizeWidth;
/// <summary>
/// A value which indicates how the BitmapButton should automcatically determine its
/// height.
/// </summary>
private bool autoSizeHeight = false;
private bool autoSizeHeight;
/// <summary>
/// A value which how the button is drawn by the control.
@ -146,26 +147,11 @@ namespace OpenLiveWriter.Controls
/// </summary>
private bool clickSetsFocus;
/// <summary>
/// The button bitmap for the disabled state.
/// </summary>
private Bitmap bitmapDisabled;
/// <summary>
/// The button bitmap for the enabled state.
/// </summary>
private Bitmap bitmapEnabled;
/// <summary>
/// The bitmap for the selected state.
/// </summary>
private Bitmap bitmapSelected;
/// <summary>
/// The bitmap for the pushed state.
/// </summary>
private Bitmap bitmapPushed;
/// <summary>
/// The text alignment for the button.
/// </summary>
@ -194,36 +180,31 @@ namespace OpenLiveWriter.Controls
/// <summary>
/// A value indicating whether the button is latched.
/// </summary>
private bool latched = false;
private bool latched;
/// <summary>
/// A value indicating whether a key press has pushed the button.
/// </summary>
private bool pushedByKeystroke = false;
private bool pushedByKeystroke;
/// <summary>
/// A value indicating whether the mouse is inside the control.
/// </summary>
private bool mouseInside = false;
private bool mouseInside;
/// <summary>
/// A value indicating whether the left mouse button is down.
/// </summary>
private bool leftMouseDown = false;
private bool leftMouseDown;
/// <summary>
/// A value indicating whether the right mouse button is down.
/// </summary>
private bool rightMouseDown = false;
private bool rightMouseDown;
/// <summary>
/// A value indicating whether focus is being shown.
/// </summary>
private bool showFocus = true;
private bool useVirtualTransparency;
private bool useVirtualTransparency = false;
private bool allowMirroring = false;
private bool allowMirroring;
#endregion Private Member Variables & Declarations
@ -244,9 +225,7 @@ namespace OpenLiveWriter.Controls
/// <param name="container"></param>
public BitmapButton(IContainer container)
{
/// <summary>
/// Required for Windows.Forms Class Composition Designer support
/// </summary>
// Required for Windows.Forms Class Composition Designer support
container.Add(this);
InitializeComponent();
@ -259,9 +238,7 @@ namespace OpenLiveWriter.Controls
/// </summary>
public BitmapButton()
{
/// <summary>
/// Required for Windows.Forms Class Composition Designer support
/// </summary>
// Required for Windows.Forms Class Composition Designer support
InitializeComponent();
// Do common initialization.
@ -294,10 +271,7 @@ namespace OpenLiveWriter.Controls
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
components?.Dispose();
}
base.Dispose(disposing);
}
@ -412,18 +386,7 @@ namespace OpenLiveWriter.Controls
DefaultValue(null),
Description("Specifies the button bitmap for the disabled state.")
]
public Bitmap BitmapDisabled
{
get
{
return bitmapDisabled;
}
set
{
bitmapDisabled = value;
}
}
public Bitmap BitmapDisabled { get; set; }
/// <summary>
/// Gets or sets the bitmap for the enabled state.
@ -456,18 +419,7 @@ namespace OpenLiveWriter.Controls
DefaultValue(null),
Description("Specifies the bitmap for the selected state.")
]
public Bitmap BitmapSelected
{
get
{
return bitmapSelected;
}
set
{
bitmapSelected = value;
}
}
public Bitmap BitmapSelected { get; set; }
/// <summary>
/// Gets or sets the bitmap for the pushed state.
@ -478,18 +430,8 @@ namespace OpenLiveWriter.Controls
DefaultValue(null),
Description("Specifies the bitmap for the pushed state. Used only when ButtonStyle.Bitmap is specified.")
]
public Bitmap BitmapPushed
{
get
{
return bitmapPushed;
}
set
{
bitmapPushed = value;
}
}
public Bitmap BitmapPushed { get; set; }
/// <summary>
/// Gets or sets the text alignment for the button.
@ -555,9 +497,7 @@ namespace OpenLiveWriter.Controls
{
get
{
if (toolTip == null)
return null;
return toolTip.GetToolTip(this);
return toolTip?.GetToolTip(this);
}
set
@ -567,7 +507,7 @@ namespace OpenLiveWriter.Controls
// we need to instantiate this tooltip lazily because it
// causes memory leaks if the form it lives on is not collected,
// which is the case for the property shelf.
toolTip = new ToolTip2(this.components);
toolTip = new ToolTip2(components);
}
toolTip.SetToolTip(this, value);
@ -673,7 +613,6 @@ namespace OpenLiveWriter.Controls
// Track whether focus is being shown.
if (e.ChangeFocus)
{
showFocus = e.ShowFocus;
Invalidate();
}
@ -971,7 +910,8 @@ namespace OpenLiveWriter.Controls
// drawBitmapRectangle.Offset(ScaleX(PUSHED_OFFSET), ScaleY(PUSHED_OFFSET));
// Draw the bitmap.
g.DrawImage(AllowMirroring, buttonBitmap, new Rectangle(ScaleX(drawBitmapRectangle.X), ScaleY(drawBitmapRectangle.Y), ScaleX(buttonBitmap.Width), ScaleY(buttonBitmap.Height)));
var destRect = new Rectangle(drawBitmapRectangle.X, drawBitmapRectangle.Y, ScaleX(buttonBitmap.Width), ScaleY(buttonBitmap.Height));
g.DrawImage(AllowMirroring, buttonBitmap, destRect);
}
// If focus is being shown, and we're focused, draw the focus rectangle.
@ -1030,7 +970,7 @@ namespace OpenLiveWriter.Controls
/// <param name="msg">A Message, passed by reference, that represents the window message to process.</param>
/// <param name="keyData">One of the Keys values that represents the key to process.</param>
/// <returns>true if the character was processed by the control; otherwise, false.</returns>
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
Keys key = keyData & ~(Keys.Control | Keys.Shift);
@ -1039,10 +979,7 @@ namespace OpenLiveWriter.Controls
PushByKeystroke();
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected virtual bool IsPushKey(Keys key)

View File

@ -4,27 +4,22 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using OpenLiveWriter.CoreServices;
using OpenLiveWriter.Extensibility.BlogClient;
using OpenLiveWriter.HtmlParser.Parser;
using OpenLiveWriter.Interop.Windows;
using OpenLiveWriter.Localization;
namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
{
internal partial class TreeCategorySelector : UserControl, ICategorySelector
{
private readonly CategoryContext ctx;
private TreeNode[] nodes = new TreeNode[0];
private string lastQuery = "";
private bool initMode = false;
private readonly CategoryContext _ctx;
private string _lastQuery = "";
private bool _initMode;
internal class DoubleClicklessTreeView : TreeView
{
@ -52,7 +47,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
public TreeCategorySelector(CategoryContext ctx)
{
this.ctx = ctx;
_ctx = ctx;
InitializeComponent();
// TODO: Whoops, missed UI Freeze... add this later
@ -71,6 +66,8 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
treeView.BeforeCollapse += delegate (object sender, TreeViewCancelEventArgs e) { e.Cancel = true; };
treeView.AfterCheck += treeView1_AfterCheck;
treeView.ItemHeight = (int) DisplayHelper.ScaleY(treeView.ItemHeight);
treeView.LostFocus += delegate { treeView.Invalidate(); };
}
@ -101,10 +98,10 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
if (initMode)
if (_initMode)
return;
List<BlogPostCategory> categories = new List<BlogPostCategory>(ctx.SelectedCategories);
List<BlogPostCategory> categories = new List<BlogPostCategory>(_ctx.SelectedCategories);
TreeNode realTreeNode = (TreeNode)e.Node.Tag;
realTreeNode.Checked = e.Node.Checked;
BlogPostCategory category = (BlogPostCategory)(realTreeNode.Tag);
@ -117,7 +114,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
}
else
categories.Remove(category);
ctx.SelectedCategories = categories.ToArray();
_ctx.SelectedCategories = categories.ToArray();
}
public static TreeNode[] CategoriesToNodes(BlogPostCategory[] categories)
@ -154,13 +151,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
return (TreeNode[])ArrayHelper.Compact(allNodes);
}
private TreeNode[] RealNodes
{
get
{
return nodes;
}
}
private TreeNode[] RealNodes { get; set; } = new TreeNode[0];
private static TreeNode[] FilteredNodes(IEnumerable nodes, Predicate<TreeNode> predicate)
{
@ -181,8 +172,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
if (results == null)
return new TreeNode[0];
else
return results.ToArray();
return results.ToArray();
}
private TreeNode FindFirstMatch(TreeNodeCollection nodes, Predicate<TreeNode> predicate)
@ -224,14 +214,14 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
public void LoadCategories()
{
initMode = true;
_initMode = true;
try
{
nodes = CategoriesToNodes(ctx.Categories);
RealNodes = CategoriesToNodes(_ctx.Categories);
treeView.Nodes.Clear();
treeView.Nodes.AddRange(FilteredNodes(RealNodes, delegate { return true; }));
HashSet selectedCategories = new HashSet();
selectedCategories.AddAll(ctx.SelectedCategories);
selectedCategories.AddAll(_ctx.SelectedCategories);
if (selectedCategories.Count > 0)
WalkNodes(treeView.Nodes, delegate (TreeNode n)
{
@ -241,7 +231,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
}
finally
{
initMode = false;
_initMode = false;
}
}
@ -255,7 +245,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
return node.Text.ToLower(CultureInfo.CurrentCulture).IndexOf(criteria, StringComparison.CurrentCultureIgnoreCase) >= 0;
};
if (criteria.Length > 0 && criteria.StartsWith(lastQuery))
if (criteria.Length > 0 && criteria.StartsWith(_lastQuery))
{
KeepNodes(treeView.Nodes, prefixPredicate);
}
@ -292,7 +282,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
treeView.EndUpdate();
}
lastQuery = criteria;
_lastQuery = criteria;
}
@ -327,8 +317,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
treeView.SelectedNode = nextNode;
}
if (treeView.SelectedNode != null)
treeView.SelectedNode.EnsureVisible();
treeView.SelectedNode?.EnsureVisible();
treeView.Focus();
}
@ -350,8 +339,7 @@ namespace OpenLiveWriter.PostEditor.PostPropertyEditing.CategoryControl
treeView.SelectedNode = nextNode;
}
if (treeView.SelectedNode != null)
treeView.SelectedNode.EnsureVisible();
treeView.SelectedNode?.EnsureVisible();
treeView.Focus();
}