Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CommonUI / System / Drawing / Advanced / CustomLineCap.cs / 2 / CustomLineCap.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Drawing.Drawing2D {
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Internal;
using System.Runtime.InteropServices;
using System.Globalization;
///
///
/// Encapsulates a custom user-defined line
/// cap.
///
public class CustomLineCap : MarshalByRefObject, ICloneable, IDisposable {
#if FINALIZATION_WATCH
private string allocationSite = Graphics.GetAllocationStack();
#endif
/*
* Handle to native line cap object
*/
internal IntPtr nativeCap;
// For subclass creation
internal CustomLineCap() {}
///
///
///
/// Initializes a new instance of the class with the specified outline
/// and fill.
///
///
public CustomLineCap(GraphicsPath fillPath,
GraphicsPath strokePath) :
this(fillPath, strokePath, LineCap.Flat) {}
///
///
///
/// Initializes a new instance of the class from the
/// specified existing with the specified outline and
/// fill.
///
///
public CustomLineCap(GraphicsPath fillPath,
GraphicsPath strokePath,
LineCap baseCap) :
this(fillPath, strokePath, baseCap, 0) {}
///
///
///
/// Initializes a new instance of the class from the
/// specified existing with the specified outline, fill, and
/// inset.
///
///
public CustomLineCap(GraphicsPath fillPath,
GraphicsPath strokePath,
LineCap baseCap,
float baseInset)
{
IntPtr nativeCap = IntPtr.Zero;
int status = SafeNativeMethods.Gdip.GdipCreateCustomLineCap(
new HandleRef(fillPath, (fillPath == null) ? IntPtr.Zero : fillPath.nativePath),
new HandleRef(strokePath, (strokePath == null) ? IntPtr.Zero : strokePath.nativePath),
baseCap, baseInset, out nativeCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
SetNativeLineCap(nativeCap);
}
internal CustomLineCap(IntPtr nativeLineCap)
{
SetNativeLineCap(nativeLineCap);
}
internal void SetNativeLineCap(IntPtr handle) {
if (handle == IntPtr.Zero)
throw new ArgumentNullException("handle");
nativeCap = handle;
}
///
///
/// Cleans up Windows resources for this
/// .
///
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
///
protected virtual void Dispose(bool disposing) {
#if FINALIZATION_WATCH
if (!disposing && nativeCap != IntPtr.Zero)
Debug.WriteLine("**********************\nDisposed through finalization:\n" + allocationSite);
#endif
if (nativeCap != IntPtr.Zero) {
try{
#if DEBUG
int status =
#endif
SafeNativeMethods.Gdip.GdipDeleteCustomLineCap(new HandleRef(this, nativeCap));
#if DEBUG
Debug.Assert(status == SafeNativeMethods.Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
#endif
}
catch( Exception ex ){
if( ClientUtils.IsSecurityOrCriticalException( ex ) ) {
throw;
}
Debug.Fail( "Exception thrown during Dispose: " + ex.ToString() );
}
finally{
nativeCap = IntPtr.Zero;
}
}
}
///
///
/// Cleans up Windows resources for this
/// .
///
~CustomLineCap() {
Dispose(false);
}
///
///
/// Creates an exact copy of this .
///
public object Clone()
{
IntPtr cloneCap = IntPtr.Zero;
int status = SafeNativeMethods.Gdip.GdipCloneCustomLineCap(new HandleRef(this, nativeCap), out cloneCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return CustomLineCap.CreateCustomLineCapObject(cloneCap);
}
internal static CustomLineCap CreateCustomLineCapObject(IntPtr cap)
{
CustomLineCapType capType = 0;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapType(new HandleRef(null, cap), out capType);
if (status != SafeNativeMethods.Gdip.Ok)
{
SafeNativeMethods.Gdip.GdipDeleteCustomLineCap(new HandleRef(null, cap));
throw SafeNativeMethods.Gdip.StatusException(status);
}
switch (capType)
{
case CustomLineCapType.Default:
return new CustomLineCap(cap);
case CustomLineCapType.AdjustableArrowCap:
return new AdjustableArrowCap(cap);
}
SafeNativeMethods.Gdip.GdipDeleteCustomLineCap(new HandleRef(null, cap));
throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.NotImplemented);
}
///
///
/// Sets the caps used to start and end lines.
///
public void SetStrokeCaps(LineCap startCap, LineCap endCap)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapStrokeCaps(new HandleRef(this, nativeCap), startCap, endCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
///
///
/// Gets the caps used to start and end lines.
///
public void GetStrokeCaps(out LineCap startCap, out LineCap endCap)
{
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapStrokeCaps(new HandleRef(this, nativeCap), out startCap, out endCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private void _SetStrokeJoin(LineJoin lineJoin)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapStrokeJoin(new HandleRef(this, nativeCap), lineJoin);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private LineJoin _GetStrokeJoin()
{
LineJoin lineJoin;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapStrokeJoin(new HandleRef(this, nativeCap), out lineJoin);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return lineJoin;
}
///
///
/// Gets or sets the used by this custom cap.
///
public LineJoin StrokeJoin
{
get { return _GetStrokeJoin(); }
set { _SetStrokeJoin(value); }
}
private void _SetBaseCap(LineCap baseCap)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapBaseCap(new HandleRef(this, nativeCap), baseCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private LineCap _GetBaseCap()
{
LineCap baseCap;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapBaseCap(new HandleRef(this, nativeCap), out baseCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return baseCap;
}
///
///
/// Gets or sets the on which this is based.
///
public LineCap BaseCap
{
get { return _GetBaseCap(); }
set { _SetBaseCap(value); }
}
private void _SetBaseInset(float inset)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapBaseInset(new HandleRef(this, nativeCap), inset);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private float _GetBaseInset()
{
float inset;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapBaseInset(new HandleRef(this, nativeCap), out inset);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return inset;
}
///
///
/// Gets or sets the distance between the cap
/// and the line.
///
public float BaseInset
{
get { return _GetBaseInset(); }
set { _SetBaseInset(value); }
}
private void _SetWidthScale(float widthScale)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapWidthScale(new HandleRef(this, nativeCap), widthScale);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private float _GetWidthScale()
{
float widthScale;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapWidthScale(new HandleRef(this, nativeCap), out widthScale);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return widthScale;
}
///
///
/// Gets or sets the amount by which to scale
/// the width of the cap.
///
public float WidthScale
{
get { return _GetWidthScale(); }
set { _SetWidthScale(value); }
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Drawing.Drawing2D {
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Internal;
using System.Runtime.InteropServices;
using System.Globalization;
///
///
/// Encapsulates a custom user-defined line
/// cap.
///
public class CustomLineCap : MarshalByRefObject, ICloneable, IDisposable {
#if FINALIZATION_WATCH
private string allocationSite = Graphics.GetAllocationStack();
#endif
/*
* Handle to native line cap object
*/
internal IntPtr nativeCap;
// For subclass creation
internal CustomLineCap() {}
///
///
///
/// Initializes a new instance of the class with the specified outline
/// and fill.
///
///
public CustomLineCap(GraphicsPath fillPath,
GraphicsPath strokePath) :
this(fillPath, strokePath, LineCap.Flat) {}
///
///
///
/// Initializes a new instance of the class from the
/// specified existing with the specified outline and
/// fill.
///
///
public CustomLineCap(GraphicsPath fillPath,
GraphicsPath strokePath,
LineCap baseCap) :
this(fillPath, strokePath, baseCap, 0) {}
///
///
///
/// Initializes a new instance of the class from the
/// specified existing with the specified outline, fill, and
/// inset.
///
///
public CustomLineCap(GraphicsPath fillPath,
GraphicsPath strokePath,
LineCap baseCap,
float baseInset)
{
IntPtr nativeCap = IntPtr.Zero;
int status = SafeNativeMethods.Gdip.GdipCreateCustomLineCap(
new HandleRef(fillPath, (fillPath == null) ? IntPtr.Zero : fillPath.nativePath),
new HandleRef(strokePath, (strokePath == null) ? IntPtr.Zero : strokePath.nativePath),
baseCap, baseInset, out nativeCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
SetNativeLineCap(nativeCap);
}
internal CustomLineCap(IntPtr nativeLineCap)
{
SetNativeLineCap(nativeLineCap);
}
internal void SetNativeLineCap(IntPtr handle) {
if (handle == IntPtr.Zero)
throw new ArgumentNullException("handle");
nativeCap = handle;
}
///
///
/// Cleans up Windows resources for this
/// .
///
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
///
protected virtual void Dispose(bool disposing) {
#if FINALIZATION_WATCH
if (!disposing && nativeCap != IntPtr.Zero)
Debug.WriteLine("**********************\nDisposed through finalization:\n" + allocationSite);
#endif
if (nativeCap != IntPtr.Zero) {
try{
#if DEBUG
int status =
#endif
SafeNativeMethods.Gdip.GdipDeleteCustomLineCap(new HandleRef(this, nativeCap));
#if DEBUG
Debug.Assert(status == SafeNativeMethods.Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
#endif
}
catch( Exception ex ){
if( ClientUtils.IsSecurityOrCriticalException( ex ) ) {
throw;
}
Debug.Fail( "Exception thrown during Dispose: " + ex.ToString() );
}
finally{
nativeCap = IntPtr.Zero;
}
}
}
///
///
/// Cleans up Windows resources for this
/// .
///
~CustomLineCap() {
Dispose(false);
}
///
///
/// Creates an exact copy of this .
///
public object Clone()
{
IntPtr cloneCap = IntPtr.Zero;
int status = SafeNativeMethods.Gdip.GdipCloneCustomLineCap(new HandleRef(this, nativeCap), out cloneCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return CustomLineCap.CreateCustomLineCapObject(cloneCap);
}
internal static CustomLineCap CreateCustomLineCapObject(IntPtr cap)
{
CustomLineCapType capType = 0;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapType(new HandleRef(null, cap), out capType);
if (status != SafeNativeMethods.Gdip.Ok)
{
SafeNativeMethods.Gdip.GdipDeleteCustomLineCap(new HandleRef(null, cap));
throw SafeNativeMethods.Gdip.StatusException(status);
}
switch (capType)
{
case CustomLineCapType.Default:
return new CustomLineCap(cap);
case CustomLineCapType.AdjustableArrowCap:
return new AdjustableArrowCap(cap);
}
SafeNativeMethods.Gdip.GdipDeleteCustomLineCap(new HandleRef(null, cap));
throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.NotImplemented);
}
///
///
/// Sets the caps used to start and end lines.
///
public void SetStrokeCaps(LineCap startCap, LineCap endCap)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapStrokeCaps(new HandleRef(this, nativeCap), startCap, endCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
///
///
/// Gets the caps used to start and end lines.
///
public void GetStrokeCaps(out LineCap startCap, out LineCap endCap)
{
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapStrokeCaps(new HandleRef(this, nativeCap), out startCap, out endCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private void _SetStrokeJoin(LineJoin lineJoin)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapStrokeJoin(new HandleRef(this, nativeCap), lineJoin);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private LineJoin _GetStrokeJoin()
{
LineJoin lineJoin;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapStrokeJoin(new HandleRef(this, nativeCap), out lineJoin);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return lineJoin;
}
///
///
/// Gets or sets the used by this custom cap.
///
public LineJoin StrokeJoin
{
get { return _GetStrokeJoin(); }
set { _SetStrokeJoin(value); }
}
private void _SetBaseCap(LineCap baseCap)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapBaseCap(new HandleRef(this, nativeCap), baseCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private LineCap _GetBaseCap()
{
LineCap baseCap;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapBaseCap(new HandleRef(this, nativeCap), out baseCap);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return baseCap;
}
///
///
/// Gets or sets the on which this is based.
///
public LineCap BaseCap
{
get { return _GetBaseCap(); }
set { _SetBaseCap(value); }
}
private void _SetBaseInset(float inset)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapBaseInset(new HandleRef(this, nativeCap), inset);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private float _GetBaseInset()
{
float inset;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapBaseInset(new HandleRef(this, nativeCap), out inset);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return inset;
}
///
///
/// Gets or sets the distance between the cap
/// and the line.
///
public float BaseInset
{
get { return _GetBaseInset(); }
set { _SetBaseInset(value); }
}
private void _SetWidthScale(float widthScale)
{
int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapWidthScale(new HandleRef(this, nativeCap), widthScale);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
private float _GetWidthScale()
{
float widthScale;
int status = SafeNativeMethods.Gdip.GdipGetCustomLineCapWidthScale(new HandleRef(this, nativeCap), out widthScale);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
return widthScale;
}
///
///
/// Gets or sets the amount by which to scale
/// the width of the cap.
///
public float WidthScale
{
get { return _GetWidthScale(); }
set { _SetWidthScale(value); }
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RoleManagerEventArgs.cs
- PropertyEntry.cs
- thaishape.cs
- ColumnMapCopier.cs
- NameValueConfigurationCollection.cs
- BindingExpressionBase.cs
- XamlTreeBuilderBamlRecordWriter.cs
- XsltFunctions.cs
- X509ServiceCertificateAuthenticationElement.cs
- StylusPointDescription.cs
- ActivityInterfaces.cs
- AsyncDataRequest.cs
- FormatConvertedBitmap.cs
- DetailsViewInsertedEventArgs.cs
- RowToParametersTransformer.cs
- CodeArgumentReferenceExpression.cs
- MembershipPasswordException.cs
- ForAllOperator.cs
- Point4DValueSerializer.cs
- DeviceSpecificDesigner.cs
- Array.cs
- CheckBoxField.cs
- ResolveDuplexAsyncResult.cs
- System.Data_BID.cs
- URLString.cs
- WinEventWrap.cs
- HttpValueCollection.cs
- WSFederationHttpSecurity.cs
- SByteStorage.cs
- XmlDictionaryString.cs
- DataBoundControl.cs
- ClientCultureInfo.cs
- BitmapData.cs
- ObjectDataSourceFilteringEventArgs.cs
- Simplifier.cs
- HtmlTableRowCollection.cs
- UInt16.cs
- Column.cs
- ProjectionRewriter.cs
- UnionCqlBlock.cs
- ParallelDesigner.xaml.cs
- Atom10FormatterFactory.cs
- _PooledStream.cs
- CachedTypeface.cs
- Parser.cs
- EndEvent.cs
- PKCS1MaskGenerationMethod.cs
- LockCookie.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- ExcludeFromCodeCoverageAttribute.cs
- UpDownEvent.cs
- Int16AnimationUsingKeyFrames.cs
- EditorPart.cs
- ConcurrencyMode.cs
- Base64Stream.cs
- ReadOnlyDictionary.cs
- XmlWriterTraceListener.cs
- OpCodes.cs
- MethodBuilderInstantiation.cs
- CodeVariableReferenceExpression.cs
- DrawingBrush.cs
- Size.cs
- TextOnlyOutput.cs
- CounterCreationDataConverter.cs
- BitmapImage.cs
- WebPartCatalogAddVerb.cs
- RowSpanVector.cs
- CommonDialog.cs
- InstanceNotFoundException.cs
- NameTable.cs
- MorphHelper.cs
- DetailsViewModeEventArgs.cs
- GroupBoxRenderer.cs
- XmlDataSourceDesigner.cs
- ContentType.cs
- FileUtil.cs
- TrustManagerPromptUI.cs
- StateMachineWorkflowInstance.cs
- RawTextInputReport.cs
- ControlsConfig.cs
- RegexNode.cs
- ThrowHelper.cs
- FontStyles.cs
- QueryComponents.cs
- TextBoxBaseDesigner.cs
- SortableBindingList.cs
- EncodingConverter.cs
- SharedDp.cs
- Security.cs
- StagingAreaInputItem.cs
- StorageBasedPackageProperties.cs
- StorageConditionPropertyMapping.cs
- OutputCacheSection.cs
- SectionXmlInfo.cs
- InstanceKeyView.cs
- NumberAction.cs
- MbpInfo.cs
- FixedSOMLineCollection.cs
- coordinatorscratchpad.cs
- GlyphingCache.cs