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

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