From 0f16b51e048f3e4f27693794f23f723e1caf3c7e Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 18 Feb 2018 21:49:58 +0100 Subject: [PATCH] Refactoring FListView::onMouseMove --- examples/termcap.cpp | 3 +- include/final/flistview.h | 3 + src/fapplication.cpp | 6 +- src/fbuttongroup.cpp | 1 - src/flabel.cpp | 1 - src/flistview.cpp | 129 +++++++++++++++++++------------------- src/foptiattr.cpp | 2 +- src/fstatusbar.cpp | 1 - src/ftogglebutton.cpp | 1 - src/fvterm.cpp | 2 - 10 files changed, 72 insertions(+), 77 deletions(-) diff --git a/examples/termcap.cpp b/examples/termcap.cpp index e66c42f9..ea1c09e8 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -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 }, diff --git a/include/final/flistview.h b/include/final/flistview.h index e8926e24..5dd56259 100644 --- a/include/final/flistview.h +++ b/include/final/flistview.h @@ -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(); diff --git a/src/fapplication.cpp b/src/fapplication.cpp index c613bac8..625cb9b9 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -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 { diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 952a408e..7aa823fe 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -511,7 +511,6 @@ void FButtonGroup::drawLabel() FString txt = " " + text + " "; uInt length = txt.getLength(); - hotkeypos = -1; try { diff --git a/src/flabel.cpp b/src/flabel.cpp index b4fda97a..fcf4105f 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -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 { diff --git a/src/flistview.cpp b/src/flistview.cpp index a19b1a89..4b5ed696 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -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; - else - drag_scroll = fc::scrollDown; - } - - if ( current_iter.getPosition() - 1 == int(getCount()) ) - { - delOwnTimer(); - drag_scroll = fc::noScroll; - } - } + dragDown (ev->getButton()); 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) { diff --git a/src/foptiattr.cpp b/src/foptiattr.cpp index 692997d4..31f754b0 100644 --- a/src/foptiattr.cpp +++ b/src/foptiattr.cpp @@ -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 ) diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 0974afa4..359641f0 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -194,7 +194,6 @@ bool FStatusBar::hasActivatedKey() //---------------------------------------------------------------------- void FStatusBar::hide() { - int screenWidth; short fg, bg; char* blank; diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index fdf22649..d44cb377 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -509,7 +509,6 @@ void FToggleButton::drawLabel() return; uInt length = text.getLength(); - hotkeypos = -1; try { diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 889d5212..b9d13096 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -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(vterm->widget);