📄 stock.cc
字号:
#include "menu.hh"#include <gfc/gtk/accelgroup.hh>#include <gfc/gtk/box.hh>#include <gfc/gtk/eventbox.hh>#include <gfc/gtk/label.hh>#include <gfc/gtk/menubar.hh>#include <gfc/gtk/imagemenuitem.hh>#include <gfc/gtk/separatormenuitem.hh>#include <gfc/gtk/stock.hh>#include <gfc/gtk/image.hh>MenuWindow::MenuWindow(){ set_title("Menu Window"); set_size_request(300, 200); // Boxes don't receive button events so use an eventbox. The eventbox is added first // and then all the other widgets added to it. Gtk::EventBox *eventbox = new Gtk::EventBox; add(*eventbox); // Set the events the eventbox is to receive. These can be any number of or'd (|) values // from the Gdk::EventMask enumeration. eventbox->set_events(Gdk::BUTTON_PRESS_MASK); // Add the packing box to eventbox Gtk::VBox *vbox = new Gtk::VBox(false, 1); vbox->set_border_width(1); eventbox->add(*vbox); // Create the menubar. Menus can be created by using the append, prepend or insert methods // in menushell.h to add menu items. Gtk::MenuBar *menubar = new Gtk::MenuBar; Gtk::AccelGroup *accel_group = add_accel_group(); // Create the File menu Gtk::Menu *menu = new Gtk::Menu(*accel_group); menu->append(Gtk::StockId::NEW, sigc::mem_fun(this, &MenuWindow::on_file_new)); menu->append(Gtk::StockId::OPEN, sigc::mem_fun(this, &MenuWindow::on_file_open)); menu->append(Gtk::StockId::SAVE, sigc::mem_fun(this, &MenuWindow::on_file_save)); menu->append(Gtk::StockId::SAVE_AS, sigc::mem_fun(this, &MenuWindow::on_file_save_as)); menu->append(*(new Gtk::SeparatorMenuItem)); menu->append(Gtk::StockId::QUIT, sigc::mem_fun(this, &MenuWindow::on_file_quit)); menubar->append(*(new Gtk::MenuItem("_File", *menu, true))); // Bind the file menu to the button_press event and use it as the popup menu. eventbox->sig_button_press_event().connect(sigc::bind(sigc::mem_fun(this, &MenuWindow::on_button_press), menu)); // Create Options menu menu = new Gtk::Menu(*accel_group); menu->append(Gtk::StockId::PREFERENCES, sigc::mem_fun(this, &MenuWindow::on_options_preferences)); menubar->append(*(new Gtk::MenuItem("_Options", *menu, true))); // Create Help menu menu = new Gtk::Menu; Gtk::MenuItem *menu_item = new Gtk::ImageMenuItem(*(new Gtk::Image(Gtk::StockId::DIALOG_INFO, Gtk::ICON_SIZE_MENU)), "_About", true); menu->append(*menu_item, sigc::mem_fun(this, &MenuWindow::on_help_about)); menu_item = new Gtk::MenuItem("_Help", *menu, true); menu_item->set_right_justified(true); menubar->append(*menu_item); // Pack the menubar into the vbox vbox->pack_start(*menubar, false); // Add a label that tells the user to click the mouse button inside the client area. Gtk::Label *label = new Gtk::Label("Click mouse button here..."); vbox->pack_start(*label); // Being lazy, just show everything with one call. show_all();}MenuWindow::~MenuWindow(){}boolMenuWindow::on_button_press(const Gdk::EventButton& event, Gtk::Menu *menu){ menu->popup(event.button(), event.time()); return true;}voidMenuWindow::menu_item_selected(const char *parent, const char *item){ g_message("Menu: activated the \"%s\" menu item: \"%s\"", parent, item);}voidMenuWindow::on_file_new(){ menu_item_selected("File", "New");}voidMenuWindow::on_file_open(){ menu_item_selected("File", "Open");}voidMenuWindow::on_file_save(){ menu_item_selected("File", "Save");}voidMenuWindow::on_file_save_as(){ menu_item_selected("File", "Save As");}voidMenuWindow::on_file_quit(){ dispose();}voidMenuWindow::on_options_preferences(){ menu_item_selected("Options", "Preferences");}voidMenuWindow::on_help_about(){ menu_item_selected("Help", "About");}// Convenience macro for a simple main functionGFC_MAIN(MenuWindow)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -