Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
More Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Jan 2, 2022
1 parent 85b1f6b commit 1ab9230
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 66 deletions.
14 changes: 8 additions & 6 deletions DrasticMaui/DrasticSplitViewWindow.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

using DrasticMaui.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DrasticMaui.Tools;

namespace DrasticMaui
{
/// <summary>
/// Drastic Split View Window.
/// </summary>
public partial class DrasticSplitViewWindow
{
private Microsoft.UI.Xaml.Controls.SplitView? splitView;

/// <summary>
/// Setup Split View Window.
/// </summary>
public void SetupSplitView()
{
if (this.Page == null)
Expand Down Expand Up @@ -44,16 +50,12 @@ public void SetupSplitView()
this.splitView.DisplayMode = Microsoft.UI.Xaml.Controls.SplitViewDisplayMode.Inline;
this.splitView.Content = this.Page.GetNative(true);

// TODO: Keep existing overlays.
panel.Children.Clear();
panel.Children.Add(this.splitView);

window.ExtendsContentIntoTitleBar = false;
this.splitView.IsPaneOpen = true;
}
}

public class TestPanel : Microsoft.UI.Xaml.Controls.Panel
{

}
}
28 changes: 19 additions & 9 deletions DrasticMaui/DrasticSplitViewWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ public partial class DrasticSplitViewWindow : DrasticMauiWindow
private Page menu;
private bool isInitialized;

/// <summary>
/// Initializes a new instance of the <see cref="DrasticSplitViewWindow"/> class.
/// </summary>
/// <param name="menu">Pane Content.</param>
/// <param name="content">Main Content.</param>
public DrasticSplitViewWindow(Page menu, Page content)
{
this.Page = content;
this.menu = menu;
}

protected override void OnHandlerChanged()
#if !__MACCATALYST__ && !__IOS__ && !WINDOWS
/// <summary>
/// Setup Split View.
/// </summary>
public void SetupSplitView()
{
base.OnHandlerChanged();
if (!this.isInitialized)
{
this.SetupSplitView();
}
}
#endif

/// <inheritdoc/>
internal override void AddVisualChildren(List<IVisualTreeElement> elements)
{
if (this.menu is not null && this.menu is IVisualTreeElement element)
Expand All @@ -37,10 +43,14 @@ internal override void AddVisualChildren(List<IVisualTreeElement> elements)
}
}

#if !__MACCATALYST__ && !__IOS__ && !WINDOWS
public void SetupSplitView()
/// <inheritdoc/>
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
if (!this.isInitialized)
{
this.SetupSplitView();
}
}
#endif
}
}
7 changes: 7 additions & 0 deletions DrasticMaui/DrasticSplitViewWindow.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public partial class DrasticSplitViewWindow
{
private UISplitViewController? splitView;

/// <summary>
/// Setup Split View.
/// </summary>
public void SetupSplitView()
{
if (this.Page == null)
Expand All @@ -35,6 +38,10 @@ public void SetupSplitView()
return;
}

// Create a split view controller.
// Take the existing content and put it into the main panel.
// Put the side panel content into the pane.

this.splitView = new UISplitViewController();
this.splitView.PrimaryBackgroundStyle = UISplitViewControllerBackgroundStyle.Sidebar;
var a = this.menu.ToUIViewController(context);
Expand Down
4 changes: 0 additions & 4 deletions DrasticMaui/DrasticTrayWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ private void Icon_LeftClicked(object? sender, EventArgs e)

#if !WINDOWS && !MACCATALYST

private void SetupWindow()
{
}

private void ShowWindow()
{
}
Expand Down
32 changes: 4 additions & 28 deletions DrasticMaui/Tray/DrasticTrayIcon.MacCatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ private void SetupStatusBarButton()

var statusBarButton = Runtime.GetNSObject(PlatformExtensions.IntPtr_objc_msgSend(this.statusBarItem.Handle, Selector.GetHandle("button")));

if (statusBarButton is not null && statusBarImage is not null)
if (statusBarButton is not null && this.statusBarImage is not null)
{
PlatformExtensions.void_objc_msgSend_IntPtr(statusBarButton.Handle, Selector.GetHandle("setImage:"), statusBarImage.Handle);
PlatformExtensions.void_objc_msgSend_IntPtr(statusBarButton.Handle, Selector.GetHandle("setImage:"), this.statusBarImage.Handle);
PlatformExtensions.void_objc_msgSend_bool(this.statusBarImage.Handle, Selector.GetHandle("setTemplate:"), true);
this.statusBarImage.Size = new CoreGraphics.CGSize(32, 32);
}
Expand Down Expand Up @@ -87,32 +87,6 @@ private void SetupStatusBarImage()
PlatformExtensions.IntPtr_objc_msgSend_IntPtr(this.statusBarImage.Handle, Selector.GetHandle("initWithData:"), imageStream.Handle);
}

