wxTextCtrl Autocomplete does not work

181 views
Skip to first unread message

Stefano Mtangoo (evstevemd)

unread,
Nov 7, 2012, 2:56:51 PM11/7/12
to wx-users
Hi,
I need to add Autocomplete of Web addresses on wxTextCtrl. Here is
what I have done
1. Create wxTextCtrl in single line mode

2. Connect it to function that catches url text as it is type
i.e m_url->Bind(wxEVT_COMMAND_TEXT_UPDATED,
&HBrowser::OnUrlAutocomplete, this);

3. Show Autocomplete list in the function i.e

void HBrowser::OnUrlAutocomplete(wxCommandEvent& e)
{
m_url->AutoComplete(m_urlList);//urlList is wxArrayString
}

I have checked the array contain the strings but Autocomplete does not
show. Is there anything else am missing?

I use latest svn (Revision: 72920).

Vadim Zeitlin

unread,
Nov 7, 2012, 6:28:13 PM11/7/12
to wx-u...@googlegroups.com
On Wed, 7 Nov 2012 11:56:51 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:

SM> I need to add Autocomplete of Web addresses on wxTextCtrl.

See the example of using this in the widgets sample. In short, you must
not change the completion whenever the text changes.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Stefano Mtangoo (evstevemd)

unread,
Nov 8, 2012, 2:51:17 AM11/8/12
to wx-users


On Nov 8, 2:28 am, Vadim Zeitlin <va...@wxwidgets.org> wrote:
> On Wed, 7 Nov 2012 11:56:51 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:
>
> SM> I need to add Autocomplete of Web addresses on wxTextCtrl.
>
>  See the example of using this in the widgets sample. In short, you must
> not change the completion whenever the text changes.
>
Thanks for that, I was looking a wrong sample (text sample) and I
could not find.
Can you elaborate what you mean by "In short, you must not change the
completion whenever the text changes."?
I want to accumulate the links as user moves from one site to another.
>  Regards,
> VZ
>
> --
> TT-Solutions: wxWidgets consultancy and technical support
>                http://www.tt-solutions.com/
>
>  application_pgp-signature_part
> < 1KViewDownload

Vadim Zeitlin

unread,
Nov 8, 2012, 5:38:18 AM11/8/12
to wx-u...@googlegroups.com
On Wed, 7 Nov 2012 23:51:17 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:

SM> Can you elaborate what you mean by "In short, you must not change the
SM> completion whenever the text changes."?

You set auto completer once and let it do its work.

SM> I want to accumulate the links as user moves from one site to another.

In this case you probably need to use a custom wxTextCompleter.
Unfortunately currently support for it is only implemented in wxMSW.

Stefano Mtangoo (evstevemd)

unread,
Nov 12, 2012, 8:38:09 AM11/12/12
to wx-users
On Nov 8, 1:38 pm, Vadim Zeitlin <va...@wxwidgets.org> wrote:
> On Wed, 7 Nov 2012 23:51:17 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:
>
> SM> Can you elaborate what you mean by "In short, you must not change the
> SM> completion whenever the text changes."?
>
>  You set auto completer once and let it do its work.
>
> SM> I want to accumulate the links as user moves from one site to another.
>
>  In this case you probably need to use a custom wxTextCompleter.
> Unfortunately currently support for it is only implemented in wxMSW.
I see, any possibility of using this custom completer in Linux?
I believe this is what I need. I will try to do it if it is trivial
(time is becoming scarce these days :))
>
>  Regards,
> VZ
>
> --
> TT-Solutions: wxWidgets consultancy and technical support
>                http://www.tt-solutions.com/
>
>  application_pgp-signature_part
> < 1KViewDownload

Vadim Zeitlin

unread,
Nov 12, 2012, 8:46:45 AM11/12/12
to wx-u...@googlegroups.com
On Mon, 12 Nov 2012 05:38:09 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:

SM> >  In this case you probably need to use a custom wxTextCompleter.
SM> > Unfortunately currently support for it is only implemented in wxMSW.
SM> I see, any possibility of using this custom completer in Linux?

This should be possible because AFAIR GTK allows you to set up an
arbitrary GtkTreeModel as a completer, so in principle just defining a
custom model which calls back to the custom completer at wx level should do
the trick. And yes, it'd be nice to have it...

Stefano Mtangoo (evstevemd)

unread,
Nov 12, 2012, 12:28:02 PM11/12/12
to wx-users


On Nov 12, 4:46 pm, Vadim Zeitlin <va...@wxwidgets.org> wrote:
> On Mon, 12 Nov 2012 05:38:09 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:
>
> SM> >  In this case you probably need to use a custom wxTextCompleter.
> SM> > Unfortunately currently support for it is only implemented in wxMSW.
> SM> I see, any possibility of using this custom completer in Linux?
>
>  This should be possible because AFAIR GTK allows you to set up an
> arbitrary GtkTreeModel as a completer, so in principle just defining a
> custom model which calls back to the custom completer at wx level should do
> the trick. And yes, it'd be nice to have it...
>
>  Regards,
> VZ
>
Let e give it a try!
> --
> TT-Solutions: wxWidgets consultancy and technical support
>                http://www.tt-solutions.com/
>
>  application_pgp-signature_part
> < 1KViewDownload

