예제 #1
0
파일: term.c 프로젝트: lchsk/xstarter
static void
set_app_to_run(void)
{
    ITEM *item = current_item(menu_list);

    if (item) {
        open_app_later(g_list_nth_data(results, item_index(item)));
    }
}
예제 #2
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	
	
	initscr();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

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

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

	while((c = getch()) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10:	/* Enter */
				cur_item = current_item(my_menu);
				move(LINES - 2, 0);
				clrtoeol();
				mvprintw(LINES - 2, 0, "You have chosen %d item with name %s and description %s", 
				item_index(cur_item) + 1,  item_name(cur_item), 
				item_description(cur_item));
				
				refresh();
				pos_menu_cursor(my_menu);
				break;
		}
	}	

	free_item(my_items[0]);
        free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}
예제 #3
0
파일: search.c 프로젝트: yourealwaysbe/rolo
static ITEM *
search_menu_backwards (MENU * menu)
{
  char *search_string = NULL;
  ITEM *result_item = NULL;

  /* the search string is stored in the menu user pointer */
  search_string = (char *) menu_userptr (menu);

  if (NULL != search_string)
    {
      int i = -1;
      int current_index = -1;
      ITEM **items = NULL;
      int found = 0;
      bool done = FALSE;

      current_index = item_index (current_item (menu));
      items = menu_items (menu);

      /* start search from the item immediately before the current item */
      for (i = current_index - 1; i >= 0 && !found; i--)
        {
          found = strstr_nocase (item_description (items[i]), search_string);
        }

      if (!found)
        {
          int count = -1;
          count = item_count (menu);
          /* start search from the end (i.e. wrap around) */
          for (i = count - 1; i >= current_index && !found; i--)
            {
              found =
                  strstr_nocase (item_description (items[i]), search_string);
            }
        }

      if (found)
        {
          result_item = items[i + 1];
        }
    }

  return result_item;
}
예제 #4
0
void
column_select_move_item(ui_t *ui, ITEM *item, int pos)
{
    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Check we have a valid position
    if (pos == item_count(info->menu) || pos < 0)
        return;

    // Swap position with destination
    int item_pos = item_index(item);
    info->items[item_pos] = info->items[pos];
    info->items[item_pos]->index = item_pos;
    info->items[pos] = item;
    info->items[pos]->index = pos;
}
예제 #5
0
파일: m1.c 프로젝트: pwarnimo/misc_projects
int main(int argc, char *argv[]) {
	int ch;

	initscr();
	atexit(quit);
	clear();
	noecho();
	curs_set(0);
	nl();
	keypad(stdscr, TRUE);

	it = (ITEM **)calloc(5, sizeof(ITEM *));
	it[0] = new_item("M1", "");
	it[1] = new_item("M2", "");
	it[2] = new_item("M3", "");
	it[3] = new_item("Ende", "");
	it[4] = 0;

	me = new_menu(it);
	post_menu(me);

	mvaddstr(7, 3, "Programm mittels Menü oder F2-Funktionstaste beenden");
	refresh();

	while ((ch = getch()) != KEY_F(2)) {
		switch (ch) {
			case KEY_DOWN:
				menu_driver(me, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(me, REQ_UP_ITEM);
				break;
			case 0xA:
				if (item_index(current_item(me)) == 3) {
					exit(0);
				}
				break;
		}
	}

	return 0;
}
예제 #6
0
/*
 * Set the menu's current item to the one given.
 */
int
set_current_item(MENU *param_menu, ITEM *item)
{
	MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
	int i = 0;

	  /* check if we have been called from an init type function */
	if (menu->in_init == 1)
		return E_BAD_STATE;

	  /* check we have items in the menu */
	if (menu->items == NULL)
		return E_NOT_CONNECTED;

	if ((i = item_index(item)) < 0)
		  /* item must not be a part of this menu */
		return E_BAD_ARGUMENT;
	
	menu->cur_item = i;
	return E_OK;
}
예제 #7
0
파일: term.c 프로젝트: lchsk/xstarter
static void
update_info_bar(void)
{
    if (! results_not_found) {
        GList *l = g_list_nth(
            results,
            item_index(current_item(menu_list))
        );

        char *path = l->data;

        clean_info_bar();

        char status[100];

        snprintf(status, 100, "Results: %d", choices_cnt);

        mvwprintw(window, MAX_Y - 1, 0, status);
        mvwprintw(window, MAX_Y, 0, path);
    } else {
        clean_info_bar();
    }
}
예제 #8
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;
}
예제 #9
0
int
sel_preset (uint32_t * num_ret, SwitchPos ** sp_ret, AppData * a)
{
  SwitchPos *np;
  uint32_t nn;
  MENU *my_menu;
  SwitchPos *sp = *sp_ret;
  uint32_t i, maxx;
  int state = 0;
  ITEM **my_items;
//      WINDOW * menu_win,*menu_sub;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  uint32_t num = *num_ret;

  message (a,
           "Select a preset using cursor keys and Enter, or cancel using Esc or Backspace.\n");

  while (state >= 0)
  {
    num_strings = SP_NUM_PRESETS;
    state = 0;
    debugMsg ("allocating items\n");
    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));
    for (i = 0; i < num_strings; ++i)
    {
      my_items[i] = new_item (spGetPresetStrings (i), spGetPresetStrings (i));
      if (NULL == my_items[i])
      {
        if (errno == E_BAD_ARGUMENT)
          errMsg ("badarg i=%" PRIu32 " \n", i);
        if (errno == E_SYSTEM_ERROR)
          errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
      }
    }
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu, O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Presets") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Presets");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    utlFAN (my_items);
    if (state > 0)
    {
      switch (state)
      {
      case 5:                  //selected
        np = spGetPreset (idx, &nn);
        if (NULL != np)
        {
          for (i = 0; i < num; i++)
          {
            spClear (sp + i);
          }
          *sp_ret = np;
          *num_ret = nn;
          return 0;
        }
        break;
      default:
        break;
      }
    }
  }
  //cancelled
  return 0;
}
예제 #10
0
static void cui_boot_editor_on_exit(struct cui *cui,
		struct pmenu_item *item,
		struct pb_boot_data *bd)
{
	struct pmenu *menu = cui->main;
	struct cui_opt_data *cod;
	int idx, top, rows, cols;
	static int user_idx = 0;

