ShiftOS_TheReturn/ShiftOS_TheReturn/Desktop.cs

287 lines
8.8 KiB
C#
Raw Normal View History

2017-01-08 10:17:07 -05:00
/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
2017-01-08 09:57:10 -05:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2017-02-16 17:14:18 -05:00
using ShiftOS.Objects.ShiftFS;
2017-01-08 09:57:10 -05:00
using static ShiftOS.Engine.SkinEngine;
namespace ShiftOS.Engine
{
2017-04-16 09:48:33 -04:00
/// <summary>
/// Denotes that this class is launchable from the App Launcher.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
2017-01-08 09:57:10 -05:00
public class LauncherAttribute : Attribute
{
/// <summary>
/// Marks this form as a launcher item that, when clicked, will open the form.
/// </summary>
/// <param name="name">The text displayed on the launcher item</param>
/// <param name="requiresUpgrade">Whether or not an upgrade must be installed to see the launcher</param>
/// <param name="upgradeID">The ID of the upgrade - leave blank if requiresUpgrade is false.</param>
/// <param name="category">The category that the item will appear in.</param>
public LauncherAttribute(string name, bool requiresUpgrade, string upgradeID = "", string category = "Other")
2017-01-08 09:57:10 -05:00
{
Category = category;
2017-01-08 09:57:10 -05:00
Name = name;
RequiresUpgrade = requiresUpgrade;
ID = upgradeID;
}
2017-04-16 09:48:33 -04:00
/// <summary>
/// Gets or sets the name of the launcher item
/// </summary>
2017-01-08 09:57:10 -05:00
public string Name { get; set; }
2017-04-16 09:48:33 -04:00
/// <summary>
/// Gets or sets whether this entry requires a Shiftorium upgrade.
/// </summary>
2017-01-08 09:57:10 -05:00
public bool RequiresUpgrade { get; set; }
2017-04-16 09:48:33 -04:00
/// <summary>
/// Gets or sets the ID of the required upgrade.
/// </summary>
2017-01-08 09:57:10 -05:00
public string ID { get; set; }
2017-04-16 09:48:33 -04:00
/// <summary>
/// Gets or sets this item's category.
/// </summary>
public string Category { get; private set; }
2017-04-16 09:48:33 -04:00
/// <summary>
/// Gets whether or not the required upgrade is installed.
/// </summary>
2017-01-08 09:57:10 -05:00
public bool UpgradeInstalled
{
get
{
if (!RequiresUpgrade)
return true;
return Shiftorium.UpgradeInstalled(ID);
}
}
}
2017-04-16 09:48:33 -04:00
/// <summary>
/// Provides core functionality for a typical ShiftOS desktop.
/// </summary>
2017-01-08 09:57:10 -05:00
public interface IDesktop
{
2017-04-16 09:48:33 -04:00
/// <summary>
/// Gets the name of the desktop.
/// </summary>
2017-02-16 17:14:18 -05:00
string DesktopName { get; }
/// <summary>
/// Show a notification on the desktop.
/// </summary>
/// <param name="app">An application ID (for determining what system icon to show the notification alongside)</param>
/// <param name="title">The title of the notification.</param>
/// <param name="message">Isn't this.... self explanatory?</param>
void PushNotification(string app, string title, string message);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Performs most of the skinning and layout handling for the desktop.
/// </summary>
2017-01-08 09:57:10 -05:00
void SetupDesktop();
2017-04-15 20:21:11 -04:00
2017-04-16 09:48:33 -04:00
/// <summary>
/// Hides the currently-opened app launcher menu.
/// </summary>
2017-04-15 20:21:11 -04:00
void HideAppLauncher();
2017-04-16 09:48:33 -04:00
/// <summary>
/// Populates the app launcher menu.
/// </summary>
/// <param name="items">All items to be placed in the menu.</param>
2017-01-08 09:57:10 -05:00
void PopulateAppLauncher(LauncherItem[] items);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Handles desktop-specific routines for showing ShiftOS windows.
/// </summary>
/// <param name="border">The calling window.</param>
2017-01-08 09:57:10 -05:00
void ShowWindow(IWindowBorder border);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Handles desktop-specific routines for closing ShiftOS windows.
/// </summary>
/// <param name="border">The calling window.</param>
2017-01-08 09:57:10 -05:00
void KillWindow(IWindowBorder border);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Populates the panel button list with all open windows.
/// </summary>
2017-01-08 09:57:10 -05:00
void PopulatePanelButtons();
2017-04-16 09:48:33 -04:00
/// <summary>
/// Performs desktop-specific routines for minimizing a window.
/// </summary>
/// <param name="brdr">The calling window.</param>
2017-01-08 09:57:10 -05:00
void MinimizeWindow(IWindowBorder brdr);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Performs desktop-specific routines for maximizing a window.
/// </summary>
/// <param name="brdr">The calling window.</param>
2017-01-08 09:57:10 -05:00
void MaximizeWindow(IWindowBorder brdr);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Performs desktop-specific routines for restoring a window to its default state.
/// </summary>
/// <param name="brdr">The calling window.</param>
2017-01-08 09:57:10 -05:00
void RestoreWindow(IWindowBorder brdr);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Invokes an action on the UI thread.
/// </summary>
/// <param name="act">The action to invoke.</param>
2017-01-08 09:57:10 -05:00
void InvokeOnWorkerThread(Action act);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Calculates the screen size of the desktop.
/// </summary>
/// <returns>The desktop's screen size.</returns>
2017-01-08 09:57:10 -05:00
Size GetSize();
2017-02-18 10:37:11 -05:00
2017-04-16 09:48:33 -04:00
/// <summary>
/// Opens the app launcher at a specific point.
/// </summary>
/// <param name="loc">Where the app launcher should be opened.</param>
2017-02-21 13:26:17 -05:00
void OpenAppLauncher(Point loc);
2017-04-16 09:48:33 -04:00
/// <summary>
/// Opens the desktop.
/// </summary>
2017-02-18 10:37:11 -05:00
void Show();
2017-04-16 09:48:33 -04:00
/// <summary>
/// Closes the desktop.
/// </summary>
2017-02-18 10:37:11 -05:00
void Close();
2017-01-08 09:57:10 -05:00
}
public static class Desktop
{
2017-04-16 09:48:33 -04:00
/// <summary>
/// The underlying desktop object.
/// </summary>
2017-01-08 09:57:10 -05:00
private static IDesktop _desktop = null;
2017-04-16 09:48:33 -04:00
public static Size Size
{
get
2017-01-08 09:57:10 -05:00
{
return _desktop.GetSize();
}
}
public static IDesktop CurrentDesktop
{
get
{
return _desktop;
}
}
2017-02-18 10:37:11 -05:00
public static void Init(IDesktop desk, bool show = false)
2017-01-08 09:57:10 -05:00
{
2017-02-18 10:37:11 -05:00
IDesktop deskToClose = null;
if (_desktop != null)
deskToClose = _desktop;
2017-01-08 09:57:10 -05:00
_desktop = desk;
2017-02-18 10:37:11 -05:00
if (show == true)
_desktop.Show();
deskToClose?.Close();
2017-01-08 09:57:10 -05:00
}
public static void MinimizeWindow(IWindowBorder brdr)
{
_desktop.MinimizeWindow(brdr);
}
public static void MaximizeWindow(IWindowBorder brdr)
{
_desktop.MaximizeWindow(brdr);
}
public static void RestoreWindow(IWindowBorder brdr)
{
_desktop.RestoreWindow(brdr);
}
2017-01-08 09:57:10 -05:00
public static void InvokeOnWorkerThread(Action act)
{
_desktop.InvokeOnWorkerThread(act);
}
public static void ResetPanelButtons()
{
_desktop.PopulatePanelButtons();
}
public static void ShowWindow(IWindowBorder brdr)
{
_desktop.ShowWindow(brdr);
}
public static void PopulateAppLauncher()
{
_desktop.PopulateAppLauncher(AppLauncherDaemon.Available().ToArray());
}
2017-02-21 13:26:17 -05:00
public static void OpenAppLauncher(Point loc)
{
_desktop.OpenAppLauncher(loc);
}
2017-04-15 20:21:11 -04:00
public static void HideAppLauncher()
{
_desktop.HideAppLauncher();
}
public static void PushNotification(string app, string title, string msg)
{
InvokeOnWorkerThread(() =>
{
_desktop.PushNotification(app, title, msg);
});
}
2017-01-08 09:57:10 -05:00
}
2017-02-24 12:23:00 -07:00
// sorry i almost killed everything :P
2017-01-08 09:57:10 -05:00
}