Changed more variables from int to std::size_t

This commit is contained in:
Markus Gans 2018-10-18 23:50:06 +02:00
parent 94e00051c5
commit 258380ae57
16 changed files with 114 additions and 107 deletions

View File

@ -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);
}

View File

@ -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 )

View File

@ -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++;

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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<FMenuItem*>::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 (' ');

View File

@ -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 )
{

View File

@ -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();

View File

@ -525,7 +525,7 @@ void FToggleButton::drawLabel()
wchar_t* dest = const_cast<wchar_t*>(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++;

View File

@ -131,7 +131,7 @@ class FButton : public FWidget
private:
// Constants
static const std::size_t NOT_FOUND = static_cast<std::size_t>(-1);
static const std::size_t NOT_SET = static_cast<std::size_t>(-1);
// Disable copy constructor
FButton (const FButton&);

View File

@ -126,7 +126,7 @@ class FButtonGroup : public FScrollView
private:
// Constants
static const std::size_t NOT_FOUND = static_cast<std::size_t>(-1);
static const std::size_t NOT_SET = static_cast<std::size_t>(-1);
// Disable copy constructor
FButtonGroup (const FButtonGroup&);

View File

@ -132,7 +132,7 @@ class FLabel : public FWidget
private:
// Constants
static const std::size_t NOT_FOUND = static_cast<std::size_t>(-1);
static const std::size_t NOT_SET = static_cast<std::size_t>(-1);
// Disable copy constructor
FLabel (const FLabel&);

View File

@ -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<std::size_t>(-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;
};

View File

@ -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<std::size_t>(-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*);

View File

@ -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<std::size_t>(-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; }
//----------------------------------------------------------------------

View File

@ -144,7 +144,7 @@ class FToggleButton : public FWidget
private:
// Constants
static const std::size_t NOT_FOUND = static_cast<std::size_t>(-1);
static const std::size_t NOT_SET = static_cast<std::size_t>(-1);
// Disable copy constructor
FToggleButton (const FToggleButton&);