FScrollView provides a scrollable viewport to change area

This commit is contained in:
Markus Gans 2017-01-02 08:07:46 +01:00
parent 628bec0b29
commit b2e4a59f54
20 changed files with 1127 additions and 144 deletions

1
.gitignore vendored
View File

@ -30,6 +30,7 @@ test/opti-move
test/hello test/hello
test/watch test/watch
test/menu test/menu
test/scrollview
test/windows test/windows
test/term-attributes test/term-attributes
test/transparent test/transparent

View File

@ -1,3 +1,8 @@
2017-01-02 Markus Gans <guru.mail@muenster.de>
* The new FScrollView widget provides a scrollable viewport
to change the area of interest
* The scrollview example illustrates the use of FScrollView class
2016-12-28 Markus Gans <guru.mail@muenster.de> 2016-12-28 Markus Gans <guru.mail@muenster.de>
* Reduce public methods in FVTerm * Reduce public methods in FVTerm

View File

@ -1,7 +1,7 @@
# #
# spec file for package finalcut # spec file for package finalcut
# #
# Copyright (c) 2016 by Markus Gans # Copyright (c) 2017 by Markus Gans
# #
Name: finalcut Name: finalcut

View File

@ -31,6 +31,7 @@ libfinal_la_SOURCES = \
fcheckmenuitem.cpp \ fcheckmenuitem.cpp \
fmenulist.cpp \ fmenulist.cpp \
fdialog.cpp \ fdialog.cpp \
fscrollview.cpp \
fwindow.cpp \ fwindow.cpp \
fmessagebox.cpp \ fmessagebox.cpp \
ftooltip.cpp \ ftooltip.cpp \
@ -84,6 +85,7 @@ finalcutinclude_HEADERS = \
fradiobutton.h \ fradiobutton.h \
frect.h \ frect.h \
fscrollbar.h \ fscrollbar.h \
fscrollview.h \
fstatusbar.h \ fstatusbar.h \
fstring.h \ fstring.h \
ftcap_map.h \ ftcap_map.h \

View File

@ -35,6 +35,7 @@ INCLUDE_HEADERS = \
fradiobutton.h \ fradiobutton.h \
frect.h \ frect.h \
fscrollbar.h \ fscrollbar.h \
fscrollview.h \
fstatusbar.h \ fstatusbar.h \
fstring.h \ fstring.h \
fterm.h \ fterm.h \
@ -77,6 +78,7 @@ OBJS = \
fcheckmenuitem.o \ fcheckmenuitem.o \
fmenulist.o \ fmenulist.o \
fdialog.o \ fdialog.o \
fscrollview.o \
fwindow.o \ fwindow.o \
fmessagebox.o \ fmessagebox.o \
ftooltip.o \ ftooltip.o \

View File

@ -35,6 +35,7 @@ INCLUDE_HEADERS = \
fradiobutton.h \ fradiobutton.h \
frect.h \ frect.h \
fscrollbar.h \ fscrollbar.h \
fscrollview.h \
fstatusbar.h \ fstatusbar.h \
fstring.h \ fstring.h \
fterm.h \ fterm.h \
@ -77,6 +78,7 @@ OBJS = \
fcheckmenuitem.o \ fcheckmenuitem.o \
fmenulist.o \ fmenulist.o \
fdialog.o \ fdialog.o \
fscrollview.o \
fwindow.o \ fwindow.o \
fmessagebox.o \ fmessagebox.o \
ftooltip.o \ ftooltip.o \

View File

@ -133,10 +133,10 @@ am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \
ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \ ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \
flabel.lo flistbox.lo fmenu.lo fdialoglistmenu.lo fmenubar.lo \ flabel.lo flistbox.lo fmenu.lo fdialoglistmenu.lo fmenubar.lo \
fmenuitem.lo fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo \ fmenuitem.lo fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo \
fdialog.lo fwindow.lo fmessagebox.lo ftooltip.lo \ fdialog.lo fscrollview.lo fwindow.lo fmessagebox.lo \
ffiledialog.lo ftextview.lo fstatusbar.lo fterm.lo fvterm.lo \ ftooltip.lo ffiledialog.lo ftextview.lo fstatusbar.lo fterm.lo \
fevent.lo foptiattr.lo foptimove.lo fapp.lo fwidget.lo \ fvterm.lo fevent.lo foptiattr.lo foptimove.lo fapp.lo \
fobject.lo fwidget.lo fobject.lo
libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS) libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -396,6 +396,7 @@ libfinal_la_SOURCES = \
fcheckmenuitem.cpp \ fcheckmenuitem.cpp \
fmenulist.cpp \ fmenulist.cpp \
fdialog.cpp \ fdialog.cpp \
fscrollview.cpp \
fwindow.cpp \ fwindow.cpp \
fmessagebox.cpp \ fmessagebox.cpp \
ftooltip.cpp \ ftooltip.cpp \
@ -447,6 +448,7 @@ finalcutinclude_HEADERS = \
fradiobutton.h \ fradiobutton.h \
frect.h \ frect.h \
fscrollbar.h \ fscrollbar.h \
fscrollview.h \
fstatusbar.h \ fstatusbar.h \
fstring.h \ fstring.h \
ftcap_map.h \ ftcap_map.h \
@ -562,6 +564,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fradiomenuitem.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fradiomenuitem.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frect.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frect.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fscrollbar.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fscrollbar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fscrollview.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstatusbar.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstatusbar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fswitch.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fswitch.Plo@am__quote@

View File

