📄 tntdbctrls.pas
字号:
S := Tnt_WideLowerCase(S);
end;
end else
S := Text { EditText? };
if PasswordChar <> #0 then
for I := 1 to Length(S) do S[I] := PasswordChar;
_Margins := GetTextMargins;
case AAlignment of
taLeftJustify: ALeft := _Margins.X;
taRightJustify: ALeft := ClientWidth - WideCanvasTextWidth(FCanvas, S) - _Margins.X - 1;
else
ALeft := (ClientWidth - WideCanvasTextWidth(FCanvas, S)) div 2;
end;
if SysLocale.MiddleEast then UpdateTextFlags;
WideCanvasTextRect(FCanvas, R, ALeft, _Margins.Y, S);
end;
finally
FCanvas.Handle := 0;
if Message.DC = 0 then EndPaint(Handle, PS);
end;
end;
end;
function TTntDBEdit.GetTextMargins: TPoint;
var
DC: HDC;
SaveFont: HFont;
I: Integer;
SysMetrics, Metrics: TTextMetric;
begin
if NewStyleControls then
begin
if BorderStyle = bsNone then I := 0 else
if Ctl3D then I := 1 else I := 2;
Result.X := SendMessage(Handle, EM_GETMARGINS, 0, 0) and $0000FFFF + I;
Result.Y := I;
end else
begin
if BorderStyle = bsNone then I := 0 else
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
I := SysMetrics.tmHeight;
if I > Metrics.tmHeight then I := Metrics.tmHeight;
I := I div 4;
end;
Result.X := I;
Result.Y := I;
end;
end;
{ TTntDBText }
constructor TTntDBText.Create(AOwner: TComponent);
begin
inherited;
FDataLink := TDataLink(Perform(CM_GETDATALINK, 0, 0)) as TFieldDataLink;
InheritedDataChange := FDataLink.OnDataChange;
FDataLink.OnDataChange := DataChange;
end;
destructor TTntDBText.Destroy;
begin
FDataLink := nil;
inherited;
end;
procedure TTntDBText.CMDialogChar(var Message: TCMDialogChar);
begin
TntLabel_CMDialogChar(Self, Message, Caption);
end;
function TTntDBText.IsCaptionStored: Boolean;
begin
Result := TntControl_IsCaptionStored(Self)
end;
function TTntDBText.GetCaption: TWideCaption;
begin
Result := TntControl_GetText(Self);
end;
procedure TTntDBText.SetCaption(const Value: TWideCaption);
begin
TntControl_SetText(Self, Value);
end;
procedure TTntDBText.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
function TTntDBText.GetLabelText: WideString;
begin
if csPaintCopy in ControlState then
Result := GetFieldText
else
Result := Caption;
end;
procedure TTntDBText.DoDrawText(var Rect: TRect; Flags: Integer);
begin
if not TntLabel_DoDrawText(Self, Rect, Flags, GetLabelText) then
inherited;
end;
function TTntDBText.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self);
end;
function TTntDBText.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntDBText.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntDBText.CMHintShow(var Message: TMessage);
begin
ProcessCMHintShowMsg(Message);
inherited;
end;
procedure TTntDBText.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntDBText.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
function TTntDBText.GetFieldText: WideString;
begin
if Field <> nil then
Result := GetWideDisplayText(Field)
else
if csDesigning in ComponentState then Result := Name else Result := '';
end;
procedure TTntDBText.DataChange(Sender: TObject);
begin
Caption := GetFieldText;
end;
{ TTntCustomDBComboBox }
constructor TTntCustomDBComboBox.Create(AOwner: TComponent);
begin
inherited;
FItems := TTntComboBoxStrings.Create;
TTntComboBoxStrings(FItems).ComboBox := Self;
FDataLink := TDataLink(Perform(CM_GETDATALINK, 0, 0)) as TFieldDataLink;
FDataLink.OnDataChange := DataChange;
FDataLink.OnUpdateData := UpdateData;
FDataLink.OnEditingChange := EditingChange;
end;
destructor TTntCustomDBComboBox.Destroy;
begin
FreeAndNil(FItems);
FreeAndNil(FSaveItems);
FDataLink := nil;
inherited;
end;
procedure TTntCustomDBComboBox.CreateWindowHandle(const Params: TCreateParams);
begin
CreateUnicodeHandle(Self, Params, 'COMBOBOX');
end;
procedure TTntCustomDBComboBox.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
type
TAccessCustomComboBox = class(TCustomComboBox{TNT-ALLOW TCustomComboBox});
procedure TTntCustomDBComboBox.CreateWnd;
var
PreInheritedAnsiText: AnsiString;
begin
PreInheritedAnsiText := TAccessCustomComboBox(Self).Text;
inherited;
TntCombo_AfterInherited_CreateWnd(Self, Items, FSaveItems, FSaveItemIndex, PreInheritedAnsiText);
end;
procedure TTntCustomDBComboBox.DestroyWnd;
var
SavedText: WideString;
begin
if not (csDestroyingHandle in ControlState) then begin { avoid recursion when parent is TToolBar and system font changes. }
TntCombo_BeforeInherited_DestroyWnd(Self, Items, FSaveItems, ItemIndex, FSaveItemIndex, SavedText);
inherited;
TntControl_SetStoredText(Self, SavedText);
end;
end;
procedure TTntCustomDBComboBox.SetReadOnly;
begin
if (Style in [csDropDown, csSimple]) and HandleAllocated then
SendMessage(EditHandle, EM_SETREADONLY, Ord(not FDataLink.CanModify), 0);
end;
procedure TTntCustomDBComboBox.EditingChange(Sender: TObject);
begin
SetReadOnly;
end;
procedure TTntCustomDBComboBox.CMEnter(var Message: TCMEnter);
var
SaveFarEast: Boolean;
begin
SaveFarEast := SysLocale.FarEast;
try
SysLocale.FarEast := False;
inherited; // inherited tries to work around Win95 FarEast bug, but introduces others
finally
SysLocale.FarEast := SaveFarEast;
end;
end;
procedure TTntCustomDBComboBox.WndProc(var Message: TMessage);
begin
if (not (csDesigning in ComponentState))
and (Message.Msg = CB_SHOWDROPDOWN)
and (Message.WParam = 0)
and (not FDataLink.Editing) then begin
DataChange(Self); {Restore text}
Dispatch(Message); {Do NOT call inherited!}
end else
inherited WndProc(Message);
end;
procedure TTntCustomDBComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer);
begin
if not TntCombo_ComboWndProc(Self, Message, ComboWnd, ComboProc, DoEditCharMsg) then
inherited;
end;
procedure TTntCustomDBComboBox.KeyPress(var Key: AnsiChar);
var
SaveAutoComplete: Boolean;
begin
TntCombo_BeforeKeyPress(Self, SaveAutoComplete);
try
inherited;
finally
TntCombo_AfterKeyPress(Self, SaveAutoComplete);
end;
end;
procedure TTntCustomDBComboBox.DoEditCharMsg(var Message: TWMChar);
begin
TntCombo_AutoCompleteKeyPress(Self, Items, Message,
GetAutoComplete_UniqueMatchOnly, GetAutoComplete_PreserveDataEntryCase);
end;
procedure TTntCustomDBComboBox.WMChar(var Message: TWMChar);
begin
TntCombo_AutoSearchKeyPress(Self, Items, Message, FFilter, FLastTime);
inherited;
end;
function TTntCustomDBComboBox.GetItems: TTntStrings;
begin
Result := FItems;
end;
procedure TTntCustomDBComboBox.SetItems(const Value: TTntStrings);
begin
FItems.Assign(Value);
DataChange(Self);
end;
function TTntCustomDBComboBox.GetSelStart: Integer;
begin
Result := TntCombo_GetSelStart(Self);
end;
procedure TTntCustomDBComboBox.SetSelStart(const Value: Integer);
begin
TntCombo_SetSelStart(Self, Value);
end;
function TTntCustomDBComboBox.GetSelLength: Integer;
begin
Result := TntCombo_GetSelLength(Self);
end;
procedure TTntCustomDBComboBox.SetSelLength(const Value: Integer);
begin
TntCombo_SetSelLength(Self, Value);
end;
function TTntCustomDBComboBox.GetSelText: WideString;
begin
Result := TntCombo_GetSelText(Self);
end;
procedure TTntCustomDBComboBox.SetSelText(const Value: WideString);
begin
TntCombo_SetSelText(Self, Value);
end;
function TTntCustomDBComboBox.GetText: WideString;
begin
Result := TntControl_GetText(Self);
end;
procedure TTntCustomDBComboBox.SetText(const Value: WideString);
begin
TntControl_SetText(Self, Value);
end;
procedure TTntCustomDBComboBox.CNCommand(var Message: TWMCommand);
begin
if not TntCombo_CNCommand(Self, Items, Message) then
inherited;
end;
function TTntCustomDBComboBox.GetFieldValue: Variant;
begin
Result := Field.Value;
end;
procedure TTntCustomDBComboBox.SetFieldValue(const Value: Variant);
begin
Field.Value := Value;
end;
procedure TTntCustomDBComboBox.DataChange(Sender: TObject);
begin
if not (Style = csSimple) and DroppedDown then Exit;
if Field <> nil then
SetComboValue(GetFieldValue)
else
if csDesigning in ComponentState then
SetComboValue(Name)
else
SetComboValue(Null);
end;
procedure TTntCustomDBComboBox.UpdateData(Sender: TObject);
begin
SetFieldValue(GetComboValue);
end;
function TTntCustomDBComboBox.GetAutoComplete_PreserveDataEntryCase: Boolean;
begin
Result := True;
end;
function TTntCustomDBComboBox.GetAutoComplete_UniqueMatchOnly: Boolean;
begin
Result := False;
end;
function TTntCustomDBComboBox.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self);
end;
function TTntCustomDBComboBox.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntCustomDBComboBox.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntCustomDBComboBox.AddItem(const Item: WideString; AObject: TObject);
begin
TntComboBox_AddItem(Items, Item, AObject);
end;
procedure TTntCustomDBComboBox.CopySelection(Destination: TCustomListControl);
begin
TntComboBox_CopySelection(Items, ItemIndex, Destination);
end;
procedure TTntCustomDBComboBox.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntCustomDBComboBox.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
{$IFDEF DELPHI_7} // fix for Delphi 7 only
function TTntCustomDBComboBox.GetItemsClass: TCustomComboBoxStringsClass;
begin
Result := TD7PatchedComboBoxStrings;
end;
{$ENDIF}
{ TTntDBComboBox }
function TTntDBComboBox.GetFieldValue: Variant;
begin
Result := GetWideText(Field);
end;
procedure TTntDBComboBox.SetFieldValue(const Value: Variant);
begin
SetWideText(Field, Value);
end;
procedure TTntDBComboBox.SetComboValue(const Value: Variant);
var
I: Integer;
Redraw: Boolean;
OldValue: WideString;
NewValue: WideString;
begin
OldValue := VarToWideStr(GetComboValue);
NewValue := VarToWideStr(Value);
if NewValue <> OldValue then
begin
if Style <> csDropDown then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -