2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* flabel.cpp - Widget FLabel *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-01-30 00:11:58 +01:00
|
|
|
* Copyright 2014-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
|
|
|
#include "final/flabel.h"
|
|
|
|
#include "final/fstatusbar.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FLabel
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FLabel::FLabel(FWidget* parent)
|
|
|
|
: FWidget(parent)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FLabel::FLabel (const FString& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
setText(txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
FLabel::~FLabel() // destructor
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-11-12 01:33:16 +01:00
|
|
|
delAccelerator();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2017-09-20 05:44:41 +02:00
|
|
|
// FLabel operators
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator = (const FString& s)
|
|
|
|
{
|
|
|
|
setText(s);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const FString& s)
|
|
|
|
{
|
|
|
|
setText(text + s);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-06 02:28:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (fc::SpecialCharacter c)
|
|
|
|
{
|
|
|
|
setText(text + static_cast<wchar_t>(c));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-09-20 05:44:41 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const wchar_t c)
|
|
|
|
{
|
|
|
|
setText(text + c);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const uInt num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const int num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const uLong num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const long num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const float num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const double num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FLabel& FLabel::operator << (const lDouble num)
|
|
|
|
{
|
|
|
|
FString num_str;
|
|
|
|
num_str << num;
|
|
|
|
setText(text + num_str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
const FLabel& FLabel::operator >> (FString& s)
|
|
|
|
{
|
|
|
|
s += text;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FLabel
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::setAccelWidget (FWidget* widget)
|
|
|
|
{
|
|
|
|
if ( widget )
|
|
|
|
accel_widget = widget;
|
|
|
|
|
|
|
|
accel_widget->addCallback
|
|
|
|
(
|
|
|
|
"destroy",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FLabel::cb_accel_widget_destroyed)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-07-23 01:19:59 +02:00
|
|
|
void FLabel::setAlignment (fc::text_alignment align)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( align != fc::alignLeft
|
2017-11-26 22:37:18 +01:00
|
|
|
&& align != fc::alignCenter
|
|
|
|
&& align != fc::alignRight )
|
2016-11-02 00:37:58 +01:00
|
|
|
alignment = fc::alignLeft;
|
|
|
|
else
|
|
|
|
alignment = align;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FLabel::setEmphasis (bool on)
|
|
|
|
{
|
|
|
|
if ( emphasis != on )
|
|
|
|
emphasis = on;
|
|
|
|
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FLabel::setReverseMode (bool on)
|
|
|
|
{
|
|
|
|
if ( reverse_mode != on )
|
|
|
|
reverse_mode = on;
|
|
|
|
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FLabel::setEnable (bool on)
|
|
|
|
{
|
|
|
|
FWidget::setEnable(on);
|
|
|
|
|
|
|
|
if ( on )
|
|
|
|
setHotkeyAccelerator();
|
|
|
|
else
|
|
|
|
delAccelerator();
|
|
|
|
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::setText (const FString& txt)
|
|
|
|
{
|
|
|
|
text = txt;
|
|
|
|
multiline_text = text.split("\r\n");
|
|
|
|
|
|
|
|
if ( int(multiline_text.size()) > 1 )
|
|
|
|
multiline = true;
|
|
|
|
else
|
|
|
|
multiline = false;
|
|
|
|
|
|
|
|
if ( isEnabled() )
|
|
|
|
{
|
|
|
|
delAccelerator();
|
|
|
|
setHotkeyAccelerator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::hide()
|
|
|
|
{
|
2018-11-13 02:51:41 +01:00
|
|
|
FColor fg, bg;
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t size;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto parent_widget = getParentWidget();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
FWidget::hide();
|
|
|
|
|
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
fg = parent_widget->getForegroundColor();
|
|
|
|
bg = parent_widget->getBackgroundColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fg = wc.dialog_fg;
|
|
|
|
bg = wc.dialog_bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
setColor (fg, bg);
|
|
|
|
size = getWidth();
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( size == 0 )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto blank = createBlankArray(size + 1);
|
2018-10-14 06:25:33 +02:00
|
|
|
setPrintPos (1, 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
print (blank);
|
2018-10-20 22:50:35 +02:00
|
|
|
destroyBlankArray (blank);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::onMouseDown (FMouseEvent* ev)
|
|
|
|
{
|
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! (isEnabled() && accel_widget) )
|
|
|
|
{
|
|
|
|
// send click to the parent widget
|
2018-12-15 00:50:09 +01:00
|
|
|
if ( auto parent = getParentWidget() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
int b = ev->getButton();
|
|
|
|
const FPoint& tp = ev->getTermPos();
|
|
|
|
const FPoint& p = parent->termToWidgetPos(tp);
|
2017-08-12 22:55:29 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2018-12-19 22:04:02 +01:00
|
|
|
const auto& _ev = \
|
|
|
|
std::make_shared<FMouseEvent>(fc::MouseDown_Event, p, tp, b);
|
|
|
|
FApplication::sendEvent (parent, _ev.get());
|
2017-08-12 22:55:29 +02:00
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
2018-11-22 21:51:32 +01:00
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
2017-08-12 22:55:29 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! accel_widget->hasFocus() )
|
|
|
|
{
|
|
|
|
// focus the accelerator widget
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
2016-11-02 00:37:58 +01:00
|
|
|
accel_widget->setFocus();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
|
|
|
|
accel_widget->redraw();
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
|
|
|
accel_widget->getStatusBar()->drawMessage();
|
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
|
|
|
if ( ! (isEnabled() && accel_widget) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! accel_widget->hasFocus() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = static_cast<FWidget*>(ev->focusedWidget());
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-06-14 01:23:10 +02:00
|
|
|
if ( focused_widget && focused_widget->isWidget() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-06-11 17:47:50 +02:00
|
|
|
accel_widget->setFocus();
|
2017-06-14 01:23:10 +02:00
|
|
|
focused_widget->redraw();
|
2017-06-11 17:47:50 +02:00
|
|
|
accel_widget->redraw();
|
|
|
|
FFocusEvent in (fc::FocusIn_Event);
|
|
|
|
FApplication::sendEvent(accel_widget, &in);
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
|
|
|
accel_widget->getStatusBar()->drawMessage();
|
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FLabel::cb_accel_widget_destroyed (FWidget*, data_ptr)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-12-10 01:48:26 +01:00
|
|
|
accel_widget = nullptr;
|
2016-11-02 00:37:58 +01:00
|
|
|
delAccelerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// private methods of FLabel
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::init()
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto parent_widget = getParentWidget();
|
2015-05-23 13:35:12 +02:00
|
|
|
unsetFocusable();
|
2016-08-21 21:27:44 +02:00
|
|
|
|
|
|
|
if ( parent_widget )
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
setForegroundColor (parent_widget->getForegroundColor());
|
|
|
|
setBackgroundColor (parent_widget->getBackgroundColor());
|
2016-08-21 21:27:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
setForegroundColor (wc.dialog_fg);
|
|
|
|
setBackgroundColor (wc.dialog_bg);
|
2016-08-21 21:27:44 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
uChar FLabel::getHotkey()
|
|
|
|
{
|
|
|
|
if ( text.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t length = text.getLength();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (std::size_t i = 0; i < length; i++)
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
if ( i + 1 < length && text[i] == '&' )
|
2015-09-30 22:39:02 +02:00
|
|
|
return uChar(text[++i]);
|
|
|
|
}
|
|
|
|
catch (const std::out_of_range&)
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
return 0;
|
2015-09-30 22:39:02 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-18 21:31:26 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-17 22:12:52 +02:00
|
|
|
std::size_t FLabel::getHotkeyPos ( wchar_t src[]
|
|
|
|
, wchar_t dest[]
|
|
|
|
, std::size_t length )
|
2015-07-18 21:31:26 +02:00
|
|
|
{
|
|
|
|
// find hotkey position in string
|
|
|
|
// + generate a new string without the '&'-sign
|
2018-10-18 23:50:06 +02:00
|
|
|
std::size_t hotkeypos = NOT_SET;
|
2015-07-18 21:31:26 +02:00
|
|
|
wchar_t* txt = src;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (std::size_t i = 0; i < length; i++)
|
2015-07-18 21:31:26 +02:00
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( i < length && txt[i] == L'&' && hotkeypos == NOT_SET )
|
2015-07-18 21:31:26 +02:00
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
hotkeypos = i;
|
2015-07-18 21:31:26 +02:00
|
|
|
i++;
|
|
|
|
src++;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-07-18 21:31:26 +02:00
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-07-18 21:31:26 +02:00
|
|
|
return hotkeypos;
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::setHotkeyAccelerator()
|
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
uChar hotkey = getHotkey();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( hotkey )
|
|
|
|
{
|
2016-10-06 23:15:09 +02:00
|
|
|
if ( std::isalpha(hotkey) || std::isdigit(hotkey) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-11-21 20:07:08 +01:00
|
|
|
addAccelerator (FKey(std::tolower(hotkey)));
|
|
|
|
addAccelerator (FKey(std::toupper(hotkey)));
|
2015-05-23 13:35:12 +02:00
|
|
|
// Meta + hotkey
|
2018-11-21 20:07:08 +01:00
|
|
|
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(hotkey)));
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
2015-11-12 01:33:16 +01:00
|
|
|
addAccelerator (getHotkey());
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
2015-11-12 01:33:16 +01:00
|
|
|
delAccelerator();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t FLabel::getAlignOffset (std::size_t length)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t width = std::size_t(getWidth());
|
|
|
|
|
2015-07-18 21:31:26 +02:00
|
|
|
switch ( alignment )
|
|
|
|
{
|
|
|
|
case fc::alignLeft:
|
|
|
|
return 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-07-18 21:31:26 +02:00
|
|
|
case fc::alignCenter:
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( length < width )
|
2018-10-17 22:12:52 +02:00
|
|
|
return (width - length) / 2;
|
2015-07-18 21:31:26 +02:00
|
|
|
else
|
|
|
|
return 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-07-18 21:31:26 +02:00
|
|
|
case fc::alignRight:
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( length < width )
|
|
|
|
return width - length;
|
2015-07-18 21:31:26 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-28 22:18:42 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-18 21:31:26 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-01-30 00:11:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::draw()
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
{
|
|
|
|
setReverse(true);
|
|
|
|
|
|
|
|
if ( hasEmphasis() )
|
|
|
|
setBold(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasEmphasis() )
|
|
|
|
setColor (emphasis_color, getBackgroundColor());
|
|
|
|
else
|
|
|
|
setColor();
|
|
|
|
|
|
|
|
// Draw the text
|
|
|
|
if ( multiline && getHeight() >= 2 )
|
|
|
|
drawMultiLine();
|
|
|
|
else
|
|
|
|
drawSingleLine();
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
{
|
|
|
|
setReverse(false);
|
|
|
|
|
|
|
|
if ( hasEmphasis() )
|
|
|
|
setBold(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::drawMultiLine()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t y = 0;
|
|
|
|
std::size_t text_lines = multiline_text.size();
|
2018-01-31 23:37:03 +01:00
|
|
|
bool hotkey_printed = false;
|
2018-01-30 00:11:58 +01:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
while ( y < text_lines && y < std::size_t(getHeight()) )
|
2018-01-30 00:11:58 +01:00
|
|
|
{
|
|
|
|
wchar_t* label_text;
|
2018-10-18 23:50:06 +02:00
|
|
|
std::size_t hotkeypos = NOT_SET;
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t align_offset;
|
|
|
|
std::size_t length = multiline_text[y].getLength();
|
2018-01-30 00:11:58 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
label_text = new wchar_t[length + 1]();
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
2018-11-22 21:51:32 +01:00
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
2018-01-30 00:11:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto src = const_cast<wchar_t*>(multiline_text[y].wc_str());
|
|
|
|
auto dest = const_cast<wchar_t*>(label_text);
|
2018-01-30 00:11:58 +01:00
|
|
|
|
|
|
|
if ( ! hotkey_printed )
|
|
|
|
hotkeypos = getHotkeyPos(src, dest, length);
|
|
|
|
else
|
|
|
|
std::wcsncpy(dest, src, length);
|
|
|
|
|
|
|
|
setPrintPos (1, 1 + int(y));
|
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( hotkeypos != NOT_SET )
|
2018-01-30 00:11:58 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
align_offset = getAlignOffset(length - 1);
|
2018-01-30 00:11:58 +01:00
|
|
|
printLine (label_text, length - 1, hotkeypos, align_offset);
|
|
|
|
hotkey_printed = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
align_offset = getAlignOffset(length);
|
2018-10-18 23:50:06 +02:00
|
|
|
printLine (label_text, length, NOT_SET, align_offset);
|
2018-01-30 00:11:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
y++;
|
|
|
|
delete[] label_text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FLabel::drawSingleLine()
|
|
|
|
{
|
|
|
|
wchar_t* label_text;
|
2018-10-18 23:50:06 +02:00
|
|
|
std::size_t hotkeypos = NOT_SET;
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t align_offset;
|
|
|
|
std::size_t length = text.getLength();
|
2018-01-30 00:11:58 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
label_text = new wchar_t[length + 1]();
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
2018-11-22 21:51:32 +01:00
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
2018-01-30 00:11:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hotkeypos = getHotkeyPos (text.wc_str(), label_text, length);
|
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( hotkeypos != NOT_SET )
|
2018-01-30 00:11:58 +01:00
|
|
|
length--;
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
setPrintPos (1, 1);
|
2018-10-14 06:25:33 +02:00
|
|
|
align_offset = getAlignOffset(length);
|
2018-01-30 00:11:58 +01:00
|
|
|
printLine (label_text, length, hotkeypos, align_offset);
|
|
|
|
delete[] label_text;
|
|
|
|
}
|
|
|
|
|
2015-07-18 21:31:26 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-12-19 02:06:27 +01:00
|
|
|
void FLabel::printLine ( wchar_t line[]
|
2018-10-14 06:25:33 +02:00
|
|
|
, std::size_t length
|
2018-10-17 22:12:52 +02:00
|
|
|
, std::size_t hotkeypos
|
|
|
|
, std::size_t align_offset )
|
2015-07-18 21:31:26 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t to_char;
|
|
|
|
std::size_t width = std::size_t(getWidth());
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-07-28 22:18:42 +02:00
|
|
|
if ( align_offset > 0 )
|
|
|
|
print (FString(align_offset, ' ')); // leading spaces
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( length <= width )
|
|
|
|
to_char = length;
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2018-10-14 06:25:33 +02:00
|
|
|
to_char = width - 2;
|
2015-05-26 23:15:49 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( hasReverseMode() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (std::size_t z = 0; z < to_char; z++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-10-06 23:15:09 +02:00
|
|
|
if ( ! std::iswprint(wint_t(line[z])) )
|
2015-10-17 21:05:49 +02:00
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ! isNewFont() && ( int(line[z]) < fc::NF_rev_left_arrow2
|
2017-11-26 22:37:18 +01:00
|
|
|
|| int(line[z]) > fc::NF_check_mark ) )
|
2015-10-17 21:05:49 +02:00
|
|
|
{
|
|
|
|
line[z] = L' ';
|
|
|
|
}
|
|
|
|
}
|
2017-11-26 22:37:18 +01:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( z == hotkeypos && flags.active )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( ! flags.no_underline )
|
2015-05-23 13:35:12 +02:00
|
|
|
setUnderline();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
print (line[z]);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( ! flags.no_underline )
|
2015-05-23 13:35:12 +02:00
|
|
|
unsetUnderline();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( hasEmphasis() )
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor (emphasis_color, getBackgroundColor());
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
2018-10-17 22:12:52 +02:00
|
|
|
print (line[z]);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( length > width )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
// Print ellipsis
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor (ellipsis_color, getBackgroundColor());
|
2015-05-23 13:35:12 +02:00
|
|
|
print ("..");
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( align_offset + to_char < width )
|
2015-07-18 21:31:26 +02:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
// Print trailing spaces
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t len = width - align_offset - to_char;
|
2017-12-21 00:25:58 +01:00
|
|
|
print (FString(len, ' '));
|
2015-07-18 21:31:26 +02:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( hasReverseMode() )
|
|
|
|
setReverse(false);
|
2015-07-18 21:31:26 +02:00
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|