tvplanit: Better sorting of contacts. Clean-up.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6484 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-06-09 22:57:50 +00:00
parent ac2f2a1cfd
commit 66df4b25d4
3 changed files with 42 additions and 109 deletions

View File

@ -183,9 +183,9 @@ type
procedure CreateParams(var Params: TCreateParams); override; procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override; procedure CreateWnd; override;
function GetContactIndexByCoord(Pnt: TPoint): Integer; function GetContactIndexByCoord(Pnt: TPoint): Integer;
function GetDisplayEMail(AContact: TVpContact): String;
function GetDisplayEMailField(AContact: TVpContact): String; function GetDisplayEMailField(AContact: TVpContact): String;
procedure SetDisplayEMail(AContact: TVpContact; AEMail: String); function GetDisplayEMailValue(AContact: TVpContact): String;
procedure SetDisplayEMailValue(AContact: TVpContact; AEMail: String);
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure MouseEnter; override; procedure MouseEnter; override;
procedure MouseLeave; override; procedure MouseLeave; override;
@ -1301,87 +1301,55 @@ begin
if field = 'Address' then begin if field = 'Address' then begin
cgInPlaceEditor.Field := 'Address1'; cgInPlaceEditor.Field := 'Address1';
cgInPlaceEditor.Move(AddressRect, true); cgInPlaceEditor.Move(AddressRect, true);
{
Canvas.DrawFocusRect(Rect(AddressRect.Left + TextMargin - 1,
AddressRect.Top, AddressRect.Right + 3, AddressRect.Bottom + 3));
}
cgInPlaceEditor.Text := FActiveContact.Address1; cgInPlaceEditor.Text := FActiveContact.Address1;
end; end;
{ edit company } { edit company }
if field = 'Company' then begin if field = 'Company' then begin
cgInPlaceEditor.Field := field; cgInPlaceEditor.Field := field;
cgInPlaceEditor.Move(CompanyRect, true); cgInPlaceEditor.Move(CompanyRect, true);
{
Canvas.DrawFocusRect(Rect(CompanyRect.Left + TextMargin - 1,
CompanyRect.Top, CompanyRect.Right + 3, CompanyRect.Bottom + 3));
}
cgInPlaceEditor.Text := FActiveContact.Company; cgInPlaceEditor.Text := FActiveContact.Company;
end; end;
{ edit CSZ } { edit CSZ }
if field = 'CSZ' then begin if field = 'CSZ' then begin
cgInPlaceEditor.Field := field; cgInPlaceEditor.Field := field;
cgInPlaceEditor.Move(CSZRect, true); cgInPlaceEditor.Move(CSZRect, true);
{
Canvas.DrawFocusRect(Rect(CSZRect.Left + TextMargin - 1,
CSZRect.Top, CSZRect.Right + 3, CSZRect.Bottom + 3));
}
cgInPlaceEditor.Text := FActiveContact.City1 + ', ' + FActiveContact.State1 cgInPlaceEditor.Text := FActiveContact.City1 + ', ' + FActiveContact.State1
+ ' ' + FActiveContact.Zip1; + ' ' + FActiveContact.Zip1;
end; end;
{ edit email } { edit email }
if field = 'EMail' then begin if field = 'EMail' then begin
cgInPlaceEditor.Field := GetDisplayEMailField(FActiveContact); //'EMail1'; cgInPlaceEditor.Field := GetDisplayEMailField(FActiveContact);
cgInPlaceEditor.Move(EMailRect, true); cgInPlaceEditor.Move(EMailRect, true);
{ cgInPlaceEditor.Text := GetDisplayEMailValue(FActiveContact);
Canvas.DrawFocusRect(EMailRect);
// Canvas.DrawFocusRect(Rect(EMailRect.Left - TextMargin,
// EMailRect.Top, EMailRect.Right + 3, EMailRect.Bottom + 3));
}
cgInPlaceEditor.Text := GetDisplayEMail(FActiveContact); //FActiveContact.EMail1;
end; end;
{ edit Phone1 } { edit Phone1 }
if field = 'Phone1' then begin if field = 'Phone1' then begin
cgInPlaceEditor.Field := field; cgInPlaceEditor.Field := field;
cgInPlaceEditor.Move(Phone1Rect, true); cgInPlaceEditor.Move(Phone1Rect, true);
{
Canvas.DrawFocusRect(Rect(Phone1Rect.Left - TextMargin,
Phone1Rect.Top, Phone1Rect.Right + 3, Phone1Rect.Bottom + 3));}
cgInPlaceEditor.Text := FActiveContact.Phone1; cgInPlaceEditor.Text := FActiveContact.Phone1;
end; end;
{ edit Phone2 } { edit Phone2 }
if field = 'Phone2' then begin if field = 'Phone2' then begin
cgInPlaceEditor.Field := field; cgInPlaceEditor.Field := field;
cgInPlaceEditor.Move(Phone2Rect, true); cgInPlaceEditor.Move(Phone2Rect, true);
{
Canvas.DrawFocusRect(Rect(Phone2Rect.Left - TextMargin,
Phone2Rect.Top, Phone2Rect.Right + 3, Phone2Rect.Bottom + 3));}
cgInPlaceEditor.Text := FActiveContact.Phone2; cgInPlaceEditor.Text := FActiveContact.Phone2;
end; end;
{ edit Phone3 } { edit Phone3 }
if field = 'Phone3' then begin if field = 'Phone3' then begin
cgInPlaceEditor.Field := field; cgInPlaceEditor.Field := field;
cgInPlaceEditor.Move(Phone3Rect, true); cgInPlaceEditor.Move(Phone3Rect, true);
{
Canvas.DrawFocusRect(Rect(Phone3Rect.Left - TextMargin,
Phone3Rect.Top, Phone3Rect.Right + 3, Phone3Rect.Bottom + 3)); }
cgInPlaceEditor.Text := FActiveContact.Phone3; cgInPlaceEditor.Text := FActiveContact.Phone3;
end; end;
{ edit Phone4 } { edit Phone4 }
if field = 'Phone4' then begin if field = 'Phone4' then begin
cgInPlaceEditor.Field := field; cgInPlaceEditor.Field := field;
cgInPlaceEditor.Move(Phone4Rect, true); cgInPlaceEditor.Move(Phone4Rect, true);
{
Canvas.DrawFocusRect(Rect(Phone4Rect.Left - TextMargin ,
Phone4Rect.Top, Phone4Rect.Right + 3, Phone4Rect.Bottom + 3));}
cgInPlaceEditor.Text := FActiveContact.Phone4; cgInPlaceEditor.Text := FActiveContact.Phone4;
end; end;
{ edit Phone5 } { edit Phone5 }
if field = 'Phone5' then begin if field = 'Phone5' then begin
cgInPlaceEditor.Field := field; cgInPlaceEditor.Field := field;
cgInPlaceEditor.Move(Phone5Rect, true); cgInPlaceEditor.Move(Phone5Rect, true);
{
Canvas.DrawFocusRect(Rect(Phone5Rect.Left - TextMargin,
Phone5Rect.Top, Phone5Rect.Right + 3, Phone5Rect.Bottom + 3));}
cgInPlaceEditor.Text := FActiveContact.Phone5; cgInPlaceEditor.Text := FActiveContact.Phone5;
end; end;
end; end;
@ -1416,17 +1384,17 @@ begin
{EMail} {EMail}
else if cgInPlaceEditor.field = 'EMail' then begin else if cgInPlaceEditor.field = 'EMail' then begin
if cgInPlaceEditor.Text <> FActiveContact.EMail1 then begin if cgInPlaceEditor.Text <> FActiveContact.EMail1 then begin
SetDisplayEMail(FACtiveContact, cgInplaceEditor.Text); SetDisplayEMailValue(FActiveContact, cgInplaceEditor.Text);
// FActiveContact.EMail1 := cgInPlaceEditor.Text;
FActiveContact.Changed := true; FActiveContact.Changed := true;
end; end;
end end
{City, State, Zip} {City, State, Zip}
else if cgInPlaceEditor.field = 'CSZ' then begin else if cgInPlaceEditor.field = 'CSZ' then begin
ParseCSZ(cgInPlaceEditor.Text, City, State, Zip); ParseCSZ(cgInPlaceEditor.Text, City, State, Zip);
if (City <> FActiveContact.City1) if (City <> FActiveContact.City1) or
or (State <> FActiveContact.State1) (State <> FActiveContact.State1) or
or (Zip <> FActiveContact.Zip1) then begin (Zip <> FActiveContact.Zip1) then
begin
FActiveContact.City1 := City; FActiveContact.City1 := City;
FActiveContact.State1 := State; FActiveContact.State1 := State;
FActiveContact.Zip1 := Zip; FActiveContact.Zip1 := Zip;
@ -1608,14 +1576,13 @@ end;
procedure TVpContactGrid.KeyDown(var Key: Word; Shift: TShiftState); procedure TVpContactGrid.KeyDown(var Key: Word; Shift: TShiftState);
var var
PopupPoint: TPoint; PopupPoint: TPoint;
begin begin
case Key of case Key of
VK_UP : VK_UP :
if ContactIndex > 0 then if ContactIndex > 0 then
ContactIndex := ContactIndex - 1; ContactIndex := ContactIndex - 1;
VK_DOWN : VK_DOWN :
if ContactIndex < Pred(DataStore.Resource.Contacts.Count) then if ContactIndex < DataStore.Resource.Contacts.Count - 1 then
ContactIndex := ContactIndex + 1; ContactIndex := ContactIndex + 1;
VK_HOME : VK_HOME :
ContactIndex := 0; ContactIndex := 0;
@ -1624,16 +1591,16 @@ begin
ContactIndex := ContactIndex - 1; ContactIndex := ContactIndex - 1;
} }
VK_END : VK_END :
ContactIndex := Pred(Datastore.Resource.Contacts.Count); ContactIndex := Datastore.Resource.Contacts.Count - 1;
{ {
if ContactIndex < Pred(DataStore.Resource.Contacts.Count) then if ContactIndex < Pred(DataStore.Resource.Contacts.Count) then
ContactIndex := ContactIndex + 1; ContactIndex := ContactIndex + 1;
} }
VK_RIGHT : VK_RIGHT :
if ContactIndex + cgCol1RecCount <= Pred(DataStore.Resource.Contacts.Count) then if ContactIndex + cgCol1RecCount <= DataStore.Resource.Contacts.Count - 1 then
ContactIndex := ContactIndex + cgCol1RecCount ContactIndex := ContactIndex + cgCol1RecCount
else else
ContactIndex := Pred(DataStore.Resource.Contacts.Count); ContactIndex := DataStore.Resource.Contacts.Count - 1;
VK_LEFT : VK_LEFT :
if ContactIndex - cgCol1RecCount <= 0 then if ContactIndex - cgCol1RecCount <= 0 then
ContactIndex := 0 ContactIndex := 0
@ -1658,8 +1625,13 @@ begin
PopupPoint := GetClientOrigin; PopupPoint := GetClientOrigin;
FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10); FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10);
end; end;
else
inherited;
end; end;
Key := 0;
Invalidate; Invalidate;
inherited;
end; end;
{=====} {=====}
@ -1831,7 +1803,7 @@ begin
Invalidate; Invalidate;
end; end;
function TVpContactGrid.GetDisplayEMail(AContact: TVpContact): String; function TVpContactGrid.GetDisplayEMailValue(AContact: TVpContact): String;
begin begin
if AContact = nil then if AContact = nil then
Result := '' Result := ''
@ -1854,7 +1826,7 @@ begin
Result := 'EMail1'; Result := 'EMail1';
end; end;
procedure TVpContactGrid.SetDisplayEMail(AContact: TVpContact; AEMail: String); procedure TVpContactGrid.SetDisplayEMailValue(AContact: TVpContact; AEMail: String);
begin begin
if (AContact.EMail1 <> '') then if (AContact.EMail1 <> '') then
AContact.EMail1 := AEMail AContact.EMail1 := AEMail

View File

@ -287,7 +287,7 @@ begin
TmpBmp.Canvas.FillRect(Rect(0, 0, TmpBmp.Width, TmpBmp.Height)); TmpBmp.Canvas.FillRect(Rect(0, 0, TmpBmp.Width, TmpBmp.Height));
{ sort the records } { sort the records }
FContactGrid.DataStore.Resource.Contacts.Sort; FContactGrid.DataStore.Resource.Contacts.Sort; // wp: why sort here?
{ Set the anchor starting point } { Set the anchor starting point }
case Angle of case Angle of
@ -463,7 +463,7 @@ begin
DrawContactLine(TmpBmp, TmpCon.Phone5, Str, WholeRect, Phone5Rect); DrawContactLine(TmpBmp, TmpCon.Phone5, Str, WholeRect, Phone5Rect);
{ do EMail } { do EMail }
Str := TVpContactGridOpener(FContactGrid).GetDisplayEMail(TmpCon); Str := TVpContactGridOpener(FContactGrid).GetDisplayEMailValue(TmpCon);
DrawContactLine(TmpBmp, Str, RSEmail + ': ', WholeRect, EMailRect); DrawContactLine(TmpBmp, Str, RSEmail + ': ', WholeRect, EMailRect);
{ if this record's too big to fit in the remaining area of this } { if this record's too big to fit in the remaining area of this }
@ -550,67 +550,9 @@ begin
cgContactArray[I].Phone3Rect := MoveRect(Phone3Rect, Anchor); cgContactArray[I].Phone3Rect := MoveRect(Phone3Rect, Anchor);
cgContactArray[I].Phone4Rect := MoveRect(Phone4Rect, Anchor); cgContactArray[I].Phone4Rect := MoveRect(Phone4Rect, Anchor);
cgContactArray[I].Phone5Rect := MoveRect(Phone5Rect, Anchor); cgContactArray[I].Phone5Rect := MoveRect(Phone5Rect, Anchor);
(*
cgContactArray[I].WholeRect.TopLeft := Point(
Anchor.X, Anchor.Y + WholeRect.Top);
cgContactArray[I].WholeRect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + WholeRect.Bottom);
cgContactArray[I].HeaderRect.TopLeft := Point(
Anchor.X, Anchor.Y + HeadRect.Top);
cgContactArray[I].HeaderRect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + HeadRect.Bottom);
cgContactArray[I].AddressRect.TopLeft := Point(
Anchor.X, Anchor.Y + AddrRect.Top);
cgContactArray[I].AddressRect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + AddrRect.Bottom);
cgContactArray[I].CSZRect.TopLeft := Point(
Anchor.X, Anchor.Y + CSZRect.Top);
cgContactArray[I].CSZRect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + CSZRect.Bottom);
cgContactArray[I].CompanyRect.TopLeft := Point(
Anchor.X, Anchor.Y + CompanyRect.Top);
cgContactArray[I].CompanyRect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + CompanyRect.Bottom);
cgContactArray[I].EMailRect.TopLeft := Point(
Anchor.X + EMailRect.Left, Anchor.Y + EMailRect.Top);
cgContactArray[I].EMailRect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + EMailRect.Bottom);
cgContactArray[I].Phone1Rect.TopLeft := Point(
Anchor.X + Phone1Rect.Left, Anchor.Y + Phone1Rect.Top);
cgContactArray[I].Phone1Rect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + Phone1Rect.Bottom);
cgContactArray[I].Phone2Rect.TopLeft := Point(
Anchor.X + Phone2Rect.Left, Anchor.Y + Phone2Rect.Top);
cgContactArray[I].Phone2Rect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + Phone2Rect.Bottom);
cgContactArray[I].Phone3Rect.TopLeft := Point(
Anchor.X + Phone3Rect.Left, Anchor.Y + Phone3Rect.Top);
cgContactArray[I].Phone3Rect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + Phone3Rect.Bottom);
cgContactArray[I].Phone4Rect.TopLeft := Point(
Anchor.X + Phone4Rect.Left, Anchor.Y + Phone4Rect.Top);
cgContactArray[I].Phone4Rect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + Phone4Rect.Bottom);
cgContactArray[I].Phone5Rect.TopLeft := Point(
Anchor.X + Phone5Rect.Left, Anchor.Y + Phone5Rect.Top);
cgContactArray[I].Phone5Rect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + Phone5Rect.Bottom);
*)
end; end;
{ move the drawn record from the bitmap to the component canvas } { move the drawn record from the bitmap to the component canvas }
case Angle of case Angle of
ra0 : ra0 :
RenderCanvas.CopyRect (Rect (Anchor.X + WholeRect.Left + RenderIn.Left, RenderCanvas.CopyRect (Rect (Anchor.X + WholeRect.Left + RenderIn.Left,

View File

@ -742,6 +742,21 @@ begin
Result := CompareValue(TVpTask(Item1).DueDate, TVpTask(Item2).DueDate); Result := CompareValue(TVpTask(Item1).DueDate, TVpTask(Item2).DueDate);
end; end;
function CompareContacts_Minors(Item1, Item2: Pointer): Integer;
begin
Result := CompareText(TVpContact(Item1).Email1, TVpContact(Item2).EMail1);
if Result = 0 then
Result := CompareText(TVpContact(Item1).Phone1, TVpContact(Item2).Phone1);
if Result = 0 then
Result := CompareText(TVpContact(Item1).Phone2, TVpContact(Item2).Phone2);
if Result = 0 then
Result := CompareText(TVpContact(Item1).Phone3, TVpContact(Item2).Phone3);
if Result = 0 then
Result := CompareText(TVpContact(Item1).Phone4, TVpContact(Item2).Phone4);
if Result = 0 then
Result := CompareText(TVpContact(Item1).Phone5, TVpContact(Item2).Phone5);
end;
{ Compare function for sorting contacts: Compare the first names of the contacts, { Compare function for sorting contacts: Compare the first names of the contacts,
if equal compare the last names. } if equal compare the last names. }
function CompareContacts_FirstLast(Item1, Item2: Pointer): Integer; function CompareContacts_FirstLast(Item1, Item2: Pointer): Integer;
@ -751,6 +766,8 @@ begin
Result := CompareText(TVpContact(Item1).LastName, TVpContact(Item2).LastName); Result := CompareText(TVpContact(Item1).LastName, TVpContact(Item2).LastName);
if Result = 0 then if Result = 0 then
Result := CompareText(TVpContact(Item1).Company, TVpContact(Item2).Company); Result := CompareText(TVpContact(Item1).Company, TVpContact(Item2).Company);
if Result = 0 then
Result := CompareContacts_Minors(Item1, Item2);
end; end;
{ Compare function for sorting contacts: Compare the last names of the contacts, { Compare function for sorting contacts: Compare the last names of the contacts,
@ -762,6 +779,8 @@ begin
Result := CompareText(TVpContact(Item1).FirstName, TVpContact(Item2).FirstName); Result := CompareText(TVpContact(Item1).FirstName, TVpContact(Item2).FirstName);
if Result = 0 then if Result = 0 then
Result := CompareText(TVpContact(Item1).Company, TVpContact(Item2).Company); Result := CompareText(TVpContact(Item1).Company, TVpContact(Item2).Company);
if Result = 0 then
Result := CompareContacts_Minors(Item1, Item2);
end; end;