Dr. Dobb's Sourcebook May/June 1997

Property Lists


A property list control is an invaluable asset for manipulating visual object properties. Tools such as Visual Basic often use property lists because they provide immediate feedback about an object's properties. Since such a control was not available, I rolled my own.

At first, I thought of using the Windows 95 list control. However, I became frustrated with it because it required too much effort to customize the capabilities I needed from my property list. So, I decided to use a simple owner-drawn list box instead.

My CPropertyList class (see CPL.H and CPL.CPP, available electronically) is simply a CWnd-derived window object with CHeaderCtrl and CListBox extensions; that is, CHeaderWnd (CHW.H and CHW.CPP) and CListWnd (CLW.H and CLW.CPP) as children; see Figure 6. (At this time, CHeaderWnd does not do anything useful.)

I set up the header control with two columns and handled the track notification messages sent by it in CPropertyList (to adjust the owner-drawn columns of CListWnd).

The CListWnd class is CProperty aware. Hence, it knows how to display both the property name and the property data. Items stored in the owner-drawn list box are of type CProperty*. Cooperating with the property objects, the list box helps the property list provide the appropriate user interface for manipulating the properties. For simple property data types, the user clicks in the data value column of the property being changed; an edit control pops up, and the user can enter data. For color values (COLORREF) and file names (CString), users click the button at the right edge of the property value column to bring up the appropriate common dialogs. In the future, I will do something similar for handling font information. If implicit validation has been enabled through the range (VT_RANGE) or choice (VT_CHOICE) specifiers, a choice menu pops up when the button provided is clicked.

With the help of the Properties() method, which must be implemented by all CControlData-derived data objects, the property list can be initialized in one shot with the properties of any compliant object, easing the synchronization of the control with the selected object in the design view of VUIM.

When users change a property through the property list, a notification is sent to the VUIM main window. The main window, in turn, forwards this request to the document object, which then takes care of updating the design view for the currently selected object. It does so by calling the required ApplyProperties() override for the visual data object and forcing a repaint. The OnUpdate() method for the "design view" in Listing Thirteen makes this clearer. The object that changed and the property data modification that caused the change are passed in as hints by the document, so that the view may be optimally refreshed as desired.

Similarly, when a user moves or sizes an object, the property list is refreshed by calling the UpdatePropertyList() method of the design view class CVuimDesignView, which passes on the request to the document class CVuimDoc method RefreshPL().

-- S.D.

Back to Article