示例#1
0
static void print_field( VSCREEN *vs, VFIELD *field, unsigned current )
{
    SAREA               *area;
    char                *str;
    ATTR                attr;
    ATTR                hotattr;
    char                ctrlbuf[CTRL_BUF_LEN+1];
    unsigned            length = 0;
    a_check             *check = NULL;
    a_radio             *radio = NULL;
    a_list              *list;
    a_combo_box         *combo;
    a_hot_spot          *hotspot;
    an_edit_control     *edit;
    VSCREEN             *c_vs;
    SAREA               c_area;
    bool                use_hottext;
    char                hotkey;

    if( field == NULL ) return;
    area = &field->area;
    str = NULL;
    use_hottext = FALSE;
    memset( ctrlbuf, '\0', CTRL_BUF_LEN+1 );

    attr = UIData->attrs[ current ? ATTR_CURR_EDIT : ATTR_EDIT ];

    switch( field->typ ) {
    case FLD_HOT :
        hotspot = field->ptr;
        if( current ) {
            hotspot->flags |= HOT_CURRENT ;
        } else {
            hotspot->flags &= (~HOT_CURRENT);
        }
        hotspot->flags |= uihotspot( vs, hotspot->str,
                            &field->area, hotspot->flags );
        return;                     // don't want to print anything
    case FLD_TEXT :
        attr = UIData->attrs[ ATTR_NORMAL ];
        str  = field->ptr;
        break;
    case FLD_LABEL :
        attr = UIData->attrs[ ATTR_NORMAL ];
        strcpy( ctrlbuf, (char *)field->ptr );
        strcat( ctrlbuf, ":" );
        length = area->width;
        break;
    case FLD_FRAME :
        uidrawbox( vs, area, UIData->attrs[ ATTR_NORMAL ], field->ptr );
        return;
    case FLD_EDIT :
    case FLD_INVISIBLE_EDIT :
        edit = field->ptr;
        if( edit->buffer != NULL ) {
            length = edit->length;
            if( length > CTRL_BUF_LEN )
                length = CTRL_BUF_LEN;
            if( length > area->width ) {
                length = area->width;
            }
            if( field->typ == FLD_INVISIBLE_EDIT ) {
                memset( ctrlbuf, '*', length );
            } else {
                strncpy( ctrlbuf, edit->buffer, length );
            }
        } else {
            length = 0;
        }
        break;
    case FLD_COMBOBOX :
        combo = field->ptr;
        edit  = &combo->edit;
        list  = &combo->list;

        if( combo->perm == FALSE ) {
            ctrlbuf[0] = UiGChar[ UI_ARROW_DOWN ];  /* JBS was 25 */
            uivtextput( vs, area->row, area->col + area->width + 1,
                        UIData->attrs[ ATTR_SCROLL_ICON ], ctrlbuf, 1 );
            ctrlbuf[0] = '\0';
        }
        if( edit->buffer != NULL ) {
            length = edit->length;
            if( length > CTRL_BUF_LEN )
                length = CTRL_BUF_LEN;
            strncpy( ctrlbuf, edit->buffer, length );
        } else {
            length = 0;
        }
        if( list->get == NULL ) {
            list->get = ( bool (*) ( void *, unsigned, char *, unsigned ) )
                            uigetlistelement;
        }
        if( list->box == NULL  &&  combo->perm == TRUE ) {
            c_area = *area;
            c_area.row += vs->area.row + 2;
            c_area.col += vs->area.col + 1;
            c_vs = uiopen( &c_area, NULL, V_DIALOGUE | V_LISTBOX );
            if( c_vs == NULL ) {
                break;
            }
            c_area.row = 0;
            c_area.col = 0;
            list->box = uibeglistbox( c_vs, &c_area, list );
        }
        break;
    case FLD_PULLDOWN :
        list = field->ptr;
        ctrlbuf[0] = UiGChar[ UI_ARROW_DOWN ];  /* JBS was 25 */
        uivtextput( vs, area->row, area->col + area->width,
                    UIData->attrs[ ATTR_SCROLL_ICON ], ctrlbuf, 1 );
        ctrlbuf[0] = '\0';
        if( list->get == NULL ) {
            list->get = ( bool (*) ( void *, unsigned, char *, unsigned ) )
                                uigetlistelement;
        }
        (*list->get)( list->data, list->choice, ctrlbuf, area->width );
        length = area->width;
        break;
    case FLD_LISTBOX:
    case FLD_EDIT_MLE:
        list = field->ptr;
        if( list->box == NULL ) {
            c_area = *area;
            c_area.row += ((VSCREEN *)vs)->area.row;
            c_area.col += ((VSCREEN *)vs)->area.col;
            c_vs = uiopen( &c_area, NULL, V_DIALOGUE | V_LISTBOX );
            if( c_vs == NULL ) {
                break;
            }
            c_area.row = 0;
            c_area.col = 0;
            list->box = uibeglistbox( c_vs, &c_area, list );
        }
        return;
    case FLD_CHECK:
        attr = UIData->attrs[ current ? ATTR_CURR_EDIT : ATTR_NORMAL ];
        check = field->ptr;

        ctrlbuf[0] = UiGChar[ UI_CHECKBOX_LEFT ];
        if( _checked( check ) ) {
            ctrlbuf[1] = UiGChar[ UI_CHECKBOX_FULL ];
        } else {
            ctrlbuf[1] = UiGChar[ UI_CHECKBOX_EMPTY ];
        }
        ctrlbuf[2] = UiGChar[ UI_CHECKBOX_RIGHT ];
        ctrlbuf[3] = ' ';

        strncat( ctrlbuf, check->str, CTRL_BUF_LEN - 4 );
        length = strlen( ctrlbuf );
        use_hottext = TRUE;
        break;
    case FLD_RADIO:
        attr = UIData->attrs[ current ? ATTR_CURR_EDIT : ATTR_NORMAL ];
        radio = field->ptr;

        ctrlbuf[0] = UiGChar[ UI_RADIO_LEFT ];
        if( radio->value == radio->group->value ) {
            ctrlbuf[1] = UiGChar[ UI_RADIO_FULL ];
        } else {
            ctrlbuf[1] = UiGChar[ UI_RADIO_EMPTY ];
        }
        ctrlbuf[2] = UiGChar[ UI_RADIO_RIGHT ];
        ctrlbuf[3] = ' ';

        strncat( ctrlbuf, radio->str, CTRL_BUF_LEN - 4 );
        length = strlen( ctrlbuf );
        use_hottext = TRUE;
        break;
    }
    if( str != NULL ) {
        uivtextput( vs, area->row, area->col, attr, str, area->width );
    } else if( use_hottext ) {
        if( current ) {
            hotattr = attr;
        } else {
            hotattr = UIData->attrs[ ATTR_RADIO_HOTSPOT ];
        }
        hotkey = uidrawhottext( vs, ctrlbuf, area, attr, hotattr, FALSE, FALSE, FALSE );
        if( field->typ == FLD_CHECK ) {
            check->hotkey = hotkey;
        } else if( field->typ == FLD_RADIO ) {
            radio->hotkey = hotkey;
        }
    } else {
        uitextfield( vs, area->row, area->col, area->width, attr,
                     ctrlbuf, length );
    }
}
示例#2
0
static void print_field( VSCREEN *vs, VFIELD *field, bool current )
{
    SAREA               *area;
    ATTR                attr;
    ATTR                hotattr;
    char                ctrlbuf[CTRL_BUF_LEN + 1];
    unsigned            ctrlbuf_len = 0;
    a_check             *check = NULL;
    a_radio             *radio = NULL;
    a_list              *list;
    a_combo_box         *combo;
    an_edit_control     *edit;
    VSCREEN             *c_vs;
    SAREA               c_area;
    bool                use_hottext;
    char                hotkey;
    UIPICKGETTEXT       *fn_get;

    if( field == NULL )
        return;
    area = &field->area;
    use_hottext = false;
    memset( ctrlbuf, '\0', CTRL_BUF_LEN + 1 );

    attr = UIData->attrs[( current ) ? ATTR_CURR_EDIT : ATTR_EDIT];

    switch( field->typ ) {
    case FLD_HOT :
        if( current ) {
            field->u.hs->flags |= HOT_CURRENT ;
        } else {
            field->u.hs->flags &= (~HOT_CURRENT);
        }
        uidisplayhotspot( vs, field );
        return;
    case FLD_TEXT :
        attr = UIData->attrs[ATTR_NORMAL];
        uivtextput( vs, area->row, area->col, attr, field->u.str, area->width );
        uirefresh();
        return;
    case FLD_LABEL :
        attr = UIData->attrs[ATTR_NORMAL];
        strcpy( ctrlbuf, field->u.str );
        strcat( ctrlbuf, ":" );
        ctrlbuf_len = strlen( ctrlbuf );
        break;
    case FLD_FRAME :
        uidrawbox( vs, area, UIData->attrs[ATTR_NORMAL], field->u.str );
        return;
    case FLD_EDIT :
    case FLD_INVISIBLE_EDIT :
        edit = field->u.edit;
        if( edit->buffer != NULL ) {
            ctrlbuf_len = edit->length;
            if( ctrlbuf_len > CTRL_BUF_LEN )
                ctrlbuf_len = CTRL_BUF_LEN;
            if( field->typ == FLD_INVISIBLE_EDIT ) {
                memset( ctrlbuf, '*', ctrlbuf_len );
            } else {
                strncpy( ctrlbuf, edit->buffer, ctrlbuf_len );
            }
        } else {
            ctrlbuf_len = 0;
        }
        break;
    case FLD_COMBOBOX :
        combo = field->u.combo;
        edit  = &combo->edit;
        list  = &combo->list;

        if( !combo->perm ) {
            ctrlbuf[0] = UiGChar[UI_ARROW_DOWN];
            uivtextput( vs, area->row, area->col + area->width + 1,
                        UIData->attrs[ATTR_SCROLL_ICON], ctrlbuf, 1 );
            ctrlbuf[0] = '\0';
        }
        if( edit->buffer != NULL ) {
            ctrlbuf_len = edit->length;
            if( ctrlbuf_len > CTRL_BUF_LEN )
                ctrlbuf_len = CTRL_BUF_LEN;
            strncpy( ctrlbuf, edit->buffer, ctrlbuf_len );
        } else {
            ctrlbuf_len = 0;
        }
        if( list->box == NULL && combo->perm ) {
            c_area = *area;
            c_area.row += vs->area.row + 2;
            c_area.col += vs->area.col + 1;
            c_vs = uiopen( &c_area, NULL, V_DIALOGUE | V_LISTBOX );
            if( c_vs == NULL ) {
                break;
            }
            c_area.row = 0;
            c_area.col = 0;
            list->box = uibeglistbox( c_vs, &c_area, list );
        }
        break;
    case FLD_PULLDOWN :
        list = field->u.list;
        ctrlbuf[0] = UiGChar[UI_ARROW_DOWN];
        uivtextput( vs, area->row, area->col + area->width,
                    UIData->attrs[ATTR_SCROLL_ICON], ctrlbuf, 1 );
        ctrlbuf[0] = '\0';
        fn_get = list->get;
        if( fn_get == NULL )
            fn_get = uigetlistelement;
        (*fn_get)( list->data_handle, list->choice, ctrlbuf, CTRL_BUF_LEN );
        /* ctrlbuf does not have to be null terminated */
        /* terminate it at maximum length */
        ctrlbuf[CTRL_BUF_LEN] = '\0';
        ctrlbuf_len = strlen( ctrlbuf );
        break;
    case FLD_LISTBOX:
    case FLD_EDIT_MLE:
        list = field->u.list;
        if( list->box == NULL ) {
            c_area = *area;
            c_area.row += ((VSCREEN *)vs)->area.row;
            c_area.col += ((VSCREEN *)vs)->area.col;
            c_vs = uiopen( &c_area, NULL, V_DIALOGUE | V_LISTBOX );
            if( c_vs == NULL ) {
                break;
            }
            c_area.row = 0;
            c_area.col = 0;
            list->box = uibeglistbox( c_vs, &c_area, list );
        }
        return;
    case FLD_CHECK:
        /* ctrlbuf must be null terminated for this case */
        use_hottext = true;
        attr = UIData->attrs[( current ) ? ATTR_CURR_EDIT : ATTR_NORMAL];
        check = field->u.check;

        ctrlbuf[0] = CHECKBOX_CHAR( LEFT );
        if( _checked( check ) ) {
            ctrlbuf[1] = CHECKBOX_CHAR( FULL );
        } else {
            ctrlbuf[1] = CHECKBOX_CHAR( EMPTY );
        }
        ctrlbuf[2] = CHECKBOX_CHAR( RIGHT );
        ctrlbuf[3] = ' ';

        strncat( ctrlbuf, check->str, CTRL_BUF_LEN - 4 );
        break;
    case FLD_RADIO:
        /* ctrlbuf must be null terminated for this case */
        use_hottext = true;
        attr = UIData->attrs[( current ) ? ATTR_CURR_EDIT : ATTR_NORMAL];
        radio = field->u.radio;

        ctrlbuf[0] = RADIO_CHAR( LEFT );
        if( radio->value == radio->group->value ) {
            ctrlbuf[1] = RADIO_CHAR( FULL );
        } else {
            ctrlbuf[1] = RADIO_CHAR( EMPTY );
        }
        ctrlbuf[2] = RADIO_CHAR( RIGHT );
        ctrlbuf[3] = ' ';

        strncat( ctrlbuf, radio->str, CTRL_BUF_LEN - 4 );
        break;
    }
    if( use_hottext ) {
        if( current ) {
            hotattr = attr;
        } else {
            hotattr = UIData->attrs[ATTR_RADIO_HOTSPOT];
        }
        hotkey = uidrawhottext( vs, ctrlbuf, area, attr, hotattr, false, false, false );
        if( field->typ == FLD_CHECK ) {
            check->hotkey = hotkey;
        } else if( field->typ == FLD_RADIO ) {
            radio->hotkey = hotkey;
        }
    } else {
        uitextfield( vs, area->row, area->col, area->width, attr, ctrlbuf, ctrlbuf_len );
    }
}