mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-30 09:06:32 +13:00
Cleanup namespaces and hide icon to image conversion from XAML
This commit is contained in:
parent
384e2e1d74
commit
8001a5324a
8 changed files with 36 additions and 50 deletions
|
@ -8,10 +8,8 @@ namespace SystemTrayMenu.Business
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
@ -21,14 +19,8 @@ namespace SystemTrayMenu.Business
|
||||||
using SystemTrayMenu.Handler;
|
using SystemTrayMenu.Handler;
|
||||||
using SystemTrayMenu.Helper;
|
using SystemTrayMenu.Helper;
|
||||||
using SystemTrayMenu.Helpers;
|
using SystemTrayMenu.Helpers;
|
||||||
using SystemTrayMenu.UserInterface;
|
|
||||||
using SystemTrayMenu.Utilities;
|
using SystemTrayMenu.Utilities;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
||||||
using static SystemTrayMenu.Utilities.IconReader;
|
|
||||||
using ListView = System.Windows.Controls.ListView;
|
|
||||||
using Menu = SystemTrayMenu.UserInterface.Menu;
|
using Menu = SystemTrayMenu.UserInterface.Menu;
|
||||||
using MessageBox = System.Windows.MessageBox;
|
|
||||||
using Point = System.Drawing.Point;
|
|
||||||
|
|
||||||
internal class Menus : IDisposable
|
internal class Menus : IDisposable
|
||||||
{
|
{
|
||||||
|
@ -650,7 +642,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
rowData.RowIndex = items.Count; // Index
|
rowData.RowIndex = items.Count; // Index
|
||||||
items.Add(new(
|
items.Add(new(
|
||||||
rowData.HiddenEntry ? AddIconOverlay(rowData.Icon, Properties.Resources.White50Percentage) : rowData.Icon,
|
(rowData.HiddenEntry ? IconReader.AddIconOverlay(rowData.Icon, Properties.Resources.White50Percentage) : rowData.Icon).ToImageSource(),
|
||||||
rowData.Text,
|
rowData.Text,
|
||||||
rowData,
|
rowData,
|
||||||
rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult ? 99 : 0));
|
rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult ? 99 : 0));
|
||||||
|
@ -1200,7 +1192,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
private void AdjustMenusSizeAndLocation()
|
private void AdjustMenusSizeAndLocation()
|
||||||
{
|
{
|
||||||
Rectangle screenBounds;
|
Rect screenBounds;
|
||||||
bool isCustomLocationOutsideOfScreen = false;
|
bool isCustomLocationOutsideOfScreen = false;
|
||||||
|
|
||||||
if (Properties.Settings.Default.AppearAtMouseLocation)
|
if (Properties.Settings.Default.AppearAtMouseLocation)
|
||||||
|
@ -1209,7 +1201,7 @@ namespace SystemTrayMenu.Business
|
||||||
}
|
}
|
||||||
else if (Properties.Settings.Default.UseCustomLocation)
|
else if (Properties.Settings.Default.UseCustomLocation)
|
||||||
{
|
{
|
||||||
screenBounds = NativeMethods.Screen.FromPoint(new Point(
|
screenBounds = NativeMethods.Screen.FromPoint(new (
|
||||||
Properties.Settings.Default.CustomLocationX,
|
Properties.Settings.Default.CustomLocationX,
|
||||||
Properties.Settings.Default.CustomLocationY));
|
Properties.Settings.Default.CustomLocationY));
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ namespace SystemTrayMenu
|
||||||
|
|
||||||
public static Color DarkModeIcons { get; set; }
|
public static Color DarkModeIcons { get; set; }
|
||||||
|
|
||||||
|
// TODO: WPF: Remove by not using system drawing colors
|
||||||
public static SolidColorBrush ToSolidColorBrush(this Color color)
|
public static SolidColorBrush ToSolidColorBrush(this Color color)
|
||||||
{
|
{
|
||||||
return new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
|
return new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace SystemTrayMenu.Helper
|
||||||
using System;
|
using System;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
public class Fading : IDisposable
|
public class Fading
|
||||||
{
|
{
|
||||||
private const int Interval100FPS = 10; // 100fps=>1s/100fps=~10ms
|
private const int Interval100FPS = 10; // 100fps=>1s/100fps=~10ms
|
||||||
|
|
||||||
|
@ -46,25 +46,11 @@ namespace SystemTrayMenu.Helper
|
||||||
|
|
||||||
internal bool IsHiding => state == FadingState.Hide;
|
internal bool IsHiding => state == FadingState.Hide;
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Fade(FadingState state)
|
internal void Fade(FadingState state)
|
||||||
{
|
{
|
||||||
StartStopTimer(state);
|
StartStopTimer(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing)
|
|
||||||
{
|
|
||||||
timer.Stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartStopTimer(FadingState newState)
|
private void StartStopTimer(FadingState newState)
|
||||||
{
|
{
|
||||||
if (newState == FadingState.Idle)
|
if (newState == FadingState.Idle)
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
namespace SystemTrayMenu.Helper
|
namespace SystemTrayMenu.Helper
|
||||||
{
|
{
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ namespace SystemTrayMenu.DllImports
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// wraps the methodcalls to native windows dll's.
|
/// wraps the methodcalls to native windows dll's.
|
||||||
|
@ -23,9 +23,9 @@ namespace SystemTrayMenu.DllImports
|
||||||
{
|
{
|
||||||
private static Point LastCursorPosition = new Point(0, 0);
|
private static Point LastCursorPosition = new Point(0, 0);
|
||||||
|
|
||||||
private static List<Rectangle>? screens;
|
private static List<Rect>? screens;
|
||||||
|
|
||||||
public static List<Rectangle> Screens
|
public static List<Rect> Screens
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ namespace SystemTrayMenu.DllImports
|
||||||
{
|
{
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
new Rectangle(0, 0, 800, 600),
|
new (0, 0, 800, 600),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ namespace SystemTrayMenu.DllImports
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Rectangle PrimaryScreen => Screens[0];
|
public static Rect PrimaryScreen => Screens[0];
|
||||||
|
|
||||||
public static Point CursorPosition
|
public static Point CursorPosition
|
||||||
{
|
{
|
||||||
|
@ -62,9 +62,9 @@ namespace SystemTrayMenu.DllImports
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Rectangle FromPoint(Point pt)
|
public static Rect FromPoint(Point pt)
|
||||||
{
|
{
|
||||||
foreach (Rectangle screen in Screens)
|
foreach (Rect screen in Screens)
|
||||||
{
|
{
|
||||||
if (screen.Contains(pt))
|
if (screen.Contains(pt))
|
||||||
{
|
{
|
||||||
|
|
|
@ -144,7 +144,7 @@
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal" Height="{DynamicResource RowHeight}">
|
<StackPanel Orientation="Horizontal" Height="{DynamicResource RowHeight}">
|
||||||
<Image Width="{DynamicResource ColumnIconWidth}" Margin="0,2,0,3" Source="{Binding ColumnIcon, Converter={utils:IconToImageSourceConverter}}" />
|
<Image Width="{DynamicResource ColumnIconWidth}" Margin="0,2,0,3" Source="{Binding ColumnIcon}" />
|
||||||
<Label Width="{DynamicResource ColumnTextWidth}" Margin="3,0" Padding="0" VerticalContentAlignment="Center">
|
<Label Width="{DynamicResource ColumnTextWidth}" Margin="3,0" Padding="0" VerticalContentAlignment="Center">
|
||||||
<TextBlock TextTrimming="CharacterEllipsis" Text="{Binding ColumnText}"/>
|
<TextBlock TextTrimming="CharacterEllipsis" Text="{Binding ColumnText}"/>
|
||||||
</Label>
|
</Label>
|
||||||
|
|
|
@ -8,7 +8,6 @@ namespace SystemTrayMenu.UserInterface
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
@ -21,8 +20,6 @@ namespace SystemTrayMenu.UserInterface
|
||||||
using SystemTrayMenu.DllImports;
|
using SystemTrayMenu.DllImports;
|
||||||
using SystemTrayMenu.Helper;
|
using SystemTrayMenu.Helper;
|
||||||
using SystemTrayMenu.Utilities;
|
using SystemTrayMenu.Utilities;
|
||||||
using Color = System.Drawing.Color;
|
|
||||||
using Point = System.Drawing.Point;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logic of Menu window.
|
/// Logic of Menu window.
|
||||||
|
@ -51,6 +48,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
timerUpdateIcons.Tick += TimerUpdateIcons_Tick;
|
timerUpdateIcons.Tick += TimerUpdateIcons_Tick;
|
||||||
Closed += (_, _) =>
|
Closed += (_, _) =>
|
||||||
{
|
{
|
||||||
|
fading.Fade(Fading.FadingState.Idle);
|
||||||
timerUpdateIcons.Stop();
|
timerUpdateIcons.Stop();
|
||||||
isClosed = true; // TODO WPF Replace Forms wrapper
|
isClosed = true; // TODO WPF Replace Forms wrapper
|
||||||
};
|
};
|
||||||
|
@ -147,14 +145,14 @@ namespace SystemTrayMenu.UserInterface
|
||||||
customScrollbar.Name = "customScrollbar";
|
customScrollbar.Name = "customScrollbar";
|
||||||
customScrollbar.Size = new Size(Scaling.Scale(15), 40);
|
customScrollbar.Size = new Size(Scaling.Scale(15), 40);
|
||||||
#endif
|
#endif
|
||||||
SolidColorBrush foreColor = Color.Black.ToSolidColorBrush();
|
SolidColorBrush foreColor = new(Colors.Black);
|
||||||
SolidColorBrush backColor = AppColors.Background.ToSolidColorBrush();
|
SolidColorBrush backColor = AppColors.Background.ToSolidColorBrush();
|
||||||
SolidColorBrush backColorSearch = AppColors.SearchField.ToSolidColorBrush();
|
SolidColorBrush backColorSearch = AppColors.SearchField.ToSolidColorBrush();
|
||||||
SolidColorBrush backgroundBorder = AppColors.BackgroundBorder.ToSolidColorBrush();
|
SolidColorBrush backgroundBorder = AppColors.BackgroundBorder.ToSolidColorBrush();
|
||||||
|
|
||||||
if (Config.IsDarkMode())
|
if (Config.IsDarkMode())
|
||||||
{
|
{
|
||||||
foreColor = Color.White.ToSolidColorBrush();
|
foreColor = new (Colors.White);
|
||||||
backColor = AppColors.DarkModeBackground.ToSolidColorBrush();
|
backColor = AppColors.DarkModeBackground.ToSolidColorBrush();
|
||||||
backColorSearch = AppColors.DarkModeSearchField.ToSolidColorBrush();
|
backColorSearch = AppColors.DarkModeSearchField.ToSolidColorBrush();
|
||||||
backgroundBorder = AppColors.DarkModeBackgroundBorder.ToSolidColorBrush();
|
backgroundBorder = AppColors.DarkModeBackgroundBorder.ToSolidColorBrush();
|
||||||
|
@ -436,8 +434,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
buttonOpenFolder.Visibility = Visibility.Collapsed;
|
buttonOpenFolder.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
// Todo: use embedded resources that we can assign image in XAML already
|
// Todo: use embedded resources that we can assign image in XAML already
|
||||||
pictureBoxLoading.Source = (ImageSource)new IconToImageSourceConverter().Convert(
|
pictureBoxLoading.Source = SystemTrayMenu.Resources.StaticResources.LoadingIcon.ToImageSource();
|
||||||
SystemTrayMenu.Resources.StaticResources.LoadingIcon, typeof(ImageSource), null, CultureInfo.InvariantCulture);
|
|
||||||
pictureBoxLoading.Visibility = Visibility.Visible;
|
pictureBoxLoading.Visibility = Visibility.Visible;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -571,7 +568,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
/// <param name="startLocation">Defines where the first menu is drawn (when no predecessor is set).</param>
|
/// <param name="startLocation">Defines where the first menu is drawn (when no predecessor is set).</param>
|
||||||
/// <param name="isCustomLocationOutsideOfScreen">isCustomLocationOutsideOfScreen.</param>
|
/// <param name="isCustomLocationOutsideOfScreen">isCustomLocationOutsideOfScreen.</param>
|
||||||
internal void AdjustSizeAndLocation(
|
internal void AdjustSizeAndLocation(
|
||||||
Rectangle bounds,
|
Rect bounds,
|
||||||
Menu menuPredecessor,
|
Menu menuPredecessor,
|
||||||
StartLocation startLocation,
|
StartLocation startLocation,
|
||||||
bool isCustomLocationOutsideOfScreen)
|
bool isCustomLocationOutsideOfScreen)
|
||||||
|
@ -1282,7 +1279,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
if (rowData.IconLoading)
|
if (rowData.IconLoading)
|
||||||
{
|
{
|
||||||
iconsToUpdate++;
|
iconsToUpdate++;
|
||||||
row.ColumnIcon = rowData.ReadIcon(false);
|
row.ColumnIcon = rowData.ReadIcon(false).ToImageSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,7 +1366,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class ListViewItemData
|
internal class ListViewItemData
|
||||||
{
|
{
|
||||||
public ListViewItemData(Icon columnIcon, string columnText, RowData rowData, int sortIndex)
|
public ListViewItemData(ImageSource columnIcon, string columnText, RowData rowData, int sortIndex)
|
||||||
{
|
{
|
||||||
ColumnIcon = columnIcon;
|
ColumnIcon = columnIcon;
|
||||||
ColumnText = columnText;
|
ColumnText = columnText;
|
||||||
|
@ -1377,7 +1374,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
SortIndex = sortIndex;
|
SortIndex = sortIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Icon ColumnIcon { get; set; }
|
public ImageSource ColumnIcon { get; set; }
|
||||||
|
|
||||||
public string ColumnText { get; set; }
|
public string ColumnText { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,12 @@
|
||||||
|
|
||||||
namespace SystemTrayMenu.Utilities
|
namespace SystemTrayMenu.Utilities
|
||||||
{
|
{
|
||||||
using System;
|
using System.Drawing;
|
||||||
|
using System.Globalization;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using Point = System.Windows.Point;
|
||||||
|
|
||||||
internal static class WPFExtensions
|
internal static class WPFExtensions
|
||||||
{
|
{
|
||||||
|
@ -58,8 +60,17 @@ namespace SystemTrayMenu.Utilities
|
||||||
|
|
||||||
internal static Point GetRelativeChildPositionTo(this Visual parent, Visual child)
|
internal static Point GetRelativeChildPositionTo(this Visual parent, Visual child)
|
||||||
{
|
{
|
||||||
var pt = child.TransformToAncestor(parent).Transform(new(0, 0));
|
return child.TransformToAncestor(parent).Transform(new(0, 0));
|
||||||
return new (pt.X, pt.Y);
|
}
|
||||||
|
|
||||||
|
// TODO: Find and remove any unnecessary convertions
|
||||||
|
internal static ImageSource ToImageSource(this Icon icon)
|
||||||
|
{
|
||||||
|
return (ImageSource)new IconToImageSourceConverter().Convert(
|
||||||
|
icon,
|
||||||
|
typeof(ImageSource),
|
||||||
|
null,
|
||||||
|
CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue