void editCB( Widget w, XtPointer client_data, XtPointer call_data) { long action; Time time; Widget widget; XButtonEvent *event; XmPushButtonCallbackStruct *acs; action = (long) client_data; acs = (XmPushButtonCallbackStruct *) call_data; event = (XButtonEvent *) acs->event; time = event->time; widget = get_document_text(w, "editCB"); switch (action) { case EDIT_CUT: XmTextCut(widget, time); break; case EDIT_COPY: XmTextCopy(widget, time); break; case EDIT_PASTE: XmTextPaste(widget); break; case EDIT_DELETE: XmTextRemove(widget); break; case EDIT_CLEAR: edit_clear(widget); break; default: break; } }
void main_loop() { char *cs; int index; int n_match; int scroll = 0; #ifdef USE_XSELECTION cs = check_sel(); #endif if(cs) edit_set_text(cs); n_match = myd_bsearch(myd, edit.text, &index); display(myd, index, n_match, scroll); print_prompt(edit.text, edit.cursor); while(1) { int c; c = term_getch(); if(isprint(c)) { edit_ins_char(c); n_match = myd_bsearch(myd, edit.text, &index); scroll = 0; } else { switch(c) { /* * move cursor */ case 1: /* ^A */ edit_cur_head(); move_cursor(edit.cursor); continue; case 2: /* ^B */ case KEY_LEFT: edit_cur_back(); move_cursor(edit.cursor); continue; case 5: /* ^E */ edit_cur_tail(); move_cursor(edit.cursor); continue; case 6: /* ^F */ case KEY_RIGHT: edit_cur_forward(); move_cursor(edit.cursor); continue; /* * scroll */ case 16: /* ^P */ case KEY_PPAGE: case KEY_UP: if(scroll == 0) continue; scroll -= SCROLL_STEP; if(scroll < 0) scroll = 0; break; case 14: /* ^N */ case KEY_NPAGE: case KEY_DOWN: if(scroll == n_match - 1) continue; scroll += SCROLL_STEP; if(scroll >= n_match) scroll = n_match - 1; break; /* * delete text */ case 8: /* ^H */ edit_back_space(); n_match = myd_bsearch(myd, edit.text, &index); scroll = 0; break; case 4: /* ^D */ case 0x7f: edit_del_char(); n_match = myd_bsearch(myd, edit.text, &index); scroll = 0; break; case 21: /* ^U */ case 10: /* ^J */ case 13: /* ^M */ edit_clear(); n_match = myd_bsearch(myd, edit.text, &index); scroll = 0; break; case 11: /* ^K */ edit_kill(); n_match = myd_bsearch(myd, edit.text, &index); scroll = 0; break; case 20: /* ^T */ edit_transpose(); n_match = myd_bsearch(myd, edit.text, &index); scroll = 0; break; case 12: /* ^L */ break; /* Exit */ case 24: /* ^X */ return; case ERR: /* timeout */ #ifdef USE_XSELECTION cs = check_sel(); #endif if(cs) { edit_set_text(cs); n_match = myd_bsearch(myd, edit.text, &index); scroll = 0; break; } else continue; default: break; } } display(myd, index, n_match, scroll); print_prompt(edit.text, edit.cursor); } }