⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvtimerlistform.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvTimLstEd.PAS, released on 2002-07-04.

The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.

Last Modified: 2002-07-04

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}

{$I JVCL.INC}

unit JvTimerListForm;

interface

uses
  Windows,
  SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, ExtCtrls, Grids, Menus,
  {$IFDEF COMPILER6_UP}
  RTLConsts, DesignIntf, DesignEditors, DesignWindows, VCLEditors,
  {$ELSE}
  LibIntf, DsgnIntf, DsgnWnds,
  {$ENDIF}
  JvJVCLUtils, JvFormPlacement, JvTimerList, JvComponent;

type
  TJvTimerItemsEditor = class(TDesignWindow)
    BtnPanel: TPanel;
    ClientPanel: TPanel;
    NewBtn: TButton;
    DeleteBtn: TButton;
    DrawGrid: TDrawGrid;
    PopupMenu: TPopupMenu;
    CutMenu: TMenuItem;
    CopyMenu: TMenuItem;
    PasteMenu: TMenuItem;
    FormStorage: TJvFormStorage;
    DeleteMenu: TMenuItem;
    N1: TMenuItem;
    NewMenu: TMenuItem;
    ClearBtn: TButton;
    Panel1: TPanel;
    CloseBtn: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DrawGridDrawCell(Sender: TObject; Col, Row: Longint;
      Rect: TRect; State: TGridDrawState);
    procedure DrawGridSelectCell(Sender: TObject; Col, Row: Longint;
      var CanSelect: Boolean);
    procedure CloseBtnClick(Sender: TObject);
    procedure DeleteClick(Sender: TObject);
    procedure DrawGridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormResize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure NewClick(Sender: TObject);
    procedure CutClick(Sender: TObject);
    procedure CopyClick(Sender: TObject);
    procedure PasteClick(Sender: TObject);
    procedure ClearBtnClick(Sender: TObject);
  private
    FTimersCollection: TJvTimerList;
    function GetForm: TCustomForm;
    function CheckCollection: Boolean;
    function ItemByRow(Row: Integer): TJvTimerEvent;
    procedure SelectItem(Item: TJvTimerEvent);
    procedure UpdateData;
    procedure SetTimersCollection(Value: TJvTimerList);
    procedure Copy;
    procedure Cut;
    procedure Paste;
  protected
    function UniqueName(Component: TComponent): string; override;
    procedure Activated; override;
  public
    {$IFDEF COMPILER6_UP}
    function EditAction(Action: TEditAction): Boolean; override;
    procedure ItemsModified(const Designer: IDesigner); override;
    procedure DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean); override;
    {$ELSE}
    procedure EditAction(Action: TEditAction); override;
    procedure FormModified; override;
    procedure FormClosed(Form: TCustomForm); override;
    {$ENDIF}
    function GetEditState: TEditState; override;
    {$IFDEF COMPILER6_UP}
    procedure ItemDeleted(const ADesigner: IDesigner; Item: TPersistent); override;
    {$ELSE}
    procedure ComponentDeleted(Component: IPersistent); override;
    {$ENDIF}
    property TimersCollection: TJvTimerList read FTimersCollection
      write SetTimersCollection;
    property OwnerForm: TCustomForm read GetForm;
  end;

  TJvTimersItemListProperty = class(TPropertyEditor)
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
    procedure Edit; override;
  end;

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

implementation

uses
  Consts,
  JvConsts, JvTypes, JvxDConst;

{$R *.DFM}

{$D-}

{$IFDEF COMPILER6_UP}
type
  TDesigner = DesignIntf.IDesigner;
  TFormDesigner = DesignIntf.IDesigner;
{$ELSE}
type
  TDesigner = IDesigner;
  TFormDesigner = IFormDesigner;
{$ENDIF}

function FindEditor(ATimersCollection: TJvTimerList): TJvTimerItemsEditor;
var
  I: Integer;
begin
  Result := nil;
  for I := 0 to Screen.FormCount - 1 do
    if Screen.Forms[I] is TJvTimerItemsEditor then
      if TJvTimerItemsEditor(Screen.Forms[I]).TimersCollection = ATimersCollection then
      begin
        Result := TJvTimerItemsEditor(Screen.Forms[I]);
        Break;
      end;
end;

procedure ShowItemsEditor(Designer: TDesigner;
  ATimersCollection: TJvTimerList);
var
  Editor: TJvTimerItemsEditor;
begin
  if ATimersCollection = nil then
    Exit;
  Editor := FindEditor(ATimersCollection);
  if Editor = nil then
  begin
    Editor := TJvTimerItemsEditor.Create(Application);
    try
      Editor.Designer := TFormDesigner(Designer);
      Editor.TimersCollection := ATimersCollection;
      Editor.Show;
    except
      Editor.Free;
      raise;
    end;
  end
  else
  begin
    Editor.Show;
    if Editor.WindowState = wsMinimized then
      Editor.WindowState := wsNormal;
  end;
end;

//=== TJvTimersItemListProperty ==============================================

function TJvTimersItemListProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paReadOnly];
end;

function TJvTimersItemListProperty.GetValue: string;
var
  List: TList;
begin
  List := TList(Pointer(GetOrdValue));
  if (List = nil) or (List.Count = 0) then
    Result := srNone
  else
    FmtStr(Result, '(%s)', [GetPropType^.Name]);
end;

procedure TJvTimersItemListProperty.Edit;
begin
  ShowItemsEditor(Designer, TJvTimerList(GetComponent(0)));
end;

//=== TJvTimersCollectionEditor ==============================================

procedure TJvTimersCollectionEditor.ExecuteVerb(Index: Integer);
begin
  case Index of
    0:
      ShowItemsEditor(Designer, TJvTimerList(Component));
  end;
end;

function TJvTimersCollectionEditor.GetVerb(Index: Integer): string;
begin
  case Index of
    0:
      Result := srTimerDesigner;
  end;
end;

function TJvTimersCollectionEditor.GetVerbCount: Integer;
begin
  Result := 1;
end;

//=== TJvTimerItemsEditor ====================================================

procedure TJvTimerItemsEditor.SetTimersCollection(Value: TJvTimerList);
begin
  if FTimersCollection <> Value then
  begin
    FTimersCollection := Value;
    UpdateData;
  end;
end;

function TJvTimerItemsEditor.UniqueName(Component: TComponent): string;
var
  Temp: string;
begin
  if Component <> nil then
    Temp := Component.ClassName
  else
    Temp := TJvTimerEvent.ClassName;
  if (UpCase(Temp[1]) = 'T') and (Length(Temp) > 1) then
    System.Delete(Temp, 1, 1);
  Result := Designer.UniqueName(Temp);
end;

function TJvTimerItemsEditor.GetEditState: TEditState;
begin
  Result := [];
  if DeleteBtn.Enabled then
    Result := [esCanDelete, esCanCut, esCanCopy];
  if ClipboardComponents then
    Include(Result, esCanPaste);
end;

{$IFDEF COMPILER6_UP}
procedure TJvTimerItemsEditor.DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean);
{$ELSE}
procedure TJvTimerItemsEditor.FormClosed(Form: TCustomForm);
{$ENDIF}
begin
  if {$IFDEF COMPILER6_UP} ADesigner.Root {$ELSE} Form {$ENDIF} = OwnerForm then
    Free;
end;

{$IFDEF COMPILER6_UP}
procedure TJvTimerItemsEditor.ItemsModified(const Designer: IDesigner);
{$ELSE}
procedure TJvTimerItemsEditor.FormModified;
{$ENDIF}
begin
  if not (csDestroying in ComponentState) then
    UpdateData;
end;

procedure TJvTimerItemsEditor.Activated;
begin
  SelectItem(ItemByRow(DrawGrid.Row - 1));
end;

procedure TJvTimerItemsEditor.UpdateData;
var
  Empty: Boolean;
begin
  if CheckCollection then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -