示例#1
0
void viewTeam(FootBallGame::TeamNumber teamNumber) {
  const int window_nlines = 10,
            window_ncols  = 90;

  char *choices[] = {
    "Team Properties",
    "List Players",
    "Add Player",
    "Return",
  };

  for (;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);

    // Set up the items of menuMain.
    int nChoices = ARRAY_SIZE(choices) + 1;
    ITEM **items = new ITEM* [nChoices];
    for (unsigned i = 0; i < ARRAY_SIZE(choices); i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 10, 80, 0, 10));

    // Make window and menu visible;
    post_menu(menu);
    wrefresh(window);
    refresh();
  
    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch (c) {
        case KEY_DOWN:
          menu_driver(menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(menu, REQ_UP_ITEM);
          break;
        case 10: // Enter
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          const ITEM *currentItem = current_item(menu);
          const char *itemName = item_name(currentItem);
          // Delete allocated data
          unpost_menu(menu); 
          free_menu(menu); 
          delwin(window); 
          for (unsigned i = 0; i < ARRAY_SIZE(choices); i++)
            free_item(items[i]);
          delete [] items;
          // Edit/View Team Name
          if (strcmp(itemName, choices[0]) == 0) {
            viewEditTeamProperties(teamNumber);
            restart = true;
          // View/Remove Players
          } else if (strcmp(itemName, choices[1]) == 0)  {
            viewListPlayers(teamNumber);
            restart = true;
          // Add new Player
          } else if (strcmp(itemName, choices[2]) == 0)  {
            viewNewPlayer(teamNumber);
            restart = true;
          // Return
          } else if (strcmp(itemName, choices[3]) == 0)  {
            delwin(window);
            return;
          }
      }
    }
  }
}
示例#2
0
//
// Affiche une fenêtre de menu.
//
int displayMenu(char **choices, int nbChoices, char title[], bool logo) {
    if(choices == NULL || nbChoices < 1) return -1;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    WINDOW *menuWin = NULL;
    
    int i = 0, c;
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = max_strlen(choices, nbChoices) + 2;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    while(true) {
        clear();
        
        menuWin = (logo) ? getMenuWindow(nbChoices, title) : getMenuWindowNoLogo(nbChoices, title, -1, -1);
        
        //on initialise le menu
        menu = new_menu((ITEM **) menuItems);
        
        //on lui précise bien que le menu fait N lignes et 1 colonne
        set_menu_format(menu, nbChoices, 1);
        
        menu_opts_off(menu, O_NONCYCLIC);
        set_menu_mark(menu, "> ");
        
        //on associe le menu à une fenêtre et une sous-fenêtre
        set_menu_win(menu, menuWin);
        //fenêtre hauteur largeur x y
        set_menu_sub(menu, derwin(menuWin, nbChoices, menuWidth, (logo) ? 15 : 4, (winWidth - menuWidth) / 2));
        
        //et hop, on affiche le menu et on rafraîchit.
        post_menu(menu);
        
        refresh();
        wrefresh(menuWin);
        
        curs_set(0);
        noecho();
        
        //boucle pour le menu
        while((c = getch())) {
            bool resized = false;
            
            switch(c) {
                case KEY_DOWN:
                    menu_driver(menu, REQ_DOWN_ITEM);
                    break;
                case KEY_UP:
                    menu_driver(menu, REQ_UP_ITEM);
                    break;
                case KEY_ESC_ALT:
                    return -1;
                case KEY_RESIZE:
                    //si on a redimensionné le terminal, on ré-exécute la boucle d'affichage
                    resized = true;
                    break;
                case KEY_MENU_ENTER: {
                    int choice = item_index(current_item(menu));
                    
                    //on libère la mémoire pour le menu, les choix, la fenêtre
                    unpost_menu(menu);
                    free_menu(menu);
                    
                    for(i = 0; i < nbChoices; ++i)
                        free_item(menuItems[i]);
                    
                    clear();
                    refresh();
                    
                    delwin(menuWin);
                    
                    //on réactive l'affichage des caractères tapés et du curseur
                    echo();
                    curs_set(1);
                    
                    return choice;
                }
            }
            
            if(resized) break;
            wrefresh(menuWin);
        }

    }
    
    return 0;
}
示例#3
0
文件: console.c 项目: mulatinho/sfm
void sfm_ncurses(void)
{
	int x;
	sfm_ncurses_win *iface = malloc(sizeof(sfm_ncurses_win));
	char root_items[FILENAME_MAX];
	int user_input;
	WINDOW *current_window;
	ITEM **ncmenu_items = NULL;
	MENU *sfm_menu;

	initscr();
	start_color();	
	noecho();
	cbreak();

	getmaxyx(stdscr, iface->lines, iface->cols);
	refresh();

	iface->sfmncmenu = newwin(3, iface->cols-1, iface->lines-5, 0);
	keypad(iface->sfmncmenu, TRUE);
	wmove(iface->sfmncmenu, 1, 1);
	box(iface->sfmncmenu, 0, 0);

	ncmenu_items = malloc((menu_choices_n+1) * sizeof(ITEM *));
	for (x = 0; x < menu_choices_n; x++)
		ncmenu_items[x] = new_item(menu_choices[x], menu_choices[x]);
	//ncmenu_items[menu_choices_n] = (ITEM *)NULL;

	sfm_menu = new_menu((ITEM **)ncmenu_items);
	menu_opts_off(sfm_menu, O_SHOWDESC);
	set_menu_format(sfm_menu, 1, menu_choices_n);
	set_menu_mark(sfm_menu, " ");
	set_menu_win(sfm_menu, iface->sfmncmenu);
	set_menu_sub(sfm_menu, derwin(iface->sfmncmenu, 1, iface->cols-2, 1, 1));
	post_menu(sfm_menu); 

	wrefresh(iface->sfmncmenu);

	iface->sfmnroot = newwin(iface->lines-6, iface->cols-4, 0, 0);
	snprintf(root_items, sizeof(root_items)-1, "%-40s . %-6s . %-4s . %-3s . %-10s", 
		"FILENAME", "SIZE", "TYPE", "UID", "PERMISSIONS");
	wattron(iface->sfmnroot, A_REVERSE|A_BOLD);
	wprintw(iface->sfmnroot, root_items);
	wattroff(iface->sfmnroot, A_REVERSE|A_BOLD);

	for (x = 1; x < (iface->lines - 6); x++) {
		snprintf(root_items, sizeof(root_items)-1, "Item line %2d                             . 55Kb   . .PDF . 100 . -rw-r--r--", x);
		mvwprintw(iface->sfmnroot, x, 0, root_items);
	}

	wrefresh(iface->sfmnroot);

	iface->sfmnstatus = newwin(1, iface->cols-1, iface->lines-2, 1);
	wprintw(iface->sfmnstatus, ":. Hello! Welcome to .: %s :. lines:%d, cols:%d", 
		SFM_VSN, iface->lines, iface->cols);
	wrefresh(iface->sfmnstatus); 

	current_window = iface->sfmncmenu;
	while (1) {
		user_input = wgetch(current_window);

		switch (user_input) {
		case KEY_LEFT:
			menu_driver(sfm_menu, REQ_LEFT_ITEM);
			break;
		case KEY_RIGHT:
			menu_driver(sfm_menu, REQ_RIGHT_ITEM);
			break; 
		case KEY_UP:
			break;
		case KEY_DOWN:
			break;
		case 9:
			if (current_window == iface->sfmncmenu)
				current_window = iface->sfmnroot;
			else
				current_window = iface->sfmncmenu;
		
			keypad(current_window, TRUE);
			break;
		case 10:
			{
				//ITEM *cur;
				
				//cur = current_item(sfm_menu);
				
			}
			break;
		case 'Q':
		case 'q':
			wclear(iface->sfmnstatus);
			wprintw(iface->sfmnstatus, ":. Are you sure you want to quit!? [Y/N] ");
			wrefresh(iface->sfmnstatus);

			user_input = wgetch(iface->sfmnstatus);
			switch (user_input) {
			case 'y': case 'Y':
			case 's': case 'S':
				wclear(iface->sfmnstatus);
				wprintw(iface->sfmnstatus, ":. Thanks for using SFM! :) Quitting...");
				wrefresh(iface->sfmnstatus);
				sleep(1);

				goto sfm_ncurses_exit;
			default:
				break;
			}
		}

		wclear(iface->sfmnstatus);
		wprintw(iface->sfmnstatus, ":. status: %d", user_input);
		wrefresh(iface->sfmnstatus);
	} 

	sfm_ncurses_exit:
	delwin(iface->sfmnroot);
	delwin(iface->sfmnstatus);
	delwin(iface->sfmncmenu);

	unpost_menu(sfm_menu);
	free_menu(sfm_menu); 

	for (x = 0; x < menu_choices_n; x++)
		free_item(ncmenu_items[x]);

	free(ncmenu_items);

	free(iface);

	refresh();
	endwin();
}
示例#4
0
void
column_select_create(ui_t *ui)
{
    int attr_id, column;
    MENU *menu;
    column_select_info_t *info;

    // Cerate a new indow for the panel and form
    ui_panel_create(ui, 20, 60);

    // Initialize Filter panel specific data
    info = sng_malloc(sizeof(column_select_info_t));

    // Store it into panel userptr
    set_panel_userptr(ui->panel, (void*) info);

    // Initialize the fields
    info->fields[FLD_COLUMNS_ACCEPT] = new_field(1, 10, ui->height - 2, 13, 0, 0);
    info->fields[FLD_COLUMNS_SAVE]   = new_field(1, 10, ui->height - 2, 25, 0, 0);
    info->fields[FLD_COLUMNS_CANCEL] = new_field(1, 10, ui->height - 2, 37, 0, 0);
    info->fields[FLD_COLUMNS_COUNT] = NULL;

    // Field Labels
    set_field_buffer(info->fields[FLD_COLUMNS_ACCEPT], 0, "[ Accept ]");
    set_field_buffer(info->fields[FLD_COLUMNS_SAVE],   0, "[  Save  ]");
    set_field_buffer(info->fields[FLD_COLUMNS_CANCEL], 0, "[ Cancel ]");

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, ui->win);
    post_form(info->form);

    // Create a subwin for the menu area
    info->menu_win = derwin(ui->win, 10, ui->width - 2, 7, 0);

    // Initialize one field for each attribute
    for (attr_id = 0; attr_id < SIP_ATTR_COUNT; attr_id++) {
        // Create a new field for this column
        info->items[attr_id] = new_item("[ ]", sip_attr_get_description(attr_id));
        set_item_userptr(info->items[attr_id], (void*) sip_attr_get_name(attr_id));
    }
    info->items[SIP_ATTR_COUNT] = NULL;

    // Create the columns menu and post it
    info->menu = menu = new_menu(info->items);

    // Set current enabled fields
    // FIXME Stealing Call list columns :/
    call_list_info_t *list_info = call_list_info(ui_find_by_type(PANEL_CALL_LIST));

    // Enable current enabled fields and move them to the top
    for (column = 0; column < list_info->columncnt; column++) {
        const char *attr = list_info->columns[column].attr;
        for (attr_id = 0; attr_id < item_count(menu); attr_id++) {
            if (!strcmp(item_userptr(info->items[attr_id]), attr)) {
                column_select_toggle_item(ui, info->items[attr_id]);
                column_select_move_item(ui, info->items[attr_id], column);
                break;
            }
        }
    }

    // Set main window and sub window
    set_menu_win(menu, ui->win);
    set_menu_sub(menu, derwin(ui->win, 10, ui->width - 5, 7, 2));
    set_menu_format(menu, 10, 1);
    set_menu_mark(menu, "");
    set_menu_fore(menu, COLOR_PAIR(CP_DEF_ON_BLUE));
    menu_opts_off(menu, O_ONEVALUE);
    post_menu(menu);

    // Draw a scrollbar to the right
    info->scroll = ui_set_scrollbar(info->menu_win, SB_VERTICAL, SB_RIGHT);
    info->scroll.max = item_count(menu) - 1;
    ui_scrollbar_draw(info->scroll);

    // Set the window title and boxes
    mvwprintw(ui->win, 1, ui->width / 2 - 14, "Call List columns selection");
    wattron(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));
    title_foot_box(ui->panel);
    mvwhline(ui->win, 6, 1, ACS_HLINE, ui->width - 1);
    mvwaddch(ui->win, 6, 0, ACS_LTEE);
    mvwaddch(ui->win, 6, ui->width - 1, ACS_RTEE);
    wattroff(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));

    // Some brief explanation abotu what window shows
    wattron(ui->win, COLOR_PAIR(CP_CYAN_ON_DEF));
    mvwprintw(ui->win, 3, 2, "This windows show the list of columns displayed on Call");
    mvwprintw(ui->win, 4, 2, "List. You can enable/disable using Space Bar and reorder");
    mvwprintw(ui->win, 5, 2, "them using + and - keys.");
    wattroff(ui->win, COLOR_PAIR(CP_CYAN_ON_DEF));

    info->form_active = 0;
}
示例#5
0
int main (int argc, char **argv)
{

    logfilepath = getenv ("HOME");
    logfilepath = strcat (logfilepath, "/.ooview.log");

    load_config();


    initscr();
    raw();
    noecho();
    start_color();
    keypad(stdscr,TRUE);

    init_pair(1, COLOR_WHITE, COLOR_BLACK);
    init_pair(2, COLOR_RED, COLOR_WHITE);
    init_pair(3, COLOR_BLUE, COLOR_WHITE);
    init_pair(4, COLOR_BLACK, COLOR_WHITE);
    bkgd(COLOR_PAIR(1));
    curs_set(0);

    menu_bar = subwin(stdscr,1,COLS,0,0);
    wbkgd(menu_bar,COLOR_PAIR(2));
    waddstr(menu_bar,"File");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F1>");
    wattroff(menu_bar, COLOR_PAIR(3));
    wmove(menu_bar, 0, 19);
    waddstr(menu_bar,"View");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F2>");
    wattroff(menu_bar, COLOR_PAIR(3));
    wmove(menu_bar, 0, 34);
    waddstr(menu_bar,"Options");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F3>");
    wattroff(menu_bar, COLOR_PAIR(3));
    wmove(menu_bar, 0, 53);
    waddstr(menu_bar,"Help");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F4>");
    wattroff(menu_bar, COLOR_PAIR(3));

    status_bar = subwin(stdscr,1,COLS,LINES-1,0);
    wbkgd(status_bar,COLOR_PAIR(4));

    n_choices[0] = ARRAY_SIZE(file_choices);
    n_choices[1] = ARRAY_SIZE(view_choices);
    n_choices[2] = ARRAY_SIZE(opts_choices);
    n_choices[3] = ARRAY_SIZE(help_choices);
    file_items = (ITEM **)calloc(n_choices[0] + 1, sizeof(ITEM *));
    view_items = (ITEM **)calloc(n_choices[1] + 1, sizeof(ITEM *));
    opts_items = (ITEM **)calloc(n_choices[2] + 1, sizeof(ITEM *));
    help_items = (ITEM **)calloc(n_choices[3] + 1, sizeof(ITEM *));

    for (i=0; i<n_choices[0]; ++i)
        file_items[i] = new_item(file_choices[i], NULL);

    for (i=0; i<n_choices[1]; ++i)
        view_items[i] = new_item(view_choices[i], NULL);

    for (i=0; i<n_choices[2]; ++i)
        opts_items[i] = new_item(opts_choices[i], NULL);

    for (i=0; i<n_choices[3]; ++i)
        help_items[i] = new_item(help_choices[i], NULL);

    file_items[n_choices[0]] = (ITEM *)NULL;
    view_items[n_choices[1]] = (ITEM *)NULL;
    opts_items[n_choices[2]] = (ITEM *)NULL;
    help_items[n_choices[3]] = (ITEM *)NULL;

    file_menu = new_menu((ITEM **)file_items);
    view_menu = new_menu((ITEM **)view_items);
    opts_menu = new_menu((ITEM **)opts_items);
    help_menu = new_menu((ITEM **)help_items);

    set_menu_mark(file_menu, "");
    set_menu_mark(view_menu, "");
    set_menu_mark(opts_menu, "");
    set_menu_mark(help_menu, "");

    init_screen();
    if (argc == 2)
        open_file(argv[1]);

    while ((c = getch()) != EXIT_KEY)
    {
        action_performed = false;

        switch (c)
        {
        case KEY_F(1):
            cur_menu=1;
            break;
        case KEY_F(2):
            cur_menu=2;
            break;
        case KEY_F(3):
            cur_menu=3;
            break;
        case KEY_F(4):
            cur_menu=4;
            break;
        case KEY_UP:
            if ((file_printed) && (buffer->cur_line > 1))
            {
                int backsteps = 0;
                int steps;
                char *tmp;

                if ((*--cur_char)==NEWLINE)
                    backsteps++;

                tmp = cur_char - 1;

                if ((*--cur_char) == NEWLINE)
                {
                    cur_char = tmp;
                    print_status_bar("yeah");
                }
                else
                {
                    do {
                        cur_char--;
                        backsteps++;
                    } while (((*cur_char)!=NEWLINE) && (cur_char != buffer->content));

                    if (backsteps > COLS)
                    {
                        int test;
                        test = backsteps/COLS;
                        steps = (backsteps%COLS);
                        if (test>1)
                            steps += COLS;

                        mvwprintw(status_bar,0,0,"%d",steps);
                        touchwin(status_bar);
                        wrefresh(status_bar);
                        cur_char += backsteps;
                        cur_char -= steps;
                    }
                }
                buffer->cur_line--;
                print_site(buffer->cur_line, buffer->lines);

                if (cur_char!=buffer->content)
                    print_file(buffer,++cur_char);
                else
                    print_file(buffer,cur_char);
            }
            break;
        case KEY_DOWN:
            if ((file_printed) && (buffer->cur_line < buffer->lines))
            {
                int cols=0;


                while (((*cur_char)!=NEWLINE) && (cols < COLS-1))
                {
                    cols++;
                    cur_char++;
                }


                buffer->cur_line++;
                print_site(buffer->cur_line, buffer->lines);
                print_file(buffer,++cur_char);
            }
            break;
        default:
            if (meta_win!=NULL)
            {
                delwin(meta_win);
                touchwin(stdscr);
                refresh();
            }

        }

        if (cur_menu == 1)
        {
            file_win = newwin(8,19,1,0);
            keypad(file_win,TRUE);
            box(file_win,0,0);
            set_menu_win(file_menu, file_win);
            set_menu_sub(file_menu, derwin(file_win,6,17,1,1));
            post_menu(file_menu);
            while (c = wgetch(file_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(file_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(file_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 2;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 4;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(file_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }

            }

            unpost_menu(file_menu);
            touchwin(stdscr);
            wrefresh(stdscr);
        }
        if (cur_menu == 2)
        {
            view_win = newwin(6,15,1,19);
            keypad(view_win,TRUE);
            box(view_win,0,0);
            set_menu_win(view_menu, view_win);
            set_menu_sub(view_menu, derwin(view_win,4,13,1,1));
            post_menu(view_menu);
            while (c = wgetch(view_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(view_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(view_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 3;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 1;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(view_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }
            }

            unpost_menu(view_menu);
            touchwin(stdscr);
            refresh();
        }
        if (cur_menu == 3)
        {
            opts_win = newwin(5,19,1,34);
            keypad(opts_win,TRUE);
            box(opts_win,0,0);
            set_menu_win(opts_menu, opts_win);
            set_menu_sub(opts_menu, derwin(opts_win,3,17,1,1));
            post_menu(opts_menu);
            while (c = wgetch(opts_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(opts_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(opts_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 4;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 2;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(opts_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }
            }

            unpost_menu(opts_menu);
            touchwin(stdscr);
            refresh();
        }
        if (cur_menu == 4)
        {
            help_win = newwin(6,17,1,53);
            keypad(help_win,TRUE);
            box(help_win,0,0);
            set_menu_win(help_menu, help_win);
            set_menu_sub(help_menu, derwin(help_win,4,15,1,1));
            post_menu(help_menu);
            while (c = wgetch(help_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(help_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(help_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 1;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 3;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(help_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }
            }

            unpost_menu(help_menu);
            touchwin(stdscr);
            refresh();
        }




        if (action_performed)
        {
            char file[80];
            clear_status_bar();

            if (!strcmp(cmd,"Open"))
            {
                if (file_printed==false)
                {
                    print_status_bar("Enter a file: ");
                    curs_set(1);
                    echo();
                    wscanw(status_bar,"%s",file);			/* get filename from user */
                    curs_set(0);
                    noecho();
                    open_file(file);


                }
                else
                {
                    print_status_bar("Please close current file.");
                }

            }
            if (!strcmp(cmd,"Close"))
            {
                if (file_printed)
                {
                    free(buffer);


                    werase(main_win);
                    init_screen();
                    wrefresh(main_win);
                    file_printed = false;
                    system("rm -rf /tmp/ooview");


                }
                else
                {
                    print_status_bar("No open file!");
                }
            }
            if (!strcmp(cmd,"Reload"))
            {
                if (file_printed)
                {
                    if (strstr(file,".ovd")!=NULL)			/* ovd*/
                    {
                        ovd_file = fopen(file,"r");

                        if (ovd_file != NULL)
                        {
                            free(buffer);
                            buffer = (struct fileinfo *)malloc(sizeof(struct fileinfo));
                            main_win = subwin(stdscr,LINES-2,COLS,1,0);
                            get_file_content(ovd_file, file, buffer);
                            fclose(ovd_file);
                            cur_char = buffer->content;
                            print_site(buffer->cur_line, buffer->lines);
                            print_file(buffer,cur_char);
                            file_printed = true;
                        }
                        else
                        {
                            print_status_bar("File does not exist!");
                        }
                    }
                    else								/* else if odt */
                    {
                        free(buffer);
                        buffer = (struct fileinfo *)malloc(sizeof(struct fileinfo));
                        main_win= subwin(stdscr,LINES-2,COLS,1,0);
                        open_odt(file,buffer);
                        get_file_meta("/tmp/ooview/meta.xml",buffer);
                        cur_char = buffer->content;
                        print_site(buffer->cur_line, buffer->lines);
                        print_file(buffer,cur_char);
                        file_printed = true;
                    }


                }
                else
                {
                    print_status_bar("No open file!");
                }
            }

            if (!strcmp(cmd,"Document info"))
            {
                if (file_printed)
                {
                    if (file_type==1)
                    {

                        meta_win = newwin(9,COLS-2,(LINES/2)-5,1);
                        wbkgd(meta_win,COLOR_PAIR(4));


                        mvwprintw(meta_win,1,1,"Genarator:  %s", buffer->generator);
                        mvwprintw(meta_win,2,1,"Initial creator:\t%s", buffer->initial_creator);
                        mvwprintw(meta_win,3,1,"Creation date:\t\t%s", buffer->creation_date);
                        mvwprintw(meta_win,4,1,"Creator:\t\t%s", buffer->creator);
                        mvwprintw(meta_win,5,1,"Date:\t\t\t%s", buffer->date);
                        mvwprintw(meta_win,6,1,"Editing cycles:\t%s", buffer->editing_cycles);
                        mvwprintw(meta_win,7,1,"Editing duration:\t%s", buffer->editing_duration);

                        box(meta_win,0,0);
                        wrefresh(meta_win);
                        touchwin(meta_win);

                    }
                }
                else
                {
                    print_status_bar("No open file!");
                }
            }

            if (!strcmp(cmd,"OOView homepage"))
            {
                char *syscall;
                syscall=(char *)malloc(strlen(BROWSER)+strlen(HOMEPAGE_URL)+1);


                sprintf(syscall, "%s %s", BROWSER, HOMEPAGE_URL);
                system(syscall);
                free(syscall);
                if (file_printed)
                    free(buffer);
                end_curses();
                return(0);

            }

            if (!strcmp(cmd,"Documentation"))
            {
                char *syscall;
                syscall=(char *)malloc(strlen(BROWSER)+strlen(HOMEPAGE_URL)+1);


                sprintf(syscall, "%s %s", BROWSER, HOMEPAGE_URL);
                system(syscall);
                free(syscall);
                if (file_printed)
                    free(buffer);
                end_curses();
                return(0);

            }

            if (!strcmp(cmd, "About OOView"))
                print_status_bar("OOView. Visit Homepage for details");

            if (!strcmp(cmd, "Copying"))
                print_status_bar("OOView is under GPL/2 Visit Homepage for details");

            if (!strcmp(cmd, "Find")) {

                if (file_printed) {

                    print_status_bar("Enter string to find: ");
                    char *findit;

                    curs_set(1);
                    echo();

                    wscanw(status_bar,"%s",findit);

                    /*

                    how to find a string in a string?
                    find it -> set cursor to position

                    */

                    print_status_bar("Not implemented yet :(");
                    curs_set(0);
                    noecho();
                } else {
                    print_status_bar("No open file!");
                }
            }

            if (!strcmp(cmd, "External Programs")) {
                char *prompt;

                /*getting printer command*/
                prompt = (char *)malloc((strlen("Enter Printing Command []: ")+strlen(PRINTER)));
                sprintf(prompt,"Enter Printing Command [%s]: ",PRINTER);
                print_status_bar(prompt);
                free(prompt);

                curs_set(1);
                echo();
                char *newcmd;
                wscanw(status_bar,"%s",newcmd);
                curs_set(0);
                noecho();
                print_status_bar(newcmd);
                /* / getting printer command*/

            }

            if (!strcmp(cmd,"Exit"))
            {
                if (file_printed)
                    free(buffer);
                end_curses();
                return 0;
            }
        }

    }
    if (file_printed)
        free(buffer);

    end_curses();
    return 0;
}
示例#6
0
int main()
{	ITEM **my_items;
	int c;
	MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
	/* Initialize curses */
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	clear();	
	refresh();
	init_pair(1, COLOR_RED, COLOR_BLACK);
	getmaxyx(stdscr,y,x);
	/* Create items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
        for(i=0;i<n_choices;++i)
	{
                my_items[i] = new_item(choices[i],"");
		set_item_userptr(my_items[i], func);
	}
	my_items[n_choices] = (ITEM *)NULL;
	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);
	/* Create the window to be associated with the menu */
        my_menu_win = newwin(10, 45, (y/2)-6,(x/2)-22 );
        keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
	/* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");
	/* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Ncurses Phone Book (NPB)", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
	mvprintw(LINES - 2, 0, "Press ESC to exit");
	refresh();
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
//upon();
	while((c = wgetch(my_menu_win)) != 27)
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10: /* Enter */
			{	ITEM *cur;
				void (*p)(char *);
				cur = current_item(my_menu);
				p = item_userptr(cur);
				p((char *)item_name(cur));
				refresh();
				//printw("%s",item_name(cur));
				if(!strcmp("[6] Exit",item_name(cur)))
				{
					unpost_menu(my_menu);
				        free_menu(my_menu);
					endwin();
					return 0;
				}
				else if(!strcmp("[3] Searching for a contact by name",item_name(cur)))
				{
					upon("Search by name");
					//if(strlen(str)>1)
					
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[4] Searching for a contact by number",item_name(cur)))
				{
					upon("Search by number");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[2] Removing a contact",item_name(cur)))
				{
					upon("Enter contact name to remove");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[5] Displaying contact list",item_name(cur)))
				{
					show();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[1] Adding a contact",item_name(cur)))
				{
					int ret=uponadd();			
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					if(ret==1)
					{
					int trash=outprint();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					}
				}
				pos_menu_cursor(my_menu);
				break;
			}
		}
                wrefresh(my_menu_win);
	}	
	/* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
//        for(i = 0; i < n_choices; ++i)
  //              free_item(my_items[i]);
	endwin();
}
示例#7
0
文件: nchgdc.c 项目: Eeketh/hgd
int
hgd_update_playlist_win(struct ui *u)
{
	ITEM			**items = NULL;
	int			  i, ret = HGD_FAIL;
	char			 *item_str;
	struct hgd_playlist	 *playlist = NULL;
	char			 *track_str;

	DPRINTF(HGD_D_INFO, "Update playlist window");

	hgd_set_statusbar_text(u, "Connected >>> Fetching playlist");

	if (sock_fd == -1) {
		ret = HGD_OK;
		goto clean;
	}

	wclear(u->content_wins[HGD_WIN_PLAYLIST]);
	hgd_unpost_and_free_content_menu(u, HGD_WIN_PLAYLIST);

	/* and now populate the menu */
	if (hgd_cli_get_playlist(&playlist) != HGD_OK) {
		goto clean;
	}

	if (playlist->n_items == 0) {
		ret = HGD_OK;
		mvwprintw(u->content_wins[HGD_WIN_PLAYLIST], 0, 0, "Playlist Empty - Saddest of times!");
		goto clean;
	}

	items = xcalloc(playlist->n_items + 1, sizeof(ITEM *));
	for (i = 0; i < playlist->n_items; i++) {

		DPRINTF(HGD_D_DEBUG, "Adding item \"%s\"",
		    playlist->items[i]->tags.title);

		if ((strcmp(playlist->items[i]->tags.artist, "")) ||
		    (strcmp(playlist->items[i]->tags.title, ""))) {

			xasprintf(&track_str, "#%03d from %-8s: '%s' by '%s'",
			    playlist->items[i]->id,
			    playlist->items[i]->user,
			    playlist->items[i]->tags.title,
			    playlist->items[i]->tags.artist);
		} else  {
			xasprintf(&track_str, "#%03d from %-8s: '%s'",
			    playlist->items[i]->id,
			    playlist->items[i]->user,
			    playlist->items[i]->filename);
		}

		hgd_prepare_item_string(&item_str, track_str);
		free(track_str);

		items[i] = new_item(item_str, NULL);
		if (items[i] == NULL)
			DPRINTF(HGD_D_WARN, "Could not make new item: %s", SERROR);
	}

	u->content_menus[HGD_WIN_PLAYLIST] = new_menu(items);
	if (u->content_menus[HGD_WIN_PLAYLIST] == NULL) {
			DPRINTF(HGD_D_ERROR, "Could not make menu");
			goto clean;
	}

	set_menu_win(u->content_menus[HGD_WIN_PLAYLIST],
	    u->content_wins[HGD_WIN_PLAYLIST]);
	set_menu_mark(u->content_menus[HGD_WIN_PLAYLIST], "");
	set_menu_format(u->content_menus[HGD_WIN_PLAYLIST], LINES - 2, 1);
	set_menu_fore(u->content_menus[HGD_WIN_PLAYLIST],
	    COLOR_PAIR(HGD_CPAIR_SELECTED));

	if ((post_menu(u->content_menus[HGD_WIN_PLAYLIST])) != E_OK) {
		DPRINTF(HGD_D_ERROR, "Could not post menu");
		goto clean;
	}

	hgd_set_standard_statusbar_text(u);

	ret = HGD_OK;
clean:
	if (playlist)
		hgd_free_playlist(playlist);
#if 0
	if (items)
		free(items);
#endif
	if (playlist)
		free(playlist);

	return (ret);
}
示例#8
0
/*
 * Menu mark get/set functions - menu_mark(3X) man page
 */
static VALUE rbncurs_c_set_menu_mark(VALUE rb_menu, VALUE value)
{
  MENU *menu = get_menu(rb_menu);
  return INT2NUM(set_menu_mark(menu, STR2CSTR(value)));
}
示例#9
0
/* Starts the program and prints the main menu */
int main(int qw) {
    static int mm = -1;
    mm++;
    initscr();
    curs_set(0);
    noecho();
    if(qw == 2)
        banner(4);
    else if(qw == 1)
        banner(3);
    ITEM **my_items;
    int c;
    MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;
    ITEM *cur;
    /* Initialize curses */
    initscr();
    start_color();
    init_pair(5, COLOR_RED, COLOR_BLACK);
    init_pair(6, COLOR_BLACK, COLOR_RED);
    init_pair(7, COLOR_CYAN, COLOR_BLACK);
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    init_pair(1, COLOR_RED, COLOR_BLACK);
START:
    attrset(COLOR_PAIR(7));
    n_choices = ARRAY_SIZE(choices_index);
    my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
    for(i = 0; i < n_choices; ++i) {
        my_items[i] = new_item(choices_index[i], NULL);
        if(i == 0)
            /* Set the user pointer */
            set_item_userptr(my_items[i], mains);
        else if(i == 1)
            set_item_userptr(my_items[i], race_menu);
        else if(i == 2)
            set_item_userptr(my_items[i], exitit);
    }
    my_items[n_choices] = (ITEM *)NULL;
    /* Crate menu */
    my_menu = new_menu((ITEM **)my_items);

    /* Create the window to be associated with the menu */
    my_menu_win = newwin(8, 25, 15, 70);
    keypad(my_menu_win, TRUE);

    /* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win, 5, 19, 3, 1));

    /* Set menu mark to the string " * " */
    set_menu_mark(my_menu, "--> ");

    /* Print a border around the main window and print a title */
    box(my_menu_win, 0, 0);
    print_in_middle1(my_menu_win, 1, 0, 25, "CHOOSE A GAME", COLOR_PAIR(7));
    attrset(COLOR_PAIR(7));
    mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
    mvwhline(my_menu_win, 2, 1, ACS_HLINE, 24);
    mvwaddch(my_menu_win, 2, 24, ACS_RTEE);
    mvprintw(LINES - 2, 1, " Press F1 to exit");
    /* Post the menu */
    mvprintw(LINES - 3, 1, " Press <ENTER> to see the option selected");
    mvprintw(LINES - 2, 1, " Up and Down arrow keys to navigate (F1 to Exit)");
    post_menu(my_menu);
    if(!mm)
        moto(0);
    else
        moto(1);
    refresh();

    /* Post the menu */
    post_menu(my_menu);
    wrefresh(my_menu_win);

    while((c = wgetch(my_menu_win)) != KEY_F(1))
    {   switch(c)
        {
        case KEY_DOWN:
            menu_driver(my_menu, REQ_DOWN_ITEM);
            break;
        case KEY_UP:
            menu_driver(my_menu, REQ_UP_ITEM);
            break;
        case 10:
            cur = current_item(my_menu);
            endwin();
            unpost_menu(my_menu);
            clear();
            refresh();
            void (*p)(char *);
            cur = current_item(my_menu);
            p = item_userptr(cur);
            p((char *)item_name(cur));
            pos_menu_cursor(my_menu);
            initscr();	/* Post the menu */
            attrset(COLOR_PAIR(7));
            mvprintw(LINES - 3, 1, " Press <ENTER> to see the option selected");
            mvprintw(LINES - 2, 1, " Up and Down arrow keys to naviage (F1 to Exit)");
            goto START;
            refresh();
            break;
        }
        wrefresh(my_menu_win);
    }

    /* Unpost and free all the memory taken up */
    for(i = 0; i < n_choices; ++i)
        free_item(my_items[i]);
    free_menu(my_menu);
    endwin();
    exit(1);
}
示例#10
0
void listModules()
{
    int x,y;
    getmaxyx(pluginWin,y,x);

    vector<ITEM*> pluginEntries;
    pluginEntries.resize(pluginList::getInstance()->activated_classes.size()+2);

    for (int i = 0; i < pluginList::getInstance()->activated_classes.size(); i++)
    {
        pluginEntries.at(i) = new_item(pluginList::getInstance()->activated_classes.at(i)->getName().c_str(),pluginList::getInstance()->activated_classes.at(i)->getDescription().c_str());
    }
    pluginEntries.at(pluginList::getInstance()->activated_classes.size()) = new_item("Exit","Return to console");
    pluginEntries.at(pluginList::getInstance()->activated_classes.size()+1) = 0;


    moduleMenu = new_menu(&pluginEntries[0]);

    WINDOW* win;

    win = derwin(pluginWin,y-4, x-4, 2, 2);
    set_menu_win (moduleMenu, win);
    set_menu_sub (moduleMenu, derwin(win, y-8, x-8, 3, 2));
    set_menu_mark (moduleMenu,"-->");
    box(win, 0, 0);
    mvwaddstr(win, 1, (x-26)/2, "***** Choose Module! *****");
    post_menu(moduleMenu);

    refresh();
    wrefresh(win);

    int ch;
    int chosen = -1;
    while ((ch = getch()))
    {
        switch(ch)
        {
        case KEY_DOWN:
            menu_driver(moduleMenu, REQ_DOWN_ITEM);
            break;
        case KEY_UP:
            menu_driver(moduleMenu, REQ_UP_ITEM);
            break;
        case 0xA:
            if(item_index(current_item(moduleMenu)) == pluginEntries.size()-2)
                exit(0);
            else
                chosen = item_index(current_item(moduleMenu));
        }
        if (chosen != -1)
            break;
        wrefresh(win);
    }
    //we have chosen the plugin we want, clean up the pluginWindow and start it!
    unpost_menu(moduleMenu);
    free_menu(moduleMenu);
    for( int i=0; i<=pluginEntries.size()-2; i++)
    {
        free_item(pluginEntries[i]);
    }
    delwin(win);
    emptyBoxWin(pluginWin);

    loadModule(chosen);
}
示例#11
0
WINDOW* vwm_main_menu(void)
{
    extern WINDOW   *SCREEN_WINDOW;
	MENU            *menu = NULL;
	WINDOW 		    *window;
	int			    width = 0,height = 0;
    int             screen_height;

	vwm_module_t	*vwm_module;
    char            buf[NAME_MAX];

    gchar			**item_list;
    int             idx = 0;
    int             i;

    // allocate storage for a total of MAX_MENU_ITEMS
    item_list = (gchar**)g_malloc0(sizeof(gchar*) * (MAX_MENU_ITEMS + 1));

    item_list[idx] = g_strdup_printf(" ");
    idx++;

    // iterate through the categories defined in modules.def
    for(i = 0;i < VWM_MOD_TYPE_MAX;i++)
    {
        // skip screensaver type modules.  they are a special class.
        if(i == VWM_MOD_TYPE_SCREENSAVER) continue;

        // print the menu category (type) to the window
        item_list[idx] = g_strdup_printf("%s",modtype_desc[i]);
        idx++;

        vwm_module = NULL;

        do
        {
            if(idx == MAX_MENU_ITEMS) break;

            vwm_module = vwm_module_find_by_type(vwm_module,i);
            if(vwm_module == NULL) break;

            vwm_module_get_title(vwm_module,buf,sizeof(buf) - 1);
            item_list[idx] = g_strdup_printf("..%s",buf);
            idx++;
        }
        while(vwm_module != NULL);

        // add a space before the next menu category
        if(idx < MAX_MENU_ITEMS)
        {
            item_list[idx] = g_strdup_printf(" ");
            idx++;
        }
    }

    menu = viper_menu_create(item_list);
    while(idx != -1)
    {
        g_free(item_list[idx]);
        idx--;
    }
    g_free(item_list);

	// hide character mark on left hand side
	set_menu_mark(menu," ");

    window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80);

	scale_menu(menu,&height,&width);
	width++;
	if(width < 16) width = 16;

 	// override the default of 1 column X 16 entries per row
    if(height>(screen_height-4)) height=screen_height-4;
	set_menu_format(menu,height,1);

	viper_thread_enter();
	window = viper_window_create(" Menu ",1,2,width,height,TRUE);
    /*
        todo:   it would be nice if the user could resize the menu
                (especially in the horizonal direction) and add more
                columns to the display.  right now, it's not a priority
                (but it would be easy to implement).  just need a few
                lines of code for the event window-resized.  for now,
                just don't allow it
    */
	set_menu_win(menu,window);
	set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD);
	set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE));
	menu_opts_off(menu,O_NONCYCLIC);
	post_menu(menu);
    vwm_menu_marshall(menu,REQ_DOWN_ITEM);

	/* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */
	viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE,
		(gpointer)menu);
	viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE);
	viper_window_set_userptr(window,(gpointer)menu);

	viper_thread_leave();
	return window;
}
示例#12
0
int main(){

	WINDOW *my_win, *menu_win, *my_menu_win;
	ITEM **my_items;
	MENU *my_menu;
	list *FileBuffer;
	
	int height, width, startx, starty, exit = 0;
	int highlight = 1;
	int ch, c, choice = 0, i, j;
	char str[81];
	
	FileBuffer = (list *)malloc(sizeof(list));
	
	
	if (FileBuffer == NULL)
		return;
	
	InitialiseBuffer(FileBuffer);
	
	initscr();
	clear();
	noecho();
	cbreak();
	
	start_color();
	
	
	/*Checking whether the terminal supports colors*/
	if (has_colors() == FALSE){
		endwin();
		printf("Your terminal does not support colors\n");
	}
		
	
	keypad(stdscr, TRUE);
	
	height = 3;
	width = 10;
	starty = (LINES - height)/2;
	startx = (COLS - width) / 2;	

	refresh();
	
	my_win = Create_NewWindow(height, width, starty, startx);

	mvwhline(my_win, 5, 1,	ACS_HLINE, width - 1);
	
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_CYAN, COLOR_BLACK);
	
	/* Create items */
    my_items = (ITEM **)calloc(nchoices, sizeof(ITEM *));
    for(i = 0; i < nchoices; ++i)
    	my_items[i] = new_item(menu_options[i], menu_options[i]);

	/* Create menu */	
	my_menu = new_menu((ITEM **)my_items);

	/* Set menu option not to show the description */
	menu_opts_off(my_menu, O_SHOWDESC);

	/* Create the window to be associated with the menu */
    my_menu_win = newwin(0, 0, 0, 0);
    keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
	set_menu_sub(my_menu, derwin(my_menu_win, 0, 0, 0, 0));
 	set_menu_format(my_menu, 1, 6);
	set_menu_mark(my_menu, " * ");


	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
	
	i = 0;
		
	mvwhline(my_menu_win, 1, 0, ACS_HLINE, COLS);
	mvwprintw(my_menu_win, LINES - 1, 0, "Press F3 to go to the menu, F6 to exit", c);
	
	
	while(1){
		choice = ToggleMenu(my_menu_win, my_menu, i);
		i = choice;
		switch(choice){
			case 0:
				MenuOpen(FileBuffer, my_menu_win);
				break;
			case 1:
				MenuNew(FileBuffer, my_menu_win, my_menu);
				break;
			case 2:
				MenuSave(FileBuffer, my_menu_win);
				break;
			case 3:
				MenuSaveAs(FileBuffer, my_menu_win);
				break;
			case 4:
				MenuEdit(FileBuffer, my_menu_win);
				break;
			case 5:
				MenuExit(FileBuffer, my_menu_win);
				exit = 1;
				break;
			default:
				break;
		}
		if (exit)
			break;
	}
	/*Assertion: the user wants to exit the program*/
    
		
	/* Unpost and free all the memory taken up */
       unpost_menu(my_menu);
       free_menu(my_menu);
       for(j = 0; j < nchoices; ++j)
               free_item(my_items[j]);
                
	clrtoeol();
	refresh();	
	
	/*Ending curses mode*/
	
	endwin();		
	return 0;
}
示例#13
0
//
// Affiche le tableau des high-scores dans une fenêtre modale.
//
void displayLeaderboard() {
    int i, c;
    
    const int menuWidth = 10;
    
    const int winHeight = MAX_SAVED_SCORES_COUNT + 6;
    const int winWidth = POPUP_WINDOW_WIDTH + 20;
    
    const int colRank = 2;
    const int colScore = 20;
    const int colName = 35;
    const int colBoard = 55;
    
    ITEM* menuItems[2];
    MENU* menu;
    
    Score scores[MAX_SAVED_SCORES_COUNT];
    
    int n = loadScoreBoard(scores);
    
    while (true) {
        clear();
        refresh();
        
        WINDOW* win = newwin(winHeight, winWidth, (LINES - winHeight) / 2, (COLS - winWidth) / 2);
        box(win, 0, 0);
        
        mvwaddch(win, 2, 0, ACS_LTEE);
        mvwhline(win, 2, 1, ACS_HLINE, winWidth - 1);
        mvwaddch(win, 2, winWidth - 1, ACS_RTEE);
        
        mvwprintw(win, 1, colRank, "CLASSEMENT");
        mvwprintw(win, 1, colScore, "SCORE");
        mvwprintw(win, 1, colName, "PSEUDO");
        mvwprintw(win, 1, colBoard, "PLATEAU");
        
        mvwaddch(win, 0, colScore - 2, ACS_TTEE);
        mvwvline(win, 1, colScore - 2, ACS_VLINE, winHeight - 2);
        mvwaddch(win, winHeight - 1, colScore - 2, ACS_BTEE);
        
        mvwaddch(win, 0, colName - 2, ACS_TTEE);
        mvwvline(win, 1, colName - 2, ACS_VLINE, winHeight - 2);
        mvwaddch(win, winHeight - 1, colName - 2, ACS_BTEE);
        
        mvwaddch(win, 0, colBoard - 2, ACS_TTEE);
        mvwvline(win, 1, colBoard - 2, ACS_VLINE, winHeight - 2);
        mvwaddch(win, winHeight - 1, colBoard - 2, ACS_BTEE);
        
        for(i = 0; i < n; i++) {
            mvwprintw(win, i + 3, colRank, "#%d", i+1);
            mvwprintw(win, i + 3, colScore, "%d", scores[i].score);
            mvwprintw(win, i + 3, colName, "%s", scores[i].username);
            mvwprintw(win, i + 3, colBoard, "%s", scores[i].boardName);
        }
        
        menuItems[0] = new_item("<Retour>", NULL);
        menuItems[1] = (ITEM *) NULL;
        
        //on initialise le menu
        menu = new_menu((ITEM **) menuItems);
        
        //on lui précise bien que le menu fait 1 ligne et 1 colonne
        set_menu_format(menu, 1, 1);
        
        //on associe le menu à une fenêtre et une sous-fenêtre
        set_menu_win(menu, win);
        //fenêtre hauteur largeur x y
        set_menu_sub(menu, derwin(win, 1, menuWidth, winHeight - 2, (winWidth - menuWidth) / 2));
        set_menu_mark(menu, "");
        
        noecho();
        curs_set(0);
        
        //et hop, on affiche le menu et on rafraîchit.
        post_menu(menu);
        
        wrefresh(win);
        refresh();
        
        //boucle pour le menu
        while((c = getch())) {
            bool resized = false;
            
            switch(c) {
                case KEY_RESIZE:
                    //si le terminal a été redimensionné, on ré-exécute la boucle d'affichage
                    resized = true;
                    break;
                case KEY_MENU_ENTER: {
                    unpost_menu(menu);
                    free_menu(menu);
                    
                    for(i = 0; i < 2; ++i)
                        free_item(menuItems[i]);
                    
                    clear();
                    refresh();
                    
                    delwin(win);
                    
                    curs_set(1);
                    echo();
                    return;
                }
            }
            
            if(resized) break;
            wrefresh(win);
        }
    }
}
示例#14
0
/**
 * Documentation here
 */
void main_menu()
{


  MENU *my_menu;
  /* Order here doesn't matter. Name (the first item in each of these
     "pairs") does. If you change the name, change the selection
     handling code towards the end of this function. */
  char *my_choices[] = {
    "Create","(Create new termship game)",
    "Join", "(Join existing termship game on network)",
    "Exit", "",
    (char *)NULL, (char *)NULL
  };
  ITEM **my_items;
  int n_choices = ARRAY_SIZE(my_choices)/2;

  /* some testing modes: */
#ifdef TEST_SHIPS
  initShips();
  return;
#endif

  keypad(stdscr, TRUE);
  curs_set(0); // make cursor invisible
  noecho();
  title_screen();

  clear();

  my_items = (ITEM **)calloc(n_choices,sizeof(ITEM *));
  for (int i=0; my_choices[i*2]!=NULL; ++i) {
    /* i*2 since we're iterating in pairs */
    my_items[i] = new_item(my_choices[(i*2)], my_choices[(i*2)+1]);
  }

  my_menu = new_menu(my_items);
  set_menu_mark(my_menu, "   * ");
  post_menu(my_menu);
  refresh();

  int c;
  while ((c = getch()) != 10) {
    switch (c) {
    case KEY_DOWN:
      menu_driver(my_menu, REQ_DOWN_ITEM);
      break;
    case KEY_UP:
      menu_driver(my_menu, REQ_UP_ITEM);
      break;
    }
  }
  ITEM *cur = current_item(my_menu);
  const char *selected_name = item_name(cur);
  
  /* delete the menu, free resources */
  for (int i=0; i<n_choices-1; ++i) {
    free_item(my_items[i]);
  }
  /* free(my_items); */
  unpost_menu(my_menu);
  free_menu(my_menu);

  if (0==strcmp(selected_name, "Create")) {
    user_mode = SERVER_MODE;
    get_text_string_from_centered_panel("Enter your name",
                    global_user_name,
                    MAX_NAME);
    init_game(user_mode);
  } else if (0==strcmp(selected_name, "Join")) {
    user_mode = CLIENT_MODE;
    get_text_string_from_centered_panel("Enter your name",
                    global_user_name,
                    MAX_NAME);
    init_game();
  }

  return;
}
示例#15
0
文件: nchgdc.c 项目: Eeketh/hgd
int
hgd_update_files_win(struct ui *u)
{
	ITEM			**items = NULL;
	char			 *slash_append, *prep_item_str;
	struct dirent		**dirents_dirs = 0, **dirents_files = 0, *d, *d_copy;
	int			  n_dirs = 0, n_files = 0;
	int			  i, cur_item = 0, ret = HGD_FAIL;

	DPRINTF(HGD_D_INFO, "Update files window");

	wclear(u->content_wins[HGD_WIN_FILES]);
	hgd_unpost_and_free_content_menu(u, HGD_WIN_FILES);

	if ((n_dirs = scandir(
	    u->cwd, &dirents_dirs, hgd_filter_dirs, alphasort)) < 0) {
		 DPRINTF(HGD_D_WARN, "Failed to scan directory: '%s'", u->cwd);
		 goto clean;
	}

	if ((n_files = scandir(
	    u->cwd, &dirents_files, hgd_filter_files, alphasort)) < 0) {
		 DPRINTF(HGD_D_WARN, "Failed to scan directory: '%s'", u->cwd);
		 goto clean;
	}

	/* make our menu items */
	DPRINTF(HGD_D_INFO, "allocating %d menu items", n_files + n_dirs);
	items = xcalloc(n_files + n_dirs + 1, sizeof(ITEM *));

	/* add dirs */
	for (i = 0; i < n_dirs; i++) {
		d = dirents_dirs[i];

		xasprintf(&slash_append, "%s/", d->d_name);
		hgd_prepare_item_string(&prep_item_str, slash_append);
		free(slash_append);

		items[cur_item] = new_item(prep_item_str, NULL);

		if (items[cur_item] == NULL) {
			DPRINTF(HGD_D_WARN,
			    "Could not make new menu item: %s", SERROR);
			free(prep_item_str);
			continue;
		}

		/*
		 * jam away the dirent for later use
		 * Note! scandir does notallocate a full struct dirent
		 */
#if !defined(__linux__)
		d_copy = xcalloc(1, sizeof(struct dirent));
		d_copy->d_fileno = d->d_fileno;2
		d_copy->d_reclen = d->d_reclen;
		d_copy->d_type = d->d_type;
		d_copy->d_namlen = d->d_namlen;
		strlcpy(d_copy->d_name, d->d_name, d->d_namlen + 1);
#else
		d_copy = xcalloc(1, d->d_reclen);
		memcpy(d_copy, d, d->d_reclen);
#endif

		set_item_userptr(items[cur_item], d_copy);

		cur_item++;
	}

	/* add files */
	for (i = 0; i < n_files; i++) {
		d = dirents_files[i];

		hgd_prepare_item_string(&prep_item_str, d->d_name);

		items[cur_item] = new_item(prep_item_str, NULL);

		if (items[cur_item] == NULL) {
			DPRINTF(HGD_D_WARN,
			    "Could not make new menu item: %s", SERROR);
			free(prep_item_str);
			continue;
		}

		/*
		 * copy manually, do not use memcpy, as scandir does not
		 * allocate a full struct dirent
		 */
#if !defined(__linux__)
		d_copy = xcalloc(1, sizeof(struct dirent));
		d_copy->d_fileno = d->d_fileno;2
		d_copy->d_reclen = d->d_reclen;
		d_copy->d_type = d->d_type;
		d_copy->d_namlen = d->d_namlen;
		strlcpy(d_copy->d_name, d->d_name, d->d_namlen + 1);
#else
		d_copy = xcalloc(1, d->d_reclen);
		memcpy(d_copy, d, d->d_reclen);
#endif

		set_item_userptr(items[cur_item], d_copy);

		cur_item++;
	}

	DPRINTF(HGD_D_INFO, "Actually allocated %d menu items", cur_item);
	items[cur_item] = NULL;

	u->content_menus[HGD_WIN_FILES] = new_menu(items);

	keypad(u->content_wins[HGD_WIN_FILES], TRUE);
	set_menu_win(u->content_menus[HGD_WIN_FILES],
	    u->content_wins[HGD_WIN_FILES]);
	set_menu_mark(u->content_menus[HGD_WIN_FILES], "");
	set_menu_format(u->content_menus[HGD_WIN_FILES],
	    LINES - 2, 1);
	set_menu_fore(u->content_menus[HGD_WIN_FILES],
	    COLOR_PAIR(HGD_CPAIR_SELECTED));

	if ((post_menu(u->content_menus[HGD_WIN_FILES])) != E_OK)
		DPRINTF(HGD_D_WARN, "Could not post menu");

	ret = HGD_OK;

clean:
	if (dirents_files) {
		for (i = 0; i < n_files; i ++)
			free(dirents_files[i]);
		free(dirents_files);
	}

	if (dirents_dirs) {
		for (i = 0; i < n_dirs; i ++)
			free(dirents_dirs[i]);
		free(dirents_dirs);
	}

#if 0
	if (items)
		free(items);
#endif

	return (ret);

}
示例#16
0
文件: term.c 项目: lchsk/xstarter
static void
prepare_for_new_results(Boolean clear)
{
    results_not_found = False;
    const config_t *conf = config();

    clear_menu(clear);

    choices_cnt = g_list_length(results);

    if (choices_cnt == 0) {
        no_results();
    }

    list_items = (ITEM**) calloc(choices_cnt + 1, sizeof(ITEM*));

    for (int i = 0; i < choices_cnt; i++) {
        if (results_not_found) {
            if (query_len == 0) {
                list_items[i] = new_item("Start typing to search", "");
            } else {
                list_items[i] = new_item("No results, sorry", "");
            }
        } else {
            GList *l = g_list_nth(results, i);
            char *path = l->data;

            char *name = g_path_get_basename(path);
            names = g_list_prepend(names, name);

            if (conf->section_main->numeric_shortcuts) {
                if (i < 10) {
                    list_items[i] = new_item(digits[i], name);
                }
                else
                    list_items[i] = new_item(" ", name);
            } else {
                list_items[i] = new_item(name, (char*) NULL);
            }
        }
    }

    list_items[choices_cnt] = new_item((char*) NULL, (char*) NULL);

    menu_list = new_menu((ITEM**) list_items);

    window = newwin(
        30, // rows
        30, // cols
        2,
        0
    );

    keypad(window, TRUE);
    /* nodelay(window, TRUE); */

    set_menu_win(menu_list, window);
    set_menu_mark(menu_list, "");
    set_menu_fore(menu_list, COLOR_PAIR(XS_COLOR_PAIR_1));
    set_menu_format(menu_list, 10, 1);

    post_menu(menu_list);

    update_info_bar();

    refresh();
}
示例#17
0
文件: nchgdc.c 项目: Eeketh/hgd
int
hgd_update_console_win(struct ui *u)
{
	char		  buf[HGD_LOG_BACKBUFFER + 1], *start = buf, *end, *copy;
	long		  pos, endpos, read;
	long		  toread = HGD_LOG_BACKBUFFER;
	ITEM		**items = NULL;
	int		  cur_index = 0;

	DPRINTF(HGD_D_INFO, "Update console window");

	wclear(u->content_wins[HGD_WIN_CONSOLE]);
	hgd_unpost_and_free_content_menu(u, HGD_WIN_CONSOLE);

	memset(buf, 0, HGD_LOG_BACKBUFFER + 1);

	/* find how long the log is */
	if ((fseek(logs.rd, 0, SEEK_END)) != 0)
		DPRINTF(HGD_D_WARN, "fseek: %s", SERROR);

	endpos = ftell(logs.rd);
	if (endpos < HGD_LOG_BACKBUFFER)
		toread = endpos;

	/* rewind at most HGD_LOG_BACKBUFFER and read into buffer */
	if ((fseek(logs.rd, -toread, SEEK_END)) != 0)
		DPRINTF(HGD_D_WARN, "fseek: %s", SERROR);

	pos = ftell(logs.rd);
	if ((read = fread(buf, toread, 1, logs.rd)) == 0) {
		if (ferror(logs.rd)) {
		    DPRINTF(HGD_D_WARN,
			"Failed to read console log: %s", SERROR);
		}
	}

	/* ensure we dont start printing the middle of a line */
	if (pos < 0)
		DPRINTF(HGD_D_WARN, "ftell failed: %s", SERROR);
	else if (pos != 0) {
		/* if not at the start of file, find a \n */
		while ((*start != '\n') && (*start != '\0'))
			start++;
	}

	/* this SHOULD happen, but not guaraunteed */
	if (*start == '\n')
		start++;

	items = xcalloc(sizeof(ITEM *), 1);

	/* scan for lines and add them as menu items */
	end = start;
	while (*start != 0) {
		while ((*end != 0) && (*end != '\n'))
			end++;

		if (*end == 0) {
			DPRINTF(HGD_D_WARN, "Unexpected end of log");
			break;
		}
		*end = 0;

		/* could be more efficient */
		items = xrealloc(items, sizeof(ITEM *) * (cur_index + 2));
		items[cur_index + 1] = NULL;

		hgd_prepare_item_string(&copy, start);
		items[cur_index] = new_item(copy, NULL);

		if (items[cur_index] == NULL) {
			DPRINTF(HGD_D_WARN,
			    "Could not make new menu item '%s'", start);
			free(copy);
		}

		end++;
		start = end;

		if (items[cur_index] == NULL)
			continue;

		cur_index++;
	}

	/* now we have our items, make the menu */
	if (u->content_menus[HGD_WIN_CONSOLE] != NULL) {
		/* XXX clean up old menu */
	}

	u->content_menus[HGD_WIN_CONSOLE] = new_menu(items);

	keypad(u->content_wins[HGD_WIN_CONSOLE], TRUE);
	set_menu_win(u->content_menus[HGD_WIN_CONSOLE],
	    u->content_wins[HGD_WIN_CONSOLE]);
	set_menu_mark(u->content_menus[HGD_WIN_CONSOLE], "");
	set_menu_format(u->content_menus[HGD_WIN_CONSOLE],
	    LINES - 2, 1);
	set_menu_fore(u->content_menus[HGD_WIN_CONSOLE],
	    COLOR_PAIR(HGD_CPAIR_SELECTED));

	if ((post_menu(u->content_menus[HGD_WIN_CONSOLE])) != E_OK)
		DPRINTF(HGD_D_WARN, "Could not post menu");

	menu_driver(u->content_menus[HGD_WIN_CONSOLE], REQ_LAST_ITEM);

	return (HGD_OK);
}
示例#18
0
int main()
{
    ITEM **my_items;
	int c;				
	MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;
	
	/* Initialize curses */
	initscr();
	start_color();
    cbreak();
    noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_CYAN, COLOR_BLACK);
    
	/* Create items */
    n_choices = ARRAY_SIZE(choices);
    my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
    for(i = 0; i < n_choices; ++i)
        my_items[i] = new_item(choices[i], choices[i]);
    
	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);
    
	/* Set menu option not to show the description */
	menu_opts_off(my_menu, O_SHOWDESC);
    
	/* Create the window to be associated with the menu */
    my_menu_win = newwin(10, 70, 4, 4);
    keypad(my_menu_win, TRUE);
    
	/* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win, 6, 68, 3, 1));
	set_menu_format(my_menu, 5, 3);
	set_menu_mark(my_menu, " * ");
    
	/* Print a border around the main window and print a title */
    box(my_menu_win, 0, 0);
	
	attron(COLOR_PAIR(2));
	mvprintw(LINES - 3, 0, "Use PageUp and PageDown to scroll");
	mvprintw(LINES - 2, 0, "Use Arrow Keys to navigate (F1 to Exit)");
	attroff(COLOR_PAIR(2));
	refresh();
    
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
	
	while((c = wgetch(my_menu_win)) != KEY_F(1))
	{
        switch(c)
	    {
        case KEY_DOWN:
            menu_driver(my_menu, REQ_DOWN_ITEM);
            break;
        case KEY_UP:
            menu_driver(my_menu, REQ_UP_ITEM);
            break;
        case KEY_LEFT:
            menu_driver(my_menu, REQ_LEFT_ITEM);
            break;
        case KEY_RIGHT:
            menu_driver(my_menu, REQ_RIGHT_ITEM);
            break;
        case KEY_NPAGE:
            menu_driver(my_menu, REQ_SCR_DPAGE);
            break;
        case KEY_PPAGE:
            menu_driver(my_menu, REQ_SCR_UPAGE);
            break;
		}
        wrefresh(my_menu_win);
	}	

	/* Unpost and free all the memory taken up */
    unpost_menu(my_menu);
    free_menu(my_menu);
    for(i = 0; i < n_choices; ++i)
        free_item(my_items[i]);
	endwin();
}
示例#19
0
// Scan MAME ROMs folder, cross-reference against XML (if present) for
// verbose descriptions, generate ncurses menu.
static void find_roms(void) {
	FILE           *fp;
	struct dirent **dirList;
	int             i, nFiles;
	Game           *g;       // For traversing Game linked list
	WINDOW         *scanWin; // Modal 'Scanning...' window

	if(noRomWin) { // Delete 'No ROMS' window if present
		delwin(noRomWin);
		noRomWin = NULL;
		werase(mainWin);
		box(mainWin, 0, 0);
	}

	if(items) { // Delete old ROM menu and contents, if any
		if(menu) {
			unpost_menu(menu);
			free_menu(menu);
			menu = NULL;
		}
		for(i=0; items[i]; i++) free_item(items[i]);
		free(items);
		items = NULL;
	}

	const char scanMsg[] = "Scanning ROM folder...";
	scanWin = newwin(3, strlen(scanMsg) + 4,
	  (LINES - 4) / 2 - 1, (COLS - strlen(scanMsg)) / 2 - 2);
	box(scanWin, 0, 0);
	mvwprintw(scanWin, 1, 2, scanMsg);

	wnoutrefresh(mainWin);
	wnoutrefresh(scanWin);
	doupdate();

	delwin(scanWin);
	werase(mainWin);
	box(mainWin, 0, 0);

	while(gameList) { // Delete existing gameList, if any
		g = gameList->next;
		if(gameList->name) free(gameList->name);
		if(gameList->desc) free(gameList->desc);
		free(gameList);
		gameList = g;
	}

	i = 0; // Count number of games found & successfully alloc'd
	if((nFiles = scandir(rom, &dirList, sel, alphasort)) > 0) {
		// Copy dirent array to a Game linked list
		while(nFiles--) { // List is assembled in reverse
			if((g = (Game *)malloc(sizeof(Game)))) {
				g->name  = strdup(dirList[nFiles]->d_name);
				g->desc  = NULL;
				g->next  = gameList;
				gameList = g;
				i++; // A winner is you
			}
			// dirList contents are freed as we go
			free(dirList[nFiles]);
		}
		free(dirList);
	}

	// Alloc, load, cross-reference XML file against ROM filenames
	if((fp = fopen(xml, "r"))) {
		fseek(fp, 0, SEEK_END);
		char *buf;
		int   len = ftell(fp);
		if((buf = (char *)malloc(len))) {
			int depth = 0;
			fseek(fp, 0, SEEK_SET);
			fread(buf, 1, len, fp);
			XML_Parser parser = XML_ParserCreate(NULL);
			XML_SetUserData(parser, &depth);
			XML_SetElementHandler(parser,
			  startElement, endElement);
			XML_SetCharacterDataHandler(parser, elementData);
			XML_Parse(parser, buf, len, 1);
			XML_ParserFree(parser);
			free(buf);
		}
		fclose(fp);
	}

	if((items = (ITEM**)malloc((i + 1) * sizeof(ITEM *)))) {
		for(i=0, g=gameList; g; g=g->next, i++) {
			items[i] = new_item(g->name, g->desc);
			set_item_userptr(items[i], g);
		}
		items[i] = NULL;
		menu = new_menu(items);
		set_menu_win(menu, mainWin);
		set_menu_sub(menu, derwin(mainWin, LINES-6, COLS-2, 1, 1));
		set_menu_format(menu, LINES-6, 1);
		set_menu_mark(menu, " ");
		post_menu(menu);
	}

	wrefresh(mainWin);

	if(!menu) { // If no ROMs, throw up a message to that effect
		const char noRomMsg[] = "No ROMs found";
		noRomWin = newwin(3, strlen(noRomMsg) + 4,
		  (LINES - 4) / 2 - 1, (COLS - strlen(noRomMsg)) / 2 - 2);
		box(noRomWin, 0, 0);
		mvwprintw(noRomWin, 1, 2, noRomMsg);
		wrefresh(noRomWin);
	}
}
示例#20
0
文件: textris.c 项目: biirdy/textris
void textris(){
	int score = 0;

	srand(time(NULL));

	setlocale(LC_ALL, "");

	initscr();			
	cbreak();
	noecho();
	halfdelay(1);
	keypad(stdscr, TRUE);

	start_color();
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_YELLOW, COLOR_BLACK);
	init_pair(3, COLOR_BLUE, COLOR_BLACK);
	init_pair(4, COLOR_GREEN, COLOR_BLACK);
	init_pair(5, COLOR_WHITE, COLOR_BLACK);
	init_pair(6, COLOR_CYAN, COLOR_BLACK);
	init_pair(7, COLOR_MAGENTA, COLOR_BLACK);

	//menu

	int MENU_WIDTH = 20;
	int SCREEN_WIDTH = 100;

	char *choices[] = {
                        "20 Lines",
                        "40 Lines",
                        "Classic",
                        "Read Me",
                        "Exit",
                  };

	ITEM **menu_items;
	int c;				
	MENU *menu;
	int n_choices, i;
	ITEM *cur_item;
	WINDOW *menu_win;

	n_choices = ARRAY_SIZE(choices);
	menu_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

	for(i = 0; i < n_choices; ++i)
	        menu_items[i] = new_item(choices[i], "");
	menu_items[n_choices] = (ITEM *)NULL;

	menu = new_menu((ITEM **)menu_items);

	/* Create the window to be associated with the menu */
	menu_win = newwin(10, MENU_WIDTH + 2, 5, (SCREEN_WIDTH/2) - (MENU_WIDTH/2));
	keypad(menu_win, TRUE);

	/* Set main window and sub window */
	set_menu_win(menu, menu_win);
	set_menu_sub(menu, derwin(menu_win, 6, MENU_WIDTH, 3, 1)); //must be less than window

	/* Set menu mark to the string " * " */
	set_menu_mark(menu, " * ");
	post_menu(menu);
	wrefresh(menu_win);

	draw_menu(menu_win, menu);

	refresh();

	while((c = wgetch(menu_win)) != KEY_F(1))
	{   switch(c)
	    {	case KEY_DOWN:
		        menu_driver(menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(menu, REQ_UP_ITEM);
				break;
			case KEY_LEFT:
				twenty_lines();
				draw_menu(menu_win, menu);
				break;
		}
	}	

	for(i = 0; i < n_choices; ++i)
		free_item(menu_items[i]);
	free_menu(menu);
	endwin();

	//double res = twenty_lines();

	/*while(1){
		mvprintw(0, 0, "20 lines cleared in %f seconds", res);
		refresh();
	}

	endwin();*/
}
示例#21
0
static void main_menu(){
    MENU *my_menu;
    WINDOW *left_win, *right_win, *bottom_win_box, *bottom_win;
    int n_options;
    
    clear();

    //initialize color schemes used by update window
    init_pair(1, COLOR_BLUE, 0);
    init_pair(2, COLOR_YELLOW, 0); 
    init_pair(3, COLOR_RED, 0);


    
    //Initialize an array of items to put in menu
    n_options = sizeof(left_main_menu_options)/sizeof(ITEM *);
    ITEM ** my_items = (ITEM **)calloc(n_options+1, sizeof(ITEM *)); 
    for(int i = 0; i < n_options; i++){
            my_items[i] = new_item(left_main_menu_options[i], "");
    }
    
    //initialize menu
    my_menu = new_menu(my_items);
    
    //create the left, right, and bottom windows for main menu.
    left_win = newwin(terminal_y/2, (terminal_x/2), 0, 0);
    right_win = newwin(terminal_y/2, (terminal_x/2), 0, terminal_x/2);
    bottom_win = newwin(terminal_y/2-2, terminal_x-2, terminal_y/2+1,1);
    bottom_win_box = newwin(terminal_y/2, terminal_x, terminal_y/2, 0);
    
    keypad(left_win, TRUE);
    nodelay(left_win, TRUE);
 
    // main/sub window
    set_menu_win(my_menu, left_win);
    set_menu_sub(my_menu, derwin(left_win, 6, (terminal_x/2)-2, 3, 1));
    
    //Set title of left menu and selection character
    char program_title[] = "Welcome to AFLDFF!";
    mvwprintw(left_win, 1, (terminal_x/4)-(strlen(program_title)/2), program_title);
    set_menu_mark(my_menu, " * ");
    
    //box seperator for left menu
    box(left_win, 0, 0);
    mvwaddch(left_win, 2, 0, ACS_LTEE);
    mvwhline(left_win, 2, 1, ACS_HLINE, (terminal_x/2)-2);
    mvwaddch(left_win, 2, (terminal_x/2)-1, ACS_RTEE);

    //menu post
    post_menu(my_menu);
    wrefresh(left_win);
    
    box(bottom_win_box, 0, 0);
    wrefresh(bottom_win_box);

    while(1){
        main_menu_right(right_win);
        main_menu_bottom(bottom_win);
        ITEM * choice = main_menu_left(left_win, my_menu); 

        /************************************************
         *Switch used to control Main menu options      *
         ************************************************/
                
        if(choice != NULL){
            char * menu_selection = (char *) item_name(choice);
            //VIEW JOBS
            if(strcmp(menu_selection, left_main_menu_options[0]) == 0){ 
                global_state = WOOPS;
                return;
            }
            //COLLECT CRASHES
            else if(strcmp(menu_selection, left_main_menu_options[1]) == 0){
                global_state = WOOPS;
                return;
            }
            //APPLY PATCH
            else if(strcmp(menu_selection, left_main_menu_options[2]) == 0){
                global_state = APPLY_PATCH;
                break;
            }
            //EXIT
            else if(strcmp(menu_selection, left_main_menu_options[3]) == 0){
                endwin();
                exit(0);
            }
            else{
                global_state = WOOPS;
                return;
            }
        
        }
                
        usleep(10000);
    }


    /* Unpost and free all the memory taken up */
    unpost_menu(my_menu);
    free_menu(my_menu);
    for(int i = 0; i < n_options; ++i){
            free_item(my_items[i]);
    }
    delwin(left_win);
    delwin(right_win);
    delwin(bottom_win);
    delwin(bottom_win_box);
}
示例#22
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
	
	/* Initialize curses */
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);

	/* Create items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i)
                my_items[i] = new_item(choices[i], choices[i]);

	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);

	/* Create the window to be associated with the menu */
        my_menu_win = newwin(10, 40, 4, 4);
        keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));

	/* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");

	/* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
	mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
	mvprintw(LINES - 2, 0, "F1 to exit");
	refresh();
        
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);

	while((c = wgetch(my_menu_win)) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
		}
                wrefresh(my_menu_win);
	}	

	/* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
        for(i = 0; i < n_choices; ++i)
                free_item(my_items[i]);
	endwin();
}
示例#23
0
int teacher_menu(char *database){
	int i, c, n, choice = 0;
	teacher *xteacher;
	WINDOW *win;
	ITEM **items;
	MENU *menu;
	n = teacher_number(database);
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	xteacher = (teacher *)malloc(sizeof(teacher) * (n + 1));
	items = (ITEM **)calloc(n + 3, sizeof(ITEM *));
	for(i = 0; i < n; ++i) {
		xteacher[i] = get_teacher(database,i);
		items[i] = new_item(xteacher[i].name, NULL);
	}
	menu = new_menu((ITEM **)items);
	win = newwin(0, 0, 0, 0);
	int y,x;
	getmaxyx(win,y,x);
	keypad(win, TRUE);
	set_menu_win(menu, win);
	set_menu_sub(menu, derwin(win, y - 5, 38, 5, 0.4*x));
	set_menu_format(menu,x - 4, 1);
	set_menu_mark(menu, " * ");
	set_menu_spacing(menu, 0, 2, 0);
	box(win, 0, 0);
	print_in_middle(win, 1, 0, x, "Teachers" , COLOR_PAIR(1));
	mvwaddch(win, 2, 0, ACS_LTEE);
	mvwhline(win, 2, 1, ACS_HLINE, x - 2);
	mvwaddch(win, 2, x - 1, ACS_RTEE);
	mvwaddch(win, y - 3, 0, ACS_LTEE);
	mvwhline(win, y - 3, 1, ACS_HLINE, x - 2);
	mvwaddch(win, y - 3, x - 1, ACS_RTEE);
	refresh();
	if(n) {
		if(n > 1)
			mvwprintw(win,y - 2, 2,"N:New Teacher\t\tR:Remove Teacher\tS:Sort\t\tB:Back\tQ:Quit");
		else
			mvwprintw(win,y - 2, 2,"N:New Teacher\t\tR:Remove Teacher\tB:Back\tQ:Quit");
		for(i = 0; i < choice; i++)
			menu_driver(menu, REQ_DOWN_ITEM);
		post_menu(menu);
		wrefresh(win);
		while((c = wgetch(win))){
			switch(c) {
				case KEY_DOWN:
					menu_driver(menu, REQ_DOWN_ITEM);
					if(choice != n -1)
						choice++;
					break;
				case KEY_UP:
					menu_driver(menu, REQ_UP_ITEM);
					if(choice != 0)
						choice--;
					break;
				case 10: /* Enter */
					remove_menu(menu,items,n);
					return choice;
				case 'R':
				case 'r':
					remove_teacher(database, choice);
					remove_menu(menu,items,n);
					return -1;
				case 'B':
				case 'b':
					remove_menu(menu,items,n);
					return n + 1;
				case 'N':
				case 'n':
					remove_menu(menu,items,n);
					return n + 2;
				case 'Q':
				case 'q':
					remove_menu(menu,items,n);
					return INT_MIN;
				default:
					break;
			}
			wrefresh(win);
		}
	}
	else {
		mvwprintw(win,y - 2, 2,"N:New Teacher\t\tB:Back\t\tQ:Quit");
		mvwprintw(win,5,3*x/7,"No Teachers found :(\n");
		wrefresh(win);
		curs_set(0);
		while((c = wgetch(win)))
		{
			switch(c) {
				case 'n':
				case 'N':
					remove_menu(menu,items,n);
					curs_set(1);
					return n+2;
				case 'b':
				case 'B':
					remove_menu(menu,items,n);
					curs_set(1);
					return n+1;
				case 'Q':
				case 'q':
					remove_menu(menu,items,n);
					curs_set(1);
					return INT_MIN;
				default:
					break;
			}
			wrefresh(win);
		}
	}
	free(xteacher);
	return -1;
}
示例#24
0
/* get the message, and buttons.
 * each button must be a char*
 * return the selected button
 *
 * this dialog is used for 2 different things:
 * 1) show a text box, no buttons.
 * 2) show a dialog, with horizontal buttons
 */
int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
{
	va_list ap;
	char *btn;
	int btns_width = 0;
	int msg_lines = 0;
	int msg_width = 0;
	int total_width;
	int win_rows = 0;
	WINDOW *win;
	WINDOW *msg_win;
	WINDOW *menu_win;
	MENU *menu;
	ITEM *btns[btn_num+1];
	int i, x, y;
	int res = -1;


	va_start(ap, btn_num);
	for (i = 0; i < btn_num; i++) {
		btn = va_arg(ap, char *);
		btns[i] = new_item(btn, "");
		btns_width += strlen(btn)+1;
	}
	va_end(ap);
	btns[btn_num] = NULL;

	/* find the widest line of msg: */
	msg_lines = get_line_no(msg);
	for (i = 0; i < msg_lines; i++) {
		const char *line = get_line(msg, i);
		int len = get_line_length(line);
		if (msg_width < len)
			msg_width = len;
	}

	total_width = max(msg_width, btns_width);
	/* place dialog in middle of screen */
	y = (getmaxy(stdscr)-(msg_lines+4))/2;
	x = (getmaxx(stdscr)-(total_width+4))/2;


	/* create the windows */
	if (btn_num > 0)
		win_rows = msg_lines+4;
	else
		win_rows = msg_lines+2;

	win = newwin(win_rows, total_width+4, y, x);
	keypad(win, TRUE);
	menu_win = derwin(win, 1, btns_width, win_rows-2,
			1+(total_width+2-btns_width)/2);
	menu = new_menu(btns);
	msg_win = derwin(win, win_rows-2, msg_width, 1,
			1+(total_width+2-msg_width)/2);

	set_menu_fore(menu, attributes[DIALOG_MENU_FORE]);
	set_menu_back(menu, attributes[DIALOG_MENU_BACK]);

	(void) wattrset(win, attributes[DIALOG_BOX]);
	box(win, 0, 0);

	/* print message */
	(void) wattrset(msg_win, attributes[DIALOG_TEXT]);
	fill_window(msg_win, msg);

	set_menu_win(menu, win);
	set_menu_sub(menu, menu_win);
	set_menu_format(menu, 1, btn_num);
	menu_opts_off(menu, O_SHOWDESC);
	menu_opts_off(menu, O_SHOWMATCH);
	menu_opts_on(menu, O_ONEVALUE);
	menu_opts_on(menu, O_NONCYCLIC);
	set_menu_mark(menu, "");
	post_menu(menu);


	touchwin(win);
	refresh_all_windows(main_window);
	while ((res = wgetch(win))) {
		switch (res) {
		case KEY_LEFT:
			menu_driver(menu, REQ_LEFT_ITEM);
			break;
		case KEY_RIGHT:
			menu_driver(menu, REQ_RIGHT_ITEM);
			break;
		case 10: /* ENTER */
		case 27: /* ESCAPE */
		case ' ':
		case KEY_F(F_BACK):
		case KEY_F(F_EXIT):
			break;
		}
		touchwin(win);
		refresh_all_windows(main_window);

		if (res == 10 || res == ' ') {
			res = item_index(current_item(menu));
			break;
		} else if (res == 27 || res == KEY_F(F_BACK) ||
				res == KEY_F(F_EXIT)) {
			res = KEY_EXIT;
			break;
		}
	}

	unpost_menu(menu);
	free_menu(menu);
	for (i = 0; i < btn_num; i++)
		free_item(btns[i]);

	delwin(win);
	return res;
}
示例#25
0
文件: pkgui.c 项目: nbyouri/pkgui
/*
 * Return codes:
 *  0 - action performed
 * -1 - quit was pressed (only for main menu)
 * +1 - backspace or escape was pressed, back to previous menu
 */
static int
do_menu(struct menuoption *runmenu, int num, int upper, const char *title, ...)
{
	int ch, i, y, x;
//	char buf[BUFSIZ];
	char *buf;
	struct menuoption *curmenu;
	ITEM **mitems, *mitem;
	MENU *mmenu;
	WINDOW *msubwin;
	va_list ap;

	/* Clear screen and print title */
	if (upper)
		show_mainwin(0);
	else
		show_mainwin(1);
	va_start(ap, title);
	head_mainwin(title, ap);
	va_end(ap);

	x = 0;
	y = 0;
	if (upper)
		msubwin = create_uppersubwin();
	else
		msubwin = create_lowersubwin(&y, &x);

	mitems = (ITEM **)calloc(num + 1, sizeof(ITEM*));
	for (curmenu = runmenu, i = 0; i < num; i++) {
		ch = sizeof buf > x ? x - 1 : sizeof buf - 1;
//		if (snprintf(buf, ch, "%s", curmenu->m_name) <= 0) {
		if (asprintf(&buf, "%s", curmenu->m_name) <= 0) {
			ask_ok("Error creating the menu.");
			for (i--; i >= 0; i--)
				free(mitems[i]);
			return 0;
		}
		mitems[i] = new_item(buf, NULL);
		set_item_userptr(mitems[i], (void *)curmenu);
//		warnx("%ld %s", (long)curmenu, curmenu->m_name);
		curmenu++;
	}
	mitems[num] = NULL;

	mmenu = new_menu(mitems);
	set_menu_win(mmenu, mainwin);
	set_menu_sub(mmenu, msubwin);
	set_menu_format(mmenu, upper ? 1 : y, 1);
	if (colouring) {
		set_menu_fore(mmenu, COLOR_PAIR(1));
		set_menu_back(mmenu, COLOR_PAIR(1));
		set_menu_grey(mmenu, COLOR_PAIR(1));
	}
	set_menu_mark(mmenu, ">");
	if (post_menu(mmenu)) {
		ask_ok("Error posting the menu.");
		return 1;
	}
	show_mainwin(0);
	show_lowersubwin(0, msubwin);

	while ((ch = getch()) != '\n' && ch != '\b') {
		switch (ch) {
			case KEY_DOWN:
				menu_driver(mmenu, REQ_NEXT_ITEM);
				break;
			case KEY_UP:
				menu_driver(mmenu, REQ_PREV_ITEM);
				break;
			case KEY_NPAGE:
				menu_driver(mmenu, REQ_SCR_DPAGE);
				break;
			case KEY_PPAGE:
				menu_driver(mmenu, REQ_SCR_UPAGE);
				break;
			case KEY_END:
				menu_driver(mmenu, REQ_LAST_ITEM);
				break;
			case KEY_HOME:
				menu_driver(mmenu, REQ_FIRST_ITEM);
				break;
		}
		show_mainwin(0);
		show_lowersubwin(0, msubwin);
	}

	mitem = current_item(mmenu);
	curmenu = (struct menuoption *)item_userptr(mitem);

	unpost_menu(mmenu);
	delwin(msubwin);
	free_menu(mmenu);
	for (i = 0; i < num; i++)
		free_item(mitems[i]);
	free(mitems);

	if (ch != '\b' && curmenu->m_action != NULL) {
		curmenu->m_action(curmenu->m_argv);
		return 0;
	} else {
		return 1;
	}
}
示例#26
0
/*
 * create the internal menu for the files 
 */
