Пример #1
0
/*
 * Initialize and call all necessary functions
 */
int main(int argc, char *argv[]) {
    int i;

    strcpy(path, getenv("PWD"));
    // Usage and invalid command line args
    if (argc > 2) {
        usage();
        return -1;
    } else if (argc == 2) {
        if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)
            usage();
        else if (strlen(argv[1]) < PATH_MAX) {
            strcpy(path, argv[1]);
            errNum = chdir(path);
            if (errNum != 0)
                fprintf(stderr, "Error changing directory: %s\n", strerror(errNum));
        }
        else
            fprintf(stderr, "Error: input path too long\n");
    }

    initscr();  // Start curses mode
    if (stdscr == NULL) {
        fprintf(stderr, "Error: could not initialize curses\n");
        exit(-1);
    }
    cbreak();               // Disable line buffering
    noecho();               // Disable user input echoing
    keypad(stdscr, TRUE);   // Read function keys

    // Setup color
    start_color();
    init_pair(1, COLOR_RED, COLOR_BLACK);

    current = FILES;
    updateDisplay();
    handleUserInput();

    // Clean up memory
    unpost_menu(menus[0]);
    free_menu(menus[0]);
    for (i = 0; i < numFiles; i++)
        free_item(fileItems[i]);
    unpost_menu(menus[1]);
    free_menu(menus[1]);
    for (i = 0; i < numDirs; i++)
        free_item(dirItems[i]);
    endwin();

    return 0;
}
Пример #2
0
/*
 * Free the menu and items memory.
 */
void __renderers_free_home_page(void)
{
	int i;
	struct userptr_data *data;

	if (!main_menu)
		return;

	unpost_menu(main_menu);

	for (i = 0; i < nb_items; i++) {
		free((void *) main_items[i]->description.str);
		free((void *) main_items[i]->name.str);

		data = item_userptr(main_items[i]);
		free((void *) data->dbus_name);
		free((void *) data->pretty_name);
		free(data);

		free_item(main_items[i]);
	}

	free_menu(main_menu);
	free(main_items);
	nb_items = 0;
	main_menu = NULL;
	main_items = NULL;
}
Пример #3
0
/*
 * delete the internal menu for the files 
 */
static void wdg_file_menu_destroy(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   int i = 0;
   
   /* nothing to free */
   if (ww->nitems == 0)
      return;
   
   unpost_menu(ww->m);
   free_menu(ww->m);

   /* free all the items */
   while(ww->items[i] != NULL) 
      free_item(ww->items[i++]);

   for (i = 0; i < ww->nlist; i++)
      WDG_SAFE_FREE(ww->namelist[i]);
  
   /* free the array */
   WDG_SAFE_FREE(ww->items);
   WDG_SAFE_FREE(ww->namelist);
   
   /* reset the counter */
   ww->nitems = 0;
}
Пример #4
0
int main()
{	
	initscr();
	start_color();
	ITEM *menuitems[6];
	MENU *menubar;
	WINDOW *win,*sub_win;
	int i,rows,cols;
	//initcolor();
	menuitems[0]=new_item("File","");
	menuitems[1]=new_item("Edit","");
	menuitems[2]=new_item("Options","");
	menuitems[3]=new_item("Window","");
	menuitems[4]=new_item("Help","");
	menuitems[5]=NULL;
	//menu_opts_off(menubar,O_ROWMAJOR);
	menubar=new_menu(menuitems);
	scale_menu(menubar,&rows,&cols);
	win=newwin(rows+2,cols+2,2,5);
	box(win,179,196);
	sub_win=derwin(win,rows,cols,1,1);
	set_menu_win(menubar,win);
	set_menu_sub(menubar,sub_win);
	post_menu(menubar);
	wrefresh(win);

	wgetch(sub_win);
	unpost_menu(menubar);
	free_menu(menubar);
	for(i=0;i<6;i++)
		free_item(menuitems[i]);
	endwin();
}
Пример #5
0
/*
 * Delete the popup allocated memory.
 * This *won't* free popup_btn_action.
 */
