apps/graphics/twm4nx: In order for widgets too draw the correct window or toolbar, it is necessary to get the CWidgetControl instance from the window we want to use, not to create a new instance.

This commit is contained in:
Gregory Nutt 2019-04-26 14:25:30 -06:00
parent fe0954cd62
commit ba58654955
3 changed files with 30 additions and 28 deletions

View File

@ -524,16 +524,6 @@ bool CIconMgr::createWindow(FAR const char *prefix)
bool CIconMgr::createButtonArray(void)
{
// Create a Widget control instance for the window using the default style
// for now. CWindowEvent derives from CWidgetControl.
// REVISIT: Create the style, using the selected colors.
FAR CWindowEvent *control = new CWindowEvent(m_twm4nx);
if (control == (FAR CWindowEvent *)0)
{
return false;
}
// Get the width of the window
struct nxgl_size_s windowSize;
@ -557,6 +547,17 @@ bool CIconMgr::createButtonArray(void)
nxgl_coord_t buttonWidth = windowSize.w / m_maxColumns;
nxgl_coord_t buttonHeight = windowSize.w / nrows;
// Get the Widget control instance from the Icon Manager window. This
// will force all widget drawing to go to the Icon Manager window.
FAR NXWidgets:: CWidgetControl *control = m_window->getWidgetControl();
if (control == (FAR NXWidgets:: CWidgetControl *)0)
{
// Should not fail
return false;
}
// Now we have enough information to create the button array
m_buttons = new NXWidgets::CButtonArray(control,
@ -566,7 +567,6 @@ bool CIconMgr::createButtonArray(void)
if (m_buttons == (FAR NXWidgets::CButtonArray *)0)
{
gerr("ERROR: Failed to get window size\n");
delete control;
return false;
}

View File

@ -628,17 +628,18 @@ bool CMenus::setMenuWindowPosition(FAR struct nxgl_point_s *framePos)
bool CMenus::createMenuListBox(void)
{
// Get the Widget control instance from the menu window. This
// will force all widget drawing to go to the Icon Manager window.
FAR NXWidgets:: CWidgetControl *control = m_menuWindow->getWidgetControl();
if (control == (FAR NXWidgets:: CWidgetControl *)0)
{
// Should not fail
return false;
}
// Create the menu list box
// 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);
// 4. Create the menu list box
struct nxgl_point_s pos;
pos.x = 0;
@ -653,7 +654,6 @@ bool CMenus::createMenuListBox(void)
if (m_menuListBox == (FAR NXWidgets::CListBox *)0)
{
gerr("ERROR: Failed to instantiate list box\n");
delete control;
return false;
}

View File

@ -843,7 +843,8 @@ bool CWindow::createToolbarButtons(void)
nxgl_coord_t w = 1;
nxgl_coord_t h = 1;
// Get the toolbar CWdigetControl instance
// Get the toolbar CWdigetControl instance. This will force all
// widget drawing to go to the toolbar.
NXWidgets::CWidgetControl *control = m_toolbar->getWidgetControl();
@ -962,13 +963,14 @@ bool CWindow::createToolbarTitle(FAR const char *name)
titlePos.x = m_tbLeftX + CONFIG_TWM4NX_FRAME_VSPACING;
titlePos.y = 0;
// Create a Widget control instance for the window using the default style
// for now. CWindowEvent derives from CWidgetControl.
// REVISIT: Create the style, using the selected colors.
// Get the Widget control instance from the toolbar window. This
// will force all widget drawing to go to the toolbar.
FAR CWindowEvent *control = new CWindowEvent(m_twm4nx);
if (control == (FAR CWindowEvent *)0)
FAR NXWidgets:: CWidgetControl *control = m_toolbar->getWidgetControl();
if (control == (FAR NXWidgets:: CWidgetControl *)0)
{
// Should not fail
return false;
}