Problem with groups in menus

I posted this some months ago, hoped about some fix in patch A that didn’t
happen, so I’m posting it again.
Below is the menu example from the online doc. If I modify it a little such
that I create a group inside the menu and the items inside the group, i.e.
the hierarchy is:

menu bar → menu button → menu → group → menu items

instead of

menu bar → menu button → menu → menu items

then the menu items are blocked. The same program works fine in Photon 1.14.
Any help is really greatly appreciated.
Markus



#include <Pt.h>
#include <stdlib.h>

// The name of the font we’ll use in the menus:
char Helvetica_14B[MAX_FONT_TAG];

int
post_menu_cb(PtWidget_t *w, void *client_data, PtCallbackInfo_t *info)
{

client_data = client_data; info = info;

if (client_data)
{
PtWidget_t *menu = (PtWidget_t *)client_data;

PtPositionMenu(menu, NULL);
PtRealizeWidget(menu);
}
return (Pt_CONTINUE);
}

int
popup_menu_cb(PtWidget_t *w, void *client_data, PtCallbackInfo_t *info)
{
PhEvent_t *event = info ? info->event : NULL;
PhPointerEvent_t *ptr = event ? (PhPointerEvent_t *)
PhGetData
(event) : NULL;

w = w;

/* post the popup if the right button was pressed */
if (event && client_data &&
(event->type & Ph_EV_BUT_PRESS) &&
(ptr->buttons == 1))
{
PtWidget_t *menu = (PtWidget_t *)client_data;

PtPositionMenu(menu, event);
PtRealizeWidget(menu);
}
return (Pt_CONTINUE);
}

int
nop_cb(PtWidget_t *w, void *client_data,
PtCallbackInfo_t *info)
{
PtArg_t arg[1];
char *text;

w = w; client_data = client_data; info = info;

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, &text, 0);
PtGetResources(w, 1, arg);

if (text)
printf(“Pushed the %s button\n”, text);
return (Pt_CONTINUE);
}

int
quit_cb(PtWidget_t *w, void *client_data, PtCallbackInfo_t *info)
{
w = w; client_data = client_data; info = info;

PtExit( EXIT_SUCCESS );
return (Pt_CONTINUE);
}

void create_import_items(PtWidget_t *parent)
{
PtArg_t arg[3];
PtCallback_t noop[] = { {nop_cb, NULL} };

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “Image”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
PtSetArg(&arg[2], Pt_CB_ACTIVATE, noop, 1);
PtCreateWidget(PtButton, parent, 3, arg);

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “Bitmap”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
PtSetArg(&arg[2], Pt_CB_ACTIVATE, noop, 1);
PtCreateWidget(PtButton, parent, 3, arg);
}

void create_file_items(PtWidget_t *parent)
{
PtArg_t arg[3];
PtWidget_t *importButton, *importMenu;
PtCallback_t quit_callbacks[] = { {quit_cb, NULL} };
PtCallback_t noop[] = { {nop_cb, NULL} };

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “Open”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
PtSetArg(&arg[2], Pt_CB_ACTIVATE, noop, 1);
PtCreateWidget(PtButton, parent, 3, arg);

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “New”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
PtSetArg(&arg[2], Pt_CB_ACTIVATE, noop, 1);
PtCreateWidget(PtButton, parent, 3, arg);

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “Import”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
PtSetArg(&arg[2], Pt_ARG_BUTTON_TYPE, Pt_MENU_RIGHT,
Pt_MENU_RIGHT);
importButton = PtCreateWidget(PtMenuButton, parent, 3, arg);

PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS,
Pt_MENU_AUTO|Pt_MENU_CHILD,
Pt_MENU_AUTO|Pt_MENU_CHILD);
importMenu = PtCreateWidget(PtMenu, importButton, 1, arg );

create_import_items(importMenu);

PtCreateWidget(PtSeparator, parent, 0, NULL);

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “Quit”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
PtSetArg(&arg[2], Pt_CB_ACTIVATE, quit_callbacks, 1);
PtCreateWidget(PtButton, parent, 3, arg);
}

void create_help_items(PtWidget_t *parent)
{
PtArg_t arg[3];
PtCallback_t noop[] = { {nop_cb, NULL} };

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “About”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
PtSetArg(&arg[2], Pt_CB_ACTIVATE, noop, 1);
PtCreateWidget(PtMenuButton, parent, 3, arg);
}

