2015-09-25 21:37:19 +02:00
|
|
|
// File: fmenubar.cpp
|
|
|
|
// Provides: class FMenuBar
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2015-10-10 03:14:14 +02:00
|
|
|
#include "fapp.h"
|
2015-08-09 23:47:08 +02:00
|
|
|
#include "fmenubar.h"
|
2015-11-01 22:45:23 +01:00
|
|
|
#include "fstatusbar.h"
|
2015-09-30 22:39:02 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FMenuBar
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FMenuBar::FMenuBar(FWidget* parent)
|
|
|
|
: FWindow(parent)
|
|
|
|
, mouse_down(false)
|
2015-11-05 23:25:21 +01:00
|
|
|
, drop_down(false)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuBar::~FMenuBar()
|
|
|
|
{
|
|
|
|
if ( vmenubar != 0 )
|
|
|
|
{
|
|
|
|
if ( vmenubar->changes != 0 )
|
|
|
|
delete[] vmenubar->changes;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( vmenubar->text != 0 )
|
|
|
|
delete[] vmenubar->text;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
delete vmenubar;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
vmenubar = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FMenuBar
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::init()
|
|
|
|
{
|
|
|
|
xmin = ymin = 1;
|
|
|
|
xpos = 1;
|
|
|
|
ypos = 1;
|
|
|
|
createArea (vmenubar);
|
2015-09-22 22:12:31 +02:00
|
|
|
vmenubar->visible = true;
|
2016-05-16 21:11:32 +02:00
|
|
|
ignore_padding = true;
|
2015-08-09 23:47:08 +02:00
|
|
|
// initialize geometry values
|
|
|
|
setGeometry (1, 1, getColumnNumber(), 1, false);
|
|
|
|
setMenuBar(this);
|
2016-08-21 21:27:44 +02:00
|
|
|
|
|
|
|
if ( getRootWidget() )
|
|
|
|
getRootWidget()->setTopPadding(1, true);
|
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
addAccelerator (fc::Fkey_f10);
|
2015-12-21 18:48:38 +01:00
|
|
|
addAccelerator (fc::Fckey_space);
|
2015-09-15 23:07:24 +02:00
|
|
|
foregroundColor = wc.menu_active_fg;
|
|
|
|
backgroundColor = wc.menu_active_bg;
|
2015-08-09 23:47:08 +02:00
|
|
|
unsetFocusable();
|
|
|
|
}
|
|
|
|
|
2015-09-28 04:31:29 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::menu_dimension()
|
|
|
|
{
|
|
|
|
int item_X = 1;
|
|
|
|
int item_Y = 1;
|
2015-10-03 01:45:13 +02:00
|
|
|
std::vector<FMenuItem*>::const_iterator end, iter;
|
2015-09-28 04:31:29 +02:00
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
|
|
|
|
2015-11-12 23:14:12 +01:00
|
|
|
// find the maximum item width
|
2015-09-28 04:31:29 +02:00
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
uInt len = (*iter)->getTextLength();
|
|
|
|
int item_width = int(len + 2);
|
|
|
|
|
|
|
|
// set item geometry
|
|
|
|
(*iter)->setGeometry (item_X, item_Y, item_width, 1, false);
|
|
|
|
|
|
|
|
// set menu position
|
|
|
|
if ( (*iter)->hasMenu() )
|
|
|
|
(*iter)->getMenu()->setPos (item_X, item_Y, false);
|
|
|
|
|
|
|
|
item_X += item_width;
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 20:05:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuBar::isMenu (FMenuItem* mi) const
|
|
|
|
{
|
|
|
|
return mi->hasMenu();
|
|
|
|
}
|
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuBar::selectNextItem()
|
|
|
|
{
|
|
|
|
std::vector<FMenuItem*>::const_iterator iter, end;
|
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
if ( (*iter)->isSelected() )
|
|
|
|
{
|
|
|
|
FMenuItem* next;
|
|
|
|
std::vector<FMenuItem*>::const_iterator next_element;
|
|
|
|
next_element = iter;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
++next_element;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( next_element == itemlist.end() )
|
|
|
|
next_element = itemlist.begin();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
next = static_cast<FMenuItem*>(*next_element);
|
|
|
|
} while ( ! next->isEnabled()
|
|
|
|
|| ! next->acceptFocus()
|
|
|
|
|| ! next->isVisible()
|
|
|
|
|| next->isSeparator() );
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( next == *iter )
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
unselectItem();
|
2015-11-01 22:45:23 +01:00
|
|
|
next->setSelected();
|
2015-11-07 23:16:09 +01:00
|
|
|
setSelectedItem(next);
|
2015-11-01 22:45:23 +01:00
|
|
|
next->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( drop_down && next->hasMenu() )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2016-07-09 00:01:59 +02:00
|
|
|
FMenuItem* first_item;
|
|
|
|
FMenu* menu = next->getMenu();
|
|
|
|
next->openMenu();
|
|
|
|
menu->selectFirstItem();
|
|
|
|
first_item = menu->getSelectedItem();
|
|
|
|
|
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
|
|
|
|
|
|
|
menu->redraw();
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
redraw();
|
|
|
|
break;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
++iter;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuBar::selectPrevItem()
|
|
|
|
{
|
|
|
|
std::vector<FMenuItem*>::const_iterator iter, begin;
|
|
|
|
iter = itemlist.end();
|
|
|
|
begin = itemlist.begin();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( (*iter)->isSelected() )
|
|
|
|
{
|
|
|
|
FMenuItem* prev;
|
|
|
|
std::vector<FMenuItem*>::const_iterator prev_element;
|
|
|
|
prev_element = iter;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( prev_element == itemlist.begin() )
|
|
|
|
prev_element = itemlist.end();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
--prev_element;
|
|
|
|
prev = static_cast<FMenuItem*>(*prev_element);
|
2016-07-09 00:01:59 +02:00
|
|
|
}
|
|
|
|
while ( ! prev->isEnabled()
|
|
|
|
|| ! prev->acceptFocus()
|
|
|
|
|| ! prev->isVisible()
|
|
|
|
|| prev->isSeparator() );
|
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( prev == *iter )
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
unselectItem();
|
2015-11-01 22:45:23 +01:00
|
|
|
prev->setSelected();
|
|
|
|
prev->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( drop_down && prev->hasMenu() )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
FMenuItem* first_item;
|
|
|
|
FMenu* menu = prev->getMenu();
|
|
|
|
prev->openMenu();
|
|
|
|
menu->selectFirstItem();
|
|
|
|
first_item = menu->getSelectedItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
menu->redraw();
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
setSelectedItem(prev);
|
2015-11-01 22:45:23 +01:00
|
|
|
redraw();
|
|
|
|
break;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
}
|
|
|
|
while ( iter != begin );
|
2015-11-01 22:45:23 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuBar::hotkeyMenu (FKeyEvent*& ev)
|
|
|
|
{
|
|
|
|
std::vector<FMenuItem*>::const_iterator iter, end;
|
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
if ( (*iter)->isEnabled() )
|
|
|
|
{
|
|
|
|
int hotkey = (*iter)->getHotkey();
|
|
|
|
int key = ev->key();
|
2015-11-05 23:25:21 +01:00
|
|
|
|
2015-11-12 01:33:16 +01:00
|
|
|
if ( fc::Fmkey_meta + tolower(hotkey) == key )
|
2015-11-04 00:14:23 +01:00
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
FMenuItem* sel_item = getSelectedItem();
|
2015-11-04 00:14:23 +01:00
|
|
|
|
|
|
|
if ( sel_item && sel_item->hasMenu() )
|
2015-11-07 23:16:09 +01:00
|
|
|
sel_item->getMenu()->unselectItem();
|
2015-11-04 00:14:23 +01:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
unselectItem();
|
2015-11-04 00:14:23 +01:00
|
|
|
|
|
|
|
if ( (*iter)->hasMenu() )
|
|
|
|
{
|
|
|
|
FMenuItem* first_item;
|
|
|
|
FMenu* menu = (*iter)->getMenu();
|
|
|
|
(*iter)->setSelected();
|
2015-11-07 23:16:09 +01:00
|
|
|
setSelectedItem(*iter);
|
2015-11-04 00:14:23 +01:00
|
|
|
(*iter)->setFocus();
|
2015-11-05 23:25:21 +01:00
|
|
|
(*iter)->openMenu();
|
2015-11-07 23:16:09 +01:00
|
|
|
menu->selectFirstItem();
|
|
|
|
first_item = menu->getSelectedItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
menu->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
redraw();
|
2015-11-05 23:25:21 +01:00
|
|
|
drop_down = true;
|
2015-11-04 00:14:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
setSelectedItem(0);
|
2015-11-04 00:14:23 +01:00
|
|
|
redraw();
|
2015-11-05 23:25:21 +01:00
|
|
|
drop_down = false;
|
2015-11-04 00:14:23 +01:00
|
|
|
(*iter)->processClicked();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
ev->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
++iter;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FMenuBar::getHotkeyPos (wchar_t*& src, wchar_t*& dest, uInt length)
|
|
|
|
{
|
|
|
|
// find hotkey position in string
|
|
|
|
// + generate a new string without the '&'-sign
|
|
|
|
int hotkeypos = -1;
|
|
|
|
wchar_t* txt = src;
|
|
|
|
|
|
|
|
for (uInt i=0; i < length; i++)
|
|
|
|
{
|
|
|
|
if ( (i < length) && (txt[i] == L'&') && (hotkeypos == -1) )
|
|
|
|
{
|
|
|
|
hotkeypos = int(i);
|
|
|
|
i++;
|
|
|
|
src++;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
return hotkeypos;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::draw()
|
|
|
|
{
|
|
|
|
xmin = ymin = 1;
|
|
|
|
height = 1;
|
|
|
|
xpos = 1;
|
|
|
|
drawItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::drawItems()
|
|
|
|
{
|
|
|
|
std::vector<FMenuItem*>::const_iterator iter, end;
|
|
|
|
int screenWidth;
|
2015-09-30 22:39:02 +02:00
|
|
|
int x = 1;
|
2015-08-09 23:47:08 +02:00
|
|
|
screenWidth = getColumnNumber();
|
|
|
|
width = screenWidth;
|
|
|
|
ypos = 1;
|
|
|
|
|
|
|
|
if ( itemlist.empty() )
|
|
|
|
return;
|
|
|
|
|
2016-08-06 21:43:39 +02:00
|
|
|
updateVTerm(false);
|
2015-08-09 23:47:08 +02:00
|
|
|
gotoxy (1,1);
|
|
|
|
|
2015-10-11 21:56:16 +02:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
wchar_t* src;
|
|
|
|
wchar_t* dest;
|
|
|
|
wchar_t* item_text;
|
|
|
|
FString txt;
|
|
|
|
uInt txt_length;
|
2015-11-01 22:45:23 +01:00
|
|
|
int hotkeypos, startpos, to_char;
|
|
|
|
bool is_active, is_selected, is_noUnderline;
|
2015-09-28 04:31:29 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
startpos = x + 1;
|
|
|
|
is_active = (*iter)->isEnabled();
|
|
|
|
is_selected = (*iter)->isSelected();
|
2016-01-24 14:53:09 +01:00
|
|
|
is_noUnderline = (((*iter)->getFlags() & fc::no_underline) != 0);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( is_active )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( is_selected )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2015-10-11 21:56:16 +02:00
|
|
|
foregroundColor = wc.menu_active_focus_fg;
|
|
|
|
backgroundColor = wc.menu_active_focus_bg;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foregroundColor = wc.menu_active_fg;
|
|
|
|
backgroundColor = wc.menu_active_bg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foregroundColor = wc.menu_inactive_fg;
|
|
|
|
backgroundColor = wc.menu_inactive_bg;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
setColor (foregroundColor, backgroundColor);
|
2015-11-01 22:45:23 +01:00
|
|
|
|
|
|
|
if ( x < screenWidth )
|
|
|
|
{
|
|
|
|
x++;
|
|
|
|
print (vmenubar, ' ');
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
txt = (*iter)->getText();
|
2015-09-20 05:44:50 +02:00
|
|
|
txt_length = uInt(txt.getLength());
|
2015-10-17 19:40:43 +02:00
|
|
|
item_text = new wchar_t[txt_length+1]();
|
2015-08-09 23:47:08 +02:00
|
|
|
src = const_cast<wchar_t*>(txt.wc_str());
|
|
|
|
dest = const_cast<wchar_t*>(item_text);
|
|
|
|
|
|
|
|
if ( x-1 <= screenWidth )
|
|
|
|
to_char = int(txt_length);
|
|
|
|
else
|
2015-09-20 05:44:50 +02:00
|
|
|
to_char = int(txt_length) - (screenWidth-x-1);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
hotkeypos = getHotkeyPos (src, dest, txt_length);
|
|
|
|
|
|
|
|
if ( hotkeypos != -1 )
|
|
|
|
{
|
|
|
|
txt_length--;
|
|
|
|
to_char--;
|
|
|
|
}
|
2015-11-01 22:45:23 +01:00
|
|
|
|
2015-09-20 05:44:50 +02:00
|
|
|
x += int(txt_length);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
for (int z=0; z < to_char; z++)
|
|
|
|
{
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( startpos > screenWidth-z )
|
|
|
|
break;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( ! iswprint(wint_t(item_text[z])) )
|
2015-10-17 21:05:49 +02:00
|
|
|
{
|
|
|
|
if ( ! isNewFont() && ( int(item_text[z]) < fc::NF_rev_left_arrow2
|
|
|
|
|| int(item_text[z]) > fc::NF_check_mark ) )
|
|
|
|
{
|
|
|
|
item_text[z] = L' ';
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( (z == hotkeypos) && is_active && ! is_selected )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( ! is_noUnderline )
|
2015-08-09 23:47:08 +02:00
|
|
|
setUnderline();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
print (vmenubar, item_text[z]);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( ! is_noUnderline )
|
2015-08-09 23:47:08 +02:00
|
|
|
unsetUnderline();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
setColor (foregroundColor, backgroundColor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print (vmenubar, item_text[z]);
|
|
|
|
}
|
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( x > screenWidth+1 )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( startpos < screenWidth )
|
|
|
|
{
|
|
|
|
gotoxy(screenWidth-1,1);
|
|
|
|
print (vmenubar, "..");
|
|
|
|
}
|
2016-01-10 10:42:55 +01:00
|
|
|
else if ( startpos-1 <= screenWidth )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
|
|
|
gotoxy(screenWidth,1);
|
|
|
|
print (vmenubar, ' ');
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2015-11-01 22:45:23 +01:00
|
|
|
|
|
|
|
if ( x < screenWidth )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
x++;
|
|
|
|
print (vmenubar, ' ');
|
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
setColor (wc.menu_active_fg, wc.menu_active_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( isMonochron() && is_active && is_selected )
|
2015-10-11 21:56:16 +02:00
|
|
|
setReverse(true);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-07-09 00:01:59 +02:00
|
|
|
delete[] item_text;
|
2015-08-09 23:47:08 +02:00
|
|
|
++iter;
|
|
|
|
}
|
2015-10-11 04:09:58 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
for (; x <= screenWidth; x++)
|
|
|
|
print (vmenubar, ' ');
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2015-10-11 04:09:58 +02:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-08-06 21:43:39 +02:00
|
|
|
updateVTerm(true);
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-12-16 23:57:14 +01:00
|
|
|
void FMenuBar::adjustItems()
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-12-16 23:57:14 +01:00
|
|
|
int item_X = 1;
|
|
|
|
int item_Y = 1;
|
|
|
|
std::vector<FMenuItem*>::const_iterator end, iter;
|
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
// get item width
|
|
|
|
int item_width = (*iter)->getWidth();
|
|
|
|
|
|
|
|
if ( (*iter)->hasMenu() )
|
|
|
|
{
|
|
|
|
FMenu* menu = (*iter)->getMenu();
|
|
|
|
|
|
|
|
// set menu position
|
|
|
|
menu->move (menu->adjustX(item_X), item_Y);
|
|
|
|
|
|
|
|
// call menu adjustItems()
|
|
|
|
menu->adjustItems();
|
|
|
|
}
|
|
|
|
|
2016-07-09 00:01:59 +02:00
|
|
|
item_X += item_width;
|
2015-12-16 23:57:14 +01:00
|
|
|
++iter;
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2015-11-15 19:46:33 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::leaveMenuBar()
|
|
|
|
{
|
|
|
|
resetMenu();
|
|
|
|
redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-06-19 20:32:03 +02:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->clearMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-06-19 20:32:03 +02:00
|
|
|
switchToPrevWindow();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-15 19:46:33 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-15 19:46:33 +01:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
2015-11-15 22:31:55 +01:00
|
|
|
mouse_down = false;
|
2015-11-15 19:46:33 +01:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
// public methods of FMenuBar
|
2015-10-29 21:10:50 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
|
|
|
switch ( ev->key() )
|
|
|
|
{
|
2015-11-01 22:45:23 +01:00
|
|
|
case fc::Fkey_return:
|
|
|
|
case fc::Fkey_enter:
|
2015-11-05 23:25:21 +01:00
|
|
|
case fc::Fkey_up:
|
|
|
|
case fc::Fkey_down:
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( hasSelectedItem() )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
FMenuItem* sel_item = getSelectedItem();
|
2015-11-05 23:25:21 +01:00
|
|
|
|
|
|
|
if ( sel_item->hasMenu() )
|
|
|
|
{
|
|
|
|
FMenuItem* first_item;
|
|
|
|
FMenu* menu = sel_item->getMenu();
|
|
|
|
sel_item->openMenu();
|
2015-11-07 23:16:09 +01:00
|
|
|
menu->selectFirstItem();
|
|
|
|
first_item = menu->getSelectedItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
menu->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
redraw();
|
|
|
|
drop_down = true;
|
|
|
|
}
|
|
|
|
else if ( ev->key() == fc::Fkey_return
|
|
|
|
|| ev->key() == fc::Fkey_enter )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
unselectItem();
|
2015-11-01 22:45:23 +01:00
|
|
|
redraw();
|
2015-11-05 23:25:21 +01:00
|
|
|
sel_item->processClicked();
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
2015-10-29 21:10:50 +01:00
|
|
|
case fc::Fkey_left:
|
2015-11-01 22:45:23 +01:00
|
|
|
selectPrevItem();
|
2015-10-29 21:10:50 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fc::Fkey_right:
|
2015-11-01 22:45:23 +01:00
|
|
|
selectNextItem();
|
2015-10-29 21:10:50 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
case fc::Fkey_escape:
|
|
|
|
case fc::Fkey_escape_mintty:
|
2015-11-15 19:46:33 +01:00
|
|
|
leaveMenuBar();
|
2015-11-05 23:25:21 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
|
|
|
|
2015-10-29 21:10:50 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FMenuBar::onMouseDown (FMouseEvent* ev)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
mouse_down = false;
|
2015-12-20 23:27:33 +01:00
|
|
|
|
|
|
|
if ( ! itemlist.empty() && hasSelectedItem() )
|
2015-11-15 19:46:33 +01:00
|
|
|
leaveMenuBar();
|
2015-12-20 23:27:33 +01:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2015-12-19 20:49:01 +01:00
|
|
|
if ( statusBar() )
|
2016-07-09 00:01:59 +02:00
|
|
|
statusBar()->clearMessage();
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( mouse_down )
|
|
|
|
return;
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
mouse_down = true;
|
|
|
|
|
2015-10-10 03:14:14 +02:00
|
|
|
if ( ! isActiveWindow() )
|
|
|
|
setActiveWindow(this);
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( ! itemlist.empty() )
|
|
|
|
{
|
|
|
|
std::vector<FMenuItem*>::const_iterator iter, end;
|
2015-10-10 03:14:14 +02:00
|
|
|
int mouse_x, mouse_y;
|
2015-09-30 22:39:02 +02:00
|
|
|
bool focus_changed = false;
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
2015-10-10 03:14:14 +02:00
|
|
|
mouse_x = ev->getX();
|
|
|
|
mouse_y = ev->getY();
|
2015-11-04 00:14:23 +01:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
while ( iter != end )
|
|
|
|
{
|
2015-10-10 03:14:14 +02:00
|
|
|
int x1, x2;
|
2015-09-30 22:39:02 +02:00
|
|
|
x1 = (*iter)->getX();
|
2016-01-10 10:42:55 +01:00
|
|
|
x2 = (*iter)->getX() + (*iter)->getWidth();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-07-03 20:08:39 +02:00
|
|
|
if ( mouse_y == 1 )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-07-03 20:16:43 +02:00
|
|
|
if ( mouse_x >= x1 && mouse_x < x2 )
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-07-03 20:08:39 +02:00
|
|
|
// Mouse pointer over item
|
|
|
|
if ( (*iter)->isEnabled() && ! (*iter)->isSelected() )
|
2015-12-08 21:05:00 +01:00
|
|
|
{
|
2016-07-03 20:08:39 +02:00
|
|
|
FWidget* focused_widget = getFocusWidget();
|
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
|
|
|
(*iter)->setSelected();
|
|
|
|
(*iter)->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-24 20:18:23 +02:00
|
|
|
if ( focused_widget && ! focused_widget->isWindow() )
|
2016-07-03 20:08:39 +02:00
|
|
|
focused_widget->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:08:39 +02:00
|
|
|
(*iter)->openMenu();
|
|
|
|
setSelectedItem(*iter);
|
|
|
|
focus_changed = true;
|
|
|
|
|
|
|
|
if ( (*iter)->hasMenu() )
|
2015-12-08 21:05:00 +01:00
|
|
|
{
|
2016-07-03 20:08:39 +02:00
|
|
|
FMenu* menu = (*iter)->getMenu();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:08:39 +02:00
|
|
|
if ( menu->hasSelectedItem() )
|
|
|
|
{
|
|
|
|
menu->unselectItem();
|
|
|
|
menu->redraw();
|
|
|
|
drop_down = true;
|
|
|
|
}
|
2015-12-08 21:05:00 +01:00
|
|
|
}
|
|
|
|
}
|
2015-09-30 22:39:02 +02:00
|
|
|
}
|
2016-07-03 20:08:39 +02:00
|
|
|
else if ( (*iter)->isEnabled() && (*iter)->isSelected() )
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
|
|
|
(*iter)->unsetSelected();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( getSelectedItem() == *iter )
|
|
|
|
setSelectedItem(0);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
focus_changed = true;
|
|
|
|
}
|
2015-08-16 20:05:39 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
++iter;
|
|
|
|
}
|
2016-07-03 20:08:39 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-03 20:08:39 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
if ( focus_changed )
|
2016-06-22 00:48:33 +02:00
|
|
|
{
|
2015-09-30 22:39:02 +02:00
|
|
|
redraw();
|
2016-06-22 00:48:33 +02:00
|
|
|
updateTerminal();
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FMenuBar::onMouseUp (FMouseEvent* ev)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-08-09 23:47:08 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( mouse_down )
|
|
|
|
{
|
|
|
|
mouse_down = false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( ! itemlist.empty() )
|
|
|
|
{
|
2015-10-10 03:14:14 +02:00
|
|
|
int mouse_x, mouse_y;
|
2016-07-09 00:01:59 +02:00
|
|
|
std::vector<FMenuItem*>::const_iterator iter, end;
|
2015-08-09 23:47:08 +02:00
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
2015-10-10 03:14:14 +02:00
|
|
|
mouse_x = ev->getX();
|
|
|
|
mouse_y = ev->getY();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
2015-10-10 03:14:14 +02:00
|
|
|
int x1, x2;
|
2015-09-30 22:39:02 +02:00
|
|
|
x1 = (*iter)->getX();
|
2016-01-10 10:42:55 +01:00
|
|
|
x2 = (*iter)->getX() + (*iter)->getWidth();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-07-03 20:08:39 +02:00
|
|
|
if ( mouse_y == 1 )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-07-03 20:16:43 +02:00
|
|
|
if ( (*iter)->isEnabled() && (*iter)->isSelected() )
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-07-03 20:16:43 +02:00
|
|
|
if ( mouse_x >= x1 && mouse_x < x2 )
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-07-03 20:16:43 +02:00
|
|
|
// Mouse pointer over item
|
|
|
|
if ( (*iter)->hasMenu() )
|
2016-07-03 20:08:39 +02:00
|
|
|
{
|
2016-07-03 20:16:43 +02:00
|
|
|
FMenu* menu = (*iter)->getMenu();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:16:43 +02:00
|
|
|
if ( ! menu->hasSelectedItem() )
|
|
|
|
{
|
|
|
|
FMenuItem* first_item;
|
|
|
|
menu->selectFirstItem();
|
|
|
|
first_item = menu->getSelectedItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:16:43 +02:00
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:16:43 +02:00
|
|
|
menu->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:16:43 +02:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:16:43 +02:00
|
|
|
redraw();
|
|
|
|
drop_down = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(*iter)->unsetSelected();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:16:43 +02:00
|
|
|
if ( getSelectedItem() == *iter )
|
|
|
|
{
|
|
|
|
setSelectedItem(0);
|
|
|
|
leaveMenuBar();
|
|
|
|
drop_down = false;
|
|
|
|
(*iter)->processClicked();
|
|
|
|
return;
|
|
|
|
}
|
2016-07-03 20:08:39 +02:00
|
|
|
}
|
2015-09-30 22:39:02 +02:00
|
|
|
}
|
2016-07-03 20:08:39 +02:00
|
|
|
else
|
2015-12-20 23:27:33 +01:00
|
|
|
{
|
2016-07-03 20:08:39 +02:00
|
|
|
(*iter)->unsetSelected();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:08:39 +02:00
|
|
|
if ( getSelectedItem() == *iter )
|
|
|
|
setSelectedItem(0);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-03 20:16:43 +02:00
|
|
|
redraw();
|
2015-12-20 23:27:33 +01:00
|
|
|
}
|
2015-08-22 18:53:52 +02:00
|
|
|
}
|
2015-11-07 23:16:09 +01:00
|
|
|
}
|
2016-07-10 03:51:20 +02:00
|
|
|
|
|
|
|
++iter;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-15 19:46:33 +01:00
|
|
|
if ( ! hasSelectedItem() )
|
|
|
|
leaveMenuBar();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FMenuBar::onMouseMove (FMouseEvent* ev)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-08-09 23:47:08 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-10 03:14:14 +02:00
|
|
|
if ( ! isActiveWindow() )
|
|
|
|
setActiveWindow(this);
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( mouse_down && ! itemlist.empty() )
|
|
|
|
{
|
|
|
|
std::vector<FMenuItem*>::const_iterator iter, end;
|
2015-10-10 03:14:14 +02:00
|
|
|
int mouse_x, mouse_y;
|
2015-11-22 23:54:05 +01:00
|
|
|
bool mouse_over_menubar = false;
|
2015-08-09 23:47:08 +02:00
|
|
|
bool focus_changed = false;
|
|
|
|
iter = itemlist.begin();
|
|
|
|
end = itemlist.end();
|
2015-10-10 03:14:14 +02:00
|
|
|
mouse_x = ev->getX();
|
|
|
|
mouse_y = ev->getY();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2015-11-22 23:54:05 +01:00
|
|
|
if ( getGeometryGlobal().contains(ev->getGlobalPos()) )
|
|
|
|
mouse_over_menubar = true;
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
while ( iter != end )
|
|
|
|
{
|
2015-10-10 03:14:14 +02:00
|
|
|
int x1, x2;
|
2015-09-30 22:39:02 +02:00
|
|
|
x1 = (*iter)->getX();
|
2016-01-10 10:42:55 +01:00
|
|
|
x2 = (*iter)->getX() + (*iter)->getWidth();
|
2015-09-28 04:31:29 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( mouse_x >= x1
|
2016-01-10 10:42:55 +01:00
|
|
|
&& mouse_x < x2
|
2015-08-09 23:47:08 +02:00
|
|
|
&& mouse_y == 1 )
|
|
|
|
{
|
2015-11-22 21:41:18 +01:00
|
|
|
// Mouse pointer over item
|
2015-10-29 21:10:50 +01:00
|
|
|
if ( (*iter)->isEnabled() && ! (*iter)->isSelected() )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-11-01 22:45:23 +01:00
|
|
|
FWidget* focused_widget = getFocusWidget();
|
2016-01-17 02:57:08 +01:00
|
|
|
FFocusEvent out (fc::FocusOut_Event);
|
2015-11-01 22:45:23 +01:00
|
|
|
FApplication::queueEvent(focused_widget, &out);
|
2015-10-10 03:14:14 +02:00
|
|
|
(*iter)->setSelected();
|
2015-10-29 21:10:50 +01:00
|
|
|
(*iter)->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-07-24 20:18:23 +02:00
|
|
|
if ( focused_widget && ! focused_widget->isWindow() )
|
2015-12-08 21:05:00 +01:00
|
|
|
focused_widget->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
(*iter)->openMenu();
|
2015-11-07 23:16:09 +01:00
|
|
|
setSelectedItem(*iter);
|
2015-08-09 23:47:08 +02:00
|
|
|
focus_changed = true;
|
2015-11-01 22:45:23 +01:00
|
|
|
|
|
|
|
if ( (*iter)->hasMenu() )
|
|
|
|
{
|
2016-07-09 00:01:59 +02:00
|
|
|
FMenu* menu = (*iter)->getMenu();
|
|
|
|
|
|
|
|
if ( menu->hasSelectedItem() )
|
|
|
|
{
|
|
|
|
menu->unselectItem();
|
|
|
|
menu->redraw();
|
|
|
|
drop_down = true;
|
|
|
|
}
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2015-11-01 22:45:23 +01:00
|
|
|
else if ( statusBar() )
|
|
|
|
statusBar()->clearMessage();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-22 23:54:05 +01:00
|
|
|
if ( mouse_over_menubar
|
2015-10-29 21:10:50 +01:00
|
|
|
&& (*iter)->isEnabled()
|
2015-10-10 03:14:14 +02:00
|
|
|
&& (*iter)->isSelected() )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-11-22 21:41:18 +01:00
|
|
|
// Unselect selected item without mouse focus
|
2015-08-09 23:47:08 +02:00
|
|
|
(*iter)->unsetSelected();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( getSelectedItem() == *iter )
|
|
|
|
setSelectedItem(0);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
focus_changed = true;
|
2015-11-05 23:25:21 +01:00
|
|
|
drop_down = false;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2015-11-07 23:16:09 +01:00
|
|
|
else if ( hasSelectedItem() && getSelectedItem()->hasMenu() )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2015-11-01 22:45:23 +01:00
|
|
|
// Mouse event handover to the menu
|
2015-11-07 23:16:09 +01:00
|
|
|
FMenu* menu = getSelectedItem()->getMenu();
|
2015-10-10 03:14:14 +02:00
|
|
|
const FRect& menu_geometry = menu->getGeometryGlobal();
|
|
|
|
|
2015-12-16 23:57:14 +01:00
|
|
|
if ( menu->count() > 0
|
|
|
|
&& menu_geometry.contains(ev->getGlobalPos()) )
|
2015-10-10 03:14:14 +02:00
|
|
|
{
|
2016-07-09 00:01:59 +02:00
|
|
|
FMouseEvent* _ev;
|
2015-10-10 03:14:14 +02:00
|
|
|
const FPoint& g = ev->getGlobalPos();
|
|
|
|
const FPoint& p = menu->globalToLocalPos(g);
|
|
|
|
int b = ev->getButton();
|
2016-07-09 00:01:59 +02:00
|
|
|
_ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
|
2015-11-07 23:16:09 +01:00
|
|
|
menu->mouse_down = true;
|
2015-10-10 03:14:14 +02:00
|
|
|
setClickedWidget(menu);
|
2015-11-25 22:10:23 +01:00
|
|
|
menu->onMouseMove(_ev);
|
|
|
|
delete _ev;
|
2015-10-10 03:14:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
++iter;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( focus_changed )
|
2016-06-22 00:48:33 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
redraw();
|
2016-06-22 00:48:33 +02:00
|
|
|
updateTerminal();
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 00:14:23 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
unselectItem();
|
|
|
|
selectFirstItem();
|
|
|
|
getSelectedItem()->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( statusBar() )
|
|
|
|
statusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
redraw();
|
2015-11-04 00:14:23 +01:00
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::hide()
|
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
int screenWidth;
|
|
|
|
short fg, bg;
|
2015-08-09 23:47:08 +02:00
|
|
|
char* blank;
|
|
|
|
|
2015-09-22 22:12:31 +02:00
|
|
|
FWindow::hide();
|
2015-08-09 23:47:08 +02:00
|
|
|
fg = wc.term_fg;
|
|
|
|
bg = wc.term_bg;
|
|
|
|
setColor (fg, bg);
|
|
|
|
screenWidth = getColumnNumber();
|
|
|
|
blank = new char[screenWidth+1];
|
|
|
|
memset(blank, ' ', uLong(screenWidth));
|
|
|
|
blank[screenWidth] = '\0';
|
2015-09-30 22:39:02 +02:00
|
|
|
gotoxy (1,1);
|
2015-08-09 23:47:08 +02:00
|
|
|
print (vmenubar, blank);
|
|
|
|
delete[] blank;
|
|
|
|
}
|
|
|
|
|
2015-11-05 23:25:21 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::resetMenu()
|
|
|
|
{
|
2015-11-07 23:16:09 +01:00
|
|
|
unselectItem();
|
2015-11-05 23:25:21 +01:00
|
|
|
drop_down = false;
|
|
|
|
}
|
|
|
|
|
2015-12-16 23:57:14 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::adjustSize()
|
|
|
|
{
|
|
|
|
xmin = ymin = 1;
|
|
|
|
height = 1;
|
|
|
|
xpos = 1;
|
|
|
|
width = getColumnNumber();
|
|
|
|
ypos = 1;
|
|
|
|
adjustItems();
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::setGeometry (int xx, int yy, int ww, int hh, bool adjust)
|
|
|
|
{
|
|
|
|
int old_width = width;
|
|
|
|
int old_height = height;
|
|
|
|
FWidget::setGeometry (xx, yy, ww, hh, adjust);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
if ( vmenubar && (width != old_width || height != old_height) )
|
|
|
|
resizeArea (vmenubar);
|
|
|
|
}
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::cb_item_deactivated (FWidget* widget, void*)
|
|
|
|
{
|
|
|
|
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
|
|
|
|
|
|
|
|
if ( menuitem->hasMenu() )
|
|
|
|
{
|
|
|
|
FMenu* menu = menuitem->getMenu();
|
2015-10-19 00:07:07 +02:00
|
|
|
menu->hide();
|
2015-11-24 23:40:41 +01:00
|
|
|
menu->hideSubMenus();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-03 20:08:39 +02:00
|
|
|
|