mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:42:44 +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
				
			
		|  | @ -17,7 +17,7 @@ int main(int argc, char** argv) | |||
|     window->set_resizable(false); | ||||
|     window->set_rect(window_rect); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     window->set_main_widget(widget); | ||||
|     widget->set_fill_with_background_color(true); | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ int main(int argc, char** argv) | |||
|     window->set_rect(100, 100, 800, 500); | ||||
|     window->set_icon(load_png("/res/icons/16x16/app-chanviewer.png")); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     window->set_main_widget(widget); | ||||
|     widget->set_fill_with_background_color(true); | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|  |  | |||
|  | @ -75,7 +75,7 @@ void DisplayPropertiesWidget::create_resolution_list() | |||
| 
 | ||||
| void DisplayPropertiesWidget::create_root_widget() | ||||
| { | ||||
|     m_root_widget = new GWidget; | ||||
|     m_root_widget = GWidget::construct(); | ||||
|     m_root_widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     m_root_widget->set_fill_with_background_color(true); | ||||
|     m_root_widget->layout()->set_margins({ 4, 4, 4, 16 }); | ||||
|  | @ -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 = new GWidget(background_splitter); | ||||
|     auto background_content = GWidget::construct(background_splitter); | ||||
|     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 = new GWidget(settings_splitter); | ||||
|     auto settings_content = GWidget::construct(settings_splitter); | ||||
|     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 = new GWidget(m_root_widget); | ||||
|     auto bottom_widget = GWidget::construct(m_root_widget); | ||||
|     bottom_widget->set_layout(make<GBoxLayout>(Orientation::Horizontal)); | ||||
|     bottom_widget->layout()->add_spacer(); | ||||
|     bottom_widget->set_size_policy(Orientation::Vertical, SizePolicy::Fixed); | ||||
|  |  | |||
|  | @ -29,7 +29,8 @@ public: | |||
|     void send_settings_to_window_server(int tabIndex); | ||||
|     void create_frame(); | ||||
| 
 | ||||
|     inline GWidget* get_root_widget() const { return m_root_widget; } | ||||
|     const GWidget* root_widget() const { return m_root_widget; } | ||||
|     GWidget* root_widget() { return m_root_widget; } | ||||
| 
 | ||||
| private: | ||||
|     void create_wallpaper_list(); | ||||
|  | @ -39,7 +40,7 @@ private: | |||
| private: | ||||
|     String m_wallpaper_path; | ||||
|     RefPtr<CConfigFile> m_wm_config; | ||||
|     GWidget* m_root_widget { nullptr }; | ||||
|     ObjectPtr<GWidget> m_root_widget; | ||||
|     Vector<Size> m_resolutions; | ||||
|     Vector<String> m_wallpapers; | ||||
|     ObjectPtr<GLabel> m_wallpaper_preview; | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ int main(int argc, char** argv) | |||
|     window->set_title("Display Properties"); | ||||
|     window->resize(400, 448); | ||||
|     window->set_resizable(false); | ||||
|     window->set_main_widget(instance.get_root_widget()); | ||||
|     window->set_main_widget(instance.root_widget()); | ||||
|     window->set_icon(load_png("/res/icons/16x16/app-display-properties.png")); | ||||
| 
 | ||||
|     window->show(); | ||||
|  |  | |||
|  | @ -44,7 +44,7 @@ int main(int argc, char** argv) | |||
|     window->set_title("File Manager"); | ||||
|     window->set_rect(20, 200, 640, 480); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     widget->layout()->set_spacing(0); | ||||
| 
 | ||||
|  |  | |||
|  | @ -153,7 +153,7 @@ void IRCAppWindow::setup_menus() | |||
| 
 | ||||
| void IRCAppWindow::setup_widgets() | ||||
| { | ||||
|     auto* widget = new GWidget(nullptr); | ||||
|     auto widget = GWidget::construct(); | ||||
|     set_main_widget(widget); | ||||
|     widget->set_fill_with_background_color(true); | ||||
|     widget->set_background_color(Color::WarmGray); | ||||
|  | @ -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 = new GWidget(widget); | ||||
|     auto outer_container = GWidget::construct(widget); | ||||
|     outer_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     outer_container->layout()->set_margins({ 2, 0, 2, 2 }); | ||||
| 
 | ||||
|  |  | |||
|  | @ -75,7 +75,7 @@ GWindow* make_launcher_window() | |||
|     window->set_show_titlebar(false); | ||||
|     window->set_window_type(GWindowType::Launcher); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     widget->set_fill_with_background_color(true); | ||||
|     widget->set_layout(make<GBoxLayout>(vertical ? Orientation::Vertical : Orientation::Horizontal)); | ||||
|     widget->layout()->set_spacing(0); | ||||
|  |  | |||
|  | @ -19,16 +19,16 @@ ColorDialog::~ColorDialog() | |||
| 
 | ||||
| void ColorDialog::build() | ||||
| { | ||||
|     auto* horizontal_container = new GWidget; | ||||
|     auto horizontal_container = GWidget::construct(); | ||||
|     horizontal_container->set_fill_with_background_color(true); | ||||
|     horizontal_container->set_layout(make<GBoxLayout>(Orientation::Horizontal)); | ||||
|     horizontal_container->layout()->set_margins({ 4, 4, 4, 4 }); | ||||
|     set_main_widget(horizontal_container); | ||||
| 
 | ||||
|     auto* left_vertical_container = new GWidget(horizontal_container); | ||||
|     auto left_vertical_container = GWidget::construct(horizontal_container); | ||||
|     left_vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
| 
 | ||||
|     auto* right_vertical_container = new GWidget(horizontal_container); | ||||
|     auto right_vertical_container = GWidget::construct(horizontal_container); | ||||
|     right_vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
| 
 | ||||
|     enum RGBComponent { | ||||
|  |  | |||
|  | @ -81,16 +81,16 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent) | |||
|         set_secondary_color(color); | ||||
|     }; | ||||
| 
 | ||||
|     auto* color_container = new GWidget(this); | ||||
|     auto color_container = GWidget::construct(this); | ||||
|     color_container->set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32); | ||||
|     color_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     color_container->layout()->set_spacing(1); | ||||
| 
 | ||||
|     auto* top_color_container = new GWidget(color_container); | ||||
|     auto top_color_container = GWidget::construct(color_container); | ||||
|     top_color_container->set_layout(make<GBoxLayout>(Orientation::Horizontal)); | ||||
|     top_color_container->layout()->set_spacing(1); | ||||
| 
 | ||||
|     auto* bottom_color_container = new GWidget(color_container); | ||||
|     auto bottom_color_container = GWidget::construct(color_container); | ||||
|     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 = new GWidget(nullptr); | ||||
|     auto horizontal_container = GWidget::construct(nullptr); | ||||
|     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 = new GWidget(horizontal_container); | ||||
|     auto vertical_container = GWidget::construct(horizontal_container); | ||||
|     vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     vertical_container->layout()->set_spacing(0); | ||||
| 
 | ||||
|  |  | |||
|  | @ -34,7 +34,7 @@ int main(int argc, char** argv) | |||
|     window->set_title("SoundPlayer"); | ||||
|     window->set_rect(300, 300, 300, 200); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     window->set_main_widget(widget); | ||||
| 
 | ||||
|     widget->set_fill_with_background_color(true); | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GWidget* parent) | |||
|     layout()->set_spacing(3); | ||||
| 
 | ||||
