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
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// 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-09-22 04:18:20 +02:00
|
|
|
, text()
|
|
|
|
, buttonlist()
|
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)
|
2015-09-22 04:18:20 +02:00
|
|
|
, text(txt)
|
|
|
|
, buttonlist()
|
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
|
|
|
|
{
|
2017-09-15 01:31:02 +02:00
|
|
|
FObjectIterator iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
iter = buttonlist.begin();
|
|
|
|
|
|
|
|
while ( iter != buttonlist.end() )
|
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
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
|
|
|
{
|
2017-09-15 01:31:02 +02:00
|
|
|
constFObjectIterator iter;
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FWidget* widget = FWidget::getFirstFocusableWidget(buttonlist);
|
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(widget);
|
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FWidget* widget = FWidget::getLastFocusableWidget(buttonlist);
|
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(widget);
|
|
|
|
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
|
|
|
|
{
|
|
|
|
FToggleButton* button = getButton(index);
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
constFObjectIterator iter, last;
|
2016-11-02 00:37:58 +01:00
|
|
|
iter = buttonlist.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
constFObjectIterator iter, last;
|
2016-11-02 00:37:58 +01:00
|
|
|
iter = buttonlist.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
int size;
|
|
|
|
short fg, bg;
|
2015-05-23 13:35:12 +02:00
|
|
|
char* blank;
|
|
|
|
FWidget::hide();
|
2016-08-21 21:27:44 +02:00
|
|
|
FWidget* parent_widget = getParentWidget();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! buttonlist.empty() )
|
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
constFObjectIterator iter, last;
|
2015-05-23 13:35:12 +02:00
|
|
|
iter = buttonlist.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
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();
|
|
|
|
|
|
|
|
if ( size < 0 )
|
|
|
|
return;
|
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
blank = new char[size + 1];
|
2017-08-12 22:55:29 +02:00
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-06 23:15:09 +02:00
|
|
|
std::memset(blank, ' ', uLong(size));
|
2015-05-23 13:35:12 +02:00
|
|
|
blank[size] = '\0';
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int y = 0; y < 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
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
delete[] blank;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
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 )
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
FToggleButton* first_button;
|
|
|
|
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
|
|
|
{
|
2017-09-15 01:31:02 +02:00
|
|
|
FObjectIterator iter;
|
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;
|
|
|
|
|
|
|
|
iter = buttonlist.begin();
|
|
|
|
|
|
|
|
while ( iter != buttonlist.end() )
|
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
|
|
|
|
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() )
|
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
constFObjectIterator iter, last;
|
2015-05-23 13:35:12 +02:00
|
|
|
iter = buttonlist.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
FWidget* 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();
|
|
|
|
FWidget* prev_element = getFocusWidget();
|
|
|
|
|
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
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FToggleButton* button = static_cast<FToggleButton*>(widget);
|
2017-09-17 01:50:41 +02:00
|
|
|
constFObjectIterator iter, last;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! button->isChecked() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
iter = buttonlist.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
uInt length;
|
|
|
|
|
|
|
|
if ( text.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
length = text.getLength();
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt 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()
|
|
|
|
{
|
|
|
|
int hotkey = getHotkey();
|
|
|
|
|
|
|
|
if ( hotkey )
|
|
|
|
{
|
|
|
|
if ( std::isalpha(hotkey) || std::isdigit(hotkey) )
|
|
|
|
{
|
|
|
|
addAccelerator (std::tolower(hotkey));
|
|
|
|
addAccelerator (std::toupper(hotkey));
|
|
|
|
// Meta + hotkey
|
|
|
|
addAccelerator (fc::Fmkey_meta + std::tolower(hotkey));
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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();
|
|
|
|
hotkeypos = -1;
|
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)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
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);
|
2017-02-20 00:00:53 +01:00
|
|
|
unsetViewportPrint();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// find hotkey position in string
|
|
|
|
// + generate a new string without the '&'-sign
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt i = 0; i < length; i++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
if ( (i < length) && (txt[i] == '&') && (hotkeypos == -1) )
|
|
|
|
{
|
|
|
|
hotkeypos = int(i);
|
|
|
|
i++;
|
|
|
|
src++;
|
|
|
|
}
|
2017-11-03 05:04:27 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hotkeypos != -1 )
|
|
|
|
length--;
|
|
|
|
|
2017-02-20 00:00:53 +01:00
|
|
|
if ( hasBorder() )
|
|
|
|
FWidget::setPrintPos (2, 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2017-02-20 00:00:53 +01:00
|
|
|
FWidget::setPrintPos (0, 1);
|
2016-07-09 00:01:59 +02: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);
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int z = 0; z < int(length); z++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
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_emphasis_fg, wc.label_bg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print ( LabelText[z] );
|
|
|
|
}
|
|
|
|
|
2017-12-25 21:17:08 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2017-02-20 00:00:53 +01:00
|
|
|
setViewportPrint();
|
2016-11-02 00:37:58 +01:00
|
|
|
delete[] LabelText;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// private methods of FButtonGroup
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-20 00:00:53 +01:00
|
|
|
bool FButtonGroup::isRadioButton (FToggleButton* button) const
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! button )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return bool ( std::strcmp ( button->getClassName()
|
2017-12-17 01:06:53 +01:00
|
|
|
, C_STR("FRadioButton") ) == 0 );
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::init()
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( isEnabled() )
|
2016-11-02 00:37:58 +01:00
|
|
|
flags |= fc::active;
|
|
|
|
|
|
|
|
setForegroundColor (wc.label_fg);
|
|
|
|
setBackgroundColor (wc.label_bg);
|
2017-02-20 00:00:53 +01:00
|
|
|
setMinimumSize (7, 4);
|
2016-11-02 00:37:58 +01:00
|
|
|
buttonlist.clear(); // no buttons yet
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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() )
|
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
constFObjectIterator iter, last;
|
2016-11-02 00:37:58 +01:00
|
|
|
iter = buttonlist.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
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
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
|
|
|
|
|
|
|
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;
|
|
|
|
FWidget* focused_widget = getFocusWidget();
|
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
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 )
|
|
|
|
{
|
|
|
|
FWidget* focused_widget = getFocusWidget();
|
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|