Skip to content

Commit

Permalink
Many small code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Oct 14, 2023
1 parent e419874 commit a547d48
Show file tree
Hide file tree
Showing 66 changed files with 428 additions and 524 deletions.
2 changes: 1 addition & 1 deletion examples/listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void doubleToItem ( FListBoxItem& item
, std::size_t index )
{
using DblList = std::list<double>;
DblList& dbl_list = flistboxhelper::getContainer<DblList>(container);
const DblList& dbl_list = flistboxhelper::getContainer<DblList>(container);
auto iter = dbl_list.begin();
std::advance (iter, index);
item.setText (FString() << *iter);
Expand Down
3 changes: 2 additions & 1 deletion examples/term-attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2022 Markus Gans *
* Copyright 2015-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -433,6 +433,7 @@ void AttribDemo::draw()
const std::vector<std::function<void()> > effect
{
[this] { printNormal(); },
[this] { printDim(); },
[this] { printBold(); },
[this] { printBoldDim(); },
[this] { printItalic(); },
Expand Down
10 changes: 4 additions & 6 deletions examples/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,12 +952,10 @@ void MyDialog::cb_showProgressBar()
//----------------------------------------------------------------------
void MyDialog::cb_updateNumber()
{
int select_num = 0;

for (const auto& item : myList.getData() )
if ( item.isSelected() )
select_num++;

auto is_selected = [] (auto item) { return item.isSelected(); };
auto select_num = std::count_if ( std::begin(myList.getData())
, std::end(myList.getData())
, is_selected );
tagged_count.clear();
tagged_count << select_num;
tagged_count.redraw();
Expand Down
10 changes: 4 additions & 6 deletions examples/watch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2022 Markus Gans *
* Copyright 2015-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -71,7 +71,8 @@ Watch::Watch (FWidget* parent)
time_label.setEmphasis();

// Switch
sec = seconds_sw.setChecked();
seconds_sw.setChecked();
sec = seconds_sw.isChecked();

// Connect switch signal "toggled" with a callback member function
clock_sw.addCallback
Expand Down Expand Up @@ -146,10 +147,7 @@ void Watch::cb_clock()
//----------------------------------------------------------------------
void Watch::cb_seconds()
{
if ( seconds_sw.isChecked() )
sec = true;
else
sec = false;
sec = seconds_sw.isChecked();

if ( clock_sw.isChecked() )
printTime();
Expand Down
7 changes: 2 additions & 5 deletions examples/xpmimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2022 Markus Gans *
* Copyright 2022-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -1124,10 +1124,7 @@ void XpmImage::parseXPM3 (XPMdataT& raw_xpm)
{
std::vector<std::string> xpm{};
xpm.reserve(getArraySize(xpm));

for (const auto& line : raw_xpm)
xpm.emplace_back(line);

std::copy (raw_xpm.begin(), raw_xpm.end(), std::back_inserter(xpm));
parseXPM3 (xpm);
}

Expand Down
41 changes: 10 additions & 31 deletions final/dialog/fdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,24 @@ FDialog::~FDialog() // destructor

// public methods of FDialog
//----------------------------------------------------------------------
auto FDialog::setDialogWidget (bool enable) -> bool
void FDialog::setDialogWidget (bool enable)
{
if ( isDialogWidget() == enable )
return true;
return;

setFlags().type.dialog_widget = enable;

if ( enable )
setTermOffsetWithPadding();
else
setParentOffset();

return enable;
}

//----------------------------------------------------------------------
auto FDialog::setModal (bool enable) -> bool
void FDialog::setModal (bool enable)
{
if ( isModal() == enable )
return true;
return;

setFlags().visibility.modal = enable;

Expand All @@ -113,12 +111,10 @@ auto FDialog::setModal (bool enable) -> bool
}
else
setModalDialogCounter()--;

return enable;
}

//----------------------------------------------------------------------
auto FDialog::setBorder (bool enable) -> bool
void FDialog::setBorder (bool enable)
{
if ( enable )
{
Expand All @@ -134,8 +130,6 @@ auto FDialog::setBorder (bool enable) -> bool
setBottomPadding(0);
setRightPadding(0);
}

return ( setFlags().feature.no_border = (! enable) );
}

//----------------------------------------------------------------------
Expand All @@ -148,29 +142,25 @@ void FDialog::resetColors()
}

//----------------------------------------------------------------------
auto FDialog::setResizeable (bool enable) -> bool
void FDialog::setResizeable (bool enable)
{
FWindow::setResizeable (enable);

if ( enable )
zoom_item->setEnable();
else
zoom_item->setDisable();

return enable;
}

//----------------------------------------------------------------------
auto FDialog::setMinimizable (bool enable) -> bool
void FDialog::setMinimizable (bool enable)
{
FWindow::setMinimizable (enable);

if ( enable )
minimize_item->setEnable();
else
minimize_item->setDisable();

return enable;
}

//----------------------------------------------------------------------
Expand Down Expand Up @@ -581,10 +571,6 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev)
if ( ev->getButton() != MouseButton::Left )
return;

const int x = getTermX();
const int y = getTermY();
const FRect title_button{x, y, 3, 1};

if ( isMouseOverMenuButton(ms) )
{
// Double click on title button
Expand Down Expand Up @@ -1430,11 +1416,8 @@ inline void FDialog::deactivateMinimizeButton()
inline void FDialog::leaveMinimizeButton (const MouseStates& ms)
{
bool minimize_button_pressed_before = minimize_button_pressed;

if ( isMouseOverMinimizeButton(ms) && minimize_button_active )
minimize_button_pressed = true;
else if ( minimize_button_pressed )
minimize_button_pressed = false;
minimize_button_pressed = isMouseOverMinimizeButton(ms)
&& minimize_button_active;

if ( minimize_button_pressed_before != minimize_button_pressed )
drawTitleBar();
Expand Down Expand Up @@ -1480,11 +1463,7 @@ inline void FDialog::deactivateZoomButton()
inline void FDialog::leaveZoomButton (const MouseStates& ms)
{
bool zoom_button_pressed_before = zoom_button_pressed;

if ( isMouseOverZoomButton(ms) && zoom_button_active )
zoom_button_pressed = true;
else if ( zoom_button_pressed )
zoom_button_pressed = false;
zoom_button_pressed = isMouseOverZoomButton(ms) && zoom_button_active;

if ( zoom_button_pressed_before != zoom_button_pressed )
drawTitleBar();
Expand Down
40 changes: 20 additions & 20 deletions final/dialog/fdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ class FDialog : public FWindow
virtual auto getText() const -> FString;

// Mutators
auto setDialogWidget (bool = true) -> bool;
auto unsetDialogWidget() -> bool;
auto setModal (bool = true) -> bool;
auto unsetModal() -> bool;
auto setResizeable (bool = true) -> bool override;
auto setMinimizable (bool = true) -> bool override;
auto setTitlebarButtonVisibility (bool = true) -> bool;
auto unsetTitlebarButtonVisibility() -> bool;
auto setBorder (bool = true) -> bool;
auto unsetBorder() -> bool;
void setDialogWidget (bool = true);
void unsetDialogWidget();
void setModal (bool = true);
void unsetModal();
void setResizeable (bool = true) override;
void setMinimizable (bool = true) override;
void setTitlebarButtonVisibility (bool = true);
void unsetTitlebarButtonVisibility();
void setBorder (bool = true);
void unsetBorder();
void resetColors() override;
virtual void setText (const FString&);

Expand Down Expand Up @@ -287,24 +287,24 @@ inline auto FDialog::getText() const -> FString
{ return tb_text; }

//----------------------------------------------------------------------
inline auto FDialog::unsetDialogWidget() -> bool
{ return setDialogWidget(false); }
inline void FDialog::unsetDialogWidget()
{ setDialogWidget(false); }

//----------------------------------------------------------------------
inline auto FDialog::unsetModal() -> bool
{ return setModal(false); }
inline void FDialog::unsetModal()
{ setModal(false); }

//----------------------------------------------------------------------
inline auto FDialog::setTitlebarButtonVisibility (bool enable) -> bool
{ return (titlebar_buttons = enable); }
inline void FDialog::setTitlebarButtonVisibility (bool enable)
{ titlebar_buttons = enable; }

//----------------------------------------------------------------------
inline auto FDialog::unsetTitlebarButtonVisibility() -> bool
{ return setTitlebarButtonVisibility(false); }
inline void FDialog::unsetTitlebarButtonVisibility()
{ setTitlebarButtonVisibility(false); }

//----------------------------------------------------------------------
inline auto FDialog::unsetBorder() -> bool
{ return setBorder(false); }
inline void FDialog::unsetBorder()
{ setBorder(false); }

//----------------------------------------------------------------------
inline void FDialog::setText (const FString& txt)
Expand Down
5 changes: 2 additions & 3 deletions final/dialog/ffiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,14 @@ void FFileDialog::setFilter (const FString& filter)
}

//----------------------------------------------------------------------
auto FFileDialog::setShowHiddenFiles (bool enable) -> bool
void FFileDialog::setShowHiddenFiles (bool enable)
{
if ( show_hidden == enable )
return show_hidden;
return;

show_hidden = enable;
readDir();
filebrowser.redraw();
return show_hidden;
}

//----------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions final/dialog/ffiledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2014-2022 Markus Gans *
* Copyright 2014-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -115,8 +115,8 @@ class FFileDialog : public FDialog
// Mutators
void setPath (const FString&);
void setFilter (const FString&);
auto setShowHiddenFiles (bool = true) -> bool;
auto unsetShowHiddenFiles() -> bool;
void setShowHiddenFiles (bool = true);
void unsetShowHiddenFiles();

// Event handler
void onKeyPress (FKeyEvent*) override;
Expand Down Expand Up @@ -226,8 +226,8 @@ inline auto FFileDialog::getFilter() const -> FString
{ return filter_pattern; }

//----------------------------------------------------------------------
inline auto FFileDialog::unsetShowHiddenFiles() -> bool
{ return setShowHiddenFiles(false); }
inline void FFileDialog::unsetShowHiddenFiles()
{ setShowHiddenFiles(false); }

//----------------------------------------------------------------------
inline auto FFileDialog::getShowHiddenFiles() const noexcept -> bool
Expand Down
12 changes: 6 additions & 6 deletions final/dialog/fmessagebox.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class FMessageBox : public FDialog
// Mutator
void setTitlebarText (const FString&);
void setHeadline (const FString&);
auto setCenterText (bool = true) -> bool;
auto unsetCenterText() -> bool;
void setCenterText (bool = true);
void unsetCenterText();
void setText (const FString&) override;

// Methods
Expand Down Expand Up @@ -197,12 +197,12 @@ inline void FMessageBox::setTitlebarText (const FString& txt)
{ return FDialog::setText(txt); }

//----------------------------------------------------------------------
inline auto FMessageBox::setCenterText(bool enable) -> bool
{ return (center_text = enable); }
inline void FMessageBox::setCenterText (bool enable)
{ center_text = enable; }

//----------------------------------------------------------------------
inline auto FMessageBox::unsetCenterText() -> bool
{ return setCenterText(false); }
inline void FMessageBox::unsetCenterText()
{ setCenterText(false); }

//----------------------------------------------------------------------
template <typename messageType>
Expand Down
1 change: 1 addition & 0 deletions final/eventloop/timer_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ inline void PosixTimer::init (handler_t hdl, T&& uc)
}
#endif // defined(USE_POSIX_TIMER)


//----------------------------------------------------------------------
// class KqueueTimer
//----------------------------------------------------------------------
Expand Down
14 changes: 5 additions & 9 deletions final/fapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ auto FApplication::getKeyboardWidget() -> FWidget*
auto FApplication::getLog() -> FLogPtr&
{
// Global logger object
static auto logger_ptr = new FLogPtr();
static const auto& logger = std::make_unique<FLogPtr>();

if ( logger_ptr && *logger_ptr == nullptr )
if ( logger && *logger == nullptr )
{
*logger_ptr = std::make_shared<FLogger>();
*logger = std::make_shared<FLogger>();

// Set the logger as rdbuf of clog
std::clog.rdbuf(logger_ptr->get());
std::clog.rdbuf(logger->get());
}

return *logger_ptr;
return *logger;
}

//----------------------------------------------------------------------
Expand Down Expand Up @@ -650,10 +650,6 @@ inline void FApplication::destroyLog()
// Reset the rdbuf of clog
std::clog << std::flush;
std::clog.rdbuf(default_clog_rdbuf);

// Delete the logger
const FLogPtr* logger = &(getLog());
delete logger;
}

//----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit a547d48

Please sign in to comment.