Some code improvements

This commit is contained in:
Markus Gans 2015-10-01 03:48:58 +02:00
parent fa05774a13
commit 3ca644669d
14 changed files with 209 additions and 104 deletions

View File

@ -152,8 +152,17 @@ uChar FButtonGroup::getHotkey()
length = text.getLength();
for (uInt i=0; i < length; i++)
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
{
try
{
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;;
}
}
return 0;
}

View File

@ -1,6 +1,6 @@
#ifndef _SRC_FCONFIG_H
#define _SRC_FCONFIG_H 1
/* src/fconfig.h. Generated automatically at end of configure. */
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
@ -171,6 +171,6 @@
#ifndef F_VERSION
#define F_VERSION "0.1.1"
#endif
/* once: _SRC_FCONFIG_H */
#endif

View File

@ -535,10 +535,18 @@ void FFileDialog::setPath (const FString& dir)
FString r_dir;
struct stat sb;
stat(dirname, &sb);
if ( stat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
if ( S_ISLNK(sb.st_mode) )
{
lstat(dirname, &sb);
if ( lstat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
}
if ( ! S_ISDIR(sb.st_mode) )
{
@ -618,9 +626,11 @@ int FFileDialog::readDir()
if ( realpath(symLink, resolved_path) != 0 ) // follow link
{
struct stat sb;
lstat(resolved_path, &sb);
if ( S_ISDIR(sb.st_mode) )
entry.type = DT_DIR;
if ( lstat(resolved_path, &sb) == 0 )
{
if ( S_ISDIR(sb.st_mode) )
entry.type = DT_DIR;
}
}
}
if ( entry.type == DT_DIR )

View File

@ -1316,6 +1316,7 @@ void FListBox::cb_VBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = height-2;
// fall through
case FScrollbar::scrollStepBackward:
current -= distance;
if ( current < 1 )
@ -1328,6 +1329,7 @@ void FListBox::cb_VBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = height-2;
// fall through
case FScrollbar::scrollStepForward:
current += distance;
if ( current > element_count )
@ -1401,6 +1403,7 @@ void FListBox::cb_HBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepBackward:
xoffset -= distance;
if ( xoffset < 0 )
@ -1409,6 +1412,7 @@ void FListBox::cb_HBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepForward:
xoffset += distance;
if ( xoffset > maxLineWidth - width + nf_offset + 4 )

View File

@ -441,7 +441,7 @@ void FMenu::onMouseUp (FMouseEvent* ev)
while ( iter != end )
{
int x1, x2, y;
x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth() - 1;
y = (*iter)->getY();
@ -456,7 +456,7 @@ void FMenu::onMouseUp (FMouseEvent* ev)
&& mouse_y == y )
{
(*iter)->processClicked();
redraw();
focus_changed = true;
}
}
++iter;

View File

@ -222,7 +222,7 @@ void FMenuBar::drawItems()
x++;
print (vmenubar, ' ');
}
setColor (wc.menu_active_fg, wc.menu_active_bg);
if ( is_Active && is_Selected )
setReverse(false);

View File

@ -260,7 +260,7 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
{
if ( isMenu(super_menu) )
dynamic_cast<FMenu*>(super_menu)->onMouseDown(ev);
if ( isMenuBar(super_menu) )
dynamic_cast<FMenuBar*>(super_menu)->onMouseDown(ev);
}
@ -282,7 +282,7 @@ void FMenuItem::onMouseUp (FMouseEvent* ev)
{
if ( isMenu(super_menu) )
dynamic_cast<FMenu*>(super_menu)->onMouseUp(ev);
if ( isMenuBar(super_menu) )
dynamic_cast<FMenuBar*>(super_menu)->onMouseUp(ev);
}
@ -304,7 +304,7 @@ void FMenuItem::onMouseMove (FMouseEvent* ev)
{
if ( isMenu(super_menu) )
dynamic_cast<FMenu*>(super_menu)->onMouseMove(ev);
if ( isMenuBar(super_menu) )
dynamic_cast<FMenuBar*>(super_menu)->onMouseMove(ev);
}

View File

@ -22,7 +22,7 @@
FMenuList FMenu
:
----------------- FMenuItem

View File

