erose@hydro.Stanford.EDU (Eric Rose) (06/28/91)
I seem to have found a problem storing a pointer with a Panel using XV_KEY_DATA. The manual does not explicitly state that this is possible for all xview objects, but then again is does not give any reason why this is not possible. I am running xview 2.0 (I think) under openwin 2.0 on a Sparc 2, SunOS 4.1.1 The code prints the string correctly while in main, but in the button callback prints garbage for the string. ------------------------------------------------------------------------------- #include <xview/xview.h> #include <xview/frame.h> #include <xview/panel.h> #include <stdio.h> Frame frame; Panel panel; char *string = "Hello World"; void button_cb(); main(argc,argv) int argc; char *argv[]; { xv_init(XV_INIT_ARGC_PTR_ARGV,&argc,argv,NULL); frame = (Frame)xv_create(NULL, FRAME, FRAME_LABEL, "Test", XV_WIDTH, 200, XV_HEIGHT, 100, NULL); printf("The string is: \"%s\"\n",string); panel = (Panel)xv_create(frame, PANEL, XV_KEY_DATA, 1, string, NULL); printf("The string still is: \"%s\"\n",string); xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Verify & Quit", PANEL_NOTIFY_PROC, button_cb, NULL); xv_main_loop(frame); exit(0); } void button_cb(item,event) Panel_item item; Event *event; { printf("The string now is \"%s\"\n",(char*)xv_get(panel,XV_KEY_DATA,1)); xv_destroy_safe(frame); } -------------------------------------------------------------------------------
naftaly@dazixco.ingr.com (Naftaly Stramer) (06/28/91)
In article <1991Jun27.221718.18172@leland.Stanford.EDU>, erose@hydro.Stanford.EDU (Eric Rose) writes: |> |> |> I seem to have found a problem storing a pointer with a Panel using |> XV_KEY_DATA. The manual does not explicitly state that this is possible |> for all xview objects, but then again is does not give any reason why |> this is not possible. |> |> I am running xview 2.0 (I think) under openwin 2.0 on a Sparc 2, SunOS 4.1.1 |> |> The code prints the string correctly while in main, but in the button callback |> prints garbage for the string. |> |> ------------------------------------------------------------------------------- If you attach the XV_KEY_DATA to the button it will work. panel = (Panel)xv_create(frame, PANEL, NULL); printf("The string still is: \"%s\"\n",string); xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Verify & Quit", PANEL_NOTIFY_PROC, button_cb, XV_KEY_DATA, 1, string, NULL); xv_main_loop(frame); exit(0); } void button_cb(item,event) Panel_item item; Event *event; { printf("The string now is \"%s\"\n",(char*)xv_get(item,XV_KEY_DATA,1)); xv_destroy_safe(frame); } -- Naftaly Stramer (303)581-1477 DAZIX, An Intergraph Company Internet: naftaly@dazixco.ingr.com 6285 Lookout Road UUCP: ..uunet!ingr!dazixco!naftaly Boulder, CO 80301 Please excuse my english -- Naftaly Stramer (303)581-1477 DAZIX, An Intergraph Company Internet: naftaly@dazixco.ingr.com 6285 Lookout Road UUCP: ..uunet!ingr!dazixco!naftaly Boulder, CO 80301 Please excuse my english
helvie@EBay.Sun.COM (Fred Helvie) (06/28/91)
when applying XV_KEY_DATA, the key specified should be a unique number. A number >= 100 should be safe. The reason for this is that the toolkit utilizes some of the lower keys internally. So try: #define MY_KEY 100 panel = (Panel)xv_create(frame, PANEL, XV_KEY_DATA, MY_KEY, string, NULL); printf("The string now is \"%s\"\n",(char*)xv_get(panel,XV_KEY_DATA,MY_KEY)); Fred Helvie Sun Education - Milpitas, CA.
thebaut@infinet.UUCP (Suzanne Thebaut) (06/28/91)
In article <1991Jun27.221718.18172@leland.Stanford.EDU> erose@hydro.Stanford.EDU (Eric Rose) writes: > > >I seem to have found a problem storing a pointer with a Panel using >XV_KEY_DATA. The manual does not explicitly state that this is possible >for all xview objects, but then again is does not give any reason why >this is not possible. > ... > > panel = (Panel)xv_create(frame, PANEL, > XV_KEY_DATA, 1, string, > NULL); Eric- It might work better if you set the XV_KEY_DATA in a call to xv_set() AFTER the call to xv_create() which creates the panel. I have found xview to be flukey in that regard. Sometimes things just don't take if they are assigned in the create, and other things don't take if they are assigned after the create, and still other things don't work quite right if they are created after the call to xv_main_loop(). Anyway, that's my suggestion. Good Luck. -Suzanne ##################################################################### Suzanne Thebaut infinet!thebaut@samsung.com Memotec, Inc N. Andover, MA 508 681-0600 x4430 Newsgroups: alt.toolkits.xview,comp.windows.open-look Subject: Re: problem attaching XV_KEY_DATA to panel References: <1991Jun27.221718.18172@leland.Stanford.EDU> Reply-To: thebaut@infinet.UUCP (Suzanne Thebaut) Organization: Memotec, Inc. North Andover, MA In article <1991Jun27.221718.18172@leland.Stanford.EDU> erose@hydro.Stanford.EDU (Eric Rose) writes: > > >I seem to have found a problem storing a pointer with a Panel using >XV_KEY_DATA. The manual does not explicitly state that this is possible >for all xview objects, but then again is does not give any reason why >this is not possible. > ... > > panel = (Panel)xv_create(frame, PANEL, > XV_KEY_DATA, 1, string, > NULL); Eric- It might work better if you set the XV_KEY_DATA in a call to xv_set() AFTER the call to xv_create() which creates the panel. I have found xview to be flukey in that regard. Sometimes things just don't take if they are assigned in the create, and other things don't take if they are assigned after the create, and still other things don't work quite right if they are created after the call to xv_main_loop(). Anyway, that's my suggestion. Good Luck. -Suzanne ##################################################################### Suzanne Thebaut infinet!thebaut@samsung.com Memotec, Inc N. Andover, MA 508 681-0600 x4430
thebaut@infinet.UUCP (Suzanne Thebaut) (06/28/91)
In article <helvie.678067565@silverwood> helvie@EBay.Sun.COM (Fred Helvie) writes: > > >when applying XV_KEY_DATA, the key specified should be a unique >number. A number >= 100 should be safe. >The reason for this is that the toolkit utilizes some of the lower keys >internally. So try: > > >#define MY_KEY 100 Alternatively, devguide uses a call to xv_unique_key() to generate unique numbers of type Attr_attribute for use as keys w/ XV_KEY_DATA: ------------------------------------------------------------------ Attr_attribute MY_KEY; ... Panel panel; char *string = "Hello"; main() { xv_init( ... ); MY_KEY = xv_unique_key(); ... panel = xv_create( ... ); xv_set( panel, XV_KEY_DATA, MY_KEY, string, NULL ); ... } ------------------------------------------------------------------- -Suzanne ################################################################### Suzanne Thebaut infinet!thebaut@samsung.com Memotec, Inc. N. Andover, MA (508) 681-0600 x4430
ed@Canada.Sun.COM (Edward Lycklama - KL Group Inc.) (06/28/91)
> > I seem to have found a problem storing a pointer with a Panel using > XV_KEY_DATA. The manual does not explicitly state that this is possible > for all xview objects, but then again is does not give any reason why > this is not possible. > > I am running xview 2.0 (I think) under openwin 2.0 on a Sparc 2, SunOS 4.1.1 > > The code prints the string correctly while in main, but in the button callback > prints garbage for the string. > One of the problems with XV_KEY_DATA is that the key must be unique - if you try with a more random key, you'll find that it works. I suspect you're using a key that the panel package is already using for something else. Ed Lycklama KL Group Inc. | Phone: (416) 594-1026 Ext. 24 134 Adelaide St. E, Suite 204 | Fax: (416) 594-1919 Toronto, Ontario, M5C 1K9 | UUCP: sun!suncan!klg!ed CANADA
fgreco@Unify.Com (06/28/91)
> I seem to have found a problem storing a pointer with a Panel using > XV_KEY_DATA. The manual does not explicitly state that this is possible > for all xview objects, but then again is does not give any reason why > this is not possible. Don't use 1 for a key. Change it to something like 1000 and it works fine. Frank G.
chuck@pluto.Harris-ATD.com (Chuck Musciano) (06/29/91)
In article <1991Jun27.221718.18172@leland.Stanford.EDU>, erose@hydro.Stanford.EDU (Eric Rose) writes: > I seem to have found a problem storing a pointer with a Panel using > XV_KEY_DATA. The manual does not explicitly state that this is possible > for all xview objects, but then again is does not give any reason why > this is not possible. > > I am running xview 2.0 (I think) under openwin 2.0 on a Sparc 2, SunOS 4.1.1 > > The code prints the string correctly while in main, but in the button callback > prints garbage for the string. > > panel = (Panel)xv_create(frame, PANEL, > XV_KEY_DATA, 1, string, > NULL); It is not a good idea to use arbitrary key values with XV_KEY_DATA. I think the toolkit uses a few keys for its own use, and you may be hitting those keys. A better way to do this: Attr_attribute THE_STRING; THE_STRING = xv_unique_key(); panel = (Panel)xv_create(frame, PANEL, XV_KEY_DATA, THE_STRING, string, NULL); and then later printf("The string is %s\n", xv_get(panel, XV_KEY_DATA, THE_STRING)); -- Chuck Musciano ARPA : chuck@trantor.harris-atd.com Harris Corporation Usenet: ...!uunet!x102a!trantor!chuck PO Box 37, MS 3A/1912 AT&T : (407) 727-6131 Melbourne, FL 32902 FAX : (407) 729-3363 A good newspaper is never good enough, but a lousy newspaper is a joy forever. -- Garrison Keillor