home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / delphi / kolekce / d6 / rxlibsetup.exe / {app} / units / gradedit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-02-19  |  11.9 KB  |  428 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. {         Copyright (c) 1998 Ritting Information Systems}
  9. {                                                       }
  10. {*******************************************************}
  11.  
  12. unit GradEdit;
  13.  
  14. {$I RX.INC}
  15.  
  16. interface
  17.  
  18. uses
  19.   Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  20.   StdCtrls, Mask, ToolEdit, RxGrdCpt, RTLConsts, DesignIntf, DesignEditors, VCLEditors, RXCtrls, Placemnt;
  21.  
  22. {$IFNDEF RX_D4}
  23. type
  24.   IDesigner = TDesigner;
  25. {$ENDIF}
  26.  
  27. type
  28.   TGradCaptionsEditor = class(TForm)
  29.     ApplyButton: TButton;
  30.     CancelButton: TButton;
  31.     OkButton: TButton;
  32.     GroupBox2: TGroupBox;
  33.     Label1: TLabel;
  34.     Label3: TLabel;
  35.     CaptionText: TEdit;
  36.     CaptionInactiveColor: TComboBox;
  37.     GroupBox1: TGroupBox;
  38.     CaptionList: TTextListBox;
  39.     NewButton: TButton;
  40.     DeleteButton: TButton;
  41.     CaptionParentFont: TCheckBox;
  42.     CaptionGlueNext: TCheckBox;
  43.     CaptionVisible: TCheckBox;
  44.     Label2: TLabel;
  45.     CaptionFont: TComboEdit;
  46.     GradientCaption: TRxGradientCaption;
  47.     FontDialog: TFontDialog;
  48.     ColorDialog: TColorDialog;
  49.     FormStorage: TFormStorage;
  50.     procedure FormCreate(Sender: TObject);
  51.     procedure CaptionListClick(Sender: TObject);
  52.     procedure CaptionListDragDrop(Sender, Source: TObject; X, Y: Integer);
  53.     procedure CaptionListDragOver(Sender, Source: TObject; X, Y: Integer;
  54.       State: TDragState; var Accept: Boolean);
  55.     procedure NewButtonClick(Sender: TObject);
  56.     procedure DeleteButtonClick(Sender: TObject);
  57.     procedure OkButtonClick(Sender: TObject);
  58.     procedure ApplyButtonClick(Sender: TObject);
  59.     procedure CaptionInactiveColorDblClick(Sender: TObject);
  60.     procedure ControlExit(Sender: TObject);
  61.     procedure CaptionTextChange(Sender: TObject);
  62.     procedure CaptionFontButtonClick(Sender: TObject);
  63.     procedure CheckBoxClick(Sender: TObject);
  64.   private
  65.     { Private declarations }
  66.     FComponent: TRxGradientCaption;
  67.     FDesigner: IDesigner;
  68.     FUpdating: Boolean;
  69.     procedure AddColorItem(const ColorName: string);
  70.     procedure EnableControls(Enable: Boolean);
  71.     procedure UpdateCaptionList(Index: Integer);
  72.     procedure ReadControls;
  73.     procedure UpdateControls;
  74.     procedure ClearControls;
  75.     function GetActiveCaption: TRxCaption;
  76.     procedure ApplyChanges;
  77.   public
  78.     { Public declarations }
  79.     procedure SetGradientCaption(Component: TRxGradientCaption;
  80.       Designer: IDesigner);
  81.     property ActiveCaption: TRxCaption read GetActiveCaption;
  82.   end;
  83.  
  84. { TGradientCaptionEditor }
  85.  
  86.   TGradientCaptionEditor = class(TComponentEditor)
  87.     procedure Edit; override;
  88.     procedure ExecuteVerb(Index: Integer); override;
  89.     function GetVerb(Index: Integer): string; override;
  90.     function GetVerbCount: Integer; override;
  91.   end;
  92.  
  93. {$IFNDEF RX_D3}
  94.  
  95. { TGradientCaptionsProperty }
  96.  
  97.   TGradientCaptionsProperty = class(TClassProperty)
  98.     function GetAttributes: TPropertyAttributes; override;
  99.     procedure Edit; override;
  100.   end;
  101.   
  102. {$ENDIF}
  103.  
  104. function EditGradientCaption(Component: TRxGradientCaption;
  105.   Designer: IDesigner): Boolean;
  106.  
  107. implementation
  108.  
  109. uses VCLUtils, BoxProcs, RxConst, RxLConst;
  110.  
  111. {$R *.DFM}
  112.  
  113. function EditGradientCaption(Component: TRxGradientCaption; Designer: IDesigner): Boolean;
  114.   var gce : TGradCaptionsEditor;
  115. begin
  116.   gce := TGradCaptionsEditor.Create(Application);
  117.   try
  118.     gce.SetGradientCaption(Component, Designer);
  119.     Result := gce.ShowModal = mrOk;
  120.   finally
  121.     gce.Free;
  122.   end;
  123. end;
  124.  
  125. { TGradientCaptionEditor }
  126.  
  127. procedure TGradientCaptionEditor.Edit;
  128. begin
  129.   EditGradientCaption(TRxGradientCaption(Component), Designer);
  130. end;
  131.  
  132. procedure TGradientCaptionEditor.ExecuteVerb(Index: Integer);
  133. begin
  134.   if Index = 0 then Edit;
  135. end;
  136.  
  137. function TGradientCaptionEditor.GetVerb(Index: Integer): string;
  138. begin
  139.   if Index = 0 then Result := LoadStr(srCaptionDesigner)
  140.   else Result := '';
  141. end;
  142.  
  143. function TGradientCaptionEditor.GetVerbCount: Integer;
  144. begin
  145.   Result := 1;
  146. end;
  147.  
  148. {$IFNDEF RX_D3}
  149.  
  150. { TGradientCaptionsProperty }
  151.  
  152. function TGradientCaptionsProperty.GetAttributes: TPropertyAttributes;
  153. begin
  154.   Result := [paDialog, paReadOnly];
  155. end;
  156.  
  157. procedure TGradientCaptionsProperty.Edit;
  158. begin
  159.   if EditGradientCaption(TRxGradientCaption(GetComponent(0)), Designer) then
  160.     Modified;
  161. end;
  162.  
  163. {$ENDIF RX_D3}
  164.  
  165. { TGradCaptionsEditor }
  166.  
  167. procedure TGradCaptionsEditor.UpdateCaptionList(Index: Integer);
  168. var
  169.   I, Save: Integer;
  170. begin
  171.   if Index >= 0 then Save := Index
  172.   else Save := CaptionList.ItemIndex;
  173.   CaptionList.Items.BeginUpdate;
  174.   try
  175.     CaptionList.Items.Clear;
  176.     for I := 0 to GradientCaption.Captions.Count - 1 do
  177.       CaptionList.Items.Add(Format('%s[%d]', [LoadStr(srGradientCaptions), I]));
  178.     if Save < 0 then Save := 0;
  179.     if Save >= CaptionList.Items.Count then
  180.       Save := CaptionList.Items.Count - 1;
  181.   finally
  182.     CaptionList.Items.EndUpdate;
  183.     CaptionList.ItemIndex := Save;
  184.   end;
  185. end;
  186.  
  187. function TGradCaptionsEditor.GetActiveCaption: TRxCaption;
  188. var
  189.   I: Integer;
  190. begin
  191.   Result := nil;
  192.   I := CaptionList.ItemIndex;
  193.   if (I >= 0) and (I < GradientCaption.Captions.Count) then
  194.     Result := GradientCaption.Captions[I];
  195. end;
  196.  
  197. procedure TGradCaptionsEditor.SetGradientCaption(Component: TRxGradientCaption;
  198.   Designer: IDesigner);
  199. begin
  200.   FComponent := Component;
  201.   FDesigner := Designer;
  202.   if Component <> nil then begin
  203.     with GradientCaption do begin
  204.       Active := False;
  205.       Font := Component.Font;
  206.       DefaultFont := Component.DefaultFont;
  207.       FontInactiveColor := Component.FontInactiveColor;
  208.       GradientActive := Component.GradientActive;
  209.       GradientInactive := Component.GradientInactive;
  210.       StartColor := Component.StartColor;
  211.       HideDirection := Component.HideDirection;
  212.       GradientSteps := Component.GradientSteps;
  213.       Captions := Component.Captions;
  214.       if Component.Name <> '' then
  215.         FormCaption := Format('%s.%s', [Component.Name,
  216.           LoadStr(srGradientCaptions)])
  217.       else
  218.         FormCaption := Format('%s.%s', [Component.ClassName,
  219.           LoadStr(srGradientCaptions)]);
  220.       Active := True;
  221.     end;
  222.   end;
  223.   UpdateCaptionList(-1);
  224.   UpdateControls;
  225. end;
  226.  
  227. procedure TGradCaptionsEditor.ApplyChanges;
  228. begin
  229.   ReadControls;
  230.   if Assigned(FComponent) then begin
  231.     FComponent.Captions := GradientCaption.Captions;
  232.     if Assigned(FDesigner) then FDesigner.Modified;
  233.   end;
  234. end;
  235.  
  236. procedure TGradCaptionsEditor.AddColorItem(const ColorName: string);
  237. begin
  238.   CaptionInactiveColor.Items.Add(ColorName);
  239. end;
  240.  
  241. procedure TGradCaptionsEditor.UpdateControls;
  242. begin
  243.   if ActiveCaption = nil then begin
  244.     ClearControls;
  245.     EnableControls(False);
  246.   end else
  247.   with ActiveCaption do begin
  248.     FUpdating := True;
  249.     try
  250.       FontDialog.Font := Font;
  251.       CaptionText.Text := Caption;
  252.       CaptionInactiveColor.ItemIndex := -1;
  253.       CaptionInactiveColor.Text := ColorToString(InactiveColor);
  254.       CaptionFont.Text := Font.Name;
  255.       CaptionParentFont.Checked := ParentFont;
  256.       CaptionGlueNext.Checked := GlueNext;
  257.       CaptionVisible.Checked := Visible;
  258.       EnableControls(True);
  259.     finally
  260.       FUpdating := False;
  261.     end;
  262.   end;
  263. end;
  264.  
  265. procedure TGradCaptionsEditor.EnableControls(Enable: Boolean);
  266. begin
  267.   CaptionText.Enabled := Enable;
  268.   CaptionInactiveColor.Enabled := Enable;
  269.   CaptionFont.Enabled := Enable;
  270.   CaptionParentFont.Enabled := Enable;
  271.   CaptionGlueNext.Enabled := Enable;
  272.   CaptionVisible.Enabled := Enable;
  273.   DeleteButton.Enabled := Enable;
  274. end;
  275.  
  276. procedure TGradCaptionsEditor.ClearControls;
  277. begin
  278.   FUpdating := True;
  279.   try
  280.     CaptionText.Text := '';
  281.     CaptionInactiveColor.ItemIndex := -1;
  282.     CaptionInactiveColor.Text := '';
  283.     CaptionFont.Text := '';
  284.     CaptionParentFont.Checked := False;
  285.     CaptionGlueNext.Checked := False;
  286.     CaptionVisible.Checked := False;
  287.   finally
  288.     FUpdating := False;  
  289.   end;
  290. end;
  291.  
  292. procedure TGradCaptionsEditor.ReadControls;
  293. begin
  294.   if not FUpdating and (ActiveCaption <> nil) then begin
  295.     GradientCaption.Captions.BeginUpdate;
  296.     FUpdating := True;
  297.     try
  298.       with ActiveCaption do begin
  299.         Caption := CaptionText.Text;
  300.         InactiveColor := StringToColor(CaptionInactiveColor.Text);
  301.         ParentFont := CaptionParentFont.Checked;
  302.         GlueNext := CaptionGlueNext.Checked;
  303.         Visible := CaptionVisible.Checked;
  304.       end;
  305.     finally
  306.       GradientCaption.Captions.EndUpdate;
  307.       FUpdating := False;
  308.     end;
  309.   end;
  310. end;
  311.  
  312. procedure TGradCaptionsEditor.FormCreate(Sender: TObject);
  313. begin
  314.   FormStorage.IniFileName := SDelphiKey;
  315.   CaptionInactiveColor.Items.BeginUpdate;
  316.   try
  317.     GetColorValues(AddColorItem);
  318.   finally
  319.     CaptionInactiveColor.Items.EndUpdate;
  320.   end;
  321. end;
  322.  
  323. procedure TGradCaptionsEditor.CaptionListClick(Sender: TObject);
  324. begin
  325.   if not FUpdating then UpdateControls;
  326. end;
  327.  
  328. procedure TGradCaptionsEditor.CaptionListDragDrop(Sender, Source: TObject; X,
  329.   Y: Integer);
  330. var
  331.   I: Integer;
  332. begin
  333.   I := CaptionList.ItemAtPos(Point(X, Y), True);
  334.   if (I >= 0) and (I < CaptionList.Items.Count) and
  335.     (I <> CaptionList.ItemIndex) then
  336.   begin
  337.     GradientCaption.MoveCaption(CaptionList.ItemIndex, I);
  338.     CaptionList.ItemIndex := I;
  339.     if not FUpdating then UpdateControls;
  340.   end;
  341. end;
  342.  
  343. procedure TGradCaptionsEditor.CaptionListDragOver(Sender, Source: TObject; X,
  344.   Y: Integer; State: TDragState; var Accept: Boolean);
  345. begin
  346.   BoxDragOver(CaptionList, Source, X, Y, State, Accept, CaptionList.Sorted);
  347. end;
  348.  
  349. procedure TGradCaptionsEditor.NewButtonClick(Sender: TObject);
  350. begin
  351.   if GradientCaption.Captions.Add <> nil then begin
  352.     UpdateCaptionList(GradientCaption.Captions.Count - 1);
  353.     UpdateControls;
  354.     if CaptionText.CanFocus then ActiveControl := CaptionText; 
  355.   end;
  356. end;
  357.  
  358. procedure TGradCaptionsEditor.DeleteButtonClick(Sender: TObject);
  359. begin
  360.   if ActiveCaption <> nil then begin
  361.     ActiveCaption.Free;
  362.     UpdateCaptionList(-1);
  363.     UpdateControls;
  364.   end;
  365. end;
  366.  
  367. procedure TGradCaptionsEditor.OkButtonClick(Sender: TObject);
  368. begin
  369.   ApplyChanges;
  370.   ModalResult := mrOk;
  371. end;
  372.  
  373. procedure TGradCaptionsEditor.ApplyButtonClick(Sender: TObject);
  374. begin
  375.   ApplyChanges;
  376. end;
  377.  
  378. procedure TGradCaptionsEditor.CaptionInactiveColorDblClick(
  379.   Sender: TObject);
  380. begin
  381.   with ColorDialog do begin
  382.     Color := StringToColor(CaptionInactiveColor.Text);
  383.     if Execute then begin
  384.       CaptionInactiveColor.Text := ColorToString(Color);
  385.       if not FUpdating and (ActiveCaption <> nil) then
  386.         ActiveCaption.InactiveColor := Color;
  387.     end;
  388.   end;
  389. end;
  390.  
  391. procedure TGradCaptionsEditor.ControlExit(Sender: TObject);
  392. begin
  393.   if not FUpdating then ReadControls;
  394. end;
  395.  
  396. procedure TGradCaptionsEditor.CaptionTextChange(Sender: TObject);
  397. begin
  398.   if not FUpdating and (ActiveCaption <> nil) then
  399.     ActiveCaption.Caption := CaptionText.Text;
  400. end;
  401.  
  402. procedure TGradCaptionsEditor.CaptionFontButtonClick(Sender: TObject);
  403. begin
  404.   if ActiveCaption <> nil then begin
  405.     with FontDialog do begin
  406.       Font := ActiveCaption.Font;
  407.       Font.Color := ColorToRGB(ActiveCaption.Font.Color);
  408.       if Execute then begin
  409.         FUpdating := True;
  410.         try
  411.           CaptionFont.Text := Font.Name;
  412.           ActiveCaption.Font := Font;
  413.           CaptionParentFont.Checked := ActiveCaption.ParentFont;
  414.         finally
  415.           FUpdating := False;
  416.         end;
  417.       end;
  418.     end;
  419.   end
  420.   else Beep;
  421. end;
  422.  
  423. procedure TGradCaptionsEditor.CheckBoxClick(Sender: TObject);
  424. begin
  425.   if not FUpdating then ReadControls;
  426. end;
  427.  
  428. end.