home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 June / HDC50.iso / Runimage / Delphi50 / Doc / ACTNLIST.INT next >
Text File  |  1999-08-11  |  6KB  |  162 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.   protected
  26.     procedure ReadState(Reader: TReader); override;
  27.     procedure SetParentComponent(AParent: TComponent); override;
  28.   public
  29.     destructor Destroy; override;
  30.     function Execute: Boolean; override;
  31.     function GetParentComponent: TComponent; override;
  32.     function HasParent: Boolean; override;
  33.     function Update: Boolean; override;
  34.     property ActionList: TCustomActionList;
  35.     property Index: Integer;
  36.   published
  37.     property Category: string;
  38.   end;
  39.  
  40.   TContainedActionClass = class of TContainedAction;
  41.  
  42. { TCustomActionList }
  43.  
  44.   TActionEvent = procedure (Action: TBasicAction; var Handled: Boolean) of object;
  45.  
  46.   TCustomActionList = class(TComponent)
  47.   protected
  48.     procedure Change; virtual;
  49.     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  50.     procedure Notification(AComponent: TComponent;
  51.       Operation: TOperation); override;
  52.     procedure SetChildOrder(Component: TComponent; Order: Integer); override;
  53.     property OnChange: TNotifyEvent;
  54.     property OnExecute: TActionEvent;
  55.     property OnUpdate: TActionEvent;
  56.   public
  57.     constructor Create(AOwner: TComponent); override;
  58.     destructor Destroy; override;
  59.     function ExecuteAction(Action: TBasicAction): Boolean; override;
  60.     function IsShortCut(var Message: TWMKey): Boolean;
  61.     function UpdateAction(Action: TBasicAction): Boolean; override;
  62.     property Actions[Index: Integer]: TContainedAction; default;
  63.     property ActionCount: Integer;
  64.     property Images: TCustomImageList;
  65.   end;
  66.  
  67. { TActionList }
  68.  
  69.   TActionList = class(TCustomActionList)
  70.   published
  71.     property Images;
  72.     property OnChange;
  73.     property OnExecute;
  74.     property OnUpdate;
  75.   end;
  76.  
  77. { TControlAction }
  78.  
  79.   THintEvent = procedure (var HintStr: string; var CanShow: Boolean) of object;
  80.  
  81.   TCustomAction = class(TContainedAction)
  82.   protected
  83.     FImage: TObject;
  84.     FMask: TObject;
  85.     procedure AssignTo(Dest: TPersistent); override;
  86.     procedure SetName(const Value: TComponentName); override;
  87.   public
  88.     constructor Create(AOwner: TComponent); override;
  89.     destructor Destroy; override;
  90.     function DoHint(var HintStr: string): Boolean; dynamic;
  91.     function Execute: Boolean; override;
  92.     property Caption: string;
  93.     property Checked: Boolean default False;
  94.     property DisableIfNoHandler: Boolean default True;
  95.     property Enabled: Boolean default True;
  96.     property HelpContext: THelpContext default 0;
  97.     property Hint: string;
  98.     property ImageIndex: TImageIndex default -1;
  99.     property ShortCut: TShortCut default 0;
  100.     property Visible: Boolean default True;
  101.     property OnHint: THintEvent;
  102.   end;
  103.  
  104.   TAction = class(TCustomAction)
  105.   published
  106.     property Caption;
  107.     property Checked;
  108.     property Enabled;
  109.     property HelpContext;
  110.     property Hint;
  111.     property ImageIndex;
  112.     property ShortCut;
  113.     property Visible;
  114.     property OnExecute;
  115.     property OnHint;
  116.     property OnUpdate;
  117.   end;
  118.  
  119. { TControlActionLink }
  120.  
  121.   TActionLink = class(TBasicActionLink)
  122.   protected
  123.     function IsCaptionLinked: Boolean; virtual;
  124.     function IsCheckedLinked: Boolean; virtual;
  125.     function IsEnabledLinked: Boolean; virtual;
  126.     function IsHelpContextLinked: Boolean; virtual;
  127.     function IsHintLinked: Boolean; virtual;
  128.     function IsImageIndexLinked: Boolean; virtual;
  129.     function IsShortCutLinked: Boolean; virtual;
  130.     function IsVisibleLinked: Boolean; virtual;
  131.     procedure SetCaption(const Value: string); virtual;
  132.     procedure SetChecked(Value: Boolean); virtual;
  133.     procedure SetEnabled(Value: Boolean); virtual;
  134.     procedure SetHelpContext(Value: THelpContext); virtual;
  135.     procedure SetHint(const Value: string); virtual;
  136.     procedure SetImageIndex(Value: Integer); virtual;
  137.     procedure SetShortCut(Value: TShortCut); virtual;
  138.     procedure SetVisible(Value: Boolean); virtual;
  139.   end;
  140.  
  141.   TActionLinkClass = class of TActionLink;
  142.  
  143. { Action registration }
  144.  
  145.   TEnumActionProc = procedure (const Category: string; ActionClass: TBasicActionClass;
  146.     Info: Pointer) of object;
  147.  
  148. procedure RegisterActions(const CategoryName: string;
  149.   const AClasses: array of TBasicActionClass; Resource: TComponentClass);
  150. procedure UnRegisterActions(const AClasses: array of TBasicActionClass);
  151. procedure EnumRegisteredActions(Proc: TEnumActionProc; Info: Pointer);
  152. function CreateAction(AOwner: TComponent; ActionClass: TBasicActionClass): TBasicAction;
  153.  
  154. const
  155.   RegisterActionsProc: procedure (const CategoryName: string;
  156.     const AClasses: array of TBasicActionClass; Resource: TComponentClass) = nil;
  157.   UnRegisterActionsProc: procedure (const AClasses: array of TBasicActionClass) = nil;
  158.   EnumRegisteredActionsProc: procedure (Proc: TEnumActionProc; Info: Pointer) = nil;
  159.   CreateActionProc: function (AOwner: TComponent; ActionClass: TBasicActionClass): TBasicAction = nil;
  160.  
  161. implementation
  162.