MCPcopy
hub / github.com/lxn/walk / SetParent

Method SetParent

widget.go:299–380  ·  view source on GitHub ↗

SetParent sets the parent of the WidgetBase and adds the WidgetBase to the Children list of the Container.

(parent Container)

Source from the content-addressed store, hash-verified

297// SetParent sets the parent of the WidgetBase and adds the WidgetBase to the
298// Children list of the Container.
299func (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

Callers 1

DisposeMethod · 0.95

Calls 11

BoundsPixelsMethod · 0.95
RemoveMethod · 0.95
containsHandleMethod · 0.95
AddMethod · 0.95
lastErrorFunction · 0.85
NextChildIDMethod · 0.80
SetVisibleMethod · 0.65
SetParentMethod · 0.65
HandleMethod · 0.65
AsContainerBaseMethod · 0.65
ChildrenMethod · 0.65

Tested by

no test coverage detected