int
main(int argc, char *argv[])
{
PtAppContext_t app;
PhDim_t dim, workarea, *group_size;
PhPoint_t pos;
PtArg_t arg[5];
PtWidget_t *window, *group, *raw, *fileGroup;
PtWidget_t *fileButton, *helpButton;
PtWidget_t *fileMenu, *helpMenu, *popupMenu;

if ((window = PtAppInit(&app, &argc, argv, 0, NULL)) == NULL)
PtExit(EXIT_FAILURE);

// Generate the name of the font for the menus.
if(PfGenerateFontName((const uchar_t *) “Helvetica”, PF_STYLE_BOLD, 14,
(uchar_t *) Helvetica_14B) == NULL) {
perror(“Unable to generate font name”);
PtExit(EXIT_FAILURE);
}

PtSetArg(&arg[0], Pt_ARG_ANCHOR_FLAGS,
Pt_LEFT_ANCHORED_LEFT|Pt_RIGHT_ANCHORED_RIGHT,
Pt_IS_ANCHORED);
PtSetArg(&arg[1], Pt_ARG_BEVEL_WIDTH, 2, 0);
PtSetArg(&arg[2], Pt_ARG_FLAGS, Pt_HIGHLIGHTED, Pt_HIGHLIGHTED);
group = PtCreateWidget(PtGroup, window, 3, arg);

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “File”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
fileButton = PtCreateWidget(PtMenuButton, group, 2, arg);

PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, “Help”, 0);
PtSetArg(&arg[1], Pt_ARG_TEXT_FONT, Helvetica_14B, 0);
helpButton = PtCreateWidget(PtMenuButton, group, 2, arg);

/* ---- start of change ---- /
fileMenu = PtCreateWidget(PtMenu, fileButton, 0, NULL);
fileGroup = PtCreateWidget(PtGroup, fileMenu, 0, NULL);
create_file_items(fileGroup);
/
---- end of change ---- */

helpMenu = PtCreateWidget(PtMenu, helpButton, 0, NULL);
create_help_items(helpMenu);

PtAddCallback(fileButton, Pt_CB_ARM, post_menu_cb, fileMenu);
PtAddCallback(helpButton, Pt_CB_ARM, post_menu_cb, helpMenu);

PtRealizeWidget(window);

PtSetArg(&arg[0], Pt_ARG_DIM, &group_size, 0);
PtGetResources(group, 1, arg);

workarea.w = 300;
workarea.h = 200;
pos.x = 0;
pos.y = group_size->h + 2 * 2;

PtSetArg(&arg[0], Pt_ARG_POS, &pos, 0);
PtSetArg(&arg[1], Pt_ARG_DIM, &workarea, 0);
raw = PtCreateWidget(PtRaw, window, 2, arg);

popupMenu = PtCreateWidget(PtMenu, window, 0, NULL );
create_file_items(popupMenu);
PtAddEventHandler(raw, Ph_EV_BUT_PRESS, popup_menu_cb, popupMenu);

PtRealizeWidget(raw);

dim.w = workarea.w;
dim.h = workarea.h + group_size->h + 2 * 2;
PtSetArg(&arg[0], Pt_ARG_DIM, &dim, 0);
PtSetResources(window, 1, arg);

PtMainLoop();
return (EXIT_SUCCESS);
}

Markus Loffler <loffler@ces.clemson.edu> wrote:

I posted this some months ago, hoped about some fix in patch A that didn’t
happen, so I’m posting it again.
Below is the menu example from the online doc. If I modify it a little such
that I create a group inside the menu and the items inside the group, i.e.
the hierarchy is:

menu bar → menu button → menu → group → menu items

instead of

menu bar → menu button → menu → menu items

then the menu items are blocked. The same program works fine in Photon 1.14.
Any help is really greatly appreciated.
Markus

Make sure you are turning on the Pt_SELECTABLE bit in Pt_ARG_FLAGS on in the
PtGroup. PtMenu looks at this flag and blocks widgets that don’t have it set.

Thanks David,
that was exactly the problem.
Markus


“David LeBlanc” <dleblanc@qnx.com> wrote in message
news:94i3ap$n4g$1@nntp.qnx.com

Markus Loffler <> loffler@ces.clemson.edu> > wrote:
I posted this some months ago, hoped about some fix in patch A that
didn’t
happen, so I’m posting it again.
Below is the menu example from the online doc. If I modify it a little
such
that I create a group inside the menu and the items inside the group,
i.e.
the hierarchy is:

menu bar → menu button → menu → group → menu items

instead of

menu bar → menu button → menu → menu items

then the menu items are blocked. The same program works fine in Photon
1.14.
Any help is really greatly appreciated.
Markus

Make sure you are turning on the Pt_SELECTABLE bit in Pt_ARG_FLAGS on in
the
PtGroup. PtMenu looks at this flag and blocks widgets that don’t have it
set.