diff --git a/graphics/twm4nx/src/cbackground.cxx b/graphics/twm4nx/src/cbackground.cxx index 16ddd1c79..f7670051b 100644 --- a/graphics/twm4nx/src/cbackground.cxx +++ b/graphics/twm4nx/src/cbackground.cxx @@ -314,7 +314,7 @@ bool CBackground::event(FAR struct SEventMsg *eventmsg) outmsg.pos.x = eventmsg->pos.x; outmsg.pos.y = eventmsg->pos.y; outmsg.context = EVENT_CONTEXT_BACKGROUND; - outmsg.handler = (FAR CTwm4NxEvent *)0; + outmsg.handler = (FAR void *)0; outmsg.obj = (FAR void *)this; int ret = mq_send(m_eventq, (FAR const char *)&outmsg, diff --git a/graphics/twm4nx/src/ciconmgr.cxx b/graphics/twm4nx/src/ciconmgr.cxx index e0af21559..5d27b48ae 100644 --- a/graphics/twm4nx/src/ciconmgr.cxx +++ b/graphics/twm4nx/src/ciconmgr.cxx @@ -936,11 +936,11 @@ void CIconMgr::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) // Got it... send an event message struct SEventMsg msg; + msg.obj = (FAR void *)this; msg.pos.x = e.getX(); msg.pos.y = e.getY(); msg.context = EVENT_CONTEXT_ICONMGR; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)swin->cwin; + msg.handler = (FAR void *)0; // Got it. Is the window Iconified? diff --git a/graphics/twm4nx/src/ciconwidget.cxx b/graphics/twm4nx/src/ciconwidget.cxx index e8ce29e29..0035bb2fa 100644 --- a/graphics/twm4nx/src/ciconwidget.cxx +++ b/graphics/twm4nx/src/ciconwidget.cxx @@ -460,11 +460,11 @@ void CIconWidget::handleUngrabEvent(const NXWidgets::CWidgetEventArgs &e) struct SEventMsg msg; msg.eventID = EVENT_ICONWIDGET_UNGRAB; + msg.obj = (FAR void *)this; msg.pos.x = e.getX(); msg.pos.y = e.getY(); msg.context = EVENT_CONTEXT_ICON; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then @@ -498,11 +498,11 @@ void CIconWidget::handleDragEvent(const NXWidgets::CWidgetEventArgs &e) struct SEventMsg msg; msg.eventID = EVENT_ICONWIDGET_DRAG; + msg.obj = (FAR void *)this; msg.pos.x = e.getX(); msg.pos.y = e.getY(); msg.context = EVENT_CONTEXT_ICON; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then @@ -557,11 +557,11 @@ void CIconWidget::handleClickEvent(const NXWidgets::CWidgetEventArgs &e) struct SEventMsg msg; msg.eventID = EVENT_ICONWIDGET_GRAB; + msg.obj = (FAR void *)this; msg.pos.x = e.getX(); msg.pos.y = e.getY(); msg.context = EVENT_CONTEXT_ICON; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then diff --git a/graphics/twm4nx/src/cmainmenu.cxx b/graphics/twm4nx/src/cmainmenu.cxx index 68e92810a..fef9addb6 100644 --- a/graphics/twm4nx/src/cmainmenu.cxx +++ b/graphics/twm4nx/src/cmainmenu.cxx @@ -142,10 +142,7 @@ bool CMainMenu::addApplication(FAR IApplication *app) // Add the new menu item to the main menu - FAR NXWidgets::CNxString appName = app->getName(); - - if (!m_mainMenu->addMenuItem(appName, app->getSubMenu(), - app->getEventHandler(), app->getEvent())) + if (!m_mainMenu->addMenuItem(app)) { twmerr("ERROR: addMenuItem failed\n"); std::free(mmitem); diff --git a/graphics/twm4nx/src/cmenus.cxx b/graphics/twm4nx/src/cmenus.cxx index 90c0832a6..caccf937c 100644 --- a/graphics/twm4nx/src/cmenus.cxx +++ b/graphics/twm4nx/src/cmenus.cxx @@ -185,38 +185,31 @@ bool CMenus::initialize(FAR NXWidgets::CNxString &name) /** * Add an item to a menu * - * \param text The text to appear in the menu - * \param subMenu The menu if it is a pull-right entry - * \param handler The application event handler. Should be null unless - * the event recipient is EVENT_RECIPIENT_APP - * \param event The event to generate on menu item selection + * @param item Describes the menu item entry + * @return True if the menu item was added successfully */ -bool CMenus::addMenuItem(FAR NXWidgets::CNxString &text, FAR CMenus *subMenu, - FAR CTwm4NxEvent *handler, uint16_t event) +bool CMenus::addMenuItem(FAR IApplication *item) { twminfo("Adding: subMenu=%p, event=%04x\n", subMenu, event); // Allocate a new menu item entry - FAR struct SMenuItem *item = new SMenuItem; - - if (item == (FAR struct SMenuItem *)0) + FAR struct SMenuItem *newitem = new SMenuItem; + if (newitem == (FAR struct SMenuItem *)0) { twmerr("ERROR: Failed to allocate menu item\n"); return false; } - // Clone the item name so that we have control over its lifespan - - item->text = text; - // Save information about the menu item - item->flink = NULL; - item->subMenu = subMenu; - item->handler = handler; - item->event = event; + newitem->flink = NULL; + newitem->text = item->getName(); + newitem->subMenu = item->getSubMenu(); + newitem->start = item->getStartFunction(); + newitem->handler = item->getEventHandler(); + newitem->event = item->getEvent(); // Increment the total number of menu items @@ -226,17 +219,17 @@ bool CMenus::addMenuItem(FAR NXWidgets::CNxString &text, FAR CMenus *subMenu, if (m_menuHead == NULL) { - m_menuHead = item; - item->blink = (FAR struct SMenuItem *)0; + m_menuHead = newitem; + newitem->blink = (FAR struct SMenuItem *)0; } else { - m_menuTail->flink = item; - item->blink = m_menuTail; + m_menuTail->flink = newitem; + newitem->blink = m_menuTail; } - m_menuTail = item; - item->flink = (FAR struct SMenuItem *)0; + m_menuTail = newitem; + newitem->flink = (FAR struct SMenuItem *)0; // Update the menu window size @@ -260,12 +253,14 @@ bool CMenus::addMenuItem(FAR NXWidgets::CNxString &text, FAR CMenus *subMenu, // We have to update all button labels after resizing + FAR struct SMenuItem *tmpitem; int index; - for (index = 0, item = m_menuHead; - item != (FAR struct SMenuItem *)0; - index++, item = item->flink) + + for (index = 0, tmpitem = m_menuHead; + tmpitem != (FAR struct SMenuItem *)0; + index++, tmpitem = tmpitem->flink) { - m_buttons->setText(0, index, item->text); + m_buttons->setText(0, index, tmpitem->text); } return true; @@ -339,11 +334,11 @@ bool CMenus::event(FAR struct SEventMsg *eventmsg) struct SEventMsg newmsg; newmsg.eventID = item->event; + newmsg.obj = eventmsg->obj; newmsg.pos.x = eventmsg->pos.x; newmsg.pos.y = eventmsg->pos.y; newmsg.context = eventmsg->context; - newmsg.handler = item->handler; - newmsg.obj = eventmsg->obj; + newmsg.handler = (FAR void *)item->handler; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then @@ -807,14 +802,44 @@ void CMenus::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) struct SEventMsg msg; - // If there is a subMenu, then bring the sub-menu up - // now. + // Precedence: + // 1. Event with recipient == EVENT_RECIPIENT_APP. + // getEventHandler() must return a non-NULL instance in this + // case. + // 2. Sub-menu + // 3. Task start-up + // 4. Event with other recipients - if (item->subMenu != (FAR CMenus *)0) + if ((item->event & EVENT_RECIPIENT_MASK) != EVENT_RECIPIENT_APP) { - msg.eventID = EVENT_MENU_SUBMENU; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)item->subMenu; + // If there is a subMenu, then bring the sub-menu up + // now. + + if (item->subMenu != (FAR CMenus *)0) + { + msg.eventID = EVENT_MENU_SUBMENU; + msg.obj = (FAR void *)item->subMenu; + msg.handler = (FAR void *)0; + } + + // If there is a start-up function, then execute the + // start-up function + + else if (item->start != (TStartFunction)0) + { + msg.eventID = EVENT_MENU_SUBMENU; + msg.obj = (FAR void *)this; + msg.handler = (FAR void *)item->start; + } + + // Otherwise, this is an internal message with no handler + + else + { + msg.eventID = item->event; + msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; + } } // Otherwise, send the event specified for the menu item. The @@ -824,8 +849,8 @@ void CMenus::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) else { msg.eventID = item->event; - msg.handler = item->handler; msg.obj = (FAR void *)this; + msg.handler = (FAR void *)item->handler; } // Fill in the remaining, common stuff diff --git a/graphics/twm4nx/src/cnxterm.cxx b/graphics/twm4nx/src/cnxterm.cxx index 68b79248b..abb3d0785 100644 --- a/graphics/twm4nx/src/cnxterm.cxx +++ b/graphics/twm4nx/src/cnxterm.cxx @@ -58,6 +58,7 @@ #include "graphics/nxglyphs.hxx" #include "graphics/twm4nx/twm4nx_config.hxx" +#include "graphics/twm4nx/twm4nx.hxx" #include "graphics/twm4nx/cnxterm.hxx" ///////////////////////////////////////////////////////////////////////////// @@ -67,7 +68,7 @@ // Configuration //////////////////////////////////////////////////////////// #ifdef CONFIG_NSH_USBKBD -# warning You probably do not really want CONFIG_NSH_USBKBD, try CONFIG_NXWM_KEYBOARD_USBHOST +# warning You probably do not really want CONFIG_NSH_USBKBD, try CONFIG_TWM4NX_KEYBOARD_USBHOST #endif /* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to @@ -127,7 +128,7 @@ using namespace Twm4Nx; * @param window. The application window */ -CNxTerm::CNxTerm(CTaskbar *twm4nx, CApplicationWindow *window) +CNxTerm::CNxTerm(CTwm4Nx *twm4nx, CApplicationWindow *window) { // Save the constructor data @@ -189,22 +190,11 @@ IApplicationWindow *CNxTerm::getWindow(void) const NXWidgets::IBitmap *CNxTerm::getIcon(void) { NXWidgets::CRlePaletteBitmap *bitmap = - new NXWidgets::CRlePaletteBitmap(&CONFIG_NXWM_NXTERM_ICON); + new NXWidgets::CRlePaletteBitmap(&CONFIG_TWM4NX_NXTERM_ICON); return bitmap; } -/** - * Get the name string associated with the application - * - * @return A copy if CNxString that contains the name of the application. - */ - -NXWidgets::CNxString CNxTerm::getName(void) -{ - return NXWidgets::CNxString("NuttShell"); -} - /** * Start the application (perhaps in the minimized state). * @@ -245,9 +235,9 @@ bool CNxTerm::run(void) // Describe the NxTerm - g_nxtermvars.wndo.wcolor[0] = CONFIG_NXWM_NXTERM_WCOLOR; - g_nxtermvars.wndo.fcolor[0] = CONFIG_NXWM_NXTERM_FONTCOLOR; - g_nxtermvars.wndo.fontid = CONFIG_NXWM_NXTERM_FONTID; + g_nxtermvars.wndo.wcolor[0] = CONFIG_TWM4NX_NXTERM_WCOLOR; + g_nxtermvars.wndo.fcolor[0] = CONFIG_TWM4NX_NXTERM_FONTCOLOR; + g_nxtermvars.wndo.fontid = CONFIG_TWM4NX_NXTERM_FONTID; // Remember the device minor number (before it is incremented) @@ -264,8 +254,8 @@ bool CNxTerm::run(void) g_nxtermvars.nxterm = 0; sched_lock(); - m_pid = task_create("NxTerm", CONFIG_NXWM_NXTERM_PRIO, - CONFIG_NXWM_NXTERM_STACKSIZE, nxterm, + m_pid = task_create("NxTerm", CONFIG_TWM4NX_NXTERM_PRIO, + CONFIG_TWM4NX_NXTERM_STACKSIZE, nxterm, (FAR char * const *)0); // Did we successfully start the NxTerm task? @@ -321,7 +311,7 @@ bool CNxTerm::run(void) void CNxTerm::stop(void) { // Delete the NxTerm task if it is still running (this could strand - // resources). If we get here due to CTaskbar::stopApplication() processing + // resources). If we get here due to CTwm4Nx::stopApplication() processing // initialed by CNxTerm::exitHandler, then do *not* delete the task (it // is already being deleted). @@ -394,7 +384,7 @@ void CNxTerm::hide(void) /** * Redraw the entire window. The application has been maximized or * otherwise moved to the top of the hierarchy. This method is call from - * CTaskbar when the application window must be displayed + * CTwm4Nx when the application window must be displayed */ void CNxTerm::redraw(void) @@ -573,7 +563,7 @@ void CNxTerm::exitHandler(int code, FAR void *arg) { // Set m_pid to -1 to prevent calling detlete_task() in CNxTerm::stop(). // CNxTerm::stop() is called by the processing initiated by the following - // call to CTaskbar::stopApplication() + // call to CTwm4Nx::stopApplication() This->m_pid = -1; @@ -606,16 +596,31 @@ void CNxTerm::close(void) * @param twm4nx. The twm4nx instance used to terminate the console */ -CNxTermFactory::CNxTermFactory(CTaskbar *twm4nx) +CNxTermFactory::CNxTermFactory(CTwm4Nx *twm4nx) { m_twm4nx = twm4nx; } /** - * Create a new instance of an CNxTerm (as IApplication). + * CNxTermFactory Initializer. Performs parts of the instance construction + * that may fail + * + * @param twm4nx. The twm4nx instance used to terminate the console */ -IApplication *CNxTermFactory::create(void) +bool CNxTermFactory::initialize(void) +{ + // Register an entry with the Main menu. When selected, this will + + FAR CMainMenu *cmain = m_twm4nx->getMainMenu(); + return cmain->addApplication(this); +} + +/** + * Create and start a new instance of an CNxTerm. + */ + +bool *CNxTermFactory::startFunction(CTwm4Nx *twm4n) { // Call CTaskBar::openFullScreenWindow to create a full screen window for // the NxTerm application @@ -647,7 +652,7 @@ IApplication *CNxTermFactory::create(void) return (IApplication *)0; } - return static_cast(nxterm); + return true; } /** @@ -661,7 +666,7 @@ IApplication *CNxTermFactory::create(void) NXWidgets::IBitmap *CNxTermFactory::getIcon(void) { NXWidgets::CRlePaletteBitmap *bitmap = - new NXWidgets::CRlePaletteBitmap(&CONFIG_NXWM_NXTERM_ICON); + new NXWidgets::CRlePaletteBitmap(&CONFIG_TWM4NX_NXTERM_ICON); return bitmap; } diff --git a/graphics/twm4nx/src/ctwm4nx.cxx b/graphics/twm4nx/src/ctwm4nx.cxx index 859e822e1..d6a73ca05 100644 --- a/graphics/twm4nx/src/ctwm4nx.cxx +++ b/graphics/twm4nx/src/ctwm4nx.cxx @@ -501,8 +501,9 @@ bool CTwm4Nx::dispatchEvent(FAR struct SEventMsg *eventmsg) // fixed, a priori endpoint. Rather, the endpoint must be // provided in the 'handler' field of the message - DEBUGASSERT(eventmsg->handler != (FAR CTwm4NxEvent *)0); - ret = eventmsg->handler->event(eventmsg); + DEBUGASSERT(eventmsg->handler != (FAR void *)0); + FAR CTwm4NxEvent *handler = (FAR CTwm4NxEvent *)eventmsg->handler; + ret = handler->event(eventmsg); } break; diff --git a/graphics/twm4nx/src/cwindow.cxx b/graphics/twm4nx/src/cwindow.cxx index 1dd3651a8..0fc350fe7 100644 --- a/graphics/twm4nx/src/cwindow.cxx +++ b/graphics/twm4nx/src/cwindow.cxx @@ -1270,11 +1270,11 @@ void CWindow::handleUngrabEvent(nxgl_coord_t x, nxgl_coord_t y) struct SEventMsg msg; msg.eventID = EVENT_TOOLBAR_UNGRAB; + msg.obj = (FAR void *)this; msg.pos.x = x; msg.pos.y = y; msg.context = EVENT_CONTEXT_TOOLBAR; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then @@ -1308,11 +1308,11 @@ void CWindow::handleClickEvent(const NXWidgets::CWidgetEventArgs &e) struct SEventMsg msg; msg.eventID = EVENT_TOOLBAR_GRAB; + msg.obj = (FAR void *)this; msg.pos.x = e.getX(); msg.pos.y = e.getY(); msg.context = EVENT_CONTEXT_TOOLBAR; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then @@ -1380,11 +1380,11 @@ void CWindow::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) struct SEventMsg msg; msg.eventID = GToolBarInfo[btindex].event; + msg.obj = (FAR void *)this; msg.pos.x = e.getX(); msg.pos.y = e.getY(); msg.context = EVENT_CONTEXT_TOOLBAR; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then @@ -1436,11 +1436,11 @@ bool CWindow::dragEvent(FAR const struct nxgl_point_s &pos, struct SEventMsg msg; msg.eventID = EVENT_WINDOW_DRAG; + msg.obj = (FAR void *)this; msg.pos.x = pos.x; msg.pos.y = pos.y + yIncr; msg.context = EVENT_CONTEXT_TOOLBAR; - msg.handler = (FAR CTwm4NxEvent *)0; - msg.obj = (FAR void *)this; + msg.handler = (FAR void *)0; // NOTE that we cannot block because we are on the same thread // as the message reader. If the event queue becomes full then diff --git a/include/graphics/twm4nx/ciconmgr.hxx b/include/graphics/twm4nx/ciconmgr.hxx index 6fd255993..6d3dedaa3 100644 --- a/include/graphics/twm4nx/ciconmgr.hxx +++ b/include/graphics/twm4nx/ciconmgr.hxx @@ -190,7 +190,7 @@ namespace Twm4Nx * @param name The name of the application. */ - inline const NXWidgets::CNxString getName(void) + inline NXWidgets::CNxString getName(void) { return m_name; } @@ -212,8 +212,9 @@ namespace Twm4Nx * be called in this implementation */ - inline void start(FAR CTwm4Nx *twm4nx) + inline TStartFunction getStartFunction(void) { + return (TStartFunction)0; } /** diff --git a/include/graphics/twm4nx/cmenus.hxx b/include/graphics/twm4nx/cmenus.hxx index 171e19ecb..7d3592a3a 100644 --- a/include/graphics/twm4nx/cmenus.hxx +++ b/include/graphics/twm4nx/cmenus.hxx @@ -56,6 +56,7 @@ #include "graphics/twm4nx/cwindow.hxx" #include "graphics/twm4nx/ctwm4nxevent.hxx" +#include "graphics/twm4nx/iapplication.hxx" ///////////////////////////////////////////////////////////////////////////// // Pre-processor Definitions @@ -99,8 +100,9 @@ namespace Twm4Nx { FAR struct SMenuItem *flink; /**< Forward link to next menu item */ FAR struct SMenuItem *blink; /**< Backward link previous menu item */ - FAR CMenus *subMenu; /**< Menu root of a pull right menu */ FAR NXWidgets::CNxString text; /**< The text string for the menu item */ + FAR CMenus *subMenu; /**< Menu root of a pull right menu */ + TStartFunction start; /**< Application start-up function */ FAR CTwm4NxEvent *handler; /**< Application event handler */ uint16_t event; /**< Menu selection event */ }; @@ -266,15 +268,11 @@ namespace Twm4Nx /** * Add an item to a menu * - * \param text The text to appear in the menu - * \param subMenu The menu root if it is a pull-right entry - * \param handler The application event handler. Should be NULL unless - * the event recipient is EVENT_RECIPIENT_APP - * \param event The event to generate on menu item selection + * @param item Describes the menu item entry + * @return True if the menu item was added successfully */ - bool addMenuItem(FAR NXWidgets::CNxString &text, FAR CMenus *subMenu, - FAR CTwm4NxEvent *handler, uint16_t event); + bool addMenuItem(FAR IApplication *item); /** * Return the size of the menu window frame diff --git a/include/graphics/twm4nx/cnxterm.hxx b/include/graphics/twm4nx/cnxterm.hxx index 7d43ad059..9a4a14b37 100644 --- a/include/graphics/twm4nx/cnxterm.hxx +++ b/include/graphics/twm4nx/cnxterm.hxx @@ -48,6 +48,7 @@ #include #include "graphics/twm4nx/ctwm4nx.hxx" +#include "graphics/twm4nx/iapplication.hxx" ///////////////////////////////////////////////////////////////////////////// // Implementation Classes @@ -68,170 +69,236 @@ namespace Twm4Nx * This class implements the NxTerm application. */ - class CNxTerm : public IApplication, private IApplicationCallback + class CNxTerm { - private: - CTaskbar *m_twm4nx; /**< Reference to the "parent" twm4nx */ - CApplicationWindow *m_window; /**< Reference to the application window */ - NXTERM m_nxterm; /**< NxTerm handle */ - pid_t m_pid; /**< Task ID of the NxTerm thread */ - int m_minor; /**< Terminal device minor number */ + private: + CTaskbar *m_twm4nx; /**< Reference to the "parent" twm4nx */ + CApplicationWindow *m_window; /**< Reference to the application window */ + NXTERM m_nxterm; /**< NxTerm handle */ + pid_t m_pid; /**< Task ID of the NxTerm thread */ + int m_minor; /**< Terminal device minor number */ - /** - * This is the NxTerm task. This function first redirects output to the - * console window then calls to start the NSH logic. - */ + /** + * This is the NxTerm task. This function first redirects output to the + * console window then calls to start the NSH logic. + */ - static int nxterm(int argc, char *argv[]); + static int nxterm(int argc, char *argv[]); - /** - * This is the NxTerm task exit handler. It is registered with on_exit() - * and called automatically when the nxterm task exits. - */ + /** + * This is the NxTerm task exit handler. It is registered with on_exit() + * and called automatically when the nxterm task exits. + */ - static void exitHandler(int code, FAR void *arg); + static void exitHandler(int code, FAR void *arg); - /** - * Called when the window minimize button is pressed. - */ + /** + * Called when the window minimize button is pressed. + */ - void minimize(void); + void minimize(void); - /** - * Called when the window close button is pressed. - */ + /** + * Called when the window close button is pressed. + */ - void close(void); + void close(void); - public: - /** - * CNxTerm constructor - * - * @param window. The application window - * - * @param twm4nx. A pointer to the parent task bar instance - * @param window. The window to be used by this application. - */ + /** + * Start the application (perhaps in the minimized state). + * + * @return True if the application was successfully started. + */ - CNxTerm(CTaskbar *twm4nx, CApplicationWindow *window); + bool run(void); - /** - * CNxTerm destructor - */ + /** + * Stop the application. + */ - ~CNxTerm(void); + void stop(void); - /** - * Each implementation of IApplication must provide a method to recover - * the contained CApplicationWindow instance. - */ + /** + * Destroy the application and free all of its resources. This method + * will initiate blocking of messages from the NX server. The server + * will flush the window message queue and reply with the blocked + * message. When the block message is received by CWindowMessenger, + * it will send the destroy message to the start window task which + * will, finally, safely delete the application. + */ - IApplicationWindow *getWindow(void) const; + void destroy(void); - /** - * Get the icon associated with the application - * - * @return An instance if IBitmap that may be used to rend the - * application's icon. This is an new IBitmap instance that must - * be deleted by the caller when it is no long needed. - */ + /** + * The application window is hidden (either it is minimized or it is + * maximized, but not at the top of the hierarchy + */ - NXWidgets::IBitmap *getIcon(void); + void hide(void); - /** - * Get the name string associated with the application - * - * @return A copy if CNxString that contains the name of the application. - */ + /** + * Redraw the entire window. The application has been maximized or + * otherwise moved to the top of the hierarchy. This method is call from + * CTaskbar when the application window must be displayed + */ - NXWidgets::CNxString getName(void); + void redraw(void); - /** - * Start the application (perhaps in the minimized state). - * - * @return True if the application was successfully started. - */ + /** + * Report of this is a "normal" window or a full screen window. The + * primary purpose of this method is so that window manager will know + * whether or not it show draw the task bar. + * + * @return True if this is a full screen window. + */ - bool run(void); - - /** - * Stop the application. - */ - - void stop(void); - - /** - * Destroy the application and free all of its resources. This method - * will initiate blocking of messages from the NX server. The server - * will flush the window message queue and reply with the blocked - * message. When the block message is received by CWindowMessenger, - * it will send the destroy message to the start window task which - * will, finally, safely delete the application. - */ - - void destroy(void); - - /** - * The application window is hidden (either it is minimized or it is - * maximized, but not at the top of the hierarchy - */ - - void hide(void); - - /** - * Redraw the entire window. The application has been maximized or - * otherwise moved to the top of the hierarchy. This method is call from - * CTaskbar when the application window must be displayed - */ - - void redraw(void); - - /** - * Report of this is a "normal" window or a full screen window. The - * primary purpose of this method is so that window manager will know - * whether or not it show draw the task bar. - * - * @return True if this is a full screen window. - */ - - bool isFullScreen(void) const; + bool isFullScreen(void) const; }; - class CNxTermFactory : public IApplicationFactory + class CNxTermFactory : public IApplication, public IApplicationFactory { - private: - CTaskbar *m_twm4nx; /**< The twm4nx */ + private: + CTaskbar *m_twm4nx; /**< The twm4nx */ - public: - /** - * CNxTermFactory Constructor - * - * @param twm4nx. The twm4nx instance used to terminate calibration - */ + /** + * Return the Main Menu item string. This overrides the method from + * IApplication + * + * @param name The name of the application. + */ - CNxTermFactory(CTaskbar *twm4nx); + inline NXWidgets::CNxString getName(void) + { + return NXWidgets::CNxString("NxTerm"); + } - /** - * CNxTermFactory Destructor - */ + /** + * There is no sub-menu for this Main Menu item. This overrides + * the method from IApplication. + * + * @return This implementation will always return a null value. + */ - inline ~CNxTermFactory(void) { } + inline FAR CMenus *getSubMenu(void) + { + return (FAR CMenus *)0; + } - /** - * Create a new instance of an CNxTerm (as IApplication). - */ + /** + * There is no application start-up function. This function will not + * be called in this implementation + */ - IApplication *create(void); + inline TStartFunction getStartFunction(void) + { + return (TStartFunction)startFunction; + } - /** - * Get the icon associated with the application - * - * @return An instance if IBitmap that may be used to rend the - * application's icon. This is an new IBitmap instance that must - * be deleted by the caller when it is no long needed. - */ + /** + * There is no custom event handler. We use the common event handler. + * + * @return. null is always returned in this impementation. + */ - NXWidgets::IBitmap *getIcon(void); + inline FAR CTwm4NxEvent *getEventHandler(void) + { + return (FAR CTwm4NxEvent *)0; + } + + /** + * Return the Twm4Nx event that will be generated when the Main Menu + * item is selected. + * + * @return. This function always returns EVENT_SYSTEM_NOP. + */ + + inline uint16_t getEvent(void) + { + return EVENT_SYSTEM_NOP; + } + + public: + /** + * CNxTerm constructor + * + * @param window. The application window + * + * @param twm4nx. A pointer to the parent task bar instance + * @param window. The window to be used by this application. + */ + + CNxTerm(CTaskbar *twm4nx, CApplicationWindow *window); + + /** + * CNxTerm destructor + */ + + ~CNxTerm(void); + + /** + * Each implementation of IApplication must provide a method to recover + * the contained CApplicationWindow instance. + */ + + IApplicationWindow *getWindow(void) const; + + /** + * Get the icon associated with the application + * + * @return An instance if IBitmap that may be used to rend the + * application's icon. This is an new IBitmap instance that must + * be deleted by the caller when it is no long needed. + */ + + NXWidgets::IBitmap *getIcon(void); + + /** + * Get the name string associated with the application + * + * @return A copy if CNxString that contains the name of the application. + */ + + NXWidgets::CNxString getName(void); + + public: + /** + * CNxTermFactory Constructor + * + * @param twm4nx. The twm4nx instance used to terminate calibration + */ + + CNxTermFactory(CTaskbar *twm4nx); + + /** + * CNxTermFactory Destructor + */ + + inline ~CNxTermFactory(void) { } + + /** + * CNxTermFactory Initializer. Performs parts of the instance + * construction that may fail + * + * @param twm4nx. The twm4nx instance used to terminate the console + */ + + bool CNxTermFactory::initialize(void); + + /** + * Create a new instance of an CNxTerm (as IApplication). + */ + + IApplication *create(void); + + /** + * Get the icon associated with the application + * + * @return An instance if IBitmap that may be used to rend the + * application's icon. This is an new IBitmap instance that must + * be deleted by the caller when it is no long needed. + */ + + NXWidgets::IBitmap *getIcon(void); }; } diff --git a/include/graphics/twm4nx/cwindowfactory.hxx b/include/graphics/twm4nx/cwindowfactory.hxx index 77b80704b..2c112c17f 100644 --- a/include/graphics/twm4nx/cwindowfactory.hxx +++ b/include/graphics/twm4nx/cwindowfactory.hxx @@ -98,7 +98,7 @@ namespace Twm4Nx * @param name The name of the application. */ - inline const NXWidgets::CNxString getName(void) + inline NXWidgets::CNxString getName(void) { return NXWidgets::CNxString("Desktop"); } @@ -120,8 +120,9 @@ namespace Twm4Nx * be called in this implementation */ - inline void start(FAR CTwm4Nx *twm4nx) + inline TStartFunction getStartFunction(void) { + return (TStartFunction)0; } /** diff --git a/include/graphics/twm4nx/iapplication.hxx b/include/graphics/twm4nx/iapplication.hxx index 96d7858c1..8b720530c 100644 --- a/include/graphics/twm4nx/iapplication.hxx +++ b/include/graphics/twm4nx/iapplication.hxx @@ -59,6 +59,17 @@ namespace Twm4Nx class CMenus; // Forward reference class CTwm4NxEvent; // Forward reference + /** + * Get the start function entry point. + * + * @param twm4nx The Twm4Nx session object. Use with care! The CTwm4Nx + * logic runs on a different thread and some of the methods of the + * class may not be thread safe. + * @return True if the application was started successfully + */ + + typedef CODE bool (*TStartFunction)(FAR CTwm4Nx *twm4nx); + /** * Defines the interface of an application to the Main Menu. "Built-In" * applications are started via CMainMenu. This interface class defines @@ -86,7 +97,7 @@ namespace Twm4Nx * @return The name of the application. */ - virtual const NXWidgets::CNxString getName(void) = 0; + virtual NXWidgets::CNxString getName(void) = 0; /** * Return any submenu item associated with the menu entry. If a non- @@ -94,10 +105,22 @@ namespace Twm4Nx * the menu entry is selected. Otherwise, the start() method will be * called. These two behaviors are mutually exlusive. * - * NOTE: Both the start() and getSubMenu() return values are ignored - * if the event() method returns an event with recipient = - * EVENT_RECIPIENT_APP. In that case, the application will be fully - * responsible for handling the menu selection event. + * NOTEs: + * * Both the start() and getSubMenu() methods are ignoredif the event() + * method returns an event with recipient = EVENT_RECIPIENT_APP. In + * that case, the application will be fully responsible for handling + * the menu selection event. + * * Otherwise, the sub-menu or start-up take precedence over + * the event. + * * If getSubMenu() returns a non-NULL CMenu instance, then the + * subMenu is used and the start() is not called. + * + * Precedence: + * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() + * must return a non-NULL instance in this case. + * 2. Sub-menu + * 3. Task start-up + * 4. Event with other recipients * * @return. A reference to any sub-menu that should be brought up if * the menu item is selected. This must be null if the menu item @@ -115,17 +138,28 @@ namespace Twm4Nx * The Main Menu runs on the main Twm4Nx thread so this function will, * typically, create a new thread to host the application. * - * NOTE: Both the start() and getSubMenu() return values are ignored - * if the event() method returns an event with recipient = - * EVENT_RECIPIENT_APP. In that case, the application will be fully - * responsible for handling the menu selection event. + * NOTEs: + * * Both the start() and getSubMenu() methods are ignoredif the event() + * method returns an event with recipient = EVENT_RECIPIENT_APP. In + * that case, the application will be fully responsible for handling + * the menu selection event. + * * Otherwise, the sub-menu or start-up take precedence over + * the event. + * * If getSubMenu() returns a non-NULL CMenu instance, then the + * subMenu is used and the start() is not called. * - * @param twm4nx The Twm4Nx session object. Use with care! The CTwm4Nx - * logic runs on a different thread and some of the methods of the - * class may not be thread safe. + * Precedence: + * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() + * must return a non-NULL instance in this case. + * 2. Sub-menu + * 3. Task start-up + * 4. Event with other recipients + * + * @return The start-up function entry point. A null value is returned + * if there is no startup function. */ - virtual void start(FAR CTwm4Nx *twm4nx) = 0; + virtual TStartFunction getStartFunction(void) = 0; /** * External applications may provide their own event handler that runs @@ -150,15 +184,33 @@ namespace Twm4Nx /** * Get the Twm4Nx event that will be generated when the menu item is - * selected. All returned values are ignored unless the event recipient - * is EVENT_RECIPIENT_APP. Otherwise, the event EVENT_MAINMENU_SELECT - * is used and any subsequent menu item action, either bringing up - * a sub-menu or starting an application, will be performed by CMainMenu. + * selected. If the returned value has the event recipient of + * EVENT_RECIPIENT_APP, then getEventHandler() must return the event + * handling instance. Otherwise, the event will be handled by internal + * Twm4Nx logic based on the internal recipient. * - * This method may return zero in that case. It would be an error if - * this method returned an event with EVENT_RECIPIENT_APP but the + * This method may return EVENT_SYSTEM_NOP if a subMenu or task start-up + * function should be executed. It would be an error if this method + * returned an event with EVENT_RECIPIENT_APP but the * getEventHandler() method returned null. * + * NOTEs: + * * Both the start() and getSubMenu() methods are ignoredif the event() + * method returns an event with recipient = EVENT_RECIPIENT_APP. In + * that case, the application will be fully responsible for handling + * the menu selection event. + * * Otherwise, the sub-menu or start-up take precedence over + * the event. + * * If getSubMenu() returns a non-NULL CMenu instance, then the + * subMenu is used and the start() is not called. + * + * Precedence: + * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() + * must return a non-NULL instance in this case. + * 2. Sub-menu + * 3. Task start-up + * 4. Event with other recipients + * * @return. Either, (1) an event with recipient = EVENT_RECIPIENT_APP * that will be generated when menu item is selected, or (2) any other * value (preferabley zero) that indicates that standard, built-in diff --git a/include/graphics/twm4nx/twm4nx_widgetevents.hxx b/include/graphics/twm4nx/twm4nx_widgetevents.hxx index 7cce35330..5fa073baf 100644 --- a/include/graphics/twm4nx/twm4nx_widgetevents.hxx +++ b/include/graphics/twm4nx/twm4nx_widgetevents.hxx @@ -47,7 +47,6 @@ #include #include -#include "graphics/nxwidgets/cwindoweventhandler.hxx" ///////////////////////////////////////////////////////////////////////////// // Preprocessor Definitions @@ -107,6 +106,7 @@ namespace Twm4Nx EVENT_SYSTEM_NOP = 0x0000, /**< Null event */ EVENT_SYSTEM_ERROR = 0x0001, /**< Report system error */ EVENT_SYSTEM_EXIT = 0x0002, /**< Terminate the Twm4Nx session */ + EVENT_SYSTEM_STARTUP = 0x0003, /**< Start an application */ // Recipient == BACKGOUND @@ -206,7 +206,7 @@ namespace Twm4Nx struct nxgl_point_s pos; /**< X/Y position */ uint8_t context; /**< Button press context */ - FAR CTwm4NxEvent *handler; /**< App event handler (APP recipient only) */ + FAR void *handler; /**< Context specific handler */ }; /**