tvplanit: Fix TVpWeekView drawing glitches. Add Alignment property for weekview's day names.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8442 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-09-04 17:59:54 +00:00
parent 460df892e1
commit 5c2d4719ab
6 changed files with 308 additions and 315 deletions

View File

@ -1,7 +1,7 @@
{$I vp.inc}
unit VpDayViewPainter; unit VpDayViewPainter;
{$I vp.inc}
interface interface
uses uses

View File

@ -116,35 +116,14 @@ var
R: TRect; R: TRect;
begin begin
R := Rect(RealLeft, RealTop, RealRight - 1, RealBottom - 1); R := Rect(RealLeft, RealTop, RealRight - 1, RealBottom - 1);
R := TPSRotateRectangle(Angle, RenderIn, R);
case FGanttView.DrawingStyle of case FGanttView.DrawingStyle of
dsNoBorder: dsNoBorder:
; // no border ; // no border
dsFlat: // Draw a simple rectangular border dsFlat: // Draw a simple rectangular border
DrawBevelRect( DrawBevelRect(RenderCanvas, R, BevelShadow, BevelShadow);
RenderCanvas, ds3D: // Draw a 3d bevel (recessed)
TPSRotateRectangle(Angle, RenderIn, R), DrawBevelRect(RenderCanvas, R, BevelShadow, BevelHighlight);
BevelShadow,
BevelShadow
);
ds3D: // Draw a 3d bevel
begin
DrawBevelRect(
RenderCanvas,
TPSRotateRectangle(Angle, RenderIn, R),
BevelShadow,
BevelHighlight
);
(*
InflateRect(R, -1, -1);
DrawBevelRect(
RenderCanvas,
TPSRotateRectangle(Angle, RenderIn, R),
BevelDarkShadow,
clRed //BevelFace
);
*)
end;
end; end;
end; end;

View File

@ -152,6 +152,7 @@ type
FDayHeadAttr: TVpMonthViewAttr; FDayHeadAttr: TVpMonthViewAttr;
FDayNameStyle: TVpMVDayNameStyle; FDayNameStyle: TVpMVDayNameStyle;
FDayNumberFont: TVpFont; FDayNumberFont: TVpFont;
FDaysMargin: Integer;
FDefaultPopup: TPopupMenu; FDefaultPopup: TPopupMenu;
FDragDropTransparent: Boolean; FDragDropTransparent: Boolean;
FDrawingStyle: TVpDrawingStyle; FDrawingStyle: TVpDrawingStyle;
@ -162,6 +163,7 @@ type
FHintMode: TVpHintMode; FHintMode: TVpHintMode;
FHolidayAttr: TVpMvHolidayAttr; FHolidayAttr: TVpMvHolidayAttr;
FKBNavigate: Boolean; FKBNavigate: Boolean;
FMonthMargin: Integer;
FLineColor: TColor; FLineColor: TColor;
FMouseDate: TDateTime; FMouseDate: TDateTime;
FOffDayColor: TColor; FOffDayColor: TColor;
@ -170,7 +172,6 @@ type
FSelectedDayColor: TColor; FSelectedDayColor: TColor;
FShowEvents: Boolean; FShowEvents: Boolean;
FShowEventTime: Boolean; FShowEventTime: Boolean;
FTextMargin: Integer;
FTimeFormat: TVpTimeFormat; FTimeFormat: TVpTimeFormat;
FTodayAttr: TVpMvTodayAttr; FTodayAttr: TVpMvTodayAttr;
FWeekendAttr: TVpMvWeekendAttr; FWeekendAttr: TVpMvWeekendAttr;
@ -201,10 +202,12 @@ type
procedure SetDateLabelFormat(Value: string); procedure SetDateLabelFormat(Value: string);
procedure SetDayNameStyle(Value: TVpMVDayNameStyle); procedure SetDayNameStyle(Value: TVpMVDayNameStyle);
procedure SetDayNumberFont(Value: TVpFont); procedure SetDayNumberFont(Value: TVpFont);
procedure SetDaysMargin(Value: Integer);
procedure SetDrawingStyle(Value: TVpDrawingStyle); procedure SetDrawingStyle(Value: TVpDrawingStyle);
procedure SetEventDayStyle(Value: TFontStyles); procedure SetEventDayStyle(Value: TFontStyles);
procedure SetEventFont(Value: TVpFont); procedure SetEventFont(Value: TVpFont);
procedure SetLineColor(Value: TColor); procedure SetLineColor(Value: TColor);
procedure SetMonthMargin(Value: Integer);
procedure SetOffDayColor(Value: TColor); procedure SetOffDayColor(Value: TColor);
procedure SetOffDayFontColor(Value: TColor); procedure SetOffDayFontColor(Value: TColor);
procedure SetPopupMenu(AValue: TPopupMenu); procedure SetPopupMenu(AValue: TPopupMenu);
@ -212,7 +215,6 @@ type
procedure SetSelectedDayColor(Value: TColor); procedure SetSelectedDayColor(Value: TColor);
procedure SetShowEvents(Value: Boolean); procedure SetShowEvents(Value: Boolean);
procedure SetShowEventTime(Value: Boolean); procedure SetShowEventTime(Value: Boolean);
procedure SetTextMargin(Value: Integer);
procedure SetTimeFormat(Value: TVpTimeFormat); procedure SetTimeFormat(Value: TVpTimeFormat);
procedure SetWeekStartsOn(Value: TVpDayType); procedure SetWeekStartsOn(Value: TVpDayType);
@ -339,6 +341,7 @@ type
property DayHeadAttributes: TVpMonthviewAttr read FDayHeadAttr write FDayHeadAttr; property DayHeadAttributes: TVpMonthviewAttr read FDayHeadAttr write FDayHeadAttr;
property DayNameStyle: TVpMVDayNameStyle read FDayNameStyle write SetDayNameStyle default dsShort; property DayNameStyle: TVpMVDayNameStyle read FDayNameStyle write SetDayNameStyle default dsShort;
property DayNumberFont: TVpFont read FDayNumberFont write SetDayNumberFont; property DayNumberFont: TVpFont read FDayNumberFont write SetDayNumberFont;
property DaysMargin: Integer read FDaysMargin write SetDaysMargin default 2;
property DragDropTransparent: Boolean read FDragDropTransparent write FDragDropTransparent default false; property DragDropTransparent: Boolean read FDragDropTransparent write FDragDropTransparent default false;
property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d; property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d;
property EventDayStyle: TFontStyles read FEventDayStyle write SetEventDayStyle default []; property EventDayStyle: TFontStyles read FEventDayStyle write SetEventDayStyle default [];
@ -348,6 +351,7 @@ type
property HintMode: TVpHintMode read FHintMode write FHintMode default hmPlannerHint; property HintMode: TVpHintMode read FHintMode write FHintMode default hmPlannerHint;
property KBNavigation: Boolean read FKBNavigate write FKBNavigate default true; property KBNavigation: Boolean read FKBNavigate write FKBNavigate default true;
property LineColor: TColor read FLineColor write SetLineColor default DEFAULT_LINECOLOR; property LineColor: TColor read FLineColor write SetLineColor default DEFAULT_LINECOLOR;
property MonthMargin: Integer read FMonthMargin write SetMonthMargin default TEXT_MARGIN;
property OffDayColor: TColor read FOffDayColor write SetOffDayColor default OFF_COLOR; property OffDayColor: TColor read FOffDayColor write SetOffDayColor default OFF_COLOR;
property OffDayFontColor: TColor read FOffDayFontColor write SetOffDayFontColor default clGray; property OffDayFontColor: TColor read FOffDayFontColor write SetOffDayFontColor default clGray;
property OwnerDrawCells: TVpOwnerDrawDayEvent read FOwnerDrawCells write FOwnerDrawCells; property OwnerDrawCells: TVpOwnerDrawDayEvent read FOwnerDrawCells write FOwnerDrawCells;
@ -356,7 +360,6 @@ type
property SelectedDayColor: TColor read FSelectedDayColor write SetSelectedDayColor default clRed; property SelectedDayColor: TColor read FSelectedDayColor write SetSelectedDayColor default clRed;
property ShowEvents: Boolean read FShowEvents write SetShowEvents default true; property ShowEvents: Boolean read FShowEvents write SetShowEvents default true;
property ShowEventTime: Boolean read FShowEventTime write SetShowEventTime default false; property ShowEventTime: Boolean read FShowEventTime write SetShowEventTime default false;
property TextMargin: Integer read FTextMargin write SetTextMargin default TEXT_MARGIN;
property TimeFormat: TVpTimeFormat read FTimeFormat write SetTimeFormat default tf12Hour; property TimeFormat: TVpTimeFormat read FTimeFormat write SetTimeFormat default tf12Hour;
property TodayAttributes: TVpMvTodayAttr read FTodayAttr write FTodayAttr; property TodayAttributes: TVpMvTodayAttr read FTodayAttr write FTodayAttr;
property WeekendAttributes: TVpMvWeekendAttr read FWeekendAttr write FWeekendAttr; property WeekendAttributes: TVpMvWeekendAttr read FWeekendAttr write FWeekendAttr;
@ -518,16 +521,14 @@ begin
// mvCreatingEditor := false; // mvCreatingEditor := false;
FSelectedDayColor := clRed; FSelectedDayColor := clRed;
FDrawingStyle := ds3d; FDrawingStyle := ds3d;
// mvPainting := false;
FColor := DEFAULT_COLOR; FColor := DEFAULT_COLOR;
FLineColor := DEFAULT_LINECOLOR; FLineColor := DEFAULT_LINECOLOR;
FDate := Trunc(Now); FDate := Trunc(Now);
FTimeFormat := tf12Hour; FTimeFormat := tf12Hour;
FDateLabelFormat := 'mmmm yyyy'; FDateLabelFormat := 'mmmm yyyy';
// FColumnWidth := 200;
FRightClickChangeDate := vpDefWVRClickChangeDate; FRightClickChangeDate := vpDefWVRClickChangeDate;
FTextMargin := TEXT_MARGIN; FDaysMargin := 2;
// mvVisibleEvents := 0; FMonthMargin := TEXT_MARGIN;
{ set up fonts and colors } { set up fonts and colors }
FDayHeadAttr.Color := clBtnFace; FDayHeadAttr.Color := clBtnFace;
@ -873,12 +874,30 @@ begin
Invalidate; Invalidate;
end; end;
procedure TVpMonthView.SetDaysMargin(Value: Integer);
begin
if Value <> FDaysMargin then
begin
FDaysMargin := Value;
Invalidate;
end;
end;
procedure TVpMonthView.SetEventFont(Value: TVpFont); procedure TVpMonthView.SetEventFont(Value: TVpFont);
begin begin
FEventFont.Assign(Value); FEventFont.Assign(Value);
Invalidate; Invalidate;
end; end;
procedure TVpMonthView.SetMonthMargin(Value: Integer);
begin
if Value <> FMonthMargin then
begin
FMonthMargin := Value;
Invalidate;
end;
end;
procedure TVpMonthView.SetSelectedDayColor(Value: TColor); procedure TVpMonthView.SetSelectedDayColor(Value: TColor);
begin begin
if Value <> FSelectedDayColor then begin if Value <> FSelectedDayColor then begin
@ -895,15 +914,6 @@ begin
end; end;
end; end;
procedure TVpMonthView.SetTextMargin(Value: Integer);
begin
if Value <> FTextMargin then
begin
FTextMargin := Value;
Invalidate;
end;
end;
procedure TVpMonthView.SetTimeFormat(Value: TVpTimeFormat); procedure TVpMonthView.SetTimeFormat(Value: TVpTimeFormat);
begin begin
if Value <> FTimeFormat then begin if Value <> FTimeFormat then begin
@ -1608,7 +1618,8 @@ begin
inherited; inherited;
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin begin
FTextMargin := round(FTextMargin * AXProportion); FDaysMargin := round(FDaysMargin * AXProportion);
FMonthMargin := round(FMonthMargin * AXProportion);
end; end;
end; end;
{$IFEND} {$IFEND}

