Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcdc!hpfclp!diamant From: diamant@hpfclp.SDE.HP.COM (John Diamant) Newsgroups: comp.windows.x Subject: Re: Re: XtReparentWidget (How about XtCopyWidget) Message-ID: <9740088@hpfclp.SDE.HP.COM> Date: 6 Apr 89 05:34:04 GMT References: <9941@polyslo.CalPoly.EDU> Organization: HP SESD, Fort Collins, CO Lines: 32 > I was wondering if anybody already had some > sort of general XtCopyWidget routine which could copy an arbitrary > widget. Any ideas on what this would involve. Does the Toolkit contain > enough information in itself about each widget? This would be a simple > solution to the reparent problem. The Toolkit does contain enough information. The size of a widget w can be obtained as follows: XtClass(w)->core_class.widget_size; With that, you can malloc up a suitable sized chunk of memory and do a raw memory copy using bcopy to the new location. Examples of this appear in the Toolkit code already (in Resources.c). So, a general XtCopyWidget routine, would in fact, be very easy to write (about 4 lines of code). In fact, here it is (untested): Widget XtCopyWidget(w) Widget w; { int widgetSize = XtClass(w)->core_class.widget_size; Widget new = (Widget) XtMalloc(widgetSize); bcopy((char *) w, (char *) new, widgetSize); return new; } John Diamant Software Engineering Systems Division Hewlett-Packard Co. ARPA Internet: diamant@hpfclp.sde.hp.com Fort Collins, CO UUCP: {hplabs,hpfcla}!hpfclp!diamant