2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* flineedit.cpp - Widget FLineEdit *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-04-19 01:55:17 +02:00
|
|
|
* Copyright 2012-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
|
|
|
#include "final/flineedit.h"
|
|
|
|
#include "final/fstatusbar.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FLineEdit
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FLineEdit::FLineEdit(FWidget* parent)
|
|
|
|
: FWidget(parent)
|
2018-12-03 03:22:36 +01:00
|
|
|
, label{new FLabel("", parent)}
|
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)
|
2018-12-03 03:22:36 +01:00
|
|
|
, label{new FLabel("", parent)}
|
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 )
|
2018-05-20 15:15:42 +02:00
|
|
|
setInsertCursor();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 07:22:08 +02:00
|
|
|
// FLineEdit operators
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator = (const FString& s)
|
|
|
|
{
|
|
|
|
setText(s);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const FString& s)
|
|
|
|
{
|
|
|
|
setText(text + s);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-06 02:28:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (fc::SpecialCharacter c)
|
|
|
|
{
|
|
|
|
setText(text + static_cast<wchar_t>(c));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-09-21 07:22:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const wchar_t c)
|
|
|
|
{
|
|
|
|
setText(text + c);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const uInt num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const int num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const uLong num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const long num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const float num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const double num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLineEdit& FLineEdit::operator << (const lDouble num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
const FLineEdit& FLineEdit::operator >> (FString& s)
|
|
|
|
{
|
|
|
|
s += text;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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-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
|
|
|
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
|
|
|
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
|
2018-05-06 21:41:55 +02:00
|
|
|
&& getEncoding() != fc::VT100
|
|
|
|
&& getEncoding() != fc::ASCII )
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
flags.shadow = true;
|
2018-11-20 21:11:04 +01:00
|
|
|
setShadowSize(1, 1);
|
2017-01-26 00:31:07 +01:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
flags.shadow = false;
|
2018-11-20 21:11:04 +01:00
|
|
|
setShadowSize(0, 0);
|
2017-01-26 00:31:07 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
return flags.shadow;
|
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()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t s, size;
|
2018-11-13 02:51:41 +01:00
|
|
|
FColor fg, bg;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto 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;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( size == 0 )
|
2016-09-25 23:53:48 +02:00
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto blank = createBlankArray(size + 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
for (std::size_t y = 0; y < getHeight() + s; y++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
setPrintPos (1, 1 + int(y));
|
2015-05-23 13:35:12 +02:00
|
|
|
print (blank);
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
destroyBlankArray(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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-21 07:22:08 +02:00
|
|
|
void FLineEdit::clear()
|
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
|
|
|
{
|
2018-11-21 20:07:08 +01:00
|
|
|
FKey key = ev->key();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
switch ( key )
|
|
|
|
{
|
|
|
|
case fc::Fkey_left:
|
2017-12-27 01:38:28 +01:00
|
|
|
keyLeft();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
2017-12-27 01:38:28 +01:00
|
|
|
keyRight();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
2017-12-27 01:38:28 +01:00
|
|
|
keyHome();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
2017-12-27 01:38:28 +01:00
|
|
|
keyEnd();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
case fc::Fkey_dc: // del key
|
2017-12-27 01:38:28 +01:00
|
|
|
keyDel();
|
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:
|
2017-12-27 01:38:28 +01:00
|
|
|
keyBackspace();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
case fc::Fkey_ic: // insert key
|
2017-12-27 01:38:28 +01:00
|
|
|
keyInsert();
|
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:
|
2017-12-27 01:38:28 +01:00
|
|
|
keyEnter();
|
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:
|
2017-12-27 01:38:28 +01:00
|
|
|
if ( keyInput(key) )
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
// end of switch
|
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->isAccepted()
|
2017-11-26 22:37:18 +01:00
|
|
|
&& 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() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
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
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
std::size_t len = text.getLength();
|
|
|
|
cursor_pos = text_offset + std::size_t(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
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
std::size_t len;
|
|
|
|
int mouse_x, mouse_y;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
len = 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
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
cursor_pos = text_offset + std::size_t(mouse_x) - 2;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cursor_pos >= len )
|
2017-10-02 07:32:33 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( mouse_x >= int(getWidth()) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
// drag right
|
2018-10-17 22:12:52 +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
|
|
|
|
2018-10-17 22:12:52 +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*)
|
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
std::size_t len = text.getLength();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
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:
|
2017-10-06 12:19:39 +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
|
|
|
|
2018-10-22 01:26:24 +02:00
|
|
|
text_offset--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-02 22:46:01 +02:00
|
|
|
if ( cursor_pos > 0 )
|
|
|
|
cursor_pos--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FLineEdit::scrollRight:
|
2018-12-03 03:22:36 +01:00
|
|
|
if ( len < getWidth() - 2
|
|
|
|
|| 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
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( text_offset <= len - getWidth() + 1 )
|
2018-09-02 22:46:01 +02:00
|
|
|
text_offset++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-02 22:46:01 +02:00
|
|
|
if ( cursor_pos < len )
|
|
|
|
cursor_pos++;
|
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
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = static_cast<FWidget*>(ev->focusedWidget());
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-06-14 01:23:10 +02:00
|
|
|
if ( focused_widget && focused_widget->isWidget() )
|
2017-06-11 17:47:50 +02:00
|
|
|
{
|
|
|
|
setFocus();
|
2017-06-14 01:23:10 +02:00
|
|
|
focused_widget->redraw();
|
2017-06-11 17:47:50 +02:00
|
|
|
redraw();
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
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 )
|
2018-05-20 15:15:42 +02:00
|
|
|
setInsertCursor();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::onFocusIn (FFocusEvent*)
|
|
|
|
{
|
|
|
|
if ( insert_mode )
|
2018-05-20 15:15:42 +02:00
|
|
|
setInsertCursor();
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2018-05-20 15:15:42 +02:00
|
|
|
unsetInsertCursor();
|
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 )
|
2018-05-20 15:15:42 +02:00
|
|
|
setInsertCursor();
|
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
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t label_length = label_text.getLength();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( hasHotkey() )
|
|
|
|
label_length--;
|
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
assert ( label_orientation == label_above
|
2017-11-26 22:37:18 +01:00
|
|
|
|| label_orientation == label_left );
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
switch ( label_orientation )
|
|
|
|
{
|
|
|
|
case label_above:
|
2017-08-27 09:50:30 +02:00
|
|
|
label->setGeometry(getX(), getY() - 1, label_length, 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case label_left:
|
2018-11-20 21:11:04 +01:00
|
|
|
label->setGeometry(getX() - int(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 ( isEnabled() )
|
|
|
|
{
|
|
|
|
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
|
|
|
drawInputField();
|
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( flags.focus && getStatusBar() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
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()
|
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
std::size_t x;
|
2016-11-02 00:37:58 +01:00
|
|
|
FString show_text;
|
2018-11-04 23:00:06 +01:00
|
|
|
bool isActiveFocus = flags.active && flags.focus;
|
2016-11-02 00:37:58 +01:00
|
|
|
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();
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
show_text = text.mid(1 + text_offset, getWidth() - 2);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-04-19 01:55:17 +02:00
|
|
|
if ( isLinuxTerm() && hasUTF8() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
setUTF8(true);
|
|
|
|
|
|
|
|
if ( show_text )
|
|
|
|
print (show_text);
|
|
|
|
|
|
|
|
setUTF8(false);
|
|
|
|
}
|
|
|
|
else if ( show_text )
|
|
|
|
print (show_text);
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
x = show_text.getLength();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
while ( x < getWidth() - 1 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
print (' ');
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isActiveFocus && getMaxColor() < 16 )
|
|
|
|
unsetBold();
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
{
|
|
|
|
setReverse(false);
|
|
|
|
setUnderline(false);
|
|
|
|
}
|
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( flags.shadow )
|
2016-11-02 00:37:58 +01:00
|
|
|
drawShadow ();
|
|
|
|
|
|
|
|
// set the cursor to the first pos.
|
2018-10-17 22:12:52 +02:00
|
|
|
setCursorPos (int(2 + cursor_pos - text_offset), 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2017-12-27 01:38:28 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyLeft()
|
|
|
|
{
|
2018-09-02 22:46:01 +02:00
|
|
|
if ( cursor_pos > 0 )
|
|
|
|
cursor_pos--;
|
2017-12-27 01:38:28 +01:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( cursor_pos < text_offset )
|
2017-12-27 01:38:28 +01:00
|
|
|
text_offset--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyRight()
|
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
std::size_t len = text.getLength();
|
2017-12-27 01:38:28 +01:00
|
|
|
|
2018-09-02 22:46:01 +02:00
|
|
|
if ( cursor_pos < len )
|
|
|
|
cursor_pos++;
|
2017-12-27 01:38:28 +01:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( cursor_pos - text_offset >= getWidth() - 2
|
|
|
|
&& text_offset <= len - getWidth() + 1 )
|
2017-12-27 01:38:28 +01:00
|
|
|
text_offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyHome()
|
|
|
|
{
|
|
|
|
cursor_pos = 0;
|
|
|
|
text_offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyEnd()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t len = text.getLength();
|
2018-10-17 22:12:52 +02:00
|
|
|
cursor_pos = len;
|
2017-12-27 01:38:28 +01:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( cursor_pos >= getWidth() - 1 )
|
2017-12-27 01:38:28 +01:00
|
|
|
text_offset = len - getWidth() + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyDel()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t len = text.getLength();
|
2017-12-27 01:38:28 +01:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( len > 0 && cursor_pos < len )
|
2017-12-27 01:38:28 +01:00
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
text.remove(cursor_pos, 1);
|
2017-12-27 01:38:28 +01:00
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( cursor_pos >= len )
|
|
|
|
cursor_pos = len;
|
2017-12-27 01:38:28 +01:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( text_offset > 0 && len - text_offset < getWidth() - 1 )
|
2017-12-27 01:38:28 +01:00
|
|
|
text_offset--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyBackspace()
|
|
|
|
{
|
|
|
|
if ( text.getLength() > 0 && cursor_pos > 0 )
|
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
text.remove(cursor_pos - 1, 1);
|
2017-12-27 01:38:28 +01:00
|
|
|
processChanged();
|
|
|
|
cursor_pos--;
|
|
|
|
|
|
|
|
if ( text_offset > 0 )
|
|
|
|
text_offset--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyInsert()
|
|
|
|
{
|
2018-11-20 21:11:04 +01:00
|
|
|
insert_mode = ! insert_mode;
|
2017-12-27 01:38:28 +01:00
|
|
|
|
|
|
|
if ( insert_mode )
|
2018-05-20 15:15:42 +02:00
|
|
|
setInsertCursor();
|
2017-12-27 01:38:28 +01:00
|
|
|
else
|
2018-05-20 15:15:42 +02:00
|
|
|
unsetInsertCursor();
|
2017-12-27 01:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLineEdit::keyEnter()
|
|
|
|
{
|
|
|
|
processActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-21 20:07:08 +01:00
|
|
|
inline bool FLineEdit::keyInput (FKey key)
|
2017-12-27 01:38:28 +01:00
|
|
|
{
|
|
|
|
if ( key >= 0x20 && key <= 0x10fff )
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t len = text.getLength();
|
2017-12-27 01:38:28 +01:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( cursor_pos == len )
|
2017-12-27 01:38:28 +01:00
|
|
|
{
|
|
|
|
text += wchar_t(key);
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
else if ( len > 0 )
|
|
|
|
{
|
|
|
|
if ( insert_mode )
|
2018-10-17 22:12:52 +02:00
|
|
|
text.insert(wchar_t(key), cursor_pos);
|
2017-12-27 01:38:28 +01:00
|
|
|
else
|
2018-10-17 22:12:52 +02:00
|
|
|
text.overwrite(wchar_t(key), cursor_pos);
|
2017-12-27 01:38:28 +01:00
|
|
|
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text = wchar_t(key);
|
|
|
|
processChanged();
|
|
|
|
}
|
2018-10-17 22:12:52 +02:00
|
|
|
|
2017-12-27 01:38:28 +01:00
|
|
|
cursor_pos++;
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
if ( cursor_pos >= getWidth() - 1 )
|
2017-12-27 01:38:28 +01:00
|
|
|
text_offset++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::processActivate()
|
|
|
|
{
|
|
|
|
if ( ! hasFocus() )
|
|
|
|
{
|
|
|
|
setFocus();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
emitCallback("activate");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLineEdit::processChanged()
|
|
|
|
{
|
|
|
|
emitCallback("changed");
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|