/* display current menu */
void display_menu() {
  
  int rows, cols, begin_y, begin_x;

  /* setup menu options */
  menu_opts_off(menu_ptr, O_ROWMAJOR);
  set_menu_fore(menu_ptr, COLOR_PAIR(MENU_PAIR) | A_STANDOUT);
  set_menu_back(menu_ptr, COLOR_PAIR(MENU_PAIR) | A_DIM | A_NORMAL);

  /* setup appropriate windows */
  set_menu_win(menu_ptr, stdscr);
  scale_menu(menu_ptr, &rows, &cols);

  /* locate menu in the center */
  getmaxyx(stdscr,LINES,COLS);
  begin_y = (LINES-rows) / 2;
  begin_x = (COLS-cols) / 2;

  /* create main menu window */
  sub_window = subwin(stdscr, rows, cols, begin_y, begin_x);
  set_menu_sub(menu_ptr, sub_window);

  /* display the menu */
  post_menu(menu_ptr);
  refresh();
  
}
Exemple #2
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();
}
MENUPAN*
menu_pan_create(MENU *menu, int y, int x, int id)
{
    MENUPAN *menupan;


    assert(menu);

    menupan=(MENUPAN *)malloc(sizeof(MENUPAN));
    if(!menupan) {
        set_error(ERR_NOMEM);
        lpr_error("menu_pan_create");
    }

    menupan->id=id;
    menupan->menu=menu;
    menupan->win=new_panel(newwin(item_count(menu)+2, MSIZE, y, x));
    menupan->sub=new_panel(derwin(menupan->win->win,
                                  item_count(menu), MSIZE-2, 1, 1));
    wcolor_set(menupan->win->win, 1, NULL);
    set_menu_fore(menu, COLOR_PAIR(1) | A_REVERSE);
    set_menu_back(menu, COLOR_PAIR(1));
    set_menu_grey(menu, COLOR_PAIR(1));
    set_menu_win(menu, menupan->win->win);
    set_menu_sub(menu, menupan->sub->win);


    box(menupan->win->win, 0, 0);
    menupan_hide(menupan);

    return menupan;
}
Exemple #4
0
void printMenus() {
    int i;
    MENU *fileMenu, *dirMenu;

    // Create items
    fileItems = malloc(numFiles * sizeof(ITEM *));
    for (i = 0; i < numFiles; i++) {
        fileItems[i] = new_item(fileEntries[i]->d_name, NULL);
        if (fileItems[i] == NULL)
            break;
    }
    fileItems[numFiles] = NULL;

    dirItems = malloc(numDirs * sizeof(ITEM *));
    for (i = 0; i < numDirs; i++) {
        dirItems[i] = new_item(dirEntries[i]->d_name, NULL);
        if (dirItems[i] == NULL)
            break;
    }
    dirItems[numDirs] = NULL;


    // Create menus
    fileMenu = new_menu(fileItems);
    dirMenu = new_menu(dirItems);
    menus = malloc(2 * sizeof(MENU *));
    menus[0] = fileMenu;
    menus[1] = dirMenu;

    if (fileMenu == NULL || dirMenu == NULL) {
        fprintf(stderr, "Error creating menus\n");
    }

    // Associate windows and menus
    set_menu_win(fileMenu, cursesWins[0]);
    set_menu_sub(fileMenu, derwin(cursesWins[0], LINES / 2, (COLS / 2) - 6, 3, 1));
    set_menu_format(fileMenu, (LINES / 2), 1);

    set_menu_win(dirMenu, cursesWins[1]);
    set_menu_sub(dirMenu, derwin(cursesWins[1], LINES / 2, (COLS / 2) - 6, 3, 1));
    set_menu_format(dirMenu, (LINES / 2), 1);

    post_menu(fileMenu);
    wrefresh(cursesWins[0]);
    post_menu(dirMenu);
    wrefresh(cursesWins[1]);
}
Exemple #5
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;
}
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;
}
Exemple #7
0
void displayMenu(int y, int x, char title[],int numOfOpt, char *options[], void (*p[])(void)){
	int i,c;
	WINDOW *menuWindow;
	MENU *myMenu;
	ITEM **myOptions;
	ITEM *currentOption;
	initscr();
	noecho();
	cbreak();
	keypad(stdscr,TRUE);
	init_pair(1,COLOR_CYAN,COLOR_BLACK);
	myOptions=(ITEM **)calloc(numOfOpt+1,sizeof(ITEM *));
	for(i=0;i<numOfOpt;i++){
		myOptions[i]=new_item(options[i]," ");
		set_item_userptr(myOptions[i],p[i]);	
	}
	myOptions[numOfOpt]=(ITEM *)NULL;
	myMenu=new_menu(myOptions);
	menuWindow = newwin(8,20,(LINES-y)/2,(COLS-x)/2);
	keypad(menuWindow,TRUE);
	set_menu_win(myMenu,menuWindow);
	set_menu_sub(myMenu, derwin(menuWindow,y-4,x-2,3,1));
	set_menu_format(myMenu,numOfOpt,1);
	menu_opts_off(myMenu, O_SHOWDESC);
	set_menu_mark(myMenu," * ");
	post_menu(myMenu);
	wrefresh(menuWindow);
	while((c=wgetch(menuWindow))!=KEY_F(2)){
		switch(c){
			case KEY_UP:
				menu_driver(myMenu,REQ_UP_ITEM);
				break;
			case KEY_DOWN:
				menu_driver(myMenu,REQ_DOWN_ITEM);
				break;
			case 10:{
				ITEM *temp;
				temp=current_item(myMenu);
				void(*pointer)(void);
				pointer=item_userptr(temp);
				pointer();
				pos_menu_cursor(myMenu);
				menu_driver(myMenu,REQ_DOWN_ITEM);
				break;
				}
			wrefresh(menuWindow);
		}
	}
	/*unpost_menu(myMenu);*/
	/*for(i=0;i<numOfOpt;++i){*/
		/*free_item(myOptions[i]);*/
	/*}*/
	/*free_menu(myMenu);*/
	/*free(optionsNumbers);*/
}
Exemple #8
0
/* 
void updateBuddyList(){
    int i;
    for(i = 1; i <= buddy_count; i++){
        char *s = (char *)malloc(100*sizeof(char));
        memset(s, '\0', 100);
        s = strncpy(s, buddies[i].nick, strlen(buddies[i].nick));
        strcat(s, "@");
        strcat(s, buddies[i].ip);

        items[i] = new_item(s, "");
    }
    unpost_menu(buddy_menu);
    post_menu(buddy_menu);
        //s = strdup(buddies[i].nick);
    //set_menu_items(buddy_menu, items);
    wrefresh(buddy_win);
  char c;
    while((c = wgetch(buddy_win)) != KEY_F(1))
    {       switch(c)
        {   case KEY_DOWN:
            menu_driver(buddy_menu, REQ_DOWN_ITEM);
            break;
            case KEY_UP:
            menu_driver(buddy_menu, REQ_UP_ITEM);
            break;
        }
    }
}
*/
void initBuddyList(){
    //build list displayName
    int i;
    items = (ITEM **)calloc(252, sizeof(ITEM *));
    items[0] = new_item("Group","");
    for(i = 1; i <= buddy_count; i++){
        char *s = (char *)malloc(100*sizeof(char));
        memset(s, '\0', 100);
        s = strncpy(s, buddies[i].nick, strlen(buddies[i].nick));
        strcat(s, "@");
        strcat(s, buddies[i].ip);

        //s = strdup(buddies[i].nick);
        items[i] = new_item(s, "");
    }
    for(i = 0; i < buddy_count; i++){
        //printf(displayNames[i]);
        //        items[i] = new_item(displayNames[i], displayNames[i]);
//        char *name = (char *)malloc(strlen(displayNames[i]) + 1);
//        name = strncpy(name, displayNames[i], strlen(displayNames[i]));
//        char *xxx = "Bonsoir";
//        name[strlen(displayNames[i])] = '\0';
        //name = strncpy(name, displayNames[i], strlen(displayNames[i]));
//        char *yyy = (char *)malloc(strlen(xxx) + 1);
//        yyy = strdup(xxx);
     //   items[i] = new_item(yyy, "");

    }

//    keypad(buddy_win, TRUE);
    buddy_menu = new_menu((ITEM **)items);
    set_menu_win(buddy_menu, buddy_win);
    set_menu_sub(buddy_menu, derwin(buddy_win, 0, 0, 0, 0));
    //set_menu_sub(buddy_menu, buddy_win);
    post_menu(buddy_menu);
    wrefresh(buddy_win);
    refresh();
    /*  char c;
    while((c = wgetch(buddy_win)) != KEY_F(1))
    {       switch(c)
        {   case KEY_DOWN:
            menu_driver(buddy_menu, REQ_DOWN_ITEM);
            break;
            case KEY_UP:
            menu_driver(buddy_menu, REQ_UP_ITEM);
            break;
        }
        wrefresh(buddy_win);
    }*/   
}
Exemple #9
0
/* glue items to menu and post menu */
static void display_menu(smsgloader *_this)
{
    int rows,cols;
    VERBOSE_DEBUGPR("displaying scom menu requested\n");
    if(_this->loadmenu)
    {
        DEBUGPR("Error!!!!! loadmenu already dsiplayed??\n");
        return;
    }
    _this->loadmenu=new_menu(_this->loaditems);
    scale_menu(_this->loadmenu,&rows,&cols);
    wresize(_this->msgloaderwin,rows+5,cols+5);
    box(_this->msgloaderwin,0,0);
    wprintw(_this->msgloaderwin,"(%s)",SCOMMENU_TOGGLE_STR);
    set_menu_win(_this->loadmenu,_this->msgloaderwin);
    _this->derwin=derwin(_this->msgloaderwin,rows,cols,2,2);
    set_menu_sub(_this->loadmenu,_this->derwin);
    set_menu_mark(_this->loadmenu," * ");
    post_menu(_this->loadmenu);
}
WINDOW *Napravi_menu(int *n_choices, ITEM **items, MENU *menu) {
	int i, height, width;
	WINDOW *menu_window;
	
	*n_choices = ARRAY_SIZE(choices);
	items = (ITEM **) calloc(*n_choices, sizeof(ITEM *));
	for(i = 0; i < *n_choices; ++i)
        items[i] = new_item(choices[i], "");
	menu = new_menu((ITEM **) items);
	height = 3;
	width = 9+7+6;
	menu_window = newwin(height, width, 16, COLS/2-width/2);
	//Validiraj_ncurses(keypad(menu_window, TRUE));
	set_menu_win(menu, menu_window);
	set_menu_sub(menu, derwin(menu_window, height-1, width-1, 1, 1));
	set_menu_mark(menu, ">");
	set_menu_format(menu, 1, 7);
	menu_opts_off(menu, O_SHOWDESC);
	box(menu_window, 0, 0);
	post_menu(menu);
	Wrefresh(menu_window);
	return menu_window;
}
Exemple #11
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;
      }
    }
  }
}
Exemple #12
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;
      }
    }
  }
}
Exemple #13
0
void viewPlayer(FootBallTeam *team, const String &name, int pid) {
  const char *itemName;
  const ITEM *currentItem;
  String playerName, playerPosition;
  float height, weight;
  int number;

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

  for(;;) {
    FootBallPlayer *player = (FootBallPlayer*)team->getPlayer(name, pid);
    if (player) {
      player->getName(playerName);
      player->getPosition(playerPosition);
      height = player->getHeight(); 
      weight = player->getWeight();
      number = player->getNumber();
    } else {
      playerName = "";
      playerPosition = "";
      height = -1;
      weight = -1;
      number = -1;
    }

    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);
    
    // Setup the menu
    int nChoices = ARRAY_SIZE(choices)+1;
    ITEM **items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices; 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, 7, 17));
  
    // Make window and menu visible;
    post_menu(menu);
    mvwprintw(window, 0, 10, "Name: %s\n", playerName.c_str());
    mvwprintw(window, 1, 10, "Number: %d\n", number);
    mvwprintw(window, 2, 10, "Position: %s\n", playerPosition.c_str());
    mvwprintw(window, 3, 10, "Height: %.2fcm\n", height);
    mvwprintw(window, 4, 10, "Weight: %.2fkg\n", weight);
    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_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10:
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          refresh();
          if (strcmp(itemName, choices[1]) == 0)
            team->removePlayer(playerName, pid);
          // Delete allocated data
          unpost_menu(menu); 
          free_menu(menu); 
          for (int i = 0; i < nChoices; i++) 
            free_item(items[i]); 
          delete[] items;
          delwin(window);
          return;
      }
    }
  }
}
Exemple #14
0
void viewMainMenu() {

  const int window_nlines = 10,
            window_ncols  = 90;

  const char *choices[] = {
    "Team 1: ",
    "Team 2: ",
    "Exit",
  };

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

    // Get the teams (used in menu items).
    FootBallTeam *team[2];
    team[0] = game.getFootBallTeam(FootBallGame::TEAM_ONE);
    team[1] = game.getFootBallTeam(FootBallGame::TEAM_TWO);
    String teamName[2];
    
    // Create the menu items
    int nChoices = ARRAY_SIZE(choices) + 1;
    ITEM **items = new ITEM* [nChoices];
    for (int i = 0; i < 2; i++ ) {
      if (team[i] == NULL)
        items[i] = new_item(choices[i], "Empty");
      else {
        teamName[i] = team[i]->getTeamName();
        items[i] = new_item(choices[i], teamName[i].c_str());
      }
    }
    items[2] = new_item(choices[2], 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 (int i = 0; i < nChoices; i++) 
            free_item(items[i]);
          delete[] items; 
          if (strcmp(itemName, choices[2]) == 0) {
            return;
          // Edit/View Team 1
          } else if (strcmp(itemName, choices[0]) == 0)  {
            restart = true;
            viewTeam(FootBallGame::TEAM_ONE);
          // Edit/View Team 2
          } else if (strcmp(itemName, choices[1]) == 0)  {
            restart = true;
            viewTeam(FootBallGame::TEAM_TWO);
          }
      }
    }
  }
}
Exemple #15
0
void createMenus() {
  int i;

  /* create menu items */
  mainMenuItems = (ITEM**)calloc(5, sizeof(ITEM*));
  mainMenuItems[0] = new_item("Operating Mode", "");
  set_item_userptr(mainMenuItems[0], (void*)MENU_ITEM_OPMODE);
  mainMenuItems[1] = new_item("Spectra",        "");
  set_item_userptr(mainMenuItems[1], (void*)MENU_ITEM_SPECTRA);
  mainMenuItems[2] = new_item("Invariants",     "");
  set_item_userptr(mainMenuItems[2], (void*)MENU_ITEM_INVARIANTS);
  mainMenuItems[3] = new_item("Exit",           "");
  set_item_userptr(mainMenuItems[3], (void*)MENU_ITEM_EXIT);
  mainMenuItems[4] = new_item(NULL,             NULL);

  opmodeMenuItems = (ITEM**)calloc(3, sizeof(ITEM*));
  opmodeMenuItems[0] = new_item("Training",     "");
  set_item_userptr(opmodeMenuItems[0], (void*)MENU_ITEM_TRAINING);
  opmodeMenuItems[1] = new_item("Testing",      "");
  set_item_userptr(opmodeMenuItems[1], (void*)MENU_ITEM_TESTING);
  opmodeMenuItems[2] = new_item(NULL,           NULL);

  spectraMenuItems = (ITEM**)calloc(guiProgramData->nSpectra+1, sizeof(ITEM*));
  for(i=0; i<guiProgramData->nSpectra; i++) {
    char *spectrumInfo = (char*)malloc(64);
    sprintf(spectrumInfo, "%-20s | %5d", 
      getSpectrum(guiProgramData, i)->name, 
      getSpectrum(guiProgramData, i)->nComponents);
    spectraMenuItems[i] = new_item(spectrumInfo, "");
  }

  spectraOpMenuItems = (ITEM**)calloc(3, sizeof(ITEM*));
  spectraOpMenuItems[0] = new_item("Inspect data",         "");
  set_item_userptr(spectraOpMenuItems[0], (void*)MENU_ITEM_DATA);
  spectraOpMenuItems[1] = new_item("Perform SFL analysis", "");
  set_item_userptr(spectraOpMenuItems[1], (void*)MENU_ITEM_SFL);
  spectraOpMenuItems[2] = new_item(NULL,                   NULL);
  
  sflCoeffMenuItems = (ITEM**)calloc(3, sizeof(ITEM*));
  sflCoeffMenuItems[0] = new_item("Ochiai",         "");
  set_item_userptr(sflCoeffMenuItems[0], (void*)S_OCHIAI);
  sflCoeffMenuItems[1] = new_item("Jaccard",        "");
  set_item_userptr(sflCoeffMenuItems[1], (void*)S_JACCARD);
  sflCoeffMenuItems[2] = new_item("Tarantula",      "");
  set_item_userptr(sflCoeffMenuItems[1], (void*)S_TARANTULA);
  sflCoeffMenuItems[3] = new_item(NULL,             NULL);
  
  invariantTypesMenuItems = (ITEM**)calloc(guiProgramData->nInvariantTypes+1, sizeof(ITEM*));
  for(i=0; i<guiProgramData->nInvariantTypes; i++) {
    char *invariantTypeInfo = (char*)malloc(64);
    sprintf(invariantTypeInfo, "%-20s | %5d", 
      getInvariantType(guiProgramData, i)->name, 
      getInvariantType(guiProgramData, i)->nInvariants);
    invariantTypesMenuItems[i] = new_item(invariantTypeInfo, "");
  }

  /*create actual menus*/
  mainMenu = new_menu((ITEM**)mainMenuItems);
  set_menu_win(mainMenu, mainMenuWin);
  set_menu_sub(mainMenu, derwin(mainMenuWin, 10,16, 1,1));
  set_menu_format(mainMenu, 10,1);
  box(mainMenuWin, 0, 0);
  post_menu(mainMenu);

  opmodeMenu = new_menu((ITEM**)opmodeMenuItems);
  set_menu_win(opmodeMenu, opmodeMenuWin);
  set_menu_format(opmodeMenu, 10,1);
  post_menu(opmodeMenu);

  spectraMenu = new_menu((ITEM**)spectraMenuItems);
  set_menu_win(spectraMenu, spectraMenuWin);
  set_menu_format(spectraMenu, 10,1);
  post_menu(spectraMenu);

  spectraOpMenu = new_menu((ITEM**)spectraOpMenuItems);
  set_menu_win(spectraOpMenu, spectraOpMenuWin);
  set_menu_format(spectraOpMenu, 10,1);
  post_menu(spectraOpMenu);

  sflCoeffMenu = new_menu((ITEM**)sflCoeffMenuItems);
  set_menu_win(sflCoeffMenu, sflCoeffMenuWin);
  set_menu_format(sflCoeffMenu, 10,1);
  post_menu(sflCoeffMenu);

  invariantTypesMenu = new_menu((ITEM**)invariantTypesMenuItems);
  set_menu_win(invariantTypesMenu, invariantTypesMenuWin);
  set_menu_format(invariantTypesMenu, 10,1);
  post_menu(invariantTypesMenu);
}
/*
 * Create and initialize a new popup. popup_btn_action *must* be filled before
 * this call.
 * @param rows The number of rows for win_body
 * @param cols The number of lines for win_body
 * @param posy Position of the top left corner on the y axis
 * @param posx Position of the top left corner on the x axis
 * @param requests An array of strings to put in the form. This can be null:
 *	only the title and the buttons will be present.
 * @param title A string to print in the popup.
 */
