[456] | 1 | unit fAutoSz;
|
---|
| 2 | { provides the basic mechanism to resize all the controls on a form when the form size is
|
---|
| 3 | changed. Differs from frmAResize in that this one descends directly from TForm, rather
|
---|
| 4 | than TPage }
|
---|
| 5 |
|
---|
| 6 | interface
|
---|
| 7 |
|
---|
| 8 | uses
|
---|
[830] | 9 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, fBase508Form,
|
---|
| 10 | VA508AccessibilityManager;
|
---|
[456] | 11 |
|
---|
| 12 | type
|
---|
[830] | 13 | TfrmAutoSz = class(TfrmBase508Form)
|
---|
[456] | 14 | procedure FormResize(Sender: TObject);
|
---|
| 15 | procedure FormDestroy(Sender: TObject);
|
---|
| 16 | private
|
---|
| 17 | FSizes: TList;
|
---|
| 18 | FAutoSizeDisabled: Boolean;
|
---|
| 19 | protected
|
---|
[830] | 20 | procedure Loaded; override;
|
---|
[456] | 21 | property AutoSizeDisabled: Boolean read FAutoSizeDisabled write FAutoSizeDisabled;
|
---|
| 22 | public
|
---|
| 23 | end;
|
---|
| 24 |
|
---|
| 25 | var
|
---|
| 26 | frmAutoSz: TfrmAutoSz;
|
---|
| 27 |
|
---|
| 28 | implementation
|
---|
| 29 |
|
---|
| 30 | {$R *.DFM}
|
---|
| 31 |
|
---|
| 32 | uses
|
---|
[830] | 33 | ORfn, VA508AccessibilityRouter;
|
---|
[456] | 34 | type
|
---|
| 35 | TSizeRatio = class // records relative sizes and positions for resizing logic
|
---|
| 36 | FControl: TControl;
|
---|
| 37 | FLeft: Extended;
|
---|
| 38 | FTop: Extended;
|
---|
| 39 | FWidth: Extended;
|
---|
| 40 | FHeight: Extended;
|
---|
| 41 | constructor Create(AControl: TControl; W, H: Integer);
|
---|
| 42 | end;
|
---|
| 43 |
|
---|
| 44 | { TSizeRatio methods }
|
---|
| 45 |
|
---|
| 46 | constructor TSizeRatio.Create(AControl: TControl; W, H: Integer);
|
---|
| 47 | begin
|
---|
| 48 | FControl := AControl;
|
---|
| 49 | with AControl do
|
---|
| 50 | begin
|
---|
| 51 | FLeft := Left / W;
|
---|
| 52 | FTop := Top / H;
|
---|
| 53 | FWidth := Width / W;
|
---|
| 54 | FHeight := Height / H;
|
---|
| 55 | end;
|
---|
| 56 | end;
|
---|
| 57 |
|
---|
| 58 | { TfrmAutoSz methods }
|
---|
| 59 |
|
---|
| 60 | procedure TfrmAutoSz.Loaded;
|
---|
| 61 | { record initial size & position info for resizing logic }
|
---|
| 62 | var
|
---|
| 63 | SizeRatio: TSizeRatio;
|
---|
| 64 | i,W,H: Integer;
|
---|
| 65 | Control: TControl;
|
---|
| 66 | begin
|
---|
| 67 | inherited Loaded;
|
---|
| 68 | FSizes := TList.Create;
|
---|
| 69 | if AutoSizeDisabled then Exit;
|
---|
| 70 | W := ClientWidth;
|
---|
| 71 | H := ClientHeight;
|
---|
| 72 | for i := 0 to ComponentCount - 1 do if Components[i] is TControl then
|
---|
| 73 | begin
|
---|
| 74 | Control := TControl(Components[i]);
|
---|
| 75 | W := HigherOf(W, Control.Left + Control.Width);
|
---|
| 76 | H := HigherOf(H, Control.Top + Control.Height);
|
---|
| 77 | end;
|
---|
| 78 | ClientHeight := H;
|
---|
| 79 | ClientWidth := W;
|
---|
| 80 | for i := 0 to ComponentCount - 1 do if Components[i] is TControl then
|
---|
| 81 | begin
|
---|
| 82 | SizeRatio := TSizeRatio.Create(TControl(Components[i]), W, H);
|
---|
| 83 | FSizes.Add(SizeRatio);
|
---|
| 84 | end;
|
---|
| 85 | end;
|
---|
| 86 |
|
---|
| 87 | procedure TfrmAutoSz.FormResize(Sender: TObject);
|
---|
| 88 | { resize child controls using their design time proportions }
|
---|
| 89 | var
|
---|
| 90 | SizeRatio: TSizeRatio;
|
---|
| 91 | i, W, H: Integer;
|
---|
| 92 | begin
|
---|
| 93 | inherited;
|
---|
| 94 | if AutoSizeDisabled then Exit;
|
---|
| 95 | W := HigherOf(ClientWidth, HorzScrollBar.Range);
|
---|
| 96 | H := HigherOf(ClientHeight, VertScrollBar.Range);
|
---|
| 97 | with FSizes do for i := 0 to Count - 1 do
|
---|
| 98 | begin
|
---|
| 99 | SizeRatio := Items[i];
|
---|
| 100 | with SizeRatio do
|
---|
| 101 | if ((FControl is TLabel) and TLabel(FControl).AutoSize) or ((FControl is TStaticText) and TStaticText(FControl).AutoSize) then
|
---|
| 102 | begin
|
---|
| 103 | FControl.Left := Round(FLeft*W);
|
---|
| 104 | FControl.Top := Round(FTop*H);
|
---|
| 105 | end
|
---|
| 106 | else FControl.SetBounds(Round(FLeft*W), Round(FTop*H), Round(FWidth*W), Round(FHeight*H));
|
---|
| 107 | end; {with FSizes}
|
---|
| 108 | end;
|
---|
| 109 |
|
---|
| 110 | procedure TfrmAutoSz.FormDestroy(Sender: TObject);
|
---|
| 111 | { destroy objects used to record size and position information for controls }
|
---|
| 112 | var
|
---|
| 113 | SizeRatio: TSizeRatio;
|
---|
| 114 | i: Integer;
|
---|
| 115 | begin
|
---|
| 116 | inherited;
|
---|
| 117 | if FSizes <> nil then with FSizes do for i := 0 to Count-1 do
|
---|
| 118 | begin
|
---|
| 119 | SizeRatio := Items[i];
|
---|
| 120 | SizeRatio.Free;
|
---|
| 121 | end;
|
---|
| 122 | FSizes.Free;
|
---|
| 123 | end;
|
---|
| 124 |
|
---|
[830] | 125 | initialization
|
---|
| 126 | SpecifyFormIsNotADialog(TfrmAutoSz);
|
---|
| 127 |
|
---|
| 128 |
|
---|
[456] | 129 | end.
|
---|