diff --git a/hello_world.cpp b/hello_world.cpp index 076b03b..52fb608 100644 --- a/hello_world.cpp +++ b/hello_world.cpp @@ -6,15 +6,15 @@ #include namespace learn_gtkmm4 { - HelloWorld::HelloWorld() : m_button("Hello world!") { + HelloWorld::HelloWorld(const Glib::RefPtr& menuModel) : + m_VBox(Gtk::Orientation::VERTICAL), m_menu_bar(menuModel), m_button("Hello world!") { set_title("Hello world!"); - set_default_size(720, 1280); - add_action("Open"); - add_action("Quit"); - set_show_menubar(); + set_default_size(1280, 720); m_button.set_margin(10); m_button.signal_clicked().connect(sigc::mem_fun(*this, &HelloWorld::on_button_clicked)); - set_child(m_button); + m_VBox.append(m_menu_bar); + m_VBox.append(m_button); + set_child(m_VBox); } void HelloWorld::on_button_clicked() { diff --git a/hello_world.hpp b/hello_world.hpp index 30b01ad..301a9c3 100644 --- a/hello_world.hpp +++ b/hello_world.hpp @@ -9,18 +9,21 @@ #include #include #include +#include +#include namespace learn_gtkmm4 { class HelloWorld : public Gtk::ApplicationWindow { public: - HelloWorld(); + explicit HelloWorld(const Glib::RefPtr& menuModel); ~HelloWorld() override = default; protected: void on_button_clicked(); Gtk::Box m_VBox; + Gtk::PopoverMenuBar m_menu_bar; Gtk::Button m_button; Gtk::GLArea gl_area; }; diff --git a/main.cpp b/main.cpp index db02ca1..1d35092 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,24 @@ #include "hello_world.hpp" #include +#include +#include +#include int main(int argc, char *argv[]) { auto app = Gtk::Application::create("org.gtkmm.example"); - return app->make_window_and_run(argc, argv); + + const auto menu_model = []() -> Glib::RefPtr { + try { + const auto builder = Gtk::Builder::create_from_file("menu_bar.ui"); + return std::dynamic_pointer_cast(builder->get_object("menu")); + } catch (const std::exception &e) { + std::cerr << e.what() << '\n'; + return nullptr; + } + }(); + if (menu_model == nullptr) { + std::cerr << "Menu model object is null. Down-cast failed.\n"; + return EXIT_FAILURE; + } + return app->make_window_and_run(argc, argv, menu_model); } diff --git a/menu_bar.ui b/menu_bar.ui new file mode 100644 index 0000000..f071df2 --- /dev/null +++ b/menu_bar.ui @@ -0,0 +1,58 @@ + + + + + + Fichiers +
+ + file.new + document-new + Nouveau fichier + + + file.open + document-open + Ouvrir + + + file.save + document-save + Enregistrer + + + file.save_as + document-save-as + Enregistrer sous + +
+
+ + file.quit + application-exit + Quitter + +
+
+ + Éditer +
+ + edit.copy + edit-copy + Copier + + + edit.cut + edit-cut + Couper + + + edit.paste + edit-paste + Coller + +
+
+
+