Skip to content

Commit

Permalink
Added classes to represent a toolbar button. This is a base class tha…
Browse files Browse the repository at this point in the history
…t can be extended. The alternative to a button is a separator hence the separation.
  • Loading branch information
jamiehighfield committed May 19, 2022
1 parent cb03452 commit 7ed67c2
Show file tree
Hide file tree
Showing 3 changed files with 535 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Runtime.InteropServices;

namespace BetterControls
{
/// <summary>
/// Extend this class to create a toolbar item that is a button.
/// </summary>
partial class BetterToolbarButton
{
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns><inheritdoc/></returns>
internal override NativeMethods.TBBUTTON ComputeTbButton()
{
NativeMethods.TBBUTTON structure = base.ComputeTbButton();

structure.fsStyle |= NativeMethods.BTNS_AUTOSIZE;

if (ShowImage)
structure.iBitmap = ImageIndexer.ComputedIndex;
if (Enabled)
structure.fsState |= NativeMethods.TBSTATE_ENABLED;
if (Pressed)
structure.fsState |= NativeMethods.TBSTATE_PRESSED;

structure.iString = _stringIndex = OwnerToolbar.AddString(Text);

return structure;
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns><inheritdoc/></returns>
internal override NativeMethods.TBBUTTONINFO ComputeTbButtonInfo()
{
NativeMethods.TBBUTTONINFO structure = base.ComputeTbButtonInfo();

structure.dwMask |= NativeMethods.TBIF_IMAGE | NativeMethods.TBIF_STATE | NativeMethods.TBIF_STYLE;

if (ShowImage)
structure.iImage = ImageIndexer.ComputedIndex;
if (Enabled)
structure.fsState |= NativeMethods.TBSTATE_ENABLED;
if (Pressed)
structure.fsState |= NativeMethods.TBSTATE_PRESSED;

structure.dwMask |= NativeMethods.TBIF_TEXT;

structure.pszText = Marshal.StringToHGlobalAuto(Text);

_previousText = Text;

return structure;
}
}
}
Loading

0 comments on commit 7ed67c2

Please sign in to comment.