Review IdleRegister (#4892)

This turns `IdleRegister::add()` into a template function to make the
provided function pointers type safe. It also adds a `delete_data`
parameter to manage the provided data pointer even in `destroy()`.
This commit is contained in:
Flössie
2018-10-28 13:12:01 +01:00
parent 7038104a20
commit 5906329485
27 changed files with 708 additions and 697 deletions

View File

@@ -45,10 +45,8 @@ struct spparams {
Glib::RefPtr<Gtk::CssProvider> cssProvider;
};
int setprogressStrUI ( void *p )
bool setprogressStrUI(spparams* s)
{
spparams *s = static_cast<spparams*> (p);
if ( ! s->str.empty() ) {
s->pProgress->set_text ( M (s->str) );
}
@@ -67,8 +65,7 @@ int setprogressStrUI ( void *p )
}
}
delete s;
return FALSE;
return false;
}
@@ -498,7 +495,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel)
// build left side panel
leftbox = new Gtk::Paned (Gtk::ORIENTATION_VERTICAL);
// make a subbox to allow resizing of the histogram (if it's on the left)
leftsubbox = new Gtk::Box (Gtk::ORIENTATION_VERTICAL);
leftsubbox->set_size_request (230, 250);
@@ -520,7 +517,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel)
leftsubbox->pack_start (*history);
leftsubbox->show_all ();
leftbox->pack2 (*leftsubbox, true, true);
leftbox->show_all ();
@@ -638,14 +635,14 @@ EditorPanel::EditorPanel (FilePanel* filePanel)
// build right side panel
vboxright = new Gtk::Paned (Gtk::ORIENTATION_VERTICAL);
vsubboxright = new Gtk::Box (Gtk::ORIENTATION_VERTICAL, 0);
vsubboxright->set_size_request (300, 250);
vsubboxright->pack_start (*ppframe, Gtk::PACK_SHRINK, 2);
// main notebook
vsubboxright->pack_start (*tpc->toolPanelNotebook);
vboxright->pack2 (*vsubboxright, true, true);
// Save buttons
@@ -862,7 +859,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel)
if (tbTopPanel_1) {
tbTopPanel_1->signal_toggled().connect ( sigc::mem_fun (*this, &EditorPanel::tbTopPanel_1_toggled) );
}
}
EditorPanel::~EditorPanel ()
@@ -1192,7 +1189,7 @@ void EditorPanel::setProgress(double p)
spparams *s = new spparams;
s->val = p;
s->pProgress = progressLabel;
idle_register.add(setprogressStrUI, s);
idle_register.add<spparams>(setprogressStrUI, s, true);
}
void EditorPanel::setProgressStr(const Glib::ustring& str)
@@ -1201,7 +1198,7 @@ void EditorPanel::setProgressStr(const Glib::ustring& str)
s->str = str;
s->val = -1;
s->pProgress = progressLabel;
idle_register.add(setprogressStrUI, s);
idle_register.add<spparams>(setprogressStrUI, s, true);
}
void EditorPanel::setProgressState(bool inProcessing)
@@ -1217,30 +1214,27 @@ void EditorPanel::setProgressState(bool inProcessing)
p->inProcessing = inProcessing;
p->epih = epih;
const auto func = [] (gpointer data) -> gboolean {
spsparams* const p = static_cast<spsparams*> (data);
if (p->epih->destroyed)
const auto func =
[](spsparams* p) -> bool
{
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
if (p->epih->destroyed)
{
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
}
return false;
}
delete p;
p->epih->epanel->refreshProcessingState (p->inProcessing);
p->epih->pending--;
return 0;
}
return false;
};
p->epih->epanel->refreshProcessingState (p->inProcessing);
p->epih->pending--;
delete p;
return FALSE;
};
idle_register.add (func, p);
idle_register.add<spsparams>(func, p, true);
}
void EditorPanel::error(const Glib::ustring& descr)
@@ -1261,30 +1255,27 @@ void EditorPanel::error(const Glib::ustring& title, const Glib::ustring& descr)
p->title = title;
p->epih = epih;
const auto func = [] (gpointer data) -> gboolean {
errparams* const p = static_cast<errparams*> (data);
if (p->epih->destroyed)
const auto func =
[](errparams* p) -> bool
{
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
if (p->epih->destroyed)
{
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
}
return false;
}
delete p;
p->epih->epanel->displayError (p->title, p->descr);
p->epih->pending--;
return 0;
}
return false;
};
p->epih->epanel->displayError (p->title, p->descr);
p->epih->pending--;
delete p;
return FALSE;
};
idle_register.add (func, p);
idle_register.add<errparams>(func, p, true);
}
void EditorPanel::displayError(const Glib::ustring& title, const Glib::ustring& descr)
@@ -2376,7 +2367,7 @@ void EditorPanel::updateHistogramPosition (int oldPosition, int newPosition)
leftbox->pack1(*histogramPanel, false, false);
histogramPanel->unreference();
}
leftbox->set_position(options.histogramHeight);
histogramPanel->reorder (Gtk::POS_LEFT);
break;
@@ -2396,14 +2387,14 @@ void EditorPanel::updateHistogramPosition (int oldPosition, int newPosition)
vboxright->pack1 (*histogramPanel, false, false);
histogramPanel->unreference();
}
vboxright->set_position(options.histogramHeight);
vboxright->set_position(options.histogramHeight);
histogramPanel->reorder (Gtk::POS_RIGHT);
break;
}
iareapanel->imageArea->setPointerMotionHListener (histogramPanel);
}