@ -2,6 +2,7 @@
// Provides: class FOptiMove
#include "foptimove.h"
#include "string.h"
//----------------------------------------------------------------------
// class FOptiMove
@ -104,136 +105,184 @@ int FOptiMove::cap_duration (char*& cap, int affcnt)
//----------------------------------------------------------------------
void FOptiMove::set_cursor_home (char*& cap)
{
F_cursor_home.cap = cap;
F_cursor_home.duration = cap_duration(cap, 0);
F_cursor_home.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_cursor_home.cap = cap;
F_cursor_home.duration = cap_duration(cap, 0);
F_cursor_home.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_to_ll (char*& cap)
{
F_cursor_to_ll.cap = cap;
F_cursor_to_ll.duration = cap_duration(cap, 0);
F_cursor_to_ll.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_cursor_to_ll.cap = cap;
F_cursor_to_ll.duration = cap_duration(cap, 0);
F_cursor_to_ll.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_carriage_return (char*& cap)
{
F_carriage_return.cap = cap;
F_carriage_return.duration = cap_duration(cap, 0);
F_carriage_return.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_carriage_return.cap = cap;
F_carriage_return.duration = cap_duration(cap, 0);
F_carriage_return.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_tabular (char*& cap)
{
F_tab.cap = cap;
F_tab.duration = cap_duration(cap, 0);
F_tab.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_tab.cap = cap;
F_tab.duration = cap_duration(cap, 0);
F_tab.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_back_tab (char*& cap)
{
F_back_tab.cap = cap;
F_back_tab.duration = cap_duration(cap, 0);
F_back_tab.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_back_tab.cap = cap;
F_back_tab.duration = cap_duration(cap, 0);
F_back_tab.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_up (char*& cap)
{
F_cursor_up.cap = cap;
F_cursor_up.duration = cap_duration(cap, 0);
F_cursor_up.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_cursor_up.cap = cap;
F_cursor_up.duration = cap_duration(cap, 0);
F_cursor_up.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_down (char*& cap)
{
F_cursor_down.cap = cap;
F_cursor_down.duration = cap_duration(cap, 0);
F_cursor_down.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_cursor_down.cap = cap;
F_cursor_down.duration = cap_duration(cap, 0);
F_cursor_down.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_left (char*& cap)
{
F_cursor_left.cap = cap;
F_cursor_left.duration = cap_duration(cap, 0);
F_cursor_left.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_cursor_left.cap = cap;
F_cursor_left.duration = cap_duration(cap, 0);
F_cursor_left.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_right (char*& cap)
{
F_cursor_right.cap = cap;
F_cursor_right.duration = cap_duration(cap, 0);
F_cursor_right.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
F_cursor_right.cap = cap;
F_cursor_right.duration = cap_duration(cap, 0);
F_cursor_right.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_address (char*& cap)
{
char* temp = tgoto(cap, 23, 23);
F_cursor_address.cap = cap;
F_cursor_address.duration = cap_duration(temp, 1);
F_cursor_address.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
char* temp = tgoto(cap, 23, 23);
F_cursor_address.cap = cap;
F_cursor_address.duration = cap_duration(temp, 1);
F_cursor_address.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_column_address (char*& cap)
{
char* temp = tparm(cap, 23);
F_column_address.cap = cap;
F_column_address.duration = cap_duration(temp, 1);
F_column_address.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
char* temp = tparm(cap, 23);
F_column_address.cap = cap;
F_column_address.duration = cap_duration(temp, 1);
F_column_address.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_row_address (char*& cap)
{
char* temp = tparm(cap, 23);
F_row_address.cap = cap;
F_row_address.duration = cap_duration(temp, 1);
F_row_address.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
char* temp = tparm(cap, 23);
F_row_address.cap = cap;
F_row_address.duration = cap_duration(temp, 1);
F_row_address.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_up_cursor (char*& cap)
{
char* temp = tparm(cap, 23);
F_parm_up_cursor.cap = cap;
F_parm_up_cursor.duration = cap_duration(temp, 1);
F_parm_up_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_up_cursor.cap = cap;
F_parm_up_cursor.duration = cap_duration(temp, 1);
F_parm_up_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_down_cursor (char*& cap)
{
char* temp = tparm(cap, 23);
F_parm_down_cursor.cap = cap;
F_parm_down_cursor.duration = cap_duration(temp, 1);
F_parm_down_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_down_cursor.cap = cap;
F_parm_down_cursor.duration = cap_duration(temp, 1);
F_parm_down_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_left_cursor (char*& cap)
{
char* temp = tparm(cap, 23);
F_parm_left_cursor.cap = cap;
F_parm_left_cursor.duration = cap_duration(temp, 1);
F_parm_left_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_left_cursor.cap = cap;
F_parm_left_cursor.duration = cap_duration(temp, 1);
F_parm_left_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_right_cursor (char*& cap)
{
char* temp = tparm(cap, 23);
F_parm_right_cursor.cap = cap;
F_parm_right_cursor.duration = cap_duration(temp, 1);
F_parm_right_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_right_cursor.cap = cap;
F_parm_right_cursor.duration = cap_duration(temp, 1);
F_parm_right_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
@ -416,7 +465,9 @@ int FOptiMove::relative_move ( char*& move
if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime )
{
strcat (hmove, tparm(F_parm_left_cursor.cap, num));
strncat ( hmove
, tparm(F_parm_left_cursor.cap, num)
, sizeof(hmove) - strlen(hmove) - 1 );
htime = F_parm_left_cursor.duration;
}
@ -565,6 +616,7 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew)
{
new_time = relative_move (null_ptr, screen_width-1, yold-1, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_carriage_return.cap
&& F_carriage_return.duration
+ F_cursor_left.duration + new_time < move_time )
{
@ -595,7 +647,7 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew)
break;
case 4:
strcpy (move_ptr, F_cursor_to_ll.cap);
strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf));
move_ptr += F_cursor_to_ll.length;
relative_move (move_ptr, 0, screen_height-1, xnew, ynew);
break;

View File

@ -702,7 +702,7 @@ const FString FString::operator + (const std::string& s)
wchar_t* wc_string = c_to_wc_str(s.c_str());
if ( ! wc_string )
return (tmp);
tmp._insert (length, uInt(wcslen(wc_string)), wc_string);
tmp._insert (length, uInt(wcslen(wc_string)), wc_string);
delete[] wc_string;
return (tmp);

View File

@ -194,22 +194,21 @@ int FTerm::inb_Attribute_Controller (int index)
int FTerm::getFramebuffer_bpp ()
{
int fd = -1;
struct stat fb_stat;
struct fb_var_screeninfo fb_var;
struct fb_fix_screeninfo fb_fix;
const char* fb = const_cast<char*>("/dev/fb/0");
if ( stat(fb, &fb_stat) < 0 )
if ( (fd = open(fb, O_RDWR)) < 0 )
{
if ( errno != ENOENT && errno != ENOTDIR )
return -1;
fb = const_cast<char*>("/dev/fb0");
if ( stat(fb, &fb_stat) < 0 )
if ( (fd = open(fb, O_RDWR)) < 0 )
return -1;
}
fd = open(fb, O_RDWR);
if (fd >= 0)
{
if ( ! ioctl(fd, FBIOGET_VSCREENINFO, &fb_var)
@ -778,7 +777,7 @@ int FTerm::parseKeyString ( char* buffer
{
char* kmeta = Fmetakey[i].string; // The string is never null
len = int(strlen(kmeta));
if ( kmeta && strncmp(kmeta, buffer, uInt(len)) == 0 ) // found
if ( strncmp(kmeta, buffer, uInt(len)) == 0 ) // found
{
if ( len == 2 && ( buffer[1] == 'O'
|| buffer[1] == '['
@ -1108,7 +1107,6 @@ void FTerm::init()
putchar(0x8); // cygwin needs a backspace to delete the '♣' char
Sec_DA = new FString(getSecDA()); // get Secondary DA
if ( Sec_DA->getLength() > 5 )
{
FString temp = Sec_DA->right(Sec_DA->getLength() - 3);
@ -1128,7 +1126,7 @@ void FTerm::init()
putty_terminal = true; // PuTTY
}
break;
case 1:
// also used by apple terminal
if ( Sec_DA_components[1]
@ -1145,12 +1143,12 @@ void FTerm::init()
termtype = const_cast<char*>("gnome");
}
break;
case 32: // Tera Term
tera_terminal = true;
termtype = const_cast<char*>("teraterm");
break;
case 77: // mintty
mintty_terminal = true;
termtype = const_cast<char*>("xterm-256color");
@ -1158,11 +1156,11 @@ void FTerm::init()
tputs ("\033[?7727h", 1, putchar);
fflush(stdout);
break;
case 83: // screen
screen_terminal = true;
break;
case 82: // rxvt
rxvt_terminal = true;
force_vt100 = true; // this rxvt terminal support on utf-8
@ -1170,7 +1168,7 @@ void FTerm::init()
|| strncmp(termtype, "rxvt-cygwin-native", 5) == 0 )
termtype = const_cast<char*>("rxvt-16color");
break;
case 85: // rxvt-unicode
rxvt_terminal = true;
urxvt_terminal = true;
@ -1182,7 +1180,7 @@ void FTerm::init()
termtype = const_cast<char*>("rxvt");
}
break;
default:
break;
}
@ -1207,7 +1205,7 @@ void FTerm::init()
// stop non-blocking stdin
unsetNonBlockingInput();
setenv("TERM", termtype, 1);
setenv(const_cast<char*>("TERM"), termtype, 1);
// Initializes variables for the current terminal
init_termcaps();
@ -3443,13 +3441,18 @@ FString FTerm::getAnswerbackMsg()
if ( raw_mode )
{
int n;
char temp[10] = {};
putchar(0x05); // send enquiry character
fflush(stdout);
usleep(150000); // wait 150 ms
// read the answerback message
if ( read(fileno(stdin), &temp, sizeof(temp)-1) > 0 )
n = read(fileno(stdin), &temp, sizeof(temp)-1);
if ( n > 0 )
{
temp[n] = '\0';
answerback = temp;
}
}
return answerback;
}
@ -3461,6 +3464,7 @@ FString FTerm::getSecDA()
if ( raw_mode )
{
int n;
char temp[16] = {};
// get the secondary device attributes
putchar(0x1b); // ESC
@ -3470,8 +3474,12 @@ FString FTerm::getSecDA()
fflush(stdout);
usleep(150000); // wait 150 ms
// read the answer
if ( read(fileno(stdin), &temp, sizeof(temp)-1) > 0 )
n = read(fileno(stdin), &temp, sizeof(temp)-1);
if ( n > 0 )
{
temp[n] = '\0';
sec_da = temp;
}
}
return sec_da;
}
@ -3610,14 +3618,19 @@ int FTerm::print (FString& s)
//----------------------------------------------------------------------
int FTerm::print (FTerm::term_area* area, FString& s)
{
assert ( area != 0 );
assert ( ! s.isNull() );
register int len = 0;
const wchar_t* p = s.wc_str();
FWidget* area_widget = area->widget;
const wchar_t* p;
FWidget* area_widget;
if ( ! area )
return -1;
area_widget = area->widget;
if ( ! area_widget )
return -1;
p = s.wc_str();
if ( p )
{
while ( *p )
@ -3735,12 +3748,13 @@ int FTerm::print (register int c)
//----------------------------------------------------------------------
int FTerm::print (FTerm::term_area* area, register int c)
{
assert ( area != 0 );
char_data nc; // new character
FWidget* area_widget;
int rsh, bsh;
short x = short(cursor->getX());
short y = short(cursor->getY());
int rsh, bsh, ax, ay;
short x, y;
if ( ! area )
return -1;
nc.code = c;
nc.fg_color = uChar(fg_color);
@ -3749,15 +3763,17 @@ int FTerm::print (FTerm::term_area* area, register int c)
nc.reverse = reverse;
nc.underline = underline;
x = short(cursor->getX());
y = short(cursor->getY());
area_widget = area->widget;
if ( ! area_widget )
return -1;
int ax = x - area_widget->getGlobalX();
int ay = y - area_widget->getGlobalY();
ax = x - area_widget->getGlobalX();
ay = y - area_widget->getGlobalY();
if ( area
&& ax >= 0 && ay >= 0
if ( ax >= 0 && ay >= 0
&& ax < area->width + area->right_shadow
&& ay < area->height + area->bottom_shadow )
{
@ -3825,6 +3841,7 @@ inline void FTerm::appendAttributes (char_data*& screen_attr)
{
case fc::LowerHalfBlock:
screen_attr->code = fc::UpperHalfBlock;
// fall through
case fc::NF_rev_left_arrow2:
case fc::NF_rev_right_arrow2:
case fc::NF_rev_border_corner_upper_right:

View File

@ -365,6 +365,7 @@ void FTextView::cb_VBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = height+nf_offset-2;
// fall through
case FScrollbar::scrollStepBackward:
yoffset -= distance;
if ( yoffset < 0 )
@ -373,6 +374,7 @@ void FTextView::cb_VBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = height+nf_offset-2;
// fall through
case FScrollbar::scrollStepForward:
yoffset += distance;
if ( yoffset > last_line - height - nf_offset + 2 )
@ -438,6 +440,7 @@ void FTextView::cb_HBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepBackward:
xoffset -= distance;
if ( xoffset < 0 )
@ -446,6 +449,7 @@ void FTextView::cb_HBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepForward:
xoffset += distance;
if ( xoffset > int(maxLineWidth) - width + nf_offset + 4 )

View File

@ -114,8 +114,17 @@ uChar FToggleButton::getHotkey()
length = text.getLength();
for (uInt i=0; i < length; i++)
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
{
try
{
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;;
}
}
return 0;
}

View File

@ -211,9 +211,9 @@ int main (int, char**)
FString index(5); // a string with five characters
index = "index";
index[0] = L'I'; // write a wide character at position 0
try
{
index[0] = L'I'; // write a wide character at position 0
printf ( " index: [0] = %c ; [4] = %c\n"
, char(index[0])
, char(index[4]) );