Help m! for Callbacks function

Hi? all

I created some buttons widget and setted Button Text(Pt_ARG_TEXT_STRING)
resource. but I only created a callback function which be referanced to
these buttons widget. so that each buttons widget got a same callback
function.

I wish to select button with Button Text parameter in callback function when
button icon is clicked.
but, how to sort through each buttons ?

I try doing it ,using callback function’s parameters(widget, apinfo,
cbinfo). yet I can’t

how to reference button widget resourcs in callback function?

I am not sure I understand, but here it goes.

Using appbuilder :

Lets say you created 3 button, you have set their names to Button_1,
Button_2 and Button_3 and set their Pt_ARG_TEXT_STRING to “button 1”,
"button 2"and “button 3”. Lets now say you have attach to same
Pt_CB_ACTIVATE callback to each button. Now you need to find out witch
button was press.

int My_ActiveCB(PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
char *button_text ;

// the easy way is to use the widget pointers
if( widget == ABW_Button_1 )
{
// then button 1 was press
}
else if( widget == ABW_Button_2 )
{
// then button 2 was press
}
else if( widget == ABW_Button_3 )
{
// then button 3 was press
}

// you could also you the widget names
if( ApName( widget ) == ABN_Button_1 )
{
// then button 1 was press
}
else if( ApName( widget ) == ABN_Button_2 )
{
// then button 2 was press
}
else if( ApName( widget ) == ABN_Button_3 )
{
// then button 3 was press
}

// or you could make it look complicated ( to justified your salary )
if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_1) == widget)
{
// then button 1 was press
}
else if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_2) == widget)
{
// then button 2 was press
}
else if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_3) == widget)
{
// then button 3 was press
}

// you could also use the widget text
PtGetResource( widget, Pt_ARG_TEXT_STRING, &button_text, 0 );
if( !strcmp( button_text, “button 1” ))
{
// then button 1 was press
}
else if( !strcmp( button_text, “button 2” ))
{
// then button 2 was press
}
if( !strcmp( button_text, “button 3” ))
{
// then button 3 was press
}

// I can probably come up with a couple more !
}

Michel Belanger wrote:

I am not sure I understand, but here it goes.

Using appbuilder :

Lets say you created 3 button, you have set their names to Button_1,
Button_2 and Button_3 and set their Pt_ARG_TEXT_STRING to “button 1”,
"button 2"and “button 3”. Lets now say you have attach to same
Pt_CB_ACTIVATE callback to each button. Now you need to find out witch
button was press.

int My_ActiveCB(PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
char *button_text ;

// the easy way is to use the widget pointers
if( widget == ABW_Button_1 )
{
// then button 1 was press
}
else if( widget == ABW_Button_2 )
{
// then button 2 was press
}
else if( widget == ABW_Button_3 )
{
// then button 3 was press
}

// you could also you the widget names
if( ApName( widget ) == ABN_Button_1 )
{
// then button 1 was press
}
else if( ApName( widget ) == ABN_Button_2 )
{
// then button 2 was press
}
else if( ApName( widget ) == ABN_Button_3 )
{
// then button 3 was press
}

// or you could make it look complicated ( to justified your salary )
if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_1) == widget)
{
// then button 1 was press
}
else if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_2) == widget)
{
// then button 2 was press
}
else if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_3) == widget)
{
// then button 3 was press
}

// you could also use the widget text
PtGetResource( widget, Pt_ARG_TEXT_STRING, &button_text, 0 );
if( !strcmp( button_text, “button 1” ))
{
// then button 1 was press
}
else if( !strcmp( button_text, “button 2” ))
{
// then button 2 was press
}
if( !strcmp( button_text, “button 3” ))
{
// then button 3 was press
}

// I can probably come up with a couple more !
}
\

Another way would be to use the Pt_ARG_USER_DATA or Pt_ARG_POINTER
that’s what i’ve been using when doing this kind of think, even thuogh
Michel’s ideas look smarter if using phab :slight_smile:

thank you for your advice…


“phearbear” <phearbear@home.se> wrote in message
news:3CE64BA7.6040108@home.se

Michel Belanger wrote:
I am not sure I understand, but here it goes.

Using appbuilder :

Lets say you created 3 button, you have set their names to Button_1,
Button_2 and Button_3 and set their Pt_ARG_TEXT_STRING to “button 1”,
"button 2"and “button 3”. Lets now say you have attach to same
Pt_CB_ACTIVATE callback to each button. Now you need to find out witch
button was press.

int My_ActiveCB(PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
char *button_text ;

// the easy way is to use the widget pointers
if( widget == ABW_Button_1 )
{
// then button 1 was press
}
else if( widget == ABW_Button_2 )
{
// then button 2 was press
}
else if( widget == ABW_Button_3 )
{
// then button 3 was press
}

// you could also you the widget names
if( ApName( widget ) == ABN_Button_1 )
{
// then button 1 was press
}
else if( ApName( widget ) == ABN_Button_2 )
{
// then button 2 was press
}
else if( ApName( widget ) == ABN_Button_3 )
{
// then button 3 was press
}

// or you could make it look complicated ( to justified your salary )
if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_1) == widget)
{
// then button 1 was press
}
else if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_2) == widget)
{
// then button 2 was press
}
else if(ApGetWidgetPtr(ApGetInstance(widget),ABN_Button_3) == widget)
{
// then button 3 was press
}

// you could also use the widget text
PtGetResource( widget, Pt_ARG_TEXT_STRING, &button_text, 0 );
if( !strcmp( button_text, “button 1” ))
{
// then button 1 was press
}
else if( !strcmp( button_text, “button 2” ))
{
// then button 2 was press
}
if( !strcmp( button_text, “button 3” ))
{
// then button 3 was press
}

// I can probably come up with a couple more !
}




Another way would be to use the Pt_ARG_USER_DATA or Pt_ARG_POINTER
that’s what i’ve been using when doing this kind of think, even thuogh
Michel’s ideas look smarter if using phab > :slight_smile: