helvie@silverwood.EBay.Sun.COM (Fred Helvie) (05/08/91)
Creating a floating point field in devguide or XView can be done by identifying a callback on the text item. Follows is a code example for a floating point text item. You need to add more checking to limit the number of digits on each side of the decimal. Fred Helvie Sun Education - Milpitas, CA - USA ------- cut here ------- /* */ /* XView program demonstrating floating point text item */ /* */ #include <stdio.h> #include <xview/xview.h> #include <xview/panel.h> main(argc,argv) int argc; char *argv[]; { Frame frame; Panel panel; Panel_item text_1; Panel_setting text_notify_proc(); xv_init(XV_INIT_ARGS, argc,argv, 0); frame = xv_create( XV_NULL, FRAME_BASE, FRAME_LABEL, "Floating Point Text Item", FRAME_SHOW_FOOTER, TRUE, 0); panel = xv_create( frame, PANEL, PANEL_LAYOUT, PANEL_VERTICAL, 0); text_1 = xv_create( panel, PANEL_TEXT, PANEL_LABEL_STRING, "Float: ", PANEL_NOTIFY_PROC, text_notify_proc, PANEL_NOTIFY_LEVEL, PANEL_ALL, PANEL_VALUE_DISPLAY_LENGTH, 24, PANEL_VALUE_STORED_LENGTH, 24, 0); window_fit(panel); window_fit(frame); xv_main_loop(frame); exit( 0 ); } Panel_setting text_notify_proc( item, event ) Panel_item item; Event *event; { switch(event_action(event)) { case '.': if (strchr(panel_get_value(item), '.')) return(PANEL_NONE); else return(PANEL_INSERT); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ACTION_ERASE_CHAR_BACKWARD: return(PANEL_INSERT); break; case '\t': case '\r': case '\n': if (event_is_up(event)) { printf("The value is: %7.2f\n", atof(panel_get_value(item))); return(PANEL_DONE); } default: return(PANEL_NONE); break; } }