New method setInputType() in FLineEdit that allows to obscure password entries

This commit is contained in:
Markus Gans 2019-10-20 20:06:33 +02:00
parent 5e4a71dc0d
commit 5ceee8b4c8
12 changed files with 924 additions and 850 deletions

View File

@ -1,3 +1,8 @@
2019-10-20 Markus Gans <guru.mail@muenster.de>
* New method setInputType() in FLineEdit that allows to obscure
password entries
* FAcceleratorList reimplemented as non-pointer
2019-10-15 Markus Gans <guru.mail@muenster.de> 2019-10-15 Markus Gans <guru.mail@muenster.de>
* Version 0.6.0 * Version 0.6.0

File diff suppressed because it is too large Load Diff

View File

@ -71,25 +71,28 @@ int main (int argc, char* argv[])
// Create input fields // Create input fields
finalcut::FLineEdit name_field (&dgl); finalcut::FLineEdit name_field (&dgl);
finalcut::FLineEdit pw_field (&dgl);
finalcut::FLineEdit email_field (&dgl); finalcut::FLineEdit email_field (&dgl);
finalcut::FLineEdit org_field (&dgl);
finalcut::FLineEdit city_field (&dgl); finalcut::FLineEdit city_field (&dgl);
finalcut::FLineEdit st_field (&dgl); finalcut::FLineEdit st_field (&dgl);
finalcut::FLineEdit c_field (&dgl); finalcut::FLineEdit c_field (&dgl);
// Set input type to password
pw_field.setInputType (finalcut::FLineEdit::password);
name_field.setLabelText (L"&Name"); name_field.setLabelText (L"&Name");
pw_field.setLabelText (L"&Password");
email_field.setLabelText (L"&Email"); email_field.setLabelText (L"&Email");
org_field.setLabelText (L"Or&ganization");
city_field.setLabelText (L"&City"); city_field.setLabelText (L"&City");
st_field.setLabelText (L"&State"); st_field.setLabelText (L"&State");
c_field.setLabelText (L"&Country"); c_field.setLabelText (L"&Country");
name_field.setGeometry (FPoint(15, 1), FSize(19, 1)); name_field.setGeometry (FPoint(11, 1), FSize(23, 1));
email_field.setGeometry (FPoint(15, 3), FSize(19, 1)); pw_field.setGeometry (FPoint(11, 3), FSize(23, 1));
org_field.setGeometry (FPoint(15, 5), FSize(19, 1)); email_field.setGeometry (FPoint(11, 5), FSize(23, 1));
city_field.setGeometry (FPoint(15, 7), FSize(19, 1)); city_field.setGeometry (FPoint(11, 7), FSize(23, 1));
st_field.setGeometry (FPoint(15, 9), FSize(19, 1)); st_field.setGeometry (FPoint(11, 9), FSize(23, 1));
c_field.setGeometry (FPoint(15, 11), FSize(4, 1)); c_field.setGeometry (FPoint(11, 11), FSize(4, 1));
// Create the button group // Create the button group
finalcut::FButtonGroup radioButtonGroup ("Sex", &dgl); finalcut::FButtonGroup radioButtonGroup ("Sex", &dgl);

View File

