Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Ink / ISFClipboardData.cs / 1305600 / 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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PrintPageEvent.cs
- SessionConnectionReader.cs
- CommaDelimitedStringAttributeCollectionConverter.cs
- DrawingContextDrawingContextWalker.cs
- XmlSchemaObject.cs
- TreeBuilder.cs
- Deserializer.cs
- InvalidOleVariantTypeException.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- XmlStreamNodeWriter.cs
- InternalEnumValidatorAttribute.cs
- X509CertificateValidator.cs
- TextContainerHelper.cs
- SystemEvents.cs
- ValidatorUtils.cs
- CorrelationManager.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- LabelAutomationPeer.cs
- DispatchWrapper.cs
- WebPartConnectionCollection.cs
- DelegateInArgument.cs
- ConditionedDesigner.cs
- AdjustableArrowCap.cs
- CorePropertiesFilter.cs
- securitymgrsite.cs
- ContentPlaceHolderDesigner.cs
- CustomTypeDescriptor.cs
- CheckBoxStandardAdapter.cs
- BatchWriter.cs
- EdgeProfileValidation.cs
- KeyboardNavigation.cs
- MsmqInputMessagePool.cs
- CheckPair.cs
- ManipulationDevice.cs
- MeshGeometry3D.cs
- EdgeProfileValidation.cs
- HttpServerProtocol.cs
- TableRow.cs
- ParameterBuilder.cs
- Renderer.cs
- Item.cs
- login.cs
- DomNameTable.cs
- Help.cs
- BrowserCapabilitiesFactory35.cs
- DrawingContextWalker.cs
- HostingEnvironmentSection.cs
- SqlConnectionHelper.cs
- TextRangeEditTables.cs
- CaseCqlBlock.cs
- ReflectEventDescriptor.cs
- XmlDataLoader.cs
- GridEntryCollection.cs
- AliasedSlot.cs
- WebPartConnectionsConnectVerb.cs
- ServiceContractViewControl.Designer.cs
- QilSortKey.cs
- OleDbParameterCollection.cs
- wmiprovider.cs
- Positioning.cs
- GifBitmapEncoder.cs
- StringFunctions.cs
- odbcmetadatafactory.cs
- NetworkAddressChange.cs
- BooleanExpr.cs
- ProfileSection.cs
- DBDataPermissionAttribute.cs
- OneWayChannelListener.cs
- NotifyCollectionChangedEventArgs.cs
- ArrayTypeMismatchException.cs
- DataSourceControl.cs
- UserControl.cs
- WebPartMenuStyle.cs
- AllMembershipCondition.cs
- HostVisual.cs
- WindowVisualStateTracker.cs
- XmlQueryCardinality.cs
- Int64Storage.cs
- MruCache.cs
- RequestSecurityTokenSerializer.cs
- FormCollection.cs
- TableCellCollection.cs
- wgx_render.cs
- XmlDictionaryReaderQuotas.cs
- DataStreamFromComStream.cs
- IdnElement.cs
- XhtmlBasicControlAdapter.cs
- WmlTextBoxAdapter.cs
- TextEffect.cs
- ToolStripOverflowButton.cs
- StoreItemCollection.Loader.cs
- OleDbFactory.cs
- XmlSchemaAttribute.cs
- codemethodreferenceexpression.cs
- JsonQueryStringConverter.cs
- InkCanvasAutomationPeer.cs
- DnsPermission.cs
- ChannelServices.cs
- SystemEvents.cs
- PersonalizationEntry.cs