Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaProductions committed May 30, 2024
1 parent d388a4a commit a1d3794
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 413 deletions.
28 changes: 14 additions & 14 deletions Rectify11Installer/Controls/DarkAwareControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override CreateParams CreateParams
}
public DarkAwareTreeView()
{
Theme.OnThemeChanged += delegate
ThemeUtil.OnThemeChanged += delegate
{
UpdateTheming();
};
Expand All @@ -48,7 +48,7 @@ protected override void CreateHandle()
}
private void UpdateTheming()
{
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
SetWindowTheme(Handle, "DarkMode_Explorer", null);
ForeColor = Color.White;
Expand All @@ -66,7 +66,7 @@ public class DarkAwareLabel : Label
{
public DarkAwareLabel()
{
Theme.OnThemeChanged += delegate
ThemeUtil.OnThemeChanged += delegate
{
UpdateTheming();
};
Expand All @@ -78,7 +78,7 @@ protected override void CreateHandle()
}
private void UpdateTheming()
{
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
BackColor = Color.Black;
ForeColor = Color.White;
Expand All @@ -94,7 +94,7 @@ public class DarkAwareRichTextBox : RichTextBox
{
public DarkAwareRichTextBox()
{
Theme.OnThemeChanged += delegate
ThemeUtil.OnThemeChanged += delegate
{
UpdateTheming();
};
Expand All @@ -106,7 +106,7 @@ protected override void CreateHandle()
}
private void UpdateTheming()
{
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
BackColor = Color.Black;
ForeColor = Color.White;
Expand All @@ -123,7 +123,7 @@ public class DarkAwareTabPage : TabPage
{
public DarkAwareTabPage()
{
Theme.OnThemeChanged += delegate
ThemeUtil.OnThemeChanged += delegate
{
UpdateTheming();
};
Expand All @@ -135,7 +135,7 @@ protected override void CreateHandle()
}
private void UpdateTheming()
{
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
BackColor = Color.Black;
ForeColor = Color.White;
Expand All @@ -153,7 +153,7 @@ public class DarkAwareRadioButton : RadioButton
private static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
public DarkAwareRadioButton()
{
Theme.OnThemeChanged += delegate
ThemeUtil.OnThemeChanged += delegate
{
UpdateTheming();
};
Expand All @@ -165,7 +165,7 @@ protected override void CreateHandle()
}
private void UpdateTheming()
{
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
SetWindowTheme(Handle, "DarkMode_Explorer", null);
ForeColor = Color.White;
Expand All @@ -183,7 +183,7 @@ public class DarkAwareCheckBox : CheckBox
private static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
public DarkAwareCheckBox()
{
Theme.OnThemeChanged += delegate
ThemeUtil.OnThemeChanged += delegate
{
UpdateTheming();
};
Expand All @@ -195,7 +195,7 @@ protected override void CreateHandle()
}
private void UpdateTheming()
{
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
SetWindowTheme(Handle, "DarkMode_Explorer", null);
ForeColor = Color.White;
Expand All @@ -213,7 +213,7 @@ public class DarkAwareComboBox : ComboBox
private static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
public DarkAwareComboBox()
{
Theme.OnThemeChanged += delegate
ThemeUtil.OnThemeChanged += delegate
{
UpdateTheming();
};
Expand All @@ -225,7 +225,7 @@ protected override void CreateHandle()
}
private void UpdateTheming()
{
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
SetWindowTheme(Handle, "DarkMode_CFD", null);
ForeColor = Color.White;
Expand Down
18 changes: 9 additions & 9 deletions Rectify11Installer/Controls/FakeCommandLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Rectify11Installer.Controls
{
public sealed partial class FakeCommandLink : UserControl
{
private static Color DefaultText => Theme.IsUsingDarkMode ? Color.FromArgb(192, 192, 192) : Color.FromArgb(64, 64, 64);
private static Color DefaultText => ThemeUtil.IsUsingDarkMode ? Color.FromArgb(192, 192, 192) : Color.FromArgb(64, 64, 64);

private static Color HotText => Theme.IsUsingDarkMode ? Color.FromArgb(255, 255, 255) : Color.FromArgb(0, 0, 0);
private static Color HotText => ThemeUtil.IsUsingDarkMode ? Color.FromArgb(255, 255, 255) : Color.FromArgb(0, 0, 0);

private static Color PressedText => Theme.IsUsingDarkMode ? Color.FromArgb(160, 160, 160) : Color.FromArgb(96, 96, 96);
private static Color PressedText => ThemeUtil.IsUsingDarkMode ? Color.FromArgb(160, 160, 160) : Color.FromArgb(96, 96, 96);

public string Note
{
Expand Down Expand Up @@ -46,7 +46,7 @@ public FakeCommandLink()
this.MouseUp += TheMouseUp;
base.Click += TheMouseClick;

BackColor = Theme.IsUsingDarkMode ? Color.Black : Color.White;
BackColor = ThemeUtil.IsUsingDarkMode ? Color.Black : Color.White;

pictureBox1.BackColor = Color.Transparent;
lblTitle.BackColor = Color.Transparent;
Expand All @@ -68,9 +68,9 @@ private void SetState(ThemeParts s)
//IsDesignMode and licensing did not work for me
if (Application.ExecutablePath.Contains("DesignToolsServer.exe") ||
Application.ExecutablePath.Contains("devenv.exe")) return;
var currentTheme = Theme.IsUsingDarkMode ? Theme.DarkStyle : Theme.LightStyle;
var currentTheme = ThemeUtil.IsUsingDarkMode ? ThemeUtil.DarkStyle : ThemeUtil.LightStyle;
if (currentTheme == null) return;
var part = Theme.GetCommandLinkPart(currentTheme);
var part = ThemeUtil.GetCommandLinkPart(currentTheme);
var renderer2 = new PartRenderer(currentTheme, part);
BackgroundImage = renderer2.RenderPreview(s, Width, Height);
}
Expand All @@ -87,9 +87,9 @@ private Bitmap GetGlyphImage(ThemeParts s)
{
if (!Application.ExecutablePath.Contains("DesignToolsServer.exe") && !Application.ExecutablePath.Contains("devenv.exe"))
{
var currentTheme = Theme.IsUsingDarkMode ? Theme.DarkStyle : Theme.LightStyle;
var currentTheme = ThemeUtil.IsUsingDarkMode ? ThemeUtil.DarkStyle : ThemeUtil.LightStyle;
if (currentTheme == null) return null;
var part = Theme.GetCommandLinkGlyphPart(currentTheme);
var part = ThemeUtil.GetCommandLinkGlyphPart(currentTheme);
var renderer2 = new PartRenderer(currentTheme, part);
return renderer2.RenderPreview(s, pictureBox1.Width, pictureBox1.Height);
}
Expand All @@ -115,7 +115,7 @@ private void TheMouseUp(object sender, MouseEventArgs e)
if (!Enabled) return;
SetState(ThemeParts.Hot);
pictureBox1.Image = GetGlyphImage(ThemeParts.Hot);
var forecolor = Theme.IsUsingDarkMode ? DefaultBackColor : Color.Black;
var forecolor = ThemeUtil.IsUsingDarkMode ? DefaultBackColor : Color.Black;
lblTitle.ForeColor = forecolor;
lblBody.ForeColor = forecolor;
}
Expand Down
6 changes: 3 additions & 3 deletions Rectify11Installer/Controls/GroupBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public GroupBox()
this.Location = new Point(3, 28);
this.Size = new Size(345, 294);
this.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
this.BackColor = Theme.IsUsingDarkMode ? Color.Black : Color.White;
this.BackColor = ThemeUtil.IsUsingDarkMode ? Color.Black : Color.White;
SetState(ThemeParts.Normal);
this.MouseUp += NavigationButton_MouseUp;

Expand All @@ -46,10 +46,10 @@ private void SetState(ThemeParts c)
//IsDesignMode and licensing did not work for me
if (!Application.ExecutablePath.Contains("DesignToolsServer.exe") && !Application.ExecutablePath.Contains("devenv.exe"))
{
var currentTheme = Theme.IsUsingDarkMode ? Theme.DarkStyle : Theme.LightStyle;
var currentTheme = ThemeUtil.IsUsingDarkMode ? ThemeUtil.DarkStyle : ThemeUtil.LightStyle;
if (currentTheme != null)
{
var part = Theme.GetGroupBox(currentTheme);
var part = ThemeUtil.GetGroupBox(currentTheme);
var renderer2 = new PartRenderer(currentTheme, part);
Glyph = renderer2.RenderPreview(c, Width, Height);
}
Expand Down
4 changes: 2 additions & 2 deletions Rectify11Installer/Controls/NavButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ private void SetState(ThemeParts c)
//IsDesignMode and licensing did not work for me
if (!Application.ExecutablePath.Contains("DesignToolsServer.exe") && !Application.ExecutablePath.Contains("devenv.exe"))
{
var currentTheme = Theme.IsUsingDarkMode ? Theme.DarkStyle : Theme.LightStyle;
var currentTheme = ThemeUtil.IsUsingDarkMode ? ThemeUtil.DarkStyle : ThemeUtil.LightStyle;
if (currentTheme != null)
{
var part = Theme.GetNavArrowPart(currentTheme, t);
var part = ThemeUtil.GetNavArrowPart(currentTheme, t);
var renderer2 = new PartRenderer(currentTheme, part);
Glyph = renderer2.RenderPreview(c, Width, Height);
}
Expand Down
14 changes: 7 additions & 7 deletions Rectify11Installer/Controls/TabControlWithoutHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public TabControlWithoutHeader()
if (!this.DesignMode) this.Multiline = true;
}

protected override void WndProc(ref Message m)
{
if (m.Msg == 0x1328 && !this.DesignMode)
m.Result = new IntPtr(1);
else
base.WndProc(ref m);
}
//protected override void WndProc(ref Message m)
//{
// if (m.Msg == 0x1328 && !this.DesignMode)
// m.Result = new IntPtr(1);
// else
// base.WndProc(ref m);
//}
}
}
10 changes: 5 additions & 5 deletions Rectify11Installer/Controls/ThemedLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected override void OnPaint(PaintEventArgs e)

using (NativeMethods.SafeThemeHandle hTheme = new(NativeMethods.OpenThemeData(Handle, "Window")))
{
if (!hTheme.IsInvalid && (Application.RenderWithVisualStyles || Vanara.Interop.DesktopWindowManager.DesktopWindowManager.IsCompositionEnabled()))
if (!hTheme.IsInvalid && (Application.RenderWithVisualStyles || NativeMethods.IsCompositionEnabled()))
{
using NativeMethods.SafeDCHandle hdc = new(e.Graphics);
NativeMethods.DrawThemeParentBackground(Handle, hdc, ClientRectangle);
Expand All @@ -76,7 +76,7 @@ protected override void OnPaint(PaintEventArgs e)
{
if (ImageList != null && ImageIndex == 0)
{
if (!hTheme.IsInvalid && !IsDesignMode(this) && Vanara.Interop.DesktopWindowManager.DesktopWindowManager.IsCompositionEnabled())
if (!hTheme.IsInvalid && !IsDesignMode(this) && NativeMethods.IsCompositionEnabled())
{
VisualStyleRendererExtension.DrawWrapper(e.Graphics, r, g => NativeMethods.DrawThemeIcon(hTheme, g, 1, 1, ref rR, ImageList.Handle, ImageIndex));
}
Expand All @@ -85,7 +85,7 @@ protected override void OnPaint(PaintEventArgs e)
ImageList.Draw(e.Graphics, r.X, r.Y, r.Width, r.Height, ImageIndex);
}
}
else if (!hTheme.IsInvalid && !IsDesignMode(this) && Vanara.Interop.DesktopWindowManager.DesktopWindowManager.IsCompositionEnabled())
else if (!hTheme.IsInvalid && !IsDesignMode(this) && NativeMethods.IsCompositionEnabled())
{
VisualStyleRendererExtension.DrawWrapper(e.Graphics, r, g => Graphics.FromHdc(g.DangerousGetHandle()).DrawImage(Image, r));
}
Expand All @@ -99,9 +99,9 @@ protected override void OnPaint(PaintEventArgs e)
return;
}

if (IsDesignMode(this) || hTheme.IsInvalid || !Vanara.Interop.DesktopWindowManager.DesktopWindowManager.IsCompositionEnabled())
if (IsDesignMode(this) || hTheme.IsInvalid || !NativeMethods.IsCompositionEnabled())
{
var brush = Vanara.Interop.DesktopWindowManager.DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText;
var brush = NativeMethods.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText;
var format = new StringFormat(StringFormat.GenericDefault);
if (GetRightToLeftProperty(this) == RightToLeft.Yes)
{
Expand Down
10 changes: 5 additions & 5 deletions Rectify11Installer/Controls/WinUIButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ protected override unsafe void OnPaint(PaintEventArgs args)
Bitmap buttonImage = null;

//Hack to fix black borders, but we lose transpancy
args.Graphics.Clear(Theme.IsUsingDarkMode ? Color.White : Color.Black);
args.Graphics.Clear(ThemeUtil.IsUsingDarkMode ? Color.White : Color.Black);

var currentTheme = Theme.IsUsingDarkMode ? Theme.DarkStyle : Theme.LightStyle;
var currentTheme = ThemeUtil.IsUsingDarkMode ? ThemeUtil.DarkStyle : ThemeUtil.LightStyle;

//Update text borders
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
ForeColor = Color.White;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ protected override unsafe void OnPaint(PaintEventArgs args)
}
else
{
var part = Theme.GetButtonPart(currentTheme);
var part = ThemeUtil.GetButtonPart(currentTheme);
var renderer2 = new PartRenderer(currentTheme, part);
buttonImage = renderer2.RenderPreview(tpart, Width, Height);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ protected override unsafe void OnPaint(PaintEventArgs args)
for (var x = 0; x < buttonImage.Width; x++)
{
var pixel = buttonImage.GetPixel(x, y);
var d = Theme.IsUsingDarkMode ? Color.Black : Color.White;
var d = ThemeUtil.IsUsingDarkMode ? Color.Black : Color.White;

*pixels++ = pixel.ToArgb();
}
Expand Down
2 changes: 1 addition & 1 deletion Rectify11Installer/Core/Backend/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public bool Install(FrmWizard frm)
Logger.WriteLine("══════════════════════════════════════════════");

// some random issue where the installer's frame gets extended
if (!Theme.IsUsingDarkMode) DarkMode.UpdateFrame(frm, false);
if (!ThemeUtil.IsUsingDarkMode) DarkMode.UpdateFrame(frm, false);

// extract files, delete if folder exists
frm.InstallerProgress = "Extracting files...";
Expand Down
4 changes: 2 additions & 2 deletions Rectify11Installer/Core/Backend/Themes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public static bool Uninstall()
{
try
{
string mode = Theme.IsUsingDarkMode ? "dark.theme" : "aero.theme";
string mode = ThemeUtil.IsUsingDarkMode ? "dark.theme" : "aero.theme";
if (File.Exists(Path.Combine(Variables.Windir, "Resources", "Themes", mode)))
Helper.RunShellExec(Path.Combine(Variables.Windir, "Resources", "Themes", mode));
string theme = Theme.IsUsingDarkMode ? "Windows (dark)" : "Windows (light)";
string theme = ThemeUtil.IsUsingDarkMode ? "Windows (dark)" : "Windows (light)";
RectifyThemeUtil.Utility.ApplyTheme(theme);

UninstallThemeWallpapers();
Expand Down
6 changes: 5 additions & 1 deletion Rectify11Installer/Core/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public static bool CheckIfUpdate()
// more priority
using (RegistryKey buildkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Rectify11", false))
{
if (buildkey == null)
return false;
var build = buildkey.GetValue("Build");
if (build != null && int.Parse(build.ToString()) < Assembly.GetEntryAssembly().GetName().Version.Build)
return true;
Expand Down Expand Up @@ -154,7 +156,7 @@ public static void UpdateSideImageOptns(string name, FrmWizard _frmWizard)
{
case "shellNode":
_frmWizard.UpdateSideImage = Properties.Resources.menus;
if (Theme.IsUsingDarkMode) _frmWizard.UpdateSideImage = Properties.Resources.menusD;
if (ThemeUtil.IsUsingDarkMode) _frmWizard.UpdateSideImage = Properties.Resources.menusD;
break;
case "gadgetsNode":
_frmWizard.UpdateSideImage = Properties.Resources.gadgets;
Expand Down Expand Up @@ -423,6 +425,8 @@ public static bool IsRectify11Installed
get
{
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Rectify11");
if (key == null)
return false;
var result = (int?)key.GetValue("IsInstalled") == 1;

key.Close();
Expand Down
2 changes: 1 addition & 1 deletion Rectify11Installer/Pages/CMenuPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Rectify11Installer/Pages/CMenuPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private Controls.DarkAwareRadioButton getButton(int num)
if (rad.Checked)
{
string a = "L";
if (Theme.IsUsingDarkMode) a = "D";
if (ThemeUtil.IsUsingDarkMode) a = "D";
PrevImg.Image = (Bitmap)Properties.Resources.ResourceManager.GetObject("_" + num + a);
InstallOptions.MenuStyle = (MenuStyles)num;
}
Expand Down
2 changes: 1 addition & 1 deletion Rectify11Installer/Pages/ThemeChoicePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class ThemeChoicePage : WizardPage
public ThemeChoicePage()
{
InitializeComponent();
if (Theme.IsUsingDarkMode)
if (ThemeUtil.IsUsingDarkMode)
{
themePreview.BackgroundImage = Properties.Resources.darkPreview;
InstallOptions.ThemeLight = false;
Expand Down
Loading

0 comments on commit a1d3794

Please sign in to comment.