Small improvements

This commit is contained in:
Markus Gans 2020-10-14 17:31:52 +02:00
parent a14c45d8c7
commit 2c9778698e
14 changed files with 57 additions and 63 deletions

View File

@ -370,7 +370,7 @@ void stringConcatenationExample()
// Test: concatenate a FString and a wide string (operator +) // Test: concatenate a FString and a wide string (operator +)
const finalcut::FString& add3 = finalcut::FString("FString + ") const finalcut::FString& add3 = finalcut::FString("FString + ")
+ const_cast<wchar_t*>(L"wchar_t*"); + L"wchar_t*";
std::cout << " add: " << add3 << std::endl; std::cout << " add: " << add3 << std::endl;
// Test: concatenate a FString and a c++ string (operator +) // Test: concatenate a FString and a c++ string (operator +)
@ -402,7 +402,7 @@ void stringConcatenationExample()
std::cout << " add: " << add9 << std::endl; std::cout << " add: " << add9 << std::endl;
// Test: concatenate a c-string and a FString (operator +) // Test: concatenate a c-string and a FString (operator +)
const finalcut::FString& add10 = const_cast<char*>("char*") const finalcut::FString& add10 = "char*"
+ finalcut::FString(" + FString"); + finalcut::FString(" + FString");
std::cout << " add: " << add10 << std::endl; std::cout << " add: " << add10 << std::endl;
@ -412,7 +412,7 @@ void stringConcatenationExample()
std::cout << " add: " << add11 << std::endl; std::cout << " add: " << add11 << std::endl;
// Test: concatenate a wide string and a FString (operator +) // Test: concatenate a wide string and a FString (operator +)
const finalcut::FString& add12 = const_cast<wchar_t*>(L"wchar_t*") const finalcut::FString& add12 = L"wchar_t*"
+ finalcut::FString(" + FString"); + finalcut::FString(" + FString");
std::cout << " add: " << add12 << std::endl; std::cout << " add: " << add12 << std::endl;

View File

