comp.lang.ada
 help / color / mirror / Atom feed
From: njt@sv1pc161.cs.york.ac.uk (Nigel J. Tracey)
To: jamrice7@themall.net (James Rice)
Subject: Re: Using Motif/AXI XmStringTable in ADA
Date: 1997/02/22
Date: 1997-02-22T00:00:00+00:00	[thread overview]
Message-ID: <81ume5.nfm.ln@localhost> (raw)
In-Reply-To: 1997Feb20.201801.29759@relay.nswc.navy.mil


In article <1997Feb20.201801.29759@relay.nswc.navy.mil>,
	jamrice7@themall.net (James Rice) writes:
>Sorry if this is a stupid question, or not phrased well, I am not very 
>experienced with ADA or the AXI bindings.  I do know Motif though.
>
>I am having a problem converting a Motif type to ADA, I am utilizing AXI Motif 
>bindings.  I want to get all selected items from a Listbox widget.  Motif in C 
>would return a StringTable, which is a pointer to some number of XmStrings, 
>which I can traverse like an array, accessing the indivual strings.  With the 
>bindings, I am returned a pointer, but how do I use it?  The relationship 
>between pointers and arrays, is definitely not the same in ADA as it is in C.  
>My question is, how do I get to the individual XmStrings in ADA.  Once I get a 
>XmString, the AXI version of StringGetLtoR( ) will convert the XmString to an 
>ADA String, so that is no problem.  
>
>Thanks in advance for any help,
>Jim.

You can use the generic Interfaces.C.Pointers package to convert
the pointer to an array. The function Interfaces.C.Pointers.Value
will return an array which has one element for each of the XmStrings.

I have done this for XmNchildren resources something like below

with Interfaces.C.Pointers

..

   type Widget_Array_Type is array (Integer range <>) of
      aliased Xt.Intrinsic.Widget;

    function To_Widget is new Ada.Unchecked_Conversion
       (Integer_Access, Xt.Intrinsic.Widget);

   package Widget_List_Package is new Interfaces.C.Pointers
      (Integer, Xt.Intrinsic.Widget, Widget_Array_Type, To_Widget (null));

   Num_Children          : aliased Integer;
   Children              : aliased Xt.Intrinsic.WidgetList;

begin

      Xt.Intrinsic.XtVaGetValues
        (GUI_Widgets.Test,
         Stdarg.Empty &
           XmNnumChildren & To_Integer (Num_Children'Unchecked_Access) &
           XmNchildren & To_Integer (Children'Unchecked_Access) &
         null);

      declare
         Widget_List : Widget_Array_Type (1 .. Num_Children);
         Pointer     : Widget_List_Package.Pointer :=
           Widget_List_Package.Pointer (Children);
         Set_State   : aliased Boolean;
      begin
         Widget_List := Widget_List_Package.Value
                          (Pointer,
                           Interfaces.C.Ptrdiff_t (Num_Children));
         for I in Widget_List'range loop
            Xt.Intrinsic.XtVaGetValues
              (Widget_List (I),
               Stdarg.Empty &
                 XmNset & To_Integer (Set_State'Unchecked_Access) &
               null);
            if Set_State then
               Selected_Test_Type := Execute_Modules.Test_Type'Val (I - 1);
               exit;
            end if;
         end loop;
      end;
..

Hope that helps some,

Nigel

--------------------
Nigel J. Tracey MEng, Research Associate (High Integrity Systems Group).
Department of Computer Science,   Office: X/D016
University of York,               Tel   : [0|+44]1904 432769
York, England.                    E-Mail: njt@minster.york.ac.uk
YO1 5DD.                          URL   : http://sv1pc161.cs.york.ac.uk/~njt





      parent reply	other threads:[~1997-02-22  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-20  0:00 Using Motif/AXI XmStringTable in ADA James Rice
1997-02-21  0:00 ` Christopher Green
1997-02-22  0:00 ` Nigel J. Tracey [this message]
replies disabled

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