diff --git a/.gitignore b/.gitignore index b2b0eaae..65add45b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ test/opti-move test/hello test/watch test/menu +test/scrollview test/windows test/term-attributes test/transparent diff --git a/ChangeLog b/ChangeLog index b89f18a4..8d9d2d9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-01-02 Markus Gans + * 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 * Reduce public methods in FVTerm diff --git a/finalcut.spec b/finalcut.spec index 712cae15..25419f9f 100644 --- a/finalcut.spec +++ b/finalcut.spec @@ -1,7 +1,7 @@ # # spec file for package finalcut # -# Copyright (c) 2016 by Markus Gans +# Copyright (c) 2017 by Markus Gans # Name: finalcut diff --git a/src/Makefile.am b/src/Makefile.am index a8170249..c06f61e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,7 @@ libfinal_la_SOURCES = \ fcheckmenuitem.cpp \ fmenulist.cpp \ fdialog.cpp \ + fscrollview.cpp \ fwindow.cpp \ fmessagebox.cpp \ ftooltip.cpp \ @@ -84,6 +85,7 @@ finalcutinclude_HEADERS = \ fradiobutton.h \ frect.h \ fscrollbar.h \ + fscrollview.h \ fstatusbar.h \ fstring.h \ ftcap_map.h \ diff --git a/src/Makefile.clang b/src/Makefile.clang index ddb359e0..133202ee 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -35,6 +35,7 @@ INCLUDE_HEADERS = \ fradiobutton.h \ frect.h \ fscrollbar.h \ + fscrollview.h \ fstatusbar.h \ fstring.h \ fterm.h \ @@ -77,6 +78,7 @@ OBJS = \ fcheckmenuitem.o \ fmenulist.o \ fdialog.o \ + fscrollview.o \ fwindow.o \ fmessagebox.o \ ftooltip.o \ diff --git a/src/Makefile.gcc b/src/Makefile.gcc index b908ca09..aed9ec36 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -35,6 +35,7 @@ INCLUDE_HEADERS = \ fradiobutton.h \ frect.h \ fscrollbar.h \ + fscrollview.h \ fstatusbar.h \ fstring.h \ fterm.h \ @@ -77,6 +78,7 @@ OBJS = \ fcheckmenuitem.o \ fmenulist.o \ fdialog.o \ + fscrollview.o \ fwindow.o \ fmessagebox.o \ ftooltip.o \ diff --git a/src/Makefile.in b/src/Makefile.in index 89bf7ed8..fcce5d12 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -133,10 +133,10 @@ am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \ ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \ flabel.lo flistbox.lo fmenu.lo fdialoglistmenu.lo fmenubar.lo \ fmenuitem.lo fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo \ - fdialog.lo fwindow.lo fmessagebox.lo ftooltip.lo \ - ffiledialog.lo ftextview.lo fstatusbar.lo fterm.lo fvterm.lo \ - fevent.lo foptiattr.lo foptimove.lo fapp.lo fwidget.lo \ - fobject.lo + fdialog.lo fscrollview.lo fwindow.lo fmessagebox.lo \ + ftooltip.lo ffiledialog.lo ftextview.lo fstatusbar.lo fterm.lo \ + fvterm.lo fevent.lo foptiattr.lo foptimove.lo fapp.lo \ + fwidget.lo fobject.lo libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -396,6 +396,7 @@ libfinal_la_SOURCES = \ fcheckmenuitem.cpp \ fmenulist.cpp \ fdialog.cpp \ + fscrollview.cpp \ fwindow.cpp \ fmessagebox.cpp \ ftooltip.cpp \ @@ -447,6 +448,7 @@ finalcutinclude_HEADERS = \ fradiobutton.h \ frect.h \ fscrollbar.h \ + fscrollview.h \ fstatusbar.h \ fstring.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)/frect.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)/fstring.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fswitch.Plo@am__quote@ diff --git a/src/flistbox.cpp b/src/flistbox.cpp index faa4c091..d733abaf 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -386,9 +386,12 @@ void FListBox::clear() void FListBox::onKeyPress (FKeyEvent* ev) { int element_count = int(getCount()); + int padding_space = 2; // 1 leading space + 1 tailing space int current_before = current; int xoffset_before = xoffset; + int xoffset_end = max_line_width - getClientWidth() + padding_space; int yoffset_before = yoffset; + int yoffset_end = element_count - getClientHeight(); int key = ev->key(); switch ( key ) @@ -419,7 +422,7 @@ void FListBox::onKeyPress (FKeyEvent* ev) if ( current > element_count ) current = element_count; - if ( current - yoffset >= getHeight() - 1 ) + if ( current - yoffset > getClientHeight() ) yoffset++; inc_search.clear(); @@ -439,8 +442,8 @@ void FListBox::onKeyPress (FKeyEvent* ev) case fc::Fkey_right: xoffset++; - if ( xoffset > max_line_width - getWidth() + nf_offset + 4 ) - xoffset = max_line_width - getWidth() + nf_offset + 4; + if ( xoffset > xoffset_end ) + xoffset = xoffset_end; if ( xoffset < 0 ) xoffset = 0; @@ -450,14 +453,14 @@ void FListBox::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_ppage: - current -= getHeight()-3; + current -= getClientHeight() - 1; if ( current < 1 ) current=1; if ( current <= yoffset ) { - yoffset -= getHeight()-3; + yoffset -= getClientHeight() - 1; if ( yoffset < 0 ) yoffset=0; @@ -468,17 +471,17 @@ void FListBox::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_npage: - current += getHeight()-3; + current += getClientHeight() - 1; if ( 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 ) - yoffset = element_count - getHeight() + 2; + if ( yoffset > yoffset_end ) + yoffset = yoffset_end; } inc_search.clear(); @@ -495,8 +498,8 @@ void FListBox::onKeyPress (FKeyEvent* ev) case fc::Fkey_end: current = element_count; - if ( current >= getHeight() - 1 ) - yoffset = element_count - getHeight() + 2; + if ( current > getClientHeight() ) + yoffset = yoffset_end; inc_search.clear(); ev->accept(); @@ -859,7 +862,7 @@ void FListBox::onMouseMove (FMouseEvent* ev) { // drag up if ( drag_scroll != FListBox::noScroll - && scroll_distance < getHeight()-2 ) + && scroll_distance < getClientHeight() ) scroll_distance++; if ( ! scroll_timer && current > 1 ) @@ -883,7 +886,7 @@ void FListBox::onMouseMove (FMouseEvent* ev) { // drag down if ( drag_scroll != FListBox::noScroll - && scroll_distance < getHeight()-2 ) + && scroll_distance < getClientHeight() ) scroll_distance++; if ( ! scroll_timer && current < int(getCount()) ) @@ -940,6 +943,7 @@ void FListBox::onTimer (FTimerEvent*) int element_count = int(getCount()); int current_before = current; int yoffset_before = yoffset; + int yoffset_end = element_count - getClientHeight(); switch ( int(drag_scroll) ) { @@ -979,11 +983,11 @@ void FListBox::onTimer (FTimerEvent*) if ( current > element_count ) current = element_count; - if ( current - yoffset >= getHeight() - 1 ) + if ( current - yoffset > getClientHeight() ) yoffset += scroll_distance; - if ( yoffset > element_count - getHeight() + 2 ) - yoffset = element_count - getHeight() + 2; + if ( yoffset > yoffset_end ) + yoffset = yoffset_end; break; @@ -1047,7 +1051,7 @@ void FListBox::onWheel (FWheelEvent* ev) element_count = int(getCount()); current_before = current; yoffset_before = yoffset; - yoffset_end = element_count - getHeight() + 2; + yoffset_end = element_count - getClientHeight(); if ( yoffset_end < 0 ) yoffset_end = 0; @@ -1153,15 +1157,20 @@ void FListBox::onFocusOut (FFocusEvent*) //---------------------------------------------------------------------- void FListBox::cb_VBarChange (FWidget*, void*) { + FScrollbar::sType scrollType; int distance = 1; int element_count = int(getCount()); int yoffset_before = yoffset; - int scrollType = vbar->getScrollType(); + int yoffset_end = element_count - getClientHeight(); + scrollType = vbar->getScrollType(); switch ( scrollType ) { + case FScrollbar::noScroll: + break; + case FScrollbar::scrollPageBackward: - distance = getHeight()-2; + distance = getClientHeight(); // fall through case FScrollbar::scrollStepBackward: current -= distance; @@ -1178,7 +1187,7 @@ void FListBox::cb_VBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = getHeight()-2; + distance = getClientHeight(); // fall through case FScrollbar::scrollStepForward: current += distance; @@ -1186,11 +1195,11 @@ void FListBox::cb_VBarChange (FWidget*, void*) if ( current > element_count ) current = element_count; - if ( current - yoffset >= getHeight() - 1 ) + if ( current - yoffset > getClientHeight() ) yoffset += distance; - if ( yoffset > element_count - getHeight() + 2 ) - yoffset = element_count - getHeight() + 2; + if ( yoffset > yoffset_end ) + yoffset = yoffset_end; break; @@ -1204,8 +1213,8 @@ void FListBox::cb_VBarChange (FWidget*, void*) int c = current - yoffset; yoffset = val; - if ( yoffset > element_count - getHeight() + 2 ) - yoffset = element_count - getHeight() + 2; + if ( yoffset > yoffset_end ) + yoffset = yoffset_end; if ( yoffset < 0 ) yoffset = 0; @@ -1234,9 +1243,6 @@ void FListBox::cb_VBarChange (FWidget*, void*) onWheel(&wheel_ev); } break; - - default: - break; } if ( isVisible() ) @@ -1258,15 +1264,20 @@ void FListBox::cb_VBarChange (FWidget*, void*) //---------------------------------------------------------------------- void FListBox::cb_HBarChange (FWidget*, void*) { + FScrollbar::sType scrollType; int distance = 1; + int padding_space = 2; // 1 leading space + 1 tailing space int xoffset_before = xoffset; - int xoffset_end = max_line_width - getWidth() + nf_offset + 4; - int scrollType = hbar->getScrollType(); + int xoffset_end = max_line_width - getClientWidth() + padding_space; + scrollType = hbar->getScrollType(); switch ( scrollType ) { + case FScrollbar::noScroll: + break; + case FScrollbar::scrollPageBackward: - distance = getWidth() - nf_offset - 4; + distance = getClientWidth() - padding_space; // fall through case FScrollbar::scrollStepBackward: xoffset -= distance; @@ -1276,13 +1287,13 @@ void FListBox::cb_HBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = getWidth() - nf_offset - 4; + distance = getClientWidth() - padding_space; // fall through case FScrollbar::scrollStepForward: xoffset += distance; - if ( xoffset > max_line_width - getWidth() + nf_offset + 4 ) - xoffset = max_line_width - getWidth() + nf_offset + 4; + if ( xoffset > xoffset_end ) + xoffset = xoffset_end; if ( xoffset < 0 ) xoffset = 0; @@ -1298,8 +1309,8 @@ void FListBox::cb_HBarChange (FWidget*, void*) xoffset = val; - if ( xoffset > max_line_width - getWidth() + nf_offset + 4 ) - xoffset = max_line_width - getWidth() + nf_offset + 4; + if ( xoffset > xoffset_end ) + xoffset = xoffset_end; if ( xoffset < 0 ) xoffset = 0; @@ -1328,9 +1339,6 @@ void FListBox::cb_HBarChange (FWidget*, void*) xoffset = xoffset_end; break; - - default: - break; } if ( isVisible() ) @@ -1360,8 +1368,8 @@ void FListBox::adjustYOffset() { int element_count = int(getCount()); - if ( yoffset > element_count - getHeight() + 2 ) - yoffset = element_count - getHeight() + 2; + if ( yoffset > element_count - getClientHeight() ) + yoffset = element_count - getClientHeight(); if ( yoffset < 0 ) yoffset = 0; @@ -1369,36 +1377,36 @@ void FListBox::adjustYOffset() if ( current < yoffset ) current = yoffset; - if ( current >= yoffset + getHeight() - 1 ) - yoffset = current - getHeight() + 2; + if ( yoffset < current - getClientHeight() ) + yoffset = current - getClientHeight(); } //---------------------------------------------------------------------- void FListBox::adjustSize() { int element_count; - adjustYOffset(); FWidget::adjustSize(); + adjustYOffset(); element_count = int(getCount()); - vbar->setMaximum(element_count - getHeight() + 2); - vbar->setPageSize(element_count, getHeight() - 2); + vbar->setMaximum(element_count - getClientHeight()); + vbar->setPageSize(element_count, getClientHeight()); vbar->setX(getWidth()); - vbar->setHeight (getHeight()-2, false); + vbar->setHeight (getClientHeight(), false); vbar->resize(); - hbar->setMaximum(max_line_width - getWidth() + nf_offset + 4); - hbar->setPageSize(max_line_width, getWidth() - nf_offset - 4); + hbar->setMaximum(max_line_width - getClientWidth() + 2); + hbar->setPageSize(max_line_width, getClientWidth() - 2); hbar->setY(getHeight()); - hbar->setWidth (getWidth()-2, false); + hbar->setWidth (getClientWidth(), false); hbar->resize(); - if ( element_count < getHeight() - 1 ) + if ( element_count <= getClientHeight() ) vbar->hide(); else vbar->setVisible(); - if ( max_line_width < getWidth() - nf_offset - 3 ) + if ( max_line_width < getClientWidth() - 1 ) hbar->hide(); else hbar->setVisible(); @@ -1415,8 +1423,6 @@ void FListBox::init() if ( isEnabled() ) flags |= fc::active; - nf_offset = isNewFont() ? 1 : 0; - setForegroundColor (wc.dialog_fg); setBackgroundColor (wc.dialog_bg); @@ -1443,6 +1449,12 @@ void FListBox::init() "change-value", _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 setColor(wc.label_inactive_fg, wc.label_inactive_bg); - if ( length <= uInt(getWidth()-2) ) + if ( length <= uInt(getClientWidth()) ) print (txt); else { - print (text.left(uInt(getWidth()-4))); + print (text.left(uInt(getClientWidth()-2))); setColor (wc.label_ellipsis_fg, wc.label_bg); print(".."); } diff --git a/src/fobject.h b/src/fobject.h index 4acc89ee..64444e8e 100644 --- a/src/fobject.h +++ b/src/fobject.h @@ -58,7 +58,6 @@ class FObject // Typedef typedef std::list object_list; - typedef std::vector TimerList; // Constructor explicit FObject (FObject* = 0); @@ -89,14 +88,17 @@ class FObject bool delOwnTimer(); bool delAllTimer(); - // Data Members - static TimerList* timer_list; - protected: + // Typedef + typedef std::vector TimerList; + // Event handler virtual bool event (FEvent*); virtual void onTimer (FTimerEvent*); + // Data Members + static TimerList* timer_list; + private: // Disable copy constructor FObject (const FObject&); diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index d90333a0..4daa2e94 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -216,7 +216,7 @@ void FScrollbar::calculateSliderValues() } slider_pos = int( round ( float((bar_length - slider_length) * val) - / float(max - min) ) ); + / float(max - min) ) ); if ( slider_pos < 0 ) slider_pos = 0; @@ -581,6 +581,14 @@ void FScrollbar::onTimer (FTimerEvent*) || ( scroll_type == FScrollbar::scrollPageForward && 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(); return; } @@ -691,7 +699,7 @@ void FScrollbar::processMiddleButton (int x, int y) if ( y >1 && y < getHeight() ) { new_val = int( round ( float(max - min) * (y - 2.0 - (slider_length/2)) - / float(bar_length - slider_length) ) ); + / float(bar_length - slider_length) ) ); } else return; @@ -703,7 +711,7 @@ void FScrollbar::processMiddleButton (int x, int y) if ( x > 1+nf && x < getWidth()-nf ) { 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 return; diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp new file mode 100644 index 00000000..cfee1766 --- /dev/null +++ b/src/fscrollview.cpp @@ -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(); +} diff --git a/src/fscrollview.h b/src/fscrollview.h new file mode 100644 index 00000000..ebed1b91 --- /dev/null +++ b/src/fscrollview.h @@ -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 diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 6623ee1e..258ba596 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -494,7 +494,7 @@ void FTextView::onWheel (FWheelEvent* ev) case fc::WheelDown: { - int yoffset_end = last_line - getHeight() - nf_offset + 2; + int yoffset_end = last_line - getClientHeight(); if ( yoffset_end < 0 ) yoffset_end = 0; @@ -599,8 +599,6 @@ void FTextView::adjustSize() //---------------------------------------------------------------------- void FTextView::init() { - nf_offset = isNewFont() ? 1 : 0; - setForegroundColor (wc.dialog_fg); setBackgroundColor (wc.dialog_bg); @@ -624,6 +622,12 @@ void FTextView::init() "change-value", _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 last_line = int(getRows()); int yoffset_before = yoffset; + int yoffset_end = last_line - getClientHeight(); scrollType = vbar->getScrollType(); switch ( int(scrollType) ) { + case FScrollbar::noScroll: + break; + case FScrollbar::scrollPageBackward: - distance = getHeight() + nf_offset - 2; + distance = getClientHeight(); // fall through case FScrollbar::scrollStepBackward: yoffset -= distance; @@ -763,13 +771,16 @@ void FTextView::cb_VBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = getHeight() + nf_offset - 2; + distance = getClientHeight(); // fall through case FScrollbar::scrollStepForward: yoffset += distance; - if ( yoffset > last_line - getHeight() - nf_offset + 2 ) - yoffset = last_line - getHeight() - nf_offset + 2; + if ( yoffset > yoffset_end ) + yoffset = yoffset_end; + + if ( yoffset < 0 ) + yoffset = 0; break; @@ -782,8 +793,8 @@ void FTextView::cb_VBarChange (FWidget*, void*) yoffset = val; - if ( yoffset > last_line - getHeight() - nf_offset + 2 ) - yoffset = last_line - getHeight() - nf_offset + 2; + if ( yoffset > yoffset_end ) + yoffset = yoffset_end; if ( yoffset < 0 ) yoffset = 0; @@ -804,9 +815,6 @@ void FTextView::cb_VBarChange (FWidget*, void*) onWheel(&wheel_ev); break; } - - default: - break; } if ( isVisible() ) @@ -830,15 +838,19 @@ void FTextView::cb_VBarChange (FWidget*, void*) //---------------------------------------------------------------------- void FTextView::cb_HBarChange (FWidget*, void*) { + FScrollbar::sType scrollType; int distance = 1; int xoffset_before = xoffset; - int xoffset_end = int(maxLineWidth) - getWidth() + nf_offset + 4; - int scrollType = hbar->getScrollType(); + int xoffset_end = int(maxLineWidth) - getClientWidth(); + scrollType = hbar->getScrollType(); switch ( scrollType ) { + case FScrollbar::noScroll: + break; + case FScrollbar::scrollPageBackward: - distance = getWidth() - nf_offset - 4; + distance = getClientWidth(); // fall through case FScrollbar::scrollStepBackward: xoffset -= distance; @@ -849,13 +861,13 @@ void FTextView::cb_HBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = getWidth() - nf_offset - 4; + distance = getClientWidth(); // fall through case FScrollbar::scrollStepForward: xoffset += distance; - if ( xoffset > int(maxLineWidth) - getWidth() + nf_offset + 4 ) - xoffset = int(maxLineWidth) - getWidth() + nf_offset + 4; + if ( xoffset > int(maxLineWidth) - getClientWidth() ) + xoffset = int(maxLineWidth) - getClientWidth(); if ( xoffset < 0 ) xoffset = 0; @@ -871,8 +883,8 @@ void FTextView::cb_HBarChange (FWidget*, void*) xoffset = val; - if ( xoffset > int(maxLineWidth) - getWidth() + nf_offset + 4 ) - xoffset = int(maxLineWidth) - getWidth() + nf_offset + 4; + if ( xoffset > int(maxLineWidth) - getClientWidth() ) + xoffset = int(maxLineWidth) - getClientWidth(); if ( xoffset < 0 ) xoffset = 0; @@ -901,9 +913,6 @@ void FTextView::cb_HBarChange (FWidget*, void*) xoffset = xoffset_end; break; - - default: - break; } if ( isVisible() ) diff --git a/src/fvterm.cpp b/src/fvterm.cpp index ac9b548d..a31456c9 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -387,10 +387,10 @@ int FVTerm::print (term_area* area, FString& s) while ( *p ) { int width, height, rsh, bsh; - width = area->width; - height = area->height; - rsh = area->right_shadow; - bsh = area->bottom_shadow; + width = area->width; + height = area->height; + rsh = area->right_shadow; + bsh = area->bottom_shadow; switch ( *p ) { @@ -532,12 +532,12 @@ int FVTerm::print (term_area* area, register int c) if ( ! area ) return -1; - width = area->width; - height = area->height; - rsh = area->right_shadow; - bsh = area->bottom_shadow; - ax = area->cursor_x - 1; - ay = area->cursor_y - 1; + width = area->width; + height = area->height; + rsh = area->right_shadow; + bsh = area->bottom_shadow; + ax = area->cursor_x - 1; + ay = area->cursor_y - 1; nc.code = c; nc.fg_color = next_attribute.fg_color; @@ -619,6 +619,34 @@ int FVTerm::print (term_area* area, register int c) // 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(this); + FVTerm* p_obj = static_cast(obj->getParent()); + + while ( ! obj->vwin && p_obj ) + { + obj = p_obj; + p_obj = static_cast(p_obj->getParent()); + } + + if ( obj->vwin ) + { + print_area = obj->vwin; + return print_area; + } + } + + return vdesktop; +} + //---------------------------------------------------------------------- void FVTerm::createArea ( const FRect& r , const FPoint& p @@ -640,6 +668,7 @@ void FVTerm::createArea ( int x_offset, int y_offset , term_area*& area ) { // initialize virtual window + area = new term_area; area->x_offset = 0; @@ -1911,33 +1940,6 @@ void FVTerm::flush_out() // 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(this); - FVTerm* p_obj = static_cast(obj->getParent()); - - while ( ! obj->vwin && p_obj ) - { - obj = p_obj; - p_obj = static_cast(p_obj->getParent()); - } - - if ( obj->vwin ) - { - print_area = obj->vwin; - return print_area; - } - } - - return vdesktop; -} - //---------------------------------------------------------------------- void FVTerm::init() { diff --git a/src/fvterm.h b/src/fvterm.h index f91f00fb..bcda4242 100644 --- a/src/fvterm.h +++ b/src/fvterm.h @@ -190,7 +190,7 @@ class FVTerm : public FObject, public FTerm static bool isInheritBackground(); // Methods - void clearArea (int = ' '); + virtual void clearArea (int = ' '); void createVTerm (const FRect&); void createVTerm (int, int); static void resizeVTerm (const FRect&); @@ -229,6 +229,9 @@ class FVTerm : public FObject, public FTerm covered_character }; + // Accessor + virtual term_area* getPrintArea(); + // Methods void createArea ( const FRect& , const FPoint& @@ -315,9 +318,6 @@ class FVTerm : public FObject, public FTerm // Disable assignment operator (=) FVTerm& operator = (const FVTerm&); - // Accessor - term_area* getPrintArea(); - // Mutators void setPrintArea (term_area*); diff --git a/test/Makefile.am b/test/Makefile.am index 76a498e1..9e3cdfa1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -18,6 +18,7 @@ noinst_PROGRAMS = \ transparent \ keyboard \ timer \ + scrollview \ windows \ menu \ ui @@ -34,6 +35,7 @@ term_attributes_SOURCES = term-attributes.cpp transparent_SOURCES = transparent.cpp keyboard_SOURCES = keyboard.cpp timer_SOURCES = timer.cpp +scrollview_SOURCES = scrollview.cpp windows_SOURCES = windows.cpp menu_SOURCES = menu.cpp ui_SOURCES = ui.cpp diff --git a/test/Makefile.in b/test/Makefile.in index 9bf85feb..dfcb0e3f 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -86,8 +86,8 @@ noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \ opti-move$(EXEEXT) string-operations$(EXEEXT) \ mandelbrot$(EXEEXT) calculator$(EXEEXT) watch$(EXEEXT) \ term-attributes$(EXEEXT) transparent$(EXEEXT) \ - keyboard$(EXEEXT) timer$(EXEEXT) windows$(EXEEXT) \ - menu$(EXEEXT) ui$(EXEEXT) + keyboard$(EXEEXT) timer$(EXEEXT) scrollview$(EXEEXT) \ + windows$(EXEEXT) menu$(EXEEXT) ui$(EXEEXT) subdir = test DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/depcomp @@ -131,6 +131,9 @@ menu_LDADD = $(LDADD) am_opti_move_OBJECTS = opti-move.$(OBJEXT) opti_move_OBJECTS = $(am_opti_move_OBJECTS) opti_move_LDADD = $(LDADD) +am_scrollview_OBJECTS = scrollview.$(OBJEXT) +scrollview_OBJECTS = $(am_scrollview_OBJECTS) +scrollview_LDADD = $(LDADD) am_string_operations_OBJECTS = string-operations.$(OBJEXT) string_operations_OBJECTS = $(am_string_operations_OBJECTS) string_operations_LDADD = $(LDADD) @@ -189,15 +192,17 @@ am__v_CXXLD_1 = SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) $(hello_SOURCES) \ $(input_dialog_SOURCES) $(keyboard_SOURCES) \ $(mandelbrot_SOURCES) $(menu_SOURCES) $(opti_move_SOURCES) \ - $(string_operations_SOURCES) $(term_attributes_SOURCES) \ - $(timer_SOURCES) $(transparent_SOURCES) $(ui_SOURCES) \ - $(watch_SOURCES) $(windows_SOURCES) + $(scrollview_SOURCES) $(string_operations_SOURCES) \ + $(term_attributes_SOURCES) $(timer_SOURCES) \ + $(transparent_SOURCES) $(ui_SOURCES) $(watch_SOURCES) \ + $(windows_SOURCES) DIST_SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) \ $(hello_SOURCES) $(input_dialog_SOURCES) $(keyboard_SOURCES) \ $(mandelbrot_SOURCES) $(menu_SOURCES) $(opti_move_SOURCES) \ - $(string_operations_SOURCES) $(term_attributes_SOURCES) \ - $(timer_SOURCES) $(transparent_SOURCES) $(ui_SOURCES) \ - $(watch_SOURCES) $(windows_SOURCES) + $(scrollview_SOURCES) $(string_operations_SOURCES) \ + $(term_attributes_SOURCES) $(timer_SOURCES) \ + $(transparent_SOURCES) $(ui_SOURCES) $(watch_SOURCES) \ + $(windows_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -358,6 +363,7 @@ term_attributes_SOURCES = term-attributes.cpp transparent_SOURCES = transparent.cpp keyboard_SOURCES = keyboard.cpp timer_SOURCES = timer.cpp +scrollview_SOURCES = scrollview.cpp windows_SOURCES = windows.cpp menu_SOURCES = menu.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) $(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) @rm -f string-operations$(EXEEXT) $(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)/menu.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)/term-attributes.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@ diff --git a/test/mandelbrot.cpp b/test/mandelbrot.cpp index 0e34ff65..c684b5bb 100644 --- a/test/mandelbrot.cpp +++ b/test/mandelbrot.cpp @@ -20,7 +20,7 @@ class Mandelbrot : public FDialog // Destructor ~Mandelbrot(); - // Callback methods + // Event handlers void onAccel (FAccelEvent*); void onClose (FCloseEvent*); diff --git a/test/scrollview.cpp b/test/scrollview.cpp new file mode 100644 index 00000000..e94caa67 --- /dev/null +++ b/test/scrollview.cpp @@ -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(); +} diff --git a/test/ui.cpp b/test/ui.cpp index 37ab9528..64799924 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -648,7 +648,7 @@ void MyDialog::cb_about (FWidget*, void*) FMessageBox info ( "About" , line + L" The Final Cut " + line + "\n\n" L"Version " + libver + "\n\n" - L"(c) 2016 by Markus Gans" + L"(c) 2017 by Markus Gans" , FMessageBox::Ok, 0, 0, this ); info.setCenterText(); info.show(); @@ -893,7 +893,7 @@ void MyDialog::adjustSize() int main (int argc, char* argv[]) { 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 || std::strcmp(argv[1], "-h") == 0 ) )