Refactoring FApplication::processMouseEvent
This commit is contained in:
parent
937cd8a0f0
commit
6d3231a498
|
@ -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
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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,44 +1751,66 @@ 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;
|
||||||
move_size_widget = 0;
|
move_size_widget = 0;
|
||||||
w->redraw();
|
w->redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FApplication::closeOpenMenu()
|
||||||
|
{
|
||||||
|
// Close the open menu
|
||||||
|
|
||||||
|
if ( ! open_menu || b_state.mouse_moved )
|
||||||
|
return;
|
||||||
|
|
||||||
// close the open menu
|
|
||||||
if ( open_menu && ! b_state.mouse_moved )
|
|
||||||
{
|
|
||||||
FMenu* menu = static_cast<FMenu*>(open_menu);
|
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();
|
||||||
|
|
||||||
|
@ -1811,14 +1833,26 @@ void FApplication::processMouseEvent()
|
||||||
|
|
||||||
updateTerminal();
|
updateTerminal();
|
||||||
flush_out();
|
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;
|
||||||
|
|
||||||
|
const FPoint& mouse_position = getMousePos();
|
||||||
|
|
||||||
// unselected menu bar item
|
|
||||||
if ( ! open_menu && getMenuBar()
|
|
||||||
&& getMenuBar()->hasSelectedItem()
|
|
||||||
&& ! b_state.mouse_moved )
|
|
||||||
{
|
|
||||||
if ( ! getMenuBar()->getTermGeometry().contains(mouse_position) )
|
if ( ! getMenuBar()->getTermGeometry().contains(mouse_position) )
|
||||||
{
|
{
|
||||||
if ( getStatusBar() )
|
if ( getStatusBar() )
|
||||||
|
@ -1837,11 +1871,16 @@ void FApplication::processMouseEvent()
|
||||||
updateTerminal();
|
updateTerminal();
|
||||||
flush_out();
|
flush_out();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FApplication::sendMouseEvent()
|
||||||
|
{
|
||||||
|
if ( ! clicked_widget )
|
||||||
|
return;
|
||||||
|
|
||||||
if ( clicked_widget )
|
|
||||||
{
|
|
||||||
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 )
|
||||||
|
@ -1857,6 +1896,23 @@ void FApplication::processMouseEvent()
|
||||||
|
|
||||||
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 )
|
||||||
{
|
{
|
||||||
FMouseEvent m_down_ev ( fc::MouseMove_Event
|
FMouseEvent m_down_ev ( fc::MouseMove_Event
|
||||||
|
@ -1883,9 +1939,13 @@ void FApplication::processMouseEvent()
|
||||||
, fc::MiddleButton | key_state );
|
, fc::MiddleButton | key_state );
|
||||||
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 )
|
||||||
{
|
{
|
||||||
FMouseEvent m_dblclick_ev ( fc::MouseDoubleClick_Event
|
FMouseEvent m_dblclick_ev ( fc::MouseDoubleClick_Event
|
||||||
|
@ -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 )
|
||||||
{
|
{
|
||||||
|
@ -1968,8 +2069,12 @@ void FApplication::processMouseEvent()
|
||||||
|
|
||||||
sendEvent (released_widget, &m_up_ev);
|
sendEvent (released_widget, &m_up_ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
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 )
|
||||||
|
|
Loading…
Reference in New Issue