Stefano Mtangoo (evstevemd)

unread,
Nov 12, 2012, 2:19:30 PM11/12/12
to wx-users


On Nov 12, 8:28 pm, "Stefano Mtangoo (evstevemd)"
<mwinjili...@gmail.com> wrote:
> On Nov 12, 4:46 pm, Vadim Zeitlin <va...@wxwidgets.org> wrote:> On Mon, 12 Nov 2012 05:38:09 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:
>
> > SM> >  In this case you probably need to use a custom wxTextCompleter.
> > SM> > Unfortunately currently support for it is only implemented in wxMSW.
> > SM> I see, any possibility of using this custom completer in Linux?
>
> >  This should be possible because AFAIR GTK allows you to set up an
> > arbitrary GtkTreeModel as a completer, so in principle just defining a
> > custom model which calls back to the custom completer at wx level should do
> > the trick. And yes, it'd be nice to have it...
>
> >  Regards,
> > VZ
>
> Let e give it a try!
>
Hi Vadim,
Sorry for asking here what would have been asked in dev. But I thought
it will be good for continuation.
I have few questions regarding the implementation. So far I have
implemented the wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
*completer) in src/gtk/textentry.cpp. I need to get list of strings
and add them to the GtkEntryCompletion model. Now:
1. How do I get Strings from wxTextCompleter? Should I call GetNext
and ignore the Start? Or have I misunderstood it altogether?
2. GtkEntryCompletion emits few signals. Is there any use of
"catching" them and do processing at wx level or should I let the GTK
deal with the rest?

Thanks
Stefano

Vadim Zeitlin

unread,
Nov 13, 2012, 9:54:59 AM11/13/12
to wx-u...@googlegroups.com
On Mon, 12 Nov 2012 11:19:30 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:

SM> I have few questions regarding the implementation. So far I have
SM> implemented the wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
SM> *completer) in src/gtk/textentry.cpp. I need to get list of strings
SM> and add them to the GtkEntryCompletion model.

I don't think you should do this, it wouldn't make it any different from
AutoComplete(wxArrayString) then. Instead the idea is to implement
GtkTreeModel in terms of wxTextCompleter, i.e. forward GTK+ requests for
its elements to wxTextCompleter. Please look at src/gtk/dataview.cpp to see
how it provides a GtkTreeModel wrapping wxDataViewModel.

SM> Now:
SM> 1. How do I get Strings from wxTextCompleter? Should I call GetNext
SM> and ignore the Start? Or have I misunderstood it altogether?

I hope the above answers this. You definitely must not ignore Start()
because otherwise it would, again, be not any different from just using a
fixed list of strings.

SM> 2. GtkEntryCompletion emits few signals. Is there any use of
SM> "catching" them and do processing at wx level or should I let the GTK
SM> deal with the rest?

I don't think you need to catch any of these signals but I could be wrong.

Regards,
VZ

Stefano Mtangoo (evstevemd)

unread,
Nov 14, 2012, 12:42:16 PM11/14/12
to wx-users


On Nov 13, 5:55 pm, Vadim Zeitlin <va...@wxwidgets.org> wrote:
> On Mon, 12 Nov 2012 11:19:30 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:
>
> SM> I have few questions regarding the implementation. So far I have
> SM> implemented the  wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
> SM> *completer) in src/gtk/textentry.cpp. I need to get list of strings
> SM> and add them to the GtkEntryCompletion model.
>
>  I don't think you should do this, it wouldn't make it any different from
> AutoComplete(wxArrayString) then. Instead the idea is to implement
> GtkTreeModel in terms of wxTextCompleter, i.e. forward GTK+ requests for
> its elements to wxTextCompleter. Please look at src/gtk/dataview.cpp to see
> how it provides a GtkTreeModel wrapping wxDataViewModel.
I understand the concept but lost on how to do the actual "fowarding".
I have looked at file pointed above but I cannot understand how it is
being done.
may be you can help me understand how forwarding is done?
Gtk objects are sometimes confusing when it comes to newbie with
little background in Gtk/C
>
> SM> Now:
> SM> 1. How do I get Strings from wxTextCompleter? Should I call GetNext
> SM> and ignore the Start? Or have I misunderstood it altogether?
>
>  I hope the above answers this. You definitely must not ignore Start()
> because otherwise it would, again, be not any different from just using a
> fixed list of strings.
>
> SM> 2. GtkEntryCompletion emits few signals. Is there any use of
> SM> "catching" them and do processing at wx level or should I let the GTK
> SM> deal with the rest?
>
>  I don't think you need to catch any of these signals but I could be wrong.
>
>  Regards,
> VZ
>
> --
> TT-Solutions: wxWidgets consultancy and technical support
>                http://www.tt-solutions.com/
>
>  application_pgp-signature_part
> < 1KViewDownload

