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

📄 jvgreport.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{-----------------------------------------------------------------------------
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: JvgReport.PAS, released on 2003-01-15.

The Initial Developer of the Original Code is Andrey V. Chudin,  [chudin att yandex dott ru]
Portions created by Andrey V. Chudin are Copyright (C) 2003 Andrey V. Chudin.
All Rights Reserved.

Contributor(s):
Michael Beck [mbeck att bigfoot dott com].

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: JvgReport.pas,v 1.36 2005/02/17 10:21:21 marquardt Exp $

unit JvgReport;

{$I jvcl.inc}

interface

uses
  {$IFDEF USEJVCL}
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  {$ENDIF USEJVCL}
  Windows, Messages, Classes, Controls, Graphics,
  Forms, OleCtnrs, ExtCtrls, SysUtils, Printers,
  {$IFDEF USEJVCL}
  JvComponent,
  {$ENDIF USEJVCL}
  JvgUtils, JvgTypes, JvgCommClasses;

type
  TJvgReport = class;

  TJvgReportParamKind = (gptUnknown, gptEdit, gptRadio, gptCheck);

  TJvgReportScrollBox = class(TScrollBox)
  private
    FGridImage: TBitmap;
    FOnDraw: TNotifyEvent;
    procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property OnDraw: TNotifyEvent read FOnDraw write FOnDraw;
  end;

  {$IFDEF USEJVCL}
  TJvgReportItem = class(TJvGraphicControl)
  {$ELSE}
  TJvgReportItem = class(TGraphicControl)
  {$ENDIF USEJVCL}
  private
    FSelected: Boolean;
    FBkColor: Integer;
    FBvColor: Integer;
    FTransparent: Integer;
    FAlignment: Word; //..1-left,2-right,3-center,4-boadwise
    FSideLeft, FSideTop, FSideRight, FSideBottom: Word;
    FPenStyle: Integer;
    FPenWidth: Word;
    FText: string;
    PrintText: string;
    FCompName: string;
    FFName: string;
    FFSize, FFColor, FFStyle: Integer;
    FContainOLE: Boolean;
    FFixed: Word;
    FOLELinkToFile: string;
    FOLESizeMode: Word;
    //    fRepaintOnlyBorder,
    fSizing: Boolean;
    R: array [1..8] of TRect;
    DownPos: TPoint;
    SizeDirection: Integer;
    FExternalCanvas: TCanvas;
    Cursors: array [1..8] of TCursor;
    Bmp: TBitmap;
    Report: TJvgReport;
    procedure SetSelected(Value: Boolean);
    procedure SetBkColor(Value: Integer);
    procedure SetBvColor(Value: Integer);
    procedure SetTransparent(Value: Integer);
    procedure SetAlignment(Value: Word);
    procedure SetSideLeft(Value: Word);
    procedure SetSideTop(Value: Word);
    procedure SetSideRight(Value: Word);
    procedure SetSideBottom(Value: Word);
    procedure SetPenStyle(Value: Integer);
    procedure SetPenWidth(Value: Word);
    procedure SetText(const Value: string);
    procedure SetFName(const Value: string);
    procedure SetFSize(Value: Integer);
    procedure SetFColor(Value: Integer);
    procedure SetFStyle(Value: Integer);
    procedure SetContainOLE(Value: Boolean);
    procedure SetOLELinkToFile(const Value: string);
    procedure SetOLESizeMode(Value: Word);
    procedure SetFixed(Value: Word);
    function IsContainOLE: Boolean;
    procedure WMMouseMove(var Msg: TWMMouse); message WM_MOUSEMOVE;
    procedure WMLMouseDown(var Msg: TWMMouse); message WM_LBUTTONDOWN;
    procedure WMLMouseUp(var Msg: TWMMouse); message WM_LBUTTONUP;
    procedure WMSize(var Msg: TWMSize); message WM_SIZE;
  {$IFDEF USEJVCL}
  protected
    procedure MouseEnter(Control: TControl); override;
    procedure MouseLeave(Control: TControl); override;
    procedure FontChanged; override;
  {$ELSE}
    procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
    procedure CMFontChanged(var Msg: TMessage); message CM_FONTCHANGED;
  protected
    procedure MouseEnter(Control: TControl); dynamic;
    procedure MouseLeave(Control: TControl); dynamic;
    procedure FontChanged; dynamic;
  {$ENDIF USEJVCL}
  public
    procedure Paint; override;
    procedure PaintTo(Canvas: TCanvas);
  protected
    procedure SetParent(Value: TWinControl); override;
  public
    ResText: string;
    OLEContainer: TOLEContainer;
    property Selected: Boolean read FSelected write SetSelected default False;
    property Visible;
    property OnClick;
    property OnDblClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    //    property OnResize;
    property ExternalCanvas: TCanvas read FExternalCanvas write FExternalCanvas;
    //    procedure RepaintBorder;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property BkColor: Integer read FBkColor write SetBkColor default clWhite;
    property BvColor: Integer read FBvColor write SetBvColor default clBlack;
    property Transparent: Integer read FTransparent write SetTransparent default 0;
    property Alignment: Word read FAlignment write SetAlignment default 1;
    property SideLeft: Word read FSideLeft write SetSideLeft default 1;
    property SideTop: Word read FSideTop write SetSideTop default 1;
    property SideRight: Word read FSideRight write SetSideRight default 1;
    property SideBottom: Word read FSideBottom write SetSideBottom default 1;
    property PenStyle: Integer read FPenStyle write SetPenStyle default Integer(psSolid);
    property PenWidth: Word read FPenWidth write SetPenWidth default 1;
    property Text: string read FText write SetText;
    property CompName: string read FCompName write FCompName;
    property FName: string read FFName write SetFName;
    property FSize: Integer read FFSize write SetFSize;
    property FColor: Integer read FFColor write SetFColor;
    property FStyle: Integer read FFStyle write SetFStyle;
    property ContainOLE: Boolean read FContainOLE write SetContainOLE default False;
    property OLELinkToFile: string read FOLELinkToFile write SetOLELinkToFile stored IsContainOLE;
    property OLESizeMode: Word read FOLESizeMode write SetOLESizeMode stored IsContainOLE default 2;
    property Fixed: Word read FFixed write SetFixed default 0;
  end;

  TJvgReportBeforePrintEvent = procedure(Sender: TJvgReport) of object;

  {$IFDEF USEJVCL}
  TJvgReport = class(TJvComponent)
  {$ELSE}
  TJvgReport = class(TComponent)
  {$ENDIF USEJVCL}
  private
    procedure ValidateWnds;
    function GetReportText: TStringList;
    procedure SetReportText(Value: TStringList);
  public
    OwnerWnd, ParentWnd: TWinControl;
    ParamNames: TStringList;
    ParamValues: TStringList;
    ParamMasks: TStringList;
    ParamTypes: TList;
    FReportList: TStringList;
    ComponentList: TList;
    FBeforePrint: TJvgReportBeforePrintEvent;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Save;
    procedure LoadFromFile(const FileName: string);
    procedure SaveToFile(const FileName: string);
    procedure PaintTo(Canvas: TCanvas);
    procedure PreviewTo(Window: TWinControl);
    procedure Print;
    procedure CreateReport(ParentWnd: TWinControl; fNeedClearOwner: Boolean);
    function SetParam(const sParamName, sParamValue: string): Boolean;
    function GetParam(const sParamName: string; var sParamValue: string): Boolean;
    function AddComponent: TJvgReportItem;
    procedure AnalyzeParams(Item: TJvgReportItem; const DefName: string);
  private
    procedure SetUnicalName(laBevel: TJvgReportItem);
  protected
    procedure Loaded; override;
    procedure ClearReport;
  published
    property Report: TStringList read FReportList;
    property ReportText: TStringList read GetReportText write SetReportText;
    property BeforePrint: TJvgReportBeforePrintEvent read FBeforePrint write FBeforePrint;
  end;

{$IFDEF USEJVCL}
{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvgReport.pas,v $';
    Revision: '$Revision: 1.36 $';
    Date: '$Date: 2005/02/17 10:21:21 $';
    LogPath: 'JVCL\run'
  );
{$ENDIF UNITVERSIONING}
{$ENDIF USEJVCL}

implementation

uses
  {$IFDEF USEJVCL}
  Math,
  JvResources, JvConsts;
  {$ELSE}
  Math;
  {$ENDIF USEJVCL}

const
  S = 2;
  DS = 2 * S + 1;

{$IFNDEF USEJVCL}
resourcestring
  RsOLELinkedObjectNotFound = 'OLE: Linked object not found.';
  RsErrorText = 'Error';
  RsErrorReadingComponent = 'Error reading component.';
{$ENDIF !USEJVCL}

//=== { TJvgReportScrollBox } ================================================

constructor TJvgReportScrollBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FGridImage := TBitmap.Create;
  FGridImage.Width := 8;
  FGridImage.Height := 8;
  FGridImage.Canvas.Brush.Color := clWhite; //clWindow;
  FGridImage.Canvas.FillRect(Rect(0, 0, 8, 8));
  FGridImage.Canvas.Pixels[7, 7] := 0;
end;

destructor TJvgReportScrollBox.Destroy;
begin
  FGridImage.Free;
  inherited Destroy;
end;

procedure TJvgReportScrollBox.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
begin
  Msg.Result := 1;
  if csDestroying in ComponentState then
    Exit;
  with TCanvas.Create do
    try
      Handle := Msg.DC;
      //    Pen.Color := clWindow;
      //    Brush.Color := clWindow;
      //    Brush.Style := bsCross;
      Brush.Bitmap := FGridImage;
      FillRect(ClientRect);
      Handle := 0;
    finally
      Free;
    end;
  if Assigned(FOnDraw) then
    FOnDraw(Self);
end;

//=== { TJvgReportItem } =====================================================

constructor TJvgReportItem.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  //..defaults
  Width := 50;
  Height := 50;
  Color := clWhite;
  FBkColor := clWhite;
  FBvColor := clBlack;
  FAlignment := 1;
  FSideLeft := 1;
  FSideTop := 1;
  FSideRight := 1;
  FSideBottom := 1;
  FPenStyle := Integer(psSolid);
  FPenWidth := 1;
  FOLESizeMode := 2;
  Cursors[1] := crSizeNWSE;
  Cursors[2] := crSizeNS;
  Cursors[3] := crSizeNESW;

  Cursors[4] := crSizeNESW;
  Cursors[5] := crSizeNS;
  Cursors[6] := crSizeNWSE;

  Cursors[7] := crSizeWE;
  Cursors[8] := crSizeWE;
  ParentFont := False;
  {$IFDEF GL_RUS}
  Font.CharSet := RUSSIAN_CHARSET;
  {$ENDIF GL_RUS}
  FontChanged;
end;

destructor TJvgReportItem.Destroy;
begin
  if Assigned(Bmp) then
    Bmp.Free;
  if Assigned(OLEContainer) then
  begin
    OLEContainer.DestroyObject;
    if not (csDestroying in ComponentState) then
    begin
      OLEContainer.Free;
      OLEContainer := nil;
    end;
  end;
  inherited;
end;

{procedure TJvgReportItem.RepaintBorder;
var
  R: TRect;
begin
  R := ClientRect;
  OffsetRect( R, Left, Top );
  InvalidateRect( Parent.Handle, @R, False );
  InflateRect( R, -DS, -DS );
//  ValidateRect( Parent.Handle, @R );
  fRepaintOnlyBorder := True;
  Paint;
  //fRepaintOnlyBorder := False;
end;
}

procedure TJvgReportItem.Paint;
begin
  PaintTo(Canvas);
end;

procedure TJvgReportItem.PaintTo(Canvas: TCanvas);
const
  Alignments: array[1..4] of TglAlignment = (ftaLeftJustify,
    ftaRightJustify, ftaCenter, ftaBroadwise);
  //  SysAlignments: array[TglAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER, 0);
var
  I, L, T: Integer;
  sPrintText: string;
  R_, Client_Rect, RCalc: TRect;
begin
  FFColor := 0;
  with Canvas do
  begin

    if Canvas = Self.Canvas then
      Client_Rect := Rect(0, 0, Width, Height)
    else
    begin
      Client_Rect := Bounds(Left, Top, Width, Height);
      Canvas.Font := Self.Canvas.Font;
      Canvas.Font.Color := 0;
    end;
    R_ := Client_Rect;
    L := Client_Rect.Left;
    T := Client_Rect.Top;
    InflateRect(R_, -DS, -S);
    RCalc := R_;

    if Transparent = 0 then
    begin
      Brush.Color := BkColor;
      FillRect(Client_Rect);
    end;

    if Canvas = Self.Canvas then
    begin
      Pen.Style := psDot;
      Pen.Width := 1;
      Pen.Color := clSilver;
      Brush.Style := bsClear;
      Rectangle(L, T, L + Width, T + Height);
      sPrintText := Text;
    end
    else
      sPrintText := PrintText;
    if sPrintText = '' then
      sPrintText := Text;

    Pen.Style := TPenStyle(PenStyle);
    Pen.Width := PenWidth;
    Pen.Color := BvColor;
    if SideLeft <> 0 then
    begin
      MoveTo(L + PenWidth div 2, T + Height - 1);
      LineTo(L + PenWidth div 2, T);
    end;
    if SideTop <> 0 then
    begin
      MoveTo(L + PenWidth div 2, T + PenWidth div 2);
      LineTo(L + Width - PenWidth, T + PenWidth div 2);
    end;
    if SideRight <> 0 then
    begin
      MoveTo(L + Width - 1, T);
      LineTo(L + Width - 1, T + Height - 1);
    end;
    if SideBottom <> 0 then
    begin
      MoveTo(L + Width - 1, T + Height - 1);
      LineTo(L, T + Height - 1);
    end;

    if not ContainOLE then
    begin
      SetBkMode(Canvas.Handle, TRANSPARENT);
      SetTextColor(Canvas.Handle, FColor);
      Windows.DrawText(Canvas.Handle, PChar(sPrintText), Length(sPrintText), RCalc,
        DT_CALCRECT or DT_WordBREAK);
      R_.Top := R_.Top + max(0, (R_.Bottom - R_.Top - (RCalc.Bottom -
        RCalc.Top)) div 2);
      DrawTextExtAligned(Canvas, sPrintText, R_, Alignments[Alignment],
        True);
    end
    else
    if (OLELinkToFile <> '') and (ExtractFileExt(OLELinkToFile) = '.bmp') then
    begin
      if Assigned(OLEContainer) then
        OLEContainer.Visible := False;
      if Bmp = nil then
      begin
        Bmp := TBitmap.Create;
        Bmp.LoadFromFile(OLELinkToFile);
      end;
      BitBlt(Canvas.Handle, L, T, Bmp.Width, Bmp.Height, Bmp.Canvas.Handle,
        0, 0, SRCCOPY);
    end;

    if Selected then
    begin
      Pen.Style := psSolid;
      Pen.Width := 1;
      Pen.Color := 0;
      Brush.Style := bsSolid;
      if Fixed <> 0 then
        Brush.Color := clBtnFace
      else
        Brush.Color := clWhite;
      R[1] := Rect(0, 0, DS, DS); //...top-left
      R[2] := Rect(Width div 2 - S, 0, Width div 2 + S + 1, DS); //...top-center
      R[3] := Rect(Width - DS, 0, Width, DS); //...top-right

      R[4] := Rect(0, Height - DS, DS, Height); //...bottom-left
      R[5] := Rect(Width div 2 - S, Height - DS, Width div 2 + S + 1, Height); //...bottom-center
      R[6] := Rect(Width - DS, Height - DS, Width, Height); //...bottom-right

      R[7] := Rect(0, Height div 2 - S, DS, Height div 2 + S + 1); //...left-center
      R[8] := Rect(Width - DS, Height div 2 - S, Width, Height div 2 + S + 1); //...right-center

      for I := 1 to 8 do
        Rectangle(R[I].Left, R[I].Top, R[I].Right, R[I].Bottom);
    end;
  end;
  if Assigned(OLEContainer) then
    OLEContainer.SetBounds(Left + DS, Top + DS, Width - 2 * DS, Height - 2 *
      DS);
end;

procedure TJvgReportItem.SetParent(Value: TWinControl);
begin

⌨️ 快捷键说明

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