finalcut/src/fmenuitem.cpp

852 lines
20 KiB
C++
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fmenuitem.cpp - Widget FMenuItem *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2015-2017 Markus Gans *
* *
* 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/>. *
***********************************************************************/
#include "final/fapplication.h"
#include "final/fdialog.h"
#include "final/fmenu.h"
#include "final/fmenubar.h"
#include "final/fmenulist.h"
#include "final/fmenuitem.h"
#include "final/fstatusbar.h"
//----------------------------------------------------------------------
// class FMenuItem
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
2015-09-22 04:18:20 +02:00
FMenuItem::FMenuItem (FWidget* parent)
: FWidget(parent)
, text()
, selected(false)
, separator(false)
, checkable(false)
2015-09-22 04:18:20 +02:00
, checked(false)
, radio_button(false)
, dialog_index(false)
, text_length(0)
2015-09-22 04:18:20 +02:00
, hotkey(0)
2015-11-12 01:33:16 +01:00
, accel_key(0)
2015-09-22 04:18:20 +02:00
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
//----------------------------------------------------------------------
2017-03-17 22:59:06 +01:00
FMenuItem::FMenuItem (const FString& txt, FWidget* parent)
2015-09-22 04:18:20 +02:00
: FWidget(parent)
, text(txt)
, selected(false)
, separator(false)
, checkable(false)
2015-09-22 04:18:20 +02:00
, checked(false)
, radio_button(false)
, dialog_index(false)
, text_length(0)
2015-09-22 04:18:20 +02:00
, hotkey(0)
2015-11-12 01:33:16 +01:00
, accel_key(0)
2015-09-22 04:18:20 +02:00
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
//----------------------------------------------------------------------
2017-03-17 22:59:06 +01:00
FMenuItem::FMenuItem (int k, const FString& txt, FWidget* parent)
2015-11-12 01:33:16 +01:00
: FWidget(parent)
, text(txt)
, selected(false)
, separator(false)
, checkable(false)
2015-11-12 01:33:16 +01:00
, checked(false)
, radio_button(false)
, dialog_index(false)
2015-11-12 01:33:16 +01:00
, text_length(0)
, hotkey(0)
, accel_key(k)
, menu(0)
, super_menu(0)
, associated_window(0)
2015-11-12 01:33:16 +01:00
{
init (parent);
}
//----------------------------------------------------------------------
FMenuItem::~FMenuItem() // destructor
{
delAccelerator();
// remove dialog list item callback from the dialog
if ( associated_window )
associated_window->delCallback(this);
}
// public methods of FMenuItem
//----------------------------------------------------------------------
bool FMenuItem::setEnable (bool on)
{
FWidget::setEnable(on);
FWidget* super = getSuperMenu();
if ( on )
{
if ( super && isMenuBar(super) )
2015-09-15 23:07:24 +02:00
{
// Meta + hotkey
super->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this);
2015-09-15 23:07:24 +02:00
}
}
else
{
if ( super && isMenuBar(super) )
super->delAccelerator (this);
}
2015-10-29 21:10:50 +01:00
return on;
}
2015-08-16 20:05:39 +02:00
//----------------------------------------------------------------------
bool FMenuItem::setFocus (bool on)
2015-08-16 20:05:39 +02:00
{
FWidget::setFocus(on);
2015-08-16 20:05:39 +02:00
if ( on )
2015-09-30 22:39:02 +02:00
{
if ( isEnabled() )
2015-09-30 22:39:02 +02:00
{
if ( ! selected )
{
FMenuList* menu_list = dynamic_cast<FMenuList*>(getSuperMenu());
setSelected();
if ( menu_list )
{
menu_list->unselectItem();
menu_list->setSelectedItem(this);
}
2015-08-16 20:05:39 +02:00
if ( getStatusBar() )
getStatusBar()->drawMessage();
FWidget* parent = getSuperMenu();
2015-09-15 23:07:24 +02:00
if ( isMenuBar(parent) )
{
2017-09-11 03:06:02 +02:00
FMenuBar* menubar_ptr = static_cast<FMenuBar*>(parent);
if ( menubar_ptr )
menubar_ptr->redraw();
}
else if ( isMenu(parent) )
{
2017-09-11 03:06:02 +02:00
FMenu* menu_ptr = static_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->redraw();
}
}
if ( getStatusBar() )
{
2017-03-26 20:40:04 +02:00
const FString& msg = getStatusbarMessage();
const FString& curMsg = getStatusBar()->getMessage();
2016-07-31 20:25:25 +02:00
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
}
}
else
{
if ( isEnabled() && getStatusBar() )
getStatusBar()->clearMessage();
}
return on;
}
//----------------------------------------------------------------------
void FMenuItem::setSelected()
{
if ( isEnabled() )
{
selected = true;
processActivate();
}
}
//----------------------------------------------------------------------
void FMenuItem::unsetSelected()
{
selected = false;
unsetCursorPos();
processDeactivate();
}
//----------------------------------------------------------------------
2017-03-17 22:59:06 +01:00
void FMenuItem::setText (const FString& txt)
{
text = txt;
text_length = text.getLength();
hotkey = hotKey();
if ( hotkey )
text_length--;
setWidth(int(text_length));
2016-06-12 23:06:58 +02:00
}
2015-11-12 01:33:16 +01:00
//----------------------------------------------------------------------
2015-11-12 01:33:16 +01:00
void FMenuItem::addAccelerator (int key, FWidget* obj)
{
FWidget* root = getRootWidget();
accelerator accel = { key, obj };
2015-11-12 01:33:16 +01:00
if ( root && root->accelerator_list )
2015-11-12 01:33:16 +01:00
{
accel_key = key;
root->accelerator_list->push_back(accel);
}
if ( isMenu(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenu* menu_ptr = static_cast<FMenu*>(super_menu);
if ( menu_ptr )
menu_ptr->calculateDimensions();
2015-11-12 01:33:16 +01:00
}
}
//----------------------------------------------------------------------
void FMenuItem::delAccelerator (FWidget* obj)
{
FWidget* root = getRootWidget();
if ( root
2017-11-26 22:37:18 +01:00
&& root->accelerator_list
&& ! root->accelerator_list->empty() )
2015-11-12 01:33:16 +01:00
{
FWidget::Accelerators::iterator iter;
iter = root->accelerator_list->begin();
2015-11-12 01:33:16 +01:00
while ( iter != root->accelerator_list->end() )
2015-11-12 01:33:16 +01:00
{
if ( iter->object == obj )
2015-11-12 01:33:16 +01:00
{
accel_key = 0;
iter = root->accelerator_list->erase(iter);
2015-11-12 01:33:16 +01:00
}
else
++iter;
2015-11-12 01:33:16 +01:00
}
}
if ( isMenu(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenu* menu_ptr = static_cast<FMenu*>(super_menu);
if ( menu_ptr )
menu_ptr->calculateDimensions();
}
2015-11-12 01:33:16 +01:00
}
//----------------------------------------------------------------------
void FMenuItem::openMenu()
{
FMenu* dd_menu; // Drop-down menu
FMenu* open_menu;
if ( ! hasMenu() )
return;
dd_menu = getMenu(); // Drop-down menu
if ( dd_menu->isVisible() )
return;
open_menu = static_cast<FMenu*>(getOpenMenu());
if ( open_menu && open_menu != dd_menu )
{
open_menu->hide();
open_menu->hideSubMenus();
}
if ( dialog_index )
createDialogList (dd_menu);
setOpenMenu(dd_menu);
dd_menu->setVisible();
dd_menu->show();
2017-08-12 20:10:27 +02:00
dd_menu->raiseWindow();
dd_menu->redraw();
updateTerminal();
flush_out();
}
//----------------------------------------------------------------------
2015-10-29 21:10:50 +01:00
void FMenuItem::onKeyPress (FKeyEvent* ev)
{
if ( ! super_menu )
return;
if ( isMenu(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenu* smenu = static_cast<FMenu*>(super_menu);
smenu->onKeyPress(ev);
}
2015-10-29 21:10:50 +01:00
if ( isMenuBar(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenuBar* mbar = static_cast<FMenuBar*>(super_menu);
if ( mbar )
{
if ( mbar->hotkeyMenu(ev) )
return;
mbar->onKeyPress(ev);
}
}
}
2016-06-12 23:06:58 +02:00
//----------------------------------------------------------------------
void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
{
if ( ! super_menu )
return;
const FPoint& t = ev->getTermPos();
int b = ev->getButton();
if ( isMenu(super_menu) )
2016-06-12 23:06:58 +02:00
{
2017-09-11 03:06:02 +02:00
FMenu* smenu = static_cast<FMenu*>(super_menu);
const FPoint& p2 = smenu->termToWidgetPos(t);
2016-06-12 23:06:58 +02:00
try
2016-06-12 23:06:58 +02:00
{
FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event
, p2, t, b );
smenu->onMouseDoubleClick(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc "
<< ex.what() << std::endl;
2016-06-12 23:06:58 +02:00
}
}
2016-06-12 23:06:58 +02:00
if ( isMenuBar(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenuBar* mbar = static_cast<FMenuBar*>(super_menu);
if ( mbar )
{
const FPoint& p2 = mbar->termToWidgetPos(t);
2017-08-12 22:55:29 +02:00
try
{
2017-09-11 03:06:02 +02:00
FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event
, p2, t, b );
2017-08-12 22:55:29 +02:00
mbar->onMouseDoubleClick(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
2017-09-11 03:06:02 +02:00
std::cerr << "not enough memory to alloc "
<< ex.what() << std::endl;
2017-08-12 22:55:29 +02:00
}
2016-06-12 23:06:58 +02:00
}
}
2016-06-12 23:06:58 +02:00
if ( isWindowsMenu(super_menu) )
{
2017-09-11 03:06:02 +02:00
FDialog* dgl = static_cast<FDialog*>(super_menu);
if ( dgl )
{
const FPoint& p2 = dgl->termToWidgetPos(t);
2017-08-12 22:55:29 +02:00
try
{
2017-09-11 03:06:02 +02:00
FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event
, p2, t, b );
2017-08-12 22:55:29 +02:00
dgl->onMouseDoubleClick(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
2017-09-11 03:06:02 +02:00
std::cerr << "not enough memory to alloc "
<< ex.what() << std::endl;
2017-08-12 22:55:29 +02:00
}
2016-06-12 23:06:58 +02:00
}
}
}
2015-09-28 04:31:29 +02:00
//----------------------------------------------------------------------
void FMenuItem::onMouseDown (FMouseEvent* ev)
{
if ( ! super_menu )
return;
const FPoint& t = ev->getTermPos();
int b = ev->getButton();
if ( isMenu(super_menu) )
2015-09-30 22:39:02 +02:00
{
2017-09-11 03:06:02 +02:00
FMenu* smenu = static_cast<FMenu*>(super_menu);
const FPoint& p2 = smenu->termToWidgetPos(t);
try
2015-10-01 04:44:26 +02:00
{
FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event
, p2, t, b );
smenu->onMouseDown(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc "
<< ex.what() << std::endl;
2015-10-01 04:44:26 +02:00
}
}
2015-10-01 03:48:58 +02:00
if ( isMenuBar(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenuBar* mbar = static_cast<FMenuBar*>(super_menu);
if ( mbar )
{
const FPoint& p2 = mbar->termToWidgetPos(t);
2017-08-12 22:55:29 +02:00
try
{
2017-09-11 03:06:02 +02:00
FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event
, p2, t, b );
2017-08-12 22:55:29 +02:00
mbar->onMouseDown(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
2017-09-11 03:06:02 +02:00
std::cerr << "not enough memory to alloc "
<< ex.what() << std::endl;
2017-08-12 22:55:29 +02:00
}
2015-10-01 04:44:26 +02:00
}
}
2016-06-12 23:06:58 +02:00
if ( isWindowsMenu(super_menu) )
{
2017-09-11 03:06:02 +02:00
FDialog* dgl = static_cast<FDialog*>(super_menu);
if ( dgl )
{
const FPoint& p2 = dgl->termToWidgetPos(t);
2017-08-12 22:55:29 +02:00
try
{
2017-09-11 03:06:02 +02:00
FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event
, p2, t, b );
2017-08-12 22:55:29 +02:00
dgl->onMouseDown(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
2017-09-11 03:06:02 +02:00
std::cerr << "not enough memory to alloc "
<< ex.what() << std::endl;
2017-08-12 22:55:29 +02:00
}
2016-06-12 23:06:58 +02:00
}
}
2015-09-28 04:31:29 +02:00
}
//----------------------------------------------------------------------
void FMenuItem::onMouseUp (FMouseEvent* ev)
{
if ( ! super_menu )
return;
const FPoint& t = ev->getTermPos();
int b = ev->getButton();
if ( isMenu(super_menu) )
2015-09-30 22:39:02 +02:00
{
2017-09-11 03:06:02 +02:00
FMenu* smenu = static_cast<FMenu*>(super_menu);
const FPoint& p2 = smenu->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b);
smenu->onMouseUp(_ev);
delete _ev;
}
2015-10-01 03:48:58 +02:00
if ( isMenuBar(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenuBar* mbar = static_cast<FMenuBar*>(super_menu);
const FPoint& p2 = mbar->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b);
mbar->onMouseUp(_ev);
delete _ev;
}
2016-06-12 23:06:58 +02:00
if ( isWindowsMenu(super_menu) )
{
2017-09-11 03:06:02 +02:00
FDialog* dgl = static_cast<FDialog*>(super_menu);
const FPoint& p2 = dgl->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b);
dgl->onMouseUp(_ev);
delete _ev;
}
2015-09-28 04:31:29 +02:00
}
//----------------------------------------------------------------------
void FMenuItem::onMouseMove (FMouseEvent* ev)
{
if ( ! super_menu )
return;
const FPoint& t = ev->getTermPos();
int b = ev->getButton();
if ( isMenu(super_menu) )
2015-09-30 22:39:02 +02:00
{
2017-09-11 03:06:02 +02:00
FMenu* smenu = static_cast<FMenu*>(super_menu);
const FPoint& p2 = smenu->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b);
smenu->onMouseMove(_ev);
delete _ev;
}
2015-10-01 03:48:58 +02:00
if ( isMenuBar(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenuBar* mbar = static_cast<FMenuBar*>(super_menu);
const FPoint& p2 = mbar->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b);
mbar->onMouseMove(_ev);
delete _ev;
}
2015-09-28 04:31:29 +02:00
if ( isWindowsMenu(super_menu) )
{
2017-09-11 03:06:02 +02:00
FDialog* dgl = static_cast<FDialog*>(super_menu);
const FPoint& p2 = dgl->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b);
dgl->onMouseMove(_ev);
delete _ev;
}
2015-09-28 04:31:29 +02:00
}
2015-10-29 21:10:50 +01:00
//----------------------------------------------------------------------
void FMenuItem::onAccel (FAccelEvent* ev)
{
if ( ! isEnabled() || isSelected() )
return;
if ( ! super_menu || ! isMenuBar(super_menu) )
2015-10-29 21:10:50 +01:00
{
processClicked();
return;
}
2017-09-11 03:06:02 +02:00
FMenuBar* mbar = static_cast<FMenuBar*>(super_menu);
if ( menu )
{
FWidget* focused_widget;
if ( mbar->getSelectedItem() )
mbar->getSelectedItem()->unsetSelected();
setSelected();
mbar->selected_item = this;
openMenu();
focused_widget = static_cast<FWidget*>(ev->focusedWidget());
2017-06-14 01:23:10 +02:00
if ( focused_widget && focused_widget->isWidget() )
2017-06-11 17:47:50 +02:00
{
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
2017-08-24 22:58:34 +02:00
}
menu->unselectItem();
menu->selectFirstItem();
2017-08-24 22:58:34 +02:00
if ( menu->getSelectedItem() )
menu->getSelectedItem()->setFocus();
2017-08-24 22:58:34 +02:00
if ( focused_widget && focused_widget->isWidget() )
2017-06-14 01:23:10 +02:00
focused_widget->redraw();
2017-08-24 22:58:34 +02:00
menu->redraw();
2017-06-11 17:47:50 +02:00
2017-08-24 22:58:34 +02:00
if ( getStatusBar() )
getStatusBar()->drawMessage();
mbar->redraw();
mbar->drop_down = true;
}
else
{
unsetSelected();
mbar->selected_item = 0;
mbar->redraw();
processClicked();
mbar->drop_down = false;
2015-10-29 21:10:50 +01:00
}
ev->accept();
2015-10-29 21:10:50 +01:00
}
//----------------------------------------------------------------------
void FMenuItem::onFocusIn (FFocusEvent*)
{
if ( getStatusBar() )
getStatusBar()->drawMessage();
2015-10-29 21:10:50 +01:00
}
//----------------------------------------------------------------------
void FMenuItem::onFocusOut (FFocusEvent*)
{
unsetSelected();
if ( super_menu && isMenuBar(super_menu) )
{
2017-09-11 03:06:02 +02:00
FMenuBar* mbar = static_cast<FMenuBar*>(super_menu);
mbar->redraw();
}
if ( getStatusBar() )
2015-10-29 21:10:50 +01:00
{
getStatusBar()->clearMessage();
getStatusBar()->drawMessage();
2015-10-29 21:10:50 +01:00
}
}
// protected methods of FMenuItem
2015-10-29 21:10:50 +01:00
//----------------------------------------------------------------------
bool FMenuItem::isWindowsMenu (FWidget* w) const
2015-10-29 21:10:50 +01:00
{
return ( w ) ? w->isDialogWidget() : false;
}
2015-10-29 21:10:50 +01:00
//----------------------------------------------------------------------
bool FMenuItem::isMenuBar (FWidget* w) const
{
return ( w ) ? w->isInstanceOf("FMenuBar") : false;
}
2015-10-29 21:10:50 +01:00
//----------------------------------------------------------------------
bool FMenuItem::isMenu (FWidget* w) const
{
if ( ! w )
return false;
bool m1 = w->isInstanceOf("FMenu");
bool m2 = w->isInstanceOf("FDialogListMenu");
return bool( m1 || m2 );
2015-10-29 21:10:50 +01:00
}
// private methods of FMenuItem
2015-10-29 21:10:50 +01:00
//----------------------------------------------------------------------
void FMenuItem::init (FWidget* parent)
2015-10-29 21:10:50 +01:00
{
text_length = text.getLength();
hotkey = hotKey();
2015-10-29 21:10:50 +01:00
if ( hotkey )
text_length--;
setGeometry (1, 1, int(text_length + 2), 1, false);
2015-11-07 23:16:09 +01:00
if ( ! parent )
return;
FMenuList* menu_list;
setSuperMenu (parent);
if ( accel_key )
addAccelerator (accel_key);
menu_list = dynamic_cast<FMenuList*>(parent);
if ( menu_list )
menu_list->insert(this);
if ( isMenuBar(parent) ) // Parent is menubar
{
FMenuBar* menubar_ptr = static_cast<FMenuBar*>(parent);
menubar_ptr->calculateDimensions();
if ( hotkey ) // Meta + hotkey
menubar_ptr->addAccelerator ( fc::Fmkey_meta + std::tolower(hotkey)
, this );
2015-10-29 21:10:50 +01:00
addCallback // for this element
(
"deactivate",
F_METHOD_CALLBACK (parent, &FMenuBar::cb_item_deactivated)
);
}
else if ( isMenu(parent) ) // Parent is menu
{
FMenu* menu_ptr = static_cast<FMenu*>(parent);
menu_ptr->calculateDimensions();
2015-10-29 21:10:50 +01:00
}
}
//----------------------------------------------------------------------
uChar FMenuItem::hotKey()
{
uInt length;
if ( text.isEmpty() )
return 0;
length = text.getLength();
for (uInt i = 0; i < length; i++)
2015-08-22 18:53:52 +02:00
{
try
{
if ( i + 1 < length && text[i] == '&' )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
2015-08-22 18:53:52 +02:00
}
return 0;
}
//----------------------------------------------------------------------
void FMenuItem::processActivate()
2015-09-30 22:39:02 +02:00
{
emitCallback("activate");
2015-09-30 22:39:02 +02:00
}
//----------------------------------------------------------------------
void FMenuItem::processDeactivate()
{
emitCallback("deactivate");
}
//----------------------------------------------------------------------
void FMenuItem::createDialogList (FMenu* winmenu)
{
winmenu->clear();
if ( dialog_list && ! dialog_list->empty() )
{
widgetList::const_iterator iter, first;
iter = first = dialog_list->begin();
while ( iter != dialog_list->end() && *iter )
{
2017-09-11 03:06:02 +02:00
FDialog* win = static_cast<FDialog*>(*iter);
if ( win )
{
2017-08-12 22:55:29 +02:00
FMenuItem* win_item;
int n = int(std::distance(first, iter));
// get the dialog title
2017-03-26 20:40:04 +02:00
const FString& name = win->getText();
2017-08-12 22:55:29 +02:00
try
{
// create a new dialog list item
win_item = new FMenuItem (name, winmenu);
}
catch (const std::bad_alloc& ex)
{
2017-09-11 03:06:02 +02:00
std::cerr << "not enough memory to alloc "
<< ex.what() << std::endl;
2017-08-12 23:11:21 +02:00
return;
2017-08-12 22:55:29 +02:00
}
if ( n < 9 )
2017-09-11 03:06:02 +02:00
win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9
win_item->addCallback
(
"clicked",
F_METHOD_CALLBACK (win_item, &FMenuItem::cb_switchToDialog),
2017-09-11 03:06:02 +02:00
static_cast<FWidget::data_ptr>(win)
);
win->addCallback
(
"destroy",
F_METHOD_CALLBACK (win_item, &FMenuItem::cb_destroyDialog)
);
win_item->associated_window = win;
}
++iter;
}
}
winmenu->calculateDimensions();
}
2015-09-30 22:39:02 +02:00
//----------------------------------------------------------------------
void FMenuItem::cb_switchToDialog (FWidget*, data_ptr data)
{
FDialog* win = static_cast<FDialog*>(data);
if ( win )
{
FWidget* focus_widget = getFocusWidget();
FAccelEvent a_ev (fc::Accelerator_Event, focus_widget);
FApplication::sendEvent (win, &a_ev);
}
}
//----------------------------------------------------------------------
void FMenuItem::cb_destroyDialog (FWidget* widget, data_ptr)
{
FDialog* win = static_cast<FDialog*>(widget);
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
if ( win && fapp )
{
delAccelerator(win);
delCallback(win);
associated_window = 0;
}
2015-08-16 20:05:39 +02:00
}
//----------------------------------------------------------------------
void FMenuItem::processClicked()
2015-08-16 20:05:39 +02:00
{
emitCallback("clicked");
}