tvplanit: Fix ContactGrid no longer scrolling if last contact is in first column

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4733 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-12 21:50:41 +00:00
parent f1c32b907a
commit 532ba34ad4

View File

@ -214,13 +214,10 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure LinkHandler(Sender: TComponent; procedure LinkHandler(Sender: TComponent;
NotificationType: TVpNotificationType; NotificationType: TVpNotificationType; const Value: Variant); override;
const Value: Variant); override;
function GetControlType : TVpItemType; override; function GetControlType : TVpItemType; override;
procedure DeleteActiveContact(Verify: Boolean); procedure DeleteActiveContact(Verify: Boolean);
procedure PaintToCanvas (ACanvas : TCanvas; procedure PaintToCanvas (ACanvas: TCanvas; ARect: TRect; Angle: TVpRotationAngle);
ARect : TRect;
Angle : TVpRotationAngle);
procedure RenderToCanvas (RenderCanvas : TCanvas; procedure RenderToCanvas (RenderCanvas : TCanvas;
RenderIn : TRect; RenderIn : TRect;
Angle : TVpRotationAngle; Angle : TVpRotationAngle;
@ -470,10 +467,10 @@ end;
destructor TVpContactGrid.Destroy; destructor TVpContactGrid.Destroy;
begin begin
if (HandleAllocated) and if (HandleAllocated) and (Assigned (DataStore)) and
(Assigned (DataStore)) and (not (csDesigning in ComponentState))
(not (csDesigning in ComponentState)) then then
DataStore.DeregisterWatcher (Handle); DataStore.DeregisterWatcher(Handle);
cgClickTimer.Free; cgClickTimer.Free;
FContactHeadAttr.Free; FContactHeadAttr.Free;
@ -488,8 +485,8 @@ procedure TVpContactGrid.LinkHandler(Sender: TComponent;
NotificationType: TVpNotificationType; const Value: Variant); NotificationType: TVpNotificationType; const Value: Variant);
begin begin
case NotificationType of case NotificationType of
neDataStoreChange: Invalidate; neDataStoreChange : Invalidate;
neInvalidate: Invalidate; neInvalidate : Invalidate;
end; end;
end; end;
{=====} {=====}
@ -754,11 +751,14 @@ var
Col, RecsInCol: Integer; Col, RecsInCol: Integer;
HeadRect, AddrRect, CSZRect, Phone1Rect, Phone2Rect, Phone3Rect: TRect; HeadRect, AddrRect, CSZRect, Phone1Rect, Phone2Rect, Phone3Rect: TRect;
Phone4Rect, Phone5Rect, WholeRect, CompanyRect, EMailRect: TRect; Phone4Rect, Phone5Rect, WholeRect, CompanyRect, EMailRect: TRect;
TmpBmpRect : TRect; TmpBmpRect: TRect;
TextColWidth : Integer; TextColWidth: Integer;
TextXOffset : Integer; TextXOffset: Integer;
TextYOffset : Integer; TextYOffset: Integer;
oldCol1RecCount: Integer;
begin begin
oldCol1RecCount := cgCol1RecCount;
FVisibleContacts := 0; FVisibleContacts := 0;
cgCol1RecCount := 0; cgCol1RecCount := 0;
TextXOffset := 0; TextXOffset := 0;
@ -1456,58 +1456,59 @@ var
case Angle of case Angle of
ra0 : begin ra0 : begin
if (RenderIn.Top + Anchor.y + WholeRect.Bottom >= RenderIn.Bottom - TextMargin * 3) and if (RenderIn.Top + Anchor.y + WholeRect.Bottom >= RenderIn.Bottom - TextMargin * 3) and
(RecsInCol > 0) then begin (RecsInCol > 0)
Anchor := Point (Anchor.x + WholeRect.Right + then begin
FBarWidth + 1 + (TextMargin * 3), Anchor := Point(
2 + (TextMargin * 2)); Anchor.x + WholeRect.Right + FBarWidth + 1 + TextMargin * 3,
2 + TextMargin * 2
);
if Col = 1 then if Col = 1 then
cgCol1RecCount := RecsInCol; cgCol1RecCount := RecsInCol;
Inc(Col); Inc(Col);
RecsInCol := 0; RecsInCol := 0;
if DisplayOnly and if DisplayOnly and (Anchor.X + TextColWidth >= RenderIn.Right) then
(Anchor.X + TextColWidth >= RenderIn.Right) then
Exit; Exit;
end; end;
end; end;
ra90 : begin ra90 : begin
if (Anchor.x + RenderIn.Left + (WholeRect.Right - WholeRect.Left) > RenderIn.Right - TextMargin * 3) and if (Anchor.x + RenderIn.Left + WholeRect.Right - WholeRect.Left > RenderIn.Right - TextMargin * 3) and
(RecsInCol > 0) then begin (RecsInCol > 0)
Anchor.x := 2 + (TextMargin * 2); then begin
Anchor.x := 2 + TextMargin * 2;
Anchor.y := Anchor.y + WholeRect.Bottom + FBarWidth + 1 + TextMargin * 3; Anchor.y := Anchor.y + WholeRect.Bottom + FBarWidth + 1 + TextMargin * 3;
if Col = 1 then if Col = 1 then
cgCol1RecCount := RecsInCol; cgCol1RecCount := RecsInCol;
Inc(Col); Inc(Col);
RecsInCol := 0; RecsInCol := 0;
if DisplayOnly and if DisplayOnly and (Anchor.y + TextColWidth >= RenderIn.Bottom) then
(Anchor.y + TextColWidth >= RenderIn.Bottom) then
Exit; Exit;
end; end;
end; end;
ra180 : begin ra180 : begin
if (Anchor.y + RenderIn.Top - (WholeRect.Bottom - WholeRect.Top) <= RenderIn.Top + TextMargin * 3) and if (Anchor.y + RenderIn.Top - WholeRect.Bottom - WholeRect.Top <= RenderIn.Top + TextMargin * 3) and
(RecsInCol > 0) then begin (RecsInCol > 0) then
Anchor.x := Anchor.x - ((WholeRect.Right) + FBarWidth + 1 + TextMargin * 3); begin
Anchor.y := TmpBmp.Height - 2 - (TextMargin * 2); Anchor.x := Anchor.x - (WholeRect.Right + FBarWidth + 1 + TextMargin * 3);
Anchor.y := TmpBmp.Height - 2 - TextMargin * 2;
if Col = 1 then if Col = 1 then
cgCol1RecCount := RecsInCol; cgCol1RecCount := RecsInCol;
Inc(Col); Inc(Col);
RecsInCol := 0; RecsInCol := 0;
if DisplayOnly and if DisplayOnly and (Anchor.x + TextColWidth < RenderIn.Left) then
(Anchor.x + TextColWidth < RenderIn.Left) then
Exit; Exit;
end; end;
end; end;
ra270 : begin ra270 : begin
if (Anchor.x + RenderIn.Left + (WholeRect.Right - WholeRect.Left) >= RenderIn.Right - TextMargin * 3) and if (Anchor.x + RenderIn.Left + (WholeRect.Right - WholeRect.Left) >= RenderIn.Right - TextMargin * 3) and
(RecsInCol > 0) then begin (RecsInCol > 0) then
Anchor.x := 2 + (TextMargin * 2); begin
Anchor.x := 2 + TextMargin * 2;
Anchor.y := Anchor.y - (WholeRect.Bottom + FBarWidth + 1 + TextMargin * 3); Anchor.y := Anchor.y - (WholeRect.Bottom + FBarWidth + 1 + TextMargin * 3);
if Col = 1 then if Col = 1 then
cgCol1RecCount := RecsInCol; cgCol1RecCount := RecsInCol;
Inc(Col); Inc(Col);
RecsInCol := 0; RecsInCol := 0;
if DisplayOnly and if DisplayOnly and (Anchor.y + TextColWidth <= RenderIn.Top) then
(Anchor.y + TextColWidth <= RenderIn.Top) then
Exit; Exit;
end; end;
end; end;
@ -1691,6 +1692,9 @@ var
FLastPrintLine := -2 FLastPrintLine := -2
else else
FLastPrintLine := FContactsAfter; FLastPrintLine := FContactsAfter;
if (oldCol1RecCount > 0) and (cgCol1RecCount = 0) then
cgCol1RecCount := oldCol1RecCount;
end; end;
{--} {--}
@ -1733,7 +1737,6 @@ var
{--} {--}
begin begin
if DisplayOnly then begin if DisplayOnly then begin
RealColor := clWhite; RealColor := clWhite;
SizingBarColor := clBlack; SizingBarColor := clBlack;
@ -1777,8 +1780,7 @@ begin
SetMeasurements; SetMeasurements;
if DisplayOnly and (PrintNumColumns > 0) then if DisplayOnly and (PrintNumColumns > 0) then
RealColumnWidth := (RealWidth - ((2 + ExtraBarWidth) * RealColumnWidth := (RealWidth - ((2 + ExtraBarWidth) * (PrintNumColumns - 1))) div PrintNumColumns
(PrintNumColumns - 1))) div PrintNumColumns
else else
RealColumnWidth := ColumnWidth; RealColumnWidth := ColumnWidth;
@ -1812,30 +1814,29 @@ end;
{ Introduced to support the buttonbar component !!.02} { Introduced to support the buttonbar component !!.02}
function TVpContactGrid.SelectContactByName(const Name: String): Boolean; function TVpContactGrid.SelectContactByName(const Name: String): Boolean;
var var
Contact: TVpContact; Contact: TVpContact;
ItemIndex: Integer; ItemIndex: Integer;
begin begin
result := false; result := false;
if (DataStore <> nil) and (DataStore.Resource <> nil) then begin if (DataStore <> nil) and (DataStore.Resource <> nil) then
begin
Contact := DataStore.Resource.Contacts.FindContactByName(Name, True); Contact := DataStore.Resource.Contacts.FindContactByName(Name, True);
if ( Contact <> nil ) then begin if (Contact <> nil) then begin
FActiveContact := Contact; FActiveContact := Contact;
ItemIndex := ItemIndex := DataStore.Resource.Contacts.ContactsList.IndexOf(Contact);
DataStore.Resource.Contacts.ContactsList.IndexOf(Contact); if (ItemIndex > FContactsBefore + FVisibleContacts) or (ItemIndex <= FContactsBefore)
if (ItemIndex > FContactsBefore + FVisibleContacts) then begin
or (ItemIndex <= FContactsBefore) if ItemIndex = 0 then
then begin FContactsBefore := 0
if ItemIndex = 0 then else
FContactsBefore := 0 FContactsBefore := ItemIndex - 1;
else end;
FContactsBefore := ItemIndex - 1; result := true;
end; Invalidate;
result := true; end;
Invalidate; end;
end; end;
end;
end;
{=====} {=====}
procedure TVpContactGrid.SetColor(const Value: TColor); procedure TVpContactGrid.SetColor(const Value: TColor);
@ -2625,20 +2626,19 @@ begin
else if (Rows > 0) and (FContactsAfter > 0) then else if (Rows > 0) and (FContactsAfter > 0) then
FContactsBefore := FContactsBefore + cgCol1RecCount; FContactsBefore := FContactsBefore + cgCol1RecCount;
if FContactsBefore < 0 then FContactsBefore := 0;
if FContactsBefore >= DataStore.Resource.Contacts.Count then if FContactsBefore >= DataStore.Resource.Contacts.Count then
FContactsBefore := DataStore.Resource.Contacts.Count - cgCol1RecCount; FContactsBefore := DataStore.Resource.Contacts.Count - cgCol1RecCount;
if FContactsBefore < 0 then FContactsBefore := 0;
end; end;
{=====} {=====}
procedure TVpContactGrid.SetHScrollPos; procedure TVpContactGrid.SetHScrollPos;
var var
SI : TScrollInfo; SI: TScrollInfo;
begin begin
if (not HandleAllocated) if (not HandleAllocated) or (DataStore = nil) or (DataStore.Resource = nil)
or (DataStore = nil) or (csDesigning in ComponentState)
or (DataStore.Resource = nil)
or (csDesigning in ComponentState)
then Exit; then Exit;
with SI do begin with SI do begin