2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* menu.cpp - A menu example *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-01-21 03:42:18 +01:00
|
|
|
* Copyright 2015-2019 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
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FPoint;
|
|
|
|
using finalcut::FSize;
|
|
|
|
|
2015-12-08 21:05:00 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Menu
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
class Menu : public finalcut::FDialog
|
2015-12-08 21:05:00 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Menu (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Menu (const Menu&) = delete;
|
2018-12-24 18:11:16 +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
|
|
|
// Disable assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
Menu& operator = (const Menu&) = delete;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
private:
|
2017-09-11 03:06:02 +02:00
|
|
|
// Methods
|
2018-10-03 22:23:55 +02:00
|
|
|
void configureFileMenuItems();
|
|
|
|
void configureEditMenuItems();
|
|
|
|
void configureChoiceMenuItems();
|
|
|
|
void configureColorMenuItems();
|
|
|
|
void configureStyleMenuItems();
|
|
|
|
void configureBorderMenuItems();
|
2018-09-20 23:59:01 +02:00
|
|
|
void defaultCallback (finalcut::FMenuList*);
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void adjustSize() override;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handler
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void onClose (finalcut::FCloseEvent*) override;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-10-29 18:27:38 +01:00
|
|
|
// Callback method
|
2018-12-27 00:14:46 +01:00
|
|
|
void cb_message (finalcut::FWidget*, FDataPtr);
|
2018-10-03 22:23:55 +02:00
|
|
|
|
|
|
|
// Data Members
|
2018-12-06 02:28:24 +01:00
|
|
|
finalcut::FString line{13, finalcut::fc::BoxDrawingsHorizontal};
|
2018-12-03 03:22:36 +01:00
|
|
|
finalcut::FMenuBar Menubar{this};
|
|
|
|
finalcut::FMenu File{"&File", &Menubar};
|
|
|
|
finalcut::FMenu Edit{"&Edit", &Menubar};
|
|
|
|
finalcut::FMenu Choice{"&Choice", &Menubar};
|
|
|
|
finalcut::FMenuItem Window{"&Window", &Menubar};
|
|
|
|
finalcut::FMenuItem Help{"&Help", &Menubar};
|
|
|
|
finalcut::FMenuItem New{"&New", &File};
|
|
|
|
finalcut::FMenuItem Open{"&Open...", &File};
|
|
|
|
finalcut::FMenuItem Save{"&Save", &File};
|
|
|
|
finalcut::FMenuItem SaveAs{"&Save as...", &File};
|
|
|
|
finalcut::FMenuItem Close{"&Close", &File};
|
|
|
|
finalcut::FMenuItem Line1{&File};
|
|
|
|
finalcut::FMenuItem Print{"&Print", &File};
|
|
|
|
finalcut::FMenuItem Line2{&File};
|
|
|
|
finalcut::FMenuItem Quit{"&Quit", &File};
|
|
|
|
finalcut::FMenuItem Undo{finalcut::fc::Fckey_z, "&Undo", &Edit};
|
|
|
|
finalcut::FMenuItem Redo{finalcut::fc::Fckey_y, "&Redo", &Edit};
|
|
|
|
finalcut::FMenuItem Line3{&Edit};
|
|
|
|
finalcut::FMenuItem Cut{finalcut::fc::Fckey_x, "Cu&t", &Edit};
|
|
|
|
finalcut::FMenuItem Copy{finalcut::fc::Fckey_c, "&Copy", &Edit};
|
|
|
|
finalcut::FMenuItem Paste{finalcut::fc::Fckey_v, "&Paste", &Edit};
|
|
|
|
finalcut::FMenuItem Line4{&Edit};
|
|
|
|
finalcut::FMenuItem Search{finalcut::fc::Fckey_f, "&Search", &Edit};
|
|
|
|
finalcut::FMenuItem Next{finalcut::fc::Fkey_f3, "Search &next", &Edit};
|
|
|
|
finalcut::FMenuItem Line5{&Edit};
|
|
|
|
finalcut::FMenuItem SelectAll{finalcut::fc::Fckey_a, "Select &all", &Edit};
|
|
|
|
finalcut::FMenu Color{"&Color", &Choice};
|
|
|
|
finalcut::FMenu Style{"&Style", &Choice};
|
|
|
|
finalcut::FMenu Border{"&Border", &Choice};
|
|
|
|
finalcut::FRadioMenuItem Color1{"Red", &Color};
|
|
|
|
finalcut::FRadioMenuItem Color2{"Green", &Color};
|
|
|
|
finalcut::FRadioMenuItem Color3{"Yellow", &Color};
|
|
|
|
finalcut::FRadioMenuItem Color4{"Brue", &Color};
|
|
|
|
finalcut::FRadioMenuItem Color5{"Black", &Color};
|
|
|
|
finalcut::FCheckMenuItem Bold{"Bold", &Style};
|
|
|
|
finalcut::FCheckMenuItem Italic{"Italic", &Style};
|
|
|
|
finalcut::FMenu BColor{"&Color", &Border};
|
|
|
|
finalcut::FMenu BStyle{"&Style", &Border};
|
|
|
|
finalcut::FRadioMenuItem BColor1{"Red", &BColor};
|
|
|
|
finalcut::FRadioMenuItem BColor2{"Blue", &BColor};
|
|
|
|
finalcut::FRadioMenuItem BStyle1{line, &BStyle};
|
|
|
|
finalcut::FRadioMenuItem BStyle2{"-------------", &BStyle};
|
|
|
|
finalcut::FRadioMenuItem BStyle3{"- - - - - - -", &BStyle};
|
|
|
|
finalcut::FRadioMenuItem BStyle4{"- - - - -", &BStyle};
|
|
|
|
finalcut::FStatusBar Statusbar{this};
|
|
|
|
finalcut::FLabel Headline1{this};
|
|
|
|
finalcut::FLabel Headline2{this};
|
|
|
|
finalcut::FLabel Info{this};
|
2015-12-08 21:05:00 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Menu::Menu (finalcut::FWidget* parent)
|
|
|
|
: finalcut::FDialog(parent)
|
2015-12-08 21:05:00 +01:00
|
|
|
{
|
2018-10-03 22:23:55 +02:00
|
|
|
// Menu bar itms
|
|
|
|
File.setStatusbarMessage ("File management commands");
|
|
|
|
Edit.setStatusbarMessage ("Cut-and-paste editing commands");
|
|
|
|
Choice.setStatusbarMessage ("Choice menu");
|
|
|
|
Window.setDisable();
|
|
|
|
Help.setStatusbarMessage ("Show version and copyright information");
|
2015-12-08 21:05:00 +01:00
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
// Menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
configureFileMenuItems();
|
|
|
|
configureEditMenuItems();
|
|
|
|
configureChoiceMenuItems();
|
2018-01-21 16:21:41 +01:00
|
|
|
|
|
|
|
// Add default menu item callback
|
2018-10-03 22:23:55 +02:00
|
|
|
defaultCallback (&Menubar);
|
2018-01-21 16:21:41 +01:00
|
|
|
|
|
|
|
// Statusbar at the bottom
|
2018-10-03 22:23:55 +02:00
|
|
|
Statusbar.setMessage("Status bar message");
|
2018-01-21 16:21:41 +01:00
|
|
|
|
|
|
|
// Headline labels
|
2018-10-03 22:23:55 +02:00
|
|
|
Headline1 << " Key ";
|
|
|
|
Headline1.ignorePadding();
|
2019-01-21 03:42:18 +01:00
|
|
|
Headline1.setGeometry(FPoint(3, 2), FSize(5, 1));
|
2018-10-03 22:23:55 +02:00
|
|
|
Headline1.setEmphasis();
|
2018-01-21 16:21:41 +01:00
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
Headline2 << " Function ";
|
|
|
|
Headline2.ignorePadding();
|
2019-01-21 03:42:18 +01:00
|
|
|
Headline2.setGeometry(FPoint(19, 2), FSize(10, 1));
|
2018-10-03 22:23:55 +02:00
|
|
|
Headline2.setEmphasis();
|
2018-01-21 16:21:41 +01:00
|
|
|
|
|
|
|
// Info label
|
2018-10-03 22:23:55 +02:00
|
|
|
Info << "<F10> Activate menu bar\n"
|
|
|
|
<< "<Ctrl>+<Space> Activate menu bar\n"
|
|
|
|
<< "<Meta>+<X> Exit";
|
2019-01-21 03:42:18 +01:00
|
|
|
Info.setGeometry(FPoint(2, 1), FSize(36, 3));
|
2018-01-21 16:21:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Menu::~Menu()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Menu::configureFileMenuItems()
|
2018-01-21 16:21:41 +01:00
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "File" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
New.addAccelerator (finalcut::fc::Fckey_n); // Ctrl + N
|
|
|
|
New.setStatusbarMessage ("Create a new file");
|
|
|
|
Open.addAccelerator (finalcut::fc::Fckey_o); // Ctrl + O
|
|
|
|
Open.setStatusbarMessage ("Locate and open a text file");
|
|
|
|
Save.addAccelerator (finalcut::fc::Fckey_s); // Ctrl + S
|
|
|
|
Save.setStatusbarMessage ("Save the file");
|
|
|
|
SaveAs.setStatusbarMessage ("Save the current file under a different name");
|
|
|
|
Close.addAccelerator (finalcut::fc::Fckey_w); // Ctrl + W
|
|
|
|
Close.setStatusbarMessage ("Close the current file");
|
|
|
|
Line1.setSeparator();
|
|
|
|
Print.addAccelerator (finalcut::fc::Fckey_p); // Ctrl + P
|
|
|
|
Print.setStatusbarMessage ("Print the current file");
|
|
|
|
Line2.setSeparator();
|
|
|
|
Quit.addAccelerator (finalcut::fc::Fmkey_x); // Meta/Alt + X
|
|
|
|
Quit.setStatusbarMessage ("Exit the program");
|
2015-12-08 21:05:00 +01:00
|
|
|
|
2018-01-21 16:21:41 +01:00
|
|
|
// Add quit menu item callback
|
2018-10-03 22:23:55 +02:00
|
|
|
Quit.addCallback
|
2018-01-21 16:21:41 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2018-09-20 23:59:01 +02:00
|
|
|
F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp)
|
2018-01-21 16:21:41 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Menu::configureEditMenuItems()
|
2018-01-21 16:21:41 +01:00
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Edit" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
Undo.setStatusbarMessage ("Undo the previous operation");
|
|
|
|
Redo.setDisable();
|
|
|
|
Line3.setSeparator();
|
|
|
|
Cut.setStatusbarMessage ( "Remove the input text "
|
|
|
|
"and put it in the clipboard" );
|
|
|
|
Copy.setStatusbarMessage ("Copy the input text into the clipboad");
|
|
|
|
Paste.setStatusbarMessage ("Insert text form clipboard");
|
|
|
|
Line4.setSeparator();
|
|
|
|
Search.setStatusbarMessage ("Search for text");
|
|
|
|
Next.setStatusbarMessage ("Repeat the last search command");
|
|
|
|
Line5.setSeparator();
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Menu::configureChoiceMenuItems()
|
2018-01-21 16:21:41 +01:00
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Choice" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
Color.setStatusbarMessage ("Choose a color");
|
|
|
|
Style.setStatusbarMessage ("Choose a Style");
|
|
|
|
Border.setStatusbarMessage ("Choose Border");
|
2015-12-08 21:05:00 +01:00
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
configureColorMenuItems();
|
|
|
|
configureStyleMenuItems();
|
|
|
|
configureBorderMenuItems();
|
2018-01-21 16:21:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Menu::configureColorMenuItems()
|
2018-01-21 16:21:41 +01:00
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Color" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
Color1.setStatusbarMessage ("Set text red");
|
|
|
|
Color2.setStatusbarMessage ("Set text green");
|
|
|
|
Color3.setStatusbarMessage ("Set text yellow");
|
|
|
|
Color4.setStatusbarMessage ("Set text brue");
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Menu::configureStyleMenuItems()
|
2018-01-21 16:21:41 +01:00
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Style" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
Bold.setStatusbarMessage ("Set text bold");
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Menu::configureBorderMenuItems()
|
2018-01-21 16:21:41 +01:00
|
|
|
{
|
2015-12-08 21:05:00 +01:00
|
|
|
// "Border" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
BColor.setStatusbarMessage ("Choose the border color");
|
|
|
|
BStyle.setStatusbarMessage ("Choose the border Style");
|
2015-12-08 21:05:00 +01:00
|
|
|
|
|
|
|
// "BColor" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
BColor1.setStatusbarMessage ("Set red border");
|
|
|
|
BColor2.setStatusbarMessage ("Set blue border");
|
2015-12-08 21:05:00 +01:00
|
|
|
|
|
|
|
// "BStyle" menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
BStyle1.setChecked();
|
|
|
|
BStyle1.setStatusbarMessage ("Set border 1");
|
|
|
|
BStyle2.setStatusbarMessage ("Set border 2");
|
|
|
|
BStyle3.setStatusbarMessage ("Set border 3");
|
|
|
|
BStyle4.setStatusbarMessage ("Set border 4");
|
2015-12-08 21:05:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Menu::defaultCallback (finalcut::FMenuList* mb)
|
2015-12-18 21:48:27 +01:00
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt i = 1; i <= mb->getCount(); i++)
|
2015-12-18 21:48:27 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto 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()
|
|
|
|
{
|
2019-02-07 23:05:50 +01:00
|
|
|
int pw = int(getDesktopWidth());
|
|
|
|
int ph = int(getDesktopHeight());
|
2018-10-14 06:25:33 +02:00
|
|
|
setX (1 + (pw - int(getWidth())) / 2, false);
|
|
|
|
setY (1 + (ph - int(getHeight())) / 4, false);
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::adjustSize();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 21:05:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Menu::onClose (finalcut::FCloseEvent* ev)
|
2015-12-08 21:05:00 +01:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2015-12-08 21:05:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
void Menu::cb_message (finalcut::FWidget* widget, FDataPtr)
|
2015-12-08 21:05:00 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menuitem = static_cast<finalcut::FMenuItem*>(widget);
|
|
|
|
auto text = menuitem->getText();
|
2015-12-08 21:05:00 +01:00
|
|
|
text = text.replace('&', "");
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FMessageBox::info ( this
|
|
|
|
, "Info"
|
|
|
|
, "You have chosen \"" + text + "\"" );
|
2015-12-08 21:05:00 +01:00
|
|
|
}
|
|
|
|
|
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
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication app (argc, argv);
|
2015-12-08 21:05:00 +01:00
|
|
|
|
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");
|
2019-01-21 03:42:18 +01:00
|
|
|
main_dlg.setGeometry ( FPoint(int(1 + (app.getWidth() - 40) / 2), 2)
|
|
|
|
, FSize(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();
|
|
|
|
}
|