Skip to content

Commit

Permalink
Cleanup TTM_ constants (#2690)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughbe authored and RussKie committed Jan 13, 2020
1 parent 6212bcd commit 35c157f
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 126 deletions.
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using static Interop.User32;

internal static partial class Interop
{
internal static partial class ComCtl32
{
public enum TTM : uint
{
ACTIVATE = WM_USER + 1,
SETDELAYTIME = WM_USER + 3,
RELAYEVENT = WM_USER + 7,
GETTOOLCOUNT = WM_USER + 13,
WINDOWFROMPOINT = WM_USER + 16,
TRACKACTIVATE = WM_USER + 17,
TRACKPOSITION = WM_USER + 18,
SETTIPBKCOLOR = WM_USER + 19,
SETTIPTEXTCOLOR = WM_USER + 20,
GETDELAYTIME = WM_USER + 21,
GETTIPBKCOLOR = WM_USER + 22,
GETTIPTEXTCOLOR = WM_USER + 23,
SETMAXTIPWIDTH = WM_USER + 24,
GETMAXTIPWIDTH = WM_USER + 25,
SETMARGIN = WM_USER + 26,
GETMARGIN = WM_USER + 27,
POP = WM_USER + 28,
UPDATE = WM_USER + 29,
GETBUBBLESIZE = WM_USER + 30,
ADJUSTRECT = WM_USER + 31,
SETTITLEW = WM_USER + 33,
POPUP = WM_USER + 34,
GETTITLE = WM_USER + 35,
ADDTOOLW = WM_USER + 50,
DELTOOLW = WM_USER + 51,
NEWTOOLRECTW = WM_USER + 52,
GETTOOLINFOW = WM_USER + 53,
SETTOOLINFOW = WM_USER + 54,
HITTESTW = WM_USER + 55,
GETTEXTW = WM_USER + 56,
UPDATETIPTEXTW = WM_USER + 57,
ENUMTOOLSW = WM_USER + 58,
GETCURRENTTOOLW = WM_USER + 59,
GETWINDOWTHEME = CCM.SETWINDOWTHEME,
}
}
}
Expand Up @@ -304,33 +304,6 @@ public enum WindowMessage : uint
CBEM_SETITEMW = WM_USER + 12,
CBEM_GETITEMW = WM_USER + 13,
CBEM_SETEXTENDEDSTYLE = WM_USER + 14,
TTM_ACTIVATE = WM_USER + 1,
TTM_SETDELAYTIME = WM_USER + 3,
TTM_RELAYEVENT = WM_USER + 7,
TTM_WINDOWFROMPOINT = WM_USER + 16,
TTM_TRACKACTIVATE = WM_USER + 17,
TTM_TRACKPOSITION = WM_USER + 18,
TTM_SETTIPBKCOLOR = WM_USER + 19,
TTM_SETTIPTEXTCOLOR = WM_USER + 20,
TTM_GETDELAYTIME = WM_USER + 21,
TTM_GETTIPBKCOLOR = WM_USER + 22,
TTM_GETTIPTEXTCOLOR = WM_USER + 23,
TTM_SETMAXTIPWIDTH = WM_USER + 24,
TTM_POP = WM_USER + 28,
TTM_UPDATE = WM_USER + 29,
TTM_GETBUBBLESIZE = WM_USER + 30,
TTM_ADJUSTRECT = WM_USER + 31,
TTM_SETTITLEW = WM_USER + 33,
TTM_ADDTOOLW = WM_USER + 50,
TTM_DELTOOLW = WM_USER + 51,
TTM_NEWTOOLRECTW = WM_USER + 52,
TTM_GETTOOLINFOW = WM_USER + 53,
TTM_SETTOOLINFOW = WM_USER + 54,
TTM_HITTESTW = WM_USER + 55,
TTM_GETTEXTW = WM_USER + 56,
TTM_UPDATETIPTEXTW = WM_USER + 57,
TTM_ENUMTOOLSW = WM_USER + 58,
TTM_GETCURRENTTOOLW = WM_USER + 59,
DTM_GETSYSTEMTIME = DTM_FIRST + 1,
DTM_SETSYSTEMTIME = DTM_FIRST + 2,
DTM_SETRANGE = DTM_FIRST + 4,
Expand Down
Expand Up @@ -29102,7 +29102,7 @@ private unsafe bool WmNotify(ref Message m)
if (!string.IsNullOrEmpty(toolTip))
{
// Setting the max width has the added benefit of enabling multiline tool tips
User32.SendMessageW(nmhdr->hwndFrom, User32.WindowMessage.TTM_SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
User32.SendMessageW(nmhdr->hwndFrom, (User32.WindowMessage)ComCtl32.TTM.SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
NativeMethods.TOOLTIPTEXT ttt = (NativeMethods.TOOLTIPTEXT)m.GetLParam(typeof(NativeMethods.TOOLTIPTEXT));

ttt.lpszText = toolTip;
Expand Down
Expand Up @@ -872,7 +872,7 @@ public void Add(ControlItem item)
}

var toolInfo = new ComCtl32.ToolInfoWrapper<ErrorWindow>(this, item.Id, ComCtl32.TTF.SUBCLASS, item.Error);
toolInfo.SendMessage(_tipWindow, User32.WindowMessage.TTM_ADDTOOLW);
toolInfo.SendMessage(_tipWindow, (User32.WindowMessage)ComCtl32.TTM.ADDTOOLW);

Update(timerCaused: false);
}
Expand Down Expand Up @@ -933,12 +933,12 @@ bool EnsureCreated()
_tipWindow = new NativeWindow();
_tipWindow.CreateHandle(cparams);

User32.SendMessageW(_tipWindow, User32.WindowMessage.TTM_SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
User32.SendMessageW(_tipWindow, (User32.WindowMessage)ComCtl32.TTM.SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
User32.SetWindowPos(
new HandleRef(_tipWindow, _tipWindow.Handle),
User32.HWND_TOP,
flags: User32.SWP.NOSIZE | User32.SWP.NOMOVE | User32.SWP.NOACTIVATE);
User32.SendMessageW(_tipWindow, User32.WindowMessage.TTM_SETDELAYTIME, (IntPtr)ComCtl32.TTDT.INITIAL, (IntPtr)0);
User32.SendMessageW(_tipWindow, (User32.WindowMessage)ComCtl32.TTM.SETDELAYTIME, (IntPtr)ComCtl32.TTDT.INITIAL, (IntPtr)0);
}

return true;
Expand Down Expand Up @@ -1119,7 +1119,7 @@ public void Remove(ControlItem item)
if (_tipWindow != null)
{
var info = new ComCtl32.ToolInfoWrapper<ErrorWindow>(this, item.Id);
info.SendMessage(_tipWindow, User32.WindowMessage.TTM_DELTOOLW);
info.SendMessage(_tipWindow, (User32.WindowMessage)ComCtl32.TTM.DELTOOLW);
}

if (_items.Count == 0)
Expand Down Expand Up @@ -1225,7 +1225,7 @@ public unsafe void Update(bool timerCaused)
}

var toolInfo = new ComCtl32.ToolInfoWrapper<ErrorWindow>(this, item.Id, flags, item.Error, iconBounds);
toolInfo.SendMessage(_tipWindow, User32.WindowMessage.TTM_SETTOOLINFOW);
toolInfo.SendMessage(_tipWindow, (User32.WindowMessage)ComCtl32.TTM.SETTOOLINFOW);
}

if (timerCaused && item.BlinkPhase > 0)
Expand Down
Expand Up @@ -6366,7 +6366,7 @@ private unsafe void WmReflectNotify(ref Message m)
if (lvi != null && !string.IsNullOrEmpty(lvi.ToolTipText))
{
// Setting the max width has the added benefit of enabling multiline tool tips
User32.SendMessageW(nmhdr->hwndFrom, User32.WindowMessage.TTM_SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
User32.SendMessageW(nmhdr->hwndFrom, (User32.WindowMessage)TTM.SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);

// UNICODE. Use char.
// we need to copy the null terminator character ourselves
Expand Down
Expand Up @@ -70,7 +70,7 @@ public string ToolTip
for (int i = 0; i < controls.Length; i++)
{
ComCtl32.ToolInfoWrapper<Control> info = GetTOOLINFO(controls[i]);
info.SendMessage(this, User32.WindowMessage.TTM_UPDATETIPTEXTW);
info.SendMessage(this, (User32.WindowMessage)ComCtl32.TTM.UPDATETIPTEXTW);
}

if (visible && !dontShow)
Expand Down Expand Up @@ -118,7 +118,7 @@ private void OnControlDestroyHandle(object sender, EventArgs e)
{
if (IsHandleCreated)
{
GetTOOLINFO((Control)sender).SendMessage(this, User32.WindowMessage.TTM_DELTOOLW);
GetTOOLINFO((Control)sender).SendMessage(this, (User32.WindowMessage)ComCtl32.TTM.DELTOOLW);
}
}

Expand All @@ -144,13 +144,13 @@ private void SetupToolTip(Control control)
flags: User32.SWP.NOMOVE | User32.SWP.NOSIZE | User32.SWP.NOACTIVATE);

ComCtl32.ToolInfoWrapper<Control> info = GetTOOLINFO(control);
if (info.SendMessage(this, User32.WindowMessage.TTM_ADDTOOLW) == IntPtr.Zero)
if (info.SendMessage(this, (User32.WindowMessage)ComCtl32.TTM.ADDTOOLW) == IntPtr.Zero)
{
Debug.Fail($"TTM_ADDTOOL failed for {control.GetType().Name}");
}

// Setting the max width has the added benefit of enabling multiline tool tips
User32.SendMessageW(this, User32.WindowMessage.TTM_SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
User32.SendMessageW(this, (User32.WindowMessage)ComCtl32.TTM.SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
}
}

Expand All @@ -166,11 +166,11 @@ public void Reset()
for (int i = 0; i < controls.Length; i++)
{
ComCtl32.ToolInfoWrapper<Control> info = GetTOOLINFO(controls[i]);
info.SendMessage(this, User32.WindowMessage.TTM_UPDATETIPTEXTW);
info.SendMessage(this, (User32.WindowMessage)ComCtl32.TTM.UPDATETIPTEXTW);
}

toolTipText = oldText;
User32.SendMessageW(this, User32.WindowMessage.TTM_UPDATE);
User32.SendMessageW(this, (User32.WindowMessage)ComCtl32.TTM.UPDATE);
}

protected override void WndProc(ref Message msg)
Expand Down
Expand Up @@ -4378,7 +4378,7 @@ internal static void PositionTooltip(Control parent, GridToolTip ToolTip, Rectan

RECT rect = itemRect;

User32.SendMessageW(ToolTip, User32.WindowMessage.TTM_ADJUSTRECT, (IntPtr)1, ref rect);
User32.SendMessageW(ToolTip, (User32.WindowMessage)ComCtl32.TTM.ADJUSTRECT, (IntPtr)1, ref rect);

// now offset it back to screen coords
Point locPoint = parent.PointToScreen(new Point(rect.left, rect.top));
Expand Down
Expand Up @@ -1763,7 +1763,7 @@ private void AddTool(Tool tool)
StatusBar p = (StatusBar)parent;

ToolInfoWrapper<Control> info = GetTOOLINFO(tool);
if (info.SendMessage(p.ToolTipSet ? (IHandle)p.mainToolTip : this, User32.WindowMessage.TTM_ADDTOOLW) == IntPtr.Zero)
if (info.SendMessage(p.ToolTipSet ? (IHandle)p.mainToolTip : this, (User32.WindowMessage)TTM.ADDTOOLW) == IntPtr.Zero)
{
throw new InvalidOperationException(SR.StatusBarAddFailed);
}
Expand All @@ -1775,7 +1775,7 @@ private void RemoveTool(Tool tool)
if (tool != null && tool.text != null && tool.text.Length > 0 && (int)tool.id >= 0)
{
ToolInfoWrapper<Control> info = GetMinTOOLINFO(tool);
info.SendMessage(this, User32.WindowMessage.TTM_DELTOOLW);
info.SendMessage(this, (User32.WindowMessage)TTM.DELTOOLW);
}
}

Expand All @@ -1784,7 +1784,7 @@ private void UpdateTool(Tool tool)
if (tool != null && tool.text != null && tool.text.Length > 0 && (int)tool.id >= 0)
{
ToolInfoWrapper<Control> info = GetTOOLINFO(tool);
info.SendMessage(this, User32.WindowMessage.TTM_SETTOOLINFOW);
info.SendMessage(this, (User32.WindowMessage)TTM.SETTOOLINFOW);
}
}

Expand All @@ -1805,7 +1805,7 @@ protected void CreateHandle()
flags: User32.SWP.NOMOVE | User32.SWP.NOSIZE | User32.SWP.NOACTIVATE);

// Setting the max width has the added benefit of enabling multiline tool tips
User32.SendMessageW(this, User32.WindowMessage.TTM_SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
User32.SendMessageW(this, (User32.WindowMessage)TTM.SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
}

/// <summary>
Expand Down
Expand Up @@ -2166,7 +2166,7 @@ protected unsafe override void WndProc(ref Message m)
break;
case (int)ComCtl32.TTN.GETDISPINFOW:
// Setting the max width has the added benefit of enabling Multiline tool tips
User32.SendMessageW(nmhdr->hwndFrom, User32.WindowMessage.TTM_SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
User32.SendMessageW(nmhdr->hwndFrom, (User32.WindowMessage)TTM.SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width);
WmNeedText(ref m);
m.Result = (IntPtr)1;
return;
Expand Down

0 comments on commit 35c157f

Please sign in to comment.