diff --git a/graphics/twm4nx/src/cbackground.cxx b/graphics/twm4nx/src/cbackground.cxx index c4b3eff36..639236159 100644 --- a/graphics/twm4nx/src/cbackground.cxx +++ b/graphics/twm4nx/src/cbackground.cxx @@ -370,7 +370,8 @@ bool CBackground::createBackgroundWindow(void) events.kbdEvent = EVENT_SYSTEM_NOP; events.closeEvent = EVENT_SYSTEM_NOP; - FAR CWindowEvent *control = new CWindowEvent(m_twm4nx, events); + FAR CWindowEvent *control = + new CWindowEvent(m_twm4nx, (FAR CWindow *)0, events); // Create the background window (CTwm4Nx inherits from CNxServer) diff --git a/graphics/twm4nx/src/ciconmgr.cxx b/graphics/twm4nx/src/ciconmgr.cxx index 8b22f9f47..d2e5039fc 100644 --- a/graphics/twm4nx/src/ciconmgr.cxx +++ b/graphics/twm4nx/src/ciconmgr.cxx @@ -291,17 +291,14 @@ void CIconMgr::removeWindow(FAR CWindow *cwin) FAR struct SWindowEntry *wentry = findEntry(cwin); if (wentry != (FAR struct SWindowEntry *)0) { - // Remove the list from the window structure + // Remove the Window from the icon manager list removeEntry(wentry); - - // Destroy the window - - CWindowFactory *factory = m_twm4nx->getWindowFactory(); - factory->destroyWindow(wentry->cwin); - m_nWindows--; std::free(wentry); + + // Repack the button array without the removed window + pack(); } } diff --git a/graphics/twm4nx/src/cnxterm.cxx b/graphics/twm4nx/src/cnxterm.cxx index de7952b30..bb16277b0 100644 --- a/graphics/twm4nx/src/cnxterm.cxx +++ b/graphics/twm4nx/src/cnxterm.cxx @@ -155,10 +155,15 @@ CNxTerm::~CNxTerm(void) stop(); - // Although we didn't create it, we are responsible for deleting the - // application window + // The following is not necessary. The system will automatically + // delete the CWindow instance when the terminate button is pressed. + // We simply have to terminate the application behind the window + +#if 0 + // Delete the application window delete m_nxtermWindow; +#endif } /** diff --git a/graphics/twm4nx/src/cresize.cxx b/graphics/twm4nx/src/cresize.cxx index 358f772df..078f2ccdc 100644 --- a/graphics/twm4nx/src/cresize.cxx +++ b/graphics/twm4nx/src/cresize.cxx @@ -972,7 +972,8 @@ bool CResize::createSizeWindow(void) events.kbdEvent = EVENT_SYSTEM_NOP; events.closeEvent = EVENT_SYSTEM_NOP; - FAR CWindowEvent *control = new CWindowEvent(m_twm4nx, events); + FAR CWindowEvent *control = + new CWindowEvent(m_twm4nx, (FAR CWindow *)0, events); // 4. Create the main window diff --git a/graphics/twm4nx/src/cwindow.cxx b/graphics/twm4nx/src/cwindow.cxx index ccdc7f6b0..a35a4cf54 100644 --- a/graphics/twm4nx/src/cwindow.cxx +++ b/graphics/twm4nx/src/cwindow.cxx @@ -705,11 +705,11 @@ bool CWindow::event(FAR struct SEventMsg *eventmsg) struct SEventMsg outmsg; outmsg.eventID = m_appEvents.closeEvent; - outmsg.obj = m_appEvents.eventObj; + outmsg.obj = (FAR void *)this; outmsg.pos.x = eventmsg->pos.x; outmsg.pos.y = eventmsg->pos.y; outmsg.context = eventmsg->context; - outmsg.handler = eventmsg->handler; + outmsg.handler = m_appEvents.eventObj; int ret = mq_send(m_eventq, (FAR const char *)&outmsg, sizeof(struct SEventMsg), 100); @@ -795,7 +795,7 @@ bool CWindow::createMainWindow(FAR const nxgl_size_s *winsize, // Setup the the CWindowEvent instance to use our inherited drag event // handler - m_windowEvent = new CWindowEvent(m_twm4nx, m_appEvents); + m_windowEvent = new CWindowEvent(m_twm4nx, this, m_appEvents); m_windowEvent->registerDragEventHandler(this, (uintptr_t)1); // 4. Create the window. Handling provided flags. NOTE: that menu windows @@ -900,7 +900,7 @@ bool CWindow::createToolbar(void) events.kbdEvent = EVENT_SYSTEM_NOP; events.closeEvent = EVENT_SYSTEM_NOP; - FAR CWindowEvent *control = new CWindowEvent(m_twm4nx, events); + FAR CWindowEvent *control = new CWindowEvent(m_twm4nx, this, events); control->registerDragEventHandler(this, (uintptr_t)0); // 3. Get the toolbar sub-window from the framed window @@ -1790,6 +1790,14 @@ void CWindow::cleanup(void) m_tbTitle = (FAR NXWidgets::CLabel *)0; } + // Delete the toolbar + + if (m_toolbar != (FAR NXWidgets::CNxToolbar *)0) + { + delete m_toolbar; + m_toolbar = (FAR NXWidgets::CNxToolbar *)0; + } + // Delete the window if (m_nxWin != (FAR NXWidgets::CNxTkWindow *)0) diff --git a/graphics/twm4nx/src/cwindowevent.cxx b/graphics/twm4nx/src/cwindowevent.cxx index b67164cc3..f857cc7df 100644 --- a/graphics/twm4nx/src/cwindowevent.cxx +++ b/graphics/twm4nx/src/cwindowevent.cxx @@ -95,18 +95,20 @@ using namespace Twm4Nx; * CWindowEvent Constructor * * @param twm4nx The Twm4Nx session instance. + * @param client The client window instance. * @param events Describes the application event configuration * @param style The default style that all widgets on this display * should use. If this is not specified, the widget will use the * values stored in the defaultCWidgetStyle object. */ -CWindowEvent::CWindowEvent(FAR CTwm4Nx *twm4nx, +CWindowEvent::CWindowEvent(FAR CTwm4Nx *twm4nx, FAR CWindow *client, FAR const struct SAppEvents &events, FAR const NXWidgets::CWidgetStyle *style) : NXWidgets::CWidgetControl(style) { m_twm4nx = twm4nx; // Cache the Twm4Nx session + m_clientWindow = client; // Cache the client window instance // Events @@ -364,7 +366,7 @@ void CWindowEvent::handleBlockedEvent(FAR void *arg) struct SNxEventMsg msg; msg.eventID = EVENT_WINDOW_DELETE; - msg.obj = arg; + msg.obj = m_clientWindow; msg.instance = this; int ret = mq_send(m_eventq, (FAR const char *)&msg, diff --git a/graphics/twm4nx/src/cwindowfactory.cxx b/graphics/twm4nx/src/cwindowfactory.cxx index 0826349e7..0b71a6e5c 100644 --- a/graphics/twm4nx/src/cwindowfactory.cxx +++ b/graphics/twm4nx/src/cwindowfactory.cxx @@ -234,12 +234,15 @@ FAR CWindow * * Handle the EVENT_WINDOW_DELETE event. The logic sequence is as * follows: * - * 1. The TERMINATE button in pressed in the Window Toolbar - * 2. CWindowFactory::event receives the widget event, - * EVENT_WINDOW_TERMINATE and request to halt the NX Server + * 1. The TERMINATE button in pressed in the Window Toolbar and + * CWindow::handleActionEvent() catches the button event on the + * event listener thread and generates the EVENT_WINDOW_TERMINATE + * 2. CWindows::event receives the widget event, EVENT_WINDOW_TERMINATE, + * on the Twm4NX manin threadand requests to halt the NX Server * messages queues. - * 3. The server responds with the EVENT_WINDOW_DELETE which is - * caught by this function. + * 3. when server responds, the CwindowsEvent::handleBlockedEvent + * generates the EVENT_WINDOW_DELETE which is caught by + * CWindows::event() and which, in turn calls this function. * * @param cwin The CWindow instance. This will be deleted and its * associated container will be freed. diff --git a/include/graphics/twm4nx/cwindowevent.hxx b/include/graphics/twm4nx/cwindowevent.hxx index 9a54f655f..e8d70414f 100644 --- a/include/graphics/twm4nx/cwindowevent.hxx +++ b/include/graphics/twm4nx/cwindowevent.hxx @@ -59,6 +59,8 @@ namespace Twm4Nx { + class CWindow; // Forward reference + // This structure provides information to support application events struct SAppEvents @@ -152,8 +154,9 @@ namespace Twm4Nx { private: FAR CTwm4Nx *m_twm4nx; /**< Cached instance of CTwm4Nx */ + FAR CWindow *m_clientWindow; /**< The client window instance */ mqd_t m_eventq; /**< NxWidget event message queue */ - struct SAppEvents m_appEvents; /**< Appliation event information */ + struct SAppEvents m_appEvents; /**< Application event information */ // Dragging @@ -202,13 +205,15 @@ namespace Twm4Nx * CWindowEvent Constructor * * @param twm4nx The Twm4Nx session instance. + * @param client The client window instance. * @param events Describes the application event configuration * @param style The default style that all widgets on this display * should use. If this is not specified, the widget will use the * values stored in the defaultCWidgetStyle object. */ - CWindowEvent(FAR CTwm4Nx *twm4nx, FAR const struct SAppEvents &events, + CWindowEvent(FAR CTwm4Nx *twm4nx, FAR CWindow *client, + FAR const struct SAppEvents &events, FAR const NXWidgets::CWidgetStyle *style = (const NXWidgets::CWidgetStyle *)NULL); diff --git a/include/graphics/twm4nx/cwindowfactory.hxx b/include/graphics/twm4nx/cwindowfactory.hxx index 5c193c879..c12ac1d46 100644 --- a/include/graphics/twm4nx/cwindowfactory.hxx +++ b/include/graphics/twm4nx/cwindowfactory.hxx @@ -252,12 +252,15 @@ namespace Twm4Nx * Handle the EVENT_WINDOW_DELETE event. The logic sequence is as * follows: * - * 1. The TERMINATE button in pressed in the Window Toolbar - * 2. CWindowFactory::event receives the widget event, - * EVENT_WINDOW_TERMINATE and request to halt the NX Server + * 1. The TERMINATE button in pressed in the Window Toolbar and + * CWindow::handleActionEvent() catches the button event on the + * event listener thread and generates the EVENT_WINDOW_TERMINATE + * 2. CWindows::event receives the widget event, EVENT_WINDOW_TERMINATE, + * on the Twm4NX manin threadand requests to halt the NX Server * messages queues. - * 3. The server responds with the EVENT_WINDOW_DELETE which is - * caught by this function. + * 3. when server responds, the CwindowsEvent::handleBlockedEvent + * generates the EVENT_WINDOW_DELETE which is caught by + * CWindows::event() and which, in turn calls this function. * * @param cwin The CWindow instance. This will be deleted and its * associated container will be freed.