Refactoring FListView::onMouseMove

This commit is contained in:
Markus Gans 2018-02-18 21:49:58 +01:00
parent 06423664c0
commit 0f16b51e04
10 changed files with 72 additions and 77 deletions

View File

@ -46,12 +46,11 @@ struct termcap_string
{
const std::string name;
const fc::termcaps cap;
};
#pragma pack(pop)
// String data array
static termcap_string strings[] =
static const termcap_string strings[] =
{
{ "t_bell", fc::t_bell },
{ "t_erase_chars", fc::t_erase_chars },

View File

@ -333,6 +333,9 @@ class FListView : public FWidget
void wheelDown (int);
bool dragScrollUp (int);
bool dragScrollDown (int);
void dragUp (int);
void dragDown (int);
void stopDragScroll();
FObjectIterator appendItem (FListViewItem*);
void processClick();
void processChanged();

View File

@ -355,14 +355,14 @@ void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev)
// private methods of FApplication
//----------------------------------------------------------------------
void FApplication::init (long key_timeout, long dblclick_interval)
void FApplication::init (long key_time, long dblclick_time)
{
// Initialize keyboard values
time_keypressed.tv_sec = 0;
time_keypressed.tv_usec = 0;
// Set the keyboard keypress timeout
setKeypressTimeout (key_timeout);
setKeypressTimeout (key_time);
// Initialize mouse control
mouse = getMouseControl();
@ -373,7 +373,7 @@ void FApplication::init (long key_timeout, long dblclick_interval)
// Set the default double click interval
if ( mouse )
mouse->setDblclickInterval (dblclick_interval);
mouse->setDblclickInterval (dblclick_time);
try
{

View File

@ -511,7 +511,6 @@ void FButtonGroup::drawLabel()
FString txt = " " + text + " ";
uInt length = txt.getLength();
hotkeypos = -1;
try
{

View File

@ -555,7 +555,6 @@ void FLabel::drawMultiLine()
align_offset = getAlignOffset (int(length - 1));
printLine (label_text, length - 1, hotkeypos, align_offset);
hotkey_printed = true;
hotkeypos = -1;
}
else
{

View File

@ -846,12 +846,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
void FListView::onMouseUp (FMouseEvent* ev)
{
if ( drag_scroll != fc::noScroll )
{
delOwnTimer();
drag_scroll = fc::noScroll;
scroll_distance = 1;
scroll_timer = false;
}
stopDragScroll();
if ( ev->getButton() == fc::LeftButton )
{
@ -922,61 +917,11 @@ void FListView::onMouseMove (FMouseEvent* ev)
// auto-scrolling when dragging mouse outside the widget
if ( mouse_y < 2 )
{
// drag up
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() > 0 )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( ev->getButton() == fc::RightButton )
drag_scroll = fc::scrollUpSelect;
else
drag_scroll = fc::scrollUp;
}
if ( current_iter.getPosition() == 0 )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
dragUp (ev->getButton());
else if ( mouse_y >= getHeight() )
{
// drag down
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() <= int(getCount()) )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( ev->getButton() == fc::RightButton )
drag_scroll = fc::scrollDownSelect;
dragDown (ev->getButton());
else
drag_scroll = fc::scrollDown;
}
if ( current_iter.getPosition() - 1 == int(getCount()) )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
else
{
// no dragging
delOwnTimer();
scroll_timer = false;
scroll_distance = 1;
drag_scroll = fc::noScroll;
}
stopDragScroll();
}
//----------------------------------------------------------------------
@ -1065,12 +1010,7 @@ void FListView::onWheel (FWheelEvent* ev)
, pagesize = 4;
if ( drag_scroll != fc::noScroll )
{
delOwnTimer();
scroll_timer = false;
scroll_distance = 1;
drag_scroll = fc::noScroll;
}
stopDragScroll();
switch ( ev->getWheel() )
{
@ -1746,6 +1686,65 @@ bool FListView::dragScrollDown (int position_before)
return true;
}
//----------------------------------------------------------------------
void FListView::dragUp (int mouse_button)
{
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() > 0 )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( mouse_button == fc::RightButton )
drag_scroll = fc::scrollUpSelect;
else
drag_scroll = fc::scrollUp;
}
if ( current_iter.getPosition() == 0 )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
//----------------------------------------------------------------------
void FListView::dragDown (int mouse_button)
{
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() <= int(getCount()) )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( mouse_button == fc::RightButton )
drag_scroll = fc::scrollDownSelect;
else
drag_scroll = fc::scrollDown;
}
if ( current_iter.getPosition() - 1 == int(getCount()) )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
//----------------------------------------------------------------------
void FListView::stopDragScroll()
{
delOwnTimer();
scroll_timer = false;
scroll_distance = 1;
drag_scroll = fc::noScroll;
}
//----------------------------------------------------------------------
FObject::FObjectIterator FListView::appendItem (FListViewItem* item)
{

View File

@ -1195,7 +1195,7 @@ inline void FOptiAttr::preProcessing_cygwin_quirks (char_data*& term)
{
// Cygwin bold color fix pre processing
if ( ! cygwin_terminal )
if ( ! cygwin_terminal || ! term )
return;
if ( term->fg_color > 7 || term->bg_color > 7 )

View File

@ -194,7 +194,6 @@ bool FStatusBar::hasActivatedKey()
//----------------------------------------------------------------------
void FStatusBar::hide()
{
int screenWidth;
short fg, bg;
char* blank;

View File

@ -509,7 +509,6 @@ void FToggleButton::drawLabel()
return;
uInt length = text.getLength();
hotkeypos = -1;
try
{

View File

@ -1876,8 +1876,6 @@ FVTerm::char_data FVTerm::generateCharacter (int x, int y)
// Generates characters for a given position considering all areas
FWidget::widgetList::const_iterator iter, end;
char_data* sc; // shown character
char_data s_ch; // shadow character
char_data i_ch; // inherit background character
FWidget* widget;
widget = static_cast<FWidget*>(vterm->widget);