-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to generate the native Win32 structures for each toolba…
…r item.
- Loading branch information
1 parent
917990b
commit cb03452
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/BetterControls/BetterToolbar/Items/BetterToolbarItem.NativeStructures.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace BetterControls | ||
{ | ||
/// <summary> | ||
/// Extend this class to create a toolbar item. | ||
/// </summary> | ||
partial class BetterToolbarItem | ||
{ | ||
/// <summary> | ||
/// Computes the native structure as an instance of <see cref="NativeMethods.TBBUTTON"/>. | ||
/// </summary> | ||
/// <returns>An instance of <see cref="NativeMethods.TBBUTTON"/>.</returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
internal virtual NativeMethods.TBBUTTON ComputeTbButton() | ||
{ | ||
NativeMethods.TBBUTTON structure = new NativeMethods.TBBUTTON(); | ||
|
||
if (!Visible) | ||
structure.fsState |= NativeMethods.TBSTATE_HIDDEN; | ||
|
||
structure.idCommand = UniqueIdentifier; | ||
structure.dwData = (IntPtr)0; | ||
structure.iBitmap = NativeMethods.I_IMAGENONE; | ||
structure.iString = (IntPtr)(-1); | ||
|
||
return structure; | ||
} | ||
|
||
/// <summary> | ||
/// Computes the native structure as an instance of <see cref="NativeMethods.TBBUTTONINFO"/>. | ||
/// </summary> | ||
/// <returns>An instance of <see cref="NativeMethods.TBBUTTONINFO"/>.</returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
internal virtual NativeMethods.TBBUTTONINFO ComputeTbButtonInfo() | ||
{ | ||
NativeMethods.TBBUTTONINFO structure = new NativeMethods.TBBUTTONINFO(); | ||
|
||
structure.cbSize = Marshal.SizeOf(typeof(NativeMethods.TBBUTTONINFO)); | ||
|
||
if (!Visible) | ||
structure.fsState |= NativeMethods.TBSTATE_HIDDEN; | ||
|
||
structure.idCommand = UniqueIdentifier; | ||
|
||
// Always update the width. Lots of other changes can cause issues | ||
// with the width, so updating to be sure. | ||
structure.dwMask = NativeMethods.TBIF_SIZE; | ||
structure.fsState = 0; | ||
structure.cx = (short)ComputedWidth; | ||
|
||
// Set the default image. This may be overridden by a child class. | ||
structure.iImage = NativeMethods.I_IMAGENONE; | ||
|
||
return structure; | ||
} | ||
} | ||
} |