Decoupling the FWidget and FWindow classes from FVTerm

This commit is contained in:
Markus Gans 2021-04-18 15:05:55 +02:00
parent 8a7ce330a3
commit 4c3b5b6737
14 changed files with 229 additions and 194 deletions

View File

@ -1,3 +1,8 @@
2021-04-18 Markus Gans <guru.mail@muenster.de>
* Decoupling the FWidget and FWindow classes from FVTerm
* Avoid redrawing widgets when show() is called multiple times
* Readjustment of the root widget when the terminal size is changed
2021-04-11 Markus Gans <guru.mail@muenster.de> 2021-04-11 Markus Gans <guru.mail@muenster.de>
* Better support for kitty terminals * Better support for kitty terminals

View File

@ -766,8 +766,11 @@ void FDialog::onWindowLowered (FEvent*)
if ( getWindowList()->empty() ) if ( getWindowList()->empty() )
return; return;
for (auto&& win : *getWindowList()) for (auto&& window : *getWindowList())
{
const auto win = static_cast<FWidget*>(window);
putArea (win->getTermPos(), win->getVWin()); putArea (win->getTermPos(), win->getVWin());
}
} }
@ -1216,8 +1219,10 @@ void FDialog::restoreOverlaidWindows()
bool overlaid{false}; bool overlaid{false};
for (auto&& win : *getWindowList()) for (auto&& window : *getWindowList())
{ {
const auto win = static_cast<FWidget*>(window);
if ( overlaid ) if ( overlaid )
putArea (win->getTermPos(), win->getVWin()); putArea (win->getTermPos(), win->getVWin());

View File

@ -599,8 +599,6 @@ void FListBox::adjustSize()
hbar->setWidth (width, false); hbar->setWidth (width, false);
hbar->resize(); hbar->resize();
if ( isShown() )
{
if ( isHorizontallyScrollable() ) if ( isHorizontallyScrollable() )
hbar->show(); hbar->show();
else else
@ -610,7 +608,6 @@ void FListBox::adjustSize()
vbar->show(); vbar->show();
else else
vbar->hide(); vbar->hide();
}
} }

View File

@ -1368,8 +1368,6 @@ void FListView::adjustScrollbars (const std::size_t element_count) const
hbar->setWidth (width, false); hbar->setWidth (width, false);
hbar->resize(); hbar->resize();
if ( isShown() )
{
if ( isHorizontallyScrollable() ) if ( isHorizontallyScrollable() )
hbar->show(); hbar->show();
else else
@ -1379,7 +1377,6 @@ void FListView::adjustScrollbars (const std::size_t element_count) const
vbar->show(); vbar->show();
else else
vbar->hide(); vbar->hide();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -638,11 +638,8 @@ void FScrollView::adjustSize()
vbar->setValue (yoffset); vbar->setValue (yoffset);
vbar->resize(); vbar->resize();
if ( isShown() )
{
setHorizontalScrollBarVisibility(); setHorizontalScrollBarVisibility();
setVerticalScrollBarVisibility(); setVerticalScrollBarVisibility();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -457,28 +457,14 @@ bool FTermDetection::get256colorEnvString()
color_env.string7 = std::getenv("COLORFGBG"); color_env.string7 = std::getenv("COLORFGBG");
color_env.string7 = std::getenv("KITTY_WINDOW_ID"); color_env.string7 = std::getenv("KITTY_WINDOW_ID");
if ( color_env.string1 != nullptr ) if ( color_env.string1 != nullptr
return true; || color_env.string2 != nullptr
|| color_env.string3 != nullptr
if ( color_env.string2 != nullptr ) || color_env.string4 != nullptr
return true; || color_env.string5 != nullptr
|| color_env.string6 != nullptr
if ( color_env.string3 != nullptr ) || color_env.string7 != nullptr
return true; || color_env.string8 != nullptr )
if ( color_env.string4 != nullptr )
return true;
if ( color_env.string5 != nullptr )
return true;
if ( color_env.string6 != nullptr )
return true;
if ( color_env.string7 != nullptr )
return true;
if ( color_env.string8 != nullptr )
return true; return true;
return false; return false;

View File

@ -526,8 +526,6 @@ void FTextView::adjustSize()
hbar->setValue (xoffset); hbar->setValue (xoffset);
hbar->resize(); hbar->resize();
if ( isShown() )
{
if ( isHorizontallyScrollable() ) if ( isHorizontallyScrollable() )
hbar->show(); hbar->show();
else else
@ -537,7 +535,6 @@ void FTextView::adjustSize()
vbar->show(); vbar->show();
else else
vbar->hide(); vbar->hide();
}
} }

View File

@ -48,8 +48,6 @@
#include "final/ftermcap.h" #include "final/ftermcap.h"
#include "final/ftypes.h" #include "final/ftypes.h"
#include "final/fvterm.h" #include "final/fvterm.h"
#include "final/fwidget.h"
#include "final/fwindow.h"
namespace finalcut namespace finalcut
{ {
@ -96,6 +94,7 @@ FVTerm::FVTerm()
fterm = std::shared_ptr<FTerm>(init_object->fterm); fterm = std::shared_ptr<FTerm>(init_object->fterm);
term_pos = std::shared_ptr<FPoint>(init_object->term_pos); term_pos = std::shared_ptr<FPoint>(init_object->term_pos);
output_buffer = std::shared_ptr<OutputBuffer>(init_object->output_buffer); output_buffer = std::shared_ptr<OutputBuffer>(init_object->output_buffer);
window_list = std::shared_ptr<FVTermList>(init_object->window_list);
} }
} }
@ -651,7 +650,7 @@ void FVTerm::createArea ( const FRect& box
return; return;
} }
area->widget = reinterpret_cast<FWidget*>(this); area->setOwner<FVTerm*>(this);
resizeArea (box, shadow, area); resizeArea (box, shadow, area);
} }
@ -1082,6 +1081,28 @@ void FVTerm::putArea (const FPoint& pos, const FTermArea* area)
vterm->has_changes = true; vterm->has_changes = true;
} }
//----------------------------------------------------------------------
int FVTerm::getLayer (FVTerm* obj)
{
// returns the layer from the FVTerm object
if ( ! getWindowList() || getWindowList()->empty() )
return -1;
auto iter = getWindowList()->begin();
const auto end = getWindowList()->end();
while ( iter != end )
{
if ( *iter == obj )
break;
++iter;
}
return int(std::distance(getWindowList()->begin(), iter) + 1);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FVTerm::scrollAreaForward (FTermArea* area) const void FVTerm::scrollAreaForward (FTermArea* area) const
{ {
@ -1389,11 +1410,11 @@ FVTerm::CoveredState FVTerm::isCovered ( const FPoint& pos
auto is_covered = CoveredState::None; auto is_covered = CoveredState::None;
if ( FWidget::getWindowList() && ! FWidget::getWindowList()->empty() ) if ( getWindowList() && ! getWindowList()->empty() )
{ {
bool found{ area == vdesktop }; bool found{ area == vdesktop };
for (auto& win_obj : *FWidget::getWindowList()) for (auto& win_obj : *getWindowList())
{ {
const auto& win = win_obj->getVWin(); const auto& win = win_obj->getVWin();
@ -1590,13 +1611,10 @@ void FVTerm::updateVTerm() const
vdesktop->has_changes = false; vdesktop->has_changes = false;
} }
const FWidget* widget = vterm->widget; if ( ! getWindowList() || getWindowList()->empty() )
if ( ! widget || ! widget->getWindowList()
|| widget->getWindowList()->empty() )
return; return;
for (auto&& window : *(widget->getWindowList())) for (auto&& window : *getWindowList())
{ {
auto v_win = window->getVWin(); auto v_win = window->getVWin();
@ -1686,10 +1704,10 @@ FChar FVTerm::generateCharacter (const FPoint& pos)
const int y = pos.getY(); const int y = pos.getY();
auto sc = &vdesktop->data[y * vdesktop->width + x]; // shown character auto sc = &vdesktop->data[y * vdesktop->width + x]; // shown character
if ( ! FWidget::getWindowList() || FWidget::getWindowList()->empty() ) if ( ! getWindowList() || getWindowList()->empty() )
return *sc; return *sc;
for (auto& win_obj : *FWidget::getWindowList()) for (auto& win_obj : *getWindowList())
{ {
const auto& win = win_obj->getVWin(); const auto& win = win_obj->getVWin();
@ -1767,24 +1785,26 @@ FChar FVTerm::getCharacter ( CharacterType char_type
auto cc = &vdesktop->data[yy * vdesktop->width + xx]; // covered character auto cc = &vdesktop->data[yy * vdesktop->width + xx]; // covered character
if ( ! area || ! FWidget::getWindowList() || FWidget::getWindowList()->empty() ) if ( ! area || ! getWindowList() || getWindowList()->empty() )
return *cc; return *cc;
// Get the window layer of this widget object // Get the window layer of this widget object
const int layer = FWindow::getWindowLayer(area->widget); const auto has_an_owner = area->hasOwner();
const auto area_owner = area->getOwner<FVTerm*>();
const int layer = has_an_owner ? getLayer(area_owner) : 0;
for (auto&& win_obj : *FWidget::getWindowList()) for (auto&& win_obj : *getWindowList())
{ {
bool significant_char{false}; bool significant_char{false};
// char_type can be "overlapped_character" // char_type can be "overlapped_character"
// or "covered_character" // or "covered_character"
if ( char_type == CharacterType::Covered ) if ( char_type == CharacterType::Covered )
significant_char = bool(layer >= FWindow::getWindowLayer(win_obj)); significant_char = bool(layer >= getLayer(win_obj));
else else
significant_char = bool(layer < FWindow::getWindowLayer(win_obj)); significant_char = bool(layer < getLayer(win_obj));
if ( area->widget && area->widget != win_obj && significant_char ) if ( has_an_owner && area_owner != win_obj && significant_char )
{ {
const auto& win = win_obj->getVWin(); const auto& win = win_obj->getVWin();
@ -1832,6 +1852,7 @@ void FVTerm::init()
fterm = std::make_shared<FTerm>(); fterm = std::make_shared<FTerm>();
term_pos = std::make_shared<FPoint>(-1, -1); term_pos = std::make_shared<FPoint>(-1, -1);
output_buffer = std::make_shared<OutputBuffer>(); output_buffer = std::make_shared<OutputBuffer>();
window_list = std::make_shared<FVTermList>();
} }
catch (const std::bad_alloc&) catch (const std::bad_alloc&)
{ {

View File

@ -54,7 +54,6 @@ FStatusBar* FWidget::statusbar{nullptr};
FMenuBar* FWidget::menubar{nullptr}; FMenuBar* FWidget::menubar{nullptr};
FWidget* FWidget::show_root_widget{nullptr}; FWidget* FWidget::show_root_widget{nullptr};
FWidget* FWidget::redraw_root_widget{nullptr}; FWidget* FWidget::redraw_root_widget{nullptr};
FWidget::FWidgetList* FWidget::window_list{nullptr};
FWidget::FWidgetList* FWidget::dialog_list{nullptr}; FWidget::FWidgetList* FWidget::dialog_list{nullptr};
FWidget::FWidgetList* FWidget::always_on_top_list{nullptr}; FWidget::FWidgetList* FWidget::always_on_top_list{nullptr};
FWidget::FWidgetList* FWidget::close_widget{nullptr}; FWidget::FWidgetList* FWidget::close_widget{nullptr};
@ -665,15 +664,16 @@ bool FWidget::setCursorPos (const FPoint& pos)
const auto& area = getPrintArea(); const auto& area = getPrintArea();
if ( area->widget ) if ( area->hasOwner() )
{ {
int woffsetX = getTermX() - area->widget->getTermX(); const auto object = area->getOwner<FWidget*>();
int woffsetY = getTermY() - area->widget->getTermY(); int woffsetX = getTermX() - object->getTermX();
int woffsetY = getTermY() - object->getTermY();
if ( isChildPrintArea() ) if ( isChildPrintArea() )
{ {
woffsetX += (1 - area->widget->getLeftPadding()); woffsetX += (1 - object->getLeftPadding());
woffsetY += (1 - area->widget->getTopPadding()); woffsetY += (1 - object->getTopPadding());
} }
bool visible = ! isCursorHideable() || flags.visible_cursor; bool visible = ! isCursorHideable() || flags.visible_cursor;
@ -959,7 +959,7 @@ void FWidget::show()
{ {
// Make the widget visible and draw it // Make the widget visible and draw it
if ( ! isVisible() || FApplication::isQuit() ) if ( ! isVisible() || isShown() || FApplication::isQuit() )
return; return;
// Initialize desktop on first call // Initialize desktop on first call
@ -1352,10 +1352,12 @@ void FWidget::adjustSizeGlobal()
return; return;
} }
if ( window_list && ! window_list->empty() ) adjustSize(); // Root widget / FApplication object
if ( getWindowList() && ! getWindowList()->empty() )
{ {
for (auto&& window : *window_list) for (auto&& window : *getWindowList())
window->adjustSize(); static_cast<FWidget*>(window)->adjustSize();
} }
} }
@ -1749,7 +1751,6 @@ void FWidget::initRootWidget()
try try
{ {
// Initialize widget lists // Initialize widget lists
window_list = new FWidgetList();
dialog_list = new FWidgetList(); dialog_list = new FWidgetList();
always_on_top_list = new FWidgetList(); always_on_top_list = new FWidgetList();
close_widget = new FWidgetList(); close_widget = new FWidgetList();
@ -1813,12 +1814,6 @@ void FWidget::finish()
delete always_on_top_list; delete always_on_top_list;
always_on_top_list = nullptr; always_on_top_list = nullptr;
} }
if ( window_list )
{
delete window_list;
window_list = nullptr;
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1946,7 +1941,7 @@ void FWidget::setWindowFocus (bool enable)
if ( ! window->isWindowActive() ) if ( ! window->isWindowActive() )
{ {
bool has_raised = window->raiseWindow(); bool has_raised = window->raiseWindow();
FWindow::setActiveWindow(window); window->setActiveWindow(window);
if ( has_raised && window->isVisible() && window->isShown() ) if ( has_raised && window->isVisible() && window->isShown() )
window->redraw(); window->redraw();
@ -2012,18 +2007,20 @@ void FWidget::drawWindows() const
default_char.attr.byte[0] = 0; default_char.attr.byte[0] = 0;
default_char.attr.byte[1] = 0; default_char.attr.byte[1] = 0;
if ( ! window_list || window_list->empty() ) if ( ! getWindowList() || getWindowList()->empty() )
return; return;
for (auto&& window : *window_list) for (auto&& window : *getWindowList())
{ {
if ( window->isShown() ) const auto win = static_cast<FWidget*>(window);
if ( win->isShown() )
{ {
auto v_win = window->getVWin(); auto v_win = win->getVWin();
const int w = v_win->width + v_win->right_shadow; const int w = v_win->width + v_win->right_shadow;
const int h = v_win->height + v_win->bottom_shadow; const int h = v_win->height + v_win->bottom_shadow;
std::fill_n (v_win->data, w * h, default_char); std::fill_n (v_win->data, w * h, default_char);
window->redraw(); win->redraw();
} }
} }
} }

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2015-2020 Markus Gans * * Copyright 2015-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -129,7 +129,7 @@ void FWindow::setActiveWindow (FWindow* window)
{ {
w->deactivateWindow(); w->deactivateWindow();
FEvent ev(Event::WindowInactive); FEvent ev(Event::WindowInactive);
FApplication::sendEvent(win, &ev); FApplication::sendEvent(static_cast<FWidget*>(win), &ev);
} }
} }
} }
@ -365,12 +365,10 @@ void FWindow::setHeight (std::size_t h, bool adjust)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::setSize (const FSize& size, bool adjust) void FWindow::setSize (const FSize& size, bool adjust)
{ {
const std::size_t old_width = getWidth(); const FSize old_size{getSize()};
const std::size_t old_height = getHeight();
FWidget::setSize (size, adjust); FWidget::setSize (size, adjust);
if ( isVirtualWindow() if ( isVirtualWindow() && getSize() != old_size )
&& (getWidth() != old_width || getHeight() != old_height) )
{ {
FRect geometry {getTermGeometry()}; FRect geometry {getTermGeometry()};
geometry.move(-1, -1); geometry.move(-1, -1);
@ -429,6 +427,7 @@ void FWindow::move (const FPoint& pos)
FWindow* FWindow::getWindowWidgetAt (int x, int y) FWindow* FWindow::getWindowWidgetAt (int x, int y)
{ {
// returns the window object to the corresponding coordinates // returns the window object to the corresponding coordinates
if ( getWindowList() && ! getWindowList()->empty() ) if ( getWindowList() && ! getWindowList()->empty() )
{ {
auto iter = getWindowList()->end(); auto iter = getWindowList()->end();
@ -482,56 +481,6 @@ void FWindow::delWindow (const FWidget* obj)
} }
} }
//----------------------------------------------------------------------
FWindow* FWindow::getWindowWidget (FWidget* obj)
{
// returns the window object to the given widget obj
auto p_obj = obj->getParentWidget();
while ( ! obj->isWindowWidget() && p_obj )
{
obj = p_obj;
p_obj = p_obj->getParentWidget();
}
if ( obj->isWindowWidget() )
return static_cast<FWindow*>(obj);
else
return nullptr;
}
//----------------------------------------------------------------------
int FWindow::getWindowLayer (FWidget* obj)
{
// returns the window layer from the widget obj
const FWidget* window;
if ( ! getWindowList() || getWindowList()->empty() )
return -1;
if ( ! obj->isWindowWidget() )
{
if ( (window = getWindowWidget(obj)) == nullptr )
return -1;
}
else
window = obj;
auto iter = getWindowList()->begin();
const auto end = getWindowList()->end();
while ( iter != end )
{
if ( *iter == window )
break;
++iter;
}
return int(std::distance(getWindowList()->begin(), iter) + 1);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::swapWindow (const FWidget* obj1, const FWidget* obj2) void FWindow::swapWindow (const FWidget* obj1, const FWidget* obj2)
{ {
@ -582,18 +531,19 @@ bool FWindow::raiseWindow (FWidget* obj)
if ( ! obj->isWindowWidget() ) if ( ! obj->isWindowWidget() )
return false; return false;
if ( getWindowList()->back() == obj ) const auto last = static_cast<FWidget*>(getWindowList()->back());
if ( last == obj )
return false; return false;
if ( getWindowList()->back()->getFlags().modal if ( last->getFlags().modal && ! obj->isMenuWidget() )
&& ! obj->isMenuWidget() )
return false; return false;
auto iter = getWindowList()->begin(); auto iter = getWindowList()->begin();
while ( iter != getWindowList()->end() ) while ( iter != getWindowList()->end() )
{ {
if ( *iter == obj ) if ( static_cast<FWidget*>(*iter) == obj )
{ {
getWindowList()->erase (iter); getWindowList()->erase (iter);
getWindowList()->push_back (obj); getWindowList()->push_back (obj);
@ -686,8 +636,7 @@ void FWindow::switchToPrevWindow (const FWidget* widget)
const bool is_activated = activatePrevWindow(); const bool is_activated = activatePrevWindow();
auto active_win = static_cast<FWindow*>(getActiveWindow()); auto active_win = static_cast<FWindow*>(getActiveWindow());
if ( ! is_activated if ( ! is_activated && getWindowList() && getWindowList()->size() > 1 )
&& getWindowList() && getWindowList()->size() > 1 )
{ {
// no previous window -> looking for another window // no previous window -> looking for another window
auto iter = getWindowList()->end(); auto iter = getWindowList()->end();
@ -716,7 +665,7 @@ void FWindow::switchToPrevWindow (const FWidget* widget)
auto focus = active_win->getWindowFocusWidget(); auto focus = active_win->getWindowFocusWidget();
if ( ! active_win->isWindowActive() ) if ( ! active_win->isWindowActive() )
setActiveWindow(active_win); active_win->setActiveWindow(active_win);
if ( focus ) if ( focus )
{ {
@ -745,7 +694,7 @@ bool FWindow::activatePrevWindow()
if ( ! w->isWindowHidden() ) if ( ! w->isWindowHidden() )
{ {
setActiveWindow(w); w->setActiveWindow(w);
return true; return true;
} }
} }
@ -885,6 +834,42 @@ void FWindow::processAlwaysOnTop()
} }
} }
//----------------------------------------------------------------------
FWindow* FWindow::getWindowWidgetImpl (FWidget* obj)
{
// returns the window object to the given widget obj
auto p_obj = obj->getParentWidget();
while ( ! obj->isWindowWidget() && p_obj )
{
obj = p_obj;
p_obj = p_obj->getParentWidget();
}
if ( obj->isWindowWidget() )
return static_cast<FWindow*>(obj);
else
return nullptr;
}
//----------------------------------------------------------------------
int FWindow::getWindowLayerImpl (FWidget* obj)
{
// returns the window layer from the widget obj
FWidget* window;
if ( ! obj->isWindowWidget() )
{
if ( (window = getWindowWidget(obj)) == nullptr )
return -1;
}
else
window = obj;
return FVTerm::getLayer(window);
}
// non-member functions // non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void closeDropDown (const FWidget* widget, const FPoint& mouse_position) void closeDropDown (const FWidget* widget, const FPoint& mouse_position)

View File

@ -165,6 +165,8 @@ class FData : public FDataAccess
, value_ref{value} , value_ref{value}
{ } { }
~FData() noexcept override = default; // Destructor
FData (const FData& d) // Copy constructor FData (const FData& d) // Copy constructor
: value{d.value} : value{d.value}
, value_ref{d.isInitializedCopy() ? std::ref(value) : d.value_ref} , value_ref{d.isInitializedCopy() ? std::ref(value) : d.value_ref}

View File

@ -58,6 +58,7 @@
#include <vector> #include <vector>
#include "final/fc.h" #include "final/fc.h"
#include "final/fdata.h"
#include "final/fstringstream.h" #include "final/fstringstream.h"
#include "final/fterm.h" #include "final/fterm.h"
@ -79,7 +80,7 @@ class FTerm;
class FTermBuffer; class FTermBuffer;
class FTermDebugData; class FTermDebugData;
class FStyle; class FStyle;
class FWidget;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FVTerm // class FVTerm
@ -102,6 +103,7 @@ class FVTerm
using FPreprocessingHandler = void (FVTerm::*)(); using FPreprocessingHandler = void (FVTerm::*)();
using FPreprocessingFunction = std::function<void()>; using FPreprocessingFunction = std::function<void()>;
using FPreprocessing = std::vector<std::unique_ptr<FVTermPreprocessing>>; using FPreprocessing = std::vector<std::unique_ptr<FVTermPreprocessing>>;
using FVTermList = std::vector<FVTerm*>;
// Enumerations // Enumerations
enum class CoveredState enum class CoveredState
@ -149,6 +151,7 @@ class FVTerm
const FTermArea* getVWin() const; const FTermArea* getVWin() const;
FPoint getPrintCursor(); FPoint getPrintCursor();
static FChar getAttribute(); static FChar getAttribute();
static FVTermList* getWindowList();
FTerm& getFTerm() const; FTerm& getFTerm() const;
// Mutators // Mutators
@ -278,6 +281,7 @@ class FVTerm
static void getArea (const FRect&, const FTermArea*); static void getArea (const FRect&, const FTermArea*);
void putArea (const FTermArea*) const; void putArea (const FTermArea*) const;
static void putArea (const FPoint&, const FTermArea*); static void putArea (const FPoint&, const FTermArea*);
static int getLayer (FVTerm*);
void scrollAreaForward (FTermArea*) const; void scrollAreaForward (FTermArea*) const;
void scrollAreaReverse (FTermArea*) const; void scrollAreaReverse (FTermArea*) const;
void clearArea (FTermArea*, wchar_t = L' ') const; void clearArea (FTermArea*, wchar_t = L' ') const;
@ -440,6 +444,7 @@ class FVTerm
std::shared_ptr<FTerm> fterm{}; std::shared_ptr<FTerm> fterm{};
std::shared_ptr<FPoint> term_pos{}; // terminal cursor position std::shared_ptr<FPoint> term_pos{}; // terminal cursor position
std::shared_ptr<OutputBuffer> output_buffer{}; std::shared_ptr<OutputBuffer> output_buffer{};
std::shared_ptr<FVTermList> window_list{}; // List of all window owner
static const FVTerm* init_object; // Global FVTerm object static const FVTerm* init_object; // Global FVTerm object
static FTermArea* vterm; // virtual terminal static FTermArea* vterm; // virtual terminal
static FTermArea* vdesktop; // virtual desktop static FTermArea* vdesktop; // virtual desktop
@ -473,6 +478,9 @@ class FVTerm
struct FVTerm::FTermArea // define virtual terminal character properties struct FVTerm::FTermArea // define virtual terminal character properties
{ {
// Using-declaration
using FDataAccessPtr = std::shared_ptr<FDataAccess>;
// Constructor // Constructor
FTermArea() = default; FTermArea() = default;
@ -485,6 +493,23 @@ struct FVTerm::FTermArea // define virtual terminal character properties
// Disable copy assignment operator (=) // Disable copy assignment operator (=)
FTermArea& operator = (const FTermArea&) = delete; FTermArea& operator = (const FTermArea&) = delete;
template <typename T>
clean_fdata_t<T>& getOwner() const
{
return static_cast<FData<clean_fdata_t<T>>&>(*owner).get();
}
template <typename T>
void setOwner (T&& obj)
{
owner.reset(makeFData(std::forward<T>(obj)));
}
bool hasOwner() const
{
return owner.get() != nullptr;
}
// Data members // Data members
int offset_left{0}; // Distance from left terminal side int offset_left{0}; // Distance from left terminal side
int offset_top{0}; // Distance from top of the terminal int offset_top{0}; // Distance from top of the terminal
@ -496,7 +521,7 @@ struct FVTerm::FTermArea // define virtual terminal character properties
int cursor_y{0}; // Y-position for the next write operation int cursor_y{0}; // Y-position for the next write operation
int input_cursor_x{-1}; // X-position input cursor int input_cursor_x{-1}; // X-position input cursor
int input_cursor_y{-1}; // Y-position input cursor int input_cursor_y{-1}; // Y-position input cursor
FWidget* widget{nullptr}; // Widget that owns this FTermArea FDataAccessPtr owner{nullptr}; // Object that owns this FTermArea
FPreprocessing preproc_list{}; FPreprocessing preproc_list{};
FLineChanges* changes{nullptr}; FLineChanges* changes{nullptr};
FChar* data{nullptr}; // FChar data of the drawing area FChar* data{nullptr}; // FChar data of the drawing area
@ -617,6 +642,14 @@ inline const FVTerm::FTermArea* FVTerm::getVWin() const
inline FChar FVTerm::getAttribute() inline FChar FVTerm::getAttribute()
{ return next_attribute; } { return next_attribute; }
//----------------------------------------------------------------------
inline FVTerm::FVTermList* FVTerm::getWindowList()
{
return (init_object && init_object->window_list)
? init_object->window_list.get()
: nullptr;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FTerm& FVTerm::getFTerm() const inline FTerm& FVTerm::getFTerm() const
{ return *fterm; } { return *fterm; }

View File

@ -183,7 +183,6 @@ class FWidget : public FVTerm, public FObject
static FWidget*& getClickedWidget(); static FWidget*& getClickedWidget();
static FWidget*& getOpenMenu(); static FWidget*& getOpenMenu();
static FWidget*& getMoveSizeWidget(); static FWidget*& getMoveSizeWidget();
static FWidgetList*& getWindowList();
static FMenuBar* getMenuBar(); static FMenuBar* getMenuBar();
static FStatusBar* getStatusBar(); static FStatusBar* getStatusBar();
static auto getColorTheme() -> std::shared_ptr<FWidgetColors>&; static auto getColorTheme() -> std::shared_ptr<FWidgetColors>&;
@ -480,7 +479,6 @@ class FWidget : public FVTerm, public FObject
static FWidget* move_size_widget; static FWidget* move_size_widget;
static FWidget* show_root_widget; static FWidget* show_root_widget;
static FWidget* redraw_root_widget; static FWidget* redraw_root_widget;
static FWidgetList* window_list;
static FWidgetList* dialog_list; static FWidgetList* dialog_list;
static FWidgetList* always_on_top_list; static FWidgetList* always_on_top_list;
static FWidgetList* close_widget; static FWidgetList* close_widget;
@ -555,10 +553,6 @@ inline FWidget*& FWidget::getOpenMenu()
inline FWidget*& FWidget::getMoveSizeWidget() inline FWidget*& FWidget::getMoveSizeWidget()
{ return move_size_widget; } { return move_size_widget; }
//----------------------------------------------------------------------
inline FWidget::FWidgetList*& FWidget::getWindowList()
{ return window_list; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FMenuBar* FWidget::getMenuBar() inline FMenuBar* FWidget::getMenuBar()
{ return menubar; } { return menubar; }

View File

@ -84,8 +84,10 @@ class FWindow : public FWidget
// Accessors // Accessors
FString getClassName() const override; FString getClassName() const override;
static FWindow* getWindowWidget (FWidget*); template<typename WidgetT>
static int getWindowLayer (FWidget*); static FWindow* getWindowWidget (WidgetT*);
template<typename WidgetT>
static int getWindowLayer (WidgetT*);
FWidget* getWindowFocusWidget() const; FWidget* getWindowFocusWidget() const;
// Mutators // Mutators
@ -159,6 +161,8 @@ class FWindow : public FWidget
// Methods // Methods
static void deleteFromAlwaysOnTopList (const FWidget*); static void deleteFromAlwaysOnTopList (const FWidget*);
static void processAlwaysOnTop(); static void processAlwaysOnTop();
static FWindow* getWindowWidgetImpl (FWidget*);
static int getWindowLayerImpl (FWidget*);
// Data members // Data members
FWidget* win_focus_widget{nullptr}; FWidget* win_focus_widget{nullptr};
@ -178,6 +182,21 @@ void closeDropDown (const FWidget*, const FPoint&);
inline FString FWindow::getClassName() const inline FString FWindow::getClassName() const
{ return "FWindow"; } { return "FWindow"; }
//----------------------------------------------------------------------
template<typename WidgetT>
inline FWindow* FWindow::getWindowWidget (WidgetT* obj)
{
return getWindowWidgetImpl (static_cast<FWidget*>(obj));
}
//----------------------------------------------------------------------
template<typename WidgetT>
inline int FWindow::getWindowLayer (WidgetT* obj)
{
return getWindowLayerImpl (static_cast<FWidget*>(obj));
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWindow::unsetWindowWidget() inline bool FWindow::unsetWindowWidget()
{ return setWindowWidget(false); } { return setWindowWidget(false); }