2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fscrollview.cpp - Widget FScrollView (a scrolling area with *
|
|
|
|
* on-demand scroll bars) *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2017-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2018-12-28 22:57:43 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fevent.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fscrollview.h"
|
|
|
|
#include "final/fwindow.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fwidgetcolors.h"
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FScrollView
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FScrollView::FScrollView (FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FWidget{parent}
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-03-08 23:48:30 +01:00
|
|
|
init(parent);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
FScrollView::~FScrollView() // destructor
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
removeArea (viewport);
|
2019-09-01 23:29:27 +02:00
|
|
|
viewport = nullptr;
|
|
|
|
setChildPrintArea (viewport);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// public methods of FScrollView
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FScrollView::setScrollWidth (std::size_t width)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( width < getViewportWidth() )
|
|
|
|
width = getViewportWidth();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-03 05:19:44 +01:00
|
|
|
if ( getScrollWidth() == width )
|
2017-01-02 08:07:46 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( viewport )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const FSize no_shadow(0, 0);
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setWidth (width);
|
|
|
|
resizeArea (scroll_geometry, no_shadow, viewport);
|
2017-02-18 23:37:10 +01:00
|
|
|
|
|
|
|
addPreprocessingHandler
|
2017-01-15 19:48:27 +01:00
|
|
|
(
|
2017-04-09 20:08:53 +02:00
|
|
|
F_PREPROC_HANDLER (this, &FScrollView::copy2area)
|
2017-01-15 19:48:27 +01:00
|
|
|
);
|
2019-09-01 23:29:27 +02:00
|
|
|
setChildPrintArea (viewport);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
hbar->setMaximum (int(width - getViewportWidth()));
|
|
|
|
hbar->setPageSize (int(width), int(getViewportWidth()));
|
2017-01-02 08:07:46 +01:00
|
|
|
hbar->calculateSliderValues();
|
2019-06-12 11:37:34 +02:00
|
|
|
|
|
|
|
if ( isShown() )
|
|
|
|
setHorizontalScrollBarVisibility();
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FScrollView::setScrollHeight (std::size_t height)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( height < getViewportHeight() )
|
|
|
|
height = getViewportHeight();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-03 05:19:44 +01:00
|
|
|
if ( getScrollHeight() == height )
|
2017-01-02 08:07:46 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( viewport )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const FSize no_shadow(0, 0);
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setHeight (height);
|
|
|
|
resizeArea (scroll_geometry, no_shadow, viewport);
|
2017-02-18 23:37:10 +01:00
|
|
|
addPreprocessingHandler
|
2017-01-15 19:48:27 +01:00
|
|
|
(
|
2017-04-09 20:08:53 +02:00
|
|
|
F_PREPROC_HANDLER (this, &FScrollView::copy2area)
|
2017-01-15 19:48:27 +01:00
|
|
|
);
|
2019-09-01 23:29:27 +02:00
|
|
|
setChildPrintArea (viewport);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setMaximum (int(height - getViewportHeight()));
|
|
|
|
vbar->setPageSize (int(height), int(getViewportHeight()));
|
2017-01-02 08:07:46 +01:00
|
|
|
vbar->calculateSliderValues();
|
2019-06-12 11:37:34 +02:00
|
|
|
|
|
|
|
if ( isShown() )
|
|
|
|
setVerticalScrollBarVisibility();
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FScrollView::setScrollSize (const FSize& size)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
std::size_t width = size.getWidth();
|
|
|
|
std::size_t height = size.getHeight();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( width < getViewportWidth() )
|
|
|
|
width = getViewportWidth();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( height < getViewportHeight() )
|
|
|
|
height = getViewportHeight();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-03 05:19:44 +01:00
|
|
|
if ( getScrollWidth() == width && getScrollHeight() == height )
|
2017-01-02 08:07:46 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( viewport )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const FSize no_shadow(0, 0);
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setSize (width, height);
|
|
|
|
resizeArea (scroll_geometry, no_shadow, viewport);
|
2017-02-18 23:37:10 +01:00
|
|
|
addPreprocessingHandler
|
2017-01-15 19:48:27 +01:00
|
|
|
(
|
2017-04-09 20:08:53 +02:00
|
|
|
F_PREPROC_HANDLER (this, &FScrollView::copy2area)
|
2017-01-15 19:48:27 +01:00
|
|
|
);
|
2019-09-01 23:29:27 +02:00
|
|
|
setChildPrintArea (viewport);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const int xoffset_end = int(getScrollWidth() - getViewportWidth());
|
|
|
|
const int yoffset_end = int(getScrollHeight() - getViewportHeight());
|
2017-01-22 23:04:40 +01:00
|
|
|
setTopPadding (1 - getScrollY());
|
|
|
|
setLeftPadding (1 - getScrollX());
|
2017-09-11 03:06:02 +02:00
|
|
|
setBottomPadding (1 - (yoffset_end - getScrollY()));
|
2018-10-17 22:12:52 +02:00
|
|
|
setRightPadding (1 - (xoffset_end - getScrollX()) + int(nf_offset));
|
2017-01-22 23:04:40 +01:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
hbar->setMaximum (int(width - getViewportWidth()));
|
|
|
|
hbar->setPageSize (int(width), int(getViewportWidth()));
|
2017-01-02 08:07:46 +01:00
|
|
|
hbar->calculateSliderValues();
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setMaximum (int(height - getViewportHeight()));
|
|
|
|
vbar->setPageSize (int(height), int(getViewportHeight()));
|
2017-01-02 08:07:46 +01:00
|
|
|
vbar->calculateSliderValues();
|
2019-06-12 11:37:34 +02:00
|
|
|
|
|
|
|
if ( isShown() )
|
|
|
|
{
|
|
|
|
setHorizontalScrollBarVisibility();
|
|
|
|
setVerticalScrollBarVisibility();
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setX (int x, bool adjust)
|
|
|
|
{
|
|
|
|
FWidget::setX (x, adjust);
|
2017-01-03 05:19:44 +01:00
|
|
|
|
|
|
|
if ( ! adjust )
|
|
|
|
{
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setX (getTermX() + getLeftPadding() - 1);
|
2017-01-03 05:19:44 +01:00
|
|
|
|
|
|
|
if ( viewport )
|
|
|
|
{
|
2017-02-25 15:18:29 +01:00
|
|
|
viewport->offset_left = scroll_geometry.getX();
|
|
|
|
viewport->offset_top = scroll_geometry.getY();
|
2017-01-03 05:19:44 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setY (int y, bool adjust)
|
|
|
|
{
|
|
|
|
FWidget::setY (y, adjust);
|
2017-01-03 05:19:44 +01:00
|
|
|
|
|
|
|
if ( ! adjust )
|
|
|
|
{
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setY (getTermY() + getTopPadding() - 1);
|
2017-01-03 05:19:44 +01:00
|
|
|
|
|
|
|
if ( viewport )
|
|
|
|
{
|
2017-02-25 15:18:29 +01:00
|
|
|
viewport->offset_left = scroll_geometry.getX();
|
|
|
|
viewport->offset_top = scroll_geometry.getY();
|
2017-01-03 05:19:44 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FScrollView::setPos (const FPoint& p, bool adjust)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
FWidget::setPos (p, adjust);
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1
|
2017-02-18 23:37:10 +01:00
|
|
|
, getTermY() + getTopPadding() - 1 );
|
2017-01-03 05:19:44 +01:00
|
|
|
|
2020-04-19 20:38:52 +02:00
|
|
|
if ( ! adjust && viewport )
|
2017-01-03 05:19:44 +01:00
|
|
|
{
|
2020-04-19 20:38:52 +02:00
|
|
|
viewport->offset_left = scroll_geometry.getX();
|
|
|
|
viewport->offset_top = scroll_geometry.getY();
|
2017-01-03 05:19:44 +01:00
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FScrollView::setWidth (std::size_t w, bool adjust)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
FWidget::setWidth (w, adjust);
|
2018-10-17 22:12:52 +02:00
|
|
|
viewport_geometry.setWidth(w - vertical_border_spacing - nf_offset);
|
2017-01-02 08:07:46 +01:00
|
|
|
calculateScrollbarPos();
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollWidth() < getViewportWidth() )
|
|
|
|
setScrollWidth (getViewportWidth());
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FScrollView::setHeight (std::size_t h, bool adjust)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
FWidget::setHeight (h, adjust);
|
2017-02-20 00:00:53 +01:00
|
|
|
viewport_geometry.setHeight(h - horizontal_border_spacing);
|
2017-01-02 08:07:46 +01:00
|
|
|
calculateScrollbarPos();
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollHeight() < getViewportHeight() )
|
|
|
|
setScrollHeight (getViewportHeight());
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FScrollView::setSize (const FSize& size, bool adjust)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t w = size.getWidth();
|
|
|
|
const std::size_t h = size.getHeight();
|
2019-01-21 03:42:18 +01:00
|
|
|
FWidget::setSize (size, adjust);
|
2018-10-17 22:12:52 +02:00
|
|
|
viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset
|
2017-02-20 00:00:53 +01:00
|
|
|
, h - horizontal_border_spacing );
|
2017-01-02 08:07:46 +01:00
|
|
|
calculateScrollbarPos();
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollWidth() < getViewportWidth()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| getScrollHeight() < getViewportHeight() )
|
2019-01-21 03:42:18 +01:00
|
|
|
setScrollSize (getViewportSize());
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FScrollView::setGeometry ( const FPoint& pos, const FSize& size
|
2018-10-17 22:12:52 +02:00
|
|
|
, bool adjust )
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-08-06 17:02:19 +02:00
|
|
|
// Set the scroll view geometry
|
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
FWidget::setGeometry (pos, size, adjust);
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t w = size.getWidth();
|
|
|
|
const std::size_t h = size.getHeight();
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1
|
|
|
|
, getTermY() + getTopPadding() - 1 );
|
2018-10-17 22:12:52 +02:00
|
|
|
viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset
|
2017-02-20 00:00:53 +01:00
|
|
|
, h - horizontal_border_spacing );
|
2017-01-02 08:07:46 +01:00
|
|
|
calculateScrollbarPos();
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollWidth() < getViewportWidth()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| getScrollHeight() < getViewportHeight() )
|
2017-01-03 05:19:44 +01:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
setScrollSize (getViewportSize());
|
2017-01-03 05:19:44 +01:00
|
|
|
}
|
|
|
|
else if ( ! adjust && viewport )
|
|
|
|
{
|
2017-02-25 15:18:29 +01:00
|
|
|
viewport->offset_left = scroll_geometry.getX();
|
|
|
|
viewport->offset_top = scroll_geometry.getY();
|
2017-01-03 05:19:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 00:30:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-18 13:33:42 +02:00
|
|
|
bool FScrollView::setCursorPos (const FPoint& p)
|
2017-02-24 00:30:07 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
return FWidget::setCursorPos ({ p.getX() + getLeftPadding()
|
|
|
|
, p.getY() + getTopPadding() });
|
2017-02-24 00:30:07 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 22:09:09 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FScrollView::setPrintPos (const FPoint& p)
|
2017-01-07 22:09:09 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
FWidget::setPrintPos (FPoint { p.getX() + getLeftPadding()
|
|
|
|
, p.getY() + getTopPadding() });
|
2017-01-07 22:09:09 +01:00
|
|
|
}
|
|
|
|
|
2017-02-18 23:37:10 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
bool FScrollView::setViewportPrint (bool enable)
|
2017-02-18 23:37:10 +01:00
|
|
|
{
|
2018-12-22 23:50:10 +01:00
|
|
|
return (use_own_print_area = ! enable);
|
2017-02-18 23:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
bool FScrollView::setBorder (bool enable)
|
2017-02-18 23:37:10 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
return (setFlags().no_border = ! enable);
|
2017-02-18 23:37:10 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 05:19:44 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setHorizontalScrollBarMode (fc::scrollBarMode mode)
|
|
|
|
{
|
2020-03-22 21:53:27 +01:00
|
|
|
h_mode = mode;
|
2019-06-12 11:37:34 +02:00
|
|
|
|
|
|
|
if ( isShown() )
|
|
|
|
setHorizontalScrollBarVisibility();
|
2017-01-03 05:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setVerticalScrollBarMode (fc::scrollBarMode mode)
|
|
|
|
{
|
2020-03-22 21:53:27 +01:00
|
|
|
v_mode = mode;
|
2019-06-12 11:37:34 +02:00
|
|
|
|
|
|
|
if ( isShown() )
|
|
|
|
setVerticalScrollBarVisibility();
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::clearArea (int fillchar)
|
|
|
|
{
|
|
|
|
if ( viewport )
|
|
|
|
clearArea (viewport, fillchar);
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:09:09 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::scrollToX (int x)
|
|
|
|
{
|
2017-01-26 00:31:07 +01:00
|
|
|
scrollTo (x, viewport_geometry.getY() + 1);
|
2017-01-07 22:09:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::scrollToY (int y)
|
|
|
|
{
|
2017-01-26 00:31:07 +01:00
|
|
|
scrollTo (viewport_geometry.getX() + 1, y);
|
2017-01-07 22:09:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::scrollTo (int x, int y)
|
|
|
|
{
|
2018-11-21 22:15:14 +01:00
|
|
|
int& xoffset = viewport_geometry.x1_ref();
|
|
|
|
int& yoffset = viewport_geometry.y1_ref();
|
2020-02-05 08:57:13 +01:00
|
|
|
const int xoffset_before = xoffset;
|
|
|
|
const int yoffset_before = yoffset;
|
|
|
|
const int xoffset_end = int(getScrollWidth() - getViewportWidth());
|
|
|
|
const int yoffset_end = int(getScrollHeight() - getViewportHeight());
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t save_width = viewport_geometry.getWidth();
|
|
|
|
const std::size_t save_height = viewport_geometry.getHeight();
|
2017-01-22 23:04:40 +01:00
|
|
|
x--;
|
|
|
|
y--;
|
2017-01-07 22:09:09 +01:00
|
|
|
|
2018-11-21 22:15:14 +01:00
|
|
|
if ( xoffset == x && yoffset == y )
|
2017-01-07 22:09:09 +01:00
|
|
|
return;
|
|
|
|
|
2018-11-21 22:15:14 +01:00
|
|
|
xoffset = x;
|
|
|
|
yoffset = y;
|
2017-01-07 22:09:09 +01:00
|
|
|
|
|
|
|
if ( yoffset < 0 )
|
|
|
|
yoffset = 0;
|
|
|
|
|
|
|
|
if ( yoffset > yoffset_end )
|
|
|
|
yoffset = yoffset_end;
|
|
|
|
|
|
|
|
if ( xoffset < 0 )
|
|
|
|
xoffset = 0;
|
|
|
|
|
|
|
|
if ( xoffset > xoffset_end )
|
|
|
|
xoffset = xoffset_end;
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const bool changeX( xoffset_before != xoffset );
|
|
|
|
const bool changeY( yoffset_before != yoffset );
|
2017-12-27 23:51:32 +01:00
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
if ( ! isShown() || ! viewport || ! (changeX || changeY) )
|
2017-12-27 23:51:32 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( changeX )
|
|
|
|
{
|
|
|
|
viewport_geometry.setWidth(save_width);
|
2018-01-21 16:21:41 +01:00
|
|
|
setLeftPadding (1 - xoffset);
|
2018-11-21 22:15:14 +01:00
|
|
|
setRightPadding (1 - (xoffset_end - xoffset) + int(nf_offset));
|
2017-12-27 23:51:32 +01:00
|
|
|
|
|
|
|
if ( update_scrollbar )
|
|
|
|
{
|
|
|
|
hbar->setValue (xoffset);
|
2019-01-11 22:16:59 +01:00
|
|
|
hbar->drawBar();
|
2017-12-27 23:51:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( changeY )
|
|
|
|
{
|
|
|
|
viewport_geometry.setHeight(save_height);
|
2018-01-21 16:21:41 +01:00
|
|
|
setTopPadding (1 - yoffset);
|
|
|
|
setBottomPadding (1 - (yoffset_end - yoffset));
|
2017-12-27 23:51:32 +01:00
|
|
|
|
|
|
|
if ( update_scrollbar )
|
|
|
|
{
|
|
|
|
vbar->setValue (yoffset);
|
2019-01-11 22:16:59 +01:00
|
|
|
vbar->drawBar();
|
2017-12-27 23:51:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:09:09 +01:00
|
|
|
viewport->has_changes = true;
|
|
|
|
copy2area();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::scrollBy (int dx, int dy)
|
|
|
|
{
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollTo (1 + getScrollX() + dx, 1 + getScrollY() + dy);
|
2017-01-07 22:09:09 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::draw()
|
|
|
|
{
|
2017-02-18 23:37:10 +01:00
|
|
|
unsetViewportPrint();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2017-01-28 23:20:38 +01:00
|
|
|
setReverse(true);
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
if ( const auto& p = getParentWidget() )
|
2017-01-02 08:07:46 +01:00
|
|
|
setColor (p->getForegroundColor(), p->getBackgroundColor());
|
|
|
|
else
|
2017-01-15 19:48:27 +01:00
|
|
|
setColor();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
if ( hasBorder() )
|
2019-08-11 20:07:39 +02:00
|
|
|
drawBorder();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2017-01-28 23:20:38 +01:00
|
|
|
setReverse(false);
|
|
|
|
|
2017-02-18 23:37:10 +01:00
|
|
|
setViewportPrint();
|
2017-01-02 08:07:46 +01:00
|
|
|
copy2area();
|
2019-06-12 11:37:34 +02:00
|
|
|
|
|
|
|
if ( ! hbar->isShown() )
|
|
|
|
setHorizontalScrollBarVisibility();
|
|
|
|
|
|
|
|
if ( ! vbar->isShown() )
|
|
|
|
setVerticalScrollBarVisibility();
|
|
|
|
|
2019-01-11 22:16:59 +01:00
|
|
|
vbar->redraw();
|
|
|
|
hbar->redraw();
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 19:02:04 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-08-11 20:07:39 +02:00
|
|
|
void FScrollView::drawBorder()
|
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
const FRect box(FPoint{1, 1}, getSize());
|
2019-11-06 02:40:47 +01:00
|
|
|
finalcut::drawListBorder (this, box);
|
2019-08-11 20:07:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-01-03 19:02:04 +01:00
|
|
|
void FScrollView::onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const int idx = int(ev->key());
|
2017-01-03 19:02:04 +01:00
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
if ( key_map.find(idx) != key_map.end() )
|
2017-01-03 19:02:04 +01:00
|
|
|
{
|
2019-10-05 23:20:07 +02:00
|
|
|
key_map[idx]();
|
|
|
|
ev->accept();
|
2017-01-03 19:02:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::onWheel (FWheelEvent* ev)
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
static constexpr int distance = 4;
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
switch ( ev->getWheel() )
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
case fc::WheelUp:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, -distance);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::WheelDown:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, distance);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 00:31:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-01-28 22:03:15 +01:00
|
|
|
void FScrollView::onFocusIn (FFocusEvent* in_ev)
|
|
|
|
{
|
|
|
|
// Sets the focus to a child widget if it exists
|
|
|
|
|
|
|
|
if ( hasChildren() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto prev_element = getFocusWidget();
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( in_ev->getFocusType() == fc::FocusNextWidget )
|
|
|
|
focusFirstChild();
|
|
|
|
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
|
|
|
|
focusLastChild();
|
|
|
|
|
|
|
|
if ( prev_element )
|
|
|
|
prev_element->redraw();
|
|
|
|
|
|
|
|
if ( getFocusWidget() )
|
|
|
|
getFocusWidget()->redraw();
|
|
|
|
|
|
|
|
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
|
|
|
onChildFocusIn(&cfi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::onChildFocusIn (FFocusEvent*)
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
|
|
|
// Scrolls the viewport so that the focused widget is visible
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& focus = FWidget::getFocusWidget();
|
2017-01-26 00:31:07 +01:00
|
|
|
|
2018-12-01 21:28:25 +01:00
|
|
|
if ( ! focus )
|
2017-01-26 00:31:07 +01:00
|
|
|
return;
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const FRect widget_geometry = focus->getGeometryWithShadow();
|
|
|
|
FRect vp_geometry = viewport_geometry;
|
2018-11-20 21:11:04 +01:00
|
|
|
vp_geometry.move(1, 1);
|
2017-01-26 00:31:07 +01:00
|
|
|
|
2017-02-20 00:00:53 +01:00
|
|
|
if ( ! vp_geometry.contains(widget_geometry) )
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
int x{};
|
|
|
|
int y{};
|
|
|
|
const int vx = vp_geometry.getX();
|
|
|
|
const int vy = vp_geometry.getY();
|
|
|
|
const int wx = widget_geometry.getX();
|
|
|
|
const int wy = widget_geometry.getY();
|
2017-01-26 00:31:07 +01:00
|
|
|
|
|
|
|
if ( wx > vx )
|
2018-10-14 06:25:33 +02:00
|
|
|
x = widget_geometry.getX2() - int(vp_geometry.getWidth()) + 1;
|
2017-01-26 00:37:02 +01:00
|
|
|
else
|
2017-01-26 00:31:07 +01:00
|
|
|
x = wx;
|
|
|
|
|
|
|
|
if ( wy > vy )
|
2018-10-14 06:25:33 +02:00
|
|
|
y = widget_geometry.getY2() - int(vp_geometry.getHeight()) + 1;
|
2017-01-26 00:37:02 +01:00
|
|
|
else
|
2017-01-26 00:31:07 +01:00
|
|
|
y = wy;
|
|
|
|
|
|
|
|
scrollTo (x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::onChildFocusOut (FFocusEvent* out_ev)
|
|
|
|
{
|
|
|
|
// Change the focus away from FScrollView to another widget
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& focus = FWidget::getFocusWidget();
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( out_ev->getFocusType() == fc::FocusNextWidget )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& last_widget = getLastFocusableWidget(getChildren());
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2018-12-01 21:28:25 +01:00
|
|
|
if ( focus == last_widget )
|
2017-01-28 22:03:15 +01:00
|
|
|
{
|
|
|
|
out_ev->accept();
|
|
|
|
focusNextChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( out_ev->getFocusType() == fc::FocusPreviousWidget )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& first_widget = getFirstFocusableWidget(getChildren());
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2018-12-01 21:28:25 +01:00
|
|
|
if ( focus == first_widget )
|
2017-01-28 22:03:15 +01:00
|
|
|
{
|
|
|
|
out_ev->accept();
|
|
|
|
focusPrevChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
// protected methods of FScrollView
|
|
|
|
//----------------------------------------------------------------------
|
2019-10-08 04:37:19 +02:00
|
|
|
FVTerm::FTermArea* FScrollView::getPrintArea()
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-01-07 22:09:09 +01:00
|
|
|
// returns print area or viewport
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-07 22:09:09 +01:00
|
|
|
if ( use_own_print_area || ! viewport )
|
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
setChildPrintArea (nullptr);
|
2018-12-15 00:50:09 +01:00
|
|
|
auto area = FWidget::getPrintArea();
|
2019-09-01 23:29:27 +02:00
|
|
|
setChildPrintArea (viewport);
|
2017-01-07 22:09:09 +01:00
|
|
|
return area;
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
else
|
2017-01-07 22:09:09 +01:00
|
|
|
return viewport;
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::adjustSize()
|
|
|
|
{
|
|
|
|
FWidget::adjustSize();
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t width = getWidth();
|
|
|
|
const std::size_t height = getHeight();
|
|
|
|
const int xoffset = viewport_geometry.getX();
|
|
|
|
const int yoffset = viewport_geometry.getY();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-26 00:31:07 +01:00
|
|
|
scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1
|
|
|
|
, getTermY() + getTopPadding() - 1 );
|
2017-01-03 05:19:44 +01:00
|
|
|
|
|
|
|
if ( viewport )
|
|
|
|
{
|
2017-02-25 15:18:29 +01:00
|
|
|
viewport->offset_left = scroll_geometry.getX();
|
|
|
|
viewport->offset_top = scroll_geometry.getY();
|
2017-01-03 05:19:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
hbar->setMaximum (int(getScrollWidth() - getViewportWidth()));
|
|
|
|
hbar->setPageSize (int(getScrollWidth()), int(getViewportWidth()));
|
|
|
|
hbar->setY (int(height));
|
2017-01-02 08:07:46 +01:00
|
|
|
hbar->setWidth (width - 2, false);
|
|
|
|
hbar->setValue (xoffset);
|
|
|
|
hbar->resize();
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setMaximum (int(getScrollHeight() - getViewportHeight()));
|
|
|
|
vbar->setPageSize (int(getScrollHeight()), int(getViewportHeight()));
|
|
|
|
vbar->setX (int(width));
|
2017-01-02 08:07:46 +01:00
|
|
|
vbar->setHeight (height - 2, false);
|
|
|
|
vbar->setValue (yoffset);
|
|
|
|
vbar->resize();
|
2019-06-12 11:37:34 +02:00
|
|
|
|
|
|
|
if ( isShown() )
|
|
|
|
{
|
|
|
|
setHorizontalScrollBarVisibility();
|
|
|
|
setVerticalScrollBarVisibility();
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::copy2area()
|
|
|
|
{
|
|
|
|
// copy viewport to area
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( ! hasPrintArea() )
|
2017-10-30 20:29:00 +01:00
|
|
|
FWidget::getPrintArea();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( ! (hasPrintArea() && viewport) )
|
2017-01-02 08:07:46 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! viewport->has_changes )
|
|
|
|
return;
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
auto printarea = getCurrentPrintArea();
|
2020-02-02 22:34:27 +01:00
|
|
|
const int ax = getTermX() - printarea->offset_left;
|
|
|
|
const int ay = getTermY() - printarea->offset_top;
|
|
|
|
const int dx = viewport_geometry.getX();
|
|
|
|
const int dy = viewport_geometry.getY();
|
|
|
|
int y_end = int(getViewportHeight());
|
|
|
|
int x_end = int(getViewportWidth());
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// viewport width does not fit into the printarea
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( printarea->width <= ax + x_end )
|
|
|
|
x_end = printarea->width - ax;
|
2017-10-06 12:19:39 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// viewport height does not fit into the printarea
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( printarea->height <= ay + y_end )
|
|
|
|
y_end = printarea->height - ay;
|
2017-10-06 12:19:39 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int y{0}; y < y_end; y++) // line loop
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2020-04-13 12:40:11 +02:00
|
|
|
const FChar* vc{}; // viewport character
|
2019-10-08 04:37:19 +02:00
|
|
|
FChar* ac{}; // area character
|
2020-02-02 22:34:27 +01:00
|
|
|
const int v_line_len = viewport->width;
|
|
|
|
const int a_line_len = printarea->width + printarea->right_shadow;
|
2019-10-08 04:37:19 +02:00
|
|
|
vc = &viewport->data[(dy + y) * v_line_len + dx];
|
|
|
|
ac = &printarea->data[(ay + y) * a_line_len + ax];
|
|
|
|
std::memcpy (ac, vc, sizeof(FChar) * unsigned(x_end));
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( int(printarea->changes[ay + y].xmin) > ax )
|
|
|
|
printarea->changes[ay + y].xmin = uInt(ax);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( int(printarea->changes[ay + y].xmax) < ax + x_end - 1 )
|
|
|
|
printarea->changes[ay + y].xmax = uInt(ax + x_end - 1);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
setViewportCursor();
|
2017-01-02 08:07:46 +01:00
|
|
|
viewport->has_changes = false;
|
2019-09-01 23:29:27 +02:00
|
|
|
printarea->has_changes = true;
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FScrollView
|
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
inline const FPoint FScrollView::getViewportCursorPos()
|
2017-03-08 23:48:30 +01:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& window = FWindow::getWindowWidget(this);
|
2017-03-12 00:29:56 +01:00
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
if ( window )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const int widget_offsetX = getTermX() - window->getTermX();
|
|
|
|
const int widget_offsetY = getTermY() - window->getTermY();
|
|
|
|
const int x = widget_offsetX + viewport->input_cursor_x
|
|
|
|
- viewport_geometry.getX();
|
|
|
|
const int y = widget_offsetY + viewport->input_cursor_y
|
|
|
|
- viewport_geometry.getY();
|
2020-05-02 00:07:35 +02:00
|
|
|
return { x, y };
|
2017-03-08 23:48:30 +01:00
|
|
|
}
|
|
|
|
else
|
2020-05-02 00:07:35 +02:00
|
|
|
return { -1, -1 };
|
2017-03-08 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
void FScrollView::init (const FWidget* parent)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2020-02-19 21:59:13 +01:00
|
|
|
assert ( parent != nullptr );
|
2017-07-23 01:19:59 +02:00
|
|
|
assert ( ! parent->isInstanceOf("FScrollView") );
|
2017-03-08 23:48:30 +01:00
|
|
|
|
2020-03-22 21:53:27 +01:00
|
|
|
initScrollbar (vbar, fc::vertical, &FScrollView::cb_vbarChange);
|
|
|
|
initScrollbar (hbar, fc::horizontal, &FScrollView::cb_hbarChange);
|
2019-10-05 23:20:07 +02:00
|
|
|
mapKeyFunctions();
|
2019-09-28 03:13:06 +02:00
|
|
|
const auto& wc = getFWidgetColors();
|
2017-01-15 19:48:27 +01:00
|
|
|
setForegroundColor (wc.dialog_fg);
|
|
|
|
setBackgroundColor (wc.dialog_bg);
|
2020-05-02 00:07:35 +02:00
|
|
|
setGeometry (FPoint{1, 1}, FSize{4, 4});
|
|
|
|
setMinimumSize (FSize{4, 4});
|
2020-02-02 22:34:27 +01:00
|
|
|
const int xoffset_end = int(getScrollWidth() - getViewportWidth());
|
|
|
|
const int yoffset_end = int(getScrollHeight() - getViewportHeight());
|
2020-05-16 22:24:36 +02:00
|
|
|
nf_offset = FTerm::isNewFont() ? 1 : 0;
|
2018-02-19 23:02:19 +01:00
|
|
|
setTopPadding (1 - getScrollY());
|
|
|
|
setLeftPadding (1 - getScrollX());
|
|
|
|
setBottomPadding (1 - (yoffset_end - getScrollY()));
|
|
|
|
setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset);
|
2020-05-02 00:07:35 +02:00
|
|
|
const FSize no_shadow{0, 0};
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t w = getViewportWidth();
|
|
|
|
std::size_t h = getViewportHeight();
|
2018-02-19 23:02:19 +01:00
|
|
|
|
|
|
|
if ( w < 1 )
|
|
|
|
w = 1;
|
|
|
|
|
|
|
|
if ( h < 1 )
|
|
|
|
h = 1;
|
|
|
|
|
|
|
|
scroll_geometry.setRect (0, 0, w, h);
|
|
|
|
createArea (scroll_geometry, no_shadow, viewport);
|
|
|
|
addPreprocessingHandler
|
|
|
|
(
|
|
|
|
F_PREPROC_HANDLER (this, &FScrollView::copy2area)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( viewport )
|
2019-09-01 23:29:27 +02:00
|
|
|
setChildPrintArea (viewport);
|
2018-02-19 23:02:19 +01:00
|
|
|
}
|
2017-01-15 19:48:27 +01:00
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollView::mapKeyFunctions()
|
|
|
|
{
|
2020-04-18 13:33:42 +02:00
|
|
|
key_map[fc::Fkey_up] = [this] { scrollBy (0, -1); };
|
|
|
|
key_map[fc::Fkey_down] = [this] { scrollBy (0, 1); };
|
|
|
|
key_map[fc::Fkey_left] = [this] { scrollBy (-1, 0); };
|
|
|
|
key_map[fc::Fkey_right] = [this] { scrollBy (1, 0); };
|
|
|
|
key_map[fc::Fkey_ppage] = [this] { scrollBy (0, -int(getViewportHeight())); };
|
|
|
|
key_map[fc::Fkey_npage] = [this] { scrollBy (0, int(getViewportHeight())); };
|
|
|
|
key_map[fc::Fkey_home] = [this] { scrollToY (1); };
|
2019-10-05 23:20:07 +02:00
|
|
|
key_map[fc::Fkey_end] = \
|
2020-04-18 13:33:42 +02:00
|
|
|
[this] ()
|
2019-10-05 23:20:07 +02:00
|
|
|
{
|
|
|
|
int yoffset_end = int(getScrollHeight() - getViewportHeight());
|
|
|
|
scrollToY (1 + yoffset_end);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::calculateScrollbarPos()
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t width = getWidth();
|
|
|
|
const std::size_t height = getHeight();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
vbar->setGeometry (FPoint{int(width), 2}, FSize{2, height - 2});
|
|
|
|
hbar->setGeometry (FPoint{1, int(height)}, FSize{width - 2, 1});
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
vbar->setGeometry (FPoint{int(width), 2}, FSize{1, height - 2});
|
|
|
|
hbar->setGeometry (FPoint{2, int(height)}, FSize{width - 2, 1});
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
vbar->resize();
|
|
|
|
hbar->resize();
|
|
|
|
}
|
|
|
|
|
2017-01-03 05:19:44 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setHorizontalScrollBarVisibility()
|
|
|
|
{
|
2020-04-19 20:38:52 +02:00
|
|
|
assert ( v_mode == fc::Auto
|
|
|
|
|| v_mode == fc::Hidden
|
|
|
|
|| v_mode == fc::Scroll );
|
|
|
|
|
2020-03-22 21:53:27 +01:00
|
|
|
switch ( h_mode )
|
2017-01-03 05:19:44 +01:00
|
|
|
{
|
|
|
|
case fc::Auto:
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollWidth() > getViewportWidth() )
|
2019-01-09 20:05:29 +01:00
|
|
|
hbar->show();
|
2017-01-03 05:19:44 +01:00
|
|
|
else
|
|
|
|
hbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Hidden:
|
|
|
|
hbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Scroll:
|
2019-01-09 20:05:29 +01:00
|
|
|
hbar->show();
|
2017-01-03 05:19:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setVerticalScrollBarVisibility()
|
|
|
|
{
|
2020-04-19 20:38:52 +02:00
|
|
|
assert ( v_mode == fc::Auto
|
|
|
|
|| v_mode == fc::Hidden
|
|
|
|
|| v_mode == fc::Scroll );
|
|
|
|
|
2020-03-22 21:53:27 +01:00
|
|
|
switch ( v_mode )
|
2017-01-03 05:19:44 +01:00
|
|
|
{
|
|
|
|
case fc::Auto:
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollHeight() > getViewportHeight() )
|
2019-01-09 20:05:29 +01:00
|
|
|
vbar->show();
|
2017-01-03 05:19:44 +01:00
|
|
|
else
|
|
|
|
vbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Hidden:
|
|
|
|
vbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Scroll:
|
2019-01-09 20:05:29 +01:00
|
|
|
vbar->show();
|
2017-01-03 05:19:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setViewportCursor()
|
|
|
|
{
|
|
|
|
if ( ! isChild(getFocusWidget()) )
|
|
|
|
return;
|
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
const FPoint cursor_pos { viewport->input_cursor_x - 1
|
|
|
|
, viewport->input_cursor_y - 1 };
|
|
|
|
const FPoint window_cursor_pos{ getViewportCursorPos() };
|
2019-09-01 23:29:27 +02:00
|
|
|
auto printarea = getCurrentPrintArea();
|
|
|
|
printarea->input_cursor_x = window_cursor_pos.getX();
|
|
|
|
printarea->input_cursor_y = window_cursor_pos.getY();
|
2017-03-08 23:48:30 +01:00
|
|
|
|
|
|
|
if ( viewport->input_cursor_visible
|
2017-11-26 22:37:18 +01:00
|
|
|
&& viewport_geometry.contains(cursor_pos) )
|
2019-09-01 23:29:27 +02:00
|
|
|
printarea->input_cursor_visible = true;
|
2017-03-08 23:48:30 +01:00
|
|
|
else
|
2019-09-01 23:29:27 +02:00
|
|
|
printarea->input_cursor_visible = false;
|
2017-03-08 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
void FScrollView::cb_vbarChange (const FWidget*, const FDataPtr)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-12-27 23:51:32 +01:00
|
|
|
FScrollbar::sType scrollType = vbar->getScrollType();
|
2020-02-02 22:34:27 +01:00
|
|
|
static constexpr int wheel_distance = 4;
|
2019-08-25 22:16:00 +02:00
|
|
|
int distance{1};
|
2020-04-19 20:38:52 +02:00
|
|
|
assert ( scrollType == FScrollbar::noScroll
|
|
|
|
|| scrollType == FScrollbar::scrollJump
|
|
|
|
|| scrollType == FScrollbar::scrollStepBackward
|
|
|
|
|| scrollType == FScrollbar::scrollStepForward
|
|
|
|
|| scrollType == FScrollbar::scrollPageBackward
|
|
|
|
|| scrollType == FScrollbar::scrollPageForward
|
|
|
|
|| scrollType == FScrollbar::scrollWheelUp
|
|
|
|
|| scrollType == FScrollbar::scrollWheelDown );
|
2017-12-27 23:51:32 +01:00
|
|
|
|
2019-09-09 19:13:38 +02:00
|
|
|
if ( scrollType >= FScrollbar::scrollStepBackward )
|
2017-12-27 23:51:32 +01:00
|
|
|
{
|
|
|
|
update_scrollbar = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
update_scrollbar = false;
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
switch ( scrollType )
|
|
|
|
{
|
|
|
|
case FScrollbar::noScroll:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageBackward:
|
2018-11-21 22:15:14 +01:00
|
|
|
distance = int(getViewportHeight());
|
2017-01-02 08:07:46 +01:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepBackward:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, -distance);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageForward:
|
2018-11-21 22:15:14 +01:00
|
|
|
distance = int(getViewportHeight());
|
2017-01-02 08:07:46 +01:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepForward:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, distance);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollJump:
|
2018-11-21 22:15:14 +01:00
|
|
|
scrollToY (1 + int(vbar->getValue()));
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollWheelUp:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, -wheel_distance);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollWheelDown:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, wheel_distance);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
update_scrollbar = true;
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-13 12:40:11 +02:00
|
|
|
void FScrollView::cb_hbarChange (const FWidget*, const FDataPtr)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-12-27 23:51:32 +01:00
|
|
|
FScrollbar::sType scrollType = hbar->getScrollType();
|
2020-02-02 22:34:27 +01:00
|
|
|
static constexpr int wheel_distance = 4;
|
2019-08-25 22:16:00 +02:00
|
|
|
int distance{1};
|
2020-04-19 20:38:52 +02:00
|
|
|
assert ( scrollType == FScrollbar::noScroll
|
|
|
|
|| scrollType == FScrollbar::scrollJump
|
|
|
|
|| scrollType == FScrollbar::scrollStepBackward
|
|
|
|
|| scrollType == FScrollbar::scrollStepForward
|
|
|
|
|| scrollType == FScrollbar::scrollPageBackward
|
|
|
|
|| scrollType == FScrollbar::scrollPageForward
|
|
|
|
|| scrollType == FScrollbar::scrollWheelUp
|
|
|
|
|| scrollType == FScrollbar::scrollWheelDown );
|
2017-12-27 23:51:32 +01:00
|
|
|
|
2019-09-09 19:13:38 +02:00
|
|
|
if ( scrollType >= FScrollbar::scrollStepBackward )
|
2017-12-27 23:51:32 +01:00
|
|
|
{
|
|
|
|
update_scrollbar = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
update_scrollbar = false;
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
switch ( scrollType )
|
|
|
|
{
|
|
|
|
case FScrollbar::noScroll:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageBackward:
|
2018-11-21 22:15:14 +01:00
|
|
|
distance = int(getViewportWidth());
|
2017-01-02 08:07:46 +01:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepBackward:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (-distance, 0);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollPageForward:
|
2018-11-21 22:15:14 +01:00
|
|
|
distance = int(getViewportWidth());
|
2017-01-02 08:07:46 +01:00
|
|
|
// fall through
|
|
|
|
case FScrollbar::scrollStepForward:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (distance, 0);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollJump:
|
2018-11-21 22:15:14 +01:00
|
|
|
scrollToX (1 + int(hbar->getValue()));
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollWheelUp:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (-wheel_distance, 0);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FScrollbar::scrollWheelDown:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (wheel_distance, 0);
|
2017-01-02 08:07:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
update_scrollbar = true;
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
2017-01-07 22:09:09 +01:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|