home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / delphi / kolekce / d6 / rxlibsetup.exe / {app} / units / MINMAXED.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-02-19  |  6.3 KB  |  210 lines

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