2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* menu.cpp - A menu example *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-01-21 16:25:19 +01:00
|
|
|
* Copyright 2015-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-12-08 21:05:00 +01:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2015-12-18 21:48:27 +01:00
|
|
|
|
2015-12-08 21:05:00 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Menu
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class Menu : public FDialog
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
explicit Menu (FWidget* = 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
|
|
|
~Menu();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
|
|
|
Menu (const Menu&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
Menu& operator = (const Menu&);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Methods
|
2018-01-21 16:21:41 +01:00
|
|
|
void createFileMenuItems (FMenu*);
|
|
|
|
void createEditMenuItems (FMenu*);
|
|
|
|
void createChoiceMenuItems (FMenu*);
|
|
|
|
void createColorMenuItems (FMenu*);
|
|
|
|
void createStyleMenuItems (FMenu*);
|
|
|
|
void createBorderMenuItems (FMenu*);
|
|
|
|
void createBorderColorMenuItems (FMenu*);
|
|
|
|
void createBorderStyleMenuItems (FMenu*);
|
2017-09-11 03:06:02 +02:00
|
|
|
void defaultCallback (FMenuList*);
|
|
|
|
void adjustSize();
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handler
|
|
|
|
void onClose (FCloseEvent*);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-10-29 18:27:38 +01:00
|
|
|
// Callback method
|
2017-09-11 03:06:02 +02:00
|
|
|
void cb_message (FWidget*, data_ptr);
|
2015-12-08 21:05:00 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Menu::Menu (FWidget* parent)
|
|
|
|
: FDialog(parent)
|
|
|
|
{
|
2018-01-21 16:21:41 +01:00
|
|
|
// Menu bar
|
2015-12-08 21:05:00 +01:00
|
|
|
FMenuBar* Menubar = new FMenuBar (this);
|
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
// Menu bar items
|
2015-12-08 21:05:00 +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* Choice = new FMenu ("&Choice", Menubar);
|
|
|
|
Choice->setStatusbarMessage ("Choice menu");
|
|
|
|
FMenuItem* Window = new FMenuItem ("&Window", Menubar);
|
|
|
|
Window->setDisable();
|
|
|
|
FMenuItem* Help = new FMenuItem ("&Help", Menubar);
|
|
|
|
Help->setStatusbarMessage ("Show version and copyright information");
|
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
// Menu items
|
|
|
|
createFileMenuItems (File);
|
|
|
|
createEditMenuItems (Edit);
|
|
|
|
createChoiceMenuItems (Choice);
|
|
|
|
|
|
|
|
// Add default menu item callback
|
|
|
|
defaultCallback (Menubar);
|
|
|
|
|
|
|
|
// Statusbar at the bottom
|
|
|
|
FStatusBar* statusbar = new FStatusBar (this);
|
|
|
|
statusbar->setMessage("Status bar message");
|
|
|
|
|
|
|
|
// Headline labels
|
|
|
|
FLabel* Headline1 = new FLabel(" Key ", this);
|
|
|
|
Headline1->ignorePadding();
|
|
|
|
Headline1->setGeometry(3, 2, 5, 1);
|
|
|
|
Headline1->setEmphasis();
|
|
|
|
|
|
|
|
FLabel* Headline2 = new FLabel(" Function ", this);
|
|
|
|
Headline2->ignorePadding();
|
|
|
|
Headline2->setGeometry(19, 2, 10, 1);
|
|
|
|
Headline2->setEmphasis();
|
|
|
|
|
|
|
|
// Info label
|
|
|
|
FLabel* Info = new FLabel("<F10> Activate menu bar\n"
|
|
|
|
"<Ctrl>+<Space> Activate menu bar\n"
|
|
|
|
"<Meta>+<X> Exit", this);
|
|
|
|
Info->setGeometry(2, 1, 36, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Menu::~Menu()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createFileMenuItems (FMenu* File)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "File" menu items
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* New = new FMenuItem ("&New", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
New->addAccelerator (fc::Fckey_n); // Ctrl + N
|
2015-12-08 21:05:00 +01:00
|
|
|
New->setStatusbarMessage ("Create a new file");
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* Open = new FMenuItem ("&Open...", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Open->addAccelerator (fc::Fckey_o); // Ctrl + O
|
2015-12-08 21:05:00 +01:00
|
|
|
Open->setStatusbarMessage ("Locate and open a text file");
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* Save = new FMenuItem ("&Save", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Save->addAccelerator (fc::Fckey_s); // Ctrl + S
|
2015-12-08 21:05:00 +01:00
|
|
|
Save->setStatusbarMessage ("Save the file");
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* SaveAs = new FMenuItem ("&Save as...", File);
|
2015-12-08 21:05:00 +01:00
|
|
|
SaveAs->setStatusbarMessage ("Save the current file under a different name");
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* Close = new FMenuItem ("&Close", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Close->addAccelerator (fc::Fckey_w); // Ctrl + W
|
2015-12-08 21:05:00 +01:00
|
|
|
Close->setStatusbarMessage ("Close the current file");
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* Line1 = new FMenuItem (File);
|
2015-12-08 21:05:00 +01:00
|
|
|
Line1->setSeparator();
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* Print = new FMenuItem ("&Print", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Print->addAccelerator (fc::Fckey_p); // Ctrl + P
|
2015-12-08 21:05:00 +01:00
|
|
|
Print->setStatusbarMessage ("Print the current file");
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* Line2 = new FMenuItem (File);
|
2015-12-08 21:05:00 +01:00
|
|
|
Line2->setSeparator();
|
2018-01-21 16:21:41 +01:00
|
|
|
FMenuItem* Quit = new FMenuItem ("&Quit", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Quit->addAccelerator (fc::Fmkey_x); // Meta/Alt + X
|
2015-12-08 21:05:00 +01:00
|
|
|
Quit->setStatusbarMessage ("Exit the program");
|
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
// Add quit menu item callback
|
|
|
|
Quit->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
|
|
|
F_METHOD_CALLBACK (this, &FApplication::cb_exitApp)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createEditMenuItems (FMenu* Edit)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Edit" menu items
|
|
|
|
FMenuItem* Undo = new FMenuItem (fc::Fckey_z, "&Undo", Edit);
|
|
|
|
Undo->setStatusbarMessage ("Undo the previous operation");
|
|
|
|
FMenuItem* Redo = new FMenuItem (fc::Fckey_y, "&Redo", Edit);
|
|
|
|
Redo->setDisable();
|
|
|
|
FMenuItem* Line3 = new FMenuItem (Edit);
|
|
|
|
Line3->setSeparator();
|
|
|
|
FMenuItem* Cut = new FMenuItem (fc::Fckey_x, "Cu&t", Edit);
|
2017-09-11 03:06:02 +02:00
|
|
|
Cut->setStatusbarMessage ( "Remove the input text "
|
|
|
|
"and put it in the clipboard" );
|
2015-12-08 21:05:00 +01:00
|
|
|
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* Line4 = new FMenuItem (Edit);
|
|
|
|
Line4->setSeparator();
|
|
|
|
FMenuItem* Search = new FMenuItem (fc::Fckey_f, "&Search", Edit);
|
|
|
|
Search->setStatusbarMessage ("Search for text");
|
|
|
|
FMenuItem* Next = new FMenuItem (fc::Fkey_f3, "Search &next", Edit);
|
|
|
|
Next->setStatusbarMessage ("Repeat the last search command");
|
|
|
|
FMenuItem* Line5 = new FMenuItem (Edit);
|
|
|
|
Line5->setSeparator();
|
|
|
|
FMenuItem* SelectAll = new FMenuItem (fc::Fckey_a, "Select &all", Edit);
|
|
|
|
SelectAll->setStatusbarMessage ("Select the whole text");
|
2018-01-21 16:21:41 +01:00
|
|
|
}
|
2015-12-08 21:05:00 +01:00
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createChoiceMenuItems (FMenu* Choice)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Choice" menu items
|
|
|
|
FMenu* Color = new FMenu ("&Color", Choice);
|
|
|
|
Color->setStatusbarMessage ("Choose a color");
|
|
|
|
FMenu* Style = new FMenu ("&Style", Choice);
|
|
|
|
Style->setStatusbarMessage ("Choose a Style");
|
|
|
|
FMenu* Border = new FMenu ("&Border", Choice);
|
|
|
|
Border->setStatusbarMessage ("Choose Border");
|
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
createColorMenuItems (Color);
|
|
|
|
createStyleMenuItems (Style);
|
|
|
|
createBorderMenuItems (Border);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createColorMenuItems (FMenu* Color)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Color" menu items
|
|
|
|
FRadioMenuItem* Color1 = new FRadioMenuItem ("Red", Color);
|
|
|
|
Color1->setStatusbarMessage ("Set text red");
|
|
|
|
FRadioMenuItem* Color2 = new FRadioMenuItem ("Green", Color);
|
|
|
|
Color2->setStatusbarMessage ("Set text green");
|
|
|
|
FRadioMenuItem* Color3 = new FRadioMenuItem ("Yellow", Color);
|
|
|
|
Color3->setStatusbarMessage ("Set text yellow");
|
|
|
|
FRadioMenuItem* Color4 = new FRadioMenuItem ("Brue", Color);
|
|
|
|
Color4->setStatusbarMessage ("Set text brue");
|
|
|
|
FRadioMenuItem* Color5 = new FRadioMenuItem ("Black", Color);
|
|
|
|
Color5->setStatusbarMessage ("Set text black");
|
|
|
|
Color5->setChecked();
|
2018-01-21 16:21:41 +01:00
|
|
|
}
|
2015-12-08 21:05:00 +01:00
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createStyleMenuItems (FMenu* Style)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Style" menu items
|
|
|
|
FCheckMenuItem* Bold = new FCheckMenuItem ("Bold", Style);
|
|
|
|
Bold->setStatusbarMessage ("Set text bold");
|
|
|
|
FCheckMenuItem* Italic = new FCheckMenuItem ("Italic", Style);
|
|
|
|
Italic->setStatusbarMessage ("Set text italic");
|
2018-01-21 16:21:41 +01:00
|
|
|
}
|
2015-12-08 21:05:00 +01:00
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createBorderMenuItems (FMenu* Border)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Border" menu items
|
|
|
|
FMenu* BColor = new FMenu ("&Color", Border);
|
|
|
|
BColor->setStatusbarMessage ("Choose the border color");
|
|
|
|
FMenu* BStyle = new FMenu ("&Style", Border);
|
|
|
|
BStyle->setStatusbarMessage ("Choose the border Style");
|
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
createBorderColorMenuItems (BColor);
|
|
|
|
createBorderStyleMenuItems (BStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createBorderColorMenuItems (FMenu* BColor)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "BColor" menu items
|
|
|
|
FRadioMenuItem* BColor1 = new FRadioMenuItem ("Red", BColor);
|
|
|
|
BColor1->setStatusbarMessage ("Set red border");
|
|
|
|
FRadioMenuItem* BColor2 = new FRadioMenuItem ("Blue", BColor);
|
|
|
|
BColor2->setStatusbarMessage ("Set blue border");
|
2018-01-21 16:21:41 +01:00
|
|
|
}
|
2015-12-08 21:05:00 +01:00
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::createBorderStyleMenuItems (FMenu* BStyle)
|
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "BStyle" menu items
|
|
|
|
FString line(13, wchar_t(fc::BoxDrawingsHorizontal));
|
|
|
|
FRadioMenuItem* BStyle1 = new FRadioMenuItem (line, BStyle);
|
|
|
|
BStyle1->setChecked();
|
|
|
|
BStyle1->setStatusbarMessage ("Set border 1");
|
|
|
|
FRadioMenuItem* BStyle2 = new FRadioMenuItem ("-------------", BStyle);
|
|
|
|
BStyle2->setStatusbarMessage ("Set border 2");
|
|
|
|
FRadioMenuItem* BStyle3 = new FRadioMenuItem ("- - - - - - -", BStyle);
|
|
|
|
BStyle3->setStatusbarMessage ("Set border 3");
|
|
|
|
FRadioMenuItem* BStyle4 = new FRadioMenuItem ("- - - - -", BStyle);
|
|
|
|
BStyle4->setStatusbarMessage ("Set border 4");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-12-18 21:48:27 +01:00
|
|
|
void Menu::defaultCallback (FMenuList* mb)
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt i = 1; i <= mb->getCount(); i++)
|
2015-12-18 21:48:27 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FMenuItem* item = mb->getItem(int(i));
|
2015-12-18 21:48:27 +01:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( item
|
2017-11-26 22:37:18 +01:00
|
|
|
&& item->isEnabled()
|
|
|
|
&& item->acceptFocus()
|
|
|
|
&& item->isVisible()
|
|
|
|
&& ! item->isSeparator()
|
|
|
|
&& item->getText() != "&Quit" )
|
2015-12-18 21:48:27 +01:00
|
|
|
{
|
|
|
|
// Add the callback function
|
|
|
|
item->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &Menu::cb_message)
|
2015-12-18 21:48:27 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Call sub-menu
|
|
|
|
if ( item->hasMenu() )
|
|
|
|
defaultCallback (item->getMenu());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::adjustSize()
|
|
|
|
{
|
|
|
|
int pw = getParentWidget()->getWidth();
|
|
|
|
int ph = getParentWidget()->getHeight();
|
|
|
|
setX (1 + (pw - getWidth()) / 2, false);
|
|
|
|
setY (1 + (ph - getHeight()) / 4, false);
|
|
|
|
FDialog::adjustSize();
|
|
|
|
}
|
|
|
|
|
2015-12-08 21:05:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Menu::onClose (FCloseEvent* ev)
|
|
|
|
{
|
2017-10-30 20:56:00 +01:00
|
|
|
FApplication::closeConfirmationDialog (this, ev);
|
2015-12-08 21:05:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void Menu::cb_message (FWidget* widget, data_ptr)
|
2015-12-08 21:05:00 +01:00
|
|
|
{
|
2015-12-16 23:57:14 +01:00
|
|
|
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
|
|
|
|
FString text = menuitem->getText();
|
2015-12-08 21:05:00 +01:00
|
|
|
text = text.replace('&', "");
|
|
|
|
FMessageBox::info (this, "Info", "You have chosen \"" + text + "\"");
|
|
|
|
}
|
|
|
|
|
2015-12-18 21:48:27 +01:00
|
|
|
|
2015-12-08 21:05:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2015-12-08 21:05:00 +01:00
|
|
|
FApplication app (argc, argv);
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2015-12-08 21:05:00 +01:00
|
|
|
Menu main_dlg (&app);
|
|
|
|
main_dlg.setText ("Menu example");
|
2017-08-27 09:50:30 +02:00
|
|
|
main_dlg.setGeometry (int(1 + (app.getWidth() - 40) / 2), 2, 40, 6);
|
2015-12-08 21:05:00 +01:00
|
|
|
main_dlg.setShadow();
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog main_dlg as main widget
|
2015-12-08 21:05:00 +01:00
|
|
|
app.setMainWidget (&main_dlg);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Show and start the application
|
2015-12-08 21:05:00 +01:00
|
|
|
main_dlg.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|