|     auto build_widgets_for_label = [this](const String& description) -> ObjectPtr<GLabel> { | ||||
|         auto* container = new GWidget(this); | ||||
|         auto container = GWidget::construct(this); | ||||
|         container->set_layout(make<GBoxLayout>(Orientation::Horizontal)); | ||||
|         container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); | ||||
|         container->set_preferred_size(275, 12); | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ int main(int argc, char** argv) | |||
| { | ||||
|     GApplication app(argc, argv); | ||||
| 
 | ||||
|     auto* keeper = new GWidget; | ||||
|     auto keeper = GWidget::construct(); | ||||
|     keeper->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     keeper->set_fill_with_background_color(true); | ||||
|     keeper->set_background_color(Color::WarmGray); | ||||
|  | @ -58,9 +58,9 @@ 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 = new GWidget(process_container_splitter); | ||||
|     auto process_table_container = GWidget::construct(process_container_splitter); | ||||
| 
 | ||||
|     auto* graphs_container = new GWidget; | ||||
|     auto graphs_container = GWidget::construct(); | ||||
|     graphs_container->set_fill_with_background_color(true); | ||||
|     graphs_container->set_background_color(Color::WarmGray); | ||||
|     graphs_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|  | @ -236,7 +236,7 @@ public: | |||
| 
 | ||||
| GWidget* build_file_systems_tab() | ||||
| { | ||||
|     auto* fs_widget = new GWidget(nullptr); | ||||
|     auto fs_widget = GWidget::construct(); | ||||
|     fs_widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     fs_widget->layout()->set_margins({ 4, 4, 4, 4 }); | ||||
|     auto fs_table_view = GTableView::construct(fs_widget); | ||||
|  | @ -301,7 +301,7 @@ GWidget* build_file_systems_tab() | |||
| 
 | ||||
| GWidget* build_pci_devices_tab() | ||||
| { | ||||
|     auto* pci_widget = new GWidget(nullptr); | ||||
|     auto pci_widget = GWidget::construct(nullptr); | ||||
|     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); | ||||
|  | @ -355,7 +355,7 @@ GWidget* build_pci_devices_tab() | |||
| 
 | ||||
| GWidget* build_devices_tab() | ||||
| { | ||||
|     auto* devices_widget = new GWidget(nullptr); | ||||
|     auto devices_widget = GWidget::construct(); | ||||
|     devices_widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     devices_widget->layout()->set_margins({ 4, 4, 4, 4 }); | ||||
| 
 | ||||
|  |  | |||
|  | @ -94,7 +94,7 @@ GWindow* create_settings_window(TerminalWidget& terminal, RefPtr<CConfigFile> co | |||
|     window->set_title("Terminal Settings"); | ||||
|     window->set_rect(50, 50, 200, 140); | ||||
| 
 | ||||
|     auto* settings = new GWidget; | ||||
|     auto settings = GWidget::construct(); | ||||
|     window->set_main_widget(settings); | ||||
|     settings->set_fill_with_background_color(true); | ||||
|     settings->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|  |  | |||
|  | @ -34,7 +34,7 @@ TextEditorWidget::TextEditorWidget() | |||
|             update_title(); | ||||
|     }; | ||||
| 
 | ||||
|     m_find_widget = new GWidget(this); | ||||
|     m_find_widget = GWidget::construct(this); | ||||
|     m_find_widget->set_fill_with_background_color(true); | ||||
|     m_find_widget->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); | ||||
|     m_find_widget->set_preferred_size(0, 22); | ||||
|  |  | |||
|  | @ -41,7 +41,7 @@ private: | |||
|     ObjectPtr<GTextBox> m_find_textbox; | ||||
|     GButton* m_find_previous_button { nullptr }; | ||||
|     GButton* m_find_next_button { nullptr }; | ||||
|     GWidget* m_find_widget { nullptr }; | ||||
|     ObjectPtr<GWidget> m_find_widget; | ||||
| 
 | ||||
|     bool m_document_dirty { false }; | ||||
| }; | ||||
|  |  | |||
|  | @ -94,13 +94,13 @@ int main(int argc, char** argv) | |||
|     // main section
 | ||||
|     //
 | ||||
| 
 | ||||
|     auto* main_section = new GWidget(background); | ||||
|     auto main_section = GWidget::construct(background); | ||||
|     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 = new GWidget(main_section); | ||||
|     auto menu = GWidget::construct(main_section); | ||||
|     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 = new GWidget(stack); | ||||
|         auto content = GWidget::construct(stack); | ||||
|         content->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|         content->layout()->set_margins({ 0, 0, 0, 0 }); | ||||
|         content->layout()->set_spacing(8); | ||||
|  | @ -139,7 +139,7 @@ int main(int argc, char** argv) | |||
|         menu_option->set_text_alignment(TextAlignment::CenterLeft); | ||||
|         menu_option->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); | ||||
|         menu_option->set_preferred_size(0, 20); | ||||
|         menu_option->on_click = [stack, content](GButton&) { | ||||
|         menu_option->on_click = [&](auto&) { | ||||
|             stack->set_active_widget(content); | ||||
|             content->invalidate_layout(); | ||||
|         }; | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ int main(int argc, char** argv) | |||
|     window->set_rect(100, 100, 240, 160); | ||||
|     window->set_title("Hello World!"); | ||||
| 
 | ||||
|     auto* main_widget = new GWidget; | ||||
|     auto main_widget = GWidget::construct(); | ||||
|     window->set_main_widget(main_widget); | ||||
|     main_widget->set_fill_with_background_color(true); | ||||
|     main_widget->set_background_color(Color::White); | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ int main(int argc, char** argv) | |||
|     window->set_rect(100, 100, 320, 620); | ||||
|     window->set_title("Widget Gallery"); | ||||
| 
 | ||||
|     auto* main_widget = new GWidget; | ||||
|     auto main_widget = GWidget::construct(); | ||||
|     window->set_main_widget(main_widget); | ||||
|     main_widget->set_fill_with_background_color(true); | ||||
|     main_widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|  | @ -66,7 +66,7 @@ int main(int argc, char** argv) | |||
|     auto spinbox2 = GSpinBox::construct(main_widget); | ||||
|     spinbox2->set_enabled(false); | ||||
| 
 | ||||
|     auto* vertical_slider_container = new GWidget(main_widget); | ||||
|     auto vertical_slider_container = GWidget::construct(main_widget); | ||||
|     vertical_slider_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); | ||||
|     vertical_slider_container->set_preferred_size(0, 100); | ||||
|     vertical_slider_container->set_layout(make<GBoxLayout>(Orientation::Horizontal)); | ||||
|  |  | |||
|  | @ -32,7 +32,7 @@ int main(int argc, char** argv) | |||
|     window->set_title("Inspector"); | ||||
|     window->set_rect(150, 150, 300, 500); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     window->set_main_widget(widget); | ||||
|     widget->set_fill_with_background_color(true); | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|  |  | |||
|  | @ -55,7 +55,7 @@ VBPropertiesWindow::VBPropertiesWindow() | |||
|     set_title("Properties"); | ||||
|     set_rect(780, 200, 240, 280); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     widget->set_fill_with_background_color(true); | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     widget->layout()->set_margins({ 2, 2, 2, 2 }); | ||||
|  |  | |||
|  | @ -30,7 +30,7 @@ VBWidget::~VBWidget() | |||
| { | ||||
|     m_form.m_gwidget_map.remove(m_gwidget); | ||||
|     m_form.m_selected_widgets.remove(this); | ||||
|     delete m_gwidget; | ||||
|     m_gwidget->parent()->remove_child(*m_gwidget); | ||||
| } | ||||
| 
 | ||||
