tvplanit: Improved positioning of VpContactGrid inplace editor.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6483 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-06-09 19:49:39 +00:00
parent 3683bf9450
commit ac2f2a1cfd
4 changed files with 73 additions and 40 deletions

View File

@ -426,6 +426,7 @@ object MainForm: TMainForm
Width = 794 Width = 794
ControlLink = VpControlLink1 ControlLink = VpControlLink1
Color = clWindow Color = clWindow
ParentFont = False
Align = alClient Align = alClient
TabStop = True TabStop = True
TabOrder = 1 TabOrder = 1

View File

@ -167,9 +167,9 @@ type
procedure SetDrawingStyle(const Value: TVpDrawingStyle); procedure SetDrawingStyle(const Value: TVpDrawingStyle);
procedure SetColor(Value: TColor); reintroduce; procedure SetColor(Value: TColor); reintroduce;
procedure SetHScrollPos; procedure SetHScrollPos;
procedure SetPrintNumColumns (const v : Integer); procedure SetPrintNumColumns(const v: Integer);
procedure SetSortBy (const v : TVpContactSort); procedure SetSortBy(const Value: TVpContactSort);
procedure SetDataStore (const Value : TVpCustomDataStore); override; procedure SetDataStore(const Value: TVpCustomDataStore); override;
{ internal methods } { internal methods }
procedure cgCalcRowHeight; procedure cgCalcRowHeight;
@ -353,7 +353,7 @@ begin
inherited Create(AOwner); inherited Create(AOwner);
field := ''; field := '';
TabStop := False; TabStop := False;
BorderStyle := bsNone; //BorderStyle := bsNone;
{$IFDEF VERSION4} {$IFDEF VERSION4}
// DoubleBuffered := False; // DoubleBuffered := False;
{$ENDIF} {$ENDIF}
@ -363,27 +363,17 @@ begin
end; end;
procedure TVpCGInPlaceEdit.Move(const Loc: TRect; Redraw: Boolean); procedure TVpCGInPlaceEdit.Move(const Loc: TRect; Redraw: Boolean);
var const
Margin: Integer; dy = 2;
begin begin
CreateHandle; CreateHandle;
Redraw := Redraw or not IsWindowVisible(Handle); Redraw := Redraw or not IsWindowVisible(Handle);
Invalidate; Invalidate;
with Loc do begin with Loc do begin
Margin := 0;
if (Field = 'Address') or (Field = 'Company') or (Field ='CSZ') then
Margin := TextMargin * 2;
{$IFDEF LCL} {$IFDEF LCL}
SetBounds( SetBounds(Left, Top-dy, Right-Left, Bottom - Top);
Left + Margin,
Top + TextMargin div 2,
Right - Left - TextMargin * 2,
Bottom - Top
);
{$ELSE} {$ELSE}
SetWindowPos(Handle, HWND_TOP, Left + Margin, SetWindowPos(Handle, HWND_TOP, Left, Top-dy, Right-Left, Bottom-Top, SWP_NOREDRAW);
Top + (TextMargin div 2), Right - Left - TextMargin * 2, Bottom - Top,
SWP_NOREDRAW);
{$ENDIF} {$ENDIF}
end; end;
if Redraw then Invalidate; if Redraw then Invalidate;
@ -889,7 +879,7 @@ procedure TVpContactGrid.SetContactIndex(Value: Integer);
begin begin
FContactIndex := Value; FContactIndex := Value;
if (DataStore <> nil) and (DataStore.Resource <> nil) then if (DataStore <> nil) and (DataStore.Resource <> nil) then
FActiveContact := DataStore.Resource.Contacts.GetContact(Value) FActiveContact := DataStore.Resource.Contacts.GetContact(FContactIndex)
else else
FContactIndex := -1; FContactIndex := -1;
end; end;
@ -1311,24 +1301,30 @@ 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, Canvas.DrawFocusRect(Rect(AddressRect.Left + TextMargin - 1,
AddressRect.Top, AddressRect.Right + 3, AddressRect.Bottom + 3)); 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, Canvas.DrawFocusRect(Rect(CompanyRect.Left + TextMargin - 1,
CompanyRect.Top, CompanyRect.Right + 3, CompanyRect.Bottom + 3)); 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, Canvas.DrawFocusRect(Rect(CSZRect.Left + TextMargin - 1,
CSZRect.Top, CSZRect.Right + 3, CSZRect.Bottom + 3)); 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;
@ -1336,48 +1332,56 @@ begin
if field = 'EMail' then begin if field = 'EMail' then begin
cgInPlaceEditor.Field := GetDisplayEMailField(FActiveContact); //'EMail1'; cgInPlaceEditor.Field := GetDisplayEMailField(FActiveContact); //'EMail1';
cgInPlaceEditor.Move(EMailRect, true); cgInPlaceEditor.Move(EMailRect, true);
Canvas.DrawFocusRect(Rect(EMailRect.Left - TextMargin, {
EMailRect.Top, EMailRect.Right + 3, EMailRect.Bottom + 3)); Canvas.DrawFocusRect(EMailRect);
cgInPlaceEditor.Text := FActiveContact.EMail1; // 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, Canvas.DrawFocusRect(Rect(Phone1Rect.Left - TextMargin,
Phone1Rect.Top, Phone1Rect.Right + 3, Phone1Rect.Bottom + 3)); 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, Canvas.DrawFocusRect(Rect(Phone2Rect.Left - TextMargin,
Phone2Rect.Top, Phone2Rect.Right + 3, Phone2Rect.Bottom + 3)); 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, Canvas.DrawFocusRect(Rect(Phone3Rect.Left - TextMargin,
Phone3Rect.Top, Phone3Rect.Right + 3, Phone3Rect.Bottom + 3)); 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 , Canvas.DrawFocusRect(Rect(Phone4Rect.Left - TextMargin ,
Phone4Rect.Top, Phone4Rect.Right + 3, Phone4Rect.Bottom + 3)); 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, Canvas.DrawFocusRect(Rect(Phone5Rect.Left - TextMargin,
Phone5Rect.Top, Phone5Rect.Right + 3, Phone5Rect.Bottom + 3)); Phone5Rect.Top, Phone5Rect.Right + 3, Phone5Rect.Bottom + 3));}
cgInPlaceEditor.Text := FActiveContact.Phone5; cgInPlaceEditor.Text := FActiveContact.Phone5;
end; end;
end; end;
@ -1614,11 +1618,17 @@ begin
if ContactIndex < Pred(DataStore.Resource.Contacts.Count) then if ContactIndex < Pred(DataStore.Resource.Contacts.Count) then
ContactIndex := ContactIndex + 1; ContactIndex := ContactIndex + 1;
VK_HOME : VK_HOME :
ContactIndex := 0;
{
if ContactIndex > 0 then if ContactIndex > 0 then
ContactIndex := ContactIndex - 1; ContactIndex := ContactIndex - 1;
}
VK_END : VK_END :
ContactIndex := Pred(Datastore.Resource.Contacts.Count);
{
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 <= Pred(DataStore.Resource.Contacts.Count) then
ContactIndex := ContactIndex + cgCol1RecCount ContactIndex := ContactIndex + cgCol1RecCount
@ -1639,16 +1649,14 @@ begin
Windows.SetFocus (GetNextDlgTabItem(GetParent(Handle), Handle, True)); Windows.SetFocus (GetNextDlgTabItem(GetParent(Handle), Handle, True));
{$ENDIF} {$ENDIF}
VK_F10 : VK_F10 :
if (ssShift in Shift) and not (Assigned (PopupMenu)) then begin if (ssShift in Shift) and not Assigned(PopupMenu) then begin
PopupPoint := GetClientOrigin; PopupPoint := GetClientOrigin;
FDefaultPopup.Popup (PopupPoint.x + 10, FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10);
PopupPoint.y + 10);
end; end;
VK_APPS : VK_APPS :
if not Assigned (PopupMenu) then begin if not Assigned(PopupMenu) then begin
PopupPoint := GetClientOrigin; PopupPoint := GetClientOrigin;
FDefaultPopup.Popup (PopupPoint.x + 10, FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10);
PopupPoint.y + 10);
end; end;
end; end;
Invalidate; Invalidate;
@ -1774,13 +1782,13 @@ begin
end; end;
{=====} {=====}
procedure TVpContactGrid.SetSortBy (const v : TVpContactSort); procedure TVpContactGrid.SetSortBy(const Value: TVpContactSort);
begin begin
if v <> FSortBy then begin if Value <> FSortBy then begin
FSortBy := v; FSortBy := Value;
if not Assigned (DataStore) then if not Assigned(DataStore) then
Exit; Exit;
if not Assigned (DataStore.Resource) then if not Assigned(DataStore.Resource) then
Exit; Exit;
DataStore.Resource.Contacts.ContactSort := FSortBy; DataStore.Resource.Contacts.ContactSort := FSortBy;
cgClickTimer.Enabled := False; cgClickTimer.Enabled := False;
@ -1812,7 +1820,7 @@ begin
if PointInRect(Pnt, cgContactArray[I].WholeRect) then begin if PointInRect(Pnt, cgContactArray[I].WholeRect) then begin
{ Set ActiveContact to the selected one } { Set ActiveContact to the selected one }
FContactIndex := I; FContactIndex := I;
FActiveContact := TVpCOntact(cgContactArray[I].Contact); FActiveContact := TVpContact(cgContactArray[I].Contact);
Break; Break;
end; end;
end; end;

View File

@ -531,7 +531,7 @@ begin
{ add a little spacing between records } { add a little spacing between records }
case Angle of case Angle of
ra0 : WholeRect.Bottom := WholeRect.Bottom + TextMargin; // * 2; ra0 : WholeRect.Bottom := WholeRect.Bottom + TextMargin * 2;
ra90 : WholeRect.Left := WholeRect.Left - TextMargin * 2; ra90 : WholeRect.Left := WholeRect.Left - TextMargin * 2;
ra180 : WholeRect.Top := WholeRect.Top - TextMargin * 2; ra180 : WholeRect.Top := WholeRect.Top - TextMargin * 2;
ra270 : WholeRect.Right := WholeRect.Right + TextMargin * 2; ra270 : WholeRect.Right := WholeRect.Right + TextMargin * 2;
@ -539,6 +539,19 @@ begin
{ Update Array Rects } { Update Array Rects }
with TVpContactGridOpener(FContactGrid) do begin with TVpContactGridOpener(FContactGrid) do begin
cgContactArray[I].WholeRect := MoveRect(WholeRect, Anchor);
cgContactArray[I].HeaderRect := MoveRect(HeadRect, Anchor);
cgContactArray[I].AddressRect := MoveRect(AddrRect, Anchor);
cgContactArray[I].CSZRect := MoveRect(CSZRect, Anchor);
cgContactArray[I].CompanyRect := MoveRect(CompanyRect, Anchor);
cgContactArray[I].EMailRect := MoveRect(EMailRect, Anchor);
cgContactArray[I].Phone1Rect := MoveRect(Phone1Rect, Anchor);
cgContactArray[I].Phone2Rect := MoveRect(Phone2Rect, Anchor);
cgContactArray[I].Phone3Rect := MoveRect(Phone3Rect, Anchor);
cgContactArray[I].Phone4Rect := MoveRect(Phone4Rect, Anchor);
cgContactArray[I].Phone5Rect := MoveRect(Phone5Rect, Anchor);
(*
cgContactArray[I].WholeRect.TopLeft := Point( cgContactArray[I].WholeRect.TopLeft := Point(
Anchor.X, Anchor.Y + WholeRect.Top); Anchor.X, Anchor.Y + WholeRect.Top);
cgContactArray[I].WholeRect.BottomRight := Point( cgContactArray[I].WholeRect.BottomRight := Point(
@ -593,6 +606,7 @@ begin
Anchor.X + Phone5Rect.Left, Anchor.Y + Phone5Rect.Top); Anchor.X + Phone5Rect.Left, Anchor.Y + Phone5Rect.Top);
cgContactArray[I].Phone5Rect.BottomRight := Point( cgContactArray[I].Phone5Rect.BottomRight := Point(
Anchor.X + TmpBmp.Width, Anchor.Y + Phone5Rect.Bottom); 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 }

View File

@ -103,6 +103,9 @@ function RightOf(AControl: TControl): Integer;
function BottomOf(AControl: TControl): Integer; function BottomOf(AControl: TControl): Integer;
{- returns the bottom edge of a control } {- returns the bottom edge of a control }
function MoveRect(const ARect: TRect; const ADelta: TPoint): TRect;
{ - moves ARect by dx in ADelta.x and dy in ADelta.y direction }
function GetDisplayString(Canvas : TCanvas; const S : string; function GetDisplayString(Canvas : TCanvas; const S : string;
MinChars, MaxWidth : Integer) : string; MinChars, MaxWidth : Integer) : string;
{ given a string, a minimum number of chars to display, and a max width, { given a string, a minimum number of chars to display, and a max width,
@ -858,6 +861,13 @@ begin
Result := AControl.Top + AControl.Height; Result := AControl.Top + AControl.Height;
end; end;
{ Moves a rectangle ARect by ADelta.x in x, and by ADelta.y in y direction }
function MoveRect(const ARect: TRect; const ADelta: TPoint): TRect;
begin
Result := ARect;
OffsetRect(Result, ADelta.x, ADelta.y);
end;
{ Replaces embedded C-style line endings (\n) by FPC line endings (#13#10, #13, { Replaces embedded C-style line endings (\n) by FPC line endings (#13#10, #13,
#10, depending on system) } #10, depending on system) }
function DecodeLineEndings(const AText: String): String; function DecodeLineEndings(const AText: String): String;