Some code improvements

This commit is contained in:
Markus Gans 2015-10-01 04:44:26 +02:00
parent 3ca644669d
commit 2ba6b0bcf7
4 changed files with 52 additions and 18 deletions

View File

@ -96,10 +96,12 @@ void FMenuItem::init (FWidget* parent)
if ( parent )
{
FMenuList* super_menu_list = dynamic_cast<FMenuList*>(parent);
setSuperMenu(super_menu_list);
super_menu_list->insert(this);
if ( isMenuBar(parent) ) // Parent is menubar
{
setSuperMenu( dynamic_cast<FMenuList*>(parent) );
superMenu()->insert(this);
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
if ( menubar_ptr )
menubar_ptr->menu_dimension();
@ -119,8 +121,6 @@ void FMenuItem::init (FWidget* parent)
}
else if ( isMenu(parent) ) // Parent is menu
{
setSuperMenu( dynamic_cast<FMenuList*>(parent) );
superMenu()->insert(this);
FMenu* super_menu_ptr = dynamic_cast<FMenu*>(parent);
if ( super_menu_ptr )
super_menu_ptr->menu_dimension();
@ -259,10 +259,18 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( super_menu )
{
if ( isMenu(super_menu) )
dynamic_cast<FMenu*>(super_menu)->onMouseDown(ev);
{
FMenu* sm = dynamic_cast<FMenu*>(super_menu);
if ( sm )
sm->onMouseDown(ev);
}
if ( isMenuBar(super_menu) )
dynamic_cast<FMenuBar*>(super_menu)->onMouseDown(ev);
{
FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu);
if ( mb )
mb->onMouseDown(ev);
}
}
delete ev;
@ -281,10 +289,18 @@ void FMenuItem::onMouseUp (FMouseEvent* ev)
if ( super_menu )
{
if ( isMenu(super_menu) )
dynamic_cast<FMenu*>(super_menu)->onMouseUp(ev);
{
FMenu* sm = dynamic_cast<FMenu*>(super_menu);
if ( sm )
sm->onMouseUp(ev);
}
if ( isMenuBar(super_menu) )
dynamic_cast<FMenuBar*>(super_menu)->onMouseUp(ev);
{
FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu);
if ( mb )
mb->onMouseUp(ev);
}
}
delete ev;
@ -303,10 +319,18 @@ void FMenuItem::onMouseMove (FMouseEvent* ev)
if ( super_menu )
{
if ( isMenu(super_menu) )
dynamic_cast<FMenu*>(super_menu)->onMouseMove(ev);
{
FMenu* sm = dynamic_cast<FMenu*>(super_menu);
if ( sm )
sm->onMouseMove(ev);
}
if ( isMenuBar(super_menu) )
dynamic_cast<FMenuBar*>(super_menu)->onMouseMove(ev);
{
FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu);
if ( mb )
mb->onMouseMove(ev);
}
}
delete ev;

View File

@ -422,7 +422,9 @@ int FOptiMove::relative_move ( char*& move
if ( F_parm_right_cursor.cap && F_parm_right_cursor.duration < htime )
{
strcat (hmove, tparm(F_parm_right_cursor.cap, num));
strncat ( hmove
, tparm(F_parm_right_cursor.cap, num)
, sizeof(hmove) - strlen(hmove) - 1 );
htime = F_parm_right_cursor.duration;
}
@ -647,7 +649,7 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew)
break;
case 4:
strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf));
strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf) - 1);
move_ptr += F_cursor_to_ll.length;
relative_move (move_ptr, 0, screen_height-1, xnew, ynew);
break;
@ -656,7 +658,9 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew)
move_buf[0] = '\0';
if ( xold >= 0 )
strcat (move_ptr, F_carriage_return.cap);
strcat (move_ptr, F_cursor_left.cap);
strncat ( move_ptr
, F_cursor_left.cap
, sizeof(move_buf) - strlen(move_ptr) - 1 );
move_ptr += strlen(move_buf);
relative_move (move_ptr, screen_width-1, yold-1, xnew, ynew);
break;

View File

@ -220,10 +220,8 @@ int FTerm::getFramebuffer_bpp ()
else
{
::close(fd);
return -1;
}
}
else
return -1;
}

View File

@ -206,8 +206,15 @@ int main (int, char**)
<< alphabet.right(11) << "\"" << std::endl;
FString insert_str = "I am a string";
try
{
std::cout << " insert: "
<< insert_str.insert("changed ", 7) << std::endl;
}
catch (const std::out_of_range& ex)
{
std::cerr << "Out of Range error: " << ex.what() << std::endl;
}
FString index(5); // a string with five characters
index = "index";
@ -222,6 +229,7 @@ int main (int, char**)
{
std::cerr << "Out of Range error: " << ex.what() << std::endl;
}
FString stringIterator = "iterator";
FString::iterator iter;
iter = stringIterator.begin();