Page 1 of 1

wxTextCtrl password entry with show&hide password option

Posted: Fri Mar 09, 2018 12:27 am
by specing
Is there any shortcut or should we create two wxTextCtrls, one with wxTE_PASSWORD, one without and switch between them when the show/hide password toggle is activated?

Documentation says wxTE_PASSWORD style can only be dynamically changed with wxGTK back-end.

Re: wxTextCtrl password entry with show&hide password option

Posted: Fri Mar 09, 2018 11:17 am
by doublemax
I can't think of an easier way.

The alternative would be to catch all key presses, store the characters only internally and then replace it with an * for the actual visible content. But it would become quite complicated with handling cursor movement, selection, backspace, delete etc.

Re: wxTextCtrl password entry with show&hide password option

Posted: Fri Mar 09, 2018 11:20 pm
by specing
I see. I will try abstracting this thing away.

Re: wxTextCtrl password entry with show&hide password option

Posted: Sat Mar 10, 2018 7:05 am
by catalin
It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.

Re: wxTextCtrl password entry with show&hide password option

Posted: Sat Mar 10, 2018 5:41 pm
by xaviou
Hi
catalin wrote:It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.
If you need an example, just have a look at this : this is exactly what I am doing.

Regards

Re: wxTextCtrl password entry with show&hide password option

Posted: Sat Mar 10, 2018 9:26 pm
by specing
xaviou wrote:....this ...
Under which license can we look at your work?

Re: wxTextCtrl password entry with show&hide password option

Posted: Sat Mar 10, 2018 9:34 pm
by specing
catalin wrote:It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.
I don't know how to ensure that they'd have the same position in the sizer. But I could put two of them in and Show()/Hide() them when needed.

Re: wxTextCtrl password entry with show&hide password option

Posted: Sat Mar 10, 2018 10:25 pm
by xaviou
specing wrote:Under which license can we look at your work?
There is no particular license : you can do what you want with it.

It's here to help...
specing wrote:
catalin wrote:It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.
I don't know how to ensure that they'd have the same position in the sizer. But I could put two of them in and Show()/Hide() them when needed.
It can also work : just don't forget to call "layout" on the containing sizer after the "show/hide" ones

Regards
Xav'

Re: wxTextCtrl password entry with show&hide password option

Posted: Sun Mar 11, 2018 1:42 pm
by specing
xaviou wrote:There is no particular license : you can do what you want with it.
I'm pretty sure "no license" means all rights reserved under current copyright systems. If you want to dedicate those samples to the public domain, then explicitly pick such a license, e.g. Creative Commons Zero and follow their licensing practice (e.g. /LICENSE file and proper text in all headers). I'm also sure that using some person's "you can do what you want with it." quote on some forum where anyone can register with whatever name and claim they are the author of that software will not fly in a courtroom.

Re: wxTextCtrl password entry with show&hide password option

Posted: Thu Mar 21, 2019 7:36 pm
by Widgets
FWIW, I find that Xaviou's solution may work only if the password text control is the only or last control in a sizer, and even with moving it to the last box, I had no luck with in wxGridSizer.
The problem seems to be that, while a sizer has functions to add a control at a given index, I have not found a way to check at which index the current control was placed to that I could try to 'insert' it at the desired 'index', rather than append it with pSzr->add which says it will append the recreated text control
As it is adding the control seems to place it at some arbitrary point within the grid sizer - at least I can see no logic, because it does not even become the last control in the sizer :(
Even getting both size & position of the old window and using it when creating the new one does not make a difference.
It does seem that, for Windows at least, there is an alternative - will check it out.
viewtopic.php?t=15093

Re: wxTextCtrl password entry with show&hide password option

Posted: Thu Mar 21, 2019 7:56 pm
by catalin
Widgets wrote: Thu Mar 21, 2019 7:36 pm I have not found a way to check at which index the current control was placed to that I could try to 'insert' it at the desired 'index'
FWIW you should be able to achieve this without needing the index, by storing the wxSizerItem* returned by wxSizer::Add(...) and using its AssignWindow() when appropriate.

Re: wxTextCtrl password entry with show&hide password option

Posted: Thu Mar 21, 2019 8:56 pm
by Widgets
the 'solution' may well be 'obvious' to you, but it is not to me and the example may well work under some (unspecified) conditions, but not under mine :?