Emulating a SortedCombo control, with a difference..

I wrote this demo quite some time ago in response to a question on the Euphoria mailing list. A normal combo dropdown can only be as wide as it's parent window. This is my attempt to emulate a combo in which the 'dropdown' portion is wider than it's parent, so that more text can be shown in the dropdown window.

This was done by simply using a read-only EditText box with a PictureButton beside it to 'fake' a combo parent. Clicking on the PictureButton will display a sorted list, which is normally hidden. Clicking on it again, will hide the sorted list again.

Single-clicking on a list item will copy the selected text to the EditText box, and double-clicking on a text item in the list will both copy the selected text, *and* hide the list box.

An event handler, ( onchange_list() ),
keeps track of user input ( for both the mouse *and* the enter key ), from the sorted list, and the 'flag' parameter keeps track of the inputs received, so the program can respond accordingly.

-- combo_emu.exw

include win32lib.ew

--select an item from the list by left-double-click, or ENTER key, or
--by closing the list thru the picturebutton.
--As written, this defaults to the '(setIndex)ed' list item.

include win32lib.ew
without warning

integer flag
flag=0

-- here's the data for our 'combo' dropdown.
sequence list
list={"Abc", "Easy", "as", "123",
 "This one is supposed to be extremely long and run out of the combobox.",
 "more", "and more", "and another", "take that!", "ok", "enough already"}

--all our windows,
-- with the SortedList() window longer than the EditText() window.
constant
Win      = create( Window, "Combo emulation", 0, 10, 10, 440, 190, 0 ),
edittext = create( EditText, "", Win, 5, 10, 160, 21, ES_READONLY ),
picture  = create( PictureButton, "", Win, 161, 10, 21, 21, 0 ),
yourlist = create( SortedList, "", Win, 6, 30, 420, 100, 0 ),
exitbtn  = create( PushButton, "Exit", Win, 40, 50, 100, 25, 0 ),
selected = create( LText, "selected = ", Win, 5, 130, 440, 20, 0 )

setBitmap(picture,".\\Bin\\arrow.bmp")

for i = 1 to length (list) do
  addItem (yourlist, list[i])
end for
setIndex (yourlist, 4)

integer sel
sequence line

procedure show_list( integer self, integer event, sequence params )
if flag=0 then
  setVisible(exitbtn,False)
  setVisible(yourlist,True)
  setFocus(yourlist)  flag=1
else
  setVisible(yourlist,False)
  setVisible(exitbtn,True)
  sel = getIndex(yourlist)
  if sel >= 1 then
    line = getItem(yourlist, sel)
    setText(edittext,line)
    setText(selected,"selected = " & line)
  end if
  setFocus(edittext)
  flag = 0
end if
end procedure

procedure show( integer self, integer event, sequence params )
  show_list( self, event, params )
end procedure

procedure proceed( integer self, integer event, sequence params )
  sel = getIndex(yourlist)
  if sel >= 1 then
    line = getItem(yourlist, sel)
    setText(edittext,line)
    setText(selected,"selected = " & line)
    flag = 1
    show_list( self, event, params )
  end if
end procedure

procedure update( integer self, integer event, sequence params )
  sel = getIndex(yourlist)
  if sel >= 1 then
    line = getItem(yourlist, sel)
    setText(edittext,line)
  end if
end procedure

procedure hide_list( integer self, integer event, sequence params )
  proceed( self, event, params )
  setVisible(yourlist,False)
end procedure


--procedure onchange_list(atom event,atom wParam,atom lParam) -- old param line
procedure onchange_list( integer self, integer event, sequence params )
-- A bit uncertain if this is ok
  integer wParam = params[1]
  event = params[1]  -- cheat old code
  
  if event = WM_KEYDOWN and wParam = VK_RETURN then proceed( self, event, params) end if
  if event = WM_LBUTTONDBLCLK then proceed( self, event, params ) end if
  
end procedure

procedure close_prog( integer self, integer event, sequence params )
  closeWindow(Win)
end procedure

setHandler( Win, w32HOpen, routine_id("hide_list") )
setHandler( picture, w32HClick, routine_id("show_list") )
setHandler( picture, w32HKeyDown, routine_id("show") )
setHandler( yourlist, w32HEvent, routine_id("onchange_list") )
setHandler( yourlist, w32HChange, routine_id("update") )
setHandler( exitbtn, w32HClick, routine_id("close_prog") )

WinMain(Win,Normal)

--------

..end of lesson.

CONTENTS