void popup_new(int rows, int cols, int posy, int posx, char **requests,
		char *title)
{
	int i, cury = 0, curx = 1, tmp, nb_buttons, nb_fields;
	WINDOW *inner;

	win_body = newwin(rows, cols, posy, posx);
	assert(win_body != NULL && popup_btn_action != NULL);
	box(win_body, 0, 0);

	for (nb_buttons = 0; popup_btn_action[nb_buttons]; nb_buttons++);

	popup_items = malloc(sizeof(ITEM *) * (nb_buttons+1));
	assert(popup_items != NULL);
	assert(popup_btn_action != NULL);

	for (i = 0; popup_btn_action[i]; i++) {
		popup_items[i] = new_item(popup_btn_action[i]->key, "");
		assert(popup_items[i] != NULL);
	}

	popup_items[i] = NULL;
	popup_menu = new_menu(popup_items);
	win_menu = derwin(win_body, 3, cols-2, rows-4, 1);
	assert(popup_menu != NULL && win_menu != NULL);
	box(win_menu, 0, 0);
	set_menu_win(popup_menu, win_menu);
	set_menu_format(popup_menu, 1, nb_buttons);
	tmp = popup_menu->fcols * (popup_menu->namelen + popup_menu->spc_rows);
	tmp--;
	inner = derwin(win_menu, 1, tmp, 1, (cols-3-tmp)/2);
	assert(inner != NULL);
	set_menu_sub(popup_menu, inner);
	set_menu_mark(popup_menu, "");
	assert(post_menu(popup_menu) == E_OK);

	mvwprintw(win_body, 1, 2, "%s", title);

	for (nb_fields = 0; requests && requests[nb_fields]; nb_fields++);

	if (nb_fields == 0) {
		popup_fields = NULL;
		popup_form = NULL;
		is_on_button = true;
		return;
	}

	popup_fields = malloc(sizeof(FIELD *) * (nb_fields+1));
	assert(popup_fields != NULL);

	for (i = 0; i < nb_fields && requests[i]; i++) {

		if (i % 2 == 1) {
			popup_fields[i] = new_field(1, 41, cury, curx, 0, 0);
			assert(popup_fields[i] != NULL);
			set_field_buffer(popup_fields[i], 0, strdup(requests[i]));
			cury = cury+1;
			curx = 1;
			field_opts_on(popup_fields[i], O_ACTIVE);
			field_opts_on(popup_fields[i], O_EDIT);
			field_opts_off(popup_fields[i], O_STATIC);
			set_field_back(popup_fields[i], A_UNDERLINE); 
		} else {
			popup_fields[i] = new_field(1, 45, cury, curx, 0, 0);
			assert(popup_fields[i] != NULL);
			set_field_buffer(popup_fields[i], 0, strdup(requests[i]));
			curx = strlen(requests[i]) + 2;
			field_opts_off(popup_fields[i], O_ACTIVE);
			field_opts_off(popup_fields[i], O_EDIT);
		}
	}

	popup_fields[i] = NULL;
	popup_form = new_form(popup_fields);
	assert(popup_form != NULL);
	win_form = derwin(win_body, rows-6, cols-2, 1, 1);
	assert(popup_form != NULL && win_form != NULL);
	assert(set_form_win(popup_form, win_form) == E_OK);

	int diff_rows = popup_form->cols - win_form->_maxx-2;

	/*
	 * There isn't enough rows for the form so we resize win_body and
	 * win_form to fit the form.
	 * This resize isn't needed for the lines (as there is always fery few
	 * of them).
	 */
	if (diff_rows > 0) {
		wresize(win_body, win_body->_maxy, win_body->_maxx + diff_rows);
		wresize(win_form, win_form->_maxy, win_form->_maxx - 2 + diff_rows);
	}

	inner = derwin(win_form, win_form->_maxy-2, win_form->_maxx, 2, 0);
	assert(inner != NULL);
	set_form_sub(popup_form, inner);

	assert(post_form(popup_form) == E_OK);
	is_on_button = false;
	set_menu_fore(popup_menu, A_NORMAL); // "hide" the button
	pos_form_cursor(popup_form);
}
Exemple #17
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);
   
}
Exemple #18
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;
}
Exemple #19
0
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();
}
Exemple #20
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;
}
/*
 * Create a menu of technologies: a selectable list of technologies.
 * @param jobj format of the json object:
 [
	 [
		 "\/net\/connman\/technology\/wifi",
		 {
			 "Name":"WiFi",
			 "Type":"wifi",
			 "Powered":true,
			 "Connected":false,
			 "Tethering":false
		 }
	 ],
	 [
		 "\/net\/connman\/technology\/ethernet",
		 {
			 "Name":"Wired",
			 "Type":"ethernet",
			 "Powered":true,
			 "Connected":true,
			 "Tethering":false
		 }
	 ]
 ]
 */
