diff --git a/components/tvplanit/source/vpprtprv.pas b/components/tvplanit/source/vpprtprv.pas index d57b59024..9c22ae121 100644 --- a/components/tvplanit/source/vpprtprv.pas +++ b/components/tvplanit/source/vpprtprv.pas @@ -57,145 +57,139 @@ interface uses {$IFDEF LCL} - LMessages,LCLProc,LCLType,LCLIntf, + LMessages, LCLProc, LCLType, LCLIntf, {$ELSE} - Windows,Messages, + Windows, Messages, {$ENDIF} - SysUtils,Classes,Controls,Forms,Graphics, Printers, VpBase, - VpMisc,VpBaseDS, VpSR, VpException, Menus; + SysUtils, Classes, Controls, Forms, Graphics, Printers, + VpBase, VpMisc, VpBaseDS, VpSR, VpException, Menus; type - TVpPageChange = procedure (Sender : TObject; NewPage : Integer) of object; + TVpPageChange = procedure(Sender: TObject; NewPage: Integer) of object; TVpPPZoomFactor = (zfFitToControl, zfActualSize, zf25Percent, zf33Percent, zf50Percent, zf67Percent, zf75Percent); +const + ZOOM_FACTOR_VALUES: array[TVpPPZoomFactor] of Double = ( + -1, 1.0, 0.25, 1.0/3, 0.5, 2.0/3, 0.75); + +type TVpPageInfo = record - Date : TDateTime; - Task : Integer; - Contact : Integer; - LastPage : Boolean; + Date: TDateTime; + Task: Integer; + Contact: Integer; + LastPage: Boolean; end; PVpPageInfo = ^TVpPageInfo; - TVpPrintPreview = class (TVpCustomControl) + 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; + 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; protected - function CalculatePageHeight (Printer : TPrinter) : Integer; - function CalculatePageWidth (Printer : TPrinter) : Integer; + function CalculatePageHeight(Printer: TPrinter): Integer; + function CalculatePageWidth(Printer: TPrinter): Integer; procedure ClearPageData; - {$IFNDEF LCL} + {$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 DoScroll(var Msg: {$IFNDEF LCL}TWMSCROLL{$ELSE}TLMScroll{$ENDIF}; BarDirection: Integer); procedure GeneratePageImage; procedure GetLastPage; - procedure InitHScrollBar (PageSize : Integer; - TotalSize : Integer); + procedure InitHScrollBar(PageSize, TotalSize: Integer); procedure InitializeDefaultPopup; - procedure InitVScrollBar (PageSize : Integer; - TotalSize : Integer); - function IsPageLoaded (PageNum : Integer) : Boolean; - procedure KeyDown (var Key: Word; Shift: TShiftState); override; + 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 : TDateTime; - EndDate : TDateTime) : Integer; + 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 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); - 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 SetBorderColor(const v: TColor); + procedure SetBorderStyle(const v: TBorderStyle); + 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 SetZoomFactor(const v: TVpPPZoomFactor); // procedure VpPrintFormatChanged (var Msg : {$IFNDEF LCL}TMessage{$ELSE}TLMessage{$ENDIF}; message Vp_PrintFormatChanged; - {$IFNDEF LCL} - 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; + {$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; + 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; + constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure FirstPage; - function IsFirstPage : Boolean; - function IsLastPage : Boolean; + function IsFirstPage: Boolean; + function IsLastPage: Boolean; procedure LastPage; procedure NextPage; procedure PrevPage; procedure ForceUpdate; - procedure SetBounds (ALeft, ATop, AWidth, AHeight: Integer); override; + procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override; + + property Printer: TPrinter read FPrinter write SetPrinter; + property DestPrinter: TPrinter read FPrinter write SetPrinter; - 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; -// 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 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 Anchors; property Align; @@ -232,87 +226,88 @@ type property OnStartDrag; end; + implementation -constructor TVpPrintPreview.Create (AOwner : TComponent); +constructor TVpPrintPreview.Create(AOwner: TComponent); begin - inherited Create (AOwner); + inherited Create(AOwner); if not (AOwner is TWinControl) then - raise EVpPrintPreviewError.Create (RSOwnerNotWinCtrl); + raise EVpPrintPreviewError.Create(RSOwnerNotWinCtrl); - Parent := TWinControl (AOwner); + Parent := TWinControl (AOwner); - RenderBmp := TBitmap.Create; - WorkBmp := TBitmap.Create; - FPageInfo := TList.Create; + RenderBmp := TBitmap.Create; + WorkBmp := TBitmap.Create; + FPageInfo := TList.Create; FDefaultPopup := TPopupMenu.Create (Self); InitializeDefaultPopup; - FNeedHScroll := False; - FNeedVScroll := False; + FNeedHScroll := False; + FNeedVScroll := False; FCurrentFormat := -1; - FBorderStyle := bsSingle; - FDrawingStyle := ds3d; - FZoomFactor := zfFitToControl; - FOffPageColor := clSilver; - FPageColor := clWhite; - FBorderColor := clBlack; - FCurPage := 0; - FStartDate := Now; - FEndDate := Now + 7; - FScrollX := 0; - FScrollY := 0; - Height := 225; - Width := 169; - FPrinter := Printer; + FBorderStyle := bsSingle; + FDrawingStyle := ds3d; + FZoomFactor := zfFitToControl; + FOffPageColor := clSilver; + FPageColor := clWhite; + FBorderColor := clBlack; + FCurPage := 0; + FStartDate := Now; + FEndDate := Now + 7; + FScrollX := 0; + FScrollY := 0; + Height := 225; + Width := 169; + FPrinter := Printer; end; destructor TVpPrintPreview.Destroy; begin if (HandleAllocated) and Assigned (FControlLink) then - FControlLink.Printer.DeregisterWatcher (Handle); + FControlLink.Printer.DeregisterWatcher(Handle); ClearPageData; RenderBmp.Free; WorkBmp.Free; - FPageInfo.Free; - FDefaultPopup.Free; inherited Destroy; end; -function TVpPrintPreview.CalculatePageHeight (Printer : TPrinter) : Integer; +function TVpPrintPreview.CalculatePageHeight(Printer: TPrinter): Integer; var - ScreenPPI : Integer; - PrinterPPI : Integer; - + ScreenPPI: Integer; + PrinterPPI: Integer; begin - {$IFNDEF LCL} ScreenPPI := GetDeviceCaps (Canvas.Handle, LOGPIXELSY); + {$IFDEF DELPHI} PrinterPPI := GetDeviceCaps (Printer.Handle, LOGPIXELSY); + {$ELSE} + PrinterPPI := Printer.XDpi; + {$ENDIF} if PrinterPPI <> 0 then Result := Round (ScreenPPI / PrinterPPI * Printer.PageHeight) else Result := ScreenPPI * Printer.PageHeight; - {$ENDIF} end; function TVpPrintPreview.CalculatePageWidth (Printer : TPrinter) : Integer; var - ScreenPPI : Integer; - PrinterPPI : Integer; - + ScreenPPI: Integer; + PrinterPPI: Integer; begin - {$IFNDEF LCL} ScreenPPI := GetDeviceCaps (Canvas.Handle, LOGPIXELSX); + {$IFDEF DELPHI} PrinterPPI := GetDeviceCaps (Printer.Handle, LOGPIXELSX); + {$ELSE} + PrinterPPI := Printer.XDpi; if PrinterPPI <> 0 then Result := Round (ScreenPPI / PrinterPPI * Printer.PageWidth) @@ -323,8 +318,7 @@ end; procedure TVpPrintPreview.ClearPageData; var - i : Integer; - + i: Integer; begin for i := FPageInfo.Count - 1 downto 0 do begin if Assigned (FPageInfo[i]) then @@ -334,7 +328,7 @@ begin CurPage := 0; end; -{$IFNDEF LCL} +{$IFDEF DELPHI} procedure TVpPrintPreview.CMWantSpecialKey(var Msg: TCMWantSpecialKey); begin inherited; @@ -342,7 +336,7 @@ begin end; {$ENDIF} -procedure TVpPrintPreview.CreateParams (var Params : TCreateParams); +procedure TVpPrintPreview.CreateParams(var Params: TCreateParams); begin inherited CreateParams (Params); @@ -357,47 +351,41 @@ end; procedure TVpPrintPreview.CreateWnd; begin - if (HandleAllocated) and (Assigned (FControlLink)) then - FControlLink.Printer.DeregisterWatcher (Handle); + if HandleAllocated and Assigned(FControlLink) then + FControlLink.Printer.DeregisterWatcher(Handle); inherited CreateWnd; - if Assigned (FControlLink) then - FControlLink.Printer.RegisterWatcher (Handle); + if Assigned(FControlLink) then + FControlLink.Printer.RegisterWatcher(Handle); end; -{$IFNDEF LCL} -procedure TVpPrintPreview.DoScroll (var Msg : TWMSCROLL; - BarDirection : Integer); -{$ELSE} -procedure TVpPrintPreview.DoScroll (var Msg : TLMSCROLL; - BarDirection : Integer); -{$ENDIF} +procedure TVpPrintPreview.DoScroll(var Msg: {$IFNDEF LCL}TWMSCROLL{$ELSE}TLMScroll{$ENDIF}; + BarDirection: Integer); var - ScrollBarInfo : TScrollInfo; - + ScrollBarInfo: TScrollInfo; begin Msg.Result := 0; - ScrollBarInfo.cbSize := SizeOf (TscrollInfo); + ScrollBarInfo.cbSize := SizeOf(TScrollInfo); ScrollBarInfo.fMask := SIF_ALL; GetScrollInfo (Handle, BarDirection, ScrollBarInfo); ScrollBarInfo.fMask := SIF_POS; case Msg.ScrollCode of SB_TOP : ScrollBarInfo.nPos := ScrollBarInfo.nMin; SB_BOTTOM : ScrollBarInfo.nPos := ScrollBarInfo.nMax; - SB_LINEUP : Dec (ScrollBarInfo.nPos, 1); - SB_LINEDOWN : Inc (ScrollBarInfo.nPos, 1); - SB_PAGEUP : Dec (ScrollBarInfo.nPos, ScrollBarInfo.nPage ); - SB_PAGEDOWN : Inc (ScrollBarInfo.nPos, ScrollBarInfo.nPage); + SB_LINEUP : Dec(ScrollBarInfo.nPos, 1); + SB_LINEDOWN : Inc(ScrollBarInfo.nPos, 1); + SB_PAGEUP : Dec(ScrollBarInfo.nPos, ScrollBarInfo.nPage ); + SB_PAGEDOWN : Inc(ScrollBarInfo.nPos, ScrollBarInfo.nPage); SB_THUMBTRACK, SB_THUMBPOSITION : ScrollBarInfo.nPos := Msg.Pos; SB_ENDSCROLL : Exit; end; ScrollBarInfo.fMask := SIF_POS; - if ScrollBarInfo.nPos < ScrollBarInfo.nMin Then + if ScrollBarInfo.nPos < ScrollBarInfo.nMin then ScrollBarInfo.nPos := ScrollBarInfo.nMin; - if ScrollBarInfo.nPos + Integer (ScrollBarInfo.nPage) > + if ScrollBarInfo.nPos + Integer(ScrollBarInfo.nPage) > ScrollBarInfo.nMax Then ScrollBarInfo.nPos := ScrollBarInfo.nMax - Integer (ScrollBarInfo.nPage); @@ -406,7 +394,7 @@ begin SB_VERT : FScrollY := ScrollBarInfo.nPos; end; - SetScrollInfo (Handle, BarDirection, ScrollBarInfo, True); + SetScrollInfo(Handle, BarDirection, ScrollBarInfo, True); Invalidate; end; @@ -432,107 +420,108 @@ end; procedure TVpPrintPreview.GeneratePageImage; var - LastPage : Boolean; - UseDate : TDateTime; - UseContact : Integer; - UseTask : Integer; - + LastPage: Boolean; + UseDate: TDateTime; + UseContact: Integer; + UseTask: Integer; begin - if not Assigned (FControlLink) then + if not Assigned(FControlLink) then Exit; - if not Assigned (FControlLink.Printer) then + if not Assigned(FControlLink.Printer) then Exit; - if (FControlLink.Printer.PrintFormats.Count = 0) or - (FControlLink.Printer.CurFormat < 0) then + if (FControlLink.Printer.PrintFormats.Count = 0) or + (FControlLink.Printer.CurFormat < 0) + then Exit; FCurrentFormat := FControlLink.Printer.CurFormat; if (FPrinter <> nil) and - ((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 = 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; end; - if not IsPageLoaded (CurPage) then - LoadPage (CurPage, FStartDate, FEndDate); + if not IsPageLoaded(CurPage) then + LoadPage(CurPage, FStartDate, FEndDate); RenderBmp.Canvas.Brush.Color := FPageColor; RenderBmp.Canvas.Pen.Color := FBorderColor; - RenderBmp.Canvas.FillRect (Rect (0, 0, RenderBmp.Width, RenderBmp.Height)); + 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) + 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; - FControlLink.Printer.RenderPage (RenderBmp.Canvas, - Rect (0, 0, RenderBmp.Width, - RenderBmp.Height), - CurPage, - UseDate, - EndDate, - UseContact, - UseTask, - LastPage); + UseDate := PVpPageInfo(FPageInfo[CurPage]).Date; + UseContact := PVpPageInfo(FPageInfo[CurPage]).Contact; + UseTask := PVpPageInfo(FPageInfo[CurPage]).Task; + FControlLink.Printer.RenderPage( + RenderBmp.Canvas, + Rect(0, 0, RenderBmp.Width, RenderBmp.Height), + CurPage, + UseDate, + EndDate, + UseContact, + UseTask, + LastPage + ); end; SetScrollBars; end; procedure TVpPrintPreview.GetLastPage; var - i : Integer; - + 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); + while (not PVpPageInfo(FPageInfo[i]).LastPage) and (i < FPageInfo.Count) do + begin + inc(i); + LoadPage(i, StartDate, EndDate); end; end; -procedure TVpPrintPreview.InitHScrollBar (PageSize : Integer; - TotalSize : Integer); +procedure TVpPrintPreview.InitHScrollBar(PageSize, TotalSize: Integer); var - ScrollBarInfo : TScrollInfo; - + ScrollBarInfo: TScrollInfo; begin FNeedHScroll := True; - ScrollBarInfo.cbSize := SizeOf (TScrollInfo); - ScrollBarInfo.fMask := SIF_ALL or SIF_DISABLENOSCROLL; - ScrollBarInfo.nMin := 0; - - ScrollBarInfo.nMax := TotalSize; - ScrollBarInfo.nPage := PageSize; - ScrollBarInfo.nPos := 0; + ScrollBarInfo.cbSize := SizeOf (TScrollInfo); + ScrollBarInfo.fMask := SIF_ALL or SIF_DISABLENOSCROLL; + ScrollBarInfo.nMin := 0; + ScrollBarInfo.nMax := TotalSize; + ScrollBarInfo.nPage := PageSize; + ScrollBarInfo.nPos := 0; ScrollBarInfo.nTrackPos := 0; - SetScrollInfo (Handle, SB_HORZ, ScrollBarInfo, True); + + SetScrollInfo(Handle, SB_HORZ, ScrollBarInfo, True); end; procedure TVpPrintPreview.InitializeDefaultPopup; var - NewItem : TMenuItem; - + NewItem: TMenuItem; begin if RSPrintPrvPrevPage <> '' then begin NewItem := TMenuItem.Create (Self); NewItem.Caption := RSPrintPrvPrevPage; NewItem.OnClick := PopupPrevPage; NewItem.Tag := 1; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); end; if RSPrintPrvNextPage <> '' then begin @@ -540,7 +529,7 @@ begin NewItem.Caption := RSPrintPrvNextPage; NewItem.OnClick := PopupNextPage; NewItem.Tag := 2; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); end; if RSPrintPrvFirstPage <> '' then begin @@ -548,7 +537,7 @@ begin NewItem.Caption := RSPrintPrvFirstPage; NewItem.OnClick := PopupFirstPage; NewItem.Tag := 1; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); end; if RSPrintPrvLastPage <> '' then begin @@ -556,111 +545,109 @@ begin NewItem.Caption := RSPrintPrvLastPage; NewItem.OnClick := PopupLastPage; NewItem.Tag := 2; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); end; end; -procedure TVpPrintPreview.InitVScrollBar (PageSize : Integer; - TotalSize : Integer); +procedure TVpPrintPreview.InitVScrollBar(PageSize, TotalSize: Integer); var - ScrollBarInfo : TScrollInfo; - + ScrollBarInfo: TScrollInfo; begin FNeedVScroll := True; - ScrollBarInfo.cbSize := SizeOf (TScrollInfo); - ScrollBarInfo.fMask := SIF_ALL or SIF_DISABLENOSCROLL; - ScrollBarInfo.nMin := 0; - ScrollBarInfo.nMax := TotalSize; - ScrollBarInfo.nPage := PageSize; - ScrollBarInfo.nTrackPos := 0; - ScrollBarInfo.nPos := 0; + ScrollBarInfo.cbSize := SizeOf (TScrollInfo); + ScrollBarInfo.fMask := SIF_ALL or SIF_DISABLENOSCROLL; + ScrollBarInfo.nMin := 0; + ScrollBarInfo.nMax := TotalSize; + ScrollBarInfo.nPage := PageSize; + ScrollBarInfo.nTrackPos := 0; + ScrollBarInfo.nPos := 0; + SetScrollInfo (Handle, SB_VERT, ScrollBarInfo, True); end; -function TVpPrintPreview.IsFirstPage : Boolean; +function TVpPrintPreview.IsFirstPage: Boolean; begin Result := CurPage = 0; end; -function TVpPrintPreview.IsLastPage : Boolean; +function TVpPrintPreview.IsLastPage: Boolean; begin if FPageInfo.Count = 0 then Result := True - else if CurPage < FPageInfo.Count then - Result := PVpPageInfo (FPageInfo[CurPage]).LastPage + else + if CurPage < FPageInfo.Count then + Result := PVpPageInfo(FPageInfo[CurPage]).LastPage else begin GetLastPage; - Result := PVpPageInfo (FPageInfo[CurPage]).LastPage; + Result := PVpPageInfo(FPageInfo[CurPage]).LastPage; end; end; -function TVpPrintPreview.IsPageLoaded (PageNum : Integer) : Boolean; +function TVpPrintPreview.IsPageLoaded(PageNum: Integer): Boolean; begin Result := PageNum < FPageInfo.Count; end; - -procedure TVpPrintPreview.KeyDown (var Key: Word; Shift: TShiftState); +procedure TVpPrintPreview.KeyDown(var Key: Word; Shift: TShiftState); var - PopupPoint : TPoint; - + PopupPoint: TPoint; begin case Key of - VK_LEFT, VK_PRIOR : + VK_LEFT, VK_PRIOR : if ssCtrl in Shift then FirstPage else PrevPage; - VK_RIGHT, VK_NEXT : + + VK_RIGHT, VK_NEXT: if ssCtrl in Shift then LastPage else NextPage; - $5A : {z} + + $5A: {z} if ssCtrl in Shift then begin - if ZoomFactor = High (FZoomFactor) then - ZOomFactor := Low (FZoomFactor) + if ZoomFactor = High(FZoomFactor) then + ZOomFactor := Low(FZoomFactor) else - ZoomFactor := Succ (FZoomFactor); - end else if ssShift in Shift then begin - if ZoomFactor = Low (FZoomFactor) then - ZOomFactor := High (FZoomFactor) + ZoomFactor := Succ(FZoomFactor); + end else + if ssShift in Shift then begin + if ZoomFactor = Low(FZoomFactor) then + ZOomFactor := High(FZoomFactor) else - ZoomFactor := Pred (FZoomFactor); + ZoomFactor := Pred(FZoomFactor); end; - $46 : {f} - if (ssCtrl in Shift) and Assigned (ControlLink) then begin + $46: {f} + if (ssCtrl in Shift) and Assigned(ControlLink) then begin if ControlLink.Printer.CurFormat < ControlLink.Printer.PrintFormats.Count - 1 then ControlLink.Printer.CurFormat := ControlLink.Printer.CurFormat + 1 else ControlLink.Printer.CurFormat := 0; - end else if (ssShift in Shift) and Assigned (ControlLink) then begin + end else + if (ssShift in Shift) and Assigned(ControlLink) then begin if ControlLink.Printer.CurFormat > 0 then ControlLink.Printer.CurFormat := ControlLink.Printer.CurFormat - 1 else ControlLink.Printer.CurFormat := ControlLink.Printer.PrintFormats.Count - 1; end; - VK_TAB : - {$IFNDEF LCL} + {$IFDEF DELPHI} + VK_TAB: if ssShift in Shift then - Windows.SetFocus (GetNextDlgTabItem (GetParent(Handle), Handle, False)) + Windows.SetFocus(GetNextDlgTabItem(GetParent(Handle), Handle, False)) else - Windows.SetFocus (GetNextDlgTabItem (GetParent(Handle), Handle, True)); - {$ELSE} - ; - {$ENDIF} - VK_F10 : - if (ssShift in Shift) and not (Assigned (PopupMenu)) then begin + Windows.SetFocus(GetNextDlgTabItem(GetParent(Handle), Handle, True)); + {$ENDIF} + VK_F10: + if (ssShift in Shift) and not Assigned(PopupMenu) then begin PopupPoint := GetClientOrigin; - FDefaultPopup.Popup (PopupPoint.x + 10, - PopupPoint.y + 10); + FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10); end; - VK_APPS : + VK_APPS: if not Assigned (PopupMenu) then begin PopupPoint := GetClientOrigin; - FDefaultPopup.Popup (PopupPoint.x + 10, - PopupPoint.y + 10); + FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10); end; else inherited; @@ -669,15 +656,13 @@ end; procedure TVpPrintPreview.LastPage; var - i : Integer; - + 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 + if (not PVpPageInfo(FPageInfo[i]).LastPage) and (i < FPageInfo.Count) then + inc(i); + if (not PVpPageInfo(FPageInfo[i]).LastPage) then GetLastPage; end else GetLastPage; @@ -687,25 +672,22 @@ end; procedure TVpPrintPreview.Loaded; begin inherited Loaded; - DestPrinter := Printer; GeneratePageImage; end; -function TVpPrintPreview.LoadPage (PageNum : Integer; - StartDate : TDateTime; - EndDate : TDateTime) : Integer; { 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; var - i : Integer; - LastPage : Boolean; - PPageInfo : PVpPageInfo; - ADate : TDateTime; - ATask : Integer; - AContact : Integer; - + i: Integer; + LastPage: Boolean; + PPageInfo: PVpPageInfo; + ADate: TDateTime; + ATask: Integer; + AContact: Integer; begin Result := PageNum; if PageNum < FPageInfo.Count then @@ -721,7 +703,7 @@ begin LastPage := False; if FPageInfo.Count = 0 then begin - GetMem (PPageInfo, SizeOf (TVpPageInfo)); + GetMem(PPageInfo, SizeOf (TVpPageInfo)); PPageInfo.Date := StartDate; PPageInfo.Contact := 0; PPageInfo.Task := 0; @@ -730,40 +712,39 @@ begin i := 0; end; - PPageInfo := PVpPageInfo (FPageInfo[i]); - ADate := PPageInfo.Date; + PPageInfo := PVpPageInfo(FPageInfo[i]); + ADate := PPageInfo.Date; AContact := PPageInfo.Contact; - ATask := PPageInfo.Task; + 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); + 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; + GetMem(PPageInfo, SizeOf(TVpPageInfo)); + PPageInfo.Date := ADate; + PPageInfo.Task := ATask; + PPageInfo.Contact := AContact; PPageInfo.LastPage := LastPage; - FPageInfo.Add (PPageInfo); - Inc (i); + FPageInfo.Add(PPageInfo); + inc(i); end; end; procedure TVpPrintPreview.NextPage; begin if CurPage < FPageInfo.Count then begin - if not PVpPageInfo (FPageInfo[CurPage]).LastPage then + if not PVpPageInfo(FPageInfo[CurPage]).LastPage then CurPage := CurPage + 1; end else CurPage := CurPage + 1; @@ -771,8 +752,8 @@ end; procedure TVpPrintPreview.Paint; var - RealWidth : Integer; - RealHeight : Integer; + RealWidth: Integer; + RealHeight: Integer; procedure Clear; begin @@ -788,7 +769,7 @@ var RealHeight := ClientHeight; WorkBmp.Canvas.Brush.Color := FOffPageColor; - WorkBmp.Canvas.FillRect (ClientRect); + WorkBmp.Canvas.FillRect(ClientRect); WorkBmp.Canvas.Brush.Color := FPageColor; WorkBmp.Canvas.Pen.Color := FBorderColor; end; @@ -798,44 +779,41 @@ var if FBorderStyle = bsSingle then begin if FDrawingStyle = dsFlat then begin { draw an outer and inner bevel } - DrawBevelRect (WorkBmp.Canvas, - Rect (ClientRect.Left, - ClientRect.Top, - ClientRect.Right - 1, - ClientRect.Bottom - 1), - clBtnShadow, - clBtnHighlight); - DrawBevelRect (WorkBmp.Canvas, - Rect (ClientRect.Left + 1, - ClientRect.Top + 1, - ClientRect.Right - 2, - ClientRect.Bottom - 2), - clBtnHighlight, - clBtnShadow); - end else if FDrawingStyle = ds3d then begin + DrawBevelRect( + WorkBmp.Canvas, + Rect(ClientRect.Left, ClientRect.Top, ClientRect.Right - 1, ClientRect.Bottom - 1), + clBtnShadow, + clBtnHighlight + ); + DrawBevelRect( + WorkBmp.Canvas, + Rect(ClientRect.Left + 1, ClientRect.Top + 1, ClientRect.Right - 2, ClientRect.Bottom - 2), + clBtnHighlight, + clBtnShadow + ); + end else + if FDrawingStyle = ds3d then begin { draw a 3d bevel } - DrawBevelRect (WorkBmp.Canvas, - Rect (ClientRect.Left, - ClientRect.Top, - ClientRect.Right - 1, - ClientRect.Bottom - 1), - clBtnShadow, - clBtnHighlight); - DrawBevelRect (WorkBmp.Canvas, - Rect (ClientRect.Left + 1, - ClientRect.Top + 1, - ClientRect.Right - 2, - ClientRect.Bottom - 2), - cl3DDkShadow, - clBtnFace); + DrawBevelRect( + WorkBmp.Canvas, + Rect(ClientRect.Left, ClientRect.Top, ClientRect.Right - 1, ClientRect.Bottom - 1), + clBtnShadow, + clBtnHighlight + ); + DrawBevelRect( + WorkBmp.Canvas, + Rect(ClientRect.Left + 1, ClientRect.Top + 1, ClientRect.Right - 2, ClientRect.Bottom - 2), + cl3DDkShadow, + clBtnFace + ); end; end; end; procedure AddPageBorder; var - w : Integer; - h : Integer; + w: Integer; + h: Integer; begin if RealWidth > ClientWidth - 2 then w := ClientWidth - 2 @@ -846,34 +824,33 @@ var else h := RealHeight; WorkBmp.Canvas.Pen.Color := FBorderColor; - WorkBmp.Canvas.MoveTo (2, 2); - WorkBmp.Canvas.LineTo (2, h); - WorkBmp.Canvas.MoveTo (2, 2); - WorkBmp.Canvas.LineTo (w, 2); + WorkBmp.Canvas.MoveTo(2, 2); + WorkBmp.Canvas.LineTo(2, h); + WorkBmp.Canvas.MoveTo(2, 2); + WorkBmp.Canvas.LineTo(w, 2); if (RealWidth < ClientWidth - 2) then begin - WorkBmp.Canvas.MoveTo (RealWidth, 2); - WorkBmp.Canvas.LineTo (RealWidth, h + 1); + WorkBmp.Canvas.MoveTo(RealWidth, 2); + WorkBmp.Canvas.LineTo(RealWidth, h + 1); end; if (RealHeight < ClientHeight - 2) then begin - WorkBmp.Canvas.MoveTo (2, RealHeight); - WorkBmp.Canvas.LineTo (w + 1, RealHeight); + WorkBmp.Canvas.MoveTo(2, RealHeight); + WorkBmp.Canvas.LineTo(w + 1, RealHeight); end; end; - function GetAspectRectangle : TRect; + function GetAspectRectangle: TRect; var - ScaleX : Extended; - ScaleY : Extended; - Offset1 : Integer; - Offset2 : Integer; - + ScaleX: Extended; + ScaleY: Extended; + Offset1: Integer; + Offset2: Integer; begin Offset1 := 3; Offset2 := 3; - if Assigned (FPrinter) then begin + if Assigned(FPrinter) then begin if ClientWidth - (Offset1 + Offset2) <> 0 then ScaleX := FPrinter.PageWidth / (ClientWidth - (Offset1 + Offset2)) else @@ -883,22 +860,28 @@ var else ScaleY := 1; if ScaleX > ScaleY then - Result := Rect (Offset1, Offset1, ClientWidth - Offset2, - Round (FPrinter.PageHeight / ScaleX)) + Result := Rect( + Offset1, + Offset1, + ClientWidth - Offset2, + Round(FPrinter.PageHeight / ScaleX) + ) else - Result := Rect (Offset1, Offset1, - Round (FPrinter.PageWidth / ScaleY), - ClientHeight - Offset2); + Result := Rect( + Offset1, + Offset1, + Round(FPrinter.PageWidth / ScaleY), + ClientHeight - Offset2 + ); end else - Result := Rect (3, 3, ClientWidth, ClientHeight); + Result := Rect(3, 3, ClientWidth, ClientHeight); end; procedure DrawPreview; var - AspectRect : TRect; - WorkHeight : Integer; - WorkWidth : Integer; - + AspectRect: TRect; + WorkHeight: Integer; + WorkWidth: Integer; begin if FControlLink.Printer.PrintFormats.Count <= 0 then Exit; @@ -906,15 +889,49 @@ var if CurPage > FPageInfo.Count then GeneratePageImage; + if FZoomFactor = zfFitToControl then + begin + AspectRect := GetAspectRectangle; + WorkBmp.Canvas.CopyRect( + AspectRect, + RenderBmp.Canvas, + Rect (0, 0, RenderBmp.Width, RenderBmp.Height) + ); + RealWidth := AspectRect.Right - AspectRect.Left + 3; + RealHeight := AspectRect.Bottom - AspectRect.Top + 3; + end else + begin + WorkWidth := Round(RenderBmp.Width * ZOOM_FACTOR_VALUES[FZoomFactor]); + WorkHeight := Round(RenderBmp.Height * ZOOM_FACTOR_VALUES[FZoomFactor]); + if WorkHeight > ClientHeight - 3 then WorkHeight := ClientHeight - 3; + if WorkWidth > ClientWidth - 3 then WorkWidth := ClientWidth - 3; + WorkBmp.Canvas.CopyRect( + Rect(3, 3, WorkWidth, WorkHeight), + RenderBmp.Canvas, + Rect( + Round(FScrollX / ZOOM_FACTOR_VALUES[FZoomFactor]), + Round(FScrollY / ZOOM_FACTOR_VALUES[FZoomFactor]), + Round((WorkWidth + FScrollX) / ZOOM_FACTOR_VALUES[FZoomFactor]), + Round((WorkHeight + FScrollY) / ZOOM_FACTOR_VALUES[FZoomFactor]) + ) + ); + RealWidth := round(RenderBmp.Width / ZOOM_FACTOR_VALUES[FZoomFactor]); + RealHeight := round(RenderBmp.Height / ZOOM_FACTOR_VALUES[FZoomFactor]); + end; + + (* case FZoomFactor of - zfFitToControl : begin - AspectRect := GetAspectRectangle; - WorkBmp.Canvas.CopyRect (AspectRect, RenderBmp.Canvas, - Rect (0, 0, - RenderBmp.Width, RenderBmp.Height)); - RealWidth := AspectRect.Right - AspectRect.Left + 3; - RealHeight := AspectRect.Bottom - AspectRect.Top + 3; - end; + zfFitToControl: + begin + AspectRect := GetAspectRectangle; + WorkBmp.Canvas.CopyRect( + AspectRect, + RenderBmp.Canvas, + Rect (0, 0, RenderBmp.Width, RenderBmp.Height) + ); + RealWidth := AspectRect.Right - AspectRect.Left + 3; + RealHeight := AspectRect.Bottom - AspectRect.Top + 3; + end; zf25Percent : begin WorkWidth := Round (RenderBmp.Width div 4); @@ -1024,6 +1041,7 @@ var RealHeight := RenderBmp.Height; end; end; + *) end; procedure RenderImage; @@ -1050,43 +1068,41 @@ begin CurPage := CurPage - 1; end; -procedure TVpPrintPreview.PopupFirstPage (Sender : TObject); +procedure TVpPrintPreview.PopupFirstPage(Sender: TObject); begin FirstPage; end; -procedure TVpPrintPreview.PopupLastPage (Sender : TObject); +procedure TVpPrintPreview.PopupLastPage(Sender: TObject); begin LastPage; end; -procedure TVpPrintPreview.PopupNextPage (Sender : TObject); +procedure TVpPrintPreview.PopupNextPage(Sender: TObject); begin NextPage; end; -procedure TVpPrintPreview.PopupPrevPage (Sender : TObject); +procedure TVpPrintPreview.PopupPrevPage(Sender: TObject); begin PrevPage; end; procedure TVpPrintPreview.RemoveHScrollbar; var - Style : Integer; - + Style: Integer; begin FNeedHScroll := False; - Style := GetWindowLong (Handle, GWL_STYLE); + Style := GetWindowLong(Handle, GWL_STYLE); if ((Style and WS_HSCROLL) <> 0) then begin - SetWindowLong (Handle, GWL_STYLE, Style and not WS_HSCROLL); + SetWindowLong(Handle, GWL_STYLE, Style and not WS_HSCROLL); RecreateWnd{$IFDEF LCL}(Self){$ENDIF}; end; end; procedure TVpPrintPreview.RemoveVScrollbar; var - Style : Integer; - + Style: Integer; begin FNeedVScroll := False; Style := GetWindowLong (Handle, GWL_STYLE); @@ -1096,7 +1112,7 @@ begin end; end; -procedure TVpPrintPreview.SetBorderColor (const v : TColor); +procedure TVpPrintPreview.SetBorderColor(const v: TColor); begin if v <> FBorderColor then begin FBorderColor := v; @@ -1104,7 +1120,7 @@ begin end; end; -procedure TVpPrintPreview.SetBorderStyle (const v : TBorderStyle); +procedure TVpPrintPreview.SetBorderStyle(const v: TBorderStyle); begin if v <> FBorderStyle then begin FBorderStyle := v; @@ -1112,40 +1128,40 @@ begin end; end; -procedure TVpPrintPreview.SetBounds (ALeft, ATop, AWidth, AHeight: Integer); +procedure TVpPrintPreview.SetBounds(ALeft, ATop, AWidth, AHeight: Integer); begin - inherited SetBounds (aLeft, ATop, AWidth, AHeight); + inherited SetBounds(ALeft, ATop, AWidth, AHeight); SetScrollBars; end; -procedure TVpPrintPreview.SetControlLink (const v : TVpControlLink); +procedure TVpPrintPreview.SetControlLink(const v: TVpControlLink); begin if FControlLink <> v then begin if Assigned (FControlLink) then - FControlLink.Printer.DeregisterWatcher (Handle); + FControlLink.Printer.DeregisterWatcher(Handle); FControlLink := v; - if Assigned (FControlLink) then - FControlLink.Printer.RegisterWatcher (Handle); + if Assigned(FControlLink) then + FControlLink.Printer.RegisterWatcher(Handle); ClearPageData; GeneratePageImage; Invalidate; end; end; -procedure TVpPrintPreview.SetCurPage (const v : Integer); +procedure TVpPrintPreview.SetCurPage(const v: Integer); begin if (v >= 0) and (v <> FCurPage) then begin FCurPage := v; if not (csDestroying in ComponentState) then begin GeneratePageImage; Invalidate; - if Assigned (FOnPageChange) then - FOnPageChange (Self, FCurPage); + if Assigned(FOnPageChange) then + FOnPageChange(Self, FCurPage); end; end; end; -procedure TVpPrintPreview.SetDrawingStyle (const v : TVpDrawingStyle); +procedure TVpPrintPreview.SetDrawingStyle(const v: TVpDrawingStyle); begin if v <> FDrawingStyle then begin FDrawingStyle := v; @@ -1153,7 +1169,7 @@ begin end; end; -procedure TVpPrintPreview.SetEndDate (const v : TDateTime); +procedure TVpPrintPreview.SetEndDate(const v: TDateTime); begin if v <> FEndDate then begin FEndDate := v; @@ -1163,7 +1179,7 @@ begin end; end; -procedure TVpPrintPreview.SetOffPageColor (const v : TColor); +procedure TVpPrintPreview.SetOffPageColor(const v: TColor); begin if v <> FOffPageColor then begin FOffPageColor := v; @@ -1171,7 +1187,7 @@ begin end; end; -procedure TVpPrintPreview.SetPageColor (const v : TColor); +procedure TVpPrintPreview.SetPageColor(const v: TColor); begin if v <> FPageColor then begin FPageColor := v; @@ -1179,12 +1195,12 @@ begin end; end; -procedure TVpPrintPreview.SetPrinter (const v : TPrinter); +procedure TVpPrintPreview.SetPrinter(const v: TPrinter); begin if FPrinter <> v then begin FPrinter := v; - RenderBmp.Width := CalculatePageWidth (v); - RenderBmp.Height := CalculatePageHeight (v); + RenderBmp.Width := CalculatePageWidth(v); + RenderBmp.Height := CalculatePageHeight(v); ClearPageData; GeneratePageImage; end; @@ -1192,11 +1208,10 @@ end; procedure TVpPrintPreview.SetScrollBars; var - RealWidth : Integer; - RealHeight : Integer; - Style : Integer; - NeedRecreate : Boolean; - + RealWidth: Integer; + RealHeight: Integer; + Style: Integer; + NeedRecreate: Boolean; begin if csDesigning in ComponentState then Exit; @@ -1204,69 +1219,46 @@ begin FScrollX := 0; FScrollY := 0; RealHeight := ClientHeight; - RealWidth := ClientWidth; - case ZoomFactor of - zfActualSize : begin - RealHeight := RenderBmp.Height; - RealWidth := RenderBmp.Width; - end; - zfFitToControl : begin - RealHeight := ClientHeight - 4; - RealWidth := ClientWidth - 4; - end; - zf25Percent : begin - RealHeight := RenderBmp.Height div 4; - RealWidth := RenderBmp.Width div 4; - end; - zf33Percent : begin - RealHeight := RenderBmp.Height div 3; - RealWidth := RenderBmp.Width div 3; - end; - zf50Percent : begin - RealHeight := RenderBmp.Height div 2; - RealWidth := RenderBmp.Width div 2; - end; - zf67Percent : begin - RealHeight := Round (RenderBmp.Height * 0.67); - RealWidth := Round (RenderBmp.Width * 0.67); - end; - zf75Percent : begin - RealHeight := Round (RenderBmp.Height * 0.75); - RealWidth := Round (RenderBmp.Width * 0.75); - end; + RealWidth := ClientWidth; + if ZoomFactor = zfFitToControl then begin + RealHeight := ClientHeight - 4; + RealWidth := ClientWidth - 4; + end else begin + RealHeight := Round(RenderBmp.Height * ZOOM_FACTOR_VALUES[ZoomFactor]); + RealWidth := Round(RenderBmp.Width * ZOOM_FACTOR_VALUES[ZoomFactor]); end; if (RealWidth > ClientWidth) or (RealHeight > ClientHeight) then begin NeedRecreate := False; - Style := GetWindowLong (Handle, GWL_STYLE); - if ((Style and WS_HSCROLL) = 0) and (RealWidth > ClientWidth) then begin + Style := GetWindowLong(Handle, GWL_STYLE); + if (Style and WS_HSCROLL = 0) and (RealWidth > ClientWidth) then begin Style := Style or WS_HSCROLL; FNeedHScroll := True; NeedRecreate := True; end; - if ((Style and WS_VSCROLL) = 0) and (RealHeight > ClientHeight) then begin + if (Style and WS_VSCROLL = 0) and (RealHeight > ClientHeight) then begin Style := Style or WS_VSCROLL; FNeedVScroll := True; NeedRecreate := True; end; if NeedRecreate then begin - SetWindowLong (Handle, GWL_STYLE, Style); + SetWindowLong(Handle, GWL_STYLE, Style); RecreateWnd{$IFDEF LCL}(Self){$ENDIF}; end; end; if (RealWidth > ClientWidth) then - InitHScrollBar (ClientWidth, RealWidth) + InitHScrollBar(ClientWidth, RealWidth) else RemoveHScrollbar; if (RealHeight > ClientHeight) then - InitVScrollBar (ClientHeight, RealHeight) + InitVScrollBar(ClientHeight, RealHeight) else RemoveVScrollbar; end; -procedure TVpPrintPreview.SetStartDate (const v : TDateTime); +procedure TVpPrintPreview.SetStartDate(const v: TDateTime); begin if v <> FStartDate then begin FStartDate := v; @@ -1276,7 +1268,7 @@ begin end; end; -procedure TVpPrintPreview.SetZoomFactor (const v : TVpPPZoomFactor); +procedure TVpPrintPreview.SetZoomFactor(const v: TVpPPZoomFactor); begin if v <> FZoomFactor then begin FZoomFactor := v; @@ -1286,53 +1278,36 @@ begin end; {$IFNDEF LCL} -procedure TVpPrintPreview.VpPrintFormatChanged (var Msg : {$IFNDEF LCL}TMessage{$ELSE}TLMessage{$ENDIF}); +procedure TVpPrintPreview.VpPrintFormatChanged(var Msg: {$IFNDEF LCL}TMessage{$ELSE}TLMessage{$ENDIF}); begin ForceUpdate; end; {$ENDIF} -{$IFNDEF LCL} -procedure TVpPrintPreview.WMEraseBackground (var Msg : TWMERASEBKGND); -{$ELSE} -procedure TVpPrintPreview.WMEraseBackground (var Msg : TLMERASEBKGND); -{$ENDIF} +procedure TVpPrintPreview.WMEraseBackground(var Msg: {$IFDEF DELPHI}TWMERASEBKGND){$ELSE}TLMERASEBKGND){$ENDIF}; begin Msg.Result := 1; end; -{$IFNDEF LCL} -procedure TVpPrintPreview.WMVScroll (var Msg : TWMSCROLL); -{$ELSE} -procedure TVpPrintPreview.WMVScroll (var Msg : TLMSCROLL); -{$ENDIF} +procedure TVpPrintPreview.WMVScroll(var Msg: {$IFDEF DELPHI}TWMSCROLL){$ELSE}TLMSCROLL{$ENDIF}); begin - DoScroll (Msg, SB_VERT); + DoScroll(Msg, SB_VERT); end; -{$IFNDEF LCL} -procedure TVpPrintPreview.WMHScroll (var Msg : TWMSCROLL); -{$ELSE} -procedure TVpPrintPreview.WMHScroll (var Msg : TLMSCROLL); -{$ENDIF} +procedure TVpPrintPreview.WMHScroll(var Msg: {$IFDEF DELPHI}TWMSCROLL){$ELSE}TLMSCROLL){$ENDIF}; begin - DoScroll (Msg, SB_HORZ); + DoScroll(Msg, SB_HORZ); end; -{$IFNDEF LCL} -procedure TVpPrintPreview.WMRButtonDown(var Msg : TWMRButtonDown); -{$ELSE} -procedure TVpPrintPreview.WMRButtonDown(var Msg : TLMRButtonDown); -{$ENDIF} +procedure TVpPrintPreview.WMRButtonDown(var Msg: {$IFDEF DELPHI}TWMRButtonDown{$ELSE}TLMRButtonDown{$ENDIF}); var - ClientOrigin : TPoint; - i : Integer; - + ClientOrigin: TPoint; + i: Integer; begin inherited; if not Assigned (PopupMenu) then begin - if not focused then + if not Focused then SetFocus; ClientOrigin := GetClientOrigin; @@ -1344,8 +1319,7 @@ begin FDefaultPopup.Items[i].Enabled := False; end; - FDefaultPopup.Popup (Msg.XPos + ClientOrigin.x, - Msg.YPos + ClientOrigin.y); + FDefaultPopup.Popup(Msg.XPos + ClientOrigin.x, Msg.YPos + ClientOrigin.y); end; end; diff --git a/components/tvplanit/source/vpprtprvdlg.lfm b/components/tvplanit/source/vpprtprvdlg.lfm index 91c42783c..ff050208e 100644 --- a/components/tvplanit/source/vpprtprvdlg.lfm +++ b/components/tvplanit/source/vpprtprvdlg.lfm @@ -16,17 +16,17 @@ object frmPrintPreview: TfrmPrintPreview LCLVersion = '1.7' object Panel1: TPanel Left = 0 - Height = 73 + Height = 62 Top = 0 Width = 477 Align = alTop - ClientHeight = 73 + ClientHeight = 62 ClientWidth = 477 TabOrder = 0 object cboxZoom: TComboBox - Left = 217 + Left = 216 Height = 23 - Top = 40 + Top = 32 Width = 145 ItemHeight = 15 Items.Strings = ( @@ -45,7 +45,7 @@ object frmPrintPreview: TfrmPrintPreview object VpPrintFormatComboBox1: TVpPrintFormatComboBox Left = 8 Height = 23 - Top = 40 + Top = 32 Width = 201 ItemHeight = 15 Sorted = True @@ -69,13 +69,13 @@ object frmPrintPreview: TfrmPrintPreview TabOrder = 0 object btnPrint: TToolButton Left = 1 - Top = 2 + Top = 0 Action = actPrint end object ToolButton3: TToolButton Left = 52 Height = 25 - Top = 2 + Top = 0 Width = 8 Caption = 'ToolButton3' ImageIndex = 2 @@ -83,32 +83,32 @@ object frmPrintPreview: TfrmPrintPreview end object btnFirstPage: TToolButton Left = 60 - Top = 2 + Top = 0 Action = actFirstPage ShowCaption = False end object btnPrevPage: TToolButton Left = 85 - Top = 2 + Top = 0 Action = actPrevPage ShowCaption = False end object btnNextPage: TToolButton Left = 110 - Top = 2 - Action = actPrevPage + Top = 0 + Action = actNextPage ShowCaption = False end object btnLastPage: TToolButton Left = 135 - Top = 2 + Top = 0 Action = actLastPage ShowCaption = False end object ToolButton8: TToolButton Left = 160 Height = 25 - Top = 2 + Top = 0 Width = 8 Caption = 'ToolButton8' ImageIndex = 6 @@ -116,15 +116,15 @@ object frmPrintPreview: TfrmPrintPreview end object btnCancel: TToolButton Left = 168 - Top = 2 + Top = 0 Action = actCancel end end end object VpPrintPreview1: TVpPrintPreview Left = 0 - Height = 445 - Top = 73 + Height = 456 + Top = 62 Width = 477 CurPage = 0 EndDate = 37355.4526088079