📄 wwdbcomb.pas
字号:
end;
// 9/17/01 -
// If shift key pressed then its not vk_up or vk_down.
// For instance '&' is ascii 38
if (isDroppedDown and
not (ssShift in KeyDataToShiftState(KeyData)) and
(CharCode in [VK_UP, VK_DOWN])) then
exit;
end
end
end;
inherited WndProc(Message);
end;
procedure TwwDBCustomComboBox.KeyPress(var Key: Char);
var TempAutoFillDate: boolean;
TempText: string;
i, curpos, TempIndex: integer;
LItem: string;
found: boolean;
startIndex: integer;
oldselstart, oldsellength: integer;
// matchIndex: integer;
// MatchTextFromList: string;
Function NewText: string;
var curStr : string;
begin
curStr:= Text;
result:= copy(curStr, 1, selStart) +
char(Key) + copy(curStr, selStart + 1 + length(SelText), 32767);
end;
procedure SelectValue(AIndex: integer);
begin
if AIndex>ListBox.Items.count-1 then exit;
if AIndex<0 then exit;
if (Datasource<>nil) then begin
DataLink.Edit;
if not DataLink.Editing then begin
if (DataLink.Field<>nil) and (DataLink.Field.Calculated) and EditCanModify then
DataLink.DataSet.Edit
else exit; { 4/2/99 - Support calculated field edits}
end
end;
curpos:= 1;
{ 9/24/97 - Call SetItemIndex instead of setting FItemIndex }
SetItemIndex(AIndex);
{ FItemIndex:= AIndex;
Text:= strGetToken(FItems[AIndex], #9, curPos);}
SetModified(True); {1/21/97}
end;
function max(x,y: integer): integer;
begin
if x>y then result:= x else result:= y;
end;
begin
tempText:= NewText;
ListBoxItemsNeeded; // 8/27/00 - Listbox items need to be initialized
{ 3/31/99 - Improved support for ShowMatchText and AllowClearKey }
if ((key=#8) or (key=#24)) {and (Style=csDropDownList) and ShowMatchText }then
begin
if IsDroppedDown then key:= #0
else begin
if Style=csDropDownList then
begin { Find first match }
ApplyList;
ListBox.KeyPress(key);
end
else { Process backspace as delete character }
end;
end;
if ShowMatchText and (Key in [#32..#254]) and (Text<>TempText) then begin
found:= False;
if (selStart>=length(NewText)-1) then begin
// startIndex:= max(0, FItemIndex);
startIndex:= max(0, HistoryList.EffectiveMRUCount);
for i:= startIndex to (startIndex + ListBox.Items.count-1) do begin
tempIndex:= i mod (ListBox.Items.count);
// 2/12/06 - Use AnsiUpperCase instead
// Litem:=uppercase(ListBox.Items[tempIndex]);
// if pos(uppercase(TempText),Litem)=1 then begin
Litem:=AnsiUpperCase(ListBox.Items[tempIndex]);
if AnsiPos(AnsiUppercase(TempText),Litem)=1 then begin
SelectValue(tempIndex);
{ 6/29/99 - ShowMatchText cursor pos should be where typing }
if (DataSource=nil) or DataLink.Editing then begin
selStart:= length(Text);
selLength:= - (length(Text)-length(TempText));
found:= True;
end;
key:= #0;
break;
end
end
end;
if not found then begin
// 8/17/00 - Only ignore key if csDropDownList
if (Style=csDropDownList) {or isDroppedDown }then begin
key:= #0;
end
end
end
else if not Editable and (Key in [#32..#254]) then begin { Use first character to search }
// found:= false;
for i:= FItemIndex+1 to (FItemIndex + ListBox.Items.count) do begin
tempIndex:= i mod (ListBox.Items.count);
// 2/12/06 - Use AnsiUpperCase instead
// Litem:=uppercase(ListBox.Items[tempIndex]);
// if pos(uppercase(char(key)),Litem)=1 then begin
Litem:=AnsiUppercase(ListBox.Items[tempIndex]);
if AnsiPos(AnsiUppercase(char(key)),Litem)=1 then begin
SelectValue(tempIndex);
break;
end
end;
// 8/17/00 - Only ignore key if csDropDownList
if (Style=csDropDownList) then key:= #0;
end;
TempAutoFillDate:= AutoFillDate;
If MapList then AutoFillDate:= False;
{ Going into edit mode the first time can cause the selStart to be wrong if displayformat is assigned }
if not MapList and (DataLink.DataSet<>nil) and (DataLink.dataset.State=dsBrowse) and
(DataLink.Field.asString<>DataLink.Field.DisplayText) then
begin
OldSelStart:= selStart;
OldSelLength:= selLength;
inherited KeyPress(Key);
if (selStart=0) then
begin
selStart:= OldSelStart;
selLength:= OldSelLength;
end
end
else begin
inherited KeyPress(Key);
end;
AutoFillDate:= TempAutoFillDate;
if Key=#13 then Key:= #0; { 8/22/96 - Avoid Beep when closing dropdown :)}
end;
constructor TwwPopupListBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF WIN32}
ControlStyle := ControlStyle + [csReplicatable];
ControlStyle := ControlStyle + [csNoDesignVisible];
{$ENDIF}
end;
procedure TwwDBCustomComboBox.ProcessSearchKey(
Key: char;
NewItemIndex: integer;
OldItemIndex: integer;
FSearchText: string;
MatchTextFromList: string);
var
oldSelStart: integer;
procedure GoBack1;
begin
SelStart:= wwMax(0, SelStart-1);
SelLength:= length(Text)-SelStart;
end;
begin
if NewItemIndex=-1 then begin
if (key=#8) then begin
if (FSearchText='') and (Style=csDropDownList) and ShowMatchText then
begin
GoBack1;
end
else if (Style<>csDropDownList) then
begin
ListBox.ItemIndex:= -1;
// 12/23/04 - Don't move to end like before
oldSelStart := selStart;
Text:= FSearchText;
selStart:= oldSelStart-1;
{
Text:= FSearchText;
SelStart:= length(Text);
}
end
end
else if (Style<>csDropDownList) and (IsDroppedDown) then
begin
ListBox.ItemIndex:= -1;
end
end
else begin
if (key=#8) then
begin
if Style=csDropDownList then
begin
if wwEqualStr(Text, MatchTextFromList) then
begin
GoBack1;
end
else begin
// 2/12/06 - Use AnsiUppercase instead
if AnsiPos(AnsiUppercase(MatchTextFromList), AnsiUppercase(Text))=1 then
begin
Text:= MatchTextFromList;
SelStart:= length(Text);
end
else begin
ListBox.ItemIndex:= OldItemIndex;
GoBack1;
end
end
end
else begin
Text:= FSearchText;
SelStart:= length(Text);
if (IsDroppedDown) then
if not wwEqualStr(FSearchText, MatchTextFromList) then
begin
ListBox.ItemIndex:=-1;
end
end
end
end;
end;
procedure TwwPopupListbox.Keypress(var Key: Char);
var
TickCount: Integer;
buf: array[0..255] of char;
selIndex: integer;
combo: TwwDBCustomComboBox;
MatchTextFromList: string;
OldItemIndex: integer;
Function NewText(Key: Char): string;
var curStr : string;
begin
curStr:= FSearchText;
if Combo.OwnerDraw then result:= curStr + char(Key)
else if (ord(key)=vk_back) then begin
if (length(curstr)>=1) then
begin
if combo.selLength>0 then
delete(curstr, wwmin(combo.selStart+1, length(curstr)),
wwmax(combo.selLength, 1))
else begin // 12/23/04 - If not selection, then delete previous character
if (combo.selStart>=1) then
delete(curstr, wwmin(combo.selStart, length(curstr)), 1);
end
end;
result:= curStr;
end
else
result:= copy(curStr, 1, combo.selStart) +
char(Key) + copy(curStr, combo.selStart + 1 + length(combo.SelText), 32767);
end;
begin
Combo:= owner as TwwDBCustomComboBox;
case Key of
#27: FSearchText := '';
#8, #32..#255:
begin
{ Allow incremental searching for up to 1.5 seconds before resetting }
if Combo.OwnerDraw then begin
TickCount := GetTickCount;
if TickCount - FSearchTickCount > 1500 then FSearchText := '';
FSearchTickCount := TickCount;
end
else FSearchText:= Combo.Text;
{if Length(FSearchText) < 32 then } //10/11/2000-PYW-Prevents backspace from working on string lengths > 32
FSearchText := NewText(Key);
strplcopy(buf, FSearchText, 255);
OldItemIndex:= ItemIndex;
selIndex:= SendMessage(Handle, LB_SelectString,
Combo.HistoryList.EffectiveMRUCount-1 {WORD(-1)}, Longint(@buf));
if ItemIndex>=0 then MatchTextFromList:= Items[ItemIndex]
else MatchTextFromList:= '';
Combo.ProcessSearchKey(key, SelIndex, OldItemIndex, FSearchText, MatchTextFromList);
Key := #0;
end;
end;
inherited Keypress(Key);
end;
procedure TwwPopupListBox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or WS_BORDER;// } or WS_CAPTION;
// Style:= style and not ws_border;
ExStyle := WS_EX_TOOLWINDOW;
WindowClass.Style := CS_SAVEBITS;
end;
end;
procedure TwwPopupListbox.CreateWnd;
begin
inherited CreateWnd;
Windows.SetParent(Handle, 0);
CallWindowProc(DefWndProc, Handle, wm_SetFocus, 0, 0);
end;
procedure TwwPopupListbox.CNCommand(var Message: TWMCommand);
begin
inherited;
case Message.NotifyCode of
LBN_SELCHANGE: { Allow text to change when scrolling with up/down, pageup/pagedown }
begin
with Owner as TwwDBCustomComboBox do
begin
if (Self.ItemIndex>=0) and IsDroppedDown and DoSelChange then
begin
if (DataSource=nil) or (DataLink.Editing) then
begin
if (DataLink.Field=nil) and Readonly then //2/22/2002 - Do not change selection if readonly.
else Text:= Self.Items[ItemIndex];
if Editable then DoSelectAll;
end
end
end
end;
end;
end;
procedure TwwPopupListBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
var combo: TwwDBCustomComboBox;
pt: TPoint;
tempValue: string;
DoDefault: boolean;
TempColumn1Width: integer;
tempRect: TRect;
// Flags:Integer;
begin
Combo:= owner as TwwDBCustomComboBox;
DoDefault:= True;
if Assigned(Combo.FOnDrawItem) and Combo.OwnerDraw then begin
if not (odSelected in State) then begin
Canvas.Brush.Color:= Color;
Canvas.Font.Color:= Font.Color;
Canvas.TextRect(Rect, Rect.Left, Rect.Top, '');
end;
try
Combo.FOnDrawItem(Combo, Index, Rect, State)
except
DoDefault:= False;
end
end;
if Combo.Column1Width=0 then TempColumn1Width:= Width div 2
else TempColumn1Width:= Combo.Column1Width;
if Combo.TwoColumnDisplay and DoDefault then
begin
if Index<=Items.Count-1 then
begin
DoDefault:= False;
// Flags:= DT_END_ELLIPSIS; { If text does not fit then put ellipsis at end }
tempRect:= Rect;
if Combo.MapList then begin
tempValue:= Items[index];
TempRect.Right:= TempRect.Left + tempColumn1Width;
Canvas.TextRect(TempRect, TempRect.Left+1, TempRect.Top+1, tempValue);
Rect.Left:= Rect.Left + TempColumn1Width;
tempValue:= Combo.GetComboValue(Items[Index]);
Canvas.TextRect(Rect, Rect.Left+1, Rect.Top+1, tempValue);
end
else begin
tempValue:= Items[Index];
TempRect.Right:= TempRect.Left + tempColumn1Width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -