2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fmenubar.cpp - Widget FMenuBar *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-01-09 20:05:29 +01:00
|
|
|
* Copyright 2015-2019 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2018-12-28 22:57:43 +01:00
|
|
|
#include <memory>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fevent.h"
|
|
|
|
#include "final/fmenu.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fmenubar.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fmenuitem.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fstatusbar.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fwidgetcolors.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
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)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
FMenuBar::~FMenuBar() // destructor
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-10-02 21:26:25 +02:00
|
|
|
setMenuBar(0);
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FMenuBar
|
2018-09-24 04:02:35 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::resetMenu()
|
|
|
|
{
|
|
|
|
unselectItem();
|
|
|
|
drop_down = false;
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::hide()
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWindow::hide();
|
2018-12-15 00:50:09 +01:00
|
|
|
FColor fg = wc.term_fg;
|
|
|
|
FColor bg = wc.term_bg;
|
2016-11-02 00:37:58 +01:00
|
|
|
setColor (fg, bg);
|
2017-12-30 21:27:17 +01:00
|
|
|
screenWidth = getDesktopWidth();
|
2019-07-14 23:05:54 +02:00
|
|
|
char* blank = createBlankArray (screenWidth + 1);
|
2019-01-27 13:44:13 +01:00
|
|
|
print() << FPoint(1, 1) << blank;
|
2018-10-20 22:50:35 +02:00
|
|
|
destroyBlankArray (blank);
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 20:05:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::adjustSize()
|
2015-08-16 20:05:39 +02:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
setGeometry (FPoint(1, 1), FSize(getDesktopWidth(), 1), false);
|
2016-11-02 00:37:58 +01:00
|
|
|
adjustItems();
|
2015-08-16 20:05:39 +02:00
|
|
|
}
|
|
|
|
|
2015-11-01 22:45:23 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::onKeyPress (FKeyEvent* ev)
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
switch ( ev->key() )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Fkey_return:
|
|
|
|
case fc::Fkey_enter:
|
|
|
|
case fc::Fkey_up:
|
|
|
|
case fc::Fkey_down:
|
|
|
|
if ( hasSelectedItem() )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto sel_item = getSelectedItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( sel_item->hasMenu() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = sel_item->getMenu();
|
2016-11-02 00:37:58 +01:00
|
|
|
sel_item->openMenu();
|
|
|
|
menu->selectFirstItem();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto first_item = menu->getSelectedItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
menu->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
redraw();
|
|
|
|
drop_down = true;
|
|
|
|
}
|
2017-01-15 19:48:27 +01:00
|
|
|
else if ( ev->key() == fc::Fkey_return
|
2017-11-26 22:37:18 +01:00
|
|
|
|| ev->key() == fc::Fkey_enter )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
unselectItem();
|
|
|
|
redraw();
|
|
|
|
sel_item->processClicked();
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
ev->accept();
|
|
|
|
break;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Fkey_left:
|
|
|
|
selectPrevItem();
|
|
|
|
ev->accept();
|
|
|
|
break;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Fkey_right:
|
|
|
|
selectNextItem();
|
|
|
|
ev->accept();
|
|
|
|
break;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Fkey_escape:
|
|
|
|
case fc::Fkey_escape_mintty:
|
|
|
|
leaveMenuBar();
|
|
|
|
ev->accept();
|
2015-11-01 22:45:23 +01:00
|
|
|
break;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
default:
|
|
|
|
break;
|
2015-11-01 22:45:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::onMouseDown (FMouseEvent* ev)
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-11-01 22:45:23 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
mouse_down = false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! item_list.empty() && hasSelectedItem() )
|
|
|
|
leaveMenuBar();
|
|
|
|
else
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->clearMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( mouse_down )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
mouse_down = true;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! isWindowActive() )
|
|
|
|
setActiveWindow(this);
|
2015-11-01 22:45:23 +01:00
|
|
|
|
2017-12-31 03:25:50 +01:00
|
|
|
// Handle menu entries
|
|
|
|
mouseDownOverList(ev);
|
2015-11-04 00:14:23 +01:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::onMouseUp (FMouseEvent* ev)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
|
|
|
return;
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( mouse_down )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
mouse_down = false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-31 03:25:50 +01:00
|
|
|
// Handle menu entries
|
|
|
|
mouseUpOverList(ev);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::onMouseMove (FMouseEvent* ev)
|
|
|
|
{
|
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
|
|
|
return;
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! isWindowActive() )
|
|
|
|
setActiveWindow(this);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2017-12-31 03:25:50 +01:00
|
|
|
// Handle menu entries
|
|
|
|
if ( mouse_down )
|
|
|
|
mouseMoveOverList(ev);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-10-01 03:48:58 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
|
|
|
unselectItem();
|
|
|
|
selectFirstItem();
|
|
|
|
getSelectedItem()->setFocus();
|
2016-07-09 00:01:59 +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
|
|
|
redraw();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
void FMenuBar::cb_item_deactivated (FWidget* widget, FDataPtr)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menuitem = static_cast<FMenuItem*>(widget);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( menuitem->hasMenu() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = menuitem->getMenu();
|
2016-11-02 00:37:58 +01:00
|
|
|
menu->hide();
|
|
|
|
menu->hideSubMenus();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-10-11 04:09:58 +02:00
|
|
|
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// private methods of FMenuBar
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::init()
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto r = getRootWidget();
|
|
|
|
auto w = r->getWidth();
|
2016-11-02 00:37:58 +01:00
|
|
|
// initialize geometry values
|
2019-01-21 03:42:18 +01:00
|
|
|
setGeometry (FPoint(1, 1), FSize(w, 1), false);
|
2016-11-02 00:37:58 +01:00
|
|
|
setAlwaysOnTop();
|
|
|
|
setMenuBar(this);
|
|
|
|
ignorePadding();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getRootWidget() )
|
|
|
|
getRootWidget()->setTopPadding(1, true);
|
|
|
|
|
|
|
|
addAccelerator (fc::Fkey_f10);
|
|
|
|
addAccelerator (fc::Fckey_space);
|
|
|
|
setForegroundColor (wc.menu_active_fg);
|
|
|
|
setBackgroundColor (wc.menu_active_bg);
|
|
|
|
unsetFocusable();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::calculateDimensions()
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
FPoint item_pos (1, 1);
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
2015-12-16 23:57:14 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// find the maximum item width
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-12-16 23:57:14 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t len = (*iter)->getTextLength();
|
|
|
|
int item_width = int(len) + 2;
|
2015-12-16 23:57:14 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// set item geometry
|
2019-01-21 03:42:18 +01:00
|
|
|
(*iter)->setGeometry (item_pos, FSize(std::size_t(item_width), 1), false);
|
2015-12-16 23:57:14 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// set menu position
|
|
|
|
if ( (*iter)->hasMenu() )
|
2019-01-21 03:42:18 +01:00
|
|
|
(*iter)->getMenu()->setPos (item_pos, false);
|
2015-12-16 23:57:14 +01:00
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
item_pos.x_ref() += item_width;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FMenuBar::selectNextItem()
|
2015-11-15 19:46:33 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
if ( (*iter)->isSelected() )
|
|
|
|
{
|
|
|
|
FMenuItem* next;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto next_element = iter;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
++next_element;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( next_element == item_list.end() )
|
|
|
|
next_element = item_list.begin();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
next = static_cast<FMenuItem*>(*next_element);
|
2016-12-18 23:34:11 +01:00
|
|
|
} while ( ! next->isEnabled()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| ! next->acceptFocus()
|
2019-01-09 20:05:29 +01:00
|
|
|
|| ! next->isShown()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| next->isSeparator() );
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( next == *iter )
|
|
|
|
return false;
|
|
|
|
|
2018-02-03 00:04:24 +01:00
|
|
|
updateTerminal (FVTerm::stop_refresh);
|
2016-11-02 00:37:58 +01:00
|
|
|
unselectItem();
|
|
|
|
next->setSelected();
|
|
|
|
setSelectedItem(next);
|
|
|
|
next->setFocus();
|
|
|
|
|
|
|
|
if ( drop_down && next->hasMenu() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = next->getMenu();
|
2016-11-02 00:37:58 +01:00
|
|
|
next->openMenu();
|
|
|
|
menu->selectFirstItem();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto first_item = menu->getSelectedItem();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
|
|
|
|
|
|
|
menu->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
|
|
|
|
redraw();
|
2018-02-03 00:04:24 +01:00
|
|
|
updateTerminal (FVTerm::start_refresh);
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-11-15 19:46:33 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 21:10:50 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FMenuBar::selectPrevItem()
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.end();
|
|
|
|
auto first = item_list.begin();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
do
|
2015-10-29 21:10:50 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
--iter;
|
2015-11-05 23:25:21 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( (*iter)->isSelected() )
|
|
|
|
{
|
|
|
|
FMenuItem* prev;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto prev_element = iter;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( prev_element == item_list.begin() )
|
|
|
|
prev_element = item_list.end();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
--prev_element;
|
|
|
|
prev = static_cast<FMenuItem*>(*prev_element);
|
|
|
|
}
|
2016-12-18 23:34:11 +01:00
|
|
|
while ( ! prev->isEnabled()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| ! prev->acceptFocus()
|
2019-01-09 20:05:29 +01:00
|
|
|
|| ! prev->isShown()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| prev->isSeparator() );
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( prev == *iter )
|
|
|
|
return false;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-02-03 00:04:24 +01:00
|
|
|
updateTerminal (FVTerm::stop_refresh);
|
2016-11-02 00:37:58 +01:00
|
|
|
unselectItem();
|
|
|
|
prev->setSelected();
|
|
|
|
prev->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( drop_down && prev->hasMenu() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = prev->getMenu();
|
2016-11-02 00:37:58 +01:00
|
|
|
prev->openMenu();
|
|
|
|
menu->selectFirstItem();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto first_item = menu->getSelectedItem();
|
2015-11-01 22:45:23 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
menu->redraw();
|
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2015-11-05 23:25:21 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setSelectedItem(prev);
|
|
|
|
redraw();
|
2018-02-03 00:04:24 +01:00
|
|
|
updateTerminal (FVTerm::stop_refresh);
|
2015-10-29 21:10:50 +01:00
|
|
|
break;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != first );
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
return true;
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool FMenuBar::hotkeyMenu (FKeyEvent*& ev)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( (*iter)->isEnabled() )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2018-11-21 20:07:08 +01:00
|
|
|
uChar hotkey = (*iter)->getHotkey();
|
|
|
|
FKey key = ev->key();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2018-11-21 20:07:08 +01:00
|
|
|
if ( fc::Fmkey_meta + FKey(std::tolower(hotkey)) == key )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto sel_item = getSelectedItem();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( sel_item && sel_item->hasMenu() )
|
|
|
|
sel_item->getMenu()->unselectItem();
|
|
|
|
|
|
|
|
unselectItem();
|
|
|
|
|
|
|
|
if ( (*iter)->hasMenu() )
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = (*iter)->getMenu();
|
2017-09-09 22:03:17 +02:00
|
|
|
(*iter)->setSelected();
|
|
|
|
setSelectedItem(*iter);
|
|
|
|
(*iter)->setFocus();
|
|
|
|
(*iter)->openMenu();
|
|
|
|
menu->selectFirstItem();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto first_item = menu->getSelectedItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-09 22:03:17 +02:00
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-09 22:03:17 +02:00
|
|
|
menu->redraw();
|
2016-07-03 20:08:39 +02:00
|
|
|
|
2017-09-09 22:03:17 +02:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-09 22:03:17 +02:00
|
|
|
redraw();
|
|
|
|
drop_down = true;
|
2015-09-30 22:39:02 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
setSelectedItem(0);
|
|
|
|
redraw();
|
|
|
|
drop_down = false;
|
|
|
|
(*iter)->processClicked();
|
2015-09-30 22:39:02 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
ev->accept();
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2016-07-03 20:08:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
++iter;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
return false;
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::draw()
|
|
|
|
{
|
|
|
|
drawItems();
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::drawItems()
|
|
|
|
{
|
|
|
|
if ( item_list.empty() )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-01-27 13:44:13 +01:00
|
|
|
print() << FPoint(1, 1);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-30 21:27:17 +01:00
|
|
|
screenWidth = getDesktopWidth();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
|
|
|
std::size_t x = 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
drawItem (*iter, x);
|
|
|
|
++iter;
|
|
|
|
}
|
2016-07-10 03:51:20 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
// Print spaces to end of line
|
2018-10-18 23:50:06 +02:00
|
|
|
for (; x <= screenWidth; x++)
|
2017-12-21 00:25:58 +01:00
|
|
|
print (' ');
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-18 23:50:06 +02:00
|
|
|
inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
FString txt = menuitem->getText();
|
|
|
|
menuText txtdata;
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t txt_length = txt.getLength();
|
|
|
|
std::size_t to_char;
|
2018-10-18 23:50:06 +02:00
|
|
|
std::size_t hotkeypos;
|
2017-12-21 00:25:58 +01:00
|
|
|
bool is_enabled = menuitem->isEnabled();
|
|
|
|
bool is_selected = menuitem->isSelected();
|
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
txtdata.startpos = x + 1;
|
2018-11-04 23:00:06 +01:00
|
|
|
txtdata.no_underline = menuitem->getFlags().no_underline;
|
2017-12-21 00:25:58 +01:00
|
|
|
|
|
|
|
// Set screen attributes
|
|
|
|
setLineAttributes (menuitem);
|
|
|
|
drawLeadingSpace (x);
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
txtdata.text = new wchar_t[txt_length + 1]();
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
2018-11-22 21:51:32 +01:00
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
2017-12-21 00:25:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( x - 1 <= screenWidth )
|
2018-10-14 06:25:33 +02:00
|
|
|
to_char = txt_length;
|
2017-12-21 00:25:58 +01:00
|
|
|
else
|
2018-10-18 23:50:06 +02:00
|
|
|
to_char = txt_length - screenWidth - x - 1;
|
2017-12-21 00:25:58 +01:00
|
|
|
|
2019-08-11 20:07:39 +02:00
|
|
|
hotkeypos = finalcut::getHotkeyPos (txt.wc_str(), txtdata.text, txt_length);
|
2017-12-21 00:25:58 +01:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( hotkeypos != NOT_SET )
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
txt_length--;
|
|
|
|
to_char--;
|
|
|
|
}
|
2017-08-12 22:55:29 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
txtdata.length = to_char;
|
2018-10-18 23:50:06 +02:00
|
|
|
x += txt_length;
|
2017-12-21 00:25:58 +01:00
|
|
|
|
|
|
|
if ( ! is_enabled || is_selected )
|
2018-10-18 23:50:06 +02:00
|
|
|
txtdata.hotkeypos = NOT_SET;
|
2017-12-21 00:25:58 +01:00
|
|
|
else
|
|
|
|
txtdata.hotkeypos = hotkeypos;
|
|
|
|
|
|
|
|
drawMenuText (txtdata);
|
|
|
|
drawEllipsis (txtdata, x);
|
|
|
|
drawTrailingSpace (x);
|
|
|
|
|
|
|
|
setColor (wc.menu_active_fg, wc.menu_active_bg);
|
|
|
|
|
|
|
|
if ( isMonochron() && is_enabled && is_selected )
|
|
|
|
setReverse(true);
|
|
|
|
|
|
|
|
delete[] txtdata.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-25 21:17:08 +01:00
|
|
|
inline void FMenuBar::setLineAttributes (FMenuItem* menuitem)
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
bool is_enabled = menuitem->isEnabled();
|
|
|
|
bool is_selected = menuitem->isSelected();
|
|
|
|
|
|
|
|
if ( is_enabled )
|
|
|
|
{
|
|
|
|
if ( is_selected )
|
2017-08-12 22:55:29 +02:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
|
|
|
|
setForegroundColor (wc.menu_active_focus_fg);
|
|
|
|
setBackgroundColor (wc.menu_active_focus_bg);
|
2017-08-12 22:55:29 +02:00
|
|
|
}
|
2017-12-21 00:25:58 +01:00
|
|
|
else
|
2017-08-12 22:55:29 +02:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
setForegroundColor (wc.menu_active_fg);
|
|
|
|
setBackgroundColor (wc.menu_active_bg);
|
2017-08-12 22:55:29 +02:00
|
|
|
}
|
2017-12-21 00:25:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setForegroundColor (wc.menu_inactive_fg);
|
|
|
|
setBackgroundColor (wc.menu_inactive_bg);
|
|
|
|
}
|
2017-08-12 22:55:29 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
setColor();
|
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-12-25 21:17:08 +01:00
|
|
|
inline void FMenuBar::drawMenuText (menuText& data)
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
// Print menu text
|
2015-11-22 23:54:05 +01:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
for (std::size_t z = 0; z < data.length; z++)
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( data.startpos > screenWidth - z )
|
2017-12-21 00:25:58 +01:00
|
|
|
break;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
if ( ! std::iswprint(wint_t(data.text[z])) )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
if ( ! isNewFont()
|
|
|
|
&& ( int(data.text[z]) < fc::NF_rev_left_arrow2
|
|
|
|
|| int(data.text[z]) > fc::NF_check_mark ) )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
data.text[z] = L' ';
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2017-12-21 00:25:58 +01:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( z == data.hotkeypos )
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
if ( ! data.no_underline )
|
|
|
|
setUnderline();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
print (data.text[z]);
|
2015-10-10 03:14:14 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
if ( ! data.no_underline )
|
|
|
|
unsetUnderline();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
setColor();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2017-12-21 00:25:58 +01:00
|
|
|
else
|
|
|
|
print (data.text[z]);
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 22:57:43 +01:00
|
|
|
inline void FMenuBar::drawEllipsis (const menuText& txtdata, std::size_t x)
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( x > screenWidth + 1 )
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
if ( txtdata.startpos < screenWidth )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
// Print ellipsis
|
2019-01-27 13:44:13 +01:00
|
|
|
print() << FPoint(int(screenWidth) - 1, 1) << "..";
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2017-12-21 00:25:58 +01:00
|
|
|
else if ( txtdata.startpos - 1 <= screenWidth )
|
2016-06-22 00:48:33 +02:00
|
|
|
{
|
2017-12-21 00:25:58 +01:00
|
|
|
// Hide first character from text
|
2019-01-27 13:44:13 +01:00
|
|
|
print() << FPoint(int(screenWidth), 1) << ' ';
|
2017-12-21 00:25:58 +01:00
|
|
|
}
|
2019-01-27 13:44:13 +01:00
|
|
|
}
|
2017-12-21 00:25:58 +01:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-18 23:50:06 +02:00
|
|
|
inline void FMenuBar::drawLeadingSpace (std::size_t& x)
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
// Print a leading blank space
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( x < screenWidth )
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
x++;
|
|
|
|
print (' ');
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2017-12-21 00:25:58 +01:00
|
|
|
}
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-18 23:50:06 +02:00
|
|
|
inline void FMenuBar::drawTrailingSpace (std::size_t& x)
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
// Print a trailing blank space
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( x < screenWidth )
|
2017-12-21 00:25:58 +01:00
|
|
|
{
|
|
|
|
x++;
|
|
|
|
print (' ');
|
|
|
|
}
|
2015-11-04 00:14:23 +01:00
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::adjustItems()
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
int item_X = 1;
|
|
|
|
int item_Y = 1;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
// get item width
|
2018-10-14 06:25:33 +02:00
|
|
|
int item_width = int((*iter)->getWidth());
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( (*iter)->hasMenu() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = (*iter)->getMenu();
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// set menu position
|
2019-01-21 03:42:18 +01:00
|
|
|
menu->setPos (FPoint(menu->adjustX(item_X), item_Y));
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// call menu adjustItems()
|
|
|
|
menu->adjustItems();
|
|
|
|
}
|
2015-11-05 23:25:21 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
item_X += item_width;
|
|
|
|
++iter;
|
|
|
|
}
|
2015-12-16 23:57:14 +01:00
|
|
|
}
|
|
|
|
|
2017-12-31 03:25:50 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::selectMenuItem (FMenuItem* item)
|
|
|
|
{
|
|
|
|
if ( ! item->isEnabled() || item->isSelected() )
|
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
2019-01-09 20:05:29 +01:00
|
|
|
unselectItem();
|
2017-12-31 03:25:50 +01:00
|
|
|
item->setSelected();
|
|
|
|
item->setFocus();
|
|
|
|
|
|
|
|
if ( focused_widget && ! focused_widget->isWindowWidget() )
|
|
|
|
focused_widget->redraw();
|
|
|
|
|
|
|
|
item->openMenu();
|
|
|
|
setSelectedItem(item);
|
|
|
|
focus_changed = true;
|
|
|
|
|
|
|
|
if ( item->hasMenu() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = item->getMenu();
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( menu->hasSelectedItem() )
|
|
|
|
{
|
|
|
|
menu->unselectItem();
|
|
|
|
menu->redraw();
|
|
|
|
drop_down = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuBar::activateMenu (FMenuItem* item)
|
|
|
|
{
|
|
|
|
if ( ! item->hasMenu() )
|
|
|
|
return false;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto menu = item->getMenu();
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( ! menu->hasSelectedItem() )
|
|
|
|
{
|
|
|
|
menu->selectFirstItem();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto first_item = menu->getSelectedItem();
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( first_item )
|
|
|
|
first_item->setFocus();
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
menu->redraw();
|
|
|
|
drop_down = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FMenuBar::clickItem (FMenuItem* item)
|
|
|
|
{
|
|
|
|
if ( item->hasMenu() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
item->unsetSelected();
|
|
|
|
|
|
|
|
if ( getSelectedItem() == item )
|
|
|
|
{
|
|
|
|
setSelectedItem(0);
|
|
|
|
leaveMenuBar();
|
|
|
|
drop_down = false;
|
|
|
|
item->processClicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuBar::unselectMenuItem (FMenuItem* item)
|
|
|
|
{
|
|
|
|
if ( ! item->isEnabled() || ! item->isSelected() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
item->unsetSelected();
|
|
|
|
focus_changed = true;
|
|
|
|
drop_down = false;
|
|
|
|
|
|
|
|
if ( getSelectedItem() == item )
|
|
|
|
setSelectedItem(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 22:57:43 +01:00
|
|
|
void FMenuBar::mouseDownOverList (const FMouseEvent* ev)
|
2017-12-31 03:25:50 +01:00
|
|
|
{
|
|
|
|
if ( item_list.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
focus_changed = false;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
|
|
|
int mouse_x = ev->getX();
|
|
|
|
int mouse_y = ev->getY();
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
while ( iter != last )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
int x1 = (*iter)->getX();
|
|
|
|
int x2 = (*iter)->getX() + int((*iter)->getWidth());
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( mouse_y == 1 )
|
|
|
|
{
|
|
|
|
if ( mouse_x >= x1 && mouse_x < x2 )
|
|
|
|
{
|
|
|
|
// Mouse pointer over item
|
|
|
|
selectMenuItem (*iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unselectMenuItem (*iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
|
|
|
if ( ! hasSelectedItem() )
|
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( focus_changed )
|
|
|
|
{
|
|
|
|
redraw();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 22:57:43 +01:00
|
|
|
void FMenuBar::mouseUpOverList (const FMouseEvent* ev)
|
2017-12-31 03:25:50 +01:00
|
|
|
{
|
|
|
|
if ( item_list.empty() )
|
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
|
|
|
int mouse_x = ev->getX();
|
|
|
|
int mouse_y = ev->getY();
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
while ( iter != last )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
int x1 = (*iter)->getX();
|
|
|
|
int x2 = (*iter)->getX() + int((*iter)->getWidth());
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( mouse_y == 1
|
|
|
|
&& mouse_x >= x1
|
|
|
|
&& mouse_x < x2
|
|
|
|
&& (*iter)->isEnabled()
|
|
|
|
&& (*iter)->isSelected() )
|
|
|
|
{
|
|
|
|
// Mouse pointer over item
|
|
|
|
if ( ! activateMenu(*iter) )
|
|
|
|
{
|
|
|
|
if ( clickItem(*iter) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unselectMenuItem(*iter);
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! hasSelectedItem() )
|
|
|
|
leaveMenuBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 22:57:43 +01:00
|
|
|
void FMenuBar::mouseMoveOverList (const FMouseEvent* ev)
|
2017-12-31 03:25:50 +01:00
|
|
|
{
|
|
|
|
if ( item_list.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
focus_changed = false;
|
2018-12-15 00:50:09 +01:00
|
|
|
bool mouse_over_menubar = false;
|
|
|
|
auto iter = item_list.begin();
|
|
|
|
auto last = item_list.end();
|
|
|
|
int mouse_x = ev->getX();
|
|
|
|
int mouse_y = ev->getY();
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( getTermGeometry().contains(ev->getTermPos()) )
|
|
|
|
mouse_over_menubar = true;
|
|
|
|
|
|
|
|
while ( iter != last )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
int x1 = (*iter)->getX();
|
|
|
|
int x2 = (*iter)->getX() + int((*iter)->getWidth());
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( mouse_x >= x1
|
|
|
|
&& mouse_x < x2
|
|
|
|
&& mouse_y == 1 )
|
|
|
|
{
|
|
|
|
// Mouse pointer over item
|
|
|
|
selectMenuItem(*iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( mouse_over_menubar )
|
|
|
|
{
|
|
|
|
// Unselect selected item without mouse focus
|
|
|
|
unselectMenuItem(*iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Event handover to the menu
|
|
|
|
passEventToMenu(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
|
|
|
if ( ! hasSelectedItem() )
|
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( focus_changed )
|
|
|
|
{
|
|
|
|
redraw();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 22:57:43 +01:00
|
|
|
void FMenuBar::passEventToMenu (const FMouseEvent*& ev)
|
2017-12-31 03:25:50 +01:00
|
|
|
{
|
|
|
|
if ( ! hasSelectedItem() || ! getSelectedItem()->hasMenu() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Mouse event handover to the menu
|
2018-12-19 22:04:02 +01:00
|
|
|
const auto& menu = getSelectedItem()->getMenu();
|
2018-12-15 00:50:09 +01:00
|
|
|
const auto& menu_geometry = menu->getTermGeometry();
|
2017-12-31 03:25:50 +01:00
|
|
|
|
|
|
|
if ( menu->getCount() > 0
|
|
|
|
&& menu_geometry.contains(ev->getTermPos()) )
|
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
const auto& t = ev->getTermPos();
|
|
|
|
const auto& p = menu->termToWidgetPos(t);
|
2017-12-31 03:25:50 +01:00
|
|
|
int b = ev->getButton();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2018-12-19 22:04:02 +01:00
|
|
|
const auto& _ev = \
|
|
|
|
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, t, b);
|
2017-12-31 03:25:50 +01:00
|
|
|
menu->mouse_down = true;
|
|
|
|
setClickedWidget(menu);
|
2018-12-19 22:04:02 +01:00
|
|
|
menu->onMouseMove(_ev.get());
|
2017-12-31 03:25:50 +01:00
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
2018-11-22 21:51:32 +01:00
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
2017-12-31 03:25:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMenuBar::leaveMenuBar()
|
2015-09-30 22:39:02 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
resetMenu();
|
|
|
|
redraw();
|
2015-09-30 22:39:02 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->clearMessage();
|
|
|
|
|
2018-10-29 00:45:45 +01:00
|
|
|
switchToPrevWindow(this);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
getStatusBar()->drawMessage();
|
2016-07-03 20:08:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
updateTerminal();
|
|
|
|
flush_out();
|
|
|
|
mouse_down = false;
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|