Home |
Obtaining a Pointer to PegPresentationManager Determining the Position of an Object Using Object Types |
Using Object TypesPegThing maintaines a type value for each object derived from. This value can be used to safely upcast a PegThing * to a pointer to a specific RTPEG-32 control or window type. RTPEG-32 does not internally use the object type value, with the exception of checking the range, which can be above or below TYPE_WINDOW. You can safely create and use your own object types and assign new type values to these classes. If your new object is derived at some point from PegWindow, it should have an object Type >= TYPE_WINDOW. The object type ranges are specified in file Include\Pegtypes.hpp. This is sometimes useful as a debugging aid in addition to the occasional need to upcast a PegThing pointer to a specific derived class pointer. An object type can be queried and set using the PegThing::Type() methods. Derived object types inherit the object type value of their parent. The type value can be overridden if desired by re-assigning the object type after calling the base class constructor. Object type values are divided into two groups. One group is for classes derived from PegWindow, and the other group is for all other object types. When assigning custom object types, one should use the value FIRST_USER_WINDOW_TYPE or FIRST_USER_CONTROL_TYPE as the base. This insures that private type values will be unique and will not overlap on the RTPEG-32 class types. Object type values can be useful when searching child object lists for objects of a certain type, for example PegString objects. This value is also useful when debugging since at times you may have a pointer to a PegThing and wish to know exactly what type of PegThing it points to. After checking the Type() member of a PegThing, one can safely upcast a PegThing pointer to a pointer to a specific RTPEG-32 object type. The possible return values of the Type() function are defined in header file Pegtypes.hpp. The following code fragment illustrates one possible method of locating the status bar attached to a window: PegThing * pTest = First(); // get pointer to first child object while (pTest) // search to the end of list if necessary { if (pTest->Type() == TYPE_STATUS_BAR) { PegStatusBar *p StatBar = (PegStatusBar *) pTest; // use pStatBar to call member functions or change attributes break; // found the status bar, exit the loop } pTest = pTest->Next(); // continue down the list of children } Of course, it is simpler to call the PegWindow member function StatusBar(), which does exactly what is shown above and returns a pointer to the PegStatusBar object if one is found. Determining the Position of an Object
|