comp.lang.ada
 help / color / mirror / Atom feed
* Gnoga Callback Handlers with user data
@ 2015-11-22 11:53 slos
  2015-11-22 15:42 ` David Botton
  0 siblings, 1 reply; 11+ messages in thread
From: slos @ 2015-11-22 11:53 UTC (permalink / raw)


Hello there,

I am training myself with this nice Gnoga framework and I have a question.

Using for example GtkAda it is possible to have callback handlers with some user data given when connecting the callback to the button let's say.
http://docs.adacore.com/gtkada-docs/gtkada_ug/_build/html/signals.html#handling-user-data

Then you can have several buttons connected to the same handler which will get different user data.

In Gnoga I have not found this kind of handler.

I can connect to my button :

   procedure On_Click_Handler (Object  : in out Base_Type;
                               Handler : in     Action_Event);

which takes only :

   type Action_Event is access
     procedure (Object : in out Base_Type'Class);

So I cannot pass any user data of course :
   My_Button.On_Click_Handler (On_Click'Unrestricted_Access);

But I may have missed something.
Any suggestion welcome.

Best Regards,
Stéphane
"Ada for Automation"
http://slo-ist.fr/ada4autom

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-22 11:53 Gnoga Callback Handlers with user data slos
@ 2015-11-22 15:42 ` David Botton
  2015-11-22 21:44   ` slos
  0 siblings, 1 reply; 11+ messages in thread
From: David Botton @ 2015-11-22 15:42 UTC (permalink / raw)


The handler will be receiving Object a class-wide object as its parameter which contains the actual Ada Object (in this case the My_Button instance) bound to the button. So you can just check to see if Object is My_Button or any other button using Ada or you can compare Unique_IDs (if My_Button.Unique_ID = Object.Unique_ID).

You should join the Gnoga list https://lists.sourceforge.net/lists/listinfo/gnoga-list

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-22 15:42 ` David Botton
@ 2015-11-22 21:44   ` slos
  2015-11-23  0:50     ` David Botton
  0 siblings, 1 reply; 11+ messages in thread
From: slos @ 2015-11-22 21:44 UTC (permalink / raw)


Dear Mister Botton,

Thanks for your answer.

Le dimanche 22 novembre 2015 16:42:25 UTC+1, David Botton a écrit :
> The handler will be receiving Object a class-wide object as its parameter which contains the actual Ada Object (in this case the My_Button instance) bound to the button. So you can just check to see if Object is My_Button or any other button using Ada or you can compare Unique_IDs (if My_Button.Unique_ID = Object.Unique_ID).
> 
In your tutorial tutorial_04.adb we have :
   procedure On_Click (Object : in out Gnoga.Gui.Base.Base_Type'Class) is
      App : App_Access := App_Access (Object.Connection_Data);
   begin
      App.My_View.Put ("I've been clicked! ");

where :
   type App_Data is new Gnoga.Types.Connection_Data_Type with
      record
         My_View   : Gnoga.Gui.View.View_Type;
         My_Button : Gnoga.Gui.Element.Common.Button_Type;
         My_Exit   : Gnoga.Gui.Element.Common.Button_Type;
         Flasher   : aliased Gnoga.Gui.Element.Common.DIV_Type;

is associated with :
      Main_Window.Connection_Data (App);

So actually, the On_Click handler gets all the App stuff without other indication.

> You should join the Gnoga list https://lists.sourceforge.net/lists/listinfo/gnoga-list

Yes I should but by writting here I wanted to show my interest for your project to others.
Does it hurt ?

Best Regards,
Stéphane
"Ada for Automation"
http://slo-ist.fr/ada4autom


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-22 21:44   ` slos
@ 2015-11-23  0:50     ` David Botton
  2015-11-23 10:44       ` slos
  0 siblings, 1 reply; 11+ messages in thread
From: David Botton @ 2015-11-23  0:50 UTC (permalink / raw)


> In your tutorial tutorial_04.adb we have :
>       App : App_Access := App_Access (Object.Connection_Data);

Yes that is a feature of Gnoga that you can associate data with a connection (not the specific control in this case). You could for example then just do the Unique_ID comparisons with the potential buttons you reused the handler for.

You could also just associate arbitrary data with the buttons by setting attributes on them using My_Button.Attribute or subclass the buttons, use the ID in a map, etc. etc.

The beauty of Gnoga is that it is not a binding like GtkAda but an actual Ada framework from the ground up so there is a wide range of possibilities of how to design your application and accomplish any give goal.

If Ada will ever have a future beyond little black boxes, it is with Gnoga which leverages JS and HTML5 the way almost all modern cross platform (even native) apps are designed now. Just wish I had the time to do the needed development to get GNAT on to modern backends needed for client side development.

> Yes I should but by writting here I wanted to show my interest for your project to others.
> Does it hurt ?

No not at all :) Just there are many people on the Gnoga list that do not read CLA and was concerned about you getting fast answers, but certainly can ask here.

David Botton


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-23  0:50     ` David Botton
@ 2015-11-23 10:44       ` slos
  2015-11-23 17:24         ` David Botton
  2015-11-23 17:41         ` Jeffrey R. Carter
  0 siblings, 2 replies; 11+ messages in thread
From: slos @ 2015-11-23 10:44 UTC (permalink / raw)


Dear Mister Botton,

Thanks for your answer.
Le lundi 23 novembre 2015 01:50:33 UTC+1, David Botton a écrit :
> > In your tutorial tutorial_04.adb we have :
> >       App : App_Access := App_Access (Object.Connection_Data);
> 
> Yes that is a feature of Gnoga that you can associate data with a connection (not the specific control in this case). You could for example then just do the Unique_ID comparisons with the potential buttons you reused the handler for.

Well, that's what I would like to achieve but cannot figure out how.
Since what I get in the handler is the whole UI data, how can I figure out which element has triggered the event ?

> 
> You could also just associate arbitrary data with the buttons by setting attributes on them using My_Button.Attribute or subclass the buttons, use the ID in a map, etc. etc.
> 
> The beauty of Gnoga is that it is not a binding like GtkAda but an actual Ada framework from the ground up so there is a wide range of possibilities of how to design your application and accomplish any give goal.
> 
> If Ada will ever have a future beyond little black boxes, it is with Gnoga which leverages JS and HTML5 the way almost all modern cross platform (even native) apps are designed now. Just wish I had the time to do the needed development to get GNAT on to modern backends needed for client side development.
> 
> > Yes I should but by writting here I wanted to show my interest for your project to others.
> > Does it hurt ?
> 
> No not at all :) Just there are many people on the Gnoga list that do not read CLA and was concerned about you getting fast answers, but certainly can ask here.
> 
> David Botton

Stéphane LOS


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-23 10:44       ` slos
@ 2015-11-23 17:24         ` David Botton
  2015-11-23 22:12           ` slos
  2015-11-23 17:41         ` Jeffrey R. Carter
  1 sibling, 1 reply; 11+ messages in thread
From: David Botton @ 2015-11-23 17:24 UTC (permalink / raw)


> Well, that's what I would like to achieve but cannot figure out how.
> Since what I get in the handler is the whole UI data, how can I figure out which element has triggered the event ?

Ok so given the code you posted.

if Object.Unique_ID = App.My_Button.Unique_ID

if Object.Unique_ID = App.My_Exit.Unique_ID

David Botton

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-23 10:44       ` slos
  2015-11-23 17:24         ` David Botton
@ 2015-11-23 17:41         ` Jeffrey R. Carter
  2015-11-23 22:19           ` slos
  1 sibling, 1 reply; 11+ messages in thread
From: Jeffrey R. Carter @ 2015-11-23 17:41 UTC (permalink / raw)


On 11/23/2015 03:44 AM, slos wrote:
> 
> Well, that's what I would like to achieve but cannot figure out how.
> Since what I get in the handler is the whole UI data, how can I figure out which element has triggered the event ?

You might want to look at the Mine_Detector demo. There's a whole array of
buttons in there with only one On_Click handler.

-- 
Jeff Carter
"Now look, Col. Batguano, if that really is your name."
Dr. Strangelove
31


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-23 17:24         ` David Botton
@ 2015-11-23 22:12           ` slos
  2015-11-23 23:34             ` David Botton
  0 siblings, 1 reply; 11+ messages in thread
From: slos @ 2015-11-23 22:12 UTC (permalink / raw)


Le lundi 23 novembre 2015 18:24:48 UTC+1, David Botton a écrit :
> > Well, that's what I would like to achieve but cannot figure out how.
> > Since what I get in the handler is the whole UI data, how can I figure out which element has triggered the event ?
> 
> Ok so given the code you posted.
> 
> if Object.Unique_ID = App.My_Button.Unique_ID
> 
> if Object.Unique_ID = App.My_Exit.Unique_ID
> 
> David Botton

OK, got it ! I shouldn't try to understand anything this late...
Well, since I cannot associate the access to the object that shall handle the click event as some user data, I have to set up some map to associate ID or Unique_ID to those object accesses because I don't want to check the IDs in a big if then else or case.
Thanks for your explanations.

Stéphane

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-23 17:41         ` Jeffrey R. Carter
@ 2015-11-23 22:19           ` slos
  0 siblings, 0 replies; 11+ messages in thread
From: slos @ 2015-11-23 22:19 UTC (permalink / raw)


Le lundi 23 novembre 2015 18:41:28 UTC+1, Jeffrey R. Carter a écrit :
> On 11/23/2015 03:44 AM, slos wrote:
> > 
> > Well, that's what I would like to achieve but cannot figure out how.
> > Since what I get in the handler is the whole UI data, how can I figure out which element has triggered the event ?
> 
> You might want to look at the Mine_Detector demo. There's a whole array of
> buttons in there with only one On_Click handler.
> 
> -- 
> Jeff Carter
> "Now look, Col. Batguano, if that really is your name."
> Dr. Strangelove
> 31

Dear Mister Carter,

Thanks for pointing this example.
I've been studying first the tutorials and wanted to go then after to the demos.
But for sure I can learn a lot from them.
I've been also through the tests which are also very informative.

Anyway, I think I've got my answer. Let's see what I can do with it now.

Best regards,
Stéphane


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-23 22:12           ` slos
@ 2015-11-23 23:34             ` David Botton
  2015-11-25  8:00               ` slos
  0 siblings, 1 reply; 11+ messages in thread
From: David Botton @ 2015-11-23 23:34 UTC (permalink / raw)


> Well, since I cannot associate the access to the object that shall handle the click event as some user data, I have to set up some map to associate ID or Unique_ID to those object accesses because I don't want to check the IDs in a big if then else or case.

You actually can associate specific data with any control, just use My_Control.Attribute (Key, Value) and to retrieve in the handler Object.Attribute (Key) of course in this case everything is a string.

Alternatively you could also just extend the controls to include additional fields and then upcast Object to the appropriate extended control type.

David Botton

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Gnoga Callback Handlers with user data
  2015-11-23 23:34             ` David Botton
@ 2015-11-25  8:00               ` slos
  0 siblings, 0 replies; 11+ messages in thread
From: slos @ 2015-11-25  8:00 UTC (permalink / raw)


Le mardi 24 novembre 2015 00:34:10 UTC+1, David Botton a écrit :
> > Well, since I cannot associate the access to the object that shall handle the click event as some user data, I have to set up some map to associate ID or Unique_ID to those object accesses because I don't want to check the IDs in a big if then else or case.
> 
> You actually can associate specific data with any control, just use My_Control.Attribute (Key, Value) and to retrieve in the handler Object.Attribute (Key) of course in this case everything is a string.
> 
> Alternatively you could also just extend the controls to include additional fields and then upcast Object to the appropriate extended control type.
> 
> David Botton

Dear Mister Botton,

I think I prefer this last option but I have to analyse further on.

Thank you very much both for your framework that shines but also for your kind support.

BR,
Stéphane


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-11-25  8:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-22 11:53 Gnoga Callback Handlers with user data slos
2015-11-22 15:42 ` David Botton
2015-11-22 21:44   ` slos
2015-11-23  0:50     ` David Botton
2015-11-23 10:44       ` slos
2015-11-23 17:24         ` David Botton
2015-11-23 22:12           ` slos
2015-11-23 23:34             ` David Botton
2015-11-25  8:00               ` slos
2015-11-23 17:41         ` Jeffrey R. Carter
2015-11-23 22:19           ` slos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox