Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / MS / Internal / Ink / ISFClipboardData.cs / 1 / ISFClipboardData.cs
//---------------------------------------------------------------------------- // // File: ISFClipboardData.cs // // Description: // A class which can convert the clipboard data from/to StrokeCollection // // Features: // // History: // 11/17/2004 waynezen: Created // // Copyright (C) 2001 by Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Ink; using System.Security; using System.Security.Permissions; namespace MS.Internal.Ink { internal class ISFClipboardData : ClipboardData { //------------------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------------------- #region Constructors // The default constructor internal ISFClipboardData() { } // The constructor which takes StrokeCollection argument internal ISFClipboardData(StrokeCollection strokes) { _strokes = strokes; } // Checks if the data can be pasted. internal override bool CanPaste(IDataObject dataObject) { return dataObject.GetDataPresent(StrokeCollection.InkSerializedFormat, false); } #endregion Constructors //-------------------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------------------- #region Protected Methods // Checks if there is stroke data in this instance protected override bool CanCopy() { return (Strokes != null && Strokes.Count != 0); } // Copies the internal strokes to the IDataObject ////// Critical: This code asserts to set data on a data object /// [SecurityCritical] protected override void DoCopy(IDataObject dataObject) { // samgeo - Presharp issue // Presharp gives a warning when local IDisposable variables are not closed // in this case, we can't call Dispose since it will also close the underlying stream // which needs to be open for consumers to read #pragma warning disable 1634, 1691 #pragma warning disable 6518 // Save the data in the data object. MemoryStream stream = new MemoryStream(); Strokes.Save(stream); stream.Position = 0; (new UIPermission(UIPermissionClipboard.AllClipboard)).Assert();//BlessedAssert try { dataObject.SetData(StrokeCollection.InkSerializedFormat, stream); } finally { UIPermission.RevertAssert(); } #pragma warning restore 6518 #pragma warning restore 1634, 1691 } // Retrieves the stroks from the IDataObject protected override void DoPaste(IDataObject dataObject) { // Check if we have ink data MemoryStream stream = dataObject.GetData(StrokeCollection.InkSerializedFormat) as MemoryStream; StrokeCollection newStrokes = null; bool fSucceeded = false; if ( stream != null && stream != Stream.Null ) { try { // Now add these ink strokes to the InkCanvas ink collection. newStrokes = new StrokeCollection(stream); fSucceeded = true; } catch ( ArgumentException ) { // If an invalid stream was passed in, we should get ArgumentException here. // We catch this specific exception and eat it. fSucceeded = false; } } // Depending on whether we are succeeded or not, we set the correct stroke collection here. _strokes = fSucceeded ? newStrokes : new StrokeCollection(); } #endregion Protected Methods //-------------------------------------------------------------------------------- // // Internal Properties // //-------------------------------------------------------------------------------- #region Internal Properties // Gets the strokes internal StrokeCollection Strokes { get { return _strokes; } } #endregion Internal Properties //------------------------------------------------------------------------------- // // Private Fields // //-------------------------------------------------------------------------------- #region Private Fields StrokeCollection _strokes; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // File: ISFClipboardData.cs // // Description: // A class which can convert the clipboard data from/to StrokeCollection // // Features: // // History: // 11/17/2004 waynezen: Created // // Copyright (C) 2001 by Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Ink; using System.Security; using System.Security.Permissions; namespace MS.Internal.Ink { internal class ISFClipboardData : ClipboardData { //------------------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------------------- #region Constructors // The default constructor internal ISFClipboardData() { } // The constructor which takes StrokeCollection argument internal ISFClipboardData(StrokeCollection strokes) { _strokes = strokes; } // Checks if the data can be pasted. internal override bool CanPaste(IDataObject dataObject) { return dataObject.GetDataPresent(StrokeCollection.InkSerializedFormat, false); } #endregion Constructors //-------------------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------------------- #region Protected Methods // Checks if there is stroke data in this instance protected override bool CanCopy() { return (Strokes != null && Strokes.Count != 0); } // Copies the internal strokes to the IDataObject ////// Critical: This code asserts to set data on a data object /// [SecurityCritical] protected override void DoCopy(IDataObject dataObject) { // samgeo - Presharp issue // Presharp gives a warning when local IDisposable variables are not closed // in this case, we can't call Dispose since it will also close the underlying stream // which needs to be open for consumers to read #pragma warning disable 1634, 1691 #pragma warning disable 6518 // Save the data in the data object. MemoryStream stream = new MemoryStream(); Strokes.Save(stream); stream.Position = 0; (new UIPermission(UIPermissionClipboard.AllClipboard)).Assert();//BlessedAssert try { dataObject.SetData(StrokeCollection.InkSerializedFormat, stream); } finally { UIPermission.RevertAssert(); } #pragma warning restore 6518 #pragma warning restore 1634, 1691 } // Retrieves the stroks from the IDataObject protected override void DoPaste(IDataObject dataObject) { // Check if we have ink data MemoryStream stream = dataObject.GetData(StrokeCollection.InkSerializedFormat) as MemoryStream; StrokeCollection newStrokes = null; bool fSucceeded = false; if ( stream != null && stream != Stream.Null ) { try { // Now add these ink strokes to the InkCanvas ink collection. newStrokes = new StrokeCollection(stream); fSucceeded = true; } catch ( ArgumentException ) { // If an invalid stream was passed in, we should get ArgumentException here. // We catch this specific exception and eat it. fSucceeded = false; } } // Depending on whether we are succeeded or not, we set the correct stroke collection here. _strokes = fSucceeded ? newStrokes : new StrokeCollection(); } #endregion Protected Methods //-------------------------------------------------------------------------------- // // Internal Properties // //-------------------------------------------------------------------------------- #region Internal Properties // Gets the strokes internal StrokeCollection Strokes { get { return _strokes; } } #endregion Internal Properties //------------------------------------------------------------------------------- // // Private Fields // //-------------------------------------------------------------------------------- #region Private Fields StrokeCollection _strokes; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypeReference.cs
- Timer.cs
- FormattedTextSymbols.cs
- MetadataProperty.cs
- ProjectedSlot.cs
- OperatorExpressions.cs
- CultureTableRecord.cs
- PageContentCollection.cs
- SiteOfOriginContainer.cs
- Effect.cs
- PrivilegeNotHeldException.cs
- ColumnTypeConverter.cs
- OleDbReferenceCollection.cs
- TrustLevel.cs
- XmlSchemaGroupRef.cs
- SortAction.cs
- NaturalLanguageHyphenator.cs
- XmlArrayItemAttributes.cs
- GlobalProxySelection.cs
- ExpressionVisitor.cs
- GridItem.cs
- Trace.cs
- ScaleTransform.cs
- WindowsFormsHostPropertyMap.cs
- TextEditorMouse.cs
- SkinBuilder.cs
- ScrollBar.cs
- BindingMemberInfo.cs
- HealthMonitoringSectionHelper.cs
- WindowsFormsHelpers.cs
- XsdBuildProvider.cs
- Model3D.cs
- DeclarationUpdate.cs
- dtdvalidator.cs
- SiteMapHierarchicalDataSourceView.cs
- QueryExpression.cs
- _ListenerRequestStream.cs
- StrokeIntersection.cs
- XPathDocumentBuilder.cs
- CallSiteHelpers.cs
- Pkcs9Attribute.cs
- Converter.cs
- ComUdtElementCollection.cs
- QuaternionAnimation.cs
- InkCanvasAutomationPeer.cs
- CrossAppDomainChannel.cs
- UIElement.cs
- ZipIOModeEnforcingStream.cs
- COM2EnumConverter.cs
- BindingList.cs
- CollectionAdapters.cs
- ReadOnlyCollectionBase.cs
- SelectedDatesCollection.cs
- hresults.cs
- Point3DCollectionConverter.cs
- Helpers.cs
- NoResizeHandleGlyph.cs
- FormCollection.cs
- OdbcEnvironmentHandle.cs
- ContainsRowNumberChecker.cs
- HwndHostAutomationPeer.cs
- OdbcException.cs
- PropertyToken.cs
- SiteMapDataSourceView.cs
- ObjectConverter.cs
- Normalizer.cs
- SignerInfo.cs
- EncoderReplacementFallback.cs
- IntMinMaxAggregationOperator.cs
- SiteMapNodeCollection.cs
- MultilineStringConverter.cs
- BitmapFrameEncode.cs
- KerberosTicketHashIdentifierClause.cs
- RoutingEndpointTrait.cs
- __ConsoleStream.cs
- ArraySubsetEnumerator.cs
- TextAnchor.cs
- CredentialSelector.cs
- ToolBarButton.cs
- ConfigXmlAttribute.cs
- NCryptSafeHandles.cs
- ContainerAction.cs
- Util.cs
- PathParser.cs
- TextBoxAutoCompleteSourceConverter.cs
- SafeHandles.cs
- _ContextAwareResult.cs
- SchemaContext.cs
- Matrix.cs
- ApplicationTrust.cs
- TextBounds.cs
- BulletedList.cs
- PermissionSetEnumerator.cs
- SmtpSection.cs
- ConstraintConverter.cs
- XPathScanner.cs
- JoinTreeSlot.cs
- NavigatingCancelEventArgs.cs
- SymbolEqualComparer.cs
- XmlBoundElement.cs