2015-09-25 21:37:19 +02:00
|
|
|
// File: flineedit.cpp
|
|
|
|
// Provides: class FLineEdit
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#include "fapp.h"
|
|
|
|
#include "flineedit.h"
|
|
|
|
#include "fstatusbar.h"
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FLineEdit
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FLineEdit::FLineEdit(FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text("")
|
|
|
|
, label_text("")
|
|
|
|
, label(new FLabel("", parent))
|
2016-11-02 00:37:58 +01:00
|
|
|
, label_orientation(FLineEdit::label_left)
|
2016-09-27 00:46:05 +02:00
|
|
|
, drag_scroll(FLineEdit::noScroll)
|
|
|
|
, scroll_timer(false)
|
|
|
|
, scroll_repeat(100)
|
2015-09-22 04:18:20 +02:00
|
|
|
, insert_mode(true)
|
|
|
|
, cursor_pos(0)
|
2016-09-25 23:53:48 +02:00
|
|
|
, text_offset(0)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FLineEdit::FLineEdit (const FString& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, label_text("")
|
|
|
|
, label(new FLabel("", parent))
|
2016-11-02 00:37:58 +01:00
|
|
|
, label_orientation(FLineEdit::label_left)
|
2016-09-27 00:46:05 +02:00
|
|
|
, drag_scroll(FLineEdit::noScroll)
|
|
|
|
, scroll_timer(false)
|
|
|
|
, scroll_repeat(100)
|
2015-09-22 04:18:20 +02:00
|
|
|
, insert_mode(true)
|
|
|
|
, cursor_pos(0)
|
2016-09-25 23:53:48 +02:00
|
|
|
, text_offset(0)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
setText(txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit::~FLineEdit() // destructor
|
|
|
|
{
|
|
|
|
if ( ! insert_mode )
|
2017-04-05 22:25:20 +02:00
|
|
|
setInsertCursorStyle();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// public methods of FLineEdit
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FLineEdit::setEnable (bool on)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::setEnable(on);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( on )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-01-24 14:53:09 +01:00
|
|
|
flags |= fc::active;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( hasFocus() )
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
setForegroundColor (wc.inputfield_active_focus_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_active_focus_bg);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
setForegroundColor (wc.inputfield_active_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_active_bg);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags &= ~fc::active;
|
2016-09-25 23:53:48 +02:00
|
|
|
setForegroundColor (wc.inputfield_inactive_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_inactive_bg);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return on;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FLineEdit::setFocus (bool on)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::setFocus(on);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( on )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags |= fc::focus;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
setForegroundColor (wc.inputfield_active_focus_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_active_focus_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
2017-03-26 20:40:04 +02:00
|
|
|
const FString& msg = getStatusbarMessage();
|
|
|
|
const FString& curMsg = getStatusBar()->getMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( curMsg != msg )
|
|
|
|
getStatusBar()->setMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags &= ~fc::focus;
|
2015-10-23 23:57:00 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
|
|
|
{
|
|
|
|
setForegroundColor (wc.inputfield_active_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_active_bg);
|
2015-10-23 23:57:00 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
}
|
2015-10-11 21:56:16 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return on;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FLineEdit::setShadow (bool on)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( on
|
2017-04-05 00:30:52 +02:00
|
|
|
&& Encoding != fc::VT100
|
2016-12-18 23:34:11 +01:00
|
|
|
&& Encoding != fc::ASCII )
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags |= fc::shadow;
|
2017-01-26 00:31:07 +01:00
|
|
|
setShadowSize(1,1);
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags &= ~fc::shadow;
|
2017-01-26 00:31:07 +01:00
|
|
|
setShadowSize(0,0);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return on;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-26 20:40:04 +02:00
|
|
|
void FLineEdit::setText (const FString& txt)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
text_offset = 0;
|
|
|
|
cursor_pos = 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( txt )
|
|
|
|
text = txt;
|
|
|
|
else
|
|
|
|
text = "";
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-26 20:40:04 +02:00
|
|
|
void FLineEdit::setLabelText (const FString& ltxt)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
label_text = ltxt;
|
|
|
|
label->setText(label_text);
|
|
|
|
adjustLabel();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-17 22:59:06 +01:00
|
|
|
void FLineEdit::setLabelOrientation(const label_o o)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
label_orientation = o;
|
2015-05-23 13:35:12 +02:00
|
|
|
adjustLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::hide()
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
int s, size;
|
2016-01-08 01:00:05 +01:00
|
|
|
short fg, bg;
|
2015-05-23 13:35:12 +02:00
|
|
|
char* blank;
|
2016-08-21 21:27:44 +02:00
|
|
|
FWidget* parent_widget = getParentWidget();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
FWidget::hide();
|
2016-08-21 21:27:44 +02:00
|
|
|
|
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
fg = parent_widget->getForegroundColor();
|
|
|
|
bg = parent_widget->getBackgroundColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fg = wc.dialog_fg;
|
|
|
|
bg = wc.dialog_bg;
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
setColor (fg, bg);
|
|
|
|
s = hasShadow() ? 1 : 0;
|
2016-09-25 23:53:48 +02:00
|
|
|
size = getWidth() + s;
|
|
|
|
|
|
|
|
if ( size < 0 )
|
|
|
|
return;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
blank = new char[size+1];
|
2016-10-06 23:15:09 +02:00
|
|
|
std::memset(blank, ' ', uLong(size));
|
2015-05-23 13:35:12 +02:00
|
|
|
blank[size] = '\0';
|
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
for (int y=0; y < getHeight()+s; y++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (1, 1+y);
|
2015-05-23 13:35:12 +02:00
|
|
|
print (blank);
|
|
|
|
}
|
|
|
|
|
2016-07-09 00:01:59 +02:00
|
|
|
delete[] blank;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( label )
|
|
|
|
label->hide();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FLineEdit::clearText()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
text_offset = 0;
|
|
|
|
cursor_pos = 0;
|
|
|
|
text.clear();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FLineEdit::onKeyPress (FKeyEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
int len = int(text.getLength());
|
2015-09-20 05:44:50 +02:00
|
|
|
int key = ev->key();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
switch ( key )
|
|
|
|
{
|
|
|
|
case fc::Fkey_left:
|
|
|
|
cursor_pos--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos < 0 )
|
|
|
|
cursor_pos=0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( cursor_pos < text_offset )
|
|
|
|
text_offset--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
|
|
|
cursor_pos++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos >= len )
|
|
|
|
cursor_pos=len;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( cursor_pos-text_offset >= getWidth()-2 && text_offset <= len-getWidth()+1 )
|
|
|
|
text_offset++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
|
|
|
cursor_pos=0;
|
2016-09-25 23:53:48 +02:00
|
|
|
text_offset=0;
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
|
|
|
cursor_pos=len;
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( cursor_pos >= getWidth()-1 )
|
|
|
|
text_offset=len-getWidth()+2;
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_dc: // del key
|
|
|
|
if ( len > 0 && cursor_pos < len )
|
|
|
|
{
|
|
|
|
text.remove(uInt(cursor_pos), 1);
|
|
|
|
processChanged();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos >= len )
|
|
|
|
cursor_pos=len;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos < 0 )
|
|
|
|
cursor_pos=0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset > 0 && len-text_offset < getWidth()-1 )
|
|
|
|
text_offset--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_erase:
|
|
|
|
case fc::Fkey_backspace:
|
|
|
|
if ( len > 0 && cursor_pos > 0 )
|
|
|
|
{
|
|
|
|
text.remove(uInt(cursor_pos-1), 1);
|
|
|
|
processChanged();
|
|
|
|
cursor_pos--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset > 0 )
|
|
|
|
text_offset--;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_ic: // insert key
|
|
|
|
insert_mode = not insert_mode;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( insert_mode )
|
2017-04-05 22:25:20 +02:00
|
|
|
setInsertCursorStyle();
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2017-04-05 22:25:20 +02:00
|
|
|
unsetInsertCursorStyle();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_return:
|
|
|
|
case fc::Fkey_enter:
|
|
|
|
processActivate();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_tab:
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->ignore();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if ( key >= 0x20 && key <= 0x10fff )
|
|
|
|
{
|
|
|
|
if ( cursor_pos == len )
|
|
|
|
{
|
|
|
|
text += wchar_t(key);
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
else if ( len > 0 )
|
|
|
|
{
|
|
|
|
if ( insert_mode )
|
|
|
|
text.insert(wchar_t(key), uInt(cursor_pos));
|
|
|
|
else
|
|
|
|
text.overwrite(wchar_t(key), uInt(cursor_pos));
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text = wchar_t(key);
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
cursor_pos++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( cursor_pos >= getWidth()-1 )
|
|
|
|
text_offset++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->ignore();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
// end of switch
|
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->isAccepted()
|
|
|
|
&& key != fc::Fkey_return
|
|
|
|
&& key != fc::Fkey_enter )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
drawInputField();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FLineEdit::onMouseDown (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
int mouse_x, mouse_y;
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! hasFocus() )
|
|
|
|
{
|
|
|
|
FWidget* focused_widget = getFocusWidget();
|
2016-01-17 02:57:08 +01:00
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
2015-05-23 13:35:12 +02:00
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
2015-09-22 04:18:20 +02:00
|
|
|
setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-22 04:18:20 +02:00
|
|
|
redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
mouse_x = ev->getX();
|
|
|
|
mouse_y = ev->getY();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( mouse_x >= 2 && mouse_x <= getWidth() && mouse_y == 1 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
int len = int(text.getLength());
|
2016-09-25 23:53:48 +02:00
|
|
|
cursor_pos = text_offset + mouse_x - 2;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos >= len )
|
|
|
|
cursor_pos = len;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
drawInputField();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::onMouseUp (FMouseEvent*)
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( drag_scroll != FLineEdit::noScroll )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-12-19 20:49:01 +01:00
|
|
|
delOwnTimer();
|
2016-09-27 00:46:05 +02:00
|
|
|
drag_scroll = FLineEdit::noScroll;
|
|
|
|
scroll_timer = false;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FLineEdit::onMouseMove (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
int len, mouse_x, mouse_y;
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
len = int(text.getLength());
|
2015-09-20 05:44:50 +02:00
|
|
|
mouse_x = ev->getX();
|
|
|
|
mouse_y = ev->getY();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( mouse_x >= 2 && mouse_x <= getWidth() && mouse_y == 1 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
cursor_pos = text_offset + mouse_x - 2;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos >= len )
|
|
|
|
cursor_pos=len;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
drawInputField();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// auto-scrolling when dragging mouse outside the widget
|
|
|
|
if ( mouse_x < 2 )
|
|
|
|
{
|
|
|
|
// drag left
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( ! scroll_timer && text_offset > 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
scroll_timer = true;
|
|
|
|
addTimer(scroll_repeat);
|
|
|
|
drag_scroll = FLineEdit::scrollLeft;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset == 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-12-19 20:49:01 +01:00
|
|
|
delOwnTimer();
|
2016-09-27 00:46:05 +02:00
|
|
|
drag_scroll = FLineEdit::noScroll;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-25 23:53:48 +02:00
|
|
|
else if ( mouse_x >= getWidth() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
// drag right
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( ! scroll_timer && text_offset <= len-getWidth()+1 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
scroll_timer = true;
|
|
|
|
addTimer(scroll_repeat);
|
|
|
|
drag_scroll = FLineEdit::scrollRight;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset == len-getWidth()+2 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-12-19 20:49:01 +01:00
|
|
|
delOwnTimer();
|
2016-09-27 00:46:05 +02:00
|
|
|
drag_scroll = FLineEdit::noScroll;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no dragging
|
2015-12-19 20:49:01 +01:00
|
|
|
delOwnTimer();
|
2016-09-27 00:46:05 +02:00
|
|
|
scroll_timer = false;
|
|
|
|
drag_scroll = FLineEdit::noScroll;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::onTimer (FTimerEvent*)
|
|
|
|
{
|
|
|
|
int len = int(text.getLength());
|
|
|
|
|
2016-09-29 04:29:12 +02:00
|
|
|
switch ( int(drag_scroll) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
case FLineEdit::noScroll:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case FLineEdit::scrollLeft:
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset == 0)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
drag_scroll = FLineEdit::noScroll;
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
text_offset--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset < 0 )
|
|
|
|
text_offset = 0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
cursor_pos--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos < 0 )
|
|
|
|
cursor_pos = 0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FLineEdit::scrollRight:
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset == len-getWidth()+2 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
drag_scroll = FLineEdit::noScroll;
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
text_offset++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( text_offset > len-getWidth()+2 )
|
|
|
|
text_offset = len-getWidth()+2;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
cursor_pos++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos > len )
|
|
|
|
cursor_pos = len;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2016-09-29 04:29:12 +02:00
|
|
|
break;
|
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
drawInputField();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FLineEdit::onAccel (FAccelEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! isEnabled() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! hasFocus() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
|
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
|
|
|
setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2016-10-17 08:44:38 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
getStatusBar()->drawMessage();
|
2016-10-17 08:44:38 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
|
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::onHide (FHideEvent*)
|
|
|
|
{
|
|
|
|
if ( ! insert_mode )
|
2017-04-05 22:25:20 +02:00
|
|
|
setInsertCursorStyle();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::onFocusIn (FFocusEvent*)
|
|
|
|
{
|
|
|
|
if ( insert_mode )
|
2017-04-05 22:25:20 +02:00
|
|
|
setInsertCursorStyle();
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2017-04-05 22:25:20 +02:00
|
|
|
unsetInsertCursorStyle();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
getStatusBar()->drawMessage();
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::onFocusOut (FFocusEvent*)
|
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
getStatusBar()->drawMessage();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! insert_mode )
|
2017-04-05 22:25:20 +02:00
|
|
|
setInsertCursorStyle();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// protected methods of FListBox
|
2015-11-29 15:58:36 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FLineEdit::adjustLabel()
|
2015-11-29 15:58:36 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
int label_length = int(label_text.getLength());
|
|
|
|
|
|
|
|
if ( hasHotkey() )
|
|
|
|
label_length--;
|
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
assert ( label_orientation == label_above
|
|
|
|
|| label_orientation == label_left );
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
switch ( label_orientation )
|
|
|
|
{
|
|
|
|
case label_above:
|
|
|
|
label->setGeometry(getX(), getY()-1, label_length, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case label_left:
|
2016-11-13 22:08:40 +01:00
|
|
|
label->setGeometry(getX()-label_length-1, getY(), label_length, 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-11-29 15:58:36 +01:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FLineEdit::adjustSize()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::adjustSize();
|
|
|
|
adjustLabel();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// private methods of FLineEdit
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::init()
|
|
|
|
{
|
|
|
|
label->setAccelWidget(this);
|
|
|
|
setVisibleCursor();
|
|
|
|
setShadow();
|
|
|
|
|
|
|
|
if ( hasFocus() )
|
|
|
|
flags |= fc::focus;
|
|
|
|
|
|
|
|
if ( isEnabled() )
|
|
|
|
{
|
|
|
|
flags |= fc::active;
|
|
|
|
|
|
|
|
if ( hasFocus() )
|
|
|
|
{
|
|
|
|
setForegroundColor (wc.inputfield_active_focus_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_active_focus_bg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setForegroundColor (wc.inputfield_active_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_active_bg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // inactive
|
|
|
|
{
|
|
|
|
setForegroundColor (wc.inputfield_inactive_fg);
|
|
|
|
setBackgroundColor (wc.inputfield_inactive_bg);
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FLineEdit::hasHotkey()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( label_text.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return label_text.includes('&');
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FLineEdit::draw()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
bool isFocus;
|
|
|
|
drawInputField();
|
|
|
|
isFocus = ((flags & fc::focus) != 0);
|
|
|
|
|
|
|
|
if ( isFocus && getStatusBar() )
|
|
|
|
{
|
2017-03-26 20:40:04 +02:00
|
|
|
const FString& msg = getStatusbarMessage();
|
|
|
|
const FString& curMsg = getStatusBar()->getMessage();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( curMsg != msg )
|
|
|
|
{
|
|
|
|
getStatusBar()->setMessage(msg);
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::drawInputField()
|
|
|
|
{
|
2016-11-13 22:08:40 +01:00
|
|
|
bool isActiveFocus, isShadow;
|
2016-11-02 00:37:58 +01:00
|
|
|
int x;
|
|
|
|
FString show_text;
|
|
|
|
int active_focus = fc::active + fc::focus;
|
|
|
|
isActiveFocus = ((flags & active_focus) == active_focus);
|
|
|
|
isShadow = ((flags & fc::shadow) != 0 );
|
|
|
|
setPrintPos (1, 1);
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
{
|
|
|
|
setReverse(true);
|
|
|
|
print (' ');
|
|
|
|
|
|
|
|
if ( isActiveFocus )
|
|
|
|
setReverse(false);
|
|
|
|
else
|
|
|
|
setUnderline(true);
|
|
|
|
}
|
2016-11-13 22:08:40 +01:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2016-11-13 22:08:40 +01:00
|
|
|
setColor();
|
|
|
|
print (' ');
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isActiveFocus && getMaxColor() < 16 )
|
|
|
|
setBold();
|
|
|
|
|
|
|
|
show_text = text.mid(uInt(1+text_offset), uInt(getWidth()-2));
|
|
|
|
|
|
|
|
if ( isUTF8_linux_terminal() )
|
|
|
|
{
|
|
|
|
setUTF8(true);
|
|
|
|
|
|
|
|
if ( show_text )
|
|
|
|
print (show_text);
|
|
|
|
|
|
|
|
setUTF8(false);
|
|
|
|
}
|
|
|
|
else if ( show_text )
|
|
|
|
print (show_text);
|
|
|
|
|
|
|
|
x = int(show_text.getLength());
|
|
|
|
|
|
|
|
while ( x < getWidth()-1 )
|
|
|
|
{
|
|
|
|
print (' ');
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isActiveFocus && getMaxColor() < 16 )
|
|
|
|
unsetBold();
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
{
|
|
|
|
setReverse(false);
|
|
|
|
setUnderline(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isShadow )
|
|
|
|
drawShadow ();
|
|
|
|
|
|
|
|
// set the cursor to the first pos.
|
|
|
|
setCursorPos (2+cursor_pos-text_offset, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::processActivate()
|
|
|
|
{
|
|
|
|
if ( ! hasFocus() )
|
|
|
|
{
|
|
|
|
setFocus();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
emitCallback("activate");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::processChanged()
|
|
|
|
{
|
|
|
|
emitCallback("changed");
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|