[gtkada] Passing context objects to handlers via Register_Handler

R. Tyler Croy tyler at monkeypox.org
Mon Jan 9 18:41:30 CET 2017


Before I do something gnarly and add some globals to my application, I'm
curious to learn more about patterns for sharing context with registered
handlers.

I'm using Glade3 and GtkAda (written about a bit here
http://unethicalblogger.com/2017/01/07/updated-glade-gtkada-example.html) and
the Register_Handler procedure for connecting my signals to my callback
procedures, e.g.:


arun.adb

    procedure Main is
      -- snip --
      Register_Handler (Builder      => Builder,
                        Handler_Name => "Main_Quit",
                        Handler      => Arun.Handlers.Quit'Access);
      -- snip --
    end Main;


arun-handlers.adb

   procedure Quit (Object : access Gtkada_Builder_Record'Class) is
      pragma Unreferenced (Object);
   begin
      Ada.Text_IO.Put_Line ("Exiting arun");
      Gtk.Main.Main_Quit;
   end Quit;


The problem I have is that there is shared state which I have in the Main
procedure which I would like to make use of during the handler procedures. My
first attempt was create a new Gtkada_Builder_Record type with a record
extension, but that failed miserably.

Outside of adding a global which I grab across package boundaries, it's not
clear to me how to pass 'context' here :(


Any suggestions or pointers would be most helpful!


Cheers
- R. Tyler Croy

------------------------------------------------------
     Code: <https://github.com/rtyler>
  Chatter: <https://twitter.com/agentdero>
     xmpp: rtyler at jabber.org

  % gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F
------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: </pipermail/gtkada/attachments/20170109/53a8c503/attachment.sig>


More information about the gtkada mailing list