Coverage Report

Created: 2026-09-23 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wt/src/Wt/WWidgetItem.C
Line
Count
Source
1
/*
2
 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
3
 *
4
 * See the LICENSE file for terms of use.
5
 */
6
7
#include "Wt/WWidgetItem.h"
8
9
#include "Wt/WContainerWidget.h"
10
#include "Wt/WException.h"
11
#include "Wt/WLayout.h"
12
#include "Wt/WLayoutItemImpl.h"
13
14
#include "StdWidgetItemImpl.h"
15
#include "FlexLayoutImpl.h"
16
#include "FlexItemImpl.h"
17
18
namespace Wt {
19
20
WWidgetItem::WWidgetItem(std::unique_ptr<WWidget> widget)
21
0
  : widget_(std::move(widget)),
22
0
    parentLayout_(nullptr)
23
0
{ }
24
25
WWidgetItem::~WWidgetItem()
26
0
{
27
0
  setParentWidget(nullptr);
28
0
}
29
30
WWidgetItem *WWidgetItem::findWidgetItem(WWidget *widget)
31
0
{
32
0
  if (widget_.get() == widget)
33
0
    return this;
34
0
  else
35
0
    return nullptr;
36
0
}
37
38
void WWidgetItem::setParentWidget(WWidget *parent)
39
0
{
40
0
  if (!widget_)
41
0
    return;
42
43
0
  if (parent) {
44
0
    WContainerWidget *pc = dynamic_cast<WContainerWidget *>(parent);
45
46
0
    if (widget_->parent()) {
47
0
      if (widget_->parent() != pc)
48
0
        throw WException("Cannot move a WWidgetItem to another container");
49
0
    } else
50
0
      pc->widgetAdded(widget_.get());
51
52
0
    bool flexLayout = parentLayout_->implementationIsFlexLayout();
53
54
0
    if (flexLayout)
55
0
      impl_ = std::make_unique<FlexItemImpl>(this);
56
0
    else
57
0
      impl_ = std::make_unique<StdWidgetItemImpl>(this);
58
0
  } else {
59
0
    WContainerWidget *pc = dynamic_cast<WContainerWidget *>(widget_->parent());
60
61
0
    if (pc) {
62
0
      assert(impl_);
63
0
      bool flex = dynamic_cast<FlexItemImpl*>(impl());
64
0
      pc->widgetRemoved(widget_.get(), flex);
65
0
    }
66
67
0
    impl_.reset();
68
0
  }
69
0
}
70
71
std::unique_ptr<WWidget> WWidgetItem::takeWidget()
72
0
{
73
0
  std::unique_ptr<WWidget> result = std::move(widget_);
74
0
  impl_.reset();
75
0
  return result;
76
0
}
77
78
void WWidgetItem::setParentLayout(WLayout *parentLayout)
79
0
{
80
0
  parentLayout_ = parentLayout;
81
0
}
82
83
void WWidgetItem::iterateWidgets(const HandleWidgetMethod& method) const
84
0
{
85
0
  if (widget_)
86
0
#ifndef WT_TARGET_JAVA
87
0
    method(widget_.get());
88
#else
89
    method.handle(widget_.get());
90
#endif
91
0
}
92
93
WWidget *WWidgetItem::parentWidget() const
94
0
{
95
0
  if (parentLayout_)
96
0
    return parentLayout_->parentWidget();
97
0
  else
98
0
    return nullptr;
99
0
}
100
101
}