private void SetupButtonFrames()
{
if (this.statusBarItem is null)
{
return;
}

var statusBarButton = Runtime.GetNSObject(PlatformExtensions.IntPtr_objc_msgSend(this.statusBarItem.Handle, Selector.GetHandle("button")));
if (statusBarButton is null)
{
return;
}

var nsButtonWindow = Runtime.GetNSObject(PlatformExtensions.IntPtr_objc_msgSend(statusBarButton.Handle, Selector.GetHandle("window")));
if (nsButtonWindow is null)
{
return;
}

var windowFrame = (NSValue)nsButtonWindow.ValueForKey(new NSString("frame"));
var buttonFrame = (NSValue)statusBarButton.ValueForKey(new NSString("frame"));

var what = windowFrame.CGRectValue;
//this.setupFrames = true;
}

[Export("handleButtonClick:")]
private void HandleClick(NSObject senderStatusBarButton)
{
Expand All @@ -126,6 +100,8 @@ private void SetupStatusBarMenu()

private void NativeElementDispose()
{
this.statusBarImage?.Dispose();
this.statusBarItem?.Dispose();
}
}
}
61 changes: 42 additions & 19 deletions DrasticMaui/Tray/DrasticTrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace DrasticMaui
{
/// <summary>
/// Drastic Tray Icon.
/// </summary>
public partial class DrasticTrayIcon : IDisposable
{
private Stream? iconStream;
Expand All @@ -16,7 +19,13 @@ public partial class DrasticTrayIcon : IDisposable
private bool holdsWindowInTray;
private bool disposedValue;

public DrasticTrayIcon(string name, Stream stream, List<DrasticTrayMenuItem>? menuItems = null)
/// <summary>
/// Initializes a new instance of the <see cref="DrasticTrayIcon"/> class.
/// </summary>
/// <param name="name">Name of the icon.</param>
/// <param name="stream">Icon Image Stream. Optional.</param>
/// <param name="menuItems">Items to populate context menu. Optional.</param>
public DrasticTrayIcon(string name, Stream? stream = null, List<DrasticTrayMenuItem>? menuItems = null)
{
this.menuItems = menuItems ?? new List<DrasticTrayMenuItem>();
this.iconName = name;
Expand All @@ -26,30 +35,32 @@ public DrasticTrayIcon(string name, Stream stream, List<DrasticTrayMenuItem>? me
this.SetupStatusBarMenu();
}

/// <summary>
/// Left Clicked Event.
/// </summary>
public event EventHandler<EventArgs>? LeftClicked;

/// <summary>
/// Right Clicked Event.
/// </summary>
public event EventHandler<EventArgs>? RightClicked;

/// <summary>
/// Menu Item Clicked.
/// </summary>
public event EventHandler<DrasticTrayMenuClickedEventArgs>? MenuClicked;

#if !__MACCATALYST__ && !WINDOWS
private void SetupStatusBarButton()
{
}

private void SetupStatusBarImage()
{
}

private void SetupStatusBarMenu()
{
}

private void NativeElementDispose()
/// <inheritdoc/>
public void Dispose()
{
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
#endif

/// <summary>
/// Dispose.
/// </summary>
/// <param name="disposing">Is Disposing.</param>
protected virtual void Dispose(bool disposing)
{
if (!this.disposedValue)
Expand All @@ -63,10 +74,22 @@ protected virtual void Dispose(bool disposing)
}
}

public void Dispose()
#if !__MACCATALYST__ && !WINDOWS
private void SetupStatusBarButton()
{
}

private void SetupStatusBarImage()
{
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}

private void SetupStatusBarMenu()
{
}

private void NativeElementDispose()
{
}
#endif
}
}

0 comments on commit 1ab9230

Please sign in to comment.