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,29 +1751,44 @@ void FApplication::processMouseEvent()
Event = parseUrxvtMouse(); Event = parseUrxvtMouse();
if ( ! Event ) if ( ! Event )
return; 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(); const FPoint& mouse_position = getMousePos();
if ( ! clicked_widget // Determine the window object on the current click 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
FWidget* window = FWindow::getWindowWidgetAt (mouse_position); FWidget* window = FWindow::getWindowWidgetAt (mouse_position);
if ( window ) if ( window )
{ {
// determine the widget at the current click position // Determine the widget at the current click position
FWidget* child = childWidgetAt (window, mouse_position); FWidget* child = childWidgetAt (window, mouse_position);
clicked_widget = ( child != 0 ) ? child : window; clicked_widget = ( child != 0 ) ? child : window;
} }
// unset the move/size mode return clicked_widget;
}
//----------------------------------------------------------------------
void FApplication::unsetMoveSizeMode()
{
// Unset the move/size mode
if ( move_size_widget ) if ( move_size_widget )
{ {
FWidget* w = move_size_widget; FWidget* w = move_size_widget;
@ -1782,13 +1797,20 @@ void FApplication::processMouseEvent()
} }
} }
// close the open menu //----------------------------------------------------------------------
if ( open_menu && ! b_state.mouse_moved ) void FApplication::closeOpenMenu()
{ {
FMenu* menu = static_cast<FMenu*>(open_menu); // 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;
if ( ! menu->containsMenuStructure(mouse_position) )
{
bool is_window_menu; bool is_window_menu;
FWidget* super = menu->getSuperMenu(); FWidget* super = menu->getSuperMenu();
@ -1812,13 +1834,25 @@ void FApplication::processMouseEvent()
updateTerminal(); updateTerminal();
flush_out(); flush_out();
} }
}
// unselected menu bar item //----------------------------------------------------------------------
if ( ! open_menu && getMenuBar() void FApplication::unselectMenubarItems()
&& getMenuBar()->hasSelectedItem()
&& ! b_state.mouse_moved )
{ {
// Unselect the menu bar items
if ( open_menu || b_state.mouse_moved )
return;
FMenuBar* menubar = getMenuBar();
if ( ! menubar )
return;
if ( ! menubar->hasSelectedItem() )
return;
const FPoint& mouse_position = getMousePos();
if ( ! getMenuBar()->getTermGeometry().contains(mouse_position) ) if ( ! getMenuBar()->getTermGeometry().contains(mouse_position) )
{ {
if ( getStatusBar() ) if ( getStatusBar() )
@ -1839,9 +1873,14 @@ void FApplication::processMouseEvent()
} }
} }
if ( clicked_widget ) //----------------------------------------------------------------------
void FApplication::sendMouseEvent()
{ {
if ( ! clicked_widget )
return;
FPoint widgetMousePos; FPoint widgetMousePos;
const FPoint& mouse_position = getMousePos();
int key_state = 0; int key_state = 0;
if ( b_state.shift_button == Pressed ) if ( b_state.shift_button == Pressed )
@ -1856,6 +1895,23 @@ void FApplication::processMouseEvent()
widgetMousePos = clicked_widget->termToWidgetPos(mouse_position); widgetMousePos = clicked_widget->termToWidgetPos(mouse_position);
if ( b_state.mouse_moved ) 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);
}
sendWheelEvent (widgetMousePos, mouse_position);
}
//----------------------------------------------------------------------
void FApplication::sendMouseMoveEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position
, int key_state )
{ {
if ( b_state.left_button == Pressed ) if ( b_state.left_button == Pressed )
{ {
@ -1884,7 +1940,11 @@ void FApplication::processMouseEvent()
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_down_ev);
} }
} }
else
//----------------------------------------------------------------------
void FApplication::sendMouseLeftClickEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position
, int key_state )
{ {
if ( b_state.left_button == DoubleClick ) if ( b_state.left_button == DoubleClick )
{ {
@ -1916,7 +1976,13 @@ void FApplication::processMouseEvent()
sendEvent (released_widget, &m_up_ev); sendEvent (released_widget, &m_up_ev);
} }
}
//----------------------------------------------------------------------
void FApplication::sendMouseRightClickEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position
, int key_state )
{
if ( b_state.right_button == Pressed ) if ( b_state.right_button == Pressed )
{ {
FMouseEvent m_down_ev ( fc::MouseDown_Event FMouseEvent m_down_ev ( fc::MouseDown_Event
@ -1939,6 +2005,41 @@ void FApplication::processMouseEvent()
sendEvent (released_widget, &m_up_ev); sendEvent (released_widget, &m_up_ev);
} }
}
//----------------------------------------------------------------------
void FApplication::sendMouseMiddleClickEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position
, int key_state )
{
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.middle_button == Pressed ) if ( b_state.middle_button == Pressed )
{ {
@ -1970,6 +2071,10 @@ void FApplication::processMouseEvent()
} }
} }
//----------------------------------------------------------------------
void FApplication::sendWheelEvent ( const FPoint& widgetMousePos
, const FPoint& mouse_position )
{
if ( b_state.wheel_up == Pressed ) if ( b_state.wheel_up == Pressed )
{ {
FWheelEvent wheel_ev ( fc::MouseWheel_Event FWheelEvent wheel_ev ( fc::MouseWheel_Event
@ -1991,7 +2096,19 @@ void FApplication::processMouseEvent()
clicked_widget = 0; clicked_widget = 0;
sendEvent (scroll_over_widget, &wheel_ev); sendEvent (scroll_over_widget, &wheel_ev);
} }
} // end of if ( clicked_widget ) }
//----------------------------------------------------------------------
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 )