FScrollView now allows client widget

This commit is contained in:
Markus Gans 2017-01-22 23:04:40 +01:00
parent 5cb7b77f4e
commit 51b1d18a84
13 changed files with 335 additions and 144 deletions

View File

@ -1,3 +1,7 @@
2017-01-22 Markus Gans <guru.mail@muenster.de>
* A FScrollView object can now have client widgets
on the scrolling area
2017-01-15 Markus Gans <guru.mail@muenster.de> 2017-01-15 Markus Gans <guru.mail@muenster.de>
* Virtual window gets a preprocessing handler. This allows * Virtual window gets a preprocessing handler. This allows
a preprocessing method to be called before the vterm is updated. a preprocessing method to be called before the vterm is updated.

View File

@ -168,6 +168,9 @@ Class digramm
: 1┌───────────┐ : : │ ┌──────────┐1 *┌──────────────┐1 : : 1┌───────────┐ : : │ ┌──────────┐1 *┌──────────────┐1 :
└---┤ FOptiMove │ : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----┘ └---┤ FOptiMove │ : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----┘
└───────────┘ : : │ └──────────┘ └──────────────┘ : └───────────┘ : : │ └──────────┘ └──────────────┘ :
: : │ ┌─────────────┐ :
: : ├────┤ FScrollView │ :
: : │ └─────────────┘ :
: : │ ┌────────────┐1 *┌────────────┐1 : : : │ ┌────────────┐1 *┌────────────┐1 :
: : │ ┌──┤ FStatusBar ├-----┤ FStatusKey ├-------┘ : : │ ┌──┤ FStatusBar ├-----┤ FStatusKey ├-------┘
: : │ │ └────┬───────┘ └────────────┘ : : : │ │ └────┬───────┘ └────────────┘ :

View File

@ -8,7 +8,7 @@ case "$1" in
./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -W -Wall -pedantic" ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -W -Wall -pedantic"
;; ;;
"--/fulldebug"|"fulldebug") "--fulldebug"|"fulldebug")
./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -W -Wall -Weffc++ -pedantic -pedantic-errors -Wextra -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winit-self -Winvalid-pch -Wlong-long -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpadded -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -fstack-protector -Wstrict-aliasing -Wstrict-aliasing=3 -Wswitch -Wswitch-enum -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wsign-promo -Woverloaded-virtual -Wstrict-null-sentinel -fext-numeric-literals -Wreorder -Wnoexcept -Wnarrowing -Wliteral-suffix -Wctor-dtor-privacy" ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -W -Wall -Weffc++ -pedantic -pedantic-errors -Wextra -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winit-self -Winvalid-pch -Wlong-long -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpadded -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -fstack-protector -Wstrict-aliasing -Wstrict-aliasing=3 -Wswitch -Wswitch-enum -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wsign-promo -Woverloaded-virtual -Wstrict-null-sentinel -fext-numeric-literals -Wreorder -Wnoexcept -Wnarrowing -Wliteral-suffix -Wctor-dtor-privacy"
;; ;;

View File

@ -63,6 +63,9 @@
: 1┌───────────┐ : : │ ┌──────────┐1 *┌──────────────┐1 : : 1┌───────────┐ : : │ ┌──────────┐1 *┌──────────────┐1 :
└---┤ FOptiMove │ : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----┘ └---┤ FOptiMove │ : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----┘
└───────────┘ : : │ └──────────┘ └──────────────┘ : └───────────┘ : : │ └──────────┘ └──────────────┘ :
: : │ ┌─────────────┐ :
: : ├────┤ FScrollView │ :
: : │ └─────────────┘ :
: : │ ┌────────────┐1 *┌────────────┐1 : : : │ ┌────────────┐1 *┌────────────┐1 :
: : │ ┌──┤ FStatusBar ├-----┤ FStatusKey ├-------┘ : : │ ┌──┤ FStatusBar ├-----┤ FStatusKey ├-------┘
: : │ │ └────┬───────┘ └────────────┘ : : : │ │ └────┬───────┘ └────────────┘ :

View File

