2013-11-06 06:58:22 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2022-01-12 05:32:17 +13:00
|
|
|
|
Copyright (c) 2007-2022 ShareX Team
|
2013-11-06 06:58:22 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib.Properties;
|
2018-11-06 12:40:05 +13:00
|
|
|
|
using System;
|
2020-07-09 19:20:06 +12:00
|
|
|
|
using System.ComponentModel;
|
2013-11-06 06:58:22 +13:00
|
|
|
|
using System.Drawing;
|
2020-07-09 20:15:43 +12:00
|
|
|
|
using System.Reflection;
|
2018-11-06 12:40:05 +13:00
|
|
|
|
using System.Windows.Forms;
|
2013-11-06 06:58:22 +13:00
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2013-11-06 06:58:22 +13:00
|
|
|
|
{
|
|
|
|
|
public static class ShareXResources
|
|
|
|
|
{
|
2021-12-11 23:16:54 +13:00
|
|
|
|
public static string Name { get; set; } = "ShareX";
|
|
|
|
|
|
2018-11-06 12:40:05 +13:00
|
|
|
|
public static string UserAgent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
Version version = Version.Parse(Application.ProductVersion);
|
2021-12-11 23:16:54 +13:00
|
|
|
|
return $"{Name}/{version.Major}.{version.Minor}.{version.Build}";
|
2018-11-06 12:40:05 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-12 09:54:42 +13:00
|
|
|
|
|
2020-02-09 04:07:17 +13:00
|
|
|
|
private static bool useCustomTheme;
|
2019-09-07 23:39:58 +12:00
|
|
|
|
|
2020-02-05 21:13:55 +13:00
|
|
|
|
public static bool UseCustomTheme
|
2019-09-07 23:39:58 +12:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-02-09 04:07:17 +13:00
|
|
|
|
return useCustomTheme && Theme != null;
|
2019-09-07 23:39:58 +12:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-02-09 04:07:17 +13:00
|
|
|
|
useCustomTheme = value;
|
2019-09-07 23:39:58 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-06 20:18:30 +12:00
|
|
|
|
|
2020-03-31 20:26:18 +13:00
|
|
|
|
public static bool IsDarkTheme => UseCustomTheme && Theme.IsDarkTheme;
|
|
|
|
|
|
2021-11-27 07:48:16 +13:00
|
|
|
|
private static bool useWhiteIcon;
|
2019-02-11 10:47:51 +13:00
|
|
|
|
|
2021-11-27 07:48:16 +13:00
|
|
|
|
public static bool UseWhiteIcon
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return useWhiteIcon;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (useWhiteIcon != value)
|
|
|
|
|
{
|
|
|
|
|
useWhiteIcon = value;
|
|
|
|
|
|
|
|
|
|
if (useWhiteIcon)
|
|
|
|
|
{
|
|
|
|
|
Icon = Resources.ShareX_Icon_White;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Icon = Resources.ShareX_Icon;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-27 08:02:18 +13:00
|
|
|
|
private static Icon icon = Resources.ShareX_Icon;
|
|
|
|
|
|
|
|
|
|
public static Icon Icon
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return icon.CloneSafe();
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (icon != value)
|
|
|
|
|
{
|
|
|
|
|
icon?.Dispose();
|
|
|
|
|
icon = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-23 22:20:22 +12:00
|
|
|
|
|
2021-11-27 08:15:24 +13:00
|
|
|
|
private static Bitmap logo = Resources.ShareX_Logo;
|
|
|
|
|
|
|
|
|
|
public static Bitmap Logo
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return logo.CloneSafe();
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (logo != value)
|
|
|
|
|
{
|
|
|
|
|
logo?.Dispose();
|
|
|
|
|
logo = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-23 23:39:17 +12:00
|
|
|
|
|
2020-12-09 18:32:46 +13:00
|
|
|
|
public static ShareXTheme Theme { get; set; } = ShareXTheme.DarkTheme;
|
2019-06-01 09:19:37 +12:00
|
|
|
|
|
2019-06-25 06:36:16 +12:00
|
|
|
|
public static void ApplyTheme(Form form, bool setIcon = true)
|
2019-06-17 19:43:13 +12:00
|
|
|
|
{
|
2019-06-25 06:17:33 +12:00
|
|
|
|
if (setIcon)
|
|
|
|
|
{
|
|
|
|
|
form.Icon = Icon;
|
|
|
|
|
}
|
2019-06-17 19:43:13 +12:00
|
|
|
|
|
2020-05-22 17:44:02 +12:00
|
|
|
|
if (UseCustomTheme)
|
2019-06-17 19:43:13 +12:00
|
|
|
|
{
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToControl(form);
|
2019-06-19 03:17:02 +12:00
|
|
|
|
|
2020-07-09 20:15:43 +12:00
|
|
|
|
IContainer components = form.GetType().GetField("components", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(form) as IContainer;
|
|
|
|
|
ApplyCustomThemeToComponents(components);
|
|
|
|
|
|
2019-06-19 08:15:53 +12:00
|
|
|
|
if (form.IsHandleCreated)
|
|
|
|
|
{
|
2020-02-05 21:23:55 +13:00
|
|
|
|
NativeMethods.UseImmersiveDarkMode(form.Handle, Theme.IsDarkTheme);
|
2019-06-19 08:15:53 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-02-05 21:23:55 +13:00
|
|
|
|
form.HandleCreated += (s, e) => NativeMethods.UseImmersiveDarkMode(form.Handle, Theme.IsDarkTheme);
|
2019-06-19 08:15:53 +12:00
|
|
|
|
}
|
2019-06-17 19:43:13 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 13:54:06 +13:00
|
|
|
|
public static void ApplyCustomThemeToControl(Control control)
|
2019-06-17 18:35:21 +12:00
|
|
|
|
{
|
2019-06-25 07:33:17 +12:00
|
|
|
|
if (control.ContextMenuStrip != null)
|
|
|
|
|
{
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToContextMenuStrip(control.ContextMenuStrip);
|
2019-06-25 07:33:17 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (control is MenuButton mb && mb.Menu != null)
|
|
|
|
|
{
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToContextMenuStrip(mb.Menu);
|
2019-06-25 07:33:17 +12:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-23 23:26:53 +12:00
|
|
|
|
switch (control)
|
2019-06-17 18:35:21 +12:00
|
|
|
|
{
|
2019-06-23 23:26:53 +12:00
|
|
|
|
case Button btn:
|
2019-06-26 04:12:34 +12:00
|
|
|
|
btn.FlatStyle = FlatStyle.Flat;
|
2019-09-06 20:18:30 +12:00
|
|
|
|
btn.FlatAppearance.BorderColor = Theme.BorderColor;
|
|
|
|
|
btn.ForeColor = Theme.TextColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
btn.BackColor = Theme.LightBackgroundColor;
|
2019-06-26 04:12:34 +12:00
|
|
|
|
return;
|
2019-06-24 03:10:51 +12:00
|
|
|
|
case CheckBox cb when cb.Appearance == Appearance.Button:
|
2019-06-26 04:29:12 +12:00
|
|
|
|
cb.FlatStyle = FlatStyle.Flat;
|
2019-09-06 20:18:30 +12:00
|
|
|
|
cb.FlatAppearance.BorderColor = Theme.BorderColor;
|
|
|
|
|
cb.ForeColor = Theme.TextColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
cb.BackColor = Theme.LightBackgroundColor;
|
2019-06-24 04:10:20 +12:00
|
|
|
|
return;
|
2019-06-25 09:49:34 +12:00
|
|
|
|
case TextBox tb:
|
2019-09-06 20:18:30 +12:00
|
|
|
|
tb.ForeColor = Theme.TextColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
tb.BackColor = Theme.LightBackgroundColor;
|
2019-06-25 09:49:34 +12:00
|
|
|
|
tb.BorderStyle = BorderStyle.FixedSingle;
|
|
|
|
|
return;
|
2019-06-26 04:29:12 +12:00
|
|
|
|
case ComboBox cb:
|
|
|
|
|
cb.FlatStyle = FlatStyle.Flat;
|
2019-09-06 20:18:30 +12:00
|
|
|
|
cb.ForeColor = Theme.TextColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
cb.BackColor = Theme.LightBackgroundColor;
|
2019-06-26 04:29:12 +12:00
|
|
|
|
return;
|
|
|
|
|
case ListBox lb:
|
2019-09-06 20:18:30 +12:00
|
|
|
|
lb.ForeColor = Theme.TextColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
lb.BackColor = Theme.LightBackgroundColor;
|
2019-06-29 10:35:34 +12:00
|
|
|
|
return;
|
2019-06-26 04:29:12 +12:00
|
|
|
|
case ListView lv:
|
2019-09-06 20:18:30 +12:00
|
|
|
|
lv.ForeColor = Theme.TextColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
lv.BackColor = Theme.LightBackgroundColor;
|
2020-02-09 04:07:17 +13:00
|
|
|
|
lv.SupportCustomTheme();
|
2019-06-26 04:29:12 +12:00
|
|
|
|
return;
|
2020-07-06 11:23:59 +12:00
|
|
|
|
case SplitContainerCustomSplitter sccs:
|
|
|
|
|
sccs.SplitterColor = Theme.BackgroundColor;
|
|
|
|
|
sccs.SplitterLineColor = Theme.BorderColor;
|
|
|
|
|
sccs.Panel1.BackColor = Theme.BackgroundColor;
|
|
|
|
|
sccs.Panel2.BackColor = Theme.BackgroundColor;
|
|
|
|
|
break;
|
2019-06-23 23:26:53 +12:00
|
|
|
|
case SplitContainer sc:
|
2019-09-06 20:18:30 +12:00
|
|
|
|
sc.Panel1.BackColor = Theme.BackgroundColor;
|
|
|
|
|
sc.Panel2.BackColor = Theme.BackgroundColor;
|
2019-06-24 04:10:20 +12:00
|
|
|
|
break;
|
2019-06-24 01:03:25 +12:00
|
|
|
|
case PropertyGrid pg:
|
2019-09-06 20:18:30 +12:00
|
|
|
|
pg.CategoryForeColor = Theme.TextColor;
|
|
|
|
|
pg.CategorySplitterColor = Theme.BackgroundColor;
|
|
|
|
|
pg.LineColor = Theme.BackgroundColor;
|
|
|
|
|
pg.SelectedItemWithFocusForeColor = Theme.BackgroundColor;
|
|
|
|
|
pg.SelectedItemWithFocusBackColor = Theme.TextColor;
|
|
|
|
|
pg.ViewForeColor = Theme.TextColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
pg.ViewBackColor = Theme.LightBackgroundColor;
|
2019-09-06 20:18:30 +12:00
|
|
|
|
pg.ViewBorderColor = Theme.BorderColor;
|
|
|
|
|
pg.HelpForeColor = Theme.TextColor;
|
|
|
|
|
pg.HelpBackColor = Theme.BackgroundColor;
|
|
|
|
|
pg.HelpBorderColor = Theme.BorderColor;
|
2019-06-25 09:49:34 +12:00
|
|
|
|
return;
|
2019-06-24 03:56:19 +12:00
|
|
|
|
case DataGridView dgv:
|
2019-09-12 04:25:11 +12:00
|
|
|
|
dgv.BackgroundColor = Theme.LightBackgroundColor;
|
2019-09-06 20:18:30 +12:00
|
|
|
|
dgv.GridColor = Theme.BorderColor;
|
2019-09-12 04:25:11 +12:00
|
|
|
|
dgv.DefaultCellStyle.BackColor = Theme.LightBackgroundColor;
|
|
|
|
|
dgv.DefaultCellStyle.SelectionBackColor = Theme.LightBackgroundColor;
|
2019-09-06 20:18:30 +12:00
|
|
|
|
dgv.DefaultCellStyle.ForeColor = Theme.TextColor;
|
|
|
|
|
dgv.DefaultCellStyle.SelectionForeColor = Theme.TextColor;
|
|
|
|
|
dgv.ColumnHeadersDefaultCellStyle.BackColor = Theme.BackgroundColor;
|
|
|
|
|
dgv.ColumnHeadersDefaultCellStyle.SelectionBackColor = Theme.BackgroundColor;
|
|
|
|
|
dgv.ColumnHeadersDefaultCellStyle.ForeColor = Theme.TextColor;
|
|
|
|
|
dgv.ColumnHeadersDefaultCellStyle.SelectionForeColor = Theme.TextColor;
|
2019-06-24 03:56:19 +12:00
|
|
|
|
dgv.EnableHeadersVisualStyles = false;
|
2019-06-24 04:10:20 +12:00
|
|
|
|
break;
|
2019-12-23 00:50:06 +13:00
|
|
|
|
case ContextMenuStrip cms:
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToContextMenuStrip(cms);
|
2019-12-23 00:50:06 +13:00
|
|
|
|
return;
|
2019-06-25 05:59:48 +12:00
|
|
|
|
case ToolStrip ts:
|
2021-08-23 15:17:35 +12:00
|
|
|
|
ts.Font = Theme.MenuFont;
|
2019-06-25 05:59:48 +12:00
|
|
|
|
ts.Renderer = new ToolStripDarkRenderer();
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToToolStripItemCollection(ts.Items);
|
2019-06-25 05:59:48 +12:00
|
|
|
|
return;
|
2019-06-24 04:10:20 +12:00
|
|
|
|
case LinkLabel ll:
|
2019-09-06 20:18:30 +12:00
|
|
|
|
ll.LinkColor = Theme.LinkColor;
|
2019-06-23 23:26:53 +12:00
|
|
|
|
break;
|
2019-06-17 19:03:56 +12:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 20:18:30 +12:00
|
|
|
|
control.ForeColor = Theme.TextColor;
|
|
|
|
|
control.BackColor = Theme.BackgroundColor;
|
2019-06-24 04:10:20 +12:00
|
|
|
|
|
2019-06-17 19:03:56 +12:00
|
|
|
|
foreach (Control child in control.Controls)
|
|
|
|
|
{
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToControl(child);
|
2019-06-17 18:35:21 +12:00
|
|
|
|
}
|
2020-11-30 13:38:48 +13:00
|
|
|
|
|
|
|
|
|
switch (control)
|
|
|
|
|
{
|
|
|
|
|
case TabToTreeView tttv:
|
|
|
|
|
tttv.LeftPanelBackColor = Theme.DarkBackgroundColor;
|
2020-11-30 14:21:53 +13:00
|
|
|
|
tttv.SeparatorColor = Theme.SeparatorDarkColor;
|
2020-11-30 13:38:48 +13:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-17 18:35:21 +12:00
|
|
|
|
}
|
2019-06-25 05:59:48 +12:00
|
|
|
|
|
2020-07-09 20:15:43 +12:00
|
|
|
|
private static void ApplyCustomThemeToComponents(IContainer container)
|
2020-07-09 19:20:06 +12:00
|
|
|
|
{
|
2020-07-09 20:15:43 +12:00
|
|
|
|
if (container != null)
|
2020-07-09 19:20:06 +12:00
|
|
|
|
{
|
2020-07-09 20:15:43 +12:00
|
|
|
|
foreach (IComponent component in container.Components)
|
2020-07-09 19:20:06 +12:00
|
|
|
|
{
|
2020-07-09 20:15:43 +12:00
|
|
|
|
switch (component)
|
|
|
|
|
{
|
|
|
|
|
case ContextMenuStrip cms:
|
|
|
|
|
ApplyCustomThemeToContextMenuStrip(cms);
|
|
|
|
|
break;
|
|
|
|
|
case ToolTip tt:
|
|
|
|
|
tt.ForeColor = Theme.TextColor;
|
|
|
|
|
tt.BackColor = Theme.BackgroundColor;
|
|
|
|
|
tt.OwnerDraw = true;
|
|
|
|
|
tt.Draw -= ToolTip_Draw;
|
|
|
|
|
tt.Draw += ToolTip_Draw;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-07-09 19:20:06 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ToolTip_Draw(object sender, DrawToolTipEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.DrawBackground();
|
|
|
|
|
e.DrawBorder();
|
2020-10-30 02:40:38 +13:00
|
|
|
|
e.DrawText(TextFormatFlags.VerticalCenter | TextFormatFlags.LeftAndRightPadding);
|
2020-07-09 19:20:06 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-09 04:07:17 +13:00
|
|
|
|
public static void ApplyCustomThemeToContextMenuStrip(ContextMenuStrip cms)
|
2019-12-23 00:50:06 +13:00
|
|
|
|
{
|
2020-07-09 20:15:43 +12:00
|
|
|
|
if (cms != null)
|
|
|
|
|
{
|
|
|
|
|
cms.Renderer = new ToolStripDarkRenderer();
|
2020-09-16 11:16:53 +12:00
|
|
|
|
cms.Font = Theme.ContextMenuFont;
|
2020-07-09 20:15:43 +12:00
|
|
|
|
cms.Opacity = Theme.ContextMenuOpacityDouble;
|
|
|
|
|
ApplyCustomThemeToToolStripItemCollection(cms.Items);
|
|
|
|
|
}
|
2019-12-23 00:50:06 +13:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-09 04:07:17 +13:00
|
|
|
|
private static void ApplyCustomThemeToToolStripItemCollection(ToolStripItemCollection collection)
|
2019-06-25 05:59:48 +12:00
|
|
|
|
{
|
|
|
|
|
foreach (ToolStripItem tsi in collection)
|
|
|
|
|
{
|
|
|
|
|
switch (tsi)
|
|
|
|
|
{
|
|
|
|
|
case ToolStripControlHost tsch:
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToControl(tsch.Control);
|
2019-06-25 05:59:48 +12:00
|
|
|
|
break;
|
|
|
|
|
case ToolStripDropDownItem tsddi:
|
2019-12-23 00:50:06 +13:00
|
|
|
|
if (tsddi.DropDown != null)
|
|
|
|
|
{
|
|
|
|
|
tsddi.DropDown.Opacity = Theme.ContextMenuOpacityDouble;
|
2020-02-09 04:07:17 +13:00
|
|
|
|
ApplyCustomThemeToToolStripItemCollection(tsddi.DropDownItems);
|
2019-12-23 00:50:06 +13:00
|
|
|
|
}
|
2019-06-25 05:59:48 +12:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-06 06:58:22 +13:00
|
|
|
|
}
|
|
|
|
|
}
|