The command line help text is now available in all applications

This commit is contained in:
Markus Gans 2017-09-19 06:18:03 +02:00
parent 82f1b7e44c
commit fc113795b4
32 changed files with 358 additions and 319 deletions

View File

@ -1,3 +1,6 @@
2017-09-19 Markus Gans <guru.mail@muenster.de>
* The command line help text is now available in all applications
2017-09-17 Markus Gans <guru.mail@muenster.de>
* FObject has received the iterator child access methods
begin() and end()

View File

@ -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();
}

View File

@ -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");

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -91,6 +91,7 @@ Treeview::Treeview (FWidget* parent)
FObjectIterator iter_egypt = item_africa->begin();
FListViewItem* item_egypt = static_cast<FListViewItem*>(*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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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

View File

@ -30,6 +30,7 @@
#ifndef FLISTVIEW_H
#define FLISTVIEW_H
#include <stack>
#include <vector>
#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<FString>&
, 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<FString>&
, data_ptr = 0 );
FObjectIterator insert ( const std::vector<FString>&
, FObjectIterator );
FObjectIterator insert ( const std::vector<FString>&
, data_ptr
, FObjectIterator );
FObjectIterator insert ( const std::vector<long>&
, data_ptr = 0 );
FObjectIterator insert ( const std::vector<long>&
, FObjectIterator );
FObjectIterator insert ( const std::vector<long>&
, 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<FString>&
, data_ptr = 0 );
FObjectIterator insert ( const std::vector<FString>&
, FObjectIterator );
FObjectIterator insert ( const std::vector<FString>&
, data_ptr
, FObjectIterator );
FObjectIterator insert ( const std::vector<long>&
, data_ptr = 0 );
FObjectIterator insert ( const std::vector<long>&
, FObjectIterator );
FObjectIterator insert ( const std::vector<long>&
, 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<Header> headerItems;
typedef std::stack<FObjectIterator> 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<FListViewItem*>(*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

View File

@ -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

View File

@ -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 <name> 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 <name> "
<< " 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();
}

View File

@ -40,9 +40,7 @@ void FCheckMenuItem::init (FWidget* parent)
if ( isMenu(parent) ) // Parent is menu
{
FMenu* menu_ptr = static_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->has_checkable_items = true;
menu_ptr->has_checkable_items = true;
}
}

View File

@ -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

View File

@ -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<FListViewItem*>(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--;
}

View File

@ -797,16 +797,12 @@ void FMenu::init(FWidget* parent)
if ( isMenuBar(parent) )
{
FMenuBar* mbar = static_cast<FMenuBar*>(parent);
if ( mbar )
mbar->calculateDimensions();
mbar->calculateDimensions();
}
else if ( isMenu(parent) )
{
FMenu* smenu = static_cast<FMenu*>(parent);
if ( smenu )
smenu->calculateDimensions();
smenu->calculateDimensions();
}
setSuperMenu(parent);

View File

@ -299,9 +299,7 @@ void FMenuItem::onKeyPress (FKeyEvent* ev)
if ( isMenu(super_menu) )
{
FMenu* smenu = static_cast<FMenu*>(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<FMenu*>(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<FMenu*>(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<FMenu*>(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<FMenuBar*>(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<FDialog*>(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<FMenu*>(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<FMenuBar*>(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<FDialog*>(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<FMenuBar*>(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<FMenuBar*>(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<FMenuList*>(parent);
if ( menu_list )
menu_list->insert(this);
if ( isMenuBar(parent) ) // Parent is menubar
{
FMenuList* menu_list;
setSuperMenu (parent);
FMenuBar* menubar_ptr = static_cast<FMenuBar*>(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<FMenuList*>(parent);
if ( menu_list )
menu_list->insert(this);
if ( isMenuBar(parent) ) // Parent is menubar
{
FMenuBar* menubar_ptr = static_cast<FMenuBar*>(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<FMenu*>(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<FMenu*>(parent);
menu_ptr->calculateDimensions();
}
}

View File

@ -41,9 +41,7 @@ void FRadioMenuItem::init (FWidget* parent)
if ( isMenu(parent) ) // Parent is menu
{
FMenu* menu_ptr = static_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->has_checkable_items = true;
menu_ptr->has_checkable_items = true;
addCallback // for this element
(