Refactoring FApplication::processMouseEvent

This commit is contained in:
Markus Gans 2017-12-05 01:03:59 +01:00
parent 937cd8a0f0
commit 6d3231a498
3 changed files with 359 additions and 218 deletions

View File

@ -1,3 +1,6 @@
2017-12-05 Markus Gans <guru.mail@muenster.de>
* Refactoring FApplication::processMouseEvent
2017-12-02 Markus Gans <guru.mail@muenster.de> 2017-12-02 Markus Gans <guru.mail@muenster.de>
* Refactoring FListBox::drawList and FListBox::onKeyPress * Refactoring FListBox::drawList and FListBox::onKeyPress
* Refactoring FWidget::event * Refactoring FWidget::event

View File

@ -159,6 +159,7 @@ class FApplication : public FWidget
bool KeyPressed(); bool KeyPressed();
ssize_t readKey(); ssize_t readKey();
void processKeyboardEvent(); void processKeyboardEvent();
#if defined(__linux__) #if defined(__linux__)
static int linuxShiftKeyCorrection (const int&); static int linuxShiftKeyCorrection (const int&);
static int linuxCtrlKeyCorrection (const int&); static int linuxCtrlKeyCorrection (const int&);
@ -169,12 +170,32 @@ class FApplication : public FWidget
static int linuxShiftCtrlAltKeyCorrection (const int&); static int linuxShiftCtrlAltKeyCorrection (const int&);
static int linuxModifierKeyCorrection (const int&); static int linuxModifierKeyCorrection (const int&);
#endif #endif
bool processDialogSwitchAccelerator(); bool processDialogSwitchAccelerator();
bool processAccelerator (const FWidget*&); bool processAccelerator (const FWidget*&);
void getX11ButtonState (int); void getX11ButtonState (int);
bool parseX11Mouse(); bool parseX11Mouse();
bool parseSGRMouse(); bool parseSGRMouse();
bool parseUrxvtMouse(); bool parseUrxvtMouse();
bool getMouseEvent();
FWidget*& determineClickedWidget();
void unsetMoveSizeMode();
void closeOpenMenu();
void unselectMenubarItems();
void sendMouseEvent();
void sendMouseMoveEvent ( const FPoint&
, const FPoint&
, int );
void sendMouseLeftClickEvent ( const FPoint&
, const FPoint&
, int );
void sendMouseRightClickEvent ( const FPoint&
, const FPoint&
, int );
void sendMouseMiddleClickEvent ( const FPoint&
, const FPoint&
, int );
void sendWheelEvent (const FPoint&, const FPoint&);
void processMouseEvent(); void processMouseEvent();
void processResizeEvent(); void processResizeEvent();
int processTimerEvent(); int processTimerEvent();

View File

