mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +00:00
AK: Improve smart pointer ergonomics a bit.
This commit is contained in:
parent
d5dec1922b
commit
3f6408919f
17 changed files with 49 additions and 31 deletions
|
@ -15,7 +15,7 @@ GAbstractView::~GAbstractView()
|
|||
|
||||
void GAbstractView::set_model(RetainPtr<GModel>&& model)
|
||||
{
|
||||
if (model.ptr() == m_model.ptr())
|
||||
if (model == m_model)
|
||||
return;
|
||||
if (m_model)
|
||||
m_model->unregister_view(Badge<GAbstractView>(), *this);
|
||||
|
|
|
@ -137,7 +137,7 @@ void GButton::set_action(GAction& action)
|
|||
|
||||
void GButton::set_icon(RetainPtr<GraphicsBitmap>&& icon)
|
||||
{
|
||||
if (m_icon.ptr() == icon.ptr())
|
||||
if (m_icon == icon)
|
||||
return;
|
||||
m_icon = move(icon);
|
||||
update();
|
||||
|
|
|
@ -11,14 +11,14 @@ GLayout::~GLayout()
|
|||
|
||||
void GLayout::notify_adopted(Badge<GWidget>, GWidget& widget)
|
||||
{
|
||||
if (m_owner.ptr() == &widget)
|
||||
if (m_owner == &widget)
|
||||
return;
|
||||
m_owner = widget.make_weak_ptr();
|
||||
}
|
||||
|
||||
void GLayout::notify_disowned(Badge<GWidget>, GWidget& widget)
|
||||
{
|
||||
ASSERT(m_owner.ptr() == &widget);
|
||||
ASSERT(m_owner == &widget);
|
||||
m_owner.clear();
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ void GLayout::add_widget(GWidget& widget)
|
|||
void GLayout::remove_widget(GWidget& widget)
|
||||
{
|
||||
m_entries.remove_first_matching([&] (auto& entry) {
|
||||
return entry.widget.ptr() == &widget;
|
||||
return entry.widget == &widget;
|
||||
});
|
||||
if (m_owner)
|
||||
m_owner->notify_layout_changed(Badge<GLayout>());
|
||||
|
|
|
@ -120,8 +120,6 @@ void GWidget::handle_paint_event(GPaintEvent& event)
|
|||
|
||||
void GWidget::set_layout(OwnPtr<GLayout>&& layout)
|
||||
{
|
||||
if (m_layout.ptr() == layout.ptr())
|
||||
return;
|
||||
if (m_layout)
|
||||
m_layout->notify_disowned(Badge<GWidget>(), *this);
|
||||
m_layout = move(layout);
|
||||
|
|
|
@ -346,14 +346,14 @@ void GWindow::set_focused_widget(GWidget* widget)
|
|||
|
||||
void GWindow::set_global_cursor_tracking_widget(GWidget* widget)
|
||||
{
|
||||
if (widget == m_global_cursor_tracking_widget.ptr())
|
||||
if (widget == m_global_cursor_tracking_widget)
|
||||
return;
|
||||
m_global_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr;
|
||||
}
|
||||
|
||||
void GWindow::set_automatic_cursor_tracking_widget(GWidget* widget)
|
||||
{
|
||||
if (widget == m_automatic_cursor_tracking_widget.ptr())
|
||||
if (widget == m_automatic_cursor_tracking_widget)
|
||||
return;
|
||||
m_automatic_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr;
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ void GWindow::set_opacity(float opacity)
|
|||
|
||||
void GWindow::set_hovered_widget(GWidget* widget)
|
||||
{
|
||||
if (widget == m_hovered_widget.ptr())
|
||||
if (widget == m_hovered_widget)
|
||||
return;
|
||||
|
||||
if (m_hovered_widget)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue