diff options
Diffstat (limited to 'Applications/HexEditor')
-rw-r--r-- | Applications/HexEditor/HexEditor.cpp | 38 | ||||
-rw-r--r-- | Applications/HexEditor/HexEditor.h | 20 | ||||
-rw-r--r-- | Applications/HexEditor/HexEditorWidget.cpp | 84 | ||||
-rw-r--r-- | Applications/HexEditor/HexEditorWidget.h | 21 | ||||
-rw-r--r-- | Applications/HexEditor/main.cpp | 10 |
5 files changed, 88 insertions, 85 deletions
diff --git a/Applications/HexEditor/HexEditor.cpp b/Applications/HexEditor/HexEditor.cpp index d5f3514ce2..a965009484 100644 --- a/Applications/HexEditor/HexEditor.cpp +++ b/Applications/HexEditor/HexEditor.cpp @@ -41,8 +41,8 @@ #include <stdio.h> #include <unistd.h> -HexEditor::HexEditor(GWidget* parent) - : GScrollableWidget(parent) +HexEditor::HexEditor(GUI::Widget* parent) + : ScrollableWidget(parent) { set_frame_shape(FrameShape::Container); set_frame_shadow(FrameShadow::Sunken); @@ -139,7 +139,7 @@ bool HexEditor::copy_selected_hex_to_clipboard() output_string_builder.appendf("%02X ", m_buffer.data()[i]); } - GClipboard::the().set_data(output_string_builder.to_string()); + GUI::Clipboard::the().set_data(output_string_builder.to_string()); return true; } @@ -153,7 +153,7 @@ bool HexEditor::copy_selected_text_to_clipboard() output_string_builder.appendf("%c", isprint(m_buffer.data()[i]) ? m_buffer[i] : '.'); } - GClipboard::the().set_data(output_string_builder.to_string()); + GUI::Clipboard::the().set_data(output_string_builder.to_string()); return true; } @@ -176,7 +176,7 @@ bool HexEditor::copy_selected_hex_to_clipboard_as_c_code() } output_string_builder.append("\n};\n"); - GClipboard::the().set_data(output_string_builder.to_string()); + GUI::Clipboard::the().set_data(output_string_builder.to_string()); return true; } @@ -195,9 +195,9 @@ void HexEditor::set_content_length(int length) set_content_size({ offset_margin_width() + (m_bytes_per_row * (character_width() * 3)) + 10 + (m_bytes_per_row * character_width()) + 20, total_rows() * line_height() + 10 }); } -void HexEditor::mousedown_event(GMouseEvent& event) +void HexEditor::mousedown_event(GUI::MouseEvent& event) { - if (event.button() != GMouseButton::Left) { + if (event.button() != GUI::MouseButton::Left) { return; } @@ -259,7 +259,7 @@ void HexEditor::mousedown_event(GMouseEvent& event) } } -void HexEditor::mousemove_event(GMouseEvent& event) +void HexEditor::mousemove_event(GUI::MouseEvent& event) { auto absolute_x = horizontal_scrollbar().value() + event.x(); auto absolute_y = vertical_scrollbar().value() + event.y(); @@ -274,12 +274,12 @@ void HexEditor::mousemove_event(GMouseEvent& event) auto text_end_x = text_start_x + (bytes_per_row() * character_width()); auto text_end_y = text_start_y + 5 + (total_rows() * line_height()); - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(GUI::StandardCursor::None); if ((absolute_x >= hex_start_x && absolute_x <= hex_end_x && absolute_y >= hex_start_y && absolute_y <= hex_end_y) || (absolute_x >= text_start_x && absolute_x <= text_end_x && absolute_y >= text_start_y && absolute_y <= text_end_y)) { - window()->set_override_cursor(GStandardCursor::IBeam); + window()->set_override_cursor(GUI::StandardCursor::IBeam); } if (m_in_drag_select) { @@ -311,9 +311,9 @@ void HexEditor::mousemove_event(GMouseEvent& event) } } -void HexEditor::mouseup_event(GMouseEvent& event) +void HexEditor::mouseup_event(GUI::MouseEvent& event) { - if (event.button() == GMouseButton::Left) { + if (event.button() == GUI::MouseButton::Left) { if (m_in_drag_select) { if (m_selection_end == -1 || m_selection_start == -1) { m_selection_start = -1; @@ -344,7 +344,7 @@ void HexEditor::scroll_position_into_view(int position) scroll_into_view(rect, true, true); } -void HexEditor::keydown_event(GKeyEvent& event) +void HexEditor::keydown_event(GUI::KeyEvent& event) { #ifdef HEX_DEBUG printf("HexEditor::keydown_event key=%d\n", event.key()); @@ -414,7 +414,7 @@ void HexEditor::keydown_event(GKeyEvent& event) } } -void HexEditor::hex_mode_keydown_event(GKeyEvent& event) +void HexEditor::hex_mode_keydown_event(GUI::KeyEvent& event) { if ((event.key() >= KeyCode::Key_0 && event.key() <= KeyCode::Key_9) || (event.key() >= KeyCode::Key_A && event.key() <= KeyCode::Key_F)) { @@ -439,7 +439,7 @@ void HexEditor::hex_mode_keydown_event(GKeyEvent& event) } } -void HexEditor::text_mode_keydown_event(GKeyEvent& event) +void HexEditor::text_mode_keydown_event(GUI::KeyEvent& event) { m_tracked_changes.set(m_position, m_buffer.data()[m_position]); m_buffer.data()[m_position] = (u8)event.text().characters()[0]; // save the first 4 bits, OR the new value in the last 4 @@ -462,11 +462,11 @@ void HexEditor::did_change() on_change(); } -void HexEditor::paint_event(GPaintEvent& event) +void HexEditor::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()); painter.fill_rect(event.rect(), Color::White); @@ -567,5 +567,5 @@ void HexEditor::paint_event(GPaintEvent& event) void HexEditor::leave_event(Core::Event&) { ASSERT(window()); - window()->set_override_cursor(GStandardCursor::None); + window()->set_override_cursor(GUI::StandardCursor::None); } diff --git a/Applications/HexEditor/HexEditor.h b/Applications/HexEditor/HexEditor.h index f570e0406e..78b1bbd95b 100644 --- a/Applications/HexEditor/HexEditor.h +++ b/Applications/HexEditor/HexEditor.h @@ -34,7 +34,7 @@ #include <LibDraw/TextAlignment.h> #include <LibGUI/GScrollableWidget.h> -class HexEditor : public GScrollableWidget { +class HexEditor : public GUI::ScrollableWidget { C_OBJECT(HexEditor) public: enum EditMode { @@ -65,13 +65,13 @@ public: Function<void()> on_change; protected: - HexEditor(GWidget* parent); + HexEditor(GUI::Widget* 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 keydown_event(GKeyEvent&) override; + virtual void paint_event(GUI::PaintEvent&) override; + virtual void mousedown_event(GUI::MouseEvent&) override; + virtual void mouseup_event(GUI::MouseEvent&) override; + virtual void mousemove_event(GUI::MouseEvent&) override; + virtual void keydown_event(GUI::KeyEvent&) override; virtual bool accepts_focus() const override { return true; } virtual void leave_event(Core::Event&) override; @@ -97,10 +97,10 @@ private: int character_width() const { return font().glyph_width('W'); } int offset_margin_width() const { return 80; } - void hex_mode_keydown_event(GKeyEvent&); - void text_mode_keydown_event(GKeyEvent&); + void hex_mode_keydown_event(GUI::KeyEvent&); + void text_mode_keydown_event(GUI::KeyEvent&); void set_content_length(int); // I might make this public if I add fetching data on demand. void update_status(); void did_change(); -};
\ No newline at end of file +}; diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 240e0bfdd5..eb548ba7b4 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -46,7 +46,7 @@ HexEditorWidget::HexEditorWidget() { - set_layout(make<GVBoxLayout>()); + set_layout(make<GUI::VBoxLayout>()); layout()->set_spacing(0); m_editor = HexEditor::construct(this); @@ -66,20 +66,20 @@ HexEditorWidget::HexEditorWidget() update_title(); }; - m_statusbar = GStatusBar::construct(5, this); + m_statusbar = GUI::StatusBar::construct(5, this); - m_new_action = GAction::create("New", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GAction&) { + m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) { if (m_document_dirty) { - auto save_document_first_box = GMessageBox::construct("Save Document First?", "Warning", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window()); + auto save_document_first_box = GUI::MessageBox::construct("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel, window()); auto save_document_first_result = save_document_first_box->exec(); - if (save_document_first_result != GDialog::ExecResult::ExecOK) + if (save_document_first_result != GUI::Dialog::ExecResult::ExecOK) return; m_save_action->activate(); } - auto input_box = GInputBox::construct("Enter new file size:", "New file size", this); - if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { + auto input_box = GUI::InputBox::construct("Enter new file size:", "New file size", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { auto valid = false; auto file_size = input_box->text_value().to_int(valid); if (valid && file_size > 0) { @@ -88,13 +88,13 @@ HexEditorWidget::HexEditorWidget() set_path(FileSystemPath()); update_title(); } else { - GMessageBox::show("Invalid file size entered.", "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); + GUI::MessageBox::show("Invalid file size entered.", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window()); } } }); - m_open_action = GCommonActions::make_open_action([this](auto&) { - Optional<String> open_path = GFilePicker::get_open_filepath(); + m_open_action = GUI::CommonActions::make_open_action([this](auto&) { + Optional<String> open_path = GUI::FilePicker::get_open_filepath(); if (!open_path.has_value()) return; @@ -102,10 +102,10 @@ HexEditorWidget::HexEditorWidget() open_file(open_path.value()); }); - m_save_action = GAction::create("Save", { Mod_Ctrl, Key_S }, GraphicsBitmap::load_from_file("/res/icons/16x16/save.png"), [&](const GAction&) { + m_save_action = GUI::Action::create("Save", { Mod_Ctrl, Key_S }, GraphicsBitmap::load_from_file("/res/icons/16x16/save.png"), [&](const GUI::Action&) { if (!m_path.is_empty()) { if (!m_editor->write_to_file(m_path)) { - GMessageBox::show("Unable to save file.\n", "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); + GUI::MessageBox::show("Unable to save file.\n", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window()); } else { m_document_dirty = false; update_title(); @@ -116,13 +116,13 @@ HexEditorWidget::HexEditorWidget() m_save_as_action->activate(); }); - m_save_as_action = GAction::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, GraphicsBitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GAction&) { - Optional<String> save_path = GFilePicker::get_save_filepath(m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "bin" : m_extension); + m_save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, GraphicsBitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GUI::Action&) { + Optional<String> save_path = GUI::FilePicker::get_save_filepath(m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "bin" : m_extension); if (!save_path.has_value()) return; if (!m_editor->write_to_file(save_path.value())) { - GMessageBox::show("Unable to save file.\n", "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); + GUI::MessageBox::show("Unable to save file.\n", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window()); return; } @@ -131,31 +131,31 @@ HexEditorWidget::HexEditorWidget() dbg() << "Wrote document to " << save_path.value(); }); - auto menubar = make<GMenuBar>(); - auto app_menu = GMenu::construct("Hex Editor"); + auto menubar = make<GUI::MenuBar>(); + auto app_menu = GUI::Menu::construct("Hex Editor"); app_menu->add_action(*m_new_action); app_menu->add_action(*m_open_action); app_menu->add_action(*m_save_action); app_menu->add_action(*m_save_as_action); app_menu->add_separator(); - app_menu->add_action(GCommonActions::make_quit_action([this](auto&) { + app_menu->add_action(GUI::CommonActions::make_quit_action([this](auto&) { if (!request_close()) return; - GApplication::the().quit(0); + GUI::Application::the().quit(0); })); menubar->add_menu(move(app_menu)); - auto bytes_per_row_menu = GMenu::construct("Bytes Per Row"); + auto bytes_per_row_menu = GUI::Menu::construct("Bytes Per Row"); for (int i = 8; i <= 32; i += 8) { - bytes_per_row_menu->add_action(GAction::create(String::number(i), [this, i](auto&) { + bytes_per_row_menu->add_action(GUI::Action::create(String::number(i), [this, i](auto&) { m_editor->set_bytes_per_row(i); m_editor->update(); })); } - m_goto_decimal_offset_action = GAction::create("Go To Offset (Decimal)...", { Mod_Ctrl | Mod_Shift, Key_G }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GAction&) { - auto input_box = GInputBox::construct("Enter Decimal offset:", "Go To", this); - if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { + m_goto_decimal_offset_action = GUI::Action::create("Go To Offset (Decimal)...", { Mod_Ctrl | Mod_Shift, Key_G }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GUI::Action&) { + auto input_box = GUI::InputBox::construct("Enter Decimal offset:", "Go To", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { auto valid = false; auto new_offset = input_box->text_value().to_int(valid); if (valid) { @@ -164,18 +164,18 @@ HexEditorWidget::HexEditorWidget() } }); - m_goto_hex_offset_action = GAction::create("Go To Offset (Hex)...", { Mod_Ctrl, Key_G }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GAction&) { - auto input_box = GInputBox::construct("Enter Hex offset:", "Go To", this); - if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { + m_goto_hex_offset_action = GUI::Action::create("Go To Offset (Hex)...", { Mod_Ctrl, Key_G }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GUI::Action&) { + auto input_box = GUI::InputBox::construct("Enter Hex offset:", "Go To", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { auto new_offset = strtol(input_box->text_value().characters(), nullptr, 16); m_editor->set_position(new_offset); } }); - auto edit_menu = GMenu::construct("Edit"); - edit_menu->add_action(GAction::create("Fill selection...", { Mod_Ctrl, Key_B }, [&](const GAction&) { - auto input_box = GInputBox::construct("Fill byte (hex):", "Fill Selection", this); - if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { + auto edit_menu = GUI::Menu::construct("Edit"); + edit_menu->add_action(GUI::Action::create("Fill selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { + auto input_box = GUI::InputBox::construct("Fill byte (hex):", "Fill Selection", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { auto fill_byte = strtol(input_box->text_value().characters(), nullptr, 16); m_editor->fill_selection(fill_byte); } @@ -184,29 +184,29 @@ HexEditorWidget::HexEditorWidget() edit_menu->add_action(*m_goto_decimal_offset_action); edit_menu->add_action(*m_goto_hex_offset_action); edit_menu->add_separator(); - edit_menu->add_action(GAction::create("Copy Hex", { Mod_Ctrl, Key_C }, [&](const GAction&) { + edit_menu->add_action(GUI::Action::create("Copy Hex", { Mod_Ctrl, Key_C }, [&](const GUI::Action&) { m_editor->copy_selected_hex_to_clipboard(); })); - edit_menu->add_action(GAction::create("Copy Text", { Mod_Ctrl | Mod_Shift, Key_C }, [&](const GAction&) { + edit_menu->add_action(GUI::Action::create("Copy Text", { Mod_Ctrl | Mod_Shift, Key_C }, [&](const GUI::Action&) { m_editor->copy_selected_text_to_clipboard(); })); edit_menu->add_separator(); - edit_menu->add_action(GAction::create("Copy As C Code", { Mod_Alt | Mod_Shift, Key_C }, [&](const GAction&) { + edit_menu->add_action(GUI::Action::create("Copy As C Code", { Mod_Alt | Mod_Shift, Key_C }, [&](const GUI::Action&) { m_editor->copy_selected_hex_to_clipboard_as_c_code(); })); menubar->add_menu(move(edit_menu)); - auto view_menu = GMenu::construct("View"); + auto view_menu = GUI::Menu::construct("View"); view_menu->add_submenu(move(bytes_per_row_menu)); menubar->add_menu(move(view_menu)); - auto help_menu = GMenu::construct("Help"); - help_menu->add_action(GAction::create("About", [&](const GAction&) { - GAboutDialog::show("Hex Editor", load_png("/res/icons/32x32/app-hexeditor.png"), window()); + auto help_menu = GUI::Menu::construct("Help"); + help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + GUI::AboutDialog::show("Hex Editor", load_png("/res/icons/32x32/app-hexeditor.png"), window()); })); menubar->add_menu(move(help_menu)); - GApplication::the().set_menubar(move(menubar)); + GUI::Application::the().set_menubar(move(menubar)); m_editor->set_focus(true); } @@ -237,7 +237,7 @@ void HexEditorWidget::open_file(const String& path) { auto file = Core::File::construct(path); if (!file->open(Core::IODevice::ReadOnly)) { - GMessageBox::show(String::format("Opening \"%s\" failed: %s", path.characters(), strerror(errno)), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); + GUI::MessageBox::show(String::format("Opening \"%s\" failed: %s", path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window()); return; } @@ -250,6 +250,6 @@ bool HexEditorWidget::request_close() { if (!m_document_dirty) return true; - auto result = GMessageBox::show("The file has been modified. Quit without saving?", "Quit without saving?", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window()); - return result == GMessageBox::ExecOK; + auto result = GUI::MessageBox::show("The file has been modified. Quit without saving?", "Quit without saving?", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel, window()); + return result == GUI::MessageBox::ExecOK; } diff --git a/Applications/HexEditor/HexEditorWidget.h b/Applications/HexEditor/HexEditorWidget.h index 081444fa46..9b1ee334ca 100644 --- a/Applications/HexEditor/HexEditorWidget.h +++ b/Applications/HexEditor/HexEditorWidget.h @@ -34,10 +34,13 @@ #include <LibGUI/GWidget.h> #include <LibGUI/GWindow.h> +namespace GUI { +class StatusBar; +} + class HexEditor; -class GStatusBar; -class HexEditorWidget final : public GWidget { +class HexEditorWidget final : public GUI::Widget { C_OBJECT(HexEditorWidget) public: virtual ~HexEditorWidget() override; @@ -53,14 +56,14 @@ private: String m_path; String m_name; String m_extension; - RefPtr<GAction> m_new_action; - RefPtr<GAction> m_open_action; - RefPtr<GAction> m_save_action; - RefPtr<GAction> m_save_as_action; - RefPtr<GAction> m_goto_decimal_offset_action; - RefPtr<GAction> m_goto_hex_offset_action; + RefPtr<GUI::Action> m_new_action; + RefPtr<GUI::Action> m_open_action; + RefPtr<GUI::Action> m_save_action; + RefPtr<GUI::Action> m_save_as_action; + RefPtr<GUI::Action> m_goto_decimal_offset_action; + RefPtr<GUI::Action> m_goto_hex_offset_action; - RefPtr<GStatusBar> m_statusbar; + RefPtr<GUI::StatusBar> m_statusbar; bool m_document_dirty { false }; }; diff --git a/Applications/HexEditor/main.cpp b/Applications/HexEditor/main.cpp index 52efb87a0e..38cf4aeb46 100644 --- a/Applications/HexEditor/main.cpp +++ b/Applications/HexEditor/main.cpp @@ -35,24 +35,24 @@ int main(int argc, char** argv) return 1; } - GApplication app(argc, argv); + GUI::Application app(argc, argv); if (pledge("stdio shared_buffer accept rpath cpath wpath", nullptr) < 0) { perror("pledge"); return 1; } - auto window = GWindow::construct(); + auto window = GUI::Window::construct(); window->set_title("Hex Editor"); window->set_rect(20, 200, 640, 400); auto hex_editor_widget = HexEditorWidget::construct(); window->set_main_widget(hex_editor_widget); - window->on_close_request = [&]() -> GWindow::CloseRequestDecision { + window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { if (hex_editor_widget->request_close()) - return GWindow::CloseRequestDecision::Close; - return GWindow::CloseRequestDecision::StayOpen; + return GUI::Window::CloseRequestDecision::Close; + return GUI::Window::CloseRequestDecision::StayOpen; }; window->show(); |