diff --git a/graphics/twm4nx/src/cmenus.cxx b/graphics/twm4nx/src/cmenus.cxx index ea8d77cf8..5971d12fb 100644 --- a/graphics/twm4nx/src/cmenus.cxx +++ b/graphics/twm4nx/src/cmenus.cxx @@ -75,6 +75,22 @@ #include "graphics/twm4nx/twm4nx_widgetevents.hxx" #include "graphics/twm4nx/cmenus.hxx" +//////////////////////////////////////////////////////////////////////////// +// Pre-processor Definitions +///////////////////////////////////////////////////////////////////////////// + +// Window flags: +// +// WFLAGS_NO_MENU_BUTTON: No menu buttons on menus +// WFLAGS_NO_DELETE_BUTTON: Menus cannot be deleted in this manner. +// WFLAGS_NO_RESIZE_BUTTON: Menus cannot be resized +// WFLAGS_HIDDEN_WINDOW: Menu windows are always created in the +// hidden state. When the menu is selected, +// then it should be shown. + +#define MENU_WINDOW_FLAGS (WFLAGS_NO_MENU_BUTTON | WFLAGS_NO_DELETE_BUTTON | \ + WFLAGS_NO_RESIZE_BUTTON | WFLAGS_HIDDEN_WINDOW) + //////////////////////////////////////////////////////////////////////////// // Class Implementations ///////////////////////////////////////////////////////////////////////////// @@ -106,11 +122,11 @@ CMenus::CMenus(CTwm4Nx *twm4nx) // Windows - m_menuWindow = (FAR NXWidgets::CNxTkWindow *)0; // The menu window + m_menuWindow = (FAR CWindow *)0; // The menu window // Widgets - m_menuListBox = (FAR NXWidgets::CListBox *)0; //The menu list box + m_menuListBox = (FAR NXWidgets::CListBox *)0; // The menu list box } /** @@ -215,12 +231,12 @@ bool CMenus::addMenuItem(FAR NXWidgets::CNxString &text, FAR CMenus *subMenu, } struct nxgl_size_s menuSize; - m_menuWindow->getSize(&menuSize); + m_menuWindow->getWindowSize(&menuSize); if (width > menuSize.w) { menuSize.w = width; - m_menuWindow->setSize(&menuSize); + m_menuWindow->setWindowSize(&menuSize); } if (subMenu != NULL) @@ -409,7 +425,7 @@ void CMenus::identify(FAR CWindow *cwin) // Make sure that the window is on the display struct nxgl_point_s menuPos; - if (m_menuWindow->getPosition(&menuPos)) + if (m_menuWindow->getWindowPosition(&menuPos)) { menuPos.x -= (menuSize.w / 2); menuPos.y -= (menuSize.h / 3); @@ -450,15 +466,15 @@ void CMenus::identify(FAR CWindow *cwin) // Set the new window size and position - if (!m_menuWindow->setPosition(&menuPos) || - !m_menuWindow->setSize(&menuSize)) + if (!m_menuWindow->setWindowPosition(&menuPos) || + !m_menuWindow->setWindowSize(&menuSize)) { return; } // Raise it to the top of the hiearchy - m_menuWindow->raise(); + m_menuWindow->raiseWindow(); } /** @@ -471,57 +487,30 @@ void CMenus::identify(FAR CWindow *cwin) bool CMenus::createMenuWindow(void) { // Create the menu window - // 1. Get the server instance. m_twm4nx inherits from NXWidgets::CNXServer - // so we all ready have the server instance. - // 2. Create the style, using the selected colors (REVISIT) - // 3. Create a Widget control instance for the window using the default - // style for now. CWindowEvent derives from CWidgetControl. - - FAR CWindowEvent *control = new CWindowEvent(m_twm4nx, (FAR void *)this); - - // 4. Create the menu window. Menu windows are always created in the - // hidden state. When the menu is selected, then it should be shown. - - uint8_t cflags = (NXBE_WINDOW_RAMBACKED | NXBE_WINDOW_HIDDEN); - m_menuWindow = m_twm4nx->createFramedWindow(control, cflags); - if (m_menuWindow == (FAR NXWidgets::CNxTkWindow *)0) + m_menuWindow = new CWindow(m_twm4nx); + if (m_menuWindow == (FAR CWindow *)0) { - delete control; + gerr("ERRR: Failed to instantiate menu window\n"); return false; } - // 5. Open and initialize the menu window + // Initialize the menu window - bool success = m_menuWindow->open(); - if (!success) + struct nxgl_point_s pos; + pos.x = 0; + pos.y = 0; + + struct nxgl_size_s size; + getMenuWindowSize(size); + + if (!m_menuWindow->initialize(m_menuName, &pos, &size, + (FAR const struct NXWidgets::SRlePaletteBitmap *)0, + (FAR CIconMgr *)0, MENU_WINDOW_FLAGS)) { + gerr("ERRR: Failed to initialize menu window\n"); delete m_menuWindow; - m_menuWindow = (FAR NXWidgets::CNxTkWindow *)0; - return false; - } - - // 6. Set the initial window size - - if (!setMenuWindowSize()) - { - delete m_menuWindow; - m_menuWindow = (FAR NXWidgets::CNxTkWindow *)0; - return false; - } - - // 7. Set the initial window position - - struct nxgl_point_s pos = - { - .x = 0, - .y = 0 - }; - - if (!m_menuWindow->setPosition(&pos)) - { - delete m_menuWindow; - m_menuWindow = (FAR NXWidgets::CNxTkWindow *)0; + m_menuWindow = (FAR CWindow *)0; return false; } @@ -529,21 +518,22 @@ bool CMenus::createMenuWindow(void) } /** - * Update the menu window size + * Calculate the optimal menu window size * * @result True is returned on success */ -bool CMenus::setMenuWindowSize(void) +void CMenus::getMenuWindowSize(FAR struct nxgl_size_s &size) { CFonts *fonts = m_twm4nx->getFonts(); FAR NXWidgets::CNxFont *menuFont = fonts->getMenuFont(); m_entryHeight = menuFont->getHeight() + 4; - // Get the length of the title + // Get the minimum width of the toolbar - nxgl_coord_t maxstring = menuFont->getStringWidth(m_menuName); + nxgl_coord_t maxWidth = minimumToolbarWidth(m_twm4nx, m_menuName, + MENU_WINDOW_FLAGS); // Compare that to the length of the longest item string in in the menu @@ -552,16 +542,16 @@ bool CMenus::setMenuWindowSize(void) curr = curr->flink) { nxgl_coord_t stringlen = menuFont->getStringWidth(curr->text); - if (stringlen > maxstring) + if (stringlen > maxWidth) { - maxstring = stringlen; + maxWidth = stringlen; } } // Lets first size the window accordingly struct nxgl_size_s menuSize; - menuSize.w = maxstring + 10; + menuSize.w = maxWidth + 10; unsigned int nMenuItems = m_nMenuItems > 0 ? m_nMenuItems : 1; menuSize.h = nMenuItems * m_entryHeight; @@ -591,9 +581,23 @@ bool CMenus::setMenuWindowSize(void) // Set the new menu window size - frameToMenuSize(&frameSize, &menuSize); + frameToMenuSize(&frameSize, &size); +} - if (!m_menuWindow->setSize(&menuSize)) +/** + * Update the menu window size + * + * @result True is returned on success + */ + +bool CMenus::setMenuWindowSize(void) +{ + // Get the optimal menu window size + + struct nxgl_size_s menuSize; + getMenuWindowSize(menuSize); + + if (!m_menuWindow->setWindowSize(&menuSize)) { twmerr("ERROR: Failed to set window size\n"); return false; @@ -614,7 +618,7 @@ bool CMenus::setMenuWindowPosition(FAR struct nxgl_point_s *framePos) { struct nxgl_point_s menuPos; frameToMenuPos(framePos, &menuPos); - return m_menuWindow->setPosition(&menuPos); + return m_menuWindow->setWindowPosition(&menuPos); } /** @@ -639,12 +643,12 @@ bool CMenus::createMenuListBox(void) // Create the menu list box struct nxgl_point_s pos; - pos.x = 0; - pos.y = 0; + pos.x = 0; + pos.y = 0; struct nxgl_size_s size; - pos.x = 0; - pos.y = 0; + size.w = 0; + size.h = 0; m_menuListBox = new NXWidgets::CListBox(control, pos.x, pos.y, size.w, size.h); @@ -780,11 +784,8 @@ bool CMenus::popUpMenu(FAR struct nxgl_point_s *pos) struct nxgl_size_s displaySize; m_twm4nx->getDisplaySize(&displaySize); - struct nxgl_size_s menuSize; - m_menuWindow->getSize(&menuSize); - struct nxgl_size_s frameSize; - menuToFrameSize(&menuSize, &frameSize); + m_menuWindow->getFrameSize(&frameSize); if (pos->x + frameSize.w > displaySize.w) { @@ -910,10 +911,10 @@ void CMenus::cleanup(void) // Free the menu window - if (m_menuWindow != (FAR NXWidgets::CNxTkWindow *)0) + if (m_menuWindow != (FAR CWindow *)0) { delete m_menuWindow; - m_menuWindow = (FAR NXWidgets::CNxTkWindow *)0; + m_menuWindow = (FAR CWindow *)0; } // Free each menu item diff --git a/graphics/twm4nx/src/cwindow.cxx b/graphics/twm4nx/src/cwindow.cxx index df4dbcd65..ce944741f 100644 --- a/graphics/twm4nx/src/cwindow.cxx +++ b/graphics/twm4nx/src/cwindow.cxx @@ -146,8 +146,8 @@ CWindow::CWindow(CTwm4Nx *twm4nx) m_tbTitle = (FAR NXWidgets::CLabel *)0; m_tbHeight = 0; // Height of the toolbar - m_tbLeftX = 0; // Temporaries - m_tbRightX = 0; + m_tbLeftX = 0; // Offset to end of left buttons + m_tbRightX = 0; // Offset to start of right buttons m_tbFlags = 0; // No customizations // Icons/Icon Manager @@ -187,14 +187,14 @@ CWindow::~CWindow(void) * @param name The the name of the window (and its icon) * @param pos The initialize position of the window * @param size The initial size of the window - * @param sbitmap The Icon bitmap image + * @param sbitmap The Icon bitmap image. null if no icon. * @param iconMgr Pointer to icon manager instance * @param flags Toolbar customizations see WFLAGS_NO_* definition * @return True if the window was successfully initialize; false on * any failure, */ -bool CWindow::initialize(FAR const char *name, +bool CWindow::initialize(FAR const NXWidgets::CNxString &name, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_size_s *size, FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap, @@ -214,7 +214,7 @@ bool CWindow::initialize(FAR const char *name, m_iconMgr = iconMgr; - if (name == (FAR const char *)0) + if (name.getLength() == 0) { m_name.setText(GNoName); } @@ -300,51 +300,86 @@ bool CWindow::initialize(FAR const char *name, } } - // Create the icon image instance + // Create and initialize the icon widget if a bitmap was provided - m_iconBitMap = new NXWidgets::CRlePaletteBitmap(sbitmap); - if (m_iconBitMap == (NXWidgets::CRlePaletteBitmap *)0) + if (sbitmap != (FAR const struct NXWidgets::SRlePaletteBitmap *)0) { - twmerr("ERROR: Failed to create icon image\n"); - cleanup(); - return false; + // Create the icon image instance + + m_iconBitMap = new NXWidgets::CRlePaletteBitmap(sbitmap); + if (m_iconBitMap == (NXWidgets::CRlePaletteBitmap *)0) + { + twmerr("ERROR: Failed to create icon image\n"); + cleanup(); + return false; + } + + // Get the widget control instance from the background. This is needed + // to force the icon widgets to be draw on the background + + FAR CBackground *background = m_twm4nx->getBackground(); + FAR NXWidgets::CWidgetControl *control = background->getWidgetControl(); + + m_iconWidget = new CIconWidget(m_twm4nx, control, pos->x, pos->y); + if (m_iconWidget == (FAR CIconWidget *)0) + { + twmerr("ERROR: Failed to create the icon widget\n"); + cleanup(); + return false; + } + + if (!m_iconWidget->initialize(this, m_iconBitMap, m_name)) + { + twmerr("ERROR: Failed to initialize the icon widget\n"); + cleanup(); + return false; + } + + // Initialize the icon widget + + m_iconWidget->disable(); + m_iconWidget->disableDrawing(); + m_iconWidget->setRaisesEvents(true); } - // Get the widget control instance from the background. This is needed - // to force the icon widgets to be draw on the background - - FAR CBackground *background = m_twm4nx->getBackground(); - FAR NXWidgets::CWidgetControl *control = background->getWidgetControl(); - - // Create and initialize the icon widget - - m_iconWidget = new CIconWidget(m_twm4nx, control, pos->x, pos->y); - if (m_iconWidget == (FAR CIconWidget *)0) - { - twmerr("ERROR: Failed to create the icon widget\n"); - cleanup(); - return false; - } - - if (!m_iconWidget->initialize(this, m_iconBitMap, m_name)) - { - twmerr("ERROR: Failed to initialize the icon widget\n"); - cleanup(); - return false; - } - - // Initialize the icon widget - - m_iconWidget->disable(); - m_iconWidget->disableDrawing(); - m_iconWidget->setRaisesEvents(true); - // Re-enable toolbar widgets enableToolbarWidgets(); return true; } +/** + * CWindow Initializer (unlike the constructor, this may fail) + * + * @param name The the name of the window (and its icon) + * @param pos The initialize position of the window + * @param size The initial size of the window + * @param sbitmap The Icon bitmap image. null if no icon. + * @param iconMgr Pointer to icon manager instance + * @param flags Toolbar customizations see WFLAGS_NO_* definition + * @return True if the window was successfully initialize; false on + * any failure, + */ + +bool CWindow::initialize(FAR const char *name, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_size_s *size, + FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap, + FAR CIconMgr *iconMgr, uint8_t flags) +{ + NXWidgets::CNxString nxname; + if (name == (FAR const char *)0) + { + nxname.setText(GNoName); + } + else + { + nxname.setText(name); + } + + return initialize(nxname, pos, size, sbitmap, iconMgr, flags); +} + /** * Get the raw window size (including toolbar and frame) * @@ -487,12 +522,15 @@ void CWindow::iconify(void) m_iconified = true; m_nxWin->hide(); - // Enable and redraw the icon widget and lower the main window + if (m_iconWidget != (FAR CIconWidget *)0) + { + // Enable and redraw the icon widget and lower the main window - m_iconOn = true; - m_iconWidget->enable(); - m_iconWidget->enableDrawing(); - m_iconWidget->redraw(); + m_iconOn = true; + m_iconWidget->enable(); + m_iconWidget->enableDrawing(); + m_iconWidget->redraw(); + } m_nxWin->synchronize(); } @@ -509,28 +547,31 @@ void CWindow::deIconify(void) m_iconified = false; m_nxWin->show(); - // Disable the icon widget - - m_iconOn = false; - m_iconWidget->disableDrawing(); - m_iconWidget->disable(); - - // Redraw the background window in the rectangle previously occupied - // by the widget. - - struct nxgl_size_s size; - m_iconWidget->getSize(size); - - struct nxgl_rect_s rect; - m_iconWidget->getPos(rect.pt1); - - rect.pt2.x = rect.pt1.x + size.w - 1; - rect.pt2.y = rect.pt1.y + size.h - 1; - - FAR CBackground *backgd = m_twm4nx->getBackground(); - if (!backgd->redrawBackgroundWindow(&rect, false)) + if (m_iconWidget != (FAR CIconWidget *)0) { - gerr("ERROR: redrawBackgroundWindow() failed\n"); + // Disable the icon widget + + m_iconOn = false; + m_iconWidget->disableDrawing(); + m_iconWidget->disable(); + + // Redraw the background window in the rectangle previously + // occupied by the widget. + + struct nxgl_size_s size; + m_iconWidget->getSize(size); + + struct nxgl_rect_s rect; + m_iconWidget->getPos(rect.pt1); + + rect.pt2.x = rect.pt1.x + size.w - 1; + rect.pt2.y = rect.pt1.y + size.h - 1; + + FAR CBackground *backgd = m_twm4nx->getBackground(); + if (!backgd->redrawBackgroundWindow(&rect, false)) + { + gerr("ERROR: redrawBackgroundWindow() failed\n"); + } } // Make sure everything is in sync @@ -726,7 +767,7 @@ bool CWindow::createMainWindow(FAR const nxgl_size_s *winsize, * Calculate the height of the tool bar */ -bool CWindow::getToolbarHeight(FAR const char *name) +bool CWindow::getToolbarHeight(FAR const NXWidgets::CNxString &name) { // The tool bar height is the largest of the toolbar button heights or the // title text font @@ -734,7 +775,7 @@ bool CWindow::getToolbarHeight(FAR const char *name) // Check if there is a title. If so, get the font height. m_tbHeight = 0; - if (name != (FAR const char *)0) + if (name.getLength() != 0) { FAR CFonts *fonts = m_twm4nx->getFonts(); FAR NXWidgets::CNxFont *titleFont = fonts->getTitleFont(); @@ -752,9 +793,9 @@ bool CWindow::getToolbarHeight(FAR const char *name) } } - // Plus somoe lines for good separation + // Plus some lines for good separation - m_tbHeight += CONFIG_TWM4NX_FRAME_VSPACING; + m_tbHeight += CONFIG_TWM4NX_TOOLBAR_VSPACING; return true; } @@ -830,7 +871,17 @@ bool CWindow::updateToolbarLayout(void) // Reposition all right buttons. Change the width of the // toolbar does not effect the left side spacing. - m_tbRightX = 0; + struct nxgl_size_s winsize; + if (!getWindowSize(&winsize)) + { + return false; + } + + // Create the title bar windows + // Set up the toolbar horizonal spacing + + m_tbRightX = winsize.w; + for (int btindex = 0; btindex < NTOOLBAR_BUTTONS; btindex++) { if (m_tbButtons[btindex] != (FAR NXWidgets::CImage *)0 && @@ -870,7 +921,7 @@ bool CWindow::updateToolbarLayout(void) struct nxgl_size_s titleSize; titleSize.h = m_tbHeight; - titleSize.w = m_tbRightX - m_tbLeftX - CONFIG_TWM4NX_FRAME_VSPACING + 1; + titleSize.w = m_tbRightX - m_tbLeftX - CONFIG_TWM4NX_TOOLBAR_HSPACING + 1; bool success = m_tbTitle->resize(titleSize.w, titleSize.h); enableToolbarWidgets(); @@ -1074,11 +1125,11 @@ bool CWindow::createToolbarButtons(uint8_t flags) * @param name The name to use for the toolbar title */ -bool CWindow::createToolbarTitle(FAR const char *name) +bool CWindow::createToolbarTitle(FAR const NXWidgets::CNxString &name) { // Is there a title? - if (name == (FAR const char *)0) + if (name.getLength() == 0) { // No.. then there is nothing to be done here @@ -1646,3 +1697,49 @@ void CWindow::cleanup(void) m_iconBitMap = (FAR NXWidgets::CRlePaletteBitmap *)0; } } + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +namespace Twm4Nx +{ + /** + * Return the minimum width of a toolbar window. If the window is + * resized smaller than this width, then the items in the toolbar will + * overlap. + * + * @param twm4nx The Twm4Nx session object + * @param title The window title string + * @param flags Window toolbar properties + * @return The minimum recommended window width. + */ + + nxgl_coord_t minimumToolbarWidth(FAR CTwm4Nx *twm4nx, + FAR const NXWidgets::CNxString &title, + uint8_t flags) + { + // Get the width of the title string + + FAR CFonts *fonts = twm4nx->getFonts(); + FAR NXWidgets::CNxFont *titleFont = fonts->getTitleFont(); + + nxgl_coord_t tbWidth = titleFont->getStringWidth(title) + + CONFIG_TWM4NX_TOOLBAR_HSPACING; + + for (int btindex = 0; btindex < NTOOLBAR_BUTTONS; btindex++) + { + // Check if this button is omitted by toolbar customizations + + if ((flags & (1 << btindex)) == 0) + { + // Add the button image width + + tbWidth += GToolBarInfo[btindex].bitmap->width + + CONFIG_TWM4NX_TOOLBAR_HSPACING; + } + } + + return tbWidth; + } +} diff --git a/include/graphics/twm4nx/cmenus.hxx b/include/graphics/twm4nx/cmenus.hxx index 3ae7bb0db..f873a419f 100644 --- a/include/graphics/twm4nx/cmenus.hxx +++ b/include/graphics/twm4nx/cmenus.hxx @@ -54,6 +54,7 @@ #include "graphics/nxwidgets/cwidgeteventargs.hxx" #include "graphics/nxwidgets/cnxtkwindow.hxx" +#include "graphics/twm4nx/cwindow.hxx" #include "graphics/twm4nx/ctwm4nxevent.hxx" ///////////////////////////////////////////////////////////////////////////// @@ -92,7 +93,6 @@ namespace NXWidgets namespace Twm4Nx { struct SEventMsg; // Forward referernce - class CWindow; // Forward reference class CMenus; // Forward reference struct SMenuItem @@ -112,7 +112,7 @@ namespace Twm4Nx CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */ mqd_t m_eventq; /**< NxWidget event message queue */ - FAR NXWidgets::CNxTkWindow *m_menuWindow; /**< The menu window */ + FAR CWindow *m_menuWindow; /**< The menu window */ FAR CMenus *m_popUpMenu; /**< Pop-up menu */ FAR NXWidgets::CListBox *m_menuListBox; /**< The menu list box */ FAR struct SMenuItem *m_activeItem; /**< The active menu item */ @@ -185,6 +185,14 @@ namespace Twm4Nx bool createMenuWindow(void); + /** + * Calculate the optimal menu window size + * + * @result True is returned on success + */ + + void getMenuWindowSize(FAR struct nxgl_size_s &size); + /** * Update the menu window size * @@ -213,7 +221,7 @@ namespace Twm4Nx inline bool raiseMenuWindow() { - return m_menuWindow->raise(); + return m_menuWindow->raiseWindow(); } /** @@ -293,7 +301,6 @@ namespace Twm4Nx * Return true if the main menu is currently being displayed */ - inline bool isVisible(void) { return m_visible; @@ -309,7 +316,7 @@ namespace Twm4Nx { if (!m_visible) { - m_visible = m_menuWindow->show(); + m_visible = m_menuWindow->showWindow(); } return m_visible; @@ -325,7 +332,7 @@ namespace Twm4Nx { if (m_visible) { - m_visible = !m_menuWindow->hide(); + m_visible = !m_menuWindow->hideWindow(); } return !m_visible; diff --git a/include/graphics/twm4nx/cwindow.hxx b/include/graphics/twm4nx/cwindow.hxx index c11cdf887..30c498298 100644 --- a/include/graphics/twm4nx/cwindow.hxx +++ b/include/graphics/twm4nx/cwindow.hxx @@ -190,7 +190,7 @@ namespace Twm4Nx * Calculate the height of the tool bar */ - bool getToolbarHeight(FAR const char *name); + bool getToolbarHeight(FAR const NXWidgets::CNxString &name); /** * Create all toolbar buttons @@ -208,7 +208,7 @@ namespace Twm4Nx * @param name The name to use for the toolbar title */ - bool createToolbarTitle(FAR const char *name); + bool createToolbarTitle(FAR const NXWidgets::CNxString &name); /** * Create the tool bar @@ -390,13 +390,19 @@ namespace Twm4Nx * @param name The the name of the window (and its icon) * @param pos The initial position of the window * @param size The initial size of the window - * @param sbitmap The Icon bitmap image + * @param sbitmap The Icon bitmap image. null if no icon. * @param iconMgr Pointer to icon manager instance * @param flags Toolbar customizations see WFLAGS_NO_* definitions * @return True if the window was successfully initialize; false on * any failure, */ + bool initialize(FAR const NXWidgets::CNxString &name, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_size_s *size, + FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap, + FAR CIconMgr *iconMgr, uint8_t flags); + bool initialize(FAR const char *name, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_size_s *size, @@ -464,6 +470,18 @@ namespace Twm4Nx return m_nxWin->getSize(size); } + /** + * Set the size of the primary window. This is useful only + * for applications that need to control the drawing area. + * + * @param size New primary window size + */ + + inline bool setWindowSize(FAR const struct nxgl_size_s *size) + { + return m_nxWin->setSize(size); + } + /** * Get the position of the primary window. This is useful only * for applications that need to know about the drawing area. @@ -477,15 +495,14 @@ namespace Twm4Nx } /** - * Set the size of the primary window. This is useful only - * for oapplications that need to control the drawing area. + * Set the position of the primary window. * - * @param size New primary window size + * @param pos The new primary window position */ - inline bool setWindowSize(FAR const struct nxgl_size_s *size) + inline bool setWindowPosition(FAR const struct nxgl_point_s *pos) { - return m_nxWin->setSize(size); + return m_nxWin->setPosition(pos); } /** @@ -662,7 +679,10 @@ namespace Twm4Nx inline void getIconWidgetSize(FAR struct nxgl_size_s &size) { - m_iconWidget->getSize(size); + if (m_iconWidget != (FAR CIconWidget *)0) + { + m_iconWidget->getSize(size); + } } /** @@ -675,7 +695,10 @@ namespace Twm4Nx inline void getIconWidgetPosition(FAR struct nxgl_point_s &pos) { - m_iconWidget->getPos(pos); + if (m_iconWidget != (FAR CIconWidget *)0) + { + m_iconWidget->getPos(pos); + } } /** @@ -688,7 +711,13 @@ namespace Twm4Nx inline bool setIconWindowPosition(FAR const struct nxgl_point_s &pos) { - return m_iconWidget->moveTo(pos.x, pos.y); + bool success = false; + if (m_iconWidget != (FAR CIconWidget *)0) + { + success = m_iconWidget->moveTo(pos.x, pos.y); + } + + return success; } /** @@ -697,12 +726,15 @@ namespace Twm4Nx inline void redrawIcon(void) { - // Make sure that the icon is properly enabled, then redraw it + if (m_iconWidget != (FAR CIconWidget *)0) + { + // Make sure that the icon is properly enabled, then redraw it - m_iconWidget->enable(); - m_iconWidget->enableDrawing(); - m_iconWidget->setRaisesEvents(true); - m_iconWidget->redraw(); + m_iconWidget->enable(); + m_iconWidget->enableDrawing(); + m_iconWidget->setRaisesEvents(true); + m_iconWidget->redraw(); + } } /** @@ -752,6 +784,25 @@ namespace Twm4Nx bool event(FAR struct SEventMsg *eventmsg); }; + + /////////////////////////////////////////////////////////////////////////// + // Public Function Prototypes + /////////////////////////////////////////////////////////////////////////// + + /** + * Return the minimum width of the toolbar window. If the window is + * resized smaller than this width, then the items in the toolbar will + * overlap. + * + * @param twm4nx The Twm4Nx session object + * @param title The window title string + * @param flags Window toolbar properties + * @return The minimum recommended window width. + */ + + nxgl_coord_t minimumToolbarWidth(FAR CTwm4Nx *twm4nx, + FAR const NXWidgets::CNxString &title, + uint8_t flags); } #endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_CWINDOW_HXX diff --git a/include/graphics/twm4nx/twm4nx_config.hxx b/include/graphics/twm4nx/twm4nx_config.hxx index 98b8fa602..35c5b16b0 100644 --- a/include/graphics/twm4nx/twm4nx_config.hxx +++ b/include/graphics/twm4nx/twm4nx_config.hxx @@ -149,8 +149,8 @@ # define CONFIG_TWM4NX_TOOLBAR_HSPACING 2 #endif -#ifndef CONFIG_TWM4NX_FRAME_VSPACING -# define CONFIG_TWM4NX_FRAME_VSPACING 2 +#ifndef CONFIG_TWM4NX_TOOLBAR_VSPACING +# define CONFIG_TWM4NX_TOOLBAR_VSPACING 2 #endif #ifndef CONFIG_TWM4NX_BUTTON_INDENT