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 * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -49,6 +49,9 @@ class Listview : public FDialog
// Disable assignment operator (=) // Disable assignment operator (=)
Listview& operator = (const Listview&); Listview& operator = (const Listview&);
// Method
void populate (FListView*);
// Event handlers // Event handlers
void onClose (FCloseEvent*); void onClose (FCloseEvent*);
@ -78,6 +81,34 @@ Listview::Listview (FWidget* parent)
listView->setColumnAlignment (5, fc::alignRight); listView->setColumnAlignment (5, fc::alignRight);
// Populate FListView with a list of items // 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] = std::string weather[][5] =
{ {
{ "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" }, { "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); FStringList line (&weather[i][0], &weather[i][0] + 5);
listView->insert (line); 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) void Listview::onClose (FCloseEvent* ev)
{ {

View File

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

View File

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

View File

@ -300,6 +300,9 @@ class FVTerm : public FTerm
static void removeArea (term_area*&); static void removeArea (term_area*&);
static void restoreVTerm (const FRect&); static void restoreVTerm (const FRect&);
static void restoreVTerm (int, int, int, int); 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& static covered_state isCovered ( const FPoint&
, term_area* ); , term_area* );

View File

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

View File

@ -4287,6 +4287,48 @@ void FTerm::disableMouse()
mouse->disable(); 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() void FTerm::captureXTermFontAndTitle()
{ {
@ -4381,26 +4423,7 @@ void FTerm::init()
if ( ttyname_r(stdout_no, term_name, sizeof(term_name)) ) if ( ttyname_r(stdout_no, term_name, sizeof(term_name)) )
term_name[0] = '\0'; term_name[0] = '\0';
#if defined(__linux__) initOSspecifics();
// 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
// Save termios settings // Save termios settings
storeTTYsettings(); storeTTYsettings();
@ -4449,22 +4472,7 @@ void FTerm::init()
std::fflush(stdout); std::fflush(stdout);
} }
if ( use_alternate_screen ) useAlternateScreenBuffer();
{
// 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);
}
}
// Enable alternate charset // Enable alternate charset
if ( TCAP(fc::t_enable_acs) ) if ( TCAP(fc::t_enable_acs) )
@ -4512,6 +4520,25 @@ void FTerm::init()
term_initialized = true; 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() void FTerm::finish()
{ {
@ -4555,6 +4582,36 @@ void FTerm::finish()
std::fflush(stdout); 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 defined(__linux__)
if ( linux_terminal ) if ( linux_terminal )
{ {
@ -4573,43 +4630,11 @@ void FTerm::finish()
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__)
resetWSConsEncoding(); resetWSConsEncoding();
#endif #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 defined(__linux__)
if ( linux_terminal && utf8_console ) if ( linux_terminal && utf8_console )
setUTF8(true); setUTF8(true);
@ -4625,8 +4650,6 @@ void FTerm::finish()
delete[] screen_unicode_map.entries; delete[] screen_unicode_map.entries;
} }
#endif #endif
deallocationValues();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -832,8 +832,7 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
assert ( rsw >= 0 ); assert ( rsw >= 0 );
assert ( bsh >= 0 ); assert ( bsh >= 0 );
int area_size; int area_size;
char_data default_char; bool realloc_success = false;
line_changes unchanged;
if ( ! area ) if ( ! area )
return; return;
@ -856,41 +855,18 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
if ( area->height + area->bottom_shadow != height + bsh ) if ( area->height + area->bottom_shadow != height + bsh )
{ {
if ( area->changes != 0 ) realloc_success = reallocateTextArea (area, height + bsh, area_size);
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;
}
} }
else if ( area->width + area->right_shadow != width + rsw ) else if ( area->width + area->right_shadow != width + rsw )
{ {
if ( area->text != 0 ) realloc_success = reallocateTextArea (area, area_size);
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;
}
} }
else else
return; return;
if ( ! realloc_success )
return;
area->offset_left = offset_left; area->offset_left = offset_left;
area->offset_top = offset_top; area->offset_top = offset_top;
area->width = width; area->width = width;
@ -899,6 +875,18 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
area->bottom_shadow = bsh; area->bottom_shadow = bsh;
area->has_changes = false; 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.code = ' ';
default_char.fg_color = fc::Default; default_char.fg_color = fc::Default;
default_char.bg_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[1] = 0;
default_char.attr.byte[2] = 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.xmax = 0;
unchanged.trans_count = 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.code = '\0';
term_attribute.fg_color = fc::Default; term_attribute.fg_color = fc::Default;
term_attribute.bg_color = fc::Default; term_attribute.bg_color = fc::Default;
term_attribute.attr.bit.bold = \ term_attribute.attr.byte[0] = 0;
term_attribute.attr.bit.dim = \ term_attribute.attr.byte[0] = 0;
term_attribute.attr.bit.italic = \ term_attribute.attr.byte[0] = 0;
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;
// next_attribute contains the state of the next printed character // next_attribute contains the state of the next printed character
std::memcpy (&next_attribute, &term_attribute, sizeof(char_data)); std::memcpy (&next_attribute, &term_attribute, sizeof(char_data));