2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* listbox.cpp - Example for using a FListBox widget *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-09-20 23:59:01 +02:00
|
|
|
* 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-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2017-04-23 18:54:46 +02:00
|
|
|
#include <fstream>
|
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2017-05-19 22:16:50 +02:00
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// Global application object
|
2018-09-20 23:59:01 +02:00
|
|
|
static finalcut::FString* temp_str = 0;
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// Function prototypes
|
2018-09-20 23:59:01 +02:00
|
|
|
void doubleToItem ( finalcut::FListBoxItem&
|
|
|
|
, finalcut::FWidget::data_ptr container
|
|
|
|
, int index) ;
|
|
|
|
finalcut::FString& doubleToString (std::list<double>::const_iterator iter);
|
|
|
|
finalcut::FString& mapToString ( std::map<finalcut::FString
|
|
|
|
, finalcut::FString>::const_iterator iter );
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-05-19 22:16:50 +02:00
|
|
|
// Lazy conversion import function
|
2018-09-20 23:59:01 +02:00
|
|
|
void doubleToItem ( finalcut::FListBoxItem& item
|
|
|
|
, finalcut::FWidget::data_ptr container, int index)
|
2017-05-19 22:16:50 +02:00
|
|
|
{
|
|
|
|
typedef std::list<double>* double_list_ptr;
|
|
|
|
double_list_ptr dbllist = static_cast<double_list_ptr>(container);
|
|
|
|
std::list<double>::iterator iter = dbllist->begin();
|
|
|
|
std::advance (iter, index);
|
2018-09-20 23:59:01 +02:00
|
|
|
item.setText (finalcut::FString() << *iter);
|
|
|
|
item.setData (finalcut::FWidget::data_ptr(&(*iter)));
|
2017-05-19 22:16:50 +02:00
|
|
|
}
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
// Import converter functions
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString& doubleToString (std::list<double>::const_iterator iter)
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
|
|
|
return temp_str->setNumber(*iter);
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString& mapToString ( std::map<finalcut::FString
|
|
|
|
, finalcut::FString>::const_iterator iter )
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
|
|
|
return *temp_str = iter->first + ": " + iter->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Listbox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
class Listbox : public finalcut::FDialog
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
explicit Listbox (FWidget* = 0);
|
|
|
|
// Destructor
|
|
|
|
~Listbox();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
|
|
|
Listbox (const Listbox&);
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
Listbox& operator = (const Listbox&);
|
|
|
|
|
|
|
|
// Event handlers
|
2018-09-20 23:59:01 +02:00
|
|
|
void onClose (finalcut::FCloseEvent*);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Data Member
|
|
|
|
std::list<double>* double_list;
|
2017-04-23 18:54:46 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Listbox::Listbox (finalcut::FWidget* parent)
|
|
|
|
: finalcut::FDialog(parent)
|
2017-05-19 22:16:50 +02:00
|
|
|
, double_list()
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
temp_str = new finalcut::FString;
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// listbox 1
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FListBox* list1 = new finalcut::FListBox (this);
|
2017-04-23 18:54:46 +02:00
|
|
|
list1->setGeometry(2, 1, 18, 10);
|
|
|
|
list1->setText ("FListBoxItem");
|
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
for (int i = 1; i < 30; i++)
|
2018-09-20 23:59:01 +02:00
|
|
|
list1->insert (L"----- " + (finalcut::FString() << i) + L" -----");
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// listbox 2
|
2017-05-19 22:47:13 +02:00
|
|
|
double_list = new std::list<double>;
|
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
for (double i = 1; i<=15; i++)
|
2017-08-27 09:50:30 +02:00
|
|
|
double_list->push_back(2 * i + (i / 100));
|
2017-05-19 22:47:13 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FListBox* list2 = new finalcut::FListBox (this);
|
2017-04-23 18:54:46 +02:00
|
|
|
list2->setGeometry(21, 1, 10, 10);
|
|
|
|
list2->setText ("double");
|
|
|
|
|
2017-05-19 22:16:50 +02:00
|
|
|
//
|
|
|
|
// Import via lazy conversion on print
|
|
|
|
//
|
2017-05-19 22:47:13 +02:00
|
|
|
list2->insert (double_list, doubleToItem);
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-05-19 22:16:50 +02:00
|
|
|
//
|
|
|
|
// Direct import of the complete list
|
|
|
|
//
|
2017-05-19 22:47:13 +02:00
|
|
|
//list2->insert (double_list->begin(), double_list->end(), doubleToString);
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// listbox 3
|
2018-09-20 23:59:01 +02:00
|
|
|
std::map<finalcut::FString, finalcut::FString> TLD;
|
2017-04-23 18:54:46 +02:00
|
|
|
TLD["com"] = "Commercial";
|
|
|
|
TLD["org"] = "Organization";
|
|
|
|
TLD["net"] = "Network";
|
|
|
|
TLD["edu"] = "Education";
|
|
|
|
TLD["gov"] = "Government";
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FListBox* list3;
|
|
|
|
list3 = new finalcut::FListBox (TLD.begin(), TLD.end(), mapToString, this);
|
2017-04-23 18:54:46 +02:00
|
|
|
list3->setGeometry(32, 1, 21, 10);
|
|
|
|
list3->setText ("key: value");
|
|
|
|
|
|
|
|
// Quit button
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FButton* Quit = new finalcut::FButton (this);
|
2017-04-23 18:54:46 +02:00
|
|
|
Quit->setGeometry(42, 12, 10, 1);
|
|
|
|
Quit->setText (L"&Quit");
|
|
|
|
|
2017-08-01 00:56:12 +02:00
|
|
|
// Add quit button function callback
|
2017-04-23 18:54:46 +02:00
|
|
|
Quit->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2018-09-20 23:59:01 +02:00
|
|
|
F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp)
|
2017-04-23 18:54:46 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
Listbox::~Listbox() // destructor
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
|
|
|
delete temp_str;
|
2017-05-19 22:16:50 +02:00
|
|
|
delete double_list;
|
2017-04-23 18:54:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Listbox::onClose (finalcut::FCloseEvent* ev)
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2017-04-23 18:54:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication app(argc, argv);
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2017-04-23 18:54:46 +02:00
|
|
|
Listbox d(&app);
|
|
|
|
d.setText (L"Listbox");
|
2017-07-18 23:50:51 +02:00
|
|
|
d.setGeometry (int(1 + (app.getWidth() - 56) / 2), 5, 56, 16);
|
2017-04-23 18:54:46 +02:00
|
|
|
d.setShadow();
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog d as main widget
|
2017-04-23 18:54:46 +02:00
|
|
|
app.setMainWidget(&d);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Show and start the application
|
2017-04-23 18:54:46 +02:00
|
|
|
d.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|