@ -386,9 +386,12 @@ void FListBox::clear()
void FListBox::onKeyPress (FKeyEvent* ev) void FListBox::onKeyPress (FKeyEvent* ev)
{ {
int element_count = int(getCount()); int element_count = int(getCount());
int padding_space = 2; // 1 leading space + 1 tailing space
int current_before = current; int current_before = current;
int xoffset_before = xoffset; int xoffset_before = xoffset;
int xoffset_end = max_line_width - getClientWidth() + padding_space;
int yoffset_before = yoffset; int yoffset_before = yoffset;
int yoffset_end = element_count - getClientHeight();
int key = ev->key(); int key = ev->key();
switch ( key ) switch ( key )
@ -419,7 +422,7 @@ void FListBox::onKeyPress (FKeyEvent* ev)
if ( current > element_count ) if ( current > element_count )
current = element_count; current = element_count;
if ( current - yoffset >= getHeight() - 1 ) if ( current - yoffset > getClientHeight() )
yoffset++; yoffset++;
inc_search.clear(); inc_search.clear();
@ -439,8 +442,8 @@ void FListBox::onKeyPress (FKeyEvent* ev)
case fc::Fkey_right: case fc::Fkey_right:
xoffset++; xoffset++;
if ( xoffset > max_line_width - getWidth() + nf_offset + 4 ) if ( xoffset > xoffset_end )
xoffset = max_line_width - getWidth() + nf_offset + 4; xoffset = xoffset_end;
if ( xoffset < 0 ) if ( xoffset < 0 )
xoffset = 0; xoffset = 0;
@ -450,14 +453,14 @@ void FListBox::onKeyPress (FKeyEvent* ev)
break; break;
case fc::Fkey_ppage: case fc::Fkey_ppage:
current -= getHeight()-3; current -= getClientHeight() - 1;
if ( current < 1 ) if ( current < 1 )
current=1; current=1;
if ( current <= yoffset ) if ( current <= yoffset )
{ {
yoffset -= getHeight()-3; yoffset -= getClientHeight() - 1;
if ( yoffset < 0 ) if ( yoffset < 0 )
yoffset=0; yoffset=0;
@ -468,17 +471,17 @@ void FListBox::onKeyPress (FKeyEvent* ev)
break; break;
case fc::Fkey_npage: case fc::Fkey_npage:
current += getHeight()-3; current += getClientHeight() - 1;
if ( current > element_count ) if ( current > element_count )
current = element_count; current = element_count;
if ( current - yoffset >= getHeight() - 1 ) if ( current - yoffset > getClientHeight() )
{ {
yoffset += getHeight()-3; yoffset += getClientHeight() - 1;
if ( yoffset > element_count - getHeight() + 2 ) if ( yoffset > yoffset_end )
yoffset = element_count - getHeight() + 2; yoffset = yoffset_end;
} }
inc_search.clear(); inc_search.clear();
@ -495,8 +498,8 @@ void FListBox::onKeyPress (FKeyEvent* ev)
case fc::Fkey_end: case fc::Fkey_end:
current = element_count; current = element_count;
if ( current >= getHeight() - 1 ) if ( current > getClientHeight() )
yoffset = element_count - getHeight() + 2; yoffset = yoffset_end;
inc_search.clear(); inc_search.clear();
ev->accept(); ev->accept();
@ -859,7 +862,7 @@ void FListBox::onMouseMove (FMouseEvent* ev)
{ {
// drag up // drag up
if ( drag_scroll != FListBox::noScroll if ( drag_scroll != FListBox::noScroll
&& scroll_distance < getHeight()-2 ) && scroll_distance < getClientHeight() )
scroll_distance++; scroll_distance++;
if ( ! scroll_timer && current > 1 ) if ( ! scroll_timer && current > 1 )
@ -883,7 +886,7 @@ void FListBox::onMouseMove (FMouseEvent* ev)
{ {
// drag down // drag down
if ( drag_scroll != FListBox::noScroll if ( drag_scroll != FListBox::noScroll
&& scroll_distance < getHeight()-2 ) && scroll_distance < getClientHeight() )
scroll_distance++; scroll_distance++;
if ( ! scroll_timer && current < int(getCount()) ) if ( ! scroll_timer && current < int(getCount()) )
@ -940,6 +943,7 @@ void FListBox::onTimer (FTimerEvent*)
int element_count = int(getCount()); int element_count = int(getCount());
int current_before = current; int current_before = current;
int yoffset_before = yoffset; int yoffset_before = yoffset;
int yoffset_end = element_count - getClientHeight();
switch ( int(drag_scroll) ) switch ( int(drag_scroll) )
{ {
@ -979,11 +983,11 @@ void FListBox::onTimer (FTimerEvent*)
if ( current > element_count ) if ( current > element_count )
current = element_count; current = element_count;
if ( current - yoffset >= getHeight() - 1 ) if ( current - yoffset > getClientHeight() )
yoffset += scroll_distance; yoffset += scroll_distance;
if ( yoffset > element_count - getHeight() + 2 ) if ( yoffset > yoffset_end )
yoffset = element_count - getHeight() + 2; yoffset = yoffset_end;
break; break;
@ -1047,7 +1051,7 @@ void FListBox::onWheel (FWheelEvent* ev)
element_count = int(getCount()); element_count = int(getCount());
current_before = current; current_before = current;
yoffset_before = yoffset; yoffset_before = yoffset;
yoffset_end = element_count - getHeight() + 2; yoffset_end = element_count - getClientHeight();
if ( yoffset_end < 0 ) if ( yoffset_end < 0 )
yoffset_end = 0; yoffset_end = 0;
@ -1153,15 +1157,20 @@ void FListBox::onFocusOut (FFocusEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::cb_VBarChange (FWidget*, void*) void FListBox::cb_VBarChange (FWidget*, void*)
{ {
FScrollbar::sType scrollType;
int distance = 1; int distance = 1;
int element_count = int(getCount()); int element_count = int(getCount());
int yoffset_before = yoffset; int yoffset_before = yoffset;
int scrollType = vbar->getScrollType(); int yoffset_end = element_count - getClientHeight();
scrollType = vbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
{ {
case FScrollbar::noScroll:
break;
case FScrollbar::scrollPageBackward: case FScrollbar::scrollPageBackward:
distance = getHeight()-2; distance = getClientHeight();
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
current -= distance; current -= distance;
@ -1178,7 +1187,7 @@ void FListBox::cb_VBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = getHeight()-2; distance = getClientHeight();
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
current += distance; current += distance;
@ -1186,11 +1195,11 @@ void FListBox::cb_VBarChange (FWidget*, void*)
if ( current > element_count ) if ( current > element_count )
current = element_count; current = element_count;
if ( current - yoffset >= getHeight() - 1 ) if ( current - yoffset > getClientHeight() )
yoffset += distance; yoffset += distance;
if ( yoffset > element_count - getHeight() + 2 ) if ( yoffset > yoffset_end )
yoffset = element_count - getHeight() + 2; yoffset = yoffset_end;
break; break;
@ -1204,8 +1213,8 @@ void FListBox::cb_VBarChange (FWidget*, void*)
int c = current - yoffset; int c = current - yoffset;
yoffset = val; yoffset = val;
if ( yoffset > element_count - getHeight() + 2 ) if ( yoffset > yoffset_end )
yoffset = element_count - getHeight() + 2; yoffset = yoffset_end;
if ( yoffset < 0 ) if ( yoffset < 0 )
yoffset = 0; yoffset = 0;
@ -1234,9 +1243,6 @@ void FListBox::cb_VBarChange (FWidget*, void*)
onWheel(&wheel_ev); onWheel(&wheel_ev);
} }
break; break;
default:
break;
} }
if ( isVisible() ) if ( isVisible() )
@ -1258,15 +1264,20 @@ void FListBox::cb_VBarChange (FWidget*, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::cb_HBarChange (FWidget*, void*) void FListBox::cb_HBarChange (FWidget*, void*)
{ {
FScrollbar::sType scrollType;
int distance = 1; int distance = 1;
int padding_space = 2; // 1 leading space + 1 tailing space
int xoffset_before = xoffset; int xoffset_before = xoffset;
int xoffset_end = max_line_width - getWidth() + nf_offset + 4; int xoffset_end = max_line_width - getClientWidth() + padding_space;
int scrollType = hbar->getScrollType(); scrollType = hbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
{ {
case FScrollbar::noScroll:
break;
case FScrollbar::scrollPageBackward: case FScrollbar::scrollPageBackward:
distance = getWidth() - nf_offset - 4; distance = getClientWidth() - padding_space;
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
xoffset -= distance; xoffset -= distance;
@ -1276,13 +1287,13 @@ void FListBox::cb_HBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = getWidth() - nf_offset - 4; distance = getClientWidth() - padding_space;
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
xoffset += distance; xoffset += distance;
if ( xoffset > max_line_width - getWidth() + nf_offset + 4 ) if ( xoffset > xoffset_end )
xoffset = max_line_width - getWidth() + nf_offset + 4; xoffset = xoffset_end;
if ( xoffset < 0 ) if ( xoffset < 0 )
xoffset = 0; xoffset = 0;
@ -1298,8 +1309,8 @@ void FListBox::cb_HBarChange (FWidget*, void*)
xoffset = val; xoffset = val;
if ( xoffset > max_line_width - getWidth() + nf_offset + 4 ) if ( xoffset > xoffset_end )
xoffset = max_line_width - getWidth() + nf_offset + 4; xoffset = xoffset_end;
if ( xoffset < 0 ) if ( xoffset < 0 )
xoffset = 0; xoffset = 0;
@ -1328,9 +1339,6 @@ void FListBox::cb_HBarChange (FWidget*, void*)
xoffset = xoffset_end; xoffset = xoffset_end;
break; break;
default:
break;
} }
if ( isVisible() ) if ( isVisible() )
@ -1360,8 +1368,8 @@ void FListBox::adjustYOffset()
{ {
int element_count = int(getCount()); int element_count = int(getCount());
if ( yoffset > element_count - getHeight() + 2 ) if ( yoffset > element_count - getClientHeight() )
yoffset = element_count - getHeight() + 2; yoffset = element_count - getClientHeight();
if ( yoffset < 0 ) if ( yoffset < 0 )
yoffset = 0; yoffset = 0;
@ -1369,36 +1377,36 @@ void FListBox::adjustYOffset()
if ( current < yoffset ) if ( current < yoffset )
current = yoffset; current = yoffset;
if ( current >= yoffset + getHeight() - 1 ) if ( yoffset < current - getClientHeight() )
yoffset = current - getHeight() + 2; yoffset = current - getClientHeight();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::adjustSize() void FListBox::adjustSize()
{ {
int element_count; int element_count;
adjustYOffset();
FWidget::adjustSize(); FWidget::adjustSize();
adjustYOffset();
element_count = int(getCount()); element_count = int(getCount());
vbar->setMaximum(element_count - getHeight() + 2); vbar->setMaximum(element_count - getClientHeight());
vbar->setPageSize(element_count, getHeight() - 2); vbar->setPageSize(element_count, getClientHeight());
vbar->setX(getWidth()); vbar->setX(getWidth());
vbar->setHeight (getHeight()-2, false); vbar->setHeight (getClientHeight(), false);
vbar->resize(); vbar->resize();
hbar->setMaximum(max_line_width - getWidth() + nf_offset + 4); hbar->setMaximum(max_line_width - getClientWidth() + 2);
hbar->setPageSize(max_line_width, getWidth() - nf_offset - 4); hbar->setPageSize(max_line_width, getClientWidth() - 2);
hbar->setY(getHeight()); hbar->setY(getHeight());
hbar->setWidth (getWidth()-2, false); hbar->setWidth (getClientWidth(), false);
hbar->resize(); hbar->resize();
if ( element_count < getHeight() - 1 ) if ( element_count <= getClientHeight() )
vbar->hide(); vbar->hide();
else else
vbar->setVisible(); vbar->setVisible();
if ( max_line_width < getWidth() - nf_offset - 3 ) if ( max_line_width < getClientWidth() - 1 )
hbar->hide(); hbar->hide();
else else
hbar->setVisible(); hbar->setVisible();
@ -1415,8 +1423,6 @@ void FListBox::init()
if ( isEnabled() ) if ( isEnabled() )
flags |= fc::active; flags |= fc::active;
nf_offset = isNewFont() ? 1 : 0;
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
@ -1443,6 +1449,12 @@ void FListBox::init()
"change-value", "change-value",
_METHOD_CALLBACK (this, &FListBox::cb_HBarChange) _METHOD_CALLBACK (this, &FListBox::cb_HBarChange)
); );
nf_offset = isNewFont() ? 1 : 0;
setTopPadding(1);
setLeftPadding(1);
setBottomPadding(1);
setRightPadding(1 + nf_offset);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1519,11 +1531,11 @@ void FListBox::drawLabel()
else else
setColor(wc.label_inactive_fg, wc.label_inactive_bg); setColor(wc.label_inactive_fg, wc.label_inactive_bg);
if ( length <= uInt(getWidth()-2) ) if ( length <= uInt(getClientWidth()) )
print (txt); print (txt);
else else
{ {
print (text.left(uInt(getWidth()-4))); print (text.left(uInt(getClientWidth()-2)));
setColor (wc.label_ellipsis_fg, wc.label_bg); setColor (wc.label_ellipsis_fg, wc.label_bg);
print(".."); print("..");
} }

View File

@ -58,7 +58,6 @@ class FObject
// Typedef // Typedef
typedef std::list<FObject*> object_list; typedef std::list<FObject*> object_list;
typedef std::vector<timer_data> TimerList;
// Constructor // Constructor
explicit FObject (FObject* = 0); explicit FObject (FObject* = 0);
@ -89,14 +88,17 @@ class FObject
bool delOwnTimer(); bool delOwnTimer();
bool delAllTimer(); bool delAllTimer();
// Data Members
static TimerList* timer_list;
protected: protected:
// Typedef
typedef std::vector<timer_data> TimerList;
// Event handler // Event handler
virtual bool event (FEvent*); virtual bool event (FEvent*);
virtual void onTimer (FTimerEvent*); virtual void onTimer (FTimerEvent*);
// Data Members
static TimerList* timer_list;
private: private:
// Disable copy constructor // Disable copy constructor
FObject (const FObject&); FObject (const FObject&);

View File

@ -216,7 +216,7 @@ void FScrollbar::calculateSliderValues()
} }
slider_pos = int( round ( float((bar_length - slider_length) * val) slider_pos = int( round ( float((bar_length - slider_length) * val)
/ float(max - min) ) ); / float(max - min) ) );
if ( slider_pos < 0 ) if ( slider_pos < 0 )
slider_pos = 0; slider_pos = 0;
@ -581,6 +581,14 @@ void FScrollbar::onTimer (FTimerEvent*)
|| ( scroll_type == FScrollbar::scrollPageForward || ( scroll_type == FScrollbar::scrollPageForward
&& slider_pos+slider_length > slider_click_stop_pos ) ) && slider_pos+slider_length > slider_click_stop_pos ) )
{ {
// Scroll to the end
if ( scroll_type == FScrollbar::scrollPageForward
&& slider_pos+slider_length > slider_click_stop_pos )
{
setValue(max);
processScroll();
}
delOwnTimer(); delOwnTimer();
return; return;
} }
@ -691,7 +699,7 @@ void FScrollbar::processMiddleButton (int x, int y)
if ( y >1 && y < getHeight() ) if ( y >1 && y < getHeight() )
{ {
new_val = int( round ( float(max - min) * (y - 2.0 - (slider_length/2)) new_val = int( round ( float(max - min) * (y - 2.0 - (slider_length/2))
/ float(bar_length - slider_length) ) ); / float(bar_length - slider_length) ) );
} }
else else
return; return;
@ -703,7 +711,7 @@ void FScrollbar::processMiddleButton (int x, int y)
if ( x > 1+nf && x < getWidth()-nf ) if ( x > 1+nf && x < getWidth()-nf )
{ {
new_val = int( round ( float(max - min) * (x - 2.0 - nf - (slider_length/2)) new_val = int( round ( float(max - min) * (x - 2.0 - nf - (slider_length/2))
/ float(bar_length - slider_length) ) ); / float(bar_length - slider_length) ) );
} }
else else
return; return;

627
src/fscrollview.cpp Normal file
View File

@ -0,0 +1,627 @@
// File: fscrollview.cpp
// Provides: class FScrollView
#include "fscrollview.h"
//----------------------------------------------------------------------
// class FScrollView
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FScrollView::FScrollView (FWidget* parent)
: FWidget(parent)
, scroll_size(1,1,1,1)
, scroll_offset()
, viewport(0)
, vbar(0)
, hbar(0)
, nf_offset(0)
, own_print_area(false)
{
init();
}
//----------------------------------------------------------------------
FScrollView::~FScrollView() // destructor
{
delete vbar;
delete hbar;
removeArea (viewport);
}
// public methods of FScrollView
//----------------------------------------------------------------------
void FScrollView::setScrollWidth (int width)
{
if ( width < getClientWidth() )
width = getClientWidth();
if ( scroll_size.getWidth() == width )
return;
if ( viewport )
{
FPoint no_shadow(0,0);
scroll_size.setWidth (width);
resizeArea (scroll_size, no_shadow, viewport);
}
hbar->setMaximum (width - getClientWidth());
hbar->setPageSize (width, getClientWidth());
hbar->calculateSliderValues();
if ( ! hbar->isVisible() )
hbar->setVisible();
}
//----------------------------------------------------------------------
void FScrollView::setScrollHeight (int height)
{
if ( height < getClientHeight() )
height = getClientHeight();
if ( scroll_size.getHeight() == height )
return;
if ( viewport )
{
FPoint no_shadow(0,0);
scroll_size.setHeight (height);
resizeArea (scroll_size, no_shadow, viewport);
}
vbar->setMaximum (height - getClientHeight());
vbar->setPageSize (height, getClientHeight());
vbar->calculateSliderValues();
if ( ! vbar->isVisible() )
vbar->setVisible();
}
//----------------------------------------------------------------------
void FScrollView::setScrollSize (int width, int height)
{
if ( width < getClientWidth() )
width = getClientWidth();
if ( height < getClientHeight() )
height = getClientHeight();
if ( scroll_size.getWidth() == width
&& scroll_size.getHeight() == height )
return;
if ( viewport )
{
FPoint no_shadow(0,0);
scroll_size.setSize (width, height);
resizeArea (scroll_size, no_shadow, viewport);
}
hbar->setMaximum (width - getClientWidth());
hbar->setPageSize (width, getClientWidth());
hbar->calculateSliderValues();
if ( ! hbar->isVisible() )
hbar->setVisible();
vbar->setMaximum (height - getClientHeight());
vbar->setPageSize (height, getClientHeight());
vbar->calculateSliderValues();
if ( ! vbar->isVisible() )
vbar->setVisible();
}
//----------------------------------------------------------------------
void FScrollView::setX (int x, bool adjust)
{
FWidget::setX (x, adjust);
scroll_size.setX (getTermX() - 1);
}
//----------------------------------------------------------------------
void FScrollView::setY (int y, bool adjust)
{
FWidget::setY (y, adjust);
scroll_size.setY (getTermY() - 1);
}
//----------------------------------------------------------------------
void FScrollView::setPos (int x, int y, bool adjust)
{
FWidget::setPos (x, y, adjust);
scroll_size.setPos (getTermX() - 1, getTermY() - 1);
}
//----------------------------------------------------------------------
void FScrollView::setWidth (int w, bool adjust)
{
FWidget::setWidth (w, adjust);
calculateScrollbarPos();
if ( scroll_size.getWidth() < getClientWidth() )
setScrollWidth (getClientWidth());
}
//----------------------------------------------------------------------
void FScrollView::setHeight (int h, bool adjust)
{
FWidget::setHeight (h, adjust);
calculateScrollbarPos();
if ( scroll_size.getHeight() < getClientHeight() )
setScrollHeight (getClientHeight());
}
//----------------------------------------------------------------------
void FScrollView::setSize (int w, int h, bool adjust)
{
FWidget::setSize (w, h, adjust);
calculateScrollbarPos();
if ( scroll_size.getWidth() < getClientWidth()
|| scroll_size.getHeight() < getClientHeight() )
setScrollSize (getClientWidth(), getClientHeight());
}
//----------------------------------------------------------------------
void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget::setGeometry (x, y, w, h, adjust);
scroll_size.setPos (getTermX() - 1, getTermY() - 1);
calculateScrollbarPos();
if ( scroll_size.getWidth() < getClientWidth()
|| scroll_size.getHeight() < getClientHeight() )
setScrollSize (getClientWidth(), getClientHeight());
}
//----------------------------------------------------------------------
void FScrollView::clearArea (int fillchar)
{
if ( viewport )
clearArea (viewport, fillchar);
}
//----------------------------------------------------------------------
void FScrollView::draw()
{
own_print_area = true;
if ( FWidget* p = getParentWidget() )
setColor (p->getForegroundColor(), p->getBackgroundColor());
else
setColor (wc.dialog_fg, wc.dialog_bg);
if ( isNewFont() )
drawBorder (1, 1, getWidth() - 1, getHeight());
else
drawBorder();
own_print_area = false;
copy2area();
if ( vbar->isVisible() )
vbar->redraw();
if ( hbar->isVisible() )
hbar->redraw();
}
//----------------------------------------------------------------------
void FScrollView::onWheel (FWheelEvent* ev)
{
int yoffset = scroll_offset.getY();
int yoffset_before = yoffset;
int wheel = ev->getWheel();
switch ( wheel )
{
case fc::WheelUp:
if ( yoffset == 0 )
break;
yoffset -= 4;
if ( yoffset < 0 )
yoffset=0;
break;
case fc::WheelDown:
{
int yoffset_end = scroll_size.getHeight() - getClientHeight();
if ( yoffset_end < 0 )
yoffset_end = 0;
if ( yoffset == yoffset_end )
break;
yoffset += 4;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
}
break;
default:
break;
}
scroll_offset.setY (yoffset);
if ( isVisible() )
{
if ( viewport && yoffset_before != yoffset )
viewport->has_changes = true;
copy2area();
}
vbar->setValue (yoffset);
if ( vbar->isVisible() && yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
}
// protected methods of FScrollView
//----------------------------------------------------------------------
FVTerm::term_area* FScrollView::getPrintArea()
{
// returns the viewport print area
if ( viewport && ! own_print_area )
return viewport;
else
return FVTerm::getPrintArea();
}
//----------------------------------------------------------------------
void FScrollView::adjustSize()
{
FWidget::adjustSize();
int width = getWidth();
int height = getHeight();
int xoffset = scroll_offset.getX();
int yoffset = scroll_offset.getY();
hbar->setMaximum (scroll_size.getWidth() - getClientWidth());
hbar->setPageSize (scroll_size.getWidth(), getClientWidth());
hbar->setY (height);
hbar->setWidth (width - 2, false);
hbar->setValue (xoffset);
hbar->resize();
vbar->setMaximum (scroll_size.getHeight() - getClientHeight());
vbar->setPageSize (scroll_size.getHeight(), getClientHeight());
vbar->setX (width);
vbar->setHeight (height - 2, false);
vbar->setValue (yoffset);
vbar->resize();
}
//----------------------------------------------------------------------
void FScrollView::copy2area()
{
// copy viewport to area
int ax, ay, dx, dy, y_end, x_end;
char_data* vc; // viewport character
char_data* ac; // area character
if ( ! print_area )
FVTerm::getPrintArea();
if ( ! (print_area && viewport) )
return;
if ( ! viewport->has_changes )
return;
ax = getTermX() - print_area->x_offset;
ay = getTermY() - print_area->y_offset;
dx = scroll_offset.getX();
dy = scroll_offset.getY();
y_end = getClientHeight();
x_end = getClientWidth();
for (int y=0; y < y_end; y++) // line loop
{
int v_line_len = viewport->width;
int a_line_len = print_area->width + print_area->right_shadow;
vc = &viewport->text[(dy+y) * v_line_len + dx];
ac = &print_area->text[(ay+y) * a_line_len + ax];
std::memcpy (ac, vc, sizeof(char_data) * unsigned(x_end));
if ( short(print_area->changes[ay+y].xmin) > ax )
print_area->changes[ay+y].xmin = uInt(ax);
if ( short(print_area->changes[ay+y].xmax) < ax+x_end-1 )
print_area->changes[ay+y].xmax = uInt(ax+x_end-1);
}
viewport->has_changes = false;
print_area->has_changes = true;
}
// private methods of FScrollView
//----------------------------------------------------------------------
void FScrollView::init()
{
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
vbar->addCallback
(
"change-value",
_METHOD_CALLBACK (this, &FScrollView::cb_VBarChange)
);
hbar->addCallback
(
"change-value",
_METHOD_CALLBACK (this, &FScrollView::cb_HBarChange)
);
nf_offset = isNewFont() ? 1 : 0;
setTopPadding(1);
setLeftPadding(1);
setBottomPadding(1);
setRightPadding(1 + nf_offset);
FPoint no_shadow(0,0);
scroll_size.setRect (0, 0, getClientWidth(), getClientHeight());
createArea (scroll_size, no_shadow, viewport);
}
//----------------------------------------------------------------------
void FScrollView::calculateScrollbarPos()
{
int width = getWidth();
int height = getHeight();
if ( isNewFont() )
{
vbar->setGeometry (width, 2, 2, height-2);
hbar->setGeometry (1, height, width-2, 1);
}
else
{
vbar->setGeometry (width, 2, 1, height-2);
hbar->setGeometry (2, height, width-2, 1);
}
setRightPadding (1 + nf_offset);
vbar->resize();
hbar->resize();
}
//----------------------------------------------------------------------
void FScrollView::cb_VBarChange (FWidget*, void*)
{
FScrollbar::sType scrollType;
bool hasChanges = false;
int distance = 1;
int yoffset = scroll_offset.getY();
int yoffset_before = yoffset;
int yoffset_end = scroll_size.getHeight() - getClientHeight();
scrollType = vbar->getScrollType();
switch ( scrollType )
{
case FScrollbar::noScroll:
break;
case FScrollbar::scrollPageBackward:
distance = getClientHeight();
// fall through
case FScrollbar::scrollStepBackward:
yoffset -= distance;
if ( yoffset < 0 )
yoffset = 0;
break;
case FScrollbar::scrollPageForward:
distance = getClientHeight();
// fall through
case FScrollbar::scrollStepForward:
yoffset += distance;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
break;
case FScrollbar::scrollJump:
{
int val = vbar->getValue();
if ( yoffset == val )
break;
yoffset = val;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
if ( yoffset < 0 )
yoffset = 0;
break;
}
case FScrollbar::scrollWheelUp:
if ( yoffset == 0 )
break;
yoffset -= 4;
if ( yoffset < 0 )
yoffset=0;
break;
case FScrollbar::scrollWheelDown:
if ( yoffset_end < 0 )
yoffset_end = 0;
if ( yoffset == yoffset_end )
break;
yoffset += 4;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
break;
}
scroll_offset.setY (yoffset);
if ( isVisible() )
{
if ( viewport && yoffset_before != yoffset )
viewport->has_changes = true;
copy2area();
hasChanges = true;
}
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
vbar->setValue (yoffset);
hasChanges = true;
if ( vbar->isVisible() && yoffset_before != yoffset )
vbar->drawBar();
}
if ( hasChanges )
updateTerminal();
}
//----------------------------------------------------------------------
void FScrollView::cb_HBarChange (FWidget*, void*)
{
FScrollbar::sType scrollType;
bool hasChanges = false;
int distance = 1;
int xoffset = scroll_offset.getX();
int xoffset_before = xoffset;
int xoffset_end = scroll_size.getWidth() - getClientWidth();
scrollType = hbar->getScrollType();
switch ( scrollType )
{
case FScrollbar::noScroll:
break;
case FScrollbar::scrollPageBackward:
distance = getClientWidth();
// fall through
case FScrollbar::scrollStepBackward:
xoffset -= distance;
if ( xoffset < 0 )
xoffset = 0;
break;
case FScrollbar::scrollPageForward:
distance = getClientWidth();
// fall through
case FScrollbar::scrollStepForward:
xoffset += distance;
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
if ( xoffset < 0 )
xoffset = 0;
break;
case FScrollbar::scrollJump:
{
int val = hbar->getValue();
if ( xoffset == val )
break;
xoffset = val;
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
if ( xoffset < 0 )
xoffset = 0;
break;
}
case FScrollbar::scrollWheelUp:
if ( xoffset == 0 )
break;
xoffset -= 4;
if ( xoffset < 0 )
xoffset=0;
break;
case FScrollbar::scrollWheelDown:
if ( xoffset == xoffset_end )
break;
xoffset += 4;
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
break;
}
scroll_offset.setX (xoffset);
if ( isVisible() )
{
if ( viewport && xoffset_before != xoffset )
viewport->has_changes = true;
copy2area();
hasChanges = true;
}
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
hbar->setValue (xoffset);
hasChanges = true;
if ( hbar->isVisible() && xoffset_before != xoffset )
hbar->drawBar();
}
if ( hasChanges )
updateTerminal();
}

141
src/fscrollview.h Normal file
View File

@ -0,0 +1,141 @@
// File: fscrollview.h
// Provides: class FScrollView
//
// Inheritance diagram
// ═══════════════════
//
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
// ▕ FObject ▏ ▕ FTerm ▏
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
// ▲ ▲
// │ │
// └─────┬─────┘
// │
// ▕▔▔▔▔▔▔▔▔▏
// ▕ FVTerm ▏
// ▕▁▁▁▁▁▁▁▁▏
// ▲
// │
// ▕▔▔▔▔▔▔▔▔▔▏
// ▕ FWidget ▏
// ▕▁▁▁▁▁▁▁▁▁▏
// ▲
// │
// ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
// ▕ FScrollView ▏
// ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
#ifndef _FSCROLLVIEW_H
#define _FSCROLLVIEW_H
#include "fscrollbar.h"
#include "fwidget.h"
//----------------------------------------------------------------------
// class FScrollView
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FScrollView : public FWidget
{
public:
// Using-declaration
using FWidget::setGeometry;
using FWidget::setPos;
// Constructor
explicit FScrollView (FWidget* = 0);
// Destructor
virtual ~FScrollView();
// Accessors
const char* getClassName() const;
int getScrollWidth();
int getScrollHeight();
// Mutator
void setScrollWidth (int);
void setScrollHeight (int);
void setScrollSize (int, int);
void setScrollOffset (FPoint);
void setScrollOffset (int, int);
virtual void setX (int, bool = true);
virtual void setY (int, bool = true);
virtual void setPos (int, int, bool = true);
virtual void setWidth (int, bool = true);
virtual void setHeight (int, bool = true);
virtual void setSize (int, int, bool = true);
void setGeometry (int, int, int, int, bool = true);
// Method
virtual void clearArea (int = ' ');
virtual void draw();
// Event handlers
void onWheel (FWheelEvent*);
protected:
// Using-declaration
using FVTerm::clearArea;
// Accessor
term_area* getPrintArea();
// Method
void adjustSize();
void copy2area();
private:
// Disable copy constructor
FScrollView (const FScrollView&);
// Disable assignment operator (=)
FScrollView& operator = (const FScrollView&);
// Methods
void init();
void calculateScrollbarPos();
// Callback methods
void cb_VBarChange (FWidget*, void*);
void cb_HBarChange (FWidget*, void*);
// Data Members
FRect scroll_size;
FPoint scroll_offset;
term_area* viewport; // virtual scroll content
FScrollbar* vbar;
FScrollbar* hbar;
int nf_offset;
bool own_print_area;
};
#pragma pack(pop)
// FScrollView inline functions
//----------------------------------------------------------------------
inline const char* FScrollView::getClassName() const
{ return "FScrollView"; }
//----------------------------------------------------------------------
inline int FScrollView::getScrollWidth()
{ return scroll_size.getWidth(); }
//----------------------------------------------------------------------
inline int FScrollView::getScrollHeight()
{ return scroll_size.getHeight(); }
//----------------------------------------------------------------------
inline void FScrollView::setScrollOffset (FPoint pos)
{ scroll_offset = pos; }
//----------------------------------------------------------------------
inline void FScrollView::setScrollOffset (int x, int y)
{ scroll_offset.setPoint (x, y); }
#endif // _FSCROLLVIEW_H

View File

@ -494,7 +494,7 @@ void FTextView::onWheel (FWheelEvent* ev)
case fc::WheelDown: case fc::WheelDown:
{ {
int yoffset_end = last_line - getHeight() - nf_offset + 2; int yoffset_end = last_line - getClientHeight();
if ( yoffset_end < 0 ) if ( yoffset_end < 0 )
yoffset_end = 0; yoffset_end = 0;
@ -599,8 +599,6 @@ void FTextView::adjustSize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::init() void FTextView::init()
{ {
nf_offset = isNewFont() ? 1 : 0;
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
@ -624,6 +622,12 @@ void FTextView::init()
"change-value", "change-value",
_METHOD_CALLBACK (this, &FTextView::cb_HBarChange) _METHOD_CALLBACK (this, &FTextView::cb_HBarChange)
); );
nf_offset = isNewFont() ? 1 : 0;
setTopPadding(1);
setLeftPadding(1);
setBottomPadding(1);
setRightPadding(1 + nf_offset);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -747,12 +751,16 @@ void FTextView::cb_VBarChange (FWidget*, void*)
int distance = 1; int distance = 1;
int last_line = int(getRows()); int last_line = int(getRows());
int yoffset_before = yoffset; int yoffset_before = yoffset;
int yoffset_end = last_line - getClientHeight();
scrollType = vbar->getScrollType(); scrollType = vbar->getScrollType();
switch ( int(scrollType) ) switch ( int(scrollType) )
{ {
case FScrollbar::noScroll:
break;
case FScrollbar::scrollPageBackward: case FScrollbar::scrollPageBackward:
distance = getHeight() + nf_offset - 2; distance = getClientHeight();
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
yoffset -= distance; yoffset -= distance;
@ -763,13 +771,16 @@ void FTextView::cb_VBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = getHeight() + nf_offset - 2; distance = getClientHeight();
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
yoffset += distance; yoffset += distance;
if ( yoffset > last_line - getHeight() - nf_offset + 2 ) if ( yoffset > yoffset_end )
yoffset = last_line - getHeight() - nf_offset + 2; yoffset = yoffset_end;
if ( yoffset < 0 )
yoffset = 0;
break; break;
@ -782,8 +793,8 @@ void FTextView::cb_VBarChange (FWidget*, void*)
yoffset = val; yoffset = val;
if ( yoffset > last_line - getHeight() - nf_offset + 2 ) if ( yoffset > yoffset_end )
yoffset = last_line - getHeight() - nf_offset + 2; yoffset = yoffset_end;
if ( yoffset < 0 ) if ( yoffset < 0 )
yoffset = 0; yoffset = 0;
@ -804,9 +815,6 @@ void FTextView::cb_VBarChange (FWidget*, void*)
onWheel(&wheel_ev); onWheel(&wheel_ev);
break; break;
} }
default:
break;
} }
if ( isVisible() ) if ( isVisible() )
@ -830,15 +838,19 @@ void FTextView::cb_VBarChange (FWidget*, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::cb_HBarChange (FWidget*, void*) void FTextView::cb_HBarChange (FWidget*, void*)
{ {
FScrollbar::sType scrollType;
int distance = 1; int distance = 1;
int xoffset_before = xoffset; int xoffset_before = xoffset;
int xoffset_end = int(maxLineWidth) - getWidth() + nf_offset + 4; int xoffset_end = int(maxLineWidth) - getClientWidth();
int scrollType = hbar->getScrollType(); scrollType = hbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
{ {
case FScrollbar::noScroll:
break;
case FScrollbar::scrollPageBackward: case FScrollbar::scrollPageBackward:
distance = getWidth() - nf_offset - 4; distance = getClientWidth();
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
xoffset -= distance; xoffset -= distance;
@ -849,13 +861,13 @@ void FTextView::cb_HBarChange (FWidget*, void*)
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = getWidth() - nf_offset - 4; distance = getClientWidth();
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
xoffset += distance; xoffset += distance;
if ( xoffset > int(maxLineWidth) - getWidth() + nf_offset + 4 ) if ( xoffset > int(maxLineWidth) - getClientWidth() )
xoffset = int(maxLineWidth) - getWidth() + nf_offset + 4; xoffset = int(maxLineWidth) - getClientWidth();
if ( xoffset < 0 ) if ( xoffset < 0 )
xoffset = 0; xoffset = 0;
@ -871,8 +883,8 @@ void FTextView::cb_HBarChange (FWidget*, void*)
xoffset = val; xoffset = val;
if ( xoffset > int(maxLineWidth) - getWidth() + nf_offset + 4 ) if ( xoffset > int(maxLineWidth) - getClientWidth() )
xoffset = int(maxLineWidth) - getWidth() + nf_offset + 4; xoffset = int(maxLineWidth) - getClientWidth();
if ( xoffset < 0 ) if ( xoffset < 0 )
xoffset = 0; xoffset = 0;
@ -901,9 +913,6 @@ void FTextView::cb_HBarChange (FWidget*, void*)
xoffset = xoffset_end; xoffset = xoffset_end;
break; break;
default:
break;
} }
if ( isVisible() ) if ( isVisible() )

View File

@ -387,10 +387,10 @@ int FVTerm::print (term_area* area, FString& s)
while ( *p ) while ( *p )
{ {
int width, height, rsh, bsh; int width, height, rsh, bsh;
width = area->width; width = area->width;
height = area->height; height = area->height;
rsh = area->right_shadow; rsh = area->right_shadow;
bsh = area->bottom_shadow; bsh = area->bottom_shadow;
switch ( *p ) switch ( *p )
{ {
@ -532,12 +532,12 @@ int FVTerm::print (term_area* area, register int c)
if ( ! area ) if ( ! area )
return -1; return -1;
width = area->width; width = area->width;
height = area->height; height = area->height;
rsh = area->right_shadow; rsh = area->right_shadow;
bsh = area->bottom_shadow; bsh = area->bottom_shadow;
ax = area->cursor_x - 1; ax = area->cursor_x - 1;
ay = area->cursor_y - 1; ay = area->cursor_y - 1;
nc.code = c; nc.code = c;
nc.fg_color = next_attribute.fg_color; nc.fg_color = next_attribute.fg_color;
@ -619,6 +619,34 @@ int FVTerm::print (term_area* area, register int c)
// protected methods of FVTerm // protected methods of FVTerm
//----------------------------------------------------------------------
FVTerm::term_area* FVTerm::getPrintArea()
{
// returns the print area of this object
if ( print_area )
return print_area;
else
{
FVTerm* obj = static_cast<FVTerm*>(this);
FVTerm* p_obj = static_cast<FVTerm*>(obj->getParent());
while ( ! obj->vwin && p_obj )
{
obj = p_obj;
p_obj = static_cast<FVTerm*>(p_obj->getParent());
}
if ( obj->vwin )
{
print_area = obj->vwin;
return print_area;
}
}
return vdesktop;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FVTerm::createArea ( const FRect& r void FVTerm::createArea ( const FRect& r
, const FPoint& p , const FPoint& p
@ -640,6 +668,7 @@ void FVTerm::createArea ( int x_offset, int y_offset
, term_area*& area ) , term_area*& area )
{ {
// initialize virtual window // initialize virtual window
area = new term_area; area = new term_area;
area->x_offset = 0; area->x_offset = 0;
@ -1911,33 +1940,6 @@ void FVTerm::flush_out()
// private methods of FVTerm // private methods of FVTerm
//----------------------------------------------------------------------
FVTerm::term_area* FVTerm::getPrintArea()
{
// returns the print area of this object
if ( print_area )
return print_area;
else
{
FVTerm* obj = static_cast<FVTerm*>(this);
FVTerm* p_obj = static_cast<FVTerm*>(obj->getParent());
while ( ! obj->vwin && p_obj )
{
obj = p_obj;
p_obj = static_cast<FVTerm*>(p_obj->getParent());
}
if ( obj->vwin )
{
print_area = obj->vwin;
return print_area;
}
}
return vdesktop;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FVTerm::init() void FVTerm::init()
{ {

View File

@ -190,7 +190,7 @@ class FVTerm : public FObject, public FTerm
static bool isInheritBackground(); static bool isInheritBackground();
// Methods // Methods
void clearArea (int = ' '); virtual void clearArea (int = ' ');
void createVTerm (const FRect&); void createVTerm (const FRect&);
void createVTerm (int, int); void createVTerm (int, int);
static void resizeVTerm (const FRect&); static void resizeVTerm (const FRect&);
@ -229,6 +229,9 @@ class FVTerm : public FObject, public FTerm
covered_character covered_character
}; };
// Accessor
virtual term_area* getPrintArea();
// Methods // Methods
void createArea ( const FRect& void createArea ( const FRect&
, const FPoint& , const FPoint&
@ -315,9 +318,6 @@ class FVTerm : public FObject, public FTerm
// Disable assignment operator (=) // Disable assignment operator (=)
FVTerm& operator = (const FVTerm&); FVTerm& operator = (const FVTerm&);
// Accessor
term_area* getPrintArea();
// Mutators // Mutators
void setPrintArea (term_area*); void setPrintArea (term_area*);

View File

@ -18,6 +18,7 @@ noinst_PROGRAMS = \
transparent \ transparent \
keyboard \ keyboard \
timer \ timer \
scrollview \
windows \ windows \
menu \ menu \
ui ui
@ -34,6 +35,7 @@ term_attributes_SOURCES = term-attributes.cpp
transparent_SOURCES = transparent.cpp transparent_SOURCES = transparent.cpp
keyboard_SOURCES = keyboard.cpp keyboard_SOURCES = keyboard.cpp
timer_SOURCES = timer.cpp timer_SOURCES = timer.cpp
scrollview_SOURCES = scrollview.cpp
windows_SOURCES = windows.cpp windows_SOURCES = windows.cpp
menu_SOURCES = menu.cpp menu_SOURCES = menu.cpp
ui_SOURCES = ui.cpp ui_SOURCES = ui.cpp

View File

@ -86,8 +86,8 @@ noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \
opti-move$(EXEEXT) string-operations$(EXEEXT) \ opti-move$(EXEEXT) string-operations$(EXEEXT) \
mandelbrot$(EXEEXT) calculator$(EXEEXT) watch$(EXEEXT) \ mandelbrot$(EXEEXT) calculator$(EXEEXT) watch$(EXEEXT) \
term-attributes$(EXEEXT) transparent$(EXEEXT) \ term-attributes$(EXEEXT) transparent$(EXEEXT) \
keyboard$(EXEEXT) timer$(EXEEXT) windows$(EXEEXT) \ keyboard$(EXEEXT) timer$(EXEEXT) scrollview$(EXEEXT) \
menu$(EXEEXT) ui$(EXEEXT) windows$(EXEEXT) menu$(EXEEXT) ui$(EXEEXT)
subdir = test subdir = test
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/depcomp $(top_srcdir)/depcomp
@ -131,6 +131,9 @@ menu_LDADD = $(LDADD)
am_opti_move_OBJECTS = opti-move.$(OBJEXT) am_opti_move_OBJECTS = opti-move.$(OBJEXT)
opti_move_OBJECTS = $(am_opti_move_OBJECTS) opti_move_OBJECTS = $(am_opti_move_OBJECTS)
opti_move_LDADD = $(LDADD) opti_move_LDADD = $(LDADD)
am_scrollview_OBJECTS = scrollview.$(OBJEXT)
scrollview_OBJECTS = $(am_scrollview_OBJECTS)
scrollview_LDADD = $(LDADD)
am_string_operations_OBJECTS = string-operations.$(OBJEXT) am_string_operations_OBJECTS = string-operations.$(OBJEXT)
string_operations_OBJECTS = $(am_string_operations_OBJECTS) string_operations_OBJECTS = $(am_string_operations_OBJECTS)
string_operations_LDADD = $(LDADD) string_operations_LDADD = $(LDADD)
@ -189,15 +192,17 @@ am__v_CXXLD_1 =
SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) $(hello_SOURCES) \ SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) $(hello_SOURCES) \
$(input_dialog_SOURCES) $(keyboard_SOURCES) \ $(input_dialog_SOURCES) $(keyboard_SOURCES) \
$(mandelbrot_SOURCES) $(menu_SOURCES) $(opti_move_SOURCES) \ $(mandelbrot_SOURCES) $(menu_SOURCES) $(opti_move_SOURCES) \
$(string_operations_SOURCES) $(term_attributes_SOURCES) \ $(scrollview_SOURCES) $(string_operations_SOURCES) \
$(timer_SOURCES) $(transparent_SOURCES) $(ui_SOURCES) \ $(term_attributes_SOURCES) $(timer_SOURCES) \
$(watch_SOURCES) $(windows_SOURCES) $(transparent_SOURCES) $(ui_SOURCES) $(watch_SOURCES) \
$(windows_SOURCES)
DIST_SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) \ DIST_SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) \
$(hello_SOURCES) $(input_dialog_SOURCES) $(keyboard_SOURCES) \ $(hello_SOURCES) $(input_dialog_SOURCES) $(keyboard_SOURCES) \
$(mandelbrot_SOURCES) $(menu_SOURCES) $(opti_move_SOURCES) \ $(mandelbrot_SOURCES) $(menu_SOURCES) $(opti_move_SOURCES) \
$(string_operations_SOURCES) $(term_attributes_SOURCES) \ $(scrollview_SOURCES) $(string_operations_SOURCES) \
$(timer_SOURCES) $(transparent_SOURCES) $(ui_SOURCES) \ $(term_attributes_SOURCES) $(timer_SOURCES) \
$(watch_SOURCES) $(windows_SOURCES) $(transparent_SOURCES) $(ui_SOURCES) $(watch_SOURCES) \
$(windows_SOURCES)
am__can_run_installinfo = \ am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \ case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \ n|no|NO) false;; \
@ -358,6 +363,7 @@ term_attributes_SOURCES = term-attributes.cpp
transparent_SOURCES = transparent.cpp transparent_SOURCES = transparent.cpp
keyboard_SOURCES = keyboard.cpp keyboard_SOURCES = keyboard.cpp
timer_SOURCES = timer.cpp timer_SOURCES = timer.cpp
scrollview_SOURCES = scrollview.cpp
windows_SOURCES = windows.cpp windows_SOURCES = windows.cpp
menu_SOURCES = menu.cpp menu_SOURCES = menu.cpp
ui_SOURCES = ui.cpp ui_SOURCES = ui.cpp
@ -437,6 +443,10 @@ opti-move$(EXEEXT): $(opti_move_OBJECTS) $(opti_move_DEPENDENCIES) $(EXTRA_opti_
@rm -f opti-move$(EXEEXT) @rm -f opti-move$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(opti_move_OBJECTS) $(opti_move_LDADD) $(LIBS) $(AM_V_CXXLD)$(CXXLINK) $(opti_move_OBJECTS) $(opti_move_LDADD) $(LIBS)
scrollview$(EXEEXT): $(scrollview_OBJECTS) $(scrollview_DEPENDENCIES) $(EXTRA_scrollview_DEPENDENCIES)
@rm -f scrollview$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(scrollview_OBJECTS) $(scrollview_LDADD) $(LIBS)
string-operations$(EXEEXT): $(string_operations_OBJECTS) $(string_operations_DEPENDENCIES) $(EXTRA_string_operations_DEPENDENCIES) string-operations$(EXEEXT): $(string_operations_OBJECTS) $(string_operations_DEPENDENCIES) $(EXTRA_string_operations_DEPENDENCIES)
@rm -f string-operations$(EXEEXT) @rm -f string-operations$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(string_operations_OBJECTS) $(string_operations_LDADD) $(LIBS) $(AM_V_CXXLD)$(CXXLINK) $(string_operations_OBJECTS) $(string_operations_LDADD) $(LIBS)
@ -479,6 +489,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mandelbrot.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mandelbrot.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/menu.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/menu.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opti-move.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opti-move.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrollview.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string-operations.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string-operations.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/term-attributes.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/term-attributes.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@

View File

@ -20,7 +20,7 @@ class Mandelbrot : public FDialog
// Destructor // Destructor
~Mandelbrot(); ~Mandelbrot();
// Callback methods // Event handlers
void onAccel (FAccelEvent*); void onAccel (FAccelEvent*);
void onClose (FCloseEvent*); void onClose (FCloseEvent*);

154
test/scrollview.cpp Normal file
View File

@ -0,0 +1,154 @@
// File: scrollview.cpp
#include "fapp.h"
#include "fbutton.h"
#include "fdialog.h"
#include "flabel.h"
#include "fmessagebox.h"
#include "fscrollview.h"
//----------------------------------------------------------------------
// class scrollview
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class scrollview : public FScrollView
{
public:
// Constructor
explicit scrollview (FWidget* = 0);
// Destructor
~scrollview ();
private:
// Methods
void draw();
};
#pragma pack(pop)
//----------------------------------------------------------------------
scrollview::scrollview (FWidget* parent)
: FScrollView(parent)
{ }
//----------------------------------------------------------------------
scrollview::~scrollview()
{ }
//----------------------------------------------------------------------
void scrollview::draw()
{
setColor (wc.dialog_fg, wc.dialog_bg);
clearArea();
for (int y=0; y < getScrollHeight(); y++)
{
setPrintPos (1, 1 + y);
for (int x=0; x < getScrollWidth(); x++)
print (32 + ((x + y) % 0x5f));
}
FScrollView::draw();
}
//----------------------------------------------------------------------
// class scrollviewdemo
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class scrollviewdemo : public FDialog
{
public:
// Constructor
explicit scrollviewdemo (FWidget* = 0);
// Destructor
~scrollviewdemo ();
// Event handler
void onClose (FCloseEvent*);
// Callback method
void cb_quit (FWidget* = 0, void* = 0);
};
#pragma pack(pop)
//----------------------------------------------------------------------
scrollviewdemo::scrollviewdemo (FWidget* parent)
: FDialog(parent)
{
setGeometry (16, 3, 50, 19);
setText ("Scrolling viewport example");
// The scrolling viewport widget
scrollview* sview = new scrollview (this);
sview->setGeometry(3, 2, 44, 12);
sview->setScrollSize(88, 24);
// Quit button
FButton* button = new FButton("&Quit", this);
button->setGeometry(37, 15, 10, 1);
// Add function callback
button->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &scrollviewdemo::cb_quit)
);
// Text label
FLabel* label = new FLabel (this);
label->setGeometry(2, 1, 46, 1);
label->setText (L"Use scrollbars to change the viewport position");
label->setEmphasis();
}
//----------------------------------------------------------------------
scrollviewdemo::~scrollviewdemo()
{ }
//----------------------------------------------------------------------
void scrollviewdemo::cb_quit (FWidget*, void*)
{
close();
}
//----------------------------------------------------------------------
void scrollviewdemo::onClose (FCloseEvent* ev)
{
int ret = FMessageBox::info ( this, "Quit"
, "Do you really want\n"
"to quit the program ?"
, FMessageBox::Yes
, FMessageBox::No );
if ( ret == FMessageBox::Yes )
ev->accept();
else
ev->ignore();
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
// Create the application object
FApplication app(argc, argv);
// Create a simple dialog box
scrollviewdemo svdemo(&app);
app.setMainWidget(&svdemo);
svdemo.show();
return app.exec();
}

View File

@ -648,7 +648,7 @@ void MyDialog::cb_about (FWidget*, void*)
FMessageBox info ( "About" FMessageBox info ( "About"
, line + L" The Final Cut " + line + "\n\n" , line + L" The Final Cut " + line + "\n\n"
L"Version " + libver + "\n\n" L"Version " + libver + "\n\n"
L"(c) 2016 by Markus Gans" L"(c) 2017 by Markus Gans"
, FMessageBox::Ok, 0, 0, this ); , FMessageBox::Ok, 0, 0, this );
info.setCenterText(); info.setCenterText();
info.show(); info.show();
@ -893,7 +893,7 @@ void MyDialog::adjustSize()
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
FString ver = F_VERSION; // library version FString ver = F_VERSION; // library version
FString title = "The FINAL CUT " + ver + " (C) 2016 by Markus Gans"; FString title = "The FINAL CUT " + ver + " (C) 2017 by Markus Gans";
if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0
|| std::strcmp(argv[1], "-h") == 0 ) ) || std::strcmp(argv[1], "-h") == 0 ) )