XtCreateWidget(3)
π NAME π
XtCreateWidget, XtVaCreateWidget, XtCreateManagedWidget, XtVaCreateManagedWidget, XtDestroyWidget β create and destroy widgets π (yes bestie, this is the page from the XT FUNCTIONS chapter, and we're making widgets fr fr)
β¨ SYNTAX β¨
First things first, you gotta bring in the header, no cap:
#include <X11/Intrinsic.h>
Then the whole squad, exactly as they are:
Widget XtCreateWidget(const char *name, WidgetClass widget_class, Widget
parent, ArgList args, Cardinal num_args);
Widget XtVaCreateWidget(const char *name, WidgetClass widget_class,
Widget parent, ...);
Widget XtCreateManagedWidget(const char *name, WidgetClass widget_class,
Widget parent, ArgList args, Cardinal num_args);
Widget XtVaCreateManagedWidget(const char *name, WidgetClass
widget_class, Widget parent, ...);
void XtDestroyWidget(Widget w);
π«Ά ARGUMENTS π«Ά
argsβ the argument list that overrides the resource defaults. it's giving "here's my custom vibe" energy πnameβ the resource name for the widget you're creating. it's used for retrieving resources, so do not name it the same as any other widget that's a child of the same parent. like, that's the one rule okay πnum_argsβ how many arguments are in that argument list, bestie. count them. fr.parentβ the parent widget. every main character needs a supporting cast π«Άwβ the widget. just... the widget.widget_classβ the widget class pointer for the widget you're creating π...β the variable argument list that overrides the resource defaults. the mysterious one. the icon β¨
π DESCRIPTION π
So XtCreateWidget does a whole bunch of the boilerplate widget-creation chores for you, and honestly? it ate. here's the rundown:
- It checks whether the
class_initializeprocedure has been called for this class and for all its superclasses, and if not, it calls the ones that are necessary in a superclass-to-subclass order. like, hierarchy first, always π - It allocates memory for the widget instance.
- If the parent is a subclass of
constraintWidgetClass, it allocates memory for the parent's constraints and stores the address of that memory into theconstraintsfield. - It initializes the core nonresource data fields β for example,
parentandvisible. - It initializes the resource fields β for example,
background_pixelβ by using the resource lists specified for this class and all its superclasses. - If the parent is a subclass of
constraintWidgetClass, it initializes the resource fields of the constraints record by using the constraint resource list specified for the parent's class and all superclasses up toconstraintWidgetClass. - It calls the initialize procedures for the widget, starting at the
Coreinitialize procedure and going on down to the widget's own initialize procedure. - If the parent is a subclass of
compositeWidgetClass, it puts the widget into its parent's children list by calling its parent'sinsert_childprocedure. for further information, see Section 3.5. - If the parent is a subclass of
constraintWidgetClass, it calls the constraint initialize procedures, starting atconstraintWidgetClassand going on down to the parent's constraint initialize procedure.
Note that you can figure out the number of arguments in an argument list by using the XtNumber macro. for further information, see Section 11.1. (macro girlies stay winning β¨)
XtCreateManagedWidget is the convenience routine bestie β it calls XtCreateWidget and XtManageChild. one call, two jobs, slay π
π XtDestroyWidget β the destroy arc π
XtDestroyWidget is the only method of destroying a widget, including widgets that need to destroy themselves. it can be called at any time, including from an application callback routine of the widget that's being destroyed. and the reason it can do that is a two-phase destroy process, because dangling references to destroyed widgets are NOT the vibe. we simply do not do those.
Phase one πΈ
In phase one, XtDestroyWidget does this:
- If the
being_destroyedfield of the widget isTrue, it returns immediately. bye π - It recursively descends the widget tree and sets the
being_destroyedfield toTruefor the widget and all its children. - It adds the widget to a list of widgets (the destroy list) that should be destroyed when it's safe to do so.
Entries on the destroy list satisfy the invariant that if w2 occurs after w1 on the destroy list, then w2 is not a descendent of w1. (and just so we're clear, "a descendant" here refers to both normal and pop-up children, okay? both kinds π)
Phase two π
Phase two happens when all procedures that should execute as a result of the current event have been called β that includes all procedures registered with the event and translation managers β that is, when the current invocation of XtDispatchEvent is about to return, or immediately if you're not in XtDispatchEvent.
In phase two, XtDestroyWidget performs the following on each entry in the destroy list:
- It calls the destroy callback procedures registered on the widget (and all descendants) in post-order β meaning it calls children callbacks before parent callbacks. children first, always π«Ά
- If the widget's parent is a subclass of
compositeWidgetClassand if the parent is not being destroyed, it callsXtUnmanageChildon the widget and then calls the widget's parent'sdelete_childprocedure (see Section 3.4). - If the widget's parent is a subclass of
constraintWidgetClass, it calls the constraint destroy procedure for the parent, then the parent's superclass, until finally it calls the constraint destroy procedure forconstraintWidgetClass. - It calls the destroy methods for the widget (and all descendants) in post-order. for each such widget, it calls the destroy procedure declared in the widget class, then the destroy procedure declared in its superclass, until finally it calls the destroy procedure declared in the
Coreclass record. - It calls
XDestroyWindowif the widget is realized (that is, it has an X window). and the server recursively destroys all descendant windows. cascade queen π - It recursively descends the tree and deallocates all pop-up widgets, constraint records, callback lists and, if the widget is a subclass of
compositeWidgetClass, children.
π SEE ALSO π
XtAppCreateShell(3),XtCreatePopupShell(3)X Toolkit Intrinsics - C Language InterfaceXlib - C Language X Interface
okay that's the whole page bestie, go forth and build widgets responsibly πβ¨
X Version 11 Β· libXt 1.3.1 Β· and yeah, this was XtCreateWidget(3) the whole time ππ¦ no cap, mwah π
π¦ where this page comes from
- alpine 3.22: libxt-doc 1.3.1-r0 Β· MIT
- alpine 3.23: libxt-doc 1.3.1-r0 Β· MIT
- alpine 3.24: libxt-doc 1.3.1-r0 Β· MIT
- arch rolling: libxt 1.3.1-1 Β· MIT AND HPND-sell-variant AND SMLNJ AND MIT-open-group AND X11
- fedora 43: libXt-devel 1.3.1-3.fc43 Β· MIT AND HPND-sell-variant AND SMLNJ AND MIT-open-group AND X11
- fedora 43: libXt-devel 1.3.1-3.fc43 Β· MIT AND HPND-sell-variant AND SMLNJ AND MIT-open-group AND X11
- fedora 44: libXt-devel 1.3.1-4.fc44 Β· MIT AND HPND-sell-variant AND SMLNJ AND MIT-open-group AND X11
- fedora 44: libXt-devel 1.3.1-4.fc44 Β· MIT AND HPND-sell-variant AND SMLNJ AND MIT-open-group AND X11
- opensuse-leap 16.0: libXt-devel 1.3.1-160000.3.2 Β· MIT
- opensuse-leap 16.0: libXt-devel 1.3.1-160000.3.2 Β· MIT
- opensuse-leap 16.0: libXt-devel 1.3.1-160000.3.2 Β· MIT
- opensuse-leap 16.0: libXt-devel 1.3.1-160000.3.2 Β· MIT
- Copyright 1993 X Consortium
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms