Add scrollTo and scrollBy methods to FScrollView
This commit is contained in:
parent
99ff28cbbe
commit
49e36e5203
|
@ -1,3 +1,6 @@
|
||||||
|
2017-01-07 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Add scrollTo and scrollBy methods to FScrollView
|
||||||
|
|
||||||
2017-01-03 Markus Gans <guru.mail@muenster.de>
|
2017-01-03 Markus Gans <guru.mail@muenster.de>
|
||||||
* FScrollView now has on-demand scroll bars
|
* FScrollView now has on-demand scroll bars
|
||||||
* Arrow keys support for FScrollView viewport scrolling
|
* Arrow keys support for FScrollView viewport scrolling
|
||||||
|
|
|
@ -31,6 +31,7 @@ FScrollView::~FScrollView() // destructor
|
||||||
delete vbar;
|
delete vbar;
|
||||||
delete hbar;
|
delete hbar;
|
||||||
removeArea (viewport);
|
removeArea (viewport);
|
||||||
|
child_print_area = viewport = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ void FScrollView::setScrollWidth (int width)
|
||||||
FPoint no_shadow(0,0);
|
FPoint no_shadow(0,0);
|
||||||
scroll_size.setWidth (width);
|
scroll_size.setWidth (width);
|
||||||
resizeArea (scroll_size, no_shadow, viewport);
|
resizeArea (scroll_size, no_shadow, viewport);
|
||||||
|
child_print_area = viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
hbar->setMaximum (width - getClientWidth());
|
hbar->setMaximum (width - getClientWidth());
|
||||||
|
@ -71,6 +73,7 @@ void FScrollView::setScrollHeight (int height)
|
||||||
FPoint no_shadow(0,0);
|
FPoint no_shadow(0,0);
|
||||||
scroll_size.setHeight (height);
|
scroll_size.setHeight (height);
|
||||||
resizeArea (scroll_size, no_shadow, viewport);
|
resizeArea (scroll_size, no_shadow, viewport);
|
||||||
|
child_print_area = viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
vbar->setMaximum (height - getClientHeight());
|
vbar->setMaximum (height - getClientHeight());
|
||||||
|
@ -96,6 +99,7 @@ void FScrollView::setScrollSize (int width, int height)
|
||||||
FPoint no_shadow(0,0);
|
FPoint no_shadow(0,0);
|
||||||
scroll_size.setSize (width, height);
|
scroll_size.setSize (width, height);
|
||||||
resizeArea (scroll_size, no_shadow, viewport);
|
resizeArea (scroll_size, no_shadow, viewport);
|
||||||
|
child_print_area = viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
hbar->setMaximum (width - getClientWidth());
|
hbar->setMaximum (width - getClientWidth());
|
||||||
|
@ -116,7 +120,7 @@ void FScrollView::setX (int x, bool adjust)
|
||||||
|
|
||||||
if ( ! adjust )
|
if ( ! adjust )
|
||||||
{
|
{
|
||||||
scroll_size.setX (getTermX() - 1);
|
scroll_size.setX (getTermX() + getLeftPadding() - 1);
|
||||||
|
|
||||||
if ( viewport )
|
if ( viewport )
|
||||||
{
|
{
|
||||||
|
@ -133,7 +137,7 @@ void FScrollView::setY (int y, bool adjust)
|
||||||
|
|
||||||
if ( ! adjust )
|
if ( ! adjust )
|
||||||
{
|
{
|
||||||
scroll_size.setY (getTermY() - 1);
|
scroll_size.setY (getTermY() + getTopPadding() - 1);
|
||||||
|
|
||||||
if ( viewport )
|
if ( viewport )
|
||||||
{
|
{
|
||||||
|
@ -147,7 +151,8 @@ void FScrollView::setY (int y, bool adjust)
|
||||||
void FScrollView::setPos (int x, int y, bool adjust)
|
void FScrollView::setPos (int x, int y, bool adjust)
|
||||||
{
|
{
|
||||||
FWidget::setPos (x, y, adjust);
|
FWidget::setPos (x, y, adjust);
|
||||||
scroll_size.setPos (getTermX() - 1, getTermY() - 1);
|
scroll_size.setPos ( getTermX() + getLeftPadding() - 1
|
||||||
|
, getTermY() + getTopPadding() - 1 );
|
||||||
|
|
||||||
if ( ! adjust )
|
if ( ! adjust )
|
||||||
{
|
{
|
||||||
|
@ -194,7 +199,8 @@ void FScrollView::setSize (int w, int h, bool adjust)
|
||||||
void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust)
|
void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust)
|
||||||
{
|
{
|
||||||
FWidget::setGeometry (x, y, w, h, adjust);
|
FWidget::setGeometry (x, y, w, h, adjust);
|
||||||
scroll_size.setPos (getTermX() - 1, getTermY() - 1);
|
scroll_size.setPos ( getTermX() + getLeftPadding() - 1
|
||||||
|
, getTermY() + getTopPadding() - 1 );
|
||||||
calculateScrollbarPos();
|
calculateScrollbarPos();
|
||||||
|
|
||||||
if ( getScrollWidth() < getClientWidth()
|
if ( getScrollWidth() < getClientWidth()
|
||||||
|
@ -209,6 +215,12 @@ void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FScrollView::setPrintPos (register int x, register int y)
|
||||||
|
{
|
||||||
|
FWidget::setPrintPos (x + getLeftPadding(), y + getTopPadding());
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FScrollView::setHorizontalScrollBarMode (fc::scrollBarMode mode)
|
void FScrollView::setHorizontalScrollBarMode (fc::scrollBarMode mode)
|
||||||
{
|
{
|
||||||
|
@ -230,6 +242,59 @@ void FScrollView::clearArea (int fillchar)
|
||||||
clearArea (viewport, fillchar);
|
clearArea (viewport, fillchar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FScrollView::scrollToX (int x)
|
||||||
|
{
|
||||||
|
scrollTo (x, scroll_offset.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FScrollView::scrollToY (int y)
|
||||||
|
{
|
||||||
|
scrollTo (scroll_offset.getX(), y);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FScrollView::scrollTo (int x, int y)
|
||||||
|
{
|
||||||
|
short& xoffset = scroll_offset.x_ref();
|
||||||
|
short& yoffset = scroll_offset.y_ref();
|
||||||
|
short xoffset_end = short(getScrollWidth() - getClientWidth());
|
||||||
|
short yoffset_end = short(getScrollHeight() - getClientHeight());
|
||||||
|
|
||||||
|
if ( xoffset == short(x) && yoffset == short(y) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
xoffset = short(x);
|
||||||
|
yoffset = short(y);
|
||||||
|
|
||||||
|
if ( yoffset < 0 )
|
||||||
|
yoffset = 0;
|
||||||
|
|
||||||
|
if ( yoffset > yoffset_end )
|
||||||
|
yoffset = yoffset_end;
|
||||||
|
|
||||||
|
if ( xoffset < 0 )
|
||||||
|
xoffset = 0;
|
||||||
|
|
||||||
|
if ( xoffset > xoffset_end )
|
||||||
|
xoffset = xoffset_end;
|
||||||
|
|
||||||
|
hbar->setValue (xoffset);
|
||||||
|
vbar->setValue (yoffset);
|
||||||
|
drawHBar();
|
||||||
|
drawVBar();
|
||||||
|
viewport->has_changes = true;
|
||||||
|
copy2area();
|
||||||
|
updateTerminal();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FScrollView::scrollBy (int dx, int dy)
|
||||||
|
{
|
||||||
|
scrollTo (getScrollX() + dx, getScrollY() + dy);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FScrollView::draw()
|
void FScrollView::draw()
|
||||||
{
|
{
|
||||||
|
@ -247,12 +312,8 @@ void FScrollView::draw()
|
||||||
|
|
||||||
use_own_print_area = false;
|
use_own_print_area = false;
|
||||||
copy2area();
|
copy2area();
|
||||||
|
redrawVBar();
|
||||||
if ( vbar->isVisible() )
|
redrawHBar();
|
||||||
vbar->redraw();
|
|
||||||
|
|
||||||
if ( hbar->isVisible() )
|
|
||||||
hbar->redraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -339,12 +400,8 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
vbar->setValue (yoffset);
|
vbar->setValue (yoffset);
|
||||||
hbar->setValue (xoffset);
|
hbar->setValue (xoffset);
|
||||||
|
drawVBar();
|
||||||
if ( vbar->isVisible() )
|
drawHBar();
|
||||||
vbar->drawBar();
|
|
||||||
|
|
||||||
if ( hbar->isVisible() )
|
|
||||||
hbar->drawBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hasChanges )
|
if ( hasChanges )
|
||||||
|
@ -400,9 +457,7 @@ void FScrollView::onWheel (FWheelEvent* ev)
|
||||||
copy2area();
|
copy2area();
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
vbar->setValue (yoffset);
|
vbar->setValue (yoffset);
|
||||||
|
drawVBar();
|
||||||
if ( vbar->isVisible() )
|
|
||||||
vbar->drawBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hasChanges )
|
if ( hasChanges )
|
||||||
|
@ -414,12 +469,17 @@ void FScrollView::onWheel (FWheelEvent* ev)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FVTerm::term_area* FScrollView::getPrintArea()
|
FVTerm::term_area* FScrollView::getPrintArea()
|
||||||
{
|
{
|
||||||
// returns the viewport print area
|
// returns print area or viewport
|
||||||
|
|
||||||
if ( viewport && ! use_own_print_area )
|
if ( use_own_print_area || ! viewport )
|
||||||
return viewport;
|
{
|
||||||
|
child_print_area = 0;
|
||||||
|
term_area* area = FVTerm::getPrintArea();
|
||||||
|
child_print_area = viewport;
|
||||||
|
return area;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return FVTerm::getPrintArea();
|
return viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -431,7 +491,8 @@ void FScrollView::adjustSize()
|
||||||
int xoffset = scroll_offset.getX();
|
int xoffset = scroll_offset.getX();
|
||||||
int yoffset = scroll_offset.getY();
|
int yoffset = scroll_offset.getY();
|
||||||
|
|
||||||
scroll_size.setPos (getTermX() - 1, getTermY() - 1);
|
scroll_size.setPos ( getTermX() + getLeftPadding() - 1
|
||||||
|
, getTermY() + getTopPadding() - 1 );
|
||||||
|
|
||||||
if ( viewport )
|
if ( viewport )
|
||||||
{
|
{
|
||||||
|
@ -534,8 +595,11 @@ void FScrollView::init()
|
||||||
setRightPadding(1 + nf_offset);
|
setRightPadding(1 + nf_offset);
|
||||||
|
|
||||||
FPoint no_shadow(0,0);
|
FPoint no_shadow(0,0);
|
||||||
scroll_size.setRect (0, 0, getClientWidth(), getClientHeight());
|
scroll_size.setRect (1, 1, getClientWidth(), getClientHeight());
|
||||||
createArea (scroll_size, no_shadow, viewport);
|
createArea (scroll_size, no_shadow, viewport);
|
||||||
|
|
||||||
|
if ( viewport )
|
||||||
|
child_print_area = viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -698,9 +762,7 @@ void FScrollView::cb_VBarChange (FWidget*, void*)
|
||||||
&& hasChanges )
|
&& hasChanges )
|
||||||
{
|
{
|
||||||
vbar->setValue (yoffset);
|
vbar->setValue (yoffset);
|
||||||
|
drawVBar();
|
||||||
if ( vbar->isVisible() )
|
|
||||||
vbar->drawBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hasChanges )
|
if ( hasChanges )
|
||||||
|
@ -801,11 +863,53 @@ void FScrollView::cb_HBarChange (FWidget*, void*)
|
||||||
&& hasChanges )
|
&& hasChanges )
|
||||||
{
|
{
|
||||||
hbar->setValue (xoffset);
|
hbar->setValue (xoffset);
|
||||||
|
drawHBar();
|
||||||
if ( hbar->isVisible() )
|
|
||||||
hbar->drawBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hasChanges )
|
if ( hasChanges )
|
||||||
updateTerminal();
|
updateTerminal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FScrollView::redrawHBar()
|
||||||
|
{
|
||||||
|
child_print_area = 0;
|
||||||
|
|
||||||
|
if ( hbar->isVisible() )
|
||||||
|
hbar->redraw();
|
||||||
|
|
||||||
|
child_print_area = viewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FScrollView::redrawVBar()
|
||||||
|
{
|
||||||
|
child_print_area = 0;
|
||||||
|
|
||||||
|
if ( vbar->isVisible() )
|
||||||
|
vbar->redraw();
|
||||||
|
|
||||||
|
child_print_area = viewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FScrollView::drawHBar()
|
||||||
|
{
|
||||||
|
child_print_area = 0;
|
||||||
|
|
||||||
|
if ( hbar->isVisible() )
|
||||||
|
hbar->drawBar();
|
||||||
|
|
||||||
|
child_print_area = viewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FScrollView::drawVBar()
|
||||||
|
{
|
||||||
|
child_print_area = 0;
|
||||||
|
|
||||||
|
if ( vbar->isVisible() )
|
||||||
|
vbar->drawBar();
|
||||||
|
|
||||||
|
child_print_area = viewport;
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ class FScrollView : public FWidget
|
||||||
public:
|
public:
|
||||||
// Using-declaration
|
// Using-declaration
|
||||||
using FWidget::setGeometry;
|
using FWidget::setGeometry;
|
||||||
|
using FWidget::setPrintPos;
|
||||||
using FWidget::setPos;
|
using FWidget::setPos;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -55,15 +56,16 @@ class FScrollView : public FWidget
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
const char* getClassName() const;
|
const char* getClassName() const;
|
||||||
int getScrollWidth();
|
int getScrollWidth() const;
|
||||||
int getScrollHeight();
|
int getScrollHeight() const;
|
||||||
|
const FPoint getScrollPos() const;
|
||||||
|
int getScrollX() const;
|
||||||
|
int getScrollY() const;
|
||||||
|
|
||||||
// Mutator
|
// Mutator
|
||||||
void setScrollWidth (int);
|
void setScrollWidth (int);
|
||||||
void setScrollHeight (int);
|
void setScrollHeight (int);
|
||||||
void setScrollSize (int, int);
|
void setScrollSize (int, int);
|
||||||
void setScrollOffset (FPoint);
|
|
||||||
void setScrollOffset (int, int);
|
|
||||||
virtual void setX (int, bool = true);
|
virtual void setX (int, bool = true);
|
||||||
virtual void setY (int, bool = true);
|
virtual void setY (int, bool = true);
|
||||||
virtual void setPos (int, int, bool = true);
|
virtual void setPos (int, int, bool = true);
|
||||||
|
@ -71,11 +73,17 @@ class FScrollView : public FWidget
|
||||||
virtual void setHeight (int, bool = true);
|
virtual void setHeight (int, bool = true);
|
||||||
virtual void setSize (int, int, bool = true);
|
virtual void setSize (int, int, bool = true);
|
||||||
void setGeometry (int, int, int, int, bool = true);
|
void setGeometry (int, int, int, int, bool = true);
|
||||||
|
void setPrintPos (register int, register int);
|
||||||
void setHorizontalScrollBarMode (fc::scrollBarMode);
|
void setHorizontalScrollBarMode (fc::scrollBarMode);
|
||||||
void setVerticalScrollBarMode (fc::scrollBarMode);
|
void setVerticalScrollBarMode (fc::scrollBarMode);
|
||||||
|
|
||||||
// Method
|
// Method
|
||||||
virtual void clearArea (int = ' ');
|
virtual void clearArea (int = ' ');
|
||||||
|
void scrollToX (int);
|
||||||
|
void scrollToY (int);
|
||||||
|
void scrollTo (FPoint);
|
||||||
|
void scrollTo (int, int);
|
||||||
|
void scrollBy (int, int);
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
|
|
||||||
// Event handlers
|
// Event handlers
|
||||||
|
@ -105,6 +113,10 @@ class FScrollView : public FWidget
|
||||||
void calculateScrollbarPos();
|
void calculateScrollbarPos();
|
||||||
void setHorizontalScrollBarVisibility();
|
void setHorizontalScrollBarVisibility();
|
||||||
void setVerticalScrollBarVisibility();
|
void setVerticalScrollBarVisibility();
|
||||||
|
void redrawHBar();
|
||||||
|
void redrawVBar();
|
||||||
|
void drawHBar();
|
||||||
|
void drawVBar();
|
||||||
|
|
||||||
// Callback methods
|
// Callback methods
|
||||||
void cb_VBarChange (FWidget*, void*);
|
void cb_VBarChange (FWidget*, void*);
|
||||||
|
@ -130,19 +142,28 @@ inline const char* FScrollView::getClassName() const
|
||||||
{ return "FScrollView"; }
|
{ return "FScrollView"; }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline int FScrollView::getScrollWidth()
|
inline int FScrollView::getScrollWidth() const
|
||||||
{ return scroll_size.getWidth(); }
|
{ return scroll_size.getWidth(); }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline int FScrollView::getScrollHeight()
|
inline int FScrollView::getScrollHeight() const
|
||||||
{ return scroll_size.getHeight(); }
|
{ return scroll_size.getHeight(); }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline void FScrollView::setScrollOffset (FPoint pos)
|
inline const FPoint FScrollView::getScrollPos() const
|
||||||
{ scroll_offset = pos; }
|
{ return scroll_offset; }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline void FScrollView::setScrollOffset (int x, int y)
|
inline int FScrollView::getScrollX() const
|
||||||
{ scroll_offset.setPoint (x, y); }
|
{ return scroll_offset.getX(); }
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline int FScrollView::getScrollY() const
|
||||||
|
{ return scroll_offset.getY(); }
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FScrollView::scrollTo (FPoint pos)
|
||||||
|
{ scrollTo(pos.getX(), pos.getY()); }
|
||||||
|
|
||||||
|
|
||||||
#endif // _FSCROLLVIEW_H
|
#endif // _FSCROLLVIEW_H
|
||||||
|
|
|
@ -36,6 +36,7 @@ FVTerm::char_data FVTerm::next_attribute;
|
||||||
FVTerm::FVTerm (FVTerm* parent)
|
FVTerm::FVTerm (FVTerm* parent)
|
||||||
: FObject(parent)
|
: FObject(parent)
|
||||||
, print_area(0)
|
, print_area(0)
|
||||||
|
, child_print_area(0)
|
||||||
, vwin(0)
|
, vwin(0)
|
||||||
{
|
{
|
||||||
terminal_update_complete = false;
|
terminal_update_complete = false;
|
||||||
|
@ -631,7 +632,7 @@ FVTerm::term_area* FVTerm::getPrintArea()
|
||||||
FVTerm* obj = static_cast<FVTerm*>(this);
|
FVTerm* obj = static_cast<FVTerm*>(this);
|
||||||
FVTerm* p_obj = static_cast<FVTerm*>(obj->getParent());
|
FVTerm* p_obj = static_cast<FVTerm*>(obj->getParent());
|
||||||
|
|
||||||
while ( ! obj->vwin && p_obj )
|
while ( ! obj->vwin && ! obj->child_print_area && p_obj )
|
||||||
{
|
{
|
||||||
obj = p_obj;
|
obj = p_obj;
|
||||||
p_obj = static_cast<FVTerm*>(p_obj->getParent());
|
p_obj = static_cast<FVTerm*>(p_obj->getParent());
|
||||||
|
@ -642,6 +643,11 @@ FVTerm::term_area* FVTerm::getPrintArea()
|
||||||
print_area = obj->vwin;
|
print_area = obj->vwin;
|
||||||
return print_area;
|
return print_area;
|
||||||
}
|
}
|
||||||
|
else if ( obj->child_print_area )
|
||||||
|
{
|
||||||
|
print_area = obj->child_print_area;
|
||||||
|
return print_area;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return vdesktop;
|
return vdesktop;
|
||||||
|
|
|
@ -302,6 +302,7 @@ class FVTerm : public FObject, public FTerm
|
||||||
static term_area* vdesktop; // virtual desktop
|
static term_area* vdesktop; // virtual desktop
|
||||||
static term_area* active_area; // active area
|
static term_area* active_area; // active area
|
||||||
term_area* print_area; // print area for this object
|
term_area* print_area; // print area for this object
|
||||||
|
term_area* child_print_area; // print area for children
|
||||||
term_area* vwin; // virtual window
|
term_area* vwin; // virtual window
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue