finalcut/test/ui.cpp

938 lines
25 KiB
C++
Raw Normal View History

// File: ui.cpp
2015-05-23 13:35:12 +02:00
#include <iostream>
#include <fstream>
#include "final.h"
2015-12-18 21:48:27 +01:00
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class ProgressDialog
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class ProgressDialog : public FDialog
{
public:
// Constructor
explicit ProgressDialog (FWidget* = 0);
// Destructor
~ProgressDialog();
2015-05-23 13:35:12 +02:00
2015-12-18 21:48:27 +01:00
private:
// Disable copy constructor
ProgressDialog (const ProgressDialog&);
// Disable assignment operator (=)
ProgressDialog& operator = (const ProgressDialog&);
2015-05-23 13:35:12 +02:00
// Event handlers
2015-05-23 13:35:12 +02:00
void onShow (FShowEvent*);
void onTimer (FTimerEvent*);
// Callback methods
void cb_reset_bar (FWidget*, data_ptr);
void cb_more_bar (FWidget*, data_ptr);
void cb_exit_bar (FWidget*, data_ptr);
2015-12-18 21:48:27 +01:00
// Data Members
FProgressbar* progressBar;
FButton* reset;
FButton* more;
FButton* quit;
2015-05-23 13:35:12 +02:00
};
#pragma pack(pop)
//----------------------------------------------------------------------
ProgressDialog::ProgressDialog (FWidget* parent)
: FDialog(parent)
2015-12-18 21:48:27 +01:00
, progressBar()
, reset()
, more()
, quit()
2015-05-23 13:35:12 +02:00
{
setGeometry (int((this->getParentWidget()->getWidth()-40)/2), 7, 40, 10);
2015-05-23 13:35:12 +02:00
setText("Progress bar");
//setModal();
reset = new FButton(this);
reset->setText("&Reset");
reset->setStatusbarMessage ("Reset the progress bar");
2015-05-23 13:35:12 +02:00
reset->setGeometry(2, 6, 8, 1, false);
reset->setDisable();
more = new FButton(this);
more->setText("&More");
more->setStatusbarMessage ("Increases the progress bar position");
2015-05-23 13:35:12 +02:00
more->setGeometry(15, 6, 8, 1, false);
more->setDisable();
quit = new FButton(this);
quit->setText("E&xit");
quit->setGeometry(28, 6, 8, 1, false);
quit->setDisable();
progressBar = new FProgressbar(this);
progressBar->setGeometry(2, 3, 34, 1, false);
//progressBar->setPercentage(78);
2015-05-23 13:35:12 +02:00
reset->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &ProgressDialog::cb_reset_bar)
2015-05-23 13:35:12 +02:00
);
more->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &ProgressDialog::cb_more_bar)
2015-05-23 13:35:12 +02:00
);
quit->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &ProgressDialog::cb_exit_bar)
2015-05-23 13:35:12 +02:00
);
}
//----------------------------------------------------------------------
ProgressDialog::~ProgressDialog()
{
2015-12-19 20:49:01 +01:00
delOwnTimer();
2015-05-23 13:35:12 +02:00
delCallback(quit);
delCallback(more);
delCallback(reset);
delete(progressBar);
delete(quit);
delete(more);
delete(reset);
}
//----------------------------------------------------------------------
void ProgressDialog::onShow (FShowEvent*)
{
addTimer(15);
}
//----------------------------------------------------------------------
void ProgressDialog::onTimer (FTimerEvent*)
{
int p = progressBar->getPercentage();
progressBar->setPercentage(++p);
flush_out();
if ( p != 100 )
return;
delOwnTimer();
activateWindow();
raiseWindow();
reset->setEnable();
reset->setFocus();
more->setEnable();
quit->setEnable();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void ProgressDialog::cb_reset_bar (FWidget*, data_ptr)
2015-05-23 13:35:12 +02:00
{
progressBar->reset();
}
//----------------------------------------------------------------------
void ProgressDialog::cb_more_bar (FWidget*, data_ptr)
2015-05-23 13:35:12 +02:00
{
int p = progressBar->getPercentage();
progressBar->setPercentage(++p);
}
//----------------------------------------------------------------------
void ProgressDialog::cb_exit_bar (FWidget*, data_ptr)
2015-05-23 13:35:12 +02:00
{
close();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
// class TextWindow
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class TextWindow : public FDialog
{
public:
// Constructor
explicit TextWindow (FWidget* = 0);
// Destructor
~TextWindow();
void append (const FString&);
private:
// Disable copy constructor
TextWindow (const TextWindow&);
// Disable assignment operator (=)
TextWindow& operator = (const TextWindow&);
void adjustSize();
// Data Members
FTextView* scrollText;
};
#pragma pack(pop)
//----------------------------------------------------------------------
TextWindow::TextWindow (FWidget* parent)
: FDialog(parent)
, scrollText()
{
scrollText = new FTextView(this);
scrollText->ignorePadding();
scrollText->setGeometry (1, 2, getWidth(), getHeight()-1);
setMinimumSize (51, 6);
scrollText->setFocus();
scrollText->insert(" -----------------------------------------------\n"
" line 1\n"
" -----------------------------------------------\n"
" line 3\n"
" line 4"
, -1);
scrollText->replaceRange(" File viewer", 1, 1);
scrollText->deleteRange(3, 4);
}
//----------------------------------------------------------------------
TextWindow::~TextWindow()
{ }
//----------------------------------------------------------------------
void TextWindow::append (const FString& str)
{
scrollText->append(str);
}
//----------------------------------------------------------------------
void TextWindow::adjustSize()
{
FDialog::adjustSize();
scrollText->setGeometry (1, 2, getWidth(), getHeight()-1);
}
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class MyDialog
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class MyDialog : public FDialog
{
public:
// Constructor
explicit MyDialog (FWidget* = 0);
// Destructor
~MyDialog();
private:
// Disable copy constructor
MyDialog (const MyDialog&);
// Disable assignment operator (=)
MyDialog& operator = (const MyDialog&);
2017-01-22 23:04:40 +01:00
// Method
void adjustSize();
// Event handlers
2015-05-23 13:35:12 +02:00
void onClose (FCloseEvent*);
// Callback methods
void cb_noFunctionMsg (FWidget*, data_ptr);
void cb_about (FWidget*, data_ptr);
void cb_terminfo (FWidget*, data_ptr);
void cb_drives (FWidget*, data_ptr);
void cb_cutClipboard (FWidget*, data_ptr);
void cb_copyClipboard (FWidget*, data_ptr);
void cb_pasteClipboard (FWidget*, data_ptr);
void cb_clearInput (FWidget*, data_ptr);
void cb_input2buttonText (FWidget*, data_ptr);
void cb_setTitlebar (FWidget*, data_ptr);
void cb_ProgressBar (FWidget*, data_ptr);
void cb_updateNumber (FWidget*, data_ptr);
void cb_activateButton (FWidget*, data_ptr);
void cb_view (FWidget*, data_ptr);
void cb_setInput (FWidget*, data_ptr);
void cb_exitApp (FWidget*, data_ptr);
2017-01-22 23:04:40 +01:00
// Data Members
FLineEdit* myLineEdit;
FListBox* myList;
FString clipboard;
2015-05-23 13:35:12 +02:00
};
#pragma pack(pop)
//----------------------------------------------------------------------
MyDialog::MyDialog (FWidget* parent)
: FDialog(parent)
, myLineEdit()
, myList()
, clipboard()
2015-05-23 13:35:12 +02:00
{
// menu bar
2015-11-12 01:33:16 +01:00
FMenuBar* Menubar = new FMenuBar (this);
// menu bar items
2015-11-12 01:33:16 +01:00
FMenu* File = new FMenu ("&File", Menubar);
File->setStatusbarMessage ("File management commands");
FMenu* Edit = new FMenu ("&Edit", Menubar);
Edit->setStatusbarMessage ("Cut-and-paste editing commands");
FMenu* View = new FMenu ("&View", Menubar);
View->setStatusbarMessage ("Show internal informations");
2015-12-11 06:04:29 +01:00
FMenuItem* Options = new FMenuItem ("&Options", Menubar);
2015-11-12 01:33:16 +01:00
Options->setStatusbarMessage ("Set program defaults");
2015-12-11 06:04:29 +01:00
Options->setDisable();
FDialogListMenu* Window = new FDialogListMenu ("&Window", Menubar);
Window->setStatusbarMessage ("List of all the active dialogs");
2015-11-12 01:33:16 +01:00
FMenuItem* Help = new FMenuItem ("&Help", Menubar);
Help->setStatusbarMessage ("Show version and copyright information");
// "File" menu items
2015-11-12 01:33:16 +01:00
FMenuItem* Open = new FMenuItem ("&Open...", File);
Open->addAccelerator (fc::Fckey_o); // Ctrl + O
Open->setStatusbarMessage ("Locate and open a text file");
2015-12-08 21:05:00 +01:00
FMenu* Recent = new FMenu ("&System files", File);
Recent->setStatusbarMessage ("View text file");
2015-11-12 01:33:16 +01:00
FMenuItem* Line1 = new FMenuItem (File);
Line1->setSeparator();
2015-11-12 01:33:16 +01:00
FMenuItem* Quit = new FMenuItem ("&Quit", File);
Quit->addAccelerator (fc::Fmkey_x); // Meta/Alt + X
Quit->setStatusbarMessage ("Exit the program");
// "Recent" menu items
FMenuItem* File1 = new FMenuItem ("/etc/services", Recent);
FMenuItem* File2 = new FMenuItem ("/etc/fstab", Recent);
FMenuItem* File3 = new FMenuItem ("/etc/passwd", Recent);
// "Edit" menu items
FMenuItem* Undo = new FMenuItem (fc::Fckey_z, "Undo", Edit);
Undo->setDisable();
FMenuItem* Redo = new FMenuItem (fc::Fckey_y, "Redo", Edit);
Redo->setDisable();
2015-11-12 01:33:16 +01:00
FMenuItem* Line2 = new FMenuItem (Edit);
Line2->setSeparator();
2015-11-12 01:33:16 +01:00
FMenuItem* Cut = new FMenuItem (fc::Fckey_x, "Cu&t", Edit);
Cut->setStatusbarMessage ("Remove the input text and put it in the clipboard");
FMenuItem* Copy = new FMenuItem (fc::Fckey_c, "&Copy", Edit);
Copy->setStatusbarMessage ("Copy the input text into the clipboad");
FMenuItem* Paste = new FMenuItem (fc::Fckey_v, "&Paste", Edit);
Paste->setStatusbarMessage ("Insert text form clipboard");
FMenuItem* Clear = new FMenuItem (fc::Fkey_dc, "C&lear", Edit);
2015-11-12 01:33:16 +01:00
Clear->setStatusbarMessage ("Delete input text");
// "View" menu items
FMenuItem* Env = new FMenuItem ("&Terminal...", View);
2015-11-12 01:33:16 +01:00
Env->setStatusbarMessage ("Informations about this terminal");
FMenuItem* Drive = new FMenuItem ("&Drive symbols...", View);
Drive->setStatusbarMessage ("Show drive symbols");
// Menu function callbacks
Open->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view)
);
Quit->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
);
Cut->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_cutClipboard)
);
Copy->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_copyClipboard)
);
Paste->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_pasteClipboard)
);
Clear->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_clearInput)
);
Env->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_terminfo)
);
Drive->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_drives)
);
Help->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_about)
);
File1->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
2015-12-08 21:05:00 +01:00
dynamic_cast<FWidget::data_ptr>(File1)
);
File2->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
2015-12-08 21:05:00 +01:00
dynamic_cast<FWidget::data_ptr>(File2)
);
File3->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
2015-12-08 21:05:00 +01:00
dynamic_cast<FWidget::data_ptr>(File3)
);
// Buttons
2015-11-12 01:33:16 +01:00
FButton* MyButton1 = new FButton (this);
2015-05-23 13:35:12 +02:00
MyButton1->setGeometry(3, 3, 5, 1);
2015-11-12 01:33:16 +01:00
MyButton1->setText (L"&SIN");
MyButton1->setStatusbarMessage ("Sine function");
2015-05-23 13:35:12 +02:00
MyButton1->setNoUnderline();
MyButton1->setFlat();
2015-11-12 01:33:16 +01:00
MyButton1->setDoubleFlatLine (fc::bottom);
2015-05-23 13:35:12 +02:00
2015-11-12 01:33:16 +01:00
FButton* MyButton2 = new FButton (this);
2015-05-23 13:35:12 +02:00
MyButton2->setGeometry(3, 5, 5, 1);
2015-11-12 01:33:16 +01:00
MyButton2->setText (L"&COS");
MyButton2->setStatusbarMessage ("Cosine function");
2015-05-23 13:35:12 +02:00
MyButton2->setNoUnderline();
MyButton2->setFlat();
MyButton2->setDoubleFlatLine (fc::top);
2015-05-23 13:35:12 +02:00
2015-11-12 01:33:16 +01:00
FButton* MyButton3 = new FButton (this);
2015-05-23 13:35:12 +02:00
MyButton3->setGeometry(10, 3, 5, 3);
2015-11-12 01:33:16 +01:00
MyButton3->setText (L"&=");
MyButton3->setStatusbarMessage ("Equal");
2015-05-23 13:35:12 +02:00
MyButton3->setNoUnderline();
MyButton3->setFlat();
// Radio buttons in a group
2015-11-12 01:33:16 +01:00
FButtonGroup* radioButtonGroup = new FButtonGroup ("Button", this);
2015-05-23 13:35:12 +02:00
radioButtonGroup->setGeometry(3, 8, 14, 4);
//radioButtonGroup->unsetBorder();
2015-11-12 01:33:16 +01:00
FRadioButton* radio1 = new FRadioButton ("E&nable", radioButtonGroup);
2017-03-12 00:29:56 +01:00
radio1->setGeometry(1, 1, 10, 1);
2015-11-12 01:33:16 +01:00
radio1->setStatusbarMessage ("Enable button Test");
2015-05-23 13:35:12 +02:00
2015-11-12 01:33:16 +01:00
FRadioButton* radio2 = new FRadioButton (radioButtonGroup);
2017-03-12 00:29:56 +01:00
radio2->setGeometry(1, 2, 11, 1);
2015-11-12 01:33:16 +01:00
radio2->setText ("&Disable");
radio2->setStatusbarMessage ("Disable button Test");
2015-05-23 13:35:12 +02:00
radio2->setChecked();
//radio2->setDisable();
// Checkboxes in a group
2015-11-12 01:33:16 +01:00
FButtonGroup* checkButtonGroup = new FButtonGroup ("Options", this);
2015-05-23 13:35:12 +02:00
checkButtonGroup->setGeometry(3, 12, 14, 4);
2015-11-12 01:33:16 +01:00
FCheckBox* check1 = new FCheckBox ("&Bitmode", checkButtonGroup);
2017-03-12 00:29:56 +01:00
check1->setGeometry(1, 1, 11, 1);
2015-05-23 13:35:12 +02:00
check1->setNoUnderline();
2015-11-12 01:33:16 +01:00
FCheckBox* check2 = new FCheckBox ("&8-Bit", checkButtonGroup);
2017-03-12 00:29:56 +01:00
check2->setGeometry(1, 2, 9, 1);
2015-05-23 13:35:12 +02:00
check2->setChecked();
check2->setNoUnderline();
// A text input field
myLineEdit = new FLineEdit (this);
myLineEdit->setGeometry(22, 1, 10, 1);
myLineEdit->setText (FString("EnTry").toLower());
myLineEdit->setLabelText (L"&Input");
myLineEdit->setStatusbarMessage ("Press Enter to set the title");
2015-05-23 13:35:12 +02:00
// Buttons
2015-11-12 01:33:16 +01:00
FButton* MyButton4 = new FButton (this);
2015-10-29 21:10:50 +01:00
MyButton4->setGeometry(20, 8, 12, 1);
2015-11-12 01:33:16 +01:00
MyButton4->setText (L"&Get input");
MyButton4->setStatusbarMessage ("Take text from input field");
2015-10-29 21:10:50 +01:00
MyButton4->setFocus();
2015-05-26 23:15:49 +02:00
2015-11-12 01:33:16 +01:00
FButton* MyButton5 = new FButton (this);
2015-10-29 21:10:50 +01:00
MyButton5->setGeometry(20, 11, 12, 1);
2015-11-12 01:33:16 +01:00
MyButton5->setText (L"&Test");
MyButton5->setStatusbarMessage ("Progressbar testing dialog");
2015-10-29 21:10:50 +01:00
MyButton5->setDisable();
2015-05-26 23:15:49 +02:00
2015-11-12 01:33:16 +01:00
FButton* MyButton6 = new FButton (this);
2015-10-29 21:10:50 +01:00
MyButton6->setGeometry(20, 14, 12, 1);
2015-11-12 01:33:16 +01:00
MyButton6->setText (L"&Quit");
MyButton6->setStatusbarMessage ("Exit the program");
2015-10-29 21:10:50 +01:00
MyButton6->addAccelerator('x');
2015-05-23 13:35:12 +02:00
// A multiple selection listbox
2015-11-12 01:33:16 +01:00
myList = new FListBox (this);
2015-05-23 13:35:12 +02:00
myList->setGeometry(38, 1, 14, 17);
2015-11-12 01:33:16 +01:00
myList->setText ("Items");
myList->setStatusbarMessage ("99 items in a list");
2015-05-23 13:35:12 +02:00
myList->setMultiSelection();
for (int z=1; z < 100; z++)
2015-11-12 01:33:16 +01:00
myList->insert (FString().setNumber(z) + L" placeholder");
2015-05-23 13:35:12 +02:00
// Text labels
2015-11-12 01:33:16 +01:00
FLabel* headline = new FLabel (this);
2015-10-29 21:10:50 +01:00
headline->setGeometry(21, 3, 10, 1);
2015-11-12 01:33:16 +01:00
headline->setText (L"List items");
2015-05-23 13:35:12 +02:00
headline->setEmphasis();
2015-11-12 01:33:16 +01:00
headline->setAlignment (fc::alignCenter);
2015-05-23 13:35:12 +02:00
2015-11-12 01:33:16 +01:00
FLabel* tagged = new FLabel (L"Tagged:", this);
2015-10-29 21:10:50 +01:00
tagged->setGeometry(21, 4, 7, 1);
2015-05-23 13:35:12 +02:00
FLabel* tagged_count = new FLabel(this);
2015-10-29 21:10:50 +01:00
tagged_count->setGeometry(29, 4, 5, 1);
2015-05-23 13:35:12 +02:00
tagged_count->setNumber(0);
2015-11-12 01:33:16 +01:00
FLabel* sum = new FLabel (L"Sum:", this);
2015-10-29 21:10:50 +01:00
sum->setGeometry(21, 5, 7, 3);
2015-11-12 01:33:16 +01:00
sum->setAlignment (fc::alignRight);
2015-05-23 13:35:12 +02:00
2015-11-12 01:33:16 +01:00
FLabel* sum_count = new FLabel (this);
2015-10-29 21:10:50 +01:00
sum_count->setGeometry(29, 5, 5, 3);
sum_count->setNumber (myList->getCount());
2015-05-23 13:35:12 +02:00
// Statusbar at the bottom
2015-11-12 01:33:16 +01:00
FStatusBar* statusbar = new FStatusBar (this);
// Statusbar keys
2015-11-12 01:33:16 +01:00
FStatusKey* key_F1 = new FStatusKey (fc::Fkey_f1, "About", statusbar);
FStatusKey* key_F2 = new FStatusKey (fc::Fkey_f2, "View", statusbar);
FStatusKey* key_F3 = new FStatusKey (fc::Fkey_f3, "Quit", statusbar);
2015-05-23 13:35:12 +02:00
// Add some function callbacks
2015-05-23 13:35:12 +02:00
MyButton1->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
2015-05-23 13:35:12 +02:00
);
MyButton2->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
2015-05-23 13:35:12 +02:00
);
MyButton3->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
2015-05-23 13:35:12 +02:00
);
MyButton4->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_input2buttonText),
dynamic_cast<FWidget::data_ptr>(myLineEdit)
2015-05-23 13:35:12 +02:00
);
MyButton5->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_ProgressBar)
2015-05-23 13:35:12 +02:00
);
MyButton6->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
2015-05-23 13:35:12 +02:00
);
myLineEdit->addCallback
2015-05-23 13:35:12 +02:00
(
"activate", // e.g. on <Enter>
F_METHOD_CALLBACK (this, &MyDialog::cb_setTitlebar)
2015-05-23 13:35:12 +02:00
);
radio1->addCallback
(
"toggled",
F_METHOD_CALLBACK (this, &MyDialog::cb_activateButton),
2015-10-29 21:10:50 +01:00
dynamic_cast<FWidget::data_ptr>(MyButton5)
2015-05-23 13:35:12 +02:00
);
myList->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_setInput),
dynamic_cast<FWidget::data_ptr>(myLineEdit)
2015-05-23 13:35:12 +02:00
);
myList->addCallback
(
"row-selected",
F_METHOD_CALLBACK (this, &MyDialog::cb_updateNumber),
2015-05-23 13:35:12 +02:00
dynamic_cast<FWidget::data_ptr>(tagged_count)
);
key_F1->addCallback
(
"activate",
F_METHOD_CALLBACK (this, &MyDialog::cb_about)
2015-05-23 13:35:12 +02:00
);
key_F2->addCallback
(
"activate",
F_METHOD_CALLBACK (this, &MyDialog::cb_view)
2015-05-23 13:35:12 +02:00
);
key_F3->addCallback
(
"activate",
F_METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
2015-05-23 13:35:12 +02:00
);
}
//----------------------------------------------------------------------
MyDialog::~MyDialog()
{ }
2015-05-23 13:35:12 +02:00
2017-01-22 23:04:40 +01:00
//----------------------------------------------------------------------
void MyDialog::adjustSize()
{
int h = getParentWidget()->getHeight() - 4;
setHeight (h, false);
int X = int((getParentWidget()->getWidth() - getWidth()) / 2);
if ( X < 1 )
X = 1;
setX (X, false);
if ( myList )
myList->setHeight (getHeight() - 3, false);
FDialog::adjustSize();
}
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
void MyDialog::onClose (FCloseEvent* ev)
2015-05-23 13:35:12 +02:00
{
int ret = FMessageBox::info ( this, "Quit"
, "Do you really want\n"
"to quit the program ?"
, FMessageBox::Yes
, FMessageBox::No );
2015-05-23 13:35:12 +02:00
if ( ret == FMessageBox::Yes )
ev->accept();
2015-05-23 13:35:12 +02:00
else
ev->ignore();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void MyDialog::cb_noFunctionMsg (FWidget* widget, data_ptr)
2015-05-23 13:35:12 +02:00
{
FButton* button = static_cast<FButton*>(widget);
FString text = button->getText();
text = text.replace('&', "");
FMessageBox::error (this, "The \"" + text + "\" button has\n"
"no function");
}
//----------------------------------------------------------------------
void MyDialog::cb_about (FWidget*, data_ptr)
2015-05-23 13:35:12 +02:00
{
2015-12-19 22:01:48 +01:00
const char libver[] = F_VERSION;
2015-05-23 13:35:12 +02:00
FString line(2, wchar_t(fc::BoxDrawingsHorizontal));
FMessageBox info ( "About"
, line + L" The Final Cut " + line + "\n\n"
2015-12-19 22:01:48 +01:00
L"Version " + libver + "\n\n"
L"(c) 2017 by Markus Gans"
, FMessageBox::Ok, 0, 0, this );
2015-05-23 13:35:12 +02:00
info.setCenterText();
info.show();
}
//----------------------------------------------------------------------
void MyDialog::cb_terminfo (FWidget*, data_ptr)
2015-10-29 21:10:50 +01:00
{
int x = getColumnNumber();
int y = getLineNumber();
2015-10-29 21:10:50 +01:00
FMessageBox info1 ( "Environment"
, " Type: " + FString(getTermType()) + "\n"
" Name: " + FString(getTermName()) + "\n"
" Mode: " + FString(getEncoding()) + "\n"
" Size: " + FString().setNumber(x) + wchar_t(fc::Times)
+ FString().setNumber(y) + "\n"
2015-10-29 21:10:50 +01:00
"Colors: " + FString().setNumber(getMaxColor())
, FMessageBox::Ok, 0, 0, this );
info1.setHeadline("Terminal:");
info1.exec();
}
//----------------------------------------------------------------------
void MyDialog::cb_drives (FWidget*, data_ptr)
2015-05-23 13:35:12 +02:00
{
FMessageBox info2 ( "Drive symbols"
, "Generic: \n\n"
2015-05-23 13:35:12 +02:00
"Network: \n\n"
" CD:"
, FMessageBox::Ok, 0, 0, this );
2015-05-23 13:35:12 +02:00
if ( isNewFont() )
{
FLabel drive (NF_Drive, &info2);
drive.setGeometry (11, 2, 4, 1);
FLabel net (NF_Net_Drive, &info2);
net.setGeometry (11, 4, 4, 1);
FLabel cd (NF_CD_ROM, &info2);
cd.setGeometry (11, 6, 4, 1);
info2.exec();
}
else
{
FLabel drive (" - ", &info2);
drive.setGeometry (11, 2, 4, 1);
FLabel net (" N ", &info2);
net.setGeometry (11, 4, 4, 1);
FLabel cd (" CD ", &info2);
cd.setGeometry (11, 6, 4, 1);
2015-05-23 13:35:12 +02:00
if ( isMonochron() )
{
net.setReverseMode();
drive.setReverseMode();
cd.setReverseMode();
}
else
{
net.setForegroundColor (fc::White);
net.setBackgroundColor (fc::DarkGray);
drive.setForegroundColor (fc::White);
drive.setBackgroundColor (fc::DarkGray);
cd.setForegroundColor (fc::White);
cd.setBackgroundColor (fc::DarkGray);
}
2015-05-23 13:35:12 +02:00
info2.exec();
}
}
//----------------------------------------------------------------------
void MyDialog::cb_cutClipboard (FWidget*, data_ptr)
{
if ( ! myLineEdit )
return;
clipboard = myLineEdit->getText();
myLineEdit->clearText();
myLineEdit->redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_copyClipboard (FWidget*, data_ptr)
{
if ( ! myLineEdit )
return;
clipboard = myLineEdit->getText();
}
//----------------------------------------------------------------------
void MyDialog::cb_pasteClipboard (FWidget*, data_ptr)
{
if ( ! myLineEdit )
return;
myLineEdit->setText(clipboard);
myLineEdit->redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_clearInput (FWidget*, data_ptr)
{
if ( ! myLineEdit )
return;
clipboard.clear();
myLineEdit->clearText();
myLineEdit->redraw();
}
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
void MyDialog::cb_input2buttonText (FWidget* widget, data_ptr data)
2015-05-23 13:35:12 +02:00
{
FButton* button = static_cast<FButton*>(widget);
FLineEdit* lineedit = static_cast<FLineEdit*>(data);
2015-05-23 13:35:12 +02:00
button->setText( lineedit->getText() );
button->redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_setTitlebar (FWidget* widget, data_ptr)
2015-05-23 13:35:12 +02:00
{
FLineEdit* lineedit = static_cast<FLineEdit*>(widget);
lineedit->setXTermTitle(lineedit->getText());
setText(lineedit->getText());
redraw();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void MyDialog::cb_ProgressBar (FWidget*, data_ptr)
2015-05-23 13:35:12 +02:00
{
ProgressDialog* p_dgl = new ProgressDialog(this);
p_dgl->show();
}
//----------------------------------------------------------------------
void MyDialog::cb_updateNumber (FWidget* widget, data_ptr data)
2015-05-23 13:35:12 +02:00
{
FListBox* list = static_cast<FListBox*>(widget);
FLabel* num = static_cast<FLabel*>(data);
2015-05-23 13:35:12 +02:00
int select_num = 0;
uInt end = list->getCount();
2015-05-23 13:35:12 +02:00
for (uInt n=1; n <= end; n++)
if ( list->isSelected(int(n)) )
select_num++;
2015-05-23 13:35:12 +02:00
num->setNumber(select_num);
num->redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_activateButton (FWidget* widget, data_ptr data)
2015-05-23 13:35:12 +02:00
{
FRadioButton* rb = static_cast<FRadioButton*>(widget);
FButton* button = static_cast<FButton*>(data);
2015-05-23 13:35:12 +02:00
if ( rb->isChecked() )
button->setEnable();
else
button->setDisable();
2015-05-23 13:35:12 +02:00
button->redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_view (FWidget*, data_ptr data)
2015-05-23 13:35:12 +02:00
{
FString file;
FMenuItem* item = static_cast<FMenuItem*>(data);
2015-12-12 00:50:59 +01:00
2015-12-08 21:05:00 +01:00
if ( item && item->getText() )
file = item->getText();
else
file = FFileDialog::fileOpenChooser (this);
2015-05-23 13:35:12 +02:00
if ( file.isNull() )
return;
TextWindow* view = new TextWindow(this);
FString filename(basename(const_cast<char*>(file.c_str())));
view->setText ("Viewer: " + filename);
2015-05-23 13:35:12 +02:00
view->setGeometry (1+int((getRootWidget()->getWidth()-60)/2),
int(getRootWidget()->getHeight()/6),
60,
int(getRootWidget()->getHeight()*3/4));
view->setResizeable();
2015-05-23 13:35:12 +02:00
std::string line = "";
std::ifstream infile;
infile.open(file);
2015-05-23 13:35:12 +02:00
while ( ! infile.eof() && infile.good() )
{
getline(infile, line);
view->append(line);
2015-05-23 13:35:12 +02:00
}
2015-05-23 13:35:12 +02:00
if ( infile.is_open() )
infile.close();
2015-05-23 13:35:12 +02:00
view->show();
}
//----------------------------------------------------------------------
void MyDialog::cb_setInput (FWidget* widget, data_ptr data)
2015-05-23 13:35:12 +02:00
{
FListBox* ListBox = static_cast<FListBox*>(widget);
FLineEdit* lineedit = static_cast<FLineEdit*>(data);
lineedit->setText( ListBox->getItem(ListBox->currentItem()).getText() );
2015-05-23 13:35:12 +02:00
lineedit->redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_exitApp (FWidget*, data_ptr)
2015-05-23 13:35:12 +02:00
{
close();
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
2015-12-19 22:01:48 +01:00
FString ver = F_VERSION; // library version
FString title = "The FINAL CUT " + ver + " (C) 2017 by Markus Gans";
2015-12-19 22:01:48 +01:00
if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0
|| std::strcmp(argv[1], "-h") == 0 ) )
2015-05-23 13:35:12 +02:00
{
std::cout << "Generic options:" << std::endl
<< " -h, --help "
<< "Display this help and exit" << std::endl;
FApplication::print_cmd_Options();
std::exit(EXIT_SUCCESS);
2015-05-23 13:35:12 +02:00
}
FApplication app(argc, argv);
2016-11-26 18:15:31 +01:00
app.setXTermDefaultColors(true);
2015-12-19 22:01:48 +01:00
app.setXTermTitle (title);
2015-05-23 13:35:12 +02:00
//app.setEncoding("VT100");
//app.setTermSize(94,30);
2015-05-23 13:35:12 +02:00
//app.setNewFont();
MyDialog d(&app);
2015-12-19 22:01:48 +01:00
d.setText (title);
d.setGeometry (int((app.getWidth()-56)/2), 2, 56, app.getHeight()-4);
2015-05-23 13:35:12 +02:00
d.setShadow();
app.setMainWidget(&d);
d.show();
return app.exec();
}