You've already forked lazarus-ccr
tvplanit: Avoid duplicate last page in print preview of TaskView. Fix display of page count.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8519 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -85,149 +85,147 @@ type
|
||||
PVpPageInfo = ^TVpPageInfo;
|
||||
|
||||
TVpPrintPreview = class(TVpCustomControl)
|
||||
private
|
||||
FBorderStyle: TBorderStyle;
|
||||
FControlLink: TVpControlLink;
|
||||
FDrawingStyle: TVpDrawingStyle;
|
||||
FCurPage: Integer;
|
||||
FPrinter: TPrinter;
|
||||
RenderBmp: TBitmap;
|
||||
WorkBmp: TBitmap;
|
||||
FZoomFactor: TVpPPZoomFactor;
|
||||
FBorderColor: TColor;
|
||||
FOffPageColor: TColor;
|
||||
FPageColor: TColor;
|
||||
FPageInfo: TList;
|
||||
FStartDate: TDateTime;
|
||||
FEndDate: TDateTime;
|
||||
FCurrentFormat: Integer;
|
||||
FNeedHScroll: Boolean;
|
||||
FNeedVScroll: Boolean;
|
||||
FScrollX: Integer;
|
||||
FScrollY: Integer;
|
||||
FOnPageChange: TVpPageChange;
|
||||
FDefaultPopup: TPopupMenu;
|
||||
function GetPageCount: Integer;
|
||||
private
|
||||
FBorderStyle: TBorderStyle;
|
||||
FControlLink: TVpControlLink;
|
||||
FDrawingStyle: TVpDrawingStyle;
|
||||
FCurPage: Integer;
|
||||
FPrinter: TPrinter;
|
||||
RenderBmp: TBitmap;
|
||||
WorkBmp: TBitmap;
|
||||
FZoomFactor: TVpPPZoomFactor;
|
||||
FBorderColor: TColor;
|
||||
FOffPageColor: TColor;
|
||||
FPageColor: TColor;
|
||||
FPageInfo: TList;
|
||||
FStartDate: TDateTime;
|
||||
FEndDate: TDateTime;
|
||||
FCurrentFormat: Integer;
|
||||
FNeedHScroll: Boolean;
|
||||
FNeedVScroll: Boolean;
|
||||
FScrollX: Integer;
|
||||
FScrollY: Integer;
|
||||
FOnPageChange: TVpPageChange;
|
||||
FDefaultPopup: TPopupMenu;
|
||||
function GetPageCount: Integer;
|
||||
|
||||
protected
|
||||
function CalculatePageHeight(Printer: TPrinter): Integer;
|
||||
function CalculatePageWidth(Printer: TPrinter): Integer;
|
||||
procedure ClearPageData;
|
||||
{$IFDEF DELPHI}
|
||||
procedure CMWantSpecialKey(var Msg: TCMWantSpecialKey);
|
||||
message CM_WANTSPECIALKEY;
|
||||
{$ENDIF}
|
||||
procedure CreateParams(var Params: TCreateParams); override;
|
||||
procedure CreateWnd; override;
|
||||
procedure DoScroll(var Msg: {$IFNDEF LCL}TWMSCROLL{$ELSE}TLMScroll{$ENDIF}; BarDirection: Integer);
|
||||
procedure GeneratePageImage;
|
||||
class function GetControlClassDefaultSize: TSize; override;
|
||||
procedure GetLastPage;
|
||||
procedure InitHScrollBar(PageSize, TotalSize: Integer);
|
||||
procedure InitializeDefaultPopup;
|
||||
procedure InitVScrollBar(PageSize, TotalSize: Integer);
|
||||
function IsPageLoaded(PageNum: Integer): Boolean;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure Loaded; override;
|
||||
function LoadPage(PageNum: Integer; StartDate, EndDate: TDateTime): Integer;
|
||||
procedure Paint; override;
|
||||
procedure PopupFirstPage(Sender: TObject);
|
||||
procedure PopupLastPage(Sender: TObject);
|
||||
procedure PopupNextPage(Sender: TObject);
|
||||
procedure PopupPrevPage(Sender: TObject);
|
||||
procedure RemoveHScrollbar;
|
||||
procedure RemoveVScrollbar;
|
||||
procedure SetBorderColor(const v: TColor);
|
||||
procedure SetBorderStyle(const v: TBorderStyle); reintroduce;
|
||||
procedure SetControlLink(const v: TVpControlLink);
|
||||
procedure SetCurPage(const v: Integer);
|
||||
procedure SetDrawingStyle(const v: TVpDrawingStyle);
|
||||
procedure SetEndDate(const v: TDateTime);
|
||||
procedure SetOffPageColor(const v: TColor);
|
||||
procedure SetPageColor(const v: TColor);
|
||||
procedure SetPrinter(const v: TPrinter);
|
||||
procedure SetStartDate(const v: TDateTime);
|
||||
procedure SetScrollBars;
|
||||
procedure SetZoomFactor(const v: TVpPPZoomFactor);
|
||||
protected
|
||||
function CalculatePageHeight(Printer: TPrinter): Integer;
|
||||
function CalculatePageWidth(Printer: TPrinter): Integer;
|
||||
procedure ClearPageData;
|
||||
{$IFDEF DELPHI}
|
||||
procedure CMWantSpecialKey(var Msg: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
|
||||
{$ENDIF}
|
||||
procedure CreateParams(var Params: TCreateParams); override;
|
||||
procedure CreateWnd; override;
|
||||
procedure DoScroll(var Msg: {$IFNDEF LCL}TWMSCROLL{$ELSE}TLMScroll{$ENDIF}; BarDirection: Integer);
|
||||
procedure GeneratePageImage;
|
||||
procedure GeneratePageInfos;
|
||||
class function GetControlClassDefaultSize: TSize; override;
|
||||
procedure InitHScrollBar(PageSize, TotalSize: Integer);
|
||||
procedure InitializeDefaultPopup;
|
||||
procedure InitVScrollBar(PageSize, TotalSize: Integer);
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure Loaded; override;
|
||||
procedure LoadPage(PageNum: Integer; StartDate, EndDate: TDateTime);
|
||||
procedure Paint; override;
|
||||
procedure PopupFirstPage(Sender: TObject);
|
||||
procedure PopupLastPage(Sender: TObject);
|
||||
procedure PopupNextPage(Sender: TObject);
|
||||
procedure PopupPrevPage(Sender: TObject);
|
||||
procedure RemoveHScrollbar;
|
||||
procedure RemoveVScrollbar;
|
||||
procedure SetBorderColor(const v: TColor);
|
||||
procedure SetBorderStyle(const v: TBorderStyle); reintroduce;
|
||||
procedure SetControlLink(const v: TVpControlLink);
|
||||
procedure SetCurPage(const v: Integer);
|
||||
procedure SetDrawingStyle(const v: TVpDrawingStyle);
|
||||
procedure SetEndDate(const v: TDateTime);
|
||||
procedure SetOffPageColor(const v: TColor);
|
||||
procedure SetPageColor(const v: TColor);
|
||||
procedure SetPrinter(const v: TPrinter);
|
||||
procedure SetStartDate(const v: TDateTime);
|
||||
procedure SetScrollBars;
|
||||
procedure SetZoomFactor(const v: TVpPPZoomFactor);
|
||||
|
||||
// procedure VpPrintFormatChanged (var Msg : {$IFNDEF LCL}TMessage{$ELSE}TLMessage{$ENDIF}; message Vp_PrintFormatChanged;
|
||||
{$IFDEF DELPHI}
|
||||
procedure WMEraseBackground(var Msg: TWMERASEBKGND); message WM_ERASEBKGND;
|
||||
procedure WMHScroll(var Msg: TWMSCROLL); message WM_HSCROLL;
|
||||
procedure WMVScroll(var Msg: TWMSCROLL); message WM_VSCROLL;
|
||||
procedure WMRButtonDown(var Msg: TWMRButtonDown); message WM_RBUTTONDOWN;
|
||||
{$ELSE}
|
||||
procedure WMEraseBackground(var Msg: TLMERASEBKGND); message LM_ERASEBKGND;
|
||||
procedure WMHScroll(var Msg: TLMSCROLL); message LM_HSCROLL;
|
||||
procedure WMVScroll(var Msg: TLMSCROLL); message LM_VSCROLL;
|
||||
procedure WMRButtonDown(var Msg: TLMRButtonDown); message LM_RBUTTONDOWN;
|
||||
{$ENDIF}
|
||||
{$IFDEF DELPHI}
|
||||
procedure WMEraseBackground(var Msg: TWMERASEBKGND); message WM_ERASEBKGND;
|
||||
procedure WMHScroll(var Msg: TWMSCROLL); message WM_HSCROLL;
|
||||
procedure WMVScroll(var Msg: TWMSCROLL); message WM_VSCROLL;
|
||||
procedure WMRButtonDown(var Msg: TWMRButtonDown); message WM_RBUTTONDOWN;
|
||||
{$ELSE}
|
||||
procedure WMEraseBackground(var Msg: TLMERASEBKGND); message LM_ERASEBKGND;
|
||||
procedure WMHScroll(var Msg: TLMSCROLL); message LM_HSCROLL;
|
||||
procedure WMVScroll(var Msg: TLMSCROLL); message LM_VSCROLL;
|
||||
procedure WMRButtonDown(var Msg: TLMRButtonDown); message LM_RBUTTONDOWN;
|
||||
{$ENDIF}
|
||||
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure FirstPage;
|
||||
function IsFirstPage: Boolean;
|
||||
function IsLastPage: Boolean;
|
||||
procedure LastPage;
|
||||
procedure NextPage;
|
||||
procedure PrevPage;
|
||||
procedure ForceUpdate;
|
||||
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
|
||||
procedure FirstPage;
|
||||
function IsFirstPage: Boolean;
|
||||
function IsLastPage: Boolean;
|
||||
procedure LastPage;
|
||||
procedure NextPage;
|
||||
procedure PrevPage;
|
||||
procedure ForceUpdate;
|
||||
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
|
||||
|
||||
property PageCount: Integer read GetPageCount;
|
||||
property Printer: TPrinter read FPrinter write SetPrinter;
|
||||
property DestPrinter: TPrinter read FPrinter write SetPrinter;
|
||||
property PageCount: Integer read GetPageCount;
|
||||
property Printer: TPrinter read FPrinter write SetPrinter;
|
||||
property DestPrinter: TPrinter read FPrinter write SetPrinter;
|
||||
|
||||
published
|
||||
property BorderColor: TColor read FBorderColor write SetBorderColor default clBlack;
|
||||
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
|
||||
property ControlLink: TVpControlLink read FControlLink write SetControlLink;
|
||||
property CurPage: Integer read FCurPage write SetCurPage;
|
||||
published
|
||||
property BorderColor: TColor read FBorderColor write SetBorderColor default clBlack;
|
||||
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
|
||||
property ControlLink: TVpControlLink read FControlLink write SetControlLink;
|
||||
property CurPage: Integer read FCurPage write SetCurPage;
|
||||
// property DestPrinter: TPrinter read FPrinter write SetPrinter;
|
||||
property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d;
|
||||
property EndDate: TDateTime read FEndDate write SetEndDate;
|
||||
property OffPageColor: TColor read FOffPageColor write SetOffPageColor default clSilver;
|
||||
property PageColor: TColor read FPageColor write SetPageColor default clWhite;
|
||||
property StartDate: TDateTime read FStartDate write SetStartDate;
|
||||
property ZoomFactor: TVpPPZoomFactor read FZoomFactor write SetZoomFactor default zfFitToControl;
|
||||
property OnPageChange: TVpPageChange read FOnPageChange write FOnPageChange;
|
||||
property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d;
|
||||
property EndDate: TDateTime read FEndDate write SetEndDate;
|
||||
property OffPageColor: TColor read FOffPageColor write SetOffPageColor default clSilver;
|
||||
property PageColor: TColor read FPageColor write SetPageColor default clWhite;
|
||||
property StartDate: TDateTime read FStartDate write SetStartDate;
|
||||
property ZoomFactor: TVpPPZoomFactor read FZoomFactor write SetZoomFactor default zfFitToControl;
|
||||
property OnPageChange: TVpPageChange read FOnPageChange write FOnPageChange;
|
||||
|
||||
property Anchors;
|
||||
property Align;
|
||||
property BorderSpacing;
|
||||
property Constraints;
|
||||
property Cursor;
|
||||
property DragCursor;
|
||||
property DragMode;
|
||||
property Enabled;
|
||||
property HelpContext;
|
||||
property Hint;
|
||||
property Parent;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ShowHint;
|
||||
property TabStop;
|
||||
property TabOrder;
|
||||
property Visible;
|
||||
property Anchors;
|
||||
property Align;
|
||||
property BorderSpacing;
|
||||
property Constraints;
|
||||
property Cursor;
|
||||
property DragCursor;
|
||||
property DragMode;
|
||||
property Enabled;
|
||||
property HelpContext;
|
||||
property Hint;
|
||||
property Parent;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ShowHint;
|
||||
property TabStop;
|
||||
property TabOrder;
|
||||
property Visible;
|
||||
|
||||
property OnClick;
|
||||
property OnDblClick;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnMouseDown;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnStartDrag;
|
||||
property OnClick;
|
||||
property OnDblClick;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnMouseDown;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnStartDrag;
|
||||
end;
|
||||
|
||||
|
||||
@ -240,7 +238,7 @@ begin
|
||||
if not (AOwner is TWinControl) then
|
||||
raise EVpPrintPreviewError.Create(RSOwnerNotWinCtrl);
|
||||
|
||||
Parent := TWinControl (AOwner);
|
||||
// Parent := TWinControl(AOwner);
|
||||
|
||||
RenderBmp := TBitmap.Create;
|
||||
WorkBmp := TBitmap.Create;
|
||||
@ -291,32 +289,32 @@ var
|
||||
ScreenPPI: Integer;
|
||||
PrinterPPI: Integer;
|
||||
begin
|
||||
ScreenPPI := GetDeviceCaps (Canvas.Handle, LOGPIXELSY);
|
||||
ScreenPPI := GetDeviceCaps(Canvas.Handle, LOGPIXELSY);
|
||||
{$IFDEF DELPHI}
|
||||
PrinterPPI := GetDeviceCaps (Printer.Handle, LOGPIXELSY);
|
||||
PrinterPPI := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
|
||||
{$ELSE}
|
||||
PrinterPPI := Printer.XDpi;
|
||||
{$ENDIF}
|
||||
|
||||
if PrinterPPI <> 0 then
|
||||
Result := Round (ScreenPPI / PrinterPPI * Printer.PageHeight)
|
||||
Result := Round(ScreenPPI / PrinterPPI * Printer.PageHeight)
|
||||
else
|
||||
Result := ScreenPPI * Printer.PageHeight;
|
||||
end;
|
||||
|
||||
function TVpPrintPreview.CalculatePageWidth (Printer : TPrinter) : Integer;
|
||||
function TVpPrintPreview.CalculatePageWidth(Printer: TPrinter) : Integer;
|
||||
var
|
||||
ScreenPPI: Integer;
|
||||
PrinterPPI: Integer;
|
||||
begin
|
||||
ScreenPPI := GetDeviceCaps (Canvas.Handle, LOGPIXELSX);
|
||||
ScreenPPI := GetDeviceCaps(Canvas.Handle, LOGPIXELSX);
|
||||
{$IFDEF DELPHI}
|
||||
PrinterPPI := GetDeviceCaps (Printer.Handle, LOGPIXELSX);
|
||||
PrinterPPI := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
|
||||
{$ELSE}
|
||||
PrinterPPI := Printer.XDpi;
|
||||
|
||||
if PrinterPPI <> 0 then
|
||||
Result := Round (ScreenPPI / PrinterPPI * Printer.PageWidth)
|
||||
Result := Round(ScreenPPI / PrinterPPI * Printer.PageWidth)
|
||||
else
|
||||
Result := ScreenPPI * Printer.PageHeight;
|
||||
{$ENDIF}
|
||||
@ -327,10 +325,10 @@ var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := FPageInfo.Count - 1 downto 0 do begin
|
||||
if Assigned (FPageInfo[i]) then
|
||||
FreeMem (FPageInfo[i]);
|
||||
FPageInfo.Delete (i);
|
||||
if Assigned(FPageInfo[i]) then
|
||||
FreeMem(FPageInfo[i]);
|
||||
end;
|
||||
FPageInfo.Clear;
|
||||
CurPage := 0;
|
||||
end;
|
||||
|
||||
@ -358,7 +356,7 @@ end;
|
||||
procedure TVpPrintPreview.CreateWnd;
|
||||
begin
|
||||
if HandleAllocated and Assigned(FControlLink) then
|
||||
FControlLink.Printer.DeregisterWatcher(Handle);
|
||||
FControlLink.Printer.DeRegisterWatcher(Handle);
|
||||
|
||||
inherited CreateWnd;
|
||||
|
||||
@ -423,11 +421,6 @@ begin
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.GeneratePageImage;
|
||||
var
|
||||
LastPage: Boolean = false;
|
||||
UseDate: TDateTime;
|
||||
UseContact: Integer;
|
||||
UseTask: Integer;
|
||||
begin
|
||||
if not Assigned(FControlLink) then
|
||||
Exit;
|
||||
@ -438,55 +431,90 @@ begin
|
||||
if (FControlLink.Printer.PrintFormats.Count = 0) or
|
||||
(FControlLink.Printer.CurFormat < 0)
|
||||
then
|
||||
Exit;
|
||||
Exit;
|
||||
|
||||
FCurrentFormat := FControlLink.Printer.CurFormat;
|
||||
|
||||
if (FPrinter <> nil) and
|
||||
((RenderBmp.Width = 0) or (RenderBmp.Height = 0)) then
|
||||
// Prepare rendering bitmap and paint its background.
|
||||
if (RenderBmp.Width = 0) or (RenderBmp.Height = 0) then
|
||||
begin
|
||||
RenderBmp.Width := CalculatePageWidth(FPrinter);
|
||||
RenderBmp.Height := CalculatePageHeight(FPrinter);
|
||||
end
|
||||
else
|
||||
if (FPrinter = nil) and
|
||||
((RenderBmp.Width = 0) or (RenderBmp.Height = 0)) then
|
||||
begin
|
||||
RenderBmp.Width := ClientWidth;
|
||||
RenderBmp.Height := ClientHeight;
|
||||
if FPrinter <> nil then
|
||||
begin
|
||||
RenderBmp.Width := CalculatePageWidth(FPrinter);
|
||||
RenderBmp.Height := CalculatePageHeight(FPrinter);
|
||||
end else
|
||||
begin
|
||||
RenderBmp.Width := ClientWidth;
|
||||
RenderBmp.Height := ClientHeight;
|
||||
end;
|
||||
end;
|
||||
|
||||
if not IsPageLoaded(CurPage) then
|
||||
LoadPage(CurPage, FStartDate, FEndDate);
|
||||
|
||||
RenderBmp.Canvas.Brush.Color := FPageColor;
|
||||
RenderBmp.Canvas.Brush.Style := bsSolid;
|
||||
RenderBmp.Canvas.Pen.Color := FBorderColor;
|
||||
RenderBmp.Canvas.Pen.Style := psSolid;
|
||||
RenderBmp.Canvas.FillRect(Rect(0, 0, RenderBmp.Width, RenderBmp.Height));
|
||||
|
||||
if not IsPageLoaded(CurPage) then
|
||||
FControlLink.Printer.PaintToCanvasRect(
|
||||
RenderBmp.Canvas,
|
||||
Rect(0, 0, RenderBmp.Width, RenderBmp.Height),
|
||||
StartDate
|
||||
)
|
||||
else begin
|
||||
UseDate := PVpPageInfo(FPageInfo[CurPage]).Date;
|
||||
UseContact := PVpPageInfo(FPageInfo[CurPage]).Contact;
|
||||
UseTask := PVpPageInfo(FPageInfo[CurPage]).Task;
|
||||
// Prepare the page infos and store them in the FPageInfo list. Page infos
|
||||
// describe at which date, contact or task line each page begins so that
|
||||
// any page later can be repainted.
|
||||
GeneratePageInfos;
|
||||
|
||||
// Loads the page info for the current page and draws the page in the preview
|
||||
LoadPage(CurPage, FStartDate, FEndDate);
|
||||
|
||||
// Adjust scrollbars. // -- wp: is this working?
|
||||
SetScrollBars;
|
||||
end;
|
||||
|
||||
{ The only way to see how the pages are going to increment is to render
|
||||
them and collect the returned information in the PageInfo list. }
|
||||
procedure TVpPrintPreview.GeneratePageInfos;
|
||||
var
|
||||
lDate: TDateTime;
|
||||
lContact, lTask: Integer;
|
||||
lLastPage: Boolean;
|
||||
i: Integer;
|
||||
pageInfo: PVpPageInfo;
|
||||
begin
|
||||
if FPageInfo.Count > 0 then
|
||||
Exit;
|
||||
|
||||
lDate := StartDate;
|
||||
lContact := 0;
|
||||
lTask := 0;
|
||||
lLastPage := false;
|
||||
|
||||
GetMem(pageInfo, SizeOf(TVpPageInfo));
|
||||
pageInfo.Date := lDate;
|
||||
pageInfo.Contact := lContact;
|
||||
pageInfo.Task := lTask;
|
||||
pageInfo.LastPage := lLastPage;
|
||||
FPageInfo.Add(pageInfo);
|
||||
|
||||
i := 0;
|
||||
while (not lLastPage) do begin
|
||||
inc(i);
|
||||
FControlLink.Printer.RenderPage(
|
||||
RenderBmp.Canvas,
|
||||
Rect(0, 0, RenderBmp.Width, RenderBmp.Height),
|
||||
CurPage,
|
||||
UseDate,
|
||||
EndDate,
|
||||
UseContact,
|
||||
UseTask,
|
||||
LastPage
|
||||
i,
|
||||
lDate,
|
||||
FEndDate,
|
||||
lContact,
|
||||
lTask,
|
||||
lLastPage
|
||||
);
|
||||
|
||||
if not lLastPage then
|
||||
begin
|
||||
GetMem(pageInfo, SizeOf(TVpPageInfo));
|
||||
pageInfo.Date := lDate;
|
||||
pageInfo.Task := lTask;
|
||||
pageInfo.Contact := lContact;
|
||||
pageInfo.LastPage := lLastPage;
|
||||
FPageInfo.Add(pageInfo);
|
||||
end;
|
||||
end;
|
||||
SetScrollBars;
|
||||
end;
|
||||
|
||||
{ Defines the initial size of the control. }
|
||||
@ -496,18 +524,8 @@ begin
|
||||
Result.CY := 225;
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.GetLastPage;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
i := FPageInfo.Count - 1;
|
||||
while (not PVpPageInfo(FPageInfo[i]).LastPage) and (i < FPageInfo.Count) do
|
||||
begin
|
||||
inc(i);
|
||||
LoadPage(i, StartDate, EndDate);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Gets the number of rendered pages from the PageInfo list where every page
|
||||
has an entry. }
|
||||
function TVpPrintPreview.GetPageCount: Integer;
|
||||
begin
|
||||
Result := FPageInfo.Count;
|
||||
@ -591,20 +609,7 @@ end;
|
||||
|
||||
function TVpPrintPreview.IsLastPage: Boolean;
|
||||
begin
|
||||
if FPageInfo.Count = 0 then
|
||||
Result := True
|
||||
else
|
||||
if CurPage < FPageInfo.Count then
|
||||
Result := PVpPageInfo(FPageInfo[CurPage]).LastPage
|
||||
else begin
|
||||
GetLastPage;
|
||||
Result := PVpPageInfo(FPageInfo[CurPage]).LastPage;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TVpPrintPreview.IsPageLoaded(PageNum: Integer): Boolean;
|
||||
begin
|
||||
Result := PageNum < FPageInfo.Count;
|
||||
Result := (FCurPage = FPageInfo.Count-1);
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
@ -663,7 +668,7 @@ begin
|
||||
FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10);
|
||||
end;
|
||||
VK_APPS:
|
||||
if not Assigned (PopupMenu) then begin
|
||||
if not Assigned(PopupMenu) then begin
|
||||
PopupPoint := GetClientOrigin;
|
||||
FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10);
|
||||
end;
|
||||
@ -673,18 +678,8 @@ begin
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.LastPage;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if CurPage < FPageInfo.Count then begin
|
||||
i := CurPage;
|
||||
if (not PVpPageInfo(FPageInfo[i]).LastPage) and (i < FPageInfo.Count) then
|
||||
inc(i);
|
||||
if (not PVpPageInfo(FPageInfo[i]).LastPage) then
|
||||
GetLastPage;
|
||||
end else
|
||||
GetLastPage;
|
||||
CurPage := FPageInfo.Count - 1;
|
||||
SetCurPage(FPageInfo.Count - 1);
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.Loaded;
|
||||
@ -694,80 +689,43 @@ begin
|
||||
GeneratePageImage;
|
||||
end;
|
||||
|
||||
{ Loads the requested page. Returns the last page loaded. If the
|
||||
return value is less than the requested page, the requested page
|
||||
is past the last page }
|
||||
function TVpPrintPreview.LoadPage(PageNum: Integer;
|
||||
StartDate, EndDate: TDateTime): Integer;
|
||||
{ Loads the requested page parameters from the PageList and renders the page
|
||||
in the RenderBmp bitmap canvas. }
|
||||
procedure TVpPrintPreview.LoadPage(PageNum: Integer;
|
||||
StartDate, EndDate: TDateTime);
|
||||
var
|
||||
i: Integer;
|
||||
LastPage: Boolean;
|
||||
PPageInfo: PVpPageInfo;
|
||||
ADate: TDateTime;
|
||||
ATask: Integer;
|
||||
AContact: Integer;
|
||||
pageInfo: PVpPageInfo;
|
||||
lDate: TDateTime;
|
||||
lTask: Integer;
|
||||
lContact: Integer;
|
||||
lLastPage: Boolean;
|
||||
begin
|
||||
Unused(EndDate);
|
||||
|
||||
Result := PageNum;
|
||||
if PageNum < FPageInfo.Count then
|
||||
Exit;
|
||||
pageInfo := PVpPageInfo(FPageInfo[PageNum]);
|
||||
lDate := pageInfo.Date;
|
||||
lContact := pageInfo.Contact;
|
||||
lTask := pageInfo.Task;
|
||||
lLastPage := pageInfo.LastPage;
|
||||
|
||||
if not Assigned(FControlLink) then
|
||||
Exit;
|
||||
|
||||
if not Assigned(FControlLink.Printer) then
|
||||
Exit;
|
||||
|
||||
i := FPageInfo.Count - 1;
|
||||
LastPage := False;
|
||||
|
||||
if FPageInfo.Count = 0 then begin
|
||||
GetMem(PPageInfo, SizeOf(TVpPageInfo));
|
||||
PPageInfo.Date := StartDate;
|
||||
PPageInfo.Contact := 0;
|
||||
PPageInfo.Task := 0;
|
||||
PPageInfo.LastPage := False;
|
||||
FPageInfo.Add(PPageInfo);
|
||||
i := 0;
|
||||
end;
|
||||
|
||||
PPageInfo := PVpPageInfo(FPageInfo[i]);
|
||||
ADate := PPageInfo.Date;
|
||||
AContact := PPageInfo.Contact;
|
||||
ATask := PPageInfo.Task;
|
||||
|
||||
{ The only way to see how the pages are going to increment is to render
|
||||
them and get the return information }
|
||||
while (i <= PageNum) and (not LastPage) do begin
|
||||
FControlLink.Printer.RenderPage(
|
||||
RenderBmp.Canvas,
|
||||
Rect(0, 0, RenderBmp.Width, RenderBmp.Height),
|
||||
i + 1,
|
||||
ADate,
|
||||
FEndDate,
|
||||
AContact,
|
||||
ATask,
|
||||
LastPage
|
||||
);
|
||||
Result := i;
|
||||
GetMem(PPageInfo, SizeOf(TVpPageInfo));
|
||||
PPageInfo.Date := ADate;
|
||||
PPageInfo.Task := ATask;
|
||||
PPageInfo.Contact := AContact;
|
||||
PPageInfo.LastPage := LastPage;
|
||||
FPageInfo.Add(PPageInfo);
|
||||
inc(i);
|
||||
end;
|
||||
FControlLink.Printer.RenderPage(
|
||||
RenderBmp.Canvas,
|
||||
Rect(0, 0, RenderBmp.Width, RenderBmp.Height),
|
||||
PageNum,
|
||||
lDate,
|
||||
FEndDate,
|
||||
lContact,
|
||||
lTask,
|
||||
lLastPage
|
||||
);
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.NextPage;
|
||||
begin
|
||||
if CurPage < FPageInfo.Count then begin
|
||||
if not PVpPageInfo(FPageInfo[CurPage]).LastPage then
|
||||
CurPage := CurPage + 1;
|
||||
end else
|
||||
CurPage := CurPage + 1;
|
||||
if FCurPage < FPageInfo.Count-1 then
|
||||
SetCurPage(FCurPage + 1);
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.Paint;
|
||||
@ -913,7 +871,6 @@ var
|
||||
RealWidth := round(RenderBmp.Width / ZOOM_FACTOR_VALUES[FZoomFactor]);
|
||||
RealHeight := round(RenderBmp.Height / ZOOM_FACTOR_VALUES[FZoomFactor]);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure RenderImage;
|
||||
@ -937,7 +894,7 @@ end;
|
||||
procedure TVpPrintPreview.PrevPage;
|
||||
begin
|
||||
if FCurPage > 0 then
|
||||
CurPage := CurPage - 1;
|
||||
SetCurPage(FCurPage - 1);
|
||||
end;
|
||||
|
||||
procedure TVpPrintPreview.PopupFirstPage(Sender: TObject);
|
||||
@ -1022,10 +979,12 @@ end;
|
||||
|
||||
procedure TVpPrintPreview.SetCurPage(const v: Integer);
|
||||
begin
|
||||
if (v >= 0) and (v <> FCurPage) then begin
|
||||
if (v >= 0) and (v < FPageInfo.Count) and (v <> FCurPage) then
|
||||
begin
|
||||
FCurPage := v;
|
||||
if not (csDestroying in ComponentState) then begin
|
||||
GeneratePageImage;
|
||||
if not (csDestroying in ComponentState) then
|
||||
begin
|
||||
LoadPage(FCurPage, FStartDate, FEndDate);
|
||||
Invalidate;
|
||||
if Assigned(FOnPageChange) then
|
||||
FOnPageChange(Self, FCurPage);
|
||||
@ -1144,6 +1103,7 @@ procedure TVpPrintPreview.SetZoomFactor(const v: TVpPPZoomFactor);
|
||||
begin
|
||||
if v <> FZoomFactor then begin
|
||||
FZoomFactor := v;
|
||||
ClearPageData;
|
||||
SetScrollBars;
|
||||
Invalidate;
|
||||
end;
|
||||
|
@ -428,21 +428,10 @@ procedure TfrmPrintPreview.actMainUpdate(Action: TBasicAction;
|
||||
begin
|
||||
Unused(Action, Handled);
|
||||
|
||||
if VpPrintPreview1.IsFirstPage then begin
|
||||
actFirstPage.Enabled := False;
|
||||
actPrevPage.Enabled := False;
|
||||
end else begin
|
||||
actFirstPage.Enabled := True;
|
||||
actPrevPage.Enabled := True;
|
||||
end;
|
||||
|
||||
if VpPrintPreview1.IsLastPage then begin
|
||||
actLastPage.Enabled := False;
|
||||
actNextPage.Enabled := False;
|
||||
end else begin
|
||||
actLastPage.Enabled := True;
|
||||
actNextPage.Enabled := True;
|
||||
end;
|
||||
actFirstPage.Enabled := not VpPrintPreview1.IsFirstPage;
|
||||
actPrevPage.Enabled := not VpPrintPreview1.IsFirstPage;
|
||||
actNextPage.Enabled := not VpPrintPreview1.IsLastPage;
|
||||
actLastPage.Enabled := not VpPrintPreview1.IsLastPage;
|
||||
end;
|
||||
|
||||
procedure TfrmPrintPreview.actCancelExecute(Sender: TObject);
|
||||
|
Reference in New Issue
Block a user