📄 jvginspectorgrid.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: JvgInspectorGrid.PAS, released on 2003-01-15.
The Initial Developer of the Original Code is Andrey V. Chudin, [chudin att yandex dott ru]
Portions created by Andrey V. Chudin are Copyright (C) 2003 Andrey V. Chudin.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
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:
-----------------------------------------------------------------------------}
// $Id: JvgInspectorGrid.pas,v 1.20 2005/02/17 10:21:20 marquardt Exp $
unit JvgInspectorGrid;
{$I jvcl.inc}
interface
uses
{$IFDEF USEJVCL}
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$ENDIF USEJVCL}
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, StdCtrls, ExtCtrls,
JvgStringGrid, JvgTypes, JvgCommClasses;
type
TJvgGridItem = class(TCollectionItem)
private
FCaption: string;
FEditMask: string;
FOriginalValues: TStringList;
FValues: TStringList;
FExpanded: Boolean;
FSelected: Boolean;
FSequence: Integer;
FRow: Integer;
procedure SetCaption(const Value: string);
procedure SetExpanded(Value: Boolean);
procedure SetSelected(Value: Boolean);
procedure SetChanged(Value: Boolean);
function GetChanged: Boolean;
procedure OnValuesChange(Sender: TObject);
procedure Undo(Index: Integer);
procedure UndoAll;
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
function GetValue: string;
procedure SetValue(ValueIndex: Integer; const Value: string);
function IsChanged(ValueIndex: Integer): Boolean;
property OriginalValues: TStringList read FOriginalValues write FOriginalValues;
property EditMask: string read FEditMask write FEditMask;
property Sequence: Integer read FSequence write FSequence;
property Row: Integer read FRow write FRow;
published
property Caption: string read FCaption write SetCaption;
property Values: TStringList read FValues write FValues;
property Expanded: Boolean read FExpanded write SetExpanded;
property Selected: Boolean read FSelected write SetSelected;
property HasChanged: Boolean read GetChanged write SetChanged;
end;
TJvgGridItems = class(TCollection)
private
FOnUpdate: TNotifyEvent;
FShowMultiValues: Boolean;
function GetItem(Index: Integer): TJvgGridItem;
procedure SetItem(Index: Integer; Value: TJvgGridItem);
procedure SetShowMultiValues(Value: Boolean);
protected
procedure Update(Item: TCollectionItem); override;
property ShowMultiValues: Boolean read FShowMultiValues write SetShowMultiValues;
public
constructor Create(ItemClass: TCollectionItemClass);
function Add: TJvgGridItem;
function Insert(Index: Integer): TJvgGridItem;
property Items[Index: Integer]: TJvgGridItem read GetItem write SetItem; default;
property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
published
end;
TJvgInspectorGrid = class(TJvgStringGrid)
private
FItems: TJvgGridItems;
procedure ItemsUpdate(Sender: TObject);
protected
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
function CanEditModify: Boolean; override;
// function GetEditText(ACol, ARow: Longint): String; override;
function SelectCell(ACol, ARow: Longint): Boolean; override;
function GetEditMask(ACol, ARow: Longint): string; override;
procedure DrawButton(ARow: Longint; Expanded: Boolean);
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure KeyPress(var Key: Char); override;
procedure GetCellStyle(Sender: TObject; var ACol, ARow: Integer; var Style: TglGridCellStyle); override;
procedure GetCellGradientParams(Sender: TObject; ACol, ARow: Longint; var CellRect: TRect; var Gradient:
TJvgGradient); override;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure UndoCurent;
procedure UndoAll;
property Items: TJvgGridItems read FItems write FItems;
function RowToItem(ARow: Integer): TJvgGridItem;
function ItemToRow(Item: TJvgGridItem): Integer;
end;
{$IFDEF USEJVCL}
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvgInspectorGrid.pas,v $';
Revision: '$Revision: 1.20 $';
Date: '$Date: 2005/02/17 10:21:20 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
{$ENDIF USEJVCL}
implementation
uses
JvgUtils;
//=== { TJvgGridItems } ======================================================
constructor TJvgGridItems.Create(ItemClass: TCollectionItemClass);
begin
inherited Create(ItemClass);
FShowMultiValues := True;
end;
function TJvgGridItems.Add: TJvgGridItem;
begin
Result := TJvgGridItem(inherited Add);
end;
function TJvgGridItems.GetItem(Index: Integer): TJvgGridItem;
begin
Result := TJvgGridItem(inherited Items[Index]);
end;
function TJvgGridItems.Insert(Index: Integer): TJvgGridItem;
begin
Result := TJvgGridItem(inherited Insert(Index));
end;
procedure TJvgGridItems.SetItem(Index: Integer; Value: TJvgGridItem);
begin
Items[Index].Assign(Value);
end;
procedure TJvgGridItems.SetShowMultiValues(Value: Boolean);
begin
if FShowMultiValues <> Value then
begin
FShowMultiValues := Value;
if Assigned(FOnUpdate) then
FOnUpdate(Self);
end;
end;
procedure TJvgGridItems.Update(Item: TCollectionItem);
begin
inherited Update(Item);
if Assigned(FOnUpdate) then
FOnUpdate(Self);
end;
//=== { TJvgGridItem } =======================================================
constructor TJvgGridItem.Create(Collection: TCollection);
begin
// (rom) moved inherited up
inherited Create(Collection);
FValues := TStringList.Create;
FOriginalValues := TStringList.Create;
FValues.OnChange := OnValuesChange;
end;
destructor TJvgGridItem.Destroy;
begin
FValues.Free;
FOriginalValues.Free;
inherited Destroy;
end;
function TJvgGridItem.GetChanged: Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to FValues.Count - 1 do
Result := Result or (FValues.Objects[I] <> nil);
end;
function TJvgGridItem.GetValue: string;
var
I: Integer;
begin
Result := '';
if Values.Count = 0 then
Result := ''
else
if (Values.Count = 1) or (not (Collection as TJvgGridItems).ShowMultiValues) then
Result := Values[0]
else
for I := 0 to Values.Count - 1 do
Result := Result + IIF(I = 0, '[', '') + IIF(I > 0, ',', '') + Values[I] + IIF(I = Values.Count - 1, ']', '');
end;
function TJvgGridItem.IsChanged(ValueIndex: Integer): Boolean;
begin
if ValueIndex > 0 then
Dec(ValueIndex);
Result := Values.Objects[ValueIndex] <> nil;
end;
procedure TJvgGridItem.OnValuesChange(Sender: TObject);
var
I: Integer;
begin
while FOriginalValues.Count > FValues.Count do
FOriginalValues.Delete(FOriginalValues.Count - 1);
for I := 0 to FValues.Count - 1 do
if I = FOriginalValues.Count then
FOriginalValues.Add(FValues[I])
else
if FOriginalValues.Objects[I] = nil then
FOriginalValues.Objects[I] := Pointer(Ord(True));
(Collection as TJvgGridItems).Update(Self);
end;
procedure TJvgGridItem.SetCaption(const Value: string);
begin
if FCaption <> Value then
begin
FCaption := Value;
(Collection as TJvgGridItems).Update(Self);
end;
end;
procedure TJvgGridItem.SetChanged(Value: Boolean);
begin
Values.OnChange := nil;
if Sequence > 0 then
Values.Objects[Sequence - 1] := Pointer(Ord(True))
else
Values.Objects[Sequence] := Pointer(Ord(True));
Values.OnChange := OnValuesChange;
end;
procedure TJvgGridItem.SetExpanded(Value: Boolean);
begin
if FExpanded <> Value then
begin
FExpanded := Value and (Values.Count > 1);
(Collection as TJvgGridItems).Update(Self);
end;
end;
procedure TJvgGridItem.SetSelected(Value: Boolean);
begin
if FSelected <> Value then
begin
FSelected := Value;
// (Collection as TJvgGridItems).Update(Self);
end;
end;
procedure TJvgGridItem.SetValue(ValueIndex: Integer; const Value: string);
var
Seq: Integer;
begin
if (Sequence = 0) and (FValues.Count > 1) then
Exit;
if Sequence > 0 then
Seq := Sequence - 1
else
Seq := Sequence;
if Values[Seq] <> Value then
begin
FValues.OnChange := nil;
FValues[Seq] := Value;
FValues.Objects[Seq] := Pointer(Integer(Value <> FOriginalValues[Seq]));
FValues.OnChange := OnValuesChange;
// FChanged := False;
end;
end;
procedure TJvgGridItem.Undo(Index: Integer);
begin
FValues[Index] := FOriginalValues[Index];
FValues.Objects[Index] := Pointer(Integer(FValues[Index] <> FOriginalValues[Index]));
end;
procedure TJvgGridItem.UndoAll;
var
I: Integer;
begin
FValues.OnChange := nil;
for I := 0 to FValues.Count - 1 do
Undo(I);
FValues.OnChange := OnValuesChange;
OnValuesChange(Self);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -