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>
* Refactoring FWidget::focusNextChild and FWidget::focusPrevChild
* Refactoring FListView::onWheel

View File

@ -4,7 +4,7 @@
* *
* 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 *
* modify it under the terms of the GNU Lesser General Public License *
@ -134,6 +134,8 @@ class FButtonGroup : public FScrollView
// Methods
void init();
int getHotkeyPos (wchar_t[], wchar_t[], uInt);
void drawText (wchar_t[], int, uInt);
void directFocus();
// Data Members

View File

@ -3,7 +3,7 @@
* *
* 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 *
* modify it under the terms of the GNU Lesser General Public License *
@ -89,8 +89,12 @@ class FTextView : public FWidget
// Mutators
void setGeometry (int, int, int, int, bool = true);
void setPosition (int);
void setText (const FString&);
void scrollToX (int);
void scrollToY (int);
void scrollTo (const FPoint&);
void scrollTo (int, int);
void scrollBy (int, int);
// Methods
void hide();
@ -121,11 +125,17 @@ class FTextView : public FWidget
// Disable assignment operator (=)
FTextView& operator = (const FTextView&);
// Accessors
int getTextHeight();
int getTextWidth();
// Methods
void init();
void draw();
void drawText();
void processChanged();
void drawHBar();
void drawVBar();
// Callback methods
void cb_VBarChange (FWidget*, data_ptr);
@ -135,6 +145,7 @@ class FTextView : public FWidget
FStringList data;
FScrollbar* vbar;
FScrollbar* hbar;
bool update_scrollbar;
int xoffset;
int yoffset;
int nf_offset;
@ -160,6 +171,10 @@ inline uInt FTextView::getRows() const
inline const FStringList& FTextView::getLines() const
{ return data; }
//----------------------------------------------------------------------
inline void FTextView::scrollTo (const FPoint& pos)
{ scrollTo(pos.getX(), pos.getY()); }
//----------------------------------------------------------------------
inline void FTextView::deleteRange (int from, int to)
{ replaceRange (FString(), from, to); }

View File

@ -3,7 +3,7 @@
* *
* 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 *
* modify it under the terms of the GNU Lesser General Public License *
@ -152,6 +152,8 @@ class FToggleButton : public FWidget
// Methods
void init();
int getHotkeyPos (wchar_t[], wchar_t[], uInt);
void drawText (wchar_t[], int, uInt);
// Friend classes
friend class FButtonGroup;

View File

