# Inheritance

Microsoft® Office Visio® 2003 shapes can inherit sections, rows, and cells from parent sheets. A Shape element that inherits from a Master element is called an instance of the Master element. An instance inherits all the elements of the master. Additionally, a Shape element can inherit from a StyleSheet element and inherit the style's line, fill, and text properties. (A Master element doesn't inherit styles, but the PageSheet or Shape elements contained in them do.) A StyleSheet and PageSheet element can also inherit from another StyleSheet element.

The inheritance relationships are established in a DatadiagramML file by means of attributes. The following table describes the attributes used to establish inheritance between a shape, a master, and a style. (Some of the attributes listed in the table are also associated with other elements. For example, the Page element also has an ID attribute that identifies it within its container, but it is unrelated to inheritance.)

Attribute | In element | Attribute description
--- | --- | ---
ID | Master and StyleSheet | A unique ID within the object's container. An integer value.
Master | Shape | The ID of the master that the shape inherits from. Top-level shapes on a page that are instances of a master must have a valid Master attribute. Mutually exclusive with the MasterShape attribute.
MasterShape | Shape | The ID of a shape in a Master element that this shape inherits. Establishes a link between an instance of a shape and its master shape. Subshapes of an instance group shape must have this attribute. Mutually exclusive with the Master attribute.
LineStyle | Shape, StyleSheet, PageSheet, DocumentSheet | ID of the StyleSheet element from which this element inherits line formatting.
FillStyle | Shape, StyleSheet, PageSheet, DocumentSheet | ID of the StyleSheet element from which this element inherits fill formatting.
TextStyle | Shape, StyleSheet, PageSheet, DocumentSheet | ID of the StyleSheet element from which this element inherits text formatting.
Del | Shape | Del is a boolean attribute. It is only meaningful if the shape is part of a master instance. If 1 (true), the shape instance is deleted locally.

## Master and MasterShape attributes

Shape elements use the Master and MasterShape attributes to establish inheritance from a Master element. For example, a shape that inherits from a master has a Master attribute whose value is the ID of the Master element. The Shape element inherits all the subelements of the Shape element contained in the Master element.

A Master element is often composed of one Shapes element that contains multiple Shape elements that can, in turn, contain additional Shapes elements. The IDs of a Master element's shapes and subshapes are all unique within the Master element. In an instance of a master, the master's subshapes can be re-expressed for the purposes of local overrides or local deletions. However, each of those subshapes must have its own ID attribute that is unique within the instance's page.

To maintain a link back to the Master element's shapes, overridden shapes must have a separate attribute called MasterShape. The value of this attribute is the ID of the Shape in the Master that this local shape is overriding.

For example, consider the following code, which describes a master that is a group:

    <Master ID='4' NameU='MasterShapeExample' ...>
       ...
       <Shapes>
          <Shape ID='5' Type='Group'>
             ...
             <Shapes>
                <Shape ID='6' Type='Shape'>
                   ...
                   <Fill>
                      <FillForegnd>2</FillForegnd>
                      ...
                   </Fill>
                   ...
                </Shape>
                ...
             </Shapes>
          </Shape>
       </Shapes>
    </Master>

The following code shows how to create an instance of the previous master that contains a local shape that overrides the fill formatting of one of the subshapes in that master. (Note that this example uses the MasterShape attribute to refer to the previous master.)

    <Shape ID='10' NameU='MasterShapeExample' Type='Group' Master='4'>
       ...
       <Shapes>
          <Shape ID='11' Type='Shape' MasterShape='6'>
             ...
             <Fill>
                <FillForegnd>3</FillForegnd>
                ...
             </Fill>
          </Shape>
       </Shapes>
    </Shape>

## FillStyle, LineStyle, and TextStyle attributes

A Shape, PageSheet, DocumentSheet, or StyleSheet element can inherit styles from up to three other StyleSheet elements. Three attributes of a sheet element— FillStyle, TextStyle, and LineStyle— can refer to a StyleSheet element by ID. When a sheet element inherits from a StyleSheet element, it inherits only elements relevant to the attribute. For example, when a Shape element contains a TextStyle attribute, it inherits only elements that affect text, such as Para, Char, Tabs, and TextBlock.

If an instance does not specify a particular style-inheritance attribute, it inherits the styles that attribute defines from the master shape, or from the style that master shape inherits. If a non-instance does not specify a particular style-inheritance attribute, Style 0 is used. (Style 0 is defined by the default document and cannot be modified in the user interface or by Automation.)

