home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Vcl / actnlist.pas next >
Pascal/Delphi Source File  |  1999-08-11  |  20KB  |  713 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {                                                       }
  6. {       Copyright (c) 1999 Inprise Corporation          }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit ActnList;
  11.  
  12. {$T-,H+,X+}
  13.  
  14. interface
  15.  
  16. uses Classes, Messages, ImgList;
  17.  
  18. type
  19.  
  20. { TContainedAction }
  21.  
  22.   TCustomActionList = class;
  23.  
  24.   TContainedAction = class(TBasicAction)
  25.   private
  26.     FCategory: string;
  27.     FActionList: TCustomActionList;
  28.     function GetIndex: Integer;
  29.     function IsCategoryStored: Boolean;
  30.     procedure SetCategory(const Value: string);
  31.     procedure SetIndex(Value: Integer);
  32.     procedure SetActionList(AActionList: TCustomActionList);
  33.   protected
  34.     procedure ReadState(Reader: TReader); override;
  35.     procedure SetParentComponent(AParent: TComponent); override;
  36.   public
  37.     destructor Destroy; override;
  38.     function Execute: Boolean; override;
  39.     function GetParentComponent: TComponent; override;
  40.     function HasParent: Boolean; override;
  41.     function Update: Boolean; override;
  42.     property ActionList: TCustomActionList read FActionList write SetActionList;
  43.     property Index: Integer read GetIndex write SetIndex stored False;
  44.   published
  45.     property Category: string read FCategory write SetCategory stored IsCategoryStored;
  46.   end;
  47.  
  48.   TContainedActionClass = class of TContainedAction;
  49.  
  50. { TCustomActionList }
  51.  
  52.   TActionEvent = procedure (Action: TBasicAction; var Handled: Boolean) of object;
  53.  
  54.   TCustomActionList = class(TComponent)
  55.   private
  56.     FActions: TList;
  57.     FImageChangeLink: TChangeLink;
  58.     FImages: TCustomImageList;
  59.     FOnChange: TNotifyEvent;
  60.     FOnExecute: TActionEvent;
  61.     FOnUpdate: TActionEvent;
  62.     procedure AddAction(Action: TContainedAction);
  63.     function GetAction(Index: Integer): TContainedAction;
  64.     function GetActionCount: Integer;
  65.     procedure ImageListChange(Sender: TObject);
  66.     procedure RemoveAction(Action: TContainedAction);
  67.     procedure SetAction(Index: Integer; Value: TContainedAction);
  68.     procedure SetImages(Value: TCustomImageList);
  69.   protected
  70.     procedure Change; virtual;
  71.     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  72.     procedure Notification(AComponent: TComponent;
  73.       Operation: TOperation); override;
  74.     procedure SetChildOrder(Component: TComponent; Order: Integer); override;
  75.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  76.     property OnExecute: TActionEvent read FOnExecute write FOnExecute;
  77.     property OnUpdate: TActionEvent read FOnUpdate write FOnUpdate;
  78.   public
  79.     constructor Create(AOwner: TComponent); override;
  80.     destructor Destroy; override;
  81.     function ExecuteAction(Action: TBasicAction): Boolean; override;
  82.     function IsShortCut(var Message: TWMKey): Boolean;
  83.     function UpdateAction(Action: TBasicAction): Boolean; override;
  84.     property Actions[Index: Integer]: TContainedAction read GetAction write SetAction; default;
  85.     property ActionCount: Integer read GetActionCount;
  86.     property Images: TCustomImageList read FImages write SetImages;
  87.   end;
  88.  
  89. { TActionList }
  90.  
  91.   TActionList = class(TCustomActionList)
  92.   published
  93.     property Images;
  94.     property OnChange;
  95.     property OnExecute;
  96.     property OnUpdate;
  97.   end;
  98.  
  99. { TControlAction }
  100.  
  101.   THintEvent = procedure (var HintStr: string; var CanShow: Boolean) of object;
  102.  
  103.   TCustomAction = class(TContainedAction)
  104.   private
  105.     FDisableIfNoHandler: Boolean;
  106.     FCaption: string;
  107.     FChecked: Boolean;
  108.     FEnabled: Boolean;
  109.     FHelpContext: THelpContext;
  110.     FHint: string;
  111.     FImageIndex: TImageIndex;
  112.     FShortCut: TShortCut;
  113.     FVisible: Boolean;
  114.     FOnHint: THintEvent;
  115.     procedure SetCaption(const Value: string);
  116.     procedure SetChecked(Value: Boolean);
  117.     procedure SetEnabled(Value: Boolean);
  118.     procedure SetHelpContext(Value: THelpContext);
  119.     procedure SetHint(const Value: string);
  120.     procedure SetImageIndex(Value: TImageIndex);
  121.     procedure SetShortCut(Value: TShortCut);
  122.     procedure SetVisible(Value: Boolean);
  123.   protected
  124.     FImage: TObject;
  125.     FMask: TObject;
  126.     procedure AssignTo(Dest: TPersistent); override;
  127.     procedure SetName(const Value: TComponentName); override;
  128.   public
  129.     constructor Create(AOwner: TComponent); override;
  130.     destructor Destroy; override;
  131.     function DoHint(var HintStr: string): Boolean; dynamic;
  132.     function Execute: Boolean; override;
  133.     property Caption: string read FCaption write SetCaption;
  134.     property Checked: Boolean read FChecked write SetChecked default False;
  135.     property DisableIfNoHandler: Boolean read FDisableIfNoHandler write FDisableIfNoHandler default True;
  136.     property Enabled: Boolean read FEnabled write SetEnabled default True;
  137.     property HelpContext: THelpContext read FHelpContext write SetHelpContext default 0;
  138.     property Hint: string read FHint write SetHint;
  139.     property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
  140.     property ShortCut: TShortCut read FShortCut write SetShortCut default 0;
  141.     property Visible: Boolean read FVisible write SetVisible default True;
  142.     property OnHint: THintEvent read FOnHint write FOnHint;
  143.   end;
  144.  
  145.   TAction = class(TCustomAction)
  146.   published
  147.     property Caption;
  148.     property Checked;
  149.     property Enabled;
  150.     property HelpContext;
  151.     property Hint;
  152.     property ImageIndex;
  153.     property ShortCut;
  154.     property Visible;
  155.     property OnExecute;
  156.     property OnHint;
  157.     property OnUpdate;
  158.   end;
  159.  
  160. { TControlActionLink }
  161.  
  162.   TActionLink = class(TBasicActionLink)
  163.   protected
  164.     function IsCaptionLinked: Boolean; virtual;
  165.     function IsCheckedLinked: Boolean; virtual;
  166.     function IsEnabledLinked: Boolean; virtual;
  167.     function IsHelpContextLinked: Boolean; virtual;
  168.     function IsHintLinked: Boolean; virtual;
  169.     function IsImageIndexLinked: Boolean; virtual;
  170.     function IsShortCutLinked: Boolean; virtual;
  171.     function IsVisibleLinked: Boolean; virtual;
  172.     procedure SetCaption(const Value: string); virtual;
  173.     procedure SetChecked(Value: Boolean); virtual;
  174.     procedure SetEnabled(Value: Boolean); virtual;
  175.     procedure SetHelpContext(Value: THelpContext); virtual;
  176.     procedure SetHint(const Value: string); virtual;
  177.     procedure SetImageIndex(Value: Integer); virtual;
  178.     procedure SetShortCut(Value: TShortCut); virtual;
  179.     procedure SetVisible(Value: Boolean); virtual;
  180.   end;
  181.  
  182.   TActionLinkClass = class of TActionLink;
  183.  
  184. { Action registration }
  185.  
  186.   TEnumActionProc = procedure (const Category: string; ActionClass: TBasicActionClass;
  187.     Info: Pointer) of object;
  188.  
  189. procedure RegisterActions(const CategoryName: string;
  190.   const AClasses: array of TBasicActionClass; Resource: TComponentClass);
  191. procedure UnRegisterActions(const AClasses: array of TBasicActionClass);
  192. procedure EnumRegisteredActions(Proc: TEnumActionProc; Info: Pointer);
  193. function CreateAction(AOwner: TComponent; ActionClass: TBasicActionClass): TBasicAction;
  194.  
  195. const
  196.   RegisterActionsProc: procedure (const CategoryName: string;
  197.     const AClasses: array of TBasicActionClass; Resource: TComponentClass) = nil;
  198.   UnRegisterActionsProc: procedure (const AClasses: array of TBasicActionClass) = nil;
  199.   EnumRegisteredActionsProc: procedure (Proc: TEnumActionProc; Info: Pointer) = nil;
  200.   CreateActionProc: function (AOwner: TComponent; ActionClass: TBasicActionClass): TBasicAction = nil;
  201.  
  202. implementation
  203.  
  204. uses SysUtils, Forms, Menus, Consts, Graphics, Controls;
  205.  
  206. procedure RegisterActions(const CategoryName: string;
  207.   const AClasses: array of TBasicActionClass; Resource: TComponentClass);
  208. begin
  209.   if Assigned(RegisterActionsProc) then
  210.     RegisterActionsProc(CategoryName, AClasses, Resource) else
  211.     raise Exception.CreateRes(@SInvalidActionRegistration);
  212. end;
  213.  
  214. procedure UnRegisterActions(const AClasses: array of TBasicActionClass);
  215. begin
  216.   if Assigned(UnRegisterActionsProc) then
  217.     UnRegisterActionsProc(AClasses) else
  218.     raise Exception.CreateRes(@SInvalidActionUnregistration);
  219. end;
  220.  
  221. procedure EnumRegisteredActions(Proc: TEnumActionProc; Info: Pointer);
  222. begin
  223.   if Assigned(EnumRegisteredActionsProc) then
  224.     EnumRegisteredActionsProc(Proc, Info) else
  225.     raise Exception.CreateRes(@SInvalidActionEnumeration);
  226. end;
  227.  
  228. function CreateAction(AOwner: TComponent; ActionClass: TBasicActionClass): TBasicAction;
  229. begin
  230.   if Assigned(CreateActionProc) then
  231.     Result := CreateActionProc(AOwner, ActionClass) else
  232.     raise Exception.CreateRes(@SInvalidActionCreation);
  233. end;
  234.  
  235. { TContainedAction }
  236.  
  237. destructor TContainedAction.Destroy;
  238. begin
  239.   if ActionList <> nil then ActionList.RemoveAction(Self);
  240.   inherited Destroy;
  241. end;
  242.  
  243. function TContainedAction.GetIndex: Integer;
  244. begin
  245.   if ActionList <> nil then
  246.     Result := ActionList.FActions.IndexOf(Self) else
  247.     Result := -1;
  248. end;
  249.  
  250. function TContainedAction.IsCategoryStored: Boolean;
  251. begin
  252.   Result := True;//GetParentComponent <> ActionList;
  253. end;
  254.  
  255. function TContainedAction.GetParentComponent: TComponent;
  256. begin
  257.   if ActionList <> nil then
  258.     Result := ActionList else
  259.     Result := inherited GetParentComponent;
  260. end;
  261.  
  262. function TContainedAction.HasParent: Boolean;
  263. begin
  264.   if ActionList <> nil then
  265.     Result := True else
  266.     Result := inherited HasParent;
  267. end;
  268.  
  269. procedure TContainedAction.ReadState(Reader: TReader);
  270. begin
  271.   inherited ReadState(Reader);
  272.   if Reader.Parent is TCustomActionList then
  273.     ActionList := TCustomActionList(Reader.Parent);
  274. end;
  275.  
  276. procedure TContainedAction.SetIndex(Value: Integer);
  277. var
  278.   CurIndex, Count: Integer;
  279. begin
  280.   CurIndex := GetIndex;
  281.   if CurIndex >= 0 then
  282.   begin
  283.     Count := ActionList.FActions.Count;
  284.     if Value < 0 then Value := 0;
  285.     if Value >= Count then Value := Count - 1;
  286.     if Value <> CurIndex then
  287.     begin
  288.       ActionList.FActions.Delete(CurIndex);
  289.       ActionList.FActions.Insert(Value, Self);
  290.     end;
  291.   end;
  292. end;
  293.  
  294. procedure TContainedAction.SetCategory(const Value: string);
  295. begin
  296.   if Value <> Category then
  297.   begin
  298.     FCategory := Value;
  299.     if ActionList <> nil then
  300.       ActionList.Change;
  301.   end;
  302. end;
  303.  
  304. procedure TContainedAction.SetActionList(AActionList: TCustomActionList);
  305. begin
  306.   if AActionList <> ActionList then
  307.   begin
  308.     if ActionList <> nil then ActionList.RemoveAction(Self);
  309.     if AActionList <> nil then AActionList.AddAction(Self);
  310.   end;
  311. end;
  312.  
  313. procedure TContainedAction.SetParentComponent(AParent: TComponent);
  314. begin
  315.   if not (csLoading in ComponentState) and (AParent is TCustomActionList) then
  316.     ActionList := TCustomActionList(AParent);
  317. end;
  318.  
  319. function TContainedAction.Execute: Boolean;
  320. begin
  321.   Result := (ActionList <> nil) and ActionList.ExecuteAction(Self) or
  322.     Application.ExecuteAction(Self) or inherited Execute or
  323.     (SendAppMessage(CM_ACTIONEXECUTE, 0, Longint(Self)) = 1);
  324. end;
  325.  
  326. function TContainedAction.Update: Boolean;
  327. begin
  328.   Result := (ActionList <> nil) and ActionList.UpdateAction(Self) or
  329.     Application.UpdateAction(Self) or inherited Update or
  330.     (SendAppMessage(CM_ACTIONUPDATE, 0, Longint(Self)) = 1);
  331. end;
  332.  
  333. { TCustomActionList }
  334.  
  335. constructor TCustomActionList.Create(AOwner: TComponent);
  336. begin
  337.   inherited Create(AOwner);
  338.   FActions := TList.Create;
  339.   FImageChangeLink := TChangeLink.Create;
  340.   FImageChangeLink.OnChange := ImageListChange;
  341. end;
  342.  
  343. destructor TCustomActionList.Destroy;
  344. begin
  345.   FImageChangeLink.Free;
  346.   while FActions.Count > 0 do TContainedAction(FActions.Last).Free;
  347.   FActions.Free;
  348.   inherited Destroy;
  349. end;
  350.  
  351. procedure TCustomActionList.GetChildren(Proc: TGetChildProc; Root: TComponent);
  352. var
  353.   I: Integer;
  354.   Action: TAction;
  355. begin
  356.   for I := 0 to FActions.Count - 1 do
  357.   begin
  358.     Action := FActions[I];
  359.     if Action.Owner = Root then Proc(Action);
  360.   end;
  361. end;
  362.  
  363. procedure TCustomActionList.SetChildOrder(Component: TComponent; Order: Integer);
  364. begin
  365.   if FActions.IndexOf(Component) >= 0 then
  366.     (Component as TContainedAction).Index := Order;
  367. end;
  368.  
  369. function TCustomActionList.GetAction(Index: Integer): TContainedAction;
  370. begin
  371.   Result := FActions[Index];
  372. end;
  373.  
  374. function TCustomActionList.GetActionCount: Integer;
  375. begin
  376.   Result := FActions.Count;
  377. end;
  378.  
  379. procedure TCustomActionList.SetAction(Index: Integer; Value: TContainedAction);
  380. begin
  381.   TContainedAction(FActions[Index]).Assign(Value);
  382. end;
  383.  
  384. procedure TCustomActionList.SetImages(Value: TCustomImageList);
  385. begin
  386.   if Images <> nil then Images.UnRegisterChanges(FImageChangeLink);
  387.   FImages := Value;
  388.   if Images <> nil then
  389.   begin
  390.     Images.RegisterChanges(FImageChangeLink);
  391.     Images.FreeNotification(Self);
  392.   end;
  393. end;
  394.  
  395. procedure TCustomActionList.ImageListChange(Sender: TObject);
  396. begin
  397.   if Sender = Images then Change;
  398. end;
  399.  
  400. procedure TCustomActionList.Notification(AComponent: TComponent;
  401.   Operation: TOperation);
  402. begin
  403.   inherited Notification(AComponent, Operation);
  404.   if Operation = opRemove then
  405.     if AComponent = Images then
  406.       Images := nil
  407.     else if (AComponent is TContainedAction) then
  408.       RemoveAction(TContainedAction(AComponent));
  409. end;
  410.  
  411. procedure TCustomActionList.AddAction(Action: TContainedAction);
  412. begin
  413.   FActions.Add(Action);
  414.   Action.FActionList := Self;
  415.   Action.FreeNotification(Self);
  416. end;
  417.  
  418. procedure TCustomActionList.RemoveAction(Action: TContainedAction);
  419. begin
  420.   if FActions.Remove(Action) >= 0 then
  421.     Action.FActionList := nil;
  422. end;
  423.  
  424. procedure TCustomActionList.Change;
  425. var
  426.   I: Integer;
  427. begin
  428.   if Assigned(FOnChange) then FOnChange(Self);
  429.   for I := 0 to FActions.Count - 1 do
  430.     TContainedAction(FActions[I]).Change;
  431.   if csDesigning in ComponentState then
  432.   begin
  433.     if (Owner is TForm) and (TForm(Owner).Designer <> nil) then
  434.       TForm(Owner).Designer.Modified;
  435.   end;
  436. end;
  437.  
  438. function TCustomActionList.IsShortCut(var Message: TWMKey): Boolean;
  439. var
  440.   I: Integer;
  441.   ShortCut: TShortCut;
  442.   ShiftState: TShiftState;
  443. begin
  444.   ShiftState := KeyDataToShiftState(Message.KeyData);
  445.   ShortCut := Menus.ShortCut(Message.CharCode, ShiftState);
  446.   for I := 0 to FActions.Count - 1 do
  447.     if TCustomAction(FActions[I]).ShortCut = ShortCut then
  448.     begin
  449.       Result := TCustomAction(FActions[I]).Execute;
  450.       Exit;
  451.     end;
  452.   Result := False;
  453. end;
  454.  
  455. function TCustomActionList.ExecuteAction(Action: TBasicAction): Boolean;
  456. begin
  457.   Result := False;
  458.   if Assigned(FOnExecute) then FOnExecute(Action, Result);
  459. end;
  460.  
  461. function TCustomActionList.UpdateAction(Action: TBasicAction): Boolean;
  462. begin
  463.   Result := False;
  464.   if Assigned(FOnUpdate) then FOnUpdate(Action, Result);
  465. end;
  466.  
  467. { TActionLink }
  468.  
  469. function TActionLink.IsCaptionLinked: Boolean;
  470. begin
  471.   Result := Action is TCustomAction;
  472. end;
  473.  
  474. function TActionLink.IsCheckedLinked: Boolean;
  475. begin
  476.   Result := Action is TCustomAction;
  477. end;
  478.  
  479. function TActionLink.IsEnabledLinked: Boolean;
  480. begin
  481.   Result := Action is TCustomAction;
  482. end;
  483.  
  484. function TActionLink.IsHelpContextLinked: Boolean;
  485. begin
  486.   Result := Action is TCustomAction;
  487. end;
  488.  
  489. function TActionLink.IsHintLinked: Boolean;
  490. begin
  491.   Result := Action is TCustomAction;
  492. end;
  493.  
  494. function TActionLink.IsImageIndexLinked: Boolean;
  495. begin
  496.   Result := Action is TCustomAction;
  497. end;
  498.  
  499. function TActionLink.IsShortCutLinked: Boolean;
  500. begin
  501.   Result := Action is TCustomAction;
  502. end;
  503.  
  504. function TActionLink.IsVisibleLinked: Boolean;
  505. begin
  506.   Result := Action is TCustomAction;
  507. end;
  508.  
  509. procedure TActionLink.SetCaption(const Value: string);
  510. begin
  511. end;
  512.  
  513. procedure TActionLink.SetChecked(Value: Boolean);
  514. begin
  515. end;
  516.  
  517. procedure TActionLink.SetEnabled(Value: Boolean);
  518. begin
  519. end;
  520.  
  521. procedure TActionLink.SetHelpContext(Value: THelpContext);
  522. begin
  523. end;
  524.  
  525. procedure TActionLink.SetHint(const Value: string);
  526. begin
  527. end;
  528.  
  529. procedure TActionLink.SetImageIndex(Value: Integer);
  530. begin
  531. end;
  532.  
  533.  
  534. procedure TActionLink.SetShortCut(Value: TShortCut);
  535. begin
  536. end;
  537.  
  538. procedure TActionLink.SetVisible(Value: Boolean);
  539. begin
  540. end;
  541.  
  542. { TCustomAction }
  543.  
  544. constructor TCustomAction.Create(AOwner: TComponent);
  545. begin
  546.   inherited Create(AOwner);
  547.   FDisableIfNoHandler := True;
  548.   FEnabled := True;
  549.   FImageIndex := -1;
  550.   FVisible := True;
  551. end;
  552.  
  553. destructor TCustomAction.Destroy;
  554. begin
  555.   FImage.Free;
  556.   FMask.Free;
  557.   inherited Destroy;
  558. end;
  559.  
  560. procedure TCustomAction.AssignTo(Dest: TPersistent);
  561. begin
  562.   if Dest is TCustomAction then
  563.     with TCustomAction(Dest) do
  564.     begin
  565.       Caption := Self.Caption;
  566.       Checked := Self.Checked;
  567.       Enabled := Self.Enabled;
  568.       HelpContext := Self.HelpContext;
  569.       Hint := Self.Hint;
  570.       ImageIndex := Self.ImageIndex;
  571.       ShortCut := Self.ShortCut;
  572.       Visible := Self.Visible;
  573.     end else inherited AssignTo(Dest);
  574. end;
  575.  
  576. procedure TCustomAction.SetCaption(const Value: string);
  577. var
  578.   I: Integer;
  579. begin
  580.   if Value <> FCaption then
  581.   begin
  582.     for I := 0 to FClients.Count - 1 do
  583.       if TBasicActionLink(FClients[I]) is TActionLink then
  584.         TActionLink(FClients[I]).SetCaption(Value);
  585.     FCaption := Value;
  586.     Change;
  587.   end;
  588. end;
  589.  
  590. procedure TCustomAction.SetChecked(Value: Boolean);
  591. var
  592.   I: Integer;
  593. begin
  594.   if Value <> FChecked then
  595.   begin
  596.     for I := 0 to FClients.Count - 1 do
  597.       if TBasicActionLink(FClients[I]) is TActionLink then
  598.         TActionLink(FClients[I]).SetChecked(Value);
  599.     FChecked := Value;
  600.     Change;
  601.   end;
  602. end;
  603.  
  604. procedure TCustomAction.SetEnabled(Value: Boolean);
  605. var
  606.   I: Integer;
  607. begin
  608.   if Value <> FEnabled then
  609.   begin
  610.     for I := 0 to FClients.Count - 1 do
  611.       if TBasicActionLink(FClients[I]) is TActionLink then
  612.         TActionLink(FClients[I]).SetEnabled(Value);
  613.     FEnabled := Value;
  614.     Change;
  615.   end;
  616. end;
  617.  
  618. procedure TCustomAction.SetHelpContext(Value: THelpContext);
  619. var
  620.   I: Integer;
  621. begin
  622.   if Value <> FHelpContext then
  623.   begin
  624.     for I := 0 to FClients.Count - 1 do
  625.       if TBasicActionLink(FClients[I]) is TActionLink then
  626.         TActionLink(FClients[I]).SetHelpContext(Value);
  627.     FHelpContext := Value;
  628.     Change;
  629.   end;
  630. end;
  631.  
  632. procedure TCustomAction.SetHint(const Value: string);
  633. var
  634.   I: Integer;
  635. begin
  636.   if Value <> FHint then
  637.   begin
  638.     for I := 0 to FClients.Count - 1 do
  639.       if TBasicActionLink(FClients[I]) is TActionLink then
  640.         TActionLink(FClients[I]).SetHint(Value);
  641.     FHint := Value;
  642.     Change;
  643.   end;
  644. end;
  645.  
  646. procedure TCustomAction.SetImageIndex(Value: TImageIndex);
  647. var
  648.   I: Integer;
  649. begin
  650.   if Value <> FImageIndex then
  651.   begin
  652.     for I := 0 to FClients.Count - 1 do
  653.       if TBasicActionLink(FClients[I]) is TActionLink then
  654.         TActionLink(FClients[I]).SetImageIndex(Value);
  655.     FImageIndex := Value;
  656.     Change;
  657.   end;
  658. end;
  659.  
  660. procedure TCustomAction.SetShortCut(Value: TShortCut);
  661. var
  662.   I: Integer;
  663. begin
  664.   if Value <> FShortCut then
  665.   begin
  666.     for I := 0 to FClients.Count - 1 do
  667.       if TBasicActionLink(FClients[I]) is TActionLink then
  668.         TActionLink(FClients[I]).SetShortCut(Value);
  669.     FShortCut := Value;
  670.     Change;
  671.   end;
  672. end;
  673.  
  674. procedure TCustomAction.SetVisible(Value: Boolean);
  675. var
  676.   I: Integer;
  677. begin
  678.   if Value <> FVisible then
  679.   begin
  680.     for I := 0 to FClients.Count - 1 do
  681.       if TBasicActionLink(FClients[I]) is TActionLink then
  682.         TActionLink(FClients[I]).SetVisible(Value);
  683.     FVisible := Value;
  684.     Change;
  685.   end;
  686. end;
  687.  
  688. procedure TCustomAction.SetName(const Value: TComponentName);
  689. var
  690.   ChangeText: Boolean;
  691. begin
  692.   ChangeText := (Name = Caption) and ((Owner = nil) or
  693.     not (csLoading in Owner.ComponentState));
  694.   inherited SetName(Value);
  695.   { Don't update caption to name if we've got clients connected. }
  696.   if ChangeText and (FClients.Count = 0) then Caption := Value;
  697. end;
  698.  
  699. function TCustomAction.DoHint(var HintStr: string): Boolean;
  700. begin
  701.   Result := True;
  702.   if Assigned(FOnHint) then FOnHint(HintStr, Result);
  703. end;
  704.  
  705. function TCustomAction.Execute: Boolean;
  706. begin
  707.   Update;
  708.   Result := Enabled and inherited Execute;
  709. end;
  710.  
  711. end.
  712.  
  713.