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

📄 pswindow.pas

📁 GREATIS Print Suite Pro for Delphi (3-7,2005,2006,2007) and C++ Builder (3-6) Set of components for
💻 PAS
📖 第 1 页 / 共 2 页
字号:
(*  GREATIS PRINT SUITE                              *)
(*  unit version 1.85.018                            *)
(*  Copyright (C) 2001-2007 Greatis Software         *)
(*  http://www.greatis.com/delphicb/printsuite/      *)
(*  http://www.greatis.com/delphicb/printsuite/faq/  *)
(*  http://www.greatis.com/bteam.html                *)

unit PSWindow;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  PSPreview, PSToolbar, PSStatusBar, PSJob;

type

  TCustomPreviewWindow = class;

  TPreviewForm = class(TCustomForm)
  private
    { Private declarations }
    FPreviewWindow: TCustomPreviewWindow;
    FPreview: TPreview;
    FToolbar: TPreviewToolbar;
    FStatusBar: TPreviewStatusBar;
  protected
    { Protected declarations }
    procedure WndProc(var Msg: TMessage); override;
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  public
    { Public declarations }
    constructor CreateWindow(AOwner: TComponent);
  published
    { Published declarations }
  end;

  TCustomPreviewWindow = class(TComponent)
  private
    { Private declarations }
    FForm: TPreviewForm;
    // main properties
    FPrintJob: TCustomPrintJob;
    // form properties
    FBorderIcons: TBorderIcons;
    FBorderStyle: TFormBorderStyle;
    FCaption: string;
    FCtl3D: Boolean;
    FFont: TFont;
    FIcon: TIcon;
    FPosition: TPosition;
    FWindowState: TWindowState;
    FWindowLeft: Integer;
    FWindowTop: Integer;
    FWindowWidth: Integer;
    FWindowHeight: Integer;
    // preview properties
    FColor: TColor;
    FShadowColor: TColor;
    FShadowSize: Integer;
    FDragScroll: Boolean;
    FScrollTracking: Boolean;
    FViewMode: TViewMode;
    FViewScale: Integer;
    // toolbar properties
    FButtons: TButtons;
    FFlat: Boolean;
    FScaleBox: Boolean;
    FScaleBoxPos: TButtonKind;
    FShowHint: Boolean;
    FUserButtonEnabled: Boolean;
    FUserButtonGlyph: TBitmap;
    FUserButtonHint: string;
    // statusbar properties
    FPagePanelWidth: Integer;
    FPanels: TPanels;
    FScalePanelWidth: Integer;
    FUserText: string;
    FSizeGrip: Boolean;
    // main events
    FOnCreate: TNotifyEvent;
    FOnDestroy: TNotifyEvent;
    FOnShow: TNotifyEvent;
    FOnClose: TNotifyEvent;
    // preview events
    FOnUpdate: TNotifyEvent;
    FOnPageChanged: TNotifyEvent;
    // toolbar event
    FOnUserButtonClick: TNotifyEvent;
    // internal events
    procedure OnCloseForm(Sender: TObject; var Action: TCloseAction);
    // main properties
    procedure SetPrintJob(const Value: TCustomPrintJob);
    // form properties
    procedure SetBorderIcons(const Value: TBorderIcons);
    procedure SetBorderStyle(const Value: TFormBorderStyle);
    procedure SetCaption(const Value: string);
    procedure SetCtl3D(const Value: Boolean);
    procedure SetFont(const Value: TFont);
    procedure SetIcon(const Value: TIcon);
    procedure SetPosition(const Value: TPosition);
    procedure SetWindowState(const Value: TWindowState);
    procedure SetWindowLeft(const Value: Integer);
    procedure SetWindowTop(const Value: Integer);
    procedure SetWindowWidth(const Value: Integer);
    procedure SetWindowHeight(const Value: Integer);
    // preview properties
    procedure SetColor(const Value: TColor);
    procedure SetShadowColor(const Value: TColor);
    procedure SetShadowSize(const Value: Integer);
    procedure SetPageIndex(const Value: Integer);
    function GetPageIndex: Integer;
    procedure SetDragScroll(const Value: Boolean);
    procedure SetScrollTracking(const Value: Boolean);
    procedure SetViewMode(const Value: TViewMode);
    procedure SetViewScale(const Value: Integer);
    // toolbar properties
    procedure SetButtons(const Value: TButtons);
    procedure SetFlat(const Value: Boolean);
    procedure SetScaleBox(const Value: Boolean);
    procedure SetScaleBoxPos(const Value: TButtonKind);
    procedure SetShowHint(const Value: Boolean);
    procedure SetUserButtonEnabled(const Value: Boolean);
    procedure SetUserButtonGlyph(const Value: TBitmap);
    procedure SetUserButtonHint(const Value: string);
    procedure SetOnUserButtonClick(const Value: TNotifyEvent);
    // statusbar properties
    procedure SetPagePanelWidth(const Value: Integer);
    procedure SetPanels(const Value: TPanels);
    procedure SetScalePanelWidth(const Value: Integer);
    procedure SetUserText(const Value: string);
    procedure SetSizeGrip(const Value: Boolean);
    // service methods and properties
    function GetPreview: TPreview;
    function GetToolbar: TPreviewToolbar;
    function GetStatusBar: TPreviewStatusBar;
    property Form: TPreviewForm read FForm write FForm;
    property Preview: TPreview read GetPreview;
    property Toolbar: TPreviewToolbar read GetToolbar;
    property StatusBar: TPreviewStatusBar read GetStatusBar;
    // preview event
    procedure PreviewPageChanged(Sender: TObject);
  protected
    { Protected declarations }
    procedure CopyProperties;
    // main properties
    property PrintJob: TCustomPrintJob read FPrintJob write SetPrintJob;
    // form properties
    property BorderIcons: TBorderIcons read FBorderIcons write SetBorderIcons default [biSystemMenu,biMinimize,biMaximize];
    property BorderStyle: TFormBorderStyle read FBorderStyle write SetBorderStyle default bsSizeable;
    property Caption: string read FCaption write SetCaption;
    property Ctl3D: Boolean read FCtl3D write SetCtl3D default True;
    property Font: TFont read FFont write SetFont;
    property Icon: TIcon read FIcon write SetIcon;
    property Position: TPosition read FPosition write SetPosition default poDesigned;
    property WindowState: TWindowState read FWindowState write SetWindowState default wsNormal;
    property WindowLeft: Integer read FWindowLeft write SetWindowLeft;
    property WindowTop: Integer read FWindowTop write SetWindowTop;
    property WindowWidth: Integer read FWindowWidth write SetWindowWidth;
    property WindowHeight: Integer read FWindowHeight write SetWindowHeight;
    // preview properties
    property Color: TColor read FColor write SetColor default clGray;
    property ShadowColor: TColor read FShadowColor write SetShadowColor default $00404040;
    property ShadowSize: Integer read FShadowSize write SetShadowSize default 8;
    property PageIndex: Integer read GetPageIndex write SetPageIndex default 1;
    property DragScroll: Boolean read FDragScroll write SetDragScroll default True;
    property ScrollTracking: Boolean read FScrollTracking write SetScrollTracking default False;
    property ViewMode: TViewMode read FViewMode write SetViewMode default vmWholePage;
    property ViewScale: Integer read FViewScale write SetViewScale default 0;
    // toolbar properties
    property Buttons: TButtons read FButtons write SetButtons default [btnPrint,btnPrinterSetupDialog,btnFirstPage,btnPrevPage,btnNextPage,btnLastPage,btnZoomOut,btnZoomIn];
    property Flat: Boolean read FFlat write SetFlat default True;
    property ScaleBox: Boolean read FScaleBox write SetScaleBox default True;
    property ScaleBoxPos: TButtonKind read FScaleBoxPos write SetScaleBoxPos default btnZoomOut;
    property ShowHint: Boolean read FShowHint write SetShowHint default True;
    property UserButtonEnabled: Boolean read FUserButtonEnabled write SetUserButtonEnabled default True;
    property UserButtonGlyph: TBitmap read FUserButtonGlyph write SetUserButtonGlyph;
    property UserButtonHint: string read FUserButtonHint write SetUserButtonHint;
    // statusbar properties
    property PagePanelWidth: Integer read FPagePanelWidth write SetPagePanelWidth default 100;
    property Panels: TPanels read FPanels write SetPanels default [pnPage,pnScale];
    property ScalePanelWidth: Integer read FScalePanelWidth write SetScalePanelWidth default 100;
    property UserText: string read FUserText write SetUserText;
    property SizeGrip: Boolean read FSizeGrip write SetSizeGrip default True;
    // main events
    property OnCreate: TNotifyEvent read FOnCreate write FOnCreate;
    property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
    property OnShow: TNotifyEvent read FOnShow write FOnShow;
    property OnClose: TNotifyEvent read FOnClose write FOnClose;
    // preview events
    property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
    property OnPageChanged: TNotifyEvent read FOnPageChanged write FOnPageChanged;
    // toolbar event
    property OnUserButtonClick: TNotifyEvent read FOnUserButtonClick write SetOnUserButtonClick;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Update; virtual;
    procedure Show;
    procedure ShowModal;
    procedure Close;
  end;

  TPreviewWindow = class(TCustomPreviewWindow)
  published
    { Published declarations }
    property PrintJob;
    property BorderIcons;
    property BorderStyle;
    property Caption;
    property Ctl3D;
    property Font;
    property Icon;
    property Position;
    property WindowState;
    property WindowLeft;
    property WindowTop;
    property WindowWidth;
    property WindowHeight;
    property Color;
    property ShadowColor;
    property ShadowSize;
    property PageIndex;
    property DragScroll;
    property ScrollTracking;
    property ViewMode;
    property ViewScale;
    property Buttons;
    property Flat;
    property ScaleBox;
    property ScaleBoxPos;
    property ShowHint;
    property UserButtonEnabled;
    property UserButtonGlyph;
    property UserButtonHint;
    property PagePanelWidth;
    property Panels;
    property ScalePanelWidth;
    property UserText;
    property SizeGrip;
    property OnCreate;
    property OnDestroy;
    property OnShow;
    property OnClose;
    property OnUpdate;
    property OnPageChanged;
    property OnUserButtonClick;
  end;

procedure Register;

implementation

procedure TPreviewForm.WndProc(var Msg: TMessage);
begin
  inherited;
  case Msg.Msg of
    WM_MOVE,WM_SIZE:
    begin
      with FPreviewWindow,Self do
      begin
        FWindowState:=WindowState;
        FWindowWidth:=Width;
        FWindowHeight:=Height;
        FWindowLeft:=Left;
        FWindowTop:=Top;
      end;
    end;
    WM_SHOWWINDOW: Update;
  end;
end;

procedure TPreviewForm.KeyDown(var Key: Word; Shift: TShiftState);
begin
  inherited;
  if Key=VK_ESCAPE then ModalResult:=mrCancel;
end;

constructor TPreviewForm.CreateWindow(AOwner: TComponent);
begin
  CreateNew(AOwner);
  KeyPreview:=True;
  FPreviewWindow:=AOwner as TCustomPreviewWindow;
  FPreview:=TPreview.Create(Self);
  with FPreview do
  begin
    Align:=alClient;
    Parent:=Self;
  end;
  FToolbar:=TPreviewToolbar.Create(Self);
  FToolbar.Preview:=FPreview;
  FToolbar.Parent:=Self;
  FStatusBar:=TPreviewStatusBar.Create(Self);
  FStatusBar.Preview:=FPreview;
  FStatusBar.Parent:=Self;
end;

procedure TCustomPreviewWindow.OnCloseForm(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(FOnClose) then FOnClose(Self);
  FForm.Release;
  FForm:=nil;
end;

procedure TCustomPreviewWindow.SetPrintJob(const Value: TCustomPrintJob);
begin
  if Value<>FPrintJob then
  begin
    FPrintJob:=Value;
    if Assigned(FPrintJob) and
      Assigned(FForm) and
      Assigned(FForm.FPreview) then FForm.FPreview.PrintJob:=FPrintJob;
    Update;
  end;
end;

procedure TCustomPreviewWindow.SetBorderIcons(const Value: TBorderIcons);
begin
  if Value<>FBorderIcons then
  begin
    FBorderIcons:=Value;
    if Assigned(Form) then Form.BorderIcons:=FBorderIcons;
  end;
end;

procedure TCustomPreviewWindow.SetBorderStyle(const Value: TFormBorderStyle);
begin
  if Value<>FBorderStyle then
  begin
    FBorderStyle:=Value;
    if Assigned(Form) then Form.BorderStyle:=FBorderStyle;
  end;
end;

procedure TCustomPreviewWindow.SetCaption(const Value: string);
begin
  if Value<>FCaption then
  begin
    FCaption:=Value;
    if Assigned(Form) then Form.Caption:=FCaption;
  end;
end;

procedure TCustomPreviewWindow.SetCtl3D(const Value: Boolean);
begin
  if Value<>FCtl3D then
  begin
    FCtl3D:=Value;
    if Assigned(Form) then Form.Ctl3D:=FCtl3D;
  end;
end;

procedure TCustomPreviewWindow.SetFont(const Value: TFont);
begin
  FFont.Assign(Value);
  if Assigned(Form) then Form.Font.Assign(FFont);
end;

procedure TCustomPreviewWindow.SetIcon(const Value: TIcon);
begin
  FIcon.Assign(Value);
  if Assigned(Form) then Form.Icon.Assign(FIcon);
end;

procedure TCustomPreviewWindow.SetPosition(const Value: TPosition);
begin
  if Value<>FPosition then
  begin
    FPosition:=Value;
    if Assigned(Form) then Form.Position:=FPosition;
  end;
end;

procedure TCustomPreviewWindow.SetWindowState(const Value: TWindowState);
begin
  if Value<>FWindowState then
  begin
    FWindowState:=Value;
    if Assigned(Form) then Form.WindowState:=FWindowState;
  end;
end;

procedure TCustomPreviewWindow.SetWindowLeft(const Value: Integer);

⌨️ 快捷键说明

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