void popup_delete(void)
{
	int i;

	if (popup_form) {
		unpost_form(popup_form);

		for (i = 0; popup_fields[i] != NULL; i++) {
			free(field_buffer(popup_fields[i], 0));
			free_field(popup_fields[i]);
		}

		free_form(popup_form);
		free(popup_fields);
	}

	unpost_menu(popup_menu);
	free_menu(popup_menu);

	for (i = 0; popup_items[i] != NULL; i++)
		free_item(popup_items[i]);

	free(popup_items);
	delwin(win_form);
	delwin(win_menu);
	delwin(win_body);
	win_body = NULL;
	popup_btn_action = NULL;
	popup_menu = NULL;
}
Пример #6
0
void clean_menu(MENU * my_menu){
        unpost_menu(my_menu);
        if(my_menu != NULL)
                free_menu(my_menu);
        mvprintw(LINES - 2, 0, "                      "); //efface pied de page pour fermer le menu
        refresh();
}
Пример #7
0
void
free_term_gui(void)
{
    if (menu_list) {
        unpost_menu(menu_list);
        free_menu(menu_list);
    }

    if (list_items) {
        for (int i = 0; i < choices_cnt; i++) {
            free_item(list_items[i]);
        }

        free(list_items);
    }

    unpost_form(form);

    if (form)
        free_form(form);

    free_field(field[0]);

    endwin();
}
Пример #8
0
void
show_chooser_win(MENU *dirmenu, size_t items, char *buf)
{
	int	 c = 0;
	size_t	 buflen, offset = 0;
	char	*tmp;

	buflen = strlen(buf) - 1;

	set_menu_fore(dirmenu, A_REVERSE);
	returnval = set_menu_format(dirmenu, LINES, 1);
	post_menu(dirmenu);
	refresh();

	while ((c = getch()) != 'q') {
		switch(c) {
		case 'j':
		case KEY_DOWN:
			menu_driver(dirmenu, REQ_DOWN_ITEM);
			break;
		case 'k':
		case KEY_UP:
			menu_driver(dirmenu, REQ_UP_ITEM);
			break;
		case KEY_NPAGE:
			menu_driver(dirmenu, REQ_SCR_DPAGE);
			break;
		case KEY_PPAGE:
			menu_driver(dirmenu, REQ_SCR_UPAGE);
			break;
		case KEY_END:
			menu_driver(dirmenu, REQ_LAST_ITEM);
			break;
		case KEY_HOME:
			menu_driver(dirmenu, REQ_FIRST_ITEM);
			break;
		case 10: /* Enter */
			move(20, 0);
			clrtoeol();

			tmp = (char *)item_name(current_item(dirmenu));
			offset = strlcpy(buf, tmp, MAX_CHOICESIZE);
			if (offset >= MAX_CHOICESIZE)
				goto toolong;
			if (strlcpy(buf + offset,
				    item_description(current_item(dirmenu)),
				    MAX_CHOICESIZE - offset))
				goto toolong;

			pos_menu_cursor(dirmenu);
			break;
		}
	}
toolong:
	unpost_menu(dirmenu);
	fprintf(stdout, "shit happens\n");

	fprintf(stdout, "VALUE WAS: %d\n", returnval);
}
Пример #9
0
int mainmenu(int height, int width) {
    int ret;
    ITEM **menu_items;
    MENU *main_menu;
    int n_choices, i;

    clean_main_menu();
    build_main_menu(instance_path);

    n_choices = menu_size;
    menu_items = (ITEM **) calloc(n_choices + 1, sizeof (ITEM *));
    for (i = 0; i < n_choices; ++i) {
        menu_items[i] = new_item(menu_values[i], menu_values[i]);
        set_item_userptr(menu_items[i], (void *) menu_selected);
    }
    menu_items[n_choices] = (ITEM *) NULL;
    main_menu = new_menu((ITEM **) menu_items);
    menu_opts_off(main_menu, O_SHOWDESC);

    set_menu_sub(main_menu, derwin(stdscr, 10, 50, 6, 10));

    post_menu(main_menu);
    attron(A_BOLD);
    mvprintw(0, 0, name);
    mvprintw(0, width - strlen(vers), vers);
    attroff(A_BOLD);
    refresh();
    pos_menu_cursor(main_menu);
    while ((i = getch()) != KEY_F(4)) {
        switch (i) {
            case KEY_DOWN:
                menu_driver(main_menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(main_menu, REQ_UP_ITEM);
                break;
            case 10:
            {
                ITEM *cur;
                int (*p)(char *);
                cur = current_item(main_menu);
                p = (int (*)(char *))item_userptr(cur);
                ret = p((char *) item_name(cur));
                pos_menu_cursor(main_menu);
                goto menu_sel;
            }
        }
    }
    if (i == KEY_F(4)) {
        ret = menu_size - 1;
    }

menu_sel:
    unpost_menu(main_menu);
    free_menu(main_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(menu_items[i]);
    return ret;
}
Пример #10
0
int main(int argc, char const *argv[]) {
    ITEM **my_items;
    int c;
    MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;

    initscr();
    start_color();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    init_pair(1, COLOR_RED, COLOR_BLACK);

    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]);

    my_menu = new_menu((ITEM **) my_items);
    my_menu_win = newwin(10, 40, 4, 4);
    keypad(my_menu_win, TRUE);

    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));

    set_menu_mark(my_menu, " * ");

    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_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_menu(my_menu);
    free_menu(my_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(my_items[i]);

    endwin();
    return 0;
}
Пример #11
0
int generic_menu::get_choice()
{
    if (choices.size() == return_values.size())
    {
        //create the menu and the item pointer vector
        MENU* my_menu;
        std::vector<ITEM*> my_items;
        WINDOW* menu_win = derwin(screen, choices.size(), 30, ypos, xpos);
        ITEM* cur = NULL;
        for (int x = 0; x < choices.size(); x++)
        {
            //populate the items vector with the string data in choices
            //c_str because ncurses is very old
            my_items.push_back(new_item(choices.at(x).c_str(), NULL));
        }
        //pushback a null item for safety
        my_items.push_back((ITEM*)NULL);
        //create the menu and attach the items
        my_menu = new_menu((ITEM**)my_items.data());
        //print the desc and post the menu
        mvwprintw(screen, LINES - 3, 0, "%s\n", desc.c_str());
        //set_current_item(my_menu, lastItem);
        set_menu_win(my_menu, menu_win);
        keypad(menu_win, TRUE);
        post_menu(my_menu);
        touchwin(screen);
        wrefresh(menu_win);
        std::vector<int>::iterator return_iter = return_values.begin();
        int c = 0;
        while((c = wgetch(menu_win)) != '\n')
        {   
            touchwin(screen);
            wrefresh(menu_win);
            switch(c)
            {	case KEY_DOWN:
                    menu_driver(my_menu, REQ_DOWN_ITEM);
                    if (return_iter != return_values.end())
                    {
                        return_iter++;
                    }
                    break;
                case KEY_UP:
                    menu_driver(my_menu, REQ_UP_ITEM);
                    if (return_iter != return_values.begin())
                    {
                        return_iter--;
                    }
                    break;
            }
        }
        unpost_menu(my_menu);
        for (int x = 0; x < my_items.size(); x++)
        {
            free_item(my_items[x]);
        }
        free_menu(my_menu);
        return *return_iter;
    }
}
static void
clear_menu(MENU* my_menu, ITEM** my_items)
{
    unpost_menu(my_menu);
    free_menu(my_menu);
    for (int i =0; my_items[i]; ++i)
        free_item(my_items[i]);
    free(my_items);
}
Пример #13
0
int Zavrsi(MENU *menu, ITEM **items, int n_choices) {
	int i;
	
	Validiraj_menu(unpost_menu(menu));
    Validiraj_menu(free_menu(menu));
    for(i = 0; i < n_choices; ++i)
        Validiraj_menu(free_item(items[i]));
    Validiraj_ncurses(endwin());
	return 0;
}
Пример #14
0
void quit(void) {
	int i;

	unpost_menu(me);
	free_menu(me);

	for (i = 0; i <= 4; i++) {
		free_item(it[i]);
	}

	free(it);
	endwin();
}
Пример #15
0
void
menu_pan_free(MENUPAN *morituro)
{
    assert(morituro);

    unpost_menu(morituro->menu);
    free_menu(morituro->menu);
    delwin(morituro->win->win);
    delwin(morituro->sub->win);
    del_panel(morituro->win);
    del_panel(morituro->sub);

    free(morituro);
}
Пример #16
0
/* unpost menu and unglue items allowing them to be freed / changed in sp */
static void release_menu(smsgloader *_this)
{
    int i;
    VERBOSE_DEBUGPR("releasing scom menu requested\n");
    if(!_this->loadmenu)
    {
        DEBUGPR("Trying to free menu which is not allocated!\n");
        return;
    }
    unpost_menu(_this->loadmenu);
    for(i=0;i<_this->itemamnt;i++)
        free_item(_this->loaditems[i]);
    free(_this->loaditems);
    _this->loaditems=NULL;
    free_menu(_this->loadmenu);
    _this->loadmenu=NULL;
    if(_this->derwin)
        delwin(_this->derwin);
}
Пример #17
0
void
column_select_update_menu(ui_t *ui)
{
    // Get panel information
    column_select_info_t *info = column_select_info(ui);
    ITEM *current = current_item(info->menu);
    int top_idx = top_row(info->menu);

    // Remove the menu from the subwindow
    unpost_menu(info->menu);
    // Set menu items
    set_menu_items(info->menu, info->items);
    // Put the menu agin into its subwindow
    post_menu(info->menu);

    // Move until the current position is set
    set_top_row(info->menu, top_idx);
    set_current_item(info->menu, current);
}
Пример #18
0
int
hgd_unpost_and_free_content_menu(struct ui *u, int which)
{
	ITEM			**items;
	int			  n_items, i;

	if (u->content_menus[which] == NULL)
		return (HGD_OK);

	DPRINTF(HGD_D_INFO, "free menu: %s", window_names[which]);

	if ((n_items = item_count(u->content_menus[which])) == ERR) {
		DPRINTF(HGD_D_ERROR, "Couldn't get item count");
		return (HGD_FAIL);
	}

	if ((items = menu_items(u->content_menus[which])) == NULL) {
		DPRINTF(HGD_D_ERROR, "Got NULL items array");
		return (HGD_FAIL);
	}

	if (unpost_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not unpost menu %d", errno);

	/* must come before freeing items */
	if (free_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not free menu");

	for (i = 0; i < n_items; i++) {
		free((char *) item_name(items[i]));
		free((char *) item_description(items[i]));
		free(item_userptr(items[i]));
		if (free_item(items[i]) != OK)
			DPRINTF(HGD_D_ERROR, "can't free item");
	}

	free(items);
	u->content_menus[which] = NULL;

	return (HGD_OK);
}
Пример #19
0
void
selection_free_or_die(struct selection *selection)
{
    if (!selection) return;
    
    if (selection->menu) {
        unpost_menu(selection->menu);
        free_menu(selection->menu);
    }
    if (selection->sub_window) delwin(selection->sub_window);
    if (selection->window) delwin(selection->window);
    
    for (int i = 0; i < selection->items_count; ++i) {
        free_or_die((char *)item_name(selection->items[i]));
        free_or_die((char *)item_description(selection->items[i]));
        free_or_die(item_userptr(selection->items[i]));
        free_item(selection->items[i]);
    }
    free_or_die(selection->items);
    free_or_die(selection->title);
    free_or_die(selection);
}
Пример #20
0
int main()
{

	initscr();
	nonl();
	raw();
	noecho();
	wclear(stdscr);
	
	MENU  *menu;
	ITEM** i = item;

	menu = new_menu();
	post_menu(menu);
	sleep(5);
	unpost_menu(menu);
	refresh();
	free_menu();
	while()
	 free_item();
	 endwin();
	 exit(0);
}
Пример #21
0
void
column_select_destroy(ui_t *ui)
{
    int i;
    column_select_info_t *info = column_select_info(ui);

    // Remove menu and items
    unpost_menu(info->menu);
    free_menu(info->menu);
    for (i = 0; i < SIP_ATTR_COUNT; i++)
        free_item(info->items[i]);

    // Remove form and fields
    unpost_form(info->form);
    free_form(info->form);
    for (i = 0; i < FLD_COLUMNS_COUNT; i++)
        free_field(info->fields[i]);

    sng_free(info);

    // Remove panel window and custom info
    ui_panel_destroy(ui);
}
Пример #22
0
/* delete space for current menu */
void delete_menu(void) {
  
  int i;

  /* unpost the menu */
  unpost_menu(menu_ptr);
  /* free menu space */
  free_menu(menu_ptr);
  
  /* free item space */
  i = 0;
  while(my_menu_items[i] != NULL) {
    free_item(my_menu_items[i]);
    i++;
  }

  free(my_menu_items);
  my_menu_items = NULL;

  /* delete the subwindow */
  delwin(sub_window);
  refresh();
  
}
Пример #23
0
static void
clear_menu(Boolean clear)
{
    const config_t* conf = config();

    if (menu_list && clear) {
        /* NB: Menu removal needs to be in this order! */
        unpost_menu(menu_list);
        free_menu(menu_list);

        if (list_items) {
            for (int i = 0; i < choices_cnt; i++) {
                free_item(list_items[i]);
            }

            free(list_items);
            list_items = NULL;
        }

        if (window) {
            delwin(window);
        }
    }
}
Пример #24
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, 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, 30, 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();                                                                        
}                                                
Пример #25
0
void viewNewPlayer(FootBallGame::TeamNumber teamNumber) {
  const char *itemName;
  const ITEM *currentItem;

  const int window_nlines = 10,
            window_ncols  = 90;

  char *choices[] = {
    "Add",
    "Cancel",
  };


  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);


    // Create the form fields
    FIELD *field[6];
    for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++)
      field[i] = new_field(1, 26, i+2, 23, 0, 0);
    field[ARRAY_SIZE(field)-1] = NULL;
    // Set feild options 
    for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) {
      set_field_back(field[i], A_UNDERLINE);
      field_opts_off(field[i], O_AUTOSKIP);
    }
    // Set the field types
    set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$");
    set_field_type(field[1], TYPE_INTEGER, 0, 1, 999);
    set_field_type(field[2], TYPE_REGEXP, "^[A-Za-z ]*$");
    set_field_type(field[3], TYPE_NUMERIC, 2, 1.00, 1500.00);
    set_field_type(field[4], TYPE_NUMERIC, 2, 1.00, 300.00);
    // Create the form
    FORM *form = new_form(field);
    set_form_win(form, window);
    set_form_sub(form, derwin(window, 10, 90, 0, 0));

    // Setup the menu items
    int nChoices = ARRAY_SIZE(choices)+1;
    ITEM **items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices-1; i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;
    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_format(menu, 1, 2);
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 1, 20, 8, 17));

    // Make window and menu visible;
    post_form(form);
    post_menu(menu);
    mvwprintw(window, 0, 10, "Player Properties: ");
    mvwprintw(window, 2, 10, "Name: ");
    mvwprintw(window, 3, 10, "Number: ");
    mvwprintw(window, 4, 10, "Position: ");
    mvwprintw(window, 5, 10, "weight (kg): ");
    mvwprintw(window, 6, 10, "height (cm): ");
    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))) {
      mvprintw(LINES-1, 0, "                                         ");
      refresh();
      switch(c) {
        case KEY_DOWN:
        case 0x09:
          // Go to next field
          form_driver(form, REQ_NEXT_FIELD);
          // GO to the end of the presend buffer
          // Leaves nicely at the last character
          form_driver(form, REQ_END_LINE);
          break;
        case KEY_UP:
          // Go to previous field
          form_driver(form, REQ_PREV_FIELD);
          form_driver(form, REQ_END_LINE);
          break;
        case 0x7F:
          form_driver(form, REQ_DEL_PREV);
          break;
        case KEY_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10:
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          // Cancel
          if (strncmp(itemName, choices[1], strlen(choices[1])) == 0) {
            // Delete allocated data
            unpost_form(form); 
            unpost_menu(menu); 
            free_form(form); 
            free_menu(menu); 
            for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) 
              free_field(field[i]); 
            for (int i = 0; i < nChoices; i++)
              free_item(items[i]);
            delete [] items; 
            delwin(window);
            return;
          } else if (strncmp(itemName, choices[0], strlen(choices[0])) == 0) {
            form_driver(form, REQ_VALIDATION);
            bool invalid = false;
            for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++)
              if (field_status(field[i])==false)
                invalid = true;;
            if (invalid == false) {
              FootBallPlayer *player = new FootBallPlayer;
              player->setName(field_buffer(field[0], 0));
              player->setNumber(atoi(field_buffer(field[1], 0)));
              player->setPosition(field_buffer(field[2], 0));
              player->setWeight(strtof(field_buffer(field[3], 0), NULL));
              player->setHeight(strtof(field_buffer(field[4], 0), NULL));
              FootBallTeam *team = game.getFootBallTeam(teamNumber);
              if (team == NULL) {
                team = new FootBallTeam;
                game.setFootBallTeam(teamNumber, team);
              }
              team->addFootBallPlayer(player);
              // Delete allocated data
              unpost_form(form); 
              unpost_menu(menu); 
              free_form(form); 
              free_menu(menu); 
              for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) 
                free_field(field[i]); 
              for (int i = 0; i < nChoices; i++)
                free_item(items[i]);
              delete [] items; 
              delwin(window);
              return;
            } else {
              mvprintw(LINES-1, 0, "Fill out the form correctly!!");
              refresh();
            }
          }
          break;
        default:
          // If this is a normal character, it gets
          // printed
          form_driver(form, c);
          break;
      }
    }
  }
}
Пример #26
0
void viewEditTeamProperties(FootBallGame::TeamNumber teamNumber) {
  const char *fieldBuffer;
  const ITEM *currentItem;
  const char *itemName;
  ITEM **items;

  const int window_nlines = 10,
            window_ncols  = 90;
  
  char *choices[] = {
    "Ok",
    "Cancel",
  };

  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);
  
    // Team the team
    FootBallTeam *team = game.getFootBallTeam(teamNumber);

    // Create the form fields
    FIELD *field[2];
    field[0] = new_field(1, 20, 2, 22, 0, 0);
    field[1] = NULL;
  
    // Set feild options 
    set_field_back(field[0], A_UNDERLINE);
    field_opts_off(field[0], O_AUTOSKIP);
    set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$");
    if (team) {
      String teamName = team->getTeamName();
      set_field_buffer(field[0], 0, teamName.c_str());
    }
    
    // Create the form
    FORM *form = new_form(field);

    // Attach the form to the window
    set_form_win(form, window);
    set_form_sub(form, derwin(window, 4, 90, 0, 0));

    // Setup the menu
    int nChoices = ARRAY_SIZE(choices)+1;
    items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices-1; i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;
  
    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_format(menu, 1, 2);
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 1, 20, 4, 17));

    // Make window and menu visible;
    post_form(form);
    post_menu(menu);
    mvwprintw(window, 0, 10, "Team Properties: ");
    mvwprintw(window, 2, 10, "Team Name: ");
    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:
        case 0x09:
          // Go to next field
          form_driver(form, REQ_NEXT_FIELD);
          // GO to the end of the presend buffer
          // Leaves nicely at the last character
          form_driver(form, REQ_END_LINE);
          break;
        case KEY_UP:
          // Go to previous field
          form_driver(form, REQ_PREV_FIELD);
          form_driver(form, REQ_END_LINE);
          break;
        case 0x7F:
          form_driver(form, REQ_DEL_PREV);
          break;
        case KEY_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10: // Enter
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          if (strcmp(itemName, choices[0]) == 0) {
            form_driver(form, REQ_VALIDATION);
            fieldBuffer = field_buffer(field[0], 0);
            if (fieldBuffer != NULL && strcmp(fieldBuffer, "") != 0) {
              if (team == NULL) {
                team = new FootBallTeam;
                game.setFootBallTeam(teamNumber, team);
              }
              team->setTeamName(fieldBuffer);
            }
          }
          // Delete allocated data
          delwin(window);
          unpost_form(form); 
          free_form(form); 
          unpost_menu(menu); 
          free_menu(menu); 
          for (unsigned i = 0; i < ARRAY_SIZE(field); i++) 
            free_field(field[i]); 
          for (int i = 0; i < nChoices-1; i++) 
            free_item(items[i]); 
          delete[] items;
          return;
        default:
          // If this is a normal character, it gets printed.
          form_driver(form, c);
          break;
      }
    }
  }
}
Пример #27
0
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 = (LINES-(msg_lines+4))/2;
	x = (COLS-(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]);

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

	/* print message */
	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;
}
Пример #28
0
int main_giris()
{	
	ITEM **my_items;
	int c;				
	MENU *my_menu;
	int n_choices, i;
	ITEM *cur_item;	
	WINDOW *my_menu_win;
	
char *anamenu[] = {
        _("Market ") ,
        _("Current Module"),
	_("Cheque Module"),
	_("Stock Module"),
        _("Reports"),
        _("Configuration"),
        _("Help"),
        _("About"),
        _("Exit"),
        (char *)NULL,
                  };
	  
  	(int) signal (SIGINT, sonlandir);
  	(int) signal (SIGILL, sonlandir);
  	(int) signal (SIGTERM, sonlandir);	
		  
	//backup control
	yedek_kontrol_et();

	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	
	//sql configuration 
	ayar_dosyasi_oku ();
	
	ana_win = newwin(LINES, 80, 0, 0);
	temizle_win=newwin(LINES, 80, 0, 0);
	
	init_pair(1, COLOR_WHITE, COLOR_RED);
	init_pair(2, COLOR_WHITE, COLOR_BLUE);
	
	terminal_kontrol_et();
	if (irsaliye_gun_kontrol())  mesaj( _("Some bills not prepared. Don't forget.!") );
			
	kullanici_onayla();
	
	init_pair(1, COLOR_WHITE, COLOR_RED);
	init_pair(2, COLOR_WHITE, COLOR_BLUE);
	
	baslik_goruntule();

    	n_choices = ARRAY_SIZE(anamenu);
	my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
	for(i = 0; i < n_choices; ++i)
	my_items[i] = new_item(anamenu[i], " ");

	my_menu = new_menu((ITEM **)my_items);

	my_menu_win = newwin(15, 50, 5, 10);
	keypad(my_menu_win, TRUE);
     
	set_menu_win(my_menu, my_menu_win);
	set_menu_sub(my_menu, derwin(my_menu_win, 10, 40, 4, 2));

	set_menu_mark(my_menu, mark);

	box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 45, "Options", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 48);
	mvwaddch(my_menu_win, 2, 49, ACS_RTEE);
        
	post_menu(my_menu);
	wrefresh(my_menu_win);

	while((c = wgetch(my_menu_win)) )
	{       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_item = current_item(my_menu);
				    switch(item_index(cur_item) + 1)
				        {
				case 1:	/* Kasa satis */
						//satis
						if ( haklari_kontrol_et(0)==1 )	market_ana_ekran();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
					
				case 2:	/*cari*/
						//stok giris kontrolu
						if ( haklari_kontrol_et(0)==1 )	cari();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
	    			case 3:	/*ceksenet*/
						
						//cari giris kontrolu
						if ( haklari_kontrol_et(1)==1 )	ceksenet();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();						
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();						
						refresh();
						break;
							
				case 4:	/*stok*/
						
						//cari giris kontrolu
						if ( haklari_kontrol_et(1)==1 )	stok();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();						
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();						
						refresh();
						break;
							
							
				case 5:	/*raporlar*/

						//rapor giris kontrolu
						if ( haklari_kontrol_et(2)==1 ) raporlar();
						else
						{mesaj(_("Access denied.!!!"));}
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
						
				case 6:	/*ayarlar*/
						
						ayarlar();
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();						
						refresh();
						break;
					
				case 7:/*yardým*/
						
						yardim();

						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
					
				case 8:/*hakkýnda*/
						hakkinda();
					
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
					
				case 9:/*Kapat*/
					donen_deger=onayla(cikis_onay);
						if (donen_deger==1)
								{
								// donen deger evet ise kapat
								beep();
								touchwin(ana_win);
								wrefresh(ana_win);
								unpost_menu(my_menu);
								free_menu(my_menu);
								for(i = 0; i < n_choices; ++i)
								free_item(my_items[i]);
								endwin();
								return;
								}
						touchwin(ana_win);
						wrefresh(ana_win);								
						touchwin(my_menu_win);
						wrefresh(my_menu_win);		
						break;	
	        }

				wrefresh(my_menu_win);
				pos_menu_cursor(my_menu);
		}
                wrefresh(my_menu_win);
	}	

}
Пример #29
0
void Menu(int *value)
{
    ITEM **my_items;
  	int c;
  	MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;
    int output = 3;

  	// Create Menu 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], "");

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

  	// Create the window to be associated with the menu
          my_menu_win = newwin(15, 50, 4, 4);
          keypad(my_menu_win, TRUE);          // Enable keyboard on that window

  	// 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, 50, "THE GAME", COLOR_PAIR(1));
  	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
  	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 48);
  	mvwaddch(my_menu_win, 2, 39, ACS_RTEE);

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

    bool done = false;
  	while(!done && (c = wgetch(my_menu_win)) != 'q' )
  	{       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 was pressed
          			if(item_index(current_item(my_menu)) == 0)
                { // First menu item was selected (Play)
                  output = 1;
                  done = true;
                }
                if(item_index(current_item(my_menu)) == 1)
                { // Second menu item was selected (Help))
                  output = 2;
                  done = true;
                }
                if(item_index(current_item(my_menu)) == 2)
                { // Third menu item was selected (Exit)
                  output = 3;
                  done = true;
                }
                  break;
  		      }
            wrefresh(my_menu_win);              // Refres the window
  	}

  	// 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();
    *value = output;
}
Пример #30
0
/*

    returns 1 if yes, 0 if no
*/
int confirm(const char *title, const char *text, chtype forecolor,
        chtype backcolor, int def)
{
    int retval = 0;
    ITEM **menu_items;
    MENU *confirm_menu;
    PANEL *my_panels[1];
    WINDOW *confirm_win, *dw;
    ITEM *cur;

    int height = 7, width = 25, startx = 5, starty = 5, max_x = 0, max_y = 0;
    const char *choices[] = {STR_YES, STR_NO};

    size_t n_choices = 2, i = 0;

    int ch, quit = 0;

    char *print_title;

    /* safety */
    vrmr_fatal_if_null(title);
    vrmr_fatal_if_null(text);

    if (width - 4 < (int)StrLen(text))
        width = (int)StrLen(text) + 4;
    if (width - 6 < (int)StrLen(title))
        width = (int)StrLen(title) + 6;
    getmaxyx(stdscr, max_y, max_x);
    startx = (max_x - width) / 2;
    starty = (max_y - height) / 2;

    print_title = malloc(StrMemLen(title) + 3);
    vrmr_fatal_alloc("malloc", print_title);
    snprintf(print_title, StrMemLen(title) + 3, " %s ", title);

    menu_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
    vrmr_fatal_alloc("calloc", menu_items);
    for (i = 0; i < n_choices; ++i) {
        menu_items[i] = new_item(choices[i], NULL);
    }
    menu_items[n_choices] = (ITEM *)NULL;
    confirm_menu = new_menu((ITEM **)menu_items);
    vrmr_fatal_if_null(confirm_menu);
    confirm_win = newwin(height, width, starty, startx);
    wbkgd(confirm_win, backcolor);
    keypad(confirm_win, TRUE);
    wrefresh(confirm_win);
    my_panels[0] = new_panel(confirm_win);
    set_menu_win(confirm_menu, confirm_win);
    dw = derwin(confirm_win, height - 4, 10, 4, (width) / 2 - 5);
    set_menu_sub(confirm_menu, dw);
    set_menu_format(confirm_menu, height - 4, 2);
    box(confirm_win, 0, 0);
    print_in_middle(confirm_win, 0, 0, width, print_title, backcolor);
    print_in_middle(confirm_win, 2, 0, width, text, backcolor);
    set_menu_back(confirm_menu, backcolor);
    set_menu_fore(confirm_menu, forecolor);
    post_menu(confirm_menu);

    /* set the cursor to the 'no' position */
    if (!def) {
        menu_driver(confirm_menu, REQ_RIGHT_ITEM);
    }
    update_panels();
    doupdate();

    while (quit == 0) {
        ch = wgetch(confirm_win);
        switch (ch) {
            case KEY_DOWN:
                menu_driver(confirm_menu, REQ_LEFT_ITEM);
                break;
            case KEY_UP:
                menu_driver(confirm_menu, REQ_RIGHT_ITEM);
                break;
            case KEY_LEFT:
                menu_driver(confirm_menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
                menu_driver(confirm_menu, REQ_RIGHT_ITEM);
                break;

            case 10: // enter
            {
                cur = current_item(confirm_menu);
                vrmr_fatal_if_null(cur);
                if (strcmp((char *)item_name(cur), STR_YES) == 0) {
                    retval = 1;
                }
                quit = 1;
                break;
            }

            case 'y':
            case 'Y':
                retval = 1;
                quit = 1;
                break;

            case 'n':
            case 'N':
                retval = 0;
                quit = 1;
                break;

            case 27:
            case KEY_F(10):
            case 'q':
            case 'Q':
                quit = 1;
                break;
        }
    }

    unpost_menu(confirm_menu);
    free_menu(confirm_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(menu_items[i]);
    free(menu_items);
    destroy_win(dw);
    del_panel(my_panels[0]);
    destroy_win(confirm_win);
    free(print_title);
    update_panels();
    doupdate();
    return (retval);
}