static void renderers_technologies(struct json_object *jobj)
{
	int i;
	char *desc_base = "%-20s Powered %-5s          Connected %-5s";
	char desc_base_sub[30];
	const char *k_name, *k_type, *k_powered, *k_connected;
	char *desc, *tech_short_name;
	struct json_object *sub_array, *dbus_tech_name, *tech_dict;
	struct userptr_data *data;

	nb_items = json_object_array_length(jobj);
	main_items = malloc(sizeof(ITEM*) * (nb_items+1));
	assert(main_items != NULL && nb_items > 0);

	for (i = 0; i < nb_items; i++) {
		sub_array = json_object_array_get_idx(jobj, i);

		if (!sub_array)
			continue;

		dbus_tech_name = json_object_array_get_idx(sub_array, 0);
		tech_dict = json_object_array_get_idx(sub_array, 1);

		json_object_object_foreach(tech_dict, key, val) {

			if (strcmp(key_serv_name, key) == 0)
				k_name = json_object_get_string(val);

			else if (strcmp("Type", key) == 0)
				k_type = json_object_get_string(val);

			else if (strcmp("Powered", key) == 0)
				k_powered = json_object_to_json_string(val);

			else if (strcmp("Connected", key) == 0)
				k_connected = json_object_to_json_string(val);
		}

		snprintf(desc_base_sub, 30, "%s (%s)", k_name, k_type);
		desc_base_sub[29] = '\0';

		desc = malloc(RENDERERS_STRING_MAX_LEN);
		assert(desc != NULL);
		snprintf(desc, RENDERERS_STRING_MAX_LEN-1, desc_base,
				desc_base_sub, k_powered, k_connected);
		desc[RENDERERS_STRING_MAX_LEN-1] = '\0';
		tech_short_name =
			extract_dbus_short_name(json_object_get_string(dbus_tech_name));
		main_items[i] = new_item(tech_short_name, desc);

		data = malloc(sizeof(struct userptr_data));
		assert(data != NULL);
		data->dbus_name = strdup(json_object_get_string(dbus_tech_name));
		data->pretty_name = strdup(k_name);
		set_item_userptr(main_items[i], data);
	}

	main_items[nb_items] = NULL;
	main_menu = new_menu(main_items);
	set_menu_win(main_menu, win_body);
	set_menu_sub(main_menu, derwin(win_body, win_body_lines-2, COLS-4, 3, 2));
	set_menu_mark(main_menu, "");
	set_menu_format(main_menu, win_body_lines-3, 1);
	assert(post_menu(main_menu) == E_OK);

	refresh_home_msg();
	wrefresh(win_header);
	wrefresh(win_body);
	repos_cursor();
}
Exemple #22
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;
}
Exemple #23
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);
}
Exemple #24
0
void display_execution(int num_instruction, mot * tab_mot_instruction, int nb_instruction, int* registres,int nb_reg, int PC, int SP, int SR){
        ITEM *item_en_cour = NULL; 
    
        char ** tab_instruction;
        // for instructions
        ITEM **instructions_items;
	int c;		
        WINDOW *instructions_win;
	MENU *instruction_menu;
	int i;
	instructions_items = (ITEM **)calloc(nb_instruction + 1, sizeof(ITEM *));
        int menu_instruction_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte
        
        
        char ** files;  //in case of F2
        
        // for register
        char  ** tab_register;
        ITEM **register_items;
	WINDOW *register_win;
	MENU *register_menu;
	register_items = (ITEM **)calloc(nb_reg + 1 +3, sizeof(ITEM *)); //+3 pour PC SP et SR
        int menu_register_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte
        
        
        char dest_string[5];
        char source_string[5];
        char brut_string[10];
        char pc_string[6], sp_string[6], sr_string[6];
        
        
        
        int is_brut = 0; //si le mot précedent contient un mode direct, alors le mot suivant est un brut //si DIRIMM les 2 suivant sont des brut
        
        
        //allocation de mémoire pour les insctruction sous forme de chaine
        tab_instruction = (char**) malloc (nb_instruction* sizeof(char*));
        
        
        
        //allocation de mémoire pour le tabeau de registre sous forme de string
        tab_register = (char**) malloc (nb_reg* sizeof(char *));
        
        int num_choix;
        char * choix = NULL;

         
	for(i = 0; i < nb_instruction; ++i){
            
            tab_instruction[i] = malloc(50 * sizeof(char)); //plus simple pour le moment, une instruction ne peut dépasser 50caractères ... a améliorer si assez de temps
                
            
            if(is_brut == 0){
               
                
                
                sprintf(dest_string, "%d", tab_mot_instruction[i].codage.dest);
                sprintf(source_string, "%d", tab_mot_instruction[i].codage.source);
                
                //si l'instruction contient une source ou destination en mode immediat ou direct, la prochaine instruction sera un brut
                if(is_brut==2 || tab_mot_instruction[i].codage.mode == REGIMM || tab_mot_instruction[i].codage.mode == INDIMM || tab_mot_instruction[i].codage.mode == REGDIR || tab_mot_instruction[i].codage.mode ==  DIRREG){
                    is_brut = 1;
                }
                if(tab_mot_instruction[i].codage.mode == DIRIMM){
                    is_brut = 2;
                }
                
                strcpy(tab_instruction[i], codeop_tostring(tab_mot_instruction[i].codage.codeop) ); //on met tout les élément sous forme de string concaténé et espacé
                strcat(tab_instruction[i], "    "); 
                strcat(tab_instruction[i], mode_tostring(tab_mot_instruction[i].codage.mode));
                strcat(tab_instruction[i], "    "); 
                strcat(tab_instruction[i], dest_string);
                strcat(tab_instruction[i], "    "); 
                strcat(tab_instruction[i], source_string);
            }
            else{
               sprintf(brut_string, "%d", tab_mot_instruction[i].brut); 
               strcpy(tab_instruction[i], brut_string ); 
               if(is_brut == 2){
                   is_brut = 1; // cas du DIRIMM
               } else{
                   is_brut = 0;
               }
            }
                

                //mvprintw(i+2, 0, "%s", tab_instruction[i]);
                instructions_items[i] = new_item(tab_instruction[i], ""); //ajoute les éléments dans mon tableau d'item
                
                if(i == num_instruction){
                        //on sauvegarde l'adresse de l'item que l'on est entrain de traiter (celui donner par num_instruction)
                        item_en_cour = instructions_items[i];
                        //n le desactive, cela permet de lui doonner une autre apparence pur le repérer
                        item_opts_off(instructions_items[i], O_SELECTABLE);
                }
        }
                
        
        
        
        
        for(i = 0; i < nb_reg; ++i){
                //contient le registre sous forme de string par exemple R1 ou PC
                tab_register[i] = malloc(3 * sizeof(char));
                
                sprintf(tab_register[i], "R%i: %d",i, registres[i]);
                
                //mvprintw(i+2, 0, "%s", tab_instruction[i]);
                register_items[i] = new_item(tab_register[i], ""); //ajoute les éléments dans mon tableau d'item
        }
                sprintf(pc_string, "%d", PC);
                sprintf(sp_string, "%d", SP);
                sprintf(sr_string, "%d", SR);
                register_items[nb_reg] = new_item("PC:", pc_string); //register_items[8]
                register_items[nb_reg+1] = new_item("SP:", sp_string); //register_items[9]
                register_items[nb_reg+2] = new_item("SR:", sr_string);  //register_items[10]
                //pour cacher la selection du premier registre
                item_opts_off(register_items[0], O_SELECTABLE);
        
        
	instruction_menu = new_menu((ITEM **)instructions_items); //creer un menu contenant les instructions
        
        register_menu = new_menu((ITEM **)register_items); //creer un menu contenant les registres
	mvprintw(LINES - 2, 0, "F9 to close the menu"); 
        
        
        
        instructions_win = newwin((LINES-4)/2, 40 , 3, (COLS/2)- (COLS-4)/4); //créer une nouvelle fenetre pour les instructions
        register_win = newwin(16, 20 , 3, (COLS/2) + 10); //créer une nouvelle fenetre pour les registres
        
        keypad(instructions_win, TRUE); //active le clavier sur les instructions
       
        
        
        /* Set main window and sub window */
        set_menu_win(instruction_menu, instructions_win); //set main menu
        set_menu_sub(instruction_menu, derwin(instructions_win, ((LINES-4)/2)-4, 38, 3, 1)); // set sub window
        set_menu_format(instruction_menu, ((LINES-4)/2)-4, 1);
        
        set_menu_win(register_menu, register_win); //set main menu
        set_menu_sub(register_menu, derwin(register_win, 13, 18, 3, 1)); // set sub window
        set_menu_format(register_menu, 13, 1);
        
        
        
        
       /* Set menu mark to the string " * " */
        set_menu_mark(instruction_menu, " * ");
        set_menu_mark(register_menu, "");
        
        
        /* Print a border around the main window and print a title */
        box(instructions_win, 0, 0);
        print_in_middle(instructions_win, 1, 0, 40, "liste des instructions", COLOR_PAIR(1));
	mvwaddch(instructions_win, 2, 0, ACS_LTEE);
	mvwhline(instructions_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(instructions_win, 2, 39, ACS_RTEE);
        
        box(register_win, 0, 0);
        print_in_middle(register_win, 1, 0, 20, "Registres", COLOR_PAIR(1));
	mvwaddch(register_win, 2, 0, ACS_LTEE);
	mvwhline(register_win, 2, 1, ACS_HLINE, 22);
	mvwaddch(register_win, 2, 19, ACS_RTEE);
	refresh();
        
	post_menu(instruction_menu);
        post_menu(register_menu);
        
        //on se place sur l'instruction en cour
        set_current_item (instruction_menu, item_en_cour);
        
	wrefresh(instructions_win);
        wrefresh(register_win);
       

	while((c = getch()) != KEY_F(9) && c != 32)
	{   switch(c)
	    {	case KEY_F(5):
                mvprintw(LINES-2, 0, "Exiting...");
                endwin();			/* End curses mode		  */
                exit(0);
            
                case KEY_F(2):
                        files = list_file("", &i);
                        draw_menu(files, execute_file_menu, "", i);
                        
                case KEY_DOWN:
		        menu_driver(instruction_menu, REQ_DOWN_ITEM);
			break;
		case KEY_UP:
			menu_driver(instruction_menu, REQ_UP_ITEM);
			break;
                
            
                //case KEY_NPAGE:
		//	menu_driver(my_menu, REQ_SCR_DPAGE);
		//	break;
                //case KEY_PPAGE:
		//	menu_driver(my_menu, REQ_SCR_UPAGE);
		//	break;
        
            
                case 10:
                        move(20, 0);
			clrtoeol();
                       
			break;
                 

		}
                wrefresh(instructions_win);
	}
        if(menu_instruction_alrdy_dlt == 0){
                clean_menu(instruction_menu);
                clean_window(instructions_win);
        }
                if(menu_register_alrdy_dlt == 0){
                clean_menu(register_menu);
                clean_window(register_win);
        }
    
    
}
Exemple #25
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);
	}	

}
Exemple #26
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();
}
Exemple #27
0
void draw_menu(char ** menu_liste, void (*ptrfonction)(int,const char *, char *), char * folder, int taille_menu){
        ITEM **my_items;
	int c;		
        WINDOW *my_menu_win;
	MENU *my_menu;
	int i;
	ITEM *cur_item;
        my_items = (ITEM **)calloc(taille_menu + 1, sizeof(ITEM *));
        int menu_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte
        char ** files; //pour le cas ou on utilise F2 (ouvrir un fichier)
        
        int num_choix;
        char choix[FILE_MAX];

	for(i = 0; i < taille_menu; ++i){
	        my_items[i] = new_item(menu_liste[i], ""); //ajoute les éléments dans mon tableau d'item
        }
	//my_items[taille_menu+1] = (ITEM *)NULL; //ajoute un item vide à la fin du tableau
        my_menu = new_menu((ITEM **)my_items); //creer un menu contenan les items
	mvprintw(LINES - 2, 0, "F9 to close the menu"); //affiche un pied de page pour fermer le menu
        
        my_menu_win = newwin(10, 45, (LINES-10)/2, (COLS-45)/2); //créer une nouvelle fenetre
        keypad(my_menu_win, TRUE); //active le clavier pour le menu
       
        
        
        
        /* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win); //set main menu
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); // set sub window
        set_menu_format(my_menu, 5, 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, "Menu Principal", 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);
	refresh();
        
	post_menu(my_menu);
	wrefresh(my_menu_win);
       

	while((c = getch()) != KEY_F(9) && c != 27)
	{   switch(c)
	    {	case KEY_F(5):
                        mvprintw(LINES-2, 0, "Exiting...");
                        endwin();			/* End curses mode		  */
                        exit(0);
            
                case KEY_F(2):
                        files = list_file("", &i);
                        clean_menu(my_menu);
                        clean_window(my_menu_win);
                        draw_menu(files, execute_file_menu, "", i);
                        return;
                    
                case KEY_DOWN:
		        menu_driver(my_menu, REQ_DOWN_ITEM);
			break;
		case KEY_UP:
			menu_driver(my_menu, REQ_UP_ITEM);
			break;
                
            
                case KEY_NPAGE:
			menu_driver(my_menu, REQ_SCR_DPAGE);
			break;
                case KEY_PPAGE:
			menu_driver(my_menu, REQ_SCR_UPAGE);
			break;
        
            
                case 10:
                        move(20, 0);
			clrtoeol();
                        num_choix = item_index(current_item(my_menu));
                        strcpy(choix, item_name(current_item(my_menu)));
			//mvprintw(5, 0, "Item selected is : %s", item_name(current_item(my_menu)));
                        clean_menu(my_menu);
                        menu_alrdy_dlt = 1;
                        clean_window(my_menu_win);
                        (*ptrfonction)(num_choix, choix, folder);
			pos_menu_cursor(my_menu);
			break;
                 

		}
                wrefresh(my_menu_win);
	}
        if(menu_alrdy_dlt == 0)
                clean_menu(my_menu);
        clean_window(my_menu_win);
        
       
        
    
}
Exemple #28
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;
          }
      }
    }
  }
}
Exemple #29
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();                                                                        
}                                                
Exemple #30
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;
            }
          }
      }
    }
  }
}