SidebarLibrary.Menus.MenuControl.PreFilterMessage C# (CSharp) Method

PreFilterMessage() public method

public PreFilterMessage ( Message &msg ) : bool
msg System.Windows.Forms.Message
return bool
		public bool PreFilterMessage(ref Message msg)
		{
			Form parentForm = this.FindForm();

			// Only interested if the Form we are on is activate (i.e. contains focus)
			if ((parentForm != null) && parentForm.ContainsFocus)
			{
				switch(msg.Msg)
				{
					case (int)Win32.Msg.WM_MDISETMENU:
					case (int)Win32.Msg.WM_MDIREFRESHMENU:
						return true;
					case (int)Win32.Msg.WM_KEYUP:
						{
							// Find up/down state of shift and control keys
							ushort shiftKey = WindowsAPI.GetKeyState((int)Win32.VirtualKeys.VK_SHIFT);
							ushort controlKey = WindowsAPI.GetKeyState((int)Win32.VirtualKeys.VK_CONTROL);

							// Basic code we are looking for is the key pressed...
							int code = (int)msg.WParam;

							// ...plus the modifier for SHIFT...
							if (((int)shiftKey & 0x00008000) != 0)
								code += 0x00010000;

							// ...plus the modifier for CONTROL
							if (((int)controlKey & 0x00008000) != 0)
								code += 0x00020000;

							// Construct shortcut from keystate and keychar
							Shortcut sc = (Shortcut)(code);

							// Search for a matching command
							return GenerateShortcut(sc, _menuCommands);
						}
					case (int)Win32.Msg.WM_SYSKEYUP:
						if ((int)msg.WParam == (int)Win32.VirtualKeys.VK_MENU)
						{
							// If not already in manual focus mode
							if (!_manualFocus)
							{
								// Are there any menu commands?
								if (_drawCommands.Count > 0)
								{
									// If no item is currently tracked then...
									if (_trackItem == -1)
									{
										// ...start tracking the first valid command
										for(int i=0; i<_drawCommands.Count; i++)
										{
											DrawCommand dc = _drawCommands[i] as DrawCommand;

											if (!dc.Separator && (dc.Chevron || dc.MenuCommand.Enabled))
											{
												_trackItem = SwitchTrackingItem(-1, i);
												break;
											}
										}
									}

									// We keep the focus until they move it
									_manualFocus = true;

									// Grab the focus for key events
									GrabTheFocus();
								}

								return true;
							}
						}
						else
						{
							// Construct shortcut from ALT + keychar
							Shortcut sc = (Shortcut)(0x00040000 + (int)msg.WParam);

							if (GenerateShortcut(sc, _menuCommands))
								return true;

							// Last resort is treat as a potential mnemonic
							return ProcessMnemonicKey((char)msg.WParam);
						}
						break;
					default:
						break;
				}
			}

			return false;
		}