Skip to content

Commit 8764a18

Browse files
committed
feat: colorize password strength bar in change password dialog (PBM_SETSTATE on Windows, Color elsewhere)
1 parent f694ce8 commit 8764a18

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

‎source/change_password.pas‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface
77
uses
88
SysUtils, Variants, Classes, Graphics,
99
Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
10-
Menus, Clipbrd, ComCtrls, extra_controls, Buttons;
10+
Menus, Clipbrd, ComCtrls, extra_controls, Buttons, LCLIntf;
1111

1212
type
1313
TfrmPasswordChange = class(TExtForm)
@@ -42,6 +42,7 @@ TfrmPasswordChange = class(TExtForm)
4242
private
4343
{ Private-Deklarationen }
4444
procedure CheckPasswordStrength;
45+
procedure SetStrengthColor(State: TProgressBarState);
4546
public
4647
{ Public-Deklarationen }
4748
end;
@@ -164,11 +165,35 @@ procedure TfrmPasswordChange.CheckPasswordStrength;
164165
end;
165166
Inc(Distance, Length(p)*10);
166167
progressbarPasswordStrength.Position := Round(progressbarPasswordStrength.Max / 500 * Distance);
167-
{case progressbarPasswordStrength.Position of
168-
0..20: progressbarPasswordStrength.State := pbsError;
169-
21..50: progressbarPasswordStrength.State := pbsPaused;
170-
51..100: progressbarPasswordStrength.State := pbsNormal;
171-
end;}
168+
// Colorize by strength. The LCL TProgressBar has no State property (unlike VCL's
169+
// pbsError/pbsPaused/pbsNormal used in trunk), so use our helper.
170+
case progressbarPasswordStrength.Position of
171+
0..20: SetStrengthColor(pbsError);
172+
21..50: SetStrengthColor(pbsPaused);
173+
51..100: SetStrengthColor(pbsNormal);
174+
end;
175+
end;
176+
177+
178+
procedure TfrmPasswordChange.SetStrengthColor(State: TProgressBarState);
179+
{$IFDEF WINDOWS}
180+
const
181+
// Win32 common control message (Vista+), paints the bar itself green/yellow/red
182+
PBM_SETSTATE = $0400 + 16; // WM_USER + 16
183+
PBST: array[TProgressBarState] of PtrUInt = (1, 2, 3); // PBST_NORMAL, PBST_ERROR, PBST_PAUSED
184+
{$ENDIF}
185+
begin
186+
{$IFDEF WINDOWS}
187+
// The native win32 progress bar ignores TProgressBar.Color for the bar itself,
188+
// so send PBM_SETSTATE like VCL's State property does.
189+
LCLIntf.SendMessage(progressbarPasswordStrength.Handle, PBM_SETSTATE, PBST[State], 0);
190+
{$ENDIF}
191+
// Fallback for other widgetsets: set the control's background color.
192+
case State of
193+
pbsError: progressbarPasswordStrength.Color := clRed;
194+
pbsPaused: progressbarPasswordStrength.Color := clYellow;
195+
pbsNormal: progressbarPasswordStrength.Color := clGreen;
196+
end;
172197
end;
173198

174199

0 commit comments

Comments
 (0)