Fixed some minor bugs

This commit is contained in:
Markus Gans 2020-08-12 22:28:02 +02:00
parent 6fef7a43a5
commit b54d1c2f38
22 changed files with 74 additions and 116 deletions

View File

@ -26,13 +26,13 @@ using finalcut::FPoint;
using finalcut::FSize; using finalcut::FSize;
// function prototype // function prototype
void cb_quit (finalcut::FApplication&); void cb_quit (const finalcut::FApplication&);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// callback function // callback function
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void cb_quit (finalcut::FApplication& app) void cb_quit (const finalcut::FApplication& app)
{ {
app.quit(); app.quit();
} }

View File

@ -105,7 +105,7 @@ int main (int argc, char* argv[])
// Callback lambda expressions // Callback lambda expressions
auto cb_exit = \ auto cb_exit = \
[] (finalcut::FApplication& a) [] (const finalcut::FApplication& a)
{ {
a.quit(); a.quit();
}; };

View File

@ -26,20 +26,21 @@ using finalcut::FPoint;
using finalcut::FSize; using finalcut::FSize;
// function prototypes // function prototypes
void cb_quit (finalcut::FApplication&); void cb_quit (const finalcut::FApplication&);
void cb_publish (finalcut::FCheckBox&, finalcut::FCheckBox&); void cb_publish (const finalcut::FCheckBox&, finalcut::FCheckBox&);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// callback functions // callback functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void cb_quit (finalcut::FApplication& app) void cb_quit (const finalcut::FApplication& app)
{ {
app.quit(); app.quit();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void cb_publish (finalcut::FCheckBox& cbox1, finalcut::FCheckBox& cbox2) void cb_publish ( const finalcut::FCheckBox& cbox1
, finalcut::FCheckBox& cbox2 )
{ {
if ( cbox1.isChecked() ) if ( cbox1.isChecked() )
cbox2.setEnable(); cbox2.setEnable();

View File

@ -61,7 +61,7 @@ class Menu final : public finalcut::FDialog
void onClose (finalcut::FCloseEvent*) override; void onClose (finalcut::FCloseEvent*) override;
// Callback method // Callback method
void cb_message (finalcut::FMenuItem*); void cb_message (const finalcut::FMenuItem*);
// Data members // Data members
finalcut::FString line{13, fc::BoxDrawingsHorizontal}; finalcut::FString line{13, fc::BoxDrawingsHorizontal};
@ -305,7 +305,7 @@ void Menu::onClose (finalcut::FCloseEvent* ev)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Menu::cb_message (finalcut::FMenuItem* menuitem) void Menu::cb_message (const finalcut::FMenuItem* menuitem)
{ {
auto text = menuitem->getText(); auto text = menuitem->getText();
text = text.replace('&', ""); text = text.replace('&', "");

View File

@ -217,12 +217,12 @@ int main (int argc, char* argv[])
// Force terminal initialization without calling show() // Force terminal initialization without calling show()
term_app.initTerminal(); term_app.initTerminal();
// Pointer to the global virtual terminal object
app = &term_app;
if ( finalcut::FApplication::isQuit() ) if ( finalcut::FApplication::isQuit() )
return 0; return 0;
// Pointer to the global virtual terminal object
app = &term_app;
// Get screen dimension // Get screen dimension
int xmax = int(term_app.getDesktopWidth() - 1); int xmax = int(term_app.getDesktopWidth() - 1);
int ymax = int(term_app.getDesktopHeight() - 1); int ymax = int(term_app.getDesktopHeight() - 1);

View File

@ -304,12 +304,13 @@ class MyDialog final : public finalcut::FDialog
void cb_switchTheme (const finalcut::FCheckMenuItem*) const; void cb_switchTheme (const finalcut::FCheckMenuItem*) const;
void cb_input2buttonText ( finalcut::FButton& void cb_input2buttonText ( finalcut::FButton&
, const finalcut::FLineEdit& ) const; , const finalcut::FLineEdit& ) const;
void cb_setTitlebar (finalcut::FLineEdit&); void cb_setTitlebar (const finalcut::FLineEdit&);
void cb_showProgressBar(); void cb_showProgressBar();
void cb_updateNumber (finalcut::FListBox&, finalcut::FLabel&) const; void cb_updateNumber ( const finalcut::FListBox&
void cb_activateButton ( finalcut::FRadioButton& , finalcut::FLabel& ) const;
void cb_activateButton ( const finalcut::FRadioButton&
, finalcut::FButton& ) const; , finalcut::FButton& ) const;
void cb_view (finalcut::FMenuItem*); void cb_view (const finalcut::FMenuItem*);
void cb_setInput (finalcut::FListBox&, finalcut::FLineEdit&) const; void cb_setInput (finalcut::FListBox&, finalcut::FLineEdit&) const;
// Data members // Data members
@ -951,7 +952,7 @@ void MyDialog::cb_input2buttonText ( finalcut::FButton& button
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_setTitlebar (finalcut::FLineEdit& lineedit) void MyDialog::cb_setTitlebar (const finalcut::FLineEdit& lineedit)
{ {
finalcut::FString title{}; finalcut::FString title{};
lineedit >> title; lineedit >> title;
@ -968,7 +969,7 @@ void MyDialog::cb_showProgressBar()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_updateNumber ( finalcut::FListBox& list void MyDialog::cb_updateNumber ( const finalcut::FListBox& list
, finalcut::FLabel& num) const , finalcut::FLabel& num) const
{ {
const auto count = list.getCount(); const auto count = list.getCount();
@ -984,7 +985,7 @@ void MyDialog::cb_updateNumber ( finalcut::FListBox& list
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_activateButton ( finalcut::FRadioButton& rb void MyDialog::cb_activateButton ( const finalcut::FRadioButton& rb
, finalcut::FButton& button) const , finalcut::FButton& button) const
{ {
if ( rb.isChecked() ) if ( rb.isChecked() )
@ -996,7 +997,7 @@ void MyDialog::cb_activateButton ( finalcut::FRadioButton& rb
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_view (finalcut::FMenuItem* item) void MyDialog::cb_view (const finalcut::FMenuItem* item)
{ {
finalcut::FString file{}; finalcut::FString file{};

View File

@ -542,7 +542,7 @@ void FButtonGroup::directFocus()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::cb_buttonToggled (FToggleButton* button) const void FButtonGroup::cb_buttonToggled (const FToggleButton* button) const
{ {
if ( (button && ! button->isChecked()) || buttonlist.empty() ) if ( (button && ! button->isChecked()) || buttonlist.empty() )
return; return;

View File

@ -201,7 +201,7 @@ void FFileDialog::setPath (const FString& dir)
return; return;
} }
if ( fsystem->realpath(dir.c_str(), resolved_path) != nullptr ) if ( fsystem && fsystem->realpath(dir.c_str(), resolved_path) != nullptr )
r_dir.setString(resolved_path); r_dir.setString(resolved_path);
else else
r_dir.setString(dir); r_dir.setString(dir);

View File

@ -339,7 +339,7 @@ void FMenu::cb_menuitemDisabled()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::cb_menuitemToggled (FMenuItem* m_item) const void FMenu::cb_menuitemToggled (const FMenuItem* m_item) const
{ {
if ( ! (has_checkable_items && m_item && m_item->isChecked()) ) if ( ! (has_checkable_items && m_item && m_item->isChecked()) )
return; return;

View File

@ -228,7 +228,7 @@ void FMenuBar::onAccel (FAccelEvent* ev)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuBar::cb_itemDeactivated (FMenuItem* menuitem) const void FMenuBar::cb_itemDeactivated (const FMenuItem* menuitem) const
{ {
if ( ! menuitem->hasMenu() ) if ( ! menuitem->hasMenu() )
return; return;

View File

@ -108,7 +108,7 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
} }
else else
{ {
for (uInt n{0}; n < num_buttons; n++) for (uInt n{0}; n < num_buttons && button[n]; n++)
delete button[n]; delete button[n];
if ( mbox.getParentWidget() ) if ( mbox.getParentWidget() )
@ -138,7 +138,7 @@ void FMessageBox::setHeadline (const FString& headline)
headline_text.setString(headline); headline_text.setString(headline);
setHeight(getHeight() + 2, true); setHeight(getHeight() + 2, true);
for (uInt n{0}; n < num_buttons; n++) for (uInt n{0}; n < num_buttons && button[n]; n++)
button[n]->setY (int(getHeight()) - 4, false); button[n]->setY (int(getHeight()) - 4, false);
const std::size_t column_width = getColumnWidth(headline_text); const std::size_t column_width = getColumnWidth(headline_text);
@ -268,7 +268,7 @@ inline void FMessageBox::allocation()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMessageBox::deallocation() inline void FMessageBox::deallocation()
{ {
for (uInt n{0}; n < num_buttons; n++) for (uInt n{0}; n < num_buttons && button[n]; n++)
delete button[n]; delete button[n];
} }
@ -388,7 +388,7 @@ void FMessageBox::resizeButtons() const
std::size_t len[3]{}; std::size_t len[3]{};
std::size_t max_size{}; std::size_t max_size{};
for (std::size_t n{0}; n < num_buttons; n++) for (std::size_t n{0}; n < num_buttons && button[n]; n++)
{ {
len[n] = button[n]->getText().getLength(); len[n] = button[n]->getText().getLength();
@ -410,7 +410,7 @@ void FMessageBox::resizeButtons() const
if ( max_size < 7 ) if ( max_size < 7 )
max_size = 7; max_size = 7;
for (std::size_t n{0}; n < num_buttons; n++) for (std::size_t n{0}; n < num_buttons && button[n]; n++)
button[n]->setWidth(max_size + 3, false); button[n]->setWidth(max_size + 3, false);
} }
@ -420,7 +420,7 @@ void FMessageBox::adjustButtons()
static constexpr std::size_t gap = 4; static constexpr std::size_t gap = 4;
std::size_t btn_width{0}; std::size_t btn_width{0};
for (std::size_t n{0}; n < num_buttons; n++) for (std::size_t n{0}; n < num_buttons && button[n]; n++)
{ {
if ( n == num_buttons - 1 ) if ( n == num_buttons - 1 )
btn_width += button[n]->getWidth(); btn_width += button[n]->getWidth();
@ -439,7 +439,7 @@ void FMessageBox::adjustButtons()
const int btn_x = int((getWidth() - btn_width) / 2); const int btn_x = int((getWidth() - btn_width) / 2);
for (std::size_t n{0}; n < num_buttons; n++) for (std::size_t n{0}; n < num_buttons && button[n]; n++)
{ {
if ( n == 0 ) if ( n == 0 )
button[n]->setX(btn_x); button[n]->setX(btn_x);

View File

@ -488,7 +488,7 @@ void FStatusBar::onMouseMove (FMouseEvent* ev)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStatusBar::cb_statuskey_activated (FStatusKey* statuskey) void FStatusBar::cb_statuskey_activated (const FStatusKey* statuskey)
{ {
if ( ! statuskey ) if ( ! statuskey )
return; return;

View File

@ -387,7 +387,10 @@ std::size_t FString::getUTF8length() const
const char* s = c_str(); const char* s = c_str();
while ( *s ) while ( *s )
len += std::size_t((*s++ & 0xc0) != 0x80); {
len += std::size_t((*s & 0xc0) != 0x80);
s++;
}
return len; return len;
} }
@ -1449,29 +1452,26 @@ inline const char* FString::_to_cstring (const wchar_t s[]) const
if ( c_string ) if ( c_string )
delete[](c_string); delete[](c_string);
const int size = int(std::wcslen(s)) + 1;
const int dest_size = size * int(CHAR_SIZE);
const wchar_t* src = s; const wchar_t* src = s;
std::mbstate_t state{}; auto state = std::mbstate_t();
std::memset (&state, '\0', sizeof(mbstate_t)); auto size = std::wcsrtombs(nullptr, &src, 0, &state) + 1;
try try
{ {
c_string = new char[std::size_t(dest_size)](); c_string = new char[size]();
// pre-initialiaze the whole string with '\0' // pre-initialiaze the whole string with '\0'
std::memset (c_string, '\0', std::size_t(dest_size)); std::memset (c_string, '\0', size);
} }
catch (const std::bad_alloc&) catch (const std::bad_alloc&)
{ {
badAllocOutput ("char[std::size_t(dest_size)]"); badAllocOutput ("char[size]");
return nullptr; return nullptr;
} }
const int mblength = \ const auto mblength = std::wcsrtombs (c_string, &src, size, &state);
int(std::wcsrtombs (c_string, &src, std::size_t(dest_size), &state));
if ( mblength == -1 && errno != EILSEQ ) if ( mblength == static_cast<std::size_t>(-1) && errno != EILSEQ )
{ {
delete[](c_string); delete[](c_string);
c_string = nullptr; c_string = nullptr;
@ -1501,29 +1501,26 @@ inline const wchar_t* FString::_to_wcstring (const char s[]) const
} }
} }
const int size = int(std::strlen(s)) + 1;
const int dest_size = size * int(CHAR_SIZE);
const char* src = s; const char* src = s;
wchar_t* dest{}; wchar_t* dest{};
std::mbstate_t state{}; auto state = std::mbstate_t();
std::memset (&state, '\0', sizeof(mbstate_t)); auto size = std::mbsrtowcs(nullptr, &src, 0, &state) + 1;
try try
{ {
dest = new wchar_t[std::size_t(size)](); dest = new wchar_t[size]();
// pre-initialiaze the whole string with '\0' // pre-initialiaze the whole string with '\0'
std::wmemset (dest, L'\0', std::size_t(size)); std::wmemset (dest, L'\0', size);
} }
catch (const std::bad_alloc&) catch (const std::bad_alloc&)
{ {
badAllocOutput ("wchar_t[std::size_t(size)]"); badAllocOutput ("wchar_t[size]");
return nullptr; return nullptr;
} }
const int wclength = \ const auto wclength = std::mbsrtowcs (dest, &src, size, &state);
int(std::mbsrtowcs (dest, &src, std::size_t(dest_size), &state));
if ( wclength == -1 ) if ( wclength == static_cast<std::size_t>(-1) )
{ {
if ( src != s ) if ( src != s )
return dest; return dest;

View File

@ -139,7 +139,7 @@ class FApplication : public FWidget
static void closeConfirmationDialog (FWidget*, FCloseEvent*); static void closeConfirmationDialog (FWidget*, FCloseEvent*);
// Callback method // Callback method
void cb_exitApp (FWidget*); void cb_exitApp (FWidget*) const;
protected: protected:
virtual void processExternalUserEvent(); virtual void processExternalUserEvent();
@ -235,7 +235,7 @@ inline char** FApplication::getArgv() const
{ return app_argv; } { return app_argv; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FApplication::cb_exitApp (FWidget* w) inline void FApplication::cb_exitApp (FWidget* w) const
{ w->close(); } { w->close(); }
} // namespace finalcut } // namespace finalcut

View File

@ -130,7 +130,7 @@ class FButtonGroup : public FScrollView
void directFocus(); void directFocus();
// Callback method // Callback method
void cb_buttonToggled (FToggleButton*) const; void cb_buttonToggled (const FToggleButton*) const;
// Data members // Data members
FString text{}; FString text{};

View File

@ -62,43 +62,6 @@ struct FCallbackData
, cb_function(c) , cb_function(c)
{ } { }
FCallbackData (const FCallbackData& c) // copy constructor
: cb_signal(c.cb_signal)
, cb_instance(c.cb_instance)
, cb_function_ptr(c.cb_function_ptr)
, cb_function(c.cb_function)
{ }
FCallbackData (FCallbackData&& c) noexcept // move constructor
: cb_signal(std::move(c.cb_signal))
, cb_instance(std::move(c.cb_instance))
, cb_function_ptr(std::move(c.cb_function_ptr))
, cb_function(std::move(c.cb_function))
{ }
// Destructor
~FCallbackData()
{ }
// Overloaded operators
FCallbackData& operator = (const FCallbackData& c)
{
cb_signal = c.cb_signal;
cb_instance = c.cb_instance;
cb_function_ptr = c.cb_function_ptr;
cb_function = c.cb_function;
return *this;
}
FCallbackData& operator = (FCallbackData&& c) noexcept
{
cb_signal = std::move(c.cb_signal);
cb_instance = std::move(c.cb_instance);
cb_function_ptr = std::move(c.cb_function_ptr);
cb_function = std::move(c.cb_function);
return *this;
}
// Data members // Data members
FString cb_signal{}; FString cb_signal{};
FWidget* cb_instance{}; FWidget* cb_instance{};
@ -132,7 +95,7 @@ class FCallback
return "FCallback"; return "FCallback";
} }
std::size_t getCallbackCount() std::size_t getCallbackCount() const
{ {
return callback_objects.size(); return callback_objects.size();
} }
@ -235,10 +198,9 @@ class FCallback
// Add a function as callback // Add a function as callback
auto ptr = reinterpret_cast<void*>(&cb_function); auto ptr = reinterpret_cast<void*>(&cb_function);
auto fn = std::bind ( std::forward<Function>(cb_function) auto fn = std::bind (cb_function, std::forward<Args>(args)...);
, std::forward<Args>(args)... );
FCallbackData obj{ cb_signal, nullptr, ptr, fn }; FCallbackData obj{ cb_signal, nullptr, ptr, fn };
callback_objects.push_back(obj);; callback_objects.push_back(obj);
} }
template<typename Function template<typename Function
@ -278,8 +240,7 @@ class FCallback
{ {
// Add a non-union class type as callback // Add a non-union class type as callback
auto fn = std::bind ( std::forward<Function>(cb_function) auto fn = std::bind (cb_function, std::forward<Args>(args)...);
, std::forward<Args>(args)... );
FCallbackData obj{ cb_signal, nullptr, nullptr, fn }; FCallbackData obj{ cb_signal, nullptr, nullptr, fn };
callback_objects.push_back(obj); callback_objects.push_back(obj);
} }
@ -419,7 +380,7 @@ class FCallback
} }
void emitCallback (const FString& emit_signal) void emitCallback (const FString& emit_signal) const
{ {
// Initiate callback for the given signal // Initiate callback for the given signal

View File

@ -127,7 +127,7 @@ class FMenu : public FWindow, public FMenuList
// Callback method // Callback method
void cb_menuitemEnabled(); void cb_menuitemEnabled();
void cb_menuitemDisabled(); void cb_menuitemDisabled();
void cb_menuitemToggled (FMenuItem*) const; void cb_menuitemToggled (const FMenuItem*) const;
private: private:
// Constants // Constants

View File

@ -99,7 +99,7 @@ class FMenuBar : public FWindow, public FMenuList
void onAccel (FAccelEvent*) override; void onAccel (FAccelEvent*) override;
// Callback methods // Callback methods
void cb_itemDeactivated (FMenuItem*) const; void cb_itemDeactivated (const FMenuItem*) const;
private: private:
// Constants // Constants

View File

@ -227,7 +227,7 @@ class FStatusBar : public FWindow
void onMouseMove (FMouseEvent*) override; void onMouseMove (FMouseEvent*) override;
// Callback method // Callback method
void cb_statuskey_activated (FStatusKey*); void cb_statuskey_activated (const FStatusKey*);
private: private:
// Typedef // Typedef

View File

@ -245,7 +245,6 @@ class FString
// Constants // Constants
static constexpr uInt FWDBUFFER = 15; static constexpr uInt FWDBUFFER = 15;
static constexpr uInt INPBUFFER = 200; static constexpr uInt INPBUFFER = 200;
static constexpr uInt CHAR_SIZE = sizeof(wchar_t); // bytes per character
// Methods // Methods
void _initLength (std::size_t); void _initLength (std::size_t);

View File

@ -317,10 +317,10 @@ class FWidget : public FVTerm, public FObject
virtual bool close(); virtual bool close();
void clearStatusbarMessage(); void clearStatusbarMessage();
template<typename... Args> template<typename... Args>
void addCallback (FString&&, Args&&...); void addCallback (const FString&, Args&&...);
template<typename... Args> template<typename... Args>
void delCallback (Args&&...); void delCallback (Args&&...);
void emitCallback (FString&&); void emitCallback (const FString&);
void addAccelerator (FKey); void addAccelerator (FKey);
virtual void addAccelerator (FKey, FWidget*); virtual void addAccelerator (FKey, FWidget*);
void delAccelerator (); void delAccelerator ();
@ -984,10 +984,9 @@ inline void FWidget::clearStatusbarMessage()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template<typename... Args> template<typename... Args>
inline void FWidget::addCallback (FString&& cb_signal, Args&&... args) inline void FWidget::addCallback (const FString& cb_signal, Args&&... args)
{ {
callback_impl.addCallback ( std::forward<FString>(cb_signal) callback_impl.addCallback (cb_signal, std::forward<Args>(args)...);
, std::forward<Args>(args)... );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -998,9 +997,9 @@ inline void FWidget::delCallback (Args&&... args)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::emitCallback (FString&& emit_signal) inline void FWidget::emitCallback (const FString& emit_signal)
{ {
callback_impl.emitCallback(std::forward<FString>(emit_signal)); callback_impl.emitCallback(emit_signal);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -38,9 +38,9 @@ class Widget
{ {
public: public:
template<typename... Args> template<typename... Args>
void addCallback (finalcut::FString&& cb_signal, Args&&... args) void addCallback (const finalcut::FString& cb_signal, Args&&... args)
{ {
cb.addCallback(std::forward<finalcut::FString>(cb_signal), std::forward<Args>(args)...); cb.addCallback (cb_signal, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
@ -49,9 +49,9 @@ class Widget
cb.delCallback (std::forward<Args>(args)...); cb.delCallback (std::forward<Args>(args)...);
} }
void emitCallback (finalcut::FString&& emit_signal) void emitCallback (const finalcut::FString& emit_signal)
{ {
cb.emitCallback(std::forward<finalcut::FString>(emit_signal)); cb.emitCallback (emit_signal);
} }
private: private: