home *** CD-ROM | disk | FTP | other *** search
-
- /* n4.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Menu Routines
- */
-
- #include "d4all.h"
- #include "w4.h"
- #include "g4char.h"
- #include "u4error.h"
- #include "p4misc.h"
-
- #ifdef VARARGS
- #include <varargs.h>
- #else
- #include <stdarg.h>
- #endif
-
- #include <string.h>
- #include <ctype.h>
- #ifndef UNIX
- #include <io.h>
- #endif
-
- extern GET *v4get ;
- extern CB_WINDOW *v4window ;
- extern CB_WINDOW *v4window_ptr ;
- extern MENU *v4menu ;
-
- static char key_data[20] ; /* Key Data Entered When Searching Menus */
- static int key_len = 0 ;
-
- extern int v4up_key ;
- extern int v4exit_key ;
- extern int v4return_start ;
- extern int v4return_end ;
-
- extern int v4screen_width ; /* Width in display characters */
- extern int v4screen_width2 ; /* Width in storage bytes */
- extern int v4screen_height ;
- extern int v4display_bytes ; /* Width in storage bytes */
-
- extern int v4cur_window ; /* The Selected Window */
- extern int v4first_window ;
-
- #ifdef UNIX
- extern int v4refresh_on ;
- #endif
-
- typedef struct menu_data_st
- {
- int ref ; /* The reference number of the current menu selection */
- int pos ; /* The position (from 0) of the current selection */
-
- int tot_entries ; /* The total number of entries in the menu */
- int scr_entries ; /* The number of entries which fit on the screen */
-
- int num_rows ; /* The number of rows in each menu */
- int num_cols ; /* The number of column positions in each menu */
-
- int do_calc ; /* 1 to calculate the (row,col) positions, otherwise 0 */
- } MENU_DATA ;
-
- static void calc_pos( int, MENU_DATA *, int, int *, int *) ;
- static void make_top( MENU_DATA * ) ;
- static void refresh_menu( MENU_DATA * ) ;
- static void display_item( MENU_DATA *, int ) ;
- static int skip( MENU_DATA *, int ) ;
- static void menu_home_end( MENU_DATA *, int ) ;
- static int menu_top_bottom( MENU_DATA *, int ) ;
- static void menu_pgup_pgdn( MENU_DATA *, int ) ;
- static void menu_up_down( MENU_DATA *, int ) ;
- static int menu_key( MENU_DATA *, int ) ;
- static int top_bottom_ref( MENU_DATA *, int ) ;
-
- static int is_window_ref( int ) ;
-
- static int is_window_ref( int w_ref )
- {
- int on_ref ;
-
- on_ref = v4first_window ;
- while ( on_ref >= 0 )
- {
- if ( w_ref == on_ref ) return 1 ;
- on_ref = v4window[on_ref].next ;
- }
- return 0 ;
- }
-
- static top_bottom_ref( MENU_DATA *m_ptr, int sign )
- {
- int on_pos, on_ref, num_pos ;
-
- on_pos = m_ptr->pos ;
- on_ref = m_ptr->ref ;
-
- if ( sign < 0 )
- {
- while( on_pos-- > 0 && on_ref >= 0 )
- on_ref = v4menu[on_ref].prev ;
- }
- else
- {
- num_pos = m_ptr->scr_entries - on_pos - 1 ;
- while( num_pos-- > 0 && on_ref >= 0 )
- on_ref = v4menu[on_ref].next ;
- }
-
- return( on_ref ) ;
- }
-
- static void calc_pos( int menu_ref, MENU_DATA *m_ptr, int i,
- int *row_ptr, int *col_ptr )
- {
- if ( ! m_ptr->do_calc )
- {
- *row_ptr = v4menu[menu_ref].row ;
- *col_ptr = v4menu[menu_ref].col ;
- return ;
- }
-
- if ( v4window_ptr->horizontal )
- {
- *row_ptr = i / m_ptr->num_cols ;
- *col_ptr = (i% m_ptr->num_cols) * v4window_ptr->item_width +1 ;
- }
- else
- {
- *row_ptr = i % m_ptr->num_rows ;
- *col_ptr = (i/ m_ptr->num_rows) * v4window_ptr->item_width +1 ;
- }
- }
-
-
- /* Makes the Current Entry as Close to the Top Entry as Possible */
- static void make_top( MENU_DATA *m_ptr )
- {
- int ref, n ;
-
- n = 0 ;
- ref = m_ptr->ref ;
-
- while ( ref >= 0 && ++n < m_ptr->scr_entries )
- ref = v4menu[ref].next ;
-
- m_ptr->pos = m_ptr->scr_entries - n ;
- }
-
-
- static void refresh_menu( MENU_DATA *m_ptr )
- {
- int save_ref, save_pos ;
-
- w4activate(-1) ;
- w4clear( 0 ) ;
-
- if ( m_ptr->pos < 0 ) m_ptr->pos = 0 ;
- if ( m_ptr->pos >= m_ptr->scr_entries )
- m_ptr->pos = m_ptr->scr_entries - 1 ;
-
- save_ref = m_ptr->ref ;
- save_pos = m_ptr->pos ;
- display_item( m_ptr, -1 ) ;
-
- for( ;; )
- {
- m_ptr->pos++ ;
- m_ptr->ref = v4menu[m_ptr->ref].next ;
- if ( m_ptr->pos >= m_ptr->scr_entries || m_ptr->ref < 0 ) break ;
-
- display_item( m_ptr, 0 ) ;
- }
-
- m_ptr->ref = save_ref ;
- m_ptr->pos = save_pos ;
-
- for( ;; )
- {
- m_ptr->pos-- ;
- m_ptr->ref = v4menu[m_ptr->ref].prev ;
- if ( m_ptr->pos < 0 || m_ptr->ref < 0 ) break ;
-
- display_item( m_ptr, 0 ) ;
- }
-
- m_ptr->ref = save_ref ;
- m_ptr->pos = save_pos ;
- }
-
-
- /* display_item
-
- do_att Value Meaning
-
- -1 Display completely with selected attribute
- >= 0 Display that number of characters blinking and
- intense. This is used to display the matching
- search characters in a different manner.
- 0 Display normally. If their is a special key
- highlight position, the character will be
- displayed intensely. Their will be no
- special highlight key for search windows.
- */
-
- static void display_item( MENU_DATA *m_ptr, int do_att )
- {
- int row, col, len, pos ;
- char *ptr ;
- MENU *menu_ptr ;
-
- calc_pos( m_ptr->ref, m_ptr, m_ptr->pos, &row, &col ) ;
- menu_ptr = v4menu + m_ptr->ref ;
-
- ptr = menu_ptr->item_ptr ;
- len = (int) strlen(ptr) ;
- if ( len > v4window_ptr->item_width )
- len = v4window_ptr->item_width ;
-
- if ( do_att )
- {
- if ( do_att < 0 )
- {
- w4num_att( row, col, ptr, len, v4window_ptr->menu_att_active) ;
- }
- else
- {
- if ( do_att > len ) do_att = len ;
- w4num_att( row, col, ptr, do_att,
- v4window_ptr->menu_att_active | B_BLINK | F_INTENSE ) ;
- w4num_att( row, col+do_att, ptr+ do_att, len- do_att,
- v4window_ptr->menu_att_active) ;
- }
- }
- else
- {
- if ( menu_ptr->key_highlight_pos < 0 ||
- menu_ptr->key_highlight_pos >= len ||
- v4window_ptr->key_read != 1 ||
- menu_ptr->skip_over )
- {
- w4num_att( row, col, ptr, len, menu_ptr->attribute ) ;
- }
- else
- {
- pos = menu_ptr->key_highlight_pos ;
-
- w4num_att( row, col, ptr, pos, menu_ptr->attribute ) ;
- w4num_att( row, col+pos, ptr+pos, 1, menu_ptr->attribute | F_INTENSE) ;
- pos++ ;
- w4num_att( row, col+pos, ptr+pos, len-pos, menu_ptr->attribute ) ;
- }
- }
- }
-
- /* Skips if necessary in the specified direction to a valid menu option */
-
- static int skip( MENU_DATA *m_ptr, int sign )
- {
- int ref, pos ;
-
- ref = m_ptr->ref ;
- pos = m_ptr->pos ;
-
- while ( v4menu[ref].skip_over )
- {
- if ( sign < 0 )
- {
- ref = v4menu[ref].prev ;
- pos-- ;
- if ( ref < 0 )
- {
- if ( m_ptr->ref == v4window_ptr->last_menu) return -1 ;
-
- m_ptr->ref = v4window_ptr->first_menu ;
- m_ptr->pos = 0 ;
- skip( m_ptr, 1) ;
- return -1 ;
- }
- }
- else
- {
- ref = v4menu[ref].next ;
- pos++ ;
- if ( ref < 0 )
- {
- if ( m_ptr->ref == v4window_ptr->first_menu) return 1 ;
-
- m_ptr->ref = v4window_ptr->last_menu ;
- m_ptr->pos = m_ptr->scr_entries-1 ;
- skip( m_ptr, -1) ;
- return 1 ;
- }
- }
- }
-
- m_ptr->pos = pos ;
- m_ptr->ref = ref ;
-
- return 0 ;
- }
-
- static void menu_home_end( MENU_DATA *m_ptr, int sign )
- {
- MENU_DATA old_data ;
-
- key_len = 0 ;
-
- memcpy( (char *) &old_data, (char *) m_ptr, sizeof(MENU_DATA) ) ;
- if ( sign < 0 )
- {
- m_ptr->pos = 0 ;
- m_ptr->ref = v4window_ptr->first_menu ;
- }
- else
- {
- m_ptr->pos = m_ptr->scr_entries-1 ;
- m_ptr->ref = v4window_ptr->last_menu ;
- }
-
- skip(m_ptr, sign) ;
-
- if ( top_bottom_ref(m_ptr,sign) != top_bottom_ref(&old_data,sign) )
- {
- refresh_menu( m_ptr ) ;
- return ;
- }
-
- display_item( &old_data, 0 ) ;
- display_item( m_ptr, -1 ) ;
- }
-
- /* Returns TRUE if already on top or bottom; otherwise, moves to top or bottom */
- static int menu_top_bottom( MENU_DATA *m_ptr, int sign )
- {
- MENU_DATA test ;
-
- memcpy( (char *) &test, (char *) m_ptr, sizeof(MENU_DATA) ) ;
- test.ref = top_bottom_ref( &test, sign ) ;
-
- if ( sign < 0 )
- test.pos = 0 ;
- else
- test.pos = m_ptr->scr_entries- 1 ;
-
- if ( m_ptr->ref == test.ref ) return( 1 ) ;
-
- skip( &test, sign ) ;
- if ( test.ref == m_ptr->ref ) return( 1 ) ;
-
- memcpy( (char *) m_ptr, (char *) &test, sizeof(MENU_DATA) ) ;
- refresh_menu( m_ptr ) ;
-
- return ( 0 ) ;
- }
-
-
- static void menu_pgup_pgdn( MENU_DATA *m_ptr, int sign )
- {
- int i, next_ref ;
-
- key_len = 0 ;
-
- if ( menu_top_bottom(m_ptr, sign) )
- {
- for ( i=0; i< m_ptr->scr_entries; i++ )
- {
- if ( sign < 0 )
- next_ref = v4menu[m_ptr->ref].prev ;
- else
- next_ref = v4menu[m_ptr->ref].next ;
- if (next_ref < 0) break ;
- m_ptr->ref = next_ref ;
- }
-
- if ( sign < 0 )
- m_ptr->pos = 0 ;
- else
- m_ptr->pos = m_ptr->scr_entries - 1;
-
- skip( m_ptr, sign ) ;
- refresh_menu( m_ptr ) ;
- }
- }
-
- static void menu_up_down( MENU_DATA *m_ptr, int sign )
- {
- MENU_DATA old_data ;
- int next_ref ;
-
- if ( sign < 0 )
- next_ref = v4menu[m_ptr->ref].prev ;
- else
- next_ref = v4menu[m_ptr->ref].next ;
-
- if ( next_ref < 0 )
- {
- menu_home_end( m_ptr, -sign ) ;
- return ;
- }
-
- key_len = 0 ;
- memcpy( (char *) &old_data, (char *) m_ptr, sizeof(MENU_DATA) ) ;
-
- m_ptr->ref = next_ref ;
- m_ptr->pos += sign ;
-
- if ( skip( m_ptr, sign ) )
- {
- memcpy( (char *) m_ptr, (char *) &old_data, sizeof(MENU_DATA) ) ;
- menu_home_end( m_ptr, -sign ) ;
- return ;
- }
-
- if ( m_ptr->pos < 0 || m_ptr->pos >= m_ptr->scr_entries )
- refresh_menu( m_ptr ) ;
- else
- {
- display_item( &old_data, 0 ) ;
- display_item( m_ptr, -1 ) ;
- }
- }
-
- /* Returns -2 if not found; else 0 */
- static int menu_key( MENU_DATA *m_ptr, int ch )
- {
- int ref, i, pos, is_found, ch_upper, ch_lower ;
-
- if ( v4window_ptr->ignore_case && ch <= 0x7E )
- {
- ch_upper = u4toupper( ch ) ;
- ch_lower = u4tolower( ch ) ;
- }
- else
- ch_upper = ch_lower = ch ;
-
- if ( v4window_ptr->key_read > 0 )
- {
- pos = m_ptr->pos ;
- ref = m_ptr->ref ;
-
- is_found = 0 ;
-
- if ( v4window_ptr->key_read == 2 && key_len < sizeof(key_data) )
- key_data[key_len++] = (char) ch ;
-
- for ( i = 0; i<= m_ptr->tot_entries; i++, pos++ )
- {
- if ( ref < 0 )
- {
- pos -= m_ptr->tot_entries ;
- ref = v4window_ptr->first_menu ;
- }
-
- if ( ! v4menu[ref].skip_over )
- {
- if ( v4window_ptr->key_read == 1 )
- {
- if ( (ch_upper == (int) v4menu[ref].key_value ||
- ch_lower == (int) v4menu[ref].key_value) &&
- (ref != m_ptr->ref || i > 0) ) is_found = 1 ;
- }
- else
- {
- /* String Compare */
- if ( v4window_ptr->ignore_case )
- {
- if ( strnicmp( key_data, v4menu[ref].item_ptr, (size_t) key_len ) == 0 )
- is_found = 1 ;
- }
- else
- {
- if ( strncmp( key_data, v4menu[ref].item_ptr, (size_t) key_len ) == 0 )
- is_found = 1 ;
- }
- }
- }
-
- if ( is_found )
- {
- if ( pos >= m_ptr->scr_entries || pos < 0 )
- {
- m_ptr->ref = ref ;
- make_top( m_ptr ) ; /* Make Found Entry the Top if Possible */
- refresh_menu( m_ptr ) ;
- if ( v4window_ptr->key_read == 2 )
- display_item( m_ptr, key_len ) ;
- else
- if ( v4menu[m_ptr->ref].key_activate ) return (RETURN) ;
- return 0 ;
- }
- else
- {
- display_item( m_ptr, 0 ) ;
- m_ptr->ref = ref ;
- m_ptr->pos = pos ;
- if ( v4window_ptr->key_read == 2 )
- display_item( m_ptr, key_len ) ;
- else
- {
- display_item( m_ptr, -1 ) ;
- if ( v4menu[m_ptr->ref].key_activate ) return (RETURN) ;
- }
- return 0 ;
- }
- }
-
- ref = v4menu[ref].next ;
- }
- if ( key_len > 0 ) key_len-- ;
- }
-
- return -2 ;
- }
-
- int n4( char *label )
- {
- return( n4item( -1, -1, label ) ) ;
- }
-
-
- static int (*rou_ptr)(void) = 0 ;
-
- #ifdef KR
- void n4char_routine( char_rou )
- int (*char_rou)() ;
- #else
- void n4char_routine( int (*char_rou)(void) )
- #endif
- {
- rou_ptr = char_rou ;
- }
-
- #ifdef UNIX
- int n4char()
- {
- int rc ;
-
- v4refresh_on = 1 ;
- w4refresh(-1) ;
-
- if ( u4ptr_equal( (void *) rou_ptr, (void *) 0 ) )
- rc = g4char() ;
- else
- rc = (*rou_ptr)() ;
-
- v4refresh_on = 0 ;
-
- return( rc ) ;
- }
- #else
- int n4char()
- {
- if ( u4ptr_equal( (void *) rou_ptr, (void *) 0 ) )
- return g4char() ;
- else
- return (*rou_ptr)() ;
- }
- #endif
-
-
- static void n4act_return( int, int, int ) ;
-
- static void n4act_return( int menu_ref, int prev_ref, int save_refresh_on )
- {
- n4message_do( "" ) ;
- w4deactivate( v4menu[menu_ref].window_ref ) ;
- w4select( prev_ref ) ;
-
- #ifdef UNIX
- v4refresh_on = save_refresh_on ;
- w4refresh(-1) ;
- #endif
- }
-
-
- int n4activate( int w_ref )
- {
- int ch, up_ch, down_ch, up_ch2, down_ch2, new_ch ;
- int max_width, cur_width, prev_ref ;
- MENU *menu_ptr ;
- MENU_DATA m ;
- int save_refresh_on ;
-
- prev_ref = w4select( w_ref ) ;
- save_refresh_on = v4window_ptr->force_refresh = 0 ;
-
- new_ch = key_len = max_width = m.do_calc = m.tot_entries = 0 ;
-
- for( m.ref = v4window_ptr->first_menu; m.ref >= 0;
- m.ref = v4menu[m.ref].next )
- {
- menu_ptr = v4menu + m.ref ;
- m.tot_entries ++ ;
- cur_width = (int) strlen( menu_ptr->item_ptr ) ;
- if ( cur_width > max_width ) max_width = cur_width ;
-
- if ( menu_ptr->row < 0 || menu_ptr->col < 0 ) m.do_calc = 1 ;
- }
- if ( m.tot_entries < 0 )
- {
- w4select( prev_ref ) ;
- return 0 ;
- }
-
- /* Initialize the menu data */
- m.num_rows = v4window_ptr->height ;
- m.num_cols = v4window_ptr->width-2 ;
- if ( v4window_ptr->item_width <= 0 )
- v4window_ptr->item_width = v4window_ptr->width-2 ;
- m.num_cols /= v4window_ptr->item_width ;
- if ( m.do_calc )
- m.scr_entries = m.num_rows * m.num_cols ;
- else
- {
- m.num_rows = m.tot_entries ;
- m.num_cols = 1 ;
- m.scr_entries = m.tot_entries ;
- }
- if ( m.scr_entries > m.tot_entries ) m.scr_entries = m.tot_entries ;
- if ( m.scr_entries <= 0 )
- {
- w4select( prev_ref ) ;
- return 0 ;
- }
-
- #ifdef UNIX
- save_refresh_on = v4refresh_on ;
- v4refresh_on = 0 ;
- #endif
-
- w4activate( w_ref ) ;
-
- if ( v4window_ptr->start_item < 0 )
- menu_home_end( &m, -1 ) ;
- else
- {
- m.ref = v4window_ptr->start_item ;
- make_top( &m ) ;
- refresh_menu( &m ) ;
- }
-
- if ( v4window_ptr->horizontal )
- {
- up_ch = LEFT ;
- down_ch = RIGHT ;
- up_ch2 = CTRL_S ;
- down_ch2= CTRL_D ;
- }
- else
- {
- up_ch = UP ;
- down_ch = DOWN ;
- up_ch2 = CTRL_E ;
- down_ch2= CTRL_X ;
- }
-
- for(;;)
- {
- w4select( v4menu[m.ref].window_ref ) ;
-
- if ( v4window_ptr->force_refresh )
- {
- v4window_ptr->force_refresh = 0 ;
- refresh_menu( &m ) ;
- }
-
- if ( new_ch > 0 )
- {
- ch = new_ch ;
- new_ch = 0 ;
- if ( ch == v4window_ptr->up_key )
- ch = 0 ; /* Only Up One at a Time */
- n4message_do( v4menu[m.ref].message ) ;
- }
- else
- {
- if ( ! u4ptr_equal( (void *) v4menu[m.ref].reaction, (void *) 0) )
- {
- #ifdef UNIX
- if ( ! u4ptr_equal( (void *) v4menu[m.ref].reaction , (void *) n4sub_menu) )
- {
- v4refresh_on = 1 ;
- w4refresh(-1) ;
- }
- #endif
- ch = (*v4menu[m.ref].reaction)( v4menu[m.ref].parm_data ) ;
-
- #ifdef UNIX
- v4refresh_on = 0 ;
- #endif
- if ( ch < 0 )
- {
- n4act_return( m.ref, prev_ref, save_refresh_on ) ;
- return( ch ) ;
- }
- if ( ch == 0 )
- {
- n4message_do( v4menu[m.ref].message ) ;
- ch = n4char() ;
- }
- }
- else
- {
- n4message_do( v4menu[m.ref].message ) ;
- ch = n4char() ;
- }
- }
-
-
- w4select( v4menu[m.ref].window_ref ) ;
-
- switch( ch )
- {
- case UP:
- case LEFT:
- case CTRL_E:
- case CTRL_S:
- if ( ch == up_ch || ch == up_ch2 )
- {
- menu_up_down( &m, -1 ) ;
- }
- else
- {
- if ( v4window_ptr->arrow_exit )
- {
- n4act_return( m.ref, prev_ref, save_refresh_on ) ;
- return( ch ) ;
- }
- }
- break ;
-
- case DOWN:
- case RIGHT:
- case CTRL_X:
- case CTRL_D:
- if ( ch == down_ch || ch == down_ch2 )
- {
- menu_up_down( &m, 1 ) ;
- }
- else
- {
- if ( v4window_ptr->arrow_exit )
- {
- n4act_return( m.ref, prev_ref, save_refresh_on ) ;
- return( ch ) ;
- }
- }
- break ;
-
- case HOME:
- case CTRL_A:
- menu_home_end( &m, -1 ) ;
- break ;
-
- case END:
- menu_home_end( &m, 1 ) ;
- break ;
-
- case PGUP:
- case CTRL_R:
- menu_pgup_pgdn( &m, -1 ) ;
- break ;
-
- case PGDN:
- case CTRL_N:
- menu_pgup_pgdn( &m, 1 ) ;
- break ;
-
- case BACK_SPACE:
- if (key_len > 0)
- {
- if ( --key_len > 0 )
- display_item( &m, key_len ) ;
- else
- display_item( &m, -1 ) ;
- }
- break ;
-
- case RETURN:
- if ( key_len > 0 )
- {
- key_len = 0 ;
- display_item( &m, -1 ) ;
- }
- if ( u4ptr_equal( (void *) v4menu[m.ref].action, (void *) 0) &&
- u4ptr_equal( (void *) v4menu[m.ref].reaction, (void *) 0) )
- {
- n4act_return( m.ref, prev_ref, save_refresh_on ) ;
- return ( v4menu[m.ref].parm_data ) ;
- }
- if ( u4ptr_equal( (void *) v4menu[m.ref].action, (void *) 0 ) )
- new_ch = 0 ;
- else
- {
- #ifdef UNIX
- if ( ! u4ptr_equal( (void *) v4menu[m.ref].action, (void *) n4sub_menu))
- {
- v4refresh_on = 1 ;
- w4refresh(-1) ;
- }
- #endif
- new_ch = (*v4menu[m.ref].action)( v4menu[m.ref].parm_data) ;
- #ifdef UNIX
- v4refresh_on = 0 ;
- #endif
- if ( new_ch < 0 )
- {
- n4act_return( m.ref, prev_ref, save_refresh_on) ;
- return ( new_ch ) ;
- }
- w4select( v4menu[m.ref].window_ref ) ;
- if ( ! v4window_ptr->force_refresh )
- display_item( &m, -1 ) ;
- break ;
- }
-
- default:
- if ( ch == v4window_ptr->exit_key || ch == v4window_ptr->up_key )
- {
- n4act_return( m.ref, prev_ref, save_refresh_on ) ;
- return( ch ) ;
- }
-
- if ( ch >= 0x1 && ch <= 0x7F00 )
- {
- new_ch = menu_key( &m, ch ) ;
- if ( new_ch == -2 )
- {
- new_ch = 0 ;
- if ( ch >= v4window_ptr->return_start &&
- ch <= v4window_ptr->return_end )
- {
- n4act_return( m.ref, prev_ref, save_refresh_on ) ;
- return( ch ) ;
- }
- }
- }
- break ;
- }
- }
- }
-
-
- void n4arrow_exit()
- {
- v4window_ptr->arrow_exit = 1 ;
- }
-
-
- void n4attribute( long attribute, long attribute_active )
- {
- v4window_ptr->menu_attribute = attribute ;
- v4window_ptr->menu_att_active = attribute_active ;
- }
-
-
- void n4attribute_item( int item_ref, long attribute )
- {
- MENU *menu_ptr ;
-
- menu_ptr = v4menu + item_ref ;
- menu_ptr->attribute = attribute ;
- }
-
-
- void n4get_calc( int w_ref )
- {
- int on_get, on_menu ;
- GET *get_ptr ;
- CB_WINDOW *w2_ptr, *w_ptr ;
-
- w_ptr = v4window + w_ref ;
-
- for (on_get= w_ptr->first_get; on_get >= 0; on_get = get_ptr->next)
- {
- get_ptr = v4get+ on_get ;
-
- if ( u4ptr_equal( (void *) get_ptr->call, (void *) g4menu) ||
- u4ptr_equal( (void *) get_ptr->call, (void *) g4menu_help ))
- {
- w2_ptr = v4window + get_ptr->call_data ;
- #ifdef UNIX
- w2_ptr->up_key = CTRL_Q ;
- #else
- w2_ptr->up_key = ESC ;
- #endif
- w2_ptr->exit_key = SHIFT_TAB ;
- w2_ptr->return_start = 0 ;
- w2_ptr->return_end = 0x7F ;
-
- n4calc( get_ptr->call_data,
- w_ptr->start_row + get_ptr->row +1,
- w_ptr->start_col + get_ptr->col ) ;
-
- for ( on_menu=w2_ptr->first_menu; on_menu>=0; on_menu=v4menu[on_menu].next)
- {
- v4menu[on_menu].parm_data = -on_menu ;
- if ( on_menu == 0 )
- v4menu[on_menu].parm_data = 0x7FFF ;
- }
- }
- }
- }
-
-
- void n4horizontal()
- {
- v4window_ptr->horizontal = 1 ;
- }
-
- int n4item( int row, int col, char *label )
- {
- MENU *menu_ptr ;
-
- if ( v4menu == (MENU *) 0 )
- if( h4create( (char **) &v4menu, 20, (int) sizeof(MENU), 20) < 0 ) return -1 ;
-
- v4window_ptr->last_menu = h4get( (char **) &v4menu, v4window_ptr->last_menu ) ;
- if ( v4window_ptr->last_menu < 0 ) return -1 ;
-
- if ( v4window_ptr->first_menu < 0 )
- v4window_ptr->first_menu = v4window_ptr->last_menu ;
- menu_ptr = v4menu+ v4window_ptr->last_menu ;
-
- menu_ptr->row = row ;
- menu_ptr->col = col ;
- menu_ptr->window_ref = v4cur_window ;
- menu_ptr->item_ptr = label ;
- menu_ptr->attribute = v4window_ptr->menu_attribute ;
- menu_ptr->parm_data = v4window_ptr->last_menu ;
- n4key( (int) label[0], 1, 0 ) ;
-
- return ( v4window_ptr->last_menu ) ;
- }
-
- char * n4item_text( int i_ref )
- {
- return ( v4menu[i_ref].item_ptr ) ;
- }
-
- void n4item_width( int item_width )
- {
- v4window_ptr->item_width = item_width ;
- }
-
-
- void n4key( int chr, int active, int highlight_pos )
- {
- MENU *menu_ptr ;
-
- if ( v4window_ptr->last_menu < 0 ) return ;
- menu_ptr = v4menu + v4window_ptr->last_menu ;
- menu_ptr->key_value = chr ;
- menu_ptr->key_activate = active ;
- menu_ptr->key_highlight_pos= highlight_pos ;
- }
-
-
- void n4key_set( int set_code, int ignore_case )
- {
- v4window_ptr->key_read = set_code ;
- v4window_ptr->ignore_case = ignore_case ;
- }
-
-
- void n4key_special( int up_key, int exit_key, int return_start, int return_end )
- {
- v4up_key = up_key ;
- v4exit_key = exit_key ;
- v4return_start= return_start ;
- v4return_end = return_end ;
- }
-
- extern int v4menu_row, v4menu_col ;
- static void calc_lotus(int, int, int) ;
-
- void n4lotus( int w_ref )
- {
- CB_WINDOW *w_ptr ;
-
- if ( ! is_window_ref( w_ref ) )
- {
- u4error( E_WINDOW_REF, "(n4lotus)", (char *) 0 ) ;
- return ;
- }
-
- w_ptr = v4window + w_ref ;
-
- if ( w_ptr->start_row < 0 ) w_ptr->start_row = 0 ;
- if ( w_ptr->start_col < 0 ) w_ptr->start_col = 0 ;
-
- calc_lotus( w_ref, w_ptr->start_row, w_ptr->start_col ) ;
- v4menu_row = w_ptr->start_row+1 ;
- v4menu_col = w_ptr->start_col ;
- }
-
-
- static void calc_lotus( int window_ref, int start_row, int start_col )
- {
- int menu_on, cur_col, start_window ;
- MENU *menu_ptr ;
- int *i_ptr ;
-
- if ( ! is_window_ref( window_ref ) )
- {
- u4error( E_WINDOW_REF, "(calc_lotus)", (char *) 0 ) ;
- return ;
- }
-
- start_window = w4select( window_ref ) ;
-
- v4window_ptr->start_row = start_row ;
- v4window_ptr->start_col = start_col ;
- v4window_ptr->return_start = 0 ;
- v4window_ptr->return_end = 0 ;
- #ifdef UNIX
- v4window_ptr->up_key = CTRL_Q ;
- #else
- v4window_ptr->up_key = ESC ;
- #endif
- v4window_ptr->exit_key = '/' ;
-
- cur_col = 0 ;
-
- for( menu_on= v4window_ptr->first_menu; menu_on >= 0; menu_on = menu_ptr->next)
- {
- menu_ptr = v4menu + menu_on ;
-
- menu_ptr->row = 0 ;
- menu_ptr->col = cur_col ;
-
- if ( u4ptr_equal( (void *) menu_ptr->reaction, (void *) n4sub_menu) ||
- u4ptr_equal( (void *) menu_ptr->action, (void *) n4sub_menu))
- {
- i_ptr = (int *) menu_ptr->ptr_data ;
- calc_lotus( *i_ptr, start_row, start_col ) ;
- }
-
- cur_col += (int) strlen( menu_ptr->item_ptr ) + 3 ;
- }
-
- v4window_ptr->height = 1 ;
- v4window_ptr->width = v4screen_width - start_col ;
-
- w4popup() ;
- n4horizontal() ;
-
- w4select( start_window ) ;
- }
-
-
- void n4message( char *message_ptr )
- {
- MENU *menu_ptr ;
-
- if ( v4window_ptr->last_menu < 0 ) return ;
- menu_ptr = v4menu + v4window_ptr->last_menu ;
- menu_ptr->message = message_ptr ;
- }
-
-
- void n4action( ACTION *action )
- {
- if ( v4window_ptr->last_menu < 0 ) return ;
- v4menu[v4window_ptr->last_menu].action = action ;
- }
-
-
- void n4reaction( ACTION *action )
- {
- if ( v4window_ptr->last_menu < 0 ) return ;
- v4menu[v4window_ptr->last_menu].reaction = action ;
- }
-
- /* Makes a Pull Down Menu out of the Currently Selected Menu */
- void n4pulldown( int w_ref )
- {
- int menu_on, cur_col, old_window_ref ;
- MENU *menu_ptr ;
- int *i_ptr ;
-
- if ( ! is_window_ref( w_ref ) )
- {
- u4error( E_WINDOW_REF, "(n4pulldown)", (char *) 0 ) ;
- return ;
- }
-
- old_window_ref = v4cur_window ;
- w4select( w_ref ) ;
-
- if ( v4window_ptr->start_row < 0 ) v4window_ptr->start_row = 0 ;
- if ( v4window_ptr->start_col < 0 ) v4window_ptr->start_col = 0 ;
-
- cur_col = 1 ;
-
- for (menu_on= v4window_ptr->first_menu; menu_on>= 0; menu_on= menu_ptr->next)
- {
- menu_ptr = v4menu + menu_on ;
-
- menu_ptr->row = 0 ;
- menu_ptr->col = cur_col ;
-
- if ( u4ptr_equal( (void *) menu_ptr->reaction, (void *) n4sub_menu) ||
- u4ptr_equal( (void *) menu_ptr->action, (void *) n4sub_menu))
- {
- i_ptr = (int *) menu_ptr->ptr_data ;
-
- n4calc( *i_ptr, v4window_ptr->start_row+1,
- v4window_ptr->start_col+cur_col ) ;
- v4window[*i_ptr].arrow_exit = 1 ;
- }
-
- cur_col += (int) strlen( menu_ptr->item_ptr ) + 3 ;
- }
-
- v4window_ptr->width = cur_col-2 ;
- v4window_ptr->height= 1 ;
- w4popup() ;
- n4horizontal() ;
-
- w4select( old_window_ref ) ;
- }
-
-
- /* Assume not popped up, no border, and (start_row,start_col) is
- the upper left hand corner of the new window.
-
- Calculate the coordinate of the window and underlying windows.
- Assign the border and specify the window to be 'popup'.
- Adjust the (start_row,start_col) if necessary.
- */
-
- void n4calc( int w_ref, int start_row, int start_col )
- {
- int start_ref, on_menu ;
- int max_width, width, num, i ;
- MENU *menu_ptr ;
-
- if ( ! is_window_ref( w_ref ) )
- {
- u4error( E_WINDOW_REF, "(n4calc)", (char *) 0 ) ;
- return ;
- }
-
- start_ref = w4select( w_ref ) ;
-
- if ( v4window_ptr->title != (char *) 0 )
- max_width = (int) strlen( v4window_ptr->title ) -2 ;
- else
- max_width = 0 ;
-
- if ( v4window_ptr->border_chars == (char *) 0 )
- w4border( SINGLE, F_WHITE ) ;
-
- num = 0 ;
-
- for (on_menu= v4window_ptr->first_menu; on_menu>= 0; on_menu= menu_ptr->next)
- {
- menu_ptr = v4menu + on_menu ;
- num ++ ;
-
- width = (int) strlen( menu_ptr->item_ptr ) ;
- if ( width > max_width ) max_width = width ;
-
- menu_ptr->row = -1 ;
- menu_ptr->col = -1 ;
- }
-
- max_width += 2 ; /* Two columns for the edges */
- if ( num > v4screen_height -2 - start_row )
- num = v4screen_height -2 - start_row ;
- if ( max_width > v4screen_width -2 ) max_width = v4screen_width -2 ;
-
- v4window_ptr->width = max_width ;
- v4window_ptr->height = num ;
-
- if ( start_col + max_width+2 > v4screen_width )
- start_col = v4screen_width -max_width -2 ;
-
- v4window_ptr->start_row = start_row+1 ;
- v4window_ptr->start_col = start_col+1 ;
-
- i = start_row+1 ;
-
- for (on_menu= v4window_ptr->first_menu; on_menu>= 0; on_menu= menu_ptr->next)
- {
- menu_ptr = v4menu + on_menu ;
- i++ ;
-
- if ( u4ptr_equal( (void *) menu_ptr->reaction, (void *) n4sub_menu) ||
- u4ptr_equal( (void *) menu_ptr->action, (void *) n4sub_menu))
- {
- int *i_ptr ;
- i_ptr = (int *) menu_ptr->ptr_data ;
- n4calc( *i_ptr, i, v4window_ptr->start_col+ 1 ) ;
- }
- }
-
- w4border( v4window_ptr->border_chars, v4window_ptr->border_attribute ) ;
- w4popup() ;
-
- w4select( start_ref ) ;
- }
-
-
- void n4refresh( int w_ref )
- {
- v4window[w_ref].force_refresh = 1 ;
- return ;
- }
-
-
- int n4search( char *ptr )
- {
- int on_menu, len, total_len, i ;
- char *item_ptr ;
-
- /* Len is the number of non-blank characters in 'ptr' */
- len = total_len = (int) strlen(ptr) ;
- len--;
- while ( len >= 0 && ptr[len] == ' ' ) len-- ;
- len++ ;
-
- for( on_menu= v4window_ptr->first_menu; on_menu>= 0; on_menu= v4menu[on_menu].next)
- {
- if ( v4menu[on_menu].skip_over ) continue ;
-
- if ( strncmp( (item_ptr = v4menu[on_menu].item_ptr), ptr, (size_t) len ) == 0 )
- {
- for(i=len;; i++)
- {
- if ( item_ptr[i] == '\000' || i==total_len ) return( on_menu ) ;
- /* If there is another non-blank character, there is no match */
- if ( item_ptr[i] != ' ' ) break ;
- }
- }
- }
-
- return -1 ;
- }
-
-
- int n4skip_over( int item_ref, int flag )
- {
- int rc ;
- if ( item_ref < 0 ) return -1;
-
- rc = v4menu[item_ref].skip_over ;
- v4menu[item_ref].skip_over = flag ;
-
- return rc ;
- }
-
-
- void n4start_item( int start_item_ref )
- {
- v4window[v4menu[start_item_ref].window_ref].start_item = start_item_ref ;
- }
-
- void n4parm( int new_parm_data )
- {
- if ( v4window_ptr->last_menu < 0 ) return ;
- v4menu[v4window_ptr->last_menu].parm_data = new_parm_data ;
- }
-
- void n4ptr_save( void *new_ptr_data )
- {
- if ( v4window_ptr->last_menu < 0 ) return ;
- v4menu[v4window_ptr->last_menu].ptr_data = new_ptr_data ;
- }
-
- void n4int_save( int new_int_data )
- {
- if ( v4window_ptr->last_menu < 0 ) return ;
- v4menu[v4window_ptr->last_menu].int_data = new_int_data ;
- }
-
- void *n4ptr_get( int item_ref )
- {
- return v4menu[item_ref].ptr_data ;
- }
-
- int n4int_get( int item_ref )
- {
- return v4menu[item_ref].int_data ;
- }
-
- int n4sub_menu( int item_ref )
- {
- int *window_ref_ptr ;
- window_ref_ptr = (int *) n4ptr_get( item_ref ) ;
- return n4activate( *window_ref_ptr ) ;
- }
-