cxgridcommon.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 614 行 · 第 1/2 页
PAS
614 行
{********************************************************************}
{ }
{ Developer Express Visual Component Library }
{ ExpressQuantumGrid }
{ }
{ Copyright (c) 1998-2008 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE EXPRESSQUANTUMGRID AND ALL }
{ ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{********************************************************************}
unit cxGridCommon;
{$I cxVer.inc}
interface
uses
Windows, Messages, TypInfo, Classes, Graphics, Controls, ComCtrls,
cxClasses, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
cxTreeView;
const
ScxGridPrefixName = 'TcxGrid';
cxGridInvisibleCoordinate = 30000{100000};
cxGridCellTextOffset = 2;
cxGridEditOffset = 1;
cxGridHeaderTextOffset = 2;
cxGridDesignViewBorderColor = 3577330;
cxGridDesignViewColor = 9295359;
cxGridDesignViewHotColor = 6862841;//6078705;
cxGridDesignSelectedBorderColor = 11504744;//clWhite;
cxGridDesignSelectedColor = 14991773;
cxGridDesignSelectedHotBorderColor = clDkGray;//12033927;
cxGridDesignSelectedHotColor = 14065255;//13747387;
type
TcxGridCellState = (gcsNone, gcsSelected, gcsPressed);
TcxGridClassEnumeratorProc = procedure(AClass: TClass) of object;
{ custom change }
TcxCustomGridChange = class
private
FControl: TcxControl;
public
function CanExecuteWhenLocked: Boolean; virtual;
procedure Execute; virtual; abstract;
function IsCompatibleWith(AChange: TcxCustomGridChange): Boolean; virtual;
function IsCumulative: Boolean; virtual;
function IsEqual(AChange: TcxCustomGridChange): Boolean; virtual;
function IsLockable: Boolean; virtual;
property Control: TcxControl read FControl write FControl; // TcxCustomGrid
end;
{ custom drag open info }
TcxCustomGridDragOpenInfo = class
public
function Equals(AInfo: TcxCustomGridDragOpenInfo): Boolean; virtual;
procedure Run; virtual; abstract;
end;
{ options tree view }
TcxGridOptionsTreeViewGetTypeItemCaptionFunction = function(ATypeItem: Integer): string;
TcxGridOptionsTreeViewItemKind = (otikCategory, otikCheckBox, otikRadioButton);
TcxGridOptionsTreeView = class(TcxTreeView)
private
FItemValuesUpdateLocked: Boolean;
FMaxID: Integer;
procedure WMDestroy(var Message: TWMDestroy); message WM_DESTROY;
procedure CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
State: TCustomDrawState; var DefaultDraw: Boolean);
procedure GetNodeImageIndex(Sender: TObject; Node: TTreeNode);
procedure GetNodeSelectedImageIndex(Sender: TObject; Node: TTreeNode);
protected
procedure CreateWnd; override;
procedure LookAndFeelChanged(Sender: TcxLookAndFeel; AChangedValues: TcxLookAndFeelValues); override;
function AddItem(AParentID, AID: Integer; const ACaption: string;
AKind: TcxGridOptionsTreeViewItemKind): Integer; virtual;
procedure ClearItems;
function FindNodeByID(AID: Integer): TTreeNode;
function GetItemImageIndex(AKind: TcxGridOptionsTreeViewItemKind; AChecked: Boolean): Integer;
function GetNodeID(ANode: TTreeNode): Integer;
function GetNodeKind(ANode: TTreeNode): TcxGridOptionsTreeViewItemKind;
function GetNodeParentID(ANode: TTreeNode): Integer;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure NodeClicked(ANode: TTreeNode); virtual;
procedure RefreshImages;
procedure RefreshItemImageIndexes;
procedure ResetMaxID;
function CalculateImagesSize: TSize; virtual;
procedure DrawImage(ACanvas: TcxCanvas; const ARect: TRect;
AItemKind: TcxGridOptionsTreeViewItemKind; AChecked: Boolean); virtual;
function GetCategoryBitmap: TBitmap;
function GetCategorySize: TSize; virtual;
function GetCheckBoxSize: TSize; virtual;
function GetRadioButtonSize: TSize; virtual;
procedure AddItems; virtual; abstract;
function IsItemChecked(AParentID, AID: Integer): Boolean; virtual; abstract;
procedure ItemClicked(AParentID, AID: Integer); virtual; abstract;
property ItemValuesUpdateLocked: Boolean read FItemValuesUpdateLocked
write FItemValuesUpdateLocked;
property MaxID: Integer read FMaxID;
public
constructor Create(AOwner: TComponent); override;
function AddCategory(AParentID, AID: Integer; const ACaption: string): Integer;
function AddCheckBox(AParentID, AID: Integer; const ACaption: string): Integer;
function AddRadioButton(AParentID, AID: Integer; const ACaption: string): Integer;
procedure AddRadioButtons(AParentID: Integer; ATypeInfo: PTypeInfo;
AGetTypeItemCaption: TcxGridOptionsTreeViewGetTypeItemCaptionFunction);
procedure RefreshItems;
procedure RefreshItemValues;
end;
function GetValidName(AComponent: TComponent; const AName: string;
AIsBaseName: Boolean = False): string;
procedure GetCellTextAreaSize(var ATextSize: Integer);
function GridCellStateToButtonState(ACellState: TcxGridCellState): TcxButtonState;
implementation
{$R cxGrid.res}
uses
cxGeometry, Math, Forms, SysUtils, cxLibraryConsts;
{ TcxCustomGridChange }
function TcxCustomGridChange.CanExecuteWhenLocked: Boolean;
begin
Result:= True;
end;
function TcxCustomGridChange.IsCompatibleWith(AChange: TcxCustomGridChange): Boolean;
begin
Result := False;
end;
function TcxCustomGridChange.IsCumulative: Boolean;
begin
Result := True;
end;
function TcxCustomGridChange.IsEqual(AChange: TcxCustomGridChange): Boolean;
begin
Result := ClassType = AChange.ClassType;
end;
function TcxCustomGridChange.IsLockable: Boolean;
begin
Result := True;
end;
{ TcxCustomGridDragOpenInfo }
function TcxCustomGridDragOpenInfo.Equals(AInfo: TcxCustomGridDragOpenInfo): Boolean;
begin
Result := ClassType = AInfo.ClassType;
end;
{ TcxGridOptionsTreeView }
const
OptionsTreeViewMaxInternalID = 99;
type
TOptionTreeNodeData = class
ID: Integer;
Kind: TcxGridOptionsTreeViewItemKind;
constructor Create(AID: Integer; AKind: TcxGridOptionsTreeViewItemKind);
end;
constructor TOptionTreeNodeData.Create(AID: Integer; AKind: TcxGridOptionsTreeViewItemKind);
begin
inherited Create;
ID := AID;
Kind := AKind;
end;
constructor TcxGridOptionsTreeView.Create(AOwner: TComponent);
begin
inherited;
ReadOnly := True;
ShowButtons := False;
ShowRoot := False;
Images := TImageList.Create(Self);
OnCustomDrawItem := CustomDrawItem;
OnGetImageIndex := GetNodeImageIndex;
OnGetSelectedIndex := GetNodeSelectedImageIndex;
ResetMaxID;
end;
procedure TcxGridOptionsTreeView.WMDestroy(var Message: TWMDestroy);
begin
ClearItems;
inherited;
end;
procedure TcxGridOptionsTreeView.CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
State: TCustomDrawState; var DefaultDraw: Boolean);
var
R: TRect;
begin
// to fix the bug in VCL tree view
Sender.Canvas.Font.Name := 'System';
Sender.Canvas.Font.Name := Font.Name;
if GetNodeKind(Node) = otikCategory then
begin
if Node.Level = 0 then
begin
R := Node.DisplayRect(False);
R.Left := Node.DisplayRect(True).Left;
if not (cdsSelected in State) then
Sender.Canvas.Brush.Color := clBtnShadow;
Sender.Canvas.FillRect(R);
end;
Sender.Canvas.Font.Style := [fsBold];
end;
end;
procedure TcxGridOptionsTreeView.GetNodeImageIndex(Sender: TObject; Node: TTreeNode);
begin
if GetNodeKind(Node) = otikCategory then
Node.ImageIndex := GetItemImageIndex(otikCategory, Node.Expanded);
end;
procedure TcxGridOptionsTreeView.GetNodeSelectedImageIndex(Sender: TObject; Node: TTreeNode);
begin
if GetNodeKind(Node) = otikCategory then
Node.SelectedIndex := GetItemImageIndex(otikCategory, Node.Expanded);
end;
procedure TcxGridOptionsTreeView.CreateWnd;
begin
inherited;
RefreshImages;
RefreshItems;
end;
procedure TcxGridOptionsTreeView.LookAndFeelChanged(Sender: TcxLookAndFeel;
AChangedValues: TcxLookAndFeelValues);
begin
inherited;
if not FIsCreating then
RefreshImages;
end;
function TcxGridOptionsTreeView.AddItem(AParentID, AID: Integer;
const ACaption: string; AKind: TcxGridOptionsTreeViewItemKind): Integer;
var
AParent: TTreeNode;
begin
if AParentID = -1 then
AParent := nil
else
AParent := FindNodeByID(AParentID);
if AID = -1 then
begin
Inc(FMaxID);
AID := FMaxID;
end
else
FMaxID := Max(FMaxID, AID);
Result := AID;
Items.AddChildObject(AParent, ACaption, TOptionTreeNodeData.Create(AID, AKind));
end;
procedure TcxGridOptionsTreeView.ClearItems;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?