Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / InterOp / HwndPanningFeedback.cs / 1305600 / HwndPanningFeedback.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; using MS.Win32; namespace System.Windows.Interop { ////// Helper class to provide window feedback that panning has hit an edge. /// internal class HwndPanningFeedback { ////// Instantiates a new instance of this class. /// /// The HWND on which to provide feedback. ////// SecurityCritical: Accesses HwndSource. /// TreatAsSafe: Information is not given out. /// [SecurityCritical, SecurityTreatAsSafe] public HwndPanningFeedback(HwndSource hwndSource) { if (hwndSource == null) { throw new ArgumentNullException("hwndSource"); } _hwndSource = hwndSource; } private static bool IsSupported { get { return OperatingSystemVersionCheck.IsVersionOrLater(OperatingSystemVersion.Windows7); } } ////// Returns the handle of the current window. /// ////// SecurityCritical: Handles _hwndSource /// SecurityCritical: Handles and exposes HwndSource.Handle /// private HandleRef Handle { [SecurityCritical] get { if (_hwndSource != null) { IntPtr handle = _hwndSource.CriticalHandle; if (handle != IntPtr.Zero) { return new HandleRef(_hwndSource, handle); } } return new HandleRef(); } } ////// Moves the window by the offset. /// Used to provide feedback that panning has hit an edge. /// /// The total offset relative to the original location. /// Whether the edge was hit due to inertia or the user panning. ////// SecurityCritical: Changes the on-screen position of a window. /// SecurityCritical: Accesses Handle. /// [SecurityCritical] public void UpdatePanningFeedback(Vector totalOverpanOffset, bool inInertia) { if ((_hwndSource != null) && IsSupported) { if (!_isProvidingPanningFeedback) { _isProvidingPanningFeedback = UnsafeNativeMethods.BeginPanningFeedback(Handle); } if (_isProvidingPanningFeedback) { var deviceOffset = _hwndSource.TransformToDevice((Point)totalOverpanOffset); _deviceOffsetX = (int)deviceOffset.X; _deviceOffsetY = (int)deviceOffset.Y; _inInertia = inInertia; if (_updatePanningOperation == null) { _updatePanningOperation = _hwndSource.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(OnUpdatePanningFeedback), this); } } } } ////// SecurityCritical: Changes the on-screen position of a window. /// SecurityCritical: Accesses Handle. /// [SecurityCritical] private object OnUpdatePanningFeedback(object args) { HwndPanningFeedback panningFeedback = (HwndPanningFeedback)args; _updatePanningOperation = null; UnsafeNativeMethods.UpdatePanningFeedback(panningFeedback.Handle, panningFeedback._deviceOffsetX, panningFeedback._deviceOffsetY, panningFeedback._inInertia); return null; } private int _deviceOffsetX; private int _deviceOffsetY; private bool _inInertia; private DispatcherOperation _updatePanningOperation; ////// Moves the window back to its original position. /// Used to provide feedback that panning has hit an edge. /// /// Whether to animate or snap back to the original position ////// SecurityCritical: Changes the on-screen position of a window. /// SecurityCritical: Accesses _handle. /// TreatAsSafe: Returns the window to its original position, which is safe. /// [SecurityCritical, SecurityTreatAsSafe] public void EndPanningFeedback(bool animateBack) { if (_hwndSource != null && _isProvidingPanningFeedback) { _isProvidingPanningFeedback = false; if (_updatePanningOperation != null) { _updatePanningOperation.Abort(); _updatePanningOperation = null; } UnsafeNativeMethods.EndPanningFeedback(Handle, animateBack); } } ////// Whether panning feedback is currently in progress. /// private bool _isProvidingPanningFeedback; ////// The HwndSource being manipulated. /// ////// SecurityCritical: Access to the window. /// [SecurityCritical] private HwndSource _hwndSource; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; using MS.Win32; namespace System.Windows.Interop { ////// Helper class to provide window feedback that panning has hit an edge. /// internal class HwndPanningFeedback { ////// Instantiates a new instance of this class. /// /// The HWND on which to provide feedback. ////// SecurityCritical: Accesses HwndSource. /// TreatAsSafe: Information is not given out. /// [SecurityCritical, SecurityTreatAsSafe] public HwndPanningFeedback(HwndSource hwndSource) { if (hwndSource == null) { throw new ArgumentNullException("hwndSource"); } _hwndSource = hwndSource; } private static bool IsSupported { get { return OperatingSystemVersionCheck.IsVersionOrLater(OperatingSystemVersion.Windows7); } } ////// Returns the handle of the current window. /// ////// SecurityCritical: Handles _hwndSource /// SecurityCritical: Handles and exposes HwndSource.Handle /// private HandleRef Handle { [SecurityCritical] get { if (_hwndSource != null) { IntPtr handle = _hwndSource.CriticalHandle; if (handle != IntPtr.Zero) { return new HandleRef(_hwndSource, handle); } } return new HandleRef(); } } ////// Moves the window by the offset. /// Used to provide feedback that panning has hit an edge. /// /// The total offset relative to the original location. /// Whether the edge was hit due to inertia or the user panning. ////// SecurityCritical: Changes the on-screen position of a window. /// SecurityCritical: Accesses Handle. /// [SecurityCritical] public void UpdatePanningFeedback(Vector totalOverpanOffset, bool inInertia) { if ((_hwndSource != null) && IsSupported) { if (!_isProvidingPanningFeedback) { _isProvidingPanningFeedback = UnsafeNativeMethods.BeginPanningFeedback(Handle); } if (_isProvidingPanningFeedback) { var deviceOffset = _hwndSource.TransformToDevice((Point)totalOverpanOffset); _deviceOffsetX = (int)deviceOffset.X; _deviceOffsetY = (int)deviceOffset.Y; _inInertia = inInertia; if (_updatePanningOperation == null) { _updatePanningOperation = _hwndSource.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(OnUpdatePanningFeedback), this); } } } } ////// SecurityCritical: Changes the on-screen position of a window. /// SecurityCritical: Accesses Handle. /// [SecurityCritical] private object OnUpdatePanningFeedback(object args) { HwndPanningFeedback panningFeedback = (HwndPanningFeedback)args; _updatePanningOperation = null; UnsafeNativeMethods.UpdatePanningFeedback(panningFeedback.Handle, panningFeedback._deviceOffsetX, panningFeedback._deviceOffsetY, panningFeedback._inInertia); return null; } private int _deviceOffsetX; private int _deviceOffsetY; private bool _inInertia; private DispatcherOperation _updatePanningOperation; ////// Moves the window back to its original position. /// Used to provide feedback that panning has hit an edge. /// /// Whether to animate or snap back to the original position ////// SecurityCritical: Changes the on-screen position of a window. /// SecurityCritical: Accesses _handle. /// TreatAsSafe: Returns the window to its original position, which is safe. /// [SecurityCritical, SecurityTreatAsSafe] public void EndPanningFeedback(bool animateBack) { if (_hwndSource != null && _isProvidingPanningFeedback) { _isProvidingPanningFeedback = false; if (_updatePanningOperation != null) { _updatePanningOperation.Abort(); _updatePanningOperation = null; } UnsafeNativeMethods.EndPanningFeedback(Handle, animateBack); } } ////// Whether panning feedback is currently in progress. /// private bool _isProvidingPanningFeedback; ////// The HwndSource being manipulated. /// ////// SecurityCritical: Access to the window. /// [SecurityCritical] private HwndSource _hwndSource; } } // 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
- XamlTreeBuilderBamlRecordWriter.cs
- ExtentCqlBlock.cs
- BulletChrome.cs
- MultiplexingDispatchMessageFormatter.cs
- SqlRecordBuffer.cs
- MultiplexingDispatchMessageFormatter.cs
- WebServiceParameterData.cs
- RequestQueryProcessor.cs
- FileDialog.cs
- XmlDomTextWriter.cs
- DataGridLengthConverter.cs
- ConfigurationFileMap.cs
- MethodToken.cs
- LeftCellWrapper.cs
- AtomServiceDocumentSerializer.cs
- PopupRootAutomationPeer.cs
- CryptoKeySecurity.cs
- Model3DGroup.cs
- sqlnorm.cs
- RowUpdatedEventArgs.cs
- TargetControlTypeCache.cs
- FlowLayout.cs
- ProcessStartInfo.cs
- SmtpNegotiateAuthenticationModule.cs
- MobileListItem.cs
- SafeWaitHandle.cs
- StackSpiller.Generated.cs
- AppDomainUnloadedException.cs
- XsdDateTime.cs
- InvalidDataException.cs
- Visual.cs
- WebPartZoneBase.cs
- ListViewDataItem.cs
- IOThreadTimer.cs
- SqlStatistics.cs
- PrefixQName.cs
- AdapterUtil.cs
- COSERVERINFO.cs
- DetailsViewPagerRow.cs
- safesecurityhelperavalon.cs
- RequestCachePolicyConverter.cs
- XPathScanner.cs
- DisplayNameAttribute.cs
- TrackingProfileDeserializationException.cs
- LayoutEditorPart.cs
- RegularExpressionValidator.cs
- XmlNullResolver.cs
- StatusBarItem.cs
- MonthCalendar.cs
- XmlValidatingReaderImpl.cs
- CodeDomLoader.cs
- GeometryCombineModeValidation.cs
- Animatable.cs
- DefaultMergeHelper.cs
- StaticFileHandler.cs
- DBDataPermission.cs
- BinaryObjectInfo.cs
- SerializationUtility.cs
- StylusCaptureWithinProperty.cs
- WindowsEditBoxRange.cs
- Encoding.cs
- ModuleConfigurationInfo.cs
- SynchronizedReadOnlyCollection.cs
- PathSegmentCollection.cs
- DocumentPaginator.cs
- CriticalFinalizerObject.cs
- Win32Native.cs
- peersecurityelement.cs
- StorageConditionPropertyMapping.cs
- MemberCollection.cs
- SmtpNtlmAuthenticationModule.cs
- Stackframe.cs
- EntityKeyElement.cs
- ObjectManager.cs
- Win32KeyboardDevice.cs
- Policy.cs
- MessageLogger.cs
- JoinElimination.cs
- DynamicUpdateCommand.cs
- IntegerValidatorAttribute.cs
- CodeTypeOfExpression.cs
- AuthenticatingEventArgs.cs
- HttpRequestCacheValidator.cs
- StorageMappingItemCollection.cs
- WsdlInspector.cs
- XmlNullResolver.cs
- XPathSelectionIterator.cs
- GACIdentityPermission.cs
- SqlMethodCallConverter.cs
- Cell.cs
- URLAttribute.cs
- CaretElement.cs
- SelectionEditor.cs
- CreatingCookieEventArgs.cs
- COAUTHIDENTITY.cs
- GCHandleCookieTable.cs
- UrlPath.cs
- Timeline.cs
- SqlTriggerContext.cs
- OdbcConnectionStringbuilder.cs