SetParent sets the parent of the WidgetBase and adds the WidgetBase to the Children list of the Container.
(parent Container)
| 297 | // SetParent sets the parent of the WidgetBase and adds the WidgetBase to the |
| 298 | // Children list of the Container. |
| 299 | func (wb *WidgetBase) SetParent(parent Container) (err error) { |
| 300 | if parent == wb.parent { |
| 301 | return nil |
| 302 | } |
| 303 | |
| 304 | style := uint32(win.GetWindowLong(wb.hWnd, win.GWL_STYLE)) |
| 305 | if style == 0 { |
| 306 | return lastError("GetWindowLong") |
| 307 | } |
| 308 | |
| 309 | if parent == nil { |
| 310 | wb.SetVisible(false) |
| 311 | |
| 312 | style &^= win.WS_CHILD |
| 313 | style |= win.WS_POPUP |
| 314 | |
| 315 | if win.SetParent(wb.hWnd, 0) == 0 { |
| 316 | return lastError("SetParent") |
| 317 | } |
| 318 | win.SetLastError(0) |
| 319 | if win.SetWindowLong(wb.hWnd, win.GWL_STYLE, int32(style)) == 0 { |
| 320 | return lastError("SetWindowLong") |
| 321 | } |
| 322 | } else { |
| 323 | style |= win.WS_CHILD |
| 324 | style &^= win.WS_POPUP |
| 325 | |
| 326 | win.SetLastError(0) |
| 327 | if win.SetWindowLong(wb.hWnd, win.GWL_STYLE, int32(style)) == 0 { |
| 328 | return lastError("SetWindowLong") |
| 329 | } |
| 330 | if win.SetParent(wb.hWnd, parent.Handle()) == 0 { |
| 331 | return lastError("SetParent") |
| 332 | } |
| 333 | |
| 334 | if cb := parent.AsContainerBase(); cb != nil { |
| 335 | win.SetWindowLong(wb.hWnd, win.GWL_ID, cb.NextChildID()) |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | b := wb.BoundsPixels() |
| 340 | |
| 341 | if !win.SetWindowPos( |
| 342 | wb.hWnd, |
| 343 | win.HWND_BOTTOM, |
| 344 | int32(b.X), |
| 345 | int32(b.Y), |
| 346 | int32(b.Width), |
| 347 | int32(b.Height), |
| 348 | win.SWP_FRAMECHANGED) { |
| 349 | |
| 350 | return lastError("SetWindowPos") |
| 351 | } |
| 352 | |
| 353 | oldParent := wb.parent |
| 354 | |
| 355 | wb.parent = parent |
| 356 |
no test coverage detected