Replacing null-terminated wide strings with FString objects

This commit is contained in:
Markus Gans 2019-10-01 23:14:00 +02:00
parent 6b9336d6c1
commit 298755a0fe
48 changed files with 514 additions and 810 deletions

View File

@ -1,3 +1,7 @@
2019-10-01 Markus Gans <guru.mail@muenster.de>
* Replacing null-terminated wide strings with FString objects
* Fix for getColumnWidth() with newfont character
2019-09-29 Markus Gans <guru.mail@muenster.de>
* Streaming into an FTextView() object
* Fixes the streaming of empty FString objects into a stream with

View File

@ -83,9 +83,7 @@ The calculator example in newfont mode:
Virtual terminal
----------------
It uses a virtual terminal to print the character via an update method on the screen.
The virtual windows are an overlying layer to realizing window movements.
The update method transmits only the changes to the virtual terminal or the screen.
FINAL CUT uses a virtual terminal to print character via an update method on the screen. It provides (as an overlying layer) virtual windows for the realization of window movements. The update methods only transfer differences to the virtual terminal or physical screen.
<pre style="line-height: 1 !important;">
print(...)
@ -261,9 +259,7 @@ GNU Lesser General Public License Version 3
Frequently Asked Questions
--------------------------
If you have any problems, please read the
[FAQ](doc/faq.md#frequently-asked-questions)
before you give up.
For general questions about FINAL CUT, likely the answer is already included in the [FAQ](doc/faq.md#frequently-asked-questions).
Please send bug reports to
--------------------------

6
debian/libfinal0.docs vendored Normal file
View File

@ -0,0 +1,6 @@
AUTHORS
COPYING
COPYING.LESSER
ChangeLog
doc/readme.txt
fonts/newfont.txt

View File

@ -1,3 +1,6 @@
usr/lib/*/lib*.so
usr/lib/*/lib*.so.*
fonts/8x16graph.pcf.gz /usr/share/fonts/X11/misc/finalcut/
fonts/fonts.alias /usr/share/fonts/X11/misc/finalcut/
fonts/fonts.dir /usr/share/fonts/X11/misc/finalcut/
fonts/newfont.txt /usr/share/fonts/X11/misc/finalcut/

View File

@ -12,3 +12,50 @@ the C++ class design of FINAL CUT. It provides common controls like
dialog boxes, push buttons, check boxes, radio buttons, input lines,
list boxes, status bars and so on.
Installation
------------
> git clone git://github.com/gansm/finalcut.git
> cd finalcut
> autoreconf --install --force
> ./configure --prefix=/usr
> make
> su -c "make install"
Supported platforms
-------------------
* Linux
* FreeBSD
* NetBSD
* OpenBSD
* macOS
* Cygwin
* Solaris
First steps
-----------
See the first-steps.md documentation for information on how to use
the library.
License
-------
GNU Lesser General Public License Version 3
Frequently Asked Questions
--------------------------
For general questions about FINAL CUT, likely the answer is already included in the faq.md.
Download
--------
You can find the latest version at https://github.com/gansm/finalcut
Please send bug reports to
--------------------------
https://github.com/gansm/finalcut/issues

View File

@ -1,6 +1,13 @@
The virtual terminal (vterm)
----------------------------
FINAL CUT uses a virtual terminal to print character via an update
method on the screen. It provides (as an overlying layer) virtual windows
for the realization of window movements. The update methods only transfer
differences to the virtual terminal or physical screen.
print(...)
printf(...)

View File

@ -80,7 +80,7 @@ void Button::setChecked (bool enable)
}
else
{
const finalcut::FWidgetColors& wc = getFWidgetColors();
const auto& wc = getFWidgetColors();
setBackgroundColor(wc.button_active_bg);
setFocusForegroundColor(wc.button_active_focus_fg);
setFocusBackgroundColor(wc.button_active_focus_bg);
@ -328,7 +328,7 @@ void Calc::drawDispay()
if ( isMonochron() )
setReverse(false);
const finalcut::FWidgetColors& wc = getFWidgetColors();
const auto& wc = getFWidgetColors();
print() << FColorPair(fc::Black, fc::LightGray)
<< FPoint(3, 3) << display << ' '
<< FColorPair(wc.dialog_fg, wc.dialog_bg);

View File

@ -131,7 +131,7 @@ void Scrollview::draw()
if ( isMonochron() )
setReverse(true);
const finalcut::FWidgetColors& wc = getFWidgetColors();
const auto& wc = getFWidgetColors();
setColor (wc.label_inactive_fg, wc.dialog_bg);
clearArea();

View File

@ -262,7 +262,7 @@ void AttribDemo::printColorLine()
//----------------------------------------------------------------------
void AttribDemo::printAltCharset()
{
const finalcut::FWidgetColors& wc = getFWidgetColors();
const auto& wc = getFWidgetColors();
auto parent = static_cast<AttribDlg*>(getParent());
if ( ! isMonochron() )
@ -413,7 +413,7 @@ void AttribDemo::printProtected()
void AttribDemo::draw()
{
// test alternate character set
const finalcut::FWidgetColors& wc = getFWidgetColors();
const auto& wc = getFWidgetColors();
printAltCharset();
std::vector<std::function<void()> > effect

View File

@ -89,7 +89,7 @@ void Transparent::draw()
if ( type == shadow )
{
const finalcut::FWidgetColors& wc = getFWidgetColors();
const auto& wc = getFWidgetColors();
setColor(wc.shadow_bg, wc.shadow_fg);
setTransShadow();
}

View File

@ -68,7 +68,7 @@ class SmallWindow : public finalcut::FDialog
SmallWindow::SmallWindow (finalcut::FWidget* parent)
: finalcut::FDialog(parent)
{
const finalcut::FWidgetColors& wc = getFWidgetColors();
const auto& wc = getFWidgetColors();
wchar_t arrow_up, arrow_down;
arrow_up = fc::BlackUpPointingTriangle;
arrow_down = fc::BlackDownPointingTriangle;

View File

@ -1,3 +1,7 @@
# The FINAL CUT newfont
## *A graphical text font for X11 and the Linux console*
### How can I use the new graphical font under the Linux text console?
Simply start your program with the parameter `--newfont`.

View File

@ -1,3 +1,9 @@
----------------------------------------------------------------------
The FINAL CUT newfont
A graphical text font for X11 and the Linux console
----------------------------------------------------------------------
How can I use the new graphical font under the Linux text console?
------------------------------------------------------------------

View File

@ -251,14 +251,11 @@ void FButton::hide()
if ( size == 0 )
return;
char* blank = createBlankArray(size + 1);
for (std::size_t y{0}; y < getHeight() + s + (f << 1); y++)
{
print() << FPoint(1 - int(f), 1 + int(y - f)) << blank;
print() << FPoint(1 - int(f), 1 + int(y - f))
<< FString(size, L' ');
}
destroyBlankArray (blank);
}
//----------------------------------------------------------------------
@ -422,25 +419,7 @@ void FButton::init()
//----------------------------------------------------------------------
void FButton::setHotkeyAccelerator()
{
FKey hotkey = getHotkey(text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
setHotkeyViaString (this, text);
}
//----------------------------------------------------------------------
@ -560,7 +539,7 @@ inline void FButton::drawTopBottomBackground()
}
//----------------------------------------------------------------------
inline void FButton::drawButtonTextLine (wchar_t button_text[])
inline void FButton::drawButtonTextLine (const FString& button_text)
{
std::size_t pos{};
print() << FPoint(2 + int(indent), 1 + int(vcenter_offset))
@ -638,23 +617,12 @@ inline void FButton::drawButtonTextLine (wchar_t button_text[])
//----------------------------------------------------------------------
void FButton::draw()
{
wchar_t* button_text{};
FString button_text{};
auto parent_widget = getParentWidget();
auto txtlength = text.getLength();
column_width = getColumnWidth(text);
space_char = int(' ');
active_focus = getFlags().active && getFlags().focus;
try
{
button_text = new wchar_t[txtlength + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
if ( isMonochron() )
setReverse(true); // Light background
@ -673,7 +641,7 @@ void FButton::draw()
if ( getFlags().flat && ! button_down )
drawFlatBorder();
hotkeypos = finalcut::getHotkeyPos(text.wc_str(), button_text, uInt(txtlength));
hotkeypos = finalcut::getHotkeyPos(text, button_text);
if ( hotkeypos != NOT_SET )
column_width--;
@ -702,7 +670,6 @@ void FButton::draw()
if ( isMonochron() )
setReverse(false); // Dark background
delete[] button_text;
updateStatusBar();
}

View File

@ -182,6 +182,7 @@ void FButtonGroup::hide()
{
for (auto&& item : buttonlist)
{
// Hide items
auto toggle_button = static_cast<FToggleButton*>(item);
toggle_button->hide();
}
@ -205,15 +206,13 @@ void FButtonGroup::hide()
if ( size == 0 )
return;
char* blank = createBlankArray(size + 1);
// Hide border
unsetViewportPrint();
for (int y{0}; y < int(getHeight()); y++)
{
FWidget::setPrintPos (FPoint(1, 1 + y));
print (blank);
}
print() << FPoint(1, 1 + y) << FString(size, L' ');
destroyBlankArray (blank);
setViewportPrint();
}
//----------------------------------------------------------------------
@ -308,10 +307,10 @@ void FButtonGroup::onAccel (FAccelEvent*)
//----------------------------------------------------------------------
void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
{
in_ev->ignore(); // Change default value to ignore
if ( hasCheckedButton() && ! buttonlist.empty() )
{
in_ev->ignore();
for (auto&& item : buttonlist)
{
auto toggle_button = static_cast<FToggleButton*>(item);
@ -374,25 +373,7 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
//----------------------------------------------------------------------
void FButtonGroup::setHotkeyAccelerator()
{
FKey hotkey = getHotkey(text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
setHotkeyViaString (this, text);
}
//----------------------------------------------------------------------
@ -417,36 +398,18 @@ void FButtonGroup::drawLabel()
if ( text.isNull() || text.isEmpty() )
return;
wchar_t* LabelText{};
FString label_text{};
FString txt{" " + text + " "};
std::size_t length = txt.getLength();
try
{
LabelText = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
wchar_t* dest = const_cast<wchar_t*>(LabelText);
unsetViewportPrint();
auto hotkeypos = finalcut::getHotkeyPos(src, dest, length);
if ( hotkeypos != NOT_SET )
length--;
auto hotkeypos = finalcut::getHotkeyPos(txt, label_text);
if ( hasBorder() )
FWidget::setPrintPos (FPoint(2, 1));
else
FWidget::setPrintPos (FPoint(0, 1));
drawText (LabelText, hotkeypos, length);
drawText (label_text, hotkeypos);
setViewportPrint();
delete[] LabelText;
}
@ -472,18 +435,18 @@ void FButtonGroup::init()
}
//----------------------------------------------------------------------
void FButtonGroup::drawText ( wchar_t LabelText[]
, std::size_t hotkeypos
, std::size_t length )
void FButtonGroup::drawText ( const FString& label_text
, std::size_t hotkeypos )
{
const auto& wc = getFWidgetColors();
std::size_t column_width = getColumnWidth(LabelText);
std::size_t column_width = getColumnWidth(label_text);
std::size_t length = label_text.getLength();
bool ellipsis{false};
if ( column_width > getClientWidth() )
{
std::size_t len = getClientWidth() - 3;
FString s = finalcut::getColumnSubString (LabelText, 1, len);
FString s = finalcut::getColumnSubString (label_text, 1, len);
length = s.getLength();
ellipsis = true;
}
@ -505,7 +468,7 @@ void FButtonGroup::drawText ( wchar_t LabelText[]
if ( ! getFlags().no_underline )
setUnderline();
print (LabelText[z]);
print (label_text[z]);
if ( ! getFlags().no_underline )
unsetUnderline();
@ -513,7 +476,7 @@ void FButtonGroup::drawText ( wchar_t LabelText[]
setColor (wc.label_emphasis_fg, wc.label_bg);
}
else
print (LabelText[z]);
print (label_text[z]);
}
if ( ellipsis ) // Print ellipsis

View File

@ -333,25 +333,7 @@ void FLabel::init()
//----------------------------------------------------------------------
void FLabel::setHotkeyAccelerator()
{
FKey hotkey = getHotkey(text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
setHotkeyViaString (this, text);
}
//----------------------------------------------------------------------
@ -423,87 +405,48 @@ void FLabel::drawMultiLine()
while ( y < text_lines && y < std::size_t(getHeight()) )
{
wchar_t* label_text{};
std::size_t hotkeypos{NOT_SET};
std::size_t align_offset{};
FString label_text{};
hotkeypos = NOT_SET;
auto length = multiline_text[y].getLength();
auto column_width = getColumnWidth(multiline_text[y]);
try
{
label_text = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
auto src = const_cast<wchar_t*>(multiline_text[y].wc_str());
auto dest = const_cast<wchar_t*>(label_text);
column_width = getColumnWidth(multiline_text[y]);
if ( ! hotkey_printed )
hotkeypos = finalcut::getHotkeyPos(src, dest, length);
hotkeypos = finalcut::getHotkeyPos (multiline_text[y], label_text);
else
std::wcsncpy(dest, src, length);
label_text = multiline_text[y];
print() << FPoint(1, 1 + int(y));
if ( hotkeypos != NOT_SET )
{
align_offset = getAlignOffset(length - 1);
printLine (label_text, length - 1, column_width, hotkeypos, align_offset);
hotkey_printed = true;
}
else
{
align_offset = getAlignOffset(length);
printLine (label_text, length, column_width, NOT_SET, align_offset);
}
printLine (std::move(label_text));
y++;
delete[] label_text;
}
}
//----------------------------------------------------------------------
void FLabel::drawSingleLine()
{
wchar_t* label_text{};
std::size_t hotkeypos{NOT_SET};
auto length = text.getLength();
auto column_width = getColumnWidth(text);
try
{
label_text = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
hotkeypos = finalcut::getHotkeyPos (text.wc_str(), label_text, length);
FString label_text{};
column_width = getColumnWidth(text);
hotkeypos = finalcut::getHotkeyPos (text, label_text);
if ( hotkeypos != NOT_SET )
{
length--;
column_width--;
}
print() << FPoint(1, 1);
auto align_offset = getAlignOffset(column_width);
printLine (label_text, length, column_width, hotkeypos, align_offset);
delete[] label_text;
align_offset = getAlignOffset(column_width);
printLine (std::move(label_text));
}
//----------------------------------------------------------------------
void FLabel::printLine ( wchar_t line[]
, std::size_t length
, std::size_t column_width
, std::size_t hotkeypos
, std::size_t align_offset )
void FLabel::printLine (FString&& line)
{
std::size_t to_char{};
std::size_t to_column{};
@ -514,7 +457,7 @@ void FLabel::printLine ( wchar_t line[]
if ( column_width <= width )
{
to_char = length;
to_char = line.getLength();
to_column = column_width;
}
else

View File

@ -27,7 +27,6 @@
#include "final/fcolorpair.h"
#include "final/fevent.h"
#include "final/flistbox.h"
#include "final/fscrollbar.h"
#include "final/fstring.h"
#include "final/fstatusbar.h"
#include "final/fwidgetcolors.h"
@ -305,21 +304,16 @@ void FListBox::clear()
const auto& wc = getFWidgetColors();
setColor (wc.list_fg, wc.list_bg);
std::size_t size = getWidth() - 2;
drawBorder();
drawHeadline();
if ( size == 0 )
return;
char* blank = createBlankArray(size + 1);
std::memset (blank, ' ', size);
blank[size] = '\0';
for (int y{0}; y < int(getHeight()) - 2; y++)
{
print() << FPoint(2, 2 + y) << blank;
print() << FPoint(2, 2 + y) << FString(size, L' ');
}
destroyBlankArray (blank);
}
//----------------------------------------------------------------------
@ -754,8 +748,8 @@ inline FString& FListBox::getString (listBoxItems::iterator iter)
//----------------------------------------------------------------------
void FListBox::init()
{
initScrollbar (vbar, fc::vertical, &FListBox::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FListBox::cb_HBarChange);
initScrollbar (vbar, fc::vertical, this, &FListBox::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, this, &FListBox::cb_HBarChange);
setGeometry (FPoint(1, 1), FSize(5, 4), false); // initialize geometry values
const auto& wc = getFWidgetColors();
setForegroundColor (wc.dialog_fg);
@ -767,32 +761,6 @@ void FListBox::init()
setRightPadding(1 + int(nf_offset));
}
//----------------------------------------------------------------------
void FListBox::initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
, FListBoxCallback callback )
{
try
{
bar = std::make_shared<FScrollbar>(o, this);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, callback)
);
}
//----------------------------------------------------------------------
void FListBox::draw()
{

View File

@ -32,7 +32,6 @@
#include "final/fcolorpair.h"
#include "final/fevent.h"
#include "final/flistview.h"
#include "final/fscrollbar.h"
#include "final/fstatusbar.h"
#include "final/fstring.h"
#include "final/ftermbuffer.h"
@ -42,7 +41,7 @@ namespace finalcut
{
// Static class attribute
FObject::FObjectIterator FListView::null_iter;
FObject::iterator FListView::null_iter;
// Function prototypes
uInt64 firstNumberFromString (const FString&);
@ -55,14 +54,13 @@ bool sortDescendingByNumber (const FObject*, const FObject*);
//----------------------------------------------------------------------
uInt64 firstNumberFromString (const FString& str)
{
auto last = str.end();
auto iter = str.begin();
while ( iter != last )
while ( iter != str.end() )
{
if ( wchar_t(*iter) >= L'0' && wchar_t(*iter) <= L'9' )
{
if ( wchar_t(*(iter - 1)) == L'-' )
if ( iter != str.begin() && wchar_t(*(iter - 1)) == L'-' )
--iter;
break;
@ -73,10 +71,10 @@ uInt64 firstNumberFromString (const FString& str)
auto first_pos = iter;
if ( first_pos == last )
if ( first_pos == str.end() )
return 0;
while ( iter != last )
while ( iter != str.end() )
{
if ( wchar_t(*iter) < L'0' || wchar_t(*iter) > L'9' )
break;
@ -86,7 +84,7 @@ uInt64 firstNumberFromString (const FString& str)
auto last_pos = iter;
if ( last_pos == last )
if ( last_pos == str.end() )
return 0;
uInt64 number;
@ -186,7 +184,7 @@ FListViewItem::FListViewItem (const FListViewItem& item)
}
//----------------------------------------------------------------------
FListViewItem::FListViewItem (FObjectIterator parent_iter)
FListViewItem::FListViewItem (iterator parent_iter)
: FObject((*parent_iter)->getParent())
{
insert (this, parent_iter);
@ -195,7 +193,7 @@ FListViewItem::FListViewItem (FObjectIterator parent_iter)
//----------------------------------------------------------------------
FListViewItem::FListViewItem ( const FStringList& cols
, FDataPtr data
, FObjectIterator parent_iter )
, iterator parent_iter )
: FObject(nullptr)
, column_list(cols)
, data_pointer(data)
@ -279,7 +277,7 @@ void FListViewItem::setText (int column, const FString& text)
}
//----------------------------------------------------------------------
FObject::FObjectIterator FListViewItem::insert (FListViewItem* child)
FObject::iterator FListViewItem::insert (FListViewItem* child)
{
// Add a FListViewItem as child element
if ( ! child )
@ -289,8 +287,8 @@ FObject::FObjectIterator FListViewItem::insert (FListViewItem* child)
}
//----------------------------------------------------------------------
FObject::FObjectIterator FListViewItem::insert ( FListViewItem* child
, FObjectIterator parent_iter )
FObject::iterator FListViewItem::insert ( FListViewItem* child
, iterator parent_iter )
{
if ( parent_iter == FListView::null_iter )
return FListView::null_iter;
@ -353,7 +351,7 @@ void FListViewItem::sort (Compare cmp)
}
//----------------------------------------------------------------------
FObject::FObjectIterator FListViewItem::appendItem (FListViewItem* child)
FObject::iterator FListViewItem::appendItem (FListViewItem* child)
{
expandable = true;
resetVisibleLineCounter();
@ -434,7 +432,7 @@ void FListViewItem::resetVisibleLineCounter()
// constructor and destructor
//----------------------------------------------------------------------
FListViewIterator::FListViewIterator (FObjectIterator iter)
FListViewIterator::FListViewIterator (iterator iter)
: node(iter)
{ }
@ -496,7 +494,7 @@ FListViewIterator& FListViewIterator::operator -= (volatile int n)
// private methods of FListViewIterator
//----------------------------------------------------------------------
void FListViewIterator::nextElement (FObjectIterator& iter)
void FListViewIterator::nextElement (iterator& iter)
{
auto item = static_cast<FListViewItem*>(*iter);
@ -526,7 +524,7 @@ void FListViewIterator::nextElement (FObjectIterator& iter)
}
//----------------------------------------------------------------------
void FListViewIterator::prevElement (FObjectIterator& iter)
void FListViewIterator::prevElement (iterator& iter)
{
auto start_iter = iter;
@ -713,7 +711,7 @@ void FListView::setColumnSortType (int column, fc::sorting_type type)
if ( column < 1 || header.empty() || column > int(header.size()) )
return;
std::size_t size = std::size_t(column + 1);
std::size_t size = std::size_t(column) + 1;
if ( sort_type.empty() || sort_type.size() < size )
sort_type.resize(size);
@ -760,10 +758,10 @@ void FListView::hide()
}
//----------------------------------------------------------------------
FObject::FObjectIterator FListView::insert ( FListViewItem* item
, FObjectIterator parent_iter )
FObject::iterator FListView::insert ( FListViewItem* item
, iterator parent_iter )
{
FObjectIterator item_iter;
iterator item_iter;
if ( parent_iter == FListView::null_iter )
return FListView::null_iter;
@ -799,9 +797,9 @@ FObject::FObjectIterator FListView::insert ( FListViewItem* item
}
//----------------------------------------------------------------------
FObject::FObjectIterator FListView::insert ( const FStringList& cols
FObject::iterator FListView::insert ( const FStringList& cols
, FDataPtr d
, FObjectIterator parent_iter )
, iterator parent_iter )
{
FListViewItem* item;
@ -1379,8 +1377,8 @@ void FListView::adjustSize()
//----------------------------------------------------------------------
void FListView::init()
{
initScrollbar (vbar, fc::vertical, &FListView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FListView::cb_HBarChange);
initScrollbar (vbar, fc::vertical, this, &FListView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, this, &FListView::cb_HBarChange);
selflist.push_back(this);
root = selflist.begin();
null_iter = selflist.end();
@ -1395,32 +1393,6 @@ void FListView::init()
setRightPadding(1 + int(nf_offset));
}
//----------------------------------------------------------------------
void FListView::initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
, FListViewCallback callback )
{
try
{
bar = std::make_shared<FScrollbar>(o, this);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, callback)
);
}
//----------------------------------------------------------------------
template <typename Compare>
void FListView::sort (Compare cmp)
@ -2283,7 +2255,7 @@ void FListView::stopDragScroll()
}
//----------------------------------------------------------------------
FObject::FObjectIterator FListView::appendItem (FListViewItem* item)
FObject::iterator FListView::appendItem (FListViewItem* item)
{
item->root = root;
addChild (item);

View File

@ -1236,8 +1236,6 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
{
FString txt(m_item->getText());
menuText txtdata{};
std::size_t txt_length = txt.getLength();
std::size_t to_char = txt_length;
std::size_t column_width = getColumnWidth(txt);
FKey accel_key = m_item->accel_key;
bool is_enabled = m_item->isEnabled();
@ -1252,25 +1250,11 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
// Print leading blank space
print (' ');
try
{
txtdata.text = new wchar_t[txt_length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
hotkeypos = finalcut::getHotkeyPos(txt.wc_str(), txtdata.text, txt_length);
hotkeypos = finalcut::getHotkeyPos(txt, txtdata.text);
if ( hotkeypos != NOT_SET )
{
to_char--;
column_width--;
}
txtdata.length = to_char;
txtdata.no_underline = m_item->getFlags().no_underline;
setCursorToHotkeyPosition (m_item);
@ -1292,8 +1276,6 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
if ( isMonochron() && is_enabled && is_selected )
setReverse(true);
delete[] txtdata.text;
}
//----------------------------------------------------------------------
@ -1347,7 +1329,7 @@ inline void FMenu::drawMenuText (menuText& data)
{
// Print menu text
for (std::size_t z{0}; z < data.length; z++)
for (std::size_t z{0}; z < data.text.getLength(); z++)
{
if ( ! std::iswprint(std::wint_t(data.text[z])) )
{

View File

@ -64,15 +64,13 @@ void FMenuBar::resetMenu()
//----------------------------------------------------------------------
void FMenuBar::hide()
{
FWindow::hide();
const auto& wc = getFWidgetColors();
FColor fg = wc.term_fg;
FColor bg = wc.term_bg;
setColor (fg, bg);
screenWidth = getDesktopWidth();
char* blank = createBlankArray (screenWidth + 1);
print() << FPoint(1, 1) << blank;
destroyBlankArray (blank);
print() << FPoint(1, 1) << FString(getDesktopWidth(), L' ');
updateTerminal();
FWindow::hide();
}
//----------------------------------------------------------------------
@ -482,14 +480,13 @@ void FMenuBar::drawItems()
if ( isMonochron() )
setReverse(true);
screenWidth = getDesktopWidth();
std::size_t x{1};
for (auto&& item : list)
drawItem (item, x);
// Print spaces to end of line
for (; x <= screenWidth; x++)
for (; x <= getDesktopWidth(); x++)
print (' ');
if ( isMonochron() )
@ -503,8 +500,6 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
txtdata.startpos = x + 1;
txtdata.no_underline = menuitem->getFlags().no_underline;
FString txt(menuitem->getText());
std::size_t to_char{};
std::size_t txt_length = txt.getLength();
std::size_t column_width = getColumnWidth(txt);
bool is_enabled = menuitem->isEnabled();
bool is_selected = menuitem->isSelected();
@ -513,32 +508,14 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
setLineAttributes (menuitem);
drawLeadingSpace (x);
try
{
txtdata.text = new wchar_t[txt_length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
if ( x - 1 > screenWidth )
txt = txt.left(getColumnWidth(txt) - screenWidth - x - 1);
if ( x - 1 <= screenWidth )
to_char = txt_length;
else
to_char = txt_length - screenWidth - x - 1;
std::size_t hotkeypos = finalcut::getHotkeyPos ( txt.wc_str()
, txtdata.text
, txt_length );
std::size_t hotkeypos = finalcut::getHotkeyPos(txt, txtdata.text);
if ( hotkeypos != NOT_SET )
{
column_width--;
to_char--;
}
txtdata.length = to_char;
x += column_width;
if ( ! is_enabled || is_selected )
@ -556,8 +533,6 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
if ( isMonochron() && is_enabled && is_selected )
setReverse(true);
delete[] txtdata.text;
}
//----------------------------------------------------------------------
@ -616,7 +591,7 @@ inline void FMenuBar::drawMenuText (menuText& data)
{
// Print menu text
for (std::size_t z{0}; z < data.length; z++)
for (std::size_t z{0}; z < data.text.getLength(); z++)
{
if ( data.startpos > screenWidth - z )
break;

View File

@ -101,7 +101,7 @@ std::ostream& operator << (std::ostream& outstr, const FPoint& p)
//----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FPoint& p)
{
int x, y;
int x{}, y{};
instr >> x;
instr >> y;
p.setPoint (x, y);

View File

@ -381,7 +381,7 @@ std::ostream& operator << (std::ostream& outstr, const FRect& r)
//----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FRect& r)
{
int x1, y1, x2, y2;
int x1{}, y1{}, x2{}, y2{};
instr >> x1;
instr >> y1;
instr >> x2;

View File

@ -346,7 +346,7 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
if ( scroll_type == FScrollbar::scrollJump )
{
int new_val;
int new_val{};
if ( bar_orientation == fc::vertical )
{

View File

@ -797,34 +797,6 @@ void FScrollView::init (FWidget* parent)
setChildPrintArea (viewport);
}
//----------------------------------------------------------------------
void FScrollView::initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
, FScrollViewCallback callback )
{
try
{
bar = std::make_shared<FScrollbar>(o, this);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
term_area* area = getPrintArea();
bar->setPrintArea(area);
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, callback)
);
}
//----------------------------------------------------------------------
void FScrollView::calculateScrollbarPos()
{

View File

@ -174,15 +174,13 @@ bool FStatusBar::hasActivatedKey()
//----------------------------------------------------------------------
void FStatusBar::hide()
{
FWindow::hide();
const auto& wc = getFWidgetColors();
FColor fg = wc.term_fg;
FColor bg = wc.term_bg;
setColor (fg, bg);
screenWidth = getDesktopWidth();
char* blank = createBlankArray(screenWidth + 1);
print() << FPoint(1, 1) << blank;
destroyBlankArray (blank);
print() << FPoint(1, 1) << FString(getDesktopWidth(), L' ');
updateTerminal();
FWindow::hide();
}
//----------------------------------------------------------------------
@ -408,10 +406,9 @@ void FStatusBar::onMouseUp (FMouseEvent* ev)
if ( (*iter)->hasMouseFocus() )
{
int mouse_x, mouse_y;
(*iter)->unsetMouseFocus();
mouse_x = ev->getX();
mouse_y = ev->getY();
int mouse_x = ev->getX();
int mouse_y = ev->getY();
if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 )
(*iter)->setActive();

View File

@ -847,7 +847,7 @@ FString& FString::setString (const FString& s)
FString& FString::setNumber (sInt64 num)
{
bool neg{false};
wchar_t buf[30];
wchar_t buf[30]{};
wchar_t* s = &buf[29];
if ( num < 0 )
@ -879,7 +879,7 @@ FString& FString::setNumber (sInt64 num)
//----------------------------------------------------------------------
FString& FString::setNumber (uInt64 num)
{
wchar_t buf[30];
wchar_t buf[30]{};
wchar_t* s = &buf[29];
*s = '\0';
@ -897,7 +897,7 @@ FString& FString::setNumber (uInt64 num)
//----------------------------------------------------------------------
FString& FString::setNumber (lDouble f_num, int precision)
{
wchar_t format[20]; // = "%.<precision>Lg"
wchar_t format[20]{}; // = "%.<precision>Lg"
wchar_t* s = &format[0];
*s++ = L'%';
*s++ = L'.';
@ -930,7 +930,7 @@ FString& FString::setFormatedNumber (sInt64 num, char separator)
{
bool neg{false};
int n{0};
wchar_t buf[30];
wchar_t buf[30]{};
wchar_t* s = &buf[29];
if ( separator == 0 )
@ -969,7 +969,7 @@ FString& FString::setFormatedNumber (sInt64 num, char separator)
FString& FString::setFormatedNumber (uInt64 num, char separator)
{
int n{0};
wchar_t buf[30];
wchar_t buf[30]{};
wchar_t* s = &buf[29];
*s = L'\0';
@ -1328,7 +1328,7 @@ void FString::_assign (const wchar_t s[])
if ( string && std::wcscmp(string, s) == 0 )
return; // string == s
uInt new_length= uInt(std::wcslen(s));
uInt new_length = uInt(std::wcslen(s));
if ( ! string || new_length > capacity() )
{

View File

@ -759,7 +759,7 @@ bool FTerm::setOldFont()
if ( font.getLength() > 2 )
{
// restore saved xterm font
xterm->setFont (font);
xterm->setFont(font);
}
else
{
@ -1855,14 +1855,14 @@ void FTerm::init_captureFontAndTitle()
// Save the used xterm font and window title
xterm->captureFontAndTitle();
const auto font = xterm->getFont();
const auto title = xterm->getTitle();
const auto& font = xterm->getFont();
const auto& title = xterm->getTitle();
if ( font )
data->setXtermFont(*font);
if ( ! font.isEmpty() )
data->setXtermFont(font);
if ( title )
data->setXtermTitle(*title);
if ( ! title.isEmpty() )
data->setXtermTitle(title);
}
//----------------------------------------------------------------------
@ -2549,7 +2549,7 @@ wchar_t cp437_to_unicode (uChar c)
{
constexpr std::size_t CP437 = 0;
constexpr std::size_t UNICODE = 1;
wchar_t ucs(c);
wchar_t ucs = c;
for (std::size_t i{0}; i <= fc::lastCP437Item; i++)
{
@ -2740,15 +2740,20 @@ std::size_t getColumnWidth (const FString& s)
//----------------------------------------------------------------------
std::size_t getColumnWidth (const wchar_t wchar)
{
int column_width = wcwidth (wchar);
int column_width{};
if ( wchar >= fc::NF_rev_left_arrow2 && wchar <= fc::NF_check_mark )
column_width = 1;
else
column_width = wcwidth(wchar);
return ( column_width == -1 ) ? 0 : std::size_t(column_width);
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (charData& term_char)
{
int column_width = wcwidth (term_char.code);
std::size_t char_width = ( column_width == -1 ) ? 0 : std::size_t(column_width);
std::size_t char_width = getColumnWidth(term_char.code);
if ( char_width == 2 && FTerm::getEncoding() != fc::UTF8 )
{

View File

@ -43,14 +43,14 @@ bool FTermXTerminal::meta_sends_esc{false};
bool FTermXTerminal::xterm_default_colors{false};
std::size_t FTermXTerminal::term_width{80};
std::size_t FTermXTerminal::term_height{24};
const FString* FTermXTerminal::xterm_font{nullptr};
const FString* FTermXTerminal::xterm_title{nullptr};
const FString* FTermXTerminal::foreground_color{nullptr};
const FString* FTermXTerminal::background_color{nullptr};
const FString* FTermXTerminal::cursor_color{nullptr};
const FString* FTermXTerminal::mouse_foreground_color{nullptr};
const FString* FTermXTerminal::mouse_background_color{nullptr};
const FString* FTermXTerminal::highlight_background_color{nullptr};
FString FTermXTerminal::xterm_font{};
FString FTermXTerminal::xterm_title{};
FString FTermXTerminal::foreground_color{};
FString FTermXTerminal::background_color{};
FString FTermXTerminal::cursor_color{};
FString FTermXTerminal::mouse_foreground_color{};
FString FTermXTerminal::mouse_background_color{};
FString FTermXTerminal::highlight_background_color{};
FSystem* FTermXTerminal::fsystem{nullptr};
FTermDetection* FTermXTerminal::term_detection{nullptr};
fc::xtermCursorStyle FTermXTerminal::cursor_style{fc::unknown_cursor_style};
@ -70,31 +70,7 @@ FTermXTerminal::FTermXTerminal()
//----------------------------------------------------------------------
FTermXTerminal::~FTermXTerminal() // destructor
{
if ( highlight_background_color )
delete highlight_background_color;
if ( mouse_background_color )
delete mouse_background_color;
if ( mouse_foreground_color )
delete mouse_foreground_color;
if ( cursor_color )
delete cursor_color;
if ( background_color )
delete background_color;
if ( foreground_color )
delete foreground_color;
if ( xterm_title )
delete xterm_title;
if ( xterm_font )
delete xterm_font;
}
{ }
// public methods of FTermXTerminal
@ -112,10 +88,7 @@ void FTermXTerminal::setFont (const FString& fontname)
{
// Change the XTerm font (needs the allowFontOps resource)
if ( xterm_font )
delete xterm_font;
xterm_font = new FString(fontname);
xterm_font = fontname;
setXTermFont();
}
@ -124,10 +97,7 @@ void FTermXTerminal::setTitle (const FString& title)
{
// Set the xterm title
if ( xterm_title )
delete xterm_title;
xterm_title = new FString(title);
xterm_title = title;
setXTermTitle();
}
@ -146,10 +116,7 @@ void FTermXTerminal::setForeground (const FString& fg)
{
// Set the XTerm text foreground color
if ( foreground_color )
delete foreground_color;
foreground_color = new FString(fg);
foreground_color = fg;
setXTermForeground();
}
@ -158,10 +125,7 @@ void FTermXTerminal::setBackground (const FString& bg)
{
// Set the XTerm text background color
if ( background_color )
delete background_color;
background_color = new FString(bg);
background_color = bg;
setXTermBackground();
}
@ -170,10 +134,7 @@ void FTermXTerminal::setCursorColor (const FString& cc)
{
// Set the text cursor color
if ( cursor_color )
delete cursor_color;
cursor_color = new FString(cc);
cursor_color = cc;
setXTermCursorColor();
}
@ -182,10 +143,7 @@ void FTermXTerminal::setMouseForeground (const FString& mfg)
{
// Set the mouse foreground color
if ( mouse_foreground_color )
delete mouse_foreground_color;
mouse_foreground_color = new FString(mfg);
mouse_foreground_color = mfg;
setXTermMouseForeground();
}
@ -194,10 +152,7 @@ void FTermXTerminal::setMouseBackground (const FString& mbg)
{
// Set the mouse background color
if ( mouse_background_color )
delete mouse_background_color;
mouse_background_color = new FString(mbg);
mouse_background_color = mbg;
setXTermMouseBackground();
}
@ -206,10 +161,7 @@ void FTermXTerminal::setHighlightBackground (const FString& hbg)
{
// Set the highlight background color
if ( highlight_background_color )
delete highlight_background_color;
highlight_background_color = new FString(hbg);
highlight_background_color = hbg;
setXTermHighlightBackground();
}
@ -266,10 +218,7 @@ void FTermXTerminal::resetForeground()
{
// Reset the XTerm text foreground color
if ( foreground_color )
delete foreground_color;
foreground_color = nullptr;
foreground_color.clear();
resetXTermForeground();
}
@ -278,10 +227,7 @@ void FTermXTerminal::resetBackground()
{
// Reset the XTerm text background color
if ( background_color )
delete background_color;
background_color = nullptr;
background_color.clear();
resetXTermBackground();
}
@ -290,10 +236,7 @@ void FTermXTerminal::resetCursorColor()
{
// Reset the text cursor color
if ( cursor_color )
delete cursor_color;
cursor_color = nullptr;
cursor_color.clear();
resetXTermCursorColor();
}
@ -302,10 +245,7 @@ void FTermXTerminal::resetMouseForeground()
{
// Reset the mouse foreground color
if ( mouse_foreground_color )
delete mouse_foreground_color;
mouse_foreground_color = nullptr;
mouse_foreground_color.clear();
resetXTermMouseForeground();
}
@ -314,10 +254,7 @@ void FTermXTerminal::resetMouseBackground()
{
// Reset the mouse background color
if ( mouse_background_color )
delete mouse_background_color;
mouse_background_color = nullptr;
mouse_background_color.clear();
resetXTermMouseBackground();
}
@ -326,10 +263,7 @@ void FTermXTerminal::resetHighlightBackground()
{
// Reset the highlight background color
if ( highlight_background_color )
delete highlight_background_color;
highlight_background_color = nullptr;
highlight_background_color.clear();
resetXTermHighlightBackground();
}
@ -364,12 +298,6 @@ void FTermXTerminal::captureFontAndTitle()
|| term_detection->isUrxvtTerminal() )
&& ! term_detection->isRxvtTerminal() )
{
if ( xterm_font )
delete xterm_font;
if ( xterm_title )
delete xterm_title;
FTermios::setCaptureSendCharacters();
xterm_font = captureXTermFont();
xterm_title = captureXTermTitle();
@ -420,7 +348,7 @@ void FTermXTerminal::setXTermTitle()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "0;%s" BEL, xterm_title->c_str());
FTerm::putstringf (OSC "0;%s" BEL, xterm_title.c_str());
oscPostfix();
std::fflush(stdout);
}
@ -449,7 +377,7 @@ void FTermXTerminal::setXTermFont()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "50;%s" BEL, xterm_font->c_str() );
FTerm::putstringf (OSC "50;%s" BEL, xterm_font.c_str() );
oscPostfix();
}
}
@ -466,7 +394,7 @@ void FTermXTerminal::setXTermForeground()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "10;%s" BEL, foreground_color->c_str());
FTerm::putstringf (OSC "10;%s" BEL, foreground_color.c_str());
oscPostfix();
std::fflush(stdout);
}
@ -484,7 +412,7 @@ void FTermXTerminal::setXTermBackground()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "11;%s" BEL, background_color->c_str());
FTerm::putstringf (OSC "11;%s" BEL, background_color.c_str());
oscPostfix();
std::fflush(stdout);
}
@ -502,7 +430,7 @@ void FTermXTerminal::setXTermCursorColor()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "12;%s" BEL, cursor_color->c_str());
FTerm::putstringf (OSC "12;%s" BEL, cursor_color.c_str());
oscPostfix();
std::fflush(stdout);
}
@ -519,7 +447,7 @@ void FTermXTerminal::setXTermMouseForeground()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "13;%s" BEL, mouse_foreground_color->c_str());
FTerm::putstringf (OSC "13;%s" BEL, mouse_foreground_color.c_str());
oscPostfix();
std::fflush(stdout);
}
@ -535,7 +463,7 @@ void FTermXTerminal::setXTermMouseBackground()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "14;%s" BEL, mouse_background_color->c_str());
FTerm::putstringf (OSC "14;%s" BEL, mouse_background_color.c_str());
oscPostfix();
std::fflush(stdout);
}
@ -552,7 +480,7 @@ void FTermXTerminal::setXTermHighlightBackground()
|| FTermcap::osc_support )
{
oscPrefix();
FTerm::putstringf (OSC "17;%s" BEL, highlight_background_color->c_str());
FTerm::putstringf (OSC "17;%s" BEL, highlight_background_color.c_str());
oscPostfix();
std::fflush(stdout);
}
@ -769,7 +697,7 @@ void FTermXTerminal::oscPostfix()
}
//----------------------------------------------------------------------
const FString* FTermXTerminal::captureXTermFont()
const FString FTermXTerminal::captureXTermFont()
{
if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm()
@ -796,36 +724,25 @@ const FString* FTermXTerminal::captureXTermFont()
if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 )
{
FString* xtermfont;
std::size_t n = std::strlen(temp);
// BEL + '\0' = string terminator
if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' )
temp[n - 1] = '\0';
try
{
xtermfont = new FString(temp);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return 0;
}
return xtermfont;
return FString(temp);
}
}
}
return 0;
return FString{};
}
//----------------------------------------------------------------------
const FString* FTermXTerminal::captureXTermTitle()
const FString FTermXTerminal::captureXTermTitle()
{
if ( term_detection->isKdeTerminal() )
return 0;
return FString{};
fd_set ifds{};
struct timeval tv{};
@ -851,29 +768,16 @@ const FString* FTermXTerminal::captureXTermTitle()
// Esc + \ = OSC string terminator
if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' )
{
FString* xtermtitle;
if ( n < 4 )
return 0;
return FString{};
temp[n - 2] = '\0';
try
{
xtermtitle = new FString(temp);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return 0;
}
return xtermtitle;
return FString{temp};
}
}
}
return 0;
return FString{};
}
//----------------------------------------------------------------------

View File

@ -65,30 +65,28 @@ const FString FTextView::getText() const
return FString("");
std::size_t len{0};
std::size_t rows = getRows();
for (std::size_t i{0} ; i < rows; i++)
len += data[i].getLength() + 1;
for (auto&& line : data)
len += line.getLength() + 1; // String length + '\n'
FString s(len + 1);
std::size_t idx{0};
FString s(len); // Reserves storage
auto iter = s.begin();
for (std::size_t i{0}; i < rows; i++)
for (auto&& line : data)
{
const wchar_t* p = data[i].wc_str();
if ( p )
if ( ! line.isEmpty() )
{
while ( (s[idx++] = *p++) != 0 );
s[idx - 1] = '\n';
if ( iter != s.begin() )
{
*iter = '\n';
++iter;
}
else
{
s[idx++] = '\n';
std::copy (line.begin(), line.end(), iter);
iter += std::distance(line.begin(), line.end());
}
}
s[idx - 1] = 0;
return s;
}
@ -297,19 +295,28 @@ void FTextView::clear()
// clear list from screen
setColor();
if ( useFDialogBorder() )
{
auto parent = getParentWidget();
static_cast<FDialog*>(parent)->redraw();
}
else
drawBorder();
std::size_t size = getWidth() - 2;
if ( size == 0 )
return;
char* blank = createBlankArray(size + 1);
for (int y{0}; y < int(getTextHeight()); y++)
{
print() << FPoint(2, 2 - nf_offset + y) << blank;
print() << FPoint(2, 2 - nf_offset + y)
<< FString(size, L' ');
}
destroyBlankArray (blank);
updateTerminal();
processChanged();
}
@ -595,8 +602,8 @@ std::size_t FTextView::getTextWidth()
//----------------------------------------------------------------------
void FTextView::init()
{
initScrollbar (vbar, fc::vertical, &FTextView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FTextView::cb_HBarChange);
initScrollbar (vbar, fc::vertical, this, &FTextView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, this, &FTextView::cb_HBarChange);
const auto& wc = getFWidgetColors();
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
@ -607,61 +614,11 @@ void FTextView::init()
setRightPadding(1 + nf_offset);
}
//----------------------------------------------------------------------
void FTextView::initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
, FTextViewCallback callback )
{
try
{
bar = std::make_shared<FScrollbar>(o, this);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, callback)
);
}
//----------------------------------------------------------------------
void FTextView::draw()
{
auto parent = getParentWidget();
bool is_text_dialog;
setColor();
if ( isMonochron() )
setReverse(true);
if ( parent
&& parent->isDialogWidget()
&& isPaddingIgnored()
&& getGeometry() == FRect ( 1
, 2
, parent->getWidth()
, parent->getHeight() - 1) )
{
is_text_dialog = true;
}
else
is_text_dialog = false;
if ( ! (is_text_dialog || isNewFont()) )
drawBorder();
if ( isMonochron() )
setReverse(false);
drawScrollbars();
drawText();
@ -682,6 +639,21 @@ void FTextView::draw()
flush_out();
}
//----------------------------------------------------------------------
void FTextView::drawBorder()
{
if ( ! useFDialogBorder() )
{
if ( isMonochron() )
setReverse(true);
FWidget::drawBorder();
if ( isMonochron() )
setReverse(false);
}
}
//----------------------------------------------------------------------
void FTextView::drawScrollbars()
{
@ -740,6 +712,26 @@ void FTextView::drawText()
setReverse(false);
}
//----------------------------------------------------------------------
inline bool FTextView::useFDialogBorder()
{
auto parent = getParentWidget();
bool use_fdialog_border{false};
if ( parent
&& parent->isDialogWidget()
&& isPaddingIgnored()
&& getGeometry() == FRect ( 1
, 2
, parent->getWidth()
, parent->getHeight() - 1) )
{
use_fdialog_border = true;
}
return use_fdialog_border;
}
//----------------------------------------------------------------------
inline bool FTextView::isPrintable (wchar_t ch)
{

View File

@ -370,25 +370,7 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev)
//----------------------------------------------------------------------
void FToggleButton::setHotkeyAccelerator()
{
FKey hotkey = getHotkey(text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
setHotkeyViaString (this, text);
}
//----------------------------------------------------------------------
@ -429,34 +411,14 @@ void FToggleButton::draw()
//----------------------------------------------------------------------
void FToggleButton::drawLabel()
{
wchar_t* LabelText;
if ( text.isNull() || text.isEmpty() )
return;
std::size_t length = text.getLength();
try
{
LabelText = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
FString txt(text);
wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
wchar_t* dest = const_cast<wchar_t*>(LabelText);
auto hotkeypos = finalcut::getHotkeyPos(src, dest, length);
if ( hotkeypos != NOT_SET )
length--;
FString label_text{};
auto hotkeypos = finalcut::getHotkeyPos(txt, label_text);
print() << FPoint(1 + int(label_offset_pos), 1);
drawText (LabelText, hotkeypos, length);
delete[] LabelText;
drawText (std::move(label_text), hotkeypos);
}
//----------------------------------------------------------------------
@ -561,9 +523,7 @@ void FToggleButton::init()
}
//----------------------------------------------------------------------
void FToggleButton::drawText ( wchar_t LabelText[]
, std::size_t hotkeypos
, std::size_t length )
void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos)
{
if ( isMonochron() )
setReverse(true);
@ -575,7 +535,7 @@ void FToggleButton::drawText ( wchar_t LabelText[]
else
setColor (wc.label_inactive_fg, wc.label_inactive_bg);
for (std::size_t z{0}; z < length; z++)
for (std::size_t z{0}; z < label_text.getLength(); z++)
{
if ( (z == hotkeypos) && flags.active )
{
@ -584,7 +544,7 @@ void FToggleButton::drawText ( wchar_t LabelText[]
if ( ! flags.no_underline )
setUnderline();
print ( LabelText[z] );
print ( label_text[z] );
if ( ! flags.no_underline )
unsetUnderline();
@ -592,7 +552,7 @@ void FToggleButton::drawText ( wchar_t LabelText[]
setColor (wc.label_fg, wc.label_bg);
}
else
print (LabelText[z]);
print (label_text[z]);
}
if ( isMonochron() )

View File

@ -1746,7 +1746,7 @@ charData FVTerm::getCharacter ( character_type char_type
for (auto&& win_obj : *FWidget::getWindowList())
{
bool significant_char;
bool significant_char{false};
// char_type can be "overlapped_character"
// or "covered_character"

View File

@ -1626,17 +1626,15 @@ void FWidget::hideArea (const FSize& size)
}
setColor (fg, bg);
char* blank = createBlankArray(size.getWidth());
if ( blank == 0 )
if ( size.getWidth() == 0 )
return;
for (int y{0}; y < int(size.getHeight()); y++)
{
print() << FPoint(1, 1 + y) << blank;
print() << FPoint(1, 1 + y) << FString(size.getWidth(), L' ');
}
destroyBlankArray (blank);
flush_out();
}
@ -2258,7 +2256,6 @@ void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2)
void FWidget::drawBlockShadow (int x1, int y1, int x2, int y2)
{
// non-transparent shadow
wchar_t block;
if ( ! hasShadowCharacter() )
return;
@ -2273,7 +2270,6 @@ void FWidget::drawBlockShadow (int x1, int y1, int x2, int y2)
else if ( auto p = getParentWidget() )
setColor (wcolors.shadow_fg, p->getBackgroundColor());
block = fc::FullBlock; // █
print (fc::LowerHalfBlock); // ▄
if ( isWindowWidget() )
@ -2281,7 +2277,7 @@ void FWidget::drawBlockShadow (int x1, int y1, int x2, int y2)
for (std::size_t y{1}; y < getHeight(); y++)
{
print() << FPoint(x2 + 1, y1 + int(y)) << block; // █
print() << FPoint(x2 + 1, y1 + int(y)) << fc::FullBlock; // █
}
print() << FPoint(x1 + 1, y2 + 1);
@ -2309,38 +2305,12 @@ void FWidget::setColorTheme()
// non-member functions
//----------------------------------------------------------------------
char* createBlankArray (std::size_t size)
{
char* blank;
if ( size == 0 )
return 0;
try
{
blank = new char[size + 1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return 0;
}
std::memset(blank, ' ', size);
blank[size] = '\0';
return blank;
}
//----------------------------------------------------------------------
void destroyBlankArray (char blank[])
{
delete[] blank;
}
//----------------------------------------------------------------------
FKey getHotkey (const FString& text)
{
// Returns the hotkey character from a string
// e.g. "E&xit" returns 'x'
if ( text.isEmpty() )
return 0;
@ -2362,34 +2332,64 @@ FKey getHotkey (const FString& text)
}
//----------------------------------------------------------------------
std::size_t getHotkeyPos (wchar_t src[], wchar_t dest[], std::size_t length)
std::size_t getHotkeyPos (const FString& src, FString& dest)
{
// Find hotkey position in string
// + generate a new string without the '&'-sign
const wchar_t* txt = src;
constexpr std::size_t NOT_SET = static_cast<std::size_t>(-1);
std::size_t hotkeypos{NOT_SET};
std::size_t i{0};
for (std::size_t i{0}; i < length; i++)
{
if ( txt[i] == L'&' && hotkeypos == NOT_SET )
for (auto&& ch : src)
{
if ( ch == L'&' && hotkeypos == NOT_SET && src.getLength() != i + 1 )
hotkeypos = i;
i++;
src++;
}
else
dest += ch;
*dest++ = *src++;
i++;
}
return hotkeypos;
}
//----------------------------------------------------------------------
void setHotkeyViaString (FWidget* w, const FString& text)
{
// Set hotkey accelerator via string
if ( ! w )
return;
FKey hotkey = getHotkey(text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
w->addAccelerator (FKey(std::tolower(int(hotkey))));
w->addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
w->addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
w->addAccelerator (hotkey);
}
else
w->delAccelerator();
}
//----------------------------------------------------------------------
inline void drawBox (FWidget* w, const FRect& r)
{
// Use box-drawing characters to draw a border
if ( ! w )
return;
w->print() << r.getUpperLeftPos() << fc::BoxDrawingsDownAndRight; // ┌
for (int x = r.getX1() + 1; x < r.getX2(); x++)

View File

@ -149,7 +149,7 @@ class FButton : public FWidget
void drawMarginLeft();
void drawMarginRight();
void drawTopBottomBackground();
void drawButtonTextLine (wchar_t[]);
void drawButtonTextLine (const FString&);
void draw() override;
void updateStatusBar();
void updateButtonColor();

View File

@ -131,7 +131,7 @@ class FButtonGroup : public FScrollView
// Methods
void init();
void drawText (wchar_t[], std::size_t, std::size_t);
void drawText (const FString&, std::size_t);
void directFocus();
// Callback method

View File

@ -146,14 +146,16 @@ class FLabel : public FWidget
void draw() override;
void drawMultiLine();
void drawSingleLine();
void printLine ( wchar_t[], std::size_t, std::size_t
, std::size_t, std::size_t = 0 );
void printLine (FString&&);
// Data members
FStringList multiline_text{};
FString text{};
FWidget* accel_widget{nullptr};
fc::text_alignment alignment{fc::alignLeft};
std::size_t align_offset{0};
std::size_t hotkeypos{NOT_SET};
std::size_t column_width{0};
FColor emphasis_color{getFWidgetColors().label_emphasis_fg};
FColor ellipsis_color{getFWidgetColors().label_ellipsis_fg};
bool multiline{false};

View File

@ -56,8 +56,10 @@ e Copyright 2014-2019 Markus Gans *
#include <memory>
#include <vector>
#include "final/fscrollbar.h"
#include "final/fwidget.h"
namespace finalcut
{
@ -236,10 +238,6 @@ class FListBox : public FWidget
void adjustSize() override;
private:
// Typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
typedef void (FListBox::*FListBoxCallback)(FWidget*, FDataPtr);
// Enumeration
enum convert_type
{
@ -257,9 +255,6 @@ class FListBox : public FWidget
// Methods
void init();
void initScrollbar ( FScrollbarPtr&
, fc::orientation
, FListBoxCallback );
void draw() override;
void drawBorder() override;
void drawScrollbars();

View File

@ -57,6 +57,7 @@
#include <stack>
#include <vector>
#include "final/fscrollbar.h"
#include "final/ftermbuffer.h"
#include "final/fwidget.h"
@ -77,10 +78,10 @@ class FListViewItem : public FObject
public:
// Constructor
FListViewItem (const FListViewItem&); // copy constructor
explicit FListViewItem (FObjectIterator);
explicit FListViewItem (iterator);
FListViewItem ( const FStringList&
, FDataPtr
, FObjectIterator );
, iterator );
// Destructor
virtual ~FListViewItem();
@ -107,8 +108,8 @@ class FListViewItem : public FObject
bool isExpand() const;
// Methods
FObjectIterator insert (FListViewItem*);
FObjectIterator insert (FListViewItem*, FObjectIterator);
iterator insert (FListViewItem*);
iterator insert (FListViewItem*, iterator);
void expand();
void collapse();
@ -120,7 +121,7 @@ class FListViewItem : public FObject
// Methods
template <typename Compare>
void sort (Compare);
FObjectIterator appendItem (FListViewItem*);
iterator appendItem (FListViewItem*);
void replaceControlCodes();
std::size_t getVisibleLines();
void resetVisibleLineCounter();
@ -128,7 +129,7 @@ class FListViewItem : public FObject
// Data members
FStringList column_list{};
FDataPtr data_pointer{nullptr};
FObjectIterator root{};
iterator root{};
std::size_t visible_lines{1};
bool expandable{false};
bool is_expand{false};
@ -188,12 +189,12 @@ class FListViewIterator
public:
// Typedefs
typedef std::list<FObject*> FObjectList;
typedef FObjectList::iterator FObjectIterator;
typedef std::stack<FObjectIterator> FObjectIteratorStack;
typedef FObjectList::iterator iterator;
typedef std::stack<iterator> iterator_stack;
// Constructor
FListViewIterator () = default;
FListViewIterator (FObjectIterator);
FListViewIterator (iterator);
// Overloaded operators
FListViewIterator& operator ++ (); // prefix
@ -216,12 +217,12 @@ class FListViewIterator
private:
// Methods
void nextElement (FObjectIterator&);
void prevElement (FObjectIterator&);
void nextElement (iterator&);
void prevElement (iterator&);
// Data members
FObjectIteratorStack iter_path{};
FObjectIterator node{};
iterator_stack iter_path{};
iterator node{};
int position{0};
};
@ -251,6 +252,7 @@ inline const char* FListViewIterator::getClassName() const
inline int FListViewIterator::getPosition() const
{ return position; }
//----------------------------------------------------------------------
// class FListView
//----------------------------------------------------------------------
@ -304,38 +306,38 @@ class FListView : public FWidget
// Methods
virtual int addColumn (const FString&, int = USE_MAX_SIZE);
void hide() override;
FObjectIterator insert (FListViewItem*);
FObjectIterator insert (FListViewItem*, FObjectIterator);
FObjectIterator insert ( const FStringList&
iterator insert (FListViewItem*);
iterator insert (FListViewItem*, iterator);
iterator insert ( const FStringList&
, FDataPtr = nullptr );
FObjectIterator insert ( const FStringList&
, FObjectIterator );
FObjectIterator insert ( const FStringList&
iterator insert ( const FStringList&
, iterator );
iterator insert ( const FStringList&
, FDataPtr
, FObjectIterator );
, iterator );
template <typename T>
FObjectIterator insert ( const std::initializer_list<T>&
iterator insert ( const std::initializer_list<T>&
, FDataPtr = nullptr );
template <typename T>
FObjectIterator insert ( const std::initializer_list<T>&
, FObjectIterator );
iterator insert ( const std::initializer_list<T>&
, iterator );
template <typename T>
FObjectIterator insert ( const std::initializer_list<T>&
iterator insert ( const std::initializer_list<T>&
, FDataPtr
, FObjectIterator );
, iterator );
template <typename ColT>
FObjectIterator insert ( const std::vector<ColT>&
iterator insert ( const std::vector<ColT>&
, FDataPtr = nullptr );
template <typename ColT>
FObjectIterator insert ( const std::vector<ColT>&
, FObjectIterator );
iterator insert ( const std::vector<ColT>&
, iterator );
template <typename ColT>
FObjectIterator insert ( const std::vector<ColT>&
iterator insert ( const std::vector<ColT>&
, FDataPtr
, FObjectIterator );
, iterator );
FObjectIterator beginOfList();
FObjectIterator endOfList();
iterator beginOfList();
iterator endOfList();
virtual void sort();
// Event handlers
@ -350,7 +352,7 @@ class FListView : public FWidget
void onFocusOut (FFocusEvent*) override;
// Data members
static FObjectIterator null_iter;
static iterator null_iter;
protected:
// Methods
@ -365,8 +367,6 @@ class FListView : public FWidget
struct Header; // forward declaration
typedef std::vector<Header> headerItems;
typedef std::vector<fc::sorting_type> sortTypes;
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
typedef void (FListView::*FListViewCallback)(FWidget*, FDataPtr);
// Constants
static constexpr int USE_MAX_SIZE = -1;
@ -377,9 +377,6 @@ class FListView : public FWidget
// Methods
void init();
void initScrollbar ( FScrollbarPtr&
, fc::orientation
, FListViewCallback );
template <typename Compare>
void sort (Compare);
std::size_t getAlignOffset ( fc::text_alignment
@ -414,7 +411,7 @@ class FListView : public FWidget
void dragUp (int);
void dragDown (int);
void stopDragScroll();
FObjectIterator appendItem (FListViewItem*);
iterator appendItem (FListViewItem*);
void processClick();
void processChanged();
void toggleCheckbox();
@ -441,7 +438,7 @@ class FListView : public FWidget
void cb_HBarChange (FWidget*, FDataPtr);
// Data members
FObjectIterator root{};
iterator root{};
FObjectList selflist{};
FObjectList itemlist{};
FListViewIterator current_iter{};
@ -537,39 +534,39 @@ inline bool FListView::unsetTreeView()
{ return setTreeView(false); }
//----------------------------------------------------------------------
inline FObject::FObjectIterator FListView::insert (FListViewItem* item)
inline FObject::iterator FListView::insert (FListViewItem* item)
{ return insert (item, root); }
//----------------------------------------------------------------------
inline FObject::FObjectIterator
inline FObject::iterator
FListView::insert (const FStringList& cols, FDataPtr d)
{ return insert (cols, d, root); }
//----------------------------------------------------------------------
inline FObject::FObjectIterator
inline FObject::iterator
FListView::insert ( const FStringList& cols
, FObjectIterator parent_iter )
, iterator parent_iter )
{ return insert (cols, 0, parent_iter); }
//----------------------------------------------------------------------
template<typename T>
inline FObject::FObjectIterator
inline FObject::iterator
FListView::insert (const std::initializer_list<T>& list, FDataPtr d)
{ return insert (list, d, root); }
//----------------------------------------------------------------------
template<typename T>
inline FObject::FObjectIterator
inline FObject::iterator
FListView::insert ( const std::initializer_list<T>& list
, FObjectIterator parent_iter )
, iterator parent_iter )
{ return insert (list, 0, parent_iter); }
//----------------------------------------------------------------------
template<typename T>
FObject::FObjectIterator
FObject::iterator
FListView::insert ( const std::initializer_list<T>& list
, FDataPtr d
, FObjectIterator parent_iter )
, iterator parent_iter )
{
FStringList str_cols;
@ -589,23 +586,23 @@ FObject::FObjectIterator
//----------------------------------------------------------------------
template <typename ColT>
inline FObject::FObjectIterator
inline FObject::iterator
FListView::insert (const std::vector<ColT>& cols, FDataPtr d)
{ return insert (cols, d, root); }
//----------------------------------------------------------------------
template <typename ColT>
inline FObject::FObjectIterator
inline FObject::iterator
FListView::insert ( const std::vector<ColT>& cols
, FObjectIterator parent_iter )
, iterator parent_iter )
{ return insert (cols, 0, parent_iter); }
//----------------------------------------------------------------------
template <typename ColT>
FObject::FObjectIterator
FObject::iterator
FListView::insert ( const std::vector<ColT>& cols
, FDataPtr d
, FObjectIterator parent_iter )
, iterator parent_iter )
{
FStringList str_cols;
@ -624,11 +621,11 @@ FObject::FObjectIterator
}
//----------------------------------------------------------------------
inline FObject::FObjectIterator FListView::beginOfList()
inline FObject::iterator FListView::beginOfList()
{ return itemlist.begin(); }
//----------------------------------------------------------------------
inline FObject::FObjectIterator FListView::endOfList()
inline FObject::iterator FListView::endOfList()
{ return itemlist.end(); }
//----------------------------------------------------------------------

View File

@ -147,8 +147,7 @@ class FMenu : public FWindow, public FMenuList
typedef struct
{
wchar_t* text;
std::size_t length;
FString text;
std::size_t hotkeypos;
bool no_underline;
} menuText;

View File

@ -112,8 +112,7 @@ class FMenuBar : public FWindow, public FMenuList
// Typedef
typedef struct
{
wchar_t* text;
std::size_t length;
FString text;
std::size_t startpos;
std::size_t hotkeypos;
bool no_underline;

View File

@ -233,7 +233,7 @@ int FMessageBox::error ( FWidget* parent
mbox.beep();
mbox.setHeadline("Warning:");
mbox.setCenterText();
const FWidgetColors& wc = mbox.getFWidgetColors();
const auto& wc = mbox.getFWidgetColors();
mbox.setForegroundColor(wc.error_box_fg);
mbox.setBackgroundColor(wc.error_box_bg);
mbox.emphasis_color = wc.error_box_emphasis_fg;

View File

@ -73,8 +73,8 @@ class FObject
public:
// Typedef
typedef std::list<FObject*> FObjectList;
typedef FObjectList::iterator FObjectIterator;
typedef FObjectList::const_iterator constFObjectIterator;
typedef FObjectList::iterator iterator;
typedef FObjectList::const_iterator const_iterator;
// Constructor
explicit FObject (FObject* = nullptr);
@ -95,10 +95,10 @@ class FObject
FObjectList& getChildren();
const FObjectList& getChildren() const;
int numOfChildren() const;
FObjectIterator begin();
FObjectIterator end();
constFObjectIterator begin() const;
constFObjectIterator end() const;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
// Inquiries
bool hasParent() const;
@ -185,19 +185,19 @@ inline int FObject::numOfChildren() const
{ return int(children_list.size()); }
//----------------------------------------------------------------------
inline FObject::FObjectIterator FObject::begin()
inline FObject::iterator FObject::begin()
{ return children_list.begin(); }
//----------------------------------------------------------------------
inline FObject::FObjectIterator FObject::end()
inline FObject::iterator FObject::end()
{ return children_list.end(); }
//----------------------------------------------------------------------
inline FObject::constFObjectIterator FObject::begin() const
inline FObject::const_iterator FObject::begin() const
{ return children_list.begin(); }
//----------------------------------------------------------------------
inline FObject::constFObjectIterator FObject::end() const
inline FObject::const_iterator FObject::end() const
{ return children_list.end(); }
//----------------------------------------------------------------------

View File

@ -57,6 +57,12 @@
namespace finalcut
{
// class forward declaration
class FScrollbar;
// Global typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
//----------------------------------------------------------------------
// class FScrollbar
//----------------------------------------------------------------------
@ -161,6 +167,37 @@ class FScrollbar : public FWidget
int max_color{getMaxColor()};
};
// non-member function forward declarations
//----------------------------------------------------------------------
template<typename Callback>
void initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
, FWidget* cb_instance
, Callback cb_handler )
{
try
{
bar = std::make_shared<FScrollbar>(o, cb_instance);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (cb_instance, cb_handler)
);
}
// FScrollbar inline functions
//----------------------------------------------------------------------
inline const char* FScrollbar::getClassName() const

View File

@ -153,10 +153,6 @@ class FScrollView : public FWidget
void copy2area();
private:
// Typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
typedef void (FScrollView::*FScrollViewCallback)(FWidget*, FDataPtr);
// Constants
static constexpr int vertical_border_spacing = 2;
static constexpr int horizontal_border_spacing = 2;
@ -166,9 +162,10 @@ class FScrollView : public FWidget
// Methods
void init (FWidget*);
template<typename Callback>
void initScrollbar ( FScrollbarPtr&
, fc::orientation
, FScrollViewCallback );
, Callback );
void calculateScrollbarPos();
void setHorizontalScrollBarVisibility();
void setVerticalScrollBarVisibility();
@ -270,6 +267,17 @@ inline void FScrollView::print (const FPoint& pos)
setPrintPos(pos);
}
//----------------------------------------------------------------------
template<typename Callback>
inline void FScrollView::initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
, Callback cb_handler )
{
finalcut::initScrollbar (bar, o, this, cb_handler);
term_area* area = getPrintArea();
bar->setPrintArea(area);
}
} // namespace finalcut
#endif // FSCROLLVIEW_H

View File

@ -76,14 +76,14 @@ class FTermXTerminal final
// Accessors
const char* getClassName() const;
static fc::xtermCursorStyle getCursorStyle();
static const FString* getFont();
static const FString* getTitle();
static const FString* getForeground();
static const FString* getBackground();
static const FString* getCursorColor();
static const FString* getMouseForeground();
static const FString* getMouseBackground();
static const FString* getHighlightBackground();
static const FString getFont();
static const FString getTitle();
static const FString getForeground();
static const FString getBackground();
static const FString getCursorColor();
static const FString getMouseForeground();
static const FString getMouseBackground();
static const FString getHighlightBackground();
// Inquiries
static bool hasFont();
@ -128,8 +128,8 @@ class FTermXTerminal final
static bool canResetColor();
static void oscPrefix();
static void oscPostfix();
static const FString* captureXTermFont();
static const FString* captureXTermTitle();
static const FString captureXTermFont();
static const FString captureXTermTitle();
static void enableXTermMouse();
static void disableXTermMouse();
static void enableXTermMetaSendsESC();
@ -141,14 +141,14 @@ class FTermXTerminal final
static bool xterm_default_colors;
static std::size_t term_width;
static std::size_t term_height;
static const FString* xterm_font;
static const FString* xterm_title;
static const FString* foreground_color;
static const FString* background_color;
static const FString* cursor_color;
static const FString* mouse_foreground_color;
static const FString* mouse_background_color;
static const FString* highlight_background_color;
static FString xterm_font;
static FString xterm_title;
static FString foreground_color;
static FString background_color;
static FString cursor_color;
static FString mouse_foreground_color;
static FString mouse_background_color;
static FString highlight_background_color;
static FSystem* fsystem;
static FTermDetection* term_detection;
static fc::xtermCursorStyle cursor_style;
@ -169,44 +169,44 @@ inline fc::xtermCursorStyle FTermXTerminal::getCursorStyle()
{ return cursor_style; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getFont()
inline const FString FTermXTerminal::getFont()
{ return xterm_font; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getTitle()
inline const FString FTermXTerminal::getTitle()
{ return xterm_title; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getForeground()
inline const FString FTermXTerminal::getForeground()
{ return foreground_color; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getBackground()
inline const FString FTermXTerminal::getBackground()
{ return background_color; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getCursorColor()
inline const FString FTermXTerminal::getCursorColor()
{ return cursor_color; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getMouseForeground()
inline const FString FTermXTerminal::getMouseForeground()
{ return mouse_foreground_color; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getMouseBackground()
inline const FString FTermXTerminal::getMouseBackground()
{ return mouse_background_color; }
//----------------------------------------------------------------------
inline const FString* FTermXTerminal::getHighlightBackground()
inline const FString FTermXTerminal::getHighlightBackground()
{ return highlight_background_color; }
//----------------------------------------------------------------------
inline bool FTermXTerminal::hasFont()
{ return bool(xterm_font && xterm_font->getLength() > 2); }
{ return bool(xterm_font.getLength() > 2); }
//----------------------------------------------------------------------
inline bool FTermXTerminal::hasTitle()
{ return bool(xterm_title && xterm_title->getLength() > 0); }
{ return bool(xterm_title.getLength() > 0); }
//----------------------------------------------------------------------
inline void FTermXTerminal::setMouseSupport()

View File

@ -136,10 +136,6 @@ class FTextView : public FWidget
void adjustSize() override;
private:
// Typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
typedef void (FTextView::*FTextViewCallback)(FWidget*, FDataPtr);
// Accessors
std::size_t getTextHeight();
std::size_t getTextWidth();
@ -150,12 +146,11 @@ class FTextView : public FWidget
// Methods
void init();
void initScrollbar ( FScrollbarPtr&
, fc::orientation
, FTextViewCallback );
void draw() override;
void drawBorder() override;
void drawScrollbars();
void drawText();
bool useFDialogBorder();
bool isPrintable (wchar_t);
void processChanged();

View File

@ -151,7 +151,7 @@ class FToggleButton : public FWidget
// Methods
void init();
void drawText (wchar_t[], std::size_t , std::size_t);
void drawText (FString&&, std::size_t);
// Friend classes
friend class FButtonGroup;

View File

@ -525,10 +525,9 @@ class FWidget : public FVTerm, public FObject
// non-member function forward declarations
//----------------------------------------------------------------------
char* createBlankArray (std::size_t);
void destroyBlankArray (char[]);
FKey getHotkey (const FString&);
std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t);
std::size_t getHotkeyPos (const FString& src, FString& dest);
void setHotkeyViaString (FWidget*, const FString&);
void drawBorder (FWidget*, FRect);
// FWidget inline functions

View File

@ -388,7 +388,7 @@ void FObjectTest::iteratorTest()
CPPUNIT_ASSERT ( child2->getParent() == obj );
CPPUNIT_ASSERT ( child3->getParent() == obj );
finalcut::FObject::constFObjectIterator c_iter, c_last;
finalcut::FObject::const_iterator c_iter, c_last;
c_iter = obj->begin();
c_last = obj->end();
int i = 0;
@ -402,7 +402,7 @@ void FObjectTest::iteratorTest()
CPPUNIT_ASSERT ( obj->numOfChildren() == i );
CPPUNIT_ASSERT ( i == 3 );
finalcut::FObject::FObjectIterator iter, last;
finalcut::FObject::iterator iter, last;
iter = obj->begin();
last = obj->end();
i = 0;