Thread Rating:
  • 393 Vote(s) - 2.84 Average
  • 1
  • 2
  • 3
  • 4
  • 5
フォーカスを受け付けないボタン押下時に、別テキストフィールドの入力確定を行う
05-20-2013, 07:51 AM,
#5
RE: フォーカスを受け付けないボタン押下時に、別テキストフィールドの入力確定を行う
「フォーカスを受け付けない」というのは、「takes-focus?=false」のことを言っていました。
回りくどくてすいません。

handle-event をオーバーライドして、Action イベント時に、
画面内のフォーカスを持っているコントロールに対して、強制的にFocusEventを発行させ、
関連する処理がすべて流れてから Actionの処理を流す、という意図のコードを書いてみました。

dispatch-events がこれで意図通り動くのか、 get-focus-manager で
フォーカスマネージャが取得できなかったときにどうすべきかなど、
いろいろ不十分な点がありそうです。


また、たしかに、ボタンでなく、グラフィックでボタンと同様の機能を作るときには、
別途方法を考えなくてはいけないかもですね。



Code:
{define-proc public {clean-screen-focus g:Graphic}:void
    ||ファンクションキーなど、フォーカスを持たないボタンが押された時に、
    ||画面内のチェックを行う場合などで、
    ||コントロールの値確定時に画面の内容を修正する機能が実行されない。
    ||上記の問題を対応するために、ボタンが押されたら、
    ||一度、画面内のフォーカスをコントロールからフォーカスアウトをさせ値確定をさせる
    {if-non-null fm = { {g.get-graphical-root}.get-focus-manager }then
        {if-non-null target = fm.keyboard-focus-target then
            {type-switch target
             case cui:ControlUI  do
                ||グリッド内のセルなどで、UIにフォーカスがある場合は、
                ||コントロールで FocusOut イベント発生させる
                ||{cui.control.handle-event {ValueFinished}}
                {cui.control.handle-event {FocusOut}}
             else
                {target.handle-event {FocusOut}}
            }
        }
    }
}
{define-class public CustomCommandButton {inherits CommandButton}
  {constructor public {default ... }
    {construct-super.CommandButton
        {splice ...}
    }
  }
  {method public {handle-event event:Event}:void
    {type-switch event
     case a:Action do
        ||フォーカスを受け付けないボタンの場合、
        ||ValueFinishedなどでイベントを起こすコントロールのイベントを起こすために
        ||現在フォーカスを持っているコントロールをフォーカスアウトさせる
        {if not self.takes-focus? then
            {clean-screen-focus self}
        }
        ||上記 clean-screen-focus で発生させた FocusOut に関連する処理を先に流す
        {dispatch-events true}
        
        {super.handle-event a}
     else
        {super.handle-event event}
    }
  }
}

{value
    || コピー元TextField
    def src-tf =
        {TextDisplay
            width=3cm
        }
    || コピー先TextField
    def dst-tf =
        {TextDisplay
            width=3cm
        }
    ||ValueFinishedで値を反映する
    def input-tf =
        {TextField
            width=3cm,
            {on ValueFinished at tf:TextField do
                set src-tf.value = tf.value
            }
        }

    || コピー実行ボタン代わりのグラフィックオブジェクト
    def copy-button =
        {CustomCommandButton
            label = "&Copy",
            takes-focus? = false,
            {on Action do
                || TextFieldに入力されて確定されている値をコピー
                {set dst-tf.value = src-tf.value}
            }
        }
    ||
    {VBox
        halign="center",
        {VBox
            {text 上段のテキストを下段へコピーします},
            {text 「Copy」ボタンまたはCtrl+cキーを押してください}
        },
        input-tf,
        src-tf,
        copy-button,
        dst-tf
    }
}


Messages In This Thread
RE: フォーカスを受け付けないボタン押下時に、別テキストフィールドの入力確定を行う - by umemura - 05-20-2013, 07:51 AM
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('897')