@ -300,7 +300,7 @@ class MyDialog final : public finalcut::FDialog
void cb_copyClipboard(); void cb_copyClipboard();
void cb_pasteClipboard(); void cb_pasteClipboard();
void cb_clearInput(); void cb_clearInput();
void cb_switchTheme (const finalcut::FCheckMenuItem*) const; void cb_switchTheme (const finalcut::FCheckMenuItem*);
void cb_input2buttonText ( finalcut::FButton& void cb_input2buttonText ( finalcut::FButton&
, const finalcut::FLineEdit& ) const; , const finalcut::FLineEdit& ) const;
void cb_setTitlebar (const finalcut::FLineEdit&); void cb_setTitlebar (const finalcut::FLineEdit&);
@ -936,7 +936,7 @@ void MyDialog::cb_clearInput()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_switchTheme (const finalcut::FCheckMenuItem* check_menu) const void MyDialog::cb_switchTheme (const finalcut::FCheckMenuItem* check_menu)
{ {
if ( check_menu->isChecked() ) if ( check_menu->isChecked() )
finalcut::FApplication::setDarkTheme(); finalcut::FApplication::setDarkTheme();

View File

@ -762,7 +762,7 @@ inline bool FApplication::sendKeyUpEvent (FWidget* widget) const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FApplication::sendKeyboardAccelerator() const inline void FApplication::sendKeyboardAccelerator()
{ {
if ( FWidget::getOpenMenu() ) if ( FWidget::getOpenMenu() )
return; return;
@ -782,7 +782,7 @@ inline void FApplication::sendKeyboardAccelerator() const
// Global keyboard accelerator // Global keyboard accelerator
if ( ! accpt ) if ( ! accpt )
{ {
auto root_widget = static_cast<const FWidget*>(getRootWidget()); auto root_widget = getRootWidget();
if ( root_widget ) if ( root_widget )
processAccelerator (root_widget); processAccelerator (root_widget);
@ -1319,17 +1319,17 @@ void FApplication::performTimerAction (FObject* receiver, FEvent* event)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FApplication::isEventProcessable ( const FObject* receiver bool FApplication::isEventProcessable ( FObject* receiver
, const FEvent* event ) , const FEvent* event )
{ {
if ( ! receiver->isWidget() ) // No restrictions for non-widgets if ( ! receiver->isWidget() ) // No restrictions for non-widgets
return true; return true;
const auto widget = static_cast<const FWidget*>(receiver); auto widget = static_cast<FWidget*>(receiver);
if ( getModalDialogCounter() > 0 ) if ( getModalDialogCounter() > 0 )
{ {
const FWidget* window; FWidget* window;
if ( widget->isWindowWidget() ) if ( widget->isWindowWidget() )
window = widget; window = widget;

View File

@ -2849,11 +2849,8 @@ void FListView::cb_vbarChange (const FWidget*)
break; break;
case FScrollbar::scrollJump: case FScrollbar::scrollJump:
{ scrollToY (vbar->getValue());
int value = vbar->getValue();
scrollToY (value);
break; break;
}
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
wheelUp (wheel_distance); wheelUp (wheel_distance);

View File

@ -694,9 +694,9 @@ void FScrollView::copy2area()
// private methods of FScrollView // private methods of FScrollView
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FPoint FScrollView::getViewportCursorPos() const inline FPoint FScrollView::getViewportCursorPos()
{ {
const auto& window = FWindow::getWindowWidget(this); auto window = FWindow::getWindowWidget(this);
if ( window ) if ( window )
{ {
@ -846,7 +846,7 @@ void FScrollView::setVerticalScrollBarVisibility() const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::setViewportCursor() const void FScrollView::setViewportCursor()
{ {
if ( ! isChild(getFocusWidget()) ) if ( ! isChild(getFocusWidget()) )
return; return;

View File

@ -128,10 +128,8 @@ FString::FString (fc::SpecialCharacter c)
{ {
if ( c ) if ( c )
{ {
wchar_t s[2]; std::array<wchar_t, 2> s{{ static_cast<wchar_t>(c), L'\0' }};
s[0] = static_cast<wchar_t>(c); _assign (s.data());
s[1] = L'\0';
_assign (s);
} }
} }
@ -140,10 +138,8 @@ FString::FString (const wchar_t c)
{ {
if ( c ) if ( c )
{ {
wchar_t s[2]; std::array<wchar_t, 2> s{{ c, L'\0' }};
s[0] = c; _assign (s.data());
s[1] = L'\0';
_assign (s);
} }
} }
@ -152,10 +148,8 @@ FString::FString (const char c)
{ {
if ( c ) if ( c )
{ {
wchar_t s[2]; std::array<wchar_t, 2> s{{ wchar_t(c & 0xff), L'\0' }};
s[0] = wchar_t(c & 0xff); _assign (s.data());
s[1] = L'\0';
_assign (s);
} }
} }
@ -403,7 +397,10 @@ char* FString::c_str()
if ( length > 0 ) if ( length > 0 )
return const_cast<char*>(_to_cstring(string)); return const_cast<char*>(_to_cstring(string));
else if ( string ) else if ( string )
return const_cast<char*>(""); {
static char empty_string[] = "";
return empty_string;
}
else else
return nullptr; return nullptr;
} }
@ -769,7 +766,7 @@ FString& FString::setString (const FString& s)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::setNumber (sInt64 num) FString& FString::setNumber (sInt64 num)
{ {
wchar_t buf[30]{}; std::array<wchar_t, 30> buf{};
wchar_t* s = &buf[29]; // Pointer to the last character wchar_t* s = &buf[29]; // Pointer to the last character
auto abs_num = static_cast<uInt64>(num); auto abs_num = static_cast<uInt64>(num);
@ -813,7 +810,7 @@ FString& FString::setNumber (uInt64 num)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::setNumber (lDouble f_num, int precision) FString& FString::setNumber (lDouble f_num, int precision)
{ {
wchar_t format[20]{}; // = "%.<precision>Lg" std::array<wchar_t, 20> format{}; // = "%.<precision>Lg"
wchar_t* s = &format[0]; wchar_t* s = &format[0];
*s++ = L'%'; *s++ = L'%';
*s++ = L'.'; *s++ = L'.';
@ -838,14 +835,14 @@ FString& FString::setNumber (lDouble f_num, int precision)
*s++ = L'g'; *s++ = L'g';
*s = L'\0'; *s = L'\0';
return sprintf(format, f_num); return sprintf(format.data(), f_num);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::setFormatedNumber (sInt64 num, char separator) FString& FString::setFormatedNumber (sInt64 num, char separator)
{ {
int n{0}; int n{0};
wchar_t buf[30]{}; std::array<wchar_t, 30> buf{};
wchar_t* s = &buf[29]; // Pointer to the last character wchar_t* s = &buf[29]; // Pointer to the last character
auto abs_num = static_cast<uInt64>(num); auto abs_num = static_cast<uInt64>(num);
@ -1515,7 +1512,7 @@ inline const wchar_t* FString::_extractToken ( wchar_t* rest[]
if ( ! token[0] ) if ( ! token[0] )
return nullptr; return nullptr;
*rest = std::wcspbrk(token, delim); *rest = std::wcspbrk(std::move(token), delim);
if ( *rest ) if ( *rest )
*(*rest)++ = '\0'; *(*rest)++ = '\0';
@ -1555,9 +1552,9 @@ std::ostream& operator << (std::ostream& outstr, const FString& s)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FString& s) std::istream& operator >> (std::istream& instr, FString& s)
{ {
char buf[FString::INPBUFFER + 1]{}; std::array<char, FString::INPBUFFER + 1> buf{};
instr.getline (buf, FString::INPBUFFER); instr.getline (buf.data(), FString::INPBUFFER);
const wchar_t* wc_str = s._to_wcstring(buf); const wchar_t* wc_str = s._to_wcstring(buf.data());
if ( wc_str ) if ( wc_str )
{ {
@ -1589,9 +1586,9 @@ std::wostream& operator << (std::wostream& outstr, const FString& s)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::wistream& operator >> (std::wistream& instr, FString& s) std::wistream& operator >> (std::wistream& instr, FString& s)
{ {
wchar_t buf[FString::INPBUFFER + 1]{}; std::array<wchar_t, FString::INPBUFFER + 1> buf{};
instr.getline (buf, FString::INPBUFFER); instr.getline (buf.data(), FString::INPBUFFER);
s._assign (buf); s._assign (buf.data());
return instr; return instr;
} }

View File

@ -211,7 +211,7 @@ bool FTermDetection::getTTYtype()
term_basename++; term_basename++;
std::FILE* fp{}; std::FILE* fp{};
char str[BUFSIZ]{}; std::array<char, BUFSIZ> str{};
if ( ! fsystem ) if ( ! fsystem )
return false; return false;
@ -220,11 +220,11 @@ bool FTermDetection::getTTYtype()
return false; return false;
// Read and parse the file // Read and parse the file
while ( fgets(str, sizeof(str) - 1, fp) != nullptr ) while ( fgets(str.data(), str.size() - 1, fp) != nullptr )
{ {
const char* type{nullptr}; // nullptr == not found const char* type{nullptr}; // nullptr == not found
const char* name{nullptr}; const char* name{nullptr};
char* p = str; char* p = str.data();
while ( *p ) while ( *p )
{ {
@ -232,7 +232,7 @@ bool FTermDetection::getTTYtype()
*p = '\0'; *p = '\0';
else if ( type == nullptr ) else if ( type == nullptr )
type = p; type = p;
else if ( name == nullptr && p != str && p[-1] == '\0' ) else if ( name == nullptr && p != str.data() && p[-1] == '\0' )
name = p; name = p;
p++; p++;

View File

@ -141,9 +141,9 @@ FWidget::~FWidget() // destructor
// public methods of FWidget // public methods of FWidget
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWidget* FWidget::getRootWidget() const FWidget* FWidget::getRootWidget()
{ {
auto obj = const_cast<FWidget*>(this); FWidget* obj = this;
auto p_obj = getParentWidget(); auto p_obj = getParentWidget();
while ( ! obj->isRootWidget() && p_obj ) while ( ! obj->isRootWidget() && p_obj )
@ -1322,7 +1322,7 @@ void FWidget::adjustSize()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::adjustSizeGlobal() const void FWidget::adjustSizeGlobal()
{ {
if ( ! isRootWidget() ) if ( ! isRootWidget() )
{ {

View File

@ -483,7 +483,7 @@ void FWindow::delWindow (const FWidget* obj)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWindow* FWindow::getWindowWidget (const FWidget* obj) FWindow* FWindow::getWindowWidget (FWidget* obj)
{ {
// returns the window object to the given widget obj // returns the window object to the given widget obj
auto p_obj = obj->getParentWidget(); auto p_obj = obj->getParentWidget();
@ -495,17 +495,17 @@ FWindow* FWindow::getWindowWidget (const FWidget* obj)
} }
if ( obj->isWindowWidget() ) if ( obj->isWindowWidget() )
return const_cast<FWindow*>(reinterpret_cast<const FWindow*>(obj)); return static_cast<FWindow*>(obj);
else else
return nullptr; return nullptr;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FWindow::getWindowLayer (const FWidget* obj) int FWindow::getWindowLayer (FWidget* obj)
{ {
// returns the window layer from the widget obj // returns the window layer from the widget obj
const FWidget* window; FWidget* window;
if ( ! getWindowList() ) if ( ! getWindowList() )
return -1; return -1;

View File

@ -186,7 +186,7 @@ class FApplication : public FWidget
bool sendKeyDownEvent (FWidget*) const; bool sendKeyDownEvent (FWidget*) const;
bool sendKeyPressEvent (FWidget*) const; bool sendKeyPressEvent (FWidget*) const;
bool sendKeyUpEvent (FWidget*) const; bool sendKeyUpEvent (FWidget*) const;
void sendKeyboardAccelerator() const; void sendKeyboardAccelerator();
void processKeyboardEvent() const; void processKeyboardEvent() const;
bool processDialogSwitchAccelerator() const; bool processDialogSwitchAccelerator() const;
bool processAccelerator (const FWidget* const&) const; bool processAccelerator (const FWidget* const&) const;
@ -216,7 +216,7 @@ class FApplication : public FWidget
void processLogger() const; void processLogger() const;
bool processNextEvent(); bool processNextEvent();
void performTimerAction (FObject*, FEvent*) override; void performTimerAction (FObject*, FEvent*) override;
static bool isEventProcessable (const FObject*, const FEvent*); static bool isEventProcessable (FObject*, const FEvent*);
static bool isNextEventTimeout(); static bool isNextEventTimeout();
// Data members // Data members

View File

@ -157,7 +157,7 @@ class FScrollView : public FWidget
static constexpr int horizontal_border_spacing = 2; static constexpr int horizontal_border_spacing = 2;
// Accessors // Accessors
FPoint getViewportCursorPos() const; FPoint getViewportCursorPos();
// Methods // Methods
void init(); void init();
@ -169,7 +169,7 @@ class FScrollView : public FWidget
, Callback ); , Callback );
void setHorizontalScrollBarVisibility() const; void setHorizontalScrollBarVisibility() const;
void setVerticalScrollBarVisibility() const; void setVerticalScrollBarVisibility() const;
void setViewportCursor() const; void setViewportCursor();
// Callback methods // Callback methods
void cb_vbarChange (const FWidget*); void cb_vbarChange (const FWidget*);

View File

@ -83,7 +83,7 @@ class FStringStream : public std::wiostream
virtual FString getClassName() const; virtual FString getClassName() const;
void swap (FStringStream&) noexcept; void swap (FStringStream&) noexcept;
void clear(); void clear();
std::wstringbuf* rdbuf() const; std::wstringbuf* rdbuf();
FString str() const; FString str() const;
private: private:
@ -101,8 +101,8 @@ inline void FStringStream::clear()
{ buffer.str(L""); } { buffer.str(L""); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline std::wstringbuf* FStringStream::rdbuf() const inline std::wstringbuf* FStringStream::rdbuf()
{ return const_cast<std::wstringbuf*>(&buffer); } { return &buffer; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString FStringStream::str() const inline FString FStringStream::str() const

View File

@ -184,7 +184,7 @@ class FWidget : public FVTerm, public FObject
// Accessors // Accessors
FString getClassName() const override; FString getClassName() const override;
FWidget* getRootWidget() const; FWidget* getRootWidget();
FWidget* getParentWidget() const; FWidget* getParentWidget() const;
static FWidget*& getMainWidget(); static FWidget*& getMainWidget();
static FWidget*& getActiveWindow(); static FWidget*& getActiveWindow();
@ -364,7 +364,7 @@ class FWidget : public FVTerm, public FObject
void initTerminal() override; void initTerminal() override;
void initDesktop(); void initDesktop();
virtual void adjustSize(); virtual void adjustSize();
void adjustSizeGlobal() const; void adjustSizeGlobal();
void hideArea (const FSize&); void hideArea (const FSize&);
virtual bool focusNextChild(); // Change child... virtual bool focusNextChild(); // Change child...
virtual bool focusPrevChild(); // ...focus virtual bool focusPrevChild(); // ...focus

View File

@ -84,8 +84,8 @@ class FWindow : public FWidget
// Accessors // Accessors
FString getClassName() const override; FString getClassName() const override;
static FWindow* getWindowWidget (const FWidget*); static FWindow* getWindowWidget (FWidget*);
static int getWindowLayer (const FWidget*); static int getWindowLayer (FWidget*);
FWidget* getWindowFocusWidget() const; FWidget* getWindowFocusWidget() const;
// Mutators // Mutators