Squashed commit of the following:

apps/graphics/twm4nx:  Remove some unnecessary twiddling with widget settings.

    apps/graphics/twm4nx:  Correct an error in how menu windows are created.

    apps/graphics/twm4nx:  Use button array vs list box for menus.
This commit is contained in:
Gregory Nutt 2019-05-10 09:20:43 -06:00
parent 71de56bca8
commit 28b4be1913
5 changed files with 246 additions and 352 deletions

View File

@ -148,7 +148,8 @@ CWidgetControl *CNxTkWindow::getWidgetControl(void) const
* @param height Height of the toolbar * @param height Height of the toolbar
*/ */
CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height, CWidgetControl *widgetControl) CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height,
CWidgetControl *widgetControl)
{ {
if (m_hNxTkWindow && !m_toolbar) if (m_hNxTkWindow && !m_toolbar)
{ {
@ -194,6 +195,7 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height, CWidgetControl *widget
{ {
delete allocControl; delete allocControl;
} }
return (CNxToolbar *)0; return (CNxToolbar *)0;
} }
@ -209,6 +211,7 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height, CWidgetControl *widget
{ {
delete allocControl; delete allocControl;
} }
return (CNxToolbar *)0; return (CNxToolbar *)0;
} }
@ -247,7 +250,8 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height, CWidgetControl *widget
struct nxgl_size_s toolbarSize; struct nxgl_size_s toolbarSize;
nxgl_rectsize(&toolbarSize, &toolbarBounds); nxgl_rectsize(&toolbarSize, &toolbarBounds);
// Get the toolbar position in display coordinates by adding the window position // Get the toolbar position in display coordinates by adding the
// window position
struct nxgl_point_s toolbarPos; struct nxgl_point_s toolbarPos;
nxgl_vectoradd(&toolbarPos, &toolbarBounds.pt1, &windowPos); nxgl_vectoradd(&toolbarPos, &toolbarBounds.pt1, &windowPos);

View File

@ -58,7 +58,7 @@
#include "graphics/nxwidgets/cnxstring.hxx" #include "graphics/nxwidgets/cnxstring.hxx"
#include "graphics/nxwidgets/cnxfont.hxx" #include "graphics/nxwidgets/cnxfont.hxx"
#include "graphics/nxwidgets/clistbox.hxx" #include "graphics/nxwidgets/cbuttonarray.hxx"
#include "graphics/nxwidgets/cwidgeteventargs.hxx" #include "graphics/nxwidgets/cwidgeteventargs.hxx"
#include "graphics/twm4nx/twm4nx_config.hxx" #include "graphics/twm4nx/twm4nx_config.hxx"
@ -115,12 +115,8 @@ CMenus::CMenus(CTwm4Nx *twm4nx)
m_menuHead = (FAR struct SMenuItem *)0; // No menu items m_menuHead = (FAR struct SMenuItem *)0; // No menu items
m_menuTail = (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 m_nMenuItems = 0; // No menu items yet
m_menuDepth = 0; // No menus up
m_entryHeight = 0; // Menu entry height m_entryHeight = 0; // Menu entry height
m_menuPull = false; // No pull right entry
// Windows // Windows
@ -128,7 +124,7 @@ CMenus::CMenus(CTwm4Nx *twm4nx)
// Widgets // Widgets
m_menuListBox = (FAR NXWidgets::CListBox *)0; // The menu list box m_buttons = (FAR NXWidgets::CButtonArray *)0; // The menu button array
} }
/** /**
@ -175,11 +171,11 @@ bool CMenus::initialize(FAR NXWidgets::CNxString &name)
return false; return false;
} }
// Create the menu list box // Create the menu button array
if (!createMenuListBox()) if (!createMenuButtonArray())
{ {
twmerr("ERROR: Failed to create menu list box\n"); twmerr("ERROR: Failed to create menu button array\n");
cleanup(); cleanup();
return false; return false;
} }
@ -219,38 +215,13 @@ bool CMenus::addMenuItem(FAR NXWidgets::CNxString &text, FAR CMenus *subMenu,
// Save information about the menu item // Save information about the menu item
item->flink = NULL; item->flink = NULL;
item->subMenu = NULL; item->subMenu = subMenu;
item->handler = handler; item->handler = handler;
item->event = event; item->event = event;
CFonts *fonts = m_twm4nx->getFonts(); // Increment the total number of menu items
FAR NXWidgets::CNxFont *menuFont = fonts->getMenuFont();
int width = menuFont->getStringWidth(text);
if (width <= 0) int index = m_nMenuItems++;
{
width = 1;
}
struct nxgl_size_s menuSize;
m_menuWindow->getWindowSize(&menuSize);
if (width > menuSize.w)
{
menuSize.w = width;
m_menuWindow->setWindowSize(&menuSize);
}
if (subMenu != NULL)
{
item->subMenu = subMenu;
m_menuPull = true;
}
// Save the index to this item and increment the total number of menu
// items
item->index = m_nMenuItems++;
// Add the menu item to the tail of the item list // Add the menu item to the tail of the item list
@ -268,20 +239,29 @@ bool CMenus::addMenuItem(FAR NXWidgets::CNxString &text, FAR CMenus *subMenu,
m_menuTail = item; m_menuTail = item;
item->flink = (FAR struct SMenuItem *)0; item->flink = (FAR struct SMenuItem *)0;
// Add the item text to the list box
m_menuListBox->addOption(item->text, item->index);
// Update the menu window size // Update the menu window size
setMenuWindowSize(); setMenuWindowSize();
m_menuWindow->synchronize();
// Redraw the list box // Get the updated window size
m_menuListBox->enable(); struct nxgl_size_s menuSize;
m_menuListBox->enableDrawing(); m_menuWindow->getWindowSize(&menuSize);
m_menuListBox->setRaisesEvents(true);
m_menuListBox->redraw(); // Resize the button array
nxgl_coord_t buttonHeight = menuSize.h / m_nMenuItems;
if (!m_buttons->resizeArray(1, m_nMenuItems, menuSize.w, buttonHeight))
{
twmerr("ERROR: CButtonArray::resizeArray failed\n");
return false;
}
// Add the new item text to the button array
m_buttons->setText(0, index, item->text);
return true; return true;
} }
@ -358,6 +338,15 @@ bool CMenus::event(FAR struct SEventMsg *eventmsg)
} }
break; break;
case EVENT_MENU_SUBMENU: // Sub-menu selected
{
// Bring up the sub-menu
FAR CMenus *cmenu = (FAR CMenus *)eventmsg->obj;
success = cmenu->show();
}
break;
default: default:
success = false; success = false;
break; break;
@ -477,6 +466,58 @@ void CMenus::identify(FAR CWindow *cwin)
m_menuWindow->raiseWindow(); m_menuWindow->raiseWindow();
} }
/**
* Convert the position of a menu window to the position of
* the containing frame.
*/
void CMenus::menuToFramePos(FAR const struct nxgl_point_s *menupos,
FAR struct nxgl_point_s *framepos)
{
nxgl_coord_t tbheight = m_menuWindow->getToolbarHeight();
framepos->x = menupos->x - CONFIG_NXTK_BORDERWIDTH;
framepos->y = menupos->y - tbheight - CONFIG_NXTK_BORDERWIDTH;
}
/**
* Convert the position of the containing frame to the position of
* the menu window.
*/
void CMenus::frameToMenuPos(FAR const struct nxgl_point_s *framepos,
FAR struct nxgl_point_s *menupos)
{
nxgl_coord_t tbheight = m_menuWindow->getToolbarHeight();
menupos->x = framepos->x + CONFIG_NXTK_BORDERWIDTH;
menupos->y = framepos->y + tbheight + CONFIG_NXTK_BORDERWIDTH;
}
/**
* Convert the size of a menu window to the size of the containing
* frame.
*/
void CMenus::menuToFrameSize(FAR const struct nxgl_size_s *menusize,
FAR struct nxgl_size_s *framesize)
{
nxgl_coord_t tbheight = m_menuWindow->getToolbarHeight();
framesize->w = menusize->w + 2 * CONFIG_NXTK_BORDERWIDTH;
framesize->h = menusize->h + tbheight + 2 * CONFIG_NXTK_BORDERWIDTH;
}
/**
* Convert the size of a containing frame to the size of the menu
* window.
*/
void CMenus::frameToMenuSize(FAR const struct nxgl_size_s *framesize,
FAR struct nxgl_size_s *menusize)
{
nxgl_coord_t tbheight = m_menuWindow->getToolbarHeight();
menusize->w = framesize->w - 2 * CONFIG_NXTK_BORDERWIDTH;
menusize->h = framesize->h - tbheight - 2 * CONFIG_NXTK_BORDERWIDTH;
}
/** /**
* Create the menu window. Menu windows are always created in the hidden * Create the menu window. Menu windows are always created in the hidden
* state. When the menu is selected, then it should be shown. * state. When the menu is selected, then it should be shown.
@ -488,27 +529,27 @@ bool CMenus::createMenuWindow(void)
{ {
// Create the menu window // Create the menu window
m_menuWindow = new CWindow(m_twm4nx); CWindowFactory *factory = m_twm4nx->getWindowFactory();
m_menuWindow =
factory->createWindow(m_menuName,
(FAR const struct NXWidgets::SRlePaletteBitmap *)0,
(FAR CIconMgr *)0, MENU_WINDOW_FLAGS);
if (m_menuWindow == (FAR CWindow *)0) if (m_menuWindow == (FAR CWindow *)0)
{ {
twmerr("ERRR: Failed to instantiate menu window\n"); twmerr("ERROR: Failed to create icon manager window");
return false; return false;
} }
// Initialize the menu window // Adjust the size of the window
struct nxgl_point_s pos; struct nxgl_size_s windowSize;
pos.x = 0; getMenuWindowSize(windowSize);
pos.y = 0;
struct nxgl_size_s size; if (!m_menuWindow->setWindowSize(&windowSize))
getMenuWindowSize(size);
if (!m_menuWindow->initialize(m_menuName, &pos, &size,
(FAR const struct NXWidgets::SRlePaletteBitmap *)0,
(FAR CIconMgr *)0, MENU_WINDOW_FLAGS))
{ {
twmerr("ERRR: Failed to initialize menu window\n"); twmerr("ERROR: Failed to set window size\n");
delete m_menuWindow; delete m_menuWindow;
m_menuWindow = (FAR CWindow *)0; m_menuWindow = (FAR CWindow *)0;
return false; return false;
@ -528,7 +569,7 @@ void CMenus::getMenuFrameSize(FAR struct nxgl_size_s &frameSize)
CFonts *fonts = m_twm4nx->getFonts(); CFonts *fonts = m_twm4nx->getFonts();
FAR NXWidgets::CNxFont *menuFont = fonts->getMenuFont(); FAR NXWidgets::CNxFont *menuFont = fonts->getMenuFont();
m_entryHeight = menuFont->getHeight() + 4; m_entryHeight = menuFont->getHeight() + CONFIG_TWM4NX_MENU_VSPACING;
// Get the minimum width of the toolbar // Get the minimum width of the toolbar
@ -551,16 +592,11 @@ void CMenus::getMenuFrameSize(FAR struct nxgl_size_s &frameSize)
// Lets first size the window accordingly // Lets first size the window accordingly
struct nxgl_size_s menuSize; struct nxgl_size_s menuSize;
menuSize.w = maxWidth + 10; menuSize.w = maxWidth + CONFIG_TWM4NX_MENU_HSPACING;
unsigned int nMenuItems = m_nMenuItems > 0 ? m_nMenuItems : 1; unsigned int nMenuItems = m_nMenuItems > 0 ? m_nMenuItems : 1;
menuSize.h = nMenuItems * m_entryHeight; menuSize.h = nMenuItems * m_entryHeight;
if (m_menuPull == true)
{
menuSize.w += 16;
}
// Clip to the size of the display // Clip to the size of the display
struct nxgl_size_s displaySize; struct nxgl_size_s displaySize;
@ -629,15 +665,31 @@ bool CMenus::setMenuWindowPosition(FAR struct nxgl_point_s *framePos)
} }
/** /**
* Create the menu list box * Create the menu button array
* *
* @result True is returned on success * @result True is returned on success
*/ */
bool CMenus::createMenuListBox(void) bool CMenus::createMenuButtonArray(void)
{ {
// Get the Widget control instance from the menu window. This // Get the width of the window
// will force all widget drawing to go to the Menu window.
struct nxgl_size_s windowSize;
if (!m_menuWindow->getWindowSize(&windowSize))
{
twmerr("ERROR: Failed to get window size\n");
return false;
}
// Create the button array
uint8_t nrows = m_nMenuItems > 0 ? m_nMenuItems : 1;
nxgl_coord_t buttonWidth = windowSize.w;
nxgl_coord_t buttonHeight = windowSize.h / 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_menuWindow->getWidgetControl(); FAR NXWidgets:: CWidgetControl *control = m_menuWindow->getWidgetControl();
if (control == (FAR NXWidgets:: CWidgetControl *)0) if (control == (FAR NXWidgets:: CWidgetControl *)0)
@ -647,231 +699,102 @@ bool CMenus::createMenuListBox(void)
return false; return false;
} }
// Create the menu list box // Now we have enough information to create the button array
// The button must be positioned at the upper left of the window
struct nxgl_point_s pos; m_buttons = new NXWidgets::CButtonArray(control, 0, 0, 1, nrows,
pos.x = 0; buttonWidth, buttonHeight);
pos.y = 0; if (m_buttons == (FAR NXWidgets::CButtonArray *)0)
struct nxgl_size_s size;
size.w = 0;
size.h = 0;
m_menuListBox = new NXWidgets::CListBox(control, pos.x, pos.y,
size.w, size.h);
if (m_menuListBox == (FAR NXWidgets::CListBox *)0)
{ {
twmerr("ERROR: Failed to instantiate list box\n"); twmerr("ERROR: Failed to create the button array\n");
return false; return false;
} }
// Get the menu font // Configure the button array widget
FAR CFonts *cfont = m_twm4nx->getFonts(); FAR CFonts *fonts = m_twm4nx->getFonts();
FAR NXWidgets::CNxFont *menuFont = cfont->getMenuFont(); FAR NXWidgets::CNxFont *iconManagerFont = fonts->getIconManagerFont();
// Configure the list box m_buttons->setFont(iconManagerFont);
m_buttons->setBorderless(true);
m_buttons->setRaisesEvents(true);
m_menuListBox->disable(); // Draw the button array
m_menuListBox->disableDrawing();
m_menuListBox->setRaisesEvents(false); m_buttons->enableDrawing();
m_menuListBox->setAllowMultipleSelections(false); m_buttons->redraw();
m_menuListBox->setFont(menuFont);
m_menuListBox->setBorderless(false);
// Register to get events from the mouse clicks on the image // Register to get events from the mouse clicks on the image
m_menuListBox->addWidgetEventHandler(this); m_buttons->addWidgetEventHandler(this);
return true; return true;
} }
/** /**
* Pop up a pull down menu. * Handle a widget action event, overriding the CWidgetEventHandler
* * method. This will indicate a button pre-release event.
* @param pos Location of upper left of menu frame
*/
bool CMenus::popUpMenu(FAR struct nxgl_point_s *pos)
{
// If there is already a popup menu, then delete it. We only permit
// one popup at this level.
if (m_popUpMenu != (FAR CMenus *)0)
{
delete m_popUpMenu;
}
// Create and initialize a new menu
m_popUpMenu = new CMenus(m_twm4nx);
if (m_popUpMenu == (FAR CMenus *)0)
{
twmerr("ERROR: Failed to create popup menu.\n");
return false;
}
if (!m_popUpMenu->initialize(m_activeItem->text))
{
twmerr("ERROR: Failed to intialize popup menu.\n");
delete m_popUpMenu;
m_popUpMenu = (FAR CMenus *)0;
return false;
}
NXWidgets::CNxString windowName("TWM Windows");
m_popUpMenu->addMenuItem(windowName, (FAR CMenus *)0,
(FAR CTwm4NxEvent *)0, EVENT_SYSTEM_NOP);
FAR CWindowFactory *factory = m_twm4nx->getWindowFactory();
int nWindowNames;
FAR struct SWindow *swin;
for (swin = factory->windowHead(), nWindowNames = 0;
swin != NULL; swin = swin->flink)
{
nWindowNames++;
}
if (nWindowNames != 0)
{
FAR CWindow **windowNames =
(FAR CWindow **)std::malloc(sizeof(FAR CWindow *) * nWindowNames);
if (windowNames == (FAR CWindow **)0)
{
twmerr("ERROR: Failed to allocat window name\n");
return false;
}
swin = factory->windowHead();
windowNames[0] = swin->cwin;
for (nWindowNames = 1;
swin != NULL;
swin = swin->flink, nWindowNames++)
{
FAR CWindow *tmpcwin1 = swin->cwin;
for (int i = 0; i < nWindowNames; i++)
{
FAR NXWidgets::CNxString windowName1 = tmpcwin1->getWindowName();
FAR NXWidgets::CNxString windowName2 = windowNames[i]->getWindowName();
if (windowName1.compareTo(windowName2) < 0)
{
FAR CWindow *tmpcwin2;
tmpcwin2 = tmpcwin1;
tmpcwin1 = windowNames[i];
windowNames[i] = tmpcwin2;
}
}
windowNames[nWindowNames] = tmpcwin1;
}
for (int i = 0; i < nWindowNames; i++)
{
NXWidgets::CNxString itemName = windowNames[i]->getWindowName();
m_popUpMenu->addMenuItem(itemName, (FAR CMenus *)0,
(FAR CTwm4NxEvent *)0,
EVENT_WINDOW_DEICONIFY);
}
std::free(windowNames);
}
if (m_nMenuItems == 0)
{
delete m_popUpMenu;
m_popUpMenu = (FAR CMenus *)0;
return false;
}
// Clip to screen
struct nxgl_size_s displaySize;
m_twm4nx->getDisplaySize(&displaySize);
struct nxgl_size_s frameSize;
m_menuWindow->getFrameSize(&frameSize);
if (pos->x + frameSize.w > displaySize.w)
{
pos->x = displaySize.w - frameSize.w;
}
if (pos->x < 0)
{
pos->x = 0;
}
if (pos->y + frameSize.h > displaySize.h)
{
pos->y = displaySize.h - frameSize.h;
}
if (pos->y < 0)
{
pos->y = 0;
}
DEBUGASSERT(m_menuDepth < UINT8_MAX);
m_menuDepth++;
if (!m_popUpMenu->setMenuWindowPosition(pos))
{
delete m_popUpMenu;
m_popUpMenu = (FAR CMenus *)0;
return false;
}
m_popUpMenu->raiseMenuWindow();
m_menuWindow->synchronize();
return m_popUpMenu;
}
/**
* Override the virtual value change event. This will get events
* when there is a change in the list box selection.
* *
* @param e The event data. * @param e The event data.
*/ */
void CMenus::handleValueChangeEvent(const NXWidgets::CWidgetEventArgs &e) void CMenus::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
{ {
// Check if anything is selected // A button should now be clicked
int menuSelection = m_menuListBox->getSelectedIndex(); int column;
if (menuSelection >= 0) int row;
if (m_buttons->isButtonClicked(column, row) && column == 0)
{ {
// Yes.. Get the selection menu item list box entry // The row number is sufficent to locate the menu entry info
// But we have to search through the menu items to find the
// at this row.
FAR const NXWidgets::CListBoxDataItem *option = FAR struct SMenuItem *item;
m_menuListBox->getSelectedOption(); int index;
// Get the menu item string for (item = m_menuHead, index = 0;
FAR const NXWidgets::CNxString itemText = option->getText();
// Now find the window with this name
for (FAR struct SMenuItem *item = m_menuHead;
item != (FAR struct SMenuItem *)0; item != (FAR struct SMenuItem *)0;
item = item->flink) item = item->flink, index++)
{ {
// Check if the menu item string matches the listbox selection // When the index matches the row number, then we have
// string // the entry.
// REVISIT: Are there any race conditions we need to
// concerned with here? Such as menuitems being removed
// while the menu is up?
if (itemText.compareTo(item->text) == 0) if (row == index)
{ {
// Generate the menu event // Send an event to the Twm4Nx event handler
struct SEventMsg msg; struct SEventMsg msg;
// If there is a subMenu, then bring the sub-menu up
// now.
if (item->subMenu != (FAR CMenus *)0)
{
msg.eventID = EVENT_MENU_SUBMENU;
msg.handler = (FAR CTwm4NxEvent *)0;
msg.obj = (FAR void *)item->subMenu;
}
// Otherwise, send the event specified for the menu item. The
// handler is only used if the recipient of the event is
// EVENT_RECIPIENT_APP
else
{
msg.eventID = item->event; msg.eventID = item->event;
msg.pos.x = e.getX();
msg.pos.y = e.getY();
msg.context = EVENT_CONTEXT_TOOLBAR;
msg.handler = item->handler; msg.handler = item->handler;
msg.obj = (FAR void *)this; msg.obj = (FAR void *)this;
}
// Fill in the remaining, common stuff
msg.pos.x = e.getX();
msg.pos.y = e.getY();
msg.context = EVENT_CONTEXT_MENU;
// NOTE that we cannot block because we are on the same thread // NOTE that we cannot block because we are on the same thread
// as the message reader. If the event queue becomes full then // as the message reader. If the event queue becomes full then
@ -887,11 +810,11 @@ void CMenus::handleValueChangeEvent(const NXWidgets::CWidgetEventArgs &e)
twmerr("ERROR: mq_send failed: %d\n", ret); twmerr("ERROR: mq_send failed: %d\n", ret);
} }
break; return;
} }
} }
twmwarn("WARNING: No matching menu item\n"); twmwarn("WARNING: No matching menu at index %d\n", row);
} }
} }
@ -909,13 +832,6 @@ void CMenus::cleanup(void)
m_eventq = (mqd_t)-1; m_eventq = (mqd_t)-1;
} }
// Free any popup menus
if (m_popUpMenu != (FAR CMenus *)0)
{
delete m_popUpMenu;
}
// Free the menu window // Free the menu window
if (m_menuWindow != (FAR CWindow *)0) if (m_menuWindow != (FAR CWindow *)0)
@ -945,4 +861,14 @@ void CMenus::cleanup(void)
delete curr; delete curr;
} }
m_menuHead = (FAR struct SMenuItem *)0;
m_menuTail = (FAR struct SMenuItem *)0;
// Free the button array
if (m_buttons != (FAR NXWidgets::CButtonArray *)0)
{
delete m_buttons;
m_buttons = (FAR NXWidgets::CButtonArray *)0;
}
} }

