1. Trapping return and excape in a ComboBox
- Posted by petelomax at blueyonder.co.uk Sep 01, 2002
- 412 views
{{{ Below is some code which works as expected when name is an EditText, but the onKeyDown routine is not invoked if I change it to a ComboBox.
I think I may be expecting cr & esc to behave differently when the drop down part is, erm, dropped down, than when not. Can it be done?
Pete
code follows
include win32lib.ew
constant MAIN = create( Window, "Test", 0, 100, 50, 370, 160, { WS_DLGFRAME, WS_SYSMENU} ) constant lab1 = create( LText, "&Name", MAIN, 8, 15, 60, 24, 0 ) constant name = create( EditText, "", MAIN, 70, 10, 200, 24, 0 ) constant name = create( ComboBox, "", MAIN, 70, 10, 200, 24, 0 ) constant lab2 = create( LText, "&Address", MAIN, 8, 45, 60, 24, 0 ) constant addr = create( EditText, "", MAIN, 70, 40, 200, 24, 0 ) constant DONE = create( PushButton, "&Done", MAIN, 275, 10, 80, 25, 0 )
procedure ongotfocusllab2() setFocus(addr) end procedure onGotFocus[lab2] = routine_id("ongotfocusllab2")
procedure OK(sequence text) integer void void = message_box(text,text,MB_OK) end procedure
procedure closeMAIN() OK("Close") closeWindow(MAIN) end procedure onClose[MAIN] = routine_id("closeMAIN")
procedure onclick_DONE() OK("CR") end procedure onClick[DONE] = routine_id("onclick_DONE")
global procedure EscapeKeyed() OK("Escape keyed") closeWindow(MAIN) end procedure onClose[MAIN] routine_id("closeMAIN")
global procedure onkeydownintext(integer keycode, integer shift) if keycode = VK_ENTER then onclick_DONE() end if if keycode = VK_ESCAPE then EscapeKeyed() return end if if shift then end if prevents spurious warning end procedure onKeyDown[name] routine_id("onkeydownintext") onKeyDown[addr] = routine_id("onkeydownintext") onKeyDown[DONE] = routine_id("onkeydownintext")
WinMain( MAIN, Normal )
2. Re: Trapping return and excape in a ComboBox
- Posted by petelomax at blueyonder.co.uk Sep 01, 2002
- 392 views
On Sun, 1 Sep 2002 09:43:43 +0000, Mario Steele <euphmario at yahoo.com> wrote: >First off, you do not need to do onGotFocus events for Labels. Labels >never receive focus. True, they don't. It's for the Alt-letter handling. Without it, Alt-A (for Address) hides the focus away somewhere & when you tab it goes back to the First Control Created. >Second, I would suggest you use >onKeyPress, instead of onKeyDown. It works out exactly the same, behaving fine on an EditText control, not on a ComboBox. Ah, I think I have another clue: when the dropdown is showing (see below for changes needed to that example I posted), then CR & ESC *are* trapped for a ComboBox; so it appears to be attaching the onkeyxxx to the list part rather than the edittext part of the combo? >Again, I could be wrong, never know. At least you were right about something Thanks anyway. Pete == update line 6 with depth 240: == constant name = create( ComboBox, "", MAIN, 70, 10, 200, 240, 0 ) = and paste these four lines in at the end to see what I mean: == addItem(name,"one") addItem(name,"two") addItem(name,"three") setText(name,"zero") WinMain( MAIN, Normal )
3. Re: Trapping return and excape in a ComboBox
- Posted by Martin Stachon <martin.stachon at worldonline.cz> Sep 01, 2002
- 392 views
I guess you need to get handle to EditText of ComboBox: sequence kids integer name_subedit name_subedit = 0 kids = findChildren(name) for i = 1 to length(kids) do if kids[i][2] = EditText then name_subedit = kids[i][1] exit end if end for and then add pComboBoxEdit to setHandler : setHandler({name, name_subedit}, w32HKeyDown, routine_id("onkeydownintext") --Martin > Below is some code which works as expected when name is an EditText, > but the onKeyDown routine is not invoked if I change it to a ComboBox. > > I think I may be expecting cr & esc to behave differently when the > drop down part is, erm, dropped down, than when not. Can it be done? > > Pete > === code follows === > include win32lib.ew > > constant MAIN = create( Window, "Test", 0, 100, 50, 370, 160, { > WS_DLGFRAME, WS_SYSMENU} ) > constant lab1 = create( LText, "&Name", MAIN, 8, 15, 60, 24, 0 ) > --constant name = create( EditText, "", MAIN, 70, 10, 200, 24, 0 ) > constant name = create( ComboBox, "", MAIN, 70, 10, 200, 24, 0 ) > constant lab2 = create( LText, "&Address", MAIN, 8, 45, 60, 24, 0 ) > constant addr = create( EditText, "", MAIN, 70, 40, 200, 24, 0 ) > constant DONE = create( PushButton, "&Done", MAIN, 275, 10, 80, 25, 0 > ) > > -- > -- Shift focus from labels to EditText they refer to when needed. > -- > procedure ongotfocuslab1() > setFocus(name) > end procedure > onGotFocus[lab1] = routine_id("ongotfocusllab1") > > procedure ongotfocusllab2() > setFocus(addr) > end procedure > onGotFocus[lab2] = routine_id("ongotfocusllab2") > > procedure OK(sequence text) > integer void > void = message_box(text,text,MB_OK) > end procedure > > procedure closeMAIN() > OK("Close") > closeWindow(MAIN) > end procedure > onClose[MAIN] = routine_id("closeMAIN") > > procedure onclick_DONE() > OK("CR") > end procedure > onClick[DONE] = routine_id("onclick_DONE") > > global procedure EscapeKeyed() > OK("Escape keyed") > closeWindow(MAIN) > end procedure > onClose[MAIN] = routine_id("closeMAIN") > > global procedure onkeydownintext(integer keycode, integer shift) > if keycode = VK_ENTER then > onclick_DONE() > end if > if keycode = VK_ESCAPE then > EscapeKeyed() > return > end if > if shift then end if -- prevents spurious warning > end procedure > onKeyDown[name] = routine_id("onkeydownintext") > onKeyDown[addr] = routine_id("onkeydownintext") > onKeyDown[DONE] = routine_id("onkeydownintext") > > -- > WinMain( MAIN, Normal ) > > >