diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-11-28 12:04:47 +0100 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-11-28 12:04:47 +0100 |
commit | 55ccb3a9f5c1dae7b1c94f70ea4f9db6afcb5021 (patch) | |
tree | bc1ea3bba9865d5af0ae50defade4ab291f67075 | |
parent | static: Use GET_[X|Y]_LPARAM to extract coordinates from LPARAM (diff) | |
download | wireguard-windows-55ccb3a9f5c1dae7b1c94f70ea4f9db6afcb5021.tar.xz wireguard-windows-55ccb3a9f5c1dae7b1c94f70ea4f9db6afcb5021.zip |
TableView: Display header tool tips for too narrow columns
-rw-r--r-- | tableview.go | 44 | ||||
-rw-r--r-- | tooltip.go | 31 |
2 files changed, 63 insertions, 12 deletions
diff --git a/tableview.go b/tableview.go index b0593ef3..a570079d 100644 --- a/tableview.go +++ b/tableview.go @@ -246,6 +246,9 @@ func NewTableViewWithCfg(parent Container, cfg *TableViewCfg) (*TableView, error win.SendMessage(tv.hwndFrozenLV, win.WM_CHANGEUISTATE, uintptr(win.MAKELONG(win.UIS_SET, win.UISF_HIDEFOCUS)), 0) win.SendMessage(tv.hwndNormalLV, win.WM_CHANGEUISTATE, uintptr(win.MAKELONG(win.UIS_SET, win.UISF_HIDEFOCUS)), 0) + tv.group.toolTip.addTool(tv.hwndFrozenHdr, false) + tv.group.toolTip.addTool(tv.hwndNormalHdr, false) + tv.applyFont(parent.Font()) tv.style.dpi = tv.DPI() @@ -343,11 +346,13 @@ func (tv *TableView) Dispose() { } if tv.hwndFrozenLV != 0 { + tv.group.toolTip.removeTool(tv.hwndFrozenHdr) win.DestroyWindow(tv.hwndFrozenLV) tv.hwndFrozenLV = 0 } if tv.hwndNormalLV != 0 { + tv.group.toolTip.removeTool(tv.hwndNormalHdr) win.DestroyWindow(tv.hwndNormalLV) tv.hwndNormalLV = 0 } @@ -2439,6 +2444,45 @@ func tableViewHdrWndProc(hwnd win.HWND, msg uint32, wp, lp uintptr) uintptr { hdl.Pwpos.Cy = int32(tv.customHeaderHeight) return result + + case win.WM_MOUSEMOVE, win.WM_LBUTTONDOWN, win.WM_LBUTTONUP, win.WM_MBUTTONDOWN, win.WM_MBUTTONUP, win.WM_RBUTTONDOWN, win.WM_RBUTTONUP: + hti := win.HDHITTESTINFO{Pt: win.POINT{int32(win.GET_X_LPARAM(lp)), int32(win.GET_Y_LPARAM(lp))}} + win.SendMessage(hwnd, win.HDM_HITTEST, 0, uintptr(unsafe.Pointer(&hti))) + if hti.IItem == -1 { + tv.group.toolTip.setText(hwnd, "") + break + } + + col := tv.fromLVColIdx(hwnd == tv.hwndFrozenHdr, hti.IItem) + text := tv.columns.At(col).TitleEffective() + + var rc win.RECT + if 0 == win.SendMessage(hwnd, win.HDM_GETITEMRECT, uintptr(hti.IItem), uintptr(unsafe.Pointer(&rc))) { + tv.group.toolTip.setText(hwnd, "") + break + } + + size := calculateTextSize(text, tv.Font(), tv.DPI(), 0, hwnd) + if size.Width <= rectangleFromRECT(rc).Width-int(win.SendMessage(hwnd, win.HDM_GETBITMAPMARGIN, 0, 0)) { + tv.group.toolTip.setText(hwnd, "") + break + } + + if tv.group.toolTip.text(hwnd) == text { + break + } + + tv.group.toolTip.setText(hwnd, text) + + m := win.MSG{ + HWnd: hwnd, + Message: msg, + WParam: wp, + LParam: lp, + Pt: hti.Pt, + } + + tv.group.toolTip.SendMessage(win.TTM_RELAYEVENT, 0, uintptr(unsafe.Pointer(&m))) } return win.CallWindowProc(origWndProcPtr, hwnd, msg, wp, lp) @@ -114,7 +114,7 @@ func (tt *ToolTip) track(tool Widget) error { return nil } - ti := tt.toolInfo(tool) + ti := tt.toolInfo(tool.Handle()) if ti == nil { return newError("unknown tool") } @@ -146,7 +146,7 @@ func (tt *ToolTip) track(tool Widget) error { } func (tt *ToolTip) untrack(tool Widget) error { - ti := tt.toolInfo(tool) + ti := tt.toolInfo(tool.Handle()) if ti == nil { return newError("unknown tool") } @@ -157,15 +157,14 @@ func (tt *ToolTip) untrack(tool Widget) error { } func (tt *ToolTip) AddTool(tool Widget) error { - return tt.addTool(tool, false) + return tt.addTool(tt.hwndForTool(tool), false) } func (tt *ToolTip) addTrackedTool(tool Widget) error { - return tt.addTool(tool, true) + return tt.addTool(tt.hwndForTool(tool), true) } -func (tt *ToolTip) addTool(tool Widget, track bool) error { - hwnd := tt.hwndForTool(tool) +func (tt *ToolTip) addTool(hwnd win.HWND, track bool) error { if hwnd == 0 { return nil } @@ -189,8 +188,10 @@ func (tt *ToolTip) addTool(tool Widget, track bool) error { } func (tt *ToolTip) RemoveTool(tool Widget) error { - hwnd := tt.hwndForTool(tool) + return tt.removeTool(tt.hwndForTool(tool)) +} +func (tt *ToolTip) removeTool(hwnd win.HWND) error { var ti win.TOOLINFO ti.CbSize = uint32(unsafe.Sizeof(ti)) ti.Hwnd = hwnd @@ -202,7 +203,11 @@ func (tt *ToolTip) RemoveTool(tool Widget) error { } func (tt *ToolTip) Text(tool Widget) string { - ti := tt.toolInfo(tool) + return tt.text(tt.hwndForTool(tool)) +} + +func (tt *ToolTip) text(hwnd win.HWND) string { + ti := tt.toolInfo(hwnd) if ti == nil { return "" } @@ -211,7 +216,11 @@ func (tt *ToolTip) Text(tool Widget) string { } func (tt *ToolTip) SetText(tool Widget, text string) error { - ti := tt.toolInfo(tool) + return tt.setText(tt.hwndForTool(tool), text) +} + +func (tt *ToolTip) setText(hwnd win.HWND, text string) error { + ti := tt.toolInfo(hwnd) if ti == nil { return newError("unknown tool") } @@ -236,12 +245,10 @@ func (tt *ToolTip) SetText(tool Widget, text string) error { return nil } -func (tt *ToolTip) toolInfo(tool Widget) *win.TOOLINFO { +func (tt *ToolTip) toolInfo(hwnd win.HWND) *win.TOOLINFO { var ti win.TOOLINFO var buf [maxToolTipTextLen]uint16 - hwnd := tt.hwndForTool(tool) - ti.CbSize = uint32(unsafe.Sizeof(ti)) ti.Hwnd = hwnd ti.UId = uintptr(hwnd) |