Skip to content

Commit

Permalink
Bugfix: Incorrect display of CAPS LOCK warning tooltip
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
Rookiestyle committed May 17, 2022
1 parent b41e56e commit 2518ef1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 54 deletions.
86 changes: 35 additions & 51 deletions src/ColoredSecureTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,20 @@ private void M_text_ParentChanged(object sender, EventArgs e)
m_form = FindForm() as KeePass.Forms.KeyPromptForm;
if (m_form == null) m_form = FindForm() as KeePass.Forms.KeyCreationForm;
if (m_form != null) m_form.Shown += CorrectFocus;
}
}

private void CorrectFocus(object sender, EventArgs e)
{
ulong uUIFlags = 0;
if (m_form is KeePass.Forms.KeyPromptForm)
uUIFlags = KeePass.Program.Config.UI.KeyPromptFlags;
else if (m_form is KeePass.Forms.KeyCreationForm)
uUIFlags = KeePass.Program.Config.UI.KeyCreationFlags;
else return;

if ((uUIFlags & (ulong)KeePass.App.Configuration.AceKeyUIFlags.UncheckHidePassword) == 0) return;
{
if (!Enabled) return;
if (m_form == null) return;

if (Enabled) UIUtil.ResetFocus(this, m_form, true);
}
UIUtil.ResetFocus(this, m_form);
if (Name.Contains("Repeat"))
{
var c = Tools.GetControl(Name.Replace("Repeat", string.Empty), m_form);
if (c != null) UIUtil.ResetFocus(c, m_form, true);
}
}

private void ColoredSecureTextBox_SizeChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -179,29 +178,25 @@ protected override void OnParentChanged(EventArgs e)
Parent.PerformLayout();
}

//KeeTheme usage of DwmSetWindowAttribute in combination with toggline the form's borderstyle
//results in the CAPS LOCK warning tooltip to be shown forever
//
//This happens if
// - password is shown unprotected right away in the key promp / key creation form
// - and KeeTheme is installed
// - and KeeTheme is enabled
//Don't show ColorTextBox if
// - m_form is set (KeyPromptForm or KeyCreationForm)
// AND
// - form.Shown event has not been raised yet
//
//To bypasss this, we perform
private bool m_bKeeThemeW10Delay = true;
private bool? m_bDoEnable = null;
//This can result in a wrong CAPS LOCK warning tooltip - cf. https://github.com/Rookiestyle/ColoredPassword/issues/15
private bool m_bKeyFormShown = false;
private bool? m_bRememberedProtectionState = null;
public override void EnableProtection(bool bEnable)
{
PluginDebug.AddInfo(Name + " Protect password display: " + bEnable.ToString());
if (KeeThemeDelayRequired())
{
HandleKeeThemeDelay(bEnable);
base.EnableProtection(bEnable);
return;
}
m_text.TextChanged -= ColorTextChanged;
base.EnableProtection(bEnable);
m_text.Name = Name + "_RTB";
base.EnableProtection(bEnable);
if (WaitForFormShown())
{
RememberProtectionState(bEnable);
return;
}
if (bEnable)
{
Visible = true;
Expand Down Expand Up @@ -255,36 +250,25 @@ public override void EnableProtection(bool bEnable)
}
}

private void HandleKeeThemeDelay(bool bEnable)
private void RememberProtectionState(bool bEnable)
{
if (!m_bDoEnable.HasValue)
//Subscribe to event 'Shown' only once
if (!m_bRememberedProtectionState.HasValue)
{
m_form.Shown += (o, e) =>
{
m_bKeeThemeW10Delay = false;
EnableProtection(m_bDoEnable.HasValue ? m_bDoEnable.Value : true);
m_bKeyFormShown = true;
EnableProtection(m_bRememberedProtectionState.Value);
CorrectFocus(null, null);
};
}
m_bDoEnable = bEnable;
m_bRememberedProtectionState = bEnable;
}

private bool KeeThemeDelayRequired()
private bool WaitForFormShown()
{
if (!m_bKeeThemeW10Delay) return false;
if (!m_bKeeTheme) return false;

ulong uUIFlags = 0;
if (m_form is KeePass.Forms.KeyPromptForm)
uUIFlags = KeePass.Program.Config.UI.KeyPromptFlags;
else if (m_form is KeePass.Forms.KeyCreationForm)
uUIFlags = KeePass.Program.Config.UI.KeyCreationFlags;
else return false;

//password not shown in plaintext
if ((uUIFlags & (ulong)KeePass.App.Configuration.AceKeyUIFlags.UncheckHidePassword) == 0) return false;

//we COULD check whether KeeTheme is active
//we ARE lazy and don't do that
if (m_bKeyFormShown) return false;
if (m_form == null) return false;
return true;
}

Expand Down Expand Up @@ -430,4 +414,4 @@ public void ColorText()
Select(nCursorPos, 0); //restore cursor position
}
}
}
}
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.14")]
[assembly: AssemblyFileVersion("0.14")]
[assembly: AssemblyVersion("0.14.1")]
[assembly: AssemblyFileVersion("0.14.1")]
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:
ColoredPassword:0.14
ColoredPassword:0.14.1
ColoredPassword!de:6
ColoredPassword!pl:2
ColoredPassword!pt:2
Expand Down

0 comments on commit 2518ef1

Please sign in to comment.