Advanced streaming functionality for FTermBuffer and FVTerm::print()

This commit is contained in:
Markus Gans 2017-08-06 17:02:19 +02:00
parent ba17c529ff
commit 55070bfc39
20 changed files with 134 additions and 84 deletions

View File

@ -1,3 +1,8 @@
2017-08-06 Markus Gans <guru.mail@muenster.de>
* Fix GNU Screen support for vte/gnome-terminals
* Advanced streaming functionality for FTermBuffer
and FVTerm::print()
2017-07-31 Markus Gans <guru.mail@muenster.de>
* New methods to retrieve or modify FListViewItem text or
a FListView column text for a specific column

View File

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

View File

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

View File

@ -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<char_data>& h = headerline.getBuffer();
std::vector<char_data> 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<char_data> header_part (first, last);
setPrintPos (2, 1);
print (header_part);
print() << std::vector<char_data>(first, last);
}
//----------------------------------------------------------------------

View File

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

View File

@ -6,7 +6,7 @@
// static class attributes
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;
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();

View File

@ -18,6 +18,7 @@
#include <list>
#include <vector>
#include "fc.h"
#include "fevent.h"

View File

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

View File

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

View File

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

View File

@ -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,6 +2596,7 @@ char* FTerm::init_256colorTerminal()
gnome_terminal = true;
// Each gnome-terminal should be able to use 256 colors
color256 = true;
if ( ! screen_terminal )
new_termtype = const_cast<char*>("gnome-256color");
}
@ -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<uChar,uChar>;
encoding_set = new std::map<std::string,fc::encoding>;
@ -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;

View File

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

View File

@ -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<FTermBuffer::char_data>& termString
, const FTermBuffer& buf )
{
if ( ! buf.data.empty() )
termString.assign(buf.data.begin(), buf.data.end());
return termString;
}

View File

@ -40,6 +40,9 @@ class FTermBuffer
// Overloaded operators
template<class type> FTermBuffer& operator << (const type&);
// Non-member operators
friend std::vector<char_data>& operator << ( std::vector<char_data>&
, const FTermBuffer& );
// Accessors
virtual const char* getClassName() const;
@ -79,7 +82,7 @@ class FTermBuffer
template<class type>
inline FTermBuffer& FTermBuffer::operator << (const type& s)
{
std::ostringstream outstream;
std::wostringstream outstream;
outstream << s;
write (outstream.str());
return *this;

View File

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

View File

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

View File

@ -133,6 +133,7 @@ class FVTerm : public FObject, public FTerm
// Overloaded operators
template<class type> FVTerm& operator << (const type&);
FVTerm& operator << (const std::vector<char_data>&);
// Accessors
virtual const char* getClassName() const;
@ -424,12 +425,19 @@ class FVTerm : public FObject, public FTerm
template<class type>
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<FVTerm::char_data>& termString)
{
print (termString);
return *this;
}
//----------------------------------------------------------------------
inline const char* FVTerm::getClassName() const
{ return "FVTerm"; }

View File

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

View File

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

View File

@ -159,7 +159,7 @@ void Listview::cb_exitApp (FWidget*, data_ptr)
//----------------------------------------------------------------------
void Listview::cb_showInMessagebox (FWidget* widget, data_ptr)
{
FListView* listView = static_cast<FListView*>(widget);listView=listView;
FListView* listView = static_cast<FListView*>(widget);
FListViewItem* item = listView->getCurrentItem();
FMessageBox info ( "Weather in " + item->getText(0)
, " Condition: " + item->getText(1) + "\n"