diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-02 15:07:41 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-02 15:15:33 +0100 |
commit | c5bd9d4ed1d80ac91d46146565127b0c185f1b43 (patch) | |
tree | b4ee9ba5999778450f8eb4006df89110617b4a10 /Libraries | |
parent | 2d39da5405a4527e91e853ddb1e56a539c96c6c1 (diff) | |
download | serenity-c5bd9d4ed1d80ac91d46146565127b0c185f1b43.zip |
LibGUI: Put all classes in the GUI namespace and remove the leading G
This took me a moment. Welcome to the new world of GUI::Widget! :^)
Diffstat (limited to 'Libraries')
140 files changed, 3128 insertions, 2615 deletions
diff --git a/Libraries/LibDraw/Palette.h b/Libraries/LibDraw/Palette.h index c2a2680cb7..5c18c10263 100644 --- a/Libraries/LibDraw/Palette.h +++ b/Libraries/LibDraw/Palette.h @@ -30,7 +30,9 @@ #include <AK/Noncopyable.h> #include <LibDraw/SystemTheme.h> -class GApplication; +namespace GUI { +class Application; +} class PaletteImpl : public RefCounted<PaletteImpl> { AK_MAKE_NONCOPYABLE(PaletteImpl) @@ -42,7 +44,7 @@ public: Color color(ColorRole) const; const SystemTheme& theme() const; - void replace_internal_buffer(Badge<GApplication>, SharedBuffer& buffer) { m_theme_buffer = buffer; } + void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer) { m_theme_buffer = buffer; } private: explicit PaletteImpl(SharedBuffer&); diff --git a/Libraries/LibGUI/GAboutDialog.cpp b/Libraries/LibGUI/GAboutDialog.cpp index 8abdc56fb2..1de0402407 100644 --- a/Libraries/LibGUI/GAboutDialog.cpp +++ b/Libraries/LibGUI/GAboutDialog.cpp @@ -30,8 +30,10 @@ #include <LibGUI/GLabel.h> #include <LibGUI/GWidget.h> -GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, Core::Object* parent) - : GDialog(parent) +namespace GUI { + +AboutDialog::AboutDialog(const StringView& name, const GraphicsBitmap* icon, Core::Object* parent) + : Dialog(parent) , m_name(name) , m_icon(icon) { @@ -39,27 +41,27 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C set_title(String::format("About %s", m_name.characters())); set_resizable(false); - auto widget = GWidget::construct(); + auto widget = Widget::construct(); set_main_widget(widget); widget->set_fill_with_background_color(true); - widget->set_layout(make<GHBoxLayout>()); + widget->set_layout(make<HBoxLayout>()); - auto left_container = GWidget::construct(widget.ptr()); + auto left_container = Widget::construct(widget.ptr()); left_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); left_container->set_preferred_size(48, 0); - left_container->set_layout(make<GVBoxLayout>()); - auto icon_label = GLabel::construct(left_container); + left_container->set_layout(make<VBoxLayout>()); + auto icon_label = Label::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); left_container->layout()->add_spacer(); - auto right_container = GWidget::construct(widget.ptr()); - right_container->set_layout(make<GVBoxLayout>()); + auto right_container = Widget::construct(widget.ptr()); + right_container->set_layout(make<VBoxLayout>()); right_container->layout()->set_margins({ 0, 4, 4, 4 }); auto make_label = [&](const StringView& text, bool bold = false) { - auto label = GLabel::construct(text, right_container); + auto label = Label::construct(text, right_container); label->set_text_alignment(TextAlignment::CenterLeft); label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); label->set_preferred_size(0, 14); @@ -72,19 +74,21 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C right_container->layout()->add_spacer(); - auto button_container = GWidget::construct(right_container.ptr()); + auto button_container = Widget::construct(right_container.ptr()); button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); button_container->set_preferred_size(0, 20); - button_container->set_layout(make<GHBoxLayout>()); + button_container->set_layout(make<HBoxLayout>()); button_container->layout()->add_spacer(); - auto ok_button = GButton::construct("OK", button_container); + auto ok_button = Button::construct("OK", button_container); ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); ok_button->set_preferred_size(80, 20); ok_button->on_click = [this](auto&) { - done(GDialog::ExecOK); + done(Dialog::ExecOK); }; } -GAboutDialog::~GAboutDialog() +AboutDialog::~AboutDialog() { } + +} diff --git a/Libraries/LibGUI/GAboutDialog.h b/Libraries/LibGUI/GAboutDialog.h index e355d0355e..601ca95bc3 100644 --- a/Libraries/LibGUI/GAboutDialog.h +++ b/Libraries/LibGUI/GAboutDialog.h @@ -28,20 +28,23 @@ #include <LibGUI/GDialog.h> -class GAboutDialog final : public GDialog { - C_OBJECT(GAboutDialog) +namespace GUI { + +class AboutDialog final : public Dialog { + C_OBJECT(AboutDialog) public: - virtual ~GAboutDialog() override; + virtual ~AboutDialog() override; static void show(const StringView& name, const GraphicsBitmap* icon = nullptr, Core::Object* parent = nullptr) { - auto dialog = GAboutDialog::construct(name, icon, parent); + auto dialog = AboutDialog::construct(name, icon, parent); dialog->exec(); } private: - GAboutDialog(const StringView& name, const GraphicsBitmap* icon = nullptr, Core::Object* parent = nullptr); + AboutDialog(const StringView& name, const GraphicsBitmap* icon = nullptr, Core::Object* parent = nullptr); String m_name; RefPtr<GraphicsBitmap> m_icon; }; +} diff --git a/Libraries/LibGUI/GAbstractButton.cpp b/Libraries/LibGUI/GAbstractButton.cpp index 68bd12fb84..0196f2ee12 100644 --- a/Libraries/LibGUI/GAbstractButton.cpp +++ b/Libraries/LibGUI/GAbstractButton.cpp @@ -28,13 +28,15 @@ #include <LibGUI/GAbstractButton.h> #include <LibGUI/GPainter.h> -GAbstractButton::GAbstractButton(GWidget* parent) - : GAbstractButton({}, parent) +namespace GUI { + +AbstractButton::AbstractButton(Widget* parent) + : AbstractButton({}, parent) { } -GAbstractButton::GAbstractButton(const StringView& text, GWidget* parent) - : GWidget(parent) +AbstractButton::AbstractButton(const StringView& text, Widget* parent) + : Widget(parent) , m_text(text) { m_auto_repeat_timer = Core::Timer::construct(this); @@ -43,11 +45,11 @@ GAbstractButton::GAbstractButton(const StringView& text, GWidget* parent) }; } -GAbstractButton::~GAbstractButton() +AbstractButton::~AbstractButton() { } -void GAbstractButton::set_text(const StringView& text) +void AbstractButton::set_text(const StringView& text) { if (m_text == text) return; @@ -55,14 +57,14 @@ void GAbstractButton::set_text(const StringView& text) update(); } -void GAbstractButton::set_checked(bool checked) +void AbstractButton::set_checked(bool checked) { if (m_checked == checked) return; m_checked = checked; if (is_exclusive() && checked) { - parent_widget()->for_each_child_of_type<GAbstractButton>([&](auto& sibling) { + parent_widget()->for_each_child_of_type<AbstractButton>([&](auto& sibling) { if (!sibling.is_exclusive() || !sibling.is_checked()) return IterationDecision::Continue; sibling.m_checked = false; @@ -79,7 +81,7 @@ void GAbstractButton::set_checked(bool checked) on_checked(checked); } -void GAbstractButton::set_checkable(bool checkable) +void AbstractButton::set_checkable(bool checkable) { if (m_checkable == checkable) return; @@ -87,11 +89,11 @@ void GAbstractButton::set_checkable(bool checkable) update(); } -void GAbstractButton::mousemove_event(GMouseEvent& event) +void AbstractButton::mousemove_event(MouseEvent& event) { bool is_over = rect().contains(event.position()); m_hovered = is_over; - if (event.buttons() & GMouseButton::Left) { + if (event.buttons() & MouseButton::Left) { if (is_enabled()) { bool being_pressed = is_over; if (being_pressed != m_being_pressed) { @@ -106,15 +108,15 @@ void GAbstractButton::mousemove_event(GMouseEvent& event) } } } - GWidget::mousemove_event(event); + Widget::mousemove_event(event); } -void GAbstractButton::mousedown_event(GMouseEvent& event) +void AbstractButton::mousedown_event(MouseEvent& event) { #ifdef GABSTRACTBUTTON_DEBUG - dbgprintf("GAbstractButton::mouse_down_event: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); + dbgprintf("AbstractButton::mouse_down_event: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); #endif - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { if (is_enabled()) { m_being_pressed = true; update(); @@ -125,15 +127,15 @@ void GAbstractButton::mousedown_event(GMouseEvent& event) } } } - GWidget::mousedown_event(event); + Widget::mousedown_event(event); } -void GAbstractButton::mouseup_event(GMouseEvent& event) +void AbstractButton::mouseup_event(MouseEvent& event) { #ifdef GABSTRACTBUTTON_DEBUG - dbgprintf("GAbstractButton::mouse_up_event: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); + dbgprintf("AbstractButton::mouse_up_event: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); #endif - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { bool was_auto_repeating = m_auto_repeat_timer->is_active(); m_auto_repeat_timer->stop(); if (is_enabled()) { @@ -144,32 +146,32 @@ void GAbstractButton::mouseup_event(GMouseEvent& event) click(); } } - GWidget::mouseup_event(event); + Widget::mouseup_event(event); } -void GAbstractButton::enter_event(Core::Event&) +void AbstractButton::enter_event(Core::Event&) { m_hovered = true; update(); } -void GAbstractButton::leave_event(Core::Event&) +void AbstractButton::leave_event(Core::Event&) { m_hovered = false; update(); } -void GAbstractButton::keydown_event(GKeyEvent& event) +void AbstractButton::keydown_event(KeyEvent& event) { if (event.key() == KeyCode::Key_Return) { click(); event.accept(); return; } - GWidget::keydown_event(event); + Widget::keydown_event(event); } -void GAbstractButton::paint_text(GPainter& painter, const Rect& rect, const Font& font, TextAlignment text_alignment) +void AbstractButton::paint_text(Painter& painter, const Rect& rect, const Font& font, TextAlignment text_alignment) { auto clipped_rect = rect.intersected(this->rect()); @@ -186,9 +188,9 @@ void GAbstractButton::paint_text(GPainter& painter, const Rect& rect, const Font painter.draw_rect(clipped_rect.inflated(6, 4), Color(140, 140, 140)); } -void GAbstractButton::change_event(GEvent& event) +void AbstractButton::change_event(Event& event) { - if (event.type() == GEvent::Type::EnabledChange) { + if (event.type() == Event::Type::EnabledChange) { if (!is_enabled()) { bool was_being_pressed = m_being_pressed; m_being_pressed = false; @@ -196,5 +198,7 @@ void GAbstractButton::change_event(GEvent& event) update(); } } - GWidget::change_event(event); + Widget::change_event(event); +} + } diff --git a/Libraries/LibGUI/GAbstractButton.h b/Libraries/LibGUI/GAbstractButton.h index 2b868b0b9d..cb9885dde3 100644 --- a/Libraries/LibGUI/GAbstractButton.h +++ b/Libraries/LibGUI/GAbstractButton.h @@ -30,12 +30,14 @@ #include <LibDraw/TextAlignment.h> #include <LibGUI/GWidget.h> -class GPainter; +namespace GUI { -class GAbstractButton : public GWidget { +class Painter; + +class AbstractButton : public Widget { C_OBJECT_ABSTRACT(GAbstractButton) public: - virtual ~GAbstractButton() override; + virtual ~AbstractButton() override; Function<void(bool)> on_checked; @@ -62,18 +64,18 @@ public: void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; } protected: - explicit GAbstractButton(GWidget* parent); - GAbstractButton(const StringView&, GWidget* parent); + explicit AbstractButton(Widget* parent); + AbstractButton(const StringView&, Widget* parent); - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; - virtual void keydown_event(GKeyEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; + virtual void keydown_event(KeyEvent&) override; virtual void enter_event(Core::Event&) override; virtual void leave_event(Core::Event&) override; - virtual void change_event(GEvent&) override; + virtual void change_event(Event&) override; - void paint_text(GPainter&, const Rect&, const Font&, TextAlignment); + void paint_text(Painter&, const Rect&, const Font&, TextAlignment); private: virtual bool is_abstract_button() const final { return true; } @@ -89,10 +91,12 @@ private: RefPtr<Core::Timer> m_auto_repeat_timer; }; +} + template<> -inline bool Core::is<GAbstractButton>(const Core::Object& object) +inline bool Core::is<GUI::AbstractButton>(const Core::Object& object) { - if (!is<GWidget>(object)) + if (!is<GUI::Widget>(object)) return false; - return to<GWidget>(object).is_abstract_button(); + return to<GUI::Widget>(object).is_abstract_button(); } diff --git a/Libraries/LibGUI/GAbstractTableView.cpp b/Libraries/LibGUI/GAbstractTableView.cpp index 8dba874668..5ab6f3947b 100644 --- a/Libraries/LibGUI/GAbstractTableView.cpp +++ b/Libraries/LibGUI/GAbstractTableView.cpp @@ -32,10 +32,12 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GScrollBar.h> +namespace GUI { + static const int minimum_column_width = 2; -GAbstractTableView::GAbstractTableView(GWidget* parent) - : GAbstractView(parent) +AbstractTableView::AbstractTableView(Widget* parent) + : AbstractView(parent) { set_frame_shape(FrameShape::Container); set_frame_shadow(FrameShadow::Sunken); @@ -44,11 +46,11 @@ GAbstractTableView::GAbstractTableView(GWidget* parent) set_should_hide_unnecessary_scrollbars(true); } -GAbstractTableView::~GAbstractTableView() +AbstractTableView::~AbstractTableView() { } -void GAbstractTableView::update_column_sizes() +void AbstractTableView::update_column_sizes() { if (!m_size_columns_to_fit_content) return; @@ -84,7 +86,7 @@ void GAbstractTableView::update_column_sizes() } } -void GAbstractTableView::update_content_size() +void AbstractTableView::update_content_size() { if (!model()) return set_content_size({}); @@ -101,7 +103,7 @@ void GAbstractTableView::update_content_size() set_size_occupied_by_fixed_elements({ 0, header_height() }); } -Rect GAbstractTableView::header_rect(int column_index) const +Rect AbstractTableView::header_rect(int column_index) const { if (!model()) return {}; @@ -116,7 +118,7 @@ Rect GAbstractTableView::header_rect(int column_index) const return { x_offset, 0, column_width(column_index) + horizontal_padding() * 2, header_height() }; } -void GAbstractTableView::set_hovered_header_index(int index) +void AbstractTableView::set_hovered_header_index(int index) { if (m_hovered_column_header_index == index) return; @@ -124,7 +126,7 @@ void GAbstractTableView::set_hovered_header_index(int index) update_headers(); } -void GAbstractTableView::paint_headers(GPainter& painter) +void AbstractTableView::paint_headers(Painter& painter) { if (!headers_visible()) return; @@ -141,16 +143,16 @@ void GAbstractTableView::paint_headers(GPainter& painter) bool is_key_column = model()->key_column() == column_index; Rect cell_rect(x_offset, 0, column_width + horizontal_padding() * 2, header_height()); bool pressed = column_index == m_pressed_column_header_index && m_pressed_column_header_is_pressed; - bool hovered = column_index == m_hovered_column_header_index && model()->column_metadata(column_index).sortable == GModel::ColumnMetadata::Sortable::True; + bool hovered = column_index == m_hovered_column_header_index && model()->column_metadata(column_index).sortable == Model::ColumnMetadata::Sortable::True; StylePainter::paint_button(painter, cell_rect, palette(), ButtonStyle::Normal, pressed, hovered); String text; if (is_key_column) { StringBuilder builder; builder.append(model()->column_name(column_index)); auto sort_order = model()->sort_order(); - if (sort_order == GSortOrder::Ascending) + if (sort_order == SortOrder::Ascending) builder.append(" \xc3\xb6"); - else if (sort_order == GSortOrder::Descending) + else if (sort_order == SortOrder::Descending) builder.append(" \xc3\xb7"); text = builder.to_string(); } else { @@ -164,12 +166,12 @@ void GAbstractTableView::paint_headers(GPainter& painter) } } -bool GAbstractTableView::is_column_hidden(int column) const +bool AbstractTableView::is_column_hidden(int column) const { return !column_data(column).visibility; } -void GAbstractTableView::set_column_hidden(int column, bool hidden) +void AbstractTableView::set_column_hidden(int column, bool hidden) { auto& column_data = this->column_data(column); if (column_data.visibility == !hidden) @@ -179,18 +181,18 @@ void GAbstractTableView::set_column_hidden(int column, bool hidden) update(); } -GMenu& GAbstractTableView::ensure_header_context_menu() +Menu& AbstractTableView::ensure_header_context_menu() { // FIXME: This menu needs to be rebuilt if the model is swapped out, // or if the column count/names change. if (!m_header_context_menu) { ASSERT(model()); - m_header_context_menu = GMenu::construct(); + m_header_context_menu = Menu::construct(); for (int column = 0; column < model()->column_count(); ++column) { auto& column_data = this->column_data(column); auto name = model()->column_name(column); - column_data.visibility_action = GAction::create(name, [this, column](GAction& action) { + column_data.visibility_action = Action::create(name, [this, column](Action& action) { action.set_checked(!action.is_checked()); set_column_hidden(column, !action.is_checked()); }); @@ -203,31 +205,31 @@ GMenu& GAbstractTableView::ensure_header_context_menu() return *m_header_context_menu; } -const Font& GAbstractTableView::header_font() +const Font& AbstractTableView::header_font() { return Font::default_bold_font(); } -void GAbstractTableView::set_cell_painting_delegate(int column, OwnPtr<GTableCellPaintingDelegate>&& delegate) +void AbstractTableView::set_cell_painting_delegate(int column, OwnPtr<TableCellPaintingDelegate>&& delegate) { column_data(column).cell_painting_delegate = move(delegate); } -void GAbstractTableView::update_headers() +void AbstractTableView::update_headers() { Rect rect { 0, 0, frame_inner_rect().width(), header_height() }; rect.move_by(frame_thickness(), frame_thickness()); update(rect); } -GAbstractTableView::ColumnData& GAbstractTableView::column_data(int column) const +AbstractTableView::ColumnData& AbstractTableView::column_data(int column) const { if (column >= m_column_data.size()) m_column_data.resize(column + 1); return m_column_data.at(column); } -Rect GAbstractTableView::column_resize_grabbable_rect(int column) const +Rect AbstractTableView::column_resize_grabbable_rect(int column) const { if (!model()) return {}; @@ -235,7 +237,7 @@ Rect GAbstractTableView::column_resize_grabbable_rect(int column) const return { header_rect.right() - 1, header_rect.top(), 4, header_rect.height() }; } -int GAbstractTableView::column_width(int column_index) const +int AbstractTableView::column_width(int column_index) const { if (!model()) return 0; @@ -248,10 +250,10 @@ int GAbstractTableView::column_width(int column_index) const return column_data.width; } -void GAbstractTableView::mousemove_event(GMouseEvent& event) +void AbstractTableView::mousemove_event(MouseEvent& event) { if (!model()) - return GAbstractView::mousemove_event(event); + return AbstractView::mousemove_event(event); if (m_in_column_resize) { auto delta = event.position() - m_column_resize_origin; @@ -288,7 +290,7 @@ void GAbstractTableView::mousemove_event(GMouseEvent& event) bool found_hovered_header = false; for (int i = 0; i < column_count; ++i) { if (column_resize_grabbable_rect(i).contains(event.position())) { - window()->set_override_cursor(GStandardCursor::ResizeHorizontal); + window()->set_override_cursor(StandardCursor::ResizeHorizontal); set_hovered_header_index(-1); return; } @@ -300,29 +302,29 @@ void GAbstractTableView::mousemove_event(GMouseEvent& event) if (!found_hovered_header) set_hovered_header_index(-1); } - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(StandardCursor::None); - GAbstractView::mousemove_event(event); + AbstractView::mousemove_event(event); } -void GAbstractTableView::mouseup_event(GMouseEvent& event) +void AbstractTableView::mouseup_event(MouseEvent& event) { auto adjusted_position = this->adjusted_position(event.position()); - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { if (m_in_column_resize) { if (!column_resize_grabbable_rect(m_resizing_column).contains(adjusted_position)) - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(StandardCursor::None); m_in_column_resize = false; return; } if (m_pressed_column_header_index != -1) { auto header_rect = this->header_rect(m_pressed_column_header_index); if (header_rect.contains(event.position())) { - auto new_sort_order = GSortOrder::Ascending; + auto new_sort_order = SortOrder::Ascending; if (model()->key_column() == m_pressed_column_header_index) - new_sort_order = model()->sort_order() == GSortOrder::Ascending - ? GSortOrder::Descending - : GSortOrder::Ascending; + new_sort_order = model()->sort_order() == SortOrder::Ascending + ? SortOrder::Descending + : SortOrder::Ascending; model()->set_key_column_and_sort_order(m_pressed_column_header_index, new_sort_order); } m_pressed_column_header_index = -1; @@ -332,16 +334,16 @@ void GAbstractTableView::mouseup_event(GMouseEvent& event) } } - GAbstractView::mouseup_event(event); + AbstractView::mouseup_event(event); } -void GAbstractTableView::mousedown_event(GMouseEvent& event) +void AbstractTableView::mousedown_event(MouseEvent& event) { if (!model()) - return GAbstractView::mousedown_event(event); + return AbstractView::mousedown_event(event); - if (event.button() != GMouseButton::Left) - return GAbstractView::mousedown_event(event); + if (event.button() != MouseButton::Left) + return AbstractView::mousedown_event(event); if (event.y() < header_height()) { int column_count = model()->column_count(); @@ -355,7 +357,7 @@ void GAbstractTableView::mousedown_event(GMouseEvent& event) } auto header_rect = this->header_rect(i); auto column_metadata = model()->column_metadata(i); - if (header_rect.contains(event.position()) && column_metadata.sortable == GModel::ColumnMetadata::Sortable::True) { + if (header_rect.contains(event.position()) && column_metadata.sortable == Model::ColumnMetadata::Sortable::True) { m_pressed_column_header_index = i; m_pressed_column_header_is_pressed = true; update_headers(); @@ -373,10 +375,10 @@ void GAbstractTableView::mousedown_event(GMouseEvent& event) return; } - GAbstractView::mousedown_event(event); + AbstractView::mousedown_event(event); } -GModelIndex GAbstractTableView::index_at_event_position(const Point& position, bool& is_toggle) const +ModelIndex AbstractTableView::index_at_event_position(const Point& position, bool& is_toggle) const { is_toggle = false; if (!model()) @@ -396,21 +398,21 @@ GModelIndex GAbstractTableView::index_at_event_position(const Point& position, b return {}; } -GModelIndex GAbstractTableView::index_at_event_position(const Point& position) const +ModelIndex AbstractTableView::index_at_event_position(const Point& position) const { bool is_toggle; auto index = index_at_event_position(position, is_toggle); - return is_toggle ? GModelIndex() : index; + return is_toggle ? ModelIndex() : index; } -int GAbstractTableView::item_count() const +int AbstractTableView::item_count() const { if (!model()) return 0; return model()->row_count(); } -void GAbstractTableView::keydown_event(GKeyEvent& event) +void AbstractTableView::keydown_event(KeyEvent& event) { if (!model()) return; @@ -420,7 +422,7 @@ void GAbstractTableView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Up) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() - 1, old_index.column()); @@ -435,7 +437,7 @@ void GAbstractTableView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Down) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() + 1, old_index.column()); @@ -471,20 +473,20 @@ void GAbstractTableView::keydown_event(GKeyEvent& event) } return; } - return GWidget::keydown_event(event); + return Widget::keydown_event(event); } -void GAbstractTableView::scroll_into_view(const GModelIndex& index, Orientation orientation) +void AbstractTableView::scroll_into_view(const ModelIndex& index, Orientation orientation) { auto rect = row_rect(index.row()).translated(0, -header_height()); - GScrollableWidget::scroll_into_view(rect, orientation); + ScrollableWidget::scroll_into_view(rect, orientation); } -void GAbstractTableView::doubleclick_event(GMouseEvent& event) +void AbstractTableView::doubleclick_event(MouseEvent& event) { if (!model()) return; - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { if (event.y() < header_height()) return; if (!selection().is_empty()) { @@ -496,7 +498,7 @@ void GAbstractTableView::doubleclick_event(GMouseEvent& event) } } -void GAbstractTableView::context_menu_event(GContextMenuEvent& event) +void AbstractTableView::context_menu_event(ContextMenuEvent& event) { if (!model()) return; @@ -517,13 +519,13 @@ void GAbstractTableView::context_menu_event(GContextMenuEvent& event) on_context_menu_request(index, event); } -void GAbstractTableView::leave_event(Core::Event&) +void AbstractTableView::leave_event(Core::Event&) { - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(StandardCursor::None); set_hovered_header_index(-1); } -Rect GAbstractTableView::content_rect(int row, int column) const +Rect AbstractTableView::content_rect(int row, int column) const { auto row_rect = this->row_rect(row); int x = 0; @@ -533,25 +535,27 @@ Rect GAbstractTableView::content_rect(int row, int column) const return { row_rect.x() + x, row_rect.y(), column_width(column) + horizontal_padding() * 2, item_height() }; } -Rect GAbstractTableView::content_rect(const GModelIndex& index) const +Rect AbstractTableView::content_rect(const ModelIndex& index) const { return content_rect(index.row(), index.column()); } -Rect GAbstractTableView::row_rect(int item_index) const +Rect AbstractTableView::row_rect(int item_index) const { return { 0, header_height() + (item_index * item_height()), max(content_size().width(), width()), item_height() }; } -Point GAbstractTableView::adjusted_position(const Point& position) const +Point AbstractTableView::adjusted_position(const Point& position) const { return position.translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness()); } -void GAbstractTableView::did_update_model() +void AbstractTableView::did_update_model() { - GAbstractView::did_update_model(); + AbstractView::did_update_model(); update_column_sizes(); update_content_size(); update(); } + +} diff --git a/Libraries/LibGUI/GAbstractTableView.h b/Libraries/LibGUI/GAbstractTableView.h index a40b155730..b728b3fb2b 100644 --- a/Libraries/LibGUI/GAbstractTableView.h +++ b/Libraries/LibGUI/GAbstractTableView.h @@ -28,17 +28,19 @@ #include <LibGUI/GAbstractView.h> -class GPainter; +namespace GUI { + +class Painter; // FIXME: Rename this to something without "table cell" in the name. -class GTableCellPaintingDelegate { +class TableCellPaintingDelegate { public: - virtual ~GTableCellPaintingDelegate() {} + virtual ~TableCellPaintingDelegate() {} - virtual void paint(GPainter&, const Rect&, const Palette&, const GModel&, const GModelIndex&) = 0; + virtual void paint(Painter&, const Rect&, const Palette&, const Model&, const ModelIndex&) = 0; }; -class GAbstractTableView : public GAbstractView { +class AbstractTableView : public AbstractView { public: int item_height() const { return 16; } @@ -56,37 +58,37 @@ public: void set_size_columns_to_fit_content(bool b) { m_size_columns_to_fit_content = b; } bool size_columns_to_fit_content() const { return m_size_columns_to_fit_content; } - void set_cell_painting_delegate(int column, OwnPtr<GTableCellPaintingDelegate>&&); + void set_cell_painting_delegate(int column, OwnPtr<TableCellPaintingDelegate>&&); int horizontal_padding() const { return m_horizontal_padding; } Point adjusted_position(const Point&) const; - virtual Rect content_rect(const GModelIndex&) const override; + virtual Rect content_rect(const ModelIndex&) const override; Rect content_rect(int row, int column) const; Rect row_rect(int item_index) const; - void scroll_into_view(const GModelIndex&, Orientation); + void scroll_into_view(const ModelIndex&, Orientation); - virtual GModelIndex index_at_event_position(const Point&, bool& is_toggle) const; - virtual GModelIndex index_at_event_position(const Point&) const override; + virtual ModelIndex index_at_event_position(const Point&, bool& is_toggle) const; + virtual ModelIndex index_at_event_position(const Point&) const override; protected: - virtual ~GAbstractTableView() override; - explicit GAbstractTableView(GWidget* parent); + virtual ~AbstractTableView() override; + explicit AbstractTableView(Widget* parent); virtual void did_update_model() override; - virtual void mouseup_event(GMouseEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void doubleclick_event(GMouseEvent&) override; - virtual void keydown_event(GKeyEvent&) override; + virtual void mouseup_event(MouseEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void doubleclick_event(MouseEvent&) override; + virtual void keydown_event(KeyEvent&) override; virtual void leave_event(Core::Event&) override; - virtual void context_menu_event(GContextMenuEvent&) override; + virtual void context_menu_event(ContextMenuEvent&) override; - virtual void toggle_index(const GModelIndex&) {} + virtual void toggle_index(const ModelIndex&) {} - void paint_headers(GPainter&); + void paint_headers(Painter&); Rect header_rect(int column) const; static const Font& header_font(); @@ -97,15 +99,15 @@ protected: int width { 0 }; bool has_initialized_width { false }; bool visibility { true }; - RefPtr<GAction> visibility_action; - OwnPtr<GTableCellPaintingDelegate> cell_painting_delegate; + RefPtr<Action> visibility_action; + OwnPtr<TableCellPaintingDelegate> cell_painting_delegate; }; ColumnData& column_data(int column) const; mutable Vector<ColumnData> m_column_data; - GMenu& ensure_header_context_menu(); - RefPtr<GMenu> m_header_context_menu; + Menu& ensure_header_context_menu(); + RefPtr<Menu> m_header_context_menu; Rect column_resize_grabbable_rect(int) const; int column_width(int) const; @@ -126,3 +128,5 @@ private: bool m_pressed_column_header_is_pressed { false }; int m_hovered_column_header_index { -1 }; }; + +} diff --git a/Libraries/LibGUI/GAbstractView.cpp b/Libraries/LibGUI/GAbstractView.cpp index 9c05e72505..6f1775b447 100644 --- a/Libraries/LibGUI/GAbstractView.cpp +++ b/Libraries/LibGUI/GAbstractView.cpp @@ -34,17 +34,19 @@ #include <LibGUI/GScrollBar.h> #include <LibGUI/GTextBox.h> -GAbstractView::GAbstractView(GWidget* parent) - : GScrollableWidget(parent) +namespace GUI { + +AbstractView::AbstractView(Widget* parent) + : ScrollableWidget(parent) , m_selection(*this) { } -GAbstractView::~GAbstractView() +AbstractView::~AbstractView() { } -void GAbstractView::set_model(RefPtr<GModel>&& model) +void AbstractView::set_model(RefPtr<Model>&& model) { if (model == m_model) return; @@ -56,13 +58,13 @@ void GAbstractView::set_model(RefPtr<GModel>&& model) did_update_model(); } -void GAbstractView::did_update_model() +void AbstractView::did_update_model() { if (!model() || selection().first() != m_edit_index) stop_editing(); } -void GAbstractView::did_update_selection() +void AbstractView::did_update_selection() { if (!model() || selection().first() != m_edit_index) stop_editing(); @@ -70,19 +72,19 @@ void GAbstractView::did_update_selection() on_selection(selection().first()); } -void GAbstractView::did_scroll() +void AbstractView::did_scroll() { update_edit_widget_position(); } -void GAbstractView::update_edit_widget_position() +void AbstractView::update_edit_widget_position() { if (!m_edit_widget) return; m_edit_widget->set_relative_rect(m_edit_widget_content_rect.translated(-horizontal_scrollbar().value(), -vertical_scrollbar().value())); } -void GAbstractView::begin_editing(const GModelIndex& index) +void AbstractView::begin_editing(const ModelIndex& index) { ASSERT(is_editable()); ASSERT(model()); @@ -99,7 +101,7 @@ void GAbstractView::begin_editing(const GModelIndex& index) ASSERT(aid_create_editing_delegate); m_editing_delegate = aid_create_editing_delegate(index); m_editing_delegate->bind(*model(), index); - m_editing_delegate->set_value(model()->data(index, GModel::Role::Display)); + m_editing_delegate->set_value(model()->data(index, Model::Role::Display)); m_edit_widget = m_editing_delegate->widget(); add_child(*m_edit_widget); m_edit_widget->move_to_back(); @@ -114,7 +116,7 @@ void GAbstractView::begin_editing(const GModelIndex& index) }; } -void GAbstractView::stop_editing() +void AbstractView::stop_editing() { m_edit_index = {}; if (m_edit_widget) { @@ -123,7 +125,7 @@ void GAbstractView::stop_editing() } } -void GAbstractView::select_all() +void AbstractView::select_all() { ASSERT(model()); int rows = model()->row_count(); @@ -135,13 +137,13 @@ void GAbstractView::select_all() } } -void GAbstractView::activate(const GModelIndex& index) +void AbstractView::activate(const ModelIndex& index) { if (on_activation) on_activation(index); } -void GAbstractView::activate_selected() +void AbstractView::activate_selected() { if (!on_activation) return; @@ -151,7 +153,7 @@ void GAbstractView::activate_selected() }); } -void GAbstractView::notify_selection_changed(Badge<GModelSelection>) +void AbstractView::notify_selection_changed(Badge<ModelSelection>) { did_update_selection(); if (on_selection_change) @@ -159,12 +161,12 @@ void GAbstractView::notify_selection_changed(Badge<GModelSelection>) update(); } -NonnullRefPtr<Font> GAbstractView::font_for_index(const GModelIndex& index) const +NonnullRefPtr<Font> AbstractView::font_for_index(const ModelIndex& index) const { if (!model()) return font(); - auto font_data = model()->data(index, GModel::Role::Font); + auto font_data = model()->data(index, Model::Role::Font); if (font_data.is_font()) return font_data.as_font(); @@ -174,14 +176,14 @@ NonnullRefPtr<Font> GAbstractView::font_for_index(const GModelIndex& index) cons return font(); } -void GAbstractView::mousedown_event(GMouseEvent& event) +void AbstractView::mousedown_event(MouseEvent& event) { - GScrollableWidget::mousedown_event(event); + ScrollableWidget::mousedown_event(event); if (!model()) return; - if (event.button() == GMouseButton::Left) + if (event.button() == MouseButton::Left) m_left_mousedown_position = event.position(); auto index = index_at_event_position(event.position()); @@ -191,7 +193,7 @@ void GAbstractView::mousedown_event(GMouseEvent& event) m_selection.clear(); } else if (event.modifiers() & Mod_Ctrl) { m_selection.toggle(index); - } else if (event.button() == GMouseButton::Left && m_selection.contains(index) && !m_model->drag_data_type().is_null()) { + } else if (event.button() == MouseButton::Left && m_selection.contains(index) && !m_model->drag_data_type().is_null()) { // We might be starting a drag, so don't throw away other selected items yet. m_might_drag = true; } else { @@ -201,14 +203,14 @@ void GAbstractView::mousedown_event(GMouseEvent& event) update(); } -void GAbstractView::mousemove_event(GMouseEvent& event) +void AbstractView::mousemove_event(MouseEvent& event) { if (!model() || !m_might_drag) - return GScrollableWidget::mousemove_event(event); + return ScrollableWidget::mousemove_event(event); - if (!(event.buttons() & GMouseButton::Left) || m_selection.is_empty()) { + if (!(event.buttons() & MouseButton::Left) || m_selection.is_empty()) { m_might_drag = false; - return GScrollableWidget::mousemove_event(event); + return ScrollableWidget::mousemove_event(event); } auto diff = event.position() - m_left_mousedown_position; @@ -216,13 +218,13 @@ void GAbstractView::mousemove_event(GMouseEvent& event) constexpr int drag_distance_threshold = 5; if (distance_travelled_squared <= drag_distance_threshold) - return GScrollableWidget::mousemove_event(event); + return ScrollableWidget::mousemove_event(event); auto data_type = m_model->drag_data_type(); ASSERT(!data_type.is_null()); dbg() << "Initiate drag!"; - auto drag_operation = GDragOperation::construct(); + auto drag_operation = DragOperation::construct(); RefPtr<GraphicsBitmap> bitmap; @@ -235,14 +237,14 @@ void GAbstractView::mousemove_event(GMouseEvent& event) text_builder.append(", "); text_builder.append(text_data.to_string()); - auto drag_data = m_model->data(index, GModel::Role::DragData); + auto drag_data = m_model->data(index, Model::Role::DragData); data_builder.append(drag_data.to_string()); data_builder.append('\n'); first = false; if (!bitmap) { - GVariant icon_data = model()->data(index, GModel::Role::Icon); + Variant icon_data = model()->data(index, Model::Role::Icon); if (icon_data.is_icon()) bitmap = icon_data.as_icon().bitmap_for_size(32); } @@ -255,10 +257,10 @@ void GAbstractView::mousemove_event(GMouseEvent& event) auto outcome = drag_operation->exec(); switch (outcome) { - case GDragOperation::Outcome::Accepted: + case DragOperation::Outcome::Accepted: dbg() << "Drag was accepted!"; break; - case GDragOperation::Outcome::Cancelled: + case DragOperation::Outcome::Cancelled: dbg() << "Drag was cancelled!"; break; default: @@ -267,9 +269,9 @@ void GAbstractView::mousemove_event(GMouseEvent& event) } } -void GAbstractView::mouseup_event(GMouseEvent& event) +void AbstractView::mouseup_event(MouseEvent& event) { - GScrollableWidget::mouseup_event(event); + ScrollableWidget::mouseup_event(event); if (!model()) return; @@ -288,12 +290,12 @@ void GAbstractView::mouseup_event(GMouseEvent& event) } } -void GAbstractView::doubleclick_event(GMouseEvent& event) +void AbstractView::doubleclick_event(MouseEvent& event) { if (!model()) return; - if (event.button() != GMouseButton::Left) + if (event.button() != MouseButton::Left) return; m_might_drag = false; @@ -308,7 +310,7 @@ void GAbstractView::doubleclick_event(GMouseEvent& event) activate_selected(); } -void GAbstractView::context_menu_event(GContextMenuEvent& event) +void AbstractView::context_menu_event(ContextMenuEvent& event) { if (!model()) return; @@ -323,3 +325,5 @@ void GAbstractView::context_menu_event(GContextMenuEvent& event) if (on_context_menu_request) on_context_menu_request(index, event); } + +} diff --git a/Libraries/LibGUI/GAbstractView.h b/Libraries/LibGUI/GAbstractView.h index bf8fecc172..e3de39c798 100644 --- a/Libraries/LibGUI/GAbstractView.h +++ b/Libraries/LibGUI/GAbstractView.h @@ -31,19 +31,21 @@ #include <LibGUI/GModelSelection.h> #include <LibGUI/GScrollableWidget.h> -class GModelEditingDelegate; +namespace GUI { -class GAbstractView : public GScrollableWidget { - C_OBJECT(GAbstractView) - friend class GModel; +class ModelEditingDelegate; + +class AbstractView : public ScrollableWidget { + C_OBJECT_ABSTRACT(AbstractView) + friend class Model; public: - void set_model(RefPtr<GModel>&&); - GModel* model() { return m_model.ptr(); } - const GModel* model() const { return m_model.ptr(); } + void set_model(RefPtr<Model>&&); + Model* model() { return m_model.ptr(); } + const Model* model() const { return m_model.ptr(); } - GModelSelection& selection() { return m_selection; } - const GModelSelection& selection() const { return m_selection; } + ModelSelection& selection() { return m_selection; } + const ModelSelection& selection() const { return m_selection; } void select_all(); bool is_editable() const { return m_editable; } @@ -53,51 +55,53 @@ public: virtual void did_update_model(); virtual void did_update_selection(); - virtual Rect content_rect(const GModelIndex&) const { return {}; } - virtual GModelIndex index_at_event_position(const Point&) const = 0; - void begin_editing(const GModelIndex&); + virtual Rect content_rect(const ModelIndex&) const { return {}; } + virtual ModelIndex index_at_event_position(const Point&) const = 0; + void begin_editing(const ModelIndex&); void stop_editing(); void set_activates_on_selection(bool b) { m_activates_on_selection = b; } bool activates_on_selection() const { return m_activates_on_selection; } Function<void()> on_selection_change; - Function<void(const GModelIndex&)> on_activation; - Function<void(const GModelIndex&)> on_selection; - Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request; + Function<void(const ModelIndex&)> on_activation; + Function<void(const ModelIndex&)> on_selection; + Function<void(const ModelIndex&, const ContextMenuEvent&)> on_context_menu_request; - Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate; + Function<OwnPtr<ModelEditingDelegate>(const ModelIndex&)> aid_create_editing_delegate; - void notify_selection_changed(Badge<GModelSelection>); + void notify_selection_changed(Badge<ModelSelection>); - NonnullRefPtr<Font> font_for_index(const GModelIndex&) const; + NonnullRefPtr<Font> font_for_index(const ModelIndex&) const; protected: - explicit GAbstractView(GWidget* parent); - virtual ~GAbstractView() override; + explicit AbstractView(Widget* parent); + virtual ~AbstractView() override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; - virtual void doubleclick_event(GMouseEvent&) override; - virtual void context_menu_event(GContextMenuEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; + virtual void doubleclick_event(MouseEvent&) override; + virtual void context_menu_event(ContextMenuEvent&) override; virtual void did_scroll() override; - void activate(const GModelIndex&); + void activate(const ModelIndex&); void activate_selected(); void update_edit_widget_position(); bool m_editable { false }; - GModelIndex m_edit_index; - RefPtr<GWidget> m_edit_widget; + ModelIndex m_edit_index; + RefPtr<Widget> m_edit_widget; Rect m_edit_widget_content_rect; Point m_left_mousedown_position; bool m_might_drag { false }; private: - RefPtr<GModel> m_model; - OwnPtr<GModelEditingDelegate> m_editing_delegate; - GModelSelection m_selection; + RefPtr<Model> m_model; + OwnPtr<ModelEditingDelegate> m_editing_delegate; + ModelSelection m_selection; bool m_activates_on_selection { false }; }; + +} diff --git a/Libraries/LibGUI/GAction.cpp b/Libraries/LibGUI/GAction.cpp index b7f0833f66..572da69c7b 100644 --- a/Libraries/LibGUI/GAction.cpp +++ b/Libraries/LibGUI/GAction.cpp @@ -30,93 +30,95 @@ #include <LibGUI/GButton.h> #include <LibGUI/GMenuItem.h> -namespace GCommonActions { +namespace GUI { -NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)> callback, Core::Object* parent) +namespace CommonActions { + +NonnullRefPtr<Action> make_open_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Open...", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), parent); + return Action::create("Open...", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Move to front", { Mod_Ctrl | Mod_Shift, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), parent); + return Action::create("Move to front", { Mod_Ctrl | Mod_Shift, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_move_to_back_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Move to back", { Mod_Ctrl | Mod_Shift, Key_Down }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-back.png"), move(callback), parent); + return Action::create("Move to back", { Mod_Ctrl | Mod_Shift, Key_Down }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-back.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_undo_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Undo", { Mod_Ctrl, Key_Z }, GraphicsBitmap::load_from_file("/res/icons/16x16/undo.png"), move(callback), parent); + return Action::create("Undo", { Mod_Ctrl, Key_Z }, GraphicsBitmap::load_from_file("/res/icons/16x16/undo.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_redo_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Redo", { Mod_Ctrl, Key_Y }, GraphicsBitmap::load_from_file("/res/icons/16x16/redo.png"), move(callback), parent); + return Action::create("Redo", { Mod_Ctrl, Key_Y }, GraphicsBitmap::load_from_file("/res/icons/16x16/redo.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_delete_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_delete_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Delete", { Mod_None, Key_Delete }, GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), move(callback), parent); + return Action::create("Delete", { Mod_None, Key_Delete }, GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_cut_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file("/res/icons/cut16.png"), move(callback), parent); + return Action::create("Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file("/res/icons/cut16.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_copy_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_copy_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), move(callback), parent); + return Action::create("Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_paste_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_paste_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), move(callback), parent); + return Action::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_fullscreen_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Fullscreen", { Mod_None, Key_F11 }, move(callback), parent); + return Action::create("Fullscreen", { Mod_None, Key_F11 }, move(callback), parent); } -NonnullRefPtr<GAction> make_quit_action(Function<void(GAction&)> callback) +NonnullRefPtr<Action> make_quit_action(Function<void(Action&)> callback) { - return GAction::create("Quit", { Mod_Alt, Key_F4 }, move(callback)); + return Action::create("Quit", { Mod_Alt, Key_F4 }, move(callback)); } -NonnullRefPtr<GAction> make_go_back_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_go_back_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Go back", { Mod_Alt, Key_Left }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-back.png"), move(callback), parent); + return Action::create("Go back", { Mod_Alt, Key_Left }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-back.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_go_forward_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Go forward", { Mod_Alt, Key_Right }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), move(callback), parent); + return Action::create("Go forward", { Mod_Alt, Key_Right }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_go_home_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Go home", { Mod_Alt, Key_Home }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-home.png"), move(callback), parent); + return Action::create("Go home", { Mod_Alt, Key_Home }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-home.png"), move(callback), parent); } -NonnullRefPtr<GAction> make_reload_action(Function<void(GAction&)> callback, Core::Object* parent) +NonnullRefPtr<Action> make_reload_action(Function<void(Action&)> callback, Core::Object* parent) { - return GAction::create("Reload", { Mod_Ctrl, Key_R }, GraphicsBitmap::load_from_file("/res/icons/16x16/reload.png"), move(callback), parent); + return Action::create("Reload", { Mod_Ctrl, Key_R }, GraphicsBitmap::load_from_file("/res/icons/16x16/reload.png"), move(callback), parent); } } -GAction::GAction(const StringView& text, Function<void(GAction&)> on_activation_callback, Core::Object* parent) +Action::Action(const StringView& text, Function<void(Action&)> on_activation_callback, Core::Object* parent) : Core::Object(parent) , on_activation(move(on_activation_callback)) , m_text(text) { } -GAction::GAction(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, Core::Object* parent) +Action::Action(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(Action&)> on_activation_callback, Core::Object* parent) : Core::Object(parent) , on_activation(move(on_activation_callback)) , m_text(text) @@ -124,35 +126,35 @@ GAction::GAction(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function { } -GAction::GAction(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, Core::Object* parent) - : GAction(text, shortcut, nullptr, move(on_activation_callback), parent) +Action::Action(const StringView& text, const Shortcut& shortcut, Function<void(Action&)> on_activation_callback, Core::Object* parent) + : Action(text, shortcut, nullptr, move(on_activation_callback), parent) { } -GAction::GAction(const StringView& text, const GShortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, Core::Object* parent) +Action::Action(const StringView& text, const Shortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(Action&)> on_activation_callback, Core::Object* parent) : Core::Object(parent) , on_activation(move(on_activation_callback)) , m_text(text) , m_icon(move(icon)) , m_shortcut(shortcut) { - if (parent && Core::is<GWidget>(*parent)) { + if (parent && Core::is<Widget>(*parent)) { m_scope = ShortcutScope::WidgetLocal; - } else if (parent && Core::is<GWindow>(*parent)) { + } else if (parent && Core::is<Window>(*parent)) { m_scope = ShortcutScope::WindowLocal; } else { m_scope = ShortcutScope::ApplicationGlobal; - GApplication::the().register_global_shortcut_action({}, *this); + Application::the().register_global_shortcut_action({}, *this); } } -GAction::~GAction() +Action::~Action() { if (m_shortcut.is_valid() && m_scope == ShortcutScope::ApplicationGlobal) - GApplication::the().unregister_global_shortcut_action({}, *this); + Application::the().unregister_global_shortcut_action({}, *this); } -void GAction::activate(Core::Object* activator) +void Action::activate(Core::Object* activator) { if (activator) m_activator = activator->make_weak_ptr(); @@ -161,54 +163,54 @@ void GAction::activate(Core::Object* activator) m_activator = nullptr; } -void GAction::register_button(Badge<GButton>, GButton& button) +void Action::register_button(Badge<Button>, Button& button) { m_buttons.set(&button); } -void GAction::unregister_button(Badge<GButton>, GButton& button) +void Action::unregister_button(Badge<Button>, Button& button) { m_buttons.remove(&button); } -void GAction::register_menu_item(Badge<GMenuItem>, GMenuItem& menu_item) +void Action::register_menu_item(Badge<MenuItem>, MenuItem& menu_item) { m_menu_items.set(&menu_item); } -void GAction::unregister_menu_item(Badge<GMenuItem>, GMenuItem& menu_item) +void Action::unregister_menu_item(Badge<MenuItem>, MenuItem& menu_item) { m_menu_items.remove(&menu_item); } template<typename Callback> -void GAction::for_each_toolbar_button(Callback callback) +void Action::for_each_toolbar_button(Callback callback) { for (auto& it : m_buttons) callback(*it); } template<typename Callback> -void GAction::for_each_menu_item(Callback callback) +void Action::for_each_menu_item(Callback callback) { for (auto& it : m_menu_items) callback(*it); } -void GAction::set_enabled(bool enabled) +void Action::set_enabled(bool enabled) { if (m_enabled == enabled) return; m_enabled = enabled; - for_each_toolbar_button([enabled](GButton& button) { + for_each_toolbar_button([enabled](auto& button) { button.set_enabled(enabled); }); - for_each_menu_item([enabled](GMenuItem& item) { + for_each_menu_item([enabled](auto& item) { item.set_enabled(enabled); }); } -void GAction::set_checked(bool checked) +void Action::set_checked(bool checked) { if (m_checked == checked) return; @@ -224,15 +226,17 @@ void GAction::set_checked(bool checked) }); } - for_each_toolbar_button([checked](GButton& button) { + for_each_toolbar_button([checked](auto& button) { button.set_checked(checked); }); - for_each_menu_item([checked](GMenuItem& item) { + for_each_menu_item([checked](MenuItem& item) { item.set_checked(checked); }); } -void GAction::set_group(Badge<GActionGroup>, GActionGroup* group) +void Action::set_group(Badge<ActionGroup>, ActionGroup* group) { m_action_group = group ? group->make_weak_ptr() : nullptr; } + +} diff --git a/Libraries/LibGUI/GAction.h b/Libraries/LibGUI/GAction.h index e9c9ddc608..85ecba48a9 100644 --- a/Libraries/LibGUI/GAction.h +++ b/Libraries/LibGUI/GAction.h @@ -38,31 +38,33 @@ #include <LibGUI/GShortcut.h> #include <LibGUI/GWindow.h> -class GAction; -class GActionGroup; -class GButton; -class GMenuItem; - -namespace GCommonActions { -NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_copy_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_paste_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_delete_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_move_to_back_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_fullscreen_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_quit_action(Function<void(GAction&)>); -NonnullRefPtr<GAction> make_go_back_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_go_forward_action(Function<void(GAction&)>, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_go_home_action(Function<void(GAction&)> callback, Core::Object* parent = nullptr); -NonnullRefPtr<GAction> make_reload_action(Function<void(GAction&)>, Core::Object* parent = nullptr); +namespace GUI { + +class Action; +class ActionGroup; +class Button; +class MenuItem; + +namespace CommonActions { +NonnullRefPtr<Action> make_open_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_undo_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_redo_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_cut_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_copy_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_paste_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_delete_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_quit_action(Function<void(Action&)>); +NonnullRefPtr<Action> make_go_back_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)>, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent = nullptr); +NonnullRefPtr<Action> make_reload_action(Function<void(Action&)>, Core::Object* parent = nullptr); }; -class GAction final : public Core::Object { - C_OBJECT(GAction) +class Action final : public Core::Object { + C_OBJECT(Action) public: enum class ShortcutScope { None, @@ -70,33 +72,33 @@ public: WindowLocal, ApplicationGlobal, }; - static NonnullRefPtr<GAction> create(const StringView& text, Function<void(GAction&)> callback, Core::Object* parent = nullptr) + static NonnullRefPtr<Action> create(const StringView& text, Function<void(Action&)> callback, Core::Object* parent = nullptr) { - return adopt(*new GAction(text, move(callback), parent)); + return adopt(*new Action(text, move(callback), parent)); } - static NonnullRefPtr<GAction> create(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, Core::Object* parent = nullptr) + static NonnullRefPtr<Action> create(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(Action&)> callback, Core::Object* parent = nullptr) { - return adopt(*new GAction(text, move(icon), move(callback), parent)); + return adopt(*new Action(text, move(icon), move(callback), parent)); } - static NonnullRefPtr<GAction> create(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> callback, Core::Object* parent = nullptr) + static NonnullRefPtr<Action> create(const StringView& text, const Shortcut& shortcut, Function<void(Action&)> callback, Core::Object* parent = nullptr) { - return adopt(*new GAction(text, shortcut, move(callback), parent)); + return adopt(*new Action(text, shortcut, move(callback), parent)); } - static NonnullRefPtr<GAction> create(const StringView& text, const GShortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, Core::Object* parent = nullptr) + static NonnullRefPtr<Action> create(const StringView& text, const Shortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(Action&)> callback, Core::Object* parent = nullptr) { - return adopt(*new GAction(text, shortcut, move(icon), move(callback), parent)); + return adopt(*new Action(text, shortcut, move(icon), move(callback), parent)); } - virtual ~GAction() override; + virtual ~Action() override; String text() const { return m_text; } - GShortcut shortcut() const { return m_shortcut; } + Shortcut shortcut() const { return m_shortcut; } const GraphicsBitmap* icon() const { return m_icon.ptr(); } void set_icon(const GraphicsBitmap* icon) { m_icon = icon; } const Core::Object* activator() const { return m_activator.ptr(); } Core::Object* activator() { return m_activator.ptr(); } - Function<void(GAction&)> on_activation; + Function<void(Action&)> on_activation; void activate(Core::Object* activator = nullptr); @@ -113,21 +115,21 @@ public: } void set_checked(bool); - void register_button(Badge<GButton>, GButton&); - void unregister_button(Badge<GButton>, GButton&); - void register_menu_item(Badge<GMenuItem>, GMenuItem&); - void unregister_menu_item(Badge<GMenuItem>, GMenuItem&); + void register_button(Badge<Button>, Button&); + void unregister_button(Badge<Button>, Button&); + void register_menu_item(Badge<MenuItem>, MenuItem&); + void unregister_menu_item(Badge<MenuItem>, MenuItem&); - const GActionGroup* group() const { return m_action_group.ptr(); } - void set_group(Badge<GActionGroup>, GActionGroup*); + const ActionGroup* group() const { return m_action_group.ptr(); } + void set_group(Badge<ActionGroup>, ActionGroup*); private: virtual bool is_action() const override { return true; } - GAction(const StringView& text, Function<void(GAction&)> = nullptr, Core::Object* = nullptr); - GAction(const StringView& text, const GShortcut&, Function<void(GAction&)> = nullptr, Core::Object* = nullptr); - GAction(const StringView& text, const GShortcut&, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, Core::Object* = nullptr); - GAction(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, Core::Object* = nullptr); + Action(const StringView& text, Function<void(Action&)> = nullptr, Core::Object* = nullptr); + Action(const StringView& text, const Shortcut&, Function<void(Action&)> = nullptr, Core::Object* = nullptr); + Action(const StringView& text, const Shortcut&, RefPtr<GraphicsBitmap>&& icon, Function<void(Action&)> = nullptr, Core::Object* = nullptr); + Action(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(Action&)> = nullptr, Core::Object* = nullptr); template<typename Callback> void for_each_toolbar_button(Callback); @@ -136,20 +138,22 @@ private: String m_text; RefPtr<GraphicsBitmap> m_icon; - GShortcut m_shortcut; + Shortcut m_shortcut; bool m_enabled { true }; bool m_checkable { false }; bool m_checked { false }; ShortcutScope m_scope { ShortcutScope::None }; - HashTable<GButton*> m_buttons; - HashTable<GMenuItem*> m_menu_items; - WeakPtr<GActionGroup> m_action_group; + HashTable<Button*> m_buttons; + HashTable<MenuItem*> m_menu_items; + WeakPtr<ActionGroup> m_action_group; WeakPtr<Core::Object> m_activator; }; +} + template<> -inline bool Core::is<GAction>(const Core::Object& object) +inline bool Core::is<GUI::Action>(const Core::Object& object) { return object.is_action(); } diff --git a/Libraries/LibGUI/GActionGroup.cpp b/Libraries/LibGUI/GActionGroup.cpp index fc11b23bde..cb469ddd57 100644 --- a/Libraries/LibGUI/GActionGroup.cpp +++ b/Libraries/LibGUI/GActionGroup.cpp @@ -27,14 +27,18 @@ #include <LibGUI/GAction.h> #include <LibGUI/GActionGroup.h> -void GActionGroup::add_action(GAction& action) +namespace GUI { + +void ActionGroup::add_action(Action& action) { action.set_group({}, this); m_actions.set(&action); } -void GActionGroup::remove_action(GAction& action) +void ActionGroup::remove_action(Action& action) { action.set_group({}, nullptr); m_actions.remove(&action); } + +} diff --git a/Libraries/LibGUI/GActionGroup.h b/Libraries/LibGUI/GActionGroup.h index f83e5dbd24..9816e0db30 100644 --- a/Libraries/LibGUI/GActionGroup.h +++ b/Libraries/LibGUI/GActionGroup.h @@ -29,15 +29,17 @@ #include <AK/HashTable.h> #include <AK/Weakable.h> -class GAction; +namespace GUI { -class GActionGroup : public Weakable<GActionGroup> { +class Action; + +class ActionGroup : public Weakable<ActionGroup> { public: - GActionGroup() {} - ~GActionGroup() {} + ActionGroup() {} + ~ActionGroup() {} - void add_action(GAction&); - void remove_action(GAction&); + void add_action(Action&); + void remove_action(Action&); bool is_exclusive() const { return m_exclusive; } void set_exclusive(bool exclusive) { m_exclusive = exclusive; } @@ -55,7 +57,9 @@ public: } private: - HashTable<GAction*> m_actions; + HashTable<Action*> m_actions; bool m_exclusive { false }; bool m_unchecking_allowed { false }; }; + +} diff --git a/Libraries/LibGUI/GApplication.cpp b/Libraries/LibGUI/GApplication.cpp index 893a952dfe..9afcebb45b 100644 --- a/Libraries/LibGUI/GApplication.cpp +++ b/Libraries/LibGUI/GApplication.cpp @@ -34,34 +34,36 @@ #include <LibGUI/GWindow.h> #include <LibGUI/GWindowServerConnection.h> -static GApplication* s_the; +namespace GUI { -GApplication& GApplication::the() +static Application* s_the; + +Application& Application::the() { ASSERT(s_the); return *s_the; } -GApplication::GApplication(int argc, char** argv) +Application::Application(int argc, char** argv) { (void)argc; (void)argv; ASSERT(!s_the); s_the = this; m_event_loop = make<Core::EventLoop>(); - GWindowServerConnection::the(); + WindowServerConnection::the(); if (argc > 0) m_invoked_as = argv[0]; for (int i = 1; i < argc; i++) m_args.append(argv[i]); } -GApplication::~GApplication() +Application::~Application() { s_the = nullptr; } -int GApplication::exec() +int Application::exec() { int exit_code = m_event_loop->exec(); // NOTE: Maybe it would be cool to return instead of exit()? @@ -70,12 +72,12 @@ int GApplication::exec() return exit_code; } -void GApplication::quit(int exit_code) +void Application::quit(int exit_code) { m_event_loop->quit(exit_code); } -void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar) +void Application::set_menubar(OwnPtr<MenuBar>&& menubar) { if (m_menubar) m_menubar->notify_removed_from_application({}); @@ -84,30 +86,30 @@ void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar) m_menubar->notify_added_to_application({}); } -void GApplication::register_global_shortcut_action(Badge<GAction>, GAction& action) +void Application::register_global_shortcut_action(Badge<Action>, Action& action) { m_global_shortcut_actions.set(action.shortcut(), &action); } -void GApplication::unregister_global_shortcut_action(Badge<GAction>, GAction& action) +void Application::unregister_global_shortcut_action(Badge<Action>, Action& action) { m_global_shortcut_actions.remove(action.shortcut()); } -GAction* GApplication::action_for_key_event(const GKeyEvent& event) +Action* Application::action_for_key_event(const KeyEvent& event) { - auto it = m_global_shortcut_actions.find(GShortcut(event.modifiers(), (KeyCode)event.key())); + auto it = m_global_shortcut_actions.find(Shortcut(event.modifiers(), (KeyCode)event.key())); if (it == m_global_shortcut_actions.end()) return nullptr; return (*it).value; } -class GApplication::TooltipWindow final : public GWindow { +class Application::TooltipWindow final : public Window { public: TooltipWindow() { - set_window_type(GWindowType::Tooltip); - m_label = GLabel::construct(); + set_window_type(WindowType::Tooltip); + m_label = Label::construct(); m_label->set_background_color(Color::from_rgb(0xdac7b5)); m_label->set_fill_with_background_color(true); m_label->set_frame_thickness(1); @@ -124,10 +126,10 @@ public: m_label->set_text(tooltip); } - RefPtr<GLabel> m_label; + RefPtr<Label> m_label; }; -void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_location) +void Application::show_tooltip(const StringView& tooltip, const Point& screen_location) { if (!m_tooltip_window) { m_tooltip_window = new TooltipWindow; @@ -135,7 +137,7 @@ void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_l } m_tooltip_window->set_tooltip(tooltip); - Rect desktop_rect = GDesktop::the().rect(); + Rect desktop_rect = Desktop::the().rect(); const int margin = 30; Point adjusted_pos = screen_location; @@ -150,7 +152,7 @@ void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_l m_tooltip_window->show(); } -void GApplication::hide_tooltip() +void Application::hide_tooltip() { if (m_tooltip_window) { m_tooltip_window->hide(); @@ -158,19 +160,19 @@ void GApplication::hide_tooltip() } } -void GApplication::did_create_window(Badge<GWindow>) +void Application::did_create_window(Badge<Window>) { if (m_event_loop->was_exit_requested()) m_event_loop->unquit(); } -void GApplication::did_delete_last_window(Badge<GWindow>) +void Application::did_delete_last_window(Badge<Window>) { if (m_quit_when_last_window_deleted) m_event_loop->quit(0); } -void GApplication::set_system_palette(SharedBuffer& buffer) +void Application::set_system_palette(SharedBuffer& buffer) { if (!m_system_palette) m_system_palette = PaletteImpl::create_with_shared_buffer(buffer); @@ -181,7 +183,9 @@ void GApplication::set_system_palette(SharedBuffer& buffer) m_palette = m_system_palette; } -void GApplication::set_palette(const Palette& palette) +void Application::set_palette(const Palette& palette) { m_palette = palette.impl(); } + +} diff --git a/Libraries/LibGUI/GApplication.h b/Libraries/LibGUI/GApplication.h index 0067d8da88..a8259f546b 100644 --- a/Libraries/LibGUI/GApplication.h +++ b/Libraries/LibGUI/GApplication.h @@ -38,29 +38,30 @@ class SharedBuffer; namespace Core { class EventLoop; } - -class GAction; -class GKeyEvent; -class GMenuBar; -class GWindow; -class GWindowServerConnection; class Palette; class Point; -class GApplication { +namespace GUI { +class Action; +class KeyEvent; +class MenuBar; +class Window; +class WindowServerConnection; + +class Application { public: - static GApplication& the(); - GApplication(int argc, char** argv); - ~GApplication(); + static Application& the(); + Application(int argc, char** argv); + ~Application(); int exec(); void quit(int = 0); - void set_menubar(OwnPtr<GMenuBar>&&); - GAction* action_for_key_event(const GKeyEvent&); + void set_menubar(OwnPtr<MenuBar>&&); + Action* action_for_key_event(const KeyEvent&); - void register_global_shortcut_action(Badge<GAction>, GAction&); - void unregister_global_shortcut_action(Badge<GAction>, GAction&); + void register_global_shortcut_action(Badge<Action>, Action&); + void unregister_global_shortcut_action(Badge<Action>, Action&); void show_tooltip(const StringView&, const Point& screen_location); void hide_tooltip(); @@ -68,8 +69,8 @@ public: bool quit_when_last_window_deleted() const { return m_quit_when_last_window_deleted; } void set_quit_when_last_window_deleted(bool b) { m_quit_when_last_window_deleted = b; } - void did_create_window(Badge<GWindow>); - void did_delete_last_window(Badge<GWindow>); + void did_create_window(Badge<Window>); + void did_delete_last_window(Badge<Window>); const String& invoked_as() const { return m_invoked_as; } const Vector<String>& args() const { return m_args; } @@ -81,13 +82,15 @@ public: private: OwnPtr<Core::EventLoop> m_event_loop; - OwnPtr<GMenuBar> m_menubar; + OwnPtr<MenuBar> m_menubar; RefPtr<PaletteImpl> m_palette; RefPtr<PaletteImpl> m_system_palette; - HashMap<GShortcut, GAction*> m_global_shortcut_actions; + HashMap<Shortcut, Action*> m_global_shortcut_actions; class TooltipWindow; TooltipWindow* m_tooltip_window { nullptr }; bool m_quit_when_last_window_deleted { true }; String m_invoked_as; Vector<String> m_args; }; + +} diff --git a/Libraries/LibGUI/GBoxLayout.cpp b/Libraries/LibGUI/GBoxLayout.cpp index c803f47e58..9707b58bf5 100644 --- a/Libraries/LibGUI/GBoxLayout.cpp +++ b/Libraries/LibGUI/GBoxLayout.cpp @@ -25,24 +25,25 @@ */ #include <LibGUI/GBoxLayout.h> -#include <LibGUI/GWidget.h> #include <stdio.h> //#define GBOXLAYOUT_DEBUG -GBoxLayout::GBoxLayout(Orientation orientation) +namespace GUI { + +BoxLayout::BoxLayout(Orientation orientation) : m_orientation(orientation) { } -void GBoxLayout::run(GWidget& widget) +void BoxLayout::run(Widget& widget) { bool should_log = false; #ifdef GBOXLAYOUT_DEBUG should_log = true; #endif if (should_log) - dbgprintf("GBoxLayout: running layout on %s{%p}, entry count: %d\n", widget.class_name(), &widget, m_entries.size()); + dbgprintf("BoxLayout: running layout on %s{%p}, entry count: %d\n", widget.class_name(), &widget, m_entries.size()); if (m_entries.is_empty()) return; @@ -53,7 +54,7 @@ void GBoxLayout::run(GWidget& widget) int number_of_visible_entries = 0; if (should_log) - dbgprintf("GBoxLayout: Starting with available size: %s\n", available_size.to_string().characters()); + dbgprintf("BoxLayout: Starting with available size: %s\n", available_size.to_string().characters()); for (auto& entry : m_entries) { if (entry.type == Entry::Type::Spacer) { @@ -67,12 +68,12 @@ void GBoxLayout::run(GWidget& widget) ++number_of_visible_entries; if (entry.widget && entry.widget->size_policy(orientation()) == SizePolicy::Fixed) { if (should_log) { - dbgprintf("GBoxLayout: Subtracting for fixed %s{%p}, size: %s\n", entry.widget->class_name(), entry.widget.ptr(), entry.widget->preferred_size().to_string().characters()); - dbgprintf("GBoxLayout: Available size before: %s\n", available_size.to_string().characters()); + dbgprintf("BoxLayout: Subtracting for fixed %s{%p}, size: %s\n", entry.widget->class_name(), entry.widget.ptr(), entry.widget->preferred_size().to_string().characters()); + dbgprintf("BoxLayout: Available size before: %s\n", available_size.to_string().characters()); } available_size -= entry.widget->preferred_size(); if (should_log) - dbgprintf("GBoxLayout: Available size after: %s\n", available_size.to_string().characters()); + dbgprintf("BoxLayout: Available size after: %s\n", available_size.to_string().characters()); ++number_of_entries_with_fixed_size; } available_size -= { spacing(), spacing() }; @@ -83,12 +84,12 @@ void GBoxLayout::run(GWidget& widget) available_size -= { margins().left() + margins().right(), margins().top() + margins().bottom() }; if (should_log) - dbgprintf("GBoxLayout: Number of visible: %d/%d\n", number_of_visible_entries, m_entries.size()); + dbgprintf("BoxLayout: Number of visible: %d/%d\n", number_of_visible_entries, m_entries.size()); int number_of_entries_with_automatic_size = number_of_visible_entries - number_of_entries_with_fixed_size; if (should_log) - dbgprintf("GBoxLayout: available_size=%s, fixed=%d, fill=%d\n", available_size.to_string().characters(), number_of_entries_with_fixed_size, number_of_entries_with_automatic_size); + dbgprintf("BoxLayout: available_size=%s, fixed=%d, fill=%d\n", available_size.to_string().characters(), number_of_entries_with_fixed_size, number_of_entries_with_automatic_size); Size automatic_size; @@ -103,7 +104,7 @@ void GBoxLayout::run(GWidget& widget) } if (should_log) - dbgprintf("GBoxLayout: automatic_size=%s\n", automatic_size.to_string().characters()); + dbgprintf("BoxLayout: automatic_size=%s\n", automatic_size.to_string().characters()); int current_x = margins().left(); int current_y = margins().top(); @@ -143,7 +144,7 @@ void GBoxLayout::run(GWidget& widget) } if (should_log) - dbgprintf("GBoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters()); + dbgprintf("BoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters()); entry.widget->set_relative_rect(rect); if (orientation() == Orientation::Horizontal) @@ -152,3 +153,5 @@ void GBoxLayout::run(GWidget& widget) current_y += rect.height() + spacing(); } } + +} diff --git a/Libraries/LibGUI/GBoxLayout.h b/Libraries/LibGUI/GBoxLayout.h index 26998b685d..b5f649243b 100644 --- a/Libraries/LibGUI/GBoxLayout.h +++ b/Libraries/LibGUI/GBoxLayout.h @@ -29,33 +29,37 @@ #include <LibGUI/GLayout.h> #include <LibGUI/GWidget.h> -class GBoxLayout : public GLayout { +namespace GUI { + +class BoxLayout : public Layout { public: - explicit GBoxLayout(Orientation); - virtual ~GBoxLayout() override {} + explicit BoxLayout(Orientation); + virtual ~BoxLayout() override {} Orientation orientation() const { return m_orientation; } - virtual void run(GWidget&) override; + virtual void run(Widget&) override; private: Orientation m_orientation; }; -class GVBoxLayout final : public GBoxLayout { +class VBoxLayout final : public BoxLayout { public: - explicit GVBoxLayout() - : GBoxLayout(Orientation::Vertical) + explicit VBoxLayout() + : BoxLayout(Orientation::Vertical) { } - virtual ~GVBoxLayout() override {} + virtual ~VBoxLayout() override {} }; -class GHBoxLayout final : public GBoxLayout { +class HBoxLayout final : public BoxLayout { public: - explicit GHBoxLayout() - : GBoxLayout(Orientation::Horizontal) + explicit HBoxLayout() + : BoxLayout(Orientation::Horizontal) { } - virtual ~GHBoxLayout() override {} + virtual ~HBoxLayout() override {} }; + +} diff --git a/Libraries/LibGUI/GButton.cpp b/Libraries/LibGUI/GButton.cpp index fa3079d38d..b3e31ef0a8 100644 --- a/Libraries/LibGUI/GButton.cpp +++ b/Libraries/LibGUI/GButton.cpp @@ -32,25 +32,27 @@ #include <LibGUI/GButton.h> #include <LibGUI/GPainter.h> -GButton::GButton(GWidget* parent) - : GAbstractButton(parent) +namespace GUI { + +Button::Button(Widget* parent) + : AbstractButton(parent) { } -GButton::GButton(const StringView& text, GWidget* parent) - : GAbstractButton(text, parent) +Button::Button(const StringView& text, Widget* parent) + : AbstractButton(text, parent) { } -GButton::~GButton() +Button::~Button() { if (m_action) m_action->unregister_button({}, *this); } -void GButton::paint_event(GPaintEvent& event) +void Button::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); StylePainter::paint_button(painter, rect(), palette(), m_button_style, is_being_pressed(), is_hovered(), is_checked(), is_enabled()); @@ -83,7 +85,7 @@ void GButton::paint_event(GPaintEvent& event) paint_text(painter, text_rect, font, text_alignment()); } -void GButton::click() +void Button::click() { if (!is_enabled()) return; @@ -98,7 +100,7 @@ void GButton::click() m_action->activate(this); } -void GButton::set_action(GAction& action) +void Button::set_action(Action& action) { m_action = action.make_weak_ptr(); action.register_button({}, *this); @@ -108,7 +110,7 @@ void GButton::set_action(GAction& action) set_checked(action.is_checked()); } -void GButton::set_icon(RefPtr<GraphicsBitmap>&& icon) +void Button::set_icon(RefPtr<GraphicsBitmap>&& icon) { if (m_icon == icon) return; @@ -116,7 +118,7 @@ void GButton::set_icon(RefPtr<GraphicsBitmap>&& icon) update(); } -bool GButton::is_uncheckable() const +bool Button::is_uncheckable() const { if (!m_action) return true; @@ -124,3 +126,5 @@ bool GButton::is_uncheckable() const return true; return m_action->group()->is_unchecking_allowed(); } + +} diff --git a/Libraries/LibGUI/GButton.h b/Libraries/LibGUI/GButton.h index 1acd09dadf..f55551f088 100644 --- a/Libraries/LibGUI/GButton.h +++ b/Libraries/LibGUI/GButton.h @@ -33,12 +33,14 @@ #include <LibDraw/TextAlignment.h> #include <LibGUI/GAbstractButton.h> -class GAction; +namespace GUI { -class GButton : public GAbstractButton { - C_OBJECT(GButton) +class Action; + +class Button : public AbstractButton { + C_OBJECT(Button) public: - virtual ~GButton() override; + virtual ~Button() override; void set_icon(RefPtr<GraphicsBitmap>&&); const GraphicsBitmap* icon() const { return m_icon.ptr(); } @@ -47,14 +49,14 @@ public: void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; } TextAlignment text_alignment() const { return m_text_alignment; } - Function<void(GButton&)> on_click; + Function<void(Button&)> on_click; void set_button_style(ButtonStyle style) { m_button_style = style; } ButtonStyle button_style() const { return m_button_style; } virtual void click() override; - void set_action(GAction&); + void set_action(Action&); virtual bool accepts_focus() const override { return m_focusable; } virtual bool is_uncheckable() const override; @@ -62,14 +64,16 @@ public: void set_focusable(bool b) { m_focusable = b; } protected: - GButton(const StringView& text, GWidget* parent); - explicit GButton(GWidget* parent); - virtual void paint_event(GPaintEvent&) override; + Button(const StringView& text, Widget* parent); + explicit Button(Widget* parent); + virtual void paint_event(PaintEvent&) override; private: RefPtr<GraphicsBitmap> m_icon; ButtonStyle m_button_style { ButtonStyle::Normal }; TextAlignment m_text_alignment { TextAlignment::Center }; - WeakPtr<GAction> m_action; + WeakPtr<Action> m_action; bool m_focusable { true }; }; + +} diff --git a/Libraries/LibGUI/GCheckBox.cpp b/Libraries/LibGUI/GCheckBox.cpp index 9ecce207ce..0df6e7397f 100644 --- a/Libraries/LibGUI/GCheckBox.cpp +++ b/Libraries/LibGUI/GCheckBox.cpp @@ -31,6 +31,8 @@ #include <LibGUI/GCheckBox.h> #include <LibGUI/GPainter.h> +namespace GUI { + static const char* s_checked_bitmap_data = { " " " # " @@ -49,23 +51,23 @@ static const int s_checked_bitmap_height = 9; static const int s_box_width = 13; static const int s_box_height = 13; -GCheckBox::GCheckBox(GWidget* parent) - : GAbstractButton(parent) +CheckBox::CheckBox(Widget* parent) + : AbstractButton(parent) { } -GCheckBox::GCheckBox(const StringView& text, GWidget* parent) - : GAbstractButton(text, parent) +CheckBox::CheckBox(const StringView& text, Widget* parent) + : AbstractButton(text, parent) { } -GCheckBox::~GCheckBox() +CheckBox::~CheckBox() { } -void GCheckBox::paint_event(GPaintEvent& event) +void CheckBox::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); auto text_rect = rect(); @@ -96,9 +98,11 @@ void GCheckBox::paint_event(GPaintEvent& event) paint_text(painter, text_rect, font(), TextAlignment::TopLeft); } -void GCheckBox::click() +void CheckBox::click() { if (!is_enabled()) return; set_checked(!is_checked()); } + +} diff --git a/Libraries/LibGUI/GCheckBox.h b/Libraries/LibGUI/GCheckBox.h index 1d2864f1b8..9045a03b2b 100644 --- a/Libraries/LibGUI/GCheckBox.h +++ b/Libraries/LibGUI/GCheckBox.h @@ -30,20 +30,24 @@ #include <AK/String.h> #include <LibGUI/GAbstractButton.h> -class GCheckBox : public GAbstractButton { - C_OBJECT(GCheckBox) +namespace GUI { + +class CheckBox : public AbstractButton { + C_OBJECT(CheckBox) public: - virtual ~GCheckBox() override; + virtual ~CheckBox() override; virtual void click() override; private: - GCheckBox(const StringView&, GWidget* parent); - explicit GCheckBox(GWidget* parent); + CheckBox(const StringView&, Widget* parent); + explicit CheckBox(Widget* parent); // These don't make sense for a check box, so hide them. - using GAbstractButton::auto_repeat_interval; - using GAbstractButton::set_auto_repeat_interval; + using AbstractButton::auto_repeat_interval; + using AbstractButton::set_auto_repeat_interval; - virtual void paint_event(GPaintEvent&) override; + virtual void paint_event(PaintEvent&) override; }; + +} diff --git a/Libraries/LibGUI/GClipboard.cpp b/Libraries/LibGUI/GClipboard.cpp index 3838414fbd..7a260db665 100644 --- a/Libraries/LibGUI/GClipboard.cpp +++ b/Libraries/LibGUI/GClipboard.cpp @@ -28,30 +28,32 @@ #include <LibGUI/GClipboard.h> #include <LibGUI/GWindowServerConnection.h> -GClipboard& GClipboard::the() +namespace GUI { + +Clipboard& Clipboard::the() { - static GClipboard* s_the; + static Clipboard* s_the; if (!s_the) - s_the = new GClipboard; + s_the = new Clipboard; return *s_the; } -GClipboard::GClipboard() +Clipboard::Clipboard() { } -GClipboard::DataAndType GClipboard::data_and_type() const +Clipboard::DataAndType Clipboard::data_and_type() const { - auto response = GWindowServerConnection::the().send_sync<WindowServer::GetClipboardContents>(); + auto response = WindowServerConnection::the().send_sync<WindowServer::GetClipboardContents>(); if (response->shared_buffer_id() < 0) return {}; auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(response->shared_buffer_id()); if (!shared_buffer) { - dbgprintf("GClipboard::data() failed to attach to the shared buffer\n"); + dbgprintf("GUI::Clipboard::data() failed to attach to the shared buffer\n"); return {}; } if (response->content_size() > shared_buffer->size()) { - dbgprintf("GClipboard::data() clipping contents size is greater than shared buffer size\n"); + dbgprintf("GUI::Clipboard::data() clipping contents size is greater than shared buffer size\n"); return {}; } auto data = String((const char*)shared_buffer->data(), response->content_size()); @@ -59,11 +61,11 @@ GClipboard::DataAndType GClipboard::data_and_type() const return { data, type }; } -void GClipboard::set_data(const StringView& data, const String& type) +void Clipboard::set_data(const StringView& data, const String& type) { auto shared_buffer = SharedBuffer::create_with_size(data.length() + 1); if (!shared_buffer) { - dbgprintf("GClipboard::set_data() failed to create a shared buffer\n"); + dbgprintf("GUI::Clipboard::set_data() failed to create a shared buffer\n"); return; } if (!data.is_empty()) @@ -71,13 +73,15 @@ void GClipboard::set_data(const StringView& data, const String& type) else ((u8*)shared_buffer->data())[0] = '\0'; shared_buffer->seal(); - shared_buffer->share_with(GWindowServerConnection::the().server_pid()); + shared_buffer->share_with(WindowServerConnection::the().server_pid()); - GWindowServerConnection::the().send_sync<WindowServer::SetClipboardContents>(shared_buffer->shared_buffer_id(), data.length(), type); + WindowServerConnection::the().send_sync<WindowServer::SetClipboardContents>(shared_buffer->shared_buffer_id(), data.length(), type); } -void GClipboard::did_receive_clipboard_contents_changed(Badge<GWindowServerConnection>, const String& data_type) +void Clipboard::did_receive_clipboard_contents_changed(Badge<WindowServerConnection>, const String& data_type) { if (on_content_change) on_content_change(data_type); } + +} diff --git a/Libraries/LibGUI/GClipboard.h b/Libraries/LibGUI/GClipboard.h index 01b3d3a03e..832ef0e334 100644 --- a/Libraries/LibGUI/GClipboard.h +++ b/Libraries/LibGUI/GClipboard.h @@ -30,11 +30,13 @@ #include <AK/Function.h> #include <AK/String.h> -class GWindowServerConnection; +namespace GUI { -class GClipboard { +class WindowServerConnection; + +class Clipboard { public: - static GClipboard& the(); + static Clipboard& the(); String data() const { return data_and_type().data; } String type() const { return data_and_type().type; } @@ -47,10 +49,12 @@ public: DataAndType data_and_type() const; - void did_receive_clipboard_contents_changed(Badge<GWindowServerConnection>, const String& data_type); + void did_receive_clipboard_contents_changed(Badge<WindowServerConnection>, const String& data_type); Function<void(const String& data_type)> on_content_change; private: - GClipboard(); + Clipboard(); }; + +} diff --git a/Libraries/LibGUI/GColorPicker.cpp b/Libraries/LibGUI/GColorPicker.cpp index 8ff9f5ce45..da5e057432 100644 --- a/Libraries/LibGUI/GColorPicker.cpp +++ b/Libraries/LibGUI/GColorPicker.cpp @@ -31,31 +31,33 @@ #include <LibGUI/GSpinBox.h> #include <LibGUI/GWidget.h> -GColorPicker::GColorPicker(Color color, Core::Object* parent) - : GDialog(parent) +namespace GUI { + +ColorPicker::ColorPicker(Color color, Core::Object* parent) + : Dialog(parent) , m_color(color) { set_title("Edit Color"); build(); } -GColorPicker::~GColorPicker() +ColorPicker::~ColorPicker() { } -void GColorPicker::build() +void ColorPicker::build() { - auto horizontal_container = GWidget::construct(); + auto horizontal_container = Widget::construct(); horizontal_container->set_fill_with_background_color(true); - horizontal_container->set_layout(make<GHBoxLayout>()); + horizontal_container->set_layout(make<HBoxLayout>()); horizontal_container->layout()->set_margins({ 4, 4, 4, 4 }); set_main_widget(horizontal_container); - auto left_vertical_container = GWidget::construct(horizontal_container.ptr()); - left_vertical_container->set_layout(make<GVBoxLayout>()); + auto left_vertical_container = Widget::construct(horizontal_container.ptr()); + left_vertical_container->set_layout(make<VBoxLayout>()); - auto right_vertical_container = GWidget::construct(horizontal_container.ptr()); - right_vertical_container->set_layout(make<GVBoxLayout>()); + auto right_vertical_container = Widget::construct(horizontal_container.ptr()); + right_vertical_container->set_layout(make<VBoxLayout>()); enum RGBComponent { Red, @@ -63,27 +65,27 @@ void GColorPicker::build() Blue }; - m_preview_widget = GFrame::construct(right_vertical_container); + m_preview_widget = Frame::construct(right_vertical_container); auto pal = m_preview_widget->palette(); pal.set_color(ColorRole::Background, m_color); m_preview_widget->set_fill_with_background_color(true); m_preview_widget->set_palette(pal); right_vertical_container->layout()->add_spacer(); - auto cancel_button = GButton::construct("Cancel", right_vertical_container); + auto cancel_button = Button::construct("Cancel", right_vertical_container); cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); cancel_button->set_preferred_size(0, 20); cancel_button->on_click = [&](auto&) { - done(GDialog::ExecCancel); + done(Dialog::ExecCancel); }; - auto ok_button = GButton::construct("Okay", right_vertical_container); + auto ok_button = Button::construct("Okay", right_vertical_container); ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); ok_button->set_preferred_size(0, 20); ok_button->on_click = [&](auto&) { - done(GDialog::ExecOK); + done(Dialog::ExecOK); }; auto make_spinbox = [&](RGBComponent component, int initial_value) { - auto spinbox = GSpinBox::construct(left_vertical_container); + auto spinbox = SpinBox::construct(left_vertical_container); spinbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); spinbox->set_preferred_size(0, 20); spinbox->set_min(0); @@ -110,3 +112,5 @@ void GColorPicker::build() make_spinbox(Green, m_color.green()); make_spinbox(Blue, m_color.blue()); } + +} diff --git a/Libraries/LibGUI/GColorPicker.h b/Libraries/LibGUI/GColorPicker.h index 4554270430..eb902b8519 100644 --- a/Libraries/LibGUI/GColorPicker.h +++ b/Libraries/LibGUI/GColorPicker.h @@ -28,20 +28,24 @@ #include <LibGUI/GDialog.h> -class GFrame; +namespace GUI { -class GColorPicker final : public GDialog { - C_OBJECT(GColorPicker) +class Frame; + +class ColorPicker final : public Dialog { + C_OBJECT(ColorPicker) public: - virtual ~GColorPicker() override; + virtual ~ColorPicker() override; Color color() const { return m_color; } private: - explicit GColorPicker(Color, Core::Object* parent = nullptr); + explicit ColorPicker(Color, Core::Object* parent = nullptr); void build(); Color m_color; - RefPtr<GFrame> m_preview_widget; + RefPtr<Frame> m_preview_widget; }; + +} diff --git a/Libraries/LibGUI/GColumnsView.cpp b/Libraries/LibGUI/GColumnsView.cpp index f762dee969..56882efe40 100644 --- a/Libraries/LibGUI/GColumnsView.cpp +++ b/Libraries/LibGUI/GColumnsView.cpp @@ -29,6 +29,8 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GScrollBar.h> +namespace GUI { + static const char* s_arrow_bitmap_data = { " " " # " @@ -43,8 +45,8 @@ static const char* s_arrow_bitmap_data = { static const int s_arrow_bitmap_width = 9; static const int s_arrow_bitmap_height = 9; -GColumnsView::GColumnsView(GWidget* parent) - : GAbstractView(parent) +ColumnsView::ColumnsView(Widget* parent) + : AbstractView(parent) { set_fill_with_background_color(true); set_background_role(ColorRole::Base); @@ -56,18 +58,18 @@ GColumnsView::GColumnsView(GWidget* parent) m_columns.append({ {}, 0 }); } -GColumnsView::~GColumnsView() +ColumnsView::~ColumnsView() { } -void GColumnsView::paint_event(GPaintEvent& event) +void ColumnsView::paint_event(PaintEvent& event) { - GAbstractView::paint_event(event); + AbstractView::paint_event(event); if (!model()) return; - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(frame_inner_rect()); painter.add_clip_rect(event.rect()); painter.translate(frame_thickness(), frame_thickness()); @@ -83,7 +85,7 @@ void GColumnsView::paint_event(GPaintEvent& event) int row_count = model()->row_count(column.parent_index); for (int row = 0; row < row_count; row++) { - GModelIndex index = model()->index(row, m_model_column, column.parent_index); + ModelIndex index = model()->index(row, m_model_column, column.parent_index); ASSERT(index.is_valid()); bool is_selected_row = selection().contains(index); @@ -102,7 +104,7 @@ void GColumnsView::paint_event(GPaintEvent& event) Rect row_rect { column_x, row * item_height(), column.width, item_height() }; painter.fill_rect(row_rect, background_color); - auto icon = model()->data(index, GModel::Role::Icon); + auto icon = model()->data(index, Model::Role::Icon); Rect icon_rect = { column_x + icon_spacing(), 0, icon_size(), icon_size() }; icon_rect.center_vertically_within(row_rect); if (icon.is_icon()) @@ -136,12 +138,12 @@ void GColumnsView::paint_event(GPaintEvent& event) } } -void GColumnsView::push_column(GModelIndex& parent_index) +void ColumnsView::push_column(ModelIndex& parent_index) { ASSERT(model()); // Drop columns at the end. - GModelIndex grandparent = model()->parent_index(parent_index); + ModelIndex grandparent = model()->parent_index(parent_index); for (int i = m_columns.size() - 1; i > 0; i--) { if (m_columns[i].parent_index == grandparent) break; @@ -156,7 +158,7 @@ void GColumnsView::push_column(GModelIndex& parent_index) update(); } -void GColumnsView::update_column_sizes() +void ColumnsView::update_column_sizes() { if (!model()) return; @@ -173,7 +175,7 @@ void GColumnsView::update_column_sizes() column.width = 10; for (int row = 0; row < row_count; row++) { - GModelIndex index = model()->index(row, m_model_column, column.parent_index); + ModelIndex index = model()->index(row, m_model_column, column.parent_index); ASSERT(index.is_valid()); auto text = model()->data(index).to_string(); int row_width = icon_spacing() + icon_size() + icon_spacing() + font().width(text) + icon_spacing() + s_arrow_bitmap_width + icon_spacing(); @@ -186,7 +188,7 @@ void GColumnsView::update_column_sizes() set_content_size({ total_width, total_height }); } -GModelIndex GColumnsView::index_at_event_position(const Point& a_position) const +ModelIndex ColumnsView::index_at_event_position(const Point& a_position) const { if (!model()) return {}; @@ -214,14 +216,14 @@ GModelIndex GColumnsView::index_at_event_position(const Point& a_position) const return {}; } -void GColumnsView::mousedown_event(GMouseEvent& event) +void ColumnsView::mousedown_event(MouseEvent& event) { - GAbstractView::mousedown_event(event); + AbstractView::mousedown_event(event); if (!model()) return; - if (event.button() != GMouseButton::Left) + if (event.button() != MouseButton::Left) return; auto index = index_at_event_position(event.position()); @@ -231,9 +233,9 @@ void GColumnsView::mousedown_event(GMouseEvent& event) } } -void GColumnsView::did_update_model() +void ColumnsView::did_update_model() { - GAbstractView::did_update_model(); + AbstractView::did_update_model(); // FIXME: Don't drop the columns on minor updates. dbg() << "Model was updated; dropping columns :("; @@ -244,7 +246,7 @@ void GColumnsView::did_update_model() update(); } -void GColumnsView::keydown_event(GKeyEvent& event) +void ColumnsView::keydown_event(KeyEvent& event) { if (!model()) return; @@ -256,7 +258,7 @@ void GColumnsView::keydown_event(GKeyEvent& event) } if (event.key() == KeyCode::Key_Up) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); auto parent_index = model.parent_index(old_index); @@ -273,7 +275,7 @@ void GColumnsView::keydown_event(GKeyEvent& event) } if (event.key() == KeyCode::Key_Down) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); auto parent_index = model.parent_index(old_index); @@ -290,7 +292,7 @@ void GColumnsView::keydown_event(GKeyEvent& event) } if (event.key() == KeyCode::Key_Left) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.parent_index(old_index); @@ -305,7 +307,7 @@ void GColumnsView::keydown_event(GKeyEvent& event) } if (event.key() == KeyCode::Key_Right) { - GModelIndex old_index, new_index; + ModelIndex old_index, new_index; if (!selection().is_empty()) { old_index = selection().first(); new_index = model.index(0, m_model_column, old_index); @@ -321,3 +323,5 @@ void GColumnsView::keydown_event(GKeyEvent& event) return; } } + +} diff --git a/Libraries/LibGUI/GColumnsView.h b/Libraries/LibGUI/GColumnsView.h index b0f65fa94e..60da79ef56 100644 --- a/Libraries/LibGUI/GColumnsView.h +++ b/Libraries/LibGUI/GColumnsView.h @@ -29,18 +29,20 @@ #include <AK/Vector.h> #include <LibGUI/GAbstractView.h> -class GColumnsView : public GAbstractView { - C_OBJECT(GColumnsView) +namespace GUI { + +class ColumnsView : public AbstractView { + C_OBJECT(ColumnsView) public: int model_column() const { return m_model_column; } void set_model_column(int column) { m_model_column = column; } - virtual GModelIndex index_at_event_position(const Point&) const override; + virtual ModelIndex index_at_event_position(const Point&) const override; private: - GColumnsView(GWidget* parent = nullptr); - virtual ~GColumnsView(); - void push_column(GModelIndex& parent_index); + ColumnsView(Widget* parent = nullptr); + virtual ~ColumnsView(); + void push_column(ModelIndex& parent_index); void update_column_sizes(); int item_height() const { return 16; } @@ -49,12 +51,12 @@ private: int text_padding() const { return 2; } virtual void did_update_model() override; - virtual void paint_event(GPaintEvent&) override; - virtual void mousedown_event(GMouseEvent& event) override; - virtual void keydown_event(GKeyEvent& event) override; + virtual void paint_event(PaintEvent&) override; + virtual void mousedown_event(MouseEvent& event) override; + virtual void keydown_event(KeyEvent& event) override; struct Column { - GModelIndex parent_index; + ModelIndex parent_index; int width; // TODO: per-column vertical scroll? }; @@ -62,3 +64,5 @@ private: Vector<Column> m_columns; int m_model_column { 0 }; }; + +} diff --git a/Libraries/LibGUI/GComboBox.cpp b/Libraries/LibGUI/GComboBox.cpp index 13d3966f3e..6d904874a0 100644 --- a/Libraries/LibGUI/GComboBox.cpp +++ b/Libraries/LibGUI/GComboBox.cpp @@ -32,10 +32,12 @@ #include <LibGUI/GTextEditor.h> #include <LibGUI/GWindow.h> -GComboBox::GComboBox(GWidget* parent) - : GWidget(parent) +namespace GUI { + +ComboBox::ComboBox(Widget* parent) + : Widget(parent) { - m_editor = GTextEditor::construct(GTextEditor::Type::SingleLine, this); + m_editor = TextEditor::construct(TextEditor::Type::SingleLine, this); m_editor->on_change = [this] { if (on_change) on_change(m_editor->text(), m_list_view->selection().first()); @@ -44,7 +46,7 @@ GComboBox::GComboBox(GWidget* parent) if (on_return_pressed) on_return_pressed(); }; - m_open_button = GButton::construct(this); + m_open_button = Button::construct(this); m_open_button->set_focusable(false); m_open_button->set_text("\xc3\xb7"); m_open_button->on_click = [this](auto&) { @@ -54,11 +56,11 @@ GComboBox::GComboBox(GWidget* parent) open(); }; - m_list_window = GWindow::construct(this); + m_list_window = Window::construct(this); // FIXME: This is obviously not a tooltip window, but it's the closest thing to what we want atm. - m_list_window->set_window_type(GWindowType::Tooltip); + m_list_window->set_window_type(WindowType::Tooltip); - m_list_view = GListView::construct(nullptr); + m_list_view = ListView::construct(nullptr); m_list_view->horizontal_scrollbar().set_visible(false); m_list_window->set_main_widget(m_list_view); @@ -75,11 +77,11 @@ GComboBox::GComboBox(GWidget* parent) }; } -GComboBox::~GComboBox() +ComboBox::~ComboBox() { } -void GComboBox::resize_event(GResizeEvent& event) +void ComboBox::resize_event(ResizeEvent& event) { int frame_thickness = m_editor->frame_thickness(); int button_height = event.size().height() - frame_thickness * 2; @@ -88,17 +90,17 @@ void GComboBox::resize_event(GResizeEvent& event) m_editor->set_relative_rect(0, 0, width(), height()); } -void GComboBox::set_model(NonnullRefPtr<GModel> model) +void ComboBox::set_model(NonnullRefPtr<Model> model) { m_list_view->set_model(move(model)); } -void GComboBox::select_all() +void ComboBox::select_all() { m_editor->select_all(); } -void GComboBox::open() +void ComboBox::open() { if (!model()) return; @@ -117,32 +119,34 @@ void GComboBox::open() }; Rect list_window_rect { my_screen_rect.bottom_left(), size }; - list_window_rect.intersect(GDesktop::the().rect().shrunken(0, 128)); + list_window_rect.intersect(Desktop::the().rect().shrunken(0, 128)); m_list_window->set_rect(list_window_rect); m_list_window->show(); } -void GComboBox::close() +void ComboBox::close() { m_list_window->hide(); m_editor->set_focus(true); } -String GComboBox::text() const +String ComboBox::text() const { return m_editor->text(); } -void GComboBox::set_text(const String& text) +void ComboBox::set_text(const String& text) { m_editor->set_text(text); } -void GComboBox::set_only_allow_values_from_model(bool b) +void ComboBox::set_only_allow_values_from_model(bool b) { if (m_only_allow_values_from_model == b) return; m_only_allow_values_from_model = b; m_editor->set_readonly(m_only_allow_values_from_model); } + +} diff --git a/Libraries/LibGUI/GComboBox.h b/Libraries/LibGUI/GComboBox.h index 932efd7ec3..26142c04b4 100644 --- a/Libraries/LibGUI/GComboBox.h +++ b/Libraries/LibGUI/GComboBox.h @@ -29,13 +29,15 @@ #include <LibGUI/GListView.h> #include <LibGUI/GWidget.h> -class GButton; -class GTextEditor; +namespace GUI { -class GComboBox : public GWidget { - C_OBJECT(GComboBox) +class Button; +class TextEditor; + +class ComboBox : public Widget { + C_OBJECT(ComboBox) public: - virtual ~GComboBox() override; + virtual ~ComboBox() override; String text() const; void set_text(const String&); @@ -44,9 +46,9 @@ public: void close(); void select_all(); - GModel* model() { return m_list_view->model(); } - const GModel* model() const { return m_list_view->model(); } - void set_model(NonnullRefPtr<GModel>); + Model* model() { return m_list_view->model(); } + const Model* model() const { return m_list_view->model(); } + void set_model(NonnullRefPtr<Model>); bool only_allow_values_from_model() const { return m_only_allow_values_from_model; } void set_only_allow_values_from_model(bool); @@ -54,17 +56,19 @@ public: int model_column() const { return m_list_view->model_column(); } void set_model_column(int column) { m_list_view->set_model_column(column); } - Function<void(const String&, const GModelIndex&)> on_change; + Function<void(const String&, const ModelIndex&)> on_change; Function<void()> on_return_pressed; protected: - explicit GComboBox(GWidget* parent = nullptr); - virtual void resize_event(GResizeEvent&) override; + explicit ComboBox(Widget* parent = nullptr); + virtual void resize_event(ResizeEvent&) override; private: - RefPtr<GTextEditor> m_editor; - RefPtr<GButton> m_open_button; - RefPtr<GWindow> m_list_window; - RefPtr<GListView> m_list_view; + RefPtr<TextEditor> m_editor; + RefPtr<Button> m_open_button; + RefPtr<Window> m_list_window; + RefPtr<ListView> m_list_view; bool m_only_allow_values_from_model { false }; }; + +} diff --git a/Libraries/LibGUI/GCommand.cpp b/Libraries/LibGUI/GCommand.cpp index 8e62fdd644..53c6bfa41f 100644 --- a/Libraries/LibGUI/GCommand.cpp +++ b/Libraries/LibGUI/GCommand.cpp @@ -26,6 +26,10 @@ #include <LibGUI/GCommand.h> -GCommand::~GCommand() +namespace GUI { + +Command::~Command() { } + +} diff --git a/Libraries/LibGUI/GCommand.h b/Libraries/LibGUI/GCommand.h index f8e4e8cd45..5bf13e1f75 100644 --- a/Libraries/LibGUI/GCommand.h +++ b/Libraries/LibGUI/GCommand.h @@ -28,9 +28,11 @@ #include <AK/String.h> -class GCommand { +namespace GUI { + +class Command { public: - virtual ~GCommand(); + virtual ~Command(); virtual void undo() {} virtual void redo() {} @@ -38,9 +40,11 @@ public: String action_text() const { return m_action_text; } protected: - GCommand() {} + Command() {} void set_action_text(const String& text) { m_action_text = text; } private: String m_action_text; }; + +} diff --git a/Libraries/LibGUI/GDesktop.cpp b/Libraries/LibGUI/GDesktop.cpp index 2ffe5801c4..ee557b5403 100644 --- a/Libraries/LibGUI/GDesktop.cpp +++ b/Libraries/LibGUI/GDesktop.cpp @@ -30,19 +30,21 @@ #include <string.h> #include <unistd.h> -GDesktop& GDesktop::the() +namespace GUI { + +Desktop& Desktop::the() { - static GDesktop* the; + static Desktop* the; if (!the) - the = new GDesktop; + the = new Desktop; return *the; } -GDesktop::GDesktop() +Desktop::Desktop() { } -void GDesktop::did_receive_screen_rect(Badge<GWindowServerConnection>, const Rect& rect) +void Desktop::did_receive_screen_rect(Badge<WindowServerConnection>, const Rect& rect) { if (m_rect == rect) return; @@ -51,15 +53,14 @@ void GDesktop::did_receive_screen_rect(Badge<GWindowServerConnection>, const Rec on_rect_change(rect); } -bool GDesktop::set_wallpaper(const StringView& path) +bool Desktop::set_wallpaper(const StringView& path) { - GWindowServerConnection::the().post_message(WindowServer::AsyncSetWallpaper(path)); - auto ret_val = GWindowServerConnection::the().wait_for_specific_message<WindowClient::AsyncSetWallpaperFinished>()->success(); + WindowServerConnection::the().post_message(WindowServer::AsyncSetWallpaper(path)); + auto ret_val = WindowServerConnection::the().wait_for_specific_message<WindowClient::AsyncSetWallpaperFinished>()->success(); if (ret_val) { + RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("WindowManager"); dbg() << "Saving wallpaper path '" << path << "' to config file at " << config->file_name(); - - RefPtr<CConfigFile> config = CConfigFile::get_for_app("WindowManager"); config->write_entry("Background", "Wallpaper", path); config->sync(); } @@ -67,7 +68,9 @@ bool GDesktop::set_wallpaper(const StringView& path) return ret_val; } -String GDesktop::wallpaper() const +String Desktop::wallpaper() const { - return GWindowServerConnection::the().send_sync<WindowServer::GetWallpaper>()->path(); + return WindowServerConnection::the().send_sync<WindowServer::GetWallpaper>()->path(); +} + } diff --git a/Libraries/LibGUI/GDesktop.h b/Libraries/LibGUI/GDesktop.h index e36e673522..b580e2b3d3 100644 --- a/Libraries/LibGUI/GDesktop.h +++ b/Libraries/LibGUI/GDesktop.h @@ -31,21 +31,25 @@ #include <AK/String.h> #include <LibDraw/Rect.h> -class GWindowServerConnection; +namespace GUI { -class GDesktop { +class WindowServerConnection; + +class Desktop { public: - static GDesktop& the(); - GDesktop(); + static Desktop& the(); + Desktop(); String wallpaper() const; bool set_wallpaper(const StringView& path); Rect rect() const { return m_rect; } - void did_receive_screen_rect(Badge<GWindowServerConnection>, const Rect&); + void did_receive_screen_rect(Badge<WindowServerConnection>, const Rect&); Function<void(const Rect&)> on_rect_change; private: Rect m_rect; }; + +} diff --git a/Libraries/LibGUI/GDialog.cpp b/Libraries/LibGUI/GDialog.cpp index 22069c434a..5b71db89fc 100644 --- a/Libraries/LibGUI/GDialog.cpp +++ b/Libraries/LibGUI/GDialog.cpp @@ -28,26 +28,28 @@ #include <LibGUI/GDialog.h> #include <LibGUI/GEvent.h> -GDialog::GDialog(Core::Object* parent) - : GWindow(parent) +namespace GUI { + +Dialog::Dialog(Core::Object* parent) + : Window(parent) { set_modal(true); } -GDialog::~GDialog() +Dialog::~Dialog() { } -int GDialog::exec() +int Dialog::exec() { ASSERT(!m_event_loop); m_event_loop = make<Core::EventLoop>(); auto new_rect = rect(); if (parent() && parent()->is_window()) { - auto& parent_window = *static_cast<GWindow*>(parent()); + auto& parent_window = *static_cast<Window*>(parent()); new_rect.center_within(parent_window.rect()); } else { - new_rect.center_within(GDesktop::the().rect()); + new_rect.center_within(Desktop::the().rect()); } set_rect(new_rect); show(); @@ -58,7 +60,7 @@ int GDialog::exec() return result; } -void GDialog::done(int result) +void Dialog::done(int result) { if (!m_event_loop) return; @@ -67,10 +69,10 @@ void GDialog::done(int result) m_event_loop->quit(result); } -void GDialog::event(Core::Event& event) +void Dialog::event(Core::Event& event) { - if (event.type() == GEvent::KeyUp) { - auto& key_event = static_cast<GKeyEvent&>(event); + if (event.type() == Event::KeyUp) { + auto& key_event = static_cast<KeyEvent&>(event); if (key_event.key() == KeyCode::Key_Escape) { done(ExecCancel); event.accept(); @@ -78,11 +80,13 @@ void GDialog::event(Core::Event& event) } } - GWindow::event(event); + Window::event(event); } -void GDialog::close() +void Dialog::close() { - GWindow::close(); + Window::close(); m_event_loop->quit(ExecCancel); } + +} diff --git a/Libraries/LibGUI/GDialog.h b/Libraries/LibGUI/GDialog.h index 4b5f8fd7b7..4724887db0 100644 --- a/Libraries/LibGUI/GDialog.h +++ b/Libraries/LibGUI/GDialog.h @@ -29,8 +29,10 @@ #include <LibCore/CEventLoop.h> #include <LibGUI/GWindow.h> -class GDialog : public GWindow { - C_OBJECT(GDialog) +namespace GUI { + +class Dialog : public Window { + C_OBJECT(Dialog) public: enum ExecResult { ExecOK = 0, @@ -38,7 +40,7 @@ public: ExecAborted = 2 }; - virtual ~GDialog() override; + virtual ~Dialog() override; int exec(); @@ -50,9 +52,11 @@ public: virtual void close() override; protected: - explicit GDialog(Core::Object* parent); + explicit Dialog(Core::Object* parent); private: OwnPtr<Core::EventLoop> m_event_loop; int m_result { ExecAborted }; }; + +} diff --git a/Libraries/LibGUI/GDragOperation.cpp b/Libraries/LibGUI/GDragOperation.cpp index 04424b9494..eb951bf3dc 100644 --- a/Libraries/LibGUI/GDragOperation.cpp +++ b/Libraries/LibGUI/GDragOperation.cpp @@ -28,18 +28,20 @@ #include <LibGUI/GDragOperation.h> #include <LibGUI/GWindowServerConnection.h> -static GDragOperation* s_current_drag_operation; +namespace GUI { -GDragOperation::GDragOperation(Core::Object* parent) +static DragOperation* s_current_drag_operation; + +DragOperation::DragOperation(Core::Object* parent) : Core::Object(parent) { } -GDragOperation::~GDragOperation() +DragOperation::~DragOperation() { } -GDragOperation::Outcome GDragOperation::exec() +DragOperation::Outcome DragOperation::exec() { ASSERT(!s_current_drag_operation); ASSERT(!m_event_loop); @@ -49,12 +51,12 @@ GDragOperation::Outcome GDragOperation::exec() RefPtr<GraphicsBitmap> shared_bitmap; if (m_bitmap) { shared_bitmap = m_bitmap->to_shareable_bitmap(); - shared_bitmap->shared_buffer()->share_with(GWindowServerConnection::the().server_pid()); + shared_bitmap->shared_buffer()->share_with(WindowServerConnection::the().server_pid()); bitmap_id = shared_bitmap->shared_buffer_id(); bitmap_size = shared_bitmap->size(); } - auto response = GWindowServerConnection::the().send_sync<WindowServer::StartDrag>(m_text, m_data_type, m_data, bitmap_id, bitmap_size); + auto response = WindowServerConnection::the().send_sync<WindowServer::StartDrag>(m_text, m_data_type, m_data, bitmap_id, bitmap_size); if (!response->started()) { m_outcome = Outcome::Cancelled; return m_outcome; @@ -70,21 +72,23 @@ GDragOperation::Outcome GDragOperation::exec() return m_outcome; } -void GDragOperation::done(Outcome outcome) +void DragOperation::done(Outcome outcome) { ASSERT(m_outcome == Outcome::None); m_outcome = outcome; m_event_loop->quit(0); } -void GDragOperation::notify_accepted(Badge<GWindowServerConnection>) +void DragOperation::notify_accepted(Badge<WindowServerConnection>) { ASSERT(s_current_drag_operation); s_current_drag_operation->done(Outcome::Accepted); } -void GDragOperation::notify_cancelled(Badge<GWindowServerConnection>) +void DragOperation::notify_cancelled(Badge<WindowServerConnection>) { ASSERT(s_current_drag_operation); s_current_drag_operation->done(Outcome::Cancelled); } + +} diff --git a/Libraries/LibGUI/GDragOperation.h b/Libraries/LibGUI/GDragOperation.h index 8713e4c34f..738ddf6b82 100644 --- a/Libraries/LibGUI/GDragOperation.h +++ b/Libraries/LibGUI/GDragOperation.h @@ -30,10 +30,13 @@ #include <LibCore/CObject.h> class GraphicsBitmap; -class GWindowServerConnection; -class GDragOperation : public Core::Object { - C_OBJECT(GDragOperation) +namespace GUI { + +class WindowServerConnection; + +class DragOperation : public Core::Object { + C_OBJECT(DragOperation) public: enum class Outcome { None, @@ -41,7 +44,7 @@ public: Cancelled, }; - virtual ~GDragOperation() override; + virtual ~DragOperation() override; void set_text(const String& text) { m_text = text; } void set_bitmap(const GraphicsBitmap* bitmap) { m_bitmap = bitmap; } @@ -54,11 +57,11 @@ public: Outcome exec(); Outcome outcome() const { return m_outcome; } - static void notify_accepted(Badge<GWindowServerConnection>); - static void notify_cancelled(Badge<GWindowServerConnection>); + static void notify_accepted(Badge<WindowServerConnection>); + static void notify_cancelled(Badge<WindowServerConnection>); protected: - explicit GDragOperation(Core::Object* parent = nullptr); + explicit DragOperation(Core::Object* parent = nullptr); private: void done(Outcome); @@ -70,3 +73,5 @@ private: String m_data; RefPtr<GraphicsBitmap> m_bitmap; }; + +} diff --git a/Libraries/LibGUI/GEvent.h b/Libraries/LibGUI/GEvent.h index 59d65fabc5..70a64c84b5 100644 --- a/Libraries/LibGUI/GEvent.h +++ b/Libraries/LibGUI/GEvent.h @@ -32,7 +32,9 @@ #include <LibDraw/Rect.h> #include <LibGUI/GWindowType.h> -class GEvent : public Core::Event { +namespace GUI { + +class Event : public Core::Event { public: enum Type { Show = 1000, @@ -68,21 +70,21 @@ public: __End_WM_Events, }; - GEvent() {} - explicit GEvent(Type type) + Event() {} + explicit Event(Type type) : Core::Event(type) { } - virtual ~GEvent() {} + virtual ~Event() {} bool is_key_event() const { return type() == KeyUp || type() == KeyDown; } bool is_paint_event() const { return type() == Paint; } }; -class GWMEvent : public GEvent { +class WMEvent : public Event { public: - GWMEvent(Type type, int client_id, int window_id) - : GEvent(type) + WMEvent(Type type, int client_id, int window_id) + : Event(type) , m_client_id(client_id) , m_window_id(window_id) { @@ -96,18 +98,18 @@ private: int m_window_id { -1 }; }; -class GWMWindowRemovedEvent : public GWMEvent { +class WMWindowRemovedEvent : public WMEvent { public: - GWMWindowRemovedEvent(int client_id, int window_id) - : GWMEvent(GEvent::Type::WM_WindowRemoved, client_id, window_id) + WMWindowRemovedEvent(int client_id, int window_id) + : WMEvent(Event::Type::WM_WindowRemoved, client_id, window_id) { } }; -class GWMWindowStateChangedEvent : public GWMEvent { +class WMWindowStateChangedEvent : public WMEvent { public: - GWMWindowStateChangedEvent(int client_id, int window_id, const StringView& title, const Rect& rect, bool is_active, GWindowType window_type, bool is_minimized) - : GWMEvent(GEvent::Type::WM_WindowStateChanged, client_id, window_id) + WMWindowStateChangedEvent(int client_id, int window_id, const StringView& title, const Rect& rect, bool is_active, WindowType window_type, bool is_minimized) + : WMEvent(Event::Type::WM_WindowStateChanged, client_id, window_id) , m_title(title) , m_rect(rect) , m_window_type(window_type) @@ -119,21 +121,21 @@ public: String title() const { return m_title; } Rect rect() const { return m_rect; } bool is_active() const { return m_active; } - GWindowType window_type() const { return m_window_type; } + WindowType window_type() const { return m_window_type; } bool is_minimized() const { return m_minimized; } private: String m_title; Rect m_rect; - GWindowType m_window_type; + WindowType m_window_type; bool m_active; bool m_minimized; }; -class GWMWindowRectChangedEvent : public GWMEvent { +class WMWindowRectChangedEvent : public WMEvent { public: - GWMWindowRectChangedEvent(int client_id, int window_id, const Rect& rect) - : GWMEvent(GEvent::Type::WM_WindowRectChanged, client_id, window_id) + WMWindowRectChangedEvent(int client_id, int window_id, const Rect& rect) + : WMEvent(Event::Type::WM_WindowRectChanged, client_id, window_id) , m_rect(rect) { } @@ -144,10 +146,10 @@ private: Rect m_rect; }; -class GWMWindowIconBitmapChangedEvent : public GWMEvent { +class WMWindowIconBitmapChangedEvent : public WMEvent { public: - GWMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Size& icon_size) - : GWMEvent(GEvent::Type::WM_WindowIconBitmapChanged, client_id, window_id) + WMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Size& icon_size) + : WMEvent(Event::Type::WM_WindowIconBitmapChanged, client_id, window_id) , m_icon_buffer_id(icon_buffer_id) , m_icon_size(icon_size) { @@ -161,10 +163,10 @@ private: Size m_icon_size; }; -class GMultiPaintEvent final : public GEvent { +class MultiPaintEvent final : public Event { public: - explicit GMultiPaintEvent(const Vector<Rect, 32>& rects, const Size& window_size) - : GEvent(GEvent::MultiPaint) + explicit MultiPaintEvent(const Vector<Rect, 32>& rects, const Size& window_size) + : Event(Event::MultiPaint) , m_rects(rects) , m_window_size(window_size) { @@ -178,10 +180,10 @@ private: Size m_window_size; }; -class GPaintEvent final : public GEvent { +class PaintEvent final : public Event { public: - explicit GPaintEvent(const Rect& rect, const Size& window_size = Size()) - : GEvent(GEvent::Paint) + explicit PaintEvent(const Rect& rect, const Size& window_size = Size()) + : Event(Event::Paint) , m_rect(rect) , m_window_size(window_size) { @@ -195,10 +197,10 @@ private: Size m_window_size; }; -class GResizeEvent final : public GEvent { +class ResizeEvent final : public Event { public: - explicit GResizeEvent(const Size& old_size, const Size& size) - : GEvent(GEvent::Resize) + explicit ResizeEvent(const Size& old_size, const Size& size) + : Event(Event::Resize) , m_old_size(old_size) , m_size(size) { @@ -212,10 +214,10 @@ private: Size m_size; }; -class GContextMenuEvent final : public GEvent { +class ContextMenuEvent final : public Event { public: - explicit GContextMenuEvent(const Point& position, const Point& screen_position) - : GEvent(GEvent::ContextMenu) + explicit ContextMenuEvent(const Point& position, const Point& screen_position) + : Event(Event::ContextMenu) , m_position(position) , m_screen_position(screen_position) { @@ -229,33 +231,33 @@ private: Point m_screen_position; }; -class GShowEvent final : public GEvent { +class ShowEvent final : public Event { public: - GShowEvent() - : GEvent(GEvent::Show) + ShowEvent() + : Event(Event::Show) { } }; -class GHideEvent final : public GEvent { +class HideEvent final : public Event { public: - GHideEvent() - : GEvent(GEvent::Hide) + HideEvent() + : Event(Event::Hide) { } }; -enum GMouseButton : u8 { +enum MouseButton : u8 { None = 0, Left = 1, Right = 2, Middle = 4, }; -class GKeyEvent final : public GEvent { +class KeyEvent final : public Event { public: - GKeyEvent(Type type, int key, u8 modifiers) - : GEvent(type) + KeyEvent(Type type, int key, u8 modifiers) + : Event(type) , m_key(key) , m_modifiers(modifiers) { @@ -270,16 +272,16 @@ public: String text() const { return m_text; } private: - friend class GWindowServerConnection; + friend class WindowServerConnection; int m_key { 0 }; u8 m_modifiers { 0 }; String m_text; }; -class GMouseEvent final : public GEvent { +class MouseEvent final : public Event { public: - GMouseEvent(Type type, const Point& position, unsigned buttons, GMouseButton button, unsigned modifiers, int wheel_delta) - : GEvent(type) + MouseEvent(Type type, const Point& position, unsigned buttons, MouseButton button, unsigned modifiers, int wheel_delta) + : Event(type) , m_position(position) , m_buttons(buttons) , m_button(button) @@ -291,7 +293,7 @@ public: Point position() const { return m_position; } int x() const { return m_position.x(); } int y() const { return m_position.y(); } - GMouseButton button() const { return m_button; } + MouseButton button() const { return m_button; } unsigned buttons() const { return m_buttons; } unsigned modifiers() const { return m_modifiers; } int wheel_delta() const { return m_wheel_delta; } @@ -299,15 +301,15 @@ public: private: Point m_position; unsigned m_buttons { 0 }; - GMouseButton m_button { GMouseButton::None }; + MouseButton m_button { MouseButton::None }; unsigned m_modifiers { 0 }; int m_wheel_delta { 0 }; }; -class GDropEvent final : public GEvent { +class DropEvent final : public Event { public: - GDropEvent(const Point& position, const String& text, const String& data_type, const String& data) - : GEvent(GEvent::Drop) + DropEvent(const Point& position, const String& text, const String& data_type, const String& data) + : Event(Event::Drop) , m_position(position) , m_text(text) , m_data_type(data_type) @@ -326,3 +328,5 @@ private: String m_data_type; String m_data; }; + +} diff --git a/Libraries/LibGUI/GFilePicker.cpp b/Libraries/LibGUI/GFilePicker.cpp index d510fc456f..0be3072aae 100644 --- a/Libraries/LibGUI/GFilePicker.cpp +++ b/Libraries/LibGUI/GFilePicker.cpp @@ -39,14 +39,16 @@ #include <LibGUI/GTextBox.h> #include <LibGUI/GToolBar.h> -Optional<String> GFilePicker::get_open_filepath(const String& window_title) +namespace GUI { + +Optional<String> FilePicker::get_open_filepath(const String& window_title) { - auto picker = GFilePicker::construct(Mode::Open); + auto picker = FilePicker::construct(Mode::Open); if (!window_title.is_null()) picker->set_title(window_title); - if (picker->exec() == GDialog::ExecOK) { + if (picker->exec() == Dialog::ExecOK) { String file_path = picker->selected_file().string(); if (file_path.is_null()) @@ -57,11 +59,11 @@ Optional<String> GFilePicker::get_open_filepath(const String& window_title) return {}; } -Optional<String> GFilePicker::get_save_filepath(const String& title, const String& extension) +Optional<String> FilePicker::get_save_filepath(const String& title, const String& extension) { - auto picker = GFilePicker::construct(Mode::Save, String::format("%s.%s", title.characters(), extension.characters())); + auto picker = FilePicker::construct(Mode::Save, String::format("%s.%s", title.characters(), extension.characters())); - if (picker->exec() == GDialog::ExecOK) { + if (picker->exec() == Dialog::ExecOK) { String file_path = picker->selected_file().string(); if (file_path.is_null()) @@ -72,45 +74,45 @@ Optional<String> GFilePicker::get_save_filepath(const String& title, const Strin return {}; } -GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringView& path, Core::Object* parent) - : GDialog(parent) - , m_model(GFileSystemModel::create()) +FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& path, Core::Object* parent) + : Dialog(parent) + , m_model(FileSystemModel::create()) , m_mode(mode) { set_title(m_mode == Mode::Open ? "Open File" : "Save File"); set_rect(200, 200, 700, 400); - auto horizontal_container = GWidget::construct(); + auto horizontal_container = Widget::construct(); set_main_widget(horizontal_container); - horizontal_container->set_layout(make<GHBoxLayout>()); + horizontal_container->set_layout(make<HBoxLayout>()); horizontal_container->layout()->set_margins({ 4, 4, 4, 4 }); horizontal_container->set_fill_with_background_color(true); - auto vertical_container = GWidget::construct(horizontal_container.ptr()); - vertical_container->set_layout(make<GVBoxLayout>()); + auto vertical_container = Widget::construct(horizontal_container.ptr()); + vertical_container->set_layout(make<VBoxLayout>()); vertical_container->layout()->set_spacing(4); - auto upper_container = GWidget::construct(vertical_container.ptr()); - upper_container->set_layout(make<GHBoxLayout>()); + auto upper_container = Widget::construct(vertical_container.ptr()); + upper_container->set_layout(make<HBoxLayout>()); upper_container->layout()->set_spacing(4); upper_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); upper_container->set_preferred_size(0, 26); - auto toolbar = GToolBar::construct(upper_container); + auto toolbar = ToolBar::construct(upper_container); toolbar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); toolbar->set_preferred_size(85, 0); toolbar->set_has_frame(false); - auto location_textbox = GTextBox::construct(upper_container); + auto location_textbox = TextBox::construct(upper_container); location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); location_textbox->set_preferred_size(0, 20); - m_view = GTableView::construct(vertical_container); - m_view->set_model(GSortingProxyModel::create(*m_model)); - m_view->set_column_hidden(GFileSystemModel::Column::Owner, true); - m_view->set_column_hidden(GFileSystemModel::Column::Group, true); - m_view->set_column_hidden(GFileSystemModel::Column::Permissions, true); - m_view->set_column_hidden(GFileSystemModel::Column::Inode, true); - m_view->set_column_hidden(GFileSystemModel::Column::SymlinkTarget, true); + m_view = TableView::construct(vertical_container); + m_view->set_model(SortingProxyModel::create(*m_model)); + m_view->set_column_hidden(FileSystemModel::Column::Owner, true); + m_view->set_column_hidden(FileSystemModel::Column::Group, true); + m_view->set_column_hidden(FileSystemModel::Column::Permissions, true); + m_view->set_column_hidden(FileSystemModel::Column::Inode, true); + m_view->set_column_hidden(FileSystemModel::Column::SymlinkTarget, true); m_model->set_root_path(path); location_textbox->on_return_pressed = [&] { @@ -118,28 +120,28 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie clear_preview(); }; - auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this](const GAction&) { + auto open_parent_directory_action = Action::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this](const Action&) { m_model->set_root_path(String::format("%s/..", m_model->root_path().characters())); clear_preview(); }); toolbar->add_action(*open_parent_directory_action); - auto go_home_action = GCommonActions::make_go_home_action([this](auto&) { + auto go_home_action = CommonActions::make_go_home_action([this](auto&) { m_model->set_root_path(get_current_user_home_path()); }); toolbar->add_action(go_home_action); toolbar->add_separator(); - auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const GAction&) { - auto input_box = GInputBox::construct("Enter name:", "New directory", this); - if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { + auto mkdir_action = Action::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) { + auto input_box = InputBox::construct("Enter name:", "New directory", this); + if (input_box->exec() == InputBox::ExecOK && !input_box->text_value().is_empty()) { auto new_dir_path = FileSystemPath(String::format("%s/%s", m_model->root_path().characters(), input_box->text_value().characters())) .string(); int rc = mkdir(new_dir_path.characters(), 0777); if (rc < 0) { - GMessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, this); + MessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", MessageBox::Type::Error, MessageBox::InputType::OK, this); } else { m_model->update(); } @@ -147,21 +149,21 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie }); toolbar->add_action(*mkdir_action); - auto lower_container = GWidget::construct(vertical_container.ptr()); - lower_container->set_layout(make<GVBoxLayout>()); + auto lower_container = Widget::construct(vertical_container.ptr()); + lower_container->set_layout(make<VBoxLayout>()); 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 = GWidget::construct(lower_container.ptr()); + auto filename_container = Widget::construct(lower_container.ptr()); filename_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); filename_container->set_preferred_size(0, 20); - filename_container->set_layout(make<GHBoxLayout>()); - auto filename_label = GLabel::construct("File name:", filename_container); + filename_container->set_layout(make<HBoxLayout>()); + auto filename_label = Label::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); - m_filename_textbox = GTextBox::construct(filename_container.ptr()); + m_filename_textbox = TextBox::construct(filename_container.ptr()); if (m_mode == Mode::Save) { m_filename_textbox->set_text(file_name); m_filename_textbox->set_focus(true); @@ -172,9 +174,9 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie }; m_view->on_selection = [this](auto& index) { - auto& filter_model = (GSortingProxyModel&)*m_view->model(); + auto& filter_model = (SortingProxyModel&)*m_view->model(); auto local_index = filter_model.map_to_target(index); - const GFileSystemModel::Node& node = m_model->node(local_index); + const FileSystemModel::Node& node = m_model->node(local_index); FileSystemPath path { node.full_path(m_model) }; clear_preview(); @@ -184,14 +186,14 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie set_preview(path); }; - auto button_container = GWidget::construct(lower_container.ptr()); + auto button_container = Widget::construct(lower_container.ptr()); button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); button_container->set_preferred_size(0, 20); - button_container->set_layout(make<GHBoxLayout>()); + button_container->set_layout(make<HBoxLayout>()); button_container->layout()->set_spacing(4); button_container->layout()->add_spacer(); - auto cancel_button = GButton::construct(button_container); + auto cancel_button = Button::construct(button_container); cancel_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); cancel_button->set_preferred_size(80, 0); cancel_button->set_text("Cancel"); @@ -199,7 +201,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie done(ExecCancel); }; - auto ok_button = GButton::construct(button_container); + auto ok_button = Button::construct(button_container); ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); ok_button->set_preferred_size(80, 0); ok_button->set_text(ok_button_name(m_mode)); @@ -208,9 +210,9 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie }; m_view->on_activation = [this](auto& index) { - auto& filter_model = (GSortingProxyModel&)*m_view->model(); + auto& filter_model = (SortingProxyModel&)*m_view->model(); auto local_index = filter_model.map_to_target(index); - const GFileSystemModel::Node& node = m_model->node(local_index); + const FileSystemModel::Node& node = m_model->node(local_index); auto path = node.full_path(m_model); if (node.is_directory()) { @@ -221,35 +223,35 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie } }; - auto preview_container = GFrame::construct(horizontal_container); + auto preview_container = Frame::construct(horizontal_container); preview_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); preview_container->set_preferred_size(180, 0); preview_container->set_frame_shape(FrameShape::Container); preview_container->set_frame_shadow(FrameShadow::Sunken); preview_container->set_frame_thickness(2); - preview_container->set_layout(make<GVBoxLayout>()); + preview_container->set_layout(make<VBoxLayout>()); preview_container->layout()->set_margins({ 8, 8, 8, 8 }); - m_preview_image_label = GLabel::construct(preview_container); + m_preview_image_label = Label::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 = GLabel::construct(preview_container); + m_preview_name_label = Label::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 = GLabel::construct(preview_container); + m_preview_geometry_label = Label::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()); } -GFilePicker::~GFilePicker() +FilePicker::~FilePicker() { } -void GFilePicker::set_preview(const FileSystemPath& path) +void FilePicker::set_preview(const FileSystemPath& path) { if (path.has_extension(".png")) { auto bitmap = load_png(path.string()); @@ -265,20 +267,20 @@ void GFilePicker::set_preview(const FileSystemPath& path) } } -void GFilePicker::clear_preview() +void FilePicker::clear_preview() { m_preview_image_label->set_icon(nullptr); m_preview_name_label->set_text(String::empty()); m_preview_geometry_label->set_text(String::empty()); } -void GFilePicker::on_file_return() +void FilePicker::on_file_return() { FileSystemPath path(String::format("%s/%s", m_model->root_path().characters(), m_filename_textbox->text().characters())); - if (GFilePicker::file_exists(path.string()) && m_mode == Mode::Save) { - auto result = GMessageBox::show("File already exists, overwrite?", "Existing File", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel); - if (result == GMessageBox::ExecCancel) + if (FilePicker::file_exists(path.string()) && m_mode == Mode::Save) { + auto result = MessageBox::show("File already exists, overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel); + if (result == MessageBox::ExecCancel) return; } @@ -286,7 +288,7 @@ void GFilePicker::on_file_return() done(ExecOK); } -bool GFilePicker::file_exists(const StringView& path) +bool FilePicker::file_exists(const StringView& path) { struct stat st; int rc = stat(String(path).characters(), &st); @@ -299,3 +301,5 @@ bool GFilePicker::file_exists(const StringView& path) } return false; } + +} diff --git a/Libraries/LibGUI/GFilePicker.h b/Libraries/LibGUI/GFilePicker.h index 21beee489b..f1bc5b6ce0 100644 --- a/Libraries/LibGUI/GFilePicker.h +++ b/Libraries/LibGUI/GFilePicker.h @@ -30,12 +30,14 @@ #include <LibGUI/GDialog.h> #include <LibGUI/GTableView.h> -class GFileSystemModel; -class GLabel; -class GTextBox; +namespace GUI { -class GFilePicker final : public GDialog { - C_OBJECT(GFilePicker) +class FileSystemModel; +class Label; +class TextBox; + +class FilePicker final : public Dialog { + C_OBJECT(FilePicker) public: enum class Mode { Open, @@ -46,7 +48,7 @@ public: static Optional<String> get_save_filepath(const String& title, const String& extension); static bool file_exists(const StringView& path); - virtual ~GFilePicker() override; + virtual ~FilePicker() override; FileSystemPath selected_file() const { return m_selected_file; } @@ -55,7 +57,7 @@ private: void clear_preview(); void on_file_return(); - GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), Core::Object* parent = nullptr); + FilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), Core::Object* parent = nullptr); static String ok_button_name(Mode mode) { @@ -69,13 +71,15 @@ private: } } - RefPtr<GTableView> m_view; - NonnullRefPtr<GFileSystemModel> m_model; + RefPtr<TableView> m_view; + NonnullRefPtr<FileSystemModel> m_model; FileSystemPath m_selected_file; - RefPtr<GTextBox> m_filename_textbox; - RefPtr<GLabel> m_preview_image_label; - RefPtr<GLabel> m_preview_name_label; - RefPtr<GLabel> m_preview_geometry_label; + RefPtr<TextBox> m_filename_textbox; + RefPtr<Label> m_preview_image_label; + RefPtr<Label> m_preview_name_label; + RefPtr<Label> m_preview_geometry_label; Mode m_mode { Mode::Open }; }; + +} diff --git a/Libraries/LibGUI/GFileSystemModel.cpp b/Libraries/LibGUI/GFileSystemModel.cpp index 4c8d28598b..24dd925f0a 100644 --- a/Libraries/LibGUI/GFileSystemModel.cpp +++ b/Libraries/LibGUI/GFileSystemModel.cpp @@ -38,7 +38,9 @@ #include <sys/stat.h> #include <unistd.h> -GModelIndex GFileSystemModel::Node::index(const GFileSystemModel& model, int column) const +namespace GUI { + +ModelIndex FileSystemModel::Node::index(const FileSystemModel& model, int column) const { if (!parent) return {}; @@ -49,7 +51,7 @@ GModelIndex GFileSystemModel::Node::index(const GFileSystemModel& model, int col ASSERT_NOT_REACHED(); } -bool GFileSystemModel::Node::fetch_data(const String& full_path, bool is_root) +bool FileSystemModel::Node::fetch_data(const String& full_path, bool is_root) { struct stat st; int rc; @@ -83,7 +85,7 @@ bool GFileSystemModel::Node::fetch_data(const String& full_path, bool is_root) return true; } -void GFileSystemModel::Node::traverse_if_needed(const GFileSystemModel& model) +void FileSystemModel::Node::traverse_if_needed(const FileSystemModel& model) { if (!is_directory() || has_traversed) return; @@ -132,11 +134,11 @@ void GFileSystemModel::Node::traverse_if_needed(const GFileSystemModel& model) mode = 0; children.clear(); reify_if_needed(model); - const_cast<GFileSystemModel&>(model).did_update(); + const_cast<FileSystemModel&>(model).did_update(); }; } -void GFileSystemModel::Node::reify_if_needed(const GFileSystemModel& model) +void FileSystemModel::Node::reify_if_needed(const FileSystemModel& model) { traverse_if_needed(model); if (mode != 0) @@ -144,7 +146,7 @@ void GFileSystemModel::Node::reify_if_needed(const GFileSystemModel& model) fetch_data(full_path(model), parent == nullptr); } -String GFileSystemModel::Node::full_path(const GFileSystemModel& model) const +String FileSystemModel::Node::full_path(const FileSystemModel& model) const { Vector<String, 32> lineage; for (auto* ancestor = parent; ancestor; ancestor = ancestor->parent) { @@ -161,7 +163,7 @@ String GFileSystemModel::Node::full_path(const GFileSystemModel& model) const return canonicalized_path(builder.to_string()); } -GModelIndex GFileSystemModel::index(const StringView& path, int column) const +ModelIndex FileSystemModel::index(const StringView& path, int column) const { FileSystemPath canonical_path(path); const Node* node = m_root; @@ -186,14 +188,14 @@ GModelIndex GFileSystemModel::index(const StringView& path, int column) const return {}; } -String GFileSystemModel::full_path(const GModelIndex& index) const +String FileSystemModel::full_path(const ModelIndex& index) const { auto& node = this->node(index); const_cast<Node&>(node).reify_if_needed(*this); return node.full_path(*this); } -GFileSystemModel::GFileSystemModel(const StringView& root_path, Mode mode) +FileSystemModel::FileSystemModel(const StringView& root_path, Mode mode) : m_root_path(canonicalized_path(root_path)) , m_mode(mode) { @@ -219,11 +221,11 @@ GFileSystemModel::GFileSystemModel(const StringView& root_path, Mode mode) update(); } -GFileSystemModel::~GFileSystemModel() +FileSystemModel::~FileSystemModel() { } -String GFileSystemModel::name_for_uid(uid_t uid) const +String FileSystemModel::name_for_uid(uid_t uid) const { auto it = m_user_names.find(uid); if (it == m_user_names.end()) @@ -231,7 +233,7 @@ String GFileSystemModel::name_for_uid(uid_t uid) const return (*it).value; } -String GFileSystemModel::name_for_gid(uid_t gid) const +String FileSystemModel::name_for_gid(uid_t gid) const { auto it = m_user_names.find(gid); if (it == m_user_names.end()) @@ -276,7 +278,7 @@ static String permission_string(mode_t mode) return builder.to_string(); } -void GFileSystemModel::set_root_path(const StringView& root_path) +void FileSystemModel::set_root_path(const StringView& root_path) { m_root_path = canonicalized_path(root_path); @@ -286,7 +288,7 @@ void GFileSystemModel::set_root_path(const StringView& root_path) update(); } -void GFileSystemModel::update() +void FileSystemModel::update() { m_root = make<Node>(); m_root->reify_if_needed(*this); @@ -294,7 +296,7 @@ void GFileSystemModel::update() did_update(); } -int GFileSystemModel::row_count(const GModelIndex& index) const +int FileSystemModel::row_count(const ModelIndex& index) const { Node& node = const_cast<Node&>(this->node(index)); node.reify_if_needed(*this); @@ -303,14 +305,14 @@ int GFileSystemModel::row_count(const GModelIndex& index) const return 0; } -const GFileSystemModel::Node& GFileSystemModel::node(const GModelIndex& index) const +const FileSystemModel::Node& FileSystemModel::node(const ModelIndex& index) const { if (!index.is_valid()) return *m_root; return *(Node*)index.internal_data(); } -GModelIndex GFileSystemModel::index(int row, int column, const GModelIndex& parent) const +ModelIndex FileSystemModel::index(int row, int column, const ModelIndex& parent) const { if (row < 0 || column < 0) return {}; @@ -321,7 +323,7 @@ GModelIndex GFileSystemModel::index(int row, int column, const GModelIndex& pare return create_index(row, column, &node.children[row]); } -GModelIndex GFileSystemModel::parent_index(const GModelIndex& index) const +ModelIndex FileSystemModel::parent_index(const ModelIndex& index) const { if (!index.is_valid()) return {}; @@ -333,7 +335,7 @@ GModelIndex GFileSystemModel::parent_index(const GModelIndex& index) const return node.parent->index(*this, index.column()); } -GVariant GFileSystemModel::data(const GModelIndex& index, Role role) const +Variant FileSystemModel::data(const ModelIndex& index, Role role) const { ASSERT(index.is_valid()); auto& node = this->node(index); @@ -407,7 +409,7 @@ GVariant GFileSystemModel::data(const GModelIndex& index, Role role) const return {}; } -GIcon GFileSystemModel::icon_for_file(const mode_t mode, const String& name) const +GIcon FileSystemModel::icon_for_file(const mode_t mode, const String& name) const { if (S_ISDIR(mode)) return m_directory_icon; @@ -426,11 +428,11 @@ GIcon GFileSystemModel::icon_for_file(const mode_t mode, const String& name) con return m_file_icon; } -GIcon GFileSystemModel::icon_for(const Node& node) const +GIcon FileSystemModel::icon_for(const Node& node) const { if (node.name.to_lowercase().ends_with(".png")) { if (!node.thumbnail) { - if (!const_cast<GFileSystemModel*>(this)->fetch_thumbnail_for(node)) + if (!const_cast<FileSystemModel*>(this)->fetch_thumbnail_for(node)) return m_filetype_image_icon; } return GIcon(m_filetype_image_icon.bitmap_for_size(16), *node.thumbnail); @@ -452,7 +454,7 @@ static RefPtr<GraphicsBitmap> render_thumbnail(const StringView& path) return thumbnail; } -bool GFileSystemModel::fetch_thumbnail_for(const Node& node) +bool FileSystemModel::fetch_thumbnail_for(const Node& node) { // See if we already have the thumbnail // we're looking for in the cache. @@ -500,12 +502,12 @@ bool GFileSystemModel::fetch_thumbnail_for(const Node& node) return false; } -int GFileSystemModel::column_count(const GModelIndex&) const +int FileSystemModel::column_count(const ModelIndex&) const { return Column::__Count; } -String GFileSystemModel::column_name(int column) const +String FileSystemModel::column_name(int column) const { switch (column) { case Column::Icon: @@ -530,11 +532,11 @@ String GFileSystemModel::column_name(int column) const ASSERT_NOT_REACHED(); } -GModel::ColumnMetadata GFileSystemModel::column_metadata(int column) const +Model::ColumnMetadata FileSystemModel::column_metadata(int column) const { switch (column) { case Column::Icon: - return { 16, TextAlignment::Center, nullptr, GModel::ColumnMetadata::Sortable::False }; + return { 16, TextAlignment::Center, nullptr, Model::ColumnMetadata::Sortable::False }; case Column::Name: return { 120, TextAlignment::CenterLeft }; case Column::Size: @@ -554,3 +556,5 @@ GModel::ColumnMetadata GFileSystemModel::column_metadata(int column) const } ASSERT_NOT_REACHED(); } + +} diff --git a/Libraries/LibGUI/GFileSystemModel.h b/Libraries/LibGUI/GFileSystemModel.h index 971a1b0001..3eb53b5f86 100644 --- a/Libraries/LibGUI/GFileSystemModel.h +++ b/Libraries/LibGUI/GFileSystemModel.h @@ -33,8 +33,11 @@ #include <sys/stat.h> #include <time.h> -class GFileSystemModel : public GModel - , public Weakable<GFileSystemModel> { +namespace GUI { + +class FileSystemModel + : public Model + , public Weakable<FileSystemModel> { friend struct Node; public: @@ -75,10 +78,10 @@ public: bool is_directory() const { return S_ISDIR(mode); } bool is_executable() const { return mode & (S_IXUSR | S_IXGRP | S_IXOTH); } - String full_path(const GFileSystemModel&) const; + String full_path(const FileSystemModel&) const; private: - friend class GFileSystemModel; + friend class FileSystemModel; Node* parent { nullptr }; NonnullOwnPtrVector<Node> children; @@ -87,38 +90,38 @@ public: int m_watch_fd { -1 }; RefPtr<Core::Notifier> m_notifier; - GModelIndex index(const GFileSystemModel&, int column) const; - void traverse_if_needed(const GFileSystemModel&); - void reify_if_needed(const GFileSystemModel&); + ModelIndex index(const FileSystemModel&, int column) const; + void traverse_if_needed(const FileSystemModel&); + void reify_if_needed(const FileSystemModel&); bool fetch_data(const String& full_path, bool is_root); }; - static NonnullRefPtr<GFileSystemModel> create(const StringView& root_path = "/", Mode mode = Mode::FilesAndDirectories) + static NonnullRefPtr<FileSystemModel> create(const StringView& root_path = "/", Mode mode = Mode::FilesAndDirectories) { - return adopt(*new GFileSystemModel(root_path, mode)); + return adopt(*new FileSystemModel(root_path, mode)); } - virtual ~GFileSystemModel() override; + virtual ~FileSystemModel() override; String root_path() const { return m_root_path; } void set_root_path(const StringView&); - String full_path(const GModelIndex&) const; - GModelIndex index(const StringView& path, int column) const; + String full_path(const ModelIndex&) const; + ModelIndex index(const StringView& path, int column) const; - const Node& node(const GModelIndex& index) const; + const Node& node(const ModelIndex& index) const; GIcon icon_for_file(const mode_t mode, const String& name) const; Function<void(int done, int total)> on_thumbnail_progress; Function<void()> on_root_path_change; - virtual int tree_column() const { return Column::Name; } - virtual int row_count(const GModelIndex& = GModelIndex()) const override; - virtual int column_count(const GModelIndex& = GModelIndex()) const override; + virtual int tree_column() const override { return Column::Name; } + virtual int row_count(const ModelIndex& = ModelIndex()) const override; + virtual int column_count(const ModelIndex& = ModelIndex()) const override; virtual String column_name(int column) const override; virtual ColumnMetadata column_metadata(int column) const override; - virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; + virtual Variant data(const ModelIndex&, Role = Role::Display) const override; virtual void update() override; - virtual GModelIndex parent_index(const GModelIndex&) const override; - virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override; + virtual ModelIndex parent_index(const ModelIndex&) const override; + virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override; virtual StringView drag_data_type() const override { return "url-list"; } static String timestamp_string(time_t timestamp) @@ -134,7 +137,7 @@ public: } private: - GFileSystemModel(const StringView& root_path, Mode); + FileSystemModel(const StringView& root_path, Mode); String name_for_uid(uid_t) const; String name_for_gid(gid_t) const; @@ -161,3 +164,5 @@ private: unsigned m_thumbnail_progress { 0 }; unsigned m_thumbnail_progress_total { 0 }; }; + +} diff --git a/Libraries/LibGUI/GFrame.cpp b/Libraries/LibGUI/GFrame.cpp index db143411b6..99ce59a60f 100644 --- a/Libraries/LibGUI/GFrame.cpp +++ b/Libraries/LibGUI/GFrame.cpp @@ -28,21 +28,24 @@ #include <LibGUI/GFrame.h> #include <LibGUI/GPainter.h> -GFrame::GFrame(GWidget* parent) - : GWidget(parent) +namespace GUI { + +Frame::Frame(Widget* parent) + : Widget(parent) { } -GFrame::~GFrame() +Frame::~Frame() { } -void GFrame::paint_event(GPaintEvent& event) +void Frame::paint_event(PaintEvent& event) { if (m_shape == FrameShape::NoFrame) return; - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); StylePainter::paint_frame(painter, rect(), palette(), m_shape, m_shadow, m_thickness, spans_entire_window_horizontally()); } +} diff --git a/Libraries/LibGUI/GFrame.h b/Libraries/LibGUI/GFrame.h index 77f8b765bd..e2a42fa203 100644 --- a/Libraries/LibGUI/GFrame.h +++ b/Libraries/LibGUI/GFrame.h @@ -29,10 +29,12 @@ #include <LibDraw/StylePainter.h> #include <LibGUI/GWidget.h> -class GFrame : public GWidget { - C_OBJECT(GFrame) +namespace GUI { + +class Frame : public Widget { + C_OBJECT(Frame) public: - virtual ~GFrame() override; + virtual ~Frame() override; int frame_thickness() const { return m_thickness; } void set_frame_thickness(int thickness) { m_thickness = thickness; } @@ -47,11 +49,13 @@ public: Rect frame_inner_rect() const { return frame_inner_rect_for_size(size()); } protected: - explicit GFrame(GWidget* parent = nullptr); - void paint_event(GPaintEvent&) override; + explicit Frame(Widget* parent = nullptr); + void paint_event(PaintEvent&) override; private: int m_thickness { 0 }; FrameShadow m_shadow { FrameShadow::Plain }; FrameShape m_shape { FrameShape::NoFrame }; }; + +} diff --git a/Libraries/LibGUI/GGroupBox.cpp b/Libraries/LibGUI/GGroupBox.cpp index 5be1c60b74..48e872582e 100644 --- a/Libraries/LibGUI/GGroupBox.cpp +++ b/Libraries/LibGUI/GGroupBox.cpp @@ -29,24 +29,26 @@ #include <LibGUI/GGroupBox.h> #include <LibGUI/GPainter.h> -GGroupBox::GGroupBox(GWidget* parent) - : GGroupBox({}, parent) +namespace GUI { + +GroupBox::GroupBox(Widget* parent) + : GroupBox({}, parent) { } -GGroupBox::GGroupBox(const StringView& title, GWidget* parent) - : GWidget(parent) +GroupBox::GroupBox(const StringView& title, Widget* parent) + : Widget(parent) , m_title(title) { } -GGroupBox::~GGroupBox() +GroupBox::~GroupBox() { } -void GGroupBox::paint_event(GPaintEvent& event) +void GroupBox::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); Rect frame_rect { @@ -60,10 +62,12 @@ void GGroupBox::paint_event(GPaintEvent& event) painter.draw_text(text_rect, m_title, TextAlignment::Center, palette().button_text()); } -void GGroupBox::set_title(const StringView& title) +void GroupBox::set_title(const StringView& title) { if (m_title == title) return; m_title = title; update(); } + +} diff --git a/Libraries/LibGUI/GGroupBox.h b/Libraries/LibGUI/GGroupBox.h index c44f454498..1198deffc2 100644 --- a/Libraries/LibGUI/GGroupBox.h +++ b/Libraries/LibGUI/GGroupBox.h @@ -28,20 +28,24 @@ #include <LibGUI/GWidget.h> -class GGroupBox : public GWidget { - C_OBJECT(GGroupBox) +namespace GUI { + +class GroupBox : public Widget { + C_OBJECT(GroupBox) public: - virtual ~GGroupBox() override; + virtual ~GroupBox() override; String title() const { return m_title; } void set_title(const StringView&); protected: - explicit GGroupBox(GWidget* parent); - GGroupBox(const StringView& title, GWidget* parent); + explicit GroupBox(Widget* parent); + GroupBox(const StringView& title, Widget* parent); - virtual void paint_event(GPaintEvent&) override; + virtual void paint_event(PaintEvent&) override; private: String m_title; }; + +} diff --git a/Libraries/LibGUI/GInputBox.cpp b/Libraries/LibGUI/GInputBox.cpp index 709c3b0861..9b9957fad5 100644 --- a/Libraries/LibGUI/GInputBox.cpp +++ b/Libraries/LibGUI/GInputBox.cpp @@ -31,21 +31,23 @@ #include <LibGUI/GTextEditor.h> #include <stdio.h> -GInputBox::GInputBox(const StringView& prompt, const StringView& title, Core::Object* parent) - : GDialog(parent) +namespace GUI { + +InputBox::InputBox(const StringView& prompt, const StringView& title, Core::Object* parent) + : Dialog(parent) , m_prompt(prompt) { set_title(title); build(); } -GInputBox::~GInputBox() +InputBox::~InputBox() { } -void GInputBox::build() +void InputBox::build() { - auto widget = GWidget::construct(); + auto widget = Widget::construct(); set_main_widget(widget); int text_width = widget->font().width(m_prompt); @@ -54,30 +56,30 @@ void GInputBox::build() set_rect(x(), y(), max_width + 80, 80); - widget->set_layout(make<GVBoxLayout>()); + widget->set_layout(make<VBoxLayout>()); widget->set_fill_with_background_color(true); widget->layout()->set_margins({ 8, 8, 8, 8 }); widget->layout()->set_spacing(8); - auto label = GLabel::construct(m_prompt, widget); + auto label = Label::construct(m_prompt, widget); label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); label->set_preferred_size(text_width, 16); - m_text_editor = GTextEditor::construct(GTextEditor::SingleLine, widget); + m_text_editor = TextEditor::construct(TextEditor::SingleLine, widget); m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); m_text_editor->set_preferred_size(0, 19); - auto button_container_outer = GWidget::construct(widget.ptr()); + auto button_container_outer = Widget::construct(widget.ptr()); button_container_outer->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); button_container_outer->set_preferred_size(0, 20); - button_container_outer->set_layout(make<GVBoxLayout>()); + button_container_outer->set_layout(make<VBoxLayout>()); - auto button_container_inner = GWidget::construct(button_container_outer.ptr()); - button_container_inner->set_layout(make<GHBoxLayout>()); + auto button_container_inner = Widget::construct(button_container_outer.ptr()); + button_container_inner->set_layout(make<HBoxLayout>()); button_container_inner->layout()->set_spacing(8); - m_cancel_button = GButton::construct(button_container_inner); + m_cancel_button = Button::construct(button_container_inner); m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); m_cancel_button->set_preferred_size(0, 20); m_cancel_button->set_text("Cancel"); @@ -86,7 +88,7 @@ void GInputBox::build() done(ExecCancel); }; - m_ok_button = GButton::construct(button_container_inner); + m_ok_button = Button::construct(button_container_inner); m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); m_ok_button->set_preferred_size(0, 20); m_ok_button->set_text("OK"); @@ -104,3 +106,5 @@ void GInputBox::build() }; m_text_editor->set_focus(true); } + +} diff --git a/Libraries/LibGUI/GInputBox.h b/Libraries/LibGUI/GInputBox.h index a957ccdba1..ab7a0c3b09 100644 --- a/Libraries/LibGUI/GInputBox.h +++ b/Libraries/LibGUI/GInputBox.h @@ -28,14 +28,16 @@ #include <LibGUI/GDialog.h> -class GButton; -class GTextEditor; +namespace GUI { -class GInputBox : public GDialog { - C_OBJECT(GInputBox) +class Button; +class TextEditor; + +class InputBox : public Dialog { + C_OBJECT(InputBox) public: - explicit GInputBox(const StringView& prompt, const StringView& title, Core::Object* parent = nullptr); - virtual ~GInputBox() override; + explicit InputBox(const StringView& prompt, const StringView& title, Core::Object* parent = nullptr); + virtual ~InputBox() override; String text_value() const { return m_text_value; } @@ -44,7 +46,9 @@ private: String m_prompt; String m_text_value; - RefPtr<GButton> m_ok_button; - RefPtr<GButton> m_cancel_button; - RefPtr<GTextEditor> m_text_editor; + RefPtr<Button> m_ok_button; + RefPtr<Button> m_cancel_button; + RefPtr<TextEditor> m_text_editor; }; + +} diff --git a/Libraries/LibGUI/GItemView.cpp b/Libraries/LibGUI/GItemView.cpp index c44c82feec..e753b10186 100644 --- a/Libraries/LibGUI/GItemView.cpp +++ b/Libraries/LibGUI/GItemView.cpp @@ -33,8 +33,10 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GScrollBar.h> -GItemView::GItemView(GWidget* parent) - : GAbstractView(parent) +namespace GUI { + +ItemView::ItemView(Widget* parent) + : AbstractView(parent) { set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); @@ -44,29 +46,29 @@ GItemView::GItemView(GWidget* parent) horizontal_scrollbar().set_visible(false); } -GItemView::~GItemView() +ItemView::~ItemView() { } -void GItemView::scroll_into_view(const GModelIndex& index, Orientation orientation) +void ItemView::scroll_into_view(const ModelIndex& index, Orientation orientation) { - GScrollableWidget::scroll_into_view(item_rect(index.row()), orientation); + ScrollableWidget::scroll_into_view(item_rect(index.row()), orientation); } -void GItemView::resize_event(GResizeEvent& event) +void ItemView::resize_event(ResizeEvent& event) { - GAbstractView::resize_event(event); + AbstractView::resize_event(event); update_content_size(); } -void GItemView::did_update_model() +void ItemView::did_update_model() { - GAbstractView::did_update_model(); + AbstractView::did_update_model(); update_content_size(); update(); } -void GItemView::update_content_size() +void ItemView::update_content_size() { if (!model()) return set_content_size({}); @@ -83,7 +85,7 @@ void GItemView::update_content_size() set_content_size({ content_width, content_height }); } -Rect GItemView::item_rect(int item_index) const +Rect ItemView::item_rect(int item_index) const { if (!m_visual_row_count || !m_visual_column_count) return {}; @@ -97,7 +99,7 @@ Rect GItemView::item_rect(int item_index) const }; } -Vector<int> GItemView::items_intersecting_rect(const Rect& rect) const +Vector<int> ItemView::items_intersecting_rect(const Rect& rect) const { ASSERT(model()); const auto& column_metadata = model()->column_metadata(model_column()); @@ -115,7 +117,7 @@ Vector<int> GItemView::items_intersecting_rect(const Rect& rect) const return item_indexes; } -GModelIndex GItemView::index_at_event_position(const Point& position) const +ModelIndex ItemView::index_at_event_position(const Point& position) const { ASSERT(model()); // FIXME: Since all items are the same size, just compute the clicked item index @@ -136,18 +138,18 @@ GModelIndex GItemView::index_at_event_position(const Point& position) const return {}; } -void GItemView::mousedown_event(GMouseEvent& event) +void ItemView::mousedown_event(MouseEvent& event) { if (!model()) - return GAbstractView::mousedown_event(event); + return AbstractView::mousedown_event(event); - if (event.button() != GMouseButton::Left) - return GAbstractView::mousedown_event(event); + if (event.button() != MouseButton::Left) + return AbstractView::mousedown_event(event); auto index = index_at_event_position(event.position()); if (index.is_valid()) { // We might start dragging this item, but not rubber-banding. - return GAbstractView::mousedown_event(event); + return AbstractView::mousedown_event(event); } ASSERT(m_rubber_band_remembered_selection.is_empty()); @@ -166,20 +168,20 @@ void GItemView::mousedown_event(GMouseEvent& event) m_rubber_band_current = event.position(); } -void GItemView::mouseup_event(GMouseEvent& event) +void ItemView::mouseup_event(MouseEvent& event) { - if (m_rubber_banding && event.button() == GMouseButton::Left) { + if (m_rubber_banding && event.button() == MouseButton::Left) { m_rubber_banding = false; m_rubber_band_remembered_selection.clear(); update(); } - GAbstractView::mouseup_event(event); + AbstractView::mouseup_event(event); } -void GItemView::mousemove_event(GMouseEvent& event) +void ItemView::mousemove_event(MouseEvent& event) { if (!model()) - return GAbstractView::mousemove_event(event); + return AbstractView::mousemove_event(event); if (m_rubber_banding) { if (m_rubber_band_current != event.position()) { @@ -199,10 +201,10 @@ void GItemView::mousemove_event(GMouseEvent& event) } } - GAbstractView::mousemove_event(event); + AbstractView::mousemove_event(event); } -void GItemView::get_item_rects(int item_index, const Font& font, const GVariant& item_text, Rect& item_rect, Rect& icon_rect, Rect& text_rect) const +void ItemView::get_item_rects(int item_index, const Font& font, const Variant& item_text, Rect& item_rect, Rect& icon_rect, Rect& text_rect) const { item_rect = this->item_rect(item_index); icon_rect = { 0, 0, 32, 32 }; @@ -214,12 +216,12 @@ void GItemView::get_item_rects(int item_index, const Font& font, const GVariant& text_rect.intersect(item_rect); } -void GItemView::second_paint_event(GPaintEvent& event) +void ItemView::second_paint_event(PaintEvent& event) { if (!m_rubber_banding) return; - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); auto rubber_band_rect = Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current); @@ -227,12 +229,12 @@ void GItemView::second_paint_event(GPaintEvent& event) painter.draw_rect(rubber_band_rect, parent_widget()->palette().rubber_band_border()); } -void GItemView::paint_event(GPaintEvent& event) +void ItemView::paint_event(PaintEvent& event) { Color widget_background_color = palette().color(background_role()); - GFrame::paint_event(event); + Frame::paint_event(event); - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(widget_inner_rect()); painter.add_clip_rect(event.rect()); painter.fill_rect(event.rect(), widget_background_color); @@ -251,8 +253,8 @@ void GItemView::paint_event(GPaintEvent& event) background_color = widget_background_color; } - auto icon = model()->data(model_index, GModel::Role::Icon); - auto item_text = model()->data(model_index, GModel::Role::Display); + auto icon = model()->data(model_index, Model::Role::Icon); + auto item_text = model()->data(model_index, Model::Role::Display); Rect item_rect; Rect icon_rect; @@ -268,20 +270,20 @@ void GItemView::paint_event(GPaintEvent& event) if (is_selected_item) text_color = palette().selection_text(); else - text_color = model()->data(model_index, GModel::Role::ForegroundColor).to_color(palette().color(foreground_role())); + text_color = model()->data(model_index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); painter.fill_rect(text_rect, background_color); painter.draw_text(text_rect, item_text.to_string(), font, TextAlignment::Center, text_color, TextElision::Right); }; } -int GItemView::item_count() const +int ItemView::item_count() const { if (!model()) return 0; return model()->row_count(); } -void GItemView::keydown_event(GKeyEvent& event) +void ItemView::keydown_event(KeyEvent& event) { if (!model()) return; @@ -312,7 +314,7 @@ void GItemView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Up) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() - m_visual_column_count, old_index.column()); @@ -327,7 +329,7 @@ void GItemView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Down) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() + m_visual_column_count, old_index.column()); @@ -342,7 +344,7 @@ void GItemView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Left) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() - 1, old_index.column()); @@ -357,7 +359,7 @@ void GItemView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Right) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() + 1, old_index.column()); @@ -393,5 +395,7 @@ void GItemView::keydown_event(GKeyEvent& event) } return; } - return GWidget::keydown_event(event); + return Widget::keydown_event(event); +} + } diff --git a/Libraries/LibGUI/GItemView.h b/Libraries/LibGUI/GItemView.h index 4eb21552c6..4412041e33 100644 --- a/Libraries/LibGUI/GItemView.h +++ b/Libraries/LibGUI/GItemView.h @@ -31,42 +31,44 @@ #include <LibGUI/GAbstractView.h> #include <LibGUI/GModel.h> -class GScrollBar; +namespace GUI { + +class ScrollBar; class Painter; -class GItemView : public GAbstractView { - C_OBJECT(GItemView) +class ItemView : public AbstractView { + C_OBJECT(ItemView) public: - virtual ~GItemView() override; + virtual ~ItemView() override; int content_width() const; int horizontal_padding() const { return m_horizontal_padding; } - void scroll_into_view(const GModelIndex&, Orientation); + void scroll_into_view(const ModelIndex&, Orientation); Size effective_item_size() const { return m_effective_item_size; } int model_column() const { return m_model_column; } void set_model_column(int column) { m_model_column = column; } - virtual GModelIndex index_at_event_position(const Point&) const override; + virtual ModelIndex index_at_event_position(const Point&) const override; private: - explicit GItemView(GWidget* parent); + explicit ItemView(Widget* parent); virtual void did_update_model() override; - virtual void paint_event(GPaintEvent&) override; - virtual void second_paint_event(GPaintEvent&) override; - virtual void resize_event(GResizeEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; - virtual void keydown_event(GKeyEvent&) override; + virtual void paint_event(PaintEvent&) override; + virtual void second_paint_event(PaintEvent&) override; + virtual void resize_event(ResizeEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; + virtual void keydown_event(KeyEvent&) override; int item_count() const; Rect item_rect(int item_index) const; Vector<int> items_intersecting_rect(const Rect&) const; void update_content_size(); - void get_item_rects(int item_index, const Font&, const GVariant& item_text, Rect& item_rect, Rect& icon_rect, Rect& text_rect) const; + void get_item_rects(int item_index, const Font&, const Variant& item_text, Rect& item_rect, Rect& icon_rect, Rect& text_rect) const; int m_horizontal_padding { 5 }; int m_model_column { 0 }; @@ -78,5 +80,7 @@ private: bool m_rubber_banding { false }; Point m_rubber_band_origin; Point m_rubber_band_current; - Vector<GModelIndex> m_rubber_band_remembered_selection; + Vector<ModelIndex> m_rubber_band_remembered_selection; }; + +} diff --git a/Libraries/LibGUI/GJsonArrayModel.cpp b/Libraries/LibGUI/GJsonArrayModel.cpp index f706a08ab0..232cc04dd4 100644 --- a/Libraries/LibGUI/GJsonArrayModel.cpp +++ b/Libraries/LibGUI/GJsonArrayModel.cpp @@ -28,7 +28,9 @@ #include <LibCore/CFile.h> #include <LibGUI/GJsonArrayModel.h> -void GJsonArrayModel::update() +namespace GUI { + +void JsonArrayModel::update() { auto file = Core::File::construct(m_json_path); if (!file->open(Core::IODevice::ReadOnly)) { @@ -46,18 +48,18 @@ void GJsonArrayModel::update() did_update(); } -GModel::ColumnMetadata GJsonArrayModel::column_metadata(int column) const +Model::ColumnMetadata JsonArrayModel::column_metadata(int column) const { ASSERT(column < m_fields.size()); return { 100, m_fields[column].text_alignment }; } -GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const +Variant JsonArrayModel::data(const ModelIndex& index, Role role) const { auto& field_spec = m_fields[index.column()]; auto& object = m_array.at(index.row()).as_object(); - if (role == GModel::Role::Display) { + if (role == Model::Role::Display) { auto& json_field_name = field_spec.json_field_name; auto data = object.get(json_field_name); if (field_spec.massage_for_display) @@ -67,13 +69,13 @@ GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const return object.get(json_field_name).to_string(); } - if (role == GModel::Role::Sort) { + if (role == Model::Role::Sort) { if (field_spec.massage_for_sort) return field_spec.massage_for_sort(object); return data(index, Role::Display); } - if (role == GModel::Role::Custom) { + if (role == Model::Role::Custom) { if (field_spec.massage_for_custom) return field_spec.massage_for_custom(object); return {}; @@ -82,7 +84,7 @@ GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const return {}; } -void GJsonArrayModel::set_json_path(const String& json_path) +void JsonArrayModel::set_json_path(const String& json_path) { if (m_json_path == json_path) return; @@ -90,3 +92,5 @@ void GJsonArrayModel::set_json_path(const String& json_path) m_json_path = json_path; update(); } + +} diff --git a/Libraries/LibGUI/GJsonArrayModel.h b/Libraries/LibGUI/GJsonArrayModel.h index 0be6b27514..f65074e478 100644 --- a/Libraries/LibGUI/GJsonArrayModel.h +++ b/Libraries/LibGUI/GJsonArrayModel.h @@ -30,10 +30,12 @@ #include <AK/JsonObject.h> #include <LibGUI/GModel.h> -class GJsonArrayModel final : public GModel { +namespace GUI { + +class JsonArrayModel final : public Model { public: struct FieldSpec { - FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function<GVariant(const JsonObject&)>&& a_massage_for_display, Function<GVariant(const JsonObject&)>&& a_massage_for_sort = {}, Function<GVariant(const JsonObject&)>&& a_massage_for_custom = {}) + FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function<Variant(const JsonObject&)>&& a_massage_for_display, Function<Variant(const JsonObject&)>&& a_massage_for_sort = {}, Function<Variant(const JsonObject&)>&& a_massage_for_custom = {}) : column_name(a_column_name) , text_alignment(a_text_alignment) , massage_for_display(move(a_massage_for_display)) @@ -52,30 +54,30 @@ public: String json_field_name; String column_name; TextAlignment text_alignment; - Function<GVariant(const JsonObject&)> massage_for_display; - Function<GVariant(const JsonObject&)> massage_for_sort; - Function<GVariant(const JsonObject&)> massage_for_custom; + Function<Variant(const JsonObject&)> massage_for_display; + Function<Variant(const JsonObject&)> massage_for_sort; + Function<Variant(const JsonObject&)> massage_for_custom; }; - static NonnullRefPtr<GJsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields) + static NonnullRefPtr<JsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields) { - return adopt(*new GJsonArrayModel(json_path, move(fields))); + return adopt(*new JsonArrayModel(json_path, move(fields))); } - virtual ~GJsonArrayModel() override {} + virtual ~JsonArrayModel() override {} - virtual int row_count(const GModelIndex& = GModelIndex()) const override { return m_array.size(); } - virtual int column_count(const GModelIndex& = GModelIndex()) const override { return m_fields.size(); } + virtual int row_count(const ModelIndex& = ModelIndex()) const override { return m_array.size(); } + virtual int column_count(const ModelIndex& = ModelIndex()) const override { return m_fields.size(); } virtual String column_name(int column) const override { return m_fields[column].column_name; } virtual ColumnMetadata column_metadata(int) const override; - virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; + virtual Variant data(const ModelIndex&, Role = Role::Display) const override; virtual void update() override; const String& json_path() const { return m_json_path; } void set_json_path(const String& json_path); private: - GJsonArrayModel(const String& json_path, Vector<FieldSpec>&& fields) + JsonArrayModel(const String& json_path, Vector<FieldSpec>&& fields) : m_json_path(json_path) , m_fields(move(fields)) { @@ -85,3 +87,5 @@ private: Vector<FieldSpec> m_fields; JsonArray m_array; }; + +} diff --git a/Libraries/LibGUI/GLabel.cpp b/Libraries/LibGUI/GLabel.cpp index 247ede8f2b..3a7fa35710 100644 --- a/Libraries/LibGUI/GLabel.cpp +++ b/Libraries/LibGUI/GLabel.cpp @@ -29,22 +29,24 @@ #include <LibGUI/GLabel.h> #include <LibGUI/GPainter.h> -GLabel::GLabel(GWidget* parent) - : GFrame(parent) +namespace GUI { + +Label::Label(Widget* parent) + : Frame(parent) { } -GLabel::GLabel(const StringView& text, GWidget* parent) - : GFrame(parent) +Label::Label(const StringView& text, Widget* parent) + : Frame(parent) , m_text(text) { } -GLabel::~GLabel() +Label::~Label() { } -void GLabel::set_icon(GraphicsBitmap* icon) +void Label::set_icon(GraphicsBitmap* icon) { if (m_icon == icon) return; @@ -52,7 +54,7 @@ void GLabel::set_icon(GraphicsBitmap* icon) update(); } -void GLabel::set_text(const StringView& text) +void Label::set_text(const StringView& text) { if (text == m_text) return; @@ -60,11 +62,11 @@ void GLabel::set_text(const StringView& text) update(); } -void GLabel::paint_event(GPaintEvent& event) +void Label::paint_event(PaintEvent& event) { - GFrame::paint_event(event); + Frame::paint_event(event); - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); if (m_icon) { @@ -92,8 +94,10 @@ void GLabel::paint_event(GPaintEvent& event) } } -void GLabel::size_to_fit() +void Label::size_to_fit() { set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); set_preferred_size(font().width(m_text), 0); } + +} diff --git a/Libraries/LibGUI/GLabel.h b/Libraries/LibGUI/GLabel.h index ad195e5b02..7e2a4267ac 100644 --- a/Libraries/LibGUI/GLabel.h +++ b/Libraries/LibGUI/GLabel.h @@ -31,10 +31,12 @@ class GraphicsBitmap; -class GLabel : public GFrame { - C_OBJECT(GLabel) +namespace GUI { + +class Label : public Frame { + C_OBJECT(Label) public: - virtual ~GLabel() override; + virtual ~Label() override; String text() const { return m_text; } void set_text(const StringView&); @@ -52,10 +54,10 @@ public: void size_to_fit(); protected: - explicit GLabel(GWidget* parent = nullptr); - GLabel(const StringView& text, GWidget* parent = nullptr); + explicit Label(Widget* parent = nullptr); + Label(const StringView& text, Widget* parent = nullptr); - virtual void paint_event(GPaintEvent&) override; + virtual void paint_event(PaintEvent&) override; private: String m_text; @@ -63,3 +65,5 @@ private: TextAlignment m_text_alignment { TextAlignment::Center }; bool m_should_stretch_icon { false }; }; + +} diff --git a/Libraries/LibGUI/GLayout.cpp b/Libraries/LibGUI/GLayout.cpp index fcd9a492b4..e83da15ac2 100644 --- a/Libraries/LibGUI/GLayout.cpp +++ b/Libraries/LibGUI/GLayout.cpp @@ -27,42 +27,44 @@ #include <LibGUI/GLayout.h> #include <LibGUI/GWidget.h> -GLayout::GLayout() +namespace GUI { + +Layout::Layout() { } -GLayout::~GLayout() +Layout::~Layout() { } -void GLayout::notify_adopted(Badge<GWidget>, GWidget& widget) +void Layout::notify_adopted(Badge<Widget>, Widget& widget) { if (m_owner == &widget) return; m_owner = widget.make_weak_ptr(); } -void GLayout::notify_disowned(Badge<GWidget>, GWidget& widget) +void Layout::notify_disowned(Badge<Widget>, Widget& widget) { ASSERT(m_owner == &widget); m_owner.clear(); } -void GLayout::add_entry(Entry&& entry) +void Layout::add_entry(Entry&& entry) { m_entries.append(move(entry)); if (m_owner) m_owner->notify_layout_changed({}); } -void GLayout::add_spacer() +void Layout::add_spacer() { Entry entry; entry.type = Entry::Type::Spacer; add_entry(move(entry)); } -void GLayout::add_layout(OwnPtr<GLayout>&& layout) +void Layout::add_layout(OwnPtr<Layout>&& layout) { Entry entry; entry.type = Entry::Type::Layout; @@ -70,7 +72,7 @@ void GLayout::add_layout(OwnPtr<GLayout>&& layout) add_entry(move(entry)); } -void GLayout::add_widget(GWidget& widget) +void Layout::add_widget(Widget& widget) { Entry entry; entry.type = Entry::Type::Widget; @@ -78,7 +80,7 @@ void GLayout::add_widget(GWidget& widget) add_entry(move(entry)); } -void GLayout::insert_widget_before(GWidget& widget, GWidget& before_widget) +void Layout::insert_widget_before(Widget& widget, Widget& before_widget) { Entry entry; entry.type = Entry::Type::Widget; @@ -90,7 +92,7 @@ void GLayout::insert_widget_before(GWidget& widget, GWidget& before_widget) m_owner->notify_layout_changed({}); } -void GLayout::remove_widget(GWidget& widget) +void Layout::remove_widget(Widget& widget) { m_entries.remove_first_matching([&](auto& entry) { return entry.widget == &widget; @@ -99,7 +101,7 @@ void GLayout::remove_widget(GWidget& widget) m_owner->notify_layout_changed({}); } -void GLayout::set_spacing(int spacing) +void Layout::set_spacing(int spacing) { if (m_spacing == spacing) return; @@ -108,7 +110,7 @@ void GLayout::set_spacing(int spacing) m_owner->notify_layout_changed({}); } -void GLayout::set_margins(const GMargins& margins) +void Layout::set_margins(const Margins& margins) { if (m_margins == margins) return; @@ -116,3 +118,5 @@ void GLayout::set_margins(const GMargins& margins) if (m_owner) m_owner->notify_layout_changed({}); } + +} diff --git a/Libraries/LibGUI/GLayout.h b/Libraries/LibGUI/GLayout.h index eedd3b1ecc..d302d18712 100644 --- a/Libraries/LibGUI/GLayout.h +++ b/Libraries/LibGUI/GLayout.h @@ -32,27 +32,29 @@ #include <AK/WeakPtr.h> #include <LibGUI/GMargins.h> -class GWidget; +namespace GUI { -class GLayout { +class Widget; + +class Layout { public: - GLayout(); - virtual ~GLayout(); + Layout(); + virtual ~Layout(); - void add_widget(GWidget&); - void insert_widget_before(GWidget& widget, GWidget& before_widget); - void add_layout(OwnPtr<GLayout>&&); + void add_widget(Widget&); + void insert_widget_before(Widget& widget, Widget& before_widget); + void add_layout(OwnPtr<Layout>&&); void add_spacer(); - void remove_widget(GWidget&); + void remove_widget(Widget&); - virtual void run(GWidget&) = 0; + virtual void run(Widget&) = 0; - void notify_adopted(Badge<GWidget>, GWidget&); - void notify_disowned(Badge<GWidget>, GWidget&); + void notify_adopted(Badge<Widget>, Widget&); + void notify_disowned(Badge<Widget>, Widget&); - GMargins margins() const { return m_margins; } - void set_margins(const GMargins&); + Margins margins() const { return m_margins; } + void set_margins(const Margins&); int spacing() const { return m_spacing; } void set_spacing(int); @@ -67,14 +69,16 @@ protected: }; Type type { Type::Invalid }; - WeakPtr<GWidget> widget; - OwnPtr<GLayout> layout; + WeakPtr<Widget> widget; + OwnPtr<Layout> layout; }; void add_entry(Entry&&); - WeakPtr<GWidget> m_owner; + WeakPtr<Widget> m_owner; Vector<Entry> m_entries; - GMargins m_margins; + Margins m_margins; int m_spacing { 3 }; }; + +} diff --git a/Libraries/LibGUI/GLazyWidget.cpp b/Libraries/LibGUI/GLazyWidget.cpp index 6f4a358dc5..c8826e347e 100644 --- a/Libraries/LibGUI/GLazyWidget.cpp +++ b/Libraries/LibGUI/GLazyWidget.cpp @@ -26,16 +26,18 @@ #include <LibGUI/GLazyWidget.h> -GLazyWidget::GLazyWidget(GWidget* parent) - : GWidget(parent) +namespace GUI { + +LazyWidget::LazyWidget(Widget* parent) + : Widget(parent) { } -GLazyWidget::~GLazyWidget() +LazyWidget::~LazyWidget() { } -void GLazyWidget::show_event(GShowEvent&) +void LazyWidget::show_event(ShowEvent&) { if (m_has_been_shown) return; @@ -44,3 +46,5 @@ void GLazyWidget::show_event(GShowEvent&) ASSERT(on_first_show); on_first_show(*this); } + +} diff --git a/Libraries/LibGUI/GLazyWidget.h b/Libraries/LibGUI/GLazyWidget.h index e698f9764d..75c4d6a382 100644 --- a/Libraries/LibGUI/GLazyWidget.h +++ b/Libraries/LibGUI/GLazyWidget.h @@ -28,18 +28,21 @@ #include <LibGUI/GWidget.h> -class GLazyWidget : public GWidget { - C_OBJECT(GLazyWidget) +namespace GUI { + +class LazyWidget : public Widget { + C_OBJECT(LazyWidget) public: - virtual ~GLazyWidget() override; + virtual ~LazyWidget() override; - Function<void(GLazyWidget&)> on_first_show; + Function<void(LazyWidget&)> on_first_show; protected: - explicit GLazyWidget(GWidget* parent = nullptr); + explicit LazyWidget(Widget* parent = nullptr); private: - virtual void show_event(GShowEvent&) override; + virtual void show_event(ShowEvent&) override; bool m_has_been_shown { false }; }; +} diff --git a/Libraries/LibGUI/GListView.cpp b/Libraries/LibGUI/GListView.cpp index 750a4b1a1b..7d98f39fae 100644 --- a/Libraries/LibGUI/GListView.cpp +++ b/Libraries/LibGUI/GListView.cpp @@ -30,8 +30,10 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GScrollBar.h> -GListView::GListView(GWidget* parent) - : GAbstractView(parent) +namespace GUI { + +ListView::ListView(Widget* parent) + : AbstractView(parent) { set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); @@ -40,18 +42,18 @@ GListView::GListView(GWidget* parent) set_frame_thickness(2); } -GListView::~GListView() +ListView::~ListView() { } -void GListView::update_content_size() +void ListView::update_content_size() { if (!model()) return set_content_size({}); int content_width = 0; for (int row = 0, row_count = model()->row_count(); row < row_count; ++row) { - auto text = model()->data(model()->index(row, m_model_column), GModel::Role::Display); + auto text = model()->data(model()->index(row, m_model_column), Model::Role::Display); content_width = max(content_width, font().width(text.to_string())); } @@ -61,30 +63,30 @@ void GListView::update_content_size() set_content_size({ content_width, content_height }); } -void GListView::resize_event(GResizeEvent& event) +void ListView::resize_event(ResizeEvent& event) { update_content_size(); - GAbstractView::resize_event(event); + AbstractView::resize_event(event); } -void GListView::did_update_model() +void ListView::did_update_model() { - GAbstractView::did_update_model(); + AbstractView::did_update_model(); update_content_size(); update(); } -Rect GListView::content_rect(int row) const +Rect ListView::content_rect(int row) const { return { 0, row * item_height(), content_width(), item_height() }; } -Rect GListView::content_rect(const GModelIndex& index) const +Rect ListView::content_rect(const ModelIndex& index) const { return content_rect(index.row()); } -GModelIndex GListView::index_at_event_position(const Point& point) const +ModelIndex ListView::index_at_event_position(const Point& point) const { ASSERT(model()); @@ -97,19 +99,19 @@ GModelIndex GListView::index_at_event_position(const Point& point) const return {}; } -Point GListView::adjusted_position(const Point& position) const +Point ListView::adjusted_position(const Point& position) const { return position.translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness()); } -void GListView::paint_event(GPaintEvent& event) +void ListView::paint_event(PaintEvent& event) { - GFrame::paint_event(event); + Frame::paint_event(event); if (!model()) return; - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(frame_inner_rect()); painter.add_clip_rect(event.rect()); painter.translate(frame_thickness(), frame_thickness()); @@ -151,7 +153,7 @@ void GListView::paint_event(GPaintEvent& event) if (is_selected_row) text_color = palette().selection_text(); else - text_color = model()->data(index, GModel::Role::ForegroundColor).to_color(palette().color(foreground_role())); + text_color = model()->data(index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); auto text_rect = row_rect; text_rect.move_by(horizontal_padding(), 0); text_rect.set_width(text_rect.width() - horizontal_padding() * 2); @@ -165,14 +167,14 @@ void GListView::paint_event(GPaintEvent& event) painter.fill_rect(unpainted_rect, palette().color(background_role())); } -int GListView::item_count() const +int ListView::item_count() const { if (!model()) return 0; return model()->row_count(); } -void GListView::keydown_event(GKeyEvent& event) +void ListView::keydown_event(KeyEvent& event) { if (!model()) return; @@ -182,7 +184,7 @@ void GListView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Up) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() - 1, old_index.column()); @@ -197,7 +199,7 @@ void GListView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Down) { - GModelIndex new_index; + ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); new_index = model.index(old_index.row() + 1, old_index.column()); @@ -233,20 +235,20 @@ void GListView::keydown_event(GKeyEvent& event) } return; } - return GWidget::keydown_event(event); + return Widget::keydown_event(event); } -void GListView::scroll_into_view(const GModelIndex& index, Orientation orientation) +void ListView::scroll_into_view(const ModelIndex& index, Orientation orientation) { auto rect = content_rect(index.row()); - GScrollableWidget::scroll_into_view(rect, orientation); + ScrollableWidget::scroll_into_view(rect, orientation); } -void GListView::doubleclick_event(GMouseEvent& event) +void ListView::doubleclick_event(MouseEvent& event) { if (!model()) return; - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { if (!selection().is_empty()) { if (is_editable()) begin_editing(selection().first()); @@ -255,3 +257,5 @@ void GListView::doubleclick_event(GMouseEvent& event) } } } + +} diff --git a/Libraries/LibGUI/GListView.h b/Libraries/LibGUI/GListView.h index fb237bf8f1..0a7b61aabb 100644 --- a/Libraries/LibGUI/GListView.h +++ b/Libraries/LibGUI/GListView.h @@ -31,14 +31,16 @@ #include <LibGUI/GAbstractView.h> #include <LibGUI/GModel.h> -class GScrollBar; +namespace GUI { + +class ScrollBar; class Painter; -class GListView : public GAbstractView { - C_OBJECT(GListView) +class ListView : public AbstractView { + C_OBJECT(ListView) public: - explicit GListView(GWidget* parent); - virtual ~GListView() override; + explicit ListView(Widget* parent); + virtual ~ListView() override; int item_height() const { return 16; } @@ -47,22 +49,22 @@ public: int horizontal_padding() const { return m_horizontal_padding; } - void scroll_into_view(const GModelIndex&, Orientation); + void scroll_into_view(const ModelIndex&, Orientation); Point adjusted_position(const Point&) const; - virtual GModelIndex index_at_event_position(const Point&) const override; - virtual Rect content_rect(const GModelIndex&) const override; + virtual ModelIndex index_at_event_position(const Point&) const override; + virtual Rect content_rect(const ModelIndex&) const override; int model_column() const { return m_model_column; } void set_model_column(int column) { m_model_column = column; } private: virtual void did_update_model() override; - virtual void paint_event(GPaintEvent&) override; - virtual void doubleclick_event(GMouseEvent&) override; - virtual void keydown_event(GKeyEvent&) override; - virtual void resize_event(GResizeEvent&) override; + virtual void paint_event(PaintEvent&) override; + virtual void doubleclick_event(MouseEvent&) override; + virtual void keydown_event(KeyEvent&) override; + virtual void resize_event(ResizeEvent&) override; Rect content_rect(int row) const; int item_count() const; @@ -72,3 +74,5 @@ private: int m_model_column { 0 }; bool m_alternating_row_colors { true }; }; + +} diff --git a/Libraries/LibGUI/GMargins.h b/Libraries/LibGUI/GMargins.h index 376162acda..fc25e58cf3 100644 --- a/Libraries/LibGUI/GMargins.h +++ b/Libraries/LibGUI/GMargins.h @@ -26,17 +26,19 @@ #pragma once -class GMargins { +namespace GUI { + +class Margins { public: - GMargins() {} - GMargins(int left, int top, int right, int bottom) + Margins() {} + Margins(int left, int top, int right, int bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) { } - ~GMargins() {} + ~Margins() {} bool is_null() const { return !m_left && !m_top && !m_right && !m_bottom; } @@ -50,7 +52,7 @@ public: void set_right(int value) { m_right = value; } void set_bottom(int value) { m_bottom = value; } - bool operator==(const GMargins& other) const + bool operator==(const Margins& other) const { return m_left == other.m_left && m_top == other.m_top @@ -64,3 +66,4 @@ private: int m_right { 0 }; int m_bottom { 0 }; }; +} diff --git a/Libraries/LibGUI/GMenu.cpp b/Libraries/LibGUI/GMenu.cpp index 18c4dd8f81..f33e6814b6 100644 --- a/Libraries/LibGUI/GMenu.cpp +++ b/Libraries/LibGUI/GMenu.cpp @@ -30,17 +30,19 @@ #include <LibGUI/GMenu.h> #include <LibGUI/GWindowServerConnection.h> -//#define GMENU_DEBUG +//#define MENU_DEBUG -static HashMap<int, GMenu*>& all_menus() +namespace GUI { + +static HashMap<int, Menu*>& all_menus() { - static HashMap<int, GMenu*>* map; + static HashMap<int, Menu*>* map; if (!map) - map = new HashMap<int, GMenu*>(); + map = new HashMap<int, Menu*>(); return *map; } -GMenu* GMenu::from_menu_id(int menu_id) +Menu* Menu::from_menu_id(int menu_id) { auto it = all_menus().find(menu_id); if (it == all_menus().end()) @@ -48,76 +50,76 @@ GMenu* GMenu::from_menu_id(int menu_id) return (*it).value; } -GMenu::GMenu(const StringView& name) +Menu::Menu(const StringView& name) : m_name(name) { } -GMenu::~GMenu() +Menu::~Menu() { unrealize_menu(); } -void GMenu::add_action(NonnullRefPtr<GAction> action) +void Menu::add_action(NonnullRefPtr<Action> action) { - m_items.append(make<GMenuItem>(m_menu_id, move(action))); + m_items.append(make<MenuItem>(m_menu_id, move(action))); #ifdef GMENU_DEBUG - dbgprintf("GMenu::add_action(): MenuItem Menu ID: %d\n", m_menu_id); + dbgprintf("GUI::Menu::add_action(): MenuItem Menu ID: %d\n", m_menu_id); #endif } -void GMenu::add_submenu(NonnullRefPtr<GMenu> submenu) +void Menu::add_submenu(NonnullRefPtr<Menu> submenu) { - m_items.append(make<GMenuItem>(m_menu_id, move(submenu))); + m_items.append(make<MenuItem>(m_menu_id, move(submenu))); } -void GMenu::add_separator() +void Menu::add_separator() { - m_items.append(make<GMenuItem>(m_menu_id, GMenuItem::Separator)); + m_items.append(make<MenuItem>(m_menu_id, MenuItem::Type::Separator)); } -void GMenu::realize_if_needed() +void Menu::realize_if_needed() { if (m_menu_id == -1) realize_menu(); } -void GMenu::popup(const Point& screen_position) +void Menu::popup(const Point& screen_position) { realize_if_needed(); - GWindowServerConnection::the().post_message(WindowServer::PopupMenu(m_menu_id, screen_position)); + WindowServerConnection::the().post_message(WindowServer::PopupMenu(m_menu_id, screen_position)); } -void GMenu::dismiss() +void Menu::dismiss() { if (m_menu_id == -1) return; - GWindowServerConnection::the().post_message(WindowServer::DismissMenu(m_menu_id)); + WindowServerConnection::the().post_message(WindowServer::DismissMenu(m_menu_id)); } -int GMenu::realize_menu() +int Menu::realize_menu() { - m_menu_id = GWindowServerConnection::the().send_sync<WindowServer::CreateMenu>(m_name)->menu_id(); + m_menu_id = WindowServerConnection::the().send_sync<WindowServer::CreateMenu>(m_name)->menu_id(); -#ifdef GMENU_DEBUG - dbgprintf("GMenu::realize_menu(): New menu ID: %d\n", m_menu_id); +#ifdef MENU_DEBUG + dbgprintf("GUI::Menu::realize_menu(): New menu ID: %d\n", m_menu_id); #endif ASSERT(m_menu_id > 0); for (int i = 0; i < m_items.size(); ++i) { auto& item = m_items[i]; item.set_menu_id({}, m_menu_id); item.set_identifier({}, i); - if (item.type() == GMenuItem::Separator) { - GWindowServerConnection::the().send_sync<WindowServer::AddMenuSeparator>(m_menu_id); + if (item.type() == MenuItem::Type::Separator) { + WindowServerConnection::the().send_sync<WindowServer::AddMenuSeparator>(m_menu_id); continue; } - if (item.type() == GMenuItem::Submenu) { + if (item.type() == MenuItem::Type::Submenu) { auto& submenu = *item.submenu(); submenu.realize_if_needed(); - GWindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, "", -1, false); + WindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, "", -1, false); continue; } - if (item.type() == GMenuItem::Action) { + if (item.type() == MenuItem::Type::Action) { auto& action = *item.action(); int icon_buffer_id = -1; if (action.icon()) { @@ -129,32 +131,34 @@ int GMenu::realize_menu() auto shared_icon = GraphicsBitmap::create_with_shared_buffer(GraphicsBitmap::Format::RGBA32, *shared_buffer, action.icon()->size()); memcpy(shared_buffer->data(), action.icon()->bits(0), action.icon()->size_in_bytes()); shared_buffer->seal(); - shared_buffer->share_with(GWindowServerConnection::the().server_pid()); + shared_buffer->share_with(WindowServerConnection::the().server_pid()); action.set_icon(shared_icon); } icon_buffer_id = action.icon()->shared_buffer_id(); } auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String(); bool exclusive = action.group() && action.group()->is_exclusive() && action.is_checkable(); - GWindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, shortcut_text, icon_buffer_id, exclusive); + WindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, shortcut_text, icon_buffer_id, exclusive); } } all_menus().set(m_menu_id, this); return m_menu_id; } -void GMenu::unrealize_menu() +void Menu::unrealize_menu() { if (m_menu_id == -1) return; all_menus().remove(m_menu_id); - GWindowServerConnection::the().send_sync<WindowServer::DestroyMenu>(m_menu_id); + WindowServerConnection::the().send_sync<WindowServer::DestroyMenu>(m_menu_id); m_menu_id = 0; } -GAction* GMenu::action_at(int index) +Action* Menu::action_at(int index) { if (index >= m_items.size()) return nullptr; return m_items[index].action(); } + +} diff --git a/Libraries/LibGUI/GMenu.h b/Libraries/LibGUI/GMenu.h index 0c4820d294..13fcac6800 100644 --- a/Libraries/LibGUI/GMenu.h +++ b/Libraries/LibGUI/GMenu.h @@ -32,24 +32,27 @@ #include <LibCore/CObject.h> #include <LibGUI/GMenuItem.h> -class GAction; class Point; -class GMenu final : public Core::Object { - C_OBJECT(GMenu) +namespace GUI { + +class Action; + +class Menu final : public Core::Object { + C_OBJECT(Menu) public: - explicit GMenu(const StringView& name = ""); - virtual ~GMenu() override; + explicit Menu(const StringView& name = ""); + virtual ~Menu() override; - static GMenu* from_menu_id(int); + static Menu* from_menu_id(int); const String& name() const { return m_name; } - GAction* action_at(int); + Action* action_at(int); - void add_action(NonnullRefPtr<GAction>); + void add_action(NonnullRefPtr<Action>); void add_separator(); - void add_submenu(NonnullRefPtr<GMenu>); + void add_submenu(NonnullRefPtr<Menu>); void popup(const Point& screen_position); void dismiss(); @@ -57,7 +60,7 @@ public: Function<void(unsigned)> on_item_activation; private: - friend class GMenuBar; + friend class MenuBar; int menu_id() const { return m_menu_id; } int realize_menu(); @@ -66,5 +69,7 @@ private: int m_menu_id { -1 }; String m_name; - NonnullOwnPtrVector<GMenuItem> m_items; + NonnullOwnPtrVector<MenuItem> m_items; }; + +} diff --git a/Libraries/LibGUI/GMenuBar.cpp b/Libraries/LibGUI/GMenuBar.cpp index 0325d652ff..b4bb11ab92 100644 --- a/Libraries/LibGUI/GMenuBar.cpp +++ b/Libraries/LibGUI/GMenuBar.cpp @@ -27,34 +27,36 @@ #include <LibGUI/GMenuBar.h> #include <LibGUI/GWindowServerConnection.h> -GMenuBar::GMenuBar() +namespace GUI { + +MenuBar::MenuBar() { } -GMenuBar::~GMenuBar() +MenuBar::~MenuBar() { unrealize_menubar(); } -void GMenuBar::add_menu(NonnullRefPtr<GMenu> menu) +void MenuBar::add_menu(NonnullRefPtr<Menu> menu) { m_menus.append(move(menu)); } -int GMenuBar::realize_menubar() +int MenuBar::realize_menubar() { - return GWindowServerConnection::the().send_sync<WindowServer::CreateMenubar>()->menubar_id(); + return WindowServerConnection::the().send_sync<WindowServer::CreateMenubar>()->menubar_id(); } -void GMenuBar::unrealize_menubar() +void MenuBar::unrealize_menubar() { if (m_menubar_id == -1) return; - GWindowServerConnection::the().send_sync<WindowServer::DestroyMenubar>(m_menubar_id); + WindowServerConnection::the().send_sync<WindowServer::DestroyMenubar>(m_menubar_id); m_menubar_id = -1; } -void GMenuBar::notify_added_to_application(Badge<GApplication>) +void MenuBar::notify_added_to_application(Badge<Application>) { ASSERT(m_menubar_id == -1); m_menubar_id = realize_menubar(); @@ -62,12 +64,14 @@ void GMenuBar::notify_added_to_application(Badge<GApplication>) for (auto& menu : m_menus) { int menu_id = menu.realize_menu(); ASSERT(menu_id != -1); - GWindowServerConnection::the().send_sync<WindowServer::AddMenuToMenubar>(m_menubar_id, menu_id); + WindowServerConnection::the().send_sync<WindowServer::AddMenuToMenubar>(m_menubar_id, menu_id); } - GWindowServerConnection::the().send_sync<WindowServer::SetApplicationMenubar>(m_menubar_id); + WindowServerConnection::the().send_sync<WindowServer::SetApplicationMenubar>(m_menubar_id); } -void GMenuBar::notify_removed_from_application(Badge<GApplication>) +void MenuBar::notify_removed_from_application(Badge<Application>) { unrealize_menubar(); } + +} diff --git a/Libraries/LibGUI/GMenuBar.h b/Libraries/LibGUI/GMenuBar.h index 2e8b9a98fa..53d88ef5f3 100644 --- a/Libraries/LibGUI/GMenuBar.h +++ b/Libraries/LibGUI/GMenuBar.h @@ -30,22 +30,26 @@ #include <AK/NonnullOwnPtrVector.h> #include <LibGUI/GMenu.h> -class GApplication; +namespace GUI { -class GMenuBar { +class Application; + +class MenuBar { public: - GMenuBar(); - ~GMenuBar(); + MenuBar(); + ~MenuBar(); - void add_menu(NonnullRefPtr<GMenu>); + void add_menu(NonnullRefPtr<Menu>); - void notify_added_to_application(Badge<GApplication>); - void notify_removed_from_application(Badge<GApplication>); + void notify_added_to_application(Badge<Application>); + void notify_removed_from_application(Badge<Application>); private: int realize_menubar(); void unrealize_menubar(); int m_menubar_id { -1 }; - NonnullRefPtrVector<GMenu> m_menus; + NonnullRefPtrVector<Menu> m_menus; }; + +} diff --git a/Libraries/LibGUI/GMenuItem.cpp b/Libraries/LibGUI/GMenuItem.cpp index 42e415131d..7cb3ae1da8 100644 --- a/Libraries/LibGUI/GMenuItem.cpp +++ b/Libraries/LibGUI/GMenuItem.cpp @@ -29,14 +29,16 @@ #include <LibGUI/GMenuItem.h> #include <LibGUI/GWindowServerConnection.h> -GMenuItem::GMenuItem(unsigned menu_id, Type type) +namespace GUI { + +MenuItem::MenuItem(unsigned menu_id, Type type) : m_type(type) , m_menu_id(menu_id) { } -GMenuItem::GMenuItem(unsigned menu_id, NonnullRefPtr<GAction>&& action) - : m_type(Action) +MenuItem::MenuItem(unsigned menu_id, NonnullRefPtr<Action>&& action) + : m_type(Type::Action) , m_menu_id(menu_id) , m_action(move(action)) { @@ -47,20 +49,20 @@ GMenuItem::GMenuItem(unsigned menu_id, NonnullRefPtr<GAction>&& action) m_checked = m_action->is_checked(); } -GMenuItem::GMenuItem(unsigned menu_id, NonnullRefPtr<GMenu>&& submenu) - : m_type(Submenu) +MenuItem::MenuItem(unsigned menu_id, NonnullRefPtr<Menu>&& submenu) + : m_type(Type::Submenu) , m_menu_id(menu_id) , m_submenu(move(submenu)) { } -GMenuItem::~GMenuItem() +MenuItem::~MenuItem() { if (m_action) m_action->unregister_menu_item({}, *this); } -void GMenuItem::set_enabled(bool enabled) +void MenuItem::set_enabled(bool enabled) { if (m_enabled == enabled) return; @@ -68,7 +70,7 @@ void GMenuItem::set_enabled(bool enabled) update_window_server(); } -void GMenuItem::set_checked(bool checked) +void MenuItem::set_checked(bool checked) { ASSERT(is_checkable()); if (m_checked == checked) @@ -77,11 +79,13 @@ void GMenuItem::set_checked(bool checked) update_window_server(); } -void GMenuItem::update_window_server() +void MenuItem::update_window_server() { if (m_menu_id < 0) return; auto& action = *m_action; auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String(); - GWindowServerConnection::the().send_sync<WindowServer::UpdateMenuItem>(m_menu_id, m_identifier, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, shortcut_text); + WindowServerConnection::the().send_sync<WindowServer::UpdateMenuItem>(m_menu_id, m_identifier, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, shortcut_text); +} + } diff --git a/Libraries/LibGUI/GMenuItem.h b/Libraries/LibGUI/GMenuItem.h index a73e7cc06a..d243dba7b4 100644 --- a/Libraries/LibGUI/GMenuItem.h +++ b/Libraries/LibGUI/GMenuItem.h @@ -31,31 +31,33 @@ #include <AK/OwnPtr.h> #include <AK/String.h> -class GAction; -class GMenu; +namespace GUI { -class GMenuItem { +class Action; +class Menu; + +class MenuItem { public: - enum Type { + enum class Type { Invalid, Action, Separator, Submenu, }; - GMenuItem(unsigned menu_id, Type); - GMenuItem(unsigned menu_id, NonnullRefPtr<GAction>&&); - GMenuItem(unsigned menu_id, NonnullRefPtr<GMenu>&&); - ~GMenuItem(); + MenuItem(unsigned menu_id, Type); + MenuItem(unsigned menu_id, NonnullRefPtr<Action>&&); + MenuItem(unsigned menu_id, NonnullRefPtr<Menu>&&); + ~MenuItem(); Type type() const { return m_type; } String text() const; - const GAction* action() const { return m_action.ptr(); } - GAction* action() { return m_action.ptr(); } + const Action* action() const { return m_action.ptr(); } + Action* action() { return m_action.ptr(); } unsigned identifier() const { return m_identifier; } - GMenu* submenu() { return m_submenu.ptr(); } - const GMenu* submenu() const { return m_submenu.ptr(); } + Menu* submenu() { return m_submenu.ptr(); } + const Menu* submenu() const { return m_submenu.ptr(); } bool is_checkable() const { return m_checkable; } void set_checkable(bool checkable) { m_checkable = checkable; } @@ -66,18 +68,20 @@ public: bool is_enabled() const { return m_enabled; } void set_enabled(bool); - void set_menu_id(Badge<GMenu>, unsigned menu_id) { m_menu_id = menu_id; } - void set_identifier(Badge<GMenu>, unsigned identifier) { m_identifier = identifier; } + void set_menu_id(Badge<Menu>, unsigned menu_id) { m_menu_id = menu_id; } + void set_identifier(Badge<Menu>, unsigned identifier) { m_identifier = identifier; } private: void update_window_server(); - Type m_type { Invalid }; + Type m_type { Type::Invalid }; int m_menu_id { -1 }; unsigned m_identifier { 0 }; bool m_enabled { true }; bool m_checkable { false }; bool m_checked { false }; - RefPtr<GAction> m_action; - RefPtr<GMenu> m_submenu; + RefPtr<Action> m_action; + RefPtr<Menu> m_submenu; }; + +} diff --git a/Libraries/LibGUI/GMessageBox.cpp b/Libraries/LibGUI/GMessageBox.cpp index ab7b0769d0..916e089ef5 100644 --- a/Libraries/LibGUI/GMessageBox.cpp +++ b/Libraries/LibGUI/GMessageBox.cpp @@ -30,14 +30,16 @@ #include <LibGUI/GMessageBox.h> #include <stdio.h> -int GMessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent) +namespace GUI { + +int MessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent) { - auto box = GMessageBox::construct(text, title, type, input_type, parent); + auto box = MessageBox::construct(text, title, type, input_type, parent); return box->exec(); } -GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent) - : GDialog(parent) +MessageBox::MessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent) + : Dialog(parent) , m_text(text) , m_type(type) , m_input_type(input_type) @@ -46,11 +48,11 @@ GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type t build(); } -GMessageBox::~GMessageBox() +MessageBox::~MessageBox() { } -RefPtr<GraphicsBitmap> GMessageBox::icon() const +RefPtr<GraphicsBitmap> MessageBox::icon() const { switch (m_type) { case Type::Information: @@ -64,75 +66,77 @@ RefPtr<GraphicsBitmap> GMessageBox::icon() const } } -bool GMessageBox::should_include_ok_button() const +bool MessageBox::should_include_ok_button() const { return m_input_type == InputType::OK || m_input_type == InputType::OKCancel; } -bool GMessageBox::should_include_cancel_button() const +bool MessageBox::should_include_cancel_button() const { return m_input_type == InputType::OKCancel; } -void GMessageBox::build() +void MessageBox::build() { - auto widget = GWidget::construct(); + auto widget = Widget::construct(); set_main_widget(widget); int text_width = widget->font().width(m_text); int icon_width = 0; - widget->set_layout(make<GVBoxLayout>()); + widget->set_layout(make<VBoxLayout>()); widget->set_fill_with_background_color(true); widget->layout()->set_margins({ 0, 15, 0, 15 }); widget->layout()->set_spacing(15); - RefPtr<GWidget> message_container = widget; + RefPtr<Widget> message_container = widget; if (m_type != Type::None) { - message_container = GWidget::construct(widget.ptr()); - message_container->set_layout(make<GHBoxLayout>()); + message_container = Widget::construct(widget.ptr()); + message_container->set_layout(make<HBoxLayout>()); message_container->layout()->set_margins({ 8, 0, 8, 0 }); message_container->layout()->set_spacing(8); - auto icon_label = GLabel::construct(message_container); + auto icon_label = Label::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 = GLabel::construct(m_text, message_container); + auto label = Label::construct(m_text, message_container); label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); label->set_preferred_size(text_width, 16); - auto button_container = GWidget::construct(widget.ptr()); - button_container->set_layout(make<GHBoxLayout>()); + auto button_container = Widget::construct(widget.ptr()); + button_container->set_layout(make<HBoxLayout>()); button_container->layout()->set_spacing(5); button_container->layout()->set_margins({ 15, 0, 15, 0 }); if (should_include_ok_button()) { - auto ok_button = GButton::construct(button_container); + auto ok_button = Button::construct(button_container); ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); ok_button->set_preferred_size(0, 20); ok_button->set_text("OK"); ok_button->on_click = [this](auto&) { dbgprintf("GMessageBox: OK button clicked\n"); - done(GDialog::ExecOK); + done(Dialog::ExecOK); }; } if (should_include_cancel_button()) { - auto cancel_button = GButton::construct(button_container); + auto cancel_button = Button::construct(button_container); cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); cancel_button->set_preferred_size(0, 20); cancel_button->set_text("Cancel"); cancel_button->on_click = [this](auto&) { dbgprintf("GMessageBox: Cancel button clicked\n"); - done(GDialog::ExecCancel); + done(Dialog::ExecCancel); }; } set_rect(x(), y(), text_width + icon_width + 80, 100); set_resizable(false); } + +} diff --git a/Libraries/LibGUI/GMessageBox.h b/Libraries/LibGUI/GMessageBox.h index f0df664d71..25f5b4c417 100644 --- a/Libraries/LibGUI/GMessageBox.h +++ b/Libraries/LibGUI/GMessageBox.h @@ -28,8 +28,10 @@ #include <LibGUI/GDialog.h> -class GMessageBox : public GDialog { - C_OBJECT(GMessageBox) +namespace GUI { + +class MessageBox : public Dialog { + C_OBJECT(MessageBox) public: enum class Type { None, @@ -43,12 +45,12 @@ public: OKCancel, }; - virtual ~GMessageBox() override; + virtual ~MessageBox() override; static int show(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, Core::Object* parent = nullptr); private: - explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, Core::Object* parent = nullptr); + explicit MessageBox(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, Core::Object* parent = nullptr); bool should_include_ok_button() const; bool should_include_cancel_button() const; @@ -59,3 +61,5 @@ private: Type m_type { Type::None }; InputType m_input_type { InputType::OK }; }; + +} diff --git a/Libraries/LibGUI/GModel.cpp b/Libraries/LibGUI/GModel.cpp index 813a051109..d83cb9ffa4 100644 --- a/Libraries/LibGUI/GModel.cpp +++ b/Libraries/LibGUI/GModel.cpp @@ -27,31 +27,33 @@ #include <LibGUI/GAbstractView.h> #include <LibGUI/GModel.h> -GModel::GModel() +namespace GUI { + +Model::Model() { } -GModel::~GModel() +Model::~Model() { } -void GModel::register_view(Badge<GAbstractView>, GAbstractView& view) +void Model::register_view(Badge<AbstractView>, AbstractView& view) { m_views.set(&view); } -void GModel::unregister_view(Badge<GAbstractView>, GAbstractView& view) +void Model::unregister_view(Badge<AbstractView>, AbstractView& view) { m_views.remove(&view); } -void GModel::for_each_view(Function<void(GAbstractView&)> callback) +void Model::for_each_view(Function<void(AbstractView&)> callback) { for (auto* view : m_views) callback(*view); } -void GModel::did_update() +void Model::did_update() { if (on_update) on_update(); @@ -60,12 +62,12 @@ void GModel::did_update() }); } -GModelIndex GModel::create_index(int row, int column, const void* data) const +ModelIndex Model::create_index(int row, int column, const void* data) const { - return GModelIndex(*this, row, column, const_cast<void*>(data)); + return ModelIndex(*this, row, column, const_cast<void*>(data)); } -GModelIndex GModel::sibling(int row, int column, const GModelIndex& parent) const +ModelIndex Model::sibling(int row, int column, const ModelIndex& parent) const { if (!parent.is_valid()) return index(row, column, {}); @@ -74,3 +76,5 @@ GModelIndex GModel::sibling(int row, int column, const GModelIndex& parent) cons return {}; return index(row, column, parent); } + +} diff --git a/Libraries/LibGUI/GModel.h b/Libraries/LibGUI/GModel.h index 12f16fdeb8..bf7857ed6e 100644 --- a/Libraries/LibGUI/GModel.h +++ b/Libraries/LibGUI/GModel.h @@ -36,15 +36,18 @@ #include <LibGUI/GVariant.h> class Font; -class GAbstractView; -enum class GSortOrder { +namespace GUI { + +class AbstractView; + +enum class SortOrder { None, Ascending, Descending }; -class GModel : public RefCounted<GModel> { +class Model : public RefCounted<Model> { public: struct ColumnMetadata { int preferred_width { 0 }; @@ -68,52 +71,54 @@ public: DragData, }; - virtual ~GModel(); + virtual ~Model(); - virtual int row_count(const GModelIndex& = GModelIndex()) const = 0; - virtual int column_count(const GModelIndex& = GModelIndex()) const = 0; + virtual int row_count(const ModelIndex& = ModelIndex()) const = 0; + virtual int column_count(const ModelIndex& = ModelIndex()) const = 0; virtual String row_name(int) const { return {}; } virtual String column_name(int) const { return {}; } virtual ColumnMetadata column_metadata(int) const { return {}; } - virtual GVariant data(const GModelIndex&, Role = Role::Display) const = 0; + virtual Variant data(const ModelIndex&, Role = Role::Display) const = 0; virtual void update() = 0; - virtual GModelIndex parent_index(const GModelIndex&) const { return {}; } - virtual GModelIndex index(int row, int column = 0, const GModelIndex& = GModelIndex()) const { return create_index(row, column); } - virtual GModelIndex sibling(int row, int column, const GModelIndex& parent) const; - virtual bool is_editable(const GModelIndex&) const { return false; } - virtual void set_data(const GModelIndex&, const GVariant&) {} + virtual ModelIndex parent_index(const ModelIndex&) const { return {}; } + virtual ModelIndex index(int row, int column = 0, const ModelIndex& = ModelIndex()) const { return create_index(row, column); } + virtual ModelIndex sibling(int row, int column, const ModelIndex& parent) const; + virtual bool is_editable(const ModelIndex&) const { return false; } + virtual void set_data(const ModelIndex&, const Variant&) {} virtual int tree_column() const { return 0; } - bool is_valid(const GModelIndex& index) const + bool is_valid(const ModelIndex& index) const { auto parent_index = this->parent_index(index); return index.row() >= 0 && index.row() < row_count(parent_index) && index.column() >= 0 && index.column() < column_count(parent_index); } virtual int key_column() const { return -1; } - virtual GSortOrder sort_order() const { return GSortOrder::None; } - virtual void set_key_column_and_sort_order(int, GSortOrder) {} + virtual SortOrder sort_order() const { return SortOrder::None; } + virtual void set_key_column_and_sort_order(int, SortOrder) {} virtual StringView drag_data_type() const { return {}; } - void register_view(Badge<GAbstractView>, GAbstractView&); - void unregister_view(Badge<GAbstractView>, GAbstractView&); + void register_view(Badge<AbstractView>, AbstractView&); + void unregister_view(Badge<AbstractView>, AbstractView&); Function<void()> on_update; protected: - GModel(); + Model(); - void for_each_view(Function<void(GAbstractView&)>); + void for_each_view(Function<void(AbstractView&)>); void did_update(); - GModelIndex create_index(int row, int column, const void* data = nullptr) const; + ModelIndex create_index(int row, int column, const void* data = nullptr) const; private: - HashTable<GAbstractView*> m_views; + HashTable<AbstractView*> m_views; }; -inline GModelIndex GModelIndex::parent() const +inline ModelIndex ModelIndex::parent() const { - return m_model ? m_model->parent_index(*this) : GModelIndex(); + return m_model ? m_model->parent_index(*this) : ModelIndex(); +} + } diff --git a/Libraries/LibGUI/GModelEditingDelegate.h b/Libraries/LibGUI/GModelEditingDelegate.h index 80a33fe1b9..2276c9c348 100644 --- a/Libraries/LibGUI/GModelEditingDelegate.h +++ b/Libraries/LibGUI/GModelEditingDelegate.h @@ -30,12 +30,14 @@ #include <LibGUI/GTextBox.h> #include <LibGUI/GWidget.h> -class GModelEditingDelegate { +namespace GUI { + +class ModelEditingDelegate { public: - GModelEditingDelegate() {} - virtual ~GModelEditingDelegate() {} + ModelEditingDelegate() {} + virtual ~ModelEditingDelegate() {} - void bind(GModel& model, const GModelIndex& index) + void bind(Model& model, const ModelIndex& index) { if (m_model.ptr() == &model && m_index == index) return; @@ -44,18 +46,18 @@ public: m_widget = create_widget(); } - GWidget* widget() { return m_widget; } - const GWidget* widget() const { return m_widget; } + Widget* widget() { return m_widget; } + const Widget* widget() const { return m_widget; } Function<void()> on_commit; - virtual GVariant value() const = 0; - virtual void set_value(const GVariant&) = 0; + virtual Variant value() const = 0; + virtual void set_value(const Variant&) = 0; virtual void will_begin_editing() {} protected: - virtual RefPtr<GWidget> create_widget() = 0; + virtual RefPtr<Widget> create_widget() = 0; void commit() { if (on_commit) @@ -63,24 +65,26 @@ protected: } private: - RefPtr<GModel> m_model; - GModelIndex m_index; - RefPtr<GWidget> m_widget; + RefPtr<Model> m_model; + ModelIndex m_index; + RefPtr<Widget> m_widget; }; -class GStringModelEditingDelegate : public GModelEditingDelegate { +class StringModelEditingDelegate : public ModelEditingDelegate { public: - GStringModelEditingDelegate() {} - virtual ~GStringModelEditingDelegate() override {} + StringModelEditingDelegate() {} + virtual ~StringModelEditingDelegate() override {} - virtual RefPtr<GWidget> create_widget() override + virtual RefPtr<Widget> create_widget() override { - auto textbox = GTextBox::construct(nullptr); + auto textbox = TextBox::construct(nullptr); textbox->on_return_pressed = [this] { commit(); }; return textbox; } - virtual GVariant value() const override { return static_cast<const GTextBox*>(widget())->text(); } - virtual void set_value(const GVariant& value) override { static_cast<GTextBox*>(widget())->set_text(value.to_string()); } + virtual Variant value() const override { return static_cast<const TextBox*>(widget())->text(); } + virtual void set_value(const Variant& value) override { static_cast<TextBox*>(widget())->set_text(value.to_string()); } }; + +} diff --git a/Libraries/LibGUI/GModelIndex.h b/Libraries/LibGUI/GModelIndex.h index 22c845fb56..2b2481fbc1 100644 --- a/Libraries/LibGUI/GModelIndex.h +++ b/Libraries/LibGUI/GModelIndex.h @@ -29,13 +29,15 @@ #include <AK/LogStream.h> #include <AK/String.h> -class GModel; +namespace GUI { -class GModelIndex { - friend class GModel; +class Model; + +class ModelIndex { + friend class Model; public: - GModelIndex() {} + ModelIndex() {} bool is_valid() const { return m_row != -1 && m_column != -1; } int row() const { return m_row; } @@ -43,20 +45,20 @@ public: void* internal_data() const { return m_internal_data; } - GModelIndex parent() const; + ModelIndex parent() const; - bool operator==(const GModelIndex& other) const + bool operator==(const ModelIndex& other) const { return m_model == other.m_model && m_row == other.m_row && m_column == other.m_column && m_internal_data == other.m_internal_data; } - bool operator!=(const GModelIndex& other) const + bool operator!=(const ModelIndex& other) const { return !(*this == other); } private: - GModelIndex(const GModel& model, int row, int column, void* internal_data) + ModelIndex(const Model& model, int row, int column, void* internal_data) : m_model(&model) , m_row(row) , m_column(column) @@ -64,22 +66,24 @@ private: { } - const GModel* m_model { nullptr }; + const Model* m_model { nullptr }; int m_row { -1 }; int m_column { -1 }; void* m_internal_data { nullptr }; }; -inline const LogStream& operator<<(const LogStream& stream, const GModelIndex& value) +inline const LogStream& operator<<(const LogStream& stream, const ModelIndex& value) { if (value.internal_data()) - return stream << String::format("GModelIndex(%d,%d,%p)", value.row(), value.column(), value.internal_data()); - return stream << String::format("GModelIndex(%d,%d)", value.row(), value.column()); + return stream << String::format("ModelIndex(%d,%d,%p)", value.row(), value.column(), value.internal_data()); + return stream << String::format("ModelIndex(%d,%d)", value.row(), value.column()); +} + } namespace AK { template<> -struct Traits<GModelIndex> : public GenericTraits<GModelIndex> { - static unsigned hash(const GModelIndex& index) { return pair_int_hash(index.row(), index.column()); } +struct Traits<GUI::ModelIndex> : public GenericTraits<GUI::ModelIndex> { + static unsigned hash(const GUI::ModelIndex& index) { return pair_int_hash(index.row(), index.column()); } }; } diff --git a/Libraries/LibGUI/GModelSelection.cpp b/Libraries/LibGUI/GModelSelection.cpp index 11cb04c8e5..2e191e8b90 100644 --- a/Libraries/LibGUI/GModelSelection.cpp +++ b/Libraries/LibGUI/GModelSelection.cpp @@ -27,7 +27,9 @@ #include <LibGUI/GAbstractView.h> #include <LibGUI/GModelSelection.h> -void GModelSelection::set(const GModelIndex& index) +namespace GUI { + +void ModelSelection::set(const ModelIndex& index) { ASSERT(index.is_valid()); if (m_indexes.size() == 1 && m_indexes.contains(index)) @@ -37,7 +39,7 @@ void GModelSelection::set(const GModelIndex& index) m_view.notify_selection_changed({}); } -void GModelSelection::add(const GModelIndex& index) +void ModelSelection::add(const ModelIndex& index) { ASSERT(index.is_valid()); if (m_indexes.contains(index)) @@ -46,7 +48,7 @@ void GModelSelection::add(const GModelIndex& index) m_view.notify_selection_changed({}); } -void GModelSelection::toggle(const GModelIndex& index) +void ModelSelection::toggle(const ModelIndex& index) { ASSERT(index.is_valid()); if (m_indexes.contains(index)) @@ -56,7 +58,7 @@ void GModelSelection::toggle(const GModelIndex& index) m_view.notify_selection_changed({}); } -bool GModelSelection::remove(const GModelIndex& index) +bool ModelSelection::remove(const ModelIndex& index) { ASSERT(index.is_valid()); if (!m_indexes.contains(index)) @@ -66,10 +68,12 @@ bool GModelSelection::remove(const GModelIndex& index) return true; } -void GModelSelection::clear() +void ModelSelection::clear() { if (m_indexes.is_empty()) return; m_indexes.clear(); m_view.notify_selection_changed({}); } + +} diff --git a/Libraries/LibGUI/GModelSelection.h b/Libraries/LibGUI/GModelSelection.h index 3e7a62706a..ec86d02e03 100644 --- a/Libraries/LibGUI/GModelSelection.h +++ b/Libraries/LibGUI/GModelSelection.h @@ -29,18 +29,20 @@ #include <AK/HashTable.h> #include <LibGUI/GModelIndex.h> -class GAbstractView; +namespace GUI { -class GModelSelection { +class AbstractView; + +class ModelSelection { public: - GModelSelection(GAbstractView& view) + ModelSelection(AbstractView& view) : m_view(view) { } int size() const { return m_indexes.size(); } bool is_empty() const { return m_indexes.is_empty(); } - bool contains(const GModelIndex& index) const { return m_indexes.contains(index); } + bool contains(const ModelIndex& index) const { return m_indexes.contains(index); } bool contains_row(int row) const { for (auto& index : m_indexes) { @@ -50,10 +52,10 @@ public: return false; } - void set(const GModelIndex&); - void add(const GModelIndex&); - void toggle(const GModelIndex&); - bool remove(const GModelIndex&); + void set(const ModelIndex&); + void add(const ModelIndex&); + void toggle(const ModelIndex&); + bool remove(const ModelIndex&); void clear(); template<typename Callback> @@ -70,9 +72,9 @@ public: callback(index); } - Vector<GModelIndex> indexes() const + Vector<ModelIndex> indexes() const { - Vector<GModelIndex> selected_indexes; + Vector<ModelIndex> selected_indexes; for (auto& index : m_indexes) selected_indexes.append(index); @@ -81,7 +83,7 @@ public: } // FIXME: This doesn't guarantee that what you get is the lowest or "first" index selected.. - GModelIndex first() const + ModelIndex first() const { if (m_indexes.is_empty()) return {}; @@ -89,6 +91,8 @@ public: } private: - GAbstractView& m_view; - HashTable<GModelIndex> m_indexes; + AbstractView& m_view; + HashTable<ModelIndex> m_indexes; }; + +} diff --git a/Libraries/LibGUI/GPainter.cpp b/Libraries/LibGUI/GPainter.cpp index 86905c68e8..dbb950344e 100644 --- a/Libraries/LibGUI/GPainter.cpp +++ b/Libraries/LibGUI/GPainter.cpp @@ -28,12 +28,13 @@ #include <LibGUI/GWidget.h> #include <LibGUI/GWindow.h> -GPainter::GPainter(GraphicsBitmap& bitmap) - : Painter(bitmap) +namespace GUI { +Painter::Painter(GraphicsBitmap& bitmap) + : ::Painter(bitmap) { } -GPainter::GPainter(GWidget& widget) +Painter::Painter(Widget& widget) : Painter(*widget.window()->back_bitmap()) { state().font = &widget.font(); @@ -43,3 +44,5 @@ GPainter::GPainter(GWidget& widget) m_clip_origin = origin_rect; state().clip_rect.intersect(m_target->rect()); } + +} diff --git a/Libraries/LibGUI/GPainter.h b/Libraries/LibGUI/GPainter.h index b5c3ce2620..d8e39617f9 100644 --- a/Libraries/LibGUI/GPainter.h +++ b/Libraries/LibGUI/GPainter.h @@ -28,11 +28,14 @@ #include <LibDraw/Painter.h> -class GWidget; -class GraphicsBitmap; +namespace GUI { -class GPainter : public Painter { +class Widget; + +class Painter : public ::Painter { public: - explicit GPainter(GWidget&); - explicit GPainter(GraphicsBitmap&); + explicit Painter(Widget&); + explicit Painter(GraphicsBitmap&); }; + +} diff --git a/Libraries/LibGUI/GProgressBar.cpp b/Libraries/LibGUI/GProgressBar.cpp index e0c1076c31..d68d4b4203 100644 --- a/Libraries/LibGUI/GProgressBar.cpp +++ b/Libraries/LibGUI/GProgressBar.cpp @@ -28,19 +28,21 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GProgressBar.h> -GProgressBar::GProgressBar(GWidget* parent) - : GFrame(parent) +namespace GUI { + +ProgressBar::ProgressBar(Widget* parent) + : Frame(parent) { set_frame_shape(FrameShape::Container); set_frame_shadow(FrameShadow::Sunken); set_frame_thickness(2); } -GProgressBar::~GProgressBar() +ProgressBar::~ProgressBar() { } -void GProgressBar::set_value(int value) +void ProgressBar::set_value(int value) { if (m_value == value) return; @@ -48,7 +50,7 @@ void GProgressBar::set_value(int value) update(); } -void GProgressBar::set_range(int min, int max) +void ProgressBar::set_range(int min, int max) { ASSERT(min < max); m_min = min; @@ -56,11 +58,11 @@ void GProgressBar::set_range(int min, int max) m_value = clamp(m_value, m_min, m_max); } -void GProgressBar::paint_event(GPaintEvent& event) +void ProgressBar::paint_event(PaintEvent& event) { - GFrame::paint_event(event); + Frame::paint_event(event); - GPainter painter(*this); + Painter painter(*this); auto rect = frame_inner_rect(); painter.add_clip_rect(rect); painter.add_clip_rect(event.rect()); @@ -83,3 +85,5 @@ void GProgressBar::paint_event(GPaintEvent& event) StylePainter::paint_progress_bar(painter, rect, palette(), m_min, m_max, m_value, progress_text); } + +} diff --git a/Libraries/LibGUI/GProgressBar.h b/Libraries/LibGUI/GProgressBar.h index 862b85c198..e75cf160f9 100644 --- a/Libraries/LibGUI/GProgressBar.h +++ b/Libraries/LibGUI/GProgressBar.h @@ -28,10 +28,12 @@ #include <LibGUI/GFrame.h> -class GProgressBar : public GFrame { - C_OBJECT(GProgressBar) +namespace GUI { + +class ProgressBar : public Frame { + C_OBJECT(ProgressBar) public: - virtual ~GProgressBar() override; + virtual ~ProgressBar() override; void set_range(int min, int max); void set_min(int min) { set_range(min, max()); } @@ -54,9 +56,9 @@ public: void set_format(Format format) { m_format = format; } protected: - explicit GProgressBar(GWidget* parent); + explicit ProgressBar(Widget* parent); - virtual void paint_event(GPaintEvent&) override; + virtual void paint_event(PaintEvent&) override; private: Format m_format { Percentage }; @@ -65,3 +67,5 @@ private: int m_value { 0 }; String m_caption; }; + +} diff --git a/Libraries/LibGUI/GRadioButton.cpp b/Libraries/LibGUI/GRadioButton.cpp index 59e8b53a92..f89b165587 100644 --- a/Libraries/LibGUI/GRadioButton.cpp +++ b/Libraries/LibGUI/GRadioButton.cpp @@ -29,28 +29,30 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GRadioButton.h> -GRadioButton::GRadioButton(GWidget* parent) - : GRadioButton({}, parent) +namespace GUI { + +RadioButton::RadioButton(Widget* parent) + : RadioButton({}, parent) { } -GRadioButton::GRadioButton(const StringView& text, GWidget* parent) - : GAbstractButton(text, parent) +RadioButton::RadioButton(const StringView& text, Widget* parent) + : AbstractButton(text, parent) { } -GRadioButton::~GRadioButton() +RadioButton::~RadioButton() { } -Size GRadioButton::circle_size() +Size RadioButton::circle_size() { return { 12, 12 }; } -void GRadioButton::paint_event(GPaintEvent& event) +void RadioButton::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); Rect circle_rect { { 2, 0 }, circle_size() }; @@ -64,16 +66,16 @@ void GRadioButton::paint_event(GPaintEvent& event) } template<typename Callback> -void GRadioButton::for_each_in_group(Callback callback) +void RadioButton::for_each_in_group(Callback callback) { if (!parent()) return; - parent()->for_each_child_of_type<GRadioButton>([&](auto& child) { - return callback(static_cast<GRadioButton&>(child)); + parent()->for_each_child_of_type<RadioButton>([&](auto& child) { + return callback(static_cast<RadioButton&>(child)); }); } -void GRadioButton::click() +void RadioButton::click() { if (!is_enabled()) return; @@ -84,3 +86,5 @@ void GRadioButton::click() }); set_checked(true); } + +} diff --git a/Libraries/LibGUI/GRadioButton.h b/Libraries/LibGUI/GRadioButton.h index 4c905ca893..101d10028e 100644 --- a/Libraries/LibGUI/GRadioButton.h +++ b/Libraries/LibGUI/GRadioButton.h @@ -28,22 +28,24 @@ #include <LibGUI/GAbstractButton.h> -class GRadioButton : public GAbstractButton { - C_OBJECT(GRadioButton) +namespace GUI { + +class RadioButton : public AbstractButton { + C_OBJECT(RadioButton) public: - virtual ~GRadioButton() override; + virtual ~RadioButton() override; virtual void click() override; protected: - explicit GRadioButton(GWidget* parent); - explicit GRadioButton(const StringView& text, GWidget* parent); - virtual void paint_event(GPaintEvent&) override; + explicit RadioButton(Widget* parent); + explicit RadioButton(const StringView& text, Widget* parent); + virtual void paint_event(PaintEvent&) override; private: // These don't make sense for a radio button, so hide them. - using GAbstractButton::auto_repeat_interval; - using GAbstractButton::set_auto_repeat_interval; + using AbstractButton::auto_repeat_interval; + using AbstractButton::set_auto_repeat_interval; virtual bool is_radio_button() const final { return true; } @@ -52,10 +54,12 @@ private: static Size circle_size(); }; +} + template<> -inline bool Core::is<GRadioButton>(const Core::Object& object) +inline bool Core::is<GUI::RadioButton>(const Core::Object& object) { - if (!is<GWidget>(object)) + if (!is<GUI::Widget>(object)) return false; - return to<GWidget>(object).is_radio_button(); + return to<GUI::Widget>(object).is_radio_button(); } diff --git a/Libraries/LibGUI/GResizeCorner.cpp b/Libraries/LibGUI/GResizeCorner.cpp index ce84aa2bef..4c1dbc9ef3 100644 --- a/Libraries/LibGUI/GResizeCorner.cpp +++ b/Libraries/LibGUI/GResizeCorner.cpp @@ -30,8 +30,10 @@ #include <LibGUI/GResizeCorner.h> #include <LibGUI/GWindow.h> -GResizeCorner::GResizeCorner(GWidget* parent) - : GWidget(parent) +namespace GUI { + +ResizeCorner::ResizeCorner(Widget* parent) + : Widget(parent) { set_background_role(ColorRole::Button); set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); @@ -40,34 +42,36 @@ GResizeCorner::GResizeCorner(GWidget* parent) ASSERT(m_bitmap); } -GResizeCorner::~GResizeCorner() +ResizeCorner::~ResizeCorner() { } -void GResizeCorner::paint_event(GPaintEvent& event) +void ResizeCorner::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); painter.fill_rect(rect(), palette().color(background_role())); painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect()); - GWidget::paint_event(event); + Widget::paint_event(event); } -void GResizeCorner::mousedown_event(GMouseEvent& event) +void ResizeCorner::mousedown_event(MouseEvent& event) { - if (event.button() == GMouseButton::Left) + if (event.button() == MouseButton::Left) window()->start_wm_resize(); - GWidget::mousedown_event(event); + Widget::mousedown_event(event); } -void GResizeCorner::enter_event(Core::Event& event) +void ResizeCorner::enter_event(Core::Event& event) { - window()->set_override_cursor(GStandardCursor::ResizeDiagonalTLBR); - GWidget::enter_event(event); + window()->set_override_cursor(StandardCursor::ResizeDiagonalTLBR); + Widget::enter_event(event); } -void GResizeCorner::leave_event(Core::Event& event) +void ResizeCorner::leave_event(Core::Event& event) { - window()->set_override_cursor(GStandardCursor::None); - GWidget::leave_event(event); + window()->set_override_cursor(StandardCursor::None); + Widget::leave_event(event); +} + } diff --git a/Libraries/LibGUI/GResizeCorner.h b/Libraries/LibGUI/GResizeCorner.h index 7f27928d93..e9ade6e459 100644 --- a/Libraries/LibGUI/GResizeCorner.h +++ b/Libraries/LibGUI/GResizeCorner.h @@ -26,19 +26,23 @@ #include <LibGUI/GWidget.h> -class GResizeCorner : public GWidget { - C_OBJECT(GResizeCorner) +namespace GUI { + +class ResizeCorner : public Widget { + C_OBJECT(ResizeCorner) public: - virtual ~GResizeCorner() override; + virtual ~ResizeCorner() override; protected: - explicit GResizeCorner(GWidget* parent); + explicit ResizeCorner(Widget* parent); - virtual void paint_event(GPaintEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; + virtual void paint_event(PaintEvent&) override; + virtual void mousedown_event(MouseEvent&) override; virtual void enter_event(Core::Event&) override; virtual void leave_event(Core::Event&) override; private: RefPtr<GraphicsBitmap> m_bitmap; }; + +} diff --git a/Libraries/LibGUI/GScrollBar.cpp b/Libraries/LibGUI/GScrollBar.cpp index 5b70bb9bc7..c0df762642 100644 --- a/Libraries/LibGUI/GScrollBar.cpp +++ b/Libraries/LibGUI/GScrollBar.cpp @@ -31,6 +31,8 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GScrollBar.h> +namespace GUI { + static const char* s_up_arrow_bitmap_data = { " " " # " @@ -84,13 +86,13 @@ static CharacterBitmap* s_down_arrow_bitmap; static CharacterBitmap* s_left_arrow_bitmap; static CharacterBitmap* s_right_arrow_bitmap; -GScrollBar::GScrollBar(GWidget* parent) - : GScrollBar(Orientation::Vertical, parent) +ScrollBar::ScrollBar(Widget* parent) + : ScrollBar(Orientation::Vertical, parent) { } -GScrollBar::GScrollBar(Orientation orientation, GWidget* parent) - : GWidget(parent) +ScrollBar::ScrollBar(Orientation orientation, Widget* parent) + : Widget(parent) , m_orientation(orientation) { m_automatic_scrolling_timer = Core::Timer::construct(this); @@ -115,11 +117,11 @@ GScrollBar::GScrollBar(Orientation orientation, GWidget* parent) }; } -GScrollBar::~GScrollBar() +ScrollBar::~ScrollBar() { } -void GScrollBar::set_range(int min, int max) +void ScrollBar::set_range(int min, int max) { ASSERT(min <= max); if (m_min == min && m_max == max) @@ -136,7 +138,7 @@ void GScrollBar::set_range(int min, int max) update(); } -void GScrollBar::set_value(int value) +void ScrollBar::set_value(int value) { value = clamp(value, m_min, m_max); if (value == m_value) @@ -147,12 +149,12 @@ void GScrollBar::set_value(int value) update(); } -Rect GScrollBar::decrement_button_rect() const +Rect ScrollBar::decrement_button_rect() const { return { 0, 0, button_width(), button_height() }; } -Rect GScrollBar::increment_button_rect() const +Rect ScrollBar::increment_button_rect() const { if (orientation() == Orientation::Vertical) return { 0, height() - button_height(), button_width(), button_height() }; @@ -160,7 +162,7 @@ Rect GScrollBar::increment_button_rect() const return { width() - button_width(), 0, button_width(), button_height() }; } -Rect GScrollBar::decrement_gutter_rect() const +Rect ScrollBar::decrement_gutter_rect() const { if (orientation() == Orientation::Vertical) return { 0, button_height(), button_width(), scrubber_rect().top() - button_height() }; @@ -168,7 +170,7 @@ Rect GScrollBar::decrement_gutter_rect() const return { button_width(), 0, scrubber_rect().x() - button_width(), button_height() }; } -Rect GScrollBar::increment_gutter_rect() const +Rect ScrollBar::increment_gutter_rect() const { auto scrubber_rect = this->scrubber_rect(); if (orientation() == Orientation::Vertical) @@ -177,7 +179,7 @@ Rect GScrollBar::increment_gutter_rect() const return { scrubber_rect.right() + 1, 0, width() - button_width() - scrubber_rect.right() - 1, button_width() }; } -int GScrollBar::scrubbable_range_in_pixels() const +int ScrollBar::scrubbable_range_in_pixels() const { if (orientation() == Orientation::Vertical) return height() - button_height() * 2 - scrubber_size(); @@ -185,19 +187,19 @@ int GScrollBar::scrubbable_range_in_pixels() const return width() - button_width() * 2 - scrubber_size(); } -bool GScrollBar::has_scrubber() const +bool ScrollBar::has_scrubber() const { return m_max != m_min; } -int GScrollBar::scrubber_size() const +int ScrollBar::scrubber_size() const { int pixel_range = length(orientation()) - button_size() * 2; int value_range = m_max - m_min; return ::max(pixel_range - value_range, button_size()); } -Rect GScrollBar::scrubber_rect() const +Rect ScrollBar::scrubber_rect() const { if (!has_scrubber() || length(orientation()) <= (button_size() * 2) + scrubber_size()) return {}; @@ -219,9 +221,9 @@ Rect GScrollBar::scrubber_rect() const return { (int)x_or_y, 0, scrubber_size(), button_height() }; } -void GScrollBar::paint_event(GPaintEvent& event) +void ScrollBar::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); painter.fill_rect(rect(), palette().button().lightened()); @@ -238,7 +240,7 @@ void GScrollBar::paint_event(GPaintEvent& event) StylePainter::paint_button(painter, scrubber_rect(), palette(), ButtonStyle::Normal, false, m_hovered_component == Component::Scrubber || m_scrubber_in_use); } -void GScrollBar::on_automatic_scrolling_timer_fired() +void ScrollBar::on_automatic_scrolling_timer_fired() { if (m_automatic_scrolling_direction == AutomaticScrollingDirection::Decrement) { set_value(value() - m_step); @@ -250,9 +252,9 @@ void GScrollBar::on_automatic_scrolling_timer_fired() } } -void GScrollBar::mousedown_event(GMouseEvent& event) +void ScrollBar::mousedown_event(MouseEvent& event) { - if (event.button() != GMouseButton::Left) + if (event.button() != MouseButton::Left) return; if (decrement_button_rect().contains(event.position())) { m_automatic_scrolling_direction = AutomaticScrollingDirection::Decrement; @@ -294,9 +296,9 @@ void GScrollBar::mousedown_event(GMouseEvent& event) } } -void GScrollBar::mouseup_event(GMouseEvent& event) +void ScrollBar::mouseup_event(MouseEvent& event) { - if (event.button() != GMouseButton::Left) + if (event.button() != MouseButton::Left) return; m_scrubber_in_use = false; m_automatic_scrolling_direction = AutomaticScrollingDirection::None; @@ -307,15 +309,15 @@ void GScrollBar::mouseup_event(GMouseEvent& event) update(); } -void GScrollBar::mousewheel_event(GMouseEvent& event) +void ScrollBar::mousewheel_event(MouseEvent& event) { if (!is_scrollable()) return; set_value(value() + event.wheel_delta() * m_step); - GWidget::mousewheel_event(event); + Widget::mousewheel_event(event); } -void GScrollBar::set_automatic_scrolling_active(bool active) +void ScrollBar::set_automatic_scrolling_active(bool active) { if (active) { on_automatic_scrolling_timer_fired(); @@ -325,7 +327,7 @@ void GScrollBar::set_automatic_scrolling_active(bool active) } } -void GScrollBar::mousemove_event(GMouseEvent& event) +void ScrollBar::mousemove_event(MouseEvent& event) { auto old_hovered_component = m_hovered_component; if (scrubber_rect().contains(event.position())) @@ -355,7 +357,7 @@ void GScrollBar::mousemove_event(GMouseEvent& event) set_value(new_value); } -void GScrollBar::leave_event(Core::Event&) +void ScrollBar::leave_event(Core::Event&) { if (m_hovered_component != Component::Invalid) { m_hovered_component = Component::Invalid; @@ -363,11 +365,13 @@ void GScrollBar::leave_event(Core::Event&) } } -void GScrollBar::change_event(GEvent& event) +void ScrollBar::change_event(Event& event) { - if (event.type() == GEvent::Type::EnabledChange) { + if (event.type() == Event::Type::EnabledChange) { if (!is_enabled()) m_scrubbing = false; } - return GWidget::change_event(event); + return Widget::change_event(event); +} + } diff --git a/Libraries/LibGUI/GScrollBar.h b/Libraries/LibGUI/GScrollBar.h index dcb5dc84ae..0e28f5701a 100644 --- a/Libraries/LibGUI/GScrollBar.h +++ b/Libraries/LibGUI/GScrollBar.h @@ -30,10 +30,12 @@ #include <LibCore/CTimer.h> #include <LibGUI/GWidget.h> -class GScrollBar final : public GWidget { - C_OBJECT(GScrollBar) +namespace GUI { + +class ScrollBar final : public Widget { + C_OBJECT(ScrollBar) public: - virtual ~GScrollBar() override; + virtual ~ScrollBar() override; Orientation orientation() const { return m_orientation; } @@ -64,16 +66,16 @@ public: }; private: - explicit GScrollBar(GWidget* parent); - explicit GScrollBar(Orientation, GWidget* parent); - - virtual void paint_event(GPaintEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mousewheel_event(GMouseEvent&) override; + explicit ScrollBar(Widget* parent); + explicit ScrollBar(Orientation, Widget* parent); + + virtual void paint_event(PaintEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void mousewheel_event(MouseEvent&) override; virtual void leave_event(Core::Event&) override; - virtual void change_event(GEvent&) override; + virtual void change_event(Event&) override; int default_button_size() const { return 16; } int button_size() const { return length(orientation()) <= (default_button_size() * 2) ? length(orientation()) / 2 : default_button_size(); } @@ -112,3 +114,5 @@ private: AutomaticScrollingDirection m_automatic_scrolling_direction { AutomaticScrollingDirection::None }; RefPtr<Core::Timer> m_automatic_scrolling_timer; }; + +} diff --git a/Libraries/LibGUI/GScrollableWidget.cpp b/Libraries/LibGUI/GScrollableWidget.cpp index 758d876356..a81267b6b5 100644 --- a/Libraries/LibGUI/GScrollableWidget.cpp +++ b/Libraries/LibGUI/GScrollableWidget.cpp @@ -27,17 +27,19 @@ #include <LibGUI/GScrollBar.h> #include <LibGUI/GScrollableWidget.h> -GScrollableWidget::GScrollableWidget(GWidget* parent) - : GFrame(parent) +namespace GUI { + +ScrollableWidget::ScrollableWidget(Widget* parent) + : Frame(parent) { - m_vertical_scrollbar = GScrollBar::construct(Orientation::Vertical, this); + m_vertical_scrollbar = ScrollBar::construct(Orientation::Vertical, this); m_vertical_scrollbar->set_step(4); m_vertical_scrollbar->on_change = [this](int) { did_scroll(); update(); }; - m_horizontal_scrollbar = GScrollBar::construct(Orientation::Horizontal, this); + m_horizontal_scrollbar = ScrollBar::construct(Orientation::Horizontal, this); m_horizontal_scrollbar->set_step(4); m_horizontal_scrollbar->set_big_step(30); m_horizontal_scrollbar->on_change = [this](int) { @@ -45,21 +47,21 @@ GScrollableWidget::GScrollableWidget(GWidget* parent) update(); }; - m_corner_widget = GWidget::construct(this); + m_corner_widget = Widget::construct(this); m_corner_widget->set_fill_with_background_color(true); } -GScrollableWidget::~GScrollableWidget() +ScrollableWidget::~ScrollableWidget() { } -void GScrollableWidget::mousewheel_event(GMouseEvent& event) +void ScrollableWidget::mousewheel_event(MouseEvent& event) { // FIXME: The wheel delta multiplier should probably come from... somewhere? vertical_scrollbar().set_value(vertical_scrollbar().value() + event.wheel_delta() * 20); } -void GScrollableWidget::custom_layout() +void ScrollableWidget::custom_layout() { auto inner_rect = frame_inner_rect_for_size(size()); int height_wanted_by_horizontal_scrollbar = m_horizontal_scrollbar->is_visible() ? m_horizontal_scrollbar->preferred_size().height() : 0; @@ -84,20 +86,20 @@ void GScrollableWidget::custom_layout() } } -void GScrollableWidget::resize_event(GResizeEvent& event) +void ScrollableWidget::resize_event(ResizeEvent& event) { - GFrame::resize_event(event); + Frame::resize_event(event); update_scrollbar_ranges(); } -Size GScrollableWidget::available_size() const +Size ScrollableWidget::available_size() const { int available_width = frame_inner_rect().width() - m_size_occupied_by_fixed_elements.width() - width_occupied_by_vertical_scrollbar(); int available_height = frame_inner_rect().height() - m_size_occupied_by_fixed_elements.height() - height_occupied_by_horizontal_scrollbar(); return { available_width, available_height }; } -void GScrollableWidget::update_scrollbar_ranges() +void ScrollableWidget::update_scrollbar_ranges() { auto available_size = this->available_size(); @@ -116,7 +118,7 @@ void GScrollableWidget::update_scrollbar_ranges() m_vertical_scrollbar->set_big_step(visible_content_rect().height() - m_vertical_scrollbar->step()); } -void GScrollableWidget::set_content_size(const Size& size) +void ScrollableWidget::set_content_size(const Size& size) { if (m_content_size == size) return; @@ -124,7 +126,7 @@ void GScrollableWidget::set_content_size(const Size& size) update_scrollbar_ranges(); } -void GScrollableWidget::set_size_occupied_by_fixed_elements(const Size& size) +void ScrollableWidget::set_size_occupied_by_fixed_elements(const Size& size) { if (m_size_occupied_by_fixed_elements == size) return; @@ -132,17 +134,17 @@ void GScrollableWidget::set_size_occupied_by_fixed_elements(const Size& size) update_scrollbar_ranges(); } -int GScrollableWidget::height_occupied_by_horizontal_scrollbar() const +int ScrollableWidget::height_occupied_by_horizontal_scrollbar() const { return m_horizontal_scrollbar->is_visible() ? m_horizontal_scrollbar->height() : 0; } -int GScrollableWidget::width_occupied_by_vertical_scrollbar() const +int ScrollableWidget::width_occupied_by_vertical_scrollbar() const { return m_vertical_scrollbar->is_visible() ? m_vertical_scrollbar->width() : 0; } -Rect GScrollableWidget::visible_content_rect() const +Rect ScrollableWidget::visible_content_rect() const { return { m_horizontal_scrollbar->value(), @@ -152,14 +154,14 @@ Rect GScrollableWidget::visible_content_rect() const }; } -void GScrollableWidget::scroll_into_view(const Rect& rect, Orientation orientation) +void ScrollableWidget::scroll_into_view(const Rect& rect, Orientation orientation) { if (orientation == Orientation::Vertical) return scroll_into_view(rect, false, true); return scroll_into_view(rect, true, false); } -void GScrollableWidget::scroll_into_view(const Rect& rect, bool scroll_horizontally, bool scroll_vertically) +void ScrollableWidget::scroll_into_view(const Rect& rect, bool scroll_horizontally, bool scroll_vertically) { auto visible_content_rect = this->visible_content_rect(); if (visible_content_rect.contains(rect)) @@ -179,7 +181,7 @@ void GScrollableWidget::scroll_into_view(const Rect& rect, bool scroll_horizonta } } -void GScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled) +void ScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled) { if (m_scrollbars_enabled == scrollbars_enabled) return; @@ -189,17 +191,17 @@ void GScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled) m_corner_widget->set_visible(m_scrollbars_enabled); } -void GScrollableWidget::scroll_to_top() +void ScrollableWidget::scroll_to_top() { scroll_into_view({ 0, 0, 1, 1 }, Orientation::Vertical); } -void GScrollableWidget::scroll_to_bottom() +void ScrollableWidget::scroll_to_bottom() { scroll_into_view({ 0, content_height(), 1, 1 }, Orientation::Vertical); } -Rect GScrollableWidget::widget_inner_rect() const +Rect ScrollableWidget::widget_inner_rect() const { auto rect = frame_inner_rect(); rect.set_width(rect.width() - width_occupied_by_vertical_scrollbar()); @@ -207,7 +209,7 @@ Rect GScrollableWidget::widget_inner_rect() const return rect; } -Point GScrollableWidget::to_content_position(const Point& widget_position) const +Point ScrollableWidget::to_content_position(const Point& widget_position) const { auto content_position = widget_position; content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); @@ -215,10 +217,12 @@ Point GScrollableWidget::to_content_position(const Point& widget_position) const return content_position; } -Point GScrollableWidget::to_widget_position(const Point& content_position) const +Point ScrollableWidget::to_widget_position(const Point& content_position) const { auto widget_position = content_position; widget_position.move_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value()); widget_position.move_by(frame_thickness(), frame_thickness()); return widget_position; } + +} diff --git a/Libraries/LibGUI/GScrollableWidget.h b/Libraries/LibGUI/GScrollableWidget.h index e20b94fab9..7a56722d34 100644 --- a/Libraries/LibGUI/GScrollableWidget.h +++ b/Libraries/LibGUI/GScrollableWidget.h @@ -28,12 +28,14 @@ #include <LibGUI/GFrame.h> -class GScrollBar; +namespace GUI { -class GScrollableWidget : public GFrame { - C_OBJECT(GScrollableWidget) +class ScrollBar; + +class ScrollableWidget : public Frame { + C_OBJECT(ScrollableWidget) public: - virtual ~GScrollableWidget() override; + virtual ~ScrollableWidget() override; Size content_size() const { return m_content_size; } int content_width() const { return m_content_size.width(); } @@ -51,12 +53,12 @@ public: Size available_size() const; - GScrollBar& vertical_scrollbar() { return *m_vertical_scrollbar; } - const GScrollBar& vertical_scrollbar() const { return *m_vertical_scrollbar; } - GScrollBar& horizontal_scrollbar() { return *m_horizontal_scrollbar; } - const GScrollBar& horizontal_scrollbar() const { return *m_horizontal_scrollbar; } - GWidget& corner_widget() { return *m_corner_widget; } - const GWidget& corner_widget() const { return *m_corner_widget; } + ScrollBar& vertical_scrollbar() { return *m_vertical_scrollbar; } + const ScrollBar& vertical_scrollbar() const { return *m_vertical_scrollbar; } + ScrollBar& horizontal_scrollbar() { return *m_horizontal_scrollbar; } + const ScrollBar& horizontal_scrollbar() const { return *m_horizontal_scrollbar; } + Widget& corner_widget() { return *m_corner_widget; } + const Widget& corner_widget() const { return *m_corner_widget; } void scroll_to_top(); void scroll_to_bottom(); @@ -71,10 +73,10 @@ public: Point to_widget_position(const Point& content_position) const; protected: - explicit GScrollableWidget(GWidget* parent); + explicit ScrollableWidget(Widget* parent); virtual void custom_layout() override; - virtual void resize_event(GResizeEvent&) override; - virtual void mousewheel_event(GMouseEvent&) override; + virtual void resize_event(ResizeEvent&) override; + virtual void mousewheel_event(MouseEvent&) override; virtual void did_scroll() {} void set_content_size(const Size&); void set_size_occupied_by_fixed_elements(const Size&); @@ -82,11 +84,13 @@ protected: private: void update_scrollbar_ranges(); - RefPtr<GScrollBar> m_vertical_scrollbar; - RefPtr<GScrollBar> m_horizontal_scrollbar; - RefPtr<GWidget> m_corner_widget; + RefPtr<ScrollBar> m_vertical_scrollbar; + RefPtr<ScrollBar> m_horizontal_scrollbar; + RefPtr<Widget> m_corner_widget; Size m_content_size; Size m_size_occupied_by_fixed_elements; bool m_scrollbars_enabled { true }; bool m_should_hide_unnecessary_scrollbars { false }; }; + +} diff --git a/Libraries/LibGUI/GShortcut.cpp b/Libraries/LibGUI/GShortcut.cpp index 34b612b8e8..982a1eadd6 100644 --- a/Libraries/LibGUI/GShortcut.cpp +++ b/Libraries/LibGUI/GShortcut.cpp @@ -27,7 +27,9 @@ #include <AK/StringBuilder.h> #include <LibGUI/GShortcut.h> -static String to_string(KeyCode key) +namespace GUI { + +static String key_code_to_string(KeyCode key) { switch (key) { case Key_Escape: @@ -244,7 +246,7 @@ static String to_string(KeyCode key) } } -String GShortcut::to_string() const +String Shortcut::to_string() const { Vector<String, 8> parts; @@ -257,7 +259,7 @@ String GShortcut::to_string() const if (m_modifiers & Mod_Logo) parts.append("Logo"); - parts.append(::to_string(m_key)); + parts.append(key_code_to_string(m_key)); StringBuilder builder; for (int i = 0; i < parts.size(); ++i) { @@ -267,3 +269,5 @@ String GShortcut::to_string() const } return builder.to_string(); } + +} diff --git a/Libraries/LibGUI/GShortcut.h b/Libraries/LibGUI/GShortcut.h index abaaa488c6..6497451fd0 100644 --- a/Libraries/LibGUI/GShortcut.h +++ b/Libraries/LibGUI/GShortcut.h @@ -30,10 +30,12 @@ #include <AK/Traits.h> #include <Kernel/KeyCode.h> -class GShortcut { +namespace GUI { + +class Shortcut { public: - GShortcut() {} - GShortcut(u8 modifiers, KeyCode key) + Shortcut() {} + Shortcut(u8 modifiers, KeyCode key) : m_modifiers(modifiers) , m_key(key) { @@ -44,7 +46,7 @@ public: KeyCode key() const { return m_key; } String to_string() const; - bool operator==(const GShortcut& other) const + bool operator==(const Shortcut& other) const { return m_modifiers == other.m_modifiers && m_key == other.m_key; @@ -55,11 +57,13 @@ private: KeyCode m_key { KeyCode::Key_Invalid }; }; +} + namespace AK { template<> -struct Traits<GShortcut> : public GenericTraits<GShortcut> { - static unsigned hash(const GShortcut& shortcut) +struct Traits<GUI::Shortcut> : public GenericTraits<GUI::Shortcut> { + static unsigned hash(const GUI::Shortcut& shortcut) { return pair_int_hash(shortcut.modifiers(), shortcut.key()); } diff --git a/Libraries/LibGUI/GSlider.cpp b/Libraries/LibGUI/GSlider.cpp index 610cb151a4..3eb96ce54c 100644 --- a/Libraries/LibGUI/GSlider.cpp +++ b/Libraries/LibGUI/GSlider.cpp @@ -28,22 +28,24 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GSlider.h> -GSlider::GSlider(GWidget* parent) - : GSlider(Orientation::Horizontal, parent) +namespace GUI { + +Slider::Slider(Widget* parent) + : Slider(Orientation::Horizontal, parent) { } -GSlider::GSlider(Orientation orientation, GWidget* parent) - : GWidget(parent) +Slider::Slider(Orientation orientation, Widget* parent) + : Widget(parent) , m_orientation(orientation) { } -GSlider::~GSlider() +Slider::~Slider() { } -void GSlider::set_range(int min, int max) +void Slider::set_range(int min, int max) { ASSERT(min <= max); if (m_min == min && m_max == max) @@ -54,7 +56,7 @@ void GSlider::set_range(int min, int max) update(); } -void GSlider::set_value(int value) +void Slider::set_value(int value) { value = clamp(value, m_min, m_max); if (m_value == value) @@ -66,9 +68,9 @@ void GSlider::set_value(int value) on_value_changed(m_value); } -void GSlider::paint_event(GPaintEvent& event) +void Slider::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); Rect track_rect; @@ -85,7 +87,7 @@ void GSlider::paint_event(GPaintEvent& event) StylePainter::paint_button(painter, knob_rect(), palette(), ButtonStyle::Normal, false, m_knob_hovered); } -Rect GSlider::knob_rect() const +Rect Slider::knob_rect() const { auto inner_rect = this->inner_rect(); Rect rect; @@ -114,11 +116,11 @@ Rect GSlider::knob_rect() const return rect; } -void GSlider::mousedown_event(GMouseEvent& event) +void Slider::mousedown_event(MouseEvent& event) { if (!is_enabled()) return; - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { if (knob_rect().contains(event.position())) { m_dragging = true; m_drag_origin = event.position(); @@ -131,10 +133,10 @@ void GSlider::mousedown_event(GMouseEvent& event) set_value(m_value - 1); } } - return GWidget::mousedown_event(event); + return Widget::mousedown_event(event); } -void GSlider::mousemove_event(GMouseEvent& event) +void Slider::mousemove_event(MouseEvent& event) { if (!is_enabled()) return; @@ -147,42 +149,44 @@ void GSlider::mousemove_event(GMouseEvent& event) set_value((int)new_value); return; } - return GWidget::mousemove_event(event); + return Widget::mousemove_event(event); } -void GSlider::mouseup_event(GMouseEvent& event) +void Slider::mouseup_event(MouseEvent& event) { if (!is_enabled()) return; - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { m_dragging = false; return; } - return GWidget::mouseup_event(event); + return Widget::mouseup_event(event); } -void GSlider::leave_event(Core::Event& event) +void Slider::leave_event(Core::Event& event) { if (!is_enabled()) return; set_knob_hovered(false); - GWidget::leave_event(event); + Widget::leave_event(event); } -void GSlider::change_event(GEvent& event) +void Slider::change_event(Event& event) { - if (event.type() == GEvent::Type::EnabledChange) { + if (event.type() == Event::Type::EnabledChange) { if (!is_enabled()) m_dragging = false; } - GWidget::change_event(event); + Widget::change_event(event); } -void GSlider::set_knob_hovered(bool hovered) +void Slider::set_knob_hovered(bool hovered) { if (m_knob_hovered == hovered) return; m_knob_hovered = hovered; update(knob_rect()); } + +} diff --git a/Libraries/LibGUI/GSlider.h b/Libraries/LibGUI/GSlider.h index 1ad1034c5a..88b021bb57 100644 --- a/Libraries/LibGUI/GSlider.h +++ b/Libraries/LibGUI/GSlider.h @@ -28,15 +28,17 @@ #include <LibGUI/GWidget.h> -class GSlider : public GWidget { - C_OBJECT(GSlider) +namespace GUI { + +class Slider : public Widget { + C_OBJECT(Slider) public: enum class KnobSizeMode { Fixed, Proportional, }; - virtual ~GSlider() override; + virtual ~Slider() override; Orientation orientation() const { return m_orientation; } @@ -70,15 +72,15 @@ public: Function<void(int)> on_value_changed; protected: - explicit GSlider(GWidget*); - explicit GSlider(Orientation, GWidget*); + explicit Slider(Widget*); + explicit Slider(Orientation, Widget*); - virtual void paint_event(GPaintEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; + virtual void paint_event(PaintEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; virtual void leave_event(Core::Event&) override; - virtual void change_event(GEvent&) override; + virtual void change_event(Event&) override; private: void set_knob_hovered(bool); @@ -93,3 +95,5 @@ private: KnobSizeMode m_knob_size_mode { KnobSizeMode::Fixed }; Orientation m_orientation { Orientation::Horizontal }; }; + +} diff --git a/Libraries/LibGUI/GSortingProxyModel.cpp b/Libraries/LibGUI/GSortingProxyModel.cpp index eeb88ca571..482ed7db62 100644 --- a/Libraries/LibGUI/GSortingProxyModel.cpp +++ b/Libraries/LibGUI/GSortingProxyModel.cpp @@ -30,7 +30,9 @@ #include <stdio.h> #include <stdlib.h> -GSortingProxyModel::GSortingProxyModel(NonnullRefPtr<GModel>&& target) +namespace GUI { + +SortingProxyModel::SortingProxyModel(NonnullRefPtr<Model>&& target) : m_target(move(target)) , m_key_column(-1) { @@ -39,21 +41,21 @@ GSortingProxyModel::GSortingProxyModel(NonnullRefPtr<GModel>&& target) }; } -GSortingProxyModel::~GSortingProxyModel() +SortingProxyModel::~SortingProxyModel() { } -int GSortingProxyModel::row_count(const GModelIndex& index) const +int SortingProxyModel::row_count(const ModelIndex& index) const { return target().row_count(index); } -int GSortingProxyModel::column_count(const GModelIndex& index) const +int SortingProxyModel::column_count(const ModelIndex& index) const { return target().column_count(index); } -GModelIndex GSortingProxyModel::map_to_target(const GModelIndex& index) const +ModelIndex SortingProxyModel::map_to_target(const ModelIndex& index) const { if (!index.is_valid()) return {}; @@ -62,37 +64,37 @@ GModelIndex GSortingProxyModel::map_to_target(const GModelIndex& index) const return target().index(m_row_mappings[index.row()], index.column()); } -String GSortingProxyModel::row_name(int index) const +String SortingProxyModel::row_name(int index) const { return target().row_name(index); } -String GSortingProxyModel::column_name(int index) const +String SortingProxyModel::column_name(int index) const { return target().column_name(index); } -GModel::ColumnMetadata GSortingProxyModel::column_metadata(int index) const +Model::ColumnMetadata SortingProxyModel::column_metadata(int index) const { return target().column_metadata(index); } -GVariant GSortingProxyModel::data(const GModelIndex& index, Role role) const +Variant SortingProxyModel::data(const ModelIndex& index, Role role) const { return target().data(map_to_target(index), role); } -void GSortingProxyModel::update() +void SortingProxyModel::update() { target().update(); } -StringView GSortingProxyModel::drag_data_type() const +StringView SortingProxyModel::drag_data_type() const { return target().drag_data_type(); } -void GSortingProxyModel::set_key_column_and_sort_order(int column, GSortOrder sort_order) +void SortingProxyModel::set_key_column_and_sort_order(int column, SortOrder sort_order) { if (column == m_key_column && sort_order == m_sort_order) return; @@ -103,7 +105,7 @@ void GSortingProxyModel::set_key_column_and_sort_order(int column, GSortOrder so resort(); } -void GSortingProxyModel::resort() +void SortingProxyModel::resort() { auto old_row_mappings = m_row_mappings; int row_count = target().row_count(); @@ -115,8 +117,8 @@ void GSortingProxyModel::resort() return; } quick_sort(m_row_mappings.begin(), m_row_mappings.end(), [&](auto row1, auto row2) -> bool { - auto data1 = target().data(target().index(row1, m_key_column), GModel::Role::Sort); - auto data2 = target().data(target().index(row2, m_key_column), GModel::Role::Sort); + auto data1 = target().data(target().index(row1, m_key_column), Model::Role::Sort); + auto data2 = target().data(target().index(row2, m_key_column), Model::Role::Sort); if (data1 == data2) return 0; bool is_less_than; @@ -124,13 +126,13 @@ void GSortingProxyModel::resort() is_less_than = data1.as_string().to_lowercase() < data2.as_string().to_lowercase(); else is_less_than = data1 < data2; - return m_sort_order == GSortOrder::Ascending ? is_less_than : !is_less_than; + return m_sort_order == SortOrder::Ascending ? is_less_than : !is_less_than; }); did_update(); - for_each_view([&](GAbstractView& view) { + for_each_view([&](AbstractView& view) { auto& selection = view.selection(); - Vector<GModelIndex> selected_indexes_in_target; - selection.for_each_index([&](const GModelIndex& index) { + Vector<ModelIndex> selected_indexes_in_target; + selection.for_each_index([&](const ModelIndex& index) { selected_indexes_in_target.append(target().index(old_row_mappings[index.row()], index.column())); }); @@ -145,3 +147,5 @@ void GSortingProxyModel::resort() } }); } + +} diff --git a/Libraries/LibGUI/GSortingProxyModel.h b/Libraries/LibGUI/GSortingProxyModel.h index c084205216..d976013bd9 100644 --- a/Libraries/LibGUI/GSortingProxyModel.h +++ b/Libraries/LibGUI/GSortingProxyModel.h @@ -28,40 +28,44 @@ #include <LibGUI/GModel.h> -class GSortingProxyModel final : public GModel { +namespace GUI { + +class SortingProxyModel final : public Model { public: - static NonnullRefPtr<GSortingProxyModel> create(NonnullRefPtr<GModel>&& model) { return adopt(*new GSortingProxyModel(move(model))); } - virtual ~GSortingProxyModel() override; + static NonnullRefPtr<SortingProxyModel> create(NonnullRefPtr<Model>&& model) { return adopt(*new SortingProxyModel(move(model))); } + virtual ~SortingProxyModel() override; - virtual int row_count(const GModelIndex& = GModelIndex()) const override; - virtual int column_count(const GModelIndex& = GModelIndex()) const override; + virtual int row_count(const ModelIndex& = ModelIndex()) const override; + virtual int column_count(const ModelIndex& = ModelIndex()) const override; virtual String row_name(int) const override; virtual String column_name(int) const override; virtual ColumnMetadata column_metadata(int) const override; - virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; + virtual Variant data(const ModelIndex&, Role = Role::Display) const override; virtual void update() override; virtual StringView drag_data_type() const override; virtual int key_column() const override { return m_key_column; } - virtual GSortOrder sort_order() const override { return m_sort_order; } - virtual void set_key_column_and_sort_order(int, GSortOrder) override; + virtual SortOrder sort_order() const override { return m_sort_order; } + virtual void set_key_column_and_sort_order(int, SortOrder) override; - GModelIndex map_to_target(const GModelIndex&) const; + ModelIndex map_to_target(const ModelIndex&) const; private: - explicit GSortingProxyModel(NonnullRefPtr<GModel>&&); + explicit SortingProxyModel(NonnullRefPtr<Model>&&); - GModel& target() { return *m_target; } - const GModel& target() const { return *m_target; } + Model& target() { return *m_target; } + const Model& target() const { return *m_target; } void resort(); void set_sorting_case_sensitive(bool b) { m_sorting_case_sensitive = b; } bool is_sorting_case_sensitive() { return m_sorting_case_sensitive; } - NonnullRefPtr<GModel> m_target; + NonnullRefPtr<Model> m_target; Vector<int> m_row_mappings; int m_key_column { -1 }; - GSortOrder m_sort_order { GSortOrder::Ascending }; + SortOrder m_sort_order { SortOrder::Ascending }; bool m_sorting_case_sensitive { false }; }; + +} diff --git a/Libraries/LibGUI/GSpinBox.cpp b/Libraries/LibGUI/GSpinBox.cpp index 9482ee6341..09eda858cb 100644 --- a/Libraries/LibGUI/GSpinBox.cpp +++ b/Libraries/LibGUI/GSpinBox.cpp @@ -28,10 +28,12 @@ #include <LibGUI/GSpinBox.h> #include <LibGUI/GTextEditor.h> -GSpinBox::GSpinBox(GWidget* parent) - : GWidget(parent) +namespace GUI { + +SpinBox::SpinBox(Widget* parent) + : Widget(parent) { - m_editor = GTextEditor::construct(GTextEditor::Type::SingleLine, this); + m_editor = TextEditor::construct(TextEditor::Type::SingleLine, this); m_editor->set_text("0"); m_editor->on_change = [this] { bool ok; @@ -41,23 +43,23 @@ GSpinBox::GSpinBox(GWidget* parent) else m_editor->set_text(String::number(m_value)); }; - m_increment_button = GButton::construct(this); + m_increment_button = Button::construct(this); m_increment_button->set_focusable(false); m_increment_button->set_text("\xc3\xb6"); - m_increment_button->on_click = [this](GButton&) { set_value(m_value + 1); }; + m_increment_button->on_click = [this](auto&) { set_value(m_value + 1); }; m_increment_button->set_auto_repeat_interval(150); - m_decrement_button = GButton::construct(this); + m_decrement_button = Button::construct(this); m_decrement_button->set_focusable(false); m_decrement_button->set_text("\xc3\xb7"); - m_decrement_button->on_click = [this](GButton&) { set_value(m_value - 1); }; + m_decrement_button->on_click = [this](auto&) { set_value(m_value - 1); }; m_decrement_button->set_auto_repeat_interval(150); } -GSpinBox::~GSpinBox() +SpinBox::~SpinBox() { } -void GSpinBox::set_value(int value) +void SpinBox::set_value(int value) { value = clamp(value, m_min, m_max); if (m_value == value) @@ -69,7 +71,7 @@ void GSpinBox::set_value(int value) on_change(value); } -void GSpinBox::set_range(int min, int max) +void SpinBox::set_range(int min, int max) { ASSERT(min <= max); if (m_min == min && m_max == max) @@ -86,7 +88,7 @@ void GSpinBox::set_range(int min, int max) update(); } -void GSpinBox::resize_event(GResizeEvent& event) +void SpinBox::resize_event(ResizeEvent& event) { int frame_thickness = m_editor->frame_thickness(); int button_height = (event.size().height() / 2) - frame_thickness; @@ -95,3 +97,5 @@ void GSpinBox::resize_event(GResizeEvent& event) m_decrement_button->set_relative_rect(width() - button_width - frame_thickness, frame_thickness + button_height, button_width, button_height); m_editor->set_relative_rect(0, 0, width(), height()); } + +} diff --git a/Libraries/LibGUI/GSpinBox.h b/Libraries/LibGUI/GSpinBox.h index 3821f424de..b4d86e58c9 100644 --- a/Libraries/LibGUI/GSpinBox.h +++ b/Libraries/LibGUI/GSpinBox.h @@ -28,13 +28,15 @@ #include <LibGUI/GWidget.h> -class GButton; -class GTextEditor; +namespace GUI { -class GSpinBox : public GWidget { - C_OBJECT(GSpinBox) +class Button; +class TextEditor; + +class SpinBox : public Widget { + C_OBJECT(SpinBox) public: - virtual ~GSpinBox() override; + virtual ~SpinBox() override; int value() const { return m_value; } void set_value(int); @@ -48,16 +50,18 @@ public: Function<void(int value)> on_change; protected: - explicit GSpinBox(GWidget* parent = nullptr); + explicit SpinBox(Widget* parent = nullptr); - virtual void resize_event(GResizeEvent&) override; + virtual void resize_event(ResizeEvent&) override; private: - RefPtr<GTextEditor> m_editor; - RefPtr<GButton> m_increment_button; - RefPtr<GButton> m_decrement_button; + RefPtr<TextEditor> m_editor; + RefPtr<Button> m_increment_button; + RefPtr<Button> m_decrement_button; int m_min { 0 }; int m_max { 100 }; int m_value { 0 }; }; + +} diff --git a/Libraries/LibGUI/GSplitter.cpp b/Libraries/LibGUI/GSplitter.cpp index 431bf8db3c..ae6c02b967 100644 --- a/Libraries/LibGUI/GSplitter.cpp +++ b/Libraries/LibGUI/GSplitter.cpp @@ -29,43 +29,45 @@ #include <LibGUI/GSplitter.h> #include <LibGUI/GWindow.h> -GSplitter::GSplitter(Orientation orientation, GWidget* parent) - : GFrame(parent) +namespace GUI { + +Splitter::Splitter(Orientation orientation, Widget* parent) + : Frame(parent) , m_orientation(orientation) { set_background_role(ColorRole::Button); - set_layout(make<GBoxLayout>(orientation)); + set_layout(make<BoxLayout>(orientation)); set_fill_with_background_color(true); layout()->set_spacing(3); } -GSplitter::~GSplitter() +Splitter::~Splitter() { } -void GSplitter::enter_event(Core::Event&) +void Splitter::enter_event(Core::Event&) { set_background_role(ColorRole::HoverHighlight); - window()->set_override_cursor(m_orientation == Orientation::Horizontal ? GStandardCursor::ResizeHorizontal : GStandardCursor::ResizeVertical); + window()->set_override_cursor(m_orientation == Orientation::Horizontal ? StandardCursor::ResizeHorizontal : StandardCursor::ResizeVertical); update(); } -void GSplitter::leave_event(Core::Event&) +void Splitter::leave_event(Core::Event&) { set_background_role(ColorRole::Button); if (!m_resizing) - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(StandardCursor::None); update(); } -void GSplitter::mousedown_event(GMouseEvent& event) +void Splitter::mousedown_event(MouseEvent& event) { - if (event.button() != GMouseButton::Left) + if (event.button() != MouseButton::Left) return; m_resizing = true; int x_or_y = event.position().primary_offset_for_orientation(m_orientation); - GWidget* first_resizee { nullptr }; - GWidget* second_resizee { nullptr }; + Widget* first_resizee { nullptr }; + Widget* second_resizee { nullptr }; int fudge = layout()->spacing(); for_each_child_widget([&](auto& child) { int child_start = child.relative_rect().first_edge_for_orientation(m_orientation); @@ -84,7 +86,7 @@ void GSplitter::mousedown_event(GMouseEvent& event) m_resize_origin = event.position(); } -void GSplitter::mousemove_event(GMouseEvent& event) +void Splitter::mousemove_event(MouseEvent& event) { if (!m_resizing) return; @@ -120,11 +122,13 @@ void GSplitter::mousemove_event(GMouseEvent& event) invalidate_layout(); } -void GSplitter::mouseup_event(GMouseEvent& event) +void Splitter::mouseup_event(MouseEvent& event) { - if (event.button() != GMouseButton::Left) + if (event.button() != MouseButton::Left) return; m_resizing = false; if (!rect().contains(event.position())) - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(StandardCursor::None); +} + } diff --git a/Libraries/LibGUI/GSplitter.h b/Libraries/LibGUI/GSplitter.h index e061f7887f..cda15f1c58 100644 --- a/Libraries/LibGUI/GSplitter.h +++ b/Libraries/LibGUI/GSplitter.h @@ -28,17 +28,19 @@ #include <LibGUI/GFrame.h> -class GSplitter : public GFrame { - C_OBJECT(GSplitter) +namespace GUI { + +class Splitter : public Frame { + C_OBJECT(Splitter) public: - virtual ~GSplitter() override; + virtual ~Splitter() override; protected: - GSplitter(Orientation, GWidget* parent); + Splitter(Orientation, Widget* parent); - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; virtual void enter_event(Core::Event&) override; virtual void leave_event(Core::Event&) override; @@ -46,8 +48,10 @@ private: Orientation m_orientation; bool m_resizing { false }; Point m_resize_origin; - WeakPtr<GWidget> m_first_resizee; - WeakPtr<GWidget> m_second_resizee; + WeakPtr<Widget> m_first_resizee; + WeakPtr<Widget> m_second_resizee; Size m_first_resizee_start_size; Size m_second_resizee_start_size; }; + +} diff --git a/Libraries/LibGUI/GStackWidget.cpp b/Libraries/LibGUI/GStackWidget.cpp index 6895948c99..358b86a1e8 100644 --- a/Libraries/LibGUI/GStackWidget.cpp +++ b/Libraries/LibGUI/GStackWidget.cpp @@ -27,16 +27,18 @@ #include <LibGUI/GBoxLayout.h> #include <LibGUI/GStackWidget.h> -GStackWidget::GStackWidget(GWidget* parent) - : GWidget(parent) +namespace GUI { + +StackWidget::StackWidget(Widget* parent) + : Widget(parent) { } -GStackWidget::~GStackWidget() +StackWidget::~StackWidget() { } -void GStackWidget::set_active_widget(GWidget* widget) +void StackWidget::set_active_widget(Widget* widget) { if (widget == m_active_widget) return; @@ -52,26 +54,26 @@ void GStackWidget::set_active_widget(GWidget* widget) on_active_widget_change(m_active_widget); } -void GStackWidget::resize_event(GResizeEvent& event) +void StackWidget::resize_event(ResizeEvent& event) { if (!m_active_widget) return; m_active_widget->set_relative_rect({ {}, event.size() }); } -void GStackWidget::child_event(Core::ChildEvent& event) +void StackWidget::child_event(Core::ChildEvent& event) { - if (!event.child() || !Core::is<GWidget>(*event.child())) - return GWidget::child_event(event); - auto& child = Core::to<GWidget>(*event.child()); - if (event.type() == GEvent::ChildAdded) { + if (!event.child() || !Core::is<Widget>(*event.child())) + return Widget::child_event(event); + auto& child = Core::to<Widget>(*event.child()); + if (event.type() == Event::ChildAdded) { if (!m_active_widget) set_active_widget(&child); else if (m_active_widget != &child) child.set_visible(false); - } else if (event.type() == GEvent::ChildRemoved) { + } else if (event.type() == Event::ChildRemoved) { if (m_active_widget == &child) { - GWidget* new_active_widget = nullptr; + Widget* new_active_widget = nullptr; for_each_child_widget([&](auto& new_child) { new_active_widget = &new_child; return IterationDecision::Break; @@ -79,5 +81,7 @@ void GStackWidget::child_event(Core::ChildEvent& event) set_active_widget(new_active_widget); } } - GWidget::child_event(event); + Widget::child_event(event); +} + } diff --git a/Libraries/LibGUI/GStackWidget.h b/Libraries/LibGUI/GStackWidget.h index 2cd071576e..aadc1d4a26 100644 --- a/Libraries/LibGUI/GStackWidget.h +++ b/Libraries/LibGUI/GStackWidget.h @@ -28,22 +28,26 @@ #include <LibGUI/GWidget.h> -class GStackWidget : public GWidget { - C_OBJECT(GStackWidget) +namespace GUI { + +class StackWidget : public Widget { + C_OBJECT(StackWidget) public: - virtual ~GStackWidget() override; + virtual ~StackWidget() override; - GWidget* active_widget() { return m_active_widget.ptr(); } - const GWidget* active_widget() const { return m_active_widget.ptr(); } - void set_active_widget(GWidget*); + Widget* active_widget() { return m_active_widget.ptr(); } + const Widget* active_widget() const { return m_active_widget.ptr(); } + void set_active_widget(Widget*); - Function<void(GWidget*)> on_active_widget_change; + Function<void(Widget*)> on_active_widget_change; protected: - explicit GStackWidget(GWidget* parent); + explicit StackWidget(Widget* parent); virtual void child_event(Core::ChildEvent&) override; - virtual void resize_event(GResizeEvent&) override; + virtual void resize_event(ResizeEvent&) override; private: - RefPtr<GWidget> m_active_widget; + RefPtr<Widget> m_active_widget; }; + +} diff --git a/Libraries/LibGUI/GStatusBar.cpp b/Libraries/LibGUI/GStatusBar.cpp index 6eddbf7d62..f6afd0ad6b 100644 --- a/Libraries/LibGUI/GStatusBar.cpp +++ b/Libraries/LibGUI/GStatusBar.cpp @@ -31,17 +31,19 @@ #include <LibGUI/GResizeCorner.h> #include <LibGUI/GStatusBar.h> -GStatusBar::GStatusBar(GWidget* parent) - : GStatusBar(1, parent) +namespace GUI { + +StatusBar::StatusBar(Widget* parent) + : StatusBar(1, parent) { } -GStatusBar::GStatusBar(int label_count, GWidget* parent) - : GWidget(parent) +StatusBar::StatusBar(int label_count, Widget* parent) + : Widget(parent) { set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); set_preferred_size(0, 20); - set_layout(make<GHBoxLayout>()); + set_layout(make<HBoxLayout>()); layout()->set_margins({ 2, 2, 2, 2 }); layout()->set_spacing(2); @@ -51,16 +53,16 @@ GStatusBar::GStatusBar(int label_count, GWidget* parent) for (auto i = 0; i < label_count; i++) m_labels.append(create_label()); - m_corner = GResizeCorner::construct(this); + m_corner = ResizeCorner::construct(this); } -GStatusBar::~GStatusBar() +StatusBar::~StatusBar() { } -NonnullRefPtr<GLabel> GStatusBar::create_label() +NonnullRefPtr<Label> StatusBar::create_label() { - auto label = GLabel::construct(this); + auto label = Label::construct(this); label->set_frame_shadow(FrameShadow::Sunken); label->set_frame_shape(FrameShape::Panel); label->set_frame_thickness(1); @@ -68,29 +70,31 @@ NonnullRefPtr<GLabel> GStatusBar::create_label() return label; } -void GStatusBar::set_text(const StringView& text) +void StatusBar::set_text(const StringView& text) { m_labels.first().set_text(text); } -String GStatusBar::text() const +String StatusBar::text() const { return m_labels.first().text(); } -void GStatusBar::set_text(int index, const StringView& text) +void StatusBar::set_text(int index, const StringView& text) { m_labels.at(index).set_text(text); } -String GStatusBar::text(int index) const +String StatusBar::text(int index) const { return m_labels.at(index).text(); } -void GStatusBar::paint_event(GPaintEvent& event) +void StatusBar::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); StylePainter::paint_surface(painter, rect(), palette(), !spans_entire_window_horizontally()); } + +} diff --git a/Libraries/LibGUI/GStatusBar.h b/Libraries/LibGUI/GStatusBar.h index 8bb01ea53d..8b9b7fe9f3 100644 --- a/Libraries/LibGUI/GStatusBar.h +++ b/Libraries/LibGUI/GStatusBar.h @@ -28,13 +28,15 @@ #include <LibGUI/GWidget.h> -class GLabel; -class GResizeCorner; +namespace GUI { -class GStatusBar : public GWidget { - C_OBJECT(GStatusBar) +class Label; +class ResizeCorner; + +class StatusBar : public Widget { + C_OBJECT(StatusBar) public: - virtual ~GStatusBar() override; + virtual ~StatusBar() override; String text() const; String text(int index) const; @@ -42,12 +44,14 @@ public: void set_text(int index, const StringView&); protected: - explicit GStatusBar(GWidget* parent); - explicit GStatusBar(int label_count, GWidget* parent); - virtual void paint_event(GPaintEvent&) override; + explicit StatusBar(Widget* parent); + explicit StatusBar(int label_count, Widget* parent); + virtual void paint_event(PaintEvent&) override; private: - NonnullRefPtr<GLabel> create_label(); - NonnullRefPtrVector<GLabel> m_labels; - RefPtr<GResizeCorner> m_corner; + NonnullRefPtr<Label> create_label(); + NonnullRefPtrVector<Label> m_labels; + RefPtr<ResizeCorner> m_corner; }; + +} diff --git a/Libraries/LibGUI/GTabWidget.cpp b/Libraries/LibGUI/GTabWidget.cpp index c9a45d2936..afa59a853d 100644 --- a/Libraries/LibGUI/GTabWidget.cpp +++ b/Libraries/LibGUI/GTabWidget.cpp @@ -30,22 +30,24 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GTabWidget.h> -GTabWidget::GTabWidget(GWidget* parent) - : GWidget(parent) +namespace GUI { + +TabWidget::TabWidget(Widget* parent) + : Widget(parent) { } -GTabWidget::~GTabWidget() +TabWidget::~TabWidget() { } -void GTabWidget::add_widget(const StringView& title, GWidget* widget) +void TabWidget::add_widget(const StringView& title, Widget* widget) { m_tabs.append({ title, widget }); add_child(*widget); } -void GTabWidget::set_active_widget(GWidget* widget) +void TabWidget::set_active_widget(Widget* widget) { if (widget == m_active_widget) return; @@ -61,14 +63,14 @@ void GTabWidget::set_active_widget(GWidget* widget) update_bar(); } -void GTabWidget::resize_event(GResizeEvent& event) +void TabWidget::resize_event(ResizeEvent& event) { if (!m_active_widget) return; m_active_widget->set_relative_rect(child_rect_for_size(event.size())); } -Rect GTabWidget::child_rect_for_size(const Size& size) const +Rect TabWidget::child_rect_for_size(const Size& size) const { Rect rect; switch (m_tab_position) { @@ -84,19 +86,19 @@ Rect GTabWidget::child_rect_for_size(const Size& size) const return rect; } -void GTabWidget::child_event(Core::ChildEvent& event) +void TabWidget::child_event(Core::ChildEvent& event) { - if (!event.child() || !Core::is<GWidget>(*event.child())) - return GWidget::child_event(event); - auto& child = Core::to<GWidget>(*event.child()); - if (event.type() == GEvent::ChildAdded) { + if (!event.child() || !Core::is<Widget>(*event.child())) + return Widget::child_event(event); + auto& child = Core::to<Widget>(*event.child()); + if (event.type() == Event::ChildAdded) { if (!m_active_widget) set_active_widget(&child); else if (m_active_widget != &child) child.set_visible(false); - } else if (event.type() == GEvent::ChildRemoved) { + } else if (event.type() == Event::ChildRemoved) { if (m_active_widget == &child) { - GWidget* new_active_widget = nullptr; + Widget* new_active_widget = nullptr; for_each_child_widget([&](auto& new_child) { new_active_widget = &new_child; return IterationDecision::Break; @@ -104,10 +106,10 @@ void GTabWidget::child_event(Core::ChildEvent& event) set_active_widget(new_active_widget); } } - GWidget::child_event(event); + Widget::child_event(event); } -Rect GTabWidget::bar_rect() const +Rect TabWidget::bar_rect() const { switch (m_tab_position) { case TabPosition::Top: @@ -118,7 +120,7 @@ Rect GTabWidget::bar_rect() const ASSERT_NOT_REACHED(); } -Rect GTabWidget::container_rect() const +Rect TabWidget::container_rect() const { switch (m_tab_position) { case TabPosition::Top: @@ -129,9 +131,9 @@ Rect GTabWidget::container_rect() const ASSERT_NOT_REACHED(); } -void GTabWidget::paint_event(GPaintEvent& event) +void TabWidget::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); auto container_rect = this->container_rect(); @@ -164,7 +166,7 @@ void GTabWidget::paint_event(GPaintEvent& event) } } -Rect GTabWidget::button_rect(int index) const +Rect TabWidget::button_rect(int index) const { int x_offset = 2; for (int i = 0; i < index; ++i) @@ -181,12 +183,12 @@ Rect GTabWidget::button_rect(int index) const return rect; } -int GTabWidget::TabData::width(const Font& font) const +int TabWidget::TabData::width(const Font& font) const { return 16 + font.width(title); } -void GTabWidget::mousedown_event(GMouseEvent& event) +void TabWidget::mousedown_event(MouseEvent& event) { for (int i = 0; i < m_tabs.size(); ++i) { auto button_rect = this->button_rect(i); @@ -197,7 +199,7 @@ void GTabWidget::mousedown_event(GMouseEvent& event) } } -void GTabWidget::mousemove_event(GMouseEvent& event) +void TabWidget::mousemove_event(MouseEvent& event) { int hovered_tab = -1; for (int i = 0; i < m_tabs.size(); ++i) { @@ -214,7 +216,7 @@ void GTabWidget::mousemove_event(GMouseEvent& event) update_bar(); } -void GTabWidget::leave_event(Core::Event&) +void TabWidget::leave_event(Core::Event&) { if (m_hovered_tab_index != -1) { m_hovered_tab_index = -1; @@ -222,14 +224,14 @@ void GTabWidget::leave_event(Core::Event&) } } -void GTabWidget::update_bar() +void TabWidget::update_bar() { auto invalidation_rect = bar_rect(); invalidation_rect.set_height(invalidation_rect.height() + 1); update(invalidation_rect); } -void GTabWidget::set_tab_position(TabPosition tab_position) +void TabWidget::set_tab_position(TabPosition tab_position) { if (m_tab_position == tab_position) return; @@ -239,7 +241,7 @@ void GTabWidget::set_tab_position(TabPosition tab_position) update(); } -int GTabWidget::active_tab_index() const +int TabWidget::active_tab_index() const { for (int i = 0; i < m_tabs.size(); i++) { if (m_tabs.at(i).widget == m_active_widget) @@ -247,3 +249,4 @@ int GTabWidget::active_tab_index() const } return -1; } +} diff --git a/Libraries/LibGUI/GTabWidget.h b/Libraries/LibGUI/GTabWidget.h index 72514b2505..434016e0af 100644 --- a/Libraries/LibGUI/GTabWidget.h +++ b/Libraries/LibGUI/GTabWidget.h @@ -28,37 +28,39 @@ #include <LibGUI/GWidget.h> -class GTabWidget : public GWidget { - C_OBJECT(GTabWidget) +namespace GUI { + +class TabWidget : public Widget { + C_OBJECT(TabWidget) public: enum TabPosition { Top, Bottom, }; - explicit GTabWidget(GWidget* parent); - virtual ~GTabWidget() override; + explicit TabWidget(Widget* parent); + virtual ~TabWidget() override; TabPosition tab_position() const { return m_tab_position; } void set_tab_position(TabPosition); int active_tab_index() const; - GWidget* active_widget() { return m_active_widget.ptr(); } - const GWidget* active_widget() const { return m_active_widget.ptr(); } - void set_active_widget(GWidget*); + Widget* active_widget() { return m_active_widget.ptr(); } + const Widget* active_widget() const { return m_active_widget.ptr(); } + void set_active_widget(Widget*); int bar_height() const { return 21; } int container_padding() const { return 2; } - void add_widget(const StringView&, GWidget*); + void add_widget(const StringView&, Widget*); protected: - virtual void paint_event(GPaintEvent&) override; + virtual void paint_event(PaintEvent&) override; virtual void child_event(Core::ChildEvent&) override; - virtual void resize_event(GResizeEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; + virtual void resize_event(ResizeEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; virtual void leave_event(Core::Event&) override; private: @@ -68,15 +70,17 @@ private: Rect container_rect() const; void update_bar(); - RefPtr<GWidget> m_active_widget; + RefPtr<Widget> m_active_widget; struct TabData { Rect rect(const Font&) const; int width(const Font&) const; String title; - GWidget* widget { nullptr }; + Widget* widget { nullptr }; }; Vector<TabData> m_tabs; TabPosition m_tab_position { TabPosition::Top }; int m_hovered_tab_index { -1 }; }; + +} diff --git a/Libraries/LibGUI/GTableView.cpp b/Libraries/LibGUI/GTableView.cpp index 727db5962f..0da8441131 100644 --- a/Libraries/LibGUI/GTableView.cpp +++ b/Libraries/LibGUI/GTableView.cpp @@ -36,23 +36,25 @@ #include <LibGUI/GTextBox.h> #include <LibGUI/GWindow.h> -GTableView::GTableView(GWidget* parent) - : GAbstractTableView(parent) +namespace GUI { + +TableView::TableView(Widget* parent) + : AbstractTableView(parent) { set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); } -GTableView::~GTableView() +TableView::~TableView() { } -void GTableView::paint_event(GPaintEvent& event) +void TableView::paint_event(PaintEvent& event) { Color widget_background_color = palette().color(background_role()); - GFrame::paint_event(event); + Frame::paint_event(event); - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(frame_inner_rect()); painter.add_clip_rect(event.rect()); painter.fill_rect(event.rect(), widget_background_color); @@ -125,7 +127,7 @@ void GTableView::paint_event(GPaintEvent& event) if (is_selected_row) text_color = palette().selection_text(); else - text_color = model()->data(cell_index, GModel::Role::ForegroundColor).to_color(palette().color(foreground_role())); + text_color = model()->data(cell_index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); painter.draw_text(cell_rect, data.to_string(), font, column_metadata.text_alignment, text_color, TextElision::Right); } } @@ -142,3 +144,5 @@ void GTableView::paint_event(GPaintEvent& event) if (headers_visible()) paint_headers(painter); } + +} diff --git a/Libraries/LibGUI/GTableView.h b/Libraries/LibGUI/GTableView.h index 1a18aa500d..25ff332d45 100644 --- a/Libraries/LibGUI/GTableView.h +++ b/Libraries/LibGUI/GTableView.h @@ -31,13 +31,17 @@ #include <LibGUI/GAbstractTableView.h> #include <LibGUI/GModel.h> -class GTableView : public GAbstractTableView { - C_OBJECT(GTableView) +namespace GUI { + +class TableView : public AbstractTableView { + C_OBJECT(TableView) public: - virtual ~GTableView() override; + virtual ~TableView() override; protected: - explicit GTableView(GWidget* parent); + explicit TableView(Widget* parent); - virtual void paint_event(GPaintEvent&) override; + virtual void paint_event(PaintEvent&) override; }; + +} diff --git a/Libraries/LibGUI/GTextBox.cpp b/Libraries/LibGUI/GTextBox.cpp index 5b19e7be91..36a8f691b8 100644 --- a/Libraries/LibGUI/GTextBox.cpp +++ b/Libraries/LibGUI/GTextBox.cpp @@ -26,11 +26,15 @@ #include <LibGUI/GTextBox.h> -GTextBox::GTextBox(GWidget* parent) - : GTextEditor(GTextEditor::SingleLine, parent) +namespace GUI { + +TextBox::TextBox(Widget* parent) + : TextEditor(TextEditor::SingleLine, parent) { } -GTextBox::~GTextBox() +TextBox::~TextBox() { } + +} diff --git a/Libraries/LibGUI/GTextBox.h b/Libraries/LibGUI/GTextBox.h index a796e736bd..38214a50c7 100644 --- a/Libraries/LibGUI/GTextBox.h +++ b/Libraries/LibGUI/GTextBox.h @@ -29,9 +29,13 @@ #include <AK/Function.h> #include <LibGUI/GTextEditor.h> -class GTextBox : public GTextEditor { - C_OBJECT(GTextBox) +namespace GUI { + +class TextBox : public TextEditor { + C_OBJECT(TextBox) public: - explicit GTextBox(GWidget* parent); - virtual ~GTextBox() override; + explicit TextBox(Widget* parent); + virtual ~TextBox() override; }; + +} diff --git a/Libraries/LibGUI/GTextDocument.cpp b/Libraries/LibGUI/GTextDocument.cpp index c6389cb0a8..bba4e80329 100644 --- a/Libraries/LibGUI/GTextDocument.cpp +++ b/Libraries/LibGUI/GTextDocument.cpp @@ -30,11 +30,13 @@ #include <LibGUI/GTextEditor.h> #include <ctype.h> -GTextDocument::GTextDocument(Client* client) +namespace GUI { + +TextDocument::TextDocument(Client* client) { if (client) m_clients.set(client); - append_line(make<GTextDocumentLine>(*this)); + append_line(make<TextDocumentLine>(*this)); // TODO: Instead of a repating timer, this we should call a delayed 2 sec timer when the user types. m_undo_timer = Core::Timer::construct( @@ -43,7 +45,7 @@ GTextDocument::GTextDocument(Client* client) }); } -void GTextDocument::set_text(const StringView& text) +void TextDocument::set_text(const StringView& text) { m_client_notifications_enabled = false; m_spans.clear(); @@ -53,7 +55,7 @@ void GTextDocument::set_text(const StringView& text) auto add_line = [&](size_t current_position) { size_t line_length = current_position - start_of_current_line; - auto line = make<GTextDocumentLine>(*this); + auto line = make<TextDocumentLine>(*this); if (line_length) line->set_text(*this, text.substring_view(start_of_current_line, current_position - start_of_current_line)); append_line(move(line)); @@ -71,7 +73,7 @@ void GTextDocument::set_text(const StringView& text) client->document_did_set_text(); } -size_t GTextDocumentLine::first_non_whitespace_column() const +size_t TextDocumentLine::first_non_whitespace_column() const { for (size_t i = 0; i < length(); ++i) { if (!isspace(m_text[(int)i])) @@ -80,24 +82,24 @@ size_t GTextDocumentLine::first_non_whitespace_column() const return length(); } -GTextDocumentLine::GTextDocumentLine(GTextDocument& document) +TextDocumentLine::TextDocumentLine(TextDocument& document) { clear(document); } -GTextDocumentLine::GTextDocumentLine(GTextDocument& document, const StringView& text) +TextDocumentLine::TextDocumentLine(TextDocument& document, const StringView& text) { set_text(document, text); } -void GTextDocumentLine::clear(GTextDocument& document) +void TextDocumentLine::clear(TextDocument& document) { m_text.clear(); m_text.append(0); document.update_views({}); } -void GTextDocumentLine::set_text(GTextDocument& document, const StringView& text) +void TextDocumentLine::set_text(TextDocument& document, const StringView& text) { if (text.length() == length() && !memcmp(text.characters_without_null_termination(), characters(), length())) return; @@ -110,7 +112,7 @@ void GTextDocumentLine::set_text(GTextDocument& document, const StringView& text document.update_views({}); } -void GTextDocumentLine::append(GTextDocument& document, const char* characters, size_t length) +void TextDocumentLine::append(TextDocument& document, const char* characters, size_t length) { int old_length = m_text.size() - 1; m_text.resize(m_text.size() + length); @@ -119,17 +121,17 @@ void GTextDocumentLine::append(GTextDocument& document, const char* characters, document.update_views({}); } -void GTextDocumentLine::append(GTextDocument& document, char ch) +void TextDocumentLine::append(TextDocument& document, char ch) { insert(document, length(), ch); } -void GTextDocumentLine::prepend(GTextDocument& document, char ch) +void TextDocumentLine::prepend(TextDocument& document, char ch) { insert(document, 0, ch); } -void GTextDocumentLine::insert(GTextDocument& document, size_t index, char ch) +void TextDocumentLine::insert(TextDocument& document, size_t index, char ch) { if (index == length()) { m_text.last() = ch; @@ -140,7 +142,7 @@ void GTextDocumentLine::insert(GTextDocument& document, size_t index, char ch) document.update_views({}); } -void GTextDocumentLine::remove(GTextDocument& document, size_t index) +void TextDocumentLine::remove(TextDocument& document, size_t index) { if (index == length()) { m_text.take_last(); @@ -151,14 +153,14 @@ void GTextDocumentLine::remove(GTextDocument& document, size_t index) document.update_views({}); } -void GTextDocumentLine::truncate(GTextDocument& document, size_t length) +void TextDocumentLine::truncate(TextDocument& document, size_t length) { m_text.resize((int)length + 1); m_text.last() = 0; document.update_views({}); } -void GTextDocument::append_line(NonnullOwnPtr<GTextDocumentLine> line) +void TextDocument::append_line(NonnullOwnPtr<TextDocumentLine> line) { lines().append(move(line)); if (m_client_notifications_enabled) { @@ -167,7 +169,7 @@ void GTextDocument::append_line(NonnullOwnPtr<GTextDocumentLine> line) } } -void GTextDocument::insert_line(size_t line_index, NonnullOwnPtr<GTextDocumentLine> line) +void TextDocument::insert_line(size_t line_index, NonnullOwnPtr<TextDocumentLine> line) { lines().insert((int)line_index, move(line)); if (m_client_notifications_enabled) { @@ -176,7 +178,7 @@ void GTextDocument::insert_line(size_t line_index, NonnullOwnPtr<GTextDocumentLi } } -void GTextDocument::remove_line(size_t line_index) +void TextDocument::remove_line(size_t line_index) { lines().remove((int)line_index); if (m_client_notifications_enabled) { @@ -185,7 +187,7 @@ void GTextDocument::remove_line(size_t line_index) } } -void GTextDocument::remove_all_lines() +void TextDocument::remove_all_lines() { lines().clear(); if (m_client_notifications_enabled) { @@ -194,26 +196,26 @@ void GTextDocument::remove_all_lines() } } -GTextDocument::Client::~Client() +TextDocument::Client::~Client() { } -void GTextDocument::register_client(Client& client) +void TextDocument::register_client(Client& client) { m_clients.set(&client); } -void GTextDocument::unregister_client(Client& client) +void TextDocument::unregister_client(Client& client) { m_clients.remove(&client); } -void GTextDocument::update_views(Badge<GTextDocumentLine>) +void TextDocument::update_views(Badge<TextDocumentLine>) { notify_did_change(); } -void GTextDocument::notify_did_change() +void TextDocument::notify_did_change() { if (m_client_notifications_enabled) { for (auto* client : m_clients) @@ -221,7 +223,7 @@ void GTextDocument::notify_did_change() } } -void GTextDocument::set_all_cursors(const GTextPosition& position) +void TextDocument::set_all_cursors(const TextPosition& position) { if (m_client_notifications_enabled) { for (auto* client : m_clients) @@ -229,7 +231,7 @@ void GTextDocument::set_all_cursors(const GTextPosition& position) } } -String GTextDocument::text_in_range(const GTextRange& a_range) const +String TextDocument::text_in_range(const TextRange& a_range) const { auto range = a_range.normalized(); @@ -246,7 +248,7 @@ String GTextDocument::text_in_range(const GTextRange& a_range) const return builder.to_string(); } -char GTextDocument::character_at(const GTextPosition& position) const +char TextDocument::character_at(const TextPosition& position) const { ASSERT(position.line() < line_count()); auto& line = this->line(position.line()); @@ -255,7 +257,7 @@ char GTextDocument::character_at(const GTextPosition& position) const return line.characters()[position.column()]; } -GTextPosition GTextDocument::next_position_after(const GTextPosition& position, SearchShouldWrap should_wrap) const +TextPosition TextDocument::next_position_after(const TextPosition& position, SearchShouldWrap should_wrap) const { auto& line = this->line(position.line()); if (position.column() == line.length()) { @@ -269,7 +271,7 @@ GTextPosition GTextDocument::next_position_after(const GTextPosition& position, return { position.line(), position.column() + 1 }; } -GTextPosition GTextDocument::previous_position_before(const GTextPosition& position, SearchShouldWrap should_wrap) const +TextPosition TextDocument::previous_position_before(const TextPosition& position, SearchShouldWrap should_wrap) const { if (position.column() == 0) { if (position.line() == 0) { @@ -285,15 +287,15 @@ GTextPosition GTextDocument::previous_position_before(const GTextPosition& posit return { position.line(), position.column() - 1 }; } -GTextRange GTextDocument::find_next(const StringView& needle, const GTextPosition& start, SearchShouldWrap should_wrap) const +TextRange TextDocument::find_next(const StringView& needle, const TextPosition& start, SearchShouldWrap should_wrap) const { if (needle.is_empty()) return {}; - GTextPosition position = start.is_valid() ? start : GTextPosition(0, 0); - GTextPosition original_position = position; + TextPosition position = start.is_valid() ? start : TextPosition(0, 0); + TextPosition original_position = position; - GTextPosition start_of_potential_match; + TextPosition start_of_potential_match; size_t needle_index = 0; do { @@ -315,16 +317,16 @@ GTextRange GTextDocument::find_next(const StringView& needle, const GTextPositio return {}; } -GTextRange GTextDocument::find_previous(const StringView& needle, const GTextPosition& start, SearchShouldWrap should_wrap) const +TextRange TextDocument::find_previous(const StringView& needle, const TextPosition& start, SearchShouldWrap should_wrap) const { if (needle.is_empty()) return {}; - GTextPosition position = start.is_valid() ? start : GTextPosition(0, 0); + TextPosition position = start.is_valid() ? start : TextPosition(0, 0); position = previous_position_before(position, should_wrap); - GTextPosition original_position = position; + TextPosition original_position = position; - GTextPosition end_of_potential_match; + TextPosition end_of_potential_match; size_t needle_index = needle.length() - 1; do { @@ -346,11 +348,11 @@ GTextRange GTextDocument::find_previous(const StringView& needle, const GTextPos return {}; } -Vector<GTextRange> GTextDocument::find_all(const StringView& needle) const +Vector<TextRange> TextDocument::find_all(const StringView& needle) const { - Vector<GTextRange> ranges; + Vector<TextRange> ranges; - GTextPosition position; + TextPosition position; for (;;) { auto range = find_next(needle, position, SearchShouldWrap::No); if (!range.is_valid()) @@ -361,7 +363,7 @@ Vector<GTextRange> GTextDocument::find_all(const StringView& needle) const return ranges; } -Optional<GTextDocumentSpan> GTextDocument::first_non_skippable_span_before(const GTextPosition& position) const +Optional<TextDocumentSpan> TextDocument::first_non_skippable_span_before(const TextPosition& position) const { for (int i = m_spans.size() - 1; i >= 0; --i) { if (!m_spans[i].range.contains(position)) @@ -375,7 +377,7 @@ Optional<GTextDocumentSpan> GTextDocument::first_non_skippable_span_before(const return {}; } -Optional<GTextDocumentSpan> GTextDocument::first_non_skippable_span_after(const GTextPosition& position) const +Optional<TextDocumentSpan> TextDocument::first_non_skippable_span_after(const TextPosition& position) const { for (int i = 0; i < m_spans.size(); ++i) { if (!m_spans[i].range.contains(position)) @@ -389,7 +391,7 @@ Optional<GTextDocumentSpan> GTextDocument::first_non_skippable_span_after(const return {}; } -void GTextDocument::undo() +void TextDocument::undo() { if (!can_undo()) return; @@ -397,7 +399,7 @@ void GTextDocument::undo() notify_did_change(); } -void GTextDocument::redo() +void TextDocument::redo() { if (!can_redo()) return; @@ -405,22 +407,22 @@ void GTextDocument::redo() notify_did_change(); } -void GTextDocument::add_to_undo_stack(NonnullOwnPtr<GTextDocumentUndoCommand> undo_command) +void TextDocument::add_to_undo_stack(NonnullOwnPtr<TextDocumentUndoCommand> undo_command) { m_undo_stack.push(move(undo_command)); } -GTextDocumentUndoCommand::GTextDocumentUndoCommand(GTextDocument& document) +TextDocumentUndoCommand::TextDocumentUndoCommand(TextDocument& document) : m_document(document) { } -GTextDocumentUndoCommand::~GTextDocumentUndoCommand() +TextDocumentUndoCommand::~TextDocumentUndoCommand() { } -InsertTextCommand::InsertTextCommand(GTextDocument& document, const String& text, const GTextPosition& position) - : GTextDocumentUndoCommand(document) +InsertTextCommand::InsertTextCommand(TextDocument& document, const String& text, const TextPosition& position) + : TextDocumentUndoCommand(document) , m_text(text) , m_range({ position, position }) { @@ -441,8 +443,8 @@ void InsertTextCommand::undo() m_document.set_all_cursors(m_range.start()); } -RemoveTextCommand::RemoveTextCommand(GTextDocument& document, const String& text, const GTextRange& range) - : GTextDocumentUndoCommand(document) +RemoveTextCommand::RemoveTextCommand(TextDocument& document, const String& text, const TextRange& range) + : TextDocumentUndoCommand(document) , m_text(text) , m_range(range) { @@ -460,20 +462,20 @@ void RemoveTextCommand::undo() m_document.set_all_cursors(new_cursor); } -void GTextDocument::update_undo_timer() +void TextDocument::update_undo_timer() { m_undo_stack.finalize_current_combo(); } -GTextPosition GTextDocument::insert_at(const GTextPosition& position, const StringView& text, const Client* client) +TextPosition TextDocument::insert_at(const TextPosition& position, const StringView& text, const Client* client) { - GTextPosition cursor = position; + TextPosition cursor = position; for (size_t i = 0; i < text.length(); ++i) cursor = insert_at(cursor, text[i], client); return cursor; } -GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch, const Client* client) +TextPosition TextDocument::insert_at(const TextPosition& position, char ch, const Client* client) { bool automatic_indentation_enabled = client ? client->is_automatic_indentation_enabled() : false; size_t m_soft_tab_width = client ? client->soft_tab_width() : 4; @@ -500,11 +502,11 @@ GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch, c Vector<char> line_content; for (size_t i = position.column(); i < line(row).length(); i++) line_content.append(line(row).characters()[i]); - insert_line(position.line() + (at_tail ? 1 : 0), make<GTextDocumentLine>(*this, new_line_contents)); + insert_line(position.line() + (at_tail ? 1 : 0), make<TextDocumentLine>(*this, new_line_contents)); notify_did_change(); return { position.line() + 1, line(position.line() + 1).length() }; } - auto new_line = make<GTextDocumentLine>(*this); + auto new_line = make<TextDocumentLine>(*this); new_line->append(*this, line(position.line()).characters() + position.column(), line(position.line()).length() - position.column()); Vector<char> line_content; @@ -529,7 +531,7 @@ GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch, c return { position.line(), position.column() + 1 }; } -void GTextDocument::remove(const GTextRange& unnormalized_range) +void TextDocument::remove(const TextRange& unnormalized_range) { if (!unnormalized_range.is_valid()) return; @@ -573,15 +575,17 @@ void GTextDocument::remove(const GTextRange& unnormalized_range) } if (lines().is_empty()) { - append_line(make<GTextDocumentLine>(*this)); + append_line(make<TextDocumentLine>(*this)); } notify_did_change(); } -GTextRange GTextDocument::range_for_entire_line(size_t line_index) const +TextRange TextDocument::range_for_entire_line(size_t line_index) const { if (line_index >= line_count()) return {}; return { { line_index, 0 }, { line_index, line(line_index).length() } }; } + +} diff --git a/Libraries/LibGUI/GTextDocument.h b/Libraries/LibGUI/GTextDocument.h index 7e12e14b80..dd25f395c5 100644 --- a/Libraries/LibGUI/GTextDocument.h +++ b/Libraries/LibGUI/GTextDocument.h @@ -37,13 +37,15 @@ #include <LibGUI/GTextRange.h> #include <LibGUI/GUndoStack.h> -class GTextEditor; -class GTextDocument; -class GTextDocumentLine; -class GTextDocumentUndoCommand; +namespace GUI { -struct GTextDocumentSpan { - GTextRange range; +class TextDocument; +class TextDocumentLine; +class TextDocumentUndoCommand; +class TextEditor; + +struct TextDocumentSpan { + TextRange range; Color color; Optional<Color> background_color; bool is_skippable { false }; @@ -51,7 +53,7 @@ struct GTextDocumentSpan { void* data { nullptr }; }; -class GTextDocument : public RefCounted<GTextDocument> { +class TextDocument : public RefCounted<TextDocument> { public: enum class SearchShouldWrap { No = 0, @@ -67,60 +69,60 @@ public: virtual void document_did_remove_all_lines() = 0; virtual void document_did_change() = 0; virtual void document_did_set_text() = 0; - virtual void document_did_set_cursor(const GTextPosition&) = 0; + virtual void document_did_set_cursor(const TextPosition&) = 0; virtual bool is_automatic_indentation_enabled() const = 0; virtual int soft_tab_width() const = 0; }; - static NonnullRefPtr<GTextDocument> create(Client* client = nullptr) + static NonnullRefPtr<TextDocument> create(Client* client = nullptr) { - return adopt(*new GTextDocument(client)); + return adopt(*new TextDocument(client)); } size_t line_count() const { return (size_t)m_lines.size(); } - const GTextDocumentLine& line(size_t line_index) const { return m_lines[(int)line_index]; } - GTextDocumentLine& line(size_t line_index) { return m_lines[(int)line_index]; } + const TextDocumentLine& line(size_t line_index) const { return m_lines[(int)line_index]; } + TextDocumentLine& line(size_t line_index) { return m_lines[(int)line_index]; } - void set_spans(const Vector<GTextDocumentSpan>& spans) { m_spans = spans; } + void set_spans(const Vector<TextDocumentSpan>& spans) { m_spans = spans; } void set_text(const StringView&); - const NonnullOwnPtrVector<GTextDocumentLine>& lines() const { return m_lines; } - NonnullOwnPtrVector<GTextDocumentLine>& lines() { return m_lines; } + const NonnullOwnPtrVector<TextDocumentLine>& lines() const { return m_lines; } + NonnullOwnPtrVector<TextDocumentLine>& lines() { return m_lines; } bool has_spans() const { return !m_spans.is_empty(); } - const Vector<GTextDocumentSpan>& spans() const { return m_spans; } - void set_span_at_index(size_t index, GTextDocumentSpan span) { m_spans[(int)index] = move(span); } + const Vector<TextDocumentSpan>& spans() const { return m_spans; } + void set_span_at_index(size_t index, TextDocumentSpan span) { m_spans[(int)index] = move(span); } - void append_line(NonnullOwnPtr<GTextDocumentLine>); + void append_line(NonnullOwnPtr<TextDocumentLine>); void remove_line(size_t line_index); void remove_all_lines(); - void insert_line(size_t line_index, NonnullOwnPtr<GTextDocumentLine>); + void insert_line(size_t line_index, NonnullOwnPtr<TextDocumentLine>); void register_client(Client&); void unregister_client(Client&); - void update_views(Badge<GTextDocumentLine>); + void update_views(Badge<TextDocumentLine>); - String text_in_range(const GTextRange&) const; + String text_in_range(const TextRange&) const; - Vector<GTextRange> find_all(const StringView& needle) const; + Vector<TextRange> find_all(const StringView& needle) const; - GTextRange find_next(const StringView&, const GTextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes) const; - GTextRange find_previous(const StringView&, const GTextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes) const; + TextRange find_next(const StringView&, const TextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes) const; + TextRange find_previous(const StringView&, const TextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes) const; - GTextPosition next_position_after(const GTextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const; - GTextPosition previous_position_before(const GTextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const; + TextPosition next_position_after(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const; + TextPosition previous_position_before(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const; - char character_at(const GTextPosition&) const; + char character_at(const TextPosition&) const; - GTextRange range_for_entire_line(size_t line_index) const; + TextRange range_for_entire_line(size_t line_index) const; - Optional<GTextDocumentSpan> first_non_skippable_span_before(const GTextPosition&) const; - Optional<GTextDocumentSpan> first_non_skippable_span_after(const GTextPosition&) const; + Optional<TextDocumentSpan> first_non_skippable_span_before(const TextPosition&) const; + Optional<TextDocumentSpan> first_non_skippable_span_after(const TextPosition&) const; - void add_to_undo_stack(NonnullOwnPtr<GTextDocumentUndoCommand>); + void add_to_undo_stack(NonnullOwnPtr<TextDocumentUndoCommand>); bool can_undo() const { return m_undo_stack.can_undo(); } bool can_redo() const { return m_undo_stack.can_redo(); } @@ -128,46 +130,46 @@ public: void redo(); void notify_did_change(); - void set_all_cursors(const GTextPosition&); + void set_all_cursors(const TextPosition&); - GTextPosition insert_at(const GTextPosition&, char, const Client* = nullptr); - GTextPosition insert_at(const GTextPosition&, const StringView&, const Client* = nullptr); - void remove(const GTextRange&); + TextPosition insert_at(const TextPosition&, char, const Client* = nullptr); + TextPosition insert_at(const TextPosition&, const StringView&, const Client* = nullptr); + void remove(const TextRange&); private: - explicit GTextDocument(Client* client); + explicit TextDocument(Client* client); void update_undo_timer(); - NonnullOwnPtrVector<GTextDocumentLine> m_lines; - Vector<GTextDocumentSpan> m_spans; + NonnullOwnPtrVector<TextDocumentLine> m_lines; + Vector<TextDocumentSpan> m_spans; HashTable<Client*> m_clients; bool m_client_notifications_enabled { true }; - GUndoStack m_undo_stack; + UndoStack m_undo_stack; RefPtr<Core::Timer> m_undo_timer; }; -class GTextDocumentLine { +class TextDocumentLine { friend class GTextEditor; - friend class GTextDocument; + friend class TextDocument; public: - explicit GTextDocumentLine(GTextDocument&); - explicit GTextDocumentLine(GTextDocument&, const StringView&); + explicit TextDocumentLine(TextDocument&); + explicit TextDocumentLine(TextDocument&, const StringView&); StringView view() const { return { characters(), (size_t)length() }; } const char* characters() const { return m_text.data(); } size_t length() const { return (size_t)m_text.size() - 1; } - void set_text(GTextDocument&, const StringView&); - void append(GTextDocument&, char); - void prepend(GTextDocument&, char); - void insert(GTextDocument&, size_t index, char); - void remove(GTextDocument&, size_t index); - void append(GTextDocument&, const char*, size_t); - void truncate(GTextDocument&, size_t length); - void clear(GTextDocument&); + void set_text(TextDocument&, const StringView&); + void append(TextDocument&, char); + void prepend(TextDocument&, char); + void insert(TextDocument&, size_t index, char); + void remove(TextDocument&, size_t index); + void append(TextDocument&, const char*, size_t); + void truncate(TextDocument&, size_t length); + void clear(TextDocument&); size_t first_non_whitespace_column() const; private: @@ -175,12 +177,12 @@ private: Vector<char> m_text; }; -class GTextDocumentUndoCommand : public GCommand { +class TextDocumentUndoCommand : public Command { public: - GTextDocumentUndoCommand(GTextDocument&); - virtual ~GTextDocumentUndoCommand(); + TextDocumentUndoCommand(TextDocument&); + virtual ~TextDocumentUndoCommand(); - void execute_from(const GTextDocument::Client& client) + void execute_from(const TextDocument::Client& client) { m_client = &client; redo(); @@ -188,28 +190,30 @@ public: } protected: - GTextDocument& m_document; - const GTextDocument::Client* m_client { nullptr }; + TextDocument& m_document; + const TextDocument::Client* m_client { nullptr }; }; -class InsertTextCommand : public GTextDocumentUndoCommand { +class InsertTextCommand : public TextDocumentUndoCommand { public: - InsertTextCommand(GTextDocument&, const String&, const GTextPosition&); + InsertTextCommand(TextDocument&, const String&, const TextPosition&); virtual void undo() override; virtual void redo() override; private: String m_text; - GTextRange m_range; + TextRange m_range; }; -class RemoveTextCommand : public GTextDocumentUndoCommand { +class RemoveTextCommand : public TextDocumentUndoCommand { public: - RemoveTextCommand(GTextDocument&, const String&, const GTextRange&); + RemoveTextCommand(TextDocument&, const String&, const TextRange&); virtual void undo() override; virtual void redo() override; private: String m_text; - GTextRange m_range; + TextRange m_range; }; + +} diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index 50f162322f..846db4156c 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -44,18 +44,20 @@ //#define DEBUG_GTEXTEDITOR -GTextEditor::GTextEditor(GWidget* parent) - : GTextEditor(Type::MultiLine, parent) +namespace GUI { + +TextEditor::TextEditor(Widget* parent) + : TextEditor(Type::MultiLine, parent) { } -GTextEditor::GTextEditor(Type type, GWidget* parent) - : GScrollableWidget(parent) +TextEditor::TextEditor(Type type, Widget* parent) + : ScrollableWidget(parent) , m_type(type) { set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); - set_document(GTextDocument::create()); + set_document(TextDocument::create()); set_frame_shape(FrameShape::Container); set_frame_shadow(FrameShadow::Sunken); set_frame_thickness(2); @@ -67,27 +69,27 @@ GTextEditor::GTextEditor(Type type, GWidget* parent) create_actions(); } -GTextEditor::~GTextEditor() +TextEditor::~TextEditor() { if (m_document) m_document->unregister_client(*this); } -void GTextEditor::create_actions() +void TextEditor::create_actions() { - m_undo_action = GCommonActions::make_undo_action([&](auto&) { undo(); }, this); - m_redo_action = GCommonActions::make_redo_action([&](auto&) { redo(); }, this); + m_undo_action = CommonActions::make_undo_action([&](auto&) { undo(); }, this); + m_redo_action = CommonActions::make_redo_action([&](auto&) { redo(); }, this); m_undo_action->set_enabled(false); m_redo_action->set_enabled(false); - m_cut_action = GCommonActions::make_cut_action([&](auto&) { cut(); }, this); - m_copy_action = GCommonActions::make_copy_action([&](auto&) { copy(); }, this); - m_paste_action = GCommonActions::make_paste_action([&](auto&) { paste(); }, this); - m_delete_action = GCommonActions::make_delete_action([&](auto&) { do_delete(); }, this); - m_go_to_line_action = GAction::create( + m_cut_action = CommonActions::make_cut_action([&](auto&) { cut(); }, this); + m_copy_action = CommonActions::make_copy_action([&](auto&) { copy(); }, this); + m_paste_action = CommonActions::make_paste_action([&](auto&) { paste(); }, this); + m_delete_action = CommonActions::make_delete_action([&](auto&) { do_delete(); }, this); + m_go_to_line_action = Action::create( "Go to line...", { Mod_Ctrl, Key_L }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) { - auto input_box = GInputBox::construct("Line:", "Go to line", window()); + auto input_box = InputBox::construct("Line:", "Go to line", window()); auto result = input_box->exec(); - if (result == GInputBox::ExecOK) { + if (result == InputBox::ExecOK) { bool ok; auto line_number = input_box->text_value().to_uint(ok); if (ok) @@ -97,7 +99,7 @@ void GTextEditor::create_actions() this); } -void GTextEditor::set_text(const StringView& text) +void TextEditor::set_text(const StringView& text) { if (is_single_line() && text.length() == line(0).length() && !memcmp(text.characters_without_null_termination(), line(0).characters(), text.length())) return; @@ -116,7 +118,7 @@ void GTextEditor::set_text(const StringView& text) update(); } -void GTextEditor::update_content_size() +void TextEditor::update_content_size() { int content_width = 0; int content_height = 0; @@ -132,7 +134,7 @@ void GTextEditor::update_content_size() set_size_occupied_by_fixed_elements({ ruler_width(), 0 }); } -GTextPosition GTextEditor::text_position_at(const Point& a_position) const +TextPosition TextEditor::text_position_at(const Point& a_position) const { auto position = a_position; position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); @@ -184,9 +186,9 @@ GTextPosition GTextEditor::text_position_at(const Point& a_position) const return { line_index, column_index }; } -void GTextEditor::doubleclick_event(GMouseEvent& event) +void TextEditor::doubleclick_event(MouseEvent& event) { - if (event.button() != GMouseButton::Left) + if (event.button() != MouseButton::Left) return; // NOTE: This ensures that spans are updated before we look at them. @@ -228,26 +230,26 @@ void GTextEditor::doubleclick_event(GMouseEvent& event) did_update_selection(); } -void GTextEditor::mousedown_event(GMouseEvent& event) +void TextEditor::mousedown_event(MouseEvent& event) { - if (event.button() != GMouseButton::Left) { + if (event.button() != MouseButton::Left) { return; } if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) { m_triple_click_timer = Core::ElapsedTimer(); - GTextPosition start; - GTextPosition end; + TextPosition start; + TextPosition end; if (is_multi_line()) { // select *current* line - start = GTextPosition(m_cursor.line(), 0); - end = GTextPosition(m_cursor.line(), line(m_cursor.line()).length()); + start = TextPosition(m_cursor.line(), 0); + end = TextPosition(m_cursor.line(), line(m_cursor.line()).length()); } else { // select *whole* line - start = GTextPosition(0, 0); - end = GTextPosition(line_count() - 1, line(line_count() - 1).length()); + start = TextPosition(0, 0); + end = TextPosition(line_count() - 1, line(line_count() - 1).length()); } m_selection.set(start, end); @@ -279,9 +281,9 @@ void GTextEditor::mousedown_event(GMouseEvent& event) did_update_selection(); } -void GTextEditor::mouseup_event(GMouseEvent& event) +void TextEditor::mouseup_event(MouseEvent& event) { - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { if (m_in_drag_select) { m_in_drag_select = false; } @@ -289,7 +291,7 @@ void GTextEditor::mouseup_event(GMouseEvent& event) } } -void GTextEditor::mousemove_event(GMouseEvent& event) +void TextEditor::mousemove_event(MouseEvent& event) { if (m_in_drag_select) { set_cursor(text_position_at(event.position())); @@ -300,7 +302,7 @@ void GTextEditor::mousemove_event(GMouseEvent& event) } } -int GTextEditor::ruler_width() const +int TextEditor::ruler_width() const { if (!m_ruler_visible) return 0; @@ -308,7 +310,7 @@ int GTextEditor::ruler_width() const return 5 * font().glyph_width('x') + 4; } -Rect GTextEditor::ruler_content_rect(size_t line_index) const +Rect TextEditor::ruler_content_rect(size_t line_index) const { if (!m_ruler_visible) return {}; @@ -320,12 +322,12 @@ Rect GTextEditor::ruler_content_rect(size_t line_index) const }; } -Rect GTextEditor::ruler_rect_in_inner_coordinates() const +Rect TextEditor::ruler_rect_in_inner_coordinates() const { return { 0, 0, ruler_width(), height() - height_occupied_by_horizontal_scrollbar() }; } -Rect GTextEditor::visible_text_rect_in_inner_coordinates() const +Rect TextEditor::visible_text_rect_in_inner_coordinates() const { return { m_horizontal_content_padding + (m_ruler_visible ? (ruler_rect_in_inner_coordinates().right() + 1) : 0), @@ -335,15 +337,15 @@ Rect GTextEditor::visible_text_rect_in_inner_coordinates() const }; } -void GTextEditor::paint_event(GPaintEvent& event) +void TextEditor::paint_event(PaintEvent& event) { Color widget_background_color = palette().color(background_role()); // NOTE: This ensures that spans are updated before we look at them. flush_pending_change_notification_if_needed(); - GFrame::paint_event(event); + Frame::paint_event(event); - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(widget_inner_rect()); painter.add_clip_rect(event.rect()); painter.fill_rect(event.rect(), widget_background_color); @@ -426,7 +428,7 @@ void GTextEditor::paint_event(GPaintEvent& event) const Font* font = &this->font(); Color color; Optional<Color> background_color; - GTextPosition physical_position(line_index, start_of_visual_line + i); + TextPosition physical_position(line_index, start_of_visual_line + i); // FIXME: This is *horribly* inefficient. for (auto& span : document().spans()) { if (!span.range.contains(physical_position)) @@ -489,7 +491,7 @@ void GTextEditor::paint_event(GPaintEvent& event) painter.fill_rect(cursor_content_rect(), Color::Red); } -void GTextEditor::toggle_selection_if_needed_for_event(const GKeyEvent& event) +void TextEditor::toggle_selection_if_needed_for_event(const KeyEvent& event) { if (event.shift() && !m_selection.is_valid()) { m_selection.set(m_cursor, {}); @@ -505,17 +507,17 @@ void GTextEditor::toggle_selection_if_needed_for_event(const GKeyEvent& event) } } -void GTextEditor::select_all() +void TextEditor::select_all() { - GTextPosition start_of_document { 0, 0 }; - GTextPosition end_of_document { line_count() - 1, line(line_count() - 1).length() }; + TextPosition start_of_document { 0, 0 }; + TextPosition end_of_document { line_count() - 1, line(line_count() - 1).length() }; m_selection.set(start_of_document, end_of_document); did_update_selection(); set_cursor(end_of_document); update(); } -void GTextEditor::get_selection_line_boundaries(size_t& first_line, size_t& last_line) +void TextEditor::get_selection_line_boundaries(size_t& first_line, size_t& last_line) { auto selection = normalized_selection(); if (!selection.is_valid()) { @@ -529,7 +531,7 @@ void GTextEditor::get_selection_line_boundaries(size_t& first_line, size_t& last last_line -= 1; } -void GTextEditor::move_selected_lines_up() +void TextEditor::move_selected_lines_up() { size_t first_line; size_t last_line; @@ -551,7 +553,7 @@ void GTextEditor::move_selected_lines_up() update(); } -void GTextEditor::move_selected_lines_down() +void TextEditor::move_selected_lines_down() { size_t first_line; size_t last_line; @@ -573,7 +575,7 @@ void GTextEditor::move_selected_lines_down() update(); } -void GTextEditor::sort_selected_lines() +void TextEditor::sort_selected_lines() { if (is_readonly()) return; @@ -598,10 +600,10 @@ void GTextEditor::sort_selected_lines() update(); } -void GTextEditor::keydown_event(GKeyEvent& event) +void TextEditor::keydown_event(KeyEvent& event) { if (is_single_line() && event.key() == KeyCode::Key_Tab) - return GWidget::keydown_event(event); + return Widget::keydown_event(event); if (is_single_line() && event.key() == KeyCode::Key_Return) { if (on_return_pressed) @@ -679,8 +681,8 @@ void GTextEditor::keydown_event(GKeyEvent& event) if (event.ctrl() && document().has_spans()) { // FIXME: Do something nice when the document has no spans. auto span = document().first_non_skippable_span_before(m_cursor); - GTextPosition new_cursor = !span.has_value() - ? GTextPosition(0, 0) + TextPosition new_cursor = !span.has_value() + ? TextPosition(0, 0) : span.value().range.start(); toggle_selection_if_needed_for_event(event); set_cursor(new_cursor); @@ -714,7 +716,7 @@ void GTextEditor::keydown_event(GKeyEvent& event) if (event.ctrl() && document().has_spans()) { // FIXME: Do something nice when the document has no spans. auto span = document().first_non_skippable_span_after(m_cursor); - GTextPosition new_cursor = !span.has_value() + TextPosition new_cursor = !span.has_value() ? document().spans().last().range.end() : span.value().range.start(); toggle_selection_if_needed_for_event(event); @@ -810,7 +812,7 @@ void GTextEditor::keydown_event(GKeyEvent& event) } // Backspace within line - GTextRange erased_range({ m_cursor.line(), m_cursor.column() - erase_count }, m_cursor); + TextRange erased_range({ m_cursor.line(), m_cursor.column() - erase_count }, m_cursor); auto erased_text = document().text_in_range(erased_range); execute<RemoveTextCommand>(erased_text, erased_range); return; @@ -818,7 +820,7 @@ void GTextEditor::keydown_event(GKeyEvent& event) if (m_cursor.column() == 0 && m_cursor.line() != 0) { // Backspace at column 0; merge with previous line size_t previous_length = line(m_cursor.line() - 1).length(); - GTextRange erased_range({ m_cursor.line() - 1, previous_length }, m_cursor); + TextRange erased_range({ m_cursor.line() - 1, previous_length }, m_cursor); execute<RemoveTextCommand>("\n", erased_range); return; } @@ -843,13 +845,13 @@ void GTextEditor::keydown_event(GKeyEvent& event) insert_at_cursor_or_replace_selection(event.text()); } -void GTextEditor::delete_current_line() +void TextEditor::delete_current_line() { if (has_selection()) return delete_selection(); - GTextPosition start; - GTextPosition end; + TextPosition start; + TextPosition end; if (m_cursor.line() == 0 && line_count() == 1) { start = { 0, 0 }; end = { 0, line(0).length() }; @@ -861,11 +863,11 @@ void GTextEditor::delete_current_line() end = { m_cursor.line() + 1, 0 }; } - GTextRange erased_range(start, end); + TextRange erased_range(start, end); execute<RemoveTextCommand>(document().text_in_range(erased_range), erased_range); } -void GTextEditor::do_delete() +void TextEditor::do_delete() { if (is_readonly()) return; @@ -875,19 +877,19 @@ void GTextEditor::do_delete() if (m_cursor.column() < current_line().length()) { // Delete within line - GTextRange erased_range(m_cursor, { m_cursor.line(), m_cursor.column() + 1 }); + TextRange erased_range(m_cursor, { m_cursor.line(), m_cursor.column() + 1 }); execute<RemoveTextCommand>(document().text_in_range(erased_range), erased_range); return; } if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) { // Delete at end of line; merge with next line - GTextRange erased_range(m_cursor, { m_cursor.line() + 1, 0 }); + TextRange erased_range(m_cursor, { m_cursor.line() + 1, 0 }); execute<RemoveTextCommand>(document().text_in_range(erased_range), erased_range); return; } } -int GTextEditor::content_x_for_position(const GTextPosition& position) const +int TextEditor::content_x_for_position(const TextPosition& position) const { auto& line = this->line(position.line()); int x_offset = -1; @@ -910,7 +912,7 @@ int GTextEditor::content_x_for_position(const GTextPosition& position) const } } -Rect GTextEditor::content_rect_for_position(const GTextPosition& position) const +Rect TextEditor::content_rect_for_position(const TextPosition& position) const { if (!position.is_valid()) return {}; @@ -943,12 +945,12 @@ Rect GTextEditor::content_rect_for_position(const GTextPosition& position) const return rect; } -Rect GTextEditor::cursor_content_rect() const +Rect TextEditor::cursor_content_rect() const { return content_rect_for_position(m_cursor); } -Rect GTextEditor::line_widget_rect(size_t line_index) const +Rect TextEditor::line_widget_rect(size_t line_index) const { auto rect = line_content_rect(line_index); rect.set_x(frame_thickness()); @@ -959,7 +961,7 @@ Rect GTextEditor::line_widget_rect(size_t line_index) const return rect; } -void GTextEditor::scroll_position_into_view(const GTextPosition& position) +void TextEditor::scroll_position_into_view(const TextPosition& position) { auto rect = content_rect_for_position(position); if (position.column() == 0) @@ -969,12 +971,12 @@ void GTextEditor::scroll_position_into_view(const GTextPosition& position) scroll_into_view(rect, true, true); } -void GTextEditor::scroll_cursor_into_view() +void TextEditor::scroll_cursor_into_view() { scroll_position_into_view(m_cursor); } -Rect GTextEditor::line_content_rect(size_t line_index) const +Rect TextEditor::line_content_rect(size_t line_index) const { auto& line = this->line(line_index); if (is_single_line()) { @@ -992,21 +994,21 @@ Rect GTextEditor::line_content_rect(size_t line_index) const }; } -void GTextEditor::update_cursor() +void TextEditor::update_cursor() { update(line_widget_rect(m_cursor.line())); } -void GTextEditor::set_cursor(size_t line, size_t column) +void TextEditor::set_cursor(size_t line, size_t column) { set_cursor({ line, column }); } -void GTextEditor::set_cursor(const GTextPosition& a_position) +void TextEditor::set_cursor(const TextPosition& a_position) { ASSERT(!lines().is_empty()); - GTextPosition position = a_position; + TextPosition position = a_position; if (position.line() >= line_count()) position.set_line(line_count() - 1); @@ -1030,25 +1032,25 @@ void GTextEditor::set_cursor(const GTextPosition& a_position) on_cursor_change(); } -void GTextEditor::focusin_event(Core::Event&) +void TextEditor::focusin_event(Core::Event&) { update_cursor(); start_timer(500); } -void GTextEditor::focusout_event(Core::Event&) +void TextEditor::focusout_event(Core::Event&) { stop_timer(); } -void GTextEditor::timer_event(Core::TimerEvent&) +void TextEditor::timer_event(Core::TimerEvent&) { m_cursor_state = !m_cursor_state; if (is_focused()) update_cursor(); } -bool GTextEditor::write_to_file(const StringView& path) +bool TextEditor::write_to_file(const StringView& path) { int fd = open_with_path_length(path.characters_without_null_termination(), path.length(), O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { @@ -1094,7 +1096,7 @@ bool GTextEditor::write_to_file(const StringView& path) return true; } -String GTextEditor::text() const +String TextEditor::text() const { StringBuilder builder; for (size_t i = 0; i < line_count(); ++i) { @@ -1106,17 +1108,17 @@ String GTextEditor::text() const return builder.to_string(); } -void GTextEditor::clear() +void TextEditor::clear() { document().remove_all_lines(); - document().append_line(make<GTextDocumentLine>(document())); + document().append_line(make<TextDocumentLine>(document())); m_selection.clear(); did_update_selection(); set_cursor(0, 0); update(); } -String GTextEditor::selected_text() const +String TextEditor::selected_text() const { if (!has_selection()) return {}; @@ -1124,7 +1126,7 @@ String GTextEditor::selected_text() const return document().text_in_range(m_selection); } -void GTextEditor::delete_selection() +void TextEditor::delete_selection() { auto selection = normalized_selection(); execute<RemoveTextCommand>(selected_text(), selection); @@ -1135,7 +1137,7 @@ void GTextEditor::delete_selection() update(); } -void GTextEditor::insert_at_cursor_or_replace_selection(const StringView& text) +void TextEditor::insert_at_cursor_or_replace_selection(const StringView& text) { ASSERT(!is_readonly()); if (has_selection()) @@ -1143,47 +1145,47 @@ void GTextEditor::insert_at_cursor_or_replace_selection(const StringView& text) execute<InsertTextCommand>(text, m_cursor); } -void GTextEditor::cut() +void TextEditor::cut() { if (is_readonly()) return; auto selected_text = this->selected_text(); printf("Cut: \"%s\"\n", selected_text.characters()); - GClipboard::the().set_data(selected_text); + Clipboard::the().set_data(selected_text); delete_selection(); } -void GTextEditor::copy() +void TextEditor::copy() { auto selected_text = this->selected_text(); printf("Copy: \"%s\"\n", selected_text.characters()); - GClipboard::the().set_data(selected_text); + Clipboard::the().set_data(selected_text); } -void GTextEditor::paste() +void TextEditor::paste() { if (is_readonly()) return; - auto paste_text = GClipboard::the().data(); + auto paste_text = Clipboard::the().data(); printf("Paste: \"%s\"\n", paste_text.characters()); TemporaryChange change(m_automatic_indentation_enabled, false); insert_at_cursor_or_replace_selection(paste_text); } -void GTextEditor::enter_event(Core::Event&) +void TextEditor::enter_event(Core::Event&) { ASSERT(window()); - window()->set_override_cursor(GStandardCursor::IBeam); + window()->set_override_cursor(StandardCursor::IBeam); } -void GTextEditor::leave_event(Core::Event&) +void TextEditor::leave_event(Core::Event&) { ASSERT(window()); - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(StandardCursor::None); } -void GTextEditor::did_change() +void TextEditor::did_change() { update_content_size(); recompute_all_visual_lines(); @@ -1201,7 +1203,7 @@ void GTextEditor::did_change() } } -void GTextEditor::set_readonly(bool readonly) +void TextEditor::set_readonly(bool readonly) { if (m_readonly == readonly) return; @@ -1211,7 +1213,7 @@ void GTextEditor::set_readonly(bool readonly) m_paste_action->set_enabled(!is_readonly()); } -void GTextEditor::did_update_selection() +void TextEditor::did_update_selection() { m_cut_action->set_enabled(!is_readonly() && has_selection()); m_copy_action->set_enabled(has_selection()); @@ -1223,10 +1225,10 @@ void GTextEditor::did_update_selection() } } -void GTextEditor::context_menu_event(GContextMenuEvent& event) +void TextEditor::context_menu_event(ContextMenuEvent& event) { if (!m_context_menu) { - m_context_menu = GMenu::construct(); + m_context_menu = Menu::construct(); m_context_menu->add_action(undo_action()); m_context_menu->add_action(redo_action()); m_context_menu->add_separator(); @@ -1248,7 +1250,7 @@ void GTextEditor::context_menu_event(GContextMenuEvent& event) m_context_menu->popup(event.screen_position()); } -void GTextEditor::set_text_alignment(TextAlignment alignment) +void TextEditor::set_text_alignment(TextAlignment alignment) { if (m_text_alignment == alignment) return; @@ -1256,14 +1258,14 @@ void GTextEditor::set_text_alignment(TextAlignment alignment) update(); } -void GTextEditor::resize_event(GResizeEvent& event) +void TextEditor::resize_event(ResizeEvent& event) { - GScrollableWidget::resize_event(event); + ScrollableWidget::resize_event(event); update_content_size(); recompute_all_visual_lines(); } -void GTextEditor::set_selection(const GTextRange& selection) +void TextEditor::set_selection(const TextRange& selection) { if (m_selection == selection) return; @@ -1273,7 +1275,7 @@ void GTextEditor::set_selection(const GTextRange& selection) update(); } -void GTextEditor::clear_selection() +void TextEditor::clear_selection() { if (!has_selection()) return; @@ -1281,7 +1283,7 @@ void GTextEditor::clear_selection() update(); } -void GTextEditor::recompute_all_visual_lines() +void TextEditor::recompute_all_visual_lines() { int y_offset = 0; for (size_t line_index = 0; line_index < line_count(); ++line_index) { @@ -1293,7 +1295,7 @@ void GTextEditor::recompute_all_visual_lines() update_content_size(); } -void GTextEditor::ensure_cursor_is_valid() +void TextEditor::ensure_cursor_is_valid() { auto new_cursor = m_cursor; if (new_cursor.line() >= line_count()) @@ -1304,7 +1306,7 @@ void GTextEditor::ensure_cursor_is_valid() set_cursor(new_cursor); } -size_t GTextEditor::visual_line_containing(size_t line_index, size_t column) const +size_t TextEditor::visual_line_containing(size_t line_index, size_t column) const { size_t visual_line_index = 0; for_each_visual_line(line_index, [&](const Rect&, const StringView& view, size_t start_of_visual_line) { @@ -1316,7 +1318,7 @@ size_t GTextEditor::visual_line_containing(size_t line_index, size_t column) con return visual_line_index; } -void GTextEditor::recompute_visual_lines(size_t line_index) +void TextEditor::recompute_visual_lines(size_t line_index) { auto& line = document().line(line_index); auto& visual_data = m_line_visual_data[line_index]; @@ -1349,7 +1351,7 @@ void GTextEditor::recompute_visual_lines(size_t line_index) } template<typename Callback> -void GTextEditor::for_each_visual_line(size_t line_index, Callback callback) const +void TextEditor::for_each_visual_line(size_t line_index, Callback callback) const { auto editor_visible_text_rect = visible_text_rect_in_inner_coordinates(); size_t start_of_line = 0; @@ -1377,7 +1379,7 @@ void GTextEditor::for_each_visual_line(size_t line_index, Callback callback) con } } -void GTextEditor::set_line_wrapping_enabled(bool enabled) +void TextEditor::set_line_wrapping_enabled(bool enabled) { if (m_line_wrapping_enabled == enabled) return; @@ -1389,54 +1391,54 @@ void GTextEditor::set_line_wrapping_enabled(bool enabled) update(); } -void GTextEditor::add_custom_context_menu_action(GAction& action) +void TextEditor::add_custom_context_menu_action(Action& action) { m_custom_context_menu_actions.append(action); } -void GTextEditor::did_change_font() +void TextEditor::did_change_font() { vertical_scrollbar().set_step(line_height()); recompute_all_visual_lines(); update(); - GWidget::did_change_font(); + Widget::did_change_font(); } -void GTextEditor::document_did_append_line() +void TextEditor::document_did_append_line() { m_line_visual_data.append(make<LineVisualData>()); recompute_all_visual_lines(); update(); } -void GTextEditor::document_did_remove_line(size_t line_index) +void TextEditor::document_did_remove_line(size_t line_index) { m_line_visual_data.remove(line_index); recompute_all_visual_lines(); update(); } -void GTextEditor::document_did_remove_all_lines() +void TextEditor::document_did_remove_all_lines() { m_line_visual_data.clear(); recompute_all_visual_lines(); update(); } -void GTextEditor::document_did_insert_line(size_t line_index) +void TextEditor::document_did_insert_line(size_t line_index) { m_line_visual_data.insert(line_index, make<LineVisualData>()); recompute_all_visual_lines(); update(); } -void GTextEditor::document_did_change() +void TextEditor::document_did_change() { did_change(); update(); } -void GTextEditor::document_did_set_text() +void TextEditor::document_did_set_text() { m_line_visual_data.clear(); for (size_t i = 0; i < m_document->line_count(); ++i) @@ -1444,12 +1446,12 @@ void GTextEditor::document_did_set_text() document_did_change(); } -void GTextEditor::document_did_set_cursor(const GTextPosition& position) +void TextEditor::document_did_set_cursor(const TextPosition& position) { set_cursor(position); } -void GTextEditor::set_document(GTextDocument& document) +void TextEditor::set_document(TextDocument& document) { if (m_document.ptr() == &document) return; @@ -1468,7 +1470,7 @@ void GTextEditor::set_document(GTextDocument& document) m_document->register_client(*this); } -void GTextEditor::flush_pending_change_notification_if_needed() +void TextEditor::flush_pending_change_notification_if_needed() { if (!m_has_pending_change_notification) return; @@ -1476,3 +1478,5 @@ void GTextEditor::flush_pending_change_notification_if_needed() on_change(); m_has_pending_change_notification = false; } + +} diff --git a/Libraries/LibGUI/GTextEditor.h b/Libraries/LibGUI/GTextEditor.h index 8c67fce7b5..a2cf26e293 100644 --- a/Libraries/LibGUI/GTextEditor.h +++ b/Libraries/LibGUI/GTextEditor.h @@ -36,26 +36,28 @@ #include <LibGUI/GTextDocument.h> #include <LibGUI/GTextRange.h> -class GAction; -class GMenu; -class GScrollBar; +namespace GUI { + +class Action; +class Menu; class Painter; +class ScrollBar; -class GTextEditor - : public GScrollableWidget - , public GTextDocument::Client { - C_OBJECT(GTextEditor) +class TextEditor + : public ScrollableWidget + , public TextDocument::Client { + C_OBJECT(TextEditor) public: enum Type { MultiLine, SingleLine }; - virtual ~GTextEditor() override; + virtual ~TextEditor() override; - const GTextDocument& document() const { return *m_document; } - GTextDocument& document() { return *m_document; } + const TextDocument& document() const { return *m_document; } + TextDocument& document() { return *m_document; } - void set_document(GTextDocument&); + void set_document(TextDocument&); bool is_readonly() const { return m_readonly; } void set_readonly(bool); @@ -83,12 +85,12 @@ public: void set_text(const StringView&); void scroll_cursor_into_view(); - void scroll_position_into_view(const GTextPosition&); + void scroll_position_into_view(const TextPosition&); size_t line_count() const { return document().line_count(); } int line_spacing() const { return m_line_spacing; } int line_height() const { return font().glyph_height() + m_line_spacing; } - GTextPosition cursor() const { return m_cursor; } - GTextRange normalized_selection() const { return m_selection.normalized(); } + TextPosition cursor() const { return m_cursor; } + TextRange normalized_selection() const { return m_selection.normalized(); } // FIXME: This should take glyph spacing into account, no? int glyph_width() const { return font().glyph_width('x'); } @@ -96,7 +98,7 @@ public: bool write_to_file(const StringView& path); bool has_selection() const { return m_selection.is_valid(); } String selected_text() const; - void set_selection(const GTextRange&); + void set_selection(const TextRange&); void clear_selection(); bool can_undo() const { return document().can_undo(); } bool can_redo() const { return document().can_redo(); } @@ -118,53 +120,53 @@ public: Function<void()> on_return_pressed; Function<void()> on_escape_pressed; - GAction& undo_action() { return *m_undo_action; } - GAction& redo_action() { return *m_redo_action; } - GAction& cut_action() { return *m_cut_action; } - GAction& copy_action() { return *m_copy_action; } - GAction& paste_action() { return *m_paste_action; } - GAction& delete_action() { return *m_delete_action; } - GAction& go_to_line_action() { return *m_go_to_line_action; } + Action& undo_action() { return *m_undo_action; } + Action& redo_action() { return *m_redo_action; } + Action& cut_action() { return *m_cut_action; } + Action& copy_action() { return *m_copy_action; } + Action& paste_action() { return *m_paste_action; } + Action& delete_action() { return *m_delete_action; } + Action& go_to_line_action() { return *m_go_to_line_action; } - void add_custom_context_menu_action(GAction&); + void add_custom_context_menu_action(Action&); void set_cursor(size_t line, size_t column); - void set_cursor(const GTextPosition&); + void set_cursor(const TextPosition&); protected: - explicit GTextEditor(GWidget* parent); - explicit GTextEditor(Type, GWidget* parent); + explicit TextEditor(Widget* parent); + explicit TextEditor(Type, Widget* parent); virtual void did_change_font() override; - virtual void paint_event(GPaintEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void doubleclick_event(GMouseEvent&) override; - virtual void keydown_event(GKeyEvent&) override; + virtual void paint_event(PaintEvent&) override; + virtual void mousedown_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; + virtual void doubleclick_event(MouseEvent&) override; + virtual void keydown_event(KeyEvent&) override; virtual void focusin_event(Core::Event&) override; virtual void focusout_event(Core::Event&) override; virtual void timer_event(Core::TimerEvent&) override; virtual bool accepts_focus() const override { return true; } virtual void enter_event(Core::Event&) override; virtual void leave_event(Core::Event&) override; - virtual void context_menu_event(GContextMenuEvent&) override; - virtual void resize_event(GResizeEvent&) override; + virtual void context_menu_event(ContextMenuEvent&) override; + virtual void resize_event(ResizeEvent&) override; virtual void cursor_did_change() {} - GTextPosition text_position_at(const Point&) const; + TextPosition text_position_at(const Point&) const; private: - friend class GTextDocumentLine; + friend class TextDocumentLine; - // ^GTextDocument::Client + // ^TextDocument::Client virtual void document_did_append_line() override; virtual void document_did_insert_line(size_t) override; virtual void document_did_remove_line(size_t) override; virtual void document_did_remove_all_lines() override; virtual void document_did_change() override; virtual void document_did_set_text() override; - virtual void document_did_set_cursor(const GTextPosition&) override; + virtual void document_did_set_cursor(const TextPosition&) override; void create_actions(); void paint_ruler(Painter&); @@ -174,20 +176,20 @@ private: Rect line_content_rect(size_t item_index) const; Rect line_widget_rect(size_t line_index) const; Rect cursor_content_rect() const; - Rect content_rect_for_position(const GTextPosition&) const; + Rect content_rect_for_position(const TextPosition&) const; void update_cursor(); - const NonnullOwnPtrVector<GTextDocumentLine>& lines() const { return document().lines(); } - NonnullOwnPtrVector<GTextDocumentLine>& lines() { return document().lines(); } - GTextDocumentLine& line(size_t index) { return document().line(index); } - const GTextDocumentLine& line(size_t index) const { return document().line(index); } - GTextDocumentLine& current_line() { return line(m_cursor.line()); } - const GTextDocumentLine& current_line() const { return line(m_cursor.line()); } + const NonnullOwnPtrVector<TextDocumentLine>& lines() const { return document().lines(); } + NonnullOwnPtrVector<TextDocumentLine>& lines() { return document().lines(); } + TextDocumentLine& line(size_t index) { return document().line(index); } + const TextDocumentLine& line(size_t index) const { return document().line(index); } + TextDocumentLine& current_line() { return line(m_cursor.line()); } + const TextDocumentLine& current_line() const { return line(m_cursor.line()); } int ruler_width() const; Rect ruler_content_rect(size_t line) const; - void toggle_selection_if_needed_for_event(const GKeyEvent&); + void toggle_selection_if_needed_for_event(const KeyEvent&); void delete_selection(); void did_update_selection(); - int content_x_for_position(const GTextPosition&) const; + int content_x_for_position(const TextPosition&) const; Rect ruler_rect_in_inner_coordinates() const; Rect visible_text_rect_in_inner_coordinates() const; void recompute_all_visual_lines(); @@ -211,7 +213,7 @@ private: Type m_type { MultiLine }; - GTextPosition m_cursor; + TextPosition m_cursor; TextAlignment m_text_alignment { TextAlignment::CenterLeft }; bool m_cursor_state { true }; bool m_in_drag_select { false }; @@ -223,19 +225,19 @@ private: int m_line_spacing { 4 }; size_t m_soft_tab_width { 4 }; int m_horizontal_content_padding { 2 }; - GTextRange m_selection; - RefPtr<GMenu> m_context_menu; - RefPtr<GAction> m_undo_action; - RefPtr<GAction> m_redo_action; - RefPtr<GAction> m_cut_action; - RefPtr<GAction> m_copy_action; - RefPtr<GAction> m_paste_action; - RefPtr<GAction> m_delete_action; - RefPtr<GAction> m_go_to_line_action; + TextRange m_selection; + RefPtr<Menu> m_context_menu; + RefPtr<Action> m_undo_action; + RefPtr<Action> m_redo_action; + RefPtr<Action> m_cut_action; + RefPtr<Action> m_copy_action; + RefPtr<Action> m_paste_action; + RefPtr<Action> m_delete_action; + RefPtr<Action> m_go_to_line_action; Core::ElapsedTimer m_triple_click_timer; - NonnullRefPtrVector<GAction> m_custom_context_menu_actions; + NonnullRefPtrVector<Action> m_custom_context_menu_actions; - RefPtr<GTextDocument> m_document; + RefPtr<TextDocument> m_document; template<typename Callback> void for_each_visual_line(size_t line_index, Callback) const; @@ -247,3 +249,5 @@ private: NonnullOwnPtrVector<LineVisualData> m_line_visual_data; }; + +} diff --git a/Libraries/LibGUI/GTextPosition.h b/Libraries/LibGUI/GTextPosition.h index e60c1354da..86eb5116e7 100644 --- a/Libraries/LibGUI/GTextPosition.h +++ b/Libraries/LibGUI/GTextPosition.h @@ -29,10 +29,12 @@ #include <AK/LogStream.h> #include <AK/String.h> -class GTextPosition { +namespace GUI { + +class TextPosition { public: - GTextPosition() {} - GTextPosition(size_t line, size_t column) + TextPosition() {} + TextPosition(size_t line, size_t column) : m_line(line) , m_column(column) { @@ -46,18 +48,20 @@ public: void set_line(size_t line) { m_line = line; } void set_column(size_t column) { m_column = column; } - bool operator==(const GTextPosition& other) const { return m_line == other.m_line && m_column == other.m_column; } - bool operator!=(const GTextPosition& other) const { return m_line != other.m_line || m_column != other.m_column; } - bool operator<(const GTextPosition& other) const { return m_line < other.m_line || (m_line == other.m_line && m_column < other.m_column); } + bool operator==(const TextPosition& other) const { return m_line == other.m_line && m_column == other.m_column; } + bool operator!=(const TextPosition& other) const { return m_line != other.m_line || m_column != other.m_column; } + bool operator<(const TextPosition& other) const { return m_line < other.m_line || (m_line == other.m_line && m_column < other.m_column); } private: size_t m_line { 0xffffffff }; size_t m_column { 0xffffffff }; }; -inline const LogStream& operator<<(const LogStream& stream, const GTextPosition& value) +inline const LogStream& operator<<(const LogStream& stream, const TextPosition& value) { if (!value.is_valid()) return stream << "GTextPosition(Invalid)"; return stream << String::format("(%zu,%zu)", value.line(), value.column()); } + +} diff --git a/Libraries/LibGUI/GTextRange.h b/Libraries/LibGUI/GTextRange.h index b6241bf456..6d309a7951 100644 --- a/Libraries/LibGUI/GTextRange.h +++ b/Libraries/LibGUI/GTextRange.h @@ -29,10 +29,12 @@ #include <AK/LogStream.h> #include <LibGUI/GTextPosition.h> -class GTextRange { +namespace GUI { + +class TextRange { public: - GTextRange() {} - GTextRange(const GTextPosition& start, const GTextPosition& end) + TextRange() {} + TextRange(const TextPosition& start, const TextPosition& end) : m_start(start) , m_end(end) { @@ -45,28 +47,28 @@ public: m_end = {}; } - GTextPosition& start() { return m_start; } - GTextPosition& end() { return m_end; } - const GTextPosition& start() const { return m_start; } - const GTextPosition& end() const { return m_end; } + TextPosition& start() { return m_start; } + TextPosition& end() { return m_end; } + const TextPosition& start() const { return m_start; } + const TextPosition& end() const { return m_end; } - GTextRange normalized() const { return GTextRange(normalized_start(), normalized_end()); } + TextRange normalized() const { return TextRange(normalized_start(), normalized_end()); } - void set_start(const GTextPosition& position) { m_start = position; } - void set_end(const GTextPosition& position) { m_end = position; } + void set_start(const TextPosition& position) { m_start = position; } + void set_end(const TextPosition& position) { m_end = position; } - void set(const GTextPosition& start, const GTextPosition& end) + void set(const TextPosition& start, const TextPosition& end) { m_start = start; m_end = end; } - bool operator==(const GTextRange& other) const + bool operator==(const TextRange& other) const { return m_start == other.m_start && m_end == other.m_end; } - bool contains(const GTextPosition& position) const + bool contains(const TextPosition& position) const { if (!(position.line() > m_start.line() || (position.line() == m_start.line() && position.column() >= m_start.column()))) return false; @@ -76,16 +78,18 @@ public: } private: - GTextPosition normalized_start() const { return m_start < m_end ? m_start : m_end; } - GTextPosition normalized_end() const { return m_start < m_end ? m_end : m_start; } + TextPosition normalized_start() const { return m_start < m_end ? m_start : m_end; } + TextPosition normalized_end() const { return m_start < m_end ? m_end : m_start; } - GTextPosition m_start; - GTextPosition m_end; + TextPosition m_start; + TextPosition m_end; }; -inline const LogStream& operator<<(const LogStream& stream, const GTextRange& value) +inline const LogStream& operator<<(const LogStream& stream, const TextRange& value) { if (!value.is_valid()) return stream << "GTextRange(Invalid)"; return stream << value.start() << '-' << value.end(); } + +} diff --git a/Libraries/LibGUI/GToolBar.cpp b/Libraries/LibGUI/GToolBar.cpp index acc27c5003..85e2cce8f0 100644 --- a/Libraries/LibGUI/GToolBar.cpp +++ b/Libraries/LibGUI/GToolBar.cpp @@ -32,13 +32,15 @@ #include <LibGUI/GPainter.h> #include <LibGUI/GToolBar.h> -GToolBar::GToolBar(GWidget* parent) - : GToolBar(Orientation::Horizontal, 16, parent) +namespace GUI { + +ToolBar::ToolBar(Widget* parent) + : ToolBar(Orientation::Horizontal, 16, parent) { } -GToolBar::GToolBar(Orientation orientation, int button_size, GWidget* parent) - : GWidget(parent) +ToolBar::ToolBar(Orientation orientation, int button_size, Widget* parent) + : Widget(parent) , m_button_size(button_size) { if (orientation == Orientation::Horizontal) { @@ -48,22 +50,22 @@ GToolBar::GToolBar(Orientation orientation, int button_size, GWidget* parent) set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); set_preferred_size(button_size + 12, 0); } - set_layout(make<GBoxLayout>(orientation)); + set_layout(make<BoxLayout>(orientation)); layout()->set_spacing(0); layout()->set_margins({ 2, 2, 2, 2 }); } -GToolBar::~GToolBar() +ToolBar::~ToolBar() { } -void GToolBar::add_action(GAction& action) +void ToolBar::add_action(Action& action) { auto item = make<Item>(); - item->type = Item::Action; + item->type = Item::Type::Action; item->action = action; - auto button = GButton::construct(this); + auto button = Button::construct(this); if (action.group() && action.group()->is_exclusive()) button->set_exclusive(true); button->set_action(*item->action); @@ -82,20 +84,20 @@ void GToolBar::add_action(GAction& action) m_items.append(move(item)); } -class SeparatorWidget final : public GWidget { +class SeparatorWidget final : public Widget { C_OBJECT(SeparatorWidget) public: - SeparatorWidget(GWidget* parent) - : GWidget(parent) + SeparatorWidget(Widget* parent) + : Widget(parent) { set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); set_preferred_size(8, 22); } virtual ~SeparatorWidget() override {} - virtual void paint_event(GPaintEvent& event) override + virtual void paint_event(PaintEvent& event) override { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); painter.translate(rect().center().x() - 1, 0); painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, palette().threed_shadow1()); @@ -103,17 +105,17 @@ public: } }; -void GToolBar::add_separator() +void ToolBar::add_separator() { auto item = make<Item>(); - item->type = Item::Separator; + item->type = Item::Type::Separator; new SeparatorWidget(this); m_items.append(move(item)); } -void GToolBar::paint_event(GPaintEvent& event) +void ToolBar::paint_event(PaintEvent& event) { - GPainter painter(*this); + Painter painter(*this); painter.add_clip_rect(event.rect()); if (m_has_frame) @@ -121,3 +123,5 @@ void GToolBar::paint_event(GPaintEvent& event) else painter.fill_rect(event.rect(), palette().button()); } + +} diff --git a/Libraries/LibGUI/GToolBar.h b/Libraries/LibGUI/GToolBar.h index c108680b3b..81ebb336a8 100644 --- a/Libraries/LibGUI/GToolBar.h +++ b/Libraries/LibGUI/GToolBar.h @@ -29,36 +29,40 @@ #include <AK/NonnullOwnPtrVector.h> #include <LibGUI/GWidget.h> -class GAction; +namespace GUI { -class GToolBar : public GWidget { - C_OBJECT(GToolBar) +class Action; + +class ToolBar : public Widget { + C_OBJECT(ToolBar) public: - virtual ~GToolBar() override; + virtual ~ToolBar() override; - void add_action(GAction&); + void add_action(Action&); void add_separator(); bool has_frame() const { return m_has_frame; } void set_has_frame(bool has_frame) { m_has_frame = has_frame; } protected: - explicit GToolBar(GWidget* parent); - explicit GToolBar(Orientation, int button_size, GWidget* parent); + explicit ToolBar(Widget* parent); + explicit ToolBar(Orientation, int button_size, Widget* parent); - virtual void paint_event(GPaintEvent&) override; + virtual void paint_event(PaintEvent&) override; private: struct Item { - enum Type { + enum class Type { Invalid, Separator, Action }; - Type type { Invalid }; - RefPtr<GAction> action; + Type type { Type::Invalid }; + RefPtr<Action> action; }; NonnullOwnPtrVector<Item> m_items; int m_button_size { 16 }; bool m_has_frame { true }; }; + +} diff --git a/Libraries/LibGUI/GTreeView.cpp b/Libraries/LibGUI/GTreeView.cpp index 452e46d5ee..5981be7ad4 100644 --- a/Libraries/LibGUI/GTreeView.cpp +++ b/Libraries/LibGUI/GTreeView.cpp @@ -31,11 +31,13 @@ //#define DEBUG_ITEM_RECTS -struct GTreeView::MetadataForIndex { +namespace GUI { + +struct TreeView::MetadataForIndex { bool open { false }; }; -GTreeView::MetadataForIndex& GTreeView::ensure_metadata_for_index(const GModelIndex& index) const +TreeView::MetadataForIndex& TreeView::ensure_metadata_for_index(const ModelIndex& index) const { ASSERT(index.is_valid()); auto it = m_view_metadata.find(index.internal_data()); @@ -47,8 +49,8 @@ GTreeView::MetadataForIndex& GTreeView::ensure_metadata_for_index(const GModelIn return new_metadata_ref; } -GTreeView::GTreeView(GWidget* parent) - : GAbstractTableView(parent) +TreeView::TreeView(Widget* parent) + : AbstractTableView(parent) { set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); @@ -58,18 +60,18 @@ GTreeView::GTreeView(GWidget* parent) m_collapse_bitmap = GraphicsBitmap::load_from_file("/res/icons/treeview-collapse.png"); } -GTreeView::~GTreeView() +TreeView::~TreeView() { } -GModelIndex GTreeView::index_at_event_position(const Point& a_position, bool& is_toggle) const +ModelIndex TreeView::index_at_event_position(const Point& a_position, bool& is_toggle) const { auto position = a_position.translated(0, -header_height()).translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness()); is_toggle = false; if (!model()) return {}; - GModelIndex result; - traverse_in_paint_order([&](const GModelIndex& index, const Rect& rect, const Rect& toggle_rect, int) { + ModelIndex result; + traverse_in_paint_order([&](const ModelIndex& index, const Rect& rect, const Rect& toggle_rect, int) { if (toggle_rect.contains(position)) { result = index; is_toggle = true; @@ -84,7 +86,7 @@ GModelIndex GTreeView::index_at_event_position(const Point& a_position, bool& is return result; } -void GTreeView::doubleclick_event(GMouseEvent& event) +void TreeView::doubleclick_event(MouseEvent& event) { if (!model()) return; @@ -94,7 +96,7 @@ void GTreeView::doubleclick_event(GMouseEvent& event) if (!index.is_valid()) return; - if (event.button() == GMouseButton::Left) { + if (event.button() == MouseButton::Left) { if (selection().first() != index) selection().set(index); @@ -105,7 +107,7 @@ void GTreeView::doubleclick_event(GMouseEvent& event) } } -void GTreeView::toggle_index(const GModelIndex& index) +void TreeView::toggle_index(const ModelIndex& index) { ASSERT(model()->row_count(index)); auto& metadata = ensure_metadata_for_index(index); @@ -116,7 +118,7 @@ void GTreeView::toggle_index(const GModelIndex& index) } template<typename Callback> -void GTreeView::traverse_in_paint_order(Callback callback) const +void TreeView::traverse_in_paint_order(Callback callback) const { ASSERT(model()); auto& model = *this->model(); @@ -130,12 +132,12 @@ void GTreeView::traverse_in_paint_order(Callback callback) const tree_column_x_offset += column_width(i); } - Function<IterationDecision(const GModelIndex&)> traverse_index = [&](const GModelIndex& index) { + Function<IterationDecision(const ModelIndex&)> traverse_index = [&](const ModelIndex& index) { int row_count_at_index = model.row_count(index); if (index.is_valid()) { auto& metadata = ensure_metadata_for_index(index); int x_offset = tree_column_x_offset + horizontal_padding() + indent_level * indent_width_in_pixels(); - auto node_text = model.data(index, GModel::Role::Display).to_string(); + auto node_text = model.data(index, Model::Role::Display).to_string(); Rect rect = { x_offset, y_offset, icon_size() + icon_spacing() + text_padding() + font().width(node_text) + text_padding(), item_height() @@ -165,15 +167,15 @@ void GTreeView::traverse_in_paint_order(Callback callback) const }; int root_count = model.row_count(); for (int root_index = 0; root_index < root_count; ++root_index) { - if (traverse_index(model.index(root_index, model.tree_column(), GModelIndex())) == IterationDecision::Break) + if (traverse_index(model.index(root_index, model.tree_column(), ModelIndex())) == IterationDecision::Break) break; } } -void GTreeView::paint_event(GPaintEvent& event) +void TreeView::paint_event(PaintEvent& event) { - GFrame::paint_event(event); - GPainter painter(*this); + Frame::paint_event(event); + Painter painter(*this); painter.add_clip_rect(frame_inner_rect()); painter.add_clip_rect(event.rect()); painter.fill_rect(event.rect(), palette().color(background_role())); @@ -196,7 +198,7 @@ void GTreeView::paint_event(GPaintEvent& event) int painted_row_index = 0; - traverse_in_paint_order([&](const GModelIndex& index, const Rect& a_rect, const Rect& a_toggle_rect, int indent_level) { + traverse_in_paint_order([&](const ModelIndex& index, const Rect& a_rect, const Rect& a_toggle_rect, int indent_level) { if (!a_rect.intersects_vertically(visible_content_rect)) return IterationDecision::Continue; @@ -257,14 +259,14 @@ void GTreeView::paint_event(GPaintEvent& event) painter.blit(cell_rect.location(), *bitmap, bitmap->rect()); } else { if (!is_selected_row) - text_color = model.data(cell_index, GModel::Role::ForegroundColor).to_color(palette().color(foreground_role())); + text_color = model.data(cell_index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); painter.draw_text(cell_rect, data.to_string(), font, column_metadata.text_alignment, text_color, TextElision::Right); } } } else { // It's the tree column! Rect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() }; - auto icon = model.data(index, GModel::Role::Icon); + auto icon = model.data(index, Model::Role::Icon); if (icon.is_icon()) { if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) painter.blit(icon_rect.location(), *bitmap, bitmap->rect()); @@ -273,7 +275,7 @@ void GTreeView::paint_event(GPaintEvent& event) icon_rect.right() + 1 + icon_spacing(), rect.y(), rect.width() - icon_size() - icon_spacing(), rect.height() }; - auto node_text = model.data(index, GModel::Role::Display).to_string(); + auto node_text = model.data(index, Model::Role::Display).to_string(); painter.draw_text(text_rect, node_text, TextAlignment::Center, text_color); auto index_at_indent = index; for (int i = indent_level; i > 0; --i) { @@ -313,30 +315,30 @@ void GTreeView::paint_event(GPaintEvent& event) paint_headers(painter); } -void GTreeView::scroll_into_view(const GModelIndex& a_index, Orientation orientation) +void TreeView::scroll_into_view(const ModelIndex& a_index, Orientation orientation) { if (!a_index.is_valid()) return; Rect found_rect; - traverse_in_paint_order([&](const GModelIndex& index, const Rect& rect, const Rect&, int) { + traverse_in_paint_order([&](const ModelIndex& index, const Rect& rect, const Rect&, int) { if (index == a_index) { found_rect = rect; return IterationDecision::Break; } return IterationDecision::Continue; }); - GScrollableWidget::scroll_into_view(found_rect, orientation); + ScrollableWidget::scroll_into_view(found_rect, orientation); } -void GTreeView::did_update_model() +void TreeView::did_update_model() { m_view_metadata.clear(); - GAbstractTableView::did_update_model(); + AbstractTableView::did_update_model(); } -void GTreeView::did_update_selection() +void TreeView::did_update_selection() { - GAbstractView::did_update_selection(); + AbstractView::did_update_selection(); ASSERT(model()); auto index = selection().first(); if (!index.is_valid()) @@ -358,7 +360,7 @@ void GTreeView::did_update_selection() activate(index); } -void GTreeView::keydown_event(GKeyEvent& event) +void TreeView::keydown_event(KeyEvent& event) { if (!model()) return; @@ -371,9 +373,9 @@ void GTreeView::keydown_event(GKeyEvent& event) } if (event.key() == KeyCode::Key_Up) { - GModelIndex previous_index; - GModelIndex found_index; - traverse_in_paint_order([&](const GModelIndex& index, const Rect&, const Rect&, int) { + ModelIndex previous_index; + ModelIndex found_index; + traverse_in_paint_order([&](const ModelIndex& index, const Rect&, const Rect&, int) { if (index == cursor_index) { found_index = previous_index; return IterationDecision::Break; @@ -388,9 +390,9 @@ void GTreeView::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Down) { - GModelIndex previous_index; - GModelIndex found_index; - traverse_in_paint_order([&](const GModelIndex& index, const Rect&, const Rect&, int) { + ModelIndex previous_index; + ModelIndex found_index; + traverse_in_paint_order([&](const ModelIndex& index, const Rect&, const Rect&, int) { if (previous_index == cursor_index) { found_index = index; return IterationDecision::Break; @@ -437,17 +439,17 @@ void GTreeView::keydown_event(GKeyEvent& event) } } -int GTreeView::item_count() const +int TreeView::item_count() const { int count = 0; - traverse_in_paint_order([&](const GModelIndex&, const Rect&, const Rect&, int) { + traverse_in_paint_order([&](const ModelIndex&, const Rect&, const Rect&, int) { ++count; return IterationDecision::Continue; }); return count; } -void GTreeView::update_column_sizes() +void TreeView::update_column_sizes() { if (!size_columns_to_fit_content()) return; @@ -489,7 +491,7 @@ void GTreeView::update_column_sizes() int tree_column_header_width = header_font().width(model.column_name(tree_column)); int tree_column_width = tree_column_header_width; - traverse_in_paint_order([&](const GModelIndex&, const Rect& rect, const Rect&, int) { + traverse_in_paint_order([&](const ModelIndex&, const Rect& rect, const Rect&, int) { tree_column_width = max(rect.right() - tree_column_x_offset, tree_column_width); return IterationDecision::Continue; }); @@ -498,3 +500,5 @@ void GTreeView::update_column_sizes() column_data.width = max(column_data.width, tree_column_width); column_data.has_initialized_width = true; } + +} diff --git a/Libraries/LibGUI/GTreeView.h b/Libraries/LibGUI/GTreeView.h index 69e0ee5d39..b30e40a39e 100644 --- a/Libraries/LibGUI/GTreeView.h +++ b/Libraries/LibGUI/GTreeView.h @@ -28,26 +28,28 @@ #include <LibGUI/GAbstractTableView.h> -class GTreeView : public GAbstractTableView { - C_OBJECT(GTreeView) +namespace GUI { + +class TreeView : public AbstractTableView { + C_OBJECT(TreeView) public: - virtual ~GTreeView() override; + virtual ~TreeView() override; - virtual void scroll_into_view(const GModelIndex&, Orientation); + virtual void scroll_into_view(const ModelIndex&, Orientation); virtual int item_count() const override; protected: - explicit GTreeView(GWidget*); + explicit TreeView(Widget*); - virtual void paint_event(GPaintEvent&) override; - virtual void doubleclick_event(GMouseEvent&) override; - virtual void keydown_event(GKeyEvent&) override; + virtual void paint_event(PaintEvent&) override; + virtual void doubleclick_event(MouseEvent&) override; + virtual void keydown_event(KeyEvent&) override; virtual void did_update_selection() override; virtual void did_update_model() override; private: - virtual GModelIndex index_at_event_position(const Point&, bool& is_toggle) const override; + virtual ModelIndex index_at_event_position(const Point&, bool& is_toggle) const override; int item_height() const { return 16; } int max_item_width() const { return frame_inner_rect().width(); } @@ -56,7 +58,7 @@ private: int icon_spacing() const { return 2; } int toggle_size() const { return 9; } int text_padding() const { return 2; } - virtual void toggle_index(const GModelIndex&) override; + virtual void toggle_index(const ModelIndex&) override; virtual void update_column_sizes() override; template<typename Callback> @@ -64,10 +66,12 @@ private: struct MetadataForIndex; - MetadataForIndex& ensure_metadata_for_index(const GModelIndex&) const; + MetadataForIndex& ensure_metadata_for_index(const ModelIndex&) const; mutable HashMap<void*, NonnullOwnPtr<MetadataForIndex>> m_view_metadata; RefPtr<GraphicsBitmap> m_expand_bitmap; RefPtr<GraphicsBitmap> m_collapse_bitmap; }; + +} diff --git a/Libraries/LibGUI/GUndoStack.cpp b/Libraries/LibGUI/GUndoStack.cpp index 23244bc0c9..433b040aed 100644 --- a/Libraries/LibGUI/GUndoStack.cpp +++ b/Libraries/LibGUI/GUndoStack.cpp @@ -26,15 +26,17 @@ #include <LibGUI/GUndoStack.h> -GUndoStack::GUndoStack() +namespace GUI { + +UndoStack::UndoStack() { } -GUndoStack::~GUndoStack() +UndoStack::~UndoStack() { } -void GUndoStack::undo() +void UndoStack::undo() { if (!can_undo()) return; @@ -57,7 +59,7 @@ void GUndoStack::undo() m_stack_index++; } -void GUndoStack::redo() +void UndoStack::redo() { if (!can_redo()) return; @@ -73,7 +75,7 @@ void GUndoStack::redo() m_stack_index--; } -void GUndoStack::push(NonnullOwnPtr<GCommand>&& command) +void UndoStack::push(NonnullOwnPtr<Command>&& command) { if (m_stack.is_empty()) { auto undo_commands_container = make<UndoCommandsContainer>(); @@ -92,7 +94,7 @@ void GUndoStack::push(NonnullOwnPtr<GCommand>&& command) m_stack[0].m_undo_vector.prepend(move(command)); } -void GUndoStack::finalize_current_combo() +void UndoStack::finalize_current_combo() { if (m_stack.is_empty()) return; @@ -112,3 +114,5 @@ void GUndoStack::finalize_current_combo() m_last_updated_undo_vector_size = undo_vector.size(); } + +} diff --git a/Libraries/LibGUI/GUndoStack.h b/Libraries/LibGUI/GUndoStack.h index afe49d3113..d45b53d704 100644 --- a/Libraries/LibGUI/GUndoStack.h +++ b/Libraries/LibGUI/GUndoStack.h @@ -29,14 +29,16 @@ #include <AK/NonnullOwnPtrVector.h> #include <LibGUI/GCommand.h> -class GCommand; +namespace GUI { -class GUndoStack { +class Command; + +class UndoStack { public: - GUndoStack(); - ~GUndoStack(); + UndoStack(); + ~UndoStack(); - void push(NonnullOwnPtr<GCommand>&&); + void push(NonnullOwnPtr<Command>&&); bool can_undo() const { return m_stack_index < m_stack.size() && !m_stack.is_empty(); } bool can_redo() const { return m_stack_index > 0 && m_stack[m_stack_index - 1].m_undo_vector.size() > 0 && !m_stack.is_empty(); } @@ -48,10 +50,12 @@ public: private: struct UndoCommandsContainer { - NonnullOwnPtrVector<GCommand> m_undo_vector; + NonnullOwnPtrVector<Command> m_undo_vector; }; NonnullOwnPtrVector<UndoCommandsContainer> m_stack; int m_stack_index { 0 }; int m_last_updated_undo_vector_size { 0 }; }; + +} diff --git a/Libraries/LibGUI/GVariant.cpp b/Libraries/LibGUI/GVariant.cpp index 676e81837e..44fbb32569 100644 --- a/Libraries/LibGUI/GVariant.cpp +++ b/Libraries/LibGUI/GVariant.cpp @@ -27,52 +27,54 @@ #include <AK/JsonValue.h> #include <LibGUI/GVariant.h> -const char* to_string(GVariant::Type type) +namespace GUI { + +const char* to_string(Variant::Type type) { switch (type) { - case GVariant::Type::Invalid: + case Variant::Type::Invalid: return "Invalid"; - case GVariant::Type::Bool: + case Variant::Type::Bool: return "Bool"; - case GVariant::Type::Int32: + case Variant::Type::Int32: return "Int32"; - case GVariant::Type::Int64: + case Variant::Type::Int64: return "Int64"; - case GVariant::Type::UnsignedInt: + case Variant::Type::UnsignedInt: return "UnsignedInt"; - case GVariant::Type::Float: + case Variant::Type::Float: return "Float"; - case GVariant::Type::String: + case Variant::Type::String: return "String"; - case GVariant::Type::Bitmap: + case Variant::Type::Bitmap: return "Bitmap"; - case GVariant::Type::Color: + case Variant::Type::Color: return "Color"; - case GVariant::Type::Icon: + case Variant::Type::Icon: return "Icon"; - case GVariant::Type::Point: + case Variant::Type::Point: return "Point"; - case GVariant::Type::Size: + case Variant::Type::Size: return "Size"; - case GVariant::Type::Rect: + case Variant::Type::Rect: return "Rect"; - case GVariant::Type::Font: + case Variant::Type::Font: return "Font"; } ASSERT_NOT_REACHED(); } -GVariant::GVariant() +Variant::Variant() { m_value.as_string = nullptr; } -GVariant::~GVariant() +Variant::~Variant() { clear(); } -void GVariant::clear() +void Variant::clear() { switch (m_type) { case Type::String: @@ -91,49 +93,49 @@ void GVariant::clear() m_value.as_string = nullptr; } -GVariant::GVariant(i32 value) +Variant::Variant(i32 value) : m_type(Type::Int32) { m_value.as_i32 = value; } -GVariant::GVariant(i64 value) +Variant::Variant(i64 value) : m_type(Type::Int64) { m_value.as_i64 = value; } -GVariant::GVariant(unsigned value) +Variant::Variant(unsigned value) : m_type(Type::UnsignedInt) { m_value.as_uint = value; } -GVariant::GVariant(float value) +Variant::Variant(float value) : m_type(Type::Float) { m_value.as_float = value; } -GVariant::GVariant(bool value) +Variant::Variant(bool value) : m_type(Type::Bool) { m_value.as_bool = value; } -GVariant::GVariant(const char* cstring) - : GVariant(String(cstring)) +Variant::Variant(const char* cstring) + : Variant(String(cstring)) { } -GVariant::GVariant(const String& value) +Variant::Variant(const String& value) : m_type(Type::String) { m_value.as_string = const_cast<StringImpl*>(value.impl()); AK::ref_if_not_null(m_value.as_string); } -GVariant::GVariant(const JsonValue& value) +Variant::Variant(const JsonValue& value) { if (value.is_null()) { m_value.as_string = nullptr; @@ -159,7 +161,7 @@ GVariant::GVariant(const JsonValue& value) } if (value.is_u64()) { - // FIXME: GVariant should have a 64-bit internal type. + // FIXME: Variant should have a 64-bit internal type. m_type = Type::UnsignedInt; m_value.as_uint = value.to_u32(); return; @@ -181,52 +183,52 @@ GVariant::GVariant(const JsonValue& value) ASSERT_NOT_REACHED(); } -GVariant::GVariant(const GraphicsBitmap& value) +Variant::Variant(const GraphicsBitmap& value) : m_type(Type::Bitmap) { m_value.as_bitmap = const_cast<GraphicsBitmap*>(&value); AK::ref_if_not_null(m_value.as_bitmap); } -GVariant::GVariant(const GIcon& value) +Variant::Variant(const GIcon& value) : m_type(Type::Icon) { m_value.as_icon = &const_cast<GIconImpl&>(value.impl()); AK::ref_if_not_null(m_value.as_icon); } -GVariant::GVariant(const Font& value) +Variant::Variant(const Font& value) : m_type(Type::Font) { m_value.as_font = &const_cast<Font&>(value); AK::ref_if_not_null(m_value.as_font); } -GVariant::GVariant(Color color) +Variant::Variant(Color color) : m_type(Type::Color) { m_value.as_color = color.value(); } -GVariant::GVariant(const Point& point) +Variant::Variant(const Point& point) : m_type(Type::Point) { m_value.as_point = { point.x(), point.y() }; } -GVariant::GVariant(const Size& size) +Variant::Variant(const Size& size) : m_type(Type::Size) { m_value.as_size = { size.width(), size.height() }; } -GVariant::GVariant(const Rect& rect) +Variant::Variant(const Rect& rect) : m_type(Type::Rect) { m_value.as_rect = (const RawRect&)rect; } -GVariant& GVariant::operator=(const GVariant& other) +Variant& Variant::operator=(const Variant& other) { if (&other == this) return *this; @@ -235,7 +237,7 @@ GVariant& GVariant::operator=(const GVariant& other) return *this; } -GVariant& GVariant::operator=(GVariant&& other) +Variant& Variant::operator=(Variant&& other) { if (&other == this) return *this; @@ -246,12 +248,12 @@ GVariant& GVariant::operator=(GVariant&& other) return *this; } -GVariant::GVariant(const GVariant& other) +Variant::Variant(const Variant& other) { copy_from(other); } -void GVariant::copy_from(const GVariant& other) +void Variant::copy_from(const Variant& other) { ASSERT(!is_valid()); m_type = other.m_type; @@ -304,7 +306,7 @@ void GVariant::copy_from(const GVariant& other) } } -bool GVariant::operator==(const GVariant& other) const +bool Variant::operator==(const Variant& other) const { if (m_type != other.m_type) return to_string() == other.to_string(); @@ -341,7 +343,7 @@ bool GVariant::operator==(const GVariant& other) const ASSERT_NOT_REACHED(); } -bool GVariant::operator<(const GVariant& other) const +bool Variant::operator<(const Variant& other) const { if (m_type != other.m_type) return to_string() < other.to_string(); @@ -378,7 +380,7 @@ bool GVariant::operator<(const GVariant& other) const ASSERT_NOT_REACHED(); } -String GVariant::to_string() const +String Variant::to_string() const { switch (m_type) { case Type::Bool: @@ -413,3 +415,5 @@ String GVariant::to_string() const } ASSERT_NOT_REACHED(); } + +} diff --git a/Libraries/LibGUI/GVariant.h b/Libraries/LibGUI/GVariant.h index a3fde901b4..c2ecb34c0a 100644 --- a/Libraries/LibGUI/GVariant.h +++ b/Libraries/LibGUI/GVariant.h @@ -35,33 +35,35 @@ namespace AK { class JsonValue; } -class GVariant { +namespace GUI { + +class Variant { public: - GVariant(); - GVariant(bool); - GVariant(float); - GVariant(i32); - GVariant(i64); - GVariant(unsigned); - GVariant(const char*); - GVariant(const String&); - GVariant(const GraphicsBitmap&); - GVariant(const GIcon&); - GVariant(const Point&); - GVariant(const Size&); - GVariant(const Rect&); - GVariant(const Font&); - GVariant(const AK::JsonValue&); - GVariant(Color); - - GVariant(const GVariant&); - GVariant& operator=(const GVariant&); - - GVariant(GVariant&&) = delete; - GVariant& operator=(GVariant&&); + Variant(); + Variant(bool); + Variant(float); + Variant(i32); + Variant(i64); + Variant(unsigned); + Variant(const char*); + Variant(const String&); + Variant(const GraphicsBitmap&); + Variant(const GIcon&); + Variant(const Point&); + Variant(const Size&); + Variant(const Rect&); + Variant(const Font&); + Variant(const AK::JsonValue&); + Variant(Color); + + Variant(const Variant&); + Variant& operator=(const Variant&); + + Variant(Variant&&) = delete; + Variant& operator=(Variant&&); void clear(); - ~GVariant(); + ~Variant(); enum class Type { Invalid, @@ -241,11 +243,11 @@ public: String to_string() const; - bool operator==(const GVariant&) const; - bool operator<(const GVariant&) const; + bool operator==(const Variant&) const; + bool operator<(const Variant&) const; private: - void copy_from(const GVariant&); + void copy_from(const Variant&); struct RawPoint { int x; @@ -281,4 +283,6 @@ private: Type m_type { Type::Invalid }; }; -const char* to_string(GVariant::Type); +const char* to_string(Variant::Type); + +} diff --git a/Libraries/LibGUI/GWidget.cpp b/Libraries/LibGUI/GWidget.cpp index f4c76f1e1e..5cdcf8f2a3 100644 --- a/Libraries/LibGUI/GWidget.cpp +++ b/Libraries/LibGUI/GWidget.cpp @@ -48,73 +48,75 @@ #include <LibGUI/GWindowServerConnection.h> #include <unistd.h> -REGISTER_GWIDGET(GButton) -REGISTER_GWIDGET(GCheckBox) -REGISTER_GWIDGET(GGroupBox) -REGISTER_GWIDGET(GLabel) -REGISTER_GWIDGET(GRadioButton) -REGISTER_GWIDGET(GScrollBar) -REGISTER_GWIDGET(GSlider) -REGISTER_GWIDGET(GSpinBox) -REGISTER_GWIDGET(GTextBox) -REGISTER_GWIDGET(GWidget) - -static HashMap<String, GWidgetClassRegistration*>& widget_classes() -{ - static HashMap<String, GWidgetClassRegistration*>* map; +namespace GUI { + +REGISTER_GWIDGET(Button) +REGISTER_GWIDGET(CheckBox) +REGISTER_GWIDGET(GroupBox) +REGISTER_GWIDGET(Label) +REGISTER_GWIDGET(RadioButton) +REGISTER_GWIDGET(ScrollBar) +REGISTER_GWIDGET(Slider) +REGISTER_GWIDGET(SpinBox) +REGISTER_GWIDGET(TextBox) +REGISTER_GWIDGET(Widget) + +static HashMap<String, WidgetClassRegistration*>& widget_classes() +{ + static HashMap<String, WidgetClassRegistration*>* map; if (!map) - map = new HashMap<String, GWidgetClassRegistration*>; + map = new HashMap<String, WidgetClassRegistration*>; return *map; } -GWidgetClassRegistration::GWidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<GWidget>(GWidget*)> factory) +WidgetClassRegistration::WidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<Widget>(Widget*)> factory) : m_class_name(class_name) , m_factory(move(factory)) { widget_classes().set(class_name, this); } -GWidgetClassRegistration::~GWidgetClassRegistration() +WidgetClassRegistration::~WidgetClassRegistration() { } -void GWidgetClassRegistration::for_each(Function<void(const GWidgetClassRegistration&)> callback) +void WidgetClassRegistration::for_each(Function<void(const WidgetClassRegistration&)> callback) { for (auto& it : widget_classes()) { callback(*it.value); } } -const GWidgetClassRegistration* GWidgetClassRegistration::find(const String& class_name) +const WidgetClassRegistration* WidgetClassRegistration::find(const String& class_name) { return widget_classes().get(class_name).value_or(nullptr); } -GWidget::GWidget(GWidget* parent) +Widget::Widget(Widget* parent) : Core::Object(parent, true) , m_font(Font::default_font()) - , m_palette(GApplication::the().palette().impl()) + , m_palette(Application::the().palette().impl()) { } -GWidget::~GWidget() +Widget::~Widget() { } -void GWidget::child_event(Core::ChildEvent& event) +void Widget::child_event(Core::ChildEvent& event) { - if (event.type() == GEvent::ChildAdded) { - if (event.child() && Core::is<GWidget>(*event.child()) && layout()) { + if (event.type() == Event::ChildAdded) { + if (event.child() && Core::is<Widget>(*event.child()) && layout()) { if (event.insertion_before_child() && event.insertion_before_child()->is_widget()) - layout()->insert_widget_before(Core::to<GWidget>(*event.child()), Core::to<GWidget>(*event.insertion_before_child())); + layout()->insert_widget_before(Core::to<Widget>(*event.child()), Core::to<Widget>(*event.insertion_before_child())); else - layout()->add_widget(Core::to<GWidget>(*event.child())); + layout()->add_widget(Core::to<Widget>(*event.child())); } } - if (event.type() == GEvent::ChildRemoved) { + if (event.type() == Event::ChildRemoved) { if (layout()) { - if (event.child() && Core::is<GWidget>(*event.child())) - layout()->remove_widget(Core::to<GWidget>(*event.child())); + if (event.child() && Core::is<Widget>(*event.child())) + layout()->remove_widget(Core::to<Widget>(*event.child())); else invalidate_layout(); } @@ -123,7 +125,7 @@ void GWidget::child_event(Core::ChildEvent& event) return Core::Object::child_event(event); } -void GWidget::set_relative_rect(const Rect& a_rect) +void Widget::set_relative_rect(const Rect& a_rect) { // Get rid of negative width/height values. Rect rect = { @@ -142,7 +144,7 @@ void GWidget::set_relative_rect(const Rect& a_rect) m_relative_rect = rect; if (size_changed) { - GResizeEvent resize_event(m_relative_rect.size(), rect.size()); + ResizeEvent resize_event(m_relative_rect.size(), rect.size()); event(resize_event); } @@ -151,59 +153,59 @@ void GWidget::set_relative_rect(const Rect& a_rect) update(); } -void GWidget::event(Core::Event& event) +void Widget::event(Core::Event& event) { switch (event.type()) { - case GEvent::Paint: - return handle_paint_event(static_cast<GPaintEvent&>(event)); - case GEvent::Resize: - return handle_resize_event(static_cast<GResizeEvent&>(event)); - case GEvent::FocusIn: + case Event::Paint: + return handle_paint_event(static_cast<PaintEvent&>(event)); + case Event::Resize: + return handle_resize_event(static_cast<ResizeEvent&>(event)); + case Event::FocusIn: return focusin_event(event); - case GEvent::FocusOut: + case Event::FocusOut: return focusout_event(event); - case GEvent::Show: - return show_event(static_cast<GShowEvent&>(event)); - case GEvent::Hide: - return hide_event(static_cast<GHideEvent&>(event)); - case GEvent::KeyDown: - return keydown_event(static_cast<GKeyEvent&>(event)); - case GEvent::KeyUp: - return keyup_event(static_cast<GKeyEvent&>(event)); - case GEvent::MouseMove: - return mousemove_event(static_cast<GMouseEvent&>(event)); - case GEvent::MouseDown: - return handle_mousedown_event(static_cast<GMouseEvent&>(event)); - case GEvent::MouseDoubleClick: - return handle_mousedoubleclick_event(static_cast<GMouseEvent&>(event)); - case GEvent::MouseUp: - return handle_mouseup_event(static_cast<GMouseEvent&>(event)); - case GEvent::MouseWheel: - return mousewheel_event(static_cast<GMouseEvent&>(event)); - case GEvent::Drop: - return drop_event(static_cast<GDropEvent&>(event)); - case GEvent::Enter: + case Event::Show: + return show_event(static_cast<ShowEvent&>(event)); + case Event::Hide: + return hide_event(static_cast<HideEvent&>(event)); + case Event::KeyDown: + return keydown_event(static_cast<KeyEvent&>(event)); + case Event::KeyUp: + return keyup_event(static_cast<KeyEvent&>(event)); + case Event::MouseMove: + return mousemove_event(static_cast<MouseEvent&>(event)); + case Event::MouseDown: + return handle_mousedown_event(static_cast<MouseEvent&>(event)); + case Event::MouseDoubleClick: + return handle_mousedoubleclick_event(static_cast<MouseEvent&>(event)); + case Event::MouseUp: + return handle_mouseup_event(static_cast<MouseEvent&>(event)); + case Event::MouseWheel: + return mousewheel_event(static_cast<MouseEvent&>(event)); + case Event::Drop: + return drop_event(static_cast<DropEvent&>(event)); + case Event::Enter: return handle_enter_event(event); - case GEvent::Leave: + case Event::Leave: return handle_leave_event(event); - case GEvent::EnabledChange: - return change_event(static_cast<GEvent&>(event)); + case Event::EnabledChange: + return change_event(static_cast<Event&>(event)); default: return Core::Object::event(event); } } -void GWidget::handle_paint_event(GPaintEvent& event) +void Widget::handle_paint_event(PaintEvent& event) { ASSERT(is_visible()); if (fill_with_background_color()) { - GPainter painter(*this); + Painter painter(*this); painter.fill_rect(event.rect(), palette().color(background_role())); } else { #ifdef DEBUG_WIDGET_UNDERDRAW // FIXME: This is a bit broken. // If the widget is not opaque, let's not mess it up with debugging color. - GPainter painter(*this); + Painter painter(*this); painter.fill_rect(rect(), Color::Red); #endif } @@ -212,7 +214,7 @@ void GWidget::handle_paint_event(GPaintEvent& event) if (!child.is_visible()) return IterationDecision::Continue; if (child.relative_rect().intersects(event.rect())) { - GPaintEvent local_event(event.rect().intersected(child.relative_rect()).translated(-child.relative_position())); + PaintEvent local_event(event.rect().intersected(child.relative_rect()).translated(-child.relative_position())); child.dispatch_event(local_event, this); } return IterationDecision::Continue; @@ -220,7 +222,7 @@ void GWidget::handle_paint_event(GPaintEvent& event) second_paint_event(event); } -void GWidget::set_layout(OwnPtr<GLayout>&& layout) +void Widget::set_layout(OwnPtr<Layout>&& layout) { if (m_layout) m_layout->notify_disowned({}, *this); @@ -233,7 +235,7 @@ void GWidget::set_layout(OwnPtr<GLayout>&& layout) } } -void GWidget::do_layout() +void Widget::do_layout() { for_each_child_widget([&](auto& child) { child.do_layout(); @@ -246,80 +248,80 @@ void GWidget::do_layout() update(); } -void GWidget::notify_layout_changed(Badge<GLayout>) +void Widget::notify_layout_changed(Badge<Layout>) { invalidate_layout(); } -void GWidget::handle_resize_event(GResizeEvent& event) +void Widget::handle_resize_event(ResizeEvent& event) { resize_event(event); do_layout(); } -void GWidget::handle_mouseup_event(GMouseEvent& event) +void Widget::handle_mouseup_event(MouseEvent& event) { mouseup_event(event); } -void GWidget::handle_mousedown_event(GMouseEvent& event) +void Widget::handle_mousedown_event(MouseEvent& event) { if (accepts_focus()) set_focus(true); mousedown_event(event); - if (event.button() == GMouseButton::Right) { - GContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position())); + if (event.button() == MouseButton::Right) { + ContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position())); context_menu_event(c_event); } } -void GWidget::handle_mousedoubleclick_event(GMouseEvent& event) +void Widget::handle_mousedoubleclick_event(MouseEvent& event) { doubleclick_event(event); } -void GWidget::handle_enter_event(Core::Event& event) +void Widget::handle_enter_event(Core::Event& event) { if (has_tooltip()) - GApplication::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2)); + Application::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2)); enter_event(event); } -void GWidget::handle_leave_event(Core::Event& event) +void Widget::handle_leave_event(Core::Event& event) { - GApplication::the().hide_tooltip(); + Application::the().hide_tooltip(); leave_event(event); } -void GWidget::click_event(GMouseEvent&) +void Widget::click_event(MouseEvent&) { } -void GWidget::doubleclick_event(GMouseEvent&) +void Widget::doubleclick_event(MouseEvent&) { } -void GWidget::resize_event(GResizeEvent&) +void Widget::resize_event(ResizeEvent&) { } -void GWidget::paint_event(GPaintEvent&) +void Widget::paint_event(PaintEvent&) { } -void GWidget::second_paint_event(GPaintEvent&) +void Widget::second_paint_event(PaintEvent&) { } -void GWidget::show_event(GShowEvent&) +void Widget::show_event(ShowEvent&) { } -void GWidget::hide_event(GHideEvent&) +void Widget::hide_event(HideEvent&) { } -void GWidget::keydown_event(GKeyEvent& event) +void Widget::keydown_event(KeyEvent& event) { if (!event.alt() && !event.ctrl() && !event.logo() && event.key() == KeyCode::Key_Tab) { if (event.shift()) @@ -332,64 +334,64 @@ void GWidget::keydown_event(GKeyEvent& event) event.ignore(); } -void GWidget::keyup_event(GKeyEvent&) +void Widget::keyup_event(KeyEvent&) { } -void GWidget::mousedown_event(GMouseEvent&) +void Widget::mousedown_event(MouseEvent&) { } -void GWidget::mouseup_event(GMouseEvent&) +void Widget::mouseup_event(MouseEvent&) { } -void GWidget::mousemove_event(GMouseEvent&) +void Widget::mousemove_event(MouseEvent&) { } -void GWidget::mousewheel_event(GMouseEvent&) +void Widget::mousewheel_event(MouseEvent&) { } -void GWidget::context_menu_event(GContextMenuEvent&) +void Widget::context_menu_event(ContextMenuEvent&) { } -void GWidget::focusin_event(Core::Event&) +void Widget::focusin_event(Core::Event&) { } -void GWidget::focusout_event(Core::Event&) +void Widget::focusout_event(Core::Event&) { } -void GWidget::enter_event(Core::Event&) +void Widget::enter_event(Core::Event&) { } -void GWidget::leave_event(Core::Event&) +void Widget::leave_event(Core::Event&) { } -void GWidget::change_event(GEvent&) +void Widget::change_event(Event&) { } -void GWidget::drop_event(GDropEvent& event) +void Widget::drop_event(DropEvent& event) { dbg() << class_name() << "{" << this << "} DROP position: " << event.position() << ", text: '" << event.text() << "'"; event.ignore(); } -void GWidget::update() +void Widget::update() { if (rect().is_empty()) return; update(rect()); } -void GWidget::update(const Rect& rect) +void Widget::update(const Rect& rect) { if (!is_visible()) return; @@ -397,8 +399,8 @@ void GWidget::update(const Rect& rect) if (!updates_enabled()) return; - GWindow* window = m_window; - GWidget* parent = parent_widget(); + Window* window = m_window; + Widget* parent = parent_widget(); while (parent) { if (!parent->updates_enabled()) return; @@ -409,7 +411,7 @@ void GWidget::update(const Rect& rect) window->update(rect.translated(window_relative_rect().location())); } -Rect GWidget::window_relative_rect() const +Rect Widget::window_relative_rect() const { auto rect = relative_rect(); for (auto* parent = parent_widget(); parent; parent = parent->parent_widget()) { @@ -418,26 +420,26 @@ Rect GWidget::window_relative_rect() const return rect; } -Rect GWidget::screen_relative_rect() const +Rect Widget::screen_relative_rect() const { return window_relative_rect().translated(window()->position()); } -GWidget* GWidget::child_at(const Point& point) const +Widget* Widget::child_at(const Point& point) const { for (int i = children().size() - 1; i >= 0; --i) { - if (!Core::is<GWidget>(children()[i])) + if (!Core::is<Widget>(children()[i])) continue; - auto& child = Core::to<GWidget>(children()[i]); + auto& child = Core::to<Widget>(children()[i]); if (!child.is_visible()) continue; if (child.relative_rect().contains(point)) - return const_cast<GWidget*>(&child); + return const_cast<Widget*>(&child); } return nullptr; } -GWidget::HitTestResult GWidget::hit_test(const Point& position, ShouldRespectGreediness should_respect_greediness) +Widget::HitTestResult Widget::hit_test(const Point& position, ShouldRespectGreediness should_respect_greediness) { if (should_respect_greediness == ShouldRespectGreediness::Yes && is_greedy_for_hits()) return { this, position }; @@ -446,14 +448,14 @@ GWidget::HitTestResult GWidget::hit_test(const Point& position, ShouldRespectGre return { this, position }; } -void GWidget::set_window(GWindow* window) +void Widget::set_window(Window* window) { if (m_window == window) return; m_window = window; } -bool GWidget::is_focused() const +bool Widget::is_focused() const { auto* win = window(); if (!win) @@ -463,7 +465,7 @@ bool GWidget::is_focused() const return win->focused_widget() == this; } -void GWidget::set_focus(bool focus) +void Widget::set_focus(bool focus) { auto* win = window(); if (!win) @@ -476,7 +478,7 @@ void GWidget::set_focus(bool focus) } } -void GWidget::set_font(const Font* font) +void Widget::set_font(const Font* font) { if (m_font.ptr() == font) return; @@ -490,7 +492,7 @@ void GWidget::set_font(const Font* font) update(); } -void GWidget::set_global_cursor_tracking(bool enabled) +void Widget::set_global_cursor_tracking(bool enabled) { auto* win = window(); if (!win) @@ -498,7 +500,7 @@ void GWidget::set_global_cursor_tracking(bool enabled) win->set_global_cursor_tracking_widget(enabled ? this : nullptr); } -bool GWidget::global_cursor_tracking() const +bool Widget::global_cursor_tracking() const { auto* win = window(); if (!win) @@ -506,7 +508,7 @@ bool GWidget::global_cursor_tracking() const return win->global_cursor_tracking_widget() == this; } -void GWidget::set_preferred_size(const Size& size) +void Widget::set_preferred_size(const Size& size) { if (m_preferred_size == size) return; @@ -514,7 +516,7 @@ void GWidget::set_preferred_size(const Size& size) invalidate_layout(); } -void GWidget::set_size_policy(Orientation orientation, SizePolicy policy) +void Widget::set_size_policy(Orientation orientation, SizePolicy policy) { if (orientation == Orientation::Horizontal) set_size_policy(policy, m_vertical_size_policy); @@ -522,7 +524,7 @@ void GWidget::set_size_policy(Orientation orientation, SizePolicy policy) set_size_policy(m_horizontal_size_policy, policy); } -void GWidget::set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_policy) +void Widget::set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_policy) { if (m_horizontal_size_policy == horizontal_policy && m_vertical_size_policy == vertical_policy) return; @@ -531,13 +533,13 @@ void GWidget::set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_ invalidate_layout(); } -void GWidget::invalidate_layout() +void Widget::invalidate_layout() { if (window()) window()->schedule_relayout(); } -void GWidget::set_visible(bool visible) +void Widget::set_visible(bool visible) { if (visible == m_visible) return; @@ -548,15 +550,15 @@ void GWidget::set_visible(bool visible) update(); if (m_visible) { - GShowEvent e; + ShowEvent e; event(e); } else { - GHideEvent e; + HideEvent e; event(e); } } -bool GWidget::spans_entire_window_horizontally() const +bool Widget::spans_entire_window_horizontally() const { auto* w = window(); if (!w) @@ -570,17 +572,17 @@ bool GWidget::spans_entire_window_horizontally() const return wrr.left() == main_widget->rect().left() && wrr.right() == main_widget->rect().right(); } -void GWidget::set_enabled(bool enabled) +void Widget::set_enabled(bool enabled) { if (m_enabled == enabled) return; m_enabled = enabled; - GEvent e(GEvent::EnabledChange); + Event e(Event::EnabledChange); event(e); update(); } -void GWidget::move_to_front() +void Widget::move_to_front() { auto* parent = parent_widget(); if (!parent) @@ -594,7 +596,7 @@ void GWidget::move_to_front() parent->update(); } -void GWidget::move_to_back() +void Widget::move_to_back() { auto* parent = parent_widget(); if (!parent) @@ -608,7 +610,7 @@ void GWidget::move_to_back() parent->update(); } -bool GWidget::is_frontmost() const +bool Widget::is_frontmost() const { auto* parent = parent_widget(); if (!parent) @@ -616,7 +618,7 @@ bool GWidget::is_frontmost() const return &parent->children().last() == this; } -bool GWidget::is_backmost() const +bool Widget::is_backmost() const { auto* parent = parent_widget(); if (!parent) @@ -624,11 +626,11 @@ bool GWidget::is_backmost() const return &parent->children().first() == this; } -GAction* GWidget::action_for_key_event(const GKeyEvent& event) +Action* Widget::action_for_key_event(const KeyEvent& event) { - GShortcut shortcut(event.modifiers(), (KeyCode)event.key()); - GAction* found_action = nullptr; - for_each_child_of_type<GAction>([&] (auto& action) { + Shortcut shortcut(event.modifiers(), (KeyCode)event.key()); + Action* found_action = nullptr; + for_each_child_of_type<Action>([&](auto& action) { if (action.shortcut() == shortcut) { found_action = &action; return IterationDecision::Break; @@ -638,7 +640,7 @@ GAction* GWidget::action_for_key_event(const GKeyEvent& event) return found_action; } -void GWidget::set_updates_enabled(bool enabled) +void Widget::set_updates_enabled(bool enabled) { if (m_updates_enabled == enabled) return; @@ -647,7 +649,7 @@ void GWidget::set_updates_enabled(bool enabled) update(); } -void GWidget::focus_previous_widget() +void Widget::focus_previous_widget() { auto focusable_widgets = window()->focusable_widgets(); for (int i = focusable_widgets.size() - 1; i >= 0; --i) { @@ -660,7 +662,7 @@ void GWidget::focus_previous_widget() } } -void GWidget::focus_next_widget() +void Widget::focus_next_widget() { auto focusable_widgets = window()->focusable_widgets(); for (int i = 0; i < focusable_widgets.size(); ++i) { @@ -673,7 +675,7 @@ void GWidget::focus_next_widget() } } -void GWidget::set_backcolor(const StringView& color_string) +void Widget::set_backcolor(const StringView& color_string) { auto color = Color::from_string(color_string); if (!color.has_value()) @@ -681,7 +683,7 @@ void GWidget::set_backcolor(const StringView& color_string) set_background_color(color.value()); } -void GWidget::set_forecolor(const StringView& color_string) +void Widget::set_forecolor(const StringView& color_string) { auto color = Color::from_string(color_string); if (!color.has_value()) @@ -689,7 +691,7 @@ void GWidget::set_forecolor(const StringView& color_string) set_foreground_color(color.value()); } -void GWidget::save_to(AK::JsonObject& json) +void Widget::save_to(AK::JsonObject& json) { json.set("relative_rect", relative_rect().to_string()); json.set("fill_with_background_color", fill_with_background_color()); @@ -704,18 +706,20 @@ void GWidget::save_to(AK::JsonObject& json) Core::Object::save_to(json); } -Vector<GWidget*> GWidget::child_widgets() const +Vector<Widget*> Widget::child_widgets() const { - Vector<GWidget*> widgets; + Vector<Widget*> widgets; widgets.ensure_capacity(children().size()); - for (auto& child : const_cast<GWidget*>(this)->children()) { + for (auto& child : const_cast<Widget*>(this)->children()) { if (child.is_widget()) - widgets.append(static_cast<GWidget*>(&child)); + widgets.append(static_cast<Widget*>(&child)); } return widgets; } -void GWidget::set_palette(const Palette& palette) +void Widget::set_palette(const Palette& palette) { m_palette = palette.impl(); } + +} diff --git a/Libraries/LibGUI/GWidget.h b/Libraries/LibGUI/GWidget.h index 9efeac0780..adb737b69e 100644 --- a/Libraries/LibGUI/GWidget.h +++ b/Libraries/LibGUI/GWidget.h @@ -40,16 +40,29 @@ #include <LibGUI/GEvent.h> #include <LibGUI/GShortcut.h> -#define REGISTER_GWIDGET(class_name) \ - extern GWidgetClassRegistration registration_##class_name; \ - GWidgetClassRegistration registration_##class_name(#class_name, [](GWidget* parent) { return class_name::construct(parent); }); - -class GAction; -class GLayout; -class GMenu; -class GWindow; +#define REGISTER_GWIDGET(class_name) \ + extern WidgetClassRegistration registration_##class_name; \ + WidgetClassRegistration registration_##class_name(#class_name, [](Widget* parent) { return class_name::construct(parent); }); + class GraphicsBitmap; +namespace GUI { +class Widget; +} + +template<> +inline bool Core::is<GUI::Widget>(const Core::Object& object) +{ + return object.is_widget(); +} + +namespace GUI { + +class Action; +class Layout; +class Menu; +class Window; + enum class SizePolicy { Fixed, Fill @@ -74,34 +87,34 @@ enum class VerticalDirection { Down }; -class GWidget; +class Widget; -class GWidgetClassRegistration { - AK_MAKE_NONCOPYABLE(GWidgetClassRegistration) - AK_MAKE_NONMOVABLE(GWidgetClassRegistration) +class WidgetClassRegistration { + AK_MAKE_NONCOPYABLE(WidgetClassRegistration) + AK_MAKE_NONMOVABLE(WidgetClassRegistration) public: - GWidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<GWidget>(GWidget*)> factory); - ~GWidgetClassRegistration(); + WidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<Widget>(Widget*)> factory); + ~WidgetClassRegistration(); String class_name() const { return m_class_name; } - NonnullRefPtr<GWidget> construct(GWidget* parent) const { return m_factory(parent); } + NonnullRefPtr<Widget> construct(Widget* parent) const { return m_factory(parent); } - static void for_each(Function<void(const GWidgetClassRegistration&)>); - static const GWidgetClassRegistration* find(const String& class_name); + static void for_each(Function<void(const WidgetClassRegistration&)>); + static const WidgetClassRegistration* find(const String& class_name); private: String m_class_name; - Function<NonnullRefPtr<GWidget>(GWidget*)> m_factory; + Function<NonnullRefPtr<Widget>(Widget*)> m_factory; }; -class GWidget : public Core::Object { - C_OBJECT(GWidget) +class Widget : public Core::Object { + C_OBJECT(Widget) public: - virtual ~GWidget() override; + virtual ~Widget() override; - GLayout* layout() { return m_layout.ptr(); } - const GLayout* layout() const { return m_layout.ptr(); } - void set_layout(OwnPtr<GLayout>&&); + Layout* layout() { return m_layout.ptr(); } + const Layout* layout() const { return m_layout.ptr(); } + void set_layout(OwnPtr<Layout>&&); SizePolicy horizontal_size_policy() const { return m_horizontal_size_policy; } SizePolicy vertical_size_policy() const { return m_vertical_size_policy; } @@ -126,7 +139,7 @@ public: virtual void event(Core::Event&) override; // This is called after children have been painted. - virtual void second_paint_event(GPaintEvent&); + virtual void second_paint_event(PaintEvent&); Rect relative_rect() const { return m_relative_rect; } Point relative_position() const { return m_relative_rect.location(); } @@ -154,11 +167,11 @@ public: enum class ShouldRespectGreediness { No = 0, Yes }; struct HitTestResult { - GWidget* widget { nullptr }; + Widget* widget { nullptr }; Point local_position; }; HitTestResult hit_test(const Point&, ShouldRespectGreediness = ShouldRespectGreediness::Yes); - GWidget* child_at(const Point&) const; + Widget* child_at(const Point&) const; void set_relative_rect(const Rect&); void set_relative_rect(int x, int y, int width, int height) { set_relative_rect({ x, y, width, height }); } @@ -193,24 +206,24 @@ public: void set_autofill(bool b) { set_fill_with_background_color(b); } - GWindow* window() + Window* window() { if (auto* pw = parent_widget()) return pw->window(); return m_window; } - const GWindow* window() const + const Window* window() const { if (auto* pw = parent_widget()) return pw->window(); return m_window; } - void set_window(GWindow*); + void set_window(Window*); - GWidget* parent_widget(); - const GWidget* parent_widget() const; + Widget* parent_widget(); + const Widget* parent_widget() const; void set_fill_with_background_color(bool b) { m_fill_with_background_color = b; } bool fill_with_background_color() const { return m_fill_with_background_color; } @@ -222,7 +235,7 @@ public: void set_global_cursor_tracking(bool); bool global_cursor_tracking() const; - void notify_layout_changed(Badge<GLayout>); + void notify_layout_changed(Badge<Layout>); void invalidate_layout(); bool is_visible() const { return m_visible; } @@ -239,19 +252,19 @@ public: bool is_frontmost() const; bool is_backmost() const; - GAction* action_for_key_event(const GKeyEvent&); + Action* action_for_key_event(const KeyEvent&); template<typename Callback> void for_each_child_widget(Callback callback) { for_each_child([&](auto& child) { - if (Core::is<GWidget>(child)) - return callback(Core::to<GWidget>(child)); + if (Core::is<Widget>(child)) + return callback(Core::to<Widget>(child)); return IterationDecision::Continue; }); } - Vector<GWidget*> child_widgets() const; + Vector<Widget*> child_widgets() const; virtual bool is_radio_button() const { return false; } virtual bool is_abstract_button() const { return false; } @@ -264,44 +277,44 @@ public: void set_palette(const Palette&); protected: - explicit GWidget(GWidget* parent = nullptr); + explicit Widget(Widget* 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 paint_event(PaintEvent&); + virtual void resize_event(ResizeEvent&); + virtual void show_event(ShowEvent&); + virtual void hide_event(HideEvent&); + virtual void keydown_event(KeyEvent&); + virtual void keyup_event(KeyEvent&); + virtual void mousemove_event(MouseEvent&); + virtual void mousedown_event(MouseEvent&); + virtual void mouseup_event(MouseEvent&); + virtual void mousewheel_event(MouseEvent&); + virtual void click_event(MouseEvent&); + virtual void doubleclick_event(MouseEvent&); + virtual void context_menu_event(ContextMenuEvent&); virtual void focusin_event(Core::Event&); virtual void focusout_event(Core::Event&); virtual void enter_event(Core::Event&); virtual void leave_event(Core::Event&); virtual void child_event(Core::ChildEvent&) override; - virtual void change_event(GEvent&); - virtual void drop_event(GDropEvent&); + virtual void change_event(Event&); + virtual void drop_event(DropEvent&); private: - void handle_paint_event(GPaintEvent&); - void handle_resize_event(GResizeEvent&); - void handle_mousedown_event(GMouseEvent&); - void handle_mousedoubleclick_event(GMouseEvent&); - void handle_mouseup_event(GMouseEvent&); + void handle_paint_event(PaintEvent&); + void handle_resize_event(ResizeEvent&); + void handle_mousedown_event(MouseEvent&); + void handle_mousedoubleclick_event(MouseEvent&); + void handle_mouseup_event(MouseEvent&); void handle_enter_event(Core::Event&); void handle_leave_event(Core::Event&); void focus_previous_widget(); void focus_next_widget(); - GWindow* m_window { nullptr }; - OwnPtr<GLayout> m_layout; + Window* m_window { nullptr }; + OwnPtr<Layout> m_layout; Rect m_relative_rect; ColorRole m_background_role { ColorRole::Window }; @@ -325,21 +338,16 @@ private: NonnullRefPtr<PaletteImpl> m_palette; }; -template<> -inline bool Core::is<GWidget>(const Core::Object& object) -{ - return object.is_widget(); -} - -inline GWidget* GWidget::parent_widget() +inline Widget* Widget::parent_widget() { - if (parent() && Core::is<GWidget>(*parent())) - return &Core::to<GWidget>(*parent()); + if (parent() && Core::is<Widget>(*parent())) + return &Core::to<Widget>(*parent()); return nullptr; } -inline const GWidget* GWidget::parent_widget() const +inline const Widget* Widget::parent_widget() const { - if (parent() && Core::is<GWidget>(*parent())) - return &Core::to<const GWidget>(*parent()); + if (parent() && Core::is<Widget>(*parent())) + return &Core::to<const Widget>(*parent()); return nullptr; } +} diff --git a/Libraries/LibGUI/GWindow.cpp b/Libraries/LibGUI/GWindow.cpp index d60c49a3ca..a8be57c229 100644 --- a/Libraries/LibGUI/GWindow.cpp +++ b/Libraries/LibGUI/GWindow.cpp @@ -42,10 +42,12 @@ //#define UPDATE_COALESCING_DEBUG -static NeverDestroyed<HashTable<GWindow*>> all_windows; -static NeverDestroyed<HashMap<int, GWindow*>> reified_windows; +namespace GUI { -GWindow* GWindow::from_window_id(int window_id) +static NeverDestroyed<HashTable<Window*>> all_windows; +static NeverDestroyed<HashMap<int, Window*>> reified_windows; + +Window* Window::from_window_id(int window_id) { auto it = reified_windows->find(window_id); if (it != reified_windows->end()) @@ -53,7 +55,7 @@ GWindow* GWindow::from_window_id(int window_id) return nullptr; } -GWindow::GWindow(Core::Object* parent) +Window::Window(Core::Object* parent) : Core::Object(parent) { all_windows->set(this); @@ -61,30 +63,30 @@ GWindow::GWindow(Core::Object* parent) m_title_when_windowless = "GWindow"; } -GWindow::~GWindow() +Window::~Window() { all_windows->remove(this); hide(); } -void GWindow::close() +void Window::close() { hide(); } -void GWindow::move_to_front() +void Window::move_to_front() { if (!m_window_id) return; - GWindowServerConnection::the().send_sync<WindowServer::MoveWindowToFront>(m_window_id); + WindowServerConnection::the().send_sync<WindowServer::MoveWindowToFront>(m_window_id); } -void GWindow::show() +void Window::show() { if (m_window_id) return; - auto response = GWindowServerConnection::the().send_sync<WindowServer::CreateWindow>( + auto response = WindowServerConnection::the().send_sync<WindowServer::CreateWindow>( m_rect_when_windowless, m_has_alpha_channel, m_modal, @@ -102,16 +104,16 @@ void GWindow::show() apply_icon(); reified_windows->set(m_window_id, this); - GApplication::the().did_create_window({}); + Application::the().did_create_window({}); update(); } -void GWindow::hide() +void Window::hide() { if (!m_window_id) return; reified_windows->remove(m_window_id); - GWindowServerConnection::the().send_sync<WindowServer::DestroyWindow>(m_window_id); + WindowServerConnection::the().send_sync<WindowServer::DestroyWindow>(m_window_id); m_window_id = 0; m_pending_paint_event_rects.clear(); m_back_bitmap = nullptr; @@ -125,32 +127,32 @@ void GWindow::hide() } } if (!app_has_visible_windows) - GApplication::the().did_delete_last_window({}); + Application::the().did_delete_last_window({}); } -void GWindow::set_title(const StringView& title) +void Window::set_title(const StringView& title) { m_title_when_windowless = title; if (!m_window_id) return; - GWindowServerConnection::the().send_sync<WindowServer::SetWindowTitle>(m_window_id, title); + WindowServerConnection::the().send_sync<WindowServer::SetWindowTitle>(m_window_id, title); } -String GWindow::title() const +String Window::title() const { if (!m_window_id) return m_title_when_windowless; - return GWindowServerConnection::the().send_sync<WindowServer::GetWindowTitle>(m_window_id)->title(); + return WindowServerConnection::the().send_sync<WindowServer::GetWindowTitle>(m_window_id)->title(); } -Rect GWindow::rect() const +Rect Window::rect() const { if (!m_window_id) return m_rect_when_windowless; - return GWindowServerConnection::the().send_sync<WindowServer::GetWindowRect>(m_window_id)->rect(); + return WindowServerConnection::the().send_sync<WindowServer::GetWindowRect>(m_window_id)->rect(); } -void GWindow::set_rect(const Rect& a_rect) +void Window::set_rect(const Rect& a_rect) { m_rect_when_windowless = a_rect; if (!m_window_id) { @@ -158,7 +160,7 @@ void GWindow::set_rect(const Rect& a_rect) m_main_widget->resize(m_rect_when_windowless.size()); return; } - GWindowServerConnection::the().send_sync<WindowServer::SetWindowRect>(m_window_id, a_rect); + WindowServerConnection::the().send_sync<WindowServer::SetWindowRect>(m_window_id, a_rect); if (m_back_bitmap && m_back_bitmap->size() != a_rect.size()) m_back_bitmap = nullptr; if (m_front_bitmap && m_front_bitmap->size() != a_rect.size()) @@ -167,43 +169,43 @@ void GWindow::set_rect(const Rect& a_rect) m_main_widget->resize(a_rect.size()); } -void GWindow::set_window_type(GWindowType window_type) +void Window::set_window_type(WindowType window_type) { m_window_type = window_type; } -void GWindow::set_override_cursor(GStandardCursor cursor) +void Window::set_override_cursor(StandardCursor cursor) { if (!m_window_id) return; - GWindowServerConnection::the().send_sync<WindowServer::SetWindowOverrideCursor>(m_window_id, (u32)cursor); + WindowServerConnection::the().send_sync<WindowServer::SetWindowOverrideCursor>(m_window_id, (u32)cursor); } -void GWindow::event(Core::Event& event) +void Window::event(Core::Event& event) { - if (event.type() == GEvent::Drop) { - auto& drop_event = static_cast<GDropEvent&>(event); + if (event.type() == Event::Drop) { + auto& drop_event = static_cast<DropEvent&>(event); if (!m_main_widget) return; auto result = m_main_widget->hit_test(drop_event.position()); - auto local_event = make<GDropEvent>(result.local_position, drop_event.text(), drop_event.data_type(), drop_event.data()); + auto local_event = make<DropEvent>(result.local_position, drop_event.text(), drop_event.data_type(), drop_event.data()); ASSERT(result.widget); return result.widget->dispatch_event(*local_event, this); } - if (event.type() == GEvent::MouseUp || event.type() == GEvent::MouseDown || event.type() == GEvent::MouseDoubleClick || event.type() == GEvent::MouseMove || event.type() == GEvent::MouseWheel) { - auto& mouse_event = static_cast<GMouseEvent&>(event); + if (event.type() == Event::MouseUp || event.type() == Event::MouseDown || event.type() == Event::MouseDoubleClick || event.type() == Event::MouseMove || event.type() == Event::MouseWheel) { + auto& mouse_event = static_cast<MouseEvent&>(event); if (m_global_cursor_tracking_widget) { auto window_relative_rect = m_global_cursor_tracking_widget->window_relative_rect(); Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() }; - auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta()); + auto local_event = make<MouseEvent>((Event::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta()); m_global_cursor_tracking_widget->dispatch_event(*local_event, this); return; } if (m_automatic_cursor_tracking_widget) { auto window_relative_rect = m_automatic_cursor_tracking_widget->window_relative_rect(); Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() }; - auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta()); + auto local_event = make<MouseEvent>((Event::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta()); m_automatic_cursor_tracking_widget->dispatch_event(*local_event, this); if (mouse_event.buttons() == 0) m_automatic_cursor_tracking_widget = nullptr; @@ -212,7 +214,7 @@ void GWindow::event(Core::Event& event) if (!m_main_widget) return; auto result = m_main_widget->hit_test(mouse_event.position()); - auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), result.local_position, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta()); + auto local_event = make<MouseEvent>((Event::Type)event.type(), result.local_position, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta()); ASSERT(result.widget); set_hovered_widget(result.widget); if (mouse_event.buttons() != 0 && !m_automatic_cursor_tracking_widget) @@ -222,12 +224,12 @@ void GWindow::event(Core::Event& event) return; } - if (event.type() == GEvent::MultiPaint) { + if (event.type() == Event::MultiPaint) { if (!m_window_id) return; if (!m_main_widget) return; - auto& paint_event = static_cast<GMultiPaintEvent&>(event); + auto& paint_event = static_cast<MultiPaintEvent&>(event); auto rects = paint_event.rects(); ASSERT(!rects.is_empty()); if (m_back_bitmap && m_back_bitmap->size() != paint_event.window_size()) { @@ -254,7 +256,7 @@ void GWindow::event(Core::Event& event) } for (auto& rect : rects) - m_main_widget->dispatch_event(*make<GPaintEvent>(rect), this); + m_main_widget->dispatch_event(*make<PaintEvent>(rect), this); if (m_double_buffering_enabled) flip(rects); @@ -265,12 +267,12 @@ void GWindow::event(Core::Event& event) Vector<Rect> rects_to_send; for (auto& r : rects) rects_to_send.append(r); - GWindowServerConnection::the().post_message(WindowServer::DidFinishPainting(m_window_id, rects_to_send)); + WindowServerConnection::the().post_message(WindowServer::DidFinishPainting(m_window_id, rects_to_send)); } return; } - if (event.type() == GEvent::KeyUp || event.type() == GEvent::KeyDown) { + if (event.type() == Event::KeyUp || event.type() == Event::KeyDown) { if (m_focused_widget) return m_focused_widget->dispatch_event(event, this); if (m_main_widget) @@ -278,8 +280,8 @@ void GWindow::event(Core::Event& event) return; } - if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) { - m_is_active = event.type() == GEvent::WindowBecameActive; + if (event.type() == Event::WindowBecameActive || event.type() == Event::WindowBecameInactive) { + m_is_active = event.type() == Event::WindowBecameActive; if (m_main_widget) m_main_widget->dispatch_event(event, this); if (m_focused_widget) @@ -287,22 +289,22 @@ void GWindow::event(Core::Event& event) return; } - if (event.type() == GEvent::WindowCloseRequest) { + if (event.type() == Event::WindowCloseRequest) { if (on_close_request) { - if (on_close_request() == GWindow::CloseRequestDecision::StayOpen) + if (on_close_request() == Window::CloseRequestDecision::StayOpen) return; } close(); return; } - if (event.type() == GEvent::WindowLeft) { + if (event.type() == Event::WindowLeft) { set_hovered_widget(nullptr); return; } - if (event.type() == GEvent::Resize) { - auto new_size = static_cast<GResizeEvent&>(event).size(); + if (event.type() == Event::Resize) { + auto new_size = static_cast<ResizeEvent&>(event).size(); if (m_back_bitmap && m_back_bitmap->size() != new_size) m_back_bitmap = nullptr; if (!m_pending_paint_event_rects.is_empty()) { @@ -314,23 +316,23 @@ void GWindow::event(Core::Event& event) return; } - if (event.type() > GEvent::__Begin_WM_Events && event.type() < GEvent::__End_WM_Events) - return wm_event(static_cast<GWMEvent&>(event)); + if (event.type() > Event::__Begin_WM_Events && event.type() < Event::__End_WM_Events) + return wm_event(static_cast<WMEvent&>(event)); Core::Object::event(event); } -bool GWindow::is_visible() const +bool Window::is_visible() const { return m_window_id != 0; } -void GWindow::update() +void Window::update() { update({ 0, 0, width(), height() }); } -void GWindow::update(const Rect& a_rect) +void Window::update(const Rect& a_rect) { if (!m_window_id) return; @@ -352,13 +354,13 @@ void GWindow::update(const Rect& a_rect) Vector<Rect> rects_to_send; for (auto& r : rects) rects_to_send.append(r); - GWindowServerConnection::the().post_message(WindowServer::InvalidateRect(m_window_id, rects_to_send)); + WindowServerConnection::the().post_message(WindowServer::InvalidateRect(m_window_id, rects_to_send)); }); } m_pending_paint_event_rects.append(a_rect); } -void GWindow::set_main_widget(GWidget* widget) +void Window::set_main_widget(Widget* widget) { if (m_main_widget == widget) return; @@ -381,36 +383,36 @@ void GWindow::set_main_widget(GWidget* widget) update(); } -void GWindow::set_focused_widget(GWidget* widget) +void Window::set_focused_widget(Widget* widget) { if (m_focused_widget == widget) return; if (m_focused_widget) { - Core::EventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusOut)); + Core::EventLoop::current().post_event(*m_focused_widget, make<Event>(Event::FocusOut)); m_focused_widget->update(); } m_focused_widget = widget ? widget->make_weak_ptr() : nullptr; if (m_focused_widget) { - Core::EventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusIn)); + Core::EventLoop::current().post_event(*m_focused_widget, make<Event>(Event::FocusIn)); m_focused_widget->update(); } } -void GWindow::set_global_cursor_tracking_widget(GWidget* widget) +void Window::set_global_cursor_tracking_widget(Widget* widget) { if (widget == m_global_cursor_tracking_widget) return; m_global_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr; } -void GWindow::set_automatic_cursor_tracking_widget(GWidget* widget) +void Window::set_automatic_cursor_tracking_widget(Widget* widget) { if (widget == m_automatic_cursor_tracking_widget) return; m_automatic_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr; } -void GWindow::set_has_alpha_channel(bool value) +void Window::set_has_alpha_channel(bool value) { if (m_has_alpha_channel == value) return; @@ -422,44 +424,44 @@ void GWindow::set_has_alpha_channel(bool value) m_back_bitmap = nullptr; m_front_bitmap = nullptr; - GWindowServerConnection::the().send_sync<WindowServer::SetWindowHasAlphaChannel>(m_window_id, value); + WindowServerConnection::the().send_sync<WindowServer::SetWindowHasAlphaChannel>(m_window_id, value); update(); } -void GWindow::set_double_buffering_enabled(bool value) +void Window::set_double_buffering_enabled(bool value) { ASSERT(!m_window_id); m_double_buffering_enabled = value; } -void GWindow::set_opacity(float opacity) +void Window::set_opacity(float opacity) { m_opacity_when_windowless = opacity; if (!m_window_id) return; - GWindowServerConnection::the().send_sync<WindowServer::SetWindowOpacity>(m_window_id, opacity); + WindowServerConnection::the().send_sync<WindowServer::SetWindowOpacity>(m_window_id, opacity); } -void GWindow::set_hovered_widget(GWidget* widget) +void Window::set_hovered_widget(Widget* widget) { if (widget == m_hovered_widget) return; if (m_hovered_widget) - Core::EventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Leave)); + Core::EventLoop::current().post_event(*m_hovered_widget, make<Event>(Event::Leave)); m_hovered_widget = widget ? widget->make_weak_ptr() : nullptr; if (m_hovered_widget) - Core::EventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Enter)); + Core::EventLoop::current().post_event(*m_hovered_widget, make<Event>(Event::Enter)); } -void GWindow::set_current_backing_bitmap(GraphicsBitmap& bitmap, bool flush_immediately) +void Window::set_current_backing_bitmap(GraphicsBitmap& bitmap, bool flush_immediately) { - GWindowServerConnection::the().send_sync<WindowServer::SetWindowBackingStore>(m_window_id, 32, bitmap.pitch(), bitmap.shared_buffer_id(), bitmap.has_alpha_channel(), bitmap.size(), flush_immediately); + WindowServerConnection::the().send_sync<WindowServer::SetWindowBackingStore>(m_window_id, 32, bitmap.pitch(), bitmap.shared_buffer_id(), bitmap.has_alpha_channel(), bitmap.size(), flush_immediately); } -void GWindow::flip(const Vector<Rect, 32>& dirty_rects) +void Window::flip(const Vector<Rect, 32>& dirty_rects) { swap(m_front_bitmap, m_back_bitmap); @@ -480,49 +482,49 @@ void GWindow::flip(const Vector<Rect, 32>& dirty_rects) m_back_bitmap->shared_buffer()->set_volatile(); } -NonnullRefPtr<GraphicsBitmap> GWindow::create_shared_bitmap(GraphicsBitmap::Format format, const Size& size) +NonnullRefPtr<GraphicsBitmap> Window::create_shared_bitmap(GraphicsBitmap::Format format, const Size& size) { - ASSERT(GWindowServerConnection::the().server_pid()); + ASSERT(WindowServerConnection::the().server_pid()); ASSERT(!size.is_empty()); size_t pitch = round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16); size_t size_in_bytes = size.height() * pitch; auto shared_buffer = SharedBuffer::create_with_size(size_in_bytes); ASSERT(shared_buffer); - shared_buffer->share_with(GWindowServerConnection::the().server_pid()); + shared_buffer->share_with(WindowServerConnection::the().server_pid()); return GraphicsBitmap::create_with_shared_buffer(format, *shared_buffer, size); } -NonnullRefPtr<GraphicsBitmap> GWindow::create_backing_bitmap(const Size& size) +NonnullRefPtr<GraphicsBitmap> Window::create_backing_bitmap(const Size& size) { auto format = m_has_alpha_channel ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32; return create_shared_bitmap(format, size); } -void GWindow::set_modal(bool modal) +void Window::set_modal(bool modal) { ASSERT(!m_window_id); m_modal = modal; } -void GWindow::wm_event(GWMEvent&) +void Window::wm_event(WMEvent&) { } -void GWindow::set_icon(const GraphicsBitmap* icon) +void Window::set_icon(const GraphicsBitmap* icon) { if (m_icon == icon) return; m_icon = create_shared_bitmap(GraphicsBitmap::Format::RGBA32, icon->size()); { - GPainter painter(*m_icon); + Painter painter(*m_icon); painter.blit({ 0, 0 }, *icon, icon->rect()); } apply_icon(); } -void GWindow::apply_icon() +void Window::apply_icon() { if (!m_icon) return; @@ -540,22 +542,22 @@ void GWindow::apply_icon() if (!has_set_process_icon) set_process_icon(m_icon->shared_buffer_id()); - GWindowServerConnection::the().send_sync<WindowServer::SetWindowIconBitmap>(m_window_id, m_icon->shared_buffer_id(), m_icon->size()); + WindowServerConnection::the().send_sync<WindowServer::SetWindowIconBitmap>(m_window_id, m_icon->shared_buffer_id(), m_icon->size()); } -void GWindow::start_wm_resize() +void Window::start_wm_resize() { - GWindowServerConnection::the().post_message(WindowServer::WM_StartWindowResize(GWindowServerConnection::the().my_client_id(), m_window_id)); + WindowServerConnection::the().post_message(WindowServer::WM_StartWindowResize(WindowServerConnection::the().my_client_id(), m_window_id)); } -Vector<GWidget*> GWindow::focusable_widgets() const +Vector<Widget*> Window::focusable_widgets() const { if (!m_main_widget) return {}; - Vector<GWidget*> collected_widgets; + Vector<Widget*> collected_widgets; - Function<void(GWidget&)> collect_focusable_widgets = [&](GWidget& widget) { + Function<void(Widget&)> collect_focusable_widgets = [&](auto& widget) { if (widget.accepts_focus()) collected_widgets.append(&widget); widget.for_each_child_widget([&](auto& child) { @@ -568,11 +570,11 @@ Vector<GWidget*> GWindow::focusable_widgets() const }); }; - collect_focusable_widgets(const_cast<GWidget&>(*m_main_widget)); + collect_focusable_widgets(const_cast<Widget&>(*m_main_widget)); return collected_widgets; } -void GWindow::save_to(AK::JsonObject& json) +void Window::save_to(AK::JsonObject& json) { json.set("title", title()); json.set("visible", is_visible()); @@ -586,17 +588,17 @@ void GWindow::save_to(AK::JsonObject& json) Core::Object::save_to(json); } -void GWindow::set_fullscreen(bool fullscreen) +void Window::set_fullscreen(bool fullscreen) { if (m_fullscreen == fullscreen) return; m_fullscreen = fullscreen; if (!m_window_id) return; - GWindowServerConnection::the().send_sync<WindowServer::SetFullscreen>(m_window_id, fullscreen); + WindowServerConnection::the().send_sync<WindowServer::SetFullscreen>(m_window_id, fullscreen); } -void GWindow::schedule_relayout() +void Window::schedule_relayout() { if (m_layout_pending) return; @@ -609,14 +611,14 @@ void GWindow::schedule_relayout() }); } -void GWindow::update_all_windows(Badge<GWindowServerConnection>) +void Window::update_all_windows(Badge<WindowServerConnection>) { for (auto* window : *all_windows) { window->update(); } } -void GWindow::notify_state_changed(Badge<GWindowServerConnection>, bool minimized, bool occluded) +void Window::notify_state_changed(Badge<WindowServerConnection>, bool minimized, bool occluded) { m_visible_for_timer_purposes = !minimized && !occluded; @@ -635,11 +637,11 @@ void GWindow::notify_state_changed(Badge<GWindowServerConnection>, bool minimize } } -GAction* GWindow::action_for_key_event(const GKeyEvent& event) +Action* Window::action_for_key_event(const KeyEvent& event) { - GShortcut shortcut(event.modifiers(), (KeyCode)event.key()); - GAction* found_action = nullptr; - for_each_child_of_type<GAction>([&](auto& action) { + Shortcut shortcut(event.modifiers(), (KeyCode)event.key()); + Action* found_action = nullptr; + for_each_child_of_type<Action>([&](auto& action) { if (action.shortcut() == shortcut) { found_action = &action; return IterationDecision::Break; @@ -648,3 +650,5 @@ GAction* GWindow::action_for_key_event(const GKeyEvent& event) }); return found_action; } + +} diff --git a/Libraries/LibGUI/GWindow.h b/Libraries/LibGUI/GWindow.h index 708ebfe707..c0ffe91020 100644 --- a/Libraries/LibGUI/GWindow.h +++ b/Libraries/LibGUI/GWindow.h @@ -35,13 +35,15 @@ #include <LibDraw/Rect.h> #include <LibGUI/GWindowType.h> -class GAction; -class GKeyEvent; -class GWMEvent; -class GWidget; -class GWindowServerConnection; +namespace GUI { -enum class GStandardCursor { +class Action; +class KeyEvent; +class WMEvent; +class Widget; +class WindowServerConnection; + +enum class StandardCursor { None = 0, Arrow, IBeam, @@ -52,12 +54,12 @@ enum class GStandardCursor { Hand, }; -class GWindow : public Core::Object { - C_OBJECT(GWindow) +class Window : public Core::Object { + C_OBJECT(Window) public: - virtual ~GWindow() override; + virtual ~Window() override; - static GWindow* from_window_id(int); + static Window* from_window_id(int); bool is_modal() const { return m_modal; } void set_modal(bool); @@ -74,7 +76,7 @@ public: void set_double_buffering_enabled(bool); void set_has_alpha_channel(bool); void set_opacity(float); - void set_window_type(GWindowType); + void set_window_type(WindowType); int window_id() const { return m_window_id; } @@ -124,28 +126,28 @@ public: void start_wm_resize(); - GWidget* main_widget() { return m_main_widget; } - const GWidget* main_widget() const { return m_main_widget; } - void set_main_widget(GWidget*); + Widget* main_widget() { return m_main_widget; } + const Widget* main_widget() const { return m_main_widget; } + void set_main_widget(Widget*); - GWidget* focused_widget() { return m_focused_widget; } - const GWidget* focused_widget() const { return m_focused_widget; } - void set_focused_widget(GWidget*); + Widget* focused_widget() { return m_focused_widget; } + const Widget* focused_widget() const { return m_focused_widget; } + void set_focused_widget(Widget*); void update(); void update(const Rect&); - void set_global_cursor_tracking_widget(GWidget*); - GWidget* global_cursor_tracking_widget() { return m_global_cursor_tracking_widget.ptr(); } - const GWidget* global_cursor_tracking_widget() const { return m_global_cursor_tracking_widget.ptr(); } + void set_global_cursor_tracking_widget(Widget*); + Widget* global_cursor_tracking_widget() { return m_global_cursor_tracking_widget.ptr(); } + const Widget* global_cursor_tracking_widget() const { return m_global_cursor_tracking_widget.ptr(); } - void set_automatic_cursor_tracking_widget(GWidget*); - GWidget* automatic_cursor_tracking_widget() { return m_automatic_cursor_tracking_widget.ptr(); } - const GWidget* automatic_cursor_tracking_widget() const { return m_automatic_cursor_tracking_widget.ptr(); } + void set_automatic_cursor_tracking_widget(Widget*); + Widget* automatic_cursor_tracking_widget() { return m_automatic_cursor_tracking_widget.ptr(); } + const Widget* automatic_cursor_tracking_widget() const { return m_automatic_cursor_tracking_widget.ptr(); } - GWidget* hovered_widget() { return m_hovered_widget.ptr(); } - const GWidget* hovered_widget() const { return m_hovered_widget.ptr(); } - void set_hovered_widget(GWidget*); + Widget* hovered_widget() { return m_hovered_widget.ptr(); } + const Widget* hovered_widget() const { return m_hovered_widget.ptr(); } + void set_hovered_widget(Widget*); GraphicsBitmap* front_bitmap() { return m_front_bitmap.ptr(); } GraphicsBitmap* back_bitmap() { return m_back_bitmap.ptr(); } @@ -155,28 +157,28 @@ public: Size base_size() const { return m_base_size; } void set_base_size(const Size& size) { m_base_size = size; } - void set_override_cursor(GStandardCursor); + void set_override_cursor(StandardCursor); void set_icon(const GraphicsBitmap*); void apply_icon(); const GraphicsBitmap* icon() const { return m_icon.ptr(); } - Vector<GWidget*> focusable_widgets() const; + Vector<Widget*> focusable_widgets() const; virtual void save_to(AK::JsonObject&) override; void schedule_relayout(); - static void update_all_windows(Badge<GWindowServerConnection>); - void notify_state_changed(Badge<GWindowServerConnection>, bool minimized, bool occluded); + static void update_all_windows(Badge<WindowServerConnection>); + void notify_state_changed(Badge<WindowServerConnection>, bool minimized, bool occluded); virtual bool is_visible_for_timer_purposes() const override { return m_visible_for_timer_purposes; } - GAction* action_for_key_event(const GKeyEvent&); + Action* action_for_key_event(const KeyEvent&); protected: - GWindow(Core::Object* parent = nullptr); - virtual void wm_event(GWMEvent&); + Window(Core::Object* parent = nullptr); + virtual void wm_event(WMEvent&); private: virtual bool is_window() const override final { return true; } @@ -191,18 +193,18 @@ private: RefPtr<GraphicsBitmap> m_icon; int m_window_id { 0 }; float m_opacity_when_windowless { 1.0f }; - RefPtr<GWidget> m_main_widget; - WeakPtr<GWidget> m_focused_widget; - WeakPtr<GWidget> m_global_cursor_tracking_widget; - WeakPtr<GWidget> m_automatic_cursor_tracking_widget; - WeakPtr<GWidget> m_hovered_widget; + RefPtr<Widget> m_main_widget; + WeakPtr<Widget> m_focused_widget; + WeakPtr<Widget> m_global_cursor_tracking_widget; + WeakPtr<Widget> m_automatic_cursor_tracking_widget; + WeakPtr<Widget> m_hovered_widget; Rect m_rect_when_windowless; String m_title_when_windowless; Vector<Rect, 32> m_pending_paint_event_rects; Size m_size_increment; Size m_base_size; Color m_background_color { Color::WarmGray }; - GWindowType m_window_type { GWindowType::Normal }; + WindowType m_window_type { WindowType::Normal }; bool m_is_active { false }; bool m_has_alpha_channel { false }; bool m_double_buffering_enabled { true }; @@ -215,8 +217,10 @@ private: bool m_visible_for_timer_purposes { true }; }; +} + template<> -inline bool Core::is<GWindow>(const Core::Object& object) +inline bool Core::is<GUI::Window>(const Core::Object& object) { return object.is_window(); } diff --git a/Libraries/LibGUI/GWindowServerConnection.cpp b/Libraries/LibGUI/GWindowServerConnection.cpp index c514e59a99..02497cd170 100644 --- a/Libraries/LibGUI/GWindowServerConnection.cpp +++ b/Libraries/LibGUI/GWindowServerConnection.cpp @@ -39,11 +39,13 @@ //#define GEVENTLOOP_DEBUG -GWindowServerConnection& GWindowServerConnection::the() +namespace GUI { + +WindowServerConnection& WindowServerConnection::the() { - static GWindowServerConnection* s_connection = nullptr; + static WindowServerConnection* s_connection = nullptr; if (!s_connection) - s_connection = new GWindowServerConnection; + s_connection = new WindowServerConnection; return *s_connection; } @@ -52,91 +54,91 @@ static void set_system_theme_from_shared_buffer_id(int id) auto system_theme = SharedBuffer::create_from_shared_buffer_id(id); ASSERT(system_theme); set_system_theme(*system_theme); - GApplication::the().set_system_palette(*system_theme); + Application::the().set_system_palette(*system_theme); } -void GWindowServerConnection::handshake() +void WindowServerConnection::handshake() { auto response = send_sync<WindowServer::Greet>(); set_my_client_id(response->client_id()); set_system_theme_from_shared_buffer_id(response->system_theme_buffer_id()); - GDesktop::the().did_receive_screen_rect({}, response->screen_rect()); + Desktop::the().did_receive_screen_rect({}, response->screen_rect()); } -void GWindowServerConnection::handle(const WindowClient::UpdateSystemTheme& message) +void WindowServerConnection::handle(const WindowClient::UpdateSystemTheme& message) { set_system_theme_from_shared_buffer_id(message.system_theme_buffer_id()); - GWindow::update_all_windows({}); + Window::update_all_windows({}); } -void GWindowServerConnection::handle(const WindowClient::Paint& message) +void WindowServerConnection::handle(const WindowClient::Paint& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d Paint\n", message.window_id()); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GMultiPaintEvent>(message.rects(), message.window_size())); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<MultiPaintEvent>(message.rects(), message.window_size())); } -void GWindowServerConnection::handle(const WindowClient::WindowResized& message) +void WindowServerConnection::handle(const WindowClient::WindowResized& message) { - if (auto* window = GWindow::from_window_id(message.window_id())) { - Core::EventLoop::current().post_event(*window, make<GResizeEvent>(message.old_rect().size(), message.new_rect().size())); + if (auto* window = Window::from_window_id(message.window_id())) { + Core::EventLoop::current().post_event(*window, make<ResizeEvent>(message.old_rect().size(), message.new_rect().size())); } } -void GWindowServerConnection::handle(const WindowClient::WindowActivated& message) +void WindowServerConnection::handle(const WindowClient::WindowActivated& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("(%d) WID=%d WindowActivated\n", getpid(), message.window_id()); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GEvent>(GEvent::WindowBecameActive)); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowBecameActive)); } -void GWindowServerConnection::handle(const WindowClient::WindowDeactivated& message) +void WindowServerConnection::handle(const WindowClient::WindowDeactivated& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("(%d) WID=%d WindowDeactivated\n", getpid(), message.window_id()); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GEvent>(GEvent::WindowBecameInactive)); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowBecameInactive)); } -void GWindowServerConnection::handle(const WindowClient::WindowCloseRequest& message) +void WindowServerConnection::handle(const WindowClient::WindowCloseRequest& message) { - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GEvent>(GEvent::WindowCloseRequest)); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowCloseRequest)); } -void GWindowServerConnection::handle(const WindowClient::WindowEntered& message) +void WindowServerConnection::handle(const WindowClient::WindowEntered& message) { - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GEvent>(GEvent::WindowEntered)); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowEntered)); } -void GWindowServerConnection::handle(const WindowClient::WindowLeft& message) +void WindowServerConnection::handle(const WindowClient::WindowLeft& message) { - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GEvent>(GEvent::WindowLeft)); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowLeft)); } -void GWindowServerConnection::handle(const WindowClient::KeyDown& message) +void WindowServerConnection::handle(const WindowClient::KeyDown& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d KeyDown character=0x%02x\n", message.window_id(), message.character()); #endif - auto* window = GWindow::from_window_id(message.window_id()); + auto* window = Window::from_window_id(message.window_id()); if (!window) return; - auto key_event = make<GKeyEvent>(GEvent::KeyDown, message.key(), message.modifiers()); + auto key_event = make<KeyEvent>(Event::KeyDown, message.key(), message.modifiers()); if (message.character() != '\0') { char ch = message.character(); key_event->m_text = String(&ch, 1); } - GAction* action = nullptr; + Action* action = nullptr; if (auto* focused_widget = window->focused_widget()) action = focused_widget->action_for_key_event(*key_event); @@ -145,7 +147,7 @@ void GWindowServerConnection::handle(const WindowClient::KeyDown& message) action = window->action_for_key_event(*key_event); if (!action) - action = GApplication::the().action_for_key_event(*key_event); + action = Application::the().action_for_key_event(*key_event); if (action && action->is_enabled()) { action->activate(); @@ -154,16 +156,16 @@ void GWindowServerConnection::handle(const WindowClient::KeyDown& message) Core::EventLoop::current().post_event(*window, move(key_event)); } -void GWindowServerConnection::handle(const WindowClient::KeyUp& message) +void WindowServerConnection::handle(const WindowClient::KeyUp& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d KeyUp character=0x%02x\n", message.window_id(), message.character()); #endif - auto* window = GWindow::from_window_id(message.window_id()); + auto* window = Window::from_window_id(message.window_id()); if (!window) return; - auto key_event = make<GKeyEvent>(GEvent::KeyUp, message.key(), message.modifiers()); + auto key_event = make<KeyEvent>(Event::KeyUp, message.key(), message.modifiers()); if (message.character() != '\0') { char ch = message.character(); key_event->m_text = String(&ch, 1); @@ -172,153 +174,155 @@ void GWindowServerConnection::handle(const WindowClient::KeyUp& message) Core::EventLoop::current().post_event(*window, move(key_event)); } -GMouseButton to_gmousebutton(u32 button) +MouseButton to_gmousebutton(u32 button) { switch (button) { case 0: - return GMouseButton::None; + return MouseButton::None; case 1: - return GMouseButton::Left; + return MouseButton::Left; case 2: - return GMouseButton::Right; + return MouseButton::Right; case 4: - return GMouseButton::Middle; + return MouseButton::Middle; default: ASSERT_NOT_REACHED(); break; } } -void GWindowServerConnection::handle(const WindowClient::MouseDown& message) +void WindowServerConnection::handle(const WindowClient::MouseDown& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d MouseDown %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GMouseEvent>(GEvent::MouseDown, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseDown, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); } -void GWindowServerConnection::handle(const WindowClient::MouseUp& message) +void WindowServerConnection::handle(const WindowClient::MouseUp& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d MouseUp %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GMouseEvent>(GEvent::MouseUp, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseUp, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); } -void GWindowServerConnection::handle(const WindowClient::MouseMove& message) +void WindowServerConnection::handle(const WindowClient::MouseMove& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d MouseMove %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GMouseEvent>(GEvent::MouseMove, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseMove, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); } -void GWindowServerConnection::handle(const WindowClient::MouseDoubleClick& message) +void WindowServerConnection::handle(const WindowClient::MouseDoubleClick& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d MouseDoubleClick %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GMouseEvent>(GEvent::MouseDoubleClick, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseDoubleClick, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); } -void GWindowServerConnection::handle(const WindowClient::MouseWheel& message) +void WindowServerConnection::handle(const WindowClient::MouseWheel& message) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%d MouseWheel %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); #endif - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GMouseEvent>(GEvent::MouseWheel, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseWheel, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); } -void GWindowServerConnection::handle(const WindowClient::MenuItemActivated& message) +void WindowServerConnection::handle(const WindowClient::MenuItemActivated& message) { - auto* menu = GMenu::from_menu_id(message.menu_id()); + auto* menu = Menu::from_menu_id(message.menu_id()); if (!menu) { - dbgprintf("GEventLoop received event for invalid menu ID %d\n", message.menu_id()); + dbgprintf("EventLoop received event for invalid menu ID %d\n", message.menu_id()); return; } if (auto* action = menu->action_at(message.identifier())) action->activate(menu); } -void GWindowServerConnection::handle(const WindowClient::WM_WindowStateChanged& message) +void WindowServerConnection::handle(const WindowClient::WM_WindowStateChanged& message) { #ifdef GEVENTLOOP_DEBUG - dbgprintf("GEventLoop: handle_wm_event: %d\n", (int)event.type); + dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); #endif - if (auto* window = GWindow::from_window_id(message.wm_id())) - Core::EventLoop::current().post_event(*window, make<GWMWindowStateChangedEvent>(message.client_id(), message.window_id(), message.title(), message.rect(), message.is_active(), (GWindowType)message.window_type(), message.is_minimized())); + if (auto* window = Window::from_window_id(message.wm_id())) + Core::EventLoop::current().post_event(*window, make<WMWindowStateChangedEvent>(message.client_id(), message.window_id(), message.title(), message.rect(), message.is_active(), static_cast<WindowType>(message.window_type()), message.is_minimized())); } -void GWindowServerConnection::handle(const WindowClient::WM_WindowRectChanged& message) +void WindowServerConnection::handle(const WindowClient::WM_WindowRectChanged& message) { #ifdef GEVENTLOOP_DEBUG - dbgprintf("GEventLoop: handle_wm_event: %d\n", (int)event.type); + dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); #endif - if (auto* window = GWindow::from_window_id(message.wm_id())) - Core::EventLoop::current().post_event(*window, make<GWMWindowRectChangedEvent>(message.client_id(), message.window_id(), message.rect())); + if (auto* window = Window::from_window_id(message.wm_id())) + Core::EventLoop::current().post_event(*window, make<WMWindowRectChangedEvent>(message.client_id(), message.window_id(), message.rect())); } -void GWindowServerConnection::handle(const WindowClient::WM_WindowIconBitmapChanged& message) +void WindowServerConnection::handle(const WindowClient::WM_WindowIconBitmapChanged& message) { #ifdef GEVENTLOOP_DEBUG - dbgprintf("GEventLoop: handle_wm_event: %d\n", (int)event.type); + dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); #endif - if (auto* window = GWindow::from_window_id(message.wm_id())) - Core::EventLoop::current().post_event(*window, make<GWMWindowIconBitmapChangedEvent>(message.client_id(), message.window_id(), message.icon_buffer_id(), message.icon_size())); + if (auto* window = Window::from_window_id(message.wm_id())) + Core::EventLoop::current().post_event(*window, make<WMWindowIconBitmapChangedEvent>(message.client_id(), message.window_id(), message.icon_buffer_id(), message.icon_size())); } -void GWindowServerConnection::handle(const WindowClient::WM_WindowRemoved& message) +void WindowServerConnection::handle(const WindowClient::WM_WindowRemoved& message) { #ifdef GEVENTLOOP_DEBUG - dbgprintf("GEventLoop: handle_wm_event: %d\n", (int)event.type); + dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); #endif - if (auto* window = GWindow::from_window_id(message.wm_id())) - Core::EventLoop::current().post_event(*window, make<GWMWindowRemovedEvent>(message.client_id(), message.window_id())); + if (auto* window = Window::from_window_id(message.wm_id())) + Core::EventLoop::current().post_event(*window, make<WMWindowRemovedEvent>(message.client_id(), message.window_id())); } -void GWindowServerConnection::handle(const WindowClient::ScreenRectChanged& message) +void WindowServerConnection::handle(const WindowClient::ScreenRectChanged& message) { - GDesktop::the().did_receive_screen_rect({}, message.rect()); + Desktop::the().did_receive_screen_rect({}, message.rect()); } -void GWindowServerConnection::handle(const WindowClient::ClipboardContentsChanged& message) +void WindowServerConnection::handle(const WindowClient::ClipboardContentsChanged& message) { - GClipboard::the().did_receive_clipboard_contents_changed({}, message.content_type()); + Clipboard::the().did_receive_clipboard_contents_changed({}, message.content_type()); } -void GWindowServerConnection::handle(const WindowClient::AsyncSetWallpaperFinished&) +void WindowServerConnection::handle(const WindowClient::AsyncSetWallpaperFinished&) { - // This is handled manually by GDesktop::set_wallpaper(). + // This is handled manually by Desktop::set_wallpaper(). } -void GWindowServerConnection::handle(const WindowClient::DragDropped& message) +void WindowServerConnection::handle(const WindowClient::DragDropped& message) { - if (auto* window = GWindow::from_window_id(message.window_id())) - Core::EventLoop::current().post_event(*window, make<GDropEvent>(message.mouse_position(), message.text(), message.data_type(), message.data())); + if (auto* window = Window::from_window_id(message.window_id())) + Core::EventLoop::current().post_event(*window, make<DropEvent>(message.mouse_position(), message.text(), message.data_type(), message.data())); } -void GWindowServerConnection::handle(const WindowClient::DragAccepted&) +void WindowServerConnection::handle(const WindowClient::DragAccepted&) { - GDragOperation::notify_accepted({}); + DragOperation::notify_accepted({}); } -void GWindowServerConnection::handle(const WindowClient::DragCancelled&) +void WindowServerConnection::handle(const WindowClient::DragCancelled&) { - GDragOperation::notify_cancelled({}); + DragOperation::notify_cancelled({}); } -void GWindowServerConnection::handle(const WindowClient::WindowStateChanged& message) +void WindowServerConnection::handle(const WindowClient::WindowStateChanged& message) { - if (auto* window = GWindow::from_window_id(message.window_id())) + if (auto* window = Window::from_window_id(message.window_id())) window->notify_state_changed({}, message.minimized(), message.occluded()); } + +} diff --git a/Libraries/LibGUI/GWindowServerConnection.h b/Libraries/LibGUI/GWindowServerConnection.h index 19b112b2b4..6355c6ab95 100644 --- a/Libraries/LibGUI/GWindowServerConnection.h +++ b/Libraries/LibGUI/GWindowServerConnection.h @@ -30,19 +30,21 @@ #include <WindowServer/WindowClientEndpoint.h> #include <WindowServer/WindowServerEndpoint.h> -class GWindowServerConnection +namespace GUI { + +class WindowServerConnection : public IServerConnection<WindowClientEndpoint, WindowServerEndpoint> , public WindowClientEndpoint { - C_OBJECT(GWindowServerConnection) + C_OBJECT(WindowServerConnection) public: - GWindowServerConnection() + WindowServerConnection() : IServerConnection(*this, "/tmp/portal/window") { handshake(); } virtual void handshake() override; - static GWindowServerConnection& the(); + static WindowServerConnection& the(); private: virtual void handle(const WindowClient::Paint&) override; @@ -73,3 +75,5 @@ private: virtual void handle(const WindowClient::UpdateSystemTheme&) override; virtual void handle(const WindowClient::WindowStateChanged&) override; }; + +} diff --git a/Libraries/LibGUI/GWindowType.h b/Libraries/LibGUI/GWindowType.h index a0166ba52f..4099dc5ebe 100644 --- a/Libraries/LibGUI/GWindowType.h +++ b/Libraries/LibGUI/GWindowType.h @@ -26,8 +26,10 @@ #pragma once +namespace GUI { + // Keep this in sync with WSWindowType. -enum class GWindowType { +enum class WindowType { Invalid = 0, Normal, Menu, @@ -37,3 +39,5 @@ enum class GWindowType { Menubar, MenuApplet, }; + +} diff --git a/Libraries/LibHTML/DOM/HTMLInputElement.cpp b/Libraries/LibHTML/DOM/HTMLInputElement.cpp index 84c2cb899f..fa0e3ef4f3 100644 --- a/Libraries/LibHTML/DOM/HTMLInputElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLInputElement.cpp @@ -49,9 +49,9 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*) ASSERT(frame.html_view()); auto& html_view = const_cast<HtmlView&>(*frame.html_view()); - RefPtr<GWidget> widget; + RefPtr<GUI::Widget> widget; if (type() == "submit") { - auto button = GButton::construct(value(), &html_view); + auto button = GUI::Button::construct(value(), &html_view); int text_width = Font::default_font().width(value()); button->set_relative_rect(0, 0, text_width + 20, 20); button->on_click = [this](auto&) { @@ -62,11 +62,11 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*) }; widget = button; } else { - auto text_box = GTextBox::construct(&html_view); + auto text_box = GUI::TextBox::construct(&html_view); text_box->set_text(value()); text_box->on_change = [this] { auto& widget = to<LayoutWidget>(layout_node())->widget(); - const_cast<HTMLInputElement*>(this)->set_attribute("value", static_cast<const GTextBox&>(widget).text()); + const_cast<HTMLInputElement*>(this)->set_attribute("value", static_cast<const GUI::TextBox&>(widget).text()); }; int text_width = Font::default_font().width(value()); text_box->set_relative_rect(0, 0, text_width + 20, 20); diff --git a/Libraries/LibHTML/DOMTreeModel.cpp b/Libraries/LibHTML/DOMTreeModel.cpp index 36e076d3f4..a6aaac033f 100644 --- a/Libraries/LibHTML/DOMTreeModel.cpp +++ b/Libraries/LibHTML/DOMTreeModel.cpp @@ -44,7 +44,7 @@ DOMTreeModel::~DOMTreeModel() { } -GModelIndex DOMTreeModel::index(int row, int column, const GModelIndex& parent) const +GUI::ModelIndex DOMTreeModel::index(int row, int column, const GUI::ModelIndex& parent) const { if (!parent.is_valid()) { return create_index(row, column, m_document.ptr()); @@ -53,7 +53,7 @@ GModelIndex DOMTreeModel::index(int row, int column, const GModelIndex& parent) return create_index(row, column, parent_node.child_at_index(row)); } -GModelIndex DOMTreeModel::parent_index(const GModelIndex& index) const +GUI::ModelIndex DOMTreeModel::parent_index(const GUI::ModelIndex& index) const { if (!index.is_valid()) return {}; @@ -67,7 +67,7 @@ GModelIndex DOMTreeModel::parent_index(const GModelIndex& index) const } // Walk the grandparent's children to find the index of node's parent in its parent. - // (This is needed to produce the row number of the GModelIndex corresponding to node's parent.) + // (This is needed to produce the row number of the GUI::ModelIndex corresponding to node's parent.) int grandparent_child_index = 0; for (auto* grandparent_child = node.parent()->parent()->first_child(); grandparent_child; grandparent_child = grandparent_child->next_sibling()) { if (grandparent_child == node.parent()) @@ -79,7 +79,7 @@ GModelIndex DOMTreeModel::parent_index(const GModelIndex& index) const return {}; } -int DOMTreeModel::row_count(const GModelIndex& index) const +int DOMTreeModel::row_count(const GUI::ModelIndex& index) const { if (!index.is_valid()) return 1; @@ -87,7 +87,7 @@ int DOMTreeModel::row_count(const GModelIndex& index) const return node.child_count(); } -int DOMTreeModel::column_count(const GModelIndex&) const +int DOMTreeModel::column_count(const GUI::ModelIndex&) const { return 1; } @@ -113,7 +113,7 @@ static String with_whitespace_collapsed(const StringView& string) return builder.to_string(); } -GVariant DOMTreeModel::data(const GModelIndex& index, Role role) const +GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const { auto& node = *static_cast<Node*>(index.internal_data()); if (role == Role::Icon) { diff --git a/Libraries/LibHTML/DOMTreeModel.h b/Libraries/LibHTML/DOMTreeModel.h index 02b7de9a1d..17cf1d0677 100644 --- a/Libraries/LibHTML/DOMTreeModel.h +++ b/Libraries/LibHTML/DOMTreeModel.h @@ -30,7 +30,7 @@ class Document; -class DOMTreeModel final : public GModel { +class DOMTreeModel final : public GUI::Model { public: static NonnullRefPtr<DOMTreeModel> create(Document& document) { @@ -39,11 +39,11 @@ public: virtual ~DOMTreeModel() override; - virtual int row_count(const GModelIndex& = GModelIndex()) const override; - virtual int column_count(const GModelIndex& = GModelIndex()) const override; - virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; - virtual GModelIndex index(int row, int column, const GModelIndex& parent = GModelIndex()) const override; - virtual GModelIndex parent_index(const GModelIndex&) const override; + virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; + virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override; + virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override; + virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual void update() override; private: diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp index ef85b0ea6b..86f2377d94 100644 --- a/Libraries/LibHTML/HtmlView.cpp +++ b/Libraries/LibHTML/HtmlView.cpp @@ -46,9 +46,9 @@ #include <LibHTML/ResourceLoader.h> #include <stdio.h> -HtmlView::HtmlView(GWidget* parent) - : GScrollableWidget(parent) - , m_main_frame(Frame::create(*this)) +HtmlView::HtmlView(GUI::Widget* parent) + : GUI::ScrollableWidget(parent) + , m_main_frame(::Frame::create(*this)) { main_frame().on_set_needs_display = [this](auto& content_rect) { if (content_rect.is_empty()) { @@ -129,17 +129,17 @@ void HtmlView::layout_and_sync_size() #endif } -void HtmlView::resize_event(GResizeEvent& event) +void HtmlView::resize_event(GUI::ResizeEvent& event) { - GScrollableWidget::resize_event(event); + GUI::ScrollableWidget::resize_event(event); layout_and_sync_size(); } -void HtmlView::paint_event(GPaintEvent& event) +void HtmlView::paint_event(GUI::PaintEvent& event) { - GFrame::paint_event(event); + GUI::Frame::paint_event(event); - GPainter painter(*this); + GUI::Painter painter(*this); painter.add_clip_rect(widget_inner_rect()); painter.add_clip_rect(event.rect()); @@ -163,10 +163,10 @@ void HtmlView::paint_event(GPaintEvent& event) layout_root()->render(context); } -void HtmlView::mousemove_event(GMouseEvent& event) +void HtmlView::mousemove_event(GUI::MouseEvent& event) { if (!layout_root()) - return GScrollableWidget::mousemove_event(event); + return GUI::ScrollableWidget::mousemove_event(event); bool hovered_node_changed = false; bool is_hovering_link = false; @@ -193,15 +193,15 @@ void HtmlView::mousemove_event(GMouseEvent& event) } } if (window()) - window()->set_override_cursor(is_hovering_link ? GStandardCursor::Hand : GStandardCursor::None); + window()->set_override_cursor(is_hovering_link ? GUI::StandardCursor::Hand : GUI::StandardCursor::None); if (hovered_node_changed) { update(); auto* hovered_html_element = document()->hovered_node() ? document()->hovered_node()->enclosing_html_element() : nullptr; if (hovered_html_element && !hovered_html_element->title().is_null()) { auto screen_position = screen_relative_rect().location().translated(event.position()); - GApplication::the().show_tooltip(hovered_html_element->title(), screen_position.translated(4, 4)); + GUI::Application::the().show_tooltip(hovered_html_element->title(), screen_position.translated(4, 4)); } else { - GApplication::the().hide_tooltip(); + GUI::Application::the().hide_tooltip(); } } if (is_hovering_link != was_hovering_link) { @@ -212,10 +212,10 @@ void HtmlView::mousemove_event(GMouseEvent& event) event.accept(); } -void HtmlView::mousedown_event(GMouseEvent& event) +void HtmlView::mousedown_event(GUI::MouseEvent& event) { if (!layout_root()) - return GScrollableWidget::mousemove_event(event); + return GUI::ScrollableWidget::mousemove_event(event); bool hovered_node_changed = false; auto result = layout_root()->hit_test(to_content_position(event.position())); @@ -229,7 +229,7 @@ void HtmlView::mousedown_event(GMouseEvent& event) if (on_link_click) on_link_click(link->href()); } else { - if (event.button() == GMouseButton::Left) { + if (event.button() == GUI::MouseButton::Left) { layout_root()->selection().set({ result.layout_node, result.index_in_node }, {}); dump_selection("MouseDown"); m_in_mouse_selection = true; @@ -242,18 +242,18 @@ void HtmlView::mousedown_event(GMouseEvent& event) event.accept(); } -void HtmlView::mouseup_event(GMouseEvent& event) +void HtmlView::mouseup_event(GUI::MouseEvent& event) { if (!layout_root()) - return GScrollableWidget::mouseup_event(event); + return GUI::ScrollableWidget::mouseup_event(event); - if (event.button() == GMouseButton::Left) { + if (event.button() == GUI::MouseButton::Left) { dump_selection("MouseUp"); m_in_mouse_selection = false; } } -void HtmlView::keydown_event(GKeyEvent& event) +void HtmlView::keydown_event(GUI::KeyEvent& event) { if (event.modifiers() == 0) { switch (event.key()) { @@ -327,7 +327,7 @@ void HtmlView::load(const URL& url) dbg() << "HtmlView::load: " << url; if (window()) - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(GUI::StandardCursor::None); if (on_load_start) on_load_start(url); @@ -390,7 +390,7 @@ void HtmlView::scroll_to_anchor(const StringView& name) auto& layout_node = *element->layout_node(); FloatRect float_rect { layout_node.box_type_agnostic_position(), { (float)visible_content_rect().width(), (float)visible_content_rect().height() } }; scroll_into_view(enclosing_int_rect(float_rect), true, true); - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(GUI::StandardCursor::None); } Document* HtmlView::document() diff --git a/Libraries/LibHTML/HtmlView.h b/Libraries/LibHTML/HtmlView.h index a2e08ade18..8b165d2778 100644 --- a/Libraries/LibHTML/HtmlView.h +++ b/Libraries/LibHTML/HtmlView.h @@ -23,7 +23,6 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #pragma once #include <AK/URL.h> @@ -32,7 +31,7 @@ class Frame; -class HtmlView : public GScrollableWidget { +class HtmlView : public GUI::ScrollableWidget { C_OBJECT(HtmlView) public: virtual ~HtmlView() override; @@ -44,8 +43,8 @@ public: const LayoutDocument* layout_root() const; LayoutDocument* layout_root(); - Frame& main_frame() { return *m_main_frame; } - const Frame& main_frame() const { return *m_main_frame; } + ::Frame& main_frame() { return *m_main_frame; } + const ::Frame& main_frame() const { return *m_main_frame; } void reload(); void load(const URL&); @@ -63,14 +62,14 @@ public: virtual bool accepts_focus() const override { return true; } protected: - HtmlView(GWidget* parent = nullptr); + HtmlView(GUI::Widget* parent = nullptr); - virtual void resize_event(GResizeEvent&) override; - virtual void paint_event(GPaintEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mouseup_event(GMouseEvent&) override; - virtual void keydown_event(GKeyEvent&) override; + virtual void resize_event(GUI::ResizeEvent&) override; + virtual void paint_event(GUI::PaintEvent&) override; + virtual void mousemove_event(GUI::MouseEvent&) override; + virtual void mousedown_event(GUI::MouseEvent&) override; + virtual void mouseup_event(GUI::MouseEvent&) override; + virtual void keydown_event(GUI::KeyEvent&) override; private: virtual void did_scroll() override; @@ -78,7 +77,7 @@ private: void layout_and_sync_size(); void dump_selection(const char* event_name); - RefPtr<Frame> m_main_frame; + RefPtr<::Frame> m_main_frame; bool m_should_show_line_box_borders { false }; bool m_in_mouse_selection { false }; diff --git a/Libraries/LibHTML/Layout/LayoutWidget.cpp b/Libraries/LibHTML/Layout/LayoutWidget.cpp index 5c77b75247..b4ba2cde78 100644 --- a/Libraries/LibHTML/Layout/LayoutWidget.cpp +++ b/Libraries/LibHTML/Layout/LayoutWidget.cpp @@ -30,7 +30,7 @@ #include <LibGUI/GWidget.h> #include <LibHTML/Layout/LayoutWidget.h> -LayoutWidget::LayoutWidget(const Element& element, GWidget& widget) +LayoutWidget::LayoutWidget(const Element& element, GUI::Widget& widget) : LayoutReplaced(element, StyleProperties::create()) , m_widget(widget) { diff --git a/Libraries/LibHTML/Layout/LayoutWidget.h b/Libraries/LibHTML/Layout/LayoutWidget.h index c113fc26be..15c73f6417 100644 --- a/Libraries/LibHTML/Layout/LayoutWidget.h +++ b/Libraries/LibHTML/Layout/LayoutWidget.h @@ -28,25 +28,27 @@ #include <LibHTML/Layout/LayoutReplaced.h> -class GWidget; +namespace GUI { +class Widget; +} class LayoutWidget : public LayoutReplaced { public: - LayoutWidget(const Element&, GWidget&); + LayoutWidget(const Element&, GUI::Widget&); virtual ~LayoutWidget() override; virtual void layout() override; virtual void render(RenderingContext&) override; - GWidget& widget() { return m_widget; } - const GWidget& widget() const { return m_widget; } + GUI::Widget& widget() { return m_widget; } + const GUI::Widget& widget() const { return m_widget; } virtual bool is_widget() const final { return true; } private: virtual const char* class_name() const override { return "LayoutWidget"; } - NonnullRefPtr<GWidget> m_widget; + NonnullRefPtr<GUI::Widget> m_widget; }; template<> diff --git a/Libraries/LibHTML/RenderingContext.h b/Libraries/LibHTML/RenderingContext.h index f515bd04e4..67df337180 100644 --- a/Libraries/LibHTML/RenderingContext.h +++ b/Libraries/LibHTML/RenderingContext.h @@ -29,17 +29,19 @@ #include <LibDraw/Palette.h> #include <LibDraw/Rect.h> -class GPainter; +namespace GUI { +class Painter; +} class RenderingContext { public: - explicit RenderingContext(GPainter& painter, const Palette& palette) + explicit RenderingContext(GUI::Painter& painter, const Palette& palette) : m_painter(painter) , m_palette(palette) { } - GPainter& painter() const { return m_painter; } + GUI::Painter& painter() const { return m_painter; } const Palette& palette() const { return m_palette; } bool should_show_line_box_borders() const { return m_should_show_line_box_borders; } @@ -49,7 +51,7 @@ public: void set_viewport_rect(const Rect& rect) { m_viewport_rect = rect; } private: - GPainter& m_painter; + GUI::Painter& m_painter; Palette m_palette; Rect m_viewport_rect; bool m_should_show_line_box_borders { false }; diff --git a/Libraries/LibHTML/StylePropertiesModel.cpp b/Libraries/LibHTML/StylePropertiesModel.cpp index e3ade70cde..f2b0b4f221 100644 --- a/Libraries/LibHTML/StylePropertiesModel.cpp +++ b/Libraries/LibHTML/StylePropertiesModel.cpp @@ -40,7 +40,7 @@ StylePropertiesModel::StylePropertiesModel(const StyleProperties& properties) }); } -int StylePropertiesModel::row_count(const GModelIndex&) const +int StylePropertiesModel::row_count(const GUI::ModelIndex&) const { return m_values.size(); } @@ -56,7 +56,7 @@ String StylePropertiesModel::column_name(int column_index) const ASSERT_NOT_REACHED(); } } -GVariant StylePropertiesModel::data(const GModelIndex& index, Role role) const +GUI::Variant StylePropertiesModel::data(const GUI::ModelIndex& index, Role role) const { auto& value = m_values[index.row()]; if (role == Role::Display) { diff --git a/Libraries/LibHTML/StylePropertiesModel.h b/Libraries/LibHTML/StylePropertiesModel.h index 2c70f1f2d5..5a8ed15284 100644 --- a/Libraries/LibHTML/StylePropertiesModel.h +++ b/Libraries/LibHTML/StylePropertiesModel.h @@ -29,7 +29,7 @@ class StyleProperties; -class StylePropertiesModel final : public GModel { +class StylePropertiesModel final : public GUI::Model { public: enum Column { PropertyName, @@ -39,10 +39,10 @@ public: static NonnullRefPtr<StylePropertiesModel> create(const StyleProperties& properties) { return adopt(*new StylePropertiesModel(properties)); } - virtual int row_count(const GModelIndex& = GModelIndex()) const override; - virtual int column_count(const GModelIndex& = GModelIndex()) const override { return Column::__Count; } + virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; + virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; } virtual String column_name(int) const override; - virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override; virtual void update() override; private: diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp index 933c8be176..364ff8af35 100644 --- a/Libraries/LibVT/TerminalWidget.cpp +++ b/Libraries/LibVT/TerminalWidget.cpp @@ -61,7 +61,7 @@ void TerminalWidget::set_pty_master_fd(int fd) if (nread < 0) { dbgprintf("Terminal read error: %s\n", strerror(errno)); perror("read(ptm)"); - GApplication::the().quit(1); + GUI::Application::the().quit(1); return; } if (nread == 0) { @@ -94,7 +94,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co set_frame_shadow(FrameShadow::Sunken); set_frame_thickness(2); - m_scrollbar = GScrollBar::construct(Orientation::Vertical, this); + m_scrollbar = GUI::ScrollBar::construct(Orientation::Vertical, this); m_scrollbar->set_relative_rect(0, 0, 16, 0); m_scrollbar->on_change = [this](int) { force_repaint(); @@ -119,11 +119,11 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co m_terminal.set_size(m_config->read_num_entry("Window", "Width", 80), m_config->read_num_entry("Window", "Height", 25)); - m_copy_action = GAction::create("Copy", { Mod_Ctrl | Mod_Shift, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [this](auto&) { + m_copy_action = GUI::Action::create("Copy", { Mod_Ctrl | Mod_Shift, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [this](auto&) { copy(); }); - m_paste_action = GAction::create("Paste", { Mod_Ctrl | Mod_Shift, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), [this](auto&) { + m_paste_action = GUI::Action::create("Paste", { Mod_Ctrl | Mod_Shift, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), [this](auto&) { paste(); }); } @@ -168,29 +168,29 @@ void TerminalWidget::set_logical_focus(bool focus) void TerminalWidget::focusin_event(Core::Event& event) { set_logical_focus(true); - return GFrame::focusin_event(event); + return GUI::Frame::focusin_event(event); } void TerminalWidget::focusout_event(Core::Event& event) { set_logical_focus(false); - return GFrame::focusout_event(event); + return GUI::Frame::focusout_event(event); } void TerminalWidget::event(Core::Event& event) { - if (event.type() == GEvent::WindowBecameActive) + if (event.type() == GUI::Event::WindowBecameActive) set_logical_focus(true); - else if (event.type() == GEvent::WindowBecameInactive) + else if (event.type() == GUI::Event::WindowBecameInactive) set_logical_focus(false); - return GFrame::event(event); + return GUI::Frame::event(event); } -void TerminalWidget::keydown_event(GKeyEvent& event) +void TerminalWidget::keydown_event(GUI::KeyEvent& event) { if (m_ptm_fd == -1) { event.ignore(); - return GFrame::keydown_event(event); + return GUI::Frame::keydown_event(event); } // Reset timer so cursor doesn't blink while typing. @@ -274,11 +274,11 @@ void TerminalWidget::keydown_event(GKeyEvent& event) m_scrollbar->set_value(m_scrollbar->max()); } -void TerminalWidget::paint_event(GPaintEvent& event) +void TerminalWidget::paint_event(GUI::PaintEvent& event) { - GFrame::paint_event(event); + GUI::Frame::paint_event(event); - GPainter painter(*this); + GUI::Painter painter(*this); painter.add_clip_rect(event.rect()); @@ -415,7 +415,7 @@ void TerminalWidget::force_repaint() update(); } -void TerminalWidget::resize_event(GResizeEvent& event) +void TerminalWidget::resize_event(GUI::ResizeEvent& event) { relayout(event.size()); } @@ -446,7 +446,7 @@ Size TerminalWidget::compute_base_size() const return { base_width, base_height }; } -void TerminalWidget::apply_size_increments_to_window(GWindow& window) +void TerminalWidget::apply_size_increments_to_window(GUI::Window& window) { window.set_size_increment({ font().glyph_width('x'), m_line_height }); window.set_base_size(compute_base_size()); @@ -511,9 +511,9 @@ VT::Position TerminalWidget::buffer_position_at(const Point& position) const return { row, column }; } -void TerminalWidget::doubleclick_event(GMouseEvent& event) +void TerminalWidget::doubleclick_event(GUI::MouseEvent& event) { - if (event.button() == GMouseButton::Left) { + if (event.button() == GUI::MouseButton::Left) { m_triple_click_timer.start(); auto position = buffer_position_at(event.position()); @@ -534,14 +534,14 @@ void TerminalWidget::doubleclick_event(GMouseEvent& event) m_selection_start = { position.row(), start_column }; m_selection_end = { position.row(), end_column }; } - GFrame::doubleclick_event(event); + GUI::Frame::doubleclick_event(event); } void TerminalWidget::paste() { if (m_ptm_fd == -1) return; - auto text = GClipboard::the().data(); + auto text = GUI::Clipboard::the().data(); if (text.is_empty()) return; int nwritten = write(m_ptm_fd, text.characters(), text.length()); @@ -554,12 +554,12 @@ void TerminalWidget::paste() void TerminalWidget::copy() { if (has_selection()) - GClipboard::the().set_data(selected_text()); + GUI::Clipboard::the().set_data(selected_text()); } -void TerminalWidget::mousedown_event(GMouseEvent& event) +void TerminalWidget::mousedown_event(GUI::MouseEvent& event) { - if (event.button() == GMouseButton::Left) { + if (event.button() == GUI::MouseButton::Left) { if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) { int start_column = 0; int end_column = m_terminal.columns() - 1; @@ -575,9 +575,9 @@ void TerminalWidget::mousedown_event(GMouseEvent& event) } } -void TerminalWidget::mousemove_event(GMouseEvent& event) +void TerminalWidget::mousemove_event(GUI::MouseEvent& event) { - if (!(event.buttons() & GMouseButton::Left)) + if (!(event.buttons() & GUI::MouseButton::Left)) return; auto old_selection_end = m_selection_end; @@ -586,12 +586,12 @@ void TerminalWidget::mousemove_event(GMouseEvent& event) update(); } -void TerminalWidget::mousewheel_event(GMouseEvent& event) +void TerminalWidget::mousewheel_event(GUI::MouseEvent& event) { if (!is_scrollable()) return; m_scrollbar->set_value(m_scrollbar->value() + event.wheel_delta()); - GFrame::mousewheel_event(event); + GUI::Frame::mousewheel_event(event); } bool TerminalWidget::is_scrollable() const @@ -649,7 +649,7 @@ void TerminalWidget::terminal_did_resize(u16 columns, u16 rows) m_pixel_height = (frame_thickness() * 2) + (m_inset * 2) + (rows * (font().glyph_height() + m_line_spacing)); if (m_automatic_size_policy) { - set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); + set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); set_preferred_size(m_pixel_width, m_pixel_height); } @@ -686,17 +686,17 @@ void TerminalWidget::emit_char(u8 ch) } } -void TerminalWidget::context_menu_event(GContextMenuEvent& event) +void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event) { if (!m_context_menu) { - m_context_menu = GMenu::construct(); + m_context_menu = GUI::Menu::construct(); m_context_menu->add_action(copy_action()); m_context_menu->add_action(paste_action()); } m_context_menu->popup(event.screen_position()); } -void TerminalWidget::drop_event(GDropEvent& event) +void TerminalWidget::drop_event(GUI::DropEvent& event) { if (event.data_type() == "text") { event.accept(); @@ -719,7 +719,7 @@ void TerminalWidget::drop_event(GDropEvent& event) void TerminalWidget::did_change_font() { - GFrame::did_change_font(); + GUI::Frame::did_change_font(); m_line_height = font().glyph_height() + m_line_spacing; // TODO: try to find a bold version of the new font (e.g. CsillaThin7x10 -> CsillaBold7x10) diff --git a/Libraries/LibVT/TerminalWidget.h b/Libraries/LibVT/TerminalWidget.h index abae678816..1dcd24b8bf 100644 --- a/Libraries/LibVT/TerminalWidget.h +++ b/Libraries/LibVT/TerminalWidget.h @@ -35,9 +35,11 @@ #include <LibGUI/GFrame.h> #include <LibVT/Terminal.h> -class GScrollBar; +namespace GUI { +class ScrollBar; +} -class TerminalWidget final : public GFrame +class TerminalWidget final : public GUI::Frame , public VT::TerminalClient { C_OBJECT(TerminalWidget) public: @@ -56,7 +58,7 @@ public: void flush_dirty_lines(); void force_repaint(); - void apply_size_increments_to_window(GWindow&); + void apply_size_increments_to_window(GUI::Window&); const Font& bold_font() const { return *m_bold_font; } @@ -76,8 +78,8 @@ public: bool is_scrollable() const; - GAction& copy_action() { return *m_copy_action; } - GAction& paste_action() { return *m_paste_action; } + GUI::Action& copy_action() { return *m_copy_action; } + GUI::Action& paste_action() { return *m_paste_action; } void copy(); void paste(); @@ -88,19 +90,19 @@ public: Function<void()> on_command_exit; private: - // ^GWidget + // ^GUI::Widget virtual void event(Core::Event&) override; - virtual void paint_event(GPaintEvent&) override; - virtual void resize_event(GResizeEvent&) override; - virtual void keydown_event(GKeyEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - virtual void mousemove_event(GMouseEvent&) override; - virtual void mousewheel_event(GMouseEvent&) override; - virtual void doubleclick_event(GMouseEvent&) override; + virtual void paint_event(GUI::PaintEvent&) override; + virtual void resize_event(GUI::ResizeEvent&) override; + virtual void keydown_event(GUI::KeyEvent&) override; + virtual void mousedown_event(GUI::MouseEvent&) override; + virtual void mousemove_event(GUI::MouseEvent&) override; + virtual void mousewheel_event(GUI::MouseEvent&) override; + virtual void doubleclick_event(GUI::MouseEvent&) override; virtual void focusin_event(Core::Event&) override; virtual void focusout_event(Core::Event&) override; - virtual void context_menu_event(GContextMenuEvent&) override; - virtual void drop_event(GDropEvent&) override; + virtual void context_menu_event(GUI::ContextMenuEvent&) override; + virtual void drop_event(GUI::DropEvent&) override; virtual void did_change_font() override; // ^TerminalClient @@ -158,12 +160,12 @@ private: RefPtr<Core::Timer> m_visual_beep_timer; RefPtr<Core::ConfigFile> m_config; - RefPtr<GScrollBar> m_scrollbar; + RefPtr<GUI::ScrollBar> m_scrollbar; - RefPtr<GAction> m_copy_action; - RefPtr<GAction> m_paste_action; + RefPtr<GUI::Action> m_copy_action; + RefPtr<GUI::Action> m_paste_action; - RefPtr<GMenu> m_context_menu; + RefPtr<GUI::Menu> m_context_menu; Core::ElapsedTimer m_triple_click_timer; }; |