int mainmenu(int height, int width) { int ret; ITEM **menu_items; MENU *main_menu; int n_choices, i; clean_main_menu(); build_main_menu(instance_path); n_choices = menu_size; menu_items = (ITEM **) calloc(n_choices + 1, sizeof (ITEM *)); for (i = 0; i < n_choices; ++i) { menu_items[i] = new_item(menu_values[i], menu_values[i]); set_item_userptr(menu_items[i], (void *) menu_selected); } menu_items[n_choices] = (ITEM *) NULL; main_menu = new_menu((ITEM **) menu_items); menu_opts_off(main_menu, O_SHOWDESC); set_menu_sub(main_menu, derwin(stdscr, 10, 50, 6, 10)); post_menu(main_menu); attron(A_BOLD); mvprintw(0, 0, name); mvprintw(0, width - strlen(vers), vers); attroff(A_BOLD); refresh(); pos_menu_cursor(main_menu); while ((i = getch()) != KEY_F(4)) { switch (i) { case KEY_DOWN: menu_driver(main_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(main_menu, REQ_UP_ITEM); break; case 10: { ITEM *cur; int (*p)(char *); cur = current_item(main_menu); p = (int (*)(char *))item_userptr(cur); ret = p((char *) item_name(cur)); pos_menu_cursor(main_menu); goto menu_sel; } } } if (i == KEY_F(4)) { ret = menu_size - 1; } menu_sel: unpost_menu(main_menu); free_menu(main_menu); for (i = 0; i < n_choices; ++i) free_item(menu_items[i]); return ret; }
ExampleWindow::ExampleWindow() : m_VBox(Gtk::ORIENTATION_VERTICAL), m_NameLabel("Name"), m_SurnameLabel("Surname"), m_CommentsLabel("Comments") { m_refPageSetup = Gtk::PageSetup::create(); m_refSettings = Gtk::PrintSettings::create(); m_ContextId = m_Statusbar.get_context_id(app_title); set_title(app_title); set_default_size(400, 300); add(m_VBox); build_main_menu(); m_VBox.pack_start(m_Grid); //Arrange the widgets inside the grid: m_Grid.set_row_spacing(5); m_Grid.set_column_spacing(5); m_Grid.attach(m_NameLabel, 0, 0, 1, 1); m_Grid.attach(m_NameEntry, 1, 0, 1, 1); m_Grid.attach(m_SurnameLabel, 0, 1, 1, 1); m_Grid.attach(m_SurnameEntry, 1, 1, 1, 1); //Add the TextView, inside a ScrolledWindow: m_ScrolledWindow.add(m_TextView); //Only show the scrollbars when they are necessary: m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); m_Grid.attach(m_CommentsLabel, 0, 2, 1, 1); m_Grid.attach(m_ScrolledWindow, 1, 2, 1, 1); m_ScrolledWindow.set_hexpand(true); m_ScrolledWindow.set_vexpand(true); m_refTextBuffer = Gtk::TextBuffer::create(); m_TextView.set_buffer(m_refTextBuffer); m_VBox.pack_start(m_Statusbar); show_all_children(); }