summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2020-09-07 10:01:22 +0200
committerAlexander Neumann <alexander.neumann@picos-software.com>2020-09-07 10:01:22 +0200
commitbf1534f83bdf67abbcde0dca37cab0d05e3eca83 (patch)
treeaa2b0261c6b252eab835c1cdafa843b33965890b
parentBitmap: Change withPixels to GlobalAlloc with GMEM_FIXED instead of GHND (diff)
downloadwireguard-windows-bf1534f83bdf67abbcde0dca37cab0d05e3eca83.tar.xz
wireguard-windows-bf1534f83bdf67abbcde0dca37cab0d05e3eca83.zip
Missed that one in a previous commit
-rw-r--r--window.go70
1 files changed, 51 insertions, 19 deletions
diff --git a/window.go b/window.go
index 21fdd2ea..9ac94b23 100644
--- a/window.go
+++ b/window.go
@@ -522,10 +522,29 @@ func AppendToWalkInit(fn func()) {
walkInit = append(walkInit, fn)
}
+type windowCfg struct {
+ Window Window
+ Parent Window
+ ClassName string
+ Style uint32
+ ExStyle uint32
+ Bounds Rectangle
+}
+
// InitWindow initializes a window.
//
// Widgets should be initialized using InitWidget instead.
func InitWindow(window, parent Window, className string, style, exStyle uint32) error {
+ return initWindowWithCfg(&windowCfg{
+ Window: window,
+ Parent: parent,
+ ClassName: className,
+ Style: style,
+ ExStyle: exStyle,
+ })
+}
+
+func initWindowWithCfg(cfg *windowCfg) error {
// We can't use sync.Once, because tooltip.go's init also calls InitWindow, so we deadlock.
if atomic.CompareAndSwapUint32(&initedWalk, 0, 1) {
runtime.LockOSThread()
@@ -541,20 +560,20 @@ func InitWindow(window, parent Window, className string, style, exStyle uint32)
}
}
- wb := window.AsWindowBase()
- wb.window = window
+ wb := cfg.Window.AsWindowBase()
+ wb.window = cfg.Window
wb.enabled = true
- wb.visible = style&win.WS_VISIBLE != 0
+ wb.visible = cfg.Style&win.WS_VISIBLE != 0
wb.calcTextSizeInfo2TextSize = make(map[calcTextSizeInfo]Size)
wb.name2Property = make(map[string]Property)
var hwndParent win.HWND
var hMenu win.HMENU
- if parent != nil {
- hwndParent = parent.Handle()
+ if cfg.Parent != nil {
+ hwndParent = cfg.Parent.Handle()
- if widget, ok := window.(Widget); ok {
- if container, ok := parent.(Container); ok {
+ if widget, ok := cfg.Window.(Widget); ok {
+ if container, ok := cfg.Parent.(Container); ok {
if cb := container.AsContainerBase(); cb != nil {
hMenu = win.HMENU(cb.NextChildID())
}
@@ -568,16 +587,29 @@ func InitWindow(window, parent Window, className string, style, exStyle uint32)
windowName = syscall.StringToUTF16Ptr(wb.name)
}
- if hwnd := window.Handle(); hwnd == 0 {
+ if hwnd := cfg.Window.Handle(); hwnd == 0 {
+ var x, y, w, h int32
+ if cfg.Bounds.IsZero() {
+ x = win.CW_USEDEFAULT
+ y = win.CW_USEDEFAULT
+ w = win.CW_USEDEFAULT
+ h = win.CW_USEDEFAULT
+ } else {
+ x = int32(cfg.Bounds.X)
+ y = int32(cfg.Bounds.Y)
+ w = int32(cfg.Bounds.Width)
+ h = int32(cfg.Bounds.Height)
+ }
+
wb.hWnd = win.CreateWindowEx(
- exStyle,
- syscall.StringToUTF16Ptr(className),
+ cfg.ExStyle,
+ syscall.StringToUTF16Ptr(cfg.ClassName),
windowName,
- style|win.WS_CLIPSIBLINGS,
- win.CW_USEDEFAULT,
- win.CW_USEDEFAULT,
- win.CW_USEDEFAULT,
- win.CW_USEDEFAULT,
+ cfg.Style|win.WS_CLIPSIBLINGS,
+ x,
+ y,
+ w,
+ h,
hwndParent,
hMenu,
0,
@@ -615,7 +647,7 @@ func InitWindow(window, parent Window, className string, style, exStyle uint32)
hwnd2WindowBase[wb.hWnd] = wb
- if !registeredWindowClasses[className] {
+ if !registeredWindowClasses[cfg.ClassName] {
// We subclass all windows of system classes.
wb.origWndProcPtr = win.SetWindowLongPtr(wb.hWnd, win.GWLP_WNDPROC, defaultWndProcPtr)
if wb.origWndProcPtr == 0 {
@@ -625,7 +657,7 @@ func InitWindow(window, parent Window, className string, style, exStyle uint32)
SetWindowFont(wb.hWnd, defaultFont)
- if form, ok := window.(Form); ok {
+ if form, ok := cfg.Window.(Form); ok {
if fb := form.AsFormBase(); fb != nil {
if err := fb.init(form); err != nil {
return err
@@ -633,7 +665,7 @@ func InitWindow(window, parent Window, className string, style, exStyle uint32)
}
}
- if widget, ok := window.(Widget); ok {
+ if widget, ok := cfg.Window.(Widget); ok {
if wb := widget.AsWidgetBase(); wb != nil {
if err := wb.init(widget); err != nil {
return err
@@ -653,7 +685,7 @@ func InitWindow(window, parent Window, className string, style, exStyle uint32)
wb.visibleProperty = NewBoolProperty(
func() bool {
- return window.AsWindowBase().visible
+ return wb.visible
},
func(b bool) error {
wb.window.SetVisible(b)