Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / PbrsForward.cs / 1 / PbrsForward.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Windows.Forms.Design {
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System;
using System.Design;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.Win32;
internal class PbrsForward : IWindowTarget {
private Control target;
private IWindowTarget oldTarget;
// we save the last key down so we can recreate the last message if we need to activate
// the properties window...
//
private Message lastKeyDown;
private ArrayList bufferedChars;
private const int WM_PRIVATE_POSTCHAR = NativeMethods.WM_USER + 0x1598;
private bool postCharMessage;
private IMenuCommandService menuCommandSvc;
private IServiceProvider sp;
private bool ignoreMessages = false;
public PbrsForward(Control target, IServiceProvider sp) {
this.target = target;
this.oldTarget = target.WindowTarget;
this.sp = sp;
target.WindowTarget = this;
}
private IMenuCommandService MenuCommandService {
get {
if (menuCommandSvc == null && sp != null) {
menuCommandSvc = (IMenuCommandService)sp.GetService(typeof(IMenuCommandService));
}
return menuCommandSvc;
}
}
private ISupportInSituService InSituSupportService {
get {
return (ISupportInSituService)sp.GetService(typeof(ISupportInSituService));
}
}
public void Dispose() {
target.WindowTarget = oldTarget;
}
///
///
/// Called when the window handle of the control has changed.
///
void IWindowTarget.OnHandleChange(IntPtr newHandle){
}
///
///
/// Called to do control-specific processing for this window.
///
void IWindowTarget.OnMessage(ref Message m){
// Get the Designer for the currently selected item on the Designer...
// SET STATE ..
ignoreMessages = false;
// Here lets query for the ISupportInSituService.
// If we find the service then ask if it has a designer which is interested
// in getting the keychars by querring the IgnoreMessages.
if (m.Msg >= NativeMethods.WM_KEYFIRST && m.Msg <= NativeMethods.WM_KEYLAST
|| (m.Msg >= NativeMethods.WM_IME_STARTCOMPOSITION && m.Msg <= NativeMethods.WM_IME_COMPOSITION)) {
if (InSituSupportService != null)
{
ignoreMessages = InSituSupportService.IgnoreMessages;
}
}
switch (m.Msg) {
case WM_PRIVATE_POSTCHAR:
if (bufferedChars == null) {
return;
}
// recreate the keystroke to the newly activated window
IntPtr hWnd = IntPtr.Zero;
if (!ignoreMessages) {
hWnd = NativeMethods.GetFocus();
}
else {
if (InSituSupportService != null)
{
hWnd = InSituSupportService.GetEditWindow();
}
else {
hWnd = NativeMethods.GetFocus();
}
}
if (hWnd != m.HWnd) {
foreach (BufferedKey bk in bufferedChars) {
if (bk.KeyChar.Msg == NativeMethods.WM_CHAR) {
if (bk.KeyDown.Msg != 0) {
NativeMethods.SendMessage(hWnd, NativeMethods.WM_KEYDOWN, bk.KeyDown.WParam, bk.KeyDown.LParam);
}
NativeMethods.SendMessage(hWnd, NativeMethods.WM_CHAR, bk.KeyChar.WParam, bk.KeyChar.LParam);
if (bk.KeyUp.Msg != 0) {
NativeMethods.SendMessage(hWnd, NativeMethods.WM_KEYUP, bk.KeyUp.WParam, bk.KeyUp.LParam);
}
}
else {
NativeMethods.SendMessage(hWnd, bk.KeyChar.Msg, bk.KeyChar.WParam, bk.KeyChar.LParam);
}
}
}
bufferedChars.Clear();
return;
case NativeMethods.WM_KEYDOWN:
this.lastKeyDown = m;
break;
case NativeMethods.WM_IME_ENDCOMPOSITION:
case NativeMethods.WM_KEYUP:
this.lastKeyDown.Msg = 0;
break;
case NativeMethods.WM_CHAR:
case NativeMethods.WM_IME_STARTCOMPOSITION:
case NativeMethods.WM_IME_COMPOSITION:
ISelectionService selService = (ISelectionService)sp.GetService(typeof(ISelectionService));
if ((Control.ModifierKeys & (Keys.Control | Keys.Alt)) != 0) {
break;
}
if (bufferedChars == null) {
bufferedChars = new ArrayList();
}
bufferedChars.Add(new BufferedKey(lastKeyDown, m, lastKeyDown));
if (!ignoreMessages && MenuCommandService != null) {
// throw the properties window command, we will redo the keystroke when we actually
// lose focus
postCharMessage = true;
MenuCommandService.GlobalInvoke(StandardCommands.PropertiesWindow);
}
else if (ignoreMessages && m.Msg != NativeMethods.WM_IME_COMPOSITION)
{
if (InSituSupportService != null)
{
postCharMessage = true;
InSituSupportService.HandleKeyChar();
}
}
if (postCharMessage) {
// If copy of message has been buffered for forwarding, eat the original now
return;
}
break;
case NativeMethods.WM_KILLFOCUS:
if (postCharMessage) {
// see ASURT 45313
// now that we've actually lost focus, post this message to the queue. This allows
// any activity that's in the queue to settle down before our characters are posted.
// to the queue.
//
// we post because we need to allow the focus to actually happen before we send
// our strokes so we know where to send them
//
// we can't use the wParam here because it may not be the actual window that needs
// to pick up the strokes.
//
UnsafeNativeMethods.PostMessage(target.Handle, WM_PRIVATE_POSTCHAR, IntPtr.Zero, IntPtr.Zero);
postCharMessage = false;
}
break;
}
if (this.oldTarget != null) {
oldTarget.OnMessage(ref m);
}
}
private struct BufferedKey {
public readonly Message KeyDown;
public readonly Message KeyUp;
public readonly Message KeyChar;
public BufferedKey(Message keyDown, Message keyChar, Message keyUp) {
this.KeyChar = keyChar;
this.KeyDown = keyDown;
this.KeyUp = keyUp;
}
}
}
}
// 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
- StrokeDescriptor.cs
- RootProfilePropertySettingsCollection.cs
- Scene3D.cs
- SubMenuStyleCollection.cs
- TypefaceMap.cs
- CellQuery.cs
- sqlmetadatafactory.cs
- ObjectStorage.cs
- ReaderWriterLock.cs
- WpfGeneratedKnownTypes.cs
- SecurityManager.cs
- Int64AnimationUsingKeyFrames.cs
- HitTestWithGeometryDrawingContextWalker.cs
- RectAnimationClockResource.cs
- ContentIterators.cs
- InvokeCompletedEventArgs.cs
- MultiAsyncResult.cs
- AddInAttribute.cs
- SID.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- FileLevelControlBuilderAttribute.cs
- CorrelationToken.cs
- ReliableChannelListener.cs
- WindowsToolbar.cs
- SpeechDetectedEventArgs.cs
- SQLBinaryStorage.cs
- RectangleConverter.cs
- SqlMultiplexer.cs
- ExpressionWriter.cs
- SortedSetDebugView.cs
- RequestQueue.cs
- DocobjHost.cs
- DesignerObjectListAdapter.cs
- CompilerGlobalScopeAttribute.cs
- SQLBytes.cs
- WorkflowPersistenceContext.cs
- ConfigurationManagerInternal.cs
- DelegatingTypeDescriptionProvider.cs
- SplashScreen.cs
- ApplicationSettingsBase.cs
- RecordConverter.cs
- ImageKeyConverter.cs
- _AcceptOverlappedAsyncResult.cs
- PageAsyncTask.cs
- DependencyObjectProvider.cs
- AxDesigner.cs
- Pair.cs
- RequiredArgumentAttribute.cs
- VectorCollectionConverter.cs
- PropertyChangedEventManager.cs
- ElasticEase.cs
- StructuralType.cs
- XmlRootAttribute.cs
- HWStack.cs
- SafeFindHandle.cs
- PropertiesTab.cs
- NumericUpDownAcceleration.cs
- HtmlPanelAdapter.cs
- LayoutTableCell.cs
- TimerElapsedEvenArgs.cs
- AmbientLight.cs
- SrgsDocument.cs
- XmlSchemaChoice.cs
- CapabilitiesAssignment.cs
- Utilities.cs
- WriterOutput.cs
- StringBuilder.cs
- ViewDesigner.cs
- HttpProfileBase.cs
- ReflectEventDescriptor.cs
- DocumentApplicationJournalEntryEventArgs.cs
- SafeFindHandle.cs
- DataGridState.cs
- BounceEase.cs
- SchemaTypeEmitter.cs
- ProfilePropertyNameValidator.cs
- SqlStatistics.cs
- XamlPoint3DCollectionSerializer.cs
- ModelTreeEnumerator.cs
- filewebrequest.cs
- BamlRecordReader.cs
- DocumentReference.cs
- XmlDocumentSerializer.cs
- ActivityUtilities.cs
- HashLookup.cs
- _LocalDataStore.cs
- DocumentScope.cs
- CodeTypeReferenceCollection.cs
- DPTypeDescriptorContext.cs
- TextBlock.cs
- IConvertible.cs
- PropertyGridCommands.cs
- HttpHandlerActionCollection.cs
- ObjectPropertyMapping.cs
- _IPv4Address.cs
- SecurityKeyUsage.cs
- EventLogTraceListener.cs
- HtmlTable.cs
- CorrelationManager.cs
- AudioBase.cs