clear() and remove() were added to FListView

This commit is contained in:
Markus Gans 2020-02-02 22:34:27 +01:00
parent 06d65ed676
commit 60009d8f4b
79 changed files with 1585 additions and 1397 deletions

View File

@ -1,3 +1,8 @@
2020-02-02 Markus Gans <guru.mail@muenster.de>
* The methods clear() and remove() were added to FListView
* Add some const type qualifiers
* A small GNU autoconf-archive check
2020-01-12 Markus Gans <guru.mail@muenster.de> 2020-01-12 Markus Gans <guru.mail@muenster.de>
* Add a "widget layout" chapter to the first steps document * Add a "widget layout" chapter to the first steps document

View File

@ -13,6 +13,9 @@ AM_INIT_AUTOMAKE
AC_PROG_CC AC_PROG_CC
AC_PROG_CXX AC_PROG_CXX
m4_pattern_forbid([^AX_CHECK_COMPILE_FLAG\b],
[Macro AX_CHECK_COMPILE_FLAG not found. Please install GNU autoconf-archive])
# Checks for header files. # Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS( \ AC_CHECK_HEADERS( \

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 2012-2019 Markus Gans * * Copyright 2012-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -200,14 +200,14 @@ void SegmentView::draw()
for (auto&& ch : Input.getText().toUpper()) for (auto&& ch : Input.getText().toUpper())
{ {
FColorPair color(fc::LightRed, fc::Black); const FColorPair color(fc::LightRed, fc::Black);
get7Segment(ch); get7Segment(ch);
for (std::size_t i{0}; i < 3; i++) for (std::size_t i{0}; i < 3; i++)
tbuffer[i] << color << line[i] << " "; tbuffer[i] << color << line[i] << " ";
} }
std::size_t length = tbuffer[0].getLength(); const std::size_t length = tbuffer[0].getLength();
if ( length < 36 ) if ( length < 36 )
left_space << finalcut::FString(36 - length, ' '); left_space << finalcut::FString(36 - length, ' ');

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 2019 Markus Gans * * Copyright 2019-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -189,8 +189,8 @@ void Background::cb_choice (finalcut::FWidget*, FDataPtr)
return; return;
uChar r{}, g{}, b{}; uChar r{}, g{}, b{};
FDataPtr data_ptr = color_choice.getItemData(); const FDataPtr data_ptr = color_choice.getItemData();
RGB* rgb = reinterpret_cast<RGB*>(data_ptr); const RGB* rgb = reinterpret_cast<RGB*>(data_ptr);
std::tie(r, g, b) = *rgb; std::tie(r, g, b) = *rgb;
red.setValue(r); red.setValue(r);
green.setValue(g); green.setValue(g);

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -92,7 +92,7 @@ void Button::setChecked (bool enable)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Button::onKeyPress (finalcut::FKeyEvent* ev) void Button::onKeyPress (finalcut::FKeyEvent* ev)
{ {
FKey key = ev->key(); const FKey key = ev->key();
// catch the enter key // catch the enter key
if ( key == fc::Fkey_return || key == fc::Fkey_enter ) if ( key == fc::Fkey_return || key == fc::Fkey_enter )
@ -210,7 +210,7 @@ class Calc : public finalcut::FDialog
void clearInfixOperator(); void clearInfixOperator();
void calcInfixOperator(); void calcInfixOperator();
void adjustSize() override; void adjustSize() override;
const wchar_t* getButtonText (std::size_t); const wchar_t* getButtonText (const std::size_t);
void mapKeyFunctions(); void mapKeyFunctions();
// Data members // Data members
@ -257,9 +257,9 @@ Calc::Calc (FWidget* parent)
btn->setGeometry(FPoint(30, 15), FSize(5, 3)); btn->setGeometry(FPoint(30, 15), FSize(5, 3));
else else
{ {
std::size_t n = ( key <= Three ) ? 0 : 1; const std::size_t n = ( key <= Three ) ? 0 : 1;
int x = int(key + n) % 5 * 7 + 2; const int x = int(key + n) % 5 * 7 + 2;
int y = int(key + n) / 5 * 2 + 3; const int y = int(key + n) / 5 * 2 + 3;
btn->setGeometry(FPoint(x, y), FSize(5, 1)); btn->setGeometry(FPoint(x, y), FSize(5, 1));
} }
@ -338,17 +338,17 @@ void Calc::drawDispay()
if ( isNewFont() ) if ( isNewFont() )
{ {
wchar_t bottom_line {fc::NF_border_line_bottom}; const wchar_t bottom_line {fc::NF_border_line_bottom};
wchar_t top_bottom_line {fc::NF_border_line_up_and_down}; const wchar_t top_bottom_line {fc::NF_border_line_up_and_down};
wchar_t top_line {fc::NF_border_line_upper}; const wchar_t top_line {fc::NF_border_line_upper};
wchar_t right_line {fc::NF_rev_border_line_right}; const wchar_t right_line {fc::NF_rev_border_line_right};
wchar_t left_line {fc::NF_border_line_left}; const wchar_t left_line {fc::NF_border_line_left};
print() << FPoint(3, 2) << finalcut::FString(33, bottom_line); print() << FPoint(3, 2) << finalcut::FString(33, bottom_line);
print() << FPoint(2, 3) << right_line; print() << FPoint(2, 3) << right_line;
print() << FPoint(36, 3) << left_line; print() << FPoint(36, 3) << left_line;
print() << FPoint(3, 4); print() << FPoint(3, 4);
finalcut::FString top_bottom_line_5 (5, top_bottom_line); const finalcut::FString top_bottom_line_5 (5, top_bottom_line);
finalcut::FString top_line_2 (2, top_line); const finalcut::FString top_line_2 (2, top_line);
print ( top_bottom_line_5 + top_line_2 print ( top_bottom_line_5 + top_line_2
+ top_bottom_line_5 + top_line_2 + top_bottom_line_5 + top_line_2
+ top_bottom_line_5 + top_line_2 + top_bottom_line_5 + top_line_2
@ -357,9 +357,9 @@ void Calc::drawDispay()
} }
else else
{ {
wchar_t vertical_and_right {fc::BoxDrawingsVerticalAndRight}; const wchar_t vertical_and_right {fc::BoxDrawingsVerticalAndRight};
wchar_t horizontal {fc::BoxDrawingsHorizontal}; const wchar_t horizontal {fc::BoxDrawingsHorizontal};
wchar_t vertical_and_left {fc::BoxDrawingsVerticalAndLeft}; const wchar_t vertical_and_left {fc::BoxDrawingsVerticalAndLeft};
finalcut::FString separator ( finalcut::FString(vertical_and_right) finalcut::FString separator ( finalcut::FString(vertical_and_right)
+ finalcut::FString(35, horizontal) + finalcut::FString(35, horizontal)
+ finalcut::FString(vertical_and_left) ); + finalcut::FString(vertical_and_left) );
@ -601,7 +601,7 @@ void Calc::pi (lDouble& x)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::open_bracket (lDouble&) void Calc::open_bracket (lDouble&)
{ {
stack_data d{ a, infix_operator }; const stack_data d{ a, infix_operator };
bracket_stack.push(d); bracket_stack.push(d);
clearInfixOperator(); clearInfixOperator();
input = ""; input = "";
@ -617,7 +617,7 @@ void Calc::close_bracket (lDouble&)
calcInfixOperator(); calcInfixOperator();
setDisplay(a); setDisplay(a);
stack_data d = bracket_stack.top(); const stack_data d = bracket_stack.top();
bracket_stack.pop(); bracket_stack.pop();
b = d.term; b = d.term;
infix_operator = d.infix_operator; infix_operator = d.infix_operator;
@ -841,7 +841,7 @@ void Calc::draw()
bool Calc::isDataEntryKey (int key) bool Calc::isDataEntryKey (int key)
{ {
// Test if key is in {'.', '0'..'9'} // Test if key is in {'.', '0'..'9'}
int data_entry_keys[] = const int data_entry_keys[] =
{ {
Decimal_point, Decimal_point,
Zero, Zero,
@ -856,7 +856,7 @@ bool Calc::isDataEntryKey (int key)
Nine Nine
}; };
int* iter = std::find (data_entry_keys, data_entry_keys + 11, key); const int* iter = std::find (data_entry_keys, data_entry_keys + 11, key);
if ( iter != data_entry_keys + 11 ) if ( iter != data_entry_keys + 11 )
return true; return true;
@ -868,7 +868,7 @@ bool Calc::isDataEntryKey (int key)
bool Calc::isOperatorKey(int key) bool Calc::isOperatorKey(int key)
{ {
// Test if key is in {'*', '/', '+', '-', '^', '='} // Test if key is in {'*', '/', '+', '-', '^', '='}
int operators[] = const int operators[] =
{ {
Multiply, Multiply,
Divide, Divide,
@ -878,7 +878,7 @@ bool Calc::isOperatorKey(int key)
Equals Equals
}; };
int* iter = std::find (operators, operators + 6, key); const int* iter = std::find (operators, operators + 6, key);
if ( iter != operators + 6 ) if ( iter != operators + 6 )
return true; return true;
@ -980,8 +980,8 @@ void Calc::calcInfixOperator()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::onKeyPress (finalcut::FKeyEvent* ev) void Calc::onKeyPress (finalcut::FKeyEvent* ev)
{ {
std::size_t len = input.getLength(); const std::size_t len = input.getLength();
FKey key = ev->key(); const FKey key = ev->key();
switch ( key ) switch ( key )
{ {
@ -1040,7 +1040,7 @@ void Calc::onClose (finalcut::FCloseEvent* ev)
void Calc::cb_buttonClicked (finalcut::FWidget*, FDataPtr data) void Calc::cb_buttonClicked (finalcut::FWidget*, FDataPtr data)
{ {
lDouble& x = getValue(); lDouble& x = getValue();
Calc::button key = *(static_cast<Calc::button*>(data)); const Calc::button key = *(static_cast<Calc::button*>(data));
// Call the key function // Call the key function
(this->*key_map[key])(x); (this->*key_map[key])(x);
@ -1071,15 +1071,15 @@ void Calc::cb_buttonClicked (finalcut::FWidget*, FDataPtr data)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::adjustSize() void Calc::adjustSize()
{ {
std::size_t pw = getDesktopWidth(); const std::size_t pw = getDesktopWidth();
std::size_t ph = getDesktopHeight(); const std::size_t ph = getDesktopHeight();
setX (1 + int(pw - getWidth()) / 2, false); setX (1 + int(pw - getWidth()) / 2, false);
setY (1 + int(ph - getHeight()) / 2, false); setY (1 + int(ph - getHeight()) / 2, false);
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const wchar_t* Calc::getButtonText (std::size_t key) const wchar_t* Calc::getButtonText (const std::size_t key)
{ {
static const wchar_t* const button_text[Calc::NUM_OF_BUTTONS] = static const wchar_t* const button_text[Calc::NUM_OF_BUTTONS] =
{ {

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 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -73,7 +73,7 @@ CheckList::CheckList (finalcut::FWidget* parent)
{ {
setText (L"Shopping list"); setText (L"Shopping list");
setShadow(); setShadow();
std::size_t nf_offset = ( isNewFont() ) ? 1 : 0; const std::size_t nf_offset = ( isNewFont() ) ? 1 : 0;
setGeometry ( FPoint(int(1 + (parent->getWidth() - 28) / 2), 5) setGeometry ( FPoint(int(1 + (parent->getWidth() - 28) / 2), 5)
, FSize(28 + nf_offset, 13) ); , FSize(28 + nf_offset, 13) );
listView.ignorePadding(); listView.ignorePadding();

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 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -106,10 +106,10 @@ int main (int argc, char* argv[])
finalcut::FDialog dgl(&app); finalcut::FDialog dgl(&app);
dgl.setModal(); dgl.setModal();
dgl.setText ("UNIX select"); dgl.setText ("UNIX select");
std::size_t w{20}; const std::size_t w{20};
std::size_t h{13}; const std::size_t h{13};
int x = int(app.getDesktopWidth() - w) / 2; const int x = int(app.getDesktopWidth() - w) / 2;
int y = int(app.getDesktopHeight() - h) / 2; const int y = int(app.getDesktopHeight() - h) / 2;
dgl.setGeometry (FPoint(x, y), FSize(w, h)); dgl.setGeometry (FPoint(x, y), FSize(w, h));
// Create a button group // Create a button group

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -53,7 +53,7 @@ Keyboard::Keyboard (finalcut::FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Keyboard::onKeyPress (finalcut::FKeyEvent* ev) void Keyboard::onKeyPress (finalcut::FKeyEvent* ev)
{ {
FKey key_id = ev->key(); const FKey key_id = ev->key();
bool is_last_line{false}; bool is_last_line{false};
if ( getPrintPos().getY() == int(getDesktopHeight()) ) if ( getPrintPos().getY() == int(getDesktopHeight()) )

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 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -175,7 +175,7 @@ void Listview::populate()
for (const auto& place : weather) for (const auto& place : weather)
{ {
finalcut::FStringList line (&place[0], &place[0] + 5); const finalcut::FStringList line (&place[0], &place[0] + 5);
listView.insert (line); listView.insert (line);
} }
} }

View File

@ -67,23 +67,23 @@ void Mandelbrot::draw()
{ {
finalcut::FDialog::draw(); finalcut::FDialog::draw();
double x_min{-2.20}; const double x_min{-2.20};
double x_max{+1.00}; const double x_max{+1.00};
double y_min{-1.05}; const double y_min{-1.05};
double y_max{+1.05}; const double y_max{+1.05};
int max_iter{99}; const int max_iter{99};
int xoffset{2}; const int xoffset{2};
int yoffset{2}; const int yoffset{2};
const int Cols = int(getClientWidth());
const int Lines = int(getClientHeight());
int current_line{0}; int current_line{0};
int Cols = int(getClientWidth());
int Lines = int(getClientHeight());
if ( Cols < 2 || Lines < 2 ) if ( Cols < 2 || Lines < 2 )
return; return;
double dX = (x_max - x_min) / (Cols - 1); const double dX = (x_max - x_min) / (Cols - 1);
double dY = (y_max - y_min) / Lines; const double dY = (y_max - y_min) / Lines;
for (double y0 = y_min; y0 < y_max && current_line < Lines; y0 += dY) for (double y0 = y_min; y0 < y_max && current_line < Lines; y0 += dY)
{ {
@ -98,7 +98,7 @@ void Mandelbrot::draw()
while ( x * x + y * y < 4 && iter < max_iter ) while ( x * x + y * y < 4 && iter < max_iter )
{ {
double xtemp = x * x - y * y + x0; const double xtemp = x * x - y * y + x0;
y = 2 * x * y + y0; y = 2 * x * y + y0;
x = xtemp; x = xtemp;
iter++; iter++;
@ -138,8 +138,8 @@ void Mandelbrot::onClose (finalcut::FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Mandelbrot::adjustSize() void Mandelbrot::adjustSize()
{ {
std::size_t h = getDesktopHeight() - 1; const std::size_t h = getDesktopHeight() - 1;
std::size_t w = getDesktopWidth() - 10; const std::size_t w = getDesktopWidth() - 10;
setGeometry(FPoint(6, 1), FSize(w, h), false); setGeometry(FPoint(6, 1), FSize(w, h), false);
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();
} }

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -288,8 +288,8 @@ void Menu::defaultCallback (finalcut::FMenuList* mb)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Menu::adjustSize() void Menu::adjustSize()
{ {
int pw = int(getDesktopWidth()); const int pw = int(getDesktopWidth());
int ph = int(getDesktopHeight()); const int ph = int(getDesktopHeight());
setX (1 + (pw - int(getWidth())) / 2, false); setX (1 + (pw - int(getWidth())) / 2, false);
setY (1 + (ph - int(getHeight())) / 4, false); setY (1 + (ph - int(getHeight())) / 4, false);
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();
@ -304,7 +304,7 @@ void Menu::onClose (finalcut::FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Menu::cb_message (finalcut::FWidget* widget, FDataPtr) void Menu::cb_message (finalcut::FWidget* widget, FDataPtr)
{ {
auto menuitem = static_cast<finalcut::FMenuItem*>(widget); const auto& menuitem = static_cast<finalcut::FMenuItem*>(widget);
auto text = menuitem->getText(); auto text = menuitem->getText();
text = text.replace('&', ""); text = text.replace('&', "");
finalcut::FMessageBox::info ( this finalcut::FMessageBox::info ( this

View File

@ -76,8 +76,8 @@ ColorChooser::ColorChooser (finalcut::FWidget* parent)
if ( parent ) if ( parent )
{ {
FColor fg = parent->getForegroundColor(); const FColor fg = parent->getForegroundColor();
FColor bg = parent->getBackgroundColor(); const FColor bg = parent->getBackgroundColor();
setForegroundColor(fg); setForegroundColor(fg);
setBackgroundColor(bg); setBackgroundColor(bg);
headline.setForegroundColor(fg); headline.setForegroundColor(fg);
@ -98,17 +98,17 @@ ColorChooser::~ColorChooser()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ColorChooser::onMouseDown (finalcut::FMouseEvent* ev) void ColorChooser::onMouseDown (finalcut::FMouseEvent* ev)
{ {
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( ev->getButton() == fc::MiddleButton ) if ( ev->getButton() == fc::MiddleButton )
return; return;
for (int c{0}; c < 16; c++) for (int c{0}; c < 16; c++)
{ {
int xmin = 2 + (c / 8) * 3; const int xmin = 2 + (c / 8) * 3;
int xmax = 4 + (c / 8) * 3; const int xmax = 4 + (c / 8) * 3;
int y = 3 + c % 8; const int y = 3 + c % 8;
if ( mouse_x >= xmin && mouse_x <= xmax && mouse_y == y ) if ( mouse_x >= xmin && mouse_x <= xmax && mouse_y == y )
{ {
@ -219,8 +219,8 @@ Brushes::Brushes (finalcut::FWidget* parent)
if ( parent ) if ( parent )
{ {
FColor fg = parent->getForegroundColor(); const FColor fg = parent->getForegroundColor();
FColor bg = parent->getBackgroundColor(); const FColor bg = parent->getBackgroundColor();
setForegroundColor(fg); setForegroundColor(fg);
setBackgroundColor(bg); setBackgroundColor(bg);
headline.setForegroundColor(fg); headline.setForegroundColor(fg);
@ -267,8 +267,8 @@ void Brushes::drawBorder()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Brushes::onMouseDown (finalcut::FMouseEvent* ev) void Brushes::onMouseDown (finalcut::FMouseEvent* ev)
{ {
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
@ -381,12 +381,12 @@ MouseDraw::~MouseDraw()
void MouseDraw::setGeometry ( const FPoint& p, const FSize& s, bool adjust) void MouseDraw::setGeometry ( const FPoint& p, const FSize& s, bool adjust)
{ {
finalcut::FDialog::setGeometry (p, s, adjust); finalcut::FDialog::setGeometry (p, s, adjust);
std::size_t w = s.getWidth(); const std::size_t w = s.getWidth();
std::size_t h = s.getHeight(); const std::size_t h = s.getHeight();
finalcut::FRect scroll_geometry (FPoint(0, 0), FSize(w - 11, h - 3)); const finalcut::FRect scroll_geometry (FPoint(0, 0), FSize(w - 11, h - 3));
FSize no_shadow(0, 0); const FSize no_shadow(0, 0);
int old_w = canvas->width; const int old_w = canvas->width;
int old_h = canvas->height; const int old_h = canvas->height;
resizeArea (scroll_geometry, no_shadow, canvas); resizeArea (scroll_geometry, no_shadow, canvas);
if ( old_w != canvas->width || old_h != canvas->height ) if ( old_w != canvas->width || old_h != canvas->height )
@ -420,7 +420,7 @@ void MouseDraw::onClose (finalcut::FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MouseDraw::draw() void MouseDraw::draw()
{ {
int y_max = int(getHeight()); const int y_max = int(getHeight());
finalcut::FDialog::draw(); finalcut::FDialog::draw();
setColor(); setColor();
@ -455,8 +455,8 @@ void MouseDraw::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MouseDraw::drawBrush (int x, int y, bool swap_color) void MouseDraw::drawBrush (int x, int y, bool swap_color)
{ {
int Cols = int(getWidth()); const int Cols = int(getWidth());
int Lines = int(getHeight()); const int Lines = int(getHeight());
if ( x > 10 && x < Cols && y > 2 && y < Lines ) if ( x > 10 && x < Cols && y > 2 && y < Lines )
{ {
@ -485,11 +485,11 @@ void MouseDraw::drawCanvas()
return; return;
auto printarea = getCurrentPrintArea(); auto printarea = getCurrentPrintArea();
int ax = 9 + getTermX() - printarea->offset_left const int ax = 9 + getTermX() - printarea->offset_left;
, ay = 1 + getTermY() - printarea->offset_top const int ay = 1 + getTermY() - printarea->offset_top;
, y_end = canvas->height const int y_end = canvas->height;
, x_end = canvas->width const int x_end = canvas->width;
, w_line_len = printarea->width + printarea->right_shadow; const int w_line_len = printarea->width + printarea->right_shadow;
for (int y{0}; y < y_end; y++) // line loop for (int y{0}; y < y_end; y++) // line loop
{ {
@ -514,9 +514,9 @@ void MouseDraw::drawCanvas()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MouseDraw::adjustSize() void MouseDraw::adjustSize()
{ {
std::size_t w{60}, h{18}; const std::size_t w{60}, h{18};
int x = 1 + int((getParentWidget()->getWidth() - w) / 2); const int x = 1 + int((getParentWidget()->getWidth() - w) / 2);
int y = 1 + int((getParentWidget()->getHeight() - h) / 2); const int y = 1 + int((getParentWidget()->getHeight() - h) / 2);
setGeometry (FPoint(x, y), FSize(w, h), false); setGeometry (FPoint(x, y), FSize(w, h), false);
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();
} }

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -64,8 +64,8 @@ bool keyPressed()
void term_boundaries (int& x, int& y) void term_boundaries (int& x, int& y)
{ {
// checks and corrects the terminal boundaries // checks and corrects the terminal boundaries
int term_width = int(app->getDesktopWidth()); const int term_width = int(app->getDesktopWidth());
int term_height = int(app->getDesktopHeight()); const int term_height = int(app->getDesktopHeight());
if ( x < 0 ) if ( x < 0 )
x = 0; x = 0;
@ -115,7 +115,7 @@ void move (int xold, int yold, int xnew, int ynew)
from.sprintf ("(%3d;%3d)", xold, yold); from.sprintf ("(%3d;%3d)", xold, yold);
to.sprintf ("(%3d;%3d)", xnew, ynew); to.sprintf ("(%3d;%3d)", xnew, ynew);
std::size_t len = buffer.getLength(); const std::size_t len = buffer.getLength();
if ( len <= 1 ) if ( len <= 1 )
byte.sprintf ("%d byte ", len); byte.sprintf ("%d byte ", len);

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 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -118,8 +118,8 @@ Scrollview::~Scrollview()
void Scrollview::setScrollSize (const FSize& size) void Scrollview::setScrollSize (const FSize& size)
{ {
FScrollView::setScrollSize (size); FScrollView::setScrollSize (size);
int width = int(size.getWidth()); const int width = int(size.getWidth());
int height = int(size.getHeight()); const int height = int(size.getHeight());
go_south.setPos (FPoint(width - 5, 1)); go_south.setPos (FPoint(width - 5, 1));
go_west.setPos (FPoint(width - 5, height - 1)); go_west.setPos (FPoint(width - 5, height - 1));
go_north.setPos (FPoint(1, height - 1)); go_north.setPos (FPoint(1, height - 1));

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -122,7 +122,7 @@ void AttribDlg::onKeyPress (finalcut::FKeyEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDlg::onWheel (finalcut::FWheelEvent* ev) void AttribDlg::onWheel (finalcut::FWheelEvent* ev)
{ {
int wheel = ev->getWheel(); const int wheel = ev->getWheel();
if ( wheel == fc::WheelUp ) if ( wheel == fc::WheelUp )
cb_next(); cb_next();
@ -251,7 +251,7 @@ AttribDemo::AttribDemo (finalcut::FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDemo::printColorLine() void AttribDemo::printColorLine()
{ {
auto parent = static_cast<AttribDlg*>(getParent()); const auto& parent = static_cast<AttribDlg*>(getParent());
for (FColor color{0}; color < last_color; color++) for (FColor color{0}; color < last_color; color++)
{ {
@ -263,7 +263,7 @@ void AttribDemo::printColorLine()
void AttribDemo::printAltCharset() void AttribDemo::printAltCharset()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
auto parent = static_cast<AttribDlg*>(getParent()); const auto& parent = static_cast<AttribDlg*>(getParent());
if ( ! isMonochron() ) if ( ! isMonochron() )
setColor (wc.label_fg, wc.label_bg); setColor (wc.label_fg, wc.label_bg);
@ -416,7 +416,7 @@ void AttribDemo::draw()
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
printAltCharset(); printAltCharset();
std::vector<std::function<void()> > effect const std::vector<std::function<void()> > effect
{ {
[&] { printDim(); }, [&] { printDim(); },
[&] { printNormal(); }, [&] { printNormal(); },
@ -448,7 +448,7 @@ void AttribDemo::draw()
setColor(wc.label_fg, wc.label_bg); setColor(wc.label_fg, wc.label_bg);
print() << FPoint(1, 15); print() << FPoint(1, 15);
FColor bg = static_cast<AttribDlg*>(getParent())->bgcolor; const FColor bg = static_cast<AttribDlg*>(getParent())->bgcolor;
print (" Background color:"); print (" Background color:");
if ( bg == fc::Default ) if ( bg == fc::Default )

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 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -174,11 +174,11 @@ void tcapString (const std::string& name, const char cap_str[])
return; return;
} }
uInt len = uInt(std::strlen(cap_str)); const uInt len = uInt(std::strlen(cap_str));
for (uInt i{0}; i < len; i++) for (uInt i{0}; i < len; i++)
{ {
uChar c = uChar(cap_str[i]); const uChar c = uChar(cap_str[i]);
if ( c > 127 ) if ( c > 127 )
{ {
@ -209,7 +209,7 @@ void tcapString (const std::string& name, const char cap_str[])
#if DEBUG #if DEBUG
void debug (finalcut::FApplication& TermApp) void debug (finalcut::FApplication& TermApp)
{ {
auto& fterm = TermApp.getFTerm(); const auto& fterm = TermApp.getFTerm();
auto& debug_data = fterm.getFTermDebugData(); auto& debug_data = fterm.getFTermDebugData();
const finalcut::FString& ab_s = debug_data.getAnswerbackString(); const finalcut::FString& ab_s = debug_data.getAnswerbackString();
const finalcut::FString& sec_da = debug_data.getSecDAString(); const finalcut::FString& sec_da = debug_data.getSecDAString();
@ -278,7 +278,7 @@ void numeric()
void string() void string()
{ {
std::cout << "\r\n[String]\r\n"; std::cout << "\r\n[String]\r\n";
finalcut::FTermcap::tcap_map (&tcap_strings)[] \ const finalcut::FTermcap::tcap_map (&tcap_strings)[] \
= finalcut::FTermcap::strings; = finalcut::FTermcap::strings;
for (const auto& entry : data::strings) for (const auto& entry : data::strings)
@ -294,7 +294,7 @@ void string()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
bool disable_alt_screen{true}; const bool disable_alt_screen{true};
finalcut::FApplication TermApp (argc, argv, disable_alt_screen); finalcut::FApplication TermApp (argc, argv, disable_alt_screen);
std::cout << "--------\r\nFTermcap\r\n--------\r\n\n"; std::cout << "--------\r\nFTermcap\r\n--------\r\n\n";

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -48,11 +48,11 @@ class Timer : public finalcut::FWidget
Timer::Timer (finalcut::FWidget* parent) Timer::Timer (finalcut::FWidget* parent)
: finalcut::FWidget(parent) : finalcut::FWidget(parent)
{ {
addTimer (60000); // 1-minute timer addTimer (60000); // 1-minute timer
int id = addTimer (50); // 50-millisecond timer const int id = addTimer (50); // 50-millisecond timer
addTimer (1000); // 1-second timer addTimer (1000); // 1-second timer
delTimer (id); delTimer (id);
addTimer (250); // 250-millisecond timer addTimer (250); // 250-millisecond timer
setFWidgetColors().term_fg = fc::Default; setFWidgetColors().term_fg = fc::Default;
setFWidgetColors().term_bg = fc::Default; setFWidgetColors().term_bg = fc::Default;
@ -72,7 +72,7 @@ void Timer::draw()
void Timer::onTimer (finalcut::FTimerEvent* ev) void Timer::onTimer (finalcut::FTimerEvent* ev)
{ {
bool is_last_line{false}; bool is_last_line{false};
int timer_id = ev->getTimerId(); const int timer_id = ev->getTimerId();
if ( getPrintPos().getY() == int(getDesktopHeight()) ) if ( getPrintPos().getY() == int(getDesktopHeight()) )
is_last_line = true; is_last_line = true;

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -105,7 +105,7 @@ void Transparent::draw()
else else
setTransparent(); setTransparent();
finalcut::FString line(getClientWidth(), '.'); const finalcut::FString line(getClientWidth(), '.');
for (int n{1}; n <= int(getClientHeight()); n++) for (int n{1}; n <= int(getClientHeight()); n++)
{ {

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 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -338,7 +338,7 @@ Treeview::Treeview (finalcut::FWidget* parent)
TreeItem* country_list = continent.child_element; TreeItem* country_list = continent.child_element;
finalcut::FStringList continent_line ( continent.begin() finalcut::FStringList continent_line ( continent.begin()
, continent.end() ); , continent.end() );
const auto& iter = listView.insert (continent_line); auto iter = listView.insert (continent_line);
while ( country_list && country_list->name ) while ( country_list && country_list->name )
{ {

View File

@ -738,7 +738,7 @@ void MyDialog::initWidgetsCallbacks()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::adjustSize() void MyDialog::adjustSize()
{ {
auto h = getParentWidget()->getHeight() - 4; const auto h = getParentWidget()->getHeight() - 4;
setHeight (h, false); setHeight (h, false);
int X = int((getDesktopWidth() - getWidth()) / 2); int X = int((getDesktopWidth() - getWidth()) / 2);
@ -788,8 +788,8 @@ void MyDialog::cb_about (finalcut::FWidget*, FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_terminfo (finalcut::FWidget*, FDataPtr) void MyDialog::cb_terminfo (finalcut::FWidget*, FDataPtr)
{ {
auto x = getDesktopWidth(); const auto x = getDesktopWidth();
auto y = getDesktopHeight(); const auto y = getDesktopHeight();
finalcut::FMessageBox info1 \ finalcut::FMessageBox info1 \
( (
"Environment" "Environment"
@ -918,7 +918,7 @@ void MyDialog::cb_updateNumber (finalcut::FWidget* widget, FDataPtr data)
{ {
auto& list = *(static_cast<finalcut::FListBox*>(widget)); auto& list = *(static_cast<finalcut::FListBox*>(widget));
auto& num = *(static_cast<finalcut::FLabel*>(data)); auto& num = *(static_cast<finalcut::FLabel*>(data));
const auto& count = list.getCount(); const auto count = list.getCount();
int select_num = 0; int select_num = 0;
for (std::size_t n{1}; n <= count; n++) for (std::size_t n{1}; n <= count; n++)
@ -948,7 +948,7 @@ void MyDialog::cb_activateButton (finalcut::FWidget* widget, FDataPtr data)
void MyDialog::cb_view (finalcut::FWidget*, FDataPtr data) void MyDialog::cb_view (finalcut::FWidget*, FDataPtr data)
{ {
finalcut::FString file; finalcut::FString file;
auto item = static_cast<finalcut::FMenuItem*>(data); const auto& item = static_cast<finalcut::FMenuItem*>(data);
if ( item && ! item->getText().isEmpty() ) if ( item && ! item->getText().isEmpty() )
file = item->getText(); file = item->getText();

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -76,7 +76,7 @@ Watch::Watch (FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog(parent)
{ {
setText ("Watch"); setText ("Watch");
int pw = int(getParentWidget()->getWidth()); const int pw = int(getParentWidget()->getWidth());
setGeometry (FPoint(1 + (pw - 22) / 2, 3), FSize(22, 13)); setGeometry (FPoint(1 + (pw - 22) / 2, 3), FSize(22, 13));
// Labels // Labels
@ -126,7 +126,7 @@ void Watch::printTime()
finalcut::FString str{}; finalcut::FString str{};
std::tm now{}; std::tm now{};
std::time_t t = std::time(0); // get current time const std::time_t t = std::time(0); // get current time
localtime_r(&t, &now); localtime_r(&t, &now);
if ( sec ) if ( sec )
@ -190,7 +190,7 @@ void Watch::cb_seconds (finalcut::FWidget*, FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Watch::adjustSize() void Watch::adjustSize()
{ {
int pw = int(getParentWidget()->getWidth()); const int pw = int(getParentWidget()->getWidth());
setX (1 + (pw - 22) / 2, false); setX (1 + (pw - 22) / 2, false);
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();
} }

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -69,9 +69,8 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog(parent)
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
wchar_t arrow_up, arrow_down; const wchar_t arrow_up = fc::BlackUpPointingTriangle;
arrow_up = fc::BlackUpPointingTriangle; const wchar_t arrow_down = fc::BlackDownPointingTriangle;
arrow_down = fc::BlackDownPointingTriangle;
left_arrow = arrow_up; left_arrow = arrow_up;
left_arrow.setForegroundColor (wc.label_inactive_fg); left_arrow.setForegroundColor (wc.label_inactive_fg);
@ -330,7 +329,7 @@ void Window::activateWindow (finalcut::FDialog* win)
if ( ! win || win->isWindowHidden() || win->isWindowActive() ) if ( ! win || win->isWindowHidden() || win->isWindowActive() )
return; return;
bool has_raised = finalcut::FWindow::raiseWindow(win); const bool has_raised = finalcut::FWindow::raiseWindow(win);
win->activateDialog(); win->activateDialog();
if ( has_raised ) if ( has_raised )
@ -342,27 +341,27 @@ void Window::activateWindow (finalcut::FDialog* win)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Window::adjustSize() void Window::adjustSize()
{ {
std::size_t w = getDesktopWidth(); const std::size_t w = getDesktopWidth();
std::size_t h = getDesktopHeight(); const std::size_t h = getDesktopHeight();
int X = int(1 + (w - 40) / 2); const int X = int(1 + (w - 40) / 2);
int Y = int(1 + (h - 22) / 2); int Y = int(1 + (h - 22) / 2);
int dx = ( w > 80 ) ? int(w - 80) / 2 : 0; const int dx = ( w > 80 ) ? int(w - 80) / 2 : 0;
int dy = ( h > 24 ) ? int(h - 24) / 2 : 0; const int dy = ( h > 24 ) ? int(h - 24) / 2 : 0;
if ( Y < 2 ) if ( Y < 2 )
Y = 2; Y = 2;
setPos (FPoint(X, Y)); setPos (FPoint(X, Y));
auto first = windows.begin(); const auto& first = windows.begin();
auto iter = first; auto iter = first;
while ( iter != windows.end() ) while ( iter != windows.end() )
{ {
if ( (*iter)->is_open ) if ( (*iter)->is_open )
{ {
int n = int(std::distance(first, iter)); const int n = int(std::distance(first, iter));
int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3; const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3;
int y = dy + 11 + int(n / 3) * 3; const int y = dy + 11 + int(n / 3) * 3;
(*iter)->dgl->setPos (FPoint(x, y)); (*iter)->dgl->setPos (FPoint(x, y));
} }
@ -409,12 +408,12 @@ void Window::onClose (finalcut::FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Window::cb_createWindows (finalcut::FWidget*, FDataPtr) void Window::cb_createWindows (finalcut::FWidget*, FDataPtr)
{ {
auto first = windows.begin(); const auto& first = windows.begin();
auto iter = first; auto iter = first;
auto w = getRootWidget()->getWidth(); const auto w = getRootWidget()->getWidth();
auto h = getRootWidget()->getHeight(); const auto h = getRootWidget()->getHeight();
int dx = ( w > 80 ) ? int(w - 80) / 2 : 0; const int dx = ( w > 80 ) ? int(w - 80) / 2 : 0;
int dy = ( h > 24 ) ? int(h - 24) / 2 : 0; const int dy = ( h > 24 ) ? int(h - 24) / 2 : 0;
while ( iter != windows.end() ) while ( iter != windows.end() )
{ {
@ -425,9 +424,9 @@ void Window::cb_createWindows (finalcut::FWidget*, FDataPtr)
win_dat->dgl = win; win_dat->dgl = win;
win_dat->is_open = true; win_dat->is_open = true;
win->setText(win_dat->title); win->setText(win_dat->title);
int n = int(std::distance(first, iter)) const int n = int(std::distance(first, iter));
, x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3 const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3;
, y = dy + 11 + int(n / 3) * 3; const int y = dy + 11 + int(n / 3) * 3;
win->setGeometry (FPoint(x, y), FSize(20, 8)); win->setGeometry (FPoint(x, y), FSize(20, 8));
win->setMinimumSize (FSize(20, 8)); win->setMinimumSize (FSize(20, 8));
win->setResizeable(); win->setResizeable();
@ -454,7 +453,7 @@ void Window::cb_closeWindows (finalcut::FWidget*, FDataPtr)
return; return;
auto iter = getDialogList()->end(); auto iter = getDialogList()->end();
auto first = getDialogList()->begin(); const auto& first = getDialogList()->begin();
activateWindow(this); activateWindow(this);
do do

BIN
src/.swp

Binary file not shown.

View File

@ -55,7 +55,7 @@ FWidget* FWidget::move_size_widget {nullptr}; // move/size by keyboar
FWidget* FApplication::keyboard_widget {nullptr}; // has the keyboard focus FWidget* FApplication::keyboard_widget {nullptr}; // has the keyboard focus
FKeyboard* FApplication::keyboard {nullptr}; // keyboard access FKeyboard* FApplication::keyboard {nullptr}; // keyboard access
FMouseControl* FApplication::mouse {nullptr}; // mouse control FMouseControl* FApplication::mouse {nullptr}; // mouse control
int FApplication::loop_level {0}; // event loop level int FApplication::loop_level {0}; // event loop level
int FApplication::quit_code {0}; int FApplication::quit_code {0};
bool FApplication::quit_now {false}; bool FApplication::quit_now {false};
@ -140,7 +140,7 @@ int FApplication::enterLoop() // event loop
loop_level++; loop_level++;
quit_now = false; quit_now = false;
bool old_app_exit_loop = app_exit_loop; const bool old_app_exit_loop = app_exit_loop;
app_exit_loop = false; app_exit_loop = false;
while ( ! (quit_now || app_exit_loop) ) while ( ! (quit_now || app_exit_loop) )
@ -350,11 +350,11 @@ void FApplication::showParameterUsage()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev) void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev)
{ {
int ret = FMessageBox::info ( w, "Quit" const int ret = FMessageBox::info ( w, "Quit"
, "Do you really want\n" , "Do you really want\n"
"to quit the program ?" "to quit the program ?"
, FMessageBox::Yes , FMessageBox::Yes
, FMessageBox::No ); , FMessageBox::No );
if ( ret == FMessageBox::Yes ) if ( ret == FMessageBox::Yes )
ev->accept(); ev->accept();
else else
@ -435,7 +435,7 @@ void FApplication::cmd_options (const int& argc, char* argv[])
opterr = 0; opterr = 0;
int idx{0}; int idx{0};
int c = getopt_long (argc, argv, "", long_options, &idx); const int c = getopt_long (argc, argv, "", long_options, &idx);
if ( c == -1 ) if ( c == -1 )
break; break;
@ -597,8 +597,8 @@ inline void FApplication::performKeyboardAction()
break; break;
default: default:
bool acceptKeyDown = sendKeyDownEvent (keyboard_widget); const bool acceptKeyDown = sendKeyDownEvent (keyboard_widget);
bool acceptKeyPress = sendKeyPressEvent (keyboard_widget); const bool acceptKeyPress = sendKeyPressEvent (keyboard_widget);
if ( ! (acceptKeyDown || acceptKeyPress) ) if ( ! (acceptKeyDown || acceptKeyPress) )
sendKeyboardAccelerator(); sendKeyboardAccelerator();
@ -693,9 +693,9 @@ bool FApplication::processDialogSwitchAccelerator()
if ( keyboard->getKey() >= fc::Fmkey_1 if ( keyboard->getKey() >= fc::Fmkey_1
&& keyboard->getKey() <= fc::Fmkey_9 ) && keyboard->getKey() <= fc::Fmkey_9 )
{ {
FKey key = keyboard->getKey(); const FKey key = keyboard->getKey();
std::size_t n = key - fc::Fmkey_0; const std::size_t n = key - fc::Fmkey_0;
std::size_t s = getDialogList()->size(); const std::size_t s = getDialogList()->size();
if ( s > 0 && s >= n ) if ( s > 0 && s >= n )
{ {
@ -727,7 +727,7 @@ bool FApplication::processAccelerator (const FWidget*& widget)
&& ! widget->getAcceleratorList().empty() ) && ! widget->getAcceleratorList().empty() )
{ {
auto iter = widget->getAcceleratorList().begin(); auto iter = widget->getAcceleratorList().begin();
auto last = widget->getAcceleratorList().end(); const auto& last = widget->getAcceleratorList().end();
while ( iter != last ) while ( iter != last )
{ {
@ -791,7 +791,7 @@ FWidget*& FApplication::determineClickedWidget()
&& ! mouse->isWheelDown() ) && ! mouse->isWheelDown() )
return clicked; return clicked;
const auto& mouse_position = mouse->getPos(); auto mouse_position = mouse->getPos();
// Determine the window object on the current click position // Determine the window object on the current click position
auto window = FWindow::getWindowWidgetAt (mouse_position); auto window = FWindow::getWindowWidgetAt (mouse_position);
@ -830,7 +830,7 @@ void FApplication::closeDropDown()
if ( ! mouse || mouse->isMoved() ) if ( ! mouse || mouse->isMoved() )
return; return;
const auto& mouse_position = mouse->getPos(); auto mouse_position = mouse->getPos();
finalcut::closeDropDown (this, mouse_position); finalcut::closeDropDown (this, mouse_position);
} }
@ -839,7 +839,7 @@ void FApplication::unselectMenubarItems()
{ {
// Unselect the menu bar items // Unselect the menu bar items
auto openmenu = FWidget::getOpenMenu(); const auto& openmenu = FWidget::getOpenMenu();
auto menu_bar = FWidget::getMenuBar(); auto menu_bar = FWidget::getMenuBar();
if ( openmenu || (mouse && mouse->isMoved()) ) if ( openmenu || (mouse && mouse->isMoved()) )
@ -890,7 +890,7 @@ void FApplication::sendMouseEvent()
if ( mouse->isMetaKeyPressed() ) if ( mouse->isMetaKeyPressed() )
key_state |= fc::MetaButton; key_state |= fc::MetaButton;
auto widgetMousePos = clicked->termToWidgetPos(mouse_position); const auto& widgetMousePos = clicked->termToWidgetPos(mouse_position);
if ( mouse->isMoved() ) if ( mouse->isMoved() )
{ {

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 2012-2019 Markus Gans * * Copyright 2012-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -217,15 +217,15 @@ void FButton::hide()
} }
else else
{ {
const auto& wc = getFWidgetColors(); auto wc = getFWidgetColors();
fg = wc.dialog_fg; fg = wc.dialog_fg;
bg = wc.dialog_bg; bg = wc.dialog_bg;
} }
setColor (fg, bg); setColor (fg, bg);
std::size_t s = hasShadow() ? 1 : 0; const std::size_t s = hasShadow() ? 1 : 0;
std::size_t f = isFlat() ? 1 : 0; const std::size_t f = isFlat() ? 1 : 0;
std::size_t size = getWidth() + s + (f << 1); const std::size_t size = getWidth() + s + (f << 1);
if ( size == 0 ) if ( size == 0 )
return; return;
@ -243,7 +243,7 @@ void FButton::onKeyPress (FKeyEvent* ev)
if ( ! isEnabled() ) if ( ! isEnabled() )
return; return;
FKey key = ev->key(); const FKey key = ev->key();
switch ( key ) switch ( key )
{ {
@ -285,7 +285,7 @@ void FButton::onMouseDown (FMouseEvent* ev)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
} }
FPoint tPos(ev->getTermPos()); const FPoint tPos(ev->getTermPos());
if ( getTermGeometry().contains(tPos) ) if ( getTermGeometry().contains(tPos) )
setDown(); setDown();
@ -312,7 +312,7 @@ void FButton::onMouseMove (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
FPoint tPos(ev->getTermPos()); const FPoint tPos(ev->getTermPos());
if ( click_animation ) if ( click_animation )
{ {
@ -575,7 +575,7 @@ inline void FButton::drawButtonTextLine (const FString& button_text)
print (button_text[z]); print (button_text[z]);
} }
auto char_width = getColumnWidth (button_text[z]); const auto char_width = getColumnWidth (button_text[z]);
columns += char_width; columns += char_width;
pos += char_width; pos += char_width;
} }
@ -597,7 +597,7 @@ inline void FButton::drawButtonTextLine (const FString& button_text)
void FButton::draw() void FButton::draw()
{ {
FString button_text{}; FString button_text{};
auto parent_widget = getParentWidget(); const auto& parent_widget = getParentWidget();
column_width = getColumnWidth(text); column_width = getColumnWidth(text);
space_char = int(' '); space_char = int(' ');
active_focus = getFlags().active && getFlags().focus; active_focus = getFlags().active && getFlags().focus;

View File

@ -4,7 +4,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -129,7 +129,7 @@ void FButtonGroup::setText (const FString& txt)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FButtonGroup::isChecked (int index) const bool FButtonGroup::isChecked (int index) const
{ {
auto button = getButton(index); const auto& button = getButton(index);
if ( button ) if ( button )
return button->isChecked(); return button->isChecked();
@ -145,7 +145,7 @@ bool FButtonGroup::hasFocusedButton() const
for (auto&& item : buttonlist) for (auto&& item : buttonlist)
{ {
auto toggle_button = static_cast<FToggleButton*>(item); const auto& toggle_button = static_cast<FToggleButton*>(item);
if ( toggle_button->hasFocus() ) if ( toggle_button->hasFocus() )
return true; return true;
@ -162,7 +162,7 @@ bool FButtonGroup::hasCheckedButton() const
for (auto&& item : buttonlist) for (auto&& item : buttonlist)
{ {
auto toggle_button = static_cast<FToggleButton*>(item); const auto& toggle_button = static_cast<FToggleButton*>(item);
if ( toggle_button->isChecked() ) if ( toggle_button->isChecked() )
return true; return true;
@ -176,7 +176,7 @@ void FButtonGroup::hide()
{ {
FColor fg{}, bg{}; FColor fg{}, bg{};
FWidget::hide(); FWidget::hide();
auto parent_widget = getParentWidget(); const auto& parent_widget = getParentWidget();
if ( ! buttonlist.empty() ) if ( ! buttonlist.empty() )
{ {
@ -201,7 +201,7 @@ void FButtonGroup::hide()
} }
setColor (fg, bg); setColor (fg, bg);
std::size_t size = getWidth(); const std::size_t size = getWidth();
if ( size == 0 ) if ( size == 0 )
return; return;
@ -253,7 +253,7 @@ void FButtonGroup::remove (FToggleButton* button)
while ( iter != buttonlist.end() ) while ( iter != buttonlist.end() )
{ {
auto toggle_button = static_cast<FToggleButton*>(*iter); const auto& toggle_button = static_cast<FToggleButton*>(*iter);
if ( toggle_button == button ) if ( toggle_button == button )
{ {
@ -280,11 +280,11 @@ void FButtonGroup::checkScrollSize (const FRect& r)
{ {
// Check and adjust the scroll size // Check and adjust the scroll size
FRect scrollgeometry (1, 1, getScrollWidth(), getScrollHeight()); const FRect scrollgeometry (1, 1, getScrollWidth(), getScrollHeight());
if ( ! scrollgeometry.contains(r) ) if ( ! scrollgeometry.contains(r) )
{ {
FRect r_combined (scrollgeometry.combined(r)); const FRect r_combined (scrollgeometry.combined(r));
setScrollSize (r_combined.getSize()); setScrollSize (r_combined.getSize());
} }
} }
@ -399,9 +399,9 @@ void FButtonGroup::drawLabel()
return; return;
FString label_text{}; FString label_text{};
FString txt{" " + text + " "}; const FString txt{" " + text + " "};
unsetViewportPrint(); unsetViewportPrint();
auto hotkeypos = finalcut::getHotkeyPos(txt, label_text); const auto hotkeypos = finalcut::getHotkeyPos(txt, label_text);
if ( hasBorder() ) if ( hasBorder() )
FWidget::setPrintPos (FPoint(2, 1)); FWidget::setPrintPos (FPoint(2, 1));
@ -438,14 +438,14 @@ void FButtonGroup::drawText ( const FString& label_text
, std::size_t hotkeypos ) , std::size_t hotkeypos )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
std::size_t column_width = getColumnWidth(label_text); const std::size_t column_width = getColumnWidth(label_text);
std::size_t length = label_text.getLength(); std::size_t length = label_text.getLength();
bool ellipsis{false}; bool ellipsis{false};
if ( column_width > getClientWidth() ) if ( column_width > getClientWidth() )
{ {
std::size_t len = getClientWidth() - 3; const std::size_t len = getClientWidth() - 3;
FString s = finalcut::getColumnSubString (label_text, 1, len); const FString s = finalcut::getColumnSubString (label_text, 1, len);
length = s.getLength(); length = s.getLength();
ellipsis = true; ellipsis = true;
} }
@ -546,7 +546,7 @@ void FButtonGroup::directFocus()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::cb_buttonToggled (FWidget* widget, FDataPtr) void FButtonGroup::cb_buttonToggled (FWidget* widget, FDataPtr)
{ {
auto button = static_cast<FToggleButton*>(widget); const auto& button = static_cast<FToggleButton*>(widget);
if ( ! button->isChecked() ) if ( ! button->isChecked() )
return; return;

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 2019 Markus Gans * * Copyright 2019-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -51,14 +51,14 @@ FDropDownListBox::FDropDownListBox (FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDropDownListBox::~FDropDownListBox() // destructor FDropDownListBox::~FDropDownListBox() // destructor
{ {
auto fapp = FApplication::getApplicationObject(); const auto& fapp = FApplication::getApplicationObject();
if ( fapp->isQuit() ) if ( fapp->isQuit() )
return; return;
FWindow* parent_win{nullptr}; FWindow* parent_win{nullptr};
if ( auto parent = getParentWidget() ) if ( const auto& parent = getParentWidget() )
parent_win = getWindowWidget(parent); parent_win = getWindowWidget(parent);
if ( parent_win ) if ( parent_win )
@ -294,7 +294,7 @@ void FComboBox::remove (std::size_t item)
if ( ! list_window.isEmpty() ) if ( ! list_window.isEmpty() )
{ {
std::size_t index = list_window.list.currentItem(); const std::size_t index = list_window.list.currentItem();
input_field = list_window.list.getItem(index).getText(); input_field = list_window.list.getItem(index).getText();
input_field.redraw(); input_field.redraw();
} }
@ -329,12 +329,8 @@ void FComboBox::showDropDown()
FPoint p(getTermPos()); FPoint p(getTermPos());
p.move(0 - int(nf), 1); p.move(0 - int(nf), 1);
setClickedWidget(&list_window.list); setClickedWidget(&list_window.list);
std::size_t w = getWidth(); const std::size_t w = getWidth();
std::size_t h = getCount(); const std::size_t h = ( getCount() <= max_items ) ? getCount() : max_items;
if ( h > max_items)
h = max_items;
list_window.setGeometry(p, FSize(w + std::size_t(nf), h + border)); list_window.setGeometry(p, FSize(w + std::size_t(nf), h + border));
list_window.show(); list_window.show();
list_window.list.setFocus(); list_window.list.setFocus();
@ -418,8 +414,8 @@ void FComboBox::onMouseDown (FMouseEvent* ev)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
} }
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x >= int(getWidth()) - nf if ( mouse_x >= int(getWidth()) - nf
&& mouse_x <= int(getWidth()) && mouse_y == 1 ) && mouse_x <= int(getWidth()) && mouse_y == 1 )
@ -481,7 +477,7 @@ bool FComboBox::isMouseOverListWindow (const FPoint& termpos)
{ {
if ( list_window.isShown() ) if ( list_window.isShown() )
{ {
const auto& list_geometry = list_window.getTermGeometry(); auto list_geometry = list_window.getTermGeometry();
if ( list_geometry.contains(termpos) ) if ( list_geometry.contains(termpos) )
return true; return true;
@ -494,7 +490,7 @@ bool FComboBox::isMouseOverListWindow (const FPoint& termpos)
void FComboBox::init() void FComboBox::init()
{ {
setShadow(); setShadow();
auto parent_widget = getParentWidget(); const auto& parent_widget = getParentWidget();
FLabel* label = input_field.getLabelObject(); FLabel* label = input_field.getLabelObject();
label->setParent(getParent()); label->setParent(getParent());
label->setForegroundColor (parent_widget->getForegroundColor()); label->setForegroundColor (parent_widget->getForegroundColor());
@ -544,7 +540,7 @@ void FComboBox::draw()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
FColorPair button_color = [&] () -> FColorPair const FColorPair button_color = [&] () -> FColorPair
{ {
if ( list_window.isEmpty() ) if ( list_window.isEmpty() )
return FColorPair ( wc.scrollbar_button_inactive_fg return FColorPair ( wc.scrollbar_button_inactive_fg
@ -605,7 +601,7 @@ void FComboBox::passEventToListWindow (FMouseEvent*& ev)
const auto& t = ev->getTermPos(); const auto& t = ev->getTermPos();
const auto& p = list_window.list.termToWidgetPos(t); const auto& p = list_window.list.termToWidgetPos(t);
int b = ev->getButton(); const int b = ev->getButton();
try try
{ {
@ -637,7 +633,7 @@ void FComboBox::processChanged()
void FComboBox::cb_setInputField (FWidget*, FDataPtr) void FComboBox::cb_setInputField (FWidget*, FDataPtr)
{ {
auto& list = list_window.list; auto& list = list_window.list;
std::size_t index = list.currentItem(); const std::size_t index = list.currentItem();
input_field = list.getItem(index).getText(); input_field = list.getItem(index).getText();
input_field.redraw(); input_field.redraw();
processChanged(); processChanged();
@ -653,7 +649,7 @@ void FComboBox::cb_closeComboBox (FWidget*, FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FComboBox::cb_inputFieldSwitch (FWidget*, FDataPtr) void FComboBox::cb_inputFieldSwitch (FWidget*, FDataPtr)
{ {
auto mouse = getFMouseControl(); const auto& mouse = getFMouseControl();
if ( mouse && ! mouse->isLeftButtonPressed() ) if ( mouse && ! mouse->isLeftButtonPressed() )
return; return;
@ -685,14 +681,14 @@ void FComboBox::cb_inputFieldSwitch (FWidget*, FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FComboBox::cb_inputFieldHandOver (FWidget*, FDataPtr) void FComboBox::cb_inputFieldHandOver (FWidget*, FDataPtr)
{ {
auto mouse = getFMouseControl(); const auto& mouse = getFMouseControl();
if ( ! mouse || list_window.isHidden() ) if ( ! mouse || list_window.isHidden() )
return; return;
const auto& t = mouse->getPos(); const auto& t = mouse->getPos();
auto p = list_window.list.termToWidgetPos(t); const auto& p = list_window.list.termToWidgetPos(t);
int b = ( mouse->isLeftButtonPressed() ) ? fc::LeftButton : 0; const int b = ( mouse->isLeftButtonPressed() ) ? fc::LeftButton : 0;
try try
{ {

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 2012-2019 Markus Gans * * Copyright 2012-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -57,8 +57,8 @@ FDialog::FDialog (const FString& txt, FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDialog::~FDialog() // destructor FDialog::~FDialog() // destructor
{ {
auto fapp = FApplication::getApplicationObject(); const auto& fapp = FApplication::getApplicationObject();
bool is_quit = fapp->isQuit(); const bool is_quit = fapp->isQuit();
delete dialog_menu; delete dialog_menu;
dgl_menuitem = nullptr; dgl_menuitem = nullptr;
@ -176,14 +176,14 @@ void FDialog::setPos (const FPoint& pos, bool)
return; return;
} }
int dx = getX() - pos.getX(); const int dx = getX() - pos.getX();
int dy = getY() - pos.getY(); const int dy = getY() - pos.getY();
int old_x = getTermX(); const int old_x = getTermX();
int old_y = getTermY(); const int old_y = getTermY();
const auto& shadow = getShadow(); const auto& shadow = getShadow();
std::size_t width = getWidth() + shadow.getWidth(); // width + right shadow const std::size_t width = getWidth() + shadow.getWidth(); // width + right shadow
std::size_t height = getHeight() + shadow.getHeight(); // height + bottom shadow const std::size_t height = getHeight() + shadow.getHeight(); // height + bottom shadow
FRect old_geometry (getTermGeometryWithShadow()); const FRect old_geometry (getTermGeometryWithShadow());
// move to the new position // move to the new position
FWindow::setPos(pos, false); FWindow::setPos(pos, false);
@ -193,8 +193,8 @@ void FDialog::setPos (const FPoint& pos, bool)
if ( getTermGeometry().overlap(old_geometry) ) if ( getTermGeometry().overlap(old_geometry) )
{ {
FRect restore{}; FRect restore{};
std::size_t d_width = std::size_t(std::abs(dx)); const std::size_t d_width = std::size_t(std::abs(dx));
std::size_t d_height = std::size_t(std::abs(dy)); const std::size_t d_height = std::size_t(std::abs(dy));
// dx > 0 : move left // dx > 0 : move left
// dx = 0 : move vertical // dx = 0 : move vertical
@ -285,16 +285,16 @@ void FDialog::setSize (const FSize& size, bool adjust)
return; return;
} }
int x = getTermX(); const int x = getTermX();
int y = getTermY(); const int y = getTermY();
int dw = int(getWidth()) - int(size.getWidth()); const int dw = int(getWidth()) - int(size.getWidth());
int dh = int(getHeight()) - int(size.getHeight()); const int dh = int(getHeight()) - int(size.getHeight());
const auto& shadow = getShadow(); const auto& shadow = getShadow();
FWindow::setSize (size, adjust); FWindow::setSize (size, adjust);
// get adjust width and height // get adjust width and height
std::size_t w = getWidth() + shadow.getWidth(); const std::size_t w = getWidth() + shadow.getWidth();
std::size_t h = getHeight() + shadow.getHeight(); const std::size_t h = getHeight() + shadow.getHeight();
// dw > 0 : scale down width // dw > 0 : scale down width
// dw = 0 : scale only height // dw = 0 : scale only height
@ -303,8 +303,8 @@ void FDialog::setSize (const FSize& size, bool adjust)
// dh = 0 : scale only width // dh = 0 : scale only width
// dh < 0 : scale up height // dh < 0 : scale up height
std::size_t d_width = std::size_t(dw); const std::size_t d_width = std::size_t(dw);
std::size_t d_height = std::size_t(dh); const std::size_t d_height = std::size_t(dh);
// restoring the non-covered terminal areas // restoring the non-covered terminal areas
if ( dw > 0 ) if ( dw > 0 )
@ -437,9 +437,9 @@ void FDialog::onKeyPress (FKeyEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseDown (FMouseEvent* ev) void FDialog::onMouseDown (FMouseEvent* ev)
{ {
int width = int(getWidth()); const int width = int(getWidth());
mouseStates ms = const mouseStates ms =
{ {
ev->getX(), ev->getX(),
ev->getY(), ev->getY(),
@ -498,7 +498,7 @@ void FDialog::onMouseDown (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseUp (FMouseEvent* ev) void FDialog::onMouseUp (FMouseEvent* ev)
{ {
mouseStates ms = const mouseStates ms =
{ {
ev->getX(), ev->getX(),
ev->getY(), ev->getY(),
@ -509,15 +509,15 @@ void FDialog::onMouseUp (FMouseEvent* ev)
if ( ev->getButton() == fc::LeftButton ) if ( ev->getButton() == fc::LeftButton )
{ {
int titlebar_x = titlebar_click_pos.getX() const int titlebar_x = titlebar_click_pos.getX();
, titlebar_y = titlebar_click_pos.getY(); const int titlebar_y = titlebar_click_pos.getY();
if ( ! titlebar_click_pos.isOrigin() if ( ! titlebar_click_pos.isOrigin()
&& titlebar_x > int(getTermX()) + 3 && titlebar_x > int(getTermX()) + 3
&& titlebar_x < getTermX() + int(getWidth()) && titlebar_x < getTermX() + int(getWidth())
&& titlebar_y == int(getTermY()) ) && titlebar_y == int(getTermY()) )
{ {
FPoint deltaPos(ms.termPos - titlebar_click_pos); const FPoint deltaPos(ms.termPos - titlebar_click_pos);
move (deltaPos); move (deltaPos);
titlebar_click_pos = ms.termPos; titlebar_click_pos = ms.termPos;
} }
@ -547,7 +547,7 @@ void FDialog::onMouseUp (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseMove (FMouseEvent* ev) void FDialog::onMouseMove (FMouseEvent* ev)
{ {
mouseStates ms = const mouseStates ms =
{ {
ev->getX(), ev->getX(),
ev->getY(), ev->getY(),
@ -561,7 +561,7 @@ void FDialog::onMouseMove (FMouseEvent* ev)
if ( ! titlebar_click_pos.isOrigin() ) if ( ! titlebar_click_pos.isOrigin() )
{ {
FPoint deltaPos(ms.termPos - titlebar_click_pos); const FPoint deltaPos(ms.termPos - titlebar_click_pos);
move (deltaPos); move (deltaPos);
titlebar_click_pos = ms.termPos; titlebar_click_pos = ms.termPos;
} }
@ -577,7 +577,7 @@ void FDialog::onMouseMove (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseDoubleClick (FMouseEvent* ev) void FDialog::onMouseDoubleClick (FMouseEvent* ev)
{ {
mouseStates ms = const mouseStates ms =
{ {
ev->getX(), ev->getX(),
ev->getY(), ev->getY(),
@ -589,10 +589,10 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
int x = getTermX(); const int x = getTermX();
int y = getTermY(); const int y = getTermY();
FRect title_button(x, y, 3, 1); const FRect title_button(x, y, 3, 1);
FPoint tPos(ms.termPos); const FPoint tPos(ms.termPos);
if ( title_button.contains(tPos) ) if ( title_button.contains(tPos) )
{ {
@ -629,7 +629,7 @@ void FDialog::onAccel (FAccelEvent*)
{ {
if ( ! (isWindowHidden() || isWindowActive()) ) if ( ! (isWindowHidden() || isWindowActive()) )
{ {
bool has_raised = raiseWindow(); const bool has_raised = raiseWindow();
activateDialog(); activateDialog();
if ( has_raised ) if ( has_raised )
@ -913,7 +913,7 @@ void FDialog::drawBorder()
if ( isNewFont() ) // Draw a newfont U-shaped frame if ( isNewFont() ) // Draw a newfont U-shaped frame
{ {
FRect r(FPoint(1, 1), getSize()); const FRect r(FPoint(1, 1), getSize());
for (int y = r.getY1() + 1; y < r.getY2(); y++) for (int y = r.getY1() + 1; y < r.getY2(); y++)
{ {
@ -1092,9 +1092,9 @@ void FDialog::drawTextBar()
else else
setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg); setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg);
auto width = getWidth(); const auto width = getWidth();
auto zoom_btn = getZoomButtonWidth(); const auto zoom_btn = getZoomButtonWidth();
auto length = getColumnWidth(tb_text); const auto length = getColumnWidth(tb_text);
if ( width > length + MENU_BTN + zoom_btn ) if ( width > length + MENU_BTN + zoom_btn )
center_offset = (width - length - MENU_BTN - zoom_btn) / 2; center_offset = (width - length - MENU_BTN - zoom_btn) / 2;
@ -1154,7 +1154,7 @@ void FDialog::setCursorToFocusWidget()
&& focus->isShown() && focus->isShown()
&& focus->hasVisibleCursor() ) && focus->hasVisibleCursor() )
{ {
FPoint cursor_pos(focus->getCursorPos()); const FPoint cursor_pos(focus->getCursorPos());
focus->setCursorPos(cursor_pos); focus->setCursorPos(cursor_pos);
updateVTermCursor(getVWin()); updateVTermCursor(getVWin());
} }
@ -1310,7 +1310,7 @@ void FDialog::pressZoomButton (const mouseStates& ms)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FDialog::isMouseOverMenu (const FPoint& termpos) inline bool FDialog::isMouseOverMenu (const FPoint& termpos)
{ {
const auto& menu_geometry = dialog_menu->getTermGeometry(); auto menu_geometry = dialog_menu->getTermGeometry();
if ( dialog_menu->getCount() > 0 && menu_geometry.contains(termpos) ) if ( dialog_menu->getCount() > 0 && menu_geometry.contains(termpos) )
return true; return true;
@ -1329,7 +1329,7 @@ inline void FDialog::passEventToSubMenu ( const mouseStates& ms
const auto& g = ms.termPos; const auto& g = ms.termPos;
const auto& p = dialog_menu->termToWidgetPos(g); const auto& p = dialog_menu->termToWidgetPos(g);
int b = ev->getButton(); const int b = ev->getButton();
try try
{ {
@ -1415,7 +1415,7 @@ inline void FDialog::moveSizeKey (FKeyEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FDialog::raiseActivateDialog() inline void FDialog::raiseActivateDialog()
{ {
bool has_raised = raiseWindow(); const bool has_raised = raiseWindow();
activateDialog(); activateDialog();
if ( has_raised ) if ( has_raised )
@ -1425,7 +1425,7 @@ inline void FDialog::raiseActivateDialog()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FDialog::lowerActivateDialog() inline void FDialog::lowerActivateDialog()
{ {
bool has_lowered = lowerWindow(); const bool has_lowered = lowerWindow();
if ( ! isWindowActive() ) if ( ! isWindowActive() )
activateDialog(); activateDialog();
@ -1472,13 +1472,13 @@ void FDialog::resizeMouseDown (const mouseStates& ms)
if ( isResizeable() && isLowerRightResizeCorner(ms) ) if ( isResizeable() && isLowerRightResizeCorner(ms) )
{ {
resize_click_pos = ms.termPos; resize_click_pos = ms.termPos;
FPoint lower_right_pos(getTermGeometry().getLowerRightPos()); const FPoint lower_right_pos(getTermGeometry().getLowerRightPos());
if ( ms.termPos != lower_right_pos ) if ( ms.termPos != lower_right_pos )
{ {
FPoint deltaPos(ms.termPos - lower_right_pos); const FPoint deltaPos(ms.termPos - lower_right_pos);
int w = lower_right_pos.getX() + deltaPos.getX() - getTermX() + 1; const int w = lower_right_pos.getX() + deltaPos.getX() - getTermX() + 1;
int h = lower_right_pos.getY() + deltaPos.getY() - getTermY() + 1; const int h = lower_right_pos.getY() + deltaPos.getY() - getTermY() + 1;
const FSize& size = FSize(std::size_t(w), std::size_t(h)); const FSize& size = FSize(std::size_t(w), std::size_t(h));
setSize (size, true); setSize (size, true);
} }
@ -1495,12 +1495,12 @@ void FDialog::resizeMouseUpMove (const mouseStates& ms, bool mouse_up)
// Resize the dialog // Resize the dialog
if ( isResizeable() && ! resize_click_pos.isOrigin() ) if ( isResizeable() && ! resize_click_pos.isOrigin() )
{ {
auto r = getRootWidget(); const auto& r = getRootWidget();
resize_click_pos = ms.termPos; resize_click_pos = ms.termPos;
int x2 = resize_click_pos.getX() const int x2 = resize_click_pos.getX();
, y2 = resize_click_pos.getY() const int y2 = resize_click_pos.getY();
, x2_offset{0} int x2_offset{0};
, y2_offset{0}; int y2_offset{0};
if ( r ) if ( r )
{ {
@ -1511,7 +1511,7 @@ void FDialog::resizeMouseUpMove (const mouseStates& ms, bool mouse_up)
if ( ms.termPos != getTermGeometry().getLowerRightPos() ) if ( ms.termPos != getTermGeometry().getLowerRightPos() )
{ {
int w{}, h{}; int w{}, h{};
FPoint deltaPos(ms.termPos - resize_click_pos); const FPoint deltaPos(ms.termPos - resize_click_pos);
if ( x2 - x2_offset <= int(getMaxWidth()) ) if ( x2 - x2_offset <= int(getMaxWidth()) )
w = resize_click_pos.getX() + deltaPos.getX() - getTermX() + 1; w = resize_click_pos.getX() + deltaPos.getX() - getTermX() + 1;

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -47,7 +47,7 @@ FDialogListMenu::FDialogListMenu (const FString& txt, FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDialogListMenu::~FDialogListMenu() FDialogListMenu::~FDialogListMenu()
{ } { }
// private methods of FMenu // private methods of FMenu

View File

@ -167,7 +167,7 @@ FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString FFileDialog::getSelectedFile() const const FString FFileDialog::getSelectedFile() const
{ {
uLong n = uLong(filebrowser.currentItem() - 1); const uLong n = uLong(filebrowser.currentItem() - 1);
if ( dir_entries[n].directory ) if ( dir_entries[n].directory )
return FString(""); return FString("");
@ -244,7 +244,7 @@ void FFileDialog::onKeyPress (FKeyEvent* ev)
if ( ! filebrowser.hasFocus() ) if ( ! filebrowser.hasFocus() )
return; return;
FKey key = ev->key(); const FKey key = ev->key();
switch ( key ) switch ( key )
{ {
@ -281,7 +281,7 @@ const FString FFileDialog::fileSaveChooser ( FWidget* parent
void FFileDialog::adjustSize() void FFileDialog::adjustSize()
{ {
std::size_t max_width{}, max_height{}; std::size_t max_width{}, max_height{};
auto root_widget = getRootWidget(); const auto& root_widget = getRootWidget();
if ( root_widget ) if ( root_widget )
{ {
@ -304,8 +304,8 @@ void FFileDialog::adjustSize()
h = 30; h = 30;
setHeight (h, false); setHeight (h, false);
int X = 1 + int((max_width - getWidth()) / 2); const int X = 1 + int((max_width - getWidth()) / 2);
int Y = 1 + int((max_height - getHeight()) / 3); const int Y = 1 + int((max_height - getHeight()) / 3);
setPos(FPoint(X, Y), false); setPos(FPoint(X, Y), false);
filebrowser.setHeight (h - 8, false); filebrowser.setHeight (h - 8, false);
hidden_check.setY (int(h) - 4, false); hidden_check.setY (int(h) - 4, false);
@ -328,7 +328,7 @@ void FFileDialog::init()
fsystem = FTerm::getFSystem(); fsystem = FTerm::getFSystem();
setGeometry(FPoint(1, 1), FSize(w, h), false); setGeometry(FPoint(1, 1), FSize(w, h), false);
auto parent_widget = getParentWidget(); const auto& parent_widget = getParentWidget();
if ( parent_widget ) if ( parent_widget )
{ {
@ -458,14 +458,14 @@ sInt64 FFileDialog::numOfDirs()
if ( dir_entries.empty() ) if ( dir_entries.empty() )
return 0; return 0;
sInt64 n = std::count_if ( std::begin(dir_entries) const sInt64 n = std::count_if ( std::begin(dir_entries)
, std::end(dir_entries) , std::end(dir_entries)
, [] (dir_entry& entry) , [] (dir_entry& entry)
{ {
return entry.directory return entry.directory
&& std::strcmp(entry.name, ".") != 0; && std::strcmp(entry.name, ".") != 0;
} }
); );
return n; return n;
} }
@ -477,7 +477,7 @@ void FFileDialog::sortDir()
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 ) if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
start = 1; start = 1;
sInt64 dir_num = numOfDirs(); const sInt64 dir_num = numOfDirs();
// directories first // directories first
std::sort ( dir_entries.begin() + start std::sort ( dir_entries.begin() + start
, dir_entries.end() , dir_entries.end()
@ -727,13 +727,13 @@ void FFileDialog::printPath (const FString& txt)
{ {
const auto& path = txt; const auto& path = txt;
const std::size_t max_width = filebrowser.getWidth() - 4; const std::size_t max_width = filebrowser.getWidth() - 4;
std::size_t column_width = getColumnWidth(path); const std::size_t column_width = getColumnWidth(path);
if ( column_width > max_width ) if ( column_width > max_width )
{ {
const std::size_t width = max_width - 2; const std::size_t width = max_width - 2;
std::size_t first = column_width + 1 - width; const std::size_t first = column_width + 1 - width;
FString sub_str(getColumnSubString (path, first, width)); const FString sub_str(getColumnSubString (path, first, width));
filebrowser.setText(".." + sub_str); filebrowser.setText(".." + sub_str);
} }
else else
@ -750,7 +750,7 @@ const FString FFileDialog::getHomeDir()
if ( ! fsystem ) if ( ! fsystem )
fsystem = FTerm::getFSystem(); fsystem = FTerm::getFSystem();
uid_t euid = fsystem->geteuid(); const uid_t euid = fsystem->geteuid();
if ( fsystem->getpwuid_r(euid, &pwd, buf, sizeof(buf), &pwd_ptr) ) if ( fsystem->getpwuid_r(euid, &pwd, buf, sizeof(buf), &pwd_ptr) )
return FString(""); return FString("");

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 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -81,7 +81,7 @@ void FKeyboard::fetchKeyCode()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString FKeyboard::getKeyName (FKey keynum) const FString FKeyboard::getKeyName (const FKey keynum)
{ {
for (std::size_t i{0}; fc::fkeyname[i].string[0] != 0; i++) for (std::size_t i{0}; fc::fkeyname[i].string[0] != 0; i++)
if ( fc::fkeyname[i].num && fc::fkeyname[i].num == keynum ) if ( fc::fkeyname[i].num && fc::fkeyname[i].num == keynum )
@ -118,13 +118,13 @@ bool FKeyboard::isKeyPressed()
{ {
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
int stdin_no = FTermios::getStdIn(); const int stdin_no = FTermios::getStdIn();
FD_ZERO(&ifds); FD_ZERO(&ifds);
FD_SET(stdin_no, &ifds); FD_SET(stdin_no, &ifds);
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 100000; // 100 ms tv.tv_usec = 100000; // 100 ms
int result = select (stdin_no + 1, &ifds, 0, 0, &tv); const int result = select (stdin_no + 1, &ifds, 0, 0, &tv);
if ( result > 0 && FD_ISSET(stdin_no, &ifds) ) if ( result > 0 && FD_ISSET(stdin_no, &ifds) )
FD_CLR (stdin_no, &ifds); FD_CLR (stdin_no, &ifds);
@ -185,7 +185,7 @@ inline FKey FKeyboard::getMouseProtocolKey()
if ( ! mouse_support ) if ( ! mouse_support )
return NOT_SET; return NOT_SET;
std::size_t buf_len = std::strlen(fifo_buf); const std::size_t buf_len = std::strlen(fifo_buf);
// x11 mouse tracking // x11 mouse tracking
if ( buf_len >= 6 && fifo_buf[1] == '[' && fifo_buf[2] == 'M' ) if ( buf_len >= 6 && fifo_buf[1] == '[' && fifo_buf[2] == 'M' )
@ -217,8 +217,8 @@ inline FKey FKeyboard::getTermcapKey()
for (std::size_t i{0}; key_map[i].tname[0] != 0; i++) for (std::size_t i{0}; key_map[i].tname[0] != 0; i++)
{ {
char* k = key_map[i].string; const char* k = key_map[i].string;
std::size_t len = ( k ) ? std::strlen(k) : 0; const std::size_t len = ( k ) ? std::strlen(k) : 0;
if ( k && std::strncmp(k, fifo_buf, len) == 0 ) // found if ( k && std::strncmp(k, fifo_buf, len) == 0 ) // found
{ {
@ -247,8 +247,8 @@ inline FKey FKeyboard::getMetaKey()
for (std::size_t i{0}; fc::fmetakey[i].string[0] != 0; i++) for (std::size_t i{0}; fc::fmetakey[i].string[0] != 0; i++)
{ {
char* kmeta = fc::fmetakey[i].string; // The string is never null const char* kmeta = fc::fmetakey[i].string; // The string is never null
std::size_t len = std::strlen(kmeta); const std::size_t len = std::strlen(kmeta);
if ( std::strncmp(kmeta, fifo_buf, len) == 0 ) // found if ( std::strncmp(kmeta, fifo_buf, len) == 0 ) // found
{ {
@ -283,7 +283,7 @@ inline FKey FKeyboard::getSingleKey()
std::size_t n{}; std::size_t n{};
std::size_t len{1}; std::size_t len{1};
uChar firstchar = uChar(fifo_buf[0]); const uChar firstchar = uChar(fifo_buf[0]);
FKey keycode{}; FKey keycode{};
// Look for a utf-8 character // Look for a utf-8 character
@ -362,7 +362,7 @@ FKey FKeyboard::UTF8decode (const char utf8[])
for (std::size_t i{0}; i < len; ++i) for (std::size_t i{0}; i < len; ++i)
{ {
uChar ch = uChar(utf8[i]); const uChar ch = uChar(utf8[i]);
if ( (ch & 0xc0) == 0x80 ) if ( (ch & 0xc0) == 0x80 )
{ {
@ -403,7 +403,7 @@ FKey FKeyboard::UTF8decode (const char utf8[])
inline ssize_t FKeyboard::readKey() inline ssize_t FKeyboard::readKey()
{ {
setNonBlockingInput(); setNonBlockingInput();
ssize_t bytes = read(FTermios::getStdIn(), &read_buf, READ_BUF_SIZE - 1); const ssize_t bytes = read(FTermios::getStdIn(), &read_buf, READ_BUF_SIZE - 1);
unsetNonBlockingInput(); unsetNonBlockingInput();
return bytes; return bytes;
} }
@ -459,7 +459,7 @@ void FKeyboard::parseKeyBuffer()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FKey FKeyboard::parseKeyString() FKey FKeyboard::parseKeyString()
{ {
uChar firstchar = uChar(fifo_buf[0]); const uChar firstchar = uChar(fifo_buf[0]);
if ( firstchar == ESC[0] ) if ( firstchar == ESC[0] )
{ {

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -163,7 +163,7 @@ void FLabel::onMouseDown (FMouseEvent* ev)
// send click to the parent widget // send click to the parent widget
if ( auto parent = getParentWidget() ) if ( auto parent = getParentWidget() )
{ {
int b = ev->getButton(); const int b = ev->getButton();
const auto& tp = ev->getTermPos(); const auto& tp = ev->getTermPos();
const auto& p = parent->termToWidgetPos(tp); const auto& p = parent->termToWidgetPos(tp);
@ -245,7 +245,7 @@ void FLabel::cb_accel_widget_destroyed (FWidget*, FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLabel::init() void FLabel::init()
{ {
auto parent_widget = getParentWidget(); const auto& parent_widget = getParentWidget();
unsetFocusable(); unsetFocusable();
if ( parent_widget ) if ( parent_widget )
@ -268,9 +268,9 @@ void FLabel::setHotkeyAccelerator()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::size_t FLabel::getAlignOffset (std::size_t length) std::size_t FLabel::getAlignOffset (const std::size_t length)
{ {
std::size_t width(getWidth()); const std::size_t width(getWidth());
switch ( alignment ) switch ( alignment )
{ {
@ -331,14 +331,14 @@ void FLabel::draw()
void FLabel::drawMultiLine() void FLabel::drawMultiLine()
{ {
std::size_t y{0}; std::size_t y{0};
std::size_t text_lines = multiline_text.size(); const std::size_t text_lines = multiline_text.size();
bool hotkey_printed{false}; bool hotkey_printed{false};
while ( y < text_lines && y < std::size_t(getHeight()) ) while ( y < text_lines && y < std::size_t(getHeight()) )
{ {
FString label_text{}; FString label_text{};
hotkeypos = NOT_SET; hotkeypos = NOT_SET;
auto length = multiline_text[y].getLength(); const auto length = multiline_text[y].getLength();
column_width = getColumnWidth(multiline_text[y]); column_width = getColumnWidth(multiline_text[y]);
if ( ! hotkey_printed ) if ( ! hotkey_printed )
@ -381,7 +381,7 @@ void FLabel::printLine (FString&& line)
{ {
std::size_t to_char{}; std::size_t to_char{};
std::size_t to_column{}; std::size_t to_column{};
std::size_t width(getWidth()); const std::size_t width(getWidth());
if ( align_offset > 0 ) if ( align_offset > 0 )
print (FString(align_offset, ' ')); // leading spaces print (FString(align_offset, ' ')); // leading spaces
@ -443,7 +443,7 @@ void FLabel::printLine (FString&& line)
else if ( align_offset + to_column < width ) else if ( align_offset + to_column < width )
{ {
// Print trailing spaces // Print trailing spaces
std::size_t len = width - align_offset - to_column; const std::size_t len = width - align_offset - to_column;
print (FString(len, ' ')); print (FString(len, ' '));
} }

View File

@ -280,7 +280,7 @@ void FLineEdit::hide()
label->hide(); label->hide();
FWidget::hide(); FWidget::hide();
FSize shadow = hasShadow() ? FSize(1, 1) : FSize(0, 0); const FSize shadow = hasShadow() ? FSize(1, 1) : FSize(0, 0);
hideArea (getSize() + shadow); hideArea (getSize() + shadow);
} }
@ -302,7 +302,7 @@ void FLineEdit::onKeyPress (FKeyEvent* ev)
if ( isReadOnly() ) if ( isReadOnly() )
return; return;
FKey key = ev->key(); const FKey key = ev->key();
switch ( key ) switch ( key )
{ {
@ -387,13 +387,13 @@ void FLineEdit::onMouseDown (FMouseEvent* ev)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
} }
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
int xmin = 2 + int(char_width_offset); const int xmin = 2 + int(char_width_offset);
if ( mouse_x >= xmin && mouse_x <= int(getWidth()) && mouse_y == 1 ) if ( mouse_x >= xmin && mouse_x <= int(getWidth()) && mouse_y == 1 )
{ {
std::size_t len = print_text.getLength(); const std::size_t len = print_text.getLength();
cursor_pos = clickPosToCursorPos (std::size_t(mouse_x) - 2); cursor_pos = clickPosToCursorPos (std::size_t(mouse_x) - 2);
if ( cursor_pos >= len ) if ( cursor_pos >= len )
@ -424,9 +424,9 @@ void FLineEdit::onMouseMove (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton || isReadOnly() ) if ( ev->getButton() != fc::LeftButton || isReadOnly() )
return; return;
std::size_t len = print_text.getLength(); const std::size_t len = print_text.getLength();
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 ) if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 )
{ {
@ -498,7 +498,7 @@ void FLineEdit::onWheel (FWheelEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::onTimer (FTimerEvent*) void FLineEdit::onTimer (FTimerEvent*)
{ {
auto len = print_text.getLength(); const auto len = print_text.getLength();
switch ( int(drag_scroll) ) switch ( int(drag_scroll) )
{ {
@ -616,7 +616,7 @@ void FLineEdit::onFocusOut (FFocusEvent*)
void FLineEdit::adjustLabel() void FLineEdit::adjustLabel()
{ {
auto label_width = getColumnWidth(label_text); auto label_width = getColumnWidth(label_text);
auto w = label_associated_widget; const auto& w = label_associated_widget;
if ( ! w ) if ( ! w )
return; return;
@ -722,7 +722,7 @@ void FLineEdit::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::drawInputField() void FLineEdit::drawInputField()
{ {
bool isActiveFocus = getFlags().active && getFlags().focus; const bool isActiveFocus = getFlags().active && getFlags().focus;
print() << FPoint(1, 1); print() << FPoint(1, 1);
if ( isMonochron() ) if ( isMonochron() )
@ -744,7 +744,7 @@ void FLineEdit::drawInputField()
if ( isActiveFocus && getMaxColor() < 16 ) if ( isActiveFocus && getMaxColor() < 16 )
setBold(); setBold();
std::size_t text_offset_column = [&] () -> std::size_t const std::size_t text_offset_column = [&] () -> std::size_t
{ {
switch ( input_type ) switch ( input_type )
{ {
@ -777,18 +777,18 @@ void FLineEdit::drawInputField()
drawShadow(this); drawShadow(this);
// set the cursor to the insert pos. // set the cursor to the insert pos.
auto cursor_pos_column = getCursorColumnPos(); const auto cursor_pos_column = getCursorColumnPos();
int xpos = int(2 + cursor_pos_column const int xpos = int(2 + cursor_pos_column
- text_offset_column - text_offset_column
+ char_width_offset); + char_width_offset);
setCursorPos (FPoint(xpos, 1)); setCursorPos (FPoint(xpos, 1));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline std::size_t FLineEdit::printTextField() inline std::size_t FLineEdit::printTextField()
{ {
std::size_t text_offset_column = getColumnWidth (print_text, text_offset); const std::size_t text_offset_column = getColumnWidth (print_text, text_offset);
std::size_t start_column = text_offset_column - char_width_offset + 1; const std::size_t start_column = text_offset_column - char_width_offset + 1;
const FString& show_text = \ const FString& show_text = \
getColumnSubString(print_text, start_column, getWidth() - 2); getColumnSubString(print_text, start_column, getWidth() - 2);
@ -802,8 +802,8 @@ inline std::size_t FLineEdit::printTextField()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline std::size_t FLineEdit::printPassword() inline std::size_t FLineEdit::printPassword()
{ {
std::size_t text_offset_column = text_offset; const std::size_t text_offset_column = text_offset;
FString show_text(print_text.mid(1 + text_offset, getWidth() - 2)); const FString show_text(print_text.mid(1 + text_offset, getWidth() - 2));
if ( ! show_text.isEmpty() ) if ( ! show_text.isEmpty() )
print() << FString(show_text.getLength(), fc::Bullet); // • print() << FString(show_text.getLength(), fc::Bullet); // •
@ -844,14 +844,23 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
{ {
std::size_t input_width = getWidth() - 2; std::size_t input_width = getWidth() - 2;
std::size_t fullwidth_char_offset{0}; std::size_t fullwidth_char_offset{0};
std::size_t len = print_text.getLength(); const std::size_t len = print_text.getLength();
if ( pos >= len ) if ( pos >= len )
pos = len - 1; pos = len - 1;
while ( pos > 0 && input_width > 0 ) while ( pos > 0 && input_width > 0 )
{ {
std::size_t char_width = getColumnWidth(print_text[pos]); std::size_t char_width{};
try
{
char_width = getColumnWidth(print_text[pos]);
}
catch (const std::out_of_range& ex)
{
std::cerr << "Out of Range error: " << ex.what() << std::endl;
}
if ( input_width >= char_width ) if ( input_width >= char_width )
input_width -= char_width; input_width -= char_width;
@ -863,10 +872,17 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
{ {
if ( char_width == 1 ) if ( char_width == 1 )
{ {
if ( getColumnWidth(print_text[pos - 1]) == 2 ) // pos is always > 0 try
{ {
fullwidth_char_offset = 1; if ( getColumnWidth(print_text[pos - 1]) == 2 ) // pos is always > 0
break; {
fullwidth_char_offset = 1;
break;
}
}
catch (const std::out_of_range& ex)
{
std::cerr << "Out of Range error: " << ex.what() << std::endl;
} }
} }
@ -888,12 +904,22 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos)
{ {
std::size_t click_width{0}; std::size_t click_width{0};
std::size_t idx = text_offset; std::size_t idx = text_offset;
std::size_t len = print_text.getLength(); const std::size_t len = print_text.getLength();
pos -= char_width_offset; pos -= char_width_offset;
while ( click_width < pos && idx < len ) while ( click_width < pos && idx < len )
{ {
std::size_t char_width = getColumnWidth(print_text[idx]); std::size_t char_width{};
try
{
char_width = getColumnWidth(print_text[idx]);
}
catch (const std::out_of_range& ex)
{
std::cerr << "Out of Range error: " << ex.what() << std::endl;
}
idx++; idx++;
click_width += char_width; click_width += char_width;
@ -907,11 +933,11 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::adjustTextOffset() void FLineEdit::adjustTextOffset()
{ {
std::size_t input_width = getWidth() - 2; const std::size_t input_width = getWidth() - 2;
std::size_t len = print_text.getLength(); const std::size_t len = print_text.getLength();
std::size_t len_column = getColumnWidth (print_text); const std::size_t len_column = getColumnWidth (print_text);
std::size_t text_offset_column = getColumnWidth (print_text, text_offset); std::size_t text_offset_column = getColumnWidth (print_text, text_offset);
std::size_t cursor_pos_column = getColumnWidth (print_text, cursor_pos); const std::size_t cursor_pos_column = getColumnWidth (print_text, cursor_pos);
std::size_t first_char_width{0}; std::size_t first_char_width{0};
std::size_t cursor_char_width{1}; std::size_t cursor_char_width{1};
char_width_offset = 0; char_width_offset = 0;
@ -929,7 +955,16 @@ void FLineEdit::adjustTextOffset()
} }
if ( len > 0 ) if ( len > 0 )
first_char_width = getColumnWidth(print_text[0]); {
try
{
first_char_width = getColumnWidth(print_text[0]);
}
catch (const std::out_of_range& ex)
{
std::cerr << "Out of Range error: " << ex.what() << std::endl;
}
}
// Text alignment right for long lines // Text alignment right for long lines
while ( text_offset > 0 && len_column - text_offset_column < input_width ) while ( text_offset > 0 && len_column - text_offset_column < input_width )
@ -941,7 +976,7 @@ void FLineEdit::adjustTextOffset()
// Right cursor overflow // Right cursor overflow
if ( cursor_pos_column + 1 > text_offset_column + input_width ) if ( cursor_pos_column + 1 > text_offset_column + input_width )
{ {
offsetPair offset_pair = endPosToOffset(cursor_pos); const offsetPair offset_pair = endPosToOffset(cursor_pos);
text_offset = offset_pair.first; text_offset = offset_pair.first;
char_width_offset = offset_pair.second; char_width_offset = offset_pair.second;
text_offset_column = getColumnWidth (print_text, text_offset); text_offset_column = getColumnWidth (print_text, text_offset);
@ -974,7 +1009,7 @@ inline void FLineEdit::cursorLeft()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FLineEdit::cursorRight() inline void FLineEdit::cursorRight()
{ {
auto len = text.getLength(); const auto& len = text.getLength();
if ( cursor_pos < len ) if ( cursor_pos < len )
cursor_pos++; cursor_pos++;
@ -993,7 +1028,7 @@ inline void FLineEdit::cursorHome()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FLineEdit::cursorEnd() inline void FLineEdit::cursorEnd()
{ {
auto len = text.getLength(); const auto& len = text.getLength();
if ( cursor_pos == len ) if ( cursor_pos == len )
return; return;
@ -1007,7 +1042,7 @@ inline void FLineEdit::deleteCurrentCharacter()
{ {
// Delete key functionality // Delete key functionality
auto len = text.getLength(); const auto& len = text.getLength();
if ( len > 0 && cursor_pos < len ) if ( len > 0 && cursor_pos < len )
{ {
@ -1063,7 +1098,7 @@ inline bool FLineEdit::keyInput (FKey key)
if ( key >= 0x20 && key <= 0x10fff ) if ( key >= 0x20 && key <= 0x10fff )
{ {
auto len = text.getLength(); auto len = text.getLength();
auto ch = characterFilter(wchar_t(key)); const auto ch = characterFilter(wchar_t(key));
if ( ch == L'\0' ) if ( ch == L'\0' )
return false; return false;
@ -1098,7 +1133,7 @@ inline wchar_t FLineEdit::characterFilter (const wchar_t c)
if ( input_filter.empty() ) if ( input_filter.empty() )
return c; return c;
wchar_t character[2]{c, L'\0'}; const wchar_t character[2]{c, L'\0'};
if ( regex_match(character, std::wregex(input_filter)) ) if ( regex_match(character, std::wregex(input_filter)) )
return c; return c;

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -106,7 +106,7 @@ void FListBox::setCurrentItem (std::size_t index)
if ( index == current ) if ( index == current )
return; return;
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
if ( index > element_count ) if ( index > element_count )
current = element_count; current = element_count;
@ -125,12 +125,12 @@ void FListBox::setCurrentItem (std::size_t index)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::setCurrentItem (listBoxItems::iterator iter) void FListBox::setCurrentItem (listBoxItems::iterator iter)
{ {
std::size_t index = std::size_t(std::distance(itemlist.begin(), iter)) + 1; const auto index = std::size_t(std::distance(itemlist.begin(), iter)) + 1;
setCurrentItem(index); setCurrentItem(index);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::showInsideBrackets ( std::size_t index void FListBox::showInsideBrackets ( const std::size_t index
, fc::brackets_type b ) , fc::brackets_type b )
{ {
auto iter = index2iterator(index - 1); auto iter = index2iterator(index - 1);
@ -139,7 +139,7 @@ void FListBox::showInsideBrackets ( std::size_t index
if ( b == fc::NoBrackets ) if ( b == fc::NoBrackets )
return; return;
std::size_t column_width = getColumnWidth(iter->getText()) + 2; const auto column_width = getColumnWidth(iter->getText()) + 2;
if ( column_width > max_line_width ) if ( column_width > max_line_width )
{ {
@ -147,9 +147,9 @@ void FListBox::showInsideBrackets ( std::size_t index
if ( column_width >= getWidth() - nf_offset - 3 ) if ( column_width >= getWidth() - nf_offset - 3 )
{ {
int hmax = ( max_line_width > getWidth() - nf_offset - 4 ) const int hmax = ( max_line_width > getWidth() - nf_offset - 4 )
? int(max_line_width - getWidth() + nf_offset + 4) ? int(max_line_width - getWidth() + nf_offset + 4)
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4)); hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4));
hbar->setValue (xoffset); hbar->setValue (xoffset);
@ -191,8 +191,8 @@ void FListBox::hide()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::insert (FListBoxItem listItem) void FListBox::insert (FListBoxItem listItem)
{ {
std::size_t column_width = getColumnWidth(listItem.text); const std::size_t column_width = getColumnWidth(listItem.text);
bool has_brackets(listItem.brackets); const bool has_brackets(listItem.brackets);
recalculateHorizontalBar (column_width, has_brackets); recalculateHorizontalBar (column_width, has_brackets);
itemlist.push_back (listItem); itemlist.push_back (listItem);
@ -211,29 +211,29 @@ void FListBox::remove (std::size_t item)
return; return;
itemlist.erase (itemlist.begin() + int(item) - 1); itemlist.erase (itemlist.begin() + int(item) - 1);
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
max_line_width = 0; max_line_width = 0;
for (auto&& listbox_item : itemlist) for (auto&& listbox_item : itemlist)
{ {
std::size_t column_width = getColumnWidth(listbox_item.getText()); const auto column_width = getColumnWidth(listbox_item.getText());
if ( column_width > max_line_width ) if ( column_width > max_line_width )
max_line_width = column_width; max_line_width = column_width;
} }
int hmax = ( max_line_width > getWidth() - nf_offset - 4 ) const int hmax = ( max_line_width > getWidth() - nf_offset - 4 )
? int(max_line_width - getWidth() + nf_offset + 4) ? int(max_line_width - getWidth() + nf_offset + 4)
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4)); hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4));
if ( hbar->isShown() && isHorizontallyScrollable() ) if ( hbar->isShown() && isHorizontallyScrollable() )
hbar->hide(); hbar->hide();
int vmax = ( element_count + 2 > getHeight() ) const int vmax = ( element_count + 2 > getHeight() )
? int(element_count - getHeight()) + 2 ? int(element_count - getHeight()) + 2
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (int(element_count), int(getHeight()) - 2); vbar->setPageSize (int(element_count), int(getHeight()) - 2);
@ -276,7 +276,7 @@ void FListBox::clear()
// clear list from screen // clear list from screen
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setColor (wc.list_fg, wc.list_bg); setColor (wc.list_fg, wc.list_bg);
std::size_t size = getWidth() - 2; const std::size_t size = getWidth() - 2;
drawBorder(); drawBorder();
drawHeadline(); drawHeadline();
@ -292,9 +292,9 @@ void FListBox::clear()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::onKeyPress (FKeyEvent* ev) void FListBox::onKeyPress (FKeyEvent* ev)
{ {
std::size_t current_before = current; const std::size_t current_before = current;
int xoffset_before = xoffset; const int xoffset_before = xoffset;
int yoffset_before = yoffset; const int yoffset_before = yoffset;
processKeyAction(ev); // Process the keystrokes processKeyAction(ev); // Process the keystrokes
if ( current_before != current ) if ( current_before != current )
@ -302,8 +302,8 @@ void FListBox::onKeyPress (FKeyEvent* ev)
if ( ev->isAccepted() ) if ( ev->isAccepted() )
{ {
bool draw_vbar( yoffset_before != yoffset ); const bool draw_vbar( yoffset_before != yoffset );
bool draw_hbar( xoffset_before != xoffset ); const bool draw_hbar( xoffset_before != xoffset );
updateDrawing (draw_vbar, draw_hbar); updateDrawing (draw_vbar, draw_hbar);
} }
} }
@ -322,16 +322,16 @@ void FListBox::onMouseDown (FMouseEvent* ev)
getWidgetFocus(); getWidgetFocus();
int yoffset_before = yoffset; const int yoffset_before = yoffset;
std::size_t current_before = current; const std::size_t current_before = current;
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && mouse_y > 1 && mouse_y < int(getHeight()) )
{ {
click_on_list = true; click_on_list = true;
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
current = std::size_t(yoffset + mouse_y - 1); current = std::size_t(yoffset + mouse_y - 1);
if ( current > element_count ) if ( current > element_count )
@ -370,8 +370,8 @@ void FListBox::onMouseUp (FMouseEvent* ev)
if ( ev->getButton() == fc::LeftButton ) if ( ev->getButton() == fc::LeftButton )
{ {
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && mouse_y > 1 && mouse_y < int(getHeight()) )
@ -392,16 +392,16 @@ void FListBox::onMouseMove (FMouseEvent* ev)
if ( ev->getButton() == fc::RightButton && ! isMultiSelection() ) if ( ev->getButton() == fc::RightButton && ! isMultiSelection() )
return; return;
std::size_t current_before = current; const std::size_t current_before = current;
int yoffset_before = yoffset; const int yoffset_before = yoffset;
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && mouse_y > 1 && mouse_y < int(getHeight()) )
{ {
click_on_list = true; click_on_list = true;
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
current = std::size_t(yoffset + mouse_y - 1); current = std::size_t(yoffset + mouse_y - 1);
if ( current > element_count ) if ( current > element_count )
@ -448,8 +448,8 @@ void FListBox::onMouseDoubleClick (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && mouse_y > 1 && mouse_y < int(getHeight()) )
@ -464,8 +464,8 @@ void FListBox::onMouseDoubleClick (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::onTimer (FTimerEvent*) void FListBox::onTimer (FTimerEvent*)
{ {
std::size_t current_before = current; const std::size_t current_before = current;
int yoffset_before = yoffset; const int yoffset_before = yoffset;
switch ( int(drag_scroll) ) switch ( int(drag_scroll) )
{ {
@ -514,10 +514,10 @@ void FListBox::onTimer (FTimerEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::onWheel (FWheelEvent* ev) void FListBox::onWheel (FWheelEvent* ev)
{ {
std::size_t current_before = current; const std::size_t current_before = current;
int yoffset_before = yoffset; const int yoffset_before = yoffset;
int pagesize{4}; static constexpr int wheel_distance = 4;
int wheel = ev->getWheel(); const int wheel = ev->getWheel();
if ( drag_scroll != fc::noScroll ) if ( drag_scroll != fc::noScroll )
stopDragScroll(); stopDragScroll();
@ -525,11 +525,11 @@ void FListBox::onWheel (FWheelEvent* ev)
switch ( wheel ) switch ( wheel )
{ {
case fc::WheelUp: case fc::WheelUp:
wheelUp (pagesize); wheelUp (wheel_distance);
break; break;
case fc::WheelDown: case fc::WheelDown:
wheelDown (pagesize); wheelDown (wheel_distance);
break; break;
default: default:
@ -581,7 +581,7 @@ void FListBox::onFocusOut (FFocusEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::adjustYOffset (std::size_t element_count) void FListBox::adjustYOffset (std::size_t element_count)
{ {
std::size_t height = getClientHeight(); const std::size_t height = getClientHeight();
if ( height == 0 || element_count == 0 ) if ( height == 0 || element_count == 0 )
return; return;
@ -603,24 +603,24 @@ void FListBox::adjustYOffset (std::size_t element_count)
void FListBox::adjustSize() void FListBox::adjustSize()
{ {
FWidget::adjustSize(); FWidget::adjustSize();
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
std::size_t width = getClientWidth(); const std::size_t width = getClientWidth();
std::size_t height = getClientHeight(); const std::size_t height = getClientHeight();
adjustYOffset (element_count); adjustYOffset (element_count);
int vmax = ( element_count > height ) const int vmax = ( element_count > height )
? int(element_count - height) ? int(element_count - height)
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (int(element_count), int(height)); vbar->setPageSize (int(element_count), int(height));
vbar->setX (int(getWidth())); vbar->setX (int(getWidth()));
vbar->setHeight (height, false); vbar->setHeight (height, false);
vbar->resize(); vbar->resize();
int hmax = ( max_line_width + 2 > width ) const int hmax = ( max_line_width + 2 > width )
? int(max_line_width - width + 2) ? int(max_line_width - width + 2)
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(width) - 2); hbar->setPageSize (int(max_line_width), int(width) - 2);
hbar->setY (int(getHeight())); hbar->setY (int(getHeight()));
@ -698,7 +698,7 @@ inline void FListBox::mapKeyFunctions()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::processKeyAction (FKeyEvent* ev) void FListBox::processKeyAction (FKeyEvent* ev)
{ {
int idx = int(ev->key()); const int idx = int(ev->key());
if ( key_map.find(idx) != key_map.end() ) if ( key_map.find(idx) != key_map.end() )
{ {
@ -789,8 +789,8 @@ void FListBox::drawHeadline()
if ( text.isNull() || text.isEmpty() ) if ( text.isNull() || text.isEmpty() )
return; return;
FString txt(" " + text + " "); const FString txt(" " + text + " ");
auto column_width = getColumnWidth(txt); const auto column_width = getColumnWidth(txt);
print() << FPoint(2, 1); print() << FPoint(2, 1);
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
@ -826,8 +826,8 @@ void FListBox::drawList()
&& last_current != int(current) ) && last_current != int(current) )
{ {
// speed up: redraw only the changed rows // speed up: redraw only the changed rows
std::size_t last_pos = current - std::size_t(yoffset) - 1; const auto last_pos = current - std::size_t(yoffset) - 1;
std::size_t current_pos = std::size_t(last_current - yoffset) - 1; const auto current_pos = std::size_t(last_current - yoffset) - 1;
start = std::min(last_pos, current_pos); start = std::min(last_pos, current_pos);
num = std::max(last_pos, current_pos) + 1; num = std::max(last_pos, current_pos) + 1;
} }
@ -837,7 +837,7 @@ void FListBox::drawList()
for (std::size_t y = start; y < num && iter != itemlist.end() ; y++) for (std::size_t y = start; y < num && iter != itemlist.end() ; y++)
{ {
bool serach_mark{false}; bool serach_mark{false};
bool lineHasBrackets = hasBrackets(iter); const bool lineHasBrackets = hasBrackets(iter);
// Import data via lazy conversion // Import data via lazy conversion
lazyConvert (iter, int(y)); lazyConvert (iter, int(y));
@ -869,12 +869,12 @@ inline void FListBox::drawListLine ( int y
, listBoxItems::iterator iter , listBoxItems::iterator iter
, bool serach_mark ) , bool serach_mark )
{ {
std::size_t inc_len = inc_search.getLength(); const std::size_t inc_len = inc_search.getLength();
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
bool isCurrentLine( y + yoffset + 1 == int(current) ); const bool isCurrentLine( y + yoffset + 1 == int(current) );
std::size_t first = std::size_t(xoffset) + 1; const std::size_t first = std::size_t(xoffset) + 1;
std::size_t max_width = getWidth() - nf_offset - 4; const std::size_t max_width = getWidth() - nf_offset - 4;
FString element(getColumnSubString (getString(iter), first, max_width)); const FString element(getColumnSubString (getString(iter), first, max_width));
std::size_t column_width = getColumnWidth(element); std::size_t column_width = getColumnWidth(element);
if ( isMonochron() && isCurrentLine && getFlags().focus ) if ( isMonochron() && isCurrentLine && getFlags().focus )
@ -924,9 +924,9 @@ inline void FListBox::drawListBracketsLine ( int y
, listBoxItems::iterator iter , listBoxItems::iterator iter
, bool serach_mark ) , bool serach_mark )
{ {
std::size_t inc_len = inc_search.getLength() std::size_t b{0};
, b{0}; const std::size_t inc_len = inc_search.getLength();
bool isCurrentLine( y + yoffset + 1 == int(current) ); const bool isCurrentLine( y + yoffset + 1 == int(current) );
if ( isMonochron() && isCurrentLine && getFlags().focus ) if ( isMonochron() && isCurrentLine && getFlags().focus )
print (fc::BlackRightPointingPointer); // ► print (fc::BlackRightPointingPointer); // ►
@ -939,11 +939,11 @@ inline void FListBox::drawListBracketsLine ( int y
printLeftBracket (iter->brackets); printLeftBracket (iter->brackets);
} }
std::size_t first = std::size_t(xoffset); const std::size_t first = std::size_t(xoffset);
std::size_t max_width = getWidth() - nf_offset - 4 - b; const std::size_t max_width = getWidth() - nf_offset - 4 - b;
FString element(getColumnSubString (getString(iter), first, max_width)); const FString element(getColumnSubString (getString(iter), first, max_width));
std::size_t column_width = getColumnWidth(element); std::size_t column_width = getColumnWidth(element);
std::size_t text_width = getColumnWidth(getString(iter)); const std::size_t text_width = getColumnWidth(getString(iter));
std::size_t i{0}; std::size_t i{0};
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
@ -987,9 +987,9 @@ inline void FListBox::setLineAttributes ( int y
, bool lineHasBrackets , bool lineHasBrackets
, bool& serach_mark ) , bool& serach_mark )
{ {
bool isCurrentLine( y + yoffset + 1 == int(current) ); const bool isCurrentLine( y + yoffset + 1 == int(current) );
std::size_t inc_len = inc_search.getLength(); const std::size_t inc_len = inc_search.getLength();
std::size_t inc_width = getColumnWidth(inc_search); const std::size_t inc_width = getColumnWidth(inc_search);
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
print() << FPoint(2, 2 + int(y)); print() << FPoint(2, 2 + int(y));
@ -1035,7 +1035,7 @@ inline void FListBox::setLineAttributes ( int y
{ {
setColor ( wc.current_element_focus_fg setColor ( wc.current_element_focus_fg
, wc.current_element_focus_bg ); , wc.current_element_focus_bg );
int b = ( lineHasBrackets ) ? 1: 0; const int b = ( lineHasBrackets ) ? 1: 0;
if ( inc_len > 0 ) // incremental search if ( inc_len > 0 ) // incremental search
{ {
@ -1105,9 +1105,9 @@ void FListBox::recalculateHorizontalBar (std::size_t len, bool has_brackets)
if ( len >= getWidth() - nf_offset - 3 ) if ( len >= getWidth() - nf_offset - 3 )
{ {
int hmax = ( max_line_width > getWidth() - nf_offset - 4 ) const int hmax = ( max_line_width > getWidth() - nf_offset - 4 )
? int(max_line_width - getWidth() + nf_offset + 4) ? int(max_line_width - getWidth() + nf_offset + 4)
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset) - 4); hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset) - 4);
hbar->calculateSliderValues(); hbar->calculateSliderValues();
@ -1125,9 +1125,9 @@ void FListBox::recalculateHorizontalBar (std::size_t len, bool has_brackets)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::recalculateVerticalBar (std::size_t element_count) void FListBox::recalculateVerticalBar (std::size_t element_count)
{ {
int vmax = ( element_count + 2 > getHeight() ) const int vmax = ( element_count + 2 > getHeight() )
? int(element_count - getHeight() + 2) ? int(element_count - getHeight() + 2)
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (int(element_count), int(getHeight()) - 2); vbar->setPageSize (int(element_count), int(getHeight()) - 2);
vbar->calculateSliderValues(); vbar->calculateSliderValues();
@ -1237,7 +1237,7 @@ void FListBox::wheelUp (int pagesize)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::wheelDown (int pagesize) void FListBox::wheelDown (int pagesize)
{ {
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
int yoffset_end = int(element_count - getClientHeight()); int yoffset_end = int(element_count - getClientHeight());
if ( yoffset_end < 0 ) if ( yoffset_end < 0 )
@ -1276,7 +1276,7 @@ bool FListBox::dragScrollUp()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FListBox::dragScrollDown() bool FListBox::dragScrollDown()
{ {
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
if ( current == element_count ) if ( current == element_count )
{ {
@ -1370,8 +1370,8 @@ void FListBox::prevListItem (int distance)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::nextListItem (int distance) void FListBox::nextListItem (int distance)
{ {
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
int yoffset_end = int(element_count - getClientHeight()); const int yoffset_end = int(element_count - getClientHeight());
if ( current == element_count ) if ( current == element_count )
return; return;
@ -1393,7 +1393,8 @@ void FListBox::nextListItem (int distance)
void FListBox::scrollToX (int val) void FListBox::scrollToX (int val)
{ {
static constexpr std::size_t padding_space = 2; // 1 leading + 1 trailing space static constexpr std::size_t padding_space = 2; // 1 leading + 1 trailing space
std::size_t xoffset_end = max_line_width - getClientWidth() + padding_space; const std::size_t xoffset_end = max_line_width - getClientWidth()
+ padding_space;
if ( xoffset == val ) if ( xoffset == val )
return; return;
@ -1410,13 +1411,13 @@ void FListBox::scrollToX (int val)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::scrollToY (int val) void FListBox::scrollToY (int val)
{ {
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
int yoffset_end = int(element_count - getClientHeight()); const int yoffset_end = int(element_count - getClientHeight());
if ( yoffset == val ) if ( yoffset == val )
return; return;
int c = int(current) - yoffset; const int c = int(current) - yoffset;
yoffset = val; yoffset = val;
if ( yoffset > yoffset_end ) if ( yoffset > yoffset_end )
@ -1450,7 +1451,8 @@ void FListBox::scrollLeft (int distance)
void FListBox::scrollRight (int distance) void FListBox::scrollRight (int distance)
{ {
static constexpr std::size_t padding_space = 2; // 1 leading + 1 trailing space static constexpr std::size_t padding_space = 2; // 1 leading + 1 trailing space
std::size_t xoffset_end = max_line_width - getClientWidth() + padding_space; const std::size_t xoffset_end = max_line_width - getClientWidth()
+ padding_space;
xoffset += distance; xoffset += distance;
if ( xoffset == int(xoffset_end) ) if ( xoffset == int(xoffset_end) )
@ -1494,7 +1496,7 @@ inline void FListBox::onePosDown()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListBox::onePageUp() inline void FListBox::onePageUp()
{ {
int pagesize = int(getClientHeight()) - 1; const int pagesize = int(getClientHeight()) - 1;
prevListItem (pagesize); prevListItem (pagesize);
inc_search.clear(); inc_search.clear();
} }
@ -1502,7 +1504,7 @@ inline void FListBox::onePageUp()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListBox::onePageDown() inline void FListBox::onePageDown()
{ {
int pagesize = int(getClientHeight()) - 1; const int pagesize = int(getClientHeight()) - 1;
nextListItem (pagesize); nextListItem (pagesize);
inc_search.clear(); inc_search.clear();
} }
@ -1518,8 +1520,8 @@ inline void FListBox::firstPos()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListBox::lastPos() inline void FListBox::lastPos()
{ {
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
int yoffset_end = int(element_count - getClientHeight()); const int yoffset_end = int(element_count - getClientHeight());
current = element_count; current = element_count;
if ( current > getClientHeight() ) if ( current > getClientHeight() )
@ -1550,7 +1552,7 @@ inline void FListBox::acceptSelection()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FListBox::spacebarProcessing() inline bool FListBox::spacebarProcessing()
{ {
std::size_t inc_len = inc_search.getLength(); const std::size_t inc_len = inc_search.getLength();
if ( inc_len > 0 ) // Enter a spacebar for incremental search if ( inc_len > 0 ) // Enter a spacebar for incremental search
{ {
@ -1623,7 +1625,7 @@ inline bool FListBox::changeSelectionAndPosition()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FListBox::deletePreviousCharacter() inline bool FListBox::deletePreviousCharacter()
{ {
std::size_t inc_len = inc_search.getLength(); const std::size_t inc_len = inc_search.getLength();
if ( inc_len > 0 ) if ( inc_len > 0 )
{ {
@ -1735,7 +1737,7 @@ void FListBox::lazyConvert(listBoxItems::iterator iter, int y)
return; return;
lazy_inserter (*iter, source_container, y + yoffset); lazy_inserter (*iter, source_container, y + yoffset);
std::size_t column_width = getColumnWidth(iter->text); const auto column_width = getColumnWidth(iter->text);
recalculateHorizontalBar (column_width, hasBrackets(iter)); recalculateHorizontalBar (column_width, hasBrackets(iter));
if ( hbar->isShown() ) if ( hbar->isShown() )
@ -1746,10 +1748,10 @@ void FListBox::lazyConvert(listBoxItems::iterator iter, int y)
void FListBox::cb_VBarChange (FWidget*, FDataPtr) void FListBox::cb_VBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType; FScrollbar::sType scrollType;
std::size_t current_before = current; const std::size_t current_before = current;
int distance{1} static constexpr int wheel_distance = 4;
, pagesize{4} int distance{1};
, yoffset_before = yoffset; const int yoffset_before = yoffset;
scrollType = vbar->getScrollType(); scrollType = vbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
@ -1776,11 +1778,11 @@ void FListBox::cb_VBarChange (FWidget*, FDataPtr)
break; break;
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
wheelUp (pagesize); wheelUp (wheel_distance);
break; break;
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
wheelDown (pagesize); wheelDown (wheel_distance);
break; break;
} }
@ -1809,10 +1811,10 @@ void FListBox::cb_VBarChange (FWidget*, FDataPtr)
void FListBox::cb_HBarChange (FWidget*, FDataPtr) void FListBox::cb_HBarChange (FWidget*, FDataPtr)
{ {
static constexpr int padding_space = 2; // 1 leading space + 1 trailing space static constexpr int padding_space = 2; // 1 leading space + 1 trailing space
static constexpr int wheel_distance = 4;
FScrollbar::sType scrollType; FScrollbar::sType scrollType;
int distance{1} int distance{1};
, pagesize{4} const int xoffset_before = xoffset;
, xoffset_before = xoffset;
scrollType = hbar->getScrollType(); scrollType = hbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
@ -1839,11 +1841,11 @@ void FListBox::cb_HBarChange (FWidget*, FDataPtr)
break; break;
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
scrollLeft (pagesize); scrollLeft (wheel_distance);
break; break;
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
scrollRight (pagesize); scrollRight (wheel_distance);
break; break;
} }

View File

@ -89,8 +89,8 @@ uInt64 firstNumberFromString (const FString& str)
return 0; return 0;
uInt64 number; uInt64 number;
std::size_t pos = std::size_t(std::distance(str.begin(), first_pos)) + 1; const auto pos = std::size_t(std::distance(str.begin(), first_pos)) + 1;
std::size_t length = std::size_t(std::distance(first_pos, last_pos)); const auto length = std::size_t(std::distance(first_pos, last_pos));
const auto& num_str = str.mid(pos, length); const auto& num_str = str.mid(pos, length);
try try
@ -108,8 +108,8 @@ uInt64 firstNumberFromString (const FString& str)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool sortAscendingByName (const FObject* lhs, const FObject* rhs) bool sortAscendingByName (const FObject* lhs, const FObject* rhs)
{ {
const auto l_item = static_cast<const FListViewItem*>(lhs); const auto& l_item = static_cast<const FListViewItem*>(lhs);
const auto r_item = static_cast<const FListViewItem*>(rhs); const auto& r_item = static_cast<const FListViewItem*>(rhs);
const int column = l_item->getSortColumn(); const int column = l_item->getSortColumn();
const auto& l_string = l_item->getText(column); const auto& l_string = l_item->getText(column);
const auto& r_string = r_item->getText(column); const auto& r_string = r_item->getText(column);
@ -121,8 +121,8 @@ bool sortAscendingByName (const FObject* lhs, const FObject* rhs)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool sortDescendingByName (const FObject* lhs, const FObject* rhs) bool sortDescendingByName (const FObject* lhs, const FObject* rhs)
{ {
const auto l_item = static_cast<const FListViewItem*>(lhs); const auto& l_item = static_cast<const FListViewItem*>(lhs);
const auto r_item = static_cast<const FListViewItem*>(rhs); const auto& r_item = static_cast<const FListViewItem*>(rhs);
const int column = l_item->getSortColumn(); const int column = l_item->getSortColumn();
const auto& l_string = l_item->getText(column); const auto& l_string = l_item->getText(column);
const auto& r_string = r_item->getText(column); const auto& r_string = r_item->getText(column);
@ -134,8 +134,8 @@ bool sortDescendingByName (const FObject* lhs, const FObject* rhs)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool sortAscendingByNumber (const FObject* lhs, const FObject* rhs) bool sortAscendingByNumber (const FObject* lhs, const FObject* rhs)
{ {
const auto l_item = static_cast<const FListViewItem*>(lhs); const auto& l_item = static_cast<const FListViewItem*>(lhs);
const auto r_item = static_cast<const FListViewItem*>(rhs); const auto& r_item = static_cast<const FListViewItem*>(rhs);
const int column = l_item->getSortColumn(); const int column = l_item->getSortColumn();
const auto& l_number = firstNumberFromString(l_item->getText(column)); const auto& l_number = firstNumberFromString(l_item->getText(column));
const auto& r_number = firstNumberFromString(r_item->getText(column)); const auto& r_number = firstNumberFromString(r_item->getText(column));
@ -147,8 +147,8 @@ bool sortAscendingByNumber (const FObject* lhs, const FObject* rhs)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool sortDescendingByNumber (const FObject* lhs, const FObject* rhs) bool sortDescendingByNumber (const FObject* lhs, const FObject* rhs)
{ {
const auto l_item = static_cast<const FListViewItem*>(lhs); const auto& l_item = static_cast<const FListViewItem*>(lhs);
const auto r_item = static_cast<const FListViewItem*>(rhs); const auto& r_item = static_cast<const FListViewItem*>(rhs);
const int column = l_item->getSortColumn(); const int column = l_item->getSortColumn();
const auto& l_number = firstNumberFromString(l_item->getText(column)); const auto& l_number = firstNumberFromString(l_item->getText(column));
const auto& r_number = firstNumberFromString(r_item->getText(column)); const auto& r_number = firstNumberFromString(r_item->getText(column));
@ -208,7 +208,23 @@ FListViewItem::FListViewItem ( const FStringList& cols
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewItem::~FListViewItem() // destructor FListViewItem::~FListViewItem() // destructor
{ } {
// Remove from parent itemlist
auto parent = getParent();
if ( ! parent )
return;
if ( parent->isInstanceOf("FListView") )
{
static_cast<FListView*>(parent)->remove (this);
}
else if ( parent->isInstanceOf("FListViewItem") )
{
static_cast<FListViewItem*>(parent)->remove (this);
}
}
// public methods of FListViewItem // public methods of FListViewItem
@ -218,7 +234,7 @@ int FListViewItem::getSortColumn() const
if ( ! *root ) if ( ! *root )
return -1; return -1;
auto root_obj = static_cast<FListView*>(*root); const auto& root_obj = static_cast<FListView*>(*root);
return root_obj->getSortColumn(); return root_obj->getSortColumn();
} }
@ -231,18 +247,18 @@ FString FListViewItem::getText (int column) const
return fc::emptyFString::get(); return fc::emptyFString::get();
// Convert column position to address offset (index) // Convert column position to address offset (index)
std::size_t index = std::size_t(column - 1); const std::size_t index = std::size_t(column - 1);
return column_list[index]; return column_list[index];
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt FListViewItem::getDepth() const uInt FListViewItem::getDepth() const
{ {
auto parent = getParent(); const auto& parent = getParent();
if ( parent && parent->isInstanceOf("FListViewItem") ) if ( parent && parent->isInstanceOf("FListViewItem") )
{ {
auto parent_item = static_cast<FListViewItem*>(parent); const auto& parent_item = static_cast<FListViewItem*>(parent);
return parent_item->getDepth() + 1; return parent_item->getDepth() + 1;
} }
@ -258,7 +274,7 @@ void FListViewItem::setText (int column, const FString& text)
return; return;
// Convert column position to address offset (index) // Convert column position to address offset (index)
std::size_t index = std::size_t(column - 1); const auto index = std::size_t(column - 1);
auto parent = getParent(); auto parent = getParent();
if ( parent && parent->isInstanceOf("FListView") ) if ( parent && parent->isInstanceOf("FListView") )
@ -267,7 +283,7 @@ void FListViewItem::setText (int column, const FString& text)
if ( ! listview->header[index].fixed_width ) if ( ! listview->header[index].fixed_width )
{ {
int column_width = int(getColumnWidth(text)); const int column_width = int(getColumnWidth(text));
if ( column_width > listview->header[index].width ) if ( column_width > listview->header[index].width )
listview->header[index].width = column_width; listview->header[index].width = column_width;
@ -313,6 +329,43 @@ FObject::iterator FListViewItem::insert ( FListViewItem* child
return FListView::null_iter; return FListView::null_iter;
} }
//----------------------------------------------------------------------
void FListViewItem::remove (FListViewItem* item)
{
if ( item == nullptr || item == *FListView::null_iter )
return;
auto parent = item->getParent();
// Search for a FListView parent in my object tree
while ( parent && ! parent->isInstanceOf("FListView") )
{
parent = parent->getParent();
}
if ( parent == nullptr )
return;
if ( parent->isInstanceOf("FListView") )
{
auto listview = static_cast<FListView*>(parent);
listview->remove(item);
}
else
{
parent = item->getParent();
parent->delChild(item);
auto parent_item = static_cast<FListViewItem*>(parent);
parent_item->visible_lines--;
if ( ! parent_item->hasChildren() )
{
parent_item->expandable = false;
parent_item->is_expand = false;
}
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListViewItem::expand() void FListViewItem::expand()
{ {
@ -391,7 +444,7 @@ std::size_t FListViewItem::getVisibleLines()
while ( iter != FObject::end() ) while ( iter != FObject::end() )
{ {
auto child = static_cast<FListViewItem*>(*iter); const auto& child = static_cast<FListViewItem*>(*iter);
visible_lines += child->getVisibleLines(); visible_lines += child->getVisibleLines();
++iter; ++iter;
} }
@ -497,7 +550,7 @@ FListViewIterator& FListViewIterator::operator -= (volatile int n)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListViewIterator::nextElement (iterator& iter) void FListViewIterator::nextElement (iterator& iter)
{ {
auto item = static_cast<FListViewItem*>(*iter); const auto& item = static_cast<FListViewItem*>(*iter);
if ( item->isExpandable() && item->isExpand() ) if ( item->isExpandable() && item->isExpand() )
{ {
@ -512,7 +565,7 @@ void FListViewIterator::nextElement (iterator& iter)
if ( ! iter_path.empty() ) if ( ! iter_path.empty() )
{ {
auto& parent_iter = iter_path.top(); const auto& parent_iter = iter_path.top();
if ( iter == (*parent_iter)->end() ) if ( iter == (*parent_iter)->end() )
{ {
@ -531,9 +584,9 @@ void FListViewIterator::prevElement (iterator& iter)
if ( ! iter_path.empty() ) if ( ! iter_path.empty() )
{ {
auto& parent_iter = iter_path.top(); const auto& parent_iter = iter_path.top();
if ( start_iter == (*parent_iter)->begin() ) if ( start_iter == (*parent_iter)->begin() ) // First sub-item
{ {
iter = parent_iter; iter = parent_iter;
position--; position--;
@ -545,7 +598,7 @@ void FListViewIterator::prevElement (iterator& iter)
--iter; --iter;
auto item = static_cast<FListViewItem*>(*iter); auto item = static_cast<FListViewItem*>(*iter);
if ( iter == start_iter ) if ( iter == start_iter ) // No changes
return; return;
else else
position--; position--;
@ -565,7 +618,7 @@ void FListViewIterator::parentElement()
if ( iter_path.empty() ) if ( iter_path.empty() )
return; return;
auto& parent_iter = iter_path.top(); const auto& parent_iter = iter_path.top();
while ( node != parent_iter ) while ( node != parent_iter )
prevElement(node); prevElement(node);
@ -598,7 +651,7 @@ std::size_t FListView::getCount()
for (auto&& item : itemlist) for (auto&& item : itemlist)
{ {
auto listitem = static_cast<FListViewItem*>(item); const auto& listitem = static_cast<FListViewItem*>(item);
n += listitem->getVisibleLines(); n += listitem->getVisibleLines();
} }
@ -614,7 +667,7 @@ fc::text_alignment FListView::getColumnAlignment (int column) const
return fc::alignLeft; return fc::alignLeft;
// Convert column position to address offset (index) // Convert column position to address offset (index)
std::size_t index = std::size_t(column - 1); const std::size_t index = std::size_t(column - 1);
return header[index].alignment; return header[index].alignment;
} }
@ -627,7 +680,7 @@ FString FListView::getColumnText (int column) const
return fc::emptyFString::get(); return fc::emptyFString::get();
// Convert column position to address offset (index) // Convert column position to address offset (index)
std::size_t index = std::size_t(column - 1); const std::size_t index = std::size_t(column - 1);
return header[index].name; return header[index].name;
} }
@ -635,7 +688,7 @@ FString FListView::getColumnText (int column) const
fc::sorting_type FListView::getColumnSortType (int column) const fc::sorting_type FListView::getColumnSortType (int column) const
{ {
fc::sorting_type type; fc::sorting_type type;
std::size_t col = std::size_t(column); const std::size_t col = std::size_t(column);
try try
{ {
@ -673,7 +726,7 @@ void FListView::setColumnAlignment (int column, fc::text_alignment align)
return; return;
// Convert column position to address offset (index) // Convert column position to address offset (index)
std::size_t index = std::size_t(column - 1); const std::size_t index = std::size_t(column - 1);
header[index].alignment = align; header[index].alignment = align;
} }
@ -690,7 +743,7 @@ void FListView::setColumnText (int column, const FString& label)
if ( ! header[index].fixed_width ) if ( ! header[index].fixed_width )
{ {
int column_width = int(getColumnWidth(label)); const int column_width = int(getColumnWidth(label));
if ( column_width > header[index].width ) if ( column_width > header[index].width )
header[index].width = column_width; header[index].width = column_width;
@ -707,7 +760,7 @@ void FListView::setColumnSortType (int column, fc::sorting_type type)
if ( column < 1 || header.empty() || column > int(header.size()) ) if ( column < 1 || header.empty() || column > int(header.size()) )
return; return;
std::size_t size = std::size_t(column) + 1; const std::size_t size = std::size_t(column) + 1;
if ( sort_type.empty() || sort_type.size() < size ) if ( sort_type.empty() || sort_type.size() < size )
sort_type.resize(size); sort_type.resize(size);
@ -761,7 +814,7 @@ FObject::iterator FListView::insert ( FListViewItem* item
beforeInsertion(item); // preprocessing beforeInsertion(item); // preprocessing
if ( parent_iter == root ) if ( parent_iter == root )
{ {
item_iter = appendItem (item); item_iter = appendItem (item);
} }
@ -816,6 +869,93 @@ FObject::iterator FListView::insert ( const FStringList& cols
return insert(item, parent_iter); return insert(item, parent_iter);
} }
//----------------------------------------------------------------------
void FListView::remove (FListViewItem* item)
{
if ( item == nullptr || itemlist.empty() )
return;
auto parent = item->getParent();
const auto& current_item = static_cast<FListViewItem*>(*current_iter);
const auto& first_item = itemlist.front();
auto end_iter = static_cast<FListViewIterator>(itemlist.end());
const auto& last_item = *(--end_iter);
const bool is_current_line( item == current_item );
const bool is_first_line( item == first_item );
const bool is_last_line( item == last_item );
if ( is_current_line )
{
if ( is_last_line || current_item == itemlist.back() )
stepBackward();
else
{
collapseSubtree();
stepForward();
}
}
if ( is_first_line )
++first_visible_line;
if ( parent )
{
if ( this == parent )
{
itemlist.remove(item);
delChild(item);
current_iter.getPosition()--;
}
else
{
parent->delChild(item);
auto parent_item = static_cast<FListViewItem*>(parent);
parent_item->visible_lines--;
current_iter.getPosition()--;
if ( ! parent_item->hasChildren() )
{
parent_item->expandable = false;
parent_item->is_expand = false;
}
}
}
const std::size_t element_count = getCount();
recalculateVerticalBar (element_count);
if ( itemlist.empty() )
{
current_iter = FListView::null_iter;
first_visible_line = FListView::null_iter;
last_visible_line = FListView::null_iter;
clearList();
}
else
{
drawList();
drawBorder();
drawHeadlines();
drawScrollbars();
}
}
//----------------------------------------------------------------------
void FListView::clear()
{
itemlist.clear();
current_iter = FListView::null_iter;
first_visible_line = FListView::null_iter;
last_visible_line = FListView::null_iter;
recalculateVerticalBar (0);
first_line_position_before = -1;
xoffset = 0;
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
clearList();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::sort() void FListView::sort()
{ {
@ -868,8 +1008,8 @@ void FListView::sort()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::onKeyPress (FKeyEvent* ev) void FListView::onKeyPress (FKeyEvent* ev)
{ {
int position_before = current_iter.getPosition(); const int position_before = current_iter.getPosition();
int xoffset_before = xoffset; const int xoffset_before = xoffset;
first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
clicked_expander_pos.setPoint(-1, -1); clicked_expander_pos.setPoint(-1, -1);
processKeyAction(ev); // Process the keystrokes processKeyAction(ev); // Process the keystrokes
@ -879,9 +1019,9 @@ void FListView::onKeyPress (FKeyEvent* ev)
if ( ev->isAccepted() ) if ( ev->isAccepted() )
{ {
bool draw_vbar( first_line_position_before const bool draw_vbar( first_line_position_before
!= first_visible_line.getPosition() ); != first_visible_line.getPosition() );
bool draw_hbar(xoffset_before != xoffset); const bool draw_hbar(xoffset_before != xoffset);
updateDrawing (draw_vbar, draw_hbar); updateDrawing (draw_vbar, draw_hbar);
} }
} }
@ -907,8 +1047,8 @@ void FListView::onMouseDown (FMouseEvent* ev)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
} }
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
if ( mouse_x > 1 && mouse_x < int(getWidth()) ) if ( mouse_x > 1 && mouse_x < int(getWidth()) )
@ -923,12 +1063,12 @@ void FListView::onMouseDown (FMouseEvent* ev)
return; return;
int indent = 0; int indent = 0;
int new_pos = first_visible_line.getPosition() + mouse_y - 2; const int new_pos = first_visible_line.getPosition() + mouse_y - 2;
if ( new_pos < int(getCount()) ) if ( new_pos < int(getCount()) )
setRelativePosition (mouse_y - 2); setRelativePosition (mouse_y - 2);
const auto item = getCurrentItem(); const auto& item = getCurrentItem();
if ( tree_view ) if ( tree_view )
{ {
@ -973,8 +1113,8 @@ void FListView::onMouseUp (FMouseEvent* ev)
if ( ev->getButton() == fc::LeftButton ) if ( ev->getButton() == fc::LeftButton )
{ {
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) ) if ( mouse_x > 1 && mouse_x < int(getWidth()) )
{ {
@ -988,7 +1128,7 @@ void FListView::onMouseUp (FMouseEvent* ev)
return; return;
int indent{0}; int indent{0};
auto item = getCurrentItem(); const auto& item = getCurrentItem();
if ( tree_view ) if ( tree_view )
{ {
@ -1044,14 +1184,14 @@ void FListView::onMouseMove (FMouseEvent* ev)
return; return;
} }
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && mouse_y > 1 && mouse_y < int(getHeight()) )
{ {
int new_pos = first_visible_line.getPosition() + mouse_y - 2; const int new_pos = first_visible_line.getPosition() + mouse_y - 2;
if ( new_pos < int(getCount()) ) if ( new_pos < int(getCount()) )
setRelativePosition (mouse_y - 2); setRelativePosition (mouse_y - 2);
@ -1083,8 +1223,8 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && mouse_y > 1 && mouse_y < int(getHeight()) )
@ -1119,7 +1259,7 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::onTimer (FTimerEvent*) void FListView::onTimer (FTimerEvent*)
{ {
int position_before = current_iter.getPosition(); const int position_before = current_iter.getPosition();
first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
switch ( int(drag_scroll) ) switch ( int(drag_scroll) )
@ -1158,8 +1298,8 @@ void FListView::onTimer (FTimerEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::onWheel (FWheelEvent* ev) void FListView::onWheel (FWheelEvent* ev)
{ {
int position_before = current_iter.getPosition(); const int position_before = current_iter.getPosition();
int pagesize{4}; static constexpr int wheel_distance = 4;
first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
if ( drag_scroll != fc::noScroll ) if ( drag_scroll != fc::noScroll )
@ -1168,11 +1308,11 @@ void FListView::onWheel (FWheelEvent* ev)
switch ( ev->getWheel() ) switch ( ev->getWheel() )
{ {
case fc::WheelUp: case fc::WheelUp:
wheelUp (pagesize); wheelUp (wheel_distance);
break; break;
case fc::WheelDown: case fc::WheelDown:
wheelDown (pagesize); wheelDown (wheel_distance);
break; break;
default: default:
@ -1218,7 +1358,7 @@ void FListView::onFocusOut (FFocusEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::adjustViewport (int element_count) void FListView::adjustViewport (int element_count)
{ {
int height = int(getClientHeight()); const int height = int(getClientHeight());
if ( height <= 0 || element_count == 0 ) if ( height <= 0 || element_count == 0 )
return; return;
@ -1232,8 +1372,8 @@ void FListView::adjustViewport (int element_count)
if ( first_visible_line.getPosition() > element_count - height ) if ( first_visible_line.getPosition() > element_count - height )
{ {
int difference = first_visible_line.getPosition() const int difference = first_visible_line.getPosition()
- (element_count - height); - (element_count - height);
if ( first_visible_line.getPosition() >= difference ) if ( first_visible_line.getPosition() >= difference )
{ {
@ -1242,8 +1382,8 @@ void FListView::adjustViewport (int element_count)
} }
} }
int after_last_visible_line = first_visible_line.getPosition() const int after_last_visible_line = first_visible_line.getPosition()
+ height; + height;
if ( last_visible_line.getPosition() >= after_last_visible_line ) if ( last_visible_line.getPosition() >= after_last_visible_line )
{ {
@ -1259,24 +1399,24 @@ void FListView::adjustViewport (int element_count)
void FListView::adjustSize() void FListView::adjustSize()
{ {
FWidget::adjustSize(); FWidget::adjustSize();
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
std::size_t width = getClientWidth(); const std::size_t width = getClientWidth();
std::size_t height = getClientHeight(); const std::size_t height = getClientHeight();
adjustViewport (int(element_count)); adjustViewport (int(element_count));
int vmax = ( element_count > height ) const int vmax = ( element_count > height )
? int(element_count - height) ? int(element_count - height)
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (int(element_count), int(height)); vbar->setPageSize (int(element_count), int(height));
vbar->setX (int(getWidth())); vbar->setX (int(getWidth()));
vbar->setHeight (height, false); vbar->setHeight (height, false);
vbar->resize(); vbar->resize();
int hmax = ( max_line_width > width ) const int hmax = ( max_line_width > width )
? int(max_line_width - width) ? int(max_line_width - width)
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(width)); hbar->setPageSize (int(max_line_width), int(width));
hbar->setY (int(getHeight())); hbar->setY (int(getHeight()));
@ -1340,7 +1480,7 @@ inline void FListView::mapKeyFunctions()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::processKeyAction (FKeyEvent* ev) void FListView::processKeyAction (FKeyEvent* ev)
{ {
int idx = int(ev->key()); const int idx = int(ev->key());
if ( key_map.find(idx) != key_map.end() ) if ( key_map.find(idx) != key_map.end() )
{ {
@ -1371,7 +1511,7 @@ void FListView::sort (Compare cmp)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::size_t FListView::getAlignOffset ( fc::text_alignment align std::size_t FListView::getAlignOffset ( const fc::text_alignment align
, std::size_t column_width , std::size_t column_width
, std::size_t width ) , std::size_t width )
{ {
@ -1444,7 +1584,7 @@ void FListView::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::drawBorder() void FListView::drawBorder()
{ {
FRect box(FPoint(1, 1), getSize()); const FRect box(FPoint(1, 1), getSize());
finalcut::drawListBorder (this, box); finalcut::drawListBorder (this, box);
} }
@ -1502,15 +1642,15 @@ void FListView::drawList()
return; return;
uInt y{0}; uInt y{0};
uInt page_height = uInt(getHeight()) - 2; const uInt page_height = uInt(getHeight()) - 2;
auto iter = first_visible_line; auto iter = first_visible_line;
while ( iter != itemlist.end() && y < page_height ) while ( iter != itemlist.end() && y < page_height )
{ {
bool is_current_line( iter == current_iter ); const bool is_current_line( iter == current_iter );
const auto item = static_cast<FListViewItem*>(*iter); const auto& item = static_cast<FListViewItem*>(*iter);
int tree_offset = ( tree_view ) ? int(item->getDepth() << 1) + 1 : 0; const int tree_offset = ( tree_view ) ? int(item->getDepth() << 1) + 1 : 0;
int checkbox_offset = ( item->isCheckable() ) ? 1 : 0; const int checkbox_offset = ( item->isCheckable() ) ? 1 : 0;
print() << FPoint(2, 2 + int(y)); print() << FPoint(2, 2 + int(y));
// Draw one FListViewItem // Draw one FListViewItem
@ -1556,7 +1696,7 @@ void FListView::drawListLine ( const FListViewItem* item
setLineAttributes (is_current, is_focus); setLineAttributes (is_current, is_focus);
// Print the entry // Print the entry
std::size_t indent = item->getDepth() << 1; // indent = 2 * depth const std::size_t indent = item->getDepth() << 1; // indent = 2 * depth
FString line(getLinePrefix (item, indent)); FString line(getLinePrefix (item, indent));
// Print columns // Print columns
@ -1567,12 +1707,12 @@ void FListView::drawListLine ( const FListViewItem* item
static constexpr std::size_t ellipsis_length = 2; static constexpr std::size_t ellipsis_length = 2;
const auto& text = item->column_list[col]; const auto& text = item->column_list[col];
std::size_t width = std::size_t(header[col].width); std::size_t width = std::size_t(header[col].width);
std::size_t column_width = getColumnWidth(text); const std::size_t column_width = getColumnWidth(text);
// Increment the value of col for the column position // Increment the value of col for the column position
// and the next iteration // and the next iteration
col++; col++;
fc::text_alignment align = getColumnAlignment(int(col)); const fc::text_alignment align = getColumnAlignment(int(col));
std::size_t align_offset = getAlignOffset (align, column_width, width); const std::size_t align_offset = getAlignOffset (align, column_width, width);
if ( tree_view && col == 1 ) if ( tree_view && col == 1 )
{ {
@ -1597,7 +1737,7 @@ void FListView::drawListLine ( const FListViewItem* item
else if ( align == fc::alignRight ) else if ( align == fc::alignRight )
{ {
// Ellipse right align text // Ellipse right align text
std::size_t first = getColumnWidth(text) + 1 - width; const std::size_t first = getColumnWidth(text) + 1 - width;
line += FString (L".."); line += FString (L"..");
line += getColumnSubString (text, first, width - ellipsis_length); line += getColumnSubString (text, first, width - ellipsis_length);
line += L' '; line += L' ';
@ -1611,9 +1751,9 @@ void FListView::drawListLine ( const FListViewItem* item
} }
} }
std::size_t width = getWidth() - nf_offset - 2; const std::size_t width = getWidth() - nf_offset - 2;
line = getColumnSubString ( line, std::size_t(xoffset) + 1, width ); line = getColumnSubString ( line, std::size_t(xoffset) + 1, width );
std::size_t len = line.getLength(); const std::size_t len = line.getLength();
std::size_t char_width{0}; std::size_t char_width{0};
for (std::size_t i{0}; i < len; i++) for (std::size_t i{0}; i < len; i++)
@ -1626,6 +1766,28 @@ void FListView::drawListLine ( const FListViewItem* item
print (' '); print (' ');
} }
//----------------------------------------------------------------------
void FListView::clearList()
{
// Clear list from terminal screen
const auto& wc = getFWidgetColors();
setColor (wc.list_fg, wc.list_bg);
const std::size_t size = getWidth() - 2;
drawBorder();
drawHeadlines();
if ( size == 0 )
return;
for (int y{0}; y < int(getHeight()) - 2; y++)
{
print() << FPoint(2, 2 + y) << FString(size, L' ');
}
drawScrollbars();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::setLineAttributes ( bool is_current inline void FListView::setLineAttributes ( bool is_current
, bool is_focus ) , bool is_focus )
@ -1757,12 +1919,12 @@ void FListView::drawHeadlineLabel (const headerItems::const_iterator& iter)
static constexpr std::size_t leading_space = 1; static constexpr std::size_t leading_space = 1;
const auto& text = iter->name; const auto& text = iter->name;
FString txt(" " + text); FString txt(" " + text);
std::size_t width = std::size_t(iter->width); const std::size_t width = std::size_t(iter->width);
std::size_t column_width = getColumnWidth(txt); std::size_t column_width = getColumnWidth(txt);
std::size_t column_max = leading_space + width; const std::size_t column_max = leading_space + width;
headerItems::const_iterator first = header.begin(); const headerItems::const_iterator first = header.begin();
int column = int(std::distance(first, iter)) + 1; const int column = int(std::distance(first, iter)) + 1;
bool has_sort_indicator( sort_column == column && ! hide_sort_indicator ); const bool has_sort_indicator( sort_column == column && ! hide_sort_indicator );
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
if ( isEnabled() ) if ( isEnabled() )
@ -1844,7 +2006,7 @@ void FListView::drawBufferedHeadline()
for (auto&& tc : FTermBuffer(first, last)) for (auto&& tc : FTermBuffer(first, last))
{ {
uInt8 char_width = tc.attr.bit.char_width; const uInt8 char_width = tc.attr.bit.char_width;
if ( column_width + char_width > getClientWidth() ) if ( column_width + char_width > getClientWidth() )
{ {
@ -1891,7 +2053,7 @@ void FListView::drawColumnEllipsis ( const headerItems::const_iterator& iter
{ {
// Print label ellipsis // Print label ellipsis
static constexpr int ellipsis_length = 2; static constexpr int ellipsis_length = 2;
int width = iter->width; const int width = iter->width;
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
headerline << ' ' headerline << ' '
@ -1929,15 +2091,15 @@ std::size_t FListView::determineLineWidth (FListViewItem* item)
static constexpr std::size_t padding_space = 1; static constexpr std::size_t padding_space = 1;
std::size_t line_width = padding_space; // leading space std::size_t line_width = padding_space; // leading space
std::size_t column_idx{0}; std::size_t column_idx{0};
std::size_t entries = std::size_t(item->column_list.size()); const auto entries = std::size_t(item->column_list.size());
if ( hasCheckableItems() ) if ( hasCheckableItems() )
line_width += checkbox_space; line_width += checkbox_space;
for (auto&& header_item : header) for (auto&& header_item : header)
{ {
std::size_t width = std::size_t(header_item.width); const std::size_t width = std::size_t(header_item.width);
bool fixed_width = header_item.fixed_width; const bool fixed_width = header_item.fixed_width;
if ( ! fixed_width ) if ( ! fixed_width )
{ {
@ -1980,7 +2142,7 @@ inline void FListView::afterInsertion()
// Sort list by a column (only if activated) // Sort list by a column (only if activated)
sort(); sort();
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
recalculateVerticalBar (element_count); recalculateVerticalBar (element_count);
} }
@ -1994,9 +2156,9 @@ void FListView::recalculateHorizontalBar (std::size_t len)
if ( len >= getWidth() - nf_offset - 3 ) if ( len >= getWidth() - nf_offset - 3 )
{ {
int hmax = ( max_line_width > getWidth() - nf_offset - 4 ) const int hmax = ( max_line_width > getWidth() - nf_offset - 4 )
? int(max_line_width - getWidth() + nf_offset + 4) ? int(max_line_width - getWidth() + nf_offset + 4)
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset) - 4); hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset) - 4);
hbar->calculateSliderValues(); hbar->calculateSliderValues();
@ -2014,9 +2176,9 @@ void FListView::recalculateHorizontalBar (std::size_t len)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::recalculateVerticalBar (std::size_t element_count) void FListView::recalculateVerticalBar (std::size_t element_count)
{ {
int vmax = ( element_count + 2 > getHeight() ) const int vmax = ( element_count + 2 > getHeight() )
? int(element_count - getHeight() + 2) ? int(element_count - getHeight() + 2)
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (int(element_count), int(getHeight()) - 2); vbar->setPageSize (int(element_count), int(getHeight()) - 2);
vbar->calculateSliderValues(); vbar->calculateSliderValues();
@ -2034,14 +2196,14 @@ void FListView::recalculateVerticalBar (std::size_t element_count)
void FListView::mouseHeaderClicked() void FListView::mouseHeaderClicked()
{ {
int column{1}; int column{1};
int checkbox_offset = ( hasCheckableItems() ) ? checkbox_space : 0; const int checkbox_offset = ( hasCheckableItems() ) ? checkbox_space : 0;
const int header_pos = clicked_header_pos.getX() + xoffset;
int header_start = 2 + checkbox_offset; int header_start = 2 + checkbox_offset;
int header_pos = clicked_header_pos.getX() + xoffset;
for (auto&& item : header) for (auto&& item : header)
{ {
static constexpr int leading_space = 1; static constexpr int leading_space = 1;
bool has_sort_indicator( column == sort_column ); const bool has_sort_indicator( column == sort_column );
int click_width = int(getColumnWidth(item.name)); int click_width = int(getColumnWidth(item.name));
if ( has_sort_indicator ) if ( has_sort_indicator )
@ -2086,9 +2248,9 @@ void FListView::wheelUp (int pagesize)
else else
{ {
// Save relative position from the first line // Save relative position from the first line
int ry = current_iter.getPosition() - first_visible_line.getPosition(); const int ry = current_iter.getPosition() - first_visible_line.getPosition();
// Save difference from top // Save difference from top
int difference = first_visible_line.getPosition(); const int difference = first_visible_line.getPosition();
first_visible_line -= difference; first_visible_line -= difference;
last_visible_line -= difference; last_visible_line -= difference;
setRelativePosition(ry); setRelativePosition(ry);
@ -2101,7 +2263,7 @@ void FListView::wheelDown (int pagesize)
if ( itemlist.empty() ) if ( itemlist.empty() )
return; return;
int element_count = int(getCount()); const int element_count = int(getCount());
if ( current_iter.getPosition() + 1 == element_count ) if ( current_iter.getPosition() + 1 == element_count )
return; return;
@ -2115,9 +2277,9 @@ void FListView::wheelDown (int pagesize)
else else
{ {
// Save relative position from the first line // Save relative position from the first line
int ry = current_iter.getPosition() - first_visible_line.getPosition(); const int ry = current_iter.getPosition() - first_visible_line.getPosition();
// Save difference from bottom // Save difference from bottom
int differenz = element_count - last_visible_line.getPosition() - 1; const int differenz = element_count - last_visible_line.getPosition() - 1;
first_visible_line += differenz; first_visible_line += differenz;
last_visible_line += differenz; last_visible_line += differenz;
setRelativePosition(ry); setRelativePosition(ry);
@ -2140,7 +2302,7 @@ bool FListView::dragScrollUp (int position_before)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FListView::dragScrollDown (int position_before) bool FListView::dragScrollDown (int position_before)
{ {
int element_count = int(getCount()); const int element_count = int(getCount());
if ( position_before + 1 == element_count ) if ( position_before + 1 == element_count )
{ {
@ -2265,20 +2427,17 @@ inline void FListView::toggleCheckbox()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::collapseAndScrollLeft() inline void FListView::collapseAndScrollLeft()
{ {
if ( itemlist.empty() ) const int position_before = current_iter.getPosition();
return;
int position_before = current_iter.getPosition();
auto item = getCurrentItem(); auto item = getCurrentItem();
if ( xoffset == 0 ) if ( xoffset == 0 && item && ! itemlist.empty() )
{ {
if ( tree_view && item->isExpandable() && item->isExpand() ) if ( tree_view && item->isExpandable() && item->isExpand() )
{ {
// Collapse element // Collapse element
item->collapse(); item->collapse();
adjustSize(); adjustSize();
std::size_t element_count = getCount(); const std::size_t element_count = getCount();
recalculateVerticalBar (element_count); recalculateVerticalBar (element_count);
// Force vertical scrollbar redraw // Force vertical scrollbar redraw
first_line_position_before = -1; first_line_position_before = -1;
@ -2286,7 +2445,7 @@ inline void FListView::collapseAndScrollLeft()
else if ( item->hasParent() ) else if ( item->hasParent() )
{ {
// Jump to parent element // Jump to parent element
auto parent = item->getParent(); const auto& parent = item->getParent();
if ( parent->isInstanceOf("FListViewItem") ) if ( parent->isInstanceOf("FListViewItem") )
{ {
@ -2294,7 +2453,7 @@ inline void FListView::collapseAndScrollLeft()
if ( current_iter.getPosition() < first_line_position_before ) if ( current_iter.getPosition() < first_line_position_before )
{ {
int difference = position_before - current_iter.getPosition(); const int difference = position_before - current_iter.getPosition();
if ( first_visible_line.getPosition() - difference >= 0 ) if ( first_visible_line.getPosition() - difference >= 0 )
{ {
@ -2303,7 +2462,7 @@ inline void FListView::collapseAndScrollLeft()
} }
else else
{ {
int d = first_visible_line.getPosition(); const int d = first_visible_line.getPosition();
first_visible_line -= d; first_visible_line -= d;
last_visible_line -= d; last_visible_line -= d;
} }
@ -2322,13 +2481,11 @@ inline void FListView::collapseAndScrollLeft()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::expandAndScrollRight() inline void FListView::expandAndScrollRight()
{ {
if ( itemlist.empty() ) const int xoffset_end = int(max_line_width) - int(getClientWidth());
return;
int xoffset_end = int(max_line_width) - int(getClientWidth());
auto item = getCurrentItem(); auto item = getCurrentItem();
if ( tree_view && item->isExpandable() && ! item->isExpand() ) if ( tree_view && ! itemlist.empty() && item
&& item->isExpandable() && ! item->isExpand() )
{ {
// Expand element // Expand element
item->expand(); item->expand();
@ -2354,7 +2511,7 @@ inline void FListView::firstPos()
return; return;
current_iter -= current_iter.getPosition(); current_iter -= current_iter.getPosition();
int difference = first_visible_line.getPosition(); const int difference = first_visible_line.getPosition();
first_visible_line -= difference; first_visible_line -= difference;
last_visible_line -= difference; last_visible_line -= difference;
} }
@ -2365,9 +2522,9 @@ inline void FListView::lastPos()
if ( itemlist.empty() ) if ( itemlist.empty() )
return; return;
int element_count = int(getCount()); const int element_count = int(getCount());
current_iter += element_count - current_iter.getPosition() - 1; current_iter += element_count - current_iter.getPosition() - 1;
int difference = element_count - last_visible_line.getPosition() - 1; const int difference = element_count - last_visible_line.getPosition() - 1;
first_visible_line += difference; first_visible_line += difference;
last_visible_line += difference; last_visible_line += difference;
} }
@ -2460,7 +2617,7 @@ void FListView::stepForward (int distance)
if ( itemlist.empty() ) if ( itemlist.empty() )
return; return;
int element_count = int(getCount()); const int element_count = int(getCount());
if ( current_iter.getPosition() + 1 == element_count ) if ( current_iter.getPosition() + 1 == element_count )
return; return;
@ -2483,7 +2640,7 @@ void FListView::stepForward (int distance)
} }
else else
{ {
int differenz = element_count - last_visible_line.getPosition() - 1; const int differenz = element_count - last_visible_line.getPosition() - 1;
first_visible_line += differenz; first_visible_line += differenz;
last_visible_line += differenz; last_visible_line += differenz;
} }
@ -2514,7 +2671,7 @@ void FListView::stepBackward (int distance)
} }
else else
{ {
int difference = first_visible_line.getPosition(); const int difference = first_visible_line.getPosition();
first_visible_line -= difference; first_visible_line -= difference;
last_visible_line -= difference; last_visible_line -= difference;
} }
@ -2524,7 +2681,7 @@ void FListView::stepBackward (int distance)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::scrollToX (int x) void FListView::scrollToX (int x)
{ {
int xoffset_end = int(max_line_width) - int(getClientWidth()); const int xoffset_end = int(max_line_width) - int(getClientWidth());
if ( xoffset == x ) if ( xoffset == x )
return; return;
@ -2541,14 +2698,14 @@ void FListView::scrollToX (int x)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::scrollToY (int y) void FListView::scrollToY (int y)
{ {
int pagesize = int(getClientHeight()) - 1; const int pagesize = int(getClientHeight()) - 1;
int element_count = int(getCount()); const int element_count = int(getCount());
if ( first_visible_line.getPosition() == y ) if ( first_visible_line.getPosition() == y )
return; return;
// Save relative position from the top line // Save relative position from the top line
int ry = current_iter.getPosition() - first_visible_line.getPosition(); const int ry = current_iter.getPosition() - first_visible_line.getPosition();
if ( y + pagesize <= element_count ) if ( y + pagesize <= element_count )
{ {
@ -2560,7 +2717,7 @@ void FListView::scrollToY (int y)
} }
else else
{ {
int differenz = element_count - last_visible_line.getPosition() - 1; const int differenz = element_count - last_visible_line.getPosition() - 1;
current_iter += differenz; current_iter += differenz;
first_visible_line += differenz; first_visible_line += differenz;
last_visible_line += differenz; last_visible_line += differenz;
@ -2590,8 +2747,8 @@ void FListView::scrollBy (int dx, int dy)
void FListView::cb_VBarChange (FWidget*, FDataPtr) void FListView::cb_VBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType = vbar->getScrollType(); FScrollbar::sType scrollType = vbar->getScrollType();
static constexpr int wheel_distance = 4;
int distance{1}; int distance{1};
int pagesize{4};
first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
switch ( scrollType ) switch ( scrollType )
@ -2621,11 +2778,11 @@ void FListView::cb_VBarChange (FWidget*, FDataPtr)
} }
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
wheelUp (pagesize); wheelUp (wheel_distance);
break; break;
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
wheelDown (pagesize); wheelDown (wheel_distance);
break; break;
} }
@ -2649,9 +2806,9 @@ void FListView::cb_VBarChange (FWidget*, FDataPtr)
void FListView::cb_HBarChange (FWidget*, FDataPtr) void FListView::cb_HBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType = hbar->getScrollType(); FScrollbar::sType scrollType = hbar->getScrollType();
int distance{1} static constexpr int wheel_distance = 4;
, pagesize{4} int distance{1};
, xoffset_before = xoffset; const int xoffset_before = xoffset;
switch ( scrollType ) switch ( scrollType )
{ {
@ -2674,17 +2831,17 @@ void FListView::cb_HBarChange (FWidget*, FDataPtr)
case FScrollbar::scrollJump: case FScrollbar::scrollJump:
{ {
int value = hbar->getValue(); const int value = hbar->getValue();
scrollToX(value); scrollToX(value);
break; break;
} }
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
scrollBy (-pagesize, 0); scrollBy (-wheel_distance, 0);
break; break;
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
scrollBy (pagesize, 0); scrollBy (wheel_distance, 0);
break; break;
} }

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -60,7 +60,7 @@ FMenu::FMenu (const FString& txt, FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenu::~FMenu() // destructor FMenu::~FMenu() // destructor
{ {
auto fapp = FApplication::getApplicationObject(); const auto& fapp = FApplication::getApplicationObject();
if ( ! fapp->isQuit() ) if ( ! fapp->isQuit() )
switchToPrevWindow(this); // Switch to previous window switchToPrevWindow(this); // Switch to previous window
@ -321,7 +321,7 @@ void FMenu::onMouseMove (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::cb_menuitem_toggled (FWidget* widget, FDataPtr) void FMenu::cb_menuitem_toggled (FWidget* widget, FDataPtr)
{ {
auto m_item = static_cast<FMenuItem*>(widget); const auto& m_item = static_cast<FMenuItem*>(widget);
if ( ! has_checkable_items ) if ( ! has_checkable_items )
return; return;
@ -374,7 +374,7 @@ bool FMenu::isRadioMenuItem (const FWidget* w) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::isSubMenu() const bool FMenu::isSubMenu() const
{ {
auto super = getSuperMenu(); const auto& super = getSuperMenu();
if ( super && isMenu(super) ) if ( super && isMenu(super) )
return true; return true;
@ -385,7 +385,7 @@ bool FMenu::isSubMenu() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::isDialogMenu() const bool FMenu::isDialogMenu() const
{ {
auto super = getSuperMenu(); const auto& super = getSuperMenu();
return ( super ) ? super->isDialogWidget() : false; return ( super ) ? super->isDialogWidget() : false;
} }
@ -415,7 +415,7 @@ bool FMenu::isMouseOverSubMenu (const FPoint& termpos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::isMouseOverSuperMenu (const FPoint& termpos) bool FMenu::isMouseOverSuperMenu (const FPoint& termpos)
{ {
const auto smenu = superMenuAt (termpos); const auto& smenu = superMenuAt (termpos);
if ( smenu ) if ( smenu )
return true; return true;
@ -481,8 +481,8 @@ void FMenu::calculateDimensions()
for (auto&& item : getItemList()) for (auto&& item : getItemList())
{ {
std::size_t item_width = item->getTextWidth() + 2; std::size_t item_width = item->getTextWidth() + 2;
FKey accel_key = item->accel_key; const FKey accel_key = item->accel_key;
bool has_menu = item->hasMenu(); const bool has_menu = item->hasMenu();
if ( has_menu ) if ( has_menu )
{ {
@ -490,7 +490,7 @@ void FMenu::calculateDimensions()
} }
else if ( accel_key ) else if ( accel_key )
{ {
std::size_t accel_len = getKeyName(accel_key).getLength(); const std::size_t accel_len = getKeyName(accel_key).getLength();
item_width += accel_len + 2; item_width += accel_len + 2;
} }
@ -501,14 +501,14 @@ void FMenu::calculateDimensions()
max_item_width = item_width; max_item_width = item_width;
} }
int adjust_X = adjustX(getX()); const int adjust_X = adjustX(getX());
// set widget geometry // set widget geometry
setGeometry ( FPoint(adjust_X, getY()) setGeometry ( FPoint(adjust_X, getY())
, FSize(max_item_width + 2, getCount() + 2) ); , FSize(max_item_width + 2, getCount() + 2) );
// set geometry of all items // set geometry of all items
int item_X = 1; const int item_X = 1;
int item_Y = 1; int item_Y = 1;
for (auto&& item : getItemList()) for (auto&& item : getItemList())
@ -517,8 +517,8 @@ void FMenu::calculateDimensions()
if ( item->hasMenu() ) if ( item->hasMenu() )
{ {
int menu_X = getTermX() + int(max_item_width) + 1; const int menu_X = getTermX() + int(max_item_width) + 1;
int menu_Y = item->getTermY() - 2; const int menu_Y = item->getTermY() - 2;
// set sub-menu position // set sub-menu position
item->getMenu()->setPos (FPoint(menu_X, menu_Y), false); item->getMenu()->setPos (FPoint(menu_X, menu_Y), false);
} }
@ -537,7 +537,7 @@ void FMenu::adjustItems()
auto menu = item->getMenu(); auto menu = item->getMenu();
int menu_X = getTermX() + int(max_item_width) + 1; int menu_X = getTermX() + int(max_item_width) + 1;
menu_X = menu->adjustX(menu_X); menu_X = menu->adjustX(menu_X);
int menu_Y = item->getTermY() - 2; const int menu_Y = item->getTermY() - 2;
// set sub-menu position // set sub-menu position
menu->setPos (FPoint(menu_X, menu_Y)); menu->setPos (FPoint(menu_X, menu_Y));
@ -658,11 +658,11 @@ bool FMenu::mouseDownOverList (FPoint mouse_pos)
for (auto&& item : getItemList()) for (auto&& item : getItemList())
{ {
int x1 = item->getX() const int x1 = item->getX();
, x2 = item->getX() + int(item->getWidth()) const int x2 = item->getX() + int(item->getWidth());
, y = item->getY() const int y = item->getY();
, mouse_x = mouse_pos.getX() const int mouse_x = mouse_pos.getX();
, mouse_y = mouse_pos.getY(); const int mouse_y = mouse_pos.getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x < x2 && mouse_x < x2
@ -729,7 +729,8 @@ void FMenu::mouseDownSelection (FMenuItem* m_item, bool& focus_changed)
if ( m_item->hasMenu() ) if ( m_item->hasMenu() )
{ {
auto sub_menu = m_item->getMenu(); const auto& sub_menu = m_item->getMenu();
if ( ! sub_menu->isShown() ) if ( ! sub_menu->isShown() )
shown_sub_menu = sub_menu; shown_sub_menu = sub_menu;
} }
@ -742,11 +743,11 @@ bool FMenu::mouseUpOverList (FPoint mouse_pos)
for (auto&& item : getItemList()) for (auto&& item : getItemList())
{ {
int x1 = item->getX() const int x1 = item->getX();
, x2 = item->getX() + int(item->getWidth()) const int x2 = item->getX() + int(item->getWidth());
, y = item->getY() const int y = item->getY();
, mouse_x = mouse_pos.getX() const int mouse_x = mouse_pos.getX();
, mouse_y = mouse_pos.getY(); const int mouse_y = mouse_pos.getY();
if ( item->isSelected() if ( item->isSelected()
&& mouse_x >= x1 && mouse_x >= x1
@ -797,11 +798,11 @@ void FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& ms)
for (auto&& item : getItemList()) for (auto&& item : getItemList())
{ {
int x1 = item->getX() const int x1 = item->getX();
, x2 = item->getX() + int(item->getWidth()) const int x2 = item->getX() + int(item->getWidth());
, y = item->getY() const int y = item->getY();
, mouse_x = mouse_pos.getX() const int mouse_x = mouse_pos.getX();
, mouse_y = mouse_pos.getY(); const int mouse_y = mouse_pos.getY();
if ( mouse_x >= x1 && mouse_x < x2 && mouse_y == y ) if ( mouse_x >= x1 && mouse_x < x2 && mouse_y == y )
mouseMoveSelection (item, ms); mouseMoveSelection (item, ms);
@ -834,7 +835,7 @@ void FMenu::mouseMoveSelection (FMenuItem* m_item, mouseStates& ms)
// Sub menu handling // Sub menu handling
if ( m_item->hasMenu() ) if ( m_item->hasMenu() )
{ {
auto sub_menu = m_item->getMenu(); const auto& sub_menu = m_item->getMenu();
if ( ! sub_menu->isShown() ) if ( ! sub_menu->isShown() )
shown_sub_menu = sub_menu; shown_sub_menu = sub_menu;
@ -900,7 +901,7 @@ void FMenu::passEventToSubMenu (FMouseEvent*& ev)
const auto& t = ev->getTermPos(); const auto& t = ev->getTermPos();
const auto& p = opened_sub_menu->termToWidgetPos(t); const auto& p = opened_sub_menu->termToWidgetPos(t);
int b = ev->getButton(); const int b = ev->getButton();
try try
{ {
@ -921,10 +922,10 @@ void FMenu::passEventToSuperMenu (FMouseEvent*& ev)
{ {
// Mouse event handover to super-menu // Mouse event handover to super-menu
const auto& smenu = superMenuAt (ev->getTermPos()); auto smenu = superMenuAt (ev->getTermPos());
const auto& t = ev->getTermPos(); const auto& t = ev->getTermPos();
const auto& p = smenu->termToWidgetPos(t); const auto& p = smenu->termToWidgetPos(t);
int b = ev->getButton(); const int b = ev->getButton();
try try
{ {
@ -945,10 +946,10 @@ void FMenu::passEventToMenuBar (FMouseEvent*& ev)
{ {
// Mouse event handover to the menu bar // Mouse event handover to the menu bar
const auto& menu_bar = getMenuBar(); auto menu_bar = getMenuBar();
const auto& t = ev->getTermPos(); const auto& t = ev->getTermPos();
const auto& p = menu_bar->termToWidgetPos(t); const auto& p = menu_bar->termToWidgetPos(t);
int b = ev->getButton(); const int b = ev->getButton();
try try
{ {
@ -970,7 +971,7 @@ bool FMenu::containsMenuStructure (int x, int y)
{ {
// Check mouse click position for item, menu and all sub menus // Check mouse click position for item, menu and all sub menus
auto si = getSelectedItem(); const auto& si = getSelectedItem();
if ( getTermGeometry().contains(x, y) ) if ( getTermGeometry().contains(x, y) )
return true; return true;
@ -998,7 +999,7 @@ FMenu* FMenu::superMenuAt (int x, int y)
return static_cast<FMenu*>(super); return static_cast<FMenu*>(super);
else else
{ {
auto smenu = static_cast<FMenu*>(getSuperMenu()); const auto& smenu = static_cast<FMenu*>(getSuperMenu());
if ( smenu ) if ( smenu )
return smenu->superMenuAt(x, y); return smenu->superMenuAt(x, y);
@ -1011,7 +1012,7 @@ FMenu* FMenu::superMenuAt (int x, int y)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::selectNextItem() bool FMenu::selectNextItem()
{ {
auto list = getItemList(); const auto& list = getItemList();
auto iter = list.begin(); auto iter = list.begin();
while ( iter != list.end() ) while ( iter != list.end() )
@ -1059,7 +1060,7 @@ bool FMenu::selectNextItem()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::selectPrevItem() bool FMenu::selectPrevItem()
{ {
auto list = getItemList(); const auto& list = getItemList();
auto iter = list.end(); auto iter = list.end();
do do
@ -1123,7 +1124,7 @@ bool FMenu::hotkeyMenu (FKeyEvent* ev)
{ {
bool found{false}; bool found{false};
FKey hotkey = item->getHotkey(); FKey hotkey = item->getHotkey();
FKey key = ev->key(); const FKey key = ev->key();
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0; hotkey -= 0xfee0;
@ -1245,9 +1246,9 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
FString txt(m_item->getText()); FString txt(m_item->getText());
menuText txtdata{}; menuText txtdata{};
std::size_t column_width = getColumnWidth(txt); std::size_t column_width = getColumnWidth(txt);
FKey accel_key = m_item->accel_key; const FKey accel_key = m_item->accel_key;
bool is_enabled = m_item->isEnabled(); const bool is_enabled = m_item->isEnabled();
bool is_selected = m_item->isSelected(); const bool is_selected = m_item->isSelected();
// Set screen position and attributes // Set screen position and attributes
setLineAttributes (m_item, y); setLineAttributes (m_item, y);
@ -1289,9 +1290,9 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::drawCheckMarkPrefix (FMenuItem* m_item) inline void FMenu::drawCheckMarkPrefix (FMenuItem* m_item)
{ {
bool is_checked = m_item->isChecked(); const bool is_checked = m_item->isChecked();
bool is_checkable = m_item->checkable; const bool is_checkable = m_item->checkable;
bool is_radio_btn = m_item->radio_button; const bool is_radio_btn = m_item->radio_button;
if ( ! has_checkable_items ) if ( ! has_checkable_items )
return; return;
@ -1373,8 +1374,8 @@ inline void FMenu::drawMenuText (menuText& data)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::drawSubMenuIndicator (std::size_t& startpos) inline void FMenu::drawSubMenuIndicator (std::size_t& startpos)
{ {
std::size_t c = ( has_checkable_items ) ? 1 : 0; const std::size_t c = ( has_checkable_items ) ? 1 : 0;
std::size_t len = max_item_width - (startpos + c + 3); const std::size_t len = max_item_width - (startpos + c + 3);
if ( len > 0 ) if ( len > 0 )
{ {
@ -1389,15 +1390,15 @@ inline void FMenu::drawSubMenuIndicator (std::size_t& startpos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::drawAcceleratorKey (std::size_t& startpos, FKey accel_key) inline void FMenu::drawAcceleratorKey (std::size_t& startpos, FKey accel_key)
{ {
FString accel_name (getKeyName(accel_key)); const FString accel_name (getKeyName(accel_key));
std::size_t c = ( has_checkable_items ) ? 1 : 0; const std::size_t c = ( has_checkable_items ) ? 1 : 0;
std::size_t accel_len = accel_name.getLength(); const std::size_t accel_len = accel_name.getLength();
std::size_t len = max_item_width - (startpos + accel_len + c + 2); const std::size_t len = max_item_width - (startpos + accel_len + c + 2);
if ( len > 0 ) if ( len > 0 )
{ {
// Print filling blank spaces + accelerator key name // Print filling blank spaces + accelerator key name
FString spaces (len, L' '); const FString spaces (len, L' ');
print (spaces + accel_name); print (spaces + accel_name);
startpos = max_item_width - (c + 2); startpos = max_item_width - (c + 2);
} }
@ -1406,7 +1407,7 @@ inline void FMenu::drawAcceleratorKey (std::size_t& startpos, FKey accel_key)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::drawTrailingSpaces (std::size_t startpos) inline void FMenu::drawTrailingSpaces (std::size_t startpos)
{ {
std::size_t c = ( has_checkable_items ) ? 1 : 0; const std::size_t c = ( has_checkable_items ) ? 1 : 0;
// Print trailing blank space // Print trailing blank space
for (std::size_t i = startpos + c; i < max_item_width - 1; i++) for (std::size_t i = startpos + c; i < max_item_width - 1; i++)
@ -1416,8 +1417,8 @@ inline void FMenu::drawTrailingSpaces (std::size_t startpos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::setLineAttributes (FMenuItem* m_item, int y) inline void FMenu::setLineAttributes (FMenuItem* m_item, int y)
{ {
bool is_enabled = m_item->isEnabled(); const bool is_enabled = m_item->isEnabled();
bool is_selected = m_item->isSelected(); const bool is_selected = m_item->isSelected();
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
if ( is_enabled ) if ( is_enabled )
@ -1455,8 +1456,8 @@ inline void FMenu::setLineAttributes (FMenuItem* m_item, int y)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::setCursorToHotkeyPosition (FMenuItem* m_item) inline void FMenu::setCursorToHotkeyPosition (FMenuItem* m_item)
{ {
bool is_checkable = m_item->checkable; const bool is_checkable = m_item->checkable;
bool is_selected = m_item->isSelected(); const bool is_selected = m_item->isSelected();
if ( hotkeypos == NOT_SET ) if ( hotkeypos == NOT_SET )
{ {
@ -1474,7 +1475,7 @@ inline void FMenu::setCursorToHotkeyPosition (FMenuItem* m_item)
if ( is_selected ) if ( is_selected )
{ {
// set cursor to the hotkey position // set cursor to the hotkey position
auto x = getColumnWidth (m_item->getText(), hotkeypos); const auto x = getColumnWidth (m_item->getText(), hotkeypos);
if ( is_checkable ) if ( is_checkable )
m_item->setCursorPos (FPoint(3 + int(x), 1)); m_item->setCursorPos (FPoint(3 + int(x), 1));
@ -1561,7 +1562,7 @@ inline void FMenu::closeMenu()
} }
else else
{ {
auto super = getSuperMenu(); const auto& super = getSuperMenu();
hideSuperMenus(); hideSuperMenus();
if ( getStatusBar() ) if ( getStatusBar() )

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -931,7 +931,7 @@ void FMenuBar::passEventToMenu (const FMouseEvent*& ev)
return; return;
// Mouse event handover to the menu // Mouse event handover to the menu
const auto& menu = getSelectedItem()->getMenu(); auto menu = getSelectedItem()->getMenu();
const auto& menu_geometry = menu->getTermGeometry(); const auto& menu_geometry = menu->getTermGeometry();
if ( menu->getCount() > 0 if ( menu->getCount() > 0
@ -939,7 +939,7 @@ void FMenuBar::passEventToMenu (const FMouseEvent*& ev)
{ {
const auto& t = ev->getTermPos(); const auto& t = ev->getTermPos();
const auto& p = menu->termToWidgetPos(t); const auto& p = menu->termToWidgetPos(t);
int b = ev->getButton(); const int b = ev->getButton();
try try
{ {

View File

@ -185,7 +185,7 @@ void FMenuItem::setText (const FString& txt)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::addAccelerator (FKey key, FWidget* obj) void FMenuItem::addAccelerator (FKey key, FWidget* obj)
{ {
auto root = getRootWidget(); const auto& root = getRootWidget();
FAccelerator accel = { key, obj }; FAccelerator accel = { key, obj };
if ( root ) if ( root )
@ -475,8 +475,8 @@ bool FMenuItem::isMenu (FWidget* w) const
if ( ! w ) if ( ! w )
return false; return false;
bool m1 = w->isInstanceOf("FMenu"); const bool m1 = w->isInstanceOf("FMenu");
bool m2 = w->isInstanceOf("FDialogListMenu"); const bool m2 = w->isInstanceOf("FDialogListMenu");
return bool( m1 || m2 ); return bool( m1 || m2 );
} }
@ -583,7 +583,7 @@ void FMenuItem::createDialogList (FMenu* winmenu)
if ( getDialogList() && ! getDialogList()->empty() ) if ( getDialogList() && ! getDialogList()->empty() )
{ {
auto first = getDialogList()->begin(); const auto& first = getDialogList()->begin();
auto iter = first; auto iter = first;
while ( iter != getDialogList()->end() && *iter ) while ( iter != getDialogList()->end() && *iter )
@ -593,7 +593,7 @@ void FMenuItem::createDialogList (FMenu* winmenu)
if ( win ) if ( win )
{ {
FMenuItem* win_item{}; FMenuItem* win_item{};
uInt32 n = uInt32(std::distance(first, iter)); const uInt32 n = uInt32(std::distance(first, iter));
// get the dialog title // get the dialog title
const auto& name = win->getText(); const auto& name = win->getText();
@ -644,7 +644,7 @@ void FMenuItem::passMouseEvent ( T widget, FMouseEvent* ev
const auto& t = ev->getTermPos(); const auto& t = ev->getTermPos();
const auto& p2 = widget->termToWidgetPos(t); const auto& p2 = widget->termToWidgetPos(t);
int b = ev->getButton(); const int b = ev->getButton();
std::shared_ptr<FMouseEvent> _ev; std::shared_ptr<FMouseEvent> _ev;
try try
@ -694,7 +694,7 @@ void FMenuItem::cb_switchToDialog (FWidget*, FDataPtr data)
void FMenuItem::cb_destroyDialog (FWidget* widget, FDataPtr) void FMenuItem::cb_destroyDialog (FWidget* widget, FDataPtr)
{ {
auto win = static_cast<FDialog*>(widget); auto win = static_cast<FDialog*>(widget);
auto fapp = FApplication::getApplicationObject(); const auto& fapp = FApplication::getApplicationObject();
if ( win && fapp ) if ( win && fapp )
{ {

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -137,7 +137,7 @@ void FMessageBox::setHeadline (const FString& headline)
for (uInt n{0}; n < num_buttons; n++) for (uInt n{0}; n < num_buttons; n++)
button[n]->setY (int(getHeight()) - 4, false); button[n]->setY (int(getHeight()) - 4, false);
std::size_t column_width = getColumnWidth(headline_text); const std::size_t column_width = getColumnWidth(headline_text);
if ( column_width > max_line_width ) if ( column_width > max_line_width )
max_line_width = column_width; max_line_width = column_width;
@ -166,7 +166,7 @@ void FMessageBox::adjustSize()
{ {
std::size_t max_width{}; std::size_t max_width{};
std::size_t max_height{}; std::size_t max_height{};
auto root_widget = getRootWidget(); const auto& root_widget = getRootWidget();
if ( root_widget ) if ( root_widget )
{ {
@ -180,8 +180,8 @@ void FMessageBox::adjustSize()
max_height = 24; max_height = 24;
} }
int x = 1 + int((max_width - getWidth()) / 2); const int x = 1 + int((max_width - getWidth()) / 2);
int y = 1 + int((max_height - getHeight()) / 3); const int y = 1 + int((max_height - getHeight()) / 3);
setPos(FPoint(x, y), false); setPos(FPoint(x, y), false);
FDialog::adjustSize(); FDialog::adjustSize();
} }
@ -189,7 +189,7 @@ void FMessageBox::adjustSize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMessageBox::cb_processClick (FWidget*, FDataPtr data) void FMessageBox::cb_processClick (FWidget*, FDataPtr data)
{ {
int reply = *(static_cast<int*>(data)); const int reply = *(static_cast<int*>(data));
done (reply); done (reply);
} }
@ -321,7 +321,7 @@ void FMessageBox::calculateDimensions()
for (auto&& line : text_components) for (auto&& line : text_components)
{ {
std::size_t column_width = getColumnWidth(line); const std::size_t column_width = getColumnWidth(line);
if ( column_width > max_line_width ) if ( column_width > max_line_width )
max_line_width = column_width; max_line_width = column_width;
@ -345,7 +345,7 @@ void FMessageBox::draw()
int head_offset{0}; int head_offset{0};
int center_x{0}; int center_x{0};
// center the whole block // center the whole block
int msg_x = int((getWidth() - max_line_width) / 2); const int msg_x = int((getWidth() - max_line_width) / 2);
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
@ -353,7 +353,7 @@ void FMessageBox::draw()
if ( ! headline_text.isEmpty() ) if ( ! headline_text.isEmpty() )
{ {
setColor(emphasis_color, getBackgroundColor()); setColor(emphasis_color, getBackgroundColor());
std::size_t headline_width = getColumnWidth(headline_text); const std::size_t headline_width = getColumnWidth(headline_text);
if ( center_text ) // center one line if ( center_text ) // center one line
center_x = int((max_line_width - headline_width) / 2); center_x = int((max_line_width - headline_width) / 2);
@ -366,7 +366,7 @@ void FMessageBox::draw()
for (auto&& line : text_components) for (auto&& line : text_components)
{ {
std::size_t line_width = getColumnWidth(line); const std::size_t line_width = getColumnWidth(line);
if ( center_text ) // center one line if ( center_text ) // center one line
center_x = int((max_line_width - line_width) / 2); center_x = int((max_line_width - line_width) / 2);
@ -428,13 +428,13 @@ void FMessageBox::adjustButtons()
if ( btn_width + 4 >= getWidth() ) if ( btn_width + 4 >= getWidth() )
{ {
std::size_t max_width; std::size_t max_width;
auto root_widget = getRootWidget(); const auto& root_widget = getRootWidget();
setWidth(btn_width + 5); setWidth(btn_width + 5);
max_width = ( root_widget ) ? root_widget->getClientWidth() : 80; max_width = ( root_widget ) ? root_widget->getClientWidth() : 80;
setX (int((max_width - getWidth()) / 2)); setX (int((max_width - getWidth()) / 2));
} }
int btn_x = int((getWidth() - btn_width) / 2); const int btn_x = int((getWidth() - btn_width) / 2);
for (std::size_t n{0}; n < num_buttons; n++) for (std::size_t n{0}; n < num_buttons; n++)
{ {
@ -442,7 +442,7 @@ void FMessageBox::adjustButtons()
button[n]->setX(btn_x); button[n]->setX(btn_x);
else else
{ {
int btn_size = int(button[n]->getWidth()); const int btn_size = int(button[n]->getWidth());
button[n]->setX(btn_x + int(n) * (btn_size + int(gap))); button[n]->setX(btn_x + int(n) * (btn_size + int(gap)));
} }
} }

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 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -178,7 +178,7 @@ inline bool FMouse::isInputDataPending()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FMouse* FMouse::createMouseObject (mouse_type mt) inline FMouse* FMouse::createMouseObject (const mouse_type mt)
{ {
switch ( mt ) switch ( mt )
{ {
@ -491,7 +491,7 @@ bool FMouseGPM::getGpmKeyPressed (bool is_pending)
{ {
setPending(is_pending); setPending(is_pending);
has_gpm_mouse_data = false; has_gpm_mouse_data = false;
int type = gpmEvent(); const int type = gpmEvent();
switch ( type ) switch ( type )
{ {
@ -519,7 +519,7 @@ void FMouseGPM::drawGpmPointer()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FMouseGPM::gpmEvent (bool clear) int FMouseGPM::gpmEvent (bool clear)
{ {
int max = ( gpm_fd > stdin_no ) ? gpm_fd : stdin_no; const int max = ( gpm_fd > stdin_no ) ? gpm_fd : stdin_no;
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
@ -528,7 +528,7 @@ int FMouseGPM::gpmEvent (bool clear)
FD_SET(gpm_fd, &ifds); FD_SET(gpm_fd, &ifds);
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 100000; // 100 ms tv.tv_usec = 100000; // 100 ms
int result = select (max + 1, &ifds, 0, 0, &tv); const int result = select (max + 1, &ifds, 0, 0, &tv);
if ( result > 0 && FD_ISSET(stdin_no, &ifds) ) if ( result > 0 && FD_ISSET(stdin_no, &ifds) )
{ {
@ -572,7 +572,7 @@ void FMouseX11::setRawData (FKeyboard::keybuffer& fifo_buf)
// Import the X11 xterm mouse protocol (SGR-Mode) raw mouse data // Import the X11 xterm mouse protocol (SGR-Mode) raw mouse data
static constexpr std::size_t len = 6; static constexpr std::size_t len = 6;
std::size_t fifo_buf_size{sizeof(fifo_buf)}; const std::size_t fifo_buf_size{sizeof(fifo_buf)};
std::size_t n{}; std::size_t n{};
x11_mouse[0] = fifo_buf[3]; x11_mouse[0] = fifo_buf[3];
x11_mouse[1] = fifo_buf[4]; x11_mouse[1] = fifo_buf[4];
@ -598,9 +598,9 @@ void FMouseX11::processEvent (struct timeval* time)
// Parse and interpret the X11 xterm mouse string // Parse and interpret the X11 xterm mouse string
const auto& mouse_position = getPos(); const auto& mouse_position = getPos();
uChar x = uChar(x11_mouse[1] - 0x20); const uChar x = uChar(x11_mouse[1] - 0x20);
uChar y = uChar(x11_mouse[2] - 0x20); const uChar y = uChar(x11_mouse[2] - 0x20);
int btn = x11_mouse[0]; const int btn = x11_mouse[0];
setNewPos (x, y); setNewPos (x, y);
clearButtonState(); clearButtonState();
setKeyState (btn); setKeyState (btn);
@ -652,7 +652,7 @@ void FMouseX11::setMoveState (const FPoint& mouse_position, int btn)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMouseX11::setButtonState (int btn, struct timeval* time) void FMouseX11::setButtonState (const int btn, struct timeval* time)
{ {
// Get the x11 mouse button state // Get the x11 mouse button state
@ -749,7 +749,7 @@ void FMouseSGR::setRawData (FKeyboard::keybuffer& fifo_buf)
{ {
// Import the X11 xterm mouse protocol (SGR-Mode) raw mouse data // Import the X11 xterm mouse protocol (SGR-Mode) raw mouse data
std::size_t fifo_buf_size = sizeof(fifo_buf); const std::size_t fifo_buf_size = sizeof(fifo_buf);
std::size_t len = std::strlen(fifo_buf); std::size_t len = std::strlen(fifo_buf);
std::size_t n{3}; std::size_t n{3};
@ -784,7 +784,7 @@ void FMouseSGR::processEvent (struct timeval* time)
int btn{0}; int btn{0};
// parse the SGR mouse string // parse the SGR mouse string
char* p = sgr_mouse; const char* p = sgr_mouse;
while ( *p && *p != ';' ) while ( *p && *p != ';' )
{ {
@ -877,7 +877,7 @@ void FMouseSGR::setMoveState (const FPoint& mouse_position, int btn)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMouseSGR::setPressedButtonState (int btn, struct timeval* time) void FMouseSGR::setPressedButtonState (const int btn, struct timeval* time)
{ {
// Gets the extended x11 mouse mode (SGR) status for pressed buttons // Gets the extended x11 mouse mode (SGR) status for pressed buttons
@ -929,7 +929,7 @@ void FMouseSGR::setPressedButtonState (int btn, struct timeval* time)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMouseSGR::setReleasedButtonState (int btn) void FMouseSGR::setReleasedButtonState (const int btn)
{ {
// Gets the extended x11 mouse mode (SGR) status for released buttons // Gets the extended x11 mouse mode (SGR) status for released buttons
@ -978,7 +978,7 @@ void FMouseUrxvt::setRawData (FKeyboard::keybuffer& fifo_buf)
{ {
// Import the X11 xterm mouse protocol (Urxvt-Mode) raw mouse data // Import the X11 xterm mouse protocol (Urxvt-Mode) raw mouse data
std::size_t fifo_buf_size = sizeof(fifo_buf); const std::size_t fifo_buf_size = sizeof(fifo_buf);
std::size_t len = std::strlen(fifo_buf); std::size_t len = std::strlen(fifo_buf);
std::size_t n{2}; std::size_t n{2};
@ -1015,7 +1015,7 @@ void FMouseUrxvt::processEvent (struct timeval* time)
int btn{0}; int btn{0};
// Parse the Urxvt mouse string // Parse the Urxvt mouse string
char* p = urxvt_mouse; const char* p = urxvt_mouse;
bool x_neg{false}; bool x_neg{false};
bool y_neg{false}; bool y_neg{false};
@ -1132,7 +1132,7 @@ void FMouseUrxvt::setMoveState (const FPoint& mouse_position, int btn)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMouseUrxvt::setButtonState (int btn, struct timeval* time) void FMouseUrxvt::setButtonState (const int btn, struct timeval* time)
{ {
// Get the urxvt mouse button state // Get the urxvt mouse button state
@ -1236,7 +1236,7 @@ FMouseControl::~FMouseControl() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FPoint& FMouseControl::getPos() FPoint& FMouseControl::getPos()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->getPos(); return mouse_object->getPos();
@ -1303,7 +1303,7 @@ void FMouseControl::useXtermMouse (bool enable)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::hasData() bool FMouseControl::hasData()
{ {
auto mouse_object = getMouseWithData(); const auto& mouse_object = getMouseWithData();
if ( mouse_object ) // with data if ( mouse_object ) // with data
return true; return true;
@ -1314,7 +1314,7 @@ bool FMouseControl::hasData()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::hasEvent() bool FMouseControl::hasEvent()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) // with event if ( mouse_object ) // with event
return true; return true;
@ -1325,7 +1325,7 @@ bool FMouseControl::hasEvent()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isLeftButtonPressed() bool FMouseControl::isLeftButtonPressed()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isLeftButtonPressed(); return mouse_object->isLeftButtonPressed();
@ -1336,7 +1336,7 @@ bool FMouseControl::isLeftButtonPressed()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isLeftButtonReleased() bool FMouseControl::isLeftButtonReleased()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isLeftButtonReleased(); return mouse_object->isLeftButtonReleased();
@ -1347,7 +1347,7 @@ bool FMouseControl::isLeftButtonReleased()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isLeftButtonDoubleClick() bool FMouseControl::isLeftButtonDoubleClick()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isLeftButtonDoubleClick(); return mouse_object->isLeftButtonDoubleClick();
@ -1358,7 +1358,7 @@ bool FMouseControl::isLeftButtonDoubleClick()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isRightButtonPressed() bool FMouseControl::isRightButtonPressed()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isRightButtonPressed(); return mouse_object->isRightButtonPressed();
@ -1369,7 +1369,7 @@ bool FMouseControl::isRightButtonPressed()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isRightButtonReleased() bool FMouseControl::isRightButtonReleased()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isRightButtonReleased(); return mouse_object->isRightButtonReleased();
@ -1380,7 +1380,7 @@ bool FMouseControl::isRightButtonReleased()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isMiddleButtonPressed() bool FMouseControl::isMiddleButtonPressed()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isMiddleButtonPressed(); return mouse_object->isMiddleButtonPressed();
@ -1391,7 +1391,7 @@ bool FMouseControl::isMiddleButtonPressed()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isMiddleButtonReleased() bool FMouseControl::isMiddleButtonReleased()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isMiddleButtonReleased(); return mouse_object->isMiddleButtonReleased();
@ -1402,7 +1402,7 @@ bool FMouseControl::isMiddleButtonReleased()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isShiftKeyPressed() bool FMouseControl::isShiftKeyPressed()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isShiftKeyPressed(); return mouse_object->isShiftKeyPressed();
@ -1413,7 +1413,7 @@ bool FMouseControl::isShiftKeyPressed()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isControlKeyPressed() bool FMouseControl::isControlKeyPressed()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isControlKeyPressed(); return mouse_object->isControlKeyPressed();
@ -1424,7 +1424,7 @@ bool FMouseControl::isControlKeyPressed()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isMetaKeyPressed() bool FMouseControl::isMetaKeyPressed()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isMetaKeyPressed(); return mouse_object->isMetaKeyPressed();
@ -1435,7 +1435,7 @@ bool FMouseControl::isMetaKeyPressed()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isWheelUp() bool FMouseControl::isWheelUp()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isWheelUp(); return mouse_object->isWheelUp();
@ -1446,7 +1446,7 @@ bool FMouseControl::isWheelUp()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isWheelDown() bool FMouseControl::isWheelDown()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isWheelDown(); return mouse_object->isWheelDown();
@ -1457,7 +1457,7 @@ bool FMouseControl::isWheelDown()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMouseControl::isMoved() bool FMouseControl::isMoved()
{ {
auto mouse_object = getMouseWithEvent(); const auto& mouse_object = getMouseWithEvent();
if ( mouse_object ) if ( mouse_object )
return mouse_object->isMoved(); return mouse_object->isMoved();
@ -1485,8 +1485,8 @@ bool FMouseControl::isGpmMouseEnabled()
if ( mouse_protocol.empty() ) if ( mouse_protocol.empty() )
return false; return false;
auto mouse = mouse_protocol[FMouse::gpm]; const auto& mouse = mouse_protocol[FMouse::gpm];
auto gpm_mouse = static_cast<FMouseGPM*>(mouse); const auto& gpm_mouse = static_cast<FMouseGPM*>(mouse);
if ( gpm_mouse ) if ( gpm_mouse )
return gpm_mouse->isGpmMouseEnabled(); return gpm_mouse->isGpmMouseEnabled();

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -183,7 +183,6 @@ void FObject::setParent (FObject* parent)
return; return;
removeParent(); removeParent();
parent_obj = parent; parent_obj = parent;
has_parent = true; has_parent = true;
parent->children_list.push_back(this); parent->children_list.push_back(this);
@ -256,7 +255,7 @@ bool FObject::isTimeout (timeval* time, uInt64 timeout)
diff.tv_usec += 1000000; diff.tv_usec += 1000000;
} }
uInt64 diff_usec = uInt64((diff.tv_sec * 1000000) + diff.tv_usec); const uInt64 diff_usec = uInt64((diff.tv_sec * 1000000) + diff.tv_usec);
return ( diff_usec > timeout ); return ( diff_usec > timeout );
} }
@ -275,7 +274,7 @@ int FObject::addTimer (int interval)
if ( ! timer_list->empty() ) if ( ! timer_list->empty() )
{ {
auto iter = timer_list->begin(); auto iter = timer_list->begin();
auto last = timer_list->end(); const auto& last = timer_list->end();
while ( iter != last ) while ( iter != last )
{ {
@ -300,14 +299,13 @@ int FObject::addTimer (int interval)
// insert in list sorted by timeout // insert in list sorted by timeout
auto iter = timer_list->begin(); auto iter = timer_list->begin();
auto last = timer_list->end(); const auto& last = timer_list->end();
while ( iter != last && iter->timeout < t.timeout ) while ( iter != last && iter->timeout < t.timeout )
++iter; ++iter;
timer_list->insert (iter, t); timer_list->insert (iter, t);
timer_modify_lock = false; timer_modify_lock = false;
return id; return id;
} }
@ -321,7 +319,7 @@ bool FObject::delTimer (int id)
timer_modify_lock = true; timer_modify_lock = true;
auto iter = timer_list->begin(); auto iter = timer_list->begin();
auto last = timer_list->end(); const auto& last = timer_list->end();
while ( iter != last && iter->id != id ) while ( iter != last && iter->id != id )
++iter; ++iter;

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -1458,7 +1458,7 @@ inline void FOptiAttr::change_to_default_color ( FChar*& term
else if ( bg == fc::Default && term->bg_color != fc::Default ) else if ( bg == fc::Default && term->bg_color != fc::Default )
{ {
char* sgr_49; char* sgr_49;
auto& op = F_orig_pair.cap; const auto& op = F_orig_pair.cap;
if ( op && std::strncmp (op, CSI "39;49;25m", 11) == 0 ) if ( op && std::strncmp (op, CSI "39;49;25m", 11) == 0 )
sgr_49 = C_STR(CSI "49;25m"); sgr_49 = C_STR(CSI "49;25m");
@ -1482,20 +1482,20 @@ inline void FOptiAttr::change_current_color ( FChar*& term
, FColor fg, FColor bg ) , FColor fg, FColor bg )
{ {
char* color_str{}; char* color_str{};
auto& AF = F_set_a_foreground.cap; const auto& AF = F_set_a_foreground.cap;
auto& AB = F_set_a_background.cap; const auto& AB = F_set_a_background.cap;
auto& Sf = F_set_foreground.cap; const auto& Sf = F_set_foreground.cap;
auto& Sb = F_set_background.cap; const auto& Sb = F_set_background.cap;
auto& sp = F_set_color_pair.cap; const auto& sp = F_set_color_pair.cap;
bool frev ( ( off.attr.bit.reverse const bool frev ( ( off.attr.bit.reverse
|| off.attr.bit.standout || off.attr.bit.standout
|| term->attr.bit.reverse || term->attr.bit.reverse
|| term->attr.bit.standout ) && fake_reverse ); || term->attr.bit.standout ) && fake_reverse );
if ( AF && AB ) if ( AF && AB )
{ {
auto ansi_fg = vga2ansi(fg); const auto ansi_fg = vga2ansi(fg);
auto ansi_bg = vga2ansi(bg); const auto ansi_bg = vga2ansi(bg);
if ( (term->fg_color != fg || frev) if ( (term->fg_color != fg || frev)
&& (color_str = tparm(AF, ansi_fg, 0, 0, 0, 0, 0, 0, 0, 0)) ) && (color_str = tparm(AF, ansi_fg, 0, 0, 0, 0, 0, 0, 0, 0)) )
@ -1552,9 +1552,9 @@ bool FOptiAttr::caused_reset_attributes (char cap[], uChar test)
if ( cap ) if ( cap )
{ {
auto& ue = F_exit_underline_mode.cap; const auto& ue = F_exit_underline_mode.cap;
auto& se = F_exit_standout_mode.cap; const auto& se = F_exit_standout_mode.cap;
auto& me = F_exit_attribute_mode.cap; const auto& me = F_exit_attribute_mode.cap;
if ( (test & test_ansi_reset) && std::strncmp (cap, CSI "m", 3) == 0 ) if ( (test & test_ansi_reset) && std::strncmp (cap, CSI "m", 3) == 0 )
return true; return true;
@ -1582,10 +1582,10 @@ inline bool FOptiAttr::hasCharsetEquivalence()
{ {
// Detect if alt charset and pc charset are the same sequences // Detect if alt charset and pc charset are the same sequences
auto& alt_on = F_enter_alt_charset_mode.cap; const auto& alt_on = F_enter_alt_charset_mode.cap;
auto& alt_off = F_enter_pc_charset_mode.cap; const auto& alt_off = F_enter_pc_charset_mode.cap;
auto& pc_on = F_enter_pc_charset_mode.cap; const auto& pc_on = F_enter_pc_charset_mode.cap;
auto& pc_off = F_exit_pc_charset_mode.cap; const auto& pc_off = F_exit_pc_charset_mode.cap;
if ( alt_on && pc_on && std::strcmp (alt_on, pc_on) == 0 ) if ( alt_on && pc_on && std::strcmp (alt_on, pc_on) == 0 )
return true; return true;

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -600,8 +600,8 @@ int FOptiMove::repeatedAppend ( const capability& o
, volatile int count , volatile int count
, char* dst ) , char* dst )
{ {
std::size_t src_len = std::strlen(o.cap); const std::size_t src_len = std::strlen(o.cap);
std::size_t dst_len = ( dst != nullptr ) ? std::strlen(dst) : 0; const std::size_t dst_len = ( dst != nullptr ) ? std::strlen(dst) : 0;
int total{0}; int total{0};
if ( (dst_len + uInt(count) * src_len) < BUF_SIZE - 1 ) if ( (dst_len + uInt(count) * src_len) < BUF_SIZE - 1 )
@ -698,7 +698,7 @@ inline int FOptiMove::verticalMove (char move[], int from_y, int to_y)
inline void FOptiMove::downMove ( char move[], int& vtime inline void FOptiMove::downMove ( char move[], int& vtime
, int from_y, int to_y ) , int from_y, int to_y )
{ {
int num = to_y - from_y; const int num = to_y - from_y;
if ( F_parm_down_cursor.cap && F_parm_down_cursor.duration < vtime ) if ( F_parm_down_cursor.cap && F_parm_down_cursor.duration < vtime )
{ {
@ -726,7 +726,7 @@ inline void FOptiMove::downMove ( char move[], int& vtime
inline void FOptiMove::upMove ( char move[], int& vtime inline void FOptiMove::upMove ( char move[], int& vtime
, int from_y, int to_y ) , int from_y, int to_y )
{ {
int num = from_y - to_y; const int num = from_y - to_y;
if ( F_parm_up_cursor.cap && F_parm_up_cursor.duration < vtime ) if ( F_parm_up_cursor.cap && F_parm_up_cursor.duration < vtime )
{ {
@ -801,7 +801,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime
while ( true ) while ( true )
{ {
int tab_pos = pos + tabstop - (pos % tabstop); const int tab_pos = pos + tabstop - (pos % tabstop);
if ( tab_pos > to_x ) if ( tab_pos > to_x )
break; break;
@ -856,7 +856,7 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime
while ( true ) while ( true )
{ {
int tab_pos = ( pos > 0 ) ? ((pos - 1) / tabstop) * tabstop : -1; const int tab_pos = ( pos > 0 ) ? ((pos - 1) / tabstop) * tabstop : -1;
if ( tab_pos < to_x ) if ( tab_pos < to_x )
break; break;
@ -898,7 +898,7 @@ inline bool FOptiMove::isMethod0Faster ( int& move_time
, int xnew, int ynew ) , int xnew, int ynew )
{ {
// Test method 0: direct cursor addressing // Test method 0: direct cursor addressing
char* move_xy = tgoto(F_cursor_address.cap, xnew, ynew); const char* move_xy = tgoto(F_cursor_address.cap, xnew, ynew);
if ( move_xy ) if ( move_xy )
{ {
@ -922,7 +922,7 @@ inline bool FOptiMove::isMethod1Faster ( int& move_time
if ( xold >= 0 && yold >= 0 ) if ( xold >= 0 && yold >= 0 )
{ {
char null_result[BUF_SIZE]; char null_result[BUF_SIZE];
int new_time = relativeMove (null_result, xold, yold, xnew, ynew); const int new_time = relativeMove (null_result, xold, yold, xnew, ynew);
if ( new_time < LONG_DURATION && new_time < move_time ) if ( new_time < LONG_DURATION && new_time < move_time )
{ {
@ -944,7 +944,7 @@ inline bool FOptiMove::isMethod2Faster ( int& move_time
if ( yold >= 0 && F_carriage_return.cap ) if ( yold >= 0 && F_carriage_return.cap )
{ {
char null_result[BUF_SIZE]; char null_result[BUF_SIZE];
int new_time = relativeMove (null_result, 0, yold, xnew, ynew); const int new_time = relativeMove (null_result, 0, yold, xnew, ynew);
if ( new_time < LONG_DURATION if ( new_time < LONG_DURATION
&& F_carriage_return.duration + new_time < move_time ) && F_carriage_return.duration + new_time < move_time )
@ -966,7 +966,7 @@ inline bool FOptiMove::isMethod3Faster ( int& move_time
if ( F_cursor_home.cap ) if ( F_cursor_home.cap )
{ {
char null_result[BUF_SIZE]; char null_result[BUF_SIZE];
int new_time = relativeMove (null_result, 0, 0, xnew, ynew); const int new_time = relativeMove (null_result, 0, 0, xnew, ynew);
if ( new_time < LONG_DURATION if ( new_time < LONG_DURATION
&& F_cursor_home.duration + new_time < move_time ) && F_cursor_home.duration + new_time < move_time )
@ -987,9 +987,9 @@ inline bool FOptiMove::isMethod4Faster ( int& move_time
if ( F_cursor_to_ll.cap ) if ( F_cursor_to_ll.cap )
{ {
char null_result[BUF_SIZE]; char null_result[BUF_SIZE];
int new_time = relativeMove ( null_result const int new_time = relativeMove ( null_result
, 0, int(screen_height) - 1 , 0, int(screen_height) - 1
, xnew, ynew ); , xnew, ynew );
if ( new_time < LONG_DURATION if ( new_time < LONG_DURATION
&& F_cursor_to_ll.duration + new_time < move_time ) && F_cursor_to_ll.duration + new_time < move_time )
@ -1014,9 +1014,9 @@ inline bool FOptiMove::isMethod5Faster ( int& move_time
&& F_cursor_left.cap ) && F_cursor_left.cap )
{ {
char null_result[BUF_SIZE]; char null_result[BUF_SIZE];
int new_time = relativeMove ( null_result const int new_time = relativeMove ( null_result
, int(screen_width) - 1, yold - 1 , int(screen_width) - 1, yold - 1
, xnew, ynew ); , xnew, ynew );
if ( new_time < LONG_DURATION if ( new_time < LONG_DURATION
&& F_carriage_return.cap && F_carriage_return.cap

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -111,7 +111,7 @@ bool FProgressbar::setShadow (bool enable)
void FProgressbar::hide() void FProgressbar::hide()
{ {
FWidget::hide(); FWidget::hide();
FSize shadow = hasShadow() ? FSize(1, 1) : FSize(0, 0); const FSize shadow = hasShadow() ? FSize(1, 1) : FSize(0, 0);
hideArea (getSize() + shadow); hideArea (getSize() + shadow);
print() << FPoint(int(getWidth()) - 4, 0) print() << FPoint(int(getWidth()) - 4, 0)
<< (" "); // hide percentage << (" "); // hide percentage
@ -148,7 +148,7 @@ void FProgressbar::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FProgressbar::drawProgressLabel() void FProgressbar::drawProgressLabel()
{ {
auto parent_widget = getParentWidget(); const auto& parent_widget = getParentWidget();
if ( parent_widget ) if ( parent_widget )
setColor ( parent_widget->getForegroundColor() setColor ( parent_widget->getForegroundColor()
@ -156,7 +156,7 @@ void FProgressbar::drawProgressLabel()
else else
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setColor ( wc.dialog_fg, wc.dialog_bg ); setColor (wc.dialog_fg, wc.dialog_bg);
} }
if ( isMonochron() ) if ( isMonochron() )
@ -199,9 +199,9 @@ std::size_t FProgressbar::drawProgressIndicator()
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
double length = double(bar_length * percentage) / 100;
auto len = std::size_t(trunc(length));
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
const double length = double(bar_length * percentage) / 100;
auto len = std::size_t(trunc(length));
print() << FColorPair (wc.progressbar_fg, wc.progressbar_fg) print() << FColorPair (wc.progressbar_fg, wc.progressbar_fg)
<< FString (len, fc::FullBlock); // █ << FString (len, fc::FullBlock); // █
@ -233,7 +233,7 @@ void FProgressbar::drawProgressBackground (std::size_t len)
{ {
// Draw the progress background // Draw the progress background
std::size_t bg_len = bar_length - len; const std::size_t bg_len = bar_length - len;
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setColor (wc.progressbar_fg, wc.progressbar_bg); setColor (wc.progressbar_fg, wc.progressbar_bg);

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -123,7 +123,7 @@ void FRect::setY2 (int n)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FRect::setX (int n) void FRect::setX (int n)
{ {
int dX = X2 - X1; const int dX = X2 - X1;
X1 = n; X1 = n;
X2 = X1 + dX; X2 = X1 + dX;
} }
@ -131,7 +131,7 @@ void FRect::setX (int n)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FRect::setY (int n) void FRect::setY (int n)
{ {
int dY = Y2 - Y1; const int dY = Y2 - Y1;
Y1 = n; Y1 = n;
Y2 = Y1 + dY; Y2 = Y1 + dY;
} }
@ -139,8 +139,8 @@ void FRect::setY (int n)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FRect::setPos (int x, int y) void FRect::setPos (int x, int y)
{ {
int dX = X2 - X1; const int dX = X2 - X1;
int dY = Y2 - Y1; const int dY = Y2 - Y1;
X1 = x; X1 = x;
Y1 = y; Y1 = y;
X2 = X1 + dX; X2 = X1 + dX;
@ -150,8 +150,8 @@ void FRect::setPos (int x, int y)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FRect::setPos (const FPoint& p) void FRect::setPos (const FPoint& p)
{ {
int dX = X2 - X1; const int dX = X2 - X1;
int dY = Y2 - Y1; const int dY = Y2 - Y1;
X1 = p.getX(); X1 = p.getX();
Y1 = p.getY(); Y1 = p.getY();
X2 = X1 + dX; X2 = X1 + dX;

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 2012-2019 Markus Gans * * Copyright 2012-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -208,7 +208,7 @@ void FScrollbar::calculateSliderValues()
return; return;
} }
std::size_t v = ( min < 0 ) ? std::size_t(val - min) : std::size_t(val); const std::size_t v = ( min < 0 ) ? std::size_t(val - min) : std::size_t(val);
if ( slider_length >= bar_length ) if ( slider_length >= bar_length )
slider_pos = 0; slider_pos = 0;
@ -249,8 +249,8 @@ void FScrollbar::onMouseDown (FMouseEvent* ev)
if ( min == max ) if ( min == max )
return; return;
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( ev->getButton() == fc::MiddleButton ) if ( ev->getButton() == fc::MiddleButton )
{ {
@ -317,8 +317,8 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
&& ev->getButton() != fc::MiddleButton ) && ev->getButton() != fc::MiddleButton )
return; return;
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( ev->getButton() == fc::MiddleButton ) if ( ev->getButton() == fc::MiddleButton )
{ {
@ -327,7 +327,7 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
} }
// Process left mouse button // Process left mouse button
int new_scroll_type = getClickedScrollType(mouse_x, mouse_y); const int new_scroll_type = getClickedScrollType(mouse_x, mouse_y);
if ( scroll_type == FScrollbar::scrollJump ) if ( scroll_type == FScrollbar::scrollJump )
{ {
@ -335,14 +335,14 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
if ( bar_orientation == fc::vertical ) if ( bar_orientation == fc::vertical )
{ {
int dy = mouse_y - slider_click_pos; const int dy = mouse_y - slider_click_pos;
slider_click_pos = mouse_y; slider_click_pos = mouse_y;
new_val = int( round ( double((max - min) * (slider_pos + dy)) new_val = int( round ( double((max - min) * (slider_pos + dy))
/ double(bar_length - slider_length) ) ); / double(bar_length - slider_length) ) );
} }
else // horizontal else // horizontal
{ {
int dx = mouse_x - slider_click_pos; const int dx = mouse_x - slider_click_pos;
slider_click_pos = mouse_x; slider_click_pos = mouse_x;
new_val = int( round ( double((max - min) * (slider_pos + dx)) new_val = int( round ( double((max - min) * (slider_pos + dx))
/ double(bar_length - slider_length) ) ); / double(bar_length - slider_length) ) );
@ -376,7 +376,7 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollbar::onWheel (FWheelEvent* ev) void FScrollbar::onWheel (FWheelEvent* ev)
{ {
int wheel = ev->getWheel(); const int wheel = ev->getWheel();
if ( scroll_type != FScrollbar::noScroll ) if ( scroll_type != FScrollbar::noScroll )
{ {
@ -411,7 +411,7 @@ void FScrollbar::onTimer (FTimerEvent*)
|| ( scroll_type == FScrollbar::scrollPageForward || ( scroll_type == FScrollbar::scrollPageForward
&& slider_pos == slider_click_stop_pos ) ) && slider_pos == slider_click_stop_pos ) )
{ {
int max_slider_pos = int(bar_length - slider_length); const int max_slider_pos = int(bar_length - slider_length);
if ( scroll_type == FScrollbar::scrollPageBackward if ( scroll_type == FScrollbar::scrollPageBackward
&& slider_pos == 0 ) && slider_pos == 0 )
@ -449,7 +449,9 @@ void FScrollbar::draw()
if ( length < 2 ) if ( length < 2 )
return; return;
drawButtons(); if ( isShown() )
drawButtons();
current_slider_pos = -1; current_slider_pos = -1;
drawBar(); drawBar();
} }
@ -739,7 +741,7 @@ void FScrollbar::jumpToClickPos (int x, int y)
} }
else // horizontal else // horizontal
{ {
int nf = isNewFont() ? 1 : 0; const int nf = isNewFont() ? 1 : 0;
if ( x > 1 + nf && x < int(getWidth()) - nf ) if ( x > 1 + nf && x < int(getWidth()) - nf )
{ {
@ -799,8 +801,8 @@ void FScrollbar::processScroll()
void FScrollbar::changeOnResize() void FScrollbar::changeOnResize()
{ {
const FSize& size = getSize(); const FSize& size = getSize();
std::size_t w = size.getWidth(); const std::size_t w = size.getWidth();
std::size_t h = size.getHeight(); const std::size_t h = size.getHeight();
length = ( bar_orientation == fc::vertical ) ? h : w; length = ( bar_orientation == fc::vertical ) ? h : w;
if ( bar_orientation == fc::vertical ) if ( bar_orientation == fc::vertical )

View File

@ -4,7 +4,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -64,7 +64,7 @@ void FScrollView::setScrollWidth (std::size_t width)
if ( viewport ) if ( viewport )
{ {
FSize no_shadow(0, 0); const FSize no_shadow(0, 0);
scroll_geometry.setWidth (width); scroll_geometry.setWidth (width);
resizeArea (scroll_geometry, no_shadow, viewport); resizeArea (scroll_geometry, no_shadow, viewport);
@ -94,7 +94,7 @@ void FScrollView::setScrollHeight (std::size_t height)
if ( viewport ) if ( viewport )
{ {
FSize no_shadow(0, 0); const FSize no_shadow(0, 0);
scroll_geometry.setHeight (height); scroll_geometry.setHeight (height);
resizeArea (scroll_geometry, no_shadow, viewport); resizeArea (scroll_geometry, no_shadow, viewport);
addPreprocessingHandler addPreprocessingHandler
@ -129,7 +129,7 @@ void FScrollView::setScrollSize (const FSize& size)
if ( viewport ) if ( viewport )
{ {
FSize no_shadow(0, 0); const FSize no_shadow(0, 0);
scroll_geometry.setSize (width, height); scroll_geometry.setSize (width, height);
resizeArea (scroll_geometry, no_shadow, viewport); resizeArea (scroll_geometry, no_shadow, viewport);
addPreprocessingHandler addPreprocessingHandler
@ -139,8 +139,8 @@ void FScrollView::setScrollSize (const FSize& size)
setChildPrintArea (viewport); setChildPrintArea (viewport);
} }
int xoffset_end = int(getScrollWidth() - getViewportWidth()); const int xoffset_end = int(getScrollWidth() - getViewportWidth());
int yoffset_end = int(getScrollHeight() - getViewportHeight()); const int yoffset_end = int(getScrollHeight() - getViewportHeight());
setTopPadding (1 - getScrollY()); setTopPadding (1 - getScrollY());
setLeftPadding (1 - getScrollX()); setLeftPadding (1 - getScrollX());
setBottomPadding (1 - (yoffset_end - getScrollY())); setBottomPadding (1 - (yoffset_end - getScrollY()));
@ -237,8 +237,8 @@ void FScrollView::setHeight (std::size_t h, bool adjust)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::setSize (const FSize& size, bool adjust) void FScrollView::setSize (const FSize& size, bool adjust)
{ {
std::size_t w = size.getWidth(); const std::size_t w = size.getWidth();
std::size_t h = size.getHeight(); const std::size_t h = size.getHeight();
FWidget::setSize (size, adjust); FWidget::setSize (size, adjust);
viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset
, h - horizontal_border_spacing ); , h - horizontal_border_spacing );
@ -256,8 +256,8 @@ void FScrollView::setGeometry ( const FPoint& pos, const FSize& size
// Set the scroll view geometry // Set the scroll view geometry
FWidget::setGeometry (pos, size, adjust); FWidget::setGeometry (pos, size, adjust);
std::size_t w = size.getWidth(); const std::size_t w = size.getWidth();
std::size_t h = size.getHeight(); const std::size_t h = size.getHeight();
scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1 scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1
, getTermY() + getTopPadding() - 1 ); , getTermY() + getTopPadding() - 1 );
viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset
@ -344,14 +344,12 @@ void FScrollView::scrollTo (int x, int y)
{ {
int& xoffset = viewport_geometry.x1_ref(); int& xoffset = viewport_geometry.x1_ref();
int& yoffset = viewport_geometry.y1_ref(); int& yoffset = viewport_geometry.y1_ref();
int xoffset_before = xoffset; const int xoffset_before = xoffset;
int yoffset_before = yoffset; const int yoffset_before = yoffset;
int xoffset_end = int(getScrollWidth() - getViewportWidth()); const int xoffset_end = int(getScrollWidth() - getViewportWidth());
int yoffset_end = int(getScrollHeight() - getViewportHeight()); const int yoffset_end = int(getScrollHeight() - getViewportHeight());
std::size_t save_width = viewport_geometry.getWidth(); const std::size_t save_width = viewport_geometry.getWidth();
std::size_t save_height = viewport_geometry.getHeight(); const std::size_t save_height = viewport_geometry.getHeight();
bool changeX{false};
bool changeY{false};
x--; x--;
y--; y--;
@ -373,8 +371,8 @@ void FScrollView::scrollTo (int x, int y)
if ( xoffset > xoffset_end ) if ( xoffset > xoffset_end )
xoffset = xoffset_end; xoffset = xoffset_end;
changeX = bool( xoffset_before != xoffset ); const bool changeX( xoffset_before != xoffset );
changeY = bool( yoffset_before != yoffset ); const bool changeY( yoffset_before != yoffset );
if ( ! isShown() || ! viewport || ! (changeX || changeY) ) if ( ! isShown() || ! viewport || ! (changeX || changeY) )
return; return;
@ -424,7 +422,7 @@ void FScrollView::draw()
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
if ( auto p = getParentWidget() ) if ( const auto& p = getParentWidget() )
setColor (p->getForegroundColor(), p->getBackgroundColor()); setColor (p->getForegroundColor(), p->getBackgroundColor());
else else
setColor(); setColor();
@ -451,14 +449,14 @@ void FScrollView::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::drawBorder() void FScrollView::drawBorder()
{ {
FRect box(FPoint(1, 1), getSize()); const FRect box(FPoint(1, 1), getSize());
finalcut::drawListBorder (this, box); finalcut::drawListBorder (this, box);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::onKeyPress (FKeyEvent* ev) void FScrollView::onKeyPress (FKeyEvent* ev)
{ {
int idx = int(ev->key()); const int idx = int(ev->key());
if ( key_map.find(idx) != key_map.end() ) if ( key_map.find(idx) != key_map.end() )
{ {
@ -470,7 +468,7 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::onWheel (FWheelEvent* ev) void FScrollView::onWheel (FWheelEvent* ev)
{ {
int distance{4}; static constexpr int distance = 4;
switch ( ev->getWheel() ) switch ( ev->getWheel() )
{ {
@ -517,25 +515,23 @@ void FScrollView::onChildFocusIn (FFocusEvent*)
{ {
// Scrolls the viewport so that the focused widget is visible // Scrolls the viewport so that the focused widget is visible
FRect widget_geometry; const auto& focus = FWidget::getFocusWidget();
FRect vp_geometry;
auto focus = FWidget::getFocusWidget();
if ( ! focus ) if ( ! focus )
return; return;
widget_geometry = focus->getGeometryWithShadow(); const FRect widget_geometry = focus->getGeometryWithShadow();
vp_geometry = viewport_geometry; FRect vp_geometry = viewport_geometry;
vp_geometry.move(1, 1); vp_geometry.move(1, 1);
if ( ! vp_geometry.contains(widget_geometry) ) if ( ! vp_geometry.contains(widget_geometry) )
{ {
int x{} int x{};
, y{} int y{};
, vx = vp_geometry.getX() const int vx = vp_geometry.getX();
, vy = vp_geometry.getY() const int vy = vp_geometry.getY();
, wx = widget_geometry.getX() const int wx = widget_geometry.getX();
, wy = widget_geometry.getY(); const int wy = widget_geometry.getY();
if ( wx > vx ) if ( wx > vx )
x = widget_geometry.getX2() - int(vp_geometry.getWidth()) + 1; x = widget_geometry.getX2() - int(vp_geometry.getWidth()) + 1;
@ -556,11 +552,11 @@ void FScrollView::onChildFocusOut (FFocusEvent* out_ev)
{ {
// Change the focus away from FScrollView to another widget // Change the focus away from FScrollView to another widget
auto focus = FWidget::getFocusWidget(); const auto& focus = FWidget::getFocusWidget();
if ( out_ev->getFocusType() == fc::FocusNextWidget ) if ( out_ev->getFocusType() == fc::FocusNextWidget )
{ {
auto last_widget = getLastFocusableWidget(getChildren()); const auto& last_widget = getLastFocusableWidget(getChildren());
if ( focus == last_widget ) if ( focus == last_widget )
{ {
@ -570,7 +566,7 @@ void FScrollView::onChildFocusOut (FFocusEvent* out_ev)
} }
else if ( out_ev->getFocusType() == fc::FocusPreviousWidget ) else if ( out_ev->getFocusType() == fc::FocusPreviousWidget )
{ {
auto first_widget = getFirstFocusableWidget(getChildren()); const auto& first_widget = getFirstFocusableWidget(getChildren());
if ( focus == first_widget ) if ( focus == first_widget )
{ {
@ -602,10 +598,10 @@ FVTerm::FTermArea* FScrollView::getPrintArea()
void FScrollView::adjustSize() void FScrollView::adjustSize()
{ {
FWidget::adjustSize(); FWidget::adjustSize();
std::size_t width = getWidth(); const std::size_t width = getWidth();
std::size_t height = getHeight(); const std::size_t height = getHeight();
int xoffset = viewport_geometry.getX(); const int xoffset = viewport_geometry.getX();
int yoffset = viewport_geometry.getY(); const int yoffset = viewport_geometry.getY();
scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1 scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1
, getTermY() + getTopPadding() - 1 ); , getTermY() + getTopPadding() - 1 );
@ -652,12 +648,12 @@ void FScrollView::copy2area()
return; return;
auto printarea = getCurrentPrintArea(); auto printarea = getCurrentPrintArea();
int ax = getTermX() - printarea->offset_left const int ax = getTermX() - printarea->offset_left;
, ay = getTermY() - printarea->offset_top const int ay = getTermY() - printarea->offset_top;
, dx = viewport_geometry.getX() const int dx = viewport_geometry.getX();
, dy = viewport_geometry.getY() const int dy = viewport_geometry.getY();
, y_end = int(getViewportHeight()) int y_end = int(getViewportHeight());
, x_end = int(getViewportWidth()); int x_end = int(getViewportWidth());
// viewport width does not fit into the printarea // viewport width does not fit into the printarea
if ( printarea->width <= ax + x_end ) if ( printarea->width <= ax + x_end )
@ -671,8 +667,8 @@ void FScrollView::copy2area()
{ {
FChar* vc{}; // viewport character FChar* vc{}; // viewport character
FChar* ac{}; // area character FChar* ac{}; // area character
int v_line_len = viewport->width; const int v_line_len = viewport->width;
int a_line_len = printarea->width + printarea->right_shadow; const int a_line_len = printarea->width + printarea->right_shadow;
vc = &viewport->data[(dy + y) * v_line_len + dx]; vc = &viewport->data[(dy + y) * v_line_len + dx];
ac = &printarea->data[(ay + y) * a_line_len + ax]; ac = &printarea->data[(ay + y) * a_line_len + ax];
std::memcpy (ac, vc, sizeof(FChar) * unsigned(x_end)); std::memcpy (ac, vc, sizeof(FChar) * unsigned(x_end));
@ -694,16 +690,16 @@ void FScrollView::copy2area()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FPoint FScrollView::getViewportCursorPos() inline FPoint FScrollView::getViewportCursorPos()
{ {
auto window = FWindow::getWindowWidget(this); const auto& window = FWindow::getWindowWidget(this);
if ( window ) if ( window )
{ {
int widget_offsetX = getTermX() - window->getTermX() const int widget_offsetX = getTermX() - window->getTermX();
, widget_offsetY = getTermY() - window->getTermY() const int widget_offsetY = getTermY() - window->getTermY();
, x = widget_offsetX + viewport->input_cursor_x const int x = widget_offsetX + viewport->input_cursor_x
- viewport_geometry.getX() - viewport_geometry.getX();
, y = widget_offsetY + viewport->input_cursor_y const int y = widget_offsetY + viewport->input_cursor_y
- viewport_geometry.getY(); - viewport_geometry.getY();
return FPoint (x, y); return FPoint (x, y);
} }
else else
@ -724,14 +720,14 @@ void FScrollView::init (FWidget* parent)
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
setGeometry (FPoint(1, 1), FSize(4, 4)); setGeometry (FPoint(1, 1), FSize(4, 4));
setMinimumSize (FSize(4, 4)); setMinimumSize (FSize(4, 4));
int xoffset_end = int(getScrollWidth() - getViewportWidth()); const int xoffset_end = int(getScrollWidth() - getViewportWidth());
int yoffset_end = int(getScrollHeight() - getViewportHeight()); const int yoffset_end = int(getScrollHeight() - getViewportHeight());
nf_offset = isNewFont() ? 1 : 0; nf_offset = isNewFont() ? 1 : 0;
setTopPadding (1 - getScrollY()); setTopPadding (1 - getScrollY());
setLeftPadding (1 - getScrollX()); setLeftPadding (1 - getScrollX());
setBottomPadding (1 - (yoffset_end - getScrollY())); setBottomPadding (1 - (yoffset_end - getScrollY()));
setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset); setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset);
FSize no_shadow(0, 0); const FSize no_shadow(0, 0);
std::size_t w = getViewportWidth(); std::size_t w = getViewportWidth();
std::size_t h = getViewportHeight(); std::size_t h = getViewportHeight();
@ -773,8 +769,8 @@ inline void FScrollView::mapKeyFunctions()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::calculateScrollbarPos() void FScrollView::calculateScrollbarPos()
{ {
std::size_t width = getWidth(); const std::size_t width = getWidth();
std::size_t height = getHeight(); const std::size_t height = getHeight();
if ( isNewFont() ) if ( isNewFont() )
{ {
@ -841,9 +837,9 @@ void FScrollView::setViewportCursor()
if ( ! isChild(getFocusWidget()) ) if ( ! isChild(getFocusWidget()) )
return; return;
FPoint cursor_pos ( viewport->input_cursor_x - 1 const FPoint cursor_pos ( viewport->input_cursor_x - 1
, viewport->input_cursor_y - 1 ); , viewport->input_cursor_y - 1 );
FPoint window_cursor_pos(getViewportCursorPos()); const FPoint window_cursor_pos(getViewportCursorPos());
auto printarea = getCurrentPrintArea(); auto printarea = getCurrentPrintArea();
printarea->input_cursor_x = window_cursor_pos.getX(); printarea->input_cursor_x = window_cursor_pos.getX();
printarea->input_cursor_y = window_cursor_pos.getY(); printarea->input_cursor_y = window_cursor_pos.getY();
@ -859,8 +855,8 @@ void FScrollView::setViewportCursor()
void FScrollView::cb_VBarChange (FWidget*, FDataPtr) void FScrollView::cb_VBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType = vbar->getScrollType(); FScrollbar::sType scrollType = vbar->getScrollType();
static constexpr int wheel_distance = 4;
int distance{1}; int distance{1};
int wheel_distance{4};
if ( scrollType >= FScrollbar::scrollStepBackward ) if ( scrollType >= FScrollbar::scrollStepBackward )
{ {
@ -910,8 +906,8 @@ void FScrollView::cb_VBarChange (FWidget*, FDataPtr)
void FScrollView::cb_HBarChange (FWidget*, FDataPtr) void FScrollView::cb_HBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType = hbar->getScrollType(); FScrollbar::sType scrollType = hbar->getScrollType();
static constexpr int wheel_distance = 4;
int distance{1}; int distance{1};
int wheel_distance{4};
if ( scrollType >= FScrollbar::scrollStepBackward ) if ( scrollType >= FScrollbar::scrollStepBackward )
{ {

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 2019 Markus Gans * * Copyright 2019-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -163,7 +163,7 @@ void FSpinBox::hide()
{ {
input_field.hide(); input_field.hide();
FWidget::hide(); FWidget::hide();
FSize shadow = hasShadow() ? FSize(1, 1) : FSize(0, 0); const FSize shadow = hasShadow() ? FSize(1, 1) : FSize(0, 0);
hideArea (getSize() + shadow); hideArea (getSize() + shadow);
} }
@ -173,7 +173,7 @@ void FSpinBox::onKeyPress (FKeyEvent* ev)
if ( ! isEnabled() ) if ( ! isEnabled() )
return; return;
FKey key = ev->key(); const FKey key = ev->key();
switch ( key ) switch ( key )
{ {
@ -215,8 +215,8 @@ void FSpinBox::onMouseDown (FMouseEvent* ev)
if ( min == max ) if ( min == max )
return; return;
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x == int(getWidth()) - 1 && mouse_y == 1 ) if ( mouse_x == int(getWidth()) - 1 && mouse_y == 1 )
{ {
@ -248,7 +248,7 @@ void FSpinBox::onMouseUp (FMouseEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FSpinBox::onWheel (FWheelEvent* ev) void FSpinBox::onWheel (FWheelEvent* ev)
{ {
int wheel = ev->getWheel(); const int wheel = ev->getWheel();
delOwnTimer(); delOwnTimer();
forceFocus(); forceFocus();
@ -324,7 +324,7 @@ void FSpinBox::draw()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
FColorPair inc_button_color = [&] () -> FColorPair const FColorPair inc_button_color = [&] () -> FColorPair
{ {
if ( value == max ) if ( value == max )
return FColorPair ( wc.scrollbar_button_inactive_fg return FColorPair ( wc.scrollbar_button_inactive_fg
@ -334,7 +334,7 @@ void FSpinBox::draw()
, wc.scrollbar_button_bg ); , wc.scrollbar_button_bg );
}(); }();
FColorPair dec_button_color = [&] () -> FColorPair const FColorPair dec_button_color = [&] () -> FColorPair
{ {
if ( value == min ) if ( value == min )
return FColorPair ( wc.scrollbar_button_inactive_fg return FColorPair ( wc.scrollbar_button_inactive_fg
@ -415,7 +415,7 @@ void FSpinBox::forceFocus()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FSpinBox::cb_inputFieldChange (finalcut::FWidget* w, FDataPtr) void FSpinBox::cb_inputFieldChange (finalcut::FWidget* w, FDataPtr)
{ {
auto lineedit = static_cast<FLineEdit*>(w); const auto& lineedit = static_cast<FLineEdit*>(w);
if ( lineedit->getText().isEmpty() ) if ( lineedit->getText().isEmpty() )
value = 0; value = 0;
@ -427,7 +427,7 @@ void FSpinBox::cb_inputFieldChange (finalcut::FWidget* w, FDataPtr)
if ( std::regex_search(text, match, regex) ) if ( std::regex_search(text, match, regex) )
{ {
FString tmp(match[0]); const FString tmp(match[0]);
value = tmp.toLong(); value = tmp.toLong();
} }
else else

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -175,8 +175,8 @@ bool FStatusBar::hasActivatedKey()
void FStatusBar::hide() void FStatusBar::hide()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
FColor fg = wc.term_fg; const FColor fg = wc.term_fg;
FColor bg = wc.term_bg; const FColor bg = wc.term_bg;
setColor (fg, bg); setColor (fg, bg);
print() << FPoint(1, 1) << FString(getDesktopWidth(), L' '); print() << FPoint(1, 1) << FString(getDesktopWidth(), L' ');
updateTerminal(); updateTerminal();
@ -194,13 +194,13 @@ void FStatusBar::drawMessage()
x = x_msg; x = x_msg;
int space_offset{1}; int space_offset{1};
bool hasKeys( ! key_list.empty() );
bool isLastActiveFocus{false}; bool isLastActiveFocus{false};
std::size_t termWidth = getDesktopWidth(); const bool hasKeys( ! key_list.empty() );
const std::size_t termWidth = getDesktopWidth();
if ( hasKeys ) if ( hasKeys )
{ {
auto iter = key_list.end(); const auto& iter = key_list.end();
isLastActiveFocus = bool ( (*(iter - 1))->isActivated() isLastActiveFocus = bool ( (*(iter - 1))->isActivated()
|| (*(iter - 1))->hasMouseFocus() ); || (*(iter - 1))->hasMouseFocus() );
} }
@ -234,7 +234,7 @@ void FStatusBar::drawMessage()
print (' '); print (' ');
} }
auto msg_length = getColumnWidth(getMessage()); const auto msg_length = getColumnWidth(getMessage());
x += int(msg_length); x += int(msg_length);
if ( x - 1 <= int(termWidth) ) if ( x - 1 <= int(termWidth) )
@ -242,7 +242,7 @@ void FStatusBar::drawMessage()
else else
{ {
// Print ellipsis // Print ellipsis
std::size_t len = msg_length + termWidth - uInt(x) - 1; const std::size_t len = msg_length + termWidth - uInt(x) - 1;
print() << getColumnSubString ( getMessage(), 1, len) print() << getColumnSubString ( getMessage(), 1, len)
<< ".."; << "..";
} }
@ -330,7 +330,7 @@ void FStatusBar::onMouseDown (FMouseEvent* ev)
if ( ! key_list.empty() ) if ( ! key_list.empty() )
{ {
auto iter = key_list.begin(); auto iter = key_list.begin();
auto last = key_list.end(); const auto& last = key_list.end();
while ( iter != last ) while ( iter != last )
{ {
@ -352,16 +352,16 @@ void FStatusBar::onMouseDown (FMouseEvent* ev)
{ {
int X{1}; int X{1};
auto iter = key_list.begin(); auto iter = key_list.begin();
auto last = key_list.end(); const auto& last = key_list.end();
while ( iter != last ) while ( iter != last )
{ {
int x1 = X const int x1 = X;
, kname_len = getKeyNameWidth(*iter) const int kname_len = getKeyNameWidth(*iter);
, txt_length = getKeyTextWidth(*iter) const int txt_length = getKeyTextWidth(*iter);
, x2 = x1 + kname_len + txt_length + 1 const int x2 = x1 + kname_len + txt_length + 1;
, mouse_x = ev->getX() const int mouse_x = ev->getX();
, mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
@ -395,20 +395,20 @@ void FStatusBar::onMouseUp (FMouseEvent* ev)
{ {
int X{1}; int X{1};
auto iter = key_list.begin(); auto iter = key_list.begin();
auto last = key_list.end(); const auto& last = key_list.end();
while ( iter != last ) while ( iter != last )
{ {
int x1 = X const int x1 = X;
, kname_len = getKeyNameWidth(*iter) const int kname_len = getKeyNameWidth(*iter);
, txt_length = getKeyTextWidth(*iter) const int txt_length = getKeyTextWidth(*iter);
, x2 = x1 + kname_len + txt_length + 1; const int x2 = x1 + kname_len + txt_length + 1;
if ( (*iter)->hasMouseFocus() ) if ( (*iter)->hasMouseFocus() )
{ {
(*iter)->unsetMouseFocus(); (*iter)->unsetMouseFocus();
int mouse_x = ev->getX(); const int mouse_x = ev->getX();
int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 ) if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 )
(*iter)->setActive(); (*iter)->setActive();
@ -439,16 +439,16 @@ void FStatusBar::onMouseMove (FMouseEvent* ev)
bool focus_changed{false}; bool focus_changed{false};
int X{1}; int X{1};
auto iter = key_list.begin(); auto iter = key_list.begin();
auto last = key_list.end(); const auto& last = key_list.end();
while ( iter != last ) while ( iter != last )
{ {
int x1 = X const int x1 = X;
, kname_len = getKeyNameWidth(*iter) const int kname_len = getKeyNameWidth(*iter);
, txt_length = getKeyTextWidth(*iter) const int txt_length = getKeyTextWidth(*iter);
, x2 = x1 + kname_len + txt_length + 1 const int x2 = x1 + kname_len + txt_length + 1;
, mouse_x = ev->getX() const int mouse_x = ev->getX();
, mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
@ -483,9 +483,9 @@ void FStatusBar::cb_statuskey_activated (FWidget* widget, FDataPtr)
{ {
if ( ! key_list.empty() ) if ( ! key_list.empty() )
{ {
auto statuskey = static_cast<FStatusKey*>(widget); const auto& statuskey = static_cast<FStatusKey*>(widget);
auto iter = key_list.begin(); auto iter = key_list.begin();
auto last = key_list.end(); const auto& last = key_list.end();
while ( iter != last ) while ( iter != last )
{ {
@ -503,9 +503,9 @@ void FStatusBar::cb_statuskey_activated (FWidget* widget, FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStatusBar::init() void FStatusBar::init()
{ {
auto r = getRootWidget(); const auto& r = getRootWidget();
std::size_t w = r->getWidth(); const std::size_t w = r->getWidth();
int h = int(r->getHeight()); const int h = int(r->getHeight());
// initialize geometry values // initialize geometry values
setGeometry (FPoint(1, h), FSize(w, 1), false); setGeometry (FPoint(1, h), FSize(w, 1), false);
setAlwaysOnTop(); setAlwaysOnTop();
@ -564,7 +564,7 @@ void FStatusBar::drawKeys()
while ( iter != key_list.end() ) while ( iter != key_list.end() )
{ {
auto item = *iter; const auto& item = *iter;
keyname_len = getKeyNameWidth(item); keyname_len = getKeyNameWidth(item);
if ( x + keyname_len + 2 < int(screenWidth) ) if ( x + keyname_len + 2 < int(screenWidth) )
@ -597,7 +597,7 @@ void FStatusBar::drawKey (keyList::const_iterator iter)
{ {
// Draw not active key // Draw not active key
auto item = *iter; const auto item = *iter;
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setColor (wc.statusbar_hotkey_fg, wc.statusbar_hotkey_bg); setColor (wc.statusbar_hotkey_fg, wc.statusbar_hotkey_bg);
x++; x++;
@ -607,7 +607,7 @@ void FStatusBar::drawKey (keyList::const_iterator iter)
setColor (wc.statusbar_fg, wc.statusbar_bg); setColor (wc.statusbar_fg, wc.statusbar_bg);
x++; x++;
print ('-'); print ('-');
auto column_width = getColumnWidth (item->getText()); const auto column_width = getColumnWidth (item->getText());
x += int(column_width); x += int(column_width);
if ( x - 1 <= int(screenWidth) ) if ( x - 1 <= int(screenWidth) )
@ -615,7 +615,7 @@ void FStatusBar::drawKey (keyList::const_iterator iter)
else else
{ {
// Print ellipsis // Print ellipsis
std::size_t len = column_width + screenWidth - std::size_t(x) - 1; const std::size_t len = column_width + screenWidth - std::size_t(x) - 1;
print() << getColumnSubString(item->getText(), 1, len) print() << getColumnSubString(item->getText(), 1, len)
<< ".."; << "..";
} }
@ -655,7 +655,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter)
{ {
// Draw active key // Draw active key
auto item = *iter; const auto& item = *iter;
if ( isMonochron() ) if ( isMonochron() )
setReverse(false); setReverse(false);
@ -670,7 +670,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter)
setColor (wc.statusbar_active_fg, wc.statusbar_active_bg); setColor (wc.statusbar_active_fg, wc.statusbar_active_bg);
x++; x++;
print ('-'); print ('-');
auto column_width = getColumnWidth (item->getText()); const auto column_width = getColumnWidth (item->getText());
x += int(column_width); x += int(column_width);
if ( x <= int(screenWidth) ) if ( x <= int(screenWidth) )

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 2012-2019 Markus Gans * * Copyright 2012-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -446,7 +446,7 @@ FString FString::toUpper() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
sInt16 FString::toShort() const sInt16 FString::toShort() const
{ {
long num = toLong(); const long num = toLong();
if ( num > SHRT_MAX ) if ( num > SHRT_MAX )
throw std::overflow_error ("overflow"); throw std::overflow_error ("overflow");
@ -460,7 +460,7 @@ sInt16 FString::toShort() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt16 FString::toUShort() const uInt16 FString::toUShort() const
{ {
uLong num = uLong(toULong()); const uLong num = uLong(toULong());
if ( num > USHRT_MAX ) if ( num > USHRT_MAX )
throw std::overflow_error ("overflow"); throw std::overflow_error ("overflow");
@ -485,7 +485,7 @@ int FString::toInt() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt FString::toUInt() const uInt FString::toUInt() const
{ {
uLong num = uLong(toULong()); const uLong num = uLong(toULong());
if ( num > UINT_MAX ) if ( num > UINT_MAX )
throw std::overflow_error ("overflow"); throw std::overflow_error ("overflow");
@ -500,7 +500,7 @@ long FString::toLong() const
long num{0}; long num{0};
long tenth_limit{LONG_MAX / 10}; long tenth_limit{LONG_MAX / 10};
long tenth_limit_digit{LONG_MAX % 10}; long tenth_limit_digit{LONG_MAX % 10};
FString s(trim()); const FString s(trim());
const wchar_t* p = s.string; const wchar_t* p = s.string;
if ( ! p ) if ( ! p )
@ -551,9 +551,9 @@ long FString::toLong() const
uLong FString::toULong() const uLong FString::toULong() const
{ {
uLong num{0}; uLong num{0};
uLong tenth_limit{ULONG_MAX / 10}; const uLong tenth_limit{ULONG_MAX / 10};
uLong tenth_limit_digit{ULONG_MAX % 10}; const uLong tenth_limit_digit{ULONG_MAX % 10};
FString s(trim()); const FString s(trim());
const wchar_t* p = s.string; const wchar_t* p = s.string;
if ( ! p ) if ( ! p )
@ -573,7 +573,7 @@ uLong FString::toULong() const
while ( std::iswdigit(std::wint_t(*p)) ) while ( std::iswdigit(std::wint_t(*p)) )
{ {
uChar d = uChar(*p - L'0'); const uChar d = uChar(*p - L'0');
if ( num > tenth_limit if ( num > tenth_limit
|| (num == tenth_limit && d > tenth_limit_digit) ) || (num == tenth_limit && d > tenth_limit_digit) )
@ -594,7 +594,7 @@ uLong FString::toULong() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
float FString::toFloat() const float FString::toFloat() const
{ {
double num = toDouble(); const double num = toDouble();
if ( num > double(FLT_MAX) || num < double(-FLT_MAX) ) if ( num > double(FLT_MAX) || num < double(-FLT_MAX) )
throw std::overflow_error ("overflow"); throw std::overflow_error ("overflow");
@ -615,7 +615,7 @@ double FString::toDouble() const
throw std::invalid_argument ("empty value"); throw std::invalid_argument ("empty value");
wchar_t* p{}; wchar_t* p{};
double ret = std::wcstod(string, &p); const double ret = std::wcstod(string, &p);
if ( p != 0 && *p != '\0' ) if ( p != 0 && *p != '\0' )
throw std::invalid_argument ("no valid floating point value"); throw std::invalid_argument ("no valid floating point value");
@ -635,7 +635,7 @@ double FString::toDouble() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString FString::ltrim() const FString FString::ltrim() const
{ {
FString s(string); const FString s(string);
// handle NULL and empty string // handle NULL and empty string
if ( ! (string && *string) ) if ( ! (string && *string) )
@ -679,7 +679,7 @@ FString FString::trim() const
if ( ! (string && *string) ) if ( ! (string && *string) )
return *this; return *this;
FString s(ltrim()); const FString s(ltrim());
return s.rtrim(); return s.rtrim();
} }
@ -704,7 +704,7 @@ FString FString::left (std::size_t len) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString FString::right (std::size_t len) const FString FString::right (std::size_t len) const
{ {
FString s(string); const FString s(string);
// handle NULL and empty string // handle NULL and empty string
if ( ! (string && *string) ) if ( ! (string && *string) )
@ -721,7 +721,7 @@ FString FString::right (std::size_t len) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString FString::mid (std::size_t pos, std::size_t len) const FString FString::mid (std::size_t pos, std::size_t len) const
{ {
FString s(string); const FString s(string);
// handle NULL and empty string // handle NULL and empty string
if ( ! (string && *string) ) if ( ! (string && *string) )
@ -745,7 +745,7 @@ FString FString::mid (std::size_t pos, std::size_t len) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FStringList FString::split (const FString& delimiter) FStringList FString::split (const FString& delimiter)
{ {
FString s(string); const FString s(string);
FStringList string_list{}; FStringList string_list{};
// handle NULL and empty string // handle NULL and empty string
@ -1025,8 +1025,8 @@ FString FString::replace (const FString& from, const FString& to)
return s; return s;
const wchar_t* p = s.string; const wchar_t* p = s.string;
std::size_t from_length = from.getLength(); const std::size_t from_length = from.getLength();
std::size_t to_length = to.getLength(); const std::size_t to_length = to.getLength();
std::size_t pos{0}; std::size_t pos{0};
while ( *p ) while ( *p )
@ -1083,13 +1083,13 @@ FString FString::expandTabs (int tabstop) const
if ( tabstop <= 0 ) if ( tabstop <= 0 )
return instr; return instr;
FStringList tab_split = instr.split("\t"); const FStringList tab_split = instr.split("\t");
uLong last = tab_split.size(); const uLong last = tab_split.size();
for (std::size_t i{0}; i < last; i++) for (std::size_t i{0}; i < last; i++)
{ {
std::size_t len = tab_split[i].getLength(); const std::size_t len = tab_split[i].getLength();
std::size_t tab_len = std::size_t(tabstop); const std::size_t tab_len = std::size_t(tabstop);
if ( i == last - 1 ) if ( i == last - 1 )
outstr += tab_split[i]; outstr += tab_split[i];
@ -1419,8 +1419,8 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const
if ( c_string ) if ( c_string )
delete[](c_string); delete[](c_string);
int size = int(std::wcslen(s)) + 1; const int size = int(std::wcslen(s)) + 1;
int dest_size = size * int(CHAR_SIZE); const int dest_size = size * int(CHAR_SIZE);
const wchar_t* src = s; const wchar_t* src = s;
std::mbstate_t state{}; std::mbstate_t state{};
std::memset (&state, '\0', sizeof(mbstate_t)); std::memset (&state, '\0', sizeof(mbstate_t));
@ -1438,7 +1438,7 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const
return 0; return 0;
} }
int mblength = \ const int mblength = \
int(std::wcsrtombs (c_string, &src, std::size_t(dest_size), &state)); int(std::wcsrtombs (c_string, &src, std::size_t(dest_size), &state));
if ( mblength == -1 && errno != EILSEQ ) if ( mblength == -1 && errno != EILSEQ )
@ -1471,8 +1471,8 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const
} }
} }
int size = int(std::strlen(s)) + 1; const int size = int(std::strlen(s)) + 1;
int dest_size = size * int(CHAR_SIZE); const int dest_size = size * int(CHAR_SIZE);
const char* src = s; const char* src = s;
wchar_t* dest{}; wchar_t* dest{};
std::mbstate_t state{}; std::mbstate_t state{};
@ -1490,7 +1490,7 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const
return 0; return 0;
} }
int wclength = \ const int wclength = \
int(std::mbsrtowcs (dest, &src, std::size_t(dest_size), &state)); int(std::mbsrtowcs (dest, &src, std::size_t(dest_size), &state));
if ( wclength == -1 ) if ( wclength == -1 )
@ -1636,7 +1636,7 @@ std::ostream& operator << (std::ostream& outstr, const FString& s)
} }
else if ( width > 0 ) else if ( width > 0 )
{ {
FString fill_str(width, outstr.fill()); const FString fill_str(width, outstr.fill());
outstr << s.wc_to_c_str(fill_str.string); outstr << s.wc_to_c_str(fill_str.string);
} }
@ -1670,7 +1670,7 @@ std::wostream& operator << (std::wostream& outstr, const FString& s)
} }
else if ( width > 0 ) else if ( width > 0 )
{ {
FString fill_str(width, outstr.fill()); const FString fill_str(width, outstr.fill());
outstr << fill_str.string; outstr << fill_str.string;
} }

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -142,7 +142,7 @@ void FSwitch::drawCheckButton()
inline void FSwitch::drawChecked() inline void FSwitch::drawChecked()
{ {
wchar_t on[6]{L" On "}; wchar_t on[6]{L" On "};
wchar_t off[6]{L" Off "}; const wchar_t off[6]{L" Off "};
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
if ( hasFocus() && ! button_pressed ) if ( hasFocus() && ! button_pressed )
@ -191,7 +191,7 @@ inline void FSwitch::drawChecked()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FSwitch::drawUnchecked() inline void FSwitch::drawUnchecked()
{ {
wchar_t on[6]{L" On "}; const wchar_t on[6]{L" On "};
wchar_t off[6]{L" Off "}; wchar_t off[6]{L" Off "};
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();

View File

@ -118,7 +118,7 @@ FTerm::~FTerm() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::size_t FTerm::getLineNumber() std::size_t FTerm::getLineNumber()
{ {
auto& term_geometry = data->getTermGeometry(); const auto& term_geometry = data->getTermGeometry();
if ( term_geometry.getHeight() == 0 ) if ( term_geometry.getHeight() == 0 )
detectTermSize(); detectTermSize();
@ -129,7 +129,7 @@ std::size_t FTerm::getLineNumber()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::size_t FTerm::getColumnNumber() std::size_t FTerm::getColumnNumber()
{ {
auto& term_geometry = data->getTermGeometry(); const auto& term_geometry = data->getTermGeometry();
if ( term_geometry.getWidth() == 0 ) if ( term_geometry.getWidth() == 0 )
detectTermSize(); detectTermSize();
@ -808,7 +808,7 @@ int FTerm::closeConsole()
if ( ! data ) if ( ! data )
data = FTerm::getFTermData(); data = FTerm::getFTermData();
int fd = data->getTTYFileDescriptor(); const int fd = data->getTTYFileDescriptor();
int ret{-1}; int ret{-1};
if ( fd < 0 ) // console is already closed if ( fd < 0 ) // console is already closed
@ -981,9 +981,9 @@ void FTerm::setPalette (FColor index, int r, int g, int b)
{ {
const char* color_str{}; const char* color_str{};
int rr = (r * 1001) / 256 const int rr = (r * 1001) / 256;
, gg = (g * 1001) / 256 const int gg = (g * 1001) / 256;
, bb = (b * 1001) / 256; const int bb = (b * 1001) / 256;
if ( Ic ) if ( Ic )
color_str = tparm(Ic, index, rr, gg, bb, 0, 0, 0, 0, 0); color_str = tparm(Ic, index, rr, gg, bb, 0, 0, 0, 0, 0);
@ -1113,9 +1113,9 @@ fc::encoding FTerm::getEncoding()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::string FTerm::getEncodingString() std::string FTerm::getEncodingString()
{ {
auto term_encoding = data->getTermEncoding(); const auto& term_encoding = data->getTermEncoding();
auto& encoding_list = data->getEncodingList(); const auto& encoding_list = data->getEncodingList();
auto end = encoding_list.end(); const auto& end = encoding_list.end();
for (auto it = encoding_list.begin(); it != end; ++it ) for (auto it = encoding_list.begin(); it != end; ++it )
if ( it->second == term_encoding ) if ( it->second == term_encoding )
@ -1127,7 +1127,7 @@ std::string FTerm::getEncodingString()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTerm::charEncodable (wchar_t c) bool FTerm::charEncodable (wchar_t c)
{ {
wchar_t ch = charEncode(c); const wchar_t ch = charEncode(c);
return bool(ch > 0 && ch != c); return bool(ch > 0 && ch != c);
} }
@ -1333,7 +1333,7 @@ void FTerm::init_global_values (bool disable_alt_screen)
void FTerm::init_terminal_device_path() void FTerm::init_terminal_device_path()
{ {
char termfilename[256]{}; char termfilename[256]{};
int stdout_no = FTermios::getStdOut(); const int stdout_no = FTermios::getStdOut();
if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) ) if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) )
termfilename[0] = '\0'; termfilename[0] = '\0';
@ -1378,8 +1378,8 @@ void FTerm::init_alt_charset()
for (std::size_t n{0}; TCAP(fc::t_acs_chars)[n]; n += 2) for (std::size_t n{0}; TCAP(fc::t_acs_chars)[n]; n += 2)
{ {
// insert the VT100 key/value pairs into a map // insert the VT100 key/value pairs into a map
uChar p1 = uChar(TCAP(fc::t_acs_chars)[n]); const uChar p1 = uChar(TCAP(fc::t_acs_chars)[n]);
uChar p2 = uChar(TCAP(fc::t_acs_chars)[n + 1]); const uChar p2 = uChar(TCAP(fc::t_acs_chars)[n + 1]);
vt100_alt_char[p1] = p2; vt100_alt_char[p1] = p2;
} }
} }
@ -1393,17 +1393,17 @@ void FTerm::init_alt_charset()
// Update array 'character' with discovered VT100 pairs // Update array 'character' with discovered VT100 pairs
for (std::size_t n{0}; n <= fc::lastKeyItem; n++ ) for (std::size_t n{0}; n <= fc::lastKeyItem; n++ )
{ {
uChar keyChar = uChar(fc::vt100_key_to_utf8[n][vt100_key]); const uChar keyChar = uChar(fc::vt100_key_to_utf8[n][vt100_key]);
uChar altChar = uChar(vt100_alt_char[keyChar]); const uChar altChar = uChar(vt100_alt_char[keyChar]);
uInt utf8char = uInt(fc::vt100_key_to_utf8[n][utf8_char]); const uInt utf8char = uInt(fc::vt100_key_to_utf8[n][utf8_char]);
fc::encoding num{fc::NUM_OF_ENCODINGS}; const fc::encoding num{fc::NUM_OF_ENCODINGS};
uInt* p = std::find ( fc::character[0] uInt* p = std::find ( fc::character[0]
, fc::character[fc::lastCharItem] + num , fc::character[fc::lastCharItem] + num
, utf8char ); , utf8char );
if ( p != fc::character[fc::lastCharItem] + num ) // found in character if ( p != fc::character[fc::lastCharItem] + num ) // found in character
{ {
int item = int(std::distance(fc::character[0], p) / num); const int item = int(std::distance(fc::character[0], p) / num);
if ( altChar ) // update alternate character set if ( altChar ) // update alternate character set
fc::character[item][fc::VT100] = altChar; fc::character[item][fc::VT100] = altChar;
@ -1751,7 +1751,7 @@ inline void FTerm::init_encoding_set()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::init_term_encoding() void FTerm::init_term_encoding()
{ {
int stdout_no = FTermios::getStdOut(); const int stdout_no = FTermios::getStdOut();
const char* termtype = data->getTermType(); const char* termtype = data->getTermType();
if ( ! fsys ) if ( ! fsys )
@ -1831,7 +1831,7 @@ void FTerm::init_tab_quirks()
// on the terminal and does not move the cursor to the next tab stop // on the terminal and does not move the cursor to the next tab stop
// position // position
auto enc = data->getTermEncoding(); const auto& enc = data->getTermEncoding();
if ( enc == fc::VT100 || enc == fc::PC ) if ( enc == fc::VT100 || enc == fc::PC )
{ {
@ -2362,8 +2362,8 @@ void FTerm::initTermspecifics()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::initBaudRate() void FTerm::initBaudRate()
{ {
int stdout_no = FTermios::getStdOut(); const int stdout_no = FTermios::getStdOut();
uInt baud = FTermios::getBaudRate(); const uInt baud = FTermios::getBaudRate();
data->setBaudrate(baud); data->setBaudrate(baud);
if ( ! fsys ) if ( ! fsys )

View File

@ -190,7 +190,7 @@ const wchar_t reverse_newfont_list[] =
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt env2uint (const char* env) uInt env2uint (const char* env)
{ {
FString str(getenv(env)); const FString str(getenv(env));
if ( str.isEmpty() ) if ( str.isEmpty() )
return 0; return 0;
@ -424,7 +424,7 @@ std::size_t getColumnWidth (const FString& s, std::size_t pos)
return 0; return 0;
std::size_t column_width{0}; std::size_t column_width{0};
auto length = s.getLength(); const auto length = s.getLength();
if ( pos > length ) if ( pos > length )
pos = length; pos = length;
@ -483,7 +483,7 @@ std::size_t getColumnWidth (const wchar_t wchar)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::size_t getColumnWidth (FChar& term_char) std::size_t getColumnWidth (FChar& term_char)
{ {
std::size_t char_width = getColumnWidth(term_char.ch); const std::size_t char_width = getColumnWidth(term_char.ch);
if ( char_width == 2 && FTerm::getEncoding() != fc::UTF8 ) if ( char_width == 2 && FTerm::getEncoding() != fc::UTF8 )
{ {

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 2017-2019 Markus Gans * * Copyright 2017-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -56,7 +56,7 @@ const FString FTermBuffer::toString() const
int FTermBuffer::write (const FString& string) int FTermBuffer::write (const FString& string)
{ {
assert ( ! string.isNull() ); assert ( ! string.isNull() );
int len = int(string.getLength()); const int len = int(string.getLength());
for (auto&& c : string) for (auto&& c : string)
{ {

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -84,7 +84,7 @@ void FTermcap::termcap()
static char string_buf[2048]{}; static char string_buf[2048]{};
char* buffer = string_buf; char* buffer = string_buf;
int status = uninitialized; int status = uninitialized;
bool color256 = term_detection->canDisplay256Colors(); const bool color256 = term_detection->canDisplay256Colors();
// Open termcap file // Open termcap file
#if defined(__sun) && defined(__SVR4) #if defined(__sun) && defined(__SVR4)

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 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -58,7 +58,7 @@ void FTermcapQuirks::terminalFixup()
{ {
fterm_data = FTerm::getFTermData(); fterm_data = FTerm::getFTermData();
term_detection = FTerm::getFTermDetection(); term_detection = FTerm::getFTermDetection();
auto& td = term_detection; const auto& td = term_detection;
if ( td->isCygwinTerminal() ) if ( td->isCygwinTerminal() )
{ {

View File

@ -203,7 +203,7 @@ bool FTermDetection::getTTYtype()
term_basename++; term_basename++;
std::FILE* fp{}; std::FILE* fp{};
char str[BUFSIZ]{}; char str[BUFSIZ]{};
if ( fsystem && (fp = fsystem->fopen(ttytypename, "r")) != 0 ) if ( fsystem && (fp = fsystem->fopen(ttytypename, "r")) != 0 )
{ {
@ -543,7 +543,7 @@ const FString FTermDetection::getXTermColorName (FColor color)
FString color_str{""}; FString color_str{""};
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
int stdin_no = FTermios::getStdIn(); const int stdin_no = FTermios::getStdIn();
// get color // get color
std::fprintf (stdout, OSC "4;%hu;?" BEL, color); std::fprintf (stdout, OSC "4;%hu;?" BEL, color);
@ -627,7 +627,7 @@ const FString FTermDetection::getAnswerbackMsg()
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
char temp[10]{}; char temp[10]{};
int stdin_no = FTermios::getStdIn(); const int stdin_no = FTermios::getStdIn();
std::putchar (ENQ[0]); // Send enquiry character std::putchar (ENQ[0]); // Send enquiry character
std::fflush(stdout); std::fflush(stdout);
@ -671,9 +671,9 @@ char* FTermDetection::parseSecDA (char current_termtype[])
// remove the last byte ("c") // remove the last byte ("c")
temp.remove(temp.getLength() - 1, 1); temp.remove(temp.getLength() - 1, 1);
// split into components // split into components
FStringList sec_da_list = temp.split(';'); const FStringList sec_da_list = temp.split(';');
uLong num_components = sec_da_list.size(); const uLong num_components = sec_da_list.size();
// The second device attribute (SEC_DA) always has 3 parameters, // The second device attribute (SEC_DA) always has 3 parameters,
// otherwise it usually has a copy of the device attribute (primary DA) // otherwise it usually has a copy of the device attribute (primary DA)
@ -728,16 +728,16 @@ const FString FTermDetection::getSecDA()
{ {
FString sec_da_str{""}; FString sec_da_str{""};
int a{0} int a{0};
, b{0} int b{0};
, c{0} int c{0};
, stdin_no{FTermios::getStdIn()} const int stdin_no{FTermios::getStdIn()};
, stdout_no{FTermios::getStdOut()}; const int stdout_no{FTermios::getStdOut()};
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
// Get the secondary device attributes // Get the secondary device attributes
ssize_t ret = write(stdout_no, SECDA, std::strlen(SECDA)); const ssize_t ret = write(stdout_no, SECDA, std::strlen(SECDA));
if ( ret == -1 ) if ( ret == -1 )
return sec_da_str; return sec_da_str;

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 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -138,7 +138,7 @@ bool FTermLinux::isLinuxConsole()
fsystem = FTerm::getFSystem(); fsystem = FTerm::getFSystem();
char arg{0}; char arg{0};
int fd_tty = FTerm::getTTYFileDescriptor(); const int fd_tty = FTerm::getTTYFileDescriptor();
// Get keyboard type an compare // Get keyboard type an compare
return ( fsystem->isTTY(fd_tty) return ( fsystem->isTTY(fd_tty)
@ -217,8 +217,8 @@ void FTermLinux::initCharMap()
{ {
for (std::size_t i{0}; i <= fc::lastCharItem; i++ ) for (std::size_t i{0}; i <= fc::lastCharItem; i++ )
{ {
auto ucs = wchar_t(fc::character[i][fc::UTF8]); const auto ucs = wchar_t(fc::character[i][fc::UTF8]);
sInt16 fontpos = getFontPos(ucs); const sInt16 fontpos = getFontPos(ucs);
// Fix for a non-cp437 Linux console with PC charset encoding // Fix for a non-cp437 Linux console with PC charset encoding
if ( fontpos > 255 || fontpos == NOT_FOUND ) if ( fontpos > 255 || fontpos == NOT_FOUND )
@ -267,7 +267,7 @@ bool FTermLinux::loadVGAFont()
if ( isLinuxConsole() ) if ( isLinuxConsole() )
{ {
// Set the standard vga font 8x16 // Set the standard vga font 8x16
int ret = setScreenFont(fc::__8x16std, 256, 8, 16); const int ret = setScreenFont(fc::__8x16std, 256, 8, 16);
if ( ret != 0 ) if ( ret != 0 )
vga_font = false; vga_font = false;
@ -354,11 +354,11 @@ bool FTermLinux::loadOldFont()
{ {
if ( screen_font.data ) if ( screen_font.data )
{ {
int ret = setScreenFont ( screen_font.data const int ret = setScreenFont ( screen_font.data
, screen_font.charcount , screen_font.charcount
, screen_font.width , screen_font.width
, screen_font.height , screen_font.height
, true ); , true );
delete[] screen_font.data; delete[] screen_font.data;
screen_font.data = nullptr; screen_font.data = nullptr;
@ -532,7 +532,7 @@ int FTermLinux::getFramebuffer_bpp()
bool FTermLinux::getScreenFont() bool FTermLinux::getScreenFont()
{ {
struct console_font_op font{}; struct console_font_op font{};
int fd_tty = FTerm::getTTYFileDescriptor(); const int fd_tty = FTerm::getTTYFileDescriptor();
int ret{-1}; int ret{-1};
if ( fd_tty < 0 ) if ( fd_tty < 0 )
@ -581,7 +581,7 @@ bool FTermLinux::getScreenFont()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermLinux::getUnicodeMap() bool FTermLinux::getUnicodeMap()
{ {
int fd_tty = FTerm::getTTYFileDescriptor(); const int fd_tty = FTerm::getTTYFileDescriptor();
int ret{-1}; int ret{-1};
if ( fd_tty < 0 ) if ( fd_tty < 0 )
@ -596,7 +596,7 @@ bool FTermLinux::getUnicodeMap()
if ( ret != 0 ) if ( ret != 0 )
{ {
std::size_t count = screen_unicode_map.entry_ct; const std::size_t count = screen_unicode_map.entry_ct;
if ( errno != ENOMEM || count == 0 ) if ( errno != ENOMEM || count == 0 )
return false; return false;
@ -657,7 +657,7 @@ int FTermLinux::setScreenFont ( uChar fontdata[], uInt count
, bool direct) , bool direct)
{ {
struct console_font_op font{}; struct console_font_op font{};
int fd_tty = FTerm::getTTYFileDescriptor(); const int fd_tty = FTerm::getTTYFileDescriptor();
int ret{-1}; int ret{-1};
if ( fd_tty < 0 ) if ( fd_tty < 0 )
@ -720,7 +720,7 @@ int FTermLinux::setScreenFont ( uChar fontdata[], uInt count
int FTermLinux::setUnicodeMap (struct unimapdesc* unimap) int FTermLinux::setUnicodeMap (struct unimapdesc* unimap)
{ {
struct unimapinit advice; struct unimapinit advice;
int fd_tty = FTerm::getTTYFileDescriptor(); const int fd_tty = FTerm::getTTYFileDescriptor();
int ret{-1}; int ret{-1};
if ( fd_tty < 0 ) if ( fd_tty < 0 )
@ -771,7 +771,7 @@ inline uInt16 FTermLinux::getInputStatusRegisterOne()
// Miscellaneous output (read port) // Miscellaneous output (read port)
static constexpr uInt16 misc_read = 0x3cc; static constexpr uInt16 misc_read = 0x3cc;
uChar misc_value = fsystem->inPortByte(misc_read); const uChar misc_value = fsystem->inPortByte(misc_read);
const uInt16 io_base = ( misc_value & 0x01 ) ? 0x3d0 : 0x3b0; const uInt16 io_base = ( misc_value & 0x01 ) ? 0x3d0 : 0x3b0;
// 0x3ba : Input status 1 mono/MDA (read port) // 0x3ba : Input status 1 mono/MDA (read port)
// 0x3da : Input status 1 color/CGA (read port) // 0x3da : Input status 1 color/CGA (read port)
@ -794,7 +794,7 @@ uChar FTermLinux::readAttributeController (uChar index)
fsystem->inPortByte (input_status_1); // switch to index mode fsystem->inPortByte (input_status_1); // switch to index mode
fsystem->outPortByte (index & 0x1f, attrib_cntlr_write); // selects address register fsystem->outPortByte (index & 0x1f, attrib_cntlr_write); // selects address register
uChar res = fsystem->inPortByte (attrib_cntlr_read); // read from data register const uChar res = fsystem->inPortByte (attrib_cntlr_read); // read from data register
// Disable access to the palette and unblank the display // Disable access to the palette and unblank the display
fsystem->inPortByte (input_status_1); // switch to index mode fsystem->inPortByte (input_status_1); // switch to index mode
@ -853,7 +853,7 @@ int FTermLinux::setBlinkAsIntensity (bool enable)
if ( ! fsystem ) if ( ! fsystem )
fsystem = FTerm::getFSystem(); fsystem = FTerm::getFSystem();
int fd_tty = FTerm::getTTYFileDescriptor(); const int fd_tty = FTerm::getTTYFileDescriptor();
// Test if the blink-bit is used by the screen font (512 characters) // Test if the blink-bit is used by the screen font (512 characters)
if ( screen_font.charcount > 256 ) if ( screen_font.charcount > 256 )
@ -893,7 +893,7 @@ bool FTermLinux::has9BitCharacters()
if ( ! fsystem ) if ( ! fsystem )
fsystem = FTerm::getFSystem(); fsystem = FTerm::getFSystem();
int fd_tty = FTerm::getTTYFileDescriptor(); const int fd_tty = FTerm::getTTYFileDescriptor();
if ( fsystem->getuid() != 0 ) // Direct hardware access requires root privileges if ( fsystem->getuid() != 0 ) // Direct hardware access requires root privileges
return false; return false;
@ -905,7 +905,7 @@ bool FTermLinux::has9BitCharacters()
if ( fsystem->ioctl(fd_tty, KDENABIO, 0) < 0 ) if ( fsystem->ioctl(fd_tty, KDENABIO, 0) < 0 )
return false; // error on KDENABIO return false; // error on KDENABIO
bool nine_bit_char( getAttributeMode() & 0x04 ); const bool nine_bit_char( getAttributeMode() & 0x04 );
// Disable access to VGA I/O ports // Disable access to VGA I/O ports
if ( fsystem->ioctl(fd_tty, KDDISABIO, 0) < 0 ) if ( fsystem->ioctl(fd_tty, KDDISABIO, 0) < 0 )
@ -1282,9 +1282,9 @@ FKey FTermLinux::shiftCtrlAltKeyCorrection (const FKey& key_id)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTermLinux::initSpecialCharacter() inline void FTermLinux::initSpecialCharacter()
{ {
wchar_t c1 = fc::UpperHalfBlock; const wchar_t c1 = fc::UpperHalfBlock;
wchar_t c2 = fc::LowerHalfBlock; const wchar_t c2 = fc::LowerHalfBlock;
wchar_t c3 = fc::FullBlock; const wchar_t c3 = fc::FullBlock;
if ( FTerm::charEncode(c1, fc::PC) == FTerm::charEncode(c1, fc::ASCII) if ( FTerm::charEncode(c1, fc::PC) == FTerm::charEncode(c1, fc::ASCII)
|| FTerm::charEncode(c2, fc::PC) == FTerm::charEncode(c2, fc::ASCII) || FTerm::charEncode(c2, fc::PC) == FTerm::charEncode(c2, fc::ASCII)
@ -1293,8 +1293,8 @@ inline void FTermLinux::initSpecialCharacter()
fterm_data->supportShadowCharacter (false); fterm_data->supportShadowCharacter (false);
} }
wchar_t c4 = fc::RightHalfBlock; const wchar_t c4 = fc::RightHalfBlock;
wchar_t c5 = fc::LeftHalfBlock; const wchar_t c5 = fc::LeftHalfBlock;
if ( FTerm::charEncode(c4, fc::PC) == FTerm::charEncode(c4, fc::ASCII) if ( FTerm::charEncode(c4, fc::PC) == FTerm::charEncode(c4, fc::ASCII)
|| FTerm::charEncode(c5, fc::PC) == FTerm::charEncode(c5, fc::ASCII) ) || FTerm::charEncode(c5, fc::PC) == FTerm::charEncode(c5, fc::ASCII) )

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 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -691,7 +691,7 @@ const FString FTermXTerminal::captureXTermFont()
{ {
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
int stdin_no = FTermios::getStdIn(); const int stdin_no = FTermios::getStdIn();
oscPrefix(); oscPrefix();
FTerm::putstring (OSC "50;?" BEL); // get font FTerm::putstring (OSC "50;?" BEL); // get font
@ -710,7 +710,7 @@ const FString FTermXTerminal::captureXTermFont()
if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 ) if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 )
{ {
std::size_t n = std::strlen(temp); const std::size_t n = std::strlen(temp);
// BEL + '\0' = string terminator // BEL + '\0' = string terminator
if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' ) if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' )
@ -732,7 +732,7 @@ const FString FTermXTerminal::captureXTermTitle()
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
int stdin_no = FTermios::getStdIn(); const int stdin_no = FTermios::getStdIn();
FTerm::putstring (CSI "21t"); // get title FTerm::putstring (CSI "21t"); // get title
std::fflush(stdout); std::fflush(stdout);
@ -749,7 +749,7 @@ const FString FTermXTerminal::captureXTermTitle()
if ( std::scanf("\033]l%509[^\n]s", temp) == 1 ) if ( std::scanf("\033]l%509[^\n]s", temp) == 1 )
{ {
std::size_t n = std::strlen(temp); const std::size_t n = std::strlen(temp);
// Esc + \ = OSC string terminator // Esc + \ = OSC string terminator
if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' ) if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' )

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -132,15 +132,15 @@ void FTextView::scrollBy (int dx, int dy)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::scrollTo (int x, int y) void FTextView::scrollTo (int x, int y)
{ {
bool changeX( x != xoffset ); const bool changeX( x != xoffset );
bool changeY( y != yoffset ); const bool changeY( y != yoffset );
if ( ! isShown() || ! (changeX || changeY) ) if ( ! isShown() || ! (changeX || changeY) )
return; return;
if ( changeX && isHorizontallyScrollable() ) if ( changeX && isHorizontallyScrollable() )
{ {
int xoffset_end = int(maxLineWidth - getTextWidth()); const int xoffset_end = int(maxLineWidth - getTextWidth());
xoffset = x; xoffset = x;
if ( xoffset < 0 ) if ( xoffset < 0 )
@ -158,7 +158,7 @@ void FTextView::scrollTo (int x, int y)
if ( changeY && isVerticallyScrollable() ) if ( changeY && isVerticallyScrollable() )
{ {
int yoffset_end = int(getRows() - getTextHeight()); const int yoffset_end = int(getRows() - getTextHeight());
yoffset = y; yoffset = y;
if ( yoffset < 0 ) if ( yoffset < 0 )
@ -213,7 +213,7 @@ void FTextView::insert (const FString& str, int pos)
.removeDel() .removeDel()
.replaceControlCodes() .replaceControlCodes()
.rtrim(); .rtrim();
auto column_width = getColumnWidth(line); const auto column_width = getColumnWidth(line);
if ( column_width > maxLineWidth ) if ( column_width > maxLineWidth )
{ {
@ -221,9 +221,9 @@ void FTextView::insert (const FString& str, int pos)
if ( column_width > getTextWidth() ) if ( column_width > getTextWidth() )
{ {
int hmax = ( maxLineWidth > getTextWidth() ) const int hmax = ( maxLineWidth > getTextWidth() )
? int(maxLineWidth) - int(getTextWidth()) ? int(maxLineWidth) - int(getTextWidth())
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (int(maxLineWidth), int(getTextWidth())); hbar->setPageSize (int(maxLineWidth), int(getTextWidth()));
hbar->calculateSliderValues(); hbar->calculateSliderValues();
@ -236,9 +236,9 @@ void FTextView::insert (const FString& str, int pos)
auto iter = data.begin(); auto iter = data.begin();
data.insert (iter + pos, text_split.begin(), text_split.end()); data.insert (iter + pos, text_split.begin(), text_split.end());
int vmax = ( getRows() > getTextHeight() ) const int vmax = ( getRows() > getTextHeight() )
? int(getRows()) - int(getTextHeight()) ? int(getRows()) - int(getTextHeight())
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (int(getRows()), int(getTextHeight())); vbar->setPageSize (int(getRows()), int(getTextHeight()));
vbar->calculateSliderValues(); vbar->calculateSliderValues();
@ -296,7 +296,7 @@ void FTextView::clear()
else else
drawBorder(); drawBorder();
std::size_t size = getWidth() - 2; const std::size_t size = getWidth() - 2;
if ( size == 0 ) if ( size == 0 )
return; return;
@ -314,7 +314,7 @@ void FTextView::clear()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::onKeyPress (FKeyEvent* ev) void FTextView::onKeyPress (FKeyEvent* ev)
{ {
int idx = int(ev->key()); const int idx = int(ev->key());
if ( key_map.find(idx) != key_map.end() ) if ( key_map.find(idx) != key_map.end() )
{ {
@ -346,13 +346,13 @@ void FTextView::onMouseDown (FMouseEvent* ev)
if ( ! parent ) if ( ! parent )
return; return;
auto dialog = static_cast<FDialog*>(parent); const auto& dialog = static_cast<FDialog*>(parent);
if ( parent->isDialogWidget() if ( parent->isDialogWidget()
&& dialog->isResizeable() && dialog->isResizeable()
&& ! dialog->isZoomed() ) && ! dialog->isZoomed() )
{ {
int b = ev->getButton(); const int b = ev->getButton();
const auto& tp = ev->getTermPos(); const auto& tp = ev->getTermPos();
const auto& p = parent->termToWidgetPos(tp); const auto& p = parent->termToWidgetPos(tp);
parent->setFocus(); parent->setFocus();
@ -377,11 +377,11 @@ void FTextView::onMouseUp (FMouseEvent* ev)
if ( parent && parent->isDialogWidget() ) if ( parent && parent->isDialogWidget() )
{ {
auto dialog = static_cast<FDialog*>(parent); const auto& dialog = static_cast<FDialog*>(parent);
if ( dialog->isResizeable() && ! dialog->isZoomed() ) if ( dialog->isResizeable() && ! dialog->isZoomed() )
{ {
int b = ev->getButton(); const int b = ev->getButton();
const auto& tp = ev->getTermPos(); const auto& tp = ev->getTermPos();
const auto& p = parent->termToWidgetPos(tp); const auto& p = parent->termToWidgetPos(tp);
parent->setFocus(); parent->setFocus();
@ -410,11 +410,11 @@ void FTextView::onMouseMove (FMouseEvent* ev)
if ( parent && parent->isDialogWidget() ) if ( parent && parent->isDialogWidget() )
{ {
auto dialog = static_cast<FDialog*>(parent); const auto& dialog = static_cast<FDialog*>(parent);
if ( dialog->isResizeable() && ! dialog->isZoomed() ) if ( dialog->isResizeable() && ! dialog->isZoomed() )
{ {
int b = ev->getButton(); const int b = ev->getButton();
const auto& tp = ev->getTermPos(); const auto& tp = ev->getTermPos();
const auto& p = parent->termToWidgetPos(tp); const auto& p = parent->termToWidgetPos(tp);
parent->setFocus(); parent->setFocus();
@ -436,7 +436,7 @@ void FTextView::onMouseMove (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::onWheel (FWheelEvent* ev) void FTextView::onWheel (FWheelEvent* ev)
{ {
int distance{4}; static constexpr int distance = 4;
switch ( ev->getWheel() ) switch ( ev->getWheel() )
{ {
@ -481,10 +481,10 @@ void FTextView::onFocusOut (FFocusEvent*)
void FTextView::adjustSize() void FTextView::adjustSize()
{ {
FWidget::adjustSize(); FWidget::adjustSize();
std::size_t width = getWidth(); const std::size_t width = getWidth();
std::size_t height = getHeight(); const std::size_t height = getHeight();
int last_line = int(getRows()); const int last_line = int(getRows());
int max_width = int(maxLineWidth); const int max_width = int(maxLineWidth);
if ( xoffset >= max_width - int(width) - nf_offset ) if ( xoffset >= max_width - int(width) - nf_offset )
xoffset = max_width - int(width) - nf_offset - 1; xoffset = max_width - int(width) - nf_offset - 1;
@ -501,9 +501,9 @@ void FTextView::adjustSize()
if ( height < 3 ) if ( height < 3 )
return; return;
int vmax = ( last_line > int(height) - 2 + nf_offset ) const int vmax = ( last_line > int(height) - 2 + nf_offset )
? last_line - int(height) + 2 - nf_offset ? last_line - int(height) + 2 - nf_offset
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (last_line, int(height) - 2 + nf_offset); vbar->setPageSize (last_line, int(height) - 2 + nf_offset);
vbar->setX (int(width)); vbar->setX (int(width));
@ -514,9 +514,9 @@ void FTextView::adjustSize()
if ( width < 3 ) if ( width < 3 )
return; return;
int hmax = ( max_width > int(width) - nf_offset - 2 ) const int hmax = ( max_width > int(width) - nf_offset - 2 )
? max_width - int(width) + nf_offset + 2 ? max_width - int(width) + nf_offset + 2
: 0; : 0;
hbar->setMaximum (hmax); hbar->setMaximum (hmax);
hbar->setPageSize (max_width, int(width) - nf_offset - 2); hbar->setPageSize (max_width, int(width) - nf_offset - 2);
hbar->setY (int(height)); hbar->setY (int(height));
@ -614,7 +614,7 @@ void FTextView::drawBorder()
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
FRect box(FPoint(1, 1), getSize()); const FRect box(FPoint(1, 1), getSize());
finalcut::drawListBorder (this, box); finalcut::drawListBorder (this, box);
if ( isMonochron() ) if ( isMonochron() )
@ -654,12 +654,12 @@ void FTextView::drawText()
for (std::size_t y{0}; y < num; y++) // Line loop for (std::size_t y{0}; y < num; y++) // Line loop
{ {
std::size_t n = std::size_t(yoffset) + y; const std::size_t n = std::size_t(yoffset) + y;
std::size_t pos = std::size_t(xoffset) + 1; const std::size_t pos = std::size_t(xoffset) + 1;
const auto text_width = getTextWidth();
const FString line(getColumnSubString(data[n], pos, text_width));
const auto column_width = getColumnWidth(line);
std::size_t trailing_whitespace{0}; std::size_t trailing_whitespace{0};
auto text_width = getTextWidth();
FString line(getColumnSubString(data[n], pos, text_width));
auto column_width = getColumnWidth(line);
print() << FPoint(2, 2 - nf_offset + int(y)); print() << FPoint(2, 2 - nf_offset + int(y));
for (auto&& ch : line) // Column loop for (auto&& ch : line) // Column loop
@ -685,7 +685,7 @@ void FTextView::drawText()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTextView::useFDialogBorder() inline bool FTextView::useFDialogBorder()
{ {
auto parent = getParentWidget(); const auto& parent = getParentWidget();
bool use_fdialog_border{false}; bool use_fdialog_border{false};
if ( parent if ( parent
@ -707,7 +707,7 @@ inline bool FTextView::isPrintable (wchar_t ch)
{ {
// Check for printable characters // Check for printable characters
bool utf8 = ( getEncoding() == fc::UTF8 ) ? true : false; const bool utf8 = ( getEncoding() == fc::UTF8 ) ? true : false;
if ( (utf8 && std::iswprint(std::wint_t(ch))) if ( (utf8 && std::iswprint(std::wint_t(ch)))
|| (!utf8 && std::isprint(ch)) ) || (!utf8 && std::isprint(ch)) )
@ -725,8 +725,8 @@ void FTextView::processChanged()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::changeOnResize() void FTextView::changeOnResize()
{ {
std::size_t width = getWidth(); const std::size_t width = getWidth();
std::size_t height = getHeight(); const std::size_t height = getHeight();
if ( isNewFont() ) if ( isNewFont() )
{ {
@ -746,9 +746,9 @@ void FTextView::changeOnResize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::cb_VBarChange (FWidget*, FDataPtr) void FTextView::cb_VBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType = vbar->getScrollType(); const FScrollbar::sType scrollType = vbar->getScrollType();
static constexpr int wheel_distance = 4;
int distance{1}; int distance{1};
int wheel_distance{4};
if ( scrollType >= FScrollbar::scrollStepBackward ) if ( scrollType >= FScrollbar::scrollStepBackward )
update_scrollbar = true; update_scrollbar = true;
@ -797,9 +797,9 @@ void FTextView::cb_VBarChange (FWidget*, FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::cb_HBarChange (FWidget*, FDataPtr) void FTextView::cb_HBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType = hbar->getScrollType(); const FScrollbar::sType scrollType = hbar->getScrollType();
static constexpr int wheel_distance = 4;
int distance{1}; int distance{1};
int wheel_distance{4};
if ( scrollType >= FScrollbar::scrollStepBackward ) if ( scrollType >= FScrollbar::scrollStepBackward )
update_scrollbar = true; update_scrollbar = true;

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -411,7 +411,7 @@ void FToggleButton::drawLabel()
if ( text.isNull() || text.isEmpty() ) if ( text.isNull() || text.isEmpty() )
return; return;
FString txt(text); const FString txt(text);
FString label_text{}; FString label_text{};
auto hotkeypos = finalcut::getHotkeyPos(txt, label_text); auto hotkeypos = finalcut::getHotkeyPos(txt, label_text);
print() << FPoint(1 + int(label_offset_pos), 1); print() << FPoint(1 + int(label_offset_pos), 1);
@ -436,7 +436,7 @@ void FToggleButton::onKeyPress (FKeyEvent* ev)
if ( ! isEnabled() ) if ( ! isEnabled() )
return; return;
FKey key = ev->key(); const FKey key = ev->key();
switch ( key ) switch ( key )
{ {
@ -559,9 +559,9 @@ void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::correctSize (FSize& size) void FToggleButton::correctSize (FSize& size)
{ {
std::size_t hotkey_mark = ( getHotkey(text) ) ? 1 : 0; const std::size_t hotkey_mark = ( getHotkey(text) ) ? 1 : 0;
std::size_t column_width = getColumnWidth(text); const std::size_t column_width = getColumnWidth(text);
std::size_t min_width = button_width + column_width - hotkey_mark; const std::size_t min_width = button_width + column_width - hotkey_mark;
if ( size.getWidth() < min_width ) if ( size.getWidth() < min_width )
size.setWidth(min_width); size.setWidth(min_width);

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -50,7 +50,7 @@ FToolTip::FToolTip (const FString& txt, FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FToolTip::~FToolTip() // destructor FToolTip::~FToolTip() // destructor
{ {
auto fapp = FApplication::getApplicationObject(); const auto& fapp = FApplication::getApplicationObject();
if ( fapp->isQuit() ) if ( fapp->isQuit() )
return; return;
@ -131,8 +131,6 @@ void FToolTip::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToolTip::calculateDimensions() void FToolTip::calculateDimensions()
{ {
int x{}, y{};
auto r = getRootWidget();
max_line_width = 0; max_line_width = 0;
text_components = text.split("\n"); text_components = text.split("\n");
text_num_lines = std::size_t(text_components.size()); text_num_lines = std::size_t(text_components.size());
@ -148,8 +146,10 @@ void FToolTip::calculateDimensions()
max_line_width = column_width; max_line_width = column_width;
} }
std::size_t h = text_num_lines + 2; int x{}, y{};
std::size_t w = max_line_width + 4; const std::size_t h = text_num_lines + 2;
const std::size_t w = max_line_width + 4;
const auto& r = getRootWidget();
if ( r ) if ( r )
{ {

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 2016-2019 Markus Gans * * Copyright 2016-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -104,7 +104,7 @@ FVTerm& FVTerm::operator << (const FTermBuffer& term_buffer)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FPoint FVTerm::getPrintCursor() FPoint FVTerm::getPrintCursor()
{ {
auto win = getPrintArea(); const auto& win = getPrintArea();
if ( win ) if ( win )
return FPoint ( win->offset_left + win->cursor_x return FPoint ( win->offset_left + win->cursor_x
@ -121,8 +121,8 @@ void FVTerm::setTermXY (int x, int y)
if ( term_pos->getX() == x && term_pos->getY() == y ) if ( term_pos->getX() == x && term_pos->getY() == y )
return; return;
int term_width = int(getColumnNumber()); const int term_width = int(getColumnNumber());
int term_height = int(getLineNumber()); const int term_height = int(getLineNumber());
if ( x >= term_width && term_width > 0 ) if ( x >= term_width && term_width > 0 )
{ {
@ -136,9 +136,8 @@ void FVTerm::setTermXY (int x, int y)
if ( y >= term_height ) if ( y >= term_height )
y = term_height - 1; y = term_height - 1;
int term_x = term_pos->getX(); const int term_x = term_pos->getX();
int term_y = term_pos->getY(); const int term_y = term_pos->getY();
const char* move_str = FTerm::moveCursorString (term_x, term_y, x, y); const char* move_str = FTerm::moveCursorString (term_x, term_y, x, y);
if ( move_str ) if ( move_str )
@ -176,9 +175,9 @@ FColor FVTerm::rgb2ColorIndex (uInt8 r, uInt8 g, uInt8 b)
{ {
// Converts a 24-bit RGB color to a 256-color compatible approximation // Converts a 24-bit RGB color to a 256-color compatible approximation
FColor ri = (((r * 5) + 127) / 255) * 36; const FColor ri = (((r * 5) + 127) / 255) * 36;
FColor gi = (((g * 5) + 127) / 255) * 6; const FColor gi = (((g * 5) + 127) / 255) * 6;
FColor bi = (((b * 5) + 127) / 255); const FColor bi = (((b * 5) + 127) / 255);
return 16 + ri + gi + bi; return 16 + ri + gi + bi;
} }
@ -259,7 +258,7 @@ void FVTerm::updateTerminal()
} }
} }
auto data = getFTerm().getFTermData(); const auto& data = getFTerm().getFTermData();
// Checks if the resizing of the terminal is not finished // Checks if the resizing of the terminal is not finished
if ( data && data->hasTermResized() ) if ( data && data->hasTermResized() )
@ -406,7 +405,7 @@ int FVTerm::print (const std::vector<FChar>& term_string)
int FVTerm::print (FTermArea* area, const std::vector<FChar>& term_string) int FVTerm::print (FTermArea* area, const std::vector<FChar>& term_string)
{ {
int len{0}; int len{0};
uInt tabstop = uInt(getTabstop()); const uInt tabstop = uInt(getTabstop());
if ( ! area ) if ( ! area )
return -1; return -1;
@ -508,13 +507,13 @@ int FVTerm::print (FTermArea* area, FChar& term_char)
if ( ! area ) if ( ! area )
return -1; return -1;
int width = area->width; const int width = area->width;
int height = area->height; const int height = area->height;
int rsh = area->right_shadow; const int rsh = area->right_shadow;
int bsh = area->bottom_shadow; const int bsh = area->bottom_shadow;
int ax = area->cursor_x - 1; const int ax = area->cursor_x - 1;
int ay = area->cursor_y - 1; const int ay = area->cursor_y - 1;
std::size_t char_width = getColumnWidth(nc); // add column width const std::size_t char_width = getColumnWidth(nc); // add column width
if ( char_width == 0 && ! nc.attr.bit.fullwidth_padding ) if ( char_width == 0 && ! nc.attr.bit.fullwidth_padding )
return 0; return 0;
@ -524,7 +523,7 @@ int FVTerm::print (FTermArea* area, FChar& term_char)
&& ax < area->width + area->right_shadow && ax < area->width + area->right_shadow
&& ay < area->height + area->bottom_shadow ) && ay < area->height + area->bottom_shadow )
{ {
int line_len = area->width + area->right_shadow; const int line_len = area->width + area->right_shadow;
auto ac = &area->data[ay * line_len + ax]; // area character auto ac = &area->data[ay * line_len + ax]; // area character
if ( *ac != nc ) // compare with an overloaded operator if ( *ac != nc ) // compare with an overloaded operator
@ -659,12 +658,12 @@ void FVTerm::resizeArea ( const FRect& box
{ {
// Resize the virtual window to a new size. // Resize the virtual window to a new size.
int offset_left = box.getX(); const int offset_left = box.getX();
int offset_top = box.getY(); const int offset_top = box.getY();
int width = int(box.getWidth()); const int width = int(box.getWidth());
int height = int(box.getHeight()); const int height = int(box.getHeight());
int rsw = int(shadow.getWidth()); const int rsw = int(shadow.getWidth());
int bsh = int(shadow.getHeight()); const int bsh = int(shadow.getHeight());
assert ( offset_top >= 0 ); assert ( offset_top >= 0 );
assert ( width > 0 && width + rsw > 0 ); assert ( width > 0 && width + rsw > 0 );
@ -690,9 +689,9 @@ void FVTerm::resizeArea ( const FRect& box
} }
bool realloc_success{false}; bool realloc_success{false};
std::size_t full_width = std::size_t(width) + std::size_t(rsw); const std::size_t full_width = std::size_t(width) + std::size_t(rsw);
std::size_t full_height = std::size_t(height) + std::size_t(bsh); const std::size_t full_height = std::size_t(height) + std::size_t(bsh);
std::size_t area_size = full_width * full_height; const std::size_t area_size = full_width * full_height;
if ( area->height + area->bottom_shadow != int(full_height) ) if ( area->height + area->bottom_shadow != int(full_height) )
{ {
@ -718,7 +717,7 @@ void FVTerm::resizeArea ( const FRect& box
area->bottom_shadow = bsh; area->bottom_shadow = bsh;
area->has_changes = false; area->has_changes = false;
FSize size(full_width, full_height); const FSize size(full_width, full_height);
setTextToDefault (area, size); setTextToDefault (area, size);
} }
@ -774,11 +773,11 @@ void FVTerm::restoreVTerm (const FRect& box)
for (int ty{0}; ty < h; ty++) for (int ty{0}; ty < h; ty++)
{ {
int ypos = y + ty; const int ypos = y + ty;
for (int tx{0}; tx < w; tx++) for (int tx{0}; tx < w; tx++)
{ {
int xpos = x + tx; const int xpos = x + tx;
auto tc = &vterm->data[ypos * vterm->width + xpos]; // terminal character auto tc = &vterm->data[ypos * vterm->width + xpos]; // terminal character
auto sc = generateCharacter(FPoint(xpos, ypos)); // shown character auto sc = generateCharacter(FPoint(xpos, ypos)); // shown character
std::memcpy (tc, &sc, sizeof(*tc)); std::memcpy (tc, &sc, sizeof(*tc));
@ -809,14 +808,14 @@ bool FVTerm::updateVTermCursor (FTermArea* area)
if ( area->input_cursor_visible ) if ( area->input_cursor_visible )
{ {
// area offset // area offset
int ax = area->offset_left; const int ax = area->offset_left;
int ay = area->offset_top; const int ay = area->offset_top;
// area cursor position // area cursor position
int cx = area->input_cursor_x; const int cx = area->input_cursor_x;
int cy = area->input_cursor_y; const int cy = area->input_cursor_y;
// terminal position // terminal position
int x = ax + cx; const int x = ax + cx;
int y = ay + cy; const int y = ay + cy;
if ( isInsideArea (FPoint(cx, cy), area) if ( isInsideArea (FPoint(cx, cy), area)
&& isInsideTerminal (FPoint(x, y)) && isInsideTerminal (FPoint(x, y))
@ -855,8 +854,8 @@ void FVTerm::getArea (const FPoint& pos, FTermArea* area)
if ( ! area ) if ( ! area )
return; return;
int ax = pos.getX() - 1; const int ax = pos.getX() - 1;
int ay = pos.getY() - 1; const int ay = pos.getY() - 1;
int y_end{}, length{}; int y_end{}, length{};
if ( area->height + ay > vterm->height ) if ( area->height + ay > vterm->height )
@ -891,12 +890,12 @@ void FVTerm::getArea (const FRect& box, FTermArea* area)
if ( ! area ) if ( ! area )
return; return;
int x = box.getX(); const int x = box.getX();
int y = box.getY(); const int y = box.getY();
int w = int(box.getWidth()); const int w = int(box.getWidth());
int h = int(box.getHeight()); const int h = int(box.getHeight());
int dx = x - area->offset_left + 1; const int dx = x - area->offset_left + 1;
int dy = y - area->offset_top + 1; const int dy = y - area->offset_top + 1;
int y_end{}, length{}; int y_end{}, length{};
if ( x < 0 || y < 0 ) if ( x < 0 || y < 0 )
@ -917,7 +916,7 @@ void FVTerm::getArea (const FRect& box, FTermArea* area)
for (int _y = 0; _y < y_end; _y++) // line loop for (int _y = 0; _y < y_end; _y++) // line loop
{ {
int line_len = area->width + area->right_shadow; const int line_len = area->width + area->right_shadow;
auto tc = &vterm->data[(y + _y - 1) * vterm->width + x - 1]; // terminal character auto tc = &vterm->data[(y + _y - 1) * vterm->width + x - 1]; // terminal character
auto ac = &area->data[(dy + _y) * line_len + dx]; // area character auto ac = &area->data[(dy + _y) * line_len + dx]; // area character
std::memcpy (ac, tc, sizeof(*ac) * unsigned(length)); std::memcpy (ac, tc, sizeof(*ac) * unsigned(length));
@ -939,9 +938,9 @@ void FVTerm::putArea (FTermArea* area)
return; return;
int ax = area->offset_left; int ax = area->offset_left;
int ay = area->offset_top; const int ay = area->offset_top;
int width = area->width + area->right_shadow; const int width = area->width + area->right_shadow;
int height = area->height + area->bottom_shadow; const int height = area->height + area->bottom_shadow;
int ol{0}; // Outside left int ol{0}; // Outside left
int y_end{}; int y_end{};
@ -981,7 +980,7 @@ void FVTerm::putArea (FTermArea* area)
{ {
// Global terminal positions // Global terminal positions
int tx = ax + x; int tx = ax + x;
int ty = ay + y; const int ty = ay + y;
if ( tx < 0 || ty < 0 ) if ( tx < 0 || ty < 0 )
continue; continue;
@ -1027,9 +1026,9 @@ void FVTerm::putArea (const FPoint& pos, FTermArea* area)
return; return;
int ax = pos.getX() - 1; int ax = pos.getX() - 1;
int ay = pos.getY() - 1; const int ay = pos.getY() - 1;
int width = area->width + area->right_shadow; const int width = area->width + area->right_shadow;
int height = area->height + area->bottom_shadow; const int height = area->height + area->bottom_shadow;
int ol{0}; // outside left int ol{0}; // outside left
int y_end{}, length{}; int y_end{}, length{};
@ -1066,8 +1065,8 @@ void FVTerm::putArea (const FPoint& pos, FTermArea* area)
// Line has one or more transparent characters // Line has one or more transparent characters
for (int x{0}; x < length; x++) // column loop for (int x{0}; x < length; x++) // column loop
{ {
int cx = ax + x; const int cx = ax + x;
int cy = ay + y; const int cy = ay + y;
ac = &area->data[y * width + ol + x]; ac = &area->data[y * width + ol + x];
tc = &vterm->data[cy * vterm->width + cx]; tc = &vterm->data[cy * vterm->width + cx];
putAreaCharacter (FPoint(cx + 1, cy + 1), area->widget, ac, tc); putAreaCharacter (FPoint(cx + 1, cy + 1), area->widget, ac, tc);
@ -1098,14 +1097,14 @@ void FVTerm::scrollAreaForward (FTermArea* area)
if ( area->height <= 1 ) if ( area->height <= 1 )
return; return;
int length = area->width; const int length = area->width;
int total_width = area->width + area->right_shadow; const int total_width = area->width + area->right_shadow;
int y_max = area->height - 1; const int y_max = area->height - 1;
for (int y{0}; y < y_max; y++) for (int y{0}; y < y_max; y++)
{ {
int pos1 = y * total_width; const int pos1 = y * total_width;
int pos2 = (y + 1) * total_width; const int pos2 = (y + 1) * total_width;
auto sc = &area->data[pos2]; // source character auto sc = &area->data[pos2]; // source character
dc = &area->data[pos1]; dc = &area->data[pos1];
std::memcpy (dc, sc, sizeof(*dc) * unsigned(length)); std::memcpy (dc, sc, sizeof(*dc) * unsigned(length));
@ -1156,14 +1155,14 @@ void FVTerm::scrollAreaReverse (FTermArea* area)
if ( area->height <= 1 ) if ( area->height <= 1 )
return; return;
int length = area->width; const int length = area->width;
int total_width = area->width + area->right_shadow; const int total_width = area->width + area->right_shadow;
int y_max = area->height - 1; const int y_max = area->height - 1;
for (int y = y_max; y > 0; y--) for (int y = y_max; y > 0; y--)
{ {
int pos1 = (y - 1) * total_width; const int pos1 = (y - 1) * total_width;
int pos2 = y * total_width; const int pos2 = y * total_width;
auto sc = &area->data[pos1]; // source character auto sc = &area->data[pos1]; // source character
dc = &area->data[pos2]; dc = &area->data[pos2];
std::memcpy (dc, sc, sizeof(*dc) * unsigned(length)); std::memcpy (dc, sc, sizeof(*dc) * unsigned(length));
@ -1216,7 +1215,7 @@ void FVTerm::clearArea (FTermArea* area, int fillchar)
return; return;
} }
uInt w = uInt(area->width + area->right_shadow); const uInt w = uInt(area->width + area->right_shadow);
if ( area->right_shadow == 0 ) if ( area->right_shadow == 0 )
{ {
@ -1243,7 +1242,7 @@ void FVTerm::clearArea (FTermArea* area, int fillchar)
for (int i{0}; i < area->bottom_shadow; i++) for (int i{0}; i < area->bottom_shadow; i++)
{ {
int y = area->height + i; const int y = area->height + i;
area->changes[y].xmin = 0; area->changes[y].xmin = 0;
area->changes[y].xmax = w - 1; area->changes[y].xmax = w - 1;
area->changes[y].trans_count = w; area->changes[y].trans_count = w;
@ -1384,7 +1383,7 @@ FVTerm::covered_state FVTerm::isCovered ( const FPoint& pos
for (auto& win_obj : *FWidget::getWindowList()) for (auto& win_obj : *FWidget::getWindowList())
{ {
auto win = win_obj->getVWin(); const auto& win = win_obj->getVWin();
if ( ! win ) if ( ! win )
continue; continue;
@ -1392,18 +1391,17 @@ FVTerm::covered_state FVTerm::isCovered ( const FPoint& pos
if ( ! win->visible ) if ( ! win->visible )
continue; continue;
int win_x = win->offset_left; const int win_x = win->offset_left;
int win_y = win->offset_top; const int win_y = win->offset_top;
FRect geometry ( win_x const FRect geometry ( win_x , win_y
, win_y , std::size_t(win->width) + std::size_t(win->right_shadow)
, std::size_t(win->width) + std::size_t(win->right_shadow) , std::size_t(win->height) + std::size_t(win->bottom_shadow) );
, std::size_t(win->height) + std::size_t(win->bottom_shadow) );
if ( found && geometry.contains(pos) ) if ( found && geometry.contains(pos) )
{ {
int width = win->width + win->right_shadow; const int width = win->width + win->right_shadow;
int x = pos.getX(); const int x = pos.getX();
int y = pos.getY(); const int y = pos.getY();
auto tmp = &win->data[(y - win_y) * width + (x - win_x)]; auto tmp = &win->data[(y - win_y) * width + (x - win_x)];
if ( tmp->attr.bit.trans_shadow ) if ( tmp->attr.bit.trans_shadow )
@ -1432,11 +1430,11 @@ void FVTerm::updateOverlappedColor ( FTermArea* area
{ {
// Add the overlapping color to this character // Add the overlapping color to this character
int x = area_pos.getX(); const int x = area_pos.getX();
int y = area_pos.getY(); const int y = area_pos.getY();
int tx = terminal_pos.getX(); const int tx = terminal_pos.getX();
int ty = terminal_pos.getY(); const int ty = terminal_pos.getY();
int width = area->width + area->right_shadow; const int width = area->width + area->right_shadow;
// Area character // Area character
auto ac = &area->data[y * width + x]; auto ac = &area->data[y * width + x];
// Terminal character // Terminal character
@ -1470,8 +1468,8 @@ void FVTerm::updateOverlappedCharacter ( FTermArea* area
// Restore one character on vterm // Restore one character on vterm
// Terminal character // Terminal character
int tx = terminal_pos.getX(); const int tx = terminal_pos.getX();
int ty = terminal_pos.getY(); const int ty = terminal_pos.getY();
auto tc = &vterm->data[ty * vterm->width + tx]; auto tc = &vterm->data[ty * vterm->width + tx];
// Overlapped character // Overlapped character
auto oc = getCoveredCharacter (terminal_pos + FPoint(1, 1), area->widget); auto oc = getCoveredCharacter (terminal_pos + FPoint(1, 1), area->widget);
@ -1486,15 +1484,15 @@ void FVTerm::updateShadedCharacter ( FTermArea* area
{ {
// Get covered character + add the current color // Get covered character + add the current color
int x = area_pos.getX(); const int x = area_pos.getX();
int y = area_pos.getY(); const int y = area_pos.getY();
int tx = terminal_pos.getX(); const int tx = terminal_pos.getX();
int ty = terminal_pos.getY(); const int ty = terminal_pos.getY();
int width = area->width + area->right_shadow; const int width = area->width + area->right_shadow;
// Area character // Area character
auto ac = &area->data[y * width + x]; const auto ac = &area->data[y * width + x];
// Terminal character // Terminal character
auto tc = &vterm->data[ty * vterm->width + tx]; const auto tc = &vterm->data[ty * vterm->width + tx];
// Overlapped character // Overlapped character
auto oc = getCoveredCharacter (terminal_pos + FPoint(1, 1), area->widget); auto oc = getCoveredCharacter (terminal_pos + FPoint(1, 1), area->widget);
oc.fg_color = ac->fg_color; oc.fg_color = ac->fg_color;
@ -1521,13 +1519,13 @@ void FVTerm::updateInheritBackground ( FTermArea* area
{ {
// Add the covered background to this character // Add the covered background to this character
int x = area_pos.getX(); const int x = area_pos.getX();
int y = area_pos.getY(); const int y = area_pos.getY();
int tx = terminal_pos.getX(); const int tx = terminal_pos.getX();
int ty = terminal_pos.getY(); const int ty = terminal_pos.getY();
int width = area->width + area->right_shadow; const int width = area->width + area->right_shadow;
// Area character // Area character
auto ac = &area->data[y * width + x]; const auto ac = &area->data[y * width + x];
// Terminal character // Terminal character
auto tc = &vterm->data[ty * vterm->width + tx]; auto tc = &vterm->data[ty * vterm->width + tx];
// New character // New character
@ -1547,13 +1545,13 @@ void FVTerm::updateCharacter ( FTermArea* area
{ {
// Copy a area character to the virtual terminal // Copy a area character to the virtual terminal
int x = area_pos.getX(); const int x = area_pos.getX();
int y = area_pos.getY(); const int y = area_pos.getY();
int tx = terminal_pos.getX(); const int tx = terminal_pos.getX();
int ty = terminal_pos.getY(); const int ty = terminal_pos.getY();
int width = area->width + area->right_shadow; const int width = area->width + area->right_shadow;
// Area character // Area character
auto ac = &area->data[y * width + x]; const auto ac = &area->data[y * width + x];
// Terminal character // Terminal character
auto tc = &vterm->data[ty * vterm->width + tx]; auto tc = &vterm->data[ty * vterm->width + tx];
std::memcpy (tc, ac, sizeof(*tc)); std::memcpy (tc, ac, sizeof(*tc));
@ -1569,14 +1567,14 @@ bool FVTerm::updateVTermCharacter ( FTermArea* area
, const FPoint& area_pos , const FPoint& area_pos
, const FPoint& terminal_pos ) , const FPoint& terminal_pos )
{ {
int x = area_pos.getX(); const int x = area_pos.getX();
int y = area_pos.getY(); const int y = area_pos.getY();
int width = area->width + area->right_shadow; const int width = area->width + area->right_shadow;
// Area character // Area character
auto ac = &area->data[y * width + x]; auto ac = &area->data[y * width + x];
// Get covered state // Get covered state
auto is_covered = isCovered(terminal_pos, area); const auto is_covered = isCovered(terminal_pos, area);
if ( is_covered == fully_covered ) if ( is_covered == fully_covered )
return false; return false;
@ -1619,7 +1617,7 @@ void FVTerm::updateVTerm()
vdesktop->has_changes = false; vdesktop->has_changes = false;
} }
FWidget* widget = static_cast<FWidget*>(vterm->widget); const FWidget* widget = static_cast<FWidget*>(vterm->widget);
if ( ! widget->getWindowList() || widget->getWindowList()->empty() ) if ( ! widget->getWindowList() || widget->getWindowList()->empty() )
return; return;
@ -1696,8 +1694,8 @@ bool FVTerm::isInsideArea (const FPoint& pos, FTermArea* area)
{ {
// Check whether the coordinates are within the area // Check whether the coordinates are within the area
auto aw = std::size_t(area->width); const auto aw = std::size_t(area->width);
auto ah = std::size_t(area->height); const auto ah = std::size_t(area->height);
FRect area_geometry(0, 0, aw, ah); FRect area_geometry(0, 0, aw, ah);
if ( area_geometry.contains(pos) ) if ( area_geometry.contains(pos) )
@ -1711,8 +1709,8 @@ FChar FVTerm::generateCharacter (const FPoint& pos)
{ {
// Generates characters for a given position considering all areas // Generates characters for a given position considering all areas
int x = pos.getX(); const int x = pos.getX();
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 ( ! FWidget::getWindowList() || FWidget::getWindowList()->empty() )
@ -1720,22 +1718,21 @@ FChar FVTerm::generateCharacter (const FPoint& pos)
for (auto& win_obj : *FWidget::getWindowList()) for (auto& win_obj : *FWidget::getWindowList())
{ {
auto win = win_obj->getVWin(); const auto& win = win_obj->getVWin();
if ( ! win || ! win->visible ) if ( ! win || ! win->visible )
continue; continue;
int win_x = win->offset_left; const int win_x = win->offset_left;
int win_y = win->offset_top; const int win_y = win->offset_top;
FRect geometry ( win_x const FRect geometry ( win_x, win_y
, win_y , std::size_t(win->width) + std::size_t(win->right_shadow)
, std::size_t(win->width) + std::size_t(win->right_shadow) , std::size_t(win->height) + std::size_t(win->bottom_shadow) );
, std::size_t(win->height) + std::size_t(win->bottom_shadow) );
// Window is visible and contains current character // Window is visible and contains current character
if ( geometry.contains(x, y) ) if ( geometry.contains(x, y) )
{ {
int line_len = win->width + win->right_shadow; const int line_len = win->width + win->right_shadow;
auto tmp = &win->data[(y - win_y) * line_len + (x - win_x)]; auto tmp = &win->data[(y - win_y) * line_len + (x - win_x)];
if ( ! tmp->attr.bit.transparent ) // Current character not transparent if ( ! tmp->attr.bit.transparent ) // Current character not transparent
@ -1779,21 +1776,15 @@ FChar FVTerm::generateCharacter (const FPoint& pos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FChar FVTerm::getCharacter ( character_type char_type FChar FVTerm::getCharacter ( character_type char_type
, const FPoint& pos , const FPoint& pos
, FVTerm* obj ) , FVTerm* obj )
{ {
// Gets the overlapped or the covered character for a given position // Gets the overlapped or the covered character for a given position
int x = pos.getX() - 1; const int x = pos.getX() - 1;
int y = pos.getY() - 1; const int y = pos.getY() - 1;
int xx = x; int xx = ( x > 0 ) ? x : 0;
int yy = y; int yy = ( y > 0 ) ? y : 0;
if ( xx < 0 )
xx = 0;
if ( yy < 0 )
yy = 0;
if ( xx >= vterm->width ) if ( xx >= vterm->width )
xx = vterm->width - 1; xx = vterm->width - 1;
@ -1807,8 +1798,8 @@ FChar FVTerm::getCharacter ( character_type char_type
return *cc; return *cc;
// Get the window layer of this object // Get the window layer of this object
auto w = static_cast<FWidget*>(obj); const auto& w = static_cast<FWidget*>(obj);
int layer = FWindow::getWindowLayer(w); const int layer = FWindow::getWindowLayer(w);
for (auto&& win_obj : *FWidget::getWindowList()) for (auto&& win_obj : *FWidget::getWindowList())
{ {
@ -1823,15 +1814,14 @@ FChar FVTerm::getCharacter ( character_type char_type
if ( obj && win_obj != obj && significant_char ) if ( obj && win_obj != obj && significant_char )
{ {
auto win = win_obj->getVWin(); const auto& win = win_obj->getVWin();
if ( ! win || ! win->visible ) if ( ! win || ! win->visible )
continue; continue;
FRect geometry ( win->offset_left const FRect geometry ( win->offset_left, win->offset_top
, win->offset_top , std::size_t(win->width) + std::size_t(win->right_shadow)
, std::size_t(win->width) + std::size_t(win->right_shadow) , std::size_t(win->height) + std::size_t(win->bottom_shadow) );
, std::size_t(win->height) + std::size_t(win->bottom_shadow) );
// Window visible and contains current character // Window visible and contains current character
if ( geometry.contains(x, y) ) if ( geometry.contains(x, y) )
@ -2016,11 +2006,11 @@ void FVTerm::putAreaCharacter ( const FPoint& pos, FVTerm* obj
void FVTerm::getAreaCharacter ( const FPoint& pos, FTermArea* area void FVTerm::getAreaCharacter ( const FPoint& pos, FTermArea* area
, FChar*& cc ) , FChar*& cc )
{ {
int area_x = area->offset_left; const int area_x = area->offset_left;
int area_y = area->offset_top; const int area_y = area->offset_top;
int line_len = area->width + area->right_shadow; const int line_len = area->width + area->right_shadow;
int x = pos.getX(); const int x = pos.getX();
int y = pos.getY(); const int y = pos.getY();
auto tmp = &area->data[(y - area_y) * line_len + (x - area_x)]; auto tmp = &area->data[(y - area_y) * line_len + (x - area_x)];
// Current character not transparent // Current character not transparent
@ -2053,12 +2043,12 @@ bool FVTerm::clearTerm (int fillchar)
{ {
// Clear the real terminal and put cursor at home // Clear the real terminal and put cursor at home
auto& cl = TCAP(fc::t_clear_screen); const auto& cl = TCAP(fc::t_clear_screen);
auto& cd = TCAP(fc::t_clr_eos); const auto& cd = TCAP(fc::t_clr_eos);
auto& cb = TCAP(fc::t_clr_eol); const auto& cb = TCAP(fc::t_clr_eol);
bool ut = FTermcap::background_color_erase; const bool ut = FTermcap::background_color_erase;
auto next = &next_attribute; auto next = &next_attribute;
bool normal = FTerm::isNormal(next); const bool normal = FTerm::isNormal(next);
appendAttributes(next); appendAttributes(next);
if ( ! ( (cl || cd || cb) && (normal || ut) ) if ( ! ( (cl || cd || cb) && (normal || ut) )
@ -2099,7 +2089,7 @@ bool FVTerm::clearTerm (int fillchar)
bool FVTerm::clearFullArea (FTermArea* area, FChar& nc) bool FVTerm::clearFullArea (FTermArea* area, FChar& nc)
{ {
// Clear area // Clear area
int area_size = area->width * area->height; const int area_size = area->width * area->height;
std::fill_n (area->data, area_size, nc); std::fill_n (area->data, area_size, nc);
if ( area != vdesktop ) // Is the area identical to the desktop? if ( area != vdesktop ) // Is the area identical to the desktop?
@ -2130,12 +2120,12 @@ bool FVTerm::clearFullArea (FTermArea* area, FChar& nc)
void FVTerm::clearAreaWithShadow (FTermArea* area, FChar& nc) void FVTerm::clearAreaWithShadow (FTermArea* area, FChar& nc)
{ {
FChar t_char = nc; FChar t_char = nc;
int total_width = area->width + area->right_shadow; const int total_width = area->width + area->right_shadow;
t_char.attr.bit.transparent = true; t_char.attr.bit.transparent = true;
for (int y{0}; y < area->height; y++) for (int y{0}; y < area->height; y++)
{ {
int pos = y * total_width; const int pos = y * total_width;
// Clear area // Clear area
std::fill_n (&area->data[pos], total_width, nc); std::fill_n (&area->data[pos], total_width, nc);
// Make right shadow transparent // Make right shadow transparent
@ -2145,7 +2135,7 @@ void FVTerm::clearAreaWithShadow (FTermArea* area, FChar& nc)
// Make bottom shadow transparent // Make bottom shadow transparent
for (int y{0}; y < area->bottom_shadow; y++) for (int y{0}; y < area->bottom_shadow; y++)
{ {
int pos = total_width * (y + area->height); const int pos = total_width * (y + area->height);
std::fill_n (&area->data[pos], total_width, t_char); std::fill_n (&area->data[pos], total_width, t_char);
} }
} }
@ -2157,14 +2147,14 @@ bool FVTerm::canClearToEOL (uInt xmin, uInt y)
// => clear to end of line // => clear to end of line
FTermArea*& vt = vterm; FTermArea*& vt = vterm;
auto& ce = TCAP(fc::t_clr_eol); const auto& ce = TCAP(fc::t_clr_eol);
auto min_char = &vt->data[y * uInt(vt->width) + xmin]; auto min_char = &vt->data[y * uInt(vt->width) + xmin];
if ( ce && min_char->ch == ' ' ) if ( ce && min_char->ch == ' ' )
{ {
uInt beginning_whitespace = 1; uInt beginning_whitespace = 1;
bool normal = FTerm::isNormal(min_char); const bool normal = FTerm::isNormal(min_char);
bool& ut = FTermcap::background_color_erase; const bool& ut = FTermcap::background_color_erase;
for (uInt x = xmin + 1; x < uInt(vt->width); x++) for (uInt x = xmin + 1; x < uInt(vt->width); x++)
{ {
@ -2192,14 +2182,14 @@ bool FVTerm::canClearLeadingWS (uInt& xmin, uInt y)
// => clear from xmin to beginning of line // => clear from xmin to beginning of line
FTermArea*& vt = vterm; FTermArea*& vt = vterm;
auto& cb = TCAP(fc::t_clr_bol); const auto& cb = TCAP(fc::t_clr_bol);
auto first_char = &vt->data[y * uInt(vt->width)]; auto first_char = &vt->data[y * uInt(vt->width)];
if ( cb && first_char->ch == ' ' ) if ( cb && first_char->ch == ' ' )
{ {
uInt leading_whitespace = 1; uInt leading_whitespace = 1;
bool normal = FTerm::isNormal(first_char); const bool normal = FTerm::isNormal(first_char);
bool& ut = FTermcap::background_color_erase; const bool& ut = FTermcap::background_color_erase;
for (uInt x{1}; x < uInt(vt->width); x++) for (uInt x{1}; x < uInt(vt->width); x++)
{ {
@ -2230,14 +2220,14 @@ bool FVTerm::canClearTrailingWS (uInt& xmax, uInt y)
// => clear from xmax to end of line // => clear from xmax to end of line
FTermArea*& vt = vterm; FTermArea*& vt = vterm;
auto& ce = TCAP(fc::t_clr_eol); const auto& ce = TCAP(fc::t_clr_eol);
auto last_char = &vt->data[(y + 1) * uInt(vt->width) - 1]; auto last_char = &vt->data[(y + 1) * uInt(vt->width) - 1];
if ( ce && last_char->ch == ' ' ) if ( ce && last_char->ch == ' ' )
{ {
uInt trailing_whitespace = 1; uInt trailing_whitespace = 1;
bool normal = FTerm::isNormal(last_char); const bool normal = FTerm::isNormal(last_char);
bool& ut = FTermcap::background_color_erase; const bool& ut = FTermcap::background_color_erase;
for (uInt x = uInt(vt->width) - 1; x > 0 ; x--) for (uInt x = uInt(vt->width) - 1; x > 0 ; x--)
{ {
@ -2302,8 +2292,8 @@ void FVTerm::printRange ( uInt xmin, uInt xmax, uInt y
for (uInt x = xmin; x <= xmax; x++) for (uInt x = xmin; x <= xmax; x++)
{ {
FTermArea*& vt = vterm; FTermArea*& vt = vterm;
auto& ec = TCAP(fc::t_erase_chars); const auto& ec = TCAP(fc::t_erase_chars);
auto& rp = TCAP(fc::t_repeat_char); const auto& rp = TCAP(fc::t_repeat_char);
auto print_char = &vt->data[y * uInt(vt->width) + x]; auto print_char = &vt->data[y * uInt(vt->width) + x];
print_char->attr.bit.printed = true; print_char->attr.bit.printed = true;
replaceNonPrintableFullwidth (x, print_char); replaceNonPrintableFullwidth (x, print_char);
@ -2384,7 +2374,7 @@ void FVTerm::printCharacter ( uInt& x, uInt y, bool min_and_not_max
void FVTerm::printFullWidthCharacter ( uInt& x, uInt y void FVTerm::printFullWidthCharacter ( uInt& x, uInt y
, FChar*& print_char ) , FChar*& print_char )
{ {
auto vt = vterm; const auto vt = vterm;
auto next_char = &vt->data[y * uInt(vt->width) + x + 1]; auto next_char = &vt->data[y * uInt(vt->width) + x + 1];
if ( print_char->attr.byte[0] == next_char->attr.byte[0] if ( print_char->attr.byte[0] == next_char->attr.byte[0]
@ -2423,7 +2413,7 @@ void FVTerm::printFullWidthCharacter ( uInt& x, uInt y
void FVTerm::printFullWidthPaddingCharacter ( uInt& x, uInt y void FVTerm::printFullWidthPaddingCharacter ( uInt& x, uInt y
, FChar*& print_char) , FChar*& print_char)
{ {
auto vt = vterm; const auto vt = vterm;
auto prev_char = &vt->data[y * uInt(vt->width) + x - 1]; auto prev_char = &vt->data[y * uInt(vt->width) + x - 1];
if ( print_char->attr.byte[0] == prev_char->attr.byte[0] if ( print_char->attr.byte[0] == prev_char->attr.byte[0]
@ -2434,8 +2424,8 @@ void FVTerm::printFullWidthPaddingCharacter ( uInt& x, uInt y
&& isFullWidthPaddingChar(print_char) ) && isFullWidthPaddingChar(print_char) )
{ {
// Move cursor one character to the left // Move cursor one character to the left
auto& le = TCAP(fc::t_cursor_left); const auto& le = TCAP(fc::t_cursor_left);
auto& RI = TCAP(fc::t_parm_right_cursor); const auto& RI = TCAP(fc::t_parm_right_cursor);
if ( le ) if ( le )
appendOutputBuffer (le); appendOutputBuffer (le);
@ -2468,14 +2458,14 @@ void FVTerm::printFullWidthPaddingCharacter ( uInt& x, uInt y
void FVTerm::printHalfCovertFullWidthCharacter ( uInt& x, uInt y void FVTerm::printHalfCovertFullWidthCharacter ( uInt& x, uInt y
, FChar*& print_char ) , FChar*& print_char )
{ {
auto vt = vterm; const auto vt = vterm;
auto prev_char = &vt->data[y * uInt(vt->width) + x - 1]; auto prev_char = &vt->data[y * uInt(vt->width) + x - 1];
if ( isFullWidthChar(prev_char) && ! isFullWidthPaddingChar(print_char) ) if ( isFullWidthChar(prev_char) && ! isFullWidthPaddingChar(print_char) )
{ {
// Move cursor one character to the left // Move cursor one character to the left
auto& le = TCAP(fc::t_cursor_left); const auto& le = TCAP(fc::t_cursor_left);
auto& RI = TCAP(fc::t_parm_right_cursor); const auto& RI = TCAP(fc::t_parm_right_cursor);
if ( le ) if ( le )
appendOutputBuffer (le); appendOutputBuffer (le);
@ -2518,15 +2508,15 @@ FVTerm::exit_state FVTerm::eraseCharacters ( uInt& x, uInt xmax, uInt y
{ {
// Erase a number of characters to draw simple whitespaces // Erase a number of characters to draw simple whitespaces
FTermArea*& vt = vterm; const auto& vt = vterm;
auto& ec = TCAP(fc::t_erase_chars); const auto& ec = TCAP(fc::t_erase_chars);
auto print_char = &vt->data[y * uInt(vt->width) + x]; auto print_char = &vt->data[y * uInt(vt->width) + x];
if ( ! ec || print_char->ch != ' ' ) if ( ! ec || print_char->ch != ' ' )
return not_used; return not_used;
uInt whitespace{1}; uInt whitespace{1};
bool normal = FTerm::isNormal(print_char); const bool normal = FTerm::isNormal(print_char);
for (uInt i = x + 1; i <= xmax; i++) for (uInt i = x + 1; i <= xmax; i++)
{ {
@ -2545,8 +2535,8 @@ FVTerm::exit_state FVTerm::eraseCharacters ( uInt& x, uInt xmax, uInt y
} }
else else
{ {
uInt start_pos = x; const uInt start_pos = x;
bool& ut = FTermcap::background_color_erase; const bool& ut = FTermcap::background_color_erase;
if ( whitespace > erase_char_length + cursor_address_length if ( whitespace > erase_char_length + cursor_address_length
&& (ut || normal) ) && (ut || normal) )
@ -2580,8 +2570,8 @@ FVTerm::exit_state FVTerm::repeatCharacter (uInt& x, uInt xmax, uInt y)
{ {
// Repeat one character n-fold // Repeat one character n-fold
FTermArea*& vt = vterm; const auto& vt = vterm;
auto& rp = TCAP(fc::t_repeat_char); const auto& rp = TCAP(fc::t_repeat_char);
auto print_char = &vt->data[y * uInt(vt->width) + x]; auto print_char = &vt->data[y * uInt(vt->width) + x];
if ( ! rp ) if ( ! rp )
@ -2606,7 +2596,7 @@ FVTerm::exit_state FVTerm::repeatCharacter (uInt& x, uInt xmax, uInt y)
} }
else else
{ {
uInt start_pos = x; const uInt start_pos = x;
if ( repetitions > repeat_char_length if ( repetitions > repeat_char_length
&& print_char->ch < 128 ) && print_char->ch < 128 )
@ -2648,7 +2638,7 @@ inline bool FVTerm::isFullWidthPaddingChar (FChar*& ch)
void FVTerm::cursorWrap() void FVTerm::cursorWrap()
{ {
// Wrap the cursor // Wrap the cursor
FTermArea*& vt = vterm; const auto& vt = vterm;
if ( term_pos->getX() >= vt->width ) if ( term_pos->getX() >= vt->width )
{ {
@ -2675,10 +2665,10 @@ void FVTerm::cursorWrap()
bool FVTerm::printWrap (FTermArea* area) bool FVTerm::printWrap (FTermArea* area)
{ {
bool end_of_area{false}; bool end_of_area{false};
int width = area->width const int width = area->width;
, height = area->height const int height = area->height;
, rsh = area->right_shadow const int rsh = area->right_shadow;
, bsh = area->bottom_shadow; const int bsh = area->bottom_shadow;
// Line break at right margin // Line break at right margin
if ( area->cursor_x > width + rsh ) if ( area->cursor_x > width + rsh )
@ -2730,7 +2720,7 @@ void FVTerm::updateTerminalLine (uInt y)
{ {
// Updates pending changes from line y to the terminal // Updates pending changes from line y to the terminal
FTermArea*& vt = vterm; const auto& vt = vterm;
uInt& xmin = vt->changes[y].xmin; uInt& xmin = vt->changes[y].xmin;
uInt& xmax = vt->changes[y].xmax; uInt& xmax = vt->changes[y].xmax;
@ -2738,7 +2728,7 @@ void FVTerm::updateTerminalLine (uInt y)
{ {
bool draw_leading_ws = false; bool draw_leading_ws = false;
bool draw_trailing_ws = false; bool draw_trailing_ws = false;
auto& ce = TCAP(fc::t_clr_eol); const auto& ce = TCAP(fc::t_clr_eol);
auto first_char = &vt->data[y * uInt(vt->width)]; auto first_char = &vt->data[y * uInt(vt->width)];
auto last_char = &vt->data[(y + 1) * uInt(vt->width) - 1]; auto last_char = &vt->data[(y + 1) * uInt(vt->width) - 1];
auto min_char = &vt->data[y * uInt(vt->width) + xmin]; auto min_char = &vt->data[y * uInt(vt->width) + xmin];
@ -2767,7 +2757,7 @@ void FVTerm::updateTerminalLine (uInt y)
{ {
if ( draw_leading_ws ) if ( draw_leading_ws )
{ {
auto& cb = TCAP(fc::t_clr_bol); const auto& cb = TCAP(fc::t_clr_bol);
appendAttributes (first_char); appendAttributes (first_char);
appendOutputBuffer (cb); appendOutputBuffer (cb);
markAsPrinted (0, xmin, y); markAsPrinted (0, xmin, y);
@ -2797,8 +2787,8 @@ bool FVTerm::updateTerminalCursor()
// Updates the input cursor visibility and the position // Updates the input cursor visibility and the position
if ( vterm && vterm->input_cursor_visible ) if ( vterm && vterm->input_cursor_visible )
{ {
int x = vterm->input_cursor_x; const int x = vterm->input_cursor_x;
int y = vterm->input_cursor_y; const int y = vterm->input_cursor_y;
if ( isInsideTerminal(FPoint(x, y)) ) if ( isInsideTerminal(FPoint(x, y)) )
{ {
@ -2818,7 +2808,7 @@ bool FVTerm::isInsideTerminal (const FPoint& pos)
{ {
// Check whether the coordinates are within the virtual terminal // Check whether the coordinates are within the virtual terminal
FRect term_geometry (0, 0, getColumnNumber(), getLineNumber()); const FRect term_geometry (0, 0, getColumnNumber(), getLineNumber());
if ( term_geometry.contains(pos) ) if ( term_geometry.contains(pos) )
return true; return true;
@ -2829,12 +2819,12 @@ bool FVTerm::isInsideTerminal (const FPoint& pos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FVTerm::isTermSizeChanged() inline bool FVTerm::isTermSizeChanged()
{ {
auto data = getFTerm().getFTermData(); const auto& data = getFTerm().getFTermData();
if ( ! data ) if ( ! data )
return false; return false;
auto old_term_geometry = data->getTermGeometry(); const auto& old_term_geometry = data->getTermGeometry();
FTerm::detectTermSize(); FTerm::detectTermSize();
auto term_geometry = data->getTermGeometry(); auto term_geometry = data->getTermGeometry();
term_geometry.move (-1, -1); term_geometry.move (-1, -1);
@ -2881,13 +2871,13 @@ inline void FVTerm::newFontChanges (FChar*& next_char)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::charsetChanges (FChar*& next_char) inline void FVTerm::charsetChanges (FChar*& next_char)
{ {
wchar_t& ch = next_char->ch; const wchar_t& ch = next_char->ch;
next_char->encoded_char = ch; next_char->encoded_char = ch;
if ( getEncoding() == fc::UTF8 ) if ( getEncoding() == fc::UTF8 )
return; return;
wchar_t ch_enc = FTerm::charEncode(ch); const wchar_t ch_enc = FTerm::charEncode(ch);
if ( ch_enc == ch ) if ( ch_enc == ch )
return; return;
@ -2925,8 +2915,8 @@ inline void FVTerm::charsetChanges (FChar*& next_char)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::appendCharacter (FChar*& next_char) inline void FVTerm::appendCharacter (FChar*& next_char)
{ {
int term_width = vterm->width - 1; const int term_width = vterm->width - 1;
int term_height = vterm->height - 1; const int term_height = vterm->height - 1;
if ( term_pos->getX() == term_width if ( term_pos->getX() == term_width
&& term_pos->getY() == term_height ) && term_pos->getY() == term_height )
@ -2953,7 +2943,7 @@ inline void FVTerm::appendAttributes (FChar*& next_attr)
auto term_attr = &term_attribute; auto term_attr = &term_attribute;
// generate attribute string for the next character // generate attribute string for the next character
char* attr_str = FTerm::changeAttribute (term_attr, next_attr); const char* attr_str = FTerm::changeAttribute (term_attr, next_attr);
if ( attr_str ) if ( attr_str )
appendOutputBuffer (attr_str); appendOutputBuffer (attr_str);
@ -2962,8 +2952,8 @@ inline void FVTerm::appendAttributes (FChar*& next_attr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FVTerm::appendLowerRight (FChar*& screen_char) int FVTerm::appendLowerRight (FChar*& screen_char)
{ {
auto& SA = TCAP(fc::t_enter_am_mode); const auto& SA = TCAP(fc::t_enter_am_mode);
auto& RA = TCAP(fc::t_exit_am_mode); const auto& RA = TCAP(fc::t_exit_am_mode);
if ( ! FTermcap::automatic_right_margin ) if ( ! FTermcap::automatic_right_margin )
{ {
@ -2977,14 +2967,14 @@ int FVTerm::appendLowerRight (FChar*& screen_char)
} }
else else
{ {
auto& IC = TCAP(fc::t_parm_ich); const auto& IC = TCAP(fc::t_parm_ich);
auto& im = TCAP(fc::t_enter_insert_mode); const auto& im = TCAP(fc::t_enter_insert_mode);
auto& ei = TCAP(fc::t_exit_insert_mode); const auto& ei = TCAP(fc::t_exit_insert_mode);
auto& ip = TCAP(fc::t_insert_padding); const auto& ip = TCAP(fc::t_insert_padding);
auto& ic = TCAP(fc::t_insert_character); const auto& ic = TCAP(fc::t_insert_character);
int x = int(getColumnNumber()) - 2; const int x = int(getColumnNumber()) - 2;
int y = int(getLineNumber()) - 1; const int y = int(getLineNumber()) - 1;
setTermXY (x, y); setTermXY (x, y);
appendChar (screen_char); appendChar (screen_char);
term_pos->x_ref()++; term_pos->x_ref()++;

View File

@ -243,7 +243,7 @@ std::vector<bool>& FWidget::doubleFlatLine_ref (fc::sides side)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FPoint FWidget::getPrintPos() FPoint FWidget::getPrintPos()
{ {
const auto cur = getPrintCursor(); const auto& cur = getPrintCursor();
return FPoint ( cur.getX() - woffset.getX1() - getX() + 1 return FPoint ( cur.getX() - woffset.getX1() - getX() + 1
, cur.getY() - woffset.getY1() - getY() + 1 ); , cur.getY() - woffset.getY1() - getY() + 1 );
} }
@ -545,8 +545,8 @@ void FWidget::setGeometry (const FPoint& p, const FSize& s, bool adjust)
{ {
// Sets the geometry of the widget relative to its parent // Sets the geometry of the widget relative to its parent
int x = p.getX(); const int x = p.getX();
int y = p.getY(); const int y = p.getY();
std::size_t w = s.getWidth(); std::size_t w = s.getWidth();
std::size_t h = s.getHeight(); std::size_t h = s.getHeight();
w = std::min (w, size_hints.max_width); w = std::min (w, size_hints.max_width);
@ -572,8 +572,8 @@ void FWidget::setGeometry (const FPoint& p, const FSize& s, bool adjust)
( h < 1 ) ? wsize.setHeight(1) : wsize.setHeight(h); ( h < 1 ) ? wsize.setHeight(1) : wsize.setHeight(h);
adjust_wsize = wsize; adjust_wsize = wsize;
int term_x = getTermX(); const int term_x = getTermX();
int term_y = getTermY(); const int term_y = getTermY();
wclient_offset.setCoordinates ( term_x - 1 + padding.left wclient_offset.setCoordinates ( term_x - 1 + padding.left
, term_y - 1 + padding.top , term_y - 1 + padding.top
@ -602,7 +602,7 @@ bool FWidget::setCursorPos (const FPoint& pos)
if ( ! FWindow::getWindowWidget(this) ) if ( ! FWindow::getWindowWidget(this) )
return false; return false;
auto area = getPrintArea(); const auto& area = getPrintArea();
if ( area->widget ) if ( area->widget )
{ {
@ -628,8 +628,8 @@ bool FWidget::setCursorPos (const FPoint& pos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setPrintPos (const FPoint& pos) void FWidget::setPrintPos (const FPoint& pos)
{ {
FPoint p{ woffset.getX1() + getX() + pos.getX() - 1, const FPoint p{ woffset.getX1() + getX() + pos.getX() - 1,
woffset.getY1() + getY() + pos.getY() - 1 }; woffset.getY1() + getY() + pos.getY() - 1 };
setPrintCursor(p); setPrintCursor(p);
} }
@ -678,7 +678,7 @@ void FWidget::setDoubleFlatLine (fc::sides side, int pos, bool bit)
assert ( pos >= 1 ); assert ( pos >= 1 );
uLong length{}; uLong length{};
uLong index = uLong(pos - 1); const uLong index = uLong(pos - 1);
switch ( side ) switch ( side )
{ {
@ -754,7 +754,7 @@ int FWidget::numOfFocusableChildren()
{ {
if ( child->isWidget() ) if ( child->isWidget() )
{ {
auto widget = static_cast<FWidget*>(child); const auto& widget = static_cast<FWidget*>(child);
if ( widget->isShown() if ( widget->isShown()
&& widget->acceptFocus() && widget->acceptFocus()
@ -961,7 +961,7 @@ void FWidget::resize()
{ {
if ( isRootWidget() ) if ( isRootWidget() )
{ {
FRect old_term_geometry (getTermGeometry()); const FRect old_term_geometry (getTermGeometry());
detectTermSize(); detectTermSize();
FRect term_geometry (getTermGeometry()); FRect term_geometry (getTermGeometry());
term_geometry.move (-1, -1); term_geometry.move (-1, -1);
@ -997,7 +997,7 @@ void FWidget::show()
initScreenSettings(); initScreenSettings();
// draw the vdesktop // draw the vdesktop
auto r = getRootWidget(); const auto& r = getRootWidget();
setColor(r->getForegroundColor(), r->getBackgroundColor()); setColor(r->getForegroundColor(), r->getBackgroundColor());
clearArea (getVirtualDesktop()); clearArea (getVirtualDesktop());
init_desktop = true; init_desktop = true;
@ -1072,7 +1072,7 @@ bool FWidget::focusFirstChild()
return false; return false;
auto iter = FObject::begin(); auto iter = FObject::begin();
auto last = FObject::end(); const auto last = FObject::end();
while ( iter != last ) while ( iter != last )
{ {
@ -1104,6 +1104,7 @@ bool FWidget::focusFirstChild()
++iter; ++iter;
} }
return false; return false;
} }
@ -1114,7 +1115,7 @@ bool FWidget::focusLastChild()
return false; return false;
auto iter = FObject::end(); auto iter = FObject::end();
auto first = FObject::begin(); const auto first = FObject::begin();
do do
{ {
@ -1217,7 +1218,7 @@ void FWidget::delPreprocessingHandler (FVTerm* instance)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::isChildPrintArea() const bool FWidget::isChildPrintArea() const
{ {
auto p_obj = static_cast<FWidget*>(getParent()); const auto& p_obj = static_cast<FWidget*>(getParent());
if ( p_obj if ( p_obj
&& p_obj->getChildPrintArea() && p_obj->getChildPrintArea()
@ -1254,7 +1255,7 @@ void FWidget::setMenuBar (FMenuBar* mbar)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setParentOffset() void FWidget::setParentOffset()
{ {
auto p = getParentWidget(); const auto& p = getParentWidget();
if ( p ) if ( p )
woffset = p->wclient_offset; woffset = p->wclient_offset;
@ -1263,16 +1264,16 @@ void FWidget::setParentOffset()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setTermOffset() void FWidget::setTermOffset()
{ {
auto r = getRootWidget(); const auto& r = getRootWidget();
int w = int(r->getWidth()); const int w = int(r->getWidth());
int h = int(r->getHeight()); const int h = int(r->getHeight());
woffset.setCoordinates (0, 0, w - 1, h - 1); woffset.setCoordinates (0, 0, w - 1, h - 1);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setTermOffsetWithPadding() void FWidget::setTermOffsetWithPadding()
{ {
auto r = getRootWidget(); const auto& r = getRootWidget();
woffset.setCoordinates ( r->getLeftPadding() woffset.setCoordinates ( r->getLeftPadding()
, r->getTopPadding() , r->getTopPadding()
, int(r->getWidth()) - 1 - r->getRightPadding() , int(r->getWidth()) - 1 - r->getRightPadding()
@ -1284,7 +1285,7 @@ void FWidget::adjustSize()
{ {
if ( ! isRootWidget() ) if ( ! isRootWidget() )
{ {
auto p = getParentWidget(); const auto& p = getParentWidget();
if ( isWindowWidget() ) if ( isWindowWidget() )
{ {
@ -1356,7 +1357,7 @@ void FWidget::hideArea (const FSize& size)
return; return;
FColor fg{}, bg{}; FColor fg{}, bg{};
auto parent_widget = getParentWidget(); const auto& parent_widget = getParentWidget();
if ( parent_widget ) if ( parent_widget )
{ {
@ -1388,7 +1389,7 @@ bool FWidget::focusNextChild()
if ( isDialogWidget() || ! hasParent() ) if ( isDialogWidget() || ! hasParent() )
return false; return false;
auto parent = getParentWidget(); const auto& parent = getParentWidget();
if ( ! parent if ( ! parent
|| ! parent->hasChildren() || ! parent->hasChildren()
@ -1396,7 +1397,7 @@ bool FWidget::focusNextChild()
return false; return false;
auto iter = parent->begin(); auto iter = parent->begin();
auto last = parent->end(); const auto last = parent->end();
while ( iter != last ) while ( iter != last )
{ {
@ -1406,7 +1407,7 @@ bool FWidget::focusNextChild()
continue; continue;
} }
auto w = static_cast<FWidget*>(*iter); const auto& w = static_cast<FWidget*>(*iter);
if ( w != this ) if ( w != this )
{ {
@ -1451,15 +1452,15 @@ bool FWidget::focusPrevChild()
if ( isDialogWidget() || ! hasParent() ) if ( isDialogWidget() || ! hasParent() )
return false; return false;
auto parent = getParentWidget(); const auto& parent = getParentWidget();
if ( ! parent if ( ! parent
|| ! parent->hasChildren() || ! parent->hasChildren()
|| parent->numOfFocusableChildren() <= 1 ) || parent->numOfFocusableChildren() <= 1 )
return false; return false;
auto iter = parent->end(); auto iter = parent->end();
auto first = parent->begin(); const auto first = parent->begin();
do do
{ {
@ -1468,7 +1469,7 @@ bool FWidget::focusPrevChild()
if ( ! (*iter)->isWidget() ) if ( ! (*iter)->isWidget() )
continue; continue;
auto w = static_cast<FWidget*>(*iter); const auto& w = static_cast<FWidget*>(*iter);
if ( w != this ) if ( w != this )
continue; continue;
@ -1495,7 +1496,7 @@ bool FWidget::focusPrevChild()
|| ! prev->isShown() || ! prev->isShown()
|| prev->isWindowWidget() ); || prev->isWindowWidget() );
bool accpt = changeFocus (prev, parent, fc::FocusPreviousWidget); const bool accpt = changeFocus (prev, parent, fc::FocusPreviousWidget);
if ( ! accpt ) if ( ! accpt )
return false; return false;
@ -1795,7 +1796,7 @@ inline void FWidget::insufficientSpaceAdjust()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::KeyPressEvent (FKeyEvent* kev) void FWidget::KeyPressEvent (FKeyEvent* kev)
{ {
FWidget* widget(this); FWidget* widget(this);
while ( widget ) while ( widget )
{ {
@ -1803,7 +1804,7 @@ void FWidget::KeyPressEvent (FKeyEvent* kev)
if ( ! kev->isAccepted() ) if ( ! kev->isAccepted() )
{ {
FKey key = kev->key(); const FKey key = kev->key();
if ( [&] () -> bool if ( [&] () -> bool
{ {
@ -1845,7 +1846,7 @@ void FWidget::KeyDownEvent (FKeyEvent* kev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::emitWheelCallback (FWheelEvent* ev) void FWidget::emitWheelCallback (FWheelEvent* ev)
{ {
int wheel = ev->getWheel(); const int wheel = ev->getWheel();
if ( wheel == fc::WheelUp ) if ( wheel == fc::WheelUp )
emitCallback("mouse-wheel-up"); emitCallback("mouse-wheel-up");
@ -1948,8 +1949,8 @@ void FWidget::drawWindows()
if ( window->isShown() ) if ( window->isShown() )
{ {
auto v_win = window->getVWin(); auto v_win = window->getVWin();
int w = v_win->width + v_win->right_shadow; const int w = v_win->width + v_win->right_shadow;
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(); window->redraw();
} }
@ -2011,7 +2012,7 @@ void FWidget::setStatusbarText (bool enable)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void detectTermSize() void detectTermSize()
{ {
auto r = rootObject; const auto& r = rootObject;
FTerm::detectTermSize(); FTerm::detectTermSize();
r->adjust_wsize.setRect (1, 1, r->getDesktopWidth(), r->getDesktopHeight()); r->adjust_wsize.setRect (1, 1, r->getDesktopWidth(), r->getDesktopHeight());
r->woffset.setRect (0, 0, r->getDesktopWidth(), r->getDesktopHeight()); r->woffset.setRect (0, 0, r->getDesktopWidth(), r->getDesktopHeight());

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 2019 Markus Gans * * Copyright 2019-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -28,7 +28,7 @@ namespace finalcut
// FWidget non-member functions // FWidget non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool isFocusNextKey (FKey key) bool isFocusNextKey (const FKey key)
{ {
if ( key == fc::Fkey_tab if ( key == fc::Fkey_tab
|| key == fc::Fkey_right || key == fc::Fkey_right
@ -39,7 +39,7 @@ bool isFocusNextKey (FKey key)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool isFocusPrevKey (FKey key) bool isFocusPrevKey (const FKey key)
{ {
if ( key == fc::Fkey_btab if ( key == fc::Fkey_btab
|| key == fc::Fkey_left || key == fc::Fkey_left
@ -58,7 +58,7 @@ FKey getHotkey (const FString& text)
if ( text.isEmpty() ) if ( text.isEmpty() )
return 0; return 0;
std::size_t length = text.getLength(); const std::size_t length = text.getLength();
for (std::size_t i{0}; i < length; i++) for (std::size_t i{0}; i < length; i++)
{ {
@ -150,8 +150,8 @@ void drawTransparentShadow (FWidget* w)
{ {
// transparent shadow // transparent shadow
std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
w->setTransparent(); w->setTransparent();
w->print() << FPoint(int(width) + 1, 1) << " "; w->print() << FPoint(int(width) + 1, 1) << " ";
w->unsetTransparent(); w->unsetTransparent();
@ -185,8 +185,8 @@ void drawBlockShadow (FWidget* w)
if ( ! w->hasShadowCharacter() ) if ( ! w->hasShadowCharacter() )
return; return;
std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
w->print() << FPoint(int(width) + 1, 1); w->print() << FPoint(int(width) + 1, 1);
if ( w->isWindowWidget() ) if ( w->isWindowWidget() )
@ -224,8 +224,8 @@ void clearShadow (FWidget* w)
if ( w->isMonochron() ) if ( w->isMonochron() )
return; return;
std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
if ( w->isWindowWidget() ) if ( w->isWindowWidget() )
{ {
@ -264,8 +264,8 @@ void drawFlatBorder (FWidget* w)
else else
w->setColor (w->wcolors.dialog_fg, w->wcolors.dialog_bg); w->setColor (w->wcolors.dialog_fg, w->wcolors.dialog_bg);
std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
for (std::size_t y{0}; y < height; y++) for (std::size_t y{0}; y < height; y++)
{ {
@ -324,8 +324,8 @@ void clearFlatBorder (FWidget* w)
else else
w->setColor (w->wcolors.dialog_fg, w->wcolors.dialog_bg); w->setColor (w->wcolors.dialog_fg, w->wcolors.dialog_bg);
std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
for (std::size_t y{0}; y < height; y++) for (std::size_t y{0}; y < height; y++)
{ {
@ -370,7 +370,7 @@ void clearFlatBorder (FWidget* w)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void checkBorder (FWidget* w, FRect r) inline void checkBorder (FWidget* w, FRect& r)
{ {
if ( r.x1_ref() > r.x2_ref() ) if ( r.x1_ref() > r.x2_ref() )
std::swap (r.x1_ref(), r.x2_ref()); std::swap (r.x1_ref(), r.x2_ref());
@ -403,7 +403,7 @@ void drawBorder (FWidget* w, FRect r)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void drawListBorder (FWidget* w, const FRect& r) void drawListBorder (FWidget* w, FRect r)
{ {
checkBorder (w, r); checkBorder (w, r);

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-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -56,7 +56,7 @@ FWindow::FWindow(FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWindow::~FWindow() // destructor FWindow::~FWindow() // destructor
{ {
auto fapp = FApplication::getApplicationObject(); const auto& fapp = FApplication::getApplicationObject();
if ( previous_window == this ) if ( previous_window == this )
previous_window = nullptr; previous_window = nullptr;
@ -243,7 +243,7 @@ void FWindow::drawBorder()
{ {
if ( isNewFont() ) // Draw a newfont outer frame if ( isNewFont() ) // Draw a newfont outer frame
{ {
FRect r(FPoint(1, 1), getSize()); const FRect r(FPoint(1, 1), getSize());
print() << r.getUpperLeftPos() print() << r.getUpperLeftPos()
<< fc::NF_border_corner_upper_left // ⎡ << fc::NF_border_corner_upper_left // ⎡
<< FString(r.getWidth() - 2, fc::NF_border_line_upper) // ¯ << FString(r.getWidth() - 2, fc::NF_border_line_upper) // ¯
@ -328,7 +328,7 @@ void FWindow::setPos (const FPoint& p, bool adjust)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::setWidth (std::size_t w, bool adjust) void FWindow::setWidth (std::size_t w, bool adjust)
{ {
std::size_t old_width = getWidth(); const std::size_t old_width = getWidth();
FWidget::setWidth (w, adjust); FWidget::setWidth (w, adjust);
if ( isVirtualWindow() && getWidth() != old_width ) if ( isVirtualWindow() && getWidth() != old_width )
@ -342,7 +342,7 @@ void FWindow::setWidth (std::size_t w, bool adjust)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::setHeight (std::size_t h, bool adjust) void FWindow::setHeight (std::size_t h, bool adjust)
{ {
std::size_t old_height = getHeight(); const std::size_t old_height = getHeight();
FWidget::setHeight (h, adjust); FWidget::setHeight (h, adjust);
if ( isVirtualWindow() && getHeight() != old_height ) if ( isVirtualWindow() && getHeight() != old_height )
@ -356,8 +356,8 @@ 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)
{ {
std::size_t old_width = getWidth(); const std::size_t old_width = getWidth();
std::size_t old_height = getHeight(); const std::size_t old_height = getHeight();
FWidget::setSize (size, adjust); FWidget::setSize (size, adjust);
if ( isVirtualWindow() if ( isVirtualWindow()
@ -374,10 +374,10 @@ void FWindow::setGeometry ( const FPoint& p, const FSize& size, bool adjust)
{ {
// Sets the geometry of the widget // Sets the geometry of the widget
int old_x = getX(); const int old_x = getX();
int old_y = getY(); const int old_y = getY();
FPoint pos(p); FPoint pos(p);
FSize old_size(getSize()); const FSize old_size(getSize());
if ( pos.getY() < 1 ) if ( pos.getY() < 1 )
pos.setY(1); pos.setY(1);
@ -422,8 +422,8 @@ 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();
auto begin = getWindowList()->begin(); const auto begin = getWindowList()->begin();
do do
{ {
@ -514,7 +514,7 @@ int FWindow::getWindowLayer (const FWidget* obj)
window = obj; window = obj;
auto iter = getWindowList()->begin(); auto iter = getWindowList()->begin();
auto end = getWindowList()->end(); const auto end = getWindowList()->end();
while ( iter != end ) while ( iter != end )
{ {
@ -544,8 +544,8 @@ void FWindow::swapWindow (FWidget* obj1, FWidget* obj2)
if ( obj2->getFlags().modal ) if ( obj2->getFlags().modal )
return; return;
auto iter = getWindowList()->begin(); auto iter = getWindowList()->begin();
auto end = getWindowList()->end(); const auto end = getWindowList()->end();
auto iter1 = end; auto iter1 = end;
auto iter2 = end; auto iter2 = end;
@ -649,7 +649,7 @@ bool FWindow::zoomWindow()
if ( zoomed ) if ( zoomed )
{ {
zoomed = false; zoomed = false;
FRect oldGeometry (getTermGeometryWithShadow()); const FRect oldGeometry (getTermGeometryWithShadow());
setGeometry (normalGeometry); setGeometry (normalGeometry);
restoreVTerm (oldGeometry); restoreVTerm (oldGeometry);
redraw(); redraw();
@ -659,7 +659,7 @@ bool FWindow::zoomWindow()
zoomed = true; zoomed = true;
// save the current geometry // save the current geometry
normalGeometry = getGeometry(); normalGeometry = getGeometry();
FRect oldGeometry (getTermGeometryWithShadow()); const FRect oldGeometry (getTermGeometryWithShadow());
setGeometry (FPoint(1, 1), FSize(getMaxWidth(), getMaxHeight())); setGeometry (FPoint(1, 1), FSize(getMaxWidth(), getMaxHeight()));
restoreVTerm (oldGeometry); restoreVTerm (oldGeometry);
redraw(); redraw();
@ -678,7 +678,7 @@ void FWindow::switchToPrevWindow (FWidget* widget)
if ( widget ) if ( widget )
widget->updateTerminal (FVTerm::stop_refresh); widget->updateTerminal (FVTerm::stop_refresh);
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 )
@ -686,8 +686,8 @@ void FWindow::switchToPrevWindow (FWidget* widget)
// no previous window -> looking for another window // no previous window -> looking for another window
if ( getWindowList() && getWindowList()->size() > 1 ) if ( getWindowList() && getWindowList()->size() > 1 )
{ {
auto iter = getWindowList()->end(); auto iter = getWindowList()->end();
auto begin = getWindowList()->begin(); const auto begin = getWindowList()->begin();
do do
{ {
@ -715,7 +715,7 @@ void FWindow::switchToPrevWindow (FWidget* widget)
if ( ! active_win->isWindowActive() ) if ( ! active_win->isWindowActive() )
setActiveWindow(active_win); setActiveWindow(active_win);
if ( focus) if ( focus )
{ {
focus->setFocus(); focus->setFocus();
@ -733,7 +733,7 @@ void FWindow::switchToPrevWindow (FWidget* widget)
bool FWindow::activatePrevWindow() bool FWindow::activatePrevWindow()
{ {
// activate the previous window // activate the previous window
auto w = previous_window; const auto& w = previous_window;
if ( w ) if ( w )
{ {
@ -770,8 +770,8 @@ void FWindow::setShadowSize (const FSize& size)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::adjustSize() void FWindow::adjustSize()
{ {
int old_x = getTermX(); const int old_x = getTermX();
int old_y = getTermY(); const int old_y = getTermY();
FWidget::adjustSize(); FWidget::adjustSize();
if ( zoomed ) if ( zoomed )

View File

@ -250,7 +250,7 @@ inline FString FComboBox::getText() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FDataPtr FComboBox::getItemData() inline FDataPtr FComboBox::getItemData()
{ {
std::size_t index = list_window.list.currentItem(); const std::size_t index = list_window.list.currentItem();
return list_window.list.getItem(index).getData(); return list_window.list.getItem(index).getData();
} }

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 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -101,7 +101,7 @@ class FKeyboard final
// Accessors // Accessors
virtual const FString getClassName() const; virtual const FString getClassName() const;
FKey getKey(); FKey getKey();
const FString getKeyName (FKey); const FString getKeyName (const FKey);
keybuffer& getKeyBuffer(); keybuffer& getKeyBuffer();
timeval* getKeyPressedTime(); timeval* getKeyPressedTime();

View File

@ -131,7 +131,7 @@ class FLabel : public FWidget
// Methods // Methods
void init(); void init();
void setHotkeyAccelerator(); void setHotkeyAccelerator();
std::size_t getAlignOffset (std::size_t); std::size_t getAlignOffset (const std::size_t);
void draw() override; void draw() override;
void drawMultiLine(); void drawMultiLine();
void drawSingleLine(); void drawSingleLine();

View File

@ -176,7 +176,7 @@ class FListBox : public FWidget
void selectItem (listBoxItems::iterator); void selectItem (listBoxItems::iterator);
void unselectItem (std::size_t); void unselectItem (std::size_t);
void unselectItem (listBoxItems::iterator); void unselectItem (listBoxItems::iterator);
void showInsideBrackets (std::size_t, fc::brackets_type); void showInsideBrackets (const std::size_t, fc::brackets_type);
void showNoBrackets (std::size_t); void showNoBrackets (std::size_t);
void showNoBrackets (listBoxItems::iterator); void showNoBrackets (listBoxItems::iterator);
void setSize (const FSize&, bool = true) override; void setSize (const FSize&, bool = true) override;
@ -496,7 +496,7 @@ void FListBox::insert (Container container, LazyConverter convert)
conv_type = lazy_convert; conv_type = lazy_convert;
source_container = container; source_container = container;
lazy_inserter = convert; lazy_inserter = convert;
std::size_t size = container->size(); const std::size_t size = container->size();
if ( size > 0 ) if ( size > 0 )
itemlist.resize(size); itemlist.resize(size);

View File

@ -104,6 +104,7 @@ class FListViewItem : public FObject
// Methods // Methods
iterator insert (FListViewItem*); iterator insert (FListViewItem*);
iterator insert (FListViewItem*, iterator); iterator insert (FListViewItem*, iterator);
void remove (FListViewItem*);
void expand(); void expand();
void collapse(); void collapse();
@ -204,7 +205,7 @@ class FListViewIterator
// Accessor // Accessor
const FString getClassName() const; const FString getClassName() const;
int getPosition() const; int& getPosition();
// Methods // Methods
void parentElement(); void parentElement();
@ -243,7 +244,7 @@ inline const FString FListViewIterator::getClassName() const
{ return "FListViewIterator"; } { return "FListViewIterator"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline int FListViewIterator::getPosition() const inline int& FListViewIterator::getPosition()
{ return position; } { return position; }
@ -330,7 +331,8 @@ class FListView : public FWidget
iterator insert ( const std::vector<ColT>& iterator insert ( const std::vector<ColT>&
, FDataPtr , FDataPtr
, iterator ); , iterator );
void remove (FListViewItem*);
void clear();
iterator beginOfList(); iterator beginOfList();
iterator endOfList(); iterator endOfList();
virtual void sort(); virtual void sort();
@ -380,7 +382,7 @@ class FListView : public FWidget
void processKeyAction (FKeyEvent*); void processKeyAction (FKeyEvent*);
template <typename Compare> template <typename Compare>
void sort (Compare); void sort (Compare);
std::size_t getAlignOffset ( fc::text_alignment std::size_t getAlignOffset ( const fc::text_alignment
, std::size_t , std::size_t
, std::size_t ); , std::size_t );
void draw() override; void draw() override;
@ -389,6 +391,7 @@ class FListView : public FWidget
void drawHeadlines(); void drawHeadlines();
void drawList(); void drawList();
void drawListLine (const FListViewItem*, bool, bool); void drawListLine (const FListViewItem*, bool, bool);
void clearList();
void setLineAttributes (bool, bool); void setLineAttributes (bool, bool);
FString getCheckBox (const FListViewItem* item); FString getCheckBox (const FListViewItem* item);
FString getLinePrefix (const FListViewItem*, std::size_t); FString getLinePrefix (const FListViewItem*, std::size_t);

View File

@ -207,7 +207,7 @@ int FMessageBox::info ( FWidget* parent
, FString() << message , FString() << message
, button0, button1, button2 , button0, button1, button2
, parent ); , parent );
int reply = mbox.exec(); const int reply = mbox.exec();
return reply; return reply;
} }
@ -232,7 +232,7 @@ int FMessageBox::error ( FWidget* parent
mbox.setForegroundColor(wc.error_box_fg); mbox.setForegroundColor(wc.error_box_fg);
mbox.setBackgroundColor(wc.error_box_bg); mbox.setBackgroundColor(wc.error_box_bg);
mbox.emphasis_color = wc.error_box_emphasis_fg; mbox.emphasis_color = wc.error_box_emphasis_fg;
int reply = mbox.exec(); const int reply = mbox.exec();
return reply; return reply;
} }

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 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -130,7 +130,7 @@ class FMouse
bool isInputDataPending(); bool isInputDataPending();
// Methods // Methods
static FMouse* createMouseObject (mouse_type); static FMouse* createMouseObject (const mouse_type);
void clearButtonState(); void clearButtonState();
virtual void setRawData (FKeyboard::keybuffer&) = 0; virtual void setRawData (FKeyboard::keybuffer&) = 0;
virtual void processEvent (struct timeval*) = 0; virtual void processEvent (struct timeval*) = 0;
@ -312,7 +312,7 @@ class FMouseX11 final : public FMouse
// Methods // Methods
void setKeyState (int); void setKeyState (int);
void setMoveState (const FPoint&, int); void setMoveState (const FPoint&, int);
void setButtonState (int, struct timeval*); void setButtonState (const int, struct timeval*);
// Data member // Data member
char x11_mouse[MOUSE_BUF_SIZE]{'\0'}; char x11_mouse[MOUSE_BUF_SIZE]{'\0'};
@ -370,8 +370,8 @@ class FMouseSGR final : public FMouse
// Methods // Methods
void setKeyState (int); void setKeyState (int);
void setMoveState (const FPoint&, int); void setMoveState (const FPoint&, int);
void setPressedButtonState (int, struct timeval*); void setPressedButtonState (const int, struct timeval*);
void setReleasedButtonState (int); void setReleasedButtonState (const int);
// Data members // Data members
char sgr_mouse[MOUSE_BUF_SIZE]{'\0'}; char sgr_mouse[MOUSE_BUF_SIZE]{'\0'};
@ -430,7 +430,7 @@ class FMouseUrxvt final : public FMouse
// Methods // Methods
void setKeyState (int); void setKeyState (int);
void setMoveState (const FPoint&, int); void setMoveState (const FPoint&, int);
void setButtonState (int, struct timeval*); void setButtonState (const int, struct timeval*);
// Data members // Data members
char urxvt_mouse[MOUSE_BUF_SIZE]{'\0'}; char urxvt_mouse[MOUSE_BUF_SIZE]{'\0'};

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -204,14 +204,14 @@ inline int FRect::getY() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline std::size_t FRect::getWidth() const inline std::size_t FRect::getWidth() const
{ {
int w = X2 - X1 + 1; const int w = X2 - X1 + 1;
return ( w < 0 ) ? 0 : std::size_t(w); return ( w < 0 ) ? 0 : std::size_t(w);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline std::size_t FRect::getHeight() const inline std::size_t FRect::getHeight() const
{ {
int h = Y2 - Y1 + 1; const int h = Y2 - Y1 + 1;
return ( h < 0 ) ? 0 : std::size_t(h); return ( h < 0 ) ? 0 : std::size_t(h);
} }

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 2014-2019 Markus Gans * * Copyright 2014-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -182,16 +182,16 @@ inline bool operator > (const FSize& s1, const FSize& s2)
inline FSize operator + (const FSize& s1, const FSize& s2) inline FSize operator + (const FSize& s1, const FSize& s2)
{ {
constexpr std::size_t max = std::numeric_limits<std::size_t>::max(); constexpr std::size_t max = std::numeric_limits<std::size_t>::max();
std::size_t w = ( s1.width < max - s2.width) ? s1.width + s2.width : max; const std::size_t w = ( s1.width < max - s2.width) ? s1.width + s2.width : max;
std::size_t h = ( s1.height < max - s2.height) ? s1.height + s2.height : max; const std::size_t h = ( s1.height < max - s2.height) ? s1.height + s2.height : max;
return FSize(w, h); return FSize(w, h);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FSize operator - (const FSize& s1, const FSize& s2) inline FSize operator - (const FSize& s1, const FSize& s2)
{ {
std::size_t w = ( s1.width >= s2.width ) ? s1.width - s2.width : 0; const std::size_t w = ( s1.width >= s2.width ) ? s1.width - s2.width : 0;
std::size_t h = ( s1.height >= s2.height ) ? s1.height - s2.height : 0; const std::size_t h = ( s1.height >= s2.height ) ? s1.height - s2.height : 0;
return FSize(w, h); return FSize(w, h);
} }

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 2012-2019 Markus Gans * * Copyright 2012-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -290,7 +290,7 @@ template <typename NumT
, int>::type > , int>::type >
inline FString& FString::operator << (const NumT val) inline FString& FString::operator << (const NumT val)
{ {
FString numstr(FString().setNumber(val)); const FString numstr(FString().setNumber(val));
_insert (length, numstr.length, numstr.string); _insert (length, numstr.length, numstr.string);
return *this; return *this;
} }

View File

@ -423,8 +423,8 @@ inline bool FTerm::unsetUTF8()
template<typename... Args> template<typename... Args>
inline void FTerm::putstringf (const char format[], Args&&... args) inline void FTerm::putstringf (const char format[], Args&&... args)
{ {
int size = std::snprintf ( nullptr, 0, format const int size = std::snprintf ( nullptr, 0, format
, std::forward<Args>(args)... ) + 1; , std::forward<Args>(args)... ) + 1;
if ( size == -1 ) if ( size == -1 )
return; return;
@ -432,7 +432,7 @@ inline void FTerm::putstringf (const char format[], Args&&... args)
if ( ! fsys ) if ( ! fsys )
getFSystem(); getFSystem();
std::size_t count = std::size_t(size); const std::size_t count = std::size_t(size);
std::vector<char> buf(count); std::vector<char> buf(count);
std::snprintf (&buf[0], count, format, std::forward<Args>(args)...); std::snprintf (&buf[0], count, format, std::forward<Args>(args)...);
fsys->tputs (&buf[0], 1, FTerm::putchar_ASCII); fsys->tputs (&buf[0], 1, FTerm::putchar_ASCII);

View File

@ -526,8 +526,8 @@ class FWidget : public FVTerm, public FObject
// implemented in fwidget_functions.cpp // implemented in fwidget_functions.cpp
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void detectTermSize(); void detectTermSize();
bool isFocusNextKey (FKey); bool isFocusNextKey (const FKey);
bool isFocusPrevKey (FKey); bool isFocusPrevKey (const FKey);
FKey getHotkey (const FString&); FKey getHotkey (const FString&);
std::size_t getHotkeyPos (const FString& src, FString& dest); std::size_t getHotkeyPos (const FString& src, FString& dest);
void setHotkeyViaString (FWidget*, const FString&); void setHotkeyViaString (FWidget*, const FString&);
@ -537,9 +537,9 @@ void drawBlockShadow (FWidget*);
void clearShadow (FWidget*); void clearShadow (FWidget*);
void drawFlatBorder (FWidget*); void drawFlatBorder (FWidget*);
void clearFlatBorder (FWidget*); void clearFlatBorder (FWidget*);
void checkBorder (FWidget*, FRect); void checkBorder (FWidget*, FRect&);
void drawBorder (FWidget*, FRect); void drawBorder (FWidget*, FRect);
void drawListBorder (FWidget*, const FRect&); void drawListBorder (FWidget*, FRect);
void drawBox (FWidget*, const FRect&); void drawBox (FWidget*, const FRect&);
void drawNewFontBox (FWidget*, const FRect&); void drawNewFontBox (FWidget*, const FRect&);
void drawNewFontListBox (FWidget*, const FRect&); void drawNewFontListBox (FWidget*, const FRect&);

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 2019 Markus Gans * * Copyright 2019-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -58,7 +58,7 @@ void SGRoptimizer::findParameter()
{ {
// Find ANSI X3.64 terminal SGR (Select Graphic Rendition) strings // Find ANSI X3.64 terminal SGR (Select Graphic Rendition) strings
std::size_t len = std::strlen(seq); const std::size_t len = std::strlen(seq);
csi_parameter.clear(); csi_parameter.clear();
if ( len < 6 ) if ( len < 6 )