tvplanit: Refactor TVpMonthView (remove internal variables unused or used by painter only).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5052 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-07-30 11:24:43 +00:00
parent fc7427cc7a
commit 88e7a16ba7
2 changed files with 74 additions and 74 deletions

View File

@ -145,25 +145,25 @@ type
FOnEventClick : TVpOnEventClick; FOnEventClick : TVpOnEventClick;
FOnEventDblClick : TVpOnEventClick; FOnEventDblClick : TVpOnEventClick;
{ internal variables } { internal variables }
mvDayNumberHeight : Integer; // mvDayNumberHeight : Integer;
mvEventTextHeight : Integer; // mvEventTextHeight : Integer;
mvLoaded : Boolean; mvLoaded : Boolean;
mvInLinkHandler : Boolean; // mvInLinkHandler : Boolean;
mvRowHeight : Integer; // mvRowHeight : Integer;
mvLineHeight : Integer; // mvLineHeight : Integer;
mvColWidth : Integer; // mvColWidth : Integer;
mvDayHeadHeight : Integer; mvDayHeadHeight : Integer;
mvSpinButtons : TUpDown; mvSpinButtons : TUpDown;
mvEventArray : TVpEventArray; mvEventArray : TVpEventArray;
mvMonthDayArray : TVpMonthdayArray; mvMonthDayArray : TVpMonthdayArray;
mvActiveEvent : TVpEvent; mvActiveEvent : TVpEvent;
mvActiveEventRec : TRect; mvActiveEventRec : TRect;
mvEventList : TList; // mvEventList : TList;
mvCreatingEditor : Boolean; // mvCreatingEditor : Boolean;
mvPainting : Boolean; // mvPainting : Boolean;
mvVScrollDelta : Integer; // mvVScrollDelta : Integer;
mvHotPoint : TPoint; // mvHotPoint : TPoint;
mvVisibleEvents : Integer; // mvVisibleEvents : Integer;
{ property methods } { property methods }
procedure SetDrawingStyle(Value: TVpDrawingStyle); procedure SetDrawingStyle(Value: TVpDrawingStyle);
@ -196,15 +196,11 @@ type
procedure CreateParams(var Params: TCreateParams); override; procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override; procedure CreateWnd; override;
{$IFNDEF LCL} {$IFNDEF LCL}
procedure WMLButtonDown(var Msg : TWMLButtonDown); procedure WMLButtonDown(var Msg : TWMLButtonDown); message WM_LBUTTONDOWN;
message WM_LBUTTONDOWN; procedure WMLButtonDblClick(var Msg: TWMLButtonDblClk);message WM_LBUTTONDBLCLK;
procedure WMLButtonDblClick(var Msg: TWMLButtonDblClk);
message WM_LBUTTONDBLCLK;
{$ELSE} {$ELSE}
procedure WMLButtonDown(var Msg: TLMLButtonDown); procedure WMLButtonDown(var Msg: TLMLButtonDown); message LM_LBUTTONDOWN;
message LM_LBUTTONDOWN; procedure WMLButtonDblClick(var Msg: TLMLButtonDblClk); message LM_LBUTTONDBLCLK;
procedure WMLButtonDblClick(var Msg: TLMLButtonDblClk);
message LM_LBUTTONDBLCLK;
{$ENDIF} {$ENDIF}
{ - renamed from EditEventAtCoord and re-written} { - renamed from EditEventAtCoord and re-written}
function SelectEventAtCoord(Point: TPoint): Boolean; function SelectEventAtCoord(Point: TPoint): Boolean;
@ -443,7 +439,7 @@ begin
FHeadAttr := TVpMvHeadAttr.Create(self); FHeadAttr := TVpMvHeadAttr.Create(self);
FDayHeadAttr := TVpDayHeadAttr.Create(self); FDayHeadAttr := TVpDayHeadAttr.Create(self);
FTodayAttr := TVpMvTodayAttr.Create(self); FTodayAttr := TVpMvTodayAttr.Create(self);
mvEventList := TList.Create; // mvEventList := TList.Create;
mvSpinButtons := TUpDown.Create(self); mvSpinButtons := TUpDown.Create(self);
{ Set styles and initialize internal variables } { Set styles and initialize internal variables }
@ -455,15 +451,15 @@ begin
FShowEventTime := false; FShowEventTime := false;
FDayNameStyle :=dsShort; FDayNameStyle :=dsShort;
FKBNavigate := true; FKBNavigate := true;
mvInLinkHandler := false; // mvInLinkHandler := false;
mvSpinButtons.OnClick := mvSpinButtonClick; mvSpinButtons.OnClick := mvSpinButtonClick;
mvSpinButtons.Orientation := udHorizontal; mvSpinButtons.Orientation := udHorizontal;
mvSpinButtons.Min := -32768; mvSpinButtons.Min := -32768;
mvSpinButtons.Max := 32767; mvSpinButtons.Max := 32767;
mvCreatingEditor := false; // mvCreatingEditor := false;
FSelectedDayColor := clRed; FSelectedDayColor := clRed;
FDrawingStyle := ds3d; FDrawingStyle := ds3d;
mvPainting := false; // mvPainting := false;
FColor := clWindow; FColor := clWindow;
FOffDayColor := clSilver; FOffDayColor := clSilver;
FLineColor := clGray; FLineColor := clGray;
@ -472,7 +468,7 @@ begin
FDateLabelFormat := 'mmmm yyyy'; FDateLabelFormat := 'mmmm yyyy';
FColumnWidth := 200; FColumnWidth := 200;
FRightClickChangeDate := vpDefWVRClickChangeDate; FRightClickChangeDate := vpDefWVRClickChangeDate;
mvVisibleEvents := 0; // mvVisibleEvents := 0;
{ set up fonts and colors } { set up fonts and colors }
// FDayHeadAttributes.Font.Name := 'Tahoma'; wp: better use defaults // FDayHeadAttributes.Font.Name := 'Tahoma'; wp: better use defaults
@ -511,7 +507,7 @@ begin
FDayNumberFont.Free; FDayNumberFont.Free;
FEventFont.Free; FEventFont.Free;
mvSpinButtons.Free; mvSpinButtons.Free;
mvEventList.Free; // mvEventList.Free;
FDefaultPopup.Free; FDefaultPopup.Free;
inherited; inherited;
end; end;
@ -533,16 +529,16 @@ end;
procedure TVpMonthView.LinkHandler(Sender: TComponent; procedure TVpMonthView.LinkHandler(Sender: TComponent;
NotificationType: TVpNotificationType; const Value: Variant); NotificationType: TVpNotificationType; const Value: Variant);
begin begin
mvInLinkHandler := true; // mvInLinkHandler := true;
try // try
case NotificationType of case NotificationType of
neDateChange: Date := Value; neDateChange : Date := Value;
neDataStoreChange: Invalidate; neDataStoreChange : Invalidate;
neInvalidate: Invalidate; neInvalidate : Invalidate;
end; end;
finally // finally
mvInLinkHandler := false; // mvInLinkHandler := false;
end; // end;
end; end;
{=====} {=====}
@ -613,14 +609,14 @@ procedure TVpMonthView.RenderToCanvas (RenderCanvas : TCanvas;
var var
painter: TVpMonthViewPainter; painter: TVpMonthViewPainter;
begin begin
mvPainting := true; // mvPainting := true;
painter := TVpMonthViewPainter.Create(Self, RenderCanvas); painter := TVpMonthViewPainter.Create(Self, RenderCanvas);
try try
painter.RenderToCanvas(RenderIn, Angle, Scale, RenderDate, StartLine, painter.RenderToCanvas(RenderIn, Angle, Scale, RenderDate, StartLine,
StopLine, UseGran, DisplayOnly); StopLine, UseGran, DisplayOnly);
finally finally
painter.Free; painter.Free;
mvPainting := false; // mvPainting := false;
end; end;
end; end;

View File

@ -30,6 +30,14 @@ type
TodayAttrColor: TColor; TodayAttrColor: TColor;
DotDotDotColor: TColor; DotDotDotColor: TColor;
// protected values from the original monthview needed only for painting
mvEventTextHeight: Integer;
mvDayNumberHeight: Integer;
mvRowHeight: Integer;
mvColWidth: Integer;
mvLineHeight: Integer;
mvVisibleEvents: Integer;
protected protected
procedure Clear; procedure Clear;
procedure DrawBorders; procedure DrawBorders;
@ -143,7 +151,7 @@ begin
end; end;
DayTag := Ord(FMonthView.WeekStartsOn); DayTag := Ord(FMonthView.WeekStartsOn);
dhRect.Right := dhRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth; dhRect.Right := dhRect.Left + mvColWidth;
for I := 0 to 6 do begin for I := 0 to 6 do begin
{ draw the little vertical lines between each day } { draw the little vertical lines between each day }
@ -206,8 +214,8 @@ begin
{ Fix Header String } { Fix Header String }
StrL := RenderCanvas.TextWidth(Str); StrL := RenderCanvas.TextWidth(Str);
if (StrL > TVpMonthViewOpener(FMonthView).mvColWidth - TextMargin * 2) then if (StrL > mvColWidth - TextMargin * 2) then
Str := GetDisplayString(RenderCanvas, Str, 0, TVpMonthViewOpener(FMonthView).mvColWidth - TextMargin * 2); Str := GetDisplayString(RenderCanvas, Str, 0, mvColWidth - TextMargin * 2);
StrL := RenderCanvas.TextWidth(Str); StrL := RenderCanvas.TextWidth(Str);
TPSTextOut( TPSTextOut(
@ -225,7 +233,7 @@ begin
Inc(DayTag); Inc(DayTag);
dhRect.Left := dhRect.Right; dhRect.Left := dhRect.Right;
dhRect.Right := dhRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth; dhRect.Right := dhRect.Left + mvColWidth;
end; end;
end; end;
@ -253,31 +261,32 @@ var
OldFont: TFont; OldFont: TFont;
todayDate: TDate; todayDate: TDate;
tmpRect: TRect; tmpRect: TRect;
hDayHead: Integer;
begin begin
todayDate := Date(); todayDate := Date();
{ initialize the MonthDayArray } { initialize the MonthDayArray }
with TVpMonthViewOpener(FMonthView) do with TVpMonthViewOpener(FMonthView) do begin
for I := 0 to Pred(Length(mvMonthDayArray)) do begin for I := 0 to Pred(Length(mvMonthDayArray)) do begin
mvMonthDayArray[I].Rec := Rect(-1, -1, -1, -1); mvMonthDayArray[I].Rec := Rect(-1, -1, -1, -1);
mvMonthDayArray[I].Date := 0.0; mvMonthDayArray[I].Date := 0.0;
end; end;
hDayHead := mvDayHeadHeight;
end;
RenderCanvas.Pen.Color := RealLineColor; RenderCanvas.Pen.Color := RealLineColor;
RenderCanvas.Brush.Color := RealColor; RenderCanvas.Brush.Color := RealColor;
with TVpMonthViewOpener(FMonthView) do begin if FMonthView.DrawingStyle = ds3d then
if DrawingStyle = ds3d then begin
begin mvRowHeight := (RealHeight - hDayHead * 2 - 4) div 6;
mvRowHeight := (RealHeight - mvDayHeadHeight * 2 - 4) div 6; TextRect.TopLeft := Point(RealLeft + 1, RealTop + hDayHead * 2 + 4);
TextRect.TopLeft := Point(RealLeft + 1, RealTop + mvDayHeadHeight * 2 + 4); end else
end else begin
begin mvRowHeight := (RealHeight - hDayHead * 2) div 6;
mvRowHeight := (RealHeight - mvDayHeadHeight * 2) div 6; TextRect.TopLeft := Point(RealLeft + 1, RealTop + hDayHead * 2);
TextRect.TopLeft := Point(RealLeft + 1, RealTop + mvDayHeadHeight * 2);
end;
TextRect.BottomRight := Point(TextRect.Left + mvColWidth, TextRect.Top + mvRowHeight);
end; end;
TextRect.BottomRight := Point(TextRect.Left + mvColWidth, TextRect.Top + mvRowHeight);
{ Determine the starting date and offset } { Determine the starting date and offset }
DecodeDate(DisplayDate, Y, M, D); DecodeDate(DisplayDate, Y, M, D);
@ -388,7 +397,7 @@ begin
RenderCanvas.Font.Color := FMonthView.OffDayFontColor; RenderCanvas.Font.Color := FMonthView.OffDayFontColor;
{ Write the day number at the top of the TextRect. } { Write the day number at the top of the TextRect. }
tmpRect.Left := TextRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth - TextAdjust - TextMargin; tmpRect.Left := TextRect.Left + mvColWidth - TextAdjust - TextMargin;
if fsItalic in RenderCanvas.Font.Style then if fsItalic in RenderCanvas.Font.Style then
dec(tmpRect.Left, 2); dec(tmpRect.Left, 2);
tmpRect.Top := TextRect.Top + TextMargin div 2; tmpRect.Top := TextRect.Top + TextMargin div 2;
@ -421,8 +430,8 @@ begin
TextRect.Bottom + 1 TextRect.Bottom + 1
); );
TextRect.BottomRight := Point( TextRect.BottomRight := Point(
TextRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth, TextRect.Left + mvColWidth,
TextRect.Top + TVpMonthViewOpener(FMonthView).mvRowHeight TextRect.Top + mvRowHeight
); );
end // if Col = 6 ... end // if Col = 6 ...
else else
@ -517,7 +526,7 @@ begin
{ slide rect one column to the right } { slide rect one column to the right }
TextRect.Left := TextRect.Right + 1; TextRect.Left := TextRect.Right + 1;
TextRect.Right := TextRect.Right + TVpMonthViewOpener(FMonthView).mvColWidth; TextRect.Right := TextRect.Right + mvColWidth;
end; end;
end; end;
end; end;
@ -555,8 +564,8 @@ begin
TVpMonthViewOpener(FMonthView).mvMonthDayArray[I].Rec.Top TVpMonthViewOpener(FMonthView).mvMonthDayArray[I].Rec.Top
); );
TextRect.BottomRight := Point( TextRect.BottomRight := Point(
TextRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth, TextRect.Left + mvColWidth,
TextRect.Top + TVpMonthViewOpener(FMonthView).mvEventTextHeight + TextMargin div 2 TextRect.Top + mvEventTextHeight + TextMargin div 2
); );
{ set canvas color } { set canvas color }
@ -613,12 +622,11 @@ begin
{ shorten events that are next to the day number, in order } { shorten events that are next to the day number, in order }
{ to give the day number enough room } { to give the day number enough room }
with TVpMonthViewOpener(FMonthView) do if (TextRect.Top < TVpMonthViewOpener(FMonthView).mvMonthDayArray[I].Rec.Top + mvDayNumberHeight + TextMargin div 2)
if (TextRect.Top < mvMonthDayArray[I].Rec.Top + mvDayNumberHeight + TextMargin div 2) then
then TextRect.Right := TextRect.Left + mvColWidth - mvDayNumberHeight - TextMargin
TextRect.Right := TextRect.Left + mvColWidth - mvDayNumberHeight - TextMargin else
else TextRect.Right := TextRect.Left + mvColWidth;
TextRect.Right := TextRect.Left + mvColWidth;
{ format the display text } { format the display text }
if FMonthView.ShowEventTime then begin if FMonthView.ShowEventTime then begin
@ -668,7 +676,7 @@ begin
{ Move TextRect down one line for the next item... } { Move TextRect down one line for the next item... }
TextRect.Top := TextRect.Bottom + 1; TextRect.Top := TextRect.Bottom + 1;
TextRect.Bottom := TextRect.Top + TVpMonthViewOpener(FMonthView).mvLineHeight; TextRect.Bottom := TextRect.Top + mvLineHeight;
end; end;
end; end;
end; end;
@ -847,7 +855,7 @@ begin
DrawDayHead; DrawDayHead;
{ draw days } { draw days }
TVpMonthViewOpener(FMonthView).mvVisibleEvents := 0; mvVisibleEvents := 0;
DrawDays; DrawDays;
{ draw the borders } { draw the borders }
@ -878,18 +886,14 @@ begin
mvDayHeadHeight := RenderCanvas.TextHeight(VpProductName) + TextMargin + 2; mvDayHeadHeight := RenderCanvas.TextHeight(VpProductName) + TextMargin + 2;
RenderCanvas.Font.Assign(FMonthView.DayNumberFont); RenderCanvas.Font.Assign(FMonthView.DayNumberFont);
with TVpMonthViewOpener(FMonthView) do mvDayNumberHeight := RenderCanvas.TextHeight('00');
mvDayNumberHeight := RenderCanvas.TextHeight('00');
RenderCanvas.Font.Assign(FMonthView.EventFont); RenderCanvas.Font.Assign(FMonthView.EventFont);
with TVpMonthViewOpener(FMonthView) do mvEventTextHeight := RenderCanvas.TextHeight(VpProductName);
mvEventTextHeight := RenderCanvas.TextHeight(VpProductName);
RenderCanvas.Font.Assign(FMonthView.Font); RenderCanvas.Font.Assign(FMonthView.Font);
with TVpMonthViewOpener(FMonthView) do begin mvLineHeight := RenderCanvas.TextHeight(VpProductName) + 2;
mvLineHeight := RenderCanvas.TextHeight(VpProductName) + 2; mvColWidth := (RealWidth - 4) div 7;
mvColWidth := (RealWidth - 4) div 7;
end;
end; end;
end. end.