home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
fed0217s.zip
/
source
/
editline.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-12-13
|
5KB
|
197 lines
/*
** Module :EDITLINE.CPP
** Abstract :Editable character string implementation
**
** Copyright (C) Sergey I. Yevtushenko
**
** Log: Mon 16/06/1997 Created
*/
#include <string.h>
#include <dialog.h>
#include <keynames.h>
#include <version.h>
EditLine::EditLine(int Row, int Col, int nRows, int nCols):
Control(Row, Col, nRows, nCols)
{
pal_start = CL_EDITLINE_INACTIVE;
add_line(new Line);
set_hiliting(0);
};
int EditLine::select(int i)
{
pal_start = (i) ? CL_EDITLINE_ACTIVE : CL_EDITLINE_INACTIVE;
return Control::select(i);
}
void EditLine::get_text(char *buff, int max_len)
{
PLine ln = line(0);
int len = ln->len();
if(len > max_len)
len = max_len;
if(len)
memcpy(buff, ln->str, len);
buff[len] = 0;
}
void EditLine::set_text(char *str)
{
PLine ln = line(0);
ln->set(str);
line_begin(*this);
mark();
line_end(*this);
}
void EditLine::draw()
{
Buffer::draw(*this);
if(active)
{
vio_cursor_pos(row+get_cur_row(), col+get_cur_col());
vio_cursor_type((get_ins_mode()) ? Underline:BigCursor);
}
}
void EditLine::do_key(KeyInfo& k)
{
// track_beg();
if(k.skey & shIsCtrl)
{
switch(k.skey & 0x00FF)
{
case kbLeft:
if(k.skey & shShift)
mark();
else
unmark();
if(k.skey & shCtrl)
word_left(*this);
else
cursor_left(*this);
break;
case kbRight:
if(k.skey & shShift)
mark();
else
unmark();
if(k.skey & shCtrl)
word_right(*this);
else
cursor_right(*this);
break;
case kbIns:
if(k.skey & shCtrl) /* Ctlr+Ins */
{
if(Clipboard)
delete Clipboard;
Clipboard = copy();
break;
}
if(k.skey & shShift) /* Shift+Ins*/
{
if(get_mark_state())
{
clear(*this);
unmark();
}
paste(*this, Clipboard);
break;
}
set_ins_mode(1 - get_ins_mode());
break;
case kbBksp:
if(k.skey & shAlt)
{
undo(*this);
break;
}
if(k.skey & shCtrl)
{
del_word_left(*this);
break;
}
back_space(*this);
break;
case kbEnd:
if(k.skey & shShift)
mark();
else
unmark();
line_end(*this);
break;
case kbDel:
if(k.skey & shShift)
{
if(Clipboard)
delete Clipboard;
Clipboard = cut(*this);
}
else
{
if(get_mark_state())
clear(*this);
else
del_char(*this);
}
unmark();
break;
case kbHome:
if(k.skey & shShift)
mark();
else
unmark();
line_begin(*this);
break;
case kbT:
if(k.skey & shCtrl)
{
del_word_right(*this);
}
break;
case kbL:
case kbU:
if(k.skey & shAlt)
{
if((k.skey & 0xFF) == kbL)
tolower(*this);
else
toupper(*this);
}
break;
default:
track_cancel();
}
if(abs_row() != 0)
goto_line(*this, 0);
}
else
{
if(get_mark_state())
clear(*this);
if(get_ins_mode())
ins_char(*this, k.key);
else
replace_char(*this, k.key);
}
track_end();
}