static void wdg_file_menu_create(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   int mrows, mcols;
   int i;
   size_t c = wdg_get_ncols(wo);
   size_t x = wdg_get_begin_x(wo);
   size_t y = wdg_get_begin_y(wo);
   struct stat buf;

   /* the menu is already posted */
   if (ww->nitems)
      return;
 
   WDG_DEBUG_MSG("wdg_file_menu_create");
   
   /* get the working directory */
   getcwd(ww->curpath, PATH_MAX);
         
   /* scan the directory */
   ww->nlist = scandir(".", &ww->namelist, 0, alphasort);

   /* on error display the message in the box */
   if (ww->nlist <= 0) {
      ww->nitems = 2;
      WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
      ww->items[ww->nitems - 2] = new_item("/", "root");
      ww->items[ww->nitems - 1] = new_item("Cannot open the directory", "");
      item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE);
   } else {

      /* for each directory in the directory */
      for (i = 0; i < ww->nlist; i++) {
        
         /* 
          * transform the current dir into the root.
          * useful to exit from a path whose parent is not readable 
          */
         if (!strcmp(ww->namelist[i]->d_name, ".")) {
            strncpy(ww->namelist[i]->d_name, "/", 1);
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "root");
            continue;
         }
         
         /* get the file properties */
         stat(ww->namelist[i]->d_name, &buf);
         
         if (S_ISDIR(buf.st_mode)) {
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "[...]");
         }
         // if not readable
         //item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE);
      }
      
      /* and now add the files */
      for (i = 0; i < ww->nlist; i++) {
         
         /* get the file properties */
         stat(ww->namelist[i]->d_name, &buf);
         
         if (!S_ISDIR(buf.st_mode)) {
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "");
         }
      }
   }

   /* null terminate the array */
   WDG_SAFE_REALLOC(ww->items, (ww->nitems + 1) * sizeof(ITEM *));
   ww->items[ww->nitems] = NULL;
     
   /* create the menu */
   ww->m = new_menu(ww->items);

   /* set the dimensions */
   set_menu_format(ww->m, ww->y - 2, 1);
   set_menu_spacing(ww->m, 2, 0, 0);

   /* get the geometry to make a window */
   scale_menu(ww->m, &mrows, &mcols);

   /* 
    * if the menu is larger than the main window
    * adapt to the new dimensions
    */
   if (mcols > (int)c - 4) {
      ww->x = mcols + 4;
      wdg_file_redraw(wo);
      return;
   }
   /* create the window for the menu */
   ww->mwin = newwin(mrows, MAX(mcols, (int)c - 4), y + 1, x + 2);
   /* set the color */
   wbkgd(ww->mwin, COLOR_PAIR(wo->window_color));
   keypad(ww->mwin, TRUE);
  
   /* associate with the menu */
   set_menu_win(ww->m, ww->mwin);
   
   /* the subwin for the menu */
   set_menu_sub(ww->m, derwin(ww->mwin, mrows + 1, mcols, 1, 1));

   /* menu attributes */
   set_menu_mark(ww->m, "");
   set_menu_grey(ww->m, COLOR_PAIR(wo->window_color));
   set_menu_back(ww->m, COLOR_PAIR(wo->window_color));
   set_menu_fore(ww->m, COLOR_PAIR(wo->window_color) | A_REVERSE | A_BOLD);
   
   /* display the menu */
   post_menu(ww->m);

   wnoutrefresh(ww->mwin);
   
}
示例#27
0
WINDOW* vwm_main_menu(void)
{
   extern WINDOW  *SCREEN_WINDOW;
	MENU           *menu=NULL;
	WINDOW 		   *window;
	gint			   width=0,height=0;
   gint           screen_height;

	VWM_MODULE	   *vwm_module;
	GSList		   *category_list=NULL;
	GSList		   *module_list=NULL;
	GSList		   *node1;
	GSList		   *node2;

	gchar			   **item_list;
   gint           idx=0;

   /* allocate storage for 128 menu items    */
   item_list=(gchar**)g_malloc0(sizeof(gchar*)*(MAX_MENU_ITEMS+1));

   item_list[idx]=g_strdup_printf(" ");
   idx++;
	category_list=vwm_modules_list_categories();
   node1=category_list;
   while(node1!=NULL && idx<MAX_MENU_ITEMS)
   {
      /* skip screensavers */
      if(strcmp((gchar*)node1->data,VWM_SCREENSAVER)==0)
      {
         node1=node1->next;
         continue;
      }

      /* add the category  */
      item_list[idx]=g_strdup_printf("%s",(gchar*)node1->data);
      idx++;
      if(idx==MAX_MENU_ITEMS) break;

      module_list=vwm_modules_list((gchar*)node1->data);
      node2=module_list;
      while(node2!=NULL)
      {
         if(idx==MAX_MENU_ITEMS) break;
         vwm_module=(VWM_MODULE*)node2->data;
         item_list[idx]=g_strdup_printf("..%s",vwm_module->title);
         idx++;
         node2=node2->next;
      }

      /* add a space before the next menu category  */
      if(idx<MAX_MENU_ITEMS)
      {
         item_list[idx]=g_strdup_printf(" ");
         idx++;
      }

      if(module_list!=NULL) g_slist_free(module_list);
      node1=node1->next;
   }
   if(category_list!=NULL) g_slist_free(category_list);

   menu=viper_menu_create(item_list);
   while(idx!=-1)
   {
      g_free(item_list[idx]);
      idx--;
   }
   g_free(item_list);

	/* hide character mark on left hand side */
	set_menu_mark(menu," ");

   window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80);

	scale_menu(menu,&height,&width);
	width++;
	if(width<16) width=16;
 	/* override the default of 1 column X 16 entries per row */
   if(height>(screen_height-4)) height=screen_height-4;
	set_menu_format(menu,height,1);

	viper_thread_enter();
	window=viper_window_create(" Menu ",1,2,width,height,TRUE);
   /* todo:  it would be nice if the user could resize the window (especially
      in the horizonal direction) and add more columns to the display.  right
      now, it's not a priority (but it would be easy to implement).  just need
      a few lines of code for the event window-resized.  for now, just don't
      allow it */
	set_menu_win(menu,window);
	set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD);
	set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE));
	menu_opts_off(menu,O_NONCYCLIC);
	post_menu(menu);
   vwm_menu_marshall(menu,REQ_DOWN_ITEM);

	/* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */
	viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE,
		(gpointer)menu);
	viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE);
	viper_window_set_userptr(window,(gpointer)menu);

	viper_thread_leave();
	return window;
}
示例#28
0
void viewListPlayers(FootBallGame::TeamNumber teamNumber) {
  String teamName;
  int nChoices;
  ITEM **items;
  const char *itemName;
  const ITEM *currentItem;
  LinkedList<String*> names = LinkedList<String*>(deleteString);
  LinkedList<int*> pids = LinkedList<int*>(deleteInt);

  const int window_nlines = 10,
            window_ncols  = 90;

  for(;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);

    // Set up the items of menu.
    FootBallTeam *team = game.getFootBallTeam(teamNumber);
    if (team != NULL) {
      nChoices = team->getPlayerCount() + 2;
      items = new ITEM* [nChoices];

      TeamIterator iterator, end;
      team->begin(iterator);
      team->end(end);
      for (int i = 0; iterator != end; i++, iterator++) {
        Player *player = *iterator;
        String *playerName = new String;
        int *pid = new int;
        player->getName(*playerName);
        *pid = player->getPid();
        names.append(playerName);
        pids.append(pid);
        items[i] = new_item(playerName->c_str(), NULL);
        set_item_userptr(items[i], pid);
      }
    } else  {
      nChoices = 2;
      items = new ITEM* [nChoices];
    }
    items[nChoices-2] = new_item("Exit", NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu((ITEM **)items);
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 10, 80, 0, 10));
    set_menu_mark(menu, NULL);
    // Do not Show the item descritpions
    menu_opts_off(menu, O_SHOWDESC);

    post_menu(menu);
    wrefresh(window);
    refresh();
    
    int c;
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch (c) {
        case KEY_DOWN:
          menu_driver(menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(menu, REQ_UP_ITEM);
          break;
        case 10: // Enter
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          if (itemName != NULL) {
            if (strcmp(itemName, "Exit") == 0) {
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              return;
            } else  {
              int *pid = (int*)item_userptr(currentItem);
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              viewPlayer(team, itemName, *pid);
              restart = true;
            }
          }
      }
    }
  }
}
示例#29
0
//
// Demande à l'utilisateur s'il souhaite rejouer.
//
bool wantsToReplay(WINDOW *win, int top) {
    if(win == NULL || top < 0) return false;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    
    int i = 0, c;
    int nbChoices = 2;
    
    char *choices[] = {
        "Menu Principal",
        "Quitter"
    };
    
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = 22;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    //on initialise le menu
    menu = new_menu((ITEM **) menuItems);
    
    //on lui précise bien que le menu fait 1 ligne et 2 colonnes
    set_menu_format(menu, 1, 2);
    
    //on associe le menu à une fenêtre et une sous-fenêtre
    set_menu_win(menu, win);
    //fenêtre hauteur largeur x y
    set_menu_sub(menu, derwin(win, nbChoices, menuWidth, top, (winWidth - menuWidth) / 2));
    
    menu_opts_off(menu, O_NONCYCLIC);
    set_menu_mark(menu, "");
    
    //et hop, on affiche le menu et on rafraîchit.
	post_menu(menu);
	
    refresh();
    wrefresh(win);
    
    curs_set(0);
    noecho();
    
    //boucle pour le menu
    while((c = getch())) {
        switch(c) {
            case KEY_LEFT:
            case KEY_UP:
                menu_driver(menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
            case KEY_DOWN:
                menu_driver(menu, REQ_RIGHT_ITEM);
                break;
            case KEY_MENU_ENTER: {
                int choice = item_index(current_item(menu));
                
                unpost_menu(menu);
                free_menu(menu);
                
                for(i = 0; i < nbChoices; ++i)
                    free_item(menuItems[i]);
                
                //si l'indice est 1 on renvoie 0 et vice-versa
                return !choice;
            }
        }
        
        wrefresh(win);
    }
    
    return false;
}