2016-06-22 21:04:36 +00:00
|
|
|
{$I vp.inc}
|
|
|
|
|
|
|
|
unit VpWeekViewPainter;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2016-11-21 17:12:05 +00:00
|
|
|
SysUtils, LCLType, LCLIntf, Types, Classes, Graphics,
|
|
|
|
VpConst, VPBase, VpData, VpBasePainter, VpWeekView;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
|
|
|
type
|
2016-06-23 09:37:07 +00:00
|
|
|
TVpWeekViewPainter = class(TVpBasePainter)
|
2016-06-22 21:04:36 +00:00
|
|
|
private
|
|
|
|
FWeekView: TVpWeekView;
|
2022-09-04 17:59:54 +00:00
|
|
|
FHeaderHeight: Integer;
|
2016-07-15 12:29:06 +00:00
|
|
|
FDayHeadHeight: Integer;
|
|
|
|
|
2016-06-22 21:04:36 +00:00
|
|
|
// local parameters of the old TVpWeekView method
|
|
|
|
DayRectHeight: Integer;
|
2016-09-23 11:40:39 +00:00
|
|
|
DayRectWidth: Integer;
|
2016-06-22 21:04:36 +00:00
|
|
|
StartDate: TDateTime;
|
|
|
|
ADEventsRect: TRect;
|
|
|
|
DotDotDotColor: TColor;
|
|
|
|
BevelHighlightColor: TColor;
|
|
|
|
BevelShadowColor: TColor;
|
|
|
|
BevelDarkShadow: TColor;
|
|
|
|
BevelButtonFace: TColor;
|
|
|
|
RealLineColor: TColor;
|
|
|
|
RealDayHeadAttrColor: TColor;
|
|
|
|
RealColor: TColor;
|
|
|
|
RealHeadAttrColor: TColor;
|
|
|
|
ADBackgroundColor: TColor;
|
|
|
|
ADEventBackgroundColor: TColor;
|
|
|
|
ADEventBorderColor: TColor;
|
|
|
|
|
|
|
|
protected
|
|
|
|
procedure Clear;
|
|
|
|
function DrawAllDayEvents(ADate: TDateTime; DayRect: TRect; var EAIndex: Integer): Boolean;
|
|
|
|
procedure DrawBorders;
|
2016-06-24 15:51:13 +00:00
|
|
|
procedure DrawFocusRect(ADayIndex: Integer; DayRect: TRect);
|
|
|
|
procedure DrawDay(ADayIndex: Integer; var DayRect: TRect; var EAIndex: Integer);
|
2016-09-23 08:41:52 +00:00
|
|
|
procedure DrawDayHeader(ADayIndex: Integer; AHolidayName: String;
|
|
|
|
var TextRect: TRect);
|
2016-06-22 21:04:36 +00:00
|
|
|
procedure DrawDays;
|
2016-07-12 09:26:14 +00:00
|
|
|
procedure DrawEvent(AEvent: TVpEvent; TextRect: TRect; ADayIndex: Integer);
|
2016-06-22 21:04:36 +00:00
|
|
|
procedure DrawHeader;
|
2016-07-05 08:42:08 +00:00
|
|
|
procedure FixFontHeights;
|
2016-06-23 11:53:21 +00:00
|
|
|
procedure InitColors;
|
|
|
|
procedure SetMeasurements; override;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(AWeekView: TVpWeekView; ARenderCanvas: TCanvas);
|
|
|
|
procedure RenderToCanvas(ARenderIn: TRect; AAngle: TVpRotationAngle;
|
|
|
|
AScale: Extended; ARenderDate: TDateTime; AStartLine, AStopLine: Integer;
|
2016-06-23 09:37:07 +00:00
|
|
|
AUseGran: TVpGranularity; ADisplayOnly: Boolean); override;
|
2016-06-22 21:04:36 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2016-07-05 08:42:08 +00:00
|
|
|
StrUtils, Math,
|
|
|
|
{$IFDEF LCL}
|
|
|
|
LazUtf8, DateUtils,
|
|
|
|
{$ENDIF}
|
2016-06-22 21:04:36 +00:00
|
|
|
VpCanvasUtils, VpMisc, VpSR;
|
|
|
|
|
|
|
|
type
|
|
|
|
TVpWeekViewOpener = class(TVpWeekView);
|
|
|
|
|
|
|
|
constructor TVpWeekViewPainter.Create(AWeekView: TVpWeekView;
|
|
|
|
ARenderCanvas: TCanvas);
|
|
|
|
begin
|
2016-06-23 09:37:07 +00:00
|
|
|
inherited Create(ARenderCanvas);
|
2016-06-22 21:04:36 +00:00
|
|
|
FWeekView := AWeekView;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekViewPainter.Clear;
|
|
|
|
begin
|
|
|
|
RenderCanvas.Brush.Color := RealColor;
|
|
|
|
RenderCanvas.FillRect(RenderIn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TVpWeekViewPainter.DrawAllDayEvents(ADate: TDateTime; DayRect: TRect;
|
|
|
|
var EAIndex: Integer): Boolean;
|
|
|
|
var
|
|
|
|
ADEventsList: TList;
|
2022-09-04 17:59:54 +00:00
|
|
|
tempList: TList;
|
2016-06-22 21:04:36 +00:00
|
|
|
I, J, K: Integer;
|
2016-07-05 08:42:08 +00:00
|
|
|
ADEvRect: TRect;
|
2022-09-04 17:59:54 +00:00
|
|
|
startsBeforeRange: Boolean;
|
|
|
|
numADEvents: Integer;
|
|
|
|
skip: Boolean;
|
2016-06-22 21:04:36 +00:00
|
|
|
ADTextHeight: Integer;
|
2022-09-04 17:59:54 +00:00
|
|
|
event: TVpEvent;
|
|
|
|
eventStr: string;
|
2016-07-05 08:42:08 +00:00
|
|
|
txtDist: Integer;
|
2022-09-02 17:38:26 +00:00
|
|
|
txtMargin: Integer;
|
2022-09-04 17:59:54 +00:00
|
|
|
txtHeight: Integer;
|
|
|
|
totalHeight: Integer;
|
2022-08-16 19:58:12 +00:00
|
|
|
cat: TVpCategoryInfo;
|
|
|
|
savedBrushColor: TColor;
|
|
|
|
savedPenColor: TColor;
|
2016-06-22 21:04:36 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
2016-07-05 08:42:08 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Initialize the All Day Events area...
|
2016-06-22 21:04:36 +00:00
|
|
|
ADEventsRect := DayRect;
|
|
|
|
|
|
|
|
if (FWeekView.DataStore = nil) or (FWeekView.DataStore.Resource = nil) then
|
|
|
|
Exit;
|
|
|
|
|
|
|
|
{ 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. }
|
2022-09-04 17:59:54 +00:00
|
|
|
numADEvents := 0;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// txtMargin is the interal margin in the all-day box, distance of text from border
|
2022-09-02 17:38:26 +00:00
|
|
|
txtMargin := FWeekView.TextMargin;
|
2022-09-04 17:59:54 +00:00
|
|
|
// txtDist is the distance of the all-day box to the day rect
|
|
|
|
txtDist := FWeekView.Textmargin * 2;
|
2022-09-02 17:38:26 +00:00
|
|
|
|
2022-08-16 19:58:12 +00:00
|
|
|
savedPenColor := RenderCanvas.Pen.Color;
|
|
|
|
savedBrushColor := RenderCanvas.Brush.Color;
|
2022-09-04 17:59:54 +00:00
|
|
|
|
2016-06-22 21:04:36 +00:00
|
|
|
ADEventsList := TList.Create;
|
|
|
|
try
|
2022-09-04 17:59:54 +00:00
|
|
|
tempList := TList.Create;
|
2016-06-22 21:04:36 +00:00
|
|
|
try
|
2022-09-04 17:59:54 +00:00
|
|
|
// Get the all day events for the day specified by ADate + I
|
|
|
|
FWeekView.DataStore.Resource.Schedule.AllDayEventsByDate(ADate, tempList);
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Iterate through these events and place them in ADEventsList
|
|
|
|
skip := false;
|
|
|
|
for J := 0 to pred(tempList.Count) do begin
|
2016-06-22 21:04:36 +00:00
|
|
|
if AdEventsList.Count > 0 then begin
|
|
|
|
for K := 0 to pred(AdEventsList.Count) do begin
|
2022-09-04 17:59:54 +00:00
|
|
|
if TVpEvent(AdEventsList[K]) = TVpEvent(tempList[J]) then begin
|
|
|
|
skip := true;
|
2016-06-22 21:04:36 +00:00
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
2022-09-04 17:59:54 +00:00
|
|
|
if not skip then
|
|
|
|
AdEventsList.Add(tempList[J]);
|
2016-06-22 21:04:36 +00:00
|
|
|
end else
|
2022-09-04 17:59:54 +00:00
|
|
|
AdEventsList.Add(tempList[J]);
|
2016-06-22 21:04:36 +00:00
|
|
|
end;
|
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
if tempList.Count > numADEvents then
|
|
|
|
numADEvents := tempList.Count;
|
2016-06-22 21:04:36 +00:00
|
|
|
finally
|
2022-09-04 17:59:54 +00:00
|
|
|
tempList.Free;
|
2016-06-22 21:04:36 +00:00
|
|
|
end;
|
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
if numADEvents > 0 then begin
|
|
|
|
// Measure the AllDayEvent TextHeight
|
2016-07-05 08:42:08 +00:00
|
|
|
RenderCanvas.Font.Assign(FWeekView.AllDayEventAttributes.Font);
|
2017-05-22 08:11:27 +00:00
|
|
|
{$IF VP_LCL_SCALING = 0}
|
2016-08-08 18:29:24 +00:00
|
|
|
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
|
2017-05-22 08:11:27 +00:00
|
|
|
{$ENDIF}
|
2022-09-04 17:59:54 +00:00
|
|
|
// Pure text height
|
|
|
|
txtHeight := RenderCanvas.TextHeight(VpProductName);
|
|
|
|
// All-day box height
|
|
|
|
ADTextHeight := txtHeight + txtMargin * 2;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Build the AllDayEvent rect based on the value of NumADEvents
|
|
|
|
totalHeight := numADEvents * ADTextHeight + txtDist * 2;
|
|
|
|
ADEventsRect.Bottom := Min(ADEventsRect.Top + totalHeight, DayRect.Bottom);
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2022-09-05 09:27:54 +00:00
|
|
|
// Clear the AllDayEvents area using its background color
|
|
|
|
RenderCanvas.Brush.Color := ADBackgroundColor;
|
2016-06-22 21:04:36 +00:00
|
|
|
TpsFillRect(RenderCanvas, Angle, RenderIn, ADEventsRect);
|
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
startsBeforeRange := false;
|
2016-07-05 08:42:08 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Cycle through the all-day events and draw them appropriately
|
2016-06-22 21:04:36 +00:00
|
|
|
for I := 0 to pred(ADEventsList.Count) do begin
|
2022-09-04 17:59:54 +00:00
|
|
|
event := ADEventsList[I];
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Draw "..." if next event would not fit into ADEventsRect any more
|
|
|
|
if ADEventsRect.Top + (I + 1) * ADTextHeight + txtDist > DayRect.Bottom then
|
2016-07-05 08:42:08 +00:00
|
|
|
begin
|
|
|
|
DrawDotDotDot(DayRect, DotDotDotColor);
|
2016-06-22 21:04:36 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
|
2016-07-05 08:42:08 +00:00
|
|
|
// Set the event's rect
|
2022-09-04 17:59:54 +00:00
|
|
|
ADEvRect.Top := ADEventsRect.Top + txtDist + I * ADTextHeight;
|
|
|
|
ADEvRect.Bottom := ADEvRect.Top + ADTextHeight + 1;
|
|
|
|
ADEvRect.Left := AdEventsRect.Left + txtDist + 1;
|
|
|
|
ADEvRect.Right := DayRect.Right - txtDist;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2016-07-05 08:42:08 +00:00
|
|
|
// Paint the background of the event rect
|
2016-06-22 21:04:36 +00:00
|
|
|
RenderCanvas.Brush.Color := ADEventBackgroundColor;
|
|
|
|
RenderCanvas.Pen.Color := ADEventBorderColor;
|
2022-08-16 19:58:12 +00:00
|
|
|
if FWeekView.ApplyCategoryInfos then
|
|
|
|
begin
|
2022-09-04 17:59:54 +00:00
|
|
|
cat := FWeekView.Datastore.CategoryColorMap.GetCategory(event.Category);
|
2022-08-16 19:58:12 +00:00
|
|
|
if cat.UseForAllDayEvents then
|
|
|
|
begin
|
|
|
|
RenderCanvas.Brush.Color := cat.BackgroundColor;
|
|
|
|
RenderCanvas.Pen.Color := cat.Color;
|
|
|
|
end;
|
|
|
|
end;
|
2022-09-04 17:59:54 +00:00
|
|
|
TPSRectangle(RenderCanvas, Angle, RenderIn, ADEvRect);
|
|
|
|
|
|
|
|
// See if the event began before the start of the range
|
|
|
|
if event.StartTime < trunc(RenderDate) then // wp: was DayOf(RenderDate) ???
|
|
|
|
startsBeforeRange := true;
|
2016-07-05 08:42:08 +00:00
|
|
|
|
|
|
|
// Paint the event string
|
2022-09-04 17:59:54 +00:00
|
|
|
eventStr := IfThen(startsBeforeRange, '>> ', '') + event.Description;
|
|
|
|
eventStr := GetDisplayString(RenderCanvas, eventStr, 0, WidthOf(ADEvRect) - 2 * txtMargin);
|
2016-07-05 08:42:08 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
TPSTextOut(RenderCanvas, Angle, RenderIn,
|
|
|
|
ADEvRect.Left + txtMargin,
|
|
|
|
(ADEvRect.Top + ADEvRect.Bottom - txtHeight) div 2,
|
|
|
|
eventStr
|
2016-06-22 21:04:36 +00:00
|
|
|
);
|
2016-07-05 10:20:36 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
TVpWeekViewOpener(FWeekView).wvEventArray[EAIndex].Rec := ADEvRect;
|
|
|
|
TVpWeekViewOpener(FWeekView).wvEventArray[EAIndex].Event := event;
|
2016-07-05 10:20:36 +00:00
|
|
|
|
2016-06-22 21:04:36 +00:00
|
|
|
Inc(EAIndex);
|
2022-09-04 17:59:54 +00:00
|
|
|
Result := True;
|
2016-06-22 21:04:36 +00:00
|
|
|
end; { for I := 0 to pred(ADEventsList.Count) do ... }
|
2016-07-05 08:42:08 +00:00
|
|
|
end; { if NumADEvents > 0 }
|
2016-06-22 21:04:36 +00:00
|
|
|
|
|
|
|
finally
|
2022-08-16 19:58:12 +00:00
|
|
|
RenderCanvas.Brush.Color := savedBrushColor;
|
|
|
|
RenderCanvas.Pen.Color := savedPenColor;
|
2016-06-22 21:04:36 +00:00
|
|
|
ADEventsList.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekViewPainter.DrawBorders;
|
2022-09-04 17:59:54 +00:00
|
|
|
var
|
|
|
|
R: TRect;
|
2016-06-22 21:04:36 +00:00
|
|
|
begin
|
2022-09-04 17:59:54 +00:00
|
|
|
R := Rect(RealLeft, RealTop, RealRight - 1, RealBottom - 1);
|
|
|
|
R := TPSRotateRectangle(Angle, RenderIn, R);
|
|
|
|
case FWeekView.DrawingStyle of
|
|
|
|
dsNoBorder: ;
|
|
|
|
dsFlat: DrawBevelRect(RenderCanvas, R, BevelShadowColor, BevelShadowColor);
|
|
|
|
ds3D: DrawBevelRect(RenderCanvas, R, BevelShadowColor, BevelHighlightColor);
|
2016-06-22 21:04:36 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-24 15:51:13 +00:00
|
|
|
procedure TVpWeekViewPainter.DrawFocusRect(ADayIndex: Integer; DayRect: TRect);
|
|
|
|
var
|
|
|
|
tmpRect: TRect;
|
|
|
|
begin
|
|
|
|
if (not DisplayOnly) and SameDate(StartDate + ADayIndex, FWeekView.Date) and FWeekView.Focused
|
|
|
|
then begin
|
|
|
|
tmpRect := DayRect;
|
|
|
|
InflateRect(tmpRect, -2, -2);
|
2016-07-15 12:29:06 +00:00
|
|
|
tmpRect.Top := tmpRect.Top + FDayHeadHeight;
|
2016-06-24 15:51:13 +00:00
|
|
|
TPSDrawFocusRect(RenderCanvas, Angle, RenderIn, tmpRect);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekViewPainter.DrawDay(ADayIndex: Integer; var DayRect: TRect;
|
2016-06-24 14:16:51 +00:00
|
|
|
var EAIndex: Integer);
|
|
|
|
var
|
|
|
|
TextRect: TRect;
|
2022-09-04 17:59:54 +00:00
|
|
|
delta: Integer;
|
2016-06-24 14:16:51 +00:00
|
|
|
J: Integer;
|
|
|
|
EventList: TList;
|
2016-06-24 14:38:05 +00:00
|
|
|
rowHeight: Integer;
|
2016-06-24 15:51:13 +00:00
|
|
|
tmpRect: TRect;
|
2016-09-23 08:41:52 +00:00
|
|
|
holiday: String;
|
2016-06-24 14:16:51 +00:00
|
|
|
begin
|
2016-06-24 14:38:05 +00:00
|
|
|
// Abbreviations
|
|
|
|
rowHeight := TVpWeekViewOpener(FWeekView).wvRowHeight;
|
2022-09-04 17:59:54 +00:00
|
|
|
delta := IfThen(FWeekView.DrawingStyle = ds3D, 1, 0);
|
2016-06-24 14:38:05 +00:00
|
|
|
|
2016-09-23 08:41:52 +00:00
|
|
|
// Check for holiday
|
|
|
|
FWeekView.IsHoliday(StartDate + ADayIndex, holiday);
|
|
|
|
|
2016-07-01 20:24:54 +00:00
|
|
|
// Get header rectangle
|
2016-06-24 14:16:51 +00:00
|
|
|
TextRect := DayRect;
|
2016-07-15 12:29:06 +00:00
|
|
|
TextRect.Bottom := DayRect.Top + FDayHeadHeight;
|
2016-07-01 20:24:54 +00:00
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
// Draw day header
|
2022-09-04 17:59:54 +00:00
|
|
|
RenderCanvas.Brush.Color := RealDayHeadAttrColor;
|
|
|
|
TPSFillRect(RenderCanvas, Angle, RenderIn, TextRect);
|
|
|
|
tmpRect := TPSRotateRectangle(Angle, RenderIn, TextRect);
|
|
|
|
DrawBevelRect(RenderCanvas, tmpRect, BevelShadowColor, BevelShadowColor);
|
|
|
|
|
|
|
|
// Fix header string and paint it
|
2016-07-01 20:24:54 +00:00
|
|
|
RenderCanvas.Font.Assign(FWeekView.DayHeadAttributes.Font);
|
2017-05-22 08:11:27 +00:00
|
|
|
{$IF VP_LCL_SCALING = 0}
|
2016-08-08 18:29:24 +00:00
|
|
|
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
|
2017-05-22 08:11:27 +00:00
|
|
|
{$ENDIF}
|
2016-09-23 08:41:52 +00:00
|
|
|
DrawDayHeader(ADayIndex, holiday, TextRect);
|
2016-06-24 14:16:51 +00:00
|
|
|
|
|
|
|
if (FWeekView.DataStore <> nil) and (FWeekView.DataStore.Resource <> nil) and
|
2016-06-24 15:51:13 +00:00
|
|
|
(FWeekView.DataStore.Resource.Schedule.EventCountByDay(StartDate + ADayIndex) > 0) and
|
2022-09-02 17:38:26 +00:00
|
|
|
(HeightOf(DayRect) >= FWeekView.TextMargin * 2 + FDayHeadHeight)
|
2016-06-24 14:16:51 +00:00
|
|
|
then begin
|
2016-07-05 10:20:36 +00:00
|
|
|
// Events exist for this day
|
2016-06-24 14:16:51 +00:00
|
|
|
EventList := TList.Create;
|
|
|
|
try
|
2016-07-05 10:20:36 +00:00
|
|
|
// Populate the event list with events for this day
|
2016-06-24 15:51:13 +00:00
|
|
|
FWeekView.DataStore.Resource.Schedule.EventsByDate(StartDate + ADayIndex, EventList);
|
2016-06-30 18:45:39 +00:00
|
|
|
|
|
|
|
{ Now sort times in ascending order. This must be done because the event
|
|
|
|
list can contain recurring events which have the wrong date part }
|
2016-06-30 21:29:02 +00:00
|
|
|
EventList.Sort(CompareEventsByTimeOnly);
|
2016-06-30 18:45:39 +00:00
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
// Initialize TextRect for this day
|
2016-06-24 14:16:51 +00:00
|
|
|
TextRect := DayRect;
|
2022-09-04 17:59:54 +00:00
|
|
|
TextRect.Top := DayRect.Top + FDayHeadHeight + 1;
|
2016-06-24 14:38:05 +00:00
|
|
|
TextRect.Bottom := TextRect.Top + rowHeight;
|
2016-06-24 14:16:51 +00:00
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
// Handle all-day events
|
2016-06-24 14:16:51 +00:00
|
|
|
tmpRect := TextRect;
|
|
|
|
tmpRect.Bottom := DayRect.Bottom;
|
2016-06-24 15:51:13 +00:00
|
|
|
if DrawAllDayEvents(StartDate + ADayIndex, tmpRect, EAIndex) then
|
2016-06-24 14:16:51 +00:00
|
|
|
begin
|
|
|
|
TextRect.Bottom := TextRect.Bottom + ADEventsRect.Bottom - TextRect.Top;
|
|
|
|
TextRect.Top := ADEventsRect.Bottom;
|
|
|
|
end;
|
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
// Discard AllDayEvents, because they are drawn above.
|
2016-06-24 14:16:51 +00:00
|
|
|
for J := pred(EventList.Count) downto 0 do
|
2016-06-30 18:45:39 +00:00
|
|
|
if TVpEvent(EventList[J]).AllDayEvent then
|
2016-06-24 14:16:51 +00:00
|
|
|
EventList.Delete(J);
|
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
// Iterate the events, painting them one by one
|
2016-06-24 14:16:51 +00:00
|
|
|
for J := 0 to pred(EventList.Count) do begin
|
|
|
|
{ if the TextRect extends below the available space then draw a }
|
|
|
|
{ dot dot dot to indicate there are more events than can be drawn }
|
|
|
|
{ in the available space }
|
2022-09-02 17:38:26 +00:00
|
|
|
if TextRect.Bottom - FWeekView.TextMargin > DayRect.Bottom then begin
|
2016-07-01 20:24:54 +00:00
|
|
|
{ Draw ". . ." }
|
2016-07-01 20:45:03 +00:00
|
|
|
DrawDotDotDot(DayRect, DotDotDotColor);
|
2016-06-24 14:16:51 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
// Write the event text
|
2016-07-12 09:26:14 +00:00
|
|
|
DrawEvent(TVpEvent(EventList.List^[J]), TextRect, ADayIndex);
|
2016-06-24 14:16:51 +00:00
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
// Update the EventArray
|
2016-06-24 15:51:13 +00:00
|
|
|
with TVpWeekViewOpener(FWeekView).wvEventArray[EAIndex] do begin
|
|
|
|
Rec := TextRect;
|
2016-07-05 10:20:36 +00:00
|
|
|
Event := TVpEvent(EventList[J]);
|
2016-06-24 15:51:13 +00:00
|
|
|
end;
|
2016-06-24 14:16:51 +00:00
|
|
|
Inc(EAIndex);
|
|
|
|
|
|
|
|
TextRect.Top := TextRect.Bottom;
|
2016-06-24 14:38:05 +00:00
|
|
|
TextRect.Bottom := TextRect.Top + rowHeight;
|
2016-06-24 14:16:51 +00:00
|
|
|
end; { for loop }
|
2016-07-05 10:20:36 +00:00
|
|
|
|
2016-06-24 14:16:51 +00:00
|
|
|
finally
|
|
|
|
EventList.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Draw focus rect if this is the current day }
|
2016-06-24 15:51:13 +00:00
|
|
|
DrawFocusRect(ADayIndex, DayRect);
|
2016-06-24 14:16:51 +00:00
|
|
|
|
|
|
|
{ update WeekdayArray }
|
2016-06-24 15:51:13 +00:00
|
|
|
with TVpWeekViewOpener(FWeekView).wvWeekdayArray[ADayIndex] do begin
|
2016-06-24 14:16:51 +00:00
|
|
|
Rec := DayRect;
|
2016-06-24 15:51:13 +00:00
|
|
|
Day := StartDate + ADayIndex;
|
2016-06-24 14:16:51 +00:00
|
|
|
end;
|
|
|
|
|
2022-09-07 16:29:58 +00:00
|
|
|
// Adjust the DayRect for the next day
|
2016-09-23 11:40:39 +00:00
|
|
|
case FWeekView.Layout of
|
2022-09-07 16:29:58 +00:00
|
|
|
wvlVertical: // DayIndex layout
|
|
|
|
if (ADayIndex = 2) then begin // 0 3
|
|
|
|
// Move the dayrect to the top of the next column //
|
|
|
|
DayRect := Rect( // 1 4
|
|
|
|
RealLeft + DayRectWidth, //
|
|
|
|
RealTop + FHeaderHeight, // 2 5
|
|
|
|
RealRight - 1 - delta, // 6
|
2022-09-04 17:59:54 +00:00
|
|
|
RealTop + FHeaderHeight + DayRectHeight
|
|
|
|
)
|
|
|
|
end else
|
|
|
|
if (ADayIndex = 4) then
|
|
|
|
begin
|
|
|
|
// Friday: shrink DayRect for weekend days
|
2016-09-23 11:40:39 +00:00
|
|
|
DayRect.Top := DayRect.Bottom;
|
2022-09-04 17:59:54 +00:00
|
|
|
DayRect.Bottom := DayRect.Top + DayRectHeight div 2;
|
2016-09-23 11:40:39 +00:00
|
|
|
end
|
2022-09-04 17:59:54 +00:00
|
|
|
else if (ADayIndex = 5) then
|
|
|
|
begin
|
|
|
|
DayRect.Top := DayRect.Bottom;
|
|
|
|
DayRect.Bottom := RealTop + FHeaderHeight + DayRectHeight;
|
|
|
|
end else
|
|
|
|
begin
|
2016-09-23 11:40:39 +00:00
|
|
|
DayRect.Top := DayRect.Bottom;
|
|
|
|
DayRect.Bottom := DayRect.Top + DayRectHeight;
|
|
|
|
end;
|
|
|
|
|
|
|
|
wvlHorizontal:
|
2022-09-07 16:29:58 +00:00
|
|
|
begin // DayIndex layout
|
|
|
|
if (ADayIndex in [0, 2, 4]) then // 0 1
|
|
|
|
begin //
|
|
|
|
DayRect.Left := RealLeft + DayRectWidth; // 2 3
|
|
|
|
DayRect.Right := RealRight - 1 - delta; //
|
|
|
|
end else if (ADayIndex <> 5) then // 4 5
|
|
|
|
begin // 6
|
2022-09-04 17:59:54 +00:00
|
|
|
DayRect.Right := RealLeft + DayRectWidth;
|
|
|
|
DayRect.Left := RealLeft;
|
2016-09-23 11:40:39 +00:00
|
|
|
end;
|
2022-09-04 17:59:54 +00:00
|
|
|
if (ADayIndex in [1, 3]) then
|
|
|
|
begin
|
2016-09-23 11:40:39 +00:00
|
|
|
DayRect.Top := DayRect.Bottom;
|
2022-09-07 16:29:58 +00:00
|
|
|
DayRect.Bottom := DayRect.Top + DayRectHeight;
|
2022-09-04 17:59:54 +00:00
|
|
|
end else
|
|
|
|
if ADayIndex = 4 then
|
|
|
|
DayRect.Bottom := DayRect.Top + DayRectHeight div 2
|
|
|
|
else if ADayIndex = 5 then
|
2022-09-07 16:29:58 +00:00
|
|
|
begin
|
|
|
|
DayRect.Top := DayRect.Bottom;
|
|
|
|
DayRect.Bottom := DayRect.Top + DayRectHeight div 2;
|
|
|
|
end;
|
2016-09-23 11:40:39 +00:00
|
|
|
end;
|
|
|
|
end; // case
|
2016-06-24 14:16:51 +00:00
|
|
|
end;
|
|
|
|
|
2016-09-23 08:41:52 +00:00
|
|
|
procedure TVpWeekViewPainter.DrawDayHeader(ADayIndex: Integer; AHolidayName: String;
|
|
|
|
var TextRect: TRect);
|
2016-06-24 15:51:13 +00:00
|
|
|
var
|
|
|
|
dayStr: String;
|
|
|
|
strWid: Integer;
|
2016-07-15 12:29:06 +00:00
|
|
|
strH: Integer;
|
2016-09-23 08:56:12 +00:00
|
|
|
savedFontstyle: TFontStyles;
|
2016-06-24 15:51:13 +00:00
|
|
|
begin
|
2016-09-23 08:56:12 +00:00
|
|
|
savedFontstyle := RenderCanvas.Font.Style;
|
|
|
|
if (not DisplayOnly) and SameDate(StartDate + ADayIndex, FWeekView.Date) then
|
|
|
|
RenderCanvas.Font.Style := RenderCanvas.Font.Style + [fsBold];
|
2016-06-24 15:51:13 +00:00
|
|
|
|
2016-09-23 08:56:12 +00:00
|
|
|
dayStr := GetDateDisplayString(RenderCanvas, StartDate + ADayIndex,
|
2022-09-04 17:59:54 +00:00
|
|
|
FWeekView.DayHeadAttributes.DateFormat, AHolidayName, WidthOf(TextRect) - FWeekView.HeaderMargin*2);
|
2016-06-24 15:51:13 +00:00
|
|
|
strWid := RenderCanvas.TextWidth(dayStr);
|
2016-07-15 12:29:06 +00:00
|
|
|
strH := RenderCanvas.TextHeight(dayStr);
|
2016-06-24 15:51:13 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
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;
|
2016-06-24 15:51:13 +00:00
|
|
|
TPSTextOut(
|
|
|
|
RenderCanvas,
|
|
|
|
Angle,
|
|
|
|
RenderIn,
|
|
|
|
TextRect.Left,
|
2016-07-15 12:29:06 +00:00
|
|
|
(TextRect.Top + TextRect.Bottom - strH) div 2,
|
2016-06-24 15:51:13 +00:00
|
|
|
dayStr
|
|
|
|
);
|
2016-09-23 08:56:12 +00:00
|
|
|
|
|
|
|
RenderCanvas.Font.Style := savedFontstyle;
|
2016-06-24 15:51:13 +00:00
|
|
|
end;
|
|
|
|
|
2016-06-22 21:04:36 +00:00
|
|
|
procedure TVpWeekViewPainter.DrawDays;
|
|
|
|
var
|
|
|
|
DayRect: TRect;
|
2016-07-05 10:20:36 +00:00
|
|
|
EAIndex: Integer; // Index of last-used item in wvEventArray
|
2016-06-24 14:16:51 +00:00
|
|
|
I: Integer;
|
2016-06-24 15:51:13 +00:00
|
|
|
realCenter: Integer;
|
2022-09-04 17:59:54 +00:00
|
|
|
delta: Integer;
|
2016-06-22 21:04:36 +00:00
|
|
|
begin
|
2016-06-24 15:51:13 +00:00
|
|
|
with TVpWeekViewOpener(FWeekView) do begin
|
2022-09-04 17:59:54 +00:00
|
|
|
// Initialize weekday array
|
2016-06-22 21:04:36 +00:00
|
|
|
for I := 0 to pred(Length(wvWeekdayArray)) do begin
|
|
|
|
wvWeekdayArray[I].Rec.TopLeft := Point(-1, -1);
|
|
|
|
wvWeekdayArray[I].Rec.BottomRight := Point(-1, -1);
|
|
|
|
wvWeekdayArray[I].Day := 0;
|
|
|
|
end;
|
2016-07-05 10:20:36 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Initialize event array
|
2016-06-24 15:51:13 +00:00
|
|
|
EAIndex := 0;
|
2016-06-22 21:04:36 +00:00
|
|
|
for I := 0 to pred(Length(wvEventArray)) do begin
|
|
|
|
wvEventArray[I].Rec.TopLeft := Point(-1, -1);
|
|
|
|
wvEventArray[I].Rec.BottomRight := Point(-1, -1);
|
|
|
|
wvEventArray[I].Event := nil;
|
|
|
|
end;
|
2022-09-04 17:59:54 +00:00
|
|
|
|
|
|
|
if DrawingStyle = ds3D then delta := 1 else delta := 0;
|
2016-06-24 15:51:13 +00:00
|
|
|
end;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
|
|
|
RenderCanvas.Pen.Color := RealLineColor;
|
2016-06-24 14:16:51 +00:00
|
|
|
RenderCanvas.Pen.Style := psSolid;
|
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Build the first day rect
|
|
|
|
DayRectHeight := (RealBottom - RealTop - FHeaderHeight) div 3;
|
2016-09-23 11:40:39 +00:00
|
|
|
DayRectWidth := (RealRight - RealLeft) div 2;
|
2016-06-24 14:38:05 +00:00
|
|
|
DayRect := Rect(
|
2022-09-04 17:59:54 +00:00
|
|
|
RealLeft,
|
|
|
|
RealTop + FHeaderHeight,
|
|
|
|
RealLeft + DayRectWidth,
|
|
|
|
RealTop + FHeaderHeight + DayRectHeight
|
2016-06-24 14:38:05 +00:00
|
|
|
);
|
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Draw the day frames and texts
|
2016-06-24 14:16:51 +00:00
|
|
|
for I := 0 to 6 do
|
|
|
|
DrawDay(I, DayRect, EAIndex);
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Draw the center vertical line
|
2016-06-22 21:04:36 +00:00
|
|
|
RenderCanvas.Pen.Color := RealLineColor;
|
2016-06-24 15:51:13 +00:00
|
|
|
realCenter := RealLeft + (RealRight - RealLeft) div 2;
|
2022-09-04 17:59:54 +00:00
|
|
|
TPSMoveTo(RenderCanvas, Angle, RenderIn, realCenter, RealTop + FHeaderHeight + 1);
|
2016-06-24 15:51:13 +00:00
|
|
|
TPSLineTo(RenderCanvas, Angle, RenderIn, realCenter, RealBottom - 1);
|
|
|
|
end;
|
|
|
|
|
2016-07-12 09:26:14 +00:00
|
|
|
procedure TVpWeekViewPainter.DrawEvent(AEvent: TVpEvent; TextRect: TRect;
|
2016-06-24 15:51:13 +00:00
|
|
|
ADayIndex: Integer);
|
|
|
|
var
|
|
|
|
dayStr: String;
|
|
|
|
todayStartTime: TDateTime;
|
|
|
|
todayEndTime: TDateTime;
|
2022-09-02 17:38:26 +00:00
|
|
|
txtMargin: Integer;
|
2016-06-24 15:51:13 +00:00
|
|
|
strLen: Integer;
|
2016-09-10 17:26:42 +00:00
|
|
|
oldFontColor: TColor;
|
2022-07-12 14:31:42 +00:00
|
|
|
eventCat: TVpCategoryInfo;
|
2022-08-06 09:51:54 +00:00
|
|
|
R: TRect;
|
2016-06-24 15:51:13 +00:00
|
|
|
begin
|
2016-09-10 17:26:42 +00:00
|
|
|
oldFontColor := RenderCanvas.Font.Color;
|
2022-09-02 17:38:26 +00:00
|
|
|
txtmargin := FWeekView.TextMargin;
|
|
|
|
|
2016-06-24 15:51:13 +00:00
|
|
|
{ format the display text }
|
|
|
|
todayStartTime := AEvent.StartTime;
|
|
|
|
todayEndTime := AEvent.EndTime;
|
2016-06-29 20:32:12 +00:00
|
|
|
|
|
|
|
// Event reaches into the next day(s)
|
|
|
|
if trunc(todayEndTime) > trunc(todayStartTime) then begin
|
|
|
|
if trunc(todayStartTime) < trunc(StartDate + ADayIndex) then // first event
|
|
|
|
todayStartTime := 0;
|
|
|
|
if trunc(TodayEndTime) > trunc(StartDate + ADayIndex) then // last event
|
|
|
|
todayEndTime := 0.9999;
|
|
|
|
end;
|
2016-06-24 15:51:13 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Set the event font
|
2016-06-24 15:51:13 +00:00
|
|
|
RenderCanvas.Font.Assign(FWeekView.EventFont);
|
2017-05-22 08:11:27 +00:00
|
|
|
{$IF VP_LCL_SCALING = 0}
|
2016-08-08 18:29:24 +00:00
|
|
|
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
|
2017-05-22 08:11:27 +00:00
|
|
|
{$ENDIF}
|
2016-09-10 17:26:42 +00:00
|
|
|
if AEvent.IsOverlayed then
|
|
|
|
RenderCanvas.Font.Color := clGray;
|
2022-09-04 17:59:54 +00:00
|
|
|
|
|
|
|
// Draw event background
|
2016-06-24 15:51:13 +00:00
|
|
|
RenderCanvas.Brush.Color := RealColor;
|
2022-07-12 14:31:42 +00:00
|
|
|
if Assigned(FWeekView.Datastore) and FWeekView.ApplyCategoryInfos then
|
|
|
|
begin
|
|
|
|
eventCat := FWeekView.Datastore.CategoryColorMap.GetCategory(AEvent.Category);
|
|
|
|
if Assigned(eventCat) then
|
|
|
|
begin
|
|
|
|
RenderCanvas.Brush.Color := eventCat.BackgroundColor;
|
|
|
|
TPSFillRect(RenderCanvas, Angle, RenderIn, TextRect);
|
2022-08-06 09:51:54 +00:00
|
|
|
R := TextRect;
|
|
|
|
{$IF VP_LCL_SCALING > 0}
|
2022-09-04 23:06:49 +00:00
|
|
|
R.Right := R.Left + FWeekView.Scale96ToFont(FWeekView.GutterWidth);
|
2022-08-06 09:51:54 +00:00
|
|
|
{$ELSE}
|
2022-09-04 23:06:49 +00:00
|
|
|
R.Right := R.Left + ScaleX(FWeekView.GutterWidth, DesignTimeDPI);
|
2022-08-06 09:51:54 +00:00
|
|
|
{$IFEND}
|
|
|
|
TextRect.Left := R.Right;
|
|
|
|
RenderCanvas.Brush.Color := eventCat.Color;
|
|
|
|
TPSFillRect(RenderCanvas, Angle, RenderIn, R);
|
2022-07-12 14:31:42 +00:00
|
|
|
end;
|
|
|
|
end;
|
2016-06-24 15:51:13 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Build the event text
|
2016-09-12 22:25:34 +00:00
|
|
|
dayStr := FWeekView.BuildEventString(AEvent, todayStartTime, todayEndTime, false);
|
2016-06-24 15:51:13 +00:00
|
|
|
strLen := RenderCanvas.TextWidth(dayStr);
|
2022-09-02 17:38:26 +00:00
|
|
|
if (strLen > WidthOf(TextRect) - txtMargin * 2) then
|
|
|
|
dayStr := GetDisplayString(RenderCanvas, dayStr, 0, WidthOf(TextRect) - txtMargin * 2);
|
2016-06-24 15:51:13 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Write out the event text
|
2016-06-24 15:51:13 +00:00
|
|
|
TPSTextOut(RenderCanvas, Angle, RenderIn,
|
2022-09-02 17:38:26 +00:00
|
|
|
TextRect.Left + txtMargin, TextRect.Top + txtMargin div 2,
|
2016-06-24 15:51:13 +00:00
|
|
|
dayStr
|
|
|
|
);
|
2016-09-10 17:26:42 +00:00
|
|
|
|
|
|
|
RenderCanvas.Font.Color := oldFontColor;
|
2016-06-22 21:04:36 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekViewPainter.DrawHeader;
|
|
|
|
var
|
2022-09-04 17:59:54 +00:00
|
|
|
headRect, R: TRect;
|
2022-09-04 22:27:33 +00:00
|
|
|
// headTextRect: TRect;
|
2022-09-04 17:59:54 +00:00
|
|
|
headStr: string = '';
|
|
|
|
headStrLen: Integer;
|
2022-09-04 22:11:52 +00:00
|
|
|
maxStrLen: Integer;
|
2016-06-24 20:00:32 +00:00
|
|
|
weekNo: Integer;
|
2022-07-21 12:31:50 +00:00
|
|
|
startStr, endStr: String;
|
2022-08-12 22:21:13 +00:00
|
|
|
txtStart: Integer;
|
2022-09-04 22:11:52 +00:00
|
|
|
margin: Integer;
|
2016-06-22 21:04:36 +00:00
|
|
|
begin
|
2022-09-04 22:11:52 +00:00
|
|
|
margin := FWeekView.HeaderMargin;
|
2022-09-04 17:59:54 +00:00
|
|
|
|
2016-06-22 21:04:36 +00:00
|
|
|
RenderCanvas.Brush.Color := RealHeadAttrColor;
|
|
|
|
RenderCanvas.Font.Assign(TFont(FWeekView.HeadAttributes.Font));
|
2017-05-22 08:11:27 +00:00
|
|
|
{$IF VP_LCL_SCALING = 0}
|
2016-08-08 18:29:24 +00:00
|
|
|
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
|
2017-05-22 08:11:27 +00:00
|
|
|
{$ENDIF}
|
2016-07-02 23:14:26 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Draw the header cell and borders
|
|
|
|
headRect := Rect(RealLeft, RealTop, RealRight, RealTop + FHeaderHeight);
|
|
|
|
case FWeekView.DrawingStyle of
|
|
|
|
dsNoBorder:
|
|
|
|
TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
|
|
|
|
dsFlat:
|
|
|
|
begin // Draw simple border rectangle
|
|
|
|
TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
|
|
|
|
R := TPSRotateRectangle(Angle, RenderIn, headRect);
|
|
|
|
DrawBevelRect(RenderCanvas, R, BevelShadowColor, BevelShadowColor);
|
|
|
|
end;
|
|
|
|
ds3D:
|
|
|
|
begin // Draw a 3D bevel (raised)
|
|
|
|
R := Rect(headRect.Left+1, headRect.Top+1, headRect.Right-2, headRect.Bottom);
|
|
|
|
TPSFillRect(RenderCanvas, Angle, RenderIn, headRect);
|
|
|
|
R := TPSRotateRectangle(Angle, RenderIn, R);
|
|
|
|
DrawBevelRect(RenderCanvas, R, BevelHighlightColor, BevelShadowColor);
|
|
|
|
end;
|
2016-07-02 23:14:26 +00:00
|
|
|
end;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2022-09-04 22:11:52 +00:00
|
|
|
// Position the spinner buttons
|
|
|
|
with FWeekView do begin
|
|
|
|
PrevMonthBtn.Width := PrevMonthBtn.Height;
|
|
|
|
PrevMonthBtn.Left := margin;
|
|
|
|
PrevMonthBtn.Top := (headRect.Top + headRect.Bottom - PrevMonthBtn.Height) div 2;
|
|
|
|
|
|
|
|
PrevWeekBtn.Height := PrevMonthBtn.Height;
|
|
|
|
PrevWeekBtn.Width := PrevMonthBtn.Height;
|
|
|
|
PrevWeekBtn.Left := PrevMonthBtn.Left + PrevMonthBtn.Width;
|
|
|
|
PrevWeekBtn.Top := PrevMonthBtn.Top;
|
|
|
|
|
|
|
|
NextWeekBtn.Height := PrevMonthBtn.Height;
|
|
|
|
NextWeekBtn.Width := PrevMonthBtn.Height;
|
|
|
|
NextWeekBtn.Left := PrevWeekBtn.Left + PrevWeekBtn.Width;
|
|
|
|
NextWeekBtn.Top := PrevMonthBtn.Top;
|
|
|
|
|
|
|
|
NextMonthBtn.Height := PrevMonthBtn.Height;
|
|
|
|
NextMonthBtn.Width := PrevMonthBtn.Height;
|
|
|
|
NextMonthBtn.Left := NextWeekBtn.Left + NextWeekBtn.Width;
|
|
|
|
NextMonthBtn.Top := PrevMonthBtn.Top;
|
|
|
|
|
|
|
|
txtStart := NextMonthBtn.Left + NextMonthBtn.Width + margin;
|
|
|
|
end;
|
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
// Build header caption
|
2016-06-24 20:00:32 +00:00
|
|
|
weekNo := GetWeekOfYear(StartDate);
|
2022-07-21 12:31:50 +00:00
|
|
|
startStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate);
|
|
|
|
endStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate+6);
|
2022-09-04 17:59:54 +00:00
|
|
|
headStr := Format('%s %d (%s - %s)', [RSCalendarWeek, weekNo, startStr, endStr]);
|
2016-06-24 20:00:32 +00:00
|
|
|
|
2022-09-04 22:11:52 +00:00
|
|
|
// Draw the text
|
|
|
|
{
|
|
|
|
if DisplayOnly and (RenderCanvas.TextWidth(headStr) >= WidthOf(RenderIn)) then
|
|
|
|
headTextRect.TopLeft := Point(RealLeft + margin, HeadRect.Top)
|
2016-06-22 21:04:36 +00:00
|
|
|
else
|
|
|
|
if DisplayOnly then
|
2022-09-04 17:59:54 +00:00
|
|
|
headTextRect.TopLeft := Point(
|
|
|
|
RealLeft + (RealRight - RealLeft - RenderCanvas.TextWidth(headStr)) div 2,
|
|
|
|
headRect.Top
|
2016-06-22 21:04:36 +00:00
|
|
|
)
|
|
|
|
else
|
2022-09-04 17:59:54 +00:00
|
|
|
headTextRect.TopLeft := Point(
|
2022-09-04 22:11:52 +00:00
|
|
|
RealLeft + Trunc(TVpWeekViewOpener(FWeekView).wvHeaderHeight * 0.8) * 2 + margin,
|
2022-09-04 17:59:54 +00:00
|
|
|
headRect.Top
|
2016-06-22 21:04:36 +00:00
|
|
|
);
|
2022-09-04 17:59:54 +00:00
|
|
|
headTextRect.BottomRight := headRect.BottomRight;
|
2022-09-04 22:11:52 +00:00
|
|
|
dec(headTextRect.Right, margin);
|
|
|
|
}
|
2016-07-03 08:39:53 +00:00
|
|
|
|
2022-09-04 22:11:52 +00:00
|
|
|
// Fix length of header string
|
2022-09-04 17:59:54 +00:00
|
|
|
headStrLen := RenderCanvas.TextWidth(headStr);
|
2022-09-04 22:11:52 +00:00
|
|
|
maxStrLen := headRect.Right - margin - txtStart;
|
|
|
|
if headStrLen > maxStrLen then
|
|
|
|
headStr := GetDisplayString(RenderCanvas, headStr, 0, maxStrlen);
|
2022-08-12 22:21:13 +00:00
|
|
|
|
2016-06-22 21:04:36 +00:00
|
|
|
TPSTextOut(RenderCanvas, Angle, RenderIn,
|
2022-08-12 22:21:13 +00:00
|
|
|
txtStart,
|
2022-09-04 22:11:52 +00:00
|
|
|
(headRect.Top + headRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2,
|
2022-09-04 17:59:54 +00:00
|
|
|
headStr
|
2016-06-22 21:04:36 +00:00
|
|
|
);
|
|
|
|
end;
|
|
|
|
|
2016-07-05 08:42:08 +00:00
|
|
|
procedure TVpWeekViewPainter.FixFontHeights;
|
|
|
|
begin
|
|
|
|
with FWeekView do begin
|
2022-09-02 17:38:26 +00:00
|
|
|
{$IF VP_LCL_SCALING = 0}
|
2016-07-05 08:42:08 +00:00
|
|
|
AllDayEventAttributes.Font.Height := GetRealFontHeight(AllDayEventAttributes.Font);
|
|
|
|
DayHeadAttributes.Font.Height := GetRealFontHeight(DayHeadAttributes.Font);
|
|
|
|
EventFont.Height := GetRealFontHeight(EventFont);
|
|
|
|
Font.Height := GetRealFontHeight(Font);
|
|
|
|
HeadAttributes.Font.Height := GetRealFontHeight(HeadAttributes.Font);
|
2022-09-02 17:38:26 +00:00
|
|
|
{$ELSE}
|
|
|
|
AllDayEventAttributes.Font.Height := FixFontHeight(AllDayEventAttributes.Font);
|
|
|
|
DayHeadAttributes.Font.Height := FixFontHeight(DayHeadAttributes.Font);
|
|
|
|
EventFont.Height := FixFontHeight(EventFont);
|
|
|
|
Font.Height := FixFontHeight(Font);
|
|
|
|
HeadAttributes.Font.Height := FixFontHeight(HeadAttributes.Font);
|
|
|
|
{$IFEND}
|
2016-07-05 08:42:08 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-23 11:53:21 +00:00
|
|
|
procedure TVpWeekViewPainter.InitColors;
|
2016-06-22 21:04:36 +00:00
|
|
|
begin
|
|
|
|
if DisplayOnly then begin
|
|
|
|
BevelHighlightColor := clBlack;
|
|
|
|
BevelShadowColor := clBlack;
|
|
|
|
BevelDarkShadow := clBlack;
|
|
|
|
BevelButtonFace := clBlack;
|
|
|
|
RealLineColor := clBlack;
|
|
|
|
RealColor := clWhite;
|
|
|
|
RealDayHeadAttrColor := clSilver;
|
|
|
|
RealHeadAttrColor := clSilver;
|
|
|
|
ADBackgroundColor := clWhite;
|
|
|
|
ADEventBackgroundColor := clWhite;
|
|
|
|
ADEventBorderColor := clSilver;
|
|
|
|
end else begin
|
|
|
|
BevelHighlightColor := clBtnHighlight;
|
|
|
|
BevelShadowColor := clBtnShadow;
|
|
|
|
BevelDarkShadow := cl3DDkShadow;
|
|
|
|
BevelButtonFace := clBtnFace;
|
|
|
|
RealLineColor := FWeekView.LineColor;
|
|
|
|
RealColor := FWeekView.Color;
|
|
|
|
RealDayHeadAttrColor := FWeekView.DayHeadAttributes.Color;
|
|
|
|
RealHeadAttrColor := FWeekView.HeadAttributes.Color;
|
|
|
|
ADBackgroundColor := FWeekView.AllDayEventAttributes.BackgroundColor;
|
|
|
|
ADEventBackgroundColor := FWeekView.AllDayEventAttributes.EventBackgroundColor;
|
|
|
|
ADEventBorderColor := FWeekView.AllDayEventAttributes.EventBorderColor;
|
|
|
|
end;
|
|
|
|
DotDotDotColor := clBlack;
|
2016-06-23 11:53:21 +00:00
|
|
|
end;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2016-06-23 11:53:21 +00:00
|
|
|
procedure TVpWeekViewPainter.RenderToCanvas(ARenderIn: TRect;
|
|
|
|
AAngle: TVpRotationAngle; AScale: Extended; ARenderDate: TDateTime;
|
|
|
|
AStartLine, AStopLine: Integer; AUseGran: TVpGranularity; ADisplayOnly: Boolean);
|
|
|
|
begin
|
|
|
|
inherited;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
2016-06-23 11:53:21 +00:00
|
|
|
InitColors;
|
|
|
|
SavePenBrush;
|
|
|
|
InitPenBrush;
|
2016-07-15 11:52:21 +00:00
|
|
|
if ADisplayOnly then FixFontHeights;
|
2016-07-02 22:46:05 +00:00
|
|
|
|
2016-06-22 21:04:36 +00:00
|
|
|
Rgn := CreateRectRgn(RenderIn.Left, RenderIn.Top, RenderIn.Right, RenderIn.Bottom);
|
|
|
|
try
|
|
|
|
SelectClipRgn(RenderCanvas.Handle, Rgn);
|
|
|
|
|
|
|
|
{ clear client area }
|
|
|
|
Clear;
|
|
|
|
|
|
|
|
{ measure the row heights }
|
|
|
|
SetMeasurements;
|
|
|
|
|
|
|
|
{ draw header }
|
|
|
|
DrawHeader;
|
|
|
|
|
|
|
|
{ draw days }
|
|
|
|
DrawDays;
|
|
|
|
|
|
|
|
{ draw the borders }
|
|
|
|
DrawBorders;
|
|
|
|
|
|
|
|
finally
|
|
|
|
{ reinstate canvas settings}
|
|
|
|
SelectClipRgn(RenderCanvas.Handle, 0);
|
|
|
|
DeleteObject(Rgn);
|
|
|
|
end;
|
|
|
|
|
2016-06-23 11:53:21 +00:00
|
|
|
RestorePenBrush;
|
2016-06-22 21:04:36 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekViewPainter.SetMeasurements;
|
2022-09-04 17:59:54 +00:00
|
|
|
var
|
|
|
|
h: Integer;
|
2016-06-22 21:04:36 +00:00
|
|
|
begin
|
2016-06-23 11:53:21 +00:00
|
|
|
inherited;
|
2016-06-22 21:04:36 +00:00
|
|
|
|
|
|
|
with TVpWeekViewOpener(FWeekView) do
|
2022-09-04 17:59:54 +00:00
|
|
|
begin
|
2016-06-22 21:04:36 +00:00
|
|
|
if RenderDate = 0 then
|
|
|
|
StartDate := GetStartOfWeek(wvStartDate, WeekStartsOn)
|
|
|
|
else
|
|
|
|
StartDate := GetStartOfWeek(RenderDate, WeekStartsOn);
|
|
|
|
|
2022-09-04 23:06:49 +00:00
|
|
|
wvRowHeight := GetCanvasTextHeight(RenderCanvas, EventFont, VpProductName) + TextMargin * 2;
|
2016-08-08 18:29:24 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
Self.FDayHeadHeight := GetCanvasTextHeight(RenderCanvas, DayHeadAttributes.Font) + TextMargin * 2;
|
2016-08-08 18:29:24 +00:00
|
|
|
|
2022-09-04 17:59:54 +00:00
|
|
|
h := GetCanvasTextHeight(RenderCanvas, HeadAttributes.Font, VpProductName);
|
|
|
|
Self.FHeaderHeight := Max(h, PrevMonthBtn.Height) + HeaderMargin * 2;
|
|
|
|
wvHeaderHeight := FHeaderHeight;
|
|
|
|
end;
|
2016-06-22 21:04:36 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|