github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/windows/winc/resizer.go (about) 1 //go:build windows 2 3 /* 4 * Copyright (C) 2019 The Winc Authors. All Rights Reserved. 5 */ 6 7 package winc 8 9 import ( 10 "github.com/secoba/wails/v2/internal/frontend/desktop/windows/winc/w32" 11 ) 12 13 type VResizer struct { 14 ControlBase 15 16 control1 Dockable 17 control2 Dockable 18 dir Direction 19 20 mouseLeft bool 21 drag bool 22 } 23 24 func NewVResizer(parent Controller) *VResizer { 25 sp := new(VResizer) 26 27 RegClassOnlyOnce("winc_VResizer") 28 sp.hwnd = CreateWindow("winc_VResizer", parent, w32.WS_EX_CONTROLPARENT, w32.WS_CHILD|w32.WS_VISIBLE) 29 sp.parent = parent 30 sp.mouseLeft = true 31 RegMsgHandler(sp) 32 33 sp.SetFont(DefaultFont) 34 sp.SetText("") 35 sp.SetSize(20, 100) 36 return sp 37 } 38 39 func (sp *VResizer) SetControl(control1, control2 Dockable, dir Direction, minSize int) { 40 sp.control1 = control1 41 sp.control2 = control2 42 if dir != Left && dir != Right { 43 panic("invalid direction") 44 } 45 sp.dir = dir 46 47 // TODO(vi): ADDED 48 /*internalTrackMouseEvent(control1.Handle()) 49 internalTrackMouseEvent(control2.Handle()) 50 51 control1.OnMouseMove().Bind(func(e *Event) { 52 if sp.drag { 53 x := e.Data.(*MouseEventData).X 54 sp.update(x) 55 w32.SetCursor(w32.LoadCursorWithResourceID(0, w32.IDC_SIZEWE)) 56 57 } 58 fmt.Println("control1.OnMouseMove") 59 }) 60 61 control2.OnMouseMove().Bind(func(e *Event) { 62 if sp.drag { 63 x := e.Data.(*MouseEventData).X 64 sp.update(x) 65 w32.SetCursor(w32.LoadCursorWithResourceID(0, w32.IDC_SIZEWE)) 66 67 } 68 fmt.Println("control2.OnMouseMove") 69 }) 70 71 control1.OnLBUp().Bind(func(e *Event) { 72 sp.drag = false 73 sp.mouseLeft = true 74 fmt.Println("control1.OnLBUp") 75 }) 76 77 control2.OnLBUp().Bind(func(e *Event) { 78 sp.drag = false 79 sp.mouseLeft = true 80 fmt.Println("control2.OnLBUp") 81 })*/ 82 83 // ---- finish ADDED 84 85 } 86 87 func (sp *VResizer) update(x int) { 88 pos := x - 10 89 90 w1, h1 := sp.control1.Width(), sp.control1.Height() 91 if sp.dir == Left { 92 w1 += pos 93 } else { 94 w1 -= pos 95 } 96 sp.control1.SetSize(w1, h1) 97 fm := sp.parent.(*Form) 98 fm.UpdateLayout() 99 100 w32.SetCursor(w32.LoadCursorWithResourceID(0, w32.IDC_ARROW)) 101 } 102 103 func (sp *VResizer) WndProc(msg uint32, wparam, lparam uintptr) uintptr { 104 switch msg { 105 case w32.WM_CREATE: 106 internalTrackMouseEvent(sp.hwnd) 107 108 case w32.WM_MOUSEMOVE: 109 if sp.drag { 110 x, _ := genPoint(lparam) 111 sp.update(x) 112 } else { 113 w32.SetCursor(w32.LoadCursorWithResourceID(0, w32.IDC_SIZEWE)) 114 } 115 116 if sp.mouseLeft { 117 internalTrackMouseEvent(sp.hwnd) 118 sp.mouseLeft = false 119 } 120 121 case w32.WM_MOUSELEAVE: 122 sp.drag = false 123 sp.mouseLeft = true 124 125 case w32.WM_LBUTTONUP: 126 sp.drag = false 127 128 case w32.WM_LBUTTONDOWN: 129 sp.drag = true 130 } 131 return w32.DefWindowProc(sp.hwnd, msg, wparam, lparam) 132 } 133 134 type HResizer struct { 135 ControlBase 136 137 control1 Dockable 138 control2 Dockable 139 dir Direction 140 mouseLeft bool 141 drag bool 142 } 143 144 func NewHResizer(parent Controller) *HResizer { 145 sp := new(HResizer) 146 147 RegClassOnlyOnce("winc_HResizer") 148 sp.hwnd = CreateWindow("winc_HResizer", parent, w32.WS_EX_CONTROLPARENT, w32.WS_CHILD|w32.WS_VISIBLE) 149 sp.parent = parent 150 sp.mouseLeft = true 151 RegMsgHandler(sp) 152 153 sp.SetFont(DefaultFont) 154 sp.SetText("") 155 sp.SetSize(100, 20) 156 157 return sp 158 } 159 160 func (sp *HResizer) SetControl(control1, control2 Dockable, dir Direction, minSize int) { 161 sp.control1 = control1 162 sp.control2 = control2 163 if dir != Top && dir != Bottom { 164 panic("invalid direction") 165 } 166 sp.dir = dir 167 168 } 169 170 func (sp *HResizer) update(y int) { 171 pos := y - 10 172 173 w1, h1 := sp.control1.Width(), sp.control1.Height() 174 if sp.dir == Top { 175 h1 += pos 176 } else { 177 h1 -= pos 178 } 179 sp.control1.SetSize(w1, h1) 180 181 fm := sp.parent.(*Form) 182 fm.UpdateLayout() 183 184 w32.SetCursor(w32.LoadCursorWithResourceID(0, w32.IDC_ARROW)) 185 } 186 187 func (sp *HResizer) WndProc(msg uint32, wparam, lparam uintptr) uintptr { 188 switch msg { 189 case w32.WM_CREATE: 190 internalTrackMouseEvent(sp.hwnd) 191 192 case w32.WM_MOUSEMOVE: 193 if sp.drag { 194 _, y := genPoint(lparam) 195 sp.update(y) 196 } else { 197 w32.SetCursor(w32.LoadCursorWithResourceID(0, w32.IDC_SIZENS)) 198 } 199 200 if sp.mouseLeft { 201 internalTrackMouseEvent(sp.hwnd) 202 sp.mouseLeft = false 203 } 204 205 case w32.WM_MOUSELEAVE: 206 sp.drag = false 207 sp.mouseLeft = true 208 209 case w32.WM_LBUTTONUP: 210 sp.drag = false 211 212 case w32.WM_LBUTTONDOWN: 213 sp.drag = true 214 } 215 return w32.DefWindowProc(sp.hwnd, msg, wparam, lparam) 216 }