[완료] Ncurses Menu위젯 질문입니다.
      글쓴이: xog2000 / 작성시간: 화, 2007/10/16 - 10:52오후    
  
  #include <menu.h>                                                                                 
 
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))                                                  
#define CTRLD   4                                                                                 
 
char *choices[] = {                                                                               
                        "Choice 1",                                                               
                        "Choice 2",                                                               
                        "Choice 3",                                                               
                        "Choice 4",     
                        "Choice 1",                                                               
                        "Choice 2",                                                               
                        "Choice 3",                                                               
                        "Choice 4",  
                        "Choice 1",                                                               
                        "Choice 2",                                                               
                        "Choice 3",                                                               
                        "Choice 4",  
                        "Choice 1",                                                               
                        "Choice 2",                                                               
                        "Choice 3",                                                               
                        "Choice 4",  
                        "Choice 1",                                                               
                        "Choice 2",                                                               
                        "Choice 3",                                                               
                        "Choice 4",                                                            
                        "Exit",                                                                   
                        (char *)NULL,                                                             
                  };                                                                              
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); 
 
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(25, 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, 21, 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();                                                                                 
}                                                                                                 
 
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)  
{       int length, x, y;                                                                         
        float temp;                                                                               
 
        if(win == NULL)                                                                           
                win = stdscr;                                                                     
        getyx(win, y, x);                                                                         
        if(startx != 0)                                                                           
                x = startx;                                                                       
        if(starty != 0)                                                                           
                y = starty;                                                                       
        if(width == 0)                                                                            
                width = 80;                                                                       
 
        length = strlen(string);                                                                  
        temp = (width - length)/ 2;                                                               
        x = startx + (int)temp;                                                                   
        wattron(win, color);                                                                      
        mvwprintw(win, y, x, "%s", string);                                                       
        wattroff(win, color);                                                                     
        refresh();                                                                                
}   제가 메뉴가 들어간 프로그램을 만들고 있는데
이상하게 아이템이 16개만 보이고 그 이하는 윈도우를 늘려도
나타나지가 않는것입니다.
그래서 위의 ncurses 예제에서
아이템의 수와
윈도우 크기만 조정 했습니다.
역시나 16라인까지만 보이고 그 상태로 메뉴가
만들어 집니다. (즉 Box 표현은 제대로 되는데 그 안쪽 16라인만 메뉴로 생성 됨)
이유가 무엇일까요?
전에는 제대로 된것 같았는데..
현재 우분투를 설치해 사용하고 있고 ncurses는 우분투에서 패키지 추가로 받아왔습니다.
Forums: 


자답이네요.
set_menu_format이라는 함수를 제공하고 있군요.
----------------------------------------
내가사는세상-Kernelist : http://blog.naver.com/xog2000
"모르는 것은 어리석은 것이 아니다.
어리석은 것은 알려는 의지가 없음을 말한다."
댓글 달기