Autocomplete text control (and its problems)

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
Sjors
In need of some credit
In need of some credit
Posts: 1
Joined: Sat Nov 20, 2004 2:40 pm
Location: Utrecht, Netherlands
Contact:

Autocomplete text control (and its problems)

Post by Sjors »

I needed a text control that anticipates what the user wants to type (like in most browsers, office programs and cell-phones) by creating an ever shrinking dropdown list as the user types. I couldn't find one for wxWidgets, so I decided to try to make one. I'm a beginner in both C++ and wxWidgets, but I managed to get something working. It's on my
homepage and everyone may feel free to use, modify and copy it.
Here is a screenshot of demo application that uses it:
Image

As I also mention on my homepage there are several problems with it:

- (part of) the code is not very elegant
- it is possible for any part of the program to use the help classes (AutocompleteListCtrlPart for the listcontrol and AutocompleteTimerPart). I'm not actually sure if this is a problem, but they are quite specifically designed to be used by the AutocompleteTextCtrl
- I don't know how to handle the tab order of a program; if you press <Tab>, the demonstration program won't jump to another control. I'm not sure if this is something that has to be built into the AutocompleteTextCtrl class or is normally handled some other way.
- if you select a random text (not in the list) and start typing you override the selected text. At the first letter you type there won't be a listcontrol visibible, because the control still sees the original text. It will work fine at the next keypress.
- when a user decides to focus on some other control the listbox part disappears (using a function triggered by a KillFocus event that runs
Jasper
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 21, 2004 1:49 pm
Contact:

Post by Jasper »

Did you consider using a combobox? I think this would solve at least a few problems.
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

No I think Sjors is on to something. You don't want to see that ugly dropdown all the time and I am not sure if all OS'es react the same to auto completion when it comes it a combobox.

I will download your source and comment on some parts when I find the time. If the dropdown can get a border and scroll features then I think we have something that is worth for the wxWidgets contrib in the future. Maybe you can create a modaless dialog for your selection, without any borders and project a wxListBox on there which is updated when the user types. This might be easier...

In any way, it is always nice to see people create new stuff that extends wxWidgets.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Hi!
I think using wxWindow::PopupMenu and creating the list in a menu would solve some problems and improve the look & feel. A problem would be that if the list is too long the menu might get very big.
Another, maybe better way, would be to use a scrolled window.

This is just my first thought, I didn't look into the sources. If you want me too I could have a look at it this weekend (when I hopefully get my internet access back at home :D )
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
raboof
Earned a small fee
Earned a small fee
Posts: 20
Joined: Fri Sep 10, 2004 10:44 pm

Post by raboof »

Jasper wrote:Did you consider using a combobox? I think this would solve at least a few problems.
I gave that a quick shot, see http://bzzt.net/~arnouten/wxautocombobox

on wxGTK, the SetSelection() doesn't apprear to be working quite right. any ideas?
leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio »

In my opinion this should simply be implemented natively.
gtk+ has it, I'm quite sure others have it aswell.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/
Post Reply