📄 wwdbcomb.pas
字号:
Canvas.TextRect(TempRect, TempRect.Left+1, TempRect.Top+1, tempValue);
Rect.Left:= Rect.Left + TempColumn1Width;
tempValue:= Combo.GetComboDisplay(Items[index]);
Canvas.TextRect(Rect, Rect.Left+1, Rect.Top+1, tempValue);
end;
end
end;
if DoDefault and not Assigned(Combo.OnDrawItem) then // 1/24/03 - Don't overwrite owner drawing above
inherited DrawItem(Index, Rect, State);
pt:= Point(2,2);
if Combo.HistoryList.EffectiveMRUCount>0 then
begin
try
if (Index = Combo.HistoryList.EffectiveMRUCount-1) then
begin
Canvas.Pen.Color := clBtnShadow;
Canvas.PolyLine([Point(0, rect.Bottom - 1), Point(Width, rect.Bottom - 1)]);
end;
if (Index = Combo.HistoryList.EffectiveMRUCount) then
begin
Canvas.Pen.Color := clBtnShadow;
Canvas.PolyLine([Point(0, rect.Top+1), Point(Width, rect.Top+1)]);
end;
finally
end
end;
end;
type
TwwCheatListBox=class(TListBox);
TwwComboStringList = class(TStringList)
protected
// procedure EndUpdate; override;
// protected
// procedure Put(Index: Integer; const S: string); override;
// procedure PutObject(Index: Integer; AObject: TObject); override;
// procedure SetCapacity(NewCapacity: Integer); override;
// procedure SetUpdateState(Updating: Boolean); override;
public
function AddObject(const S: string; AObject: TObject): Integer; override;
function Add(const S: string): Integer; override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Exchange(Index1, Index2: Integer); override;
procedure Insert(Index: Integer; const S: string); override;
procedure Sort; override;
function ListBoxReady: boolean; virtual;
function IndexOf(const S: string): Integer; override;
private
Combo: TwwDBCustomComboBox;
end;
function TwwComboStringList.IndexOf(const S: string): Integer;
begin
// if Combo.DirtyListBox then
// Combo.ListBoxItemsNeeded;
result:= inherited IndexOf(S);
end;
function TwwComboStringList.ListBoxReady: boolean;
begin
result:= (Combo.ListBox<>nil) and Combo.Listbox.HandleAllocated;
end;
{
procedure TwwComboStringList.Put(Index: Integer; const S: string);
begin
inherited Put(Index, S);
// if ListBoxReady then TStringList(Combo.ListBox.Items).Put(Index, S);
end;
procedure TwwComboStringList.PutObject(Index: Integer; AObject: TObject);
begin
inherited PutObject(Index, AObject);
// if ListBoxReady then Combo.ListBox.Items.PutObject(Index, AObject);
end;
}
function TwwComboStringList.Add(const S: string): Integer;
begin
result:= inherited Add(S);
Combo.DirtyListBox:= True;
// if ListBoxReady then Combo.Listbox.Items.Add(S);
end;
function TwwComboStringList.AddObject(const S: string; AObject: TObject): Integer;
begin
result:= inherited AddObject(S, AObject);
Combo.DirtyListBox:= True;
// if ListBoxReady then Combo.Listbox.Items.AddObject(S, AObject);
// if ListBoxReady then Combo.ListBox.Items.Objects[
// PutObject(Result, AObject);
end;
procedure TwwComboStringList.Clear;
begin
inherited Clear;
Combo.DirtyListBox:= True;
// if ListBoxReady then Combo.Listbox.Items.Clear;
end;
procedure TwwComboStringList.Delete(Index: Integer);
begin
inherited Delete(Index);
Combo.DirtyListBox:= True;
// if ListBoxReady then Combo.Listbox.Items.Delete(Index);
end;
procedure TwwComboStringList.Exchange(Index1, Index2: Integer);
begin
inherited Exchange(Index1, Index2);
Combo.DirtyListBox:= True;
// if ListBoxReady then Combo.Listbox.Items.Exchange(Index1, Index2);
end;
procedure TwwComboStringList.Insert(Index: Integer; const S: string);
begin
inherited Insert(Index, S);
Combo.DirtyListBox:= True;
// if ListBoxReady then Combo.Listbox.Items.Insert(Index, S);
end;
// Refresh listbox list
{
procedure TwwComboStringList.EndUpdate;
begin
inherited EndUpdate;
if ListBoxReady then
Combo.ListBoxItemsNeeded;
end;
}
procedure TwwComboStringList.Sort;
begin
inherited Sort;
if ListBoxReady and (Combo.ListBox.Items is TStringList) then
TStringList(Combo.Listbox.Items).Sort;
end;
constructor TwwDBCustomComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DropDownCount:= 8;
FItems:= TwwComboStringList.create;
TwwComboStringList(FItems).Combo:= self;
FItemIndex:= -1;
FHistoryList := TwwHistoryList.Create;
with FHistoryList do begin
Owner:= self;
// Source := FItems;
end;
ButtonStyle:= cbsDownArrow; {???}
DataLink.OnDataChange := DataChange;
{$ifdef wwDelphi4Up}
if not Patch[2] then
Button.OnClick:= nil;
{$endif}
end;
Function TwwDBCustomComboBox.GetCanvas: TCanvas;
begin
if FCanvas<>Nil then result:= FCanvas
else if FListBox<>Nil then result:= FListBox.Canvas
else result:= Nil;
end;
destructor TwwDBCustomComboBox.Destroy;
begin
FHistoryList.Free;
FHistoryList := nil;
FItems.Free;
FItems:= nil;
FListbox.Free;
FListbox:= nil;
{$ifdef wwDelphi4up}
if wwHook<>0 then begin
UnhookWindowsHookEx(wwHook);
wwHook:= 0;
end;
{$endif}
inherited Destroy;
end;
procedure TwwDBCustomComboBox.ListBoxItemsNeeded;
begin
ListBoxNeeded;
if (ListBox.Items.Count=0) or DirtyListBox then ApplyList;
DirtyListBox:= False;
end;
function TwwDBCustomComboBox.CreateListBox: TwwPopupListBox;
begin
result:= TwwPopupListbox.create(self);
end;
procedure TwwDBCustomComboBox.ListboxNeeded;
begin
if FListbox<>Nil then exit;
FListbox:= CreateListBox;
if (csDesigning in ComponentState) then
begin
FListBox.Width:= 10;
FListBox.Height:= 10;
end;
FListbox.visible:= False;
FListbox.integralHeight:= True;
FListbox.ItemHeight := 11;
FListbox.parent:= self;
FListbox.ParentShowHint:=false;
FListbox.showhint:= false;
SetWindowPos(FListbox.Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or HWND_TOPMOST or
SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW); { Hide window }
FListbox.visible:= False;
FListbox.OnMouseUp := ListMouseUp;
end;
Function TwwDBCustomComboBox.GetFieldMapText(StoreValue: string; var res: string): boolean;
begin
if maplist then begin
Res:= GetComboDisplay(StoreValue);
result:= True;
end
else result:= False;
end;
Function TwwDBCustomComboBox.GetStoredText: string;
begin
result:= GetComboText;
end;
{ Return current combo's hidden value }
function TwwDBCustomComboBox.GetComboText: string;
begin
if (Style in [csDropDown]) and (Text='') then Result:= ''
else Result:= GetComboValue(Text);
end;
Function TwwDBCustomComboBox.GetValue: string;
begin
result:= GetStoredText;
end;
Procedure TwwDBCustomComboBox.SetValue(Value: string);
var curpos, i, j: integer;
DisplayVal: string;
begin
EnableEdit;
ListBoxItemsNeeded;
if FMapList then begin
FItemIndex:= -1; {4/8/98 }
for i:= 0 to FItems.count-1 do begin
curpos:= 1;
DisplayVal:= strGetToken(FItems[i], #9, curPos);
if strGetToken(FItems[i], #9, curPos)=Value then
begin
for j:= 0 to ListBox.Items.Count-1 do
begin
if wwEqualStr(ListBox.Items[j], DisplayVal) then
begin
FItemIndex:= i;
Text:= DisplayVal;
Listbox.itemindex := i; //10/20/2000 - Update listbox's itemindex property when value set.
break;
end
end;
exit;
end
end;
if FItemIndex=-1 then Text:= '';
end
else begin
// FItemIndex:= ListBox.Items.IndexOf(Value);
FItemIndex:= IndexOf(Value);
Text:= Value;
end
end;
{ Map a HiddenValue to its corresponding Display Value }
Function TwwDBCustomComboBox.GetComboDisplay(Value: string): string;
var curpos, i: integer;
DisplayVal: string;
begin
Result:= '';
if FMapList or TwoColumnDisplay then
begin
for i:= 0 to FItems.count-1 do begin
curpos:= 1;
DisplayVal:= strGetToken(FItems[i], #9, curPos);
if strGetToken(FItems[i], #9, curPos)=Value then
begin
result:= DisplayVal;
exit;
end
end
end
else Result:= Value;
end;
{ Map a DisplayValue to its corresponding Hidden Value }
Function TwwDBCustomComboBox.GetComboValue(DisplayText: string): string;
var curpos, i: integer;
begin
result:= DisplayText;
if FMapList or TwoColumnDisplay then begin
// 12/12/2001-Don't clear result if this is for TwoColumnDisplay
if not TwoColumnDisplay then result:= ''; // 10/4/01 - Otherwise returns displaytext when it does not find value
for i:= 0 to FItems.count-1 do begin
curpos:= 1;
if wwEqualStr(strGetToken(FItems[i], #9, curPos), DisplayText) then // 2/19/02 - Case insensitive
// if strGetToken(FItems[i], #9, curPos)=DisplayText then
begin
result:= strGetToken(FItems[i], #9, curPos);
break;
end
end
end
// else Result:= DisplayText;
end;
procedure TwwDBCustomComboBox.DataChange(Sender: TObject);
begin
if Patch[1] then exit; // 2/24/99 - Fix for ItemIndex being incorrect at time of OnCloseUp
if csDestroying in ComponentState then exit; // 12/17/00 RSW - Fix problem where handle gets created when destroying
if MapList or HistoryList.enabled then // 2/22/2002 - Don't do otherwise to delay listbox creation until necessary
ListBoxItemsNeeded;
{ When mapping list don't do edit masking }
if MapList then begin
if DataLink.Field <> nil then
SetComboText(DataLink.Field.asString)
else
if csDesigning in ComponentState then
SetComboText(Name)
else
SetComboText('');
end
else begin
if (DataLink.Field<>Nil) then begin
SetComboText(DataLink.Field.DisplayText); { 6/20/98 }
if OwnerDraw then begin
FItemIndex:= IndexOf(DataLink.Field.asString);
// FItemIndex:= FListBox.Items.IndexOf(DataLink.Field.asString);
invalidate;
end
end;
inherited DataChange(Sender);
end
end;
procedure TwwDBCustomComboBox.SetComboText(const Value: string);
var
I,J: Integer;
curPos: integer;
NewText: string;
begin
if (Value <> GetComboText) or ((Value='') and MapList) then {5/6/97 - Support null mapping }
begin
if (Style in [csDropDown]) and (not FMapList) then
begin
Text := Value;
FItemIndex:= IndexOf(Value);
exit;
end;
if (Value = '') and (not MapList) then I := -1 { 5/6/97 - Support null mapping }
else begin
if (FMapList) then begin
i:= -1;
for j:= 0 to FItems.count-1 do begin
curpos:= 1;
NewText:= strGetToken(FItems[j], #9, curPos);
if Value=strGetToken(FItems[j], #9, curPos) then begin
// i:= j;
i:= IndexOf(NewText);
// i:= ListBox.Items.IndexOf(NewText);
Text:= NewText;
break;
end
end;
// if i>=FListBox.Items.count then i:= -1;
end
else I:= IndexOf(Value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -