mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:27:45 +00:00
LibCore: Make CObject reference-counted
Okay, I've spent a whole day on this now, and it finally kinda works! With this patch, CObject and all of its derived classes are reference counted instead of tree-owned. The previous, Qt-like model was nice and familiar, but ultimately also outdated and difficult to reason about. CObject-derived types should now be stored in RefPtr/NonnullRefPtr and each class can be constructed using the forwarding construct() helper: auto widget = GWidget::construct(parent_widget); Note that construct() simply forwards all arguments to an existing constructor. It is inserted into each class by the C_OBJECT macro, see CObject.h to understand how that works. CObject::delete_later() disappears in this patch, as there is no longer a single logical owner of a CObject.
This commit is contained in:
parent
0c72e0c09f
commit
bc319d9e88
45 changed files with 174 additions and 233 deletions
|
@ -97,7 +97,7 @@ void DisplayPropertiesWidget::create_frame()
|
|||
auto background_splitter = GSplitter::construct(Orientation::Vertical, nullptr);
|
||||
tab_widget->add_widget("Wallpaper", background_splitter);
|
||||
|
||||
auto background_content = GWidget::construct(background_splitter);
|
||||
auto background_content = GWidget::construct(background_splitter.ptr());
|
||||
background_content->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
background_content->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
|
@ -120,7 +120,7 @@ void DisplayPropertiesWidget::create_frame()
|
|||
auto settings_splitter = GSplitter::construct(Orientation::Vertical, nullptr);
|
||||
tab_widget->add_widget("Settings", settings_splitter);
|
||||
|
||||
auto settings_content = GWidget::construct(settings_splitter);
|
||||
auto settings_content = GWidget::construct(settings_splitter.ptr());
|
||||
settings_content->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
settings_content->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
|
@ -135,7 +135,7 @@ void DisplayPropertiesWidget::create_frame()
|
|||
settings_content->layout()->add_spacer();
|
||||
|
||||
// Add the apply and cancel buttons
|
||||
auto bottom_widget = GWidget::construct(m_root_widget);
|
||||
auto bottom_widget = GWidget::construct(m_root_widget.ptr());
|
||||
bottom_widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
bottom_widget->layout()->add_spacer();
|
||||
bottom_widget->set_size_policy(Orientation::Vertical, SizePolicy::Fixed);
|
||||
|
|
|
@ -171,7 +171,7 @@ void IRCAppWindow::setup_widgets()
|
|||
toolbar->add_action(*m_open_query_action);
|
||||
toolbar->add_action(*m_close_query_action);
|
||||
|
||||
auto outer_container = GWidget::construct(widget);
|
||||
auto outer_container = GWidget::construct(widget.ptr());
|
||||
outer_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
outer_container->layout()->set_margins({ 2, 0, 2, 2 });
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ void ColorDialog::build()
|
|||
horizontal_container->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
set_main_widget(horizontal_container);
|
||||
|
||||
auto left_vertical_container = GWidget::construct(horizontal_container);
|
||||
auto left_vertical_container = GWidget::construct(horizontal_container.ptr());
|
||||
left_vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
|
||||
auto right_vertical_container = GWidget::construct(horizontal_container);
|
||||
auto right_vertical_container = GWidget::construct(horizontal_container.ptr());
|
||||
right_vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
|
||||
enum RGBComponent {
|
||||
|
|
|
@ -87,11 +87,11 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
|
|||
color_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
color_container->layout()->set_spacing(1);
|
||||
|
||||
auto top_color_container = GWidget::construct(color_container);
|
||||
auto top_color_container = GWidget::construct(color_container.ptr());
|
||||
top_color_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
top_color_container->layout()->set_spacing(1);
|
||||
|
||||
auto bottom_color_container = GWidget::construct(color_container);
|
||||
auto bottom_color_container = GWidget::construct(color_container.ptr());
|
||||
bottom_color_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
bottom_color_container->layout()->set_spacing(1);
|
||||
|
||||
|
|
|
@ -19,14 +19,14 @@ int main(int argc, char** argv)
|
|||
window->set_title("PaintBrush");
|
||||
window->set_rect(100, 100, 640, 480);
|
||||
|
||||
auto horizontal_container = GWidget::construct(nullptr);
|
||||
auto horizontal_container = GWidget::construct();
|
||||
window->set_main_widget(horizontal_container);
|
||||
horizontal_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
horizontal_container->layout()->set_spacing(0);
|
||||
|
||||
new ToolboxWidget(horizontal_container);
|
||||
|
||||
auto vertical_container = GWidget::construct(horizontal_container);
|
||||
auto vertical_container = GWidget::construct(horizontal_container.ptr());
|
||||
vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
vertical_container->layout()->set_spacing(0);
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
GApplication app(argc, argv);
|
||||
AClientConnection audio_connection;
|
||||
audio_connection.handshake();
|
||||
auto audio_client = AClientConnection::construct();
|
||||
audio_client->handshake();
|
||||
|
||||
auto window = GWindow::construct();
|
||||
window->set_title("Piano");
|
||||
|
|
|
@ -27,8 +27,8 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
AClientConnection audio_client;
|
||||
audio_client.handshake();
|
||||
auto audio_client = AClientConnection::construct();
|
||||
audio_client->handshake();
|
||||
|
||||
auto window = GWindow::construct();
|
||||
window->set_title("SoundPlayer");
|
||||
|
@ -57,7 +57,7 @@ int main(int argc, char** argv)
|
|||
sample_widget->set_buffer(nullptr);
|
||||
return;
|
||||
}
|
||||
bool enqueued = audio_client.try_enqueue(*next_sample_buffer);
|
||||
bool enqueued = audio_client->try_enqueue(*next_sample_buffer);
|
||||
if (!enqueued)
|
||||
return;
|
||||
sample_widget->set_buffer(next_sample_buffer);
|
||||
|
|
|
@ -58,7 +58,7 @@ int main(int argc, char** argv)
|
|||
auto process_container_splitter = GSplitter::construct(Orientation::Vertical, nullptr);
|
||||
tabwidget->add_widget("Processes", process_container_splitter);
|
||||
|
||||
auto process_table_container = GWidget::construct(process_container_splitter);
|
||||
auto process_table_container = GWidget::construct(process_container_splitter.ptr());
|
||||
|
||||
auto graphs_container = GWidget::construct();
|
||||
graphs_container->set_fill_with_background_color(true);
|
||||
|
@ -301,7 +301,7 @@ ObjectPtr<GWidget> build_file_systems_tab()
|
|||
|
||||
ObjectPtr<GWidget> build_pci_devices_tab()
|
||||
{
|
||||
auto pci_widget = GWidget::construct(nullptr);
|
||||
auto pci_widget = GWidget::construct();
|
||||
pci_widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
pci_widget->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
auto pci_table_view = GTableView::construct(pci_widget);
|
||||
|
|
|
@ -46,7 +46,7 @@ void TaskbarWindow::on_screen_rect_change(const Rect& rect)
|
|||
set_rect(new_rect);
|
||||
}
|
||||
|
||||
GButton* TaskbarWindow::create_button(const WindowIdentifier& identifier)
|
||||
NonnullRefPtr<GButton> TaskbarWindow::create_button(const WindowIdentifier& identifier)
|
||||
{
|
||||
auto button = TaskbarButton::construct(identifier, main_widget());
|
||||
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
|
|
|
@ -12,7 +12,7 @@ public:
|
|||
|
||||
private:
|
||||
void on_screen_rect_change(const Rect&);
|
||||
GButton* create_button(const WindowIdentifier&);
|
||||
NonnullRefPtr<GButton> create_button(const WindowIdentifier&);
|
||||
|
||||
virtual void wm_event(GWMEvent&) override;
|
||||
};
|
||||
|
|
|
@ -15,7 +15,6 @@ public:
|
|||
|
||||
~Window()
|
||||
{
|
||||
delete m_button;
|
||||
}
|
||||
|
||||
WindowIdentifier identifier() const { return m_identifier; }
|
||||
|
@ -41,7 +40,7 @@ private:
|
|||
WindowIdentifier m_identifier;
|
||||
String m_title;
|
||||
Rect m_rect;
|
||||
GButton* m_button { nullptr };
|
||||
RefPtr<GButton> m_button;
|
||||
RefPtr<GraphicsBitmap> m_icon;
|
||||
bool m_active { false };
|
||||
bool m_minimized { false };
|
||||
|
@ -62,7 +61,7 @@ public:
|
|||
Window& ensure_window(const WindowIdentifier&);
|
||||
void remove_window(const WindowIdentifier&);
|
||||
|
||||
Function<GButton*(const WindowIdentifier&)> aid_create_button;
|
||||
Function<NonnullRefPtr<GButton>(const WindowIdentifier&)> aid_create_button;
|
||||
|
||||
private:
|
||||
HashMap<WindowIdentifier, NonnullOwnPtr<Window>> m_windows;
|
||||
|
|
|
@ -83,7 +83,7 @@ int main(int argc, char** argv)
|
|||
// header
|
||||
//
|
||||
|
||||
auto header = GLabel::construct(background);
|
||||
auto header = GLabel::construct(background.ptr());
|
||||
header->set_font(Font::default_bold_font());
|
||||
header->set_text("Welcome to Serenity");
|
||||
header->set_text_alignment(TextAlignment::CenterLeft);
|
||||
|
@ -94,13 +94,13 @@ int main(int argc, char** argv)
|
|||
// main section
|
||||
//
|
||||
|
||||
auto main_section = GWidget::construct(background);
|
||||
auto main_section = GWidget::construct(background.ptr());
|
||||
main_section->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
main_section->layout()->set_margins({ 0, 0, 0, 0 });
|
||||
main_section->layout()->set_spacing(8);
|
||||
main_section->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
|
||||
|
||||
auto menu = GWidget::construct(main_section);
|
||||
auto menu = GWidget::construct(main_section.ptr());
|
||||
menu->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
menu->layout()->set_margins({ 0, 0, 0, 0 });
|
||||
menu->layout()->set_spacing(8);
|
||||
|
@ -111,7 +111,7 @@ int main(int argc, char** argv)
|
|||
stack->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
|
||||
|
||||
for (auto& page : pages) {
|
||||
auto content = GWidget::construct(stack);
|
||||
auto content = GWidget::construct(stack.ptr());
|
||||
content->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
content->layout()->set_margins({ 0, 0, 0, 0 });
|
||||
content->layout()->set_spacing(8);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue