Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Identifying Widget in a Callback: (4 Items)
   
Identifying Widget in a Callback  
Hi,

I have a situation where I need to use the same callback for different buttons. Is there any way to identify the Widget 
(button in my case) that triggered the callback?

I looked at the Pt_Widget structure but wasn't able to find any relevant information.

Thanks!
Re: Identifying Widget in a Callback  
> Hi,
> 
> I have a situation where I need to use the same callback for different buttons
> . Is there any way to identify the Widget (button in my case) that triggered 
> the callback?
> 
> I looked at the Pt_Widget structure but wasn't able to find any relevant 
> information.
> 
> Thanks!


I'm currently using user data specific to each button to identify them in the callback (Pt_Widget->user_data). I was 
just interested to know if Photon has a default/recommended practice for identifying a Widget.
Re: Identifying Widget in a Callback  
Hi,

there are at least three different ways to recognize the widget which invoked a callback. One of them, attaching unique 
user data to each widget, you already named - and that is often the best way.

Of course you could also compare the 'widget' pointer directly, as in:
   if ( widget == ABW_widget1 ) {
      /* do widget1 processing */
   }
   else if ( widget == ABW_widget2 ) {
      /* do widget2 processing */
   }
   else {
      /* do something else? */
   }

But then it's much nicer to go by the 'widget name' (which is actually an index):

   switch ( ApName( widget ) ) {
   case ABN_widget1:
      /* do widget1 processing */
   case ABN_widget2:
      /* do widget2 processing */
   default:
      /* do something else? */
    }

- Thomas
Re: Identifying Widget in a Callback  
Ok, thats good to know. Thanks!