Menu Item Code Callbacks

I would like to have several (many actually) different menu items call the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122

A PtWidget_t pointer is passed to your callback. Compare this one with all
the menu item widgets in your menu to determine which one was called.
Markus

“Bill Caroselli” <Bill@Sattel.com> wrote in message
news:9bhogk$erl$1@inn.qnx.com

I would like to have several (many actually) different menu items call the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122

\

Well, that is the obvious answer and it does work with everything but menu
items, but

If I have a Menu called ‘menu_x’ and it has three menu items called
‘menu_x_1’, ‘menu_x_2’ & ‘menu_x_3’ and I try to compare ( widget ==
ABW_menu_x_1 ) I get that ABW_menu_x_1 does not exist.

BTW, ABW_menu_x does not exist either.

The on-line docs mention that PhAB does NOT create ABWs for menus or meni
items.

So, how do I have to manipulate the parameters that are passed to a callback
to know what menu item originated the callback?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122



“Markus Loffler” <loffler@ces.clemson.edu> wrote in message
news:9bhqac$fsb$1@inn.qnx.com

A PtWidget_t pointer is passed to your callback. Compare this one with all
the menu item widgets in your menu to determine which one was called.
Markus

“Bill Caroselli” <> Bill@Sattel.com> > wrote in message
news:9bhogk$erl$> 1@inn.qnx.com> …
I would like to have several (many actually) different menu items call
the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122



\

Ok, I didn’t know that - I never do PhAB Photon programming. That’s a little
strange that PHAB does not create ABW’s for menus.
The other way to do it is to attach user data to the menu items (e.g., a
string containing the menu name, a number etc), and then accessing the
resouce Pt_ARG_USER_DATA to retrieve it.
Markus


“Bill Caroselli” <Bill@Sattel.com> wrote in message
news:9bhqnl$g6n$1@inn.qnx.com

Well, that is the obvious answer and it does work with everything but menu
items, but

If I have a Menu called ‘menu_x’ and it has three menu items called
‘menu_x_1’, ‘menu_x_2’ & ‘menu_x_3’ and I try to compare ( widget ==
ABW_menu_x_1 ) I get that ABW_menu_x_1 does not exist.

BTW, ABW_menu_x does not exist either.

The on-line docs mention that PhAB does NOT create ABWs for menus or meni
items.

So, how do I have to manipulate the parameters that are passed to a
callback
to know what menu item originated the callback?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122



“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9bhqac$fsb$> 1@inn.qnx.com> …
A PtWidget_t pointer is passed to your callback. Compare this one with
all
the menu item widgets in your menu to determine which one was called.
Markus

“Bill Caroselli” <> Bill@Sattel.com> > wrote in message
news:9bhogk$erl$> 1@inn.qnx.com> …
I would like to have several (many actually) different menu items call
the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122





\

Been there, thought of that, doesn’t work. There is no way, in PhAB, to add
user data to a menu item.

Can someone from QSSL offer a hint?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122



“Markus Loffler” <loffler@ces.clemson.edu> wrote in message
news:9bhr66$ggj$1@inn.qnx.com

Ok, I didn’t know that - I never do PhAB Photon programming. That’s a
little
strange that PHAB does not create ABW’s for menus.
The other way to do it is to attach user data to the menu items (e.g., a
string containing the menu name, a number etc), and then accessing the
resouce Pt_ARG_USER_DATA to retrieve it.

[other creative but unsuccessful stuff deleted]

“Bill Caroselli” <> Bill@Sattel.com> > wrote in message
news:9bhogk$erl$> 1@inn.qnx.com> …
I would like to have several (many actually) different menu items
call
the
same code callback function.

In that function how do I determine which menu item called it?

Hey Bill,

In your callback, you could use:

PtArg_t arg[1];
char name;

PtSetArg(&arg[0],Pt_ARG_TEXT_STRING,&name,0);
PtGetResources(widget,1,arg);

<<<<<

That should return your menu item text.
I know it’s not the instance name, but hey…a strcmp is better than nothin’!
:slight_smile:


F. Carl Sherbino
CriSys Limited


Bill Caroselli wrote:

Well, that is the obvious answer and it does work with everything but menu
items, but

If I have a Menu called ‘menu_x’ and it has three menu items called
‘menu_x_1’, ‘menu_x_2’ & ‘menu_x_3’ and I try to compare ( widget ==
ABW_menu_x_1 ) I get that ABW_menu_x_1 does not exist.

BTW, ABW_menu_x does not exist either.

The on-line docs mention that PhAB does NOT create ABWs for menus or meni
items.

So, how do I have to manipulate the parameters that are passed to a callback
to know what menu item originated the callback?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122

“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9bhqac$fsb$> 1@inn.qnx.com> …
A PtWidget_t pointer is passed to your callback. Compare this one with all
the menu item widgets in your menu to determine which one was called.
Markus

“Bill Caroselli” <> Bill@Sattel.com> > wrote in message
news:9bhogk$erl$> 1@inn.qnx.com> …
I would like to have several (many actually) different menu items call
the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122



\

You can use “ApName( widgetptr )” and compare with “ABN_name”. But take care
that you know
the real parent. The ABN_ number is only valid inside a module. If you
created a new window module
the ABN_ - Count start from 1 or 0. If the function ApGetInstance works,
there you can get the
instanceparent of the widget.

Second choice is. Enable names in phab ( somewhere in the option ) and use
the function ApInstanceName.
Do not forget you have to enbable it.

\

Bye Sascha( sascha@bitctrl.de )

