From 9ef3bd32435957dbd621489527e1f022921bdffc Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 14 Jul 2016 00:12:16 +0200 Subject: [PATCH] Bind accelerator key from the FMenuItem to the root widget --- ChangeLog | 3 ++ README.md | 7 ++-- doc/class-diagram.txt | 7 ++-- src/fmenuitem.cpp | 80 ++++++++++++++----------------------------- 4 files changed, 39 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ceac943..426ffa77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2016-07-13 Markus Gans + * Bind accelerator key from the FMenuItem to the root widget + 2016-07-12 Markus Gans * The status bar and the menu bar insert now the accelerator keys into the global scope of the root widget diff --git a/README.md b/README.md index 09b7c5fb..bd26e677 100644 --- a/README.md +++ b/README.md @@ -177,8 +177,11 @@ Class digramm : : │ ┌───┤ FMenuBar │ : : : ┌───────────┐ └─────┤ └──────────┘ : : : │ FMenuList │◄──────────┤ ┌───────┐ : - : : └────┬──────┘ └───┤ FMenu │ : - : : : └───────┘ : + : : └────┬──────┘ └───┤ FMenu │◄──┐ : + : : : └───────┘ │ : + : : : ┌─────────────────┐ │ : + : : : │ FDialogListMenu ├───┘ : + : : : └─────────────────┘ : : : 1: ┌────────────────┐* : : : : *┌───────────┐ ┌──┤ FCheckMenuItem ├-┐ : : : ├--┤ FMenuItem │◄─┤ └────────────────┘ : : diff --git a/doc/class-diagram.txt b/doc/class-diagram.txt index ae72215b..ac71e628 100644 --- a/doc/class-diagram.txt +++ b/doc/class-diagram.txt @@ -78,8 +78,11 @@ : : │ ┌───┤ FMenuBar │ : : : ┌───────────┐ └─────┤ └──────────┘ : : : │ FMenuList │◄──────────┤ ┌───────┐ : - : : └────┬──────┘ └───┤ FMenu │ : - : : : └───────┘ : + : : └────┬──────┘ └───┤ FMenu │◄──┐ : + : : : └───────┘ │ : + : : : ┌─────────────────┐ │ : + : : : │ FDialogListMenu ├───┘ : + : : : └─────────────────┘ : : : 1: ┌────────────────┐* : : : : *┌───────────┐ ┌──┤ FCheckMenuItem ├-┐ : : : ├--┤ FMenuItem │◄─┤ └────────────────┘ : : diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 4e22a1d0..0a6027d2 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -319,19 +319,25 @@ void FMenuItem::processClicked() //---------------------------------------------------------------------- bool FMenuItem::isWindowsMenu (FWidget* w) const { - return w->isDialog(); + return ( ! w ) ? false : w->isDialog(); } //---------------------------------------------------------------------- bool FMenuItem::isMenuBar (FWidget* w) const { - return bool( strcmp ( w->getClassName() - , const_cast("FMenuBar") ) == 0 ); + if ( ! w ) + return false; + else + return bool( strcmp ( w->getClassName() + , const_cast("FMenuBar") ) == 0 ); } //---------------------------------------------------------------------- bool FMenuItem::isMenu (FWidget* w) const { + if ( ! w ) + return false; + bool m1 = ( strcmp ( w->getClassName() , const_cast("FMenu") ) == 0 ); bool m2 = ( strcmp ( w->getClassName() @@ -344,30 +350,13 @@ bool FMenuItem::isMenu (FWidget* w) const //---------------------------------------------------------------------- void FMenuItem::addAccelerator (int key, FWidget* obj) { - FWidget* super = super_menu; + FWidget* root = getRootWidget(); + accelerator accel = { key, obj }; - if ( ! super ) - return; - - while ( super && strncmp ( super->getClassName() - , const_cast("FMenu"), 5) == 0 ) + if ( root && root->accelerator_list ) { - super = super->getParentWidget(); - } - - if ( super ) - { - FWidget* window = FWindow::getWindowWidget(super); - accelerator accel = { key, obj }; - - if ( ! window ) - window = getRootWidget(); - - if ( window && window->accelerator_list ) - { - accel_key = key; - window->accelerator_list->push_back(accel); - } + accel_key = key; + root->accelerator_list->push_back(accel); } if ( isMenu(super_menu) ) @@ -382,41 +371,24 @@ void FMenuItem::addAccelerator (int key, FWidget* obj) //---------------------------------------------------------------------- void FMenuItem::delAccelerator (FWidget* obj) { - FWidget* super = super_menu; + FWidget* root = getRootWidget(); - if ( ! super ) - return; - - while ( super && strncmp ( super->getClassName() - , const_cast("FMenu"), 5) == 0 ) + if ( root + && root->accelerator_list + && ! root->accelerator_list->empty() ) { - super = super->getParentWidget(); - } + FWidget::Accelerators::iterator iter; + iter = root->accelerator_list->begin(); - if ( super ) - { - FWidget* window = FWindow::getWindowWidget(super); - - if ( ! window ) - window = getRootWidget(); - - if ( window - && window->accelerator_list - && ! window->accelerator_list->empty() ) + while ( iter != root->accelerator_list->end() ) { - FWidget::Accelerators::iterator iter; - iter = window->accelerator_list->begin(); - - while ( iter != window->accelerator_list->end() ) + if ( iter->object == obj ) { - if ( iter->object == obj ) - { - accel_key = 0; - iter = window->accelerator_list->erase(iter); - } - else - ++iter; + accel_key = 0; + iter = root->accelerator_list->erase(iter); } + else + ++iter; } }