1{ 2 *************************************************************************** 3 * * 4 * This source is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This code is distributed in the hope that it will be useful, but * 10 * WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 12 * General Public License for more details. * 13 * * 14 * A copy of the GNU General Public License is available on the World * 15 * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * 16 * obtain it by writing to the Free Software Foundation, * 17 * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. * 18 * * 19 *************************************************************************** 20 21 Author: Mattias Gaertner 22 23 Abstract: 24 Defines TSizeComponentsDialog. 25} 26unit SizeCompsDlg; 27 28{$mode objfpc}{$H+} 29 30interface 31 32uses 33 Classes, SysUtils, LCLIntf, Forms, Controls, Buttons, ExtCtrls, StdCtrls, 34 ButtonPanel; 35 36type 37 { TSizeComponentsDialog } 38 TSizeComponentsDialog = class(TForm) 39 ButtonPanel1: TButtonPanel; 40 PosLabel: TLabel; 41 WidthRadioGroup: TRadioGroup; 42 HeightRadioGroup: TRadioGroup; 43 WidthEdit: TEdit; 44 HeightEdit: TEdit; 45 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 46 procedure HeightEditChange(Sender: TObject); 47 procedure WidthEditChange(Sender: TObject); 48 private 49 IsAutoChangeWidth, IsAutoChangeHeight: boolean; 50 SaveItemIndexWidth, NumberItemWidth: Integer; 51 SaveItemIndexHeight, NumberItemHeight: Integer; 52 public 53 constructor Create(AOwner: TComponent); override; 54 end; 55 56function ShowSizeComponentsDialog(out HorizSizingID, FixedWidth, 57 VertSizingID, FixedHeight: integer): TModalResult; 58 59implementation 60 61{$R *.lfm} 62 63uses 64 LazarusIDEStrConsts; 65 66function ShowSizeComponentsDialog(out HorizSizingID, FixedWidth, VertSizingID, 67 FixedHeight: integer): TModalResult; 68var 69 SizeComponentsDialog: TSizeComponentsDialog; 70begin 71 SizeComponentsDialog := TSizeComponentsDialog.Create(nil); 72 with SizeComponentsDialog do 73 begin 74 Result := ShowModal; 75 HorizSizingID := WidthRadioGroup.ItemIndex; 76 FixedWidth := StrToIntDef(WidthEdit.Text,0); 77 VertSizingID := HeightRadioGroup.ItemIndex; 78 FixedHeight := StrToIntDef(HeightEdit.Text,0); 79 Free; 80 end; 81end; 82 83{ TSizeComponentsDialog } 84 85procedure TSizeComponentsDialog.FormClose(Sender: TObject; 86 var CloseAction: TCloseAction); 87begin 88 CloseAction := caFree; 89end; 90 91procedure TSizeComponentsDialog.HeightEditChange(Sender: TObject); 92begin 93 if HeightEdit.Text = '' then 94 begin 95 HeightRadioGroup.ItemIndex := SaveItemIndexHeight; 96 IsAutoChangeHeight := false; 97 end 98 else if not IsAutoChangeHeight then 99 begin 100 SaveItemIndexHeight := HeightRadioGroup.ItemIndex; 101 HeightRadioGroup.ItemIndex := NumberItemHeight; 102 IsAutoChangeHeight := true; 103 end; 104end; 105 106procedure TSizeComponentsDialog.WidthEditChange(Sender: TObject); 107begin 108 if WidthEdit.Text = '' then 109 begin 110 WidthRadioGroup.ItemIndex := SaveItemIndexWidth; 111 IsAutoChangeWidth := false; 112 end 113 else if not IsAutoChangeWidth then 114 begin 115 SaveItemIndexWidth := WidthRadioGroup.ItemIndex; 116 WidthRadioGroup.ItemIndex := NumberItemWidth; 117 IsAutoChangeWidth := true; 118 end; 119end; 120 121constructor TSizeComponentsDialog.Create(AOwner: TComponent); 122begin 123 inherited Create(AOwner); 124 125 Caption:=fdmSizeWord; 126 127 with WidthRadioGroup do 128 begin 129 Caption:=dlgWidthPos; 130 with Items do 131 begin 132 BeginUpdate; 133 Add(lisNoChange); 134 Add(lisShrinkToSmal); 135 Add(lisGrowToLarges); 136 NumberItemWidth := Add(dlgWidthPos); 137 EndUpdate; 138 end; 139 ItemIndex:=0; 140 end; 141 142 with HeightRadioGroup do 143 begin 144 Caption:=DlgHeightPos; 145 with Items do 146 begin 147 BeginUpdate; 148 Add(lisNoChange); 149 Add(lisShrinkToSmal); 150 Add(lisGrowToLarges); 151 NumberItemHeight := Add(DlgHeightPos); 152 EndUpdate; 153 end; 154 ItemIndex:=0; 155 end; 156 157 WidthEdit.Text:=''; 158 HeightEdit.Text:=''; 159 160 IsAutoChangeWidth := false; 161 IsAutoChangeHeight := false; 162 SaveItemIndexWidth := WidthRadioGroup.ItemIndex; 163 SaveItemIndexHeight := HeightRadioGroup.ItemIndex; 164end; 165 166end. 167