home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d6 / RX275D6.ZIP / Units / MINMAXED.PAS < prev    next >
Pascal/Delphi Source File  |  2001-06-24  |  6KB  |  209 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 1997 Master-Bank                }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit MinMaxEd;
  10.  
  11. interface
  12.  
  13. {$I RX.INC}
  14.  
  15. uses SysUtils, {$IFDEF WIN32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  16.   Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
  17.   Buttons, Mask, CurrEdit, VclUtils, Placemnt, RTLConsts, DesignIntf, DesignEditors, VCLEditors, Consts;
  18.  
  19. type
  20.   TMinMaxInfoEditDialog = class(TForm)
  21.     Bevel1: TBevel;
  22.     Label1: TLabel;
  23.     Label2: TLabel;
  24.     Label3: TLabel;
  25.     Label4: TLabel;
  26.     Label5: TLabel;
  27.     Label6: TLabel;
  28.     Label7: TLabel;
  29.     Label8: TLabel;
  30.     Label9: TLabel;
  31.     Label10: TLabel;
  32.     Label11: TLabel;
  33.     Label12: TLabel;
  34.     OkBtn: TButton;
  35.     CancelBtn: TButton;
  36.     MaxPosBtn: TSpeedButton;
  37.     MaxSizeBtn: TSpeedButton;
  38.     MaxTrackBtn: TSpeedButton;
  39.     MinTrackBtn: TSpeedButton;
  40.     MaxPosLeftEdit: TCurrencyEdit;
  41.     MaxPosTopEdit: TCurrencyEdit;
  42.     MaxSizeWidthEdit: TCurrencyEdit;
  43.     MaxSizeHeightEdit: TCurrencyEdit;
  44.     MaxTrackWidthEdit: TCurrencyEdit;
  45.     MaxTrackHeightEdit: TCurrencyEdit;
  46.     MinTrackWidthEdit: TCurrencyEdit;
  47.     MinTrackHeightEdit: TCurrencyEdit;
  48.     ClearBtn: TButton;
  49.     procedure FormCreate(Sender: TObject);
  50.     procedure FormDestroy(Sender: TObject);
  51.     procedure SetCurrentBtnClick(Sender: TObject);
  52.     procedure OkBtnClick(Sender: TObject);
  53.     procedure ClearBtnClick(Sender: TObject);
  54.   private
  55.     { Private declarations }
  56.     FWinMinMaxInfo: TWinMinMaxInfo;
  57.     FForm: TCustomForm;
  58.     procedure SetWinMinMaxInfo(Value: TWinMinMaxInfo);
  59.     procedure UpdateMinMaxInfo;
  60.   public
  61.     { Public declarations }
  62.     property WinMinMaxInfo: TWinMinMaxInfo read FWinMinMaxInfo write SetWinMinMaxInfo;
  63.   end;
  64.  
  65. { TMinMaxProperty }
  66.  
  67.   TMinMaxProperty = class(TClassProperty)
  68.   public
  69.     function GetAttributes: TPropertyAttributes; override;
  70.     function GetValue: string; override;
  71.     procedure Edit; override;
  72.   end;
  73.  
  74. function EditMinMaxInfo(AComponent: TFormPlacement): Boolean;
  75.  
  76. implementation
  77.  
  78. {$R *.DFM}
  79.  
  80. {$IFDEF WIN32}
  81.  {$D-}
  82. {$ENDIF}
  83.  
  84. function EditMinMaxInfo(AComponent: TFormPlacement): Boolean;
  85. begin
  86.   Result := False;
  87.   if AComponent = nil then Exit;
  88.   with TMinMaxInfoEditDialog.Create(Application) do
  89.   try
  90.     WinMinMaxInfo := AComponent.MinMaxInfo;
  91.     if AComponent.Owner is TCustomForm then
  92.       FForm := TCustomForm(AComponent.Owner);
  93.     if AComponent.Name <> '' then
  94.       Caption := Format('%s.MinMaxInfo', [AComponent.Name]);
  95.     Result := ShowModal = mrOk;
  96.     if Result then AComponent.MinMaxInfo := WinMinMaxInfo;
  97.   finally
  98.     Free;
  99.   end;
  100. end;
  101.  
  102. { TMinMaxProperty }
  103.  
  104. function TMinMaxProperty.GetValue: string;
  105. var
  106.   WinMinMaxInfo: TWinMinMaxInfo;
  107. begin
  108.   WinMinMaxInfo := TWinMinMaxInfo(GetOrdValue);
  109.   with WinMinMaxInfo do begin
  110.     if DefaultMinMaxInfo then Result := ResStr(srNone)
  111.     else Result := Format('(%d,%d),(%d,%d),(%d,%d),(%d,%d)',
  112.       [MaxPosLeft, MaxPosTop, MaxSizeWidth, MaxSizeHeight,
  113.       MaxTrackWidth, MaxTrackHeight, MinTrackWidth, MinTrackHeight]);
  114.   end;
  115. end;
  116.  
  117. function TMinMaxProperty.GetAttributes: TPropertyAttributes;
  118. begin
  119.   Result := [paSubProperties, paDialog, paReadOnly];
  120. end;
  121.  
  122. procedure TMinMaxProperty.Edit;
  123. begin
  124.   if EditMinMaxInfo(GetComponent(0) as TFormPlacement) then Modified;
  125. end;
  126.  
  127. { TMinMaxInfoEditDialog }
  128.  
  129. procedure TMinMaxInfoEditDialog.SetWinMinMaxInfo(Value: TWinMinMaxInfo);
  130. begin
  131.   FWinMinMaxInfo.Assign(Value);
  132.   with FWinMinMaxInfo do begin
  133.     MaxPosLeftEdit.AsInteger := MaxPosLeft;
  134.     MaxPosTopEdit.AsInteger := MaxPosTop;
  135.     MaxSizeWidthEdit.AsInteger := MaxSizeWidth;
  136.     MaxSizeHeightEdit.AsInteger := MaxSizeHeight;
  137.     MaxTrackWidthEdit.AsInteger := MaxTrackWidth;
  138.     MaxTrackHeightEdit.AsInteger := MaxTrackHeight;
  139.     MinTrackWidthEdit.AsInteger := MinTrackWidth;
  140.     MinTrackHeightEdit.AsInteger := MinTrackHeight;
  141.   end;
  142. end;
  143.  
  144. procedure TMinMaxInfoEditDialog.UpdateMinMaxInfo;
  145. begin
  146.   with FWinMinMaxInfo do begin
  147.     MaxPosLeft := MaxPosLeftEdit.AsInteger;
  148.     MaxPosTop := MaxPosTopEdit.AsInteger;
  149.     MaxSizeWidth := MaxSizeWidthEdit.AsInteger;
  150.     MaxSizeHeight := MaxSizeHeightEdit.AsInteger;
  151.     MaxTrackWidth := MaxTrackWidthEdit.AsInteger;
  152.     MaxTrackHeight := MaxTrackHeightEdit.AsInteger;
  153.     MinTrackWidth := MinTrackWidthEdit.AsInteger;
  154.     MinTrackHeight := MinTrackHeightEdit.AsInteger;
  155.   end;
  156. end;
  157.  
  158. procedure TMinMaxInfoEditDialog.FormCreate(Sender: TObject);
  159. begin
  160.   FWinMinMaxInfo := TWinMinMaxInfo.Create;
  161. end;
  162.  
  163. procedure TMinMaxInfoEditDialog.FormDestroy(Sender: TObject);
  164. begin
  165.   FWinMinMaxInfo.Free;
  166. end;
  167.  
  168. procedure TMinMaxInfoEditDialog.SetCurrentBtnClick(Sender: TObject);
  169. begin
  170.   if FForm <> nil then
  171.     case TComponent(Sender).Tag of
  172.       1: begin
  173.            MaxPosLeftEdit.AsInteger := TForm(FForm).Left;
  174.            MaxPosTopEdit.AsInteger := TForm(FForm).Top;
  175.          end;
  176.       2: begin
  177.            MaxSizeWidthEdit.AsInteger := TForm(FForm).Width;
  178.            MaxSizeHeightEdit.AsInteger := TForm(FForm).Height;
  179.          end;
  180.       3: begin
  181.            MaxTrackWidthEdit.AsInteger := TForm(FForm).Width;
  182.            MaxTrackHeightEdit.AsInteger := TForm(FForm).Height;
  183.          end;
  184.       4: begin
  185.            MinTrackWidthEdit.AsInteger := TForm(FForm).Width;
  186.            MinTrackHeightEdit.AsInteger := TForm(FForm).Height;
  187.          end;
  188.       else Exit;
  189.     end;
  190. end;
  191.  
  192. procedure TMinMaxInfoEditDialog.OkBtnClick(Sender: TObject);
  193. begin
  194.   UpdateMinMaxInfo;
  195. end;
  196.  
  197. procedure TMinMaxInfoEditDialog.ClearBtnClick(Sender: TObject);
  198. begin
  199.   MaxPosLeftEdit.AsInteger := 0;
  200.   MaxPosTopEdit.AsInteger := 0;
  201.   MaxSizeWidthEdit.AsInteger := 0;
  202.   MaxSizeHeightEdit.AsInteger := 0;
  203.   MaxTrackWidthEdit.AsInteger := 0;
  204.   MaxTrackHeightEdit.AsInteger := 0;
  205.   MinTrackWidthEdit.AsInteger := 0;
  206.   MinTrackHeightEdit.AsInteger := 0;
  207. end;
  208.  
  209. end.