Retrieving Widget Names

Is there a way to retrieve the name of a widget generated by PhAB within a callback?

For example:

I have two label widgets named “label_widget_0” and “label_widget_1” both using the same realized callback “realized_callback@file.cc”. I’d like to be able to determine which widget is being realized in the callback without using the user data or comparing against the PhAB generated ABW index. (i.e. I could do if(widget == ABW_label_widget_0) but that requires a hard coded solution).

Since we enforce a naming scheme within PhAB it would be much more convenient to parse the name string so I could determine that it was widget 0 or 1 that was being realized.

Anyone know if this text is stored somewhere or is it only used by PhAB to generate the ABW index name?

I don’t know of any way to get the string. Usually ApName() is used to this type of thing but it is not much different than using the ABW_ value:

if ( ApName( widget ) == ABN_widget1 ) {
/* do widget1 processing */
}

Phab stores the widgets as indexs and defines when it generates the code.

ApInstanceName() might do what you want.

char *generated_string…
if (strcmp(ApInstanceName(widget), generated_string) == 0)…

Make sure you look at the ApInstanceName() documentation. The strings aren’t retained by default, so you have to change a setting in PhAB.

Incidentally, I handle this problem slightly differently. At startup, we assign all the ABW_xxx pointers into an array. Then we put a value corresponding to the index in Pt_ARG_USER_DATA. Pull the number out of Pt_ARG_USER_DATA and then you can directly use widget_array[widget_index]. This adds the work of dealing with Pt_ARG_USER_DATA, but saves the work of dealing with strings and the space of storing the strings in the running project.

-James Ingraham
Sage Automation, Inc.

Excellent. Thanks that’s exactly what I was looking for.

I think I will take your suggestion and assign the USER_DATA at runtime. We had been doing something similar, but backwards i.e. assigning the USER_DATA in PhAB and then hardcoding an array of widgets that would line up with these numbers. Your solution makes a lot more sense.

Just in case anyone is reading this post later looking for the option in PhAB to store the strings, it is the aptly named “Store Names for ApInstanceName()” under the “Generate Options” tab in Project Properties. The document is here: qnx.com/developers/docs/6.3. … herOptions