diff --git a/ChangeLog b/ChangeLog index 377131bd..cdaa503d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2018-10-03 Markus Gans + * At the end of the lifetime of an FMenuItem object, + delete its entry from the object list of the parent object + * Reduce the use of the new operators in the examples + * Adding a unit test for the FTermData class + +2018-10-01 Markus Gans + * Extract FTerm data members into the data class FTermData + +2018-09-28 Markus Gans + * FListView now has the ability to sort by columns + +2018-09-27 Markus Gans + * Move time event processing from FApplication to FObject + +2018-09-26 Markus Gans + * The FListViewItem class now has a getData() and a setData() method + similar to the FListBoxItem class. + +2018-09-24 Markus Gans + * Stricter use of the keyword virtual + * Add a first steps document + 2018-09-20 Markus Gans * Added pkg-config file finalcut.pc * The entire library source code is now encapsulated under diff --git a/README.md b/README.md index a11594f2..352aba85 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -![The Final Cut](logo/png/finalcut-logo.png) +![FINAL CUT](logo/svg/finalcut-logo.svg) +============================================ ### Building and code analysis *Travis CI:*
@@ -10,6 +11,9 @@ *Class Reference:*
     [![documented](https://codedocs.xyz/gansm/finalcut.svg)](https://codedocs.xyz/gansm/finalcut/hierarchy.html) +The Final Cut is a C++ class library and widget toolkit with full mouse support for creating a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface). The library supports the programmer to develop an application for the text console. It allows the simultaneous handling of multiple text windows on the screen. +The C++ class design was inspired by the Qt framework. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on. + ### Installation ```bash > git clone git://github.com/gansm/finalcut.git @@ -29,29 +33,47 @@ * Cygwin * Solaris -The Final Cut -============= -The Final Cut is a C++ class library and widget toolkit with full mouse support for creating a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface). The library supports the programmer to develop an application for the text console. It allows the simultaneous handling of multiple text windows on the screen. -The C++ class design was inspired by the Qt framework. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on. +### First steps -![](doc/fileopen-dialog.png) +[How to use the library](doc/first-steps.md) -![](doc/progress-bar.png) +### Screenshots -![](doc/textview.png) +The FFileDialog widget: -![](doc/Mandelbrot.png) +![FFileDialog](doc/fileopen-dialog.png) + + +The Final Cut FProgressbar widget: + +![FProgressbar](doc/progress-bar.png) + + +Scrollable text in the FTextView widget: + + ![FTextView](doc/textview.png) + + +The Mandelbrot set example: + + ![Mandelbrot set](doc/Mandelbrot.png) newfont ------- A [graphical text font](fonts/) for X11 and the Linux console. -![](doc/newfont1.png) +![ui example in newfont mode](doc/newfont1.png) -![](doc/newfont2.png) -![](doc/calculator.png) +Newfont drive symbols: + +![drive symbols](doc/newfont2.png) + + +The calculator example in newfont mode: + +![calculator](doc/calculator.png) Virtual terminal diff --git a/autogen.sh b/autogen.sh index f5b403c2..f47cec46 100755 --- a/autogen.sh +++ b/autogen.sh @@ -3,7 +3,13 @@ if test "$1" = "update" then # Update generated configuration files - autoreconf --force --install --verbose --warnings=all + if which autoreconf >/dev/null + then + autoreconf --force --install --verbose --warnings=all + else + echo "Update failed, please install autoconf first" + exit 1 + fi else # Set up an m4 environment aclocal diff --git a/build.sh b/build.sh index 29ece85e..91aaad2f 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,16 @@ test "$CPU_COUNT" -eq 0 && CPU_COUNT=1 if [ -n "$1" ] then - test ! -f ./configure && autoreconf --install --force + if [ ! -f ./configure ] + then + if which autoreconf >/dev/null + then + autoreconf --install --force + else + echo "Build failed, please install autoconf first" + exit -1 + fi + fi fi # Build commands diff --git a/doc/first-steps.md b/doc/first-steps.md new file mode 100644 index 00000000..27f8b0a8 --- /dev/null +++ b/doc/first-steps.md @@ -0,0 +1,100 @@ + +First steps with the Final Cut widget toolkit +============================================= + + +How to use the library +---------------------- + +At the beginning of this introduction to the Final Cut +we will start with a small example. + +It creates an empty 30×10 character dialog. + +**File:** *dialog.cpp* +```cpp +#include + +int main (int argc, char* argv[]) +{ + finalcut::FApplication app(argc, argv); + finalcut::FDialog dialog(&app); + dialog.setText ("A dialog"); + dialog.setGeometry (25, 5, 30, 10); + app.setMainWidget(&dialog); + dialog.show(); + return app.exec(); +} +``` +*(Note: Use mouse or Shift+F10 or +Ctrl+^ to close the dialog)* + + +After entering the source code in *dialog.cpp* you can compile +the above program with gcc: +```cpp +g++ -O2 -lfinal dialog.cpp -o dialog +``` + + +How it works +------------ + + +```cpp +#include +``` +All final cut programs must include the *final.h* header. + +```cpp +finalcut::FApplication app(argc, argv); +``` +In this line creates the `finalcut::FApplication` object `app` with +the command line arguments `argc` and `argv`. This object manages +the application main event loop. It receives keyboard and mouse events +and sends them to the target widgets. Before widgets can be created, +an application object must be created! Only one `finalcut::FApplication` +object should be created. + +The next line +```cpp +finalcut::FDialog dialog(&app); +``` +creates the `finalcut::FDialog` object `dialog` with the object `app` +as parent object. The `finalcut::FDialog` class is the base class for +creating dialog windows. + +```cpp +dialog.setText ("A dialog"); +``` +The title bar of the dialog box gets the text "A dialog". + +```cpp +dialog.setGeometry (25, 5, 30, 10); +``` +The dialog window geometry is set to a width of 30 characters and +a height of 10 characters. The window in the terminal is positioned +at the positions x=25 and y=5 (note: x=1 and y=1 represents the upper +left corner). + +```cpp +app.setMainWidget(&dialog); +``` +The `dialog` object is selected as the main widget for the application. +When the user closes a main widget, the application will be closed. + +```cpp +dialog.show(); +``` +A window or widget is not visible directly after its creation. +Only the call of `show()` makes it (and its child objects, +if available) visible. + +```cpp +return app.exec(); +``` +The last line calls `exec()` to start the application and return +the result to the operating system. When the application starts, +it enters the main event loop. This loop doesn't end until the +window/application is closed. + diff --git a/examples/Makefile.clang b/examples/Makefile.clang index 3ce11e90..8fe6f0c9 100644 --- a/examples/Makefile.clang +++ b/examples/Makefile.clang @@ -16,7 +16,7 @@ INCLUDES = -I../src/include -I/usr/include/final RM = rm -f ifdef DEBUG - OPTIMIZE = -O0 -fsanitize=undefined + OPTIMIZE = -O0 -fsanitize=bool,bounds,enum,float-cast-overflow,function,null else OPTIMIZE = -O2 endif diff --git a/examples/calculator.cpp b/examples/calculator.cpp index da16205f..e7d9949d 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -49,7 +49,7 @@ class Button : public finalcut::FButton void setChecked(bool); // Event handler - void onKeyPress (finalcut::FKeyEvent*); + virtual void onKeyPress (finalcut::FKeyEvent*); private: // Data Member @@ -118,12 +118,12 @@ class Calc : public finalcut::FDialog ~Calc(); // Event handlers - void onKeyPress (finalcut::FKeyEvent*); - void onAccel (finalcut::FAccelEvent*); - void onClose (finalcut::FCloseEvent*); + virtual void onKeyPress (finalcut::FKeyEvent*); + virtual void onAccel (finalcut::FAccelEvent*); + virtual void onClose (finalcut::FCloseEvent*); // Callback method - void cb_buttonClicked (finalcut::FWidget*, data_ptr); + void cb_buttonClicked (finalcut::FWidget*, data_ptr); private: // Typedef and Enumeration @@ -212,7 +212,7 @@ class Calc : public finalcut::FDialog void setInfixOperator (char); void clearInfixOperator(); void calcInfixOperator(); - void adjustSize(); + virtual void adjustSize(); const wchar_t* getButtonText (int); void mapKeyFunctions(); 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/keyboard.cpp b/examples/keyboard.cpp index c5fc5fa5..49195c4d 100644 --- a/examples/keyboard.cpp +++ b/examples/keyboard.cpp @@ -34,10 +34,12 @@ class Keyboard : public finalcut::FWidget protected: // Event handlers - void onKeyPress (finalcut::FKeyEvent*); - void onAccel (finalcut::FAccelEvent*); + virtual void onKeyPress (finalcut::FKeyEvent*); + virtual void onAccel (finalcut::FAccelEvent*); - void draw(); + private: + // Methods + virtual void draw(); }; //---------------------------------------------------------------------- diff --git a/examples/listbox.cpp b/examples/listbox.cpp index 23a731c1..4daaf2be 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -88,10 +88,14 @@ class Listbox : public finalcut::FDialog Listbox& operator = (const Listbox&); // Event handlers - void onClose (finalcut::FCloseEvent*); + 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 7c9f0137..d353748a 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -50,52 +50,68 @@ class Listview : public finalcut::FDialog Listview& operator = (const Listview&); // Method - void populate (finalcut::FListView*); + void populate(); // Event handlers - void onClose (finalcut::FCloseEvent*); + 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); + + // Sort in ascending order by the 1st column + 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) @@ -107,7 +123,7 @@ Listview::~Listview() // destructor { } //---------------------------------------------------------------------- -void Listview::populate (finalcut::FListView* listView) +void Listview::populate() { std::string weather[][5] = { @@ -159,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); } } @@ -170,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/mandelbrot.cpp b/examples/mandelbrot.cpp index a854898c..ad3be26e 100644 --- a/examples/mandelbrot.cpp +++ b/examples/mandelbrot.cpp @@ -40,13 +40,13 @@ class Mandelbrot : public finalcut::FDialog ~Mandelbrot(); // Event handlers - void onAccel (finalcut::FAccelEvent*); - void onClose (finalcut::FCloseEvent*); + virtual void onAccel (finalcut::FAccelEvent*); + virtual void onClose (finalcut::FCloseEvent*); private: // Methods virtual void draw(); - void adjustSize(); + virtual void adjustSize(); }; #pragma pack(pop) diff --git a/examples/menu.cpp b/examples/menu.cpp index 1aaf7eaf..b80df0a2 100644 --- a/examples/menu.cpp +++ b/examples/menu.cpp @@ -47,81 +47,161 @@ 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*); - void adjustSize(); + virtual void adjustSize(); // Event handler - void onClose (finalcut::FCloseEvent*); + virtual void onClose (finalcut::FCloseEvent*); // 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 e22fb230..ab829f46 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -50,14 +50,15 @@ class ColorChooser : public finalcut::FWidget ColorChooser& operator = (const ColorChooser&); // Method - void draw(); + virtual void draw(); // Event handler - void onMouseDown (finalcut::FMouseEvent*); + virtual void onMouseDown (finalcut::FMouseEvent*); // 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"; } //---------------------------------------------------------------------- @@ -188,15 +193,16 @@ class Brushes : public finalcut::FWidget Brushes& operator = (const Brushes&); // Method - void draw(); + virtual void draw(); // Event handler - void onMouseDown (finalcut::FMouseEvent*); + virtual void onMouseDown (finalcut::FMouseEvent*); // Data Members 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"; } //---------------------------------------------------------------------- @@ -316,8 +326,8 @@ class MouseDraw : public finalcut::FDialog void setGeometry (int, int, int, int, bool = true); // Event handlers - void onAccel (finalcut::FAccelEvent*); - void onClose (finalcut::FCloseEvent*); + virtual void onAccel (finalcut::FAccelEvent*); + virtual void onClose (finalcut::FCloseEvent*); private: // Disable copy constructor @@ -329,19 +339,19 @@ class MouseDraw : public finalcut::FDialog virtual void draw(); void drawBrush (int, int, bool = false); void drawCanvas(); - void adjustSize(); + virtual void adjustSize(); // Event handler - void onMouseDown (finalcut::FMouseEvent*); - void onMouseMove (finalcut::FMouseEvent*); + virtual void onMouseDown (finalcut::FMouseEvent*); + virtual void onMouseMove (finalcut::FMouseEvent*); // Callback methods 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 76edb6bb..451cf1f7 100644 --- a/examples/scrollview.cpp +++ b/examples/scrollview.cpp @@ -49,7 +49,7 @@ class Scrollview : public finalcut::FScrollView Scrollview& operator = (const Scrollview&); // Method - void draw(); + virtual void draw(); // Callback methods void cb_go_east (finalcut::FWidget*, data_ptr); @@ -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(); } @@ -206,10 +203,15 @@ class Scrollviewdemo : public finalcut::FDialog ~Scrollviewdemo(); // Event handler - void onClose (finalcut::FCloseEvent*); + virtual void onClose (finalcut::FCloseEvent*); // 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 234ae58a..c6b3df2a 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -40,9 +40,9 @@ class AttribDlg : public finalcut::FDialog ~AttribDlg(); // Event handlers - void onAccel (finalcut::FAccelEvent*); - void onWheel (finalcut::FWheelEvent*); - void onClose (finalcut::FCloseEvent*); + virtual void onAccel (finalcut::FAccelEvent*); + virtual void onWheel (finalcut::FWheelEvent*); + virtual void onClose (finalcut::FCloseEvent*); // Callback methods void cb_next (finalcut::FWidget* = 0, data_ptr = 0); @@ -58,11 +58,11 @@ class AttribDlg : public finalcut::FDialog AttribDlg& operator = (const AttribDlg&); // Method - void adjustSize(); + 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(); } @@ -191,7 +189,7 @@ class AttribDemo : public finalcut::FWidget { } // Event handler - void onWheel (finalcut::FWheelEvent* ev) + virtual void onWheel (finalcut::FWheelEvent* ev) { AttribDlg* p = static_cast(getParentWidget()); @@ -216,7 +214,7 @@ class AttribDemo : public finalcut::FWidget void printStandout(); void printInvisible(); void printProtected(); - void draw(); + virtual void draw(); // Data Member int colors; @@ -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/timer.cpp b/examples/timer.cpp index 3765f53d..7cef7206 100644 --- a/examples/timer.cpp +++ b/examples/timer.cpp @@ -35,11 +35,11 @@ class Timer : public finalcut::FWidget protected: // Method - void draw(); + virtual void draw(); // Event handlers - void onTimer (finalcut::FTimerEvent*); - void onAccel (finalcut::FAccelEvent*); + virtual void onTimer (finalcut::FTimerEvent*); + virtual void onAccel (finalcut::FAccelEvent*); }; //---------------------------------------------------------------------- diff --git a/examples/transparent.cpp b/examples/transparent.cpp index 6a5cb78a..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); @@ -56,10 +55,10 @@ class Transparent : public finalcut::FDialog Transparent& operator = (const Transparent&); // Method - void draw(); + virtual void draw(); // Event handlers - void onKeyPress (finalcut::FKeyEvent* ev); + virtual void onKeyPress (finalcut::FKeyEvent* ev); // Data Members trans_type type; @@ -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 @@ -160,13 +161,13 @@ class MainWindow : public finalcut::FDialog // Disable assignment operator (=) MainWindow& operator = (const MainWindow&); - void draw(); + virtual void draw(); // Event handlers - void onClose (finalcut::FCloseEvent*); - void onShow (finalcut::FShowEvent*); - void onTimer (finalcut::FTimerEvent*); - void onKeyPress (finalcut::FKeyEvent* ev) + virtual void onClose (finalcut::FCloseEvent*); + virtual void onShow (finalcut::FShowEvent*); + virtual void onTimer (finalcut::FTimerEvent*); + virtual void onKeyPress (finalcut::FKeyEvent* ev) { if ( ! ev ) return; @@ -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 ceeba2c7..92da5836 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -53,20 +53,21 @@ class Treeview : public finalcut::FDialog Treeview& operator = (const Treeview&); // Methods - void adjustSize(); - TreeItem* getAfrica(); - TreeItem* getAsia(); - TreeItem* getEurope(); - TreeItem* getNorthAmerica(); - TreeItem* getSouthAmerica(); - TreeItem* getOceania(); + virtual void adjustSize(); // 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 7810402d..4ede5747 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -50,8 +50,8 @@ class ProgressDialog : public finalcut::FDialog ProgressDialog& operator = (const ProgressDialog&); // Event handlers - void onShow (finalcut::FShowEvent*); - void onTimer (finalcut::FTimerEvent*); + virtual void onShow (finalcut::FShowEvent*); + virtual void onTimer (finalcut::FTimerEvent*); // Callback methods void cb_reset_bar (finalcut::FWidget*, data_ptr); @@ -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); } //---------------------------------------------------------------------- @@ -208,31 +200,30 @@ class TextWindow : public finalcut::FDialog TextWindow& operator = (const TextWindow&); // Method - void adjustSize(); + 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(); @@ -289,10 +279,10 @@ class MyDialog : public finalcut::FDialog void initButtons(); void initLabels(); void initWidgetsCallbacks(); - void adjustSize(); + virtual void adjustSize(); // Event handlers - void onClose (finalcut::FCloseEvent*); + virtual void onClose (finalcut::FCloseEvent*); // Callback methods void cb_noFunctionMsg (finalcut::FWidget*, data_ptr); @@ -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 da31c27a..0e00d924 100644 --- a/examples/watch.cpp +++ b/examples/watch.cpp @@ -44,8 +44,8 @@ class Watch : public finalcut::FDialog void printTime(); // Event handlers - void onTimer (finalcut::FTimerEvent*); - void onClose (finalcut::FCloseEvent*); + virtual void onTimer (finalcut::FTimerEvent*); + virtual void onClose (finalcut::FCloseEvent*); // Callback methods void cb_clock (finalcut::FWidget*, data_ptr); @@ -53,7 +53,7 @@ class Watch : public finalcut::FDialog protected: // Method - void adjustSize(); + virtual void adjustSize(); private: // Disable copy constructor @@ -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 8396faf7..cbf7cd7e 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -48,68 +48,65 @@ class SmallWindow : public finalcut::FDialog SmallWindow& operator = (const SmallWindow&); // Method - void adjustSize(); + virtual void adjustSize(); // Event handlers - void onShow (finalcut::FShowEvent*); - void onTimer (finalcut::FTimerEvent*); + virtual void onShow (finalcut::FShowEvent*); + 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,15 +209,15 @@ class Window : public finalcut::FDialog Window& operator = (const Window&); // Method - void createFileMenuItems (finalcut::FMenu*); - void createDialogButtons(); + void configureFileMenuItems(); + void configureDialogButtons(); void activateWindow (finalcut::FDialog*); - void adjustSize(); + virtual void adjustSize(); void addClickedCallback (finalcut::FWidget*, WindowCallback); void addClickedCallback (finalcut::FWidget*, FAppCallback); // Event handlers - void onClose (finalcut::FCloseEvent*); + virtual void onClose (finalcut::FCloseEvent*); // Callback methods void cb_createWindows (finalcut::FWidget*, data_ptr); @@ -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/logo/png/finalcut-logo.png b/logo/png/finalcut-logo.png index aaacf0f4..3a66c498 100644 Binary files a/logo/png/finalcut-logo.png and b/logo/png/finalcut-logo.png differ diff --git a/logo/svg/finalcut-logo.svg b/logo/svg/finalcut-logo.svg index b6491c09..ee9a0d32 100644 --- a/logo/svg/finalcut-logo.svg +++ b/logo/svg/finalcut-logo.svg @@ -11,7 +11,7 @@ version="1.1" width="100%" height="100%" - viewBox="0 0 750 128" + viewBox="0 0 650 128" id="svg2" style="fill-rule:evenodd"> + id="defs43"> + + + + + + + + + + + + + + + + + + + + + + + + + + + FINAL CUT + @@ -142,15 +289,15 @@ id="path35" style="fill:url(#f);stroke:#000000;stroke-width:0.70560002" /> + style="font-size:96px;font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0;word-spacing:0;writing-mode:lr-tb;text-anchor:start;fill:#083c99;fill-opacity:0.88747732;fill-rule:evenodd;stroke:none;font-family:FreeSans;-inkscape-font-specification:FreeSans Semi-Bold"> The Final Cut + id="tspan3006" + style="font-size:96px;font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#083c99;fill-opacity:0.88747732;stroke:none;font-family:FreeSans;-inkscape-font-specification:FreeSans Semi-Bold">FINAL CUT diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index 5c255254..116a20b3 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -2,8 +2,8 @@ if [ $# -gt 0 ] then - eval cppcheck --force --enable=all -I../include/ "$@" + eval cppcheck --force --enable=all -I../src/include/ "$@" else - eval cppcheck --force --enable=all -I../include/ ../src/ ../examples/ + 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/Makefile.am b/src/Makefile.am index 5d099c39..ccb53641 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,6 +42,7 @@ libfinal_la_SOURCES = \ fkey_map.cpp \ ftextview.cpp \ fstatusbar.cpp \ + ftermcap.cpp \ ftermcapquirks.cpp \ ftermxterminal.cpp \ ftermfreebsd.cpp \ @@ -108,7 +109,6 @@ finalcutinclude_HEADERS = \ include/final/fscrollview.h \ include/final/fstatusbar.h \ include/final/fstring.h \ - include/final/ftcap_map.h \ include/final/ftermcap.h \ include/final/ftermcapquirks.h \ include/final/ftermxterminal.h \ diff --git a/src/Makefile.clang b/src/Makefile.clang index 36a18907..a86ff5ee 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -12,10 +12,11 @@ INCLUDE_HEADERS = \ fapplication.h \ fbuttongroup.h \ fbutton.h \ + ftogglebutton.h \ fcheckbox.h \ fswitch.h \ fdialog.h \ - fevent.h \ + fwindow.h \ ffiledialog.h \ final.h \ flabel.h \ @@ -23,15 +24,12 @@ INCLUDE_HEADERS = \ flistbox.h \ flistview.h \ fmenu.h \ - fmouse.h \ - fkeyboard.h \ fdialoglistmenu.h \ fmenubar.h \ fradiomenuitem.h \ fcheckmenuitem.h \ fmessagebox.h \ ftooltip.h \ - fobject.h \ foptiattr.h \ foptimove.h \ ftermbuffer.h \ @@ -43,6 +41,8 @@ INCLUDE_HEADERS = \ fscrollview.h \ fstatusbar.h \ fstring.h \ + fmouse.h \ + fkeyboard.h \ ftermcap.h \ fterm.h \ ftermios.h \ @@ -54,11 +54,11 @@ INCLUDE_HEADERS = \ ftermlinux.h \ fvterm.h \ ftextview.h \ - ftogglebutton.h \ fcolorpalette.h \ fwidgetcolors.h \ fwidget.h \ - fwindow.h + fevent.h \ + fobject.h \ # compiler parameter CXX = clang++ @@ -87,8 +87,6 @@ OBJS = \ flistbox.o \ flistview.o \ fmenu.o \ - fmouse.o \ - fkeyboard.o \ fdialoglistmenu.o \ fmenubar.o \ fmenuitem.o \ @@ -96,14 +94,17 @@ OBJS = \ fcheckmenuitem.o \ fmenulist.o \ fdialog.o \ - fscrollview.o \ fwindow.o \ + fscrollview.o \ fmessagebox.o \ ftooltip.o \ ffiledialog.o \ fkey_map.o \ ftextview.o \ fstatusbar.o \ + fmouse.o \ + fkeyboard.o \ + ftermcap.o \ fterm.o \ ftermios.o \ ftermdetection.o \ @@ -113,7 +114,6 @@ OBJS = \ ftermopenbsd.o \ ftermlinux.o \ fvterm.o \ - fevent.o \ foptiattr.o \ foptimove.o \ ftermbuffer.o \ @@ -121,12 +121,14 @@ OBJS = \ fcolorpalette.o \ fwidgetcolors.o \ fwidget.o \ + fevent.o \ fobject.o TERMCAP := $(shell test -n "$$(ldd {/usr,}/lib64/libncursesw.so.5 2>/dev/null | grep libtinfo)" && echo "-ltinfo" || echo "-lncurses") ifdef DEBUG - OPTIMIZE = -O0 -fsanitize=undefined + OPTIMIZE = -O0 -fsanitize=bool,bounds,enum,float-cast-overflow,function,null +# OPTIMIZE = -O0 -fsanitize=undefined else OPTIMIZE = -O2 endif diff --git a/src/Makefile.gcc b/src/Makefile.gcc index 909b2afe..60a1c15f 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -12,10 +12,11 @@ INCLUDE_HEADERS = \ fapplication.h \ fbuttongroup.h \ fbutton.h \ + ftogglebutton.h \ fcheckbox.h \ fswitch.h \ fdialog.h \ - fevent.h \ + fwindow.h \ ffiledialog.h \ final.h \ flabel.h \ @@ -23,15 +24,12 @@ INCLUDE_HEADERS = \ flistbox.h \ flistview.h \ fmenu.h \ - fmouse.h \ - fkeyboard.h \ fdialoglistmenu.h \ fmenubar.h \ fradiomenuitem.h \ fcheckmenuitem.h \ fmessagebox.h \ ftooltip.h \ - fobject.h \ foptiattr.h \ foptimove.h \ ftermbuffer.h \ @@ -43,6 +41,8 @@ INCLUDE_HEADERS = \ fscrollview.h \ fstatusbar.h \ fstring.h \ + fmouse.h \ + fkeyboard.h \ ftermcap.h \ fterm.h \ ftermios.h \ @@ -54,11 +54,11 @@ INCLUDE_HEADERS = \ ftermlinux.h \ fvterm.h \ ftextview.h \ - ftogglebutton.h \ fcolorpalette.h \ fwidgetcolors.h \ fwidget.h \ - fwindow.h + fevent.h \ + fobject.h # compiler parameter CXX = g++ @@ -87,8 +87,6 @@ OBJS = \ flistbox.o \ flistview.o \ fmenu.o \ - fmouse.o \ - fkeyboard.o \ fdialoglistmenu.o \ fmenubar.o \ fmenuitem.o \ @@ -96,14 +94,17 @@ OBJS = \ fcheckmenuitem.o \ fmenulist.o \ fdialog.o \ - fscrollview.o \ fwindow.o \ + fscrollview.o \ fmessagebox.o \ ftooltip.o \ ffiledialog.o \ fkey_map.o \ ftextview.o \ fstatusbar.o \ + fmouse.o \ + fkeyboard.o \ + ftermcap.o \ fterm.o \ ftermios.o \ ftermdetection.o \ @@ -113,7 +114,6 @@ OBJS = \ ftermopenbsd.o \ ftermlinux.o \ fvterm.o \ - fevent.o \ foptiattr.o \ foptimove.o \ ftermbuffer.o \ @@ -121,6 +121,7 @@ OBJS = \ fcolorpalette.o \ fwidgetcolors.o \ fwidget.o \ + fevent.o \ fobject.o TERMCAP := $(shell test -n "$$(ldd {/usr,}/lib64/libncursesw.so.5 2>/dev/null | grep libtinfo)" && echo "-ltinfo" || echo "-lncurses") diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 9a3b7769..3e3a5d3d 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -1149,51 +1149,6 @@ void FApplication::processResizeEvent() } } -//---------------------------------------------------------------------- -int FApplication::processTimerEvent() -{ - FObject::TimerList::iterator iter, last; - timeval currentTime; - int activated = 0; - - getCurrentTime (¤tTime); - - if ( isTimerInUpdating() ) - return 0; - - if ( ! timer_list ) - return 0; - - if ( timer_list->empty() ) - return 0; - - iter = timer_list->begin(); - last = timer_list->end(); - - while ( iter != last ) - { - if ( ! iter->id - || ! iter->object - || currentTime < iter->timeout ) // no timer expired - break; - - iter->timeout += iter->interval; - - if ( iter->timeout < currentTime ) - iter->timeout = currentTime + iter->interval; - - if ( iter->interval.tv_usec > 0 || iter->interval.tv_sec > 0 ) - activated++; - - FTimerEvent t_ev(fc::Timer_Event, iter->id); - sendEvent(iter->object, &t_ev); - - ++iter; - } - - return activated; -} - //---------------------------------------------------------------------- void FApplication::processCloseWidget() { @@ -1219,7 +1174,7 @@ void FApplication::processCloseWidget() //---------------------------------------------------------------------- bool FApplication::processNextEvent() { - int num_events = 0; + uInt num_events = 0; processKeyboardEvent(); processMouseEvent(); @@ -1233,4 +1188,11 @@ bool FApplication::processNextEvent() return ( num_events > 0 ); } +//---------------------------------------------------------------------- +void FApplication::performTimerAction ( const FObject* receiver + , const FEvent* event ) +{ + sendEvent(receiver, event); +} + } // namespace finalcut diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 2813e0a3..83a38a47 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -1548,15 +1548,31 @@ inline void FDialog::lowerActivateDialog() updateTerminal(); } +//---------------------------------------------------------------------- +bool FDialog::isLowerRightResizeCorner (mouseStates& ms) +{ + // 3 characters in the lower right corner | + // x + // -----xx + + if ( (ms.mouse_x == getWidth() && ms.mouse_y == getHeight() - 1) + || ( ( ms.mouse_x == getWidth() - 1 + || ms.mouse_x == getWidth() ) && ms.mouse_y == getHeight() ) ) + { + return true; + } + else + { + return false; + } +} + //---------------------------------------------------------------------- void FDialog::resizeMouseDown (mouseStates& ms) { // Click on the lower right resize corner - if ( isResizeable() - && ( (ms.mouse_x == getWidth() && ms.mouse_y == getHeight()) - || (ms.mouse_x == getWidth() - 1 && ms.mouse_y == getHeight()) - || (ms.mouse_x == getWidth() && ms.mouse_y == getHeight() - 1) ) ) + if ( isResizeable() && isLowerRightResizeCorner(ms) ) { resize_click_pos = ms.termPos; FPoint lower_right_pos = getTermGeometry().getLowerRightPos(); diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 3e196224..2b56c952 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -33,7 +33,7 @@ bool sortByName ( const FFileDialog::dir_entry& lhs , const FFileDialog::dir_entry& rhs ) { // lhs < rhs - return bool(strcasecmp(lhs.name, rhs.name) < 0); + return bool( strcasecmp(lhs.name, rhs.name) < 0 ); } //---------------------------------------------------------------------- @@ -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/fkeyboard.cpp b/src/fkeyboard.cpp index d78c7dd6..918ef8e5 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -79,7 +79,7 @@ FKeyboard::FKeyboard() , keypressed_cmd() , keyreleased_cmd() , escape_key_cmd() - , termcap_map(0) + , key_map(0) { // Initialize keyboard values time_keypressed.tv_sec = 0; @@ -123,7 +123,7 @@ const FString FKeyboard::getKeyName (int keynum) //---------------------------------------------------------------------- void FKeyboard::setTermcapMap (fc::fkeymap* keymap) { - termcap_map = keymap; + key_map = keymap; } //---------------------------------------------------------------------- @@ -232,10 +232,10 @@ inline int FKeyboard::getTermcapKey() assert ( fifo_buf_size > 0 ); - if ( ! termcap_map ) + if ( ! key_map ) return -1; - fc::fkeymap* keymap = reinterpret_cast(termcap_map); + fc::fkeymap* keymap = reinterpret_cast(key_map); for (int i = 0; keymap[i].tname[0] != 0; i++) { char* k = keymap[i].string; @@ -515,9 +515,9 @@ int FKeyboard::keyCorrection (const int& keycode) if ( linux ) key_correction = linux->modifierKeyCorrection(keycode); else - key_correction = key; + key_correction = keycode; #else - key_correction = key; + key_correction = keycode; #endif return key_correction; diff --git a/src/flistview.cpp b/src/flistview.cpp index f62e4e5a..c02fdd6c 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -34,6 +34,123 @@ namespace finalcut // Static class attribute FObject::FObjectIterator FListView::null_iter; +// Function prototypes +long firstNumberFromString (const FString&); +bool sortAscendingByName (const FObject*, const FObject*); +bool sortDescendingByName (const FObject*, const FObject*); +bool sortAscendingByNumber (const FObject*, const FObject*); +bool sortDescendingByNumber (const FObject*, const FObject*); + +// non-member functions +//---------------------------------------------------------------------- +long firstNumberFromString (const FString& str) +{ + const FString::iterator last = str.end(); + FString::iterator iter = str.begin(); + FString::iterator first_pos; + FString::iterator last_pos; + long number; + + while ( iter != last ) + { + if ( wchar_t(*iter) >= L'0' && wchar_t(*iter) <= L'9' ) + { + if ( wchar_t(*(iter - 1)) == L'-' ) + --iter; + + break; + } + + ++iter; + } + + first_pos = iter; + + if ( first_pos == last ) + return 0; + + while ( iter != last ) + { + if ( wchar_t(*iter) < L'0' || wchar_t(*iter) > L'9' ) + break; + + ++iter; + } + + last_pos = iter; + + if ( last_pos == last ) + return 0; + + uInt pos = uInt(std::distance(str.begin(), first_pos)) + 1; + uInt length = uInt(std::distance(first_pos, last_pos)); + const FString num_str = str.mid(pos, length); + + try + { + number = num_str.toLong(); + } + catch (const std::exception&) + { + return 0; + } + + return number; +} + +//---------------------------------------------------------------------- +bool sortAscendingByName (const FObject* lhs, const FObject* rhs) +{ + const FListViewItem* l_item = static_cast(lhs); + const FListViewItem* r_item = static_cast(rhs); + const int column = l_item->getSortColumn(); + const FString l_string = l_item->getText(column); + const FString r_string = r_item->getText(column); + + // lhs < rhs + return bool( strcasecmp(l_string.c_str(), r_string.c_str()) < 0 ); +} + +//---------------------------------------------------------------------- +bool sortDescendingByName (const FObject* lhs, const FObject* rhs) +{ + const FListViewItem* l_item = static_cast(lhs); + const FListViewItem* r_item = static_cast(rhs); + const int column = l_item->getSortColumn(); + const FString l_string = l_item->getText(column); + const FString r_string = r_item->getText(column); + + // lhs > rhs + return bool( strcasecmp(l_string.c_str(), r_string.c_str()) > 0 ); +} + +//---------------------------------------------------------------------- +bool sortAscendingByNumber (const FObject* lhs, const FObject* rhs) +{ + const FListViewItem* l_item = static_cast(lhs); + const FListViewItem* r_item = static_cast(rhs); + const int column = l_item->getSortColumn(); + const long l_number = firstNumberFromString(l_item->getText(column)); + const long r_number = firstNumberFromString(r_item->getText(column)); + + // lhs < rhs + return bool( l_number < r_number ); +} + +//---------------------------------------------------------------------- +bool sortDescendingByNumber (const FObject* lhs, const FObject* rhs) +{ + const FListViewItem* l_item = static_cast(lhs); + const FListViewItem* r_item = static_cast(rhs); + const int column = l_item->getSortColumn(); + const long l_number = firstNumberFromString(l_item->getText(column)); + const long r_number = firstNumberFromString(r_item->getText(column)); + + // lhs > rhs + return bool( l_number > r_number ); +} + + //---------------------------------------------------------------------- // class FListViewItem //---------------------------------------------------------------------- @@ -44,6 +161,7 @@ FListViewItem::FListViewItem (const FListViewItem& item) : FObject(item.getParent()) , column_list(item.column_list) , data_pointer(item.data_pointer) + , root() , visible_lines(1) , expandable(false) , is_expand(false) @@ -68,6 +186,7 @@ FListViewItem::FListViewItem (FObjectIterator parent_iter) : FObject((*parent_iter)->getParent()) , column_list() , data_pointer(0) + , root() , visible_lines(1) , expandable(false) , is_expand(false) @@ -82,6 +201,7 @@ FListViewItem::FListViewItem ( const FStringList& cols : FObject(0) , column_list(cols) , data_pointer(data) + , root() , visible_lines(1) , expandable(false) , is_expand(false) @@ -99,6 +219,16 @@ FListViewItem::~FListViewItem() // destructor // public methods of FListViewItem +//---------------------------------------------------------------------- +int FListViewItem::getSortColumn() const +{ + if ( ! *root ) + return -1; + + FListView* root_obj = static_cast(*root); + return root_obj->getSortColumn(); +} + //---------------------------------------------------------------------- FString FListViewItem::getText (int column) const { @@ -208,11 +338,40 @@ void FListViewItem::collapse() } // private methods of FListView +//---------------------------------------------------------------------- +template +void FListViewItem::sort (Compare cmp) +{ + if ( ! expandable ) + return; + + // Sort the top level + FObject::FObjectList& children_list = getChildren(); + + if ( ! children_list.empty() ) + children_list.sort(cmp); + + // Sort the sublevels + FListViewIterator iter = children_list.begin(); + + while ( iter != children_list.end() ) + { + if ( *iter ) + { + FListViewItem* item = static_cast(*iter); + item->sort(cmp); + } + + ++iter; + } +} + //---------------------------------------------------------------------- FObject::FObjectIterator FListViewItem::appendItem (FListViewItem* child) { expandable = true; resetVisibleLineCounter(); + child->root = root; addChild (child); // Return iterator to child/last element return --FObject::end(); @@ -288,9 +447,6 @@ FListViewIterator::FListViewIterator (FObjectIterator iter) , position(0) { } -//---------------------------------------------------------------------- -FListViewIterator::~FListViewIterator() // destructor -{ } // FListViewIterator operators //---------------------------------------------------------------------- @@ -454,6 +610,11 @@ FListView::FListView (FWidget* parent) , xoffset(0) , nf_offset(0) , max_line_width(1) + , sort_column(-1) + , sort_type() + , sort_order(fc::unsorted) + , user_defined_ascending(0) + , user_defined_descending(0) { init(); } @@ -507,6 +668,24 @@ FString FListView::getColumnText (int column) const return header[uInt(column)].name; } +//---------------------------------------------------------------------- +fc::sorting_type FListView::getColumnSortType (int column) const +{ + fc::sorting_type type; + std::size_t size = uInt(column); + + try + { + type = sort_type.at(size); + } + catch (const std::out_of_range&) + { + type = fc::unknown; + } + + return type; +} + //---------------------------------------------------------------------- void FListView::setGeometry (int x, int y, int w, int h, bool adjust) { @@ -559,6 +738,34 @@ void FListView::setColumnText (int column, const FString& label) header[uInt(column)].name = label; } +//---------------------------------------------------------------------- +void FListView::setColumnSortType (int column, fc::sorting_type type) +{ + // Sets the sort type by which the list is to be sorted + + if ( column < 1 || header.empty() || column > int(header.size()) ) + return; + + std::size_t size = uInt(column + 1); + + if ( sort_type.empty() || sort_type.size() < size ) + sort_type.resize(size); + + sort_type[uInt(column)] = type; +} + +//---------------------------------------------------------------------- +void FListView::setColumnSort (int column, fc::sorting_order order) +{ + // Sets the column to sort by + the sorting order + + if ( column < 1 || header.empty() || column > int(header.size()) ) + column = -1; + + sort_column = column; + sort_order = order; +} + //---------------------------------------------------------------------- int FListView::addColumn (const FString& label, int width) { @@ -582,42 +789,14 @@ int FListView::addColumn (const FString& label, int width) FObject::FObjectIterator FListView::insert ( FListViewItem* item , FObjectIterator parent_iter ) { - static const int padding_space = 1; - int line_width = padding_space; // leading space - uInt column_idx = 0; - uInt entries = uInt(item->column_list.size()); FObjectIterator item_iter; - headerItems::iterator header_iter; + int line_width; + int element_count; if ( parent_iter == FListView::null_iter ) return FListView::null_iter; - // Determine the line width - header_iter = header.begin(); - - while ( header_iter != header.end() ) - { - int width = header_iter->width; - bool fixed_width = header_iter->fixed_width; - - if ( ! fixed_width ) - { - int len; - - if ( column_idx < entries ) - len = int(item->column_list[column_idx].getLength()); - else - len = 0; - - if ( len > width ) - header_iter->width = len; - } - - line_width += header_iter->width + padding_space; // width + trailing space - column_idx++; - ++header_iter; - } - + line_width = determineLineWidth (item); recalculateHorizontalBar (line_width); if ( parent_iter == root ) @@ -652,7 +831,10 @@ FObject::FObjectIterator FListView::insert ( FListViewItem* item first_visible_line = itemlist.begin(); } - int element_count = int(getCount()); + // Sort list by a column (only if activated) + sort(); + + element_count = int(getCount()); recalculateVerticalBar (element_count); return item_iter; } @@ -703,6 +885,55 @@ FObject::FObjectIterator FListView::insert ( const std::vector& cols return item_iter; } +//---------------------------------------------------------------------- +void FListView::sort() +{ + // Sorts the list view according to the specified setting + + if ( sort_column < 1 && sort_column > int(header.size()) ) + return; + + switch ( getColumnSortType(sort_column) ) + { + case fc::unknown: + case fc::by_name: + if ( sort_order == fc::ascending ) + { + sort (sortAscendingByName); + } + else if ( sort_order == fc::descending ) + { + sort (sortDescendingByName); + } + break; + + case fc::by_number: + if ( sort_order == fc::ascending ) + { + sort (sortAscendingByNumber); + } + else if ( sort_order == fc::descending ) + { + sort (sortDescendingByNumber); + } + break; + + case fc::user_defined: + if ( sort_order == fc::ascending && user_defined_ascending ) + { + sort (user_defined_ascending); + } + else if ( sort_order == fc::descending && user_defined_descending ) + { + sort (user_defined_descending); + } + break; + } + + current_iter = itemlist.begin(); + first_visible_line = itemlist.begin(); +} + //---------------------------------------------------------------------- void FListView::onKeyPress (FKeyEvent* ev) { @@ -1189,6 +1420,28 @@ void FListView::init() setRightPadding(1 + nf_offset); } +//---------------------------------------------------------------------- +template +void FListView::sort (Compare cmp) +{ + // Sort the top level + itemlist.sort(cmp); + + // Sort the sublevels + FListViewIterator iter = itemlist.begin(); + + while ( iter != itemlist.end() ) + { + if ( *iter ) + { + FListViewItem* item = static_cast(*iter); + item->sort(cmp); + } + + ++iter; + } +} + //---------------------------------------------------------------------- uInt FListView::getAlignOffset ( fc::text_alignment align , uInt txt_length @@ -1581,6 +1834,42 @@ void FListView::updateDrawing (bool draw_vbar, bool draw_hbar) flush_out(); } +//---------------------------------------------------------------------- +int FListView::determineLineWidth (FListViewItem* item) +{ + static const int padding_space = 1; + int line_width = padding_space; // leading space + uInt column_idx = 0; + uInt entries = uInt(item->column_list.size()); + headerItems::iterator header_iter; + header_iter = header.begin(); + + while ( header_iter != header.end() ) + { + int width = header_iter->width; + bool fixed_width = header_iter->fixed_width; + + if ( ! fixed_width ) + { + int len; + + if ( column_idx < entries ) + len = int(item->column_list[column_idx].getLength()); + else + len = 0; + + if ( len > width ) + header_iter->width = len; + } + + line_width += header_iter->width + padding_space; // width + trailing space + column_idx++; + ++header_iter; + } + + return line_width; +} + //---------------------------------------------------------------------- void FListView::recalculateHorizontalBar (int len) { @@ -1751,6 +2040,7 @@ void FListView::stopDragScroll() //---------------------------------------------------------------------- FObject::FObjectIterator FListView::appendItem (FListViewItem* item) { + item->root = root; addChild (item); itemlist.push_back (item); return --itemlist.end(); diff --git a/src/fmenu.cpp b/src/fmenu.cpp index df9f829f..79c3a134 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -38,7 +38,7 @@ namespace finalcut //---------------------------------------------------------------------- FMenu::FMenu(FWidget* parent) : FWindow(parent) - , item(0) + , item() , super_menu(0) , opened_sub_menu(0) , shown_sub_menu(0) @@ -53,7 +53,7 @@ FMenu::FMenu(FWidget* parent) //---------------------------------------------------------------------- FMenu::FMenu (const FString& txt, FWidget* parent) : FWindow(parent) - , item(0) + , item(txt, parent) , super_menu(0) , opened_sub_menu(0) , shown_sub_menu(0) @@ -62,16 +62,6 @@ FMenu::FMenu (const FString& txt, FWidget* parent) , mouse_down(false) , has_checkable_items(false) { - try - { - item = new FMenuItem(txt, parent); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - init(parent); } @@ -104,9 +94,7 @@ bool FMenu::setMenuWidget (bool on) void FMenu::setStatusbarMessage (const FString& msg) { FWidget::setStatusbarMessage(msg); - - if ( item ) - item->setStatusbarMessage(msg); + item.setStatusbarMessage(msg); } //---------------------------------------------------------------------- @@ -474,9 +462,7 @@ void FMenu::init(FWidget* parent) setForegroundColor (wc.menu_active_fg); setBackgroundColor (wc.menu_active_bg); - - if ( item ) - item->setMenu(this); + item.setMenu(this); if ( parent ) { @@ -500,9 +486,7 @@ void FMenu::init(FWidget* parent) //---------------------------------------------------------------------- void FMenu::calculateDimensions() { - int item_X - , item_Y - , adjust_X; + int item_X, item_Y, adjust_X; std::vector::const_iterator iter, last; iter = item_list.begin(); last = item_list.end(); @@ -1038,7 +1022,7 @@ bool FMenu::containsMenuStructure (int x, int y) return true; else if ( si && si->hasMenu() && opened_sub_menu ) return si->getMenu()->containsMenuStructure(x, y); - else if ( item && item->getTermGeometry().contains(x, y) ) + else if ( item.getTermGeometry().contains(x, y) ) return true; else return false; diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 88be543e..6e2d8d19 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -53,6 +53,13 @@ FMenuBar::~FMenuBar() // destructor // public methods of FMenuBar +//---------------------------------------------------------------------- +void FMenuBar::resetMenu() +{ + unselectItem(); + drop_down = false; +} + //---------------------------------------------------------------------- void FMenuBar::hide() { @@ -85,13 +92,6 @@ void FMenuBar::hide() delete[] blank; } -//---------------------------------------------------------------------- -void FMenuBar::resetMenu() -{ - unselectItem(); - drop_down = false; -} - //---------------------------------------------------------------------- void FMenuBar::adjustSize() { diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 725d3451..6bf0a942 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -99,6 +99,14 @@ FMenuItem::FMenuItem (int k, const FString& txt, FWidget* parent) //---------------------------------------------------------------------- FMenuItem::~FMenuItem() // destructor { + if ( super_menu && (isMenu(super_menu) || isMenuBar(super_menu)) ) + { + FMenuList* menu_list = dynamic_cast(super_menu); + + if ( menu_list ) + menu_list->remove(this); + } + delAccelerator(); // remove dialog list item callback from the dialog diff --git a/src/fobject.cpp b/src/fobject.cpp index 897cb893..80436273 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -240,22 +240,8 @@ int FObject::addTimer (int interval) timeval time_interval; timeval currentTime; int id = 1; - timer_modify_lock = true; - if ( ! timer_list ) - { - try - { - timer_list = new TimerList(); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return -1; - } - } - // find an unused timer id if ( ! timer_list->empty() ) { @@ -389,4 +375,52 @@ bool FObject::event (FEvent* ev) void FObject::onTimer (FTimerEvent*) { } +//---------------------------------------------------------------------- +uInt FObject::processTimerEvent() +{ + FObject::TimerList::iterator iter, last; + timeval currentTime; + uInt activated = 0; + + getCurrentTime (¤tTime); + + if ( isTimerInUpdating() ) + return 0; + + if ( ! timer_list ) + return 0; + + if ( timer_list->empty() ) + return 0; + + iter = timer_list->begin(); + last = timer_list->end(); + + while ( iter != last ) + { + if ( ! iter->id + || ! iter->object + || currentTime < iter->timeout ) // no timer expired + break; + + iter->timeout += iter->interval; + + if ( iter->timeout < currentTime ) + iter->timeout = currentTime + iter->interval; + + if ( iter->interval.tv_usec > 0 || iter->interval.tv_sec > 0 ) + activated++; + + FTimerEvent t_ev(fc::Timer_Event, iter->id); + performTimerAction (iter->object, &t_ev); + ++iter; + } + + return activated; +} + +//---------------------------------------------------------------------- +void FObject::performTimerAction (const FObject*, const FEvent*) +{ } + } // namespace finalcut diff --git a/src/foptimove.cpp b/src/foptimove.cpp index 95541d8e..d198408c 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -57,6 +57,7 @@ FOptiMove::FOptiMove (int baud) , F_clr_eol() , automatic_left_margin(false) , eat_nl_glitch(false) + , move_buf() , char_duration(1) , baudrate(baud) , tabstop(0) @@ -64,7 +65,10 @@ FOptiMove::FOptiMove (int baud) , screen_height(24) { assert ( baud >= 0 ); - move_buf[0] = '\0'; + + // Initialize arrays with '\0' + std::fill_n (move_buf, sizeof(move_buf), '\0'); + calculateCharDuration(); // ANSI set cursor address preset for undefined terminals @@ -830,7 +834,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x) // Move to fixed column position1 std::strncat ( hmove , tparm(F_column_address.cap, to_x, 0, 0, 0, 0, 0, 0, 0, 0) - , BUF_SIZE - std::strlen(hmove) ); + , BUF_SIZE - std::strlen(hmove) - 1); hmove[BUF_SIZE - 1] = '\0'; htime = F_column_address.duration; } @@ -853,7 +857,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime { std::strncpy ( hmove , tparm(F_parm_right_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0) - , BUF_SIZE ); + , BUF_SIZE - 1); hmove[BUF_SIZE - 1] = '\0'; htime = F_parm_right_cursor.duration; } @@ -908,7 +912,7 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime { std::strncpy ( hmove , tparm(F_parm_left_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0) - , BUF_SIZE ); + , BUF_SIZE - 1); hmove[BUF_SIZE - 1] = '\0'; htime = F_parm_left_cursor.duration; } @@ -973,7 +977,7 @@ inline bool FOptiMove::isMethod0Faster ( int& move_time if ( move_xy ) { char* move_ptr = move_buf; - std::strncpy (move_ptr, move_xy, BUF_SIZE); + std::strncpy (move_ptr, move_xy, BUF_SIZE - 1); move_ptr[BUF_SIZE - 1] = '\0'; move_time = F_cursor_address.duration; return true; @@ -1123,7 +1127,7 @@ void FOptiMove::moveByMethod ( int method case 2: if ( F_carriage_return.cap ) { - std::strncpy (move_ptr, F_carriage_return.cap, BUF_SIZE); + std::strncpy (move_ptr, F_carriage_return.cap, BUF_SIZE - 1); move_ptr[BUF_SIZE - 1] ='\0'; move_ptr += F_carriage_return.length; relativeMove (move_ptr, 0, yold, xnew, ynew); @@ -1131,14 +1135,14 @@ void FOptiMove::moveByMethod ( int method break; case 3: - std::strncpy (move_ptr, F_cursor_home.cap, BUF_SIZE); + std::strncpy (move_ptr, F_cursor_home.cap, BUF_SIZE - 1); move_ptr[BUF_SIZE - 1] ='\0'; move_ptr += F_cursor_home.length; relativeMove (move_ptr, 0, 0, xnew, ynew); break; case 4: - std::strncpy (move_ptr, F_cursor_to_ll.cap, BUF_SIZE); + std::strncpy (move_ptr, F_cursor_to_ll.cap, BUF_SIZE - 1); move_ptr[BUF_SIZE - 1] ='\0'; move_ptr += F_cursor_to_ll.length; relativeMove (move_ptr, 0, screen_height - 1, xnew, ynew); diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 79112831..cd40903d 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -99,7 +99,7 @@ bool FStatusKey::setMouseFocus(bool on) if ( on == mouse_focus ) return true; - return mouse_focus = ( on ) ? true : false; + return mouse_focus = on; } diff --git a/src/fstring.cpp b/src/fstring.cpp index eb0a31f5..64fa3c05 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -2675,32 +2675,41 @@ inline void FString::_assign (const wchar_t s[]) length = new_length; } +//---------------------------------------------------------------------- +inline void FString::_insert (uInt len, const wchar_t s[]) +{ + if ( len == 0 ) // String s is a null or a empty string + return; + + if ( string ) + delete[](string); + + length = len; + bufsize = FWDBUFFER + length + 1; + + try + { + string = new wchar_t[bufsize](); + } + catch (const std::bad_alloc& ex) + { + std::cerr << bad_alloc_str << " " << ex.what() << std::endl; + return; + } + + std::wcsncpy (string, s, bufsize); + string[bufsize - 1] = L'\0'; +} + //---------------------------------------------------------------------- inline void FString::_insert (uInt pos, uInt len, const wchar_t s[]) { if ( len == 0 ) // String s is a null or a empty string return; - if ( ! string ) + if ( ! string ) // string is null { - // string is null - - length = len; - bufsize = FWDBUFFER + length + 1; - - try - { - string = new wchar_t[bufsize](); - } - catch (const std::bad_alloc& ex) - { - std::cerr << bad_alloc_str << " " << ex.what() << std::endl; - return; - } - - std::wcsncpy (string, s, bufsize); - string[bufsize - 1] = L'\0'; - return; + _insert (len, s); } else { diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 0724ae74..792d573a 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -40,7 +40,7 @@ FSwitch::FSwitch(FWidget* parent) } //---------------------------------------------------------------------- -FSwitch::FSwitch ( const FString& txt, FWidget* parent ) +FSwitch::FSwitch (const FString& txt, FWidget* parent) : FToggleButton(txt, parent) , switch_offset_pos(0) , button_pressed(false) diff --git a/src/fterm.cpp b/src/fterm.cpp index 82af5598..5acf5408 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -27,7 +27,6 @@ #include "final/fterm.h" #include "final/fcharmap.h" -#include "final/ftcap_map.h" namespace finalcut { @@ -42,59 +41,15 @@ static bool term_initialized = false; int (*FTerm::Fputchar)(int); // static class attributes -int FTerm::fd_tty; -uInt FTerm::baudrate; -bool FTerm::resize_term; -bool FTerm::monochron; -bool FTerm::pc_charset_console; -bool FTerm::utf8_state; -bool FTerm::utf8_console; -bool FTerm::utf8_linux_terminal; -bool FTerm::force_vt100; // VT100 line drawing -bool FTerm::vt100_console; -bool FTerm::ascii_console; -bool FTerm::NewFont; -bool FTerm::VGAFont; -bool FTerm::shadow_character; -bool FTerm::half_block_character; -bool FTerm::cursor_optimisation; -bool FTerm::hidden_cursor; -bool FTerm::use_alternate_screen = true; -char FTerm::termtype[256] = { }; -char FTerm::termfilename[256] = { }; -#if DEBUG -int FTerm::framebuffer_bpp = -1; -#endif -char* FTerm::locale_name = 0; -char* FTerm::locale_xterm = 0; -FRect* FTerm::term = 0; - -char FTerm::exit_message[8192] = ""; -fc::encoding FTerm::term_encoding; -const FString* FTerm::save_xterm_font = 0; -const FString* FTerm::save_xterm_title = 0; -FOptiMove* FTerm::opti_move = 0; -FOptiAttr* FTerm::opti_attr = 0; -FTermDetection* FTerm::term_detection = 0; -FTermXTerminal* FTerm::xterm = 0; -FKeyboard* FTerm::keyboard = 0; -FMouseControl* FTerm::mouse = 0; -std::map* FTerm::vt100_alt_char = 0; -std::map* \ - FTerm::encoding_set = 0; -FTerm::termcap_map* FTerm::tcap = fc::term_caps; -bool FTermcap::background_color_erase = false; -bool FTermcap::automatic_left_margin = false; -bool FTermcap::automatic_right_margin = false; -bool FTermcap::eat_nl_glitch = false; -bool FTermcap::ansi_default_color = false; -bool FTermcap::osc_support = false; -bool FTermcap::no_utf8_acs_chars = false; -int FTermcap::max_color = 1; -int FTermcap::tabstop = 8; -int FTermcap::attr_without_color = 0; -FTerm::initializationValues FTerm::init_values; -fc::linuxConsoleCursorStyle FTerm::linux_console_cursor_style; +FTerm::initializationValues FTerm::init_values; +FTermData* FTerm::data = 0; +FTermcap::tcap_map* FTerm::tcap = 0; +FOptiMove* FTerm::opti_move = 0; +FOptiAttr* FTerm::opti_attr = 0; +FTermDetection* FTerm::term_detection = 0; +FTermXTerminal* FTerm::xterm = 0; +FKeyboard* FTerm::keyboard = 0; +FMouseControl* FTerm::mouse = 0; #if defined(__linux__) FTermLinux* FTerm::linux = 0; @@ -117,13 +72,8 @@ fc::linuxConsoleCursorStyle FTerm::linux_console_cursor_style; //---------------------------------------------------------------------- FTerm::FTerm (bool disable_alt_screen) { - resize_term = false; - if ( ! term_initialized ) - { - use_alternate_screen = ! disable_alt_screen; - init(); - } + init (disable_alt_screen); } //---------------------------------------------------------------------- @@ -138,19 +88,23 @@ FTerm::~FTerm() // destructor //---------------------------------------------------------------------- int FTerm::getLineNumber() { - if ( term->getHeight() == 0 ) + FRect& term_geometry = data->getTermGeometry(); + + if ( term_geometry.getHeight() == 0 ) detectTermSize(); - return term->getHeight(); + return term_geometry.getHeight(); } //---------------------------------------------------------------------- int FTerm::getColumnNumber() { - if ( term->getWidth() == 0 ) + FRect& term_geometry = data->getTermGeometry(); + + if ( term_geometry.getWidth() == 0 ) detectTermSize(); - return term->getWidth(); + return term_geometry.getWidth(); } //---------------------------------------------------------------------- @@ -168,11 +122,7 @@ bool FTerm::isNormal (charData*& ch) //---------------------------------------------------------------------- void FTerm::setTermType (const char term_name[]) { - if ( ! term_name ) - return; - - std::strncpy (termtype, term_name, sizeof(termtype)); - termtype[sizeof(termtype) - 1] = '\0'; + data->setTermType(term_name); } //---------------------------------------------------------------------- @@ -199,26 +149,26 @@ void FTerm::setDblclickInterval (const long timeout) //---------------------------------------------------------------------- bool FTerm::setUTF8 (bool on) // UTF-8 (Unicode) { - if ( on == utf8_state ) - return utf8_state; + if ( on == data->isUTF8() ) + return on; if ( on ) - utf8_state = true; + data->setUTF8(true); else - utf8_state = false; + data->setUTF8(false); #if defined(__linux__) linux->setUTF8 (on); #endif - return utf8_state; + return data->isUTF8(); } //---------------------------------------------------------------------- bool FTerm::setVGAFont() { - if ( VGAFont ) - return VGAFont; + if ( data->isVGAFont() ) + return data->isVGAFont(); if ( isGnomeTerminal() || isKdeTerminal() @@ -232,14 +182,13 @@ bool FTerm::setVGAFont() if ( isXTerminal() || isScreenTerm() || isUrxvtTerminal() || FTermcap::osc_support ) { - VGAFont = true; + data->setVGAFont(true); // Set font in xterm to vga xterm->setFont("vga"); - NewFont = false; - pc_charset_console = true; - term_encoding = fc::PC; + data->setNewFont(false); + data->setTermEncoding (fc::PC); - if ( isXTerminal() && utf8_console ) + if ( isXTerminal() && data->hasUTF8Console() ) Fputchar = &FTerm::putchar_UTF8; else Fputchar = &FTerm::putchar_ASCII; @@ -247,25 +196,27 @@ bool FTerm::setVGAFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - VGAFont = linux->loadVGAFont(); - pc_charset_console = true; - term_encoding = fc::PC; + data->setVGAFont(linux->loadVGAFont()); + data->setTermEncoding (fc::PC); Fputchar = &FTerm::putchar_ASCII; } #endif // defined(__linux__) else - VGAFont = false; + data->setVGAFont(false); - if ( VGAFont ) - shadow_character = half_block_character = true; + if ( data->isVGAFont() ) + { + data->supportShadowCharacter (true); + data->supportHalfBlockCharacter (true); + } - return VGAFont; + return data->isVGAFont(); } //---------------------------------------------------------------------- bool FTerm::setNewFont() { - if ( NewFont ) + if ( isNewFont() ) return true; if ( isGnomeTerminal() @@ -279,13 +230,12 @@ bool FTerm::setNewFont() if ( isXTerminal() || isScreenTerm() || isUrxvtTerminal() || FTermcap::osc_support ) { - NewFont = true; + data->setNewFont(true); // Set font in xterm to 8x16graph xterm->setFont("8x16graph"); - pc_charset_console = true; - term_encoding = fc::PC; + data->setTermEncoding (fc::PC); - if ( isXTerminal() && utf8_console ) + if ( isXTerminal() && data->hasUTF8Console() ) Fputchar = &FTerm::putchar_UTF8; else Fputchar = &FTerm::putchar_ASCII; @@ -293,19 +243,21 @@ bool FTerm::setNewFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - NewFont = linux->loadNewFont(); - pc_charset_console = true; - term_encoding = fc::PC; + data->setNewFont(linux->loadNewFont()); + data->setTermEncoding (fc::PC); Fputchar = &FTerm::putchar_ASCII; // function pointer } #endif // defined(__linux__) else - NewFont = false; + data->setNewFont(false); - if ( NewFont ) - shadow_character = half_block_character = true; + if ( isNewFont() ) + { + data->supportShadowCharacter (true); + data->supportHalfBlockCharacter (true); + } - return NewFont; + return isNewFont(); } //---------------------------------------------------------------------- @@ -313,20 +265,22 @@ bool FTerm::setOldFont() { bool retval = false; - if ( ! (NewFont || VGAFont) ) + if ( ! (data->isNewFont() || data->isVGAFont()) ) return false; - retval = \ - NewFont = \ - VGAFont = false; + retval = false; + data->setNewFont(false); + data->setVGAFont(false); if ( isXTerminal() || isScreenTerm() || isUrxvtTerminal() || FTermcap::osc_support ) { - if ( save_xterm_font && save_xterm_font->getLength() > 2 ) + const FString& font = data->getXtermFont(); + + if ( font.getLength() > 2 ) { // restore saved xterm font - xterm->setFont(*save_xterm_font); + xterm->setFont (font); } else { @@ -343,14 +297,17 @@ bool FTerm::setOldFont() if ( retval ) { - shadow_character = linux->hasShadowCharacter(); - half_block_character = linux->hasHalfBlockCharacter(); + data->supportShadowCharacter (linux->hasShadowCharacter()); + data->supportHalfBlockCharacter (linux->hasHalfBlockCharacter()); } } #endif // defined(__linux__) if ( retval ) - VGAFont = NewFont = false; + { + data->setVGAFont(false); + data->setNewFont(false); + } return retval; } @@ -358,6 +315,9 @@ bool FTerm::setOldFont() //---------------------------------------------------------------------- int FTerm::openConsole() { + int fd = data->getTTYFileDescriptor(); + char* termfilename = data->getTermFileName(); + static const char* terminal_devices[] = { "/proc/self/fd/0", @@ -369,15 +329,20 @@ int FTerm::openConsole() 0 }; - if ( fd_tty >= 0 ) // console is already opened + if ( fd >= 0 ) // console is already opened return 0; if ( ! *termfilename ) return 0; for (int i = 0; terminal_devices[i] != 0; i++) - if ( (fd_tty = open(terminal_devices[i], O_RDWR, 0)) >= 0 ) + { + fd = open(terminal_devices[i], O_RDWR, 0); + data->setTTYFileDescriptor(fd); + + if ( fd >= 0 ) return 0; + } return -1; // No file descriptor referring to the console } @@ -385,11 +350,14 @@ int FTerm::openConsole() //---------------------------------------------------------------------- int FTerm::closeConsole() { - if ( fd_tty < 0 ) // console is already closed + int fd = data->getTTYFileDescriptor(); + + if ( fd < 0 ) // console is already closed return 0; - int ret = ::close (fd_tty); // use 'close' from the global namespace - fd_tty = -1; + // use 'close' from the global namespace + int ret = ::close (fd); + data->setTTYFileDescriptor(-1); if ( ret == 0 ) return 0; @@ -402,7 +370,7 @@ char* FTerm::moveCursor (int xold, int yold, int xnew, int ynew) { // Returns the cursor move string - if ( cursor_optimisation ) + if ( data->hasCursorOptimisation() ) return opti_move->moveCursor (xold, yold, xnew, ynew); else return tgoto(TCAP(fc::t_cursor_address), xnew, ynew); @@ -415,7 +383,7 @@ char* FTerm::cursorsVisibility (bool on) char* visibility_str = 0; - if ( on == hidden_cursor ) + if ( on == data->isCursorHidden() ) return 0; if ( on ) @@ -423,14 +391,14 @@ char* FTerm::cursorsVisibility (bool on) visibility_str = disableCursor(); if ( visibility_str ) - hidden_cursor = true; // global state + data->setCursorHidden (true); // Global state } else { visibility_str = enableCursor(); if ( visibility_str ) - hidden_cursor = false; // global state + data->setCursorHidden (false); // Global state } return visibility_str; @@ -453,9 +421,9 @@ char* FTerm::enableCursor() char*& ve = TCAP(fc::t_cursor_normal); if ( ve ) - std::strncpy (enable_str, ve, SIZE); + std::strncpy (enable_str, ve, SIZE - 1); else if ( vs ) - std::strncpy (enable_str, vs, SIZE); + std::strncpy (enable_str, vs, SIZE - 1); #if defined(__linux__) if ( isLinuxTerm() ) @@ -500,55 +468,57 @@ void FTerm::detectTermSize() struct winsize win_size; bool close_after_detect = false; + int fd = data->getTTYFileDescriptor(); int ret; - if ( fd_tty < 0 ) // console is already closed + if ( fd < 0 ) // console is closed { if ( openConsole() != 0 ) return; + fd = data->getTTYFileDescriptor(); close_after_detect = true; } - ret = ioctl (fd_tty, TIOCGWINSZ, &win_size); + FRect& term_geometry = data->getTermGeometry(); + ret = ioctl (fd, TIOCGWINSZ, &win_size); if ( ret != 0 || win_size.ws_col == 0 || win_size.ws_row == 0 ) { char* str; - term->setPos(1,1); + term_geometry.setPos(1,1); // Use COLUMNS or fallback to the xterm default width of 80 characters str = std::getenv("COLUMNS"); - term->setWidth(str ? std::atoi(str) : 80); + term_geometry.setWidth(str ? std::atoi(str) : 80); // Use LINES or fallback to the xterm default height of 24 characters str = std::getenv("LINES"); - term->setHeight(str ? std::atoi(str) : 24); + term_geometry.setHeight(str ? std::atoi(str) : 24); } else { - term->setRect(1, 1, win_size.ws_col, win_size.ws_row); + term_geometry.setRect(1, 1, win_size.ws_col, win_size.ws_row); } - opti_move->setTermSize (term->getWidth(), term->getHeight()); + opti_move->setTermSize ( term_geometry.getWidth() + , term_geometry.getHeight() ); if ( close_after_detect ) closeConsole(); } //---------------------------------------------------------------------- -void FTerm::setTermSize (int term_width, int term_height) +void FTerm::setTermSize (int width, int height) { - // Set xterm size to {term_width} x {term_height} + // Set xterm size to {width} x {height} - if ( isXTerminal() ) - { - putstringf (CSI "8;%d;%dt", term_height, term_width); - std::fflush(stdout); - } + xterm->setTermSize (width, height); } //---------------------------------------------------------------------- void FTerm::setTermTitle (const FString& title) { + // Set the xterm window title + xterm->setTitle (title); } @@ -661,15 +631,15 @@ void FTerm::beep() //---------------------------------------------------------------------- void FTerm::setEncoding (fc::encoding enc) { - term_encoding = enc; + data->setTermEncoding (enc); - assert ( term_encoding == fc::UTF8 - || term_encoding == fc::VT100 // VT100 line drawing - || term_encoding == fc::PC // CP-437 - || term_encoding == fc::ASCII ); + assert ( enc == fc::UTF8 + || enc == fc::VT100 // VT100 line drawing + || enc == fc::PC // CP-437 + || enc == fc::ASCII ); // Set the new Fputchar function pointer - switch ( term_encoding ) + switch ( enc ) { case fc::UTF8: Fputchar = &FTerm::putchar_UTF8; @@ -677,7 +647,7 @@ void FTerm::setEncoding (fc::encoding enc) case fc::VT100: case fc::PC: - if ( isXTerminal() && utf8_console ) + if ( isXTerminal() && data->hasUTF8Console() ) Fputchar = &FTerm::putchar_UTF8; else Fputchar = &FTerm::putchar_ASCII; @@ -691,7 +661,7 @@ void FTerm::setEncoding (fc::encoding enc) if ( isLinuxTerm() ) { - if ( term_encoding == fc::VT100 || term_encoding == fc::PC ) + if ( enc == fc::VT100 || enc == fc::PC ) { char* empty = 0; opti_move->set_tabular (empty); @@ -704,16 +674,18 @@ void FTerm::setEncoding (fc::encoding enc) //---------------------------------------------------------------------- fc::encoding FTerm::getEncoding() { - return term_encoding; + return data->getTermEncoding(); } //---------------------------------------------------------------------- std::string FTerm::getEncodingString() { - std::map::const_iterator it, end; - end = encoding_set->end(); + fc::encoding term_encoding = data->getTermEncoding(); + FTermData::encodingMap& encoding_list = data->getEncodingList(); + std::map::const_iterator it, end; + end = encoding_list.end(); - for (it = encoding_set->begin(); it != end; ++it ) + for (it = encoding_list.begin(); it != end; ++it ) if ( it->second == term_encoding ) return it->first; @@ -730,7 +702,7 @@ bool FTerm::charEncodable (uInt c) //---------------------------------------------------------------------- uInt FTerm::charEncode (uInt c) { - return charEncode (c, term_encoding); + return charEncode (c, data->getTermEncoding()); } //---------------------------------------------------------------------- @@ -866,8 +838,8 @@ void FTerm::initScreenSettings() // Important: Do not use setNewFont() or setVGAFont() after // the console character mapping has been initialized linux->initCharMap (fc::character); - shadow_character = linux->hasShadowCharacter(); - half_block_character = linux->hasHalfBlockCharacter(); + data->supportShadowCharacter (linux->hasShadowCharacter()); + data->supportHalfBlockCharacter (linux->hasHalfBlockCharacter()); #endif #if defined(__FreeBSD__) || defined(__DragonFly__) @@ -889,14 +861,8 @@ char* FTerm::changeAttribute ( charData*& term_attr } //---------------------------------------------------------------------- -void FTerm::exitWithMessage (std::string message) +void FTerm::exitWithMessage (const FString& message) { - // Set the exit_message for the atexit-handler - snprintf ( exit_message - , sizeof(exit_message) - , "%s" - , message.c_str() ); - // Exit the programm if ( init_term_object ) init_term_object->finish(); @@ -904,8 +870,8 @@ void FTerm::exitWithMessage (std::string message) std::fflush (stderr); std::fflush (stdout); - if ( exit_message[0] ) - std::fprintf (stderr, "Warning: %s\n", exit_message); + if ( ! message.isEmpty() ) + std::cerr << "Warning: " << message << std::endl; std::exit (EXIT_FAILURE); } @@ -913,41 +879,35 @@ void FTerm::exitWithMessage (std::string message) // private methods of FTerm //---------------------------------------------------------------------- -void FTerm::init_global_values() +void FTerm::init_global_values (bool disable_alt_screen) { // Initialize global values - // Teletype (tty) file descriptor is still undefined - fd_tty = -1; - - // Preset to true - shadow_character = \ - half_block_character = \ - cursor_optimisation = true; - // Preset to false - hidden_cursor = \ - utf8_console = \ - utf8_state = \ - utf8_linux_terminal = \ - pc_charset_console = \ - vt100_console = \ - NewFont = \ - VGAFont = \ - ascii_console = \ - force_vt100 = false; + data->setNewFont(false); - // Init arrays with '\0' - std::fill_n (exit_message, sizeof(exit_message), '\0'); + // Sets alternative screen usage + data->useAlternateScreen(! disable_alt_screen); // Initialize xterm object - xterm->setTermcapMap(tcap); xterm->setFTermDetection(term_detection); if ( ! init_values.terminal_detection ) term_detection->setTerminalDetection (false); } +//---------------------------------------------------------------------- +void FTerm::init_terminal_device_path() +{ + char termfilename[256] = { }; + int stdout_no = FTermios::getStdOut(); + + if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) ) + termfilename[0] = '\0'; + + data->setTermFileName(termfilename); +} + //---------------------------------------------------------------------- void FTerm::oscPrefix() { @@ -978,6 +938,8 @@ void FTerm::init_alt_charset() { // Read the used VT100 pairs + std::map vt100_alt_char; + if ( TCAP(fc::t_acs_chars) ) { for (int n = 0; TCAP(fc::t_acs_chars)[n]; n += 2) @@ -985,7 +947,7 @@ void FTerm::init_alt_charset() // insert the VT100 key/value pairs into a map uChar p1 = uChar(TCAP(fc::t_acs_chars)[n]); uChar p2 = uChar(TCAP(fc::t_acs_chars)[n + 1]); - (*vt100_alt_char)[p1] = p2; + vt100_alt_char[p1] = p2; } } @@ -999,7 +961,7 @@ void FTerm::init_alt_charset() for (int n = 0; n <= fc::lastKeyItem; n++ ) { uChar keyChar = uChar(fc::vt100_key_to_utf8[n][vt100_key]); - uChar altChar = uChar((*vt100_alt_char)[ keyChar ]); + uChar altChar = uChar(vt100_alt_char[keyChar]); uInt utf8char = uInt(fc::vt100_key_to_utf8[n][utf8_char]); fc::encoding num = fc::NUM_OF_ENCODINGS; @@ -1010,10 +972,10 @@ void FTerm::init_alt_charset() { int item = int(std::distance(fc::character[0], p) / num); - if ( altChar ) - fc::character[item][fc::VT100] = altChar; // update alternate character set - else - fc::character[item][fc::VT100] = 0; // delete VT100 char in character + if ( altChar ) // update alternate character set + fc::character[item][fc::VT100] = altChar; + else // delete VT100 char in character + fc::character[item][fc::VT100] = 0; } } } @@ -1032,7 +994,7 @@ void FTerm::init_pc_charset() // Fallback if tcap "S2" is not found if ( ! TCAP(fc::t_enter_pc_charset_mode) ) { - if ( utf8_console ) + if ( data->hasUTF8Console() ) { // Select iso8859-1 + null mapping TCAP(fc::t_enter_pc_charset_mode) = \ @@ -1053,7 +1015,7 @@ void FTerm::init_pc_charset() // Fallback if tcap "S3" is not found if ( ! TCAP(fc::t_exit_pc_charset_mode) ) { - if ( utf8_console ) + if ( data->hasUTF8Console() ) { // Select ascii mapping + utf8 TCAP(fc::t_exit_pc_charset_mode) = \ @@ -1150,9 +1112,10 @@ void FTerm::init_termcap() bool color256 = term_detection->canDisplay256Colors(); // Share the terminal capabilities - FTermcap().setTermcapMap(tcap); + tcap = FTermcap::getTermcapMap(); // Open termcap file + const char* termtype = data->getTermType(); terminals.push_back(termtype); // available terminal type if ( color256 ) // 1st fallback if not found @@ -1165,8 +1128,7 @@ void FTerm::init_termcap() while ( iter != terminals.end() ) { - // Copy c-string + terminating null-character ('\0') - std::strncpy (termtype, iter->c_str(), iter->length() + 1); + data->setTermType(iter->c_str()); // Open the termcap file + load entry for termtype status = tgetent(term_buffer, termtype); @@ -1193,6 +1155,7 @@ void FTerm::init_termcap_error (int status) if ( status == no_entry || status == uninitialized ) { + const char* termtype = data->getTermType(); std::cerr << "Unknown terminal: " << termtype << "\n" << "Check the TERM environment variable\n" << "Also make sure that the terminal\n" @@ -1220,9 +1183,8 @@ void FTerm::init_termcap_variables (char*& buffer) // Terminal quirks FTermcapQuirks quirks; - quirks.setTermcapMap (tcap); + quirks.setTermData (data); quirks.setFTermDetection (term_detection); - quirks.setTerminalType (termtype); quirks.terminalFixup(); // Fix terminal quirks // Get termcap keys @@ -1276,9 +1238,9 @@ void FTerm::init_termcap_numerics() FTermcap::max_color = 1; if ( getMaxColor() < 8 ) - monochron = true; + data->setMonochron(true); else - monochron = false; + data->setMonochron(false); // Get initial spacing for hardware tab stop FTermcap::tabstop = tgetnum(C_STR("it")); @@ -1297,6 +1259,46 @@ void FTerm::init_termcap_strings (char*& buffer) tcap[i].string = tgetstr(tcap[i].tname, &buffer); } +//---------------------------------------------------------------------- +void FTerm::init_termcap_keys_vt100 (char*& buffer) +{ + // Some terminals (e.g. PuTTY) send vt100 key codes for + // the arrow and function keys. + + char* key_up_string = tgetstr(C_STR("ku"), &buffer); + + if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0)) + || ( TCAP(fc::t_cursor_up) + && (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) ) + { + for (int i = 0; fc::Fkey[i].tname[0] != 0; i++) + { + if ( std::strncmp(fc::Fkey[i].tname, "kux", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "A"); // Key up + + if ( std::strncmp(fc::Fkey[i].tname, "kdx", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "B"); // Key down + + if ( std::strncmp(fc::Fkey[i].tname, "krx", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "C"); // Key right + + if ( std::strncmp(fc::Fkey[i].tname, "klx", 3) == 0 ) + fc::Fkey[i].string = C_STR(CSI "D"); // Key left + + if ( std::strncmp(fc::Fkey[i].tname, "k1X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OP"); // PF1 + + if ( std::strncmp(fc::Fkey[i].tname, "k2X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OQ"); // PF2 + + if ( std::strncmp(fc::Fkey[i].tname, "k3X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OR"); // PF3 + + if ( std::strncmp(fc::Fkey[i].tname, "k4X", 3) == 0 ) + fc::Fkey[i].string = C_STR(ESC "OS"); // PF4 + } + } +} //---------------------------------------------------------------------- void FTerm::init_termcap_keys (char*& buffer) { @@ -1346,42 +1348,8 @@ void FTerm::init_termcap_keys (char*& buffer) fc::Fkey[i].string = C_STR(ESC "Ok"); // Keypad plus sign } - // Some terminals (e.g. PuTTY) send the wrong code for the arrow keys - // http://www.unix.com/shell-programming-scripting/.. - // ..110380-using-arrow-keys-shell-scripts.html - char* key_up_string = tgetstr(C_STR("ku"), &buffer); - - if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0)) - || ( TCAP(fc::t_cursor_up) - && (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) ) - { - for (int i = 0; fc::Fkey[i].tname[0] != 0; i++) - { - if ( std::strncmp(fc::Fkey[i].tname, "kux", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "A"); // Key up - - if ( std::strncmp(fc::Fkey[i].tname, "kdx", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "B"); // Key down - - if ( std::strncmp(fc::Fkey[i].tname, "krx", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "C"); // Key right - - if ( std::strncmp(fc::Fkey[i].tname, "klx", 3) == 0 ) - fc::Fkey[i].string = C_STR(CSI "D"); // Key left - - if ( std::strncmp(fc::Fkey[i].tname, "k1X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OP"); // PF1 - - if ( std::strncmp(fc::Fkey[i].tname, "k2X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OQ"); // PF2 - - if ( std::strncmp(fc::Fkey[i].tname, "k3X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OR"); // PF3 - - if ( std::strncmp(fc::Fkey[i].tname, "k4X", 3) == 0 ) - fc::Fkey[i].string = C_STR(ESC "OS"); // PF4 - } - } + // VT100 key codes for the arrow and function keys + init_termcap_keys_vt100(buffer); } //---------------------------------------------------------------------- @@ -1493,8 +1461,12 @@ void FTerm::init_font() void FTerm::init_locale() { // Init current locale + + char* locale_name; + 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"); @@ -1534,7 +1506,7 @@ void FTerm::init_locale() // Fallback to C if ( ! locale_name ) - locale_name = C_STR("C"); + std::setlocale (LC_ALL, "C"); } //---------------------------------------------------------------------- @@ -1542,6 +1514,7 @@ void FTerm::init_encoding() { // detect encoding and set the Fputchar function pointer + bool force_vt100 = false; // VT100 line drawing (G1 character set) init_encoding_set(); if ( isRxvtTerminal() && ! isUrxvtTerminal() ) @@ -1551,7 +1524,9 @@ void FTerm::init_encoding() init_pc_charset(); init_individual_term_encoding(); - if ( ! init_force_vt100_encoding() ) + if ( force_vt100 ) + init_force_vt100_encoding(); + else init_utf8_without_alt_charset(); init_tab_quirks(); @@ -1567,25 +1542,28 @@ inline void FTerm::init_encoding_set() { // Define the encoding set - (*encoding_set)["UTF8"] = fc::UTF8; - (*encoding_set)["UTF-8"] = fc::UTF8; - (*encoding_set)["VT100"] = fc::VT100; // VT100 line drawing - (*encoding_set)["PC"] = fc::PC; // CP-437 - (*encoding_set)["ASCII"] = fc::ASCII; + FTermData::encodingMap& encoding_list = data->getEncodingList(); + + encoding_list["UTF8"] = fc::UTF8; + encoding_list["UTF-8"] = fc::UTF8; + encoding_list["VT100"] = fc::VT100; // VT100 line drawing + encoding_list["PC"] = fc::PC; // CP-437 + encoding_list["ASCII"] = fc::ASCII; } //---------------------------------------------------------------------- void FTerm::init_term_encoding() { int stdout_no = FTermios::getStdOut(); + const char* termtype = data->getTermType(); if ( isatty(stdout_no) && ! std::strcmp(nl_langinfo(CODESET), "UTF-8") ) { - utf8_console = true; - term_encoding = fc::UTF8; - Fputchar = &FTerm::putchar_UTF8; // function pointer - utf8_state = true; + data->setUTF8Console(true); + data->setTermEncoding (fc::UTF8); + Fputchar = &FTerm::putchar_UTF8; // function pointer + data->setUTF8(true); setUTF8(true); keyboard->enableUTF8(); } @@ -1593,15 +1571,15 @@ void FTerm::init_term_encoding() && (std::strlen(termtype) > 0) && (TCAP(fc::t_exit_alt_charset_mode) != 0) ) { - vt100_console = true; - term_encoding = fc::VT100; - Fputchar = &FTerm::putchar_ASCII; // function pointer + data->setVT100Console (true); + data->setTermEncoding (fc::VT100); + Fputchar = &FTerm::putchar_ASCII; // function pointer } else { - ascii_console = true; - term_encoding = fc::ASCII; - Fputchar = &FTerm::putchar_ASCII; // function pointer + data->setASCIIConsole (true); + data->setTermEncoding (fc::ASCII); + Fputchar = &FTerm::putchar_ASCII; // function pointer } } @@ -1611,12 +1589,11 @@ void FTerm::init_individual_term_encoding() if ( isLinuxTerm() || isCygwinTerminal() || isNewFont() - || (isPuttyTerminal() && ! isUTF8()) - || (isTeraTerm() && ! isUTF8()) ) + || (isPuttyTerminal() && ! data->isUTF8()) + || (isTeraTerm() && ! data->isUTF8()) ) { - pc_charset_console = true; - term_encoding = fc::PC; - Fputchar = &FTerm::putchar_ASCII; // function pointer + data->setTermEncoding (fc::PC); + Fputchar = &FTerm::putchar_ASCII; // function pointer if ( hasUTF8() ) { @@ -1629,16 +1606,11 @@ void FTerm::init_individual_term_encoding() } //---------------------------------------------------------------------- -bool FTerm::init_force_vt100_encoding() +void FTerm::init_force_vt100_encoding() { - if ( force_vt100 ) // Force VT100 line drawing - { - vt100_console = true; - term_encoding = fc::VT100; - Fputchar = &FTerm::putchar_ASCII; // function pointer - } - - return force_vt100; + data->setVT100Console(true); + data->setTermEncoding (fc::VT100); + Fputchar = &FTerm::putchar_ASCII; // function pointer } //---------------------------------------------------------------------- @@ -1647,12 +1619,12 @@ void FTerm::init_utf8_without_alt_charset() // Fall back to ascii for utf-8 terminals that // do not support VT100 line drawings - if ( FTermcap::no_utf8_acs_chars && isUTF8() - && term_encoding == fc::VT100 ) + if ( FTermcap::no_utf8_acs_chars && data->isUTF8() + && data->getTermEncoding() == fc::VT100 ) { - ascii_console = true; - term_encoding = fc::ASCII; - Fputchar = &FTerm::putchar_ASCII; // function pointer + data->setASCIIConsole(true); + data->setTermEncoding (fc::ASCII); + Fputchar = &FTerm::putchar_ASCII; // function pointer } } @@ -1663,7 +1635,9 @@ void FTerm::init_tab_quirks() // on the terminal and does not move the cursor to the next tab stop // position - if ( term_encoding == fc::VT100 || term_encoding == fc::PC ) + fc::encoding enc = data->getTermEncoding(); + + if ( enc == fc::VT100 || enc == fc::PC ) { char* empty = 0; opti_move->set_tabular (empty); @@ -1680,10 +1654,10 @@ void FTerm::init_captureFontAndTitle() const FString* title = xterm->getTitle(); if ( font ) - save_xterm_font = new FString(*font); + data->setXtermFont(*font); if ( title ) - save_xterm_title = new FString(*title); + data->setXtermTitle(*title); } //---------------------------------------------------------------------- @@ -1741,13 +1715,15 @@ void FTerm::setInsertCursorStyle() #if defined(__linux__) char* cstyle; - cstyle = linux->setCursorStyle (fc::underscore_cursor, isCursorHidden()); + cstyle = linux->setCursorStyle ( fc::underscore_cursor + , data->isCursorHidden() ); putstring (cstyle); std::fflush(stdout); #endif #if defined(__FreeBSD__) || defined(__DragonFly__) - freebsd->setCursorStyle (fc::destructive_cursor, isCursorHidden()); + freebsd->setCursorStyle ( fc::destructive_cursor + , data->isCursorHidden() ); #endif if ( isUrxvtTerminal() ) @@ -1762,13 +1738,15 @@ void FTerm::setOverwriteCursorStyle() #if defined(__linux__) char* cstyle; - cstyle = linux->setCursorStyle (fc::full_block_cursor, isCursorHidden()); + cstyle = linux->setCursorStyle ( fc::full_block_cursor + , data->isCursorHidden() ); putstring (cstyle); std::fflush(stdout); #endif #if defined(__FreeBSD__) || defined(__DragonFly__) - freebsd->setCursorStyle (fc::normal_cursor, isCursorHidden()); + freebsd->setCursorStyle ( fc::normal_cursor + , data->isCursorHidden() ); #endif if ( isUrxvtTerminal() ) @@ -1814,7 +1792,7 @@ void FTerm::disableMouse() //---------------------------------------------------------------------- void FTerm::useAlternateScreenBuffer() { - if ( ! use_alternate_screen ) + if ( ! hasAlternateScreen() ) return; // Save current cursor position @@ -1835,7 +1813,7 @@ void FTerm::useAlternateScreenBuffer() //---------------------------------------------------------------------- void FTerm::useNormalScreenBuffer() { - if ( ! use_alternate_screen ) + if ( ! hasAlternateScreen() ) return; // restores the screen and the cursor position @@ -1858,10 +1836,13 @@ inline void FTerm::allocationValues() { try { + data = new FTermData(); opti_move = new FOptiMove(); opti_attr = new FOptiAttr(); term_detection = new FTermDetection(); xterm = new FTermXTerminal(); + keyboard = new FKeyboard(); + mouse = new FMouseControl(); #if defined(__linux__) linux = new FTermLinux(); @@ -1874,12 +1855,6 @@ inline void FTerm::allocationValues() #if defined(__NetBSD__) || defined(__OpenBSD__) openbsd = new FTermOpenBSD(); #endif - - keyboard = new FKeyboard(); - mouse = new FMouseControl(); - term = new FRect(0, 0, 0, 0); - vt100_alt_char = new std::map; - encoding_set = new std::map; } catch (const std::bad_alloc& ex) { @@ -1891,26 +1866,6 @@ inline void FTerm::allocationValues() //---------------------------------------------------------------------- inline void FTerm::deallocationValues() { - if ( encoding_set ) - delete encoding_set; - - if ( vt100_alt_char ) - delete vt100_alt_char; - - if ( save_xterm_title ) - delete save_xterm_title; - - if ( save_xterm_font ) - delete save_xterm_font; - - if ( term ) - delete term; - - if ( mouse ) - delete mouse; - - if ( keyboard ) - delete keyboard; #if defined(__NetBSD__) || defined(__OpenBSD__) if ( openbsd ) @@ -1927,6 +1882,12 @@ inline void FTerm::deallocationValues() delete linux; #endif + if ( mouse ) + delete mouse; + + if ( keyboard ) + delete keyboard; + if ( xterm ) delete xterm; @@ -1938,39 +1899,42 @@ inline void FTerm::deallocationValues() if ( opti_move ) delete opti_move; + + if ( data ) + delete data; } //---------------------------------------------------------------------- -void FTerm::init() +void FTerm::init (bool disable_alt_screen) { int stdout_no = FTermios::getStdOut(); init_term_object = this; // Initialize global values for all objects allocationValues(); - init_global_values(); + init_global_values(disable_alt_screen); // Initialize termios FTermios::init(); // Get pathname of the terminal device - if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) ) - termfilename[0] = '\0'; - - term_detection->setTermFileName(termfilename); + init_terminal_device_path(); + // Initialize Linux or *BSD console initOSspecifics(); // Save termios settings FTermios::storeTTYsettings(); // Get output baud rate - baudrate = FTermios::getBaudRate(); + uInt baud = FTermios::getBaudRate(); + data->setBaudrate(baud); if ( isatty(stdout_no) ) - opti_move->setBaudRate(int(baudrate)); + opti_move->setBaudRate(int(baud)); // Terminal detection + term_detection->setTermData(data); term_detection->detect(); setTermType (term_detection->getTermType()); @@ -2024,14 +1988,8 @@ void FTerm::init() // Save the used xterm font and window title init_captureFontAndTitle(); - if ( isKdeTerminal() ) - setKDECursor(fc::UnderlineCursor); - - if ( isCygwinTerminal() ) - init_cygwin_charmap(); - - if ( isTeraTerm() ) - init_teraterm_charmap(); + // KDE terminal cursor and cygwin + teraterm charmap correction + initTermspecifics(); // Redefine the color palette if ( init_values.color_change ) @@ -2044,7 +2002,7 @@ void FTerm::init() setSignalHandler(); if ( ! init_values.cursor_optimisation ) - setCursorOptimisation (false); + data->supportCursorOptimisation(false); // Activate the VGA or the new graphic font // (depending on the initialization values) @@ -2068,7 +2026,7 @@ void FTerm::initOSspecifics() linux->init(); // Initialize Linux console #if DEBUG - framebuffer_bpp = linux->getFramebufferBpp(); + data->setFramebufferBpp (linux->getFramebufferBpp()); #endif #endif // defined(__linux__) @@ -2097,14 +2055,29 @@ void FTerm::initOSspecifics() #endif } +//---------------------------------------------------------------------- +void FTerm::initTermspecifics() +{ + if ( isKdeTerminal() ) + setKDECursor(fc::UnderlineCursor); + + if ( isCygwinTerminal() ) + init_cygwin_charmap(); + + if ( isTeraTerm() ) + init_teraterm_charmap(); +} + //---------------------------------------------------------------------- void FTerm::finish() { // Set default signal handler + + const FString& title = data->getXtermTitle(); resetSignalHandler(); - if ( save_xterm_title && isXTerminal() && ! isRxvtTerminal() ) - setTermTitle (*save_xterm_title); + if ( title && isXTerminal() && ! isRxvtTerminal() ) + setTermTitle (title); // Restore the saved termios settings FTermios::restoreTTYsettings(); @@ -2166,7 +2139,7 @@ void FTerm::finish() finish_encoding(); - if ( NewFont || VGAFont ) + if ( data->isNewFont() || data->isVGAFont() ) setOldFont(); deallocationValues(); @@ -2192,7 +2165,7 @@ void FTerm::finishOSspecifics1() void FTerm::finish_encoding() { #if defined(__linux__) - if ( isLinuxTerm() && utf8_console ) + if ( isLinuxTerm() && data->hasUTF8Console() ) setUTF8(true); #endif } @@ -2244,10 +2217,13 @@ void FTerm::signal_handler (int signum) switch (signum) { case SIGWINCH: - if ( resize_term ) + if ( ! data ) break; + else if ( data->hasTermResized() ) + break; + // initialize a resize event to the root element - resize_term = true; + data->setTermResized(true); break; case SIGTERM: diff --git a/src/include/final/ftcap_map.h b/src/ftermcap.cpp similarity index 87% rename from src/include/final/ftcap_map.h rename to src/ftermcap.cpp index 1b43b71d..7e0f15ce 100644 --- a/src/include/final/ftcap_map.h +++ b/src/ftermcap.cpp @@ -1,9 +1,9 @@ /*********************************************************************** -* ftcap_map.h - Internally used termcap capabilities * +* ftermcap.cpp - Provides access to terminal capabilities * * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2015-2017 Markus Gans * +* Copyright 2015-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -20,22 +20,41 @@ * . * ***********************************************************************/ -#ifndef FTCAPMAP_H -#define FTCAPMAP_H - -#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) - #error "Only can be included directly." -#endif - #include "final/ftermcap.h" namespace finalcut { -namespace fc -{ +// static class attributes +bool FTermcap::background_color_erase = false; +bool FTermcap::automatic_left_margin = false; +bool FTermcap::automatic_right_margin = false; +bool FTermcap::eat_nl_glitch = false; +bool FTermcap::ansi_default_color = false; +bool FTermcap::osc_support = false; +bool FTermcap::no_utf8_acs_chars = false; +int FTermcap::max_color = 1; +int FTermcap::tabstop = 8; +int FTermcap::attr_without_color = 0; -static FTermcap::tcap_map term_caps[] = + +//---------------------------------------------------------------------- +// class FTermcap +//---------------------------------------------------------------------- + +// constructors and destructor +//---------------------------------------------------------------------- +FTermcap::FTermcap() +{ } + +//---------------------------------------------------------------------- +FTermcap::~FTermcap() // destructor +{ } + + +// private Data Member of FTermcap - termcap capabilities +//---------------------------------------------------------------------- +FTermcap::tcap_map FTermcap::tcap[] = { // .------------- term string // | .-------- Tcap-code @@ -140,8 +159,4 @@ static FTermcap::tcap_map term_caps[] = * "XX", "Us" and "Ue" are unofficial and they are only used here. */ -} // namespace fc - } // namespace finalcut - -#endif // FTCAPMAP_H diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index b58b5833..18b085e5 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -26,8 +26,8 @@ namespace finalcut { // static class attributes -char FTermcapQuirks::termtype[256] = { }; FTermcap::tcap_map* FTermcapQuirks::tcap = 0; +FTermData* FTermcapQuirks::fterm_data = 0; FTermDetection* FTermcapQuirks::term_detection = 0; @@ -38,7 +38,9 @@ FTermDetection* FTermcapQuirks::term_detection = 0; // constructors and destructor //---------------------------------------------------------------------- FTermcapQuirks::FTermcapQuirks() -{ } +{ + tcap = FTermcap::getTermcapMap(); +} //---------------------------------------------------------------------- FTermcapQuirks::~FTermcapQuirks() // destructor @@ -47,16 +49,9 @@ FTermcapQuirks::~FTermcapQuirks() // destructor // public methods of FTermcapQuirks //---------------------------------------------------------------------- -void FTermcapQuirks::setTerminalType (const char tt[]) +void FTermcapQuirks::setTermData (FTermData* data) { - std::strncpy (termtype, tt, sizeof(termtype)); - termtype[sizeof(termtype) - 1] = '\0'; -} - -//---------------------------------------------------------------------- -void FTermcapQuirks::setTermcapMap (FTermcap::tcap_map* tc) -{ - tcap = tc; + fterm_data = data; } //---------------------------------------------------------------------- @@ -255,6 +250,8 @@ void FTermcapQuirks::init_termcap_xterm_quirks() void FTermcapQuirks::init_termcap_rxvt_quirks() { // Set enter/exit alternative charset mode for rxvt terminal + const char* termtype = fterm_data->getTermType(); + if ( std::strncmp(termtype, "rxvt-16color", 12) == 0 ) { TCAP(fc::t_enter_alt_charset_mode) = \ diff --git a/src/ftermdetection.cpp b/src/ftermdetection.cpp index 84803c26..ba728668 100644 --- a/src/ftermdetection.cpp +++ b/src/ftermdetection.cpp @@ -31,8 +31,8 @@ FTermDetection::terminalType FTermDetection::terminal_type = \ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; FTermDetection::colorEnv FTermDetection::color_env; FTermDetection::secondaryDA FTermDetection::secondary_da; +FTermData* FTermDetection::fterm_data = 0; char FTermDetection::termtype[256] = { }; -char FTermDetection::termfilename[256] = { }; char FTermDetection::ttytypename[256] = { }; bool FTermDetection::decscusr_support; bool FTermDetection::terminal_detection; @@ -89,13 +89,9 @@ FTermDetection::~FTermDetection() // destructor // public methods of FTermDetection //---------------------------------------------------------------------- -void FTermDetection::setTermFileName (char term_filename[]) +void FTermDetection::setTermData (FTermData* data) { - if ( ! term_filename ) - return; - - std::strncpy (termfilename, term_filename, sizeof(termfilename)); - termfilename[sizeof(termfilename) - 1] = '\0'; + fterm_data = data; } //---------------------------------------------------------------------- @@ -128,6 +124,7 @@ void FTermDetection::getSystemTermType() { // Import the untrusted environment variable TERM const char* const& term_env = std::getenv(C_STR("TERM")); + const char* termfilename = fterm_data->getTermFileName(); if ( term_env ) { @@ -164,6 +161,7 @@ bool FTermDetection::getTTYtype() // vt100 ttys0 // Get term basename + const char* termfilename = fterm_data->getTermFileName(); const char* term_basename = std::strrchr(termfilename, '/'); if ( term_basename == 0 ) @@ -221,6 +219,7 @@ bool FTermDetection::getTTYSFileEntry() // Analyse /etc/ttys and get the term name // get term basename + const char* termfilename = fterm_data->getTermFileName(); const char* term_basename = std::strrchr(termfilename, '/'); if ( term_basename == 0 ) diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 50f95984..e802805e 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -38,8 +38,8 @@ namespace finalcut console_font_op FTermLinux::screen_font; unimapdesc FTermLinux::screen_unicode_map; - bool FTermLinux::NewFont; - bool FTermLinux::VGAFont; + bool FTermLinux::new_font; + bool FTermLinux::vga_font; bool FTermLinux::shadow_character = true; bool FTermLinux::half_block_character = true; bool FTermLinux::has_saved_palette = false; @@ -194,7 +194,7 @@ void FTermLinux::initCharMap (uInt char_map[][fc::NUM_OF_ENCODINGS]) { uInt c1, c2, c3, c4, c5; - if ( NewFont || VGAFont ) + if ( new_font || vga_font ) return; if ( screen_unicode_map.entry_ct != 0 ) @@ -255,7 +255,7 @@ void FTermLinux::finish() //---------------------------------------------------------------------- bool FTermLinux::loadVGAFont() { - VGAFont = true; + vga_font = true; if ( FTerm::openConsole() == 0 ) { @@ -265,7 +265,7 @@ bool FTermLinux::loadVGAFont() int ret = setScreenFont(fc::__8x16std, 256, 8, 16); if ( ret != 0 ) - VGAFont = false; + vga_font = false; // unicode character mapping struct unimapdesc unimap; @@ -275,24 +275,24 @@ bool FTermLinux::loadVGAFont() setUnicodeMap(&unimap); } else - VGAFont = false; + vga_font = false; FTerm::detectTermSize(); FTerm::closeConsole(); } else - VGAFont = false; + vga_font = false; - if ( VGAFont ) + if ( vga_font ) shadow_character = half_block_character = true; - return VGAFont; + return vga_font; } //---------------------------------------------------------------------- bool FTermLinux::loadNewFont() { - NewFont = true; + new_font = true; if ( FTerm::openConsole() == 0 ) { @@ -302,7 +302,7 @@ bool FTermLinux::loadNewFont() int ret = setScreenFont(fc::__8x16graph, 256, 8, 16); if ( ret != 0 ) - NewFont = false; + new_font = false; // unicode character mapping struct unimapdesc unimap; @@ -312,18 +312,18 @@ bool FTermLinux::loadNewFont() setUnicodeMap(&unimap); } else - NewFont = false; + new_font = false; FTerm::detectTermSize(); FTerm::closeConsole(); } else - NewFont = false; + new_font = false; - if ( VGAFont ) + if ( vga_font ) shadow_character = half_block_character = true; - return NewFont; + return new_font; } //---------------------------------------------------------------------- @@ -363,7 +363,7 @@ bool FTermLinux::loadOldFont (uInt char_map[][fc::NUM_OF_ENCODINGS]) } if ( retval ) - VGAFont = NewFont = false; + vga_font = new_font = false; return retval; } diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index 0b4d07e9..7cfb1517 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -31,9 +31,8 @@ namespace finalcut bool FTermXTerminal::mouse_support; bool FTermXTerminal::meta_sends_esc; bool FTermXTerminal::xterm_default_colors; -FTermcap::tcap_map* FTermXTerminal::tcap = 0; -FTermDetection* FTermXTerminal::term_detection = 0; -fc::xtermCursorStyle FTermXTerminal::cursor_style = fc::unknown_cursor_style; +int FTermXTerminal::term_width = 80; +int FTermXTerminal::term_height = 24; const FString* FTermXTerminal::xterm_font = 0; const FString* FTermXTerminal::xterm_title = 0; const FString* FTermXTerminal::foreground_color = 0; @@ -42,6 +41,9 @@ const FString* FTermXTerminal::cursor_color = 0; const FString* FTermXTerminal::mouse_foreground_color = 0; const FString* FTermXTerminal::mouse_background_color = 0; const FString* FTermXTerminal::highlight_background_color = 0; +FTermcap::tcap_map* FTermXTerminal::tcap = 0; +FTermDetection* FTermXTerminal::term_detection = 0; +fc::xtermCursorStyle FTermXTerminal::cursor_style = fc::unknown_cursor_style; //---------------------------------------------------------------------- @@ -56,6 +58,8 @@ FTermXTerminal::FTermXTerminal() mouse_support = \ meta_sends_esc = \ xterm_default_colors = false; + + tcap = FTermcap::getTermcapMap(); } //---------------------------------------------------------------------- @@ -121,6 +125,16 @@ void FTermXTerminal::setTitle (const FString& title) setXTermTitle(); } +//---------------------------------------------------------------------- +void FTermXTerminal::setTermSize (int width, int height) +{ + // Set xterm size to {term_width} x {term_height} + + term_width = width; + term_height = height; + setXTermSize(); +} + //---------------------------------------------------------------------- void FTermXTerminal::setForeground (const FString& fg) { @@ -398,6 +412,16 @@ void FTermXTerminal::setXTermTitle() } } +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermSize() +{ + if ( term_detection->isXTerminal() ) + { + FTerm::putstringf (CSI "8;%d;%dt", term_height, term_width); + std::fflush(stdout); + } +} + //---------------------------------------------------------------------- void FTermXTerminal::setXTermFont() { diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index b75b7108..8c9f5d0d 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -64,7 +64,8 @@ FToggleButton::FToggleButton (const FString& txt, FWidget* parent) , focus_inside_group(true) , text() { - init(txt); + FToggleButton::setText(txt); // call own method + init(); if ( parent && parent->isInstanceOf("FButtonGroup") ) { @@ -611,13 +612,6 @@ void FToggleButton::setGroup (FButtonGroup* btngroup) button_group = btngroup; } -//---------------------------------------------------------------------- -void FToggleButton::init (const FString& txt) -{ - setText(txt); - init(); -} - //---------------------------------------------------------------------- void FToggleButton::init() { diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 6e2c09bc..0cba59ba 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -51,8 +51,7 @@ FPoint* FVTerm::term_pos = 0; FVTerm::term_area* FVTerm::vterm = 0; FVTerm::term_area* FVTerm::vdesktop = 0; FVTerm::term_area* FVTerm::active_area = 0; -FVTerm::termcap_map* FVTerm::tcap = 0; -FTermcap::tcap_map* FTermcap::tcap = 0; +FTermcap::tcap_map* FVTerm::tcap = 0; FKeyboard* FVTerm::keyboard = 0; FVTerm::charData FVTerm::term_attribute; FVTerm::charData FVTerm::next_attribute; @@ -2099,7 +2098,7 @@ void FVTerm::init() std::memcpy (&next_attribute, &term_attribute, sizeof(charData)); // Receive the terminal capabilities - tcap = FTermcap().getTermcapMap(); + tcap = FTermcap::getTermcapMap(); // Create virtual terminal FRect term_geometry (0, 0, getColumnNumber(), getLineNumber()); diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 040f1134..8c6c563f 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -361,7 +361,7 @@ bool FWidget::setEnable (bool on) else flags &= ~fc::active; - return enable = ( on ) ? true : false; + return enable = on; } //---------------------------------------------------------------------- @@ -414,7 +414,7 @@ bool FWidget::setFocus (bool on) window->setWindowFocusWidget(this); } - return focus = ( on ) ? true : false; + return focus = on; } //---------------------------------------------------------------------- diff --git a/src/fwindow.cpp b/src/fwindow.cpp index f59decf1..ec501bd5 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -174,7 +174,7 @@ bool FWindow::activateWindow (bool on) active_area = getVWin(); } - return window_active = ( on ) ? true : false; + return window_active = on; } //---------------------------------------------------------------------- diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 58f8bbf7..3b04c661 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -89,11 +89,11 @@ class FApplication : public FWidget virtual ~FApplication(); // Accessors - const char* getClassName() const; - int getArgc() const; - char** getArgv() const; - FWidget* getMainWidget() const; - FWidget* getFocusWidget() const; + const char* getClassName() const; + int getArgc() const; + char** getArgv() const; + FWidget* getMainWidget() const; + virtual FWidget* getFocusWidget() const; // Mutator void setMainWidget (FWidget*); @@ -175,9 +175,10 @@ class FApplication : public FWidget void sendWheelEvent (const FPoint&, const FPoint&); void processMouseEvent(); void processResizeEvent(); - int processTimerEvent(); void processCloseWidget(); bool processNextEvent(); + virtual void performTimerAction ( const FObject* + , const FEvent* ); // Data Members int app_argc; diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index d5c0c2bd..62162c29 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -89,13 +89,13 @@ class FButton : public FWidget bool setNoUnderline(bool); bool setNoUnderline(); bool unsetNoUnderline(); - bool setEnable(bool); - bool setEnable(); - bool unsetEnable(); - bool setDisable(); - bool setFocus(bool); - bool setFocus(); - bool unsetFocus(); + virtual bool setEnable(bool); + virtual bool setEnable(); + virtual bool unsetEnable(); + virtual bool setDisable(); + virtual bool setFocus(bool); + virtual bool setFocus(); + virtual bool unsetFocus(); bool setFlat(bool); bool setFlat(); bool unsetFlat(); @@ -117,17 +117,17 @@ class FButton : public FWidget bool hasClickAnimation(); // Methods - void hide(); + virtual void hide(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onTimer (FTimerEvent*); - void onAccel (FAccelEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onTimer (FTimerEvent*); + virtual void onAccel (FAccelEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); private: // Disable copy constructor @@ -149,7 +149,7 @@ class FButton : public FWidget void drawMarginRight(); void drawTopBottomBackground(); void drawButtonTextLine (wchar_t[]); - void draw(); + virtual void draw(); void updateStatusBar(); void updateButtonColor(); void processClick(); diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index 633a0357..c2c819c6 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -87,10 +87,10 @@ class FButtonGroup : public FScrollView FString& getText(); // Mutator - bool setEnable(bool); - bool setEnable(); - bool unsetEnable(); - bool setDisable(); + virtual bool setEnable(bool); + virtual bool setEnable(); + virtual bool unsetEnable(); + virtual bool setDisable(); void setText (const FString&); // Inquiries @@ -99,16 +99,16 @@ class FButtonGroup : public FScrollView bool hasCheckedButton() const; // Methods - void hide(); + virtual void hide(); void insert (FToggleButton*); void remove (FToggleButton*); void checkScrollSize (FToggleButton*); void checkScrollSize (const FRect&); // Event handlers - void onMouseDown (FMouseEvent*); - void onAccel (FAccelEvent*); - void onFocusIn (FFocusEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onAccel (FAccelEvent*); + virtual void onFocusIn (FFocusEvent*); // Callback method void cb_buttonToggled (FWidget*, data_ptr); diff --git a/src/include/final/fc.h b/src/include/final/fc.h index b3b5ef18..9613c1f8 100644 --- a/src/include/final/fc.h +++ b/src/include/final/fc.h @@ -79,7 +79,7 @@ enum events Timer_Event // timer event occur }; -// Properties of a widget +// Properties of a widget ⚑ enum widget_flags { shadow = 0x00000001, @@ -1039,6 +1039,21 @@ enum sides left = 3 }; +enum sorting_type +{ + by_name, + by_number, + user_defined, + unknown +}; + +enum sorting_order +{ + ascending, + descending, + unsorted +}; + enum brackets_type { NoBrackets = 0, diff --git a/src/include/final/fcheckbox.h b/src/include/final/fcheckbox.h index ef854a89..bc56cce2 100644 --- a/src/include/final/fcheckbox.h +++ b/src/include/final/fcheckbox.h @@ -90,9 +90,9 @@ class FCheckBox : public FToggleButton FCheckBox& operator = (const FCheckBox&); // Methods - void init(); - void draw(); - void drawCheckButton(); + void init(); + virtual void draw(); + void drawCheckButton(); }; #pragma pack(pop) diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index 91f003e6..edcd32f4 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -104,7 +104,7 @@ class FDialog : public FWindow bool setModal (bool); bool setModal(); bool unsetModal(); - bool setResizeable (bool); + virtual bool setResizeable (bool); bool setScrollable (bool); bool setScrollable(); bool unsetScrollable(); @@ -115,16 +115,16 @@ class FDialog : public FWindow bool isScrollable(); // Methods - void show(); - void hide(); + virtual void show(); + virtual void hide(); int exec(); - void setPos (int, int, bool = true); - void move (int, int); + virtual void setPos (int, int, bool = true); + virtual void move (int, int); bool moveUp (int); bool moveDown (int); bool moveLeft (int); bool moveRight (int); - void setSize (int, int, bool = true); + virtual void setSize (int, int, bool = true); bool reduceHeight (int); bool expandHeight (int); bool reduceWidth (int); @@ -132,16 +132,16 @@ class FDialog : public FWindow void activateDialog(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onMouseDoubleClick (FMouseEvent*); - void onAccel (FAccelEvent*); - void onWindowActive (FEvent*); - void onWindowInactive (FEvent*); - void onWindowRaised (FEvent*); - void onWindowLowered (FEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onMouseDoubleClick (FMouseEvent*); + virtual void onAccel (FAccelEvent*); + virtual void onWindowActive (FEvent*); + virtual void onWindowInactive (FEvent*); + virtual void onWindowRaised (FEvent*); + virtual void onWindowLowered (FEvent*); protected: // Methods @@ -207,6 +207,7 @@ class FDialog : public FWindow void moveSizeKey (FKeyEvent*); void raiseActivateDialog(); void lowerActivateDialog(); + bool isLowerRightResizeCorner (mouseStates&); void resizeMouseDown (mouseStates&); void resizeMouseUpMove (mouseStates&, bool = false); void cancelMouseResize(); diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index 1c0412ab..56f1fd62 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -109,7 +109,7 @@ class FFileDialog : public FDialog , DialogType = FFileDialog::Open , FWidget* = 0 ); // Destructor - ~FFileDialog(); + virtual ~FFileDialog(); // Assignment operator (=) FFileDialog& operator = (const FFileDialog&); @@ -129,7 +129,7 @@ class FFileDialog : public FDialog bool unsetShowHiddenFiles(); // Event handler - void onKeyPress (FKeyEvent*); + virtual void onKeyPress (FKeyEvent*); // Methods static const FString fileOpenChooser ( FWidget* @@ -141,7 +141,7 @@ class FFileDialog : public FDialog protected: // Method - void adjustSize(); + virtual void adjustSize(); private: // Typedef @@ -163,10 +163,9 @@ class FFileDialog : public FDialog // Method void init(); - void allocation (int, int); - void deallocation(); + void widgetSettings (int, int); void initCallbacks(); - inline bool pattern_match (const char* const, char[]); + bool pattern_match (const char* const, char[]); void clear(); int numOfDirs(); void sortDir(); @@ -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/fkeyboard.h b/src/include/final/fkeyboard.h index 495752ec..85fd5eb0 100644 --- a/src/include/final/fkeyboard.h +++ b/src/include/final/fkeyboard.h @@ -177,7 +177,7 @@ class FKeyboard FKeyboardCommand escape_key_cmd; static timeval time_keypressed; - fc::fkeymap* termcap_map; + fc::fkeymap* key_map; #if defined(__linux__) #undef linux diff --git a/src/include/final/flabel.h b/src/include/final/flabel.h index 17ee55f5..15378063 100644 --- a/src/include/final/flabel.h +++ b/src/include/final/flabel.h @@ -107,7 +107,7 @@ class FLabel : public FWidget bool setReverseMode(bool); bool setReverseMode(); bool unsetReverseMode(); - bool setEnable (bool); + virtual bool setEnable (bool); void setNumber (uLong); void setNumber (long); void setNumber (float, int = FLT_DIG); @@ -120,12 +120,12 @@ class FLabel : public FWidget bool hasReverseMode(); // Methods - void hide(); + virtual void hide(); void clear(); // Event handlers - void onMouseDown (FMouseEvent*); - void onAccel (FAccelEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onAccel (FAccelEvent*); // Callback method void cb_accel_widget_destroyed (FWidget*, data_ptr); @@ -143,7 +143,7 @@ class FLabel : public FWidget int getHotkeyPos (wchar_t[], wchar_t[], uInt); void setHotkeyAccelerator(); int getAlignOffset (int); - void draw(); + virtual void draw(); void drawMultiLine(); void drawSingleLine(); void printLine (wchar_t[], uInt, int, int = 0); diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 02f38fb0..77e65dd0 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -96,46 +96,46 @@ class FLineEdit : public FWidget const FLineEdit& operator >> (FString&); // Accessors - const char* getClassName() const; - FString getText() const; - int getLabelOrientation(); + const char* getClassName() const; + FString getText() const; + int getLabelOrientation(); // Mutators - void setText (const FString&); - void setLabelText (const FString&); - void setLabelOrientation(const label_o); - bool setEnable(bool); - bool setEnable(); - bool unsetEnable(); - bool setDisable(); - bool setFocus(bool); - bool setFocus(); - bool unsetFocus(); - bool setShadow(bool); - bool setShadow(); - bool unsetShadow(); + void setText (const FString&); + void setLabelText (const FString&); + void setLabelOrientation(const label_o); + virtual bool setEnable(bool); + virtual bool setEnable(); + virtual bool unsetEnable(); + virtual bool setDisable(); + virtual bool setFocus(bool); + virtual bool setFocus(); + virtual bool unsetFocus(); + bool setShadow(bool); + bool setShadow(); + bool unsetShadow(); // Inquiry - bool hasShadow(); + bool hasShadow(); // Methods - void hide(); - void clear(); + virtual void hide(); + void clear(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onTimer (FTimerEvent*); - void onAccel (FAccelEvent*); - void onHide (FHideEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onTimer (FTimerEvent*); + virtual void onAccel (FAccelEvent*); + virtual void onHide (FHideEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); protected: - void adjustLabel(); - void adjustSize(); + void adjustLabel(); + virtual void adjustSize(); private: // Enumeration @@ -153,33 +153,33 @@ class FLineEdit : public FWidget FLineEdit& operator = (const FLineEdit&); // Methods - void init(); - bool hasHotkey(); - void draw(); - void drawInputField(); - void keyLeft(); - void keyRight(); - void keyHome(); - void keyEnd(); - void keyDel(); - void keyBackspace(); - void keyInsert(); - void keyEnter(); - bool keyInput (int); - void processActivate(); - void processChanged(); + void init(); + bool hasHotkey(); + virtual void draw(); + void drawInputField(); + void keyLeft(); + void keyRight(); + void keyHome(); + void keyEnd(); + void keyDel(); + void keyBackspace(); + void keyInsert(); + void keyEnter(); + bool keyInput (int); + void processActivate(); + void processChanged(); // Data Members - FString text; - FString label_text; - FLabel* label; - label_o label_orientation; - dragScroll drag_scroll; - bool scroll_timer; - int scroll_repeat; - bool insert_mode; - int cursor_pos; - int text_offset; + FString text; + FString label_text; + FLabel* label; + label_o label_orientation; + dragScroll drag_scroll; + bool scroll_timer; + int scroll_repeat; + bool insert_mode; + int cursor_pos; + int text_offset; }; #pragma pack(pop) diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 2ba95a76..966c70d2 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -153,7 +153,7 @@ class FListBox : public FWidget FListBox (Container, LazyConverter, FWidget* = 0); // Destructor - ~FListBox(); + virtual ~FListBox(); // Accessors const char* getClassName() const; @@ -173,14 +173,14 @@ class FListBox : public FWidget void showInsideBrackets (int, fc::brackets_type); void showNoBrackets (int); void showNoBrackets (listBoxItems::iterator); - void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, int, int, bool = true); void setMultiSelection (bool); void setMultiSelection (); void unsetMultiSelection (); - bool setDisable(); - bool setFocus (bool); - bool setFocus(); - bool unsetFocus(); + virtual bool setDisable(); + virtual bool setFocus (bool); + virtual bool setFocus(); + virtual bool unsetFocus(); void setText (const FString&); // Inquiries @@ -191,7 +191,7 @@ class FListBox : public FWidget bool hasBrackets (listBoxItems::iterator) const; // Methods - void hide(); + virtual void hide(); template void insert (Iterator, Iterator, InsertConverter); template @@ -209,21 +209,20 @@ class FListBox : public FWidget void clear(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onMouseDoubleClick (FMouseEvent*); - void onWheel (FWheelEvent*); - void onTimer (FTimerEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); - + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onMouseDoubleClick (FMouseEvent*); + virtual void onWheel (FWheelEvent*); + virtual void onTimer (FTimerEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); protected: // Methods - void adjustYOffset(); - void adjustSize(); + void adjustYOffset(); + virtual void adjustSize(); private: // Enumeration @@ -244,53 +243,53 @@ class FListBox : public FWidget static FString& getString (listBoxItems::iterator); // Methods - void init(); - void draw(); - void drawLabel(); - void drawList(); - void drawListLine (int, listBoxItems::iterator, bool); - void printLeftBracket (fc::brackets_type); - void printRightBracket (fc::brackets_type); - void drawListBracketsLine (int, listBoxItems::iterator, bool); - void setLineAttributes (int, bool, bool, bool&); - void unsetAttributes(); - void updateDrawing (bool, bool); - void recalculateHorizontalBar (int, bool); - void recalculateVerticalBar (int); - void getWidgetFocus(); - void multiSelection (int); - void multiSelectionUpTo (int); - void wheelUp (int); - void wheelDown (int); - bool dragScrollUp(); - bool dragScrollDown(); - void dragUp (int); - void dragDown (int); - void stopDragScroll(); - void prevListItem (int); - void nextListItem (int); - void scrollToX (int); - void scrollToY (int); - void scrollLeft (int); - void scrollRight (int); - void keyUp(); - void keyDown(); - void keyLeft(); - void keyRight(); - void keyPgUp(); - void keyPgDn(); - void keyHome(); - void keyEnd(); - bool keyEsc(); - void keyEnter(); - bool keySpace(); - bool keyInsert(); - bool keyBackspace(); - bool keyIncSearchInput (int); - void processClick(); - void processSelect(); - void processChanged(); - void lazyConvert (listBoxItems::iterator, int); + void init(); + virtual void draw(); + void drawLabel(); + void drawList(); + void drawListLine (int, listBoxItems::iterator, bool); + void printLeftBracket (fc::brackets_type); + void printRightBracket (fc::brackets_type); + void drawListBracketsLine (int, listBoxItems::iterator, bool); + void setLineAttributes (int, bool, bool, bool&); + void unsetAttributes(); + void updateDrawing (bool, bool); + void recalculateHorizontalBar (int, bool); + void recalculateVerticalBar (int); + void getWidgetFocus(); + void multiSelection (int); + void multiSelectionUpTo (int); + void wheelUp (int); + void wheelDown (int); + bool dragScrollUp(); + bool dragScrollDown(); + void dragUp (int); + void dragDown (int); + void stopDragScroll(); + void prevListItem (int); + void nextListItem (int); + void scrollToX (int); + void scrollToY (int); + void scrollLeft (int); + void scrollRight (int); + void keyUp(); + void keyDown(); + void keyLeft(); + void keyRight(); + void keyPgUp(); + void keyPgDn(); + void keyHome(); + void keyEnd(); + bool keyEsc(); + void keyEnter(); + bool keySpace(); + bool keyInsert(); + bool keyBackspace(); + bool keyIncSearchInput (int); + void processClick(); + void processSelect(); + void processChanged(); + void lazyConvert (listBoxItems::iterator, int); listBoxItems::iterator index2iterator (int); // Callback methods @@ -298,9 +297,9 @@ class FListBox : public FWidget void cb_HBarChange (FWidget*, data_ptr); // Function Pointer - void (*convertToItem) ( FListBoxItem& - , FWidget::data_ptr - , int index ); + void (*convertToItem) ( FListBoxItem& + , FWidget::data_ptr + , int index ); // Data Members listBoxItems itemlist; diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 709afe24..11f0f4bb 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -84,7 +84,7 @@ class FListViewItem : public FObject , FObjectIterator ); // Destructor - ~FListViewItem(); + virtual ~FListViewItem(); // Assignment operator (=) FListViewItem& operator = (const FListViewItem&); @@ -92,12 +92,14 @@ class FListViewItem : public FObject // Accessors const char* getClassName() const; uInt getColumnCount() const; + int getSortColumn() const; FString getText (int) const; + FWidget::data_ptr getData() const; uInt getDepth() const; // Mutator void setText (int, const FString&); - + void setData (FWidget::data_ptr); // Inquiry bool isExpand() const; @@ -113,6 +115,8 @@ class FListViewItem : public FObject bool isExpandable() const; // Methods + template + void sort (Compare); FObjectIterator appendItem (FListViewItem*); void replaceControlCodes(); int getVisibleLines(); @@ -121,6 +125,7 @@ class FListViewItem : public FObject // Data Members FStringList column_list; FWidget::data_ptr data_pointer; + FObjectIterator root; int visible_lines; bool expandable; bool is_expand; @@ -141,6 +146,14 @@ inline const char* FListViewItem::getClassName() const inline uInt FListViewItem::getColumnCount() const { return uInt(column_list.size()); } +//---------------------------------------------------------------------- +inline FWidget::data_ptr FListViewItem::getData() const +{ return data_pointer; } + +//---------------------------------------------------------------------- +inline void FListViewItem::setData (FWidget::data_ptr data) +{ data_pointer = data; } + //---------------------------------------------------------------------- inline bool FListViewItem::isExpand() const { return is_expand; } @@ -166,12 +179,9 @@ class FListViewIterator typedef std::stack FObjectIteratorStack; // Constructor - FListViewIterator (); + explicit FListViewIterator (); FListViewIterator (FObjectIterator); - // Destructor - ~FListViewIterator(); - // Overloaded operators FListViewIterator& operator ++ (); // prefix FListViewIterator operator ++ (int); // postfix @@ -246,19 +256,30 @@ class FListView : public FWidget explicit FListView (FWidget* = 0); // Destructor - ~FListView(); + virtual ~FListView(); // Accessors const char* getClassName() const; uInt getCount(); fc::text_alignment getColumnAlignment (int) const; FString getColumnText (int) const; + fc::sorting_type getColumnSortType (int) const; + fc::sorting_order getSortOrder() const; + int getSortColumn() const; FListViewItem* getCurrentItem(); // Mutators - void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, int, int, bool = true); void setColumnAlignment (int, fc::text_alignment); void setColumnText (int, const FString&); + void setColumnSortType (int,fc::sorting_type \ + = fc::by_name); + void setColumnSort (int, fc::sorting_order \ + = fc::ascending); + template + void setUserAscendingCompare (Compare); + template + void setUserDescendingCompare (Compare); bool setTreeView (bool); bool setTreeView(); bool unsetTreeView(); @@ -283,17 +304,18 @@ class FListView : public FWidget , FObjectIterator ); FObjectIterator beginOfList(); FObjectIterator endOfList(); + virtual void sort(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onMouseDoubleClick (FMouseEvent*); - void onWheel (FWheelEvent*); - void onTimer (FTimerEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onMouseDoubleClick (FMouseEvent*); + virtual void onWheel (FWheelEvent*); + virtual void onTimer (FTimerEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); // Data Members static FObjectIterator null_iter; @@ -301,12 +323,13 @@ class FListView : public FWidget protected: // Methods void adjustViewport(); - void adjustSize(); + virtual void adjustSize(); private: // Typedef struct Header; // forward declaration typedef std::vector
headerItems; + typedef std::vector sortTypes; // Constants static const int USE_MAX_SIZE = -1; @@ -319,8 +342,10 @@ class FListView : public FWidget // Methods void init(); + template + void sort (Compare); uInt getAlignOffset (fc::text_alignment, uInt, uInt); - void draw(); + virtual void draw(); void drawColumnLabels(); void drawList(); void drawListLine (const FListViewItem*, bool, bool); @@ -330,6 +355,7 @@ class FListView : public FWidget void drawColumnEllipsis ( headerItems::const_iterator& , const FString& ); void updateDrawing (bool, bool); + int determineLineWidth (FListViewItem* item); void recalculateHorizontalBar (int); void recalculateVerticalBar (int); void wheelUp (int); @@ -383,6 +409,11 @@ class FListView : public FWidget int xoffset; int nf_offset; int max_line_width; + int sort_column; + sortTypes sort_type; + fc::sorting_order sort_order; + bool (*user_defined_ascending) (const FObject*, const FObject*); + bool (*user_defined_descending) (const FObject*, const FObject*); // Friend class friend class FListViewItem; @@ -399,16 +430,13 @@ class FListView : public FWidget struct FListView::Header { public: - Header() + explicit Header() : name() , width (0) , fixed_width (false) , alignment (fc::alignLeft) { } - ~Header() - { } - FString name; int width; bool fixed_width; @@ -422,13 +450,31 @@ struct FListView::Header inline const char* FListView::getClassName() const { return "FListView"; } +//---------------------------------------------------------------------- +inline fc::sorting_order FListView::getSortOrder() const +{ return sort_order; } + +//---------------------------------------------------------------------- +inline int FListView::getSortColumn() const +{ return sort_column; } + //---------------------------------------------------------------------- inline FListViewItem* FListView::getCurrentItem() { return static_cast(*current_iter); } +//---------------------------------------------------------------------- +template +inline void FListView::setUserAscendingCompare (Compare cmp) +{ user_defined_ascending = cmp; } + +//---------------------------------------------------------------------- +template +inline void FListView::setUserDescendingCompare (Compare cmp) +{ user_defined_descending = cmp; } + //---------------------------------------------------------------------- inline bool FListView::setTreeView (bool on) -{ return tree_view = ( on ) ? true : false; } +{ return tree_view = on; } //---------------------------------------------------------------------- inline bool FListView::setTreeView() @@ -444,24 +490,24 @@ inline FObject::FObjectIterator FListView::insert (FListViewItem* item) //---------------------------------------------------------------------- inline FObject::FObjectIterator - FListView::insert ( const FStringList& cols, data_ptr d ) + FListView::insert (const FStringList& cols, data_ptr d) { return insert (cols, d, root); } //---------------------------------------------------------------------- inline FObject::FObjectIterator - FListView::insert ( const FStringList& cols - , FObjectIterator parent_iter ) + FListView::insert ( const FStringList& cols + , FObjectIterator parent_iter ) { return insert (cols, 0, parent_iter); } //---------------------------------------------------------------------- inline FObject::FObjectIterator - FListView::insert ( const std::vector& cols, data_ptr d ) + FListView::insert (const std::vector& cols, data_ptr d) { return insert (cols, d, root); } //---------------------------------------------------------------------- inline FObject::FObjectIterator - FListView::insert ( const std::vector& cols - , FObjectIterator parent_iter ) + FListView::insert ( const std::vector& cols + , FObjectIterator parent_iter ) { return insert (cols, 0, parent_iter); } //---------------------------------------------------------------------- diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index 7f79d4ac..4fad0255 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -87,19 +87,19 @@ class FMenu : public FWindow, public FMenuList // Accessors virtual const char* getClassName() const; FString getText() const; - FMenuItem* getItem() const; + FMenuItem* getItem(); // Mutators - bool setEnable(bool); - bool setEnable(); - bool unsetEnable(); - bool setDisable(); + virtual bool setEnable(bool); + virtual bool setEnable(); + virtual bool unsetEnable(); + virtual bool setDisable(); void setSelected(); void unsetSelected(); bool setMenuWidget (bool); bool setMenuWidget(); bool unsetMenuWidget(); - void setStatusbarMessage (const FString&); + virtual void setStatusbarMessage (const FString&); void setMenu (FMenu*); void setText (const FString&); @@ -110,15 +110,15 @@ class FMenu : public FWindow, public FMenuList bool hasMenu() const; // Methods - void show(); - void hide(); + virtual void show(); + virtual void hide(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onAccel (FAccelEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onAccel (FAccelEvent*); // Callback method void cb_menuitem_toggled (FWidget*, data_ptr); @@ -200,7 +200,7 @@ class FMenu : public FWindow, public FMenuList void keypressMenuBar (FKeyEvent*); bool hotkeyMenu (FKeyEvent*); int getHotkeyPos (wchar_t[], wchar_t[], uInt); - void draw(); + virtual void draw(); void drawItems(); void drawSeparator (int); void drawMenuLine (FMenuItem*, int); @@ -228,7 +228,7 @@ class FMenu : public FWindow, public FMenuList friend class FRadioMenuItem; // Data Members - FMenuItem* item; + FMenuItem item; FWidget* super_menu; FMenu* opened_sub_menu; FMenu* shown_sub_menu; @@ -247,35 +247,35 @@ inline const char* FMenu::getClassName() const //---------------------------------------------------------------------- inline FString FMenu::getText() const -{ return item->getText(); } +{ return item.getText(); } //---------------------------------------------------------------------- -inline FMenuItem* FMenu::getItem() const -{ return item; } +inline FMenuItem* FMenu::getItem() +{ return &item; } //---------------------------------------------------------------------- inline bool FMenu::setEnable(bool on) -{ return item->setEnable(on); } +{ return item.setEnable(on); } //---------------------------------------------------------------------- inline bool FMenu::setEnable() -{ return item->setEnable(); } +{ return item.setEnable(); } //---------------------------------------------------------------------- inline bool FMenu::unsetEnable() -{ return item->unsetEnable(); } +{ return item.unsetEnable(); } //---------------------------------------------------------------------- inline bool FMenu::setDisable() -{ return item->setDisable(); } +{ return item.setDisable(); } //---------------------------------------------------------------------- inline void FMenu::setSelected() -{ item->setSelected(); } +{ item.setSelected(); } //---------------------------------------------------------------------- inline void FMenu::unsetSelected() -{ item->unsetSelected(); } +{ item.unsetSelected(); } //---------------------------------------------------------------------- inline bool FMenu::setMenuWidget() @@ -287,27 +287,27 @@ inline bool FMenu::unsetMenuWidget() //---------------------------------------------------------------------- inline void FMenu::setMenu (FMenu* m) -{ item->setMenu(m); } +{ item.setMenu(m); } //---------------------------------------------------------------------- inline void FMenu::setText (const FString& txt) -{ item->setText(txt); } +{ item.setText(txt); } //---------------------------------------------------------------------- inline bool FMenu::isEnabled() const -{ return item->isEnabled(); } +{ return item.isEnabled(); } //---------------------------------------------------------------------- inline bool FMenu::isSelected() const -{ return item->isSelected(); } +{ return item.isSelected(); } //---------------------------------------------------------------------- inline bool FMenu::hasHotkey() const -{ return item->hasHotkey(); } +{ return item.hasHotkey(); } //---------------------------------------------------------------------- inline bool FMenu::hasMenu() const -{ return item->hasMenu(); } +{ return item.hasMenu(); } //---------------------------------------------------------------------- inline FWidget* FMenu::getSuperMenu() const @@ -327,7 +327,7 @@ inline FMenu* FMenu::superMenuAt (const FPoint& p) //---------------------------------------------------------------------- inline void FMenu::onAccel (FAccelEvent* ev) -{ item->onAccel(ev); } +{ item.onAccel(ev); } } // namespace finalcut diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index 5ca9ba73..922b6b5f 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -86,19 +86,19 @@ class FMenuBar : public FWindow, public FMenuList virtual const char* getClassName() const; // Methods - void hide(); - void resetMenu(); - void adjustSize(); + void resetMenu(); + virtual void hide(); + virtual void adjustSize(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onAccel (FAccelEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onAccel (FAccelEvent*); // Callback methods - void cb_item_deactivated (FWidget*, data_ptr); + void cb_item_deactivated (FWidget*, data_ptr); private: // Typedef @@ -115,46 +115,46 @@ class FMenuBar : public FWindow, public FMenuList FMenuBar (const FMenuBar&); // Disable assignment operator (=) - FMenuBar& operator = (const FMenuBar&); + FMenuBar& operator = (const FMenuBar&); // Inquiry - bool isMenu (FMenuItem*) const; + bool isMenu (FMenuItem*) const; // Methods - void init(); - void calculateDimensions(); - bool selectNextItem(); - bool selectPrevItem(); - bool hotkeyMenu (FKeyEvent*&); - int getHotkeyPos (wchar_t[], wchar_t[], uInt); - void draw(); - void drawItems(); - void drawItem (FMenuItem*, int&); - void setLineAttributes (FMenuItem*); - void drawMenuText (menuText&); - void drawEllipsis (menuText&, int); - void drawLeadingSpace (int&); - void drawTrailingSpace (int&); - void adjustItems(); - bool activateMenu (FMenuItem*); - bool clickItem (FMenuItem*); - void unselectMenuItem (FMenuItem*); - void selectMenuItem (FMenuItem*); - void mouseDownOverList (FMouseEvent*); - void mouseUpOverList (FMouseEvent*); - void mouseMoveOverList (FMouseEvent*); - void passEventToMenu (FMouseEvent*&); - void leaveMenuBar(); + void init(); + void calculateDimensions(); + bool selectNextItem(); + bool selectPrevItem(); + bool hotkeyMenu (FKeyEvent*&); + int getHotkeyPos (wchar_t[], wchar_t[], uInt); + virtual void draw(); + void drawItems(); + void drawItem (FMenuItem*, int&); + void setLineAttributes (FMenuItem*); + void drawMenuText (menuText&); + void drawEllipsis (menuText&, int); + void drawLeadingSpace (int&); + void drawTrailingSpace (int&); + void adjustItems(); + bool activateMenu (FMenuItem*); + bool clickItem (FMenuItem*); + void unselectMenuItem (FMenuItem*); + void selectMenuItem (FMenuItem*); + void mouseDownOverList (FMouseEvent*); + void mouseUpOverList (FMouseEvent*); + void mouseMoveOverList (FMouseEvent*); + void passEventToMenu (FMouseEvent*&); + void leaveMenuBar(); // Friend classes friend class FMenu; friend class FMenuItem; // Data Members - bool mouse_down; - bool drop_down; - bool focus_changed; - int screenWidth; + bool mouse_down; + bool drop_down; + bool focus_changed; + int screenWidth; }; #pragma pack(pop) diff --git a/src/include/final/fmenuitem.h b/src/include/final/fmenuitem.h index 8e6a31e7..493c48aa 100644 --- a/src/include/final/fmenuitem.h +++ b/src/include/final/fmenuitem.h @@ -90,74 +90,74 @@ class FMenuItem : public FWidget virtual ~FMenuItem(); // Accessors - const char* getClassName() const; - int getHotkey() const; - FMenu* getMenu() const; - uInt getTextLength() const; - FString getText() const; + const char* getClassName() const; + int getHotkey() const; + FMenu* getMenu() const; + uInt getTextLength() const; + FString getText() const; // Mutators - bool setEnable (bool); - bool setFocus (bool); - bool setFocus(); - bool unsetFocus(); - void setSelected(); - void unsetSelected(); - void setSeparator(); - void unsetSeparator(); - void setChecked(); - void unsetChecked(); - void setMenu (FMenu*); - void setText (const FString&); + virtual bool setEnable (bool); + virtual bool setFocus (bool); + virtual bool setFocus(); + virtual bool unsetFocus(); + void setSelected(); + void unsetSelected(); + void setSeparator(); + void unsetSeparator(); + void setChecked(); + void unsetChecked(); + void setMenu (FMenu*); + void setText (const FString&); // Inquiries - bool isSelected() const; - bool isSeparator() const; - bool isChecked() const; - bool hasHotkey() const; - bool hasMenu() const; + bool isSelected() const; + bool isSeparator() const; + bool isChecked() const; + bool hasHotkey() const; + bool hasMenu() const; // Methods - void addAccelerator (int, FWidget*); - void delAccelerator (FWidget*); - void openMenu(); + virtual void addAccelerator (int, FWidget*); + virtual void delAccelerator (FWidget*); + void openMenu(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDoubleClick (FMouseEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onAccel (FAccelEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDoubleClick (FMouseEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onAccel (FAccelEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); protected: // Accessor - FWidget* getSuperMenu() const; + FWidget* getSuperMenu() const; // Mutator - void setSuperMenu (FWidget*); + void setSuperMenu (FWidget*); // Inquiries - bool isWindowsMenu (FWidget*) const; - bool isMenuBar (FWidget*) const; - bool isMenu (FWidget*) const; + bool isWindowsMenu (FWidget*) const; + bool isMenuBar (FWidget*) const; + bool isMenu (FWidget*) const; // Data Members - FString text; - bool selected; - bool separator; - bool checkable; - bool checked; - bool radio_button; - bool dialog_index; - uInt text_length; - int hotkey; - int accel_key; - FMenu* menu; - FWidget* super_menu; - FDialog* associated_window; + FString text; + bool selected; + bool separator; + bool checkable; + bool checked; + bool radio_button; + bool dialog_index; + uInt text_length; + int hotkey; + int accel_key; + FMenu* menu; + FWidget* super_menu; + FDialog* associated_window; private: // Disable copy constructor @@ -167,17 +167,17 @@ class FMenuItem : public FWidget FMenuItem& operator = (const FMenuItem&); // Methods - void init (FWidget*); - uChar hotKey(); - void processActivate(); - void processDeactivate(); - void createDialogList (FMenu*); + void init (FWidget*); + uChar hotKey(); + void processActivate(); + void processDeactivate(); + void createDialogList (FMenu*); template - void passMouseEvent (T, FMouseEvent*, fc::events); + void passMouseEvent (T, FMouseEvent*, fc::events); // Callback methods - void cb_switchToDialog (FWidget*, data_ptr); - void cb_destroyDialog (FWidget*, data_ptr); + void cb_switchToDialog (FWidget*, data_ptr); + void cb_destroyDialog (FWidget*, data_ptr); virtual void processClicked(); diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index 95f8e86f..9f30c062 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -101,7 +101,7 @@ class FMessageBox : public FDialog , int, int, int , FWidget* = 0 ); // Destructor - ~FMessageBox(); + virtual ~FMessageBox(); // Assignment operator (=) FMessageBox& operator = (const FMessageBox&); @@ -142,7 +142,7 @@ class FMessageBox : public FDialog , int = 0 ); protected: // Method - void adjustSize(); + virtual void adjustSize(); // Callback method void cb_processClick (FWidget*, data_ptr); diff --git a/src/include/final/fobject.h b/src/include/final/fobject.h index 9d0d919b..3ebb31af 100644 --- a/src/include/final/fobject.h +++ b/src/include/final/fobject.h @@ -71,37 +71,38 @@ class FObject virtual ~FObject(); // Accessors - virtual const char* getClassName() const; - FObject* getParent() const; - FObject* getChild (int) const; - const FObjectList& getChildren() const; - int numOfChildren() const; - FObjectIterator begin(); - FObjectIterator end(); - constFObjectIterator begin() const; - constFObjectIterator end() const; + virtual const char* getClassName() const; + FObject* getParent() const; + FObject* getChild (int) const; + FObjectList& getChildren(); + const FObjectList& getChildren() const; + int numOfChildren() const; + FObjectIterator begin(); + FObjectIterator end(); + constFObjectIterator begin() const; + constFObjectIterator end() const; // Inquiries - bool hasParent() const; - bool hasChildren() const; - bool isChild (FObject*) const; - bool isDirectChild (FObject*) const; - bool isWidget() const; - bool isInstanceOf (const char[]) const; - bool isTimerInUpdating() const; + bool hasParent() const; + bool hasChildren() const; + bool isChild (FObject*) const; + bool isDirectChild (FObject*) const; + bool isWidget() const; + bool isInstanceOf (const char[]) const; + bool isTimerInUpdating() const; // Methods - void removeParent(); - void addChild (FObject*); - void delChild (FObject*); + void removeParent(); + void addChild (FObject*); + void delChild (FObject*); // Timer methods - static void getCurrentTime (timeval*); - static bool isTimeout (timeval*, long); - int addTimer (int); - bool delTimer (int); - bool delOwnTimer(); - bool delAllTimer(); + static void getCurrentTime (timeval*); + static bool isTimeout (timeval*, long); + int addTimer (int); + bool delTimer (int); + bool delOwnTimer(); + bool delAllTimer(); protected: struct timer_data @@ -115,13 +116,18 @@ class FObject // Typedef typedef std::vector TimerList; - // Event handler - virtual bool event (FEvent*); - virtual void onTimer (FTimerEvent*); + // Accessor + TimerList* getTimerList() const; - // Data Members - static TimerList* timer_list; - bool widget_object; + // Method + uInt processTimerEvent(); + + // Event handler + virtual bool event (FEvent*); + virtual void onTimer (FTimerEvent*); + + // Data Member + bool widget_object; private: // Disable copy constructor @@ -130,11 +136,15 @@ class FObject // Disable assignment operator (=) FObject& operator = (const FObject&); + // Method + virtual void performTimerAction (const FObject*, const FEvent*); + // Data Members - FObject* parent_obj; - FObjectList children_list; - bool has_parent; - static bool timer_modify_lock; + FObject* parent_obj; + FObjectList children_list; + bool has_parent; + static bool timer_modify_lock; + static TimerList* timer_list; }; #pragma pack(pop) @@ -147,6 +157,10 @@ inline const char* FObject::getClassName() const inline FObject* FObject::getParent() const { return parent_obj; } +//---------------------------------------------------------------------- +inline FObject::FObjectList& FObject::getChildren() +{ return children_list; } + //---------------------------------------------------------------------- inline const FObject::FObjectList& FObject::getChildren() const { return children_list; } @@ -195,7 +209,9 @@ inline bool FObject::isInstanceOf (const char classname[]) const inline bool FObject::isTimerInUpdating() const { return timer_modify_lock; } -} // namespace finalcut +//---------------------------------------------------------------------- +inline FObject::TimerList* FObject::getTimerList() const +{ return timer_list; } //---------------------------------------------------------------------- @@ -252,4 +268,6 @@ static inline bool operator < (const timeval& t1, const timeval& t2) || (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec); } +} // namespace finalcut + #endif // FOBJECT_H diff --git a/src/include/final/foptiattr.h b/src/include/final/foptiattr.h index ccf34f97..4524d5b9 100644 --- a/src/include/final/foptiattr.h +++ b/src/include/final/foptiattr.h @@ -159,7 +159,7 @@ class FOptiAttr explicit FOptiAttr(); // Destructor - ~FOptiAttr(); + virtual ~FOptiAttr(); // Friend operator functions friend bool operator == (const charData&, const charData&); diff --git a/src/include/final/foptimove.h b/src/include/final/foptimove.h index 11345618..99259e5f 100644 --- a/src/include/final/foptimove.h +++ b/src/include/final/foptimove.h @@ -110,7 +110,7 @@ class FOptiMove explicit FOptiMove (int = 0); // Destructor - ~FOptiMove(); + virtual ~FOptiMove(); // Accessors const char* getClassName() const; diff --git a/src/include/final/fprogressbar.h b/src/include/final/fprogressbar.h index 07fa5dd8..8670c356 100644 --- a/src/include/final/fprogressbar.h +++ b/src/include/final/fprogressbar.h @@ -82,7 +82,7 @@ class FProgressbar : public FWidget // Mutators void setPercentage (int); - void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, int, int, bool = true); bool setShadow (bool); bool setShadow(); bool unsetShadow(); @@ -91,7 +91,7 @@ class FProgressbar : public FWidget bool hasShadow(); // Methods - void hide(); + virtual void hide(); void reset(); private: diff --git a/src/include/final/fradiobutton.h b/src/include/final/fradiobutton.h index 71d66a7b..68f56796 100644 --- a/src/include/final/fradiobutton.h +++ b/src/include/final/fradiobutton.h @@ -90,9 +90,9 @@ class FRadioButton : public FToggleButton FRadioButton& operator = (const FRadioButton&); // Methods - void init(); - void draw(); - void drawRadioButton(); + void init(); + virtual void draw(); + void drawRadioButton(); }; #pragma pack(pop) diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index 08082a35..343a264b 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -91,34 +91,34 @@ class FScrollbar : public FWidget virtual ~FScrollbar(); // Accessors - const char* getClassName() const; - int getValue() const; - sType getScrollType() const; + const char* getClassName() const; + int getValue() const; + sType getScrollType() const; // Mutators - void setMinimum (int); - void setMaximum (int); - void setRange (int, int); - void setValue (int); - void setSteps (double); - void setPageSize (int, int); - void setOrientation (int); - void setGeometry (int, int, int, int, bool = true); + void setMinimum (int); + void setMaximum (int); + void setRange (int, int); + void setValue (int); + void setSteps (double); + void setPageSize (int, int); + void setOrientation (int); + virtual void setGeometry (int, int, int, int, bool = true); // Methods - void resize(); - void redraw(); - void calculateSliderValues(); - void drawVerticalBar(); - void drawHorizontalBar(); - void drawBar(); + virtual void resize(); + virtual void redraw(); + void calculateSliderValues(); + void drawVerticalBar(); + void drawHorizontalBar(); + void drawBar(); // Event handlers - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onWheel (FWheelEvent*); - void onTimer (FTimerEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onWheel (FWheelEvent*); + virtual void onTimer (FTimerEvent*); private: // Disable copy constructor @@ -128,37 +128,37 @@ class FScrollbar : public FWidget FScrollbar& operator = (const FScrollbar&); // Methods - void init(); - void draw(); - void drawButtons(); - sType getClickedScrollType (int, int); - sType getVerticalClickedScrollType (int); - sType getHorizontalClickedScrollType (int); - int getSliderClickPos (int, int); - void jumpToClickPos (int, int); - void jumpToClickPos (int); - void avoidScrollOvershoot(); - void processScroll(); + void init(); + virtual void draw(); + void drawButtons(); + sType getClickedScrollType (int, int); + sType getVerticalClickedScrollType (int); + sType getHorizontalClickedScrollType (int); + int getSliderClickPos (int, int); + void jumpToClickPos (int, int); + void jumpToClickPos (int); + void avoidScrollOvershoot(); + void processScroll(); // Data Members - sType scroll_type; - bool threshold_reached; - int threshold_time; - int repeat_time; - int slider_click_pos; - int slider_click_stop_pos; - int current_slider_pos; - int slider_pos; - int slider_length; - int bar_length; - int val; - int min; - int max; - double steps; - int pagesize; - int length; - int bar_orientation; - int max_color; + sType scroll_type; + bool threshold_reached; + int threshold_time; + int repeat_time; + int slider_click_pos; + int slider_click_stop_pos; + int current_slider_pos; + int slider_pos; + int slider_length; + int bar_length; + int val; + int min; + int max; + double steps; + int pagesize; + int length; + int bar_orientation; + int max_color; }; #pragma pack(pop) diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index 31af25d0..fbf16c4d 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -100,7 +100,7 @@ class FScrollView : public FWidget virtual void setWidth (int, bool = true); virtual void setHeight (int, bool = true); virtual void setSize (int, int, bool = true); - void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, int, int, bool = true); void setCursorPos (int, int); void setPrintPos (int, int); bool setViewportPrint (bool); @@ -126,11 +126,11 @@ class FScrollView : public FWidget virtual void draw(); // Event handlers - void onKeyPress (FKeyEvent*); - void onWheel (FWheelEvent*); - void onFocusIn (FFocusEvent*); - void onChildFocusIn (FFocusEvent*); - void onChildFocusOut (FFocusEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onWheel (FWheelEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onChildFocusIn (FFocusEvent*); + virtual void onChildFocusOut (FFocusEvent*); protected: // Using-declaration @@ -140,7 +140,7 @@ class FScrollView : public FWidget term_area* getPrintArea(); // Method - void adjustSize(); + virtual void adjustSize(); void copy2area(); private: diff --git a/src/include/final/fstatusbar.h b/src/include/final/fstatusbar.h index a9e9278d..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); @@ -103,12 +105,7 @@ class FStatusKey : public FWidget bool hasMouseFocus() const; // Event handler - void onAccel (FAccelEvent*); - - protected: - // Mutators - void setKey (int); - void setText (const FString&); + virtual void onAccel (FAccelEvent*); private: // Disable copy constructor @@ -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; } @@ -218,19 +215,19 @@ class FStatusBar : public FWindow bool hasActivatedKey(); // Methods - void hide(); + virtual void hide(); void drawMessage(); void clearMessage(); void insert (FStatusKey*); void remove (FStatusKey*); void remove (int); void clear(); - void adjustSize(); + virtual void adjustSize(); // Event handlers - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); // Callback method void cb_statuskey_activated (FWidget*, data_ptr); @@ -247,7 +244,7 @@ class FStatusBar : public FWindow // Methods void init(); - void draw(); + virtual void draw(); void drawKeys(); void drawKey (keyList::const_iterator); void drawActiveKey (keyList::const_iterator); diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 4d6b8338..c3e873ef 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -382,6 +382,7 @@ class FString // Methods void initLength (uInt); void _assign (const wchar_t[]); + void _insert (uInt, const wchar_t[]); void _insert (uInt, uInt, const wchar_t[]); void _remove (uInt, uInt); char* wc_to_c_str (const wchar_t[]) const; diff --git a/src/include/final/fswitch.h b/src/include/final/fswitch.h index 7abfd1c2..f8ecbc7c 100644 --- a/src/include/final/fswitch.h +++ b/src/include/final/fswitch.h @@ -80,15 +80,15 @@ class FSwitch : public FToggleButton virtual ~FSwitch(); // Accessor - const char* getClassName() const; + const char* getClassName() const; // Mutator - void setText (const FString&); + virtual void setText (const FString&); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); private: // Disable copy constructor @@ -98,14 +98,14 @@ class FSwitch : public FToggleButton FSwitch& operator = (const FSwitch&); // Methods - void draw(); - void drawCheckButton(); - void drawChecked(); - void drawUnchecked(); + virtual void draw(); + void drawCheckButton(); + void drawChecked(); + void drawUnchecked(); // Data Members - int switch_offset_pos; - bool button_pressed; + int switch_offset_pos; + bool button_pressed; }; #pragma pack(pop) diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 09a7b7d9..2d9d8eb2 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -139,7 +139,6 @@ #include "final/fkey_map.h" #include "final/fkeyboard.h" #include "final/fmouse.h" -#include "final/fobject.h" #include "final/foptiattr.h" #include "final/foptimove.h" #include "final/fpoint.h" @@ -147,6 +146,7 @@ #include "final/fstring.h" #include "final/ftermcap.h" #include "final/ftermcapquirks.h" +#include "final/ftermdata.h" #include "final/ftermdetection.h" #if defined(__linux__) @@ -187,147 +187,138 @@ class FTerm virtual ~FTerm(); // Accessors - virtual const char* getClassName() const; - static FKeyboard* getKeyboard(); - static FMouseControl* getMouseControl(); - static int getLineNumber(); - static int getColumnNumber(); - static const FString getKeyName (int); + virtual const char* getClassName() const; + static FKeyboard* getKeyboard(); + static FMouseControl* getMouseControl(); + static int getLineNumber(); + static int getColumnNumber(); + static const FString getKeyName (int); - static int getTTYFileDescriptor(); - static char* getTermType(); - static char* getTermFileName(); - static int getTabstop(); - static int getMaxColor(); + static int getTTYFileDescriptor(); + static char* getTermType(); + static char* getTermFileName(); + static int getTabstop(); + static int getMaxColor(); #if DEBUG - static const FString& getAnswerbackString(); - static const FString& getSecDAString(); - static const char* getTermType_256color(); - static const char* getTermType_Answerback(); - static const char* getTermType_SecDA(); - static int getFramebufferBpp(); + static const FString& getAnswerbackString(); + static const FString& getSecDAString(); + static const char* getTermType_256color(); + static const char* getTermType_Answerback(); + static const char* getTermType_SecDA(); + static int getFramebufferBpp(); #endif // DEBUG // Inquiries - static bool isCursorHidden(); - static bool isNormal (charData*&); - static bool isRaw(); - static bool hasPCcharset(); - static bool hasUTF8(); - static bool hasVT100(); - static bool hasASCII(); - static bool isMonochron(); - static bool isXTerminal(); - static bool isAnsiTerminal(); - static bool isRxvtTerminal(); - static bool isUrxvtTerminal(); - static bool isMltermTerminal(); - static bool isPuttyTerminal(); - static bool isKdeTerminal(); - static bool isGnomeTerminal(); - static bool isKtermTerminal(); - static bool isTeraTerm(); - static bool isSunTerminal(); - static bool isCygwinTerminal(); - static bool isMinttyTerm(); - static bool isLinuxTerm(); - static bool isFreeBSDTerm(); - static bool isNetBSDTerm(); - static bool isOpenBSDTerm(); - static bool isScreenTerm(); - static bool isTmuxTerm(); - static bool isNewFont(); - static bool isUTF8(); + static bool isNormal (charData*&); + static bool isRaw(); + static bool hasUTF8(); + static bool hasVT100(); + static bool hasASCII(); + static bool isMonochron(); + static bool isXTerminal(); + static bool isAnsiTerminal(); + static bool isRxvtTerminal(); + static bool isUrxvtTerminal(); + static bool isMltermTerminal(); + static bool isPuttyTerminal(); + static bool isKdeTerminal(); + static bool isGnomeTerminal(); + static bool isKtermTerminal(); + static bool isTeraTerm(); + static bool isSunTerminal(); + static bool isCygwinTerminal(); + static bool isMinttyTerm(); + static bool isLinuxTerm(); + static bool isFreeBSDTerm(); + static bool isNetBSDTerm(); + static bool isOpenBSDTerm(); + static bool isScreenTerm(); + static bool isTmuxTerm(); + static bool isNewFont(); // Mutators - static void setTermType (const char[]); - static void setInsertCursor (bool on); - static void setInsertCursor(); - static void unsetInsertCursor(); - static bool setCursorOptimisation (bool); - static void redefineDefaultColors (bool); - static void setDblclickInterval (const long); - static void disableAltScreen(); - static bool setUTF8 (bool); - static bool setUTF8(); - static bool unsetUTF8(); + static void setTermType (const char[]); + static void setInsertCursor (bool on); + static void setInsertCursor(); + static void unsetInsertCursor(); + static void redefineDefaultColors (bool); + static void setDblclickInterval (const long); + static bool setUTF8 (bool); + static bool setUTF8(); + static bool unsetUTF8(); // Methods - static bool setVGAFont(); - static bool setNewFont(); - static bool setOldFont(); - static int openConsole(); - static int closeConsole(); - static char* moveCursor (int, int, int, int); - static char* cursorsVisibility (bool); - static void printMoveDurations(); - static char* enableCursor(); - static char* disableCursor(); - static void detectTermSize(); - static void setTermSize (int, int); - static void setTermTitle(const FString&); - static void setKDECursor (fc::kdeKonsoleCursorShape); - static void saveColorMap(); - static void resetColorMap(); - static void setPalette (short, int, int, int); - static void setBeep (int, int); - static void resetBeep(); - static void beep(); + static bool setVGAFont(); + static bool setNewFont(); + static bool setOldFont(); + static int openConsole(); + static int closeConsole(); + static char* moveCursor (int, int, int, int); + static char* cursorsVisibility (bool); + static void printMoveDurations(); + static char* enableCursor(); + static char* disableCursor(); + static void detectTermSize(); + static void setTermSize (int, int); + static void setTermTitle(const FString&); + static void setKDECursor (fc::kdeKonsoleCursorShape); + static void saveColorMap(); + static void resetColorMap(); + static void setPalette (short, int, int, int); + static void setBeep (int, int); + static void resetBeep(); + static void beep(); - static void setEncoding (fc::encoding); - static fc::encoding getEncoding(); - static std::string getEncodingString(); - static bool charEncodable (uInt); - static uInt charEncode (uInt); - static uInt charEncode (uInt, fc::encoding); + static void setEncoding (fc::encoding); + static fc::encoding getEncoding(); + static std::string getEncodingString(); + static bool charEncodable (uInt); + static uInt charEncode (uInt); + static uInt charEncode (uInt, fc::encoding); - static bool scrollTermForward(); - static bool scrollTermReverse(); + static bool scrollTermForward(); + static bool scrollTermReverse(); // function pointer -> static function - static int (*Fputchar)(int); + static int (*Fputchar)(int); - static void putstringf (const char[], ...) + static void putstringf (const char[], ...) #if defined(__clang__) __attribute__((__format__ (__printf__, 1, 2))) #elif defined(__GNUC__) __attribute__ ((format (printf, 1, 2))) #endif - ; - static void putstring (const char[], int = 1); + ; + static void putstring (const char[], int = 1); #if defined(__sun) && defined(__SVR4) - static int putchar_ASCII (char); + static int putchar_ASCII (char); #endif - static int putchar_ASCII (int); - static int putchar_UTF8 (int); - -#if DEBUG - static int framebuffer_bpp; -#endif + static int putchar_ASCII (int); + static int putchar_UTF8 (int); protected: // Inquiries - static bool hasChangedTermSize(); - static bool hasShadowCharacter(); - static bool hasHalfBlockCharacter(); - static bool hasAlternateScreen(); + static bool hasChangedTermSize(); + static bool hasShadowCharacter(); + static bool hasHalfBlockCharacter(); + static bool hasAlternateScreen(); // Accessors - FOptiMove* getFOptiMove(); + FOptiMove* getFOptiMove(); // Methods - static void initScreenSettings(); - static char* changeAttribute ( charData*& - , charData*& ); - static void changeTermSizeFinished(); - static void exitWithMessage (std::string) + static void initScreenSettings(); + static char* changeAttribute ( charData*& + , charData*& ); + static void changeTermSizeFinished(); + static void exitWithMessage (const FString&) #if defined(__clang__) || defined(__GNUC__) __attribute__((noreturn)) #endif - ; + ; // Data Members static struct initializationValues { @@ -374,107 +365,72 @@ class FTerm } init_values; private: - // Typedefs - typedef FTermcap::tcap_map termcap_map; - // Disable copy constructor FTerm (const FTerm&); // Disable assignment operator (=) FTerm& operator = (const FTerm&); // Methods - static void init_global_values(); - static void oscPrefix(); - static void oscPostfix(); - static void init_alt_charset(); - static void init_pc_charset(); - static void init_cygwin_charmap(); - static void init_teraterm_charmap(); - static void init_fixed_max_color(); - static void init_keyboard(); - static void init_termcap(); - static void init_termcap_error (int); - static void init_termcap_variables(char*&); - static void init_termcap_booleans(); - static void init_termcap_numerics(); - static void init_termcap_strings (char*&); - static void init_termcap_keys (char*&); - static void init_OptiMove(); - static void init_OptiAttr(); - static void init_font(); - static void init_locale(); - static void init_encoding(); - static void init_encoding_set(); - static void init_term_encoding(); - static void init_individual_term_encoding(); - static bool init_force_vt100_encoding(); - static void init_utf8_without_alt_charset(); - static void init_tab_quirks(); - static void init_captureFontAndTitle(); - static void redefineColorPalette(); - static void restoreColorPalette(); - static void setInsertCursorStyle(); - static void setOverwriteCursorStyle(); - static void enableMouse(); - static void disableMouse(); - static void useAlternateScreenBuffer(); - static void useNormalScreenBuffer(); - void allocationValues(); - void deallocationValues(); - void init(); - void initOSspecifics(); - void finish(); - void finishOSspecifics1(); - void finish_encoding(); - static uInt cp437_to_unicode (uChar); - static void setSignalHandler(); - static void resetSignalHandler(); - static void signal_handler (int); + static void init_global_values (bool); + static void init_terminal_device_path(); + static void oscPrefix(); + static void oscPostfix(); + static void init_alt_charset(); + static void init_pc_charset(); + static void init_cygwin_charmap(); + static void init_teraterm_charmap(); + static void init_fixed_max_color(); + static void init_keyboard(); + static void init_termcap(); + static void init_termcap_error (int); + static void init_termcap_variables(char*&); + static void init_termcap_booleans(); + static void init_termcap_numerics(); + static void init_termcap_strings (char*&); + static void init_termcap_keys_vt100 (char*&); + static void init_termcap_keys (char*&); + static void init_OptiMove(); + static void init_OptiAttr(); + static void init_font(); + static void init_locale(); + static void init_encoding(); + static void init_encoding_set(); + static void init_term_encoding(); + static void init_individual_term_encoding(); + static void init_force_vt100_encoding(); + static void init_utf8_without_alt_charset(); + static void init_tab_quirks(); + static void init_captureFontAndTitle(); + static void redefineColorPalette(); + static void restoreColorPalette(); + static void setInsertCursorStyle(); + static void setOverwriteCursorStyle(); + static void enableMouse(); + static void disableMouse(); + static void useAlternateScreenBuffer(); + static void useNormalScreenBuffer(); + void allocationValues(); + void deallocationValues(); + void init (bool); + void initOSspecifics(); + void initTermspecifics(); + void finish(); + void finishOSspecifics1(); + void finish_encoding(); + static uInt cp437_to_unicode (uChar); + static void setSignalHandler(); + static void resetSignalHandler(); + static void signal_handler (int); // Data Members - static std::map * vt100_alt_char; - static std::map * encoding_set; + static FTermData* data; static FTermcap::tcap_map* tcap; - static fc::encoding term_encoding; - - static bool shadow_character; - static bool half_block_character; - static bool cursor_optimisation; - static bool hidden_cursor; - static bool use_alternate_screen; - static bool pc_charset_console; - static bool utf8_state; - static bool utf8_console; - static bool utf8_linux_terminal; - static bool force_vt100; - static bool vt100_console; - static bool ascii_console; - static bool NewFont; - static bool VGAFont; - static bool monochron; - static char termtype[256]; - static char termfilename[256]; - static char exit_message[8192]; - static char* locale_name; - static char* locale_xterm; - static FRect* term; // current terminal geometry - - static int fd_tty; - static uInt baudrate; - static bool resize_term; - - static fc::linuxConsoleCursorStyle \ - linux_console_cursor_style; - static struct console_font_op \ - screen_font; - static struct unimapdesc \ - screen_unicode_map; - static FOptiMove* opti_move; static FOptiAttr* opti_attr; static FTermDetection* term_detection; static FTermXTerminal* xterm; static FKeyboard* keyboard; + static FMouseControl* mouse; #if defined(__linux__) #undef linux @@ -488,10 +444,6 @@ class FTerm #if defined(__NetBSD__) || defined(__OpenBSD__) static FTermOpenBSD* openbsd; #endif - - static FMouseControl* mouse; - static const FString* save_xterm_font; - static const FString* save_xterm_title; }; #pragma pack(pop) @@ -511,15 +463,15 @@ inline FMouseControl* FTerm::getMouseControl() //---------------------------------------------------------------------- inline int FTerm::getTTYFileDescriptor() -{ return fd_tty; } +{ return data->getTTYFileDescriptor(); } //---------------------------------------------------------------------- inline char* FTerm::getTermType() -{ return termtype; } +{ return data->getTermType(); } //---------------------------------------------------------------------- inline char* FTerm::getTermFileName() -{ return termfilename; } +{ return data->getTermFileName(); } //---------------------------------------------------------------------- inline int FTerm::getTabstop() @@ -552,32 +504,16 @@ inline const char* FTerm::getTermType_SecDA() //---------------------------------------------------------------------- inline int FTerm::getFramebufferBpp() -{ return framebuffer_bpp; } +{ return data->getFramebufferBpp(); } #endif // DEBUG -//---------------------------------------------------------------------- -inline bool FTerm::isCursorHidden() -{ return hidden_cursor; } - -//---------------------------------------------------------------------- -inline bool FTerm::hasPCcharset() -{ return pc_charset_console; } - //---------------------------------------------------------------------- inline bool FTerm::hasUTF8() -{ return utf8_console; } - -//---------------------------------------------------------------------- -inline bool FTerm::hasVT100() -{ return vt100_console; } - -//---------------------------------------------------------------------- -inline bool FTerm::hasASCII() -{ return ascii_console; } +{ return data->hasUTF8Console(); } //---------------------------------------------------------------------- inline bool FTerm::isMonochron() -{ return monochron; } +{ return data->isMonochron(); } //---------------------------------------------------------------------- inline bool FTerm::isXTerminal() @@ -657,11 +593,7 @@ inline bool FTerm::isTmuxTerm() //---------------------------------------------------------------------- inline bool FTerm::isNewFont() -{ return NewFont; } - -//---------------------------------------------------------------------- -inline bool FTerm::isUTF8() -{ return utf8_state; } +{ return data->isNewFont(); } //---------------------------------------------------------------------- inline void FTerm::setInsertCursor() @@ -671,14 +603,6 @@ inline void FTerm::setInsertCursor() inline void FTerm::unsetInsertCursor() { setInsertCursor(false); } -//---------------------------------------------------------------------- -inline bool FTerm::setCursorOptimisation (bool on) -{ return cursor_optimisation = ( on ) ? true : false; } - -//---------------------------------------------------------------------- -inline void FTerm::disableAltScreen() -{ use_alternate_screen = false; } - //---------------------------------------------------------------------- inline bool FTerm::setUTF8() { return setUTF8(true); } @@ -689,19 +613,19 @@ inline bool FTerm::unsetUTF8() //---------------------------------------------------------------------- inline bool FTerm::hasChangedTermSize() -{ return resize_term; } +{ return data->hasTermResized(); } //---------------------------------------------------------------------- inline bool FTerm::hasShadowCharacter() -{ return shadow_character; } +{ return data->hasShadowCharacter(); } //---------------------------------------------------------------------- inline bool FTerm::hasHalfBlockCharacter() -{ return half_block_character; } +{ return data->hasHalfBlockCharacter(); } //---------------------------------------------------------------------- inline bool FTerm::hasAlternateScreen() -{ return use_alternate_screen; } +{ return data->hasAlternateScreen(); } //---------------------------------------------------------------------- inline FOptiMove* FTerm::getFOptiMove() @@ -709,7 +633,7 @@ inline FOptiMove* FTerm::getFOptiMove() //---------------------------------------------------------------------- inline void FTerm::changeTermSizeFinished() -{ resize_term = false; } +{ data->setTermResized(false); } } // namespace finalcut diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index eb619c0d..44140854 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2016-2017 Markus Gans * +* Copyright 2016-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -61,12 +61,10 @@ class FTermcap tcap_map; // Constructors - FTermcap() - { } + FTermcap(); // Destructor - ~FTermcap() - { } + ~FTermcap(); // Accessors const char* getClassName() const; @@ -76,12 +74,6 @@ class FTermcap return tcap; } - // Mutator - static void setTermcapMap (tcap_map* t) - { - tcap = t; - } - // Data Members static bool background_color_erase; static bool automatic_left_margin; @@ -95,16 +87,17 @@ class FTermcap static int attr_without_color; private: - // Data Members - static tcap_map* tcap; + // Data Member + static tcap_map tcap[]; }; #pragma pack(pop) -// FOptiMove inline functions +// FTermcap inline functions //---------------------------------------------------------------------- inline const char* FTermcap::getClassName() const { return "FTermcap"; } } // namespace finalcut + #endif // FTERMCAP_H diff --git a/src/include/final/ftermcapquirks.h b/src/include/final/ftermcapquirks.h index 3ff65dcf..01cc64b4 100644 --- a/src/include/final/ftermcapquirks.h +++ b/src/include/final/ftermcapquirks.h @@ -38,6 +38,7 @@ #include "final/fc.h" #include "final/fterm.h" #include "final/ftermcap.h" +#include "final/ftermdata.h" #include "final/ftermdetection.h" namespace finalcut @@ -57,14 +58,13 @@ class FTermcapQuirks FTermcapQuirks(); // Destructor - ~FTermcapQuirks(); + virtual ~FTermcapQuirks(); // Accessor const char* getClassName() const; // Mutator - static void setTerminalType (const char[]); - static void setTermcapMap (FTermcap::tcap_map*); + static void setTermData (FTermData*); static void setFTermDetection (FTermDetection*); // Methods @@ -87,8 +87,8 @@ class FTermcapQuirks static void init_termcap_general_quirks(); // Data Members - static char termtype[256]; static FTermcap::tcap_map* tcap; + static FTermData* fterm_data; static FTermDetection* term_detection; }; #pragma pack(pop) diff --git a/src/include/final/ftermdata.h b/src/include/final/ftermdata.h new file mode 100644 index 00000000..47ef2bf6 --- /dev/null +++ b/src/include/final/ftermdata.h @@ -0,0 +1,397 @@ +/*********************************************************************** +* ftermdata.h - Data class for FTerm * +* * +* This file is part of the Final Cut widget toolkit * +* * +* Copyright 2018 Markus Gans * +* * +* The Final Cut is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Lesser General Public License * +* as published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* The Final Cut is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +/* Standalone class + * ════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FTermData ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +#ifndef FTERMDATA_H +#define FTERMDATA_H + +#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) + #error "Only can be included directly." +#endif + +#include + +#include "final/fc.h" +#include "final/frect.h" +#include "final/fstring.h" +#include "final/ftypes.h" + +namespace finalcut +{ + +//---------------------------------------------------------------------- +// class FTermData +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FTermData +{ + public: + // Typedefs + typedef std::map encodingMap; + + // Constructors + FTermData(); + + // Destructor + ~FTermData(); + + // Accessors + const char* getClassName() const; + encodingMap& getEncodingList(); + fc::encoding getTermEncoding() const; + FRect& getTermGeometry(); + int getTTYFileDescriptor() const; + uInt getBaudrate() const; + char* getTermType(); + char* getTermFileName(); + const FString& getXtermFont() const; + const FString& getXtermTitle() const; +#if DEBUG + int getFramebufferBpp() const; +#endif + + // Inquiries + bool hasShadowCharacter() const; + bool hasHalfBlockCharacter() const; + bool hasCursorOptimisation() const; + bool isCursorHidden() const; + bool hasAlternateScreen() const; + bool hasASCIIConsole() const; + bool hasVT100Console() const; + bool hasUTF8Console() const; + bool isUTF8() const; + bool isNewFont() const; + bool isVGAFont() const; + bool isMonochron() const; + bool hasTermResized() const; + + // Mutators + void setTermEncoding(fc::encoding); + void setTTYFileDescriptor (int); + void setBaudrate (uInt); + void supportShadowCharacter (bool); + void supportHalfBlockCharacter (bool); + void supportCursorOptimisation (bool); + void setCursorHidden (bool); + void useAlternateScreen (bool); + void setASCIIConsole (bool); + void setVT100Console (bool); + void setUTF8Console (bool); + void setUTF8 (bool); + void setNewFont (bool); + void setVGAFont (bool); + void setMonochron (bool); + void setTermResized (bool); + void setTermType (const char[]); + void setTermFileName (const char[]); + void setXtermFont (const FString&); + void setXtermTitle (const FString&); +#if DEBUG + void setFramebufferBpp (int); +#endif + + private: + // Disable copy constructor + FTermData (const FTermData&); + + // Disable assignment operator (=) + FTermData& operator = (const FTermData&); + + // Data Members + encodingMap encoding_list; + fc::encoding term_encoding; + FRect term_geometry; // current terminal geometry + int fd_tty; + uInt baudrate; + bool shadow_character; + bool half_block_character; + bool cursor_optimisation; + bool hidden_cursor; + bool use_alternate_screen; + bool ascii_console; + bool vt100_console; + bool utf8_console; + bool utf8_state; + bool new_font; + bool vga_font; + bool monochron; + bool resize_term; + char termtype[256]; + char termfilename[256]; + FString xterm_font; + FString xterm_title; + +#if DEBUG + int framebuffer_bpp; +#endif +}; +#pragma pack(pop) + +// FTermData inline functions +//---------------------------------------------------------------------- +inline FTermData::FTermData() + : encoding_list() + , term_encoding(fc::UNKNOWN) + , term_geometry() + , fd_tty(-1) // Teletype (tty) file descriptor is still undefined + , baudrate(0) + , shadow_character(true) + , half_block_character(true) + , cursor_optimisation(true) + , hidden_cursor(false) // Global cursor hidden state + , use_alternate_screen(true) + , ascii_console(false) + , vt100_console(false) + , utf8_console(false) + , utf8_state(false) + , new_font(false) + , vga_font(false) + , monochron(false) + , resize_term(false) + , termtype() + , termfilename() + , xterm_font() + , xterm_title() +#if DEBUG + , framebuffer_bpp(-1) +#endif +{ + // Initialize arrays with '\0' + std::fill_n (termtype, sizeof(termtype), '\0'); + std::fill_n (termfilename, sizeof(termfilename), '\0'); +} + +//---------------------------------------------------------------------- +inline FTermData::~FTermData() +{ } + +//---------------------------------------------------------------------- +inline const char* FTermData::getClassName() const +{ return "FTermData"; } + +//---------------------------------------------------------------------- +inline FTermData::encodingMap& FTermData::getEncodingList() +{ return encoding_list; } + +//---------------------------------------------------------------------- +inline fc::encoding FTermData::getTermEncoding() const +{ return term_encoding; } + +//---------------------------------------------------------------------- +inline FRect& FTermData::getTermGeometry() +{ return term_geometry; } + +//---------------------------------------------------------------------- +inline int FTermData::getTTYFileDescriptor() const +{ return fd_tty; } + +//---------------------------------------------------------------------- +inline uInt FTermData::getBaudrate() const +{ return baudrate; } + +//---------------------------------------------------------------------- +inline char* FTermData::getTermType() +{ return termtype; } + +//---------------------------------------------------------------------- +inline char* FTermData::getTermFileName() +{ return termfilename; } + +//---------------------------------------------------------------------- +inline const FString& FTermData::getXtermFont() const +{ return xterm_font; } + +//---------------------------------------------------------------------- +inline const FString& FTermData::getXtermTitle() const +{ return xterm_title; } + +//---------------------------------------------------------------------- +#if DEBUG +inline int FTermData::getFramebufferBpp() const +{ return framebuffer_bpp; } +#endif + +//---------------------------------------------------------------------- +inline bool FTermData::hasShadowCharacter() const +{ return shadow_character; } + +//---------------------------------------------------------------------- +inline bool FTermData::hasHalfBlockCharacter() const +{ return half_block_character; } + +//---------------------------------------------------------------------- +inline bool FTermData::hasCursorOptimisation() const +{ return cursor_optimisation; } + +//---------------------------------------------------------------------- +inline bool FTermData::isCursorHidden() const +{ return hidden_cursor; } + +//---------------------------------------------------------------------- +inline bool FTermData::hasAlternateScreen() const +{ return use_alternate_screen; } + +//---------------------------------------------------------------------- +inline bool FTermData::hasASCIIConsole() const +{ return ascii_console; } + +//---------------------------------------------------------------------- +inline bool FTermData::hasVT100Console() const +{ return vt100_console; } + +//---------------------------------------------------------------------- +inline bool FTermData::hasUTF8Console() const +{ return utf8_console; } + +//---------------------------------------------------------------------- +inline bool FTermData::isUTF8() const +{ return utf8_state; } + +//---------------------------------------------------------------------- +inline bool FTermData::isNewFont() const +{ return new_font; } + +//---------------------------------------------------------------------- +inline bool FTermData::isVGAFont() const +{ return vga_font; } + +//---------------------------------------------------------------------- +inline bool FTermData::isMonochron() const +{ return monochron; } + +//---------------------------------------------------------------------- +inline bool FTermData::hasTermResized() const +{ return resize_term; } + +//---------------------------------------------------------------------- +inline void FTermData::setTermEncoding (fc::encoding enc) +{ term_encoding = enc; } + +//---------------------------------------------------------------------- +inline void FTermData::setTTYFileDescriptor (int fd) +{ fd_tty = fd; } + +//---------------------------------------------------------------------- +inline void FTermData::setBaudrate (uInt baud) +{ baudrate = baud; } + +//---------------------------------------------------------------------- +inline void FTermData::supportShadowCharacter (bool available) +{ shadow_character = available; } + +//---------------------------------------------------------------------- +inline void FTermData::supportHalfBlockCharacter (bool available) +{ half_block_character = available; } + +//---------------------------------------------------------------------- +inline void FTermData::supportCursorOptimisation (bool available) +{ cursor_optimisation = available; } + +//---------------------------------------------------------------------- +inline void FTermData::setCursorHidden (bool hidden_state) +{ hidden_cursor = hidden_state; } + +//---------------------------------------------------------------------- +inline void FTermData::useAlternateScreen (bool use) +{ use_alternate_screen = use; } + +//---------------------------------------------------------------------- +inline void FTermData::setASCIIConsole (bool ascii) +{ ascii_console = ascii; } + +//---------------------------------------------------------------------- +inline void FTermData::setVT100Console (bool vt100) +{ vt100_console = vt100; } + +//---------------------------------------------------------------------- +inline void FTermData::setUTF8Console (bool utf8) +{ utf8_console = utf8; } + +//---------------------------------------------------------------------- +inline void FTermData::setUTF8 (bool utf8) +{ utf8_state = utf8; } + +//---------------------------------------------------------------------- +inline void FTermData::setNewFont (bool nfont) +{ new_font = nfont; } + +//---------------------------------------------------------------------- +inline void FTermData::setVGAFont (bool vga) +{ vga_font = vga; } + +//---------------------------------------------------------------------- +inline void FTermData::setMonochron (bool mono) +{ monochron = mono; } + +//---------------------------------------------------------------------- +inline void FTermData::setTermResized (bool resize) +{ resize_term = resize; } + +//---------------------------------------------------------------------- +inline void FTermData::setTermType (const char name[]) +{ + if ( ! name ) + return; + + std::strncpy (termtype, name, sizeof(termtype)); + termtype[sizeof(termtype) - 1] = '\0'; +} + +//---------------------------------------------------------------------- +inline void FTermData::setTermFileName (const char file_name[]) +{ + if ( ! file_name ) + return; + + std::strncpy (termfilename, file_name, sizeof(termfilename)); + termfilename[sizeof(termfilename) - 1] = '\0'; +} + +//---------------------------------------------------------------------- +inline void FTermData::setXtermFont (const FString& font) +{ xterm_font = font; } + +//---------------------------------------------------------------------- +inline void FTermData::setXtermTitle (const FString& title) +{ xterm_title = title; } + +//---------------------------------------------------------------------- +#if DEBUG +inline void FTermData::setFramebufferBpp (int bpp) +{ framebuffer_bpp = bpp; } +#endif + +} // namespace finalcut + +#endif // FTERMDATA_H + + diff --git a/src/include/final/ftermdetection.h b/src/include/final/ftermdetection.h index 57069b6f..6c2e57db 100644 --- a/src/include/final/ftermdetection.h +++ b/src/include/final/ftermdetection.h @@ -43,6 +43,7 @@ #include "final/fc.h" #include "final/fconfig.h" +#include "final/ftermdata.h" #include "final/ftermios.h" #include "final/ftypes.h" @@ -91,12 +92,11 @@ class FTermDetection FTermDetection(); // Destructor - ~FTermDetection(); + virtual ~FTermDetection(); // Accessor const char* getClassName() const; static char* getTermType(); - static char* getTermFileName(); static int getGnomeTerminalID(); terminalType& getTermTypeStruct(); @@ -153,7 +153,7 @@ class FTermDetection static void setScreenTerm (bool); static void setTmuxTerm (bool); static void setTerminalDetection (bool); - static void setTermFileName (char[]); + static void setTermData (FTermData*); static void setTtyTypeFileName (char[]); // Methods @@ -199,7 +199,6 @@ class FTermDetection // Data Members static char termtype[256]; - static char termfilename[256]; static char ttytypename[256]; static bool decscusr_support; static bool terminal_detection; @@ -207,6 +206,7 @@ class FTermDetection static int gnome_terminal_id; static const FString* answer_back; static const FString* sec_da; + static FTermData* fterm_data; static terminalType terminal_type; static struct colorEnv @@ -256,10 +256,6 @@ inline const char* FTermDetection::getClassName() const inline char* FTermDetection::getTermType() { return termtype; } -//---------------------------------------------------------------------- -inline char* FTermDetection::getTermFileName() -{ return termfilename; } - //---------------------------------------------------------------------- inline int FTermDetection::getGnomeTerminalID() { return gnome_terminal_id; } diff --git a/src/include/final/ftermfreebsd.h b/src/include/final/ftermfreebsd.h index 79fca3b8..9592571d 100644 --- a/src/include/final/ftermfreebsd.h +++ b/src/include/final/ftermfreebsd.h @@ -66,7 +66,7 @@ class FTermFreeBSD FTermFreeBSD(); // Destructor - ~FTermFreeBSD(); + virtual ~FTermFreeBSD(); // Accessors const char* getClassName() const; diff --git a/src/include/final/ftermios.h b/src/include/final/ftermios.h index 5b532264..2e49448e 100644 --- a/src/include/final/ftermios.h +++ b/src/include/final/ftermios.h @@ -57,7 +57,7 @@ class FTermios FTermios(); // Destructor - ~FTermios(); + virtual ~FTermios(); // Accessors const char* getClassName() const; diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index 8e6f1e64..9378243e 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -73,7 +73,7 @@ class FTermLinux FTermLinux(); // Destructor - ~FTermLinux(); + virtual ~FTermLinux(); // Accessors const char* getClassName() const; @@ -169,8 +169,8 @@ class FTermLinux // Data Members #if defined(__linux__) - static bool VGAFont; - static bool NewFont; + static bool vga_font; + static bool new_font; static bool shadow_character; static bool half_block_character; static bool has_saved_palette; @@ -210,11 +210,11 @@ inline bool FTermLinux::hasHalfBlockCharacter() //---------------------------------------------------------------------- inline bool FTermLinux::isVGAFontUsed() -{ return VGAFont; } +{ return vga_font; } //---------------------------------------------------------------------- inline bool FTermLinux::isNewFontUsed() -{ return NewFont; } +{ return new_font; } #endif // defined(__linux__) } // namespace finalcut diff --git a/src/include/final/ftermopenbsd.h b/src/include/final/ftermopenbsd.h index 4f0aaa36..4125821d 100644 --- a/src/include/final/ftermopenbsd.h +++ b/src/include/final/ftermopenbsd.h @@ -59,7 +59,7 @@ class FTermOpenBSD FTermOpenBSD(); // Destructor - ~FTermOpenBSD(); + virtual ~FTermOpenBSD(); // Accessor const char* getClassName() const; diff --git a/src/include/final/ftermxterminal.h b/src/include/final/ftermxterminal.h index a6215014..b8ed1e7c 100644 --- a/src/include/final/ftermxterminal.h +++ b/src/include/final/ftermxterminal.h @@ -57,15 +57,15 @@ class FTermXTerminal FTermXTerminal(); // Destructor - ~FTermXTerminal(); + virtual ~FTermXTerminal(); // Mutators - static void setTermcapMap (FTermcap::tcap_map*); static void setFTermDetection (FTermDetection*); static void redefineDefaultColors (bool); static void setCursorStyle (fc::xtermCursorStyle); static void setFont (const FString&); static void setTitle (const FString&); + static void setTermSize (int, int); static void setForeground (const FString&); static void setBackground (const FString&); static void setCursorColor (const FString&); @@ -110,6 +110,7 @@ class FTermXTerminal static void setXTermCursorStyle(); static void setXTermFont(); static void setXTermTitle(); + static void setXTermSize(); static void setXTermForeground(); static void setXTermBackground(); static void setXTermCursorColor(); @@ -135,9 +136,11 @@ class FTermXTerminal static void disableXTermMetaSendsESC(); // Data Members - static FTermcap::tcap_map* tcap; - static FTermDetection* term_detection; - static fc::xtermCursorStyle cursor_style; + static bool mouse_support; + static bool meta_sends_esc; + static bool xterm_default_colors; + static int term_width; + static int term_height; static const FString* xterm_font; static const FString* xterm_title; static const FString* foreground_color; @@ -146,9 +149,9 @@ class FTermXTerminal static const FString* mouse_foreground_color; static const FString* mouse_background_color; static const FString* highlight_background_color; - static bool mouse_support; - static bool meta_sends_esc; - static bool xterm_default_colors; + static FTermcap::tcap_map* tcap; + static FTermDetection* term_detection; + static fc::xtermCursorStyle cursor_style; }; #pragma pack(pop) @@ -157,10 +160,6 @@ class FTermXTerminal inline const char* FTermXTerminal::getClassName() const { return "FTermXTerminal"; } -//---------------------------------------------------------------------- -inline void FTermXTerminal::setTermcapMap (FTermcap::tcap_map* tc) -{ tcap = tc; } - //---------------------------------------------------------------------- inline void FTermXTerminal::setFTermDetection (FTermDetection* td) { term_detection = td; } diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index bd160c63..6e04ff2e 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -80,7 +80,7 @@ class FTextView : public FWidget explicit FTextView (FWidget* = 0); // Destructor - ~FTextView(); + virtual ~FTextView(); // Accessors const char* getClassName() const; @@ -90,7 +90,7 @@ class FTextView : public FWidget const FStringList& getLines() const; // Mutators - void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, int, int, bool = true); void setText (const FString&); void scrollToX (int); void scrollToY (int); @@ -99,7 +99,7 @@ class FTextView : public FWidget void scrollBy (int, int); // Methods - void hide(); + virtual void hide(); void append (const FString&); void insert (const FString&, int); void replaceRange (const FString&, int, int); @@ -108,17 +108,17 @@ class FTextView : public FWidget void clear(); // Event handlers - void onKeyPress (FKeyEvent*); - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onMouseMove (FMouseEvent*); - void onWheel (FWheelEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); + virtual void onKeyPress (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onWheel (FWheelEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); protected: // Method - void adjustSize(); + virtual void adjustSize(); private: // Disable copy constructor @@ -133,7 +133,7 @@ class FTextView : public FWidget // Methods void init(); - void draw(); + virtual void draw(); void drawText(); void processChanged(); void drawHBar(); diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 7ad6b54f..0beceeb5 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -85,17 +85,17 @@ class FToggleButton : public FWidget FString& getText(); // Mutators - void setGeometry (int, int, int, int, bool = true); + virtual void setGeometry (int, int, int, int, bool = true); bool setNoUnderline (bool); bool setNoUnderline(); bool unsetNoUnderline(); - bool setEnable (bool); - bool setEnable(); - bool unsetEnable(); - bool setDisable(); - bool setFocus (bool); - bool setFocus(); - bool unsetFocus(); + virtual bool setEnable (bool); + virtual bool setEnable(); + virtual bool unsetEnable(); + virtual bool setDisable(); + virtual bool setFocus (bool); + virtual bool setFocus(); + virtual bool unsetFocus(); bool setChecked (bool); bool setChecked(); bool unsetChecked(); @@ -105,15 +105,15 @@ class FToggleButton : public FWidget bool isChecked(); // Methods - void hide(); + virtual void hide(); // Event handlers - void onMouseDown (FMouseEvent*); - void onMouseUp (FMouseEvent*); - void onWheel (FWheelEvent*); - void onAccel (FAccelEvent*); - void onFocusIn (FFocusEvent*); - void onFocusOut (FFocusEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onWheel (FWheelEvent*); + virtual void onAccel (FAccelEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); protected: // Accessor @@ -153,7 +153,6 @@ class FToggleButton : public FWidget void setGroup (FButtonGroup*); // Methods - void init (const FString&); void init(); int getHotkeyPos (wchar_t[], wchar_t[], uInt); void drawText (wchar_t[], int, uInt); diff --git a/src/include/final/ftooltip.h b/src/include/final/ftooltip.h index 405dba37..b3987731 100644 --- a/src/include/final/ftooltip.h +++ b/src/include/final/ftooltip.h @@ -90,11 +90,11 @@ class FToolTip : public FWindow // Methods virtual void draw(); - void show(); - void hide(); + virtual void show(); + virtual void hide(); // Event handler - void onMouseDown (FMouseEvent*); + virtual void onMouseDown (FMouseEvent*); private: // Disable copy constructor diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index 4fe61e88..976339ce 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -116,7 +116,7 @@ class FVTerm : public FTerm explicit FVTerm (bool, bool = false); // Destructor - ~FVTerm(); + virtual ~FVTerm(); // Overloaded operators template FVTerm& operator << (const type&); @@ -440,7 +440,7 @@ class FVTerm : public FTerm static charData s_ch; // shadow character static charData i_ch; // inherit background character static FPoint* term_pos; // terminal cursor position - static termcap_map* tcap; + static FTermcap::tcap_map* tcap; static FKeyboard* keyboard; static bool terminal_update_complete; static bool terminal_update_pending; diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 545f8e7c..73838541 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -146,7 +146,7 @@ class FWidget : public FVTerm, public FObject explicit FWidget (FWidget* = 0, bool = false); // Destructor - ~FWidget(); + virtual ~FWidget(); // Accessors const char* getClassName() const; @@ -349,7 +349,7 @@ class FWidget : public FVTerm, public FObject virtual bool focusPrevChild(); // ...focus // Event handlers - bool event (FEvent*); + virtual bool event (FEvent*); virtual void onKeyPress (FKeyEvent*); virtual void onKeyUp (FKeyEvent*); virtual void onKeyDown (FKeyEvent*); @@ -860,7 +860,7 @@ inline FPoint FWidget::termToWidgetPos (const FPoint& tPos) //---------------------------------------------------------------------- inline void FWidget::move (const FPoint& pos) -{ move( pos.getX(), pos.getY() ); } +{ move(pos.getX(), pos.getY()); } //---------------------------------------------------------------------- inline void FWidget::drawBorder() diff --git a/src/include/final/fwindow.h b/src/include/final/fwindow.h index f1b55cee..0125cfe7 100644 --- a/src/include/final/fwindow.h +++ b/src/include/final/fwindow.h @@ -85,7 +85,7 @@ class FWindow : public FWidget explicit FWindow (FWidget* = 0); // Destructor - ~FWindow (); + virtual ~FWindow (); // Accessors const char* getClassName() const; @@ -157,7 +157,7 @@ class FWindow : public FWidget virtual void adjustSize(); // Event handlers - bool event (FEvent*); + virtual bool event (FEvent*); virtual void onWindowActive (FEvent*); virtual void onWindowInactive (FEvent*); virtual void onWindowRaised (FEvent*); diff --git a/test/Makefile.am b/test/Makefile.am index 1ad0e9d3..7908c851 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -10,6 +10,7 @@ noinst_PROGRAMS = \ fobject_test \ fmouse_test \ fkeyboard_test \ + ftermdata_test \ ftermdetection_test \ ftermcapquirks_test \ foptimove_test \ @@ -21,6 +22,7 @@ noinst_PROGRAMS = \ fobject_test_SOURCES = fobject-test.cpp fmouse_test_SOURCES = fmouse-test.cpp fkeyboard_test_SOURCES = fkeyboard-test.cpp +ftermdata_test_SOURCES = ftermdata-test.cpp ftermdetection_test_SOURCES = ftermdetection-test.cpp ftermcapquirks_test_SOURCES = ftermcapquirks-test.cpp foptimove_test_SOURCES = foptimove-test.cpp @@ -32,6 +34,7 @@ frect_test_SOURCES = frect-test.cpp TESTS = fobject_test \ fmouse_test \ fkeyboard_test \ + ftermdata_test \ ftermdetection_test \ ftermcapquirks_test \ foptimove_test \ 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 d2f86991..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 * * * @@ -199,6 +199,8 @@ void FMouseTest::noArgumentTest() //---------------------------------------------------------------------- void FMouseTest::doubleClickTest() { + using finalcut::operator -; + FMouse_protected mouse; CPPUNIT_ASSERT ( mouse.getDblclickInterval() == 500000 ); // 500 ms timeval tv = { 0, 0 }; diff --git a/test/fobject-test.cpp b/test/fobject-test.cpp index 151fc35d..c7543b71 100644 --- a/test/fobject-test.cpp +++ b/test/fobject-test.cpp @@ -41,15 +41,34 @@ class FObject_protected : public finalcut::FObject { public: + FObject_protected() + : count(0) + { } + bool event (finalcut::FEvent* ev) { return finalcut::FObject::event(ev); } - finalcut::FObject::TimerList* getTimerList() const + TimerList* getTimerList() const { - return timer_list; + return finalcut::FObject::getTimerList(); } + + uInt processEvent() + { + return processTimerEvent(); + } + + virtual void performTimerAction (const FObject*, const finalcut::FEvent*) + { + std::cout << "."; + fflush(stdout); + count++; + } + + // Data Member + uInt count; }; #pragma pack(pop) @@ -77,6 +96,7 @@ class FObjectTest : public CPPUNIT_NS::TestFixture void iteratorTest(); void timeTest(); void timerTest(); + void performTimerActionTest(); private: // Adds code needed to register the test suite @@ -92,6 +112,7 @@ class FObjectTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST (iteratorTest); CPPUNIT_TEST (timeTest); CPPUNIT_TEST (timerTest); + CPPUNIT_TEST (performTimerActionTest); // End of test suite definition CPPUNIT_TEST_SUITE_END(); @@ -116,7 +137,7 @@ void FObjectTest::noArgumentTest() CPPUNIT_ASSERT ( o1.getChild(0) == 0 ); CPPUNIT_ASSERT ( o1.getChild(1) == 0 ); CPPUNIT_ASSERT ( o1.numOfChildren() == 0 ); - const finalcut::FObject::FObjectList& children_list = o1.getChildren(); + finalcut::FObject::FObjectList& children_list = o1.getChildren(); CPPUNIT_ASSERT ( children_list.begin() == o1.begin() ); CPPUNIT_ASSERT ( children_list.begin() == o1.end() ); CPPUNIT_ASSERT ( children_list.end() == o1.begin() ); @@ -258,6 +279,7 @@ void FObjectTest::delTest() */ finalcut::FObject* obj = new finalcut::FObject(); finalcut::FObject* child = new finalcut::FObject(obj); + CPPUNIT_ASSERT ( obj->hasChildren() ); CPPUNIT_ASSERT ( obj->numOfChildren() == 1 ); CPPUNIT_ASSERT ( obj->isChild(child) ); @@ -333,11 +355,19 @@ void FObjectTest::timeTest() CPPUNIT_ASSERT ( ! finalcut::FObject::isTimeout (&time1, timeout) ); sleep(1); CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (&time1, timeout) ); + time1.tv_sec = 300; + time1.tv_usec = 2000000; // > 1000000 µs to test diff underflow + CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (&time1, timeout) ); } //---------------------------------------------------------------------- void FObjectTest::timerTest() { + using finalcut::operator +; + using finalcut::operator -; + using finalcut::operator +=; + using finalcut::operator <; + FObject_protected t1; FObject_protected t2; int id1, id2; @@ -436,6 +466,27 @@ void FObjectTest::timerTest() CPPUNIT_ASSERT ( ! t1.delTimer(-1) ); } +//---------------------------------------------------------------------- +void FObjectTest::performTimerActionTest() +{ + FObject_protected t; + uInt num_events = 0; + uInt loop = 0; + t.addTimer(100); + + while ( loop < 10 ) + { + num_events += t.processEvent(); + // Wait 100 ms + nanosleep ((const struct timespec[]){{0, 100000000L}}, NULL); + loop++; + } + + CPPUNIT_ASSERT ( loop == 10 ); + CPPUNIT_ASSERT ( num_events == 9 ); + CPPUNIT_ASSERT ( t.count == 9 ); +} + // Put the test suite in the registry CPPUNIT_TEST_SUITE_REGISTRATION (FObjectTest); 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 f805f9af..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 * * * @@ -149,7 +149,7 @@ static tcap_map tcap[] = { 0, "\0" } }; -} // namespace test +} // namespace test //---------------------------------------------------------------------- @@ -227,17 +227,18 @@ void FTermcapQuirksTest::classNameTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::generalTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcap::tabstop = -1; finalcut::FTermcap::attr_without_color = -1; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; - quirks.setTermcapMap (reinterpret_cast(caps)); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -286,23 +287,23 @@ void FTermcapQuirksTest::generalTest() , C_STR(CSI "29m") ); CPPUNIT_ASSERT_CSTRING ( printSequence(caps[finalcut::fc::t_enter_ca_mode].string).c_str() , C_STR("Esc 7 Esc [ ? 4 7 h ") ); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::xtermTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setXTerminal (true); - quirks.setTerminalType ("xterm"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("xterm"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -316,25 +317,25 @@ void FTermcapQuirksTest::xtermTest() CPPUNIT_ASSERT_CSTRING ( caps[finalcut::fc::t_cursor_normal].string , C_STR(CSI "?12l" CSI "?25h") ); detect.setXTerminal (false); - delete[] caps; } #if defined(__FreeBSD__) || defined(__DragonFly__) //---------------------------------------------------------------------- void FTermcapQuirksTest::freebsdTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcap::attr_without_color = -1; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setFreeBSDTerm (true); - quirks.setTerminalType ("xterm-16color"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("xterm-16color"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -355,25 +356,25 @@ void FTermcapQuirksTest::freebsdTest() "%?%p4%t;5%;m" "%?%p9%t\016%e\017%;") ); detect.setFreeBSDTerm (false); - delete[] caps; } #endif //---------------------------------------------------------------------- void FTermcapQuirksTest::cygwinTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcap::background_color_erase = false; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setCygwinTerminal (true); - quirks.setTerminalType ("cygwin"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("cygwin"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -383,25 +384,25 @@ void FTermcapQuirksTest::cygwinTest() CPPUNIT_ASSERT_CSTRING ( caps[finalcut::fc::t_cursor_visible].string , C_STR(CSI "?25h") ); detect.setCygwinTerminal (false); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::linuxTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcap::max_color = 8; finalcut::FTermcap::attr_without_color = -1; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setLinuxTerm (true); - quirks.setTerminalType ("linux"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("linux"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -457,23 +458,23 @@ void FTermcapQuirksTest::linuxTest() CPPUNIT_ASSERT_CSTRING ( caps[finalcut::fc::t_exit_underline_mode].string , 0 ); detect.setLinuxTerm (false); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::rxvtTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setRxvtTerminal (true); - quirks.setTerminalType ("rxvt"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("rxvt"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -483,7 +484,7 @@ void FTermcapQuirksTest::rxvtTest() CPPUNIT_ASSERT_CSTRING ( caps[finalcut::fc::t_exit_alt_charset_mode].string , 0 ); // rxvt-16color - quirks.setTerminalType ("rxvt-16color"); + data.setTermType ("rxvt-16color"); quirks.terminalFixup(); CPPUNIT_ASSERT_CSTRING ( caps[finalcut::fc::t_enter_alt_charset_mode].string , C_STR(ESC "(0") ); @@ -500,24 +501,24 @@ void FTermcapQuirksTest::rxvtTest() detect.setUrxvtTerminal (false); detect.setRxvtTerminal (false); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::vteTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcap::attr_without_color = -1; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setGnomeTerminal (true); - quirks.setTerminalType ("gnome-256color"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("gnome-256color"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -526,26 +527,26 @@ void FTermcapQuirksTest::vteTest() , C_STR(CSI "24m") ); detect.setGnomeTerminal (false); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::puttyTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcap::background_color_erase = false; finalcut::FTermcap::osc_support = false; finalcut::FTermcap::attr_without_color = -1; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setPuttyTerminal (true); - quirks.setTerminalType ("putty"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("putty"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -611,24 +612,24 @@ void FTermcapQuirksTest::puttyTest() , C_STR(CSI "M") ); detect.setPuttyTerminal (false); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::teratermTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcap::eat_nl_glitch = false; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setTeraTerm (true); - quirks.setTerminalType ("teraterm"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("teraterm"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -643,47 +644,41 @@ void FTermcapQuirksTest::teratermTest() , C_STR(CSI "39;49m") ); detect.setTeraTerm (false); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::sunTest() { - const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; - - for (int i = 0; i < last_item; i++) - memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); - + finalcut::FTermData data; finalcut::FTermcap::eat_nl_glitch = false; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setSunTerminal (true); - quirks.setTerminalType ("sun-color"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("sun-color"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); CPPUNIT_ASSERT ( finalcut::FTermcap::eat_nl_glitch == true ); detect.setSunTerminal (false); - delete[] caps; } //---------------------------------------------------------------------- void FTermcapQuirksTest::screenTest() { + finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::getTermcapMap(); const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; - test::tcap_map* caps = new test::tcap_map[last_item]; for (int i = 0; i < last_item; i++) memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0])); + finalcut::FTermData data; finalcut::FTermcapQuirks quirks; finalcut::FTermDetection detect; detect.setScreenTerm (true); - quirks.setTerminalType ("screen-256color"); - quirks.setTermcapMap (reinterpret_cast(caps)); + data.setTermType ("screen-256color"); + quirks.setTermData(&data); quirks.setFTermDetection (&detect); quirks.terminalFixup(); @@ -704,7 +699,6 @@ void FTermcapQuirksTest::screenTest() "%p4%{255}%*%{1000}%/%2.2X" BEL ESC "\\") ); detect.setTmuxTerm (false); detect.setScreenTerm (false); - delete[] caps; } diff --git a/test/ftermdata-test.cpp b/test/ftermdata-test.cpp new file mode 100644 index 00000000..1e95936f --- /dev/null +++ b/test/ftermdata-test.cpp @@ -0,0 +1,250 @@ +/*********************************************************************** +* ftermdata-test.cpp - FTermData unit tests * +* * +* This file is part of the Final Cut widget toolkit * +* * +* Copyright 2018 Markus Gans * +* * +* The Final Cut is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Lesser General Public License * +* as published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* The Final Cut is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define CPPUNIT_ASSERT_CSTRING(expected, actual) \ + check_c_string (expected, actual, CPPUNIT_SOURCELINE()) + +//---------------------------------------------------------------------- +void check_c_string ( const char* s1 + , const char* s2 + , CppUnit::SourceLine sourceLine ) +{ + if ( s1 == 0 && s2 == 0 ) // Strings are equal + return; + + if ( s1 && s2 && std::strcmp (s1, s2) == 0 ) // Strings are equal + return; + + ::CppUnit::Asserter::fail ("Strings are not equal", sourceLine); +} + + +//---------------------------------------------------------------------- +// class FTermDataTest +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FTermDataTest : public CPPUNIT_NS::TestFixture +{ + public: + FTermDataTest() + { } + + protected: + void classNameTest(); + void defaultDataTest(); + void dataTest(); + + private: + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE (FTermDataTest); + + // Add a methods to the test suite + CPPUNIT_TEST (classNameTest); + CPPUNIT_TEST (defaultDataTest); + CPPUNIT_TEST (dataTest); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; +#pragma pack(pop) + +//---------------------------------------------------------------------- +void FTermDataTest::classNameTest() +{ + finalcut::FTermData d; + const char* const classname = d.getClassName(); + CPPUNIT_ASSERT ( std::strcmp(classname, "FTermData") == 0 ); +} + +//---------------------------------------------------------------------- +void FTermDataTest::defaultDataTest() +{ + finalcut::FTermData data; + CPPUNIT_ASSERT ( data.getEncodingList().size() == 0 ); + CPPUNIT_ASSERT ( data.getTermEncoding() == finalcut::fc::UNKNOWN ); + CPPUNIT_ASSERT ( data.getTermGeometry() == finalcut::FRect() ); + CPPUNIT_ASSERT ( data.getTTYFileDescriptor() == -1 ); + CPPUNIT_ASSERT ( data.getBaudrate() == 0 ); + CPPUNIT_ASSERT_CSTRING ( data.getTermType(), C_STR("") ); + CPPUNIT_ASSERT_CSTRING ( data.getTermFileName(), C_STR("") ); + CPPUNIT_ASSERT ( data.getXtermFont() == finalcut::FString() ); + CPPUNIT_ASSERT ( data.getXtermTitle() == finalcut::FString() ); + +#if DEBUG + CPPUNIT_ASSERT ( data.getFramebufferBpp() == -1 ); +#endif + + CPPUNIT_ASSERT ( data.hasShadowCharacter() == true ); + CPPUNIT_ASSERT ( data.hasHalfBlockCharacter() == true ); + CPPUNIT_ASSERT ( data.hasCursorOptimisation() == true ); + CPPUNIT_ASSERT ( data.isCursorHidden() == false ); + CPPUNIT_ASSERT ( data.hasAlternateScreen() == true ); + CPPUNIT_ASSERT ( data.hasASCIIConsole() == false ); + CPPUNIT_ASSERT ( data.hasVT100Console() == false ); + CPPUNIT_ASSERT ( data.hasUTF8Console() == false ); + CPPUNIT_ASSERT ( data.isUTF8() == false ); + CPPUNIT_ASSERT ( data.isNewFont() == false ); + CPPUNIT_ASSERT ( data.isVGAFont() == false ); + CPPUNIT_ASSERT ( data.isMonochron() == false ); + CPPUNIT_ASSERT ( data.hasTermResized() == false ); +} + +//---------------------------------------------------------------------- +void FTermDataTest::dataTest() +{ + finalcut::FTermData data; + + CPPUNIT_ASSERT ( data.getEncodingList().size() == 0 ); + finalcut::FTermData::encodingMap& encoding_list = data.getEncodingList(); + encoding_list["UTF8"] = finalcut::fc::UTF8; + encoding_list["UTF-8"] = finalcut::fc::UTF8; + encoding_list["VT100"] = finalcut::fc::VT100; + encoding_list["PC"] = finalcut::fc::PC; + encoding_list["ASCII"] = finalcut::fc::ASCII; + finalcut::FTermData::encodingMap& enc_list = data.getEncodingList(); + CPPUNIT_ASSERT ( enc_list.size() == 5 ); + CPPUNIT_ASSERT ( enc_list["UTF8"] == finalcut::fc::UTF8 ); + CPPUNIT_ASSERT ( enc_list["UTF-8"] == finalcut::fc::UTF8 ); + CPPUNIT_ASSERT ( enc_list["VT100"] == finalcut::fc::VT100 ); + CPPUNIT_ASSERT ( enc_list["PC"] == finalcut::fc::PC ); + CPPUNIT_ASSERT ( enc_list["ASCII"] == finalcut::fc::ASCII ); + + CPPUNIT_ASSERT ( data.getTermEncoding() == finalcut::fc::UNKNOWN ); + data.setTermEncoding(finalcut::fc::UTF8); + CPPUNIT_ASSERT ( data.getTermEncoding() == finalcut::fc::UTF8 ); + data.setTermEncoding(finalcut::fc::VT100); + CPPUNIT_ASSERT ( data.getTermEncoding() == finalcut::fc::VT100 ); + data.setTermEncoding(finalcut::fc::PC); + CPPUNIT_ASSERT ( data.getTermEncoding() == finalcut::fc::PC ); + data.setTermEncoding(finalcut::fc::ASCII); + CPPUNIT_ASSERT ( data.getTermEncoding() == finalcut::fc::ASCII ); + data.setTermEncoding(finalcut::fc::UNKNOWN); + CPPUNIT_ASSERT ( data.getTermEncoding() == finalcut::fc::UNKNOWN ); + + CPPUNIT_ASSERT ( data.getTermGeometry() == finalcut::FRect() ); + data.getTermGeometry().setSize(10, 10); + data.getTermGeometry().setPos(3, 5); + CPPUNIT_ASSERT ( data.getTermGeometry() == finalcut::FRect(3, 5, 10, 10) ); + + CPPUNIT_ASSERT ( data.getTTYFileDescriptor() == -1 ); + data.setTTYFileDescriptor (1); + CPPUNIT_ASSERT ( data.getTTYFileDescriptor() == 1 ); + CPPUNIT_ASSERT ( data.getBaudrate() == 0 ); + data.setBaudrate(38400); + CPPUNIT_ASSERT ( data.getBaudrate() != 9600 ); + CPPUNIT_ASSERT ( data.getBaudrate() == 38400 ); + + CPPUNIT_ASSERT_CSTRING ( data.getTermType(), C_STR("") ); + data.setTermType("linux"); + CPPUNIT_ASSERT_CSTRING ( data.getTermType(), C_STR("linux") ); + + CPPUNIT_ASSERT_CSTRING ( data.getTermFileName(), C_STR("") ); + data.setTermFileName("/dev/pts/2"); + CPPUNIT_ASSERT_CSTRING ( data.getTermFileName(), C_STR("/dev/pts/2") ); + + CPPUNIT_ASSERT ( data.getXtermFont() == finalcut::FString() ); + data.setXtermFont("terminus-20"); + CPPUNIT_ASSERT ( data.getXtermFont() == finalcut::FString("terminus-20") ); + + CPPUNIT_ASSERT ( data.getXtermTitle() == finalcut::FString() ); + data.setXtermTitle("Terminal"); + CPPUNIT_ASSERT ( data.getXtermTitle() == finalcut::FString("Terminal") ); + +#if DEBUG + CPPUNIT_ASSERT ( data.getFramebufferBpp() == -1 ); + data.setFramebufferBpp(32); + CPPUNIT_ASSERT ( data.getFramebufferBpp() == 32 ); +#endif + + CPPUNIT_ASSERT ( data.hasShadowCharacter() == true ); + data.supportShadowCharacter (false); + CPPUNIT_ASSERT ( data.hasShadowCharacter() == false ); + + CPPUNIT_ASSERT ( data.hasHalfBlockCharacter() == true ); + data.supportHalfBlockCharacter (false); + CPPUNIT_ASSERT ( data.hasHalfBlockCharacter() == false ); + + CPPUNIT_ASSERT ( data.hasCursorOptimisation() == true ); + data.supportCursorOptimisation (false); + CPPUNIT_ASSERT ( data.hasCursorOptimisation() == false ); + + CPPUNIT_ASSERT ( data.isCursorHidden() == false ); + data.setCursorHidden (true); + CPPUNIT_ASSERT ( data.isCursorHidden() == true ); + + CPPUNIT_ASSERT ( data.hasAlternateScreen() == true ); + data.useAlternateScreen (false); + CPPUNIT_ASSERT ( data.hasAlternateScreen() == false ); + + CPPUNIT_ASSERT ( data.hasASCIIConsole() == false ); + data.setASCIIConsole (true); + CPPUNIT_ASSERT ( data.hasASCIIConsole() == true ); + + CPPUNIT_ASSERT ( data.hasVT100Console() == false ); + data.setVT100Console (true); + CPPUNIT_ASSERT ( data.hasVT100Console() == true ); + + CPPUNIT_ASSERT ( data.hasUTF8Console() == false ); + data.setUTF8Console (true); + CPPUNIT_ASSERT ( data.hasUTF8Console() == true ); + + CPPUNIT_ASSERT ( data.isUTF8() == false ); + data.setUTF8 (true); + CPPUNIT_ASSERT ( data.isUTF8() == true ); + + CPPUNIT_ASSERT ( data.isNewFont() == false ); + data.setNewFont (true); + CPPUNIT_ASSERT ( data.isNewFont() == true ); + + CPPUNIT_ASSERT ( data.isVGAFont() == false ); + data.setVGAFont (true); + CPPUNIT_ASSERT ( data.isVGAFont() == true ); + + CPPUNIT_ASSERT ( data.isMonochron() == false ); + data.setMonochron (true); + CPPUNIT_ASSERT ( data.isMonochron() == true ); + + CPPUNIT_ASSERT ( data.hasTermResized() == false ); + data.setTermResized (true); + CPPUNIT_ASSERT ( data.hasTermResized() == true ); +} + + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION (FTermDataTest); + +// The general unit test main part +#include + diff --git a/test/ftermdetection-test.cpp b/test/ftermdetection-test.cpp index c29b2e88..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 * * * @@ -442,6 +442,7 @@ FTermDetectionTest::FTermDetectionTest() , fd_master(-1) , fd_slave(-1) , debug(false) + , buffer() { // Map shared memory void* ptr = mmap ( NULL @@ -473,9 +474,11 @@ void FTermDetectionTest::classNameTest() //---------------------------------------------------------------------- void FTermDetectionTest::ansiTest() { - setenv ("TERM", "ansi", 1); + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("ansi")); + setenv ("TERM", "ansi", 1); + data.setTermFileName(C_STR("ansi")); + detect.setTermData(&data); pid_t pid = forkProcess(); @@ -541,8 +544,10 @@ void FTermDetectionTest::ansiTest() //---------------------------------------------------------------------- void FTermDetectionTest::xtermTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("xterm")); + data.setTermFileName(C_STR("xterm")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -601,8 +606,10 @@ void FTermDetectionTest::xtermTest() //---------------------------------------------------------------------- void FTermDetectionTest::rxvtTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("rxvt-cygwin-native")); + data.setTermFileName(C_STR("rxvt-cygwin-native")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -662,8 +669,10 @@ void FTermDetectionTest::rxvtTest() //---------------------------------------------------------------------- void FTermDetectionTest::urxvtTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("rxvt-unicode-256color")); + data.setTermFileName(C_STR("rxvt-unicode-256color")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -723,8 +732,10 @@ void FTermDetectionTest::urxvtTest() //---------------------------------------------------------------------- void FTermDetectionTest::mltermTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("mlterm")); + data.setTermFileName(C_STR("mlterm")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -791,8 +802,10 @@ void FTermDetectionTest::mltermTest() //---------------------------------------------------------------------- void FTermDetectionTest::puttyTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("xterm")); + data.setTermFileName(C_STR("xterm")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -852,8 +865,10 @@ void FTermDetectionTest::puttyTest() //---------------------------------------------------------------------- void FTermDetectionTest::kdeKonsoleTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("xterm-256color")); + data.setTermFileName(C_STR("xterm-256color")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -912,8 +927,10 @@ void FTermDetectionTest::kdeKonsoleTest() //---------------------------------------------------------------------- void FTermDetectionTest::gnomeTerminalTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("xterm-256color")); + data.setTermFileName(C_STR("xterm-256color")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -973,8 +990,10 @@ void FTermDetectionTest::gnomeTerminalTest() //---------------------------------------------------------------------- void FTermDetectionTest::ktermTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("kterm")); + data.setTermFileName(C_STR("kterm")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1041,8 +1060,10 @@ void FTermDetectionTest::ktermTest() //---------------------------------------------------------------------- void FTermDetectionTest::teraTermTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("xterm")); + data.setTermFileName(C_STR("xterm")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1102,8 +1123,10 @@ void FTermDetectionTest::teraTermTest() //---------------------------------------------------------------------- void FTermDetectionTest::cygwinTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("cygwin")); + data.setTermFileName(C_STR("cygwin")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1163,8 +1186,10 @@ void FTermDetectionTest::cygwinTest() //---------------------------------------------------------------------- void FTermDetectionTest::minttyTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("xterm-256color")); + data.setTermFileName(C_STR("xterm-256color")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1224,8 +1249,10 @@ void FTermDetectionTest::minttyTest() //---------------------------------------------------------------------- void FTermDetectionTest::linuxTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("linux")); + data.setTermFileName(C_STR("linux")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1292,8 +1319,10 @@ void FTermDetectionTest::linuxTest() //---------------------------------------------------------------------- void FTermDetectionTest::freebsdTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("xterm")); + data.setTermFileName(C_STR("xterm")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1363,8 +1392,10 @@ void FTermDetectionTest::freebsdTest() //---------------------------------------------------------------------- void FTermDetectionTest::netbsdTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("wsvt25")); + data.setTermFileName(C_STR("wsvt25")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1432,8 +1463,10 @@ void FTermDetectionTest::netbsdTest() //---------------------------------------------------------------------- void FTermDetectionTest::openbsdTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("vt220")); + data.setTermFileName(C_STR("vt220")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1501,8 +1534,10 @@ void FTermDetectionTest::openbsdTest() //---------------------------------------------------------------------- void FTermDetectionTest::sunTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("sun-color")); + data.setTermFileName(C_STR("sun-color")); + detect.setTermData(&data); pid_t pid = forkProcess(); @@ -1568,8 +1603,10 @@ void FTermDetectionTest::sunTest() //---------------------------------------------------------------------- void FTermDetectionTest::screenTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("screen")); + data.setTermFileName(C_STR("screen")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1635,8 +1672,10 @@ void FTermDetectionTest::screenTest() //---------------------------------------------------------------------- void FTermDetectionTest::tmuxTest() { + finalcut::FTermData data; finalcut::FTermDetection detect; - detect.setTermFileName(C_STR("screen")); + data.setTermFileName(C_STR("screen")); + detect.setTermData(&data); detect.setTerminalDetection(true); pid_t pid = forkProcess(); @@ -1738,7 +1777,9 @@ void FTermDetectionTest::ttytypeTest() ttytype << "vt100" << "\t" << "ttyp6" << std::endl; ttytype.close(); + finalcut::FTermData data; finalcut::FTermDetection detect; + detect.setTermData(&data); detect.setTerminalDetection(true); detect.setTtyTypeFileName(C_STR("new-root-dir/etc/ttytype")); @@ -1758,17 +1799,17 @@ void FTermDetectionTest::ttytypeTest() unsetenv("TMUX"); // Test /dev/tty3 with linux - detect.setTermFileName(C_STR("/dev/tty3")); + data.setTermFileName(C_STR("/dev/tty3")); detect.detect(); CPPUNIT_ASSERT_CSTRING ( detect.getTermType(), C_STR("linux") ); // Test /dev/ttyp0 with vt100 - detect.setTermFileName(C_STR("/dev/ttyp0")); + data.setTermFileName(C_STR("/dev/ttyp0")); detect.detect(); CPPUNIT_ASSERT_CSTRING ( detect.getTermType(), C_STR("vt100") ); // Test non-existent /dev/tty8 with fallback to vt100 - detect.setTermFileName(C_STR("/dev/tty8")); + data.setTermFileName(C_STR("/dev/tty8")); detect.detect(); CPPUNIT_ASSERT_CSTRING ( detect.getTermType(), C_STR("vt100") ); @@ -2086,14 +2127,10 @@ pid_t FTermDetectionTest::forkProcess() // Initialize buffer with '\0' std::fill_n (buffer, sizeof(buffer), '\0'); - bool result = openMasterPTY(); - - if ( ! result ) + if ( ! openMasterPTY() ) return -1; - result = openSlavePTY(); - - if ( ! result ) + if ( ! openSlavePTY() ) return -1; pid_t pid = fork(); // Create a child process @@ -2119,7 +2156,11 @@ pid_t FTermDetectionTest::forkProcess() #endif // Get current terminal settings - result = tcgetattr(fd_slave, &term_settings); + if ( tcgetattr(fd_slave, &term_settings) == -1 ) + { + *shared_state = true; + return -1; + } // Set raw mode on the slave side of the PTY cfmakeraw (&term_settings); @@ -2157,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++; }