Further small code improvements

This commit is contained in:
Markus Gans 2020-04-20 01:01:20 +02:00
parent 88667f2cbb
commit 803e54d456
21 changed files with 167 additions and 162 deletions

View File

@ -74,7 +74,7 @@ class ColorChooser final : public finalcut::FWidget
ColorChooser::ColorChooser (finalcut::FWidget* parent)
: FWidget(parent)
{
setSize (FSize(8, 12));
FWidget::setSize (FSize(8, 12));
setFixedSize (FSize(8, 12));
unsetFocusable();
@ -228,7 +228,7 @@ class Brushes final : public finalcut::FWidget
Brushes::Brushes (finalcut::FWidget* parent)
: FWidget(parent)
{
setSize (FSize(8, 4));
FWidget::setSize (FSize(8, 4));
setFixedSize (FSize(8, 4));
unsetFocusable();

View File

@ -122,7 +122,7 @@ void streamingIntoFStringExample()
// ...from wide string
finalcut::FString streamer3;
wchar_t* wchar_str{const_cast<wchar_t*>(L"wchar_t*")};
const wchar_t* wchar_str{const_cast<wchar_t*>(L"wchar_t*")};
streamer3 << wchar_str;
std::cout << " stream in: " << streamer3 << std::endl;
@ -133,7 +133,7 @@ void streamingIntoFStringExample()
// ...from c-string
finalcut::FString streamer5;
char* char_str{C_STR("char*")};
const char* char_str{C_STR("char*")};
streamer5 << char_str;
std::cout << " stream in: " << streamer5 << std::endl;

View File

@ -238,13 +238,12 @@ class AttribDemo final : public finalcut::FWidget
void draw() override;
// Data member
FColor last_color;
FColor last_color{FColor(getMaxColor())};
};
//----------------------------------------------------------------------
AttribDemo::AttribDemo (finalcut::FWidget* parent)
: finalcut::FWidget(parent)
, last_color(FColor(getMaxColor()))
{
if ( isMonochron() )
last_color = 1;

View File

@ -57,9 +57,6 @@ class Transparent final : public finalcut::FDialog
// Disable copy assignment operator (=)
Transparent& operator = (const Transparent&) = delete;
// Mutator
void setStatusbarMessage (const finalcut::FString&) override;
private:
// Method
void draw() override;
@ -78,21 +75,15 @@ Transparent::Transparent ( finalcut::FWidget* parent
, type(tt)
{
// Set statusbar text for this window
setStatusbarMessage("Press Q to quit");
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FWidget::setStatusbarMessage("Press Q to quit");
}
//----------------------------------------------------------------------
Transparent::~Transparent()
{ }
//----------------------------------------------------------------------
void Transparent::setStatusbarMessage (const finalcut::FString& msg)
{
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FWidget::setStatusbarMessage(msg);
}
//----------------------------------------------------------------------
void Transparent::draw()
{

View File

@ -678,11 +678,8 @@ bool FApplication::processAccelerator (const FWidget* const& widget)
auto iter = widget->getAcceleratorList().begin();
const auto& last = widget->getAcceleratorList().end();
while ( iter != last )
while ( iter != last && ! quit_now && ! app_exit_loop )
{
if ( quit_now || app_exit_loop )
break;
if ( iter->key == keyboard->getKey() )
{
// unset the move/size mode

View File

@ -504,7 +504,7 @@ int FFileDialog::readDir()
while ( true )
{
errno = 0;
struct dirent* next = readdir(directory_stream);
const struct dirent* next = readdir(directory_stream);
if ( next )
{

View File

@ -405,14 +405,13 @@ void FLabel::printLine (FString& line)
for (std::size_t z{0}; z < to_char; z++)
{
if ( ! std::iswprint(std::wint_t(line[z])) )
{
if ( ! isNewFont() && ( line[z] < fc::NF_rev_left_arrow2
if ( ! std::iswprint(std::wint_t(line[z]))
&& ! isNewFont()
&& ( line[z] < fc::NF_rev_left_arrow2
|| line[z] > fc::NF_check_mark ) )
{
line[z] = L' ';
}
}
if ( z == hotkeypos && getFlags().active )
{

View File

@ -317,13 +317,13 @@ void FMenu::onMouseMove (FMouseEvent* ev)
}
//----------------------------------------------------------------------
void FMenu::cb_menuitemEnabled (FWidget*, const FDataPtr)
void FMenu::cb_menuitemEnabled (const FWidget*, const FDataPtr)
{
setEnable();
}
//----------------------------------------------------------------------
void FMenu::cb_menuitemDisabled (FWidget*, const FDataPtr)
void FMenu::cb_menuitemDisabled (const FWidget*, const FDataPtr)
{
setDisable();
}

View File

@ -294,7 +294,7 @@ void FMouse::setEvent()
}
//----------------------------------------------------------------------
bool FMouse::isDblclickTimeout (timeval* time)
bool FMouse::isDblclickTimeout (const timeval* time)
{
return FObject::isTimeout (time, dblclick_interval);
}
@ -652,7 +652,7 @@ void FMouseX11::setMoveState (const FPoint& mouse_position, int btn)
}
//----------------------------------------------------------------------
void FMouseX11::setButtonState (const int btn, struct timeval* time)
void FMouseX11::setButtonState (const int btn, const struct timeval* time)
{
// Get the x11 mouse button state
@ -1132,7 +1132,7 @@ void FMouseUrxvt::setMoveState (const FPoint& mouse_position, int btn)
}
//----------------------------------------------------------------------
void FMouseUrxvt::setButtonState (const int btn, struct timeval* time)
void FMouseUrxvt::setButtonState (const int btn, const struct timeval* time)
{
// Get the urxvt mouse button state

View File

@ -956,7 +956,7 @@ bool FOptiAttr::setTermAttributes ( FChar*& term
{
if ( term && F_set_attributes.cap )
{
char* sgr = tparm ( F_set_attributes.cap
const char* sgr = tparm ( F_set_attributes.cap
, p1 && ! fake_reverse
, p2
, p3 && ! fake_reverse
@ -1458,7 +1458,7 @@ inline void FOptiAttr::change_to_default_color ( FChar*& term
}
else if ( bg == fc::Default && term->bg_color != fc::Default )
{
char* sgr_49;
const char* sgr_49;
const auto& op = F_orig_pair.cap;
if ( op && std::strncmp (op, CSI "39;49;25m", 11) == 0 )
@ -1482,7 +1482,7 @@ inline void FOptiAttr::change_to_default_color ( FChar*& term
inline void FOptiAttr::change_current_color ( const FChar* const& term
, FColor fg, FColor bg )
{
char* color_str{};
const char* color_str{};
const auto& AF = F_set_a_foreground.cap;
const auto& AB = F_set_a_background.cap;
const auto& Sf = F_set_foreground.cap;

View File

@ -267,7 +267,7 @@ void FOptiMove::set_cursor_address (char cap[])
{
if ( cap )
{
char* temp = tgoto(cap, 23, 23);
const char* temp = tgoto(cap, 23, 23);
F_cursor_address.cap = cap;
F_cursor_address.duration = capDuration (temp, 1);
F_cursor_address.length = capDurationToLength (F_cursor_address.duration);
@ -285,7 +285,7 @@ void FOptiMove::set_column_address (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
F_column_address.cap = cap;
F_column_address.duration = capDuration (temp, 1);
F_column_address.length = capDurationToLength (F_column_address.duration);
@ -303,7 +303,7 @@ void FOptiMove::set_row_address (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
F_row_address.cap = cap;
F_row_address.duration = capDuration (temp, 1);
F_row_address.length = capDurationToLength (F_row_address.duration);
@ -321,7 +321,7 @@ void FOptiMove::set_parm_up_cursor (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
F_parm_up_cursor.cap = cap;
F_parm_up_cursor.duration = capDuration (temp, 1);
F_parm_up_cursor.length = capDurationToLength (F_parm_up_cursor.duration);
@ -339,7 +339,7 @@ void FOptiMove::set_parm_down_cursor (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
F_parm_down_cursor.cap = cap;
F_parm_down_cursor.duration = capDuration (temp, 1);
F_parm_down_cursor.length = capDurationToLength (F_parm_down_cursor.duration);
@ -357,7 +357,7 @@ void FOptiMove::set_parm_left_cursor (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
F_parm_left_cursor.cap = cap;
F_parm_left_cursor.duration = capDuration (temp, 1);
F_parm_left_cursor.length = capDurationToLength (F_parm_left_cursor.duration);
@ -375,7 +375,7 @@ void FOptiMove::set_parm_right_cursor (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
F_parm_right_cursor.cap = cap;
F_parm_right_cursor.duration = capDuration (temp, 1);
F_parm_right_cursor.length = capDurationToLength (F_parm_right_cursor.duration);
@ -393,7 +393,7 @@ void FOptiMove::set_erase_chars (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
F_erase_chars.cap = cap;
F_erase_chars.duration = capDuration (temp, 1);
F_erase_chars.length = capDurationToLength (F_erase_chars.duration);
@ -411,7 +411,7 @@ void FOptiMove::set_repeat_char (char cap[])
{
if ( cap )
{
char* temp = tparm(cap, ' ', 23, 0, 0, 0, 0, 0, 0, 0);
const char* temp = tparm(cap, ' ', 23, 0, 0, 0, 0, 0, 0, 0);
F_repeat_char.cap = cap;
F_repeat_char.duration = capDuration (temp, 1);
F_repeat_char.length = capDurationToLength (F_repeat_char.duration);

View File

@ -217,9 +217,7 @@ void FStatusBar::drawMessage()
if ( isMonochron() )
setReverse(true);
if ( x + space_offset + 3 < int(termWidth) )
{
if ( text )
if ( x + space_offset + 3 < int(termWidth) && text )
{
if ( ! isLastActiveFocus )
{
@ -247,7 +245,6 @@ void FStatusBar::drawMessage()
<< "..";
}
}
}
for (int i = x; i <= int(termWidth); i++)
print (' ');

View File

@ -918,9 +918,7 @@ inline char* FTermDetection::secDA_Analysis_65 (char current_termtype[])
{
// Terminal ID 65 - DEC VT525
char* new_termtype = current_termtype;
new_termtype = secDA_Analysis_vte(new_termtype);
return new_termtype;
return secDA_Analysis_1 (current_termtype);
}
//----------------------------------------------------------------------

View File

@ -1886,7 +1886,7 @@ void FWidget::setWindowFocus (bool enable)
}
//----------------------------------------------------------------------
FWidget::FCallbackPtr FWidget::getCallbackPtr (FCallback cb_function)
FWidget::FCallbackPtr FWidget::getCallbackPtr (const FCallback& cb_function)
{
return *cb_function.template target<FCallbackPtr>();
}

View File

@ -73,6 +73,7 @@ class FMenu : public FWindow, public FMenuList
public:
// Using-declaration
using FMenuList::getItem;
using FMenuList::isSelected;
// Constructor
explicit FMenu (FWidget* = nullptr);
@ -123,8 +124,8 @@ class FMenu : public FWindow, public FMenuList
void onAccel (FAccelEvent*) override;
// Callback method
void cb_menuitemEnabled (FWidget*, const FDataPtr);
void cb_menuitemDisabled (FWidget*, const FDataPtr);
void cb_menuitemEnabled (const FWidget*, const FDataPtr);
void cb_menuitemDisabled (const FWidget*, const FDataPtr);
void cb_menuitemToggled (FWidget*, const FDataPtr);
private:

View File

@ -176,7 +176,7 @@ class FMouse
void resetMousePressedTime();
// Inquiry
bool isDblclickTimeout (timeval*);
bool isDblclickTimeout (const timeval*);
private:
// Data members
@ -312,7 +312,7 @@ class FMouseX11 final : public FMouse
// Methods
void setKeyState (int);
void setMoveState (const FPoint&, int);
void setButtonState (const int, struct timeval*);
void setButtonState (const int, const struct timeval*);
// Data member
char x11_mouse[MOUSE_BUF_SIZE]{'\0'};
@ -430,7 +430,7 @@ class FMouseUrxvt final : public FMouse
// Methods
void setKeyState (int);
void setMoveState (const FPoint&, int);
void setButtonState (const int, struct timeval*);
void setButtonState (const int, const struct timeval*);
// Data members
char urxvt_mouse[MOUSE_BUF_SIZE]{'\0'};

View File

@ -155,6 +155,9 @@ class FTermDetection final
static void detect();
private:
struct colorEnv; // forward declaration
struct secondaryDA; // forward declaration
// Methods
static void deallocation();
static void getSystemTermType();
@ -205,8 +208,15 @@ class FTermDetection final
static FTermData* fterm_data;
static FSystem* fsystem;
static FTerminalType terminal_type;
static colorEnv color_env;
static secondaryDA secondary_da;
};
static struct colorEnv
//----------------------------------------------------------------------
// struct FTermDetection::colorEnv
//----------------------------------------------------------------------
struct FTermDetection::colorEnv
{
char* string1{nullptr};
char* string2{nullptr};
@ -215,16 +225,19 @@ class FTermDetection final
char* string5{nullptr};
char* string6{nullptr};
char* string7{nullptr};
} color_env;
};
static struct secondaryDA
//----------------------------------------------------------------------
// struct FTermDetection::secondaryDA
//----------------------------------------------------------------------
struct FTermDetection::secondaryDA
{
int terminal_id_type{-1};
int terminal_id_version{-1};
int terminal_id_hardware{-1};
} secondary_da;
};
// FTermDetection inline functions
//----------------------------------------------------------------------
inline const FString FTermDetection::getClassName() const

View File

@ -131,7 +131,7 @@ class FTermLinux final
uChar ctrl : 1; // 0..1
uChar alt : 1; // 0..1
uChar : 4; // padding bits
} mod_key{};
};
typedef struct
{
@ -197,6 +197,7 @@ class FTermLinux final
ColorMap saved_color_map{};
ColorMap cmap{};
int framebuffer_bpp{-1};
modifier_key mod_key{};
#endif // defined(__linux__)
};

View File

@ -107,16 +107,7 @@ struct getPrecision
typedef std::unordered_map<wchar_t, wchar_t> charSubstitution;
typedef struct
{
wchar_t ch; // character code
wchar_t encoded_char; // encoded output character
FColor fg_color; // foreground color
FColor bg_color; // background color
union attribute
{
struct
struct FCharAttribute
{
// Attribute byte #0
uInt8 bold : 1; // bold
@ -144,12 +135,23 @@ typedef struct
uInt8 : 3; // padding bits
// Attribute byte #3
uInt8 : 8; // padding byte
} bit;
};
typedef struct
{
wchar_t ch; // character code
wchar_t encoded_char; // encoded output character
FColor fg_color; // foreground color
FColor bg_color; // background color
union attribute
{
FCharAttribute bit;
uInt8 byte[4];
} attr;
} FChar;
namespace fc
{

View File

@ -396,26 +396,6 @@ class FWidget : public FVTerm, public FObject
virtual void onClose (FCloseEvent*);
private:
// Methods
void initRootWidget();
void finish();
void insufficientSpaceAdjust();
void KeyPressEvent (FKeyEvent*);
void KeyDownEvent (FKeyEvent*);
void emitWheelCallback (const FWheelEvent*);
void setWindowFocus (bool);
FCallbackPtr getCallbackPtr (FCallback);
bool changeFocus (FWidget*, FWidget*, fc::FocusTypes);
void processDestroy();
virtual void draw();
void drawWindows();
void drawChildren();
static void setColorTheme();
void setStatusbarText (bool);
// Data members
FPoint widget_cursor_position{-1, -1};
struct widget_size_hints
{
widget_size_hints() = default;
@ -437,7 +417,7 @@ class FWidget : public FVTerm, public FObject
std::size_t min_height{0};
std::size_t max_width{INT_MAX};
std::size_t max_height{INT_MAX};
} size_hints{};
};
struct dbl_line_mask
{
@ -448,7 +428,7 @@ class FWidget : public FVTerm, public FObject
std::vector<bool> right{};
std::vector<bool> bottom{};
std::vector<bool> left{};
} double_flatline_mask{};
};
struct widget_padding
{
@ -459,9 +439,31 @@ class FWidget : public FVTerm, public FObject
int left{0};
int bottom{0};
int right{0};
} padding{};
};
// Methods
void initRootWidget();
void finish();
void insufficientSpaceAdjust();
void KeyPressEvent (FKeyEvent*);
void KeyDownEvent (FKeyEvent*);
void emitWheelCallback (const FWheelEvent*);
void setWindowFocus (bool);
FCallbackPtr getCallbackPtr (const FCallback&);
bool changeFocus (FWidget*, FWidget*, fc::FocusTypes);
void processDestroy();
virtual void draw();
void drawWindows();
void drawChildren();
static void setColorTheme();
void setStatusbarText (bool);
// Data members
struct FWidgetFlags flags{};
FPoint widget_cursor_position{-1, -1};
widget_size_hints size_hints{};
dbl_line_mask double_flatline_mask{};
widget_padding padding{};
bool ignore_padding{false};
// widget size
@ -843,7 +845,11 @@ inline bool FWidget::setDisable()
//----------------------------------------------------------------------
inline bool FWidget::setVisibleCursor (bool enable)
{
flags.visible_cursor = ( enable ) ? true : (( hideable ) ? false : true);
if ( enable )
flags.visible_cursor = true;
else
flags.visible_cursor = ( hideable ) ? false : true;
return flags.visible_cursor;
}

View File

@ -65,7 +65,8 @@ void SGRoptimizer::findParameter()
return;
std::size_t start{NOT_SET};
bool esc{false}, csi{false};
bool esc{false};
bool csi{false};
// Find SGR parameter
for (std::size_t i = 0; i < len; i++)