finalcut/examples/choice.cpp

164 lines
5.8 KiB
C++
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* choice.cpp - FButtonGroup with scroll view *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2017-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/>. *
***********************************************************************/
2017-03-12 00:29:56 +01:00
2018-11-20 21:11:04 +01:00
#include <vector>
#include <final/final.h>
2018-12-19 22:04:02 +01:00
// Typedef
typedef std::shared_ptr<finalcut::FRadioButton> FRadioButtonPtr;
2017-03-12 00:29:56 +01:00
2018-12-19 22:04:02 +01:00
// Function prototypes
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr);
2018-12-19 22:04:02 +01:00
void populateChoice (std::vector<FRadioButtonPtr>&, finalcut::FButtonGroup&);
void preset (std::vector<FRadioButtonPtr>&);
2017-03-12 00:29:56 +01:00
//----------------------------------------------------------------------
2018-12-19 22:04:02 +01:00
// Callback functions
2017-03-12 00:29:56 +01:00
//----------------------------------------------------------------------
void cb_quit (finalcut::FWidget*, finalcut::FWidget::data_ptr data)
2017-03-12 00:29:56 +01:00
{
auto dlg = static_cast<finalcut::FDialog*>(data);
2017-03-12 00:29:56 +01:00
dlg->close();
}
2018-02-24 18:13:42 +01:00
//----------------------------------------------------------------------
2018-12-19 22:04:02 +01:00
void populateChoice ( std::vector<FRadioButtonPtr>& os
, finalcut::FButtonGroup& group )
2018-02-24 18:13:42 +01:00
{
2018-12-19 22:04:02 +01:00
os[0] = std::make_shared<finalcut::FRadioButton>("AIX", &group);
os[1] = std::make_shared<finalcut::FRadioButton>("Cygwin", &group);
os[2] = std::make_shared<finalcut::FRadioButton>("FreeBSD", &group);
os[3] = std::make_shared<finalcut::FRadioButton>("HP-UX", &group);
os[4] = std::make_shared<finalcut::FRadioButton>("Linux", &group);
os[5] = std::make_shared<finalcut::FRadioButton>("Mac OS X", &group);
os[6] = std::make_shared<finalcut::FRadioButton>("NetBSD", &group);
os[7] = std::make_shared<finalcut::FRadioButton>("OpenBSD", &group);
os[8] = std::make_shared<finalcut::FRadioButton>("Solaris", &group);
2018-02-24 18:13:42 +01:00
}
//----------------------------------------------------------------------
2018-12-19 22:04:02 +01:00
void preset (std::vector<FRadioButtonPtr>& os)
2018-02-24 18:13:42 +01:00
{
#if defined(_AIX)
os[0]->setChecked();
os[0]->setFocus();
#elif defined(__CYGWIN__)
os[1]->setChecked();
os[1]->setFocus();
#elif defined(__FreeBSD__)
os[2]->setChecked();
os[2]->setFocus();
#elif defined(__hpux)
os[3]->setChecked();
os[3]->setFocus();
#elif defined(__linux__)
os[4]->setChecked();
os[4]->setFocus();
#elif defined(__APPLE__) && defined(__MACH__)
os[5]->setChecked();
os[5]->setFocus();
#elif defined(__NetBSD__)
os[6]->setChecked();
os[6]->setFocus();
#elif defined(__OpenBSD__)
os[7]->setChecked();
os[7]->setFocus();
#elif defined(__sun) && defined(__SVR4)
os[8]->setChecked();
os[8]->setFocus();
#endif
}
2017-03-12 00:29:56 +01:00
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
finalcut::FString label_text = "no OS";
2017-03-12 00:29:56 +01:00
// Create the application object
finalcut::FApplication app(argc, argv);
2017-03-12 00:29:56 +01:00
{ // Create a simple modal dialog box in this scope
finalcut::FDialog dgl(&app);
dgl.setModal();
dgl.setText ("UNIX select");
std::size_t w = 20;
std::size_t h = 13;
int x = int(app.getDesktopWidth() - w) / 2;
int y = int(app.getDesktopHeight() - h) / 2;
dgl.setGeometry (x, y, w, h);
// Create a button group
finalcut::FButtonGroup checkButtonGroup("choice", &dgl);
checkButtonGroup.setGeometry (2, 1, 16, 7);
// Create radio buttons
std::vector<FRadioButtonPtr> os(9);
2018-12-19 22:04:02 +01:00
populateChoice (os, checkButtonGroup);
// Set the radio button geometry
// => checkButtonGroup.setScrollSize(...) is not required
// because a FButtonGroup is self-adjusting
for (uInt i = 0; i < os.size(); i++)
os[i]->setGeometry(1, int(1 + i), 12, 1);
preset(os);
// Scroll to the focused child element
finalcut::FFocusEvent cfi (finalcut::fc::ChildFocusIn_Event);
2018-12-17 02:06:22 +01:00
finalcut::FApplication::queueEvent(&checkButtonGroup, &cfi);
// Create a OK button
finalcut::FButton ok("&OK", &dgl);
ok.setGeometry (10, 9, 8, 1);
// Connect the button signal "clicked" with the callback function
ok.addCallback
(
"clicked",
F_FUNCTION_CALLBACK (&cb_quit),
&dgl
);
// Show the dialog
dgl.show();
// Get the checked radio button text
for (int n = 1; n <= int(checkButtonGroup.getCount()); n++)
2017-03-12 00:29:56 +01:00
{
if ( checkButtonGroup.isChecked(n) )
{
label_text = checkButtonGroup.getButton(n)->getText();
break;
}
2017-03-12 00:29:56 +01:00
}
} // Hide and destroy the dialog object
2017-03-12 00:29:56 +01:00
// Create and show tooltip for two seconds
finalcut::FToolTip tooltip(&app);
tooltip.setText ("You have chosen " + label_text);
tooltip.show();
2017-03-12 00:29:56 +01:00
sleep(2);
}