finalcut/src/fmenuitem.cpp

166 lines
3.8 KiB
C++
Raw Normal View History

// fmenuitem.cpp
// class FMenuItem
2015-08-16 20:05:39 +02:00
#include "fmenubar.h"
#include "fmenuitem.h"
#include "fmenulist.h"
//----------------------------------------------------------------------
// class FMenuItem
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FMenuItem::FMenuItem (FWidget* parent) : FWidget(parent)
{
init (parent);
}
//----------------------------------------------------------------------
2015-08-16 20:05:39 +02:00
FMenuItem::FMenuItem (FString& txt, FWidget* parent) : FWidget(parent)
{
setText(txt);
init (parent);
}
//----------------------------------------------------------------------
FMenuItem::FMenuItem (const std::string& txt, FWidget* parent) : FWidget(parent)
{
setText(txt);
init (parent);
}
//----------------------------------------------------------------------
FMenuItem::FMenuItem (const char* txt, FWidget* parent) : FWidget(parent)
{
setText(txt);
init (parent);
}
//----------------------------------------------------------------------
FMenuItem::~FMenuItem() // destructor
{
}
// private methods of FMenuItem
//----------------------------------------------------------------------
void FMenuItem::init (FWidget* parent)
{
active = true;
selected = false;
separator = false;
checked = false;
2015-08-16 20:05:39 +02:00
hotkey = 0;
menu = 0;
setGeometry (1,1,1,1);
if ( parent && isMenuBar(parent) )
{
setSuperMenu( dynamic_cast<FMenuList*>(parent) );
superMenu()->insert(this);
2015-08-16 20:05:39 +02:00
//addAccelerator (item->getKey(), item);
this->addCallback
(
"activate",
(FWidget*)superMenu(),
reinterpret_cast<FWidget::FMemberCallback>(&FMenuBar::cb_item_activated),
null
);
}
}
2015-08-16 20:05:39 +02:00
//----------------------------------------------------------------------
uChar FMenuItem::getHotkey()
{
uInt length;
if ( text.isEmpty() )
return 0;
length = text.getLength();
for (uInt i=0; i < length; i++)
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
return 0;
}
//----------------------------------------------------------------------
bool FMenuItem::isMenuBar (FWidget* w) const
{
return bool ( strcmp ( w->getClassName(),
const_cast<char*>("FMenuBar") ) == 0 );
}
2015-08-16 20:05:39 +02:00
//----------------------------------------------------------------------
FMenuList* FMenuItem::superMenu() const
{
return super_menu;
}
//----------------------------------------------------------------------
void FMenuItem::setSuperMenu (FMenuList* smenu)
{
super_menu = smenu;
}
//----------------------------------------------------------------------
void FMenuItem::processActivate()
{
2015-08-16 20:05:39 +02:00
emitCallback("activate");
}
2015-08-22 18:53:52 +02:00
//----------------------------------------------------------------------
void FMenuItem::processClicked()
{
emitCallback("clicked");
}
// public methods of FMenuItem
//----------------------------------------------------------------------
void FMenuItem::onAccel (FAccelEvent* event)
{
if ( isSelected() )
{
unsetSelected();
FWidget* w = reinterpret_cast<FWidget*>(superMenu());
if ( isMenuBar(w) )
w->redraw();
event->accept();
}
}
//----------------------------------------------------------------------
2015-08-16 20:05:39 +02:00
void FMenuItem::setSelected()
{
2015-08-22 18:53:52 +02:00
if ( isActivated() )
{
this->selected = true;
processActivate();
}
}
//----------------------------------------------------------------------
2015-08-16 20:05:39 +02:00
inline void FMenuItem::setText (FString& txt)
{
2015-08-16 20:05:39 +02:00
this->text = txt;
this->hotkey = getHotkey();
}
//----------------------------------------------------------------------
2015-08-16 20:05:39 +02:00
inline void FMenuItem::setText (const std::string& txt)
{
2015-08-16 20:05:39 +02:00
this->text = txt;
this->hotkey = getHotkey();
}
//----------------------------------------------------------------------
inline void FMenuItem::setText (const char* txt)
{
this->text = txt;
this->hotkey = getHotkey();
}