Use of smart pointers
This commit is contained in:
parent
554d26ca00
commit
f3bdc3b410
|
@ -1,3 +1,6 @@
|
||||||
|
2018-12-19 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Use of smart pointers
|
||||||
|
|
||||||
2018-12-17 Markus Gans <guru.mail@muenster.de>
|
2018-12-17 Markus Gans <guru.mail@muenster.de>
|
||||||
* Improve FButton mouse click animation
|
* Improve FButton mouse click animation
|
||||||
* Minor data type corrections
|
* Minor data type corrections
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
#include <final/final.h>
|
#include <final/final.h>
|
||||||
|
@ -236,7 +237,7 @@ class Calc : public finalcut::FDialog
|
||||||
};
|
};
|
||||||
|
|
||||||
std::stack<stack_data> bracket_stack{};
|
std::stack<stack_data> bracket_stack{};
|
||||||
std::map<Calc::button, Button*> calculator_buttons{};
|
std::map<Calc::button, std::shared_ptr<Button> > calculator_buttons{};
|
||||||
std::map<Calc::button, keyFunction> key_map{};
|
std::map<Calc::button, keyFunction> key_map{};
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
@ -252,9 +253,9 @@ Calc::Calc (FWidget* parent)
|
||||||
setGeometry (19, 6, 37, 18);
|
setGeometry (19, 6, 37, 18);
|
||||||
addAccelerator('q'); // Press 'q' to quit
|
addAccelerator('q'); // Press 'q' to quit
|
||||||
|
|
||||||
for (int key = 0; key < Calc::NUM_OF_BUTTONS; key++)
|
for (std::size_t key = 0; key < Calc::NUM_OF_BUTTONS; key++)
|
||||||
{
|
{
|
||||||
auto btn = new Button(this);
|
auto btn = std::make_shared<Button>(this);
|
||||||
button_no[key] = key;
|
button_no[key] = key;
|
||||||
|
|
||||||
if ( key == Equals )
|
if ( key == Equals )
|
||||||
|
|
|
@ -23,14 +23,16 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <final/final.h>
|
#include <final/final.h>
|
||||||
|
|
||||||
|
// Typedef
|
||||||
|
typedef std::shared_ptr<finalcut::FRadioButton> FRadioButtonPtr;
|
||||||
|
|
||||||
// function prototypes
|
// Function prototypes
|
||||||
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr);
|
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr);
|
||||||
void populateChoice (std::vector<finalcut::FRadioButton*>&, finalcut::FButtonGroup*);
|
void populateChoice (std::vector<FRadioButtonPtr>&, finalcut::FButtonGroup&);
|
||||||
void preset (std::vector<finalcut::FRadioButton*>&);
|
void preset (std::vector<FRadioButtonPtr>&);
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// callback functions
|
// Callback functions
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr data)
|
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr data)
|
||||||
{
|
{
|
||||||
|
@ -39,22 +41,22 @@ void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void populateChoice ( std::vector<finalcut::FRadioButton*>& os
|
void populateChoice ( std::vector<FRadioButtonPtr>& os
|
||||||
, finalcut::FButtonGroup* group )
|
, finalcut::FButtonGroup& group )
|
||||||
{
|
{
|
||||||
os[0] = new finalcut::FRadioButton("AIX", group);
|
os[0] = std::make_shared<finalcut::FRadioButton>("AIX", &group);
|
||||||
os[1] = new finalcut::FRadioButton("Cygwin", group);
|
os[1] = std::make_shared<finalcut::FRadioButton>("Cygwin", &group);
|
||||||
os[2] = new finalcut::FRadioButton("FreeBSD", group);
|
os[2] = std::make_shared<finalcut::FRadioButton>("FreeBSD", &group);
|
||||||
os[3] = new finalcut::FRadioButton("HP-UX", group);
|
os[3] = std::make_shared<finalcut::FRadioButton>("HP-UX", &group);
|
||||||
os[4] = new finalcut::FRadioButton("Linux", group);
|
os[4] = std::make_shared<finalcut::FRadioButton>("Linux", &group);
|
||||||
os[5] = new finalcut::FRadioButton("Mac OS X", group);
|
os[5] = std::make_shared<finalcut::FRadioButton>("Mac OS X", &group);
|
||||||
os[6] = new finalcut::FRadioButton("NetBSD", group);
|
os[6] = std::make_shared<finalcut::FRadioButton>("NetBSD", &group);
|
||||||
os[7] = new finalcut::FRadioButton("OpenBSD", group);
|
os[7] = std::make_shared<finalcut::FRadioButton>("OpenBSD", &group);
|
||||||
os[8] = new finalcut::FRadioButton("Solaris", group);
|
os[8] = std::make_shared<finalcut::FRadioButton>("Solaris", &group);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void preset (std::vector<finalcut::FRadioButton*>& os)
|
void preset (std::vector<FRadioButtonPtr>& os)
|
||||||
{
|
{
|
||||||
#if defined(_AIX)
|
#if defined(_AIX)
|
||||||
os[0]->setChecked();
|
os[0]->setChecked();
|
||||||
|
@ -111,8 +113,8 @@ int main (int argc, char* argv[])
|
||||||
checkButtonGroup.setGeometry (2, 1, 16, 7);
|
checkButtonGroup.setGeometry (2, 1, 16, 7);
|
||||||
|
|
||||||
// Create radio buttons
|
// Create radio buttons
|
||||||
std::vector<finalcut::FRadioButton*> os (9);
|
std::vector<FRadioButtonPtr> os (9);
|
||||||
populateChoice (os, &checkButtonGroup);
|
populateChoice (os, checkButtonGroup);
|
||||||
|
|
||||||
// Set the radio button geometry
|
// Set the radio button geometry
|
||||||
// => checkButtonGroup.setScrollSize(...) is not required
|
// => checkButtonGroup.setScrollSize(...) is not required
|
||||||
|
|
|
@ -31,8 +31,8 @@ void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr);
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr data)
|
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr data)
|
||||||
{
|
{
|
||||||
auto app = static_cast<finalcut::FApplication*>(data);
|
auto& app = *(static_cast<finalcut::FApplication*>(data));
|
||||||
app->quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
|
|
||||||
// Global application object
|
// Global application object
|
||||||
static finalcut::FString* temp_str = nullptr;
|
static std::shared_ptr<finalcut::FString> temp_str { nullptr };
|
||||||
|
|
||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
|
@ -103,7 +103,7 @@ class Listbox : public finalcut::FDialog
|
||||||
Listbox::Listbox (finalcut::FWidget* parent)
|
Listbox::Listbox (finalcut::FWidget* parent)
|
||||||
: finalcut::FDialog(parent)
|
: finalcut::FDialog(parent)
|
||||||
{
|
{
|
||||||
temp_str = new finalcut::FString;
|
temp_str = std::make_shared<finalcut::FString>();
|
||||||
|
|
||||||
// listbox 1
|
// listbox 1
|
||||||
//----------
|
//----------
|
||||||
|
@ -158,9 +158,7 @@ Listbox::Listbox (finalcut::FWidget* parent)
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
Listbox::~Listbox() // destructor
|
Listbox::~Listbox() // destructor
|
||||||
{
|
{ }
|
||||||
delete temp_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void Listbox::onClose (finalcut::FCloseEvent* ev)
|
void Listbox::onClose (finalcut::FCloseEvent* ev)
|
||||||
|
|
|
@ -189,7 +189,7 @@ void Listview::onClose (finalcut::FCloseEvent* ev)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void Listview::cb_showInMessagebox (finalcut::FWidget*, data_ptr)
|
void Listview::cb_showInMessagebox (finalcut::FWidget*, data_ptr)
|
||||||
{
|
{
|
||||||
auto item = listView.getCurrentItem();
|
const auto& item = listView.getCurrentItem();
|
||||||
finalcut::FMessageBox info ( "Weather in " + item->getText(1)
|
finalcut::FMessageBox info ( "Weather in " + item->getText(1)
|
||||||
, " Condition: " + item->getText(2) + "\n"
|
, " Condition: " + item->getText(2) + "\n"
|
||||||
"Temperature: " + item->getText(3) + "\n"
|
"Temperature: " + item->getText(3) + "\n"
|
||||||
|
|
|
@ -201,7 +201,7 @@ MainWindow::MainWindow (finalcut::FWidget* parent)
|
||||||
// The memory allocation for the following three sub windows occurs
|
// The memory allocation for the following three sub windows occurs
|
||||||
// with the operator new. The lifetime of the generated widget
|
// with the operator new. The lifetime of the generated widget
|
||||||
// is managed by the parent object (this). The operator delete
|
// is managed by the parent object (this). The operator delete
|
||||||
// is not required in this scope and would result in a double free.
|
// is not required in this class and would result in a double free.
|
||||||
transpwin = new Transparent(this);
|
transpwin = new Transparent(this);
|
||||||
transpwin->setText("transparent");
|
transpwin->setText("transparent");
|
||||||
transpwin->setGeometry (6, 3, 29, 12);
|
transpwin->setGeometry (6, 3, 29, 12);
|
||||||
|
|
|
@ -338,10 +338,10 @@ Treeview::Treeview (finalcut::FWidget* parent)
|
||||||
|
|
||||||
while ( continent_list->name )
|
while ( continent_list->name )
|
||||||
{
|
{
|
||||||
auto country_list = continent_list->child_element;
|
auto& country_list = continent_list->child_element;
|
||||||
finalcut::FStringList continent_line ( continent_list->begin()
|
finalcut::FStringList continent_line ( continent_list->begin()
|
||||||
, continent_list->end() );
|
, continent_list->end() );
|
||||||
auto iter = listView.insert (continent_line);
|
const auto& iter = listView.insert (continent_line);
|
||||||
|
|
||||||
while ( country_list && country_list->name )
|
while ( country_list && country_list->name )
|
||||||
{
|
{
|
||||||
|
|
|
@ -757,8 +757,8 @@ void MyDialog::onClose (finalcut::FCloseEvent* ev)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_noFunctionMsg (finalcut::FWidget* widget, data_ptr)
|
void MyDialog::cb_noFunctionMsg (finalcut::FWidget* widget, data_ptr)
|
||||||
{
|
{
|
||||||
auto button = static_cast<finalcut::FButton*>(widget);
|
auto& button = *(static_cast<finalcut::FButton*>(widget));
|
||||||
auto text = button->getText();
|
auto text = button.getText();
|
||||||
text = text.replace('&', "");
|
text = text.replace('&', "");
|
||||||
finalcut::FMessageBox::error ( this
|
finalcut::FMessageBox::error ( this
|
||||||
, "The \"" + text + "\" button has\n"
|
, "The \"" + text + "\" button has\n"
|
||||||
|
@ -884,18 +884,18 @@ void MyDialog::cb_clearInput (finalcut::FWidget*, data_ptr)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_input2buttonText (finalcut::FWidget* widget, data_ptr data)
|
void MyDialog::cb_input2buttonText (finalcut::FWidget* widget, data_ptr data)
|
||||||
{
|
{
|
||||||
auto button = static_cast<finalcut::FButton*>(widget);
|
auto& button = *(static_cast<finalcut::FButton*>(widget));
|
||||||
auto lineedit = static_cast<finalcut::FLineEdit*>(data);
|
const auto& lineedit = *(static_cast<finalcut::FLineEdit*>(data));
|
||||||
button->setText(lineedit->getText());
|
button.setText(lineedit.getText());
|
||||||
button->redraw();
|
button.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_setTitlebar (finalcut::FWidget* widget, data_ptr)
|
void MyDialog::cb_setTitlebar (finalcut::FWidget* widget, data_ptr)
|
||||||
{
|
{
|
||||||
auto lineedit = static_cast<finalcut::FLineEdit*>(widget);
|
auto& lineedit = *(static_cast<finalcut::FLineEdit*>(widget));
|
||||||
finalcut::FString title;
|
finalcut::FString title;
|
||||||
*lineedit >> title;
|
lineedit >> title;
|
||||||
setTermTitle (title);
|
setTermTitle (title);
|
||||||
setText (title);
|
setText (title);
|
||||||
redraw();
|
redraw();
|
||||||
|
@ -911,32 +911,32 @@ void MyDialog::cb_ProgressBar (finalcut::FWidget*, data_ptr)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_updateNumber (finalcut::FWidget* widget, data_ptr data)
|
void MyDialog::cb_updateNumber (finalcut::FWidget* widget, data_ptr data)
|
||||||
{
|
{
|
||||||
auto list = static_cast<finalcut::FListBox*>(widget);
|
auto& list = *(static_cast<finalcut::FListBox*>(widget));
|
||||||
auto num = static_cast<finalcut::FLabel*>(data);
|
auto& num = *(static_cast<finalcut::FLabel*>(data));
|
||||||
auto count = list->getCount();
|
const auto& count = list.getCount();
|
||||||
int select_num = 0;
|
int select_num = 0;
|
||||||
|
|
||||||
for (std::size_t n = 1; n <= count; n++)
|
for (std::size_t n = 1; n <= count; n++)
|
||||||
if ( list->isSelected(n) )
|
if ( list.isSelected(n) )
|
||||||
select_num++;
|
select_num++;
|
||||||
|
|
||||||
num->clear();
|
num.clear();
|
||||||
*num << select_num;
|
num << select_num;
|
||||||
num->redraw();
|
num.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_activateButton (finalcut::FWidget* widget, data_ptr data)
|
void MyDialog::cb_activateButton (finalcut::FWidget* widget, data_ptr data)
|
||||||
{
|
{
|
||||||
auto rb = static_cast<finalcut::FRadioButton*>(widget);
|
auto& rb = *(static_cast<finalcut::FRadioButton*>(widget));
|
||||||
auto button = static_cast<finalcut::FButton*>(data);
|
auto& button = *(static_cast<finalcut::FButton*>(data));
|
||||||
|
|
||||||
if ( rb->isChecked() )
|
if ( rb.isChecked() )
|
||||||
button->setEnable();
|
button.setEnable();
|
||||||
else
|
else
|
||||||
button->setDisable();
|
button.setDisable();
|
||||||
|
|
||||||
button->redraw();
|
button.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -953,7 +953,7 @@ void MyDialog::cb_view (finalcut::FWidget*, data_ptr data)
|
||||||
if ( file.isNull() )
|
if ( file.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextWindow* view = new TextWindow(this);
|
const auto& view = new TextWindow(this);
|
||||||
finalcut::FString filename(basename(const_cast<char*>(file.c_str())));
|
finalcut::FString filename(basename(const_cast<char*>(file.c_str())));
|
||||||
view->setText ("Viewer: " + filename);
|
view->setText ("Viewer: " + filename);
|
||||||
view->setGeometry ( 1 + int((getRootWidget()->getWidth() - 60) / 2),
|
view->setGeometry ( 1 + int((getRootWidget()->getWidth() - 60) / 2),
|
||||||
|
@ -961,7 +961,6 @@ void MyDialog::cb_view (finalcut::FWidget*, data_ptr data)
|
||||||
60,
|
60,
|
||||||
getRootWidget()->getHeight() * 3 / 4 );
|
getRootWidget()->getHeight() * 3 / 4 );
|
||||||
view->setResizeable();
|
view->setResizeable();
|
||||||
|
|
||||||
std::string line = "";
|
std::string line = "";
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
infile.open(file);
|
infile.open(file);
|
||||||
|
@ -981,10 +980,10 @@ void MyDialog::cb_view (finalcut::FWidget*, data_ptr data)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_setInput (finalcut::FWidget* widget, data_ptr data)
|
void MyDialog::cb_setInput (finalcut::FWidget* widget, data_ptr data)
|
||||||
{
|
{
|
||||||
auto ListBox = static_cast<finalcut::FListBox*>(widget);
|
auto& ListBox = *(static_cast<finalcut::FListBox*>(widget));
|
||||||
auto lineedit = static_cast<finalcut::FLineEdit*>(data);
|
auto& lineedit = *(static_cast<finalcut::FLineEdit*>(data));
|
||||||
*lineedit = ListBox->getItem(ListBox->currentItem()).getText();
|
lineedit = ListBox.getItem(ListBox.currentItem()).getText();
|
||||||
lineedit->redraw();
|
lineedit.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,9 +84,6 @@ FApplication::FApplication ( const int& _argc
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FApplication::~FApplication() // destructor
|
FApplication::~FApplication() // destructor
|
||||||
{
|
{
|
||||||
//if ( event_queue )
|
|
||||||
// delete event_queue;
|
|
||||||
|
|
||||||
app_object = nullptr;
|
app_object = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +386,6 @@ void FApplication::init (long key_time, long dblclick_time)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//event_queue = new eventQueue;
|
|
||||||
event_queue = std::make_shared<eventQueue>();
|
event_queue = std::make_shared<eventQueue>();
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
|
|
|
@ -1381,11 +1381,11 @@ inline void FDialog::passEventToSubMenu ( mouseStates& ms
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
|
const auto& _ev = \
|
||||||
|
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, g, b);
|
||||||
dialog_menu->mouse_down = true;
|
dialog_menu->mouse_down = true;
|
||||||
setClickedWidget(dialog_menu);
|
setClickedWidget(dialog_menu);
|
||||||
dialog_menu->onMouseMove(_ev);
|
dialog_menu->onMouseMove(_ev.get());
|
||||||
delete _ev;
|
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -220,7 +220,7 @@ const FString FFileDialog::fileOpenChooser ( FWidget* parent
|
||||||
, const FString& dirname
|
, const FString& dirname
|
||||||
, const FString& filter )
|
, const FString& filter )
|
||||||
{
|
{
|
||||||
FFileDialog* fileopen;
|
//FFileDialog* fileopen;
|
||||||
FString ret;
|
FString ret;
|
||||||
FString path = dirname;
|
FString path = dirname;
|
||||||
FString file_filter = filter;
|
FString file_filter = filter;
|
||||||
|
@ -236,25 +236,16 @@ const FString FFileDialog::fileOpenChooser ( FWidget* parent
|
||||||
if ( file_filter.isNull() || file_filter.isEmpty() )
|
if ( file_filter.isNull() || file_filter.isEmpty() )
|
||||||
file_filter = FString("*");
|
file_filter = FString("*");
|
||||||
|
|
||||||
try
|
FFileDialog fileopen ( path
|
||||||
{
|
, file_filter
|
||||||
fileopen = new FFileDialog ( path
|
, FFileDialog::Open
|
||||||
, file_filter
|
, parent );
|
||||||
, FFileDialog::Open
|
|
||||||
, parent );
|
|
||||||
}
|
|
||||||
catch (const std::bad_alloc& ex)
|
|
||||||
{
|
|
||||||
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
|
||||||
return FString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fileopen->exec() == FDialog::Accept )
|
if ( fileopen.exec() == FDialog::Accept )
|
||||||
ret = fileopen->getPath() + fileopen->getSelectedFile();
|
ret = fileopen.getPath() + fileopen.getSelectedFile();
|
||||||
else
|
else
|
||||||
ret = FString();
|
ret = FString();
|
||||||
|
|
||||||
delete fileopen;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +254,6 @@ const FString FFileDialog::fileSaveChooser ( FWidget* parent
|
||||||
, const FString& dirname
|
, const FString& dirname
|
||||||
, const FString& filter )
|
, const FString& filter )
|
||||||
{
|
{
|
||||||
FFileDialog* fileopen;
|
|
||||||
FString ret;
|
FString ret;
|
||||||
FString path = dirname;
|
FString path = dirname;
|
||||||
FString file_filter = filter;
|
FString file_filter = filter;
|
||||||
|
@ -279,25 +269,16 @@ const FString FFileDialog::fileSaveChooser ( FWidget* parent
|
||||||
if ( file_filter.isNull() || file_filter.isEmpty() )
|
if ( file_filter.isNull() || file_filter.isEmpty() )
|
||||||
file_filter = FString("*");
|
file_filter = FString("*");
|
||||||
|
|
||||||
try
|
FFileDialog fileopen ( path
|
||||||
{
|
, file_filter
|
||||||
fileopen = new FFileDialog ( path
|
, FFileDialog::Save
|
||||||
, file_filter
|
, parent );
|
||||||
, FFileDialog::Save
|
|
||||||
, parent );
|
|
||||||
}
|
|
||||||
catch (const std::bad_alloc& ex)
|
|
||||||
{
|
|
||||||
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
|
||||||
return FString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fileopen->exec() == FDialog::Accept )
|
if ( fileopen.exec() == FDialog::Accept )
|
||||||
ret = fileopen->getPath() + fileopen->getSelectedFile();
|
ret = fileopen.getPath() + fileopen.getSelectedFile();
|
||||||
else
|
else
|
||||||
ret = FString();
|
ret = FString();
|
||||||
|
|
||||||
delete fileopen;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,9 +277,9 @@ void FLabel::onMouseDown (FMouseEvent* ev)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
|
const auto& _ev = \
|
||||||
FApplication::sendEvent (parent, _ev);
|
std::make_shared<FMouseEvent>(fc::MouseDown_Event, p, tp, b);
|
||||||
delete _ev;
|
FApplication::sendEvent (parent, _ev.get());
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -918,11 +918,11 @@ void FMenu::passEventToSubMenu (FMouseEvent*& ev)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
|
const auto& _ev = \
|
||||||
|
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, t, b);
|
||||||
opened_sub_menu->mouse_down = true;
|
opened_sub_menu->mouse_down = true;
|
||||||
setClickedWidget(opened_sub_menu);
|
setClickedWidget(opened_sub_menu);
|
||||||
opened_sub_menu->onMouseMove(_ev);
|
opened_sub_menu->onMouseMove(_ev.get());
|
||||||
delete _ev;
|
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
@ -935,18 +935,18 @@ void FMenu::passEventToSuperMenu (FMouseEvent*& ev)
|
||||||
{
|
{
|
||||||
// Mouse event handover to super-menu
|
// Mouse event handover to super-menu
|
||||||
|
|
||||||
auto smenu = superMenuAt (ev->getTermPos());
|
const auto& smenu = superMenuAt (ev->getTermPos());
|
||||||
const FPoint& t = ev->getTermPos();
|
const FPoint& t = ev->getTermPos();
|
||||||
const FPoint& p = smenu->termToWidgetPos(t);
|
const FPoint& p = smenu->termToWidgetPos(t);
|
||||||
int b = ev->getButton();
|
int b = ev->getButton();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
|
const auto& _ev = \
|
||||||
|
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, t, b);
|
||||||
smenu->mouse_down = true;
|
smenu->mouse_down = true;
|
||||||
setClickedWidget(smenu);
|
setClickedWidget(smenu);
|
||||||
smenu->onMouseMove(_ev);
|
smenu->onMouseMove(_ev.get());
|
||||||
delete _ev;
|
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
@ -959,19 +959,19 @@ void FMenu::passEventToMenuBar (FMouseEvent*& ev)
|
||||||
{
|
{
|
||||||
// Mouse event handover to the menu bar
|
// Mouse event handover to the menu bar
|
||||||
|
|
||||||
auto menu_bar = getMenuBar();
|
const auto& menu_bar = getMenuBar();
|
||||||
const FPoint& t = ev->getTermPos();
|
const FPoint& t = ev->getTermPos();
|
||||||
const FPoint& p = menu_bar->termToWidgetPos(t);
|
const FPoint& p = menu_bar->termToWidgetPos(t);
|
||||||
int b = ev->getButton();
|
int b = ev->getButton();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
|
const auto& _ev = \
|
||||||
|
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, t, b);
|
||||||
setClickedWidget(menu_bar);
|
setClickedWidget(menu_bar);
|
||||||
auto mbar = static_cast<FMenuBar*>(menu_bar);
|
auto& mbar = *(static_cast<FMenuBar*>(menu_bar));
|
||||||
mbar->mouse_down = true;
|
mbar.mouse_down = true;
|
||||||
mbar->onMouseMove(_ev);
|
mbar.onMouseMove(_ev.get());
|
||||||
delete _ev;
|
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -976,7 +976,7 @@ void FMenuBar::passEventToMenu (FMouseEvent*& ev)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Mouse event handover to the menu
|
// Mouse event handover to the menu
|
||||||
auto menu = getSelectedItem()->getMenu();
|
const auto& menu = getSelectedItem()->getMenu();
|
||||||
const auto& menu_geometry = menu->getTermGeometry();
|
const auto& menu_geometry = menu->getTermGeometry();
|
||||||
|
|
||||||
if ( menu->getCount() > 0
|
if ( menu->getCount() > 0
|
||||||
|
@ -988,11 +988,11 @@ void FMenuBar::passEventToMenu (FMouseEvent*& ev)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
|
const auto& _ev = \
|
||||||
|
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, t, b);
|
||||||
menu->mouse_down = true;
|
menu->mouse_down = true;
|
||||||
setClickedWidget(menu);
|
setClickedWidget(menu);
|
||||||
menu->onMouseMove(_ev);
|
menu->onMouseMove(_ev.get());
|
||||||
delete _ev;
|
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -680,14 +680,14 @@ void FMenuItem::passMouseEvent ( T widget, FMouseEvent* ev
|
||||||
if ( ! widget )
|
if ( ! widget )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FMouseEvent* _ev;
|
|
||||||
const FPoint& t = ev->getTermPos();
|
const FPoint& t = ev->getTermPos();
|
||||||
const FPoint& p2 = widget->termToWidgetPos(t);
|
const FPoint& p2 = widget->termToWidgetPos(t);
|
||||||
int b = ev->getButton();
|
int b = ev->getButton();
|
||||||
|
std::shared_ptr<FMouseEvent> _ev;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_ev = new FMouseEvent (ev_type, p2, t, b);
|
_ev = std::make_shared<FMouseEvent>(ev_type, p2, t, b);
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
@ -698,23 +698,21 @@ void FMenuItem::passMouseEvent ( T widget, FMouseEvent* ev
|
||||||
switch ( int(ev_type) )
|
switch ( int(ev_type) )
|
||||||
{
|
{
|
||||||
case fc::MouseDoubleClick_Event:
|
case fc::MouseDoubleClick_Event:
|
||||||
widget->onMouseDoubleClick(_ev);
|
widget->onMouseDoubleClick(_ev.get());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case fc::MouseDown_Event:
|
case fc::MouseDown_Event:
|
||||||
widget->onMouseDown(_ev);
|
widget->onMouseDown(_ev.get());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case fc::MouseUp_Event:
|
case fc::MouseUp_Event:
|
||||||
widget->onMouseUp(_ev);
|
widget->onMouseUp(_ev.get());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case fc::MouseMove_Event:
|
case fc::MouseMove_Event:
|
||||||
widget->onMouseMove(_ev);
|
widget->onMouseMove(_ev.get());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete _ev;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -169,22 +169,10 @@ int FMessageBox::info ( FWidget* parent
|
||||||
, int button2 )
|
, int button2 )
|
||||||
{
|
{
|
||||||
int reply;
|
int reply;
|
||||||
FMessageBox* mbox;
|
FMessageBox mbox ( caption, message
|
||||||
|
, button0, button1, button2
|
||||||
try
|
, parent );
|
||||||
{
|
reply = mbox.exec();
|
||||||
mbox = new FMessageBox ( caption, message
|
|
||||||
, button0, button1, button2
|
|
||||||
, parent );
|
|
||||||
}
|
|
||||||
catch (const std::bad_alloc& ex)
|
|
||||||
{
|
|
||||||
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
|
||||||
return FDialog::Reject;
|
|
||||||
}
|
|
||||||
|
|
||||||
reply = mbox->exec();
|
|
||||||
delete mbox;
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,23 +185,11 @@ int FMessageBox::info ( FWidget* parent
|
||||||
, int button2 )
|
, int button2 )
|
||||||
{
|
{
|
||||||
int reply;
|
int reply;
|
||||||
FMessageBox* mbox;
|
FMessageBox mbox ( caption
|
||||||
|
, FString() << num
|
||||||
try
|
, button0, button1, button2
|
||||||
{
|
, parent );
|
||||||
mbox = new FMessageBox ( caption
|
reply = mbox.exec();
|
||||||
, FString() << num
|
|
||||||
, button0, button1, button2
|
|
||||||
, parent );
|
|
||||||
}
|
|
||||||
catch (const std::bad_alloc& ex)
|
|
||||||
{
|
|
||||||
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
|
||||||
return FDialog::Reject;
|
|
||||||
}
|
|
||||||
|
|
||||||
reply = mbox->exec();
|
|
||||||
delete mbox;
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,28 +202,16 @@ int FMessageBox::error ( FWidget* parent
|
||||||
{
|
{
|
||||||
int reply;
|
int reply;
|
||||||
const FString& caption = "Error message";
|
const FString& caption = "Error message";
|
||||||
FMessageBox* mbox;
|
FMessageBox mbox ( caption, message
|
||||||
|
, button0, button1, button2
|
||||||
try
|
, parent );
|
||||||
{
|
mbox.beep();
|
||||||
mbox = new FMessageBox ( caption, message
|
mbox.setHeadline("Warning:");
|
||||||
, button0, button1, button2
|
mbox.setCenterText();
|
||||||
, parent );
|
mbox.setForegroundColor(mbox.wc.error_box_fg);
|
||||||
}
|
mbox.setBackgroundColor(mbox.wc.error_box_bg);
|
||||||
catch (const std::bad_alloc& ex)
|
mbox.emphasis_color = mbox.wc.error_box_emphasis_fg;
|
||||||
{
|
reply = mbox.exec();
|
||||||
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
|
||||||
return FDialog::Reject;
|
|
||||||
}
|
|
||||||
|
|
||||||
mbox->beep();
|
|
||||||
mbox->setHeadline("Warning:");
|
|
||||||
mbox->setCenterText();
|
|
||||||
mbox->setForegroundColor(mbox->wc.error_box_fg);
|
|
||||||
mbox->setBackgroundColor(mbox->wc.error_box_bg);
|
|
||||||
mbox->emphasis_color = mbox->wc.error_box_emphasis_fg;
|
|
||||||
reply = mbox->exec();
|
|
||||||
delete mbox;
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,11 @@ namespace finalcut
|
||||||
{
|
{
|
||||||
|
|
||||||
// static class attributes
|
// static class attributes
|
||||||
bool FObject::timer_modify_lock;
|
bool FObject::timer_modify_lock;
|
||||||
FObject::TimerList* FObject::timer_list = nullptr;
|
FObject::TimerListPtr FObject::timer_list = nullptr;
|
||||||
const FString* fc::emptyFString::empty_string = nullptr;
|
const FString* fc::emptyFString::empty_string = nullptr;
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// class FObject
|
// class FObject
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -52,7 +53,7 @@ FObject::FObject (FObject* parent)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
timer_list = new TimerList();
|
timer_list = std::make_shared<TimerList>();
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc& ex)
|
catch (const std::bad_alloc& ex)
|
||||||
{
|
{
|
||||||
|
@ -69,10 +70,7 @@ FObject::~FObject() // destructor
|
||||||
delOwnTimer(); // Delete all timers of this object
|
delOwnTimer(); // Delete all timers of this object
|
||||||
|
|
||||||
if ( ! has_parent && timer_list )
|
if ( ! has_parent && timer_list )
|
||||||
{
|
|
||||||
delete timer_list;
|
|
||||||
timer_list = nullptr;
|
timer_list = nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! has_parent && ! fc::emptyFString::isNull() )
|
if ( ! has_parent && ! fc::emptyFString::isNull() )
|
||||||
fc::emptyFString::clear();
|
fc::emptyFString::clear();
|
||||||
|
|
|
@ -177,18 +177,18 @@ class FApplication : public FWidget
|
||||||
, const FEvent* );
|
, const FEvent* );
|
||||||
|
|
||||||
// Data Members
|
// Data Members
|
||||||
int app_argc;
|
int app_argc;
|
||||||
char** app_argv;
|
char** app_argv;
|
||||||
long key_timeout{100000}; // 100 ms
|
long key_timeout{100000}; // 100 ms
|
||||||
long dblclick_interval{500000}; // 500 ms
|
long dblclick_interval{500000}; // 500 ms
|
||||||
static FMouseControl* mouse;
|
static FMouseControl* mouse;
|
||||||
static eventQueuePtr event_queue;
|
static eventQueuePtr event_queue;
|
||||||
static int quit_code;
|
static int quit_code;
|
||||||
static bool quit_now;
|
static bool quit_now;
|
||||||
static int loop_level;
|
static int loop_level;
|
||||||
static bool process_timer_event;
|
static bool process_timer_event;
|
||||||
static FKeyboard* keyboard;
|
static FKeyboard* keyboard;
|
||||||
static FWidget* keyboard_widget;
|
static FWidget* keyboard_widget;
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "final/emptyfstring.h"
|
#include "final/emptyfstring.h"
|
||||||
|
@ -123,8 +124,9 @@ class FObject
|
||||||
FObject* object;
|
FObject* object;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Typedef
|
// Typedefs
|
||||||
typedef std::vector<timer_data> TimerList;
|
typedef std::vector<timer_data> TimerList;
|
||||||
|
typedef std::shared_ptr<TimerList> TimerListPtr;
|
||||||
|
|
||||||
// Accessor
|
// Accessor
|
||||||
TimerList* getTimerList() const;
|
TimerList* getTimerList() const;
|
||||||
|
@ -144,12 +146,12 @@ class FObject
|
||||||
virtual void performTimerAction (const FObject*, const FEvent*);
|
virtual void performTimerAction (const FObject*, const FEvent*);
|
||||||
|
|
||||||
// Data Members
|
// Data Members
|
||||||
FObject* parent_obj{nullptr};
|
FObject* parent_obj{nullptr};
|
||||||
FObjectList children_list{}; // no children yet
|
FObjectList children_list{}; // no children yet
|
||||||
bool has_parent{false};
|
bool has_parent{false};
|
||||||
bool widget_object{false};
|
bool widget_object{false};
|
||||||
static bool timer_modify_lock;
|
static bool timer_modify_lock;
|
||||||
static TimerList* timer_list;
|
static TimerListPtr timer_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
@ -216,7 +218,7 @@ inline bool FObject::isTimerInUpdating() const
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline FObject::TimerList* FObject::getTimerList() const
|
inline FObject::TimerList* FObject::getTimerList() const
|
||||||
{ return timer_list; }
|
{ return timer_list.get(); }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline void FObject::setWidgetProperty (bool property)
|
inline void FObject::setWidgetProperty (bool property)
|
||||||
|
|
Loading…
Reference in New Issue