diff --git a/ChangeLog b/ChangeLog index aa8cfae7..8ceac943 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +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 + 2016-07-10 Markus Gans * Remove obsolete code from FDialog destructor * FDialog focus fix diff --git a/src/fapp.cpp b/src/fapp.cpp index 318e743a..afd436a0 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -391,35 +391,14 @@ void FApplication::processKeyboardEvent() && ! k_press_ev.isAccepted() && ! k_down_ev.isAccepted() ) { - // keyboard accelerator + // windows keyboard accelerator FWidget* window = static_cast(active_window); - if ( ! window ) - window = getRootWidget(); + if ( window ) + processAccelerator (window); - if ( window - && window->accelerator_list - && ! window->accelerator_list->empty() ) - { - FWidget::Accelerators::const_iterator iter, end; - iter = window->accelerator_list->begin(); - end = window->accelerator_list->end(); - - while ( iter != end ) - { - if ( quit_now || app_exit_loop ) - break; - - if ( iter->key == key ) - { - FAccelEvent a_ev (fc::Accelerator_Event, focus_widget); - sendEvent (iter->object, &a_ev); - break; - }; - - ++iter; - } - } + // global keyboard accelerator + processAccelerator (getRootWidget()); } } // end of else } @@ -449,6 +428,34 @@ void FApplication::processKeyboardEvent() } } +//---------------------------------------------------------------------- +void FApplication::processAccelerator (FWidget* widget) +{ + if ( widget + && widget->accelerator_list + && ! widget->accelerator_list->empty() ) + { + FWidget::Accelerators::const_iterator iter, end; + iter = widget->accelerator_list->begin(); + end = widget->accelerator_list->end(); + + while ( iter != end ) + { + if ( quit_now || app_exit_loop ) + break; + + if ( iter->key == key ) + { + FAccelEvent a_ev (fc::Accelerator_Event, focus_widget); + sendEvent (iter->object, &a_ev); + break; + }; + + ++iter; + } + } +} + //---------------------------------------------------------------------- void FApplication::getX11ButtonState (int button) { diff --git a/src/fapp.h b/src/fapp.h index ba4e83cc..12a01258 100644 --- a/src/fapp.h +++ b/src/fapp.h @@ -124,6 +124,7 @@ class FApplication : public FWidget bool KeyPressed(); ssize_t readKey(); void processKeyboardEvent(); + void processAccelerator (FWidget*); void getX11ButtonState (int); bool parseX11Mouse(); bool parseSGRMouse(); diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 000988d7..9923de72 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1160,41 +1160,35 @@ void FWidget::emitCallback (FString emit_signal) //---------------------------------------------------------------------- void FWidget::addAccelerator (int key, FWidget* obj) { - FWidget* window = FWindow::getWindowWidget(obj); + FWidget* widget = FWindow::getWindowWidget(obj); accelerator accel = { key, obj }; - if ( ! window ) - window = getRootWidget(); + if ( ! widget || widget == statusbar || widget == menubar ) + widget = getRootWidget(); - if ( window == statusbar || window == menubar ) - window = FWindow::getWindowWidget(getParentWidget()); - - if ( window && window->accelerator_list ) - window->accelerator_list->push_back(accel); + if ( widget && widget->accelerator_list ) + widget->accelerator_list->push_back(accel); } //---------------------------------------------------------------------- void FWidget::delAccelerator (FWidget* obj) { - FWidget* window = FWindow::getWindowWidget(this); + FWidget* widget = FWindow::getWindowWidget(this); - if ( ! window ) - window = getRootWidget(); + if ( ! widget || widget == statusbar || widget == menubar ) + widget = getRootWidget(); - if ( window == statusbar || window == menubar ) - window = FWindow::getWindowWidget(getParentWidget()); - - if ( window - && window->accelerator_list - && ! window->accelerator_list->empty() ) + if ( widget + && widget->accelerator_list + && ! widget->accelerator_list->empty() ) { FWidget::Accelerators::iterator iter; - iter = window->accelerator_list->begin(); + iter = widget->accelerator_list->begin(); - while ( iter != window->accelerator_list->end() ) + while ( iter != widget->accelerator_list->end() ) { if ( iter->object == obj ) - iter = window->accelerator_list->erase(iter); + iter = widget->accelerator_list->erase(iter); else ++iter; }