Shows accelerator keys on the right side of the FMenu

This commit is contained in:
Markus Gans 2015-11-12 23:14:12 +01:00
parent 6fd2e7c650
commit ca60b762a7
6 changed files with 85 additions and 37 deletions

View File

@ -1,5 +1,6 @@
2015-11-12 Markus Gans <guru.mail@muenster.de>
* Improve menu accelerator keys
* Shows accelerator keys on the right side of the FMenu.
2015-11-08 Markus Gans <guru.mail@muenster.de>
* Activate the previous window in case if the menu is open and

View File

@ -416,31 +416,31 @@ keyname;
static keyname FkeyName[] =
{
{ fc::Fckey_at , "Ctrl+@" },
{ fc::Fckey_a , "Ctrl+a" },
{ fc::Fckey_b , "Ctrl+b" },
{ fc::Fckey_c , "Ctrl+c" },
{ fc::Fckey_d , "Ctrl+d" },
{ fc::Fckey_e , "Ctrl+e" },
{ fc::Fckey_f , "Ctrl+f" },
{ fc::Fckey_g , "Ctrl+g" },
{ fc::Fkey_erase , "Backspace" }, // Ctrl+h
{ fc::Fkey_tab , "Tab" }, // Ctrl+i
{ fc::Fckey_h , "Ctrl+k" },
{ fc::Fckey_l , "Ctrl+l" },
{ fc::Fkey_return , "Return" }, // Ctrl+m
{ fc::Fckey_n , "Ctrl+n" },
{ fc::Fckey_o , "Ctrl+o" },
{ fc::Fckey_p , "Ctrl+p" },
{ fc::Fckey_q , "Ctrl+q" },
{ fc::Fckey_r , "Ctrl+r" },
{ fc::Fckey_s , "Ctrl+s" },
{ fc::Fckey_t , "Ctrl+t" },
{ fc::Fckey_u , "Ctrl+u" },
{ fc::Fckey_v , "Ctrl+v" },
{ fc::Fckey_w , "Ctrl+w" },
{ fc::Fckey_x , "Ctrl+x" },
{ fc::Fckey_y , "Ctrl+y" },
{ fc::Fckey_z , "Ctrl+t" },
{ fc::Fckey_a , "Ctrl+A" },
{ fc::Fckey_b , "Ctrl+B" },
{ fc::Fckey_c , "Ctrl+C" },
{ fc::Fckey_d , "Ctrl+D" },
{ fc::Fckey_e , "Ctrl+E" },
{ fc::Fckey_f , "Ctrl+F" },
{ fc::Fckey_g , "Ctrl+G" },
{ fc::Fkey_erase , "Backspace" }, // Ctrl+H
{ fc::Fkey_tab , "Tab" }, // Ctrl+I
{ fc::Fckey_h , "Ctrl+K" },
{ fc::Fckey_l , "Ctrl+L" },
{ fc::Fkey_return , "Return" }, // Ctrl+M
{ fc::Fckey_n , "Ctrl+N" },
{ fc::Fckey_o , "Ctrl+O" },
{ fc::Fckey_p , "Ctrl+P" },
{ fc::Fckey_q , "Ctrl+Q" },
{ fc::Fckey_r , "Ctrl+R" },
{ fc::Fckey_s , "Ctrl+S" },
{ fc::Fckey_t , "Ctrl+T" },
{ fc::Fckey_u , "Ctrl+U" },
{ fc::Fckey_v , "Ctrl+V" },
{ fc::Fckey_w , "Ctrl+W" },
{ fc::Fckey_x , "Ctrl+X" },
{ fc::Fckey_y , "Ctrl+Y" },
{ fc::Fckey_z , "Ctrl+Z" },
{ fc::Fkey_escape , "Esc" }, // Ctrl+[
{ fc::Fckey_backslash , "Ctrl+\\" },
{ fc::Fckey_right_square_bracket, "Ctrl+]" },

View File

@ -127,12 +127,19 @@ void FMenu::menu_dimension()
std::vector<FMenuItem*>::const_iterator iter, end;
iter = itemlist.begin();
end = itemlist.end();
maxItemWidth = 10;
maxItemWidth = 10; // minimum width
// find the max item width
// find the maximum item width
while ( iter != end )
{
uInt item_width = (*iter)->getTextLength() + 2;
int accel_key = (*iter)->accel_key;
if ( accel_key )
{
uInt accel_len = getKeyName(accel_key).getLength();
item_width += accel_len + 2;
}
if ( item_width > maxItemWidth )
maxItemWidth = item_width;
@ -489,6 +496,7 @@ void FMenu::drawItems()
FString txt;
uInt txt_length;
int hotkeypos, to_char;
int accel_key = (*iter)->accel_key;
bool is_enabled = (*iter)->isEnabled();
bool is_selected = (*iter)->isSelected();
bool is_noUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0);
@ -575,6 +583,19 @@ void FMenu::drawItems()
print (item_text[z]);
}
if ( accel_key )
{
FString accel_name (getKeyName(accel_key));
int accel_len = int(accel_name.getLength());
int len = maxItemWidth - (to_char + accel_len + 2);
if ( len > 0 )
{
FString line(len, wchar_t(' '));
print (line + accel_name);
to_char = maxItemWidth - 2;
}
}
if ( is_selected )
{
for (uInt i=uInt(to_char); i < maxItemWidth-1; i++)

View File

@ -64,7 +64,7 @@ void FMenuBar::menu_dimension()
iter = itemlist.begin();
end = itemlist.end();
// find the max item width
// find the maximum item width
while ( iter != end )
{
uInt len = (*iter)->getTextLength();

View File

@ -125,7 +125,9 @@ FMenuItem::FMenuItem (int k, const char* txt, FWidget* parent)
}
//----------------------------------------------------------------------
FMenuItem::~FMenuItem() // destructor
{ }
{
delAccelerator();
}
// private methods of FMenuItem
@ -260,6 +262,8 @@ void FMenuItem::processClicked()
void FMenuItem::addAccelerator (int key, FWidget* obj)
{
FWidget* super = super_menu;
if ( ! super )
return;
while ( super && strncmp ( super->getClassName()
, const_cast<char*>("FMenu"), 5) == 0 )
@ -275,7 +279,17 @@ void FMenuItem::addAccelerator (int key, FWidget* obj)
if ( ! window )
window = getRootWidget();
if ( window && window->accelerator_list )
{
accel_key = key;
window->accelerator_list->push_back(accel);
}
}
if ( isMenu(super_menu) )
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(super_menu);
if ( menu_ptr )
menu_ptr->menu_dimension();
}
}
@ -283,6 +297,8 @@ void FMenuItem::addAccelerator (int key, FWidget* obj)
void FMenuItem::delAccelerator (FWidget* obj)
{
FWidget* super = super_menu;
if ( ! super )
return;
while ( super && strncmp ( super->getClassName()
, const_cast<char*>("FMenu"), 5) == 0 )
@ -302,16 +318,26 @@ void FMenuItem::delAccelerator (FWidget* obj)
{
FWidget::Accelerators::iterator iter;
iter = window->accelerator_list->begin();
while ( iter != window->accelerator_list->end() )
{
if ( iter->object == obj )
{
accel_key = 0;
iter = window->accelerator_list->erase(iter);
}
else
++iter;
}
}
}
if ( isMenu(super_menu) )
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(super_menu);
if ( menu_ptr )
menu_ptr->menu_dimension();
}
}
//----------------------------------------------------------------------
@ -581,7 +607,7 @@ bool FMenuItem::setFocus (bool on)
menu_ptr->redraw();
}
}
if ( statusBar() )
{
FString msg = getStatusbarMessage();
@ -627,14 +653,14 @@ void FMenuItem::openMenu()
if ( hasMenu() )
{
submenu = getMenu();
if ( ! submenu->isVisible() )
{
open_menu = static_cast<FMenu*>(getOpenMenu());
if ( open_menu && open_menu != submenu )
open_menu->hide();
setOpenMenu(submenu);
submenu->setVisible();
submenu->show();
submenu->raiseWindow(submenu);

View File

@ -219,9 +219,9 @@ MyDialog::MyDialog (FWidget* parent)
Quit->setStatusbarMessage ("Exit the program");
// "Edit" menu items
FMenuItem* Undo = new FMenuItem ("Undo", Edit);
FMenuItem* Undo = new FMenuItem (fc::Fckey_z, "Undo", Edit);
Undo->setDisable();
FMenuItem* Redo = new FMenuItem ("Redo", Edit);
FMenuItem* Redo = new FMenuItem (fc::Fckey_y, "Redo", Edit);
Redo->setDisable();
FMenuItem* Line2 = new FMenuItem (Edit);
Line2->setSeparator();
@ -231,11 +231,11 @@ MyDialog::MyDialog (FWidget* parent)
Copy->setStatusbarMessage ("Copy the input text into the clipboad");
FMenuItem* Paste = new FMenuItem (fc::Fckey_v, "&Paste", Edit);
Paste->setStatusbarMessage ("Insert text form clipboard");
FMenuItem* Clear = new FMenuItem ("C&lear", Edit);
FMenuItem* Clear = new FMenuItem (fc::Fkey_dc, "C&lear", Edit);
Clear->setStatusbarMessage ("Delete input text");
// "View" menu items
FMenuItem* Env = new FMenuItem ("&Terminal info...", View);
FMenuItem* Env = new FMenuItem ("&Terminal...", View);
Env->setStatusbarMessage ("Informations about this terminal");
FMenuItem* Drive = new FMenuItem ("&Drive symbols...", View);
Drive->setStatusbarMessage ("Show drive symbols");