diff options
| author | John T <[email protected]> | 2017-09-27 18:32:16 -0400 |
|---|---|---|
| committer | John T <[email protected]> | 2017-09-27 18:32:16 -0400 |
| commit | a25baf08203237fc2eeeb4b7ca720f7d47f8a666 (patch) | |
| tree | 2664b08ca0f9b57ed0a9240ab54441ece6ac2d71 /ShiftOS.Engine/WindowManager/ShiftWM.cs | |
| parent | dc7533184a88271bfd2a3aae299532ec7632144d (diff) | |
| download | shiftos-rewind-a25baf08203237fc2eeeb4b7ca720f7d47f8a666.tar.gz shiftos-rewind-a25baf08203237fc2eeeb4b7ca720f7d47f8a666.tar.bz2 shiftos-rewind-a25baf08203237fc2eeeb4b7ca720f7d47f8a666.zip | |
added desktop and some small additions and changes to shiftwm
Diffstat (limited to 'ShiftOS.Engine/WindowManager/ShiftWM.cs')
| -rw-r--r-- | ShiftOS.Engine/WindowManager/ShiftWM.cs | 82 |
1 files changed, 61 insertions, 21 deletions
diff --git a/ShiftOS.Engine/WindowManager/ShiftWM.cs b/ShiftOS.Engine/WindowManager/ShiftWM.cs index 38537c7..539d469 100644 --- a/ShiftOS.Engine/WindowManager/ShiftWM.cs +++ b/ShiftOS.Engine/WindowManager/ShiftWM.cs @@ -1,41 +1,81 @@ -using System.Drawing; +using System; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Drawing; +using System.Linq; using System.Windows.Forms; using static ShiftOS.Engine.WindowManager.InfoboxTemplate; namespace ShiftOS.Engine.WindowManager { - public class ShiftWM + public static class ShiftWM { - public ShiftWindow Init(UserControl content, string title, Image icon, bool ShowAsInfobox = false, bool resize = true) + public static ObservableCollection<ShiftWindow> Windows { get; } = new ObservableCollection<ShiftWindow>(); + + public static ShiftWindow GetShiftWindow(this UserControl control) + { + return Windows.First(p => (uint) control.Tag == p.Id); + } + + public static ShiftWindow Init(UserControl content, string title, Icon icon, bool showAsInfobox = false, bool resize = true) { // Setup Window - ShiftWindow app = new ShiftWindow(); - app.Text = title; - app.Title.Text = title; - app.Width = content.Width + app.left.Width + app.right.Width; + ShiftWindow app = new ShiftWindow + { + Text = title, + Title = {Text = title} + }; + + app.Width = content.Width + app.left.Width + app.right.Width; app.Height = content.Height + app.bottom.Height + app.top.Height; // 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; - - // Setup UC - content.Parent = app.programContent; + 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; + } + + // Setup UC + content.Parent = app.programContent; content.BringToFront(); content.Dock = DockStyle.Fill; app.Show(); + + content.Tag = app.SetId(); + + Debug.WriteLine($"usercontrol: {content.Tag} window: {app.Id}"); + + app.Closed += (sender, args) => + { + Windows.Remove((ShiftWindow) sender); + }; + + Windows.Add(app); + + if (content is IShiftWindowExtensions extensions) + { + extensions.OnLoaded(app); + } + return app; } - public InfoboxTemplate StartInfoboxSession(string title, string body, buttonType type) + + public static InfoboxTemplate StartInfoboxSession(string title, string body, ButtonType type) { - InfoboxTemplate info = new InfoboxTemplate(type); - info.label1.Text = body; - Init(info, title, Properties.Resources.iconInfoBox_fw, true, false); + InfoboxTemplate info = new InfoboxTemplate(type) + { + label1 = { Text = body } + }; + + Init(info, title, Properties.Resources.iconInfoBox_fw.ToIcon(), true, false); return info; } } |