## Local overrides

A Shape element that inherits from a Master element is called an instance of the Master. An instance inherits all the elements of the master. Therefore, the instance in a DatadiagramML file does not explicitly express the elements that it inherits. By locally overriding an element, you can block inheritance of that element.

Consider the following XML:

    <Master ID='0'>
       ...
       <XForm>
          <PinX> 1.0 </PinX>
          <PinY> 2.0 </PinY>
       </XForm>
       ...
    </Master>
    ...
    <Shape ID='99' Master='0'/>

Shape 99 inherits all the elements of Master 0. It does not explicitly express its PinX and PinY elements, but the Shape element behaves as if they were present. If a Shape element does explicitly express an inherited element, that component is locally overridden in the instance. Consider the following code:

    <Master ID='0'>
       ...
       <XForm>
          <PinX> 1.0 </PinX>
          <PinY> 2.0 </PinY>
       </XForm>
       ...
    </Master>
    ...
    <Shape ID='99' Master='0'>
       <XForm>
          <PinX> 2.0 </PinX>
       </XForm>
    </Shape>

In this case, Shape 99 still inherits its master's PinY element value, but it has locally overridden the value of PinX to 2.0.

## Local deletion

A Shape element can also suppress the appearance of an element in an instance. When an instance suppresses a component, that component is locally deleted. Consider this example:

    <Master ID='0'>
       <Shapes>
          <Shape ID='5' Type='Group' ...>
             <Shapes>
                <Shape ID='6' Type='Shape' ...>
                ...
                </Shape>
                <Shape ID='7' Type='Shape' ...>
                ...
                </Shape>
             </Shapes>
          </Shape>
       </Shapes>
    </Master>

In this case, the Master element is a group that contains two shapes. To suppress one of the shapes on the shape instance, use the Del attribute. For example, the following would suppress a shape (ID='2') in the instance of the group:

    <Shapes>
       <Shape ID='1' Type='Group' Master='0'>
          ...
          <Shapes>
             <Shape ID='2' Type='Shape' MasterShape='6' Del='1'>
             ...
             </Shape>
             <Shape ID='3' Type='Shape' MasterShape='7'>
             ...
             </Shape>
          </Shapes>
       </Shape>
    </Shapes>

## Inheritance states

The following table describes all the possible inheritance states in which the sheet elements can exist.

XML example | Description of inheritance state
--- | ---
empty | Represents full inheritance. If a sheet element inherits its state fully from its parent, the element simply does not appear within the instance.
`<Geom IX='1' Del='1'/>` | A section (represented by the Geom element) is locally deleted. This means that the section has been severed locally, blocking inheritance of the section and all its children.
`<Geom IX ='1'/>` | A section is local, but its children are inherited from the master.
`<Geom IX ='1'>` `<LineTo IX ='2' Del='1'/>` `</Geom>` | A row (represented by the LineTo element) is locally deleted. The row has been severed locally, blocking inheritance of the row and its children.
`<PinX F='Inh'> 20 </PinX>` | A locally overridden value.
`<PinX F='Inh' Err='#NUM!'> 20 </PinX>` | A locally overridden value. The Err attribute value has also been overridden. The formula (represented by the F attribute) is inherited from the parent.
`<PinX> 20 </PinX>` | The most common case. The formula is a constant value. The value is a number and the F attribute is not present.
`<PinX F='Height*2'> 20 </PinX>` | The formula is a complex expression represented by a string that is not empty and not the string "No Formula". The value contains a number, which is the last valid value.
`<PinX F='Height/0' Err='#DIV/0!'> 20 </PinX>` | The formula is a complex expression represented by a string that is not empty and not the string "No Formula". The value contains a number, which is the last valid value. The Err attribute is also present and contains a string representing the error state.

Note Every Visio document is based on a default document with a built-in StyleSheet element with the ID of 0. Style 0 is defined by the default document and cannot be modified in the user interface or through Automation. If a sheet does not explicitly inherit from a Master or StyleSheet element, it implicitly inherits from StyleSheet ID = '0'. All absent document-level elements also inherit from Style 0.

When Visio reads a DatadiagramML file, it ignores any StyleSheet element with the ID = '0'. It always uses its built-in Style 0 when loading a DatadiagramML file.

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp