LibGUI: Convert GTextBox, GTextEditor and GResizeCorner to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-21 15:43:52 +02:00
parent 4ea229accd
commit 93851c3832
Notes: sideshowbarker 2024-07-19 12:02:16 +09:00
25 changed files with 38 additions and 36 deletions

View File

@ -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);

View File

@ -25,6 +25,6 @@ private:
Calculator m_calculator;
Keypad m_keypad;
GTextBox* m_entry { nullptr };
ObjectPtr<GTextBox> m_entry;
ObjectPtr<GLabel> m_label;
};

View File

@ -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);

View File

@ -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] {

View File

@ -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 };
};

View File

@ -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);

View File

@ -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;
};

View File

@ -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();

View File

@ -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 };

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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());

View File

@ -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 };

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;
};

View File

@ -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();
};

View File

@ -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;

View File

@ -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;

View File

@ -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 };

View File

@ -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()

View File

@ -18,5 +18,5 @@ private:
virtual void paint_event(GPaintEvent&) override;
ObjectPtr<GLabel> m_label;
GResizeCorner* m_corner { nullptr };
ObjectPtr<GResizeCorner> m_corner;
};

View File

@ -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();