Add macro _METHOD_CALLBACK and _FUNCTION_CALLBACK to simplify the use callback functions. The callback data pointer is now predefined with NULL as default argument.

This commit is contained in:
Markus Gans 2015-09-24 19:01:27 +02:00
parent 53a3db9980
commit 9740350abd
15 changed files with 130 additions and 144 deletions

View File

@ -1,4 +1,10 @@
2015-09-22 Markus Gans <guru.mail@muenster.de> 2015-09-24 Markus Gans <guru.mail@muenster.de>
* Add macro _METHOD_CALLBACK and _FUNCTION_CALLBACK
to simplify the use callback functions
* The callback data pointer is now predefined with
NULL as default argument
2015-09-23 Markus Gans <guru.mail@muenster.de>
* Further code optimizations * Further code optimizations
2015-09-22 Markus Gans <guru.mail@muenster.de> 2015-09-22 Markus Gans <guru.mail@muenster.de>

View File

@ -298,9 +298,7 @@ void FButtonGroup::insert(FToggleButton* button)
button->addCallback button->addCallback
( (
"toggled", "toggled",
this, _METHOD_CALLBACK (this, &FButtonGroup::cb_buttonToggled)
reinterpret_cast<FWidget::FMemberCallback>(&FButtonGroup::cb_buttonToggled),
null
); );
} }

View File

@ -148,44 +148,32 @@ void FFileDialog::init()
filename->addCallback filename->addCallback
( (
"activate", "activate",
this, _METHOD_CALLBACK (this, &FFileDialog::cb_processActivate)
reinterpret_cast<FWidget::FMemberCallback>(&FFileDialog::cb_processActivate),
null
); );
filebrowser->addCallback filebrowser->addCallback
( (
"row-changed", "row-changed",
this, _METHOD_CALLBACK (this, &FFileDialog::cb_processRowChanged)
reinterpret_cast<FWidget::FMemberCallback>(&FFileDialog::cb_processRowChanged),
null
); );
filebrowser->addCallback filebrowser->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &FFileDialog::cb_processClicked)
reinterpret_cast<FWidget::FMemberCallback>(&FFileDialog::cb_processClicked),
null
); );
hidden->addCallback hidden->addCallback
( (
"toggled", "toggled",
this, _METHOD_CALLBACK (this, &FFileDialog::cb_processShowHidden)
reinterpret_cast<FWidget::FMemberCallback>(&FFileDialog::cb_processShowHidden),
null
); );
cancel->addCallback cancel->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &FFileDialog::cb_processCancel)
reinterpret_cast<FWidget::FMemberCallback>(&FFileDialog::cb_processCancel),
null
); );
open->addCallback open->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &FFileDialog::cb_processOpen)
reinterpret_cast<FWidget::FMemberCallback>(&FFileDialog::cb_processOpen),
null
); );
setModal(); setModal();
setTransparentShadow(); setTransparentShadow();

View File

@ -377,9 +377,7 @@ void FLabel::setAccelWidget (FWidget* widget)
accel_widget->addCallback accel_widget->addCallback
( (
"destroy", "destroy",
this, _METHOD_CALLBACK (this, &FLabel::cb_accel_widget_destroyed)
reinterpret_cast<FWidget::FMemberCallback>(&FLabel::cb_accel_widget_destroyed),
null
); );
} }

View File

@ -115,16 +115,12 @@ void FListBox::init()
VBar->addCallback VBar->addCallback
( (
"change-value", "change-value",
this, _METHOD_CALLBACK (this, &FListBox::cb_VBarChange)
reinterpret_cast<FWidget::FMemberCallback>(&FListBox::cb_VBarChange),
null
); );
HBar->addCallback HBar->addCallback
( (
"change-value", "change-value",
this, _METHOD_CALLBACK (this, &FListBox::cb_HBarChange)
reinterpret_cast<FWidget::FMemberCallback>(&FListBox::cb_HBarChange),
null
); );
} }

View File

