FButtonGroup now inherits from FScrollView

This commit is contained in:
Markus Gans 2017-02-20 00:00:53 +01:00
parent 3f8ed6e78e
commit b35d225ff5
8 changed files with 188 additions and 163 deletions

View File

@ -1,3 +1,9 @@
2017-02-19 Markus Gans <guru.mail@muenster.de>
* New FWidget methods setMinimumWidth(), setMinimumHeight(),
setMaximumWidth() and setMaximumHeight()
* FButtonGroup now inherits from FScrollView. This supports
many buttons to be displayed in a smaller frame.
2017-02-18 Markus Gans <guru.mail@muenster.de>
* Allows a window to have more than one FScrollView widget

View File

@ -14,9 +14,8 @@
// constructor and destructor
//----------------------------------------------------------------------
FButtonGroup::FButtonGroup(FWidget* parent)
: FWidget(parent)
: FScrollView(parent)
, text()
, border(true)
, buttonlist()
{
init();
@ -24,9 +23,8 @@ FButtonGroup::FButtonGroup(FWidget* parent)
//----------------------------------------------------------------------
FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent)
: FWidget(parent)
: FScrollView(parent)
, text(txt)
, border(true)
, buttonlist()
{
init();
@ -88,17 +86,6 @@ bool FButtonGroup::setEnable (bool on)
return on;
}
//----------------------------------------------------------------------
bool FButtonGroup::setBorder(bool on)
{
if ( on )
border = true;
else
border = false;
return on;
}
//----------------------------------------------------------------------
void FButtonGroup::setText (const FString& txt)
{
@ -203,7 +190,7 @@ void FButtonGroup::hide()
for (int y=0; y < getHeight(); y++)
{
setPrintPos (1, 1+y);
FWidget::setPrintPos (1, 1+y);
print (blank);
}
@ -426,14 +413,13 @@ void FButtonGroup::draw()
setReverse(true);
setColor();
if ( border )
drawBorder();
drawLabel();
clearArea();
if ( isMonochron() )
setReverse(false);
FScrollView::draw();
drawLabel();
}
//----------------------------------------------------------------------
@ -459,6 +445,7 @@ void FButtonGroup::drawLabel()
isActive = ((flags & fc::active) != 0);
isNoUnderline = ((flags & fc::no_underline) != 0);
unsetViewportPrint();
// find hotkey position in string
// + generate a new string without the '&'-sign
@ -476,10 +463,10 @@ void FButtonGroup::drawLabel()
if ( hotkeypos != -1 )
length--;
if ( border )
setPrintPos (2, 1);
if ( hasBorder() )
FWidget::setPrintPos (2, 1);
else
setPrintPos (0, 1);
FWidget::setPrintPos (0, 1);
if ( isEnabled() )
setColor(wc.label_emphasis_fg, wc.label_bg);
@ -506,13 +493,14 @@ void FButtonGroup::drawLabel()
print ( LabelText[z] );
}
setViewportPrint();
delete[] LabelText;
}
// private methods of FButtonGroup
//----------------------------------------------------------------------
bool FButtonGroup::isRadioButton(FToggleButton* button) const
bool FButtonGroup::isRadioButton (FToggleButton* button) const
{
if ( ! button )
return false;
@ -524,16 +512,12 @@ bool FButtonGroup::isRadioButton(FToggleButton* button) const
//----------------------------------------------------------------------
void FButtonGroup::init()
{
setTopPadding(1);
setLeftPadding(1);
setBottomPadding(1);
setRightPadding(1);
if ( isEnabled() )
flags |= fc::active;
setForegroundColor (wc.label_fg);
setBackgroundColor (wc.label_bg);
setMinimumSize (7, 4);
buttonlist.clear(); // no buttons yet
}

View File

@ -28,7 +28,7 @@
#ifndef _FBUTTONGROUP_H
#define _FBUTTONGROUP_H
#include "fwidget.h"
#include "fscrollview.h"
// class forward declaration
@ -41,7 +41,7 @@ class FToggleButton;
#pragma pack(push)
#pragma pack(1)
class FButtonGroup : public FWidget
class FButtonGroup : public FScrollView
{
public:
// Constructors
@ -62,9 +62,6 @@ class FButtonGroup : public FWidget
bool setEnable();
bool unsetEnable();
bool setDisable();
bool setBorder(bool);
bool setBorder();
bool unsetBorder();
void setText (const FString&);
// Inquiries
@ -103,7 +100,7 @@ class FButtonGroup : public FWidget
FButtonGroup& operator = (const FButtonGroup&);
// Inquiries
bool isRadioButton(FToggleButton*) const;
bool isRadioButton (FToggleButton*) const;
// Methods
void init();
@ -111,7 +108,6 @@ class FButtonGroup : public FWidget
// Data Members
FString text;
bool border;
FObjectList buttonlist;
};
#pragma pack(pop)
@ -134,14 +130,6 @@ inline bool FButtonGroup::unsetEnable()
inline bool FButtonGroup::setDisable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FButtonGroup::setBorder()
{ return setBorder(true); }
//----------------------------------------------------------------------
inline bool FButtonGroup::unsetBorder()
{ return setBorder(false); }
//----------------------------------------------------------------------
inline FString& FButtonGroup::getText()
{ return text; }

View File

@ -70,10 +70,12 @@ void FRadioButton::drawRadioButton()
else
{
print ('(');
if ( isCygwinTerminal() )
print (0x04);
else
print (fc::Bullet); // Bullet ●
print (')');
}
}

