📄 tntjvdbcombobox.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvDBComb.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
Contributor(s):
Polaris Software
Last Modified: 2002-07-04
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
{$I TntCompilers.INC}
unit TntJvDBCombobox;
interface
uses Windows, DbCtrls,
{$IFDEF COMPILER_6_UP}
VDBConsts,
{$ENDIF}
Messages, Menus, Graphics, Classes, Controls, DB,
StdCtrls, DBConsts, TntClasses, TntSysUtils, TntSystem,
TntDB, TntControls, TntJvExStdCtrls, TntDBCtrls;
type
TTntJvCustomDBComboBox = class(TTntJvExCustomComboBox)
private
FDataLink: TFieldDataLink;
FPaintControl: TTntPaintControl;
procedure DataChange(Sender: TObject);
procedure EditingChange(Sender: TObject);
function GetDataField: string;
function GetDataSource: TDataSource;
function GetField: TField;
function GetReadOnly: Boolean;
procedure SetDataField(const Value: string);
procedure SetDataSource(Value: TDataSource);
procedure SetEditReadOnly;
procedure SetReadOnly(Value: Boolean);
procedure UpdateData(Sender: TObject);
function GetComboText: WideString; virtual;
procedure SetComboText(const Value: WideString); virtual;
procedure CMExit(var Msg: TCMExit); message CM_EXIT;
procedure CMGetDataLink(var Msg: TMessage); message CM_GETDATALINK;
procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
protected
procedure Change; override;
procedure Click; override;
procedure ComboWndProc(var Msg: TMessage; ComboWnd: HWND;
ComboProc: Pointer); override;
procedure CreateWnd; override;
procedure DropDown; override;
function GetPaintText: WideString; virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure Loaded; override;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
procedure SetStyle(Value: TComboBoxStyle); override;
procedure SetItems(const Value: TTntStrings); override;
procedure WndProc(var Msg: TMessage); override;
property ComboText: WideString read GetComboText write SetComboText;
property DataField: string read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecuteAction(Action: TBasicAction): Boolean; override;
function UpdateAction(Action: TBasicAction): Boolean; override;
function UseRightToLeftAlignment: Boolean; override;
property Field: TField read GetField;
property Items write SetItems;
property Text;
end;
TTntJvDBComboBox = class(TTntJvCustomDBComboBox)
private
FValues: TTntStrings;
FEnableValues: Boolean;
procedure SetEnableValues(Value: Boolean);
procedure SetValues(Value: TTntStrings);
procedure ValuesChanged(Sender: TObject);
protected
procedure SetStyle(Value: TComboBoxStyle); override;
function GetComboText: WideString; override;
function GetPaintText: WideString; override;
procedure SetComboText(const Value: WideString); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align; // Polaris
property Style { must be published before Items }
default csDropDownList; // Polaris
property Color;
property Ctl3D;
property DataField;
property DataSource;
property DragMode;
property DragCursor;
property DropDownCount;
property Enabled;
property EnableValues: Boolean read FEnableValues write SetEnableValues
default True; // Polaris
property Font;
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
property HintColor;
property ImeMode;
property ImeName;
property ItemHeight;
property Items;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Values: TTntStrings read FValues write SetValues;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnStartDrag;
property OnContextPopup;
property OnEndDock;
property OnStartDock;
end;
implementation
uses
JvDBUtils,
TntDBCtrls2;
constructor TTntJvCustomDBComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csReplicatable];
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnUpdateData := UpdateData;
FDataLink.OnEditingChange := EditingChange;
FPaintControl := TTntPaintControl.Create(Self, 'COMBOBOX');
end;
destructor TTntJvCustomDBComboBox.Destroy;
begin
FPaintControl.Free;
FDataLink.OnDataChange := nil;
FDataLink.OnUpdateData := nil;
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TTntJvCustomDBComboBox.Loaded;
begin
inherited Loaded;
if csDesigning in ComponentState then
DataChange(Self);
end;
procedure TTntJvCustomDBComboBox.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then
DataSource := nil;
end;
procedure TTntJvCustomDBComboBox.CreateWnd;
begin
inherited CreateWnd;
SetEditReadOnly;
end;
procedure TTntJvCustomDBComboBox.DataChange(Sender: TObject);
begin
if DroppedDown then
Exit;
if FDataLink.Field <> nil then
ComboText := FDataLink.Field.Text
else
if csDesigning in ComponentState then
ComboText := Name
else
ComboText := '';
end;
procedure TTntJvCustomDBComboBox.UpdateData(Sender: TObject);
begin
FDataLink.Field.Text := ComboText;
end;
procedure TTntJvCustomDBComboBox.SetComboText(const Value: WideString);
var
I: Integer;
Redraw: Boolean;
begin
if Value <> ComboText then
begin
if Style <> csDropDown then
begin
Redraw := (Style <> csSimple) and HandleAllocated;
if Redraw then
SendMessage(Handle, WM_SETREDRAW, 0, 0);
try
if Value = '' then
I := -1
else
I := Items.IndexOf(Value);
ItemIndex := I;
finally
if Redraw then
begin
SendMessage(Handle, WM_SETREDRAW, 1, 0);
Invalidate;
end;
end;
if I >= 0 then
Exit;
end;
if Style in [csDropDown, csSimple] then
Text := Value;
end;
end;
function TTntJvCustomDBComboBox.GetComboText: WideString;
var
I: Integer;
begin
if Style in [csDropDown, csSimple] then
Result := Text
else
begin
I := ItemIndex;
if I < 0 then
Result := ''
else
Result := Items[I];
end;
end;
procedure TTntJvCustomDBComboBox.Change;
begin
FDataLink.Edit;
inherited Change;
FDataLink.Modified;
end;
procedure TTntJvCustomDBComboBox.Click;
begin
FDataLink.Edit;
inherited Click;
FDataLink.Modified;
end;
procedure TTntJvCustomDBComboBox.DropDown;
begin
inherited DropDown;
end;
function TTntJvCustomDBComboBox.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -