Generalize scroll functions in FTextView

This commit is contained in:
Markus Gans 2018-02-17 19:12:48 +01:00
parent d8a6c25ce0
commit 4da8982f42
9 changed files with 324 additions and 363 deletions

View File

@ -1,3 +1,8 @@
2017-02-17 Markus Gans <guru.mail@muenster.de>
* Generalize scroll functions in FTextView
* Refactoring FButtonGroup::drawLabel
* Refactoring FToggleButton::drawLabel
2017-02-11 Markus Gans <guru.mail@muenster.de> 2017-02-11 Markus Gans <guru.mail@muenster.de>
* Refactoring FWidget::focusNextChild and FWidget::focusPrevChild * Refactoring FWidget::focusNextChild and FWidget::focusPrevChild
* Refactoring FListView::onWheel * Refactoring FListView::onWheel

View File

@ -4,7 +4,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2017 Markus Gans * * Copyright 2014-2018 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -134,6 +134,8 @@ class FButtonGroup : public FScrollView
// Methods // Methods
void init(); void init();
int getHotkeyPos (wchar_t[], wchar_t[], uInt);
void drawText (wchar_t[], int, uInt);
void directFocus(); void directFocus();
// Data Members // Data Members

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2017 Markus Gans * * Copyright 2014-2018 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -89,8 +89,12 @@ class FTextView : public FWidget
// Mutators // Mutators
void setGeometry (int, int, int, int, bool = true); void setGeometry (int, int, int, int, bool = true);
void setPosition (int);
void setText (const FString&); void setText (const FString&);
void scrollToX (int);
void scrollToY (int);
void scrollTo (const FPoint&);
void scrollTo (int, int);
void scrollBy (int, int);
// Methods // Methods
void hide(); void hide();
@ -121,11 +125,17 @@ class FTextView : public FWidget
// Disable assignment operator (=) // Disable assignment operator (=)
FTextView& operator = (const FTextView&); FTextView& operator = (const FTextView&);
// Accessors
int getTextHeight();
int getTextWidth();
// Methods // Methods
void init(); void init();
void draw(); void draw();
void drawText(); void drawText();
void processChanged(); void processChanged();
void drawHBar();
void drawVBar();
// Callback methods // Callback methods
void cb_VBarChange (FWidget*, data_ptr); void cb_VBarChange (FWidget*, data_ptr);
@ -135,6 +145,7 @@ class FTextView : public FWidget
FStringList data; FStringList data;
FScrollbar* vbar; FScrollbar* vbar;
FScrollbar* hbar; FScrollbar* hbar;
bool update_scrollbar;
int xoffset; int xoffset;
int yoffset; int yoffset;
int nf_offset; int nf_offset;
@ -160,6 +171,10 @@ inline uInt FTextView::getRows() const
inline const FStringList& FTextView::getLines() const inline const FStringList& FTextView::getLines() const
{ return data; } { return data; }
//----------------------------------------------------------------------
inline void FTextView::scrollTo (const FPoint& pos)
{ scrollTo(pos.getX(), pos.getY()); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTextView::deleteRange (int from, int to) inline void FTextView::deleteRange (int from, int to)
{ replaceRange (FString(), from, to); } { replaceRange (FString(), from, to); }

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2017 Markus Gans * * Copyright 2014-2018 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -152,6 +152,8 @@ class FToggleButton : public FWidget
// Methods // Methods
void init(); void init();
int getHotkeyPos (wchar_t[], wchar_t[], uInt);
void drawText (wchar_t[], int, uInt);
// Friend classes // Friend classes
friend class FButtonGroup; friend class FButtonGroup;

View File

@ -504,18 +504,13 @@ void FButtonGroup::draw()
void FButtonGroup::drawLabel() void FButtonGroup::drawLabel()
{ {
wchar_t* LabelText; wchar_t* LabelText;
register wchar_t* src;
register wchar_t* dest;
FString txt;
uInt length;
int hotkeypos; int hotkeypos;
bool isActive, isNoUnderline;
if ( text.isNull() || text.isEmpty() ) if ( text.isNull() || text.isEmpty() )
return; return;
txt = " " + text + " "; FString txt = " " + text + " ";
length = txt.getLength(); uInt length = txt.getLength();
hotkeypos = -1; hotkeypos = -1;
try try
@ -528,26 +523,10 @@ void FButtonGroup::drawLabel()
return; return;
} }
src = const_cast<wchar_t*>(txt.wc_str()); wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(LabelText); wchar_t* dest = const_cast<wchar_t*>(LabelText);
isActive = ((flags & fc::active) != 0);
isNoUnderline = ((flags & fc::no_underline) != 0);
unsetViewportPrint(); unsetViewportPrint();
hotkeypos = getHotkeyPos(src, dest, uInt(length));
// find hotkey position in string
// + generate a new string without the '&'-sign
for (uInt i = 0; i < length; i++)
{
if ( (i < length) && (txt[i] == '&') && (hotkeypos == -1) )
{
hotkeypos = int(i);
i++;
src++;
}
*dest++ = *src++;
}
if ( hotkeypos != -1 ) if ( hotkeypos != -1 )
length--; length--;
@ -557,6 +536,64 @@ void FButtonGroup::drawLabel()
else else
FWidget::setPrintPos (0, 1); FWidget::setPrintPos (0, 1);
drawText (LabelText, hotkeypos, length);
setViewportPrint();
delete[] LabelText;
}
// private methods of FButtonGroup
//----------------------------------------------------------------------
bool FButtonGroup::isRadioButton (FToggleButton* button) const
{
if ( ! button )
return false;
return bool ( std::strcmp ( button->getClassName()
, C_STR("FRadioButton") ) == 0 );
}
//----------------------------------------------------------------------
void FButtonGroup::init()
{
if ( isEnabled() )
flags |= fc::active;
setForegroundColor (wc.label_fg);
setBackgroundColor (wc.label_bg);
setMinimumSize (7, 4);
buttonlist.clear(); // no buttons yet
}
//----------------------------------------------------------------------
int FButtonGroup::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length)
{
// find hotkey position in string
// + generate a new string without the '&'-sign
int pos = -1;
wchar_t* txt = src;
for (uInt i = 0; i < length; i++)
{
if ( i < length && txt[i] == L'&' && pos == -1 )
{
pos = int(i);
i++;
src++;
}
*dest++ = *src++;
}
return pos;
}
//----------------------------------------------------------------------
void FButtonGroup::drawText (wchar_t LabelText[], int hotkeypos, uInt length)
{
bool isActive = ((flags & fc::active) != 0);
bool isNoUnderline = ((flags & fc::no_underline) != 0);
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
@ -587,33 +624,6 @@ void FButtonGroup::drawLabel()
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
setViewportPrint();
delete[] LabelText;
}
// private methods of FButtonGroup
//----------------------------------------------------------------------
bool FButtonGroup::isRadioButton (FToggleButton* button) const
{
if ( ! button )
return false;
return bool ( std::strcmp ( button->getClassName()
, C_STR("FRadioButton") ) == 0 );
}
//----------------------------------------------------------------------
void FButtonGroup::init()
{
if ( isEnabled() )
flags |= fc::active;
setForegroundColor (wc.label_fg);
setBackgroundColor (wc.label_bg);
setMinimumSize (7, 4);
buttonlist.clear(); // no buttons yet
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -863,7 +863,6 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime
inline void FOptiMove::leftMove ( char hmove[], int& htime inline void FOptiMove::leftMove ( char hmove[], int& htime
, int from_x, int to_x ) , int from_x, int to_x )
{ {
char str[BUF_SIZE] = {};
int num = from_x - to_x; int num = from_x - to_x;
if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime ) if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime )
@ -876,6 +875,7 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime
if ( F_cursor_left.cap ) if ( F_cursor_left.cap )
{ {
char str[BUF_SIZE] = {};
int htime_l = 0; int htime_l = 0;
str[0] = '\0'; str[0] = '\0';

View File

@ -489,7 +489,7 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::onWheel (FWheelEvent* ev) void FScrollView::onWheel (FWheelEvent* ev)
{ {
short distance = 4; short distance = 4;
switch ( ev->getWheel() ) switch ( ev->getWheel() )
{ {
@ -935,7 +935,7 @@ void FScrollView::cb_VBarChange (FWidget*, data_ptr)
void FScrollView::cb_HBarChange (FWidget*, data_ptr) void FScrollView::cb_HBarChange (FWidget*, data_ptr)
{ {
FScrollbar::sType scrollType = hbar->getScrollType(); FScrollbar::sType scrollType = hbar->getScrollType();
short distance = 1; short distance = 1;
short wheel_distance = 4; short wheel_distance = 4;
if ( scrollType >= FScrollbar::scrollStepBackward if ( scrollType >= FScrollbar::scrollStepBackward

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2017 Markus Gans * * Copyright 2014-2018 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -36,6 +36,7 @@ FTextView::FTextView(FWidget* parent)
, data() , data()
, vbar(0) , vbar(0)
, hbar(0) , hbar(0)
, update_scrollbar(true)
, xoffset(0) , xoffset(0)
, yoffset(0) , yoffset(0)
, nf_offset(0) , nf_offset(0)
@ -113,27 +114,6 @@ void FTextView::setGeometry (int x, int y, int w, int h, bool adjust)
hbar->resize(); hbar->resize();
} }
//----------------------------------------------------------------------
void FTextView::setPosition (int pos)
{
int last_line = int(getRows());
if ( pos < 0 || pos > last_line - getHeight() + 2 )
return;
yoffset = pos;
if ( isVisible() )
drawText();
vbar->setValue (yoffset);
if ( vbar->isVisible() )
vbar->drawBar();
flush_out();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::setText (const FString& str) void FTextView::setText (const FString& str)
{ {
@ -141,6 +121,73 @@ void FTextView::setText (const FString& str)
insert(str, -1); insert(str, -1);
} }
//----------------------------------------------------------------------
void FTextView::scrollToX (int x)
{
scrollTo (x, yoffset);
}
//----------------------------------------------------------------------
void FTextView::scrollToY (int y)
{
scrollTo (xoffset, y);
}
//----------------------------------------------------------------------
void FTextView::scrollBy (int dx, int dy)
{
scrollTo (xoffset + dx, yoffset + dy);
}
//----------------------------------------------------------------------
void FTextView::scrollTo (int x, int y)
{
bool changeX = bool(x != xoffset);
bool changeY = bool(y != yoffset);
if ( ! isVisible() || ! (changeX || changeY) )
return;
if ( xoffset != x )
{
int xoffset_end = int(maxLineWidth) - getTextWidth();
xoffset = x;
if ( xoffset < 0 )
xoffset = 0;
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
if ( update_scrollbar )
{
hbar->setValue (xoffset);
drawHBar();
}
}
if ( yoffset != y )
{
int yoffset_end = int(getRows()) - getTextHeight();
yoffset = y;
if ( yoffset < 0 )
yoffset = 0;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
if ( update_scrollbar )
{
vbar->setValue (yoffset);
drawVBar();
}
}
drawText();
updateTerminal();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::hide() void FTextView::hide()
{ {
@ -231,10 +278,10 @@ void FTextView::insert (const FString& str, int pos)
{ {
maxLineWidth = len; maxLineWidth = len;
if ( len > uInt(getWidth() - nf_offset - 2) ) if ( len > uInt(getTextWidth()) )
{ {
hbar->setMaximum (int(maxLineWidth) - getWidth() + nf_offset + 2); hbar->setMaximum (int(maxLineWidth) - getTextWidth());
hbar->setPageSize (int(maxLineWidth), getWidth() - nf_offset - 2); hbar->setPageSize (int(maxLineWidth), getTextWidth());
hbar->calculateSliderValues(); hbar->calculateSliderValues();
if ( ! hbar->isVisible() ) if ( ! hbar->isVisible() )
@ -244,14 +291,14 @@ void FTextView::insert (const FString& str, int pos)
} }
data.insert (iter + pos, text_split.begin(), text_split.end()); data.insert (iter + pos, text_split.begin(), text_split.end());
vbar->setMaximum (int(getRows()) - getHeight() + 2 - nf_offset); vbar->setMaximum (int(getRows()) - getTextHeight());
vbar->setPageSize (int(getRows()), getHeight() - 2 + nf_offset); vbar->setPageSize (int(getRows()), getTextHeight());
vbar->calculateSliderValues(); vbar->calculateSliderValues();
if ( ! vbar->isVisible() && int(getRows()) >= getHeight() + nf_offset - 1 ) if ( ! vbar->isVisible() && int(getRows()) >= getTextHeight() + 1 )
vbar->setVisible(); vbar->setVisible();
if ( vbar->isVisible() && int(getRows()) < getHeight() + nf_offset - 1 ) if ( vbar->isVisible() && int(getRows()) < getTextHeight() + 1 )
vbar->hide(); vbar->hide();
processChanged(); processChanged();
@ -317,7 +364,7 @@ void FTextView::clear()
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
for (int y = 0; y < getHeight() + nf_offset - 2; y++) for (int y = 0; y < getTextHeight(); y++)
{ {
setPrintPos (2, 2 - nf_offset + y); setPrintPos (2, 2 - nf_offset + y);
print (blank); print (blank);
@ -330,95 +377,51 @@ void FTextView::clear()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::onKeyPress (FKeyEvent* ev) void FTextView::onKeyPress (FKeyEvent* ev)
{ {
int last_line = int(getRows()); switch ( ev->key() )
int key = ev->key();
switch ( key )
{ {
case fc::Fkey_up: case fc::Fkey_up:
if ( yoffset > 0 ) scrollBy (0, -1);
yoffset--;
ev->accept(); ev->accept();
break; break;
case fc::Fkey_down: case fc::Fkey_down:
if ( yoffset + getHeight() + nf_offset <= last_line + 1 ) scrollBy (0, 1);
yoffset++;
ev->accept();
break;
case fc::Fkey_right:
if ( xoffset + getWidth() - nf_offset <= int(maxLineWidth) + 1 )
xoffset++;
ev->accept(); ev->accept();
break; break;
case fc::Fkey_left: case fc::Fkey_left:
if ( xoffset > 0 ) scrollBy (-1, 0);
xoffset--; ev->accept();
break;
case fc::Fkey_right:
scrollBy (1, 0);
ev->accept(); ev->accept();
break; break;
case fc::Fkey_ppage: case fc::Fkey_ppage:
yoffset -= getHeight() - 2; scrollBy (0, -getTextHeight());
if ( yoffset < 0 )
yoffset = 0;
ev->accept(); ev->accept();
break; break;
case fc::Fkey_npage: case fc::Fkey_npage:
if ( last_line >= getHeight() ) scrollBy (0, getTextHeight());
yoffset += getHeight() - 2;
if ( yoffset > last_line - getHeight() - nf_offset + 2 )
yoffset = last_line - getHeight() - nf_offset + 2;
if ( yoffset < 0 )
yoffset = 0;
ev->accept(); ev->accept();
break; break;
case fc::Fkey_home: case fc::Fkey_home:
yoffset = 0; scrollToY (0);
ev->accept(); ev->accept();
break; break;
case fc::Fkey_end: case fc::Fkey_end:
if ( last_line >= getHeight() ) scrollToY (int(getRows()) - getTextHeight());
yoffset = last_line - getHeight() - nf_offset + 2;
ev->accept(); ev->accept();
break; break;
default: default:
break; break;
} }
if ( ev->isAccepted() )
{
if ( isVisible() )
drawText();
vbar->setValue (yoffset);
if ( vbar->isVisible() )
vbar->drawBar();
hbar->setValue (xoffset);
if ( hbar->isVisible() )
hbar->drawBar();
updateTerminal();
flush_out();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -542,37 +545,16 @@ void FTextView::onMouseMove (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::onWheel (FWheelEvent* ev) void FTextView::onWheel (FWheelEvent* ev)
{ {
int last_line = int(getRows()); int distance = 4;
int wheel = ev->getWheel();
switch ( wheel ) switch ( ev->getWheel() )
{ {
case fc::WheelUp: case fc::WheelUp:
if ( yoffset == 0 ) scrollBy (0, -distance);
break;
yoffset -= 4;
if ( yoffset < 0 )
yoffset = 0;
break; break;
case fc::WheelDown: case fc::WheelDown:
{ scrollBy (0, distance);
int yoffset_end = last_line - getClientHeight();
if ( yoffset_end < 0 )
yoffset_end = 0;
if ( yoffset == yoffset_end )
break;
yoffset += 4;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
}
break; break;
default: default:
@ -582,16 +564,6 @@ void FTextView::onWheel (FWheelEvent* ev)
if ( isVisible() ) if ( isVisible() )
drawText(); drawText();
vbar->setValue (yoffset);
if ( vbar->isVisible() )
vbar->drawBar();
hbar->setValue (xoffset);
if ( hbar->isVisible() )
hbar->drawBar();
updateTerminal(); updateTerminal();
} }
@ -662,6 +634,18 @@ void FTextView::adjustSize()
// private methods of FTextView // private methods of FTextView
//----------------------------------------------------------------------
int FTextView::getTextHeight()
{
return getHeight() - 2 + nf_offset;
}
//----------------------------------------------------------------------
int FTextView::getTextWidth()
{
return getWidth() - 2 - nf_offset;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::init() void FTextView::init()
{ {
@ -767,7 +751,7 @@ void FTextView::drawText()
if ( data.empty() || getHeight() <= 2 || getWidth() <= 2 ) if ( data.empty() || getHeight() <= 2 || getWidth() <= 2 )
return; return;
num = uInt(getHeight() + nf_offset - 2); num = uInt(getTextHeight());
if ( num > getRows() ) if ( num > getRows() )
num = getRows(); num = getRows();
@ -784,7 +768,7 @@ void FTextView::drawText()
const wchar_t* line_str; const wchar_t* line_str;
setPrintPos (2, 2 - nf_offset + int(y)); setPrintPos (2, 2 - nf_offset + int(y));
line = data[y + uInt(yoffset)].mid ( uInt(1 + xoffset) line = data[y + uInt(yoffset)].mid ( uInt(1 + xoffset)
, uInt(getWidth() - nf_offset - 2) ); , uInt(getTextWidth()) );
line_str = line.wc_str(); line_str = line.wc_str();
len = line.getLength(); len = line.getLength();
@ -804,7 +788,7 @@ void FTextView::drawText()
print ('.'); print ('.');
} }
for (; i < uInt(getWidth() - nf_offset - 2); i++) for (; i < uInt(getTextWidth()); i++)
print (' '); print (' ');
} }
@ -818,17 +802,38 @@ void FTextView::processChanged()
emitCallback("changed"); emitCallback("changed");
} }
//----------------------------------------------------------------------
inline void FTextView::drawHBar()
{
if ( hbar->isVisible() )
hbar->drawBar();
}
//----------------------------------------------------------------------
inline void FTextView::drawVBar()
{
if ( vbar->isVisible() )
vbar->drawBar();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::cb_VBarChange (FWidget*, data_ptr) void FTextView::cb_VBarChange (FWidget*, data_ptr)
{ {
FScrollbar::sType scrollType; FScrollbar::sType scrollType = vbar->getScrollType();
int distance = 1 int distance = 1;
, last_line = int(getRows()) int wheel_distance = 4;
, yoffset_before = yoffset
, yoffset_end = last_line - getClientHeight();
scrollType = vbar->getScrollType();
switch ( int(scrollType) ) if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
update_scrollbar = true;
}
else
{
update_scrollbar = false;
}
switch ( scrollType )
{ {
case FScrollbar::noScroll: case FScrollbar::noScroll:
break; break;
@ -837,86 +842,52 @@ void FTextView::cb_VBarChange (FWidget*, data_ptr)
distance = getClientHeight(); distance = getClientHeight();
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
yoffset -= distance; scrollBy (0, -distance);
if ( yoffset < 0 )
yoffset = 0;
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = getClientHeight(); distance = getClientHeight();
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
yoffset += distance; scrollBy (0, distance);
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
if ( yoffset < 0 )
yoffset = 0;
break; break;
case FScrollbar::scrollJump: case FScrollbar::scrollJump:
{ scrollToY (vbar->getValue());
int val = vbar->getValue();
if ( yoffset == val )
break;
yoffset = val;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
if ( yoffset < 0 )
yoffset = 0;
break; break;
}
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
{ {
FWheelEvent wheel_ev (fc::MouseWheel_Event, FPoint(2,2), fc::WheelUp); scrollBy (0, -wheel_distance);
onWheel(&wheel_ev);
break; break;
} }
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
{ {
FWheelEvent wheel_ev (fc::MouseWheel_Event, FPoint(2,2), fc::WheelDown); scrollBy (0, wheel_distance);
onWheel(&wheel_ev);
break; break;
} }
} }
if ( isVisible() ) update_scrollbar = true;
{
drawText();
updateTerminal();
}
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollPageForward )
{
vbar->setValue (yoffset);
if ( vbar->isVisible() && yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::cb_HBarChange (FWidget*, data_ptr) void FTextView::cb_HBarChange (FWidget*, data_ptr)
{ {
FScrollbar::sType scrollType; FScrollbar::sType scrollType = hbar->getScrollType();
int distance = 1 int distance = 1;
, xoffset_before = xoffset int wheel_distance = 4;
, xoffset_end = int(maxLineWidth) - getClientWidth();
scrollType = hbar->getScrollType(); if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
update_scrollbar = true;
}
else
{
update_scrollbar = false;
}
switch ( scrollType ) switch ( scrollType )
{ {
@ -927,82 +898,28 @@ void FTextView::cb_HBarChange (FWidget*, data_ptr)
distance = getClientWidth(); distance = getClientWidth();
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
xoffset -= distance; scrollBy (-distance, 0);
if ( xoffset < 0 )
xoffset = 0;
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = getClientWidth(); distance = getClientWidth();
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
xoffset += distance; scrollBy (distance, 0);
if ( xoffset > int(maxLineWidth) - getClientWidth() )
xoffset = int(maxLineWidth) - getClientWidth();
if ( xoffset < 0 )
xoffset = 0;
break; break;
case FScrollbar::scrollJump: case FScrollbar::scrollJump:
{ scrollToX (hbar->getValue());
int val = hbar->getValue();
if ( xoffset == val )
break;
xoffset = val;
if ( xoffset > int(maxLineWidth) - getClientWidth() )
xoffset = int(maxLineWidth) - getClientWidth();
if ( xoffset < 0 )
xoffset = 0;
break; break;
}
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
if ( xoffset == 0 ) scrollBy (-wheel_distance, 0);
break;
xoffset -= 4;
if ( xoffset < 0 )
xoffset = 0;
break; break;
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
if ( xoffset == xoffset_end ) scrollBy (-wheel_distance, 0);
break;
xoffset += 4;
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
break; break;
} }
if ( isVisible() ) update_scrollbar = true;
{
drawText();
updateTerminal();
}
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
hbar->setValue (xoffset);
if ( hbar->isVisible() && xoffset_before != xoffset )
hbar->drawBar();
updateTerminal();
}
} }

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2017 Markus Gans * * Copyright 2014-2018 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -499,13 +499,8 @@ void FToggleButton::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::drawLabel() void FToggleButton::drawLabel()
{ {
uInt length, i;
int hotkeypos;
FString txt;
wchar_t* LabelText; wchar_t* LabelText;
register wchar_t* src; int hotkeypos;
register wchar_t* dest;
bool isActive, isNoUnderline;
if ( ! isVisible() ) if ( ! isVisible() )
return; return;
@ -513,7 +508,7 @@ void FToggleButton::drawLabel()
if ( text.isNull() || text.isEmpty() ) if ( text.isNull() || text.isEmpty() )
return; return;
length = text.getLength(); uInt length = text.getLength();
hotkeypos = -1; hotkeypos = -1;
try try
@ -526,62 +521,16 @@ void FToggleButton::drawLabel()
return; return;
} }
txt = text; FString txt = text;
src = const_cast<wchar_t*>(txt.wc_str()); wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(LabelText); wchar_t* dest = const_cast<wchar_t*>(LabelText);
isActive = ((flags & fc::active) != 0); hotkeypos = getHotkeyPos(src, dest, uInt(length));
isNoUnderline = ((flags & fc::no_underline) != 0);
// find hotkey position in string
// + generate a new string without the '&'-sign
for (i = 0; i < length; i++)
{
if ( i < length && txt[i] == '&' && hotkeypos == -1 )
{
hotkeypos = int(i);
i++;
src++;
}
*dest++ = *src++;
}
if ( hotkeypos != -1 ) if ( hotkeypos != -1 )
length--; length--;
setPrintPos (1 + label_offset_pos, 1); setPrintPos (1 + label_offset_pos, 1);
drawText (LabelText, hotkeypos, length);
if ( isMonochron() )
setReverse(true);
if ( isEnabled() )
setColor (wc.label_fg, wc.label_bg);
else
setColor (wc.label_inactive_fg, wc.label_inactive_bg);
for (int z = 0; z < int(length); z++)
{
if ( (z == hotkeypos) && isActive )
{
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
if ( ! isNoUnderline )
setUnderline();
print ( LabelText[z] );
if ( ! isNoUnderline )
unsetUnderline();
setColor (wc.label_fg, wc.label_bg);
}
else
print (LabelText[z]);
}
if ( isMonochron() )
setReverse(false);
delete[] LabelText; delete[] LabelText;
} }
@ -686,3 +635,64 @@ void FToggleButton::init()
setBackgroundColor (wc.label_inactive_bg); setBackgroundColor (wc.label_inactive_bg);
} }
} }
//----------------------------------------------------------------------
int FToggleButton::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length)
{
// find hotkey position in string
// + generate a new string without the '&'-sign
int pos = -1;
wchar_t* txt = src;
for (uInt i = 0; i < length; i++)
{
if ( i < length && txt[i] == L'&' && pos == -1 )
{
pos = int(i);
i++;
src++;
}
*dest++ = *src++;
}
return pos;
}
//----------------------------------------------------------------------
void FToggleButton::drawText (wchar_t LabelText[], int hotkeypos, uInt length)
{
bool isActive = ((flags & fc::active) != 0);
bool isNoUnderline = ((flags & fc::no_underline) != 0);
if ( isMonochron() )
setReverse(true);
if ( isEnabled() )
setColor (wc.label_fg, wc.label_bg);
else
setColor (wc.label_inactive_fg, wc.label_inactive_bg);
for (int z = 0; z < int(length); z++)
{
if ( (z == hotkeypos) && isActive )
{
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
if ( ! isNoUnderline )
setUnderline();
print ( LabelText[z] );
if ( ! isNoUnderline )
unsetUnderline();
setColor (wc.label_fg, wc.label_bg);
}
else
print (LabelText[z]);
}
if ( isMonochron() )
setReverse(false);;
}