Small code improvements
This commit is contained in:
parent
d126c4996a
commit
fc1b9ebdf3
|
@ -27,7 +27,7 @@ How to use the library
|
||||||
At the beginning of this introduction to the Final Cut
|
At the beginning of this introduction to the Final Cut
|
||||||
we will start with a small example.
|
we will start with a small example.
|
||||||
|
|
||||||
The following example creates an empty 30??10 character dialog.
|
The following example creates an empty 30×10 character dialog.
|
||||||
|
|
||||||
**File:** *dialog.cpp*
|
**File:** *dialog.cpp*
|
||||||
```cpp
|
```cpp
|
||||||
|
@ -702,12 +702,12 @@ class dialogWidget : public FDialog
|
||||||
void setTemperature()
|
void setTemperature()
|
||||||
{
|
{
|
||||||
label.clear();
|
label.clear();
|
||||||
label << t << "??C";
|
label << t << "°C";
|
||||||
label.redraw();
|
label.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
int t = 20;
|
int t = 20;
|
||||||
FLabel label{FString() << t << "??C", this};
|
FLabel label{FString() << t << "°C", this};
|
||||||
FButton plus {"&+", this};
|
FButton plus {"&+", this};
|
||||||
FButton minus {"&-", this};
|
FButton minus {"&-", this};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 *
|
||||||
|
@ -241,16 +241,14 @@ Brushes::~Brushes()
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void Brushes::draw()
|
void Brushes::draw()
|
||||||
{
|
{
|
||||||
int pos{};
|
int pos{0};
|
||||||
setColor();
|
setColor();
|
||||||
drawBorder();
|
drawBorder();
|
||||||
print() << FPoint(2, 3)
|
print() << FPoint(2, 3)
|
||||||
<< FColorPair(fg_color, bg_color) << " "
|
<< FColorPair(fg_color, bg_color) << " "
|
||||||
<< finalcut::FString(3, fc::MediumShade);
|
<< finalcut::FString(3, fc::MediumShade);
|
||||||
|
|
||||||
if ( brush == L' ' )
|
if ( brush != L' ' )
|
||||||
pos = 0;
|
|
||||||
else
|
|
||||||
pos = 3;
|
pos = 3;
|
||||||
|
|
||||||
setColor();
|
setColor();
|
||||||
|
|
|
@ -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 2013-2019 Markus Gans *
|
* Copyright 2013-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 *
|
||||||
|
@ -117,11 +117,12 @@ bool FApplication::isQuit()
|
||||||
int FApplication::exec() // run
|
int FApplication::exec() // run
|
||||||
{
|
{
|
||||||
if ( quit_now )
|
if ( quit_now )
|
||||||
|
{
|
||||||
|
quit_now = false;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
quit_now = false;
|
|
||||||
quit_code = 0;
|
quit_code = 0;
|
||||||
|
|
||||||
enterLoop();
|
enterLoop();
|
||||||
return quit_code;
|
return quit_code;
|
||||||
}
|
}
|
||||||
|
@ -825,7 +826,7 @@ void FApplication::closeDropDown()
|
||||||
{
|
{
|
||||||
// Close the open menu
|
// Close the open menu
|
||||||
|
|
||||||
if ( ! mouse || (mouse && mouse->isMoved()) )
|
if ( ! mouse || mouse->isMoved() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto& mouse_position = mouse->getPos();
|
const auto& mouse_position = mouse->getPos();
|
||||||
|
|
|
@ -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 *
|
||||||
|
@ -472,12 +472,10 @@ sInt64 FFileDialog::numOfDirs()
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FFileDialog::sortDir()
|
void FFileDialog::sortDir()
|
||||||
{
|
{
|
||||||
sInt64 start{};
|
sInt64 start{0};
|
||||||
|
|
||||||
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
|
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
|
||||||
start = 1;
|
start = 1;
|
||||||
else
|
|
||||||
start = 0;
|
|
||||||
|
|
||||||
sInt64 dir_num = numOfDirs();
|
sInt64 dir_num = numOfDirs();
|
||||||
// directories first
|
// directories first
|
||||||
|
|
|
@ -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 *
|
||||||
|
@ -730,15 +730,12 @@ void FListView::setColumnSort (int column, fc::sorting_order order)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
int FListView::addColumn (const FString& label, int width)
|
int FListView::addColumn (const FString& label, int width)
|
||||||
{
|
{
|
||||||
Header new_column;
|
Header new_column{};
|
||||||
new_column.name = label;
|
new_column.name = label;
|
||||||
new_column.width = width;
|
new_column.width = width;
|
||||||
|
|
||||||
if ( new_column.width == USE_MAX_SIZE )
|
if ( new_column.width == USE_MAX_SIZE )
|
||||||
{
|
|
||||||
new_column.fixed_width = false;
|
|
||||||
new_column.width = int(getColumnWidth(label));
|
new_column.width = int(getColumnWidth(label));
|
||||||
}
|
|
||||||
else
|
else
|
||||||
new_column.fixed_width = true;
|
new_column.fixed_width = true;
|
||||||
|
|
||||||
|
@ -1944,12 +1941,10 @@ std::size_t FListView::determineLineWidth (FListViewItem* item)
|
||||||
|
|
||||||
if ( ! fixed_width )
|
if ( ! fixed_width )
|
||||||
{
|
{
|
||||||
std::size_t len{};
|
std::size_t len{0};
|
||||||
|
|
||||||
if ( column_idx < entries )
|
if ( column_idx < entries )
|
||||||
len = getColumnWidth(item->column_list[column_idx]);
|
len = getColumnWidth(item->column_list[column_idx]);
|
||||||
else
|
|
||||||
len = 0;
|
|
||||||
|
|
||||||
if ( len > width )
|
if ( len > width )
|
||||||
header_item.width = int(len);
|
header_item.width = int(len);
|
||||||
|
|
|
@ -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 *
|
||||||
|
@ -485,7 +485,7 @@ bool FMenuItem::isMenu (FWidget* w) const
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FMenuList* FMenuItem::getFMenuList (FWidget& widget)
|
FMenuList* FMenuItem::getFMenuList (FWidget& widget)
|
||||||
{
|
{
|
||||||
FMenuList* menu_list{};
|
FMenuList* menu_list{nullptr};
|
||||||
|
|
||||||
if ( isMenu(&widget) )
|
if ( isMenu(&widget) )
|
||||||
{
|
{
|
||||||
|
@ -497,8 +497,6 @@ FMenuList* FMenuItem::getFMenuList (FWidget& widget)
|
||||||
auto Menubar = static_cast<FMenuBar*>(&widget);
|
auto Menubar = static_cast<FMenuBar*>(&widget);
|
||||||
menu_list = static_cast<FMenuList*>(Menubar);
|
menu_list = static_cast<FMenuList*>(Menubar);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
menu_list = nullptr;
|
|
||||||
|
|
||||||
return menu_list;
|
return menu_list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 *
|
||||||
|
@ -1272,8 +1272,7 @@ void FTerm::initScreenSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
char* FTerm::changeAttribute ( FChar*& term_attr
|
char* FTerm::changeAttribute (FChar*& term_attr, FChar*& next_attr)
|
||||||
, FChar*& next_attr )
|
|
||||||
{
|
{
|
||||||
return opti_attr->changeAttribute (term_attr, next_attr);
|
return opti_attr->changeAttribute (term_attr, next_attr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 *
|
||||||
|
@ -34,6 +34,17 @@
|
||||||
namespace finalcut
|
namespace finalcut
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Enumeration
|
||||||
|
enum fullWidthSupport
|
||||||
|
{
|
||||||
|
unknown_fullwidth_support = -1,
|
||||||
|
supports_fullwidth = 0,
|
||||||
|
no_fullwidth_support = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
// global state
|
||||||
|
static fullWidthSupport has_fullwidth_support = unknown_fullwidth_support;
|
||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
bool hasAmbiguousWidth (wchar_t);
|
bool hasAmbiguousWidth (wchar_t);
|
||||||
|
|
||||||
|
@ -218,6 +229,29 @@ bool isReverseNewFontchar (wchar_t wchar)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
bool hasFullWidthSupports()
|
||||||
|
{
|
||||||
|
// Checks if the terminal has full-width character support
|
||||||
|
|
||||||
|
if ( has_fullwidth_support == unknown_fullwidth_support )
|
||||||
|
{
|
||||||
|
if ( FTerm::isCygwinTerminal()
|
||||||
|
|| FTerm::isTeraTerm()
|
||||||
|
|| FTerm::isRxvtTerminal()
|
||||||
|
|| FTerm::isFreeBSDTerm()
|
||||||
|
|| FTerm::isNetBSDTerm()
|
||||||
|
|| FTerm::isOpenBSDTerm()
|
||||||
|
|| FTerm::isSunTerminal()
|
||||||
|
|| FTerm::isAnsiTerminal() )
|
||||||
|
has_fullwidth_support = no_fullwidth_support;
|
||||||
|
else
|
||||||
|
has_fullwidth_support = supports_fullwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( has_fullwidth_support == supports_fullwidth) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
wchar_t cp437_to_unicode (uChar c)
|
wchar_t cp437_to_unicode (uChar c)
|
||||||
{
|
{
|
||||||
|
@ -428,7 +462,8 @@ std::size_t getColumnWidth (const wchar_t wchar)
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( wchar >= fc::NF_rev_left_arrow2 && wchar <= fc::NF_check_mark )
|
if ( (wchar >= fc::NF_rev_left_arrow2 && wchar <= fc::NF_check_mark)
|
||||||
|
|| ! hasFullWidthSupports() )
|
||||||
column_width = 1;
|
column_width = 1;
|
||||||
else
|
else
|
||||||
column_width = wcwidth(wchar);
|
column_width = wcwidth(wchar);
|
||||||
|
|
|
@ -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 *
|
||||||
|
@ -453,6 +453,18 @@ char* FTermDetection::termtype_256color_quirks()
|
||||||
{
|
{
|
||||||
char* new_termtype{nullptr};
|
char* new_termtype{nullptr};
|
||||||
|
|
||||||
|
if ( color_env.string2
|
||||||
|
|| (color_env.string1
|
||||||
|
&& std::strncmp(color_env.string1, "gnome-terminal", 14) == 0) )
|
||||||
|
{
|
||||||
|
terminal_type.gnome_terminal = true;
|
||||||
|
// Each gnome-terminal should be able to use 256 colors
|
||||||
|
color256 = true;
|
||||||
|
|
||||||
|
if ( ! isScreenTerm() )
|
||||||
|
return (new_termtype = C_STR("gnome-256color"));
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! color256 )
|
if ( ! color256 )
|
||||||
return new_termtype;
|
return new_termtype;
|
||||||
|
|
||||||
|
@ -486,18 +498,6 @@ char* FTermDetection::termtype_256color_quirks()
|
||||||
if ( color_env.string3 && std::strlen(color_env.string3) > 0 )
|
if ( color_env.string3 && std::strlen(color_env.string3) > 0 )
|
||||||
decscusr_support = true;
|
decscusr_support = true;
|
||||||
|
|
||||||
if ( color_env.string2
|
|
||||||
|| (color_env.string1
|
|
||||||
&& std::strncmp(color_env.string1, "gnome-terminal", 14) == 0) )
|
|
||||||
{
|
|
||||||
terminal_type.gnome_terminal = true;
|
|
||||||
// Each gnome-terminal should be able to use 256 colors
|
|
||||||
color256 = true;
|
|
||||||
|
|
||||||
if ( ! isScreenTerm() )
|
|
||||||
new_termtype = C_STR("gnome-256color");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_termtype;
|
return new_termtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,8 +290,7 @@ class FTerm final
|
||||||
static int putchar_UTF8 (int);
|
static int putchar_UTF8 (int);
|
||||||
|
|
||||||
static void initScreenSettings();
|
static void initScreenSettings();
|
||||||
static char* changeAttribute ( FChar*&
|
static char* changeAttribute (FChar*&, FChar*&);
|
||||||
, FChar*& );
|
|
||||||
static void changeTermSizeFinished();
|
static void changeTermSizeFinished();
|
||||||
static void exitWithMessage (const FString&)
|
static void exitWithMessage (const FString&)
|
||||||
#if defined(__clang__) || defined(__GNUC__)
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
|
@ -389,6 +388,7 @@ class FTerm final
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
uInt env2uint (const char*);
|
uInt env2uint (const char*);
|
||||||
bool isReverseNewFontchar (wchar_t);
|
bool isReverseNewFontchar (wchar_t);
|
||||||
|
bool hasFullWidthSupports();
|
||||||
wchar_t cp437_to_unicode (uChar);
|
wchar_t cp437_to_unicode (uChar);
|
||||||
uChar unicode_to_cp437 (wchar_t);
|
uChar unicode_to_cp437 (wchar_t);
|
||||||
FString getFullWidth (const FString&);
|
FString getFullWidth (const FString&);
|
||||||
|
|
Loading…
Reference in New Issue