| Rect VBWidget::rect() const | ||||
|  |  | |||
|  | @ -8,10 +8,10 @@ | |||
| #include <AK/RefCounted.h> | ||||
| #include <AK/Weakable.h> | ||||
| #include <LibDraw/Rect.h> | ||||
| #include <LibGUI/GWidget.h> | ||||
| 
 | ||||
| class GPainter; | ||||
| class GVariant; | ||||
| class GWidget; | ||||
| class VBForm; | ||||
| class VBProperty; | ||||
| class VBWidgetPropertyModel; | ||||
|  | @ -81,7 +81,7 @@ private: | |||
| 
 | ||||
|     VBWidgetType m_type { VBWidgetType::None }; | ||||
|     VBForm& m_form; | ||||
|     GWidget* m_gwidget { nullptr }; | ||||
|     ObjectPtr<GWidget> m_gwidget; | ||||
|     NonnullOwnPtrVector<VBProperty> m_properties; | ||||
|     NonnullRefPtr<VBWidgetPropertyModel> m_property_model; | ||||
|     Rect m_transform_origin_rect; | ||||
|  |  | |||
|  | @ -68,11 +68,11 @@ VBWidgetType widget_type_from_class_name(const StringView& name) | |||
|     ASSERT_NOT_REACHED(); | ||||
| } | ||||
| 
 | ||||
