kopia lustrzana https://github.com/jamescoxon/dl-fldigi
Modify FText add() methods
Use efficient versions of add() for all FText derived classes except FTextRX (which receives text one character at a time anyway). This greatly reduces the Event log window's draw overhead.pull/2/head
rodzic
92a8fd6746
commit
d2df10a5fc
|
@ -36,6 +36,13 @@ public:
|
|||
|
||||
virtual int handle(int event);
|
||||
|
||||
virtual void add(unsigned char c, int attr = RECV);
|
||||
virtual void add(const char *s, int attr = RECV)
|
||||
{
|
||||
while (*s)
|
||||
add(*s++, attr);
|
||||
}
|
||||
|
||||
void set_quick_entry(bool b);
|
||||
bool get_quick_entry(void) { return quick_entry; }
|
||||
void mark(FTextBase::TEXT_ATTR attr = CLICK_START);
|
||||
|
|
|
@ -48,8 +48,8 @@ public:
|
|||
FTextBase(int x, int y, int w, int h, const char *l = 0);
|
||||
virtual ~FTextBase() { delete tbuf; delete sbuf; }
|
||||
|
||||
virtual void add(const char *text, int attr = RECV) = 0;
|
||||
virtual void add(unsigned char c, int attr = RECV) = 0;
|
||||
virtual void add(const char *text, int attr = RECV);
|
||||
virtual void add(unsigned char c, int attr = RECV);
|
||||
void addstr(const char *text, int attr = RECV) { add(text, attr); }
|
||||
void addchr(unsigned char c, int attr = RECV) { add(c, attr); }
|
||||
|
||||
|
@ -117,12 +117,6 @@ public:
|
|||
~FTextView() { }
|
||||
|
||||
virtual int handle(int event);
|
||||
virtual void add(unsigned char c, int attr = RECV);
|
||||
virtual void add(const char *s, int attr = RECV)
|
||||
{
|
||||
while (*s)
|
||||
add(*s++, attr);
|
||||
}
|
||||
|
||||
protected:
|
||||
enum {
|
||||
|
@ -156,9 +150,6 @@ public:
|
|||
|
||||
virtual int handle(int event);
|
||||
|
||||
virtual void add(const char *s, int attr = RECV);
|
||||
virtual void add(unsigned char c, int attr = RECV);
|
||||
|
||||
protected:
|
||||
enum {
|
||||
EDIT_MENU_CUT, EDIT_MENU_COPY, EDIT_MENU_PASTE, EDIT_MENU_CLEAR,
|
||||
|
|
|
@ -234,6 +234,53 @@ out:
|
|||
return FTextView::handle(event);
|
||||
}
|
||||
|
||||
/// Adds a char to the buffer
|
||||
///
|
||||
/// @param c The character
|
||||
/// @param attr The attribute (@see enum text_attr_e); RECV if omitted.
|
||||
///
|
||||
void FTextRX::add(unsigned char c, int attr)
|
||||
{
|
||||
if (c == '\r')
|
||||
return;
|
||||
|
||||
// The user may have moved the cursor by selecting text or
|
||||
// scrolling. Place it at the end of the buffer.
|
||||
if (mCursorPos != tbuf->length())
|
||||
insert_position(tbuf->length());
|
||||
|
||||
switch (c) {
|
||||
case '\b':
|
||||
// we don't call kf_backspace because it kills selected text
|
||||
tbuf->remove(tbuf->length() - 1, tbuf->length());
|
||||
sbuf->remove(sbuf->length() - 1, sbuf->length());
|
||||
break;
|
||||
case '\n':
|
||||
// maintain the scrollback limit, if we have one
|
||||
if (max_lines > 0 && tbuf->count_lines(0, tbuf->length()) >= max_lines) {
|
||||
int le = tbuf->line_end(0) + 1; // plus 1 for the newline
|
||||
tbuf->remove(0, le);
|
||||
sbuf->remove(0, le);
|
||||
}
|
||||
// fall-through
|
||||
default:
|
||||
char s[] = { '\0', '\0', FTEXT_DEF + attr, '\0' };
|
||||
const char *cp;
|
||||
|
||||
if ((c < ' ' || c == 127) && attr != CTRL) // look it up
|
||||
cp = ascii[(unsigned char)c];
|
||||
else { // insert verbatim
|
||||
s[0] = c;
|
||||
cp = &s[0];
|
||||
}
|
||||
|
||||
for (int i = 0; cp[i]; ++i)
|
||||
sbuf->append(s + 2);
|
||||
insert(cp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FTextRX::set_quick_entry(bool b)
|
||||
{
|
||||
if ((quick_entry = b))
|
||||
|
|
|
@ -97,6 +97,37 @@ int FTextBase::handle(int event)
|
|||
return Fl_Text_Editor_mod::handle(event);
|
||||
}
|
||||
|
||||
/// @see FTextRX::add
|
||||
///
|
||||
/// @param s
|
||||
/// @param attr
|
||||
///
|
||||
void FTextBase::add(const char *s, int attr)
|
||||
{
|
||||
// handle the text attribute first
|
||||
int n = strlen(s);
|
||||
char a[n + 1];
|
||||
memset(a, FTEXT_DEF + attr, n);
|
||||
a[n] = '\0';
|
||||
sbuf->replace(insert_position(), insert_position() + n, a);
|
||||
|
||||
insert(s);
|
||||
}
|
||||
|
||||
/// @see FTextBase::add
|
||||
///
|
||||
/// @param s
|
||||
/// @param attr
|
||||
///
|
||||
void FTextBase::add(unsigned char c, int attr)
|
||||
{
|
||||
char s[] = { FTEXT_DEF + attr, '\0' };
|
||||
sbuf->replace(insert_position(), insert_position() + 1, s);
|
||||
|
||||
s[0] = c;
|
||||
insert(s);
|
||||
}
|
||||
|
||||
void FTextBase::set_word_wrap(bool b)
|
||||
{
|
||||
wrap_mode((wrap = b), wrap_col);
|
||||
|
@ -452,53 +483,6 @@ FTextView::FTextView(int x, int y, int w, int h, const char *l)
|
|||
init_context_menu();
|
||||
}
|
||||
|
||||
/// Adds a char to the buffer
|
||||
///
|
||||
/// @param c The character
|
||||
/// @param attr The attribute (@see enum text_attr_e); RECV if omitted.
|
||||
///
|
||||
void FTextView::add(unsigned char c, int attr)
|
||||
{
|
||||
if (c == '\r')
|
||||
return;
|
||||
|
||||
// The user may have moved the cursor by selecting text or
|
||||
// scrolling. Place it at the end of the buffer.
|
||||
if (mCursorPos != tbuf->length())
|
||||
insert_position(tbuf->length());
|
||||
|
||||
switch (c) {
|
||||
case '\b':
|
||||
// we don't call kf_backspace because it kills selected text
|
||||
tbuf->remove(tbuf->length() - 1, tbuf->length());
|
||||
sbuf->remove(sbuf->length() - 1, sbuf->length());
|
||||
break;
|
||||
case '\n':
|
||||
// maintain the scrollback limit, if we have one
|
||||
if (max_lines > 0 && tbuf->count_lines(0, tbuf->length()) >= max_lines) {
|
||||
int le = tbuf->line_end(0) + 1; // plus 1 for the newline
|
||||
tbuf->remove(0, le);
|
||||
sbuf->remove(0, le);
|
||||
}
|
||||
// fall-through
|
||||
default:
|
||||
char s[] = { '\0', '\0', FTEXT_DEF + attr, '\0' };
|
||||
const char *cp;
|
||||
|
||||
if ((c < ' ' || c == 127) && attr != CTRL) // look it up
|
||||
cp = ascii[(unsigned char)c];
|
||||
else { // insert verbatim
|
||||
s[0] = c;
|
||||
cp = &s[0];
|
||||
}
|
||||
|
||||
for (int i = 0; cp[i]; ++i)
|
||||
sbuf->append(s + 2);
|
||||
insert(cp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles fltk events for this widget.
|
||||
|
||||
/// We only care about mouse presses (to display the popup menu and prevent
|
||||
|
@ -700,37 +684,6 @@ int FTextEdit::handle(int event)
|
|||
return FTextBase::handle(event);
|
||||
}
|
||||
|
||||
/// @see FTextView::add
|
||||
///
|
||||
/// @param s
|
||||
/// @param attr
|
||||
///
|
||||
void FTextEdit::add(const char *s, int attr)
|
||||
{
|
||||
// handle the text attribute first
|
||||
int n = strlen(s);
|
||||
char a[n + 1];
|
||||
memset(a, FTEXT_DEF + attr, n);
|
||||
a[n] = '\0';
|
||||
sbuf->replace(insert_position(), insert_position() + n, a);
|
||||
|
||||
insert(s);
|
||||
}
|
||||
|
||||
/// @see FTextEdit::add
|
||||
///
|
||||
/// @param s
|
||||
/// @param attr
|
||||
///
|
||||
void FTextEdit::add(unsigned char c, int attr)
|
||||
{
|
||||
char s[] = { FTEXT_DEF + attr, '\0' };
|
||||
sbuf->replace(insert_position(), insert_position() + 1, s);
|
||||
|
||||
s[0] = c;
|
||||
insert(s);
|
||||
}
|
||||
|
||||
/// Handles keyboard events to override Fl_Text_Editor_mod's handling of some
|
||||
/// keystrokes.
|
||||
///
|
||||
|
|
Ładowanie…
Reference in New Issue