You've already forked lazarus-ccr
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:
@ -69,6 +69,8 @@ type
|
|||||||
SearchString: String) of object;
|
SearchString: String) of object;
|
||||||
|
|
||||||
TVpContactButtonBar = class(TVPCustomControl)
|
TVpContactButtonBar = class(TVPCustomControl)
|
||||||
|
private
|
||||||
|
FOnContactNotFound: TNotifyEvent;
|
||||||
protected {private}
|
protected {private}
|
||||||
FBarOrientation: TVpButtonBarOrientation;
|
FBarOrientation: TVpButtonBarOrientation;
|
||||||
FBorderWidth: Integer;
|
FBorderWidth: Integer;
|
||||||
@ -138,8 +140,10 @@ type
|
|||||||
read FShowNumberButton write SetShowNumberButton default True;
|
read FShowNumberButton write SetShowNumberButton default True;
|
||||||
property OnButtonClick: TVpButtonBarClickEvent
|
property OnButtonClick: TVpButtonBarClickEvent
|
||||||
read FOnButtonClick write FOnButtonClick;
|
read FOnButtonClick write FOnButtonClick;
|
||||||
|
property OnContactNotFound: TNotifyEvent
|
||||||
|
read FOnContactNotFound write FOnContactNotFound;
|
||||||
property RadioStyle: Boolean
|
property RadioStyle: Boolean
|
||||||
read FRadioStyle write FRadioStyle;
|
read FRadioStyle write FRadioStyle default true;
|
||||||
|
|
||||||
property Align;
|
property Align;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
@ -210,6 +214,7 @@ begin
|
|||||||
FButtonWidth := 34;
|
FButtonWidth := 34;
|
||||||
FCaptionStyle := csLowercase;
|
FCaptionStyle := csLowercase;
|
||||||
FDrawingStyle := ds3d;
|
FDrawingStyle := ds3d;
|
||||||
|
FRadioStyle := true;
|
||||||
FShowNumberButton := True;
|
FShowNumberButton := True;
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
@ -379,7 +384,9 @@ begin
|
|||||||
FContactGrid.SetFocus;
|
FContactGrid.SetFocus;
|
||||||
for I := 1 to Length(bbSearchString) do
|
for I := 1 to Length(bbSearchString) do
|
||||||
if FContactGrid.SelectContactByName(bbSearchString[I]) then
|
if FContactGrid.SelectContactByName(bbSearchString[I]) then
|
||||||
Break;
|
Exit;
|
||||||
|
if Assigned(FOnContactNotFound) then
|
||||||
|
FOnContactNotFound(self);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
@ -397,14 +404,17 @@ var
|
|||||||
I: Integer;
|
I: Integer;
|
||||||
P: TPoint;
|
P: TPoint;
|
||||||
R: TRect;
|
R: TRect;
|
||||||
|
found: Boolean;
|
||||||
begin
|
begin
|
||||||
inherited MouseDown(Button, Shift, X, Y);
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
|
|
||||||
if Button = mbLeft then begin
|
if Button = mbLeft then begin
|
||||||
|
found := false;
|
||||||
P := Point(X, Y);
|
P := Point(X, Y);
|
||||||
for I := 0 to pred(FButtonCount) do begin
|
for I := 0 to pred(FButtonCount) do begin
|
||||||
R := FButtonsArray[I].Rect;
|
R := FButtonsArray[I].Rect;
|
||||||
if PointInRect(P, R) then begin
|
if PointInRect(P, R) then begin
|
||||||
|
found := True;
|
||||||
{ if RadioStyle then un-press the last clicked button. }
|
{ if RadioStyle then un-press the last clicked button. }
|
||||||
if RadioStyle then
|
if RadioStyle then
|
||||||
DrawButton(FButtonPressed, False);
|
DrawButton(FButtonPressed, False);
|
||||||
@ -415,11 +425,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if found then begin
|
||||||
if Assigned(FOnButtonClick) then
|
if Assigned(FOnButtonClick) then
|
||||||
FOnButtonClick(Self, FButtonPressed, bbSearchString)
|
FOnButtonClick(Self, FButtonPressed, bbSearchString)
|
||||||
else
|
else
|
||||||
SelectContact;
|
SelectContact;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ type
|
|||||||
function Count: Integer;
|
function Count: Integer;
|
||||||
procedure DeleteContact(Contact: TVpContact);
|
procedure DeleteContact(Contact: TVpContact);
|
||||||
function First: TVpContact;
|
function First: TVpContact;
|
||||||
function FindContactByName(const Name: string;
|
function FindContactByName(const AName: string;
|
||||||
CaseInsensitive: Boolean = True): TVpContact;
|
CaseInsensitive: Boolean = True): TVpContact;
|
||||||
function FindContactIndexByName(const Name: string;
|
function FindContactIndexByName(const Name: string;
|
||||||
CaseInsensitive: Boolean = True): Integer;
|
CaseInsensitive: Boolean = True): Integer;
|
||||||
@ -2567,41 +2567,33 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ new function introduced to support the new buttonbar component }
|
{ new function introduced to support the new buttonbar component. }
|
||||||
function TVpContacts.FindContactByName(const Name: string;
|
function TVpContacts.FindContactByName(const AName: string;
|
||||||
CaseInsensitive: Boolean): TVpContact;
|
CaseInsensitive: Boolean): TVpContact;
|
||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
SearchStr: String;
|
SearchStr: String;
|
||||||
SearchLength: Integer;
|
SearchLength: Integer;
|
||||||
|
SearchName: String;
|
||||||
begin
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
|
|
||||||
// To enhance performance, uppercase the input name and get its length only once
|
// To enhance performance, uppercase the input name and get its length only once
|
||||||
if CaseInsensitive then
|
if CaseInsensitive then
|
||||||
SearchStr := uppercase(Name)
|
SearchStr := UpperCase(AName)
|
||||||
else
|
else
|
||||||
SearchStr := Name;
|
SearchStr := AName;
|
||||||
SearchLength := Length(SearchStr);
|
SearchLength := Length(SearchStr);
|
||||||
|
|
||||||
// Iterate the contacts looking for a match
|
// Iterate the contacts looking for a match
|
||||||
for I := 0 to FContactsList.Count - 1 do begin
|
for I := 0 to FContactsList.Count - 1 do begin
|
||||||
if CaseInsensitive then begin
|
SearchName := Copy(TVpContact(FContactsList[I]).LastName, 1, SearchLength);
|
||||||
// not case sensitive
|
if CaseInsensitive then
|
||||||
if Copy(uppercase(TVpContact(FContactsList[I]).LastName), 1, SearchLength) = SearchStr
|
SearchName := Uppercase(SearchName);
|
||||||
then begin
|
|
||||||
// We found a match, so return it and bail out
|
// We found a match, so return it and bail out
|
||||||
|
if SearchName = SearchStr then begin
|
||||||
Result := TVpContact(FContactsList[I]);
|
Result := TVpContact(FContactsList[I]);
|
||||||
Exit;
|
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;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user