@ -13,10 +13,13 @@ License: LGPL-3.0-or-later
Group: Development/Libraries/C and C++ Group: Development/Libraries/C and C++
URL: https://github.com/gansm/finalcut/ URL: https://github.com/gansm/finalcut/
Source: https://github.com/gansm/finalcut/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz Source: https://github.com/gansm/finalcut/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
BuildRequires: autoconf
BuildRequires: autoconf-archive
BuildRequires: automake BuildRequires: automake
BuildRequires: gcc-c++ BuildRequires: gcc-c++ >= 5.1
BuildRequires: glib2-devel BuildRequires: glib2-devel
BuildRequires: gpm-devel BuildRequires: gpm-devel
BuildRequires: gdb
BuildRequires: libtool BuildRequires: libtool
BuildRequires: ncurses-devel BuildRequires: ncurses-devel
@ -35,12 +38,13 @@ Group: Development/Libraries/C and C++
Requires: libfinal%{sover} = %{version} Requires: libfinal%{sover} = %{version}
Requires: bdftopcf Requires: bdftopcf
Requires: coreutils Requires: coreutils
Requires: gcc-c++ Requires: gcc-c++ >= 5.1
Requires: grep Requires: grep
Requires: gzip Requires: gzip
Requires: sed Requires: sed
Requires: vim Requires: vim
Provides: libfinal-devel = %{version} Provides: libfinal-devel = %{version}
Obsoletes: libfinal-devel < %{version}
Recommends: libfinal-examples = %{version} Recommends: libfinal-examples = %{version}
%description -n libfinal-devel %description -n libfinal-devel
@ -56,6 +60,8 @@ radio buttons, input lines, list boxes, status bars and so on.
Summary: Example files for the FINAL CUT library Summary: Example files for the FINAL CUT library
Group: Development/Languages/C and C++ Group: Development/Languages/C and C++
BuildArch: noarch BuildArch: noarch
Provides: libfinal-examples = %{version}
Obsoletes: libfinal-examples < %{version}
%description -n libfinal-examples %description -n libfinal-examples
FINAL CUT is a class library and widget toolkit with full mouse FINAL CUT is a class library and widget toolkit with full mouse
@ -108,8 +114,10 @@ make %{?_smp_mflags} V=1
make install libdir=%{buildroot}%{_libdir}/ \ make install libdir=%{buildroot}%{_libdir}/ \
includedir=%{buildroot}%{_includedir} \ includedir=%{buildroot}%{_includedir} \
bindir=%{buildroot}%{_bindir} \ bindir=%{buildroot}%{_bindir} \
docdir=%{buildroot}%{_docdir}/%{name}/ docdir=%{buildroot}%{_docdir}/%{name}/ \
fontdir=%{buildroot}%{_miscfontsdir}/%{name}/
mkdir -p %{buildroot}%{_docdir}/%{name}/examples mkdir -p %{buildroot}%{_docdir}/%{name}/examples
mkdir -p %{buildroot}%{_miscfontsdir}/%{name}/
cp -p examples/*.cpp %{buildroot}%{_docdir}/%{name}/examples cp -p examples/*.cpp %{buildroot}%{_docdir}/%{name}/examples
cp -p examples/Makefile.clang %{buildroot}%{_docdir}/%{name}/examples cp -p examples/Makefile.clang %{buildroot}%{_docdir}/%{name}/examples
cp -p examples/Makefile.gcc %{buildroot}%{_docdir}/%{name}/examples cp -p examples/Makefile.gcc %{buildroot}%{_docdir}/%{name}/examples

View File

@ -716,11 +716,10 @@ bool FApplication::processAccelerator (const FWidget*& widget)
bool accpt{false}; bool accpt{false};
if ( widget if ( widget
&& widget->getAcceleratorList() && ! widget->getAcceleratorList().empty() )
&& ! widget->getAcceleratorList()->empty() )
{ {
auto iter = widget->getAcceleratorList()->begin(); auto iter = widget->getAcceleratorList().begin();
auto last = widget->getAcceleratorList()->end(); auto last = widget->getAcceleratorList().end();
while ( iter != last ) while ( iter != last )
{ {

View File

@ -794,9 +794,6 @@ void FDialog::init()
old_focus->redraw(); old_focus->redraw();
} }
// Create your own accelerator list for this dialog
createWidgetAcceleratorList();
// Add the dialog menu // Add the dialog menu
initDialogMenu(); initDialogMenu();
} }

View File

@ -263,6 +263,8 @@ void FLineEdit::setText (const FString& txt)
else else
text.setString(""); text.setString("");
print_text = ( isPasswordField() ) ? getPasswordText() : text;
if ( isShown() ) if ( isShown() )
{ {
cursorEnd(); cursorEnd();
@ -276,7 +278,10 @@ void FLineEdit::setMaxLength (std::size_t max)
max_length = max; max_length = max;
if ( text.getLength() > max_length ) if ( text.getLength() > max_length )
{
text.setString(text.left(max_length)); text.setString(text.left(max_length));
print_text = ( isPasswordField() ) ? getPasswordText() : text;
}
if ( isShown() ) if ( isShown() )
{ {
@ -343,6 +348,7 @@ void FLineEdit::clear()
text_offset = 0; text_offset = 0;
char_width_offset = 0; char_width_offset = 0;
text.clear(); text.clear();
print_text.clear();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -439,7 +445,7 @@ void FLineEdit::onMouseDown (FMouseEvent* ev)
if ( mouse_x >= xmin && mouse_x <= int(getWidth()) && mouse_y == 1 ) if ( mouse_x >= xmin && mouse_x <= int(getWidth()) && mouse_y == 1 )
{ {
std::size_t len = text.getLength(); std::size_t len = print_text.getLength();
cursor_pos = clickPosToCursorPos (std::size_t(mouse_x) - 2); cursor_pos = clickPosToCursorPos (std::size_t(mouse_x) - 2);
if ( cursor_pos >= len ) if ( cursor_pos >= len )
@ -470,7 +476,7 @@ void FLineEdit::onMouseMove (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
std::size_t len = text.getLength(); std::size_t len = print_text.getLength();
int mouse_x = ev->getX(); int mouse_x = ev->getX();
int mouse_y = ev->getY(); int mouse_y = ev->getY();
@ -531,7 +537,7 @@ void FLineEdit::onMouseMove (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::onTimer (FTimerEvent*) void FLineEdit::onTimer (FTimerEvent*)
{ {
auto len = text.getLength(); auto len = print_text.getLength();
switch ( int(drag_scroll) ) switch ( int(drag_scroll) )
{ {
@ -765,20 +771,24 @@ void FLineEdit::drawInputField()
if ( isActiveFocus && getMaxColor() < 16 ) if ( isActiveFocus && getMaxColor() < 16 )
setBold(); setBold();
auto text_offset_column = getColumnWidth (text, text_offset); std::size_t text_offset_column = [&] () -> std::size_t
std::size_t start_column = text_offset_column - char_width_offset + 1; {
const FString& show_text = \ switch ( input_type )
getColumnSubString(text, start_column, getWidth() - 2); {
case FLineEdit::textfield:
return printTextField();
if ( show_text ) case FLineEdit::password:
print (show_text); return printPassword();
}
std::size_t x = getColumnWidth(show_text); return 0;
}();
while ( x + 1 < getWidth() ) while ( x_pos + 1 < getWidth() )
{ {
print (' '); print (' ');
x++; x_pos++;
} }
if ( isActiveFocus && getMaxColor() < 16 ) if ( isActiveFocus && getMaxColor() < 16 )
@ -794,26 +804,81 @@ void FLineEdit::drawInputField()
drawShadow(this); drawShadow(this);
// set the cursor to the insert pos. // set the cursor to the insert pos.
auto cursor_pos_column = getColumnWidth (text, cursor_pos); auto cursor_pos_column = getCursorColumnPos();
int xpos = int(2 + cursor_pos_column int xpos = int(2 + cursor_pos_column
- text_offset_column - text_offset_column
+ char_width_offset); + char_width_offset);
setCursorPos (FPoint(xpos, 1)); setCursorPos (FPoint(xpos, 1));
} }
//----------------------------------------------------------------------
inline std::size_t FLineEdit::printTextField()
{
std::size_t text_offset_column = getColumnWidth (print_text, text_offset);
std::size_t start_column = text_offset_column - char_width_offset + 1;
const FString& show_text = \
getColumnSubString(print_text, start_column, getWidth() - 2);
if ( ! show_text.isEmpty() )
print (show_text);
x_pos = getColumnWidth(show_text);
return text_offset_column;
}
//----------------------------------------------------------------------
inline std::size_t FLineEdit::printPassword()
{
std::size_t text_offset_column = text_offset;
FString show_text(print_text.mid(1 + text_offset, getWidth() - 2));
if ( ! show_text.isEmpty() )
print() << FString(show_text.getLength(), fc::Bullet); // •
x_pos = show_text.getLength();
return text_offset_column;
}
//----------------------------------------------------------------------
inline std::size_t FLineEdit::getCursorColumnPos()
{
switch ( input_type )
{
case FLineEdit::textfield:
return getColumnWidth (print_text, cursor_pos);
case FLineEdit::password:
return cursor_pos;
}
return 0;
}
//----------------------------------------------------------------------
inline const FString FLineEdit::getPasswordText() const
{
return FString(text.getLength(), fc::Bullet); // •
}
//----------------------------------------------------------------------
inline bool FLineEdit::isPasswordField() const
{
return bool( input_type == FLineEdit::password );
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
{ {
std::size_t input_width = getWidth() - 2; std::size_t input_width = getWidth() - 2;
std::size_t fullwidth_char_offset{0}; std::size_t fullwidth_char_offset{0};
std::size_t len = text.getLength(); std::size_t len = print_text.getLength();
if ( pos >= len ) if ( pos >= len )
pos = len - 1; pos = len - 1;
while ( pos > 0 && input_width > 0 ) while ( pos > 0 && input_width > 0 )
{ {
std::size_t char_width = getColumnWidth(text[pos]); std::size_t char_width = getColumnWidth(print_text[pos]);
if ( input_width >= char_width ) if ( input_width >= char_width )
input_width -= char_width; input_width -= char_width;
@ -825,7 +890,7 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
{ {
if ( char_width == 1 ) if ( char_width == 1 )
{ {
if ( getColumnWidth(text[pos - 1]) == 2 ) // pos is always > 0 if ( getColumnWidth(print_text[pos - 1]) == 2 ) // pos is always > 0
{ {
fullwidth_char_offset = 1; fullwidth_char_offset = 1;
break; break;
@ -850,12 +915,12 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos)
{ {
std::size_t click_width{0}; std::size_t click_width{0};
std::size_t idx = text_offset; std::size_t idx = text_offset;
std::size_t len = text.getLength(); std::size_t len = print_text.getLength();
pos -= char_width_offset; pos -= char_width_offset;
while ( click_width < pos && idx < len ) while ( click_width < pos && idx < len )
{ {
std::size_t char_width = getColumnWidth(text[idx]); std::size_t char_width = getColumnWidth(print_text[idx]);
idx++; idx++;
click_width += char_width; click_width += char_width;
@ -870,25 +935,25 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos)
void FLineEdit::adjustTextOffset() void FLineEdit::adjustTextOffset()
{ {
std::size_t input_width = getWidth() - 2; std::size_t input_width = getWidth() - 2;
std::size_t len = text.getLength(); std::size_t len = print_text.getLength();
std::size_t len_column = getColumnWidth (text); std::size_t len_column = getColumnWidth (print_text);
std::size_t text_offset_column = getColumnWidth (text, text_offset); std::size_t text_offset_column = getColumnWidth (print_text, text_offset);
std::size_t cursor_pos_column = getColumnWidth (text, cursor_pos); std::size_t cursor_pos_column = getColumnWidth (print_text, cursor_pos);
std::size_t first_char_width{0}; std::size_t first_char_width{0};
std::size_t cursor_char_width{1}; std::size_t cursor_char_width{1};
char_width_offset = 0; char_width_offset = 0;
if ( cursor_pos < len ) if ( cursor_pos < len )
cursor_char_width = getColumnWidth(text[cursor_pos]); cursor_char_width = getColumnWidth(print_text[cursor_pos]);
if ( len > 0 ) if ( len > 0 )
first_char_width = getColumnWidth(text[0]); first_char_width = getColumnWidth(print_text[0]);
// Text alignment right for long lines // Text alignment right for long lines
while ( text_offset > 0 && len_column - text_offset_column < input_width ) while ( text_offset > 0 && len_column - text_offset_column < input_width )
{ {
text_offset--; text_offset--;
text_offset_column = getColumnWidth (text, text_offset); text_offset_column = getColumnWidth (print_text, text_offset);
} }
// Right cursor overflow // Right cursor overflow
@ -897,7 +962,7 @@ void FLineEdit::adjustTextOffset()
offsetPair offset_pair = endPosToOffset(cursor_pos); offsetPair offset_pair = endPosToOffset(cursor_pos);
text_offset = offset_pair.first; text_offset = offset_pair.first;
char_width_offset = offset_pair.second; char_width_offset = offset_pair.second;
text_offset_column = getColumnWidth (text, text_offset); text_offset_column = getColumnWidth (print_text, text_offset);
} }
// Right full-width cursor overflow // Right full-width cursor overflow
@ -965,6 +1030,7 @@ inline void FLineEdit::deleteCurrentCharacter()
if ( len > 0 && cursor_pos < len ) if ( len > 0 && cursor_pos < len )
{ {
text.remove(cursor_pos, 1); text.remove(cursor_pos, 1);
print_text = ( isPasswordField() ) ? getPasswordText() : text;
processChanged(); processChanged();
} }
@ -1035,6 +1101,7 @@ inline bool FLineEdit::keyInput (FKey key)
text.setString(ch); text.setString(ch);
cursor_pos++; cursor_pos++;
print_text = ( isPasswordField() ) ? getPasswordText() : text;
adjustTextOffset(); adjustTextOffset();
processChanged(); processChanged();
return true; return true;

View File

@ -208,10 +208,10 @@ void FMenuItem::addAccelerator (FKey key, FWidget* obj)
auto root = getRootWidget(); auto root = getRootWidget();
FAccelerator accel = { key, obj }; FAccelerator accel = { key, obj };
if ( root && root->getAcceleratorList() ) if ( root )
{ {
accel_key = key; accel_key = key;
root->getAcceleratorList()->push_back(accel); root->setAcceleratorList().push_back(accel);
} }
updateSuperMenuDimensions(); updateSuperMenuDimensions();
@ -223,17 +223,16 @@ void FMenuItem::delAccelerator (FWidget* obj)
auto root = getRootWidget(); auto root = getRootWidget();
if ( root if ( root
&& root->getAcceleratorList() && ! root->getAcceleratorList().empty() )
&& ! root->getAcceleratorList()->empty() )
{ {
auto iter = root->getAcceleratorList()->begin(); auto iter = root->getAcceleratorList().begin();
while ( iter != root->getAcceleratorList()->end() ) while ( iter != root->getAcceleratorList().end() )
{ {
if ( iter->object == obj ) if ( iter->object == obj )
{ {
accel_key = 0; accel_key = 0;
iter = root->getAcceleratorList()->erase(iter); iter = root->setAcceleratorList().erase(iter);
} }
else else
++iter; ++iter;

View File

@ -124,11 +124,7 @@ FWidget::~FWidget() // destructor
quit(); quit();
} }
if ( accelerator_list ) accelerator_list.clear();
{
delete accelerator_list;
accelerator_list = nullptr;
}
// finish the program // finish the program
if ( rootObject == this ) if ( rootObject == this )
@ -929,8 +925,8 @@ void FWidget::addAccelerator (FKey key, FWidget* obj)
if ( ! widget || widget == statusbar || widget == menubar ) if ( ! widget || widget == statusbar || widget == menubar )
widget = getRootWidget(); widget = getRootWidget();
if ( widget && widget->accelerator_list ) if ( widget )
widget->accelerator_list->push_back(accel); widget->accelerator_list.push_back(accel);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -944,15 +940,14 @@ void FWidget::delAccelerator (FWidget* obj)
widget = getRootWidget(); widget = getRootWidget();
if ( widget if ( widget
&& widget->accelerator_list && ! widget->accelerator_list.empty() )
&& ! widget->accelerator_list->empty() )
{ {
auto iter = widget->accelerator_list->begin(); auto iter = widget->accelerator_list.begin();
while ( iter != widget->accelerator_list->end() ) while ( iter != widget->accelerator_list.end() )
{ {
if ( iter->object == obj ) if ( iter->object == obj )
iter = widget->accelerator_list->erase(iter); iter = widget->accelerator_list.erase(iter);
else else
++iter; ++iter;
} }
@ -1393,23 +1388,6 @@ void FWidget::hideArea (const FSize& size)
flushOutputBuffer(); flushOutputBuffer();
} }
//----------------------------------------------------------------------
void FWidget::createWidgetAcceleratorList()
{
if ( accelerator_list == 0 )
{
try
{
accelerator_list = new FAcceleratorList();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
std::abort();
}
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::focusNextChild() bool FWidget::focusNextChild()
{ {
@ -1734,9 +1712,6 @@ void FWidget::init()
foreground_color = wcolors.term_fg; foreground_color = wcolors.term_fg;
background_color = wcolors.term_bg; background_color = wcolors.term_bg;
init_desktop = false; init_desktop = false;
// Create the root object accelerator list
createWidgetAcceleratorList();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -70,11 +70,17 @@ class FLabel;
class FLineEdit : public FWidget class FLineEdit : public FWidget
{ {
public: public:
// Enumeration // Enumerations
enum label_o enum label_o
{ {
label_above = 0, label_above = 0,
label_left = 1 label_left = 1
};
enum inputType
{
textfield = 0,
password = 1
}; };
// Using-declaration // Using-declaration
@ -121,6 +127,7 @@ class FLineEdit : public FWidget
void setMaxLength (std::size_t); void setMaxLength (std::size_t);
void setCursorPosition (std::size_t); void setCursorPosition (std::size_t);
void setLabelText (const FString&); void setLabelText (const FString&);
void setInputType (const inputType);
void setLabelOrientation (const label_o); void setLabelOrientation (const label_o);
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
@ -177,6 +184,11 @@ class FLineEdit : public FWidget
bool hasHotkey(); bool hasHotkey();
void draw() override; void draw() override;
void drawInputField(); void drawInputField();
std::size_t printTextField();
std::size_t printPassword();
std::size_t getCursorColumnPos();
const FString getPasswordText() const;
bool isPasswordField() const;
offsetPair endPosToOffset (std::size_t); offsetPair endPosToOffset (std::size_t);
std::size_t clickPosToCursorPos (std::size_t); std::size_t clickPosToCursorPos (std::size_t);
void adjustTextOffset(); void adjustTextOffset();
@ -195,17 +207,20 @@ class FLineEdit : public FWidget
// Data members // Data members
FString text{""}; FString text{""};
FString print_text{""};
FString label_text{""}; FString label_text{""};
FLabel* label{}; FLabel* label{};
std::wstring input_filter{}; std::wstring input_filter{};
dragScroll drag_scroll{FLineEdit::noScroll}; dragScroll drag_scroll{FLineEdit::noScroll};
label_o label_orientation{FLineEdit::label_left}; label_o label_orientation{FLineEdit::label_left};
inputType input_type{FLineEdit::textfield};
int scroll_repeat{100}; int scroll_repeat{100};
bool scroll_timer{false}; bool scroll_timer{false};
bool insert_mode{true}; bool insert_mode{true};
std::size_t cursor_pos{NOT_SET}; std::size_t cursor_pos{NOT_SET};
std::size_t text_offset{0}; std::size_t text_offset{0};
std::size_t char_width_offset{0}; std::size_t char_width_offset{0};
std::size_t x_pos{0};
std::size_t max_length{std::numeric_limits<std::size_t>::max()}; std::size_t max_length{std::numeric_limits<std::size_t>::max()};
}; };
@ -239,6 +254,10 @@ inline void FLineEdit::setInputFilter (const FString& regex_string)
inline void FLineEdit::clearInputFilter() inline void FLineEdit::clearInputFilter()
{ input_filter.clear(); } { input_filter.clear(); }
//----------------------------------------------------------------------
inline void FLineEdit::setInputType (const inputType type)
{ input_type = type; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FLineEdit::setEnable() inline bool FLineEdit::setEnable()
{ return setEnable(true); } { return setEnable(true); }

View File

@ -36,9 +36,19 @@
#endif #endif
#if defined(__linux__) #if defined(__linux__)
#if defined(__x86_64__) || defined(__i386) || defined(__arm__)
#include <sys/io.h> // <asm/io.h> is deprecated #if defined(__arm__) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#endif // defined(__x86_64__) || defined(__i386) || defined(__arm__) // ISA sysctl support on arm processors only up to glibc-2.29
#if !__GLIBC_PREREQ(2,30)
#define ARM_ISA_SYSCTL
#endif
#endif
#if defined(__x86_64__) || defined(__i386) || defined(ARM_ISA_SYSCTL)
#define ISA_SYSCTL_SUPPORT
#include <sys/io.h>
#endif // defined(__x86_64__) || defined(__i386) || defined(ARM_ISA_SYSCTL)
#endif // defined(__linux__) #endif // defined(__linux__)
#if defined(__sun) && defined(__SVR4) #if defined(__sun) && defined(__SVR4)
@ -88,8 +98,7 @@ class FSystemImpl : public FSystem
virtual ~FSystemImpl(); virtual ~FSystemImpl();
// Methods // Methods
#if defined(__linux__) #if defined(ISA_SYSCTL_SUPPORT)
#if defined(__x86_64__) || defined(__i386) || defined(__arm__)
uChar inPortByte (uShort port) override uChar inPortByte (uShort port) override
{ {
return ::inb (port); return ::inb (port);
@ -100,16 +109,9 @@ class FSystemImpl : public FSystem
return 0; return 0;
} }
#endif #endif
#else
uChar inPortByte (uShort) override
{
return 0;
}
#endif
#if defined(__linux__) #if defined(ISA_SYSCTL_SUPPORT)
#if defined(__x86_64__) || defined(__i386) || defined(__arm__)
void outPortByte (uChar value, uShort port) override void outPortByte (uChar value, uShort port) override
{ {
::outb (value, port); ::outb (value, port);
@ -118,11 +120,6 @@ class FSystemImpl : public FSystem
void outPortByte (uChar, uShort) override void outPortByte (uChar, uShort) override
{ } { }
#endif #endif
#else
void outPortByte (uChar, uShort) override
{ }
#endif
int isTTY (int fd) override int isTTY (int fd) override
{ {

View File

@ -188,161 +188,162 @@ class FWidget : public FVTerm, public FObject
FWidget& operator = (const FWidget&) = delete; FWidget& operator = (const FWidget&) = delete;
// Accessors // Accessors
const FString getClassName() const override; const FString getClassName() const override;
FWidget* getRootWidget() const; FWidget* getRootWidget() const;
FWidget* getParentWidget() const; FWidget* getParentWidget() const;
static FWidget*& getMainWidget(); static FWidget*& getMainWidget();
static FWidget*& getActiveWindow(); static FWidget*& getActiveWindow();
static FWidget*& getFocusWidget(); static FWidget*& getFocusWidget();
static FWidget*& getClickedWidget(); static FWidget*& getClickedWidget();
static FWidget*& getOpenMenu(); static FWidget*& getOpenMenu();
static FWidget*& getMoveSizeWidget(); static FWidget*& getMoveSizeWidget();
static FWidgetList*& getWindowList(); static FWidgetList*& getWindowList();
static FMenuBar* getMenuBar(); static FMenuBar* getMenuBar();
static FStatusBar* getStatusBar(); static FStatusBar* getStatusBar();
virtual FWidget* getFirstFocusableWidget (FObjectList); virtual FWidget* getFirstFocusableWidget (FObjectList);
virtual FWidget* getLastFocusableWidget (FObjectList); virtual FWidget* getLastFocusableWidget (FObjectList);
FAcceleratorList* getAcceleratorList() const; const FAcceleratorList& getAcceleratorList() const;
FString getStatusbarMessage() const; FAcceleratorList& setAcceleratorList();
FColor getForegroundColor() const; // get the primary FString getStatusbarMessage() const;
FColor getBackgroundColor() const; // widget colors FColor getForegroundColor() const; // get the primary
std::vector<bool>& doubleFlatLine_ref (fc::sides); FColor getBackgroundColor() const; // widget colors
std::vector<bool>& doubleFlatLine_ref (fc::sides);
// Positioning and sizes accessors... // Positioning and sizes accessors...
int getX() const; int getX() const;
int getY() const; int getY() const;
const FPoint getPos() const; const FPoint getPos() const;
int getTermX() const; int getTermX() const;
int getTermY() const; int getTermY() const;
const FPoint getTermPos() const; const FPoint getTermPos() const;
std::size_t getWidth() const; std::size_t getWidth() const;
std::size_t getHeight() const; std::size_t getHeight() const;
const FSize getSize() const; const FSize getSize() const;
int getTopPadding() const; int getTopPadding() const;
int getLeftPadding() const; int getLeftPadding() const;
int getBottomPadding() const; int getBottomPadding() const;
int getRightPadding() const; int getRightPadding() const;
std::size_t getClientWidth() const; std::size_t getClientWidth() const;
std::size_t getClientHeight() const; std::size_t getClientHeight() const;
std::size_t getMaxWidth() const; std::size_t getMaxWidth() const;
std::size_t getMaxHeight() const; std::size_t getMaxHeight() const;
const FSize& getShadow() const; const FSize& getShadow() const;
const FRect& getGeometry() const; const FRect& getGeometry() const;
const FRect& getGeometryWithShadow(); const FRect& getGeometryWithShadow();
const FRect& getTermGeometry(); const FRect& getTermGeometry();
const FRect& getTermGeometryWithShadow(); const FRect& getTermGeometryWithShadow();
std::size_t getDesktopWidth(); std::size_t getDesktopWidth();
std::size_t getDesktopHeight(); std::size_t getDesktopHeight();
const FWidgetFlags& getFlags() const; const FWidgetFlags& getFlags() const;
FPoint getCursorPos(); FPoint getCursorPos();
FPoint getPrintPos(); FPoint getPrintPos();
// Mutators // Mutators
static void setMainWidget (FWidget*); static void setMainWidget (FWidget*);
static void setFocusWidget (FWidget*); static void setFocusWidget (FWidget*);
static void setClickedWidget (FWidget*); static void setClickedWidget (FWidget*);
static void setMoveSizeWidget (FWidget*); static void setMoveSizeWidget (FWidget*);
static void setActiveWindow (FWidget*); static void setActiveWindow (FWidget*);
static void setOpenMenu (FWidget*); static void setOpenMenu (FWidget*);
virtual void setStatusbarMessage (const FString&); virtual void setStatusbarMessage (const FString&);
bool setVisible (bool); bool setVisible (bool);
bool setVisible(); bool setVisible();
bool unsetVisible(); bool unsetVisible();
virtual bool setEnable (bool); virtual bool setEnable (bool);
virtual bool setEnable(); virtual bool setEnable();
virtual bool unsetEnable(); virtual bool unsetEnable();
virtual bool setDisable(); virtual bool setDisable();
virtual bool setVisibleCursor (bool); // input cursor visibility virtual bool setVisibleCursor (bool); // input cursor visibility
virtual bool setVisibleCursor(); // for the widget virtual bool setVisibleCursor(); // for the widget
virtual bool unsetVisibleCursor(); virtual bool unsetVisibleCursor();
virtual bool setFocus (bool); virtual bool setFocus (bool);
virtual bool setFocus(); virtual bool setFocus();
virtual bool unsetFocus(); virtual bool unsetFocus();
void setFocusable(); void setFocusable();
void unsetFocusable(); void unsetFocusable();
bool ignorePadding (bool); // ignore padding from bool ignorePadding (bool); // ignore padding from
bool ignorePadding(); // the parent widget bool ignorePadding(); // the parent widget
bool acceptPadding(); bool acceptPadding();
void setForegroundColor (FColor); void setForegroundColor (FColor);
void setBackgroundColor (FColor); void setBackgroundColor (FColor);
void setColor(); void setColor();
FWidgetFlags& setFlags(); FWidgetFlags& setFlags();
// Positioning and sizes mutators... // Positioning and sizes mutators...
virtual void setX (int, bool = true); virtual void setX (int, bool = true);
virtual void setY (int, bool = true); virtual void setY (int, bool = true);
virtual void setPos (const FPoint&, bool = true); virtual void setPos (const FPoint&, bool = true);
virtual void setWidth (std::size_t, bool = true); virtual void setWidth (std::size_t, bool = true);
virtual void setHeight (std::size_t, bool = true); virtual void setHeight (std::size_t, bool = true);
virtual void setSize (const FSize&, bool = true); virtual void setSize (const FSize&, bool = true);
void setTopPadding (int, bool = true); void setTopPadding (int, bool = true);
void setLeftPadding (int, bool = true); void setLeftPadding (int, bool = true);
void setBottomPadding (int, bool = true); void setBottomPadding (int, bool = true);
void setRightPadding (int, bool = true); void setRightPadding (int, bool = true);
void setParentOffset(); void setParentOffset();
void setTermOffset(); void setTermOffset();
void setTermOffsetWithPadding(); void setTermOffsetWithPadding();
void setTermSize (const FSize&); void setTermSize (const FSize&);
virtual void setGeometry (const FRect&, bool = true); virtual void setGeometry (const FRect&, bool = true);
virtual void setGeometry (const FPoint&, const FSize&, bool = true); virtual void setGeometry (const FPoint&, const FSize&, bool = true);
virtual void setShadowSize (const FSize&); virtual void setShadowSize (const FSize&);
void setMinimumWidth (std::size_t); void setMinimumWidth (std::size_t);
void setMinimumHeight (std::size_t); void setMinimumHeight (std::size_t);
void setMinimumSize (const FSize&); void setMinimumSize (const FSize&);
void setMaximumWidth (std::size_t); void setMaximumWidth (std::size_t);
void setMaximumHeight (const FSize&); void setMaximumHeight (const FSize&);
void setMaximumSize (std::size_t, std::size_t); void setMaximumSize (std::size_t, std::size_t);
void setFixedSize (const FSize&); void setFixedSize (const FSize&);
bool setCursorPos (const FPoint&); bool setCursorPos (const FPoint&);
void unsetCursorPos(); void unsetCursorPos();
void setPrintPos (const FPoint&); void setPrintPos (const FPoint&);
void setDoubleFlatLine (fc::sides, bool = true); void setDoubleFlatLine (fc::sides, bool = true);
void unsetDoubleFlatLine (fc::sides); void unsetDoubleFlatLine (fc::sides);
void setDoubleFlatLine (fc::sides, int, bool = true); void setDoubleFlatLine (fc::sides, int, bool = true);
void unsetDoubleFlatLine (fc::sides, int); void unsetDoubleFlatLine (fc::sides, int);
// Inquiries // Inquiries
bool isRootWidget() const; bool isRootWidget() const;
bool isWindowWidget() const; bool isWindowWidget() const;
bool isDialogWidget() const; bool isDialogWidget() const;
bool isMenuWidget() const; bool isMenuWidget() const;
bool isVisible() const; bool isVisible() const;
bool isShown() const; bool isShown() const;
bool isEnabled() const; bool isEnabled() const;
bool hasVisibleCursor() const; bool hasVisibleCursor() const;
bool hasFocus() const; bool hasFocus() const;
bool acceptFocus() const; // is focusable bool acceptFocus() const; // is focusable
bool isPaddingIgnored(); bool isPaddingIgnored();
// Methods // Methods
FWidget* childWidgetAt (const FPoint&); FWidget* childWidgetAt (const FPoint&);
int numOfFocusableChildren(); int numOfFocusableChildren();
virtual bool close(); virtual bool close();
void clearStatusbarMessage(); void clearStatusbarMessage();
void addCallback ( const FString& void addCallback ( const FString&
, FCallback , FCallback
, FDataPtr = nullptr ); , FDataPtr = nullptr );
void addCallback ( const FString& void addCallback ( const FString&
, FWidget* , FWidget*
, FCallback , FCallback
, FDataPtr = nullptr ); , FDataPtr = nullptr );
void delCallback (FCallback); void delCallback (FCallback);
void delCallback (FWidget*); void delCallback (FWidget*);
void delCallbacks(); void delCallbacks();
void emitCallback (const FString&); void emitCallback (const FString&);
void addAccelerator (FKey); void addAccelerator (FKey);
virtual void addAccelerator (FKey, FWidget*); virtual void addAccelerator (FKey, FWidget*);
void delAccelerator (); void delAccelerator ();
virtual void delAccelerator (FWidget*); virtual void delAccelerator (FWidget*);
virtual void redraw(); virtual void redraw();
virtual void resize(); virtual void resize();
virtual void show(); virtual void show();
virtual void hide(); virtual void hide();
virtual bool focusFirstChild(); // widget focusing virtual bool focusFirstChild(); // widget focusing
virtual bool focusLastChild(); virtual bool focusLastChild();
FPoint termToWidgetPos (const FPoint&); FPoint termToWidgetPos (const FPoint&);
void print (const FPoint&) override; void print (const FPoint&) override;
virtual void move (const FPoint&); virtual void move (const FPoint&);
virtual void drawBorder(); virtual void drawBorder();
static void quit(); static void quit();
protected: protected:
struct FCallbackData struct FCallbackData
@ -357,69 +358,68 @@ class FWidget : public FVTerm, public FObject
typedef std::vector<FCallbackData> FCallbackObjects; typedef std::vector<FCallbackData> FCallbackObjects;
// Accessor // Accessor
FTermArea* getPrintArea() override; FTermArea* getPrintArea() override;
const FWidgetColors& getFWidgetColors() const; const FWidgetColors& getFWidgetColors() const;
static uInt getModalDialogCounter(); static uInt getModalDialogCounter();
static FWidgetList*& getDialogList(); static FWidgetList*& getDialogList();
static FWidgetList*& getAlwaysOnTopList(); static FWidgetList*& getAlwaysOnTopList();
static FWidgetList*& getWidgetCloseList(); static FWidgetList*& getWidgetCloseList();
void addPreprocessingHandler (FVTerm*, FPreprocessingFunction) override; void addPreprocessingHandler (FVTerm*, FPreprocessingFunction) override;
void delPreprocessingHandler (FVTerm*) override; void delPreprocessingHandler (FVTerm*) override;
// Inquiry // Inquiry
bool isChildPrintArea() const; bool isChildPrintArea() const;
// Mutators // Mutators
virtual void setStatusBar (FStatusBar*); virtual void setStatusBar (FStatusBar*);
virtual void setMenuBar (FMenuBar*); virtual void setMenuBar (FMenuBar*);
FWidgetColors& setFWidgetColors(); FWidgetColors& setFWidgetColors();
static uInt& setModalDialogCounter(); static uInt& setModalDialogCounter();
// Methods // Methods
virtual void adjustSize(); virtual void adjustSize();
void adjustSizeGlobal(); void adjustSizeGlobal();
void hideArea (const FSize&); void hideArea (const FSize&);
void createWidgetAcceleratorList(); virtual bool focusNextChild(); // Change child...
virtual bool focusNextChild(); // Change child... virtual bool focusPrevChild(); // ...focus
virtual bool focusPrevChild(); // ...focus
// Event handlers // Event handlers
bool event (FEvent*) override; bool event (FEvent*) override;
virtual void onKeyPress (FKeyEvent*); virtual void onKeyPress (FKeyEvent*);
virtual void onKeyUp (FKeyEvent*); virtual void onKeyUp (FKeyEvent*);
virtual void onKeyDown (FKeyEvent*); virtual void onKeyDown (FKeyEvent*);
virtual void onMouseDown (FMouseEvent*); virtual void onMouseDown (FMouseEvent*);
virtual void onMouseUp (FMouseEvent*); virtual void onMouseUp (FMouseEvent*);
virtual void onMouseDoubleClick (FMouseEvent*); virtual void onMouseDoubleClick (FMouseEvent*);
virtual void onWheel (FWheelEvent*); virtual void onWheel (FWheelEvent*);
virtual void onMouseMove (FMouseEvent*); virtual void onMouseMove (FMouseEvent*);
virtual void onFocusIn (FFocusEvent*); virtual void onFocusIn (FFocusEvent*);
virtual void onFocusOut (FFocusEvent*); virtual void onFocusOut (FFocusEvent*);
virtual void onChildFocusIn (FFocusEvent*); virtual void onChildFocusIn (FFocusEvent*);
virtual void onChildFocusOut (FFocusEvent*); virtual void onChildFocusOut (FFocusEvent*);
virtual void onAccel (FAccelEvent*); virtual void onAccel (FAccelEvent*);
virtual void onResize (FResizeEvent*); virtual void onResize (FResizeEvent*);
virtual void onShow (FShowEvent*); virtual void onShow (FShowEvent*);
virtual void onHide (FHideEvent*); virtual void onHide (FHideEvent*);
virtual void onClose (FCloseEvent*); virtual void onClose (FCloseEvent*);
private: private:
// Methods // Methods
void init(); void init();
void finish(); void finish();
void insufficientSpaceAdjust(); void insufficientSpaceAdjust();
void KeyPressEvent (FKeyEvent*); void KeyPressEvent (FKeyEvent*);
void KeyDownEvent (FKeyEvent*); void KeyDownEvent (FKeyEvent*);
FCallbackPtr getCallbackPtr (FCallback); FCallbackPtr getCallbackPtr (FCallback);
bool changeFocus (FWidget*, FWidget*, fc::FocusTypes); bool changeFocus (FWidget*, FWidget*, fc::FocusTypes);
void processDestroy(); void processDestroy();
virtual void draw(); virtual void draw();
void drawWindows(); void drawWindows();
void drawChildren(); void drawChildren();
static void setColorTheme(); static void setColorTheme();
// Data members // Data members
FPoint widget_cursor_position{-1, -1}; FPoint widget_cursor_position{-1, -1};
struct widget_size_hints struct widget_size_hints
{ {
@ -466,47 +466,47 @@ class FWidget : public FVTerm, public FObject
int right{0}; int right{0};
} padding{}; } padding{};
struct FWidgetFlags flags{}; struct FWidgetFlags flags{};
bool ignore_padding{false}; bool ignore_padding{false};
// widget size // widget size
FRect wsize{1, 1, 1, 1}; FRect wsize{1, 1, 1, 1};
FRect adjust_wsize{1, 1, 1, 1}; FRect adjust_wsize{1, 1, 1, 1};
FRect adjust_wsize_term{}; FRect adjust_wsize_term{};
FRect adjust_wsize_shadow{}; FRect adjust_wsize_shadow{};
FRect adjust_wsize_term_shadow{}; FRect adjust_wsize_term_shadow{};
// widget offset // widget offset
FRect woffset{}; FRect woffset{};
// offset of the widget client area // offset of the widget client area
FRect wclient_offset{}; FRect wclient_offset{};
// widget shadow size (on the right and bottom side) // widget shadow size (on the right and bottom side)
FSize wshadow{0, 0}; FSize wshadow{0, 0};
// default widget foreground and background color // default widget foreground and background color
FColor foreground_color{fc::Default}; FColor foreground_color{fc::Default};
FColor background_color{fc::Default}; FColor background_color{fc::Default};
FString statusbar_message{}; FString statusbar_message{};
FAcceleratorList* accelerator_list{nullptr}; FAcceleratorList accelerator_list{};
FCallbackObjects callback_objects{}; FCallbackObjects callback_objects{};
static FStatusBar* statusbar; static FStatusBar* statusbar;
static FMenuBar* menubar; static FMenuBar* menubar;
static FWidget* main_widget; static FWidget* main_widget;
static FWidget* active_window; static FWidget* active_window;
static FWidget* focus_widget; static FWidget* focus_widget;
static FWidget* clicked_widget; static FWidget* clicked_widget;
static FWidget* open_menu; static FWidget* open_menu;
static FWidget* move_size_widget; static FWidget* move_size_widget;
static FWidget* show_root_widget; static FWidget* show_root_widget;
static FWidget* redraw_root_widget; static FWidget* redraw_root_widget;
static FWidgetList* window_list; static FWidgetList* window_list;
static FWidgetList* dialog_list; static FWidgetList* dialog_list;
static FWidgetList* always_on_top_list; static FWidgetList* always_on_top_list;
static FWidgetList* close_widget; static FWidgetList* close_widget;
static FWidgetColors wcolors; static FWidgetColors wcolors;
static uInt modal_dialog_counter; static uInt modal_dialog_counter;
static bool init_desktop; static bool init_desktop;
static bool hideable; static bool hideable;
// Friend classes // Friend classes
friend class FToggleButton; friend class FToggleButton;
@ -583,7 +583,11 @@ inline FStatusBar* FWidget::getStatusBar()
{ return statusbar; } { return statusbar; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FWidget::FAcceleratorList* FWidget::getAcceleratorList() const inline const FWidget::FAcceleratorList& FWidget::getAcceleratorList() const
{ return accelerator_list; }
//----------------------------------------------------------------------
inline FWidget::FAcceleratorList& FWidget::setAcceleratorList()
{ return accelerator_list; } { return accelerator_list; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------