From 0b51df32b5d69d9c24b57a91ab3a021d053230bc Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 8 Oct 2018 04:14:20 +0200 Subject: [PATCH 01/17] Move all termcap code into FTermcap --- ChangeLog | 3 + src/fapplication.cpp | 12 +- src/fbutton.cpp | 16 +- src/fbuttongroup.cpp | 4 +- src/flabel.cpp | 4 +- src/flineedit.cpp | 4 +- src/flistbox.cpp | 8 +- src/flistview.cpp | 56 ++--- src/fmenubar.cpp | 4 +- src/fmouse.cpp | 2 - src/fprogressbar.cpp | 4 +- src/fstatusbar.cpp | 4 +- src/fstring.cpp | 8 +- src/fterm.cpp | 320 ++++------------------------- src/ftermcap.cpp | 292 +++++++++++++++++++++++++- src/ftermcapquirks.cpp | 46 ++--- src/ftermlinux.cpp | 2 +- src/ftextview.cpp | 8 +- src/ftogglebutton.cpp | 4 +- src/fvterm.cpp | 25 +-- src/include/final/fmouse.h | 1 - src/include/final/fterm.h | 56 +---- src/include/final/ftermcap.h | 51 ++++- src/include/final/ftermcapquirks.h | 22 +- src/include/final/fvterm.h | 6 +- test/ftermdata-test.cpp | 4 +- 26 files changed, 496 insertions(+), 470 deletions(-) diff --git a/ChangeLog b/ChangeLog index 933985eb..b6921e88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-10-08 Markus Gans + * Move all termcap code into FTermcap + 2018-10-05 Markus Gans * Remove redundant program code from FString diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 3e3a5d3d..9b77d01e 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -346,9 +346,7 @@ void FApplication::showParameterUsage() << " Do not send a ESC prefix for the alt/meta key" << std::endl << " --no-cursorstyle-change" << " Do not change the current cursor style" << std::endl -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) << std::endl << "NetBSD/OpenBSD console options:" << std::endl << " --no-esc-for-alt-meta " @@ -436,9 +434,7 @@ void FApplication::cmd_options (const int& argc, char* argv[]) #if defined(__FreeBSD__) || defined(__DragonFly__) {C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 }, {C_STR("no-cursorstyle-change"), no_argument, 0, 0 }, - #endif - - #if defined(__NetBSD__) || defined(__OpenBSD__) + #elif defined(__NetBSD__) || defined(__OpenBSD__) {C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 }, #endif @@ -497,9 +493,7 @@ void FApplication::cmd_options (const int& argc, char* argv[]) if ( std::strcmp(long_options[idx].name, "no-cursorstyle-change") == 0 ) init_values.change_cursorstyle = false; - #endif - - #if defined(__NetBSD__) || defined(__OpenBSD__) + #elif defined(__NetBSD__) || defined(__OpenBSD__) if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) init_values.meta_sends_escape = false; #endif diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 4a93ea78..5e45b60c 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -290,7 +290,7 @@ void FButton::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -298,7 +298,7 @@ void FButton::hide() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getHeight() + s + (f << 1); y++) @@ -489,19 +489,19 @@ void FButton::getButtonState() //---------------------------------------------------------------------- uChar FButton::getHotkey() { - int length; + uInt length; if ( text.isEmpty() ) return 0; - length = int(text.getLength()); + length = text.getLength(); - for (int i = 0; i < length; i++) + for (uInt i = 0; i < length; i++) { try { - if ( i + 1 < length && text[uInt(i)] == '&' ) - return uChar(text[uInt(++i)]); + if ( i + 1 < length && text[i] == '&' ) + return uChar(text[++i]); } catch (const std::out_of_range&) { @@ -754,7 +754,7 @@ void FButton::draw() try { - button_text = new wchar_t[uInt(txtlength) + 1](); + button_text = new wchar_t[std::size_t(txtlength) + 1](); } catch (const std::bad_alloc& ex) { diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 77b2a505..d1c3bef2 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -228,7 +228,7 @@ void FButtonGroup::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -236,7 +236,7 @@ void FButtonGroup::hide() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getHeight(); y++) diff --git a/src/flabel.cpp b/src/flabel.cpp index fc80a391..9ad63be0 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -267,7 +267,7 @@ void FLabel::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -275,7 +275,7 @@ void FLabel::hide() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[getWidth()] = '\0'; setPrintPos (1,1); print (blank); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 6648c2e9..f584d1fc 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -308,7 +308,7 @@ void FLineEdit::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -316,7 +316,7 @@ void FLineEdit::hide() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getHeight() + s; y++) diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 0cd7bf19..1c2ec9b5 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -267,7 +267,7 @@ void FListBox::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -275,7 +275,7 @@ void FListBox::hide() return; } - std::memset (blank, ' ', uLong(size)); + std::memset (blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getHeight(); y++) @@ -402,7 +402,7 @@ void FListBox::clear() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -410,7 +410,7 @@ void FListBox::clear() return; } - std::memset (blank, ' ', uLong(size)); + std::memset (blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getHeight() - 2; y++) diff --git a/src/flistview.cpp b/src/flistview.cpp index c02fdd6c..868a5332 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -237,8 +237,9 @@ FString FListViewItem::getText (int column) const || column > int(column_list.size()) ) return fc::emptyFString::get(); - column--; // Convert column position to address offset (index) - return column_list[uInt(column)]; + // Convert column position to address offset (index) + std::size_t index = uInt(column - 1); + return column_list[index]; } //---------------------------------------------------------------------- @@ -263,23 +264,24 @@ void FListViewItem::setText (int column, const FString& text) || column > int(column_list.size()) ) return; + // Convert column position to address offset (index) + std::size_t index = uInt(column - 1); FObject* parent = getParent(); - column--; // Convert column position to address offset (index) if ( parent && parent->isInstanceOf("FListView") ) { FListView* listview = static_cast(parent); - if ( ! listview->header[uInt(column)].fixed_width ) + if ( ! listview->header[index].fixed_width ) { int length = int(text.getLength()); - if ( length > listview->header[uInt(column)].width ) - listview->header[uInt(column)].width = length; + if ( length > listview->header[index].width ) + listview->header[index].width = length; } } - column_list[uInt(column)] = text; + column_list[index] = text; } //---------------------------------------------------------------------- @@ -346,15 +348,15 @@ void FListViewItem::sort (Compare cmp) return; // Sort the top level - FObject::FObjectList& children_list = getChildren(); + FObject::FObjectList& children = getChildren(); - if ( ! children_list.empty() ) - children_list.sort(cmp); + if ( ! children.empty() ) + children.sort(cmp); // Sort the sublevels - FListViewIterator iter = children_list.begin(); + FListViewIterator iter = begin(); - while ( iter != children_list.end() ) + while ( iter != end() ) { if ( *iter ) { @@ -652,8 +654,9 @@ fc::text_alignment FListView::getColumnAlignment (int column) const if ( column < 1 || header.empty() || column > int(header.size()) ) return fc::alignLeft; - column--; // Convert column position to address offset (index) - return header[uInt(column)].alignment; + // Convert column position to address offset (index) + std::size_t index = uInt(column - 1); + return header[index].alignment; } //---------------------------------------------------------------------- @@ -664,19 +667,20 @@ FString FListView::getColumnText (int column) const if ( column < 1 || header.empty() || column > int(header.size()) ) return fc::emptyFString::get(); - column--; // Convert column position to address offset (index) - return header[uInt(column)].name; + // Convert column position to address offset (index) + std::size_t index = uInt(column - 1); + return header[index].name; } //---------------------------------------------------------------------- fc::sorting_type FListView::getColumnSortType (int column) const { fc::sorting_type type; - std::size_t size = uInt(column); + std::size_t col = uInt(column); try { - type = sort_type.at(size); + type = sort_type.at(col); } catch (const std::out_of_range&) { @@ -713,8 +717,9 @@ void FListView::setColumnAlignment (int column, fc::text_alignment align) if ( column < 1 || header.empty() || column > int(header.size()) ) return; - column--; // Convert column position to address offset (index) - header[uInt(column)].alignment = align; + // Convert column position to address offset (index) + std::size_t index = uInt(column - 1); + header[index].alignment = align; } //---------------------------------------------------------------------- @@ -725,17 +730,18 @@ void FListView::setColumnText (int column, const FString& label) if ( column < 1 || header.empty() || column > int(header.size()) ) return; - column--; // Convert column position to address offset (index) + // Convert column position to address offset (index) + std::size_t index = uInt(column - 1); - if ( ! header[uInt(column)].fixed_width ) + if ( ! header[index].fixed_width ) { int length = int(label.getLength()); - if ( length > header[uInt(column)].width ) - header[uInt(column)].width = length; + if ( length > header[index].width ) + header[index].width = length; } - header[uInt(column)].name = label; + header[index].name = label; } //---------------------------------------------------------------------- diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 6e2d8d19..74207f4d 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -77,7 +77,7 @@ void FMenuBar::hide() try { - blank = new char[uInt(screenWidth) + 1]; + blank = new char[std::size_t(screenWidth) + 1]; } catch (const std::bad_alloc& ex) { @@ -85,7 +85,7 @@ void FMenuBar::hide() return; } - std::memset(blank, ' ', uLong(screenWidth)); + std::memset(blank, ' ', std::size_t(screenWidth)); blank[screenWidth] = '\0'; setPrintPos (1,1); print (blank); diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 298204c1..292d3edd 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -1487,13 +1487,11 @@ bool FMouseControl::isGpmMouseEnabled() return false; #ifdef F_HAVE_LIBGPM - FMouse* mouse = mouse_protocol[FMouse::gpm]; FMouseGPM* gpm_mouse = static_cast(mouse); if ( gpm_mouse ) return gpm_mouse->isGpmMouseEnabled(); - #endif // F_HAVE_LIBGPM return false; diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index a2653f82..993b8c75 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -126,7 +126,7 @@ void FProgressbar::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -134,7 +134,7 @@ void FProgressbar::hide() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getHeight() + s; y++) diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index cd40903d..623cb8f2 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -210,7 +210,7 @@ void FStatusBar::hide() try { - blank = new char[uInt(screenWidth) + 1]; + blank = new char[std::size_t(screenWidth) + 1]; } catch (const std::bad_alloc& ex) { @@ -218,7 +218,7 @@ void FStatusBar::hide() return; } - std::memset(blank, ' ', uLong(screenWidth)); + std::memset(blank, ' ', std::size_t(screenWidth)); blank[screenWidth] = '\0'; setPrintPos (1, 1); print (blank); diff --git a/src/fstring.cpp b/src/fstring.cpp index a8e40270..13c83e57 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -1750,7 +1750,7 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const try { - c_string = new char[uInt(dest_size)](); + c_string = new char[std::size_t(dest_size)](); // pre-initialiaze the whole string with '\0' std::memset (c_string, '\0', std::size_t(dest_size)); @@ -1761,7 +1761,7 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const return 0; } - mblength = int(std::wcsrtombs (c_string, &src, uLong(dest_size), &state)); + mblength = int(std::wcsrtombs (c_string, &src, std::size_t(dest_size), &state)); if ( mblength == -1 && errno != EILSEQ ) { @@ -1807,7 +1807,7 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const try { - dest = new wchar_t[uInt(size)](); + dest = new wchar_t[std::size_t(size)](); // pre-initialiaze the whole string with '\0' std::wmemset (dest, L'\0', std::size_t(size)); } @@ -1817,7 +1817,7 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const return 0; } - wclength = int(std::mbsrtowcs (dest, &src, uLong(dest_size), &state)); + wclength = int(std::mbsrtowcs (dest, &src, std::size_t(dest_size), &state)); if ( wclength == -1 ) { diff --git a/src/fterm.cpp b/src/fterm.cpp index 5acf5408..b1e244d6 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -53,13 +53,9 @@ FMouseControl* FTerm::mouse = 0; #if defined(__linux__) FTermLinux* FTerm::linux = 0; -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) FTermFreeBSD* FTerm::freebsd = 0; -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) FTermOpenBSD* FTerm::openbsd = 0; #endif @@ -840,9 +836,7 @@ void FTerm::initScreenSettings() linux->initCharMap (fc::character); data->supportShadowCharacter (linux->hasShadowCharacter()); data->supportHalfBlockCharacter (linux->hasHalfBlockCharacter()); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) freebsd->initCharMap (fc::character); #endif @@ -1091,269 +1085,32 @@ void FTerm::init_keyboard() } //---------------------------------------------------------------------- -/* Terminal capability data base - * ----------------------------- - * Info under: man 5 terminfo - * - * Importent shell commands: - * captoinfo - convert all termcap descriptions into terminfo descriptions - * infocmp - print out terminfo description from the current terminal - */ void FTerm::init_termcap() { - std::vector terminals; - std::vector::iterator iter; - static const int success = 1; - static const int uninitialized = -2; - static char term_buffer[2048]; - static char string_buf[2048]; - char* buffer = string_buf; - int status = uninitialized; - bool color256 = term_detection->canDisplay256Colors(); + // Initialize the terminal capabilities + + FTermcap termcap; + termcap.setTermData(data); + termcap.setFTermDetection(term_detection); + termcap.init(); // Share the terminal capabilities - tcap = FTermcap::getTermcapMap(); - - // Open termcap file - const char* termtype = data->getTermType(); - terminals.push_back(termtype); // available terminal type - - if ( color256 ) // 1st fallback if not found - terminals.push_back("xterm-256color"); - - terminals.push_back("xterm"); // 2nd fallback if not found - terminals.push_back("ansi"); // 3rd fallback if not found - terminals.push_back("vt100"); // 4th fallback if not found - iter = terminals.begin(); - - while ( iter != terminals.end() ) - { - data->setTermType(iter->c_str()); - - // Open the termcap file + load entry for termtype - status = tgetent(term_buffer, termtype); - - if ( status == success || ! term_detection->hasTerminalDetection() ) - break; - - ++iter; - } - - if ( std::strncmp(termtype, "ansi", 4) == 0 ) - term_detection->setAnsiTerminal (true); - - init_termcap_error (status); - init_termcap_variables (buffer); + tcap = termcap.getTermcapMap(); } //---------------------------------------------------------------------- -void FTerm::init_termcap_error (int status) +void FTerm::init_quirks() { - static const int no_entry = 0; - static const int db_not_found = -1; - static const int uninitialized = -2; + // Initialize terminal quirks - if ( status == no_entry || status == uninitialized ) - { - const char* termtype = data->getTermType(); - std::cerr << "Unknown terminal: " << termtype << "\n" - << "Check the TERM environment variable\n" - << "Also make sure that the terminal\n" - << "is defined in the termcap/terminfo database.\n"; - std::abort(); - } - else if ( status == db_not_found ) - { - std::cerr << "The termcap/terminfo database could not be found.\n"; - std::abort(); - } -} - -//---------------------------------------------------------------------- -void FTerm::init_termcap_variables (char*& buffer) -{ - // Get termcap booleans - init_termcap_booleans(); - - // Get termcap numerics - init_termcap_numerics(); - - // Get termcap strings - init_termcap_strings(buffer); - - // Terminal quirks FTermcapQuirks quirks; quirks.setTermData (data); quirks.setFTermDetection (term_detection); - quirks.terminalFixup(); // Fix terminal quirks - - // Get termcap keys - init_termcap_keys(buffer); - - // Initialize cursor movement optimization - init_OptiMove(); - - // Initialize video attributes optimization - init_OptiAttr(); + quirks.terminalFixup(); // Fix terminal quirks } //---------------------------------------------------------------------- -void FTerm::init_termcap_booleans() -{ - // Get termcap booleans - - // Screen erased with the background color - FTermcap::background_color_erase = tgetflag(C_STR("ut")); - - // t_cursor_left wraps from column 0 to last column - FTermcap::automatic_left_margin = tgetflag(C_STR("bw")); - - // Terminal has auto-matic margins - FTermcap::automatic_right_margin = tgetflag(C_STR("am")); - - // NewLine ignored after 80 cols - FTermcap::eat_nl_glitch = tgetflag(C_STR("xn")); - - // Terminal supports ANSI set default fg and bg color - FTermcap::ansi_default_color = tgetflag(C_STR("AX")); - - // Terminal supports operating system commands (OSC) - // OSC = Esc + ']' - FTermcap::osc_support = tgetflag(C_STR("XT")); - - // U8 is nonzero for terminals with no VT100 line-drawing in UTF-8 mode - FTermcap::no_utf8_acs_chars = bool(tgetnum(C_STR("U8")) != 0); -} - -//---------------------------------------------------------------------- -void FTerm::init_termcap_numerics() -{ - // Get termcap numeric - - // Maximum number of colors on screen - FTermcap::max_color = std::max( FTermcap::max_color - , tgetnum(C_STR("Co")) ); - - if ( getMaxColor() < 0 ) - FTermcap::max_color = 1; - - if ( getMaxColor() < 8 ) - data->setMonochron(true); - else - data->setMonochron(false); - - // Get initial spacing for hardware tab stop - FTermcap::tabstop = tgetnum(C_STR("it")); - - // Get video attributes that cannot be used with colors - FTermcap::attr_without_color = tgetnum(C_STR("NC")); -} - -//---------------------------------------------------------------------- -void FTerm::init_termcap_strings (char*& buffer) -{ - // Get termcap strings - - // Read termcap output strings - for (int i = 0; tcap[i].tname[0] != 0; i++) - tcap[i].string = tgetstr(tcap[i].tname, &buffer); -} - -//---------------------------------------------------------------------- -void FTerm::init_termcap_keys_vt100 (char*& buffer) -{ - // Some terminals (e.g. PuTTY) send vt100 key codes for - // the arrow and function keys. - - char* key_up_string = tgetstr(C_STR("ku"), &buffer); - - if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0)) - || ( TCAP(fc::t_cursor_up) - && (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) ) - { - for (int i = 0; fc::Fkey[i].tname[0] != 0; i++) - { - if ( std::strncmp(fc::Fkey[i].tname, "kux", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "A"); // Key up - - if ( std::strncmp(fc::Fkey[i].tname, "kdx", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "B"); // Key down - - if ( std::strncmp(fc::Fkey[i].tname, "krx", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "C"); // Key right - - if ( std::strncmp(fc::Fkey[i].tname, "klx", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "D"); // Key left - - if ( std::strncmp(fc::Fkey[i].tname, "k1X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OP"); // PF1 - - if ( std::strncmp(fc::Fkey[i].tname, "k2X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OQ"); // PF2 - - if ( std::strncmp(fc::Fkey[i].tname, "k3X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OR"); // PF3 - - if ( std::strncmp(fc::Fkey[i].tname, "k4X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OS"); // PF4 - } - } -} -//---------------------------------------------------------------------- -void FTerm::init_termcap_keys (char*& buffer) -{ - // Read termcap key strings - - for (int i = 0; fc::Fkey[i].tname[0] != 0; i++) - { - fc::Fkey[i].string = tgetstr(fc::Fkey[i].tname, &buffer); - - // Fallback for rxvt with TERM=xterm - if ( std::strncmp(fc::Fkey[i].tname, "khx", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "7~"); // Home key - - if ( std::strncmp(fc::Fkey[i].tname, "@7x", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "8~"); // End key - - if ( std::strncmp(fc::Fkey[i].tname, "k1x", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "11~"); // F1 - - if ( std::strncmp(fc::Fkey[i].tname, "k2x", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "12~"); // F2 - - if ( std::strncmp(fc::Fkey[i].tname, "k3x", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "13~"); // F3 - - if ( std::strncmp(fc::Fkey[i].tname, "k4x", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "14~"); // F4 - - // Fallback for TERM=ansi - if ( std::strncmp(fc::Fkey[i].tname, "@7X", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "K"); // End key - - // Keypad keys - if ( std::strncmp(fc::Fkey[i].tname, "@8x", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OM"); // Enter key - - if ( std::strncmp(fc::Fkey[i].tname, "KP1", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "Oo"); // Keypad slash - - if ( std::strncmp(fc::Fkey[i].tname, "KP2", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "Oj"); // Keypad asterisk - - if ( std::strncmp(fc::Fkey[i].tname, "KP3", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "Om"); // Keypad minus sign - - if ( std::strncmp(fc::Fkey[i].tname, "KP4", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "Ok"); // Keypad plus sign - } - - // VT100 key codes for the arrow and function keys - init_termcap_keys_vt100(buffer); -} - -//---------------------------------------------------------------------- -void FTerm::init_OptiMove() +void FTerm::init_optiMove() { // Duration precalculation of the cursor movement strings @@ -1388,7 +1145,7 @@ void FTerm::init_OptiMove() } //---------------------------------------------------------------------- -void FTerm::init_OptiAttr() +void FTerm::init_optiAttr() { // Setting video attribute optimization @@ -1719,9 +1476,7 @@ void FTerm::setInsertCursorStyle() , data->isCursorHidden() ); putstring (cstyle); std::fflush(stdout); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) freebsd->setCursorStyle ( fc::destructive_cursor , data->isCursorHidden() ); #endif @@ -1742,9 +1497,7 @@ void FTerm::setOverwriteCursorStyle() , data->isCursorHidden() ); putstring (cstyle); std::fflush(stdout); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) freebsd->setCursorStyle ( fc::normal_cursor , data->isCursorHidden() ); #endif @@ -1846,13 +1599,9 @@ inline void FTerm::allocationValues() #if defined(__linux__) linux = new FTermLinux(); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) freebsd = new FTermFreeBSD(); -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) openbsd = new FTermOpenBSD(); #endif } @@ -1870,14 +1619,10 @@ inline void FTerm::deallocationValues() #if defined(__NetBSD__) || defined(__OpenBSD__) if ( openbsd ) delete openbsd; -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) if ( freebsd ) delete freebsd; -#endif - -#if defined(__linux__) +#elif defined(__linux__) if ( linux ) delete linux; #endif @@ -1943,6 +1688,17 @@ void FTerm::init (bool disable_alt_screen) // Initializes variables for the current terminal init_termcap(); + + // Initialize terminal quirks + init_quirks(); + + // Initialize cursor movement optimization + init_optiMove(); + + // Initialize video attributes optimization + init_optiAttr(); + + // Initialize vt100 alternate character set init_alt_charset(); // Pass the terminal capabilities to the keyboard object @@ -2043,9 +1799,7 @@ void FTerm::initOSspecifics() freebsd->disableChangeCursorStyle(); freebsd->init(); // Initialize BSD console -#endif // defined(__FreeBSD__) || defined(__DragonFly__) - -#if defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) if ( init_values.meta_sends_escape ) openbsd->enableMetaSendsEscape(); else @@ -2150,13 +1904,9 @@ void FTerm::finishOSspecifics1() { #if defined(__linux__) linux->finish(); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) freebsd->finish(); -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) openbsd->finish(); #endif } diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index 7e0f15ce..071bcca6 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -26,16 +26,18 @@ namespace finalcut { // static class attributes -bool FTermcap::background_color_erase = false; -bool FTermcap::automatic_left_margin = false; -bool FTermcap::automatic_right_margin = false; -bool FTermcap::eat_nl_glitch = false; -bool FTermcap::ansi_default_color = false; -bool FTermcap::osc_support = false; -bool FTermcap::no_utf8_acs_chars = false; -int FTermcap::max_color = 1; -int FTermcap::tabstop = 8; -int FTermcap::attr_without_color = 0; +bool FTermcap::background_color_erase = false; +bool FTermcap::automatic_left_margin = false; +bool FTermcap::automatic_right_margin = false; +bool FTermcap::eat_nl_glitch = false; +bool FTermcap::ansi_default_color = false; +bool FTermcap::osc_support = false; +bool FTermcap::no_utf8_acs_chars = false; +int FTermcap::max_color = 1; +int FTermcap::tabstop = 8; +int FTermcap::attr_without_color = 0; +FTermData* FTermcap::fterm_data = 0; +FTermDetection* FTermcap::term_detection = 0; //---------------------------------------------------------------------- @@ -51,6 +53,276 @@ FTermcap::FTermcap() FTermcap::~FTermcap() // destructor { } +/* Terminal capability data base + * ----------------------------- + * Info under: man 5 terminfo + * + * Importent shell commands: + * captoinfo - convert all termcap descriptions into terminfo descriptions + * infocmp - print out terminfo description from the current terminal + */ + +// public methods of FTermcap +//---------------------------------------------------------------------- +void FTermcap::setTermData (FTermData* data) +{ + fterm_data = data; +} + +//---------------------------------------------------------------------- +void FTermcap::setFTermDetection (FTermDetection* td) +{ + term_detection = td; +} + +//---------------------------------------------------------------------- +void FTermcap::init() +{ + termcap(); +} + +// private methods of FTermcap +//---------------------------------------------------------------------- +void FTermcap::termcap() +{ + std::vector terminals; + std::vector::iterator iter; + static const int success = 1; + static const int uninitialized = -2; + static char term_buffer[2048]; + static char string_buf[2048]; + char* buffer = string_buf; + int status = uninitialized; + bool color256 = term_detection->canDisplay256Colors(); + + // Open termcap file + const char* termtype = fterm_data->getTermType(); + terminals.push_back(termtype); // available terminal type + + if ( color256 ) // 1st fallback if not found + terminals.push_back("xterm-256color"); + + terminals.push_back("xterm"); // 2nd fallback if not found + terminals.push_back("ansi"); // 3rd fallback if not found + terminals.push_back("vt100"); // 4th fallback if not found + iter = terminals.begin(); + + while ( iter != terminals.end() ) + { + fterm_data->setTermType(iter->c_str()); + + // Open the termcap file + load entry for termtype + status = tgetent(term_buffer, termtype); + + if ( status == success || ! term_detection->hasTerminalDetection() ) + break; + + ++iter; + } + + if ( std::strncmp(termtype, "ansi", 4) == 0 ) + term_detection->setAnsiTerminal (true); + + termcapError (status); + termcapVariables (buffer); +} + +//---------------------------------------------------------------------- +void FTermcap::termcapError (int status) +{ + static const int no_entry = 0; + static const int db_not_found = -1; + static const int uninitialized = -2; + + if ( status == no_entry || status == uninitialized ) + { + const char* termtype = fterm_data->getTermType(); + std::cerr << "Unknown terminal: " << termtype << "\n" + << "Check the TERM environment variable\n" + << "Also make sure that the terminal\n" + << "is defined in the termcap/terminfo database.\n"; + std::abort(); + } + else if ( status == db_not_found ) + { + std::cerr << "The termcap/terminfo database could not be found.\n"; + std::abort(); + } +} + +//---------------------------------------------------------------------- +void FTermcap::termcapVariables (char*& buffer) +{ + // Get termcap booleans + termcapBoleans(); + + // Get termcap numerics + termcapNumerics(); + + // Get termcap strings + termcapStrings (buffer); + + // Get termcap keys + termcapKeys (buffer); +} + +//---------------------------------------------------------------------- +void FTermcap::termcapBoleans() +{ + // Get termcap booleans + + // Screen erased with the background color + background_color_erase = tgetflag(C_STR("ut")); + + // t_cursor_left wraps from column 0 to last column + automatic_left_margin = tgetflag(C_STR("bw")); + + // Terminal has auto-matic margins + automatic_right_margin = tgetflag(C_STR("am")); + + // NewLine ignored after 80 cols + eat_nl_glitch = tgetflag(C_STR("xn")); + + // Terminal supports ANSI set default fg and bg color + ansi_default_color = tgetflag(C_STR("AX")); + + // Terminal supports operating system commands (OSC) + // OSC = Esc + ']' + osc_support = tgetflag(C_STR("XT")); + + // U8 is nonzero for terminals with no VT100 line-drawing in UTF-8 mode + no_utf8_acs_chars = bool(tgetnum(C_STR("U8")) != 0); +} + +//---------------------------------------------------------------------- +void FTermcap::termcapNumerics() +{ + // Get termcap numeric + + // Maximum number of colors on screen + max_color = std::max(max_color, tgetnum(C_STR("Co"))); + + if ( max_color < 0 ) + max_color = 1; + + if ( max_color < 8 ) + fterm_data->setMonochron(true); + else + fterm_data->setMonochron(false); + + // Get initial spacing for hardware tab stop + tabstop = tgetnum(C_STR("it")); + + // Get video attributes that cannot be used with colors + attr_without_color = tgetnum(C_STR("NC")); +} + +//---------------------------------------------------------------------- +void FTermcap::termcapStrings (char*& buffer) +{ + // Get termcap strings + + // Read termcap output strings + for (int i = 0; tcap[i].tname[0] != 0; i++) + tcap[i].string = tgetstr(tcap[i].tname, &buffer); +} + + + +//---------------------------------------------------------------------- +void FTermcap::termcapKeys (char*& buffer) +{ + // Read termcap key strings + + for (int i = 0; fc::Fkey[i].tname[0] != 0; i++) + { + fc::Fkey[i].string = tgetstr(fc::Fkey[i].tname, &buffer); + + // Fallback for rxvt with TERM=xterm + if ( std::strncmp(fc::Fkey[i].tname, "khx", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "7~"); // Home key + + if ( std::strncmp(fc::Fkey[i].tname, "@7x", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "8~"); // End key + + if ( std::strncmp(fc::Fkey[i].tname, "k1x", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "11~"); // F1 + + if ( std::strncmp(fc::Fkey[i].tname, "k2x", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "12~"); // F2 + + if ( std::strncmp(fc::Fkey[i].tname, "k3x", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "13~"); // F3 + + if ( std::strncmp(fc::Fkey[i].tname, "k4x", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "14~"); // F4 + + // Fallback for TERM=ansi + if ( std::strncmp(fc::Fkey[i].tname, "@7X", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "K"); // End key + + // Keypad keys + if ( std::strncmp(fc::Fkey[i].tname, "@8x", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OM"); // Enter key + + if ( std::strncmp(fc::Fkey[i].tname, "KP1", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "Oo"); // Keypad slash + + if ( std::strncmp(fc::Fkey[i].tname, "KP2", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "Oj"); // Keypad asterisk + + if ( std::strncmp(fc::Fkey[i].tname, "KP3", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "Om"); // Keypad minus sign + + if ( std::strncmp(fc::Fkey[i].tname, "KP4", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "Ok"); // Keypad plus sign + } + + // VT100 key codes for the arrow and function keys + termcapKeysVt100 (buffer); +} + +//---------------------------------------------------------------------- +void FTermcap::termcapKeysVt100 (char*& buffer) +{ + // Some terminals (e.g. PuTTY) send vt100 key codes for + // the arrow and function keys. + + char* key_up_string = tgetstr(C_STR("ku"), &buffer); + + if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0)) + || ( TCAP(fc::t_cursor_up) + && (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) ) + { + for (int i = 0; fc::Fkey[i].tname[0] != 0; i++) + { + if ( std::strncmp(fc::Fkey[i].tname, "kux", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "A"); // Key up + + if ( std::strncmp(fc::Fkey[i].tname, "kdx", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "B"); // Key down + + if ( std::strncmp(fc::Fkey[i].tname, "krx", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "C"); // Key right + + if ( std::strncmp(fc::Fkey[i].tname, "klx", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "D"); // Key left + + if ( std::strncmp(fc::Fkey[i].tname, "k1X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OP"); // PF1 + + if ( std::strncmp(fc::Fkey[i].tname, "k2X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OQ"); // PF2 + + if ( std::strncmp(fc::Fkey[i].tname, "k3X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OR"); // PF3 + + if ( std::strncmp(fc::Fkey[i].tname, "k4X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OS"); // PF4 + } + } +} + // private Data Member of FTermcap - termcap capabilities //---------------------------------------------------------------------- diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index 18b085e5..4e77b038 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -69,54 +69,54 @@ void FTermcapQuirks::terminalFixup() if ( td->isCygwinTerminal() ) { - init_termcap_cygwin_quirks(); + cygwin(); } else if ( td->isLinuxTerm() ) { - init_termcap_linux_quirks(); + linux(); } else if ( td->isRxvtTerminal() ) { - init_termcap_rxvt_quirks(); + rxvt(); } else if ( td->isGnomeTerminal() ) { - init_termcap_vte_quirks(); + vte(); } else if ( td->isTeraTerm() ) { - init_termcap_teraterm_quirks(); + teraterm(); } else if ( td->isSunTerminal() ) { - init_termcap_sun_quirks(); + sun(); } else if ( td->isPuttyTerminal() ) { - init_termcap_putty_quirks(); + putty(); } else if ( td->isScreenTerm() ) { - init_termcap_screen_quirks(); + screen(); } #if defined(__FreeBSD__) || defined(__DragonFly__) else if ( td->isFreeBSDTerm() ) { - init_termcap_freebsd_quirks(); + freebsd(); } #endif // defined(__FreeBSD__) || defined(__DragonFly__) // xterm and compatible terminals if ( td->isXTerminal() && ! td->isPuttyTerminal() ) - init_termcap_xterm_quirks(); + xterm(); // Fixes general quirks - init_termcap_general_quirks(); + general(); } #if defined(__FreeBSD__) || defined(__DragonFly__) //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_freebsd_quirks() +void FTermcapQuirks::freebsd() { // FreeBSD console fixes @@ -142,7 +142,7 @@ void FTermcapQuirks::init_termcap_freebsd_quirks() #endif // defined(__FreeBSD__) || defined(__DragonFly__) //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_cygwin_quirks() +void FTermcapQuirks::cygwin() { // Set invisible cursor for cygwin terminal if ( ! TCAP(fc::t_cursor_invisible) ) @@ -168,11 +168,11 @@ void FTermcapQuirks::init_termcap_cygwin_quirks() FTermcap::background_color_erase = true; // Include the Linux console quirks - init_termcap_linux_quirks(); + linux(); } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_linux_quirks() +void FTermcapQuirks::linux() { /* Same settings are used by cygwin */ @@ -223,7 +223,7 @@ void FTermcapQuirks::init_termcap_linux_quirks() } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_xterm_quirks() +void FTermcapQuirks::xterm() { // Fallback if "Ic" is not found if ( ! TCAP(fc::t_initialize_color) ) @@ -247,7 +247,7 @@ void FTermcapQuirks::init_termcap_xterm_quirks() } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_rxvt_quirks() +void FTermcapQuirks::rxvt() { // Set enter/exit alternative charset mode for rxvt terminal const char* termtype = fterm_data->getTermType(); @@ -271,7 +271,7 @@ void FTermcapQuirks::init_termcap_rxvt_quirks() } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_vte_quirks() +void FTermcapQuirks::vte() { // gnome-terminal has NC=16 however, it can use the dim attribute FTermcap::attr_without_color = 0; @@ -282,7 +282,7 @@ void FTermcapQuirks::init_termcap_vte_quirks() } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_putty_quirks() +void FTermcapQuirks::putty() { FTermcap::background_color_erase = true; FTermcap::osc_support = true; @@ -368,7 +368,7 @@ void FTermcapQuirks::init_termcap_putty_quirks() } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_teraterm_quirks() +void FTermcapQuirks::teraterm() { // Tera Term eat_nl_glitch fix FTermcap::eat_nl_glitch = true; @@ -385,14 +385,14 @@ void FTermcapQuirks::init_termcap_teraterm_quirks() } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_sun_quirks() +void FTermcapQuirks::sun() { // Sun Microsystems workstation console eat_nl_glitch fix FTermcap::eat_nl_glitch = true; } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_screen_quirks() +void FTermcapQuirks::screen() { // Fallback if "Ic" is not found if ( ! TCAP(fc::t_initialize_color) ) @@ -417,7 +417,7 @@ void FTermcapQuirks::init_termcap_screen_quirks() } //---------------------------------------------------------------------- -void FTermcapQuirks::init_termcap_general_quirks() +void FTermcapQuirks::general() { static const int not_available = -1; diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index e802805e..8dec6fc7 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -589,7 +589,7 @@ bool FTermLinux::getUnicodeMap() try { - screen_unicode_map.entries = new struct unipair[uInt(count)](); + screen_unicode_map.entries = new struct unipair[std::size_t(count)](); } catch (const std::bad_alloc& ex) { diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 8da1d863..9e64cf39 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -220,7 +220,7 @@ void FTextView::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -228,7 +228,7 @@ void FTextView::hide() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getHeight(); y++) @@ -355,7 +355,7 @@ void FTextView::clear() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -363,7 +363,7 @@ void FTextView::clear() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; for (int y = 0; y < getTextHeight(); y++) diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 8c9f5d0d..d5c65d95 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -243,7 +243,7 @@ void FToggleButton::hide() try { - blank = new char[uInt(size) + 1]; + blank = new char[std::size_t(size) + 1]; } catch (const std::bad_alloc& ex) { @@ -251,7 +251,7 @@ void FToggleButton::hide() return; } - std::memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; setPrintPos (1, 1); print (blank); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 753d153d..e0f7adf1 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -653,7 +653,7 @@ void FVTerm::resizeArea ( int offset_left, int offset_top assert ( height > 0 ); assert ( rsw >= 0 ); assert ( bsh >= 0 ); - int area_size; + std::size_t area_size; bool realloc_success = false; if ( ! area ) @@ -673,11 +673,13 @@ void FVTerm::resizeArea ( int offset_left, int offset_top return; } - area_size = (width + rsw) * (height + bsh); + area_size = std::size_t((width + rsw) * (height + bsh)); if ( area->height + area->bottom_shadow != height + bsh ) { - realloc_success = reallocateTextArea (area, height + bsh, area_size); + realloc_success = reallocateTextArea ( area + , std::size_t(height + bsh) + , area_size ); } else if ( area->width + area->right_shadow != width + rsw ) { @@ -727,12 +729,9 @@ inline void FVTerm::setTextToDefault ( term_area* area //---------------------------------------------------------------------- inline bool FVTerm::reallocateTextArea ( term_area* area - , int height - , int size ) + , std::size_t height + , std::size_t size ) { - assert ( height > 0 ); - assert ( size > 0 ); - if ( area->changes != 0 ) delete[] area->changes; @@ -741,8 +740,8 @@ inline bool FVTerm::reallocateTextArea ( term_area* area try { - area->changes = new line_changes[uInt(height)]; - area->text = new charData[uInt(size)]; + area->changes = new line_changes[height]; + area->text = new charData[size]; } catch (const std::bad_alloc& ex) { @@ -754,16 +753,14 @@ inline bool FVTerm::reallocateTextArea ( term_area* area } //---------------------------------------------------------------------- -inline bool FVTerm::reallocateTextArea (term_area* area, int size) +inline bool FVTerm::reallocateTextArea (term_area* area, std::size_t size) { - assert ( size > 0 ); - if ( area->text != 0 ) delete[] area->text; try { - area->text = new charData[uInt(size)]; + area->text = new charData[size]; } catch (const std::bad_alloc& ex) { diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index 584b80d7..60ca9392 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -73,7 +73,6 @@ #ifdef F_HAVE_LIBGPM #include - #undef buttons // from term.h #endif namespace finalcut diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 2d9d8eb2..1c7475a2 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -103,26 +103,6 @@ #include #include -#if defined(__sun) && defined(__SVR4) - #include - typedef struct termio SGTTY; - typedef struct termios SGTTYS; - - #ifdef _LP64 - typedef unsigned int chtype; - #else - typedef unsigned long chtype; - #endif // _LP64 - - #include // termcap -#else - #include // termcap -#endif // defined(__sun) && defined(__SVR4) - -#ifdef F_HAVE_LIBGPM - #undef buttons // from term.h -#endif - #if F_HAVE_GETTTYNAM && F_HAVE_TTYENT_H #include #endif @@ -151,13 +131,9 @@ #if defined(__linux__) #include "final/ftermlinux.h" -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) #include "final/ftermfreebsd.h" -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) #include "final/ftermopenbsd.h" #endif @@ -336,9 +312,7 @@ class FTerm #if defined(__FreeBSD__) || defined(__DragonFly__) meta_sends_escape = true; change_cursorstyle = true; - #endif - - #if defined(__NetBSD__) || defined(__OpenBSD__) + #elif defined(__NetBSD__) || defined(__OpenBSD__) meta_sends_escape = true; #endif } @@ -356,9 +330,7 @@ class FTerm uInt8 meta_sends_escape : 1; uInt8 change_cursorstyle : 1; uInt8 : 6; // padding bits - #endif - - #if defined(__NetBSD__) || defined(__OpenBSD__) + #elif defined(__NetBSD__) || defined(__OpenBSD__) uInt8 meta_sends_escape : 1; uInt8 : 7; // padding bits #endif @@ -382,15 +354,9 @@ class FTerm static void init_fixed_max_color(); static void init_keyboard(); static void init_termcap(); - static void init_termcap_error (int); - static void init_termcap_variables(char*&); - static void init_termcap_booleans(); - static void init_termcap_numerics(); - static void init_termcap_strings (char*&); - static void init_termcap_keys_vt100 (char*&); - static void init_termcap_keys (char*&); - static void init_OptiMove(); - static void init_OptiAttr(); + static void init_quirks(); + static void init_optiMove(); + static void init_optiAttr(); static void init_font(); static void init_locale(); static void init_encoding(); @@ -435,13 +401,9 @@ class FTerm #if defined(__linux__) #undef linux static FTermLinux* linux; -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) static FTermFreeBSD* freebsd; -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) static FTermOpenBSD* openbsd; #endif }; diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index 44140854..791a9431 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -35,10 +35,36 @@ #error "Only can be included directly." #endif -// FTermcap string macro -#define TCAP(s) tcap[(s)].string +#if defined(__sun) && defined(__SVR4) + #include + typedef struct termio SGTTY; + typedef struct termios SGTTYS; + + #ifdef _LP64 + typedef unsigned int chtype; + #else + typedef unsigned long chtype; + #endif // _LP64 + + #include // termcap +#else + #include // termcap +#endif // defined(__sun) && defined(__SVR4) + +#ifdef F_HAVE_LIBGPM + #undef buttons // from term.h +#endif #include +#include + +#include "final/emptyfstring.h" +#include "final/fkey_map.h" +#include "final/ftermdetection.h" + + +// FTermcap string macro +#define TCAP(s) tcap[(s)].string namespace finalcut { @@ -74,6 +100,13 @@ class FTermcap return tcap; } + // Mutator + static void setTermData (FTermData*); + static void setFTermDetection (FTermDetection*); + + // Methods + static void init(); + // Data Members static bool background_color_erase; static bool automatic_left_margin; @@ -87,8 +120,20 @@ class FTermcap static int attr_without_color; private: + // Methods + static void termcap(); + static void termcapError (int); + static void termcapVariables (char*&); + static void termcapBoleans(); + static void termcapNumerics(); + static void termcapStrings (char*&); + static void termcapKeys (char*&); + static void termcapKeysVt100 (char*&); + // Data Member - static tcap_map tcap[]; + static tcap_map tcap[]; + static FTermData* fterm_data; + static FTermDetection* term_detection; }; #pragma pack(pop) diff --git a/src/include/final/ftermcapquirks.h b/src/include/final/ftermcapquirks.h index 01cc64b4..a8b6712d 100644 --- a/src/include/final/ftermcapquirks.h +++ b/src/include/final/ftermcapquirks.h @@ -73,18 +73,18 @@ class FTermcapQuirks private: // Methods #if defined(__FreeBSD__) || defined(__DragonFly__) - static void init_termcap_freebsd_quirks(); + static void freebsd(); #endif - static void init_termcap_cygwin_quirks(); - static void init_termcap_linux_quirks(); - static void init_termcap_xterm_quirks(); - static void init_termcap_rxvt_quirks(); - static void init_termcap_vte_quirks(); - static void init_termcap_putty_quirks(); - static void init_termcap_teraterm_quirks(); - static void init_termcap_sun_quirks(); - static void init_termcap_screen_quirks(); - static void init_termcap_general_quirks(); + static void cygwin(); + static void linux(); + static void xterm(); + static void rxvt(); + static void vte(); + static void putty(); + static void teraterm(); + static void sun(); + static void screen(); + static void general(); // Data Members static FTermcap::tcap_map* tcap; diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index d778d2b3..389530f3 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -56,6 +56,7 @@ #include "final/fterm.h" + // Preprocessing handler macro #define F_PREPROC_HANDLER(i,h) \ static_cast((i)) \ @@ -283,8 +284,8 @@ class FVTerm : public FTerm static void restoreVTerm (const FRect&); static void restoreVTerm (int, int, int, int); static void setTextToDefault (term_area*, int, int); - static bool reallocateTextArea (term_area*, int, int); - static bool reallocateTextArea (term_area*, int); + static bool reallocateTextArea (term_area*, std::size_t, std::size_t); + static bool reallocateTextArea (term_area*, std::size_t); static covered_state isCovered ( const FPoint& , term_area* ); @@ -417,7 +418,6 @@ class FVTerm : public FTerm #endif static int appendOutputBuffer (int); - // Data Members static std::queue* output_buffer; static charData term_attribute; diff --git a/test/ftermdata-test.cpp b/test/ftermdata-test.cpp index 1e95936f..e68fe0f4 100644 --- a/test/ftermdata-test.cpp +++ b/test/ftermdata-test.cpp @@ -177,11 +177,11 @@ void FTermDataTest::dataTest() CPPUNIT_ASSERT ( data.getXtermFont() == finalcut::FString() ); data.setXtermFont("terminus-20"); CPPUNIT_ASSERT ( data.getXtermFont() == finalcut::FString("terminus-20") ); - + CPPUNIT_ASSERT ( data.getXtermTitle() == finalcut::FString() ); data.setXtermTitle("Terminal"); CPPUNIT_ASSERT ( data.getXtermTitle() == finalcut::FString("Terminal") ); - + #if DEBUG CPPUNIT_ASSERT ( data.getFramebufferBpp() == -1 ); data.setFramebufferBpp(32); From ef21076bbda50236d41685f2468b069bae420435 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 9 Oct 2018 00:33:26 +0200 Subject: [PATCH 02/17] Some small code splits --- ChangeLog | 1 + src/fterm.cpp | 164 +++++++++++++++++++---------- src/ftermcap.cpp | 32 +++--- src/ftermcapquirks.cpp | 4 +- src/include/final/fterm.h | 8 ++ src/include/final/ftermcap.h | 1 + src/include/final/ftermcapquirks.h | 2 +- 7 files changed, 142 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6921e88..76dbe706 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2018-10-08 Markus Gans * Move all termcap code into FTermcap + * Some small code splits 2018-10-05 Markus Gans * Remove redundant program code from FString diff --git a/src/fterm.cpp b/src/fterm.cpp index b1e244d6..23bc5821 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -166,15 +166,9 @@ bool FTerm::setVGAFont() if ( data->isVGAFont() ) return data->isVGAFont(); - if ( isGnomeTerminal() - || isKdeTerminal() - || isPuttyTerminal() - || isTeraTerm() - || isCygwinTerminal() - || isMinttyTerm() ) + if ( hasNoFontSettingOption() ) return false; - if ( isXTerminal() || isScreenTerm() || isUrxvtTerminal() || FTermcap::osc_support ) { @@ -215,12 +209,7 @@ bool FTerm::setNewFont() if ( isNewFont() ) return true; - if ( isGnomeTerminal() - || isKdeTerminal() - || isPuttyTerminal() - || isTeraTerm() - || isCygwinTerminal() - || isMinttyTerm() ) + if ( hasNoFontSettingOption() ) return false; if ( isXTerminal() || isScreenTerm() @@ -1418,10 +1407,22 @@ void FTerm::init_captureFontAndTitle() } //---------------------------------------------------------------------- -void FTerm::redefineColorPalette() +inline bool FTerm::hasNoFontSettingOption() { - // Redefine the color palette + if ( isGnomeTerminal() + || isKdeTerminal() + || isPuttyTerminal() + || isTeraTerm() + || isCygwinTerminal() + || isMinttyTerm() ) + return true; + return false; +} + +//---------------------------------------------------------------------- +inline bool FTerm::canChangeColorPalette() +{ if ( isCygwinTerminal() || isKdeTerminal() || isTeraTerm() @@ -1430,6 +1431,17 @@ void FTerm::redefineColorPalette() || isOpenBSDTerm() || isSunTerminal() || isAnsiTerminal() ) + return false; + + return FTermcap::can_change_color_palette; +} + +//---------------------------------------------------------------------- +void FTerm::redefineColorPalette() +{ + // Redefine the color palette + + if ( ! canChangeColorPalette() ) return; resetColorMap(); @@ -1444,14 +1456,7 @@ void FTerm::redefineColorPalette() //---------------------------------------------------------------------- void FTerm::restoreColorPalette() { - if ( isCygwinTerminal() - || isKdeTerminal() - || isTeraTerm() - || isMltermTerminal() - || isNetBSDTerm() - || isOpenBSDTerm() - || isSunTerminal() - || isAnsiTerminal() ) + if ( ! canChangeColorPalette() ) return; // Reset screen settings @@ -1509,6 +1514,11 @@ void FTerm::setOverwriteCursorStyle() //---------------------------------------------------------------------- void FTerm::enableMouse() { + // Enable the terminal mouse support + + if ( ! init_values.mouse_support ) + return; + bool gpm_mouse = false; bool xterm_mouse = false; @@ -1536,12 +1546,68 @@ void FTerm::enableMouse() } //---------------------------------------------------------------------- -void FTerm::disableMouse() +inline void FTerm::disableMouse() { + // Disable the terminal mouse support + keyboard->disableMouseSequences(); mouse->disable(); } +//---------------------------------------------------------------------- +inline void FTerm::enableKeypad() +{ + // Enter 'keyboard_transmit' mode + + if ( TCAP(fc::t_keypad_xmit) ) + { + putstring (TCAP(fc::t_keypad_xmit)); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +inline void FTerm::disableKeypad() +{ + // Leave 'keyboard_transmit' mode + + if ( TCAP(fc::t_keypad_local) ) + { + putstring (TCAP(fc::t_keypad_local)); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +inline void FTerm::enableAlternateCharset() +{ + // Enable alternate charset + + if ( TCAP(fc::t_enable_acs) ) + { + putstring (TCAP(fc::t_enable_acs)); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +inline void FTerm::enableApplicationEscKey() +{ + // switch to application escape key mode + + if ( isMinttyTerm() ) + FTerm::putstring (CSI "?7727h"); +} + +//---------------------------------------------------------------------- +inline void FTerm::disableApplicationEscKey() +{ + // Switch to normal escape key mode + + if ( isMinttyTerm() ) + putstring (CSI "?7727l"); +} + //---------------------------------------------------------------------- void FTerm::useAlternateScreenBuffer() { @@ -1652,7 +1718,6 @@ inline void FTerm::deallocationValues() //---------------------------------------------------------------------- void FTerm::init (bool disable_alt_screen) { - int stdout_no = FTermios::getStdOut(); init_term_object = this; // Initialize global values for all objects @@ -1672,11 +1737,7 @@ void FTerm::init (bool disable_alt_screen) FTermios::storeTTYsettings(); // Get output baud rate - uInt baud = FTermios::getBaudRate(); - data->setBaudrate(baud); - - if ( isatty(stdout_no) ) - opti_move->setBaudRate(int(baud)); + initBaudRate(); // Terminal detection term_detection->setTermData(data); @@ -1714,32 +1775,22 @@ void FTerm::init (bool disable_alt_screen) init_keyboard(); // Enable the terminal mouse support - if ( init_values.mouse_support ) - enableMouse(); + enableMouse(); // Activate meta key sends escape if ( isXTerminal() ) xterm->metaSendsESC(true); // switch to application escape key mode - if ( isMinttyTerm() ) - FTerm::putstring (CSI "?7727h"); + enableApplicationEscKey(); // Enter 'keyboard_transmit' mode - if ( TCAP(fc::t_keypad_xmit) ) - { - putstring (TCAP(fc::t_keypad_xmit)); - std::fflush(stdout); - } + enableKeypad(); useAlternateScreenBuffer(); // Enable alternate charset - if ( TCAP(fc::t_enable_acs) ) - { - putstring (TCAP(fc::t_enable_acs)); - std::fflush(stdout); - } + enableAlternateCharset(); // Save the used xterm font and window title init_captureFontAndTitle(); @@ -1822,6 +1873,17 @@ void FTerm::initTermspecifics() init_teraterm_charmap(); } +//---------------------------------------------------------------------- +void FTerm::initBaudRate() +{ + int stdout_no = FTermios::getStdOut(); + uInt baud = FTermios::getBaudRate(); + data->setBaudrate(baud); + + if ( isatty(stdout_no) ) + opti_move->setBaudRate(int(baud)); +} + //---------------------------------------------------------------------- void FTerm::finish() { @@ -1860,12 +1922,8 @@ void FTerm::finish() if ( init_values.color_change ) restoreColorPalette(); - if ( isMinttyTerm() ) - { - // Switch to normal escape key mode - putstring (CSI "?7727l"); - std::fflush(stdout); - } + // Switch to normal escape key mode + disableApplicationEscKey(); finishOSspecifics1(); @@ -1885,11 +1943,7 @@ void FTerm::finish() useNormalScreenBuffer(); // leave 'keyboard_transmit' mode - if ( TCAP(fc::t_keypad_local) ) - { - putstring (TCAP(fc::t_keypad_local)); - std::fflush(stdout); - } + disableKeypad(); finish_encoding(); diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index 071bcca6..e35b62b9 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -26,18 +26,19 @@ namespace finalcut { // static class attributes -bool FTermcap::background_color_erase = false; -bool FTermcap::automatic_left_margin = false; -bool FTermcap::automatic_right_margin = false; -bool FTermcap::eat_nl_glitch = false; -bool FTermcap::ansi_default_color = false; -bool FTermcap::osc_support = false; -bool FTermcap::no_utf8_acs_chars = false; -int FTermcap::max_color = 1; -int FTermcap::tabstop = 8; -int FTermcap::attr_without_color = 0; -FTermData* FTermcap::fterm_data = 0; -FTermDetection* FTermcap::term_detection = 0; +bool FTermcap::background_color_erase = false; +bool FTermcap::can_change_color_palette = false; +bool FTermcap::automatic_left_margin = false; +bool FTermcap::automatic_right_margin = false; +bool FTermcap::eat_nl_glitch = false; +bool FTermcap::ansi_default_color = false; +bool FTermcap::osc_support = false; +bool FTermcap::no_utf8_acs_chars = false; +int FTermcap::max_color = 1; +int FTermcap::tabstop = 8; +int FTermcap::attr_without_color = 0; +FTermData* FTermcap::fterm_data = 0; +FTermDetection* FTermcap::term_detection = 0; //---------------------------------------------------------------------- @@ -96,7 +97,11 @@ void FTermcap::termcap() bool color256 = term_detection->canDisplay256Colors(); // Open termcap file +#if defined(__sun) && defined(__SVR4) + char* termtype = fterm_data->getTermType(); +#else const char* termtype = fterm_data->getTermType(); +#endif terminals.push_back(termtype); // available terminal type if ( color256 ) // 1st fallback if not found @@ -174,6 +179,9 @@ void FTermcap::termcapBoleans() // Screen erased with the background color background_color_erase = tgetflag(C_STR("ut")); + // Terminal is able to redefine existing colors + can_change_color_palette = tgetflag(C_STR("cc")); + // t_cursor_left wraps from column 0 to last column automatic_left_margin = tgetflag(C_STR("bw")); diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index 4e77b038..7cba5aa1 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -89,7 +89,7 @@ void FTermcapQuirks::terminalFixup() } else if ( td->isSunTerminal() ) { - sun(); + sunConsole(); } else if ( td->isPuttyTerminal() ) { @@ -385,7 +385,7 @@ void FTermcapQuirks::teraterm() } //---------------------------------------------------------------------- -void FTermcapQuirks::sun() +void FTermcapQuirks::sunConsole() { // Sun Microsystems workstation console eat_nl_glitch fix FTermcap::eat_nl_glitch = true; diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 1c7475a2..2f463262 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -367,12 +367,19 @@ class FTerm static void init_utf8_without_alt_charset(); static void init_tab_quirks(); static void init_captureFontAndTitle(); + static bool hasNoFontSettingOption(); + static bool canChangeColorPalette(); static void redefineColorPalette(); static void restoreColorPalette(); static void setInsertCursorStyle(); static void setOverwriteCursorStyle(); static void enableMouse(); static void disableMouse(); + static void enableApplicationEscKey(); + static void disableApplicationEscKey(); + static void enableKeypad(); + static void disableKeypad(); + static void enableAlternateCharset(); static void useAlternateScreenBuffer(); static void useNormalScreenBuffer(); void allocationValues(); @@ -380,6 +387,7 @@ class FTerm void init (bool); void initOSspecifics(); void initTermspecifics(); + void initBaudRate(); void finish(); void finishOSspecifics1(); void finish_encoding(); diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index 791a9431..04f20a3a 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -109,6 +109,7 @@ class FTermcap // Data Members static bool background_color_erase; + static bool can_change_color_palette; static bool automatic_left_margin; static bool automatic_right_margin; static bool eat_nl_glitch; diff --git a/src/include/final/ftermcapquirks.h b/src/include/final/ftermcapquirks.h index a8b6712d..9d9b5e53 100644 --- a/src/include/final/ftermcapquirks.h +++ b/src/include/final/ftermcapquirks.h @@ -82,7 +82,7 @@ class FTermcapQuirks static void vte(); static void putty(); static void teraterm(); - static void sun(); + static void sunConsole(); static void screen(); static void general(); From b854224eb5166b4450fb5863d719761ea5b061c9 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 9 Oct 2018 16:04:21 +0200 Subject: [PATCH 03/17] Terminal detection for newer vte libraries (>= 0.53.0) --- ChangeLog | 3 ++ src/ftermdetection.cpp | 58 +++++++++++++++++------- src/include/final/ftermdetection.h | 2 + test/ftermdetection-test.cpp | 72 ++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76dbe706..063f34c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-10-09 Markus Gans + * Terminal detection for newer vte libraries (>= 0.53.0) + 2018-10-08 Markus Gans * Move all termcap code into FTermcap * Some small code splits diff --git a/src/ftermdetection.cpp b/src/ftermdetection.cpp index ba728668..139efe94 100644 --- a/src/ftermdetection.cpp +++ b/src/ftermdetection.cpp @@ -750,7 +750,12 @@ char* FTermDetection::secDA_Analysis (char current_termtype[]) case 41: // DEC VT420 case 61: // DEC VT510 case 64: // DEC VT520 + break; + case 65: // DEC VT525 + new_termtype = secDA_Analysis_65(current_termtype); + break; + case 67: // Cygwin new_termtype = secDA_Analysis_67(current_termtype); break; @@ -780,7 +785,9 @@ char* FTermDetection::secDA_Analysis (char current_termtype[]) } // Correct false assumptions - if ( isGnomeTerminal() && secondary_da.terminal_id_type != 1 ) + if ( isGnomeTerminal() + && secondary_da.terminal_id_type != 1 + && secondary_da.terminal_id_type != 65 ) terminal_type.gnome_terminal = false; if ( isKdeTerminal() && secondary_da.terminal_id_type != 0 ) @@ -815,20 +822,7 @@ inline char* FTermDetection::secDA_Analysis_1 (char current_termtype[]) // Terminal ID 1 - DEC VT220 char* new_termtype = current_termtype; - - if ( secondary_da.terminal_id_version > 1000 ) - { - terminal_type.gnome_terminal = true; - // Each gnome-terminal should be able to use 256 colors - color256 = true; - new_termtype = C_STR("gnome-256color"); - gnome_terminal_id = secondary_da.terminal_id_version; - - // VTE 0.40.0 or higher and gnome-terminal 3.16 or higher - if ( gnome_terminal_id >= 4000 ) - decscusr_support = true; - } - + new_termtype = secDA_Analysis_vte(new_termtype); return new_termtype; } @@ -870,6 +864,16 @@ inline char* FTermDetection::secDA_Analysis_32 (char[]) return new_termtype; } +//---------------------------------------------------------------------- +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; +} + //---------------------------------------------------------------------- inline char* FTermDetection::secDA_Analysis_67 (char[]) { @@ -955,4 +959,28 @@ inline char* FTermDetection::secDA_Analysis_85 (char current_termtype[]) return new_termtype; } +//---------------------------------------------------------------------- +inline char* FTermDetection::secDA_Analysis_vte (char current_termtype[]) +{ + // VTE terminal library + // (Since VTE ) the terminal ID has changed from 1 to 65) + + char* new_termtype = current_termtype; + + if ( secondary_da.terminal_id_version > 1000 ) + { + terminal_type.gnome_terminal = true; + // Each gnome-terminal should be able to use 256 colors + color256 = true; + new_termtype = C_STR("gnome-256color"); + gnome_terminal_id = secondary_da.terminal_id_version; + + // VTE 0.40.0 or higher and gnome-terminal 3.16 or higher + if ( gnome_terminal_id >= 4000 ) + decscusr_support = true; + } + + return new_termtype; +} + } // namespace finalcut diff --git a/src/include/final/ftermdetection.h b/src/include/final/ftermdetection.h index 6c2e57db..474ee08c 100644 --- a/src/include/final/ftermdetection.h +++ b/src/include/final/ftermdetection.h @@ -190,12 +190,14 @@ class FTermDetection static char* secDA_Analysis_1 (char[]); static char* secDA_Analysis_24 (char[]); static char* secDA_Analysis_32 (char[]); + static char* secDA_Analysis_65 (char[]); static char* secDA_Analysis_67 (char[]); static char* secDA_Analysis_77 (char[]); static char* secDA_Analysis_82 (char[]); static char* secDA_Analysis_83 (char[]); static char* secDA_Analysis_84 (char[]); static char* secDA_Analysis_85 (char[]); + static char* secDA_Analysis_vte (char[]); // Data Members static char termtype[256]; diff --git a/test/ftermdetection-test.cpp b/test/ftermdetection-test.cpp index 037290cb..9d5187b7 100644 --- a/test/ftermdetection-test.cpp +++ b/test/ftermdetection-test.cpp @@ -332,6 +332,7 @@ class FTermDetectionTest : public CPPUNIT_NS::TestFixture putty, kde_konsole, gnome_terminal, + newer_vte_terminal, kterm, tera_term, cygwin, @@ -358,6 +359,7 @@ class FTermDetectionTest : public CPPUNIT_NS::TestFixture void puttyTest(); void kdeKonsoleTest(); void gnomeTerminalTest(); + void newerVteTerminalTest(); void ktermTest(); void teraTermTest(); void cygwinTest(); @@ -402,6 +404,7 @@ class FTermDetectionTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST (puttyTest); CPPUNIT_TEST (kdeKonsoleTest); CPPUNIT_TEST (gnomeTerminalTest); + CPPUNIT_TEST (newerVteTerminalTest); CPPUNIT_TEST (ktermTest); CPPUNIT_TEST (teraTermTest); CPPUNIT_TEST (cygwinTest); @@ -987,6 +990,69 @@ void FTermDetectionTest::gnomeTerminalTest() } } +//---------------------------------------------------------------------- +void FTermDetectionTest::newerVteTerminalTest() +{ + finalcut::FTermData data; + finalcut::FTermDetection detect; + data.setTermFileName(C_STR("xterm-256color")); + detect.setTermData(&data); + detect.setTerminalDetection(true); + + pid_t pid = forkProcess(); + + if ( isChildProcess(pid) ) + { + setenv ("TERM", "xterm-256color", 1); + setenv ("COLORTERM", "truecolor", 1); + setenv ("VTE_VERSION", "5300", 1); + unsetenv("COLORFGBG"); + unsetenv("TERMCAP"); + unsetenv("XTERM_VERSION"); + unsetenv("ROXTERM_ID"); + unsetenv("KONSOLE_DBUS_SESSION"); + unsetenv("KONSOLE_DCOP"); + unsetenv("TMUX"); + + detect.detect(); + + CPPUNIT_ASSERT ( detect.isXTerminal() ); + CPPUNIT_ASSERT ( ! detect.isAnsiTerminal() ); + CPPUNIT_ASSERT ( ! detect.isRxvtTerminal() ); + CPPUNIT_ASSERT ( ! detect.isUrxvtTerminal() ); + CPPUNIT_ASSERT ( ! detect.isMltermTerminal() ); + CPPUNIT_ASSERT ( ! detect.isPuttyTerminal() ); + CPPUNIT_ASSERT ( ! detect.isKdeTerminal() ); + CPPUNIT_ASSERT ( detect.isGnomeTerminal() ); + CPPUNIT_ASSERT ( ! detect.isKtermTerminal() ); + CPPUNIT_ASSERT ( ! detect.isTeraTerm() ); + CPPUNIT_ASSERT ( ! detect.isCygwinTerminal() ); + CPPUNIT_ASSERT ( ! detect.isMinttyTerm() ); + CPPUNIT_ASSERT ( ! detect.isLinuxTerm() ); + CPPUNIT_ASSERT ( ! detect.isFreeBSDTerm() ); + CPPUNIT_ASSERT ( ! detect.isNetBSDTerm() ); + CPPUNIT_ASSERT ( ! detect.isOpenBSDTerm() ); + CPPUNIT_ASSERT ( ! detect.isSunTerminal() ); + CPPUNIT_ASSERT ( ! detect.isScreenTerm() ); + CPPUNIT_ASSERT ( ! detect.isTmuxTerm() ); + CPPUNIT_ASSERT ( detect.canDisplay256Colors() ); + CPPUNIT_ASSERT ( detect.hasTerminalDetection() ); + CPPUNIT_ASSERT ( detect.hasSetCursorStyleSupport() ); + + debugOutput(); + closeStandardStreams(); + exit(EXIT_SUCCESS); + } + else // Parent + { + // Start the terminal simulation + terminalSimulation (newer_vte_terminal); + + if ( waitpid(pid, 0, WUNTRACED) != pid ) + std::cerr << "waitpid error" << std::endl; + } +} + //---------------------------------------------------------------------- void FTermDetectionTest::ktermTest() { @@ -1846,6 +1912,7 @@ char* FTermDetectionTest::getAnswerback (console con) C_STR("PuTTY"), // PuTTY 0, // KDE Konsole 0, // GNOME Terminal + 0, // VTE Terminal >= 0.53.0 0, // kterm, 0, // Tera Term 0, // Cygwin @@ -1875,6 +1942,7 @@ char* FTermDetectionTest::getDSR (console con) C_STR("\033[0n"), // PuTTY C_STR("\033[0n"), // KDE Konsole C_STR("\033[0n"), // GNOME Terminal + C_STR("\033[0n"), // VTE Terminal >= 0.53.0 C_STR("\033[0n"), // kterm, C_STR("\033[0n"), // Tera Term 0, // Cygwin @@ -1904,6 +1972,7 @@ char* FTermDetectionTest::getDECID (console con) C_STR("\033[?6c"), // PuTTY C_STR("\033[?1;2c"), // KDE Konsole C_STR("\033[?62;c"), // GNOME Terminal + C_STR("\033[?65;1;9c"), // VTE Terminal >= 0.53.0 C_STR("\033[?1;2c"), // kterm, C_STR("\033[?1;2c"), // Tera Term 0, // Cygwin @@ -1933,6 +2002,7 @@ char* FTermDetectionTest::getDA (console con) C_STR("\033[?6c"), // PuTTY C_STR("\033[?1;2c"), // KDE Konsole C_STR("\033[?62;c"), // GNOME Terminal + C_STR("\033[?65;1;9c"), // VTE Terminal >= 0.53.0 C_STR("\033[?1;2c"), // kterm, C_STR("\033[?1;2c"), // Tera Term C_STR("\033[?6c"), // Cygwin @@ -1962,6 +2032,7 @@ char* FTermDetectionTest::getDA1 (console con) C_STR("\033[?6c"), // PuTTY C_STR("\033[?1;2c"), // KDE Konsole C_STR("\033[?62;c"), // GNOME Terminal + C_STR("\033[?65;1;9c"), // VTE Terminal >= 0.53.0 0, // kterm, C_STR("\033[?1;2c"), // Tera Term C_STR("\033[?6c"), // Cygwin @@ -1991,6 +2062,7 @@ char* FTermDetectionTest::getSEC_DA (console con) C_STR("\033[>0;136;0c"), // PuTTY C_STR("\033[>0;115;0c"), // KDE Konsole C_STR("\033[>1;5202;0c"), // GNOME Terminal + C_STR("\033[>65;5300;1c"), // VTE Terminal >= 0.53.0 C_STR("\033[?1;2c"), // kterm, C_STR("\033[>32;278;0c"), // Tera Term C_STR("\033[>67;200502;0c"), // Cygwin From a274dd8b5e23694ed8ad652183d223a098bf6ede Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 9 Oct 2018 20:21:43 +0200 Subject: [PATCH 04/17] Prevent unnecessary screen flushing in command line help --- src/fapplication.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 9b77d01e..af6b5d30 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -317,43 +317,43 @@ FWidget* FApplication::processParameters (const int& argc, char* argv[]) void FApplication::showParameterUsage() { std::cout \ - << "Generic options:" << std::endl + << "Generic options:\n" << " -h, --help " - << " Display this help and exit" << std::endl - << std::endl - << "The Final Cut options:" << std::endl + << " Display this help and exit\n" + << "\n" + << "The Final Cut options:\n" << " --encoding " - << " Sets the character encoding mode" << std::endl + << " Sets the character encoding mode\n" << " " - << " {utf8, vt100, pc, ascii}" << std::endl + << " {utf8, vt100, pc, ascii}\n" << " --no-mouse " - << " Disable mouse support" << std::endl + << " Disable mouse support\n" << " --no-optimized-cursor " - << " Disable cursor optimization" << std::endl + << " Disable cursor optimization\n" << " --no-terminal-detection" - << " Disable terminal detection" << std::endl + << " Disable terminal detection\n" << " --no-color-change " - << " Do not redefine the color palette" << std::endl + << " Do not redefine the color palette\n" << " --vgafont " - << " Set the standard vga 8x16 font" << std::endl + << " Set the standard vga 8x16 font\n" << " --newfont " - << " Enables the graphical font" << std::endl + << " Enables the graphical font\n" #if defined(__FreeBSD__) || defined(__DragonFly__) - << std::endl - << "FreeBSD console options:" << std::endl + << "\n" + << "FreeBSD console options:\n" << " --no-esc-for-alt-meta " - << " Do not send a ESC prefix for the alt/meta key" << std::endl + << " Do not send a ESC prefix for the alt/meta key\n" << " --no-cursorstyle-change" - << " Do not change the current cursor style" << std::endl + << " Do not change the current cursor style\n" #elif defined(__NetBSD__) || defined(__OpenBSD__) - << std::endl - << "NetBSD/OpenBSD console options:" << std::endl + << "\n" + << "NetBSD/OpenBSD console options:\n" << " --no-esc-for-alt-meta " - << " Do not send a ESC prefix for the alt/meta key" << std::endl + << " Do not send a ESC prefix for the alt/meta key\n" #endif - << std::endl; + << std::endl; // newline character + flushes the output stream std::exit(EXIT_SUCCESS); } From fea78841b9117e8a123cf7ddec1f36ec3dd0275c Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 11 Oct 2018 03:46:37 +0200 Subject: [PATCH 05/17] FKeyboard now uses references for keyboard buffer passing --- ChangeLog | 3 + src/fapplication.cpp | 17 +- src/fkeyboard.cpp | 38 ++-- src/fmouse.cpp | 28 +-- src/include/final/fkeyboard.h | 22 ++- src/include/final/fmouse.h | 15 +- test/fkeyboard-test.cpp | 8 +- test/fmouse-test.cpp | 343 +++++++++++++++++++--------------- 8 files changed, 259 insertions(+), 215 deletions(-) diff --git a/ChangeLog b/ChangeLog index 063f34c4..15a9d1b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-10-11 Markus Gans + * FKeyboard now uses references for keyboard buffer passing + 2018-10-09 Markus Gans * Terminal detection for newer vte libraries (>= 0.53.0) diff --git a/src/fapplication.cpp b/src/fapplication.cpp index af6b5d30..0fa19fd5 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -353,7 +353,7 @@ void FApplication::showParameterUsage() << " Do not send a ESC prefix for the alt/meta key\n" #endif - << std::endl; // newline character + flushes the output stream + << std::endl; // newline character + flushes the output stream std::exit(EXIT_SUCCESS); } @@ -565,9 +565,8 @@ inline void FApplication::performKeyboardAction() case fc::Fkey_mouse: if ( mouse ) { - char* buffer = keyboard->getKeyBuffer(); - int buffer_size = keyboard->getKeyBufferSize(); - mouse->setRawData (FMouse::x11, buffer, buffer_size); + FKeyboard::keybuffer& buffer = keyboard->getKeyBuffer(); + mouse->setRawData (FMouse::x11, buffer); keyboard->unprocessedInput() = mouse->isInputDataPending(); processMouseEvent(); } @@ -576,9 +575,8 @@ inline void FApplication::performKeyboardAction() case fc::Fkey_extended_mouse: if ( mouse ) { - char* buffer = keyboard->getKeyBuffer(); - int buffer_size = keyboard->getKeyBufferSize(); - mouse->setRawData (FMouse::sgr, buffer, buffer_size); + FKeyboard::keybuffer& buffer = keyboard->getKeyBuffer(); + mouse->setRawData (FMouse::sgr, buffer); keyboard->unprocessedInput() = mouse->isInputDataPending(); processMouseEvent(); } @@ -587,9 +585,8 @@ inline void FApplication::performKeyboardAction() case fc::Fkey_urxvt_mouse: if ( mouse ) { - char* buffer = keyboard->getKeyBuffer(); - int buffer_size = keyboard->getKeyBufferSize(); - mouse->setRawData (FMouse::urxvt, buffer, buffer_size); + FKeyboard::keybuffer& buffer = keyboard->getKeyBuffer(); + mouse->setRawData (FMouse::urxvt, buffer); keyboard->unprocessedInput() = mouse->isInputDataPending(); processMouseEvent(); } diff --git a/src/fkeyboard.cpp b/src/fkeyboard.cpp index 918ef8e5..6d4398bb 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -70,7 +70,6 @@ FKeyboard::FKeyboard() : key(0) , fifo_offset(0) , fifo_in_use(false) - , fifo_buf_size(sizeof(fifo_buf)) , stdin_status_flags(0) , input_data_pending(false) , utf8_input(false) @@ -92,8 +91,8 @@ FKeyboard::FKeyboard() std::abort(); // Initialize arrays with '\0' - std::fill_n (k_buf, sizeof(k_buf), '\0'); - std::fill_n (fifo_buf, fifo_buf_size, '\0'); + std::fill_n (read_buf, READ_BUF_SIZE, '\0'); + std::fill_n (fifo_buf, FIFO_BUF_SIZE, '\0'); } //---------------------------------------------------------------------- @@ -159,7 +158,7 @@ void FKeyboard::clearKeyBuffer() fifo_offset = 0; key = 0; - std::fill_n (fifo_buf, fifo_buf_size, '\0'); + std::fill_n (fifo_buf, FIFO_BUF_SIZE, '\0'); fifo_in_use = false; } @@ -230,7 +229,7 @@ inline int FKeyboard::getTermcapKey() { // Looking for termcap key strings in the buffer - assert ( fifo_buf_size > 0 ); + assert ( FIFO_BUF_SIZE > 0 ); if ( ! key_map ) return -1; @@ -243,12 +242,12 @@ inline int FKeyboard::getTermcapKey() if ( k && std::strncmp(k, fifo_buf, uInt(len)) == 0 ) // found { - int n; + std::size_t n; - for (n = len; n < fifo_buf_size; n++) // Remove founded entry + for (n = len; n < FIFO_BUF_SIZE; n++) // Remove founded entry fifo_buf[n - len] = fifo_buf[n]; - for (n = n - len; n < fifo_buf_size; n++) // Fill rest with '\0' + for (n = n - len; n < FIFO_BUF_SIZE; n++) // Fill rest with '\0' fifo_buf[n] = '\0'; input_data_pending = bool(fifo_buf[0] != '\0'); @@ -264,7 +263,7 @@ inline int FKeyboard::getMetaKey() { // Looking for meta key strings in the buffer - assert ( fifo_buf_size > 0 ); + assert ( FIFO_BUF_SIZE > 0 ); for (int i = 0; fc::Fmetakey[i].string[0] != 0; i++) { @@ -273,7 +272,7 @@ inline int FKeyboard::getMetaKey() if ( std::strncmp(kmeta, fifo_buf, uInt(len)) == 0 ) // found { - int n; + std::size_t n; if ( len == 2 && ( fifo_buf[1] == 'O' || fifo_buf[1] == '[' @@ -283,10 +282,10 @@ inline int FKeyboard::getMetaKey() return NEED_MORE_DATA; } - for (n = len; n < fifo_buf_size; n++) // Remove founded entry + for (n = len; n < FIFO_BUF_SIZE; n++) // Remove founded entry fifo_buf[n - len] = fifo_buf[n]; - for (n = n - len; n < fifo_buf_size; n++) // Fill rest with '\0' + for (n = n - len; n < FIFO_BUF_SIZE; n++) // Fill rest with '\0' fifo_buf[n] = '\0'; input_data_pending = bool(fifo_buf[0] != '\0'); @@ -303,7 +302,8 @@ inline int FKeyboard::getSingleKey() // Looking for single key code in the buffer uChar firstchar = uChar(fifo_buf[0]); - int keycode, n, len; + std::size_t n; + int keycode, len; len = 1; // Look for a utf-8 character @@ -326,10 +326,10 @@ inline int FKeyboard::getSingleKey() else keycode = uChar(fifo_buf[0] & 0xff); - for (n = len; n < fifo_buf_size; n++) // Remove the key from the buffer front + for (n = len; n < FIFO_BUF_SIZE; n++) // Remove the key from the buffer front fifo_buf[n - len] = fifo_buf[n]; - for (n = n - len; n < fifo_buf_size; n++) // Fill the rest with '\0' bytes + for (n = n - len; n < FIFO_BUF_SIZE; n++) // Fill the rest with '\0' bytes fifo_buf[n] = '\0'; input_data_pending = bool(fifo_buf[0] != '\0'); @@ -424,7 +424,7 @@ inline ssize_t FKeyboard::readKey() { ssize_t bytes; setNonBlockingInput(); - bytes = read(FTermios::getStdIn(), &k_buf, sizeof(k_buf) - 1); + bytes = read(FTermios::getStdIn(), &read_buf, READ_BUF_SIZE - 1); unsetNonBlockingInput(); return bytes; } @@ -437,11 +437,11 @@ void FKeyboard::parseKeyBuffer() while ( (bytesread = readKey()) > 0 ) { - if ( bytesread + fifo_offset <= fifo_buf_size ) + if ( bytesread + fifo_offset <= int(FIFO_BUF_SIZE) ) { for (int i = 0; i < bytesread; i++) { - fifo_buf[fifo_offset] = k_buf[i]; + fifo_buf[fifo_offset] = read_buf[i]; fifo_offset++; } @@ -474,7 +474,7 @@ void FKeyboard::parseKeyBuffer() key = 0; } - std::fill_n (k_buf, sizeof(k_buf), '\0'); + std::fill_n (read_buf, READ_BUF_SIZE, '\0'); } //---------------------------------------------------------------------- diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 292d3edd..dd3faa13 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -270,7 +270,7 @@ bool FMouseGPM::hasData() } //---------------------------------------------------------------------- -void FMouseGPM::setRawData (char[], int) +void FMouseGPM::setRawData (FKeyboard::keybuffer&) { } //---------------------------------------------------------------------- @@ -490,12 +490,13 @@ bool FMouseX11::hasData() } //---------------------------------------------------------------------- -void FMouseX11::setRawData (char fifo_buf[], int fifo_buf_size) +void FMouseX11::setRawData (FKeyboard::keybuffer& fifo_buf) { // Import the X11 xterm mouse protocol (SGR-Mode) raw mouse data - static const int len = 6; - int n; + static const std::size_t len = 6; + std::size_t fifo_buf_size = sizeof(fifo_buf); + std::size_t n; x11_mouse[0] = fifo_buf[3]; x11_mouse[1] = fifo_buf[4]; x11_mouse[2] = fifo_buf[5]; @@ -691,12 +692,13 @@ bool FMouseSGR::hasData() } //---------------------------------------------------------------------- -void FMouseSGR::setRawData (char fifo_buf[], int fifo_buf_size) +void FMouseSGR::setRawData (FKeyboard::keybuffer& fifo_buf) { // Import the X11 xterm mouse protocol (SGR-Mode) raw mouse data - int len = int(std::strlen(fifo_buf)); - int n = 3; + std::size_t fifo_buf_size = sizeof(fifo_buf); + std::size_t len = std::strlen(fifo_buf); + std::size_t n = 3; while ( n < len && n < fifo_buf_size ) { @@ -944,12 +946,13 @@ bool FMouseUrxvt::hasData() } //---------------------------------------------------------------------- -void FMouseUrxvt::setRawData (char fifo_buf[], int fifo_buf_size) +void FMouseUrxvt::setRawData (FKeyboard::keybuffer& fifo_buf) { // Import the X11 xterm mouse protocol (Urxvt-Mode) raw mouse data - int len = int(std::strlen(fifo_buf)); - int n = 2; + std::size_t fifo_buf_size = sizeof(fifo_buf); + std::size_t len = std::strlen(fifo_buf); + std::size_t n = 2; while ( n < len && n < fifo_buf_size ) { @@ -1535,13 +1538,12 @@ void FMouseControl::disable() //---------------------------------------------------------------------- void FMouseControl::setRawData ( FMouse::mouse_type mt - , char fifo_buf[] - , int fifo_buf_size ) + , FKeyboard::keybuffer& fifo_buf) { FMouse* mouse = mouse_protocol[mt]; if ( mouse ) - mouse->setRawData (fifo_buf, fifo_buf_size); + mouse->setRawData (fifo_buf); } //---------------------------------------------------------------------- diff --git a/src/include/final/fkeyboard.h b/src/include/final/fkeyboard.h index 85fd5eb0..92c5f7ea 100644 --- a/src/include/final/fkeyboard.h +++ b/src/include/final/fkeyboard.h @@ -83,6 +83,12 @@ class FKeyboardCommand class FKeyboard { public: + // Constants + static const std::size_t FIFO_BUF_SIZE = 512; + + // Typedef + typedef char keybuffer[FIFO_BUF_SIZE]; + // Constructor FKeyboard(); @@ -93,8 +99,7 @@ class FKeyboard virtual const char* getClassName() const; int getKey(); const FString getKeyName (int); - char* getKeyBuffer(); - int getKeyBufferSize(); + keybuffer& getKeyBuffer(); timeval* getKeyPressedTime(); // Mutators @@ -127,6 +132,7 @@ class FKeyboard private: // Constants static const int NEED_MORE_DATA = -1; + static const std::size_t READ_BUF_SIZE = 1024; // Disable copy constructor FKeyboard (const FKeyboard&); @@ -161,11 +167,10 @@ class FKeyboard // Data Members int key; - char k_buf[1024]; - char fifo_buf[512]; + char read_buf[READ_BUF_SIZE]; + char fifo_buf[FIFO_BUF_SIZE]; int fifo_offset; bool fifo_in_use; - int fifo_buf_size; int stdin_status_flags; static long key_timeout; bool input_data_pending; @@ -195,12 +200,9 @@ inline const char* FKeyboard::getClassName() const inline int FKeyboard::getKey() { return key; } -inline char* FKeyboard::getKeyBuffer() -{ return fifo_buf; } - //---------------------------------------------------------------------- -inline int FKeyboard::getKeyBufferSize() -{ return fifo_buf_size; } +inline FKeyboard::keybuffer& FKeyboard::getKeyBuffer() +{ return fifo_buf; } //---------------------------------------------------------------------- inline timeval* FKeyboard::getKeyPressedTime() diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index 60ca9392..e24aa8a0 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -64,6 +64,7 @@ #include #include "final/fconfig.h" +#include "final/fkeyboard.h" #include "final/fpoint.h" #include "final/ftypes.h" @@ -135,7 +136,7 @@ class FMouse // Methods static FMouse* createMouseObject (mouse_type); - virtual void setRawData (char[], int) = 0; + virtual void setRawData (FKeyboard::keybuffer&) = 0; virtual void processEvent (struct timeval*) = 0; protected: @@ -211,7 +212,7 @@ class FMouseGPM : public FMouse bool isGpmMouseEnabled(); // Methods - virtual void setRawData (char[], int); + virtual void setRawData (FKeyboard::keybuffer&); virtual void processEvent (struct timeval*); bool gpmMouse (bool); bool enableGpmMouse(); @@ -276,7 +277,7 @@ class FMouseX11 : public FMouse virtual bool hasData(); // Methods - virtual void setRawData (char[], int); + virtual void setRawData (FKeyboard::keybuffer&); virtual void processEvent (struct timeval*); private: @@ -339,7 +340,7 @@ class FMouseSGR : public FMouse virtual bool hasData(); // Methods - virtual void setRawData (char[], int); + virtual void setRawData (FKeyboard::keybuffer&); virtual void processEvent (struct timeval*); private: @@ -402,7 +403,7 @@ class FMouseUrxvt : public FMouse virtual bool hasData(); // Methods - virtual void setRawData (char[], int); + virtual void setRawData (FKeyboard::keybuffer&); virtual void processEvent (struct timeval*); private: @@ -492,8 +493,8 @@ class FMouseControl // Methods void enable(); void disable(); - - virtual void setRawData (FMouse::mouse_type, char[], int); + virtual void setRawData ( FMouse::mouse_type + , FKeyboard::keybuffer& ); virtual void processEvent (struct timeval* time); bool getGpmKeyPressed (bool); void drawGpmPointer(); diff --git a/test/fkeyboard-test.cpp b/test/fkeyboard-test.cpp index 539817cd..7d5c5099 100644 --- a/test/fkeyboard-test.cpp +++ b/test/fkeyboard-test.cpp @@ -310,14 +310,14 @@ void FKeyboardTest::classNameTest() void FKeyboardTest::noArgumentTest() { CPPUNIT_ASSERT ( keyboard->getKey() == 0 ); - char* buffer = keyboard->getKeyBuffer(); - int size = keyboard->getKeyBufferSize(); + finalcut::FKeyboard::keybuffer& buffer = keyboard->getKeyBuffer(); + std::size_t size = sizeof(buffer); - CPPUNIT_ASSERT ( size == 512 ); + CPPUNIT_ASSERT ( size == finalcut::FKeyboard::FIFO_BUF_SIZE ); CPPUNIT_ASSERT ( buffer[0] == 0 ); int sum = 0; - for (int i = 0; i < size; i++) + for (std::size_t i = 0; i < size; i++) sum += int(buffer[i]); CPPUNIT_ASSERT ( sum == 0 ); diff --git a/test/fmouse-test.cpp b/test/fmouse-test.cpp index 6e856908..bed7604e 100644 --- a/test/fmouse-test.cpp +++ b/test/fmouse-test.cpp @@ -44,7 +44,7 @@ class FMouse_protected : public finalcut::FMouse virtual bool hasData() { return true; } - virtual void setRawData (char[], int) + virtual void setRawData (finalcut::FKeyboard::keybuffer&) { } virtual void processEvent (struct timeval*) @@ -263,8 +263,9 @@ void FMouseTest::x11MouseTest() finalcut::FMouseX11 x11_mouse; CPPUNIT_ASSERT ( ! x11_mouse.hasData() ); - char rawdata1[] = { 0x1b, '[', 'M', 0x23, 0x50, 0x32, 0x40, 0x40 }; - x11_mouse.setRawData (rawdata1, sizeof(rawdata1)); + finalcut::FKeyboard::keybuffer rawdata1 = \ + { 0x1b, '[', 'M', 0x23, 0x50, 0x32, 0x40, 0x40 }; + x11_mouse.setRawData (rawdata1); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( x11_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( std::strcmp(rawdata1, "@@") == 0 ); @@ -290,14 +291,16 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); // The same input again - char raw[] = { 0x1b, '[', 'M', 0x23, 0x50, 0x32 }; - x11_mouse.setRawData ( raw, sizeof(raw)); + finalcut::FKeyboard::keybuffer raw = \ + { 0x1b, '[', 'M', 0x23, 0x50, 0x32 }; + x11_mouse.setRawData (raw); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! x11_mouse.hasEvent() ); // Left mouse button pressed - char rawdata2[] = { 0x1b, '[', 'M', 0x20, 0x21, 0x21 }; - x11_mouse.setRawData (rawdata2, sizeof(rawdata2)); + finalcut::FKeyboard::keybuffer rawdata2 = \ + { 0x1b, '[', 'M', 0x20, 0x21, 0x21 }; + x11_mouse.setRawData (rawdata2); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( ! x11_mouse.isInputDataPending() ); x11_mouse.processEvent (&tv); @@ -319,8 +322,9 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); // Left mouse button released - char rawdata3[] = { 0x1b, '[', 'M', 0x23, 0x21, 0x21 }; - x11_mouse.setRawData (rawdata3, sizeof(rawdata3)); + finalcut::FKeyboard::keybuffer rawdata3 = \ + { 0x1b, '[', 'M', 0x23, 0x21, 0x21 }; + x11_mouse.setRawData (rawdata3); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( ! x11_mouse.isInputDataPending() ); @@ -343,8 +347,9 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); // Left mouse button pressed again (double click) - char rawdata4[] = { 0x1b, '[', 'M', 0x20, 0x21, 0x21 }; - x11_mouse.setRawData (rawdata4, sizeof(rawdata4)); + finalcut::FKeyboard::keybuffer rawdata4 = \ + { 0x1b, '[', 'M', 0x20, 0x21, 0x21 }; + x11_mouse.setRawData (rawdata4); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( ! x11_mouse.isInputDataPending() ); @@ -369,9 +374,10 @@ void FMouseTest::x11MouseTest() // Middle mouse button - char rawdata5[] = { 0x1b, '[', 'M', 0x21, 0x21, 0x21 - , 0x1b, '[', 'M', 0x23, 0x21, 0x21 }; - x11_mouse.setRawData (rawdata5, sizeof(rawdata5)); + finalcut::FKeyboard::keybuffer rawdata5 = \ + { 0x1b, '[', 'M', 0x21, 0x21, 0x21 + , 0x1b, '[', 'M', 0x23, 0x21, 0x21 }; + x11_mouse.setRawData (rawdata5); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( x11_mouse.isInputDataPending() ); @@ -394,16 +400,17 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); - x11_mouse.setRawData (rawdata5, sizeof(rawdata5)); + x11_mouse.setRawData (rawdata5); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! x11_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( ! x11_mouse.isMiddleButtonPressed() ); CPPUNIT_ASSERT ( x11_mouse.isMiddleButtonReleased() ); // Right mouse button - char rawdata6[] = { 0x1b, '[', 'M', 0x22, 0x21, 0x21 - , 0x1b, '[', 'M', 0x23, 0x21, 0x21 }; - x11_mouse.setRawData (rawdata6, sizeof(rawdata6)); + finalcut::FKeyboard::keybuffer rawdata6 = \ + { 0x1b, '[', 'M', 0x22, 0x21, 0x21 + , 0x1b, '[', 'M', 0x23, 0x21, 0x21 }; + x11_mouse.setRawData (rawdata6); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( x11_mouse.isInputDataPending() ); @@ -426,16 +433,17 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); - x11_mouse.setRawData (rawdata6, sizeof(rawdata6)); + x11_mouse.setRawData (rawdata6); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! x11_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( ! x11_mouse.isRightButtonPressed() ); CPPUNIT_ASSERT ( x11_mouse.isRightButtonReleased() ); // Mouse wheel - char rawdata7[] = { 0x1b, '[', 'M', 0x60, 0x70, 0x39 - , 0x1b, '[', 'M', 0x61, 0x70, 0x39 }; - x11_mouse.setRawData (rawdata7, sizeof(rawdata7)); + finalcut::FKeyboard::keybuffer rawdata7 = \ + { 0x1b, '[', 'M', 0x60, 0x70, 0x39 + , 0x1b, '[', 'M', 0x61, 0x70, 0x39 }; + x11_mouse.setRawData (rawdata7); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( x11_mouse.isInputDataPending() ); @@ -458,16 +466,17 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); - x11_mouse.setRawData (rawdata7, sizeof(rawdata7)); + x11_mouse.setRawData (rawdata7); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! x11_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( x11_mouse.isWheelDown() ); // Mouse move - char rawdata8[] = { 0x1b, '[', 'M', 0x20, 0x21, 0x21 - , 0x1b, '[', 'M', 0x40, 0x23, 0x25 - , 0x1b, '[', 'M', 0x23, 0x23, 0x25 }; - x11_mouse.setRawData (rawdata8, sizeof(rawdata8)); + finalcut::FKeyboard::keybuffer rawdata8 = \ + { 0x1b, '[', 'M', 0x20, 0x21, 0x21 + , 0x1b, '[', 'M', 0x40, 0x23, 0x25 + , 0x1b, '[', 'M', 0x23, 0x23, 0x25 }; + x11_mouse.setRawData (rawdata8); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( x11_mouse.isInputDataPending() ); @@ -490,22 +499,23 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); - x11_mouse.setRawData (rawdata8, sizeof(rawdata8)); + x11_mouse.setRawData (rawdata8); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(3, 5) ); CPPUNIT_ASSERT ( x11_mouse.isMoved() ); - x11_mouse.setRawData (rawdata8, sizeof(rawdata8)); + x11_mouse.setRawData (rawdata8); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( x11_mouse.getPos() == finalcut::FPoint(3, 5) ); CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); // Mouse + keyboard modifier key - char rawdata9[] = { 0x1b, '[', 'M', 0x24, 0x30, 0x40 - , 0x1b, '[', 'M', 0x28, 0x30, 0x40 - , 0x1b, '[', 'M', 0x30, 0x30, 0x40 - , 0x1b, '[', 'M', 0x3c, 0x30, 0x40 }; - x11_mouse.setRawData (rawdata9, sizeof(rawdata9)); + finalcut::FKeyboard::keybuffer rawdata9 = \ + { 0x1b, '[', 'M', 0x24, 0x30, 0x40 + , 0x1b, '[', 'M', 0x28, 0x30, 0x40 + , 0x1b, '[', 'M', 0x30, 0x30, 0x40 + , 0x1b, '[', 'M', 0x3c, 0x30, 0x40 }; + x11_mouse.setRawData (rawdata9); CPPUNIT_ASSERT ( x11_mouse.hasData() ); CPPUNIT_ASSERT ( x11_mouse.isInputDataPending() ); @@ -528,21 +538,21 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); - x11_mouse.setRawData (rawdata9, sizeof(rawdata9)); + x11_mouse.setRawData (rawdata9); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( x11_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( ! x11_mouse.isShiftKeyPressed() ); CPPUNIT_ASSERT ( ! x11_mouse.isControlKeyPressed() ); CPPUNIT_ASSERT ( x11_mouse.isMetaKeyPressed() ); - x11_mouse.setRawData (rawdata9, sizeof(rawdata9)); + x11_mouse.setRawData (rawdata9); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( x11_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( ! x11_mouse.isShiftKeyPressed() ); CPPUNIT_ASSERT ( x11_mouse.isControlKeyPressed() ); CPPUNIT_ASSERT ( ! x11_mouse.isMetaKeyPressed() ); - x11_mouse.setRawData (rawdata9, sizeof(rawdata9)); + x11_mouse.setRawData (rawdata9); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( x11_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( x11_mouse.isShiftKeyPressed() ); @@ -550,8 +560,9 @@ void FMouseTest::x11MouseTest() CPPUNIT_ASSERT ( x11_mouse.isMetaKeyPressed() ); // Clear event test - char rawdata10[] = { 0x1b, '[', 'M', 0x20, 0x7f, 0x3f }; - x11_mouse.setRawData (rawdata10, sizeof(rawdata10)); + finalcut::FKeyboard::keybuffer rawdata10 = \ + { 0x1b, '[', 'M', 0x20, 0x7f, 0x3f }; + x11_mouse.setRawData (rawdata10); CPPUNIT_ASSERT ( x11_mouse.hasData() ); x11_mouse.processEvent (&tv); CPPUNIT_ASSERT ( x11_mouse.hasEvent() ); @@ -566,9 +577,10 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.hasData() ); // Left mouse button pressed - char rawdata1[] = { 0x1b, '[', '<', '0', ';', '7' - , '3', ';', '4', 'M', '@', '@' }; - sgr_mouse.setRawData (rawdata1, sizeof(rawdata1)); + finalcut::FKeyboard::keybuffer rawdata1 = \ + { 0x1b, '[', '<', '0', ';', '7' + , '3', ';', '4', 'M', '@', '@' }; + sgr_mouse.setRawData (rawdata1); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( sgr_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( std::strcmp(rawdata1, "@@") == 0 ); @@ -594,14 +606,16 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); // The same input again - char raw[] = { 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'M' }; - sgr_mouse.setRawData ( raw, sizeof(raw)); + finalcut::FKeyboard::keybuffer raw = \ + { 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'M' }; + sgr_mouse.setRawData (raw); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() ); // Left mouse button released - char rawdata2[] = { 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'm' }; - sgr_mouse.setRawData (rawdata2, sizeof(rawdata2)); + finalcut::FKeyboard::keybuffer rawdata2 = \ + { 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'm' }; + sgr_mouse.setRawData (rawdata2); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( ! sgr_mouse.isInputDataPending() ); @@ -624,8 +638,9 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); // Left mouse button pressed again (double click) - char rawdata4[] = { 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'M' }; - sgr_mouse.setRawData (rawdata4, sizeof(rawdata4)); + finalcut::FKeyboard::keybuffer rawdata4 = \ + { 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'M' }; + sgr_mouse.setRawData (rawdata4); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( ! sgr_mouse.isInputDataPending() ); @@ -649,9 +664,10 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); // Middle mouse button - char rawdata5[] = { 0x1b, '[', '<', '1', ';', '1', ';', '1', 'M' - , 0x1b, '[', '<', '1', ';', '1', ';', '1', 'm' }; - sgr_mouse.setRawData (rawdata5, sizeof(rawdata5)); + finalcut::FKeyboard::keybuffer rawdata5 = \ + { 0x1b, '[', '<', '1', ';', '1', ';', '1', 'M' + , 0x1b, '[', '<', '1', ';', '1', ';', '1', 'm' }; + sgr_mouse.setRawData (rawdata5); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( sgr_mouse.isInputDataPending() ); @@ -674,16 +690,17 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); - sgr_mouse.setRawData (rawdata5, sizeof(rawdata5)); + sgr_mouse.setRawData (rawdata5); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! sgr_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( ! sgr_mouse.isMiddleButtonPressed() ); CPPUNIT_ASSERT ( sgr_mouse.isMiddleButtonReleased() ); // Right mouse button - char rawdata6[] = { 0x1b, '[', '<', '2', ';', '3', ';', '3', 'M' - , 0x1b, '[', '<', '2', ';', '3', ';', '4', 'm' }; - sgr_mouse.setRawData (rawdata6, sizeof(rawdata6)); + finalcut::FKeyboard::keybuffer rawdata6 = \ + { 0x1b, '[', '<', '2', ';', '3', ';', '3', 'M' + , 0x1b, '[', '<', '2', ';', '3', ';', '4', 'm' }; + sgr_mouse.setRawData (rawdata6); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( sgr_mouse.isInputDataPending() ); @@ -706,7 +723,7 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); - sgr_mouse.setRawData (rawdata6, sizeof(rawdata6)); + sgr_mouse.setRawData (rawdata6); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! sgr_mouse.isInputDataPending() ); @@ -714,9 +731,10 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( sgr_mouse.isRightButtonReleased() ); // Mouse wheel - char rawdata7[] = { 0x1b, '[', '<', '6', '4', ';', '4', ';', '9', 'M' - , 0x1b, '[', '<', '6', '5', ';', '4', ';', '9', 'M' }; - sgr_mouse.setRawData (rawdata7, sizeof(rawdata7)); + finalcut::FKeyboard::keybuffer rawdata7 = \ + { 0x1b, '[', '<', '6', '4', ';', '4', ';', '9', 'M' + , 0x1b, '[', '<', '6', '5', ';', '4', ';', '9', 'M' }; + sgr_mouse.setRawData (rawdata7); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( sgr_mouse.isInputDataPending() ); @@ -739,16 +757,17 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); - sgr_mouse.setRawData (rawdata7, sizeof(rawdata7)); + sgr_mouse.setRawData (rawdata7); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! sgr_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( sgr_mouse.isWheelDown() ); // Mouse move - char rawdata8[] = { 0x1b, '[', '<', '0', ';', '1', ';', '2', 'M' - , 0x1b, '[', '<', '3', '2', ';', '2', ';', '3', 'M' - , 0x1b, '[', '<', '0', ';', '3', ';', '4', 'm' }; - sgr_mouse.setRawData (rawdata8, sizeof(rawdata8)); + finalcut::FKeyboard::keybuffer rawdata8 = \ + { 0x1b, '[', '<', '0', ';', '1', ';', '2', 'M' + , 0x1b, '[', '<', '3', '2', ';', '2', ';', '3', 'M' + , 0x1b, '[', '<', '0', ';', '3', ';', '4', 'm' }; + sgr_mouse.setRawData (rawdata8); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( sgr_mouse.isInputDataPending() ); @@ -771,22 +790,23 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); - sgr_mouse.setRawData (rawdata8, sizeof(rawdata8)); + sgr_mouse.setRawData (rawdata8); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(2, 3) ); CPPUNIT_ASSERT ( sgr_mouse.isMoved() ); - sgr_mouse.setRawData (rawdata8, sizeof(rawdata8)); + sgr_mouse.setRawData (rawdata8); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( sgr_mouse.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); // Mouse + keyboard modifier key - char rawdata9[] = { 0x1b, '[', '<', '4', ';', '5', ';', '5', 'M' - , 0x1b, '[', '<', '8', ';', '5', ';', '5', 'M' - , 0x1b, '[', '<', '1', '6', ';', '5', ';', '5', 'M' - , 0x1b, '[', '<', '2', '8', ';', '5', ';', '5', 'M' }; - sgr_mouse.setRawData (rawdata9, sizeof(rawdata9)); + finalcut::FKeyboard::keybuffer rawdata9 = \ + { 0x1b, '[', '<', '4', ';', '5', ';', '5', 'M' + , 0x1b, '[', '<', '8', ';', '5', ';', '5', 'M' + , 0x1b, '[', '<', '1', '6', ';', '5', ';', '5', 'M' + , 0x1b, '[', '<', '2', '8', ';', '5', ';', '5', 'M' }; + sgr_mouse.setRawData (rawdata9); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); CPPUNIT_ASSERT ( sgr_mouse.isInputDataPending() ); @@ -809,21 +829,21 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() ); - sgr_mouse.setRawData (rawdata9, sizeof(rawdata9)); + sgr_mouse.setRawData (rawdata9); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( ! sgr_mouse.isShiftKeyPressed() ); CPPUNIT_ASSERT ( ! sgr_mouse.isControlKeyPressed() ); CPPUNIT_ASSERT ( sgr_mouse.isMetaKeyPressed() ); - sgr_mouse.setRawData (rawdata9, sizeof(rawdata9)); + sgr_mouse.setRawData (rawdata9); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( ! sgr_mouse.isShiftKeyPressed() ); CPPUNIT_ASSERT ( sgr_mouse.isControlKeyPressed() ); CPPUNIT_ASSERT ( ! sgr_mouse.isMetaKeyPressed() ); - sgr_mouse.setRawData (rawdata9, sizeof(rawdata9)); + sgr_mouse.setRawData (rawdata9); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( sgr_mouse.isShiftKeyPressed() ); @@ -831,8 +851,9 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( sgr_mouse.isMetaKeyPressed() ); // Clear event test - char rawdata10[] = { 0x1b, '[', '<', '2', ';', '1', ';', '1', 'M' }; - sgr_mouse.setRawData (rawdata10, sizeof(rawdata10)); + finalcut::FKeyboard::keybuffer rawdata10 = \ + { 0x1b, '[', '<', '2', ';', '1', ';', '1', 'M' }; + sgr_mouse.setRawData (rawdata10); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( sgr_mouse.hasEvent() ); @@ -840,20 +861,21 @@ void FMouseTest::sgrMouseTest() CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() ); // Wrong mouse data - char rawdata11[] = { 0x1b, '[', '<', '2', 'O', ';', '2', ';', '2', 'M' - , 0x1b, '[', '<', '1', ';', 'x', ';', '3', 'M' - , 0x1b, '[', '<', '6', ';', '5', ';', '@', 'M', '@' }; - sgr_mouse.setRawData (rawdata11, sizeof(rawdata11)); + finalcut::FKeyboard::keybuffer rawdata11 = \ + { 0x1b, '[', '<', '2', 'O', ';', '2', ';', '2', 'M' + , 0x1b, '[', '<', '1', ';', 'x', ';', '3', 'M' + , 0x1b, '[', '<', '6', ';', '5', ';', '@', 'M', '@' }; + sgr_mouse.setRawData (rawdata11); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() ); - sgr_mouse.setRawData (rawdata11, sizeof(rawdata11)); + sgr_mouse.setRawData (rawdata11); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() ); - sgr_mouse.setRawData (rawdata11, sizeof(rawdata11)); + sgr_mouse.setRawData (rawdata11); CPPUNIT_ASSERT ( sgr_mouse.hasData() ); sgr_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() ); @@ -869,9 +891,10 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() ); // Left mouse button pressed - char rawdata1[] = { 0x1b, '[', '3', '2', ';', '4' - , '9', ';', '6', 'M', '@', '@' }; - urxvt_mouse.setRawData (rawdata1, sizeof(rawdata1)); + finalcut::FKeyboard::keybuffer rawdata1 = \ + { 0x1b, '[', '3', '2', ';', '4' + , '9', ';', '6', 'M', '@', '@' }; + urxvt_mouse.setRawData (rawdata1); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( urxvt_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( std::strcmp(rawdata1, "@@") == 0 ); @@ -896,14 +919,16 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); // The same input again - char raw[] = { 0x1b, '[', '3', '2', ';', '4', '9', ';', '6', 'M' }; - urxvt_mouse.setRawData ( raw, sizeof(raw)); + finalcut::FKeyboard::keybuffer raw = \ + { 0x1b, '[', '3', '2', ';', '4', '9', ';', '6', 'M' }; + urxvt_mouse.setRawData (raw); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() ); // Left mouse button released - char rawdata2[] = { 0x1b, '[', '3', '5', ';', '4', '9', ';', '6', 'M' }; - urxvt_mouse.setRawData (rawdata2, sizeof(rawdata2)); + finalcut::FKeyboard::keybuffer rawdata2 = \ + { 0x1b, '[', '3', '5', ';', '4', '9', ';', '6', 'M' }; + urxvt_mouse.setRawData (rawdata2); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isInputDataPending() ); @@ -926,8 +951,9 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); // Left mouse button pressed again (double click) - char rawdata4[] = { 0x1b, '[', '3', '2', ';', '4', '9', ';', '6', 'M' }; - urxvt_mouse.setRawData (rawdata4, sizeof(rawdata4)); + finalcut::FKeyboard::keybuffer rawdata4 = \ + { 0x1b, '[', '3', '2', ';', '4', '9', ';', '6', 'M' }; + urxvt_mouse.setRawData (rawdata4); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isInputDataPending() ); @@ -951,9 +977,10 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); // Middle mouse button - char rawdata5[] = { 0x1b, '[', '3', '3', ';', '1', ';', '1', 'M' - , 0x1b, '[', '3', '5', ';', '1', ';', '1', 'M' }; - urxvt_mouse.setRawData (rawdata5, sizeof(rawdata5)); + finalcut::FKeyboard::keybuffer rawdata5 = \ + { 0x1b, '[', '3', '3', ';', '1', ';', '1', 'M' + , 0x1b, '[', '3', '5', ';', '1', ';', '1', 'M' }; + urxvt_mouse.setRawData (rawdata5); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( urxvt_mouse.isInputDataPending() ); @@ -976,16 +1003,17 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); - urxvt_mouse.setRawData (rawdata5, sizeof(rawdata5)); + urxvt_mouse.setRawData (rawdata5); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMiddleButtonPressed() ); CPPUNIT_ASSERT ( urxvt_mouse.isMiddleButtonReleased() ); // Right mouse button - char rawdata6[] = { 0x1b, '[', '3', '4', ';', '3', ';', '3', 'M' - , 0x1b, '[', '3', '5', ';', '3', ';', '4', 'M' }; - urxvt_mouse.setRawData (rawdata6, sizeof(rawdata6)); + finalcut::FKeyboard::keybuffer rawdata6 = \ + { 0x1b, '[', '3', '4', ';', '3', ';', '3', 'M' + , 0x1b, '[', '3', '5', ';', '3', ';', '4', 'M' }; + urxvt_mouse.setRawData (rawdata6); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( urxvt_mouse.isInputDataPending() ); @@ -1008,7 +1036,7 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); - urxvt_mouse.setRawData (rawdata6, sizeof(rawdata6)); + urxvt_mouse.setRawData (rawdata6); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! urxvt_mouse.isInputDataPending() ); @@ -1016,9 +1044,10 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( urxvt_mouse.isRightButtonReleased() ); // Mouse wheel - char rawdata7[] = { 0x1b, '[', '9', '6', ';', '4', ';', '9', 'M' - , 0x1b, '[', '9', '7', ';', '4', ';', '9', 'M' }; - urxvt_mouse.setRawData (rawdata7, sizeof(rawdata7)); + finalcut::FKeyboard::keybuffer rawdata7 = \ + { 0x1b, '[', '9', '6', ';', '4', ';', '9', 'M' + , 0x1b, '[', '9', '7', ';', '4', ';', '9', 'M' }; + urxvt_mouse.setRawData (rawdata7); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( urxvt_mouse.isInputDataPending() ); @@ -1041,16 +1070,17 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); - urxvt_mouse.setRawData (rawdata7, sizeof(rawdata7)); + urxvt_mouse.setRawData (rawdata7); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.isInputDataPending() ); CPPUNIT_ASSERT ( urxvt_mouse.isWheelDown() ); // Mouse move - char rawdata8[] = { 0x1b, '[', '3', '2', ';', '1', ';', '2', 'M' - , 0x1b, '[', '6', '4', ';', '2', ';', '3', 'M' - , 0x1b, '[', '3', '5', ';', '3', ';', '4', 'M' }; - urxvt_mouse.setRawData (rawdata8, sizeof(rawdata8)); + finalcut::FKeyboard::keybuffer rawdata8 = \ + { 0x1b, '[', '3', '2', ';', '1', ';', '2', 'M' + , 0x1b, '[', '6', '4', ';', '2', ';', '3', 'M' + , 0x1b, '[', '3', '5', ';', '3', ';', '4', 'M' }; + urxvt_mouse.setRawData (rawdata8); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( urxvt_mouse.isInputDataPending() ); @@ -1073,22 +1103,23 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); - urxvt_mouse.setRawData (rawdata8, sizeof(rawdata8)); + urxvt_mouse.setRawData (rawdata8); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(2, 3) ); CPPUNIT_ASSERT ( urxvt_mouse.isMoved() ); - urxvt_mouse.setRawData (rawdata8, sizeof(rawdata8)); + urxvt_mouse.setRawData (rawdata8); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); // Mouse + keyboard modifier key - char rawdata9[] = { 0x1b, '[', '3', '6', ';', '5', ';', '5', 'M' - , 0x1b, '[', '4', '0', ';', '5', ';', '5', 'M' - , 0x1b, '[', '4', '8', ';', '5', ';', '5', 'M' - , 0x1b, '[', '6', '0', ';', '5', ';', '5', 'M' }; - urxvt_mouse.setRawData (rawdata9, sizeof(rawdata9)); + finalcut::FKeyboard::keybuffer rawdata9 = \ + { 0x1b, '[', '3', '6', ';', '5', ';', '5', 'M' + , 0x1b, '[', '4', '0', ';', '5', ';', '5', 'M' + , 0x1b, '[', '4', '8', ';', '5', ';', '5', 'M' + , 0x1b, '[', '6', '0', ';', '5', ';', '5', 'M' }; + urxvt_mouse.setRawData (rawdata9); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( urxvt_mouse.isInputDataPending() ); @@ -1111,21 +1142,21 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMoved() ); - urxvt_mouse.setRawData (rawdata9, sizeof(rawdata9)); + urxvt_mouse.setRawData (rawdata9); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( urxvt_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isShiftKeyPressed() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isControlKeyPressed() ); CPPUNIT_ASSERT ( urxvt_mouse.isMetaKeyPressed() ); - urxvt_mouse.setRawData (rawdata9, sizeof(rawdata9)); + urxvt_mouse.setRawData (rawdata9); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( urxvt_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isShiftKeyPressed() ); CPPUNIT_ASSERT ( urxvt_mouse.isControlKeyPressed() ); CPPUNIT_ASSERT ( ! urxvt_mouse.isMetaKeyPressed() ); - urxvt_mouse.setRawData (rawdata9, sizeof(rawdata9)); + urxvt_mouse.setRawData (rawdata9); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( urxvt_mouse.isLeftButtonPressed() ); CPPUNIT_ASSERT ( urxvt_mouse.isShiftKeyPressed() ); @@ -1133,8 +1164,9 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( urxvt_mouse.isMetaKeyPressed() ); // Clear event test - char rawdata10[] = { 0x1b, '[', '3', '2', ';', '1', ';', '1', 'M' }; - urxvt_mouse.setRawData (rawdata10, sizeof(rawdata10)); + finalcut::FKeyboard::keybuffer rawdata10 = \ + { 0x1b, '[', '3', '2', ';', '1', ';', '1', 'M' }; + urxvt_mouse.setRawData (rawdata10); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() ); @@ -1142,20 +1174,21 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() ); // Wrong mouse data - char rawdata11[] = { 0x1b, '[', '3', 'O', ';', '2', ';', '2', 'M' - , 0x1b, '[', '3', '3', ';', 'x', ';', '3', 'M' - , 0x1b, '[', '3', '4', ';', '5', ';', '@', 'M', '@' }; - urxvt_mouse.setRawData (rawdata11, sizeof(rawdata11)); + finalcut::FKeyboard::keybuffer rawdata11 = \ + { 0x1b, '[', '3', 'O', ';', '2', ';', '2', 'M' + , 0x1b, '[', '3', '3', ';', 'x', ';', '3', 'M' + , 0x1b, '[', '3', '4', ';', '5', ';', '@', 'M', '@' }; + urxvt_mouse.setRawData (rawdata11); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() ); - urxvt_mouse.setRawData (rawdata11, sizeof(rawdata11)); + urxvt_mouse.setRawData (rawdata11); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() ); - urxvt_mouse.setRawData (rawdata11, sizeof(rawdata11)); + urxvt_mouse.setRawData (rawdata11); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.hasEvent() ); @@ -1164,9 +1197,10 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( std::strcmp(rawdata11, "@") == 0 ); // Negative values - char rawdata12[] = { 0x1b, '[', '3', '2', ';', '-', '5', ';', '5', 'M' - , 0x1b, '[', '3', '2', ';', '3', ';', '-', '3', 'M' }; - urxvt_mouse.setRawData (rawdata12, sizeof(rawdata12)); + finalcut::FKeyboard::keybuffer rawdata12 = \ + { 0x1b, '[', '3', '2', ';', '-', '5', ';', '5', 'M' + , 0x1b, '[', '3', '2', ';', '3', ';', '-', '3', 'M' }; + urxvt_mouse.setRawData (rawdata12); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); CPPUNIT_ASSERT ( urxvt_mouse.isInputDataPending() ); urxvt_mouse.processEvent (&tv); @@ -1175,7 +1209,7 @@ void FMouseTest::urxvtMouseTest() CPPUNIT_ASSERT ( urxvt_mouse.getPos() == finalcut::FPoint(1, 5) ); CPPUNIT_ASSERT ( urxvt_mouse.hasEvent() ); - urxvt_mouse.setRawData (rawdata12, sizeof(rawdata12)); + urxvt_mouse.setRawData (rawdata12); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() ); @@ -1186,8 +1220,9 @@ void FMouseTest::urxvtMouseTest() // Oversize values urxvt_mouse.setMaxWidth(40); urxvt_mouse.setMaxHeight(20); - char rawdata13[] = { 0x1b, '[', '3', '2', ';', '7', '0', ';', '2', '5', 'M' }; - urxvt_mouse.setRawData (rawdata13, sizeof(rawdata13)); + finalcut::FKeyboard::keybuffer rawdata13 = \ + { 0x1b, '[', '3', '2', ';', '7', '0', ';', '2', '5', 'M' }; + urxvt_mouse.setRawData (rawdata13); CPPUNIT_ASSERT ( urxvt_mouse.hasData() ); urxvt_mouse.processEvent (&tv); CPPUNIT_ASSERT ( ! urxvt_mouse.hasData() ); @@ -1233,9 +1268,10 @@ void FMouseTest::mouseControlTest() } // Left mouse button pressed on an X11 mouse - char rawdata1[] = { 0x1b, '[', 'M', 0x20, 0x25, 0x28 - , 0x1b, '[', 'M', 0x23, 0x25, 0x28 }; - mouse_control.setRawData (finalcut::FMouse::x11, rawdata1, sizeof(rawdata1)); + finalcut::FKeyboard::keybuffer rawdata1 = \ + { 0x1b, '[', 'M', 0x20, 0x25, 0x28 + , 0x1b, '[', 'M', 0x23, 0x25, 0x28 }; + mouse_control.setRawData (finalcut::FMouse::x11, rawdata1); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.isInputDataPending() ); @@ -1260,7 +1296,7 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); CPPUNIT_ASSERT ( mouse_control.isInputDataPending() ); - mouse_control.setRawData (finalcut::FMouse::x11, rawdata1, sizeof(rawdata1)); + mouse_control.setRawData (finalcut::FMouse::x11, rawdata1); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( ! mouse_control.isInputDataPending() ); CPPUNIT_ASSERT ( ! mouse_control.isLeftButtonPressed() ); @@ -1268,9 +1304,10 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isLeftButtonDoubleClick() ); // Middle mouse button on an SGR mouse - char rawdata2[] = { 0x1b, '[', '<', '1', ';', '1', ';', '1', 'M' - , 0x1b, '[', '<', '1', ';', '1', ';', '1', 'm' }; - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata2, sizeof(rawdata2)); + finalcut::FKeyboard::keybuffer rawdata2 = \ + { 0x1b, '[', '<', '1', ';', '1', ';', '1', 'M' + , 0x1b, '[', '<', '1', ';', '1', ';', '1', 'm' }; + mouse_control.setRawData (finalcut::FMouse::sgr, rawdata2); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.isInputDataPending() ); finalcut::FObject::getCurrentTime(&tv); @@ -1292,16 +1329,16 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata2, sizeof(rawdata2)); + mouse_control.setRawData (finalcut::FMouse::sgr, rawdata2); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( ! mouse_control.isInputDataPending() ); CPPUNIT_ASSERT ( ! mouse_control.isMiddleButtonPressed() ); CPPUNIT_ASSERT ( mouse_control.isMiddleButtonReleased() ); // Right mouse button on a urxvt mouse - char rawdata3[] = { 0x1b, '[', '3', '4', ';', '3', ';', '3', 'M' + finalcut::FKeyboard::keybuffer rawdata3 = { 0x1b, '[', '3', '4', ';', '3', ';', '3', 'M' , 0x1b, '[', '3', '5', ';', '3', ';', '4', 'M' }; - mouse_control.setRawData (finalcut::FMouse::urxvt, rawdata3, sizeof(rawdata3)); + mouse_control.setRawData (finalcut::FMouse::urxvt, rawdata3); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.isInputDataPending() ); finalcut::FObject::getCurrentTime(&tv); @@ -1323,7 +1360,7 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::urxvt, rawdata3, sizeof(rawdata3)); + mouse_control.setRawData (finalcut::FMouse::urxvt, rawdata3); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! mouse_control.isInputDataPending() ); @@ -1331,9 +1368,10 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( mouse_control.isRightButtonReleased() ); // Mouse wheel on an X11 mouse - char rawdata4[] = { 0x1b, '[', 'M', 0x60, 0x70, 0x39 - , 0x1b, '[', 'M', 0x61, 0x70, 0x39 }; - mouse_control.setRawData (finalcut::FMouse::x11, rawdata4, sizeof(rawdata4)); + finalcut::FKeyboard::keybuffer rawdata4 = \ + { 0x1b, '[', 'M', 0x60, 0x70, 0x39 + , 0x1b, '[', 'M', 0x61, 0x70, 0x39 }; + mouse_control.setRawData (finalcut::FMouse::x11, rawdata4); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.isInputDataPending() ); finalcut::FObject::getCurrentTime(&tv); @@ -1355,16 +1393,17 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::x11, rawdata4, sizeof(rawdata4)); + mouse_control.setRawData (finalcut::FMouse::x11, rawdata4); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( ! mouse_control.isInputDataPending() ); CPPUNIT_ASSERT ( mouse_control.isWheelDown() ); // Mouse move on an SGR mouse - char rawdata5[] = { 0x1b, '[', '<', '0', ';', '1', ';', '2', 'M' - , 0x1b, '[', '<', '3', '2', ';', '2', ';', '3', 'M' - , 0x1b, '[', '<', '0', ';', '3', ';', '4', 'm' }; - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5, sizeof(rawdata5)); + finalcut::FKeyboard::keybuffer rawdata5 = \ + { 0x1b, '[', '<', '0', ';', '1', ';', '2', 'M' + , 0x1b, '[', '<', '3', '2', ';', '2', ';', '3', 'M' + , 0x1b, '[', '<', '0', ';', '3', ';', '4', 'm' }; + mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.isInputDataPending() ); finalcut::FObject::getCurrentTime(&tv); @@ -1386,12 +1425,12 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5, sizeof(rawdata5)); + mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(2, 3) ); CPPUNIT_ASSERT ( mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5, sizeof(rawdata5)); + mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); From dbaebf0efce6d1bb288bbb6fc77028e87b8f61e3 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 11 Oct 2018 11:40:28 +0200 Subject: [PATCH 06/17] Out-of-bounds fix for FMouse --- src/fmouse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fmouse.cpp b/src/fmouse.cpp index dd3faa13..b010af73 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -700,7 +700,7 @@ void FMouseSGR::setRawData (FKeyboard::keybuffer& fifo_buf) std::size_t len = std::strlen(fifo_buf); std::size_t n = 3; - while ( n < len && n < fifo_buf_size ) + while ( n < len && n < MOUSE_BUF_SIZE + 3 ) { sgr_mouse[n - 3] = fifo_buf[n]; n++; @@ -954,7 +954,7 @@ void FMouseUrxvt::setRawData (FKeyboard::keybuffer& fifo_buf) std::size_t len = std::strlen(fifo_buf); std::size_t n = 2; - while ( n < len && n < fifo_buf_size ) + while ( n < len && n < MOUSE_BUF_SIZE + 2 ) { urxvt_mouse[n - 2] = fifo_buf[n]; n++; From 3fd5abfa1a24d1ff8eaaee5a894f3c23e5aa09a7 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 13 Oct 2018 00:32:14 +0200 Subject: [PATCH 07/17] Avoid using dynamic_cast in source code --- ChangeLog | 5 +++++ src/fmenuitem.cpp | 30 +++++++++++++++++++++++++----- src/include/final/fmenuitem.h | 3 +++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15a9d1b4..0fbc99a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-10-13 Markus Gans + * Avoid using dynamic_cast so that you can compile Final Cut + without Run-Time Type Information (RTTI). + Thanks to user1095108 for reporting that. + 2018-10-11 Markus Gans * FKeyboard now uses references for keyboard buffer passing diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 6bf0a942..a012f21e 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -101,7 +101,7 @@ FMenuItem::~FMenuItem() // destructor { if ( super_menu && (isMenu(super_menu) || isMenuBar(super_menu)) ) { - FMenuList* menu_list = dynamic_cast(super_menu); + FMenuList* menu_list = getFMenuList(*super_menu); if ( menu_list ) menu_list->remove(this); @@ -150,7 +150,7 @@ bool FMenuItem::setFocus (bool on) { if ( ! selected ) { - FMenuList* menu_list = dynamic_cast(getSuperMenu()); + FMenuList* menu_list = getFMenuList(*getSuperMenu()); setSelected(); if ( menu_list ) @@ -559,6 +559,27 @@ bool FMenuItem::isMenu (FWidget* w) const // private methods of FMenuItem +//---------------------------------------------------------------------- +FMenuList* FMenuItem::getFMenuList (FWidget& widget) +{ + FMenuList* menu_list; + + if ( isMenu(&widget) ) + { + FMenu* menu = static_cast(&widget); + menu_list = static_cast(menu); + } + else if ( isMenuBar(&widget) ) + { + FMenuBar* menubar = static_cast(&widget); + menu_list = static_cast(menubar); + } + else + menu_list = 0; + + return menu_list; +} + //---------------------------------------------------------------------- void FMenuItem::init (FWidget* parent) { @@ -573,13 +594,12 @@ void FMenuItem::init (FWidget* parent) if ( ! parent ) return; - FMenuList* menu_list; setSuperMenu (parent); if ( accel_key ) addAccelerator (accel_key); - menu_list = dynamic_cast(parent); + FMenuList* menu_list = getFMenuList(*parent); if ( menu_list ) menu_list->insert(this); @@ -616,7 +636,7 @@ uChar FMenuItem::hotKey() length = text.getLength(); - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { try { diff --git a/src/include/final/fmenuitem.h b/src/include/final/fmenuitem.h index 493c48aa..28deba43 100644 --- a/src/include/final/fmenuitem.h +++ b/src/include/final/fmenuitem.h @@ -166,6 +166,9 @@ class FMenuItem : public FWidget // Disable assignment operator (=) FMenuItem& operator = (const FMenuItem&); + // Accessor + FMenuList* getFMenuList (FWidget&); + // Methods void init (FWidget*); uChar hotKey(); From b6ffa0f19000456fa62060f319b15801b86b20f3 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 13 Oct 2018 00:39:48 +0200 Subject: [PATCH 08/17] Avoid using dynamic_cast in source code --- src/fmenuitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index a012f21e..b866371c 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -636,7 +636,7 @@ uChar FMenuItem::hotKey() length = text.getLength(); - for (std::size_t i = 0; i < length; i++) + for (uInt i = 0; i < length; i++) { try { From cfc1c4ef25e385028e70e6d4e5f815dd7cb421dc Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 14 Oct 2018 06:25:33 +0200 Subject: [PATCH 09/17] change from int to std::size_t for width or height --- ChangeLog | 4 + build.sh | 2 +- examples/Makefile.clang | 2 +- examples/calculator.cpp | 8 +- examples/choice.cpp | 8 +- examples/keyboard.cpp | 2 +- examples/mandelbrot.cpp | 8 +- examples/menu.cpp | 8 +- examples/mouse.cpp | 17 +- examples/opti-move.cpp | 10 +- examples/scrollview.cpp | 24 +-- examples/term-attributes.cpp | 14 +- examples/timer.cpp | 2 +- examples/transparent.cpp | 4 +- examples/treeview.cpp | 4 +- examples/ui.cpp | 14 +- examples/watch.cpp | 4 +- examples/windows.cpp | 28 +-- logo/svg/finalcut-logo.svg | 8 +- src/Makefile.clang | 4 +- src/Makefile.gcc | 2 +- src/fbutton.cpp | 52 ++--- src/fbuttongroup.cpp | 28 +-- src/fdialog.cpp | 109 +++++----- src/ffiledialog.cpp | 27 ++- src/fkeyboard.cpp | 14 +- src/flabel.cpp | 79 +++---- src/flineedit.cpp | 72 +++---- src/flistbox.cpp | 322 ++++++++++++++--------------- src/flistview.cpp | 158 +++++++------- src/fmenu.cpp | 67 +++--- src/fmenubar.cpp | 61 +++--- src/fmenuitem.cpp | 16 +- src/fmessagebox.cpp | 62 +++--- src/fmouse.cpp | 4 +- src/foptimove.cpp | 24 +-- src/fprogressbar.cpp | 16 +- src/frect.cpp | 33 +-- src/fscrollbar.cpp | 63 +++--- src/fscrollview.cpp | 104 +++++----- src/fstatusbar.cpp | 56 +++-- src/fstring.cpp | 139 +++---------- src/fterm.cpp | 10 +- src/ftermxterminal.cpp | 8 +- src/ftextview.cpp | 134 ++++++------ src/ftogglebutton.cpp | 40 ++-- src/ftooltip.cpp | 13 +- src/fvterm.cpp | 47 +++-- src/fwidget.cpp | 152 +++++++------- src/fwindow.cpp | 30 +-- src/include/final/fbutton.h | 2 +- src/include/final/fbuttongroup.h | 10 +- src/include/final/fdialog.h | 16 +- src/include/final/flabel.h | 6 +- src/include/final/flineedit.h | 2 +- src/include/final/flistbox.h | 52 ++--- src/include/final/flistview.h | 10 +- src/include/final/fmenu.h | 12 +- src/include/final/fmenubar.h | 14 +- src/include/final/fmenuitem.h | 6 +- src/include/final/fmenulist.h | 6 +- src/include/final/fmessagebox.h | 2 +- src/include/final/foptimove.h | 6 +- src/include/final/fprogressbar.h | 6 +- src/include/final/frect.h | 104 +++++----- src/include/final/fscrollbar.h | 8 +- src/include/final/fscrollview.h | 32 +-- src/include/final/fstatusbar.h | 8 +- src/include/final/fstring.h | 45 ++-- src/include/final/fterm.h | 6 +- src/include/final/ftermxterminal.h | 6 +- src/include/final/ftextview.h | 18 +- src/include/final/ftogglebutton.h | 10 +- src/include/final/ftooltip.h | 6 +- src/include/final/fwidget.h | 92 ++++----- src/include/final/fwindow.h | 10 +- test/fstring-test.cpp | 12 +- 77 files changed, 1285 insertions(+), 1339 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0fbc99a9..dffab7fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2018-10-14 Markus Gans + * A width or height can not be negative. + For that reason the change from int to std::size_t. + 2018-10-13 Markus Gans * Avoid using dynamic_cast so that you can compile Final Cut without Run-Time Type Information (RTTI). diff --git a/build.sh b/build.sh index 91aaad2f..da7b8863 100755 --- a/build.sh +++ b/build.sh @@ -43,7 +43,7 @@ fi # Build commands case "$1" in "--release"|"release") - if ! ./configure --prefix="$PREFIX" + if ! ./configure --prefix="$PREFIX" CXXFLAGS="-O3 -fno-rtti" then echo "${RED}Configure failed!${NORMAL}" 1>&2 exit -1 diff --git a/examples/Makefile.clang b/examples/Makefile.clang index 8fe6f0c9..57564bec 100644 --- a/examples/Makefile.clang +++ b/examples/Makefile.clang @@ -29,7 +29,7 @@ endif all: $(OBJS) debug: - $(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -Wall -Wextra -Wpedantic -Weverything -Wpadded" + $(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -Wall -Wextra -Wpedantic -Weverything -Wpadded -Wno-reserved-id-macro" profile: $(MAKE) $(MAKEFILE) PROFILE="-pg" diff --git a/examples/calculator.cpp b/examples/calculator.cpp index e7d9949d..2bf1af22 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -1100,10 +1100,10 @@ void Calc::cb_buttonClicked (finalcut::FWidget*, data_ptr data) //---------------------------------------------------------------------- void Calc::adjustSize() { - int pw = getParentWidget()->getWidth(); - int ph = getParentWidget()->getHeight(); - setX (1 + (pw - getWidth()) / 2, false); - setY (1 + (ph - getHeight()) / 2, false); + std::size_t pw = getParentWidget()->getWidth(); + std::size_t ph = getParentWidget()->getHeight(); + setX (1 + int(pw - getWidth()) / 2, false); + setY (1 + int(ph - getHeight()) / 2, false); finalcut::FDialog::adjustSize(); } diff --git a/examples/choice.cpp b/examples/choice.cpp index cd13e04b..53c08f7a 100644 --- a/examples/choice.cpp +++ b/examples/choice.cpp @@ -99,10 +99,10 @@ int main (int argc, char* argv[]) finalcut::FDialog dgl(&app); dgl.setModal(); dgl.setText ("UNIX select"); - int w = 20; - int h = 13; - int x = (app.getDesktopWidth() - w) / 2; - int y = (app.getDesktopHeight() - h) / 2; + std::size_t w = 20; + std::size_t h = 13; + int x = int(app.getDesktopWidth() - w) / 2; + int y = int(app.getDesktopHeight() - h) / 2; dgl.setGeometry (x, y, w, h); // Create a button group diff --git a/examples/keyboard.cpp b/examples/keyboard.cpp index 49195c4d..ba55db63 100644 --- a/examples/keyboard.cpp +++ b/examples/keyboard.cpp @@ -56,7 +56,7 @@ void Keyboard::onKeyPress (finalcut::FKeyEvent* ev) int key_id = ev->key(); bool is_last_line = false; - if ( getPrintPos().getY() == getDesktopHeight() ) + if ( getPrintPos().getY() == int(getDesktopHeight()) ) is_last_line = true; print() << "Key " << getKeyName(key_id).c_str() diff --git a/examples/mandelbrot.cpp b/examples/mandelbrot.cpp index ad3be26e..bb5e70ab 100644 --- a/examples/mandelbrot.cpp +++ b/examples/mandelbrot.cpp @@ -80,8 +80,8 @@ void Mandelbrot::draw() xoffset = 2; yoffset = 2; current_line = 0; - Cols = getClientWidth(); - Lines = getClientHeight(); + Cols = int(getClientWidth()); + Lines = int(getClientHeight()); dX = (x_max - x_min) / (Cols - 1); dY = (y_max - y_min) / Lines; @@ -131,8 +131,8 @@ void Mandelbrot::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void Mandelbrot::adjustSize() { - int h = getParentWidget()->getHeight() - 1; - int w = getParentWidget()->getWidth() - 10; + std::size_t h = getParentWidget()->getHeight() - 1; + std::size_t w = getParentWidget()->getWidth() - 10; setGeometry(6, 1, w, h, false); finalcut::FDialog::adjustSize(); } diff --git a/examples/menu.cpp b/examples/menu.cpp index b80df0a2..117ae6a4 100644 --- a/examples/menu.cpp +++ b/examples/menu.cpp @@ -337,10 +337,10 @@ void Menu::defaultCallback (finalcut::FMenuList* mb) //---------------------------------------------------------------------- void Menu::adjustSize() { - int pw = getParentWidget()->getWidth(); - int ph = getParentWidget()->getHeight(); - setX (1 + (pw - getWidth()) / 2, false); - setY (1 + (ph - getHeight()) / 4, false); + int pw = int(getParentWidget()->getWidth()); + int ph = int(getParentWidget()->getHeight()); + setX (1 + (pw - int(getWidth())) / 2, false); + setY (1 + (ph - int(getHeight())) / 4, false); finalcut::FDialog::adjustSize(); } diff --git a/examples/mouse.cpp b/examples/mouse.cpp index ab829f46..445d6d50 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -323,7 +323,7 @@ class MouseDraw : public finalcut::FDialog ~MouseDraw(); // Methods - void setGeometry (int, int, int, int, bool = true); + void setGeometry (int, int, std::size_t, std::size_t, bool = true); // Event handlers virtual void onAccel (finalcut::FAccelEvent*); @@ -382,7 +382,7 @@ MouseDraw::~MouseDraw() { } //---------------------------------------------------------------------- -void MouseDraw::setGeometry (int x, int y, int w, int h, bool adjust) +void MouseDraw::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { int old_w, old_h; finalcut::FDialog::setGeometry (x, y, w, h, adjust); @@ -416,7 +416,7 @@ void MouseDraw::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void MouseDraw::draw() { - int y_max = getHeight(); + int y_max = int(getHeight()); finalcut::FDialog::draw(); setColor(); @@ -452,8 +452,8 @@ void MouseDraw::draw() //---------------------------------------------------------------------- void MouseDraw::drawBrush (int x, int y, bool swap_color) { - int Cols = getWidth(); - int Lines = getHeight(); + int Cols = int(getWidth()); + int Lines = int(getHeight()); if ( x > 10 && x < Cols && y > 2 && y < Lines ) { @@ -508,10 +508,9 @@ void MouseDraw::drawCanvas() //---------------------------------------------------------------------- void MouseDraw::adjustSize() { - int w = 60 - , h = 18 - , x = 1 + (getParentWidget()->getWidth() - w) / 2 - , y = 1 + (getParentWidget()->getHeight() - h) / 2; + std::size_t w = 60, h = 18; + int x = 1 + int((getParentWidget()->getWidth() - w) / 2); + int y = 1 + int((getParentWidget()->getHeight() - h) / 2); setGeometry (x, y, w, h, false); finalcut::FDialog::adjustSize(); } diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index 90cf38ef..810932a0 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -66,8 +66,8 @@ bool keyPressed() void term_boundaries (int& x, int& y) { // checks and corrects the terminal boundaries - int term_width = app->getDesktopWidth(); - int term_height = app->getDesktopHeight(); + int term_width = int(app->getDesktopWidth()); + int term_height = int(app->getDesktopHeight()); if ( x < 0 ) x = 0; @@ -152,9 +152,9 @@ int main (int argc, char* argv[]) app = &TermApp; // Get screen dimension - xmax = TermApp.getDesktopWidth() - 1; - ymax = TermApp.getDesktopHeight() - 1; - finalcut::FString line(xmax + 1, '-'); + xmax = int(TermApp.getDesktopWidth() - 1); + ymax = int(TermApp.getDesktopHeight() - 1); + finalcut::FString line(std::size_t(xmax) + 1, '-'); // Place the cursor in the upper left corner TermApp.setTermXY(0,0); diff --git a/examples/scrollview.cpp b/examples/scrollview.cpp index 451cf1f7..505f7a08 100644 --- a/examples/scrollview.cpp +++ b/examples/scrollview.cpp @@ -40,7 +40,7 @@ class Scrollview : public finalcut::FScrollView ~Scrollview (); // Mutator - void setScrollSize (int, int); + void setScrollSize (std::size_t, std::size_t); private: // Disable copy constructor @@ -83,9 +83,9 @@ Scrollview::Scrollview (finalcut::FWidget* parent) { // Sets the navigation button geometry go_east.setGeometry (1, 1, 5, 1); - go_south.setGeometry (getScrollWidth() - 5, 1, 5, 1); - go_west.setGeometry (getScrollWidth() - 5, getScrollHeight() - 2, 5, 1); - go_north.setGeometry (1, getScrollHeight() - 2, 5, 1); + go_south.setGeometry (int(getScrollWidth()) - 5, 1, 5, 1); + go_west.setGeometry (int(getScrollWidth()) - 5, int(getScrollHeight()) - 2, 5, 1); + go_north.setGeometry (1, int(getScrollHeight()) - 2, 5, 1); // Add scroll function callbacks to the buttons go_east.addCallback @@ -118,12 +118,12 @@ Scrollview::~Scrollview() { } //---------------------------------------------------------------------- -void Scrollview::setScrollSize (int width, int height) +void Scrollview::setScrollSize (std::size_t width, std::size_t height) { FScrollView::setScrollSize (width, height); - go_south.setPos (width - 5, 1); - go_west.setPos (width - 5, height - 1); - go_north.setPos (1, height - 1); + go_south.setPos (int(width) - 5, 1); + go_west.setPos (int(width) - 5, int(height) - 1); + go_north.setPos (1, int(height) - 1); } //---------------------------------------------------------------------- @@ -135,11 +135,11 @@ void Scrollview::draw() setColor (wc.label_inactive_fg, wc.dialog_bg); clearArea(); - for (int y = 0; y < getScrollHeight(); y++) + for (int y = 0; y < int(getScrollHeight()); y++) { setPrintPos (1, 1 + y); - for (int x = 0; x < getScrollWidth(); x++) + for (int x = 0; x < int(getScrollWidth()); x++) print (32 + ((x + y) % 0x5f)); } @@ -152,7 +152,7 @@ void Scrollview::draw() //---------------------------------------------------------------------- void Scrollview::cb_go_east (finalcut::FWidget*, data_ptr) { - scrollToX (getScrollWidth() - getViewportWidth() + 1); + scrollToX (int(getScrollWidth() - getViewportWidth()) + 1); go_south.setFocus(); go_east.redraw(); go_south.redraw(); @@ -161,7 +161,7 @@ void Scrollview::cb_go_east (finalcut::FWidget*, data_ptr) //---------------------------------------------------------------------- void Scrollview::cb_go_south (finalcut::FWidget*, data_ptr) { - scrollToY (getScrollHeight() - getViewportHeight() + 1); + scrollToY (int(getScrollHeight() - getViewportHeight()) + 1); go_west.setFocus(); go_south.redraw(); go_west.redraw(); diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index c6b3df2a..2cd7b4cc 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -77,9 +77,9 @@ AttribDlg::AttribDlg (finalcut::FWidget* parent) + finalcut::FString(getTermType()) + ")"); - next_button.setGeometry(getWidth() - 13, getHeight() - 4, 10, 1); + next_button.setGeometry(int(getWidth()) - 13, int(getHeight()) - 4, 10, 1); next_button.addAccelerator(finalcut::fc::Fkey_right); - back_button.setGeometry(getWidth() - 25, getHeight() - 4, 10, 1); + back_button.setGeometry(int(getWidth()) - 25, int(getHeight()) - 4, 10, 1); back_button.addAccelerator(finalcut::fc::Fkey_left); // Add function callbacks @@ -155,8 +155,8 @@ void AttribDlg::cb_back (finalcut::FWidget*, data_ptr) //---------------------------------------------------------------------- void AttribDlg::adjustSize() { - int x = ((getParentWidget()->getWidth() - getWidth()) / 2); - int y = ((getParentWidget()->getHeight() - getHeight()) / 2) + 1; + int x = int((getParentWidget()->getWidth() - getWidth()) / 2); + int y = int((getParentWidget()->getHeight() - getHeight()) / 2) + 1; if ( x < 1 ) x = 1; @@ -165,8 +165,8 @@ void AttribDlg::adjustSize() y = 1; setGeometry(x, y, 69, 21, false); - next_button.setGeometry(getWidth() - 13, getHeight() - 4, 10, 1, false); - back_button.setGeometry(getWidth() - 25, getHeight() - 4, 10, 1, false); + next_button.setGeometry(int(getWidth()) - 13, int(getHeight()) - 4, 10, 1, false); + back_button.setGeometry(int(getWidth()) - 25, int(getHeight()) - 4, 10, 1, false); finalcut::FDialog::adjustSize(); } @@ -399,7 +399,7 @@ void AttribDemo::draw() // test alternate character set printAltCharset(); - for (int y = 0; y < getParentWidget()->getHeight() - 7; y++) + for (int y = 0; y < int(getParentWidget()->getHeight()) - 7; y++) { setPrintPos (1, 2 + y); diff --git a/examples/timer.cpp b/examples/timer.cpp index 7cef7206..c189e2e9 100644 --- a/examples/timer.cpp +++ b/examples/timer.cpp @@ -72,7 +72,7 @@ void Timer::onTimer (finalcut::FTimerEvent* ev) bool is_last_line = false; int timer_id = ev->timerId(); - if ( getPrintPos().getY() == getDesktopHeight() ) + if ( getPrintPos().getY() == int(getDesktopHeight()) ) is_last_line = true; setColor (short(1 + timer_id), finalcut::fc::Default); diff --git a/examples/transparent.cpp b/examples/transparent.cpp index 09ce1df7..3672c440 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -105,7 +105,7 @@ void Transparent::draw() finalcut::FString line(getClientWidth(), wchar_t('.')); - for (int n = 1; n <= getClientHeight(); n++) + for (int n = 1; n <= int(getClientHeight()); n++) { setPrintPos (2, 2 + n); print(line); @@ -264,7 +264,7 @@ void MainWindow::onShow (finalcut::FShowEvent*) void MainWindow::onTimer (finalcut::FTimerEvent*) { wchar_t first_Char[2]; - uInt length = line1.getLength(); + std::size_t length = line1.getLength(); first_Char[0] = line1[0]; first_Char[1] = line2[0]; line1 = line1.right(length - 1) + first_Char[0]; diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 92da5836..d2f5c045 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -297,7 +297,7 @@ Treeview::~Treeview() // destructor //---------------------------------------------------------------------- void Treeview::adjustSize() { - int h = getParentWidget()->getHeight() - 4; + std::size_t h = getParentWidget()->getHeight() - 4; setHeight (h, false); int X = int((getParentWidget()->getWidth() - getWidth()) / 2); @@ -309,7 +309,7 @@ void Treeview::adjustSize() if ( initialized ) { listView.setHeight (getHeight() - 6, false); - Quit.setY(getHeight() - 4); + Quit.setY(int(getHeight()) - 4); } finalcut::FDialog::adjustSize(); diff --git a/examples/ui.cpp b/examples/ui.cpp index 4ede5747..f0b01a2e 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -780,7 +780,7 @@ void MyDialog::initWidgetsCallbacks() //---------------------------------------------------------------------- void MyDialog::adjustSize() { - int h = getParentWidget()->getHeight() - 4; + std::size_t h = getParentWidget()->getHeight() - 4; setHeight (h, false); int X = int((getParentWidget()->getWidth() - getWidth()) / 2); @@ -830,8 +830,8 @@ void MyDialog::cb_about (finalcut::FWidget*, data_ptr) //---------------------------------------------------------------------- void MyDialog::cb_terminfo (finalcut::FWidget*, data_ptr) { - int x = getDesktopWidth(); - int y = getDesktopHeight(); + std::size_t x = getDesktopWidth(); + std::size_t y = getDesktopHeight(); finalcut::FMessageBox info1 \ ( "Environment" @@ -961,10 +961,10 @@ void MyDialog::cb_updateNumber (finalcut::FWidget* widget, data_ptr data) finalcut::FListBox* list = static_cast(widget); finalcut::FLabel* num = static_cast(data); int select_num = 0; - uInt count = list->getCount(); + std::size_t count = list->getCount(); - for (uInt n = 1; n <= count; n++) - if ( list->isSelected(int(n)) ) + for (std::size_t n = 1; n <= count; n++) + if ( list->isSelected(n) ) select_num++; num->clear(); @@ -1006,7 +1006,7 @@ void MyDialog::cb_view (finalcut::FWidget*, data_ptr data) view->setGeometry ( 1 + int((getRootWidget()->getWidth() - 60) / 2), int(getRootWidget()->getHeight() / 6), 60, - int(getRootWidget()->getHeight() * 3 / 4) ); + getRootWidget()->getHeight() * 3 / 4 ); view->setResizeable(); std::string line = ""; diff --git a/examples/watch.cpp b/examples/watch.cpp index 0e00d924..ac144156 100644 --- a/examples/watch.cpp +++ b/examples/watch.cpp @@ -83,7 +83,7 @@ Watch::Watch (FWidget* parent) , quit_btn(L"&Quit", this) { setText ("Watch"); - int pw = getParentWidget()->getWidth(); + int pw = int(getParentWidget()->getWidth()); setGeometry (1 + (pw - 22) / 2, 3, 22, 13); // Labels @@ -198,7 +198,7 @@ void Watch::cb_seconds (finalcut::FWidget*, data_ptr) //---------------------------------------------------------------------- void Watch::adjustSize() { - int pw = getParentWidget()->getWidth(); + int pw = int(getParentWidget()->getWidth()); setX (1 + (pw - 22) / 2, false); finalcut::FDialog::adjustSize(); } diff --git a/examples/windows.cpp b/examples/windows.cpp index cbf7cd7e..4e2005a0 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -86,7 +86,7 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent) right_arrow.setForegroundColor (wc.label_inactive_fg); right_arrow.setEmphasis(); right_arrow.ignorePadding(); - right_arrow.setGeometry (getWidth() - 1, 2, 1, 1); + right_arrow.setGeometry (int(getWidth()) - 1, 2, 1, 1); top_left_label = "menu"; top_left_label.setForegroundColor (wc.label_inactive_fg); @@ -97,7 +97,7 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent) top_right_label.setAlignment (finalcut::fc::alignRight); top_right_label.setForegroundColor (wc.label_inactive_fg); top_right_label.setEmphasis(); - top_right_label.setGeometry (getClientWidth() - 5, 1, 6, 1); + top_right_label.setGeometry (int(getClientWidth()) - 5, 1, 6, 1); finalcut::FString bottom_label_text = "resize\n" "corner\n"; @@ -131,9 +131,9 @@ void SmallWindow::adjustSize() } finalcut::FDialog::adjustSize(); - right_arrow.setGeometry (getWidth() - 1, 2, 1, 1); - top_right_label.setGeometry (getClientWidth() - 5, 1, 6, 1); - bottom_label.setGeometry (1, getClientHeight() - 2, getClientWidth(), 3); + right_arrow.setGeometry (int(getWidth()) - 1, 2, 1, 1); + top_right_label.setGeometry (int(getClientWidth()) - 5, 1, 6, 1); + bottom_label.setGeometry (1, int(getClientHeight()) - 2, getClientWidth(), 3); } //---------------------------------------------------------------------- @@ -368,12 +368,12 @@ void Window::activateWindow (finalcut::FDialog* win) void Window::adjustSize() { std::vector::const_iterator iter, first; - int w = getRootWidget()->getWidth() - , h = getRootWidget()->getHeight() - , X = int(1 + (w - 40) / 2) + std::size_t w = getRootWidget()->getWidth(); + std::size_t h = getRootWidget()->getHeight(); + int X = int(1 + (w - 40) / 2) , Y = int(1 + (h - 22) / 2) - , dx = ( w > 80 ) ? (w - 80) / 2 : 0 - , dy = ( h > 24 ) ? (h - 24) / 2 : 0; + , dx = ( w > 80 ) ? int(w - 80) / 2 : 0 + , dy = ( h > 24 ) ? int(h - 24) / 2 : 0; if ( Y < 2 ) Y = 2; @@ -436,10 +436,10 @@ void Window::cb_createWindows (finalcut::FWidget*, data_ptr) { std::vector::const_iterator iter, first; iter = first = windows.begin(); - int w = getRootWidget()->getWidth() - , h = getRootWidget()->getHeight() - , dx = ( w > 80 ) ? (w - 80) / 2 : 0 - , dy = ( h > 24 ) ? (h - 24) / 2 : 0; + std::size_t w = getRootWidget()->getWidth(); + std::size_t h = getRootWidget()->getHeight(); + int dx = ( w > 80 ) ? int(w - 80) / 2 : 0; + int dy = ( h > 24 ) ? int(h - 24) / 2 : 0; while ( iter != windows.end() ) { diff --git a/logo/svg/finalcut-logo.svg b/logo/svg/finalcut-logo.svg index ee9a0d32..5426d960 100644 --- a/logo/svg/finalcut-logo.svg +++ b/logo/svg/finalcut-logo.svg @@ -247,12 +247,12 @@ y="93.333893" transform="scale(0.95126779,1.0512287)" id="text37-5" - style="font-size:96px;font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0;word-spacing:0;writing-mode:lr-tb;text-anchor:start;fill:#9f9f9f;fill-opacity:0.6206896;fill-rule:evenodd;stroke:none;font-family:FreeSans;-inkscape-font-specification:FreeSans Semi-Bold"> + style="font-size:96px;font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0;word-spacing:0;writing-mode:lr-tb;text-anchor:start;fill:#9f9f9f;fill-opacity:0.6206896;fill-rule:evenodd;stroke:none;font-family:FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif"> FINAL CUT + style="font-size:96px;font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#9f9f9f;fill-opacity:0.6206896;stroke:none;font-family:FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif">FINAL CUT + style="font-size:96px;font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0;word-spacing:0;writing-mode:lr-tb;text-anchor:start;fill:#083c99;fill-opacity:0.88747732;fill-rule:evenodd;stroke:none;font-family:FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif"> FINAL CUT + style="font-size:96px;font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#083c99;fill-opacity:0.88747732;stroke:none;font-family:FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif">FINAL CUT diff --git a/src/Makefile.clang b/src/Makefile.clang index a86ff5ee..4ee741bf 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -62,7 +62,7 @@ INCLUDE_HEADERS = \ # compiler parameter CXX = clang++ -CCXFLAGS = $(OPTIMIZE) $(PROFILE) -DCOMPILE_FINAL_CUT $(DEBUG) $(VER) $(GPM) -march=x86-64 -frtti -fexceptions +CCXFLAGS = $(OPTIMIZE) $(PROFILE) -DCOMPILE_FINAL_CUT $(DEBUG) $(VER) $(GPM) -fexceptions MAKEFILE = -f Makefile.clang LDFLAGS = $(TERMCAP) -lgpm INCLUDES = -Iinclude @@ -148,7 +148,7 @@ all: dep $(OBJS) $(LIB): all debug: - $(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -Wall -Wextra -Wpedantic -Weverything -Wpadded" + $(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -Wall -Wextra -Wpedantic -Weverything -Wpadded -Wno-reserved-id-macro" profile: $(MAKE) $(MAKEFILE) PROFILE="-pg" diff --git a/src/Makefile.gcc b/src/Makefile.gcc index 60a1c15f..d0f3de3c 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -62,7 +62,7 @@ INCLUDE_HEADERS = \ # compiler parameter CXX = g++ -CCXFLAGS = $(OPTIMIZE) $(PROFILE) -DCOMPILE_FINAL_CUT $(DEBUG) $(VER) $(GPM) -march=x86-64 -frtti -fexceptions +CCXFLAGS = $(OPTIMIZE) $(PROFILE) -DCOMPILE_FINAL_CUT $(DEBUG) $(VER) $(GPM) -fexceptions MAKEFILE = -f Makefile.gcc LDFLAGS = $(TERMCAP) -lgpm INCLUDES = -Iinclude diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 5e45b60c..c7ae8689 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -263,7 +263,7 @@ void FButton::setText (const FString& txt) //---------------------------------------------------------------------- void FButton::hide() { - int s, f, size; + std::size_t s, f, size; short fg, bg; char* blank; FWidget* parent_widget = getParentWidget(); @@ -285,12 +285,12 @@ void FButton::hide() f = isFlat() ? 1 : 0; size = getWidth() + s + (f << 1); - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -298,12 +298,12 @@ void FButton::hide() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < getHeight() + s + (f << 1); y++) + for (std::size_t y = 0; y < getHeight() + s + (f << 1); y++) { - setPrintPos (1 - f, 1 + y - f); + setPrintPos (1 - int(f), 1 + int(y - f)); print (blank); } @@ -489,14 +489,12 @@ void FButton::getButtonState() //---------------------------------------------------------------------- uChar FButton::getHotkey() { - uInt length; - if ( text.isEmpty() ) return 0; - length = text.getLength(); + std::size_t length = text.getLength(); - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { try { @@ -544,14 +542,16 @@ inline void FButton::detectHotkey() } //---------------------------------------------------------------------- -int FButton::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) +int FButton::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign int pos = -1; wchar_t* txt = src; - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { if ( i < length && txt[i] == L'&' && pos == -1 ) { @@ -582,7 +582,7 @@ inline int FButton::clickAnimationIndent (FWidget* parent_widget) setColor ( parent_widget->getForegroundColor() , parent_widget->getBackgroundColor() ); - for (int y = 1; y <= getHeight(); y++) + for (int y = 1; y <= int(getHeight()); y++) { setPrintPos (1, y); print (' '); // clear one left █ @@ -602,12 +602,12 @@ inline void FButton::clearRightMargin (FWidget* parent_widget) setColor ( parent_widget->getForegroundColor() , parent_widget->getBackgroundColor() ); - for (int y = 1; y <= getHeight(); y++) + for (int y = 1; y <= int(getHeight()); y++) { if ( isMonochron() ) setReverse(true); // Light background - setPrintPos (1 + getWidth(), y); + setPrintPos (1 + int(getWidth()), y); print (' '); // clear right if ( is.active && isMonochron() ) @@ -622,7 +622,7 @@ inline void FButton::drawMarginLeft() setColor (getForegroundColor(), button_bg); - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { setPrintPos (1 + indent, 1 + y); @@ -638,9 +638,9 @@ inline void FButton::drawMarginRight() { // Print right margin - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { - setPrintPos (getWidth() + indent, 1 + y); + setPrintPos (int(getWidth()) + indent, 1 + y); if ( isMonochron() && is.active_focus && y == vcenter_offset ) print (fc::BlackLeftPointingPointer); // ◄ @@ -661,15 +661,15 @@ inline void FButton::drawTopBottomBackground() { setPrintPos (2 + indent, 1 + y); - for (int x = 1; x < getWidth() - 1; x++) + for (std::size_t x = 1; x < getWidth() - 1; x++) print (space); // █ } - for (int y = vcenter_offset + 1; y < getHeight(); y++) + for (int y = vcenter_offset + 1; y < int(getHeight()); y++) { setPrintPos (2 + indent, 1 + y); - for (int x = 1; x < getWidth() - 1; x++) + for (std::size_t x = 1; x < getWidth() - 1; x++) print (space); // █ } } @@ -678,7 +678,7 @@ inline void FButton::drawTopBottomBackground() inline void FButton::drawButtonTextLine (wchar_t button_text[]) { int pos; - center_offset = int((getWidth() - txtlength - 1) / 2); + center_offset = int((int(getWidth()) - txtlength - 1) / 2); setPrintPos (2 + indent, 1 + vcenter_offset); setColor (button_fg, button_bg); @@ -700,7 +700,7 @@ inline void FButton::drawButtonTextLine (wchar_t button_text[]) setBold(); for ( int z = 0 - ; pos < center_offset + txtlength && z < getWidth() - 2 + ; pos < center_offset + txtlength && z < int(getWidth()) - 2 ; z++, pos++) { if ( (z == hotkeypos) && is.active ) @@ -729,17 +729,17 @@ inline void FButton::drawButtonTextLine (wchar_t button_text[]) } } - if ( txtlength >= getWidth() - 1 ) + if ( txtlength >= int(getWidth()) - 1 ) { // Print ellipsis - setPrintPos (getWidth() + indent - 2, 1); + setPrintPos (int(getWidth()) + indent - 2, 1); print (L".."); } if ( is.active_focus && (isMonochron() || getMaxColor() < 16) ) unsetBold(); - for (pos = center_offset + txtlength; pos < getWidth() - 2; pos++) + for (pos = center_offset + txtlength; pos < int(getWidth()) - 2; pos++) print (space); // █ } diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index d1c3bef2..030c7e24 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -189,7 +189,7 @@ bool FButtonGroup::hasCheckedButton() const //---------------------------------------------------------------------- void FButtonGroup::hide() { - int size; + std::size_t size; short fg, bg; char* blank; FWidget::hide(); @@ -223,12 +223,12 @@ void FButtonGroup::hide() setColor (fg, bg); size = getWidth(); - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -236,10 +236,10 @@ void FButtonGroup::hide() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { FWidget::setPrintPos (1, 1 + y); print (blank); @@ -443,14 +443,12 @@ void FButtonGroup::cb_buttonToggled (FWidget* widget, data_ptr) //---------------------------------------------------------------------- uChar FButtonGroup::getHotkey() { - uInt length; - if ( text.isEmpty() ) return 0; - length = text.getLength(); + std::size_t length = text.getLength(); - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { try { @@ -512,7 +510,7 @@ void FButtonGroup::drawLabel() return; FString txt = " " + text + " "; - uInt length = txt.getLength(); + std::size_t length = txt.getLength(); try { @@ -527,7 +525,7 @@ void FButtonGroup::drawLabel() wchar_t* src = const_cast(txt.wc_str()); wchar_t* dest = const_cast(LabelText); unsetViewportPrint(); - hotkeypos = getHotkeyPos(src, dest, uInt(length)); + hotkeypos = getHotkeyPos(src, dest, length); if ( hotkeypos != -1 ) length--; @@ -567,7 +565,9 @@ void FButtonGroup::init() } //---------------------------------------------------------------------- -int FButtonGroup::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) +int FButtonGroup::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign @@ -590,7 +590,9 @@ int FButtonGroup::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) } //---------------------------------------------------------------------- -void FButtonGroup::drawText (wchar_t LabelText[], int hotkeypos, uInt length) +void FButtonGroup::drawText ( wchar_t LabelText[] + , int hotkeypos + , std::size_t length ) { bool isActive = ((flags & fc::active) != 0); bool isNoUnderline = ((flags & fc::no_underline) != 0); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 83a38a47..f2da97aa 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -213,11 +213,14 @@ void FDialog::setPos (int x, int y, bool) return; } - width = getWidth(); - height = getHeight(); + width = int(getWidth()); + height = int(getHeight()); // Avoid to move widget completely outside the terminal - if ( x + width <= 1 || x > getMaxWidth() || y < 1 || y > getMaxHeight() ) + if ( x + width <= 1 + || x > int(getMaxWidth()) + || y < 1 + || y > int(getMaxHeight()) ) { setPos_error = true; return; @@ -256,7 +259,7 @@ void FDialog::setPos (int x, int y, bool) { if ( dy > 0 ) restoreVTerm ( old_x + width + rsw - dx, old_y - , dx, getHeight() + bsh - dy ); + , dx, height + bsh - dy ); else restoreVTerm ( old_x + width + rsw - dx, old_y + std::abs(dy) , dx, height + bsh - std::abs(dy)); @@ -321,7 +324,7 @@ inline bool FDialog::moveRight (int n) } //---------------------------------------------------------------------- -void FDialog::setSize (int w, int h, bool adjust) +void FDialog::setSize (std::size_t w, std::size_t h, bool adjust) { setSize_error = false; @@ -339,10 +342,10 @@ void FDialog::setSize (int w, int h, bool adjust) int x = getTermX() , y = getTermY() - , old_width = getWidth() - , old_height = getHeight() - , dw = old_width - w - , dh = old_height - h; + , old_width = int(getWidth()) + , old_height = int(getHeight()) + , dw = old_width - int(w) + , dh = old_height - int(h); const FPoint& shadow = getShadow(); int rsw = shadow.getX(); // right shadow width; int bsh = shadow.getY(); // bottom shadow height @@ -362,10 +365,10 @@ void FDialog::setSize (int w, int h, bool adjust) // restoring the non-covered terminal areas if ( dw > 0 ) - restoreVTerm (x + w + rsw, y, dw, h + bsh + dh); // restore right + restoreVTerm (x + int(w) + rsw, y, dw, int(h) + bsh + dh); // restore right if ( dh > 0 ) - restoreVTerm (x, y + h + bsh, w + rsw + dw, dh); // restore bottom + restoreVTerm (x, y + int(h) + bsh, int(w) + rsw + dw, dh); // restore bottom redraw(); @@ -406,17 +409,17 @@ bool FDialog::reduceHeight (int n) if ( ! isResizeable() ) return false; - setSize (getWidth(), getHeight() - n); + setSize (getWidth(), getHeight() - std::size_t(n)); return ! setSize_error; } //---------------------------------------------------------------------- bool FDialog::expandHeight (int n) { - if ( ! isResizeable() || getHeight() + getY() > getMaxHeight() ) + if ( ! isResizeable() || getHeight() + std::size_t(getY()) > getMaxHeight() ) return false; - setSize (getWidth(), getHeight() + n); + setSize (getWidth(), getHeight() + std::size_t(n)); return ! setSize_error; } @@ -426,17 +429,17 @@ bool FDialog::reduceWidth (int n) if ( ! isResizeable() ) return false; - setSize (getWidth() - n, getHeight()); + setSize (getWidth() - std::size_t(n), getHeight()); return ! setSize_error; } //---------------------------------------------------------------------- bool FDialog::expandWidth (int n) { - if ( ! isResizeable() || getWidth() + getX() > getMaxWidth() ) + if ( ! isResizeable() || getWidth() + std::size_t(getX()) > getMaxWidth() ) return false; - setSize (getWidth() + n, getHeight()); + setSize (getWidth() + std::size_t(n), getHeight()); return ! setSize_error; } @@ -515,6 +518,8 @@ void FDialog::onKeyPress (FKeyEvent* ev) //---------------------------------------------------------------------- void FDialog::onMouseDown (FMouseEvent* ev) { + int width = int(getWidth()); + mouseStates ms = { ev->getX(), @@ -532,7 +537,7 @@ void FDialog::onMouseDown (FMouseEvent* ev) raiseActivateDialog(); if ( ms.mouse_x >= 4 - && ms.mouse_x <= getWidth() - ms.zoom_btn + && ms.mouse_x <= width - int(ms.zoom_btn) && ms.mouse_y == 1 ) titlebar_click_pos.setPoint (ev->getTermX(), ev->getTermY()); else @@ -560,13 +565,13 @@ void FDialog::onMouseDown (FMouseEvent* ev) // Click on titlebar: just activate if ( ev->getButton() == fc::RightButton && ms.mouse_x >= 4 - && ms.mouse_x <= getWidth() + && ms.mouse_x <= width && ms.mouse_y == 1 ) activateDialog(); // Click on titlebar: lower + activate if ( ev->getButton() == fc::MiddleButton - && ms.mouse_x >= 4 && ms.mouse_x <= getWidth() + && ms.mouse_x >= 4 && ms.mouse_x <= width && ms.mouse_y == 1 ) lowerActivateDialog(); } @@ -589,9 +594,9 @@ void FDialog::onMouseUp (FMouseEvent* ev) , titlebar_y = titlebar_click_pos.getY(); if ( ! titlebar_click_pos.isNull() - && titlebar_x > getTermX() + 3 - && titlebar_x < getTermX() + getWidth() - && titlebar_y == getTermY() ) + && titlebar_x > int(getTermX()) + 3 + && titlebar_x < getTermX() + int(getWidth()) + && titlebar_y == int(getTermY()) ) { FPoint deltaPos = ms.termPos - titlebar_click_pos; move (deltaPos); @@ -693,7 +698,7 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev) } else if ( isResizeable() && ms.mouse_x >= 4 - && ms.mouse_x <= getWidth() - ms.zoom_btn + && ms.mouse_x <= int(getWidth() - ms.zoom_btn) && ms.mouse_y == 1 ) { // Double click on titlebar @@ -828,7 +833,7 @@ void FDialog::draw() clearArea(); drawBorder(); drawTitleBar(); - setCursorPos(2, getHeight() - 1); + setCursorPos(2, int(getHeight()) - 1); if ( (flags & fc::shadow) != 0 ) drawDialogShadow(); @@ -1009,9 +1014,9 @@ void FDialog::initCloseMenuItem (FMenu* menu) void FDialog::drawBorder() { int x1 = 1 - , x2 = 1 + getWidth() - 1 + , x2 = 1 + int(getWidth()) - 1 , y1 = 2 - , y2 = 1 + getHeight() - 1; + , y2 = 1 + int(getHeight()) - 1; if ( (getMoveSizeWidget() == this || ! resize_click_pos.isNull() ) && ! isZoomed() ) @@ -1035,7 +1040,7 @@ void FDialog::drawBorder() // Lower left corner border ⎣ print (fc::NF_border_corner_lower_left); - for (int x = 1; x < getWidth() - 1; x++) // low line _ + for (std::size_t x = 1; x < getWidth() - 1; x++) // low line _ print (fc::NF_border_line_bottom); setPrintPos (x2, y2); @@ -1193,10 +1198,11 @@ inline void FDialog::drawZoomedButton() void FDialog::drawTextBar() { // Fill with spaces (left of the title) - int center_offset - , zoom_btn - , length - , x; + std::size_t center_offset + , width + , zoom_btn + , length + , x; if ( getMaxColor() < 16 ) setBold(); @@ -1206,9 +1212,10 @@ void FDialog::drawTextBar() else setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg); + width = std::size_t(getWidth()); zoom_btn = getZoomButtonWidth(); - length = int(tb_text.getLength()); - center_offset = int((getWidth() - length - MENU_BTN - zoom_btn) / 2); + length = tb_text.getLength(); + center_offset = (width - length - MENU_BTN - zoom_btn) / 2; for (x = 1; x <= center_offset; x++) print (' '); @@ -1216,18 +1223,18 @@ void FDialog::drawTextBar() // Print title bar text if ( ! tb_text.isEmpty() ) { - if ( length <= getWidth() - MENU_BTN - zoom_btn ) + if ( length <= width - MENU_BTN - zoom_btn ) print (tb_text); else { // Print ellipsis - print (tb_text.left(getWidth() - MENU_BTN - zoom_btn - 2)); + print (tb_text.left(width - MENU_BTN - zoom_btn - 2)); print (".."); } } // Fill the rest of the bar - for ( ; x + 1 + length < getWidth() - zoom_btn - 1; x++) + for ( ; x + 1 + length < width - zoom_btn - 1; x++) print (' '); if ( getMaxColor() < 16 ) @@ -1358,7 +1365,7 @@ void FDialog::setZoomItem() } //---------------------------------------------------------------------- -inline int FDialog::getZoomButtonWidth() +inline std::size_t FDialog::getZoomButtonWidth() { if ( ! isResizeable() ) return 0; @@ -1382,7 +1389,7 @@ inline void FDialog::deactivateZoomButton() //---------------------------------------------------------------------- inline void FDialog::activateZoomButton (mouseStates& ms) { - if ( ms.mouse_x <= getWidth() - ms.zoom_btn + if ( ms.mouse_x <= int(getWidth() - ms.zoom_btn) || ms.mouse_y != 1 ) return; @@ -1396,8 +1403,8 @@ inline void FDialog::leaveZoomButton (mouseStates& ms) { bool zoom_button_pressed_before = zoom_button_pressed; - if ( ms.mouse_x > getWidth() - ms.zoom_btn - && ms.mouse_x <= getWidth() + if ( ms.mouse_x > int(getWidth() - ms.zoom_btn) + && ms.mouse_x <= int(getWidth()) && ms.mouse_y == 1 && zoom_button_active ) zoom_button_pressed = true; @@ -1411,7 +1418,7 @@ inline void FDialog::leaveZoomButton (mouseStates& ms) //---------------------------------------------------------------------- void FDialog::pressZoomButton (mouseStates& ms) { - if ( ms.mouse_x <= getWidth() - ms.zoom_btn + if ( ms.mouse_x <= int(getWidth() - ms.zoom_btn) || ms.mouse_y != 1 || ! zoom_button_pressed ) return; @@ -1555,9 +1562,9 @@ bool FDialog::isLowerRightResizeCorner (mouseStates& ms) // x // -----xx - if ( (ms.mouse_x == getWidth() && ms.mouse_y == getHeight() - 1) - || ( ( ms.mouse_x == getWidth() - 1 - || ms.mouse_x == getWidth() ) && ms.mouse_y == getHeight() ) ) + if ( (ms.mouse_x == int(getWidth()) && ms.mouse_y == int(getHeight()) - 1) + || ( ( ms.mouse_x == int(getWidth()) - 1 + || ms.mouse_x == int(getWidth()) ) && ms.mouse_y == int(getHeight()) ) ) { return true; } @@ -1582,7 +1589,7 @@ void FDialog::resizeMouseDown (mouseStates& ms) FPoint deltaPos = ms.termPos - lower_right_pos; int w = lower_right_pos.getX() + deltaPos.getX() - getTermX() + 1; int h = lower_right_pos.getY() + deltaPos.getY() - getTermY() + 1; - setSize (w, h); + setSize (std::size_t(w), std::size_t(h)); } else drawBorder(); @@ -1615,17 +1622,17 @@ void FDialog::resizeMouseUpMove (mouseStates& ms, bool mouse_up) int w, h; FPoint deltaPos = ms.termPos - resize_click_pos; - if ( x2 - x2_offset <= getMaxWidth() ) + if ( x2 - x2_offset <= int(getMaxWidth()) ) w = resize_click_pos.getX() + deltaPos.getX() - getTermX() + 1; else - w = getMaxWidth() - getTermX() + x2_offset + 1; + w = int(getMaxWidth()) - getTermX() + x2_offset + 1; - if ( y2 - y2_offset <= getMaxHeight() ) + if ( y2 - y2_offset <= int(getMaxHeight()) ) h = resize_click_pos.getY() + deltaPos.getY() - getTermY() + 1; else - h = getMaxHeight() - getTermY() + y2_offset + 1; + h = int(getMaxHeight()) - getTermY() + y2_offset + 1; - setSize (w, h); + setSize (std::size_t(w), std::size_t(h)); } if ( mouse_up ) diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 2b56c952..02094097 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -337,11 +337,10 @@ const FString FFileDialog::fileSaveChooser ( FWidget* parent //---------------------------------------------------------------------- void FFileDialog::adjustSize() { - int h - , X - , Y - , max_width - , max_height; + int X, Y; + std::size_t max_width; + std::size_t max_height; + std::size_t h; FWidget* root_widget = getRootWidget(); if ( root_widget ) @@ -369,9 +368,9 @@ void FFileDialog::adjustSize() Y = 1 + int((max_height - getHeight()) / 3); setPos(X, Y, false); filebrowser.setHeight (h - 8, false); - hidden.setY (h - 4, false); - cancel.setY (h - 4, false); - open.setY (h - 4, false); + hidden.setY (int(h) - 4, false); + cancel.setY (int(h) - 4, false); + open.setY (int(h) - 4, false); FDialog::adjustSize(); printPath(directory); } @@ -381,8 +380,8 @@ void FFileDialog::adjustSize() //---------------------------------------------------------------------- void FFileDialog::init() { - static const int w = 42; - static const int h = 15; + static const std::size_t w = 42; + static const std::size_t h = 15; int x, y; FWidget* parent_widget; @@ -751,7 +750,7 @@ int FFileDialog::changeDir (const FString& dirname) filename.setText('/'); else if ( ! dir_entries.empty() ) { - int i = 1; + std::size_t i = 1; std::vector::const_iterator iter, last; const char* const baseName = \ basename(C_STR(lastdir.c_str())); @@ -872,14 +871,14 @@ void FFileDialog::cb_processActivate (FWidget*, data_ptr) //---------------------------------------------------------------------- void FFileDialog::cb_processRowChanged (FWidget*, data_ptr) { - const int n = filebrowser.currentItem(); + const std::size_t n = filebrowser.currentItem(); if ( n == 0 ) return; - const FString& name = dir_entries[uLong(n - 1)].name; + const FString& name = dir_entries[n - 1].name; - if ( dir_entries[uLong(n - 1)].directory ) + if ( dir_entries[n - 1].directory ) filename.setText( name + '/' ); else filename.setText( name ); diff --git a/src/fkeyboard.cpp b/src/fkeyboard.cpp index 6d4398bb..4cf6008a 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -238,9 +238,9 @@ inline int FKeyboard::getTermcapKey() for (int i = 0; keymap[i].tname[0] != 0; i++) { char* k = keymap[i].string; - int len = ( k ) ? int(std::strlen(k)) : 0; + std::size_t len = ( k ) ? std::strlen(k) : 0; - if ( k && std::strncmp(k, fifo_buf, uInt(len)) == 0 ) // found + if ( k && std::strncmp(k, fifo_buf, len) == 0 ) // found { std::size_t n; @@ -268,9 +268,9 @@ inline int FKeyboard::getMetaKey() for (int i = 0; fc::Fmetakey[i].string[0] != 0; i++) { char* kmeta = fc::Fmetakey[i].string; // The string is never null - int len = int(std::strlen(kmeta)); + std::size_t len = std::strlen(kmeta); - if ( std::strncmp(kmeta, fifo_buf, uInt(len)) == 0 ) // found + if ( std::strncmp(kmeta, fifo_buf, len) == 0 ) // found { std::size_t n; @@ -303,8 +303,8 @@ inline int FKeyboard::getSingleKey() uChar firstchar = uChar(fifo_buf[0]); std::size_t n; - int keycode, len; - len = 1; + std::size_t len = 1; + int keycode; // Look for a utf-8 character if ( utf8_input && (firstchar & 0xc0) == 0xc0 ) @@ -318,7 +318,7 @@ inline int FKeyboard::getSingleKey() else if ( (firstchar & 0xf8) == 0xf0 ) len = 4; - for (int i = 0; i < len ; i++) + for (std::size_t i = 0; i < len ; i++) utf8char[i] = char(fifo_buf[i] & 0xff); keycode = UTF8decode(utf8char); diff --git a/src/flabel.cpp b/src/flabel.cpp index 9ad63be0..a50bce71 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -242,7 +242,7 @@ void FLabel::setText (const FString& txt) void FLabel::hide() { short fg, bg; - int size; + std::size_t size; char* blank; FWidget* parent_widget = getParentWidget(); @@ -262,12 +262,12 @@ void FLabel::hide() setColor (fg, bg); size = getWidth(); - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -275,9 +275,9 @@ void FLabel::hide() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[getWidth()] = '\0'; - setPrintPos (1,1); + setPrintPos (1, 1); print (blank); delete[] blank; } @@ -397,14 +397,12 @@ void FLabel::init() //---------------------------------------------------------------------- uChar FLabel::getHotkey() { - uInt length; - if ( text.isEmpty() ) return 0; - length = text.getLength(); + std::size_t length = text.getLength(); - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { try { @@ -421,14 +419,16 @@ uChar FLabel::getHotkey() } //---------------------------------------------------------------------- -int FLabel::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) +int FLabel::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign int hotkeypos = -1; wchar_t* txt = src; - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { if ( i < length && txt[i] == L'&' && hotkeypos == -1 ) { @@ -465,22 +465,24 @@ void FLabel::setHotkeyAccelerator() } //---------------------------------------------------------------------- -int FLabel::getAlignOffset (int length) +std::size_t FLabel::getAlignOffset (std::size_t length) { + std::size_t width = std::size_t(getWidth()); + switch ( alignment ) { case fc::alignLeft: return 0; case fc::alignCenter: - if ( length < getWidth() ) - return int((getWidth() - length) / 2); + if ( length < width ) + return std::size_t((width - length) / 2); else return 0; case fc::alignRight: - if ( length < getWidth() ) - return getWidth() - length; + if ( length < width ) + return width - length; else return 0; } @@ -522,15 +524,16 @@ void FLabel::draw() //---------------------------------------------------------------------- void FLabel::drawMultiLine() { - uInt y = 0; - uInt text_lines = uInt(multiline_text.size()); + std::size_t y = 0; + std::size_t text_lines = multiline_text.size(); bool hotkey_printed = false; - while ( y < text_lines && y < uInt(getHeight()) ) + while ( y < text_lines && y < std::size_t(getHeight()) ) { wchar_t* label_text; - int align_offset, hotkeypos = -1; - uInt length = multiline_text[y].getLength(); + int hotkeypos = -1; + std::size_t align_offset; + std::size_t length = multiline_text[y].getLength(); try { @@ -554,13 +557,13 @@ void FLabel::drawMultiLine() if ( hotkeypos != -1 ) { - align_offset = getAlignOffset (int(length - 1)); + align_offset = getAlignOffset(length - 1); printLine (label_text, length - 1, hotkeypos, align_offset); hotkey_printed = true; } else { - align_offset = getAlignOffset (int(length)); + align_offset = getAlignOffset(length); printLine (label_text, length, -1, align_offset); } @@ -573,8 +576,9 @@ void FLabel::drawMultiLine() void FLabel::drawSingleLine() { wchar_t* label_text; - int hotkeypos = -1, align_offset; - uInt length = text.getLength(); + int hotkeypos = -1; + std::size_t align_offset; + std::size_t length = text.getLength(); try { @@ -592,18 +596,19 @@ void FLabel::drawSingleLine() length--; setPrintPos (1,1); - align_offset = getAlignOffset (int(length)); + align_offset = getAlignOffset(length); printLine (label_text, length, hotkeypos, align_offset); delete[] label_text; } //---------------------------------------------------------------------- void FLabel::printLine ( wchar_t line[] - , uInt length + , std::size_t length , int hotkeypos - , int align_offset ) + , std::size_t align_offset ) { - int to_char; + std::size_t to_char; + std::size_t width = std::size_t(getWidth()); bool isActive, isNoUnderline; isActive = ((flags & fc::active) != 0); isNoUnderline = ((flags & fc::no_underline) != 0); @@ -611,15 +616,15 @@ void FLabel::printLine ( wchar_t line[] if ( align_offset > 0 ) print (FString(align_offset, ' ')); // leading spaces - if ( length <= uInt(getWidth()) ) - to_char = int(length); + if ( length <= width ) + to_char = length; else - to_char = getWidth() - 2; + to_char = width - 2; if ( hasReverseMode() ) setReverse(true); - for (int z = 0; z < to_char; z++) + for (std::size_t z = 0; z < to_char; z++) { if ( ! std::iswprint(wint_t(line[z])) ) { @@ -630,7 +635,7 @@ void FLabel::printLine ( wchar_t line[] } } - if ( (z == hotkeypos) && isActive ) + if ( (int(z) == hotkeypos) && isActive ) { setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); @@ -651,17 +656,17 @@ void FLabel::printLine ( wchar_t line[] print ( line[z] ); } - if ( length > uInt(getWidth()) ) + if ( length > width ) { // Print ellipsis setColor (ellipsis_color, getBackgroundColor()); print (".."); setColor(); } - else if ( align_offset + to_char < getWidth() ) + else if ( align_offset + to_char < width ) { // Print trailing spaces - int len = getWidth() - align_offset - to_char; + std::size_t len = width - align_offset - to_char; print (FString(len, ' ')); } diff --git a/src/flineedit.cpp b/src/flineedit.cpp index f584d1fc..7a9364e2 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -281,7 +281,7 @@ void FLineEdit::setLabelOrientation(const label_o o) //---------------------------------------------------------------------- void FLineEdit::hide() { - int s, size; + std::size_t s, size; short fg, bg; char* blank; FWidget* parent_widget = getParentWidget(); @@ -303,7 +303,7 @@ void FLineEdit::hide() s = hasShadow() ? 1 : 0; size = getWidth() + s; - if ( size < 0 ) + if ( size == 0 ) return; try @@ -319,7 +319,7 @@ void FLineEdit::hide() std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; - for (int y = 0; y < getHeight() + s; y++) + for (int y = 0; y < int(getHeight() + s); y++) { setPrintPos (1, 1 + y); print (blank); @@ -434,10 +434,10 @@ void FLineEdit::onMouseDown (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= getWidth() && mouse_y == 1 ) + if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 ) { int len = int(text.getLength()); - cursor_pos = text_offset + mouse_x - 2; + cursor_pos = int(text_offset) + mouse_x - 2; if ( cursor_pos >= len ) cursor_pos = len; @@ -470,9 +470,9 @@ void FLineEdit::onMouseMove (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= getWidth() && mouse_y == 1 ) + if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 ) { - cursor_pos = text_offset + mouse_x - 2; + cursor_pos = int(text_offset) + mouse_x - 2; if ( cursor_pos >= len ) cursor_pos = len; @@ -498,17 +498,17 @@ void FLineEdit::onMouseMove (FMouseEvent* ev) drag_scroll = FLineEdit::noScroll; } } - else if ( mouse_x >= getWidth() ) + else if ( mouse_x >= int(getWidth()) ) { // drag right - if ( ! scroll_timer && text_offset <= len - getWidth() + 1 ) + if ( ! scroll_timer && int(text_offset) <= len - int(getWidth()) + 1 ) { scroll_timer = true; addTimer(scroll_repeat); drag_scroll = FLineEdit::scrollRight; } - if ( text_offset == len - getWidth() + 2 ) + if ( int(text_offset) == len - int(getWidth()) + 2 ) { delOwnTimer(); drag_scroll = FLineEdit::noScroll; @@ -549,13 +549,13 @@ void FLineEdit::onTimer (FTimerEvent*) break; case FLineEdit::scrollRight: - if ( text_offset == len - getWidth() + 2 ) + if ( int(text_offset) == len - int(getWidth()) + 2 ) { drag_scroll = FLineEdit::noScroll; return; } - if ( text_offset <= len - getWidth() + 1 ) + if ( int(text_offset) <= len - int(getWidth()) + 1 ) text_offset++; if ( cursor_pos < len ) @@ -642,7 +642,7 @@ void FLineEdit::onFocusOut (FFocusEvent*) //---------------------------------------------------------------------- void FLineEdit::adjustLabel() { - int label_length = int(label_text.getLength()); + std::size_t label_length = label_text.getLength(); if ( hasHotkey() ) label_length--; @@ -657,7 +657,7 @@ void FLineEdit::adjustLabel() break; case label_left: - label->setGeometry(getX() - label_length - 1, getY(), label_length, 1); + label->setGeometry(getX() - int(label_length) - 1, getY(), label_length, 1); break; } } @@ -757,7 +757,8 @@ void FLineEdit::drawInputField() if ( isActiveFocus && getMaxColor() < 16 ) setBold(); - show_text = text.mid(uInt(1 + text_offset), uInt(getWidth() - 2)); + show_text = text.mid( std::size_t(1 + text_offset) + , std::size_t(getWidth() - 2) ); if ( isLinuxTerm() && hasUTF8() ) { @@ -773,7 +774,7 @@ void FLineEdit::drawInputField() x = int(show_text.getLength()); - while ( x < getWidth() - 1 ) + while ( x < int(getWidth()) - 1 ) { print (' '); x++; @@ -792,7 +793,7 @@ void FLineEdit::drawInputField() drawShadow (); // set the cursor to the first pos. - setCursorPos (2 + cursor_pos - text_offset, 1); + setCursorPos (2 + cursor_pos - int(text_offset), 1); } //---------------------------------------------------------------------- @@ -801,7 +802,7 @@ inline void FLineEdit::keyLeft() if ( cursor_pos > 0 ) cursor_pos--; - if ( cursor_pos < text_offset ) + if ( cursor_pos < int(text_offset) ) text_offset--; } @@ -813,8 +814,8 @@ inline void FLineEdit::keyRight() if ( cursor_pos < len ) cursor_pos++; - if ( cursor_pos - text_offset >= getWidth() - 2 - && text_offset <= len - getWidth() + 1 ) + if ( cursor_pos - int(text_offset) >= int(getWidth()) - 2 + && int(text_offset) <= len - int(getWidth()) + 1 ) text_offset++; } @@ -828,31 +829,32 @@ inline void FLineEdit::keyHome() //---------------------------------------------------------------------- inline void FLineEdit::keyEnd() { - int len = int(text.getLength()); - cursor_pos = len; + std::size_t len = text.getLength(); + cursor_pos = int(len); - if ( cursor_pos >= getWidth() - 1 ) + if ( cursor_pos >= int(getWidth()) - 1 ) text_offset = len - getWidth() + 2; } //---------------------------------------------------------------------- inline void FLineEdit::keyDel() { - int len = int(text.getLength()); + std::size_t len = text.getLength(); - if ( len > 0 && cursor_pos < len ) + if ( len > 0 && std::size_t(cursor_pos) < len ) { - text.remove(cursor_pos, 1); + text.remove(std::size_t(cursor_pos), 1); processChanged(); } - if ( cursor_pos >= len ) - cursor_pos = len; + if ( cursor_pos >= int(len) ) + cursor_pos = int(len); if ( cursor_pos < 0 ) cursor_pos = 0; - if ( text_offset > 0 && len - text_offset < getWidth() - 1 ) + if ( text_offset > 0 + && len - std::size_t(text_offset) < std::size_t(getWidth()) - 1 ) text_offset--; } @@ -861,7 +863,7 @@ inline void FLineEdit::keyBackspace() { if ( text.getLength() > 0 && cursor_pos > 0 ) { - text.remove(cursor_pos - 1, 1); + text.remove(std::size_t(cursor_pos) - 1, 1); processChanged(); cursor_pos--; @@ -892,9 +894,9 @@ inline bool FLineEdit::keyInput (int key) { if ( key >= 0x20 && key <= 0x10fff ) { - int len = int(text.getLength()); + std::size_t len = text.getLength(); - if ( cursor_pos == len ) + if ( std::size_t(cursor_pos) == len ) { text += wchar_t(key); processChanged(); @@ -902,9 +904,9 @@ inline bool FLineEdit::keyInput (int key) else if ( len > 0 ) { if ( insert_mode ) - text.insert(wchar_t(key), uInt(cursor_pos)); + text.insert(wchar_t(key), std::size_t(cursor_pos)); else - text.overwrite(wchar_t(key), uInt(cursor_pos)); + text.overwrite(wchar_t(key), std::size_t(cursor_pos)); processChanged(); } @@ -915,7 +917,7 @@ inline bool FLineEdit::keyInput (int key) } cursor_pos++; - if ( cursor_pos >= getWidth() - 1 ) + if ( cursor_pos >= int(getWidth()) - 1 ) text_offset++; return true; diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 1c2ec9b5..909353c4 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -127,14 +127,14 @@ FListBox::~FListBox() // destructor // public methods of FListBox //---------------------------------------------------------------------- -void FListBox::setCurrentItem (int index) +void FListBox::setCurrentItem (std::size_t index) { - int element_count; + std::size_t element_count; if ( index == current ) return; - element_count = int(getCount()); + element_count = getCount(); if ( index > element_count ) current = element_count; @@ -155,12 +155,12 @@ void FListBox::setCurrentItem (int index) //---------------------------------------------------------------------- void FListBox::setCurrentItem (listBoxItems::iterator iter) { - int index = int(std::distance(itemlist.begin(), iter) + 1); + std::size_t index = std::size_t(std::distance(itemlist.begin(), iter)) + 1; setCurrentItem(index); } //---------------------------------------------------------------------- -void FListBox::showInsideBrackets ( int index +void FListBox::showInsideBrackets ( std::size_t index , fc::brackets_type b ) { listBoxItems::iterator iter = index2iterator(index - 1); @@ -175,10 +175,10 @@ void FListBox::showInsideBrackets ( int index { max_line_width = len; - if ( len >= getWidth() - nf_offset - 3 ) + if ( len >= int(getWidth()) - nf_offset - 3 ) { - hbar->setMaximum (max_line_width - getWidth() + nf_offset + 4); - hbar->setPageSize (max_line_width, getWidth() - nf_offset - 4); + hbar->setMaximum (max_line_width - int(getWidth()) + nf_offset + 4); + hbar->setPageSize (max_line_width, int(getWidth()) - nf_offset - 4); hbar->setValue (xoffset); if ( ! hbar->isVisible() ) @@ -188,7 +188,7 @@ void FListBox::showInsideBrackets ( int index } //---------------------------------------------------------------------- -void FListBox::setGeometry (int x, int y, int w, int h, bool adjust) +void FListBox::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Set the widget geometry @@ -196,13 +196,13 @@ void FListBox::setGeometry (int x, int y, int w, int h, bool adjust) if ( isNewFont() ) { - vbar->setGeometry (getWidth(), 2, 2, getHeight() - 2); - hbar->setGeometry (1, getHeight(), getWidth() - 2 - nf_offset, 1); + vbar->setGeometry (int(getWidth()), 2, 2, getHeight() - 2); + hbar->setGeometry (1, int(getHeight()), getWidth() - 2 - std::size_t(nf_offset), 1); } else { - vbar->setGeometry (getWidth(), 2, 1, getHeight() - 2); - hbar->setGeometry (2, getHeight(), getWidth() - 2, 1); + vbar->setGeometry (int(getWidth()), 2, 1, getHeight() - 2); + hbar->setGeometry (2, int(getHeight()), getWidth() - 2, 1); } } @@ -240,7 +240,7 @@ void FListBox::setText (const FString& txt) //---------------------------------------------------------------------- void FListBox::hide() { - int n, size; + std::size_t n, size; short fg, bg; char* blank; FWidget* parent_widget = getParentWidget(); @@ -262,12 +262,12 @@ void FListBox::hide() n = isNewFont() ? 1 : 0; size = getWidth() + n; - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -275,10 +275,10 @@ void FListBox::hide() return; } - std::memset (blank, ' ', std::size_t(size)); + std::memset (blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { setPrintPos (1, 1 + y); print (blank); @@ -322,15 +322,15 @@ void FListBox::insert ( long item } //---------------------------------------------------------------------- -void FListBox::remove (int item) +void FListBox::remove (std::size_t item) { - int element_count; + std::size_t element_count; - if ( int(getCount()) < item ) + if ( item > getCount() ) return; - itemlist.erase (itemlist.begin() + item - 1); - element_count = int(getCount()); + itemlist.erase (itemlist.begin() + int(item) - 1); + element_count = getCount(); max_line_width = 0; listBoxItems::iterator iter = itemlist.begin(); @@ -345,14 +345,14 @@ void FListBox::remove (int item) ++iter; } - hbar->setMaximum (max_line_width - getWidth() + nf_offset + 4); - hbar->setPageSize (max_line_width, getWidth() - nf_offset - 4); + hbar->setMaximum (max_line_width - int(getWidth()) + nf_offset + 4); + hbar->setPageSize (max_line_width, int(getWidth()) - nf_offset - 4); - if ( hbar->isVisible() && max_line_width < getWidth() - nf_offset - 3 ) + if ( hbar->isVisible() && max_line_width < int(getWidth()) - nf_offset - 3 ) hbar->hide(); - vbar->setMaximum (element_count - getHeight() + 2); - vbar->setPageSize (element_count, getHeight() - 2); + vbar->setMaximum (int(element_count - getHeight()) + 2); + vbar->setPageSize (int(element_count), int(getHeight()) - 2); if ( vbar->isVisible() && element_count < getHeight() - 1 ) vbar->hide(); @@ -363,8 +363,8 @@ void FListBox::remove (int item) if ( current > element_count ) current = element_count; - if ( yoffset > element_count - getHeight() + 2 ) - yoffset = element_count - getHeight() + 2; + if ( yoffset > int(element_count - getHeight()) + 2 ) + yoffset = int(element_count - getHeight()) + 2; if ( yoffset < 0 ) yoffset = 0; @@ -373,7 +373,7 @@ void FListBox::remove (int item) //---------------------------------------------------------------------- void FListBox::clear() { - int size; + std::size_t size; char* blank; itemlist.clear(); @@ -397,12 +397,12 @@ void FListBox::clear() setColor (wc.list_fg, wc.list_bg); size = getWidth() - 2; - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -410,10 +410,10 @@ void FListBox::clear() return; } - std::memset (blank, ' ', std::size_t(size)); + std::memset (blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < getHeight() - 2; y++) + for (int y = 0; y < int(getHeight()) - 2; y++) { setPrintPos (2, 2 + y); print (blank); @@ -425,8 +425,8 @@ void FListBox::clear() //---------------------------------------------------------------------- void FListBox::onKeyPress (FKeyEvent* ev) { - int current_before = current - , xoffset_before = xoffset + std::size_t current_before = current; + int xoffset_before = xoffset , yoffset_before = yoffset , key = ev->key(); @@ -543,11 +543,11 @@ void FListBox::onMouseDown (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { - int element_count = int(getCount()); - current = yoffset + mouse_y - 1; + std::size_t element_count = getCount(); + current = std::size_t(yoffset + mouse_y - 1); if ( current > element_count ) current = element_count; @@ -581,8 +581,8 @@ void FListBox::onMouseUp (FMouseEvent* ev) int mouse_x = ev->getX(); int mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { processChanged(); @@ -602,16 +602,16 @@ void FListBox::onMouseMove (FMouseEvent* ev) if ( ev->getButton() == fc::RightButton && ! isMultiSelection() ) return; - int current_before = current; + std::size_t current_before = current; int yoffset_before = yoffset; int mouse_x = ev->getX(); int mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { - int element_count = int(getCount()); - current = yoffset + mouse_y - 1; + std::size_t element_count = getCount(); + current = std::size_t(yoffset + mouse_y - 1); if ( current > element_count ) current = element_count; @@ -640,7 +640,7 @@ void FListBox::onMouseMove (FMouseEvent* ev) // Auto-scrolling when dragging mouse outside the widget if ( mouse_y < 2 ) dragUp (ev->getButton()); - else if ( mouse_y >= getHeight() ) + else if ( mouse_y >= int(getHeight()) ) dragDown (ev->getButton()); else stopDragScroll(); @@ -657,8 +657,8 @@ void FListBox::onMouseDoubleClick (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { if ( yoffset + mouse_y - 1 > int(getCount()) ) return; @@ -670,7 +670,7 @@ void FListBox::onMouseDoubleClick (FMouseEvent* ev) //---------------------------------------------------------------------- void FListBox::onTimer (FTimerEvent*) { - int current_before = current; + std::size_t current_before = current; int yoffset_before = yoffset; switch ( int(drag_scroll) ) @@ -719,8 +719,8 @@ void FListBox::onTimer (FTimerEvent*) //---------------------------------------------------------------------- void FListBox::onWheel (FWheelEvent* ev) { + std::size_t current_before = current; int wheel - , current_before = current , yoffset_before = yoffset , pagesize = 4; @@ -791,45 +791,42 @@ void FListBox::onFocusOut (FFocusEvent*) //---------------------------------------------------------------------- void FListBox::adjustYOffset() { - int element_count = int(getCount()); + std::size_t element_count = getCount(); - if ( getClientHeight() < 0 ) - return; - - if ( element_count == 0 || getClientHeight() <= 0 ) + if ( element_count == 0 || getClientHeight() == 0 ) return; - if ( yoffset > element_count - getClientHeight() ) - yoffset = element_count - getClientHeight(); + if ( yoffset > int(element_count - getClientHeight()) ) + yoffset = int(element_count - getClientHeight()); if ( yoffset < 0 ) yoffset = 0; - if ( current < yoffset ) - current = yoffset; + if ( current < std::size_t(yoffset) ) + current = std::size_t(yoffset); - if ( yoffset < current - getClientHeight() ) - yoffset = current - getClientHeight(); + if ( yoffset < int(current - getClientHeight()) ) + yoffset = int(current - getClientHeight()); } //---------------------------------------------------------------------- void FListBox::adjustSize() { - int element_count; + std::size_t element_count; FWidget::adjustSize(); adjustYOffset(); - element_count = int(getCount()); - vbar->setMaximum (element_count - getClientHeight()); - vbar->setPageSize (element_count, getClientHeight()); - vbar->setX (getWidth()); + element_count = getCount(); + vbar->setMaximum (int(element_count - getClientHeight())); + vbar->setPageSize (int(element_count), int(getClientHeight())); + vbar->setX (int(getWidth())); vbar->setHeight (getClientHeight(), false); vbar->resize(); - hbar->setMaximum (max_line_width - getClientWidth() + 2); - hbar->setPageSize (max_line_width, getClientWidth() - 2); - hbar->setY (getHeight()); - hbar->setWidth (getClientWidth() + nf_offset, false); + hbar->setMaximum (max_line_width - int(getClientWidth()) + 2); + hbar->setPageSize (max_line_width, int(getClientWidth()) - 2); + hbar->setY (int(getHeight())); + hbar->setWidth (getClientWidth() + std::size_t(nf_offset), false); hbar->resize(); if ( element_count <= getClientHeight() ) @@ -837,7 +834,7 @@ void FListBox::adjustSize() else vbar->setVisible(); - if ( max_line_width < getClientWidth() - 1 ) + if ( max_line_width < int(getClientWidth()) - 1 ) hbar->hide(); else hbar->setVisible(); @@ -910,7 +907,7 @@ void FListBox::draw() setReverse(true); if ( isNewFont() ) - drawBorder (1, 1, getWidth() - 1, getHeight()); + drawBorder (1, 1, int(getWidth()) - 1, int(getHeight())); else drawBorder(); @@ -918,9 +915,9 @@ void FListBox::draw() { setColor(); - for (int y = 2; y < getHeight(); y++) + for (int y = 2; y < int(getHeight()); y++) { - setPrintPos (getWidth(), y); + setPrintPos (int(getWidth()), y); print (' '); // clear right side of the scrollbar } } @@ -955,14 +952,11 @@ void FListBox::draw() //---------------------------------------------------------------------- void FListBox::drawLabel() { - FString txt; - uInt length; - if ( text.isNull() || text.isEmpty() ) return; - txt = " " + text + " "; - length = txt.getLength(); + FString txt = " " + text + " "; + std::size_t length = txt.getLength(); setPrintPos (2, 1); if ( isEnabled() ) @@ -984,7 +978,7 @@ void FListBox::drawLabel() //---------------------------------------------------------------------- void FListBox::drawList() { - uInt start, num; + std::size_t start, num; listBoxItems::iterator iter; if ( itemlist.empty() || getHeight() <= 2 || getWidth() <= 4 ) @@ -998,18 +992,18 @@ void FListBox::drawList() if ( last_yoffset >= 0 && last_yoffset == yoffset - && last_current != current ) + && last_current != int(current) ) { // speed up: redraw only the changed rows - uInt last_pos = uInt(current - yoffset) - 1; - uInt current_pos = uInt(last_current - yoffset) - 1; + std::size_t last_pos = current - std::size_t(yoffset) - 1; + std::size_t current_pos = std::size_t(last_current - yoffset) - 1; start = std::min(last_pos, current_pos); num = std::max(last_pos, current_pos) + 1; } - iter = index2iterator(int(start) + yoffset); + iter = index2iterator(start + std::size_t(yoffset)); - for (uInt 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 lineHasBrackets = hasBrackets(iter); @@ -1036,7 +1030,7 @@ void FListBox::drawList() unsetAttributes(); last_yoffset = yoffset; - last_current = current; + last_current = int(current); } //---------------------------------------------------------------------- @@ -1044,13 +1038,13 @@ inline void FListBox::drawListLine ( int y , listBoxItems::iterator iter , bool serach_mark ) { - uInt i, len; - uInt inc_len = inc_search.getLength(); - bool isCurrentLine = bool(y + yoffset + 1 == current); + std::size_t i, len; + std::size_t inc_len = inc_search.getLength(); + bool isCurrentLine = bool(y + yoffset + 1 == int(current)); bool isFocus = ((flags & fc::focus) != 0); FString element; element = getString(iter).mid ( uInt(1 + xoffset) - , uInt(getWidth() - nf_offset - 4) ); + , uInt(getWidth() - std::size_t(nf_offset) - 4) ); const wchar_t* const& element_str = element.wc_str(); len = element.getLength(); @@ -1078,7 +1072,7 @@ inline void FListBox::drawListLine ( int y i++; } - for (; i < uInt(getWidth() - nf_offset - 3); i++) + for (; i < getWidth() - std::size_t(nf_offset) - 3; i++) print (' '); } @@ -1139,13 +1133,13 @@ inline void FListBox::drawListBracketsLine ( int y , listBoxItems::iterator iter , bool serach_mark ) { - int full_length; FString element; - uInt len - , inc_len = inc_search.getLength() - , i = 0 - , b = 0; - bool isCurrentLine = bool(y + yoffset + 1 == current); + std::size_t len + , full_length + , inc_len = inc_search.getLength() + , i = 0 + , b = 0; + bool isCurrentLine = bool(y + yoffset + 1 == int(current)); bool isFocus = ((flags & fc::focus) != 0); if ( isMonochron() && isCurrentLine && isFocus ) @@ -1158,12 +1152,12 @@ inline void FListBox::drawListBracketsLine ( int y b = 1; printLeftBracket (iter->brackets); - element = getString(iter).mid ( uInt(1 + xoffset) - , uInt(getWidth() - nf_offset - 5) ); + element = getString(iter).mid ( std::size_t(xoffset) + 1 + , getWidth() - std::size_t(nf_offset) - 5 ); } else - element = getString(iter).mid ( uInt(xoffset) - , uInt(getWidth() - nf_offset - 4) ); + element = getString(iter).mid ( std::size_t(xoffset) + , getWidth() - std::size_t(nf_offset) - 4 ); const wchar_t* const& element_str = element.wc_str(); len = element.getLength(); @@ -1181,10 +1175,10 @@ inline void FListBox::drawListBracketsLine ( int y print (element_str[i]); } - full_length = int(getString(iter).getLength()); + full_length = getString(iter).getLength(); - if ( b + i < uInt(getWidth() - nf_offset - 4 ) - && xoffset <= full_length + 1 ) + if ( b + i < getWidth() - std::size_t(nf_offset) - 4 + && std::size_t(xoffset) <= full_length + 1 ) { if ( serach_mark && i == inc_len ) setColor ( wc.current_element_focus_fg @@ -1200,7 +1194,7 @@ inline void FListBox::drawListBracketsLine ( int y i++; } - for (; b + i < uInt(getWidth() - nf_offset - 3); i++) + for (; b + i < getWidth() - std::size_t(nf_offset) - 3; i++) print (' '); } @@ -1211,8 +1205,8 @@ inline void FListBox::setLineAttributes ( int y , bool& serach_mark ) { bool isFocus = ((flags & fc::focus) != 0) - , isCurrentLine = bool(y + yoffset + 1 == current); - uInt inc_len = inc_search.getLength(); + , isCurrentLine = bool(y + yoffset + 1 == int(current)); + std::size_t inc_len = inc_search.getLength(); setPrintPos (2, 2 + int(y)); @@ -1326,10 +1320,10 @@ void FListBox::recalculateHorizontalBar (int len, bool has_brackets) max_line_width = len; - if ( len >= getWidth() - nf_offset - 3 ) + if ( len >= int(getWidth()) - nf_offset - 3 ) { - hbar->setMaximum (max_line_width - getWidth() + nf_offset + 4); - hbar->setPageSize (max_line_width, getWidth() - nf_offset - 4); + hbar->setMaximum (max_line_width - int(getWidth()) + nf_offset + 4); + hbar->setPageSize (max_line_width, int(getWidth()) - nf_offset - 4); hbar->calculateSliderValues(); if ( ! hbar->isVisible() ) @@ -1340,11 +1334,11 @@ void FListBox::recalculateHorizontalBar (int len, bool has_brackets) //---------------------------------------------------------------------- void FListBox::recalculateVerticalBar (int element_count) { - vbar->setMaximum (element_count - getHeight() + 2); - vbar->setPageSize (element_count, getHeight() - 2); + vbar->setMaximum (element_count - int(getHeight()) + 2); + vbar->setPageSize (element_count, int(getHeight()) - 2); vbar->calculateSliderValues(); - if ( ! vbar->isVisible() && element_count >= getHeight() - 1 ) + if ( ! vbar->isVisible() && element_count >= int(getHeight()) - 1 ) vbar->setVisible(); } @@ -1367,7 +1361,7 @@ inline void FListBox::getWidgetFocus() } //---------------------------------------------------------------------- -void FListBox::multiSelection (int pos) +void FListBox::multiSelection (std::size_t pos) { if ( ! isMultiSelection() ) return; @@ -1384,29 +1378,29 @@ void FListBox::multiSelection (int pos) } processSelect(); - secect_from_item = pos; + secect_from_item = int(pos); } //---------------------------------------------------------------------- -void FListBox::multiSelectionUpTo (int pos) +void FListBox::multiSelectionUpTo (std::size_t pos) { - int from, to; + std::size_t from, to; if ( ! isMultiSelection() ) return; - if ( secect_from_item > pos ) + if ( std::size_t(secect_from_item) > pos ) { from = pos; - to = secect_from_item - 1; + to = std::size_t(secect_from_item) - 1; } else { - from = secect_from_item + 1; + from = std::size_t(secect_from_item) + 1; to = pos; } - for (int i = from; i <= to; i++) + for (std::size_t i = from; i <= to; i++) { if ( mouse_select ) { @@ -1420,7 +1414,7 @@ void FListBox::multiSelectionUpTo (int pos) } } - secect_from_item = pos; + secect_from_item = int(pos); } //---------------------------------------------------------------------- @@ -1433,11 +1427,11 @@ void FListBox::wheelUp (int pagesize) if ( yoffset < 0 ) { - current -= pagesize + yoffset; + current -= std::size_t(pagesize + yoffset); yoffset = 0; } else - current -= pagesize; + current -= std::size_t(pagesize); if ( current < 1 ) current = 1; @@ -1446,8 +1440,8 @@ void FListBox::wheelUp (int pagesize) //---------------------------------------------------------------------- void FListBox::wheelDown (int pagesize) { - int element_count = int(getCount()); - int yoffset_end = element_count - getClientHeight(); + std::size_t element_count = getCount(); + int yoffset_end = int(element_count - getClientHeight()); if ( yoffset_end < 0 ) yoffset_end = 0; @@ -1459,11 +1453,11 @@ void FListBox::wheelDown (int pagesize) if ( yoffset > yoffset_end ) { - current += pagesize - (yoffset - yoffset_end); + current += std::size_t(pagesize - (yoffset - yoffset_end)); yoffset = yoffset_end; } else - current += pagesize; + current += std::size_t(pagesize); if ( current > element_count ) current = element_count; @@ -1485,7 +1479,7 @@ bool FListBox::dragScrollUp() //---------------------------------------------------------------------- bool FListBox::dragScrollDown() { - int element_count = int(getCount()); + std::size_t element_count = getCount(); if ( current == element_count ) { @@ -1501,7 +1495,7 @@ bool FListBox::dragScrollDown() void FListBox::dragUp (int mouse_button) { if ( drag_scroll != fc::noScroll - && scroll_distance < getClientHeight() ) + && scroll_distance < int(getClientHeight()) ) scroll_distance++; if ( ! scroll_timer && current > 1 ) @@ -1526,10 +1520,10 @@ void FListBox::dragUp (int mouse_button) void FListBox::dragDown (int mouse_button) { if ( drag_scroll != fc::noScroll - && scroll_distance < getClientHeight() ) + && scroll_distance < int(getClientHeight()) ) scroll_distance++; - if ( ! scroll_timer && current < int(getCount()) ) + if ( ! scroll_timer && current < getCount() ) { scroll_timer = true; addTimer(scroll_repeat); @@ -1540,7 +1534,7 @@ void FListBox::dragDown (int mouse_button) drag_scroll = fc::scrollDown; } - if ( current == int(getCount()) ) + if ( current == getCount() ) { delOwnTimer(); drag_scroll = fc::noScroll; @@ -1562,12 +1556,12 @@ void FListBox::prevListItem (int distance) if ( current == 1 ) return; - current -= distance; + current -= std::size_t(distance); if ( current < 1 ) current = 1; - if ( current <= yoffset ) + if ( current <= std::size_t(yoffset) ) { yoffset -= distance; @@ -1579,18 +1573,18 @@ void FListBox::prevListItem (int distance) //---------------------------------------------------------------------- void FListBox::nextListItem (int distance) { - int element_count = int(getCount()); - int yoffset_end = element_count - getClientHeight(); + std::size_t element_count = getCount(); + int yoffset_end = int(element_count - getClientHeight()); if ( current == element_count ) return; - current += distance; + current += std::size_t(distance); if ( current > element_count ) current = element_count; - if ( current - yoffset > getClientHeight() ) + if ( current - std::size_t(yoffset) > getClientHeight() ) { yoffset += distance; @@ -1602,7 +1596,7 @@ void FListBox::nextListItem (int distance) void FListBox::scrollToX (int val) { static const int padding_space = 2; // 1 leading space + 1 trailing space - int xoffset_end = max_line_width - getClientWidth() + padding_space; + int xoffset_end = max_line_width - int(getClientWidth()) + padding_space; if ( xoffset == val ) return; @@ -1619,13 +1613,13 @@ void FListBox::scrollToX (int val) //---------------------------------------------------------------------- void FListBox::scrollToY (int val) { - int element_count = int(getCount()); - int yoffset_end = element_count - getClientHeight(); + std::size_t element_count = getCount(); + int yoffset_end = int(element_count - getClientHeight()); if ( yoffset == val ) return; - int c = current - yoffset; + int c = int(current) - yoffset; yoffset = val; if ( yoffset > yoffset_end ) @@ -1634,10 +1628,10 @@ void FListBox::scrollToY (int val) if ( yoffset < 0 ) yoffset = 0; - current = yoffset + c; + current = std::size_t(yoffset + c); - if ( current < yoffset ) - current = yoffset; + if ( current < std::size_t(yoffset) ) + current = std::size_t(yoffset); if ( current > element_count ) current = element_count; @@ -1659,7 +1653,7 @@ void FListBox::scrollLeft (int distance) void FListBox::scrollRight (int distance) { static const int padding_space = 2; // 1 leading space + 1 trailing space - int xoffset_end = max_line_width - getClientWidth() + padding_space; + int xoffset_end = max_line_width - int(getClientWidth()) + padding_space; xoffset += distance; if ( xoffset == xoffset_end ) @@ -1703,7 +1697,7 @@ inline void FListBox::keyRight() //---------------------------------------------------------------------- inline void FListBox::keyPgUp() { - int pagesize = getClientHeight() - 1; + int pagesize = int(getClientHeight()) - 1; prevListItem (pagesize); inc_search.clear(); } @@ -1711,7 +1705,7 @@ inline void FListBox::keyPgUp() //---------------------------------------------------------------------- inline void FListBox::keyPgDn() { - int pagesize = getClientHeight() - 1; + int pagesize = int(getClientHeight()) - 1; nextListItem (pagesize); inc_search.clear(); } @@ -1727,8 +1721,8 @@ inline void FListBox::keyHome() //---------------------------------------------------------------------- inline void FListBox::keyEnd() { - int element_count = int(getCount()); - int yoffset_end = element_count - getClientHeight(); + std::size_t element_count = getCount(); + int yoffset_end = int(element_count - getClientHeight()); current = element_count; if ( current > getClientHeight() ) @@ -1759,7 +1753,7 @@ inline void FListBox::keyEnter() //---------------------------------------------------------------------- inline bool FListBox::keySpace() { - uInt inc_len = inc_search.getLength(); + std::size_t inc_len = inc_search.getLength(); if ( inc_len > 0 ) { @@ -1806,7 +1800,7 @@ inline bool FListBox::keyInsert() { if ( isMultiSelection() ) { - int element_count = int(getCount()); + std::size_t element_count = getCount(); if ( isSelected(current) ) unselectItem(current); @@ -1819,7 +1813,7 @@ inline bool FListBox::keyInsert() if ( current > element_count ) current = element_count; - if ( current - yoffset >= getHeight() - 1 ) + if ( current - std::size_t(yoffset) >= getHeight() - 1 ) yoffset++; return true; @@ -1832,7 +1826,7 @@ inline bool FListBox::keyInsert() //---------------------------------------------------------------------- inline bool FListBox::keyBackspace() { - uInt inc_len = inc_search.getLength(); + std::size_t inc_len = inc_search.getLength(); if ( inc_len > 0 ) { @@ -1873,7 +1867,7 @@ inline bool FListBox::keyIncSearchInput (int key) else inc_search += wchar_t(key); - uInt inc_len = inc_search.getLength(); + std::size_t inc_len = inc_search.getLength(); bool inc_found = false; listBoxItems::iterator iter = itemlist.begin(); @@ -1940,9 +1934,9 @@ void FListBox::lazyConvert(listBoxItems::iterator iter, int y) void FListBox::cb_VBarChange (FWidget*, data_ptr) { FScrollbar::sType scrollType; + std::size_t current_before = current; int distance = 1 , pagesize = 4 - , current_before = current , yoffset_before = yoffset; scrollType = vbar->getScrollType(); @@ -1952,14 +1946,14 @@ void FListBox::cb_VBarChange (FWidget*, data_ptr) break; case FScrollbar::scrollPageBackward: - distance = getClientHeight(); + distance = int(getClientHeight()); // fall through case FScrollbar::scrollStepBackward: prevListItem (distance); break; case FScrollbar::scrollPageForward: - distance = getClientHeight(); + distance = int(getClientHeight()); // fall through case FScrollbar::scrollStepForward: nextListItem (distance); @@ -2019,14 +2013,14 @@ void FListBox::cb_HBarChange (FWidget*, data_ptr) break; case FScrollbar::scrollPageBackward: - distance = getClientWidth() - padding_space; + distance = int(getClientWidth()) - padding_space; // fall through case FScrollbar::scrollStepBackward: scrollLeft (distance); break; case FScrollbar::scrollPageForward: - distance = getClientWidth() - padding_space; + distance = int(getClientWidth()) - padding_space; // fall through case FScrollbar::scrollStepForward: scrollRight (distance); diff --git a/src/flistview.cpp b/src/flistview.cpp index 868a5332..1b97cc62 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -49,6 +49,8 @@ long firstNumberFromString (const FString& str) FString::iterator iter = str.begin(); FString::iterator first_pos; FString::iterator last_pos; + std::size_t pos; + std::size_t length; long number; while ( iter != last ) @@ -82,8 +84,8 @@ long firstNumberFromString (const FString& str) if ( last_pos == last ) return 0; - uInt pos = uInt(std::distance(str.begin(), first_pos)) + 1; - uInt length = uInt(std::distance(first_pos, last_pos)); + pos = std::size_t(std::distance(str.begin(), first_pos)) + 1; + length = std::size_t(std::distance(first_pos, last_pos)); const FString num_str = str.mid(pos, length); try @@ -631,7 +633,7 @@ FListView::~FListView() // destructor // public methods of FListView //---------------------------------------------------------------------- -uInt FListView::getCount() +std::size_t FListView::getCount() { int n = 0; FObjectIterator iter = itemlist.begin(); @@ -643,7 +645,7 @@ uInt FListView::getCount() ++iter; } - return uInt(n); + return std::size_t(n); } //---------------------------------------------------------------------- @@ -691,7 +693,7 @@ fc::sorting_type FListView::getColumnSortType (int column) const } //---------------------------------------------------------------------- -void FListView::setGeometry (int x, int y, int w, int h, bool adjust) +void FListView::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Set the widget geometry @@ -699,13 +701,13 @@ void FListView::setGeometry (int x, int y, int w, int h, bool adjust) if ( isNewFont() ) { - vbar->setGeometry (getWidth(), 2, 2, getHeight() - 2); - hbar->setGeometry (1, getHeight(), getWidth() - 2, 1); + vbar->setGeometry (int(getWidth()), 2, 2, getHeight() - 2); + hbar->setGeometry (1, int(getHeight()), getWidth() - 2, 1); } else { - vbar->setGeometry (getWidth(), 2, 1, getHeight() - 2); - hbar->setGeometry (2, getHeight(), getWidth() - 2, 1); + vbar->setGeometry (int(getWidth()), 2, 1, getHeight() - 2); + hbar->setGeometry (2, int(getHeight()), getWidth() - 2, 1); } } @@ -946,7 +948,7 @@ void FListView::onKeyPress (FKeyEvent* ev) int position_before = current_iter.getPosition() , xoffset_before = xoffset , first_line_position_before = first_visible_line.getPosition() - , pagesize = getClientHeight() - 1 + , pagesize = int(getClientHeight()) - 1 , key = ev->key(); clicked_expander_pos.setPoint(-1, -1); @@ -1051,8 +1053,8 @@ void FListView::onMouseDown (FMouseEvent* ev) , mouse_x = ev->getX() , mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { int new_pos = first_visible_line.getPosition() + mouse_y - 2; @@ -1093,8 +1095,8 @@ void FListView::onMouseUp (FMouseEvent* ev) int mouse_x = ev->getX(); int mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { if ( tree_view ) { @@ -1134,8 +1136,8 @@ void FListView::onMouseMove (FMouseEvent* ev) , mouse_x = ev->getX() , mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { int new_pos = first_visible_line.getPosition() + mouse_y - 2; @@ -1158,7 +1160,7 @@ void FListView::onMouseMove (FMouseEvent* ev) // auto-scrolling when dragging mouse outside the widget if ( mouse_y < 2 ) dragUp (ev->getButton()); - else if ( mouse_y >= getHeight() ) + else if ( mouse_y >= int(getHeight()) ) dragDown (ev->getButton()); else stopDragScroll(); @@ -1175,8 +1177,8 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < getWidth() - && mouse_y > 1 && mouse_y < getHeight() ) + if ( mouse_x > 1 && mouse_x < int(getWidth()) + && mouse_y > 1 && mouse_y < int(getHeight()) ) { if ( first_visible_line.getPosition() + mouse_y - 1 > int(getCount()) ) return; @@ -1307,7 +1309,7 @@ void FListView::onFocusOut (FFocusEvent*) void FListView::adjustViewport() { int element_count = int(getCount()); - int height = getClientHeight(); + int height = int(getClientHeight()); if ( element_count == 0 || height <= 0 ) return; @@ -1347,20 +1349,20 @@ void FListView::adjustViewport() //---------------------------------------------------------------------- void FListView::adjustSize() { - int element_count; + std::size_t element_count; FWidget::adjustSize(); adjustViewport(); - element_count = int(getCount()); - vbar->setMaximum (element_count - getClientHeight()); - vbar->setPageSize (element_count, getClientHeight()); - vbar->setX (getWidth()); + element_count = getCount(); + vbar->setMaximum (int(element_count - getClientHeight())); + vbar->setPageSize (int(element_count), int(getClientHeight())); + vbar->setX (int(getWidth())); vbar->setHeight (getClientHeight(), false); vbar->resize(); - hbar->setMaximum (max_line_width - getClientWidth()); - hbar->setPageSize (max_line_width, getClientWidth()); - hbar->setY (getHeight() ); + hbar->setMaximum (max_line_width - int(getClientWidth())); + hbar->setPageSize (max_line_width, int(getClientWidth())); + hbar->setY (int(getHeight())); hbar->setWidth (getClientWidth(), false); hbar->resize(); @@ -1369,7 +1371,7 @@ void FListView::adjustSize() else vbar->setVisible(); - if ( max_line_width <= getClientWidth() ) + if ( max_line_width <= int(getClientWidth()) ) hbar->hide(); else hbar->setVisible(); @@ -1449,9 +1451,9 @@ void FListView::sort (Compare cmp) } //---------------------------------------------------------------------- -uInt FListView::getAlignOffset ( fc::text_alignment align - , uInt txt_length - , uInt width ) +std::size_t FListView::getAlignOffset ( fc::text_alignment align + , std::size_t txt_length + , std::size_t width ) { switch ( align ) { @@ -1460,7 +1462,7 @@ uInt FListView::getAlignOffset ( fc::text_alignment align case fc::alignCenter: if ( txt_length < width ) - return uInt((width - txt_length) / 2); + return std::size_t((width - txt_length) / 2); else return 0; @@ -1488,7 +1490,7 @@ void FListView::draw() setReverse(true); if ( isNewFont() ) - drawBorder (1, 1, getWidth() - 1, getHeight()); + drawBorder (1, 1, int(getWidth()) - 1, int(getHeight())); else drawBorder(); @@ -1496,9 +1498,9 @@ void FListView::draw() { setColor(); - for (int y = 2; y < getHeight(); y++) + for (int y = 2; y < int(getHeight()); y++) { - setPrintPos (getWidth(), y); + setPrintPos (int(getWidth()), y); print (' '); // clear right side of the scrollbar } } @@ -1563,11 +1565,11 @@ void FListView::drawColumnLabels() h << headerline; first = h.begin() + xoffset; - if ( int(h.size()) <= getClientWidth() ) + if ( h.size() <= getClientWidth() ) last = h.end(); else { - int len = getClientWidth() + xoffset - 1; + int len = int(getClientWidth()) + xoffset - 1; if ( len > int(h.size()) ) len = int(h.size()); @@ -1618,7 +1620,7 @@ void FListView::drawList() while ( y < uInt(getClientHeight()) ) { setPrintPos (2, 2 + int(y)); - print (FString(getClientWidth(), ' ')); + print (FString(std::size_t(getClientWidth()), ' ')); y++; } } @@ -1628,7 +1630,7 @@ void FListView::drawListLine ( const FListViewItem* item , bool is_focus , bool is_current ) { - uInt indent = item->getDepth() << 1; // indent = 2 * depth + std::size_t indent = item->getDepth() << 1; // indent = 2 * depth // Set line color and attributes setLineAttributes (is_current, is_focus); @@ -1639,19 +1641,19 @@ void FListView::drawListLine ( const FListViewItem* item // Print columns if ( ! item->column_list.empty() ) { - for (uInt i = 0; i < item->column_list.size(); ) + for (std::size_t i = 0; i < item->column_list.size(); ) { - static const int leading_space = 1; - static const int ellipsis_length = 2; + static const std::size_t leading_space = 1; + static const std::size_t ellipsis_length = 2; const FString& text = item->column_list[i]; - int width = header[i].width; - uInt txt_length = text.getLength(); + std::size_t width = std::size_t(header[i].width); + std::size_t txt_length = text.getLength(); // Increment the value of i for the column position // and the next iteration i++; fc::text_alignment align = getColumnAlignment(int(i)); - uInt align_offset = getAlignOffset (align, txt_length, uInt(width)); + std::size_t align_offset = getAlignOffset (align, txt_length, width); if ( tree_view && i == 1 ) { @@ -1663,12 +1665,12 @@ void FListView::drawListLine ( const FListViewItem* item if ( align_offset > 0 ) line += FString(align_offset, L' '); - if ( align_offset + txt_length <= uInt(width) ) + if ( align_offset + txt_length <= width ) { // Insert text and trailing space line += text.left(width); line += FString ( leading_space + width - - int(align_offset + txt_length), L' '); + - align_offset + txt_length, L' '); } else if ( align == fc::alignRight ) { @@ -1686,16 +1688,16 @@ void FListView::drawListLine ( const FListViewItem* item } } - line = line.mid ( uInt(1 + xoffset) - , uInt(getWidth() - nf_offset - 2) ); + line = line.mid ( std::size_t(xoffset) + 1 + , getWidth() - std::size_t(nf_offset) - 2); const wchar_t* const& element_str = line.wc_str(); - uInt len = line.getLength(); - uInt i; + std::size_t len = line.getLength(); + std::size_t i; for (i = 0; i < len; i++) *this << element_str[i]; - for (; i < uInt(getWidth() - nf_offset - 2); i++) + for (; i < getWidth() - std::size_t(nf_offset) - 2; i++) print (' '); } @@ -1736,7 +1738,7 @@ inline void FListView::setLineAttributes ( bool is_current //---------------------------------------------------------------------- inline FString FListView::getLinePrefix ( const FListViewItem* item - , uInt indent ) + , std::size_t indent ) { FString line = ""; @@ -1771,30 +1773,30 @@ inline FString FListView::getLinePrefix ( const FListViewItem* item void FListView::drawColumnText (headerItems::const_iterator& iter) { // Print lable text - static const int leading_space = 1; - static const int trailing_space = 1; + static const std::size_t leading_space = 1; + static const std::size_t trailing_space = 1; const FString& text = iter->name; - int width = iter->width; + std::size_t width = std::size_t(iter->width); FString txt = " " + text; - uInt txt_length = txt.getLength(); - int column_width = leading_space + width; + std::size_t txt_length = txt.getLength(); + std::size_t column_width = leading_space + width; if ( isEnabled() ) setColor (wc.label_emphasis_fg, wc.label_bg); else setColor (wc.label_inactive_fg, wc.label_inactive_bg); - if ( txt_length <= uInt(column_width) ) + if ( txt_length <= column_width ) { headerline << txt; - if ( txt_length < uInt(column_width) ) + if ( txt_length < column_width ) headerline << ' '; // trailing space - if ( txt_length + trailing_space < uInt(column_width) ) + if ( txt_length + trailing_space < column_width ) { setColor(); - const FString line ( uInt(column_width) - trailing_space - txt_length + const FString line ( column_width - trailing_space - txt_length , wchar_t(fc::BoxDrawingsHorizontal) ); headerline << line; // horizontal line } @@ -1884,10 +1886,10 @@ void FListView::recalculateHorizontalBar (int len) max_line_width = len; - if ( len >= getWidth() - nf_offset - 3 ) + if ( len >= int(getWidth()) - nf_offset - 3 ) { - hbar->setMaximum (max_line_width - getWidth() + nf_offset + 4); - hbar->setPageSize (max_line_width, getWidth() - nf_offset - 4); + hbar->setMaximum (max_line_width - int(getWidth()) + nf_offset + 4); + hbar->setPageSize (max_line_width, int(getWidth()) - nf_offset - 4); hbar->calculateSliderValues(); if ( ! hbar->isVisible() ) @@ -1898,11 +1900,11 @@ void FListView::recalculateHorizontalBar (int len) //---------------------------------------------------------------------- void FListView::recalculateVerticalBar (int element_count) { - vbar->setMaximum (element_count - getHeight() + 2); - vbar->setPageSize (element_count, getHeight() - 2); + vbar->setMaximum (element_count - int(getHeight()) + 2); + vbar->setPageSize (element_count, int(getHeight()) - 2); vbar->calculateSliderValues(); - if ( ! vbar->isVisible() && element_count >= getHeight() - 1 ) + if ( ! vbar->isVisible() && element_count >= int(getHeight()) - 1 ) vbar->setVisible(); } @@ -1988,7 +1990,7 @@ bool FListView::dragScrollDown (int position_before) void FListView::dragUp (int mouse_button) { if ( drag_scroll != fc::noScroll - && scroll_distance < getClientHeight() ) + && scroll_distance < int(getClientHeight()) ) scroll_distance++; if ( ! scroll_timer && current_iter.getPosition() > 0 ) @@ -2013,7 +2015,7 @@ void FListView::dragUp (int mouse_button) void FListView::dragDown (int mouse_button) { if ( drag_scroll != fc::noScroll - && scroll_distance < getClientHeight() ) + && scroll_distance < int(getClientHeight()) ) scroll_distance++; if ( ! scroll_timer && current_iter.getPosition() <= int(getCount()) ) @@ -2121,7 +2123,7 @@ inline void FListView::keyLeft (int& first_line_position_before) //---------------------------------------------------------------------- inline void FListView::keyRight (int& first_line_position_before) { - int xoffset_end = max_line_width - getClientWidth(); + int xoffset_end = max_line_width - int(getClientWidth()); FListViewItem* item = getCurrentItem(); if ( tree_view && item->isExpandable() && ! item->isExpand() ) @@ -2299,7 +2301,7 @@ void FListView::stepBackward (int distance) //---------------------------------------------------------------------- void FListView::scrollToX (int x) { - int xoffset_end = max_line_width - getClientWidth(); + int xoffset_end = max_line_width - int(getClientWidth()); if ( xoffset == x ) return; @@ -2316,7 +2318,7 @@ void FListView::scrollToX (int x) //---------------------------------------------------------------------- void FListView::scrollToY (int y) { - int pagesize = getClientHeight() - 1; + int pagesize = int(getClientHeight()) - 1; int element_count = int(getCount()); if ( first_visible_line.getPosition() == y ) @@ -2375,14 +2377,14 @@ void FListView::cb_VBarChange (FWidget*, data_ptr) break; case FScrollbar::scrollPageBackward: - distance = getClientHeight(); + distance = int(getClientHeight()); // fall through case FScrollbar::scrollStepBackward: stepBackward(distance); break; case FScrollbar::scrollPageForward: - distance = getClientHeight(); + distance = int(getClientHeight()); // fall through case FScrollbar::scrollStepForward: stepForward(distance); @@ -2435,14 +2437,14 @@ void FListView::cb_HBarChange (FWidget*, data_ptr) break; case FScrollbar::scrollPageBackward: - distance = getClientWidth(); + distance = int(getClientWidth()); // fall through case FScrollbar::scrollStepBackward: scrollBy (-distance, 0); break; case FScrollbar::scrollPageForward: - distance = getClientWidth(); + distance = int(getClientWidth()); // fall through case FScrollbar::scrollStepForward: scrollBy (distance, 0); diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 79c3a134..7d6f51cc 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -495,9 +495,9 @@ void FMenu::calculateDimensions() // find the maximum item width while ( iter != last ) { - uInt item_width = (*iter)->getTextLength() + 2; - int accel_key = (*iter)->accel_key; - bool has_menu = (*iter)->hasMenu(); + std::size_t item_width = (*iter)->getTextLength() + 2; + int accel_key = (*iter)->accel_key; + bool has_menu = (*iter)->hasMenu(); if ( has_menu ) { @@ -505,7 +505,7 @@ void FMenu::calculateDimensions() } else if ( accel_key ) { - uInt accel_len = getKeyName(accel_key).getLength(); + std::size_t accel_len = getKeyName(accel_key).getLength(); item_width += accel_len + 2; } @@ -521,7 +521,7 @@ void FMenu::calculateDimensions() adjust_X = adjustX(getX()); // set widget geometry - setGeometry (adjust_X, getY(), int(max_item_width + 2), int(getCount() + 2)); + setGeometry (adjust_X, getY(), max_item_width + 2, getCount() + 2); // set geometry of all items iter = item_list.begin(); @@ -530,7 +530,7 @@ void FMenu::calculateDimensions() while ( iter != last ) { - (*iter)->setGeometry (item_X, item_Y, int(max_item_width), 1); + (*iter)->setGeometry (item_X, item_Y, max_item_width, 1); if ( (*iter)->hasMenu() ) { @@ -579,9 +579,9 @@ void FMenu::adjustItems() int FMenu::adjustX (int x_pos) { // Is menu outside on the right of the screen? - if ( x_pos + int(max_item_width) >= getDesktopWidth() - 1 ) + if ( x_pos + int(max_item_width) >= int(getDesktopWidth() - 1) ) { - x_pos = getDesktopWidth() - int(max_item_width + 1); + x_pos = int(getDesktopWidth() - max_item_width + 1); // Menu to large for the screen if ( x_pos < 1 ) x_pos = 1; @@ -689,7 +689,7 @@ bool FMenu::mouseDownOverList (FPoint mouse_pos) while ( iter != last ) { int x1 = (*iter)->getX() - , x2 = (*iter)->getX() + (*iter)->getWidth() + , x2 = (*iter)->getX() + int((*iter)->getWidth()) , y = (*iter)->getY() , mouse_x = mouse_pos.getX() , mouse_y = mouse_pos.getY(); @@ -780,7 +780,7 @@ bool FMenu::mouseUpOverList (FPoint mouse_pos) while ( iter != last ) { int x1 = (*iter)->getX() - , x2 = (*iter)->getX() + (*iter)->getWidth() + , x2 = (*iter)->getX() + int((*iter)->getWidth()) , y = (*iter)->getY() , mouse_x = mouse_pos.getX() , mouse_y = mouse_pos.getY(); @@ -840,7 +840,7 @@ void FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& ms) while ( iter != last ) { int x1 = (*iter)->getX() - , x2 = (*iter)->getX() + (*iter)->getWidth() + , x2 = (*iter)->getX() + int((*iter)->getWidth()) , y = (*iter)->getY() , mouse_x = mouse_pos.getX() , mouse_y = mouse_pos.getY(); @@ -1222,14 +1222,16 @@ bool FMenu::hotkeyMenu (FKeyEvent* ev) } //---------------------------------------------------------------------- -int FMenu::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) +int FMenu::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // Find hotkey position in string // + generate a new string without the '&'-sign int pos = -1; wchar_t* txt = src; - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { if ( i < length && txt[i] == L'&' && pos == -1 ) { @@ -1294,14 +1296,16 @@ inline void FMenu::drawSeparator (int y) if ( isNewFont() ) { print (fc::NF_border_line_vertical_right); - FString line(getWidth() - 2, wchar_t(fc::BoxDrawingsHorizontal)); + FString line ( std::size_t(getWidth()) - 2 + , wchar_t(fc::BoxDrawingsHorizontal) ); print (line); print (fc::NF_rev_border_line_vertical_left); } else { print (fc::BoxDrawingsVerticalAndRight); - FString line(getWidth() - 2, wchar_t(fc::BoxDrawingsHorizontal)); + FString line ( std::size_t(getWidth()) - 2 + , wchar_t(fc::BoxDrawingsHorizontal)); print (line); print (fc::BoxDrawingsVerticalAndLeft); } @@ -1315,8 +1319,8 @@ inline void FMenu::drawMenuLine (FMenuItem* menuitem, int y) { FString txt = menuitem->getText(); menuText txtdata; - uInt txt_length = uInt(txt.getLength()); - int to_char = int(txt_length); + std::size_t txt_length = txt.getLength(); + std::size_t to_char = txt_length; int accel_key = menuitem->accel_key; bool is_enabled = menuitem->isEnabled(); bool is_selected = menuitem->isSelected(); @@ -1421,7 +1425,7 @@ inline void FMenu::drawMenuText (menuText& data) { // Print menu text - for (int z = 0; z < data.length; z++) + for (std::size_t z = 0; z < data.length; z++) { if ( ! std::iswprint(wint_t(data.text[z])) ) { @@ -1434,7 +1438,7 @@ inline void FMenu::drawMenuText (menuText& data) } } - if ( z == data.hotkeypos ) + if ( int(z) == data.hotkeypos ) { setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); @@ -1454,10 +1458,10 @@ inline void FMenu::drawMenuText (menuText& data) } //---------------------------------------------------------------------- -inline void FMenu::drawSubMenuIndicator (int& startpos) +inline void FMenu::drawSubMenuIndicator (std::size_t& startpos) { - int c = ( has_checkable_items ) ? 1 : 0; - int len = int(max_item_width) - (startpos + c + 3); + std::size_t c = ( has_checkable_items ) ? 1 : 0; + std::size_t len = max_item_width - (startpos + c + 3); if ( len > 0 ) { @@ -1465,33 +1469,34 @@ inline void FMenu::drawSubMenuIndicator (int& startpos) print (FString(len, wchar_t(' '))); // Print BlackRightPointingPointer ► print (wchar_t(fc::BlackRightPointingPointer)); - startpos = int(max_item_width) - (c + 2); + startpos = max_item_width - (c + 2); } } //---------------------------------------------------------------------- -inline void FMenu::drawAcceleratorKey (int& startpos, int accel_key) +inline void FMenu::drawAcceleratorKey (std::size_t& startpos, int accel_key) { FString accel_name (getKeyName(accel_key)); - int c = ( has_checkable_items ) ? 1 : 0; - int accel_len = int(accel_name.getLength()); - int len = int(max_item_width) - (startpos + accel_len + c + 2); + std::size_t c = ( has_checkable_items ) ? 1 : 0; + std::size_t accel_len = accel_name.getLength(); + std::size_t len = max_item_width - (startpos + accel_len + c + 2); if ( len > 0 ) { // Print filling blank spaces + accelerator key name FString spaces (len, wchar_t(' ')); print (spaces + accel_name); - startpos = int(max_item_width) - (c + 2); + startpos = max_item_width - (c + 2); } } //---------------------------------------------------------------------- -inline void FMenu::drawTrailingSpaces (int startpos) +inline void FMenu::drawTrailingSpaces (std::size_t startpos) { - int c = ( has_checkable_items ) ? 1 : 0; + std::size_t c = ( has_checkable_items ) ? 1 : 0; + // Print trailing blank space - for (uInt i = uInt(startpos + c); i < max_item_width - 1; i++) + for (std::size_t i = startpos + c; i < max_item_width - 1; i++) print (' '); } diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 74207f4d..9af70023 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -72,12 +72,9 @@ void FMenuBar::hide() setColor (fg, bg); screenWidth = getDesktopWidth(); - if ( screenWidth < 0 ) - return; - try { - blank = new char[std::size_t(screenWidth) + 1]; + blank = new char[screenWidth + 1]; } catch (const std::bad_alloc& ex) { @@ -85,9 +82,9 @@ void FMenuBar::hide() return; } - std::memset(blank, ' ', std::size_t(screenWidth)); + std::memset(blank, ' ', screenWidth); blank[screenWidth] = '\0'; - setPrintPos (1,1); + setPrintPos (1, 1); print (blank); delete[] blank; } @@ -256,7 +253,7 @@ void FMenuBar::cb_item_deactivated (FWidget* widget, data_ptr) void FMenuBar::init() { FWidget* r = getRootWidget(); - int w = r->getWidth(); + std::size_t w = r->getWidth(); // initialize geometry values setGeometry (1, 1, w, 1, false); setAlwaysOnTop(); @@ -285,11 +282,11 @@ void FMenuBar::calculateDimensions() // find the maximum item width while ( iter != last ) { - uInt len = (*iter)->getTextLength(); - int item_width = int(len + 2); + std::size_t len = (*iter)->getTextLength(); + int item_width = int(len) + 2; // set item geometry - (*iter)->setGeometry (item_X, item_Y, item_width, 1, false); + (*iter)->setGeometry (item_X, item_Y, std::size_t(item_width), 1, false); // set menu position if ( (*iter)->hasMenu() ) @@ -497,14 +494,16 @@ bool FMenuBar::hotkeyMenu (FKeyEvent*& ev) } //---------------------------------------------------------------------- -int FMenuBar::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) +int FMenuBar::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign int hotkeypos = -1; wchar_t* txt = src; - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { if ( i < length && txt[i] == L'&' && hotkeypos == -1 ) { @@ -550,7 +549,7 @@ void FMenuBar::drawItems() } // Print spaces to end of line - for (; x <= screenWidth; x++) + for (; x <= int(screenWidth); x++) print (' '); if ( isMonochron() ) @@ -562,13 +561,13 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, int& x) { FString txt = menuitem->getText(); menuText txtdata; - uInt txt_length = txt.getLength(); + std::size_t txt_length = txt.getLength(); + std::size_t to_char; int hotkeypos; - int to_char; bool is_enabled = menuitem->isEnabled(); bool is_selected = menuitem->isSelected(); - txtdata.startpos = x + 1; + txtdata.startpos = std::size_t(x) + 1; txtdata.no_underline = ((menuitem->getFlags() & fc::no_underline) != 0); // Set screen attributes @@ -585,10 +584,10 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, int& x) return; } - if ( x - 1 <= screenWidth ) - to_char = int(txt_length); + if ( x - 1 <= int(screenWidth) ) + to_char = txt_length; else - to_char = int(txt_length) - (screenWidth - x - 1); + to_char = txt_length - screenWidth - std::size_t(x) - 1; hotkeypos = getHotkeyPos (txt.wc_str(), txtdata.text, txt_length); @@ -654,9 +653,9 @@ inline void FMenuBar::drawMenuText (menuText& data) { // Print menu text - for (int z = 0; z < data.length; z++) + for (std::size_t z = 0; z < data.length; z++) { - if ( data.startpos > screenWidth - z ) + if ( data.startpos > std::size_t(screenWidth) - z ) break; if ( ! std::iswprint(wint_t(data.text[z])) ) @@ -669,7 +668,7 @@ inline void FMenuBar::drawMenuText (menuText& data) } } - if ( z == data.hotkeypos ) + if ( int(z) == data.hotkeypos ) { setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); @@ -691,18 +690,18 @@ inline void FMenuBar::drawMenuText (menuText& data) //---------------------------------------------------------------------- inline void FMenuBar::drawEllipsis (menuText& txtdata, int x) { - if ( x > screenWidth + 1 ) + if ( x > int(screenWidth) + 1 ) { if ( txtdata.startpos < screenWidth ) { // Print ellipsis - setPrintPos (screenWidth - 1, 1); + setPrintPos (int(screenWidth) - 1, 1); print (".."); } else if ( txtdata.startpos - 1 <= screenWidth ) { // Hide first character from text - setPrintPos (screenWidth, 1); + setPrintPos (int(screenWidth), 1); print (' '); } } @@ -713,7 +712,7 @@ inline void FMenuBar::drawLeadingSpace (int& x) { // Print a leading blank space - if ( x < screenWidth ) + if ( x < int(screenWidth) ) { x++; print (' '); @@ -725,7 +724,7 @@ inline void FMenuBar::drawTrailingSpace (int& x) { // Print a trailing blank space - if ( x < screenWidth ) + if ( x < int(screenWidth) ) { x++; print (' '); @@ -744,7 +743,7 @@ void FMenuBar::adjustItems() while ( iter != last ) { // get item width - int item_width = (*iter)->getWidth(); + int item_width = int((*iter)->getWidth()); if ( (*iter)->hasMenu() ) { @@ -874,7 +873,7 @@ void FMenuBar::mouseDownOverList (FMouseEvent* ev) { int x1, x2; x1 = (*iter)->getX(); - x2 = (*iter)->getX() + (*iter)->getWidth(); + x2 = (*iter)->getX() + int((*iter)->getWidth()); if ( mouse_y == 1 ) { @@ -924,7 +923,7 @@ void FMenuBar::mouseUpOverList (FMouseEvent* ev) { int x1, x2; x1 = (*iter)->getX(); - x2 = (*iter)->getX() + (*iter)->getWidth(); + x2 = (*iter)->getX() + int((*iter)->getWidth()); if ( mouse_y == 1 && mouse_x >= x1 @@ -974,7 +973,7 @@ void FMenuBar::mouseMoveOverList (FMouseEvent* ev) { int x1, x2; x1 = (*iter)->getX(); - x2 = (*iter)->getX() + (*iter)->getWidth(); + x2 = (*iter)->getX() + int((*iter)->getWidth()); if ( mouse_x >= x1 && mouse_x < x2 diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index b866371c..7bd62ff7 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -227,7 +227,7 @@ void FMenuItem::setText (const FString& txt) if ( hotkey ) text_length--; - setWidth(int(text_length)); + setWidth(text_length); } //---------------------------------------------------------------------- @@ -566,13 +566,13 @@ FMenuList* FMenuItem::getFMenuList (FWidget& widget) if ( isMenu(&widget) ) { - FMenu* menu = static_cast(&widget); - menu_list = static_cast(menu); + FMenu* Menu = static_cast(&widget); + menu_list = static_cast(Menu); } else if ( isMenuBar(&widget) ) { - FMenuBar* menubar = static_cast(&widget); - menu_list = static_cast(menubar); + FMenuBar* Menubar = static_cast(&widget); + menu_list = static_cast(Menubar); } else menu_list = 0; @@ -589,7 +589,7 @@ void FMenuItem::init (FWidget* parent) if ( hotkey ) text_length--; - setGeometry (1, 1, int(text_length + 2), 1, false); + setGeometry (1, 1, text_length + 2, 1, false); if ( ! parent ) return; @@ -629,14 +629,14 @@ void FMenuItem::init (FWidget* parent) //---------------------------------------------------------------------- uChar FMenuItem::hotKey() { - uInt length; + std::size_t length; if ( text.isEmpty() ) return 0; length = text.getLength(); - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { try { diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index a8e660a7..1cef1720 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -159,9 +159,9 @@ void FMessageBox::setHeadline (const FString& headline) setHeight(getHeight() + 2, true); for (uInt n = 0; n < num_buttons; n++) - button[n]->setY (getHeight() - 4, false); + button[n]->setY (int(getHeight()) - 4, false); - uInt len = headline_text.getLength(); + std::size_t len = headline_text.getLength(); if ( len > max_line_width ) max_line_width = len; @@ -172,13 +172,13 @@ void FMessageBox::setText (const FString& txt) { text = txt; calculateDimensions(); - button[0]->setY (getHeight() - 4, false); + button[0]->setY (int(getHeight()) - 4, false); if ( button_digit[1] != 0 ) - button[1]->setY (getHeight() - 4, false); + button[1]->setY (int(getHeight()) - 4, false); if ( button_digit[2] != 0 ) - button[2]->setY (getHeight() - 4, false); + button[2]->setY (int(getHeight()) - 4, false); adjustButtons(); } @@ -279,10 +279,9 @@ int FMessageBox::error ( FWidget* parent //---------------------------------------------------------------------- void FMessageBox::adjustSize() { - int X - , Y - , max_width - , max_height; + int X, Y; + std::size_t max_width; + std::size_t max_height; FWidget* root_widget = getRootWidget(); if ( root_widget ) @@ -350,7 +349,7 @@ inline void FMessageBox::allocation (int button0, int button1, int button2) { button[0] = new FButton (this); button[0]->setText(button_text[button0]); - button[0]->setPos(3, getHeight() - 4, false); + button[0]->setPos(3, int(getHeight()) - 4, false); button[0]->setWidth(1, false); button[0]->setHeight(1, false); button[0]->setFocus(); @@ -359,7 +358,7 @@ inline void FMessageBox::allocation (int button0, int button1, int button2) { button[1] = new FButton(this); button[1]->setText(button_text[button1]); - button[1]->setPos(17, getHeight() - 4, false); + button[1]->setPos(17, int(getHeight()) - 4, false); button[1]->setWidth(0, false); button[1]->setHeight(1, false); } @@ -368,7 +367,7 @@ inline void FMessageBox::allocation (int button0, int button1, int button2) { button[2] = new FButton(this); button[2]->setText(button_text[button2]); - button[2]->setPos(32, getHeight() - 4, false); + button[2]->setPos(32, int(getHeight()) - 4, false); button[2]->setWidth(0, false); button[2]->setHeight(1, false); } @@ -424,8 +423,9 @@ inline void FMessageBox::initCallbacks() //---------------------------------------------------------------------- void FMessageBox::calculateDimensions() { - int x, y, w, h; - int headline_height = 0; + int x, y; + std::size_t w, h; + std::size_t headline_height = 0; FWidget* parent_widget = getParentWidget(); text_split = text.split("\n"); text_num_lines = uInt(text_split.size()); @@ -437,14 +437,14 @@ void FMessageBox::calculateDimensions() for (uInt i = 0; i < text_num_lines; i++) { - uInt len = text_components[i].getLength(); + std::size_t len = text_components[i].getLength(); if ( len > max_line_width ) max_line_width = len; } - h = int(text_num_lines) + 8 + headline_height; - w = int(max_line_width + 4); + h = text_num_lines + 8 + headline_height; + w = max_line_width + 4; if ( w < 20 ) w = 20; @@ -468,7 +468,7 @@ void FMessageBox::draw() int head_offset = 0; int center_x = 0; // center the whole block - int msg_x = int((getWidth() - int(max_line_width)) / 2); + int msg_x = int((getWidth() - max_line_width) / 2); if ( isMonochron() ) setReverse(true); @@ -476,7 +476,7 @@ void FMessageBox::draw() if ( ! headline_text.isNull() ) { setColor(emphasis_color, getBackgroundColor()); - uInt headline_length = headline_text.getLength(); + std::size_t headline_length = headline_text.getLength(); if ( center_text ) // center one line center_x = int((max_line_width - headline_length) / 2); @@ -490,7 +490,7 @@ void FMessageBox::draw() for (int i = 0; i < int(text_num_lines); i++) { - uInt line_length = text_components[i].getLength(); + std::size_t line_length = text_components[i].getLength(); if ( center_text ) // center one line center_x = int((max_line_width - line_length) / 2); @@ -506,9 +506,9 @@ void FMessageBox::draw() //---------------------------------------------------------------------- void FMessageBox::resizeButtons() { - uInt len[3], max_size; + std::size_t len[3], max_size; - for (uInt n = 0; n < num_buttons; n++) + for (std::size_t n = 0; n < num_buttons; n++) { len[n] = button[n]->getText().getLength(); @@ -530,17 +530,17 @@ void FMessageBox::resizeButtons() if ( max_size < 7 ) max_size = 7; - for (uInt n = 0; n < num_buttons; n++) - button[n]->setWidth(int(max_size + 3), false); + for (std::size_t n = 0; n < num_buttons; n++) + button[n]->setWidth(max_size + 3, false); } //---------------------------------------------------------------------- void FMessageBox::adjustButtons() { - static const int gap = 4; - int btn_width = 0; + static const std::size_t gap = 4; + std::size_t btn_width = 0; - for (uInt n = 0; n < num_buttons; n++) + for (std::size_t n = 0; n < num_buttons; n++) { if ( n == num_buttons - 1 ) btn_width += button[n]->getWidth(); @@ -550,7 +550,7 @@ void FMessageBox::adjustButtons() if ( btn_width >= getWidth() - 4 ) { - int max_width; + std::size_t max_width; FWidget* root_widget = getRootWidget(); setWidth(btn_width + 5); max_width = ( root_widget ) ? root_widget->getClientWidth() : 80; @@ -559,14 +559,14 @@ void FMessageBox::adjustButtons() int btn_x = int((getWidth() - btn_width) / 2); - for (uInt n = 0; n < num_buttons; n++) + for (std::size_t n = 0; n < num_buttons; n++) { if ( n == 0 ) button[n]->setX(btn_x); else { - int btn_size = button[n]->getWidth(); - button[n]->setX( btn_x + int(n) * (btn_size + gap) ); + int btn_size = int(button[n]->getWidth()); + button[n]->setX(btn_x + int(n) * (btn_size + int(gap))); } } } diff --git a/src/fmouse.cpp b/src/fmouse.cpp index b010af73..efece03e 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -700,7 +700,7 @@ void FMouseSGR::setRawData (FKeyboard::keybuffer& fifo_buf) std::size_t len = std::strlen(fifo_buf); std::size_t n = 3; - while ( n < len && n < MOUSE_BUF_SIZE + 3 ) + while ( n < len && n <= MOUSE_BUF_SIZE + 1 ) { sgr_mouse[n - 3] = fifo_buf[n]; n++; @@ -954,7 +954,7 @@ void FMouseUrxvt::setRawData (FKeyboard::keybuffer& fifo_buf) std::size_t len = std::strlen(fifo_buf); std::size_t n = 2; - while ( n < len && n < MOUSE_BUF_SIZE + 2 ) + while ( n < len && n <= MOUSE_BUF_SIZE ) { urxvt_mouse[n - 2] = fifo_buf[n]; n++; diff --git a/src/foptimove.cpp b/src/foptimove.cpp index d198408c..dfbc3471 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -102,7 +102,7 @@ void FOptiMove::setTabStop (int t) } //---------------------------------------------------------------------- -void FOptiMove::setTermSize (int w, int h) +void FOptiMove::setTermSize (std::size_t w, std::size_t h) { assert ( w > 0 ); assert ( h > 0 ); @@ -493,10 +493,10 @@ void FOptiMove::set_clr_eol (char cap[]) void FOptiMove::check_boundaries ( int& xold, int& yold , int& xnew, int& ynew ) { - if ( xold < 0 || xold >= screen_width ) + if ( xold < 0 || xold >= int(screen_width) ) xold = -1; - if ( yold < 0 || yold >= screen_height ) + if ( yold < 0 || yold >= int(screen_height) ) yold = -1; if ( xnew < 0 ) @@ -505,11 +505,11 @@ void FOptiMove::check_boundaries ( int& xold, int& yold if ( ynew < 0 ) ynew = 0; - if ( xnew >= screen_width ) - xnew = screen_width - 1; + if ( xnew >= int(screen_width) ) + xnew = int(screen_width) - 1; - if ( ynew >= screen_height ) - ynew = screen_height - 1; + if ( ynew >= int(screen_height) ) + ynew = int(screen_height) - 1; } //---------------------------------------------------------------------- @@ -962,7 +962,7 @@ inline bool FOptiMove::isWideMove ( int xold, int yold , int xnew, int ynew ) { return bool ( xnew > MOVE_LIMIT - && xnew < screen_width - 1 - MOVE_LIMIT + && xnew < int(screen_width) - 1 - MOVE_LIMIT && std::abs(xnew - xold) + std::abs(ynew - yold) > MOVE_LIMIT ); } @@ -1066,7 +1066,7 @@ inline bool FOptiMove::isMethod4Faster ( int& move_time char null_result[BUF_SIZE]; char* null_ptr = null_result; int new_time = relativeMove ( null_ptr - , 0, screen_height - 1 + , 0, int(screen_height) - 1 , xnew, ynew ); if ( new_time < LONG_DURATION @@ -1094,7 +1094,7 @@ inline bool FOptiMove::isMethod5Faster ( int& move_time char null_result[BUF_SIZE]; char* null_ptr = null_result; int new_time = relativeMove ( null_ptr - , screen_width - 1, yold - 1 + , int(screen_width) - 1, yold - 1 , xnew, ynew ); if ( new_time < LONG_DURATION @@ -1145,7 +1145,7 @@ void FOptiMove::moveByMethod ( int method std::strncpy (move_ptr, F_cursor_to_ll.cap, BUF_SIZE - 1); move_ptr[BUF_SIZE - 1] ='\0'; move_ptr += F_cursor_to_ll.length; - relativeMove (move_ptr, 0, screen_height - 1, xnew, ynew); + relativeMove (move_ptr, 0, int(screen_height) - 1, xnew, ynew); break; case 5: @@ -1161,7 +1161,7 @@ void FOptiMove::moveByMethod ( int method , BUF_SIZE - std::strlen(move_ptr) ); move_ptr[BUF_SIZE - 1] ='\0'; move_ptr += std::strlen(move_buf); - relativeMove (move_ptr, screen_width - 1, yold - 1, xnew, ynew); + relativeMove (move_ptr, int(screen_width) - 1, yold - 1, xnew, ynew); break; default: diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 993b8c75..622b85d8 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -69,7 +69,7 @@ void FProgressbar::setPercentage (int percentage_value) } //---------------------------------------------------------------------- -void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust) +void FProgressbar::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Set the progress bar geometry @@ -99,7 +99,7 @@ bool FProgressbar::setShadow (bool on) //---------------------------------------------------------------------- void FProgressbar::hide() { - int s, size; + std::size_t s, size; short fg, bg; char* blank; FWidget* parent_widget = getParentWidget(); @@ -121,7 +121,7 @@ void FProgressbar::hide() s = hasShadow() ? 1 : 0; size = getWidth() + s; - if ( size < 0 ) + if ( size == 0 ) return; try @@ -137,14 +137,14 @@ void FProgressbar::hide() std::memset(blank, ' ', std::size_t(size)); blank[size] = '\0'; - for (int y = 0; y < getHeight() + s; y++) + for (int y = 0; y < int(getHeight() + s); y++) { setPrintPos (1, 1 + y); print (blank); } delete[] blank; - setPrintPos (getWidth() - 4, 0); + setPrintPos (int(getWidth()) - 4, 0); print (" "); // hide percentage } @@ -190,7 +190,7 @@ void FProgressbar::drawPercentage() if ( isMonochron() ) setReverse(true); - setPrintPos (getWidth() - 3, 0); + setPrintPos (int(getWidth()) - 3, 0); if ( percentage < 0 || percentage > 100 ) print ("--- %"); @@ -204,8 +204,8 @@ void FProgressbar::drawPercentage() //---------------------------------------------------------------------- void FProgressbar::drawBar() { - int i = 0; - double length = double(bar_length * percentage) / 100; + std::size_t i = 0; + double length = double(int(bar_length) * percentage) / 100; setPrintPos (1,1); setColor ( wc.progressbar_bg , wc.progressbar_fg ); diff --git a/src/frect.cpp b/src/frect.cpp index 1a4b7f16..7c4a0b35 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -115,37 +115,40 @@ void FRect::setPos (const FPoint& p) } //---------------------------------------------------------------------- -void FRect::setWidth (int w) +void FRect::setWidth (std::size_t w) { - X2 = short(X1 + w - 1); + X2 = short(X1 + short(w) - 1); } //---------------------------------------------------------------------- -void FRect::setHeight (int h) +void FRect::setHeight (std::size_t h) { - Y2 = short(Y1 + h - 1); + Y2 = short(Y1 + short(h) - 1); } //---------------------------------------------------------------------- -void FRect::setSize (int w, int h) +void FRect::setSize (std::size_t w, std::size_t h) { - X2 = short(X1 + w - 1); - Y2 = short(Y1 + h - 1); + X2 = short(X1 + short(w) - 1); + Y2 = short(Y1 + short(h) - 1); } //---------------------------------------------------------------------- void FRect::setRect (const FRect& r) { - setRect (r.X1, r.Y1, r.X2 - r.X1 + 1, r.Y2 - r.Y1 + 1); + setRect ( r.X1 + , r.Y1 + , std::size_t(r.X2 - r.X1 + 1) + , std::size_t(r.Y2 - r.Y1 + 1) ); } //---------------------------------------------------------------------- -void FRect::setRect (int x, int y, int width, int height) +void FRect::setRect (int x, int y, std::size_t width, std::size_t height) { X1 = short(x); Y1 = short(y); - X2 = short(x + width - 1); - Y2 = short(y + height - 1); + X2 = short(x + int(width) - 1); + Y2 = short(y + int(height) - 1); } //---------------------------------------------------------------------- @@ -248,8 +251,8 @@ FRect operator + (const FRect& r, const FPoint& p) { return FRect ( r.X1 , r.Y1 - , r.X2 - r.X1 + 1 + p.getX() - , r.Y2 - r.Y1 + 1 + p.getY() ); + , std::size_t(r.X2 - r.X1 + 1 + p.getX()) + , std::size_t(r.Y2 - r.Y1 + 1 + p.getY()) ); } //---------------------------------------------------------------------- @@ -257,8 +260,8 @@ FRect operator - (const FRect& r, const FPoint& p) { return FRect ( r.X1 , r.Y1 - , r.X2 - r.X1 + 1 - p.getX() - , r.Y2 - r.Y1 + 1 - p.getY() ); + , std::size_t(r.X2 - r.X1 + 1 - p.getX()) + , std::size_t(r.Y2 - r.Y1 + 1 - p.getY()) ); } //---------------------------------------------------------------------- diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index 8648c0f4..21d4324f 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -152,7 +152,7 @@ void FScrollbar::setPageSize (int document_size, int page_size) //---------------------------------------------------------------------- void FScrollbar::setOrientation (int o) { - int nf = 0; + std::size_t nf = 0; length = ( getHeight() > getWidth() ) ? getHeight() : getWidth(); if ( o == fc::vertical && bar_orientation == fc::horizontal ) @@ -174,13 +174,13 @@ void FScrollbar::setOrientation (int o) } //---------------------------------------------------------------------- -void FScrollbar::setGeometry (int x, int y, int w, int h, bool adjust) +void FScrollbar::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Set the scrollbar geometry FWidget::setGeometry (x, y, w, h, adjust); - int nf = 0; + std::size_t nf = 0; length = ( h > w ) ? h : w; if ( bar_orientation == fc::vertical ) @@ -223,7 +223,7 @@ void FScrollbar::calculateSliderValues() else bar_length = length - 2; - slider_length = int(double(bar_length) / steps); + slider_length = std::size_t(double(bar_length) / steps); if ( slider_length < 1 ) slider_length = 1; @@ -238,17 +238,18 @@ void FScrollbar::calculateSliderValues() if ( val == max ) { - slider_pos = bar_length - slider_length; + slider_pos = int(bar_length - slider_length); return; } - slider_pos = int( round ( double((bar_length - slider_length) * val) + std::size_t v = std::size_t(val); + slider_pos = int( round ( double((bar_length - slider_length) * v) / double(max - min) ) ); if ( slider_pos < 0 ) slider_pos = 0; - else if ( slider_pos > bar_length - slider_length ) - slider_pos = bar_length - slider_length; + else if ( slider_pos > int(bar_length - slider_length) ) + slider_pos = int(bar_length - slider_length); } //---------------------------------------------------------------------- @@ -280,7 +281,7 @@ void FScrollbar::drawVerticalBar() if ( isMonochron() ) setReverse(false); - for (z = 1; z <= slider_length; z++) + for (z = 1; z <= int(slider_length); z++) { setPrintPos (1, 1 + slider_pos + z); @@ -295,7 +296,7 @@ void FScrollbar::drawVerticalBar() setColor (wc.scrollbar_fg, wc.scrollbar_bg); - for (z = slider_pos + slider_length + 1; z <= bar_length; z++) + for (z = slider_pos + int(slider_length) + 1; z <= int(bar_length); z++) { setPrintPos (1, 1 + z); @@ -343,16 +344,16 @@ void FScrollbar::drawHorizontalBar() if ( isMonochron() ) setReverse(false); - for (z = 0; z < slider_length; z++) + for (z = 0; z < int(slider_length); z++) print (' '); if ( isMonochron() ) setReverse(true); setColor (wc.scrollbar_fg, wc.scrollbar_bg); - z = slider_pos + slider_length + 1; + z = slider_pos + int(slider_length) + 1; - for (; z <= bar_length; z++) + for (; z <= int(bar_length); z++) { if ( isNewFont() && max_color > 8 ) print (fc::NF_border_line_upper); // ¯ @@ -500,8 +501,8 @@ void FScrollbar::onMouseMove (FMouseEvent* ev) } } - if ( mouse_x < 1 || mouse_x > getWidth() - || mouse_y < 1 || mouse_y > getHeight() ) + if ( mouse_x < 1 || mouse_x > int(getWidth()) + || mouse_y < 1 || mouse_y > int(getHeight()) ) { delOwnTimer(); } @@ -554,7 +555,7 @@ void FScrollbar::onTimer (FTimerEvent*) || ( scroll_type == FScrollbar::scrollPageForward && slider_pos == slider_click_stop_pos ) ) { - int max_slider_pos = bar_length - slider_length; + int max_slider_pos = int(bar_length - slider_length); if ( scroll_type == FScrollbar::scrollPageBackward && slider_pos == 0 ) @@ -610,7 +611,7 @@ void FScrollbar::drawButtons() { print (fc::NF_rev_up_arrow1); print (fc::NF_rev_up_arrow2); - setPrintPos (1, length); + setPrintPos (1, int(length)); print (fc::NF_rev_down_arrow1); print (fc::NF_rev_down_arrow2); } @@ -618,7 +619,7 @@ void FScrollbar::drawButtons() { print (fc::NF_rev_left_arrow1); print (fc::NF_rev_left_arrow2); - setPrintPos (length - 1, 1); + setPrintPos (int(length) - 1, 1); print (fc::NF_rev_right_arrow1); print (fc::NF_rev_right_arrow2); } @@ -633,13 +634,13 @@ void FScrollbar::drawButtons() if ( bar_orientation == fc::vertical ) { print (fc::BlackUpPointingTriangle); // ▲ - setPrintPos (1, length); + setPrintPos (1, int(length)); print (fc::BlackDownPointingTriangle); // ▼ } else // horizontal { print (fc::BlackLeftPointingPointer); // ◄ - setPrintPos (length, 1); + setPrintPos (int(length), 1); print (fc::BlackRightPointingPointer); // ► } @@ -672,11 +673,11 @@ FScrollbar::sType FScrollbar::getVerticalClickedScrollType (int y) { return FScrollbar::scrollPageBackward; // before slider } - else if ( y > slider_pos + slider_length + 1 && y < getHeight() ) + else if ( y > slider_pos + int(slider_length) + 1 && y < int(getHeight()) ) { return FScrollbar::scrollPageForward; // after slider } - else if ( y == getHeight() ) + else if ( y == int(getHeight()) ) { return FScrollbar::scrollStepForward; // increment button } @@ -697,11 +698,11 @@ FScrollbar::sType FScrollbar::getHorizontalClickedScrollType (int x) { return FScrollbar::scrollPageBackward; // before slider } - else if ( x > slider_pos + slider_length + 2 && x < getWidth() - 1 ) + else if ( x > slider_pos + int(slider_length) + 2 && x < int(getWidth()) - 1 ) { return FScrollbar::scrollPageForward; // after slider } - else if ( x == getWidth() - 1 || x == getWidth() ) + else if ( x == int(getWidth()) - 1 || x == int(getWidth()) ) { return FScrollbar::scrollStepForward; // increment button } @@ -718,11 +719,11 @@ FScrollbar::sType FScrollbar::getHorizontalClickedScrollType (int x) { return FScrollbar::scrollPageBackward; // before slider } - else if ( x > slider_pos + slider_length + 1 && x < getWidth() ) + else if ( x > slider_pos + int(slider_length) + 1 && x < int(getWidth()) ) { return FScrollbar::scrollPageForward; // after slider } - else if ( x == getWidth() ) + else if ( x == int(getWidth()) ) { return FScrollbar::scrollStepForward; // increment button } @@ -739,7 +740,7 @@ int FScrollbar::getSliderClickPos (int mouse_x, int mouse_y) if ( bar_orientation == fc::vertical ) { if ( mouse_y > slider_pos + 1 - && mouse_y <= slider_pos + slider_length + 1 ) + && mouse_y <= slider_pos + int(slider_length) + 1 ) return mouse_y; // on slider } else // horizontal bar orientation @@ -747,13 +748,13 @@ int FScrollbar::getSliderClickPos (int mouse_x, int mouse_y) if ( isNewFont() ) { if ( mouse_x > slider_pos + 2 - && mouse_x <= slider_pos + slider_length + 2 ) + && mouse_x <= slider_pos + int(slider_length) + 2 ) return mouse_x; // on slider } else { if ( mouse_x > slider_pos + 1 - && mouse_x <= slider_pos + slider_length + 1 ) + && mouse_x <= slider_pos + int(slider_length) + 1 ) return mouse_x; // on slider } } @@ -768,7 +769,7 @@ void FScrollbar::jumpToClickPos (int x, int y) if ( bar_orientation == fc::vertical ) { - if ( y >1 && y < getHeight() ) + if ( y >1 && y < int(getHeight()) ) { new_val = int( round ( double(max - min) * (y - 2.0 - (slider_length/2)) / double(bar_length - slider_length) ) ); @@ -780,7 +781,7 @@ void FScrollbar::jumpToClickPos (int x, int y) { int nf = isNewFont() ? 1 : 0; - if ( x > 1 + nf && x < getWidth() - nf ) + if ( x > 1 + nf && x < int(getWidth()) - nf ) { new_val = int( round ( double(max - min) * (x - 2.0 - nf - (slider_length/2)) / double(bar_length - slider_length) ) ); diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 5da218f7..90172312 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -62,7 +62,7 @@ FScrollView::~FScrollView() // destructor // public methods of FScrollView //---------------------------------------------------------------------- -void FScrollView::setScrollWidth (int width) +void FScrollView::setScrollWidth (std::size_t width) { if ( width < getViewportWidth() ) width = getViewportWidth(); @@ -83,14 +83,14 @@ void FScrollView::setScrollWidth (int width) child_print_area = viewport; } - hbar->setMaximum (width - getViewportWidth()); - hbar->setPageSize (width, getViewportWidth()); + hbar->setMaximum (int(width - getViewportWidth())); + hbar->setPageSize (int(width), int(getViewportWidth())); hbar->calculateSliderValues(); setHorizontalScrollBarVisibility(); } //---------------------------------------------------------------------- -void FScrollView::setScrollHeight (int height) +void FScrollView::setScrollHeight (std::size_t height) { if ( height < getViewportHeight() ) height = getViewportHeight(); @@ -110,14 +110,14 @@ void FScrollView::setScrollHeight (int height) child_print_area = viewport; } - vbar->setMaximum (height - getViewportHeight()); - vbar->setPageSize (height, getViewportHeight()); + vbar->setMaximum (int(height - getViewportHeight())); + vbar->setPageSize (int(height), int(getViewportHeight())); vbar->calculateSliderValues(); setVerticalScrollBarVisibility(); } //---------------------------------------------------------------------- -void FScrollView::setScrollSize (int width, int height) +void FScrollView::setScrollSize (std::size_t width, std::size_t height) { int xoffset_end , yoffset_end; @@ -143,20 +143,20 @@ void FScrollView::setScrollSize (int width, int height) child_print_area = viewport; } - xoffset_end = getScrollWidth() - getViewportWidth(); - yoffset_end = getScrollHeight() - getViewportHeight(); + xoffset_end = int(getScrollWidth() - getViewportWidth()); + yoffset_end = int(getScrollHeight() - getViewportHeight()); setTopPadding (1 - getScrollY()); setLeftPadding (1 - getScrollX()); setBottomPadding (1 - (yoffset_end - getScrollY())); setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset); - hbar->setMaximum (width - getViewportWidth()); - hbar->setPageSize (width, getViewportWidth()); + hbar->setMaximum (int(width - getViewportWidth())); + hbar->setPageSize (int(width), int(getViewportWidth())); hbar->calculateSliderValues(); setHorizontalScrollBarVisibility(); - vbar->setMaximum (height - getViewportHeight()); - vbar->setPageSize (height, getViewportHeight()); + vbar->setMaximum (int(height - getViewportHeight())); + vbar->setPageSize (int(height), int(getViewportHeight())); vbar->calculateSliderValues(); setVerticalScrollBarVisibility(); } @@ -213,10 +213,10 @@ void FScrollView::setPos (int x, int y, bool adjust) } //---------------------------------------------------------------------- -void FScrollView::setWidth (int w, bool adjust) +void FScrollView::setWidth (std::size_t w, bool adjust) { FWidget::setWidth (w, adjust); - viewport_geometry.setWidth(w - vertical_border_spacing - nf_offset); + viewport_geometry.setWidth(w - vertical_border_spacing - std::size_t(nf_offset)); calculateScrollbarPos(); if ( getScrollWidth() < getViewportWidth() ) @@ -224,7 +224,7 @@ void FScrollView::setWidth (int w, bool adjust) } //---------------------------------------------------------------------- -void FScrollView::setHeight (int h, bool adjust) +void FScrollView::setHeight (std::size_t h, bool adjust) { FWidget::setHeight (h, adjust); viewport_geometry.setHeight(h - horizontal_border_spacing); @@ -235,10 +235,10 @@ void FScrollView::setHeight (int h, bool adjust) } //---------------------------------------------------------------------- -void FScrollView::setSize (int w, int h, bool adjust) +void FScrollView::setSize (std::size_t w, std::size_t h, bool adjust) { FWidget::setSize (w, h, adjust); - viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset + viewport_geometry.setSize ( w - vertical_border_spacing - std::size_t(nf_offset) , h - horizontal_border_spacing ); calculateScrollbarPos(); @@ -248,14 +248,14 @@ void FScrollView::setSize (int w, int h, bool adjust) } //---------------------------------------------------------------------- -void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust) +void FScrollView::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Set the scroll view geometry FWidget::setGeometry (x, y, w, h, adjust); scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1 , getTermY() + getTopPadding() - 1 ); - viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset + viewport_geometry.setSize ( w - vertical_border_spacing - std::size_t(nf_offset) , h - horizontal_border_spacing ); calculateScrollbarPos(); @@ -337,10 +337,10 @@ void FScrollView::scrollTo (int x, int y) short yoffset_before = yoffset; short xoffset_end = short(getScrollWidth() - getViewportWidth()); short yoffset_end = short(getScrollHeight() - getViewportHeight()); - int save_width = viewport_geometry.getWidth(); - int save_height = viewport_geometry.getHeight(); - bool changeX = false; - bool changeY = false; + std::size_t save_width = viewport_geometry.getWidth(); + std::size_t save_height = viewport_geometry.getHeight(); + bool changeX = false; + bool changeY = false; x--; y--; @@ -421,7 +421,7 @@ void FScrollView::draw() if ( border ) { if ( isNewFont() ) - drawBorder (1, 1, getWidth() - 1, getHeight()); + drawBorder (1, 1, int(getWidth()) - 1, int(getHeight())); else drawBorder(); } @@ -463,12 +463,12 @@ void FScrollView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_ppage: - scrollBy (0, -getViewportHeight()); + scrollBy (0, int(-getViewportHeight())); ev->accept(); break; case fc::Fkey_npage: - scrollBy (0, getViewportHeight()); + scrollBy (0, int(getViewportHeight())); ev->accept(); break; @@ -558,12 +558,12 @@ void FScrollView::onChildFocusIn (FFocusEvent*) , wy = widget_geometry.getY(); if ( wx > vx ) - x = widget_geometry.getX2() - vp_geometry.getWidth() + 1; + x = widget_geometry.getX2() - int(vp_geometry.getWidth()) + 1; else x = wx; if ( wy > vy ) - y = widget_geometry.getY2() - vp_geometry.getHeight() + 1; + y = widget_geometry.getY2() - int(vp_geometry.getHeight()) + 1; else y = wy; @@ -622,10 +622,10 @@ FVTerm::term_area* FScrollView::getPrintArea() void FScrollView::adjustSize() { FWidget::adjustSize(); - int width = getWidth() - , height = getHeight() - , xoffset = viewport_geometry.getX() - , yoffset = viewport_geometry.getY(); + std::size_t width = getWidth(); + std::size_t height = getHeight(); + int xoffset = viewport_geometry.getX(); + int yoffset = viewport_geometry.getY(); scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1 , getTermY() + getTopPadding() - 1 ); @@ -636,17 +636,17 @@ void FScrollView::adjustSize() viewport->offset_top = scroll_geometry.getY(); } - hbar->setMaximum (getScrollWidth() - getViewportWidth()); - hbar->setPageSize (getScrollWidth(), getViewportWidth()); - hbar->setY (height); + hbar->setMaximum (int(getScrollWidth() - getViewportWidth())); + hbar->setPageSize (int(getScrollWidth()), int(getViewportWidth())); + hbar->setY (int(height)); hbar->setWidth (width - 2, false); hbar->setValue (xoffset); hbar->resize(); setHorizontalScrollBarVisibility(); - vbar->setMaximum (getScrollHeight() - getViewportHeight()); - vbar->setPageSize (getScrollHeight(), getViewportHeight()); - vbar->setX (width); + vbar->setMaximum (int(getScrollHeight() - getViewportHeight())); + vbar->setPageSize (int(getScrollHeight()), int(getViewportHeight())); + vbar->setX (int(width)); vbar->setHeight (height - 2, false); vbar->setValue (yoffset); vbar->resize(); @@ -671,8 +671,8 @@ void FScrollView::copy2area() , ay = getTermY() - print_area->offset_top , dx = viewport_geometry.getX() , dy = viewport_geometry.getY() - , y_end = getViewportHeight() - , x_end = getViewportWidth(); + , y_end = int(getViewportHeight()) + , x_end = int(getViewportWidth()); // viewport width does not fit into the print_area if ( print_area->width <= ax + x_end ) @@ -737,8 +737,10 @@ void FScrollView::init (FWidget* parent) setForegroundColor (wc.dialog_fg); setBackgroundColor (wc.dialog_bg); init_scrollbar(); - xoffset_end = getScrollWidth() - getViewportWidth(); - yoffset_end = getScrollHeight() - getViewportHeight(); + setGeometry (1, 1, 4, 4); + setMinimumSize (4, 4); + xoffset_end = int(getScrollWidth() - getViewportWidth()); + yoffset_end = int(getScrollHeight() - getViewportHeight()); nf_offset = isNewFont() ? 1 : 0; setTopPadding (1 - getScrollY()); setLeftPadding (1 - getScrollX()); @@ -746,8 +748,8 @@ void FScrollView::init (FWidget* parent) setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset); FPoint no_shadow(0,0); - int w = getViewportWidth(); - int h = getViewportHeight(); + std::size_t w = getViewportWidth(); + std::size_t h = getViewportHeight(); if ( w < 1 ) w = 1; @@ -803,18 +805,18 @@ void FScrollView::init_scrollbar() //---------------------------------------------------------------------- void FScrollView::calculateScrollbarPos() { - int width = getWidth(); - int height = getHeight(); + std::size_t width = getWidth(); + std::size_t height = getHeight(); if ( isNewFont() ) { - vbar->setGeometry (width, 2, 2, height - 2); - hbar->setGeometry (1, height, width - 2, 1); + vbar->setGeometry (int(width), 2, 2, height - 2); + hbar->setGeometry (1, int(height), width - 2, 1); } else { - vbar->setGeometry (width, 2, 1, height - 2); - hbar->setGeometry (2, height, width - 2, 1); + vbar->setGeometry (int(width), 2, 1, height - 2); + hbar->setGeometry (2, int(height), width - 2, 1); } vbar->resize(); diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 623cb8f2..2d073909 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -205,12 +205,9 @@ void FStatusBar::hide() setColor (fg, bg); screenWidth = getDesktopWidth(); - if ( screenWidth < 0 ) - return; - try { - blank = new char[std::size_t(screenWidth) + 1]; + blank = new char[screenWidth + 1]; } catch (const std::bad_alloc& ex) { @@ -218,7 +215,7 @@ void FStatusBar::hide() return; } - std::memset(blank, ' ', std::size_t(screenWidth)); + std::memset(blank, ' ', screenWidth); blank[screenWidth] = '\0'; setPrintPos (1, 1); print (blank); @@ -228,7 +225,8 @@ void FStatusBar::hide() //---------------------------------------------------------------------- void FStatusBar::drawMessage() { - int termWidth, space_offset; + std::size_t termWidth; + int space_offset; bool isLastActiveFocus, hasKeys; if ( ! (isVisible() ) ) @@ -260,7 +258,7 @@ void FStatusBar::drawMessage() if ( isMonochron() ) setReverse(true); - if ( x + space_offset + 3 < termWidth ) + if ( x + space_offset + 3 < int(termWidth) ) { if ( text ) { @@ -277,21 +275,21 @@ void FStatusBar::drawMessage() print (' '); } - int msg_length = int(getMessage().getLength()); - x += msg_length; + std::size_t msg_length = getMessage().getLength(); + x += int(msg_length); - if ( x - 1 <= termWidth ) + if ( x - 1 <= int(termWidth) ) print (getMessage()); else { // Print ellipsis - print ( getMessage().left(uInt(msg_length + termWidth - x - 1)) ); + print ( getMessage().left(msg_length + termWidth - uInt(x) - 1) ); print (".."); } } } - for (int i = x; i <= termWidth; i++) + for (int i = x; i <= int(termWidth); i++) print (' '); if ( isMonochron() ) @@ -355,7 +353,7 @@ void FStatusBar::clear() //---------------------------------------------------------------------- void FStatusBar::adjustSize() { - setGeometry (1, getDesktopHeight(), getDesktopWidth(), 1, false); + setGeometry (1, int(getDesktopHeight()), getDesktopWidth(), 1, false); } //---------------------------------------------------------------------- @@ -554,8 +552,8 @@ void FStatusBar::cb_statuskey_activated (FWidget* widget, data_ptr) void FStatusBar::init() { FWidget* r = getRootWidget(); - int w = r->getWidth(); - int h = r->getHeight(); + std::size_t w = r->getWidth(); + int h = int(r->getHeight()); // initialize geometry values setGeometry (1, h, w, 1, false); setAlwaysOnTop(); @@ -604,7 +602,7 @@ void FStatusBar::drawKeys() { keyname_len = int(getKeyName((*iter)->getKey()).getLength()); - if ( x + keyname_len + 2 < screenWidth ) + if ( x + keyname_len + 2 < int(screenWidth) ) { if ( (*iter)->isActivated() || (*iter)->hasMouseFocus() ) drawActiveKey (iter); @@ -615,7 +613,7 @@ void FStatusBar::drawKeys() { setColor (wc.statusbar_fg, wc.statusbar_bg); - for (; x <= screenWidth; x++) + for (; x <= int(screenWidth); x++) print (' '); } @@ -633,7 +631,7 @@ void FStatusBar::drawKey (keyList::const_iterator iter) { // Draw not active key - int txt_length; + std::size_t txt_length; FStatusKey* item = *iter; setColor (wc.statusbar_hotkey_fg, wc.statusbar_hotkey_bg); @@ -644,23 +642,23 @@ void FStatusBar::drawKey (keyList::const_iterator iter) setColor (wc.statusbar_fg, wc.statusbar_bg); x++; print ('-'); - txt_length = int(item->getText().getLength()); - x += txt_length; + txt_length = item->getText().getLength(); + x += int(txt_length); - if ( x - 1 <= screenWidth ) + if ( x - 1 <= int(screenWidth) ) print (item->getText()); else { // Print ellipsis print ( item->getText() - .left(uInt(txt_length + screenWidth - x - 1)) ); + .left(txt_length + screenWidth - std::size_t(x) - 1) ); print (".."); } if ( iter + 1 != key_list.end() && ( (*(iter + 1))->isActivated() || (*(iter + 1))->hasMouseFocus() ) && x + int(getKeyName((*(iter + 1))->getKey()).getLength()) + 3 - < screenWidth ) + < int(screenWidth) ) { // Next element is active if ( isMonochron() ) @@ -679,7 +677,7 @@ void FStatusBar::drawKey (keyList::const_iterator iter) if ( isMonochron() ) setReverse(true); } - else if ( iter + 1 != key_list.end() && x < screenWidth ) + else if ( iter + 1 != key_list.end() && x < int(screenWidth) ) { // Not the last element setColor (wc.statusbar_separator_fg, wc.statusbar_bg); @@ -693,7 +691,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter) { // Draw active key - int txt_length; + std::size_t txt_length; FStatusKey* item = *iter; if ( isMonochron() ) @@ -708,10 +706,10 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter) setColor (wc.statusbar_active_fg, wc.statusbar_active_bg); x++; print ('-'); - txt_length = int(item->getText().getLength()); - x += txt_length; + txt_length = item->getText().getLength(); + x += int(txt_length); - if ( x <= screenWidth ) + if ( x <= int(screenWidth) ) { print (item->getText()); x++; @@ -721,7 +719,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter) { // Print ellipsis print ( item->getText() - .left(uInt(txt_length + screenWidth - x - 1)) ); + .left(txt_length + screenWidth - std::size_t(x) - 1) ); print (".."); } diff --git a/src/fstring.cpp b/src/fstring.cpp index 13c83e57..b6bcf696 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -53,13 +53,13 @@ FString::FString (int len) , c_string(0) { if ( len > 0 ) - initLength(uInt(len)); + initLength(std::size_t(len)); else initLength(0); } //---------------------------------------------------------------------- -FString::FString (uInt len) +FString::FString (std::size_t len) : string(0) , length(0) , bufsize(0) @@ -69,20 +69,7 @@ FString::FString (uInt len) } //---------------------------------------------------------------------- -FString::FString (int len, wchar_t c) - : string(0) - , length(0) - , bufsize(0) - , c_string(0) -{ - if ( len > 0 ) - _assign ( FString(uInt(len), c).string ); - else - initLength(0); -} - -//---------------------------------------------------------------------- -FString::FString (uInt len, wchar_t c) +FString::FString (std::size_t len, wchar_t c) : string(0) , length(0) , bufsize(0) @@ -100,25 +87,7 @@ FString::FString (uInt len, wchar_t c) } //---------------------------------------------------------------------- -FString::FString (int len, char c) - : string(0) - , length(0) - , bufsize(0) - , c_string(0) -{ - string = 0; - length = 0; - bufsize = 0; - c_string = 0; - - if ( len > 0 ) - _assign ( FString(uInt(len), c).string ); - else - initLength(0); -} - -//---------------------------------------------------------------------- -FString::FString (uInt len, char c) +FString::FString (std::size_t len, char c) : string(0) , length(0) , bufsize(0) @@ -475,17 +444,7 @@ const FString& FString::operator >> (float& num) } //---------------------------------------------------------------------- -wchar_t& FString::operator [] (int pos) -{ - if ( pos < 0 ) - throw std::out_of_range(""); // Invalid index position - - FString& s = *this; - return s[uInt(pos)]; -} - -//---------------------------------------------------------------------- -wchar_t& FString::operator [] (uInt pos) +wchar_t& FString::operator [] (std::size_t pos) { if ( pos >= length ) throw std::out_of_range(""); // Invalid index position @@ -502,9 +461,9 @@ const FString& FString::operator () () // public methods of FString //---------------------------------------------------------------------- -uInt FString::getUTF8length() const +std::size_t FString::getUTF8length() const { - uInt len; + std::size_t len; const char* s; if ( ! string ) @@ -514,7 +473,7 @@ uInt FString::getUTF8length() const s = c_str(); while ( *s ) - len += uInt((*s++ & 0xc0) != 0x80); + len += std::size_t((*s++ & 0xc0) != 0x80); return len; } @@ -902,16 +861,7 @@ FString FString::trim() const } //---------------------------------------------------------------------- -FString FString::left (int len) const -{ - if ( len > 0 ) - return left (uInt(len)); - else - return left (uInt(0)); -} - -//---------------------------------------------------------------------- -FString FString::left (uInt len) const +FString FString::left (std::size_t len) const { wchar_t* p; FString s(string); @@ -930,16 +880,7 @@ FString FString::left (uInt len) const } //---------------------------------------------------------------------- -FString FString::right (int len) const -{ - if ( len > 0 ) - return right (uInt(len)); - else - return right (uInt(0)); -} - -//---------------------------------------------------------------------- -FString FString::right (uInt len) const +FString FString::right (std::size_t len) const { wchar_t* p; FString s(string); @@ -957,21 +898,7 @@ FString FString::right (uInt len) const } //---------------------------------------------------------------------- -FString FString::mid (int pos, int len) const -{ - if ( pos > 0 ) - { - if ( len > 0 ) - return mid (uInt(pos), uInt(len)); - else - return mid (uInt(pos), uInt(0)); - } - else - return mid (uInt(0), uInt(0)); -} - -//---------------------------------------------------------------------- -FString FString::mid (uInt pos, uInt len) const +FString FString::mid (std::size_t pos, std::size_t len) const { wchar_t* p; wchar_t* first; @@ -1282,7 +1209,7 @@ const FString& FString::insert (const FString& s, int pos) } //---------------------------------------------------------------------- -const FString& FString::insert (const FString& s, uInt pos) +const FString& FString::insert (const FString& s, std::size_t pos) { if ( pos > length ) throw std::out_of_range(""); @@ -1295,7 +1222,7 @@ const FString& FString::insert (const FString& s, uInt pos) FString FString::replace (const FString& from, const FString& to) { wchar_t* p; - uInt from_length, to_length, pos; + std::size_t from_length, to_length, pos; FString s(string); // handle NULL and empty string @@ -1380,10 +1307,11 @@ FString FString::expandTabs (int tabstop) const tab_split = instr.split("\t"); last = tab_split.size(); - for (uInt i = 0; i < last; i++) + for (std::size_t i = 0; i < last; i++) { - uInt len = tab_split[i].getLength(); - uInt tab_len = uInt(tabstop); + std::size_t len = tab_split[i].getLength(); + std::size_t tab_len = std::size_t(tabstop); + if ( i == last - 1 ) outstr += tab_split[i]; else @@ -1471,11 +1399,11 @@ const FString& FString::overwrite (const FString& s, int pos) if ( pos < 0 ) return overwrite (s, 0); - return overwrite (s, uInt(pos)); + return overwrite (s, std::size_t(pos)); } //---------------------------------------------------------------------- -const FString& FString::overwrite (const FString& s, uInt pos) +const FString& FString::overwrite (const FString& s, std::size_t pos) { if ( pos > length ) pos = length; @@ -1494,16 +1422,7 @@ const FString& FString::overwrite (const FString& s, uInt pos) } //---------------------------------------------------------------------- -const FString& FString::remove (int pos, uInt len) -{ - if ( pos < 0 || len < 1 ) - return *this; - - return remove (uInt(pos), len); -} - -//---------------------------------------------------------------------- -const FString& FString::remove (uInt pos, uInt len) +const FString& FString::remove (std::size_t pos, std::size_t len) { if ( pos > length ) return *this; @@ -1531,7 +1450,7 @@ bool FString::includes (const FString& s) const // private methods of FString //---------------------------------------------------------------------- -inline void FString::initLength (uInt len) +inline void FString::initLength (std::size_t len) { if ( len == 0 ) return; @@ -1588,7 +1507,7 @@ inline void FString::_assign (const wchar_t s[]) } //---------------------------------------------------------------------- -inline void FString::_insert (uInt len, const wchar_t s[]) +inline void FString::_insert (std::size_t len, const wchar_t s[]) { if ( len == 0 ) // String s is a null or a empty string return; @@ -1614,7 +1533,9 @@ inline void FString::_insert (uInt len, const wchar_t s[]) } //---------------------------------------------------------------------- -inline void FString::_insert (uInt pos, uInt len, const wchar_t s[]) +inline void FString::_insert ( std::size_t pos + , std::size_t len + , const wchar_t s[] ) { if ( len == 0 ) // String s is a null or a empty string return; @@ -1625,7 +1546,7 @@ inline void FString::_insert (uInt pos, uInt len, const wchar_t s[]) } else { - uInt x; + std::size_t x; if ( (length + len + 1) <= bufsize ) { @@ -1654,7 +1575,7 @@ inline void FString::_insert (uInt pos, uInt len, const wchar_t s[]) return; } - uInt y = 0; + std::size_t y = 0; for (x = 0; x < pos; x++) // left side sptr[y++] = string[x]; @@ -1673,12 +1594,12 @@ inline void FString::_insert (uInt pos, uInt len, const wchar_t s[]) } //---------------------------------------------------------------------- -inline void FString::_remove (uInt pos, uInt len) +inline void FString::_remove (std::size_t pos, std::size_t len) { if ( (bufsize - length - 1 + len) <= FWDBUFFER ) { // shifting left side to pos - for (uInt i = pos; i + len < length + 1; i++) + for (std::size_t i = pos; i + len < length + 1; i++) string[i] = string[i + len]; length -= len; @@ -1698,7 +1619,7 @@ inline void FString::_remove (uInt pos, uInt len) return; } - uInt x, y = 0; + std::size_t x, y = 0; for (x = 0; x < pos; x++) // left side sptr[y++] = string[x]; diff --git a/src/fterm.cpp b/src/fterm.cpp index 23bc5821..dfd3588d 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -82,7 +82,7 @@ FTerm::~FTerm() // destructor // public methods of FTerm //---------------------------------------------------------------------- -int FTerm::getLineNumber() +std::size_t FTerm::getLineNumber() { FRect& term_geometry = data->getTermGeometry(); @@ -93,7 +93,7 @@ int FTerm::getLineNumber() } //---------------------------------------------------------------------- -int FTerm::getColumnNumber() +std::size_t FTerm::getColumnNumber() { FRect& term_geometry = data->getTermGeometry(); @@ -474,10 +474,10 @@ void FTerm::detectTermSize() term_geometry.setPos(1,1); // Use COLUMNS or fallback to the xterm default width of 80 characters str = std::getenv("COLUMNS"); - term_geometry.setWidth(str ? std::atoi(str) : 80); + term_geometry.setWidth(str ? std::size_t(std::atoi(str)) : 80); // Use LINES or fallback to the xterm default height of 24 characters str = std::getenv("LINES"); - term_geometry.setHeight(str ? std::atoi(str) : 24); + term_geometry.setHeight(str ? std::size_t(std::atoi(str)) : 24); } else { @@ -492,7 +492,7 @@ void FTerm::detectTermSize() } //---------------------------------------------------------------------- -void FTerm::setTermSize (int width, int height) +void FTerm::setTermSize (std::size_t width, std::size_t height) { // Set xterm size to {width} x {height} diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index 7cfb1517..d2436da1 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -31,8 +31,8 @@ namespace finalcut bool FTermXTerminal::mouse_support; bool FTermXTerminal::meta_sends_esc; bool FTermXTerminal::xterm_default_colors; -int FTermXTerminal::term_width = 80; -int FTermXTerminal::term_height = 24; +std::size_t FTermXTerminal::term_width = 80; +std::size_t FTermXTerminal::term_height = 24; const FString* FTermXTerminal::xterm_font = 0; const FString* FTermXTerminal::xterm_title = 0; const FString* FTermXTerminal::foreground_color = 0; @@ -126,7 +126,7 @@ void FTermXTerminal::setTitle (const FString& title) } //---------------------------------------------------------------------- -void FTermXTerminal::setTermSize (int width, int height) +void FTermXTerminal::setTermSize (std::size_t width, std::size_t height) { // Set xterm size to {term_width} x {term_height} @@ -417,7 +417,7 @@ void FTermXTerminal::setXTermSize() { if ( term_detection->isXTerminal() ) { - FTerm::putstringf (CSI "8;%d;%dt", term_height, term_width); + FTerm::putstringf (CSI "8;%lu;%lut", term_height, term_width); std::fflush(stdout); } } diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 9e64cf39..60536366 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -59,7 +59,7 @@ FTextView::~FTextView() // destructor //---------------------------------------------------------------------- const FString FTextView::getText() const { - uInt len, rows, idx; + std::size_t len, rows, idx; if ( data.empty() ) return FString(""); @@ -67,13 +67,13 @@ const FString FTextView::getText() const len = 0; rows = getRows(); - for (uInt i = 0 ; i < rows; i++) + for (std::size_t i = 0 ; i < rows; i++) len += data[i].getLength() + 1; FString s(len + 1); idx = 0; - for (uInt i = 0 ; i < rows; i++) + for (std::size_t i = 0 ; i < rows; i++) { const wchar_t* p = data[i].wc_str(); @@ -93,23 +93,23 @@ const FString FTextView::getText() const } //---------------------------------------------------------------------- -void FTextView::setGeometry (int x, int y, int w, int h, bool adjust) +void FTextView::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Set the text view geometry FWidget::setGeometry(x, y, w, h, adjust); - int width = getWidth(); - int height = getHeight(); + std::size_t width = getWidth(); + std::size_t height = getHeight(); if ( isNewFont() ) { - vbar->setGeometry (width, 1, 2, height - 1); - hbar->setGeometry (1, height, width - 2, 1); + vbar->setGeometry (int(width), 1, 2, height - 1); + hbar->setGeometry (1, int(height), width - 2, 1); } else { - vbar->setGeometry (width, 2, 1, height - 2); - hbar->setGeometry (2, height, width - 2, 1); + vbar->setGeometry (int(width), 2, 1, height - 2); + hbar->setGeometry (2, int(height), width - 2, 1); } vbar->resize(); @@ -152,7 +152,7 @@ void FTextView::scrollTo (int x, int y) if ( xoffset != x ) { - int xoffset_end = int(maxLineWidth) - getTextWidth(); + int xoffset_end = int(maxLineWidth - getTextWidth()); xoffset = x; if ( xoffset < 0 ) @@ -170,7 +170,7 @@ void FTextView::scrollTo (int x, int y) if ( yoffset != y ) { - int yoffset_end = int(getRows()) - getTextHeight(); + int yoffset_end = int(getRows() - getTextHeight()); yoffset = y; if ( yoffset < 0 ) @@ -193,7 +193,7 @@ void FTextView::scrollTo (int x, int y) //---------------------------------------------------------------------- void FTextView::hide() { - int n, size; + std::size_t n, size; short fg, bg; char* blank; FWidget* parent_widget = getParentWidget(); @@ -215,12 +215,12 @@ void FTextView::hide() n = isNewFont() ? 1 : 0; size = getWidth() + n; - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -228,10 +228,10 @@ void FTextView::hide() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { setPrintPos (1, 1 + y); print (blank); @@ -267,9 +267,9 @@ void FTextView::insert (const FString& str, int pos) text_split = s.split("\r\n"); num = text_split.size(); - for (uInt i = 0; i < num; i++) + for (std::size_t i = 0; i < num; i++) { - uInt len; + std::size_t len; text_split[i] = text_split[i].removeBackspaces() .removeDel() .replaceControlCodes() @@ -280,10 +280,10 @@ void FTextView::insert (const FString& str, int pos) { maxLineWidth = len; - if ( len > uInt(getTextWidth()) ) + if ( len > getTextWidth() ) { - hbar->setMaximum (int(maxLineWidth) - getTextWidth()); - hbar->setPageSize (int(maxLineWidth), getTextWidth()); + hbar->setMaximum (int(maxLineWidth) - int(getTextWidth())); + hbar->setPageSize (int(maxLineWidth), int(getTextWidth())); hbar->calculateSliderValues(); if ( ! hbar->isVisible() ) @@ -293,14 +293,14 @@ void FTextView::insert (const FString& str, int pos) } data.insert (iter + pos, text_split.begin(), text_split.end()); - vbar->setMaximum (int(getRows()) - getTextHeight()); - vbar->setPageSize (int(getRows()), getTextHeight()); + vbar->setMaximum (int(getRows()) - int(getTextHeight())); + vbar->setPageSize (int(getRows()), int(getTextHeight())); vbar->calculateSliderValues(); - if ( ! vbar->isVisible() && int(getRows()) > getTextHeight() ) + if ( ! vbar->isVisible() && int(getRows()) > int(getTextHeight()) ) vbar->setVisible(); - if ( vbar->isVisible() && int(getRows()) <= getTextHeight() ) + if ( vbar->isVisible() && int(getRows()) <= int(getTextHeight()) ) vbar->hide(); processChanged(); @@ -330,7 +330,7 @@ void FTextView::replaceRange (const FString& str, int from, int to) //---------------------------------------------------------------------- void FTextView::clear() { - int size; + std::size_t size; char* blank; data.clear(); @@ -350,12 +350,12 @@ void FTextView::clear() setColor(); size = getWidth() - 2; - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -363,10 +363,10 @@ void FTextView::clear() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < getTextHeight(); y++) + for (int y = 0; y < int(getTextHeight()); y++) { setPrintPos (2, 2 - nf_offset + y); print (blank); @@ -402,12 +402,12 @@ void FTextView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_ppage: - scrollBy (0, -getTextHeight()); + scrollBy (0, int(-getTextHeight())); ev->accept(); break; case fc::Fkey_npage: - scrollBy (0, getTextHeight()); + scrollBy (0, int(getTextHeight())); ev->accept(); break; @@ -417,7 +417,7 @@ void FTextView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_end: - scrollToY (int(getRows()) - getTextHeight()); + scrollToY (int(getRows() - getTextHeight())); ev->accept(); break; @@ -592,43 +592,43 @@ void FTextView::onFocusOut (FFocusEvent*) void FTextView::adjustSize() { FWidget::adjustSize(); - int width = getWidth() - , height = getHeight() - , last_line = int(getRows()) - , max_width = int(maxLineWidth); + std::size_t width = getWidth(); + std::size_t height = getHeight(); + int last_line = int(getRows()); + int max_width = int(maxLineWidth); - if ( xoffset >= max_width - width - nf_offset ) - xoffset = max_width - width - nf_offset - 1; + if ( xoffset >= max_width - int(width) - nf_offset ) + xoffset = max_width - int(width) - nf_offset - 1; if ( xoffset < 0 ) xoffset = 0; - if ( yoffset > last_line - height - nf_offset + 2 ) - yoffset = last_line - height - nf_offset + 2; + if ( yoffset > last_line - int(height) - nf_offset + 2 ) + yoffset = last_line - int(height) - nf_offset + 2; if ( yoffset < 0 ) yoffset = 0; - vbar->setMaximum (last_line - height + 2 - nf_offset); - vbar->setPageSize (last_line, height - 2 + nf_offset); - vbar->setX (width); - vbar->setHeight (height - 2 + nf_offset, false); + vbar->setMaximum (last_line - int(height) + 2 - nf_offset); + vbar->setPageSize (last_line, int(height) - 2 + nf_offset); + vbar->setX (int(width)); + vbar->setHeight (height - 2 + std::size_t(nf_offset), false); vbar->setValue (yoffset); vbar->resize(); - hbar->setMaximum (max_width - width + nf_offset + 2); - hbar->setPageSize (max_width, width - nf_offset - 2); - hbar->setY (height); + hbar->setMaximum (max_width - int(width) + nf_offset + 2); + hbar->setPageSize (max_width, int(width) - nf_offset - 2); + hbar->setY (int(height)); hbar->setWidth (width - 2, false); hbar->setValue (xoffset); hbar->resize(); - if ( last_line < height + nf_offset - 1 ) + if ( last_line < int(height) + nf_offset - 1 ) vbar->hide(); else vbar->setVisible(); - if ( max_width < width - nf_offset - 1 ) + if ( max_width < int(width) - nf_offset - 1 ) hbar->hide(); else hbar->setVisible(); @@ -637,15 +637,15 @@ void FTextView::adjustSize() // private methods of FTextView //---------------------------------------------------------------------- -int FTextView::getTextHeight() +std::size_t FTextView::getTextHeight() { - return getHeight() - 2 + nf_offset; + return getHeight() - 2 + std::size_t(nf_offset); } //---------------------------------------------------------------------- -int FTextView::getTextWidth() +std::size_t FTextView::getTextWidth() { - return getWidth() - 2 - nf_offset; + return getWidth() - 2 - std::size_t(nf_offset); } //---------------------------------------------------------------------- @@ -740,7 +740,7 @@ void FTextView::draw() } } - setCursorPos (getWidth(), getHeight()); + setCursorPos (int(getWidth()), int(getHeight())); updateTerminal(); flush_out(); } @@ -748,12 +748,10 @@ void FTextView::draw() //---------------------------------------------------------------------- void FTextView::drawText() { - uInt num; - if ( data.empty() || getHeight() <= 2 || getWidth() <= 2 ) return; - num = uInt(getTextHeight()); + std::size_t num = getTextHeight(); if ( num > getRows() ) num = getRows(); @@ -763,14 +761,14 @@ void FTextView::drawText() if ( isMonochron() ) setReverse(true); - for (uInt y = 0; y < num; y++) + for (std::size_t y = 0; y < num; y++) { - uInt i, len; + std::size_t i, len; FString line; const wchar_t* line_str; setPrintPos (2, 2 - nf_offset + int(y)); - line = data[y + uInt(yoffset)].mid ( uInt(1 + xoffset) - , uInt(getTextWidth()) ); + line = data[y + std::size_t(yoffset)].mid ( std::size_t(1 + xoffset) + , getTextWidth() ); line_str = line.wc_str(); len = line.getLength(); @@ -790,7 +788,7 @@ void FTextView::drawText() print ('.'); } - for (; i < uInt(getTextWidth()); i++) + for (; i < getTextWidth(); i++) print (' '); } @@ -841,14 +839,14 @@ void FTextView::cb_VBarChange (FWidget*, data_ptr) break; case FScrollbar::scrollPageBackward: - distance = getClientHeight(); + distance = int(getClientHeight()); // fall through case FScrollbar::scrollStepBackward: scrollBy (0, -distance); break; case FScrollbar::scrollPageForward: - distance = getClientHeight(); + distance = int(getClientHeight()); // fall through case FScrollbar::scrollStepForward: scrollBy (0, distance); @@ -897,14 +895,14 @@ void FTextView::cb_HBarChange (FWidget*, data_ptr) break; case FScrollbar::scrollPageBackward: - distance = getClientWidth(); + distance = int(getClientWidth()); // fall through case FScrollbar::scrollStepBackward: scrollBy (-distance, 0); break; case FScrollbar::scrollPageForward: - distance = getClientWidth(); + distance = int(getClientWidth()); // fall through case FScrollbar::scrollStepForward: scrollBy (distance, 0); diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index d5c65d95..59d0643b 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -88,12 +88,12 @@ FToggleButton::~FToggleButton() // destructor // public methods of FToggleButton //---------------------------------------------------------------------- -void FToggleButton::setGeometry (int x, int y, int w, int h, bool adjust) +void FToggleButton::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Set the toggle button geometry - int hotkey_mark = ( getHotkey() ) ? 1 : 0; - int min_width = button_width + int(text.getLength()) - hotkey_mark; + std::size_t hotkey_mark = ( getHotkey() ) ? 1 : 0; + std::size_t min_width = button_width + text.getLength() - hotkey_mark; if ( w < min_width ) w = min_width; @@ -203,9 +203,9 @@ bool FToggleButton::setChecked (bool on) void FToggleButton::setText (const FString& txt) { text = txt; - int hotkey_mark = ( getHotkey() ) ? 1 : 0; + std::size_t hotkey_mark = ( getHotkey() ) ? 1 : 0; - setWidth(button_width + int(text.getLength()) - hotkey_mark); + setWidth(button_width + text.getLength() - hotkey_mark); if ( isEnabled() ) { @@ -217,7 +217,7 @@ void FToggleButton::setText (const FString& txt) //---------------------------------------------------------------------- void FToggleButton::hide() { - int size; + std::size_t size; short fg, bg; char* blank; FWidget* parent_widget = getParentWidget(); @@ -238,12 +238,12 @@ void FToggleButton::hide() setColor (fg, bg); size = getWidth(); - if ( size < 0 ) + if ( size == 0 ) return; try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -251,7 +251,7 @@ void FToggleButton::hide() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[size] = '\0'; setPrintPos (1, 1); print (blank); @@ -420,14 +420,12 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev) //---------------------------------------------------------------------- uChar FToggleButton::getHotkey() { - uInt length; - if ( text.isEmpty() ) return 0; - length = text.getLength(); + std::size_t length = text.getLength(); - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { try { @@ -510,7 +508,7 @@ void FToggleButton::drawLabel() if ( text.isNull() || text.isEmpty() ) return; - uInt length = text.getLength(); + std::size_t length = text.getLength(); try { @@ -525,12 +523,12 @@ void FToggleButton::drawLabel() FString txt = text; wchar_t* src = const_cast(txt.wc_str()); wchar_t* dest = const_cast(LabelText); - hotkeypos = getHotkeyPos(src, dest, uInt(length)); + hotkeypos = getHotkeyPos(src, dest, length); if ( hotkeypos != -1 ) length--; - setPrintPos (1 + label_offset_pos, 1); + setPrintPos (1 + int(label_offset_pos), 1); drawText (LabelText, hotkeypos, length); delete[] LabelText; } @@ -638,14 +636,16 @@ void FToggleButton::init() } //---------------------------------------------------------------------- -int FToggleButton::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) +int FToggleButton::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign int pos = -1; wchar_t* txt = src; - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { if ( i < length && txt[i] == L'&' && pos == -1 ) { @@ -661,7 +661,9 @@ int FToggleButton::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) } //---------------------------------------------------------------------- -void FToggleButton::drawText (wchar_t LabelText[], int hotkeypos, uInt length) +void FToggleButton::drawText ( wchar_t LabelText[] + , int hotkeypos + , std::size_t length ) { bool isActive = ((flags & fc::active) != 0); bool isNoUnderline = ((flags & fc::no_underline) != 0); diff --git a/src/ftooltip.cpp b/src/ftooltip.cpp index 2fb648e0..7cb88ef6 100644 --- a/src/ftooltip.cpp +++ b/src/ftooltip.cpp @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2016-2017 Markus Gans * +* Copyright 2016-2018 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 * @@ -143,23 +143,24 @@ void FToolTip::init() //---------------------------------------------------------------------- void FToolTip::calculateDimensions() { - int x, y, w, h; + int x, y; + std::size_t w, h; FWidget* r = getRootWidget(); text_split = text.split("\n"); text_num_lines = uInt(text_split.size()); text_components = &text_split[0]; max_line_width = 0; - for (uInt i = 0; i < text_num_lines; i++) + for (std::size_t i = 0; i < text_num_lines; i++) { - uInt len = text_components[i].getLength(); + std::size_t len = text_components[i].getLength(); if ( len > max_line_width ) max_line_width = len; } - h = int(text_num_lines) + 2; - w = int(max_line_width + 4); + h = text_num_lines + 2; + w = max_line_width + 4; if ( r ) { diff --git a/src/fvterm.cpp b/src/fvterm.cpp index e0f7adf1..565f7c1a 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -110,8 +110,8 @@ void FVTerm::setTermXY (int x, int y) if ( term_pos->getX() == x && term_pos->getY() == y ) return; - term_width = getColumnNumber(); - term_height = getLineNumber(); + term_width = int(getColumnNumber()); + term_height = int(getLineNumber()); if ( x >= term_width ) { @@ -597,8 +597,8 @@ void FVTerm::createArea ( const FRect& r { createArea ( r.getX() , r.getY() - , r.getWidth() - , r.getHeight() + , int(r.getWidth()) + , int(r.getHeight()) , p.getX() , p.getY() , area ); @@ -633,8 +633,8 @@ void FVTerm::resizeArea ( const FRect& r { resizeArea ( r.getX() , r.getY() - , r.getWidth() - , r.getHeight() + , int(r.getWidth()) + , int(r.getHeight()) , p.getX() , p.getY() , area ); @@ -800,8 +800,8 @@ void FVTerm::restoreVTerm (const FRect& box) { restoreVTerm ( box.getX() , box.getY() - , box.getWidth() - , box.getHeight() ); + , int(box.getWidth()) + , int(box.getHeight()) ); } //---------------------------------------------------------------------- @@ -901,8 +901,8 @@ FVTerm::covered_state FVTerm::isCovered ( int x, int y int win_y = win->offset_top; FRect geometry ( win_x , win_y - , win->width + win->right_shadow - , win->height + win->bottom_shadow ); + , std::size_t(win->width + win->right_shadow) + , std::size_t(win->height + win->bottom_shadow) ); if ( found && geometry.contains(x, y) ) { @@ -1306,10 +1306,9 @@ bool FVTerm::isInsideArea (int x, int y, term_area* area) { // Check whether the coordinates are within the area - int ax = 0 - , ay = 0 - , aw = area->width - , ah = area->height; + int ax = 0, ay = 0; + std::size_t aw = std::size_t(area->width); + std::size_t ah = std::size_t(area->height); FRect area_geometry(ax, ay, aw, ah); if ( area_geometry.contains(x, y) ) @@ -1389,8 +1388,8 @@ void FVTerm::getArea (const FRect& box, term_area* area) { getArea ( box.getX() , box.getY() - , box.getWidth() - , box.getHeight() + , int(box.getWidth()) + , int(box.getHeight()) , area ); } @@ -1719,7 +1718,7 @@ FVTerm::charData FVTerm::generateCharacter (int x, int y) // Generates characters for a given position considering all areas FWidget::widgetList::const_iterator iter, end; charData* sc; // shown character - FWidget* widget; + FWidget* widget; widget = static_cast(vterm->widget); sc = &vdesktop->text[y * vdesktop->width + x]; @@ -1741,8 +1740,8 @@ FVTerm::charData FVTerm::generateCharacter (int x, int y) int win_y = win->offset_top; FRect geometry ( win_x , win_y - , win->width + win->right_shadow - , win->height + win->bottom_shadow ); + , std::size_t(win->width + win->right_shadow) + , std::size_t(win->height + win->bottom_shadow) ); // Window is visible and contains current character if ( geometry.contains(x, y) ) @@ -1857,8 +1856,8 @@ FVTerm::charData FVTerm::getCharacter ( character_type char_type FRect geometry ( win->offset_left , win->offset_top - , win->width + win->right_shadow - , win->height + win->bottom_shadow ); + , std::size_t(win->width + win->right_shadow) + , std::size_t(win->height + win->bottom_shadow) ); // Window visible and contains current character if ( geometry.contains(x, y) ) @@ -2188,7 +2187,7 @@ bool FVTerm::clearTerm (int fillchar) { term_pos->setPoint(-1, -1); - for (int i = 0; i < getLineNumber(); i++) + for (int i = 0; i < int(getLineNumber()); i++) { setTermXY (0, i); appendOutputBuffer (cb); @@ -2875,8 +2874,8 @@ int FVTerm::appendLowerRight (charData*& screen_char) char* ip = TCAP(fc::t_insert_padding); char* ic = TCAP(fc::t_insert_character); - x = getColumnNumber() - 2; - y = getLineNumber() - 1; + x = int(getColumnNumber()) - 2; + y = int(getLineNumber()) - 1; setTermXY (x, y); appendChar (screen_char); term_pos->x_ref()++; diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 8c6c563f..27dec6d1 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -106,10 +106,10 @@ FWidget::FWidget (FWidget* parent, bool disable_alt_screen) { visible_cursor = ! hideable; offset = parent->client_offset; - double_flatline_mask.top.resize (uLong(getWidth()), false); - double_flatline_mask.right.resize (uLong(getHeight()), false); - double_flatline_mask.bottom.resize (uLong(getWidth()), false); - double_flatline_mask.left.resize (uLong(getHeight()), false); + double_flatline_mask.top.resize (getWidth(), false); + double_flatline_mask.right.resize (getHeight(), false); + double_flatline_mask.bottom.resize (getWidth(), false); + double_flatline_mask.left.resize (getHeight(), false); } } @@ -482,7 +482,7 @@ void FWidget::setPos (int x, int y, bool adjust) } //---------------------------------------------------------------------- -void FWidget::setWidth (int width, bool adjust) +void FWidget::setWidth (std::size_t width, bool adjust) { width = std::min (width, size_hints.max_width); width = std::max (width, size_hints.min_width); @@ -499,12 +499,12 @@ void FWidget::setWidth (int width, bool adjust) if ( adjust ) adjustSize(); - double_flatline_mask.top.resize (uLong(getWidth()), false); - double_flatline_mask.bottom.resize (uLong(getWidth()), false); + double_flatline_mask.top.resize (getWidth(), false); + double_flatline_mask.bottom.resize (getWidth(), false); } //---------------------------------------------------------------------- -void FWidget::setHeight (int height, bool adjust) +void FWidget::setHeight (std::size_t height, bool adjust) { height = std::min (height, size_hints.max_height); height = std::max (height, size_hints.min_height); @@ -521,12 +521,12 @@ void FWidget::setHeight (int height, bool adjust) if ( adjust ) adjustSize(); - double_flatline_mask.right.resize (uLong(getHeight()), false); - double_flatline_mask.left.resize (uLong(getHeight()), false); + double_flatline_mask.right.resize (getHeight(), false); + double_flatline_mask.left.resize (getHeight(), false); } //---------------------------------------------------------------------- -void FWidget::setSize (int width, int height, bool adjust) +void FWidget::setSize (std::size_t width, std::size_t height, bool adjust) { width = std::min (width, size_hints.max_width); width = std::max (width, size_hints.min_width); @@ -551,10 +551,10 @@ void FWidget::setSize (int width, int height, bool adjust) if ( adjust ) adjustSize(); - double_flatline_mask.top.resize (uLong(getWidth()), false); - double_flatline_mask.right.resize (uLong(getHeight()), false); - double_flatline_mask.bottom.resize (uLong(getWidth()), false); - double_flatline_mask.left.resize (uLong(getHeight()), false); + double_flatline_mask.top.resize (getWidth(), false); + double_flatline_mask.right.resize (getHeight(), false); + double_flatline_mask.bottom.resize (getWidth(), false); + double_flatline_mask.left.resize (getHeight(), false); } //---------------------------------------------------------------------- @@ -612,7 +612,7 @@ void FWidget::setBottomPadding (int bottom, bool adjust) if ( isRootWidget() ) { FWidget* r = rootObject; - r->client_offset.setY2 (r->getHeight() - 1 - r->padding.bottom); + r->client_offset.setY2 (int(r->getHeight()) - 1 - r->padding.bottom); adjustSizeGlobal(); } else @@ -633,7 +633,7 @@ void FWidget::setRightPadding (int right, bool adjust) if ( isRootWidget() ) { FWidget* r = rootObject; - r->client_offset.setX2 (r->getWidth() - 1 - r->padding.right); + r->client_offset.setX2 (int(r->getWidth()) - 1 - r->padding.right); adjustSizeGlobal(); } else @@ -654,8 +654,8 @@ void FWidget::setParentOffset() void FWidget::setTermOffset() { FWidget* r = getRootWidget(); - int w = r->getWidth(); - int h = r->getHeight(); + int w = int(r->getWidth()); + int h = int(r->getHeight()); offset.setCoordinates (0, 0, w - 1, h - 1); } @@ -665,14 +665,15 @@ void FWidget::setTermOffsetWithPadding() FWidget* r = getRootWidget(); offset.setCoordinates ( r->getLeftPadding() , r->getTopPadding() - , r->getWidth() - 1 - r->getRightPadding() - , r->getHeight() - 1 - r->getBottomPadding() ); + , int(r->getWidth()) - 1 - r->getRightPadding() + , int(r->getHeight()) - 1 - r->getBottomPadding() ); } //---------------------------------------------------------------------- -void FWidget::setTermSize (int w, int h) +void FWidget::setTermSize (std::size_t w, std::size_t h) { // Set xterm size to w x h + if ( isXTerminal() ) { rootObject->wsize.setRect(1, 1, w, h); @@ -683,12 +684,11 @@ void FWidget::setTermSize (int w, int h) } //---------------------------------------------------------------------- -void FWidget::setGeometry (int x, int y, int w, int h, bool adjust) +void FWidget::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Sets the geometry of the widget relative to its parent - int term_x - , term_y; + int term_x, term_y; w = std::min (w, size_hints.max_width); w = std::max (w, size_hints.min_width); @@ -718,13 +718,13 @@ void FWidget::setGeometry (int x, int y, int w, int h, bool adjust) client_offset.setCoordinates ( term_x - 1 + padding.left , term_y - 1 + padding.top - , term_x - 2 + getWidth() - padding.right - , term_y - 2 + getHeight() - padding.bottom ); + , term_x - 2 + int(getWidth()) - padding.right + , term_y - 2 + int(getHeight()) - padding.bottom ); - double_flatline_mask.top.resize (uLong(getWidth()), false); - double_flatline_mask.right.resize (uLong(getHeight()), false); - double_flatline_mask.bottom.resize (uLong(getWidth()), false); - double_flatline_mask.left.resize (uLong(getHeight()), false); + double_flatline_mask.top.resize (getWidth(), false); + double_flatline_mask.right.resize (getHeight(), false); + double_flatline_mask.bottom.resize (getWidth(), false); + double_flatline_mask.left.resize (getHeight(), false); if ( adjust ) adjustSize(); @@ -1148,10 +1148,10 @@ void FWidget::resize() adjustSize(); // resize the four double-flatline-masks - double_flatline_mask.top.resize (uLong(getWidth()), false); - double_flatline_mask.right.resize (uLong(getHeight()), false); - double_flatline_mask.bottom.resize (uLong(getWidth()), false); - double_flatline_mask.left.resize (uLong(getHeight()), false); + double_flatline_mask.top.resize (getWidth(), false); + double_flatline_mask.right.resize (getHeight(), false); + double_flatline_mask.bottom.resize (getWidth(), false); + double_flatline_mask.left.resize (getHeight(), false); } //---------------------------------------------------------------------- @@ -1329,8 +1329,8 @@ void FWidget::detectTermSize() ( r->padding.left, r->padding.top, - getDesktopWidth() - 1 - r->padding.right, - getDesktopHeight() - 1 - r->padding.bottom + int(getDesktopWidth()) - 1 - r->padding.right, + int(getDesktopHeight()) - 1 - r->padding.bottom ); } @@ -1357,9 +1357,9 @@ void FWidget::drawShadow() } int x1 = 1 - , x2 = getWidth() + , x2 = int(getWidth()) , y1 = 1 - , y2 = getHeight(); + , y2 = int(getHeight()); if ( trans_shadow ) { @@ -1379,8 +1379,8 @@ void FWidget::clearShadow() if ( isMonochron() ) return; - int w = getWidth() - , h = getHeight(); + int w = int(getWidth()); + int h = int(getHeight()); if ( isWindowWidget() ) { @@ -1392,7 +1392,7 @@ void FWidget::clearShadow() if ( w <= offset.getX2() ) { - for (int i = 1; i <= getHeight(); i++) + for (int i = 1; i <= int(getHeight()); i++) { setPrintPos (w + 1, i); print (' '); // clear █ @@ -1403,7 +1403,7 @@ void FWidget::clearShadow() { setPrintPos (2, h + 1); - for (int i = 1; i <= getWidth(); i++) + for (std::size_t i = 1; i <= getWidth(); i++) print (' '); // clear ▀ } @@ -1418,16 +1418,16 @@ void FWidget::drawFlatBorder() return; int x1 = 1 - , x2 = getWidth() + 1 + , x2 = int(getWidth()) + 1 , y1 = 0 - , y2 = getHeight() + 1; + , y2 = int(getHeight()) + 1; if ( FWidget* p = getParentWidget() ) setColor (wc.dialog_fg, p->getBackgroundColor()); else setColor (wc.dialog_fg, wc.dialog_bg); - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { setPrintPos (x1 - 1, y1 + y + 1); @@ -1441,7 +1441,7 @@ void FWidget::drawFlatBorder() setPrintPos (x2, y1 + 1); - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { if ( double_flatline_mask.right[uLong(y)] ) // left+right line (on right side) @@ -1455,7 +1455,7 @@ void FWidget::drawFlatBorder() setPrintPos (x1, y1); - for (int x = 0; x < getWidth(); x++) + for (int x = 0; x < int(getWidth()); x++) { if ( double_flatline_mask.top[uLong(x)] ) // top+bottom line (at top) @@ -1467,7 +1467,7 @@ void FWidget::drawFlatBorder() setPrintPos (x1, y2); - for (int x = 0; x < getWidth(); x++) + for (int x = 0; x < int(getWidth()); x++) { if ( double_flatline_mask.bottom[uLong(x)] ) // top+bottom line (at bottom) @@ -1485,9 +1485,9 @@ void FWidget::clearFlatBorder() return; int x1 = 1 - , x2 = getWidth() + 1 + , x2 = int(getWidth()) + 1 , y1 = 0 - , y2 = getHeight() + 1; + , y2 = int(getHeight()) + 1; if ( FWidget* p = getParentWidget() ) setColor (wc.dialog_fg, p->getBackgroundColor()); @@ -1495,7 +1495,7 @@ void FWidget::clearFlatBorder() setColor (wc.dialog_fg, wc.dialog_bg); // clear on left side - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { setPrintPos (x1 - 1, y1 + y + 1); @@ -1506,7 +1506,7 @@ void FWidget::clearFlatBorder() } // clear on right side - for (int y = 0; y < getHeight(); y++) + for (int y = 0; y < int(getHeight()); y++) { setPrintPos (x2, y1 + y + 1); @@ -1519,7 +1519,7 @@ void FWidget::clearFlatBorder() // clear at top setPrintPos (x1, y1); - for (int x = 0; x < getWidth(); x++) + for (int x = 0; x < int(getWidth()); x++) { if ( double_flatline_mask.top[uLong(x)] ) print (fc::NF_border_line_upper); @@ -1530,7 +1530,7 @@ void FWidget::clearFlatBorder() // clear at bottom setPrintPos (x1, y2); - for (int x = 0; x < getWidth(); x++) + for (int x = 0; x < int(getWidth()); x++) { if ( double_flatline_mask.bottom[uLong(x)] ) print (fc::NF_border_line_bottom); @@ -1554,11 +1554,11 @@ void FWidget::drawBorder (int x1, int y1, int x2, int y2) if ( y1 < 1 ) y1 = 1; - if ( x2 > getWidth() ) - x2 = getWidth(); + if ( x2 > int(getWidth()) ) + x2 = int(getWidth()); - if ( y2 > getHeight() ) - y2 = getHeight(); + if ( y2 > int(getHeight()) ) + y2 = int(getHeight()); if ( isNewFont() ) drawNewFontBox (x1, y1, x2, y2); @@ -1683,8 +1683,8 @@ void FWidget::adjustSize() { offset.setCoordinates ( p->getTermX() - 1 , p->getTermY() - 1 - , p->getTermX() + p->getWidth() - 2 - , p->getTermY() + p->getHeight() - 2 ); + , p->getTermX() + int(p->getWidth()) - 2 + , p->getTermY() + int(p->getHeight()) - 2 ); } else if ( p ) offset = p->client_offset; @@ -1700,8 +1700,8 @@ void FWidget::adjustSize() ( getTermX() - 1 + padding.left, getTermY() - 1 + padding.top, - getTermX() - 2 + getWidth() - padding.right, - getTermY() - 2 + getHeight() - padding.bottom + getTermX() - 2 + int(getWidth()) - padding.right, + getTermY() - 2 + int(getHeight()) - padding.bottom ); if ( hasChildren() ) @@ -2069,10 +2069,10 @@ void FWidget::init() offset.setRect(0, 0, getDesktopWidth(), getDesktopHeight()); client_offset = offset; - double_flatline_mask.top.resize (uLong(getWidth()), false); - double_flatline_mask.right.resize (uLong(getHeight()), false); - double_flatline_mask.bottom.resize (uLong(getWidth()), false); - double_flatline_mask.left.resize (uLong(getHeight()), false); + double_flatline_mask.top.resize (getWidth(), false); + double_flatline_mask.right.resize (getHeight(), false); + double_flatline_mask.bottom.resize (getWidth(), false); + double_flatline_mask.left.resize (getHeight(), false); // Initialize default widget colors setColorTheme(); @@ -2132,7 +2132,7 @@ inline void FWidget::insufficientSpaceAdjust() return; // move left if not enough space - while ( getTermX() + getWidth() - padding.right > offset.getX2() + 2 ) + while ( getTermX() + int(getWidth()) - padding.right > offset.getX2() + 2 ) { adjust_wsize.x1_ref()--; adjust_wsize.x2_ref()--; @@ -2142,7 +2142,7 @@ inline void FWidget::insufficientSpaceAdjust() } // move up if not enough space - while ( getTermY() + getHeight() - padding.bottom > offset.getY2() + 2 ) + while ( getTermY() + int(getHeight()) - padding.bottom > offset.getY2() + 2 ) { adjust_wsize.y1_ref()--; adjust_wsize.y2_ref()--; @@ -2152,17 +2152,17 @@ inline void FWidget::insufficientSpaceAdjust() } // reduce the width if not enough space - while ( offset.getX1() + getWidth() - 1 > offset.getX2() ) + while ( offset.getX1() + int(getWidth()) - 1 > offset.getX2() ) adjust_wsize.x2_ref()--; if ( getWidth() < size_hints.min_width ) adjust_wsize.setWidth(size_hints.min_width); - if ( getWidth() <= 0 ) + if ( getWidth() == 0 ) adjust_wsize.setWidth(1); // reduce the height if not enough space - while ( offset.getY1() + getHeight() - 1 > offset.getY2() ) + while ( offset.getY1() + int(getHeight()) - 1 > offset.getY2() ) adjust_wsize.y2_ref()--; if ( getHeight() < size_hints.min_height ) @@ -2343,7 +2343,7 @@ void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2) setColor (wc.shadow_bg, wc.shadow_fg); setTransShadow(); - for (int i = 1; i < getHeight(); i++) + for (int i = 1; i < int(getHeight()); i++) { setPrintPos (x2 + 1, y1 + i); print (" "); @@ -2358,7 +2358,7 @@ void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2) setColor (wc.shadow_bg, wc.shadow_fg); setTransShadow(); - for (int i = 2; i <= getWidth() + 1; i++) + for (std::size_t i = 2; i <= getWidth() + 1; i++) print (' '); unsetTransShadow(); @@ -2392,7 +2392,7 @@ void FWidget::drawBlockShadow (int x1, int y1, int x2, int y2) if ( isWindowWidget() ) unsetInheritBackground(); - for (int i = 1; i < getHeight(); i++) + for (int i = 1; i < int(getHeight()); i++) { setPrintPos (x2 + 1, y1 + i); print (block); // █ @@ -2403,7 +2403,7 @@ void FWidget::drawBlockShadow (int x1, int y1, int x2, int y2) if ( isWindowWidget() ) setInheritBackground(); - for (int i = 1; i <= getWidth(); i++) + for (std::size_t i = 1; i <= getWidth(); i++) print (fc::UpperHalfBlock); // ▀ if ( isWindowWidget() ) diff --git a/src/fwindow.cpp b/src/fwindow.cpp index ec501bd5..dc53fea9 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -278,9 +278,9 @@ void FWindow::drawBorder() if ( isNewFont() ) { int x1 = 1 - , x2 = 1 + getWidth() - 1 + , x2 = 1 + int(getWidth()) - 1 , y1 = 1 - , y2 = 1 + getHeight() - 1; + , y2 = 1 + int(getHeight()) - 1; setPrintPos (x1, y1); print (fc::NF_border_corner_upper_left); // ⎡ @@ -304,7 +304,7 @@ void FWindow::drawBorder() // lower left corner border ⎣ print (fc::NF_border_corner_lower_left); - for (int x = 2; x < getWidth(); x++) // low line _ + for (std::size_t x = 2; x < getWidth(); x++) // low line _ print (fc::NF_border_line_bottom); setPrintPos (x2, y2); @@ -372,9 +372,9 @@ void FWindow::setPos (int x, int y, bool adjust) } //---------------------------------------------------------------------- -void FWindow::setWidth (int w, bool adjust) +void FWindow::setWidth (std::size_t w, bool adjust) { - int old_width = getWidth(); + std::size_t old_width = getWidth(); FWidget::setWidth (w, adjust); if ( isVirtualWindow() && getWidth() != old_width ) @@ -386,9 +386,9 @@ void FWindow::setWidth (int w, bool adjust) } //---------------------------------------------------------------------- -void FWindow::setHeight (int h, bool adjust) +void FWindow::setHeight (std::size_t h, bool adjust) { - int old_height = getHeight(); + std::size_t old_height = getHeight(); FWidget::setHeight (h, adjust); if ( isVirtualWindow() && getHeight() != old_height ) @@ -400,10 +400,10 @@ void FWindow::setHeight (int h, bool adjust) } //---------------------------------------------------------------------- -void FWindow::setSize (int w, int h, bool adjust) +void FWindow::setSize (std::size_t w, std::size_t h, bool adjust) { - int old_width = getWidth(); - int old_height = getHeight(); + std::size_t old_width = getWidth(); + std::size_t old_height = getHeight(); FWidget::setSize (w, h, adjust); if ( isVirtualWindow() @@ -416,14 +416,14 @@ void FWindow::setSize (int w, int h, bool adjust) } //---------------------------------------------------------------------- -void FWindow::setGeometry (int x, int y, int w, int h, bool adjust) +void FWindow::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) { // Sets the geometry of the widget - int old_x = getX() - , old_y = getY() - , old_width = getWidth() - , old_height = getHeight(); + int old_x = getX(); + int old_y = getY(); + std::size_t old_width = getWidth(); + std::size_t old_height = getHeight(); if ( y < 1 ) y = 1; diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index 62162c29..22e05fc7 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -142,7 +142,7 @@ class FButton : public FWidget uChar getHotkey(); void setHotkeyAccelerator(); void detectHotkey(); - int getHotkeyPos (wchar_t[], wchar_t[], uInt); + int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); int clickAnimationIndent (FWidget*); void clearRightMargin (FWidget*); void drawMarginLeft(); diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index c2c819c6..dba9fd87 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -83,7 +83,7 @@ class FButtonGroup : public FScrollView FToggleButton* getFirstButton(); FToggleButton* getLastButton(); FToggleButton* getButton (int) const; - uInt getCount() const; + std::size_t getCount() const; FString& getText(); // Mutator @@ -136,8 +136,8 @@ class FButtonGroup : public FScrollView // Methods void init(); - int getHotkeyPos (wchar_t[], wchar_t[], uInt); - void drawText (wchar_t[], int, uInt); + int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + void drawText (wchar_t[], int, std::size_t); void directFocus(); // Data Members @@ -165,8 +165,8 @@ inline bool FButtonGroup::setDisable() { return setEnable(false); } //---------------------------------------------------------------------- -inline uInt FButtonGroup::getCount() const -{ return uInt(buttonlist.size()); } +inline std::size_t FButtonGroup::getCount() const +{ return buttonlist.size(); } //---------------------------------------------------------------------- inline FString& FButtonGroup::getText() diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index edcd32f4..d2196207 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -124,7 +124,7 @@ class FDialog : public FWindow bool moveDown (int); bool moveLeft (int); bool moveRight (int); - virtual void setSize (int, int, bool = true); + virtual void setSize (std::size_t, std::size_t, bool = true); bool reduceHeight (int); bool expandHeight (int); bool reduceWidth (int); @@ -158,15 +158,15 @@ class FDialog : public FWindow // Typedef typedef struct { - int mouse_x; - int mouse_y; - FPoint termPos; - int zoom_btn; - bool mouse_over_menu; + int mouse_x; + int mouse_y; + FPoint termPos; + std::size_t zoom_btn; + bool mouse_over_menu; } mouseStates; // Constant - static const int MENU_BTN = 3; + static const std::size_t MENU_BTN = 3; static const bool PRINT_WIN_NUMBER = false; // Only for debug // Using-declaration @@ -197,7 +197,7 @@ class FDialog : public FWindow void openMenu(); void selectFirstMenuItem(); void setZoomItem(); - int getZoomButtonWidth(); + std::size_t getZoomButtonWidth(); void activateZoomButton (mouseStates&); void deactivateZoomButton(); void leaveZoomButton (mouseStates&); diff --git a/src/include/final/flabel.h b/src/include/final/flabel.h index 15378063..37c986ca 100644 --- a/src/include/final/flabel.h +++ b/src/include/final/flabel.h @@ -140,13 +140,13 @@ class FLabel : public FWidget // Methods void init(); uChar getHotkey(); - int getHotkeyPos (wchar_t[], wchar_t[], uInt); + int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); void setHotkeyAccelerator(); - int getAlignOffset (int); + std::size_t getAlignOffset (std::size_t); virtual void draw(); void drawMultiLine(); void drawSingleLine(); - void printLine (wchar_t[], uInt, int, int = 0); + void printLine (wchar_t[], std::size_t, int, std::size_t = 0); // Data Members FStringList multiline_text; diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 77e65dd0..59385258 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -179,7 +179,7 @@ class FLineEdit : public FWidget int scroll_repeat; bool insert_mode; int cursor_pos; - int text_offset; + std::size_t text_offset; }; #pragma pack(pop) diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 966c70d2..a8cd7da2 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -157,23 +157,23 @@ class FListBox : public FWidget // Accessors const char* getClassName() const; - uInt getCount() const; - FListBoxItem getItem (int); + std::size_t getCount() const; + FListBoxItem getItem (std::size_t); FListBoxItem getItem (listBoxItems::iterator) const; - int currentItem() const; + std::size_t currentItem() const; FString& getText(); // Mutators - void setCurrentItem (int); + void setCurrentItem (std::size_t); void setCurrentItem (listBoxItems::iterator); - void selectItem (int); + void selectItem (std::size_t); void selectItem (listBoxItems::iterator); - void unselectItem (int); + void unselectItem (std::size_t); void unselectItem (listBoxItems::iterator); - void showInsideBrackets (int, fc::brackets_type); - void showNoBrackets (int); + void showInsideBrackets (std::size_t, fc::brackets_type); + void showNoBrackets (std::size_t); void showNoBrackets (listBoxItems::iterator); - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); void setMultiSelection (bool); void setMultiSelection (); void unsetMultiSelection (); @@ -184,10 +184,10 @@ class FListBox : public FWidget void setText (const FString&); // Inquiries - bool isSelected (int); + bool isSelected (std::size_t); bool isSelected (listBoxItems::iterator) const; bool isMultiSelection() const; - bool hasBrackets (int); + bool hasBrackets (std::size_t); bool hasBrackets (listBoxItems::iterator) const; // Methods @@ -205,7 +205,7 @@ class FListBox : public FWidget , fc::brackets_type = fc::NoBrackets , bool = false , data_ptr = 0 ); - void remove (int); + void remove (std::size_t); void clear(); // Event handlers @@ -257,8 +257,8 @@ class FListBox : public FWidget void recalculateHorizontalBar (int, bool); void recalculateVerticalBar (int); void getWidgetFocus(); - void multiSelection (int); - void multiSelectionUpTo (int); + void multiSelection (std::size_t); + void multiSelectionUpTo (std::size_t); void wheelUp (int); void wheelDown (int); bool dragScrollUp(); @@ -290,7 +290,7 @@ class FListBox : public FWidget void processSelect(); void processChanged(); void lazyConvert (listBoxItems::iterator, int); - listBoxItems::iterator index2iterator (int); + listBoxItems::iterator index2iterator (std::size_t); // Callback methods void cb_VBarChange (FWidget*, data_ptr); @@ -315,7 +315,7 @@ class FListBox : public FWidget bool scroll_timer; int scroll_repeat; int scroll_distance; - int current; + std::size_t current; int last_current; int secect_from_item; int xoffset; @@ -405,11 +405,11 @@ inline const char* FListBox::getClassName() const { return "FListBox"; } //---------------------------------------------------------------------- -inline uInt FListBox::getCount() const -{ return uInt(itemlist.size()); } +inline std::size_t FListBox::getCount() const +{ return itemlist.size(); } //---------------------------------------------------------------------- -inline FListBoxItem FListBox::getItem (int index) +inline FListBoxItem FListBox::getItem (std::size_t index) { listBoxItems::iterator iter = index2iterator(index - 1); return *iter; @@ -420,7 +420,7 @@ inline FListBoxItem FListBox::getItem (listBoxItems::iterator iter) const { return *iter; } //---------------------------------------------------------------------- -inline int FListBox::currentItem() const +inline std::size_t FListBox::currentItem() const { return current; } //---------------------------------------------------------------------- @@ -428,7 +428,7 @@ inline FString& FListBox::getText() { return text; } //---------------------------------------------------------------------- -inline void FListBox::selectItem (int index) +inline void FListBox::selectItem (std::size_t index) { index2iterator(index - 1)->selected = true; } //---------------------------------------------------------------------- @@ -436,7 +436,7 @@ inline void FListBox::selectItem (listBoxItems::iterator iter) { iter->selected = true; } //---------------------------------------------------------------------- -inline void FListBox::unselectItem (int index) +inline void FListBox::unselectItem (std::size_t index) { index2iterator(index - 1)->selected = false; } //---------------------------------------------------------------------- @@ -444,7 +444,7 @@ inline void FListBox::unselectItem (listBoxItems::iterator iter) { iter->selected = false; } //---------------------------------------------------------------------- -inline void FListBox::showNoBrackets (int index) +inline void FListBox::showNoBrackets (std::size_t index) { index2iterator(index - 1)->brackets = fc::NoBrackets; } //---------------------------------------------------------------------- @@ -476,7 +476,7 @@ inline bool FListBox::unsetFocus() { return setFocus(false); } //---------------------------------------------------------------------- -inline bool FListBox::isSelected (int index) +inline bool FListBox::isSelected (std::size_t index) { return index2iterator(index - 1)->selected; } //---------------------------------------------------------------------- @@ -488,7 +488,7 @@ inline bool FListBox::isMultiSelection() const { return multi_select; } //---------------------------------------------------------------------- -inline bool FListBox::hasBrackets(int index) +inline bool FListBox::hasBrackets(std::size_t index) { return bool(index2iterator(index - 1)->brackets > 0); } //---------------------------------------------------------------------- @@ -526,7 +526,7 @@ void FListBox::insert (Container container, LazyConverter convert) } //---------------------------------------------------------------------- -inline FListBox::listBoxItems::iterator FListBox::index2iterator (int index) +inline FListBox::listBoxItems::iterator FListBox::index2iterator (std::size_t index) { listBoxItems::iterator iter = itemlist.begin(); std::advance (iter, index); diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 11f0f4bb..4a466e0a 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -260,7 +260,7 @@ class FListView : public FWidget // Accessors const char* getClassName() const; - uInt getCount(); + std::size_t getCount(); fc::text_alignment getColumnAlignment (int) const; FString getColumnText (int) const; fc::sorting_type getColumnSortType (int) const; @@ -269,7 +269,7 @@ class FListView : public FWidget FListViewItem* getCurrentItem(); // Mutators - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); void setColumnAlignment (int, fc::text_alignment); void setColumnText (int, const FString&); void setColumnSortType (int,fc::sorting_type \ @@ -344,13 +344,15 @@ class FListView : public FWidget void init(); template void sort (Compare); - uInt getAlignOffset (fc::text_alignment, uInt, uInt); + std::size_t getAlignOffset ( fc::text_alignment + , std::size_t + , std::size_t ); virtual void draw(); void drawColumnLabels(); void drawList(); void drawListLine (const FListViewItem*, bool, bool); void setLineAttributes (bool, bool); - FString getLinePrefix (const FListViewItem*, uInt); + FString getLinePrefix (const FListViewItem*, std::size_t); void drawColumnText (headerItems::const_iterator&); void drawColumnEllipsis ( headerItems::const_iterator& , const FString& ); diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index 4fad0255..336762e0 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -139,7 +139,7 @@ class FMenu : public FWindow, public FMenuList typedef struct { wchar_t* text; - int length; + std::size_t length; int hotkeypos; bool no_underline; } menuText; @@ -199,16 +199,16 @@ class FMenu : public FWindow, public FMenuList bool selectPrevItem(); void keypressMenuBar (FKeyEvent*); bool hotkeyMenu (FKeyEvent*); - int getHotkeyPos (wchar_t[], wchar_t[], uInt); + int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); virtual void draw(); void drawItems(); void drawSeparator (int); void drawMenuLine (FMenuItem*, int); void drawCheckMarkPrefix (FMenuItem*); void drawMenuText (menuText&); - void drawSubMenuIndicator (int&); - void drawAcceleratorKey (int&, int); - void drawTrailingSpaces (int); + void drawSubMenuIndicator (std::size_t&); + void drawAcceleratorKey (std::size_t&, int); + void drawTrailingSpaces (std::size_t); void setLineAttributes (FMenuItem*, int); void setCursorToHotkeyPosition (FMenuItem*); void keyUp(); @@ -232,7 +232,7 @@ class FMenu : public FWindow, public FMenuList FWidget* super_menu; FMenu* opened_sub_menu; FMenu* shown_sub_menu; - uInt max_item_width; + std::size_t max_item_width; int hotkeypos; bool mouse_down; bool has_checkable_items; diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index 922b6b5f..e25b1b77 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -105,8 +105,8 @@ class FMenuBar : public FWindow, public FMenuList typedef struct { wchar_t* text; - int length; - int startpos; + std::size_t length; + std::size_t startpos; int hotkeypos; bool no_underline; } menuText; @@ -126,7 +126,7 @@ class FMenuBar : public FWindow, public FMenuList bool selectNextItem(); bool selectPrevItem(); bool hotkeyMenu (FKeyEvent*&); - int getHotkeyPos (wchar_t[], wchar_t[], uInt); + int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); virtual void draw(); void drawItems(); void drawItem (FMenuItem*, int&); @@ -151,10 +151,10 @@ class FMenuBar : public FWindow, public FMenuList friend class FMenuItem; // Data Members - bool mouse_down; - bool drop_down; - bool focus_changed; - int screenWidth; + bool mouse_down; + bool drop_down; + bool focus_changed; + std::size_t screenWidth; }; #pragma pack(pop) diff --git a/src/include/final/fmenuitem.h b/src/include/final/fmenuitem.h index 28deba43..bec1e29f 100644 --- a/src/include/final/fmenuitem.h +++ b/src/include/final/fmenuitem.h @@ -93,7 +93,7 @@ class FMenuItem : public FWidget const char* getClassName() const; int getHotkey() const; FMenu* getMenu() const; - uInt getTextLength() const; + std::size_t getTextLength() const; FString getText() const; // Mutators @@ -152,7 +152,7 @@ class FMenuItem : public FWidget bool checked; bool radio_button; bool dialog_index; - uInt text_length; + std::size_t text_length; int hotkey; int accel_key; FMenu* menu; @@ -207,7 +207,7 @@ inline FMenu* FMenuItem::getMenu() const { return menu; } //---------------------------------------------------------------------- -inline uInt FMenuItem::getTextLength() const +inline std::size_t FMenuItem::getTextLength() const { return text_length; } //---------------------------------------------------------------------- diff --git a/src/include/final/fmenulist.h b/src/include/final/fmenulist.h index 5703311d..20a99b22 100644 --- a/src/include/final/fmenulist.h +++ b/src/include/final/fmenulist.h @@ -69,7 +69,7 @@ class FMenuList // Accessors virtual const char* getClassName() const; - uInt getCount() const; + std::size_t getCount() const; FMenuItem* getItem (int) const; FMenuItem* getSelectedItem() const; @@ -110,8 +110,8 @@ inline const char* FMenuList::getClassName() const { return "FMenuList"; } //---------------------------------------------------------------------- -inline uInt FMenuList::getCount() const -{ return uInt(item_list.size()); } +inline std::size_t FMenuList::getCount() const +{ return item_list.size(); } //---------------------------------------------------------------------- inline FMenuItem* FMenuList::getItem (int index) const diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index 9f30c062..e8e150c3 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -163,7 +163,7 @@ class FMessageBox : public FDialog FString text; FString* text_components; FStringList text_split; - uInt max_line_width; + std::size_t max_line_width; bool center_text; short emphasis_color; uInt num_buttons; diff --git a/src/include/final/foptimove.h b/src/include/final/foptimove.h index 99259e5f..8681f509 100644 --- a/src/include/final/foptimove.h +++ b/src/include/final/foptimove.h @@ -138,7 +138,7 @@ class FOptiMove // Mutators void setBaudRate (int); void setTabStop (int); - void setTermSize (int, int); + void setTermSize (std::size_t, std::size_t); void setTermEnvironment (termEnv&); void set_cursor_home (char[]); void set_cursor_to_ll (char[]); @@ -237,8 +237,8 @@ class FOptiMove int char_duration; int baudrate; int tabstop; - int screen_width; - int screen_height; + std::size_t screen_width; + std::size_t screen_height; }; #pragma pack(pop) diff --git a/src/include/final/fprogressbar.h b/src/include/final/fprogressbar.h index 8670c356..b20b38f8 100644 --- a/src/include/final/fprogressbar.h +++ b/src/include/final/fprogressbar.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2014-2017 Markus Gans * +* Copyright 2014-2018 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 * @@ -82,7 +82,7 @@ class FProgressbar : public FWidget // Mutators void setPercentage (int); - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); bool setShadow (bool); bool setShadow(); bool unsetShadow(); @@ -102,7 +102,7 @@ class FProgressbar : public FWidget // Data Members int percentage; - int bar_length; + std::size_t bar_length; }; #pragma pack(pop) diff --git a/src/include/final/frect.h b/src/include/final/frect.h index b6bbaed6..760f0db0 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -54,7 +54,7 @@ class FRect // Constructors FRect (); FRect (const FRect&); // copy constructor - FRect (int, int, int, int); + FRect (int, int, std::size_t, std::size_t); FRect (const FPoint&, const FPoint&); // Destructor @@ -72,55 +72,55 @@ class FRect // Accessors virtual const char* getClassName(); - int getX1() const; - int getY1() const; - int getX2() const; - int getY2() const; - int getX() const; - int getY() const; - FPoint getPos() const; - FPoint getUpperLeftPos() const; - FPoint getUpperRightPos() const; - FPoint getLowerLeftPos() const; - FPoint getLowerRightPos() const; - int getWidth() const; - int getHeight() const; + int getX1() const; + int getY1() const; + int getX2() const; + int getY2() const; + int getX() const; + int getY() const; + FPoint getPos() const; + FPoint getUpperLeftPos() const; + FPoint getUpperRightPos() const; + FPoint getLowerLeftPos() const; + FPoint getLowerRightPos() const; + std::size_t getWidth() const; + std::size_t getHeight() const; // Mutators - void setX1 (int); - void setY1 (int); - void setX2 (int); - void setY2 (int); - void setX (int); - void setY (int); - void setPos (int, int); - void setPos (const FPoint&); - void setWidth (int); - void setHeight (int); - void setSize (int, int); - void setRect (const FRect&); - void setRect (int, int, int, int); - void setCoordinates (const FPoint&, const FPoint&); - void setCoordinates (int, int, int, int); + void setX1 (int); + void setY1 (int); + void setX2 (int); + void setY2 (int); + void setX (int); + void setY (int); + void setPos (int, int); + void setPos (const FPoint&); + void setWidth (std::size_t); + void setHeight (std::size_t); + void setSize (std::size_t, std::size_t); + void setRect (const FRect&); + void setRect (int, int, std::size_t, std::size_t); + void setCoordinates (const FPoint&, const FPoint&); + void setCoordinates (int, int, int, int); // Inquiry - bool isNull() const; + bool isNull() const; // Coordinate references - short& x1_ref(); - short& y1_ref(); - short& x2_ref(); - short& y2_ref(); + short& x1_ref(); + short& y1_ref(); + short& x2_ref(); + short& y2_ref(); // Methods - void move (int, int); - void move (const FPoint&); - bool contains (int, int) const; - bool contains (const FPoint&) const; - bool contains (const FRect&) const; - bool overlap (const FRect&) const; - FRect intersect (const FRect&) const; - FRect combined (const FRect&) const; + void move (int, int); + void move (const FPoint&); + bool contains (int, int) const; + bool contains (const FPoint&) const; + bool contains (const FRect&) const; + bool overlap (const FRect&) const; + FRect intersect (const FRect&) const; + FRect combined (const FRect&) const; private: // Data Members @@ -150,11 +150,11 @@ inline FRect::FRect (const FRect& r) // copy constructor { } //---------------------------------------------------------------------- -inline FRect::FRect (int x, int y, int width, int height) +inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) : X1(short(x)) , Y1(short(y)) - , X2(short(x + width - 1)) - , Y2(short(y + height - 1)) + , X2(short(x + short(width) - 1)) + , Y2(short(y + short(height) - 1)) { } //---------------------------------------------------------------------- @@ -206,12 +206,18 @@ inline FPoint FRect::getLowerRightPos() const { return FPoint(X2, Y2); } //---------------------------------------------------------------------- -inline int FRect::getWidth() const -{ return short(X2 - X1 + 1); } +inline std::size_t FRect::getWidth() const +{ + short w = X2 - X1 + 1; + return ( w < 0 ) ? 0 : std::size_t(w); +} //---------------------------------------------------------------------- -inline int FRect::getHeight() const -{ return short(Y2 - Y1 + 1); } +inline std::size_t FRect::getHeight() const +{ + short h = Y2 - Y1 + 1; + return ( h < 0 ) ? 0 : std::size_t(h); +} //---------------------------------------------------------------------- inline short& FRect::x1_ref() diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index 343a264b..c97741ee 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -103,7 +103,7 @@ class FScrollbar : public FWidget void setSteps (double); void setPageSize (int, int); void setOrientation (int); - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); // Methods virtual void resize(); @@ -149,14 +149,14 @@ class FScrollbar : public FWidget int slider_click_stop_pos; int current_slider_pos; int slider_pos; - int slider_length; - int bar_length; + std::size_t slider_length; + std::size_t bar_length; int val; int min; int max; double steps; int pagesize; - int length; + std::size_t length; int bar_orientation; int max_color; }; diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index fbf16c4d..64514c7d 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -82,25 +82,25 @@ class FScrollView : public FWidget // Accessors const char* getClassName() const; - int getViewportWidth() const; - int getViewportHeight() const; - int getScrollWidth() const; - int getScrollHeight() const; + std::size_t getViewportWidth() const; + std::size_t getViewportHeight() const; + std::size_t getScrollWidth() const; + std::size_t getScrollHeight() const; const FPoint getScrollPos() const; int getScrollX() const; int getScrollY() const; // Mutator - virtual void setScrollWidth (int); - virtual void setScrollHeight (int); - virtual void setScrollSize (int, int); + virtual void setScrollWidth (std::size_t); + virtual void setScrollHeight (std::size_t); + virtual void setScrollSize (std::size_t, std::size_t); virtual void setX (int, bool = true); virtual void setY (int, bool = true); virtual void setPos (int, int, bool = true); - virtual void setWidth (int, bool = true); - virtual void setHeight (int, bool = true); - virtual void setSize (int, int, bool = true); - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setWidth (std::size_t, bool = true); + virtual void setHeight (std::size_t, bool = true); + virtual void setSize (std::size_t, std::size_t, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); void setCursorPos (int, int); void setPrintPos (int, int); bool setViewportPrint (bool); @@ -195,19 +195,19 @@ inline const char* FScrollView::getClassName() const { return "FScrollView"; } //---------------------------------------------------------------------- -inline int FScrollView::getViewportWidth() const -{ return getWidth() - vertical_border_spacing - nf_offset; } +inline std::size_t FScrollView::getViewportWidth() const +{ return getWidth() - vertical_border_spacing - std::size_t(nf_offset); } //---------------------------------------------------------------------- -inline int FScrollView::getViewportHeight() const +inline std::size_t FScrollView::getViewportHeight() const { return getHeight() - horizontal_border_spacing; } //---------------------------------------------------------------------- -inline int FScrollView::getScrollWidth() const +inline std::size_t FScrollView::getScrollWidth() const { return scroll_geometry.getWidth(); } //---------------------------------------------------------------------- -inline int FScrollView::getScrollHeight() const +inline std::size_t FScrollView::getScrollHeight() const { return scroll_geometry.getHeight(); } //---------------------------------------------------------------------- diff --git a/src/include/final/fstatusbar.h b/src/include/final/fstatusbar.h index 3749278d..aa4416a5 100644 --- a/src/include/final/fstatusbar.h +++ b/src/include/final/fstatusbar.h @@ -203,7 +203,7 @@ class FStatusBar : public FWindow virtual const char* getClassName() const; FStatusKey* getStatusKey (int) const; FString getMessage() const; - uInt getCount() const; + std::size_t getCount() const; // Mutators void activateKey (int); @@ -253,7 +253,7 @@ class FStatusBar : public FWindow keyList key_list; FString text; bool mouse_down; - int screenWidth; + std::size_t screenWidth; int keyname_len; int x; int x_msg; @@ -271,8 +271,8 @@ inline FStatusKey* FStatusBar::getStatusKey (int index) const { return key_list[uInt(index - 1)]; } //---------------------------------------------------------------------- -inline uInt FStatusBar::getCount() const -{ return uInt(key_list.size()); } +inline std::size_t FStatusBar::getCount() const +{ return key_list.size(); } //---------------------------------------------------------------------- inline void FStatusBar::activateKey (int index) diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index d59eff85..eca1666c 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -80,11 +80,9 @@ class FString // Constructors FString (); explicit FString (int); - explicit FString (uInt); - FString (int, wchar_t); - FString (uInt, wchar_t); - FString (int, char); - FString (uInt, char); + explicit FString (std::size_t); + FString (std::size_t, wchar_t); + FString (std::size_t, char); FString (const FString&); // implicit conversion copy constructor FString (const std::wstring&); // implicit conversion constructor FString (const wchar_t[]); // implicit conversion constructor @@ -132,8 +130,7 @@ class FString const FString& operator >> (double&); const FString& operator >> (float&); - wchar_t& operator [] (int); - wchar_t& operator [] (uInt); + wchar_t& operator [] (std::size_t); const FString& operator () (); bool operator < (const FString&) const; @@ -181,8 +178,8 @@ class FString bool isEmpty() const; // Methods - uInt getLength() const; - uInt getUTF8length() const; + std::size_t getLength() const; + std::size_t getUTF8length() const; iterator begin() const; iterator end() const; @@ -214,12 +211,9 @@ class FString FString rtrim() const; FString trim() const; - FString left (int) const; - FString left (uInt) const; - FString right (int) const; - FString right (uInt) const; - FString mid (int, int) const; - FString mid (uInt, uInt) const; + FString left (std::size_t) const; + FString right (std::size_t) const; + FString mid (std::size_t, std::size_t) const; FStringList split (const FString&); FString& setString (const FString&); @@ -242,7 +236,7 @@ class FString FString& setFormatedNumber (uLong, char = nl_langinfo(THOUSEP)[0]); const FString& insert (const FString&, int); - const FString& insert (const FString&, uInt); + const FString& insert (const FString&, std::size_t); FString replace (const FString&, const FString&); @@ -252,10 +246,9 @@ class FString FString removeBackspaces() const; const FString& overwrite (const FString&, int); - const FString& overwrite (const FString&, uInt = 0); + const FString& overwrite (const FString&, std::size_t = 0); - const FString& remove (int, uInt); - const FString& remove (uInt, uInt); + const FString& remove (std::size_t, std::size_t); bool includes (const FString&) const; private: @@ -266,19 +259,19 @@ class FString static const char* const bad_alloc_str; // Methods - void initLength (uInt); + void initLength (std::size_t); void _assign (const wchar_t[]); - void _insert (uInt, const wchar_t[]); - void _insert (uInt, uInt, const wchar_t[]); - void _remove (uInt, uInt); + void _insert (std::size_t, const wchar_t[]); + void _insert (std::size_t, std::size_t, const wchar_t[]); + void _remove (std::size_t, std::size_t); char* wc_to_c_str (const wchar_t[]) const; wchar_t* c_to_wc_str (const char[]) const; wchar_t* extractToken (wchar_t*[], const wchar_t[], const wchar_t[]); // Data Members wchar_t* string; - uInt length; - uInt bufsize; + std::size_t length; + std::size_t bufsize; mutable char* c_string; }; @@ -345,7 +338,7 @@ inline bool FString::isEmpty() const { return ( ! string ) || ( ! *string ); } //---------------------------------------------------------------------- -inline uInt FString::getLength() const +inline std::size_t FString::getLength() const { return length; } //---------------------------------------------------------------------- diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 2f463262..29dd9cb1 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -166,8 +166,8 @@ class FTerm virtual const char* getClassName() const; static FKeyboard* getKeyboard(); static FMouseControl* getMouseControl(); - static int getLineNumber(); - static int getColumnNumber(); + static std::size_t getLineNumber(); + static std::size_t getColumnNumber(); static const FString getKeyName (int); static int getTTYFileDescriptor(); @@ -236,7 +236,7 @@ class FTerm static char* enableCursor(); static char* disableCursor(); static void detectTermSize(); - static void setTermSize (int, int); + static void setTermSize (std::size_t, std::size_t); static void setTermTitle(const FString&); static void setKDECursor (fc::kdeKonsoleCursorShape); static void saveColorMap(); diff --git a/src/include/final/ftermxterminal.h b/src/include/final/ftermxterminal.h index b8ed1e7c..65c97ef8 100644 --- a/src/include/final/ftermxterminal.h +++ b/src/include/final/ftermxterminal.h @@ -65,7 +65,7 @@ class FTermXTerminal static void setCursorStyle (fc::xtermCursorStyle); static void setFont (const FString&); static void setTitle (const FString&); - static void setTermSize (int, int); + static void setTermSize (std::size_t, std::size_t); static void setForeground (const FString&); static void setBackground (const FString&); static void setCursorColor (const FString&); @@ -139,8 +139,8 @@ class FTermXTerminal static bool mouse_support; static bool meta_sends_esc; static bool xterm_default_colors; - static int term_width; - static int term_height; + static std::size_t term_width; + static std::size_t term_height; static const FString* xterm_font; static const FString* xterm_title; static const FString* foreground_color; diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 6e04ff2e..72d28878 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -84,13 +84,13 @@ class FTextView : public FWidget // Accessors const char* getClassName() const; - uInt getColumns() const; - uInt getRows() const; + std::size_t getColumns() const; + std::size_t getRows() const; const FString getText() const; const FStringList& getLines() const; // Mutators - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); void setText (const FString&); void scrollToX (int); void scrollToY (int); @@ -128,8 +128,8 @@ class FTextView : public FWidget FTextView& operator = (const FTextView&); // Accessors - int getTextHeight(); - int getTextWidth(); + std::size_t getTextHeight(); + std::size_t getTextWidth(); // Methods void init(); @@ -151,7 +151,7 @@ class FTextView : public FWidget int xoffset; int yoffset; int nf_offset; - uInt maxLineWidth; + std::size_t maxLineWidth; }; #pragma pack(pop) @@ -162,12 +162,12 @@ inline const char* FTextView::getClassName() const { return "FTextView"; } //---------------------------------------------------------------------- -inline uInt FTextView::getColumns() const +inline std::size_t FTextView::getColumns() const { return maxLineWidth; } //---------------------------------------------------------------------- -inline uInt FTextView::getRows() const -{ return uInt(data.size()); } +inline std::size_t FTextView::getRows() const +{ return std::size_t(data.size()); } //---------------------------------------------------------------------- inline const FStringList& FTextView::getLines() const diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 0beceeb5..3f382c98 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -85,7 +85,7 @@ class FToggleButton : public FWidget FString& getText(); // Mutators - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); bool setNoUnderline (bool); bool setNoUnderline(); bool unsetNoUnderline(); @@ -139,8 +139,8 @@ class FToggleButton : public FWidget // Data Members bool checked; - int label_offset_pos; - int button_width; // plus margin spaces + std::size_t label_offset_pos; + std::size_t button_width; // plus margin spaces private: // Disable copy constructor @@ -154,8 +154,8 @@ class FToggleButton : public FWidget // Methods void init(); - int getHotkeyPos (wchar_t[], wchar_t[], uInt); - void drawText (wchar_t[], int, uInt); + int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + void drawText (wchar_t[], int, std::size_t); // Friend classes friend class FButtonGroup; diff --git a/src/include/final/ftooltip.h b/src/include/final/ftooltip.h index b3987731..37c2f567 100644 --- a/src/include/final/ftooltip.h +++ b/src/include/final/ftooltip.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2016-2017 Markus Gans * +* Copyright 2016-2018 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 * @@ -112,8 +112,8 @@ class FToolTip : public FWindow FString text; FString* text_components; FStringList text_split; - uInt max_line_width; - uInt text_num_lines; + std::size_t max_line_width; + std::size_t text_num_lines; }; #pragma pack(pop) diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 73838541..90154c6d 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -170,23 +170,23 @@ class FWidget : public FVTerm, public FObject int getTermX() const; int getTermY() const; const FPoint getTermPos() const; - int getWidth() const; - int getHeight() const; + std::size_t getWidth() const; + std::size_t getHeight() const; int getTopPadding() const; int getLeftPadding() const; int getBottomPadding() const; int getRightPadding() const; - int getClientWidth() const; - int getClientHeight() const; - int getMaxWidth() const; - int getMaxHeight() const; + std::size_t getClientWidth() const; + std::size_t getClientHeight() const; + std::size_t getMaxWidth() const; + std::size_t getMaxHeight() const; const FPoint& getShadow() const; const FRect& getGeometry() const; const FRect& getGeometryWithShadow(); const FRect& getTermGeometry(); const FRect& getTermGeometryWithShadow(); - int getDesktopWidth(); - int getDesktopHeight(); + std::size_t getDesktopWidth(); + std::size_t getDesktopHeight(); int getFlags() const; FPoint getCursorPos(); FPoint getPrintPos(); @@ -222,9 +222,9 @@ class FWidget : public FVTerm, public FObject virtual void setY (int, bool = true); virtual void setPos (const FPoint&, bool = true); virtual void setPos (int, int, bool = true); - virtual void setWidth (int, bool = true); - virtual void setHeight (int, bool = true); - virtual void setSize (int, int, bool = true); + virtual void setWidth (std::size_t, bool = true); + virtual void setHeight (std::size_t, bool = true); + virtual void setSize (std::size_t, std::size_t, bool = true); void setTopPadding (int, bool = true); void setLeftPadding (int, bool = true); void setBottomPadding (int, bool = true); @@ -232,17 +232,17 @@ class FWidget : public FVTerm, public FObject void setParentOffset(); void setTermOffset(); void setTermOffsetWithPadding(); - void setTermSize (int, int); + void setTermSize (std::size_t, std::size_t); virtual void setGeometry (const FRect&, bool = true); - virtual void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); virtual void setShadowSize (int, int); - void setMinimumWidth (int); - void setMinimumHeight (int); - void setMinimumSize (int, int); - void setMaximumWidth (int); - void setMaximumHeight (int); - void setMaximumSize (int, int); - void setFixedSize (int, int); + void setMinimumWidth (std::size_t); + void setMinimumHeight (std::size_t); + void setMinimumSize (std::size_t, std::size_t); + void setMaximumWidth (std::size_t); + void setMaximumHeight (std::size_t); + void setMaximumSize (std::size_t, std::size_t); + void setFixedSize (std::size_t, std::size_t); bool setCursorPos (const FPoint&); bool setCursorPos (int, int); void unsetCursorPos(); @@ -414,8 +414,8 @@ class FWidget : public FVTerm, public FObject struct widget_size_hints { widget_size_hints() - : min_width (INT_MIN) - , min_height (INT_MIN) + : min_width (0) + , min_height (0) , max_width (INT_MAX) , max_height (INT_MAX) { } @@ -423,22 +423,22 @@ class FWidget : public FVTerm, public FObject ~widget_size_hints() { } - void setMinimum (int w, int h) + void setMinimum (std::size_t w, std::size_t h) { min_width = w; min_height = h; } - void setMaximum (int w, int h) + void setMaximum (std::size_t w, std::size_t h) { max_width = w; max_height = h; } - int min_width; - int min_height; - int max_width; - int max_height; + std::size_t min_width; + std::size_t min_height; + std::size_t max_width; + std::size_t max_height; } size_hints; struct dbl_line_mask @@ -545,11 +545,11 @@ inline const FPoint FWidget::getTermPos() const // position on terminal { return FPoint(getTermX(), getTermY()); } //---------------------------------------------------------------------- -inline int FWidget::getWidth() const +inline std::size_t FWidget::getWidth() const { return adjust_wsize.getWidth(); } //---------------------------------------------------------------------- -inline int FWidget::getHeight() const +inline std::size_t FWidget::getHeight() const { return adjust_wsize.getHeight(); } //---------------------------------------------------------------------- @@ -569,19 +569,19 @@ inline int FWidget::getRightPadding() const { return padding.right; } //---------------------------------------------------------------------- -inline int FWidget::getClientWidth() const +inline std::size_t FWidget::getClientWidth() const { return client_offset.getWidth(); } //---------------------------------------------------------------------- -inline int FWidget::getClientHeight() const +inline std::size_t FWidget::getClientHeight() const { return client_offset.getHeight(); } //---------------------------------------------------------------------- -inline int FWidget::getMaxWidth() const +inline std::size_t FWidget::getMaxWidth() const { return offset.getWidth(); } //---------------------------------------------------------------------- -inline int FWidget::getMaxHeight() const +inline std::size_t FWidget::getMaxHeight() const { return offset.getHeight(); } //---------------------------------------------------------------------- @@ -635,11 +635,11 @@ inline const FRect& FWidget::getTermGeometryWithShadow() } //---------------------------------------------------------------------- -inline int FWidget::getDesktopWidth() +inline std::size_t FWidget::getDesktopWidth() { return getColumnNumber(); } //---------------------------------------------------------------------- -inline int FWidget::getDesktopHeight() +inline std::size_t FWidget::getDesktopHeight() { return getLineNumber(); } //---------------------------------------------------------------------- @@ -731,8 +731,8 @@ inline void FWidget::setGeometry (const FRect& box, bool adjust) { setGeometry ( box.getX() , box.getY() - , box.getWidth() - , box.getHeight() + , std::size_t(box.getWidth()) + , std::size_t(box.getHeight()) , adjust ); } @@ -741,31 +741,31 @@ inline void FWidget::setShadowSize (int right, int bottom) { wshadow.setPoint (right, bottom); } //---------------------------------------------------------------------- -inline void FWidget::setMinimumWidth (int min_width) +inline void FWidget::setMinimumWidth (std::size_t min_width) { size_hints.setMinimum (min_width, size_hints.min_height); } //---------------------------------------------------------------------- -inline void FWidget::setMinimumHeight (int min_height) +inline void FWidget::setMinimumHeight (std::size_t min_height) { size_hints.setMinimum (size_hints.min_width, min_height); } //---------------------------------------------------------------------- -inline void FWidget::setMinimumSize (int min_width, int min_height) +inline void FWidget::setMinimumSize (std::size_t min_width, std::size_t min_height) { size_hints.setMinimum (min_width, min_height); } //---------------------------------------------------------------------- -inline void FWidget::setMaximumWidth (int max_width) +inline void FWidget::setMaximumWidth (std::size_t max_width) { size_hints.setMaximum (max_width, size_hints.max_height); } //---------------------------------------------------------------------- -inline void FWidget::setMaximumHeight (int max_height) +inline void FWidget::setMaximumHeight (std::size_t max_height) { size_hints.setMaximum (size_hints.max_width, max_height); } //---------------------------------------------------------------------- -inline void FWidget::setMaximumSize (int max_width, int max_height) +inline void FWidget::setMaximumSize (std::size_t max_width, std::size_t max_height) { size_hints.setMaximum (max_width, max_height); } //---------------------------------------------------------------------- -inline void FWidget::setFixedSize (int width, int height) +inline void FWidget::setFixedSize (std::size_t width, std::size_t height) { size_hints.setMinimum (width, height); size_hints.setMaximum (width, height); @@ -864,7 +864,7 @@ inline void FWidget::move (const FPoint& pos) //---------------------------------------------------------------------- inline void FWidget::drawBorder() -{ drawBorder (1, 1, getWidth(), getHeight()); } +{ drawBorder (1, 1, int(getWidth()), int(getHeight())); } //---------------------------------------------------------------------- inline void FWidget::processDestroy() diff --git a/src/include/final/fwindow.h b/src/include/final/fwindow.h index 0125cfe7..d05dda77 100644 --- a/src/include/final/fwindow.h +++ b/src/include/final/fwindow.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2015-2017 Markus Gans * +* Copyright 2015-2018 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 * @@ -133,10 +133,10 @@ class FWindow : public FWidget virtual void setX (int, bool = true); virtual void setY (int, bool = true); virtual void setPos (int, int, bool = true); - virtual void setWidth (int, bool = true); - virtual void setHeight (int, bool = true); - virtual void setSize (int, int, bool = true); - void setGeometry (int, int, int, int, bool = true); + virtual void setWidth (std::size_t, bool = true); + virtual void setHeight (std::size_t, bool = true); + virtual void setSize (std::size_t, std::size_t, bool = true); + void setGeometry (int, int, std::size_t, std::size_t, bool = true); virtual void move (int, int); static FWindow* getWindowWidgetAt (const FPoint&); static FWindow* getWindowWidgetAt (int, int); diff --git a/test/fstring-test.cpp b/test/fstring-test.cpp index 51982299..451d61e9 100644 --- a/test/fstring-test.cpp +++ b/test/fstring-test.cpp @@ -220,8 +220,8 @@ void FStringTest::initLengthTest() CPPUNIT_ASSERT ( s1.isNull() ); CPPUNIT_ASSERT ( s1.isEmpty() ); - const int x1 = 10; - const uInt x2 = 10; + const int x1 = 10; + const std::size_t x2 = 10; const finalcut::FString s2(x1); CPPUNIT_ASSERT ( s2.getLength() == 10 ); CPPUNIT_ASSERT ( ! s2.isNull() ); @@ -1261,7 +1261,8 @@ void FStringTest::subStringTest() CPPUNIT_ASSERT ( str1.left(int(11)) == L"Look behind" ); CPPUNIT_ASSERT ( str1.left(999) == L"Look behind you, a three-headed monkey!" ); - CPPUNIT_ASSERT ( str1.left(-5) == L"" ); + CPPUNIT_ASSERT ( str1.left(-5) + == L"Look behind you, a three-headed monkey!" ); CPPUNIT_ASSERT ( str1.left(0) == L"" ); CPPUNIT_ASSERT ( str1.left(0).isEmpty() ); CPPUNIT_ASSERT ( ! str1.left(0).isNull() ); @@ -1273,7 +1274,8 @@ void FStringTest::subStringTest() CPPUNIT_ASSERT ( str1.right(int(7)) == L"monkey!" ); CPPUNIT_ASSERT ( str1.right(999) == L"Look behind you, a three-headed monkey!" ); - CPPUNIT_ASSERT ( str1.right(-5) == L"" ); + CPPUNIT_ASSERT ( str1.right(-5) + == L"Look behind you, a three-headed monkey!" ); CPPUNIT_ASSERT ( str1.right(0) == L"" ); CPPUNIT_ASSERT ( str1.right(0).isEmpty() ); CPPUNIT_ASSERT ( ! str1.right(0).isNull() ); @@ -1290,7 +1292,7 @@ void FStringTest::subStringTest() CPPUNIT_ASSERT ( str1.mid(5, 0) == L"" ); CPPUNIT_ASSERT ( str1.mid(-5, 2) == L"" ); CPPUNIT_ASSERT ( str1.mid(0, 0) == L"" ); - CPPUNIT_ASSERT ( str1.mid(0, 5) == L"" ); + CPPUNIT_ASSERT ( str1.mid(0, 5) == L"Look " ); CPPUNIT_ASSERT ( str1.mid(0, 0).isEmpty() ); CPPUNIT_ASSERT ( ! str1.mid(0, 0).isNull() ); CPPUNIT_ASSERT ( finalcut::FString().mid(5, 0).isNull() ); From 6b753c54edcd88b35341c6912cfef84b6dc5ac5b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 14 Oct 2018 20:15:52 +0200 Subject: [PATCH 10/17] Add #pragma pack to FString --- src/include/final/emptyfstring.h | 5 +++++ src/include/final/fstring.h | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/include/final/emptyfstring.h b/src/include/final/emptyfstring.h index 5e941879..7835a8b2 100644 --- a/src/include/final/emptyfstring.h +++ b/src/include/final/emptyfstring.h @@ -38,6 +38,10 @@ namespace fc //---------------------------------------------------------------------- // class emptyFString //---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + class emptyFString { public: @@ -58,6 +62,7 @@ private: // Data Member static const FString* empty_string; }; +#pragma pack(pop) // emptyFString inline functions //---------------------------------------------------------------------- diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index eca1666c..89aedc39 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -71,6 +71,9 @@ typedef std::vector FStringList; // class FString //---------------------------------------------------------------------- +#pragma pack(push) +#pragma pack(1) + class FString { public: @@ -274,7 +277,7 @@ class FString std::size_t bufsize; mutable char* c_string; }; - +#pragma pack(pop) // FString inline functions //---------------------------------------------------------------------- From de4be23a045bb9ab62d11d709e9aa824868c067a Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 15 Oct 2018 01:34:57 +0200 Subject: [PATCH 11/17] FString fix for 32-bit architectures --- ChangeLog | 1 + src/fstring.cpp | 9 +++++++++ src/ftermxterminal.cpp | 4 +++- src/include/final/fstring.h | 17 ++++++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index dffab7fc..76f8b818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2018-10-14 Markus Gans * A width or height can not be negative. For that reason the change from int to std::size_t. + * FString fix for 32-bit architectures 2018-10-13 Markus Gans * Avoid using dynamic_cast so that you can compile Final Cut diff --git a/src/fstring.cpp b/src/fstring.cpp index b6bcf696..6fefd216 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -452,6 +452,15 @@ wchar_t& FString::operator [] (std::size_t pos) return string[pos]; } +//---------------------------------------------------------------------- +const wchar_t& FString::operator [] (std::size_t pos) const +{ + if ( pos >= length ) + throw std::out_of_range(""); // Invalid index position + + return string[pos]; +} + //---------------------------------------------------------------------- const FString& FString::operator () () { diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index d2436da1..2aee3374 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -417,7 +417,9 @@ void FTermXTerminal::setXTermSize() { if ( term_detection->isXTerminal() ) { - FTerm::putstringf (CSI "8;%lu;%lut", term_height, term_width); + FTerm::putstringf ( CSI "8;%lu;%lut" + , uLong(term_height) + , uLong(term_width) ); std::fflush(stdout); } } diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 89aedc39..10738cea 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -133,7 +133,12 @@ class FString const FString& operator >> (double&); const FString& operator >> (float&); - wchar_t& operator [] (std::size_t); + template + wchar_t& operator [] (IndexT); + template + const wchar_t& operator [] (IndexT) const; + wchar_t& operator [] (std::size_t); + const wchar_t& operator [] (std::size_t) const; const FString& operator () (); bool operator < (const FString&) const; @@ -284,6 +289,16 @@ class FString inline const char* FString::getClassName() { return "FString"; } +//---------------------------------------------------------------------- +template +inline wchar_t& FString::operator [] (IndexT pos) +{ return string[std::size_t(pos)]; } + +//---------------------------------------------------------------------- +template +inline const wchar_t& FString::operator [] (IndexT pos) const +{ return string[std::size_t(pos)]; } + //---------------------------------------------------------------------- template inline bool FString::operator < (CharT& s) const From 4fac4627cdf0494a7d6a4a2df26e7ac61ae1ae41 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 15 Oct 2018 01:51:09 +0200 Subject: [PATCH 12/17] FString fix for 32-bit architectures --- src/fstring.cpp | 18 ------------------ src/include/final/fstring.h | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/fstring.cpp b/src/fstring.cpp index 6fefd216..bfff3f9d 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -443,24 +443,6 @@ const FString& FString::operator >> (float& num) return *this; } -//---------------------------------------------------------------------- -wchar_t& FString::operator [] (std::size_t pos) -{ - if ( pos >= length ) - throw std::out_of_range(""); // Invalid index position - - return string[pos]; -} - -//---------------------------------------------------------------------- -const wchar_t& FString::operator [] (std::size_t pos) const -{ - if ( pos >= length ) - throw std::out_of_range(""); // Invalid index position - - return string[pos]; -} - //---------------------------------------------------------------------- const FString& FString::operator () () { diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 10738cea..73ac4866 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -137,8 +137,6 @@ class FString wchar_t& operator [] (IndexT); template const wchar_t& operator [] (IndexT) const; - wchar_t& operator [] (std::size_t); - const wchar_t& operator [] (std::size_t) const; const FString& operator () (); bool operator < (const FString&) const; @@ -292,12 +290,22 @@ inline const char* FString::getClassName() //---------------------------------------------------------------------- template inline wchar_t& FString::operator [] (IndexT pos) -{ return string[std::size_t(pos)]; } +{ + if ( pos < 0 || pos >= IndexT(length) ) + throw std::out_of_range(""); // Invalid index position + + return string[std::size_t(pos)]; +} //---------------------------------------------------------------------- template inline const wchar_t& FString::operator [] (IndexT pos) const -{ return string[std::size_t(pos)]; } +{ + if ( pos < 0 || pos >= IndexT(length) ) + throw std::out_of_range(""); // Invalid index position + + return string[std::size_t(pos)]; +} //---------------------------------------------------------------------- template From 94e00051c577a278448306722056b762d2fb66c4 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 17 Oct 2018 22:12:52 +0200 Subject: [PATCH 13/17] Changed more variables from int to std::size_t --- ChangeLog | 5 +- src/fbutton.cpp | 94 +++++++++++++++---------------- src/fbuttongroup.cpp | 26 ++++----- src/fdialog.cpp | 4 +- src/flabel.cpp | 38 ++++++------- src/flineedit.cpp | 77 ++++++++++++------------- src/flistview.cpp | 4 +- src/fmessagebox.cpp | 2 +- src/fscrollview.cpp | 14 +++-- src/fswitch.cpp | 10 ++-- src/ftogglebutton.cpp | 16 +++--- src/include/final/fbutton.h | 19 ++++--- src/include/final/fbuttongroup.h | 7 ++- src/include/final/fdialog.h | 6 +- src/include/final/flabel.h | 8 ++- src/include/final/flineedit.h | 2 +- src/include/final/flistview.h | 4 +- src/include/final/fmessagebox.h | 2 +- src/include/final/fscrollview.h | 2 +- src/include/final/fswitch.h | 2 +- src/include/final/ftermbuffer.h | 6 +- src/include/final/ftogglebutton.h | 7 ++- 22 files changed, 185 insertions(+), 170 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76f8b818..350a9eee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ +2018-10-17 Markus Gans + * Changed more variables from int to std::size_t + 2018-10-14 Markus Gans * A width or height can not be negative. - For that reason the change from int to std::size_t. + For that reason the change from int to std::size_t * FString fix for 32-bit architectures 2018-10-13 Markus Gans diff --git a/src/fbutton.cpp b/src/fbutton.cpp index c7ae8689..b3962d21 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -39,12 +39,12 @@ FButton::FButton(FWidget* parent) , button_down(false) , click_animation(true) , click_time(150) + , space_char(int(' ')) + , hotkeypos(NOT_FOUND) , indent(0) - , space(int(' ')) , center_offset(0) , vcenter_offset(0) , txtlength(0) - , hotkeypos(-1) , button_fg(wc.button_active_fg) , button_bg(wc.button_active_bg) , button_hotkey_fg(wc.button_hotkey_fg) @@ -64,12 +64,12 @@ FButton::FButton (const FString& txt, FWidget* parent) , button_down(false) , click_animation(true) , click_time(150) + , space_char(int(' ')) + , hotkeypos(NOT_FOUND) , indent(0) - , space(int(' ')) , center_offset(0) , vcenter_offset(0) , txtlength(0) - , hotkeypos(-1) , button_fg(wc.button_active_fg) , button_bg(wc.button_active_bg) , button_hotkey_fg(wc.button_hotkey_fg) @@ -542,20 +542,20 @@ inline void FButton::detectHotkey() } //---------------------------------------------------------------------- -int FButton::getHotkeyPos ( wchar_t src[] - , wchar_t dest[] - , std::size_t length ) +std::size_t FButton::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign - int pos = -1; wchar_t* txt = src; + std::size_t pos = NOT_FOUND; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && pos == -1 ) + if ( i < length && txt[i] == L'&' && pos == NOT_FOUND ) { - pos = int(i); + pos = i; i++; src++; } @@ -567,7 +567,7 @@ int FButton::getHotkeyPos ( wchar_t src[] } //---------------------------------------------------------------------- -inline int FButton::clickAnimationIndent (FWidget* parent_widget) +inline std::size_t FButton::clickAnimationIndent (FWidget* parent_widget) { if ( ! button_down || ! click_animation ) return 0; @@ -582,9 +582,9 @@ inline int FButton::clickAnimationIndent (FWidget* parent_widget) setColor ( parent_widget->getForegroundColor() , parent_widget->getBackgroundColor() ); - for (int y = 1; y <= int(getHeight()); y++) + for (std::size_t y = 1; y <= getHeight(); y++) { - setPrintPos (1, y); + setPrintPos (1, int(y)); print (' '); // clear one left █ } @@ -622,14 +622,14 @@ inline void FButton::drawMarginLeft() setColor (getForegroundColor(), button_bg); - for (int y = 0; y < int(getHeight()); y++) + for (std::size_t y = 0; y < getHeight(); y++) { - setPrintPos (1 + indent, 1 + y); + setPrintPos (1 + int(indent), 1 + int(y)); if ( isMonochron() && is.active_focus && y == vcenter_offset ) print (fc::BlackRightPointingPointer); // ► else - print (space); // full block █ + print (space_char); // full block █ } } @@ -638,14 +638,14 @@ inline void FButton::drawMarginRight() { // Print right margin - for (int y = 0; y < int(getHeight()); y++) + for (std::size_t y = 0; y < getHeight(); y++) { - setPrintPos (int(getWidth()) + indent, 1 + y); + setPrintPos (int(getWidth() + indent), 1 + int(y)); if ( isMonochron() && is.active_focus && y == vcenter_offset ) print (fc::BlackLeftPointingPointer); // ◄ else - print (space); // full block █ + print (space_char); // full block █ } } @@ -657,41 +657,41 @@ inline void FButton::drawTopBottomBackground() if ( getHeight() < 2 ) return; - for (int y = 0; y < vcenter_offset; y++) + for (std::size_t y = 0; y < vcenter_offset; y++) { - setPrintPos (2 + indent, 1 + y); + setPrintPos (2 + int(indent), 1 + int(y)); for (std::size_t x = 1; x < getWidth() - 1; x++) - print (space); // █ + print (space_char); // █ } - for (int y = vcenter_offset + 1; y < int(getHeight()); y++) + for (std::size_t y = vcenter_offset + 1; y < getHeight(); y++) { - setPrintPos (2 + indent, 1 + y); + setPrintPos (2 + int(indent), 1 + int(y)); for (std::size_t x = 1; x < getWidth() - 1; x++) - print (space); // █ + print (space_char); // █ } } //---------------------------------------------------------------------- inline void FButton::drawButtonTextLine (wchar_t button_text[]) { - int pos; - center_offset = int((int(getWidth()) - txtlength - 1) / 2); - setPrintPos (2 + indent, 1 + vcenter_offset); + std::size_t pos; + center_offset = (getWidth() - txtlength - 1) / 2; + setPrintPos (2 + int(indent), 1 + int(vcenter_offset)); setColor (button_fg, button_bg); // Print button text line -------- for (pos = 0; pos < center_offset; pos++) - print (space); // █ + print (space_char); // █ - if ( hotkeypos == -1 ) - setCursorPos ( 2 + center_offset - , 1 + vcenter_offset ); // first character + if ( hotkeypos == NOT_FOUND ) + setCursorPos ( 2 + int(center_offset) + , 1 + int(vcenter_offset) ); // first character else - setCursorPos ( 2 + center_offset + hotkeypos - , 1 + vcenter_offset ); // hotkey + setCursorPos ( 2 + int(center_offset) + hotkeypos + , 1 + int(vcenter_offset) ); // hotkey if ( ! is.active && isMonochron() ) setReverse(true); // Light background @@ -699,11 +699,11 @@ inline void FButton::drawButtonTextLine (wchar_t button_text[]) if ( is.active_focus && (isMonochron() || getMaxColor() < 16) ) setBold(); - for ( int z = 0 - ; pos < center_offset + txtlength && z < int(getWidth()) - 2 + for ( std::size_t z = 0 + ; pos < center_offset + txtlength && z < getWidth() - 2 ; z++, pos++) { - if ( (z == hotkeypos) && is.active ) + if ( z == hotkeypos && is.active ) { setColor (button_hotkey_fg, button_bg); @@ -729,18 +729,18 @@ inline void FButton::drawButtonTextLine (wchar_t button_text[]) } } - if ( txtlength >= int(getWidth()) - 1 ) + if ( txtlength >= getWidth() - 1 ) { // Print ellipsis - setPrintPos (int(getWidth()) + indent - 2, 1); + setPrintPos (int(getWidth() + indent) - 2, 1); print (L".."); } if ( is.active_focus && (isMonochron() || getMaxColor() < 16) ) unsetBold(); - for (pos = center_offset + txtlength; pos < int(getWidth()) - 2; pos++) - print (space); // █ + for (pos = center_offset + txtlength; pos < getWidth() - 2; pos++) + print (space_char); // █ } //---------------------------------------------------------------------- @@ -748,13 +748,13 @@ void FButton::draw() { wchar_t* button_text; FWidget* parent_widget = getParentWidget(); - txtlength = int(text.getLength()); - space = int(' '); + txtlength = text.getLength(); + space_char = int(' '); getButtonState(); try { - button_text = new wchar_t[std::size_t(txtlength) + 1](); + button_text = new wchar_t[txtlength + 1](); } catch (const std::bad_alloc& ex) { @@ -772,7 +772,7 @@ void FButton::draw() clearRightMargin (parent_widget); if ( ! is.active && isMonochron() ) - space = fc::MediumShade; // ▒ simulates greyed out at Monochron + space_char = fc::MediumShade; // ▒ simulates greyed out at Monochron if ( isMonochron() && (is.active || is.focus) ) setReverse(false); // Dark background @@ -782,11 +782,11 @@ void FButton::draw() hotkeypos = getHotkeyPos(text.wc_str(), button_text, uInt(txtlength)); - if ( hotkeypos != -1 ) + if ( hotkeypos != NOT_FOUND ) txtlength--; if ( getHeight() >= 2 ) - vcenter_offset = int((getHeight() - 1) / 2); + vcenter_offset = (getHeight() - 1) / 2; else vcenter_offset = 0; diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 030c7e24..34affdc3 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -504,7 +504,7 @@ void FButtonGroup::draw() void FButtonGroup::drawLabel() { wchar_t* LabelText; - int hotkeypos; + std::size_t hotkeypos; if ( text.isNull() || text.isEmpty() ) return; @@ -527,7 +527,7 @@ void FButtonGroup::drawLabel() unsetViewportPrint(); hotkeypos = getHotkeyPos(src, dest, length); - if ( hotkeypos != -1 ) + if ( hotkeypos != NOT_FOUND ) length--; if ( hasBorder() ) @@ -565,20 +565,20 @@ void FButtonGroup::init() } //---------------------------------------------------------------------- -int FButtonGroup::getHotkeyPos ( wchar_t src[] - , wchar_t dest[] - , std::size_t length ) +std::size_t FButtonGroup::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign - int pos = -1; + std::size_t pos = NOT_FOUND; wchar_t* txt = src; - for (uInt i = 0; i < length; i++) + for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && pos == -1 ) + if ( i < length && txt[i] == L'&' && pos == NOT_FOUND ) { - pos = int(i); + pos = i; i++; src++; } @@ -591,7 +591,7 @@ int FButtonGroup::getHotkeyPos ( wchar_t src[] //---------------------------------------------------------------------- void FButtonGroup::drawText ( wchar_t LabelText[] - , int hotkeypos + , std::size_t hotkeypos , std::size_t length ) { bool isActive = ((flags & fc::active) != 0); @@ -605,7 +605,7 @@ void FButtonGroup::drawText ( wchar_t LabelText[] else setColor(wc.label_inactive_fg, wc.label_inactive_bg); - for (int z = 0; z < int(length); z++) + for (std::size_t z = 0; z < length; z++) { if ( (z == hotkeypos) && isActive ) { @@ -614,7 +614,7 @@ void FButtonGroup::drawText ( wchar_t LabelText[] if ( ! isNoUnderline ) setUnderline(); - print ( LabelText[z] ); + print (LabelText[z]); if ( ! isNoUnderline ) unsetUnderline(); @@ -622,7 +622,7 @@ void FButtonGroup::drawText ( wchar_t LabelText[] setColor (wc.label_emphasis_fg, wc.label_bg); } else - print ( LabelText[z] ); + print (LabelText[z]); } if ( isMonochron() ) diff --git a/src/fdialog.cpp b/src/fdialog.cpp index f2da97aa..0542e912 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -193,7 +193,7 @@ void FDialog::hide() } //---------------------------------------------------------------------- -int FDialog::exec() +FDialog::DialogCode FDialog::exec() { result_code = FDialog::Reject; show(); @@ -809,7 +809,7 @@ void FDialog::onWindowLowered (FEvent*) // protected methods of FDialog //---------------------------------------------------------------------- -void FDialog::done(int result) +void FDialog::done(DialogCode result) { hide(); result_code = result; diff --git a/src/flabel.cpp b/src/flabel.cpp index a50bce71..74782d61 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -419,20 +419,20 @@ uChar FLabel::getHotkey() } //---------------------------------------------------------------------- -int FLabel::getHotkeyPos ( wchar_t src[] - , wchar_t dest[] - , std::size_t length ) +std::size_t FLabel::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign - int hotkeypos = -1; + std::size_t hotkeypos = NOT_FOUND; wchar_t* txt = src; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && hotkeypos == -1 ) + if ( i < length && txt[i] == L'&' && hotkeypos == NOT_FOUND ) { - hotkeypos = int(i); + hotkeypos = i; i++; src++; } @@ -446,7 +446,7 @@ int FLabel::getHotkeyPos ( wchar_t src[] //---------------------------------------------------------------------- void FLabel::setHotkeyAccelerator() { - int hotkey = getHotkey(); + std::size_t hotkey = getHotkey(); if ( hotkey ) { @@ -476,7 +476,7 @@ std::size_t FLabel::getAlignOffset (std::size_t length) case fc::alignCenter: if ( length < width ) - return std::size_t((width - length) / 2); + return (width - length) / 2; else return 0; @@ -531,7 +531,7 @@ void FLabel::drawMultiLine() while ( y < text_lines && y < std::size_t(getHeight()) ) { wchar_t* label_text; - int hotkeypos = -1; + std::size_t hotkeypos = NOT_FOUND; std::size_t align_offset; std::size_t length = multiline_text[y].getLength(); @@ -555,7 +555,7 @@ void FLabel::drawMultiLine() setPrintPos (1, 1 + int(y)); - if ( hotkeypos != -1 ) + if ( hotkeypos != NOT_FOUND ) { align_offset = getAlignOffset(length - 1); printLine (label_text, length - 1, hotkeypos, align_offset); @@ -564,7 +564,7 @@ void FLabel::drawMultiLine() else { align_offset = getAlignOffset(length); - printLine (label_text, length, -1, align_offset); + printLine (label_text, length, NOT_FOUND, align_offset); } y++; @@ -576,7 +576,7 @@ void FLabel::drawMultiLine() void FLabel::drawSingleLine() { wchar_t* label_text; - int hotkeypos = -1; + std::size_t hotkeypos = NOT_FOUND; std::size_t align_offset; std::size_t length = text.getLength(); @@ -592,10 +592,10 @@ void FLabel::drawSingleLine() hotkeypos = getHotkeyPos (text.wc_str(), label_text, length); - if ( hotkeypos != -1 ) + if ( hotkeypos != NOT_FOUND ) length--; - setPrintPos (1,1); + setPrintPos (1, 1); align_offset = getAlignOffset(length); printLine (label_text, length, hotkeypos, align_offset); delete[] label_text; @@ -604,8 +604,8 @@ void FLabel::drawSingleLine() //---------------------------------------------------------------------- void FLabel::printLine ( wchar_t line[] , std::size_t length - , int hotkeypos - , std::size_t align_offset ) + , std::size_t hotkeypos + , std::size_t align_offset ) { std::size_t to_char; std::size_t width = std::size_t(getWidth()); @@ -635,14 +635,14 @@ void FLabel::printLine ( wchar_t line[] } } - if ( (int(z) == hotkeypos) && isActive ) + if ( z == hotkeypos && isActive ) { setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); if ( ! isNoUnderline ) setUnderline(); - print ( line[z] ); + print (line[z]); if ( ! isNoUnderline ) unsetUnderline(); @@ -653,7 +653,7 @@ void FLabel::printLine ( wchar_t line[] setColor(); } else - print ( line[z] ); + print (line[z]); } if ( length > width ) diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 7a9364e2..bbe87892 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -308,7 +308,7 @@ void FLineEdit::hide() try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -316,12 +316,12 @@ void FLineEdit::hide() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < int(getHeight() + s); y++) + for (std::size_t y = 0; y < getHeight() + s; y++) { - setPrintPos (1, 1 + y); + setPrintPos (1, 1 + int(y)); print (blank); } @@ -436,8 +436,8 @@ void FLineEdit::onMouseDown (FMouseEvent* ev) if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 ) { - int len = int(text.getLength()); - cursor_pos = int(text_offset) + mouse_x - 2; + std::size_t len = text.getLength(); + cursor_pos = text_offset + std::size_t(mouse_x) - 2; if ( cursor_pos >= len ) cursor_pos = len; @@ -461,18 +461,19 @@ void FLineEdit::onMouseUp (FMouseEvent*) //---------------------------------------------------------------------- void FLineEdit::onMouseMove (FMouseEvent* ev) { - int len, mouse_x, mouse_y; + std::size_t len; + int mouse_x, mouse_y; if ( ev->getButton() != fc::LeftButton ) return; - len = int(text.getLength()); + len = text.getLength(); mouse_x = ev->getX(); mouse_y = ev->getY(); if ( mouse_x >= 2 && mouse_x <= int(getWidth()) && mouse_y == 1 ) { - cursor_pos = int(text_offset) + mouse_x - 2; + cursor_pos = text_offset + std::size_t(mouse_x) - 2; if ( cursor_pos >= len ) cursor_pos = len; @@ -501,14 +502,14 @@ void FLineEdit::onMouseMove (FMouseEvent* ev) else if ( mouse_x >= int(getWidth()) ) { // drag right - if ( ! scroll_timer && int(text_offset) <= len - int(getWidth()) + 1 ) + if ( ! scroll_timer && text_offset <= len - getWidth() + 1 ) { scroll_timer = true; addTimer(scroll_repeat); drag_scroll = FLineEdit::scrollRight; } - if ( int(text_offset) == len - int(getWidth()) + 2 ) + if ( text_offset == len - getWidth() + 2 ) { delOwnTimer(); drag_scroll = FLineEdit::noScroll; @@ -526,7 +527,7 @@ void FLineEdit::onMouseMove (FMouseEvent* ev) //---------------------------------------------------------------------- void FLineEdit::onTimer (FTimerEvent*) { - int len = int(text.getLength()); + std::size_t len = text.getLength(); switch ( int(drag_scroll) ) { @@ -549,13 +550,13 @@ void FLineEdit::onTimer (FTimerEvent*) break; case FLineEdit::scrollRight: - if ( int(text_offset) == len - int(getWidth()) + 2 ) + if ( text_offset == len - getWidth() + 2 ) { drag_scroll = FLineEdit::noScroll; return; } - if ( int(text_offset) <= len - int(getWidth()) + 1 ) + if ( text_offset <= len - getWidth() + 1 ) text_offset++; if ( cursor_pos < len ) @@ -731,7 +732,7 @@ void FLineEdit::draw() void FLineEdit::drawInputField() { bool isActiveFocus, isShadow; - int x; + std::size_t x; FString show_text; int active_focus = fc::active + fc::focus; isActiveFocus = ((flags & active_focus) == active_focus); @@ -757,8 +758,7 @@ void FLineEdit::drawInputField() if ( isActiveFocus && getMaxColor() < 16 ) setBold(); - show_text = text.mid( std::size_t(1 + text_offset) - , std::size_t(getWidth() - 2) ); + show_text = text.mid(1 + text_offset, getWidth() - 2); if ( isLinuxTerm() && hasUTF8() ) { @@ -772,9 +772,9 @@ void FLineEdit::drawInputField() else if ( show_text ) print (show_text); - x = int(show_text.getLength()); + x = show_text.getLength(); - while ( x < int(getWidth()) - 1 ) + while ( x < getWidth() - 1 ) { print (' '); x++; @@ -793,7 +793,7 @@ void FLineEdit::drawInputField() drawShadow (); // set the cursor to the first pos. - setCursorPos (2 + cursor_pos - int(text_offset), 1); + setCursorPos (int(2 + cursor_pos - text_offset), 1); } //---------------------------------------------------------------------- @@ -802,20 +802,20 @@ inline void FLineEdit::keyLeft() if ( cursor_pos > 0 ) cursor_pos--; - if ( cursor_pos < int(text_offset) ) + if ( cursor_pos < text_offset ) text_offset--; } //---------------------------------------------------------------------- inline void FLineEdit::keyRight() { - int len = int(text.getLength()); + std::size_t len = text.getLength(); if ( cursor_pos < len ) cursor_pos++; - if ( cursor_pos - int(text_offset) >= int(getWidth()) - 2 - && int(text_offset) <= len - int(getWidth()) + 1 ) + if ( cursor_pos - text_offset >= getWidth() - 2 + && text_offset <= len - getWidth() + 1 ) text_offset++; } @@ -830,9 +830,9 @@ inline void FLineEdit::keyHome() inline void FLineEdit::keyEnd() { std::size_t len = text.getLength(); - cursor_pos = int(len); + cursor_pos = len; - if ( cursor_pos >= int(getWidth()) - 1 ) + if ( cursor_pos >= getWidth() - 1 ) text_offset = len - getWidth() + 2; } @@ -841,20 +841,16 @@ inline void FLineEdit::keyDel() { std::size_t len = text.getLength(); - if ( len > 0 && std::size_t(cursor_pos) < len ) + if ( len > 0 && cursor_pos < len ) { - text.remove(std::size_t(cursor_pos), 1); + text.remove(cursor_pos, 1); processChanged(); } - if ( cursor_pos >= int(len) ) - cursor_pos = int(len); + if ( cursor_pos >= len ) + cursor_pos = len; - if ( cursor_pos < 0 ) - cursor_pos = 0; - - if ( text_offset > 0 - && len - std::size_t(text_offset) < std::size_t(getWidth()) - 1 ) + if ( text_offset > 0 && len - text_offset < getWidth() - 1 ) text_offset--; } @@ -863,7 +859,7 @@ inline void FLineEdit::keyBackspace() { if ( text.getLength() > 0 && cursor_pos > 0 ) { - text.remove(std::size_t(cursor_pos) - 1, 1); + text.remove(cursor_pos - 1, 1); processChanged(); cursor_pos--; @@ -896,7 +892,7 @@ inline bool FLineEdit::keyInput (int key) { std::size_t len = text.getLength(); - if ( std::size_t(cursor_pos) == len ) + if ( cursor_pos == len ) { text += wchar_t(key); processChanged(); @@ -904,9 +900,9 @@ inline bool FLineEdit::keyInput (int key) else if ( len > 0 ) { if ( insert_mode ) - text.insert(wchar_t(key), std::size_t(cursor_pos)); + text.insert(wchar_t(key), cursor_pos); else - text.overwrite(wchar_t(key), std::size_t(cursor_pos)); + text.overwrite(wchar_t(key), cursor_pos); processChanged(); } @@ -915,9 +911,10 @@ inline bool FLineEdit::keyInput (int key) text = wchar_t(key); processChanged(); } + cursor_pos++; - if ( cursor_pos >= int(getWidth()) - 1 ) + if ( cursor_pos >= getWidth() - 1 ) text_offset++; return true; diff --git a/src/flistview.cpp b/src/flistview.cpp index 1b97cc62..bbbcbab9 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -395,7 +395,7 @@ void FListViewItem::replaceControlCodes() } //---------------------------------------------------------------------- -int FListViewItem::getVisibleLines() +std::size_t FListViewItem::getVisibleLines() { if ( visible_lines > 1 ) return visible_lines; @@ -1670,7 +1670,7 @@ void FListView::drawListLine ( const FListViewItem* item // Insert text and trailing space line += text.left(width); line += FString ( leading_space + width - - align_offset + txt_length, L' '); + - align_offset - txt_length, L' '); } else if ( align == fc::alignRight ) { diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 1cef1720..38c35bd7 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -305,7 +305,7 @@ void FMessageBox::adjustSize() //---------------------------------------------------------------------- void FMessageBox::cb_processClick (FWidget*, data_ptr data) { - int* reply = static_cast(data); + FDialog::DialogCode* reply = static_cast(data); done (*reply); } diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 90172312..1cc6e658 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -148,7 +148,7 @@ void FScrollView::setScrollSize (std::size_t width, std::size_t height) setTopPadding (1 - getScrollY()); setLeftPadding (1 - getScrollX()); setBottomPadding (1 - (yoffset_end - getScrollY())); - setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset); + setRightPadding (1 - (xoffset_end - getScrollX()) + int(nf_offset)); hbar->setMaximum (int(width - getViewportWidth())); hbar->setPageSize (int(width), int(getViewportWidth())); @@ -216,7 +216,7 @@ void FScrollView::setPos (int x, int y, bool adjust) void FScrollView::setWidth (std::size_t w, bool adjust) { FWidget::setWidth (w, adjust); - viewport_geometry.setWidth(w - vertical_border_spacing - std::size_t(nf_offset)); + viewport_geometry.setWidth(w - vertical_border_spacing - nf_offset); calculateScrollbarPos(); if ( getScrollWidth() < getViewportWidth() ) @@ -238,7 +238,7 @@ void FScrollView::setHeight (std::size_t h, bool adjust) void FScrollView::setSize (std::size_t w, std::size_t h, bool adjust) { FWidget::setSize (w, h, adjust); - viewport_geometry.setSize ( w - vertical_border_spacing - std::size_t(nf_offset) + viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset , h - horizontal_border_spacing ); calculateScrollbarPos(); @@ -248,14 +248,16 @@ void FScrollView::setSize (std::size_t w, std::size_t h, bool adjust) } //---------------------------------------------------------------------- -void FScrollView::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust) +void FScrollView::setGeometry ( int x, int y + , std::size_t w, std::size_t h + , bool adjust ) { // Set the scroll view geometry FWidget::setGeometry (x, y, w, h, adjust); scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1 , getTermY() + getTopPadding() - 1 ); - viewport_geometry.setSize ( w - vertical_border_spacing - std::size_t(nf_offset) + viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset , h - horizontal_border_spacing ); calculateScrollbarPos(); @@ -372,7 +374,7 @@ void FScrollView::scrollTo (int x, int y) { viewport_geometry.setWidth(save_width); setLeftPadding (1 - xoffset); - setRightPadding (1 - (xoffset_end - xoffset) + nf_offset); + setRightPadding (1 - (xoffset_end - xoffset) + short(nf_offset)); if ( update_scrollbar ) { diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 792d573a..bf68cd2d 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -45,7 +45,7 @@ FSwitch::FSwitch (const FString& txt, FWidget* parent) , switch_offset_pos(0) , button_pressed(false) { - switch_offset_pos = int(txt.getLength()) + 1; + switch_offset_pos = txt.getLength() + 1; button_width = 11; } @@ -59,7 +59,7 @@ FSwitch::~FSwitch() // destructor void FSwitch::setText (const FString& txt) { FToggleButton::setText(txt); - switch_offset_pos = int(txt.getLength()) + 1; + switch_offset_pos = txt.getLength() + 1; } //---------------------------------------------------------------------- @@ -131,7 +131,7 @@ void FSwitch::drawCheckButton() if ( ! isVisible() ) return; - setPrintPos (1 + switch_offset_pos, 1); + setPrintPos (1 + int(switch_offset_pos), 1); if ( checked ) drawChecked(); @@ -185,7 +185,7 @@ void FSwitch::drawChecked() if ( isMonochron() ) setReverse(false); - setCursorPos (3 + switch_offset_pos, 1); + setCursorPos (3 + int(switch_offset_pos), 1); } //---------------------------------------------------------------------- @@ -232,7 +232,7 @@ void FSwitch::drawUnchecked() if ( isMonochron() || getMaxColor() < 16 ) setBold(false); - setCursorPos (7 + switch_offset_pos, 1); + setCursorPos (7 + int(switch_offset_pos), 1); } } // namespace finalcut diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 59d0643b..f3a26082 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -500,7 +500,7 @@ void FToggleButton::draw() void FToggleButton::drawLabel() { wchar_t* LabelText; - int hotkeypos; + std::size_t hotkeypos; if ( ! isVisible() ) return; @@ -525,7 +525,7 @@ void FToggleButton::drawLabel() wchar_t* dest = const_cast(LabelText); hotkeypos = getHotkeyPos(src, dest, length); - if ( hotkeypos != -1 ) + if ( hotkeypos != NOT_FOUND ) length--; setPrintPos (1 + int(label_offset_pos), 1); @@ -636,20 +636,20 @@ void FToggleButton::init() } //---------------------------------------------------------------------- -int FToggleButton::getHotkeyPos ( wchar_t src[] +std::size_t FToggleButton::getHotkeyPos ( wchar_t src[] , wchar_t dest[] , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign - int pos = -1; + std::size_t pos = NOT_FOUND; wchar_t* txt = src; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && pos == -1 ) + if ( i < length && txt[i] == L'&' && pos == NOT_FOUND ) { - pos = int(i); + pos = i; i++; src++; } @@ -662,7 +662,7 @@ int FToggleButton::getHotkeyPos ( wchar_t src[] //---------------------------------------------------------------------- void FToggleButton::drawText ( wchar_t LabelText[] - , int hotkeypos + , std::size_t hotkeypos , std::size_t length ) { bool isActive = ((flags & fc::active) != 0); @@ -676,7 +676,7 @@ void FToggleButton::drawText ( wchar_t LabelText[] else setColor (wc.label_inactive_fg, wc.label_inactive_bg); - for (int z = 0; z < int(length); z++) + for (std::size_t z = 0; z < length; z++) { if ( (z == hotkeypos) && isActive ) { diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index 22e05fc7..debf88f5 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -130,6 +130,9 @@ class FButton : public FWidget virtual void onFocusOut (FFocusEvent*); private: + // Constants + static const std::size_t NOT_FOUND = static_cast(-1); + // Disable copy constructor FButton (const FButton&); @@ -142,8 +145,8 @@ class FButton : public FWidget uChar getHotkey(); void setHotkeyAccelerator(); void detectHotkey(); - int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); - int clickAnimationIndent (FWidget*); + std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + std::size_t clickAnimationIndent (FWidget*); void clearRightMargin (FWidget*); void drawMarginLeft(); void drawMarginRight(); @@ -159,12 +162,12 @@ class FButton : public FWidget bool button_down; bool click_animation; int click_time; - int indent; - int space; - int center_offset; - int vcenter_offset; - int txtlength; - int hotkeypos; + int space_char; + std::size_t hotkeypos; + std::size_t indent; + std::size_t center_offset; + std::size_t vcenter_offset; + std::size_t txtlength; short button_fg; short button_bg; short button_hotkey_fg; diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index dba9fd87..42dea674 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -125,6 +125,9 @@ class FButtonGroup : public FScrollView void drawLabel(); private: + // Constants + static const std::size_t NOT_FOUND = static_cast(-1); + // Disable copy constructor FButtonGroup (const FButtonGroup&); @@ -136,8 +139,8 @@ class FButtonGroup : public FScrollView // Methods void init(); - int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); - void drawText (wchar_t[], int, std::size_t); + std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + void drawText (wchar_t[], std::size_t, std::size_t); void directFocus(); // Data Members diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index d2196207..a129c9f5 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -117,7 +117,7 @@ class FDialog : public FWindow // Methods virtual void show(); virtual void hide(); - int exec(); + DialogCode exec(); virtual void setPos (int, int, bool = true); virtual void move (int, int); bool moveUp (int); @@ -145,7 +145,7 @@ class FDialog : public FWindow protected: // Methods - virtual void done (int); + virtual void done (DialogCode); virtual void draw(); void drawDialogShadow(); @@ -223,7 +223,7 @@ class FDialog : public FWindow // Data Members FString tb_text; // title bar text - int result_code; + DialogCode result_code; bool zoom_button_pressed; bool zoom_button_active; bool setPos_error; diff --git a/src/include/final/flabel.h b/src/include/final/flabel.h index 37c986ca..8f388983 100644 --- a/src/include/final/flabel.h +++ b/src/include/final/flabel.h @@ -131,6 +131,9 @@ class FLabel : public FWidget void cb_accel_widget_destroyed (FWidget*, data_ptr); private: + // Constants + static const std::size_t NOT_FOUND = static_cast(-1); + // Disable copy constructor FLabel (const FLabel&); @@ -140,13 +143,14 @@ class FLabel : public FWidget // Methods void init(); uChar getHotkey(); - int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t); void setHotkeyAccelerator(); std::size_t getAlignOffset (std::size_t); virtual void draw(); void drawMultiLine(); void drawSingleLine(); - void printLine (wchar_t[], std::size_t, int, std::size_t = 0); + void printLine ( wchar_t[], std::size_t + , std::size_t, std::size_t = 0 ); // Data Members FStringList multiline_text; diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 59385258..e5cdb51e 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -178,7 +178,7 @@ class FLineEdit : public FWidget bool scroll_timer; int scroll_repeat; bool insert_mode; - int cursor_pos; + std::size_t cursor_pos; std::size_t text_offset; }; #pragma pack(pop) diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 4a466e0a..6453705d 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -119,14 +119,14 @@ class FListViewItem : public FObject void sort (Compare); FObjectIterator appendItem (FListViewItem*); void replaceControlCodes(); - int getVisibleLines(); + std::size_t getVisibleLines(); void resetVisibleLineCounter(); // Data Members FStringList column_list; FWidget::data_ptr data_pointer; FObjectIterator root; - int visible_lines; + std::size_t visible_lines; bool expandable; bool is_expand; diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index e8e150c3..a5cc497e 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -82,7 +82,7 @@ class FMessageBox : public FDialog { public: // Enumeration - enum + enum ButtonType { Reject = 0, Ok = 1, diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index 64514c7d..b9dd1ef5 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -179,7 +179,7 @@ class FScrollView : public FWidget term_area* viewport; // virtual scroll content FScrollbar* vbar; FScrollbar* hbar; - int nf_offset; + uInt8 nf_offset; bool border; bool use_own_print_area; bool update_scrollbar; diff --git a/src/include/final/fswitch.h b/src/include/final/fswitch.h index f8ecbc7c..4ea2e264 100644 --- a/src/include/final/fswitch.h +++ b/src/include/final/fswitch.h @@ -104,7 +104,7 @@ class FSwitch : public FToggleButton void drawUnchecked(); // Data Members - int switch_offset_pos; + std::size_t switch_offset_pos; bool button_pressed; }; #pragma pack(pop) diff --git a/src/include/final/ftermbuffer.h b/src/include/final/ftermbuffer.h index 8d63fd73..f6952246 100644 --- a/src/include/final/ftermbuffer.h +++ b/src/include/final/ftermbuffer.h @@ -72,7 +72,7 @@ class FTermBuffer // Accessors virtual const char* getClassName() const; - int getLength() const; + std::size_t getLength() const; // Inquiry bool isEmpty() const; @@ -107,8 +107,8 @@ inline const char* FTermBuffer::getClassName() const { return "FTermBuffer"; } //---------------------------------------------------------------------- -inline int FTermBuffer::getLength() const -{ return int(data.size()); } +inline std::size_t FTermBuffer::getLength() const +{ return data.size(); } //---------------------------------------------------------------------- inline bool FTermBuffer::isEmpty() const diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 3f382c98..dc242a32 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -143,6 +143,9 @@ class FToggleButton : public FWidget std::size_t button_width; // plus margin spaces private: + // Constants + static const std::size_t NOT_FOUND = static_cast(-1); + // Disable copy constructor FToggleButton (const FToggleButton&); @@ -154,8 +157,8 @@ class FToggleButton : public FWidget // Methods void init(); - int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); - void drawText (wchar_t[], int, std::size_t); + std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + void drawText (wchar_t[], std::size_t , std::size_t); // Friend classes friend class FButtonGroup; From 258380ae576bb0c340b6fa25a58ab2e4f9256271 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 18 Oct 2018 23:50:06 +0200 Subject: [PATCH 14/17] Changed more variables from int to std::size_t --- examples/ui.cpp | 4 +-- src/fbutton.cpp | 14 ++++----- src/fbuttongroup.cpp | 6 ++-- src/flabel.cpp | 16 +++++------ src/fmenu.cpp | 28 +++++++++--------- src/fmenubar.cpp | 48 +++++++++++++++---------------- src/fprogressbar.cpp | 36 ++++++++++++----------- src/ftextview.cpp | 20 +++++-------- src/ftogglebutton.cpp | 6 ++-- src/include/final/fbutton.h | 2 +- src/include/final/fbuttongroup.h | 2 +- src/include/final/flabel.h | 2 +- src/include/final/fmenu.h | 9 ++++-- src/include/final/fmenubar.h | 15 ++++++---- src/include/final/fprogressbar.h | 11 ++++--- src/include/final/ftogglebutton.h | 2 +- 16 files changed, 114 insertions(+), 107 deletions(-) diff --git a/examples/ui.cpp b/examples/ui.cpp index f0b01a2e..1e527fc9 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -132,7 +132,7 @@ void ProgressDialog::onShow (finalcut::FShowEvent*) //---------------------------------------------------------------------- void ProgressDialog::onTimer (finalcut::FTimerEvent*) { - int p = progressBar.getPercentage(); + std::size_t p = progressBar.getPercentage(); progressBar.setPercentage(++p); flush_out(); @@ -164,7 +164,7 @@ void ProgressDialog::cb_reset_bar (finalcut::FWidget*, data_ptr) //---------------------------------------------------------------------- void ProgressDialog::cb_more_bar (finalcut::FWidget*, data_ptr) { - int p = progressBar.getPercentage(); + std::size_t p = progressBar.getPercentage(); progressBar.setPercentage(++p); } diff --git a/src/fbutton.cpp b/src/fbutton.cpp index b3962d21..70b67040 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -40,7 +40,7 @@ FButton::FButton(FWidget* parent) , click_animation(true) , click_time(150) , space_char(int(' ')) - , hotkeypos(NOT_FOUND) + , hotkeypos(NOT_SET) , indent(0) , center_offset(0) , vcenter_offset(0) @@ -65,7 +65,7 @@ FButton::FButton (const FString& txt, FWidget* parent) , click_animation(true) , click_time(150) , space_char(int(' ')) - , hotkeypos(NOT_FOUND) + , hotkeypos(NOT_SET) , indent(0) , center_offset(0) , vcenter_offset(0) @@ -549,11 +549,11 @@ std::size_t FButton::getHotkeyPos ( wchar_t src[] // find hotkey position in string // + generate a new string without the '&'-sign wchar_t* txt = src; - std::size_t pos = NOT_FOUND; + std::size_t pos = NOT_SET; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && pos == NOT_FOUND ) + if ( i < length && txt[i] == L'&' && pos == NOT_SET ) { pos = i; i++; @@ -686,11 +686,11 @@ inline void FButton::drawButtonTextLine (wchar_t button_text[]) for (pos = 0; pos < center_offset; pos++) print (space_char); // █ - if ( hotkeypos == NOT_FOUND ) + if ( hotkeypos == NOT_SET ) setCursorPos ( 2 + int(center_offset) , 1 + int(vcenter_offset) ); // first character else - setCursorPos ( 2 + int(center_offset) + hotkeypos + setCursorPos ( 2 + int(center_offset + hotkeypos) , 1 + int(vcenter_offset) ); // hotkey if ( ! is.active && isMonochron() ) @@ -782,7 +782,7 @@ void FButton::draw() hotkeypos = getHotkeyPos(text.wc_str(), button_text, uInt(txtlength)); - if ( hotkeypos != NOT_FOUND ) + if ( hotkeypos != NOT_SET ) txtlength--; if ( getHeight() >= 2 ) diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 34affdc3..67f6dd6a 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -527,7 +527,7 @@ void FButtonGroup::drawLabel() unsetViewportPrint(); hotkeypos = getHotkeyPos(src, dest, length); - if ( hotkeypos != NOT_FOUND ) + if ( hotkeypos != NOT_SET ) length--; if ( hasBorder() ) @@ -571,12 +571,12 @@ std::size_t FButtonGroup::getHotkeyPos ( wchar_t src[] { // find hotkey position in string // + generate a new string without the '&'-sign - std::size_t pos = NOT_FOUND; + std::size_t pos = NOT_SET; wchar_t* txt = src; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && pos == NOT_FOUND ) + if ( i < length && txt[i] == L'&' && pos == NOT_SET ) { pos = i; i++; diff --git a/src/flabel.cpp b/src/flabel.cpp index 74782d61..98ae734c 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -425,12 +425,12 @@ std::size_t FLabel::getHotkeyPos ( wchar_t src[] { // find hotkey position in string // + generate a new string without the '&'-sign - std::size_t hotkeypos = NOT_FOUND; + std::size_t hotkeypos = NOT_SET; wchar_t* txt = src; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && hotkeypos == NOT_FOUND ) + if ( i < length && txt[i] == L'&' && hotkeypos == NOT_SET ) { hotkeypos = i; i++; @@ -446,7 +446,7 @@ std::size_t FLabel::getHotkeyPos ( wchar_t src[] //---------------------------------------------------------------------- void FLabel::setHotkeyAccelerator() { - std::size_t hotkey = getHotkey(); + uChar hotkey = getHotkey(); if ( hotkey ) { @@ -531,7 +531,7 @@ void FLabel::drawMultiLine() while ( y < text_lines && y < std::size_t(getHeight()) ) { wchar_t* label_text; - std::size_t hotkeypos = NOT_FOUND; + std::size_t hotkeypos = NOT_SET; std::size_t align_offset; std::size_t length = multiline_text[y].getLength(); @@ -555,7 +555,7 @@ void FLabel::drawMultiLine() setPrintPos (1, 1 + int(y)); - if ( hotkeypos != NOT_FOUND ) + if ( hotkeypos != NOT_SET ) { align_offset = getAlignOffset(length - 1); printLine (label_text, length - 1, hotkeypos, align_offset); @@ -564,7 +564,7 @@ void FLabel::drawMultiLine() else { align_offset = getAlignOffset(length); - printLine (label_text, length, NOT_FOUND, align_offset); + printLine (label_text, length, NOT_SET, align_offset); } y++; @@ -576,7 +576,7 @@ void FLabel::drawMultiLine() void FLabel::drawSingleLine() { wchar_t* label_text; - std::size_t hotkeypos = NOT_FOUND; + std::size_t hotkeypos = NOT_SET; std::size_t align_offset; std::size_t length = text.getLength(); @@ -592,7 +592,7 @@ void FLabel::drawSingleLine() hotkeypos = getHotkeyPos (text.wc_str(), label_text, length); - if ( hotkeypos != NOT_FOUND ) + if ( hotkeypos != NOT_SET ) length--; setPrintPos (1, 1); diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 7d6f51cc..07c1b64d 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -43,7 +43,7 @@ FMenu::FMenu(FWidget* parent) , opened_sub_menu(0) , shown_sub_menu(0) , max_item_width(0) - , hotkeypos(-1) + , hotkeypos(NOT_SET) , mouse_down(false) , has_checkable_items(false) { @@ -58,7 +58,7 @@ FMenu::FMenu (const FString& txt, FWidget* parent) , opened_sub_menu(0) , shown_sub_menu(0) , max_item_width(0) - , hotkeypos(-1) + , hotkeypos(NOT_SET) , mouse_down(false) , has_checkable_items(false) { @@ -1222,20 +1222,20 @@ bool FMenu::hotkeyMenu (FKeyEvent* ev) } //---------------------------------------------------------------------- -int FMenu::getHotkeyPos ( wchar_t src[] - , wchar_t dest[] - , std::size_t length ) +std::size_t FMenu::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // Find hotkey position in string // + generate a new string without the '&'-sign - int pos = -1; + std::size_t pos = NOT_SET; wchar_t* txt = src; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && pos == -1 ) + if ( i < length && txt[i] == L'&' && pos == NOT_SET ) { - pos = int(i); + pos = i; i++; src++; } @@ -1346,7 +1346,7 @@ inline void FMenu::drawMenuLine (FMenuItem* menuitem, int y) hotkeypos = getHotkeyPos(txt.wc_str(), txtdata.text, txt_length); - if ( hotkeypos != -1 ) + if ( hotkeypos != NOT_SET ) to_char--; txtdata.length = to_char; @@ -1354,7 +1354,7 @@ inline void FMenu::drawMenuLine (FMenuItem* menuitem, int y) setCursorToHotkeyPosition (menuitem); if ( ! is_enabled || is_selected ) - txtdata.hotkeypos = -1; + txtdata.hotkeypos = NOT_SET; else txtdata.hotkeypos = hotkeypos; @@ -1438,7 +1438,7 @@ inline void FMenu::drawMenuText (menuText& data) } } - if ( int(z) == data.hotkeypos ) + if ( z == data.hotkeypos ) { setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); @@ -1544,7 +1544,7 @@ inline void FMenu::setCursorToHotkeyPosition (FMenuItem* menuitem) bool is_checkable = menuitem->checkable; bool is_selected = menuitem->isSelected(); - if ( hotkeypos == -1 ) + if ( hotkeypos == NOT_SET ) { // set cursor to the first character if ( is_selected ) @@ -1561,9 +1561,9 @@ inline void FMenu::setCursorToHotkeyPosition (FMenuItem* menuitem) { // set cursor to the hotkey position if ( is_checkable ) - menuitem->setCursorPos (3 + hotkeypos, 1); + menuitem->setCursorPos (3 + int(hotkeypos), 1); else - menuitem->setCursorPos (2 + hotkeypos, 1); + menuitem->setCursorPos (2 + int(hotkeypos), 1); } } } diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 9af70023..dfaf07b9 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -494,20 +494,20 @@ bool FMenuBar::hotkeyMenu (FKeyEvent*& ev) } //---------------------------------------------------------------------- -int FMenuBar::getHotkeyPos ( wchar_t src[] - , wchar_t dest[] - , std::size_t length ) +std::size_t FMenuBar::getHotkeyPos ( wchar_t src[] + , wchar_t dest[] + , std::size_t length ) { // find hotkey position in string // + generate a new string without the '&'-sign - int hotkeypos = -1; + std::size_t hotkeypos = NOT_SET; wchar_t* txt = src; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && hotkeypos == -1 ) + if ( i < length && txt[i] == L'&' && hotkeypos == NOT_SET ) { - hotkeypos = int(i); + hotkeypos = i; i++; src++; } @@ -528,7 +528,7 @@ void FMenuBar::draw() void FMenuBar::drawItems() { std::vector::const_iterator iter, last; - int x = 1; + std::size_t x = 1; if ( item_list.empty() ) return; @@ -549,7 +549,7 @@ void FMenuBar::drawItems() } // Print spaces to end of line - for (; x <= int(screenWidth); x++) + for (; x <= screenWidth; x++) print (' '); if ( isMonochron() ) @@ -557,17 +557,17 @@ void FMenuBar::drawItems() } //---------------------------------------------------------------------- -inline void FMenuBar::drawItem (FMenuItem* menuitem, int& x) +inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x) { FString txt = menuitem->getText(); menuText txtdata; std::size_t txt_length = txt.getLength(); std::size_t to_char; - int hotkeypos; + std::size_t hotkeypos; bool is_enabled = menuitem->isEnabled(); bool is_selected = menuitem->isSelected(); - txtdata.startpos = std::size_t(x) + 1; + txtdata.startpos = x + 1; txtdata.no_underline = ((menuitem->getFlags() & fc::no_underline) != 0); // Set screen attributes @@ -584,24 +584,24 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, int& x) return; } - if ( x - 1 <= int(screenWidth) ) + if ( x - 1 <= screenWidth ) to_char = txt_length; else - to_char = txt_length - screenWidth - std::size_t(x) - 1; + to_char = txt_length - screenWidth - x - 1; hotkeypos = getHotkeyPos (txt.wc_str(), txtdata.text, txt_length); - if ( hotkeypos != -1 ) + if ( hotkeypos != NOT_SET ) { txt_length--; to_char--; } txtdata.length = to_char; - x += int(txt_length); + x += txt_length; if ( ! is_enabled || is_selected ) - txtdata.hotkeypos = -1; + txtdata.hotkeypos = NOT_SET; else txtdata.hotkeypos = hotkeypos; @@ -655,7 +655,7 @@ inline void FMenuBar::drawMenuText (menuText& data) for (std::size_t z = 0; z < data.length; z++) { - if ( data.startpos > std::size_t(screenWidth) - z ) + if ( data.startpos > screenWidth - z ) break; if ( ! std::iswprint(wint_t(data.text[z])) ) @@ -668,7 +668,7 @@ inline void FMenuBar::drawMenuText (menuText& data) } } - if ( int(z) == data.hotkeypos ) + if ( z == data.hotkeypos ) { setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); @@ -688,9 +688,9 @@ inline void FMenuBar::drawMenuText (menuText& data) } //---------------------------------------------------------------------- -inline void FMenuBar::drawEllipsis (menuText& txtdata, int x) +inline void FMenuBar::drawEllipsis (menuText& txtdata, std::size_t x) { - if ( x > int(screenWidth) + 1 ) + if ( x > screenWidth + 1 ) { if ( txtdata.startpos < screenWidth ) { @@ -708,11 +708,11 @@ inline void FMenuBar::drawEllipsis (menuText& txtdata, int x) } //---------------------------------------------------------------------- -inline void FMenuBar::drawLeadingSpace (int& x) +inline void FMenuBar::drawLeadingSpace (std::size_t& x) { // Print a leading blank space - if ( x < int(screenWidth) ) + if ( x < screenWidth ) { x++; print (' '); @@ -720,11 +720,11 @@ inline void FMenuBar::drawLeadingSpace (int& x) } //---------------------------------------------------------------------- -inline void FMenuBar::drawTrailingSpace (int& x) +inline void FMenuBar::drawTrailingSpace (std::size_t& x) { // Print a trailing blank space - if ( x < int(screenWidth) ) + if ( x < screenWidth ) { x++; print (' '); diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 622b85d8..54e70396 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -33,7 +33,7 @@ namespace finalcut //---------------------------------------------------------------------- FProgressbar::FProgressbar(FWidget* parent) : FWidget(parent) - , percentage(-1) + , percentage(NOT_SET) , bar_length(getWidth()) { unsetFocusable(); @@ -47,15 +47,14 @@ FProgressbar::~FProgressbar() // destructor // public methods of FProgressbar //---------------------------------------------------------------------- -void FProgressbar::setPercentage (int percentage_value) +void FProgressbar::setPercentage (std::size_t percentage_value) { - if ( percentage_value <= percentage ) - return; - - if ( percentage_value > 100 ) + if ( percentage_value == NOT_SET ) + percentage = NOT_SET; + else if ( percentage_value > 100 ) percentage = 100; - else if ( percentage_value < 0 ) - percentage = 0; + else if ( percentage_value <= percentage && percentage != NOT_SET ) + return; else percentage = percentage_value; @@ -126,7 +125,7 @@ void FProgressbar::hide() try { - blank = new char[std::size_t(size) + 1]; + blank = new char[size + 1]; } catch (const std::bad_alloc& ex) { @@ -134,12 +133,12 @@ void FProgressbar::hide() return; } - std::memset(blank, ' ', std::size_t(size)); + std::memset(blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < int(getHeight() + s); y++) + for (std::size_t y = 0; y < getHeight() + s; y++) { - setPrintPos (1, 1 + y); + setPrintPos (1, 1 + int(y)); print (blank); } @@ -151,7 +150,7 @@ void FProgressbar::hide() //---------------------------------------------------------------------- void FProgressbar::reset() { - percentage = -1; + percentage = NOT_SET; if ( isVisible() ) { @@ -192,7 +191,7 @@ void FProgressbar::drawPercentage() setPrintPos (int(getWidth()) - 3, 0); - if ( percentage < 0 || percentage > 100 ) + if ( percentage > 100 ) print ("--- %"); else printf ("%3d %%", percentage); @@ -205,11 +204,16 @@ void FProgressbar::drawPercentage() void FProgressbar::drawBar() { std::size_t i = 0; - double length = double(int(bar_length) * percentage) / 100; + double length; setPrintPos (1,1); setColor ( wc.progressbar_bg , wc.progressbar_fg ); + if ( percentage == NOT_SET ) + length = double(-0/100); + else + length = double(bar_length * percentage) / 100; + if ( isMonochron() ) setReverse(false); @@ -219,7 +223,7 @@ void FProgressbar::drawBar() if ( isMonochron() ) setReverse(true); - if ( percentage > 0.0f && trunc(length) < bar_length ) + if ( percentage > 0 && percentage <= 100 && trunc(length) < bar_length ) { if ( round(length) > trunc(length) || getMaxColor() < 16 ) { diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 60536366..d7fe4640 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -231,9 +231,9 @@ void FTextView::hide() std::memset(blank, ' ', size); blank[size] = '\0'; - for (int y = 0; y < int(getHeight()); y++) + for (std::size_t y = 0; y < getHeight(); y++) { - setPrintPos (1, 1 + y); + setPrintPos (1, 1 + int(y)); print (blank); } @@ -253,9 +253,9 @@ void FTextView::insert (const FString& str, int pos) FStringList::iterator iter; FStringList text_split; FString s; - uLong num; + std::size_t num; - if ( pos < 0 || pos >= int(getRows()) ) + if ( pos >= int(getRows()) ) pos = int(getRows()); if ( str.isEmpty() ) @@ -297,10 +297,10 @@ void FTextView::insert (const FString& str, int pos) vbar->setPageSize (int(getRows()), int(getTextHeight())); vbar->calculateSliderValues(); - if ( ! vbar->isVisible() && int(getRows()) > int(getTextHeight()) ) + if ( ! vbar->isVisible() && getRows() > getTextHeight() ) vbar->setVisible(); - if ( vbar->isVisible() && int(getRows()) <= int(getTextHeight()) ) + if ( vbar->isVisible() && getRows() <= getTextHeight() ) vbar->hide(); processChanged(); @@ -311,13 +311,7 @@ void FTextView::replaceRange (const FString& str, int from, int to) { FStringList::iterator iter; - if ( from > to ) - return; - - if ( from < 0 || from >= int(getRows()) ) - return; - - if ( to < 0 || to >= int(getRows()) ) + if ( from > to || from >= int(getRows()) || to >= int(getRows()) ) return; iter = data.begin(); diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index f3a26082..15f8ba8e 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -525,7 +525,7 @@ void FToggleButton::drawLabel() wchar_t* dest = const_cast(LabelText); hotkeypos = getHotkeyPos(src, dest, length); - if ( hotkeypos != NOT_FOUND ) + if ( hotkeypos != NOT_SET ) length--; setPrintPos (1 + int(label_offset_pos), 1); @@ -642,12 +642,12 @@ std::size_t FToggleButton::getHotkeyPos ( wchar_t src[] { // find hotkey position in string // + generate a new string without the '&'-sign - std::size_t pos = NOT_FOUND; + std::size_t pos = NOT_SET; wchar_t* txt = src; for (std::size_t i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && pos == NOT_FOUND ) + if ( i < length && txt[i] == L'&' && pos == NOT_SET ) { pos = i; i++; diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index debf88f5..ca19690c 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -131,7 +131,7 @@ class FButton : public FWidget private: // Constants - static const std::size_t NOT_FOUND = static_cast(-1); + static const std::size_t NOT_SET = static_cast(-1); // Disable copy constructor FButton (const FButton&); diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index 42dea674..09017270 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -126,7 +126,7 @@ class FButtonGroup : public FScrollView private: // Constants - static const std::size_t NOT_FOUND = static_cast(-1); + static const std::size_t NOT_SET = static_cast(-1); // Disable copy constructor FButtonGroup (const FButtonGroup&); diff --git a/src/include/final/flabel.h b/src/include/final/flabel.h index 8f388983..e09379b8 100644 --- a/src/include/final/flabel.h +++ b/src/include/final/flabel.h @@ -132,7 +132,7 @@ class FLabel : public FWidget private: // Constants - static const std::size_t NOT_FOUND = static_cast(-1); + static const std::size_t NOT_SET = static_cast(-1); // Disable copy constructor FLabel (const FLabel&); diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index 336762e0..32d540af 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -124,6 +124,9 @@ class FMenu : public FWindow, public FMenuList void cb_menuitem_toggled (FWidget*, data_ptr); private: + // Constants + static const std::size_t NOT_SET = static_cast(-1); + // Typedef typedef struct { @@ -140,7 +143,7 @@ class FMenu : public FWindow, public FMenuList { wchar_t* text; std::size_t length; - int hotkeypos; + std::size_t hotkeypos; bool no_underline; } menuText; @@ -199,7 +202,7 @@ class FMenu : public FWindow, public FMenuList bool selectPrevItem(); void keypressMenuBar (FKeyEvent*); bool hotkeyMenu (FKeyEvent*); - int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t); virtual void draw(); void drawItems(); void drawSeparator (int); @@ -233,7 +236,7 @@ class FMenu : public FWindow, public FMenuList FMenu* opened_sub_menu; FMenu* shown_sub_menu; std::size_t max_item_width; - int hotkeypos; + std::size_t hotkeypos; bool mouse_down; bool has_checkable_items; }; diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index e25b1b77..2391e32f 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -101,13 +101,16 @@ class FMenuBar : public FWindow, public FMenuList void cb_item_deactivated (FWidget*, data_ptr); private: + // Constants + static const std::size_t NOT_SET = static_cast(-1); + // Typedef typedef struct { wchar_t* text; std::size_t length; std::size_t startpos; - int hotkeypos; + std::size_t hotkeypos; bool no_underline; } menuText; @@ -126,15 +129,15 @@ class FMenuBar : public FWindow, public FMenuList bool selectNextItem(); bool selectPrevItem(); bool hotkeyMenu (FKeyEvent*&); - int getHotkeyPos (wchar_t[], wchar_t[], std::size_t); + std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t); virtual void draw(); void drawItems(); - void drawItem (FMenuItem*, int&); + void drawItem (FMenuItem*, std::size_t&); void setLineAttributes (FMenuItem*); void drawMenuText (menuText&); - void drawEllipsis (menuText&, int); - void drawLeadingSpace (int&); - void drawTrailingSpace (int&); + void drawEllipsis (menuText&, std::size_t); + void drawLeadingSpace (std::size_t&); + void drawTrailingSpace (std::size_t&); void adjustItems(); bool activateMenu (FMenuItem*); bool clickItem (FMenuItem*); diff --git a/src/include/final/fprogressbar.h b/src/include/final/fprogressbar.h index b20b38f8..c0861719 100644 --- a/src/include/final/fprogressbar.h +++ b/src/include/final/fprogressbar.h @@ -78,10 +78,10 @@ class FProgressbar : public FWidget // Accessors const char* getClassName() const; - int getPercentage(); + std::size_t getPercentage(); // Mutators - void setPercentage (int); + void setPercentage (std::size_t); virtual void setGeometry (int, int, std::size_t, std::size_t, bool = true); bool setShadow (bool); bool setShadow(); @@ -95,13 +95,16 @@ class FProgressbar : public FWidget void reset(); private: + // Constants + static const std::size_t NOT_SET = static_cast(-1); + // Methods virtual void draw(); void drawPercentage(); void drawBar(); // Data Members - int percentage; + std::size_t percentage; std::size_t bar_length; }; #pragma pack(pop) @@ -113,7 +116,7 @@ inline const char* FProgressbar::getClassName() const { return "FProgressbar"; } //---------------------------------------------------------------------- -inline int FProgressbar::getPercentage() +inline std::size_t FProgressbar::getPercentage() { return percentage; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index dc242a32..dbfea09a 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -144,7 +144,7 @@ class FToggleButton : public FWidget private: // Constants - static const std::size_t NOT_FOUND = static_cast(-1); + static const std::size_t NOT_SET = static_cast(-1); // Disable copy constructor FToggleButton (const FToggleButton&); From 689199efe2f52c49c6b781fcd5be2828d707cb4b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 20 Oct 2018 22:50:35 +0200 Subject: [PATCH 15/17] createBlankArray + destroyBlankArray --- src/fbutton.cpp | 16 +---- src/fbuttongroup.cpp | 16 +---- src/flabel.cpp | 16 +---- src/flineedit.cpp | 16 +---- src/flistbox.cpp | 114 +++++++++++++------------------- src/flistview.cpp | 6 +- src/fmenubar.cpp | 18 +---- src/fmenuitem.cpp | 2 +- src/fprogressbar.cpp | 16 +---- src/fstatusbar.cpp | 18 +---- src/ftextview.cpp | 33 ++------- src/ftogglebutton.cpp | 17 +---- src/include/final/flistbox.h | 26 ++++---- src/include/final/flistview.h | 12 ++-- src/include/final/fmenuitem.h | 2 +- src/include/final/fstring.h | 12 ++-- src/include/final/ftermbuffer.h | 5 +- src/include/final/fvterm.h | 5 +- src/include/final/fwidget.h | 27 ++++++++ 19 files changed, 128 insertions(+), 249 deletions(-) diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 70b67040..d68266a0 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -265,7 +265,6 @@ void FButton::hide() { std::size_t s, f, size; short fg, bg; - char* blank; FWidget* parent_widget = getParentWidget(); FWidget::hide(); @@ -288,18 +287,7 @@ void FButton::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); for (std::size_t y = 0; y < getHeight() + s + (f << 1); y++) { @@ -307,7 +295,7 @@ void FButton::hide() print (blank); } - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 67f6dd6a..fcede4b7 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -191,7 +191,6 @@ void FButtonGroup::hide() { std::size_t size; short fg, bg; - char* blank; FWidget::hide(); FWidget* parent_widget = getParentWidget(); @@ -226,18 +225,7 @@ void FButtonGroup::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); for (int y = 0; y < int(getHeight()); y++) { @@ -245,7 +233,7 @@ void FButtonGroup::hide() print (blank); } - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- diff --git a/src/flabel.cpp b/src/flabel.cpp index 98ae734c..c2b1baec 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -243,7 +243,6 @@ void FLabel::hide() { short fg, bg; std::size_t size; - char* blank; FWidget* parent_widget = getParentWidget(); FWidget::hide(); @@ -265,21 +264,10 @@ void FLabel::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[getWidth()] = '\0'; + char* blank = createBlankArray(size + 1); setPrintPos (1, 1); print (blank); - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- diff --git a/src/flineedit.cpp b/src/flineedit.cpp index bbe87892..050a376b 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -283,7 +283,6 @@ void FLineEdit::hide() { std::size_t s, size; short fg, bg; - char* blank; FWidget* parent_widget = getParentWidget(); FWidget::hide(); @@ -306,18 +305,7 @@ void FLineEdit::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); for (std::size_t y = 0; y < getHeight() + s; y++) { @@ -325,7 +313,7 @@ void FLineEdit::hide() print (blank); } - delete[] blank; + destroyBlankArray(blank); if ( label ) label->hide(); diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 909353c4..9cca9f6d 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -169,16 +169,16 @@ void FListBox::showInsideBrackets ( std::size_t index if ( b == fc::NoBrackets ) return; - int len = int(iter->getText().getLength() + 2); + std::size_t len = iter->getText().getLength() + 2; if ( len > max_line_width ) { max_line_width = len; - if ( len >= int(getWidth()) - nf_offset - 3 ) + if ( len >= getWidth() - nf_offset - 3 ) { - hbar->setMaximum (max_line_width - int(getWidth()) + nf_offset + 4); - hbar->setPageSize (max_line_width, int(getWidth()) - nf_offset - 4); + hbar->setMaximum (int(max_line_width - getWidth() + nf_offset + 4)); + hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4)); hbar->setValue (xoffset); if ( ! hbar->isVisible() ) @@ -197,7 +197,7 @@ void FListBox::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adj if ( isNewFont() ) { vbar->setGeometry (int(getWidth()), 2, 2, getHeight() - 2); - hbar->setGeometry (1, int(getHeight()), getWidth() - 2 - std::size_t(nf_offset), 1); + hbar->setGeometry (1, int(getHeight()), getWidth() - 2 - nf_offset, 1); } else { @@ -242,9 +242,7 @@ void FListBox::hide() { std::size_t n, size; short fg, bg; - char* blank; FWidget* parent_widget = getParentWidget(); - FWidget::hide(); if ( parent_widget ) @@ -265,18 +263,7 @@ void FListBox::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset (blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); for (int y = 0; y < int(getHeight()); y++) { @@ -284,19 +271,19 @@ void FListBox::hide() print (blank); } - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- void FListBox::insert (FListBoxItem listItem) { - int len = int(listItem.text.getLength()); + std::size_t len = listItem.text.getLength(); bool has_brackets = bool(listItem.brackets); recalculateHorizontalBar (len, has_brackets); itemlist.push_back (listItem); - int element_count = int(getCount()); + std::size_t element_count = getCount(); recalculateVerticalBar (element_count); } @@ -337,7 +324,7 @@ void FListBox::remove (std::size_t item) while ( iter != itemlist.end() ) { - int len = int(iter->getText().getLength()); + std::size_t len = iter->getText().getLength(); if ( len > max_line_width ) max_line_width = len; @@ -345,10 +332,10 @@ void FListBox::remove (std::size_t item) ++iter; } - hbar->setMaximum (max_line_width - int(getWidth()) + nf_offset + 4); - hbar->setPageSize (max_line_width, int(getWidth()) - nf_offset - 4); + hbar->setMaximum (int(max_line_width - getWidth() + nf_offset + 4)); + hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4)); - if ( hbar->isVisible() && max_line_width < int(getWidth()) - nf_offset - 3 ) + if ( hbar->isVisible() && max_line_width < getWidth() - nf_offset - 3 ) hbar->hide(); vbar->setMaximum (int(element_count - getHeight()) + 2); @@ -374,10 +361,7 @@ void FListBox::remove (std::size_t item) void FListBox::clear() { std::size_t size; - char* blank; - itemlist.clear(); - current = 0; xoffset = 0; yoffset = 0; @@ -400,15 +384,7 @@ void FListBox::clear() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } + char* blank = createBlankArray(size + 1); std::memset (blank, ' ', size); blank[size] = '\0'; @@ -419,7 +395,7 @@ void FListBox::clear() print (blank); } - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- @@ -823,10 +799,10 @@ void FListBox::adjustSize() vbar->setHeight (getClientHeight(), false); vbar->resize(); - hbar->setMaximum (max_line_width - int(getClientWidth()) + 2); - hbar->setPageSize (max_line_width, int(getClientWidth()) - 2); + hbar->setMaximum (int(max_line_width - getClientWidth() + 2)); + hbar->setPageSize (int(max_line_width), int(getClientWidth()) - 2); hbar->setY (int(getHeight())); - hbar->setWidth (getClientWidth() + std::size_t(nf_offset), false); + hbar->setWidth (getClientWidth() + nf_offset, false); hbar->resize(); if ( element_count <= getClientHeight() ) @@ -834,7 +810,7 @@ void FListBox::adjustSize() else vbar->setVisible(); - if ( max_line_width < int(getClientWidth()) - 1 ) + if ( max_line_width < getClientWidth() - 1 ) hbar->hide(); else hbar->setVisible(); @@ -890,7 +866,7 @@ void FListBox::init() setTopPadding(1); setLeftPadding(1); setBottomPadding(1); - setRightPadding(1 + nf_offset); + setRightPadding(1 + int(nf_offset)); } //---------------------------------------------------------------------- @@ -1043,8 +1019,8 @@ inline void FListBox::drawListLine ( int y bool isCurrentLine = bool(y + yoffset + 1 == int(current)); bool isFocus = ((flags & fc::focus) != 0); FString element; - element = getString(iter).mid ( uInt(1 + xoffset) - , uInt(getWidth() - std::size_t(nf_offset) - 4) ); + element = getString(iter).mid ( std::size_t(1 + xoffset) + , getWidth() - nf_offset - 4 ); const wchar_t* const& element_str = element.wc_str(); len = element.getLength(); @@ -1072,7 +1048,7 @@ inline void FListBox::drawListLine ( int y i++; } - for (; i < getWidth() - std::size_t(nf_offset) - 3; i++) + for (; i < getWidth() - nf_offset - 3; i++) print (' '); } @@ -1153,11 +1129,11 @@ inline void FListBox::drawListBracketsLine ( int y printLeftBracket (iter->brackets); element = getString(iter).mid ( std::size_t(xoffset) + 1 - , getWidth() - std::size_t(nf_offset) - 5 ); + , getWidth() - nf_offset - 5 ); } else element = getString(iter).mid ( std::size_t(xoffset) - , getWidth() - std::size_t(nf_offset) - 4 ); + , getWidth() - nf_offset - 4 ); const wchar_t* const& element_str = element.wc_str(); len = element.getLength(); @@ -1177,7 +1153,7 @@ inline void FListBox::drawListBracketsLine ( int y full_length = getString(iter).getLength(); - if ( b + i < getWidth() - std::size_t(nf_offset) - 4 + if ( b + i < getWidth() - nf_offset - 4 && std::size_t(xoffset) <= full_length + 1 ) { if ( serach_mark && i == inc_len ) @@ -1194,7 +1170,7 @@ inline void FListBox::drawListBracketsLine ( int y i++; } - for (; b + i < getWidth() - std::size_t(nf_offset) - 3; i++) + for (; b + i < getWidth() - nf_offset - 3; i++) print (' '); } @@ -1310,7 +1286,7 @@ inline void FListBox::updateDrawing (bool draw_vbar, bool draw_hbar) } //---------------------------------------------------------------------- -void FListBox::recalculateHorizontalBar (int len, bool has_brackets) +void FListBox::recalculateHorizontalBar (std::size_t len, bool has_brackets) { if ( has_brackets ) len += 2; @@ -1320,10 +1296,10 @@ void FListBox::recalculateHorizontalBar (int len, bool has_brackets) max_line_width = len; - if ( len >= int(getWidth()) - nf_offset - 3 ) + if ( len >= getWidth() - nf_offset - 3 ) { - hbar->setMaximum (max_line_width - int(getWidth()) + nf_offset + 4); - hbar->setPageSize (max_line_width, int(getWidth()) - nf_offset - 4); + hbar->setMaximum (int(max_line_width - getWidth() + nf_offset + 4)); + hbar->setPageSize (int(max_line_width), int(getWidth() - nf_offset - 4)); hbar->calculateSliderValues(); if ( ! hbar->isVisible() ) @@ -1332,13 +1308,13 @@ void FListBox::recalculateHorizontalBar (int len, bool has_brackets) } //---------------------------------------------------------------------- -void FListBox::recalculateVerticalBar (int element_count) +void FListBox::recalculateVerticalBar (std::size_t element_count) { - vbar->setMaximum (element_count - int(getHeight()) + 2); - vbar->setPageSize (element_count, int(getHeight()) - 2); + vbar->setMaximum (int(element_count - getHeight() + 2)); + vbar->setPageSize (int(element_count), int(getHeight()) - 2); vbar->calculateSliderValues(); - if ( ! vbar->isVisible() && element_count >= int(getHeight()) - 1 ) + if ( ! vbar->isVisible() && element_count >= getHeight() - 1 ) vbar->setVisible(); } @@ -1595,16 +1571,16 @@ void FListBox::nextListItem (int distance) //---------------------------------------------------------------------- void FListBox::scrollToX (int val) { - static const int padding_space = 2; // 1 leading space + 1 trailing space - int xoffset_end = max_line_width - int(getClientWidth()) + padding_space; + static const std::size_t padding_space = 2; // 1 leading space + 1 trailing space + std::size_t xoffset_end = max_line_width - getClientWidth() + padding_space; if ( xoffset == val ) return; xoffset = val; - if ( xoffset > xoffset_end ) - xoffset = xoffset_end; + if ( xoffset > int(xoffset_end) ) + xoffset = int(xoffset_end); if ( xoffset < 0 ) xoffset = 0; @@ -1652,15 +1628,15 @@ void FListBox::scrollLeft (int distance) //---------------------------------------------------------------------- void FListBox::scrollRight (int distance) { - static const int padding_space = 2; // 1 leading space + 1 trailing space - int xoffset_end = max_line_width - int(getClientWidth()) + padding_space; + static const std::size_t padding_space = 2; // 1 leading space + 1 trailing space + std::size_t xoffset_end = max_line_width - getClientWidth() + padding_space; xoffset += distance; - if ( xoffset == xoffset_end ) + if ( xoffset == int(xoffset_end) ) return; - if ( xoffset > xoffset_end ) - xoffset = xoffset_end; + if ( xoffset > int(xoffset_end) ) + xoffset = int(xoffset_end); if ( xoffset < 0 ) xoffset = 0; @@ -1923,7 +1899,7 @@ void FListBox::lazyConvert(listBoxItems::iterator iter, int y) return; convertToItem (*iter, source_container, y + yoffset); - int len = int(iter->text.getLength()); + std::size_t len = iter->text.getLength(); recalculateHorizontalBar (len, hasBrackets(iter)); if ( hbar->isVisible() ) diff --git a/src/flistview.cpp b/src/flistview.cpp index bbbcbab9..7eb67cfb 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -343,7 +343,7 @@ void FListViewItem::collapse() // private methods of FListView //---------------------------------------------------------------------- -template +template void FListViewItem::sort (Compare cmp) { if ( ! expandable ) @@ -1429,7 +1429,7 @@ void FListView::init() } //---------------------------------------------------------------------- -template +template void FListView::sort (Compare cmp) { // Sort the top level @@ -1462,7 +1462,7 @@ std::size_t FListView::getAlignOffset ( fc::text_alignment align case fc::alignCenter: if ( txt_length < width ) - return std::size_t((width - txt_length) / 2); + return (width - txt_length) / 2; else return 0; diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index dfaf07b9..0564fd31 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -64,29 +64,15 @@ void FMenuBar::resetMenu() void FMenuBar::hide() { short fg, bg; - char* blank; - FWindow::hide(); fg = wc.term_fg; bg = wc.term_bg; setColor (fg, bg); screenWidth = getDesktopWidth(); - - try - { - blank = new char[screenWidth + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', screenWidth); - blank[screenWidth] = '\0'; + char* blank = createBlankArray (screenWidth + 1); setPrintPos (1, 1); print (blank); - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 7bd62ff7..c856196a 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -724,7 +724,7 @@ void FMenuItem::createDialogList (FMenu* winmenu) } //---------------------------------------------------------------------- -template +template void FMenuItem::passMouseEvent ( T widget, FMouseEvent* ev , fc::events ev_type ) { diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 54e70396..821ee5db 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -100,7 +100,6 @@ void FProgressbar::hide() { std::size_t s, size; short fg, bg; - char* blank; FWidget* parent_widget = getParentWidget(); FWidget::hide(); @@ -123,18 +122,7 @@ void FProgressbar::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); for (std::size_t y = 0; y < getHeight() + s; y++) { @@ -142,7 +130,7 @@ void FProgressbar::hide() print (blank); } - delete[] blank; + destroyBlankArray (blank); setPrintPos (int(getWidth()) - 4, 0); print (" "); // hide percentage } diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 2d073909..8011a876 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -197,29 +197,15 @@ bool FStatusBar::hasActivatedKey() void FStatusBar::hide() { short fg, bg; - char* blank; - FWindow::hide(); fg = wc.term_fg; bg = wc.term_bg; setColor (fg, bg); screenWidth = getDesktopWidth(); - - try - { - blank = new char[screenWidth + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', screenWidth); - blank[screenWidth] = '\0'; + char* blank = createBlankArray(screenWidth + 1); setPrintPos (1, 1); print (blank); - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- diff --git a/src/ftextview.cpp b/src/ftextview.cpp index d7fe4640..01c2b98e 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -195,7 +195,6 @@ void FTextView::hide() { std::size_t n, size; short fg, bg; - char* blank; FWidget* parent_widget = getParentWidget(); FWidget::hide(); @@ -218,18 +217,7 @@ void FTextView::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); for (std::size_t y = 0; y < getHeight(); y++) { @@ -237,7 +225,7 @@ void FTextView::hide() print (blank); } - delete[] blank; + destroyBlankArray (blank); flush_out(); } @@ -325,8 +313,6 @@ void FTextView::replaceRange (const FString& str, int from, int to) void FTextView::clear() { std::size_t size; - char* blank; - data.clear(); xoffset = 0; yoffset = 0; @@ -347,18 +333,7 @@ void FTextView::clear() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); for (int y = 0; y < int(getTextHeight()); y++) { @@ -366,7 +341,7 @@ void FTextView::clear() print (blank); } - delete[] blank; + destroyBlankArray (blank); processChanged(); } diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 15f8ba8e..b86bec1e 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -219,9 +219,7 @@ void FToggleButton::hide() { std::size_t size; short fg, bg; - char* blank; FWidget* parent_widget = getParentWidget(); - FWidget::hide(); if ( parent_widget ) @@ -241,21 +239,10 @@ void FToggleButton::hide() if ( size == 0 ) return; - try - { - blank = new char[size + 1]; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - std::memset(blank, ' ', size); - blank[size] = '\0'; + char* blank = createBlankArray(size + 1); setPrintPos (1, 1); print (blank); - delete[] blank; + destroyBlankArray (blank); } //---------------------------------------------------------------------- diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index a8cd7da2..37db0f41 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -147,9 +147,9 @@ class FListBox : public FWidget // Constructor explicit FListBox (FWidget* = 0); - template + template FListBox (Iterator, Iterator, InsertConverter, FWidget* = 0); - template + template FListBox (Container, LazyConverter, FWidget* = 0); // Destructor @@ -192,9 +192,9 @@ class FListBox : public FWidget // Methods virtual void hide(); - template + template void insert (Iterator, Iterator, InsertConverter); - template + template void insert (Container, LazyConverter); void insert (FListBoxItem); void insert ( const FString& @@ -254,8 +254,8 @@ class FListBox : public FWidget void setLineAttributes (int, bool, bool, bool&); void unsetAttributes(); void updateDrawing (bool, bool); - void recalculateHorizontalBar (int, bool); - void recalculateVerticalBar (int); + void recalculateHorizontalBar (std::size_t, bool); + void recalculateVerticalBar (std::size_t); void getWidgetFocus(); void multiSelection (std::size_t); void multiSelectionUpTo (std::size_t); @@ -321,15 +321,15 @@ class FListBox : public FWidget int xoffset; int yoffset; int last_yoffset; - int nf_offset; - int max_line_width; + std::size_t nf_offset; + std::size_t max_line_width; }; #pragma pack(pop) // FListBox inline functions //---------------------------------------------------------------------- -template +template inline FListBox::FListBox ( Iterator first , Iterator last , InsertConverter convert @@ -368,7 +368,7 @@ inline FListBox::FListBox ( Iterator first } //---------------------------------------------------------------------- -template +template inline FListBox::FListBox ( Container container , LazyConverter convert , FWidget* parent ) @@ -496,7 +496,7 @@ inline bool FListBox::hasBrackets(listBoxItems::iterator iter) const { return bool(iter->brackets > 0); } //---------------------------------------------------------------------- -template +template inline void FListBox::insert ( Iterator first , Iterator last , InsertConverter convert ) @@ -511,7 +511,7 @@ inline void FListBox::insert ( Iterator first } //---------------------------------------------------------------------- -template +template void FListBox::insert (Container container, LazyConverter convert) { conv_type = lazy_convert; @@ -522,7 +522,7 @@ void FListBox::insert (Container container, LazyConverter convert) if ( size > 0 ) itemlist.resize(size); - recalculateVerticalBar(int(size)); + recalculateVerticalBar(size); } //---------------------------------------------------------------------- diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 6453705d..57a81ecb 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -115,7 +115,7 @@ class FListViewItem : public FObject bool isExpandable() const; // Methods - template + template void sort (Compare); FObjectIterator appendItem (FListViewItem*); void replaceControlCodes(); @@ -276,9 +276,9 @@ class FListView : public FWidget = fc::by_name); void setColumnSort (int, fc::sorting_order \ = fc::ascending); - template + template void setUserAscendingCompare (Compare); - template + template void setUserDescendingCompare (Compare); bool setTreeView (bool); bool setTreeView(); @@ -342,7 +342,7 @@ class FListView : public FWidget // Methods void init(); - template + template void sort (Compare); std::size_t getAlignOffset ( fc::text_alignment , std::size_t @@ -465,12 +465,12 @@ inline FListViewItem* FListView::getCurrentItem() { return static_cast(*current_iter); } //---------------------------------------------------------------------- -template +template inline void FListView::setUserAscendingCompare (Compare cmp) { user_defined_ascending = cmp; } //---------------------------------------------------------------------- -template +template inline void FListView::setUserDescendingCompare (Compare cmp) { user_defined_descending = cmp; } diff --git a/src/include/final/fmenuitem.h b/src/include/final/fmenuitem.h index bec1e29f..7f5a891d 100644 --- a/src/include/final/fmenuitem.h +++ b/src/include/final/fmenuitem.h @@ -175,7 +175,7 @@ class FMenuItem : public FWidget void processActivate(); void processDeactivate(); void createDialogList (FMenu*); - template + template void passMouseEvent (T, FMouseEvent*, fc::events); // Callback methods diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 73ac4866..9fd56227 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -308,7 +308,7 @@ inline const wchar_t& FString::operator [] (IndexT pos) const } //---------------------------------------------------------------------- -template +template inline bool FString::operator < (CharT& s) const { const FString tmp(s); @@ -316,7 +316,7 @@ inline bool FString::operator < (CharT& s) const } //---------------------------------------------------------------------- -template +template inline bool FString::operator <= (CharT& s) const { const FString tmp(s); @@ -324,7 +324,7 @@ inline bool FString::operator <= (CharT& s) const } //---------------------------------------------------------------------- -template +template inline bool FString::operator == (CharT& s) const { const FString tmp(s); @@ -332,7 +332,7 @@ inline bool FString::operator == (CharT& s) const } //---------------------------------------------------------------------- -template +template inline bool FString::operator != (CharT& s) const { const FString tmp(s); @@ -340,7 +340,7 @@ inline bool FString::operator != (CharT& s) const } //---------------------------------------------------------------------- -template +template inline bool FString::operator >= (CharT& s) const { const FString tmp(s); @@ -348,7 +348,7 @@ inline bool FString::operator >= (CharT& s) const } //---------------------------------------------------------------------- -template +template inline bool FString::operator > (CharT& s) const { const FString tmp(s); diff --git a/src/include/final/ftermbuffer.h b/src/include/final/ftermbuffer.h index f6952246..c2dd5618 100644 --- a/src/include/final/ftermbuffer.h +++ b/src/include/final/ftermbuffer.h @@ -65,7 +65,8 @@ class FTermBuffer virtual ~FTermBuffer(); // Overloaded operators - template FTermBuffer& operator << (const type&); + template + FTermBuffer& operator << (const type&); // Non-member operators friend std::vector& operator << ( std::vector& , const FTermBuffer& ); @@ -93,7 +94,7 @@ class FTermBuffer // FTermBuffer inline functions //---------------------------------------------------------------------- -template +template inline FTermBuffer& FTermBuffer::operator << (const type& s) { std::wostringstream outstream; diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index 389530f3..a60612e3 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -120,7 +120,8 @@ class FVTerm : public FTerm virtual ~FVTerm(); // Overloaded operators - template FVTerm& operator << (const type&); + template + FVTerm& operator << (const type&); FVTerm& operator << (const std::vector&); // Accessors @@ -503,7 +504,7 @@ struct FVTerm::term_area // define virtual terminal character properties // FVTerm inline functions //---------------------------------------------------------------------- -template +template inline FVTerm& FVTerm::operator << (const type& s) { std::wostringstream outstream; diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 90154c6d..69fbef5f 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -932,6 +932,33 @@ const wchar_t CHECKED_RADIO_BUTTON[4] = '\0' }; +// non-member functions +//---------------------------------------------------------------------- +inline char* createBlankArray (std::size_t size) +{ + char* blank; + + try + { + blank = new char[size + 1]; + } + catch (const std::bad_alloc& ex) + { + std::cerr << "not enough memory to alloc " << ex.what() << std::endl; + return 0; + } + + std::memset(blank, ' ', size); + blank[size] = '\0'; + return blank; +} + +//---------------------------------------------------------------------- +inline void destroyBlankArray (char blank[]) +{ + delete[] blank; +} + } // namespace finalcut #endif // FWIDGET_H From 540291b410932ecc62e6007e3ef7a2b441293b9e Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 21 Oct 2018 21:06:52 +0200 Subject: [PATCH 16/17] Moving static attributes from FApplication to FWidget --- ChangeLog | 3 + src/fapplication.cpp | 122 ++++++++++++++++++------------- src/ftextview.cpp | 2 +- src/fwidget.cpp | 115 +++++------------------------ src/fwindow.cpp | 14 +--- src/include/final/fapplication.h | 36 +-------- src/include/final/fwidget.h | 76 +++++++++++++++++-- src/include/final/fwindow.h | 1 - 8 files changed, 167 insertions(+), 202 deletions(-) diff --git a/ChangeLog b/ChangeLog index 350a9eee..646e374b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-10-21 Markus Gans + * Moving static attributes from FApplication to FWidget + 2018-10-17 Markus Gans * Changed more variables from int to std::size_t diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 0fa19fd5..2a1e04f5 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -31,25 +31,25 @@ namespace finalcut { -// global application object -static FApplication* rootObj = 0; +// Global application object +static FApplication* app_object = 0; -// flag to exit local loop +// Flag to exit the local event loop static bool app_exit_loop = false; -// static attributes -int FApplication::loop_level = 0; // event loop level -FWidget* FApplication::main_widget = 0; // main application widget -FWidget* FApplication::active_window = 0; // the active window -FWidget* FApplication::focus_widget = 0; // has keyboard input focus -FWidget* FApplication::clicked_widget = 0; // is focused by click -FWidget* FApplication::open_menu = 0; // currently open menu -FWidget* FApplication::move_size_widget = 0; // move/size by keyboard -FWidget* FApplication::keyboard_widget = 0; // has the keyboard focus -FKeyboard* FApplication::keyboard = 0; // keyboard access -FMouseControl* FApplication::mouse = 0; // mouse control -int FApplication::quit_code = 0; -bool FApplication::quit_now = false; +// Static attributes +FWidget* FWidget::main_widget = 0; // main application widget +FWidget* FWidget::active_window = 0; // the active window +FWidget* FWidget::focus_widget = 0; // has keyboard input focus +FWidget* FWidget::clicked_widget = 0; // is focused by click +FWidget* FWidget::open_menu = 0; // currently open menu +FWidget* FWidget::move_size_widget = 0; // move/size by keyboard +FWidget* FApplication::keyboard_widget = 0; // has the keyboard focus +FKeyboard* FApplication::keyboard = 0; // keyboard access +FMouseControl* FApplication::mouse = 0; // mouse control +int FApplication::loop_level = 0; // event loop level +int FApplication::quit_code = 0; +bool FApplication::quit_now = false; FApplication::eventQueue* FApplication::event_queue = 0; @@ -69,9 +69,9 @@ FApplication::FApplication ( const int& _argc , key_timeout(100000) // 100 ms , dblclick_interval(500000) // 500 ms { - assert ( ! rootObj + assert ( ! app_object && "FApplication: There should be only one application object" ); - rootObj = this; + app_object = this; if ( ! (_argc && _argv) ) { @@ -89,27 +89,21 @@ FApplication::~FApplication() // destructor if ( event_queue ) delete event_queue; - rootObj = 0; + app_object = 0; } // public methods of FApplication //---------------------------------------------------------------------- -void FApplication::setMainWidget (FWidget* widget) +FWidget* FApplication::getApplicationObject() { - main_widget = widget; - - if ( widget && ! getFocusWidget() ) - rootObj->focusFirstChild(); + return static_cast(app_object); } //---------------------------------------------------------------------- bool FApplication::isQuit() { - if ( rootObj ) - return quit_now; - else - return true; + return ( app_object ) ? quit_now : true; } //---------------------------------------------------------------------- @@ -152,7 +146,7 @@ void FApplication::exit_loop() //---------------------------------------------------------------------- void FApplication::exit (int retcode) { - if ( ! rootObj ) // no global app object + if ( ! app_object ) // no global app object return; if ( quit_now ) // don't overwrite quit code @@ -264,7 +258,7 @@ void FApplication::sendQueuedEvents() //---------------------------------------------------------------------- bool FApplication::eventInQueue() { - if ( rootObj ) + if ( app_object ) return ( ! event_queue->empty() ); else return false; @@ -507,6 +501,8 @@ inline void FApplication::findKeyboardWidget() // Find the widget that has the keyboard focus FWidget* widget = 0; + FWidget* focus_widget = getFocusWidget(); + FWidget* move_size_widget = getMoveSizeWidget(); if ( focus_widget ) { @@ -517,7 +513,7 @@ inline void FApplication::findKeyboardWidget() } else { - widget = main_widget; + widget = getMainWidget(); if ( widget && widget->numOfChildren() >= 1 ) widget->focusFirstChild(); @@ -641,7 +637,7 @@ inline bool FApplication::sendKeyUpEvent (FWidget* widget) //---------------------------------------------------------------------- inline void FApplication::sendKeyboardAccelerator() { - if ( open_menu ) + if ( getOpenMenu() ) return; // Switch to a specific dialog with Meta + 1..9 @@ -650,7 +646,7 @@ inline void FApplication::sendKeyboardAccelerator() // Windows keyboard accelerator if ( ! accpt ) { - const FWidget* window = active_window; + const FWidget* window = getActiveWindow(); if ( window ) accpt = processAccelerator (window); @@ -696,14 +692,16 @@ bool FApplication::processDialogSwitchAccelerator() if ( s > 0 && s >= n ) { // unset the move/size mode + FWidget* move_size_widget = getMoveSizeWidget(); + if ( move_size_widget ) { FWidget* w = move_size_widget; - move_size_widget = 0; + setMoveSizeWidget(0); w->redraw(); } - FAccelEvent a_ev (fc::Accelerator_Event, focus_widget); + FAccelEvent a_ev (fc::Accelerator_Event, getFocusWidget()); sendEvent (dialog_list->at(n - 1), &a_ev); return true; } @@ -733,14 +731,16 @@ bool FApplication::processAccelerator (const FWidget*& widget) if ( iter->key == keyboard->getKey() ) { // unset the move/size mode + FWidget* move_size_widget = getMoveSizeWidget(); + if ( move_size_widget ) { FWidget* w = move_size_widget; - move_size_widget = 0; + setMoveSizeWidget(0); w->redraw(); } - FAccelEvent a_ev (fc::Accelerator_Event, focus_widget); + FAccelEvent a_ev (fc::Accelerator_Event, getFocusWidget()); sendEvent (iter->object, &a_ev); accpt = a_ev.isAccepted(); break; @@ -772,6 +772,8 @@ bool FApplication::getMouseEvent() //---------------------------------------------------------------------- FWidget*& FApplication::determineClickedWidget() { + FWidget*& clicked_widget = getClickedWidget(); + if ( clicked_widget ) return clicked_widget; @@ -796,6 +798,7 @@ FWidget*& FApplication::determineClickedWidget() // Determine the widget at the current click position FWidget* child = childWidgetAt (window, mouse_position); clicked_widget = ( child != 0 ) ? child : window; + setClickedWidget (clicked_widget); } return clicked_widget; @@ -805,10 +808,13 @@ FWidget*& FApplication::determineClickedWidget() void FApplication::unsetMoveSizeMode() { // Unset the move/size mode + + FWidget* move_size_widget = getMoveSizeWidget(); + if ( move_size_widget ) { FWidget* w = move_size_widget; - move_size_widget = 0; + setMoveSizeWidget(0); w->redraw(); } } @@ -818,11 +824,12 @@ void FApplication::closeOpenMenu() { // Close the open menu + FWidget* open_menu = getOpenMenu(); + FMenu* menu = static_cast(open_menu); + if ( ! open_menu || ( mouse && mouse->isMoved()) ) return; - FMenu* menu = static_cast(open_menu); - if ( mouse ) { const FPoint& mouse_position = mouse->getPos(); @@ -845,7 +852,7 @@ void FApplication::closeOpenMenu() menu->hideSuperMenus(); // No widget was been clicked and the menu is no dialog menu - if ( ! (clicked_widget || is_window_menu) ) + if ( ! (getClickedWidget() || is_window_menu) ) FWindow::switchToPrevWindow(); if ( getStatusBar() ) @@ -860,11 +867,12 @@ void FApplication::unselectMenubarItems() { // Unselect the menu bar items + FWidget* open_menu = getOpenMenu(); + FMenuBar* menu_bar = getMenuBar(); + if ( open_menu || (mouse && mouse->isMoved()) ) return; - FMenuBar* menu_bar = getMenuBar(); - if ( ! menu_bar ) return; @@ -885,7 +893,7 @@ void FApplication::unselectMenubarItems() getMenuBar()->redraw(); // No widget was been clicked - if ( ! clicked_widget ) + if ( ! getClickedWidget() ) FWindow::switchToPrevWindow(); if ( getStatusBar() ) @@ -899,6 +907,8 @@ void FApplication::unselectMenubarItems() //---------------------------------------------------------------------- void FApplication::sendMouseEvent() { + FWidget* clicked_widget = getClickedWidget(); + if ( ! clicked_widget ) return; @@ -943,6 +953,8 @@ void FApplication::sendMouseMoveEvent ( const FPoint& widgetMousePos if ( ! mouse ) return; + FWidget* clicked_widget = getClickedWidget(); + if ( mouse->isLeftButtonPressed() ) { FMouseEvent m_down_ev ( fc::MouseMove_Event @@ -979,6 +991,8 @@ void FApplication::sendMouseLeftClickEvent ( const FPoint& widgetMousePos if ( ! mouse ) return; + FWidget* clicked_widget = getClickedWidget(); + if ( mouse->isLeftButtonDoubleClick() ) { FMouseEvent m_dblclick_ev ( fc::MouseDoubleClick_Event @@ -1005,7 +1019,7 @@ void FApplication::sendMouseLeftClickEvent ( const FPoint& widgetMousePos if ( ! mouse->isRightButtonPressed() && ! mouse->isMiddleButtonPressed() ) - clicked_widget = 0; + setClickedWidget(0); sendEvent (released_widget, &m_up_ev); } @@ -1019,6 +1033,8 @@ void FApplication::sendMouseRightClickEvent ( const FPoint& widgetMousePos if ( ! mouse ) return; + FWidget* clicked_widget = getClickedWidget(); + if ( mouse->isRightButtonPressed() ) { FMouseEvent m_down_ev ( fc::MouseDown_Event @@ -1037,7 +1053,7 @@ void FApplication::sendMouseRightClickEvent ( const FPoint& widgetMousePos if ( ! mouse->isLeftButtonPressed() && ! mouse->isMiddleButtonPressed() ) - clicked_widget = 0; + setClickedWidget(0); sendEvent (released_widget, &m_up_ev); } @@ -1051,6 +1067,8 @@ void FApplication::sendMouseMiddleClickEvent ( const FPoint& widgetMousePos if ( ! mouse ) return; + FWidget* clicked_widget = getClickedWidget(); + if ( mouse->isMiddleButtonPressed() ) { FMouseEvent m_down_ev ( fc::MouseDown_Event @@ -1061,7 +1079,7 @@ void FApplication::sendMouseMiddleClickEvent ( const FPoint& widgetMousePos // gnome-terminal sends no released on middle click if ( isGnomeTerminal() ) - clicked_widget = 0; + setClickedWidget(0); } else if ( mouse->isMiddleButtonReleased() ) { @@ -1074,7 +1092,7 @@ void FApplication::sendMouseMiddleClickEvent ( const FPoint& widgetMousePos if ( ! mouse->isLeftButtonPressed() && ! mouse->isRightButtonPressed() ) { - clicked_widget = 0; + setClickedWidget(0); } sendEvent (released_widget, &m_up_ev); @@ -1088,6 +1106,8 @@ void FApplication::sendWheelEvent ( const FPoint& widgetMousePos if ( ! mouse ) return; + FWidget* clicked_widget = getClickedWidget(); + if ( mouse->isWheelUp() ) { FWheelEvent wheel_ev ( fc::MouseWheel_Event @@ -1095,7 +1115,7 @@ void FApplication::sendWheelEvent ( const FPoint& widgetMousePos , mouse_position , fc::WheelUp ); FWidget* scroll_over_widget = clicked_widget; - clicked_widget = 0; + setClickedWidget(0); sendEvent(scroll_over_widget, &wheel_ev); } @@ -1106,7 +1126,7 @@ void FApplication::sendWheelEvent ( const FPoint& widgetMousePos , mouse_position , fc::WheelDown ); FWidget* scroll_over_widget = clicked_widget; - clicked_widget = 0; + setClickedWidget(0); sendEvent (scroll_over_widget, &wheel_ev); } } @@ -1133,7 +1153,7 @@ void FApplication::processResizeEvent() if ( hasChangedTermSize() ) { FResizeEvent r_ev(fc::Resize_Event); - sendEvent(rootObj, &r_ev); + sendEvent(app_object, &r_ev); if ( r_ev.isAccepted() ) changeTermSizeFinished(); diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 01c2b98e..a4b46b57 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -243,7 +243,7 @@ void FTextView::insert (const FString& str, int pos) FString s; std::size_t num; - if ( pos >= int(getRows()) ) + if ( pos < 0 || pos >= int(getRows()) ) pos = int(getRows()); if ( str.isEmpty() ) diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 27dec6d1..a0d3acdb 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -34,19 +34,18 @@ namespace finalcut static FWidget* rootObject = 0; // static class attributes -uInt FWidget::modal_dialogs; - -FStatusBar* FWidget::statusbar = 0; -FMenuBar* FWidget::menubar = 0; -FWidget* FWidget::show_root_widget = 0; -FWidget* FWidget::redraw_root_widget = 0; -FWidget::widgetList* FWidget::window_list = 0; -FWidget::widgetList* FWidget::dialog_list = 0; -FWidget::widgetList* FWidget::always_on_top_list = 0; -FWidget::widgetList* FWidget::close_widget = 0; -FWidgetColors FWidget::wc; -bool FWidget::init_desktop; -bool FWidget::hideable; +FStatusBar* FWidget::statusbar = 0; +FMenuBar* FWidget::menubar = 0; +FWidget* FWidget::show_root_widget = 0; +FWidget* FWidget::redraw_root_widget = 0; +FWidget::widgetList* FWidget::window_list = 0; +FWidget::widgetList* FWidget::dialog_list = 0; +FWidget::widgetList* FWidget::always_on_top_list = 0; +FWidget::widgetList* FWidget::close_widget = 0; +FWidgetColors FWidget::wc; +bool FWidget::init_desktop; +bool FWidget::hideable; +uInt FWidget::modal_dialogs; //---------------------------------------------------------------------- @@ -175,20 +174,6 @@ FWidget* FWidget::getParentWidget() const return 0; } -//---------------------------------------------------------------------- -FWidget* FWidget::getMainWidget() -{ - FWidget* main_widget = static_cast(FApplication::main_widget); - return main_widget; -} - -//---------------------------------------------------------------------- -FWidget* FWidget::getFocusWidget() const -{ - FWidget* focus_widget = static_cast(FApplication::focus_widget); - return focus_widget; -} - //---------------------------------------------------------------------- FWidget* FWidget::getFirstFocusableWidget (FObjectList list) { @@ -242,44 +227,6 @@ FWidget* FWidget::getLastFocusableWidget (FObjectList list) return 0; } -//---------------------------------------------------------------------- -FWidget* FWidget::getClickedWidget() -{ - FWidget* clicked_widget = static_cast(FApplication::clicked_widget); - return clicked_widget; -} - -//---------------------------------------------------------------------- -FWidget* FWidget::getMoveSizeWidget() -{ - return FApplication::move_size_widget; -} - -//---------------------------------------------------------------------- -FWidget* FWidget::getOpenMenu() -{ - FWidget* open_menu = static_cast(FApplication::open_menu); - return open_menu; -} - -//---------------------------------------------------------------------- -FMenuBar* FWidget::getMenuBar() -{ - if ( menubar ) - return menubar; - else - return 0; -} - -//---------------------------------------------------------------------- -FStatusBar* FWidget::getStatusBar() -{ - if ( statusbar ) - return statusbar; - else - return 0; -} - //---------------------------------------------------------------------- FPoint FWidget::getPrintPos() { @@ -319,38 +266,11 @@ std::vector& FWidget::doubleFlatLine_ref (fc::sides side) //---------------------------------------------------------------------- void FWidget::setMainWidget (FWidget* obj) { - FApplication* fapp = static_cast(rootObject); - fapp->setMainWidget(obj); -} + main_widget = obj; + FWidget* app_object = FApplication::getApplicationObject(); -//---------------------------------------------------------------------- -void FWidget::setFocusWidget (FWidget* obj) -{ - FApplication::focus_widget = obj; -} - -//---------------------------------------------------------------------- -void FWidget::setClickedWidget (FWidget* obj) -{ - FApplication::clicked_widget = obj; -} - -//---------------------------------------------------------------------- -void FWidget::setMoveSizeWidget (FWidget* obj) -{ - FApplication::move_size_widget = obj; -} - -//---------------------------------------------------------------------- -void FWidget::setOpenMenu (FWidget* obj) -{ - FApplication::open_menu = obj; -} - -//---------------------------------------------------------------------- -void FWidget::setStatusbarMessage (const FString& msg) -{ - statusbar_message = msg; + if ( obj && app_object && ! getFocusWidget() ) + app_object->focusFirstChild(); } //---------------------------------------------------------------------- @@ -1569,7 +1489,8 @@ void FWidget::drawBorder (int x1, int y1, int x2, int y2) //---------------------------------------------------------------------- void FWidget::quit() { - FApplication* fapp = static_cast(rootObject); + FWidget* app_object = FApplication::getApplicationObject(); + FApplication* fapp = static_cast(app_object); fapp->exit(0); } diff --git a/src/fwindow.cpp b/src/fwindow.cpp index dc53fea9..e3a8e539 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -80,14 +80,6 @@ FWindow::~FWindow() // destructor // public methods of FWindow -//---------------------------------------------------------------------- -FWindow* FWindow::getActiveWindow() -{ - // returns the active FWindow object - FWindow* active_window = static_cast(FApplication::active_window); - return active_window; -} - //---------------------------------------------------------------------- FWidget* FWindow::getWindowFocusWidget() const { @@ -170,7 +162,7 @@ bool FWindow::activateWindow (bool on) // activate/deactivate this window if ( on ) { - FApplication::active_window = this; + FWidget::setActiveWindow (this); active_area = getVWin(); } @@ -181,7 +173,7 @@ bool FWindow::activateWindow (bool on) void FWindow::unsetActiveWindow() { // unset the active FWindow object - FApplication::active_window = 0; + FWidget::setActiveWindow (0); } //---------------------------------------------------------------------- @@ -728,7 +720,7 @@ void FWindow::switchToPrevWindow() updateTerminal (FVTerm::stop_refresh); bool is_activated = activatePrevWindow(); - FWindow* active_window = getActiveWindow(); + FWindow* active_window = static_cast(getActiveWindow()); if ( ! is_activated ) { diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 3b04c661..fa22cbeb 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -92,11 +92,7 @@ class FApplication : public FWidget const char* getClassName() const; int getArgc() const; char** getArgv() const; - FWidget* getMainWidget() const; - virtual FWidget* getFocusWidget() const; - - // Mutator - void setMainWidget (FWidget*); + static FWidget* getApplicationObject(); // Inquiry static bool isQuit(); @@ -193,28 +189,6 @@ class FApplication : public FWidget static bool process_timer_event; static FKeyboard* keyboard; static FWidget* keyboard_widget; - static FWidget* move_size_widget; - static FWidget* main_widget; - static FWidget* active_window; - static FWidget* focus_widget; - static FWidget* clicked_widget; - static FWidget* open_menu; - - // Friend functions from FWidget - friend FWidget* FWidget::getMainWidget(); - friend FWidget* FWidget::getFocusWidget() const; - friend void FWidget::setFocusWidget (FWidget*); - friend FWidget* FWidget::getClickedWidget(); - friend void FWidget::setClickedWidget (FWidget*); - friend FWidget* FWidget::getMoveSizeWidget(); - friend void FWidget::setMoveSizeWidget (FWidget*); - friend FWidget* FWidget::getOpenMenu(); - friend void FWidget::setOpenMenu (FWidget*); - - // Friend functions from FWindow - friend bool FWindow::activateWindow (bool); - friend FWindow* FWindow::getActiveWindow(); - friend void FWindow::unsetActiveWindow(); }; #pragma pack(pop) @@ -232,14 +206,6 @@ inline int FApplication::getArgc() const inline char** FApplication::getArgv() const { return app_argv; } -//---------------------------------------------------------------------- -inline FWidget* FApplication::getMainWidget() const -{ return main_widget; } - -//---------------------------------------------------------------------- -inline FWidget* FApplication::getFocusWidget() const -{ return focus_widget; } - //---------------------------------------------------------------------- inline void FApplication::cb_exitApp (FWidget*, data_ptr) { close(); } diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 69fbef5f..2dab5d76 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -152,13 +152,14 @@ class FWidget : public FVTerm, public FObject const char* getClassName() const; FWidget* getRootWidget() const; FWidget* getParentWidget() const; - static FWidget* getMainWidget(); - virtual FWidget* getFocusWidget() const; + static FWidget*& getMainWidget(); + static FWidget*& getActiveWindow(); + static FWidget*& getFocusWidget(); + static FWidget*& getClickedWidget(); + static FWidget*& getOpenMenu(); + static FWidget*& getMoveSizeWidget(); virtual FWidget* getFirstFocusableWidget (FObjectList); virtual FWidget* getLastFocusableWidget (FObjectList); - static FWidget* getClickedWidget(); - static FWidget* getMoveSizeWidget(); - static FWidget* getOpenMenu(); static FMenuBar* getMenuBar(); static FStatusBar* getStatusBar(); FString getStatusbarMessage() const; @@ -194,9 +195,10 @@ class FWidget : public FVTerm, public FObject // Mutators static void setMainWidget (FWidget*); - virtual void setFocusWidget (FWidget*); + static void setFocusWidget (FWidget*); static void setClickedWidget (FWidget*); static void setMoveSizeWidget (FWidget*); + static void setActiveWindow (FWidget*); static void setOpenMenu (FWidget*); virtual void setStatusbarMessage (const FString&); bool setVisible(); @@ -491,6 +493,12 @@ class FWidget : public FVTerm, public FObject FString statusbar_message; static FStatusBar* statusbar; static FMenuBar* menubar; + static FWidget* main_widget; + static FWidget* active_window; + static FWidget* focus_widget; + static FWidget* clicked_widget; + static FWidget* open_menu; + static FWidget* move_size_widget; static FWidget* show_root_widget; static FWidget* redraw_root_widget; static bool init_desktop; @@ -508,6 +516,38 @@ class FWidget : public FVTerm, public FObject inline const char* FWidget::getClassName() const { return "FWidget"; } +//---------------------------------------------------------------------- +inline FWidget*& FWidget::getMainWidget() +{ return main_widget; } + +//---------------------------------------------------------------------- +inline FWidget*& FWidget::getActiveWindow() // returns active FWindow object +{ return active_window; } + +//---------------------------------------------------------------------- +inline FWidget*& FWidget::getFocusWidget() +{ return focus_widget; } + +//---------------------------------------------------------------------- +inline FWidget*& FWidget::getClickedWidget() +{ return clicked_widget; } + +//---------------------------------------------------------------------- +inline FWidget*& FWidget::getOpenMenu() +{ return open_menu; } + +//---------------------------------------------------------------------- +inline FWidget*& FWidget::getMoveSizeWidget() +{ return move_size_widget; } + +//---------------------------------------------------------------------- +inline FMenuBar* FWidget::getMenuBar() +{ return menubar; } + +//---------------------------------------------------------------------- +inline FStatusBar* FWidget::getStatusBar() +{ return statusbar; } + //---------------------------------------------------------------------- inline FString FWidget::getStatusbarMessage() const { return statusbar_message; } @@ -650,6 +690,30 @@ inline int FWidget::getFlags() const inline FPoint FWidget::getCursorPos() { return widget_cursor_position; } +//---------------------------------------------------------------------- +inline void FWidget::setActiveWindow (FWidget* obj) +{ active_window = obj; } + +//---------------------------------------------------------------------- +inline void FWidget::setFocusWidget (FWidget* obj) +{ focus_widget = obj; } + +//---------------------------------------------------------------------- +inline void FWidget::setClickedWidget (FWidget* obj) +{ clicked_widget = obj; } + +//---------------------------------------------------------------------- +inline void FWidget::setOpenMenu (FWidget* obj) +{ open_menu = obj; } + +//---------------------------------------------------------------------- +inline void FWidget::setMoveSizeWidget (FWidget* obj) +{ move_size_widget = obj; } + +//---------------------------------------------------------------------- +inline void FWidget::setStatusbarMessage (const FString& msg) +{ statusbar_message = msg; } + //---------------------------------------------------------------------- inline bool FWidget::setVisible() { return visible = true; } diff --git a/src/include/final/fwindow.h b/src/include/final/fwindow.h index d05dda77..2aa649b0 100644 --- a/src/include/final/fwindow.h +++ b/src/include/final/fwindow.h @@ -91,7 +91,6 @@ class FWindow : public FWidget const char* getClassName() const; static FWindow* getWindowWidget (const FWidget*); static int getWindowLayer (const FWidget*); - static FWindow* getActiveWindow(); FWidget* getWindowFocusWidget() const; // Mutators From 3678d527665de15c788aa57562f62f25b868fe5f Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 22 Oct 2018 01:26:24 +0200 Subject: [PATCH 17/17] Small code fixes --- src/fdialog.cpp | 8 ++------ src/fdialoglistmenu.cpp | 4 +--- src/flineedit.cpp | 3 +-- src/foptimove.cpp | 4 ++-- src/fterm.cpp | 2 +- src/ftermlinux.cpp | 11 +++-------- src/include/final/fpoint.h | 10 +++++----- test/fkeyboard-test.cpp | 2 +- test/fobject-test.cpp | 8 +++++--- test/fpoint-test.cpp | 6 ++++-- test/frect-test.cpp | 4 +++- 11 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 0542e912..bad4c777 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -925,12 +925,8 @@ void FDialog::initDialogMenu() dialog_menu->setPos (getX(), getY() + 1); dgl_menuitem = dialog_menu->getItem(); - - if ( dgl_menuitem ) - { - dgl_menuitem->ignorePadding(); - dgl_menuitem->unsetFocusable(); - } + dgl_menuitem->ignorePadding(); + dgl_menuitem->unsetFocusable(); // Add the move/size menu item initMoveSizeMenuItem (dialog_menu); diff --git a/src/fdialoglistmenu.cpp b/src/fdialoglistmenu.cpp index c7ebff1c..fec9d201 100644 --- a/src/fdialoglistmenu.cpp +++ b/src/fdialoglistmenu.cpp @@ -54,9 +54,7 @@ FDialogListMenu::~FDialogListMenu() void FDialogListMenu::init() { FMenuItem* menuitem = getItem(); - - if ( menuitem ) - menuitem->dialog_index = true; + menuitem->dialog_index = true; } } // namespace finalcut diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 050a376b..a1bef7b3 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -529,8 +529,7 @@ void FLineEdit::onTimer (FTimerEvent*) return; } - if ( text_offset > 0 ) - text_offset--; + text_offset--; if ( cursor_pos > 0 ) cursor_pos--; diff --git a/src/foptimove.cpp b/src/foptimove.cpp index dfbc3471..d20ff575 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -1154,11 +1154,11 @@ void FOptiMove::moveByMethod ( int method if ( xold >= 0 ) std::strncat ( move_ptr , F_carriage_return.cap - , BUF_SIZE - std::strlen(move_ptr) ); + , BUF_SIZE - std::strlen(move_ptr) - 1 ); std::strncat ( move_ptr , F_cursor_left.cap - , BUF_SIZE - std::strlen(move_ptr) ); + , BUF_SIZE - std::strlen(move_ptr) - 1); move_ptr[BUF_SIZE - 1] ='\0'; move_ptr += std::strlen(move_buf); relativeMove (move_ptr, int(screen_width) - 1, yold - 1, xnew, ynew); diff --git a/src/fterm.cpp b/src/fterm.cpp index dfd3588d..246efefc 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -416,7 +416,7 @@ char* FTerm::enableCursor() // Restore the last used Linux console cursor style char* cstyle; cstyle = linux->restoreCursorStyle(); - std::strncat (enable_str, cstyle, SIZE - std::strlen(enable_str)); + std::strncat (enable_str, cstyle, SIZE - std::strlen(enable_str) - 1); } #endif // defined(__linux__) diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 8dec6fc7..e1b9e639 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -577,19 +577,14 @@ bool FTermLinux::getUnicodeMap() if ( ret != 0 ) { - int count; + std::size_t count = screen_unicode_map.entry_ct; - if ( errno != ENOMEM || screen_unicode_map.entry_ct == 0 ) - return false; - - count = screen_unicode_map.entry_ct; - - if ( count <= 0 ) + if ( errno != ENOMEM || count == 0 ) return false; try { - screen_unicode_map.entries = new struct unipair[std::size_t(count)](); + screen_unicode_map.entries = new struct unipair[count](); } catch (const std::bad_alloc& ex) { diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index 9e4fc746..44c68172 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -63,11 +63,11 @@ class FPoint FPoint& operator += (const FPoint&); FPoint& operator -= (const FPoint&); - friend inline bool operator == (const FPoint&, const FPoint&); - friend inline bool operator != (const FPoint&, const FPoint&); - friend inline FPoint operator + (const FPoint&, const FPoint&); - friend inline FPoint operator - (const FPoint&, const FPoint&); - friend inline FPoint operator - (const FPoint&); + friend bool operator == (const FPoint&, const FPoint&); + friend bool operator != (const FPoint&, const FPoint&); + friend FPoint operator + (const FPoint&, const FPoint&); + friend FPoint operator - (const FPoint&, const FPoint&); + friend FPoint operator - (const FPoint&); friend std::ostream& operator << (std::ostream&, const FPoint&); friend std::istream& operator >> (std::istream&, FPoint&); diff --git a/test/fkeyboard-test.cpp b/test/fkeyboard-test.cpp index 7d5c5099..e919c384 100644 --- a/test/fkeyboard-test.cpp +++ b/test/fkeyboard-test.cpp @@ -2763,7 +2763,7 @@ void FKeyboardTest::utf8Test() keyboard->disableUTF8(); input("\360\220\200\200"); processInput(); - CPPUNIT_ASSERT ( key_released == 0200 ); + CPPUNIT_ASSERT ( key_released == 128 ); clear(); } diff --git a/test/fobject-test.cpp b/test/fobject-test.cpp index c7543b71..6dac3f6c 100644 --- a/test/fobject-test.cpp +++ b/test/fobject-test.cpp @@ -131,6 +131,7 @@ void FObjectTest::classNameTest() void FObjectTest::noArgumentTest() { finalcut::FObject o1; + finalcut::FObject o2; CPPUNIT_ASSERT ( ! o1.hasParent() ); CPPUNIT_ASSERT ( o1.getParent() == 0 ); CPPUNIT_ASSERT ( ! o1.hasChildren() ); @@ -142,8 +143,8 @@ void FObjectTest::noArgumentTest() CPPUNIT_ASSERT ( children_list.begin() == o1.end() ); CPPUNIT_ASSERT ( children_list.end() == o1.begin() ); CPPUNIT_ASSERT ( children_list.end() == o1.end() ); - CPPUNIT_ASSERT ( ! o1.isChild(&o1) ); - CPPUNIT_ASSERT ( ! o1.isDirectChild(&o1) ); + CPPUNIT_ASSERT ( ! o1.isChild(&o2) ); + CPPUNIT_ASSERT ( ! o1.isDirectChild(&o2) ); CPPUNIT_ASSERT ( ! o1.isWidget() ); CPPUNIT_ASSERT ( o1.isInstanceOf("FObject") ); CPPUNIT_ASSERT ( ! o1.isTimerInUpdating() ); @@ -176,6 +177,7 @@ void FObjectTest::childObjectTest() finalcut::FObject* c4 = new finalcut::FObject(&obj); finalcut::FObject* c5 = new finalcut::FObject(c1); finalcut::FObject* c6 = new finalcut::FObject(c5); + finalcut::FObject* c7 = new finalcut::FObject(); CPPUNIT_ASSERT ( obj.hasChildren() ); CPPUNIT_ASSERT ( obj.getChild(0) == 0 ); @@ -213,7 +215,7 @@ void FObjectTest::childObjectTest() CPPUNIT_ASSERT ( children_list2.begin() != c1->end() ); CPPUNIT_ASSERT ( children_list2.end() != c1->begin() ); CPPUNIT_ASSERT ( children_list2.end() == c1->end() ); - CPPUNIT_ASSERT ( ! c1->isDirectChild(c1) ); + CPPUNIT_ASSERT ( ! c1->isDirectChild(c7) ); CPPUNIT_ASSERT ( ! c1->isWidget() ); CPPUNIT_ASSERT ( c1->isInstanceOf("FObject") ); CPPUNIT_ASSERT ( ! c1->isTimerInUpdating() ); diff --git a/test/fpoint-test.cpp b/test/fpoint-test.cpp index e0cfe327..771031ea 100644 --- a/test/fpoint-test.cpp +++ b/test/fpoint-test.cpp @@ -219,8 +219,10 @@ void FPointTest::equalTest() CPPUNIT_ASSERT ( p1 == p2 ); CPPUNIT_ASSERT ( finalcut::FPoint(1,2) == p2 ); CPPUNIT_ASSERT ( p1 == finalcut::FPoint(1,2) ); - CPPUNIT_ASSERT ( finalcut::FPoint() == finalcut::FPoint() ); - CPPUNIT_ASSERT ( finalcut::FPoint() == -finalcut::FPoint() ); + const finalcut::FPoint p3; + const finalcut::FPoint p4; + CPPUNIT_ASSERT ( p3 == p4 ); + CPPUNIT_ASSERT ( p3 == -p4 ); } //---------------------------------------------------------------------- diff --git a/test/frect-test.cpp b/test/frect-test.cpp index 913eb3c3..fe3c024d 100644 --- a/test/frect-test.cpp +++ b/test/frect-test.cpp @@ -299,7 +299,9 @@ void FRectTest::equalTest() CPPUNIT_ASSERT ( r1 == r2 ); CPPUNIT_ASSERT ( finalcut::FRect(1, 2, 10, 20) == r2 ); CPPUNIT_ASSERT ( r1 == finalcut::FRect(1, 2, 10, 20) ); - CPPUNIT_ASSERT ( finalcut::FRect() == finalcut::FRect() ); + const finalcut::FRect r3; + const finalcut::FRect r4; + CPPUNIT_ASSERT ( r3 == r4 ); } //----------------------------------------------------------------------