2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fbuttongroup.cpp - The FButtonGroup widget organizes FToggleButton *
|
|
|
|
* widgets in a group. *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-01-02 20:38:45 +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/fbuttongroup.h"
|
|
|
|
#include "final/fstatusbar.h"
|
|
|
|
#include "final/ftogglebutton.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 FButtonGroup
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FButtonGroup::FButtonGroup(FWidget* parent)
|
2017-02-20 00:00:53 +01:00
|
|
|
: FScrollView(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
|
|
|
FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent)
|
2017-02-20 00:00:53 +01:00
|
|
|
: FScrollView(parent)
|
2018-12-03 03:22:36 +01:00
|
|
|
, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FButtonGroup::~FButtonGroup() // destructor
|
|
|
|
{
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
while ( iter != buttonlist.end() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->setGroup(0);
|
2015-05-23 13:35:12 +02:00
|
|
|
iter = buttonlist.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// public methods of FButtonGroup
|
2017-03-12 00:29:56 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-11-03 05:04:27 +01:00
|
|
|
FToggleButton* FButtonGroup::getButton (int index) const
|
2017-03-12 00:29:56 +01:00
|
|
|
{
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return 0;
|
|
|
|
|
2018-01-02 20:38:45 +01:00
|
|
|
if ( index <= 0 || index > int(getCount()) )
|
2017-03-12 00:29:56 +01:00
|
|
|
return 0;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
2018-01-02 20:38:45 +01:00
|
|
|
std::advance (iter, index - 1);
|
2017-03-12 00:29:56 +01:00
|
|
|
return static_cast<FToggleButton*>(*iter);
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
FToggleButton* FButtonGroup::getFirstButton()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = FWidget::getFirstFocusableWidget(buttonlist);
|
|
|
|
auto toggle_button = static_cast<FToggleButton*>(widget);
|
2017-01-28 22:03:15 +01:00
|
|
|
return toggle_button;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
FToggleButton* FButtonGroup::getLastButton()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = FWidget::getLastFocusableWidget(buttonlist);
|
|
|
|
auto toggle_button = static_cast<FToggleButton*>(widget);
|
2017-01-28 22:03:15 +01:00
|
|
|
return toggle_button;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FButtonGroup::setEnable (bool on)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::setEnable(on);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( on )
|
|
|
|
setHotkeyAccelerator();
|
|
|
|
else
|
|
|
|
delAccelerator();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return on;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FButtonGroup::setText (const FString& txt)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
text = txt;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-11-12 01:33:16 +01:00
|
|
|
delAccelerator();
|
2016-11-02 00:37:58 +01:00
|
|
|
setHotkeyAccelerator();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-12 00:29:56 +01:00
|
|
|
bool FButtonGroup::isChecked (int index) const
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto button = getButton(index);
|
2017-03-12 00:29:56 +01:00
|
|
|
|
|
|
|
if ( button )
|
|
|
|
return button->isChecked();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FButtonGroup::hasFocusedButton() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
|
|
|
auto last = buttonlist.end();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->hasFocus() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
++iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-12 00:29:56 +01:00
|
|
|
bool FButtonGroup::hasCheckedButton() const
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
|
|
|
auto last = buttonlist.end();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->isChecked() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
++iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::hide()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t size;
|
2018-11-13 02:51:41 +01:00
|
|
|
FColor fg, bg;
|
2015-05-23 13:35:12 +02:00
|
|
|
FWidget::hide();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto parent_widget = getParentWidget();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! buttonlist.empty() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
|
|
|
auto last = buttonlist.end();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->hide();
|
2015-05-23 13:35:12 +02:00
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
fg = parent_widget->getForegroundColor();
|
|
|
|
bg = parent_widget->getBackgroundColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fg = wc.dialog_fg;
|
|
|
|
bg = wc.dialog_bg;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
setColor (fg, bg);
|
2016-09-25 23:53:48 +02:00
|
|
|
size = getWidth();
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( size == 0 )
|
2016-09-25 23:53:48 +02:00
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto blank = createBlankArray(size + 1);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (int y = 0; y < int(getHeight()); y++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
FWidget::setPrintPos (1, 1 + y);
|
2015-05-23 13:35:12 +02:00
|
|
|
print (blank);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
destroyBlankArray (blank);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-12-21 18:48:38 +01:00
|
|
|
void FButtonGroup::insert (FToggleButton* button)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-08-21 22:47:45 +02:00
|
|
|
if ( ! button )
|
|
|
|
return;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( button->getGroup() )
|
|
|
|
button->getGroup()->remove(button);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
// setChecked the first FRadioButton
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( buttonlist.size() == 1 )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto first_button = static_cast<FToggleButton*>(*buttonlist.begin());
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( isRadioButton(first_button) )
|
|
|
|
first_button->setChecked();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
button->setGroup(this);
|
|
|
|
buttonlist.push_back(button);
|
|
|
|
|
|
|
|
button->addCallback
|
|
|
|
(
|
|
|
|
"toggled",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FButtonGroup::cb_buttonToggled)
|
2015-05-23 13:35:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-12-21 18:48:38 +01:00
|
|
|
void FButtonGroup::remove (FToggleButton* button)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-08-21 22:47:45 +02:00
|
|
|
if ( ! button || buttonlist.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
while ( iter != buttonlist.end() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button == button )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
iter = buttonlist.erase(iter);
|
|
|
|
button->setGroup(0);
|
|
|
|
button->delCallback(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 00:29:56 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::checkScrollSize (FToggleButton* button)
|
|
|
|
{
|
|
|
|
// Check and adjust the scroll size
|
|
|
|
|
|
|
|
checkScrollSize (button->getGeometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::checkScrollSize (const FRect& r)
|
|
|
|
{
|
|
|
|
// Check and adjust the scroll size
|
|
|
|
|
|
|
|
FRect scrollgeometry (1, 1, getScrollWidth(), getScrollHeight());
|
|
|
|
|
|
|
|
if ( ! scrollgeometry.contains(r) )
|
|
|
|
{
|
|
|
|
FRect new_size = scrollgeometry.combined(r);
|
|
|
|
setScrollSize (new_size.getWidth(), new_size.getHeight());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FButtonGroup::onMouseDown (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
directFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::onAccel (FAccelEvent*)
|
|
|
|
{
|
|
|
|
directFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
|
|
|
|
{
|
|
|
|
if ( hasCheckedButton() && ! buttonlist.empty() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
|
|
|
auto last = buttonlist.end();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->isChecked() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( isRadioButton(toggle_button) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto prev_element = getFocusWidget();
|
2017-03-12 00:29:56 +01:00
|
|
|
in_ev->ignore();
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-03-12 00:29:56 +01:00
|
|
|
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
|
|
|
FApplication::sendEvent(this, &cfi);
|
|
|
|
|
|
|
|
FFocusEvent in (fc::FocusIn_Event);
|
|
|
|
FApplication::sendEvent(toggle_button, &in);
|
|
|
|
|
2016-06-19 23:18:53 +02:00
|
|
|
if ( prev_element )
|
|
|
|
prev_element->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->redraw();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( in_ev->isAccepted() )
|
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
in_ev->ignore();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto prev_element = getFocusWidget();
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( in_ev->getFocusType() == fc::FocusNextWidget )
|
2015-05-23 13:35:12 +02:00
|
|
|
focusFirstChild();
|
2016-01-17 02:57:08 +01:00
|
|
|
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
|
2015-05-23 13:35:12 +02:00
|
|
|
focusLastChild();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( prev_element )
|
|
|
|
prev_element->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( getFocusWidget() )
|
|
|
|
getFocusWidget()->redraw();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
getStatusBar()->drawMessage();
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FButtonGroup::cb_buttonToggled (FWidget* widget, data_ptr)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto button = static_cast<FToggleButton*>(widget);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! button->isChecked() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
|
|
|
auto last = buttonlist.end();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button != button
|
2017-11-26 22:37:18 +01:00
|
|
|
&& toggle_button->isChecked()
|
|
|
|
&& isRadioButton(toggle_button) )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->unsetChecked();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( toggle_button->isVisible() && toggle_button->isShown() )
|
|
|
|
toggle_button->redraw();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// protected methods of FButtonGroup
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
uChar FButtonGroup::getHotkey()
|
|
|
|
{
|
|
|
|
if ( text.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t length = text.getLength();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (std::size_t i = 0; i < length; i++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
try
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
if ( i + 1 < length && text[i] == '&' )
|
2016-11-02 00:37:58 +01:00
|
|
|
return uChar(text[++i]);
|
|
|
|
}
|
|
|
|
catch (const std::out_of_range&)
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
return 0;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::setHotkeyAccelerator()
|
|
|
|
{
|
2018-11-21 20:07:08 +01:00
|
|
|
uChar hotkey = getHotkey();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( hotkey )
|
|
|
|
{
|
|
|
|
if ( std::isalpha(hotkey) || std::isdigit(hotkey) )
|
|
|
|
{
|
2018-11-21 20:07:08 +01:00
|
|
|
addAccelerator (FKey(std::tolower(hotkey)));
|
|
|
|
addAccelerator (FKey(std::toupper(hotkey)));
|
2016-11-02 00:37:58 +01:00
|
|
|
// Meta + hotkey
|
2018-11-21 20:07:08 +01:00
|
|
|
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(hotkey)));
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
addAccelerator (getHotkey());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delAccelerator();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FButtonGroup::draw()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
|
|
|
setColor();
|
2017-02-20 00:00:53 +01:00
|
|
|
clearArea();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2017-02-20 00:00:53 +01:00
|
|
|
|
|
|
|
FScrollView::draw();
|
|
|
|
drawLabel();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::drawLabel()
|
|
|
|
{
|
|
|
|
wchar_t* LabelText;
|
|
|
|
|
|
|
|
if ( text.isNull() || text.isEmpty() )
|
|
|
|
return;
|
|
|
|
|
2018-02-17 19:12:48 +01:00
|
|
|
FString txt = " " + text + " ";
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t length = txt.getLength();
|
2017-08-12 22:55:29 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
LabelText = new wchar_t[length + 1]();
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-17 19:12:48 +01:00
|
|
|
wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
|
|
|
|
wchar_t* dest = const_cast<wchar_t*>(LabelText);
|
2017-02-20 00:00:53 +01:00
|
|
|
unsetViewportPrint();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto hotkeypos = getHotkeyPos(src, dest, length);
|
2018-02-17 19:12:48 +01:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( hotkeypos != NOT_SET )
|
2018-02-17 19:12:48 +01:00
|
|
|
length--;
|
|
|
|
|
|
|
|
if ( hasBorder() )
|
|
|
|
FWidget::setPrintPos (2, 1);
|
|
|
|
else
|
|
|
|
FWidget::setPrintPos (0, 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-02-17 19:12:48 +01:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
setForegroundColor (wc.label_fg);
|
|
|
|
setBackgroundColor (wc.label_bg);
|
|
|
|
setMinimumSize (7, 4);
|
|
|
|
buttonlist.clear(); // no buttons yet
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-17 22:12:52 +02:00
|
|
|
std::size_t FButtonGroup::getHotkeyPos ( wchar_t src[]
|
|
|
|
, wchar_t dest[]
|
|
|
|
, std::size_t length )
|
2018-02-17 19:12:48 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
// find hotkey position in string
|
|
|
|
// + generate a new string without the '&'-sign
|
2018-10-18 23:50:06 +02:00
|
|
|
std::size_t pos = NOT_SET;
|
2018-02-17 19:12:48 +01:00
|
|
|
wchar_t* txt = src;
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
for (std::size_t i = 0; i < length; i++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( i < length && txt[i] == L'&' && pos == NOT_SET )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-10-17 22:12:52 +02:00
|
|
|
pos = i;
|
2016-11-02 00:37:58 +01:00
|
|
|
i++;
|
|
|
|
src++;
|
|
|
|
}
|
2017-11-03 05:04:27 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
|
2018-02-17 19:12:48 +01:00
|
|
|
return pos;
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-02-17 19:12:48 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FButtonGroup::drawText ( wchar_t LabelText[]
|
2018-10-17 22:12:52 +02:00
|
|
|
, std::size_t hotkeypos
|
2018-10-14 06:25:33 +02:00
|
|
|
, std::size_t length )
|
2018-02-17 19:12:48 +01:00
|
|
|
{
|
2017-12-25 21:17:08 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
|
|
|
setColor(wc.label_emphasis_fg, wc.label_bg);
|
|
|
|
else
|
|
|
|
setColor(wc.label_inactive_fg, wc.label_inactive_bg);
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
for (std::size_t z = 0; z < length; z++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( (z == hotkeypos) && flags.active )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
|
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( ! flags.no_underline )
|
2016-11-02 00:37:58 +01:00
|
|
|
setUnderline();
|
|
|
|
|
2018-10-17 22:12:52 +02:00
|
|
|
print (LabelText[z]);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-11-04 23:00:06 +01:00
|
|
|
if ( ! flags.no_underline )
|
2016-11-02 00:37:58 +01:00
|
|
|
unsetUnderline();
|
|
|
|
|
|
|
|
setColor (wc.label_emphasis_fg, wc.label_bg);
|
|
|
|
}
|
|
|
|
else
|
2018-10-17 22:12:52 +02:00
|
|
|
print (LabelText[z]);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2017-12-25 21:17:08 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::directFocus()
|
|
|
|
{
|
|
|
|
if ( ! hasFocusedButton() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
bool found_checked = false;
|
|
|
|
|
|
|
|
if ( hasCheckedButton() && ! buttonlist.empty() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
|
|
|
auto last = buttonlist.end();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->isChecked() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( isRadioButton(toggle_button) )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
found_checked = true;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->setFocus();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
|
|
|
|
focused_widget = getFocusWidget();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! found_checked )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
2016-11-02 00:37:58 +01:00
|
|
|
focusFirstChild();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
|
|
|
|
focused_widget = getFocusWidget();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|