diff --git a/ChangeLog b/ChangeLog index 18e29da6..6e9981ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-09-19 Markus Gans + * The command line help text is now available in all applications + 2017-09-17 Markus Gans * FObject has received the iterator child access methods begin() and end() diff --git a/examples/calculator.cpp b/examples/calculator.cpp index d03d5278..b2edfedb 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -1014,7 +1014,10 @@ int main (int argc, char* argv[]) // Create a calculator object Calc calculator(&app); + // Set calculator object as main widget app.setMainWidget(&calculator); + + // Show and start the application calculator.show(); return app.exec(); } diff --git a/examples/choice.cpp b/examples/choice.cpp index 37493438..23c5fab7 100644 --- a/examples/choice.cpp +++ b/examples/choice.cpp @@ -32,7 +32,7 @@ int main (int argc, char* argv[]) // Create the application object FApplication app(argc, argv); - // Create a simple dialog box + // Create a simple modal dialog box FDialog* dgl = new FDialog(&app); dgl->setModal(); dgl->setText ("UNIX select"); diff --git a/examples/dialog.cpp b/examples/dialog.cpp index 677d855e..ec783be0 100644 --- a/examples/dialog.cpp +++ b/examples/dialog.cpp @@ -58,7 +58,10 @@ int main (int argc, char* argv[]) &app ); + // Set dialog object as main widget app.setMainWidget(&dgl); + + // Show and start the application dgl.show(); return app.exec(); } diff --git a/examples/hello.cpp b/examples/hello.cpp index 6f3006c4..7af7c4c1 100644 --- a/examples/hello.cpp +++ b/examples/hello.cpp @@ -12,5 +12,7 @@ int main (int argc, char* argv[]) // Create a simple dialog box FMessageBox mbox(&app); mbox.setText("Hello world"); + + // Start the application mbox.exec(); } diff --git a/examples/input-dialog.cpp b/examples/input-dialog.cpp index 603ebb02..65d242ff 100644 --- a/examples/input-dialog.cpp +++ b/examples/input-dialog.cpp @@ -113,7 +113,10 @@ int main (int argc, char* argv[]) &app ); + // Set dialog object as main widget app.setMainWidget(&dgl); + + // Show and start the application dgl.show(); return app.exec(); } diff --git a/examples/keyboard.cpp b/examples/keyboard.cpp index 7c03578e..577fdcd2 100644 --- a/examples/keyboard.cpp +++ b/examples/keyboard.cpp @@ -70,12 +70,19 @@ void keyboard::draw() //---------------------------------------------------------------------- int main (int argc, char* argv[]) { + // Create the application object FApplication app(argc, argv); app.setForegroundColor(fc::Default); app.setBackgroundColor(fc::Default); + + // Create a keyboard object keyboard key(&app); key.addAccelerator('q'); + + // Set the keyboard object as main widget app.setMainWidget(&key); + + // Show and start the application key.show(); return app.exec(); } diff --git a/examples/listbox.cpp b/examples/listbox.cpp index f50107d5..00a747bc 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -169,24 +169,19 @@ void Listbox::cb_exitApp (FWidget*, data_ptr) int main (int argc, char* argv[]) { - if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 - || std::strcmp(argv[1], "-h") == 0 ) ) - { - std::cout << "Generic options:" << std::endl - << " -h, --help " - << "Display this help and exit" << std::endl; - FApplication::print_cmd_Options(); - std::exit(EXIT_SUCCESS); - } - + // Create the application object FApplication app(argc, argv); + // Create main dialog object Listbox d(&app); d.setText (L"Listbox"); d.setGeometry (int(1 + (app.getWidth() - 56) / 2), 5, 56, 16); d.setShadow(); + // Set dialog d as main widget app.setMainWidget(&d); + + // Show and start the application d.show(); return app.exec(); } diff --git a/examples/listview.cpp b/examples/listview.cpp index c8d975bf..d5c0c9cb 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -178,24 +178,19 @@ void Listview::cb_showInMessagebox (FWidget* widget, data_ptr) int main (int argc, char* argv[]) { - if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 - || std::strcmp(argv[1], "-h") == 0 ) ) - { - std::cout << "Generic options:" << std::endl - << " -h, --help " - << "Display this help and exit" << std::endl; - FApplication::print_cmd_Options(); - std::exit(EXIT_SUCCESS); - } - + // Create the application object FApplication app(argc, argv); + // Create main dialog object Listview d(&app); d.setText (L"Weather data"); d.setGeometry (int(1 + (app.getWidth() - 37) / 2), 3, 37, 20); d.setShadow(); + // Set dialog d as main widget app.setMainWidget(&d); + + // Show and start the application d.show(); return app.exec(); } diff --git a/examples/mandelbrot.cpp b/examples/mandelbrot.cpp index e2eb19d0..0120aa76 100644 --- a/examples/mandelbrot.cpp +++ b/examples/mandelbrot.cpp @@ -141,7 +141,10 @@ int main (int argc, char* argv[]) mb.addAccelerator('q'); // press 'q' to quit mb.setShadow(); + // Set the mandelbrot object as main widget app.setMainWidget(&mb); + + // Show and start the application mb.show(); return app.exec(); } diff --git a/examples/menu.cpp b/examples/menu.cpp index b76b74c5..aaf8b3e0 100644 --- a/examples/menu.cpp +++ b/examples/menu.cpp @@ -279,24 +279,19 @@ void Menu::cb_exitApp (FWidget*, data_ptr) int main (int argc, char* argv[]) { - if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 - || std::strcmp(argv[1], "-h") == 0 ) ) - { - std::cout << "Generic options:" << std::endl - << " -h, --help " - << "Display this help and exit" << std::endl; - FApplication::print_cmd_Options(); - std::exit(EXIT_SUCCESS); - } - + // Create the application object FApplication app (argc, argv); + // Create main dialog object Menu main_dlg (&app); main_dlg.setText ("Menu example"); main_dlg.setGeometry (int(1 + (app.getWidth() - 40) / 2), 2, 40, 6); main_dlg.setShadow(); + // Set dialog main_dlg as main widget app.setMainWidget (&main_dlg); + + // Show and start the application main_dlg.show(); return app.exec(); } diff --git a/examples/mouse.cpp b/examples/mouse.cpp index 9f8bf4e6..64dbb413 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -532,7 +532,10 @@ int main (int argc, char* argv[]) mouse_draw.setGeometry (12, 4, 60, 18); mouse_draw.addAccelerator('q'); // press 'q' to quit + // Set dialog object mouse_draw as main widget app.setMainWidget(&mouse_draw); + + // Show and start the application mouse_draw.show(); return app.exec(); } diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index 6c99eabb..ee05e183 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -132,20 +132,28 @@ int main (int argc, char* argv[]) { int xmax, ymax; + // Create the application object FApplication app(argc, argv); + + // Create a FVTerm object as virtual terminal terminal = new FVTerm(&app); xmax = terminal->getColumnNumber() - 1; ymax = terminal->getLineNumber() - 1; FString line(xmax + 1, '-'); + // Place the cursor in the upper left corner terminal->setTermXY(0,0); + // Reset all terminal attributes terminal->setNormal(); + // Clear the screen terminal->clearArea(); + // Show the determined terminal name and text resolution std::cout << "Terminal: " << terminal->getTermType() << "\r\n"; std::cout << " Columns: 0.." << xmax << "\r\n"; std::cout << " Lines: 0.." << ymax << "\r\n"; + // Show the escape sequences for the following cursor movements std::cout << std::setw(38) << "Cursor move\r\n"; std::cout << " (From) -> (To) "; std::cout << "escape sequence "; @@ -169,10 +177,13 @@ int main (int argc, char* argv[]) move (3, 2, xmax, 2); move (5, 5, xmax - 5, ymax - 5); + // Waiting for keypress keyPressed(); + // Show terminal speed and milliseconds for all cursor movement sequence std::cout << "\r" << line; terminal->printMoveDurations(); + // Waiting for keypress keyPressed(); } diff --git a/examples/scrollview.cpp b/examples/scrollview.cpp index f2ffb41d..37dd51fd 100644 --- a/examples/scrollview.cpp +++ b/examples/scrollview.cpp @@ -57,6 +57,7 @@ scrollview::scrollview (FWidget* parent) , go_west() , go_north() { + // Create the four navigation buttons go_east = new FButton(wchar_t(fc::BlackRightPointingPointer) , this); go_east->setGeometry (1, 1, 5, 1); @@ -69,6 +70,7 @@ scrollview::scrollview (FWidget* parent) go_north = new FButton(wchar_t(fc::BlackUpPointingTriangle) , this); go_north->setGeometry (1, getScrollHeight() - 2, 5, 1); + // Add scroll function callbacks to the buttons go_east->addCallback ( "clicked", @@ -259,7 +261,10 @@ int main (int argc, char* argv[]) // Create a simple dialog box scrollviewdemo svdemo(&app); + // Set dialog main_dlg as main widget app.setMainWidget(&svdemo); + + // Show and start the application svdemo.show(); return app.exec(); } diff --git a/examples/string-operations.cpp b/examples/string-operations.cpp index 81a149ba..8cee6a4d 100644 --- a/examples/string-operations.cpp +++ b/examples/string-operations.cpp @@ -47,11 +47,11 @@ int main (int, char**) std::cout << " cpp_str: \"" << cpp_str << "\"" << std::endl; // Test: copy a character - const FString& ch('c'); + const FString ch('c'); std::cout << " char: '" << ch << "'" << std::endl; // Test: copy a wide character - const FString& wch(L'w'); + const FString wch(L'w'); std::cout << " wchar_t: '" << wch << "'" << std::endl; // Test: utf-8 string diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index 9fd4e4ae..1af88bd9 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -400,11 +400,14 @@ int main (int argc, char* argv[]) 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); + // Set the dialog object as main widget app.setMainWidget(dialog); - dialog->show(); + // Show and start the application + dialog->show(); return app.exec(); } diff --git a/examples/timer.cpp b/examples/timer.cpp index ad440735..85442abc 100644 --- a/examples/timer.cpp +++ b/examples/timer.cpp @@ -78,12 +78,19 @@ void timer::onAccel (FAccelEvent* ev) //---------------------------------------------------------------------- int main (int argc, char* argv[]) { + // Create the application object FApplication app(argc, argv); app.setForegroundColor(fc::Default); app.setBackgroundColor(fc::Default); + + // Create a timer object t timer t(&app); t.addAccelerator('q'); + + // Set the timer object t as main widget app.setMainWidget(&t); + + // Show and start the application t.show(); return app.exec(); } diff --git a/examples/transparent.cpp b/examples/transparent.cpp index c8274f86..0fede05e 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -268,24 +268,18 @@ void MainWindow::onTimer (FTimerEvent*) int main (int argc, char* argv[]) { - if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 - || std::strcmp(argv[1], "-h") == 0 ) ) - { - std::cout << "Generic options:" << std::endl - << " -h, --help " - << "Display this help and exit" << std::endl; - FApplication::print_cmd_Options(); - std::exit(EXIT_SUCCESS); - } - + // Create the application object FApplication app (argc, argv); + // Create main dialog object MainWindow main_dlg (&app); main_dlg.setText ("non-transparent"); main_dlg.setGeometry (8, 16, 26, 7); + // Set dialog main_dlg as main widget app.setMainWidget (&main_dlg); - main_dlg.show(); + // Show and start the application + main_dlg.show(); return app.exec(); } diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 5e4e4ca7..c13509f1 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -91,6 +91,7 @@ Treeview::Treeview (FWidget* parent) FObjectIterator iter_egypt = item_africa->begin(); FListViewItem* item_egypt = static_cast(*iter_egypt); item_egypt = item_egypt; +item_africa->expand(); // Quit button FButton* Quit = new FButton (this); @@ -135,24 +136,19 @@ void Treeview::cb_exitApp (FWidget*, data_ptr) int main (int argc, char* argv[]) { - if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 - || std::strcmp(argv[1], "-h") == 0 ) ) - { - std::cout << "Generic options:" << std::endl - << " -h, --help " - << "Display this help and exit" << std::endl; - FApplication::print_cmd_Options(); - std::exit(EXIT_SUCCESS); - } - + // Create the application object FApplication app(argc, argv); + // Create main dialog object Treeview d(&app); d.setText (L"Continents"); d.setGeometry (int(1 + (app.getWidth() - 37) / 2), 3, 37, 20); d.setShadow(); + // Set dialog d as main widget app.setMainWidget(&d); + + // Show and start the application d.show(); return app.exec(); } diff --git a/examples/ui.cpp b/examples/ui.cpp index 691d720f..fa2a903a 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -911,16 +911,7 @@ int main (int argc, char* argv[]) FString ver = F_VERSION; // library version FString title = "The FINAL CUT " + ver + " (C) 2017 by Markus Gans"; - if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 - || std::strcmp(argv[1], "-h") == 0 ) ) - { - std::cout << "Generic options:" << std::endl - << " -h, --help " - << "Display this help and exit" << std::endl; - FApplication::print_cmd_Options(); - std::exit(EXIT_SUCCESS); - } - + // Create the application object app FApplication app(argc, argv); app.setXTermDefaultColors(true); app.setXTermTitle (title); @@ -929,12 +920,20 @@ int main (int argc, char* argv[]) //app.setTermSize(94,30); //app.setNewFont(); + // Create main dialog object d MyDialog d(&app); d.setText (title); d.setGeometry (int((app.getWidth() - 56) / 2), 2, 56, app.getHeight() - 4); d.setShadow(); + // Set the dialog object d as the main widget of the application. + // When you close the main widget, the application will be closed. app.setMainWidget(&d); + + // Show the dialog d d.show(); + + // Start the application + // and return the result to the operating system return app.exec(); } diff --git a/examples/watch.cpp b/examples/watch.cpp index a99e15e1..d624cb78 100644 --- a/examples/watch.cpp +++ b/examples/watch.cpp @@ -215,7 +215,10 @@ int main (int argc, char* argv[]) // Create a simple dialog box watch w(&app); + // Set dialog w as main widget app.setMainWidget(&w); + + // Show and start the application w.show(); return app.exec(); } diff --git a/examples/windows.cpp b/examples/windows.cpp index 373d4930..d550a94d 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -567,24 +567,18 @@ void Window::cb_destroyWindow (FWidget*, data_ptr data) int main (int argc, char* argv[]) { - if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 - || std::strcmp(argv[1], "-h") == 0 ) ) - { - std::cout << "Generic options:" << std::endl - << " -h, --help " - << "Display this help and exit" << std::endl; - FApplication::print_cmd_Options(); - std::exit(EXIT_SUCCESS); - } - + // Create the application object FApplication app (argc, argv); + // Create main dialog object Window main_dlg (&app); main_dlg.setText ("Main window"); main_dlg.setGeometry (int(1 + (app.getWidth() - 40) / 2), 2, 40, 6); + // Set dialog main_dlg as main widget app.setMainWidget (&main_dlg); - main_dlg.show(); + // Show and start the application + main_dlg.show(); return app.exec(); } diff --git a/include/final/fapplication.h b/include/final/fapplication.h index f8febe8f..d257f23e 100644 --- a/include/final/fapplication.h +++ b/include/final/fapplication.h @@ -85,8 +85,8 @@ class FApplication : public FWidget static void queueEvent (const FObject*, const FEvent*); static void sendQueuedEvents (); static bool eventInQueue(); - static bool removeQueuedEvent(const FObject*); - static void print_cmd_Options(); + static bool removeQueuedEvent (const FObject*); + static FWidget* showParameterUsage (const int&, char*[]); private: // Typedefs and Enumerations diff --git a/include/final/flistview.h b/include/final/flistview.h index a3bddf15..c12bc17c 100644 --- a/include/final/flistview.h +++ b/include/final/flistview.h @@ -30,6 +30,7 @@ #ifndef FLISTVIEW_H #define FLISTVIEW_H +#include #include #include "final/fscrollbar.h" @@ -52,8 +53,6 @@ class FListViewItem : public FObject public: // Constructor FListViewItem (const FListViewItem&); // copy constructor - explicit FListViewItem (FListViewItem*); - explicit FListViewItem (FListView*); explicit FListViewItem (FObjectIterator); FListViewItem ( const std::vector& , FWidget::data_ptr @@ -69,6 +68,7 @@ class FListViewItem : public FObject const char* getClassName() const; uInt getColumnCount() const; FString getText (int) const; + uInt getDepth() const; // Mutator void setText (int, const FString&); @@ -142,56 +142,56 @@ class FListView : public FWidget ~FListView(); // Accessors - const char* getClassName() const; - uInt getCount() const; - fc::text_alignment getColumnAlignment (int) const; - FString getColumnText (int) const; - FListViewItem* getCurrentItem(); + const char* getClassName() const; + uInt getCount() const; + fc::text_alignment getColumnAlignment (int) const; + FString getColumnText (int) const; + FListViewItem* getCurrentItem(); // Mutators - void setGeometry (int, int, int, int, bool = true); - void setColumnAlignment (int, fc::text_alignment); - void setColumnText (int, const FString&); - bool setTreeView (bool); - bool setTreeView(); - bool unsetTreeView(); + void setGeometry (int, int, int, int, bool = true); + void setColumnAlignment (int, fc::text_alignment); + void setColumnText (int, const FString&); + bool setTreeView (bool); + bool setTreeView(); + bool unsetTreeView(); // Methods - virtual int addColumn (const FString&, int = USE_MAX_SIZE); - FObjectIterator insert (FListViewItem*); - FObjectIterator insert (FListViewItem*, FObjectIterator); - FObjectIterator insert ( const std::vector& - , data_ptr = 0 ); - FObjectIterator insert ( const std::vector& - , FObjectIterator ); - FObjectIterator insert ( const std::vector& - , data_ptr - , FObjectIterator ); - FObjectIterator insert ( const std::vector& - , data_ptr = 0 ); - FObjectIterator insert ( const std::vector& - , FObjectIterator ); - FObjectIterator insert ( const std::vector& - , data_ptr - , FObjectIterator ); - FObjectIterator beginOfList(); - FObjectIterator endOfList(); + virtual int addColumn (const FString&, int = USE_MAX_SIZE); + FObjectIterator insert (FListViewItem*); + FObjectIterator insert (FListViewItem*, FObjectIterator); + FObjectIterator insert ( const std::vector& + , data_ptr = 0 ); + FObjectIterator insert ( const std::vector& + , FObjectIterator ); + FObjectIterator insert ( const std::vector& + , data_ptr + , FObjectIterator ); + FObjectIterator insert ( const std::vector& + , data_ptr = 0 ); + FObjectIterator insert ( const std::vector& + , FObjectIterator ); + FObjectIterator insert ( const std::vector& + , data_ptr + , FObjectIterator ); + FObjectIterator beginOfList(); + FObjectIterator endOfList(); // 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*); + 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*); protected: // Methods - void adjustYOffset(); - void adjustSize(); + void adjustYOffset(); + void adjustSize(); private: // Typedef @@ -215,6 +215,7 @@ class FListView : public FWidget }; typedef std::vector
headerItems; + typedef std::stack FObjectIteratorStack; // Constants static const int USE_MAX_SIZE = -1; @@ -226,42 +227,43 @@ class FListView : public FWidget FListView& operator = (const FListView&); // Methods - void init(); - uInt getAlignOffset (fc::text_alignment, uInt, uInt); - void draw(); - void drawColumnLabels(); - void drawList(); - void drawListLine (const FListViewItem*, bool, bool); - void recalculateHorizontalBar (int); - void recalculateVerticalBar (int); - FObjectIterator appendItem (FListViewItem*); - void processClick(); - void processChanged(); - FObjectIterator index2iterator (int); - void nextElement (FObjectIterator&); + void init(); + uInt getAlignOffset (fc::text_alignment, uInt, uInt); + void draw(); + void drawColumnLabels(); + void drawList(); + void drawListLine (const FListViewItem*, bool, bool); + void recalculateHorizontalBar (int); + void recalculateVerticalBar (int); + FObjectIterator appendItem (FListViewItem*); + void processClick(); + void processChanged(); + FObjectIterator index2iterator (int); + void nextElement (FObjectIterator&); // Callback methods - void cb_VBarChange (FWidget*, data_ptr); - void cb_HBarChange (FWidget*, data_ptr); + void cb_VBarChange (FWidget*, data_ptr); + void cb_HBarChange (FWidget*, data_ptr); // Data Members - FObjectIterator root; - FObjectList selflist; - FObjectList itemlist; - headerItems header; - FTermBuffer headerline; - FScrollbar* vbar; - FScrollbar* hbar; - fc::dragScroll drag_scroll; - int scroll_repeat; - int scroll_distance; - bool scroll_timer; - bool tree_view; - int current; - int xoffset; - int yoffset; - int nf_offset; - int max_line_width; + FObjectIterator root; + FObjectList selflist; + FObjectList itemlist; + FObjectIteratorStack iter_path; + headerItems header; + FTermBuffer headerline; + FScrollbar* vbar; + FScrollbar* hbar; + fc::dragScroll drag_scroll; + int scroll_repeat; + int scroll_distance; + bool scroll_timer; + bool tree_view; + int current; + int xoffset; + int yoffset; + int nf_offset; + int max_line_width; // Friend class friend class FListViewItem; @@ -345,13 +347,27 @@ inline void FListView::nextElement (FObjectIterator& iter) { FListViewItem* item = static_cast(*iter); - if ( item->isExpandable() ) + if ( item->isExpandable() && item->isExpand() ) { - //iter = item->begin(); - ++iter; + iter_path.push(iter); + iter = item->begin(); } else + { ++iter; + + if ( ! iter_path.empty() ) + { + FObjectIterator& parent_iter = iter_path.top(); + + if ( iter == (*parent_iter)->end() ) + { + iter = parent_iter; + iter_path.pop(); + ++iter; + } + } + } } #endif // FLISTVIEW_H diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index 83b1c234..5c255254 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -2,8 +2,8 @@ if [ $# -gt 0 ] then - eval cppcheck --enable=all "$@" + eval cppcheck --force --enable=all -I../include/ "$@" else - eval cppcheck --enable=all ../include/final/ ../src/ ../examples/ + eval cppcheck --force --enable=all -I../include/ ../src/ ../examples/ fi diff --git a/src/fapplication.cpp b/src/fapplication.cpp index a50118c7..58af611e 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -38,7 +38,7 @@ FApplication::eventQueue* FApplication::event_queue = 0; FApplication::FApplication ( const int& _argc , char* _argv[] , bool disable_alt_screen ) - : FWidget(0, disable_alt_screen) + : FWidget(showParameterUsage(_argc,_argv), disable_alt_screen) , app_argc(_argc) , app_argv(_argv) , key(0) @@ -290,14 +290,31 @@ bool FApplication::removeQueuedEvent (const FObject* receiver) } //---------------------------------------------------------------------- -void FApplication::print_cmd_Options () +FWidget* FApplication::showParameterUsage (const int& argc, char* argv[]) { - std::printf ( "\nFinalCut Options:\n" - " --encoding Sets the character encoding mode\n" - " {UTF8, VT100, PC, ASCII}\n" - " --no-optimized-cursor No cursor optimisation\n" - " --vgafont Set the standard vga 8x16 font\n" - " --newfont Enables the graphical font\n" ); + if ( argc > 0 && argv[1] && ( std::strcmp(argv[1], "--help") == 0 + || std::strcmp(argv[1], "-h") == 0 ) ) + { + std::cout \ + << "Generic options:" << std::endl + << " -h, --help " + << " Display this help and exit" << std::endl + << std::endl + << "FinalCut Options:" << std::endl + << " --encoding " + << " Sets the character encoding mode" << std::endl + << " " + << " {UTF8, VT100, PC, ASCII}" << std::endl + << " --no-optimized-cursor" + << " No cursor optimisation" << std::endl + << " --vgafont " + << " Set the standard vga 8x16 font" << std::endl + << " --newfont " + << " Enables the graphical font" << std::endl; + std::exit(EXIT_SUCCESS); + } + + return 0; } @@ -335,6 +352,7 @@ void FApplication::init() std::fill_n (urxvt_mouse, sizeof(urxvt_mouse), '\0'); // init bit field with 0 std::memset(&b_state, 0x00, sizeof(b_state)); + // interpret the command line options cmd_options(); } diff --git a/src/fcheckmenuitem.cpp b/src/fcheckmenuitem.cpp index a6f0b618..6c9aab38 100644 --- a/src/fcheckmenuitem.cpp +++ b/src/fcheckmenuitem.cpp @@ -40,9 +40,7 @@ void FCheckMenuItem::init (FWidget* parent) if ( isMenu(parent) ) // Parent is menu { FMenu* menu_ptr = static_cast(parent); - - if ( menu_ptr ) - menu_ptr->has_checkable_items = true; + menu_ptr->has_checkable_items = true; } } diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 3a93e99b..b928defe 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -241,7 +241,6 @@ int FFileDialog::readDir() int start, dir_num; const char* const dir = directory.c_str(); const char* const filter = filter_pattern.c_str(); - errno = 0; directory_stream = opendir(dir); if ( ! directory_stream ) @@ -254,37 +253,40 @@ int FFileDialog::readDir() while ( true ) { - errno = 0; - struct dirent* next = readdir (directory_stream); + int retval; + struct dirent next; + struct dirent* result; - if ( next ) + retval = readdir_r(directory_stream, &next, &result); + + if ( result && retval == 0 ) { - if ( next->d_name[0] == '.' && next->d_name[1] == '\0' ) + if ( next.d_name[0] == '.' && next.d_name[1] == '\0' ) continue; if ( ! show_hidden - && next->d_name[0] == '.' - && next->d_name[1] != '\0' - && next->d_name[1] != '.' ) + && next.d_name[0] == '.' + && next.d_name[1] != '\0' + && next.d_name[1] != '.' ) { continue; } if ( dir[0] == '/' && dir[1] == '\0' - && std::strcmp(next->d_name, "..") == 0 ) + && std::strcmp(next.d_name, "..") == 0 ) continue; dir_entry entry; - entry.name = strdup(next->d_name); - entry.type = next->d_type; + entry.name = strdup(next.d_name); + entry.type = next.d_type; - if ( next->d_type == DT_LNK ) // symbolic link + if ( next.d_type == DT_LNK ) // symbolic link { char resolved_path[MAXPATHLEN] = {}; char symLink[MAXPATHLEN] = {}; std::strncpy (symLink, dir, sizeof(symLink) - 1); std::strncat ( symLink - , next->d_name + , next.d_name , sizeof(symLink) - std::strlen(symLink) - 1); if ( realpath(symLink, resolved_path) != 0 ) // follow link @@ -306,11 +308,11 @@ int FFileDialog::readDir() else std::free(entry.name); } - else if (errno != 0) + else if ( retval > 0 ) { FMessageBox::error (this, "Reading directory\n" + directory); - if ( errno != EOVERFLOW ) + if ( retval == EBADF ) // Invalid directory stream descriptor break; } else diff --git a/src/flistview.cpp b/src/flistview.cpp index ee0a49a1..c63bcd4a 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -87,6 +87,20 @@ FString FListViewItem::getText (int column) const return column_list[uInt(column)]; } +//---------------------------------------------------------------------- +uInt FListViewItem::getDepth() const +{ + FObject* parent = getParent(); + + if ( parent && parent->isInstanceOf("FListViewItem") ) + { + FListViewItem* parent_item = static_cast(parent); + return parent_item->getDepth() + 1; + } + + return 0; +} + //---------------------------------------------------------------------- void FListViewItem::setText (int column, const FString& text) { @@ -226,6 +240,7 @@ FListView::FListView (FWidget* parent) , root() , selflist() , itemlist() + , iter_path() , header() , headerline() , vbar(0) @@ -408,6 +423,8 @@ FObject::FObjectIterator FListView::insert ( FListViewItem* item item_iter = parent->appendItem (item); } } + else + item_iter = FObjectIterator(0); int element_count = int(getCount()); recalculateVerticalBar (element_count); @@ -1294,6 +1311,8 @@ void FListView::drawListLine ( const FListViewItem* item , bool is_focus , bool is_current ) { + uInt indent = item->getDepth() << 1; // indent = 2 * depth + setColor (wc.list_fg, wc.list_bg); if ( is_current ) @@ -1329,13 +1348,24 @@ void FListView::drawListLine ( const FListViewItem* item if ( tree_view ) { + if ( indent > 0 ) + line = FString(indent, L' '); + if ( item->expandable ) { - line = wchar_t(fc::BlackRightPointingPointer); - line += L' '; + if (item->is_expand ) + { + line += wchar_t(fc::BlackDownPointingTriangle); // ▼ + line += L' '; + } + else + { + line += wchar_t(fc::BlackRightPointingPointer); // ► + line += L' '; + } } else - line = L" "; + line += L" "; } else line = L" "; @@ -1359,6 +1389,7 @@ void FListView::drawListLine ( const FListViewItem* item if ( tree_view && i == 1 ) { + width -= indent; width--; } diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 908ac773..9bb2a4f2 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -797,16 +797,12 @@ void FMenu::init(FWidget* parent) if ( isMenuBar(parent) ) { FMenuBar* mbar = static_cast(parent); - - if ( mbar ) - mbar->calculateDimensions(); + mbar->calculateDimensions(); } else if ( isMenu(parent) ) { FMenu* smenu = static_cast(parent); - - if ( smenu ) - smenu->calculateDimensions(); + smenu->calculateDimensions(); } setSuperMenu(parent); diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index e642df1a..470f64ea 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -299,9 +299,7 @@ void FMenuItem::onKeyPress (FKeyEvent* ev) if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); - - if ( smenu ) - smenu->onKeyPress(ev); + smenu->onKeyPress(ev); } if ( isMenuBar(super_menu) ) @@ -330,23 +328,19 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); + const FPoint& p2 = smenu->termToWidgetPos(t); - if ( smenu ) + try { - const FPoint& p2 = smenu->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event - , p2, t, b ); - smenu->onMouseDoubleClick(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } + FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event + , p2, t, b ); + smenu->onMouseDoubleClick(_ev); + delete _ev; + } + catch (const std::bad_alloc& ex) + { + std::cerr << "not enough memory to alloc " + << ex.what() << std::endl; } } @@ -409,23 +403,19 @@ void FMenuItem::onMouseDown (FMouseEvent* ev) if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); + const FPoint& p2 = smenu->termToWidgetPos(t); - if ( smenu ) + try { - const FPoint& p2 = smenu->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event - , p2, t, b ); - smenu->onMouseDown(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } + FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event + , p2, t, b ); + smenu->onMouseDown(_ev); + delete _ev; + } + catch (const std::bad_alloc& ex) + { + std::cerr << "not enough memory to alloc " + << ex.what() << std::endl; } } @@ -488,40 +478,28 @@ void FMenuItem::onMouseUp (FMouseEvent* ev) if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); - - if ( smenu ) - { - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - smenu->onMouseUp(_ev); - delete _ev; - } + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); + smenu->onMouseUp(_ev); + delete _ev; } if ( isMenuBar(super_menu) ) { FMenuBar* mbar = static_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - mbar->onMouseUp(_ev); - delete _ev; - } + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); + mbar->onMouseUp(_ev); + delete _ev; } if ( isWindowsMenu(super_menu) ) { FDialog* dgl = static_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - dgl->onMouseUp(_ev); - delete _ev; - } + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); + dgl->onMouseUp(_ev); + delete _ev; } } @@ -537,40 +515,28 @@ void FMenuItem::onMouseMove (FMouseEvent* ev) if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); - - if ( smenu ) - { - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - smenu->onMouseMove(_ev); - delete _ev; - } + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); + smenu->onMouseMove(_ev); + delete _ev; } if ( isMenuBar(super_menu) ) { FMenuBar* mbar = static_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - mbar->onMouseMove(_ev); - delete _ev; - } + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); + mbar->onMouseMove(_ev); + delete _ev; } if ( isWindowsMenu(super_menu) ) { FDialog* dgl = static_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - dgl->onMouseMove(_ev); - delete _ev; - } + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); + dgl->onMouseMove(_ev); + delete _ev; } } @@ -588,9 +554,6 @@ void FMenuItem::onAccel (FAccelEvent* ev) FMenuBar* mbar = static_cast(super_menu); - if ( ! mbar ) - return; - if ( menu ) { FWidget* focused_widget; @@ -635,6 +598,7 @@ void FMenuItem::onAccel (FAccelEvent* ev) processClicked(); mbar->drop_down = false; } + ev->accept(); } @@ -653,9 +617,7 @@ void FMenuItem::onFocusOut (FFocusEvent*) if ( super_menu && isMenuBar(super_menu) ) { FMenuBar* mbar = static_cast(super_menu); - - if ( mbar ) - mbar->redraw(); + mbar->redraw(); } if ( getStatusBar() ) @@ -703,45 +665,39 @@ void FMenuItem::init (FWidget* parent) setGeometry (1, 1, int(text_length + 2), 1, false); - if ( parent ) + if ( ! parent ) + return; + + FMenuList* menu_list; + setSuperMenu (parent); + + if ( accel_key ) + addAccelerator (accel_key); + + menu_list = dynamic_cast(parent); + + if ( menu_list ) + menu_list->insert(this); + + if ( isMenuBar(parent) ) // Parent is menubar { - FMenuList* menu_list; - setSuperMenu (parent); + FMenuBar* menubar_ptr = static_cast(parent); + menubar_ptr->calculateDimensions(); - if ( accel_key ) - addAccelerator (accel_key); + if ( hotkey ) // Meta + hotkey + menubar_ptr->addAccelerator ( fc::Fmkey_meta + std::tolower(hotkey) + , this ); - menu_list = dynamic_cast(parent); - - if ( menu_list ) - menu_list->insert(this); - - if ( isMenuBar(parent) ) // Parent is menubar - { - FMenuBar* menubar_ptr = static_cast(parent); - - if ( menubar_ptr ) - { - menubar_ptr->calculateDimensions(); - - if ( hotkey ) // Meta + hotkey - menubar_ptr->addAccelerator ( fc::Fmkey_meta + std::tolower(hotkey) - , this ); - } - - addCallback // for this element - ( - "deactivate", - F_METHOD_CALLBACK (parent, &FMenuBar::cb_item_deactivated) - ); - } - else if ( isMenu(parent) ) // Parent is menu - { - FMenu* menu_ptr = static_cast(parent); - - if ( menu_ptr ) - menu_ptr->calculateDimensions(); - } + addCallback // for this element + ( + "deactivate", + F_METHOD_CALLBACK (parent, &FMenuBar::cb_item_deactivated) + ); + } + else if ( isMenu(parent) ) // Parent is menu + { + FMenu* menu_ptr = static_cast(parent); + menu_ptr->calculateDimensions(); } } diff --git a/src/fradiomenuitem.cpp b/src/fradiomenuitem.cpp index 5c06ad23..718b8a05 100644 --- a/src/fradiomenuitem.cpp +++ b/src/fradiomenuitem.cpp @@ -41,9 +41,7 @@ void FRadioMenuItem::init (FWidget* parent) if ( isMenu(parent) ) // Parent is menu { FMenu* menu_ptr = static_cast(parent); - - if ( menu_ptr ) - menu_ptr->has_checkable_items = true; + menu_ptr->has_checkable_items = true; addCallback // for this element (