View File

@ -286,10 +286,11 @@ void FScrollbar::drawButtons()
//----------------------------------------------------------------------
void FScrollbar::drawBar()
{
if ( slider_pos != current_slider_pos )
{
int z;
if ( slider_pos == current_slider_pos || length < 3 )
return;
if ( bar_orientation == fc::vertical )
{
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
@ -391,7 +392,6 @@ void FScrollbar::drawBar()
if ( isMonochron() )
setReverse(false);
}
}
//----------------------------------------------------------------------
@ -418,6 +418,8 @@ void FScrollbar::onMouseDown (FMouseEvent* ev)
// process LeftButton
scroll_type = getClickedScrollType(mouse_x, mouse_y);
if ( scroll_type == FScrollbar::noScroll )
{
if ( bar_orientation == fc::vertical )
{
if ( mouse_y > slider_pos+1 && mouse_y <= slider_pos+slider_length+1 )
@ -439,6 +441,7 @@ void FScrollbar::onMouseDown (FMouseEvent* ev)
if ( slider_click_pos > 0 )
scroll_type = FScrollbar::scrollJump;
}
if ( scroll_type == FScrollbar::scrollPageBackward
|| scroll_type == FScrollbar::scrollPageForward )
@ -609,6 +612,9 @@ void FScrollbar::init()
//----------------------------------------------------------------------
void FScrollbar::draw()
{
if ( length < 2 )
return;
drawButtons();
current_slider_pos = -1;
drawBar();

View File

@ -187,7 +187,7 @@ void FScrollView::setPos (int x, int y, bool adjust)
void FScrollView::setWidth (int w, bool adjust)
{
FWidget::setWidth (w, adjust);
viewport_geometry.setWidth(w);
viewport_geometry.setWidth(w - vertical_border_spacing - nf_offset);
calculateScrollbarPos();
if ( getScrollWidth() < getViewportWidth() )
@ -198,7 +198,7 @@ void FScrollView::setWidth (int w, bool adjust)
void FScrollView::setHeight (int h, bool adjust)
{
FWidget::setHeight (h, adjust);
viewport_geometry.setHeight(h);
viewport_geometry.setHeight(h - horizontal_border_spacing);
calculateScrollbarPos();
if ( getScrollHeight() < getViewportHeight() )
@ -209,7 +209,8 @@ void FScrollView::setHeight (int h, bool adjust)
void FScrollView::setSize (int w, int h, bool adjust)
{
FWidget::setSize (w, h, adjust);
viewport_geometry.setSize(w, h);
viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset
, h - horizontal_border_spacing );
calculateScrollbarPos();
if ( getScrollWidth() < getViewportWidth()
@ -223,7 +224,8 @@ void FScrollView::setGeometry (int x, int y, int w, int h, bool adjust)
FWidget::setGeometry (x, y, w, h, adjust);
scroll_geometry.setPos ( getTermX() + getLeftPadding() - 1
, getTermY() + getTopPadding() - 1 );
viewport_geometry.setSize(w, h);
viewport_geometry.setSize ( w - vertical_border_spacing - nf_offset
, h - horizontal_border_spacing );
calculateScrollbarPos();
if ( getScrollWidth() < getViewportWidth()
@ -296,6 +298,8 @@ void FScrollView::scrollTo (int x, int y)
short& yoffset = viewport_geometry.y1_ref();
short xoffset_end = short(getScrollWidth() - getViewportWidth());
short yoffset_end = short(getScrollHeight() - getViewportHeight());
int save_width = viewport_geometry.getWidth();
int save_height = viewport_geometry.getHeight();
x--;
y--;
@ -317,6 +321,8 @@ void FScrollView::scrollTo (int x, int y)
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
viewport_geometry.setWidth(save_width);
viewport_geometry.setHeight(save_height);
hbar->setValue (xoffset);
vbar->setValue (yoffset);
drawHBar();
@ -377,6 +383,8 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
short yoffset_before = yoffset;
short xoffset_end = short(getScrollWidth() - getViewportWidth());
short yoffset_end = short(getScrollHeight() - getViewportHeight());
int save_width = viewport_geometry.getWidth();
int save_height = viewport_geometry.getHeight();
switch ( key )
{
@ -445,6 +453,8 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
if ( isVisible() && viewport
&& (xoffset_before != xoffset || yoffset_before != yoffset) )
{
viewport_geometry.setWidth(save_width);
viewport_geometry.setHeight(save_height);
viewport->has_changes = true;
setTopPadding (1 - yoffset);
setLeftPadding (1 - xoffset);
@ -469,6 +479,7 @@ void FScrollView::onWheel (FWheelEvent* ev)
bool hasChanges = false;
short& yoffset = viewport_geometry.y1_ref();
short yoffset_before = yoffset;
int save_height = viewport_geometry.getHeight();
int wheel = ev->getWheel();
switch ( wheel )
@ -507,6 +518,7 @@ void FScrollView::onWheel (FWheelEvent* ev)
if ( isVisible() && viewport && yoffset_before != yoffset )
{
viewport_geometry.setHeight(save_height);
viewport->has_changes = true;
setTopPadding (1 - yoffset);
setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - yoffset));
@ -551,28 +563,31 @@ void FScrollView::onChildFocusIn (FFocusEvent*)
// Scrolls the viewport so that the focused widget is visible
FRect widget_geometry;
FRect vp_geometry;
FWidget* focus_widget = FWidget::getFocusWidget();
if ( ! focus_widget )
return;
widget_geometry = focus_widget->getGeometryWithShadow();
vp_geometry = viewport_geometry;
vp_geometry.move(1,1);
if ( ! viewport_geometry.contains(widget_geometry) )
if ( ! vp_geometry.contains(widget_geometry) )
{
int x, y;
int vx = viewport_geometry.getX();
int vy = viewport_geometry.getY();
int vx = vp_geometry.getX();
int vy = vp_geometry.getY();
int wx = widget_geometry.getX();
int wy = widget_geometry.getY();
if ( wx > vx )
x = widget_geometry.getX2() - viewport_geometry.getWidth() + 3;
x = widget_geometry.getX2() - vp_geometry.getWidth() + 1;
else
x = wx;
if ( wy > vy )
y = widget_geometry.getY2() - viewport_geometry.getHeight() + 3;
y = widget_geometry.getY2() - vp_geometry.getHeight() + 1;
else
y = wy;
@ -837,6 +852,7 @@ void FScrollView::cb_VBarChange (FWidget*, void*)
short& yoffset = viewport_geometry.y1_ref();
short yoffset_before = yoffset;
short yoffset_end = short(getScrollHeight() - getViewportHeight());
int save_height = viewport_geometry.getHeight();
scrollType = vbar->getScrollType();
switch ( scrollType )
@ -912,6 +928,7 @@ void FScrollView::cb_VBarChange (FWidget*, void*)
if ( isVisible() && viewport && yoffset_before != yoffset )
{
viewport_geometry.setHeight(save_height);
viewport->has_changes = true;
setTopPadding (1 - yoffset);
setBottomPadding (1 - (getScrollHeight() - getViewportHeight() - yoffset));
@ -940,6 +957,7 @@ void FScrollView::cb_HBarChange (FWidget*, void*)
short& xoffset = viewport_geometry.x1_ref();
short xoffset_before = xoffset;
short xoffset_end = short(getScrollWidth() - getViewportWidth());
int save_width = viewport_geometry.getWidth();
scrollType = hbar->getScrollType();
switch ( scrollType )
@ -1015,6 +1033,7 @@ void FScrollView::cb_HBarChange (FWidget*, void*)
if ( isVisible() && viewport && xoffset_before != xoffset )
{
viewport_geometry.setWidth(save_width);
viewport->has_changes = true;
setLeftPadding (1 - xoffset);
setRightPadding (1 - (getScrollWidth() - getViewportWidth() - xoffset) + nf_offset);

View File

@ -13,7 +13,7 @@
// constructor and destructor
//----------------------------------------------------------------------
FToggleButton::FToggleButton(FWidget* parent)
FToggleButton::FToggleButton (FWidget* parent)
: FWidget(parent)
, checked(false)
, label_offset_pos(0)

View File

@ -204,7 +204,11 @@ class FWidget : public FVTerm
virtual void setGeometry (const FRect&, bool = true);
virtual void setGeometry (int, int, int, int, bool = true);
virtual void setShadowSize (int, int);
void setMinimumWidth (int);
void setMinimumHeight (int);
void setMinimumSize (int, int);
void setMaximumWidth (int);
void setMaximumHeight (int);
void setMaximumSize (int, int);
void setFixedSize (int, int);
bool setCursorPos (const FPoint&);
@ -771,10 +775,26 @@ inline void FWidget::setGeometry (const FRect& box, bool adjust)
inline void FWidget::setShadowSize (int right, int bottom)
{ wshadow.setPoint (right, bottom); }
//----------------------------------------------------------------------
inline void FWidget::setMinimumWidth (int min_width)
{ size_hints.setMinimum (min_width, size_hints.min_height); }
//----------------------------------------------------------------------
inline void FWidget::setMinimumHeight (int min_height)
{ size_hints.setMinimum (size_hints.min_width, min_height); }
//----------------------------------------------------------------------
inline void FWidget::setMinimumSize (int min_width, int min_height)
{ size_hints.setMinimum (min_width, min_height); }
//----------------------------------------------------------------------
inline void FWidget::setMaximumWidth (int max_width)
{ size_hints.setMaximum (max_width, size_hints.max_height); }
//----------------------------------------------------------------------
inline void FWidget::setMaximumHeight (int max_height)
{ size_hints.setMaximum (size_hints.max_width, max_height); }
//----------------------------------------------------------------------
inline void FWidget::setMaximumSize (int max_width, int max_height)
{ size_hints.setMaximum (max_width, max_height); }