tvplanit: Some more refactoring of VpPrtFmt

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4794 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-21 20:03:42 +00:00
parent 8116ba68c4
commit ab7f8386d8

View File

@@ -393,8 +393,8 @@ type
procedure SetRightMargin(const v: Extended); procedure SetRightMargin(const v: Extended);
procedure SetTopMargin(const v: Extended); procedure SetTopMargin(const v: Extended);
procedure SetUseFormComponents(const v: Boolean); procedure SetUseFormComponents(const v: Boolean);
procedure xmlPrintFormatAttribute(oOwner: TObject; procedure xmlPrintFormatAttribute(oOwner: TObject; sName, sValue: DOMString;
sName, sValue: DOMString; bSpecified: Boolean); bSpecified: Boolean);
procedure xmlPrintFormatEndElement(oOwner: TObject; sValue: DOMString); procedure xmlPrintFormatEndElement(oOwner: TObject; sValue: DOMString);
procedure xmlPrintFormatStartElement(oOwner: TObject; sValue: DOMString); procedure xmlPrintFormatStartElement(oOwner: TObject; sValue: DOMString);
@@ -425,7 +425,6 @@ type
procedure UpdateDateVariables(Date: TDateTime); procedure UpdateDateVariables(Date: TDateTime);
function ValidFormat(const v: Integer): Boolean; function ValidFormat(const v: Integer): Boolean;
property Calendar: TComponent read FCalendar write FCalendar; property Calendar: TComponent read FCalendar write FCalendar;
property ContactGrid: TComponent read FContactGrid write FContactGrid; property ContactGrid: TComponent read FContactGrid write FContactGrid;
property CurFormat: Integer read FCurFormat write SetCurFormat; property CurFormat: Integer read FCurFormat write SetCurFormat;
@@ -965,7 +964,6 @@ end;
procedure TVpPrintFormatElement.NotifyAll(Item: TCollectionItem); procedure TVpPrintFormatElement.NotifyAll(Item: TCollectionItem);
var var
Notifier: TPersistent; Notifier: TPersistent;
begin begin
if not Assigned (FOwner) then if not Assigned (FOwner) then
Exit; Exit;
@@ -1167,7 +1165,6 @@ end;
{=====} {=====}
// TVpPrintFormat ************************************************************ // TVpPrintFormat ************************************************************
constructor TVpPrintFormat.Create(AOwner: TPersistent); constructor TVpPrintFormat.Create(AOwner: TPersistent);
@@ -1335,7 +1332,6 @@ procedure TVpPrinter.AddDefaultVariables(Date: TDateTime);
DataStore: TVpCustomDataStore; DataStore: TVpCustomDataStore;
i: Integer; i: Integer;
TopLevel: TComponent; TopLevel: TComponent;
begin begin
if not Assigned(FOwner) then if not Assigned(FOwner) then
Exit; Exit;
@@ -1739,6 +1735,7 @@ var
var var
i: Integer; i: Integer;
elem: TVpPrintFormatElementItem;
begin begin
CheckPrintFormat; CheckPrintFormat;
@@ -1759,34 +1756,35 @@ begin
raise EVpPrintFormatError.Create(RSBadPrintFormat + IntToStr(CurFormat)); raise EVpPrintFormatError.Create(RSBadPrintFormat + IntToStr(CurFormat));
for i := 0 to FPrintFormats.Items[CurFormat].Elements.Count - 1 do begin 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 elem.ItemType = itCaption then begin
if FPrintFormats.Items[CurFormat].Elements.Items[i].Visible then begin if elem.Visible then begin
UpdateDateVariables(GetDate(FPrintFormats.Items[CurFormat].Elements.Items[i])); UpdateDateVariables(GetDate(elem));
ACanvas.Font.Assign(FPrintFormats.Items[CurFormat].Elements.Items[i].FCaption.Font); ACanvas.Font.Assign(elem.FCaption.Font);
FPrintFormats.Items[CurFormat].Elements.Items[i].FCaption.PaintToCanvas( elem.FCaption.PaintToCanvas(
ACanvas, ACanvas,
Rect(StartX, StartY, StopX, StopY), Rect(StartX, StartY, StopX, StopY),
FPrintFormats.Items[CurFormat].Elements.Items[i].Rotation, elem.Rotation,
ARect, ARect,
ReplaceVariables(FPrintFormats.Items[CurFormat].Elements.Items[i].FCaption.Caption) ReplaceVariables(elem.FCaption.Caption)
); );
end; end;
end else end else
if FPrintFormats.Items[CurFormat].Elements.Items[i].ItemType = itShape then begin if elem.ItemType = itShape then begin
if FPrintFormats.Items[CurFormat].Elements.Items[i].Visible then begin if elem.Visible then begin
ACanvas.Pen.Assign(FPrintFormats.Items[CurFormat].Elements.Items[i].FShape.Pen); ACanvas.Pen.Assign(elem.FShape.Pen);
ACanvas.Brush.Assign(FPrintFormats.Items[CurFormat].Elements.Items[i].FShape.Brush); ACanvas.Brush.Assign(elem.FShape.Brush);
FPrintFormats.Items[CurFormat].Elements.Items[i].FShape.PaintToCanvas( elem.FShape.PaintToCanvas(
ACanvas, ACanvas,
Rect(StartX, StartY, StopX, StopY), Rect(StartX, StartY, StopX, StopY),
FPrintFormats.Items[CurFormat].Elements.Items[i].Rotation, elem.Rotation,
ARect ARect
) );
end; end;
end else end else
RenderItem(FPrintFormats.Items[CurFormat].Elements.Items[i]); RenderItem(elem);
end; end;
end; end;
{=====} {=====}
@@ -1953,7 +1951,6 @@ procedure TVpPrinter.RegisterWatcher(Watcher: THandle);
var var
i: Integer; i: Integer;
NewHandle: PVpWatcher; NewHandle: PVpWatcher;
begin begin
for i := 0 to FNotifiers.Count - 1 do for i := 0 to FNotifiers.Count - 1 do
if Assigned(FNotifiers[i]) then if Assigned(FNotifiers[i]) then
@@ -2178,13 +2175,9 @@ begin
TriggerOnGetVariable(Self, VarName, Found, Value, Change); TriggerOnGetVariable(Self, VarName, Found, Value, Change);
case Change of case Change of
cvChange: cvChange : Result := Result + LookupVariable(VarName);
Result := Result + LookupVariable(VarName); cvIgnore : Result := Result + '$' + VarName + s[i - 1];
cvIgnore : cvRemove : ;
Result := Result + '$' + VarName + s[i - 1];
cvRemove :
begin
end;
end; end;
end; end;
end; end;
@@ -2195,7 +2188,8 @@ var
fpOut: TextFile; fpOut: TextFile;
i: Integer; i: Integer;
j: Integer; j: Integer;
fmt: TVpPrintFormatItem;
elem: TVpPrintFormatElementItem;
begin begin
if FileName = '' then if FileName = '' then
FileName := DefaultXMLFileName; FileName := DefaultXMLFileName;
@@ -2206,35 +2200,39 @@ begin
Writeln(fpOut, '<?xml version="1.0" encoding="UTF-8"?>'); Writeln(fpOut, '<?xml version="1.0" encoding="UTF-8"?>');
Writeln(fpOut, '<VpPrintFormats'); Writeln(fpOut, '<VpPrintFormats');
Writeln(fpOut, ' Version = "0.0.1">'); Writeln(fpOut, ' Version = "0.0.1">');
for i := 0 to FPrintFormats.Count - 1 do begin for i := 0 to FPrintFormats.Count - 1 do begin
fmt := FPrintFormats.Items[i];
Writeln(fpOut, ' <PrintFormat'); Writeln(fpOut, ' <PrintFormat');
Writeln(fpOut, ' Name="' + XMLizeString(FPrintFormats.Items[i].FormatName) + '"'); Writeln(fpOut, ' Name="' + XMLizeString(fmt.FormatName) + '"');
Writeln(fpOut, ' Description="' + XMLizeString(FPrintFormats.Items[i].Description) + '"'); Writeln(fpOut, ' Description="' + XMLizeString(fmt.Description) + '"');
Writeln(fpOut, ' DayIncrement="' + IntToStr(FPrintFormats.Items[i].DayInc) + '"'); Writeln(fpOut, ' DayIncrement="' + IntToStr(fmt.DayInc) + '"');
if FPrintFormats.Items[i].Visible then if fmt.Visible then
Writeln(fpOut, ' Visble="True"') Writeln(fpOut, ' Visble="True"')
else else
Writeln(fpOut, ' Visble="False"'); Writeln(fpOut, ' Visble="False"');
case FPrintFormats.Items[i].DayIncUnits of case fmt.DayIncUnits of
duDay : Writeln(fpOut, ' DayIncrementUnits="Day">'); duDay : Writeln(fpOut, ' DayIncrementUnits="Day">');
duWeek : Writeln(fpOut, ' DayIncrementUnits="Week">'); duWeek : Writeln(fpOut, ' DayIncrementUnits="Week">');
duMonth : Writeln(fpOut, ' DayIncrementUnits="Month">'); duMonth : Writeln(fpOut, ' DayIncrementUnits="Month">');
duYear : Writeln(fpOut, ' DayIncrementUnits="Year">'); duYear : Writeln(fpOut, ' DayIncrementUnits="Year">');
end; 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, ' <Element'); Writeln(fpOut, ' <Element');
Writeln(fpOut, ' Name="' + FPrintFormats.Items[i].Elements.Items[j].ElementName + '"'); Writeln(fpOut, ' Name="' + elem.ElementName + '"');
if FPrintFormats.Items[i].Elements.Items[j].Visible then if elem.Visible then
Writeln(fpOut, ' Visible="True"') Writeln(fpOut, ' Visible="True"')
else else
Writeln(fpOut, ' Visible="False"'); Writeln(fpOut, ' Visible="False"');
case FPrintFormats.Items[i].Elements.Items[j].Rotation of case elem.Rotation of
ra0 : Writeln(fpOut, ' Rotation="0"'); ra0 : Writeln(fpOut, ' Rotation="0"');
ra90 : Writeln(fpOut, ' Rotation="90"'); ra90 : Writeln(fpOut, ' Rotation="90"');
ra180 : Writeln(fpOut, ' Rotation="180"'); ra180 : Writeln(fpOut, ' Rotation="180"');
ra270 : Writeln(fpOut, ' Rotation="270"'); ra270 : Writeln(fpOut, ' Rotation="270"');
end; end;
case FPrintFormats.Items[i].Elements.Items[j].ItemType of case elem.ItemType of
itDayView : Writeln(fpOut, ' Item="DayView"'); itDayView : Writeln(fpOut, ' Item="DayView"');
itWeekView : Writeln(fpOut, ' Item="WeekView"'); itWeekView : Writeln(fpOut, ' Item="WeekView"');
itMonthView : Writeln(fpOut, ' Item="MonthView"'); itMonthView : Writeln(fpOut, ' Item="MonthView"');
@@ -2244,26 +2242,26 @@ begin
itTasks : Writeln(fpOut, ' Item="Tasks"'); itTasks : Writeln(fpOut, ' Item="Tasks"');
itContacts : Writeln(fpOut, ' Item="Contacts"'); itContacts : Writeln(fpOut, ' Item="Contacts"');
end; end;
case FPrintFormats.Items[i].Elements.Items[j].Measurement of case elem.Measurement of
imAbsolutePixel : Writeln(fpOut, ' Measurement="AbsolutePixel"'); imAbsolutePixel : Writeln(fpOut, ' Measurement="AbsolutePixel"');
imPercent : Writeln(fpOut, ' Measurement="Percent"'); imPercent : Writeln(fpOut, ' Measurement="Percent"');
imInches : Writeln(fpOut, ' Measurement="Inches"'); imInches : Writeln(fpOut, ' Measurement="Inches"');
end; end;
Writeln(fpOut, ' Left="' + FloatToStr(FPrintFormats.Items[i].Elements.Items[j].Left) + '"'); Writeln(fpOut, ' Left="' + FloatToStr(elem.Left) + '"');
Writeln(fpOut, ' Top="' + FloatToStr(FPrintFormats.Items[i].Elements.Items[j].Top) + '"'); Writeln(fpOut, ' Top="' + FloatToStr(elem.Top) + '"');
Writeln(fpOut, ' Width="' + FloatToStr(FPrintFormats.Items[i].Elements.Items[j].Width) + '"'); Writeln(fpOut, ' Width="' + FloatToStr(elem.Width) + '"');
Writeln(fpOut, ' Height="' + FloatToStr(FPrintFormats.Items[i].Elements.Items[j].Height) + '"'); Writeln(fpOut, ' Height="' + FloatToStr(elem.Height) + '"');
Writeln(fpOut, ' DayOffset="' + IntToStr(FPrintFormats.Items[i].Elements.Items[j].DayOffset) + '"'); Writeln(fpOut, ' DayOffset="' + IntToStr(elem.DayOffset) + '"');
case FPrintFormats.Items[i].Elements.Items[j].DayOffsetUnits of case elem.DayOffsetUnits of
duDay : Writeln(fpOut, ' DayOffsetUnits="Day">'); duDay : Writeln(fpOut, ' DayOffsetUnits="Day">');
duWeek : Writeln(fpOut, ' DayOffsetUnits="Week">'); duWeek : Writeln(fpOut, ' DayOffsetUnits="Week">');
duMonth : Writeln(fpOut, ' DayOffsetUnits="Month">'); duMonth : Writeln(fpOut, ' DayOffsetUnits="Month">');
duYear : Writeln(fpOut, ' DayOffsetUnits="Year">'); duYear : Writeln(fpOut, ' DayOffsetUnits="Year">');
end; end;
if FPrintFormats.Items[i].Elements.Items[j].ItemType = itShape then begin if elem.ItemType = itShape then begin
Writeln(fpOut, ' <Shape'); Writeln(fpOut, ' <Shape');
case FPrintFormats.Items[i].Elements.Items[j].FShape.Shape of case elem.FShape.Shape of
ustRectangle : Writeln(fpOut, ' Type="Rectangle">'); ustRectangle : Writeln(fpOut, ' Type="Rectangle">');
ustTopLine : Writeln(fpOut, ' Type="TopLine">'); ustTopLine : Writeln(fpOut, ' Type="TopLine">');
ustBottomLine : Writeln(fpOut, ' Type="BottomLine">'); ustBottomLine : Writeln(fpOut, ' Type="BottomLine">');
@@ -2275,8 +2273,8 @@ begin
end; end;
Writeln(fpOut, ' <Brush'); Writeln(fpOut, ' <Brush');
Writeln(fpOut, ' Color="' + IntToStr(FPrintFormats.Items[i].Elements.Items[j].FShape.Brush.Color) + '"'); Writeln(fpOut, ' Color="' + IntToStr(elem.FShape.Brush.Color) + '"');
case FPrintFormats.Items[i].Elements.Items[j].FShape.Brush.Style of case elem.FShape.Brush.Style of
bsSolid : Writeln(fpOut, ' Style="Solid"/>'); bsSolid : Writeln(fpOut, ' Style="Solid"/>');
bsClear : Writeln(fpOut, ' Style="Clear"/>'); bsClear : Writeln(fpOut, ' Style="Clear"/>');
bsHorizontal : Writeln(fpOut, ' Style="Horizontal"/>'); bsHorizontal : Writeln(fpOut, ' Style="Horizontal"/>');
@@ -2287,8 +2285,8 @@ begin
bsDiagCross : Writeln(fpOut, ' Style="DiagCross"/>'); bsDiagCross : Writeln(fpOut, ' Style="DiagCross"/>');
end; end;
Writeln(fpOut, ' <Pen'); Writeln(fpOut, ' <Pen');
Writeln(fpOut, ' Color="' + IntToStr(FPrintFormats.Items[i].Elements.Items[j].FShape.Pen.Color) + '"'); Writeln(fpOut, ' Color="' + IntToStr(elem.FShape.Pen.Color) + '"');
case FPrintFormats.Items[i].Elements.Items[j].FShape.Pen.Style of case elem.FShape.Pen.Style of
psSolid : Writeln(fpOut, ' Style="Solid"'); psSolid : Writeln(fpOut, ' Style="Solid"');
psDash : Writeln(fpOut, ' Style="Dash"'); psDash : Writeln(fpOut, ' Style="Dash"');
psDot : Writeln(fpOut, ' Style="Dot"'); psDot : Writeln(fpOut, ' Style="Dot"');
@@ -2297,15 +2295,15 @@ begin
psClear : Writeln(fpOut, ' Style="Clear"'); psClear : Writeln(fpOut, ' Style="Clear"');
psInsideFrame : Writeln(fpOut, ' Style="InsideFrame"'); psInsideFrame : Writeln(fpOut, ' Style="InsideFrame"');
end; end;
Writeln(fpOut, ' Width="' + IntToStr(FPrintFormats.Items[i].Elements.Items[j].FShape.Pen.Width) + '"/>'); Writeln(fpOut, ' Width="' + IntToStr(elem.FShape.Pen.Width) + '"/>');
Writeln(fpOut, ' </Shape>'); Writeln(fpOut, ' </Shape>');
end; end;
if FPrintFormats.Items[i].Elements.Items[j].ItemType = itCaption then begin if elem.ItemType = itCaption then begin
Writeln(fpOut, ' <Caption'); Writeln(fpOut, ' <Caption');
Writeln(fpOut, ' Caption="' + XMLizeString(FPrintFormats.Items[i].Elements.Items[j].Caption.Caption) + '">'); Writeln(fpOut, ' Caption="' + XMLizeString(elem.Caption.Caption) + '">');
Writeln(fpOut, ' <Font'); Writeln(fpOut, ' <Font');
case FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Charset of case elem.Caption.Font.Charset of
ANSI_CHARSET : Writeln(fpOut, ' CharSet="ANSI"'); ANSI_CHARSET : Writeln(fpOut, ' CharSet="ANSI"');
DEFAULT_CHARSET : Writeln(fpOut, ' CharSet="Default"'); DEFAULT_CHARSET : Writeln(fpOut, ' CharSet="Default"');
SYMBOL_CHARSET : Writeln(fpOut, ' CharSet="Symbol"'); SYMBOL_CHARSET : Writeln(fpOut, ' CharSet="Symbol"');
@@ -2332,27 +2330,27 @@ begin
EASTEUROPE_CHARSET : Writeln(fpOut, ' CharSet="EastEurope"'); EASTEUROPE_CHARSET : Writeln(fpOut, ' CharSet="EastEurope"');
OEM_CHARSET : Writeln(fpOut, ' CharSet="OEM"'); OEM_CHARSET : Writeln(fpOut, ' CharSet="OEM"');
end; end;
Writeln(fpOut, ' Color="' + IntToStr(FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Color) + '"'); Writeln(fpOut, ' Color="' + IntToStr(elem.Caption.Font.Color) + '"');
Writeln(fpOut, ' Height="' + IntToStr(FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Height) + '"'); Writeln(fpOut, ' Height="' + IntToStr(elem.Caption.Font.Height) + '"');
Writeln(fpOut, ' Name="' + XMLizeString(FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Name) + '"'); Writeln(fpOut, ' Name="' + XMLizeString(elem.Caption.Font.Name) + '"');
case FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Pitch of case elem.Caption.Font.Pitch of
fpDefault : Writeln(fpOut, ' Pitch="Default"'); fpDefault : Writeln(fpOut, ' Pitch="Default"');
fpVariable : Writeln(fpOut, ' Pitch="Variable"'); fpVariable : Writeln(fpOut, ' Pitch="Variable"');
fpFixed : Writeln(fpOut, ' Pitch="Fixed"'); fpFixed : Writeln(fpOut, ' Pitch="Fixed"');
end; end;
if fsBold in FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Style then if fsBold in elem.Caption.Font.Style then
Writeln(fpOut, ' Bold="True"') Writeln(fpOut, ' Bold="True"')
else else
Writeln(fpOut, ' Bold="False"'); Writeln(fpOut, ' Bold="False"');
if fsItalic in FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Style then if fsItalic in elem.Caption.Font.Style then
Writeln(fpOut, ' Italic="True"') Writeln(fpOut, ' Italic="True"')
else else
Writeln(fpOut, ' Italic="False"'); Writeln(fpOut, ' Italic="False"');
if fsUnderline in FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Style then if fsUnderline in elem.Caption.Font.Style then
Writeln(fpOut, ' Underline="True"') Writeln(fpOut, ' Underline="True"')
else else
Writeln(fpOut, ' Underline="False"'); Writeln(fpOut, ' Underline="False"');
if fsStrikeout in FPrintFormats.Items[i].Elements.Items[j].Caption.Font.Style then if fsStrikeout in elem.Caption.Font.Style then
Writeln(fpOut, ' Strikeout="True"/>') Writeln(fpOut, ' Strikeout="True"/>')
else else
Writeln(fpOut, ' Strikeout="False"/>'); Writeln(fpOut, ' Strikeout="False"/>');