diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 15:43:52 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 15:46:47 +0200 |
commit | 93851c3832bb59259309ede0465be056a706df3e (patch) | |
tree | 4157375673d1b839ea5a84409bd22204744c89da | |
parent | 4ea229accdac70e418af8f3f6d57cb5797d5dfad (diff) | |
download | serenity-93851c3832bb59259309ede0465be056a706df3e.zip |
LibGUI: Convert GTextBox, GTextEditor and GResizeCorner to ObjectPtr
25 files changed, 38 insertions, 36 deletions
diff --git a/Applications/Calculator/CalculatorWidget.cpp b/Applications/Calculator/CalculatorWidget.cpp index 3d7e5ffa72..8b889024d3 100644 --- a/Applications/Calculator/CalculatorWidget.cpp +++ b/Applications/Calculator/CalculatorWidget.cpp @@ -9,7 +9,7 @@ CalculatorWidget::CalculatorWidget(GWidget* parent) { set_fill_with_background_color(true); - m_entry = new GTextBox(this); + m_entry = GTextBox::construct(this); m_entry->set_relative_rect(5, 5, 244, 26); m_entry->set_text_alignment(TextAlignment::CenterRight); diff --git a/Applications/Calculator/CalculatorWidget.h b/Applications/Calculator/CalculatorWidget.h index e167030cf8..a0b126595f 100644 --- a/Applications/Calculator/CalculatorWidget.h +++ b/Applications/Calculator/CalculatorWidget.h @@ -25,6 +25,6 @@ private: Calculator m_calculator; Keypad m_keypad; - GTextBox* m_entry { nullptr }; + ObjectPtr<GTextBox> m_entry; ObjectPtr<GLabel> m_label; }; diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index a89a5b5abf..53caad0a20 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) auto location_label = GLabel::construct("Location: ", location_toolbar); location_label->size_to_fit(); - auto* location_textbox = new GTextEditor(GTextEditor::SingleLine, location_toolbar); + auto location_textbox = GTextEditor::construct(GTextEditor::SingleLine, location_toolbar); auto* splitter = new GSplitter(Orientation::Horizontal, widget); auto* tree_view = new GTreeView(splitter); @@ -312,7 +312,7 @@ int main(int argc, char** argv) main_toolbar->add_action(*view_as_icons_action); main_toolbar->add_action(*view_as_table_action); - directory_view->on_path_change = [window, location_textbox, &file_system_model, tree_view, &go_forward_action, &go_back_action, directory_view](const String& new_path) { + directory_view->on_path_change = [&](const String& new_path) { window->set_title(String::format("File Manager: %s", new_path.characters())); location_textbox->set_text(new_path); auto new_index = file_system_model->index(new_path); diff --git a/Applications/IRCClient/IRCWindow.cpp b/Applications/IRCClient/IRCWindow.cpp index dcf011ad8e..6fa0de4c42 100644 --- a/Applications/IRCClient/IRCWindow.cpp +++ b/Applications/IRCClient/IRCWindow.cpp @@ -41,7 +41,7 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na member_view->set_activates_on_selection(true); } - m_text_editor = new GTextEditor(GTextEditor::SingleLine, this); + m_text_editor = GTextEditor::construct(GTextEditor::SingleLine, this); m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); m_text_editor->set_preferred_size(0, 19); m_text_editor->on_return_pressed = [this] { diff --git a/Applications/IRCClient/IRCWindow.h b/Applications/IRCClient/IRCWindow.h index 1e3e4b6227..297463c982 100644 --- a/Applications/IRCClient/IRCWindow.h +++ b/Applications/IRCClient/IRCWindow.h @@ -47,7 +47,7 @@ private: Type m_type; String m_name; GTableView* m_table_view { nullptr }; - GTextEditor* m_text_editor { nullptr }; + ObjectPtr<GTextEditor> m_text_editor; RefPtr<IRCLogBuffer> m_log_buffer; int m_unread_count { 0 }; }; diff --git a/Applications/SystemMonitor/ProcessStacksWidget.cpp b/Applications/SystemMonitor/ProcessStacksWidget.cpp index 6c52dfd8b1..d9f28322d7 100644 --- a/Applications/SystemMonitor/ProcessStacksWidget.cpp +++ b/Applications/SystemMonitor/ProcessStacksWidget.cpp @@ -8,7 +8,7 @@ ProcessStacksWidget::ProcessStacksWidget(GWidget* parent) { set_layout(make<GBoxLayout>(Orientation::Vertical)); layout()->set_margins({ 4, 4, 4, 4 }); - m_stacks_editor = new GTextEditor(GTextEditor::Type::MultiLine, this); + m_stacks_editor = GTextEditor::construct(GTextEditor::Type::MultiLine, this); m_stacks_editor->set_readonly(true); m_timer = CTimer::create(1000, [this] { refresh(); }, this); diff --git a/Applications/SystemMonitor/ProcessStacksWidget.h b/Applications/SystemMonitor/ProcessStacksWidget.h index fb7cac94dd..1779d1498d 100644 --- a/Applications/SystemMonitor/ProcessStacksWidget.h +++ b/Applications/SystemMonitor/ProcessStacksWidget.h @@ -17,6 +17,6 @@ public: private: pid_t m_pid { -1 }; - GTextEditor* m_stacks_editor { nullptr }; + ObjectPtr<GTextEditor> m_stacks_editor; ObjectPtr<CTimer> m_timer; }; diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index 05f72be383..c98fc39d32 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -22,7 +22,7 @@ TextEditorWidget::TextEditorWidget() layout()->set_spacing(0); auto* toolbar = new GToolBar(this); - m_editor = new GTextEditor(GTextEditor::MultiLine, this); + m_editor = GTextEditor::construct(GTextEditor::MultiLine, this); m_editor->set_ruler_visible(true); m_editor->set_automatic_indentation_enabled(true); m_editor->set_line_wrapping_enabled(true); @@ -42,7 +42,7 @@ TextEditorWidget::TextEditorWidget() m_find_widget->layout()->set_margins({ 2, 2, 2, 2 }); m_find_widget->set_visible(false); - m_find_textbox = new GTextBox(m_find_widget); + m_find_textbox = GTextBox::construct(m_find_widget); m_find_next_action = GAction::create("Find next", { Mod_Ctrl, Key_G }, [&](auto&) { auto needle = m_find_textbox->text(); diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h index aafc6c8367..304f92a31e 100644 --- a/Applications/TextEditor/TextEditorWidget.h +++ b/Applications/TextEditor/TextEditorWidget.h @@ -22,7 +22,7 @@ private: void set_path(const FileSystemPath& file); void update_title(); - GTextEditor* m_editor { nullptr }; + ObjectPtr<GTextEditor> m_editor; String m_path; String m_name; String m_extension; @@ -35,7 +35,7 @@ private: RefPtr<GAction> m_find_next_action; RefPtr<GAction> m_find_previous_action; - GTextBox* m_find_textbox { nullptr }; + ObjectPtr<GTextBox> m_find_textbox; GButton* m_find_previous_button { nullptr }; GButton* m_find_next_button { nullptr }; GWidget* m_find_widget { nullptr }; diff --git a/Demos/WidgetGallery/main.cpp b/Demos/WidgetGallery/main.cpp index 0e1c8c89c8..f26372ed22 100755 --- a/Demos/WidgetGallery/main.cpp +++ b/Demos/WidgetGallery/main.cpp @@ -55,9 +55,9 @@ int main(int argc, char** argv) auto label2 = GLabel::construct("GLabel 2", main_widget); label2->set_enabled(false); - auto* textbox1 = new GTextBox(main_widget); + auto textbox1 = new GTextBox(main_widget); textbox1->set_text("GTextBox 1"); - auto* textbox2 = new GTextBox(main_widget); + auto textbox2 = new GTextBox(main_widget); textbox2->set_text("GTextBox 2"); textbox2->set_enabled(false); diff --git a/DevTools/VisualBuilder/VBPropertiesWindow.cpp b/DevTools/VisualBuilder/VBPropertiesWindow.cpp index b167fa5857..3a235b9479 100644 --- a/DevTools/VisualBuilder/VBPropertiesWindow.cpp +++ b/DevTools/VisualBuilder/VBPropertiesWindow.cpp @@ -31,7 +31,7 @@ public: BoolModelEditingDelegate() {} virtual ~BoolModelEditingDelegate() override {} - virtual GWidget* create_widget() override + virtual ObjectPtr<GWidget> create_widget() override { auto* combo = new GComboBox(nullptr); combo->set_only_allow_values_from_model(true); diff --git a/DevTools/VisualBuilder/VBWidgetRegistry.cpp b/DevTools/VisualBuilder/VBWidgetRegistry.cpp index 678bf64f28..341e3b0180 100644 --- a/DevTools/VisualBuilder/VBWidgetRegistry.cpp +++ b/DevTools/VisualBuilder/VBWidgetRegistry.cpp @@ -95,7 +95,7 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent) return box; } case VBWidgetType::GTextEditor: { - auto* editor = new GTextEditor(GTextEditor::Type::MultiLine, parent); + auto editor = GTextEditor::construct(GTextEditor::Type::MultiLine, parent); editor->set_ruler_visible(false); return editor; } diff --git a/Libraries/LibGUI/GComboBox.cpp b/Libraries/LibGUI/GComboBox.cpp index 2210733381..e3d0585a18 100644 --- a/Libraries/LibGUI/GComboBox.cpp +++ b/Libraries/LibGUI/GComboBox.cpp @@ -9,7 +9,7 @@ GComboBox::GComboBox(GWidget* parent) : GWidget(parent) { - m_editor = new GTextEditor(GTextEditor::Type::SingleLine, this); + m_editor = GTextEditor::construct(GTextEditor::Type::SingleLine, this); m_editor->on_change = [this] { if (on_change) on_change(m_editor->text(), m_list_view->selection().first()); diff --git a/Libraries/LibGUI/GComboBox.h b/Libraries/LibGUI/GComboBox.h index 839566fe64..650a4e6102 100644 --- a/Libraries/LibGUI/GComboBox.h +++ b/Libraries/LibGUI/GComboBox.h @@ -36,7 +36,7 @@ protected: virtual void resize_event(GResizeEvent&) override; private: - GTextEditor* m_editor { nullptr }; + ObjectPtr<GTextEditor> m_editor; GButton* m_open_button { nullptr }; GWindow* m_list_window { nullptr }; GListView* m_list_view { nullptr }; diff --git a/Libraries/LibGUI/GFilePicker.cpp b/Libraries/LibGUI/GFilePicker.cpp index f827f1aa2c..7776f63179 100644 --- a/Libraries/LibGUI/GFilePicker.cpp +++ b/Libraries/LibGUI/GFilePicker.cpp @@ -72,7 +72,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie toolbar->set_preferred_size(85, 0); toolbar->set_has_frame(false); - auto* location_textbox = new GTextBox(upper_container); + auto location_textbox = GTextBox::construct(upper_container); location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); location_textbox->set_preferred_size(0, 20); @@ -132,7 +132,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie filename_label->set_text_alignment(TextAlignment::CenterLeft); filename_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); filename_label->set_preferred_size(60, 0); - m_filename_textbox = new GTextBox(filename_container); + m_filename_textbox = GTextBox::construct(filename_container); if (m_mode == Mode::Save) { m_filename_textbox->set_text(file_name); m_filename_textbox->set_focus(true); diff --git a/Libraries/LibGUI/GFilePicker.h b/Libraries/LibGUI/GFilePicker.h index edbf438afc..33bf05def1 100644 --- a/Libraries/LibGUI/GFilePicker.h +++ b/Libraries/LibGUI/GFilePicker.h @@ -46,7 +46,7 @@ private: NonnullRefPtr<GDirectoryModel> m_model; FileSystemPath m_selected_file; - GTextBox* m_filename_textbox { nullptr }; + ObjectPtr<GTextBox> m_filename_textbox; ObjectPtr<GLabel> m_preview_image_label; ObjectPtr<GLabel> m_preview_name_label; ObjectPtr<GLabel> m_preview_geometry_label; diff --git a/Libraries/LibGUI/GInputBox.cpp b/Libraries/LibGUI/GInputBox.cpp index cb75b12795..a14cf1970c 100644 --- a/Libraries/LibGUI/GInputBox.cpp +++ b/Libraries/LibGUI/GInputBox.cpp @@ -38,7 +38,7 @@ void GInputBox::build() label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); label->set_preferred_size(text_width, 16); - m_text_editor = new GTextEditor(GTextEditor::SingleLine, widget); + m_text_editor = GTextEditor::construct(GTextEditor::SingleLine, widget); m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); m_text_editor->set_preferred_size(0, 19); diff --git a/Libraries/LibGUI/GInputBox.h b/Libraries/LibGUI/GInputBox.h index f7a36bebf0..d921e6afd2 100644 --- a/Libraries/LibGUI/GInputBox.h +++ b/Libraries/LibGUI/GInputBox.h @@ -20,5 +20,5 @@ private: GButton* m_ok_button { nullptr }; GButton* m_cancel_button { nullptr }; - GTextEditor* m_text_editor { nullptr }; + ObjectPtr<GTextEditor> m_text_editor; }; diff --git a/Libraries/LibGUI/GModelEditingDelegate.h b/Libraries/LibGUI/GModelEditingDelegate.h index 5d1cb6194c..7214f9d1b6 100644 --- a/Libraries/LibGUI/GModelEditingDelegate.h +++ b/Libraries/LibGUI/GModelEditingDelegate.h @@ -15,7 +15,7 @@ public: return; m_model = model; m_index = index; - m_widget = create_widget()->make_weak_ptr(); + m_widget = create_widget(); } GWidget* widget() { return m_widget; } @@ -29,7 +29,7 @@ public: virtual void will_begin_editing() { } protected: - virtual GWidget* create_widget() = 0; + virtual ObjectPtr<GWidget> create_widget() = 0; void commit() { if (on_commit) @@ -39,7 +39,7 @@ protected: private: RefPtr<GModel> m_model; GModelIndex m_index; - WeakPtr<GWidget> m_widget; + ObjectPtr<GWidget> m_widget; }; class GStringModelEditingDelegate : public GModelEditingDelegate { @@ -47,9 +47,9 @@ public: GStringModelEditingDelegate() {} virtual ~GStringModelEditingDelegate() override {} - virtual GWidget* create_widget() override + virtual ObjectPtr<GWidget> create_widget() override { - auto* textbox = new GTextBox(nullptr); + auto textbox = GTextBox::construct(nullptr); textbox->on_return_pressed = [this] { commit(); }; diff --git a/Libraries/LibGUI/GResizeCorner.h b/Libraries/LibGUI/GResizeCorner.h index 2fd540363b..44b4057fc0 100644 --- a/Libraries/LibGUI/GResizeCorner.h +++ b/Libraries/LibGUI/GResizeCorner.h @@ -3,10 +3,11 @@ class GResizeCorner : public GWidget { C_OBJECT(GResizeCorner) public: - explicit GResizeCorner(GWidget* parent); virtual ~GResizeCorner() override; protected: + explicit GResizeCorner(GWidget* parent); + virtual void paint_event(GPaintEvent&) override; virtual void mousedown_event(GMouseEvent&) override; virtual void enter_event(CEvent&) override; diff --git a/Libraries/LibGUI/GSpinBox.cpp b/Libraries/LibGUI/GSpinBox.cpp index 35569d4e59..8c135ecd49 100644 --- a/Libraries/LibGUI/GSpinBox.cpp +++ b/Libraries/LibGUI/GSpinBox.cpp @@ -5,7 +5,7 @@ GSpinBox::GSpinBox(GWidget* parent) : GWidget(parent) { - m_editor = new GTextEditor(GTextEditor::Type::SingleLine, this); + m_editor = GTextEditor::construct(GTextEditor::Type::SingleLine, this); m_editor->set_text("0"); m_editor->on_change = [this] { bool ok; diff --git a/Libraries/LibGUI/GSpinBox.h b/Libraries/LibGUI/GSpinBox.h index d849c3c472..476e406cac 100644 --- a/Libraries/LibGUI/GSpinBox.h +++ b/Libraries/LibGUI/GSpinBox.h @@ -26,7 +26,7 @@ protected: virtual void resize_event(GResizeEvent&) override; private: - GTextEditor* m_editor { nullptr }; + ObjectPtr<GTextEditor> m_editor; GButton* m_increment_button { nullptr }; GButton* m_decrement_button { nullptr }; diff --git a/Libraries/LibGUI/GStatusBar.cpp b/Libraries/LibGUI/GStatusBar.cpp index 74a0bd56fb..f9813d1990 100644 --- a/Libraries/LibGUI/GStatusBar.cpp +++ b/Libraries/LibGUI/GStatusBar.cpp @@ -19,7 +19,7 @@ GStatusBar::GStatusBar(GWidget* parent) m_label->set_frame_thickness(1); m_label->set_text_alignment(TextAlignment::CenterLeft); - m_corner = new GResizeCorner(this); + m_corner = GResizeCorner::construct(this); } GStatusBar::~GStatusBar() diff --git a/Libraries/LibGUI/GStatusBar.h b/Libraries/LibGUI/GStatusBar.h index 1e0911540a..90d5f146a4 100644 --- a/Libraries/LibGUI/GStatusBar.h +++ b/Libraries/LibGUI/GStatusBar.h @@ -18,5 +18,5 @@ private: virtual void paint_event(GPaintEvent&) override; ObjectPtr<GLabel> m_label; - GResizeCorner* m_corner { nullptr }; + ObjectPtr<GResizeCorner> m_corner; }; diff --git a/Libraries/LibGUI/GTextEditor.h b/Libraries/LibGUI/GTextEditor.h index 023dc091c8..3caa350924 100644 --- a/Libraries/LibGUI/GTextEditor.h +++ b/Libraries/LibGUI/GTextEditor.h @@ -93,7 +93,6 @@ public: MultiLine, SingleLine }; - GTextEditor(Type, GWidget* parent); virtual ~GTextEditor() override; bool is_readonly() const { return m_readonly; } @@ -166,9 +165,9 @@ public: void add_custom_context_menu_action(GAction&); protected: - virtual void did_change_font() override; + GTextEditor(Type, GWidget* parent); -private: + virtual void did_change_font() override; virtual void paint_event(GPaintEvent&) override; virtual void mousedown_event(GMouseEvent&) override; virtual void mouseup_event(GMouseEvent&) override; @@ -184,6 +183,8 @@ private: virtual void context_menu_event(GContextMenuEvent&) override; virtual void resize_event(GResizeEvent&) override; +private: + void create_actions(); void paint_ruler(Painter&); void update_content_size(); |