@ -99,9 +99,7 @@ void FMenuItem::init (FWidget* parent)
this->addCallback this->addCallback
( (
"activate", "activate",
(FWidget*)superMenu(), _METHOD_CALLBACK (superMenu(), &FMenu::cb_menuitem_activated)
reinterpret_cast<FWidget::FMemberCallback>(&FMenuBar::cb_item_activated),
null
); );
} }
else if ( isMenu(parent) ) // Parent is menu else if ( isMenu(parent) ) // Parent is menu
@ -114,9 +112,7 @@ void FMenuItem::init (FWidget* parent)
this->addCallback this->addCallback
( (
"activate", "activate",
(FWidget*)superMenu(), _METHOD_CALLBACK (superMenu(), &FMenu::cb_menuitem_activated)
reinterpret_cast<FWidget::FMemberCallback>(&FMenu::cb_menuitem_activated),
null
); );
} }
} }

View File

@ -160,8 +160,7 @@ void FMessageBox::init(int button0, int button1, int button2)
button[0]->addCallback button[0]->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
reinterpret_cast<FWidget::FMemberCallback>(&FMessageBox::cb_processClick),
static_cast<FWidget::data_ptr>(button_digit[0]) static_cast<FWidget::data_ptr>(button_digit[0])
); );
@ -170,8 +169,7 @@ void FMessageBox::init(int button0, int button1, int button2)
button[1]->addCallback button[1]->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
reinterpret_cast<FWidget::FMemberCallback>(&FMessageBox::cb_processClick),
static_cast<FWidget::data_ptr>(button_digit[1]) static_cast<FWidget::data_ptr>(button_digit[1])
); );
@ -179,8 +177,7 @@ void FMessageBox::init(int button0, int button1, int button2)
button[2]->addCallback button[2]->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
reinterpret_cast<FWidget::FMemberCallback>(&FMessageBox::cb_processClick),
static_cast<FWidget::data_ptr>(button_digit[2]) static_cast<FWidget::data_ptr>(button_digit[2])
); );

View File

@ -626,9 +626,7 @@ void FStatusBar::insert (FStatusKey* skey)
skey->addCallback skey->addCallback
( (
"activate", "activate",
this, _METHOD_CALLBACK (this, &FStatusBar::cb_statuskey_activated)
reinterpret_cast<FWidget::FMemberCallback>(&FStatusBar::cb_statuskey_activated),
null
); );
} }

View File

@ -53,16 +53,12 @@ void FTextView::init()
VBar->addCallback VBar->addCallback
( (
"change-value", "change-value",
this, _METHOD_CALLBACK (this, &FTextView::cb_VBarChange)
reinterpret_cast<FWidget::FMemberCallback>(&FTextView::cb_VBarChange),
null
); );
HBar->addCallback HBar->addCallback
( (
"change-value", "change-value",
this, _METHOD_CALLBACK (this, &FTextView::cb_HBarChange)
reinterpret_cast<FWidget::FMemberCallback>(&FTextView::cb_HBarChange),
null
); );
} }

View File

@ -17,6 +17,14 @@
#define FLAT 0x00000080 #define FLAT 0x00000080
#define NO_UNDERLINE 0x00000100 #define NO_UNDERLINE 0x00000100
// Callback macros
#define _FUNCTION_CALLBACK(h) \
reinterpret_cast<FWidget::FCallback>((h))
#define _METHOD_CALLBACK(i,h) \
reinterpret_cast<FWidget*>((i)) \
, reinterpret_cast<FWidget::FMemberCallback>((h))
class FStatusBar; class FStatusBar;
class FMenuBar; class FMenuBar;
@ -268,8 +276,13 @@ class FWidget : public FObject, public FTerm
void clearStatusbarMessage(); void clearStatusbarMessage();
FString getStatusbarMessage(); FString getStatusbarMessage();
void addCallback (FString, FCallback, void*); void addCallback ( FString
void addCallback (FString, FWidget*, FMemberCallback, void*); , FCallback
, void* data = null );
void addCallback ( FString
, FWidget*
, FMemberCallback
, void* data = null );
void delCallback (FCallback); void delCallback (FCallback);
void delCallback (FWidget*); void delCallback (FWidget*);
void emitCallback (FString); void emitCallback (FString);

View File

@ -259,8 +259,7 @@ Calc::Calc (FWidget* parent)
btn->addCallback btn->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &Calc::cb_buttonClicked),
reinterpret_cast<FWidget::FMemberCallback>(&Calc::cb_buttonClicked),
&button_no[key] &button_no[key]
); );

View File

@ -56,7 +56,7 @@ int main (int argc, char* argv[])
btn.addCallback btn.addCallback
( (
"clicked", "clicked",
reinterpret_cast<FWidget::FCallback>(&cb_quit), _FUNCTION_CALLBACK (&cb_quit),
&app &app
); );

