EVENT uihotkeyfilter( a_dialog *ui_dlg_info, EVENT ev ) { char ch, hotkey; VFIELD *vf; /* is the event a key press or alt-key press */ if( ev < 0x100 && isalpha( ev ) ) { ch = tolower( ev ); } else { ch = uialtchar( ev ); } if( ch ) { hotkey = '\0'; for( vf = ui_dlg_info->fields ; vf->typ != FLD_VOID; ++vf ){ switch( vf->typ ) { case FLD_HOT: hotkey = vf->u.hs->flags; break; case FLD_CHECK: hotkey = vf->u.check->hotkey; break; case FLD_RADIO: hotkey = vf->u.radio->hotkey; break; default: hotkey = '\0'; break; } if( hotkey == ch ) { break; } } /* make sure the new field is hilighted */ if( ui_dlg_info->curr != vf && vf->typ != FLD_VOID ) { uidialogsetcurr( ui_dlg_info, vf ); } if( hotkey == ch ) { switch( vf->typ ) { case FLD_HOT: ev = vf->u.hs->event; break; case FLD_CHECK: ui_dlg_info->dirty = TRUE; vf->u.check->val = !vf->u.check->val; print_field( ui_dlg_info->vs, vf, TRUE ); ev = EV_CHECK_BOX_CLICK; break; case FLD_RADIO: do_radio( ui_dlg_info, vf ); ev = EV_CHECK_BOX_CLICK; break; } } } return( ev ); }
ui_event uihotkeyfilter( a_dialog *ui_dlg_info, ui_event ui_ev ) { char ch, hotkey; VFIELD *fields; /* is the event a key press or alt-key press */ if( iseditchar( ui_ev ) && isalpha( (unsigned char)ui_ev ) ) { ch = tolower( (unsigned char)ui_ev ); } else { ch = uialtchar( ui_ev ); } if( ch ) { hotkey = '\0'; for( fields = ui_dlg_info->fields; fields->typ != FLD_NONE; fields++ ) { switch( fields->typ ) { case FLD_HOT: hotkey = fields->u.hs->flags; break; case FLD_CHECK: hotkey = fields->u.check->hotkey; break; case FLD_RADIO: hotkey = fields->u.radio->hotkey; break; default: hotkey = '\0'; break; } if( hotkey == ch ) { break; } } /* make sure the new field is hilighted */ if( ui_dlg_info->curr != fields && fields->typ != FLD_NONE ) { uidialogsetcurr( ui_dlg_info, fields ); } if( hotkey == ch ) { switch( fields->typ ) { case FLD_HOT: ui_ev = fields->u.hs->event; break; case FLD_CHECK: ui_dlg_info->dirty = true; fields->u.check->val = !fields->u.check->val; print_field( ui_dlg_info->vs, fields, true ); ui_ev = EV_CHECK_BOX_CLICK; break; case FLD_RADIO: do_radio( ui_dlg_info, fields ); ui_ev = EV_CHECK_BOX_CLICK; break; } } } return( ui_ev ); }
static EVENT uitabkey( EVENT ev, a_dialog *info ) { VFIELD *curr, *fld; ORD row, col; SAREA area; EVENT newev; if( info->first == NULL ) return( FALSE ); curr = info->curr; newev = ev; switch( ev ){ case EV_MOUSE_DCLICK: case EV_MOUSE_PRESS: { a_combo_box *combo; a_list *list; VSCREEN *mousevs; mousevs = uivmousepos( info->vs, &row, &col ); fld = info->first; while( fld != NULL ) { list = NULL; area = fld->area; if( fld->typ == FLD_PULLDOWN ) { list = fld->ptr; area.height = 1; area.width += 1; /* pulldown button */ } else if( fld->typ == FLD_LISTBOX ) { list = fld->ptr; } else if( fld->typ == FLD_EDIT_MLE ) { list = fld->ptr; } else if( fld->typ == FLD_COMBOBOX ) { area.height = 1; area.width += 2; /* pulldown button */ combo = fld->ptr; list = &combo->list; } if( mousevs != info->vs ) { if( list != NULL && list->box != NULL ) { if( list->box->vs == mousevs ) { break; } } } else if( row >= area.row && row < area.row + area.height && col >= area.col && col < area.col + area.width ) { break; } fld = nextfield( fld ); } /* check boxes don't get mouse events unless mouse over them */ if( fld == NULL && curr != NULL && curr->typ == FLD_CHECK ) { newev = EV_NO_EVENT; } else { curr = fld; } break; } case EV_TAB_FORWARD : curr = forwardtab( info ); break; case EV_TAB_BACKWARD : curr = backwardtab( info ); break; case EV_CURSOR_RIGHT : case EV_CURSOR_DOWN : { a_radio *r1, *r2; if( curr!= NULL && curr->typ == FLD_RADIO ) { fld = nextfield( curr ); if( fld != NULL ) { r1 = curr->ptr; r2 = fld->ptr; if( r1->group == r2->group ) { curr = fld; do_radio( info, fld ); newev = EV_CHECK_BOX_CLICK; } } } break; } case EV_CURSOR_LEFT : case EV_CURSOR_UP : { a_radio *r1, *r2; if( curr!= NULL && curr->typ == FLD_RADIO ) { if( curr != info->first ) { fld = curr - 1; r1 = curr->ptr; r2 = fld->ptr; if( r1->group == r2->group ) { curr = fld; do_radio( info, fld ); newev = EV_CHECK_BOX_CLICK; } } } break; } } if( info->curr != curr ) { uidialogsetcurr( info, curr ); } return( newev ); }
bool GUIXCreateDialog( gui_create_info *dlg_info, gui_window *wnd, int num_controls, gui_control_info *controls_info, bool sys, long dlg_id ) { EVENT ev; int i; a_dialog *ui_dlg_info; VFIELD *fields; char *title; VFIELD *focus; int size; bool colours_set; bool ok; if( dlg_id != -1 ) { if( !GUICreateDialogFromRes( dlg_id, dlg_info->parent, dlg_info->call_back, dlg_info->extra ) ) { return( false ); } GUIMemFree( wnd ); return( true ); } sys = sys; RadioGroup = NULL; Group = false; fields = NULL; title = NULL; ui_dlg_info = NULL; colours_set = false; wnd->flags |= DIALOG; if( !GUISetupStruct( wnd, dlg_info, true ) ) { return( false ); } size = ( num_controls + 1 ) * sizeof( VFIELD ); fields = (VFIELD *)GUIMemAlloc( size ); if( fields == NULL ) { return( false ); } memset( fields, 0, size ); focus = NULL; for( i = 0; i < num_controls; i++ ) { uiyield(); if( !GUIDoAddControl( &controls_info[i], wnd, &fields[i] ) ) { GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true ); return( false ); } else { if( ( focus == NULL ) && ( controls_info[i].style & GUI_FOCUS ) ) { focus = &fields[i]; } } } CleanUpRadioGroups(); fields[num_controls].typ = FLD_VOID; /* mark end of list */ title = GUIStrDup( dlg_info->title, &ok ); if( !ok ) { GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true ); return( false ); } colours_set = GUISetDialColours(); ui_dlg_info = uibegdialog( title, fields, wnd->screen.area.height, wnd->screen.area.width, wnd->screen.area.row, wnd->screen.area.col ); if( ui_dlg_info == NULL ) { GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true ); return( false ); } if( focus != NULL ) { uidialogsetcurr( ui_dlg_info, focus ); } if( !InsertDialog( wnd, ui_dlg_info, num_controls, title, colours_set ) ) { GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true ); return( false ); } for( i = 0; i < num_controls; i++ ) { uiyield(); GUIInsertControl( wnd, &controls_info[i], i ); } GUIEVENTWND( wnd, GUI_INIT_DIALOG, NULL ); uipushlist( NULL ); uipushlist( GUIUserEvents ); GUIPushControlEvents(); uipushlist( DlgEvents ); while( ( GetDialog( ui_dlg_info ) != NULL ) ) { ev = uidialog( ui_dlg_info ); switch( ev ) { case EV_KILL_UI: uiforceevadd( EV_KILL_UI ); case EV_ESCAPE: GUIEVENTWND( wnd, GUI_DIALOG_ESCAPE, NULL ); GUICloseDialog( wnd ); break; default : GUIProcessControlNotify( ev, ui_dlg_info, wnd ); } } return( true ); }