Stefano Mtangoo (evstevemd)

unread,
Nov 14, 2012, 12:51:23 PM11/14/12
to wx-users


On Nov 14, 8:42 pm, "Stefano Mtangoo (evstevemd)"
<mwinjili...@gmail.com> wrote:
> On Nov 13, 5:55 pm, Vadim Zeitlin <va...@wxwidgets.org> wrote:> On Mon, 12 Nov 2012 11:19:30 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:
>
> > SM> I have few questions regarding the implementation. So far I have
> > SM> implemented the  wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
> > SM> *completer) in src/gtk/textentry.cpp. I need to get list of strings
> > SM> and add them to the GtkEntryCompletion model.
>
> >  I don't think you should do this, it wouldn't make it any different from
> > AutoComplete(wxArrayString) then. Instead the idea is to implement
> > GtkTreeModel in terms of wxTextCompleter, i.e. forward GTK+ requests for
> > its elements to wxTextCompleter. Please look at src/gtk/dataview.cpp to see
> > how it provides a GtkTreeModel wrapping wxDataViewModel.
>
> I understand the concept but lost on how to do the actual "fowarding".
> I have looked at file pointed above but I cannot understand how it is
> being done.
> may be you can help me understand how forwarding is done?
> Gtk objects are sometimes confusing when it comes to newbie with
> little background in Gtk/C
>
I think I'm a bit unclear on what I'm facing. If it was pure C++,
Implementing GtkTreeModel would be inheriting it, implementing virtual
methods and it is ready to go.
I cannot find information on how to implement the model. Anyone to
shed light on implementing Gtk+ Models?

Vadim Zeitlin

unread,
Nov 14, 2012, 1:37:03 PM11/14/12
to wx-u...@googlegroups.com
On Wed, 14 Nov 2012 09:42:16 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:

SM> I have looked at file pointed above but I cannot understand how it is
SM> being done.
SM> may be you can help me understand how forwarding is done?
SM> Gtk objects are sometimes confusing when it comes to newbie with
SM> little background in Gtk/C

You need to read a GTK (GObject) tutorial to really understand this but
you actually can just copy the code in src/gtk/dataview.cpp after "define
new GTK+ class wxGtkTreeModel" comment without even understanding it fully.
Of course, it would still be better to understand it... Roughly speaking
you just define a bunch of C functions and then assign pointers to them to
the GTK C++ vtbl equivalent.

As for forwarding itself, it's pretty trivial, look at e.g.
wxgtk_tree_model_get_value() implementation. It is called by GTK+ to get a
value for the given cell and it in turn forwards to wxDataViewModel to get
it and then returns it to GTK+.

You should do something similar here except much simpler because you can
hard code a lot of things instead of having to forward them (e.g. you will
have only one column and there will be no hierarchy for the items so your
iterators would be just trivial indices) and you don't need to support any
extra interfaces so you don't need any g_type_add_interface_static() calls.

Stefano Mtangoo (evstevemd)

unread,
Nov 14, 2012, 1:53:16 PM11/14/12
to wx-users


On Nov 14, 9:37 pm, Vadim Zeitlin <va...@wxwidgets.org> wrote:
> On Wed, 14 Nov 2012 09:42:16 -0800 (PST) Stefano Mtangoo (evstevemd) wrote:
>
> SM> I have looked at file pointed above but I cannot understand how it is
> SM> being done.
> SM> may be you can help me understand how forwarding is done?
> SM> Gtk objects are sometimes confusing when it comes to newbie with
> SM> little background in Gtk/C
>
>  You need to read a GTK (GObject) tutorial to really understand this
I really need to get my head on this!
> but
> you actually can just copy the code in src/gtk/dataview.cpp after "define
> new GTK+ class wxGtkTreeModel" comment without even understanding it fully.
> Of course, it would still be better to understand it... Roughly speaking
> you just define a bunch of C functions and then assign pointers to them to
> the GTK C++ vtbl equivalent.
>  As for forwarding itself, it's pretty trivial, look at e.g.
> wxgtk_tree_model_get_value() implementation. It is called by GTK+ to get a
> value for the given cell and it in turn forwards to wxDataViewModel to get
> it and then returns it to GTK+.
>
>  You should do something similar here except much simpler because you can
> hard code a lot of things instead of having to forward them (e.g. you will
> have only one column and there will be no hierarchy for the items so your
> iterators would be just trivial indices) and you don't need to support any
> extra interfaces so you don't need any g_type_add_interface_static() calls.
>
Thanks. Let me give it a try again!
>  Regards,
> VZ
>
> --
> TT-Solutions: wxWidgets consultancy and technical support
>                http://www.tt-solutions.com/
>
>  application_pgp-signature_part
> < 1KViewDownload
Reply all
Reply to author
Forward
0 new messages