diff --git a/Applications/About/main.cpp b/Applications/About/main.cpp index c948aea0f1..a559505cfc 100644 --- a/Applications/About/main.cpp +++ b/Applications/About/main.cpp @@ -24,12 +24,12 @@ int main(int argc, char** argv) widget->layout()->set_margins({ 0, 8, 0, 8 }); widget->layout()->set_spacing(8); - auto* icon_label = new GLabel(widget); + auto icon_label = GLabel::construct(widget); icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/serenity.png")); icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); icon_label->set_preferred_size(icon_label->icon()->size()); - auto* label = new GLabel(widget); + auto label = GLabel::construct(widget); label->set_font(Font::default_bold_font()); label->set_text("Serenity Operating System"); label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); @@ -39,7 +39,7 @@ int main(int argc, char** argv) int rc = uname(&uts); ASSERT(rc == 0); - auto* version_label = new GLabel(widget); + auto version_label = GLabel::construct(widget); version_label->set_text(String::format("Version %s", uts.release)); version_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); version_label->set_preferred_size(0, 11); diff --git a/Applications/Calculator/CalculatorWidget.cpp b/Applications/Calculator/CalculatorWidget.cpp index 38070cbe07..3d7e5ffa72 100644 --- a/Applications/Calculator/CalculatorWidget.cpp +++ b/Applications/Calculator/CalculatorWidget.cpp @@ -13,7 +13,7 @@ CalculatorWidget::CalculatorWidget(GWidget* parent) m_entry->set_relative_rect(5, 5, 244, 26); m_entry->set_text_alignment(TextAlignment::CenterRight); - m_label = new GLabel(this); + m_label = GLabel::construct(this); m_label->set_relative_rect(12, 42, 27, 27); m_label->set_foreground_color(Color::NamedColor::Red); m_label->set_frame_shadow(FrameShadow::Sunken); diff --git a/Applications/Calculator/CalculatorWidget.h b/Applications/Calculator/CalculatorWidget.h index 7ecfec5f0c..e167030cf8 100644 --- a/Applications/Calculator/CalculatorWidget.h +++ b/Applications/Calculator/CalculatorWidget.h @@ -26,5 +26,5 @@ private: Keypad m_keypad; GTextBox* m_entry { nullptr }; - GLabel* m_label { nullptr }; + ObjectPtr m_label; }; diff --git a/Applications/DisplayProperties/DisplayProperties.cpp b/Applications/DisplayProperties/DisplayProperties.cpp index 12046f5113..a21caba385 100644 --- a/Applications/DisplayProperties/DisplayProperties.cpp +++ b/Applications/DisplayProperties/DisplayProperties.cpp @@ -101,19 +101,19 @@ void DisplayPropertiesWidget::create_frame() background_content->set_layout(make(Orientation::Vertical)); background_content->layout()->set_margins({ 4, 4, 4, 4 }); - auto* wallpaper_preview = new GLabel(background_splitter); + m_wallpaper_preview = GLabel::construct(background_splitter); auto* wallpaper_list = new GListView(background_content); wallpaper_list->set_background_color(Color::White); wallpaper_list->set_model(*ItemListModel::create(m_wallpapers)); wallpaper_list->horizontal_scrollbar().set_visible(false); - wallpaper_list->on_selection = [this, wallpaper_preview](auto& index) { + wallpaper_list->on_selection = [this](auto& index) { StringBuilder builder; m_selected_wallpaper = m_wallpapers.at(index.row()); builder.append("/res/wallpapers/"); builder.append(m_selected_wallpaper); - wallpaper_preview->set_icon(load_png(builder.to_string())); - wallpaper_preview->set_should_stretch_icon(true); + m_wallpaper_preview->set_icon(load_png(builder.to_string())); + m_wallpaper_preview->set_should_stretch_icon(true); }; // Let's add the settings tab diff --git a/Applications/DisplayProperties/DisplayProperties.h b/Applications/DisplayProperties/DisplayProperties.h index c8c96988f1..afba1930cc 100644 --- a/Applications/DisplayProperties/DisplayProperties.h +++ b/Applications/DisplayProperties/DisplayProperties.h @@ -7,6 +7,7 @@ #include #include #include +#include class DisplayPropertiesWidget final { public: @@ -41,6 +42,7 @@ private: GWidget* m_root_widget { nullptr }; Vector m_resolutions; Vector m_wallpapers; + ObjectPtr m_wallpaper_preview; Size m_selected_resolution; String m_selected_wallpaper; diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index debf987652..a89a5b5abf 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv) location_toolbar->layout()->set_margins({ 6, 3, 6, 3 }); location_toolbar->set_preferred_size(0, 25); - auto* location_label = new GLabel("Location: ", location_toolbar); + auto location_label = GLabel::construct("Location: ", location_toolbar); location_label->size_to_fit(); auto* location_textbox = new GTextEditor(GTextEditor::SingleLine, location_toolbar); diff --git a/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Applications/SystemMonitor/MemoryStatsWidget.cpp index 6412dba161..b0d1331d61 100644 --- a/Applications/SystemMonitor/MemoryStatsWidget.cpp +++ b/Applications/SystemMonitor/MemoryStatsWidget.cpp @@ -22,15 +22,15 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GWidget* parent) layout()->set_margins({ 0, 8, 0, 0 }); layout()->set_spacing(3); - auto build_widgets_for_label = [this](const String& description) -> GLabel* { + auto build_widgets_for_label = [this](const String& description) -> ObjectPtr { auto* container = new GWidget(this); container->set_layout(make(Orientation::Horizontal)); container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); container->set_preferred_size(275, 12); - auto* description_label = new GLabel(description, container); + auto description_label = GLabel::construct(description, container); description_label->set_font(Font::default_bold_font()); description_label->set_text_alignment(TextAlignment::CenterLeft); - auto* label = new GLabel(container); + auto label = GLabel::construct(container); label->set_text_alignment(TextAlignment::CenterRight); return label; }; diff --git a/Applications/SystemMonitor/MemoryStatsWidget.h b/Applications/SystemMonitor/MemoryStatsWidget.h index e3912b9b94..a7b94ef2c6 100644 --- a/Applications/SystemMonitor/MemoryStatsWidget.h +++ b/Applications/SystemMonitor/MemoryStatsWidget.h @@ -17,9 +17,9 @@ private: virtual void timer_event(CTimerEvent&) override; GraphWidget& m_graph; - GLabel* m_user_physical_pages_label { nullptr }; - GLabel* m_supervisor_physical_pages_label { nullptr }; - GLabel* m_kmalloc_label { nullptr }; - GLabel* m_kmalloc_count_label { nullptr }; + ObjectPtr m_user_physical_pages_label; + ObjectPtr m_supervisor_physical_pages_label; + ObjectPtr m_kmalloc_label; + ObjectPtr m_kmalloc_count_label; CFile m_proc_memstat; }; diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp index 14a20e3d61..6e4bea273d 100644 --- a/Applications/Welcome/main.cpp +++ b/Applications/Welcome/main.cpp @@ -69,7 +69,7 @@ int main(int argc, char** argv) window->set_resizable(true); window->set_rect(window_rect); - auto* background = new GLabel; + auto background = GLabel::construct(); window->set_main_widget(background); background->set_fill_with_background_color(true); background->set_layout(make(Orientation::Vertical)); @@ -83,7 +83,7 @@ int main(int argc, char** argv) // header // - auto* header = new GLabel(background); + auto header = GLabel::construct(background); header->set_font(Font::default_bold_font()); header->set_text("Welcome to Serenity"); header->set_text_alignment(TextAlignment::CenterLeft); @@ -117,7 +117,7 @@ int main(int argc, char** argv) content->layout()->set_spacing(8); content->set_size_policy(SizePolicy::Fill, SizePolicy::Fill); - auto* content_title = new GLabel(content); + auto content_title = GLabel::construct(content); content_title->set_font(Font::default_bold_font()); content_title->set_text(page.title); content_title->set_text_alignment(TextAlignment::CenterLeft); diff --git a/Demos/Fire/Fire.cpp b/Demos/Fire/Fire.cpp index 92202d75a4..2714f40240 100644 --- a/Demos/Fire/Fire.cpp +++ b/Demos/Fire/Fire.cpp @@ -223,7 +223,7 @@ int main(int argc, char** argv) auto* fire = new Fire; window->set_main_widget(fire); - auto* time = new GLabel(fire); + auto time = GLabel::construct(fire); time->set_relative_rect({ 0, 4, 40, 10 }); time->move_by({ window->width() - time->width(), 0 }); time->set_foreground_color(Color::from_rgb(0x444444)); diff --git a/Demos/HelloWorld/main.cpp b/Demos/HelloWorld/main.cpp index 0bc320d9bd..6b06b9ed5b 100644 --- a/Demos/HelloWorld/main.cpp +++ b/Demos/HelloWorld/main.cpp @@ -20,7 +20,7 @@ int main(int argc, char** argv) main_widget->set_layout(make(Orientation::Vertical)); main_widget->layout()->set_margins({ 4, 4, 4, 4 }); - auto* label = new GLabel(main_widget); + auto label = GLabel::construct(main_widget); label->set_text("Hello\nWorld!"); auto* button = new GButton(main_widget); diff --git a/Demos/WidgetGallery/main.cpp b/Demos/WidgetGallery/main.cpp index 060a0d3f7c..5e08783485 100755 --- a/Demos/WidgetGallery/main.cpp +++ b/Demos/WidgetGallery/main.cpp @@ -50,9 +50,9 @@ int main(int argc, char** argv) progress1->set_value(progress1->min()); }); - auto* label1 = new GLabel("GLabel 1", main_widget); + auto label1 = GLabel::construct("GLabel 1", main_widget); (void)label1; - auto* label2 = new GLabel("GLabel 2", main_widget); + auto label2 = GLabel::construct("GLabel 2", main_widget); label2->set_enabled(false); auto* textbox1 = new GTextBox(main_widget); diff --git a/DevTools/VisualBuilder/VBWidgetRegistry.cpp b/DevTools/VisualBuilder/VBWidgetRegistry.cpp index 661d639a47..d310f7e1e9 100644 --- a/DevTools/VisualBuilder/VBWidgetRegistry.cpp +++ b/DevTools/VisualBuilder/VBWidgetRegistry.cpp @@ -78,7 +78,7 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent) case VBWidgetType::GGroupBox: return new GGroupBox("groupbox_1", parent); case VBWidgetType::GLabel: { - auto* label = new GLabel(parent); + auto label = GLabel::construct(parent); label->set_fill_with_background_color(true); label->set_text("label_1"); return label; diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp index 98e8991a45..8d6afb4883 100644 --- a/Games/Minesweeper/main.cpp +++ b/Games/Minesweeper/main.cpp @@ -29,16 +29,16 @@ int main(int argc, char** argv) container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); container->set_preferred_size(0, 36); container->set_layout(make(Orientation::Horizontal)); - auto* flag_icon_label = new GLabel(container); + auto flag_icon_label = GLabel::construct(container); flag_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/flag.png")); - auto* flag_label = new GLabel(container); + auto flag_label = GLabel::construct(container); auto* face_button = new GButton(container); face_button->set_button_style(ButtonStyle::CoolBar); face_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); face_button->set_preferred_size(36, 0); - auto* time_icon_label = new GLabel(container); + auto time_icon_label = GLabel::construct(container); time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png")); - auto* time_label = new GLabel(container); + auto time_label = GLabel::construct(container); auto* field = new Field(*flag_label, *time_label, *face_button, widget, [&](Size size) { size.set_height(size.height() + container->preferred_size().height()); window->resize(size); diff --git a/Libraries/LibGUI/GAboutDialog.cpp b/Libraries/LibGUI/GAboutDialog.cpp index 615c87bff2..e89f9447c3 100644 --- a/Libraries/LibGUI/GAboutDialog.cpp +++ b/Libraries/LibGUI/GAboutDialog.cpp @@ -22,7 +22,7 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C left_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); left_container->set_preferred_size(48, 0); left_container->set_layout(make(Orientation::Vertical)); - auto* icon_label = new GLabel(left_container); + auto icon_label = GLabel::construct(left_container); icon_label->set_icon(m_icon); icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); icon_label->set_preferred_size(40, 40); @@ -33,7 +33,7 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C right_container->layout()->set_margins({ 0, 4, 4, 4 }); auto make_label = [&](const StringView& text, bool bold = false) { - auto* label = new GLabel(text, right_container); + auto label = GLabel::construct(text, right_container); label->set_text_alignment(TextAlignment::CenterLeft); label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); label->set_preferred_size(0, 14); diff --git a/Libraries/LibGUI/GApplication.cpp b/Libraries/LibGUI/GApplication.cpp index eb7f930cd2..a2172fe552 100644 --- a/Libraries/LibGUI/GApplication.cpp +++ b/Libraries/LibGUI/GApplication.cpp @@ -75,7 +75,7 @@ public: TooltipWindow() { set_window_type(GWindowType::Tooltip); - m_label = new GLabel; + m_label = GLabel::construct(); m_label->set_background_color(Color::from_rgb(0xdac7b5)); m_label->set_fill_with_background_color(true); m_label->set_frame_thickness(1); @@ -92,7 +92,7 @@ public: m_label->set_text(tooltip); } - GLabel* m_label { nullptr }; + ObjectPtr m_label; }; void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_location) diff --git a/Libraries/LibGUI/GFilePicker.cpp b/Libraries/LibGUI/GFilePicker.cpp index e15b549d1f..f827f1aa2c 100644 --- a/Libraries/LibGUI/GFilePicker.cpp +++ b/Libraries/LibGUI/GFilePicker.cpp @@ -128,7 +128,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie filename_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); filename_container->set_preferred_size(0, 20); filename_container->set_layout(make(Orientation::Horizontal)); - auto* filename_label = new GLabel("File name:", filename_container); + auto filename_label = GLabel::construct("File name:", filename_container); filename_label->set_text_alignment(TextAlignment::CenterLeft); filename_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); filename_label->set_preferred_size(60, 0); @@ -201,17 +201,17 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie preview_container->set_layout(make(Orientation::Vertical)); preview_container->layout()->set_margins({ 8, 8, 8, 8 }); - m_preview_image_label = new GLabel(preview_container); + m_preview_image_label = GLabel::construct(preview_container); m_preview_image_label->set_should_stretch_icon(true); m_preview_image_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); m_preview_image_label->set_preferred_size(160, 160); - m_preview_name_label = new GLabel(preview_container); + m_preview_name_label = GLabel::construct(preview_container); m_preview_name_label->set_font(Font::default_bold_font()); m_preview_name_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); m_preview_name_label->set_preferred_size(0, m_preview_name_label->font().glyph_height()); - m_preview_geometry_label = new GLabel(preview_container); + m_preview_geometry_label = GLabel::construct(preview_container); m_preview_geometry_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); m_preview_geometry_label->set_preferred_size(0, m_preview_name_label->font().glyph_height()); } diff --git a/Libraries/LibGUI/GFilePicker.h b/Libraries/LibGUI/GFilePicker.h index 49546c4f61..edbf438afc 100644 --- a/Libraries/LibGUI/GFilePicker.h +++ b/Libraries/LibGUI/GFilePicker.h @@ -47,8 +47,8 @@ private: FileSystemPath m_selected_file; GTextBox* m_filename_textbox { nullptr }; - GLabel* m_preview_image_label { nullptr }; - GLabel* m_preview_name_label { nullptr }; - GLabel* m_preview_geometry_label { nullptr }; + ObjectPtr m_preview_image_label; + ObjectPtr m_preview_name_label; + ObjectPtr m_preview_geometry_label; Mode m_mode { Mode::Open }; }; diff --git a/Libraries/LibGUI/GInputBox.cpp b/Libraries/LibGUI/GInputBox.cpp index 39e7012522..cb75b12795 100644 --- a/Libraries/LibGUI/GInputBox.cpp +++ b/Libraries/LibGUI/GInputBox.cpp @@ -34,7 +34,7 @@ void GInputBox::build() widget->layout()->set_margins({ 8, 8, 8, 8 }); widget->layout()->set_spacing(8); - auto* label = new GLabel(m_prompt, widget); + auto label = GLabel::construct(m_prompt, widget); label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); label->set_preferred_size(text_width, 16); diff --git a/Libraries/LibGUI/GMessageBox.cpp b/Libraries/LibGUI/GMessageBox.cpp index 03cab4858f..be95447c2e 100644 --- a/Libraries/LibGUI/GMessageBox.cpp +++ b/Libraries/LibGUI/GMessageBox.cpp @@ -69,14 +69,14 @@ void GMessageBox::build() message_container->layout()->set_margins({ 8, 0, 8, 0 }); message_container->layout()->set_spacing(8); - auto* icon_label = new GLabel(message_container); + auto icon_label = GLabel::construct(message_container); icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); icon_label->set_preferred_size(32, 32); icon_label->set_icon(icon()); icon_width = icon_label->icon()->width(); } - auto* label = new GLabel(m_text, message_container); + auto label = GLabel::construct(m_text, message_container); label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); label->set_preferred_size(text_width, 16); diff --git a/Libraries/LibGUI/GStatusBar.cpp b/Libraries/LibGUI/GStatusBar.cpp index dfd24ab4b7..74a0bd56fb 100644 --- a/Libraries/LibGUI/GStatusBar.cpp +++ b/Libraries/LibGUI/GStatusBar.cpp @@ -13,7 +13,7 @@ GStatusBar::GStatusBar(GWidget* parent) set_layout(make(Orientation::Horizontal)); layout()->set_margins({ 2, 2, 2, 2 }); layout()->set_spacing(2); - m_label = new GLabel(this); + m_label = GLabel::construct(this); m_label->set_frame_shadow(FrameShadow::Sunken); m_label->set_frame_shape(FrameShape::Panel); m_label->set_frame_thickness(1); diff --git a/Libraries/LibGUI/GStatusBar.h b/Libraries/LibGUI/GStatusBar.h index 36f83b8609..1e0911540a 100644 --- a/Libraries/LibGUI/GStatusBar.h +++ b/Libraries/LibGUI/GStatusBar.h @@ -17,6 +17,6 @@ public: private: virtual void paint_event(GPaintEvent&) override; - GLabel* m_label { nullptr }; + ObjectPtr m_label; GResizeCorner* m_corner { nullptr }; };