/*** Remove the char under the cursor ***/ void del(Project p, BYTE word) { if(p->nbc < p->edited->size) { ULONG nbc = word ? forward_word(p->edited,p->nbc)-1 : p->nbc; rem_chars(&p->undo, p->edited, p->nbc, nbc); REDRAW_CURLINE(p); inv_curs(p, TRUE); } else if(p->edited->next) { /* Join current and next line: */ if( join_lines(&p->undo, p->edited, p->edited->next) ) { REDRAW_CURLINE(p); /* Is it needed to scroll display? */ if(p->ycurs < gui.botcurs) scroll_up(p,p->edited->next,p->ycurs,p->left_pos); /* Redraw the cursor: */ inv_curs(p,TRUE); p->max_lines--; prop_adj(p); } else ThrowError(Wnd, ErrMsg(ERR_NOMEM)); } }
/*** One pos right ***/ void curs_right(Project p, BYTE word) { if(p->nbc < p->edited->size) { inv_curs(p,FALSE); if(word) p->nbc = forward_word(p->edited, p->nbc); else p->nbc++; p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc); p->xcurs = (p->nbrc-p->left_pos) * XSIZE + gui.left; /* Move the cursor */ /* Is it gone outside edit area? */ if(p->nbrc>=p->left_pos+gui.nbcol) scroll_xy(p, adjust_leftpos(p, gui.xstep), p->top_line, FALSE); if(p->ccp.select) move_selection(p, p->nbrc, p->nbl); inv_curs(p,TRUE); draw_info( p ); } else if(p->edited->next) { /* jump down to next line */ p->nbrwc = 0; curs_down(p); } }
bool TextWidget::on_key_event(const KeyEvent *event) { if (!_text_interaction_on) return false; if (_on_key_event(this, event)) { // user ate this event return true; } if (event->action == KeyActionUp) return false; int start, end; get_cursor_slice(start, end); switch (event->virt_key) { case VirtKeyLeft: if (key_mod_ctrl(event->modifiers) && key_mod_shift(event->modifiers)) { int new_end = backward_word(); set_selection(_cursor_start, new_end); } else if (key_mod_ctrl(event->modifiers)) { int new_start = backward_word(); set_selection(new_start, new_start); } else if (key_mod_shift(event->modifiers)) { set_selection(_cursor_start, _cursor_end - 1); } else { if (start == end) { set_selection(start - 1, start - 1); } else { set_selection(start, start); } } return true; case VirtKeyRight: if (key_mod_ctrl(event->modifiers) && key_mod_shift(event->modifiers)) { int new_end = forward_word(); set_selection(_cursor_start, new_end); } else if (key_mod_ctrl(event->modifiers)) { int new_start = forward_word(); set_selection(new_start, new_start); } else if (key_mod_shift(event->modifiers)) { set_selection(_cursor_start, _cursor_end + 1); } else { if (start == end) { set_selection(start + 1, end + 1); } else { set_selection(end, end); } } return true; case VirtKeyBackspace: if (start == end) { if (key_mod_ctrl(event->modifiers)) { int new_start = backward_word(); replace_text(new_start, start, "", 0); } else { replace_text(start - 1, end, "", 0); } } else { replace_text(start, end, "", 0); } return true; case VirtKeyDelete: if (start == end) { if (key_mod_ctrl(event->modifiers)) { int new_start = forward_word(); replace_text(start, new_start, "", 0); } else { replace_text(start, end + 1, "", 0); } } else { replace_text(start, end, "", 0); } return true; case VirtKeyHome: if (key_mod_shift(event->modifiers)) { set_selection(_cursor_start, 0); } else { set_selection(0, 0); } return true; case VirtKeyEnd: if (key_mod_shift(event->modifiers)) { set_selection(_cursor_start, _label.text().length()); } else { set_selection(_label.text().length(), _label.text().length()); } return true; case VirtKeyA: if (key_mod_only_ctrl(event->modifiers)) { select_all(); return true; } case VirtKeyX: if (key_mod_only_ctrl(event->modifiers)) { cut(); return true; } case VirtKeyC: if (key_mod_only_ctrl(event->modifiers)) { copy(); return true; } case VirtKeyV: if (key_mod_only_ctrl(event->modifiers)) { paste(); return true; } default: // do nothing return true; } }
/*** Mark: stream selection ***/ BYTE move_stream_selection(Project p, LONG xn, LONG yn) { LONG yline; /* Nb. of line marked */ LINE *ln; /* Running pointer */ BYTE ret; /* Autoscroll ? */ WORD y; /* VPos of item sel */ /* Vertical autoscroll ? */ ret = (yn<p->top_line ? 2 : (yn>=(LONG)(p->top_line+gui.nbline) ? 1 : 0)); if(yn<0) yn=0; if(yn>=p->max_lines) yn=p->max_lines-1,ret=0; yline=p->ccp.yc; ln=p->ccp.cline; /* top_line may changed */ y=(yline-p->top_line)*YSIZE+gui.topcurs; /* If new selection point is situated after the prece- ** ** eding one (ie:looking afterward in linked list) */ if( yn>yline || (yn==yline && xn>p->ccp.xp) ) for(; yline<yn; yline++, ln=ln->next, y+=YSIZE) { if(ln->flags && yline<=p->ccp.yp) if(yline == p->ccp.yp ) p->ccp.startsel = (p->ccp.select != WORD_TYPE ? p->ccp.xp : x2pos(ln, backward_word(ln, find_nbc(ln,p->ccp.xp)))), ln->flags = (p->ccp.select == LINE_TYPE ? WHOLESEL : FIRSTSEL); else ln->flags=0; else ln->flags=WHOLESEL; if(gui.topcurs <= y && y <= gui.botcurs) Move(RP, gui.left, y),write_text(p,ln); } else /* New selection point is before the previous */ for(; yline>yn; yline--, ln=ln->prev, y-=YSIZE) { if(ln->flags && yline>=p->ccp.yp) if(yline == p->ccp.yp) p->ccp.endsel = (p->ccp.select != WORD_TYPE ? p->ccp.xp : x2pos(ln, forward_word(ln, find_nbc(ln,p->ccp.xp)))), ln->flags = (p->ccp.select == LINE_TYPE ? WHOLESEL : LASTSEL); else ln->flags=0; else ln->flags=WHOLESEL; if(gui.topcurs <= y && y <= gui.botcurs) Move(RP, gui.left, y),write_text(p,ln); } /* Current point will be the previous */ p->ccp.cline=ln; p->ccp.yc=yn; p->ccp.xc=xn; /* Update last-selected line */ { register UBYTE Set = 0; if(p->ccp.select != LINE_TYPE) if(yn == p->ccp.yp) { ln->flags = FIRSTSEL | LASTSEL; if(xn < p->ccp.xp) p->ccp.startsel=xn, p->ccp.endsel=p->ccp.xp; else p->ccp.startsel=p->ccp.xp, p->ccp.endsel=xn; Set = 3; } else if( yn > p->ccp.yp ) ln->flags=LASTSEL, p->ccp.endsel=xn, Set = 2; else ln->flags=FIRSTSEL,p->ccp.startsel=xn, Set = 1; else ln->flags = WHOLESEL; /* Adjust selection for word selection */ if(p->ccp.select == WORD_TYPE) { if(Set & 1) p->ccp.startsel = x2pos(ln, backward_word(ln, find_nbc(ln,p->ccp.startsel))); if(Set & 2) p->ccp.endsel = x2pos(ln, forward_word (ln, find_nbc(ln,p->ccp.endsel))); } } /* Last line can overlap edit area */ if(gui.topcurs<=y && y<=gui.botcurs) Move(RP, gui.left, y),write_text(p,ln); return ret; }