void myg_menu_add(Gtk::Menu &menu, const std::string &icon, const Glib::ustring &label, const sigc::slot<void> &slot, const std::string &id) { Gtk::MenuItem *item= myg_make_image_item(icon, label); menu.append(*item); item->signal_activate().connect(slot); item->set_data("id", g_strdup(id.c_str()), g_free); item->show(); }
int main(int argc, char *argv[]) { // make window Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "tutorial2"); Gtk::Window window; window.set_default_size(400,200); window.set_title("Tutorial 2"); // This creates a vertical box container with 0 padding Gtk::Box *vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); window.add(*vbox); // creates menu bar Gtk::MenuBar *menubar = Gtk::manage(new Gtk::MenuBar()); vbox->pack_start(*menubar, Gtk::PACK_SHRINK, 0); // create menu items Gtk::MenuItem *menuitem_file = Gtk::manage(new Gtk::MenuItem("_File", true)); menubar->append(*menuitem_file); Gtk::Menu *filemenu = Gtk::manage(new Gtk::Menu()); menuitem_file->set_submenu(*filemenu); Gtk::MenuItem *menuitem_quit = Gtk::manage(new Gtk::MenuItem("_Quit", true)); filemenu->append(*menuitem_quit); // create grid container with border width 10 // and add it to the new cell of the vertical box Gtk::Grid *grid = Gtk::manage(new Gtk::Grid); grid->set_border_width(10); vbox->add(*grid); // create button Gtk::Button *b1 = Gtk::manage(new Gtk::Button("Button 1")); b1->set_hexpand(true); // take up all unused space horizontally b1->set_vexpand(true); // take up all unused space vertically // possition 0(x), 0(y), span 1 cell wide and 2 cells down grid->attach(*b1, 0, 0, 1, 2); Gtk::Button *b2 = Gtk::manage(new Gtk::Button("Button 2")); grid->attach(*b2, 1, 0, 1, 1); Gtk::Button *b3 = Gtk::manage(new Gtk::Button("Button 3")); grid->attach(*b3, 1, 1, 1, 1); vbox->show_all(); return app->run(window); }
myWindow::myWindow() { set_default_size(400, 200); set_title("Tutorial 3"); Gtk::Box *vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); add(*vbox); Gtk::MenuBar *menubar = Gtk::manage(new Gtk::MenuBar()); vbox->pack_start(*menubar, Gtk::PACK_SHRINK, 0); Gtk::MenuItem *menuitem_file = Gtk::manage(new Gtk::MenuItem("_File", true)); menubar->append(*menuitem_file); Gtk::Menu *filemenu = Gtk::manage(new Gtk::Menu()); menuitem_file->set_submenu(*filemenu); Gtk::MenuItem *menuitem_quit = Gtk::manage(new Gtk::MenuItem("_Quit", true)); menuitem_quit->signal_activate().connect(sigc::mem_fun(*this, &myWindow::on_quit_click)); filemenu->append(*menuitem_quit); Gtk::Grid *grid = Gtk::manage(new Gtk::Grid); grid->set_border_width(10); vbox->add(*grid); Gtk::Button *b1 = Gtk::manage(new Gtk::Button("Big Button 1")); b1->set_hexpand(true); b1->set_vexpand(true); b1->signal_clicked().connect(sigc::mem_fun(*this, &myWindow::on_big_button1_click)); grid->attach(*b1, 0, 0, 1, 2); Gtk::Button *b2 = Gtk::manage(new Gtk::Button("Button 2")); b2->signal_clicked().connect(sigc::mem_fun(*this, &myWindow::on_button2_click)); grid->attach(*b2, 1, 0, 1, 1); Gtk::Button *b3 = Gtk::manage(new Gtk::Button("Button 3")); b3->signal_clicked().connect(sigc::mem_fun(*this, &myWindow::on_button3_click)); grid->attach(*b3, 1, 1, 1, 1); vbox->show_all(); }
HistorySubMenu::HistorySubMenu( const std::string& url_history ) : Gtk::Menu(), m_url_history( url_history ) { Gtk::MenuItem* item; // メニュー項目作成 // 履歴クリア Gtk::Menu* menu = Gtk::manage( new Gtk::Menu() ); item = Gtk::manage( new Gtk::MenuItem( "クリアする(_C)", true ) ); menu->append( *item ); item->signal_activate().connect( sigc::mem_fun( *this, &HistorySubMenu::slot_clear ) ); item = Gtk::manage( new Gtk::MenuItem( "履歴クリア(_C)", true ) ); item->set_submenu( *menu ); append( *item ); item = Gtk::manage( new Gtk::MenuItem( "サイドバーに全て表示(_S)", true ) ); append( *item ); item->signal_activate().connect( sigc::mem_fun( *this, &HistorySubMenu::slot_switch_sideber ) ); // セパレータ item = Gtk::manage( new Gtk::SeparatorMenuItem() ); append( *item ); // 履歴項目 for( int i = 0; i < CONFIG::get_history_size(); ++i ){ Gtk::Image* image = Gtk::manage( new Gtk::Image() ); m_vec_images.push_back( image ); Gtk::Label* label = Gtk::manage( new Gtk::Label( HIST_NONAME ) ); m_vec_label.push_back( label ); Gtk::Label *label_motion = Gtk::manage( new Gtk::Label() ); if( i == 0 ) label_motion->set_text( CONTROL::get_str_motions( CONTROL::RestoreLastTab ) ); Gtk::HBox* hbox = Gtk::manage( new Gtk::HBox() ); hbox->set_spacing( SPACING_MENU ); hbox->pack_start( *image, Gtk::PACK_SHRINK ); hbox->pack_start( *label, Gtk::PACK_SHRINK ); hbox->pack_end( *label_motion, Gtk::PACK_SHRINK ); Gtk::MenuItem* item = Gtk::manage( new Gtk::MenuItem( *hbox ) ); append( *item ); item->signal_activate().connect( sigc::bind< int >( sigc::mem_fun( *this, &HistorySubMenu::slot_active ), i ) ); item->signal_button_press_event().connect( sigc::bind< int >( sigc::mem_fun( *this, &HistorySubMenu::slot_button_press ), i ) ); } // ポップアップメニュー作成 m_popupmenu.signal_deactivate().connect( sigc::mem_fun( *this, &HistorySubMenu::deactivate ) ); item = Gtk::manage( new Gtk::MenuItem( "タブで開く" ) ); item->signal_activate().connect( sigc::mem_fun( *this, &HistorySubMenu::slot_open_history ) ); m_popupmenu.append( *item ); item = Gtk::manage( new Gtk::SeparatorMenuItem() ); m_popupmenu.append( *item ); item = Gtk::manage( new Gtk::MenuItem( "履歴から削除" ) ); item->signal_activate().connect( sigc::mem_fun( *this, &HistorySubMenu::slot_remove_history ) ); m_popupmenu.append( *item ); item = Gtk::manage( new Gtk::SeparatorMenuItem() ); m_popupmenu.append( *item ); item = Gtk::manage( new Gtk::MenuItem( "プロパティ" ) ); item->signal_activate().connect( sigc::mem_fun( *this, &HistorySubMenu::slot_show_property ) ); m_popupmenu.append( *item ); m_popupmenu.show_all_children(); }
void myg_menu_add(Gtk::Menu &menu) { menu.append(*myg_make_separator_item()); }