Microsoft Office Professional Developer Portal
 Print Print
Average Rating: 4.8/5 | Rate this item | 5 users have rated this item.
Designing Smart Documents in Office 2003 (cont'd)
Implementing XMLType Definitions
At this point you have created all the XMLTypes and their associated ISmartControl instances. Note that so far, there's been no rendering or creation of physical controls.


After initialization the API calls the SmartXMLTypeCount method of the ISmartDocument interface within CustomerDocument.vb. In this case, because you have three types the return value should be 3. The types Hashtable contains the list of these types so a simple Count function returns the number of items stored in the collection.

   Public Shared Function Count() As Integer
      Return types.Count
   End Function
Next, the API calls the SmartDocXmlTypeName and SmartDocXmlTypeCaption for each type. In these methods you make calls to DocumentUtils.Name and DocumentUtils.Caption.

In each of these cases the XMLTypeID used will be iterative. The order of the calls follows the sequence shown in Table 3.

Table 3. Method Call Sequence. The Office API calls these methods in sequence for the three XmlTypes defined in the sample application.
Method XMLTypeID Value
SmartDocXmlTypeName 1 http://Officesamples/Customer/2004#documentRoot
SmartDocXmlTypeCaption 1 Root content
SmartDocXmlTypeName 2 http://Officesamples/Customer/2004#region
SmartDocXmlTypeCaption 2 Region selection
SmartDocXmlTypeName 3 http://Officesamples/Customer/2004#itemname
SmartDocXmlTypeCaption 3 Item Selection

Remember that the SmartType stores the return values for Caption and Name while initializing each XmlType instance.

   Public Shared Function Name( _
      ByVal XMLTypeId As Integer) As String
      Dim XMLTypeName As String = GetTypeName(XMLTypeId)
         If types.ContainsKey(XMLTypeName) Then
            Return XMLTypeName
         End If
   End Function 
The preceding snippet uses the GetTypeName(XMLTypeId) call to fetch the XMLTypeName for the XMLTypeID. The XMLTypeName is the key for the types hashtable, from which you retrieve the appropriate SmartNode and its corresponding Caption/Name.

Previous Page: Initializing the Document Next Page: Implementing Control Definitions


Page 1: IntroductionPage 7: Implementing Control Definitions
Page 2: Getting StartedPage 8: Rendering and Populating Controls
Page 3: Applying SchemaPage 9: Populating ComboBoxes in the Itemname and Region Nodes
Page 4: Writing SmartDocument Managed CodePage 10: Reading Values from SmartDocuments
Page 5: Initializing the DocumentPage 11: Creating a Manifest
Page 6: Implementing XMLType Definitions