Ejemplo n.º 1
0
        /// <summary>
        /// Checks if a specified keystroke is a shortcut on Yata's Menubar.
        /// </summary>
        /// <param name="keyData"></param>
        /// <returns><c>true</c> if <paramref name="keyData"/> is a shortcut</returns>
        internal static bool isShortcut(Keys keyData)
        {
            ToolStripMenuItem it;

            ToolStripItemCollection its = Yata.that._bar.Items;

            for (int i = 0; i != its.Count; ++i)             // rifle through the top-level Menu its ->
            {
                if ((it = its[i] as ToolStripMenuItem) != null &&
                    it.Visible && it.Enabled)
                {
//					if ((e.KeyData & ~gc.ControlShift) != 0)
//						logfile.Log(it.Text);

                    if (YataStrip.hasShortcut(it, keyData))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Overrides the <c>PreviewKeyDown</c> eventhandler. Sets
        /// <c>e.IsInputKey</c> <c>true</c> for any shortcut that's found in
        /// Yata's menus in order to bypass those operations and allow this
        /// <c>YataEditbox</c> to do its text-related stuff. Eg, <c>[Ctrl+a]</c>
        /// for select-all (instead of File|SaveAll).
        /// </summary>
        /// <param name="e"></param>
        /// <seealso cref="YataStrip"><c>YataStrip.ProcessCmdKey()</c></seealso>
        protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
        {
#if Keys
            if ((e.KeyData & ~gc.ControlShift) != 0)
            {
                logfile.Log("YataEditbox.OnPreviewKeyDown() e.KeyData= " + e.KeyData + " e.IsInputKey= " + e.IsInputKey);
                logfile.Log(". Parent= " + Parent);
            }
#endif

/*			switch (e.KeyData)
 *                      {
 *                              // Set 'e.IsInputKey' TRUE to bypass Menu shortcuts
 *                              // (keystrokes that are used by menuitems) as well as
 *                              // ProcessCmdKey(), IsInputKey(), and ProcessDialogKey().
 *                              // Only keystrokes that .net uses in TextBox AND that are also
 *                              // used on the Menus need 'e.IsInputKey' set TRUE.
 *                              //
 *                              // Note that forcing IsInputKey() TRUE will *not* bypass
 *                              // ProcessCmdKey() but will bypass ProcessDialogKey(). And do
 *                              // *not* rely on .net to figure out whether or not a keystroke
 *                              // is or should be an input-key in IsInputKey() anyway ... tests
 *                              // have indicated that it doesn't.
 *                              //
 *                              // but unfortunately I can't find a complete list of keystrokes
 *                              // that .net's TextBox treats as input-keys. Some of them are
 *                              // totally whacko - eg. [Ctrl+Backspace]. So, to be safe, set
 *                              // all Menu shortcuts to 'e.IsInputKey' here ->
 *                              //
 *                              // unfortunately again, setting 'e.IsInputKey' TRUE does *not*
 *                              // consume the keystroke, and it will still be sent to the
 *                              // OnKeyDown() handlers, bubbling up through the
 *                              // containing controls, if the key-events of those controls are
 *                              // set to fire ... note that during the bubbling, OnKeyDown()
 *                              // for this Editbox fires *last* - *after* YataTabs.OnKeyDown()
 *                              // and Yata.OnKeyDown() in that order, only then does
 *                              // YataEditbox.OnKeyDown() execute.
 *                              //
 *                              //
 *                              // Do *not* try to force 'e.IsInputKey' FALSE in OnPreviewKeyDown()
 *                              // because 'IsInputKey' FALSE will be redetermined by .net in
 *                              // its event-chain to be TRUE by the time IsInputKey() fires, if
 *                              // .net determined a key to be a stock-defined input-key ...
 *                              // that is, .net will say that such a key is *not* an input-key
 *                              // here in OnPreviewKeyDown() but will later say that it *is*
 *                              // an input-key in the return from IsInputKey().
 *                              //
 *                              // IsInputKey TRUE makes the KeyDown event(s) fire, bypassing ProcessDialogKey().
 *                              // IsInputKey FALSE executes ProcessDialogKey(), bypassing the KeyDown events <- not necessarily!
 *                              //
 *                              // The order of keyed events is as follows:
 *                              // - OnPreviewKeyDown
 *                              // - ProcessCmdKey (if !e.IsInputKey) - bubbles up through containing controls
 *                              // - IsInputKey    (if !e.IsInputKey)
 *                              // - ProcessDialogKey OR OnKeyDown    - bubbles up through containing controls, kinda.
 *                              //
 *                              // THIS IS SO F****D. but i think i got it enough to start
 *                              // coding again ...
 *                              //
 *                              //
 *                              // The following keystrokes are used by .net's default TextBox
 *                              // behavior. Keystrokes that are also used outside of the
 *                              // TextBox - eg. in a Menu or in ProcessCmdKey() etc. - need to
 *                              // have 'e.IsInputKey' set TRUE here so that *nothing fires* in
 *                              // Yata other than stuff for this TextBox exclusively ->
 *                              //
 *                              // but note allow [Escape] and [Enter] to bubble up ... through
 *                              // the Process*Key() functs.
 *                              //
 *                              // Note that [Escape] is not actually the ShortcutKeys for
 *                              // Edit|Deselect all ... [Escape] is processed by
 *                              // YataGrid.ProcessCmdKey() iff the editor has focus - note that
 *                              // [Escape] gets treated differently by different Yata-objects.
 *                              //
 *                              // [Enter] is not on the Menu and very likely never will be.
 *
 *
 *                              case Keys.Control | Keys.X: // Cells|Cut
 *                              case Keys.Control | Keys.C: // Cells|Copy
 *                              case Keys.Control | Keys.V: // Cells|Paste
 *                              case Keys.Delete:           // Cells|Delete
 *
 * //				case Keys.Shift | Keys.Delete: // appears to not be hooked by textboxes.
 *
 *                              case Keys.Control | Keys.A: // File|SaveAll
 *
 *                              case Keys.Control | Keys.Z: // Edit|Undo
 *                              case Keys.Control | Keys.Y: // Edit|Redo
 *                                      logfile.Log(". YataEditbox.OnPreviewKeyDown force e.IsInputKey TRUE");
 *                                      e.IsInputKey = true;
 *                                      break;
 *                      } */


            switch (e.KeyData)
            {
            // no need to check these keys for Menu shortcuts ->
            case Keys.Enter:                            // handled in YataGrid.ProcessCmdKey()
            case Keys.Escape:                           // handled in YataGrid.ProcessCmdKey()
                break;

            default:
                if (YataStrip.isShortcut(e.KeyData))
                {
#if Keys
                    logfile.Log(". YataEditbox.OnPreviewKeyDown force e.IsInputKey TRUE (shortcut)");
#endif
                    e.IsInputKey = true;
                }
                break;
            }
            base.OnPreviewKeyDown(e);
        }