View File

@ -230,12 +230,12 @@ begin
{ Calculate size of rect for the day number at the top of the TextRect. } { Calculate size of rect for the day number at the top of the TextRect. }
if ACol = 6 then if ACol = 6 then
tmpRect.Left := ATextRect.Left + mvColWidth - TextAdjust - FMonthView.TextMargin tmpRect.Left := ATextRect.Left + mvColWidth - TextAdjust - FMonthView.DaysMargin
else else
tmpRect.Left := ATextRect.Right - TextAdjust - FMonthView.TextMargin + 2; tmpRect.Left := ATextRect.Right - TextAdjust - FMonthView.DaysMargin + 2;
if fsItalic in RenderCanvas.Font.Style then if fsItalic in RenderCanvas.Font.Style then
dec(tmpRect.Left, 2); dec(tmpRect.Left, 2);
tmpRect.Top := ATextRect.Top + FMonthView.TextMargin div 2; tmpRect.Top := ATextRect.Top + FMonthView.DaysMargin div 2;
tmpRect.Right := tmpRect.Left + textAdjust; tmpRect.Right := tmpRect.Left + textAdjust;
tmpRect.Bottom := tmpRect.Top + textHeight; tmpRect.Bottom := tmpRect.Top + textHeight;
@ -383,8 +383,8 @@ begin
{ Fix header string } { Fix header string }
strLen := RenderCanvas.TextWidth(str); strLen := RenderCanvas.TextWidth(str);
if (strLen > mvColWidth - FMonthView.TextMargin * 2) then if (strLen > mvColWidth - FMonthView.DaysMargin * 2) then
str := GetDisplayString(RenderCanvas, str, 0, mvColWidth - FMonthView.TextMargin * 2); str := GetDisplayString(RenderCanvas, str, 0, mvColWidth - FMonthView.DaysMargin * 2);
strLen := RenderCanvas.TextWidth(str); strLen := RenderCanvas.TextWidth(str);
{ Draw header text } { Draw header text }
@ -516,7 +516,7 @@ begin
RenderCanvas.Pen.Style := psSolid; RenderCanvas.Pen.Style := psSolid;
RenderCanvas.Brush.Color := RealColor; RenderCanvas.Brush.Color := RealColor;
txtMargin := FMonthView.TextMargin; txtMargin := FMonthView.DaysMargin;
{ write the events } { write the events }
if (FMonthView.DataStore <> nil) and FMonthView.ShowEvents and if (FMonthView.DataStore <> nil) and FMonthView.ShowEvents and
@ -659,16 +659,16 @@ begin
InflateRect(headRect, -1, -1); InflateRect(headRect, -1, -1);
dec(headRect.Right); dec(headRect.Right);
headRect.Bottom := headRect.Top + FMonthHeadHeight; headRect.Bottom := headRect.Top + FMonthHeadHeight;
TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect); TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
R := TPSRotateRectangle(Angle, RenderIn, HeadRect); R := TPSRotateRectangle(Angle, RenderIn, headRect);
DrawBevelRect(RenderCanvas, R, BevelHighlight, BevelShadow); DrawBevelRect(RenderCanvas, R, BevelHighlight, BevelShadow);
end else end else
TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect); TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
// Position the spinner buttons // Position the spinner buttons
with TVpMonthViewOpener(FMonthView) do begin with TVpMonthViewOpener(FMonthView) do begin
FPrevYearBtn.Width := FPrevYearBtn.Height; FPrevYearBtn.Width := FPrevYearBtn.Height;
FPrevYearBtn.Left := TextMargin; FPrevYearBtn.Left := MonthMargin;
FPrevYearBtn.Top := (HeadRect.Top + HeadRect.Bottom - FPrevYearBtn.Height) div 2 + 1; FPrevYearBtn.Top := (HeadRect.Top + HeadRect.Bottom - FPrevYearBtn.Height) div 2 + 1;
FPrevMonthBtn.Height := FPrevYearBtn.Height; FPrevMonthBtn.Height := FPrevYearBtn.Height;
@ -686,7 +686,7 @@ begin
FNextYearBtn.Left := FNextMonthBtn.Left + FNextMonthBtn.Width; FNextYearBtn.Left := FNextMonthBtn.Left + FNextMonthBtn.Width;
FNextYearBtn.Top := FPrevYearBtn.Top; FNextYearBtn.Top := FPrevYearBtn.Top;
txtStart := FNextYearBtn.Left + FNextYearBtn.Width + 2*TextMargin; txtStart := FNextYearBtn.Left + FNextYearBtn.Width + 2*MonthMargin;
end; end;
{ Acquire startdate and end date } { Acquire startdate and end date }
@ -701,12 +701,12 @@ begin
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= RealWidth) then if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= RealWidth) then
HeadTextRect.Left := RealLeft + FMonthView.TextMargin * 2 HeadTextRect.Left := RealLeft + FMonthView.MonthMargin * 2
else else
if DisplayOnly then if DisplayOnly then
HeadTextRect.Left := RealLeft + (RealWidth - RenderCanvas.TextWidth(HeadStr)) div 2 HeadTextRect.Left := RealLeft + (RealWidth - RenderCanvas.TextWidth(HeadStr)) div 2
else else
HeadTextRect.Left := RealLeft + 30 + FMonthView.TextMargin * 2; HeadTextRect.Left := RealLeft + 30 + FMonthView.MonthMargin * 2;
HeadTextRect.Top := (HeadRect.Top + HeadRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2; HeadTextRect.Top := (HeadRect.Top + HeadRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2;
HeadTextRect.BottomRight := HeadRect.BottomRight; HeadTextRect.BottomRight := HeadRect.BottomRight;
@ -718,7 +718,7 @@ begin
RenderCanvas, RenderCanvas,
HeadStr, HeadStr,
0, 0,
HeadTextRect.Right - HeadTextRect.Left - FMonthView.TextMargin HeadTextRect.Right - HeadTextRect.Left - FMonthView.MonthMargin
); );
end; end;
@ -844,10 +844,10 @@ begin
with TVpMonthViewOpener(FMonthView) do with TVpMonthViewOpener(FMonthView) do
begin begin
h := GetCanvasTextHeight(RenderCanvas, HeadAttributes.Font, txt); h := GetCanvasTextHeight(RenderCanvas, HeadAttributes.Font, txt);
mvMonthHeadHeight := Max(h, FPrevYearBtn.Height) + TextMargin; mvMonthHeadHeight := Max(h, FPrevYearBtn.Height) + MonthMargin;
h := GetCanvasTextHeight(RenderCanvas, DayHeadAttributes.Font, txt); h := GetCanvasTextHeight(RenderCanvas, DayHeadAttributes.Font, txt);
mvDayHeadHeight := Max(h, FPrevYearBtn.Height) + TextMargin; mvDayHeadHeight := Max(h, FPrevYearBtn.Height) + DaysMargin;
mvHeaderHeight := mvMonthHeadHeight + mvDayHeadHeight; mvHeaderHeight := mvMonthHeadHeight + mvDayHeadHeight;

View File

@ -107,18 +107,21 @@ type
FFont: TVpFont; FFont: TVpFont;
FDateFormat: string; FDateFormat: string;
FColor: TColor; FColor: TColor;
FAlignment: TAlignment;
FBordered: Boolean; FBordered: Boolean;
function IsStoredDateFormat: Boolean; function IsStoredDateFormat: Boolean;
procedure SetColor(Value: TColor); procedure SetAlignment(Value: TAlignment);
procedure SetFont(Value: TVpFont);
procedure SetBordered(Value: Boolean); procedure SetBordered(Value: Boolean);
procedure SetColor(Value: TColor);
procedure SetDateFormat(Value: string); procedure SetDateFormat(Value: string);
procedure SetFont(Value: TVpFont);
protected protected
public public
constructor Create(AOwner: TVpWeekView); constructor Create(AOwner: TVpWeekView);
destructor Destroy; override; destructor Destroy; override;
property WeekView: TVpWeekView read FWeekView; property WeekView: TVpWeekView read FWeekView;
published published
property Alignment: TAlignment read FAlignment write SetAlignment default taRightJustify;
property Bordered: Boolean read FBordered write SetBordered default true; property Bordered: Boolean read FBordered write SetBordered default true;
property Color: TColor read FColor write SetColor default DEFAULT_COLOR; property Color: TColor read FColor write SetColor default DEFAULT_COLOR;
property DateFormat: string read FDateFormat write SetDateFormat stored IsStoredDateFormat; property DateFormat: string read FDateFormat write SetDateFormat stored IsStoredDateFormat;
@ -136,7 +139,6 @@ type
FAllowDragAndDrop: Boolean; FAllowDragAndDrop: Boolean;
FApplyCategoryInfos: Boolean; FApplyCategoryInfos: Boolean;
FColor: TColor; FColor: TColor;
// FColumnWidth: Integer;
FComponentHint: TTranslateString; FComponentHint: TTranslateString;
FDateLabelFormat: string; FDateLabelFormat: string;
FDayHeadAttributes: TVpDayHeadAttr; FDayHeadAttributes: TVpDayHeadAttr;
@ -146,6 +148,7 @@ type
FEventFont: TVpFont; // was: TFont FEventFont: TVpFont; // was: TFont
FExternalPopup: TPopupMenu; FExternalPopup: TPopupMenu;
FHeadAttr: TVpWvHeadAttributes; FHeadAttr: TVpWvHeadAttributes;
FHeaderMargin: Integer;
FHintMode: TVpHintMode; FHintMode: TVpHintMode;
FLineColor: TColor; FLineColor: TColor;
FMouseEvent: TVpEvent; FMouseEvent: TVpEvent;
@ -186,8 +189,9 @@ type
procedure SetDateLabelFormat(Value: string); procedure SetDateLabelFormat(Value: string);
procedure SetDrawingStyle(Value: TVpDrawingStyle); procedure SetDrawingStyle(Value: TVpDrawingStyle);
procedure SetEventFont(Value: TVpFont); procedure SetEventFont(Value: TVpFont);
procedure SetHeaderMargin(AValue: Integer);
procedure SetLayout(AValue: TVpWeekviewLayout); procedure SetLayout(AValue: TVpWeekviewLayout);
procedure SetLineColor(Value: TColor); procedure SetLineColor(AValue: TColor);
procedure SetPopupMenu(AValue: TPopupMenu); procedure SetPopupMenu(AValue: TPopupMenu);
procedure SetShowEventTime(Value: Boolean); procedure SetShowEventTime(Value: Boolean);
procedure SetTextMargin(Value: Integer); procedure SetTextMargin(Value: Integer);
@ -318,6 +322,11 @@ type
property Date: TDateTime read FActiveDate write SetActiveDate; property Date: TDateTime read FActiveDate write SetActiveDate;
property VisibleLines: Integer read FVisibleLines; property VisibleLines: Integer read FVisibleLines;
property PrevWeekBtn: TSpeedButton read FPrevWeekBtn;
property PrevMonthBtn: TSpeedButton read FPrevMonthBtn;
property NextMonthBtn: TSpeedButton read FNextMonthBtn;
property NextWeekBtn: TSpeedButton read FNextWeekBtn;
published published
property AllDayEventAttributes: TVpAllDayEventAttributes read FAllDayEventAttr write FAllDayEventAttr; property AllDayEventAttributes: TVpAllDayEventAttributes read FAllDayEventAttr write FAllDayEventAttr;
property AllowDragAndDrop: Boolean read FAllowDragAndDrop write FAllowDragAndDrop default false; property AllowDragAndDrop: Boolean read FAllowDragAndDrop write FAllowDragAndDrop default false;
@ -330,10 +339,11 @@ type
property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d; property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d;
property EventFont: TVpFont read FEventFont write SetEventFont; property EventFont: TVpFont read FEventFont write SetEventFont;
property HeadAttributes: TVpWvHeadAttributes read FHeadAttr write FHeadAttr; property HeadAttributes: TVpWvHeadAttributes read FHeadAttr write FHeadAttr;
property HeaderMargin: Integer read FHeaderMargin write SetHeaderMargin default TEXT_MARGIN;
property HintMode: TVpHintMode read FHintMode write FHintMode default hmPlannerHint; property HintMode: TVpHintMode read FHintMode write FHintMode default hmPlannerHint;
property LineColor: TColor read FLineColor write SetLineColor default DEFAULT_LINECOLOR; property LineColor: TColor read FLineColor write SetLineColor default DEFAULT_LINECOLOR;
property Layout: TVpWeekviewLayout read FLayout write SetLayout default wvlVertical; property Layout: TVpWeekviewLayout read FLayout write SetLayout default wvlVertical;
property TextMargin: Integer read FTextMargin write SetTextMargin default TEXT_MARGIN; property TextMargin: Integer read FTextMargin write SetTextMargin default 2;
property TimeFormat: TVpTimeFormat read FTimeFormat write SetTimeFormat default tf12Hour; property TimeFormat: TVpTimeFormat read FTimeFormat write SetTimeFormat default tf12Hour;
property ShowEventTime: Boolean read FShowEventTime write SetShowEventTime default true; property ShowEventTime: Boolean read FShowEventTime write SetShowEventTime default true;
property WeekStartsOn: TVpDayType read FWeekStartsOn write SetWeekStartsOn default dtSunday; property WeekStartsOn: TVpDayType read FWeekStartsOn write SetWeekStartsOn default dtSunday;
@ -439,6 +449,7 @@ begin
FFont := TVpFont.Create(AOwner); FFont := TVpFont.Create(AOwner);
FColor := DEFAULT_COLOR; FColor := DEFAULT_COLOR;
FBordered := true; FBordered := true;
FAlignment := taRightJustify;
end; end;
destructor TVpDayHeadAttr.Destroy; destructor TVpDayHeadAttr.Destroy;
@ -451,6 +462,15 @@ begin
Result := FDateFormat = 'ddddd'; Result := FDateFormat = 'ddddd';
end; end;
procedure TVpDayHeadAttr.SetAlignment(Value: TAlignment);
begin
if Value <> FAlignment then
begin
FAlignment := Value;
WeekView.Invalidate;
end;
end;
procedure TVpDayHeadAttr.SetBordered(Value: Boolean); procedure TVpDayHeadAttr.SetBordered(Value: Boolean);
begin begin
if Value <> FBordered then begin if Value <> FBordered then begin
@ -582,7 +602,8 @@ begin
wvPainting := false; wvPainting := false;
FColor := DEFAULT_COLOR; FColor := DEFAULT_COLOR;
FLineColor := DEFAULT_LINECOLOR; FLineColor := DEFAULT_LINECOLOR;
FTextMargin := TEXT_MARGIN; FTextMargin := 2;
FHeaderMargin := TEXT_MARGIN;
wvStartDate := trunc(GetStartOfWeek(Now, FWeekStartsOn)); wvStartDate := trunc(GetStartOfWeek(Now, FWeekStartsOn));
FTimeFormat := tf12Hour; FTimeFormat := tf12Hour;
FDateLabelFormat := 'ddddd'; FDateLabelFormat := 'ddddd';
@ -902,10 +923,10 @@ begin
end; end;
end; end;
procedure TVpWeekView.SetLineColor(Value: TColor); procedure TVpWeekView.SetLineColor(AValue: TColor);
begin begin
if FLineColor <> Value then begin if FLineColor <> AValue then begin
FLineColor := Value; FLineColor := AValue;
Invalidate; Invalidate;
end; end;
end; end;
@ -929,6 +950,15 @@ begin
Invalidate; Invalidate;
end; end;
procedure TVpWeekView.SetHeaderMargin(AValue: Integer);
begin
if AValue <> FHeaderMargin then
begin
FHeaderMargin := AValue;
Invalidate;
end;
end;
procedure TVpWeekView.SetLayout(AValue: TVpWeekviewLayout); procedure TVpWeekView.SetLayout(AValue: TVpWeekviewLayout);
begin begin
if AValue <> FLayout then begin if AValue <> FLayout then begin
@ -1954,6 +1984,7 @@ begin
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin begin
FTextMargin := round(FTextMargin * AXProportion); FTextMargin := round(FTextMargin * AXProportion);
FHeaderMargin := round(FHeaderMargin * AXProportion);
end; end;
end; end;
{$IFEND} {$IFEND}

