From ab7f8386d85e1992a7f62cf1cced78eff9a98121 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 21 Jun 2016 20:03:42 +0000 Subject: [PATCH] tvplanit: Some more refactoring of VpPrtFmt git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4794 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpprtfmt.pas | 216 ++++++++++++------------ 1 file changed, 107 insertions(+), 109 deletions(-) diff --git a/components/tvplanit/source/vpprtfmt.pas b/components/tvplanit/source/vpprtfmt.pas index 82fb9d540..ffc1098ca 100644 --- a/components/tvplanit/source/vpprtfmt.pas +++ b/components/tvplanit/source/vpprtfmt.pas @@ -377,7 +377,7 @@ type FTaskList: TComponent; { Notification Handles } FNotifiers: TList; - FDefaultXMLFileName: string; + FDefaultXMLFileName: string; protected procedure CreateWorkControls; @@ -393,8 +393,8 @@ type procedure SetRightMargin(const v: Extended); procedure SetTopMargin(const v: Extended); procedure SetUseFormComponents(const v: Boolean); - procedure xmlPrintFormatAttribute(oOwner: TObject; - sName, sValue: DOMString; bSpecified: Boolean); + procedure xmlPrintFormatAttribute(oOwner: TObject; sName, sValue: DOMString; + bSpecified: Boolean); procedure xmlPrintFormatEndElement(oOwner: TObject; sValue: DOMString); procedure xmlPrintFormatStartElement(oOwner: TObject; sValue: DOMString); @@ -425,7 +425,6 @@ type procedure UpdateDateVariables(Date: TDateTime); function ValidFormat(const v: Integer): Boolean; - property Calendar: TComponent read FCalendar write FCalendar; property ContactGrid: TComponent read FContactGrid write FContactGrid; property CurFormat: Integer read FCurFormat write SetCurFormat; @@ -583,39 +582,39 @@ begin case FShape of ustRectangle: {$IFDEF VERSION5} - ACanvas.Rectangle (ARect); + ACanvas.Rectangle(ARect); {$ELSE} - ACanvas.Rectangle (ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); + ACanvas.Rectangle(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); {$ENDIF} ustTopLine: begin - ACanvas.MoveTo (ARect.Left, ARect.Top); - ACanvas.LineTo (ARect.Right, ARect.Top); + ACanvas.MoveTo(ARect.Left, ARect.Top); + ACanvas.LineTo(ARect.Right, ARect.Top); end; ustBottomLine: begin - ACanvas.MoveTo (ARect.Left, ARect.Bottom); - ACanvas.LineTo (ARect.Right, ARect.Bottom); + ACanvas.MoveTo(ARect.Left, ARect.Bottom); + ACanvas.LineTo(ARect.Right, ARect.Bottom); end; ustLeftLine: begin - ACanvas.MoveTo (ARect.Left, ARect.Top); - ACanvas.LineTo (ARect.Left, ARect.Bottom); + ACanvas.MoveTo(ARect.Left, ARect.Top); + ACanvas.LineTo(ARect.Left, ARect.Bottom); end; ustRightLine: begin - ACanvas.MoveTo (ARect.Right, ARect.Top); - ACanvas.LineTo (ARect.Right, ARect.Bottom); + ACanvas.MoveTo(ARect.Right, ARect.Top); + ACanvas.LineTo(ARect.Right, ARect.Bottom); end; ustTLToBRLine: begin - ACanvas.MoveTo (ARect.Left, ARect.Top); - ACanvas.LineTo (ARect.Right, ARect.Bottom); + ACanvas.MoveTo(ARect.Left, ARect.Top); + ACanvas.LineTo(ARect.Right, ARect.Bottom); end; ustBLToTRLine: begin - ACanvas.MoveTo (ARect.Left, ARect.Bottom); - ACanvas.LineTo (ARect.Right, ARect.Top); + ACanvas.MoveTo(ARect.Left, ARect.Bottom); + ACanvas.LineTo(ARect.Right, ARect.Top); end; ustEllipse: ACanvas.Ellipse(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); @@ -697,7 +696,7 @@ constructor TVpPrintFormatElementItem.Create(Collection: TCollection); begin inherited Create(Collection); FCollection := TVpPrintFormatElement.Create(TVpPrintFormatElement(Collection).FOwner); - FShape := TVpPrintShape.Create(Self); + FShape := TVpPrintShape.Create(Self); FCaption := TVpPrintCaption.Create(Self); FRotation := ra0; FElementName := ''; @@ -753,7 +752,7 @@ begin if v = FDayOffset then Exit; - if Assigned (FCollection) then begin + if Assigned(FCollection) then begin FCollection.BeginUpdate; FDayOffset := v; FCollection.EndUpdate; @@ -965,14 +964,13 @@ end; procedure TVpPrintFormatElement.NotifyAll(Item: TCollectionItem); var Notifier: TPersistent; - begin if not Assigned (FOwner) then Exit; if FOwner is TVpPrintFormatItem then begin if Assigned(TVpPrintFormatItem(FOwner).FCollection) then - TVpPrintFormatItem (FOwner).FCollection.NotifyAll((TVpPrintFormatItem (FOwner))); + TVpPrintFormatItem(FOwner).FCollection.NotifyAll((TVpPrintFormatItem(FOwner))); end; if FOwner is TVpPrintFormatItem then @@ -1003,7 +1001,7 @@ end; procedure TVpPrintFormatElement.Notify(Item: TCollectionItem; Action: TCollectionNotification); begin inherited Notify(Item, Action); - NotifyAll (Item); + NotifyAll(Item); end; {$ENDIF} {=====} @@ -1167,7 +1165,6 @@ end; {=====} - // TVpPrintFormat ************************************************************ constructor TVpPrintFormat.Create(AOwner: TPersistent); @@ -1335,7 +1332,6 @@ procedure TVpPrinter.AddDefaultVariables(Date: TDateTime); DataStore: TVpCustomDataStore; i: Integer; TopLevel: TComponent; - begin if not Assigned(FOwner) then Exit; @@ -1353,7 +1349,7 @@ procedure TVpPrinter.AddDefaultVariables(Date: TDateTime); end; if Assigned(DataStore) then begin - AddVariable('ResourceID', IntToStr (DataStore.ResourceID)); + AddVariable('ResourceID', IntToStr(DataStore.ResourceID)); if Assigned(DataStore.Resource) then begin AddVariable('Resource', DataStore.Resource.Description); AddVariable('ResourceNotes', DataStore.Resource.Notes); @@ -1423,7 +1419,7 @@ end; procedure TVpPrinter.CreateWorkControls; begin {$IFNDEF LCL} - FParentHandle := AllocateHWnd (nil); + FParentHandle := AllocateHWnd(nil); FDayView := TVpDayView.CreateParented(FParentHandle); FWeekView := TVpWeekView.CreateParented(FParentHandle); FMonthView := TVpMonthView.CreateParented(FParentHandle); @@ -1437,7 +1433,7 @@ end; procedure TVpPrinter.DestroyWorkControls; begin {$IFNDEF LCL} - DeallocateHWnd (FParentHandle); + DeallocateHWnd(FParentHandle); FDayView.Free; FWeekView.Free; FMonthView.Free; @@ -1564,7 +1560,7 @@ var i: Integer; begin for i := 0 to FNotifiers.Count - 1 do - if Assigned (FNotifiers[i]) then + if Assigned(FNotifiers[i]) then PostMessage(PVpWatcher(FNotifiers[i]).Handle, Vp_PrintFormatChanged, 0, 0); end; {=====} @@ -1611,9 +1607,9 @@ var imPercent: begin - StartX := Round(Element.Left * WidthInPixels / 100); - StartY := Round(Element.Top * HeightInPixels / 100); - StopX := Round((Element.Left + Element.Width) * WidthInPixels / 100); + StartX := Round(Element.Left * WidthInPixels / 100); + StartY := Round(Element.Top * HeightInPixels / 100); + StopX := Round((Element.Left + Element.Width) * WidthInPixels / 100); StopY := Round((Element.Top + Element.Height) * HeightInPixels / 100); end; @@ -1628,8 +1624,8 @@ var inc(StartX, ARect.Left); inc(StartY, ARect.Top); - inc(StopX, ARect.Left); - inc(StopY, ARect.Top); + inc(StopX, ARect.Left); + inc(StopY, ARect.Top); end; function GetDate(Element: TVpPrintFormatElementItem): TDateTime; @@ -1661,7 +1657,7 @@ var for i := 0 to DependentList.Count - 1 do begin DI := TVpDependentInfo(DependentList.List^[I]); if TVpLinkableControl(DI.Component).GetControlType = Element.ItemType then begin - RenderControl := TVpLinkableControl (DI.Component); + RenderControl := TVpLinkableControl(DI.Component); Break; end; end; @@ -1683,20 +1679,20 @@ var case Element.ItemType of itTasks: begin - FHaveTaskList := True; - RenderControl.RenderToCanvas( - ACanvas, - Rect(StartX, StartY, StopX, StopY), - Element.Rotation, - Scale, - GetDate(Element), - FLastTask, - EndLine, - Granularity, - True - ); - FLastTask := RenderControl.GetLastPrintLine; - end; + FHaveTaskList := True; + RenderControl.RenderToCanvas( + ACanvas, + Rect(StartX, StartY, StopX, StopY), + Element.Rotation, + Scale, + GetDate(Element), + FLastTask, + EndLine, + Granularity, + True + ); + FLastTask := RenderControl.GetLastPrintLine; + end; itContacts: begin @@ -1739,6 +1735,7 @@ var var i: Integer; + elem: TVpPrintFormatElementItem; begin CheckPrintFormat; @@ -1759,34 +1756,35 @@ begin raise EVpPrintFormatError.Create(RSBadPrintFormat + IntToStr(CurFormat)); for i := 0 to FPrintFormats.Items[CurFormat].Elements.Count - 1 do begin - GetPrintRectangle(FPrintFormats.Items[CurFormat].Elements.Items[i]); + elem := FPrintFormats.Items[CurFormat].Elements.Items[i]; + GetPrintRectangle(elem); - if FPrintFormats.Items[CurFormat].Elements.Items[i].ItemType = itCaption then begin - if FPrintFormats.Items[CurFormat].Elements.Items[i].Visible then begin - UpdateDateVariables(GetDate(FPrintFormats.Items[CurFormat].Elements.Items[i])); - ACanvas.Font.Assign(FPrintFormats.Items[CurFormat].Elements.Items[i].FCaption.Font); - FPrintFormats.Items[CurFormat].Elements.Items[i].FCaption.PaintToCanvas( + if elem.ItemType = itCaption then begin + if elem.Visible then begin + UpdateDateVariables(GetDate(elem)); + ACanvas.Font.Assign(elem.FCaption.Font); + elem.FCaption.PaintToCanvas( ACanvas, Rect(StartX, StartY, StopX, StopY), - FPrintFormats.Items[CurFormat].Elements.Items[i].Rotation, + elem.Rotation, ARect, - ReplaceVariables(FPrintFormats.Items[CurFormat].Elements.Items[i].FCaption.Caption) + ReplaceVariables(elem.FCaption.Caption) ); end; end else - if FPrintFormats.Items[CurFormat].Elements.Items[i].ItemType = itShape then begin - if FPrintFormats.Items[CurFormat].Elements.Items[i].Visible then begin - ACanvas.Pen.Assign(FPrintFormats.Items[CurFormat].Elements.Items[i].FShape.Pen); - ACanvas.Brush.Assign(FPrintFormats.Items[CurFormat].Elements.Items[i].FShape.Brush); - FPrintFormats.Items[CurFormat].Elements.Items[i].FShape.PaintToCanvas( + if elem.ItemType = itShape then begin + if elem.Visible then begin + ACanvas.Pen.Assign(elem.FShape.Pen); + ACanvas.Brush.Assign(elem.FShape.Brush); + elem.FShape.PaintToCanvas( ACanvas, Rect(StartX, StartY, StopX, StopY), - FPrintFormats.Items[CurFormat].Elements.Items[i].Rotation, + elem.Rotation, ARect - ) + ); end; end else - RenderItem(FPrintFormats.Items[CurFormat].Elements.Items[i]); + RenderItem(elem); end; end; {=====} @@ -1953,7 +1951,6 @@ procedure TVpPrinter.RegisterWatcher(Watcher: THandle); var i: Integer; NewHandle: PVpWatcher; - begin for i := 0 to FNotifiers.Count - 1 do if Assigned(FNotifiers[i]) then @@ -2178,13 +2175,9 @@ begin TriggerOnGetVariable(Self, VarName, Found, Value, Change); case Change of - cvChange: - Result := Result + LookupVariable(VarName); - cvIgnore : - Result := Result + '$' + VarName + s[i - 1]; - cvRemove : - begin - end; + cvChange : Result := Result + LookupVariable(VarName); + cvIgnore : Result := Result + '$' + VarName + s[i - 1]; + cvRemove : ; end; end; end; @@ -2195,7 +2188,8 @@ var fpOut: TextFile; i: Integer; j: Integer; - + fmt: TVpPrintFormatItem; + elem: TVpPrintFormatElementItem; begin if FileName = '' then FileName := DefaultXMLFileName; @@ -2206,35 +2200,39 @@ begin Writeln(fpOut, ''); Writeln(fpOut, ''); + for i := 0 to FPrintFormats.Count - 1 do begin + fmt := FPrintFormats.Items[i]; Writeln(fpOut, ' '); duWeek : Writeln(fpOut, ' DayIncrementUnits="Week">'); duMonth : Writeln(fpOut, ' DayIncrementUnits="Month">'); duYear : Writeln(fpOut, ' DayIncrementUnits="Year">'); end; - for j := 0 to FPrintFormats.Items[i].Elements.Count - 1 do begin + + for j := 0 to fmt.Elements.Count - 1 do begin + elem := fmt.Elements.Items[j]; Writeln(fpOut, ' '); duWeek : Writeln(fpOut, ' DayOffsetUnits="Week">'); duMonth : Writeln(fpOut, ' DayOffsetUnits="Month">'); duYear : Writeln(fpOut, ' DayOffsetUnits="Year">'); end; - if FPrintFormats.Items[i].Elements.Items[j].ItemType = itShape then begin + if elem.ItemType = itShape then begin Writeln(fpOut, ' '); ustTopLine : Writeln(fpOut, ' Type="TopLine">'); ustBottomLine : Writeln(fpOut, ' Type="BottomLine">'); @@ -2275,8 +2273,8 @@ begin end; Writeln(fpOut, ' '); bsClear : Writeln(fpOut, ' Style="Clear"/>'); bsHorizontal : Writeln(fpOut, ' Style="Horizontal"/>'); @@ -2287,8 +2285,8 @@ begin bsDiagCross : Writeln(fpOut, ' Style="DiagCross"/>'); end; Writeln(fpOut, ' '); + Writeln(fpOut, ' Width="' + IntToStr(elem.FShape.Pen.Width) + '"/>'); Writeln(fpOut, ' '); end; - if FPrintFormats.Items[i].Elements.Items[j].ItemType = itCaption then begin + if elem.ItemType = itCaption then begin Writeln(fpOut, ' '); + Writeln(fpOut, ' Caption="' + XMLizeString(elem.Caption.Caption) + '">'); Writeln(fpOut, ' ') else Writeln(fpOut, ' Strikeout="False"/>');