@ -39,8 +39,8 @@ FScrollView::~FScrollView() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::setScrollWidth (int width) void FScrollView::setScrollWidth (int width)
{ {
if ( width < getClientWidth() ) if ( width < getViewportWidth() )
width = getClientWidth(); width = getViewportWidth();
if ( getScrollWidth() == width ) if ( getScrollWidth() == width )
return; return;
@ -57,8 +57,8 @@ void FScrollView::setScrollWidth (int width)
child_print_area = viewport; child_print_area = viewport;
} }
hbar->setMaximum (width - getClientWidth()); hbar->setMaximum (width - getViewportWidth());
hbar->setPageSize (width, getClientWidth()); hbar->setPageSize (width, getViewportWidth());
hbar->calculateSliderValues(); hbar->calculateSliderValues();
setHorizontalScrollBarVisibility(); setHorizontalScrollBarVisibility();
} }
@ -66,8 +66,8 @@ void FScrollView::setScrollWidth (int width)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::setScrollHeight (int height) void FScrollView::setScrollHeight (int height)
{ {
if ( height < getClientHeight() ) if ( height < getViewportHeight() )
height = getClientHeight(); height = getViewportHeight();
if ( getScrollHeight() == height ) if ( getScrollHeight() == height )
return; return;
@ -84,8 +84,8 @@ void FScrollView::setScrollHeight (int height)
child_print_area = viewport; child_print_area = viewport;
} }
vbar->setMaximum (height - getClientHeight()); vbar->setMaximum (height - getViewportHeight());
vbar->setPageSize (height, getClientHeight()); vbar->setPageSize (height, getViewportHeight());
vbar->calculateSliderValues(); vbar->calculateSliderValues();
setVerticalScrollBarVisibility(); setVerticalScrollBarVisibility();
} }
@ -93,11 +93,11 @@ void FScrollView::setScrollHeight (int height)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::setScrollSize (int width, int height) void FScrollView::setScrollSize (int width, int height)
{ {
if ( width < getClientWidth() ) if ( width < getViewportWidth() )
width = getClientWidth(); width = getViewportWidth();
if ( height < getClientHeight() ) if ( height < getViewportHeight() )
height = getClientHeight(); height = getViewportHeight();
if ( getScrollWidth() == width && getScrollHeight() == height ) if ( getScrollWidth() == width && getScrollHeight() == height )
return; return;
@ -114,13 +114,18 @@ void FScrollView::setScrollSize (int width, int height)
child_print_area = viewport; child_print_area = viewport;
} }
hbar->setMaximum (width - getClientWidth()); setTopPadding (1 - getScrollY());
hbar->setPageSize (width, getClientWidth()); setLeftPadding (1 - getScrollX());
setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - getScrollY()));
setRightPadding (1 - (getScrollWidth() - getViewportWidth() - getScrollX()) + nf_offset);
hbar->setMaximum (width - getViewportWidth());
hbar->setPageSize (width, getViewportWidth());
hbar->calculateSliderValues(); hbar->calculateSliderValues();
setHorizontalScrollBarVisibility(); setHorizontalScrollBarVisibility();
vbar->setMaximum (height - getClientHeight()); vbar->setMaximum (height - getViewportHeight());
vbar->setPageSize (height, getClientHeight()); vbar->setPageSize (height, getViewportHeight());
vbar->calculateSliderValues(); vbar->calculateSliderValues();
setVerticalScrollBarVisibility(); setVerticalScrollBarVisibility();
} }
@ -182,8 +187,8 @@ void FScrollView::setWidth (int w, bool adjust)
FWidget::setWidth (w, adjust); FWidget::setWidth (w, adjust);
calculateScrollbarPos(); calculateScrollbarPos();
if ( getScrollWidth() < getClientWidth() ) if ( getScrollWidth() < getViewportWidth() )
setScrollWidth (getClientWidth()); setScrollWidth (getViewportWidth());
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -192,8 +197,8 @@ void FScrollView::setHeight (int h, bool adjust)
FWidget::setHeight (h, adjust); FWidget::setHeight (h, adjust);
calculateScrollbarPos(); calculateScrollbarPos();
if ( getScrollHeight() < getClientHeight() ) if ( getScrollHeight() < getViewportHeight() )
setScrollHeight (getClientHeight()); setScrollHeight (getViewportHeight());
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -202,9 +207,9 @@ void FScrollView::setSize (int w, int h, bool adjust)
FWidget::setSize (w, h, adjust); FWidget::setSize (w, h, adjust);
calculateScrollbarPos(); calculateScrollbarPos();
if ( getScrollWidth() < getClientWidth() if ( getScrollWidth() < getViewportWidth()
|| getScrollHeight() < getClientHeight() ) || getScrollHeight() < getViewportHeight() )
setScrollSize (getClientWidth(), getClientHeight()); setScrollSize (getViewportWidth(), getViewportHeight());
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -215,10 +220,10 @@ void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust)
, getTermY() + getTopPadding() - 1 ); , getTermY() + getTopPadding() - 1 );
calculateScrollbarPos(); calculateScrollbarPos();
if ( getScrollWidth() < getClientWidth() if ( getScrollWidth() < getViewportWidth()
|| getScrollHeight() < getClientHeight() ) || getScrollHeight() < getViewportHeight() )
{ {
setScrollSize (getClientWidth(), getClientHeight()); setScrollSize (getViewportWidth(), getViewportHeight());
} }
else if ( ! adjust && viewport ) else if ( ! adjust && viewport )
{ {
@ -257,13 +262,13 @@ void FScrollView::clearArea (int fillchar)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::scrollToX (int x) void FScrollView::scrollToX (int x)
{ {
scrollTo (x, scroll_offset.getY()); scrollTo (x, scroll_offset.getY() + 1);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::scrollToY (int y) void FScrollView::scrollToY (int y)
{ {
scrollTo (scroll_offset.getX(), y); scrollTo (scroll_offset.getX() + 1, y);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -271,8 +276,10 @@ void FScrollView::scrollTo (int x, int y)
{ {
short& xoffset = scroll_offset.x_ref(); short& xoffset = scroll_offset.x_ref();
short& yoffset = scroll_offset.y_ref(); short& yoffset = scroll_offset.y_ref();
short xoffset_end = short(getScrollWidth() - getClientWidth()); short xoffset_end = short(getScrollWidth() - getViewportWidth());
short yoffset_end = short(getScrollHeight() - getClientHeight()); short yoffset_end = short(getScrollHeight() - getViewportHeight());
x--;
y--;
if ( xoffset == short(x) && yoffset == short(y) ) if ( xoffset == short(x) && yoffset == short(y) )
return; return;
@ -297,6 +304,10 @@ void FScrollView::scrollTo (int x, int y)
drawHBar(); drawHBar();
drawVBar(); drawVBar();
viewport->has_changes = true; viewport->has_changes = true;
setTopPadding (1 - yoffset);
setLeftPadding (1 - xoffset);
setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - yoffset));
setRightPadding (1 - (getScrollWidth() - getViewportWidth() - xoffset) + nf_offset);
copy2area(); copy2area();
updateTerminal(); updateTerminal();
} }
@ -337,8 +348,8 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
short& yoffset = scroll_offset.y_ref(); short& yoffset = scroll_offset.y_ref();
short xoffset_before = xoffset; short xoffset_before = xoffset;
short yoffset_before = yoffset; short yoffset_before = yoffset;
short xoffset_end = short(getScrollWidth() - getClientWidth()); short xoffset_end = short(getScrollWidth() - getViewportWidth());
short yoffset_end = short(getScrollHeight() - getClientHeight()); short yoffset_end = short(getScrollHeight() - getViewportHeight());
switch ( key ) switch ( key )
{ {
@ -371,7 +382,7 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
break; break;
case fc::Fkey_ppage: case fc::Fkey_ppage:
yoffset -= getClientHeight(); yoffset -= getViewportHeight();
if ( yoffset < 0 ) if ( yoffset < 0 )
yoffset = 0; yoffset = 0;
@ -380,7 +391,7 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
break; break;
case fc::Fkey_npage: case fc::Fkey_npage:
yoffset += getClientHeight(); yoffset += getViewportHeight();
if ( yoffset > yoffset_end ) if ( yoffset > yoffset_end )
yoffset = yoffset_end; yoffset = yoffset_end;
@ -408,6 +419,10 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
&& (xoffset_before != xoffset || yoffset_before != yoffset) ) && (xoffset_before != xoffset || yoffset_before != yoffset) )
{ {
viewport->has_changes = true; viewport->has_changes = true;
setTopPadding (1 - yoffset);
setLeftPadding (1 - xoffset);
setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - yoffset));
setRightPadding (1 - (getScrollWidth() - getViewportWidth() - xoffset) + nf_offset);
copy2area(); copy2area();
hasChanges = true; hasChanges = true;
vbar->setValue (yoffset); vbar->setValue (yoffset);
@ -444,7 +459,7 @@ void FScrollView::onWheel (FWheelEvent* ev)
case fc::WheelDown: case fc::WheelDown:
{ {
short yoffset_end = short(getScrollHeight() - getClientHeight()); short yoffset_end = short(getScrollHeight() - getViewportHeight());
if ( yoffset_end < 0 ) if ( yoffset_end < 0 )
yoffset_end = 0; yoffset_end = 0;
@ -466,6 +481,8 @@ void FScrollView::onWheel (FWheelEvent* ev)
if ( isVisible() && viewport && yoffset_before != yoffset ) if ( isVisible() && viewport && yoffset_before != yoffset )
{ {
viewport->has_changes = true; viewport->has_changes = true;
setTopPadding (1 - yoffset);
setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - yoffset));
copy2area(); copy2area();
hasChanges = true; hasChanges = true;
vbar->setValue (yoffset); vbar->setValue (yoffset);
@ -512,22 +529,21 @@ void FScrollView::adjustSize()
viewport->offset_left = scroll_size.getY(); viewport->offset_left = scroll_size.getY();
} }
hbar->setMaximum (getScrollWidth() - getClientWidth()); hbar->setMaximum (getScrollWidth() - getViewportWidth());
hbar->setPageSize (getScrollWidth(), getClientWidth()); hbar->setPageSize (getScrollWidth(), getViewportWidth());
hbar->setY (height); hbar->setY (height);
hbar->setWidth (width - 2, false); hbar->setWidth (width - 2, false);
hbar->setValue (xoffset); hbar->setValue (xoffset);
hbar->resize(); hbar->resize();
setHorizontalScrollBarVisibility(); setHorizontalScrollBarVisibility();
vbar->setMaximum (getScrollHeight() - getClientHeight()); vbar->setMaximum (getScrollHeight() - getViewportHeight());
vbar->setPageSize (getScrollHeight(), getClientHeight()); vbar->setPageSize (getScrollHeight(), getViewportHeight());
vbar->setX (width); vbar->setX (width);
vbar->setHeight (height - 2, false); vbar->setHeight (height - 2, false);
vbar->setValue (yoffset); vbar->setValue (yoffset);
vbar->resize(); vbar->resize();
setVerticalScrollBarVisibility(); setVerticalScrollBarVisibility();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -539,10 +555,10 @@ void FScrollView::copy2area()
char_data* vc; // viewport character char_data* vc; // viewport character
char_data* ac; // area character char_data* ac; // area character
if ( ! print_area ) if ( ! hasPrintArea() )
FVTerm::getPrintArea(); FVTerm::getPrintArea();
if ( ! (print_area && viewport) ) if ( ! (hasPrintArea() && viewport) )
return; return;
if ( ! viewport->has_changes ) if ( ! viewport->has_changes )
@ -552,8 +568,8 @@ void FScrollView::copy2area()
ay = getTermY() - print_area->offset_left; ay = getTermY() - print_area->offset_left;
dx = scroll_offset.getX(); dx = scroll_offset.getX();
dy = scroll_offset.getY(); dy = scroll_offset.getY();
y_end = getClientHeight(); y_end = getViewportHeight();
x_end = getClientWidth(); x_end = getViewportWidth();
for (int y=0; y < y_end; y++) // line loop for (int y=0; y < y_end; y++) // line loop
{ {
@ -605,13 +621,22 @@ void FScrollView::init()
); );
nf_offset = isNewFont() ? 1 : 0; nf_offset = isNewFont() ? 1 : 0;
setTopPadding(1); setTopPadding (1 - getScrollY());
setLeftPadding(1); setLeftPadding (1 - getScrollX());
setBottomPadding(1); setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - getScrollY()));
setRightPadding(1 + nf_offset); setRightPadding (1 - (getScrollWidth() - getViewportWidth() - getScrollX()) + nf_offset);
FPoint no_shadow(0,0); FPoint no_shadow(0,0);
scroll_size.setRect (1, 1, getClientWidth(), getClientHeight()); int w = getViewportWidth();
int h = getViewportHeight();
if ( w < 1 )
w = 1;
if ( h < 1 )
h = 1;
scroll_size.setRect (0, 0, w, h);
createArea (scroll_size, no_shadow, viewport); createArea (scroll_size, no_shadow, viewport);
setPreprocessingHandler setPreprocessingHandler
( (
@ -639,7 +664,6 @@ void FScrollView::calculateScrollbarPos()
hbar->setGeometry (2, height, width-2, 1); hbar->setGeometry (2, height, width-2, 1);
} }
setRightPadding (1 + nf_offset);
vbar->resize(); vbar->resize();
hbar->resize(); hbar->resize();
} }
@ -650,7 +674,7 @@ void FScrollView::setHorizontalScrollBarVisibility()
switch ( hMode ) switch ( hMode )
{ {
case fc::Auto: case fc::Auto:
if ( getScrollWidth() > getClientWidth() ) if ( getScrollWidth() > getViewportWidth() )
hbar->setVisible(); hbar->setVisible();
else else
hbar->hide(); hbar->hide();
@ -672,7 +696,7 @@ void FScrollView::setVerticalScrollBarVisibility()
switch ( vMode ) switch ( vMode )
{ {
case fc::Auto: case fc::Auto:
if ( getScrollHeight() > getClientHeight() ) if ( getScrollHeight() > getViewportHeight() )
vbar->setVisible(); vbar->setVisible();
else else
vbar->hide(); vbar->hide();
@ -696,7 +720,7 @@ void FScrollView::cb_VBarChange (FWidget*, void*)
short distance = 1; short distance = 1;
short& yoffset = scroll_offset.y_ref(); short& yoffset = scroll_offset.y_ref();
short yoffset_before = yoffset; short yoffset_before = yoffset;
short yoffset_end = short(getScrollHeight() - getClientHeight()); short yoffset_end = short(getScrollHeight() - getViewportHeight());
scrollType = vbar->getScrollType(); scrollType = vbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
@ -705,7 +729,7 @@ void FScrollView::cb_VBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageBackward: case FScrollbar::scrollPageBackward:
distance = short(getClientHeight()); distance = short(getViewportHeight());
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
yoffset -= distance; yoffset -= distance;
@ -716,7 +740,7 @@ void FScrollView::cb_VBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = short(getClientHeight()); distance = short(getViewportHeight());
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
yoffset += distance; yoffset += distance;
@ -773,6 +797,8 @@ void FScrollView::cb_VBarChange (FWidget*, void*)
if ( isVisible() && viewport && yoffset_before != yoffset ) if ( isVisible() && viewport && yoffset_before != yoffset )
{ {
viewport->has_changes = true; viewport->has_changes = true;
setTopPadding (1 - yoffset);
setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - yoffset));
copy2area(); copy2area();
hasChanges = true; hasChanges = true;
} }
@ -797,7 +823,7 @@ void FScrollView::cb_HBarChange (FWidget*, void*)
short distance = 1; short distance = 1;
short& xoffset = scroll_offset.x_ref(); short& xoffset = scroll_offset.x_ref();
short xoffset_before = xoffset; short xoffset_before = xoffset;
short xoffset_end = short(getScrollWidth() - getClientWidth()); short xoffset_end = short(getScrollWidth() - getViewportWidth());
scrollType = hbar->getScrollType(); scrollType = hbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
@ -806,7 +832,7 @@ void FScrollView::cb_HBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageBackward: case FScrollbar::scrollPageBackward:
distance = short(getClientWidth()); distance = short(getViewportWidth());
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
xoffset -= distance; xoffset -= distance;
@ -817,7 +843,7 @@ void FScrollView::cb_HBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = short(getClientWidth()); distance = short(getViewportWidth());
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
xoffset += distance; xoffset += distance;
@ -874,6 +900,8 @@ void FScrollView::cb_HBarChange (FWidget*, void*)
if ( isVisible() && viewport && xoffset_before != xoffset ) if ( isVisible() && viewport && xoffset_before != xoffset )
{ {
viewport->has_changes = true; viewport->has_changes = true;
setLeftPadding (1 - xoffset);
setRightPadding (1 - (getScrollWidth() - getViewportWidth() - xoffset) + nf_offset);
copy2area(); copy2area();
hasChanges = true; hasChanges = true;
} }

View File

@ -56,6 +56,8 @@ class FScrollView : public FWidget
// Accessors // Accessors
const char* getClassName() const; const char* getClassName() const;
int getViewportWidth() const;
int getViewportHeight() const;
int getScrollWidth() const; int getScrollWidth() const;
int getScrollHeight() const; int getScrollHeight() const;
const FPoint getScrollPos() const; const FPoint getScrollPos() const;
@ -63,9 +65,9 @@ class FScrollView : public FWidget
int getScrollY() const; int getScrollY() const;
// Mutator // Mutator
void setScrollWidth (int); virtual void setScrollWidth (int);
void setScrollHeight (int); virtual void setScrollHeight (int);
void setScrollSize (int, int); virtual void setScrollSize (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);
@ -102,6 +104,10 @@ class FScrollView : public FWidget
void copy2area(); void copy2area();
private: private:
// Constants
static const int vertical_border_spacing = 2;
static const int horizontal_border_spacing = 2;
// Disable copy constructor // Disable copy constructor
FScrollView (const FScrollView&); FScrollView (const FScrollView&);
@ -141,6 +147,14 @@ class FScrollView : public FWidget
inline const char* FScrollView::getClassName() const inline const char* FScrollView::getClassName() const
{ return "FScrollView"; } { return "FScrollView"; }
//----------------------------------------------------------------------
inline int FScrollView::getViewportWidth() const
{ return getWidth() - vertical_border_spacing - nf_offset; }
//----------------------------------------------------------------------
inline int FScrollView::getViewportHeight() const
{ return getHeight() - horizontal_border_spacing; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline int FScrollView::getScrollWidth() const inline int FScrollView::getScrollWidth() const
{ return scroll_size.getWidth(); } { return scroll_size.getWidth(); }

View File

@ -733,6 +733,12 @@ void FVTerm::resizeArea ( int offset_top, int offset_left
, int rsw, int bsh , int rsw, int bsh
, term_area* area ) , term_area* area )
{ {
assert ( offset_top >= 0 );
assert ( offset_left >= 0 );
assert ( width > 0 );
assert ( height > 0 );
assert ( rsw >= 0 );
assert ( bsh >= 0 );
int area_size; int area_size;
char_data default_char; char_data default_char;
line_changes unchanged; line_changes unchanged;

View File

@ -242,6 +242,11 @@ class FVTerm : public FObject, public FTerm
// Accessor // Accessor
virtual term_area* getPrintArea(); virtual term_area* getPrintArea();
// Inquiries
bool hasPrintArea() const;
bool hasChildPrintArea() const;
bool isVirtualWindow() const;
// Methods // Methods
void createArea ( const FRect& void createArea ( const FRect&
, const FPoint& , const FPoint&
@ -704,6 +709,18 @@ inline bool FVTerm::isInheritBackground()
inline FVTerm& FVTerm::print() inline FVTerm& FVTerm::print()
{ return *this; } { return *this; }
//----------------------------------------------------------------------
inline bool FVTerm::hasPrintArea() const
{ return print_area; }
//----------------------------------------------------------------------
inline bool FVTerm::hasChildPrintArea() const
{ return child_print_area; }
//----------------------------------------------------------------------
inline bool FVTerm::isVirtualWindow() const
{ return vwin; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::setPrintArea (term_area* area) inline void FVTerm::setPrintArea (term_area* area)
{ print_area = area; } { print_area = area; }

View File

@ -451,7 +451,7 @@ void FWidget::setTopPadding (int top, bool adjust)
if ( padding.top == top ) if ( padding.top == top )
return; return;
(top < 0) ? padding.top = 0 : padding.top = top; padding.top = top;
if ( adjust ) if ( adjust )
{ {
@ -472,7 +472,7 @@ void FWidget::setLeftPadding (int left, bool adjust)
if ( padding.left == left ) if ( padding.left == left )
return; return;
(left < 0) ? padding.left = 0 : padding.left = left; padding.left = left;
if ( adjust ) if ( adjust )
{ {
@ -493,7 +493,7 @@ void FWidget::setBottomPadding (int bottom, bool adjust)
if ( padding.bottom == bottom ) if ( padding.bottom == bottom )
return; return;
(bottom < 0) ? padding.bottom = 0 : padding.bottom = bottom; padding.bottom = bottom;
if ( adjust ) if ( adjust )
{ {
@ -514,7 +514,7 @@ void FWidget::setRightPadding (int right, bool adjust)
if ( padding.right == right ) if ( padding.right == right )
return; return;
(right < 0) ? padding.right = 0 : padding.right = right; padding.right = right;
if ( adjust ) if ( adjust )
{ {
@ -1697,48 +1697,9 @@ void FWidget::adjustSize()
adjust_wsize = wsize; adjust_wsize = wsize;
} }
if ( ! isWindowWidget() ) // Move and shrink in case of lack of space
{ if ( ! hasChildPrintArea() )
// move left if not enough space insufficientSpaceAdjust();
while ( getTermX()+getWidth()-padding.right > offset.getX2()+2 )
{
adjust_wsize.x1_ref()--;
adjust_wsize.x2_ref()--;
if ( adjust_wsize.x1_ref() < 1 )
adjust_wsize.x1_ref() = 1;
}
// move up if not enough space
while ( getTermY()+getHeight()-padding.bottom > offset.getY2()+2 )
{
adjust_wsize.y1_ref()--;
adjust_wsize.y2_ref()--;
if ( adjust_wsize.y1_ref() < 1 )
adjust_wsize.y1_ref() = 1;
}
// reduce the width if not enough space
while ( offset.getX1()+getWidth()-1 > offset.getX2() )
adjust_wsize.x2_ref()--;
if ( getWidth() < size_hints.min_width )
adjust_wsize.setWidth(size_hints.min_width);
if ( getWidth() <= 0 )
adjust_wsize.setWidth(1);
// reduce the height if not enough space
while ( offset.getY1()+getHeight()-1 > offset.getY2() )
adjust_wsize.y2_ref()--;
if ( getHeight() < size_hints.min_height )
adjust_wsize.setWidth(size_hints.min_height);
if ( getHeight() <= 0 )
adjust_wsize.setHeight(1);
}
client_offset.setCoordinates client_offset.setCoordinates
( (
@ -2202,6 +2163,55 @@ void FWidget::finish()
} }
} }
//----------------------------------------------------------------------
inline void FWidget::insufficientSpaceAdjust()
{
// Move and shrink widget if there is not enough space available
if ( isWindowWidget() )
return;
// move left if not enough space
while ( getTermX()+getWidth()-padding.right > offset.getX2()+2 )
{
adjust_wsize.x1_ref()--;
adjust_wsize.x2_ref()--;
if ( adjust_wsize.x1_ref() < 1 )
adjust_wsize.x1_ref() = 1;
}
// move up if not enough space
while ( getTermY()+getHeight()-padding.bottom > offset.getY2()+2 )
{
adjust_wsize.y1_ref()--;
adjust_wsize.y2_ref()--;
if ( adjust_wsize.y1_ref() < 1 )
adjust_wsize.y1_ref() = 1;
}
// reduce the width if not enough space
while ( offset.getX1()+getWidth()-1 > offset.getX2() )
adjust_wsize.x2_ref()--;
if ( getWidth() < size_hints.min_width )
adjust_wsize.setWidth(size_hints.min_width);
if ( getWidth() <= 0 )
adjust_wsize.setWidth(1);
// reduce the height if not enough space
while ( offset.getY1()+getHeight()-1 > offset.getY2() )
adjust_wsize.y2_ref()--;
if ( getHeight() < size_hints.min_height )
adjust_wsize.setWidth(size_hints.min_height);
if ( getHeight() <= 0 )
adjust_wsize.setHeight(1);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::draw() void FWidget::draw()
{ } { }

View File

@ -427,6 +427,7 @@ class FWidget : public FVTerm
// Methods // Methods
void init(); void init();
void finish(); void finish();
void insufficientSpaceAdjust();
void processDestroy(); void processDestroy();
virtual void draw(); virtual void draw();
static void setColorTheme(); static void setColorTheme();

View File

@ -232,7 +232,8 @@ bool FWindow::setAlwaysOnTop (bool on)
bool FWindow::isWindowHidden() const bool FWindow::isWindowHidden() const
{ {
// returns the window hidden state // returns the window hidden state
if ( vwin )
if ( isVirtualWindow() )
return ! vwin->visible; return ! vwin->visible;
else else
return false; return false;
@ -286,7 +287,7 @@ void FWindow::drawBorder()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::show() void FWindow::show()
{ {
if ( vwin ) if ( isVirtualWindow() )
vwin->visible = true; vwin->visible = true;
FWidget::show(); FWidget::show();
@ -295,7 +296,7 @@ void FWindow::show()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::hide() void FWindow::hide()
{ {
if ( vwin ) if ( isVirtualWindow() )
vwin->visible = false; vwin->visible = false;
FWidget::hide(); FWidget::hide();
@ -306,7 +307,7 @@ void FWindow::setX (int x, bool adjust)
{ {
FWidget::setX (x, adjust); FWidget::setX (x, adjust);
if ( vwin ) if ( isVirtualWindow() )
vwin->offset_top = getTermX() - 1; vwin->offset_top = getTermX() - 1;
} }
@ -318,7 +319,7 @@ void FWindow::setY (int y, bool adjust)
FWidget::setY (y, adjust); FWidget::setY (y, adjust);
if ( vwin ) if ( isVirtualWindow() )
vwin->offset_left = getTermY() - 1; vwin->offset_left = getTermY() - 1;
} }
@ -330,7 +331,7 @@ void FWindow::setPos (int x, int y, bool adjust)
FWidget::setPos (x, y, adjust); FWidget::setPos (x, y, adjust);
if ( vwin ) if ( isVirtualWindow() )
{ {
vwin->offset_top = getTermX() - 1; vwin->offset_top = getTermX() - 1;
vwin->offset_left = getTermY() - 1; vwin->offset_left = getTermY() - 1;
@ -343,7 +344,7 @@ void FWindow::setWidth (int w, bool adjust)
int old_width = getWidth(); int old_width = getWidth();
FWidget::setWidth (w, adjust); FWidget::setWidth (w, adjust);
if ( vwin && getWidth() != old_width ) if ( isVirtualWindow() && getWidth() != old_width )
{ {
FRect geometry = getTermGeometry(); FRect geometry = getTermGeometry();
geometry.move(-1,-1); geometry.move(-1,-1);
@ -357,7 +358,7 @@ void FWindow::setHeight (int h, bool adjust)
int old_height = getHeight(); int old_height = getHeight();
FWidget::setHeight (h, adjust); FWidget::setHeight (h, adjust);
if ( vwin && getHeight() != old_height ) if ( isVirtualWindow() && getHeight() != old_height )
{ {
FRect geometry = getTermGeometry(); FRect geometry = getTermGeometry();
geometry.move(-1,-1); geometry.move(-1,-1);
@ -372,7 +373,7 @@ void FWindow::setSize (int w, int h, bool adjust)
int old_height = getHeight(); int old_height = getHeight();
FWidget::setSize (w, h, adjust); FWidget::setSize (w, h, adjust);
if ( vwin && (getWidth() != old_width || getHeight() != old_height) ) if ( isVirtualWindow() && (getWidth() != old_width || getHeight() != old_height) )
{ {
FRect geometry = getTermGeometry(); FRect geometry = getTermGeometry();
geometry.move(-1,-1); geometry.move(-1,-1);
@ -393,7 +394,7 @@ void FWindow::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);
if ( ! vwin ) if ( ! isVirtualWindow() )
return; return;
if ( getWidth() != old_width || getHeight() != old_height ) if ( getWidth() != old_width || getHeight() != old_height )
@ -417,7 +418,7 @@ void FWindow::move (int dx, int dy)
{ {
FWidget::move (dx,dy); FWidget::move (dx,dy);
if ( vwin ) if ( isVirtualWindow() )
{ {
vwin->offset_top = getTermX() - 1; vwin->offset_top = getTermX() - 1;
vwin->offset_left = getTermY() - 1; vwin->offset_left = getTermY() - 1;
@ -765,7 +766,7 @@ void FWindow::setShadowSize (int right, int bottom)
new_right = getShadow().getX(); new_right = getShadow().getX();
new_bottom = getShadow().getY(); new_bottom = getShadow().getY();
if ( vwin && (new_right != old_right || new_bottom != old_bottom) ) if ( isVirtualWindow() && (new_right != old_right || new_bottom != old_bottom) )
{ {
FRect geometry = getTermGeometry(); FRect geometry = getTermGeometry();
geometry.move(-1,-1); geometry.move(-1,-1);
@ -784,7 +785,7 @@ void FWindow::adjustSize()
if ( zoomed ) if ( zoomed )
setGeometry (1, 1, getMaxWidth(), getMaxHeight(), false); setGeometry (1, 1, getMaxWidth(), getMaxHeight(), false);
else if ( vwin ) else if ( isVirtualWindow() )
{ {
if ( getX() != old_x ) if ( getX() != old_x )
vwin->offset_top = getTermX() - 1; vwin->offset_top = getTermX() - 1;

View File

@ -23,21 +23,88 @@ class scrollview : public FScrollView
// Destructor // Destructor
~scrollview (); ~scrollview ();
// Mutator
void setScrollSize (int, int);
private: private:
// Methods // Method
void draw(); void draw();
// Callback methods
void cb_go_east (FWidget*, void*);
void cb_go_south (FWidget*, void*);
void cb_go_west (FWidget*, void*);
void cb_go_north (FWidget*, void*);
// Data Members
FButton* go_east;
FButton* go_south;
FButton* go_west;
FButton* go_north;
}; };
#pragma pack(pop) #pragma pack(pop)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
scrollview::scrollview (FWidget* parent) scrollview::scrollview (FWidget* parent)
: FScrollView(parent) : FScrollView(parent)
{ } {
go_east = new FButton(wchar_t(fc::BlackRightPointingPointer) , this);
go_east->setGeometry (1, 1, 5, 1);
go_south = new FButton(wchar_t(fc::BlackDownPointingTriangle) , this);
go_south->setGeometry (getScrollWidth() - 5, 1, 5, 1);
go_west = new FButton(wchar_t(fc::BlackLeftPointingPointer) , this);
go_west->setGeometry (getScrollWidth() - 5, getScrollHeight() - 2, 5, 1);
go_north = new FButton(wchar_t(fc::BlackUpPointingTriangle) , this);
go_north->setGeometry (1, getScrollHeight() - 2, 5, 1);
if ( isCygwinTerminal() )
{
go_south->setText ('v');
go_north->setText ('^');
}
go_east->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &scrollview::cb_go_east)
);
go_south->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &scrollview::cb_go_south)
);
go_west->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &scrollview::cb_go_west)
);
go_north->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &scrollview::cb_go_north)
);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
scrollview::~scrollview() scrollview::~scrollview()
{ } { }
//----------------------------------------------------------------------
void scrollview::setScrollSize (int width, int height)
{
FScrollView::setScrollSize (width, height);
go_south->setPos (width - 5, 1);
go_west->setPos (width - 5, height - 1);
go_north->setPos (1, height - 1);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void scrollview::draw() void scrollview::draw()
{ {
@ -55,6 +122,41 @@ void scrollview::draw()
FScrollView::draw(); FScrollView::draw();
} }
//----------------------------------------------------------------------
void scrollview::cb_go_east (FWidget*, void*)
{
scrollToX (getScrollWidth() - getViewportWidth() + 1);
go_south->setFocus();
go_east->redraw();
go_south->redraw();
}
//----------------------------------------------------------------------
void scrollview::cb_go_south (FWidget*, void*)
{
scrollToY (getScrollHeight() - getViewportHeight() + 1);
go_west->setFocus();
go_south->redraw();
go_west->redraw();
}
//----------------------------------------------------------------------
void scrollview::cb_go_west (FWidget*, void*)
{
scrollToX (1);
go_north->setFocus();
go_west->redraw();
go_north->redraw();}
//----------------------------------------------------------------------
void scrollview::cb_go_north (FWidget*, void*)
{
scrollToY (1);
go_east->setFocus();
go_north->redraw();
go_east->redraw();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class scrollviewdemo // class scrollviewdemo
@ -91,7 +193,7 @@ scrollviewdemo::scrollviewdemo (FWidget* parent)
// The scrolling viewport widget // The scrolling viewport widget
scrollview* sview = new scrollview (this); scrollview* sview = new scrollview (this);
sview->setGeometry(3, 2, 44, 12); sview->setGeometry(3, 2, 44, 12);
sview->setScrollSize(88, 24); sview->setScrollSize(188, 124);
// Quit button // Quit button
FButton* button = new FButton("&Quit", this); FButton* button = new FButton("&Quit", this);

View File

@ -250,6 +250,9 @@ class MyDialog : public FDialog
// Disable assignment operator (=) // Disable assignment operator (=)
MyDialog& operator = (const MyDialog&); MyDialog& operator = (const MyDialog&);
// Method
void adjustSize();
// Event handlers // Event handlers
void onClose (FCloseEvent*); void onClose (FCloseEvent*);
@ -271,8 +274,6 @@ class MyDialog : public FDialog
void cb_setInput (FWidget*, void*); void cb_setInput (FWidget*, void*);
void cb_exitApp (FWidget*, void*); void cb_exitApp (FWidget*, void*);
void adjustSize();
// Data Members // Data Members
FLineEdit* myLineEdit; FLineEdit* myLineEdit;
FListBox* myList; FListBox* myList;
@ -626,6 +627,24 @@ MyDialog::MyDialog (FWidget* parent)
MyDialog::~MyDialog() MyDialog::~MyDialog()
{ } { }
//----------------------------------------------------------------------
void MyDialog::adjustSize()
{
int h = getParentWidget()->getHeight() - 4;
setHeight (h, false);
int X = int((getParentWidget()->getWidth() - getWidth()) / 2);
if ( X < 1 )
X = 1;
setX (X, false);
if ( myList )
myList->setHeight (getHeight() - 3, false);
FDialog::adjustSize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::onClose (FCloseEvent* ev) void MyDialog::onClose (FCloseEvent* ev)
{ {
@ -879,23 +898,6 @@ void MyDialog::cb_exitApp (FWidget*, void*)
close(); close();
} }
//----------------------------------------------------------------------
void MyDialog::adjustSize()
{
int h = getParentWidget()->getHeight() - 4;
setHeight (h, false);
int X = int((getParentWidget()->getWidth() - getWidth()) / 2);
if ( X < 1 )
X = 1;
setX (X, false);
if ( myList )
myList->setHeight (getHeight() - 3, false);
FDialog::adjustSize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part