diff --git a/graphics/twm4nx/src/cresize.cxx b/graphics/twm4nx/src/cresize.cxx index 1b0143516..47bcbddfd 100644 --- a/graphics/twm4nx/src/cresize.cxx +++ b/graphics/twm4nx/src/cresize.cxx @@ -167,28 +167,6 @@ bool CResize::initialize(void) return true; } -void CResize::resizeFromCenter(FAR CWindow *cwin) -{ - // Get the current frame size and position - - struct nxgl_point_s winpos; - if (!cwin->getFramePosition(&winpos)) - { - return; - } - - struct nxgl_size_s winsize; - if (!cwin->getFrameSize(&winsize)) - { - return; - } - - FAR CResize *resize = m_twm4nx->getResize(); - resize->addingSize(&winsize); - - resize->menuStartResize(cwin, &winpos, &winsize); -} - /** * Begin a window resize operation * @@ -212,8 +190,6 @@ void CResize::startResize(FAR struct SEventMsg *eventmsg, FAR CWindow *cwin) return; } - m_dragpos.x += 0; - m_dragpos.y += 0; m_origpos.x = m_dragpos.x; m_origpos.y = m_dragpos.y; m_origsize.w = m_dragsize.w; @@ -257,88 +233,6 @@ void CResize::startResize(FAR struct SEventMsg *eventmsg, FAR CWindow *cwin) } } -void CResize::menuStartResize(FAR CWindow *cwin, - FAR struct nxgl_point_s *pos, - FAR struct nxgl_size_s *size) -{ - m_dragpos.x = pos->x; - m_dragpos.y = pos->y; - m_origpos.x = m_dragpos.x; - m_origpos.y = m_dragpos.y; - m_origsize.w = size->w; - m_origsize.h = size->h; - m_dragsize.w = size->w; - m_dragsize.h = size->h; - m_clamp.pt1.x = 0; - m_clamp.pt1.y = 0; - m_clamp.pt2.x = 0; - m_clamp.pt2.y = 0; - m_delta.x = 0; - m_delta.y = 0; - m_last.w = 0; - m_last.h = 0; - - FAR CFonts *fonts = m_twm4nx->getFonts(); - FAR NXWidgets::CNxFont *sizeFont = fonts->getSizeFont(); - - // Set the window size - - struct nxgl_size_s winsize; - winsize.w = m_stringWidth + CONFIG_TWM4NX_ICONMGR_HSPACING * 2; - winsize.h = sizeFont->getHeight() + CONFIG_TWM4NX_ICONMGR_VSPACING * 2; - - if (!setWindowSize(&winsize)) - { - twmerr("ERROR: setWindowSize() failed\n"); - return; - } - - // Move the size window it to the top of the hieararchy - - m_sizeWindow->raise(); - updateSizeLabel(cwin, &m_origsize); - - // Set the new frame position and size - - if (!cwin->resizeFrame(&m_dragsize, &m_dragpos)) - { - twmerr("ERROR: Failed to resize frame\n"); - } -} - -/** - * Begin a window resize operation - * - * @param cwin the Twm4Nx window pointer - */ - -void CResize::addStartResize(FAR CWindow *cwin, - FAR struct nxgl_point_s *pos, - FAR struct nxgl_size_s *size) -{ - m_dragpos.x = pos->x; - m_dragpos.y = pos->y; - m_origpos.x = m_dragpos.x; - m_origpos.y = m_dragpos.y; - m_origsize.w = size->w; - m_origsize.h = size->h; - m_dragsize.w = m_origsize.w; - m_dragsize.h = m_origsize.h; - - m_clamp.pt1.x = 0; - m_clamp.pt1.y = 0; - m_clamp.pt2.x = 0; - m_clamp.pt2.y = 0; - m_delta.x = 0; - m_delta.y = 0; - m_last.w = 0; - m_last.h = 0; - - m_last.w = 0; - m_last.h = 0; - updateSizeLabel(cwin, &m_origsize); -} - /** * @param cwin The current Twm4Nx window * @param root The X position in the root window @@ -908,7 +802,7 @@ bool CResize::event(FAR struct SEventMsg *eventmsg) eventmsg->context == EVENT_CONTEXT_WINDOW || eventmsg->context == EVENT_CONTEXT_TOOLBAR) { - resizeFromCenter(cwin); + menuStartResize(cwin); } else { @@ -1105,6 +999,66 @@ bool CResize::setWindowSize(FAR struct nxgl_size_s *size) return true; } +void CResize::menuStartResize(FAR CWindow *cwin) +{ + // Get the current frame size and position + + struct nxgl_point_s windowPos; + if (!cwin->getFramePosition(&windowPos)) + { + return; + } + + struct nxgl_size_s windowSize; + if (!cwin->getFrameSize(&windowSize)) + { + return; + } + + m_dragpos.x = windowPos.x; + m_dragpos.y = windowPos.y; + m_origpos.x = windowPos.x; + m_origpos.y = windowPos.y; + m_origsize.w = windowSize.w; + m_origsize.h = windowSize.h; + m_dragsize.w = windowSize.w; + m_dragsize.h = windowSize.h; + m_clamp.pt1.x = 0; + m_clamp.pt1.y = 0; + m_clamp.pt2.x = 0; + m_clamp.pt2.y = 0; + m_delta.x = 0; + m_delta.y = 0; + m_last.w = 0; + m_last.h = 0; + + FAR CFonts *fonts = m_twm4nx->getFonts(); + FAR NXWidgets::CNxFont *sizeFont = fonts->getSizeFont(); + + // Set the window size + + windowSize.w = m_stringWidth + CONFIG_TWM4NX_ICONMGR_HSPACING * 2; + windowSize.h = sizeFont->getHeight() + CONFIG_TWM4NX_ICONMGR_VSPACING * 2; + + if (!setWindowSize(&windowSize)) + { + twmerr("ERROR: setWindowSize() failed\n"); + return; + } + + // Move the size window it to the top of the hieararchy + + m_sizeWindow->raise(); + updateSizeLabel(cwin, &m_origsize); + + // Set the new frame position and size + + if (!cwin->resizeFrame(&m_dragsize, &m_dragpos)) + { + twmerr("ERROR: Failed to resize frame\n"); + } +} + /** * Update the size show in the size dimension label. * diff --git a/graphics/twm4nx/src/cwindow.cxx b/graphics/twm4nx/src/cwindow.cxx index 92da6355d..c972871b3 100644 --- a/graphics/twm4nx/src/cwindow.cxx +++ b/graphics/twm4nx/src/cwindow.cxx @@ -796,7 +796,7 @@ bool CWindow::createMainWindow(FAR const nxgl_size_s *winsize, // handler m_windowEvent = new CWindowEvent(m_twm4nx, this, m_appEvents); - m_windowEvent->registerDragEventHandler(this, (uintptr_t)1); + m_windowEvent->installEventTap(this, (uintptr_t)1); // 4. Create the window. Handling provided flags. NOTE: that menu windows // are always created hidden and in the iconified state (although they @@ -901,7 +901,7 @@ bool CWindow::createToolbar(void) events.closeEvent = EVENT_SYSTEM_NOP; FAR CWindowEvent *control = new CWindowEvent(m_twm4nx, this, events); - control->registerDragEventHandler(this, (uintptr_t)0); + control->installEventTap(this, (uintptr_t)0); // 3. Get the toolbar sub-window from the framed window @@ -1443,7 +1443,7 @@ void CWindow::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) * This function is called when there is any moved of the mouse or * touch position that would indicate that the object is being moved. * - * This function overrides the virtual IDragEvent::dragEvent method. + * This function overrides the virtual IEventTap::moveEvent method. * * @param pos The current mouse/touch X/Y position in toolbar relative * coordinates. @@ -1452,7 +1452,7 @@ void CWindow::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) * a drag event in progress */ -bool CWindow::dragEvent(FAR const struct nxgl_point_s &pos, +bool CWindow::moveEvent(FAR const struct nxgl_point_s &pos, uintptr_t arg) { twminfo("m_dragging=%u pos=(%d,%d)\n", m_dragging, pos.x, pos.y); @@ -1503,7 +1503,7 @@ bool CWindow::dragEvent(FAR const struct nxgl_point_s &pos, * if the touchscrreen touch is lost. This indicates that the * dragging sequence is complete. * - * This function overrides the virtual IDragEvent::dropEvent method. + * This function overrides the virtual IEventTap::dropEvent method. * * @param pos The last mouse/touch X/Y position in toolbar relative * coordinates. @@ -1548,7 +1548,7 @@ bool CWindow::dropEvent(FAR const struct nxgl_point_s &pos, * @return True: If the dragging is enabled. */ -bool CWindow::isDragging(uintptr_t arg) +bool CWindow::isActive(uintptr_t arg) { return m_clicked; } @@ -1560,7 +1560,7 @@ bool CWindow::isDragging(uintptr_t arg) * @param arg The user-argument provided that accompanies the callback */ -void CWindow::setDragging(bool enable, uintptr_t arg) +void CWindow::enableMovement(bool enable, uintptr_t arg) { m_clicked = enable; } diff --git a/graphics/twm4nx/src/cwindowevent.cxx b/graphics/twm4nx/src/cwindowevent.cxx index f857cc7df..96c3de113 100644 --- a/graphics/twm4nx/src/cwindowevent.cxx +++ b/graphics/twm4nx/src/cwindowevent.cxx @@ -120,8 +120,8 @@ CWindowEvent::CWindowEvent(FAR CTwm4Nx *twm4nx, FAR CWindow *client, // Dragging - m_dragHandler = (FAR IDragEvent *)0; // No drag handler callbacks - m_dragArg = (uintptr_t)0; // No callback argument + m_tapHandler = (FAR IEventTap *)0; // No event tap handler callbacks + m_tapArg = (uintptr_t)0; // No callback argument // Open a message queue to send raw NX events. This cannot fail! @@ -205,8 +205,8 @@ void CWindowEvent::handleRedrawEvent(FAR const nxgl_rect_s *nxRect, * toolbar, but can easily move into the main window (or even outside * of the window!). To these case, there may be two instances of * CWindowEvent, one for the toolbar and one for the main window. The - * IDragEvent implementation (along with the user arguement) can keep a - * consistent drag context across both instances. + * IEventTap implementation (along with the user arguement) can keep a + * consistent movement context across both instances. * * NOTE: NX will continually forward the mouse events to the same raw * window in all cases.. even when the mouse position moves outside of @@ -217,75 +217,75 @@ void CWindowEvent::handleRedrawEvent(FAR const nxgl_rect_s *nxRect, void CWindowEvent::handleMouseEvent(FAR const struct nxgl_point_s *pos, uint8_t buttons) { - // Check if dragging can be supported + // Check if There is an active tap on mouse events - if (m_dragHandler != (FAR IDragEvent *)0) + if (m_tapHandler != (FAR IEventTap *)0) { - twminfo("Mouse input: dragging=%u\n", - m_dragHandler->isDragging(m_dragArg)); + twminfo("Mouse input: active=%u\n", + m_tapHandler->isActive(m_tapArg)); // STATE LEFT BUTTON ACTION - // dragging clicked dragEvent - // dragging released dropEvent - // NOT dragging clicked May be detected as a grab - // NOT dragging released None + // active clicked moveEvent + // active released dropEvent + // NOT active clicked May be detected as a grab + // NOT active released None - if (m_dragHandler->isDragging(m_dragArg)) + if (m_tapHandler->isActive(m_tapArg)) { - // The new drag position in window relative display coordinates + // The new movement position in window relative display coordinates - struct nxgl_point_s dragPos; - dragPos.x = pos->x; - dragPos.y = pos->y; + struct nxgl_point_s movePos; + movePos.x = pos->x; + movePos.y = pos->y; // Is the left button still pressed? if ((buttons & MOUSE_BUTTON_1) != 0) { - twminfo("Continue dragging (%d,%d) buttons=%02x m_dragHandler=%p\n", - dragPos.x, dragPos.y, buttons, m_dragHandler); + twminfo("Continue movemenht (%d,%d) buttons=%02x m_tapHandler=%p\n", + movePos.x, movePos.y, buttons, m_tapHandler); - // Yes.. generate a drag event if we have a drag event handler + // Yes.. generate a movment event if we have a tap event handler - if (m_dragHandler->dragEvent(dragPos, m_dragArg)) + if (m_tapHandler->moveEvent(movePos, m_tapArg)) { - // Skip the input poll until the drag completes + // Skip the input poll until the movment completes return; } } else { - twminfo("Stop dragging (%d,%d) buttons=%02x m_dragHandler=%p\n", - dragPos.x, dragPos.y, buttons, m_dragHandler); + twminfo("Stop movement (%d,%d) buttons=%02x m_tapHandler=%p\n", + movePos.x, movePos.y, buttons, m_tapHandler); - // No.. then we are no longer dragging + // No.. then the tap is no longer active - m_dragHandler->setDragging(false, m_dragArg); + m_tapHandler->enableMovement(false, m_tapArg); // Generate a dropEvent - if (m_dragHandler->dropEvent(dragPos, m_dragArg)) + if (m_tapHandler->dropEvent(movePos, m_tapArg)) { // If the drop event was processed then skip the - // input poll until AFTER the drag completes + // input poll until AFTER the movement completes return; } } } - // If we are not currently dragging but the left button is pressed, then - // start the drag event + // If we are not currently moving anything but the left button is + // pressed, then start a movement event else if ((buttons & MOUSE_BUTTON_1) != 0) { - // Indicate that we are (or may be) dragging + // Indicate that we are (or may be) moving - m_dragHandler->setDragging(true, m_dragArg); + m_tapHandler->enableMovement(true, m_tapArg); - twminfo("Start dragging (%d,%d) buttons=%02x m_dragHandler=%p\n", - pos->x, pos->y, buttons, m_dragHandler); + twminfo("Start moving (%d,%d) buttons=%02x m_tapHandler=%p\n", + pos->x, pos->y, buttons, m_tapHandler); // But take no other actions until the window recognizes the grab } diff --git a/include/graphics/twm4nx/cresize.hxx b/include/graphics/twm4nx/cresize.hxx index 97d91c884..9b6de0cd8 100644 --- a/include/graphics/twm4nx/cresize.hxx +++ b/include/graphics/twm4nx/cresize.hxx @@ -85,8 +85,6 @@ namespace Twm4Nx struct nxgl_rect_s m_clamp; struct nxgl_point_s m_delta; struct nxgl_size_s m_last; - struct nxgl_point_s m_addingPos; - struct nxgl_size_s m_addingSize; int m_stringWidth; /**< Size of current size string */ /** @@ -107,8 +105,6 @@ namespace Twm4Nx bool setWindowSize(FAR struct nxgl_size_s *size); - void resizeFromCenter(FAR CWindow *win); - /** * Begin a window resize operation * @param ev the event structure (button press) @@ -116,10 +112,7 @@ namespace Twm4Nx */ void startResize(FAR struct SEventMsg *eventmsg, FAR CWindow *cwin); - - void menuStartResize(FAR CWindow *cwin, - FAR struct nxgl_point_s *pos, - FAR struct nxgl_size_s *size); + void menuStartResize(FAR CWindow *cwin); /** * Update the size show in the size dimension label. @@ -155,16 +148,6 @@ namespace Twm4Nx bool initialize(void); - /** - * What is this? - */ - - void addingSize(FAR struct nxgl_size_s *size) - { - m_addingSize.w = size->w; - m_addingSize.h = size->h; - } - /** * Begin a window resize operation * diff --git a/include/graphics/twm4nx/cwindow.hxx b/include/graphics/twm4nx/cwindow.hxx index c45ef1e42..67cec8df9 100644 --- a/include/graphics/twm4nx/cwindow.hxx +++ b/include/graphics/twm4nx/cwindow.hxx @@ -134,7 +134,7 @@ namespace Twm4Nx // containing the standard buttons and the window title. class CWindow : protected NXWidgets::CWidgetEventHandler, - protected IDragEvent, + protected IEventTap, public CTwm4NxEvent { private: @@ -290,55 +290,55 @@ namespace Twm4Nx void handleActionEvent(const NXWidgets::CWidgetEventArgs &e); /** - * This function is called when there is any moved of the mouse or + * This function is called when there is any movement of the mouse or * touch position that would indicate that the object is being moved. * - * This function overrides the virtual IDragEvent::dragEvent method. + * This function overrides the virtual IEventTap::moveEvent method. * * @param pos The current mouse/touch X/Y position. * @param arg The user-argument provided that accompanies the callback - * @return True: if the drage event was processed; false it is was + * @return True: if the movement event was processed; false it is was * ignored. The event should be ignored if there is not actually - * a drag event in progress + * a movement event in progress */ - bool dragEvent(FAR const struct nxgl_point_s &pos, + bool moveEvent(FAR const struct nxgl_point_s &pos, uintptr_t arg); /** * This function is called if the mouse left button is released or * if the touchscrreen touch is lost. This indicates that the - * dragging sequence is complete. + * movement sequence is complete. * - * This function overrides the virtual IDragEvent::dropEvent method. + * This function overrides the virtual IEventTap::dropEvent method. * * @param pos The last mouse/touch X/Y position. * @param arg The user-argument provided that accompanies the callback - * @return True: if the drage event was processed; false it is was + * @return True: if the drop event was processed; false it is was * ignored. The event should be ignored if there is not actually - * a drag event in progress + * a movement event in progress */ bool dropEvent(FAR const struct nxgl_point_s &pos, uintptr_t arg); /** - * Is dragging enabled? + * Is the tap enabled? * * @param arg The user-argument provided that accompanies the callback - * @return True: If the dragging is enabled. + * @return True: If the the tap is enabled. */ - bool isDragging(uintptr_t arg); + bool isActive(uintptr_t arg); /** - * Enable/disable dragging + * Enable/disable the tap * - * @param enable. True: Enable dragging + * @param enable. True: Enable the tap * @param arg The user-argument provided that accompanies the callback */ - void setDragging(bool enable, uintptr_t arg); + void enableMovement(bool enable, uintptr_t arg); /** * Handle the TOOLBAR_GRAB event. That corresponds to a left diff --git a/include/graphics/twm4nx/cwindowevent.hxx b/include/graphics/twm4nx/cwindowevent.hxx index 129564998..87efdc0b6 100644 --- a/include/graphics/twm4nx/cwindowevent.hxx +++ b/include/graphics/twm4nx/cwindowevent.hxx @@ -74,11 +74,11 @@ namespace Twm4Nx }; /** - * This abstract base class provides add on methods to support dragging + * This abstract base class provides add on methods to support movement * of a window. */ - class IDragEvent + class IEventTap { public: /** @@ -88,58 +88,58 @@ namespace Twm4Nx * one. */ - virtual ~IDragEvent(void) + virtual ~IEventTap(void) { } /** - * This function is called when there is any moved of the mouse or + * This function is called when there is any movement of the mouse or * touch position that would indicate that the object is being moved. * * @param pos The current mouse/touch X/Y position in toolbar relative * coordinates. * @param arg The user-argument provided that accompanies the callback - * @return True: if the drag event was processed; false it is was + * @return True: if the movement event was processed; false it is was * ignored. The event should be ignored if there is not actually - * a drag event in progress + * a movement event in progress */ - virtual bool dragEvent(FAR const struct nxgl_point_s &pos, + virtual bool moveEvent(FAR const struct nxgl_point_s &pos, uintptr_t arg) = 0; /** * This function is called if the mouse left button is released or - * if the touchscrreen touch is lost. This indicates that the - * dragging sequence is complete. + * if the touchscreen touch is lost. This indicates that the + * movement sequence is complete. * * @param pos The last mouse/touch X/Y position in toolbar relative * coordinates. * @param arg The user-argument provided that accompanies the callback - * @return True: If the drag event was processed; false it is was + * @return True: If the movement event was processed; false it is was * ignored. The event should be ignored if there is not actually - * a drag event in progress + * a movement event in progress */ virtual bool dropEvent(FAR const struct nxgl_point_s &pos, uintptr_t arg) = 0; /** - * Is dragging enabled? + * Is the tap active? * * @param arg The user-argument provided that accompanies the callback - * @return True: If the dragging is enabled. + * @return True: If the tap is enabled. */ - virtual bool isDragging(uintptr_t arg) = 0; + virtual bool isActive(uintptr_t arg) = 0; /** - * Enable/disable dragging + * Enable/disable movement * - * @param enable. True: Enable dragging + * @param enable. True: Enable movement * @param arg The user-argument provided that accompanies the callback */ - virtual void setDragging(bool enable, uintptr_t arg) = 0; + virtual void enableMovement(bool enable, uintptr_t arg) = 0; }; /** @@ -162,8 +162,8 @@ namespace Twm4Nx // Dragging - FAR IDragEvent *m_dragHandler; /**< Drag event handlers (may be NULL) */ - uintptr_t m_dragArg; /**< User argument associated with callback */ + FAR IEventTap *m_tapHandler; /**< Event tap handlers (may be NULL) */ + uintptr_t m_tapArg; /**< User argument associated with callback */ // Override CWidgetEventHandler virtual methods /////////////////////// @@ -226,20 +226,35 @@ namespace Twm4Nx ~CWindowEvent(void); /** - * Register an IDragEvent instance to provide callbacks when mouse + * Register an IEventTap instance to provide callbacks when mouse * movement is received. A mouse movement with the left button down * or a touchscreen touch movement are treated as a drag event. * Release of the mouse left button or loss of the touchscreen touch * is treated as a drop event. * - * @param cb A reference to the IDragEvent callback interface. + * @param tapHandler A reference to the IEventTap callback interface. + * @param arg The argument returned with the IEventTap callbacks. */ - inline void registerDragEventHandler(FAR IDragEvent *dragHandler, - uintptr_t arg) + inline void installEventTap(FAR IEventTap *tapHandler, uintptr_t arg) { - m_dragHandler = dragHandler; - m_dragArg = arg; + m_tapHandler = tapHandler; + m_tapArg = arg; + } + + /** + * Return the installed event tap. This is useful if you want to + * install a different event tap, then restore the event tap returned + * by this method when you are finished. + * + * @param tapHandler The location to return IEventTap callback interface. + * @param arg The loation to return the IEventTap argument + */ + + inline void getEventTap(FAR IEventTap *&tapHandler, uintptr_t &arg) + { + m_tapHandler = tapHandler; + m_tapArg = arg; } /**