@ -1715,7 +1715,7 @@ bool FApplication::processGpmEvent()
#endif // F_HAVE_LIBGPM #endif // F_HAVE_LIBGPM
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FApplication::processMouseEvent() bool FApplication::getMouseEvent()
{ {
bool Event = false; bool Event = false;
@ -1725,14 +1725,14 @@ void FApplication::processMouseEvent()
&& sgr_mouse[0] == '\0' && sgr_mouse[0] == '\0'
&& urxvt_mouse[0] == '\0' ) && urxvt_mouse[0] == '\0' )
{ {
return; return false;
} }
#else #else
if ( x11_mouse[0] == '\0' if ( x11_mouse[0] == '\0'
&& sgr_mouse[0] == '\0' && sgr_mouse[0] == '\0'
&& urxvt_mouse[0] == '\0' ) && urxvt_mouse[0] == '\0' )
{ {
return; return false;
} }
#endif #endif
@ -1751,247 +1751,364 @@ void FApplication::processMouseEvent()
Event = parseUrxvtMouse(); Event = parseUrxvtMouse();
if ( ! Event ) if ( ! Event )
return false;
return true;
}
//----------------------------------------------------------------------
FWidget*& FApplication::determineClickedWidget()
{
if ( clicked_widget )
return clicked_widget;
if ( b_state.left_button != Pressed
&& b_state.left_button != DoubleClick
&& b_state.right_button != Pressed
&& b_state.middle_button != Pressed
&& b_state.wheel_up != Pressed
&& b_state.wheel_down != Pressed )
return clicked_widget;
const FPoint& mouse_position = getMousePos();
// Determine the window object on the current click position
FWidget* window = FWindow::getWindowWidgetAt (mouse_position);
if ( window )
{
// Determine the widget at the current click position
FWidget* child = childWidgetAt (window, mouse_position);
clicked_widget = ( child != 0 ) ? child : window;
}
return clicked_widget;
}
//----------------------------------------------------------------------
void FApplication::unsetMoveSizeMode()
{
// Unset the move/size mode
if ( move_size_widget )
{
FWidget* w = move_size_widget;
move_size_widget = 0;
w->redraw();
}
}
//----------------------------------------------------------------------
void FApplication::closeOpenMenu()
{
// Close the open menu
if ( ! open_menu || b_state.mouse_moved )
return;
FMenu* menu = static_cast<FMenu*>(open_menu);
const FPoint& mouse_position = getMousePos();
if ( menu && menu->containsMenuStructure(mouse_position) )
return;
bool is_window_menu;
FWidget* super = menu->getSuperMenu();
if ( super && menu->isWindowsMenu(super) )
is_window_menu = true;
else
is_window_menu = false;
menu->unselectItem();
menu->hide();
menu->hideSubMenus();
menu->hideSuperMenus();
// No widget was been clicked and the menu is no dialog menu
if ( ! (clicked_widget || is_window_menu) )
FWindow::switchToPrevWindow();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
//----------------------------------------------------------------------
void FApplication::unselectMenubarItems()
{
// Unselect the menu bar items
if ( open_menu || b_state.mouse_moved )
return;
FMenuBar* menubar = getMenuBar();
if ( ! menubar )
return;
if ( ! menubar->hasSelectedItem() )
return; return;
const FPoint& mouse_position = getMousePos(); const FPoint& mouse_position = getMousePos();
if ( ! clicked_widget if ( ! getMenuBar()->getTermGeometry().contains(mouse_position) )
&& ( b_state.left_button == Pressed
|| b_state.left_button == DoubleClick
|| b_state.right_button == Pressed
|| b_state.middle_button == Pressed
|| b_state.wheel_up == Pressed
|| b_state.wheel_down == Pressed ) )
{ {
// determine the window object on the current click position if ( getStatusBar() )
FWidget* window = FWindow::getWindowWidgetAt (mouse_position); getStatusBar()->clearMessage();
if ( window ) getMenuBar()->resetMenu();
{ getMenuBar()->redraw();
// determine the widget at the current click position
FWidget* child = childWidgetAt (window, mouse_position);
clicked_widget = ( child != 0 ) ? child : window;
}
// unset the move/size mode // No widget was been clicked
if ( move_size_widget ) if ( ! clicked_widget )
{ FWindow::switchToPrevWindow();
FWidget* w = move_size_widget;
move_size_widget = 0; if ( getStatusBar() )
w->redraw(); getStatusBar()->drawMessage();
}
updateTerminal();
flush_out();
}
}
//----------------------------------------------------------------------
void FApplication::sendMouseEvent()
{
if ( ! clicked_widget )
return;
FPoint widgetMousePos;
const FPoint& mouse_position = getMousePos();
int key_state = 0;
if ( b_state.shift_button == Pressed )
key_state |= fc::ShiftButton;
if ( b_state.meta_button == Pressed )
key_state |= fc::MetaButton;
if ( b_state.control_button == Pressed )
key_state |= fc::ControlButton;
widgetMousePos = clicked_widget->termToWidgetPos(mouse_position);
if ( b_state.mouse_moved )
{
sendMouseMoveEvent (widgetMousePos, mouse_position, key_state);
}
else
{
sendMouseLeftClickEvent (widgetMousePos, mouse_position, key_state);
sendMouseRightClickEvent (widgetMousePos, mouse_position, key_state);
sendMouseMiddleClickEvent (widgetMousePos, mouse_position, key_state);
} }
// close the open menu sendWheelEvent (widgetMousePos, mouse_position);
if ( open_menu && ! b_state.mouse_moved ) }
//----------------------------------------------------------------------
void FApplication::sendMouseMoveEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position
, int key_state )
{
if ( b_state.left_button == Pressed )
{ {
FMenu* menu = static_cast<FMenu*>(open_menu); FMouseEvent m_down_ev ( fc::MouseMove_Event
, widgetMousePos
if ( ! menu->containsMenuStructure(mouse_position) ) , mouse_position
{ , fc::LeftButton | key_state );
bool is_window_menu; sendEvent (clicked_widget, &m_down_ev);
FWidget* super = menu->getSuperMenu();
if ( super && menu->isWindowsMenu(super) )
is_window_menu = true;
else
is_window_menu = false;
menu->unselectItem();
menu->hide();
menu->hideSubMenus();
menu->hideSuperMenus();
// No widget was been clicked and the menu is no dialog menu
if ( ! (clicked_widget || is_window_menu) )
FWindow::switchToPrevWindow();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
} }
// unselected menu bar item if ( b_state.right_button == Pressed )
if ( ! open_menu && getMenuBar()
&& getMenuBar()->hasSelectedItem()
&& ! b_state.mouse_moved )
{ {
if ( ! getMenuBar()->getTermGeometry().contains(mouse_position) ) FMouseEvent m_down_ev ( fc::MouseMove_Event
{ , widgetMousePos
if ( getStatusBar() ) , mouse_position
getStatusBar()->clearMessage(); , fc::RightButton | key_state );
sendEvent (clicked_widget, &m_down_ev);
getMenuBar()->resetMenu();
getMenuBar()->redraw();
// No widget was been clicked
if ( ! clicked_widget )
FWindow::switchToPrevWindow();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
} }
if ( clicked_widget ) if ( b_state.middle_button == Pressed )
{ {
FPoint widgetMousePos; FMouseEvent m_down_ev ( fc::MouseMove_Event
int key_state = 0; , widgetMousePos
, mouse_position
, fc::MiddleButton | key_state );
sendEvent (clicked_widget, &m_down_ev);
}
}
if ( b_state.shift_button == Pressed ) //----------------------------------------------------------------------
key_state |= fc::ShiftButton; void FApplication::sendMouseLeftClickEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position
if ( b_state.meta_button == Pressed ) , int key_state )
key_state |= fc::MetaButton; {
if ( b_state.left_button == DoubleClick )
if ( b_state.control_button == Pressed ) {
key_state |= fc::ControlButton; FMouseEvent m_dblclick_ev ( fc::MouseDoubleClick_Event
widgetMousePos = clicked_widget->termToWidgetPos(mouse_position);
if ( b_state.mouse_moved )
{
if ( b_state.left_button == Pressed )
{
FMouseEvent m_down_ev ( fc::MouseMove_Event
, widgetMousePos , widgetMousePos
, mouse_position , mouse_position
, fc::LeftButton | key_state ); , fc::LeftButton | key_state );
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_dblclick_ev);
} }
else if ( b_state.left_button == Pressed )
{
FMouseEvent m_down_ev ( fc::MouseDown_Event
, widgetMousePos
, mouse_position
, fc::LeftButton | key_state );
sendEvent (clicked_widget, &m_down_ev);
}
else if ( b_state.left_button == Released )
{
FMouseEvent m_up_ev ( fc::MouseUp_Event
, widgetMousePos
, mouse_position
, fc::LeftButton | key_state );
FWidget* released_widget = clicked_widget;
if ( b_state.right_button == Pressed ) if ( b_state.right_button != Pressed
{ && b_state.middle_button != Pressed )
FMouseEvent m_down_ev ( fc::MouseMove_Event clicked_widget = 0;
, widgetMousePos
, mouse_position sendEvent (released_widget, &m_up_ev);
, fc::RightButton | key_state ); }
sendEvent (clicked_widget, &m_down_ev); }
}
//----------------------------------------------------------------------
if ( b_state.middle_button == Pressed ) void FApplication::sendMouseRightClickEvent ( const FPoint& widgetMousePos
{ , const FPoint& mouse_position
FMouseEvent m_down_ev ( fc::MouseMove_Event , int key_state )
, widgetMousePos {
, mouse_position if ( b_state.right_button == Pressed )
, fc::MiddleButton | key_state ); {
sendEvent (clicked_widget, &m_down_ev); FMouseEvent m_down_ev ( fc::MouseDown_Event
} , widgetMousePos
} , mouse_position
else , fc::RightButton | key_state );
{ sendEvent (clicked_widget, &m_down_ev);
if ( b_state.left_button == DoubleClick ) }
{ else if ( b_state.right_button == Released )
FMouseEvent m_dblclick_ev ( fc::MouseDoubleClick_Event {
, widgetMousePos FMouseEvent m_up_ev ( fc::MouseUp_Event
, mouse_position , widgetMousePos
, fc::LeftButton | key_state ); , mouse_position
sendEvent (clicked_widget, &m_dblclick_ev); , fc::RightButton | key_state );
} FWidget* released_widget = clicked_widget;
else if ( b_state.left_button == Pressed )
{ if ( b_state.left_button != Pressed
FMouseEvent m_down_ev ( fc::MouseDown_Event && b_state.middle_button != Pressed )
, widgetMousePos clicked_widget = 0;
, mouse_position
, fc::LeftButton | key_state ); sendEvent (released_widget, &m_up_ev);
sendEvent (clicked_widget, &m_down_ev); }
} }
else if ( b_state.left_button == Released )
{ //----------------------------------------------------------------------
FMouseEvent m_up_ev ( fc::MouseUp_Event void FApplication::sendMouseMiddleClickEvent ( const FPoint& widgetMousePos
, widgetMousePos , const FPoint& mouse_position
, mouse_position , int key_state )
, fc::LeftButton | key_state ); {
FWidget* released_widget = clicked_widget; if ( b_state.middle_button == Pressed )
{
if ( b_state.right_button != Pressed FMouseEvent m_down_ev ( fc::MouseDown_Event
&& b_state.middle_button != Pressed ) , widgetMousePos
clicked_widget = 0; , mouse_position
, fc::MiddleButton | key_state );
sendEvent (released_widget, &m_up_ev); sendEvent (clicked_widget, &m_down_ev);
}
// gnome-terminal sends no released on middle click
if ( b_state.right_button == Pressed ) if ( isGnomeTerminal() )
{ clicked_widget = 0;
FMouseEvent m_down_ev ( fc::MouseDown_Event }
, widgetMousePos else if ( b_state.middle_button == Released )
, mouse_position {
, fc::RightButton | key_state ); FMouseEvent m_up_ev ( fc::MouseUp_Event
sendEvent (clicked_widget, &m_down_ev); , widgetMousePos
} , mouse_position
else if ( b_state.right_button == Released ) , fc::MiddleButton | key_state );
{ FWidget* released_widget = clicked_widget;
FMouseEvent m_up_ev ( fc::MouseUp_Event
, widgetMousePos if ( b_state.right_button != Pressed
, mouse_position && b_state.left_button != Pressed )
, fc::RightButton | key_state ); {
FWidget* released_widget = clicked_widget;
if ( b_state.left_button != Pressed
&& b_state.middle_button != Pressed )
clicked_widget = 0;
sendEvent (released_widget, &m_up_ev);
}
if ( b_state.middle_button == Pressed )
{
FMouseEvent m_down_ev ( fc::MouseDown_Event
, widgetMousePos
, mouse_position
, fc::MiddleButton | key_state );
sendEvent (clicked_widget, &m_down_ev);
// gnome-terminal sends no released on middle click
if ( isGnomeTerminal() )
clicked_widget = 0;
}
else if ( b_state.middle_button == Released )
{
FMouseEvent m_up_ev ( fc::MouseUp_Event
, widgetMousePos
, mouse_position
, fc::MiddleButton | key_state );
FWidget* released_widget = clicked_widget;
if ( b_state.right_button != Pressed
&& b_state.left_button != Pressed )
{
clicked_widget = 0;
}
sendEvent (released_widget, &m_up_ev);
}
}
if ( b_state.wheel_up == Pressed )
{
FWheelEvent wheel_ev ( fc::MouseWheel_Event
, widgetMousePos
, mouse_position
, fc::WheelUp );
FWidget* scroll_over_widget = clicked_widget;
clicked_widget = 0; clicked_widget = 0;
sendEvent(scroll_over_widget, &wheel_ev);
} }
if ( b_state.wheel_down == Pressed ) sendEvent (released_widget, &m_up_ev);
{ }
FWheelEvent wheel_ev ( fc::MouseWheel_Event
, widgetMousePos if ( b_state.middle_button == Pressed )
, mouse_position {
, fc::WheelDown ); FMouseEvent m_down_ev ( fc::MouseDown_Event
FWidget* scroll_over_widget = clicked_widget; , widgetMousePos
, mouse_position
, fc::MiddleButton | key_state );
sendEvent (clicked_widget, &m_down_ev);
// gnome-terminal sends no released on middle click
if ( isGnomeTerminal() )
clicked_widget = 0;
}
else if ( b_state.middle_button == Released )
{
FMouseEvent m_up_ev ( fc::MouseUp_Event
, widgetMousePos
, mouse_position
, fc::MiddleButton | key_state );
FWidget* released_widget = clicked_widget;
if ( b_state.right_button != Pressed
&& b_state.left_button != Pressed )
{
clicked_widget = 0; clicked_widget = 0;
sendEvent (scroll_over_widget, &wheel_ev);
} }
} // end of if ( clicked_widget )
sendEvent (released_widget, &m_up_ev);
}
}
//----------------------------------------------------------------------
void FApplication::sendWheelEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position )
{
if ( b_state.wheel_up == Pressed )
{
FWheelEvent wheel_ev ( fc::MouseWheel_Event
, widgetMousePos
, mouse_position
, fc::WheelUp );
FWidget* scroll_over_widget = clicked_widget;
clicked_widget = 0;
sendEvent(scroll_over_widget, &wheel_ev);
}
if ( b_state.wheel_down == Pressed )
{
FWheelEvent wheel_ev ( fc::MouseWheel_Event
, widgetMousePos
, mouse_position
, fc::WheelDown );
FWidget* scroll_over_widget = clicked_widget;
clicked_widget = 0;
sendEvent (scroll_over_widget, &wheel_ev);
}
}
//----------------------------------------------------------------------
void FApplication::processMouseEvent()
{
if ( ! getMouseEvent() )
return;
determineClickedWidget();
unsetMoveSizeMode();
closeOpenMenu();
unselectMenubarItems();
sendMouseEvent();
#ifdef F_HAVE_LIBGPM #ifdef F_HAVE_LIBGPM
if ( isGpmMouseEnabled() && gpm_ev.x != -1 ) if ( isGpmMouseEnabled() && gpm_ev.x != -1 )