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"
|
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)
|
|
|
|
, checked(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)
|
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)
|
|
|
|
, checked(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)
|
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)
|
|
|
|
, checked(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)
|
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)
|
|
|
|
, checked(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)
|
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuItem::FMenuItem (int k, FString& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
|
|
|
, checked(false)
|
|
|
|
, text_length(0)
|
|
|
|
, hotkey(0)
|
|
|
|
, accel_key(k)
|
|
|
|
, menu(0)
|
|
|
|
, super_menu(0)
|
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuItem::FMenuItem (int k, const std::string& txt, FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, text(txt)
|
|
|
|
, selected(false)
|
|
|
|
, separator(false)
|
|
|
|
, checked(false)
|
|
|
|
, text_length(0)
|
|
|
|
, hotkey(0)
|
|
|
|
, accel_key(k)
|
2015-09-22 04:18:20 +02:00
|
|
|
, menu(0)
|
|
|
|
, super_menu(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)
|
|
|
|
, checked(false)
|
|
|
|
, text_length(0)
|
|
|
|
, hotkey(0)
|
|
|
|
, accel_key(k)
|
|
|
|
, menu(0)
|
|
|
|
, super_menu(0)
|
|
|
|
{
|
|
|
|
init (parent);
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuItem::~FMenuItem() // destructor
|
2015-11-12 23:14:12 +01:00
|
|
|
{
|
|
|
|
delAccelerator();
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
// private methods of FMenuItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::init (FWidget* parent)
|
|
|
|
{
|
2015-09-27 16:00:13 +02:00
|
|
|
text_length = text.getLength();
|
2015-11-01 22:45:23 +01:00
|
|
|
hotkey = hotKey();
|
2015-11-12 01:33:16 +01:00
|
|
|
|
2015-09-27 16:00:13 +02:00
|
|
|
if ( hotkey )
|
|
|
|
text_length--;
|
2015-11-12 01:33:16 +01:00
|
|
|
|
2015-10-04 19:01:34 +02:00
|
|
|
setGeometry (1,1,int(text_length+2),1, false);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2015-09-15 23:07:24 +02:00
|
|
|
if ( parent )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-11-12 01:33:16 +01:00
|
|
|
FMenuList* menu_list;
|
|
|
|
setSuperMenu (parent);
|
|
|
|
|
|
|
|
if ( accel_key )
|
|
|
|
addAccelerator (accel_key);
|
|
|
|
|
|
|
|
menu_list = dynamic_cast<FMenuList*>(parent);
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( menu_list )
|
|
|
|
menu_list->insert(this);
|
2015-10-01 04:44:26 +02:00
|
|
|
|
2015-09-15 23:07:24 +02:00
|
|
|
if ( isMenuBar(parent) ) // Parent is menubar
|
|
|
|
{
|
2015-09-30 22:39:02 +02:00
|
|
|
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
|
|
|
|
if ( menubar_ptr )
|
|
|
|
menubar_ptr->menu_dimension();
|
2015-09-18 21:38:26 +02:00
|
|
|
|
2015-10-23 00:24:20 +02:00
|
|
|
// Meta + hotkey
|
2015-11-12 01:33:16 +01:00
|
|
|
if ( hotkey )
|
|
|
|
menubar_ptr->addAccelerator (fc::Fmkey_meta + tolower(hotkey), this);
|
2015-09-18 21:38:26 +02:00
|
|
|
|
2015-09-15 23:07:24 +02:00
|
|
|
this->addCallback
|
|
|
|
(
|
|
|
|
"activate",
|
2015-10-10 03:14:14 +02:00
|
|
|
_METHOD_CALLBACK (getSuperMenu(), &FMenuBar::cb_item_activated)
|
2015-09-15 23:07:24 +02:00
|
|
|
);
|
2015-09-30 22:39:02 +02:00
|
|
|
this->addCallback
|
|
|
|
(
|
|
|
|
"deactivate",
|
2015-10-10 03:14:14 +02:00
|
|
|
_METHOD_CALLBACK (getSuperMenu(), &FMenuBar::cb_item_deactivated)
|
2015-09-30 22:39:02 +02:00
|
|
|
);
|
2015-09-15 23:07:24 +02:00
|
|
|
}
|
|
|
|
else if ( isMenu(parent) ) // Parent is menu
|
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
|
|
|
|
if ( menu_ptr )
|
|
|
|
menu_ptr->menu_dimension();
|
2015-09-18 21:38:26 +02:00
|
|
|
|
2015-09-15 23:07:24 +02:00
|
|
|
this->addCallback
|
|
|
|
(
|
|
|
|
"activate",
|
2015-10-10 03:14:14 +02:00
|
|
|
_METHOD_CALLBACK (getSuperMenu(), &FMenu::cb_menuitem_activated)
|
2015-09-15 23:07:24 +02:00
|
|
|
);
|
2015-09-30 22:39:02 +02:00
|
|
|
this->addCallback
|
|
|
|
(
|
|
|
|
"deactivate",
|
2015-10-10 03:14:14 +02:00
|
|
|
_METHOD_CALLBACK (getSuperMenu(), &FMenu::cb_menuitem_deactivated)
|
2015-09-30 22:39:02 +02:00
|
|
|
);
|
2015-09-15 23:07:24 +02:00
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
if ( hasFocus() )
|
|
|
|
flags = FOCUS;
|
|
|
|
|
|
|
|
if ( isEnabled() )
|
|
|
|
flags |= ACTIVE;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 20:05:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-11-01 22:45:23 +01:00
|
|
|
uChar FMenuItem::hotKey()
|
2015-08-16 20:05:39 +02:00
|
|
|
{
|
|
|
|
uInt length;
|
|
|
|
|
|
|
|
if ( text.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
length = text.getLength();
|
|
|
|
|
|
|
|
for (uInt i=0; i < length; i++)
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( (i+1 < length) && (text[i] == '&') )
|
|
|
|
return uChar(text[++i]);
|
|
|
|
}
|
|
|
|
catch (const std::out_of_range&)
|
|
|
|
{
|
|
|
|
return 0;;
|
|
|
|
}
|
|
|
|
}
|
2015-08-16 20:05:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuItem::isMenuBar (FWidget* w) const
|
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
return bool ( strcmp ( w->getClassName()
|
|
|
|
, const_cast<char*>("FMenuBar") ) == 0 );
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-15 23:07:24 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuItem::isMenu (FWidget* w) const
|
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
return bool ( strcmp ( w->getClassName()
|
|
|
|
, const_cast<char*>("FMenu") ) == 0 );
|
2015-09-15 23:07:24 +02:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::processActivate()
|
|
|
|
{
|
2015-08-16 20:05:39 +02:00
|
|
|
emitCallback("activate");
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::processDeactivate()
|
|
|
|
{
|
|
|
|
emitCallback("deactivate");
|
|
|
|
}
|
|
|
|
|
2015-08-22 18:53:52 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::processClicked()
|
|
|
|
{
|
|
|
|
emitCallback("clicked");
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
// public methods of FMenuItem
|
2015-11-12 01:33:16 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::addAccelerator (int key, FWidget* obj)
|
|
|
|
{
|
|
|
|
FWidget* super = super_menu;
|
2015-11-12 23:14:12 +01:00
|
|
|
if ( ! super )
|
|
|
|
return;
|
2015-11-12 01:33:16 +01:00
|
|
|
|
|
|
|
while ( super && strncmp ( super->getClassName()
|
|
|
|
, const_cast<char*>("FMenu"), 5) == 0 )
|
|
|
|
{
|
|
|
|
super = super->parentWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( super )
|
|
|
|
{
|
|
|
|
FWidget* window = FWindow::getWindowWidget(super);
|
|
|
|
accelerator accel = { key, obj };
|
|
|
|
|
|
|
|
if ( ! window )
|
|
|
|
window = getRootWidget();
|
|
|
|
if ( window && window->accelerator_list )
|
2015-11-12 23:14:12 +01:00
|
|
|
{
|
|
|
|
accel_key = key;
|
2015-11-12 01:33:16 +01:00
|
|
|
window->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);
|
|
|
|
if ( menu_ptr )
|
|
|
|
menu_ptr->menu_dimension();
|
2015-11-12 01:33:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::delAccelerator (FWidget* obj)
|
|
|
|
{
|
|
|
|
FWidget* super = super_menu;
|
2015-11-12 23:14:12 +01:00
|
|
|
if ( ! super )
|
|
|
|
return;
|
2015-11-12 01:33:16 +01:00
|
|
|
|
|
|
|
while ( super && strncmp ( super->getClassName()
|
|
|
|
, const_cast<char*>("FMenu"), 5) == 0 )
|
|
|
|
{
|
|
|
|
super = super->parentWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( super )
|
|
|
|
{
|
|
|
|
FWidget* window = FWindow::getWindowWidget(super);
|
|
|
|
|
|
|
|
if ( ! window )
|
|
|
|
window = getRootWidget();
|
|
|
|
if ( window
|
|
|
|
&& window->accelerator_list
|
|
|
|
&& ! window->accelerator_list->empty() )
|
|
|
|
{
|
|
|
|
FWidget::Accelerators::iterator iter;
|
|
|
|
iter = window->accelerator_list->begin();
|
2015-11-12 23:14:12 +01:00
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
while ( iter != window->accelerator_list->end() )
|
|
|
|
{
|
|
|
|
if ( iter->object == obj )
|
2015-11-12 23:14:12 +01:00
|
|
|
{
|
|
|
|
accel_key = 0;
|
2015-11-12 01:33:16 +01:00
|
|
|
iter = window->accelerator_list->erase(iter);
|
2015-11-12 23:14:12 +01:00
|
|
|
}
|
2015-11-12 01:33:16 +01:00
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 23:14:12 +01:00
|
|
|
|
|
|
|
if ( isMenu(super_menu) )
|
|
|
|
{
|
|
|
|
FMenu* menu_ptr = dynamic_cast<FMenu*>(super_menu);
|
|
|
|
if ( menu_ptr )
|
|
|
|
menu_ptr->menu_dimension();
|
|
|
|
}
|
2015-11-12 01:33:16 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-10-29 21:10:50 +01:00
|
|
|
if ( super_menu )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-10-29 21:10:50 +01:00
|
|
|
if ( isMenu(super_menu) )
|
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
|
|
|
if ( smenu )
|
|
|
|
smenu->onKeyPress(ev);
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isMenuBar(super_menu) )
|
2015-10-23 00:24:20 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
|
|
|
if ( mbar )
|
2015-11-04 05:55:20 +01:00
|
|
|
{
|
|
|
|
if ( mbar->hotkeyMenu(ev) )
|
|
|
|
return;
|
2015-11-04 00:14:23 +01:00
|
|
|
mbar->onKeyPress(ev);
|
2015-11-04 05:55:20 +01:00
|
|
|
}
|
2015-10-23 00:24:20 +02:00
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 04:31:29 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onMouseDown (FMouseEvent* ev)
|
|
|
|
{
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( super_menu )
|
|
|
|
{
|
2015-10-10 03:14:14 +02:00
|
|
|
const FPoint& g = ev->getGlobalPos();
|
|
|
|
int b = ev->getButton();
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( isMenu(super_menu) )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
|
|
|
if ( smenu )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
const FPoint& p2 = smenu->globalToLocalPos(g);
|
2015-10-10 03:14:14 +02:00
|
|
|
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
|
2015-11-04 00:14:23 +01:00
|
|
|
smenu->onMouseDown(ev);
|
2015-10-10 03:14:14 +02:00
|
|
|
delete ev;
|
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
|
|
|
if ( mbar )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
const FPoint& p2 = mbar->globalToLocalPos(g);
|
2015-10-10 03:14:14 +02:00
|
|
|
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
|
2015-11-04 00:14:23 +01:00
|
|
|
mbar->onMouseDown(ev);
|
2015-10-10 03:14:14 +02:00
|
|
|
delete ev;
|
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2015-10-10 03:14:14 +02:00
|
|
|
}
|
2015-09-28 04:31:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onMouseUp (FMouseEvent* ev)
|
|
|
|
{
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( super_menu )
|
|
|
|
{
|
2015-10-10 03:14:14 +02:00
|
|
|
const FPoint& g = ev->getGlobalPos();
|
|
|
|
int b = ev->getButton();
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( isMenu(super_menu) )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
|
|
|
if ( smenu )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
const FPoint& p2 = smenu->globalToLocalPos(g);
|
2015-10-10 03:14:14 +02:00
|
|
|
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
|
2015-11-04 00:14:23 +01:00
|
|
|
smenu->onMouseUp(ev);
|
2015-10-10 03:14:14 +02:00
|
|
|
delete ev;
|
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
|
|
|
if ( mbar )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
const FPoint& p2 = mbar->globalToLocalPos(g);
|
2015-10-10 03:14:14 +02:00
|
|
|
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
|
2015-11-04 00:14:23 +01:00
|
|
|
mbar->onMouseUp(ev);
|
2015-10-10 03:14:14 +02:00
|
|
|
delete ev;
|
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2015-10-10 03:14:14 +02:00
|
|
|
}
|
2015-09-28 04:31:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onMouseMove (FMouseEvent* ev)
|
|
|
|
{
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( super_menu )
|
|
|
|
{
|
2015-10-10 03:14:14 +02:00
|
|
|
const FPoint& g = ev->getGlobalPos();
|
|
|
|
int b = ev->getButton();
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( isMenu(super_menu) )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
|
|
|
|
if ( smenu )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
const FPoint& p2 = smenu->globalToLocalPos(g);
|
2015-10-10 03:14:14 +02:00
|
|
|
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
|
2015-11-04 00:14:23 +01:00
|
|
|
smenu->onMouseMove(ev);
|
2015-10-10 03:14:14 +02:00
|
|
|
delete ev;
|
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( isMenuBar(super_menu) )
|
2015-10-01 04:44:26 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
|
|
|
if ( mbar )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
const FPoint& p2 = mbar->globalToLocalPos(g);
|
2015-10-10 03:14:14 +02:00
|
|
|
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
|
2015-11-04 00:14:23 +01:00
|
|
|
mbar->onMouseMove(ev);
|
2015-10-10 03:14:14 +02:00
|
|
|
delete ev;
|
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
}
|
2015-09-28 04:31:29 +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)
|
|
|
|
{
|
|
|
|
if ( isEnabled() && ! isSelected() )
|
|
|
|
{
|
|
|
|
if ( super_menu && isMenuBar(super_menu) )
|
|
|
|
{
|
2015-11-04 00:14:23 +01:00
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
|
|
|
if ( mbar )
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( menu )
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2015-11-01 22:45:23 +01:00
|
|
|
FWidget* focused_widget;
|
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( mbar->getSelectedItem() )
|
|
|
|
mbar->getSelectedItem()->unsetSelected();
|
2015-11-01 22:45:23 +01:00
|
|
|
setSelected();
|
2015-11-07 23:16:09 +01:00
|
|
|
mbar->selectedItem = this;
|
2015-11-05 23:25:21 +01:00
|
|
|
openMenu();
|
2015-11-01 22:45:23 +01:00
|
|
|
|
|
|
|
focused_widget = static_cast<FWidget*>(ev->focusedWidget());
|
2015-10-29 21:10:50 +01:00
|
|
|
FFocusEvent out (FocusOut_Event);
|
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
2015-11-07 23:16:09 +01:00
|
|
|
menu->unselectItem();
|
|
|
|
menu->selectFirstItem();
|
|
|
|
menu->getSelectedItem()->setFocus();
|
2015-10-29 21:10:50 +01:00
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
menu->redraw();
|
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2015-11-04 00:14:23 +01:00
|
|
|
mbar->redraw();
|
2015-11-05 23:25:21 +01:00
|
|
|
mbar->drop_down = true;
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsetSelected();
|
2015-11-07 23:16:09 +01:00
|
|
|
mbar->selectedItem = 0;
|
2015-11-04 00:14:23 +01:00
|
|
|
mbar->redraw();
|
2015-11-01 22:45:23 +01:00
|
|
|
processClicked();
|
2015-11-05 23:25:21 +01:00
|
|
|
mbar->drop_down = false;
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 01:33:16 +01:00
|
|
|
else
|
|
|
|
processClicked();
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onFocusIn (FFocusEvent*)
|
|
|
|
{
|
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::onFocusOut (FFocusEvent*)
|
|
|
|
{
|
2015-11-05 23:25:21 +01:00
|
|
|
unsetSelected();
|
|
|
|
if ( super_menu && isMenuBar(super_menu) )
|
|
|
|
{
|
|
|
|
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
|
|
|
|
if ( mbar )
|
|
|
|
mbar->redraw();
|
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
{
|
|
|
|
statusBar()->clearMessage();
|
|
|
|
statusBar()->drawMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuItem::setEnable (bool on)
|
|
|
|
{
|
|
|
|
FWidget::setEnable(on);
|
|
|
|
|
|
|
|
FWidget* super = getSuperMenu();
|
|
|
|
|
|
|
|
if ( on )
|
|
|
|
{
|
|
|
|
flags |= ACTIVE;
|
|
|
|
|
|
|
|
if ( super && isMenuBar(super) )
|
|
|
|
{
|
|
|
|
// Meta + hotkey
|
2015-11-12 01:33:16 +01:00
|
|
|
super->addAccelerator (fc::Fmkey_meta + tolower(hotkey), this);
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags &= ~ACTIVE;
|
|
|
|
|
|
|
|
if ( super && isMenuBar(super) )
|
|
|
|
super->delAccelerator (this);
|
|
|
|
}
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuItem::setFocus (bool on)
|
|
|
|
{
|
|
|
|
FWidget::setFocus(on);
|
|
|
|
|
|
|
|
if ( on )
|
|
|
|
{
|
|
|
|
flags |= FOCUS;
|
|
|
|
|
|
|
|
if ( isEnabled() )
|
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( ! selected )
|
|
|
|
{
|
|
|
|
FMenuList* menu_list = dynamic_cast<FMenuList*>(getSuperMenu());
|
|
|
|
setSelected();
|
2015-11-08 02:01:35 +01:00
|
|
|
if ( menu_list )
|
|
|
|
{
|
|
|
|
menu_list->unselectItem();
|
|
|
|
menu_list->setSelectedItem(this);
|
|
|
|
}
|
2015-11-07 23:16:09 +01:00
|
|
|
|
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
|
|
|
|
|
|
|
FWidget* parent = getSuperMenu();
|
|
|
|
if ( isMenuBar(parent) )
|
|
|
|
{
|
|
|
|
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
|
|
|
|
if ( menubar_ptr )
|
|
|
|
menubar_ptr->redraw();
|
|
|
|
}
|
|
|
|
else if ( isMenu(parent) )
|
|
|
|
{
|
|
|
|
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
|
|
|
|
if ( menu_ptr )
|
|
|
|
menu_ptr->redraw();
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 23:14:12 +01:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( statusBar() )
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
|
|
|
FString msg = getStatusbarMessage();
|
|
|
|
FString curMsg = statusBar()->getMessage();
|
|
|
|
if ( curMsg != msg )
|
|
|
|
statusBar()->setMessage(msg);
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags &= ~FOCUS;
|
|
|
|
|
|
|
|
if ( isEnabled() && statusBar() )
|
|
|
|
statusBar()->clearMessage();
|
|
|
|
}
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-08-16 20:05:39 +02:00
|
|
|
void FMenuItem::setSelected()
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-10-29 21:10:50 +01:00
|
|
|
if ( isEnabled() )
|
2015-08-22 18:53:52 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
selected = true;
|
2015-08-22 18:53:52 +02:00
|
|
|
processActivate();
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-30 22:39:02 +02:00
|
|
|
void FMenuItem::unsetSelected()
|
|
|
|
{
|
|
|
|
selected = false;
|
|
|
|
processDeactivate();
|
|
|
|
}
|
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::openMenu()
|
|
|
|
{
|
2015-11-12 01:33:16 +01:00
|
|
|
FMenu* submenu;
|
2015-11-05 23:25:21 +01:00
|
|
|
FMenu* open_menu;
|
|
|
|
|
|
|
|
if ( hasMenu() )
|
|
|
|
{
|
2015-11-12 01:33:16 +01:00
|
|
|
submenu = getMenu();
|
2015-11-12 23:14:12 +01:00
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
if ( ! submenu->isVisible() )
|
2015-11-05 23:25:21 +01:00
|
|
|
{
|
|
|
|
open_menu = static_cast<FMenu*>(getOpenMenu());
|
2015-11-12 01:33:16 +01:00
|
|
|
if ( open_menu && open_menu != submenu )
|
2015-11-05 23:25:21 +01:00
|
|
|
open_menu->hide();
|
2015-11-12 01:33:16 +01:00
|
|
|
setOpenMenu(submenu);
|
2015-11-12 23:14:12 +01:00
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
submenu->setVisible();
|
|
|
|
submenu->show();
|
|
|
|
submenu->raiseWindow(submenu);
|
|
|
|
submenu->redraw();
|
2015-11-05 23:25:21 +01:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuItem::setText (FString& txt)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
text = txt;
|
2015-09-27 16:00:13 +02:00
|
|
|
text_length = text.getLength();
|
2015-11-01 22:45:23 +01:00
|
|
|
hotkey = hotKey();
|
2015-09-27 16:00:13 +02:00
|
|
|
if ( hotkey )
|
|
|
|
text_length--;
|
2015-10-04 19:01:34 +02:00
|
|
|
setWidth(int(text_length));
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-10-04 19:01:34 +02:00
|
|
|
void FMenuItem::setText (const std::string& txt)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-10-04 19:01:34 +02:00
|
|
|
FString s = FString(txt);
|
|
|
|
setText (s);
|
2015-08-16 20:05:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-10-04 19:01:34 +02:00
|
|
|
void FMenuItem::setText (const char* txt)
|
2015-08-16 20:05:39 +02:00
|
|
|
{
|
2015-10-04 19:01:34 +02:00
|
|
|
FString s = FString(txt);
|
|
|
|
setText (s);
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|