2019-12-16 11:14:24 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fcombobox.cpp - Widget FComboBox *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2019-12-16 11:14:24 +01:00
|
|
|
* *
|
2021-05-07 23:17:23 +02:00
|
|
|
* Copyright 2019-2021 Markus Gans *
|
2019-12-16 11:14:24 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* 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 *
|
2019-12-16 11:14:24 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2019-12-16 11:14:24 +01:00
|
|
|
* 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/>. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
2020-08-23 00:32:41 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
#include "final/fapplication.h"
|
|
|
|
#include "final/fcolorpair.h"
|
|
|
|
#include "final/fcombobox.h"
|
|
|
|
#include "final/fevent.h"
|
|
|
|
#include "final/flabel.h"
|
|
|
|
#include "final/flineedit.h"
|
|
|
|
#include "final/flistbox.h"
|
|
|
|
#include "final/fmouse.h"
|
|
|
|
#include "final/fpoint.h"
|
|
|
|
#include "final/fsize.h"
|
|
|
|
#include "final/fstatusbar.h"
|
|
|
|
#include "final/fwidgetcolors.h"
|
|
|
|
|
|
|
|
namespace finalcut
|
|
|
|
{
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FDropDownListBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FDropDownListBox::FDropDownListBox (FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FWindow{parent}
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FDropDownListBox::~FDropDownListBox() // destructor
|
|
|
|
{
|
2020-04-13 12:40:11 +02:00
|
|
|
if ( FApplication::isQuit() )
|
2019-12-16 11:14:24 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
FWindow* parent_win{nullptr};
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
if ( const auto& parent = getParentWidget() )
|
2019-12-16 11:14:24 +01:00
|
|
|
parent_win = getWindowWidget(parent);
|
|
|
|
|
|
|
|
if ( parent_win )
|
|
|
|
setActiveWindow (parent_win);
|
|
|
|
else
|
|
|
|
switchToPrevWindow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FDropDownListBox::setGeometry ( const FPoint& pos, const FSize& size
|
|
|
|
, bool adjust )
|
|
|
|
{
|
|
|
|
FWindow::setGeometry (pos, size, adjust);
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
FSize new_size{size};
|
2019-12-16 11:14:24 +01:00
|
|
|
new_size.scaleBy(-1, 0);
|
2020-05-02 00:07:35 +02:00
|
|
|
list.setGeometry (FPoint{2, 1}, new_size, adjust);
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
else
|
2020-05-02 00:07:35 +02:00
|
|
|
list.setGeometry (FPoint{1, 1}, size, adjust);
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FDropDownListBox::show()
|
|
|
|
{
|
|
|
|
if ( ! isVisible() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
FWindow::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FDropDownListBox::hide()
|
|
|
|
{
|
|
|
|
if ( ! isVisible() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
FWindow::hide();
|
|
|
|
setOpenMenu(nullptr);
|
|
|
|
const auto& t_geometry = getTermGeometryWithShadow();
|
|
|
|
restoreVTerm (t_geometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FDropDownListBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FDropDownListBox::init()
|
|
|
|
{
|
|
|
|
setAlwaysOnTop();
|
|
|
|
ignorePadding();
|
|
|
|
setShadow();
|
|
|
|
// initialize geometry values
|
2020-05-02 00:07:35 +02:00
|
|
|
setGeometry (FPoint{1, 1}, FSize{3, 3}, false);
|
|
|
|
setMinimumSize (FSize{3, 3});
|
2019-12-16 11:14:24 +01:00
|
|
|
hide();
|
2020-05-02 00:07:35 +02:00
|
|
|
list.setGeometry (FPoint{1, 1}, FSize{3, 3}, false);
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FDropDownListBox::draw()
|
|
|
|
{
|
|
|
|
// Fill the background
|
2020-06-06 21:10:06 +02:00
|
|
|
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
2020-06-06 21:10:06 +02:00
|
|
|
setForegroundColor (wc->list_fg);
|
|
|
|
setBackgroundColor (wc->list_bg);
|
|
|
|
setColor();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-12-16 11:14:24 +01:00
|
|
|
setReverse(true);
|
|
|
|
|
|
|
|
clearArea();
|
|
|
|
drawShadow();
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-12-16 11:14:24 +01:00
|
|
|
setReverse(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FDropDownListBox::drawShadow()
|
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
2019-12-16 11:14:24 +01:00
|
|
|
finalcut::drawShadow(this);
|
2020-05-26 21:37:39 +02:00
|
|
|
setColor (wc->shadow_fg, wc->shadow_bg);
|
2020-12-31 20:45:10 +01:00
|
|
|
print() << FPoint{int(getWidth()) + 1, 1} << UniChar::FullBlock; // █
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FDropDownListBox::containsWidget (const FPoint& p)
|
|
|
|
{
|
|
|
|
// Check mouse click position for item, menu and all sub menus
|
|
|
|
|
|
|
|
FWidget* parent = getParentWidget();
|
|
|
|
|
|
|
|
if ( getTermGeometry().contains(p) )
|
|
|
|
return true;
|
|
|
|
else if ( parent && parent->isInstanceOf("FComboBox") )
|
|
|
|
return static_cast<FComboBox*>(parent)->getTermGeometry().contains(p);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FComboBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FComboBox::FComboBox (FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FWidget{parent}
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-11-24 21:06:39 +01:00
|
|
|
FComboBox::~FComboBox() noexcept = default; // destructor
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
// public methods of FComboBox
|
2019-12-23 03:53:32 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::setSize (const FSize& size, bool adjust)
|
|
|
|
{
|
|
|
|
FWidget::setSize (size, adjust);
|
2020-05-02 00:07:35 +02:00
|
|
|
FSize input_field_size{size};
|
2019-12-23 03:53:32 +01:00
|
|
|
input_field_size.scaleBy(-(1 + nf), 0);
|
|
|
|
input_field.setSize (input_field_size, adjust);
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::setGeometry ( const FPoint& pos, const FSize& size
|
|
|
|
, bool adjust )
|
|
|
|
{
|
|
|
|
FWidget::setGeometry (pos, size, adjust);
|
2020-05-02 00:07:35 +02:00
|
|
|
FSize input_field_size{size};
|
2019-12-16 11:14:24 +01:00
|
|
|
input_field_size.scaleBy(-(1 + nf), 0);
|
2020-05-02 00:07:35 +02:00
|
|
|
input_field.setGeometry (FPoint{1, 1}, input_field_size, adjust);
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FComboBox::setEnable (bool enable)
|
|
|
|
{
|
|
|
|
FWidget::setEnable(enable);
|
|
|
|
input_field.setEnable(enable);
|
|
|
|
return enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FComboBox::setFocus (bool enable)
|
|
|
|
{
|
|
|
|
FWidget::setFocus(enable);
|
|
|
|
input_field.setFocus(enable);
|
|
|
|
return enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FComboBox::setShadow (bool enable)
|
|
|
|
{
|
|
|
|
if ( enable
|
2020-12-31 20:45:10 +01:00
|
|
|
&& FTerm::getEncoding() != Encoding::VT100
|
|
|
|
&& FTerm::getEncoding() != Encoding::ASCII )
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
setFlags().shadow = true;
|
2020-05-02 00:07:35 +02:00
|
|
|
setShadowSize(FSize{1, 1});
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setFlags().shadow = false;
|
2020-05-02 00:07:35 +02:00
|
|
|
setShadowSize(FSize{0, 0});
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return getFlags().shadow;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FComboBox::setEditable (bool enable)
|
|
|
|
{
|
|
|
|
if ( is_editable == enable )
|
|
|
|
return is_editable;
|
|
|
|
|
|
|
|
if ( enable )
|
|
|
|
unsetVisibleCursor();
|
|
|
|
else
|
|
|
|
setVisibleCursor();
|
|
|
|
|
|
|
|
input_field.setReadOnly(! enable);
|
|
|
|
return (is_editable = enable);
|
|
|
|
}
|
|
|
|
|
2020-01-09 19:21:16 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::setCurrentItem (std::size_t index)
|
|
|
|
{
|
|
|
|
if ( index > getCount() )
|
|
|
|
index = getCount();
|
|
|
|
else if ( index < 1 )
|
|
|
|
index = 1;
|
|
|
|
|
|
|
|
if ( index == list_window.list.currentItem() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_window.list.setCurrentItem(index);
|
|
|
|
input_field = list_window.list.getItem(index).getText();
|
|
|
|
input_field.redraw();
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::setMaxVisibleItems (std::size_t items)
|
|
|
|
{
|
|
|
|
// Sets the maximum height of the combo box in elements
|
|
|
|
|
|
|
|
if ( items > getCount() )
|
|
|
|
max_items = getCount();
|
|
|
|
else
|
|
|
|
max_items = items;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-19 20:38:52 +02:00
|
|
|
void FComboBox::insert (const FListBoxItem& listItem)
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
list_window.list.insert(listItem);
|
|
|
|
|
|
|
|
if ( getCount() == 1 )
|
|
|
|
input_field = list_window.list.getItem(1).getText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::remove (std::size_t item)
|
|
|
|
{
|
|
|
|
list_window.list.remove(item);
|
|
|
|
|
|
|
|
if ( ! list_window.isEmpty() )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t index = list_window.list.currentItem();
|
2020-01-09 19:21:16 +01:00
|
|
|
input_field = list_window.list.getItem(index).getText();
|
2019-12-16 11:14:24 +01:00
|
|
|
input_field.redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( list_window.isShown() )
|
|
|
|
{
|
|
|
|
// Adjusting the size of the drop-down list
|
|
|
|
hideDropDown();
|
|
|
|
showDropDown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::clear()
|
|
|
|
{
|
|
|
|
if ( list_window.isShown() )
|
|
|
|
hideDropDown();
|
|
|
|
|
|
|
|
list_window.list.clear();
|
|
|
|
input_field.clear();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::showDropDown()
|
|
|
|
{
|
|
|
|
if ( list_window.isEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
static constexpr std::size_t border = 2; // Size of the top and bottom border
|
|
|
|
setOpenMenu(&list_window);
|
2020-05-02 00:07:35 +02:00
|
|
|
FPoint p{getTermPos()};
|
2019-12-16 11:14:24 +01:00
|
|
|
p.move(0 - int(nf), 1);
|
|
|
|
setClickedWidget(&list_window.list);
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t w = getWidth();
|
|
|
|
const std::size_t h = ( getCount() <= max_items ) ? getCount() : max_items;
|
2020-05-02 00:07:35 +02:00
|
|
|
list_window.setGeometry(p, FSize{w + std::size_t(nf), h + border});
|
2019-12-16 11:14:24 +01:00
|
|
|
list_window.show();
|
|
|
|
list_window.list.setFocus();
|
|
|
|
list_window.redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::hideDropDown()
|
|
|
|
{
|
|
|
|
if ( list_window.isHidden() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_window.hide();
|
|
|
|
input_field.setFocus();
|
|
|
|
input_field.redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
|
|
|
if ( ! isEnabled() )
|
|
|
|
return;
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
const auto key = ev->key();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( key == FKey::Tab )
|
|
|
|
{
|
|
|
|
focusNextChild();
|
|
|
|
}
|
|
|
|
else if ( key == FKey::Back_tab )
|
|
|
|
{
|
|
|
|
focusPrevChild();
|
|
|
|
}
|
|
|
|
else if ( key == FKey::Up )
|
|
|
|
{
|
|
|
|
onePosUp();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
else if ( key == FKey::Down )
|
|
|
|
{
|
|
|
|
onePosDown();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
else if ( key == FKey::Meta_up
|
|
|
|
|| key == FKey::Ctrl_up
|
|
|
|
|| key == FKey::Escape
|
|
|
|
|| key == FKey::Escape_mintty )
|
|
|
|
{
|
|
|
|
hideDropDown();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
else if ( key == FKey::F4
|
|
|
|
|| key == FKey::Meta_down
|
|
|
|
|| key == FKey::Ctrl_down )
|
|
|
|
{
|
|
|
|
showDropDown();
|
|
|
|
ev->accept();
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::onMouseDown (FMouseEvent* ev)
|
|
|
|
{
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( ev->getButton() != MouseButton::Left )
|
2019-12-16 11:14:24 +01:00
|
|
|
return;
|
|
|
|
|
2021-04-27 11:51:53 +02:00
|
|
|
setWidgetFocus(this);
|
2020-02-02 22:34:27 +01:00
|
|
|
const int mouse_x = ev->getX();
|
|
|
|
const int mouse_y = ev->getY();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
if ( mouse_x >= int(getWidth()) - nf
|
|
|
|
&& mouse_x <= int(getWidth()) && mouse_y == 1 )
|
|
|
|
{
|
2021-04-27 11:51:53 +02:00
|
|
|
redraw();
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
if ( list_window.isHidden() )
|
|
|
|
showDropDown();
|
|
|
|
else
|
|
|
|
list_window.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::onMouseMove (FMouseEvent* ev)
|
|
|
|
{
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( ev->getButton() != MouseButton::Left )
|
2019-12-16 11:14:24 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( isMouseOverListWindow(ev->getTermPos()) )
|
|
|
|
{
|
2020-10-25 01:21:45 +02:00
|
|
|
passEventToListWindow(*ev); // Event handover to window list
|
2019-12-16 11:14:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::onWheel (FWheelEvent* ev)
|
|
|
|
{
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( ev->getWheel() == MouseWheel::Up )
|
|
|
|
onePosUp();
|
|
|
|
else if ( ev->getWheel() == MouseWheel::Down )
|
|
|
|
onePosDown();
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::onFocusOut (FFocusEvent*)
|
|
|
|
{
|
|
|
|
hideDropDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FComboBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FComboBox::isMouseOverListWindow (const FPoint& termpos)
|
|
|
|
{
|
|
|
|
if ( list_window.isShown() )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
auto list_geometry = list_window.getTermGeometry();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
if ( list_geometry.contains(termpos) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::init()
|
|
|
|
{
|
|
|
|
setShadow();
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& parent_widget = getParentWidget();
|
2019-12-16 11:14:24 +01:00
|
|
|
FLabel* label = input_field.getLabelObject();
|
|
|
|
label->setParent(getParent());
|
|
|
|
label->setForegroundColor (parent_widget->getForegroundColor());
|
|
|
|
label->setBackgroundColor (parent_widget->getBackgroundColor());
|
|
|
|
input_field.setLabelAssociatedWidget(this);
|
|
|
|
input_field.unsetShadow();
|
|
|
|
adjustSize();
|
|
|
|
initCallbacks();
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2019-12-16 11:14:24 +01:00
|
|
|
nf = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::initCallbacks()
|
|
|
|
{
|
|
|
|
input_field.addCallback
|
|
|
|
(
|
|
|
|
"mouse-press",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &FComboBox::cb_inputFieldSwitch
|
2019-12-16 11:14:24 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
input_field.addCallback
|
|
|
|
(
|
|
|
|
"mouse-move",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &FComboBox::cb_inputFieldHandOver
|
2019-12-16 11:14:24 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
list_window.list.addCallback
|
|
|
|
(
|
|
|
|
"row-changed",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &FComboBox::cb_setInputField
|
2019-12-16 11:14:24 +01:00
|
|
|
);
|
|
|
|
|
2019-12-23 14:20:31 +01:00
|
|
|
for (const auto& signal : {"row-selected", "clicked"})
|
|
|
|
{
|
|
|
|
list_window.list.addCallback
|
|
|
|
(
|
|
|
|
signal,
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &FComboBox::cb_closeComboBox
|
2019-12-23 14:20:31 +01:00
|
|
|
);
|
|
|
|
}
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::draw()
|
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
const FColorPair button_color = [this, &wc] ()
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
if ( list_window.isEmpty() )
|
2020-05-26 21:37:39 +02:00
|
|
|
return FColorPair { wc->scrollbar_button_inactive_fg
|
|
|
|
, wc->scrollbar_button_inactive_bg };
|
2019-12-16 11:14:24 +01:00
|
|
|
else
|
2020-05-26 21:37:39 +02:00
|
|
|
return FColorPair { wc->scrollbar_button_fg
|
|
|
|
, wc->scrollbar_button_bg };
|
2019-12-16 11:14:24 +01:00
|
|
|
}();
|
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{int(getWidth()) - nf, 1}
|
2019-12-16 11:14:24 +01:00
|
|
|
<< button_color;
|
|
|
|
|
2020-08-23 00:32:41 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
|
|
|
print() << NF_button_arrow_down;
|
|
|
|
else
|
2020-12-31 20:45:10 +01:00
|
|
|
print() << UniChar::BlackDownPointingTriangle; // ▼
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
if ( getFlags().shadow )
|
|
|
|
drawShadow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::onePosUp()
|
|
|
|
{
|
2020-01-09 19:21:16 +01:00
|
|
|
std::size_t index = list_window.list.currentItem();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2020-01-09 19:21:16 +01:00
|
|
|
if ( index > 1 )
|
|
|
|
index--;
|
2019-12-16 11:14:24 +01:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2020-01-09 19:21:16 +01:00
|
|
|
list_window.list.setCurrentItem(index);
|
|
|
|
input_field = list_window.list.getItem(index).getText();
|
2019-12-16 11:14:24 +01:00
|
|
|
input_field.redraw();
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FComboBox::onePosDown()
|
|
|
|
{
|
2020-01-09 19:21:16 +01:00
|
|
|
std::size_t index = list_window.list.currentItem();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2020-01-09 19:21:16 +01:00
|
|
|
if ( index < getCount() )
|
|
|
|
index++;
|
2019-12-16 11:14:24 +01:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2020-01-09 19:21:16 +01:00
|
|
|
list_window.list.setCurrentItem(index);
|
|
|
|
input_field = list_window.list.getItem(index).getText();
|
2019-12-16 11:14:24 +01:00
|
|
|
input_field.redraw();
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-10-25 01:21:45 +02:00
|
|
|
void FComboBox::passEventToListWindow (const FMouseEvent& ev)
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
// Mouse event handover to list window
|
|
|
|
|
2020-10-25 01:21:45 +02:00
|
|
|
const auto& t = ev.getTermPos();
|
2019-12-16 11:14:24 +01:00
|
|
|
const auto& p = list_window.list.termToWidgetPos(t);
|
2020-12-31 20:45:10 +01:00
|
|
|
const auto b = ev.getButton();
|
|
|
|
const auto& _ev = \
|
|
|
|
std::make_shared<FMouseEvent>(Event::MouseMove, p, t, b);
|
|
|
|
setClickedWidget(&list_window.list);
|
|
|
|
list_window.list.setFocus();
|
|
|
|
list_window.list.onMouseMove(_ev.get());
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-13 23:58:32 +02:00
|
|
|
void FComboBox::processClick() const
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
emitCallback("clicked");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-13 23:58:32 +02:00
|
|
|
void FComboBox::processChanged() const
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
emitCallback("row-changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void FComboBox::cb_setInputField()
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
auto& list = list_window.list;
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t index = list.currentItem();
|
2020-01-09 19:21:16 +01:00
|
|
|
input_field = list.getItem(index).getText();
|
2019-12-16 11:14:24 +01:00
|
|
|
input_field.redraw();
|
|
|
|
processChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void FComboBox::cb_closeComboBox()
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
|
|
|
hideDropDown();
|
|
|
|
processClick();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void FComboBox::cb_inputFieldSwitch()
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
2021-06-19 23:05:18 +02:00
|
|
|
auto& mouse = FMouseControl::getInstance();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2021-05-07 23:17:23 +02:00
|
|
|
if ( ! mouse.isLeftButtonPressed() )
|
2019-12-16 11:14:24 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( list_window.isShown() )
|
|
|
|
{
|
|
|
|
hideDropDown();
|
|
|
|
}
|
|
|
|
else if ( ! is_editable )
|
|
|
|
{
|
2021-04-27 11:51:53 +02:00
|
|
|
setWidgetFocus(this);
|
2019-12-16 11:14:24 +01:00
|
|
|
showDropDown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void FComboBox::cb_inputFieldHandOver()
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
2021-06-19 23:05:18 +02:00
|
|
|
auto& mouse = FMouseControl::getInstance();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2021-05-07 23:17:23 +02:00
|
|
|
if ( list_window.isHidden() )
|
2019-12-16 11:14:24 +01:00
|
|
|
return;
|
|
|
|
|
2021-05-07 23:17:23 +02:00
|
|
|
const auto& t = mouse.getPos();
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& p = list_window.list.termToWidgetPos(t);
|
2021-05-07 23:17:23 +02:00
|
|
|
const auto b = ( mouse.isLeftButtonPressed() ) ? MouseButton::Left : MouseButton::None;
|
2020-12-31 20:45:10 +01:00
|
|
|
const auto& _ev = \
|
|
|
|
std::make_shared<FMouseEvent>(Event::MouseMove, p, t, b);
|
|
|
|
setClickedWidget(&list_window.list);
|
|
|
|
list_window.list.setFocus();
|
|
|
|
list_window.list.onMouseMove(_ev.get());
|
2019-12-16 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// non-member functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void closeOpenComboBox()
|
|
|
|
{
|
|
|
|
// Close open comboboxes
|
|
|
|
auto openmenu = FWidget::getOpenMenu();
|
|
|
|
|
|
|
|
if ( ! openmenu )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( openmenu->isInstanceOf("FDropDownListBox") )
|
|
|
|
{
|
|
|
|
auto drop_down = static_cast<FDropDownListBox*>(openmenu);
|
|
|
|
drop_down->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool closeComboBox ( FDropDownListBox* list_window
|
|
|
|
, const FPoint& mouse_position )
|
|
|
|
{
|
|
|
|
// Close the drop down list box
|
|
|
|
|
|
|
|
if ( ! list_window )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( list_window->containsWidget(mouse_position) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
list_window->hide();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace finalcut
|