From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,41b2c090403fab50 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-15 03:08:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!129.240.148.23!uio.no!ntnu.no!not-for-mail From: Preben Randhol Newsgroups: comp.lang.ada Subject: Re: Creating tempfile takes too long: GNAT or Windows bug? (& GtkAda) Date: Tue, 15 Oct 2002 10:08:42 +0000 (UTC) Organization: Norwegian university of science and technology Message-ID: References: <4a4de33a.0210090358.fc50c13@posting.google.com> <3DA463E8.1080202@cogeco.ca> <3DA5B8E6.3010109@cogeco.ca> <3DAB4A59.6060208@cogeco.ca> NNTP-Posting-Host: kiuk0152.chembio.ntnu.no X-Trace: tyfon.itea.ntnu.no 1034676522 17529 129.241.83.78 (15 Oct 2002 10:08:42 GMT) X-Complaints-To: usenet@itea.ntnu.no NNTP-Posting-Date: Tue, 15 Oct 2002 10:08:42 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:29788 Date: 2002-10-15T10:08:42+00:00 List-Id: Warren W. Gay VE3WWG wrote: > > It was 1.x of some sort. Here is a snippit that bugs me: > > procedure On_Clist2_Select_Row > (Object : access Gtk_Clist_Record'Class; > Params : Gtk.Arguments.Gtk_Args) > is > Row_X : Gint := To_Gint (Params, 1); > -- Rows : Gint := To_Gint (Params, 2); > -- Evt : Gdk_Event := To_Event (Params, 3); > begin > ... > > The Params argument is of type Gtk.Arguments.Gtk_Args. To get the > real args, I have to use a bunch of To_G*() conversion calls. If > the API changes at some later date, this now incorrect code will not > be caught at compile time. This bugs me because, as a GUI, this > error may not be noticed for a long time -- in fact, it is likely > the user will find it instead of me. ;-) Yes I agree with you there. Perhaps this is what you look for: -------------------------------------------------------------------------- -- This small examples show how you can create your own marshallers when -- you want to create a handler for a signal that has no predefined -- marshaller. -- -- NOTE: you should already be quite familiar with how handlers and -- marshallers work in GtkAda before trying to understand this example. -- -- Most of the time, in this case, you should simply create a general -- handler such as defined in the generic packages in Gtk.Handlers, and -- as demonstrated in the first example below. -- In that case, the conversion from C's System.Address types to your own -- types is done directly in your handler. -- -- In other cases, for instance when you reuse the same signal multiple -- times, it might be cleaner to define a marshaller, so that your handlers -- can have typed parameters. This is the second example demonstrated -- below. -- -- This example interfaces to a signal defined in the gtktipsquery.h in the -- gtk+ distribution. The signal is called "widget_entered", and is called to -- display a tooltip every time the pointer enteres a new widget -- The general form for handlers, as defined in the C package is: -- -- void (*widget_entered) (GtkTipsQuery *tips_query, -- GtkWidget *widget, -- const gchar *tip_text, -- const gchar *tip_private); -- -- There is no predefined marshaller for it in gtk-marshallers.ads with Gtk.Arguments; with Gtk.Handlers; with Gtk.Marshallers; with Gtk.Tips_Query; use Gtk.Tips_Query; with Gtk.Widget; use Gtk.Widget; package Own_Marshaller is package Tips_Handlers is new Gtk.Handlers.Callback (Widget_Type => Gtk.Tips_Query.Gtk_Tips_Query_Record); -------------------- -- First solution -- -------------------- -- First and simpler solution: use the general form for handlers, as -- defined in gtk-handlers. -- This does not require anything special, and the conversion of -- arguments will have to be done in the handler itself. -- -- Example of use: -- see general_tips.adb procedure My_General_Tips (Tips : access Gtk_Tips_Query_Record'Class; Params : Gtk.Arguments.Gtk_Args); --------------------- -- Second solution -- --------------------- -- If you want your handlers to directly have the -- correct number of parameters (and correctly typed), you have to -- provide your own marshallers. The subprogram below is the correct -- form for the handler, and the package implements the marshaller. -- -- This solution is more work, but on the other hand is easier to reuse -- when the package below has been written. -- -- Example of use: -- see specific_tips.adb procedure My_Specific_Tips (Tips : access Gtk_Tips_Query_Record'Class; Widget : access Gtk_Widget_Record'Class; Text : String; Tips_P : String); package My_Tips_Marshaller_Pkg is type Handler is access procedure (Tips : access Gtk_Tips_Query_Record'Class; Widget : access Gtk_Widget_Record'Class; Text : String; Tips_P : String); procedure My_Tips_Marshaller (Tips : access Gtk_Tips_Query_Record'Class; Params : Gtk.Arguments.Gtk_Args; Cb : Gtk.Marshallers.General_Handler); function To_Marshaller (Cb : Handler) return Tips_Handlers.Marshallers.Marshaller; end My_Tips_Marshaller_Pkg; end Own_Marshaller; with Gtk.Marshallers; use Gtk.Marshallers; with Unchecked_Conversion; package body Own_Marshaller is --------------------- -- My_General_Tips -- --------------------- procedure My_General_Tips (Tips : access Gtk_Tips_Query_Record'Class; Params : Gtk.Arguments.Gtk_Args) is -- Have to do the conversion by hand Widget : Gtk_Widget := Gtk_Widget (Gtk.Arguments.To_Object (Params, 1)); Text : String := Gtk.Arguments.To_String (Params, 2); Tips_P : String := Gtk.Arguments.To_String (Params, 3); begin null; -- Whatever you want here end My_General_Tips; ---------------------- -- My_Specific_Tips -- ---------------------- procedure My_Specific_Tips (Tips : access Gtk_Tips_Query_Record'Class; Widget : access Gtk_Widget_Record'Class; Text : String; Tips_P : String) is begin null; -- Whatever you want here end My_Specific_Tips; ---------------------------- -- My_Tips_Marshaller_Pkg -- ---------------------------- package body My_Tips_Marshaller_Pkg is function To_Handler is new Unchecked_Conversion (Gtk.Marshallers.General_Handler, Handler); function To_General_Handler is new Unchecked_Conversion (Handler, Gtk.Marshallers.General_Handler); ------------------------ -- My_Tips_Marshaller -- ------------------------ procedure My_Tips_Marshaller (Tips : access Gtk_Tips_Query_Record'Class; Params : Gtk.Arguments.Gtk_Args; Cb : Gtk.Marshallers.General_Handler) is My_Cb : Handler := To_Handler (Cb); begin -- Basically, we do the same thing as in My_General_Tips above My_Cb (Tips, Gtk_Widget (Gtk.Arguments.To_Object (Params, 1)), Gtk.Arguments.To_String (Params, 2), Gtk.Arguments.To_String (Params, 3)); end My_Tips_Marshaller; ------------------- -- To_Marshaller -- ------------------- function To_Marshaller (Cb : Handler) return Tips_Handlers.Marshallers.Marshaller is begin return (Func => To_General_Handler (Cb), Proxy => My_Tips_Marshaller'Access); end To_Marshaller; end My_Tips_Marshaller_Pkg; end Own_Marshaller; ----------------------------------------------------------------------------- It is taken from the examples in the document that comes with the library. > I don't think much of using Gint as a data type, but maybe I am > being fussy. I'd prefer to user more strongly typed data types that > match the parameter or argument's purpose, than any general purpose > argument. If you must, Gint as a base type might be ok. No I use Integer or Natural etc and I do Gint (variable) if needed in function call. Preben -- Ada95 is good for you. http://libre.act-europe.fr/Software_Matters/02-C_pitfalls.pdf