SRL Archive - Extensions

Suggested Feature in Security Extension


mc_teo

2010-08-10 15:57:11

although the extension is fairly good, and come along way since its creation in the dark reccesses of navatwo's mind. but this little thing has bugged me for a while. if the path is bigger than about 30 characters it trails off the side of the form that pops up, and you cant actually see what you're allowing or denying.

my solution is just to make the form adjust its width if bigger that a certain size. i didnt change the position of the other objects on the form, but i could make it center them or whatever.

this is just the whole procedure within security.sex responsible for creating the form.


procedure LoadOptionDialog(const isURL: Boolean; const path: String);
var
i, w, h: Integer;
begin
{
Load the form.
}
OptionForm := TForm.Create(nil);
OptionForm.BringToFront;
OptionForm.Visible := False;
OptionForm.BORDERSTYLE := bsSingle;
OptionForm.BORDERICONS := [biSystemMenu];
// if the length of the string to be displayed is greater than the default width of the form
if ((Length(path) * 7) > 200) then
// then make it wide enough to fit the entire string
OptionForm.SetBounds({L} 100, {T} 100, {W} (Length(path) * 7), {H} 150)
else
// otherwise leave it as the usual
OptionForm.SetBounds({L} 100, {T} 100, {W} 200, {H} 150);
OptionForm.POSITION := poDesktopCenter;

Option_Lock_Image := TImage.Create(OptionForm);
Option_Lock_Image.Parent := OptionForm;
w := Icon_Lock.Width;
h := Icon_Lock.Height;
Icon_Lock.DrawToCanvas(0, 0, Option_Lock_Image.Canvas);
Option_Lock_Image.SetBounds({L} 140, {T} 10, w, h);
Option_Lock_Image.Visible:= True;

Option_Label_Title := TLabel.Create(OptionForm);
Option_Label_Title.Parent := OptionForm;
Option_Label_Title.setBounds({L} 10, {T} 20, {W} 130, {H} 50);
Option_Label_Title.FONT.Size := 20;
Option_Label_Title.Visible := True;
Option_Label_Title.WORDWRAP := True;

Option_Label_Path := TLabel.Create(OptionForm);
Option_Label_Path.Parent := OptionForm;
Option_Label_Path.Left := 10;
Option_Label_Path.Top := 65;
Option_Label_Path.Visible := True;
Option_Label_Path.FONT.Style := [fsBold];
Option_Label_Path.WORDWRAP := True;
Option_Label_Path.ShowHint := True;

Option_Button_Okay := TButton.Create(OptionForm);
Option_Button_Okay.Parent := OptionForm;
Option_Button_Okay.CAPTION := 'Okay';
Option_Button_Okay.Left := 115;
Option_Button_Okay.Top := 120;
Option_Button_Okay.Visible := True;
Option_Button_Okay.ONCLICK := @OptionCloseForm;

Option_Label_Default := TLabel.Create(OptionForm);
Option_Label_Default.Parent := OptionForm;
Option_Label_Default.Left := 10;
Option_Label_Default.Top := 125;
Option_Label_Default.Visible := True;

Option_Timer := TTimer.Create(OptionForm);
Option_Timer.INTERVAL := Settings_DEFAULT_TIMEOUT * 1000;
Option_Timer.ONTIMER := @OptionCloseForm;
Option_Timer.ENABLED := True;

Option_Timer_Label := TTimer.Create(OptionForm);
Option_Timer_Label.INTERVAL := 1000;
Option_Timer_Label.ONTIMER := @DefaultLabel;
Option_Timer_Label.ENABLED := True;
Option_Default_Time := GetSystemTime;
Option_Timer_Label.ONTIMER(Option_Timer_Label);

Option_ComboBox := TComboBox.Create(OptionForm);
Option_ComboBox.Parent := OptionForm;
Option_ComboBox.SetBounds({L} 10, {T} 90, {W} 180, {H} 30);
Option_ComboBox.ONCHANGE := @OptionResetTimer;
Option_ComboBox.CLEAR;

{
Use the passed parameters to change how the form looks depending on whether
its a URL or a File path.
}
if (isURL) then
begin
{ Form Caption }
OptionForm.CAPTION := 'Security - Fire Wall';
Option_Label_Title.CAPTION := 'Fire Wall';

{ Fill the combo box with options. }
for i := 0 to high(Option_URL_Options) do
Option_ComboBox.ITEMS.Add(Option_URL_Options[i]);

{ Default Option: }
Option_ComboBox.ITEMINDEX := Settings_DEFAULT_URL;

{ Show the path in question. }
Option_Label_Path.CAPTION := Path;
end else
begin
{ Form Captions. }
OptionForm.CAPTION := 'Security - File Wall';
Option_Label_Title.CAPTION := 'File Wall';

{ Fill the combo box with options. }
for i := 0 to high(Option_File_Options) do
Option_ComboBox.ITEMS.Add(Option_File_Options[i]);

{ Default Option: }
Option_ComboBox.ITEMINDEX := Settings_DEFAULT_FILE;

{ Show the path in question. }
Option_Label_Path.CAPTION := substitutePaths(Path);
end;

{ Display the full path as a hint. }
Option_Label_Path.Hint := Path;

OptionForm.ShowModal;
end;

the font is not monospaced (i.e. m takes up more room that i) so the length can vary for longer strings. Here I'm just using 7 pixels as an average width of the characters. to make it perfect either change to a monospaced font, or calculate the actuall width of the string (so a string of m's will be longer than a string of i's) and some padding on the end.

i thought the latter would be slow if called regularly, so i didnt bother making it here, but i could if you wish.

so how does it look?

~mc_teo

Widget

2010-08-10 18:44:51

TCanvases have a function called GetWidth that lets you figure out how wide a string will be when rendered.

mc_teo

2010-09-12 16:18:05

but PascalScripts TCanvases dont have that

Nava2

2010-09-12 16:27:48

I thought I set it up to do kind of an elipses of sorts, and if you hover over the label will show up saying what it is.