From d5e345ab68972d7239b56d3315dcb2fb8afab67f Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 3 Oct 2018 22:23:55 +0200 Subject: [PATCH] Reduce the use of the new operators in the examples --- examples/choice.cpp | 96 +++-- examples/input-dialog.cpp | 72 ++-- examples/listbox.cpp | 48 +-- examples/listview.cpp | 59 ++-- examples/menu.cpp | 375 ++++++++++---------- examples/mouse.cpp | 68 ++-- examples/scrollview.cpp | 108 +++--- examples/term-attributes.cpp | 42 ++- examples/termcap.cpp | 37 +- examples/transparent.cpp | 49 +-- examples/treeview.cpp | 322 ++++++++--------- examples/ui.cpp | 597 +++++++++++++++----------------- examples/watch.cpp | 71 ++-- examples/windows.cpp | 269 +++++++------- scripts/cppcheck.sh | 2 +- scripts/remove_eol_spaces.sh | 3 +- scripts/syscall_statistic.sh | 2 +- src/ffiledialog.cpp | 160 ++++----- src/fterm.cpp | 4 +- src/include/final/ffiledialog.h | 13 +- src/include/final/fstatusbar.h | 23 +- test/fkeyboard-test.cpp | 12 +- test/fmouse-test.cpp | 2 +- test/fobject-test.cpp | 5 +- test/foptiattr-test.cpp | 2 +- test/foptimove-test.cpp | 2 +- test/fpoint-test.cpp | 2 +- test/frect-test.cpp | 2 +- test/fstring-test.cpp | 2 +- test/ftermcapquirks-test.cpp | 2 +- test/ftermdetection-test.cpp | 5 +- 31 files changed, 1190 insertions(+), 1266 deletions(-) diff --git a/examples/choice.cpp b/examples/choice.cpp index a22eae48..f5121a12 100644 --- a/examples/choice.cpp +++ b/examples/choice.cpp @@ -96,68 +96,66 @@ int main (int argc, char* argv[]) // Create the application object finalcut::FApplication app(argc, argv); - // Create a simple modal dialog box - finalcut::FDialog* dgl = new finalcut::FDialog(&app); - dgl->setModal(); - dgl->setText ("UNIX select"); - w = 20; - h = 13; - x = (app.getDesktopWidth() - w) / 2; - y = (app.getDesktopHeight() - h) / 2; - dgl->setGeometry (x, y, w, h); + { // Create a simple modal dialog box in this scope + finalcut::FDialog dgl(&app); + dgl.setModal(); + dgl.setText ("UNIX select"); + w = 20; + h = 13; + x = (app.getDesktopWidth() - w) / 2; + y = (app.getDesktopHeight() - h) / 2; + dgl.setGeometry (x, y, w, h); - // Create a button group - finalcut::FButtonGroup* checkButtonGroup = new finalcut::FButtonGroup("choice", dgl); - checkButtonGroup->setGeometry (2, 1, 16, 7); + // Create a button group + finalcut::FButtonGroup checkButtonGroup("choice", &dgl); + checkButtonGroup.setGeometry (2, 1, 16, 7); - // Create radio buttons - std::vector os (9); - populateChoice (os, checkButtonGroup); + // Create radio buttons + std::vector os (9); + populateChoice (os, &checkButtonGroup); - // Set the radio button geometry - // => checkButtonGroup->setScrollSize(...) is not required - // because a FButtonGroup is self-adjusting - for (uInt i = 0; i < os.size(); i++) - os[i]->setGeometry(1, int(1 + i), 12, 1); + // Set the radio button geometry + // => checkButtonGroup.setScrollSize(...) is not required + // because a FButtonGroup is self-adjusting + for (uInt i = 0; i < os.size(); i++) + os[i]->setGeometry(1, int(1 + i), 12, 1); - preset(os); + preset(os); - // Scroll to the focused child element - finalcut::FFocusEvent cfi (finalcut::fc::ChildFocusIn_Event); - finalcut::FApplication::sendEvent(checkButtonGroup, &cfi); + // Scroll to the focused child element + finalcut::FFocusEvent cfi (finalcut::fc::ChildFocusIn_Event); + finalcut::FApplication::sendEvent(&checkButtonGroup, &cfi); - // Create a OK button - finalcut::FButton* ok = new finalcut::FButton("&OK", dgl); - ok->setGeometry (10, 9, 8, 1); + // Create a OK button + finalcut::FButton ok("&OK", &dgl); + ok.setGeometry (10, 9, 8, 1); - // Connect the button signal "clicked" with the callback function - ok->addCallback - ( - "clicked", - F_FUNCTION_CALLBACK (&cb_quit), - dgl - ); + // Connect the button signal "clicked" with the callback function + ok.addCallback + ( + "clicked", + F_FUNCTION_CALLBACK (&cb_quit), + &dgl + ); - // Show the dialog - dgl->show(); + // Show the dialog + dgl.show(); - // Get the checked radio button text - for (int n = 1; n <= int(checkButtonGroup->getCount()); n++) - { - if ( checkButtonGroup->isChecked(n) ) + // Get the checked radio button text + for (int n = 1; n <= int(checkButtonGroup.getCount()); n++) { - label_text = checkButtonGroup->getButton(n)->getText(); - break; + if ( checkButtonGroup.isChecked(n) ) + { + label_text = checkButtonGroup.getButton(n)->getText(); + break; + } } - } + } // Hide and destroy the dialog object - // Hide and destroy the dialog object - delete dgl; // Create and show tooltip for two seconds - finalcut::FToolTip* tooltip = new finalcut::FToolTip(&app); - tooltip->setText ("You have chosen " + label_text); - tooltip->show(); + finalcut::FToolTip tooltip(&app); + tooltip.setText ("You have chosen " + label_text); + tooltip.show(); sleep(2); - delete tooltip; } diff --git a/examples/input-dialog.cpp b/examples/input-dialog.cpp index 25a5ec92..5339f4d5 100644 --- a/examples/input-dialog.cpp +++ b/examples/input-dialog.cpp @@ -66,64 +66,58 @@ int main (int argc, char* argv[]) dgl.setShadow(); // Create input fields - finalcut::FLineEdit* name_field = new finalcut::FLineEdit(&dgl); - finalcut::FLineEdit* email_field = new finalcut::FLineEdit(&dgl); - finalcut::FLineEdit* org_field = new finalcut::FLineEdit(&dgl); - finalcut::FLineEdit* city_field = new finalcut::FLineEdit(&dgl); - finalcut::FLineEdit* st_field = new finalcut::FLineEdit(&dgl); - finalcut::FLineEdit* c_field = new finalcut::FLineEdit(&dgl); + finalcut::FLineEdit name_field (&dgl); + finalcut::FLineEdit email_field (&dgl); + finalcut::FLineEdit org_field (&dgl); + finalcut::FLineEdit city_field (&dgl); + finalcut::FLineEdit st_field (&dgl); + finalcut::FLineEdit c_field (&dgl); - name_field->setLabelText(L"&Name"); - email_field->setLabelText(L"&Email"); - org_field->setLabelText(L"Or&ganization"); - city_field->setLabelText(L"&City"); - st_field->setLabelText(L"&State"); - c_field->setLabelText(L"&Country"); + name_field.setLabelText (L"&Name"); + email_field.setLabelText (L"&Email"); + org_field.setLabelText (L"Or&ganization"); + city_field.setLabelText (L"&City"); + st_field.setLabelText (L"&State"); + c_field.setLabelText (L"&Country"); - name_field->setGeometry(15, 1, 19, 1); - email_field->setGeometry(15, 3, 19, 1); - org_field->setGeometry(15, 5, 19, 1); - city_field->setGeometry(15, 7, 19, 1); - st_field->setGeometry(15, 9, 19, 1); - c_field->setGeometry(15, 11, 4, 1); + name_field.setGeometry (15, 1, 19, 1); + email_field.setGeometry (15, 3, 19, 1); + org_field.setGeometry (15, 5, 19, 1); + city_field.setGeometry (15, 7, 19, 1); + st_field.setGeometry (15, 9, 19, 1); + c_field.setGeometry (15, 11, 4, 1); // Create the button group - finalcut::FButtonGroup* radioButtonGroup = \ - new finalcut::FButtonGroup("Sex", &dgl); - radioButtonGroup->setGeometry(2, 13, 13, 4); + finalcut::FButtonGroup radioButtonGroup ("Sex", &dgl); + radioButtonGroup.setGeometry(2, 13, 13, 4); // Create radio buttons - finalcut::FRadioButton* male = \ - new finalcut::FRadioButton("&Male", radioButtonGroup); - finalcut::FRadioButton* female = \ - new finalcut::FRadioButton("&Female", radioButtonGroup); - male->setGeometry(1, 1, 8, 1); - female->setGeometry(1, 2, 10, 1); + finalcut::FRadioButton male ("&Male", &radioButtonGroup); + finalcut::FRadioButton female ("&Female", &radioButtonGroup); + male.setGeometry (1, 1, 8, 1); + female.setGeometry (1, 2, 10, 1); // Create another button group - finalcut::FButtonGroup* checkButtonGroup = \ - new finalcut::FButtonGroup("&Data options", &dgl); - checkButtonGroup->setGeometry(16, 13, 19, 4); + finalcut::FButtonGroup checkButtonGroup ("&Data options", &dgl); + checkButtonGroup.setGeometry(16, 13, 19, 4); // Create checkbox buttons - finalcut::FCheckBox* check1 = \ - new finalcut::FCheckBox("Save data", checkButtonGroup); - finalcut::FCheckBox* check2 = \ - new finalcut::FCheckBox("Encrypt data", checkButtonGroup); - check1->setGeometry(1, 1, 13, 1); - check2->setGeometry(1, 2, 16, 1); - check2->setDisable(); + finalcut::FCheckBox check1 ("Save data", &checkButtonGroup); + finalcut::FCheckBox check2 ("Encrypt data", &checkButtonGroup); + check1.setGeometry (1, 1, 13, 1); + check2.setGeometry (1, 2, 16, 1); + check2.setDisable(); // Create a OK button finalcut::FButton btn("&OK", &dgl); btn.setGeometry (24, 18, 10, 1); // Connect checkbox signal "clicked" with a callback function - check1->addCallback + check1.addCallback ( "clicked", F_FUNCTION_CALLBACK (&cb_publish), - check2 + &check2 ); // Connect the button signal "clicked" with the callback function diff --git a/examples/listbox.cpp b/examples/listbox.cpp index c8804bbe..4daaf2be 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -91,7 +91,11 @@ class Listbox : public finalcut::FDialog virtual void onClose (finalcut::FCloseEvent*); // Data Member - std::list* double_list; + std::list double_list; + finalcut::FListBox list1; + finalcut::FListBox list2; + finalcut::FListBox list3; + finalcut::FButton Quit; }; #pragma pack(pop) @@ -99,38 +103,41 @@ class Listbox : public finalcut::FDialog Listbox::Listbox (finalcut::FWidget* parent) : finalcut::FDialog(parent) , double_list() + , list1(this) + , list2(this) + , list3(this) + , Quit(this) { temp_str = new finalcut::FString; // listbox 1 - finalcut::FListBox* list1 = new finalcut::FListBox (this); - list1->setGeometry(2, 1, 18, 10); - list1->setText ("FListBoxItem"); + //---------- + list1.setGeometry(2, 1, 18, 10); + list1.setText ("FListBoxItem"); for (int i = 1; i < 30; i++) - list1->insert (L"----- " + (finalcut::FString() << i) + L" -----"); + list1.insert (L"----- " + (finalcut::FString() << i) + L" -----"); // listbox 2 - double_list = new std::list; - + //---------- for (double i = 1; i<=15; i++) - double_list->push_back(2 * i + (i / 100)); + double_list.push_back(2 * i + (i / 100)); - finalcut::FListBox* list2 = new finalcut::FListBox (this); - list2->setGeometry(21, 1, 10, 10); - list2->setText ("double"); + list2.setGeometry(21, 1, 10, 10); + list2.setText ("double"); // // Import via lazy conversion on print // - list2->insert (double_list, doubleToItem); + list2.insert (&double_list, doubleToItem); // // Direct import of the complete list // - //list2->insert (double_list->begin(), double_list->end(), doubleToString); + //list2.insert (double_list.begin(), double_list.end(), doubleToString); // listbox 3 + //---------- std::map TLD; TLD["com"] = "Commercial"; TLD["org"] = "Organization"; @@ -138,18 +145,16 @@ Listbox::Listbox (finalcut::FWidget* parent) TLD["edu"] = "Education"; TLD["gov"] = "Government"; - finalcut::FListBox* list3; - list3 = new finalcut::FListBox (TLD.begin(), TLD.end(), mapToString, this); - list3->setGeometry(32, 1, 21, 10); - list3->setText ("key: value"); + list3.insert (TLD.begin(), TLD.end(), mapToString); + list3.setGeometry(32, 1, 21, 10); + list3.setText ("key: value"); // Quit button - finalcut::FButton* Quit = new finalcut::FButton (this); - Quit->setGeometry(42, 12, 10, 1); - Quit->setText (L"&Quit"); + Quit.setGeometry(42, 12, 10, 1); + Quit.setText (L"&Quit"); // Add quit button function callback - Quit->addCallback + Quit.addCallback ( "clicked", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) @@ -160,7 +165,6 @@ Listbox::Listbox (finalcut::FWidget* parent) Listbox::~Listbox() // destructor { delete temp_str; - delete double_list; } //---------------------------------------------------------------------- diff --git a/examples/listview.cpp b/examples/listview.cpp index c75bf625..d353748a 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -50,64 +50,68 @@ class Listview : public finalcut::FDialog Listview& operator = (const Listview&); // Method - void populate (finalcut::FListView*); + void populate(); // Event handlers virtual void onClose (finalcut::FCloseEvent*); // Callback method void cb_showInMessagebox (finalcut::FWidget*, data_ptr); + + // Data Members + finalcut::FListView listView; + finalcut::FButton Quit; }; #pragma pack(pop) //---------------------------------------------------------------------- Listview::Listview (finalcut::FWidget* parent) : finalcut::FDialog(parent) + , listView(this) + , Quit(this) { // Create FListView object - finalcut::FListView* listView = new finalcut::FListView (this); - listView->setGeometry(2, 1, 33, 14); + listView.setGeometry(2, 1, 33, 14); // Add columns to the view - listView->addColumn ("City"); - listView->addColumn ("Condition"); - listView->addColumn ("Temp."); - listView->addColumn ("Humidity"); - listView->addColumn ("Pressure", 10); + listView.addColumn ("City"); + listView.addColumn ("Condition"); + listView.addColumn ("Temp."); + listView.addColumn ("Humidity"); + listView.addColumn ("Pressure", 10); // Set right alignment for the third, fourth, and fifth column - listView->setColumnAlignment (3, finalcut::fc::alignRight); - listView->setColumnAlignment (4, finalcut::fc::alignRight); - listView->setColumnAlignment (5, finalcut::fc::alignRight); + listView.setColumnAlignment (3, finalcut::fc::alignRight); + listView.setColumnAlignment (4, finalcut::fc::alignRight); + listView.setColumnAlignment (5, finalcut::fc::alignRight); // Set the type of sorting - listView->setColumnSortType (1, finalcut::fc::by_name); - listView->setColumnSortType (2, finalcut::fc::by_name); - listView->setColumnSortType (3, finalcut::fc::by_number); - listView->setColumnSortType (4, finalcut::fc::by_number); - listView->setColumnSortType (5, finalcut::fc::by_number); + listView.setColumnSortType (1, finalcut::fc::by_name); + listView.setColumnSortType (2, finalcut::fc::by_name); + listView.setColumnSortType (3, finalcut::fc::by_number); + listView.setColumnSortType (4, finalcut::fc::by_number); + listView.setColumnSortType (5, finalcut::fc::by_number); // Sort in ascending order by the 1st column - listView->setColumnSort (1, finalcut::fc::ascending); + listView.setColumnSort (1, finalcut::fc::ascending); // The sorting occurs later automatically at insert(). // Otherwise you could start the sorting directly with sort() // Populate FListView with a list of items - populate (listView); + populate(); // Quit button - finalcut::FButton* Quit = new finalcut::FButton (this); - Quit->setGeometry(24, 16, 10, 1); - Quit->setText (L"&Quit"); + Quit.setGeometry(24, 16, 10, 1); + Quit.setText (L"&Quit"); // Add some function callbacks - Quit->addCallback + Quit.addCallback ( "clicked", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) ); - listView->addCallback + listView.addCallback ( "clicked", F_METHOD_CALLBACK (this, &Listview::cb_showInMessagebox) @@ -119,7 +123,7 @@ Listview::~Listview() // destructor { } //---------------------------------------------------------------------- -void Listview::populate (finalcut::FListView* listView) +void Listview::populate() { std::string weather[][5] = { @@ -171,7 +175,7 @@ void Listview::populate (finalcut::FListView* listView) for (int i = 0; i <= lastItem; i++) { finalcut::FStringList line (&weather[i][0], &weather[i][0] + 5); - listView->insert (line); + listView.insert (line); } } @@ -182,10 +186,9 @@ void Listview::onClose (finalcut::FCloseEvent* ev) } //---------------------------------------------------------------------- -void Listview::cb_showInMessagebox (finalcut::FWidget* widget, data_ptr) +void Listview::cb_showInMessagebox (finalcut::FWidget*, data_ptr) { - finalcut::FListView* listView = static_cast(widget); - finalcut::FListViewItem* item = listView->getCurrentItem(); + finalcut::FListViewItem* item = listView.getCurrentItem(); finalcut::FMessageBox info ( "Weather in " + item->getText(1) , " Condition: " + item->getText(2) + "\n" "Temperature: " + item->getText(3) + "\n" diff --git a/examples/menu.cpp b/examples/menu.cpp index 78ba5899..b80df0a2 100644 --- a/examples/menu.cpp +++ b/examples/menu.cpp @@ -47,14 +47,12 @@ class Menu : public finalcut::FDialog Menu& operator = (const Menu&); // Methods - void createFileMenuItems (finalcut::FMenu*); - void createEditMenuItems (finalcut::FMenu*); - void createChoiceMenuItems (finalcut::FMenu*); - void createColorMenuItems (finalcut::FMenu*); - void createStyleMenuItems (finalcut::FMenu*); - void createBorderMenuItems (finalcut::FMenu*); - void createBorderColorMenuItems (finalcut::FMenu*); - void createBorderStyleMenuItems (finalcut::FMenu*); + void configureFileMenuItems(); + void configureEditMenuItems(); + void configureChoiceMenuItems(); + void configureColorMenuItems(); + void configureStyleMenuItems(); + void configureBorderMenuItems(); void defaultCallback (finalcut::FMenuList*); virtual void adjustSize(); @@ -63,65 +61,147 @@ class Menu : public finalcut::FDialog // Callback method void cb_message (finalcut::FWidget*, data_ptr); + + // Data Members + finalcut::FString line; + finalcut::FMenuBar Menubar; + finalcut::FMenu File; + finalcut::FMenu Edit; + finalcut::FMenu Choice; + finalcut::FMenuItem Window; + finalcut::FMenuItem Help; + finalcut::FMenuItem New; + finalcut::FMenuItem Open; + finalcut::FMenuItem Save; + finalcut::FMenuItem SaveAs; + finalcut::FMenuItem Close; + finalcut::FMenuItem Line1; + finalcut::FMenuItem Print; + finalcut::FMenuItem Line2; + finalcut::FMenuItem Quit; + finalcut::FMenuItem Undo; + finalcut::FMenuItem Redo; + finalcut::FMenuItem Line3; + finalcut::FMenuItem Cut; + finalcut::FMenuItem Copy; + finalcut::FMenuItem Paste; + finalcut::FMenuItem Line4; + finalcut::FMenuItem Search; + finalcut::FMenuItem Next; + finalcut::FMenuItem Line5; + finalcut::FMenuItem SelectAll; + finalcut::FMenu Color; + finalcut::FMenu Style; + finalcut::FMenu Border; + finalcut::FRadioMenuItem Color1; + finalcut::FRadioMenuItem Color2; + finalcut::FRadioMenuItem Color3; + finalcut::FRadioMenuItem Color4; + finalcut::FRadioMenuItem Color5; + finalcut::FCheckMenuItem Bold; + finalcut::FCheckMenuItem Italic; + finalcut::FMenu BColor; + finalcut::FMenu BStyle; + finalcut::FRadioMenuItem BColor1; + finalcut::FRadioMenuItem BColor2; + finalcut::FRadioMenuItem BStyle1; + finalcut::FRadioMenuItem BStyle2; + finalcut::FRadioMenuItem BStyle3; + finalcut::FRadioMenuItem BStyle4; + finalcut::FStatusBar Statusbar; + finalcut::FLabel Headline1; + finalcut::FLabel Headline2; + finalcut::FLabel Info; }; #pragma pack(pop) //---------------------------------------------------------------------- Menu::Menu (finalcut::FWidget* parent) : finalcut::FDialog(parent) + , line(13, wchar_t(finalcut::fc::BoxDrawingsHorizontal)) + , Menubar(this) + , File("&File", &Menubar) + , Edit("&Edit", &Menubar) + , Choice("&Choice", &Menubar) + , Window("&Window", &Menubar) + , Help("&Help", &Menubar) + , New("&New", &File) + , Open("&Open...", &File) + , Save("&Save", &File) + , SaveAs("&Save as...", &File) + , Close("&Close", &File) + , Line1(&File) + , Print("&Print", &File) + , Line2(&File) + , Quit("&Quit", &File) + , Undo(finalcut::fc::Fckey_z, "&Undo", &Edit) + , Redo(finalcut::fc::Fckey_y, "&Redo", &Edit) + , Line3(&Edit) + , Cut(finalcut::fc::Fckey_x, "Cu&t", &Edit) + , Copy(finalcut::fc::Fckey_c, "&Copy", &Edit) + , Paste(finalcut::fc::Fckey_v, "&Paste", &Edit) + , Line4(&Edit) + , Search(finalcut::fc::Fckey_f, "&Search", &Edit) + , Next(finalcut::fc::Fkey_f3, "Search &next", &Edit) + , Line5(&Edit) + , SelectAll(finalcut::fc::Fckey_a, "Select &all", &Edit) + , Color("&Color", &Choice) + , Style("&Style", &Choice) + , Border("&Border", &Choice) + , Color1("Red", &Color) + , Color2("Green", &Color) + , Color3("Yellow", &Color) + , Color4("Brue", &Color) + , Color5("Black", &Color) + , Bold("Bold", &Style) + , Italic("Italic", &Style) + , BColor("&Color", &Border) + , BStyle("&Style", &Border) + , BColor1("Red", &BColor) + , BColor2("Blue", &BColor) + , BStyle1(line, &BStyle) + , BStyle2("-------------", &BStyle) + , BStyle3("- - - - - - -", &BStyle) + , BStyle4("- - - - -", &BStyle) + , Statusbar(this) + , Headline1(this) + , Headline2(this) + , Info(this) { - // Menu bar - finalcut::FMenuBar* Menubar = new finalcut::FMenuBar(this); - - // Menu bar items - finalcut::FMenu* File = \ - new finalcut::FMenu ("&File", Menubar); - File->setStatusbarMessage ("File management commands"); - finalcut::FMenu* Edit = \ - new finalcut::FMenu ("&Edit", Menubar); - Edit->setStatusbarMessage ("Cut-and-paste editing commands"); - finalcut::FMenu* Choice = \ - new finalcut::FMenu ("&Choice", Menubar); - Choice->setStatusbarMessage ("Choice menu"); - finalcut::FMenuItem* Window = \ - new finalcut::FMenuItem ("&Window", Menubar); - Window->setDisable(); - finalcut::FMenuItem* Help = \ - new finalcut::FMenuItem ("&Help", Menubar); - Help->setStatusbarMessage ("Show version and copyright information"); + // Menu bar itms + File.setStatusbarMessage ("File management commands"); + Edit.setStatusbarMessage ("Cut-and-paste editing commands"); + Choice.setStatusbarMessage ("Choice menu"); + Window.setDisable(); + Help.setStatusbarMessage ("Show version and copyright information"); // Menu items - createFileMenuItems (File); - createEditMenuItems (Edit); - createChoiceMenuItems (Choice); + configureFileMenuItems(); + configureEditMenuItems(); + configureChoiceMenuItems(); // Add default menu item callback - defaultCallback (Menubar); + defaultCallback (&Menubar); // Statusbar at the bottom - finalcut::FStatusBar* Statusbar = \ - new finalcut::FStatusBar (this); - Statusbar->setMessage("Status bar message"); + Statusbar.setMessage("Status bar message"); // Headline labels - finalcut::FLabel* Headline1 = \ - new finalcut::FLabel(" Key ", this); - Headline1->ignorePadding(); - Headline1->setGeometry(3, 2, 5, 1); - Headline1->setEmphasis(); + Headline1 << " Key "; + Headline1.ignorePadding(); + Headline1.setGeometry(3, 2, 5, 1); + Headline1.setEmphasis(); - finalcut::FLabel* Headline2 = \ - new finalcut::FLabel(" Function ", this); - Headline2->ignorePadding(); - Headline2->setGeometry(19, 2, 10, 1); - Headline2->setEmphasis(); + Headline2 << " Function "; + Headline2.ignorePadding(); + Headline2.setGeometry(19, 2, 10, 1); + Headline2.setEmphasis(); // Info label - finalcut::FLabel* Info = \ - new finalcut::FLabel( " Activate menu bar\n" - "+ Activate menu bar\n" - "+ Exit", this ); - Info->setGeometry(2, 1, 36, 3); + Info << " Activate menu bar\n" + << "+ Activate menu bar\n" + << "+ Exit"; + Info.setGeometry(2, 1, 36, 3); } //---------------------------------------------------------------------- @@ -129,45 +209,27 @@ Menu::~Menu() { } //---------------------------------------------------------------------- -void Menu::createFileMenuItems (finalcut::FMenu* File) +void Menu::configureFileMenuItems() { // "File" menu items - finalcut::FMenuItem* New = \ - new finalcut::FMenuItem ("&New", File); - New->addAccelerator (finalcut::fc::Fckey_n); // Ctrl + N - New->setStatusbarMessage ("Create a new file"); - finalcut::FMenuItem* Open = \ - new finalcut::FMenuItem ("&Open...", File); - Open->addAccelerator (finalcut::fc::Fckey_o); // Ctrl + O - Open->setStatusbarMessage ("Locate and open a text file"); - finalcut::FMenuItem* Save = \ - new finalcut::FMenuItem ("&Save", File); - Save->addAccelerator (finalcut::fc::Fckey_s); // Ctrl + S - Save->setStatusbarMessage ("Save the file"); - finalcut::FMenuItem* SaveAs = \ - new finalcut::FMenuItem ("&Save as...", File); - SaveAs->setStatusbarMessage ("Save the current file under a different name"); - finalcut::FMenuItem* Close = \ - new finalcut::FMenuItem ("&Close", File); - Close->addAccelerator (finalcut::fc::Fckey_w); // Ctrl + W - Close->setStatusbarMessage ("Close the current file"); - finalcut::FMenuItem* Line1 = \ - new finalcut::FMenuItem (File); - Line1->setSeparator(); - finalcut::FMenuItem* Print = \ - new finalcut::FMenuItem ("&Print", File); - Print->addAccelerator (finalcut::fc::Fckey_p); // Ctrl + P - Print->setStatusbarMessage ("Print the current file"); - finalcut::FMenuItem* Line2 = \ - new finalcut::FMenuItem (File); - Line2->setSeparator(); - finalcut::FMenuItem* Quit = \ - new finalcut::FMenuItem ("&Quit", File); - Quit->addAccelerator (finalcut::fc::Fmkey_x); // Meta/Alt + X - Quit->setStatusbarMessage ("Exit the program"); + New.addAccelerator (finalcut::fc::Fckey_n); // Ctrl + N + New.setStatusbarMessage ("Create a new file"); + Open.addAccelerator (finalcut::fc::Fckey_o); // Ctrl + O + Open.setStatusbarMessage ("Locate and open a text file"); + Save.addAccelerator (finalcut::fc::Fckey_s); // Ctrl + S + Save.setStatusbarMessage ("Save the file"); + SaveAs.setStatusbarMessage ("Save the current file under a different name"); + Close.addAccelerator (finalcut::fc::Fckey_w); // Ctrl + W + Close.setStatusbarMessage ("Close the current file"); + Line1.setSeparator(); + Print.addAccelerator (finalcut::fc::Fckey_p); // Ctrl + P + Print.setStatusbarMessage ("Print the current file"); + Line2.setSeparator(); + Quit.addAccelerator (finalcut::fc::Fmkey_x); // Meta/Alt + X + Quit.setStatusbarMessage ("Exit the program"); // Add quit menu item callback - Quit->addCallback + Quit.addCallback ( "clicked", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) @@ -175,138 +237,73 @@ void Menu::createFileMenuItems (finalcut::FMenu* File) } //---------------------------------------------------------------------- -void Menu::createEditMenuItems (finalcut::FMenu* Edit) +void Menu::configureEditMenuItems() { // "Edit" menu items - finalcut::FMenuItem* Undo = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_z, "&Undo", Edit); - Undo->setStatusbarMessage ("Undo the previous operation"); - finalcut::FMenuItem* Redo = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_y, "&Redo", Edit); - Redo->setDisable(); - finalcut::FMenuItem* Line3 = \ - new finalcut::FMenuItem (Edit); - Line3->setSeparator(); - finalcut::FMenuItem* Cut = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_x, "Cu&t", Edit); - Cut->setStatusbarMessage ( "Remove the input text " - "and put it in the clipboard" ); - finalcut::FMenuItem* Copy = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_c, "&Copy", Edit); - Copy->setStatusbarMessage ("Copy the input text into the clipboad"); - finalcut::FMenuItem* Paste = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_v, "&Paste", Edit); - Paste->setStatusbarMessage ("Insert text form clipboard"); - finalcut::FMenuItem* Line4 = \ - new finalcut::FMenuItem (Edit); - Line4->setSeparator(); - finalcut::FMenuItem* Search = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_f, "&Search", Edit); - Search->setStatusbarMessage ("Search for text"); - finalcut::FMenuItem* Next = \ - new finalcut::FMenuItem (finalcut::fc::Fkey_f3, "Search &next", Edit); - Next->setStatusbarMessage ("Repeat the last search command"); - finalcut::FMenuItem* Line5 = \ - new finalcut::FMenuItem (Edit); - Line5->setSeparator(); - finalcut::FMenuItem* SelectAll = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_a, "Select &all", Edit); - SelectAll->setStatusbarMessage ("Select the whole text"); + Undo.setStatusbarMessage ("Undo the previous operation"); + Redo.setDisable(); + Line3.setSeparator(); + Cut.setStatusbarMessage ( "Remove the input text " + "and put it in the clipboard" ); + Copy.setStatusbarMessage ("Copy the input text into the clipboad"); + Paste.setStatusbarMessage ("Insert text form clipboard"); + Line4.setSeparator(); + Search.setStatusbarMessage ("Search for text"); + Next.setStatusbarMessage ("Repeat the last search command"); + Line5.setSeparator(); + SelectAll.setStatusbarMessage ("Select the whole text"); } //---------------------------------------------------------------------- -void Menu::createChoiceMenuItems (finalcut::FMenu* Choice) +void Menu::configureChoiceMenuItems() { // "Choice" menu items - finalcut::FMenu* Color = new finalcut::FMenu ("&Color", Choice); - Color->setStatusbarMessage ("Choose a color"); - finalcut::FMenu* Style = new finalcut::FMenu ("&Style", Choice); - Style->setStatusbarMessage ("Choose a Style"); - finalcut::FMenu* Border = new finalcut::FMenu ("&Border", Choice); - Border->setStatusbarMessage ("Choose Border"); + Color.setStatusbarMessage ("Choose a color"); + Style.setStatusbarMessage ("Choose a Style"); + Border.setStatusbarMessage ("Choose Border"); - createColorMenuItems (Color); - createStyleMenuItems (Style); - createBorderMenuItems (Border); + configureColorMenuItems(); + configureStyleMenuItems(); + configureBorderMenuItems(); } //---------------------------------------------------------------------- -void Menu::createColorMenuItems (finalcut::FMenu* Color) +void Menu::configureColorMenuItems() { // "Color" menu items - finalcut::FRadioMenuItem* Color1 = \ - new finalcut::FRadioMenuItem ("Red", Color); - Color1->setStatusbarMessage ("Set text red"); - finalcut::FRadioMenuItem* Color2 = \ - new finalcut::FRadioMenuItem ("Green", Color); - Color2->setStatusbarMessage ("Set text green"); - finalcut::FRadioMenuItem* Color3 = \ - new finalcut::FRadioMenuItem ("Yellow", Color); - Color3->setStatusbarMessage ("Set text yellow"); - finalcut::FRadioMenuItem* Color4 = \ - new finalcut::FRadioMenuItem ("Brue", Color); - Color4->setStatusbarMessage ("Set text brue"); - finalcut::FRadioMenuItem* Color5 = \ - new finalcut::FRadioMenuItem ("Black", Color); - Color5->setStatusbarMessage ("Set text black"); - Color5->setChecked(); + Color1.setStatusbarMessage ("Set text red"); + Color2.setStatusbarMessage ("Set text green"); + Color3.setStatusbarMessage ("Set text yellow"); + Color4.setStatusbarMessage ("Set text brue"); + Color5.setStatusbarMessage ("Set text black"); + Color5.setChecked(); } //---------------------------------------------------------------------- -void Menu::createStyleMenuItems (finalcut::FMenu* Style) +void Menu::configureStyleMenuItems() { // "Style" menu items - finalcut::FCheckMenuItem* Bold = \ - new finalcut::FCheckMenuItem ("Bold", Style); - Bold->setStatusbarMessage ("Set text bold"); - finalcut::FCheckMenuItem* Italic = \ - new finalcut::FCheckMenuItem ("Italic", Style); - Italic->setStatusbarMessage ("Set text italic"); + Bold.setStatusbarMessage ("Set text bold"); + Italic.setStatusbarMessage ("Set text italic"); } //---------------------------------------------------------------------- -void Menu::createBorderMenuItems (finalcut::FMenu* Border) +void Menu::configureBorderMenuItems() { // "Border" menu items - finalcut::FMenu* BColor = new finalcut::FMenu ("&Color", Border); - BColor->setStatusbarMessage ("Choose the border color"); - finalcut::FMenu* BStyle = new finalcut::FMenu ("&Style", Border); - BStyle->setStatusbarMessage ("Choose the border Style"); + BColor.setStatusbarMessage ("Choose the border color"); + BStyle.setStatusbarMessage ("Choose the border Style"); - createBorderColorMenuItems (BColor); - createBorderStyleMenuItems (BStyle); -} - -//---------------------------------------------------------------------- -void Menu::createBorderColorMenuItems (finalcut::FMenu* BColor) -{ // "BColor" menu items - finalcut::FRadioMenuItem* BColor1 = \ - new finalcut::FRadioMenuItem ("Red", BColor); - BColor1->setStatusbarMessage ("Set red border"); - finalcut::FRadioMenuItem* BColor2 = \ - new finalcut::FRadioMenuItem ("Blue", BColor); - BColor2->setStatusbarMessage ("Set blue border"); -} + BColor1.setStatusbarMessage ("Set red border"); + BColor2.setStatusbarMessage ("Set blue border"); -//---------------------------------------------------------------------- -void Menu::createBorderStyleMenuItems (finalcut::FMenu* BStyle) -{ // "BStyle" menu items - finalcut::FString line(13, wchar_t(finalcut::fc::BoxDrawingsHorizontal)); - finalcut::FRadioMenuItem* BStyle1 = \ - new finalcut::FRadioMenuItem (line, BStyle); - BStyle1->setChecked(); - BStyle1->setStatusbarMessage ("Set border 1"); - finalcut::FRadioMenuItem* BStyle2 = \ - new finalcut::FRadioMenuItem ("-------------", BStyle); - BStyle2->setStatusbarMessage ("Set border 2"); - finalcut::FRadioMenuItem* BStyle3 = \ - new finalcut::FRadioMenuItem ("- - - - - - -", BStyle); - BStyle3->setStatusbarMessage ("Set border 3"); - finalcut::FRadioMenuItem* BStyle4 = \ - new finalcut::FRadioMenuItem ("- - - - -", BStyle); - BStyle4->setStatusbarMessage ("Set border 4"); + BStyle1.setChecked(); + BStyle1.setStatusbarMessage ("Set border 1"); + BStyle2.setStatusbarMessage ("Set border 2"); + BStyle3.setStatusbarMessage ("Set border 3"); + BStyle4.setStatusbarMessage ("Set border 4"); } //---------------------------------------------------------------------- diff --git a/examples/mouse.cpp b/examples/mouse.cpp index abbbff6e..ab829f46 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -58,6 +58,7 @@ class ColorChooser : public finalcut::FWidget // Data Members short fg_color; short bg_color; + finalcut::FLabel headline; }; #pragma pack(pop) @@ -66,6 +67,7 @@ ColorChooser::ColorChooser (finalcut::FWidget* parent) : FWidget(parent) , fg_color(finalcut::fc::White) , bg_color(finalcut::fc::Black) + , headline(this) { setSize (8, 12); setFixedSize (8, 12); @@ -73,16 +75,19 @@ ColorChooser::ColorChooser (finalcut::FWidget* parent) if ( parent ) { - setForegroundColor(parent->getForegroundColor()); - setBackgroundColor(parent->getBackgroundColor()); + short fg = parent->getForegroundColor(); + short bg = parent->getBackgroundColor(); + setForegroundColor(fg); + setBackgroundColor(bg); + headline.setForegroundColor(fg); + headline.setBackgroundColor(bg); } // Text label - finalcut::FLabel* headline = new finalcut::FLabel (this); - headline->setGeometry(1, 1, 8, 1); - headline->setEmphasis(); - headline->setAlignment (finalcut::fc::alignCenter); - *headline << "Color"; + headline.setGeometry (1, 1, 8, 1); + headline.setEmphasis(); + headline.setAlignment (finalcut::fc::alignCenter); + headline << "Color"; } //---------------------------------------------------------------------- @@ -197,6 +202,7 @@ class Brushes : public finalcut::FWidget wchar_t brush; short fg_color; short bg_color; + finalcut::FLabel headline; }; #pragma pack(pop) @@ -206,6 +212,7 @@ Brushes::Brushes (finalcut::FWidget* parent) , brush(L' ') , fg_color(finalcut::fc::White) , bg_color(finalcut::fc::Black) + , headline(this) { setSize (8, 4); setFixedSize (8, 4); @@ -213,16 +220,19 @@ Brushes::Brushes (finalcut::FWidget* parent) if ( parent ) { - setForegroundColor(parent->getForegroundColor()); - setBackgroundColor(parent->getBackgroundColor()); + short fg = parent->getForegroundColor(); + short bg = parent->getBackgroundColor(); + setForegroundColor(fg); + setBackgroundColor(bg); + headline.setForegroundColor(fg); + headline.setBackgroundColor(bg); } // Text label - finalcut::FLabel* headline = new finalcut::FLabel (this); - headline->setGeometry(1, 1, 8, 1); - headline->setEmphasis(); - headline->setAlignment (finalcut::fc::alignCenter); - *headline << "Brush"; + headline.setGeometry(1, 1, 8, 1); + headline.setEmphasis(); + headline.setAlignment (finalcut::fc::alignCenter); + headline << "Brush"; } //---------------------------------------------------------------------- @@ -339,9 +349,9 @@ class MouseDraw : public finalcut::FDialog void cb_colorChanged (finalcut::FWidget*, data_ptr); // Data Members - term_area* canvas; - ColorChooser* c_chooser; - Brushes* brush; + term_area* canvas; + ColorChooser c_chooser; + Brushes brush; }; #pragma pack(pop) @@ -349,20 +359,18 @@ class MouseDraw : public finalcut::FDialog MouseDraw::MouseDraw (finalcut::FWidget* parent) : finalcut::FDialog(parent) , canvas(0) - , c_chooser() - , brush() + , c_chooser(this) + , brush(this) { setText ("Drawing with the mouse"); - c_chooser = new ColorChooser(this); - c_chooser->setPos (1, 1); - c_chooser->addCallback + c_chooser.setPos (1, 1); + c_chooser.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MouseDraw::cb_colorChanged) ); - brush = new Brushes(this); - brush->setPos (1, 12); + brush.setPos (1, 12); finalcut::FPoint no_shadow(0,0); finalcut::FRect scroll_geometry(0, 0, 1, 1); @@ -450,15 +458,15 @@ void MouseDraw::drawBrush (int x, int y, bool swap_color) if ( x > 10 && x < Cols && y > 2 && y < Lines ) { if ( swap_color ) - setColor (c_chooser->getBackground(), c_chooser->getForeground()); + setColor (c_chooser.getBackground(), c_chooser.getForeground()); else - setColor (c_chooser->getForeground(), c_chooser->getBackground()); + setColor (c_chooser.getForeground(), c_chooser.getBackground()); // set canvas print cursor position canvas->cursor_x = x - canvas->offset_left - 10; canvas->cursor_y = y - canvas->offset_top - 2; // print on canvas - print (canvas, brush->getBrush()); + print (canvas, brush.getBrush()); // copy canvas to the dialog drawCanvas(); } @@ -539,9 +547,9 @@ void MouseDraw::onMouseMove (finalcut::FMouseEvent* ev) //---------------------------------------------------------------------- void MouseDraw::cb_colorChanged (finalcut::FWidget*, data_ptr) { - brush->setForeground (c_chooser->getForeground()); - brush->setBackground (c_chooser->getBackground()); - brush->redraw(); + brush.setForeground (c_chooser.getForeground()); + brush.setBackground (c_chooser.getBackground()); + brush.redraw(); } diff --git a/examples/scrollview.cpp b/examples/scrollview.cpp index 32f7305a..451cf1f7 100644 --- a/examples/scrollview.cpp +++ b/examples/scrollview.cpp @@ -58,58 +58,55 @@ class Scrollview : public finalcut::FScrollView void cb_go_north (finalcut::FWidget*, data_ptr); // Data Members - finalcut::FButton* go_east; - finalcut::FButton* go_south; - finalcut::FButton* go_west; - finalcut::FButton* go_north; + wchar_t pointer_right; + wchar_t pointer_down; + wchar_t pointer_left; + wchar_t pointer_up; + finalcut::FButton go_east; + finalcut::FButton go_south; + finalcut::FButton go_west; + finalcut::FButton go_north; }; #pragma pack(pop) //---------------------------------------------------------------------- Scrollview::Scrollview (finalcut::FWidget* parent) : finalcut::FScrollView(parent) - , go_east() - , go_south() - , go_west() - , go_north() + , pointer_right(wchar_t(finalcut::fc::BlackRightPointingPointer)) + , pointer_down(wchar_t(finalcut::fc::BlackDownPointingTriangle)) + , pointer_left(wchar_t(finalcut::fc::BlackLeftPointingPointer)) + , pointer_up(wchar_t(finalcut::fc::BlackUpPointingTriangle)) + , go_east(pointer_right, this) + , go_south(pointer_down, this) + , go_west(pointer_left, this) + , go_north(pointer_up, this) { - // Create the four navigation buttons - wchar_t pointer_right = wchar_t(finalcut::fc::BlackRightPointingPointer); - go_east = new finalcut::FButton(pointer_right, this); - go_east->setGeometry (1, 1, 5, 1); - - wchar_t pointer_down = wchar_t(finalcut::fc::BlackDownPointingTriangle); - go_south = new finalcut::FButton(pointer_down, this); - go_south->setGeometry (getScrollWidth() - 5, 1, 5, 1); - - wchar_t pointer_left = wchar_t(finalcut::fc::BlackLeftPointingPointer); - go_west = new finalcut::FButton(pointer_left, this); - go_west->setGeometry (getScrollWidth() - 5, getScrollHeight() - 2, 5, 1); - - wchar_t pointer_up = wchar_t(finalcut::fc::BlackUpPointingTriangle); - go_north = new finalcut::FButton(pointer_up, this); - go_north->setGeometry (1, getScrollHeight() - 2, 5, 1); + // Sets the navigation button geometry + go_east.setGeometry (1, 1, 5, 1); + go_south.setGeometry (getScrollWidth() - 5, 1, 5, 1); + go_west.setGeometry (getScrollWidth() - 5, getScrollHeight() - 2, 5, 1); + go_north.setGeometry (1, getScrollHeight() - 2, 5, 1); // Add scroll function callbacks to the buttons - go_east->addCallback + go_east.addCallback ( "clicked", F_METHOD_CALLBACK (this, &Scrollview::cb_go_east) ); - go_south->addCallback + go_south.addCallback ( "clicked", F_METHOD_CALLBACK (this, &Scrollview::cb_go_south) ); - go_west->addCallback + go_west.addCallback ( "clicked", F_METHOD_CALLBACK (this, &Scrollview::cb_go_west) ); - go_north->addCallback + go_north.addCallback ( "clicked", F_METHOD_CALLBACK (this, &Scrollview::cb_go_north) @@ -124,9 +121,9 @@ Scrollview::~Scrollview() void Scrollview::setScrollSize (int width, int height) { FScrollView::setScrollSize (width, height); - go_south->setPos (width - 5, 1); - go_west->setPos (width - 5, height - 1); - go_north->setPos (1, height - 1); + go_south.setPos (width - 5, 1); + go_west.setPos (width - 5, height - 1); + go_north.setPos (1, height - 1); } //---------------------------------------------------------------------- @@ -156,36 +153,36 @@ void Scrollview::draw() void Scrollview::cb_go_east (finalcut::FWidget*, data_ptr) { scrollToX (getScrollWidth() - getViewportWidth() + 1); - go_south->setFocus(); - go_east->redraw(); - go_south->redraw(); + go_south.setFocus(); + go_east.redraw(); + go_south.redraw(); } //---------------------------------------------------------------------- void Scrollview::cb_go_south (finalcut::FWidget*, data_ptr) { scrollToY (getScrollHeight() - getViewportHeight() + 1); - go_west->setFocus(); - go_south->redraw(); - go_west->redraw(); + go_west.setFocus(); + go_south.redraw(); + go_west.redraw(); } //---------------------------------------------------------------------- void Scrollview::cb_go_west (finalcut::FWidget*, data_ptr) { scrollToX (1); - go_north->setFocus(); - go_west->redraw(); - go_north->redraw(); + go_north.setFocus(); + go_west.redraw(); + go_north.redraw(); } //---------------------------------------------------------------------- void Scrollview::cb_go_north (finalcut::FWidget*, data_ptr) { scrollToY (1); - go_east->setFocus(); - go_north->redraw(); - go_east->redraw(); + go_east.setFocus(); + go_north.redraw(); + go_east.redraw(); } @@ -210,6 +207,11 @@ class Scrollviewdemo : public finalcut::FDialog // Callback method void cb_quit (finalcut::FWidget* = 0, data_ptr = 0); + + // Data Members + Scrollview sview; + finalcut::FButton quit_btn; + finalcut::FLabel label; }; #pragma pack(pop) @@ -217,31 +219,31 @@ class Scrollviewdemo : public finalcut::FDialog //---------------------------------------------------------------------- Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent) : finalcut::FDialog(parent) + , sview(this) + , quit_btn("&Quit", this) + , label(this) { setGeometry (16, 3, 50, 19); setText ("Scrolling viewport example"); // The scrolling viewport widget - Scrollview* sview = new Scrollview (this); - sview->setGeometry(3, 2, 44, 12); - sview->setScrollSize(188, 124); + sview.setGeometry(3, 2, 44, 12); + sview.setScrollSize(188, 124); // Quit button - finalcut::FButton* button = new finalcut::FButton("&Quit", this); - button->setGeometry(37, 15, 10, 1); + quit_btn.setGeometry(37, 15, 10, 1); // Add function callback - button->addCallback + quit_btn.addCallback ( "clicked", F_METHOD_CALLBACK (this, &Scrollviewdemo::cb_quit) ); // Text label - finalcut::FLabel* label = new finalcut::FLabel (this); - label->setGeometry(2, 1, 46, 1); - label->setEmphasis(); - *label << L"Use scrollbars to change the viewport position"; + label.setGeometry(2, 1, 46, 1); + label.setEmphasis(); + label << L"Use scrollbars to change the viewport position"; } //---------------------------------------------------------------------- diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index 843ad30b..c6b3df2a 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -61,8 +61,8 @@ class AttribDlg : public finalcut::FDialog virtual void adjustSize(); // Data Members - finalcut::FButton* next_button; - finalcut::FButton* back_button; + finalcut::FButton next_button; + finalcut::FButton back_button; }; #pragma pack(pop) @@ -70,28 +70,26 @@ class AttribDlg : public finalcut::FDialog AttribDlg::AttribDlg (finalcut::FWidget* parent) : finalcut::FDialog(parent) , bgcolor(wc.label_bg) - , next_button() - , back_button() + , next_button("&Next >", this) + , back_button("< &Back", this) { setText ( "A terminal attributes test (" + finalcut::FString(getTermType()) + ")"); - next_button = new finalcut::FButton("&Next >", this); - next_button->setGeometry(getWidth() - 13, getHeight() - 4, 10, 1); - next_button->addAccelerator(finalcut::fc::Fkey_right); - back_button = new finalcut::FButton("< &Back", this); - back_button->setGeometry(getWidth() - 25, getHeight() - 4, 10, 1); - back_button->addAccelerator(finalcut::fc::Fkey_left); + next_button.setGeometry(getWidth() - 13, getHeight() - 4, 10, 1); + next_button.addAccelerator(finalcut::fc::Fkey_right); + back_button.setGeometry(getWidth() - 25, getHeight() - 4, 10, 1); + back_button.addAccelerator(finalcut::fc::Fkey_left); // Add function callbacks - next_button->addCallback + next_button.addCallback ( "clicked", F_METHOD_CALLBACK (this, &AttribDlg::cb_next) ); - back_button->addCallback + back_button.addCallback ( "clicked", F_METHOD_CALLBACK (this, &AttribDlg::cb_back) @@ -167,8 +165,8 @@ void AttribDlg::adjustSize() y = 1; setGeometry(x, y, 69, 21, false); - next_button->setGeometry(getWidth() - 13, getHeight() - 4, 10, 1, false); - back_button->setGeometry(getWidth() - 25, getHeight() - 4, 10, 1, false); + next_button.setGeometry(getWidth() - 13, getHeight() - 4, 10, 1, false); + back_button.setGeometry(getWidth() - 25, getHeight() - 4, 10, 1, false); finalcut::FDialog::adjustSize(); } @@ -492,20 +490,20 @@ int main (int argc, char* argv[]) // Create a dialog box object. // This object will be automatically deleted by // the parent object "app" (FObject destructor). - AttribDlg* dialog = new AttribDlg(&app); + AttribDlg dialog(&app); - dialog->setGeometry (6, 2, 69, 21); - dialog->addAccelerator('q'); // press 'q' to quit - dialog->setShadow(); + dialog.setGeometry (6, 2, 69, 21); + dialog.addAccelerator('q'); // press 'q' to quit + dialog.setShadow(); // Create the attribute demo widget as a child object from the dialog - AttribDemo* demo = new AttribDemo(dialog); - demo->setGeometry (1, 1, 67, 19); + AttribDemo demo(&dialog); + demo.setGeometry (1, 1, 67, 19); // Set the dialog object as main widget - app.setMainWidget(dialog); + app.setMainWidget(&dialog); // Show and start the application - dialog->show(); + dialog.show(); return app.exec(); } diff --git a/examples/termcap.cpp b/examples/termcap.cpp index 479decb5..85fb3e26 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -39,18 +39,32 @@ void booleans(); void numeric(); void string(finalcut::FTermcap::tcap_map*&); + +//---------------------------------------------------------------------- +// struct data +//---------------------------------------------------------------------- + #pragma pack(push) #pragma pack(1) -struct termcap_string +struct data { - const std::string name; - const finalcut::fc::termcaps cap; + static int getNumberOfItems(); + + struct termcap_string + { + const std::string name; + const finalcut::fc::termcaps cap; + }; + + static termcap_string strings[]; }; #pragma pack(pop) -// String data array -static const termcap_string strings[] = +//---------------------------------------------------------------------- +// struct data - string data array +//---------------------------------------------------------------------- +data::termcap_string data::strings[] = { { "t_bell", finalcut::fc::t_bell }, { "t_erase_chars", finalcut::fc::t_erase_chars }, @@ -136,7 +150,12 @@ static const termcap_string strings[] = { "t_key_mouse", finalcut::fc::t_key_mouse } }; -const int last_item = int ( sizeof(strings) / sizeof(strings[0]) ) - 1; +// data inline functions +//---------------------------------------------------------------------- +inline int data::getNumberOfItems() +{ + return int ( sizeof(strings) / sizeof(strings[0]) ) - 1; +} //---------------------------------------------------------------------- @@ -272,10 +291,10 @@ void string(finalcut::FTermcap::tcap_map*& tcap) { std::cout << "\r\n[String]\r\n"; - for (int n = 0; n <= last_item; n++ ) + for (int n = 0; n <= data::getNumberOfItems(); n++ ) { - const std::string name = strings[n].name; - const finalcut::fc::termcaps cap = strings[n].cap; + const std::string name = data::strings[n].name; + const finalcut::fc::termcaps cap = data::strings[n].cap; tcapString (name, tcap[cap].string); } } diff --git a/examples/transparent.cpp b/examples/transparent.cpp index b556e9bc..09ce1df7 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -41,7 +41,6 @@ class Transparent : public finalcut::FDialog inherit_background = 2 } trans_type; - public: // Constructor explicit Transparent (finalcut::FWidget* = 0, trans_type = transparent); @@ -150,9 +149,11 @@ void Transparent::onKeyPress (finalcut::FKeyEvent* ev) class MainWindow : public finalcut::FDialog { - private: - finalcut::FString line1; - finalcut::FString line2; + public: + // Constructor + explicit MainWindow (finalcut::FWidget* = 0); + // Destructor + ~MainWindow(); private: // Disable copy constructor @@ -180,11 +181,13 @@ class MainWindow : public finalcut::FDialog finalcut::FDialog::onKeyPress(ev); } - public: - // Constructor - explicit MainWindow (finalcut::FWidget* = 0); - // Destructor - ~MainWindow(); + // Data Members + finalcut::FString line1; + finalcut::FString line2; + Transparent transpwin; + Transparent shadowwin; + Transparent ibg; + finalcut::FStatusBar status_bar; }; #pragma pack(pop) @@ -193,28 +196,28 @@ MainWindow::MainWindow (finalcut::FWidget* parent) : FDialog(parent) , line1() , line2() + , transpwin(this) + , shadowwin(this, Transparent::shadow) + , ibg(this, Transparent::inherit_background) + , status_bar(this) { line1 = " .-. .-. .-."; line2 = "`._.' `._.' `._.' "; - Transparent* transpwin = new Transparent(this); - transpwin->setText("transparent"); - transpwin->setGeometry (6, 3, 29, 12); - transpwin->unsetTransparentShadow(); + transpwin.setText("transparent"); + transpwin.setGeometry (6, 3, 29, 12); + transpwin.unsetTransparentShadow(); - Transparent* shadowwin = new Transparent(this, Transparent::shadow); - shadowwin->setText("shadow"); - shadowwin->setGeometry (46, 11, 29, 12); - shadowwin->unsetTransparentShadow(); + shadowwin.setText("shadow"); + shadowwin.setGeometry (46, 11, 29, 12); + shadowwin.unsetTransparentShadow(); - Transparent* ibg = new Transparent(this, Transparent::inherit_background); - ibg->setText("inherit background"); - ibg->setGeometry (42, 3, 29, 7); - ibg->unsetTransparentShadow(); + ibg.setText("inherit background"); + ibg.setGeometry (42, 3, 29, 7); + ibg.unsetTransparentShadow(); // Statusbar at the bottom - finalcut::FStatusBar* status_bar = new finalcut::FStatusBar (this); - status_bar->setMessage("Press Q to quit"); + status_bar.setMessage("Press Q to quit"); addAccelerator('q'); unsetTransparentShadow(); diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 55388c02..92da5836 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -54,19 +54,20 @@ class Treeview : public finalcut::FDialog // Methods virtual void adjustSize(); - TreeItem* getAfrica(); - TreeItem* getAsia(); - TreeItem* getEurope(); - TreeItem* getNorthAmerica(); - TreeItem* getSouthAmerica(); - TreeItem* getOceania(); // Event handlers void onClose (finalcut::FCloseEvent*); // Data Members - finalcut::FListView* listView; - finalcut::FButton* Quit; + bool initialized; + finalcut::FListView listView; + finalcut::FButton Quit; + static TreeItem africa[]; + static TreeItem asia[]; + static TreeItem europe[]; + static TreeItem north_america[]; + static TreeItem south_america[]; + static TreeItem oceania[]; }; #pragma pack(pop) @@ -94,192 +95,154 @@ struct Treeview::TreeItem #pragma pack(pop) //---------------------------------------------------------------------- -Treeview::TreeItem* Treeview::getAfrica() -{ - static TreeItem africa[] = - { - { "Algeria", "40,400,000", "15.9", 0 }, - { "Angola", "25,789,024", "20.69", 0 }, - { "Botswana", "2,250,260", "3.7", 0 }, - { "Cameroon", "22,534,532", "39.7", 0 }, - { "Chad", "13,670,084", "8.6", 0 }, - { "Egypt", "94,666,000", "87", 0 }, - { "Ethiopia", "102,374,044", "92.7", 0 }, - { "Ivory Coast", "23,740,424", "63.9", 0 }, - { "Libya", "6,541,948", "3.55", 0 }, - { "Madagascar", "24,430,325", "35.2", 0 }, - { "Mali", "14,517,176", "11.7", 0 }, - { "Mauritania", "4,301,018", "3.4", 0 }, - { "Mozambique", "24,692,144", "28.7", 0 }, - { "Namibia", "2,113,077", "2.54", 0 }, - { "Niger", "20,672,987", "12.1", 0 }, - { "Nigeria", "185,989,640", "197.2", 0 }, - { "Somalia", "14,317,996", "19.31", 0 }, - { "South Africa", "54,956,900", "42.4", 0 }, - { "South Sudan", "12,340,000", "13.33", 0 }, - { "Sudan", "39,578,828", "21.3", 0 }, - { "Tanzania", "51,820,00", "47.5", 0 }, - { "Zambia", "16,212,000", "17.2", 0 }, - { 0, 0, 0, 0 } - }; - - return africa; -} - +// class Treeview - array data //---------------------------------------------------------------------- -Treeview::TreeItem* Treeview::getAsia() +Treeview::TreeItem Treeview::africa[] = { - static TreeItem asia[] = - { - { "Afghanistan", "34,656,032", "49.88", 0 }, - { "China", "1,403,500,365", "145.0", 0 }, - { "India", "1,324,171,354", "393.9", 0 }, - { "Indonesia", "261,115,456", "124.66", 0 }, - { "Iran", "80,829,192", "48.0", 0 }, - { "Iraq", "37,202,572", "82.7", 0 }, - { "Japan", "126,740,000", "336.0", 0 }, - { "Kazakhstan", "17,987,736", "6.49", 0 }, - { "Mongolia", "3,081,677", "1.97", 0 }, - { "Myanmar", "51,486,253", "76.0", 0 }, - { "Pakistan", "207,774,520", "244.4", 0 }, - { "Russia", "144,463,451", "8.4", 0 }, - { "Saudi Arabia", "33,000,000", "15.0", 0 }, - { "Thailand", "68,863,514", "132.1", 0 }, - { "Turkey", "79,814,871", "102.0", 0 }, - { "Turkmenistan", "5,662,544", "10.5", 0 }, - { "Uzbekistan", "32,979,000", "70.5", 0 }, - { "Vietnam", "94,569,072", "276.03", 0 }, - { "Yemen", "27,584,213", "44.7", 0 }, - { 0, 0, 0, 0 } - }; + { "Algeria", "40,400,000", "15.9", 0 }, + { "Angola", "25,789,024", "20.69", 0 }, + { "Botswana", "2,250,260", "3.7", 0 }, + { "Cameroon", "22,534,532", "39.7", 0 }, + { "Chad", "13,670,084", "8.6", 0 }, + { "Egypt", "94,666,000", "87", 0 }, + { "Ethiopia", "102,374,044", "92.7", 0 }, + { "Ivory Coast", "23,740,424", "63.9", 0 }, + { "Libya", "6,541,948", "3.55", 0 }, + { "Madagascar", "24,430,325", "35.2", 0 }, + { "Mali", "14,517,176", "11.7", 0 }, + { "Mauritania", "4,301,018", "3.4", 0 }, + { "Mozambique", "24,692,144", "28.7", 0 }, + { "Namibia", "2,113,077", "2.54", 0 }, + { "Niger", "20,672,987", "12.1", 0 }, + { "Nigeria", "185,989,640", "197.2", 0 }, + { "Somalia", "14,317,996", "19.31", 0 }, + { "South Africa", "54,956,900", "42.4", 0 }, + { "South Sudan", "12,340,000", "13.33", 0 }, + { "Sudan", "39,578,828", "21.3", 0 }, + { "Tanzania", "51,820,00", "47.5", 0 }, + { "Zambia", "16,212,000", "17.2", 0 }, + { 0, 0, 0, 0 } +}; - return asia; -} - -//---------------------------------------------------------------------- -Treeview::TreeItem* Treeview::getEurope() +Treeview::TreeItem Treeview::asia[] = { - static TreeItem europe[] = - { - { "Austria", "8,794,267", "104.0", 0 }, - { "Belarus", "9,498,700", "45.8", 0 }, - { "Bulgaria", "7,101,859", "64.9", 0 }, - { "Czech Republic", "10,610,947", "134.0", 0 }, - { "Finland", "5,506,312", "16.0", 0 }, - { "France", "66,991,000", "103.0", 0 }, - { "Germany", "82,175,700", "227.0", 0 }, - { "Greece", "11,183,716", "82.0", 0 }, - { "Hungary", "9,797,561", "105.3", 0 }, - { "Iceland", "332,529", "3.2", 0 }, - { "Italy", "60,589,445", "201.3", 0 }, - { "Norway", "5,267,146", "15.8", 0 }, - { "Poland", "38,634,007", "123.0", 0 }, - { "Portugal", "10,309,573", "115.0", 0 }, - { "Romania", "19,638,000", "84.4", 0 }, - { "Serbia", "7,058,322", "91.1", 0 }, - { "Spain", "46,468,102", "92.0", 0 }, - { "Sweden", "10,065,389", "22.0", 0 }, - { "United Kingdom", "65,648,000", "270.7", 0 }, - { 0, 0, 0, 0 } - }; + { "Afghanistan", "34,656,032", "49.88", 0 }, + { "China", "1,403,500,365", "145.0", 0 }, + { "India", "1,324,171,354", "393.9", 0 }, + { "Indonesia", "261,115,456", "124.66", 0 }, + { "Iran", "80,829,192", "48.0", 0 }, + { "Iraq", "37,202,572", "82.7", 0 }, + { "Japan", "126,740,000", "336.0", 0 }, + { "Kazakhstan", "17,987,736", "6.49", 0 }, + { "Mongolia", "3,081,677", "1.97", 0 }, + { "Myanmar", "51,486,253", "76.0", 0 }, + { "Pakistan", "207,774,520", "244.4", 0 }, + { "Russia", "144,463,451", "8.4", 0 }, + { "Saudi Arabia", "33,000,000", "15.0", 0 }, + { "Thailand", "68,863,514", "132.1", 0 }, + { "Turkey", "79,814,871", "102.0", 0 }, + { "Turkmenistan", "5,662,544", "10.5", 0 }, + { "Uzbekistan", "32,979,000", "70.5", 0 }, + { "Vietnam", "94,569,072", "276.03", 0 }, + { "Yemen", "27,584,213", "44.7", 0 }, + { 0, 0, 0, 0 } +}; - return europe; -} - -//---------------------------------------------------------------------- -Treeview::TreeItem* Treeview::getNorthAmerica() +Treeview::TreeItem Treeview::europe[] = { - static TreeItem north_america[] = - { - { "Canada", "35,151,728", "3.92", 0 }, - { "Cuba", "11,239,224", "102.3", 0 }, - { "Greenland", "56,483", "0.028", 0 }, - { "Guatemala", "16,582,469", "129.0", 0 }, - { "Honduras", "9,112,867", "64.0", 0 }, - { "Mexico", "119,530,753", "61.0", 0 }, - { "Nicaragua", "6,167,237", "51.0", 0 }, - { "USA", "325,365,189", "35.0", 0 }, - { 0, 0, 0, 0 } - }; + { "Austria", "8,794,267", "104.0", 0 }, + { "Belarus", "9,498,700", "45.8", 0 }, + { "Bulgaria", "7,101,859", "64.9", 0 }, + { "Czech Republic", "10,610,947", "134.0", 0 }, + { "Finland", "5,506,312", "16.0", 0 }, + { "France", "66,991,000", "103.0", 0 }, + { "Germany", "82,175,700", "227.0", 0 }, + { "Greece", "11,183,716", "82.0", 0 }, + { "Hungary", "9,797,561", "105.3", 0 }, + { "Iceland", "332,529", "3.2", 0 }, + { "Italy", "60,589,445", "201.3", 0 }, + { "Norway", "5,267,146", "15.8", 0 }, + { "Poland", "38,634,007", "123.0", 0 }, + { "Portugal", "10,309,573", "115.0", 0 }, + { "Romania", "19,638,000", "84.4", 0 }, + { "Serbia", "7,058,322", "91.1", 0 }, + { "Spain", "46,468,102", "92.0", 0 }, + { "Sweden", "10,065,389", "22.0", 0 }, + { "United Kingdom", "65,648,000", "270.7", 0 }, + { 0, 0, 0, 0 } +}; - return north_america; -} -//---------------------------------------------------------------------- -Treeview::TreeItem* Treeview::getSouthAmerica() +Treeview::TreeItem Treeview::north_america[] = { - static TreeItem south_america[] = - { - { "Argentina", "43,847,430", "14.4", 0 }, - { "Bolivia", "11,410,651", "10.4", 0 }, - { "Brazil", "208,064,000", "24.35", 0 }, - { "Chile", "18,006,407", "24.0", 0 }, - { "Colombia", "49,364,592", "40.74", 0 }, - { "Ecuador", "16,385,068", "58.95", 0 }, - { "Guyana", "773,303", "3.502", 0 }, - { "Paraguay", "6,725,308", "17.2", 0 }, - { "Peru", "31,826,018", "23.0", 0 }, - { "Venezuela", "31,568,179", "33.75", 0 }, - { 0, 0, 0, 0 } - }; + { "Canada", "35,151,728", "3.92", 0 }, + { "Cuba", "11,239,224", "102.3", 0 }, + { "Greenland", "56,483", "0.028", 0 }, + { "Guatemala", "16,582,469", "129.0", 0 }, + { "Honduras", "9,112,867", "64.0", 0 }, + { "Mexico", "119,530,753", "61.0", 0 }, + { "Nicaragua", "6,167,237", "51.0", 0 }, + { "USA", "325,365,189", "35.0", 0 }, + { 0, 0, 0, 0 } +}; - return south_america; -} - -//---------------------------------------------------------------------- -Treeview::TreeItem* Treeview::getOceania() +Treeview::TreeItem Treeview::south_america[] = { - static TreeItem oceania[] = - { - { "Australia", "24,675,900", "3.2", 0 }, - { "Papua New Guinea", "7,059,653", "15.0", 0 }, - { "Papua", "3,486,432", "11.0", 0 }, - { "New Zealand", "4,823,090", "17.5", 0 }, - { "West Papua", "877,437", "6.3", 0 }, - { "Solomon Islands", "599,419", "18.1", 0 }, - { "New Caledonia", "268,767", "14.5", 0 }, - { "Fiji", "898,76", "46.4", 0 }, - { "Hawaii", "1,428,557", "82.6", 0 }, - { "Vanuatu", "270,402", "19.7", 0 }, - { "French Polynesia", "280,208", "76.0", 0 }, - { "Samoa", "192,342", "68.0", 0 }, - { "Kiribati", "110,136", "152.0", 0 }, - { 0, 0, 0, 0 } - }; + { "Argentina", "43,847,430", "14.4", 0 }, + { "Bolivia", "11,410,651", "10.4", 0 }, + { "Brazil", "208,064,000", "24.35", 0 }, + { "Chile", "18,006,407", "24.0", 0 }, + { "Colombia", "49,364,592", "40.74", 0 }, + { "Ecuador", "16,385,068", "58.95", 0 }, + { "Guyana", "773,303", "3.502", 0 }, + { "Paraguay", "6,725,308", "17.2", 0 }, + { "Peru", "31,826,018", "23.0", 0 }, + { "Venezuela", "31,568,179", "33.75", 0 }, + { 0, 0, 0, 0 } +}; - return oceania; -} +Treeview::TreeItem Treeview::oceania[] = +{ + { "Australia", "24,675,900", "3.2", 0 }, + { "Papua New Guinea", "7,059,653", "15.0", 0 }, + { "Papua", "3,486,432", "11.0", 0 }, + { "New Zealand", "4,823,090", "17.5", 0 }, + { "West Papua", "877,437", "6.3", 0 }, + { "Solomon Islands", "599,419", "18.1", 0 }, + { "New Caledonia", "268,767", "14.5", 0 }, + { "Fiji", "898,76", "46.4", 0 }, + { "Hawaii", "1,428,557", "82.6", 0 }, + { "Vanuatu", "270,402", "19.7", 0 }, + { "French Polynesia", "280,208", "76.0", 0 }, + { "Samoa", "192,342", "68.0", 0 }, + { "Kiribati", "110,136", "152.0", 0 }, + { 0, 0, 0, 0 } +}; +// constructors and destructor //---------------------------------------------------------------------- Treeview::Treeview (finalcut::FWidget* parent) : finalcut::FDialog(parent) - , listView() - , Quit() + , initialized(false) + , listView(this) + , Quit(this) { // Create FListView object - listView = new finalcut::FListView (this); - listView->setGeometry(2, 1, 53, 14); + listView.setGeometry(2, 1, 53, 14); // Add columns to the view - listView->addColumn ("Name", 23); - listView->addColumn ("Population"); - listView->addColumn ("Density/km²"); + listView.addColumn ("Name", 23); + listView.addColumn ("Population"); + listView.addColumn ("Density/km²"); // Set right alignment for the second and third column - listView->setColumnAlignment (2, finalcut::fc::alignRight); - listView->setColumnAlignment (3, finalcut::fc::alignRight); + listView.setColumnAlignment (2, finalcut::fc::alignRight); + listView.setColumnAlignment (3, finalcut::fc::alignRight); // Activate tree view - listView->setTreeView(); + listView.setTreeView(); // Populate FListView with a list of items - TreeItem* africa = getAfrica(); - TreeItem* asia = getAsia(); - TreeItem* europe = getEurope(); - TreeItem* north_america = getNorthAmerica(); - TreeItem* south_america = getSouthAmerica(); - TreeItem* oceania = getOceania(); - static TreeItem continent[] = { { "Africa", "944,000,000", "31.2", africa }, @@ -300,13 +263,13 @@ Treeview::Treeview (finalcut::FWidget* parent) finalcut::FStringList continent_line ( continent_list->begin() , continent_list->end() ); finalcut::FListViewIterator::FObjectIterator iter = \ - listView->insert (continent_line); + listView.insert (continent_line); while ( country_list && country_list->name ) { finalcut::FStringList country_line ( country_list->begin() , country_list->end() ); - listView->insert (country_line, iter); + listView.insert (country_line, iter); country_list++; } @@ -314,16 +277,17 @@ Treeview::Treeview (finalcut::FWidget* parent) } // Quit button - Quit = new finalcut::FButton (this); - Quit->setGeometry(24, 16, 10, 1); - Quit->setText (L"&Quit"); + Quit.setGeometry(24, 16, 10, 1); + Quit.setText (L"&Quit"); // Add some function callbacks - Quit->addCallback + Quit.addCallback ( "clicked", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) ); + + initialized = true; } //---------------------------------------------------------------------- @@ -342,11 +306,11 @@ void Treeview::adjustSize() setX (X, false); - if ( listView ) - listView->setHeight (getHeight() - 6, false); - - if ( Quit ) - Quit->setY(getHeight() - 4); + if ( initialized ) + { + listView.setHeight (getHeight() - 6, false); + Quit.setY(getHeight() - 4); + } finalcut::FDialog::adjustSize(); } diff --git a/examples/ui.cpp b/examples/ui.cpp index 318e585c..4ede5747 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -59,59 +59,55 @@ class ProgressDialog : public finalcut::FDialog void cb_exit_bar (finalcut::FWidget*, data_ptr); // Data Members - finalcut::FProgressbar* progressBar; - finalcut::FButton* reset; - finalcut::FButton* more; - finalcut::FButton* quit; + finalcut::FProgressbar progressBar; + finalcut::FButton reset; + finalcut::FButton more; + finalcut::FButton quit; }; #pragma pack(pop) //---------------------------------------------------------------------- ProgressDialog::ProgressDialog (finalcut::FWidget* parent) : finalcut::FDialog(parent) - , progressBar() - , reset() - , more() - , quit() + , progressBar(this) + , reset(this) + , more(this) + , quit(this) { setGeometry (int((getParentWidget()->getWidth() - 40) / 2), 7, 40, 10); setText("Progress bar"); //setModal(); - reset = new finalcut::FButton(this); - reset->setText("&Reset"); - reset->setStatusbarMessage ("Reset the progress bar"); - reset->setGeometry(2, 6, 8, 1, false); - reset->setDisable(); + reset.setText("&Reset"); + reset.setStatusbarMessage ("Reset the progress bar"); + reset.setGeometry(2, 6, 8, 1, false); + reset.setDisable(); - more = new finalcut::FButton(this); - more->setText("&More"); - more->setStatusbarMessage ("Increases the progress bar position"); - more->setGeometry(15, 6, 8, 1, false); - more->setDisable(); + more.setText("&More"); + more.setStatusbarMessage ("Increases the progress bar position"); + more.setGeometry(15, 6, 8, 1, false); + more.setDisable(); - quit = new finalcut::FButton(this); - quit->setText("E&xit"); - quit->setGeometry(28, 6, 8, 1, false); - quit->setDisable(); + quit.setText("E&xit"); + quit.setGeometry(28, 6, 8, 1, false); + quit.setDisable(); - progressBar = new finalcut::FProgressbar(this); - progressBar->setGeometry(2, 3, 34, 1, false); - //progressBar->setPercentage(78); + progressBar.setGeometry(2, 3, 34, 1, false); + //progressBar.setPercentage(78); - reset->addCallback + reset.addCallback ( "clicked", F_METHOD_CALLBACK (this, &ProgressDialog::cb_reset_bar) ); - more->addCallback + more.addCallback ( "clicked", F_METHOD_CALLBACK (this, &ProgressDialog::cb_more_bar) ); - quit->addCallback + quit.addCallback ( "clicked", F_METHOD_CALLBACK (this, &ProgressDialog::cb_exit_bar) @@ -122,13 +118,9 @@ ProgressDialog::ProgressDialog (finalcut::FWidget* parent) ProgressDialog::~ProgressDialog() // destructor { delOwnTimer(); - delCallback(quit); - delCallback(more); - delCallback(reset); - delete(progressBar); - delete(quit); - delete(more); - delete(reset); + delCallback(&quit); + delCallback(&more); + delCallback(&reset); } //---------------------------------------------------------------------- @@ -140,8 +132,8 @@ void ProgressDialog::onShow (finalcut::FShowEvent*) //---------------------------------------------------------------------- void ProgressDialog::onTimer (finalcut::FTimerEvent*) { - int p = progressBar->getPercentage(); - progressBar->setPercentage(++p); + int p = progressBar.getPercentage(); + progressBar.setPercentage(++p); flush_out(); if ( p != 100 ) @@ -150,10 +142,10 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*) delOwnTimer(); activateWindow(); raiseWindow(); - reset->setEnable(); - reset->setFocus(); - more->setEnable(); - quit->setEnable(); + reset.setEnable(); + reset.setFocus(); + more.setEnable(); + quit.setEnable(); redraw(); if ( getStatusBar() ) @@ -166,14 +158,14 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*) //---------------------------------------------------------------------- void ProgressDialog::cb_reset_bar (finalcut::FWidget*, data_ptr) { - progressBar->reset(); + progressBar.reset(); } //---------------------------------------------------------------------- void ProgressDialog::cb_more_bar (finalcut::FWidget*, data_ptr) { - int p = progressBar->getPercentage(); - progressBar->setPercentage(++p); + int p = progressBar.getPercentage(); + progressBar.setPercentage(++p); } //---------------------------------------------------------------------- @@ -211,28 +203,27 @@ class TextWindow : public finalcut::FDialog virtual void adjustSize(); // Data Members - finalcut::FTextView* scrollText; + finalcut::FTextView scrollText; }; #pragma pack(pop) //---------------------------------------------------------------------- TextWindow::TextWindow (finalcut::FWidget* parent) : finalcut::FDialog(parent) - , scrollText() + , scrollText(this) { - scrollText = new finalcut::FTextView(this); - scrollText->ignorePadding(); - scrollText->setGeometry (1, 2, getWidth(), getHeight() - 1); + scrollText.ignorePadding(); + scrollText.setGeometry (1, 2, getWidth(), getHeight() - 1); setMinimumSize (51, 6); - scrollText->setFocus(); - scrollText->insert(" -----------------------------------------------\n" - " line 1\n" - " -----------------------------------------------\n" - " line 3\n" - " line 4" - , -1); - scrollText->replaceRange(" File viewer", 1, 1); - scrollText->deleteRange(3, 4); + scrollText.setFocus(); + scrollText.insert(" -----------------------------------------------\n" + " line 1\n" + " -----------------------------------------------\n" + " line 3\n" + " line 4" + , -1); + scrollText.replaceRange(" File viewer", 1, 1); + scrollText.deleteRange(3, 4); } //---------------------------------------------------------------------- @@ -242,14 +233,14 @@ TextWindow::~TextWindow() // destructor //---------------------------------------------------------------------- void TextWindow::append (const finalcut::FString& str) { - scrollText->append(str); + scrollText.append(str); } //---------------------------------------------------------------------- void TextWindow::adjustSize() { finalcut::FDialog::adjustSize(); - scrollText->setGeometry (1, 2, getWidth(), getHeight() - 1); + scrollText.setGeometry (1, 2, getWidth(), getHeight() - 1); } @@ -281,7 +272,6 @@ class MyDialog : public finalcut::FDialog void initEditMenuCallbacks(); void initViewMenuCallbacks(); void initHelpMenuCallback(); - void initStatusBar(); void initStatusBarCallbacks(); void initWidgets(); void initFlatButtons(); @@ -312,71 +302,115 @@ class MyDialog : public finalcut::FDialog void cb_setInput (finalcut::FWidget*, data_ptr); // Data Members - finalcut::FMenuItem* Open; - finalcut::FMenuItem* Quit; - finalcut::FMenuItem* File1; - finalcut::FMenuItem* File2; - finalcut::FMenuItem* File3; - finalcut::FMenuItem* Cut; - finalcut::FMenuItem* Copy; - finalcut::FMenuItem* Paste; - finalcut::FMenuItem* Clear; - finalcut::FMenuItem* Env; - finalcut::FMenuItem* Drive; - finalcut::FMenuItem* Help; - finalcut::FStatusKey* key_F1; - finalcut::FStatusKey* key_F2; - finalcut::FStatusKey* key_F3; - finalcut::FButton* MyButton1; - finalcut::FButton* MyButton2; - finalcut::FButton* MyButton3; - finalcut::FButton* MyButton4; - finalcut::FButton* MyButton5; - finalcut::FButton* MyButton6; - finalcut::FRadioButton* radio1; - finalcut::FLabel* tagged_count; - finalcut::FLineEdit* myLineEdit; - finalcut::FListBox* myList; - finalcut::FString clipboard; + bool initialized; + finalcut::FMenuBar Menubar; + finalcut::FMenu File; // Menu bar items + finalcut::FMenu Edit; + finalcut::FMenu View; + finalcut::FMenuItem Options; + finalcut::FDialogListMenu Window; + finalcut::FMenuItem Help; + finalcut::FMenuItem Open; // "File" menu items + finalcut::FMenu Recent; + finalcut::FMenuItem Line1; + finalcut::FMenuItem Quit; + finalcut::FMenuItem File1; // "Recent" menu items + finalcut::FMenuItem File2; + finalcut::FMenuItem File3; + finalcut::FMenuItem Undo; + finalcut::FMenuItem Redo; + finalcut::FMenuItem Line2; + finalcut::FMenuItem Cut; + finalcut::FMenuItem Copy; + finalcut::FMenuItem Paste; + finalcut::FMenuItem Clear; + finalcut::FMenuItem Env; + finalcut::FMenuItem Drive; + finalcut::FStatusBar Statusbar; + finalcut::FStatusKey key_F1; + finalcut::FStatusKey key_F2; + finalcut::FStatusKey key_F3; + finalcut::FButton MyButton1; + finalcut::FButton MyButton2; + finalcut::FButton MyButton3; + finalcut::FButtonGroup radioButtonGroup; + finalcut::FRadioButton radio1; + finalcut::FRadioButton radio2; + finalcut::FButtonGroup checkButtonGroup; + finalcut::FCheckBox check1; + finalcut::FCheckBox check2; + finalcut::FLineEdit myLineEdit; + finalcut::FButton MyButton4; + finalcut::FButton MyButton5; + finalcut::FButton MyButton6; + finalcut::FListBox myList; + finalcut::FLabel headline; + finalcut::FLabel tagged; + finalcut::FLabel tagged_count; + finalcut::FLabel sum; + finalcut::FLabel sum_count; + finalcut::FString clipboard; }; #pragma pack(pop) //---------------------------------------------------------------------- MyDialog::MyDialog (finalcut::FWidget* parent) : finalcut::FDialog(parent) - , Open() - , Quit() - , File1() - , File2() - , File3() - , Cut() - , Copy() - , Paste() - , Clear() - , Env() - , Drive() - , Help() - , key_F1() - , key_F2() - , key_F3() - , MyButton1() - , MyButton2() - , MyButton3() - , MyButton4() - , MyButton5() - , MyButton6() - , radio1() - , tagged_count() - , myLineEdit() - , myList() + , initialized(false) + , Menubar(this) + , File("&File", &Menubar) + , Edit("&Edit", &Menubar) + , View("&View", &Menubar) + , Options("&Options", &Menubar) + , Window("&Window", &Menubar) + , Help("&Help", &Menubar) + , Open("&Open...", &File) + , Recent("&System files", &File) + , Line1(&File) + , Quit("&Quit", &File) + , File1("/etc/services", &Recent) + , File2("/etc/fstab", &Recent) + , File3("/etc/passwd", &Recent) + , Undo(finalcut::fc::Fckey_z, "Undo", &Edit) + , Redo(finalcut::fc::Fckey_y, "Redo", &Edit) + , Line2(&Edit) + , Cut(finalcut::fc::Fckey_x, "Cu&t", &Edit) + , Copy(finalcut::fc::Fckey_c, "&Copy", &Edit) + , Paste(finalcut::fc::Fckey_v, "&Paste", &Edit) + , Clear(finalcut::fc::Fkey_dc, "C&lear", &Edit) + , Env("&Terminal...", &View) + , Drive("&Drive symbols...", &View) + , Statusbar(this) + , key_F1(finalcut::fc::Fkey_f1, "About", &Statusbar) + , key_F2(finalcut::fc::Fkey_f2, "View", &Statusbar) + , key_F3(finalcut::fc::Fkey_f3, "Quit", &Statusbar) + , MyButton1(this) + , MyButton2(this) + , MyButton3(this) + , radioButtonGroup("Button", this) + , radio1("E&nable", &radioButtonGroup) + , radio2(&radioButtonGroup) + , checkButtonGroup("Options", this) + , check1("&Bitmode", &checkButtonGroup) + , check2("&8-Bit", &checkButtonGroup) + , myLineEdit(this) + , MyButton4(this) + , MyButton5(this) + , MyButton6(this) + , myList(this) + , headline(this) + , tagged(L"Tagged:", this) + , tagged_count(this) + , sum(L"Sum:", this) + , sum_count(this) , clipboard() { initMenu(); // Initialize the program menu initMenuCallbacks(); // Initialize program menu callbacks - initStatusBar(); // Initialize the status bar initStatusBarCallbacks(); // Initialize status bar callbacks initWidgets(); // Initialize the dialog widgets initWidgetsCallbacks(); // Initialize dialog widget callbacks + initialized = true; } //---------------------------------------------------------------------- @@ -386,69 +420,36 @@ MyDialog::~MyDialog() // destructor //---------------------------------------------------------------------- void MyDialog::initMenu() { - // Menu bar - finalcut::FMenuBar* Menubar = new finalcut::FMenuBar (this); - // Menu bar items - finalcut::FMenu* File = new finalcut::FMenu ("&File", Menubar); - File->setStatusbarMessage ("File management commands"); - finalcut::FMenu* Edit = new finalcut::FMenu ("&Edit", Menubar); - Edit->setStatusbarMessage ("Cut-and-paste editing commands"); - finalcut::FMenu* View = new finalcut::FMenu ("&View", Menubar); - View->setStatusbarMessage ("Show internal informations"); - finalcut::FMenuItem* Options = \ - new finalcut::FMenuItem ("&Options", Menubar); - Options->setStatusbarMessage ("Set program defaults"); - Options->setDisable(); - finalcut::FDialogListMenu* Window = \ - new finalcut::FDialogListMenu ("&Window", Menubar); - Window->setStatusbarMessage ("List of all the active dialogs"); - Help = new finalcut::FMenuItem ("&Help", Menubar); - Help->setStatusbarMessage ("Show version and copyright information"); + File.setStatusbarMessage ("File management commands"); + Edit.setStatusbarMessage ("Cut-and-paste editing commands"); + View.setStatusbarMessage ("Show internal informations"); + Options.setStatusbarMessage ("Set program defaults"); + Options.setDisable(); + Window.setStatusbarMessage ("List of all the active dialogs"); + Help.setStatusbarMessage ("Show version and copyright information"); // "File" menu items - Open = new finalcut::FMenuItem ("&Open...", File); - Open->addAccelerator (finalcut::fc::Fckey_o); // Ctrl + O - Open->setStatusbarMessage ("Locate and open a text file"); - finalcut::FMenu* Recent = new finalcut::FMenu ("&System files", File); - Recent->setStatusbarMessage ("View text file"); - - finalcut::FMenuItem* Line1 = new finalcut::FMenuItem (File); - Line1->setSeparator(); - Quit = new finalcut::FMenuItem ("&Quit", File); - Quit->addAccelerator (finalcut::fc::Fmkey_x); // Meta/Alt + X - Quit->setStatusbarMessage ("Exit the program"); - - // "Recent" menu items - File1 = new finalcut::FMenuItem ("/etc/services", Recent); - File2 = new finalcut::FMenuItem ("/etc/fstab", Recent); - File3 = new finalcut::FMenuItem ("/etc/passwd", Recent); + Open.addAccelerator (finalcut::fc::Fckey_o); // Ctrl + O + Open.setStatusbarMessage ("Locate and open a text file"); + Recent.setStatusbarMessage ("View text file"); + Line1.setSeparator(); + Quit.addAccelerator (finalcut::fc::Fmkey_x); // Meta/Alt + X + Quit.setStatusbarMessage ("Exit the program"); // "Edit" menu items - finalcut::FMenuItem* Undo = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_z, "Undo", Edit); - Undo->setDisable(); - finalcut::FMenuItem* Redo = \ - new finalcut::FMenuItem (finalcut::fc::Fckey_y, "Redo", Edit); - Redo->setDisable(); - finalcut::FMenuItem* Line2 = \ - new finalcut::FMenuItem (Edit); - Line2->setSeparator(); - Cut = new finalcut::FMenuItem (finalcut::fc::Fckey_x, "Cu&t", Edit); - Cut->setStatusbarMessage ( "Remove the input text" - " and put it in the clipboard" ); - Copy= new finalcut::FMenuItem (finalcut::fc::Fckey_c, "&Copy", Edit); - Copy->setStatusbarMessage ("Copy the input text into the clipboad"); - Paste = new finalcut::FMenuItem (finalcut::fc::Fckey_v, "&Paste", Edit); - Paste->setStatusbarMessage ("Insert text form clipboard"); - Clear = new finalcut::FMenuItem (finalcut::fc::Fkey_dc, "C&lear", Edit); - Clear->setStatusbarMessage ("Delete input text"); + Undo.setDisable(); + Redo.setDisable(); + Line2.setSeparator(); + Cut.setStatusbarMessage ( "Remove the input text" + " and put it in the clipboard" ); + Copy.setStatusbarMessage ("Copy the input text into the clipboad"); + Paste.setStatusbarMessage ("Insert text form clipboard"); + Clear.setStatusbarMessage ("Delete input text"); // "View" menu items - Env = new finalcut::FMenuItem ("&Terminal...", View); - Env->setStatusbarMessage ("Informations about this terminal"); - Drive = new finalcut::FMenuItem ("&Drive symbols...", View); - Drive->setStatusbarMessage ("Show drive symbols"); + Env.setStatusbarMessage ("Informations about this terminal"); + Drive.setStatusbarMessage ("Show drive symbols"); } //---------------------------------------------------------------------- @@ -465,38 +466,38 @@ void MyDialog::initMenuCallbacks() void MyDialog::initFileMenuCallbacks() { // File menu - Open->addCallback + Open.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_view) ); - Quit->addCallback + Quit.addCallback ( "clicked", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) ); // System files submenu - File1->addCallback + File1.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_view), - static_cast(File1) + static_cast(&File1) ); - File2->addCallback + File2.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_view), - static_cast(File2) + static_cast(&File2) ); - File3->addCallback + File3.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_view), - static_cast(File3) + static_cast(&File3) ); } @@ -504,25 +505,25 @@ void MyDialog::initFileMenuCallbacks() void MyDialog::initEditMenuCallbacks() { // Edit menu - Cut->addCallback + Cut.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_cutClipboard) ); - Copy->addCallback + Copy.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_copyClipboard) ); - Paste->addCallback + Paste.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_pasteClipboard) ); - Clear->addCallback + Clear.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_clearInput) @@ -533,13 +534,13 @@ void MyDialog::initEditMenuCallbacks() void MyDialog::initViewMenuCallbacks() { // View menu - Env->addCallback + Env.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_terminfo) ); - Drive->addCallback + Drive.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_drives) @@ -549,43 +550,31 @@ void MyDialog::initViewMenuCallbacks() //---------------------------------------------------------------------- void MyDialog::initHelpMenuCallback() { - Help->addCallback + Help.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_about) ); } -//---------------------------------------------------------------------- -void MyDialog::initStatusBar() -{ - // Statusbar at the bottom - finalcut::FStatusBar* Statusbar = new finalcut::FStatusBar (this); - - // Statusbar keys - key_F1 = new finalcut::FStatusKey (finalcut::fc::Fkey_f1, "About", Statusbar); - key_F2 = new finalcut::FStatusKey (finalcut::fc::Fkey_f2, "View", Statusbar); - key_F3 = new finalcut::FStatusKey (finalcut::fc::Fkey_f3, "Quit", Statusbar); -} - //---------------------------------------------------------------------- void MyDialog::initStatusBarCallbacks() { // Add statusbar function callbacks - key_F1->addCallback + key_F1.addCallback ( "activate", F_METHOD_CALLBACK (this, &MyDialog::cb_about) ); - key_F2->addCallback + key_F2.addCallback ( "activate", F_METHOD_CALLBACK (this, &MyDialog::cb_view) ); - key_F3->addCallback + key_F3.addCallback ( "activate", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) @@ -602,24 +591,22 @@ void MyDialog::initWidgets() initToggleButtons(); // A text input field - myLineEdit = new finalcut::FLineEdit (this); - myLineEdit->setGeometry(22, 1, 10, 1); - myLineEdit->setLabelText (L"&Input"); - myLineEdit->setStatusbarMessage ("Press Enter to set the title"); - *myLineEdit << finalcut::FString("EnTry").toLower(); + myLineEdit.setGeometry(22, 1, 10, 1); + myLineEdit.setLabelText (L"&Input"); + myLineEdit.setStatusbarMessage ("Press Enter to set the title"); + myLineEdit << finalcut::FString("EnTry").toLower(); // Buttons initButtons(); // A multiple selection listbox - myList = new finalcut::FListBox (this); - myList->setGeometry(38, 1, 14, 17); - myList->setText ("Items"); - myList->setStatusbarMessage ("99 items in a list"); - myList->setMultiSelection(); + myList.setGeometry(38, 1, 14, 17); + myList.setText ("Items"); + myList.setStatusbarMessage ("99 items in a list"); + myList.setMultiSelection(); for (int z = 1; z < 100; z++) - myList->insert (finalcut::FString() << z << L" placeholder"); + myList.insert (finalcut::FString() << z << L" placeholder"); // Text labels initLabels(); @@ -629,43 +616,40 @@ void MyDialog::initWidgets() void MyDialog::initFlatButtons() { // Flat buttons - MyButton1 = new finalcut::FButton (this); - MyButton1->setGeometry(3, 3, 5, 1); - MyButton1->setText (L"&SIN"); - MyButton1->setStatusbarMessage ("Sine function"); - MyButton1->setNoUnderline(); - MyButton1->setFlat(); - MyButton1->setDoubleFlatLine (finalcut::fc::bottom); + MyButton1.setGeometry(3, 3, 5, 1); + MyButton1.setText (L"&SIN"); + MyButton1.setStatusbarMessage ("Sine function"); + MyButton1.setNoUnderline(); + MyButton1.setFlat(); + MyButton1.setDoubleFlatLine (finalcut::fc::bottom); - MyButton2 = new finalcut::FButton (this); - MyButton2->setGeometry(3, 5, 5, 1); - MyButton2->setText (L"&COS"); - MyButton2->setStatusbarMessage ("Cosine function"); - MyButton2->setNoUnderline(); - MyButton2->setFlat(); - MyButton2->setDoubleFlatLine (finalcut::fc::top); + MyButton2.setGeometry(3, 5, 5, 1); + MyButton2.setText (L"&COS"); + MyButton2.setStatusbarMessage ("Cosine function"); + MyButton2.setNoUnderline(); + MyButton2.setFlat(); + MyButton2.setDoubleFlatLine (finalcut::fc::top); - MyButton3 = new finalcut::FButton (this); - MyButton3->setGeometry(10, 3, 5, 3); - MyButton3->setText (L"&="); - MyButton3->setStatusbarMessage ("Equal"); - MyButton3->setNoUnderline(); - MyButton3->setFlat(); + MyButton3.setGeometry(10, 3, 5, 3); + MyButton3.setText (L"&="); + MyButton3.setStatusbarMessage ("Equal"); + MyButton3.setNoUnderline(); + MyButton3.setFlat(); // Add button callback functions - MyButton1->addCallback + MyButton1.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg) ); - MyButton2->addCallback + MyButton2.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg) ); - MyButton3->addCallback + MyButton3.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg) @@ -676,77 +660,63 @@ void MyDialog::initFlatButtons() void MyDialog::initToggleButtons() { // Radio buttons in a group - finalcut::FButtonGroup* radioButtonGroup = \ - new finalcut::FButtonGroup ("Button", this); - radioButtonGroup->setGeometry(3, 8, 14, 4); + radioButtonGroup.setGeometry(3, 8, 14, 4); //radioButtonGroup->unsetBorder(); - radio1 = new finalcut::FRadioButton ("E&nable", radioButtonGroup); - radio1->setGeometry(1, 1, 10, 1); - radio1->setStatusbarMessage ("Enable button Test"); + radio1.setGeometry(1, 1, 10, 1); + radio1.setStatusbarMessage ("Enable button Test"); - finalcut::FRadioButton* radio2 = \ - new finalcut::FRadioButton (radioButtonGroup); - radio2->setGeometry(1, 2, 11, 1); - radio2->setText ("&Disable"); - radio2->setStatusbarMessage ("Disable button Test"); - radio2->setChecked(); - //radio2->setDisable(); + radio2.setGeometry(1, 2, 11, 1); + radio2.setText ("&Disable"); + radio2.setStatusbarMessage ("Disable button Test"); + radio2.setChecked(); + //radio2.setDisable(); // Checkboxes in a group - finalcut::FButtonGroup* checkButtonGroup = \ - new finalcut::FButtonGroup ("Options", this); - checkButtonGroup->setGeometry(3, 12, 14, 4); + checkButtonGroup.setGeometry(3, 12, 14, 4); - finalcut::FCheckBox* check1 = \ - new finalcut::FCheckBox ("&Bitmode", checkButtonGroup); - check1->setGeometry(1, 1, 11, 1); - check1->setNoUnderline(); + check1.setGeometry(1, 1, 11, 1); + check1.setNoUnderline(); - finalcut::FCheckBox* check2 = \ - new finalcut::FCheckBox ("&8-Bit", checkButtonGroup); - check2->setGeometry(1, 2, 9, 1); - check2->setChecked(); - check2->setNoUnderline(); + check2.setGeometry(1, 2, 9, 1); + check2.setChecked(); + check2.setNoUnderline(); } //---------------------------------------------------------------------- void MyDialog::initButtons() { // Buttons - MyButton4 = new finalcut::FButton (this); - MyButton4->setGeometry(20, 8, 12, 1); - MyButton4->setText (L"&Get input"); - MyButton4->setStatusbarMessage ("Take text from input field"); - MyButton4->setFocus(); + MyButton4.setGeometry(20, 8, 12, 1); + MyButton4.setText (L"&Get input"); + MyButton4.setStatusbarMessage ("Take text from input field"); + MyButton4.setFocus(); - MyButton5 = new finalcut::FButton (this); - MyButton5->setGeometry(20, 11, 12, 1); - MyButton5->setText (L"&Test"); - MyButton5->setStatusbarMessage ("Progressbar testing dialog"); - MyButton5->setDisable(); + MyButton5.setGeometry(20, 11, 12, 1); + MyButton5.setText (L"&Test"); + MyButton5.setStatusbarMessage ("Progressbar testing dialog"); + MyButton5.setDisable(); - MyButton6 = new finalcut::FButton (this); - MyButton6->setGeometry(20, 14, 12, 1); - MyButton6->setText (L"&Quit"); - MyButton6->setStatusbarMessage ("Exit the program"); - MyButton6->addAccelerator('x'); + MyButton6.setGeometry(20, 14, 12, 1); + MyButton6.setText (L"&Quit"); + MyButton6.setStatusbarMessage ("Exit the program"); + MyButton6.addAccelerator('x'); // Add button callback functions - MyButton4->addCallback + MyButton4.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_input2buttonText), - static_cast(myLineEdit) + static_cast(&myLineEdit) ); - MyButton5->addCallback + MyButton5.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_ProgressBar) ); - MyButton6->addCallback + MyButton6.addCallback ( "clicked", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) @@ -757,26 +727,21 @@ void MyDialog::initButtons() void MyDialog::initLabels() { // Text labels - finalcut::FLabel* headline = new finalcut::FLabel (this); - headline->setGeometry(21, 3, 10, 1); - headline->setEmphasis(); - headline->setAlignment (finalcut::fc::alignCenter); - *headline = L"List items"; + headline.setGeometry(21, 3, 10, 1); + headline.setEmphasis(); + headline.setAlignment (finalcut::fc::alignCenter); + headline = L"List items"; - finalcut::FLabel* tagged = new finalcut::FLabel (L"Tagged:", this); - tagged->setGeometry(21, 4, 7, 1); + tagged.setGeometry(21, 4, 7, 1); - tagged_count = new finalcut::FLabel(this); - tagged_count->setGeometry(29, 4, 5, 1); - *tagged_count << 0; + tagged_count.setGeometry(29, 4, 5, 1); + tagged_count << 0; - finalcut::FLabel* sum = new finalcut::FLabel (L"Sum:", this); - sum->setGeometry(21, 5, 7, 3); - sum->setAlignment (finalcut::fc::alignRight); + sum.setGeometry(21, 5, 7, 3); + sum.setAlignment (finalcut::fc::alignRight); - finalcut::FLabel* sum_count = new finalcut::FLabel (this); - sum_count->setGeometry(29, 5, 5, 3); - *sum_count << myList->getCount(); + sum_count.setGeometry(29, 5, 5, 3); + sum_count << myList.getCount(); } //---------------------------------------------------------------------- @@ -784,31 +749,31 @@ void MyDialog::initWidgetsCallbacks() { // Add some function callbacks - myLineEdit->addCallback + myLineEdit.addCallback ( "activate", // e.g. on F_METHOD_CALLBACK (this, &MyDialog::cb_setTitlebar) ); - radio1->addCallback + radio1.addCallback ( "toggled", F_METHOD_CALLBACK (this, &MyDialog::cb_activateButton), - static_cast(MyButton5) + static_cast(&MyButton5) ); - myList->addCallback + myList.addCallback ( "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_setInput), - static_cast(myLineEdit) + static_cast(&myLineEdit) ); - myList->addCallback + myList.addCallback ( "row-selected", F_METHOD_CALLBACK (this, &MyDialog::cb_updateNumber), - static_cast(tagged_count) + static_cast(&tagged_count) ); } @@ -824,8 +789,8 @@ void MyDialog::adjustSize() setX (X, false); - if ( myList ) - myList->setHeight (getHeight() - 3, false); + if ( initialized ) + myList.setHeight (getHeight() - 3, false); finalcut::FDialog::adjustSize(); } @@ -937,42 +902,30 @@ void MyDialog::cb_drives (finalcut::FWidget*, data_ptr) //---------------------------------------------------------------------- void MyDialog::cb_cutClipboard (finalcut::FWidget*, data_ptr) { - if ( ! myLineEdit ) - return; - - clipboard = myLineEdit->getText(); - myLineEdit->clear(); - myLineEdit->redraw(); + clipboard = myLineEdit.getText(); + myLineEdit.clear(); + myLineEdit.redraw(); } //---------------------------------------------------------------------- void MyDialog::cb_copyClipboard (finalcut::FWidget*, data_ptr) { - if ( ! myLineEdit ) - return; - - clipboard = myLineEdit->getText(); + clipboard = myLineEdit.getText(); } //---------------------------------------------------------------------- void MyDialog::cb_pasteClipboard (finalcut::FWidget*, data_ptr) { - if ( ! myLineEdit ) - return; - - *myLineEdit = clipboard; - myLineEdit->redraw(); + myLineEdit = clipboard; + myLineEdit.redraw(); } //---------------------------------------------------------------------- void MyDialog::cb_clearInput (finalcut::FWidget*, data_ptr) { - if ( ! myLineEdit ) - return; - clipboard.clear(); - myLineEdit->clear(); - myLineEdit->redraw(); + myLineEdit.clear(); + myLineEdit.redraw(); } //---------------------------------------------------------------------- diff --git a/examples/watch.cpp b/examples/watch.cpp index 890d5806..0e00d924 100644 --- a/examples/watch.cpp +++ b/examples/watch.cpp @@ -63,11 +63,12 @@ class Watch : public finalcut::FDialog Watch& operator = (const Watch&); // Data Members - bool sec; - finalcut::FLabel* time_label; - finalcut::FLabel* time_str; - finalcut::FSwitch* clock_sw; - finalcut::FSwitch* seconds_sw; + bool sec; + finalcut::FLabel time_label; + finalcut::FLabel time_str; + finalcut::FSwitch clock_sw; + finalcut::FSwitch seconds_sw; + finalcut::FButton quit_btn; }; #pragma pack(pop) @@ -75,49 +76,45 @@ class Watch : public finalcut::FDialog Watch::Watch (FWidget* parent) : finalcut::FDialog(parent) , sec(true) - , time_label(0) - , time_str(0) - , clock_sw(0) - , seconds_sw(0) + , time_label(L"Time", this) + , time_str(L"--:--:--", this) + , clock_sw(L"Clock", this) + , seconds_sw(L"Seconds", this) + , quit_btn(L"&Quit", this) { setText ("Watch"); int pw = getParentWidget()->getWidth(); setGeometry (1 + (pw - 22) / 2, 3, 22, 13); - // Create labels - time_label = new finalcut::FLabel(L"Time", this); - time_label->setGeometry(5, 2, 5, 1); - time_label->setEmphasis(); - time_str = new finalcut::FLabel(L"--:--:--", this); - time_str->setGeometry(10, 2, 8, 1); + // Labels + time_label.setGeometry(5, 2, 5, 1); + time_label.setEmphasis(); + time_str.setGeometry(10, 2, 8, 1); - // Create checkbox buttons - clock_sw = new finalcut::FSwitch(L"Clock", this); - seconds_sw = new finalcut::FSwitch(L"Seconds", this); - clock_sw->setGeometry(4, 4, 9, 1); - seconds_sw->setGeometry(2, 6, 11, 1); - sec = seconds_sw->setChecked(); + // Checkbox buttons + clock_sw.setGeometry(4, 4, 9, 1); + seconds_sw.setGeometry(2, 6, 11, 1); + sec = seconds_sw.setChecked(); - // Create button - finalcut::FButton* quit_btn = new finalcut::FButton(L"&Quit", this); - quit_btn->setGeometry(6, 9, 9, 1); + // Quit button + quit_btn.setGeometry(6, 9, 9, 1); // Connect switch signal "toggled" with a callback member function - clock_sw->addCallback + clock_sw.addCallback ( "toggled", F_METHOD_CALLBACK (this, &Watch::cb_clock) ); // Connect switch signal "toggled" with a callback member function - seconds_sw->addCallback + seconds_sw.addCallback ( "toggled", F_METHOD_CALLBACK (this, &Watch::cb_seconds) ); // Connect button signal "clicked" with a callback member function - quit_btn->addCallback + quit_btn.addCallback ( "clicked", F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp) @@ -145,8 +142,8 @@ void Watch::printTime() else str.sprintf("%02d:%02d ", now.tm_hour, now.tm_min); - *time_str = str; - time_str->redraw(); + time_str = str; + time_str.redraw(); } //---------------------------------------------------------------------- @@ -164,7 +161,7 @@ void Watch::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void Watch::cb_clock (finalcut::FWidget*, data_ptr) { - if ( clock_sw->isChecked() ) + if ( clock_sw.isChecked() ) { printTime(); addTimer(1000); @@ -172,29 +169,29 @@ void Watch::cb_clock (finalcut::FWidget*, data_ptr) else { delAllTimer(); - *time_str = "--:--:--"; - time_str->redraw(); + time_str = "--:--:--"; + time_str.redraw(); } } //---------------------------------------------------------------------- void Watch::cb_seconds (finalcut::FWidget*, data_ptr) { - if ( seconds_sw->isChecked() ) + if ( seconds_sw.isChecked() ) sec = true; else sec = false; - if ( clock_sw->isChecked() ) + if ( clock_sw.isChecked() ) printTime(); else { if ( sec ) - *time_str = "--:--:--"; + time_str = "--:--:--"; else - *time_str = "--:-- "; + time_str = "--:-- "; - time_str->redraw(); + time_str.redraw(); } } diff --git a/examples/windows.cpp b/examples/windows.cpp index 821ec02a..cbf7cd7e 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -55,61 +55,58 @@ class SmallWindow : public finalcut::FDialog virtual void onTimer (finalcut::FTimerEvent*); // Data Members - finalcut::FLabel* left_arrow; - finalcut::FLabel* right_arrow; - finalcut::FLabel* top_left_label; - finalcut::FLabel* top_right_label; - finalcut::FLabel* bottom_label; + finalcut::FLabel left_arrow; + finalcut::FLabel right_arrow; + finalcut::FLabel top_left_label; + finalcut::FLabel top_right_label; + finalcut::FLabel bottom_label; }; #pragma pack(pop) //---------------------------------------------------------------------- SmallWindow::SmallWindow (finalcut::FWidget* parent) : finalcut::FDialog(parent) - , left_arrow() - , right_arrow() - , top_left_label() - , top_right_label() - , bottom_label() + , left_arrow(this) + , right_arrow(this) + , top_left_label(this) + , top_right_label(this) + , bottom_label(this) { wchar_t arrow_up, arrow_down; - arrow_up = finalcut::fc::BlackUpPointingTriangle; arrow_down = finalcut::fc::BlackDownPointingTriangle; - left_arrow = new finalcut::FLabel (arrow_up, this); - left_arrow->setForegroundColor (wc.label_inactive_fg); - left_arrow->setEmphasis(); - left_arrow->ignorePadding(); - left_arrow->setGeometry (2, 2, 1, 1); + left_arrow = arrow_up; + left_arrow.setForegroundColor (wc.label_inactive_fg); + left_arrow.setEmphasis(); + left_arrow.ignorePadding(); + left_arrow.setGeometry (2, 2, 1, 1); - right_arrow = new finalcut::FLabel (arrow_up, this); - right_arrow->setForegroundColor (wc.label_inactive_fg); - right_arrow->setEmphasis(); - right_arrow->ignorePadding(); - right_arrow->setGeometry (getWidth() - 1, 2, 1, 1); + right_arrow = arrow_up; + right_arrow.setForegroundColor (wc.label_inactive_fg); + right_arrow.setEmphasis(); + right_arrow.ignorePadding(); + right_arrow.setGeometry (getWidth() - 1, 2, 1, 1); - const finalcut::FString& top_left_label_text = "menu"; - top_left_label = new finalcut::FLabel (top_left_label_text, this); - top_left_label->setForegroundColor (wc.label_inactive_fg); - top_left_label->setEmphasis(); - top_left_label->setGeometry (1, 1, 6, 1); + top_left_label = "menu"; + top_left_label.setForegroundColor (wc.label_inactive_fg); + top_left_label.setEmphasis(); + top_left_label.setGeometry (1, 1, 6, 1); - const finalcut::FString& top_right_label_text = "zoom"; - top_right_label = new finalcut::FLabel (top_right_label_text, this); - top_right_label->setAlignment (finalcut::fc::alignRight); - top_right_label->setForegroundColor (wc.label_inactive_fg); - top_right_label->setEmphasis(); - top_right_label->setGeometry (getClientWidth() - 5, 1, 6, 1); + top_right_label = "zoom"; + top_right_label.setAlignment (finalcut::fc::alignRight); + top_right_label.setForegroundColor (wc.label_inactive_fg); + top_right_label.setEmphasis(); + top_right_label.setGeometry (getClientWidth() - 5, 1, 6, 1); finalcut::FString bottom_label_text = "resize\n" "corner\n"; bottom_label_text += arrow_down; - bottom_label = new finalcut::FLabel (bottom_label_text, this); - bottom_label->setAlignment (finalcut::fc::alignRight); - bottom_label->setForegroundColor (wc.label_inactive_fg); - bottom_label->setEmphasis(); - bottom_label->setGeometry (13, 3, 6, 3); + bottom_label = bottom_label_text; + bottom_label.setAlignment (finalcut::fc::alignRight); + bottom_label.setForegroundColor (wc.label_inactive_fg); + bottom_label.setEmphasis(); + bottom_label.setGeometry (13, 3, 6, 3); } //---------------------------------------------------------------------- @@ -124,19 +121,19 @@ void SmallWindow::adjustSize() { if ( isZoomed() ) { - *top_right_label = "unzoom"; - bottom_label->hide(); + top_right_label = "unzoom"; + bottom_label.hide(); } else { - *top_right_label = "zoom"; - bottom_label->setVisible(); + top_right_label = "zoom"; + bottom_label.setVisible(); } finalcut::FDialog::adjustSize(); - right_arrow->setGeometry (getWidth() - 1, 2, 1, 1); - top_right_label->setGeometry (getClientWidth() - 5, 1, 6, 1); - bottom_label->setGeometry (1, getClientHeight() - 2, getClientWidth(), 3); + right_arrow.setGeometry (getWidth() - 1, 2, 1, 1); + top_right_label.setGeometry (getClientWidth() - 5, 1, 6, 1); + bottom_label.setGeometry (1, getClientHeight() - 2, getClientWidth(), 3); } //---------------------------------------------------------------------- @@ -148,16 +145,16 @@ void SmallWindow::onShow (finalcut::FShowEvent*) //---------------------------------------------------------------------- void SmallWindow::onTimer (finalcut::FTimerEvent*) { - left_arrow->unsetEmphasis(); - left_arrow->redraw(); - right_arrow->unsetEmphasis(); - right_arrow->redraw(); - top_left_label->unsetEmphasis(); - top_left_label->redraw(); - top_right_label->unsetEmphasis(); - top_right_label->redraw(); - bottom_label->unsetEmphasis(); - bottom_label->redraw(); + left_arrow.unsetEmphasis(); + left_arrow.redraw(); + right_arrow.unsetEmphasis(); + right_arrow.redraw(); + top_left_label.unsetEmphasis(); + top_left_label.redraw(); + top_right_label.unsetEmphasis(); + top_right_label.redraw(); + bottom_label.unsetEmphasis(); + bottom_label.redraw(); updateTerminal(); delOwnTimer(); } @@ -183,13 +180,27 @@ class Window : public finalcut::FDialog // Typedefs typedef void (Window::*WindowCallback)(finalcut::FWidget*, data_ptr); typedef void (finalcut::FApplication::*FAppCallback)(finalcut::FWidget*, data_ptr); - typedef struct + + class win_data { - bool is_open; - finalcut::FString* title; - SmallWindow* dgl; - } - win_data; + public: + win_data() + : is_open(false) + , title() + , dgl(0) + { } + + // Data Members + bool is_open; + finalcut::FString title; + SmallWindow* dgl; + + private: + // Disable copy constructor + win_data (const win_data&); + // Disable assignment operator (=) + win_data& operator = (const win_data&); + }; // Disable copy constructor Window (const Window&); @@ -198,8 +209,8 @@ class Window : public finalcut::FDialog Window& operator = (const Window&); // Method - void createFileMenuItems (finalcut::FMenu*); - void createDialogButtons(); + void configureFileMenuItems(); + void configureDialogButtons(); void activateWindow (finalcut::FDialog*); virtual void adjustSize(); void addClickedCallback (finalcut::FWidget*, WindowCallback); @@ -216,7 +227,22 @@ class Window : public finalcut::FDialog void cb_destroyWindow (finalcut::FWidget*, data_ptr); // Data Members - std::vector windows; + std::vector windows; + finalcut::FString drop_down_symbol; + finalcut::FMenuBar Menubar; + finalcut::FMenu File; + finalcut::FDialogListMenu DglList; + finalcut::FStatusBar Statusbar; + finalcut::FMenuItem New; + finalcut::FMenuItem Close; + finalcut::FMenuItem Line1; + finalcut::FMenuItem Next; + finalcut::FMenuItem Previous; + finalcut::FMenuItem Line2; + finalcut::FMenuItem Quit; + finalcut::FButton CreateButton; + finalcut::FButton CloseButton; + finalcut::FButton QuitButton; }; #pragma pack(pop) @@ -224,42 +250,42 @@ class Window : public finalcut::FDialog Window::Window (finalcut::FWidget* parent) : finalcut::FDialog(parent) , windows() + , drop_down_symbol(wchar_t(finalcut::fc::BlackDownPointingTriangle)) + , Menubar(this) + , File("&File", &Menubar) + , DglList(drop_down_symbol, &Menubar) + , Statusbar(this) + , New("&New", &File) + , Close("&Close", &File) + , Line1(&File) + , Next("Ne&xt window", &File) + , Previous("&Previous window", &File) + , Line2(&File) + , Quit("&Quit", &File) + , CreateButton(this) + , CloseButton(this) + , QuitButton(this) { - finalcut::FMenu* File; - finalcut::FDialogListMenu* DglList; - finalcut::FString drop_down_symbol; - finalcut::FMenuBar* Menubar; - finalcut::FStatusBar* Statusbar; - - // Menu bar - Menubar = new finalcut::FMenuBar (this); - // Menu bar item - File = new finalcut::FMenu ("&File", Menubar); - File->setStatusbarMessage ("File management commands"); + File.setStatusbarMessage ("File management commands"); // Dialog list menu item - drop_down_symbol = wchar_t(finalcut::fc::BlackDownPointingTriangle); - DglList = new finalcut::FDialogListMenu (drop_down_symbol, Menubar); - DglList->setStatusbarMessage ("List of all the active dialogs"); + DglList.setStatusbarMessage ("List of all the active dialogs"); // File menu items - createFileMenuItems (File); + configureFileMenuItems(); // Dialog buttons - createDialogButtons(); + configureDialogButtons(); // Statusbar at the bottom - Statusbar = new finalcut::FStatusBar (this); - Statusbar->setMessage("Status bar message"); + Statusbar.setMessage("Status bar message"); // Generate data vector for the windows for (int n = 1; n <= 6; n++) { win_data* win_dat = new win_data; - win_dat->is_open = false; - win_dat->title = new finalcut::FString(); - win_dat->title->sprintf("Window %d", n); + win_dat->title.sprintf("Window %d", n); windows.push_back(win_dat); } } @@ -278,68 +304,49 @@ Window::~Window() if ( win_dat->is_open && win_dat->dgl ) win_dat->dgl->delCallbacks(); - delete win_dat->title; delete win_dat; iter = windows.erase(iter); } } //---------------------------------------------------------------------- -void Window::createFileMenuItems (finalcut::FMenu* File) +void Window::configureFileMenuItems() { - // "File" menu item - finalcut::FMenuItem* New = new finalcut::FMenuItem ("&New", File); - New->setStatusbarMessage ("Create the windows"); - - finalcut::FMenuItem* Close = new finalcut::FMenuItem ("&Close", File); - Close->setStatusbarMessage ("Close the windows"); - - finalcut::FMenuItem* Line1 = new finalcut::FMenuItem (File); - Line1->setSeparator(); - - finalcut::FMenuItem* Next = new finalcut::FMenuItem ("Ne&xt window", File); - Next->addAccelerator (finalcut::fc::Fmkey_npage); // Meta/Alt + PgDn - Next->setStatusbarMessage ("Switch to the next window"); - - finalcut::FMenuItem* Previous = new finalcut::FMenuItem ("&Previous window", File); - Previous->addAccelerator (finalcut::fc::Fmkey_ppage); // Meta/Alt + PgUp - Previous->setStatusbarMessage ("Switch to the previous window"); - - finalcut::FMenuItem* Line2 = new finalcut::FMenuItem (File); - Line2->setSeparator(); - - finalcut::FMenuItem* Quit = new finalcut::FMenuItem ("&Quit", File); - Quit->addAccelerator (finalcut::fc::Fmkey_x); // Meta/Alt + X - Quit->setStatusbarMessage ("Exit the program"); + // "File" menu item setting + New.setStatusbarMessage ("Create the windows"); + Close.setStatusbarMessage ("Close the windows"); + Line1.setSeparator(); + Next.addAccelerator (finalcut::fc::Fmkey_npage); // Meta/Alt + PgDn + Next.setStatusbarMessage ("Switch to the next window"); + Previous.addAccelerator (finalcut::fc::Fmkey_ppage); // Meta/Alt + PgUp + Previous.setStatusbarMessage ("Switch to the previous window"); + Line2.setSeparator(); + Quit.addAccelerator (finalcut::fc::Fmkey_x); // Meta/Alt + X + Quit.setStatusbarMessage ("Exit the program"); // Add menu item callback - addClickedCallback (New, &Window::cb_createWindows); - addClickedCallback (Close, &Window::cb_closeWindows); - addClickedCallback (Next, &Window::cb_next); - addClickedCallback (Previous, &Window::cb_previous); - addClickedCallback (Quit, &finalcut::FApplication::cb_exitApp); + addClickedCallback (&New, &Window::cb_createWindows); + addClickedCallback (&Close, &Window::cb_closeWindows); + addClickedCallback (&Next, &Window::cb_next); + addClickedCallback (&Previous, &Window::cb_previous); + addClickedCallback (&Quit, &finalcut::FApplication::cb_exitApp); } //---------------------------------------------------------------------- -void Window::createDialogButtons() +void Window::configureDialogButtons() { // Dialog buttons - finalcut::FButton* CreateButton = new finalcut::FButton (this); - CreateButton->setGeometry(2, 2, 9, 1); - CreateButton->setText (L"&Create"); - - finalcut::FButton* CloseButton = new finalcut::FButton (this); - CloseButton->setGeometry(15, 2, 9, 1); - CloseButton->setText (L"C&lose"); - - finalcut::FButton* QuitButton = new finalcut::FButton (this); - QuitButton->setGeometry(28, 2, 9, 1); - QuitButton->setText (L"&Quit"); + CreateButton.setGeometry (2, 2, 9, 1); + CreateButton.setText (L"&Create"); + CloseButton.setGeometry (15, 2, 9, 1); + CloseButton.setText (L"C&lose"); + QuitButton.setGeometry (28, 2, 9, 1); + QuitButton.setText (L"&Quit"); // Add button callback - addClickedCallback (CreateButton, &Window::cb_createWindows); - addClickedCallback (CloseButton, &Window::cb_closeWindows); - addClickedCallback (QuitButton, &finalcut::FApplication::cb_exitApp); + addClickedCallback (&CreateButton, &Window::cb_createWindows); + addClickedCallback (&CloseButton, &Window::cb_closeWindows); + addClickedCallback (&QuitButton, &finalcut::FApplication::cb_exitApp); } //---------------------------------------------------------------------- @@ -442,7 +449,7 @@ void Window::cb_createWindows (finalcut::FWidget*, data_ptr) SmallWindow* win = new SmallWindow(this); win_dat->dgl = win; win_dat->is_open = true; - win->setText(*(win_dat)->title); + win->setText(win_dat->title); int n = int(std::distance(first, iter)) , x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3 , y = dy + 11 + int(n / 3) * 3; diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index bf861ee4..116a20b3 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -2,7 +2,7 @@ if [ $# -gt 0 ] then - eval cppcheck --force --enable=all -I../scr/include/ "$@" + eval cppcheck --force --enable=all -I../src/include/ "$@" else eval cppcheck --force --enable=all -I../src/include/ ../src/ ../examples/ fi diff --git a/scripts/remove_eol_spaces.sh b/scripts/remove_eol_spaces.sh index c394b7be..72bce211 100755 --- a/scripts/remove_eol_spaces.sh +++ b/scripts/remove_eol_spaces.sh @@ -1,8 +1,9 @@ #!/bin/bash find ../src/ \ - ../include/final/ \ + ../src/include/final/ \ ../examples/ \ + ../test/ \ -regextype posix-egrep \ -regex ".*\\.(cpp|h)$" \ -exec sed -i 's/ *$//' "{}" \; diff --git a/scripts/syscall_statistic.sh b/scripts/syscall_statistic.sh index b3bbafd7..3f6757fb 100755 --- a/scripts/syscall_statistic.sh +++ b/scripts/syscall_statistic.sh @@ -1,3 +1,3 @@ #!/bin/sh -strace -c ../examples/.libs/ui +LD_LIBRARY_PATH=../src/.libs strace -c ../examples/.libs/ui diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index e2423822..2b56c952 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -60,8 +60,8 @@ FFileDialog::FFileDialog (FWidget* parent) , dir_entries() , directory() , filter_pattern() - , filebrowser() , filename() + , filebrowser() , hidden() , cancel() , open() @@ -78,8 +78,8 @@ FFileDialog::FFileDialog (const FFileDialog& fdlg) , dir_entries() , directory(fdlg.directory) , filter_pattern(fdlg.filter_pattern) - , filebrowser() , filename() + , filebrowser() , hidden() , cancel() , open() @@ -102,11 +102,11 @@ FFileDialog::FFileDialog ( const FString& dirname , dir_entries() , directory() , filter_pattern(filter) - , filebrowser() - , filename() - , hidden() - , cancel() - , open() + , filename(this) + , filebrowser(this) + , hidden(this) + , cancel(this) + , open(this) , dlg_type(type) , show_hidden(false) { @@ -119,7 +119,6 @@ FFileDialog::FFileDialog ( const FString& dirname //---------------------------------------------------------------------- FFileDialog::~FFileDialog() // destructor { - deallocation(); clear(); } @@ -134,11 +133,6 @@ FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg) } else { - delete open; - delete cancel; - delete hidden; - delete filebrowser; - delete filename; clear(); if ( fdlg.getParentWidget() ) @@ -160,7 +154,7 @@ FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg) //---------------------------------------------------------------------- const FString FFileDialog::getSelectedFile() const { - uLong n = uLong(filebrowser->currentItem() - 1); + uLong n = uLong(filebrowser.currentItem() - 1); if ( dir_entries[n].directory ) return FString(""); @@ -222,7 +216,7 @@ bool FFileDialog::setShowHiddenFiles (bool on) show_hidden = on; readDir(); - filebrowser->redraw(); + filebrowser.redraw(); return show_hidden; } @@ -234,7 +228,7 @@ void FFileDialog::onKeyPress (FKeyEvent* ev) FDialog::onKeyPress (ev); - if ( ! filebrowser->hasFocus() ) + if ( ! filebrowser.hasFocus() ) return; int key = ev->key(); @@ -374,10 +368,10 @@ void FFileDialog::adjustSize() X = 1 + int((max_width - getWidth()) / 2); Y = 1 + int((max_height - getHeight()) / 3); setPos(X, Y, false); - filebrowser->setHeight (h - 8, false); - hidden->setY (h - 4, false); - cancel->setY (h - 4, false); - open->setY (h - 4, false); + filebrowser.setHeight (h - 8, false); + hidden.setY (h - 4, false); + cancel.setY (h - 4, false); + open.setY (h - 4, false); FDialog::adjustSize(); printPath(directory); } @@ -408,92 +402,72 @@ void FFileDialog::init() else FDialog::setText("Open file"); - allocation (x, y); // Create widgets + widgetSettings (x, y); // Create widgets initCallbacks(); setModal(); readDir(); } //---------------------------------------------------------------------- -inline void FFileDialog::allocation (int x, int y) +inline void FFileDialog::widgetSettings (int x, int y) { - try - { - filename = new FLineEdit(this); - filename->setLabelText("File&name"); - filename->setText(filter_pattern); - filename->setGeometry(11, 1, 28, 1); - filename->setFocus(); + filename.setLabelText ("File&name"); + filename.setText (filter_pattern); + filename.setGeometry (11, 1, 28, 1); + filename.setFocus(); - filebrowser = new FListBox(this); - filebrowser->setGeometry(2, 3, 38, 6); - printPath(directory); + filebrowser.setGeometry (2, 3, 38, 6); + printPath (directory); - hidden = new FCheckBox("&hidden files", this); - hidden->setGeometry(2, 10, 16, 1); + hidden.setText ("&hidden files"); + hidden.setGeometry (2, 10, 16, 1); - cancel = new FButton("&Cancel", this); - cancel->setGeometry(19, 10, 9, 1); + cancel.setText ("&Cancel"); + cancel.setGeometry(19, 10, 9, 1); - if ( dlg_type == FFileDialog::Save ) - open = new FButton("&Save", this); - else - open = new FButton("&Open", this); + if ( dlg_type == FFileDialog::Save ) + open.setText ("&Save"); + else + open.setText ("&Open"); - open->setGeometry(30, 10, 9, 1); - setGeometry (x, y, getWidth(), getHeight()); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } -} - -//---------------------------------------------------------------------- -inline void FFileDialog::deallocation() -{ - delete open; - delete cancel; - delete hidden; - delete filebrowser; - delete filename; + open.setGeometry(30, 10, 9, 1); + setGeometry (x, y, getWidth(), getHeight()); } //---------------------------------------------------------------------- void FFileDialog::initCallbacks() { - filename->addCallback + filename.addCallback ( "activate", F_METHOD_CALLBACK (this, &FFileDialog::cb_processActivate) ); - filebrowser->addCallback + filebrowser.addCallback ( "row-changed", F_METHOD_CALLBACK (this, &FFileDialog::cb_processRowChanged) ); - filebrowser->addCallback + filebrowser.addCallback ( "clicked", F_METHOD_CALLBACK (this, &FFileDialog::cb_processClicked) ); - hidden->addCallback + hidden.addCallback ( "toggled", F_METHOD_CALLBACK (this, &FFileDialog::cb_processShowHidden) ); - cancel->addCallback + cancel.addCallback ( "clicked", F_METHOD_CALLBACK (this, &FFileDialog::cb_processCancel) ); - open->addCallback + open.addCallback ( "clicked", F_METHOD_CALLBACK (this, &FFileDialog::cb_processOpen) @@ -725,7 +699,7 @@ void FFileDialog::dirEntriesToList() { // Fill list with directory entries - filebrowser->clear(); + filebrowser.clear(); if ( dir_entries.empty() ) return; @@ -737,9 +711,9 @@ void FFileDialog::dirEntriesToList() while ( iter != last ) { if ( iter->directory ) - filebrowser->insert(FString(iter->name), fc::SquareBrackets); + filebrowser.insert(FString(iter->name), fc::SquareBrackets); else - filebrowser->insert(FString(iter->name)); + filebrowser.insert(FString(iter->name)); ++iter; } @@ -774,7 +748,7 @@ int FFileDialog::changeDir (const FString& dirname) if ( newdir == FString("..") ) { if ( lastdir == FString('/') ) - filename->setText('/'); + filename.setText('/'); else if ( ! dir_entries.empty() ) { int i = 1; @@ -788,8 +762,8 @@ int FFileDialog::changeDir (const FString& dirname) { if ( std::strcmp(iter->name, baseName) == 0 ) { - filebrowser->setCurrentItem(i); - filename->setText(FString(baseName) + '/'); + filebrowser.setCurrentItem(i); + filename.setText(FString(baseName) + '/'); break; } @@ -803,14 +777,14 @@ int FFileDialog::changeDir (const FString& dirname) FString firstname = dir_entries[0].name; if ( dir_entries[0].directory ) - filename->setText(firstname + '/'); + filename.setText(firstname + '/'); else - filename->setText(firstname); + filename.setText(firstname); } printPath(directory); - filename->redraw(); - filebrowser->redraw(); + filename.redraw(); + filebrowser.redraw(); // fall through default: return 0; @@ -821,12 +795,12 @@ int FFileDialog::changeDir (const FString& dirname) void FFileDialog::printPath (const FString& txt) { const FString& path = txt; - const uInt max_width = uInt(filebrowser->getWidth()) - 4; + const uInt max_width = uInt(filebrowser.getWidth()) - 4; if ( path.getLength() > max_width ) - filebrowser->setText(".." + path.right(max_width - 2)); + filebrowser.setText(".." + path.right(max_width - 2)); else - filebrowser->setText(path); + filebrowser.setText(path); } //---------------------------------------------------------------------- @@ -845,24 +819,24 @@ const FString FFileDialog::getHomeDir() //---------------------------------------------------------------------- void FFileDialog::cb_processActivate (FWidget*, data_ptr) { - if ( filename->getText().includes('*') - || filename->getText().includes('?') ) + if ( filename.getText().includes('*') + || filename.getText().includes('?') ) { - setFilter(filename->getText()); + setFilter(filename.getText()); readDir(); - filebrowser->redraw(); + filebrowser.redraw(); } - else if ( filename->getText().getLength() == 0 ) + else if ( filename.getText().getLength() == 0 ) { setFilter("*"); readDir(); - filebrowser->redraw(); + filebrowser.redraw(); } - else if ( filename->getText().trim() == FString("..") - || filename->getText().includes('/') - || filename->getText().includes('~') ) + else if ( filename.getText().trim() == FString("..") + || filename.getText().includes('/') + || filename.getText().includes('~') ) { - changeDir(filename->getText().trim()); + changeDir(filename.getText().trim()); } else { @@ -871,7 +845,7 @@ void FFileDialog::cb_processActivate (FWidget*, data_ptr) if ( ! dir_entries.empty() ) { std::vector::const_iterator iter, last; - const FString& input = filename->getText().trim(); + const FString& input = filename.getText().trim(); iter = dir_entries.begin(); last = dir_entries.end(); @@ -898,7 +872,7 @@ void FFileDialog::cb_processActivate (FWidget*, data_ptr) //---------------------------------------------------------------------- void FFileDialog::cb_processRowChanged (FWidget*, data_ptr) { - const int n = filebrowser->currentItem(); + const int n = filebrowser.currentItem(); if ( n == 0 ) return; @@ -906,17 +880,17 @@ void FFileDialog::cb_processRowChanged (FWidget*, data_ptr) const FString& name = dir_entries[uLong(n - 1)].name; if ( dir_entries[uLong(n - 1)].directory ) - filename->setText( name + '/' ); + filename.setText( name + '/' ); else - filename->setText( name ); + filename.setText( name ); - filename->redraw(); + filename.redraw(); } //---------------------------------------------------------------------- void FFileDialog::cb_processClicked (FWidget*, data_ptr) { - const uLong n = uLong(filebrowser->currentItem() - 1); + const uLong n = uLong(filebrowser.currentItem() - 1); if ( dir_entries[n].directory ) changeDir(dir_entries[n].name); diff --git a/src/fterm.cpp b/src/fterm.cpp index 09ada8ba..5acf5408 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1466,7 +1466,7 @@ void FTerm::init_locale() char* locale_xterm; const char* termtype = data->getTermType(); locale_name = std::setlocale (LC_ALL, ""); - locale_name = std::setlocale (LC_NUMERIC, ""); + std::setlocale (LC_NUMERIC, ""); // Get XTERM_LOCALE locale_xterm = std::getenv("XTERM_LOCALE"); @@ -1506,7 +1506,7 @@ void FTerm::init_locale() // Fallback to C if ( ! locale_name ) - locale_name = C_STR("C"); + std::setlocale (LC_ALL, "C"); } //---------------------------------------------------------------------- diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index 521cba18..56f1fd62 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -163,8 +163,7 @@ class FFileDialog : public FDialog // Method void init(); - void allocation (int, int); - void deallocation(); + void widgetSettings (int, int); void initCallbacks(); bool pattern_match (const char* const, char[]); void clear(); @@ -191,11 +190,11 @@ class FFileDialog : public FDialog dirEntries dir_entries; FString directory; FString filter_pattern; - FListBox* filebrowser; - FLineEdit* filename; - FCheckBox* hidden; - FButton* cancel; - FButton* open; + FLineEdit filename; + FListBox filebrowser; + FCheckBox hidden; + FButton cancel; + FButton open; DialogType dlg_type; bool show_hidden; diff --git a/src/include/final/fstatusbar.h b/src/include/final/fstatusbar.h index 098d8601..3749278d 100644 --- a/src/include/final/fstatusbar.h +++ b/src/include/final/fstatusbar.h @@ -92,6 +92,8 @@ class FStatusKey : public FWidget virtual FString getText() const; // Mutators + void setKey (int); + void setText (const FString&); void setActive(); void unsetActive(); bool setMouseFocus(bool); @@ -105,11 +107,6 @@ class FStatusKey : public FWidget // Event handler virtual void onAccel (FAccelEvent*); - protected: - // Mutators - void setKey (int); - void setText (const FString&); - private: // Disable copy constructor FStatusKey (const FStatusKey&); @@ -149,6 +146,14 @@ inline int FStatusKey::getKey() const inline FString FStatusKey::getText() const { return text; } +//---------------------------------------------------------------------- +inline void FStatusKey::setKey (int k) +{ key = k; } + +//---------------------------------------------------------------------- +inline void FStatusKey::setText (const FString& txt) +{ text = txt; } + //---------------------------------------------------------------------- inline void FStatusKey::unsetActive() { active = false; } @@ -169,14 +174,6 @@ inline bool FStatusKey::isActivated() const inline bool FStatusKey::hasMouseFocus() const { return mouse_focus; } -//---------------------------------------------------------------------- -inline void FStatusKey::setKey (int k) -{ key = k; } - -//---------------------------------------------------------------------- -inline void FStatusKey::setText (const FString& txt) -{ text = txt; } - //---------------------------------------------------------------------- inline FStatusBar* FStatusKey::getConnectedStatusbar() const { return bar; } diff --git a/test/fkeyboard-test.cpp b/test/fkeyboard-test.cpp index e2a8f584..539817cd 100644 --- a/test/fkeyboard-test.cpp +++ b/test/fkeyboard-test.cpp @@ -356,7 +356,8 @@ void FKeyboardTest::escapeKeyTest() // Normal escape (needs a timeout) input("\033"); processInput(); - usleep(100000); + // Wait 100 ms (= 100,000,000 ns) + nanosleep ((const struct timespec[]){{0, 100000000L}}, NULL); keyboard->escapeKeyHandling(); std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_escape ); @@ -2085,7 +2086,8 @@ void FKeyboardTest::metaKeyTest() // shifted meta-O input("\033O"); processInput(); - usleep(100000); // Substring keys needs a timeout + // Wait 100 ms - Substring keys needs a timeout + nanosleep ((const struct timespec[]){{0, 100000000L}}, NULL); keyboard->escapeKeyHandling(); std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fmkey_O ); @@ -2171,7 +2173,8 @@ void FKeyboardTest::metaKeyTest() // meta-[ input("\033["); processInput(); - usleep(100000); // Substring keys needs a timeout + // Wait 100 ms - Substring keys needs a timeout + nanosleep ((const struct timespec[]){{0, 100000000L}}, NULL); keyboard->escapeKeyHandling(); std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fmkey_left_square_bracket ); @@ -2187,7 +2190,8 @@ void FKeyboardTest::metaKeyTest() // meta-] input("\033]"); processInput(); - usleep(100000); // Substring keys needs a timeout + // Wait 100 ms - Substring keys needs a timeout + nanosleep ((const struct timespec[]){{0, 100000000L}}, NULL); keyboard->escapeKeyHandling(); std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fmkey_right_square_bracket ); diff --git a/test/fmouse-test.cpp b/test/fmouse-test.cpp index 5bb2f3d0..6e856908 100644 --- a/test/fmouse-test.cpp +++ b/test/fmouse-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* fmouse-test.cpp - finalcut::FMouse unit tests * +* fmouse-test.cpp - FMouse unit tests * * * * This file is part of the Final Cut widget toolkit * * * diff --git a/test/fobject-test.cpp b/test/fobject-test.cpp index 9ce2a57e..c7543b71 100644 --- a/test/fobject-test.cpp +++ b/test/fobject-test.cpp @@ -54,7 +54,7 @@ class FObject_protected : public finalcut::FObject { return finalcut::FObject::getTimerList(); } - + uInt processEvent() { return processTimerEvent(); @@ -477,7 +477,8 @@ void FObjectTest::performTimerActionTest() while ( loop < 10 ) { num_events += t.processEvent(); - usleep(100000); + // Wait 100 ms + nanosleep ((const struct timespec[]){{0, 100000000L}}, NULL); loop++; } diff --git a/test/foptiattr-test.cpp b/test/foptiattr-test.cpp index 09aeb471..35a1c01c 100644 --- a/test/foptiattr-test.cpp +++ b/test/foptiattr-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* foptiattr_test.cpp - finalcut::FOptiAttr unit tests * +* foptiattr_test.cpp - FOptiAttr unit tests * * * * This file is part of the Final Cut widget toolkit * * * diff --git a/test/foptimove-test.cpp b/test/foptimove-test.cpp index a6ddd2af..c1fe9f3d 100644 --- a/test/foptimove-test.cpp +++ b/test/foptimove-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* foptimove-test.cpp - finalcut::FOptiMove unit tests * +* foptimove-test.cpp - FOptiMove unit tests * * * * This file is part of the Final Cut widget toolkit * * * diff --git a/test/fpoint-test.cpp b/test/fpoint-test.cpp index c7a9c736..e0cfe327 100644 --- a/test/fpoint-test.cpp +++ b/test/fpoint-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* fpoint-test.cpp - finalcut::FPoint unit tests * +* fpoint-test.cpp - FPoint unit tests * * * * This file is part of the Final Cut widget toolkit * * * diff --git a/test/frect-test.cpp b/test/frect-test.cpp index d5cbb316..913eb3c3 100644 --- a/test/frect-test.cpp +++ b/test/frect-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* frect-test.cpp - finalcut::FRect unit tests * +* frect-test.cpp - FRect unit tests * * * * This file is part of the Final Cut widget toolkit * * * diff --git a/test/fstring-test.cpp b/test/fstring-test.cpp index 1881b216..a3cb1881 100644 --- a/test/fstring-test.cpp +++ b/test/fstring-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* fstring-test.cpp - finalcut::FString unit tests * +* fstring-test.cpp - FString unit tests * * * * This file is part of the Final Cut widget toolkit * * * diff --git a/test/ftermcapquirks-test.cpp b/test/ftermcapquirks-test.cpp index 48f3f655..b75e6bfb 100644 --- a/test/ftermcapquirks-test.cpp +++ b/test/ftermcapquirks-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* ftermcapquirks-test.cpp - finalcut::FTermcapQuirks unit tests * +* ftermcapquirks-test.cpp - FTermcapQuirks unit tests * * * * This file is part of the Final Cut widget toolkit * * * diff --git a/test/ftermdetection-test.cpp b/test/ftermdetection-test.cpp index eac89d28..037290cb 100644 --- a/test/ftermdetection-test.cpp +++ b/test/ftermdetection-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* ftermdetection-test.cpp - finalcut::FTermDetection unit tests * +* ftermdetection-test.cpp - FTermDetection unit tests * * * * This file is part of the Final Cut widget toolkit * * * @@ -2198,7 +2198,8 @@ pid_t FTermDetectionTest::forkProcess() // Wait until the child process is ready for input while ( ! *shared_state && i < timeout ) { - usleep(10000); // wait 10 ms + // Wait 10 ms (= 10,000,000 ns) + nanosleep ((const struct timespec[]){{0, 10000000L}}, NULL); i++; }