@ -504,18 +504,13 @@ void FButtonGroup::draw()
void FButtonGroup::drawLabel()
{
wchar_t* LabelText;
register wchar_t* src;
register wchar_t* dest;
FString txt;
uInt length;
int hotkeypos;
bool isActive, isNoUnderline;
if ( text.isNull() || text.isEmpty() )
return;
txt = " " + text + " ";
length = txt.getLength();
FString txt = " " + text + " ";
uInt length = txt.getLength();
hotkeypos = -1;
try
@ -528,26 +523,10 @@ void FButtonGroup::drawLabel()
return;
}
src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(LabelText);
isActive = ((flags & fc::active) != 0);
isNoUnderline = ((flags & fc::no_underline) != 0);
wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
wchar_t* dest = const_cast<wchar_t*>(LabelText);
unsetViewportPrint();
// 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++;
}
hotkeypos = getHotkeyPos(src, dest, uInt(length));
if ( hotkeypos != -1 )
length--;
@ -557,6 +536,64 @@ void FButtonGroup::drawLabel()
else
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() )
setReverse(true);
@ -587,33 +624,6 @@ void FButtonGroup::drawLabel()
if ( isMonochron() )
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
, int from_x, int to_x )
{
char str[BUF_SIZE] = {};
int num = from_x - to_x;
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 )
{
char str[BUF_SIZE] = {};
int htime_l = 0;
str[0] = '\0';

View File

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

View File

@ -3,7 +3,7 @@
* *
* 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 *
* modify it under the terms of the GNU Lesser General Public License *
@ -36,6 +36,7 @@ FTextView::FTextView(FWidget* parent)
, data()
, vbar(0)
, hbar(0)
, update_scrollbar(true)
, xoffset(0)
, yoffset(0)
, nf_offset(0)
@ -113,27 +114,6 @@ void FTextView::setGeometry (int x, int y, int w, int h, bool adjust)
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)
{
@ -141,6 +121,73 @@ void FTextView::setText (const FString& str)
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()
{
@ -231,10 +278,10 @@ void FTextView::insert (const FString& str, int pos)
{
maxLineWidth = len;
if ( len > uInt(getWidth() - nf_offset - 2) )
if ( len > uInt(getTextWidth()) )
{
hbar->setMaximum (int(maxLineWidth) - getWidth() + nf_offset + 2);
hbar->setPageSize (int(maxLineWidth), getWidth() - nf_offset - 2);
hbar->setMaximum (int(maxLineWidth) - getTextWidth());
hbar->setPageSize (int(maxLineWidth), getTextWidth());
hbar->calculateSliderValues();
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());
vbar->setMaximum (int(getRows()) - getHeight() + 2 - nf_offset);
vbar->setPageSize (int(getRows()), getHeight() - 2 + nf_offset);
vbar->setMaximum (int(getRows()) - getTextHeight());
vbar->setPageSize (int(getRows()), getTextHeight());
vbar->calculateSliderValues();
if ( ! vbar->isVisible() && int(getRows()) >= getHeight() + nf_offset - 1 )
if ( ! vbar->isVisible() && int(getRows()) >= getTextHeight() + 1 )
vbar->setVisible();
if ( vbar->isVisible() && int(getRows()) < getHeight() + nf_offset - 1 )
if ( vbar->isVisible() && int(getRows()) < getTextHeight() + 1 )
vbar->hide();
processChanged();
@ -317,7 +364,7 @@ void FTextView::clear()
std::memset(blank, ' ', uLong(size));
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);
print (blank);
@ -330,95 +377,51 @@ void FTextView::clear()
//----------------------------------------------------------------------
void FTextView::onKeyPress (FKeyEvent* ev)
{
int last_line = int(getRows());
int key = ev->key();
switch ( key )
switch ( ev->key() )
{
case fc::Fkey_up:
if ( yoffset > 0 )
yoffset--;
scrollBy (0, -1);
ev->accept();
break;
case fc::Fkey_down:
if ( yoffset + getHeight() + nf_offset <= last_line + 1 )
yoffset++;
ev->accept();
break;
case fc::Fkey_right:
if ( xoffset + getWidth() - nf_offset <= int(maxLineWidth) + 1 )
xoffset++;
scrollBy (0, 1);
ev->accept();
break;
case fc::Fkey_left:
if ( xoffset > 0 )
xoffset--;
scrollBy (-1, 0);
ev->accept();
break;
case fc::Fkey_right:
scrollBy (1, 0);
ev->accept();
break;
case fc::Fkey_ppage:
yoffset -= getHeight() - 2;
if ( yoffset < 0 )
yoffset = 0;
scrollBy (0, -getTextHeight());
ev->accept();
break;
case fc::Fkey_npage:
if ( last_line >= getHeight() )
yoffset += getHeight() - 2;
if ( yoffset > last_line - getHeight() - nf_offset + 2 )
yoffset = last_line - getHeight() - nf_offset + 2;
if ( yoffset < 0 )
yoffset = 0;
scrollBy (0, getTextHeight());
ev->accept();
break;
case fc::Fkey_home:
yoffset = 0;
scrollToY (0);
ev->accept();
break;
case fc::Fkey_end:
if ( last_line >= getHeight() )
yoffset = last_line - getHeight() - nf_offset + 2;
scrollToY (int(getRows()) - getTextHeight());
ev->accept();
break;
default:
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)
{
int last_line = int(getRows());
int wheel = ev->getWheel();
int distance = 4;
switch ( wheel )
switch ( ev->getWheel() )
{
case fc::WheelUp:
if ( yoffset == 0 )
break;
yoffset -= 4;
if ( yoffset < 0 )
yoffset = 0;
scrollBy (0, -distance);
break;
case fc::WheelDown:
{
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;
}
scrollBy (0, distance);
break;
default:
@ -582,16 +564,6 @@ void FTextView::onWheel (FWheelEvent* ev)
if ( isVisible() )
drawText();
vbar->setValue (yoffset);
if ( vbar->isVisible() )
vbar->drawBar();
hbar->setValue (xoffset);
if ( hbar->isVisible() )
hbar->drawBar();
updateTerminal();
}
@ -662,6 +634,18 @@ void FTextView::adjustSize()
// private methods of FTextView
//----------------------------------------------------------------------
int FTextView::getTextHeight()
{
return getHeight() - 2 + nf_offset;
}
//----------------------------------------------------------------------
int FTextView::getTextWidth()
{
return getWidth() - 2 - nf_offset;
}
//----------------------------------------------------------------------
void FTextView::init()
{
@ -767,7 +751,7 @@ void FTextView::drawText()
if ( data.empty() || getHeight() <= 2 || getWidth() <= 2 )
return;
num = uInt(getHeight() + nf_offset - 2);
num = uInt(getTextHeight());
if ( num > getRows() )
num = getRows();
@ -784,7 +768,7 @@ void FTextView::drawText()
const wchar_t* line_str;
setPrintPos (2, 2 - nf_offset + int(y));
line = data[y + uInt(yoffset)].mid ( uInt(1 + xoffset)
, uInt(getWidth() - nf_offset - 2) );
, uInt(getTextWidth()) );
line_str = line.wc_str();
len = line.getLength();
@ -804,7 +788,7 @@ void FTextView::drawText()
print ('.');
}
for (; i < uInt(getWidth() - nf_offset - 2); i++)
for (; i < uInt(getTextWidth()); i++)
print (' ');
}
@ -818,17 +802,38 @@ void FTextView::processChanged()
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)
{
FScrollbar::sType scrollType;
int distance = 1
, last_line = int(getRows())
, yoffset_before = yoffset
, yoffset_end = last_line - getClientHeight();
scrollType = vbar->getScrollType();
FScrollbar::sType scrollType = vbar->getScrollType();
int distance = 1;
int wheel_distance = 4;
switch ( int(scrollType) )
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
update_scrollbar = true;
}
else
{
update_scrollbar = false;
}
switch ( scrollType )
{
case FScrollbar::noScroll:
break;
@ -837,86 +842,52 @@ void FTextView::cb_VBarChange (FWidget*, data_ptr)
distance = getClientHeight();
// fall through
case FScrollbar::scrollStepBackward:
yoffset -= distance;
if ( yoffset < 0 )
yoffset = 0;
scrollBy (0, -distance);
break;
case FScrollbar::scrollPageForward:
distance = getClientHeight();
// fall through
case FScrollbar::scrollStepForward:
yoffset += distance;
if ( yoffset > yoffset_end )
yoffset = yoffset_end;
if ( yoffset < 0 )
yoffset = 0;
scrollBy (0, distance);
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;
scrollToY (vbar->getValue());
break;
}
case FScrollbar::scrollWheelUp:
{
FWheelEvent wheel_ev (fc::MouseWheel_Event, FPoint(2,2), fc::WheelUp);
onWheel(&wheel_ev);
scrollBy (0, -wheel_distance);
break;
}
case FScrollbar::scrollWheelDown:
{
FWheelEvent wheel_ev (fc::MouseWheel_Event, FPoint(2,2), fc::WheelDown);
onWheel(&wheel_ev);
scrollBy (0, wheel_distance);
break;
}
}
if ( isVisible() )
{
drawText();
updateTerminal();
}
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollPageForward )
{
vbar->setValue (yoffset);
if ( vbar->isVisible() && yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
}
update_scrollbar = true;
}
//----------------------------------------------------------------------
void FTextView::cb_HBarChange (FWidget*, data_ptr)
{
FScrollbar::sType scrollType;
int distance = 1
, xoffset_before = xoffset
, xoffset_end = int(maxLineWidth) - getClientWidth();
scrollType = hbar->getScrollType();
FScrollbar::sType scrollType = hbar->getScrollType();
int distance = 1;
int wheel_distance = 4;
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
update_scrollbar = true;
}
else
{
update_scrollbar = false;
}
switch ( scrollType )
{
@ -927,82 +898,28 @@ void FTextView::cb_HBarChange (FWidget*, data_ptr)
distance = getClientWidth();
// fall through
case FScrollbar::scrollStepBackward:
xoffset -= distance;
if ( xoffset < 0 )
xoffset = 0;
scrollBy (-distance, 0);
break;
case FScrollbar::scrollPageForward:
distance = getClientWidth();
// fall through
case FScrollbar::scrollStepForward:
xoffset += distance;
if ( xoffset > int(maxLineWidth) - getClientWidth() )
xoffset = int(maxLineWidth) - getClientWidth();
if ( xoffset < 0 )
xoffset = 0;
scrollBy (distance, 0);
break;
case FScrollbar::scrollJump:
{
int val = hbar->getValue();
if ( xoffset == val )
break;
xoffset = val;
if ( xoffset > int(maxLineWidth) - getClientWidth() )
xoffset = int(maxLineWidth) - getClientWidth();
if ( xoffset < 0 )
xoffset = 0;
scrollToX (hbar->getValue());
break;
}
case FScrollbar::scrollWheelUp:
if ( xoffset == 0 )
break;
xoffset -= 4;
if ( xoffset < 0 )
xoffset = 0;
scrollBy (-wheel_distance, 0);
break;
case FScrollbar::scrollWheelDown:
if ( xoffset == xoffset_end )
break;
xoffset += 4;
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
scrollBy (-wheel_distance, 0);
break;
}
if ( isVisible() )
{
drawText();
updateTerminal();
}
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
{
hbar->setValue (xoffset);
if ( hbar->isVisible() && xoffset_before != xoffset )
hbar->drawBar();
updateTerminal();
}
update_scrollbar = true;
}

