2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fwidget.cpp - Intermediate base class for all widget objects *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-01-20 21:40:00 +01:00
|
|
|
* Copyright 2015-2020 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 <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fevent.h"
|
2020-05-13 23:47:14 +02:00
|
|
|
#include "final/flog.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fmenubar.h"
|
2020-05-29 00:27:25 +02:00
|
|
|
#include "final/fstartoptions.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fstatusbar.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fstring.h"
|
2019-08-18 02:04:44 +02:00
|
|
|
#include "final/ftermdata.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fwidget.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fwidgetcolors.h"
|
2019-09-08 02:04:24 +02:00
|
|
|
#include "final/fwindow.h"
|
2016-10-11 04:57:36 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
// global FWidget object
|
2020-03-05 21:30:54 +01:00
|
|
|
static FWidget* root_widget{nullptr};
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
// static class attributes
|
2019-10-06 22:35:00 +02:00
|
|
|
FStatusBar* FWidget::statusbar{nullptr};
|
|
|
|
FMenuBar* FWidget::menubar{nullptr};
|
|
|
|
FWidget* FWidget::show_root_widget{nullptr};
|
|
|
|
FWidget* FWidget::redraw_root_widget{nullptr};
|
|
|
|
FWidget::FWidgetList* FWidget::window_list{nullptr};
|
|
|
|
FWidget::FWidgetList* FWidget::dialog_list{nullptr};
|
|
|
|
FWidget::FWidgetList* FWidget::always_on_top_list{nullptr};
|
|
|
|
FWidget::FWidgetList* FWidget::close_widget{nullptr};
|
2020-06-06 21:10:06 +02:00
|
|
|
bool FWidget::init_terminal{false};
|
2019-10-06 22:35:00 +02:00
|
|
|
bool FWidget::init_desktop{false};
|
|
|
|
uInt FWidget::modal_dialog_counter{};
|
2016-11-12 22:59:48 +01:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FWidget
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2020-06-06 21:10:06 +02:00
|
|
|
FWidget::FWidget (FWidget* parent)
|
|
|
|
: FVTerm{}
|
2020-05-24 23:55:08 +02:00
|
|
|
, FObject{parent}
|
2015-09-22 04:18:20 +02:00
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
// init bit field with 0
|
|
|
|
memset (&flags, 0, sizeof(flags));
|
|
|
|
|
2018-11-05 23:19:03 +01:00
|
|
|
flags.active = true; // Enable widget by default
|
|
|
|
flags.visible = true; // A widget is visible by default
|
|
|
|
flags.focusable = true; // A widget is focusable by default
|
|
|
|
flags.visible_cursor = true; // A widget has a visible cursor by default
|
2018-12-09 18:24:31 +01:00
|
|
|
setWidgetProperty (true); // This FObject is a widget
|
2017-06-11 17:47:50 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( ! parent )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2020-03-05 21:30:54 +01:00
|
|
|
if ( root_widget )
|
2020-01-20 21:40:00 +01:00
|
|
|
{
|
2020-04-13 12:40:11 +02:00
|
|
|
auto ftermdata = FTerm::getFTermData();
|
2020-01-20 21:40:00 +01:00
|
|
|
ftermdata->setExitMessage("FWidget: No parent defined! "
|
|
|
|
"There should be only one root object");
|
|
|
|
FApplication::exit(EXIT_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:30:54 +01:00
|
|
|
initRootWidget();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-09 19:13:38 +02:00
|
|
|
woffset = parent->wclient_offset;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2020-06-06 21:10:06 +02:00
|
|
|
|
|
|
|
flags.visible_cursor = false;
|
|
|
|
double_flatline_mask.top.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.right.resize (getHeight(), false);
|
|
|
|
double_flatline_mask.bottom.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.left.resize (getHeight(), false);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FWidget::~FWidget() // destructor
|
|
|
|
{
|
|
|
|
processDestroy();
|
2017-11-03 22:57:40 +01:00
|
|
|
delCallbacks();
|
2020-04-15 23:17:42 +02:00
|
|
|
auto app_object = FApplication::getApplicationObject();
|
|
|
|
app_object->removeQueuedEvent(this);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-07-31 20:25:25 +02:00
|
|
|
// unset clicked widget
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( this == getClickedWidget() )
|
2019-09-08 02:04:24 +02:00
|
|
|
setClickedWidget(nullptr);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-07-31 20:25:25 +02:00
|
|
|
// unset the local window widget focus
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( flags.focus )
|
2016-07-31 20:25:25 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
if ( auto window = FWindow::getWindowWidget(this) )
|
2019-09-09 19:13:38 +02:00
|
|
|
if ( window != this )
|
|
|
|
window->setWindowFocusWidget(nullptr);
|
2016-07-31 20:25:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// unset the global widget focus
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( this == FWidget::getFocusWidget() )
|
2019-09-08 02:04:24 +02:00
|
|
|
FWidget::setFocusWidget(nullptr);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-07-31 20:25:25 +02:00
|
|
|
// unset main widget
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( this == getMainWidget() )
|
|
|
|
{
|
2019-09-08 02:04:24 +02:00
|
|
|
setMainWidget(nullptr);
|
2015-05-23 13:35:12 +02:00
|
|
|
quit();
|
|
|
|
}
|
|
|
|
|
2019-10-20 20:06:33 +02:00
|
|
|
accelerator_list.clear();
|
2019-09-01 23:29:27 +02:00
|
|
|
|
2016-07-31 20:25:25 +02:00
|
|
|
// finish the program
|
2020-03-05 21:30:54 +01:00
|
|
|
if ( root_widget == this )
|
2017-09-17 01:50:41 +02:00
|
|
|
finish();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// public methods of FWidget
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget* FWidget::getRootWidget() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto obj = const_cast<FWidget*>(this);
|
|
|
|
auto p_obj = getParentWidget();
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
while ( ! obj->isRootWidget() && p_obj )
|
|
|
|
{
|
|
|
|
obj = p_obj;
|
|
|
|
p_obj = p_obj->getParentWidget();
|
|
|
|
}
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return obj;
|
|
|
|
}
|
2015-06-21 23:27:10 +02:00
|
|
|
|
2017-06-11 17:47:50 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-06-14 01:06:48 +02:00
|
|
|
FWidget* FWidget::getParentWidget() const
|
2017-06-11 17:47:50 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto p_obj = getParent();
|
2017-06-11 17:47:50 +02:00
|
|
|
|
|
|
|
if ( p_obj && p_obj->isWidget() )
|
|
|
|
return static_cast<FWidget*>(p_obj);
|
|
|
|
else
|
2020-02-19 21:59:13 +01:00
|
|
|
return nullptr;
|
2017-06-11 17:47:50 +02:00
|
|
|
}
|
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-09-17 01:50:41 +02:00
|
|
|
FWidget* FWidget::getFirstFocusableWidget (FObjectList list)
|
2017-01-28 22:03:15 +01:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( list.empty() )
|
2020-02-19 21:59:13 +01:00
|
|
|
return nullptr;
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = list.begin();
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
while ( iter != list.end() )
|
2017-01-28 22:03:15 +01:00
|
|
|
{
|
2017-06-11 17:47:50 +02:00
|
|
|
if ( (*iter)->isWidget() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto child = static_cast<FWidget*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2017-06-11 17:47:50 +02:00
|
|
|
if ( child->isEnabled() && child->acceptFocus() )
|
|
|
|
return child;
|
|
|
|
}
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
2020-02-19 21:59:13 +01:00
|
|
|
return nullptr;
|
2017-01-28 22:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-17 01:50:41 +02:00
|
|
|
FWidget* FWidget::getLastFocusableWidget (FObjectList list)
|
2017-01-28 22:03:15 +01:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( list.empty() )
|
2020-02-19 21:59:13 +01:00
|
|
|
return nullptr;
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = list.end();
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
2017-06-11 17:47:50 +02:00
|
|
|
|
|
|
|
if ( ! (*iter)->isWidget() )
|
|
|
|
continue;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto child = static_cast<FWidget*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( child->isEnabled() && child->acceptFocus() )
|
|
|
|
return child;
|
|
|
|
}
|
2019-10-06 22:35:00 +02:00
|
|
|
while ( iter != list.begin() );
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2020-02-19 21:59:13 +01:00
|
|
|
return nullptr;
|
2017-01-28 22:03:15 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
std::vector<bool>& FWidget::doubleFlatLine_ref (fc::sides side)
|
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
assert ( side == fc::top
|
2017-11-26 22:37:18 +01:00
|
|
|
|| side == fc::right
|
|
|
|
|| side == fc::bottom
|
|
|
|
|| side == fc::left );
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
switch ( side )
|
2016-07-14 23:55:22 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::top:
|
|
|
|
return double_flatline_mask.top;
|
|
|
|
|
|
|
|
case fc::right:
|
|
|
|
return double_flatline_mask.right;
|
|
|
|
|
|
|
|
case fc::bottom:
|
|
|
|
return double_flatline_mask.bottom;
|
|
|
|
|
|
|
|
case fc::left:
|
|
|
|
return double_flatline_mask.left;
|
2016-07-14 23:55:22 +02:00
|
|
|
}
|
|
|
|
|
2020-04-24 00:34:26 +02:00
|
|
|
return double_flatline_mask.top;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
const FPoint FWidget::getPrintPos()
|
2019-10-06 22:35:00 +02:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& cur = getPrintCursor();
|
2020-05-02 00:07:35 +02:00
|
|
|
return { cur.getX() - woffset.getX1() - getX() + 1
|
|
|
|
, cur.getY() - woffset.getY1() - getY() + 1 };
|
2019-10-06 22:35:00 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setMainWidget (FWidget* obj)
|
|
|
|
{
|
2018-10-21 21:06:52 +02:00
|
|
|
main_widget = obj;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto app_object = FApplication::getApplicationObject();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-10-21 21:06:52 +02:00
|
|
|
if ( obj && app_object && ! getFocusWidget() )
|
|
|
|
app_object->focusFirstChild();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWidget::setVisible (bool enable)
|
|
|
|
{
|
|
|
|
return (flags.visible = enable);
|
|
|
|
}
|
|
|
|
|
2017-06-05 16:11:25 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
bool FWidget::setEnable (bool enable)
|
2017-06-11 17:47:50 +02:00
|
|
|
{
|
2020-04-18 13:33:42 +02:00
|
|
|
if ( enable )
|
|
|
|
emitCallback("enable");
|
|
|
|
else
|
|
|
|
emitCallback("disable");
|
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
return (flags.active = enable);
|
2017-06-05 16:11:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
bool FWidget::setFocus (bool enable)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( ! isEnabled() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
if ( flags.focus == enable )
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto last_focus = FWidget::getFocusWidget();
|
2017-01-26 00:31:07 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// set widget focus
|
2018-12-22 23:50:10 +01:00
|
|
|
if ( enable && ! flags.focus )
|
2016-10-01 23:18:49 +02:00
|
|
|
{
|
2017-01-26 00:31:07 +01:00
|
|
|
if ( last_focus )
|
|
|
|
last_focus->unsetFocus();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2019-01-07 05:03:00 +01:00
|
|
|
FWidget::setFocusWidget(this);
|
2016-10-01 23:18:49 +02:00
|
|
|
}
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
// Activates the window with the focused widget
|
|
|
|
setWindowFocus (enable);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
// Set status bar text for widget focus
|
|
|
|
setStatusbarText (enable);
|
2018-12-22 23:50:10 +01:00
|
|
|
return (flags.focus = enable);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 23:02:53 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::resetColors()
|
|
|
|
{
|
|
|
|
if ( ! hasChildren() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (auto&& child : getChildren())
|
|
|
|
{
|
|
|
|
if ( child->isWidget() )
|
|
|
|
{
|
|
|
|
auto widget = static_cast<FWidget*>(child);
|
|
|
|
widget->resetColors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::useParentWidgetColor()
|
|
|
|
{
|
|
|
|
const auto& parent_widget = getParentWidget();
|
|
|
|
|
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
setForegroundColor (parent_widget->getForegroundColor());
|
|
|
|
setBackgroundColor (parent_widget->getBackgroundColor());
|
|
|
|
}
|
|
|
|
else // Fallback
|
|
|
|
{
|
|
|
|
const auto& wc = getColorTheme();
|
|
|
|
setForegroundColor (wc->dialog_fg);
|
|
|
|
setBackgroundColor (wc->dialog_bg);
|
|
|
|
}
|
|
|
|
|
|
|
|
setColor();
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-30 12:17:48 +01:00
|
|
|
void FWidget::setColor()
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
// Changes colors to the widget default colors
|
|
|
|
setColor (foreground_color, background_color);
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setX (int x, bool adjust)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getX() == x && wsize.getX() == x )
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! isWindowWidget() && x < 1 )
|
|
|
|
x = 1;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
wsize.setX(x);
|
|
|
|
adjust_wsize.setX(x);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
adjustSize();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setY (int y, bool adjust)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getY() == y && wsize.getY() == y )
|
|
|
|
return;
|
2016-08-21 21:27:44 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! isWindowWidget() && y < 1 )
|
|
|
|
y = 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
wsize.setY(y);
|
|
|
|
adjust_wsize.setY(y);
|
|
|
|
|
|
|
|
if ( adjust )
|
|
|
|
adjustSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FWidget::setPos (const FPoint& p, bool adjust)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
FPoint pos{p};
|
2019-01-21 03:42:18 +01:00
|
|
|
|
|
|
|
if ( getX() == pos.getX() && wsize.getX() == pos.getX()
|
|
|
|
&& getY() == pos.getY() && wsize.getY() == pos.getY() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( ! isWindowWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
if ( pos.getX() < 1 )
|
|
|
|
pos.setX(1);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
if ( pos.getY() < 1 )
|
|
|
|
pos.setY(1);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
wsize.setPos(pos);
|
|
|
|
adjust_wsize.setPos(pos);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
adjustSize();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FWidget::setWidth (std::size_t width, bool adjust)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
width = std::min (width, size_hints.max_width);
|
|
|
|
width = std::max (width, size_hints.min_width);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getWidth() == width && wsize.getWidth() == width )
|
|
|
|
return;
|
2016-01-17 23:37:52 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( width < 1 )
|
|
|
|
width = 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
wsize.setWidth(width);
|
|
|
|
adjust_wsize.setWidth(width);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
adjustSize();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
double_flatline_mask.top.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.bottom.resize (getWidth(), false);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FWidget::setHeight (std::size_t height, bool adjust)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
height = std::min (height, size_hints.max_height);
|
|
|
|
height = std::max (height, size_hints.min_height);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getHeight() == height && wsize.getHeight() == height )
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( height < 1 )
|
|
|
|
height = 1;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
wsize.setHeight(height);
|
|
|
|
adjust_wsize.setHeight(height);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
adjustSize();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
double_flatline_mask.right.resize (getHeight(), false);
|
|
|
|
double_flatline_mask.left.resize (getHeight(), false);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 21:11:32 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FWidget::setSize (const FSize& size, bool adjust)
|
2016-05-16 21:11:32 +02:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
std::size_t width = size.getWidth();
|
|
|
|
std::size_t height = size.getHeight();
|
2016-11-02 00:37:58 +01:00
|
|
|
width = std::min (width, size_hints.max_width);
|
|
|
|
width = std::max (width, size_hints.min_width);
|
|
|
|
height = std::min (height, size_hints.max_height);
|
|
|
|
height = std::max (height, size_hints.min_height);
|
|
|
|
|
|
|
|
if ( getWidth() == width && wsize.getWidth() == width
|
2017-11-26 22:37:18 +01:00
|
|
|
&& getHeight() == height && wsize.getHeight() == height )
|
2016-05-16 21:11:32 +02:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( width < 1 )
|
|
|
|
width = 1;
|
2016-05-16 21:11:32 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( height < 1 )
|
|
|
|
height = 1;
|
|
|
|
|
|
|
|
wsize.setWidth(width);
|
|
|
|
wsize.setHeight(height);
|
|
|
|
adjust_wsize.setWidth(width);
|
|
|
|
adjust_wsize.setHeight(height);
|
|
|
|
|
|
|
|
if ( adjust )
|
|
|
|
adjustSize();
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
double_flatline_mask.top.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.right.resize (getHeight(), false);
|
|
|
|
double_flatline_mask.bottom.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.left.resize (getHeight(), false);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setTopPadding (int top, bool adjust)
|
|
|
|
{
|
|
|
|
if ( padding.top == top )
|
|
|
|
return;
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
padding.top = top;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( adjust )
|
|
|
|
{
|
|
|
|
if ( isRootWidget() )
|
2016-05-16 21:11:32 +02:00
|
|
|
{
|
2020-03-05 21:30:54 +01:00
|
|
|
auto r = root_widget;
|
2019-09-09 19:13:38 +02:00
|
|
|
r->wclient_offset.setY1 (r->padding.top);
|
2016-11-02 00:37:58 +01:00
|
|
|
adjustSizeGlobal();
|
2016-05-16 21:11:32 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
|
|
|
adjustSize();
|
2016-05-16 21:11:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setLeftPadding (int left, bool adjust)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( padding.left == left )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
padding.left = left;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
{
|
|
|
|
if ( isRootWidget() )
|
|
|
|
{
|
2020-03-05 21:30:54 +01:00
|
|
|
auto r = root_widget;
|
2019-09-09 19:13:38 +02:00
|
|
|
r->wclient_offset.setX1 (r->padding.left);
|
2016-11-02 00:37:58 +01:00
|
|
|
adjustSizeGlobal();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
adjustSize();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:44:11 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setBottomPadding (int bottom, bool adjust)
|
2015-08-09 23:44:11 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( padding.bottom == bottom )
|
2015-08-09 23:44:11 +02:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
padding.bottom = bottom;
|
2015-08-09 23:44:11 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
{
|
|
|
|
if ( isRootWidget() )
|
|
|
|
{
|
2020-03-05 21:30:54 +01:00
|
|
|
auto r = root_widget;
|
2019-09-09 19:13:38 +02:00
|
|
|
r->wclient_offset.setY2 (int(r->getHeight()) - 1 - r->padding.bottom);
|
2016-11-02 00:37:58 +01:00
|
|
|
adjustSizeGlobal();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
adjustSize();
|
|
|
|
}
|
2015-08-09 23:44:11 +02:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setRightPadding (int right, bool adjust)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( padding.right == right )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
padding.right = right;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
{
|
|
|
|
if ( isRootWidget() )
|
|
|
|
{
|
2020-03-05 21:30:54 +01:00
|
|
|
auto r = root_widget;
|
2019-09-09 19:13:38 +02:00
|
|
|
r->wclient_offset.setX2 (int(r->getWidth()) - 1 - r->padding.right);
|
2016-11-02 00:37:58 +01:00
|
|
|
adjustSizeGlobal();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
adjustSize();
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FWidget::setTermSize (const FSize& size)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
// Set xterm size to width x height
|
2018-10-14 06:25:33 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isXTerminal() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
root_widget->wsize.setRect(FPoint{1, 1}, size);
|
2020-03-05 21:30:54 +01:00
|
|
|
root_widget->adjust_wsize = root_widget->wsize;
|
2019-01-21 03:42:18 +01:00
|
|
|
FTerm::setTermSize(size); // width = columns / height = lines
|
2016-11-02 00:37:58 +01:00
|
|
|
detectTermSize();
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FWidget::setGeometry (const FPoint& p, const FSize& s, bool adjust)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-08-06 17:02:19 +02:00
|
|
|
// Sets the geometry of the widget relative to its parent
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const int x = p.getX();
|
|
|
|
const int y = p.getY();
|
2019-01-21 03:42:18 +01:00
|
|
|
std::size_t w = s.getWidth();
|
|
|
|
std::size_t h = s.getHeight();
|
2016-11-02 00:37:58 +01:00
|
|
|
w = std::min (w, size_hints.max_width);
|
|
|
|
w = std::max (w, size_hints.min_width);
|
|
|
|
h = std::min (h, size_hints.max_height);
|
|
|
|
h = std::max (h, size_hints.min_height);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
if ( getPos() == p && getWidth() == w && getHeight() == h )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! isWindowWidget() )
|
|
|
|
{
|
2017-09-17 21:32:46 +02:00
|
|
|
( x < 1 ) ? wsize.setX(1) : wsize.setX(x);
|
|
|
|
( y < 1 ) ? wsize.setY(1) : wsize.setY(y);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wsize.setX(x);
|
|
|
|
wsize.setY(y);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
( w < 1 ) ? wsize.setWidth(1) : wsize.setWidth(w);
|
|
|
|
( h < 1 ) ? wsize.setHeight(1) : wsize.setHeight(h);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
adjust_wsize = wsize;
|
2020-02-02 22:34:27 +01:00
|
|
|
const int term_x = getTermX();
|
|
|
|
const int term_y = getTermY();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-09-09 19:13:38 +02:00
|
|
|
wclient_offset.setCoordinates ( term_x - 1 + padding.left
|
|
|
|
, term_y - 1 + padding.top
|
|
|
|
, term_x - 2 + int(getWidth()) - padding.right
|
|
|
|
, term_y - 2 + int(getHeight()) - padding.bottom );
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
double_flatline_mask.top.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.right.resize (getHeight(), false);
|
|
|
|
double_flatline_mask.bottom.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.left.resize (getHeight(), false);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( adjust )
|
|
|
|
adjustSize();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
bool FWidget::setCursorPos (const FPoint& pos)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
// sets the input cursor position
|
2017-02-24 00:30:07 +01:00
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
widget_cursor_position.setPoint(pos);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( ! flags.focus || isWindowWidget() )
|
2017-02-24 00:30:07 +01:00
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
if ( ! FWindow::getWindowWidget(this) )
|
2017-02-24 00:30:07 +01:00
|
|
|
return false;
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& area = getPrintArea();
|
2017-03-08 23:48:30 +01:00
|
|
|
|
|
|
|
if ( area->widget )
|
2017-02-24 00:30:07 +01:00
|
|
|
{
|
2019-09-09 19:13:38 +02:00
|
|
|
int woffsetX = getTermX() - area->widget->getTermX();
|
|
|
|
int woffsetY = getTermY() - area->widget->getTermY();
|
2017-03-08 23:48:30 +01:00
|
|
|
|
|
|
|
if ( isChildPrintArea() )
|
|
|
|
{
|
2019-09-09 19:13:38 +02:00
|
|
|
woffsetX += (1 - area->widget->getLeftPadding());
|
|
|
|
woffsetY += (1 - area->widget->getTopPadding());
|
2017-03-08 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 21:10:06 +02:00
|
|
|
bool visible = ! isCursorHideable() || flags.visible_cursor;
|
2020-05-02 00:07:35 +02:00
|
|
|
setAreaCursor ( { woffsetX + pos.getX()
|
|
|
|
, woffsetY + pos.getY() }
|
2020-06-06 21:10:06 +02:00
|
|
|
, visible
|
2017-02-24 00:30:07 +01:00
|
|
|
, area );
|
|
|
|
return true;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FWidget::setPrintPos (const FPoint& pos)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const FPoint p{ woffset.getX1() + getX() + pos.getX() - 1,
|
|
|
|
woffset.getY1() + getY() + pos.getY() - 1 };
|
2019-01-21 03:42:18 +01:00
|
|
|
setPrintCursor(p);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setDoubleFlatLine (fc::sides side, bool bit)
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
uLong length{};
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
assert ( side == fc::top
|
2017-11-26 22:37:18 +01:00
|
|
|
|| side == fc::right
|
|
|
|
|| side == fc::bottom
|
|
|
|
|| side == fc::left );
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
switch ( side )
|
|
|
|
{
|
|
|
|
case fc::top:
|
|
|
|
length = double_flatline_mask.top.size();
|
|
|
|
double_flatline_mask.top.assign(length, bit);
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::right:
|
|
|
|
length = double_flatline_mask.right.size();
|
|
|
|
double_flatline_mask.right.assign(length, bit);
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::bottom:
|
|
|
|
length = double_flatline_mask.bottom.size();
|
|
|
|
double_flatline_mask.bottom.assign(length, bit);
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::left:
|
|
|
|
length = double_flatline_mask.left.size();
|
|
|
|
double_flatline_mask.left.assign(length, bit);
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setDoubleFlatLine (fc::sides side, int pos, bool bit)
|
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
assert ( side == fc::top
|
2017-11-26 22:37:18 +01:00
|
|
|
|| side == fc::right
|
|
|
|
|| side == fc::bottom
|
|
|
|
|| side == fc::left );
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
assert ( pos >= 1 );
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
uLong length{};
|
2020-02-02 22:34:27 +01:00
|
|
|
const uLong index = uLong(pos - 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
switch ( side )
|
|
|
|
{
|
|
|
|
case fc::top:
|
|
|
|
length = double_flatline_mask.top.size();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( index < length )
|
|
|
|
double_flatline_mask.top[index] = bit;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::right:
|
|
|
|
length = double_flatline_mask.right.size();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( index < length )
|
|
|
|
double_flatline_mask.right[index] = bit;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::bottom:
|
|
|
|
length = double_flatline_mask.bottom.size();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( index < length )
|
|
|
|
double_flatline_mask.bottom[index] = bit;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::left:
|
|
|
|
length = double_flatline_mask.left.size();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( index < length )
|
|
|
|
double_flatline_mask.left[index] = bit;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-10-06 22:35:00 +02:00
|
|
|
FWidget* FWidget::childWidgetAt (const FPoint& pos)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( ! hasChildren() )
|
2020-02-19 21:59:13 +01:00
|
|
|
return nullptr;
|
2017-06-11 17:47:50 +02:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
for (auto&& child : getChildren())
|
|
|
|
{
|
|
|
|
if ( ! child->isWidget() )
|
|
|
|
continue;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
auto widget = static_cast<FWidget*>(child);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( widget->isEnabled()
|
|
|
|
&& widget->isShown()
|
|
|
|
&& ! widget->isWindowWidget()
|
|
|
|
&& widget->getTermGeometry().contains(pos) )
|
|
|
|
{
|
2019-10-08 04:37:19 +02:00
|
|
|
auto sub_child = widget->childWidgetAt(pos);
|
2020-02-19 21:59:13 +01:00
|
|
|
return ( sub_child != nullptr ) ? sub_child : widget;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2020-02-19 21:59:13 +01:00
|
|
|
return nullptr;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
int FWidget::numOfFocusableChildren()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( ! hasChildren() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return 0;
|
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
int num{0};
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
for (auto&& child : getChildren())
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( child->isWidget() )
|
2017-06-11 17:47:50 +02:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& widget = static_cast<FWidget*>(child);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
if ( widget->isShown()
|
2019-01-07 05:03:00 +01:00
|
|
|
&& widget->acceptFocus()
|
|
|
|
&& ! widget->isWindowWidget() )
|
2017-06-11 17:47:50 +02:00
|
|
|
num++;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWidget::close()
|
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Sends a close event and quits the application on acceptance
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
FCloseEvent ev(fc::Close_Event);
|
2015-09-20 05:44:50 +02:00
|
|
|
FApplication::sendEvent(this, &ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
if ( ev.isAccepted() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
if ( this == getMainWidget() )
|
|
|
|
quit();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hide();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( ! flags.modal )
|
2015-05-23 13:35:12 +02:00
|
|
|
close_widget->push_back(this);
|
|
|
|
}
|
2019-09-08 02:04:24 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-26 20:40:04 +02:00
|
|
|
void FWidget::addCallback ( const FString& cb_signal
|
2020-04-19 20:38:52 +02:00
|
|
|
, const FCallback& cb_function
|
2018-12-27 00:14:46 +01:00
|
|
|
, FDataPtr data )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Add a (normal) function pointer as callback
|
|
|
|
|
2019-10-08 04:37:19 +02:00
|
|
|
FCallbackData obj{ cb_signal, nullptr, cb_function, data };
|
2016-09-25 23:53:48 +02:00
|
|
|
callback_objects.push_back(obj);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-26 20:40:04 +02:00
|
|
|
void FWidget::addCallback ( const FString& cb_signal
|
2019-10-05 23:20:07 +02:00
|
|
|
, FWidget* cb_instance
|
2020-04-19 20:38:52 +02:00
|
|
|
, const FCallback& cb_function
|
2018-12-27 00:14:46 +01:00
|
|
|
, FDataPtr data )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Add a member function pointer as callback
|
|
|
|
|
2019-10-08 04:37:19 +02:00
|
|
|
FCallbackData obj{ cb_signal, cb_instance, cb_function, data };
|
2019-10-05 23:20:07 +02:00
|
|
|
callback_objects.push_back(obj);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-19 20:38:52 +02:00
|
|
|
void FWidget::delCallback (const FCallback& cb_function)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Delete cb_function form callback list
|
2017-02-18 23:37:10 +01:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( callback_objects.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = callback_objects.begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
while ( iter != callback_objects.end() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
if ( getCallbackPtr(iter->cb_function) == getCallbackPtr(cb_function) )
|
2016-09-25 23:53:48 +02:00
|
|
|
iter = callback_objects.erase(iter);
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
void FWidget::delCallback (const FWidget* cb_instance)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Delete all member function pointer from cb_instance
|
2017-02-18 23:37:10 +01:00
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
if ( callback_objects.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
auto iter = callback_objects.begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
while ( iter != callback_objects.end() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
if ( iter->cb_instance == cb_instance )
|
2019-10-05 23:20:07 +02:00
|
|
|
iter = callback_objects.erase(iter);
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 14:34:13 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-11-03 22:57:40 +01:00
|
|
|
void FWidget::delCallbacks()
|
2016-07-30 14:34:13 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Delete all callbacks from this widget
|
2017-01-15 19:48:27 +01:00
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
callback_objects.clear(); // function pointer
|
2016-07-30 14:34:13 +02:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-26 20:40:04 +02:00
|
|
|
void FWidget::emitCallback (const FString& emit_signal)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Initiate callback for the given signal
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
if ( callback_objects.empty() )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
for (auto&& cback : callback_objects)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( cback.cb_signal == emit_signal )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Calling the stored function pointer
|
2019-10-06 22:35:00 +02:00
|
|
|
auto callback = cback.cb_function;
|
|
|
|
callback (this, cback.data);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-21 20:07:08 +01:00
|
|
|
void FWidget::addAccelerator (FKey key, FWidget* obj)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Adding a keyboard accelerator for the given widget
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = static_cast<FWidget*>(FWindow::getWindowWidget(obj));
|
2019-10-08 04:37:19 +02:00
|
|
|
FAccelerator accel = { key, obj };
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-07-12 23:35:33 +02:00
|
|
|
if ( ! widget || widget == statusbar || widget == menubar )
|
|
|
|
widget = getRootWidget();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-10-20 20:06:33 +02:00
|
|
|
if ( widget )
|
|
|
|
widget->accelerator_list.push_back(accel);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::delAccelerator (FWidget* obj)
|
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Deletes all accelerators of the given widget
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = static_cast<FWidget*>(FWindow::getWindowWidget(this));
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-12 23:35:33 +02:00
|
|
|
if ( ! widget || widget == statusbar || widget == menubar )
|
|
|
|
widget = getRootWidget();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( widget
|
2019-10-20 20:06:33 +02:00
|
|
|
&& ! widget->accelerator_list.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-20 20:06:33 +02:00
|
|
|
auto iter = widget->accelerator_list.begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-10-20 20:06:33 +02:00
|
|
|
while ( iter != widget->accelerator_list.end() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
if ( iter->object == obj )
|
2019-10-20 20:06:33 +02:00
|
|
|
iter = widget->accelerator_list.erase(iter);
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::redraw()
|
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Redraw the widget immediately unless it is hidden.
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! redraw_root_widget )
|
|
|
|
redraw_root_widget = this;
|
|
|
|
|
|
|
|
if ( isRootWidget() )
|
|
|
|
{
|
2016-10-13 02:16:51 +02:00
|
|
|
startTerminalUpdate();
|
2016-10-02 21:26:25 +02:00
|
|
|
// clean desktop
|
2020-05-26 21:37:39 +02:00
|
|
|
auto color_theme = getColorTheme();
|
|
|
|
setColor (color_theme->term_fg, color_theme->term_bg);
|
2019-09-01 23:29:27 +02:00
|
|
|
clearArea (getVirtualDesktop());
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2019-01-09 20:05:29 +01:00
|
|
|
else if ( ! isShown() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
draw();
|
|
|
|
|
|
|
|
if ( isRootWidget() )
|
2018-01-31 00:17:00 +01:00
|
|
|
drawWindows();
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2018-01-31 00:17:00 +01:00
|
|
|
drawChildren();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( isRootWidget() )
|
2016-10-13 02:16:51 +02:00
|
|
|
finishTerminalUpdate();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( redraw_root_widget == this )
|
|
|
|
{
|
|
|
|
updateTerminal();
|
2019-12-16 11:14:24 +01:00
|
|
|
flush();
|
2018-12-10 01:48:26 +01:00
|
|
|
redraw_root_widget = nullptr;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::resize()
|
|
|
|
{
|
2016-10-13 02:16:51 +02:00
|
|
|
if ( isRootWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
const FRect old_term_geometry {getTermGeometry()};
|
2016-10-13 02:16:51 +02:00
|
|
|
detectTermSize();
|
2020-05-02 00:07:35 +02:00
|
|
|
FRect term_geometry {getTermGeometry()};
|
2017-08-27 09:50:30 +02:00
|
|
|
term_geometry.move (-1, -1);
|
2016-10-14 13:02:35 +02:00
|
|
|
|
2019-08-18 02:04:44 +02:00
|
|
|
if ( old_term_geometry.getSize() == term_geometry.getSize() )
|
|
|
|
return;
|
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
resizeVTerm (term_geometry.getSize());
|
2019-09-01 23:29:27 +02:00
|
|
|
resizeArea (term_geometry, getShadow(), getVirtualDesktop());
|
2016-05-16 23:36:13 +02:00
|
|
|
adjustSizeGlobal();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
adjustSize();
|
2015-10-11 21:56:16 +02:00
|
|
|
|
|
|
|
// resize the four double-flatline-masks
|
2018-10-14 06:25:33 +02:00
|
|
|
double_flatline_mask.top.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.right.resize (getHeight(), false);
|
|
|
|
double_flatline_mask.bottom.resize (getWidth(), false);
|
|
|
|
double_flatline_mask.left.resize (getHeight(), false);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::show()
|
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Make the widget visible and draw it
|
|
|
|
|
2020-06-06 21:10:06 +02:00
|
|
|
if ( ! isVisible() || FApplication::isQuit() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2020-06-06 21:10:06 +02:00
|
|
|
// Initialize desktop on first call
|
|
|
|
if ( ! init_desktop && root_widget )
|
|
|
|
root_widget->initDesktop();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( ! show_root_widget )
|
|
|
|
{
|
2016-10-13 02:16:51 +02:00
|
|
|
startTerminalUpdate();
|
2015-05-23 13:35:12 +02:00
|
|
|
show_root_widget = this;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:53:27 +01:00
|
|
|
draw(); // Draw the widget
|
2019-01-09 20:05:29 +01:00
|
|
|
flags.hidden = false;
|
2018-11-05 23:19:03 +01:00
|
|
|
flags.shown = true;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( hasChildren() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
for (auto&& child : getChildren())
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( child->isWidget() )
|
2017-06-11 17:47:50 +02:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
auto widget = static_cast<FWidget*>(child);
|
2019-01-09 20:05:29 +01:00
|
|
|
|
|
|
|
if ( ! widget->flags.hidden )
|
|
|
|
widget->show();
|
2017-06-11 17:47:50 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( show_root_widget && show_root_widget == this )
|
|
|
|
{
|
2016-10-13 02:16:51 +02:00
|
|
|
finishTerminalUpdate();
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
2019-12-16 11:14:24 +01:00
|
|
|
flush();
|
2018-12-10 01:48:26 +01:00
|
|
|
show_root_widget = nullptr;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
FShowEvent show_ev (fc::Show_Event);
|
2015-09-20 05:44:50 +02:00
|
|
|
FApplication::sendEvent(this, &show_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::hide()
|
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
// Hide the widget
|
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
flags.hidden = true;
|
|
|
|
|
2018-11-04 23:12:41 +01:00
|
|
|
if ( isVisible() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-11-05 23:19:03 +01:00
|
|
|
flags.shown = false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( ! isDialogWidget()
|
2017-11-26 22:37:18 +01:00
|
|
|
&& FWidget::getFocusWidget() == this
|
|
|
|
&& ! focusPrevChild() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-08-21 21:27:44 +02:00
|
|
|
if ( FWidget::getFocusWidget() )
|
|
|
|
FWidget::getFocusWidget()->unsetFocus();
|
|
|
|
|
2016-08-20 22:27:23 +02:00
|
|
|
FWidget::setFocusWidget(getParentWidget());
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
FHideEvent hide_ev (fc::Hide_Event);
|
2015-09-20 05:44:50 +02:00
|
|
|
FApplication::sendEvent(this, &hide_ev);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-05-22 19:18:16 +02:00
|
|
|
bool FWidget::focusFirstChild()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( ! hasChildren() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = FObject::begin();
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto last = FObject::end();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-06-11 17:47:50 +02:00
|
|
|
if ( ! (*iter)->isWidget() )
|
|
|
|
{
|
|
|
|
++iter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = static_cast<FWidget*>(*iter);
|
2016-05-16 23:26:04 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( widget->isEnabled()
|
2017-11-26 22:37:18 +01:00
|
|
|
&& widget->acceptFocus()
|
|
|
|
&& ! widget->isMenuWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-07-13 00:15:57 +02:00
|
|
|
widget->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2020-04-19 20:38:52 +02:00
|
|
|
if ( widget->numOfChildren() >= 1
|
|
|
|
&& ! widget->focusFirstChild()
|
|
|
|
&& widget->isWindowWidget() )
|
2015-07-12 21:49:30 +02:00
|
|
|
{
|
2020-04-19 20:38:52 +02:00
|
|
|
++iter;
|
|
|
|
continue;
|
2015-07-12 21:49:30 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
++iter;
|
|
|
|
}
|
2020-02-02 22:34:27 +01:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-05-22 19:18:16 +02:00
|
|
|
bool FWidget::focusLastChild()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( ! hasChildren() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = FObject::end();
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto first = FObject::begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
2017-06-11 17:47:50 +02:00
|
|
|
|
|
|
|
if ( ! (*iter)->isWidget() )
|
|
|
|
continue;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = static_cast<FWidget*>(*iter);
|
2016-05-16 23:26:04 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( widget->isEnabled()
|
2017-11-26 22:37:18 +01:00
|
|
|
&& widget->acceptFocus()
|
|
|
|
&& ! widget->isMenuWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-07-13 00:15:57 +02:00
|
|
|
widget->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2020-04-19 20:38:52 +02:00
|
|
|
if ( widget->numOfChildren() >= 1
|
|
|
|
&& ! widget->focusLastChild() && widget->isWindowWidget() )
|
|
|
|
continue;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != first );
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FWidget::move (const FPoint& pos)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
wsize.move(pos);
|
|
|
|
adjust_wsize.move(pos);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::quit()
|
2016-09-25 23:53:48 +02:00
|
|
|
{
|
2020-04-13 12:40:11 +02:00
|
|
|
FApplication::exit(0);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// protected methods of FWidget
|
2017-10-27 23:28:37 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-10-08 04:37:19 +02:00
|
|
|
FVTerm::FTermArea* FWidget::getPrintArea()
|
2017-10-27 23:28:37 +02:00
|
|
|
{
|
|
|
|
// returns the print area of this object
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( getCurrentPrintArea() )
|
|
|
|
return getCurrentPrintArea();
|
2017-10-27 23:28:37 +02:00
|
|
|
else
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
FWidget* obj{};
|
2017-10-30 20:29:00 +01:00
|
|
|
FWidget* p_obj = this;
|
2017-10-27 23:28:37 +02:00
|
|
|
|
2017-10-30 20:29:00 +01:00
|
|
|
do
|
2017-10-27 23:28:37 +02:00
|
|
|
{
|
|
|
|
obj = p_obj;
|
2017-10-30 20:29:00 +01:00
|
|
|
p_obj = static_cast<FWidget*>(obj->getParent());
|
2017-10-27 23:28:37 +02:00
|
|
|
}
|
2019-09-01 23:29:27 +02:00
|
|
|
while ( ! obj->getVWin() && ! obj->getChildPrintArea() && p_obj );
|
2017-10-27 23:28:37 +02:00
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( obj->getVWin() )
|
2017-10-27 23:28:37 +02:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
setPrintArea (obj->getVWin());
|
|
|
|
return getCurrentPrintArea();
|
2017-10-27 23:28:37 +02:00
|
|
|
}
|
2019-09-01 23:29:27 +02:00
|
|
|
else if ( obj->getChildPrintArea() )
|
2017-10-27 23:28:37 +02:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
setPrintArea (obj->getChildPrintArea());
|
|
|
|
return getCurrentPrintArea();
|
2017-10-27 23:28:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
return getVirtualDesktop();
|
2017-10-27 23:28:37 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 20:29:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
void FWidget::addPreprocessingHandler ( const FVTerm* instance
|
|
|
|
, const FPreprocessingFunction& function )
|
2017-10-30 20:29:00 +01:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! getCurrentPrintArea() )
|
2017-10-30 20:29:00 +01:00
|
|
|
FWidget::getPrintArea();
|
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
FVTerm::addPreprocessingHandler (instance, function);
|
2017-10-30 20:29:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
void FWidget::delPreprocessingHandler (const FVTerm* instance)
|
2017-10-30 20:29:00 +01:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! getCurrentPrintArea() )
|
2017-10-30 20:29:00 +01:00
|
|
|
FWidget::getPrintArea();
|
|
|
|
|
|
|
|
FVTerm::delPreprocessingHandler (instance);
|
|
|
|
}
|
|
|
|
|
2017-10-27 23:28:37 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWidget::isChildPrintArea() const
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& p_obj = static_cast<FWidget*>(getParent());
|
2017-10-27 23:28:37 +02:00
|
|
|
|
|
|
|
if ( p_obj
|
2019-09-01 23:29:27 +02:00
|
|
|
&& p_obj->getChildPrintArea()
|
|
|
|
&& p_obj->getChildPrintArea() == getCurrentPrintArea() )
|
2017-10-27 23:28:37 +02:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-06 19:32:01 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWidget::isDesktopInitialized() const
|
|
|
|
{
|
|
|
|
return ( root_widget ) ? root_widget->init_desktop : false;
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setStatusBar (FStatusBar* sbar)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! sbar || statusbar == sbar )
|
|
|
|
return;
|
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
if ( statusbar )
|
2016-11-02 00:37:58 +01:00
|
|
|
delete statusbar;
|
|
|
|
|
|
|
|
statusbar = sbar;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::setMenuBar (FMenuBar* mbar)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! mbar || menubar == mbar )
|
|
|
|
return;
|
2016-09-11 16:48:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( menubar )
|
|
|
|
delete menubar;
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
menubar = mbar;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2020-01-09 19:21:16 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setParentOffset()
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& p = getParentWidget();
|
2020-01-09 19:21:16 +01:00
|
|
|
|
|
|
|
if ( p )
|
|
|
|
woffset = p->wclient_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setTermOffset()
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& r = getRootWidget();
|
|
|
|
const int w = int(r->getWidth());
|
|
|
|
const int h = int(r->getHeight());
|
2020-01-09 19:21:16 +01:00
|
|
|
woffset.setCoordinates (0, 0, w - 1, h - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setTermOffsetWithPadding()
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& r = getRootWidget();
|
2020-01-09 19:21:16 +01:00
|
|
|
woffset.setCoordinates ( r->getLeftPadding()
|
|
|
|
, r->getTopPadding()
|
|
|
|
, int(r->getWidth()) - 1 - r->getRightPadding()
|
|
|
|
, int(r->getHeight()) - 1 - r->getBottomPadding() );
|
|
|
|
}
|
|
|
|
|
2020-06-06 21:10:06 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::initTerminal()
|
|
|
|
{
|
|
|
|
if ( hasParent() || init_terminal )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Initialize the physical and virtual terminal
|
|
|
|
FVTerm::initTerminal();
|
|
|
|
|
|
|
|
// Initialize default widget colors (after terminal detection)
|
|
|
|
initColorTheme();
|
|
|
|
|
|
|
|
// Set default foreground and background color of the desktop/terminal
|
|
|
|
auto color_theme = getColorTheme();
|
|
|
|
root_widget->foreground_color = color_theme->term_fg;
|
|
|
|
root_widget->background_color = color_theme->term_bg;
|
|
|
|
resetColors();
|
|
|
|
|
|
|
|
// The terminal is now initialized
|
|
|
|
init_terminal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::initDesktop()
|
|
|
|
{
|
|
|
|
if ( hasParent() || init_desktop )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! init_terminal )
|
|
|
|
initTerminal();
|
|
|
|
|
|
|
|
// Sets the initial screen settings
|
|
|
|
FTerm::initScreenSettings();
|
|
|
|
|
|
|
|
// Initializing vdesktop
|
|
|
|
const auto& r = getRootWidget();
|
|
|
|
setColor(r->getForegroundColor(), r->getBackgroundColor());
|
|
|
|
clearArea (getVirtualDesktop());
|
|
|
|
|
|
|
|
// Destop is now initialized
|
|
|
|
init_desktop = true;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::adjustSize()
|
|
|
|
{
|
|
|
|
if ( ! isRootWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& p = getParentWidget();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( isWindowWidget() )
|
|
|
|
{
|
|
|
|
if ( ignore_padding && ! isDialogWidget() )
|
|
|
|
setTermOffset();
|
|
|
|
else
|
2020-03-05 21:30:54 +01:00
|
|
|
woffset = root_widget->wclient_offset;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else if ( ignore_padding && p )
|
|
|
|
{
|
2019-09-09 19:13:38 +02:00
|
|
|
woffset.setCoordinates ( p->getTermX() - 1
|
2019-09-28 03:13:06 +02:00
|
|
|
, p->getTermY() - 1
|
|
|
|
, p->getTermX() + int(p->getWidth()) - 2
|
|
|
|
, p->getTermY() + int(p->getHeight()) - 2 );
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else if ( p )
|
2019-09-09 19:13:38 +02:00
|
|
|
woffset = p->wclient_offset;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
adjust_wsize = wsize;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-09-02 23:06:47 +02:00
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
// Move and shrink in case of lack of space
|
|
|
|
if ( ! hasChildPrintArea() )
|
|
|
|
insufficientSpaceAdjust();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-09-09 19:13:38 +02:00
|
|
|
wclient_offset.setCoordinates
|
2016-11-02 00:37:58 +01:00
|
|
|
(
|
|
|
|
getTermX() - 1 + padding.left,
|
|
|
|
getTermY() - 1 + padding.top,
|
2018-10-14 06:25:33 +02:00
|
|
|
getTermX() - 2 + int(getWidth()) - padding.right,
|
|
|
|
getTermY() - 2 + int(getHeight()) - padding.bottom
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
if ( hasChildren() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
for (auto&& child : getChildren())
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( child->isWidget() )
|
2017-06-11 17:47:50 +02:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
auto widget = static_cast<FWidget*>(child);
|
2016-10-15 03:32:30 +02:00
|
|
|
|
2017-06-11 17:47:50 +02:00
|
|
|
if ( ! widget->isWindowWidget() )
|
|
|
|
widget->adjustSize();
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-11 04:57:36 +02:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::adjustSizeGlobal()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! isRootWidget() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
getRootWidget()->adjustSizeGlobal();
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( window_list && ! window_list->empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
for (auto&& window : *window_list)
|
|
|
|
window->adjustSize();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-01-11 22:16:59 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-09-01 23:29:27 +02:00
|
|
|
void FWidget::hideArea (const FSize& size)
|
2019-01-11 22:16:59 +01:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
if ( size.isEmpty() )
|
2019-01-11 22:16:59 +01:00
|
|
|
return;
|
|
|
|
|
2020-04-13 12:40:11 +02:00
|
|
|
FColor fg{};
|
|
|
|
FColor bg{};
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& parent_widget = getParentWidget();
|
2019-01-11 22:16:59 +01:00
|
|
|
|
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
fg = parent_widget->getForegroundColor();
|
|
|
|
bg = parent_widget->getBackgroundColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
auto color_theme = getColorTheme();
|
|
|
|
fg = color_theme->dialog_fg;
|
|
|
|
bg = color_theme->dialog_bg;
|
2019-01-11 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setColor (fg, bg);
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
if ( size.getWidth() == 0 )
|
2019-01-11 22:16:59 +01:00
|
|
|
return;
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
for (int y{0}; y < int(size.getHeight()); y++)
|
2019-01-11 22:16:59 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{1, 1 + y} << FString{size.getWidth(), L' '};
|
2019-01-11 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
flush();
|
2019-01-11 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWidget::focusNextChild()
|
|
|
|
{
|
2018-02-11 23:41:23 +01:00
|
|
|
if ( isDialogWidget() || ! hasParent() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& parent = getParentWidget();
|
2018-02-11 23:41:23 +01:00
|
|
|
|
2018-03-30 00:12:20 +02:00
|
|
|
if ( ! parent
|
|
|
|
|| ! parent->hasChildren()
|
|
|
|
|| parent->numOfFocusableChildren() <= 1 )
|
2018-02-11 23:41:23 +01:00
|
|
|
return false;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = parent->begin();
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto last = parent->end();
|
2018-02-11 23:41:23 +01:00
|
|
|
|
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-02-11 23:41:23 +01:00
|
|
|
if ( ! (*iter)->isWidget() )
|
|
|
|
{
|
|
|
|
++iter;
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-27 23:23:42 +02:00
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& w = static_cast<FWidget*>(*iter);
|
2018-02-11 23:41:23 +01:00
|
|
|
|
|
|
|
if ( w != this )
|
2016-08-27 23:23:42 +02:00
|
|
|
{
|
2018-02-11 23:41:23 +01:00
|
|
|
++iter;
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
FWidget* next{nullptr};
|
2018-12-15 00:50:09 +01:00
|
|
|
auto next_element = iter;
|
2017-06-11 17:47:50 +02:00
|
|
|
|
2018-02-11 23:41:23 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
++next_element;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-02-11 23:41:23 +01:00
|
|
|
if ( next_element == parent->end() )
|
|
|
|
next_element = parent->begin();
|
|
|
|
|
|
|
|
if ( ! (*next_element)->isWidget() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
next = static_cast<FWidget*>(*next_element);
|
|
|
|
} while ( ! next
|
|
|
|
|| ! next->isEnabled()
|
|
|
|
|| ! next->acceptFocus()
|
2019-01-09 20:05:29 +01:00
|
|
|
|| ! next->isShown()
|
2018-02-11 23:41:23 +01:00
|
|
|
|| next->isWindowWidget() );
|
|
|
|
|
|
|
|
bool accpt = changeFocus (next, parent, fc::FocusNextWidget);
|
|
|
|
|
|
|
|
if ( ! accpt )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break; // The focus has been changed
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-02-11 23:41:23 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FWidget::focusPrevChild()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-02-11 23:41:23 +01:00
|
|
|
if ( isDialogWidget() || ! hasParent() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& parent = getParentWidget();
|
2018-02-11 23:41:23 +01:00
|
|
|
|
2018-03-30 00:12:20 +02:00
|
|
|
if ( ! parent
|
|
|
|
|| ! parent->hasChildren()
|
|
|
|
|| parent->numOfFocusableChildren() <= 1 )
|
2018-02-11 23:41:23 +01:00
|
|
|
return false;
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
auto iter = parent->end();
|
|
|
|
const auto first = parent->begin();
|
2018-02-11 23:41:23 +01:00
|
|
|
|
|
|
|
do
|
2016-08-27 23:23:42 +02:00
|
|
|
{
|
2018-02-11 23:41:23 +01:00
|
|
|
--iter;
|
2016-08-27 23:23:42 +02:00
|
|
|
|
2018-02-11 23:41:23 +01:00
|
|
|
if ( ! (*iter)->isWidget() )
|
|
|
|
continue;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& w = static_cast<FWidget*>(*iter);
|
2017-06-11 17:47:50 +02:00
|
|
|
|
2018-02-11 23:41:23 +01:00
|
|
|
if ( w != this )
|
|
|
|
continue;
|
2017-06-11 17:47:50 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
FWidget* prev{nullptr};
|
2018-12-15 00:50:09 +01:00
|
|
|
auto prev_element = iter;
|
2016-08-27 23:23:42 +02:00
|
|
|
|
2018-02-11 23:41:23 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( ! (*prev_element)->isWidget() )
|
|
|
|
{
|
|
|
|
--prev_element;
|
|
|
|
continue;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-02-11 23:41:23 +01:00
|
|
|
|
|
|
|
if ( prev_element == parent->begin() )
|
|
|
|
prev_element = parent->end();
|
|
|
|
|
|
|
|
--prev_element;
|
|
|
|
prev = static_cast<FWidget*>(*prev_element);
|
|
|
|
} while ( ! prev
|
|
|
|
|| ! prev->isEnabled()
|
|
|
|
|| ! prev->acceptFocus()
|
2019-01-09 20:05:29 +01:00
|
|
|
|| ! prev->isShown()
|
2018-02-11 23:41:23 +01:00
|
|
|
|| prev->isWindowWidget() );
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const bool accpt = changeFocus (prev, parent, fc::FocusPreviousWidget);
|
2018-02-11 23:41:23 +01:00
|
|
|
|
|
|
|
if ( ! accpt )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break; // The focus has been changed
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-02-11 23:41:23 +01:00
|
|
|
while ( iter != first );
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWidget::event (FEvent* ev)
|
|
|
|
{
|
2020-05-21 14:53:51 +02:00
|
|
|
switch ( uInt(ev->getType()) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::KeyPress_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
KeyPressEvent (static_cast<FKeyEvent*>(ev));
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::KeyUp_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onKeyUp (static_cast<FKeyEvent*>(ev));
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2016-08-27 23:23:42 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::KeyDown_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
KeyDownEvent (static_cast<FKeyEvent*>(ev));
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::MouseDown_Event:
|
2019-12-16 11:14:24 +01:00
|
|
|
emitCallback("mouse-press");
|
2018-12-15 00:50:09 +01:00
|
|
|
onMouseDown (static_cast<FMouseEvent*>(ev));
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2016-09-03 15:17:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::MouseUp_Event:
|
2019-12-16 11:14:24 +01:00
|
|
|
emitCallback("mouse-release");
|
2018-12-15 00:50:09 +01:00
|
|
|
onMouseUp (static_cast<FMouseEvent*>(ev));
|
2015-06-21 23:27:10 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::MouseDoubleClick_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onMouseDoubleClick (static_cast<FMouseEvent*>(ev));
|
2015-06-21 23:27:10 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::MouseWheel_Event:
|
2019-12-16 11:14:24 +01:00
|
|
|
emitWheelCallback(static_cast<FWheelEvent*>(ev));
|
2018-12-15 00:50:09 +01:00
|
|
|
onWheel (static_cast<FWheelEvent*>(ev));
|
2015-06-21 23:27:10 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::MouseMove_Event:
|
2019-12-16 11:14:24 +01:00
|
|
|
emitCallback("mouse-move");
|
2018-12-15 00:50:09 +01:00
|
|
|
onMouseMove (static_cast<FMouseEvent*>(ev));
|
2015-06-21 23:27:10 +02:00
|
|
|
break;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::FocusIn_Event:
|
2019-12-16 11:14:24 +01:00
|
|
|
emitCallback("focus-in");
|
2018-12-15 00:50:09 +01:00
|
|
|
onFocusIn (static_cast<FFocusEvent*>(ev));
|
2015-09-20 05:44:50 +02:00
|
|
|
break;
|
2016-09-03 15:17:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::FocusOut_Event:
|
2019-12-16 11:14:24 +01:00
|
|
|
emitCallback("focus-out");
|
2018-12-15 00:50:09 +01:00
|
|
|
onFocusOut (static_cast<FFocusEvent*>(ev));
|
2016-09-03 15:17:48 +02:00
|
|
|
break;
|
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
case fc::ChildFocusIn_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onChildFocusIn (static_cast<FFocusEvent*>(ev));
|
2017-01-28 22:03:15 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::ChildFocusOut_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onChildFocusOut (static_cast<FFocusEvent*>(ev));
|
2017-01-26 00:31:07 +01:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Accelerator_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onAccel (static_cast<FAccelEvent*>(ev));
|
2016-09-03 15:17:48 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Resize_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onResize (static_cast<FResizeEvent*>(ev));
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2016-09-03 15:17:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Show_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onShow (static_cast<FShowEvent*>(ev));
|
2016-09-03 15:17:48 +02:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Hide_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onHide (static_cast<FHideEvent*>(ev));
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2016-09-03 15:17:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Close_Event:
|
2018-12-15 00:50:09 +01:00
|
|
|
onClose (static_cast<FCloseEvent*>(ev));
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
2016-09-03 15:17:48 +02:00
|
|
|
|
|
|
|
default:
|
2020-05-16 22:24:36 +02:00
|
|
|
return FObject::event(ev);
|
2016-09-03 15:17:48 +02:00
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
2016-09-03 15:17:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::onKeyPress (FKeyEvent*)
|
|
|
|
{ }
|
2015-06-21 23:27:10 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onKeyUp (FKeyEvent*)
|
|
|
|
{ }
|
2015-06-21 23:27:10 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onKeyDown (FKeyEvent*)
|
|
|
|
{ }
|
2015-06-21 23:27:10 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onMouseDown (FMouseEvent*)
|
|
|
|
{ }
|
2015-06-21 23:27:10 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onMouseUp (FMouseEvent*)
|
|
|
|
{ }
|
2015-06-21 23:27:10 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::onMouseDoubleClick (FMouseEvent*)
|
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onWheel (FWheelEvent*)
|
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onMouseMove (FMouseEvent*)
|
|
|
|
{ }
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onFocusIn (FFocusEvent*)
|
|
|
|
{ }
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onFocusOut (FFocusEvent*)
|
|
|
|
{ }
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-26 00:31:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-01-28 22:03:15 +01:00
|
|
|
void FWidget::onChildFocusIn (FFocusEvent*)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onChildFocusOut (FFocusEvent*)
|
2017-01-26 00:31:07 +01:00
|
|
|
{ }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onAccel (FAccelEvent*)
|
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onResize (FResizeEvent* ev)
|
|
|
|
{
|
2019-12-23 14:20:31 +01:00
|
|
|
// The terminal was resized
|
2020-03-05 21:30:54 +01:00
|
|
|
root_widget->resize();
|
|
|
|
root_widget->redraw();
|
2016-11-02 00:37:58 +01:00
|
|
|
ev->accept();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onShow (FShowEvent*)
|
|
|
|
{ }
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onHide (FHideEvent*)
|
|
|
|
{ }
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::onClose (FCloseEvent* ev)
|
|
|
|
{
|
|
|
|
ev->accept();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// private methods of FWidget
|
2020-06-06 21:10:06 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::determineDesktopSize()
|
|
|
|
{
|
|
|
|
// Determine width and height of the terminal
|
|
|
|
|
|
|
|
detectTermSize();
|
|
|
|
wsize.setRect(1, 1, getDesktopWidth(), getDesktopHeight());
|
|
|
|
adjust_wsize = wsize;
|
|
|
|
woffset.setRect(0, 0, getDesktopWidth(), getDesktopHeight());
|
|
|
|
wclient_offset = woffset;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-03-05 21:30:54 +01:00
|
|
|
void FWidget::initRootWidget()
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Initialize widget lists
|
2019-10-06 22:35:00 +02:00
|
|
|
window_list = new FWidgetList();
|
|
|
|
dialog_list = new FWidgetList();
|
|
|
|
always_on_top_list = new FWidgetList();
|
|
|
|
close_widget = new FWidgetList();
|
2017-08-12 22:55:29 +02:00
|
|
|
}
|
2020-05-13 23:47:14 +02:00
|
|
|
catch (const std::bad_alloc&)
|
2017-08-12 22:55:29 +02:00
|
|
|
{
|
2020-05-13 23:47:14 +02:00
|
|
|
badAllocOutput ("FWidgetList");
|
2017-08-12 22:55:29 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2020-07-06 19:32:01 +02:00
|
|
|
// Initialize default widget colors
|
|
|
|
// (before terminal detection and root_widget is set)
|
|
|
|
initColorTheme();
|
|
|
|
|
2020-06-06 21:10:06 +02:00
|
|
|
// Root widget basic initialization
|
|
|
|
root_widget = this;
|
|
|
|
show_root_widget = nullptr;
|
|
|
|
redraw_root_widget = nullptr;
|
|
|
|
modal_dialog_counter = 0;
|
|
|
|
statusbar = nullptr;
|
2016-11-12 22:59:48 +01:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
// Determine width and height of the terminal
|
2020-06-06 21:10:06 +02:00
|
|
|
determineDesktopSize();
|
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 FWidget::finish()
|
|
|
|
{
|
|
|
|
if ( close_widget )
|
|
|
|
{
|
|
|
|
delete close_widget;
|
2018-12-10 01:48:26 +01:00
|
|
|
close_widget = nullptr;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dialog_list )
|
|
|
|
{
|
|
|
|
delete dialog_list;
|
2018-12-10 01:48:26 +01:00
|
|
|
dialog_list = nullptr;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( always_on_top_list )
|
|
|
|
{
|
|
|
|
delete always_on_top_list;
|
2018-12-10 01:48:26 +01:00
|
|
|
always_on_top_list = nullptr;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( window_list )
|
|
|
|
{
|
|
|
|
delete window_list;
|
2018-12-10 01:48:26 +01:00
|
|
|
window_list = nullptr;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2020-05-26 21:37:39 +02:00
|
|
|
|
|
|
|
destroyColorTheme();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FWidget::insufficientSpaceAdjust()
|
|
|
|
{
|
|
|
|
// Move and shrink widget if there is not enough space available
|
|
|
|
|
|
|
|
if ( isWindowWidget() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// move left if not enough space
|
2019-09-09 19:13:38 +02:00
|
|
|
while ( getTermX() + int(getWidth()) - padding.right > woffset.getX2() + 2 )
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
adjust_wsize.x1_ref()--;
|
|
|
|
adjust_wsize.x2_ref()--;
|
|
|
|
|
|
|
|
if ( adjust_wsize.x1_ref() < 1 )
|
|
|
|
adjust_wsize.x1_ref() = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// move up if not enough space
|
2019-09-09 19:13:38 +02:00
|
|
|
while ( getTermY() + int(getHeight()) - padding.bottom > woffset.getY2() + 2 )
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
adjust_wsize.y1_ref()--;
|
|
|
|
adjust_wsize.y2_ref()--;
|
|
|
|
|
|
|
|
if ( adjust_wsize.y1_ref() < 1 )
|
|
|
|
adjust_wsize.y1_ref() = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reduce the width if not enough space
|
2019-09-09 19:13:38 +02:00
|
|
|
while ( woffset.getX1() + int(getWidth()) - 1 > woffset.getX2() )
|
2017-01-22 23:04:40 +01:00
|
|
|
adjust_wsize.x2_ref()--;
|
|
|
|
|
|
|
|
if ( getWidth() < size_hints.min_width )
|
|
|
|
adjust_wsize.setWidth(size_hints.min_width);
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( getWidth() == 0 )
|
2017-01-22 23:04:40 +01:00
|
|
|
adjust_wsize.setWidth(1);
|
|
|
|
|
|
|
|
// reduce the height if not enough space
|
2019-09-09 19:13:38 +02:00
|
|
|
while ( woffset.getY1() + int(getHeight()) - 1 > woffset.getY2() )
|
2017-01-22 23:04:40 +01:00
|
|
|
adjust_wsize.y2_ref()--;
|
|
|
|
|
|
|
|
if ( getHeight() < size_hints.min_height )
|
2019-12-23 14:20:31 +01:00
|
|
|
adjust_wsize.setHeight(size_hints.min_height);
|
2017-01-22 23:04:40 +01:00
|
|
|
|
2019-07-14 18:30:35 +02:00
|
|
|
if ( getHeight() == 0 )
|
2017-01-22 23:04:40 +01:00
|
|
|
adjust_wsize.setHeight(1);
|
|
|
|
}
|
|
|
|
|
2017-12-03 21:06:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::KeyPressEvent (FKeyEvent* kev)
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
FWidget* widget(this);
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
while ( widget )
|
|
|
|
{
|
|
|
|
widget->onKeyPress(kev);
|
|
|
|
|
|
|
|
if ( ! kev->isAccepted() )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const FKey key = kev->key();
|
2019-11-16 15:16:44 +01:00
|
|
|
|
2020-04-18 13:33:42 +02:00
|
|
|
if ( [this, &key] ()
|
2019-11-16 15:16:44 +01:00
|
|
|
{
|
|
|
|
if ( isFocusNextKey(key) )
|
|
|
|
return focusNextChild();
|
|
|
|
else if ( isFocusPrevKey(key) )
|
|
|
|
return focusPrevChild();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}() )
|
|
|
|
{
|
2017-12-03 21:06:21 +01:00
|
|
|
return;
|
2019-11-16 15:16:44 +01:00
|
|
|
}
|
2017-12-03 21:06:21 +01:00
|
|
|
}
|
|
|
|
|
2020-03-07 21:32:18 +01:00
|
|
|
if ( kev->isAccepted()
|
|
|
|
|| widget->isRootWidget()
|
|
|
|
|| widget->getFlags().modal )
|
2017-12-03 21:06:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
widget = widget->getParentWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::KeyDownEvent (FKeyEvent* kev)
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
FWidget* widget(this);
|
2017-12-03 21:06:21 +01:00
|
|
|
|
|
|
|
while ( widget )
|
|
|
|
{
|
|
|
|
widget->onKeyDown(kev);
|
|
|
|
|
|
|
|
if ( kev->isAccepted() || widget->isRootWidget() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
widget = widget->getParentWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
void FWidget::emitWheelCallback (const FWheelEvent* ev)
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const int wheel = ev->getWheel();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
if ( wheel == fc::WheelUp )
|
|
|
|
emitCallback("mouse-wheel-up");
|
|
|
|
else if ( wheel == fc::WheelDown )
|
|
|
|
emitCallback("mouse-wheel-down");
|
|
|
|
}
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setWindowFocus (bool enable)
|
|
|
|
{
|
|
|
|
// set the window focus
|
|
|
|
|
|
|
|
if ( ! enable )
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto window = FWindow::getWindowWidget(this);
|
|
|
|
|
|
|
|
if ( ! window )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! window->isWindowActive() )
|
|
|
|
{
|
|
|
|
bool has_raised = window->raiseWindow();
|
|
|
|
FWindow::setActiveWindow(window);
|
|
|
|
|
|
|
|
if ( has_raised && window->isVisible() && window->isShown() )
|
|
|
|
window->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
window->setWindowFocusWidget(this);
|
|
|
|
}
|
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-20 01:01:20 +02:00
|
|
|
FWidget::FCallbackPtr FWidget::getCallbackPtr (const FCallback& cb_function)
|
2019-10-05 23:20:07 +02:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
auto ptr = cb_function.template target<FCallbackPtr>();
|
|
|
|
|
|
|
|
if ( ptr )
|
|
|
|
return *ptr;
|
|
|
|
else
|
|
|
|
return nullptr;
|
2019-10-05 23:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-02-11 23:41:23 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-15 23:17:42 +02:00
|
|
|
bool FWidget::changeFocus ( FWidget* follower, FWidget* parent
|
2018-02-11 23:41:23 +01:00
|
|
|
, fc::FocusTypes ft )
|
|
|
|
{
|
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
|
|
|
out.setFocusType(ft);
|
|
|
|
FApplication::sendEvent(this, &out);
|
|
|
|
|
|
|
|
FFocusEvent cfo (fc::ChildFocusOut_Event);
|
|
|
|
cfo.setFocusType(ft);
|
|
|
|
cfo.ignore();
|
|
|
|
FApplication::sendEvent(parent, &cfo);
|
|
|
|
|
|
|
|
if ( cfo.isAccepted() )
|
|
|
|
out.ignore();
|
|
|
|
|
|
|
|
if ( out.isAccepted() )
|
|
|
|
{
|
|
|
|
if ( follower == this )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
follower->setFocus();
|
|
|
|
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
|
|
|
FApplication::sendEvent(parent, &cfi);
|
|
|
|
|
|
|
|
FFocusEvent in (fc::FocusIn_Event);
|
|
|
|
in.setFocusType(ft);
|
|
|
|
FApplication::sendEvent(follower, &in);
|
|
|
|
|
|
|
|
if ( in.isAccepted() )
|
|
|
|
{
|
|
|
|
redraw();
|
|
|
|
follower->redraw();
|
|
|
|
updateTerminal();
|
2019-12-16 11:14:24 +01:00
|
|
|
flush();
|
2018-02-11 23:41:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FWidget::draw()
|
|
|
|
{ }
|
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::drawWindows()
|
|
|
|
{
|
|
|
|
// redraw windows
|
2019-10-08 04:37:19 +02:00
|
|
|
FChar default_char{};
|
|
|
|
default_char.ch = ' ';
|
2018-01-31 00:17:00 +01:00
|
|
|
default_char.fg_color = fc::Black;
|
|
|
|
default_char.bg_color = fc::Black;
|
|
|
|
default_char.attr.byte[0] = 0;
|
|
|
|
default_char.attr.byte[1] = 0;
|
|
|
|
|
|
|
|
if ( ! window_list || window_list->empty() )
|
|
|
|
return;
|
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
for (auto&& window : *window_list)
|
2018-01-31 00:17:00 +01:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( window->isShown() )
|
2018-01-31 00:17:00 +01:00
|
|
|
{
|
2019-10-08 04:37:19 +02:00
|
|
|
auto v_win = window->getVWin();
|
2020-02-02 22:34:27 +01:00
|
|
|
const int w = v_win->width + v_win->right_shadow;
|
|
|
|
const int h = v_win->height + v_win->bottom_shadow;
|
2019-10-08 04:37:19 +02:00
|
|
|
std::fill_n (v_win->data, w * h, default_char);
|
2019-10-06 22:35:00 +02:00
|
|
|
window->redraw();
|
2018-01-31 00:17:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::drawChildren()
|
|
|
|
{
|
|
|
|
// draw child elements
|
|
|
|
if ( ! hasChildren() )
|
|
|
|
return;
|
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
for (auto&& child : getChildren())
|
2018-01-31 00:17:00 +01:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
if ( child->isWidget() )
|
2018-01-31 00:17:00 +01:00
|
|
|
{
|
2019-10-06 22:35:00 +02:00
|
|
|
auto widget = static_cast<FWidget*>(child);
|
2018-01-31 00:17:00 +01:00
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
if ( widget->isShown() && ! widget->isWindowWidget() )
|
2018-01-31 00:17:00 +01:00
|
|
|
widget->redraw();
|
|
|
|
}
|
2018-01-21 16:21:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 19:32:01 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FWidget::isDefaultTheme()
|
|
|
|
{
|
|
|
|
FStringList default_themes
|
|
|
|
{
|
|
|
|
"default8ColorTheme",
|
|
|
|
"default16ColorTheme",
|
|
|
|
"default8ColorDarkTheme",
|
|
|
|
"default16ColorDarkTheme"
|
|
|
|
};
|
|
|
|
|
|
|
|
auto iter = std::find ( default_themes.begin()
|
|
|
|
, default_themes.end()
|
|
|
|
, getColorTheme()->getClassName() );
|
|
|
|
|
|
|
|
if ( iter == default_themes.end() ) // No default theme
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-05-26 21:37:39 +02:00
|
|
|
void FWidget::initColorTheme()
|
2017-11-19 19:47:24 +01:00
|
|
|
{
|
2018-02-10 17:35:09 +01:00
|
|
|
// Sets the default color theme
|
|
|
|
|
2020-07-06 19:32:01 +02:00
|
|
|
if ( getColorTheme().use_count() > 0 && ! isDefaultTheme() )
|
|
|
|
return; // A user theme is in use
|
|
|
|
|
2020-05-29 00:27:25 +02:00
|
|
|
if ( FStartOptions::getFStartOptions().dark_theme )
|
|
|
|
{
|
|
|
|
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
|
|
|
|
setColorTheme<default8ColorDarkTheme>();
|
|
|
|
else
|
|
|
|
setColorTheme<default16ColorDarkTheme>();
|
|
|
|
}
|
2020-07-06 19:32:01 +02:00
|
|
|
else // Default theme
|
2020-05-29 00:27:25 +02:00
|
|
|
{
|
|
|
|
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
|
|
|
|
setColorTheme<default8ColorTheme>();
|
|
|
|
else
|
|
|
|
setColorTheme<default16ColorTheme>();
|
|
|
|
}
|
2020-05-26 21:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::destroyColorTheme()
|
|
|
|
{
|
2020-05-28 01:02:53 +02:00
|
|
|
const FWidgetColorsPtr* theme = &(getColorTheme());
|
2020-05-26 21:37:39 +02:00
|
|
|
delete theme;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWidget::setStatusbarText (bool enable)
|
|
|
|
{
|
|
|
|
if ( ! isEnabled() || ! getStatusBar() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( enable )
|
|
|
|
{
|
|
|
|
const auto& msg = getStatusbarMessage();
|
|
|
|
const auto& curMsg = getStatusBar()->getMessage();
|
|
|
|
|
|
|
|
if ( curMsg != msg )
|
|
|
|
getStatusBar()->setMessage(msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-04 23:38:47 +02:00
|
|
|
|
|
|
|
// non-member functions
|
2019-10-06 22:35:00 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void detectTermSize()
|
|
|
|
{
|
2020-03-05 21:30:54 +01:00
|
|
|
const auto& r = root_widget;
|
2019-10-06 22:35:00 +02:00
|
|
|
FTerm::detectTermSize();
|
|
|
|
r->adjust_wsize.setRect (1, 1, r->getDesktopWidth(), r->getDesktopHeight());
|
|
|
|
r->woffset.setRect (0, 0, r->getDesktopWidth(), r->getDesktopHeight());
|
|
|
|
r->wclient_offset.setCoordinates
|
|
|
|
(
|
|
|
|
r->padding.left,
|
|
|
|
r->padding.top,
|
|
|
|
int(r->getDesktopWidth()) - 1 - r->padding.right,
|
|
|
|
int(r->getDesktopHeight()) - 1 - r->padding.bottom
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|