mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibGUI: Convert GWidget to ObjectPtr
This commit is contained in:
parent
e4e92980a1
commit
ff6ce422dd
41 changed files with 115 additions and 107 deletions
|
@ -13,12 +13,12 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C
|
|||
set_title(String::format("About %s", m_name.characters()));
|
||||
set_resizable(false);
|
||||
|
||||
auto* widget = new GWidget;
|
||||
auto widget = GWidget::construct();
|
||||
set_main_widget(widget);
|
||||
widget->set_fill_with_background_color(true);
|
||||
widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
|
||||
auto* left_container = new GWidget(widget);
|
||||
auto left_container = GWidget::construct(widget);
|
||||
left_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
left_container->set_preferred_size(48, 0);
|
||||
left_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
|
@ -28,7 +28,7 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C
|
|||
icon_label->set_preferred_size(40, 40);
|
||||
left_container->layout()->add_spacer();
|
||||
|
||||
auto* right_container = new GWidget(widget);
|
||||
auto right_container = GWidget::construct(widget);
|
||||
right_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
right_container->layout()->set_margins({ 0, 4, 4, 4 });
|
||||
|
||||
|
@ -46,7 +46,7 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C
|
|||
|
||||
right_container->layout()->add_spacer();
|
||||
|
||||
auto* button_container = new GWidget(right_container);
|
||||
auto button_container = GWidget::construct(right_container);
|
||||
button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button_container->set_preferred_size(0, 20);
|
||||
button_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
|
|
|
@ -14,7 +14,6 @@ GAbstractView::GAbstractView(GWidget* parent)
|
|||
|
||||
GAbstractView::~GAbstractView()
|
||||
{
|
||||
delete m_edit_widget;
|
||||
}
|
||||
|
||||
void GAbstractView::set_model(RefPtr<GModel>&& model)
|
||||
|
@ -63,8 +62,10 @@ void GAbstractView::begin_editing(const GModelIndex& index)
|
|||
return;
|
||||
if (!model()->is_editable(index))
|
||||
return;
|
||||
if (m_edit_widget)
|
||||
delete m_edit_widget;
|
||||
if (m_edit_widget) {
|
||||
remove_child(*m_edit_widget);
|
||||
m_edit_widget = nullptr;
|
||||
}
|
||||
m_edit_index = index;
|
||||
|
||||
ASSERT(aid_create_editing_delegate);
|
||||
|
@ -88,8 +89,10 @@ void GAbstractView::begin_editing(const GModelIndex& index)
|
|||
void GAbstractView::stop_editing()
|
||||
{
|
||||
m_edit_index = {};
|
||||
delete m_edit_widget;
|
||||
m_edit_widget = nullptr;
|
||||
if (m_edit_widget) {
|
||||
remove_child(*m_edit_widget);
|
||||
m_edit_widget = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void GAbstractView::activate(const GModelIndex& index)
|
||||
|
|
|
@ -52,7 +52,7 @@ protected:
|
|||
|
||||
bool m_editable { false };
|
||||
GModelIndex m_edit_index;
|
||||
GWidget* m_edit_widget { nullptr };
|
||||
ObjectPtr<GWidget> m_edit_widget;
|
||||
Rect m_edit_widget_content_rect;
|
||||
|
||||
private:
|
||||
|
|
|
@ -50,18 +50,18 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
|
|||
{
|
||||
set_title(m_mode == Mode::Open ? "Open File" : "Save File");
|
||||
set_rect(200, 200, 700, 400);
|
||||
auto* horizontal_container = new GWidget;
|
||||
auto horizontal_container = GWidget::construct();
|
||||
set_main_widget(horizontal_container);
|
||||
horizontal_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
horizontal_container->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
horizontal_container->set_fill_with_background_color(true);
|
||||
horizontal_container->set_background_color(Color::WarmGray);
|
||||
|
||||
auto* vertical_container = new GWidget(horizontal_container);
|
||||
auto vertical_container = GWidget::construct(horizontal_container);
|
||||
vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
vertical_container->layout()->set_spacing(4);
|
||||
|
||||
auto* upper_container = new GWidget(vertical_container);
|
||||
auto upper_container = GWidget::construct(vertical_container);
|
||||
upper_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
upper_container->layout()->set_spacing(4);
|
||||
upper_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
|
@ -118,13 +118,13 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
|
|||
});
|
||||
toolbar->add_action(*mkdir_action);
|
||||
|
||||
auto* lower_container = new GWidget(vertical_container);
|
||||
auto lower_container = GWidget::construct(vertical_container);
|
||||
lower_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
lower_container->layout()->set_spacing(4);
|
||||
lower_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
lower_container->set_preferred_size(0, 60);
|
||||
|
||||
auto* filename_container = new GWidget(lower_container);
|
||||
auto filename_container = GWidget::construct(lower_container);
|
||||
filename_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
filename_container->set_preferred_size(0, 20);
|
||||
filename_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
|
@ -155,7 +155,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
|
|||
set_preview(path);
|
||||
};
|
||||
|
||||
auto* button_container = new GWidget(lower_container);
|
||||
auto button_container = GWidget::construct(lower_container);
|
||||
button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button_container->set_preferred_size(0, 20);
|
||||
button_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
|
|
|
@ -19,7 +19,7 @@ GInputBox::~GInputBox()
|
|||
|
||||
void GInputBox::build()
|
||||
{
|
||||
auto* widget = new GWidget;
|
||||
auto widget = GWidget::construct();
|
||||
set_main_widget(widget);
|
||||
|
||||
int text_width = widget->font().width(m_prompt);
|
||||
|
@ -42,12 +42,12 @@ void GInputBox::build()
|
|||
m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_text_editor->set_preferred_size(0, 19);
|
||||
|
||||
auto* button_container_outer = new GWidget(widget);
|
||||
auto button_container_outer = GWidget::construct(widget);
|
||||
button_container_outer->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button_container_outer->set_preferred_size(0, 20);
|
||||
button_container_outer->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
|
||||
auto* button_container_inner = new GWidget(button_container_outer);
|
||||
auto button_container_inner = GWidget::construct(button_container_outer);
|
||||
button_container_inner->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
button_container_inner->layout()->set_spacing(8);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ bool GMessageBox::should_include_cancel_button() const
|
|||
|
||||
void GMessageBox::build()
|
||||
{
|
||||
auto* widget = new GWidget;
|
||||
auto widget = GWidget::construct();
|
||||
set_main_widget(widget);
|
||||
|
||||
int text_width = widget->font().width(m_text);
|
||||
|
@ -62,9 +62,9 @@ void GMessageBox::build()
|
|||
widget->layout()->set_margins({ 0, 15, 0, 15 });
|
||||
widget->layout()->set_spacing(15);
|
||||
|
||||
GWidget* message_container = widget;
|
||||
ObjectPtr<GWidget> message_container = widget;
|
||||
if (m_type != Type::None) {
|
||||
message_container = new GWidget(widget);
|
||||
message_container = GWidget::construct(widget);
|
||||
message_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
message_container->layout()->set_margins({ 8, 0, 8, 0 });
|
||||
message_container->layout()->set_spacing(8);
|
||||
|
@ -80,7 +80,7 @@ void GMessageBox::build()
|
|||
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
label->set_preferred_size(text_width, 16);
|
||||
|
||||
auto* button_container = new GWidget(widget);
|
||||
auto button_container = GWidget::construct(widget);
|
||||
button_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
button_container->layout()->set_spacing(5);
|
||||
button_container->layout()->set_margins({ 15, 0, 15, 0 });
|
||||
|
|
|
@ -19,7 +19,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent)
|
|||
update();
|
||||
};
|
||||
|
||||
m_corner_widget = new GWidget(this);
|
||||
m_corner_widget = GWidget::construct(this);
|
||||
m_corner_widget->set_fill_with_background_color(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ private:
|
|||
|
||||
ObjectPtr<GScrollBar> m_vertical_scrollbar;
|
||||
ObjectPtr<GScrollBar> m_horizontal_scrollbar;
|
||||
GWidget* m_corner_widget { nullptr };
|
||||
ObjectPtr<GWidget> m_corner_widget;
|
||||
Size m_content_size;
|
||||
Size m_size_occupied_by_fixed_elements;
|
||||
bool m_scrollbars_enabled { true };
|
||||
|
|
|
@ -8,7 +8,8 @@ public:
|
|||
explicit GStackWidget(GWidget* parent);
|
||||
virtual ~GStackWidget() override;
|
||||
|
||||
GWidget* active_widget() const { return m_active_widget; }
|
||||
GWidget* active_widget() { return m_active_widget.ptr(); }
|
||||
const GWidget* active_widget() const { return m_active_widget.ptr(); }
|
||||
void set_active_widget(GWidget*);
|
||||
|
||||
Function<void(GWidget*)> on_active_widget_change;
|
||||
|
@ -18,5 +19,5 @@ protected:
|
|||
virtual void resize_event(GResizeEvent&) override;
|
||||
|
||||
private:
|
||||
GWidget* m_active_widget { nullptr };
|
||||
ObjectPtr<GWidget> m_active_widget;
|
||||
};
|
||||
|
|
|
@ -18,7 +18,8 @@ public:
|
|||
|
||||
int active_tab_index() const;
|
||||
|
||||
GWidget* active_widget() const { return m_active_widget; }
|
||||
GWidget* active_widget() { return m_active_widget.ptr(); }
|
||||
const GWidget* active_widget() const { return m_active_widget.ptr(); }
|
||||
void set_active_widget(GWidget*);
|
||||
|
||||
int bar_height() const { return 21; }
|
||||
|
@ -41,7 +42,7 @@ private:
|
|||
Rect container_rect() const;
|
||||
void update_bar();
|
||||
|
||||
GWidget* m_active_widget { nullptr };
|
||||
ObjectPtr<GWidget> m_active_widget;
|
||||
|
||||
struct TabData {
|
||||
Rect rect(const Font&) const;
|
||||
|
|
|
@ -45,10 +45,10 @@ enum class VerticalDirection {
|
|||
class GWidget : public CObject {
|
||||
C_OBJECT(GWidget)
|
||||
public:
|
||||
explicit GWidget(GWidget* parent = nullptr);
|
||||
virtual ~GWidget() override;
|
||||
|
||||
GLayout* layout() { return m_layout.ptr(); }
|
||||
const GLayout* layout() const { return m_layout.ptr(); }
|
||||
void set_layout(OwnPtr<GLayout>&&);
|
||||
|
||||
SizePolicy horizontal_size_policy() const { return m_horizontal_size_policy; }
|
||||
|
@ -72,25 +72,6 @@ public:
|
|||
void set_updates_enabled(bool);
|
||||
|
||||
virtual void event(CEvent&) override;
|
||||
virtual void paint_event(GPaintEvent&);
|
||||
virtual void resize_event(GResizeEvent&);
|
||||
virtual void show_event(GShowEvent&);
|
||||
virtual void hide_event(GHideEvent&);
|
||||
virtual void keydown_event(GKeyEvent&);
|
||||
virtual void keyup_event(GKeyEvent&);
|
||||
virtual void mousemove_event(GMouseEvent&);
|
||||
virtual void mousedown_event(GMouseEvent&);
|
||||
virtual void mouseup_event(GMouseEvent&);
|
||||
virtual void mousewheel_event(GMouseEvent&);
|
||||
virtual void click_event(GMouseEvent&);
|
||||
virtual void doubleclick_event(GMouseEvent&);
|
||||
virtual void context_menu_event(GContextMenuEvent&);
|
||||
virtual void focusin_event(CEvent&);
|
||||
virtual void focusout_event(CEvent&);
|
||||
virtual void enter_event(CEvent&);
|
||||
virtual void leave_event(CEvent&);
|
||||
virtual void child_event(CChildEvent&) override;
|
||||
virtual void change_event(GEvent&);
|
||||
|
||||
// This is called after children have been painted.
|
||||
virtual void second_paint_event(GPaintEvent&);
|
||||
|
@ -221,8 +202,29 @@ public:
|
|||
virtual void save_to(AK::JsonObject&) override;
|
||||
|
||||
protected:
|
||||
explicit GWidget(GWidget* parent = nullptr);
|
||||
|
||||
virtual void custom_layout() {}
|
||||
virtual void did_change_font() {}
|
||||
virtual void paint_event(GPaintEvent&);
|
||||
virtual void resize_event(GResizeEvent&);
|
||||
virtual void show_event(GShowEvent&);
|
||||
virtual void hide_event(GHideEvent&);
|
||||
virtual void keydown_event(GKeyEvent&);
|
||||
virtual void keyup_event(GKeyEvent&);
|
||||
virtual void mousemove_event(GMouseEvent&);
|
||||
virtual void mousedown_event(GMouseEvent&);
|
||||
virtual void mouseup_event(GMouseEvent&);
|
||||
virtual void mousewheel_event(GMouseEvent&);
|
||||
virtual void click_event(GMouseEvent&);
|
||||
virtual void doubleclick_event(GMouseEvent&);
|
||||
virtual void context_menu_event(GContextMenuEvent&);
|
||||
virtual void focusin_event(CEvent&);
|
||||
virtual void focusout_event(CEvent&);
|
||||
virtual void enter_event(CEvent&);
|
||||
virtual void leave_event(CEvent&);
|
||||
virtual void child_event(CChildEvent&) override;
|
||||
virtual void change_event(GEvent&);
|
||||
|
||||
private:
|
||||
void handle_paint_event(GPaintEvent&);
|
||||
|
|
|
@ -698,7 +698,7 @@ Vector<GWidget*> GWindow::focusable_widgets() const
|
|||
});
|
||||
};
|
||||
|
||||
collect_focusable_widgets(*m_main_widget);
|
||||
collect_focusable_widgets(const_cast<GWidget&>(*m_main_widget));
|
||||
return collected_widgets;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ private:
|
|||
RefPtr<GraphicsBitmap> m_icon;
|
||||
int m_window_id { 0 };
|
||||
float m_opacity_when_windowless { 1.0f };
|
||||
GWidget* m_main_widget { nullptr };
|
||||
ObjectPtr<GWidget> m_main_widget;
|
||||
WeakPtr<GWidget> m_focused_widget;
|
||||
WeakPtr<GWidget> m_global_cursor_tracking_widget;
|
||||
WeakPtr<GWidget> m_automatic_cursor_tracking_widget;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue