[text] test

Viewer

  1. unit kallupPanelMenu;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls, Menus,
  8.   //
  9.   DesignIntf, DesignEditors, DesignMenus, DesignWindows;
  10.  
  11. type
  12.   TkallupMenuPanel = class;
  13.  
  14.   // ----------------------------------------------------------
  15.   // component menu for the quick access to the control
  16.   // ----------------------------------------------------------
  17.   TkallupMenuEditor = class (TComponentEditor)
  18.     function GetVerbCount: Integer; override;
  19.     function GetVerb(Index: Integer): string; override;
  20.     procedure ExecuteVerb(Index: Integer); override;
  21.     procedure Edit; override;
  22.   end;
  23.  
  24.   // ----------------------------------------------------------
  25.   // collection for items of the menu panels, one for each ...
  26.   // ----------------------------------------------------------
  27.   TkallupMenuPanelCollection = class(TCollection)
  28.   private
  29.     FComponent : TComponent;
  30.     FCollectionString: String;
  31.   public
  32.     constructor Create(AOwner: TComponent);
  33.     function GetOwner: TPersistent; override;
  34.     procedure Update(Item: TCollectionItem); override;
  35.   end;
  36.  
  37.   // ----------------------------------------------------------
  38.   // item display state mode basis class
  39.   // ----------------------------------------------------------
  40.   TkallupMenuPanelCollectionItemStateBasis = class(TPersistent)
  41.   private
  42.     FBitmap       : TBitmap;
  43.     FCaption      : TCaption;
  44.     FColor        : TColor;
  45.     FFontText     : TFont;
  46.     FFontShortCut : TFont;
  47.  
  48.     procedure SetBitmap       (AValue: TBitmap);
  49.     procedure SetCaption      (AValue: TCaption);
  50.     procedure SetColor        (AValue: TColor);
  51.     procedure SetFontText     (AValue: TFont);
  52.     procedure SetFontShortCut (AValue: TFont);
  53.   public
  54.     constructor Create;
  55.     destructor Destroy; override;
  56.   published
  57.     property Bitmap       : TBitmap  read FBitmap       write SetBitmap;
  58.     property Caption      : TCaption read FCaption      write SetCaption;
  59.     property Color        : TColor   read FColor        write SetColor;
  60.     property FontText     : TFont    read FFontText     write SetFontText;
  61.     property FontShortCut : TFont    read FFontShortCut write SetFontShortCut;
  62.   end;
  63.  
  64.   // ----------------------------------------------------------
  65.   // item on hover display mode
  66.   // ----------------------------------------------------------
  67.   TkallupMenuPanelCollectionItemHover = class(TkallupMenuPanelCollectionItemStateBasis)
  68.   public
  69.     constructor Create;
  70.     destructor Destroy; override;
  71.   published
  72.     property Bitmap;
  73.     property Caption;
  74.     property Color;
  75.     property FontText;
  76.     property FontShortCut;
  77.   end;
  78.  
  79.   // ----------------------------------------------------------
  80.   // item on normal display mode
  81.   // ----------------------------------------------------------
  82.   TkallupMenuPanelCollectionItemNormal = class(TkallupMenuPanelCollectionItemStateBasis)
  83.   public
  84.     constructor Create;
  85.     destructor Destroy; override;
  86.   published
  87.     property Bitmap;
  88.     property Caption;
  89.     property Color;
  90.     property FontText;
  91.     property FontShortCut;
  92.   end;
  93.  
  94.   // ----------------------------------------------------------
  95.   // item on selected with mousePress
  96.   // ----------------------------------------------------------
  97.   TkallupMenuPanelCollectionItemSelected = class(TkallupMenuPanelCollectionItemStateBasis)
  98.   public
  99.     constructor Create;
  100.     destructor Destroy; override;
  101.   published
  102.     property Bitmap;
  103.     property Caption;
  104.     property Color;
  105.     property FontText;
  106.     property FontShortCut;
  107.   end;
  108.  
  109.   // ----------------------------------------------------------
  110.   // a collection item for the collection
  111.   // ----------------------------------------------------------
  112.   TkallupMenuPanelCollectionItem = class(TCollectionItem)
  113.   private
  114.     { state properties }
  115.     FItemHover     : TkallupMenuPanelCollectionItemHover;
  116.     FItemNormal    : TkallupMenuPanelCollectionItemNormal;
  117.     FItemSelected  : TkallupMenuPanelCollectionItemSelected;
  118.  
  119.     FItemShortCut  : TComboBox;
  120.     FItemName      : String;
  121.  
  122.     FCollection : TkallupMenuPanelCollection;
  123.     FComponent  : TComponent;
  124.  
  125.     FPopupMenu : TPopupMenu;
  126.  
  127.     procedure SetItemSubItem  (AValue: TkallupMenuPanelCollection);
  128.  
  129.     procedure SetItemHover    (const AValue: TkallupMenuPanelCollectionItemHover   );
  130.     procedure SetItemNormal   (const AValue: TkallupMenuPanelCollectionItemNormal  );
  131.     procedure SetItemSelected (const AValue: TkallupMenuPanelCollectionItemSelected);
  132.  
  133.     procedure SetItemShortCut (const AValue: TComboBox);
  134.     procedure SetItemName     (const AValue: String);
  135.  
  136.   public
  137.     constructor Create(AOwner: TCollection); override;
  138.     destructor Destroy; override;
  139.   published
  140.     property Items : TkallupMenuPanelCollection read FCollection write SetItemSubItem;
  141.  
  142.     property Hover    : TkallupMenuPanelCollectionItemHover    read FItemHover    write SetItemHover;
  143.     property Normal   : TkallupMenuPanelCollectionItemNormal   read FItemNormal   write SetItemNormal;
  144.     property Selected : TkallupMenuPanelCollectionItemSelected read FItemSelected write SetItemSelected;
  145.  
  146.     property ShortCut : TComboBox  read FItemShortCut write SetItemShortCut;
  147.     property Text     : String     read FItemName     write SetItemName;
  148.   end;
  149.  
  150.   // ----------------------------------------------------------
  151.   // wrapper class to save code size, for índividual menu ...
  152.   // ----------------------------------------------------------
  153.   TkallupMenuPanel = class(TComponent)
  154.   private
  155.     FCollection: TkallupMenuPanelCollection;
  156.     function GetCollectionString: String;
  157.     procedure SetItems(const AValue: TkallupMenuPanelCollection);
  158.   public
  159.     constructor Create(AOwner: TComponent); override;
  160.     destructor Destroy; override;
  161.   published
  162.     property Items: TkallupMenuPanelCollection read FCollection write SetItems;
  163.     property CollectionString: String read GetCollectionString;
  164.   end;
  165.  
  166.   TkallupMenuPanelDialog = class(TForm)
  167.   end;
  168.  
  169.   procedure Register;
  170.  
  171. implementation
  172.  
  173. uses kallupPanelMenuDesigner;
  174.  
  175. { TkallupMenuPanelCollectionItemStateBasis }
  176.  
  177. constructor TkallupMenuPanelCollectionItemStateBasis.Create;
  178. begin
  179.   inherited Create;
  180. end;
  181. destructor TkallupMenuPanelCollectionItemStateBasis.Destroy;
  182. begin
  183.   if self.FFontText     <> nil then FreeAndNil(self.FFontText);
  184.   if self.FFontShortCut <> nil then FreeAndNil(self.FFontShortCut);
  185.  
  186.   if self.FBitmap       <> nil then FreeAndNil(self.FBitmap);
  187.  
  188.   inherited;
  189. end;
  190.  
  191. procedure TkallupMenuPanelCollectionItemStateBasis.SetBitmap(AValue: TBitmap);
  192. begin
  193.   if FBitmap = nil then FBitmap := TBitmap.Create;
  194.   if AValue  = nil then AValue  := TBitmap.Create;
  195.  
  196.   FBitmap.Assign(AValue);
  197. end;
  198. procedure TkallupMenuPanelCollectionItemStateBasis.SetCaption(AValue: TCaption);
  199. begin
  200.   FCaption := AValue;
  201. end;
  202. procedure TkallupMenuPanelCollectionItemStateBasis.SetColor(AValue: TColor);
  203. begin
  204.   FColor := AValue;
  205. end;
  206. procedure TkallupMenuPanelCollectionItemStateBasis.SetFontText(AValue: TFont);
  207. begin
  208.   if FFontText = nil then FFontText := TFont.Create;
  209.   if AValue    = nil then AValue    := TFont.Create;
  210.  
  211.   FFontText.Assign(AValue);
  212. end;
  213. procedure TkallupMenuPanelCollectionItemStateBasis.SetFontShortCut(AValue: TFont);
  214. begin
  215.   if FFontShortCut = nil then FFontText := TFont.Create;
  216.   if AValue        = nil then AValue    := TFont.Create;
  217.  
  218.   FFontShortCut.Assign(AValue);
  219. end;
  220.  
  221.  
  222. { TkallupMenuPanelCollectionItemHover }
  223.  
  224. constructor TkallupMenuPanelCollectionItemHover.Create;
  225. begin
  226.   inherited Create;
  227.  
  228.   self.FFontText     := TFont.Create;
  229.   self.FFontShortCut := TFont.Create;
  230.  
  231.   self.FBitmap := TBitmap.Create;
  232. end;
  233.  
  234. destructor TkallupMenuPanelCollectionItemHover.Destroy;
  235. begin
  236.   if self.FFontText     <> nil then FreeAndNil(self.FFontText);
  237.   if self.FFontShortCut <> nil then FreeAndNil(self.FFontShortCut);
  238.  
  239.   if self.FBitmap       <> nil then FreeAndNil(self.FBitmap);
  240.  
  241.   inherited Destroy;
  242. end;
  243.  
  244.  
  245. { TkallupMenuPanelCollectionItemNormal }
  246.  
  247. constructor TkallupMenuPanelCollectionItemNormal.Create;
  248. begin
  249.   inherited Create;
  250.  
  251.   self.FFontText     := TFont.Create;
  252.   self.FFontShortCut := TFont.Create;
  253.  
  254.   self.FBitmap := TBitmap.Create;
  255. end;
  256.  
  257. destructor TkallupMenuPanelCollectionItemNormal.Destroy;
  258. begin
  259.   if self.FFontText     <> nil then FreeAndNil(self.FFontText);
  260.   if self.FFontShortCut <> nil then FreeAndNil(self.FFontShortCut);
  261.  
  262.   if self.FBitmap       <> nil then FreeAndNil(self.FBitmap);
  263.  
  264.   inherited Destroy;
  265. end;
  266.  
  267.  
  268. { TkallupMenuPanelCollectionItemSelected }
  269.  
  270. constructor TkallupMenuPanelCollectionItemSelected.Create;
  271. begin
  272.   inherited Create;
  273.  
  274.   self.FFontText     := TFont.Create;
  275.   self.FFontShortCut := TFont.Create;
  276.  
  277.   self.FBitmap := TBitmap.Create;
  278. end;
  279.  
  280. destructor TkallupMenuPanelCollectionItemSelected.Destroy;
  281. begin
  282.   if self.FFontText     <> nil then FreeAndNil(self.FFontText);
  283.   if self.FFontShortCut <> nil then FreeAndNil(self.FFontShortCut);
  284.  
  285.   if self.FBitmap       <> nil then FreeAndNil(self.FBitmap);
  286.  
  287.   inherited Destroy;
  288. end;
  289.  
  290.  
  291. { TkallupMenuEditor }
  292.  
  293. function TkallupMenuEditor.GetVerbCount: Integer;
  294. begin
  295.   result := 3;
  296. end;
  297.  
  298. function TkallupMenuEditor.GetVerb (Index: Integer): string;
  299. begin
  300.   case Index of
  301.     0: Result := ' Individual Menus © 2022 by paule32)';
  302.     1: Result := '&About ...';
  303.     2: Result := 'Open Design Editor';
  304.   end;
  305. end;
  306.  
  307. procedure TKallupMenuEditor.ExecuteVerb (Index: Integer);
  308. begin
  309.   case Index of
  310.     0: begin end;
  311.     1: begin
  312.       MessageDlg ('This is a simple component editor', mtInformation, [mbOK], 0);
  313.     end;
  314.     2: begin
  315.       Form1 := TForm1.Create(Application);
  316.       Form1.ShowModal;
  317.     end
  318.   end;
  319. end;
  320.  
  321. procedure TKallupMenuEditor.Edit;
  322. begin
  323.   Beep;
  324.   ExecuteVerb(0);
  325. end;
  326.  
  327. { TkallupMenuPanelCollectionItem }
  328.  
  329. constructor TkallupMenuPanelCollectionItem.Create(AOwner: TCollection);
  330. begin
  331.   inherited Create(AOwner);
  332.  
  333.   self.FItemHover    := TkallupMenuPanelCollectionItemHover    . Create;
  334.   self.FItemNormal   := TkallupMenuPanelCollectionItemNormal   . Create;
  335.   self.FItemSelected := TkallupMenuPanelCollectionItemSelected . Create;
  336.  
  337.   self.FCollection   := TkallupMenuPanelCollection.Create(self.FComponent);
  338. end;
  339.  
  340. destructor TkallupMenuPanelCollectionItem.Destroy;
  341. begin
  342.   FreeAndNil(self.FItemSelected);
  343.   FreeAndNil(self.FItemNormal  );
  344.   FreeAndNil(self.FItemHover   );
  345.  
  346.   inherited Destroy;
  347. end;
  348.  
  349. procedure TkallupMenuPanelCollectionItem.SetItemSubItem(AValue: TkallupMenuPanelCollection);
  350. begin
  351.   FCollection.Assign(AValue);
  352. end;
  353.  
  354. procedure TkallupMenuPanelCollectionItem.SetItemHover(const AValue: TkallupMenuPanelCollectionItemHover   );
  355. begin
  356.   FItemHover := AValue;
  357. end;
  358. procedure TkallupMenuPanelCollectionItem.SetItemNormal(const AValue: TkallupMenuPanelCollectionItemNormal  );
  359. begin
  360.   FItemNormal := AValue;
  361. end;
  362. procedure TkallupMenuPanelCollectionItem.SetItemSelected(const AValue: TkallupMenuPanelCollectionItemSelected);
  363. begin
  364.   FItemSelected := AValue;
  365. end;
  366. procedure TkallupMenuPanelCollectionItem.SetItemName(const AValue: String);
  367. begin
  368.   FItemName := AValue;
  369. end;
  370. procedure TkallupMenuPanelCollectionItem.SetItemShortCut(const AValue: TComboBox);
  371. begin
  372.   FItemShortCut := AValue;
  373. end;
  374.  
  375.  
  376. { TkallupMenuPanelCollection }
  377.  
  378. constructor TkallupMenuPanelCollection.Create(AOwner: TComponent);
  379. var
  380.   item : TkallupMenuPanelCollectionItem;
  381. begin
  382.   item := TkallupMenuPanelCollectionItem.Create(self);
  383.   item.FComponent := AOwner;
  384.  
  385.   inherited Create(TCollectionItemClass(item));
  386.   FComponent := AOwner;
  387. end;
  388.  
  389. function TkallupMenuPanelCollection.GetOwner: TPersistent;
  390. begin
  391.   Result := FComponent;
  392. end;
  393.  
  394. procedure TkallupMenuPanelCollection.Update(Item: TCollectionItem);
  395. var
  396.   str: String;
  397.   i: Integer;
  398. begin
  399.   str := '';
  400.   for i := 0 to Count- 1 do
  401.   begin
  402.     str := str + (Items[i] as TkallupMenuPanelCollectionItem).Text;
  403.     if i < Count - 1 then
  404.     str := str + '-';
  405.   end;
  406.   FCollectionString := str;
  407. end;
  408.  
  409.  
  410.  
  411. { TkallupMenuPanel }
  412.  
  413. constructor TkallupMenuPanel.Create(AOwner: TComponent);
  414. begin
  415.   inherited Create(AOwner);
  416.   FCollection := TkallupMenuPanelCollection.Create(self);
  417. end;
  418.  
  419. destructor TKallupMenuPanel.Destroy;
  420. begin
  421.   FCollection.Free;
  422.   inherited;
  423. end;
  424.  
  425. procedure TkallupMenuPanel.SetItems(const AValue: TkallupMenuPanelCollection);
  426. begin
  427.   FCollection.Assign(AValue);
  428. end;
  429.  
  430. function TkallupMenuPanel.GetCollectionString: String;
  431. begin
  432.   Result := FCollection.FCollectionString;
  433. end;
  434.  
  435. procedure Register;
  436. begin
  437.   RegisterComponents('KALLUP', [TkallupMenuPanel]);
  438.   RegisterComponentEditor (TkallupMenuPanel, TKallupMenuEditor);
  439. end;
  440.  
  441. end.

Editor

You can edit this paste and save as new:


File Description
  • test
  • Paste Code
  • 25 Dec-2021
  • 12.64 Kb
You can Share it: