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. 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