2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* flistbox.cpp - Widget FListBox and FListBoxItem *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-09-12 22:51:15 +02:00
|
|
|
* Copyright 2014-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-11 03:06:02 +02:00
|
|
|
#include <algorithm>
|
2018-12-28 22:57:43 +01:00
|
|
|
#include <memory>
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
|
|
|
#include "final/flistbox.h"
|
|
|
|
#include "final/fscrollbar.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 FListBoxItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FListBoxItem::FListBoxItem()
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-02-25 15:18:29 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FListBoxItem::FListBoxItem (const FListBoxItem& item)
|
|
|
|
: text(item.text)
|
|
|
|
, data_pointer(item.data_pointer)
|
|
|
|
, brackets(item.brackets)
|
|
|
|
, selected(item.selected)
|
|
|
|
{ }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
FListBoxItem::FListBoxItem (const FString& txt, FDataPtr data)
|
2015-09-22 04:18:20 +02:00
|
|
|
: text(txt)
|
2017-02-24 00:30:07 +01:00
|
|
|
, data_pointer(data)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
FListBoxItem::~FListBoxItem() // destructor
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-02-25 15:18:29 +01:00
|
|
|
// public methods of FListBoxItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FListBoxItem& FListBoxItem::operator = (const FListBoxItem& item)
|
|
|
|
{
|
|
|
|
if ( &item == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text = item.text;
|
|
|
|
data_pointer = item.data_pointer;
|
|
|
|
brackets = item.brackets;
|
|
|
|
selected = item.selected;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-25 15:18:29 +01:00
|
|
|
FListBox::FListBox (FWidget* parent)
|
2015-09-22 04:18:20 +02:00
|
|
|
: FWidget(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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FListBox::~FListBox() // destructor
|
|
|
|
{
|
2015-12-19 20:49:01 +01:00
|
|
|
delOwnTimer();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FListBox
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FListBox::setCurrentItem (std::size_t index)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( index == current )
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
element_count = getCount();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( index > element_count )
|
|
|
|
current = element_count;
|
|
|
|
else if ( index < 1 )
|
|
|
|
current = 1;
|
|
|
|
else
|
|
|
|
current = index;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
xoffset = 0;
|
|
|
|
yoffset = 0;
|
|
|
|
adjustSize();
|
|
|
|
vbar->setValue(yoffset);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isVisible() )
|
|
|
|
redraw();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::setCurrentItem (listBoxItems::iterator iter)
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t index = std::size_t(std::distance(itemlist.begin(), iter)) + 1;
|
2017-04-23 18:54:46 +02:00
|
|
|
setCurrentItem(index);
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FListBox::showInsideBrackets ( std::size_t index
|
2016-11-02 00:37:58 +01:00
|
|
|
, fc::brackets_type b )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = index2iterator(index - 1);
|
2017-04-23 18:54:46 +02:00
|
|
|
iter->brackets = b;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( b == fc::NoBrackets )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
std::size_t len = iter->getText().getLength() + 2;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( len > max_line_width )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
max_line_width = len;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( len >= getWidth() - nf_offset - 3 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-09 18:24:31 +01:00
|
|
|
int hmax = ( max_line_width > getWidth() - nf_offset - 4 )
|
|
|
|
? int(max_line_width - getWidth() + nf_offset + 4)
|
|
|
|
: 0;
|
|
|
|
hbar->setMaximum (hmax);
|
2018-10-20 22:50:35 +02:00
|
|
|
hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4));
|
2016-11-02 00:37:58 +01:00
|
|
|
hbar->setValue (xoffset);
|
|
|
|
|
|
|
|
if ( ! hbar->isVisible() )
|
|
|
|
hbar->setVisible();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 22:57:43 +01:00
|
|
|
void FListBox::setGeometry ( int x, int y
|
|
|
|
, std::size_t w, std::size_t h
|
|
|
|
, bool adjust )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-08-06 17:02:19 +02:00
|
|
|
// Set the widget geometry
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::setGeometry(x, y, w, h, adjust);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isNewFont() )
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setGeometry (int(getWidth()), 2, 2, getHeight() - 2);
|
2018-10-20 22:50:35 +02:00
|
|
|
hbar->setGeometry (1, int(getHeight()), getWidth() - 2 - nf_offset, 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setGeometry (int(getWidth()), 2, 1, getHeight() - 2);
|
|
|
|
hbar->setGeometry (2, int(getHeight()), getWidth() - 2, 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
bool FListBox::setFocus (bool enable)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-12-22 23:50:10 +01:00
|
|
|
FWidget::setFocus(enable);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
if ( enable )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
const auto& msg = getStatusbarMessage();
|
|
|
|
const auto& curMsg = getStatusBar()->getMessage();
|
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
|
|
|
|
{
|
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
}
|
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
return enable;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-26 20:40:04 +02:00
|
|
|
void FListBox::setText (const FString& txt)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
text = txt;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::hide()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t n, size;
|
2018-11-13 02:51:41 +01:00
|
|
|
FColor fg, bg;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto parent_widget = getParentWidget();
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::hide();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
fg = parent_widget->getForegroundColor();
|
|
|
|
bg = parent_widget->getBackgroundColor();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
fg = wc.dialog_fg;
|
|
|
|
bg = wc.dialog_bg;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setColor (fg, bg);
|
|
|
|
n = isNewFont() ? 1 : 0;
|
|
|
|
size = getWidth() + n;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( size == 0 )
|
2015-05-23 13:35:12 +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-14 06:25:33 +02:00
|
|
|
for (int y = 0; y < int(getHeight()); y++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
setPrintPos (1, 1 + y);
|
|
|
|
print (blank);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
destroyBlankArray (blank);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-04-23 18:54:46 +02:00
|
|
|
void FListBox::insert (FListBoxItem listItem)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-10-20 22:50:35 +02:00
|
|
|
std::size_t len = listItem.text.getLength();
|
2017-05-20 22:43:55 +02:00
|
|
|
bool has_brackets = bool(listItem.brackets);
|
2017-07-03 16:56:32 +02:00
|
|
|
recalculateHorizontalBar (len, has_brackets);
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-09-15 01:31:02 +02:00
|
|
|
itemlist.push_back (listItem);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
std::size_t element_count = getCount();
|
2017-07-03 16:56:32 +02:00
|
|
|
recalculateVerticalBar (element_count);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FListBox::remove (std::size_t item)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( item > getCount() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
itemlist.erase (itemlist.begin() + int(item) - 1);
|
|
|
|
element_count = getCount();
|
2016-11-02 00:37:58 +01:00
|
|
|
max_line_width = 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-17 00:50:24 +01:00
|
|
|
for (auto&& listbox_item : itemlist)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-12-17 00:50:24 +01:00
|
|
|
std::size_t len = listbox_item.getText().getLength();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( len > max_line_width )
|
|
|
|
max_line_width = len;
|
|
|
|
}
|
2016-09-27 00:46:05 +02:00
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
int hmax = ( max_line_width > getWidth() - nf_offset - 4 )
|
|
|
|
? int(max_line_width - getWidth() + nf_offset + 4)
|
|
|
|
: 0;
|
|
|
|
hbar->setMaximum (hmax);
|
2018-10-20 22:50:35 +02:00
|
|
|
hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4));
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( hbar->isVisible() && max_line_width < getWidth() - nf_offset - 3 )
|
2016-09-27 00:46:05 +02:00
|
|
|
hbar->hide();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
int vmax = ( element_count > getHeight() - 2 )
|
|
|
|
? int(element_count - getHeight()) + 2
|
|
|
|
: 0;
|
|
|
|
vbar->setMaximum (vmax);
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setPageSize (int(element_count), int(getHeight()) - 2);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( vbar->isVisible() && element_count < getHeight() - 1 )
|
|
|
|
vbar->hide();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( current >= item && current > 1 )
|
|
|
|
current--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( current > element_count )
|
2015-05-23 13:35:12 +02:00
|
|
|
current = element_count;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( yoffset > int(element_count - getHeight()) + 2 )
|
|
|
|
yoffset = int(element_count - getHeight()) + 2;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( yoffset < 0 )
|
|
|
|
yoffset = 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FListBox::clear()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t size;
|
2017-09-15 01:31:02 +02:00
|
|
|
itemlist.clear();
|
2016-11-02 00:37:58 +01:00
|
|
|
current = 0;
|
|
|
|
xoffset = 0;
|
|
|
|
yoffset = 0;
|
|
|
|
max_line_width = 0;
|
|
|
|
last_current = -1;
|
|
|
|
last_yoffset = -1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
vbar->setMinimum(0);
|
|
|
|
vbar->setValue(0);
|
|
|
|
vbar->hide();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
hbar->setMinimum(0);
|
|
|
|
hbar->setValue(0);
|
|
|
|
hbar->hide();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// clear list from screen
|
|
|
|
setColor (wc.list_fg, wc.list_bg);
|
|
|
|
size = getWidth() - 2;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( size == 0 )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto blank = createBlankArray(size + 1);
|
2017-08-12 22:55:29 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
std::memset (blank, ' ', size);
|
2016-11-02 00:37:58 +01:00
|
|
|
blank[size] = '\0';
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (int y = 0; y < int(getHeight()) - 2; y++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
setPrintPos (2, 2 + y);
|
|
|
|
print (blank);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
destroyBlankArray (blank);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FListBox::onKeyPress (FKeyEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t current_before = current;
|
2018-11-21 20:07:08 +01:00
|
|
|
int xoffset_before = xoffset;
|
|
|
|
int yoffset_before = yoffset;
|
|
|
|
FKey key = ev->key();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
switch ( key )
|
|
|
|
{
|
|
|
|
case fc::Fkey_return:
|
|
|
|
case fc::Fkey_enter:
|
2017-12-03 21:06:21 +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_up:
|
2017-12-03 21:06:21 +01:00
|
|
|
keyUp();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
2017-12-03 21:06:21 +01:00
|
|
|
keyDown();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
2017-12-03 21:06:21 +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-03 21:06:21 +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_ppage:
|
2017-12-03 21:06:21 +01:00
|
|
|
keyPgUp();
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
2017-12-03 21:06:21 +01:00
|
|
|
keyPgDn();
|
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-03 21:06:21 +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-03 21:06:21 +01:00
|
|
|
keyEnd();
|
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
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( keyInsert() )
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_space:
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( keySpace() )
|
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_erase:
|
|
|
|
case fc::Fkey_backspace:
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( keyBackspace() )
|
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_escape:
|
|
|
|
case fc::Fkey_escape_mintty:
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( keyEsc() )
|
2015-09-20 05:44:50 +02:00
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( keyIncSearchInput(key) )
|
|
|
|
ev->accept();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( current_before != current )
|
|
|
|
{
|
|
|
|
processChanged();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! isMultiSelection() )
|
|
|
|
processSelect();
|
|
|
|
}
|
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
if ( ev->isAccepted() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
bool draw_vbar = yoffset_before != yoffset;
|
|
|
|
bool draw_hbar = xoffset_before != xoffset;
|
|
|
|
updateDrawing (draw_vbar, draw_hbar);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FListBox::onMouseDown (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
int yoffset_before
|
|
|
|
, mouse_x
|
|
|
|
, mouse_y;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton
|
2017-11-26 22:37:18 +01:00
|
|
|
&& ev->getButton() != fc::RightButton )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() == fc::RightButton && ! isMultiSelection() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
getWidgetFocus();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
yoffset_before = yoffset;
|
2015-09-20 05:44:50 +02:00
|
|
|
mouse_x = ev->getX();
|
|
|
|
mouse_y = ev->getY();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( mouse_x > 1 && mouse_x < int(getWidth())
|
|
|
|
&& mouse_y > 1 && mouse_y < int(getHeight()) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
|
|
|
current = std::size_t(yoffset + mouse_y - 1);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( current > element_count )
|
|
|
|
current = element_count;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
inc_search.clear();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() == fc::RightButton )
|
2017-12-30 03:54:05 +01:00
|
|
|
multiSelection(current);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( isVisible() )
|
|
|
|
drawList();
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
vbar->setValue (yoffset);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( vbar->isVisible() && yoffset_before != yoffset )
|
|
|
|
vbar->drawBar();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FListBox::onMouseUp (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-06-18 19:36:22 +02:00
|
|
|
if ( drag_scroll != fc::noScroll )
|
2017-12-30 03:54:05 +01:00
|
|
|
stopDragScroll();
|
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
|
|
|
{
|
2015-09-20 05:44:50 +02:00
|
|
|
int mouse_x = ev->getX();
|
|
|
|
int mouse_y = ev->getY();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( mouse_x > 1 && mouse_x < int(getWidth())
|
|
|
|
&& mouse_y > 1 && mouse_y < int(getHeight()) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
processChanged();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! isMultiSelection() )
|
|
|
|
processSelect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FListBox::onMouseMove (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton
|
2017-11-26 22:37:18 +01:00
|
|
|
&& ev->getButton() != fc::RightButton )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() == fc::RightButton && ! isMultiSelection() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t current_before = current;
|
2017-12-30 03:54:05 +01:00
|
|
|
int yoffset_before = yoffset;
|
|
|
|
int mouse_x = ev->getX();
|
|
|
|
int mouse_y = ev->getY();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( mouse_x > 1 && mouse_x < int(getWidth())
|
|
|
|
&& mouse_y > 1 && mouse_y < int(getHeight()) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
|
|
|
current = std::size_t(yoffset + mouse_y - 1);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( current > element_count )
|
|
|
|
current = element_count;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
inc_search.clear();
|
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
// Handle multiple selections
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->getButton() == fc::RightButton
|
2017-11-26 22:37:18 +01:00
|
|
|
&& current_before != current )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-12-30 03:54:05 +01:00
|
|
|
multiSelectionUpTo(current);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isVisible() )
|
|
|
|
drawList();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
vbar->setValue (yoffset);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( vbar->isVisible() && yoffset_before != yoffset )
|
|
|
|
vbar->drawBar();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
// Auto-scrolling when dragging mouse outside the widget
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( mouse_y < 2 )
|
2017-12-30 03:54:05 +01:00
|
|
|
dragUp (ev->getButton());
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( mouse_y >= int(getHeight()) )
|
2017-12-30 03:54:05 +01:00
|
|
|
dragDown (ev->getButton());
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2017-12-30 03:54:05 +01:00
|
|
|
stopDragScroll();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FListBox::onMouseDoubleClick (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;
|
|
|
|
|
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 > 1 && mouse_x < int(getWidth())
|
|
|
|
&& mouse_y > 1 && mouse_y < int(getHeight()) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( yoffset + mouse_y - 1 > int(getCount()) )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
processClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::onTimer (FTimerEvent*)
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t current_before = current;
|
2017-12-30 03:54:05 +01:00
|
|
|
int yoffset_before = yoffset;
|
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
|
|
|
{
|
2017-06-18 19:36:22 +02:00
|
|
|
case fc::noScroll:
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2017-06-18 19:36:22 +02:00
|
|
|
case fc::scrollUp:
|
|
|
|
case fc::scrollUpSelect:
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( ! dragScrollUp() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
2017-06-18 19:36:22 +02:00
|
|
|
case fc::scrollDown:
|
|
|
|
case fc::scrollDownSelect:
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( ! dragScrollDown() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( current_before != current )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-12-30 03:54:05 +01:00
|
|
|
inc_search.clear();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
// Handle multiple selections
|
|
|
|
if ( drag_scroll == fc::scrollUpSelect
|
|
|
|
|| drag_scroll == fc::scrollDownSelect )
|
|
|
|
multiSelectionUpTo(current);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isVisible() )
|
|
|
|
drawList();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
vbar->setValue (yoffset);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( vbar->isVisible() && yoffset_before != yoffset )
|
|
|
|
vbar->drawBar();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FListBox::onWheel (FWheelEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t current_before = current;
|
2017-10-02 07:32:33 +02:00
|
|
|
int wheel
|
|
|
|
, yoffset_before = yoffset
|
|
|
|
, pagesize = 4;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
wheel = ev->getWheel();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-06-18 19:36:22 +02:00
|
|
|
if ( drag_scroll != fc::noScroll )
|
2017-12-30 03:54:05 +01:00
|
|
|
stopDragScroll();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
switch ( wheel )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
case fc::WheelUp:
|
2017-12-30 03:54:05 +01:00
|
|
|
wheelUp (pagesize);
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
case fc::WheelDown:
|
2017-12-30 03:54:05 +01:00
|
|
|
wheelDown (pagesize);
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( current_before != current )
|
|
|
|
{
|
2017-12-30 03:54:05 +01:00
|
|
|
inc_search.clear();
|
2015-05-23 13:35:12 +02:00
|
|
|
processChanged();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! isMultiSelection() )
|
|
|
|
processSelect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isVisible() )
|
|
|
|
drawList();
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
vbar->setValue (yoffset);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( vbar->isVisible() && yoffset_before != yoffset )
|
|
|
|
vbar->drawBar();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::onFocusIn (FFocusEvent*)
|
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::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
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-12-19 20:49:01 +01:00
|
|
|
delOwnTimer();
|
2015-05-23 13:35:12 +02:00
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// protected methods of FListBox
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-09 18:24:31 +01:00
|
|
|
void FListBox::adjustYOffset (std::size_t element_count)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-12-09 18:24:31 +01:00
|
|
|
std::size_t height = getClientHeight();
|
2017-10-14 22:20:19 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
if ( height == 0 || element_count == 0 )
|
2017-10-02 07:32:33 +02:00
|
|
|
return;
|
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
if ( yoffset > int(element_count - height) )
|
|
|
|
yoffset = int(element_count - height);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( yoffset < 0 )
|
|
|
|
yoffset = 0;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( current < std::size_t(yoffset) )
|
|
|
|
current = std::size_t(yoffset);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
if ( yoffset < int(current - height) )
|
|
|
|
yoffset = int(current - height);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::adjustSize()
|
|
|
|
{
|
|
|
|
FWidget::adjustSize();
|
2018-12-09 18:24:31 +01:00
|
|
|
std::size_t element_count = getCount();
|
|
|
|
std::size_t width = getClientWidth();
|
|
|
|
std::size_t height = getClientHeight();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
adjustYOffset (element_count);
|
|
|
|
|
|
|
|
int vmax = ( element_count > height )
|
|
|
|
? int(element_count - height)
|
|
|
|
: 0;
|
|
|
|
vbar->setMaximum (vmax);
|
|
|
|
vbar->setPageSize (int(element_count), int(height));
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setX (int(getWidth()));
|
2018-12-09 18:24:31 +01:00
|
|
|
vbar->setHeight (height, false);
|
2016-11-02 00:37:58 +01:00
|
|
|
vbar->resize();
|
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
int hmax = ( max_line_width > width - 2 )
|
|
|
|
? int(max_line_width - width + 2)
|
|
|
|
: 0;
|
|
|
|
hbar->setMaximum (hmax);
|
|
|
|
hbar->setPageSize (int(max_line_width), int(width) - 2);
|
2018-10-14 06:25:33 +02:00
|
|
|
hbar->setY (int(getHeight()));
|
2018-12-09 18:24:31 +01:00
|
|
|
hbar->setWidth (width + nf_offset, false);
|
2016-11-02 00:37:58 +01:00
|
|
|
hbar->resize();
|
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
if ( element_count <= height )
|
2016-11-02 00:37:58 +01:00
|
|
|
vbar->hide();
|
|
|
|
else
|
|
|
|
vbar->setVisible();
|
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
if ( max_line_width < width - 1 )
|
2016-11-02 00:37:58 +01:00
|
|
|
hbar->hide();
|
|
|
|
else
|
|
|
|
hbar->setVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FListBox
|
2017-04-23 18:54:46 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-05-19 22:16:50 +02:00
|
|
|
inline FString& FListBox::getString (listBoxItems::iterator iter)
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
|
|
|
return iter->getText();
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::init()
|
|
|
|
{
|
|
|
|
setForegroundColor (wc.dialog_fg);
|
|
|
|
setBackgroundColor (wc.dialog_bg);
|
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
|
|
|
{
|
2018-12-20 01:41:04 +01:00
|
|
|
vbar = std::make_shared<FScrollbar>(fc::vertical, this);
|
2017-08-12 22:55:29 +02:00
|
|
|
vbar->setMinimum(0);
|
|
|
|
vbar->setValue(0);
|
|
|
|
vbar->hide();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-12-20 01:41:04 +01:00
|
|
|
hbar = std::make_shared<FScrollbar>(fc::horizontal, this);
|
2017-08-12 22:55:29 +02:00
|
|
|
hbar->setMinimum(0);
|
|
|
|
hbar->setValue(0);
|
|
|
|
hbar->hide();
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
2018-11-22 21:51:32 +01:00
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
2017-08-12 22:55:29 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setGeometry (1, 1, 5, 4, false); // initialize geometry values
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
vbar->addCallback
|
|
|
|
(
|
|
|
|
"change-value",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FListBox::cb_VBarChange)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
hbar->addCallback
|
|
|
|
(
|
|
|
|
"change-value",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FListBox::cb_HBarChange)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
nf_offset = isNewFont() ? 1 : 0;
|
|
|
|
setTopPadding(1);
|
|
|
|
setLeftPadding(1);
|
|
|
|
setBottomPadding(1);
|
2018-10-20 22:50:35 +02:00
|
|
|
setRightPadding(1 + int(nf_offset));
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::draw()
|
|
|
|
{
|
|
|
|
if ( current < 1 )
|
|
|
|
current = 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setColor();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isNewFont() )
|
2018-10-14 06:25:33 +02:00
|
|
|
drawBorder (1, 1, int(getWidth()) - 1, int(getHeight()));
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
|
|
|
drawBorder();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isNewFont() && ! vbar->isVisible() )
|
|
|
|
{
|
|
|
|
setColor();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (int y = 2; y < int(getHeight()); y++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
setPrintPos (int(getWidth()), y);
|
2017-09-11 03:06:02 +02:00
|
|
|
print (' '); // clear right side of the scrollbar
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-11-18 01:15:38 +01:00
|
|
|
drawHeadline();
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( vbar->isVisible() )
|
|
|
|
vbar->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( hbar->isVisible() )
|
|
|
|
hbar->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
drawList();
|
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( flags.focus && getStatusBar() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
const auto& msg = getStatusbarMessage();
|
|
|
|
const auto& curMsg = getStatusBar()->getMessage();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( curMsg != msg )
|
|
|
|
{
|
|
|
|
getStatusBar()->setMessage(msg);
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-18 01:15:38 +01:00
|
|
|
void FListBox::drawHeadline()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( text.isNull() || text.isEmpty() )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
FString txt = " " + text + " ";
|
|
|
|
std::size_t length = txt.getLength();
|
2016-11-02 00:37:58 +01:00
|
|
|
setPrintPos (2, 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
|
|
|
setColor(wc.label_emphasis_fg, wc.label_bg);
|
|
|
|
else
|
|
|
|
setColor(wc.label_inactive_fg, wc.label_inactive_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
if ( length <= uInt(getClientWidth()) )
|
2016-11-02 00:37:58 +01:00
|
|
|
print (txt);
|
|
|
|
else
|
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
// Print ellipsis
|
2017-08-27 09:50:30 +02:00
|
|
|
print (text.left(uInt(getClientWidth() - 2)));
|
2016-11-02 00:37:58 +01:00
|
|
|
setColor (wc.label_ellipsis_fg, wc.label_bg);
|
|
|
|
print("..");
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::drawList()
|
|
|
|
{
|
2017-09-15 01:31:02 +02:00
|
|
|
if ( itemlist.empty() || getHeight() <= 2 || getWidth() <= 4 )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
std::size_t start = 0;
|
|
|
|
std::size_t num = uInt(getHeight() - 2);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( num > getCount() )
|
|
|
|
num = getCount();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( last_yoffset >= 0
|
2017-11-26 22:37:18 +01:00
|
|
|
&& last_yoffset == yoffset
|
2018-10-14 06:25:33 +02:00
|
|
|
&& last_current != int(current) )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
// speed up: redraw only the changed rows
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t last_pos = current - std::size_t(yoffset) - 1;
|
|
|
|
std::size_t current_pos = std::size_t(last_current - yoffset) - 1;
|
2016-11-02 00:37:58 +01:00
|
|
|
start = std::min(last_pos, current_pos);
|
2017-09-17 01:50:41 +02:00
|
|
|
num = std::max(last_pos, current_pos) + 1;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = index2iterator(start + std::size_t(yoffset));
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (std::size_t y = start; y < num && iter != itemlist.end() ; y++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
bool serach_mark = false;
|
|
|
|
bool lineHasBrackets = hasBrackets(iter);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
// Import data via lazy conversion
|
|
|
|
lazyConvert (iter, int(y));
|
|
|
|
|
|
|
|
// Set screen position and attributes
|
|
|
|
setLineAttributes ( int(y), isSelected(iter), lineHasBrackets
|
|
|
|
, serach_mark );
|
|
|
|
|
|
|
|
// print the entry
|
|
|
|
if ( lineHasBrackets )
|
|
|
|
{
|
|
|
|
drawListBracketsLine (int(y), iter, serach_mark);
|
|
|
|
}
|
|
|
|
else // line has no brackets
|
|
|
|
{
|
|
|
|
drawListLine (int(y), iter, serach_mark);
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsetAttributes();
|
|
|
|
last_yoffset = yoffset;
|
2018-10-14 06:25:33 +02:00
|
|
|
last_current = int(current);
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-10 15:36:02 +01:00
|
|
|
inline void FListBox::drawListLine ( int y
|
|
|
|
, listBoxItems::iterator iter
|
|
|
|
, bool serach_mark )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t i, len;
|
|
|
|
std::size_t inc_len = inc_search.getLength();
|
|
|
|
bool isCurrentLine = bool(y + yoffset + 1 == int(current));
|
2017-12-03 21:06:21 +01:00
|
|
|
FString element;
|
2018-10-20 22:50:35 +02:00
|
|
|
element = getString(iter).mid ( std::size_t(1 + xoffset)
|
|
|
|
, getWidth() - nf_offset - 4 );
|
2017-12-03 21:06:21 +01:00
|
|
|
const wchar_t* const& element_str = element.wc_str();
|
|
|
|
len = element.getLength();
|
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( isMonochron() && isCurrentLine && flags.focus )
|
2017-12-25 21:17:08 +01:00
|
|
|
print (fc::BlackRightPointingPointer); // ►
|
2017-12-03 21:06:21 +01:00
|
|
|
else
|
|
|
|
print (' ');
|
|
|
|
|
|
|
|
if ( serach_mark )
|
|
|
|
setColor ( wc.current_inc_search_element_fg
|
|
|
|
, wc.current_element_focus_bg );
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( serach_mark && i == inc_len && flags.focus )
|
2017-12-03 21:06:21 +01:00
|
|
|
setColor ( wc.current_element_focus_fg
|
|
|
|
, wc.current_element_focus_bg );
|
|
|
|
|
|
|
|
print (element_str[i]);
|
|
|
|
}
|
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( isMonochron() && isCurrentLine && flags.focus )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-12-03 03:22:36 +01:00
|
|
|
print (fc::BlackLeftPointingPointer); // ◄
|
2017-12-03 21:06:21 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
for (; i < getWidth() - nf_offset - 3; i++)
|
2017-12-03 21:06:21 +01:00
|
|
|
print (' ');
|
|
|
|
}
|
|
|
|
|
2017-12-25 21:17:08 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::printLeftBracket (fc::brackets_type bracket_type)
|
|
|
|
{
|
2018-12-03 03:22:36 +01:00
|
|
|
if ( bracket_type != fc::NoBrackets )
|
|
|
|
print ("\0[({<"[bracket_type]);
|
2017-12-25 21:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::printRightBracket (fc::brackets_type bracket_type)
|
|
|
|
{
|
2018-12-03 03:22:36 +01:00
|
|
|
if ( bracket_type != fc::NoBrackets )
|
|
|
|
print ("\0])}>"[bracket_type]);
|
2017-12-25 21:17:08 +01:00
|
|
|
}
|
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-12-10 15:36:02 +01:00
|
|
|
inline void FListBox::drawListBracketsLine ( int y
|
|
|
|
, listBoxItems::iterator iter
|
|
|
|
, bool serach_mark )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
|
|
|
FString element;
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t len
|
|
|
|
, full_length
|
|
|
|
, inc_len = inc_search.getLength()
|
|
|
|
, i = 0
|
|
|
|
, b = 0;
|
|
|
|
bool isCurrentLine = bool(y + yoffset + 1 == int(current));
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( isMonochron() && isCurrentLine && flags.focus )
|
2017-12-25 21:17:08 +01:00
|
|
|
print (fc::BlackRightPointingPointer); // ►
|
2017-12-03 21:06:21 +01:00
|
|
|
else
|
|
|
|
print (' ');
|
|
|
|
|
|
|
|
if ( xoffset == 0 )
|
|
|
|
{
|
|
|
|
b = 1;
|
2017-12-25 21:17:08 +01:00
|
|
|
printLeftBracket (iter->brackets);
|
2017-05-20 22:43:55 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
element = getString(iter).mid ( std::size_t(xoffset) + 1
|
2018-10-20 22:50:35 +02:00
|
|
|
, getWidth() - nf_offset - 5 );
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
|
|
|
else
|
2018-10-14 06:25:33 +02:00
|
|
|
element = getString(iter).mid ( std::size_t(xoffset)
|
2018-10-20 22:50:35 +02:00
|
|
|
, getWidth() - nf_offset - 4 );
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
const wchar_t* const& element_str = element.wc_str();
|
|
|
|
len = element.getLength();
|
|
|
|
|
|
|
|
for (; i < len; i++)
|
|
|
|
{
|
|
|
|
if ( serach_mark && i == 0 )
|
|
|
|
setColor ( wc.current_inc_search_element_fg
|
|
|
|
, wc.current_element_focus_bg );
|
|
|
|
|
|
|
|
if ( serach_mark && i == inc_len )
|
|
|
|
setColor ( wc.current_element_focus_fg
|
|
|
|
, wc.current_element_focus_bg );
|
|
|
|
|
|
|
|
print (element_str[i]);
|
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
full_length = getString(iter).getLength();
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( b + i < getWidth() - nf_offset - 4
|
2018-10-14 06:25:33 +02:00
|
|
|
&& std::size_t(xoffset) <= full_length + 1 )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
|
|
|
if ( serach_mark && i == inc_len )
|
|
|
|
setColor ( wc.current_element_focus_fg
|
|
|
|
, wc.current_element_focus_bg );
|
|
|
|
|
2017-12-25 21:17:08 +01:00
|
|
|
printRightBracket (iter->brackets);
|
2017-12-03 21:06:21 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( isMonochron() && isCurrentLine && flags.focus )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2017-12-25 21:17:08 +01:00
|
|
|
print (fc::BlackLeftPointingPointer); // ◄
|
2017-12-03 21:06:21 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
for (; b + i < getWidth() - nf_offset - 3; i++)
|
2017-12-03 21:06:21 +01:00
|
|
|
print (' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::setLineAttributes ( int y
|
|
|
|
, bool isLineSelected
|
|
|
|
, bool lineHasBrackets
|
|
|
|
, bool& serach_mark )
|
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
bool isCurrentLine = bool(y + yoffset + 1 == int(current));
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t inc_len = inc_search.getLength();
|
2017-12-03 21:06:21 +01:00
|
|
|
setPrintPos (2, 2 + int(y));
|
|
|
|
|
|
|
|
if ( isLineSelected )
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
setBold();
|
|
|
|
else
|
|
|
|
setColor (wc.selected_list_fg, wc.selected_list_bg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
unsetBold();
|
|
|
|
else
|
|
|
|
setColor (wc.list_fg, wc.list_bg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isCurrentLine )
|
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( flags.focus && getMaxColor() < 16 )
|
2017-12-03 21:06:21 +01:00
|
|
|
setBold();
|
2017-05-19 22:16:50 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isLineSelected )
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
setBold();
|
2018-11-04 23:00:06 +01:00
|
|
|
else if ( flags.focus )
|
2017-12-03 21:06:21 +01:00
|
|
|
setColor ( wc.selected_current_element_focus_fg
|
|
|
|
, wc.selected_current_element_focus_bg );
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2017-12-03 21:06:21 +01:00
|
|
|
setColor ( wc.selected_current_element_fg
|
|
|
|
, wc.selected_current_element_bg );
|
|
|
|
|
|
|
|
setCursorPos (3, 2 + int(y)); // first character
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
unsetBold();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( flags.focus )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
setColor ( wc.current_element_focus_fg
|
|
|
|
, wc.current_element_focus_bg );
|
|
|
|
int b = ( lineHasBrackets ) ? 1: 0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( inc_len > 0 ) // incremental search
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
serach_mark = true;
|
|
|
|
// Place the cursor on the last found character
|
|
|
|
setCursorPos (2 + b + int(inc_len), 2 + int(y));
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
else // only highlighted
|
|
|
|
setCursorPos (3 + b, 2 + int(y)); // first character
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
else
|
|
|
|
setColor ( wc.current_element_fg
|
|
|
|
, wc.current_element_bg );
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2018-11-04 23:00:06 +01:00
|
|
|
else if ( flags.focus && getMaxColor() < 16 )
|
2017-12-03 21:06:21 +01:00
|
|
|
unsetBold();
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::unsetAttributes()
|
|
|
|
{
|
|
|
|
if ( isMonochron() ) // unset for the last element
|
|
|
|
setReverse(false);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
unsetBold();
|
|
|
|
}
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::updateDrawing (bool draw_vbar, bool draw_hbar)
|
|
|
|
{
|
|
|
|
if ( isVisible() )
|
|
|
|
drawList();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
vbar->setValue (yoffset);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( vbar->isVisible() && draw_vbar )
|
|
|
|
vbar->drawBar();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
hbar->setValue (xoffset);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( hbar->isVisible() && draw_hbar )
|
|
|
|
hbar->drawBar();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-20 22:50:35 +02:00
|
|
|
void FListBox::recalculateHorizontalBar (std::size_t len, bool has_brackets)
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
|
|
|
if ( has_brackets )
|
|
|
|
len += 2;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( len <= max_line_width )
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
max_line_width = len;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( len >= getWidth() - nf_offset - 3 )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-12-09 18:24:31 +01:00
|
|
|
int hmax = ( max_line_width > getWidth() - nf_offset - 4 )
|
|
|
|
? int(max_line_width - getWidth() + nf_offset + 4)
|
|
|
|
: 0;
|
|
|
|
hbar->setMaximum (hmax);
|
2018-10-20 22:50:35 +02:00
|
|
|
hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4));
|
2017-12-03 21:06:21 +01:00
|
|
|
hbar->calculateSliderValues();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( ! hbar->isVisible() )
|
|
|
|
hbar->setVisible();
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-20 22:50:35 +02:00
|
|
|
void FListBox::recalculateVerticalBar (std::size_t element_count)
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-12-09 18:24:31 +01:00
|
|
|
int vmax = ( element_count > getHeight() - 2 )
|
|
|
|
? int(element_count - getHeight() + 2)
|
|
|
|
: 0;
|
|
|
|
vbar->setMaximum (vmax);
|
2018-10-20 22:50:35 +02:00
|
|
|
vbar->setPageSize (int(element_count), int(getHeight()) - 2);
|
2017-12-03 21:06:21 +01:00
|
|
|
vbar->calculateSliderValues();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( ! vbar->isVisible() && element_count >= getHeight() - 1 )
|
2017-12-03 21:06:21 +01:00
|
|
|
vbar->setVisible();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-12-30 03:54:05 +01:00
|
|
|
inline void FListBox::getWidgetFocus()
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( hasFocus() )
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
2017-12-30 03:54:05 +01:00
|
|
|
setFocus();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FListBox::multiSelection (std::size_t pos)
|
2017-12-30 03:54:05 +01:00
|
|
|
{
|
|
|
|
if ( ! isMultiSelection() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( isSelected(pos) )
|
|
|
|
{
|
|
|
|
mouse_select = false;
|
|
|
|
unselectItem(pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mouse_select = true;
|
|
|
|
selectItem(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
processSelect();
|
2018-10-14 06:25:33 +02:00
|
|
|
secect_from_item = int(pos);
|
2017-12-30 03:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FListBox::multiSelectionUpTo (std::size_t pos)
|
2017-12-30 03:54:05 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t from, to;
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( ! isMultiSelection() )
|
|
|
|
return;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( std::size_t(secect_from_item) > pos )
|
2017-12-30 03:54:05 +01:00
|
|
|
{
|
|
|
|
from = pos;
|
2018-10-14 06:25:33 +02:00
|
|
|
to = std::size_t(secect_from_item) - 1;
|
2017-12-30 03:54:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
from = std::size_t(secect_from_item) + 1;
|
2017-12-30 03:54:05 +01:00
|
|
|
to = pos;
|
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (std::size_t i = from; i <= to; i++)
|
2017-12-30 03:54:05 +01:00
|
|
|
{
|
|
|
|
if ( mouse_select )
|
|
|
|
{
|
|
|
|
selectItem(i);
|
|
|
|
processSelect();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unselectItem(i);
|
|
|
|
processSelect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
secect_from_item = int(pos);
|
2017-12-30 03:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::wheelUp (int pagesize)
|
|
|
|
{
|
|
|
|
if ( yoffset == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
yoffset -= pagesize;
|
|
|
|
|
|
|
|
if ( yoffset < 0 )
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
current -= std::size_t(pagesize + yoffset);
|
2017-12-30 03:54:05 +01:00
|
|
|
yoffset = 0;
|
|
|
|
}
|
|
|
|
else
|
2018-10-14 06:25:33 +02:00
|
|
|
current -= std::size_t(pagesize);
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( current < 1 )
|
|
|
|
current = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::wheelDown (int pagesize)
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
|
|
|
int yoffset_end = int(element_count - getClientHeight());
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( yoffset_end < 0 )
|
|
|
|
yoffset_end = 0;
|
|
|
|
|
|
|
|
if ( yoffset == yoffset_end )
|
|
|
|
return;
|
|
|
|
|
|
|
|
yoffset += pagesize;
|
|
|
|
|
|
|
|
if ( yoffset > yoffset_end )
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
current += std::size_t(pagesize - (yoffset - yoffset_end));
|
2017-12-30 03:54:05 +01:00
|
|
|
yoffset = yoffset_end;
|
|
|
|
}
|
|
|
|
else
|
2018-10-14 06:25:33 +02:00
|
|
|
current += std::size_t(pagesize);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( current > element_count )
|
|
|
|
current = element_count;
|
2017-12-30 03:54:05 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FListBox::dragScrollUp()
|
|
|
|
{
|
|
|
|
if ( current == 1 )
|
|
|
|
{
|
|
|
|
drag_scroll = fc::noScroll;
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
prevListItem (scroll_distance);
|
|
|
|
return true;
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-30 03:54:05 +01:00
|
|
|
bool FListBox::dragScrollDown()
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( current == element_count )
|
|
|
|
{
|
|
|
|
drag_scroll = fc::noScroll;
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
nextListItem (scroll_distance);
|
|
|
|
return true;
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-30 03:54:05 +01:00
|
|
|
void FListBox::dragUp (int mouse_button)
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( drag_scroll != fc::noScroll
|
2018-10-14 06:25:33 +02:00
|
|
|
&& scroll_distance < int(getClientHeight()) )
|
2017-12-30 03:54:05 +01:00
|
|
|
scroll_distance++;
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( ! scroll_timer && current > 1 )
|
|
|
|
{
|
|
|
|
scroll_timer = true;
|
|
|
|
addTimer(scroll_repeat);
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( mouse_button == fc::RightButton )
|
|
|
|
drag_scroll = fc::scrollUpSelect;
|
|
|
|
else
|
|
|
|
drag_scroll = fc::scrollUp;
|
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( current == 1 )
|
|
|
|
{
|
|
|
|
delOwnTimer();
|
|
|
|
drag_scroll = fc::noScroll;
|
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-30 03:54:05 +01:00
|
|
|
void FListBox::dragDown (int mouse_button)
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( drag_scroll != fc::noScroll
|
2018-10-14 06:25:33 +02:00
|
|
|
&& scroll_distance < int(getClientHeight()) )
|
2017-12-30 03:54:05 +01:00
|
|
|
scroll_distance++;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( ! scroll_timer && current < getCount() )
|
2017-12-30 03:54:05 +01:00
|
|
|
{
|
|
|
|
scroll_timer = true;
|
|
|
|
addTimer(scroll_repeat);
|
|
|
|
|
|
|
|
if ( mouse_button == fc::RightButton )
|
|
|
|
drag_scroll = fc::scrollDownSelect;
|
|
|
|
else
|
|
|
|
drag_scroll = fc::scrollDown;
|
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( current == getCount() )
|
2017-12-30 03:54:05 +01:00
|
|
|
{
|
|
|
|
delOwnTimer();
|
|
|
|
drag_scroll = fc::noScroll;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::stopDragScroll()
|
|
|
|
{
|
|
|
|
delOwnTimer();
|
|
|
|
drag_scroll = fc::noScroll;
|
|
|
|
scroll_distance = 1;
|
|
|
|
scroll_timer = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::prevListItem (int distance)
|
|
|
|
{
|
|
|
|
if ( current == 1 )
|
|
|
|
return;
|
|
|
|
|
2018-10-29 19:10:42 +01:00
|
|
|
if ( current <= std::size_t(distance) )
|
2017-12-03 21:06:21 +01:00
|
|
|
current = 1;
|
2018-10-29 02:59:41 +01:00
|
|
|
else
|
|
|
|
current -= std::size_t(distance);
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( current <= std::size_t(yoffset) )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-10-29 19:10:42 +01:00
|
|
|
if ( yoffset < distance )
|
2017-12-03 21:06:21 +01:00
|
|
|
yoffset = 0;
|
2018-10-29 19:10:42 +01:00
|
|
|
else
|
|
|
|
yoffset -= distance;
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-30 03:54:05 +01:00
|
|
|
void FListBox::nextListItem (int distance)
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
|
|
|
int yoffset_end = int(element_count - getClientHeight());
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( current == element_count )
|
|
|
|
return;
|
|
|
|
|
2018-10-29 19:10:42 +01:00
|
|
|
if ( current + std::size_t(distance) > element_count )
|
2017-12-03 21:06:21 +01:00
|
|
|
current = element_count;
|
2018-10-29 19:10:42 +01:00
|
|
|
else
|
|
|
|
current += std::size_t(distance);
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( current - std::size_t(yoffset) > getClientHeight() )
|
2017-12-03 21:06:21 +01:00
|
|
|
{
|
2018-10-29 19:10:42 +01:00
|
|
|
if ( yoffset > yoffset_end - distance )
|
2017-12-03 21:06:21 +01:00
|
|
|
yoffset = yoffset_end;
|
2018-10-29 19:10:42 +01:00
|
|
|
else
|
|
|
|
yoffset += distance;
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
2017-12-30 03:54:05 +01:00
|
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::scrollToX (int val)
|
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
static constexpr std::size_t padding_space = 2; // 1 leading + 1 trailing space
|
2018-10-20 22:50:35 +02:00
|
|
|
std::size_t xoffset_end = max_line_width - getClientWidth() + padding_space;
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( xoffset == val )
|
|
|
|
return;
|
|
|
|
|
|
|
|
xoffset = val;
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( xoffset > int(xoffset_end) )
|
|
|
|
xoffset = int(xoffset_end);
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( xoffset < 0 )
|
|
|
|
xoffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::scrollToY (int val)
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
|
|
|
int yoffset_end = int(element_count - getClientHeight());
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( yoffset == val )
|
|
|
|
return;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
int c = int(current) - yoffset;
|
2017-12-30 03:54:05 +01:00
|
|
|
yoffset = val;
|
|
|
|
|
|
|
|
if ( yoffset > yoffset_end )
|
|
|
|
yoffset = yoffset_end;
|
|
|
|
|
|
|
|
if ( yoffset < 0 )
|
|
|
|
yoffset = 0;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
current = std::size_t(yoffset + c);
|
2017-12-30 03:54:05 +01:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( current < std::size_t(yoffset) )
|
|
|
|
current = std::size_t(yoffset);
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( current > element_count )
|
|
|
|
current = element_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::scrollLeft (int distance)
|
|
|
|
{
|
|
|
|
if ( xoffset == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
xoffset -= distance;
|
|
|
|
|
|
|
|
if ( xoffset < 0 )
|
|
|
|
xoffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::scrollRight (int distance)
|
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
static constexpr std::size_t padding_space = 2; // 1 leading + 1 trailing space
|
2018-10-20 22:50:35 +02:00
|
|
|
std::size_t xoffset_end = max_line_width - getClientWidth() + padding_space;
|
2017-12-30 03:54:05 +01:00
|
|
|
xoffset += distance;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( xoffset == int(xoffset_end) )
|
2017-12-30 03:54:05 +01:00
|
|
|
return;
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
if ( xoffset > int(xoffset_end) )
|
|
|
|
xoffset = int(xoffset_end);
|
2017-12-30 03:54:05 +01:00
|
|
|
|
|
|
|
if ( xoffset < 0 )
|
|
|
|
xoffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyUp()
|
|
|
|
{
|
|
|
|
prevListItem (1);
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyDown()
|
|
|
|
{
|
|
|
|
nextListItem (1);
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyLeft()
|
|
|
|
{
|
|
|
|
scrollLeft(1);
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyRight()
|
|
|
|
{
|
|
|
|
scrollRight(1);
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyPgUp()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
int pagesize = int(getClientHeight()) - 1;
|
2017-12-30 03:54:05 +01:00
|
|
|
prevListItem (pagesize);
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyPgDn()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
int pagesize = int(getClientHeight()) - 1;
|
2017-12-30 03:54:05 +01:00
|
|
|
nextListItem (pagesize);
|
2017-12-03 21:06:21 +01:00
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyHome()
|
|
|
|
{
|
|
|
|
current = 1;
|
|
|
|
yoffset = 0;
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyEnd()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
|
|
|
int yoffset_end = int(element_count - getClientHeight());
|
2017-12-03 21:06:21 +01:00
|
|
|
current = element_count;
|
|
|
|
|
|
|
|
if ( current > getClientHeight() )
|
|
|
|
yoffset = yoffset_end;
|
|
|
|
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::keyEsc()
|
|
|
|
{
|
|
|
|
if ( inc_search.getLength() > 0 )
|
|
|
|
{
|
|
|
|
inc_search.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::keyEnter()
|
|
|
|
{
|
|
|
|
processClick();
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::keySpace()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t inc_len = inc_search.getLength();
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
if ( inc_len > 0 )
|
|
|
|
{
|
|
|
|
inc_search += L' ';
|
|
|
|
bool inc_found = false;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = itemlist.begin();
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
while ( iter != itemlist.end() )
|
|
|
|
{
|
|
|
|
if ( ! inc_found
|
|
|
|
&& inc_search.toLower()
|
|
|
|
== iter->getText().left(inc_len + 1).toLower() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
setCurrentItem(iter);
|
|
|
|
inc_found = true;
|
|
|
|
break;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
++iter;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( ! inc_found )
|
|
|
|
{
|
|
|
|
inc_search.remove(inc_len, 1);
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
else if ( isMultiSelection() )
|
|
|
|
{
|
|
|
|
if ( isSelected(current) )
|
|
|
|
unselectItem(current);
|
|
|
|
else
|
|
|
|
selectItem(current);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
processSelect();
|
|
|
|
inc_search.clear();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
return true;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 22:43:55 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-12-03 21:06:21 +01:00
|
|
|
inline bool FListBox::keyInsert()
|
2017-05-20 22:43:55 +02:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( isMultiSelection() )
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t element_count = getCount();
|
2017-05-20 22:43:55 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( isSelected(current) )
|
|
|
|
unselectItem(current);
|
|
|
|
else
|
|
|
|
selectItem(current);
|
|
|
|
|
|
|
|
processSelect();
|
|
|
|
current++;
|
|
|
|
|
|
|
|
if ( current > element_count )
|
|
|
|
current = element_count;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( current - std::size_t(yoffset) >= getHeight() - 1 )
|
2017-12-03 21:06:21 +01:00
|
|
|
yoffset++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inc_search.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::keyBackspace()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t inc_len = inc_search.getLength();
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
if ( inc_len > 0 )
|
2017-05-20 22:43:55 +02:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
inc_search.remove(inc_len - 1, 1);
|
2017-05-20 22:43:55 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( inc_len > 1 )
|
2017-05-20 22:43:55 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = itemlist.begin();
|
2017-05-20 22:43:55 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
while ( iter != itemlist.end() )
|
|
|
|
{
|
|
|
|
if ( inc_search.toLower()
|
|
|
|
== iter->getText().left(inc_len - 1).toLower() )
|
|
|
|
{
|
|
|
|
setCurrentItem(iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
2017-05-20 22:43:55 +02:00
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
return true;
|
2017-05-20 22:43:55 +02:00
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
return false;
|
2017-05-20 22:43:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-21 20:07:08 +01:00
|
|
|
inline bool FListBox::keyIncSearchInput (FKey key)
|
2017-05-20 22:43:55 +02:00
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
if ( key <= 0x20 || key > 0x10fff )
|
|
|
|
return false;
|
2017-05-20 22:43:55 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
// incremental search
|
|
|
|
if ( inc_search.getLength() == 0 )
|
|
|
|
inc_search = wchar_t(key);
|
|
|
|
else
|
|
|
|
inc_search += wchar_t(key);
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t inc_len = inc_search.getLength();
|
2017-12-03 21:06:21 +01:00
|
|
|
bool inc_found = false;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = itemlist.begin();
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
while ( iter != itemlist.end() )
|
|
|
|
{
|
|
|
|
if ( ! inc_found
|
|
|
|
&& inc_search.toLower()
|
|
|
|
== iter->getText().left(inc_len).toLower() )
|
|
|
|
{
|
|
|
|
setCurrentItem(iter);
|
|
|
|
inc_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! inc_found )
|
|
|
|
{
|
|
|
|
inc_search.remove(inc_len - 1, 1);
|
|
|
|
|
|
|
|
if ( inc_len == 1 )
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-05-20 22:43:55 +02:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FListBox::processClick()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
emitCallback("clicked");
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::processSelect()
|
|
|
|
{
|
|
|
|
emitCallback("row-selected");
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FListBox::processChanged()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
emitCallback("row-changed");
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2017-07-23 01:19:59 +02:00
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FListBox::lazyConvert(listBoxItems::iterator iter, int y)
|
|
|
|
{
|
|
|
|
if ( conv_type != lazy_convert || ! iter->getText().isNull() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
convertToItem (*iter, source_container, y + yoffset);
|
2018-10-20 22:50:35 +02:00
|
|
|
std::size_t len = iter->text.getLength();
|
2017-12-03 21:06:21 +01:00
|
|
|
recalculateHorizontalBar (len, hasBrackets(iter));
|
|
|
|
|
|
|
|
if ( hbar->isVisible() )
|
|
|
|
hbar->redraw();
|
|
|
|
}
|
|
|
|
|
2017-07-23 01:19:59 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
void FListBox::cb_VBarChange (FWidget*, FDataPtr)
|
2017-07-23 01:19:59 +02:00
|
|
|
{
|
|
|
|
FScrollbar::sType scrollType;
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t current_before = current;
|
2017-10-02 07:32:33 +02:00
|
|
|
int distance = 1
|
2017-12-30 03:54:05 +01:00
|
|
|
, pagesize = 4
|
|
|
|
, yoffset_before = yoffset;
|
2017-07-23 01:19:59 +02:00
|
|
|
scrollType = vbar->getScrollType();
|
|
|
|
|
|
|
|
switch ( scrollType )
|
|
|
|
{
|
|
|
|
case FScrollbar::noScroll:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageBackward:
|
2018-10-14 06:25:33 +02:00
|
|
|
distance = int(getClientHeight());
|
2017-07-23 01:19:59 +02:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepBackward:
|
2017-12-30 03:54:05 +01:00
|
|
|
prevListItem (distance);
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageForward:
|
2018-10-14 06:25:33 +02:00
|
|
|
distance = int(getClientHeight());
|
2017-07-23 01:19:59 +02:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepForward:
|
2017-12-30 03:54:05 +01:00
|
|
|
nextListItem (distance);
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollJump:
|
2017-12-30 03:54:05 +01:00
|
|
|
scrollToY (vbar->getValue());
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollWheelUp:
|
2017-12-30 03:54:05 +01:00
|
|
|
wheelUp (pagesize);
|
|
|
|
break;
|
2017-07-23 01:19:59 +02:00
|
|
|
|
|
|
|
case FScrollbar::scrollWheelDown:
|
2017-12-30 03:54:05 +01:00
|
|
|
wheelDown (pagesize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( current_before != current )
|
|
|
|
{
|
|
|
|
inc_search.clear();
|
|
|
|
processChanged();
|
|
|
|
|
|
|
|
if ( ! isMultiSelection() )
|
|
|
|
processSelect();
|
2017-07-23 01:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isVisible() )
|
|
|
|
drawList();
|
|
|
|
|
|
|
|
if ( scrollType >= FScrollbar::scrollStepBackward
|
2017-12-30 03:54:05 +01:00
|
|
|
&& scrollType <= FScrollbar::scrollWheelDown )
|
2017-07-23 01:19:59 +02:00
|
|
|
{
|
|
|
|
vbar->setValue (yoffset);
|
|
|
|
|
|
|
|
if ( vbar->isVisible() && yoffset_before != yoffset )
|
|
|
|
vbar->drawBar();
|
|
|
|
|
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
void FListBox::cb_HBarChange (FWidget*, FDataPtr)
|
2017-07-23 01:19:59 +02:00
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
static constexpr int padding_space = 2; // 1 leading space + 1 trailing space
|
2017-07-23 01:19:59 +02:00
|
|
|
FScrollbar::sType scrollType;
|
2017-10-02 07:32:33 +02:00
|
|
|
int distance = 1
|
|
|
|
, pagesize = 4
|
2017-12-30 03:54:05 +01:00
|
|
|
, xoffset_before = xoffset;
|
2017-07-23 01:19:59 +02:00
|
|
|
scrollType = hbar->getScrollType();
|
|
|
|
|
|
|
|
switch ( scrollType )
|
|
|
|
{
|
|
|
|
case FScrollbar::noScroll:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageBackward:
|
2018-10-14 06:25:33 +02:00
|
|
|
distance = int(getClientWidth()) - padding_space;
|
2017-07-23 01:19:59 +02:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepBackward:
|
2017-12-30 03:54:05 +01:00
|
|
|
scrollLeft (distance);
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageForward:
|
2018-10-14 06:25:33 +02:00
|
|
|
distance = int(getClientWidth()) - padding_space;
|
2017-07-23 01:19:59 +02:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepForward:
|
2017-12-30 03:54:05 +01:00
|
|
|
scrollRight (distance);
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollJump:
|
2017-12-30 03:54:05 +01:00
|
|
|
scrollToX (hbar->getValue());
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollWheelUp:
|
2017-12-30 03:54:05 +01:00
|
|
|
scrollLeft (pagesize);
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollWheelDown:
|
2017-12-30 03:54:05 +01:00
|
|
|
scrollRight (pagesize);
|
2017-07-23 01:19:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-30 03:54:05 +01:00
|
|
|
if ( xoffset_before != xoffset )
|
|
|
|
inc_search.clear();
|
|
|
|
|
2017-07-23 01:19:59 +02:00
|
|
|
if ( isVisible() )
|
|
|
|
{
|
|
|
|
drawList();
|
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( scrollType >= FScrollbar::scrollStepBackward
|
2017-11-26 22:37:18 +01:00
|
|
|
&& scrollType <= FScrollbar::scrollWheelDown )
|
2017-07-23 01:19:59 +02:00
|
|
|
{
|
|
|
|
hbar->setValue (xoffset);
|
|
|
|
|
|
|
|
if ( hbar->isVisible() && xoffset_before != xoffset )
|
|
|
|
hbar->drawBar();
|
|
|
|
|
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|