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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9ed4deecbbd3a4b3 X-Google-Attributes: gid103376,public X-Google-Thread: 10b6ac,9ed4deecbbd3a4b3 X-Google-Attributes: gid10b6ac,public From: njt@sv1pc161.cs.york.ac.uk (Nigel J. Tracey) Subject: Re: Using Motif/AXI XmStringTable in ADA Date: 1997/02/22 Message-ID: <81ume5.nfm.ln@localhost>#1/1 X-Deja-AN: 220660896 Distribution: inet References: <1997Feb20.201801.29759@relay.nswc.navy.mil> To: jamrice7@themall.net (James Rice) Organization: The University of York, UK Newsgroups: comp.lang.ada,comp.windows.x.motif Date: 1997-02-22T00:00:00+00:00 List-Id: 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