Exemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the selection props for the specified IVwSelection
		/// </summary>
		/// <param name="vwSel">The view Selection</param>
		/// <param name="vttp">Returned array of ITsTextProps in the selection</param>
		/// <param name="vvps">Returned array of IVwPropertyStores in the selection</param>
		/// <param name="cttp">Returned count of TsTxtProps (this is basically just the number
		/// of runs in the selection)</param>
		/// ------------------------------------------------------------------------------------
		public static void GetSelectionProps(IVwSelection vwSel, out ITsTextProps[] vttp,
			out IVwPropertyStore[] vvps, out int cttp)
		{
			Debug.Assert(vwSel != null);
			vttp = null;
			vvps = null;
			cttp = 0;
			if (!vwSel.IsValid)
				return;

			// The first call to GetSelectionProps gets the count of properties
			vwSel.GetSelectionProps(0, ArrayPtr.Null, ArrayPtr.Null, out cttp);
			if (cttp == 0)
				return;

			using (ArrayPtr pvTtp = MarshalEx.ArrayToNative<ITsTextProps>(cttp))
			{
				using (ArrayPtr pvVps = MarshalEx.ArrayToNative<IVwPropertyStore>(cttp))
				{
					vwSel.GetSelectionProps(cttp, pvTtp, pvVps, out cttp);
					vttp = MarshalEx.NativeToArray<ITsTextProps>(pvTtp, cttp);
					vvps = MarshalEx.NativeToArray< IVwPropertyStore>(pvVps, cttp);
				}
			}
		}