From a10440a45c40652b13e883aec832a0c8ded685e8 Mon Sep 17 00:00:00 2001 From: John T Date: Sun, 5 Nov 2017 18:47:46 -0500 Subject: Added a half-complete ShiftFS and did some code cleanup --- ShiftOS.Engine/WindowManager/InfoboxTemplate.cs | 162 +++++++++--------- ShiftOS.Engine/WindowManager/ShiftSkinData.cs | 39 ++--- ShiftOS.Engine/WindowManager/ShiftWM.cs | 215 ++++++++++++------------ ShiftOS.Engine/WindowManager/ShiftWindow.cs | 99 +++++------ 4 files changed, 260 insertions(+), 255 deletions(-) (limited to 'ShiftOS.Engine/WindowManager') diff --git a/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs b/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs index 948df22..c2b45e0 100644 --- a/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs +++ b/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs @@ -1,94 +1,94 @@ using System; using System.Drawing; -using System.Windows.Forms; -using System.Media; using System.IO; +using System.Media; +using System.Windows.Forms; +using ShiftOS.Engine.Properties; namespace ShiftOS.Engine.WindowManager { - public partial class InfoboxTemplate : UserControl - { - Stream _str; - private int _buttonChoice; - private int _buttonSelected; - public InfoboxTemplate(ButtonType type) - { - InitializeComponent(); - - switch (type) - { - case ButtonType.Ok: - btnOpt1.Text = "OK"; - btnOpt2.Hide(); - btnOpt1.Location = new Point(109, 134); - _buttonChoice = 1; - break; - case ButtonType.OkCancel: - btnOpt1.Text = "OK"; - btnOpt2.Text = "Cancel"; - _buttonChoice = 2; - break; - case ButtonType.YesNo: - btnOpt1.Text = "Yes"; - btnOpt2.Text = "No"; - _buttonChoice = 3; - break; - } - } + public partial class InfoboxTemplate : UserControl + { + public enum ButtonType + { + YesNo, + OkCancel, + Ok + } - public enum ButtonType - { - YesNo, - OkCancel, - Ok - } + public enum DialogResult + { + Yes, + No, + Cancel, + Ok + } - public enum DialogResult - { - Yes, - No, - Cancel, - Ok - } + int _buttonChoice; + int _buttonSelected; + Stream _str; - private void btnOpt1_Click(object sender, EventArgs e) - { - switch (btnOpt1.Text) - { - case "OK": - ParentForm?.Close(); - break; - case "Yes": - _buttonSelected = 2; - ParentForm?.Close(); - break; - } - } + public InfoboxTemplate(ButtonType type) + { + InitializeComponent(); - private void btnOpt2_Click(object sender, EventArgs e) - { - switch (btnOpt2.Text) - { - case "No": - _buttonSelected = 3; - break; - case "Cancel": - _buttonSelected = 4; - break; - } - } + switch (type) + { + case ButtonType.Ok: + btnOpt1.Text = "OK"; + btnOpt2.Hide(); + btnOpt1.Location = new Point(109, 134); + _buttonChoice = 1; + break; + case ButtonType.OkCancel: + btnOpt1.Text = "OK"; + btnOpt2.Text = "Cancel"; + _buttonChoice = 2; + break; + case ButtonType.YesNo: + btnOpt1.Text = "Yes"; + btnOpt2.Text = "No"; + _buttonChoice = 3; + break; + } + } - public void Play() - { - _str = Properties.Resources.infobox; - SoundPlayer sp = new SoundPlayer(_str); - sp.Play(); - sp.Stream.Position = 0; - } + void btnOpt1_Click(object sender, EventArgs e) + { + switch (btnOpt1.Text) + { + case "OK": + ParentForm?.Close(); + break; + case "Yes": + _buttonSelected = 2; + ParentForm?.Close(); + break; + } + } - private void InfoboxTemplate_Load(object sender, EventArgs e) - => Play(); + void btnOpt2_Click(object sender, EventArgs e) + { + switch (btnOpt2.Text) + { + case "No": + _buttonSelected = 3; + break; + case "Cancel": + _buttonSelected = 4; + break; + } + } + + public void Play() + { + _str = Resources.infobox; + var sp = new SoundPlayer(_str); + sp.Play(); + sp.Stream.Position = 0; + } - - } -} + void InfoboxTemplate_Load(object sender, EventArgs e) + => Play(); + } +} \ No newline at end of file diff --git a/ShiftOS.Engine/WindowManager/ShiftSkinData.cs b/ShiftOS.Engine/WindowManager/ShiftSkinData.cs index 9f4bf45..2c8c4c8 100644 --- a/ShiftOS.Engine/WindowManager/ShiftSkinData.cs +++ b/ShiftOS.Engine/WindowManager/ShiftSkinData.cs @@ -2,22 +2,23 @@ namespace ShiftOS.Engine.WindowManager { - public abstract class ShiftSkinData - { - // ColorData - public static Color leftTopCornerColor = Color.Empty; - public static Color titleBarColor = Color.Empty; - public static Color rightTopCornerColor = Color.Empty; - public static Color btnCloseColor = Color.Empty; - public static Color btnMaxColor = Color.Empty; - public static Color btnMinColor = Color.Empty; - public static Color btnCloseHoverColor = Color.Empty; - public static Color btnMaxHoverColor = Color.Empty; - public static Color btnMinHoverColor = Color.Empty; - public static Color leftSideColor = Color.Empty; - public static Color rightSideColor = Color.Empty; - public static Color leftBottomCornerColor = Color.Empty; - public static Color bottomSideColor = Color.Empty; - public static Color rightBottomCornerColor = Color.Empty; - } -} + public abstract class ShiftSkinData + { + // ColorData + public static Color LeftTopCornerColor = Color.Empty; + + public static Color TitleBarColor = Color.Empty; + public static Color RightTopCornerColor = Color.Empty; + public static Color BtnCloseColor = Color.Empty; + public static Color BtnMaxColor = Color.Empty; + public static Color BtnMinColor = Color.Empty; + public static Color BtnCloseHoverColor = Color.Empty; + public static Color BtnMaxHoverColor = Color.Empty; + public static Color BtnMinHoverColor = Color.Empty; + public static Color LeftSideColor = Color.Empty; + public static Color RightSideColor = Color.Empty; + public static Color LeftBottomCornerColor = Color.Empty; + public static Color BottomSideColor = Color.Empty; + public static Color RightBottomCornerColor = Color.Empty; + } +} \ No newline at end of file diff --git a/ShiftOS.Engine/WindowManager/ShiftWM.cs b/ShiftOS.Engine/WindowManager/ShiftWM.cs index 64b84f9..b6079bd 100644 --- a/ShiftOS.Engine/WindowManager/ShiftWM.cs +++ b/ShiftOS.Engine/WindowManager/ShiftWM.cs @@ -1,126 +1,129 @@ -using System; -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Windows.Forms; +using ShiftOS.Engine.Misc; +using ShiftOS.Engine.Properties; using static ShiftOS.Engine.WindowManager.InfoboxTemplate; namespace ShiftOS.Engine.WindowManager { - public static class ShiftWM - { + public static class ShiftWm + { public static ObservableCollection Windows { get; } = new ObservableCollection(); - public static ShiftWindow GetShiftWindow(this UserControl control) - { - return Windows.First(p => (uint) control.Tag == p.Id); - } - - /// - /// Shows a new ShiftWindow based on a UserControl. - /// - /// The UserControl to use - /// The program's title - /// The icon to show - /// Checks if this is an infobox - /// Enables or disables resizing - /// - public static ShiftWindow Init(UserControl content, string title, Icon icon, bool showAsInfobox = false, bool resize = true) - { - // Setup Window - ShiftWindow app = new ShiftWindow - { - Text = title, - Title = {Text = title} - }; - - app.Width = content.Width + app.leftSide.Width + app.rightSide.Width; - app.Height = content.Height + app.bottomSide.Height + app.titleBar.Height; - - if (ShiftSkinData.titleBarColor == Color.Empty) - { - Color borderColor = Color.FromArgb(64, 64, 64); - ShiftSkinData.btnCloseColor = Color.Black; - ShiftSkinData.btnMaxColor = Color.Black; - ShiftSkinData.btnMinColor = Color.Black; - ShiftSkinData.leftTopCornerColor = borderColor; - ShiftSkinData.titleBarColor = borderColor; - ShiftSkinData.rightTopCornerColor = borderColor; - ShiftSkinData.leftSideColor = borderColor; - ShiftSkinData.rightSideColor = borderColor; - ShiftSkinData.leftBottomCornerColor = borderColor; - ShiftSkinData.bottomSideColor = borderColor; - ShiftSkinData.rightBottomCornerColor = borderColor; - } - - app.btnClose.BackColor = ShiftSkinData.btnCloseColor; - app.btnMax.BackColor = ShiftSkinData.btnMaxColor; - app.btnMin.BackColor = ShiftSkinData.btnMinColor; - app.leftTopCorner.BackColor = ShiftSkinData.leftTopCornerColor; - app.titleBar.BackColor = ShiftSkinData.titleBarColor; - app.rightTopCorner.BackColor = ShiftSkinData.rightTopCornerColor; - app.leftSide.BackColor = ShiftSkinData.leftSideColor; - app.rightSide.BackColor = ShiftSkinData.rightSideColor; - app.leftBottomCorner.BackColor = ShiftSkinData.leftBottomCornerColor; - app.bottomSide.BackColor = ShiftSkinData.bottomSideColor; - app.rightBottomCorner.BackColor = ShiftSkinData.rightBottomCornerColor; - - - // Icon Setup - if (icon == null) - { - app.programIcon.Hide(); - app.programIcon.Image = Properties.Resources.nullIcon; - app.Title.Location = new Point(2, 7); - } - - else - { - app.programIcon.Image = icon.ToBitmap(); - app.Icon = icon; - } + public static ShiftWindow GetShiftWindow(this UserControl control) + { + return Windows.First(p => (uint) control.Tag == p.Id); + } + + /// + /// Shows a new ShiftWindow based on a UserControl. + /// + /// The UserControl to use + /// The program's title + /// The icon to show + /// Checks if this is an infobox + /// Enables or disables resizing + /// + public static ShiftWindow Init( + UserControl content, + string title, + Icon icon, + bool showAsInfobox = false, + bool resize = true) + { + // Setup Window + var app = new ShiftWindow + { + Text = title, + Title = { Text = title } + }; + + app.Width = content.Width + app.leftSide.Width + app.rightSide.Width; + app.Height = content.Height + app.bottomSide.Height + app.titleBar.Height; + + if (ShiftSkinData.TitleBarColor == Color.Empty) + { + var borderColor = Color.FromArgb(64, 64, 64); + ShiftSkinData.BtnCloseColor = Color.Black; + ShiftSkinData.BtnMaxColor = Color.Black; + ShiftSkinData.BtnMinColor = Color.Black; + ShiftSkinData.LeftTopCornerColor = borderColor; + ShiftSkinData.TitleBarColor = borderColor; + ShiftSkinData.RightTopCornerColor = borderColor; + ShiftSkinData.LeftSideColor = borderColor; + ShiftSkinData.RightSideColor = borderColor; + ShiftSkinData.LeftBottomCornerColor = borderColor; + ShiftSkinData.BottomSideColor = borderColor; + ShiftSkinData.RightBottomCornerColor = borderColor; + } + + app.btnClose.BackColor = ShiftSkinData.BtnCloseColor; + app.btnMax.BackColor = ShiftSkinData.BtnMaxColor; + app.btnMin.BackColor = ShiftSkinData.BtnMinColor; + app.leftTopCorner.BackColor = ShiftSkinData.LeftTopCornerColor; + app.titleBar.BackColor = ShiftSkinData.TitleBarColor; + app.rightTopCorner.BackColor = ShiftSkinData.RightTopCornerColor; + app.leftSide.BackColor = ShiftSkinData.LeftSideColor; + app.rightSide.BackColor = ShiftSkinData.RightSideColor; + app.leftBottomCorner.BackColor = ShiftSkinData.LeftBottomCornerColor; + app.bottomSide.BackColor = ShiftSkinData.BottomSideColor; + app.rightBottomCorner.BackColor = ShiftSkinData.RightBottomCornerColor; + + + // Icon Setup + if (icon == null) + { + app.programIcon.Hide(); + app.programIcon.Image = Resources.nullIcon; + app.Title.Location = new Point(2, 7); + } + + else + { + app.programIcon.Image = icon.ToBitmap(); + app.Icon = icon; + } // Setup UC content.Parent = app.programContent; - content.BringToFront(); - content.Dock = DockStyle.Fill; - app.Show(); + content.BringToFront(); + content.Dock = DockStyle.Fill; + app.Show(); - content.Tag = app.SetId(); + content.Tag = app.SetId(); Debug.WriteLine($"usercontrol: {content.Tag} window: {app.Id}"); - app.Closed += (sender, args) => - { - Windows.Remove((ShiftWindow) sender); - }; + app.Closed += (sender, args) => { Windows.Remove((ShiftWindow) sender); }; Windows.Add(app); - if (content is IShiftWindowExtensions extensions) - { - extensions.OnLoaded(app); - } - - return app; - } - - /// - /// Shows a new infobox. - /// - /// The title of the infobox. - /// The infobox's content. - /// The ButtonType used for the infobox. - /// - public static InfoboxTemplate StartInfoboxSession(string title, string body, ButtonType type) - { - InfoboxTemplate info = new InfoboxTemplate(type) - { - label1 = { Text = body } - }; - Init(info, title, Properties.Resources.iconInfoBox_fw.ToIcon(), true, false); - return info; - } - } -} + if (content is IShiftWindowExtensions extensions) + { + extensions.OnLoaded(app); + } + + return app; + } + + /// + /// Shows a new infobox. + /// + /// The title of the infobox. + /// The infobox's content. + /// The ButtonType used for the infobox. + /// + public static InfoboxTemplate StartInfoboxSession(string title, string body, ButtonType type) + { + var info = new InfoboxTemplate(type) + { + label1 = { Text = body } + }; + Init(info, title, Resources.iconInfoBox_fw.ToIcon(), true, false); + return info; + } + } +} \ No newline at end of file diff --git a/ShiftOS.Engine/WindowManager/ShiftWindow.cs b/ShiftOS.Engine/WindowManager/ShiftWindow.cs index a8b9c79..aa327f1 100644 --- a/ShiftOS.Engine/WindowManager/ShiftWindow.cs +++ b/ShiftOS.Engine/WindowManager/ShiftWindow.cs @@ -1,74 +1,76 @@ using System; -using System.Drawing; using System.Linq; -using System.Windows.Forms; using System.Runtime.InteropServices; +using System.Windows.Forms; +using ShiftOS.Engine.Misc; namespace ShiftOS.Engine.WindowManager { - public partial class ShiftWindow : Form - { - public uint Id { get; private set; } + public partial class ShiftWindow : Form + { + const int WmNclbuttondown = 0xA1; + const int HtCaption = 0x2; - public UserControl ChildControl { get; set; } + public ShiftWindow() + { + InitializeComponent(); + } - public ShiftWindow() - { - InitializeComponent(); - } + public uint Id { get; private set; } + + public UserControl ChildControl { get; set; } - public uint SetId() - { + public uint SetId() + { do { - Id = (uint)Tools.Rnd.Next(100000, 999999); - } - while (ShiftWM.Windows.FirstOrDefault(w => w.Id == Id) != null); + Id = (uint) Tools.Rnd.Next(100000, 999999); + } while (ShiftWm.Windows.FirstOrDefault(w => w.Id == Id) != null); - return Id; - } + return Id; + } - private const int WM_NCLBUTTONDOWN = 0xA1; - private const int HT_CAPTION = 0x2; + [DllImport("user32.dll")] + static extern int SendMessage( + IntPtr hWnd, + int msg, + int wParam, + int lParam); - [DllImportAttribute("user32.dll")] - private static extern int SendMessage(IntPtr hWnd, - int Msg, int wParam, int lParam); + [DllImport("user32.dll")] + static extern bool ReleaseCapture(); - [DllImportAttribute("user32.dll")] - private static extern bool ReleaseCapture(); + void Programtopbar_drag(object sender, MouseEventArgs e) + { + if (e.Button != MouseButtons.Left) return; - private void Programtopbar_drag(object sender, MouseEventArgs e) - { - if (e.Button != MouseButtons.Left) return; + ReleaseCapture(); + SendMessage(Handle, WmNclbuttondown, HtCaption, 0); + } - ReleaseCapture(); - SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); - } + void closebutton_Click(object sender, EventArgs e) + => Close(); - private void closebutton_Click(object sender, EventArgs e) - => this.Close(); + void closebutton_MouseEnter(object sender, EventArgs e) + => btnClose.BackColor = ShiftSkinData.BtnCloseHoverColor; - private void closebutton_MouseEnter(object sender, EventArgs e) - => btnClose.BackColor = ShiftSkinData.btnCloseHoverColor; + void closebutton_MouseLeave(object sender, EventArgs e) + => btnClose.BackColor = ShiftSkinData.BtnCloseColor; - private void closebutton_MouseLeave(object sender, EventArgs e) - => btnClose.BackColor = ShiftSkinData.btnCloseColor; + void maximizebutton_MouseEnter(object sender, EventArgs e) + => btnMax.BackColor = ShiftSkinData.BtnMaxHoverColor; - private void maximizebutton_MouseEnter(object sender, EventArgs e) - => btnMax.BackColor = ShiftSkinData.btnMaxHoverColor; + void maximizebutton_MouseLeave(object sender, EventArgs e) + => btnMax.BackColor = ShiftSkinData.BtnMaxColor; - private void maximizebutton_MouseLeave(object sender, EventArgs e) - => btnMax.BackColor = ShiftSkinData.btnMaxColor; + void minimizebutton_MouseEnter(object sender, EventArgs e) + => btnMin.BackColor = ShiftSkinData.BtnMinHoverColor; - private void minimizebutton_MouseEnter(object sender, EventArgs e) - => btnMin.BackColor = ShiftSkinData.btnMinHoverColor; - - private void minimizebutton_MouseLeave(object sender, EventArgs e) - => btnMin.BackColor = ShiftSkinData.btnMinColor; + void minimizebutton_MouseLeave(object sender, EventArgs e) + => btnMin.BackColor = ShiftSkinData.BtnMinColor; - /* + /* private void closebutton_MouseDown(object sender, MouseEventArgs e) => btnClose.BackColor = Color.Black; @@ -77,12 +79,11 @@ namespace ShiftOS.Engine.WindowManager private void minimizebutton_MouseDown(object sender, MouseEventArgs e) => btnMin.BackColor = Color.Black; - */ - + */ } public interface IShiftWindowExtensions { void OnLoaded(ShiftWindow window); } -} +} \ No newline at end of file -- cgit v1.2.3