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

📄 jvthreaddialog.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: JvThreadDialog.PAS, released on 2004-12-06.

The Initial Developer of the Original Code is Jens Fudickar [jens dott fudickar att oratool dott de]
All Rights Reserved.

Contributor(s): Jens Fudickar [jens dott fudickar att oratool dott de].

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:
-----------------------------------------------------------------------------}
// $Id: JvThreadDialog.pas,v 1.11 2005/02/17 10:20:57 marquardt Exp $

unit JvThreadDialog;

{$I jvcl.inc}

interface

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  SysUtils, Classes, Forms, ExtCtrls, Buttons, StdCtrls,
  {$IFDEF MSWINDOWS}
  Windows, Controls, ComCtrls,
  {$ENDIF MSWINDOWS}
  {$IFDEF UNIX}
  QWindows, QControls,
  {$ENDIF UNIX}
  JvTypes, JvComponent;

type
  TJvCustomThreadDialog = class;

  TJvThreadBaseDialogOptions = class(TPersistent)
  private
    FEnableCancelButton: Boolean;
    FShowDialog: Boolean;
    FShowModal: Boolean;
    FShowCancelButton: Boolean;
    FShowElapsedTime: Boolean;
    FInfoText: string;
    FCaption: string;
    FCancelButtonCaption: string;
    FOwner: TJvCustomThreadDialog;
  protected
    procedure SetEnableCancelButton(Value: Boolean);
    procedure SetShowDialog(Value: Boolean);
    procedure SetShowModal(Value: Boolean);
    procedure SetShowCancelButton(Value: Boolean);
    procedure SetShowElapsedTime(Value: Boolean);
    procedure SetInfoText(Value: string);
    procedure SetCaption(Value: string);
    procedure SetCancelButtonCaption(Value: string);
  public
    constructor Create(AOwner: TJvCustomThreadDialog); virtual;
  published
    property EnableCancelButton: Boolean read FEnableCancelButton write SetEnableCancelButton default True;
    property ShowDialog: Boolean read FShowDialog write SetShowDialog default False;
    property ShowModal: Boolean read FShowModal write SetShowModal default True;
    property ShowCancelButton: Boolean read FShowCancelButton write SetShowCancelButton default True;
    property ShowElapsedTime: Boolean read FShowElapsedTime write SetShowElapsedTime default True;
    property InfoText: string read FInfoText write SetInfoText;
    property Caption: string read FCaption write SetCaption;
    property CancelButtonCaption: string read FCancelButtonCaption write SetCancelButtonCaption;
  end;

  TJvCustomThreadDialogForm = class(TForm)
  private
    FConnectedThread: TComponent;
  protected
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure SetConnectedThread(Value: TComponent);
  public
    property ConnectedThread: TComponent read FConnectedThread write SetConnectedThread;
  end;

  TJvCustomThreadDialog = class(TJvComponent)
  private
    FDialogOptions: TJvThreadBaseDialogOptions;
    FThreadStatusDialog: TJvCustomThreadDialogForm;
  protected
    function CreateDialogOptions: TJvThreadBaseDialogOptions; virtual; abstract;
    procedure TransferThreadDialogOptions; virtual;
    property ThreadStatusDialog: TJvCustomThreadDialogForm read FThreadStatusDialog write FThreadStatusDialog;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
    destructor Destroy; override;
    procedure CloseThreadDialogForm;
    function CreateThreadDialogForm(ConnectedThread: TComponent): TJvCustomThreadDialogForm; virtual; abstract;
  published
    property DialogOptions: TJvThreadBaseDialogOptions read FDialogOptions write FDialogOptions;
  end;

  TJvThreadSimpleDialog = class(TJvCustomThreadDialog)
  private
    FCancelButtonPanel: TPanel;
    FCancelBtn: TButton;
    FInfoTextPanel: TPanel;
    FInfoText: TStaticText;
    FTimeTextPanel: TPanel;
    FTimeText: TStaticText;
    FMainTimer: TTimer;
    FCounter: Integer;
    FStartTime: TDateTime;
  protected
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CancelBtnClick(Sender: TObject);
    procedure MainTimerTimer(Sender: TObject);
    procedure SetFormData;
    procedure SetFormHeightWidth;
    procedure TransferThreadDialogOptions; override;
    function CreateDialogOptions: TJvThreadBaseDialogOptions; override;
  public
    function CreateThreadDialogForm(ConnectedThread: TComponent): TJvCustomThreadDialogForm; override;
  end;

  TJvThreadAnimateDialogOptions = class(TJvThreadBaseDialogOptions)
  private
    FCommonAVI: TCommonAVI;
    FFileName: string;
  published
    property CommonAVI: TCommonAVI read FCommonAVI write FCommonAVI;
    property FileName: string read FFileName write FFileName;
  end;

  TJvThreadAnimateDialog = class(TJvCustomThreadDialog)
  private
    FCancelButtonPanel: TPanel;
    FCancelBtn: TButton;
    FAnimatePanel: TPanel;
    FAnimate: TAnimate;
    FInfoTextPanel: TPanel;
    FInfoText: TStaticText;
    FTimeTextPanel: TPanel;
    FTimeText: TStaticText;
    FMainTimer: TTimer;
    FCounter: Integer;
    FStartTime: TDateTime;
  protected
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CancelBtnClick(Sender: TObject);
    procedure MainTimerTimer(Sender: TObject);
    procedure SetFormData;
    procedure SetFormHeightWidth;
    procedure TransferThreadDialogOptions; override;
    function GetDialogOptions: TJvThreadAnimateDialogOptions;
    function CreateDialogOptions: TJvThreadBaseDialogOptions; override;
  public
    function CreateThreadDialogForm(ConnectedThread: TComponent): TJvCustomThreadDialogForm; override;
  published
    //property DialogOptions: TJvThreadAnimateDialogOptions read GetDialogOptions;
  end;

