Refactoring of some functions

This commit is contained in:
Markus Gans 2018-02-04 19:42:30 +01:00
parent 2ef3d84829
commit d1083b6a95
7 changed files with 220 additions and 162 deletions

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2017 Markus Gans *
* Copyright 2017-2018 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -49,6 +49,9 @@ class Listview : public FDialog
// Disable assignment operator (=)
Listview& operator = (const Listview&);
// Method
void populate (FListView*);
// Event handlers
void onClose (FCloseEvent*);
@ -78,6 +81,34 @@ Listview::Listview (FWidget* parent)
listView->setColumnAlignment (5, fc::alignRight);
// Populate FListView with a list of items
populate (listView);
// Quit button
FButton* Quit = new FButton (this);
Quit->setGeometry(24, 16, 10, 1);
Quit->setText (L"&Quit");
// Add some function callbacks
Quit->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &FApplication::cb_exitApp)
);
listView->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &Listview::cb_showInMessagebox)
);
}
//----------------------------------------------------------------------
Listview::~Listview() // destructor
{ }
//----------------------------------------------------------------------
void Listview::populate (FListView* listView)
{
std::string weather[][5] =
{
{ "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" },
@ -130,30 +161,8 @@ Listview::Listview (FWidget* parent)
FStringList line (&weather[i][0], &weather[i][0] + 5);
listView->insert (line);
}
// Quit button
FButton* Quit = new FButton (this);
Quit->setGeometry(24, 16, 10, 1);
Quit->setText (L"&Quit");
// Add some function callbacks
Quit->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &FApplication::cb_exitApp)
);
listView->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &Listview::cb_showInMessagebox)
);
}
//----------------------------------------------------------------------
Listview::~Listview() // destructor
{ }
//----------------------------------------------------------------------
void Listview::onClose (FCloseEvent* ev)
{

View File

@ -52,7 +52,7 @@ class Treeview : public FDialog
// Disable assignment operator (=)
Treeview& operator = (const Treeview&);
// Method
// Methods
void adjustSize();
TreeItem* getAfrica();
TreeItem* getAsia();

View File

@ -518,11 +518,16 @@ class FTerm
static void restoreColorPalette();
static void enableMouse();
static void disableMouse();
static void useAlternateScreenBuffer();
static void useNormalScreenBuffer();
static void captureXTermFontAndTitle();
void allocationValues();
void deallocationValues();
void init();
void initOSspecifics();
void finish();
void finishOSspecifics1();
void finishOSspecifics2();
static uInt cp437_to_unicode (uChar);
static int getMouseProtocolKey (char[]);
static int getTermcapKey (char[], int);

View File

@ -300,6 +300,9 @@ class FVTerm : public FTerm
static void removeArea (term_area*&);
static void restoreVTerm (const FRect&);
static void restoreVTerm (int, int, int, int);
static void setTextToDefault (term_area*, int, int);
static bool reallocateTextArea (term_area*, int, int);
static bool reallocateTextArea (term_area*, int);
static covered_state isCovered ( const FPoint&
, term_area* );

View File

@ -7,6 +7,7 @@ then
PROG="../examples/.libs/ui"
else
PROG="$1"
shift
fi
# Is the file executable?

View File

@ -4287,6 +4287,48 @@ void FTerm::disableMouse()
mouse->disable();
}
//----------------------------------------------------------------------
void FTerm::useAlternateScreenBuffer()
{
if ( ! use_alternate_screen )
return;
// Save current cursor position
if ( TCAP(fc::t_save_cursor) )
{
putstring (TCAP(fc::t_save_cursor));
std::fflush(stdout);
}
// Saves the screen and the cursor position
if ( TCAP(fc::t_enter_ca_mode) )
{
putstring (TCAP(fc::t_enter_ca_mode));
std::fflush(stdout);
}
}
//----------------------------------------------------------------------
void FTerm::useNormalScreenBuffer()
{
if ( ! use_alternate_screen )
return;
// restores the screen and the cursor position
if ( TCAP(fc::t_exit_ca_mode) )
{
putstring (TCAP(fc::t_exit_ca_mode));
std::fflush(stdout);
}
// restore cursor to position of last save_cursor
if ( TCAP(fc::t_restore_cursor) )
{
putstring (TCAP(fc::t_restore_cursor));
std::fflush(stdout);
}
}
//----------------------------------------------------------------------
void FTerm::captureXTermFontAndTitle()
{
@ -4381,26 +4423,7 @@ void FTerm::init()
if ( ttyname_r(stdout_no, term_name, sizeof(term_name)) )
term_name[0] = '\0';
#if defined(__linux__)
// initialize Linux console
initLinuxConsole();
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
// Initialize BSD console
initFreeBSDConsole();
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
// Initialize wscons console
initWSConsConsole();
#endif
initOSspecifics();
// Save termios settings
storeTTYsettings();
@ -4449,22 +4472,7 @@ void FTerm::init()
std::fflush(stdout);
}
if ( use_alternate_screen )
{
// Save current cursor position
if ( TCAP(fc::t_save_cursor) )
{
putstring (TCAP(fc::t_save_cursor));
std::fflush(stdout);
}
// Saves the screen and the cursor position
if ( TCAP(fc::t_enter_ca_mode) )
{
putstring (TCAP(fc::t_enter_ca_mode));
std::fflush(stdout);
}
}
useAlternateScreenBuffer();
// Enable alternate charset
if ( TCAP(fc::t_enable_acs) )
@ -4512,6 +4520,25 @@ void FTerm::init()
term_initialized = true;
}
//----------------------------------------------------------------------
void FTerm::initOSspecifics()
{
#if defined(__linux__)
// initialize Linux console
initLinuxConsole();
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
// Initialize BSD console
initFreeBSDConsole();
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
// Initialize wscons console
initWSConsConsole();
#endif
}
//----------------------------------------------------------------------
void FTerm::finish()
{
@ -4555,6 +4582,36 @@ void FTerm::finish()
std::fflush(stdout);
}
finishOSspecifics1();
if ( kde_konsole )
setKDECursor(fc::BlockCursor);
resetBeep();
// Disable the terminal mouse support
disableMouse();
// Deactivate meta key sends escape
if ( xterm_terminal )
xtermMetaSendsESC(false);
useNormalScreenBuffer();
// leave 'keyboard_transmit' mode
if ( TCAP(fc::t_keypad_local) )
{
putstring (TCAP(fc::t_keypad_local));
std::fflush(stdout);
}
finishOSspecifics2();
deallocationValues();
}
//----------------------------------------------------------------------
void FTerm::finishOSspecifics1()
{
#if defined(__linux__)
if ( linux_terminal )
{
@ -4573,43 +4630,11 @@ void FTerm::finish()
#if defined(__NetBSD__) || defined(__OpenBSD__)
resetWSConsEncoding();
#endif
if ( kde_konsole )
setKDECursor(fc::BlockCursor);
resetBeep();
// Disable the terminal mouse support
disableMouse();
// Deactivate meta key sends escape
if ( xterm_terminal )
xtermMetaSendsESC(false);
if ( use_alternate_screen )
{
// restores the screen and the cursor position
if ( TCAP(fc::t_exit_ca_mode) )
{
putstring (TCAP(fc::t_exit_ca_mode));
std::fflush(stdout);
}
// restore cursor to position of last save_cursor
if ( TCAP(fc::t_restore_cursor) )
//----------------------------------------------------------------------
void FTerm::finishOSspecifics2()
{
putstring (TCAP(fc::t_restore_cursor));
std::fflush(stdout);
}
}
// leave 'keyboard_transmit' mode
if ( TCAP(fc::t_keypad_local) )
{
putstring (TCAP(fc::t_keypad_local));
std::fflush(stdout);
}
#if defined(__linux__)
if ( linux_terminal && utf8_console )
setUTF8(true);
@ -4625,8 +4650,6 @@ void FTerm::finish()
delete[] screen_unicode_map.entries;
}
#endif
deallocationValues();
}
//----------------------------------------------------------------------

