[SOLVED] wxTextCtrl - is it possible to insert gaps in order to see text tokens?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

[SOLVED] wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

Hi All,
What I am trying to achieve with my wxTextCtrl is to insert (automatically if possible) a gap/space every 5 characters and at the same time by having the 5 characters tokens being masked by the wxTE_PASSWORD style.
I've tried to add the wxTE_PASSWORD style during the control construction but it only let the text being masked.
I did implement the character filtering by hand but I could not obtain a space separator being not masked by the wxTE_PASSWORD style flag.
What I am trying to obtain is something like the image attached.
Thank you in advance.
Image
Last edited by Astro2000 on Thu Sep 28, 2017 8:46 pm, edited 1 time in total.
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

Forgot the image:
validator.png
You do not have the required permissions to view the files attached to this post.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7481
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by ONEEYEMAN »

Hi,
There is no image attached, sorry. ;-)
Moreover, wxTE_PASSWORD style is applied to the whole control. You will not be able to apply it to part of the text.

Please attach the screenshot, so that we know what you are trying to accomplish.
Also:

1. What version of the library do you use?
2. What OS?/version?
3. What toolkit (if applicable)?

Thank you.
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

vvv.png
Hope the image will work now.
lib version is 3.0.3
os: windows 10
You do not have the required permissions to view the files attached to this post.
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

lib version: 3.0.3
os: win32
Thanks
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7481
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by ONEEYEMAN »

OK.
So let me re-phrase:

User will type "abcdefghijklmnop" and hit Enter (or Tab).
Your program will get this text and convert it to be "abcde fghij klmno p".

Did I understood correctly?

If I did - you probably need to catch EVT_FOCUS_LOST event, grab the content of the control, parse it inserting spaces as appropriate and set the value back.

If you want the "*" to appear while the user types the text you catch EVT_TEXT event and convert the current symbol typed replacing it to be "*".

Thank you.
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

Yep this is the case :) btw I understand that I can change the symbol displayed without altering the real character stored in the model.
Could you please give me some snippet to do that? Thanks.
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by doublemax »

If this for something like entering a registration code or similar, i would use separate wxTextCtrls.
Use the source, Luke!
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

Yep this is the case but I can not as I need to meet the requirements. thanks
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by eranon »

You can also:
- Associate a validator derived from wxTextValidator (catch the wxEVT_CHAR or KEY_DOWN event (not sure about the best one) and eventually override the Validate method) to your text control.
- Or maybe this class (wxMaskedEdit) that provide mask on edit ctrl may match your need: viewtopic.php?t=6262
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Manolo »

eranon: that wxMaskedEdit version had a lot of issues (sea https://groups.google.com/forum/#!searc ... U5AhEll2AJ)

I did a working class (see https://trac.wxwidgets.org/ticket/14535) which VZ decided to abandon (too big for his little time).
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by eranon »

Manolo wrote:eranon: that wxMaskedEdit version had a lot of issues (sea https://groups.google.com/forum/#!searc ... U5AhEll2AJ)
OK, I never used it, just found the existence of a wxPython flavor in a first pass (https://docs.wxpython.org/wx.lib.masked ... maskededit), then quickly checked a C++ sister was discussed somewhere...
Manolo wrote:I did a working class (see https://trac.wxwidgets.org/ticket/14535) which VZ decided to abandon (too big for his little time).
Nice! So, a premade way for the OP :)
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

Thank you guys :) I have some stuff to implement today so I will try...yep...I ve read about the masked control but as you have noted it is still incomplete.
I will post my results after.
Astro2000
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 21, 2017 11:59 am

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by Astro2000 »

I forgot...do you know which the ASCII code is for the character that is used for the wxTE_PASSWORD style?
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France

Re: wxTextCtrl - is it possible to insert gaps in order to see text tokens?

Post by eranon »

I would say asterisk, Astro2000: https://en.wikipedia.org/wiki/Asterisk. About wxMaskedEdit, remember there're two ones: the aborted incomplete one and the Manolo's working one (following the links in this report, you can reach it as patch and as source in Git repository: https://trac.wxwidgets.org/ticket/14535).
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]