{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvThreadDialog.pas,v $';
    Revision: '$Revision: 1.11 $';
    Date: '$Date: 2005/02/17 10:20:57 $';
    LogPath: 'JVCL\run'
    );
{$ENDIF UNITVERSIONING}

implementation

uses
  Dialogs,
  JvThread, JvResources;

function JvThreadComp(AComp: TComponent): TJvThread;
begin
  if AComp is TJvThread then
    Result := TJvThread(AComp)
  else
    Result := nil;
end;

//=== { TJvThreadBaseDialogOptions } =========================================

constructor TJvThreadBaseDialogOptions.Create(AOwner: TJvCustomThreadDialog);
begin
  inherited Create;
  FOwner := AOwner;
  FEnableCancelButton := True;
  FShowDialog := False;
  FShowModal := True;
  FShowCancelButton := True;
  FShowElapsedTime := True;
  FCancelButtonCaption := RsButtonCancelCaption;
end;

procedure TJvThreadBaseDialogOptions.SetEnableCancelButton(Value: Boolean);
begin
  FEnableCancelButton := Value;
  if Assigned(FOwner) then
    FOwner.TransferThreadDialogOptions;
end;

procedure TJvThreadBaseDialogOptions.SetShowDialog(Value: Boolean);
begin
  FShowDialog := Value;
end;

procedure TJvThreadBaseDialogOptions.SetShowModal(Value: Boolean);
begin
  FShowModal := Value;
end;

procedure TJvThreadBaseDialogOptions.SetShowCancelButton(Value: Boolean);
begin
  FShowCancelButton := Value;
  if Assigned(FOwner) then
    FOwner.TransferThreadDialogOptions;
end;

procedure TJvThreadBaseDialogOptions.SetShowElapsedTime(Value: Boolean);
begin
  FShowElapsedTime := Value;
  if Assigned(FOwner) then
    FOwner.TransferThreadDialogOptions;
end;

procedure TJvThreadBaseDialogOptions.SetInfoText(Value: string);
begin
  FInfoText := Value;
  if Assigned(FOwner) then
    FOwner.TransferThreadDialogOptions;
end;

procedure TJvThreadBaseDialogOptions.SetCaption(Value: string);
begin
  FCaption := Value;
  if Assigned(FOwner) then
    FOwner.TransferThreadDialogOptions;
end;

procedure TJvThreadBaseDialogOptions.SetCancelButtonCaption(Value: string);
begin
  FCancelButtonCaption := Value;
  if Assigned(FOwner) then
    FOwner.TransferThreadDialogOptions;
end;

//=== { TJvCustomThreadDialog } ==============================================

procedure TJvCustomThreadDialogForm.SetConnectedThread(Value: TComponent);
begin
  if not (Value is TJvThread) then
    raise EJVCLException.CreateRes(@RsENotATJvThread);
  FConnectedThread := Value;
end;

procedure TJvCustomThreadDialogForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := JvThreadComp(FConnectedThread).Terminated;
end;

//=== { TJvCustomThreadDialog } ==============================================

constructor TJvCustomThreadDialog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDialogOptions := CreateDialogOptions;
end;

destructor TJvCustomThreadDialog.Destroy;
begin
  FDialogOptions.Free;
  inherited Destroy;
end;

procedure TJvCustomThreadDialog.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if Operation = opRemove then
    if AComponent = FThreadStatusDialog then
      FThreadStatusDialog := nil;
end;

procedure TJvCustomThreadDialog.TransferThreadDialogOptions;
begin
end;

procedure TJvCustomThreadDialog.CloseThreadDialogForm;
begin
  if Assigned(FThreadStatusDialog) and not (csDestroying in ComponentState) then
  begin
    FThreadStatusDialog.Close;
    Application.HandleMessage;
  end;
end;

//=== { TJvThreadSimpleDialog } ==============================================

function TJvThreadSimpleDialog.CreateDialogOptions: TJvThreadBaseDialogOptions;
begin
  Result := TJvThreadBaseDialogOptions.Create(Self);
end;

function TJvThreadSimpleDialog.CreateThreadDialogForm(ConnectedThread: TComponent): TJvCustomThreadDialogForm;
begin
  Result := nil;
  if DialogOptions.ShowDialog then
  begin
    ThreadStatusDialog := TJvCustomThreadDialogForm.CreateNew(Self);
    ThreadStatusDialog.ConnectedThread := ConnectedThread;
    Result := ThreadStatusDialog;
    FCancelButtonPanel := TPanel.Create(ThreadStatusDialog);
    FCancelBtn := TBitBtn.Create(ThreadStatusDialog);
    FInfoTextPanel := TPanel.Create(ThreadStatusDialog);
    FInfoText := TStaticText.Create(ThreadStatusDialog);
    FTimeTextPanel := TPanel.Create(ThreadStatusDialog);
    FTimeText := TStaticText.Create(ThreadStatusDialog);
    FMainTimer := TTimer.Create(ThreadStatusDialog);
    with ThreadStatusDialog do
    begin
      BorderIcons := [];
      BorderStyle := bsDialog;
      Caption := ' ';
      ClientHeight := 88;
      ClientWidth := 268;
      FormStyle := fsStayOnTop;
      OldCreateOrder := False;
      Position := poScreenCenter;
      OnClose := FormClose;
      OnCloseQuery := FormCloseQuery;
      OnShow := FormShow;
      PixelsPerInch := 96;
    end;
    with FInfoTextPanel do
    begin
      Top := 0;
      Caption := '';
      Parent := FThreadStatusDialog;
      Align := alTop;
      BevelOuter := bvNone;
      BorderWidth := 3;
    end;
    with FInfoText do
    begin
      Parent := FInfoTextPanel;
      Height := 22;
      FInfoTextPanel.Height := FInfoText.Height + 6;
      Align := alClient;
      AutoSize := False;
      {$IFDEF COMPILER6_UP}
      BevelInner := bvNone;
      BevelOuter := bvNone;
      {$ENDIF COMPILER6_UP}
      ParentFont := False;
    end;
    with FTimeTextPanel do
    begin
      Top := FInfoTextPanel.Top + FInfoTextPanel.Height + 1;
      Parent := ThreadStatusDialog;
      Align := alTop;
      BevelOuter := bvNone;

⌨️ 快捷键说明

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