From 55070bfc399fa329512bf40a621c23915291e7ed Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 6 Aug 2017 17:02:19 +0200 Subject: [PATCH] Advanced streaming functionality for FTermBuffer and FVTerm::print() --- ChangeLog | 5 +++ src/fc.h | 5 +++ src/flistbox.cpp | 2 + src/flistview.cpp | 34 +++++++------- src/flistview.h | 3 +- src/fobject.cpp | 18 ++++++-- src/fobject.h | 1 + src/fprogressbar.cpp | 2 + src/fscrollbar.cpp | 2 + src/fscrollview.cpp | 2 + src/fterm.cpp | 8 +--- src/fterm.h | 101 +++++++++++++++++++++--------------------- src/ftermbuffer.cpp | 10 ++++- src/ftermbuffer.h | 5 ++- src/ftextview.cpp | 2 + src/ftogglebutton.cpp | 2 + src/fvterm.h | 10 ++++- src/fwidget.cpp | 2 + src/fwindow.cpp | 2 + test/listview.cpp | 2 +- 20 files changed, 134 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70eda37a..28a2b709 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-08-06 Markus Gans + * Fix GNU Screen support for vte/gnome-terminals + * Advanced streaming functionality for FTermBuffer + and FVTerm::print() + 2017-07-31 Markus Gans * New methods to retrieve or modify FListViewItem text or a FListView column text for a specific column diff --git a/src/fc.h b/src/fc.h index 9006287d..37881baa 100644 --- a/src/fc.h +++ b/src/fc.h @@ -11,6 +11,8 @@ #ifndef FC_H #define FC_H +#include "fstring.h" + //---------------------------------------------------------------------- // class fc @@ -1081,6 +1083,9 @@ class fc t_keypad_local, t_key_mouse }; + + // Data Member + static const FString* empty_string; }; #pragma pack(pop) diff --git a/src/flistbox.cpp b/src/flistbox.cpp index de75c574..b56d4eab 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -168,6 +168,8 @@ void FListBox::showInsideBrackets ( int index //---------------------------------------------------------------------- void FListBox::setGeometry (int x, int y, int w, int h, bool adjust) { + // Set the widget geometry + FWidget::setGeometry(x, y, w, h, adjust); if ( isNewFont() ) diff --git a/src/flistview.cpp b/src/flistview.cpp index a654ea51..2abb2645 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -8,10 +8,6 @@ #include "fstatusbar.h" #include "ftermbuffer.h" - -// static class attributes -FString FListView::empty_string = FString(""); - //---------------------------------------------------------------------- // class FListViewItem //---------------------------------------------------------------------- @@ -84,9 +80,9 @@ FListViewItem::~FListViewItem() FString FListViewItem::getText (int column) const { if (column < 0 || column_line.empty() || column >= int(column_line.size()) ) - return FListView::empty_string; + return *fc::empty_string; - return column_line[column]; + return column_line[uInt(column)]; } //---------------------------------------------------------------------- @@ -110,7 +106,7 @@ void FListViewItem::setText (int column, const FString& text) } } - column_line[column] = text; + column_line[uInt(column)] = text; } //---------------------------------------------------------------------- @@ -165,7 +161,7 @@ FString FListView::getColumnText (int column) const // Get the text of column if ( column < 0 || header.empty() || column >= int(header.size()) ) - return empty_string; + return *fc::empty_string; return header[uInt(column)].name; } @@ -173,6 +169,8 @@ FString FListView::getColumnText (int column) const //---------------------------------------------------------------------- void FListView::setGeometry (int x, int y, int w, int h, bool adjust) { + // Set the widget geometry + FWidget::setGeometry(x, y, w, h, adjust); if ( isNewFont() ) @@ -1032,34 +1030,35 @@ void FListView::drawColumnLabels() if ( txt_length <= uInt(column_width) ) { - headerline.write (txt); + headerline << txt; if ( txt_length < uInt(column_width) ) - headerline.write (' '); // tailing space + headerline << ' '; // tailing space if ( txt_length + tailing_space < uInt(column_width) ) { setColor(); FString line ( uInt(column_width) - tailing_space - txt_length , wchar_t(fc::BoxDrawingsHorizontal) ); - headerline.write (line); // horizontal line + headerline << line; // horizontal line } } else { - headerline.write (' '); - headerline.write (text.left(uInt(width - ellipsis_length))); + headerline << ' '; + headerline << text.left(uInt(width - ellipsis_length)); setColor (wc.label_ellipsis_fg, wc.label_bg); - headerline.write (".."); + headerline << ".."; if ( iter == header.end() - 1 ) // Last element - headerline.write (' '); + headerline << ' '; } ++iter; } - const std::vector& h = headerline.getBuffer(); + std::vector h; + h << headerline; first = h.begin() + xoffset; if ( int(h.size()) <= getClientWidth() ) @@ -1067,9 +1066,8 @@ void FListView::drawColumnLabels() else last = h.begin() + getClientWidth() + xoffset - 1; - const std::vector header_part (first, last); setPrintPos (2, 1); - print (header_part); + print() << std::vector(first, last); } //---------------------------------------------------------------------- diff --git a/src/flistview.h b/src/flistview.h index 6e936ce0..e5b797c4 100644 --- a/src/flistview.h +++ b/src/flistview.h @@ -198,7 +198,6 @@ class FListView : public FWidget void cb_HBarChange (FWidget*, data_ptr); // Data Members - static FString empty_string; listViewItems data; headerItems header; FTermBuffer headerline; @@ -227,7 +226,7 @@ inline const char* FListView::getClassName() const //---------------------------------------------------------------------- inline FListViewItem* FListView::getCurrentItem() const -{ return data[current-1]; } +{ return data[uInt(current-1)]; } //---------------------------------------------------------------------- inline FListView::listViewItems::iterator FListView::index2iterator (int index) diff --git a/src/fobject.cpp b/src/fobject.cpp index b6b24adf..3b24c9ba 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -4,9 +4,9 @@ #include "fobject.h" // static class attributes -bool FObject::timer_modify_lock; +bool FObject::timer_modify_lock; FObject::TimerList* FObject::timer_list = 0; - +const FString* fc::empty_string = 0; //---------------------------------------------------------------------- // class FObject @@ -27,8 +27,14 @@ FObject::FObject (FObject* parent) if ( parent == 0 ) { + timer_modify_lock = false; - timer_list = new TimerList(); + + if ( ! timer_list ) + timer_list = new TimerList(); + + if ( ! fc::empty_string ) + fc::empty_string = new FString(""); } else has_parent = true; @@ -49,6 +55,12 @@ FObject::~FObject() // destructor timer_list = 0; } + if ( ! has_parent && fc::empty_string ) + { + delete fc::empty_string; + fc::empty_string = 0; + } + // delete children objects FObjectList children = this->getChildren(); diff --git a/src/fobject.h b/src/fobject.h index d54afc72..cb5f6b71 100644 --- a/src/fobject.h +++ b/src/fobject.h @@ -18,6 +18,7 @@ #include #include +#include "fc.h" #include "fevent.h" diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 7d4bf394..5d6ff86c 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -49,6 +49,8 @@ void FProgressbar::setPercentage (int percentage_value) //---------------------------------------------------------------------- void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust) { + // Set the progress bar geometry + FWidget::setGeometry (x, y, w, h, adjust); bar_length = w; } diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index 9f4a5f80..a6d44dd4 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -151,6 +151,8 @@ void FScrollbar::setOrientation (int o) //---------------------------------------------------------------------- void FScrollbar::setGeometry (int x, int y, int w, int h, bool adjust) { + // Set the scrollbar geometry + FWidget::setGeometry (x, y, w, h, adjust); int nf = 0; diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 31508a86..fb836a65 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -222,6 +222,8 @@ void FScrollView::setSize (int w, int h, bool adjust) //---------------------------------------------------------------------- void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust) { + // Set the scroll view geometry + FWidget::setGeometry (x, y, w, h, adjust); scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1 , getTermY() + getTopPadding() - 1 ); diff --git a/src/fterm.cpp b/src/fterm.cpp index c10a3ed2..892cdf29 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -94,7 +94,6 @@ const FString* FTerm::xterm_font = 0; const FString* FTerm::xterm_title = 0; const FString* FTerm::answer_back = 0; const FString* FTerm::sec_da = 0; -const FString* FTerm::empty_string = 0; FOptiMove* FTerm::opti_move = 0; FOptiAttr* FTerm::opti_attr = 0; FTerm::modifier_key FTerm::mod_key; @@ -2597,7 +2596,8 @@ char* FTerm::init_256colorTerminal() gnome_terminal = true; // Each gnome-terminal should be able to use 256 colors color256 = true; - new_termtype = const_cast("gnome-256color"); + if ( ! screen_terminal ) + new_termtype = const_cast("gnome-256color"); } #if DEBUG @@ -3574,7 +3574,6 @@ void FTerm::init() opti_attr = new FOptiAttr(); term = new FRect(0,0,0,0); mouse = new FPoint(0,0); - empty_string = new FString(""); vt100_alt_char = new std::map; encoding_set = new std::map; @@ -4080,9 +4079,6 @@ void FTerm::finish() if ( vt100_alt_char ) delete vt100_alt_char; - if ( empty_string ) - delete empty_string; - if ( sec_da ) delete sec_da; diff --git a/src/fterm.h b/src/fterm.h index e488cf3c..7c215765 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -421,63 +421,63 @@ class FTerm static std::map * encoding_set; static FTermcap::tcap_map* tcap; - static bool mouse_support; - static bool terminal_detection; - static bool raw_mode; - static bool input_data_pending; - static bool non_blocking_stdin; - static bool gpm_mouse_enabled; - static bool pc_charset_console; - static bool utf8_input; - 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 color256; - static bool monochron; - static bool xterm_terminal; - static bool ansi_terminal; - static bool rxvt_terminal; - static bool urxvt_terminal; - static bool mlterm_terminal; - static bool putty_terminal; - static bool kde_konsole; - static bool gnome_terminal; - static bool kterm_terminal; - static bool tera_terminal; - static bool cygwin_terminal; - static bool mintty_terminal; - static bool linux_terminal; - static bool netbsd_terminal; - static bool openbsd_terminal; - static bool screen_terminal; - static bool tmux_terminal; - static char termtype[30]; - static char* term_name; - static char* locale_name; - static char* locale_xterm; - static FRect* term; // current terminal geometry - static FPoint* mouse; // mouse click position + static bool mouse_support; + static bool terminal_detection; + static bool raw_mode; + static bool input_data_pending; + static bool non_blocking_stdin; + static bool gpm_mouse_enabled; + static bool pc_charset_console; + static bool utf8_input; + 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 color256; + static bool monochron; + static bool xterm_terminal; + static bool ansi_terminal; + static bool rxvt_terminal; + static bool urxvt_terminal; + static bool mlterm_terminal; + static bool putty_terminal; + static bool kde_konsole; + static bool gnome_terminal; + static bool kterm_terminal; + static bool tera_terminal; + static bool cygwin_terminal; + static bool mintty_terminal; + static bool linux_terminal; + static bool netbsd_terminal; + static bool openbsd_terminal; + static bool screen_terminal; + static bool tmux_terminal; + static char termtype[30]; + static char* term_name; + static char* locale_name; + static char* locale_xterm; + static FRect* term; // current terminal geometry + static FPoint* mouse; // mouse click position - static int stdin_status_flags; - static int fd_tty; - static uInt baudrate; - static bool resize_term; + static int stdin_status_flags; + static int fd_tty; + static uInt baudrate; + static bool resize_term; - static struct termios term_init; + static struct termios term_init; static fc::linuxConsoleCursorStyle linux_console_cursor_style; static fc::freebsdConsoleCursorStyle freebsd_console_cursor_style; - static struct console_font_op screen_font; - static struct unimapdesc screen_unicode_map; + static struct console_font_op screen_font; + static struct unimapdesc screen_unicode_map; #if defined(__FreeBSD__) || defined(__DragonFly__) - static uInt bsd_alt_keymap; + static uInt bsd_alt_keymap; #endif #if defined(__NetBSD__) || defined(__OpenBSD__) - static kbd_t wscons_keyboard_encoding; + static kbd_t wscons_keyboard_encoding; #endif static FOptiMove* opti_move; @@ -486,7 +486,6 @@ class FTerm static const FString* xterm_title; static const FString* answer_back; static const FString* sec_da; - static const FString* empty_string; struct { @@ -520,11 +519,11 @@ inline int FTerm::getMaxColor() #if DEBUG //---------------------------------------------------------------------- inline const FString& FTerm::getAnswerbackString() -{ return (answer_back) ? *answer_back : *empty_string; } +{ return (answer_back) ? *answer_back : *fc::empty_string; } //---------------------------------------------------------------------- inline const FString& FTerm::getSecDAString() -{ return (sec_da) ? *sec_da : *empty_string; } +{ return (sec_da) ? *sec_da : *fc::empty_string; } #endif //---------------------------------------------------------------------- diff --git a/src/ftermbuffer.cpp b/src/ftermbuffer.cpp index 52533def..477d12f7 100644 --- a/src/ftermbuffer.cpp +++ b/src/ftermbuffer.cpp @@ -137,5 +137,13 @@ int FTermBuffer::write (register int c) } -// private methods of FTermBuffer +// FTermBuffer non-member operators //---------------------------------------------------------------------- +std::vector< FTermBuffer::char_data>& operator << ( std::vector& termString + , const FTermBuffer& buf ) +{ + if ( ! buf.data.empty() ) + termString.assign(buf.data.begin(), buf.data.end()); + + return termString; +} diff --git a/src/ftermbuffer.h b/src/ftermbuffer.h index 59ead670..e96454c2 100644 --- a/src/ftermbuffer.h +++ b/src/ftermbuffer.h @@ -40,6 +40,9 @@ class FTermBuffer // Overloaded operators template FTermBuffer& operator << (const type&); + // Non-member operators + friend std::vector& operator << ( std::vector& + , const FTermBuffer& ); // Accessors virtual const char* getClassName() const; @@ -79,7 +82,7 @@ class FTermBuffer template inline FTermBuffer& FTermBuffer::operator << (const type& s) { - std::ostringstream outstream; + std::wostringstream outstream; outstream << s; write (outstream.str()); return *this; diff --git a/src/ftextview.cpp b/src/ftextview.cpp index ddcf8226..2e02960f 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -73,6 +73,8 @@ const FString FTextView::getText() const //---------------------------------------------------------------------- void FTextView::setGeometry (int x, int y, int w, int h, bool adjust) { + // Set the text view geometry + FWidget::setGeometry(x, y, w, h, adjust); int width = getWidth(); int height = getHeight(); diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 3fab3cea..08d959c5 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -69,6 +69,8 @@ FToggleButton::~FToggleButton() // destructor //---------------------------------------------------------------------- void FToggleButton::setGeometry (int x, int y, int w, int h, bool adjust) { + // Set the toggle button geometry + int min_width = button_width + int(text.getLength()); if ( w < min_width ) diff --git a/src/fvterm.h b/src/fvterm.h index a91d768b..ddad1434 100644 --- a/src/fvterm.h +++ b/src/fvterm.h @@ -133,6 +133,7 @@ class FVTerm : public FObject, public FTerm // Overloaded operators template FVTerm& operator << (const type&); + FVTerm& operator << (const std::vector&); // Accessors virtual const char* getClassName() const; @@ -424,12 +425,19 @@ class FVTerm : public FObject, public FTerm template inline FVTerm& FVTerm::operator << (const type& s) { - std::ostringstream outstream; + std::wostringstream outstream; outstream << s; print (outstream.str()); return *this; } +//---------------------------------------------------------------------- +inline FVTerm& FVTerm::operator << (const std::vector& termString) +{ + print (termString); + return *this; +} + //---------------------------------------------------------------------- inline const char* FVTerm::getClassName() const { return "FVTerm"; } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 5a2609c2..16a26c72 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -661,6 +661,8 @@ void FWidget::setTermSize (int w, int h) //---------------------------------------------------------------------- void FWidget::setGeometry (int x, int y, int w, int h, bool adjust) { + // Sets the geometry of the widget relative to its parent + int term_x, term_y; w = std::min (w, size_hints.max_width); diff --git a/src/fwindow.cpp b/src/fwindow.cpp index d291676c..636d5f4b 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -395,6 +395,8 @@ void FWindow::setSize (int w, int h, bool adjust) //---------------------------------------------------------------------- void FWindow::setGeometry (int x, int y, int w, int h, bool adjust) { + // Sets the geometry of the widget + int old_x = getX(); int old_y = getY(); int old_width = getWidth(); diff --git a/test/listview.cpp b/test/listview.cpp index 129c8f64..9c46351b 100644 --- a/test/listview.cpp +++ b/test/listview.cpp @@ -159,7 +159,7 @@ void Listview::cb_exitApp (FWidget*, data_ptr) //---------------------------------------------------------------------- void Listview::cb_showInMessagebox (FWidget* widget, data_ptr) { - FListView* listView = static_cast(widget);listView=listView; + FListView* listView = static_cast(widget); FListViewItem* item = listView->getCurrentItem(); FMessageBox info ( "Weather in " + item->getText(0) , " Condition: " + item->getText(1) + "\n"