Skip to content

Commit

Permalink
Completed support for Win32 Menu and Win32 Toolbar integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehighfield committed May 24, 2022
1 parent c248e5e commit 13ee0fd
Show file tree
Hide file tree
Showing 50 changed files with 5,138 additions and 687 deletions.
45 changes: 45 additions & 0 deletions src/BetterControls/BetterMenu/BetterContextMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* COPYRIGHT NOTICE
MIT License
Copyright (c) 2022 SharpVNC Limited
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.ComponentModel;
using System.Drawing;

namespace BetterControls
{
/// <summary>
/// Represents a context menu.
/// </summary>
[ToolboxItem(true)]
[DesignTimeVisible(true)]
[ToolboxBitmap(typeof(BetterToolbar), "BetterContextMenuIcon.bmp")]
public class BetterContextMenu : BetterMenuRoot
{
/// <summary>
/// Initialize a new instance of <see cref="BetterContextMenu"/>.
/// </summary>
public BetterContextMenu() { }
}
}
93 changes: 93 additions & 0 deletions src/BetterControls/BetterMenu/BetterMenu.Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* COPYRIGHT NOTICE
MIT License
Copyright (c) 2022 SharpVNC Limited
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;

namespace BetterControls
{
/// <summary>
/// Wrapper of the Windows Menu classes.
/// </summary>
partial class BetterMenu
{
/// <summary>
/// This method is raised when <see cref="AutoSizeItems"/> has been changed.
/// </summary>
/// <param name="e">The event arguments as an instance of <see cref="EventArgs"/>.</param>
protected virtual void OnAutoSizeItemsChanged(EventArgs e)
{
if (e is null)
{
throw new ArgumentNullException(nameof(e));
}

AutoSizeItemsChanged?.Invoke(this, e);
}

/// <summary>
/// This method is raised when <see cref="CustomStatusWidth"/> has been changed.
/// </summary>
/// <param name="e">The event arguments as an instance of <see cref="EventArgs"/>.</param>
protected virtual void OnCustomStatusWidthChanged(EventArgs e)
{
if (e is null)
{
throw new ArgumentNullException(nameof(e));
}

CustomStatusWidthChanged?.Invoke(this, e);
}

/// <summary>
/// This method is raised when <see cref="DefaultButton"/> has been changed.
/// </summary>
/// <param name="e">The event arguments as an instance of <see cref="EventArgs"/>.</param>
protected virtual void OnDefaultButtonChanged(EventArgs e)
{
if (e is null)
{
throw new ArgumentNullException(nameof(e));
}

DefaultButtonChanged?.Invoke(this, e);
}

/// <summary>
/// This event is raised <see cref="AutoSizeItems"/> has been changed.
/// </summary>
public event EventHandler<EventArgs> AutoSizeItemsChanged;

/// <summary>
/// This event is raised <see cref="CustomStatusWidth"/> has been changed.
/// </summary>
public event EventHandler<EventArgs> CustomStatusWidthChanged;

/// <summary>
/// This event is raised <see cref="DefaultButton"/> has been changed.
/// </summary>
public event EventHandler<EventArgs> DefaultButtonChanged;
}
}
91 changes: 91 additions & 0 deletions src/BetterControls/BetterMenu/BetterMenu.Initialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* COPYRIGHT NOTICE
MIT License
Copyright (c) 2022 SharpVNC Limited
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;

namespace BetterControls
{
/// <summary>
/// Wrapper of the Windows Menu classes.
/// </summary>
partial class BetterMenu
{
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void CreateHandle()
{
if (!IsHandleCreated)
_handle = UnsafeNativeMethods.CreatePopupMenu();

base.CreateHandle();
}

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void DestroyHandle()
{
if (IsHandleCreated)
{
UnsafeNativeMethods.DestroyMenu(GetHandleRef());
_handle = IntPtr.Zero;

foreach (BetterMenuItem item in Items)
item.DestroyHandle();
}

base.DestroyHandle();
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="e"><inheritdoc/></param>
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);

InitializeItems();
}

/// <summary>
/// Initializes items in the menu.
/// </summary>
private void InitializeItems()
{
foreach (BetterMenuItem item in Items)
{
if (!item.Visible)
continue;

NativeMethods.MENUITEMINFO_T structure = item.ComputeMenuItemInfoT();

UnsafeNativeMethods.InsertMenuItem(GetHandleRef(), -1, true, structure);
}
}
}
}
Loading

0 comments on commit 13ee0fd

Please sign in to comment.