LCL Key Handling/ja

From Free Pascal wiki
Jump to navigationJump to search

English (en) 日本語 (ja) português (pt)

日本語版メニュー
メインページ - Lazarus Documentation日本語版 - 翻訳ノート - 日本語障害情報

キーを押し下げた (KeyDown)

widgetsetがキーを押されたことを受け取ると、次のようにふるまいます。 "ネイティブ"なwidgetにキーを処理させる前に、CN_KEYDOWNやCN_SYSKEYDOWNをLCLに送ります。(CN_SYSKEYDOWNはaltキーが押されたときに発生します。) これは、DoKeyDownBeforeInterfaceが次のようなフローでコールします。

  1. Application.NotifyKeyDownBeforeHandlerがコールされます。 (ハンドラの前に呼び出されます。)
  2. keypreviewがある親フォームを取得し、そのDoKeyDownBeforeInterfaceメソッドを呼び出します。
  3. 関連づけられているdragobjectにキーを処理させます。
  1. KeyDownBeforeInterfaceをコールします。 (もし、コントロールがcsNoStdEventsをControlStyleに持っていない場合):
    1. KeyDownをコールします。
      1. OnKeyDown ハンドラがあればコールします。

もし、キーが処理されなければ(すなわち、Message.Result=0)、widgetにキーを処理させます。もしwidgetが有意義なことをすることがなければ、LCLにLM_KEYDOWN/LM_SYSKEYDOWNメッセージを送ります。これは、DoRemainingKeyDownを次のようなフローでコールします。

  1. もしpopupmenuが割り当てられていれば、(それがポップアップされているかどうかにかかわらず)、ショートカットをチェックします。
  2. 親フォームを取得し、ショートカットが有効ならば処理させます。(TCustomForm.IsShortcut):
    1. フォームにOnShortcutイベントがあれば、それをコールします。
    2. フォームにMenuがあれば、そのショートカットをチェックします。:
      • このメニューの全てのアイテムをイテレーションして、ショートカットをチェックして、該当するなら、そのアイテムの".Click"をコールします。
      • もし、そのショートカットを処理しなかったり、後続のキー処理をさせたくない場合は、メニューアイテムのOnClickハンドラ内でメニューのShortcutHandledプロパティをfalseにします。
    3. アクションリストのショートカットをチェックして、一致するアクションの.Executeを実行します。
  3. アプリケーションにショートカットを処理させます。(Application.IsShortcut):
    1. もし、アプリケーションのOnShortcutが割り当てられていれ呼び出します。
    2. もし、モーダルフォームがアクティブになっている場合は、それにショートカットを処理させます。(上記の TCustomForm.IsShortcut を参照)
    3. そうでなくて、もしフォーカスされたフォームがある場合(Screen.ActiveCustomForm), そのフォームにショートカットを処理させます。
    4. そうではなくて、もし、メインフォームがあれば(Application.MainForm), そのフォームにショートカットを処理させます。
  4. if there is a Parent, iteratively call Parent.ChildKey to handle key message
    • use it to handle key shortcuts in a certain "area", for example a panel
    • TWinControl will call it's Parent's ChildKey; that's the "iteratively"
  5. call ControlKeyDown, which in TWinControl, calls Application.ControlKeyDown:
    1. handle tab navigation for controls
    • if your custom control does something special with tab, override and inhibit, for example TCustomMemo
  6. call KeyDownAfterInterface; TWinControl does nothing here
  7. let Application call KeyDownAfter handlers

Note that result (returning 1 or 0 in Message.Result) matters sometimes: windows for example will only send a WM_CHAR message for a key when a WM_KEYDOWN message that key has returned 0.

キーを押している, キャラクタが送られている(KeyPress)

The widgetset can either send CN_CHAR message, or call the IntfUtf8KeyPress method. CN_CHAR does not support UTF-8 characters, so that is why a IntfUtf8KeyPress exists. CN_CHAR handling consists of:

  1. if widgetset (interface) does not send utf8 key presses, then call IntfUtf8KeyPress
  2. call DoKeyPress:
    1. get parent form, and if it has KeyPreview call it's DoKeyPress
    2. call KeyPress (if control does not have csNoStdEvents in ControlStyle):
      1. call OnKeyPress handler if any

IntfUtf8KeyPress (DoUtf8KeyPress) handling consists of:

  1. get parent form, and if it has KeyPreview call it's DoUtf8KeyPress
  2. call Utf8KeyPress (if control does not have csNoStdEvents in ControlStyle):
    1. call OnUtf8KeyPress handler if any

When unhandled, that is, Message.Result = 0, it lets the widget handle the key, and if the widget has not done anything useful, then send a LM_CHAR/LM_SYSCHAR message to the LCL, which calls SendDialogChar consisting of:

  1. get parent form and if found call it's .DialogChar:
    1. TWinControl broadcasts DialogChar to all it's children
      • use it to implement accelerator shortcuts for controls "near" (on the same form) as the focused control
      • example: TCustomLabel uses it to Focus the assigned .FocusControl when alt+accelerator is pressed

押されているキーを離した(KeyUp)

Releasing a key is very much, in the order of events happening, alike pressing a key, but some functions are missing. Again the widgetset will send a CN_KEYUP/CN_SYSKEYUP to the LCL before letting the widget handle the key, which will call DoKeyUpBeforeInterface consisting of:

  1. get parent form, if it has keypreview, call it's DoKeyUpBeforeInterface
  2. let the associated dragobject handle the key
  3. call KeyUpBeforeInterface (if control does not have csNoStdEvents in ControlStyle):
    1. call KeyUp:
      1. call OnKeyUp handler if any

When unhandled, that is, Message.Result = 0, it lets the widget handle the key, and if the widget has not done anything useful, then send a LM_KEYUP/LM_SYSKEYUP message to the LCL, which calls DoRemainingKeyUp consisting of:

  1. call ControlKeyUp, which in TWinControl, calls Application.ControlKeyDown:
    1. handle Enter and Escape keys for forms
    • if your custom control does something special with enter and escape, override and inhibit
  2. call KeyUpAfterInterface; TWinControl does nothing here