	/* Was the edit cancelled? */
	if (!bd) {
		cui_set_current(cui, &cui->main->scr);
		talloc_free(cui->boot_editor);
		cui->boot_editor = NULL;
		return;
	}

	/* Is this was a new item, we'll need to update the menu */
	if (!item) {
		int insert_pt;

		cod = talloc_zero(NULL, struct cui_opt_data);
		cod->name = talloc_asprintf(cod, _("User item %u"), ++user_idx);

		item = pmenu_item_create(menu, cod->name);
		if (!item) {
			talloc_free(cod);
			goto out;
		}

		item->on_edit = cui_item_edit;
		item->on_execute = cui_boot;
		item->data = cod;

		talloc_steal(item, cod);

		/* Detach the items array. */
		set_menu_items(menu->ncm, NULL);

		/* Insert new item at insert_pt. */
		insert_pt = pmenu_grow(menu, 1);
		pmenu_item_insert(menu, item, insert_pt);

		/* Re-attach the items array. */
		set_menu_items(menu->ncm, menu->items);

		/* If our index is above the current top row, align
		 * us to the new top. Otherwise, align us to the new
		 * bottom */
		menu_format(cui->main->ncm, &rows, &cols);
		top = top_row(cui->main->ncm);
		idx = item_index(item->nci);

		if (top >= idx)
			top = idx;
		else
			top = idx < rows ? 0 : idx - rows + 1;

		set_top_row(cui->main->ncm, top);
		set_current_item(item->pmenu->ncm, item->nci);

		nc_scr_post(&menu->scr);
	} else {
예제 #11
0
파일: gui.c 프로젝트: gmy987/zoltar
/* main gui loop function, can be called repeatedly, until returning 0 */
int loopGui() {
  int c;

  updateGui(guiProgramData, guiContext);

  c = getch();
  
  if(c=='q') {
    return 0;
  }

  switch(guiState) {
    case GUI_STATE_MAIN:
      switch(c) {
        case KEY_DOWN:
          menu_driver(mainMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(mainMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          {
            switch((int)item_userptr(current_item(mainMenu))) {
              case MENU_ITEM_EXIT:
                return 0;
              case MENU_ITEM_OPMODE:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_OPMODE;
                break;
              case MENU_ITEM_SPECTRA:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_SPECTRA;
                break;
              case MENU_ITEM_INVARIANTS:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_INVARIANTTYPES;
                break;
              default:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_TMP;
                break;
            }
          }
          break;
        default:
          break;
      }
      break;
    case GUI_STATE_OPMODE:
      switch(c) {
        case KEY_DOWN:
          menu_driver(opmodeMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(opmodeMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          {
            switch((int)item_userptr(current_item(opmodeMenu))) {
              case MENU_ITEM_TRAINING:
                guiProgramData->opMode = 0; /* TODO: define this */
                guiDataChanged = 1;
                break;
              case MENU_ITEM_TESTING:
                guiProgramData->opMode = 1; /* TODO: define this */
                guiDataChanged = 1;
                break;
              default:
                break;
            }
            set_menu_fore(mainMenu, A_STANDOUT);
            guiState = GUI_STATE_MAIN;
          }
          break;
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
    case GUI_STATE_SPECTRA:
      switch(c) {
        case KEY_DOWN:
          menu_driver(spectraMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(spectraMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          guiSelectedSpectrum = item_index(current_item(spectraMenu));
          if(guiSelectedSpectrum >= 0) {
            guiState = GUI_STATE_SPECTRA_OP;
          }
          break;
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
    case GUI_STATE_SPECTRA_OP:
      switch(c) {
        case KEY_DOWN:
          menu_driver(spectraOpMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(spectraOpMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          switch((int)item_userptr(current_item(spectraOpMenu))) {
            case MENU_ITEM_DATA:
              guiSelectedSFLResultOffset = 0;
              guiState = GUI_STATE_SPECTRUM_DATA;
              break;
            case MENU_ITEM_SFL:
              guiState = GUI_STATE_SFL_COEFF;
              break;
            default:
              guiState = GUI_STATE_SPECTRA;
              break;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SPECTRA;
          break;
      }
      break;
    case GUI_STATE_SFL_COEFF:
      switch(c) {
        case KEY_DOWN:
          menu_driver(sflCoeffMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(sflCoeffMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          switch((int)item_userptr(current_item(sflCoeffMenu))) {
            case S_OCHIAI:
            case S_JACCARD:
            case S_TARANTULA:
              guiSelectedSFLCoeff = (int)item_userptr(current_item(sflCoeffMenu));
              guiSFL = performSFL(guiProgramData, guiSelectedSpectrum, guiSelectedSFLCoeff);
              guiSelectedSFLResultOffset = 0;
              guiState = GUI_STATE_SFL_RESULT;
              break;
            default:
              guiState = GUI_STATE_SPECTRA_OP;
              break;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SPECTRA_OP;
          break;
      }
      break;
    case GUI_STATE_SFL_RESULT:
      switch(c) {
        case KEY_DOWN:
          if(guiSelectedSFLResultOffset < (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset += 1;
          }
          break;
        case KEY_UP:
          if(guiSelectedSFLResultOffset > 0) {
            guiSelectedSFLResultOffset -= 1;
          }
          break;
        case KEY_NPAGE:
          guiSelectedSFLResultOffset += SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset > (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset = (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS;
          }
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_PPAGE:
          guiSelectedSFLResultOffset -= SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SFL_COEFF;
          break;
      }
      break;
    case GUI_STATE_SPECTRUM_DATA:
      switch(c) {
        case KEY_DOWN:
          if(guiSelectedSFLResultOffset < (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset += 1;
          }
          break;
        case KEY_UP:
          if(guiSelectedSFLResultOffset > 0) {
            guiSelectedSFLResultOffset -= 1;
          }
          break;
        case KEY_NPAGE:
          guiSelectedSFLResultOffset += SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset > (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset = (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS;
          }
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_PPAGE:
          guiSelectedSFLResultOffset -= SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SPECTRA_OP;
          break;
      }
      break;
    case GUI_STATE_INVARIANTTYPES:
      switch(c) {
        case KEY_DOWN:
          menu_driver(invariantTypesMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(invariantTypesMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          guiSelectedInvariantType = item_index(current_item(invariantTypesMenu));
          if(guiSelectedInvariantType >= 0) {
            refreshInvariantsList();
            guiState = GUI_STATE_INVARIANTS;
            guiSelectedInvariantMode = INV_MODE_RANGE;
          }
          break;
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
    case GUI_STATE_INVARIANTS:
      switch(c) {
        case KEY_DOWN:
          menu_driver(invariantsMenuScr, REQ_DOWN_ITEM);
          menu_driver(invariantsMenuRng, REQ_DOWN_ITEM);
          menu_driver(invariantsMenuBmsk, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(invariantsMenuScr, REQ_UP_ITEM);
          menu_driver(invariantsMenuRng, REQ_UP_ITEM);
          menu_driver(invariantsMenuBmsk, REQ_UP_ITEM);
          break;
        case KEY_RIGHT:
          guiSelectedInvariantMode = (guiSelectedInvariantMode + 1 + 3)%3;
          break;
        case KEY_LEFT:
          guiSelectedInvariantMode = (guiSelectedInvariantMode - 1 + 3)%3;
          break;
        case KEY_NPAGE:
          {
            int i;
            for(i=0; i<10; i++) {
              menu_driver(invariantsMenuScr, REQ_DOWN_ITEM);
              menu_driver(invariantsMenuRng, REQ_DOWN_ITEM);
              menu_driver(invariantsMenuBmsk, REQ_DOWN_ITEM);
            }
          }
          break;
        case KEY_PPAGE:
          {
            int i;
            for(i=0; i<10; i++) {
              menu_driver(invariantsMenuScr, REQ_UP_ITEM);
              menu_driver(invariantsMenuRng, REQ_UP_ITEM);
              menu_driver(invariantsMenuBmsk, REQ_UP_ITEM);
            }
          }
          break;
        case 10: /* enter */
          guiSelectedInvariant = item_index(current_item(invariantsMenuScr));
          if(guiSelectedInvariant >= 0) {
            guiInv = getInvariantType(guiProgramData, guiSelectedInvariantType)->data[guiSelectedInvariant];
            guiState = GUI_STATE_INVARIANT_EDIT;
            guiEditState = GUI_EDIT_STATE_NONE;
            guiSelectedEditState = 0;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_INVARIANTTYPES;
          break;
      }
      break;
    case GUI_STATE_INVARIANT_EDIT:
      if(guiEditState == GUI_EDIT_STATE_NONE) {
        switch(c) {
          case KEY_UP:
            guiSelectedEditState = (guiSelectedEditState - 1 + 4)%4;
            break;
          case KEY_DOWN:
            guiSelectedEditState = (guiSelectedEditState + 1 + 4)%4;
            break;
          case 10: /* enter */
            guiEditState = guiSelectedEditState+1;
            guiSelectedInvariant = item_index(current_item(invariantsMenuScr));
            break;
          case KEY_BACKSPACE:
            refreshInvariantsList();
            guiState = GUI_STATE_INVARIANTS;
            break;
        }
      }
      if(guiEditState != GUI_EDIT_STATE_NONE) {
        if(guiEditState == GUI_EDIT_STATE_MIN) {
          switch(guiInv.datatype) {
            case DATA_TYPE_INT:
              editValue(textMin, &guiInv.range.i.min, DATA_TYPE_INT);
              break;
            case DATA_TYPE_UINT:
            case DATA_TYPE_UNSET:
              editValue(textMin, &guiInv.range.u.min, DATA_TYPE_UINT);
              break;
            case DATA_TYPE_DOUBLE:
              editValue(textMin, &guiInv.range.d.min, DATA_TYPE_DOUBLE);
              break;
            case DATA_TYPE_PTR:
              editValue(textMin, &guiInv.range.p.min, DATA_TYPE_PTR);
              break;
          }
        } else if(guiEditState == GUI_EDIT_STATE_MAX) {
          switch(guiInv.datatype) {
            case DATA_TYPE_INT:
              editValue(textMax, &guiInv.range.i.max, DATA_TYPE_INT);
              break;
            case DATA_TYPE_UINT:
            case DATA_TYPE_UNSET:
              editValue(textMax, &guiInv.range.u.max, DATA_TYPE_UINT);
              break;
            case DATA_TYPE_DOUBLE:
              editValue(textMax, &guiInv.range.d.max, DATA_TYPE_DOUBLE);
              break;
            case DATA_TYPE_PTR:
              editValue(textMax, &guiInv.range.p.max, DATA_TYPE_PTR);
              break;
          }
        } else if(guiEditState == GUI_EDIT_STATE_FIRST) {
          editValue(textFirst, &guiInv.bitmask.first, DATA_TYPE_PTR);
        } else if(guiEditState == GUI_EDIT_STATE_MASK) {
          editValue(textMask, &guiInv.bitmask.mask, DATA_TYPE_PTR);
        }
        guiEditState = GUI_EDIT_STATE_NONE;
        getInvariantType(guiProgramData, guiSelectedInvariantType)->data[guiSelectedInvariant] = guiInv;
        guiDataChanged = 1;
      }
      break;
    case GUI_STATE_TMP:
    default:
      switch(c) {
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
  }
  return 1;
}
예제 #12
0
int
column_select_handle_key_menu(ui_t *ui, int key)
{
    MENU *menu;
    ITEM *current;
    int current_idx;
    int action = -1;

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    menu = info->menu;
    current = current_item(menu);
    current_idx = item_index(current);

    // Check actions for this key
    while ((action = key_find_action(key, action)) != ERR) {
        // Check if we handle this action
        switch (action) {
            case ACTION_DOWN:
                menu_driver(menu, REQ_DOWN_ITEM);
                break;
            case ACTION_UP:
                menu_driver(menu, REQ_UP_ITEM);
                break;
            case ACTION_NPAGE:
                menu_driver(menu, REQ_SCR_DPAGE);
                break;
            case ACTION_PPAGE:
                menu_driver(menu, REQ_SCR_UPAGE);
                break;
            case ACTION_SELECT:
                column_select_toggle_item(ui, current);
                column_select_update_menu(ui);
                break;
            case ACTION_COLUMN_MOVE_DOWN:
                column_select_move_item(ui, current, current_idx + 1);
                column_select_update_menu(ui);
                break;
            case ACTION_COLUMN_MOVE_UP:
                column_select_move_item(ui, current, current_idx - 1);
                column_select_update_menu(ui);
                break;
            case ACTION_NEXT_FIELD:
                info->form_active = 1;
                set_menu_fore(menu, COLOR_PAIR(CP_DEFAULT));
                set_field_back(info->fields[FLD_COLUMNS_ACCEPT], A_REVERSE);
                form_driver(info->form, REQ_VALIDATION);
                break;
            case ACTION_CONFIRM:
                column_select_update_columns(ui);
                ui_destroy(ui);
                return KEY_HANDLED;
            default:
                // Parse next action
                continue;
        }

        // This panel has handled the key successfully
        break;
    }

    // Draw a scrollbar to the right
    info->scroll.pos = top_row(menu);
    ui_scrollbar_draw(info->scroll);
    wnoutrefresh(info->menu_win);

    // Return if this panel has handled or not the key
    return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
예제 #13
0
int
edit_pol (SwitchPol * spol, AppData * a)
{
  uint32_t i, maxx;
  int state = 0;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  MENU *my_menu;
  SwitchPol tmp;
  SwitchCmd *scmd;
  ITEM **my_items;
  char **mnu_str[2];
//      WINDOW * menu_win,*menu_sub;
  uint32_t num;

  spPolDeepCopy (&tmp, spol);
  num = tmp.num_cmds;
  scmd = tmp.cmds;

  message (a,
           "Modify Polarisation parameters or edit Commands.\nPress a to add a command, d to delete, press c to cancel");
  while (state >= 0)
  {
    num_strings = num + 1;
    state = 0;
    debugMsg ("allocating items\n");

    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));

    mnu_str[0] = utlCalloc (num_strings, sizeof (char *));
    mnu_str[1] = utlCalloc (num_strings, sizeof (char *));

    debugMsg ("allocating items\n");
    mnu_str[0][0] = "Pol";
    mnu_str[1][0] = (char *) tpiGetPolStr (tmp.pol);
    my_items[0] = new_item (mnu_str[0][0], mnu_str[1][0]);

    for (i = 1; i < num_strings; ++i)
    {
      mnu_str[0][i] = utlCalloc (32, sizeof (char));
      mnu_str[1][i] = (char *) spGetCmdStr (scmd[i - 1].what);
      snprintf (mnu_str[0][i], 32, "Cmd%" PRIu32, i - 1);
      my_items[i] = new_item (mnu_str[0][i], mnu_str[1][i]);
      if (NULL == my_items[i])
      {
        if (errno == E_BAD_ARGUMENT)
          errMsg ("badarg i=%" PRIu32 "\n", i);
        if (errno == E_SYSTEM_ERROR)
          errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
      }
    }
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu,
                   O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR | O_SHOWDESC);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Pol") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Pol");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 'd':
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 1;
        break;
      case 'a':
        state = 2;
        break;
      case 'c':
        state = 3;
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    for (i = 1; i < num_strings; ++i)
      utlFAN (mnu_str[0][i]);
    utlFAN (mnu_str[0]);
    utlFAN (mnu_str[1]);
    utlFAN (my_items);
    if (state > 0)
    {
      switch (state)
      {
      case 1:                  //del
        if (idx >= 1)
          spCmdDel (&scmd, &num, idx - 1);
        break;
      case 2:                  //add(at the end)
        spCmdAdd (&scmd, &num, num);
        break;
      case 3:                  //cancel
        spPolClear (&tmp);      //clear temporary
        return 1;
      case 5:                  //edit
        if (idx >= 1)
          edit_cmd (scmd + idx - 1, a);
        else
        {
          int rv;
          rv = get_pol (a);
          if (rv >= 0)
            tmp.pol = rv;
        }
        break;
      default:
        break;
      }
    }
  }
  spPolClear (spol);            //clear original
  *spol = tmp;                  //replace with temporary
  return 0;
}
예제 #14
0
int
get_pol (AppData * a)
{
  uint32_t i, maxx;
  int state = 0;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  MENU *my_menu;
  ITEM *my_items[5];
//      WINDOW * menu_win,*menu_sub;

  message (a, "Select a Polarisation.\n");
  while (state >= 0)
  {
    num_strings = 4;
    state = 0;
    debugMsg ("allocating items\n");
    my_items[0] = new_item ("H", "H");
    my_items[1] = new_item ("V", "V");
    my_items[2] = new_item ("L", "L");
    my_items[3] = new_item ("R", "R");
    my_items[4] = NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu, O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Pol") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Pol");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        idx = -1;
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = -1;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
  }
  return idx;
}
예제 #15
0
int
edit_cmd (SwitchCmd * scmd, AppData * a)
{
  uint32_t i, maxx;
  int state = 0;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  MENU *my_menu;
  SwitchCmd tmp;
  ITEM *my_items[11];
  char *mnu_str[2][10];
//      WINDOW * menu_win,*menu_sub;

  tmp = *scmd;

  message (a, "Modify Command\n");

  while (state >= 0)
  {
    num_strings = 10;           //what,len,data[8]
    state = 0;
    debugMsg ("allocating items\n");

    mnu_str[0][0] = "Cmd";
    mnu_str[1][0] = (char *) spGetCmdStr (tmp.what);
    my_items[0] = new_item (mnu_str[0][0], mnu_str[1][0]);

    mnu_str[0][1] = "Len";
    mnu_str[1][1] = utlCalloc (32, sizeof (char));
    snprintf (mnu_str[1][1], 32, "%u", tmp.len);
    my_items[1] = new_item (mnu_str[0][1], mnu_str[1][1]);

    for (i = 2; i < num_strings; i++)
    {
      mnu_str[0][i] = utlCalloc (32, sizeof (char));
      snprintf (mnu_str[0][i], 32, "data[%" PRIu32 "]", i - 2);
      mnu_str[1][i] = utlCalloc (32, sizeof (char));
      snprintf (mnu_str[1][i], 32, "%u", tmp.data[i - 2]);
      my_items[i] = new_item (mnu_str[0][i], mnu_str[1][i]);
    }

    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu,
                   O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR | O_SHOWDESC);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Cmd") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Cmd");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 'c':
        state = 3;
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    utlFAN (mnu_str[1][1]);
    for (i = 2; i < num_strings; ++i)
    {
      utlFAN (mnu_str[0][i]);
      utlFAN (mnu_str[1][i]);
    }
    if (state > 0)
    {
      int rv;
      switch (state)
      {
      case 3:                  //cancel
        return 1;
      case 5:                  //edit
        switch (idx)
        {
        case 0:
          rv = get_cmd_id (a);
          if (rv >= 0)
            tmp.what = rv;
          break;
        case 1:
          tmp.len = get_num (a);        //1,29,a);
          break;
        default:
          tmp.data[idx - 2] = get_num (a);      //idx,29,a);
          break;
        }
        break;
      default:
        break;
      }
    }
  }
  *scmd = tmp;                  //replace with temporary
  return 0;
}
예제 #16
0
static VALUE rbncurs_c_item_index(VALUE rb_item)
{
  ITEM *item = get_item(rb_item);
  return INT2NUM(item_index(item));
}
예제 #17
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);
	}	

}
예제 #18
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);
        
       
        
    
}
예제 #19
0
struct result
selection_show(struct selection *selection, WINDOW *parent)
{
    if (!selection) return result_set_system_error(EINVAL);
    
    selection->menu = new_menu(selection->items);
    if (!selection->menu) return result_ncurses_errno();
    
    int menu_height;
    int menu_width;
    int code = scale_menu(selection->menu, &menu_height, &menu_width);
    if (E_OK != code) return result_ncurses_error(code);
    
    int title_width = (int)strlen(selection->title) + 1;
    if (title_width > menu_width) menu_width = title_width;
    
    int main_window_height;
    int main_window_width;
    getmaxyx(parent, main_window_height, main_window_width);
    
    int menu_window_height = menu_height + 4;
    int menu_window_width = menu_width + 5;
    int menu_window_y = (main_window_height - menu_window_height) / 2;
    int menu_window_x = (main_window_width - menu_window_width) / 2;
    
    selection->window = newwin(menu_window_height, menu_window_width,
                               menu_window_y, menu_window_x);
    if (!selection->window) return result_ncurses_err();
    
    code = keypad(selection->window, TRUE);
    if (ERR == code) return result_ncurses_err();
        
    struct result result = draw_window(selection);
    if (!result_is_success(result)) return result;
    
    code = set_menu_win(selection->menu, selection->window);
    if (E_OK != code) return result_ncurses_error(code);
    
    int menu_sub_height = menu_height;
    int menu_sub_width = menu_width;
    int menu_sub_y = 2;
    int menu_sub_x = 2;
    
    selection->sub_window = derwin(selection->window,
                                   menu_sub_height, menu_sub_width,
                                   menu_sub_y, menu_sub_x);
    if (!selection->sub_window) return result_ncurses_err();
    
    code = set_menu_sub(selection->menu, selection->sub_window);
    if (E_OK != code) return result_ncurses_error(code);
    
    selection->index = 0;
    code = post_menu(selection->menu);
    if (E_OK != code) return result_ncurses_error(code);
    
    code = wrefresh(selection->window);
    if (ERR == code) return result_ncurses_err();
        
    result = get_selection(selection);
    if (!result_is_success(result)) return result;
    
    ITEM *selected_item = current_item(selection->menu);
    if (selected_item) selection->index = item_index(selected_item);
    
    code = unpost_menu(selection->menu);
    if (E_OK != code) return result_ncurses_error(code);
    
    code = wclear(selection->window);
    if (ERR == code) return result_ncurses_err();
        
    code = wrefresh(selection->window);
    if (ERR == code) return result_ncurses_err();
    
    code = free_menu(selection->menu);
    if (E_OK != code) return result_ncurses_error(code);
    selection->menu = NULL;
    
    code = delwin(selection->sub_window);
    if (E_OK != code) return result_ncurses_error(code);
    selection->sub_window = NULL;
        
    code = delwin(selection->window);
    if (E_OK != code) return result_ncurses_error(code);
    selection->window = NULL;
    
    return result_success();
}
예제 #20
0
파일: loader.c 프로젝트: FishTest/loader
/*主程序入口*/
void main(){
	//初始化GPIO按钮
	gpiosetup();
	//构建菜单
	ITEM **my_items;
	int c;
	MENU *my_menu;
	int n_choices, i;
	ITEM *cur_item;
	initscr();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	n_choices = ARRAY_SIZE(choices);
	my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
	for(i = 0; i < n_choices; ++i)
		my_items[i] = new_item(choices[i],choice_descp[i]);
	my_items[n_choices] = (ITEM *)NULL;
	my_menu = new_menu((ITEM **)my_items);
	post_menu(my_menu);
	refresh();
	//开始检测按键
	int ret = 0;
	while(ret==0){
		refresh();
		if (digitalRead (BTN_UP) == LOW){
			menu_driver(my_menu, REQ_UP_ITEM);
			delay(200);
			continue;
		}
		if (digitalRead (BTN_DOWN) == LOW){
			menu_driver(my_menu, REQ_DOWN_ITEM);
			delay(200);
			continue;
		}
		if (digitalRead (BTN_OK) == LOW){
			switch(item_index(current_item(my_menu)))
				{	
					case 0://执行第一个程序
						def_prog_mode();
						endwin();
						system ("cd //home//pi//xpi// && sudo python tools.py");
						reset_prog_mode();
						refresh();
						break;
					case 1://执行第二个程序
						def_prog_mode();
						endwin();
						system ("cd //home//pi//ada// && sudo python cam.py");
						reset_prog_mode();
						refresh();
						break;
					case 2://MPC
						def_prog_mode();
						endwin();
						system ("cd //home//pi//impc// && sudo python radioplayer.py");
						reset_prog_mode();
						refresh();
						break;
					case 3://HD Music Player
						def_prog_mode();
						endwin();
						system ("cd //home//pi//pplayer && sudo python player.py");
						reset_prog_mode();
						refresh();
						break;
					case 4://back to console
						ret = 1;
						break;
					case 5://关机
						free_item(my_items[0]);
						free_item(my_items[1]);
						free_menu(my_menu);
						endwin();
						refresh();
						system ("sudo shutdown -h now");
						break;
				}
			delay(200);
			continue;
		}
		mvprintw(LINES-1,0,"[%s]                 ", item_name(current_item(my_menu)));
	}
	free_item(my_items[0]);
	free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
	fflush (stdout) ;
}
예제 #21
0
int
edit_pos (SwitchPos * sp, AppData * a)
{
  MENU *my_menu;
  uint32_t i, maxx;
  int state = 0;
  ITEM **my_items;
//      WINDOW * menu_win,*menu_sub;
  uint32_t num_strings;
  int lbl_x, idx;

  message (a,
           "Here you can set the initial tuning file or edit the frequency bands.\n");
  while (state >= 0)
  {
    num_strings = 2;
    state = 0;
    debugMsg ("allocating items\n");
    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));
    my_items[0] = new_item ("Bands", "Bands");
    my_items[1] = new_item ("ITF", "ITF");
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu, O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Position") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Position");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    utlFAN (my_items);
    if (state == 5)
    {
      switch (idx)
      {
      case 0:
        edit_bands (sp, a);
        break;
      case 1:
        set_itf (sp, a);
        break;
      default:
        break;
      }
    }
  }
  return 0;
}
예제 #22
0
int
edit_bands (SwitchPos * sp, AppData * a)
{
  MENU *my_menu;
  SwitchBand *sb;
  SwitchPos tmp;
  uint32_t i, maxx;
  int state = 0;
  ITEM **my_items;
  char **mnu_str;
//      WINDOW * menu_win,*menu_sub;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  uint32_t num;
  spDeepCopy (&tmp, sp);
  num = tmp.num_bands;
  sb = tmp.bands;

  message (a,
           "Select and press enter to edit. Use d to delete a frequency band or a to add a new one. Use c to cancel and backspace to exit.\n");

  while (state >= 0)
  {
    num_strings = num;
    state = 0;
    maxx = getmaxx (stdscr);
    if (num)
    {

      debugMsg ("allocating items\n");
      my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));
      mnu_str = utlCalloc (num_strings, sizeof (char *));
      for (i = 0; i < num_strings; ++i)
      {
        mnu_str[i] = utlCalloc (20, sizeof (char));
        snprintf (mnu_str[i], 20, "%" PRIu32, i);
        my_items[i] = new_item (mnu_str[i], mnu_str[i]);
        if (NULL == my_items[i])
        {
          if (errno == E_BAD_ARGUMENT)
            errMsg ("badarg i=%" PRIu32 "\n", i);
          if (errno == E_SYSTEM_ERROR)
            errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
        }
      }
      my_items[num_strings] = (ITEM *) NULL;
      my_menu = new_menu ((ITEM **) my_items);
      set_menu_opts (my_menu, O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR);
      appDataMakeMenuWnd (my_menu);
      lbl_x = 3 + (maxx - 6) / 2 - strlen ("Bands") / 2;
      mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Bands");
      post_menu (my_menu);
      debugMsg ("starting menu loop\n");
      wrefresh (menu_win (my_menu));
      while (state == 0)
      {
        int c;
        ITEM *selection;
        c = getch ();
        switch (c)
        {
        case 263:              //ESC
        case K_BACK:           //Backspace
          state = -1;
          break;
        case KEY_DOWN:
          menu_driver (my_menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver (my_menu, REQ_UP_ITEM);
          break;
        case KEY_RESIZE:
          //windows need to be resized.. ignore
          break;
        case 'd':
          selection = current_item (my_menu);
          idx = item_index (selection);
          state = 1;
          break;
        case 'a':
          state = 2;
          break;
        case 'c':
          state = 3;
          break;
        case 13:               //enter
          selection = current_item (my_menu);
          idx = item_index (selection);
          state = 5;
          break;
        default:
          break;
        }
        wrefresh (menu_win (my_menu));
      }
      unpost_menu (my_menu);
      appDataDestroyMenuWnd (my_menu);
      free_menu (my_menu);
      for (i = 0; i < num_strings; ++i)
      {
        free_item (my_items[i]);
        utlFAN (mnu_str[i]);
      }
      utlFAN (mnu_str);
      utlFAN (my_items);
    }
    else
    {
      WINDOW *wnd;
      wnd = appDataMakeEmptyWnd ();

      wrefresh (wnd);
      while (state == 0)
      {
        int c;
        c = getch ();
        switch (c)
        {
        case KEY_RESIZE:
          wnd = appDataResizeEmpty (wnd);
          break;
        case 263:              //ESC
        case K_BACK:           //Backspace
          state = -1;
          break;
        case 'a':
          state = 2;
          break;
        case 'c':
          state = 3;
          break;
        default:
          break;
        }
        wrefresh (wnd);
      }
      assert (ERR != delwin (wnd));
    }
    if (state > 0)
    {
      switch (state)
      {
      case 1:                  //del
        spBandDel (&sb, &num, idx);
        break;
      case 2:                  //add(at the end)
        spBandAdd (&sb, &num, num);
        break;
      case 3:                  //cancel
        spClear (&tmp);         //clear temporary
        return 1;
      case 5:                  //edit
        edit_band (sb + idx, a);
        break;
      default:
        break;
      }
    }
  }
  spClear (sp);                 //clear original
  *sp = tmp;                    //replace with temporary
  return 0;
}
예제 #23
0
int
edit_band (SwitchBand * sb, AppData * a)
{
  uint32_t i, maxx;
  int state = 0;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  MENU *my_menu;
  SwitchBand tmp;
  SwitchPol *spol;
  ITEM **my_items;
  char **mnu_str[2];
//      WINDOW * menu_win,*menu_sub;
  uint32_t num;

  spBandDeepCopy (&tmp, sb);
  num = tmp.num_pol;
  spol = tmp.pol;

  message (a, "Modify Band parameters or edit Band's polarisations.\n");

  while (state >= 0)
  {
    num_strings = num + 3;
    state = 0;
    debugMsg ("allocating items\n");

    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));

    mnu_str[0] = utlCalloc (num_strings, sizeof (char *));
    mnu_str[1] = utlCalloc (num_strings, sizeof (char *));

    debugMsg ("allocating items\n");
    mnu_str[0][0] = "lof";
    mnu_str[1][0] = utlCalloc (32, sizeof (char));
    snprintf (mnu_str[1][0], 32, "%u", sb->lof);
    my_items[0] = new_item (mnu_str[0][0], mnu_str[1][0]);

    mnu_str[0][1] = "f_min";
    mnu_str[1][1] = utlCalloc (32, sizeof (char));
    snprintf (mnu_str[1][1], 32, "%u", sb->f_min);
    my_items[1] = new_item (mnu_str[0][1], mnu_str[1][1]);

    mnu_str[0][2] = "f_max";
    mnu_str[1][2] = utlCalloc (32, sizeof (char));
    snprintf (mnu_str[1][2], 32, "%u", sb->f_max);
    my_items[2] = new_item (mnu_str[0][2], mnu_str[1][2]);

    for (i = 3; i < num_strings; ++i)
    {
      mnu_str[0][i] = utlCalloc (32, sizeof (char));
      mnu_str[1][i] = (char *) tpiGetPolStr (sb->pol[i - 3].pol);
      snprintf (mnu_str[0][i], 32, "Pol%" PRIu32, i - 3);
      my_items[i] = new_item (mnu_str[0][i], mnu_str[1][i]);
      if (NULL == my_items[i])
      {
        if (errno == E_BAD_ARGUMENT)
          errMsg ("badarg i=%" PRIu32 "\n", i);
        if (errno == E_SYSTEM_ERROR)
          errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
      }
    }
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu,
                   O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR | O_SHOWDESC);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Band") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Band");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 'd':
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 1;
        break;
      case 'a':
        state = 2;
        break;
      case 'c':
        state = 3;
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    utlFAN (mnu_str[1][0]);
    utlFAN (mnu_str[1][1]);
    utlFAN (mnu_str[1][2]);
    for (i = 3; i < num_strings; ++i)
      utlFAN (mnu_str[0][i]);
    utlFAN (mnu_str[0]);
    utlFAN (mnu_str[1]);
    utlFAN (my_items);
    if (state > 0)
    {
      switch (state)
      {
      case 1:                  //del
        if (idx >= 3)
          spPolDel (&spol, &num, idx - 3);
        break;
      case 2:                  //add(at the end)
        spPolAdd (&spol, &num, num);
        break;
      case 3:                  //cancel
        spBandClear (&tmp);     //clear temporary
        return 1;
      case 5:                  //edit
        if (idx >= 3)
          edit_pol (spol + idx - 3, a);
        else
          switch (idx)
          {
          case 0:
            tmp.lof = get_num (a);      //3,29,a);
            break;
          case 1:
            tmp.f_min = get_num (a);    //4,29,a);
            break;
          case 2:
            tmp.f_max = get_num (a);    //5,29,a);
            break;
          }
        break;
      default:
        break;
      }
    }
  }
  spBandClear (sb);             //clear original
  *sb = tmp;                    //replace with temporary
  return 0;
}
예제 #24
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;
}
예제 #25
0
//
// Affiche une fenêtre de menu.
//
int displayMenu(char **choices, int nbChoices, char title[], bool logo) {
    if(choices == NULL || nbChoices < 1) return -1;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    WINDOW *menuWin = NULL;
    
    int i = 0, c;
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = max_strlen(choices, nbChoices) + 2;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    while(true) {
        clear();
        
        menuWin = (logo) ? getMenuWindow(nbChoices, title) : getMenuWindowNoLogo(nbChoices, title, -1, -1);
        
        //on initialise le menu
        menu = new_menu((ITEM **) menuItems);
        
        //on lui précise bien que le menu fait N lignes et 1 colonne
        set_menu_format(menu, nbChoices, 1);
        
        menu_opts_off(menu, O_NONCYCLIC);
        set_menu_mark(menu, "> ");
        
        //on associe le menu à une fenêtre et une sous-fenêtre
        set_menu_win(menu, menuWin);
        //fenêtre hauteur largeur x y
        set_menu_sub(menu, derwin(menuWin, nbChoices, menuWidth, (logo) ? 15 : 4, (winWidth - menuWidth) / 2));
        
        //et hop, on affiche le menu et on rafraîchit.
        post_menu(menu);
        
        refresh();
        wrefresh(menuWin);
        
        curs_set(0);
        noecho();
        
        //boucle pour le menu
        while((c = getch())) {
            bool resized = false;
            
            switch(c) {
                case KEY_DOWN:
                    menu_driver(menu, REQ_DOWN_ITEM);
                    break;
                case KEY_UP:
                    menu_driver(menu, REQ_UP_ITEM);
                    break;
                case KEY_ESC_ALT:
                    return -1;
                case KEY_RESIZE:
                    //si on a redimensionné le terminal, on ré-exécute la boucle d'affichage
                    resized = true;
                    break;
                case KEY_MENU_ENTER: {
                    int choice = item_index(current_item(menu));
                    
                    //on libère la mémoire pour le menu, les choix, la fenêtre
                    unpost_menu(menu);
                    free_menu(menu);
                    
                    for(i = 0; i < nbChoices; ++i)
                        free_item(menuItems[i]);
                    
                    clear();
                    refresh();
                    
                    delwin(menuWin);
                    
                    //on réactive l'affichage des caractères tapés et du curseur
                    echo();
                    curs_set(1);
                    
                    return choice;
                }
            }
            
            if(resized) break;
            wrefresh(menuWin);
        }

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

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

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


    moduleMenu = new_menu(&pluginEntries[0]);

    WINDOW* win;

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

    refresh();
    wrefresh(win);

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

    loadModule(chosen);
}