Query: class_part_initialize
OS: hpux
Section: 4
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
class_part_initialize() class_part_initialize() Name class_part_initialize - Object class method to initialize class part structure fields. Synopsis typedef void (*XtWidgetClassProc)(WidgetClass); WidgetClass subclass; Inputs subclass Specifies the pointer to a widget class structure. It is the class that registered this method or a subclass thereof. Description The class_part_initialize() method is registered on the class_part_initialize field of the Object, RectObj, or Core class structure, and is called to dynamically initialize any fields in the class part structure of its widget class. During class initialization, the class_part_initialize() method for the class and for all its superclasses is called in superclass-to-sub- class order on the class record. These procedures do any dynamic initializations necessary to their class's part of the record, including resolution of any inherited methods defined in the class. For example, if a widget class C has superclasses Core, Composite, A, and B, then the class record for C is passed first to Core's class_part_initialize() method. This resolves any inherited Core methods and com- piles the textual representations of the resource list and action table that are defined in the Core class part. Next, the Composite's class_part_initialize() is called to initialize the Composite part of C's class record. Finally, the class_part_initialize() procedures for A, B, and C (in order) are called. All these methods will be called again if subclass D of class C is initialized, this time to ini- tialize the various parts of D's class structure. The class_part_initialize() method is chained in superclass-to-subclass order and cannot be inherited. Classes that do not define any new class fields or that need no extra processing for them can set their class_part_initialize field to be NULL. See the "Background" section below for more details on when class initialization is performed. Usage The subclass argument to a class_part_initialize() procedure may be the widget class itself, or any subclass of it. You should cast it to a pointer to your widget class and use that pointer to access the fields of the class part structure that your class defines. If you need to access the superclass, use the superclass field in the Object, RectObj, or Core class part. This is shown in the example below. The most common usage of the class_part_initialize() method is to handle inheritance of class methods and other fields. If you define a class with a method or other field that can be inherited, you should define a special value that the writer of the subclass can use to inherit the field (use the constant _XtInherit cast to the appropriate type, as shown in the example below) and provide a class_part_ini- tialize() method which checks the inheritable field for this special value and overwrites it with the contents of the superclass's field. Example The following procedure is the class_part_initialize() method for the Xaw Form widget class. Note how it determines the immediate super- class and handles the inheritance of the Form layout() class method. Note that it does not initialize the Core, Composite, or Constraint class part fields, nor does it make any assumptions about its Widget- Class argument except that it is a subclass of Form. Also note that when this method is called for the Form widget class itself, the vari- able super will be set to the superclass of Form, which cannot correctly be cast to FormWidgetClass. This is a bug, but will never cause problems, because the Form class itself will never have to inherit any fields. Note that the identifier class is a reserved word in C++, and your code will be more portable if you avoid using it as an argument name in C code. static void ClassPartInitialize(class) WidgetClass class; { register FormWidgetClass c = (FormWidgetClass)class; register FormWidgetClass super = (FormWidgetClass) c->core_class.superclass; if (c->form_class.layout == XtInheritLayout) c->form_class.layout = super->form_class.layout; } The constant XtInheritLayout is defined as follows (in <X11/Xaw/FormP.h>): #define XtInheritLayout ((Boolean (*)())_XtInherit) Background All widget classes, whether or not they have class and class part initialization procedures, must start with their class_inited field False. The first time a widget of a class is created, XtCreateWidget() ensures that the widget class and all superclasses are initialized, in superclass-to-subclass order, by checking each class_inited field. If this field is False, XtCreateWidget() calls the class_initialize() and the class_part_initialize() methods for the class and all its superclasses. The Intrinsics then set the class_inited field to a nonzero value. After the one-time initialization, a class structure is constant. This initialization can also be performed explicitly, without creating a widget, by calling XtInitializeWidgetClass(). See Also XtInitializeWidgetClass(1), Core(3), class_initialize(4), initialize(4). Xt - Intrinsics Methods class_part_initialize()