Refactoring of some functions
This commit is contained in:
parent
2af1b1d0d4
commit
d8a6c25ce0
|
@ -1,4 +1,11 @@
|
|||
2017-10-02 Markus Gans <guru.mail@muenster.de>
|
||||
2017-02-11 Markus Gans <guru.mail@muenster.de>
|
||||
* Refactoring FWidget::focusNextChild and FWidget::focusPrevChild
|
||||
* Refactoring FListView::onWheel
|
||||
* Refactoring FListView::drawColumnLabels
|
||||
* Refactoring FTerm::getSystemTermType
|
||||
* Rename getTermName() to getTermFileName()
|
||||
|
||||
2017-02-10 Markus Gans <guru.mail@muenster.de>
|
||||
* Refactoring FOptiMove::verticalMove and FOptiMove::horizontalMove
|
||||
* Refactoring FVTerm::getCharacter
|
||||
* Refactoring FWidget::drawBorder
|
||||
|
|
|
@ -828,7 +828,7 @@ void MyDialog::cb_terminfo (FWidget*, data_ptr)
|
|||
FMessageBox info1 ( "Environment"
|
||||
, FString()
|
||||
<< " Type: " << getTermType() << "\n"
|
||||
<< " Name: " << getTermName() << "\n"
|
||||
<< " Name: " << getTermFileName() << "\n"
|
||||
<< " Mode: " << getEncodingString() << "\n"
|
||||
<< " Size: " << x << wchar_t(fc::Times)
|
||||
<< y << "\n"
|
||||
|
|
|
@ -323,9 +323,16 @@ class FListView : public FWidget
|
|||
void drawListLine (const FListViewItem*, bool, bool);
|
||||
void setLineAttributes (bool, bool);
|
||||
FString getLinePrefix (const FListViewItem*, uInt);
|
||||
void drawColumnText (headerItems::const_iterator&);
|
||||
void drawColumnEllipsis ( headerItems::const_iterator&
|
||||
, const FString& );
|
||||
void updateDrawing (bool, bool);
|
||||
void recalculateHorizontalBar (int);
|
||||
void recalculateVerticalBar (int);
|
||||
void wheelUp (int);
|
||||
void wheelDown (int);
|
||||
bool dragScrollUp (int);
|
||||
bool dragScrollDown (int);
|
||||
FObjectIterator appendItem (FListViewItem*);
|
||||
void processClick();
|
||||
void processChanged();
|
||||
|
|
|
@ -173,7 +173,7 @@ class FTerm
|
|||
#endif
|
||||
|
||||
static char* getTermType();
|
||||
static char* getTermName();
|
||||
static char* getTermFileName();
|
||||
static int getTabstop();
|
||||
static int getMaxColor();
|
||||
|
||||
|
@ -437,6 +437,10 @@ class FTerm
|
|||
static int openConsole();
|
||||
static int closeConsole();
|
||||
static void getSystemTermType();
|
||||
static void getTTYtype();
|
||||
#if F_HAVE_GETTTYNAM
|
||||
static bool getTTYSFileEntry();
|
||||
#endif
|
||||
static void storeTTYsettings();
|
||||
static void restoreTTYsettings();
|
||||
|
||||
|
@ -576,7 +580,7 @@ class FTerm
|
|||
static bool screen_terminal;
|
||||
static bool tmux_terminal;
|
||||
static char termtype[256];
|
||||
static char term_name[256];
|
||||
static char termfilename[256];
|
||||
static char* locale_name;
|
||||
static char* locale_xterm;
|
||||
static FRect* term; // current terminal geometry
|
||||
|
@ -662,8 +666,8 @@ inline char* FTerm::getTermType()
|
|||
{ return termtype; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline char* FTerm::getTermName()
|
||||
{ return term_name; }
|
||||
inline char* FTerm::getTermFileName()
|
||||
{ return termfilename; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline int FTerm::getTabstop()
|
||||
|
|
|
@ -342,8 +342,8 @@ class FWidget : public FVTerm, public FObject
|
|||
// Methods
|
||||
virtual void adjustSize();
|
||||
void adjustSizeGlobal();
|
||||
virtual bool focusNextChild(); // Change child
|
||||
virtual bool focusPrevChild(); // focus
|
||||
virtual bool focusNextChild(); // Change child...
|
||||
virtual bool focusPrevChild(); // ...focus
|
||||
|
||||
// Event handlers
|
||||
bool event (FEvent*);
|
||||
|
@ -388,6 +388,7 @@ class FWidget : public FVTerm, public FObject
|
|||
void insufficientSpaceAdjust();
|
||||
void KeyPressEvent (FKeyEvent*);
|
||||
void KeyDownEvent (FKeyEvent*);
|
||||
bool changeFocus (FWidget*, FWidget*, fc::FocusTypes);
|
||||
void processDestroy();
|
||||
virtual void draw();
|
||||
void drawWindows();
|
||||
|
|
|
@ -1020,8 +1020,7 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev)
|
|||
//----------------------------------------------------------------------
|
||||
void FListView::onTimer (FTimerEvent*)
|
||||
{
|
||||
int element_count = int(getCount())
|
||||
, position_before = current_iter.getPosition()
|
||||
int position_before = current_iter.getPosition()
|
||||
, first_line_position_before = first_visible_line.getPosition();
|
||||
|
||||
switch ( int(drag_scroll) )
|
||||
|
@ -1031,24 +1030,14 @@ void FListView::onTimer (FTimerEvent*)
|
|||
|
||||
case fc::scrollUp:
|
||||
case fc::scrollUpSelect:
|
||||
if ( position_before == 0 )
|
||||
{
|
||||
drag_scroll = fc::noScroll;
|
||||
if ( ! dragScrollUp(position_before) )
|
||||
return;
|
||||
}
|
||||
|
||||
stepBackward(scroll_distance);
|
||||
break;
|
||||
|
||||
case fc::scrollDown:
|
||||
case fc::scrollDownSelect:
|
||||
if ( position_before + 1 == element_count )
|
||||
{
|
||||
drag_scroll = fc::noScroll;
|
||||
if ( ! dragScrollDown(position_before) )
|
||||
return;
|
||||
}
|
||||
|
||||
stepForward(scroll_distance);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1071,14 +1060,10 @@ void FListView::onTimer (FTimerEvent*)
|
|||
//----------------------------------------------------------------------
|
||||
void FListView::onWheel (FWheelEvent* ev)
|
||||
{
|
||||
int wheel
|
||||
, element_count = int(getCount())
|
||||
, position_before = current_iter.getPosition()
|
||||
int position_before = current_iter.getPosition()
|
||||
, first_line_position_before = first_visible_line.getPosition()
|
||||
, pagesize = 4;
|
||||
|
||||
wheel = ev->getWheel();
|
||||
|
||||
if ( drag_scroll != fc::noScroll )
|
||||
{
|
||||
delOwnTimer();
|
||||
|
@ -1087,52 +1072,14 @@ void FListView::onWheel (FWheelEvent* ev)
|
|||
drag_scroll = fc::noScroll;
|
||||
}
|
||||
|
||||
switch ( wheel )
|
||||
switch ( ev->getWheel() )
|
||||
{
|
||||
case fc::WheelUp:
|
||||
if ( current_iter.getPosition() == 0 )
|
||||
break;
|
||||
|
||||
if ( first_visible_line.getPosition() >= pagesize )
|
||||
{
|
||||
current_iter -= pagesize;
|
||||
first_visible_line -= pagesize;
|
||||
last_visible_line -= pagesize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save relative position from the first line
|
||||
int ry = current_iter.getPosition() - first_visible_line.getPosition();
|
||||
// Save difference from top
|
||||
int difference = first_visible_line.getPosition();
|
||||
first_visible_line -= difference;
|
||||
last_visible_line -= difference;
|
||||
setRelativePosition(ry);
|
||||
}
|
||||
|
||||
wheelUp (pagesize);
|
||||
break;
|
||||
|
||||
case fc::WheelDown:
|
||||
if ( current_iter.getPosition() + 1 == element_count )
|
||||
break;
|
||||
|
||||
if ( last_visible_line.getPosition() < element_count - pagesize )
|
||||
{
|
||||
current_iter += pagesize;
|
||||
first_visible_line += pagesize;
|
||||
last_visible_line += pagesize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save relative position from the first line
|
||||
int ry = current_iter.getPosition() - first_visible_line.getPosition();
|
||||
// Save difference from bottom
|
||||
int differenz = element_count - last_visible_line.getPosition() - 1;
|
||||
first_visible_line += differenz;
|
||||
last_visible_line += differenz;
|
||||
setRelativePosition(ry);
|
||||
}
|
||||
|
||||
wheelDown (pagesize);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1384,13 +1331,8 @@ void FListView::draw()
|
|||
//----------------------------------------------------------------------
|
||||
void FListView::drawColumnLabels()
|
||||
{
|
||||
static const int leading_space = 1;
|
||||
static const int trailing_space = 1;
|
||||
static const int ellipsis_length = 2;
|
||||
std::vector<char_data>::const_iterator first, last;
|
||||
headerItems::const_iterator iter;
|
||||
FString txt;
|
||||
uInt txt_length;
|
||||
|
||||
if ( header.empty()
|
||||
|| getHeight() <= 2
|
||||
|
@ -1404,8 +1346,6 @@ void FListView::drawColumnLabels()
|
|||
while ( iter != header.end() )
|
||||
{
|
||||
const FString& text = (*iter).name;
|
||||
int width = (*iter).width;
|
||||
int column_width;
|
||||
|
||||
if ( text.isNull() || text.isEmpty() )
|
||||
{
|
||||
|
@ -1413,42 +1353,7 @@ void FListView::drawColumnLabels()
|
|||
continue;
|
||||
}
|
||||
|
||||
txt = " " + text;
|
||||
txt_length = txt.getLength();
|
||||
column_width = leading_space + width;
|
||||
|
||||
if ( isEnabled() )
|
||||
setColor (wc.label_emphasis_fg, wc.label_bg);
|
||||
else
|
||||
setColor (wc.label_inactive_fg, wc.label_inactive_bg);
|
||||
|
||||
if ( txt_length <= uInt(column_width) )
|
||||
{
|
||||
headerline << txt;
|
||||
|
||||
if ( txt_length < uInt(column_width) )
|
||||
headerline << ' '; // trailing space
|
||||
|
||||
if ( txt_length + trailing_space < uInt(column_width) )
|
||||
{
|
||||
setColor();
|
||||
const FString line ( uInt(column_width) - trailing_space - txt_length
|
||||
, wchar_t(fc::BoxDrawingsHorizontal) );
|
||||
headerline << line; // horizontal line
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print ellipsis
|
||||
headerline << ' ';
|
||||
headerline << text.left(uInt(width - ellipsis_length));
|
||||
setColor (wc.label_ellipsis_fg, wc.label_bg);
|
||||
headerline << "..";
|
||||
|
||||
if ( iter == header.end() - 1 ) // Last element
|
||||
headerline << ' ';
|
||||
}
|
||||
|
||||
drawColumnText(iter);
|
||||
++iter;
|
||||
}
|
||||
|
||||
|
@ -1660,6 +1565,59 @@ inline FString FListView::getLinePrefix ( const FListViewItem* item
|
|||
return line;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListView::drawColumnText (headerItems::const_iterator& iter)
|
||||
{
|
||||
// Print lable text
|
||||
static const int leading_space = 1;
|
||||
static const int trailing_space = 1;
|
||||
const FString& text = (*iter).name;
|
||||
int width = (*iter).width;
|
||||
FString txt = " " + text;
|
||||
uInt txt_length = txt.getLength();
|
||||
int column_width = leading_space + width;
|
||||
|
||||
if ( isEnabled() )
|
||||
setColor (wc.label_emphasis_fg, wc.label_bg);
|
||||
else
|
||||
setColor (wc.label_inactive_fg, wc.label_inactive_bg);
|
||||
|
||||
if ( txt_length <= uInt(column_width) )
|
||||
{
|
||||
headerline << txt;
|
||||
|
||||
if ( txt_length < uInt(column_width) )
|
||||
headerline << ' '; // trailing space
|
||||
|
||||
if ( txt_length + trailing_space < uInt(column_width) )
|
||||
{
|
||||
setColor();
|
||||
const FString line ( uInt(column_width) - trailing_space - txt_length
|
||||
, wchar_t(fc::BoxDrawingsHorizontal) );
|
||||
headerline << line; // horizontal line
|
||||
}
|
||||
}
|
||||
else
|
||||
drawColumnEllipsis (iter, text); // Print ellipsis
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListView::drawColumnEllipsis ( headerItems::const_iterator& iter
|
||||
, const FString& text )
|
||||
{
|
||||
// Print lable ellipsis
|
||||
static const int ellipsis_length = 2;
|
||||
int width = (*iter).width;
|
||||
|
||||
headerline << ' ';
|
||||
headerline << text.left(uInt(width - ellipsis_length));
|
||||
setColor (wc.label_ellipsis_fg, wc.label_bg);
|
||||
headerline << "..";
|
||||
|
||||
if ( iter == header.end() - 1 ) // Last element
|
||||
headerline << ' ';
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListView::updateDrawing (bool draw_vbar, bool draw_hbar)
|
||||
{
|
||||
|
@ -1710,6 +1668,84 @@ void FListView::recalculateVerticalBar (int element_count)
|
|||
vbar->setVisible();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListView::wheelUp (int pagesize)
|
||||
{
|
||||
if ( current_iter.getPosition() == 0 )
|
||||
return;
|
||||
|
||||
if ( first_visible_line.getPosition() >= pagesize )
|
||||
{
|
||||
current_iter -= pagesize;
|
||||
first_visible_line -= pagesize;
|
||||
last_visible_line -= pagesize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save relative position from the first line
|
||||
int ry = current_iter.getPosition() - first_visible_line.getPosition();
|
||||
// Save difference from top
|
||||
int difference = first_visible_line.getPosition();
|
||||
first_visible_line -= difference;
|
||||
last_visible_line -= difference;
|
||||
setRelativePosition(ry);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListView::wheelDown (int pagesize)
|
||||
{
|
||||
int element_count = int(getCount());
|
||||
|
||||
if ( current_iter.getPosition() + 1 == element_count )
|
||||
return;
|
||||
|
||||
if ( last_visible_line.getPosition() < element_count - pagesize )
|
||||
{
|
||||
current_iter += pagesize;
|
||||
first_visible_line += pagesize;
|
||||
last_visible_line += pagesize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save relative position from the first line
|
||||
int ry = current_iter.getPosition() - first_visible_line.getPosition();
|
||||
// Save difference from bottom
|
||||
int differenz = element_count - last_visible_line.getPosition() - 1;
|
||||
first_visible_line += differenz;
|
||||
last_visible_line += differenz;
|
||||
setRelativePosition(ry);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FListView::dragScrollUp (int position_before)
|
||||
{
|
||||
if ( position_before == 0 )
|
||||
{
|
||||
drag_scroll = fc::noScroll;
|
||||
return false;
|
||||
}
|
||||
|
||||
stepBackward(scroll_distance);
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FListView::dragScrollDown (int position_before)
|
||||
{
|
||||
int element_count = int(getCount());
|
||||
|
||||
if ( position_before + 1 == element_count )
|
||||
{
|
||||
drag_scroll = fc::noScroll;
|
||||
return false;
|
||||
}
|
||||
|
||||
stepForward(scroll_distance);
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
FObject::FObjectIterator FListView::appendItem (FListViewItem* item)
|
||||
{
|
||||
|
|
|
@ -810,7 +810,6 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
|
|||
inline void FOptiMove::rightMove ( char hmove[], int& htime
|
||||
, int from_x, int to_x )
|
||||
{
|
||||
char str[BUF_SIZE] = {};
|
||||
int num = to_x - from_x;
|
||||
|
||||
if ( F_parm_right_cursor.cap && F_parm_right_cursor.duration < htime )
|
||||
|
@ -823,6 +822,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime
|
|||
|
||||
if ( F_cursor_right.cap )
|
||||
{
|
||||
char str[BUF_SIZE] = {};
|
||||
int htime_r = 0;
|
||||
str[0] = '\0';
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ bool FTerm::xterm_default_colors;
|
|||
bool FTerm::use_alternate_screen = true;
|
||||
termios FTerm::term_init;
|
||||
char FTerm::termtype[256] = {};
|
||||
char FTerm::term_name[256] = {};
|
||||
char FTerm::termfilename[256] = {};
|
||||
|
||||
#if DEBUG
|
||||
char FTerm::termtype_256color[256] = {};
|
||||
|
@ -1989,7 +1989,7 @@ int FTerm::openConsole()
|
|||
if ( fd_tty >= 0 ) // console is already opened
|
||||
return 0;
|
||||
|
||||
if ( ! *term_name )
|
||||
if ( ! *termfilename )
|
||||
return 0;
|
||||
|
||||
for (int i = 0; terminal_devices[i] != 0; i++)
|
||||
|
@ -2022,21 +2022,29 @@ void FTerm::getSystemTermType()
|
|||
|
||||
if ( term_env )
|
||||
{
|
||||
// Save name in termtype
|
||||
std::strncpy (termtype, term_env, sizeof(termtype) - 1);
|
||||
return;
|
||||
}
|
||||
else if ( *term_name ) // fallback: look into /etc/ttytype or /etc/ttys
|
||||
else if ( *termfilename ) // 1st fallback: use the teminal file name
|
||||
{
|
||||
// get term basename
|
||||
const char* term_basename = std::strrchr(term_name, '/');
|
||||
getTTYtype(); // Look into /etc/ttytype
|
||||
|
||||
if ( term_basename == 0 )
|
||||
term_basename = term_name;
|
||||
else
|
||||
term_basename++;
|
||||
#if F_HAVE_GETTTYNAM
|
||||
if ( getTTYSFileEntry() ) // Look into /etc/ttys
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Analyse /etc/ttytype
|
||||
// --------------------
|
||||
// 2nd fallback: use vt100 if not found
|
||||
std::strncpy (termtype, C_STR("vt100"), 6);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FTerm::getTTYtype()
|
||||
{
|
||||
// Analyse /etc/ttytype and get the term name
|
||||
// ------------------------------------------
|
||||
// file format:
|
||||
// <terminal type> <whitespace> <tty name>
|
||||
//
|
||||
|
@ -2044,6 +2052,14 @@ void FTerm::getSystemTermType()
|
|||
// linux tty1
|
||||
// vt100 ttys0
|
||||
|
||||
// Get term basename
|
||||
const char* term_basename = std::strrchr(termfilename, '/');
|
||||
|
||||
if ( term_basename == 0 )
|
||||
term_basename = termfilename;
|
||||
else
|
||||
term_basename++;
|
||||
|
||||
std::FILE *fp;
|
||||
|
||||
if ( (fp = std::fopen("/etc/ttytype", "r")) != 0 )
|
||||
|
@ -2051,7 +2067,7 @@ void FTerm::getSystemTermType()
|
|||
char* p;
|
||||
char str[BUFSIZ];
|
||||
|
||||
// read and parse the file
|
||||
// Read and parse the file
|
||||
while ( fgets(str, sizeof(str) - 1, fp) != 0 )
|
||||
{
|
||||
char* name;
|
||||
|
@ -2073,6 +2089,7 @@ void FTerm::getSystemTermType()
|
|||
|
||||
if ( type != 0 && name != 0 && ! std::strcmp(name, term_basename) )
|
||||
{
|
||||
// Save name in termtype
|
||||
std::strncpy (termtype, type, sizeof(termtype) - 1);
|
||||
std::fclose(fp);
|
||||
return;
|
||||
|
@ -2081,11 +2098,22 @@ void FTerm::getSystemTermType()
|
|||
|
||||
std::fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
#if F_HAVE_GETTTYNAM
|
||||
//----------------------------------------------------------------------
|
||||
bool FTerm::getTTYSFileEntry()
|
||||
{
|
||||
// Analyse /etc/ttys and get the term name
|
||||
|
||||
// get term basename
|
||||
const char* term_basename = std::strrchr(termfilename, '/');
|
||||
|
||||
if ( term_basename == 0 )
|
||||
term_basename = termfilename;
|
||||
else
|
||||
term_basename++;
|
||||
|
||||
// Analyse /etc/ttys
|
||||
// --------------------
|
||||
struct ttyent* ttys_entryt;
|
||||
ttys_entryt = getttynam(term_basename);
|
||||
|
||||
|
@ -2095,19 +2123,17 @@ void FTerm::getSystemTermType()
|
|||
|
||||
if ( type != 0 )
|
||||
{
|
||||
// Save name in termtype
|
||||
std::strncpy (termtype, type, sizeof(termtype) - 1);
|
||||
endttyent();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
endttyent();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// use vt100 if not found
|
||||
std::strncpy (termtype, C_STR("vt100"), 6);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FTerm::storeTTYsettings()
|
||||
|
@ -4420,8 +4446,8 @@ void FTerm::init()
|
|||
std::abort();
|
||||
|
||||
// Get pathname of the terminal device
|
||||
if ( ttyname_r(stdout_no, term_name, sizeof(term_name)) )
|
||||
term_name[0] = '\0';
|
||||
if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) )
|
||||
termfilename[0] = '\0';
|
||||
|
||||
initOSspecifics();
|
||||
|
||||
|
|
147
src/fwidget.cpp
147
src/fwidget.cpp
|
@ -1761,15 +1761,14 @@ void FWidget::adjustSizeGlobal()
|
|||
//----------------------------------------------------------------------
|
||||
bool FWidget::focusNextChild()
|
||||
{
|
||||
if ( isDialogWidget() )
|
||||
if ( isDialogWidget() || ! hasParent() )
|
||||
return false;
|
||||
|
||||
if ( hasParent() )
|
||||
{
|
||||
FWidget* parent = getParentWidget();
|
||||
|
||||
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
||||
{
|
||||
if ( ! parent->hasChildren() || parent->numOfFocusableChildren() <= 1 )
|
||||
return false;
|
||||
|
||||
FObjectIterator iter, last;
|
||||
iter = parent->begin();
|
||||
last = parent->end();
|
||||
|
@ -1784,8 +1783,12 @@ bool FWidget::focusNextChild()
|
|||
|
||||
FWidget* w = static_cast<FWidget*>(*iter);
|
||||
|
||||
if ( w == this )
|
||||
if ( w != this )
|
||||
{
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
FWidget* next = 0;
|
||||
constFObjectIterator next_element;
|
||||
next_element = iter;
|
||||
|
@ -1807,60 +1810,28 @@ bool FWidget::focusNextChild()
|
|||
|| ! next->isVisible()
|
||||
|| next->isWindowWidget() );
|
||||
|
||||
FFocusEvent out (fc::FocusOut_Event);
|
||||
out.setFocusType(fc::FocusNextWidget);
|
||||
FApplication::sendEvent(this, &out);
|
||||
bool accpt = changeFocus (next, parent, fc::FocusNextWidget);
|
||||
|
||||
FFocusEvent cfo (fc::ChildFocusOut_Event);
|
||||
cfo.setFocusType(fc::FocusNextWidget);
|
||||
cfo.ignore();
|
||||
FApplication::sendEvent(parent, &cfo);
|
||||
|
||||
if ( cfo.isAccepted() )
|
||||
out.ignore();
|
||||
|
||||
if ( out.isAccepted() )
|
||||
{
|
||||
if ( next == this )
|
||||
if ( ! accpt )
|
||||
return false;
|
||||
|
||||
next->setFocus();
|
||||
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
||||
FApplication::sendEvent(parent, &cfi);
|
||||
break; // The focus has been changed
|
||||
}
|
||||
|
||||
FFocusEvent in (fc::FocusIn_Event);
|
||||
in.setFocusType(fc::FocusNextWidget);
|
||||
FApplication::sendEvent(next, &in);
|
||||
|
||||
if ( in.isAccepted() )
|
||||
{
|
||||
redraw();
|
||||
next->redraw();
|
||||
updateTerminal();
|
||||
flush_out();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FWidget::focusPrevChild()
|
||||
{
|
||||
if ( isDialogWidget() )
|
||||
if ( isDialogWidget() || ! hasParent() )
|
||||
return false;
|
||||
|
||||
if ( hasParent() )
|
||||
{
|
||||
FWidget* parent = getParentWidget();
|
||||
|
||||
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
||||
{
|
||||
if ( ! parent->hasChildren() || parent->numOfFocusableChildren() <= 1 )
|
||||
return false;
|
||||
|
||||
FObjectIterator iter, first;
|
||||
iter = parent->end();
|
||||
first = parent->begin();
|
||||
|
@ -1874,8 +1845,9 @@ bool FWidget::focusPrevChild()
|
|||
|
||||
FWidget* w = static_cast<FWidget*>(*iter);
|
||||
|
||||
if ( w == this )
|
||||
{
|
||||
if ( w != this )
|
||||
continue;
|
||||
|
||||
FWidget* prev = 0;
|
||||
constFObjectIterator prev_element;
|
||||
prev_element = iter;
|
||||
|
@ -1899,46 +1871,14 @@ bool FWidget::focusPrevChild()
|
|||
|| ! prev->isVisible()
|
||||
|| prev->isWindowWidget() );
|
||||
|
||||
FFocusEvent out (fc::FocusOut_Event);
|
||||
out.setFocusType(fc::FocusPreviousWidget);
|
||||
FApplication::sendEvent(this, &out);
|
||||
bool accpt = changeFocus (prev, parent, fc::FocusPreviousWidget);
|
||||
|
||||
FFocusEvent cfo (fc::ChildFocusOut_Event);
|
||||
cfo.setFocusType(fc::FocusPreviousWidget);
|
||||
cfo.ignore();
|
||||
FApplication::sendEvent(parent, &cfo);
|
||||
|
||||
if ( cfo.isAccepted() )
|
||||
out.ignore();
|
||||
|
||||
if ( out.isAccepted() )
|
||||
{
|
||||
if ( prev == this )
|
||||
if ( ! accpt )
|
||||
return false;
|
||||
|
||||
prev->setFocus();
|
||||
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
||||
FApplication::sendEvent(parent, &cfi);
|
||||
|
||||
FFocusEvent in (fc::FocusIn_Event);
|
||||
in.setFocusType(fc::FocusPreviousWidget);
|
||||
FApplication::sendEvent(prev, &in);
|
||||
|
||||
if ( in.isAccepted() )
|
||||
{
|
||||
redraw();
|
||||
prev->redraw();
|
||||
updateTerminal();
|
||||
flush_out();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
break; // The focus has been changed
|
||||
}
|
||||
while ( iter != first );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2294,6 +2234,47 @@ void FWidget::KeyDownEvent (FKeyEvent* kev)
|
|||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FWidget::changeFocus ( FWidget* follower, FWidget* parent
|
||||
, fc::FocusTypes ft )
|
||||
{
|
||||
FFocusEvent out (fc::FocusOut_Event);
|
||||
out.setFocusType(ft);
|
||||
FApplication::sendEvent(this, &out);
|
||||
|
||||
FFocusEvent cfo (fc::ChildFocusOut_Event);
|
||||
cfo.setFocusType(ft);
|
||||
cfo.ignore();
|
||||
FApplication::sendEvent(parent, &cfo);
|
||||
|
||||
if ( cfo.isAccepted() )
|
||||
out.ignore();
|
||||
|
||||
if ( out.isAccepted() )
|
||||
{
|
||||
if ( follower == this )
|
||||
return false;
|
||||
|
||||
follower->setFocus();
|
||||
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
||||
FApplication::sendEvent(parent, &cfi);
|
||||
|
||||
FFocusEvent in (fc::FocusIn_Event);
|
||||
in.setFocusType(ft);
|
||||
FApplication::sendEvent(follower, &in);
|
||||
|
||||
if ( in.isAccepted() )
|
||||
{
|
||||
redraw();
|
||||
follower->redraw();
|
||||
updateTerminal();
|
||||
flush_out();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FWidget::draw()
|
||||
{ }
|
||||
|
|
Loading…
Reference in New Issue