View File

@ -12,6 +12,7 @@ type
TVpWeekViewPainter = class(TVpBasePainter) TVpWeekViewPainter = class(TVpBasePainter)
private private
FWeekView: TVpWeekView; FWeekView: TVpWeekView;
FHeaderHeight: Integer;
FDayHeadHeight: Integer; FDayHeadHeight: Integer;
// local parameters of the old TVpWeekView method // local parameters of the old TVpWeekView method
@ -84,24 +85,26 @@ function TVpWeekViewPainter.DrawAllDayEvents(ADate: TDateTime; DayRect: TRect;
var EAIndex: Integer): Boolean; var EAIndex: Integer): Boolean;
var var
ADEventsList: TList; ADEventsList: TList;
TempList: TList; tempList: TList;
I, J, K: Integer; I, J, K: Integer;
Event: TVpEvent;
ADEvRect: TRect; ADEvRect: TRect;
StartsBeforeRange: Boolean; startsBeforeRange: Boolean;
NumADEvents: Integer; numADEvents: Integer;
Skip: Boolean; skip: Boolean;
ADTextHeight: Integer; ADTextHeight: Integer;
EventStr: string; event: TVpEvent;
eventStr: string;
txtDist: Integer; txtDist: Integer;
txtMargin: Integer; txtMargin: Integer;
txtHeight: Integer;
totalHeight: Integer;
cat: TVpCategoryInfo; cat: TVpCategoryInfo;
savedBrushColor: TColor; savedBrushColor: TColor;
savedPenColor: TColor; savedPenColor: TColor;
begin begin
Result := False; Result := False;
{ initialize the All Day Events area... } // Initialize the All Day Events area...
ADEventsRect := DayRect; ADEventsRect := DayRect;
if (FWeekView.DataStore = nil) or (FWeekView.DataStore.Resource = nil) then if (FWeekView.DataStore = nil) or (FWeekView.DataStore.Resource = nil) then
@ -109,125 +112,115 @@ begin
{ Collect all of the events for this range and determine the maximum } { Collect all of the events for this range and determine the maximum }
{ number of all day events for the range of days covered by the control. } { number of all day events for the range of days covered by the control. }
NumADEvents := 0; numADEvents := 0;
// txtMargin is the interal margin in the all-day box, distance of text from border
txtMargin := FWeekView.TextMargin; txtMargin := FWeekView.TextMargin;
// txtDist is the distance of the all-day box to the day rect
txtDist := FWeekView.Textmargin * 2;
savedPenColor := RenderCanvas.Pen.Color; savedPenColor := RenderCanvas.Pen.Color;
savedBrushColor := RenderCanvas.Brush.Color; savedBrushColor := RenderCanvas.Brush.Color;
ADEventsList := TList.Create; ADEventsList := TList.Create;
try try
TempList := TList.Create; tempList := TList.Create;
try try
{ get the all day events for the day specified by ADate + I } // Get the all day events for the day specified by ADate + I
FWeekView.DataStore.Resource.Schedule.AllDayEventsByDate(ADate, TempList); FWeekView.DataStore.Resource.Schedule.AllDayEventsByDate(ADate, tempList);
{ Iterate through these events and place them in ADEventsList } // Iterate through these events and place them in ADEventsList
Skip := false; skip := false;
for J := 0 to pred(TempList.Count) do begin for J := 0 to pred(tempList.Count) do begin
if AdEventsList.Count > 0 then begin if AdEventsList.Count > 0 then begin
for K := 0 to pred(AdEventsList.Count) do begin for K := 0 to pred(AdEventsList.Count) do begin
if TVpEvent(AdEventsList[K]) = TVpEvent(TempList[J]) then begin if TVpEvent(AdEventsList[K]) = TVpEvent(tempList[J]) then begin
Skip := true; skip := true;
Break; Break;
end; end;
end; end;
if not Skip then if not skip then
AdEventsList.Add(TempList[J]); AdEventsList.Add(tempList[J]);
end else end else
AdEventsList.Add(TempList[J]); AdEventsList.Add(tempList[J]);
end; end;
if TempList.Count > NumADEvents then if tempList.Count > numADEvents then
NumADEvents := TempList.Count; numADEvents := tempList.Count;
finally finally
TempList.Free; tempList.Free;
end; end;
if NumADEvents > 0 then begin if numADEvents > 0 then begin
{ Set attributes } // Measure the AllDayEvent TextHeight
RenderCanvas.Brush.Color := ADBackgroundColor;
{ Measure the AllDayEvent TextHeight }
txtDist := FWeekView.TextMargin div 2;
RenderCanvas.Font.Assign(FWeekView.AllDayEventAttributes.Font); RenderCanvas.Font.Assign(FWeekView.AllDayEventAttributes.Font);
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
ADTextHeight := RenderCanvas.TextHeight(VpProductName) + txtMargin + txtDist; // Pure text height
txtHeight := RenderCanvas.TextHeight(VpProductName);
// All-day box height
ADTextHeight := txtHeight + txtMargin * 2;
{ Build the AllDayEvent rect based on the value of NumADEvents } // Build the AllDayEvent rect based on the value of NumADEvents
if AdEventsRect.Top + (NumADEvents * ADTextHeight) + txtMargin * 2 > DayRect.Bottom totalHeight := numADEvents * ADTextHeight + txtDist * 2;
then ADEventsRect.Bottom := Min(ADEventsRect.Top + totalHeight, DayRect.Bottom);
ADEventsRect.Bottom := DayRect.Bottom
else
ADEventsRect.Bottom := AdEventsRect.Top + NumADEvents * ADTextHeight + txtMargin * 2;
// Clear the AllDayEvents area // Clear the AllDayEvents area
TpsFillRect(RenderCanvas, Angle, RenderIn, ADEventsRect); TpsFillRect(RenderCanvas, Angle, RenderIn, ADEventsRect);
StartsBeforeRange := false; startsBeforeRange := false;
// Cycle through the all day events and draw them appropriately // Cycle through the all-day events and draw them appropriately
for I := 0 to pred(ADEventsList.Count) do begin for I := 0 to pred(ADEventsList.Count) do begin
Event := ADEventsList[I]; event := ADEventsList[I];
// Draw "..." // Draw "..." if next event would not fit into ADEventsRect any more
if ADEventsRect.Top + ((I + 1) * ADTextHeight) > DayRect.Bottom then if ADEventsRect.Top + (I + 1) * ADTextHeight + txtDist > DayRect.Bottom then
begin begin
DrawDotDotDot(DayRect, DotDotDotColor); DrawDotDotDot(DayRect, DotDotDotColor);
break; break;
end; end;
// See if the event began before the start of the range
if (Event.StartTime < DayOf(RenderDate)) then
StartsBeforeRange := true;
// Set the event's rect // Set the event's rect
ADEvRect.Top := ADEventsRect.Top + txtMargin + I * ADTextHeight; ADEvRect.Top := ADEventsRect.Top + txtDist + I * ADTextHeight;
ADEvRect.Bottom := ADEvRect.Top + ADTextHeight; ADEvRect.Bottom := ADEvRect.Top + ADTextHeight + 1;
ADEvRect.Left := AdEventsRect.Left + txtDist; ADEvRect.Left := AdEventsRect.Left + txtDist + 1;
ADEvRect.Right := DayRect.Right; ADEvRect.Right := DayRect.Right - txtDist;
// Paint the background of the event rect // Paint the background of the event rect
RenderCanvas.Brush.Color := ADEventBackgroundColor; RenderCanvas.Brush.Color := ADEventBackgroundColor;
RenderCanvas.Pen.Color := ADEventBorderColor; RenderCanvas.Pen.Color := ADEventBorderColor;
if FWeekView.ApplyCategoryInfos then if FWeekView.ApplyCategoryInfos then
begin begin
cat := FWeekView.Datastore.CategoryColorMap.GetCategory(Event.Category); cat := FWeekView.Datastore.CategoryColorMap.GetCategory(event.Category);
if cat.UseForAllDayEvents then if cat.UseForAllDayEvents then
begin begin
RenderCanvas.Brush.Color := cat.BackgroundColor; RenderCanvas.Brush.Color := cat.BackgroundColor;
RenderCanvas.Pen.Color := cat.Color; RenderCanvas.Pen.Color := cat.Color;
end; end;
end; end;
TPSRectangle(RenderCanvas, Angle, RenderIn, TPSRectangle(RenderCanvas, Angle, RenderIn, ADEvRect);
ADEvRect.Left + txtMargin,
ADEvRect.Top + txtDist, // See if the event began before the start of the range
ADEvRect.Right - txtMargin, if event.StartTime < trunc(RenderDate) then // wp: was DayOf(RenderDate) ???
ADEvRect.Top + ADTextHeight + txtDist startsBeforeRange := true;
);
// Paint the event string // Paint the event string
EventStr := IfThen(StartsBeforeRange, '>> ', '') + Event.Description; eventStr := IfThen(startsBeforeRange, '>> ', '') + event.Description;
EventStr := GetDisplayString(RenderCanvas, EventStr, 0, WidthOf(ADEvRect) - 3*txtMargin); eventStr := GetDisplayString(RenderCanvas, eventStr, 0, WidthOf(ADEvRect) - 2 * txtMargin);
TPSTextOut(RenderCanvas, Angle, RenderIn, TPSTextOut(RenderCanvas, Angle, RenderIn,
ADEvRect.Left + txtMargin * 2 + txtDist,
ADEvRect.Top + txtMargin,
EventStr
);
Result := True;
TVpWeekViewOpener(FWeekView).wvEventArray[EAIndex].Rec := Rect(
ADEvRect.Left + txtMargin, ADEvRect.Left + txtMargin,
ADEvRect.Top + txtMargin, (ADEvRect.Top + ADEvRect.Bottom - txtHeight) div 2,
ADEvRect.Right - txtMargin, eventStr
ADEvRect.Bottom
); );
TVpWeekViewOpener(FWeekView).wvEventArray[EAIndex].Event := Event;
TVpWeekViewOpener(FWeekView).wvEventArray[EAIndex].Rec := ADEvRect;
TVpWeekViewOpener(FWeekView).wvEventArray[EAIndex].Event := event;
Inc(EAIndex); Inc(EAIndex);
Result := True;
end; { for I := 0 to pred(ADEventsList.Count) do ... } end; { for I := 0 to pred(ADEventsList.Count) do ... }
end; { if NumADEvents > 0 } end; { if NumADEvents > 0 }
@ -239,33 +232,15 @@ begin
end; end;
procedure TVpWeekViewPainter.DrawBorders; procedure TVpWeekViewPainter.DrawBorders;
var
R: TRect;
begin begin
if FWeekView.DrawingStyle = dsFlat then begin R := Rect(RealLeft, RealTop, RealRight - 1, RealBottom - 1);
{ R := TPSRotateRectangle(Angle, RenderIn, R);
DrawBevelRect(RenderCanvas, case FWeekView.DrawingStyle of
TPSRotateRectangle(Angle, RenderIn, Rect(RealLeft, RealTop, RealRight - 1, RealBottom - 1)), dsNoBorder: ;
BevelShadowColor, dsFlat: DrawBevelRect(RenderCanvas, R, BevelShadowColor, BevelShadowColor);
BevelShadowColor ds3D: DrawBevelRect(RenderCanvas, R, BevelShadowColor, BevelHighlightColor);
);
}
DrawBevelRect(RenderCanvas,
TPSRotateRectangle(Angle, RenderIn, Rect(RealLeft + 1, RealTop + 1, RealRight - 2, RealBottom - 2)),
BevelShadowColor,
BevelShadowColor // use the same color --> no bevel in flat mode!
);
end else
if FWeekView.DrawingStyle = ds3d then begin
{ draw a 3d bevel }
DrawBevelRect(RenderCanvas,
TPSRotateRectangle(Angle, RenderIn, Rect(RealLeft, RealTop, RealRight - 1, RealBottom - 1)),
BevelShadowColor,
BevelShadowColor
);
DrawBevelRect(RenderCanvas,
TPSRotateRectangle(Angle, RenderIn, Rect(RealLeft + 1, RealTop + 1, RealRight - 2, RealBottom - 2)),
BevelDarkShadow,
BevelButtonFace
);
end; end;
end; end;
@ -286,16 +261,16 @@ procedure TVpWeekViewPainter.DrawDay(ADayIndex: Integer; var DayRect: TRect;
var EAIndex: Integer); var EAIndex: Integer);
var var
TextRect: TRect; TextRect: TRect;
delta: Integer;
J: Integer; J: Integer;
EventList: TList; EventList: TList;
rowHeight: Integer; rowHeight: Integer;
headerHeight: Integer;
tmpRect: TRect; tmpRect: TRect;
holiday: String; holiday: String;
begin begin
// Abbreviations // Abbreviations
rowHeight := TVpWeekViewOpener(FWeekView).wvRowHeight; rowHeight := TVpWeekViewOpener(FWeekView).wvRowHeight;
headerHeight := TVpWeekViewOpener(FWeekView).wvHeaderHeight; delta := IfThen(FWeekView.DrawingStyle = ds3D, 1, 0);
// Check for holiday // Check for holiday
FWeekView.IsHoliday(StartDate + ADayIndex, holiday); FWeekView.IsHoliday(StartDate + ADayIndex, holiday);
@ -305,18 +280,16 @@ begin
TextRect.Bottom := DayRect.Top + FDayHeadHeight; TextRect.Bottom := DayRect.Top + FDayHeadHeight;
// Draw day header // Draw day header
tmpRect := TextRect; RenderCanvas.Brush.Color := RealDayHeadAttrColor;
inc(tmpRect.Right); TPSFillRect(RenderCanvas, Angle, RenderIn, TextRect);
tmpRect := TPSRotateRectangle(Angle, RenderIn, TextRect);
DrawBevelRect(RenderCanvas, tmpRect, BevelShadowColor, BevelShadowColor);
// Fix header string and paint it
RenderCanvas.Font.Assign(FWeekView.DayHeadAttributes.Font); RenderCanvas.Font.Assign(FWeekView.DayHeadAttributes.Font);
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
RenderCanvas.Brush.Color := RealDayHeadAttrColor;
TPSFillRect(RenderCanvas, Angle, RenderIn, tmpRect);
if FWeekView.DayHeadAttributes.Bordered and (FWeekView.DrawingStyle <> dsNoBorder) then
TPSRectangle(RenderCanvas, Angle, RenderIn, tmpRect);
// Fix header string and paint it
DrawDayHeader(ADayIndex, holiday, TextRect); DrawDayHeader(ADayIndex, holiday, TextRect);
if (FWeekView.DataStore <> nil) and (FWeekView.DataStore.Resource <> nil) and if (FWeekView.DataStore <> nil) and (FWeekView.DataStore.Resource <> nil) and
@ -335,7 +308,7 @@ begin
// Initialize TextRect for this day // Initialize TextRect for this day
TextRect := DayRect; TextRect := DayRect;
TextRect.Top := DayRect.Top + FDayHeadHeight; TextRect.Top := DayRect.Top + FDayHeadHeight + 1;
TextRect.Bottom := TextRect.Top + rowHeight; TextRect.Bottom := TextRect.Top + rowHeight;
// Handle all-day events // Handle all-day events
@ -394,56 +367,57 @@ begin
{ adjust the DayRect for the next day } { adjust the DayRect for the next day }
case FWeekView.Layout of case FWeekView.Layout of
wvlVertical: wvlVertical:
{ 0 3
1 4
2 5
6 }
if (ADayIndex = 2) then begin if (ADayIndex = 2) then begin
{ move the dayrect to the top of the next column } // Move the dayrect to the top of the next column
DayRect := Rect( DayRect := Rect(
RealLeft + DayRectWidth, //(RealRight - RealLeft) div 2, RealLeft + DayRectWidth,
RealTop + headerHeight + 2, RealTop + FHeaderHeight,
RealRight - 2, RealRight - 1 - delta,
RealTop + headerHeight + DayRectHeight RealTop + FHeaderHeight + DayRectHeight
); )
if FWeekView.DrawingStyle = ds3D then begin end else
inc(DayRect.Top); if (ADayIndex = 4) then
dec(DayRect.Right); begin
end; // Friday: shrink DayRect for weekend days
end
else
if (ADayIndex = 4 {Friday}) then begin
{ shrink DayRect for weekend days }
DayRectHeight := DayRectHeight div 2;
DayRect.Top := DayRect.Bottom; DayRect.Top := DayRect.Bottom;
DayRect.Bottom := DayRect.Top + DayRectHeight; DayRect.Bottom := DayRect.Top + DayRectHeight div 2;
end end
else begin else if (ADayIndex = 5) then
begin
DayRect.Top := DayRect.Bottom;
DayRect.Bottom := RealTop + FHeaderHeight + DayRectHeight;
end else
begin
DayRect.Top := DayRect.Bottom; DayRect.Top := DayRect.Bottom;
DayRect.Bottom := DayRect.Top + DayRectHeight; DayRect.Bottom := DayRect.Top + DayRectHeight;
end; end;
wvlHorizontal: wvlHorizontal:
if (ADayIndex = 1) or (ADayIndex = 3) then begin
{ move the day rect to the left of the next row }
DayRect := Rect(
RealLeft + 1,
DayRect.Bottom,
RealLeft + DayRectWidth + 1,
DayRect.Bottom + DayRectHeight);
if FWeekView.DrawingStyle = ds3D then begin
inc(DayRect.Top);
dec(DayRect.Right);
end;
end else
if (ADayIndex in [4, 5]) {Friday or Saturday} then begin
if ADayIndex = 4 then begin
DayRectHeight := DayRectHeight div 2;
DayRect.Left := DayRect.Right - 1;
DayRect.Right := RealRight - 2;
end else
DayRect.Top := DayRect.Bottom;
DayRect.Bottom := DayRect.Top + DayRectHeight;
end else
begin begin
DayRect.Left := DayRect.Right - 1; if (ADayIndex in [0, 2, 4]) then
DayRect.Right := RealRight - 2; begin
DayRect.Left := RealLeft + DayRectWidth;
DayRect.Right := RealRight - 1 - delta;
end else if (ADayIndex <> 5) then
begin
DayRect.Right := RealLeft + DayRectWidth;
DayRect.Left := RealLeft;
end;
if (ADayIndex in [1, 3]) then
begin
DayRect.Top := DayRect.Bottom;
DayRect.Bottom := DayRect.Top + DayRectHeight; // - 8;
end else
if ADayIndex = 4 then
DayRect.Bottom := DayRect.Top + DayRectHeight div 2
else if ADayIndex = 5 then
DayRect.Top := DayRect.Top + DayRectHeight div 2;
end; end;
end; // case end; // case
end; end;
@ -461,11 +435,18 @@ begin
RenderCanvas.Font.Style := RenderCanvas.Font.Style + [fsBold]; RenderCanvas.Font.Style := RenderCanvas.Font.Style + [fsBold];
dayStr := GetDateDisplayString(RenderCanvas, StartDate + ADayIndex, dayStr := GetDateDisplayString(RenderCanvas, StartDate + ADayIndex,
FWeekView.DayHeadAttributes.DateFormat, AHolidayName, WidthOf(TextRect) - FWeekView.TextMargin); FWeekView.DayHeadAttributes.DateFormat, AHolidayName, WidthOf(TextRect) - FWeekView.HeaderMargin*2);
strWid := RenderCanvas.TextWidth(dayStr); strWid := RenderCanvas.TextWidth(dayStr);
strH := RenderCanvas.TextHeight(dayStr); strH := RenderCanvas.TextHeight(dayStr);
TextRect.Left := TextRect.Right - strWid - FWeekView.TextMargin; case FWeekView.DayHeadAttributes.Alignment of
taLeftJustify:
TextRect.Left := TextRect.Left + FWeekView.HeaderMargin;
taCenter:
TextRect.Left := (TextRect.Left + TextRect.Right - strWid) div 2;
taRightJustify:
TextRect.Left := TextRect.Right - strWid - FWeekView.HeaderMargin;
end;
TPSTextOut( TPSTextOut(
RenderCanvas, RenderCanvas,
Angle, Angle,
@ -483,51 +464,49 @@ var
DayRect: TRect; DayRect: TRect;
EAIndex: Integer; // Index of last-used item in wvEventArray EAIndex: Integer; // Index of last-used item in wvEventArray
I: Integer; I: Integer;
headerHeight: Integer;
realCenter: Integer; realCenter: Integer;
delta: Integer;
begin begin
with TVpWeekViewOpener(FWeekView) do begin with TVpWeekViewOpener(FWeekView) do begin
// Initialize weekday array
{ Initialize weekday array }
for I := 0 to pred(Length(wvWeekdayArray)) do begin for I := 0 to pred(Length(wvWeekdayArray)) do begin
wvWeekdayArray[I].Rec.TopLeft := Point(-1, -1); wvWeekdayArray[I].Rec.TopLeft := Point(-1, -1);
wvWeekdayArray[I].Rec.BottomRight := Point(-1, -1); wvWeekdayArray[I].Rec.BottomRight := Point(-1, -1);
wvWeekdayArray[I].Day := 0; wvWeekdayArray[I].Day := 0;
end; end;
{ initialize event array } // Initialize event array
EAIndex := 0; EAIndex := 0;
for I := 0 to pred(Length(wvEventArray)) do begin for I := 0 to pred(Length(wvEventArray)) do begin
wvEventArray[I].Rec.TopLeft := Point(-1, -1); wvEventArray[I].Rec.TopLeft := Point(-1, -1);
wvEventArray[I].Rec.BottomRight := Point(-1, -1); wvEventArray[I].Rec.BottomRight := Point(-1, -1);
wvEventArray[I].Event := nil; wvEventArray[I].Event := nil;
end; end;
if DrawingStyle = ds3D then delta := 1 else delta := 0;
end; end;
RenderCanvas.Pen.Color := RealLineColor; RenderCanvas.Pen.Color := RealLineColor;
RenderCanvas.Pen.Style := psSolid; RenderCanvas.Pen.Style := psSolid;
{ build the first day rect } // Build the first day rect
headerHeight := TVpWeekViewOpener(FWeekView).wvHeaderHeight; DayRectHeight := (RealBottom - RealTop - FHeaderHeight) div 3;
DayRectHeight := (RealBottom - RealTop - headerHeight) div 3;
DayRectWidth := (RealRight - RealLeft) div 2; DayRectWidth := (RealRight - RealLeft) div 2;
DayRect := Rect( DayRect := Rect(
RealLeft + 1, RealLeft,
RealTop + headerHeight + 2, RealTop + FHeaderHeight,
RealLeft + DayRectWidth + 1, RealLeft + DayRectWidth,
RealTop + headerHeight + DayRectHeight RealTop + FHeaderHeight + DayRectHeight
); );
if FWeekView.DrawingStyle = ds3D then
inc(DayRect.Top, 1);
{ Draw the day frames and texts } // Draw the day frames and texts
for I := 0 to 6 do for I := 0 to 6 do
DrawDay(I, DayRect, EAIndex); DrawDay(I, DayRect, EAIndex);
{ Draw the center vertical line } // Draw the center vertical line
RenderCanvas.Pen.Color := RealLineColor; RenderCanvas.Pen.Color := RealLineColor;
realCenter := RealLeft + (RealRight - RealLeft) div 2; realCenter := RealLeft + (RealRight - RealLeft) div 2;
TPSMoveTo(RenderCanvas, Angle, RenderIn, realCenter, RealTop + headerHeight + 2); TPSMoveTo(RenderCanvas, Angle, RenderIn, realCenter, RealTop + FHeaderHeight + 1);
TPSLineTo(RenderCanvas, Angle, RenderIn, realCenter, RealBottom - 1); TPSLineTo(RenderCanvas, Angle, RenderIn, realCenter, RealBottom - 1);
end; end;
@ -546,7 +525,6 @@ var
R: TRect; R: TRect;
begin begin
oldFontColor := RenderCanvas.Font.Color; oldFontColor := RenderCanvas.Font.Color;
txtmargin := FWeekView.TextMargin; txtmargin := FWeekView.TextMargin;
{ format the display text } { format the display text }
@ -561,13 +539,15 @@ begin
todayEndTime := 0.9999; todayEndTime := 0.9999;
end; end;
{ set the event font } // Set the event font
RenderCanvas.Font.Assign(FWeekView.EventFont); RenderCanvas.Font.Assign(FWeekView.EventFont);
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
if AEvent.IsOverlayed then if AEvent.IsOverlayed then
RenderCanvas.Font.Color := clGray; RenderCanvas.Font.Color := clGray;
// Draw event background
RenderCanvas.Brush.Color := RealColor; RenderCanvas.Brush.Color := RealColor;
if Assigned(FWeekView.Datastore) and FWeekView.ApplyCategoryInfos then if Assigned(FWeekView.Datastore) and FWeekView.ApplyCategoryInfos then
begin begin
@ -588,13 +568,13 @@ begin
end; end;
end; end;
{ Build the event text } // Build the event text
dayStr := FWeekView.BuildEventString(AEvent, todayStartTime, todayEndTime, false); dayStr := FWeekView.BuildEventString(AEvent, todayStartTime, todayEndTime, false);
strLen := RenderCanvas.TextWidth(dayStr); strLen := RenderCanvas.TextWidth(dayStr);
if (strLen > WidthOf(TextRect) - txtMargin * 2) then if (strLen > WidthOf(TextRect) - txtMargin * 2) then
dayStr := GetDisplayString(RenderCanvas, dayStr, 0, WidthOf(TextRect) - txtMargin * 2); dayStr := GetDisplayString(RenderCanvas, dayStr, 0, WidthOf(TextRect) - txtMargin * 2);
{ Write the event text } // Write out the event text
TPSTextOut(RenderCanvas, Angle, RenderIn, TPSTextOut(RenderCanvas, Angle, RenderIn,
TextRect.Left + txtMargin, TextRect.Top + txtMargin div 2, TextRect.Left + txtMargin, TextRect.Top + txtMargin div 2,
dayStr dayStr
@ -605,102 +585,102 @@ end;
procedure TVpWeekViewPainter.DrawHeader; procedure TVpWeekViewPainter.DrawHeader;
var var
HeadRect: TRect; headRect, R: TRect;
HeadTextRect: TRect; headTextRect: TRect;
HeadStr: string = ''; headStr: string = '';
HeadStrLen: Integer; headStrLen: Integer;
weekNo: Integer; weekNo: Integer;
startStr, endStr: String; startStr, endStr: String;
txtStart: Integer; txtStart: Integer;
txtMargin: Integer; txtMargin: Integer;
begin begin
txtMargin := FWeekView.TextMargin;
RenderCanvas.Brush.Color := RealHeadAttrColor; RenderCanvas.Brush.Color := RealHeadAttrColor;
RenderCanvas.Font.Assign(TFont(FWeekView.HeadAttributes.Font)); RenderCanvas.Font.Assign(TFont(FWeekView.HeadAttributes.Font));
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
txtMargin := FWeekView.TextMargin; // Draw the header cell and borders
headRect := Rect(RealLeft, RealTop, RealRight, RealTop + FHeaderHeight);
{ draw the header cell and borders } case FWeekView.DrawingStyle of
if FWeekView.DrawingStyle = ds3d then begin dsNoBorder:
{ draw a 3d bevel } TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
HeadRect.Left := RealLeft + 2; dsFlat:
HeadRect.Top := RealTop + 2; begin // Draw simple border rectangle
HeadRect.Right := RealRight - 3; TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
HeadRect.Bottom := RealTop + TVpWeekViewOpener(FWeekView).wvHeaderHeight + 2; R := TPSRotateRectangle(Angle, RenderIn, headRect);
TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect); DrawBevelRect(RenderCanvas, R, BevelShadowColor, BevelShadowColor);
DrawBevelRect( end;
RenderCanvas, ds3D:
TPSRotateRectangle(Angle, RenderIn, HeadRect), begin // Draw a 3D bevel (raised)
BevelHighlightColor, R := Rect(headRect.Left+1, headRect.Top+1, headRect.Right-2, headRect.Bottom);
BevelDarkShadow TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
); R := TPSRotateRectangle(Angle, RenderIn, R);
end else begin DrawBevelRect(RenderCanvas, R, BevelHighlightColor, BevelShadowColor);
{ draw simple border rectangle } end;
HeadRect := Rect(RealLeft, RealTop, RealRight, RealTop + TVpWeekViewOpener(FWeekView).wvHeaderHeight + 2);
TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect);
end; end;
{ build header caption } // Build header caption
weekNo := GetWeekOfYear(StartDate); weekNo := GetWeekOfYear(StartDate);
startStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate); startStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate);
endStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate+6); endStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate+6);
HeadStr := Format('%s %d (%s - %s)', [RSCalendarWeek, weekNo, startStr, endStr]); headStr := Format('%s %d (%s - %s)', [RSCalendarWeek, weekNo, startStr, endStr]);
{ draw the text } { draw the text }
if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= WidthOf(RenderIn)) then if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= WidthOf(RenderIn)) then
HeadTextRect.TopLeft:= Point(RealLeft + txtMargin * 2, HeadRect.Top) headTextRect.TopLeft := Point(RealLeft + txtMargin * 2, HeadRect.Top)
else else
if DisplayOnly then if DisplayOnly then
HeadTextRect.TopLeft := Point( headTextRect.TopLeft := Point(
RealLeft + (RealRight - RealLeft - RenderCanvas.TextWidth(HeadStr)) div 2, RealLeft + (RealRight - RealLeft - RenderCanvas.TextWidth(headStr)) div 2,
HeadRect.Top headRect.Top
) )
else else
HeadTextRect.TopLeft := Point( headTextRect.TopLeft := Point(
RealLeft + Trunc(TVpWeekViewOpener(FWeekView).wvHeaderHeight * 0.8) * 2 + txtMargin * 2, RealLeft + Trunc(TVpWeekViewOpener(FWeekView).wvHeaderHeight * 0.8) * 2 + txtMargin * 2,
HeadRect.Top headRect.Top
); );
HeadTextRect.BottomRight := HeadRect.BottomRight; headTextRect.BottomRight := headRect.BottomRight;
dec(headTextRect.Right, txtMargin);
{ Fix Header String } // Fix header string
HeadStrLen := RenderCanvas.TextWidth(HeadStr); headStrLen := RenderCanvas.TextWidth(headStr);
if HeadStrLen > HeadTextRect.Right - HeadTextRect.Left - txtMargin then if headStrLen > headTextRect.Right - headTextRect.Left - txtMargin then
begin begin
HeadStr := GetDisplayString(RenderCanvas, HeadStr, 0, headStr := GetDisplayString(RenderCanvas, headStr, 0,
HeadTextRect.Right - HeadTextRect.Left - txtMargin ); headTextRect.Right - headTextRect.Left - txtMargin);
end; end;
{ Position the spinner } // Position the spinner buttons
with TVpWeekViewOpener(FWeekView) do begin with FWeekView do begin
FPrevMonthBtn.Height := Trunc(wvHeaderHeight * 0.8);; PrevMonthBtn.Width := PrevMonthBtn.Height;
FPrevMonthBtn.Width := FPrevMonthBtn.Height; PrevMonthBtn.Left := TextMargin;
FPrevMonthBtn.Left := TextMargin; PrevMonthBtn.Top := (headRect.Top + headRect.Bottom - PrevMonthBtn.Height) div 2;
FPrevMonthBtn.Top := (wvHeaderHeight - FPrevMonthBtn.Height) div 2 + 2;
FPrevWeekBtn.Height := FPrevMonthBtn.Height; PrevWeekBtn.Height := PrevMonthBtn.Height;
FPrevWeekBtn.Width := FPrevMonthBtn.Height; PrevWeekBtn.Width := PrevMonthBtn.Height;
FPrevWeekBtn.Left := FPrevMonthBtn.Left + FPrevMonthBtn.Width; PrevWeekBtn.Left := PrevMonthBtn.Left + PrevMonthBtn.Width;
FPrevWeekBtn.Top := FPrevMonthBtn.Top; PrevWeekBtn.Top := PrevMonthBtn.Top;
FNextWeekBtn.Height := FPrevMonthBtn.Height; NextWeekBtn.Height := PrevMonthBtn.Height;
FNextWeekBtn.Width := FPrevMonthBtn.Height; NextWeekBtn.Width := PrevMonthBtn.Height;
FNextWeekBtn.Left := FPrevWeekBtn.Left + FPrevWeekBtn.Width; NextWeekBtn.Left := PrevWeekBtn.Left + PrevWeekBtn.Width;
FNextWeekBtn.Top := FPrevMonthBtn.Top; NextWeekBtn.Top := PrevMonthBtn.Top;
FNextMonthBtn.Height := FPrevMonthBtn.Height; NextMonthBtn.Height := PrevMonthBtn.Height;
FNextMonthBtn.Width := FPrevMonthBtn.Height; NextMonthBtn.Width := PrevMonthBtn.Height;
FNextMonthBtn.Left := FNextWeekBtn.Left + FNextWeekBtn.Width; NextMonthBtn.Left := NextWeekBtn.Left + NextWeekBtn.Width;
FNextMonthBtn.Top := FPrevMonthBtn.Top; NextMonthBtn.Top := PrevMonthBtn.Top;
txtStart := FNextMonthBtn.Left + FNextMonthBtn.Width + TextMargin; txtStart := NextMonthBtn.Left + NextMonthBtn.Width + txtMargin;
end; end;
TPSTextOut(RenderCanvas, Angle, RenderIn, TPSTextOut(RenderCanvas, Angle, RenderIn,
txtStart, txtStart,
(HeadTextRect.Top + HeadTextRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2, (headTextRect.Top + headTextRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2,
HeadStr headStr
); );
end; end;
@ -793,34 +773,26 @@ begin
end; end;
procedure TVpWeekViewPainter.SetMeasurements; procedure TVpWeekViewPainter.SetMeasurements;
var
h: Integer;
begin begin
inherited; inherited;
with TVpWeekViewOpener(FWeekView) do with TVpWeekViewOpener(FWeekView) do
begin
if RenderDate = 0 then if RenderDate = 0 then
StartDate := GetStartOfWeek(wvStartDate, WeekStartsOn) StartDate := GetStartOfWeek(wvStartDate, WeekStartsOn)
else else
StartDate := GetStartOfWeek(RenderDate, WeekStartsOn); StartDate := GetStartOfWeek(RenderDate, WeekStartsOn);
RenderCanvas.Font.Assign(FWeekView.DayHeadAttributes.Font); wvRowHeight := GetCanvasTextHeight(RenderCanvas, EventFont, VpProductName);
{$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF}
FDayHeadHeight := RenderCanvas.TextHeight(VpProductName) + FWeekView.TextMargin + 2 ;
RenderCanvas.Font.Assign(FWeekView.EventFont); Self.FDayHeadHeight := GetCanvasTextHeight(RenderCanvas, DayHeadAttributes.Font) + TextMargin * 2;
{$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF}
with TVpWeekViewOpener(FWeekView) do
wvRowHeight := RenderCanvas.TextHeight(VpProductName) + FWeekView.TextMargin div 2;
RenderCanvas.Font.Assign(TFont(FWeekView.HeadAttributes.Font)); h := GetCanvasTextHeight(RenderCanvas, HeadAttributes.Font, VpProductName);
{$IF VP_LCL_SCALING = 0} Self.FHeaderHeight := Max(h, PrevMonthBtn.Height) + HeaderMargin * 2;
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); wvHeaderHeight := FHeaderHeight;
{$ENDIF} end;
with TVpWeekViewOpener(FWeekView) do
wvHeaderHeight := RenderCanvas.TextHeight(VpProductName) + FWeekView.TextMargin * 2;
end; end;
end. end.