View File

@ -221,7 +221,7 @@ bool CTwm4Nx::run(void)
(unsigned int)m_displaySize.h <= INT16_MAX); (unsigned int)m_displaySize.h <= INT16_MAX);
m_maxWindow.w = INT16_MAX - m_displaySize.w; m_maxWindow.w = INT16_MAX - m_displaySize.w;
m_maxWindow.h = INT16_MAX - m_displaySize.w; m_maxWindow.h = INT16_MAX - m_displaySize.h;
#if !defined(CONFIG_TWM4NX_NOKEYBOARD) || !defined(CONFIG_TWM4NX_NOMOUSE) #if !defined(CONFIG_TWM4NX_NOKEYBOARD) || !defined(CONFIG_TWM4NX_NOMOUSE)
// Create the keyboard/mouse input device thread // Create the keyboard/mouse input device thread

View File

@ -57,14 +57,6 @@
#include "graphics/nxwidgets/cwindoweventhandlerlist.hxx" #include "graphics/nxwidgets/cwindoweventhandlerlist.hxx"
#include "graphics/nxwidgets/tnxarray.hxx" #include "graphics/nxwidgets/tnxarray.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Implementation Classes * Implementation Classes
****************************************************************************/ ****************************************************************************/

View File

@ -85,7 +85,7 @@
namespace NXWidgets namespace NXWidgets
{ {
class CListBox; // Forward reference class CButtonArray; // Forward reference
class CWidgetEventArgs; // Forward reference class CWidgetEventArgs; // Forward reference
class CWidgetEventArgs; // Forward reference class CWidgetEventArgs; // Forward reference
} }
@ -102,7 +102,6 @@ namespace Twm4Nx
FAR CMenus *subMenu; /**< Menu root of a pull right menu */ FAR CMenus *subMenu; /**< Menu root of a pull right menu */
FAR NXWidgets::CNxString text; /**< The text string for the menu item */ FAR NXWidgets::CNxString text; /**< The text string for the menu item */
FAR CTwm4NxEvent *handler; /**< Application event handler */ FAR CTwm4NxEvent *handler; /**< Application event handler */
uint16_t index; /**< Index of this menu item */
uint16_t event; /**< Menu selection event */ uint16_t event; /**< Menu selection event */
}; };
@ -113,16 +112,13 @@ namespace Twm4Nx
CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */ CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
mqd_t m_eventq; /**< NxWidget event message queue */ mqd_t m_eventq; /**< NxWidget event message queue */
FAR CWindow *m_menuWindow; /**< The menu window */ FAR CWindow *m_menuWindow; /**< The menu window */
FAR CMenus *m_popUpMenu; /**< Pop-up menu */ FAR NXWidgets::CButtonArray *m_buttons; /**< The menu button array */
FAR NXWidgets::CListBox *m_menuListBox; /**< The menu list box */
FAR struct SMenuItem *m_activeItem; /**< The active menu item */
FAR struct SMenuItem *m_menuHead; /**< First item in menu */ FAR struct SMenuItem *m_menuHead; /**< First item in menu */
FAR struct SMenuItem *m_menuTail; /**< Last item in menu */ FAR struct SMenuItem *m_menuTail; /**< Last item in menu */
NXWidgets::CNxString m_menuName; /**< The name of the menu */ NXWidgets::CNxString m_menuName; /**< The name of the menu */
nxgl_coord_t m_entryHeight; /**< Menu entry height */ nxgl_coord_t m_entryHeight; /**< Menu entry height */
uint16_t m_nMenuItems; /**< Number of items in the menu */ uint16_t m_nMenuItems; /**< Number of items in the menu */
uint8_t m_menuDepth; /**< Number of menus up */ uint8_t m_nrows; /**< Number of rows in the button array */
bool m_menuPull; /**< Is there a pull right entry? */
char m_info[INFO_LINES][INFO_SIZE]; char m_info[INFO_LINES][INFO_SIZE];
void identify(FAR CWindow *cwin); void identify(FAR CWindow *cwin);
@ -132,48 +128,32 @@ namespace Twm4Nx
* the containing frame. * the containing frame.
*/ */
inline void menuToFramePos(FAR const struct nxgl_point_s *menupos, void menuToFramePos(FAR const struct nxgl_point_s *menupos,
FAR struct nxgl_point_s *framepos) FAR struct nxgl_point_s *framepos);
{
framepos->x = menupos->x - CONFIG_NXTK_BORDERWIDTH;
framepos->y = menupos->y - CONFIG_NXTK_BORDERWIDTH;
}
/** /**
* Convert the position of the containing frame to the position of * Convert the position of the containing frame to the position of
* the menu window. * the menu window.
*/ */
inline void frameToMenuPos(FAR const struct nxgl_point_s *framepos, void frameToMenuPos(FAR const struct nxgl_point_s *framepos,
FAR struct nxgl_point_s *menupos) FAR struct nxgl_point_s *menupos);
{
menupos->x = framepos->x + CONFIG_NXTK_BORDERWIDTH;
menupos->y = framepos->y + CONFIG_NXTK_BORDERWIDTH;
}
/** /**
* Convert the size of a menu window to the size of the containing * Convert the size of a menu window to the size of the containing
* frame. * frame.
*/ */
inline void menuToFrameSize(FAR const struct nxgl_size_s *menusize, void menuToFrameSize(FAR const struct nxgl_size_s *menusize,
FAR struct nxgl_size_s *framesize) FAR struct nxgl_size_s *framesize);
{
framesize->w = menusize->w + 2 * CONFIG_NXTK_BORDERWIDTH;
framesize->h = menusize->h + 2 * CONFIG_NXTK_BORDERWIDTH;
}
/** /**
* Convert the size of a containing frame to the size of the menu * Convert the size of a containing frame to the size of the menu
* window. * window.
*/ */
inline void frameToMenuSize(FAR const struct nxgl_size_s *framesize, void frameToMenuSize(FAR const struct nxgl_size_s *framesize,
FAR struct nxgl_size_s *menusize) FAR struct nxgl_size_s *menusize);
{
menusize->w = framesize->w - 2 * CONFIG_NXTK_BORDERWIDTH;
menusize->h = framesize->h - 2 * CONFIG_NXTK_BORDERWIDTH;
}
/** /**
* Create the menu window. Menu windows are always created in the * Create the menu window. Menu windows are always created in the
@ -232,32 +212,24 @@ namespace Twm4Nx
} }
/** /**
* Create the menu list box * Create the menu button array
* *
* @result True is returned on success * @result True is returned on success
*/ */
bool createMenuListBox(void); bool createMenuButtonArray(void);
void paintMenu(void); void paintMenu(void);
void destroyMenu(void); void destroyMenu(void);
/** /**
* Pop up a pull down menu. * Handle a widget action event, overriding the CWidgetEventHandler
* * method. This will indicate a button pre-release event.
* @param pos Location of upper left of menu
*/
bool popUpMenu(FAR struct nxgl_point_s *pos);
/**
* Override the virtual value change event. This will get events
* when there is a change in the list box selection.
* *
* @param e The event data. * @param e The event data.
*/ */
void handleValueChangeEvent(const NXWidgets::CWidgetEventArgs &e); void handleActionEvent(const NXWidgets::CWidgetEventArgs &e);
/** /**
* Cleanup or initialization error or on deconstruction. * Cleanup or initialization error or on deconstruction.