Sascha Morgenstern
BitCtrl Systems GmbH
Weißenfelser Straße 67
Germany - 04229 Leipzig
Phon. +49 341 490 670
FAX. +49 341 490 67 15
eMail: sascha@bitctrl.de
WWW: http://www.bitctrl.de



Bill Caroselli <Bill@Sattel.com> schrieb in im Newsbeitrag:
9bhogk$erl$1@inn.qnx.com

I would like to have several (many actually) different menu items call the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122

Wellllll…

I set up a simple app with base window, a menu bar, and a menu button with an
‘Arm’ callback to a menu module that has two menu items, each with a callback to
the same function. All widgets were given a unique instance name, and I enabled
‘include names’ in the “Application->Startup Info/Modules…” dialog.

I tried using all three different widget source references from the callback
args in the menu item callback function:
Pt_widget_t *mywidg = widget;
Pt_widget_t *mywidg = apinfo->widget;
Pt_widget_t *mywidg = ApWidget(cbinfo);

In all three instances:
ApInstanceName(mywidg) returns NULL
ApGetInstance(mywidg) returns the name of the base window.
ApName(mywidg) returns -1.

So…using

PtSetArg(&arg[0],Pt_ARG_TEXT_STRING,&name,0);
PtGetResources(widget,1,arg);

to get the text from the label portion of the menu item is still the only way i
have managed to get a ‘handle’ on which menu item was selected.

It still seems a little weird that you can use the widget callback arg with
PtGetResources, and get the menu item text, but even though the menu item is
given a unique instance name in the module editor, ApinstanceName(widget)
returns NULL !???

F. Carl sherbino
CriSys limited



Sascha Morgenstern wrote:

You can use “ApName( widgetptr )” and compare with “ABN_name”. But take care
that you know
the real parent. The ABN_ number is only valid inside a module. If you
created a new window module
the ABN_ - Count start from 1 or 0. If the function ApGetInstance works,
there you can get the
instanceparent of the widget.

Second choice is. Enable names in phab ( somewhere in the option ) and use
the function ApInstanceName.
Do not forget you have to enbable it.


Bye Sascha( > sascha@bitctrl.de > )

Sascha Morgenstern
BitCtrl Systems GmbH
Weißenfelser Straße 67
Germany - 04229 Leipzig
Phon. +49 341 490 670
FAX. +49 341 490 67 15
eMail: > sascha@bitctrl.de
WWW: > http://www.bitctrl.de

Bill Caroselli <> Bill@Sattel.com> > schrieb in im Newsbeitrag:
9bhogk$erl$> 1@inn.qnx.com> …
I would like to have several (many actually) different menu items call the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122

I tried yesterday and if find out that ApName on the widget from the
callback
gives you the number inside the module. <= First position to findout on what
you are click
Now go up on the tree till you find the object which created your menu or at
least the parent.
Take from this object again ApName and this two number give you an
information
about on what you pressed.

I was thinking, a usual PtMenuButton is your parent.


Bye Sascha( sascha@bitctrl.de )

Sascha Morgenstern
BitCtrl Systems GmbH
Weißenfelser Straße 67
Germany - 04229 Leipzig
Phon. +49 341 490 670
FAX. +49 341 490 67 15
eMail: sascha@bitctrl.de
WWW: http://www.bitctrl.de


F. Carl Sherbino <csherbino@crisys.com> schrieb in im Newsbeitrag:
3ADDA6B6.DDA54A6C@crisys.com

Wellllll…

I set up a simple app with base window, a menu bar, and a menu button with
an
‘Arm’ callback to a menu module that has two menu items, each with a
callback to
the same function. All widgets were given a unique instance name, and I
enabled
‘include names’ in the “Application->Startup Info/Modules…” dialog.

I tried using all three different widget source references from the
callback
args in the menu item callback function:
Pt_widget_t *mywidg = widget;
Pt_widget_t *mywidg = apinfo->widget;
Pt_widget_t *mywidg = ApWidget(cbinfo);

In all three instances:
ApInstanceName(mywidg) returns NULL
ApGetInstance(mywidg) returns the name of the base window.
ApName(mywidg) returns -1.

So…using

PtSetArg(&arg[0],Pt_ARG_TEXT_STRING,&name,0);
PtGetResources(widget,1,arg);

to get the text from the label portion of the menu item is still the only
way i
have managed to get a ‘handle’ on which menu item was selected.

It still seems a little weird that you can use the widget callback arg
with
PtGetResources, and get the menu item text, but even though the menu item
is
given a unique instance name in the module editor, ApinstanceName(widget)
returns NULL !???

F. Carl sherbino
CriSys limited



Sascha Morgenstern wrote:

You can use “ApName( widgetptr )” and compare with “ABN_name”. But take
care
that you know
the real parent. The ABN_ number is only valid inside a module. If you
created a new window module
the ABN_ - Count start from 1 or 0. If the function ApGetInstance
works,
there you can get the
instanceparent of the widget.

Second choice is. Enable names in phab ( somewhere in the option ) and
use
the function ApInstanceName.
Do not forget you have to enbable it.


Bye Sascha( > sascha@bitctrl.de > )

Sascha Morgenstern
BitCtrl Systems GmbH
Weißenfelser Straße 67
Germany - 04229 Leipzig
Phon. +49 341 490 670
FAX. +49 341 490 67 15
eMail: > sascha@bitctrl.de
WWW: > http://www.bitctrl.de

Bill Caroselli <> Bill@Sattel.com> > schrieb in im Newsbeitrag:
9bhogk$erl$> 1@inn.qnx.com> …
I would like to have several (many actually) different menu items call
the
same code callback function.

In that function how do I determine which menu item called it?


Bill Caroselli - Sattel Global Networks
1-818-709-6201 ext 122