LCL: TComboBox: clean up and added TCustomComboBox.UTF8KeyPress override for lower/uppercase, LCL: nicer parameter names

git-svn-id: trunk@16462 -
This commit is contained in:
mattias 2008-09-07 11:09:00 +00:00
parent 45780ee1aa
commit 2b3fb23528
3 changed files with 76 additions and 62 deletions

View File

@ -486,76 +486,88 @@ var
iSelStart: Integer; // byte position
sCompleteText, sPrefixText, sResultText: string;
begin
inherited KeyUp(Key, Shift);
if ((cbactEnabled in FAutoCompleteText) and (Style <> csDropDownList)) then
inherited KeyUp(Key, Shift);
//SelectAll when hitting return key for AutoSelect feature
if (Key = VK_RETURN) then
begin
//Only happens with alpha-numeric keys and return key and editable Style
if (IsEditableTextKey(Key) or (Key = VK_RETURN) or (ssShift in Shift)) then
begin
if (Key = VK_RETURN) then
SelectAll
else begin
iSelStart := SelStart;//Capture original cursor position
//End of line completion
if ((iSelStart < Length(Text))
and (cbactEndOfLineComplete in FAutoCompleteText)) then
Exit;
sPrefixText := LeftStr(Text, iSelStart);
sCompleteText := GetCompleteText(Text, iSelStart,
(cbactSearchCaseSensitive in FAutoCompleteText),
(cbactSearchAscending in FAutoCompleteText), Items);
if not (sCompleteText = Text) then
begin
sResultText := sCompleteText;
if ((cbactEndOfLineComplete in FAutoCompleteText) and
(cbactRetainPrefixCase in FAutoCompleteText)) then
begin//Retain Prefix Character cases
Delete(sResultText, 1, iSelStart);
Insert(sPrefixText, sResultText, 1);
end;//End if ((cbactEndOfLineComplete in FAutoCompleteText) and....
Text := sResultText;
SelStart := iSelStart;
SelLength := Length(Text);
end;//End if not (sCompleteText = Text)
end;//End if (Key = VK_RETURN)
end;//End if (IsEditableTextKey(Key) or (Key = VK_RETURN) or (ssShift in Shift))
end;//End if ((cbactEnabled in FAutoCompleteText) and (Style = csDropDown))
//SelectAll when hitting return key for AutoSelect feature
if (Key = VK_RETURN) then
begin
if FAutoSelect then
if ((cbactEnabled in FAutoCompleteText) and (Style <> csDropDownList)) then
begin
// Only happens with alpha-numeric keys and return key and editable Style
SelectAll;
end;
if FAutoSelect then
begin
SelectAll;
if (SelText = Text) then FAutoSelected := True;
end;//End if FAutoSelect
end;//End if (Key = VK_RETURN)
end;
end
else if ((cbactEnabled in FAutoCompleteText) and (Style <> csDropDownList))
then begin
//Only happens with alpha-numeric keys and return key and editable Style
//DebugLn(['TCustomComboBox.KeyUp ',Key,' ',IsEditableTextKey(Key)]);
if IsEditableTextKey(Key) then
begin
iSelStart := SelStart;//Capture original cursor position
//DebugLn(['TCustomComboBox.UTF8KeyPress SelStart=',SelStart,' Text=',Text]);
//End of line completion
if ((iSelStart < Length(Text))
and (cbactEndOfLineComplete in FAutoCompleteText)) then
Exit;
sPrefixText := LeftStr(Text, iSelStart);
sCompleteText := GetCompleteText(Text, iSelStart,
(cbactSearchCaseSensitive in FAutoCompleteText),
(cbactSearchAscending in FAutoCompleteText), Items);
//DebugLn(['TCustomComboBox.UTF8KeyPress sCompleteText=',sCompleteText,' Text=',Text]);
if (sCompleteText <> Text) then
begin
sResultText := sCompleteText;
if ((cbactEndOfLineComplete in FAutoCompleteText) and
(cbactRetainPrefixCase in FAutoCompleteText)) then
begin//Retain Prefix Character cases
Delete(sResultText, 1, iSelStart);
Insert(sPrefixText, sResultText, 1);
end;
Text := sResultText;
SelStart := iSelStart;
SelLength := Length(Text);
end;
end;
end;
end;
procedure TCustomComboBox.KeyPress(var Key: char);
begin
//Convert character cases if FCharCase is not ecNormalCase
case FCharCase of
//Convert character cases if FCharCase is not ecNormalCase
case FCharCase of
ecLowerCase: Key := lowerCase(Key);
ecUpperCase: Key := upCase(Key);
end;//End case
inherited KeyPress(Key);
end;
inherited KeyPress(Key);
end;
procedure TCustomComboBox.UTF8KeyPress(var UTF8Key: TUTF8Char);
begin
//Convert character cases if FCharCase is not ecNormalCase
case FCharCase of
ecLowerCase: UTF8Key := AnsiLowerCase(UTF8Key);
ecUpperCase: UTF8Key := AnsiUpperCase(UTF8Key);
end;
inherited UTF8KeyPress(UTF8Key);
end;
procedure TCustomComboBox.MouseUp(Button: TMouseButton; Shift:TShiftState;
X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
//AutoSelect when left mouse is clicked for the 1st time after having focus
if (Button = mbLeft) then
inherited MouseUp(Button, Shift, X, Y);
//AutoSelect when left mouse is clicked for the 1st time after having focus
if (Button = mbLeft) then
begin
if (FAutoSelect and not FAutoSelected) then
begin
SelectAll;
if (SelText = Text) then FAutoSelected := True;
end;//End if (FAutoSelect and not FAutoSelected)
end;//End if (Button = mbLeft)
//if (Style = csDropDownList) then
// DroppedDown := not DroppedDown;
end;
end;
end;
{------------------------------------------------------------------------------

View File

@ -294,9 +294,9 @@ function UTF8ToDoubleByte(UTF8Str: PChar; Len: integer; DBStr: PByte): integer;
function UTF8FindNearestCharStart(UTF8Str: PChar; Len: integer;
BytePos: integer): integer;
// find the n-th UTF8 character, ignoring BIDI
function UTF8CharStart(UTF8Str: PChar; Len, Index: integer): PChar;
function UTF8CharStart(UTF8Str: PChar; Len, CharIndex: integer): PChar;
// find the byte index of the n-th UTF8 character, ignoring BIDI (byte len of substr)
function UTF8CharToByteIndex(UTF8Str: PChar; Len, Index: integer): Integer;
function UTF8CharToByteIndex(UTF8Str: PChar; Len, CharIndex: integer): Integer;
procedure UTF8FixBroken(P: PChar);
function UTF8CharacterStrictLength(P: PChar): integer;
function UTF8CStringToUTF8String(SourceStart: PChar; SourceLen: SizeInt) : string;
@ -542,12 +542,13 @@ function GetCompleteText(sText: string; iSelStart: Integer;
begin
ResultText := sCompareText;
Result := True;
end;//End if (sTempText = sPrefix)
end;//End function IsSamePrefix
end;
end;
var i: Integer;
sPrefixText: string;
begin
//DebugLn(['GetCompleteText sText=',sText,' iSelStart=',iSelStart,' bCaseSensitive=',bCaseSensitive,' bSearchAscending=',bSearchAscending,' slTextList.Count=',slTextList.Count]);
Result := sText;//Default to return original text if no identical text are found
if (sText = '') then Exit;//Everything is compatible with nothing, Exit.
if (iSelStart = 0) then Exit;//Cursor at beginning
@ -563,7 +564,7 @@ begin
begin
for i:=slTextList.Count-1 downto 0 do
if IsSamePrefix(slTextList[i], sPrefixText, iSelStart, Result) then Break;
end;//End if bSearchAscending
end;
end;
function IsEditableTextKey(Key: Word): Boolean;
@ -2475,32 +2476,32 @@ begin
end;
{ Len is the length in bytes of UTF8Str
Index is the position of the desired char, in chars
CharIndex is the position of the desired char, in chars
This function is similar to UTF8FindNearestCharStart
}
function UTF8CharStart(UTF8Str: PChar; Len, Index: integer): PChar;
function UTF8CharStart(UTF8Str: PChar; Len, CharIndex: integer): PChar;
var
CharLen: LongInt;
begin
Result:=UTF8Str;
if Result<>nil then begin
while (Index>0) and (Len>0) do begin
while (CharIndex>0) and (Len>0) do begin
CharLen:=UTF8CharacterLength(Result);
dec(Len,CharLen);
dec(Index);
dec(CharIndex);
inc(Result,CharLen);
end;
if (Index>0) or (Len<0) then
if (CharIndex>0) or (Len<0) then
Result:=nil;
end;
end;
function UTF8CharToByteIndex(UTF8Str : PChar; Len, Index : integer) : Integer;
function UTF8CharToByteIndex(UTF8Str : PChar; Len, CharIndex : integer) : Integer;
var
p: PChar;
begin
p := UTF8CharStart(UTF8Str, Len, Index);
p := UTF8CharStart(UTF8Str, Len, CharIndex);
if p = nil
then Result := -1
else Result := p - UTF8Str;

View File

@ -331,6 +331,7 @@ type
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: char); override;
procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override;
procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X, Y: Integer); override;
function SelectItem(const AnItem: String): Boolean;