View File

@ -832,8 +832,7 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
assert ( rsw >= 0 );
assert ( bsh >= 0 );
int area_size;
char_data default_char;
line_changes unchanged;
bool realloc_success = false;
if ( ! area )
return;
@ -856,41 +855,18 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
if ( area->height + area->bottom_shadow != height + bsh )
{
if ( area->changes != 0 )
delete[] area->changes;
if ( area->text != 0 )
delete[] area->text;
try
{
area->changes = new line_changes[height + bsh];
area->text = new char_data[area_size];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
realloc_success = reallocateTextArea (area, height + bsh, area_size);
}
else if ( area->width + area->right_shadow != width + rsw )
{
if ( area->text != 0 )
delete[] area->text;
try
{
area->text = new char_data[area_size];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
realloc_success = reallocateTextArea (area, area_size);
}
else
return;
if ( ! realloc_success )
return;
area->offset_left = offset_left;
area->offset_top = offset_top;
area->width = width;
@ -899,6 +875,18 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
area->bottom_shadow = bsh;
area->has_changes = false;
setTextToDefault (area, width + rsw, height + bsh);
}
//----------------------------------------------------------------------
inline void FVTerm::setTextToDefault ( term_area* area
, int width
, int height )
{
char_data default_char;
line_changes unchanged;
int size = width * height;
default_char.code = ' ';
default_char.fg_color = fc::Default;
default_char.bg_color = fc::Default;
@ -906,13 +894,57 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
default_char.attr.byte[1] = 0;
default_char.attr.byte[2] = 0;
std::fill_n (area->text, area_size, default_char);
std::fill_n (area->text, size, default_char);
unchanged.xmin = uInt(width + rsw);
unchanged.xmin = uInt(width);
unchanged.xmax = 0;
unchanged.trans_count = 0;
std::fill_n (area->changes, height + bsh, unchanged);
std::fill_n (area->changes, height, unchanged);
}
//----------------------------------------------------------------------
inline bool FVTerm::reallocateTextArea ( term_area* area
, int height
, int size )
{
if ( area->changes != 0 )
delete[] area->changes;
if ( area->text != 0 )
delete[] area->text;
try
{
area->changes = new line_changes[height];
area->text = new char_data[size];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return false;
}
return true;
}
//----------------------------------------------------------------------
inline bool FVTerm::reallocateTextArea (term_area* area, int size)
{
if ( area->text != 0 )
delete[] area->text;
try
{
area->text = new char_data[size];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return false;
}
return true;
}
//----------------------------------------------------------------------
@ -2246,24 +2278,9 @@ void FVTerm::init()
term_attribute.code = '\0';
term_attribute.fg_color = fc::Default;
term_attribute.bg_color = fc::Default;
term_attribute.attr.bit.bold = \
term_attribute.attr.bit.dim = \
term_attribute.attr.bit.italic = \
term_attribute.attr.bit.underline = \
term_attribute.attr.bit.blink = \
term_attribute.attr.bit.reverse = \
term_attribute.attr.bit.standout = \
term_attribute.attr.bit.invisible = \
term_attribute.attr.bit.protect = \
term_attribute.attr.bit.crossed_out = \
term_attribute.attr.bit.dbl_underline = \
term_attribute.attr.bit.alt_charset = \
term_attribute.attr.bit.pc_charset = \
term_attribute.attr.bit.transparent = \
term_attribute.attr.bit.trans_shadow = \
term_attribute.attr.bit.inherit_bg = \
term_attribute.attr.bit.no_changes = \
term_attribute.attr.bit.printed = false;
term_attribute.attr.byte[0] = 0;
term_attribute.attr.byte[0] = 0;
term_attribute.attr.byte[0] = 0;
// next_attribute contains the state of the next printed character
std::memcpy (&next_attribute, &term_attribute, sizeof(char_data));