diff options
author | Anthony Dong <adongy@users.noreply.github.com> | 2019-05-08 15:24:36 +0200 |
---|---|---|
committer | Anthony Dong <adongy@users.noreply.github.com> | 2019-05-08 15:24:36 +0200 |
commit | 0f9c2715380b87983e6f333a28a5ca99b7105161 (patch) | |
tree | 26be3458e6fa7760b1740ed176c763260831994b /tabwidget.go | |
parent | mainwindow: exit in response to ENDSESSION_CLOSEAPP (diff) | |
download | wireguard-windows-0f9c2715380b87983e6f333a28a5ca99b7105161.tar.xz wireguard-windows-0f9c2715380b87983e6f333a28a5ca99b7105161.zip |
ui: allow manually drawing tab widgetad/pkg/walk/manual-draw-tabwidget
Diffstat (limited to 'tabwidget.go')
-rw-r--r-- | tabwidget.go | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/tabwidget.go b/tabwidget.go index a4f037dc..36af3629 100644 --- a/tabwidget.go +++ b/tabwidget.go @@ -32,6 +32,10 @@ type TabWidget struct { } func NewTabWidget(parent Container) (*TabWidget, error) { + return NewTabWidgetWithStyle(parent, 0) +} + +func NewTabWidgetWithStyle(parent Container, style uint32) (*TabWidget, error) { tw := &TabWidget{currentIndex: -1} tw.pages = newTabPageList(tw) @@ -55,7 +59,7 @@ func NewTabWidget(parent Container) (*TabWidget, error) { tw.hWndTab = win.CreateWindowEx( 0, syscall.StringToUTF16Ptr("SysTabControl32"), nil, - win.WS_CHILD|win.WS_CLIPSIBLINGS|win.WS_TABSTOP|win.WS_VISIBLE, + win.WS_CHILD|win.WS_CLIPSIBLINGS|win.WS_TABSTOP|win.WS_VISIBLE|style, 0, 0, 0, 0, tw.hWnd, 0, 0, nil) if tw.hWndTab == 0 { return nil, lastError("CreateWindowEx") @@ -344,6 +348,69 @@ func (tw *TabWidget) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) case win.TCN_SELCHANGE: tw.onSelChange() } + + case win.WM_DRAWITEM: + dis := (*win.DRAWITEMSTRUCT)(unsafe.Pointer(lParam)) + + page := tw.pages.At(int(dis.ItemID)) + + rc := dis.RcItem + hdc := dis.HDC + savedDC := win.SaveDC(hdc) + defer win.RestoreDC(hdc, savedDC) + + canvas, err := newCanvasFromHDC(hdc) + if err != nil { + return 1 + } + defer canvas.Dispose() + + if err := canvas.FillRectangle(sysColorBtnFaceBrush, rectangleFromRECT(rc)); err != nil { + return 1 + } + + if bg, wnd := page.AsWindowBase().backgroundEffective(); bg != nil { + tw.prepareDCForBackground(canvas.hdc, hwnd, wnd) + + hRgn := win.CreateRectRgn(rc.Left, rc.Top, rc.Right, rc.Bottom+2) + defer win.DeleteObject(win.HGDIOBJ(hRgn)) + if !win.FillRgn(canvas.hdc, hRgn, bg.handle()) { + return 1 + } + + if page.image != nil { + x := rc.Left + 6 + y := rc.Top + s := int32(16) + + if imageCanvas, err := NewCanvasFromImage(page.image); err == nil { + defer imageCanvas.Dispose() + + if !win.TransparentBlt( + canvas.hdc, x, y, s, s, + imageCanvas.hdc, 0, 0, int32(page.image.size.Width), int32(page.image.size.Height), + 0) { + break + } + } + + rc.Left += s + 6 + } + + rc.Left += 6 + rc.Top += 1 + + title := syscall.StringToUTF16(page.title) + + hOldFont := win.SelectObject(canvas.hdc, win.HGDIOBJ(page.TitleFont().handleForDPI(0))) + defer win.SelectObject(canvas.hdc, hOldFont) + + if 0 == win.DrawTextEx(canvas.hdc, &title[0], int32(len(title)), &rc, 0, nil) { + break + } + } + + return 1 } } |