tvplanit: Fix VpContactButtons behavior when search contact does not exist.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6744 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-12-04 11:34:23 +00:00
parent fc5c783aef
commit f474ac55d6
2 changed files with 38 additions and 34 deletions

View File

@ -69,6 +69,8 @@ type
SearchString: String) of object;
TVpContactButtonBar = class(TVPCustomControl)
private
FOnContactNotFound: TNotifyEvent;
protected {private}
FBarOrientation: TVpButtonBarOrientation;
FBorderWidth: Integer;
@ -138,8 +140,10 @@ type
read FShowNumberButton write SetShowNumberButton default True;
property OnButtonClick: TVpButtonBarClickEvent
read FOnButtonClick write FOnButtonClick;
property OnContactNotFound: TNotifyEvent
read FOnContactNotFound write FOnContactNotFound;
property RadioStyle: Boolean
read FRadioStyle write FRadioStyle;
read FRadioStyle write FRadioStyle default true;
property Align;
property Anchors;
@ -210,6 +214,7 @@ begin
FButtonWidth := 34;
FCaptionStyle := csLowercase;
FDrawingStyle := ds3d;
FRadioStyle := true;
FShowNumberButton := True;
end;
{=====}
@ -379,7 +384,9 @@ begin
FContactGrid.SetFocus;
for I := 1 to Length(bbSearchString) do
if FContactGrid.SelectContactByName(bbSearchString[I]) then
Break;
Exit;
if Assigned(FOnContactNotFound) then
FOnContactNotFound(self);
end;
end;
{=====}
@ -397,14 +404,17 @@ var
I: Integer;
P: TPoint;
R: TRect;
found: Boolean;
begin
inherited MouseDown(Button, Shift, X, Y);
if Button = mbLeft then begin
found := false;
P := Point(X, Y);
for I := 0 to pred(FButtonCount) do begin
R := FButtonsArray[I].Rect;
if PointInRect(P, R) then begin
found := True;
{ if RadioStyle then un-press the last clicked button. }
if RadioStyle then
DrawButton(FButtonPressed, False);
@ -415,10 +425,12 @@ begin
end;
end;
if Assigned(FOnButtonClick) then
FOnButtonClick(Self, FButtonPressed, bbSearchString)
else
SelectContact;
if found then begin
if Assigned(FOnButtonClick) then
FOnButtonClick(Self, FButtonPressed, bbSearchString)
else
SelectContact;
end;
end;
end;
{=====}

View File

@ -473,7 +473,7 @@ type
function Count: Integer;
procedure DeleteContact(Contact: TVpContact);
function First: TVpContact;
function FindContactByName(const Name: string;
function FindContactByName(const AName: string;
CaseInsensitive: Boolean = True): TVpContact;
function FindContactIndexByName(const Name: string;
CaseInsensitive: Boolean = True): Integer;
@ -2567,44 +2567,36 @@ begin
end;
end;
{ new function introduced to support the new buttonbar component }
function TVpContacts.FindContactByName(const Name: string;
CaseInsensitive: Boolean): TVpContact;
{ new function introduced to support the new buttonbar component. }
function TVpContacts.FindContactByName(const AName: string;
CaseInsensitive: Boolean): TVpContact;
var
I: Integer;
SearchStr: String;
SearchLength: Integer;
SearchLength: Integer;
SearchName: String;
begin
Result := nil;
// To enhance performance, uppercase the input name and get its length only once
if CaseInsensitive then
SearchStr := uppercase(Name)
SearchStr := UpperCase(AName)
else
SearchStr := Name;
SearchStr := AName;
SearchLength := Length(SearchStr);
// Iterate the contacts looking for a match
for I := 0 to FContactsList.Count - 1 do begin
if CaseInsensitive then begin
// not case sensitive
if Copy(uppercase(TVpContact(FContactsList[I]).LastName), 1, SearchLength) = SearchStr
then begin
// We found a match, so return it and bail out
Result := TVpContact(FContactsList[I]);
Exit;
end;
end else begin
// case sensitive
if Copy(TVpContact(FContactsList[I]).LastName, 1, SearchLength) = SearchStr
then begin
// We found a match, so return it and bail out
Result := TVpContact(FContactsList[I]);
Exit;
end;
end;
end;
end;
for I := 0 to FContactsList.Count - 1 do begin
SearchName := Copy(TVpContact(FContactsList[I]).LastName, 1, SearchLength);
if CaseInsensitive then
SearchName := Uppercase(SearchName);
// We found a match, so return it and bail out
if SearchName = SearchStr then begin
Result := TVpContact(FContactsList[I]);
exit;
end;
end;
end;
{ new function introduced to support the new buttonbar component }
function TVpContacts.FindContactIndexByName(const Name: string;