2015-09-25 21:37:19 +02:00
|
|
|
// File: fmenuitem.cpp
|
|
|
|
// Provides: class FMenuItem
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2015-10-29 21:10:50 +01:00
|
|
|
#include "fapp.h"
|
2016-06-12 23:06:58 +02:00
|
|
|
#include "fdialog.h"
|
2015-09-15 23:07:24 +02:00
|
|
|
#include "fmenu.h"
|
2015-08-16 20:05:39 +02:00
|
|
|
#include "fmenubar.h"
|
2015-08-09 23:47:08 +02:00
|
|
|
#include "fmenulist.h"
|
2015-10-10 03:14:14 +02:00
|
|
|
#include "fmenuitem.h"
|
2015-10-29 21:10:50 +01:00
|
|
|
#include "fstatusbar.h"
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FMenuItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FMenuItem::FMenuItem (FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text()
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
2015-11-15 19:46:33 +01:00
|
|
|
, checkable(false)
|
2015-09-22 04:18:20 +02:00
|
|
|
, checked(false)
|
2016-07-03 20:08:39 +02:00
|
|
|
, radio_button(false)
|
2016-07-14 23:55:22 +02:00
|
|
|
, dialog_index(false)
|
2015-09-27 16:00:13 +02:00
|
|
|
, 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)
|
2016-07-30 23:00:37 +02:00
|
|
|
, associated_window(0)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FMenuItem::FMenuItem (FString& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
2015-11-15 19:46:33 +01:00
|
|
|
, checkable(false)
|
2015-09-22 04:18:20 +02:00
|
|
|
, checked(false)
|
2016-07-03 20:08:39 +02:00
|
|
|
, radio_button(false)
|
2016-07-14 23:55:22 +02:00
|
|
|
, dialog_index(false)
|
2015-09-27 16:00:13 +02:00
|
|
|
, 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)
|
2016-07-30 23:00:37 +02:00
|
|
|
, associated_window(0)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FMenuItem::FMenuItem (const std::string& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
2015-11-15 19:46:33 +01:00
|
|
|
, checkable(false)
|
2015-09-22 04:18:20 +02:00
|
|
|
, checked(false)
|
2016-07-03 20:08:39 +02:00
|
|
|
, radio_button(false)
|
2016-07-14 23:55:22 +02:00
|
|
|
, dialog_index(false)
|
2015-09-27 16:00:13 +02:00
|
|
|
, 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)
|
2016-07-30 23:00:37 +02:00
|
|
|
, associated_window(0)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FMenuItem::FMenuItem (const char* txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
2015-11-15 19:46:33 +01:00
|
|
|
, checkable(false)
|
2015-09-22 04:18:20 +02:00
|
|
|
, checked(false)
|
2016-07-03 20:08:39 +02:00
|
|
|
, radio_button(false)
|
2016-07-14 23:55:22 +02:00
|
|
|
, dialog_index(false)
|
2015-09-27 16:00:13 +02:00
|
|
|
, text_length(0)
|
2015-09-22 04:18:20 +02:00
|
|
|
, hotkey(0)
|
2015-11-12 01:33:16 +01:00
|
|
|
, accel_key(0)
|
|
|
|
, menu(0)
|
|
|
|
, super_menu(0)
|
2016-07-30 23:00:37 +02:00
|
|
|
, associated_window(0)
|
2015-11-12 01:33:16 +01:00
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
2015-11-15 19:46:33 +01:00
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuItem::FMenuItem (int k, FString& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
2015-11-15 19:46:33 +01:00
|
|
|
, checkable(false)
|
2015-11-12 01:33:16 +01:00
|
|
|
, checked(false)
|
2016-07-03 20:08:39 +02:00
|
|
|
, radio_button(false)
|
2016-07-14 23:55:22 +02:00
|
|
|
, dialog_index(false)
|
2015-11-12 01:33:16 +01:00
|
|
|
, text_length(0)
|
|
|
|
, hotkey(0)
|
|
|
|
, accel_key(k)
|
|
|
|
, menu(0)
|
|
|
|
, super_menu(0)
|
2016-07-30 23:00:37 +02:00
|
|
|
, associated_window(0)
|
2015-11-12 01:33:16 +01:00
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuItem::FMenuItem (int k, const std::string& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
2015-11-15 19:46:33 +01:00
|
|
|
, checkable(false)
|
2015-11-12 01:33:16 +01:00
|
|
|
, checked(false)
|
2016-07-03 20:08:39 +02:00
|
|
|
, radio_button(false)
|
2016-07-14 23:55:22 +02:00
|
|
|
, dialog_index(false)
|
2015-11-12 01:33:16 +01:00
|
|
|
, text_length(0)
|
|
|
|
, hotkey(0)
|
|
|
|
, accel_key(k)
|
2015-09-22 04:18:20 +02:00
|
|
|
, menu(0)
|
|
|
|
, super_menu(0)
|
2016-07-30 23:00:37 +02:00
|
|
|
, associated_window(0)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuItem::FMenuItem (int k, const char* txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
2015-11-15 19:46:33 +01:00
|
|
|
, checkable(false)
|
2015-11-12 01:33:16 +01:00
|
|
|
, checked(false)
|
2016-07-03 20:08:39 +02:00
|
|
|
, radio_button(false)
|
2016-07-14 23:55:22 +02:00
|
|
|
, dialog_index(false)
|
2015-11-12 01:33:16 +01:00
|
|
|
, text_length(0)
|
|
|
|
, hotkey(0)
|
|
|
|
, accel_key(k)
|
|
|
|
, menu(0)
|
|
|
|
, super_menu(0)
|
2016-07-30 23:00:37 +02:00
|
|
|
, associated_window(0)
|
2015-11-12 01:33:16 +01:00
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
2015-11-15 19:46:33 +01:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuItem::~FMenuItem() // destructor
|
2015-11-12 23:14:12 +01:00
|
|
|
{
|
|
|
|
delAccelerator();
|
2016-07-30 23:00:37 +02:00
|
|
|
|
|
|
|
// remove dialog list item callback from the dialog
|
|
|
|
if ( associated_window )
|
|
|
|
associated_window->delCallback(this);
|
2015-11-12 23:14:12 +01:00
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FMenuItem
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FMenuItem::setEnable (bool on)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::setEnable(on);
|
|
|
|
FWidget* super = getSuperMenu();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( on )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags |= fc::active;
|
2015-09-18 21:38:26 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( super && isMenuBar(super) )
|
2015-09-15 23:07:24 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
// Meta + hotkey
|
|
|
|
super->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this);
|
2015-09-15 23:07:24 +02:00
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
flags &= ~fc::active;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( super && isMenuBar(super) )
|
|
|
|
super->delAccelerator (this);
|
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return on;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 20:05:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FMenuItem::setFocus (bool on)
|
2015-08-16 20:05:39 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::setFocus(on);
|
2015-08-16 20:05:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( on )
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags |= fc::focus;
|
|
|
|
|
|
|
|
if ( isEnabled() )
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! selected )
|
|
|
|
{
|
|
|
|
FMenuList* menu_list = dynamic_cast<FMenuList*>(getSuperMenu());
|
|
|
|
setSelected();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( menu_list )
|
|
|
|
{
|
|
|
|
menu_list->unselectItem();
|
|
|
|
menu_list->setSelectedItem(this);
|
|
|
|
}
|
2015-08-16 20:05:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget* parent = getSuperMenu();
|
2015-09-15 23:07:24 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isMenuBar(parent) )
|
|
|
|
{
|
|
|
|
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
|
2016-07-03 20:08:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( menubar_ptr )
|
|
|
|
menubar_ptr->redraw();
|
|
|
|
}
|
|
|
|
else if ( isMenu(parent) )
|
|
|
|
{
|
|
|
|
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
|
2016-07-03 20:08:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( menu_ptr )
|
|
|
|
menu_ptr->redraw();
|
|
|
|
}
|
|
|
|
}
|
2016-07-16 20:39:38 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2016-07-03 20:08:39 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FString msg = getStatusbarMessage();
|
|
|
|
FString curMsg = getStatusBar()->getMessage();
|
2016-07-31 20:25:25 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( curMsg != msg )
|
|
|
|
getStatusBar()->setMessage(msg);
|
2016-07-03 20:08:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
flags &= ~fc::focus;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() && getStatusBar() )
|
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return on;
|
2016-07-03 20:08:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::setSelected()
|
2016-07-03 20:08:39 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
2016-07-03 20:08:39 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
selected = true;
|
|
|
|
processActivate();
|
2016-07-03 20:08:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-24 20:18:23 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::unsetSelected()
|
2016-07-24 20:18:23 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
selected = false;
|
2016-11-12 22:59:48 +01:00
|
|
|
unsetCursorPos();
|
2016-11-02 00:37:58 +01:00
|
|
|
processDeactivate();
|
2016-07-24 20:18:23 +02:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::setText (FString& txt)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
text = txt;
|
|
|
|
text_length = text.getLength();
|
|
|
|
hotkey = hotKey();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( hotkey )
|
|
|
|
text_length--;
|
2015-11-15 19:46:33 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setWidth(int(text_length));
|
2016-06-12 23:06:58 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::setText (const std::string& txt)
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FString s = FString(txt);
|
|
|
|
setText (s);
|
2015-09-30 22:39:02 +02:00
|
|
|
}
|
|
|
|
|
2015-08-22 18:53:52 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::setText (const char* txt)
|
2015-08-22 18:53:52 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FString s = FString(txt);
|
|
|
|
setText (s);
|
2015-08-22 18:53:52 +02:00
|
|
|
}
|
2015-11-12 01:33:16 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
void FMenuItem::addAccelerator (int key, FWidget* obj)
|
|
|
|
{
|
2016-07-14 00:12:16 +02:00
|
|
|
FWidget* root = getRootWidget();
|
|
|
|
accelerator accel = { key, obj };
|
2015-11-12 01:33:16 +01:00
|
|
|
|
2016-07-14 00:12:16 +02:00
|
|
|
if ( root && root->accelerator_list )
|
2015-11-12 01:33:16 +01:00
|
|
|
{
|
2016-07-14 00:12:16 +02:00
|
|
|
accel_key = key;
|
|
|
|
root->accelerator_list->push_back(accel);
|
2015-11-12 23:14:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isMenu(super_menu) )
|
|
|
|
{
|
|
|
|
FMenu* menu_ptr = dynamic_cast<FMenu*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-12 23:14:12 +01:00
|
|
|
if ( menu_ptr )
|
2016-09-27 00:46:05 +02:00
|
|
|
menu_ptr->calculateDimensions();
|
2015-11-12 01:33:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::delAccelerator (FWidget* obj)
|
|
|
|
{
|
2016-07-14 00:12:16 +02:00
|
|
|
FWidget* root = getRootWidget();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( root
|
|
|
|
&& root->accelerator_list
|
|
|
|
&& ! root->accelerator_list->empty() )
|
2015-11-12 01:33:16 +01:00
|
|
|
{
|
2016-07-14 00:12:16 +02:00
|
|
|
FWidget::Accelerators::iterator iter;
|
|
|
|
iter = root->accelerator_list->begin();
|
2015-11-12 01:33:16 +01:00
|
|
|
|
2016-07-14 00:12:16 +02:00
|
|
|
while ( iter != root->accelerator_list->end() )
|
2015-11-12 01:33:16 +01:00
|
|
|
{
|
2016-07-14 00:12:16 +02:00
|
|
|
if ( iter->object == obj )
|
2015-11-12 01:33:16 +01:00
|
|
|
{
|
2016-07-14 00:12:16 +02:00
|
|
|
accel_key = 0;
|
|
|
|
iter = root->accelerator_list->erase(iter);
|
2015-11-12 01:33:16 +01:00
|
|
|
}
|
2016-07-14 00:12:16 +02:00
|
|
|
else
|
|
|
|
++iter;
|
2015-11-12 01:33:16 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-12 23:14:12 +01:00
|
|
|
|
|
|
|
if ( isMenu(super_menu) )
|
|
|
|
{
|
|
|
|
FMenu* menu_ptr = dynamic_cast<FMenu*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-12 23:14:12 +01:00
|
|
|
if ( menu_ptr )
|
2016-09-27 00:46:05 +02:00
|
|
|
menu_ptr->calculateDimensions();
|
2015-11-12 23:14:12 +01:00
|
|
|
}
|
2015-11-12 01:33:16 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +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();
|
|
|
|
dd_menu->raiseWindow(dd_menu);
|
|
|
|
dd_menu->redraw();
|
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-10-29 21:10:50 +01:00
|
|
|
void FMenuItem::onKeyPress (FKeyEvent* ev)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! super_menu )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( isMenu(super_menu) )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( smenu )
|
|
|
|
smenu->onKeyPress(ev);
|
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
|
|
|
{
|
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( mbar )
|
|
|
|
{
|
|
|
|
if ( mbar->hotkeyMenu(ev) )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
mbar->onKeyPress(ev);
|
2015-10-23 00:24:20 +02:00
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 23:06:58 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
|
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
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
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
2016-06-12 23:06:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( smenu )
|
2016-06-12 23:06:58 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
const FPoint& p2 = smenu->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
|
|
|
|
smenu->onMouseDoubleClick(_ev);
|
|
|
|
delete _ev;
|
2016-06-12 23:06:58 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2016-06-12 23:06:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
|
|
|
{
|
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( mbar )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = mbar->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
|
|
|
|
mbar->onMouseDoubleClick(_ev);
|
|
|
|
delete _ev;
|
2016-06-12 23:06:58 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2016-06-12 23:06:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isWindowsMenu(super_menu) )
|
|
|
|
{
|
|
|
|
FDialog* dgl = dynamic_cast<FDialog*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( dgl )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = dgl->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
|
|
|
|
dgl->onMouseDoubleClick(_ev);
|
|
|
|
delete _ev;
|
2016-06-12 23:06:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 04:31:29 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onMouseDown (FMouseEvent* ev)
|
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
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
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( smenu )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
const FPoint& p2 = smenu->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
|
|
|
|
smenu->onMouseDown(_ev);
|
|
|
|
delete _ev;
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
|
|
|
{
|
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( mbar )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = mbar->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
|
|
|
|
mbar->onMouseDown(_ev);
|
|
|
|
delete _ev;
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2016-06-12 23:06:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isWindowsMenu(super_menu) )
|
|
|
|
{
|
|
|
|
FDialog* dgl = dynamic_cast<FDialog*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( dgl )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = dgl->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
|
|
|
|
dgl->onMouseDown(_ev);
|
|
|
|
delete _ev;
|
2016-06-12 23:06:58 +02:00
|
|
|
}
|
2015-10-10 03:14:14 +02:00
|
|
|
}
|
2015-09-28 04:31:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onMouseUp (FMouseEvent* ev)
|
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
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
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( smenu )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
const FPoint& p2 = smenu->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b);
|
|
|
|
smenu->onMouseUp(_ev);
|
|
|
|
delete _ev;
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
|
|
|
{
|
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( mbar )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = mbar->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b);
|
|
|
|
mbar->onMouseUp(_ev);
|
|
|
|
delete _ev;
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2016-06-12 23:06:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isWindowsMenu(super_menu) )
|
|
|
|
{
|
|
|
|
FDialog* dgl = dynamic_cast<FDialog*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( dgl )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = dgl->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b);
|
|
|
|
dgl->onMouseUp(_ev);
|
|
|
|
delete _ev;
|
2016-06-12 23:06:58 +02:00
|
|
|
}
|
2015-10-10 03:14:14 +02:00
|
|
|
}
|
2015-09-28 04:31:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onMouseMove (FMouseEvent* ev)
|
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
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
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( smenu )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
const FPoint& p2 = smenu->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b);
|
|
|
|
smenu->onMouseMove(_ev);
|
|
|
|
delete _ev;
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
|
|
|
{
|
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( mbar )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = mbar->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b);
|
|
|
|
mbar->onMouseMove(_ev);
|
|
|
|
delete _ev;
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2015-09-28 04:31:29 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( isWindowsMenu(super_menu) )
|
|
|
|
{
|
|
|
|
FDialog* dgl = dynamic_cast<FDialog*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( dgl )
|
|
|
|
{
|
|
|
|
const FPoint& p2 = dgl->termToWidgetPos(t);
|
|
|
|
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b);
|
|
|
|
dgl->onMouseMove(_ev);
|
|
|
|
delete _ev;
|
2016-06-12 23:06:58 +02:00
|
|
|
}
|
2015-10-10 03:14:14 +02:00
|
|
|
}
|
2015-09-28 04:31:29 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 21:10:50 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! isEnabled() || isSelected() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! super_menu || ! isMenuBar(super_menu) )
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
processClicked();
|
|
|
|
return;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
|
|
|
|
|
|
|
if ( ! mbar )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( menu )
|
|
|
|
{
|
|
|
|
FWidget* focused_widget;
|
|
|
|
|
|
|
|
if ( mbar->getSelectedItem() )
|
|
|
|
mbar->getSelectedItem()->unsetSelected();
|
|
|
|
|
|
|
|
setSelected();
|
|
|
|
mbar->selected_item = this;
|
|
|
|
openMenu();
|
|
|
|
|
|
|
|
focused_widget = static_cast<FWidget*>(ev->focusedWidget());
|
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
|
|
|
menu->unselectItem();
|
|
|
|
menu->selectFirstItem();
|
|
|
|
|
|
|
|
if ( menu->getSelectedItem() )
|
|
|
|
menu->getSelectedItem()->setFocus();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
|
|
|
|
menu->redraw();
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2016-10-17 08:44:38 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
ev->accept();
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onFocusIn (FFocusEvent*)
|
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onFocusOut (FFocusEvent*)
|
|
|
|
{
|
2015-11-05 23:25:21 +01:00
|
|
|
unsetSelected();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( super_menu && isMenuBar(super_menu) )
|
|
|
|
{
|
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( mbar )
|
|
|
|
mbar->redraw();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
getStatusBar()->drawMessage();
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// protected methods of FMenuItem
|
2015-10-29 21:10:50 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FMenuItem::isWindowsMenu (FWidget* w) const
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
return ( ! w ) ? false : w->isDialogWidget();
|
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuItem::isMenuBar (FWidget* w) const
|
|
|
|
{
|
|
|
|
if ( ! w )
|
|
|
|
return false;
|
2015-10-29 21:10:50 +01:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
return bool( std::strcmp ( w->getClassName()
|
|
|
|
, const_cast<char*>("FMenuBar") ) == 0 );
|
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuItem::isMenu (FWidget* w) const
|
|
|
|
{
|
|
|
|
if ( ! w )
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
bool m1 = ( std::strcmp ( w->getClassName()
|
|
|
|
, const_cast<char*>("FMenu") ) == 0 );
|
|
|
|
bool m2 = ( std::strcmp ( w->getClassName()
|
|
|
|
, const_cast<char*>("FDialogListMenu") ) == 0 );
|
|
|
|
return bool( m1 || m2 );
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// private methods of FMenuItem
|
2015-10-29 21:10:50 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::init (FWidget* parent)
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
text_length = text.getLength();
|
|
|
|
hotkey = hotKey();
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( hotkey )
|
|
|
|
text_length--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setGeometry (1,1,int(text_length+2),1, false);
|
2015-11-07 23:16:09 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( parent )
|
|
|
|
{
|
|
|
|
FMenuList* menu_list;
|
|
|
|
setSuperMenu (parent);
|
2015-11-07 23:16:09 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( accel_key )
|
|
|
|
addAccelerator (accel_key);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
menu_list = dynamic_cast<FMenuList*>(parent);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( menu_list )
|
|
|
|
menu_list->insert(this);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isMenuBar(parent) ) // Parent is menubar
|
|
|
|
{
|
|
|
|
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
|
2015-11-12 23:14:12 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( menubar_ptr )
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
menubar_ptr->calculateDimensions();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( hotkey ) // Meta + hotkey
|
|
|
|
menubar_ptr->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this);
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
this->addCallback
|
|
|
|
(
|
|
|
|
"deactivate",
|
|
|
|
_METHOD_CALLBACK (parent, &FMenuBar::cb_item_deactivated)
|
|
|
|
);
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else if ( isMenu(parent) ) // Parent is menu
|
|
|
|
{
|
|
|
|
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( menu_ptr )
|
|
|
|
menu_ptr->calculateDimensions();
|
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( hasFocus() )
|
|
|
|
flags = fc::focus;
|
|
|
|
|
|
|
|
if ( isEnabled() )
|
|
|
|
flags |= fc::active;
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
uChar FMenuItem::hotKey()
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
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
|
|
|
{
|
2016-11-02 00:37:58 +01: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
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
return 0;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::processActivate()
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
emitCallback("activate");
|
2015-09-30 22:39:02 +02:00
|
|
|
}
|
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::processDeactivate()
|
2015-11-05 23:25:21 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
emitCallback("deactivate");
|
|
|
|
}
|
2015-11-05 23:25:21 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::createDialogList (FMenu* winmenu)
|
|
|
|
{
|
|
|
|
winmenu->clear();
|
2015-11-12 23:14:12 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dialog_list && ! dialog_list->empty() )
|
|
|
|
{
|
|
|
|
widgetList::const_iterator iter, begin;
|
|
|
|
iter = begin = dialog_list->begin();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
while ( iter != dialog_list->end() && *iter )
|
|
|
|
{
|
|
|
|
FDialog* win = dynamic_cast<FDialog*>(*iter);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( win )
|
|
|
|
{
|
|
|
|
int n = int(std::distance(begin, iter));
|
|
|
|
// get the dialog title
|
|
|
|
FString name = win->getText();
|
|
|
|
// create a new dialog list item
|
|
|
|
FMenuItem* win_item = new FMenuItem (name, winmenu);
|
2015-11-24 23:40:41 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( n < 9 )
|
|
|
|
win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9
|
2016-10-11 04:57:36 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
win_item->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
|
|
|
_METHOD_CALLBACK (win_item, &FMenuItem::cb_switchToDialog),
|
|
|
|
dynamic_cast<FWidget::data_ptr>(win)
|
|
|
|
);
|
2016-10-11 04:57:36 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
win->addCallback
|
|
|
|
(
|
|
|
|
"destroy",
|
|
|
|
_METHOD_CALLBACK (win_item, &FMenuItem::cb_destroyDialog)
|
|
|
|
);
|
|
|
|
|
|
|
|
win_item->associated_window = win;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
winmenu->calculateDimensions();
|
2015-11-05 23:25:21 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FMenuItem::cb_switchToDialog (FWidget*, data_ptr data)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2017-02-24 00:30:07 +01:00
|
|
|
FDialog* win = static_cast<FDialog*>(data);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( win )
|
|
|
|
{
|
|
|
|
FWidget* focus_widget = getFocusWidget();
|
|
|
|
FAccelEvent a_ev (fc::Accelerator_Event, focus_widget);
|
|
|
|
FApplication::sendEvent (win, &a_ev);
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FMenuItem::cb_destroyDialog (FWidget* widget, data_ptr)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuItem::processClicked()
|
2015-08-16 20:05:39 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
emitCallback("clicked");
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|