Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2FontConverter.cs / 1 / COM2FontConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.ComponentModel.Com2Interop { using System.Runtime.Serialization.Formatters; using System.Runtime.InteropServices; using System.ComponentModel; using System.Diagnostics; using System; using System.Drawing; using System.Collections; using Microsoft.Win32; ////// /// This class maps an OLE_COLOR to a managed Color editor. /// internal class Com2FontConverter : Com2DataTypeToManagedDataTypeConverter { private IntPtr lastHandle = IntPtr.Zero; private Font lastFont = null; public override bool AllowExpand { get { return true; } } ////// /// Returns the managed type that this editor maps the property type to. /// public override Type ManagedType { get { return typeof(Font); } } ////// /// Converts the native value into a managed value /// public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd) { // we're getting an IFont thing here UnsafeNativeMethods.IFont nativeFont = nativeValue as UnsafeNativeMethods.IFont; if (nativeFont == null) { lastHandle = IntPtr.Zero; lastFont = Control.DefaultFont; return lastFont; } IntPtr fontHandle = nativeFont.GetHFont(); // see if we have this guy cached if (fontHandle == lastHandle && lastFont != null) { return lastFont; } lastHandle = fontHandle; try { // this wasn't working because it was converting everything to // world units. // Font font = Font.FromHfont(lastHandle); try { lastFont = ControlPaint.FontInPoints(font); } finally { font.Dispose(); } } catch(ArgumentException) { // we will fail on non-truetype fonts, so // just use the default font. lastFont = Control.DefaultFont; } return lastFont; } ////// /// Converts the managed value into a native value /// public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet) { // we default to black. // if (managedValue == null) { managedValue = Control.DefaultFont; } cancelSet = true; if (lastFont != null && lastFont.Equals(managedValue)) { // don't do anything here. return null; } lastFont = (Font)managedValue; UnsafeNativeMethods.IFont nativeFont = (UnsafeNativeMethods.IFont)pd.GetNativeValue(pd.TargetObject); // now, push all the values into the native side if (nativeFont != null) { bool changed = ControlPaint.FontToIFont(lastFont, nativeFont); if (changed) { // here, we want to pick up a new font from the handle lastFont = null; ConvertNativeToManaged(nativeFont, pd); } } return null; } } } // 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
- WindowsStartMenu.cs
- WebPartDescription.cs
- BaseTreeIterator.cs
- ASCIIEncoding.cs
- _BaseOverlappedAsyncResult.cs
- Binding.cs
- WhitespaceRuleReader.cs
- MediaPlayerState.cs
- X509Utils.cs
- Random.cs
- PointHitTestParameters.cs
- ResourcePermissionBase.cs
- RenderDataDrawingContext.cs
- SevenBitStream.cs
- CodeLinePragma.cs
- ScrollBarAutomationPeer.cs
- TableLayoutSettingsTypeConverter.cs
- TraceHandler.cs
- DataRow.cs
- DataGridViewImageColumn.cs
- AutoGeneratedField.cs
- PagedDataSource.cs
- ResolvedKeyFrameEntry.cs
- Matrix3DStack.cs
- ExpressionConverter.cs
- ContravarianceAdapter.cs
- WSHttpBindingElement.cs
- LiteralSubsegment.cs
- SessionEndedEventArgs.cs
- IntellisenseTextBox.designer.cs
- FileCodeGroup.cs
- FileDialog_Vista_Interop.cs
- WebException.cs
- BaseTemplateCodeDomTreeGenerator.cs
- processwaithandle.cs
- unsafenativemethodstextservices.cs
- TreeViewImageKeyConverter.cs
- PropertyValueUIItem.cs
- CompositeControl.cs
- AQNBuilder.cs
- DecimalConverter.cs
- TextEditorParagraphs.cs
- GlobalEventManager.cs
- Mappings.cs
- XmlBinaryReader.cs
- EventWaitHandleSecurity.cs
- HttpCookiesSection.cs
- Function.cs
- SqlNode.cs
- PrimaryKeyTypeConverter.cs
- ScaleTransform.cs
- WebPartEditorCancelVerb.cs
- VarRefManager.cs
- EventProxy.cs
- FrameworkReadOnlyPropertyMetadata.cs
- OpCodes.cs
- DynamicValueConverter.cs
- AdornerDecorator.cs
- ProviderUtil.cs
- AttachedPropertyMethodSelector.cs
- CodeMethodInvokeExpression.cs
- ControlIdConverter.cs
- DataControlField.cs
- MarkupCompilePass1.cs
- DetailsViewPageEventArgs.cs
- AnnotationHelper.cs
- HttpListener.cs
- TextServicesPropertyRanges.cs
- ErrorFormatterPage.cs
- PersonalizationProvider.cs
- SqlInternalConnection.cs
- SqlResolver.cs
- FontUnitConverter.cs
- StringConverter.cs
- RectangleGeometry.cs
- DesignerActionList.cs
- PaintValueEventArgs.cs
- XPathChildIterator.cs
- ResourceSet.cs
- DataTableNewRowEvent.cs
- TrackBar.cs
- ControlSerializer.cs
- MsdtcClusterUtils.cs
- HttpResponse.cs
- DriveInfo.cs
- PowerModeChangedEventArgs.cs
- Misc.cs
- GC.cs
- DataSourceIDConverter.cs
- HighlightVisual.cs
- DecimalMinMaxAggregationOperator.cs
- JournalEntry.cs
- WebPartChrome.cs
- DefaultShape.cs
- httpserverutility.cs
- ExtensibleClassFactory.cs
- MailSettingsSection.cs
- CodeCommentStatementCollection.cs
- TagPrefixCollection.cs
- ContentHostHelper.cs