tvplanit: Some elemental code for VpGanttView (cooperation with control link and datastore).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8415 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-08-22 22:30:13 +00:00
parent 0be0798652
commit c11c9f5163
4 changed files with 146 additions and 6 deletions

View File

@@ -32,7 +32,7 @@ Portions created by TurboPower Software Inc. are Copyright (C) 2002 TurboPower S
Contributor(s): "/> Contributor(s): "/>
<Version Major="1" Minor="7"/> <Version Major="1" Minor="7"/>
<Files Count="68"> <Files Count="69">
<Item1> <Item1>
<Filename Value="source\vpbase.pas"/> <Filename Value="source\vpbase.pas"/>
<UnitName Value="VpBase"/> <UnitName Value="VpBase"/>
@@ -299,12 +299,16 @@ Contributor(s): "/>
</Item66> </Item66>
<Item67> <Item67>
<Filename Value="source\vpganttview.pas"/> <Filename Value="source\vpganttview.pas"/>
<UnitName Value="vpganttview"/> <UnitName Value="VpGanttView"/>
</Item67> </Item67>
<Item68> <Item68>
<Filename Value="source\vpganttview.pas"/> <Filename Value="source\vpganttview.pas"/>
<UnitName Value="vpganttview"/> <UnitName Value="VpGanttView"/>
</Item68> </Item68>
<Item69>
<Filename Value="source\vpganttviewpainter.pas"/>
<UnitName Value="vpganttviewpainter"/>
</Item69>
</Files> </Files>
<CompatibilityMode Value="True"/> <CompatibilityMode Value="True"/>
<i18n> <i18n>

View File

@@ -176,6 +176,7 @@ uses
VpMonthView, { Month View Component } VpMonthView, { Month View Component }
VpContactGrid, { ContactGrid Component } VpContactGrid, { ContactGrid Component }
VpTaskList, { Task List Component } VpTaskList, { Task List Component }
VpGanttView, { Gantt View Component }
{$IFDEF DELPHI} {$IFDEF DELPHI}
VpBDEDS, { DataStore Component } VpBDEDS, { DataStore Component }
VpDateEdit, { DateEdit Component } VpDateEdit, { DateEdit Component }
@@ -676,6 +677,7 @@ begin
TVpTaskList, TVpTaskList,
TVpContactGrid, TVpContactGrid,
TVpContactButtonBar, TVpContactButtonBar,
TVpGanttView,
TVpResourceCombo, TVpResourceCombo,
TVpPrintFormatComboBox, TVpPrintFormatComboBox,
TVpResourceEditDialog, TVpResourceEditDialog,

View File

@@ -1938,7 +1938,7 @@ end;
procedure TVpDayView.CreateWnd; procedure TVpDayView.CreateWnd;
begin begin
inherited; inherited;
PostMessage (Handle, Vp_DayViewInit, 0, 0); PostMessage(Handle, Vp_DayViewInit, 0, 0);
end; end;
procedure TVpDayView.MouseEnter; procedure TVpDayView.MouseEnter;

View File

@@ -5,16 +5,38 @@ unit VpGanttView;
interface interface
uses uses
Classes, SysUtils, Classes, SysUtils, Graphics,
VpBaseDS, VpData; VpBase, VpBaseDS, VpData;
type type
TVpGanttView = class(TVpLinkableControl) TVpGanttView = class(TVpLinkableControl)
private private
FDate: TDateTime;
FInLinkHandler: Boolean;
FLoaded: Boolean;
FPainting: Boolean;
FStartDate: TDateTime;
procedure SetDate(AValue: TDateTime);
protected protected
{ internal methods }
procedure Hookup;
procedure Populate;
{ inherited methods }
procedure Loaded; override;
procedure Paint; override;
public public
constructor Create(AOwner: TComponent); override;
procedure LinkHandler(Sender: TComponent;
NotificationType: TVpNotificationType; const Value: Variant); override;
procedure RenderToCanvas(RenderCanvas: TCanvas; RenderIn: TRect;
Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime;
StartLine, StopLine: Integer; UseGran: TVpGranularity;
DisplayOnly: Boolean); override;
property Date: TDateTime read FDate write SetDate;
published published
@@ -22,5 +44,117 @@ type
implementation implementation
uses
VpGanttViewPainter;
constructor TVpGanttView.Create(AOwner: TComponent);
begin
inherited;
FInLinkHandler := false;
FLoaded := false;
FPainting := false;
SetDate(Now);
FStartDate := FDate;
end;
{ If the component is being dropped on a form at designtime, then
automatically hook up to the first datastore component found. }
procedure TVpGanttView.HookUp;
var
I: Integer;
begin
if csDesigning in ComponentState then
for I := 0 to pred(Owner.ComponentCount) do begin
if (Owner.Components[I] is TVpCustomDataStore) then begin
DataStore := TVpCustomDataStore(Owner.Components[I]);
Exit;
end;
end;
end;
procedure TVpGanttView.LinkHandler(Sender: TComponent;
NotificationType: TVpNotificationType; const Value: Variant);
begin
FInLinkHandler := true;
try
case NotificationType of
neDateChange : Date := Value;
neDataStoreChange : Invalidate;
neInvalidate : Invalidate;
end;
finally
FInLinkHandler := false;
end;
end;
procedure TVpGanttView.Loaded;
begin
inherited;
FLoaded := true;
Populate;
end;
procedure TVpGanttView.Populate;
begin
if DataStore <> nil then
DataStore.Date := FDate;
end;
procedure TVpGanttView.Paint;
begin
RenderToCanvas(
Canvas, // Paint Canvas
Rect(0, 0, Width, Height), // Paint Rectangle
ra0, // Rotation angle: none
1, // Scale
FStartDate, // Date
-1, // Start At
-1, // End At
gr30Min, // Granularity
False // Display Only
);
end;
procedure TVpGanttView.RenderToCanvas(RenderCanvas: TCanvas; RenderIn: TRect;
Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime;
StartLine, StopLine: Integer; UseGran: TVpGranularity; DisplayOnly: Boolean);
var
painter: TVpGanttViewPainter;
begin
FPainting := true;
painter := TVpGanttViewPainter.Create(Self, RenderCanvas);
try
painter.RenderToCanvas(RenderIn, Angle, Scale, RenderDate, StartLine,
StopLine, UseGran, DisplayOnly);
finally
painter.Free;
FPainting := false;
end;
end;
procedure TVpGanttView.SetDate(AValue: TDateTime);
begin
if FDate <> AValue then begin
FDate := AValue;
(*
if (AValue < wvStartDate) or (Value >= wvStartDate + 7) then
wvStartDate := Trunc(GetStartOfWeek(Value, FWeekStartsOn));
if wvStartDate > Value then
wvStartDate := wvStartDate - 7;
*)
if FLoaded then
Populate;
Invalidate;
if (not FInLinkHandler) and (ControlLink <> nil) then
ControlLink.Notify(self, neDateChange, FDate);
end;
end;
end. end.