View File

@ -109,7 +109,7 @@ int main (int argc, char* argv[])
check1->addCallback check1->addCallback
( (
"clicked", "clicked",
reinterpret_cast<FWidget::FCallback>(&cb_publish), _FUNCTION_CALLBACK (&cb_publish),
check2 check2
); );
@ -117,7 +117,7 @@ int main (int argc, char* argv[])
btn.addCallback btn.addCallback
( (
"clicked", "clicked",
reinterpret_cast<FWidget::FCallback>(&cb_quit), _FUNCTION_CALLBACK (&cb_quit),
&app &app
); );

View File

@ -14,6 +14,10 @@
class ProgressDialog : public FDialog class ProgressDialog : public FDialog
{ {
private:
ProgressDialog (const ProgressDialog&); // Disabled copy constructor
ProgressDialog& operator = (const ProgressDialog&); // and operator '='
public: public:
FButton* reset; FButton* reset;
FButton* more; FButton* more;
@ -33,7 +37,12 @@ class ProgressDialog : public FDialog
#pragma pack(pop) #pragma pack(pop)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
ProgressDialog::ProgressDialog (FWidget* parent) : FDialog(parent) ProgressDialog::ProgressDialog (FWidget* parent)
: FDialog(parent)
, reset()
, more()
, quit()
, progressBar()
{ {
setGeometry (int((this->parentWidget()->getWidth()-40)/2), 7, 40, 10); setGeometry (int((this->parentWidget()->getWidth()-40)/2), 7, 40, 10);
setText("Progress bar"); setText("Progress bar");
@ -66,25 +75,19 @@ ProgressDialog::ProgressDialog (FWidget* parent) : FDialog(parent)
reset->addCallback reset->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &ProgressDialog::cb_reset_bar)
reinterpret_cast<FWidget::FMemberCallback>(&ProgressDialog::cb_reset_bar),
null
); );
more->addCallback more->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &ProgressDialog::cb_more_bar)
reinterpret_cast<FWidget::FMemberCallback>(&ProgressDialog::cb_more_bar),
null
); );
quit->addCallback quit->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &ProgressDialog::cb_exit_bar)
reinterpret_cast<FWidget::FMemberCallback>(&ProgressDialog::cb_exit_bar),
null
); );
} }
@ -143,7 +146,7 @@ void ProgressDialog::cb_more_bar (FWidget*, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::cb_exit_bar (FWidget*, void*) void ProgressDialog::cb_exit_bar (FWidget*, void*)
{ {
this->close(); close();
} }
@ -158,6 +161,11 @@ class MyDialog : public FDialog
{ {
private: private:
FListBox* myList; FListBox* myList;
private:
MyDialog (const MyDialog&); // Disabled copy constructor
MyDialog& operator = (const MyDialog&); // and operator '='
public: public:
explicit MyDialog (FWidget* parent=0); // constructor explicit MyDialog (FWidget* parent=0); // constructor
~MyDialog(); // destructor ~MyDialog(); // destructor
@ -179,8 +187,29 @@ class MyDialog : public FDialog
#pragma pack(pop) #pragma pack(pop)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
MyDialog::MyDialog (FWidget* parent) : FDialog(parent) MyDialog::MyDialog (FWidget* parent)
: FDialog(parent)
, myList()
{ {
/* This Code is working in progress...
FMenuBar* menubar = new FMenuBar(this);
FMenu* file = new FMenu("&File", menubar);
FMenu* edit = new FMenu("&Edit", menubar);
FMenuItem* open = new FMenuItem("&Open", file);
FMenuItem* quit = new FMenuItem("&Quit", file);
FMenuItem* cut = new FMenuItem("Cu&t", edit);
FMenuItem* copy = new FMenuItem("&Copy", edit);
FMenuItem* paste = new FMenuItem("&Paste", edit);
quit->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
);
*/
FButton* MyButton1 = new FButton(this); FButton* MyButton1 = new FButton(this);
MyButton1->setGeometry(3, 3, 5, 1); MyButton1->setGeometry(3, 3, 5, 1);
MyButton1->setText(L"&SIN"); MyButton1->setText(L"&SIN");
@ -302,133 +331,109 @@ MyDialog::MyDialog (FWidget* parent) : FDialog(parent)
MyButton1->addCallback MyButton1->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_noFunctionMsg),
null
); );
MyButton2->addCallback MyButton2->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_noFunctionMsg),
null
); );
MyButton3->addCallback MyButton3->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_noFunctionMsg),
null
); );
MyButton4->addCallback MyButton4->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_ProgressBar)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_ProgressBar),
null
); );
MyButton5->addCallback MyButton5->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_info)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_info),
null
); );
MyButton6->addCallback MyButton6->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_input2buttonText),
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_input2buttonText),
dynamic_cast<FWidget::data_ptr>(MyLineEdit) dynamic_cast<FWidget::data_ptr>(MyLineEdit)
); );
MyButton7->addCallback MyButton7->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_exitApp),
null
); );
MyLineEdit->addCallback MyLineEdit->addCallback
( (
"activate", // e.g. on <Enter> "activate", // e.g. on <Enter>
this, _METHOD_CALLBACK (this, &MyDialog::cb_setTitlebar)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_setTitlebar),
null
); );
radio1->addCallback radio1->addCallback
( (
"toggled", "toggled",
this, _METHOD_CALLBACK (this, &MyDialog::cb_activateButton),
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_activateButton),
dynamic_cast<FWidget::data_ptr>(MyButton4) dynamic_cast<FWidget::data_ptr>(MyButton4)
); );
myList->addCallback myList->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &MyDialog::cb_setInput),
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_setInput),
dynamic_cast<FWidget::data_ptr>(MyLineEdit) dynamic_cast<FWidget::data_ptr>(MyLineEdit)
); );
myList->addCallback myList->addCallback
( (
"row-selected", "row-selected",
this, _METHOD_CALLBACK (this, &MyDialog::cb_updateNumber),
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_updateNumber),
dynamic_cast<FWidget::data_ptr>(tagged_count) dynamic_cast<FWidget::data_ptr>(tagged_count)
); );
key_F1->addCallback key_F1->addCallback
( (
"activate", "activate",
this, _METHOD_CALLBACK (this, &MyDialog::cb_about)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_about),
null
); );
key_F2->addCallback key_F2->addCallback
( (
"activate", "activate",
this, _METHOD_CALLBACK (this, &MyDialog::cb_view)
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_view),
null
); );
key_F3->addCallback key_F3->addCallback
( (
"activate", "activate",
this, _METHOD_CALLBACK (this, &MyDialog::cb_exitApp),
reinterpret_cast<FWidget::FMemberCallback>(&MyDialog::cb_exitApp),
key_F3 key_F3
); );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
MyDialog::~MyDialog() MyDialog::~MyDialog()
{ { }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::onClose (FCloseEvent* event) void MyDialog::onClose (FCloseEvent* ev)
{ {
int ret = FMessageBox::info ( this, "Quit", int ret = FMessageBox::info ( this, "Quit"
"Do you really want\n" , "Do you really want\n"
"to quit the program ?", "to quit the program ?"
FMessageBox::Yes, , FMessageBox::Yes
FMessageBox::No ); , FMessageBox::No );
if ( ret == FMessageBox::Yes ) if ( ret == FMessageBox::Yes )
event->accept(); ev->accept();
else else
event->ignore(); ev->ignore();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -444,13 +449,15 @@ void MyDialog::cb_noFunctionMsg (FWidget* widget, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_about (FWidget* widget, void*) void MyDialog::cb_about (FWidget* widget, void*)
{ {
const char ver[] = F_VERSION;
FStatusKey* skey = static_cast<FStatusKey*>(widget); FStatusKey* skey = static_cast<FStatusKey*>(widget);
FString line(2, wchar_t(fc::BoxDrawingsHorizontal)); FString line(2, wchar_t(fc::BoxDrawingsHorizontal));
FMessageBox info ( "About", line + L" The Final Cut " + line + "\n\n" FMessageBox info ( "About"
L"Version 0.1.1\n\n" , line + L" The Final Cut " + line + "\n\n"
L"(c) 2015 by Markus Gans", L"Version " + ver + "\n\n"
FMessageBox::Ok, 0, 0, this ); L"(c) 2015 by Markus Gans"
, FMessageBox::Ok, 0, 0, this );
info.setCenterText(); info.setCenterText();
info.show(); info.show();
skey->unsetActive(); skey->unsetActive();
@ -460,21 +467,21 @@ void MyDialog::cb_about (FWidget* widget, void*)
void MyDialog::cb_info (FWidget*, void*) void MyDialog::cb_info (FWidget*, void*)
{ {
{ {
FMessageBox info1 ( "Environment", FMessageBox info1 ( "Environment"
" Type: " + FString(getTermType()) + "\n" , " Type: " + FString(getTermType()) + "\n"
" Name: " + FString(getTermName()) + "\n" " Name: " + FString(getTermName()) + "\n"
" Mode: " + FString(getEncoding()), " Mode: " + FString(getEncoding())
FMessageBox::Ok, 0, 0, this ); , FMessageBox::Ok, 0, 0, this );
info1.setHeadline("Terminal:"); info1.setHeadline("Terminal:");
info1.exec(); info1.exec();
} // end of scope => delete info1 } // end of scope => delete info1
FString line(15, wchar_t(fc::BoxDrawingsHorizontal)); FString line(15, wchar_t(fc::BoxDrawingsHorizontal));
FMessageBox info2 ( "Drive symbols", FMessageBox info2 ( "Drive symbols"
"Generic: \n\n" , "Generic: \n\n"
"Network: \n\n" "Network: \n\n"
" CD:", " CD:"
FMessageBox::Ok, 0, 0, this ); , FMessageBox::Ok, 0, 0, this );
if ( isNewFont() ) if ( isNewFont() )
{ {
FLabel drive (NF_Drive, &info2); FLabel drive (NF_Drive, &info2);
@ -526,8 +533,8 @@ void MyDialog::cb_setTitlebar (FWidget* widget, void*)
{ {
FLineEdit* lineedit = static_cast<FLineEdit*>(widget); FLineEdit* lineedit = static_cast<FLineEdit*>(widget);
lineedit->setXTermTitle(lineedit->getText()); lineedit->setXTermTitle(lineedit->getText());
this->setText(lineedit->getText()); setText(lineedit->getText());
this->redraw(); redraw();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -629,13 +636,13 @@ void MyDialog::cb_exitApp (FWidget*, void* data_ptr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::adjustSize() void MyDialog::adjustSize()
{ {
int h = parentWidget()->getHeight() - 3; int h = parentWidget()->getHeight() - 4;
setHeight (h, false); setHeight (h, false);
int X = int((parentWidget()->getWidth() - getWidth()) / 2); int X = int((parentWidget()->getWidth() - getWidth()) / 2);
if ( X < 1 ) if ( X < 1 )
X = 1; X = 1;
setX (X, false); setX (X, false);
myList->setHeight (getHeight() - 3, false); myList->setHeight (getHeight() - 4, false);
FDialog::adjustSize(); FDialog::adjustSize();
} }
@ -664,7 +671,7 @@ int main (int argc, char* argv[])
MyDialog d(&app); MyDialog d(&app);
d.setText ("The FINAL CUT 0.1.1 (C) 2015 by Markus Gans"); d.setText ("The FINAL CUT 0.1.1 (C) 2015 by Markus Gans");
d.setGeometry (int((app.getWidth()-56)/2), 2, 56, app.getHeight()-3); d.setGeometry (int((app.getWidth()-56)/2), 2, 56, app.getHeight()-4);
d.setShadow(); d.setShadow();
app.setMainWidget(&d); app.setMainWidget(&d);

View File

@ -83,27 +83,21 @@ watch::watch (FWidget* parent)
clock_sw->addCallback clock_sw->addCallback
( (
"toggled", "toggled",
this, _METHOD_CALLBACK (this, &watch::cb_clock)
reinterpret_cast<FWidget::FMemberCallback>(&watch::cb_clock),
null
); );
// Connect switch signal "toggled" with a callback member function // Connect switch signal "toggled" with a callback member function
seconds_sw->addCallback seconds_sw->addCallback
( (
"toggled", "toggled",
this, _METHOD_CALLBACK (this, &watch::cb_seconds)
reinterpret_cast<FWidget::FMemberCallback>(&watch::cb_seconds),
null
); );
// Connect button signal "clicked" with a callback member function // Connect button signal "clicked" with a callback member function
quit_btn->addCallback quit_btn->addCallback
( (
"clicked", "clicked",
this, _METHOD_CALLBACK (this, &watch::cb_exitApp)
reinterpret_cast<FWidget::FMemberCallback>(&watch::cb_exitApp),
null
); );
} }