View File

@ -3,7 +3,7 @@
* *
* 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 *
* modify it under the terms of the GNU Lesser General Public License *
@ -499,13 +499,8 @@ void FToggleButton::draw()
//----------------------------------------------------------------------
void FToggleButton::drawLabel()
{
uInt length, i;
int hotkeypos;
FString txt;
wchar_t* LabelText;
register wchar_t* src;
register wchar_t* dest;
bool isActive, isNoUnderline;
int hotkeypos;
if ( ! isVisible() )
return;
@ -513,7 +508,7 @@ void FToggleButton::drawLabel()
if ( text.isNull() || text.isEmpty() )
return;
length = text.getLength();
uInt length = text.getLength();
hotkeypos = -1;
try
@ -526,62 +521,16 @@ void FToggleButton::drawLabel()
return;
}
txt = text;
src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(LabelText);
isActive = ((flags & fc::active) != 0);
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++;
}
FString txt = text;
wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
wchar_t* dest = const_cast<wchar_t*>(LabelText);
hotkeypos = getHotkeyPos(src, dest, uInt(length));
if ( hotkeypos != -1 )
length--;
setPrintPos (1 + label_offset_pos, 1);
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);
drawText (LabelText, hotkeypos, length);
delete[] LabelText;
}
@ -686,3 +635,64 @@ void FToggleButton::init()
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);;
}