Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / UIAutomation / Win32Providers / MS / Internal / AutomationProxies / WindowsListViewScroll.cs / 1 / WindowsListViewScroll.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Class to provide scroll bars for listview
//
// History:
// Jean-Francois Peyroux (in DotNet)
// 2003/08/08 - alexsn Updated for WCP
// 2004/08/19 - preid Took this out of the class hierarchy for listview and made the
// non-client area use to create the scroll bar children
//
//---------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Windows;
using MS.Win32;
namespace MS.Internal.AutomationProxies
{
// The default implementation for scroll bars uses SB_THUMBTRACK and SB_THUMBPOSITION for SetValue
// This does not work with listview so the Scrollbar is overloaded with a derived version that
// uses LVM_SCROLL messages instead
class WindowsListViewScrollBar: WindowsScrollBar, IRangeValueProvider
{
// -----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
internal WindowsListViewScrollBar(IntPtr hwnd, ProxyFragment parent, int item, int sbFlag)
: base( hwnd, parent, item, sbFlag){}
#endregion Constructors
//------------------------------------------------------
//
// Patterns Implementation
//
//-----------------------------------------------------
#region RangeValue Pattern
void IRangeValueProvider.SetValue(double val)
{
// Check if the window is disabled
if (!SafeNativeMethods.IsWindowEnabled (_hwnd))
{
throw new ElementNotEnabledException();
}
NativeMethods.ScrollInfo si = new NativeMethods.ScrollInfo ();
si.fMask = NativeMethods.SIF_ALL;
si.cbSize = Marshal.SizeOf (si.GetType ());
if (!Misc.GetScrollInfo(_hwnd, _sbFlag, ref si))
{
return;
}
int pos = (int)val;
// Throw if val is greater than the maximum or less than the minimum.
// See remarks for WindowsScrollBar.GetScrollValue(ScrollBarInfo.MaximumPosition)
// regarding this calculation of the allowed maximum.
if (pos > si.nMax - si.nPage + (si.nPage > 0 ? 1 : 0))
{
throw new ArgumentOutOfRangeException("value", val, SR.Get(SRID.RangeValueMax));
}
else if (pos < si.nMin)
{
throw new ArgumentOutOfRangeException("value", val, SR.Get(SRID.RangeValueMin));
}
// LVM_SCROLL does not work in mode Report, use SetScrollPos instead
bool isVerticalScroll = IsScrollBarVertical(_hwnd, _sbFlag);
if (isVerticalScroll && WindowsListView.InReportView (_hwnd))
{
Misc.SetScrollPos(_hwnd, _sbFlag, pos, true);
return;
}
// get the "full size" of the list-view
int size = WindowsListView.ApproximateViewRect (_hwnd);
// delta between current and user-requested position in pixels
// since the cPelsAll contains the dimension in pels for all items + the 2 pels of the border
// the operation below does a trunc on purpose
int dx = 0, dy = 0;
if (!isVerticalScroll)
{
int cPelsAll = NativeMethods.Util.LOWORD (size);
dx = (int)((pos - si.nPos) * ((double)cPelsAll / (si.nMax + 1 - si.nMin)));
}
else
{
int cPelsAll = NativeMethods.Util.HIWORD (size);
dy = (int)((pos - si.nPos) * ((double)cPelsAll / (si.nMax + 1 - si.nMin)));
}
if (WindowsListView.Scroll (_hwnd, (IntPtr) dx, (IntPtr) dy))
{
// Check the result, on occasion the result will be different to given value
// a-jeanp: I played a lot to figure out what it is not the case.
// I am giving up and issuing instead a second call with a new delta.
if (!Misc.GetScrollInfo(_hwnd, _sbFlag, ref si))
{
return;
}
if (si.nPos != pos)
{
if (!isVerticalScroll)
{
int cPelsAll = NativeMethods.Util.LOWORD (size);
dx = (pos - si.nPos) * (cPelsAll / (si.nMax + 1 - si.nMin));
}
else
{
int cPelsAll = NativeMethods.Util.HIWORD (size);
dy = (pos - si.nPos) * (cPelsAll / (si.nMax + 1 - si.nMin));
}
WindowsListView.Scroll (_hwnd, (IntPtr) dx, (IntPtr) dy);
}
}
}
#endregion Value Pattern
}
}
// 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.
//
//
//
// Description: Class to provide scroll bars for listview
//
// History:
// Jean-Francois Peyroux (in DotNet)
// 2003/08/08 - alexsn Updated for WCP
// 2004/08/19 - preid Took this out of the class hierarchy for listview and made the
// non-client area use to create the scroll bar children
//
//---------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Windows;
using MS.Win32;
namespace MS.Internal.AutomationProxies
{
// The default implementation for scroll bars uses SB_THUMBTRACK and SB_THUMBPOSITION for SetValue
// This does not work with listview so the Scrollbar is overloaded with a derived version that
// uses LVM_SCROLL messages instead
class WindowsListViewScrollBar: WindowsScrollBar, IRangeValueProvider
{
// -----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
internal WindowsListViewScrollBar(IntPtr hwnd, ProxyFragment parent, int item, int sbFlag)
: base( hwnd, parent, item, sbFlag){}
#endregion Constructors
//------------------------------------------------------
//
// Patterns Implementation
//
//-----------------------------------------------------
#region RangeValue Pattern
void IRangeValueProvider.SetValue(double val)
{
// Check if the window is disabled
if (!SafeNativeMethods.IsWindowEnabled (_hwnd))
{
throw new ElementNotEnabledException();
}
NativeMethods.ScrollInfo si = new NativeMethods.ScrollInfo ();
si.fMask = NativeMethods.SIF_ALL;
si.cbSize = Marshal.SizeOf (si.GetType ());
if (!Misc.GetScrollInfo(_hwnd, _sbFlag, ref si))
{
return;
}
int pos = (int)val;
// Throw if val is greater than the maximum or less than the minimum.
// See remarks for WindowsScrollBar.GetScrollValue(ScrollBarInfo.MaximumPosition)
// regarding this calculation of the allowed maximum.
if (pos > si.nMax - si.nPage + (si.nPage > 0 ? 1 : 0))
{
throw new ArgumentOutOfRangeException("value", val, SR.Get(SRID.RangeValueMax));
}
else if (pos < si.nMin)
{
throw new ArgumentOutOfRangeException("value", val, SR.Get(SRID.RangeValueMin));
}
// LVM_SCROLL does not work in mode Report, use SetScrollPos instead
bool isVerticalScroll = IsScrollBarVertical(_hwnd, _sbFlag);
if (isVerticalScroll && WindowsListView.InReportView (_hwnd))
{
Misc.SetScrollPos(_hwnd, _sbFlag, pos, true);
return;
}
// get the "full size" of the list-view
int size = WindowsListView.ApproximateViewRect (_hwnd);
// delta between current and user-requested position in pixels
// since the cPelsAll contains the dimension in pels for all items + the 2 pels of the border
// the operation below does a trunc on purpose
int dx = 0, dy = 0;
if (!isVerticalScroll)
{
int cPelsAll = NativeMethods.Util.LOWORD (size);
dx = (int)((pos - si.nPos) * ((double)cPelsAll / (si.nMax + 1 - si.nMin)));
}
else
{
int cPelsAll = NativeMethods.Util.HIWORD (size);
dy = (int)((pos - si.nPos) * ((double)cPelsAll / (si.nMax + 1 - si.nMin)));
}
if (WindowsListView.Scroll (_hwnd, (IntPtr) dx, (IntPtr) dy))
{
// Check the result, on occasion the result will be different to given value
// a-jeanp: I played a lot to figure out what it is not the case.
// I am giving up and issuing instead a second call with a new delta.
if (!Misc.GetScrollInfo(_hwnd, _sbFlag, ref si))
{
return;
}
if (si.nPos != pos)
{
if (!isVerticalScroll)
{
int cPelsAll = NativeMethods.Util.LOWORD (size);
dx = (pos - si.nPos) * (cPelsAll / (si.nMax + 1 - si.nMin));
}
else
{
int cPelsAll = NativeMethods.Util.HIWORD (size);
dy = (pos - si.nPos) * (cPelsAll / (si.nMax + 1 - si.nMin));
}
WindowsListView.Scroll (_hwnd, (IntPtr) dx, (IntPtr) dy);
}
}
}
#endregion Value Pattern
}
}
// 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
- ContainerAction.cs
- ListBindingConverter.cs
- RestHandler.cs
- NumericUpDown.cs
- ServicePoint.cs
- ThreadPool.cs
- RestHandlerFactory.cs
- LineProperties.cs
- TemplateApplicationHelper.cs
- ClientSettingsStore.cs
- StyleModeStack.cs
- AgileSafeNativeMemoryHandle.cs
- DataGridItemCollection.cs
- ReaderContextStackData.cs
- ProfileModule.cs
- EngineSiteSapi.cs
- RadialGradientBrush.cs
- BuildDependencySet.cs
- SkewTransform.cs
- ThrowHelper.cs
- CLSCompliantAttribute.cs
- Parameter.cs
- XmlSchema.cs
- HighlightVisual.cs
- DefaultValidator.cs
- TypedReference.cs
- SelectionList.cs
- WebHttpBehavior.cs
- SuppressIldasmAttribute.cs
- LinqDataSourceSelectEventArgs.cs
- HashCodeCombiner.cs
- FocusWithinProperty.cs
- StorageMappingItemCollection.cs
- ReturnType.cs
- OdbcException.cs
- CodeCompiler.cs
- BuildManager.cs
- LayoutDump.cs
- AspCompat.cs
- ToolBar.cs
- ParserContext.cs
- AmbientValueAttribute.cs
- IOException.cs
- RoleServiceManager.cs
- LocatorPartList.cs
- ClientFormsAuthenticationMembershipProvider.cs
- SchemaCollectionPreprocessor.cs
- SiteMapDataSource.cs
- ToolStripDesignerUtils.cs
- propertyentry.cs
- ApplicationHost.cs
- RequestQueue.cs
- DataSysAttribute.cs
- GroupItemAutomationPeer.cs
- Timer.cs
- ReferenceEqualityComparer.cs
- DataRecordInfo.cs
- FileAuthorizationModule.cs
- WSHttpBindingElement.cs
- EventlogProvider.cs
- ThousandthOfEmRealDoubles.cs
- XmlChoiceIdentifierAttribute.cs
- TakeQueryOptionExpression.cs
- LogEntryHeaderSerializer.cs
- Bits.cs
- HttpServerUtilityWrapper.cs
- UshortList2.cs
- MulticastDelegate.cs
- TabItemWrapperAutomationPeer.cs
- ProxyElement.cs
- MdImport.cs
- HtmlInputFile.cs
- AdapterDictionary.cs
- SessionState.cs
- KnownTypesProvider.cs
- BuildProvidersCompiler.cs
- Encoding.cs
- _ListenerAsyncResult.cs
- DataGridViewColumnEventArgs.cs
- EntitySqlException.cs
- ExpressionsCollectionEditor.cs
- EncryptedPackageFilter.cs
- TableAdapterManagerHelper.cs
- GacUtil.cs
- HttpAsyncResult.cs
- DBDataPermission.cs
- RawStylusInputCustomDataList.cs
- SplitterCancelEvent.cs
- ResourceExpressionBuilder.cs
- ProcessStartInfo.cs
- XPathNode.cs
- SoapAttributes.cs
- DictionaryKeyPropertyAttribute.cs
- XPathDocument.cs
- RecordsAffectedEventArgs.cs
- BufferAllocator.cs
- FixedBufferAttribute.cs
- BlurEffect.cs
- FontNameConverter.cs
- InputLanguageCollection.cs