  ////////////////////////////////////////////////////////////
 // TrayIconForm.pas - Файл редактора компенента TTrayIcon
// Дмитрий Демидов, С-Петербург 06.Мар.2000 г.
////////////////////////////////////////////////////////////
// Редактор компонента TTrayIcon позволяет наглядно настроить
// основные свойства компенента и понадлюдать его в действии...
////////////////////////////////////////////////////////////

unit TrayIconForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  TrayIcon, ExtDlgs, StdCtrls, Buttons, ExtCtrls, dsgnintf, Menus, ImgList;

type
  TTrayIconEditDialog = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Panel1: TPanel;
    IconImg: TImage;
    BrowseBtn: TBitBtn;
    ClearBtn: TBitBtn;
    Label2: TLabel;
    TipEdt: TEdit;
    VisibleCbx: TCheckBox;
    Label3: TLabel;
    Label4: TLabel;
    OkBtn: TBitBtn;
    CancelBtn: TBitBtn;
    OpenPictureDialog1: TOpenPictureDialog;
    TrayIcon: TTrayIcon;
    PopupMenu1: TPopupMenu;
    N11: TMenuItem;
    N21: TMenuItem;
    N1: TMenuItem;
    N31: TMenuItem;
    N2: TMenuItem;
    N12: TMenuItem;
    N22: TMenuItem;
    N3: TMenuItem;
    ImageList1: TImageList;
    procedure BrowseBtnClick(Sender: TObject);
    procedure ClearBtnClick(Sender: TObject);
    procedure TipEdtChange(Sender: TObject);
    procedure VisibleCbxClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure N31Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N12Click(Sender: TObject);
    procedure N22Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure TrayIconDblClick(Button: TMouseButton);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TTrayIconEditor = class ( TComponentEditor )
    function GetVerbCount : Integer; override;
    function GetVerb ( Index : Integer ) : String; override;
    procedure ExecuteVerb ( Index : Integer ); override;
  end;

var
  TrayIconEditDialog: TTrayIconEditDialog;

procedure Register;

implementation

{$R *.DFM}

procedure TTrayIconEditDialog.BrowseBtnClick(Sender: TObject);
begin
  // Изменение иконки
  if OpenPictureDialog1.Execute then
  begin
    IconImg.Picture.LoadFromFile(OpenPictureDialog1.FileName);
    TrayIcon.Icon := IconImg.Picture.Icon;
  end;
end;

procedure TTrayIconEditDialog.ClearBtnClick(Sender: TObject);
begin
  IconImg.Picture.Assign(nil);
  TrayIcon.Icon := nil;
end;

procedure TTrayIconEditDialog.TipEdtChange(Sender: TObject);
begin
  TrayIcon.Tip := TipEdt.Text;
end;

procedure TTrayIconEditDialog.VisibleCbxClick(Sender: TObject);
begin
  TrayIcon.Visible := VisibleCbx.Checked;
end;

procedure TTrayIconEditDialog.FormShow(Sender: TObject);
begin
  // Обновить поля окна.
  IconImg.Picture.Assign(TrayIcon.Icon);
  TipEdt.Text := TrayIcon.Tip;
  VisibleCbx.Checked := TrayIcon.Visible;
end;

  //////////////////////////////////////////////////////
 // TTrayIconEditor
//////////////////////////////////////////////////////
function TTrayIconEditor.GetVerbCount : Integer;
begin
  Result := 1;
end;

function TTrayIconEditor.GetVerb( Index : Integer ): String;
begin
  case Index of
    0: Result := 'Edit &TrayIcon...';
  end;
end;

procedure TTrayIconEditor.ExecuteVerb( Index : Integer);
Var Dialog: TTrayIconEditDialog;
  procedure CopyTrayIcon( Dest, Source : TTrayIcon);
  begin
    Dest.Icon := Source.Icon;
    Dest.Tip := Source.Tip;
    Dest.Visible := Source.Visible;
  end;

begin
  case Index of
  0:
    begin
      Dialog := TTrayIconEditDialog.Create(Application);
      try
        //Копирование атрибутов в компонент диалогового окна
        CopyTrayIcon( Dialog.TrayIcon, Component as TTrayIcon );
        Dialog.Caption := Component.Owner.Name + '.' +
                          Component.Name + Dialog.Caption;
        if Dialog.ShowModal = mrOK then // Отображение окна
        begin
          CopyTrayIcon( Component as TTrayIcon, Dialog.TrayIcon);
          Designer.Modified;
        end;
      finally
        Dialog.Free;
      end;
    end;
  end;
end;

  //////////////////////////////////////////////////////
 // Функция регистрации компонентов
//////////////////////////////////////////////////////

procedure Register;
begin
  RegisterComponentEditor(TTrayIcon,TTrayIconEditor);
end;

procedure TTrayIconEditDialog.N11Click(Sender: TObject);
begin
  MessageBox(Handle,'Выбрана Позиция 1','TTrayIcon Test',MB_OK);
end;

procedure TTrayIconEditDialog.N31Click(Sender: TObject);
begin
  MessageBox(Handle,'Выбрана Позиция 3','TTrayIcon Test',MB_OK);
end;

procedure TTrayIconEditDialog.N2Click(Sender: TObject);
begin
  MessageBox(Handle,'To be continued...','TTrayIcon Test',MB_OK);
end;

procedure TTrayIconEditDialog.N12Click(Sender: TObject);
begin
  MessageBox(Handle,'Выбрана Опция 1','TTrayIcon Test',MB_OK);
end;

procedure TTrayIconEditDialog.N22Click(Sender: TObject);
begin
  MessageBox(Handle,'Выбрана Опция 2','TTrayIcon Test',MB_OK);
end;

procedure TTrayIconEditDialog.N3Click(Sender: TObject);
begin
  MessageBox(Handle,'Выбраны ВСЕ остальные опции! :)','TTrayIcon Test',MB_OK);
end;

procedure TTrayIconEditDialog.TrayIconDblClick(Button: TMouseButton);
begin
  MessageBox(Handle,'ЭТО был двойной целчёк! :)','TTrayIcon Test',MB_OK or MB_ICONWARNING);
end;

end.
