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 *
|
|
|
|
* *
|
2018-01-21 16:25:19 +01:00
|
|
|
* Copyright 2017-2018 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
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fscrollview.h"
|
|
|
|
#include "final/fwindow.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)
|
|
|
|
: FWidget(parent)
|
|
|
|
{
|
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);
|
2018-12-10 01:48:26 +01:00
|
|
|
child_print_area = viewport = nullptr;
|
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 )
|
|
|
|
{
|
2018-11-20 21:11:04 +01:00
|
|
|
FPoint 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
|
|
|
);
|
2017-01-07 22:09:09 +01:00
|
|
|
child_print_area = 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();
|
2017-01-03 05:19:44 +01:00
|
|
|
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 )
|
|
|
|
{
|
2018-11-20 21:11:04 +01:00
|
|
|
FPoint 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
|
|
|
);
|
2017-01-07 22:09:09 +01:00
|
|
|
child_print_area = 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();
|
2017-01-03 05:19:44 +01:00
|
|
|
setVerticalScrollBarVisibility();
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FScrollView::setScrollSize (std::size_t width, std::size_t height)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
int xoffset_end
|
|
|
|
, yoffset_end;
|
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 )
|
|
|
|
{
|
2018-11-20 21:11:04 +01:00
|
|
|
FPoint 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
|
|
|
);
|
2017-01-07 22:09:09 +01:00
|
|
|
child_print_area = viewport;
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
xoffset_end = int(getScrollWidth() - getViewportWidth());
|
|
|
|
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();
|
2017-01-03 05:19:44 +01:00
|
|
|
setHorizontalScrollBarVisibility();
|
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();
|
2017-01-03 05:19:44 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setPos (int x, int y, bool adjust)
|
|
|
|
{
|
|
|
|
FWidget::setPos (x, y, 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
|
|
|
|
|
|
|
if ( ! adjust )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FScrollView::setSize (std::size_t w, std::size_t h, bool adjust)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
FWidget::setSize (w, h, 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() )
|
2017-01-22 23:04:40 +01:00
|
|
|
setScrollSize (getViewportWidth(), getViewportHeight());
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-17 22:12:52 +02:00
|
|
|
void FScrollView::setGeometry ( int x, int y
|
|
|
|
, std::size_t w, std::size_t h
|
|
|
|
, bool adjust )
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-08-06 17:02:19 +02:00
|
|
|
// Set the scroll view geometry
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
FWidget::setGeometry (x, y, w, h, adjust);
|
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
|
|
|
{
|
2017-01-22 23:04:40 +01:00
|
|
|
setScrollSize (getViewportWidth(), getViewportHeight());
|
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
|
|
|
//----------------------------------------------------------------------
|
2018-09-12 22:51:15 +02:00
|
|
|
void FScrollView::setCursorPos (int x, int y)
|
2017-02-24 00:30:07 +01:00
|
|
|
{
|
|
|
|
FWidget::setCursorPos (x + getLeftPadding(), y + getTopPadding());
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:09:09 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-09-12 22:51:15 +02:00
|
|
|
void FScrollView::setPrintPos (int x, int y)
|
2017-01-07 22:09:09 +01:00
|
|
|
{
|
|
|
|
FWidget::setPrintPos (x + getLeftPadding(), y + getTopPadding());
|
|
|
|
}
|
|
|
|
|
2017-02-18 23:37:10 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FScrollView::setViewportPrint (bool on)
|
|
|
|
{
|
2018-11-05 23:19:03 +01:00
|
|
|
return (use_own_print_area = ! on);
|
2017-02-18 23:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FScrollView::setBorder (bool on)
|
|
|
|
{
|
2018-11-05 23:19:03 +01:00
|
|
|
return (border = on);
|
2017-02-18 23:37:10 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 05:19:44 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setHorizontalScrollBarMode (fc::scrollBarMode mode)
|
|
|
|
{
|
|
|
|
hMode = mode;
|
|
|
|
setHorizontalScrollBarVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setVerticalScrollBarMode (fc::scrollBarMode mode)
|
|
|
|
{
|
|
|
|
vMode = mode;
|
|
|
|
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();
|
|
|
|
int xoffset_before = xoffset;
|
|
|
|
int yoffset_before = yoffset;
|
|
|
|
int xoffset_end = int(getScrollWidth() - getViewportWidth());
|
|
|
|
int yoffset_end = int(getScrollHeight() - getViewportHeight());
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t save_width = viewport_geometry.getWidth();
|
|
|
|
std::size_t save_height = viewport_geometry.getHeight();
|
|
|
|
bool changeX = false;
|
|
|
|
bool changeY = false;
|
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;
|
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
changeX = bool(xoffset_before != xoffset);
|
|
|
|
changeY = bool(yoffset_before != yoffset);
|
|
|
|
|
|
|
|
if ( ! isVisible() || ! viewport || ! (changeX || changeY) )
|
|
|
|
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);
|
|
|
|
drawHBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
drawVBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-01-28 23:20:38 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
if ( 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
|
|
|
|
2017-02-18 23:37:10 +01:00
|
|
|
if ( border )
|
|
|
|
{
|
|
|
|
if ( isNewFont() )
|
2018-10-14 06:25:33 +02:00
|
|
|
drawBorder (1, 1, int(getWidth()) - 1, int(getHeight()));
|
2017-02-18 23:37:10 +01:00
|
|
|
else
|
|
|
|
drawBorder();
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-01-28 23:20:38 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
|
2017-02-18 23:37:10 +01:00
|
|
|
setViewportPrint();
|
2017-01-02 08:07:46 +01:00
|
|
|
copy2area();
|
2017-01-07 22:09:09 +01:00
|
|
|
redrawVBar();
|
|
|
|
redrawHBar();
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 19:02:04 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
2018-11-21 22:15:14 +01:00
|
|
|
int yoffset_end = int(getScrollHeight() - getViewportHeight());
|
2017-01-03 19:02:04 +01:00
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
switch ( ev->key() )
|
2017-01-03 19:02:04 +01:00
|
|
|
{
|
|
|
|
case fc::Fkey_up:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, -1);
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_down:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (0, 1);
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_left:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (-1, 0);
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollBy (1, 0);
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_ppage:
|
2018-10-14 06:25:33 +02:00
|
|
|
scrollBy (0, int(-getViewportHeight()));
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_npage:
|
2018-10-14 06:25:33 +02:00
|
|
|
scrollBy (0, int(getViewportHeight()));
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_home:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollToY (1);
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_end:
|
2017-12-27 23:51:32 +01:00
|
|
|
scrollToY (1 + yoffset_end);
|
2017-01-03 19:02:04 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::onWheel (FWheelEvent* ev)
|
|
|
|
{
|
2018-11-21 22:15:14 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
FRect widget_geometry;
|
2017-02-20 00:00:53 +01:00
|
|
|
FRect vp_geometry;
|
2018-12-15 00:50:09 +01:00
|
|
|
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;
|
|
|
|
|
2018-12-01 21:28:25 +01:00
|
|
|
widget_geometry = focus->getGeometryWithShadow();
|
2017-02-20 00:00:53 +01:00
|
|
|
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
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
int x
|
|
|
|
, y
|
|
|
|
, vx = vp_geometry.getX()
|
|
|
|
, vy = vp_geometry.getY()
|
|
|
|
, wx = widget_geometry.getX()
|
|
|
|
, 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
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focus = FWidget::getFocusWidget();
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( out_ev->getFocusType() == fc::FocusNextWidget )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
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 )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
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
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FVTerm::term_area* FScrollView::getPrintArea()
|
|
|
|
{
|
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 )
|
|
|
|
{
|
2018-12-10 01:48:26 +01:00
|
|
|
child_print_area = nullptr;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto area = FWidget::getPrintArea();
|
2017-01-07 22:09:09 +01:00
|
|
|
child_print_area = viewport;
|
|
|
|
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();
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t width = getWidth();
|
|
|
|
std::size_t height = getHeight();
|
|
|
|
int xoffset = viewport_geometry.getX();
|
|
|
|
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();
|
2017-01-03 05:19:44 +01:00
|
|
|
setHorizontalScrollBarVisibility();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
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();
|
2017-01-03 05:19:44 +01:00
|
|
|
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;
|
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
int ax = getTermX() - print_area->offset_left
|
|
|
|
, ay = getTermY() - print_area->offset_top
|
|
|
|
, dx = viewport_geometry.getX()
|
|
|
|
, dy = viewport_geometry.getY()
|
2018-10-14 06:25:33 +02:00
|
|
|
, y_end = int(getViewportHeight())
|
|
|
|
, x_end = int(getViewportWidth());
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-10-06 12:19:39 +02:00
|
|
|
// viewport width does not fit into the print_area
|
|
|
|
if ( print_area->width <= ax + x_end )
|
|
|
|
x_end = print_area->width - ax;
|
|
|
|
|
|
|
|
// viewport height does not fit into the print_area
|
|
|
|
if ( print_area->height <= ay + y_end )
|
|
|
|
y_end = print_area->height - ay;
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int y = 0; y < y_end; y++) // line loop
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2018-06-25 00:14:53 +02:00
|
|
|
charData* vc; // viewport character
|
|
|
|
charData* ac; // area character
|
2017-01-02 08:07:46 +01:00
|
|
|
int v_line_len = viewport->width;
|
|
|
|
int a_line_len = print_area->width + print_area->right_shadow;
|
2017-08-27 09:50:30 +02:00
|
|
|
vc = &viewport->text[(dy + y) * v_line_len + dx];
|
|
|
|
ac = &print_area->text[(ay + y) * a_line_len + ax];
|
2018-06-25 00:14:53 +02:00
|
|
|
std::memcpy (ac, vc, sizeof(charData) * unsigned(x_end));
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2018-11-21 22:15:14 +01:00
|
|
|
if ( int(print_area->changes[ay + y].xmin) > ax )
|
2017-08-27 09:50:30 +02:00
|
|
|
print_area->changes[ay + y].xmin = uInt(ax);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2018-11-21 22:15:14 +01:00
|
|
|
if ( int(print_area->changes[ay + y].xmax) < ax + x_end - 1 )
|
2017-08-27 09:50:30 +02:00
|
|
|
print_area->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;
|
|
|
|
print_area->has_changes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FScrollView
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-08 23:48:30 +01:00
|
|
|
inline FPoint FScrollView::getViewportCursorPos()
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto window = FWindow::getWindowWidget(this);
|
2017-03-12 00:29:56 +01:00
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
if ( window )
|
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
int widget_offsetX = getTermX() - window->getTermX()
|
|
|
|
, widget_offsetY = getTermY() - window->getTermY()
|
|
|
|
, x = widget_offsetX + viewport->input_cursor_x
|
|
|
|
- viewport_geometry.getX()
|
|
|
|
, y = widget_offsetY + viewport->input_cursor_y
|
2017-03-26 20:40:04 +02:00
|
|
|
- viewport_geometry.getY();
|
2017-08-27 09:50:30 +02:00
|
|
|
return FPoint (x, y);
|
2017-03-08 23:48:30 +01:00
|
|
|
}
|
|
|
|
else
|
2017-08-27 09:50:30 +02:00
|
|
|
return FPoint (-1, -1);
|
2017-03-08 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::init (FWidget* parent)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2018-02-19 23:02:19 +01:00
|
|
|
int xoffset_end;
|
|
|
|
int yoffset_end;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
assert ( parent != 0 );
|
2017-07-23 01:19:59 +02:00
|
|
|
assert ( ! parent->isInstanceOf("FScrollView") );
|
2017-03-08 23:48:30 +01:00
|
|
|
|
2017-01-15 19:48:27 +01:00
|
|
|
setForegroundColor (wc.dialog_fg);
|
|
|
|
setBackgroundColor (wc.dialog_bg);
|
2018-02-19 23:02:19 +01:00
|
|
|
init_scrollbar();
|
2018-10-14 06:25:33 +02:00
|
|
|
setGeometry (1, 1, 4, 4);
|
|
|
|
setMinimumSize (4, 4);
|
|
|
|
xoffset_end = int(getScrollWidth() - getViewportWidth());
|
|
|
|
yoffset_end = int(getScrollHeight() - getViewportHeight());
|
2018-02-19 23:02:19 +01:00
|
|
|
nf_offset = isNewFont() ? 1 : 0;
|
|
|
|
setTopPadding (1 - getScrollY());
|
|
|
|
setLeftPadding (1 - getScrollX());
|
|
|
|
setBottomPadding (1 - (yoffset_end - getScrollY()));
|
|
|
|
setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset);
|
|
|
|
|
2018-11-20 21:11:04 +01:00
|
|
|
FPoint 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 )
|
|
|
|
child_print_area = viewport;
|
|
|
|
}
|
2017-01-15 19:48:27 +01:00
|
|
|
|
2018-02-19 23:02:19 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::init_scrollbar()
|
|
|
|
{
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
|
|
|
{
|
2018-12-20 01:41:04 +01:00
|
|
|
vbar = std::make_shared<FScrollbar>(fc::vertical, this);
|
2017-08-12 22:55:29 +02:00
|
|
|
vbar->setMinimum(0);
|
|
|
|
vbar->setValue(0);
|
|
|
|
vbar->hide();
|
|
|
|
|
2018-12-20 01:41:04 +01:00
|
|
|
hbar = std::make_shared<FScrollbar>(fc::horizontal, this);
|
2017-08-12 22:55:29 +02:00
|
|
|
hbar->setMinimum(0);
|
|
|
|
hbar->setValue(0);
|
|
|
|
hbar->hide();
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
2018-11-22 21:51:32 +01:00
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
2017-08-12 22:55:29 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
vbar->addCallback
|
|
|
|
(
|
|
|
|
"change-value",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FScrollView::cb_VBarChange)
|
2017-01-02 08:07:46 +01:00
|
|
|
);
|
2017-01-15 19:48:27 +01:00
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
hbar->addCallback
|
|
|
|
(
|
|
|
|
"change-value",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FScrollView::cb_HBarChange)
|
2017-01-02 08:07:46 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::calculateScrollbarPos()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t width = getWidth();
|
|
|
|
std::size_t height = getHeight();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
if ( isNewFont() )
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setGeometry (int(width), 2, 2, height - 2);
|
|
|
|
hbar->setGeometry (1, int(height), width - 2, 1);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
vbar->setGeometry (int(width), 2, 1, height - 2);
|
|
|
|
hbar->setGeometry (2, int(height), 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()
|
|
|
|
{
|
|
|
|
switch ( hMode )
|
|
|
|
{
|
|
|
|
case fc::Auto:
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollWidth() > getViewportWidth() )
|
2017-01-03 05:19:44 +01:00
|
|
|
hbar->setVisible();
|
|
|
|
else
|
|
|
|
hbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Hidden:
|
|
|
|
hbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Scroll:
|
|
|
|
hbar->setVisible();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setVerticalScrollBarVisibility()
|
|
|
|
{
|
|
|
|
switch ( vMode )
|
|
|
|
{
|
|
|
|
case fc::Auto:
|
2017-01-22 23:04:40 +01:00
|
|
|
if ( getScrollHeight() > getViewportHeight() )
|
2017-01-03 05:19:44 +01:00
|
|
|
vbar->setVisible();
|
|
|
|
else
|
|
|
|
vbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Hidden:
|
|
|
|
vbar->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Scroll:
|
|
|
|
vbar->setVisible();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollView::setViewportCursor()
|
|
|
|
{
|
|
|
|
if ( ! isChild(getFocusWidget()) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
FPoint cursor_pos ( viewport->input_cursor_x - 1
|
|
|
|
, viewport->input_cursor_y - 1 );
|
|
|
|
FPoint window_cursor_pos = getViewportCursorPos();
|
|
|
|
print_area->input_cursor_x = window_cursor_pos.getX();
|
|
|
|
print_area->input_cursor_y = window_cursor_pos.getY();
|
|
|
|
|
|
|
|
if ( viewport->input_cursor_visible
|
2017-11-26 22:37:18 +01:00
|
|
|
&& viewport_geometry.contains(cursor_pos) )
|
2017-03-08 23:48:30 +01:00
|
|
|
print_area->input_cursor_visible = true;
|
|
|
|
else
|
|
|
|
print_area->input_cursor_visible = false;
|
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FScrollView::cb_VBarChange (FWidget*, data_ptr)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-12-27 23:51:32 +01:00
|
|
|
FScrollbar::sType scrollType = vbar->getScrollType();
|
2018-11-21 22:15:14 +01:00
|
|
|
int distance = 1;
|
|
|
|
int wheel_distance = 4;
|
2017-12-27 23:51:32 +01:00
|
|
|
|
|
|
|
if ( scrollType >= FScrollbar::scrollStepBackward
|
|
|
|
&& scrollType <= FScrollbar::scrollWheelDown )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FScrollView::cb_HBarChange (FWidget*, data_ptr)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-12-27 23:51:32 +01:00
|
|
|
FScrollbar::sType scrollType = hbar->getScrollType();
|
2018-11-21 22:15:14 +01:00
|
|
|
int distance = 1;
|
|
|
|
int wheel_distance = 4;
|
2017-12-27 23:51:32 +01:00
|
|
|
|
|
|
|
if ( scrollType >= FScrollbar::scrollStepBackward
|
|
|
|
&& scrollType <= FScrollbar::scrollWheelDown )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollView::redrawHBar()
|
|
|
|
{
|
2018-12-10 01:48:26 +01:00
|
|
|
child_print_area = nullptr;
|
2017-01-07 22:09:09 +01:00
|
|
|
|
|
|
|
if ( hbar->isVisible() )
|
|
|
|
hbar->redraw();
|
|
|
|
|
|
|
|
child_print_area = viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollView::redrawVBar()
|
|
|
|
{
|
2018-12-10 01:48:26 +01:00
|
|
|
child_print_area = nullptr;
|
2017-01-07 22:09:09 +01:00
|
|
|
|
|
|
|
if ( vbar->isVisible() )
|
|
|
|
vbar->redraw();
|
|
|
|
|
|
|
|
child_print_area = viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollView::drawHBar()
|
|
|
|
{
|
2018-12-10 01:48:26 +01:00
|
|
|
child_print_area = nullptr;
|
2017-01-07 22:09:09 +01:00
|
|
|
|
|
|
|
if ( hbar->isVisible() )
|
|
|
|
hbar->drawBar();
|
|
|
|
|
|
|
|
child_print_area = viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollView::drawVBar()
|
|
|
|
{
|
2018-12-10 01:48:26 +01:00
|
|
|
child_print_area = nullptr;
|
2017-01-07 22:09:09 +01:00
|
|
|
|
|
|
|
if ( vbar->isVisible() )
|
|
|
|
vbar->drawBar();
|
|
|
|
|
|
|
|
child_print_area = viewport;
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|