Code:
/ FX-1434 / FX-1434 / 1.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
- MenuItem.cs
- MatrixStack.cs
- coordinatorscratchpad.cs
- EventListenerClientSide.cs
- Preprocessor.cs
- ComponentEvent.cs
- UnauthorizedWebPart.cs
- ConnectionStringEditor.cs
- HtmlTableCell.cs
- FontSource.cs
- PopOutPanel.cs
- AspNetSynchronizationContext.cs
- FileUpload.cs
- MediaPlayer.cs
- TextBox.cs
- ReflectionUtil.cs
- DynamicQueryStringParameter.cs
- SaveFileDialog.cs
- RequestCachingSection.cs
- CodeDomSerializerException.cs
- DbConnectionClosed.cs
- ServerProtocol.cs
- IdentityNotMappedException.cs
- RichTextBox.cs
- HTMLTagNameToTypeMapper.cs
- _AutoWebProxyScriptHelper.cs
- LocatorManager.cs
- VerificationAttribute.cs
- ObjectStateManagerMetadata.cs
- SiteIdentityPermission.cs
- WebPartCloseVerb.cs
- XmlAttributeAttribute.cs
- NativeMethods.cs
- XmlSchemaException.cs
- CroppedBitmap.cs
- ProcessThreadCollection.cs
- TextRangeProviderWrapper.cs
- _CookieModule.cs
- NamespaceTable.cs
- CheckBoxPopupAdapter.cs
- PropertyChangeTracker.cs
- xsdvalidator.cs
- SQLDecimal.cs
- WebBrowserBase.cs
- DataObjectSettingDataEventArgs.cs
- BooleanKeyFrameCollection.cs
- WorkflowMarkupElementEventArgs.cs
- ReflectTypeDescriptionProvider.cs
- ToolStripItemClickedEventArgs.cs
- TimeStampChecker.cs
- XPathSelectionIterator.cs
- MatrixIndependentAnimationStorage.cs
- SiteMapNode.cs
- QueueProcessor.cs
- MD5.cs
- UTF7Encoding.cs
- SerializationHelper.cs
- FunctionNode.cs
- EdmFunctionAttribute.cs
- BaseParagraph.cs
- TranslateTransform.cs
- PointValueSerializer.cs
- HttpModuleActionCollection.cs
- ConstraintStruct.cs
- WebPageTraceListener.cs
- Debug.cs
- TypeListConverter.cs
- DSASignatureDeformatter.cs
- WebMessageEncoderFactory.cs
- SignatureDescription.cs
- IdnElement.cs
- BitmapCacheBrush.cs
- PeoplePickerWrapper.cs
- Compiler.cs
- SqlFactory.cs
- CookielessData.cs
- WindowsGraphics2.cs
- MaskedTextBoxTextEditorDropDown.cs
- OleDbErrorCollection.cs
- PointHitTestResult.cs
- AuthStoreRoleProvider.cs
- TrackingProfile.cs
- MembershipUser.cs
- Floater.cs
- assemblycache.cs
- CharAnimationUsingKeyFrames.cs
- TriState.cs
- JsonDeserializer.cs
- BaseDataBoundControl.cs
- X509ChainPolicy.cs
- StrokeNodeEnumerator.cs
- PropertyEmitterBase.cs
- DataControlImageButton.cs
- InvariantComparer.cs
- ProxyFragment.cs
- ColumnClickEvent.cs
- AndCondition.cs
- WebBaseEventKeyComparer.cs
- HttpMethodConstraint.cs
- CacheSection.cs