Status and menu bar insert accelerator keys into root widget

This commit is contained in:
Markus Gans 2016-07-12 23:35:33 +02:00
parent fbb3c8ef11
commit 2acda53224
4 changed files with 52 additions and 46 deletions

View File

@ -1,3 +1,7 @@
2016-07-12 Markus Gans <guru.mail@muenster.de>
* 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 <guru.mail@muenster.de>
* Remove obsolete code from FDialog destructor
* FDialog focus fix

View File

@ -391,35 +391,14 @@ void FApplication::processKeyboardEvent()
&& ! k_press_ev.isAccepted()
&& ! k_down_ev.isAccepted() )
{
// keyboard accelerator
// windows keyboard accelerator
FWidget* window = static_cast<FWidget*>(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)
{

View File

@ -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();

View File

@ -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;
}