/*********************************************************************/
/* */
/* AgentService Framework */
/* www.agentservice.it */
/* */
/* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */
/* GNU Lesser General Public License */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation, */
/* version 2.1 of the License. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the */
/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/* */
/*********************************************************************/
// AddingACustomProperty.cs
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This file contains the AddingACustomProperty class.
using System;
using Microsoft.Office.Interop.Visio;
namespace lido.VSVisioEditor
{
/// This class demonstrates how to add a new custom property for the shape.
public class AddingACustomProperty
{
/// This method is the class constructor.
public AddingACustomProperty()
{
// No initialization is required.
}
/// This method creates a custom property for the shape that
/// is passed in as a parameter.
/// Shape to which the custom property is
/// to be added
/// Local name for the row. This name will
/// appear in custom properties dialog for users running in developer
/// mode.
/// Universal name of the custom property to be
/// created
/// Label of the custom property
/// Type of the value of the custom property.
/// Not all VisCellVals constants are valid for this parameter. Only
/// constants that start with visPropType make sense in this context.
///
/// Format of the custom property
/// Prompt for the custom property
/// Value of the "Ask On Drop" check box of the
/// custom property. Only seen in developer mode
/// Value of the "Hidden" check box of the custom
/// property. Only seen in developer mode
/// Value of the Sort key of the custom property.
/// Only seen in developer mode
/// True if successful; false otherwise
public bool AddCustomProperty(Shape addedToShape, string localRowName, string rowNameU, string labelName, VisCellVals propType, string format, string prompt, bool askOnDrop, bool hidden, string sortKey)
{
const string CUST_PROP_PREFIX = "Prop.";
Cell shapeCell;
short rowIndex;
StringValueInCell formatHelper;
bool returnValue = false;
if (addedToShape == null)
{
return false;
}
try
{
formatHelper = new StringValueInCell();
// Add a named custom property row. In addition to adding a row
// with the local name, specified via localRowName parameter,
// this call will usually set the universal name of the new row
// to localRowName as well. However, the universal row name
// will not be set if this shape already has a custom property
// row that has the universal name equal to localRowName.
rowIndex = addedToShape.AddNamedRow((short)(VisSectionIndices.visSectionProp),localRowName, (short)(VisRowIndices.visRowProp));
// The columns of the properties to set are fixed and can be
// accessed directly using the CellsSRC method and column index.
// Get the Cell object for each one of the items in the
// custom property and set its value using the FormulaU property
// of the Cell object.
// Column 1 : Prompt
shapeCell = addedToShape.get_CellsSRC((short)VisSectionIndices.visSectionProp, rowIndex, (short)VisCellIndices.visCustPropsPrompt);
formatHelper.SetCellValueToString(shapeCell, prompt);
// Any cell in the row can be used to set the universal
// row name. Only set the name if rowNameU parameter differs
// from the local name and is not blank.
if (rowNameU != null)
{
if ((localRowName != rowNameU) && (rowNameU.Length > 0))
{
shapeCell.RowNameU = rowNameU;
}
}
// Column 2 : Label
shapeCell = addedToShape.get_CellsSRC((short)VisSectionIndices.visSectionProp, rowIndex,(short)VisCellIndices.visCustPropsLabel);
formatHelper.SetCellValueToString(shapeCell, labelName);
// Column 3 : Format
shapeCell = addedToShape.get_CellsSRC((short)VisSectionIndices.visSectionProp, rowIndex, (short)VisCellIndices.visCustPropsFormat);
formatHelper.SetCellValueToString(shapeCell, format);
// Column 4 : Sort Key
shapeCell = addedToShape.get_CellsSRC((short)VisSectionIndices.visSectionProp, rowIndex, (short)VisCellIndices.visCustPropsSortKey);
formatHelper.SetCellValueToString(shapeCell, sortKey);
// Column 5 : Type
shapeCell = addedToShape.get_CellsSRC((short)VisSectionIndices.visSectionProp, rowIndex, (short)VisCellIndices.visCustPropsType);
formatHelper.SetCellValueToString(shapeCell, ((short)propType).ToString(System.Globalization.CultureInfo.InvariantCulture));
// Column 6 : Hidden (This corresponds to the invisible cell in
// the Shapesheet)
shapeCell = addedToShape.get_CellsSRC((short)VisSectionIndices.visSectionProp, rowIndex, (short)VisCellIndices.visCustPropsInvis);
formatHelper.SetCellValueToString(shapeCell, hidden.ToString(System.Globalization.CultureInfo.InvariantCulture));
// Column 7 : Ask on drop
shapeCell = addedToShape.get_CellsSRC((short)VisSectionIndices.visSectionProp, rowIndex, (short)VisCellIndices.visCustPropsAsk);
formatHelper.SetCellValueToString(shapeCell, askOnDrop.ToString(System.Globalization.CultureInfo.InvariantCulture));
// Set the custom property for the shape using FormulaU
// property of the cell.
shapeCell = addedToShape.get_CellsU(CUST_PROP_PREFIX + rowNameU);
formatHelper.SetCellValueToString(shapeCell, rowNameU);
returnValue = true;
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine(err.Message);
throw;
}
return returnValue;
}
}
}