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
|
||||
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*
|
||||
```cpp
|
||||
|
@ -702,12 +702,12 @@ class dialogWidget : public FDialog
|
|||
void setTemperature()
|
||||
{
|
||||
label.clear();
|
||||
label << t << "??C";
|
||||
label << t << "°C";
|
||||
label.redraw();
|
||||
}
|
||||
|
||||
int t = 20;
|
||||
FLabel label{FString() << t << "??C", this};
|
||||
FLabel label{FString() << t << "°C", this};
|
||||
FButton plus {"&+", this};
|
||||
FButton minus {"&-", this};
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* modify it under the terms of the GNU Lesser General Public License *
|
||||
|
@ -241,16 +241,14 @@ Brushes::~Brushes()
|
|||
//----------------------------------------------------------------------
|
||||
void Brushes::draw()
|
||||
{
|
||||
int pos{};
|
||||
int pos{0};
|
||||
setColor();
|
||||
drawBorder();
|
||||
print() << FPoint(2, 3)
|
||||
<< FColorPair(fg_color, bg_color) << " "
|
||||
<< finalcut::FString(3, fc::MediumShade);
|
||||
|
||||
if ( brush == L' ' )
|
||||
pos = 0;
|
||||
else
|
||||
if ( brush != L' ' )
|
||||
pos = 3;
|
||||
|
||||
setColor();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* modify it under the terms of the GNU Lesser General Public License *
|
||||
|
@ -117,11 +117,12 @@ bool FApplication::isQuit()
|
|||
int FApplication::exec() // run
|
||||
{
|
||||
if ( quit_now )
|
||||
return EXIT_FAILURE;
|
||||
|
||||
{
|
||||
quit_now = false;
|
||||
quit_code = 0;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
quit_code = 0;
|
||||
enterLoop();
|
||||
return quit_code;
|
||||
}
|
||||
|
@ -825,7 +826,7 @@ void FApplication::closeDropDown()
|
|||
{
|
||||
// Close the open menu
|
||||
|
||||
if ( ! mouse || (mouse && mouse->isMoved()) )
|
||||
if ( ! mouse || mouse->isMoved() )
|
||||
return;
|
||||
|
||||
const auto& mouse_position = mouse->getPos();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* modify it under the terms of the GNU Lesser General Public License *
|
||||
|
@ -472,12 +472,10 @@ sInt64 FFileDialog::numOfDirs()
|
|||
//----------------------------------------------------------------------
|
||||
void FFileDialog::sortDir()
|
||||
{
|
||||
sInt64 start{};
|
||||
sInt64 start{0};
|
||||
|
||||
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
|
||||
start = 1;
|
||||
else
|
||||
start = 0;
|
||||
|
||||
sInt64 dir_num = numOfDirs();
|
||||
// directories first
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* 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)
|
||||
{
|
||||
Header new_column;
|
||||
Header new_column{};
|
||||
new_column.name = label;
|
||||
new_column.width = width;
|
||||
|
||||
if ( new_column.width == USE_MAX_SIZE )
|
||||
{
|
||||
new_column.fixed_width = false;
|
||||
new_column.width = int(getColumnWidth(label));
|
||||
}
|
||||
else
|
||||
new_column.fixed_width = true;
|
||||
|
||||
|
@ -1944,12 +1941,10 @@ std::size_t FListView::determineLineWidth (FListViewItem* item)
|
|||
|
||||
if ( ! fixed_width )
|
||||
{
|
||||
std::size_t len{};
|
||||
std::size_t len{0};
|
||||
|
||||
if ( column_idx < entries )
|
||||
len = getColumnWidth(item->column_list[column_idx]);
|
||||
else
|
||||
len = 0;
|
||||
|
||||
if ( len > width )
|
||||
header_item.width = int(len);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* 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* menu_list{};
|
||||
FMenuList* menu_list{nullptr};
|
||||
|
||||
if ( isMenu(&widget) )
|
||||
{
|
||||
|
@ -497,8 +497,6 @@ FMenuList* FMenuItem::getFMenuList (FWidget& widget)
|
|||
auto Menubar = static_cast<FMenuBar*>(&widget);
|
||||
menu_list = static_cast<FMenuList*>(Menubar);
|
||||
}
|
||||
else
|
||||
menu_list = nullptr;
|
||||
|
||||
return menu_list;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* 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
|
||||
, FChar*& next_attr )
|
||||
char* FTerm::changeAttribute (FChar*& term_attr, FChar*& next_attr)
|
||||
{
|
||||
return opti_attr->changeAttribute (term_attr, next_attr);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* modify it under the terms of the GNU Lesser General Public License *
|
||||
|
@ -34,6 +34,17 @@
|
|||
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
|
||||
bool hasAmbiguousWidth (wchar_t);
|
||||
|
||||
|
@ -218,6 +229,29 @@ bool isReverseNewFontchar (wchar_t wchar)
|
|||
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)
|
||||
{
|
||||
|
@ -428,7 +462,8 @@ std::size_t getColumnWidth (const wchar_t wchar)
|
|||
else
|
||||
#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;
|
||||
else
|
||||
column_width = wcwidth(wchar);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* 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};
|
||||
|
||||
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 )
|
||||
return new_termtype;
|
||||
|
||||
|
@ -486,18 +498,6 @@ char* FTermDetection::termtype_256color_quirks()
|
|||
if ( color_env.string3 && std::strlen(color_env.string3) > 0 )
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* 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 void initScreenSettings();
|
||||
static char* changeAttribute ( FChar*&
|
||||
, FChar*& );
|
||||
static char* changeAttribute (FChar*&, FChar*&);
|
||||
static void changeTermSizeFinished();
|
||||
static void exitWithMessage (const FString&)
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
|
@ -389,6 +388,7 @@ class FTerm final
|
|||
//----------------------------------------------------------------------
|
||||
uInt env2uint (const char*);
|
||||
bool isReverseNewFontchar (wchar_t);
|
||||
bool hasFullWidthSupports();
|
||||
wchar_t cp437_to_unicode (uChar);
|
||||
uChar unicode_to_cp437 (wchar_t);
|
||||
FString getFullWidth (const FString&);
|
||||
|
|
Loading…
Reference in New Issue