| static GWidget* build_gwidget(VBWidgetType type, GWidget* parent) | ||||
| static ObjectPtr<GWidget> build_gwidget(VBWidgetType type, GWidget* parent) | ||||
| { | ||||
|     switch (type) { | ||||
|     case VBWidgetType::GWidget: | ||||
|         return new GWidget(parent); | ||||
|         return GWidget::construct(parent); | ||||
|     case VBWidgetType::GScrollBar: | ||||
|         return GScrollBar::construct(Orientation::Vertical, parent); | ||||
|     case VBWidgetType::GGroupBox: | ||||
|  | @ -113,21 +113,21 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent) | |||
|         return slider; | ||||
|     } | ||||
|     case VBWidgetType::GCheckBox: { | ||||
|         auto* box = new GCheckBox(parent); | ||||
|         auto box = GCheckBox::construct(parent); | ||||
|         box->set_text("checkbox_1"); | ||||
|         return box; | ||||
|     } | ||||
|     case VBWidgetType::GRadioButton: | ||||
|         return new GRadioButton("radio_1", parent); | ||||
|         return GRadioButton::construct("radio_1", parent); | ||||
|     default: | ||||
|         ASSERT_NOT_REACHED(); | ||||
|         return nullptr; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| GWidget* VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, NonnullOwnPtrVector<VBProperty>& properties) | ||||
| ObjectPtr<GWidget> VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, NonnullOwnPtrVector<VBProperty>& properties) | ||||
| { | ||||
|     auto* gwidget = ::build_gwidget(type, parent); | ||||
|     auto gwidget = ::build_gwidget(type, parent); | ||||
|     auto add_readonly_property = [&](const String& name, const GVariant& value) { | ||||
|         auto property = make<VBProperty>(widget, name, value); | ||||
|         property->set_readonly(true); | ||||
|  |  | |||
|  | @ -1,12 +1,12 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include "VBWidgetType.h" | ||||
| #include <AK/String.h> | ||||
| #include <AK/HashMap.h> | ||||
| #include <AK/NonnullOwnPtrVector.h> | ||||
| #include <AK/OwnPtr.h> | ||||
| #include <AK/String.h> | ||||
| #include <LibGUI/GWidget.h> | ||||
| 
 | ||||
| class GWidget; | ||||
| class VBProperty; | ||||
| class VBWidget; | ||||
| 
 | ||||
|  | @ -19,7 +19,7 @@ public: | |||
|             callback((VBWidgetType)i); | ||||
|     } | ||||
| 
 | ||||
|     static GWidget* build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, NonnullOwnPtrVector<VBProperty>&); | ||||
|     static ObjectPtr<GWidget> build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, NonnullOwnPtrVector<VBProperty>&); | ||||
| }; | ||||
| 
 | ||||
| String to_class_name(VBWidgetType); | ||||
|  |  | |||
|  | @ -80,7 +80,7 @@ GWindow* make_toolbox_window() | |||
|     window->set_title("Widgets"); | ||||
|     window->set_rect(20, 200, 80, 300); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     widget->set_fill_with_background_color(true); | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     widget->layout()->set_spacing(0); | ||||
|  |  | |||
|  | @ -19,12 +19,12 @@ int main(int argc, char** argv) | |||
|     window->set_title("Minesweeper"); | ||||
|     window->set_rect(100, 100, 139, 175); | ||||
| 
 | ||||
|     auto* widget = new GWidget; | ||||
|     auto widget = GWidget::construct(); | ||||
|     window->set_main_widget(widget); | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
|     widget->layout()->set_spacing(0); | ||||
| 
 | ||||
|     auto* container = new GWidget(widget); | ||||
|     auto container = GWidget::construct(widget); | ||||
|     container->set_fill_with_background_color(true); | ||||
|     container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); | ||||
|     container->set_preferred_size(0, 36); | ||||
|  |  | |||
|  | @ -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
	
	 Andreas Kling
						Andreas Kling