From b0d39372fbd323353217cf588b024b4d35794408 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 7 May 2019 08:51:37 -0600 Subject: [PATCH] apps/graphics/twm4nx: Exploit the new feature to create hidden windows. This cleans up some brief window startup anomalies. Also fixes an initialization error in CMenus. --- graphics/twm4nx/src/ciconmgr.cxx | 8 +++----- graphics/twm4nx/src/cmenus.cxx | 18 +++++++++++++----- graphics/twm4nx/src/cwindow.cxx | 14 +++++++++++--- include/graphics/twm4nx/cmenus.hxx | 3 ++- include/graphics/twm4nx/cwindow.hxx | 7 ++++++- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/graphics/twm4nx/src/ciconmgr.cxx b/graphics/twm4nx/src/ciconmgr.cxx index 145142ae0..f12a6e04d 100644 --- a/graphics/twm4nx/src/ciconmgr.cxx +++ b/graphics/twm4nx/src/ciconmgr.cxx @@ -527,11 +527,13 @@ bool CIconMgr::createIconManagerWindow(FAR const char *prefix) // WFLAGS_NO_RESIZE_BUTTON: The user cannot control the Icon Manager // window size // WFLAGS_IS_ICONMGR: Yes, this is the Icon Manager window + // WFLAGS_HIDDEN_WINDOW: The window is created in the hidden state CWindowFactory *factory = m_twm4nx->getWindowFactory(); uint8_t wflags = (WFLAGS_NO_MENU_BUTTON | WFLAGS_NO_DELETE_BUTTON | - WFLAGS_NO_RESIZE_BUTTON | WFLAGS_IS_ICONMGR); + WFLAGS_NO_RESIZE_BUTTON | WFLAGS_IS_ICONMGR | + WFLAGS_HIDDEN_WINDOW); m_window = factory->createWindow(name, &CONFIG_TWM4NX_ICONMGR_IMAGE, this, wflags); @@ -542,10 +544,6 @@ bool CIconMgr::createIconManagerWindow(FAR const char *prefix) return false; } - // Hide the window until we complete the configuration - - m_window->hideWindow(); - // Free any temporary name strings if (allocName != (FAR char *)0) diff --git a/graphics/twm4nx/src/cmenus.cxx b/graphics/twm4nx/src/cmenus.cxx index feb288cf9..63b07d9dd 100644 --- a/graphics/twm4nx/src/cmenus.cxx +++ b/graphics/twm4nx/src/cmenus.cxx @@ -94,6 +94,8 @@ CMenus::CMenus(CTwm4Nx *twm4nx) // Menus + m_menuHead = (FAR struct SMenuItem *)0; // No menu items + m_menuTail = (FAR struct SMenuItem *)0; // No menu items m_popUpMenu = (FAR CMenus *)0; // No pop-up menu m_activeItem = (FAR struct SMenuItem *)0; // No active menu item m_nMenuItems = 0; // No menu items yet @@ -461,7 +463,8 @@ void CMenus::identify(FAR CWindow *cwin) } /** - * Create the menu window + * Create the menu window. Menu windows are always created in the hidden + * state. When the menu is selected, then it should be shown. * * @result True is returned on success */ @@ -478,9 +481,11 @@ bool CMenus::createMenuWindow(void) FAR CWindowEvent *control = new CWindowEvent(m_twm4nx, (FAR void *)this); - // 4. Create the menu window + // 4. Create the menu window. Menu windows are always created in the + // hidden state. When the menu is selected, then it should be shown. - m_menuWindow = m_twm4nx->createFramedWindow(control, NXBE_WINDOW_RAMBACKED); + uint8_t cflags = (NXBE_WINDOW_RAMBACKED | NXBE_WINDOW_HIDDEN); + m_menuWindow = m_twm4nx->createFramedWindow(control, cflags); if (m_menuWindow == (FAR NXWidgets::CNxTkWindow *)0) { delete control; @@ -537,9 +542,12 @@ bool CMenus::setMenuWindowSize(void) m_entryHeight = menuFont->getHeight() + 4; - // Get the length of the longest item string in in the menu + // Get the length of the title + + nxgl_coord_t maxstring = menuFont->getStringWidth(m_menuName); + + // Compare that to the length of the longest item string in in the menu - nxgl_coord_t maxstring = 0; for (FAR struct SMenuItem *curr = m_menuHead; curr != NULL; curr = curr->flink) diff --git a/graphics/twm4nx/src/cwindow.cxx b/graphics/twm4nx/src/cwindow.cxx index 91a1d9003..fe0e3c131 100644 --- a/graphics/twm4nx/src/cwindow.cxx +++ b/graphics/twm4nx/src/cwindow.cxx @@ -249,7 +249,7 @@ bool CWindow::initialize(FAR const char *name, // Create the main window - if (!createMainWindow(&winsize, pos)) + if (!createMainWindow(&winsize, pos, flags)) { twmerr("ERROR: createMainWindow() failed\n"); cleanup(); @@ -662,10 +662,12 @@ bool CWindow::event(FAR struct SEventMsg *eventmsg) * * @param winsize The initial window size * @param winpos The initial window position + * @param flags Toolbar customizations see WFLAGS_NO_* definitions */ bool CWindow::createMainWindow(FAR const nxgl_size_s *winsize, - FAR const nxgl_point_s *winpos) + FAR const nxgl_point_s *winpos, + uint8_t flags) { // 1. Get the server instance. m_twm4nx inherits from NXWidgets::CNXServer // so we all ready have the server instance. @@ -678,7 +680,13 @@ bool CWindow::createMainWindow(FAR const nxgl_size_s *winsize, // 4. Create the window - m_nxWin = m_twm4nx->createFramedWindow(control, NXBE_WINDOW_RAMBACKED); + uint8_t cflags = NXBE_WINDOW_RAMBACKED; + if (WFLAGS_IS_HIDDEN_WINDOW(flags)) + { + cflags |= NXBE_WINDOW_HIDDEN; + } + + m_nxWin = m_twm4nx->createFramedWindow(control, cflags); if (m_nxWin == (FAR NXWidgets::CNxTkWindow *)0) { delete control; diff --git a/include/graphics/twm4nx/cmenus.hxx b/include/graphics/twm4nx/cmenus.hxx index f7e95b263..e378917aa 100644 --- a/include/graphics/twm4nx/cmenus.hxx +++ b/include/graphics/twm4nx/cmenus.hxx @@ -176,7 +176,8 @@ namespace Twm4Nx } /** - * Create the menu window + * Create the menu window. Menu windows are always created in the + * hidden state. When the menu is selected, then it should be shown. * * @result True is returned on success */ diff --git a/include/graphics/twm4nx/cwindow.hxx b/include/graphics/twm4nx/cwindow.hxx index 57bc3558d..a475c31ff 100644 --- a/include/graphics/twm4nx/cwindow.hxx +++ b/include/graphics/twm4nx/cwindow.hxx @@ -87,6 +87,7 @@ #define NO_TOOLBAR (NTOOLBAR_BUTTONS + 0) #define ICONMGR_WINDOW (NTOOLBAR_BUTTONS + 1) +#define HIDDEN_WINDOW (NTOOLBAR_BUTTONS + 2) #define WFLAGS_NO_MENU_BUTTON (1 << MENU_BUTTON) #define WFLAGS_NO_DELETE_BUTTON (1 << DELETE_BUTTON) @@ -94,6 +95,7 @@ #define WFLAGS_NO_MINIMIZE_BUTTON (1 << MINIMIZE_BUTTON) #define WFLAGS_NO_TOOLBAR (1 << NO_TOOLBAR) #define WFLAGS_IS_ICONMGR (1 << ICONMGR_WINDOW) +#define WFLAGS_HIDDEN_WINDOW (1 << HIDDEN_WINDOW) #define WFLAGS_HAVE_MENU_BUTTON(f) (((f) & WFLAGS_NO_MENU_BUTTON) == 0) #define WFLAGS_HAVE_DELETE_BUTTON(f) (((f) & WFLAGS_NO_DELETE_BUTTON) == 0) @@ -101,6 +103,7 @@ #define WFLAGS_HAVE_MINIMIZE_BUTTON(f) (((f) & WFLAGS_NO_MINIMIZE_BUTTON) == 0) #define WFLAGS_HAVE_TOOLBAR(f) (((f) & WFLAGS_NO_TOOLBAR) == 0) #define WFLAGS_IS_ICONMGR_WINDOW(f) (((f) & WFLAGS_IS_ICONMGR) != 0) +#define WFLAGS_IS_HIDDEN_WINDOW(f) (((f) & WFLAGS_HIDDEN_WINDOW) != 0) ///////////////////////////////////////////////////////////////////////////// // Implementation Classes @@ -172,10 +175,12 @@ namespace Twm4Nx * * @param winsize The initial window size * @param winpos The initial window position + * @param flags Toolbar customizations see WFLAGS_NO_* definitions */ bool createMainWindow(FAR const nxgl_size_s *winsize, - FAR const nxgl_point_s *winpos); + FAR const nxgl_point_s *winpos, + uint8_t flags); /** * Calculate the height of the tool bar