diff --git a/ChangeLog b/ChangeLog index d9b3c8de..28b7e46c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ -2015-09-22 Markus Gans +2015-09-24 Markus Gans + * 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 * Further code optimizations 2015-09-22 Markus Gans diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index a63dc7d6..ae991fcd 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -298,9 +298,7 @@ void FButtonGroup::insert(FToggleButton* button) button->addCallback ( "toggled", - this, - reinterpret_cast(&FButtonGroup::cb_buttonToggled), - null + _METHOD_CALLBACK (this, &FButtonGroup::cb_buttonToggled) ); } diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 4d7d5e0e..eb961969 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -148,44 +148,32 @@ void FFileDialog::init() filename->addCallback ( "activate", - this, - reinterpret_cast(&FFileDialog::cb_processActivate), - null + _METHOD_CALLBACK (this, &FFileDialog::cb_processActivate) ); filebrowser->addCallback ( "row-changed", - this, - reinterpret_cast(&FFileDialog::cb_processRowChanged), - null + _METHOD_CALLBACK (this, &FFileDialog::cb_processRowChanged) ); filebrowser->addCallback ( "clicked", - this, - reinterpret_cast(&FFileDialog::cb_processClicked), - null + _METHOD_CALLBACK (this, &FFileDialog::cb_processClicked) ); hidden->addCallback ( "toggled", - this, - reinterpret_cast(&FFileDialog::cb_processShowHidden), - null + _METHOD_CALLBACK (this, &FFileDialog::cb_processShowHidden) ); cancel->addCallback ( "clicked", - this, - reinterpret_cast(&FFileDialog::cb_processCancel), - null + _METHOD_CALLBACK (this, &FFileDialog::cb_processCancel) ); open->addCallback ( "clicked", - this, - reinterpret_cast(&FFileDialog::cb_processOpen), - null + _METHOD_CALLBACK (this, &FFileDialog::cb_processOpen) ); setModal(); setTransparentShadow(); diff --git a/src/flabel.cpp b/src/flabel.cpp index f22967d3..d37ddf1d 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -377,9 +377,7 @@ void FLabel::setAccelWidget (FWidget* widget) accel_widget->addCallback ( "destroy", - this, - reinterpret_cast(&FLabel::cb_accel_widget_destroyed), - null + _METHOD_CALLBACK (this, &FLabel::cb_accel_widget_destroyed) ); } diff --git a/src/flistbox.cpp b/src/flistbox.cpp index a8b9a901..72d4bc15 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -115,16 +115,12 @@ void FListBox::init() VBar->addCallback ( "change-value", - this, - reinterpret_cast(&FListBox::cb_VBarChange), - null + _METHOD_CALLBACK (this, &FListBox::cb_VBarChange) ); HBar->addCallback ( "change-value", - this, - reinterpret_cast(&FListBox::cb_HBarChange), - null + _METHOD_CALLBACK (this, &FListBox::cb_HBarChange) ); } diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index a778e1af..8630d9d1 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -99,9 +99,7 @@ void FMenuItem::init (FWidget* parent) this->addCallback ( "activate", - (FWidget*)superMenu(), - reinterpret_cast(&FMenuBar::cb_item_activated), - null + _METHOD_CALLBACK (superMenu(), &FMenu::cb_menuitem_activated) ); } else if ( isMenu(parent) ) // Parent is menu @@ -114,9 +112,7 @@ void FMenuItem::init (FWidget* parent) this->addCallback ( "activate", - (FWidget*)superMenu(), - reinterpret_cast(&FMenu::cb_menuitem_activated), - null + _METHOD_CALLBACK (superMenu(), &FMenu::cb_menuitem_activated) ); } } diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 1375a02f..7ebbe6cc 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -160,8 +160,7 @@ void FMessageBox::init(int button0, int button1, int button2) button[0]->addCallback ( "clicked", - this, - reinterpret_cast(&FMessageBox::cb_processClick), + _METHOD_CALLBACK (this, &FMessageBox::cb_processClick), static_cast(button_digit[0]) ); @@ -170,8 +169,7 @@ void FMessageBox::init(int button0, int button1, int button2) button[1]->addCallback ( "clicked", - this, - reinterpret_cast(&FMessageBox::cb_processClick), + _METHOD_CALLBACK (this, &FMessageBox::cb_processClick), static_cast(button_digit[1]) ); @@ -179,8 +177,7 @@ void FMessageBox::init(int button0, int button1, int button2) button[2]->addCallback ( "clicked", - this, - reinterpret_cast(&FMessageBox::cb_processClick), + _METHOD_CALLBACK (this, &FMessageBox::cb_processClick), static_cast(button_digit[2]) ); diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index de4d4447..d5f130eb 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -626,9 +626,7 @@ void FStatusBar::insert (FStatusKey* skey) skey->addCallback ( "activate", - this, - reinterpret_cast(&FStatusBar::cb_statuskey_activated), - null + _METHOD_CALLBACK (this, &FStatusBar::cb_statuskey_activated) ); } diff --git a/src/ftextview.cpp b/src/ftextview.cpp index eaea0aa5..962ed5de 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -53,16 +53,12 @@ void FTextView::init() VBar->addCallback ( "change-value", - this, - reinterpret_cast(&FTextView::cb_VBarChange), - null + _METHOD_CALLBACK (this, &FTextView::cb_VBarChange) ); HBar->addCallback ( "change-value", - this, - reinterpret_cast(&FTextView::cb_HBarChange), - null + _METHOD_CALLBACK (this, &FTextView::cb_HBarChange) ); } diff --git a/src/fwidget.h b/src/fwidget.h index 82e16448..51043390 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -17,6 +17,14 @@ #define FLAT 0x00000080 #define NO_UNDERLINE 0x00000100 +// Callback macros +#define _FUNCTION_CALLBACK(h) \ + reinterpret_cast((h)) + +#define _METHOD_CALLBACK(i,h) \ + reinterpret_cast((i)) \ + , reinterpret_cast((h)) + class FStatusBar; class FMenuBar; @@ -268,8 +276,13 @@ class FWidget : public FObject, public FTerm void clearStatusbarMessage(); FString getStatusbarMessage(); - void addCallback (FString, FCallback, void*); - void addCallback (FString, FWidget*, FMemberCallback, void*); + void addCallback ( FString + , FCallback + , void* data = null ); + void addCallback ( FString + , FWidget* + , FMemberCallback + , void* data = null ); void delCallback (FCallback); void delCallback (FWidget*); void emitCallback (FString); diff --git a/test/calculator.cpp b/test/calculator.cpp index a06f4913..4826b88e 100644 --- a/test/calculator.cpp +++ b/test/calculator.cpp @@ -259,8 +259,7 @@ Calc::Calc (FWidget* parent) btn->addCallback ( "clicked", - this, - reinterpret_cast(&Calc::cb_buttonClicked), + _METHOD_CALLBACK (this, &Calc::cb_buttonClicked), &button_no[key] ); diff --git a/test/dialog.cpp b/test/dialog.cpp index aeb2f8f9..0493bd51 100644 --- a/test/dialog.cpp +++ b/test/dialog.cpp @@ -56,7 +56,7 @@ int main (int argc, char* argv[]) btn.addCallback ( "clicked", - reinterpret_cast(&cb_quit), + _FUNCTION_CALLBACK (&cb_quit), &app ); diff --git a/test/input-dialog.cpp b/test/input-dialog.cpp index bf1cc2ac..a47243fe 100644 --- a/test/input-dialog.cpp +++ b/test/input-dialog.cpp @@ -109,7 +109,7 @@ int main (int argc, char* argv[]) check1->addCallback ( "clicked", - reinterpret_cast(&cb_publish), + _FUNCTION_CALLBACK (&cb_publish), check2 ); @@ -117,7 +117,7 @@ int main (int argc, char* argv[]) btn.addCallback ( "clicked", - reinterpret_cast(&cb_quit), + _FUNCTION_CALLBACK (&cb_quit), &app ); diff --git a/test/ui.cpp b/test/ui.cpp index 4dbd7245..966f0f77 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -14,6 +14,10 @@ class ProgressDialog : public FDialog { + private: + ProgressDialog (const ProgressDialog&); // Disabled copy constructor + ProgressDialog& operator = (const ProgressDialog&); // and operator '=' + public: FButton* reset; FButton* more; @@ -33,7 +37,12 @@ class ProgressDialog : public FDialog #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); setText("Progress bar"); @@ -66,25 +75,19 @@ ProgressDialog::ProgressDialog (FWidget* parent) : FDialog(parent) reset->addCallback ( "clicked", - this, - reinterpret_cast(&ProgressDialog::cb_reset_bar), - null + _METHOD_CALLBACK (this, &ProgressDialog::cb_reset_bar) ); more->addCallback ( "clicked", - this, - reinterpret_cast(&ProgressDialog::cb_more_bar), - null + _METHOD_CALLBACK (this, &ProgressDialog::cb_more_bar) ); quit->addCallback ( "clicked", - this, - reinterpret_cast(&ProgressDialog::cb_exit_bar), - null + _METHOD_CALLBACK (this, &ProgressDialog::cb_exit_bar) ); } @@ -143,7 +146,7 @@ void ProgressDialog::cb_more_bar (FWidget*, void*) //---------------------------------------------------------------------- void ProgressDialog::cb_exit_bar (FWidget*, void*) { - this->close(); + close(); } @@ -158,6 +161,11 @@ class MyDialog : public FDialog { private: FListBox* myList; + + private: + MyDialog (const MyDialog&); // Disabled copy constructor + MyDialog& operator = (const MyDialog&); // and operator '=' + public: explicit MyDialog (FWidget* parent=0); // constructor ~MyDialog(); // destructor @@ -179,8 +187,29 @@ class MyDialog : public FDialog #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); MyButton1->setGeometry(3, 3, 5, 1); MyButton1->setText(L"&SIN"); @@ -302,133 +331,109 @@ MyDialog::MyDialog (FWidget* parent) : FDialog(parent) MyButton1->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_noFunctionMsg), - null + _METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg) ); MyButton2->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_noFunctionMsg), - null + _METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg) ); MyButton3->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_noFunctionMsg), - null + _METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg) ); MyButton4->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_ProgressBar), - null + _METHOD_CALLBACK (this, &MyDialog::cb_ProgressBar) ); MyButton5->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_info), - null + _METHOD_CALLBACK (this, &MyDialog::cb_info) ); MyButton6->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_input2buttonText), + _METHOD_CALLBACK (this, &MyDialog::cb_input2buttonText), dynamic_cast(MyLineEdit) ); MyButton7->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_exitApp), - null + _METHOD_CALLBACK (this, &MyDialog::cb_exitApp) ); MyLineEdit->addCallback ( "activate", // e.g. on - this, - reinterpret_cast(&MyDialog::cb_setTitlebar), - null + _METHOD_CALLBACK (this, &MyDialog::cb_setTitlebar) ); radio1->addCallback ( "toggled", - this, - reinterpret_cast(&MyDialog::cb_activateButton), + _METHOD_CALLBACK (this, &MyDialog::cb_activateButton), dynamic_cast(MyButton4) ); myList->addCallback ( "clicked", - this, - reinterpret_cast(&MyDialog::cb_setInput), + _METHOD_CALLBACK (this, &MyDialog::cb_setInput), dynamic_cast(MyLineEdit) ); myList->addCallback ( "row-selected", - this, - reinterpret_cast(&MyDialog::cb_updateNumber), + _METHOD_CALLBACK (this, &MyDialog::cb_updateNumber), dynamic_cast(tagged_count) ); key_F1->addCallback ( "activate", - this, - reinterpret_cast(&MyDialog::cb_about), - null + _METHOD_CALLBACK (this, &MyDialog::cb_about) ); key_F2->addCallback ( "activate", - this, - reinterpret_cast(&MyDialog::cb_view), - null + _METHOD_CALLBACK (this, &MyDialog::cb_view) ); key_F3->addCallback ( "activate", - this, - reinterpret_cast(&MyDialog::cb_exitApp), + _METHOD_CALLBACK (this, &MyDialog::cb_exitApp), key_F3 ); } //---------------------------------------------------------------------- MyDialog::~MyDialog() -{ -} +{ } //---------------------------------------------------------------------- -void MyDialog::onClose (FCloseEvent* event) +void MyDialog::onClose (FCloseEvent* ev) { - int ret = FMessageBox::info ( this, "Quit", - "Do you really want\n" - "to quit the program ?", - FMessageBox::Yes, - FMessageBox::No ); + int ret = FMessageBox::info ( this, "Quit" + , "Do you really want\n" + "to quit the program ?" + , FMessageBox::Yes + , FMessageBox::No ); if ( ret == FMessageBox::Yes ) - event->accept(); + ev->accept(); else - event->ignore(); + ev->ignore(); } //---------------------------------------------------------------------- @@ -444,13 +449,15 @@ void MyDialog::cb_noFunctionMsg (FWidget* widget, void*) //---------------------------------------------------------------------- void MyDialog::cb_about (FWidget* widget, void*) { + const char ver[] = F_VERSION; FStatusKey* skey = static_cast(widget); FString line(2, wchar_t(fc::BoxDrawingsHorizontal)); - FMessageBox info ( "About", line + L" The Final Cut " + line + "\n\n" - L"Version 0.1.1\n\n" - L"(c) 2015 by Markus Gans", - FMessageBox::Ok, 0, 0, this ); + FMessageBox info ( "About" + , line + L" The Final Cut " + line + "\n\n" + L"Version " + ver + "\n\n" + L"(c) 2015 by Markus Gans" + , FMessageBox::Ok, 0, 0, this ); info.setCenterText(); info.show(); skey->unsetActive(); @@ -460,21 +467,21 @@ void MyDialog::cb_about (FWidget* widget, void*) void MyDialog::cb_info (FWidget*, void*) { { - FMessageBox info1 ( "Environment", - " Type: " + FString(getTermType()) + "\n" + FMessageBox info1 ( "Environment" + , " Type: " + FString(getTermType()) + "\n" " Name: " + FString(getTermName()) + "\n" - " Mode: " + FString(getEncoding()), - FMessageBox::Ok, 0, 0, this ); + " Mode: " + FString(getEncoding()) + , FMessageBox::Ok, 0, 0, this ); info1.setHeadline("Terminal:"); info1.exec(); } // end of scope => delete info1 FString line(15, wchar_t(fc::BoxDrawingsHorizontal)); - FMessageBox info2 ( "Drive symbols", - "Generic: \n\n" + FMessageBox info2 ( "Drive symbols" + , "Generic: \n\n" "Network: \n\n" - " CD:", - FMessageBox::Ok, 0, 0, this ); + " CD:" + , FMessageBox::Ok, 0, 0, this ); if ( isNewFont() ) { FLabel drive (NF_Drive, &info2); @@ -526,8 +533,8 @@ void MyDialog::cb_setTitlebar (FWidget* widget, void*) { FLineEdit* lineedit = static_cast(widget); lineedit->setXTermTitle(lineedit->getText()); - this->setText(lineedit->getText()); - this->redraw(); + setText(lineedit->getText()); + redraw(); } //---------------------------------------------------------------------- @@ -629,13 +636,13 @@ void MyDialog::cb_exitApp (FWidget*, void* data_ptr) //---------------------------------------------------------------------- void MyDialog::adjustSize() { - int h = parentWidget()->getHeight() - 3; + int h = parentWidget()->getHeight() - 4; setHeight (h, false); int X = int((parentWidget()->getWidth() - getWidth()) / 2); if ( X < 1 ) X = 1; setX (X, false); - myList->setHeight (getHeight() - 3, false); + myList->setHeight (getHeight() - 4, false); FDialog::adjustSize(); } @@ -664,7 +671,7 @@ int main (int argc, char* argv[]) MyDialog d(&app); 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(); app.setMainWidget(&d); diff --git a/test/watch.cpp b/test/watch.cpp index 5bf124a6..0d1e0022 100644 --- a/test/watch.cpp +++ b/test/watch.cpp @@ -83,27 +83,21 @@ watch::watch (FWidget* parent) clock_sw->addCallback ( "toggled", - this, - reinterpret_cast(&watch::cb_clock), - null + _METHOD_CALLBACK (this, &watch::cb_clock) ); // Connect switch signal "toggled" with a callback member function seconds_sw->addCallback ( "toggled", - this, - reinterpret_cast(&watch::cb_seconds), - null + _METHOD_CALLBACK (this, &watch::cb_seconds) ); // Connect button signal "clicked" with a callback member function quit_btn->addCallback ( "clicked", - this, - reinterpret_cast(&watch::cb_exitApp), - null + _METHOD_CALLBACK (this, &watch::cb_exitApp) ); }