1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
unit GridEx;
interface
Uses Messages, Grids, Classes, Controls, StdCtrls;
Type
TGetEditStyleEvent = Procedure (Sender : TObject; ACol, ARow : Integer; VAR AStyle : TEditStyle) of Object;
TGetPickListItemsEvent = Procedure (Sender : TObject; ACol, ARow : Integer; AList : TStrings) of Object;
TEditButtonClickEvent = Procedure (Sender : TObject; ACol, ARow : Integer; VAR Value : String) of Object;
TCellChangeEvent = Procedure (Sender : TObject; ACol, ARow : Integer; Value : String) of Object;
TInplaceEditListEx = Class(TInplaceEditList)
Private
FOnKillFocus : TNotifyEvent;
Protected
Procedure DoKillFocus;
procedure WndProc(var Message: TMessage); override;
Published
Property OnKillFocus : TNotifyEvent Read FOnKillFocus Write FOnKillFocus;
end;
TStringGridEx = Class(TStringGrid)
Private
_InplaceList : TInplaceEditListEx;
_Cellchange : Boolean;
FOnGetEditStyle : TGetEditStyleEvent;
FOnGetPickListItems : TGetPickListItemsEvent;
FOnEditButtonClick : TEditButtonClickEvent;
FOnCellChange : TCellChangeEvent;
Procedure InplaceListGetPickListItems(ACol, ARow : Integer; AList : TStrings);
Procedure InplaceListEditButtonClick(Sender : TObject);
Procedure InplaceListEditKillFocus(Sender : TObject);
Protected
Function CreateEditor: TInplaceEdit; Override;
Function GetEditStyle(ACol, ARow: Longint): TEditStyle; Override;
Procedure DoGetEditStyle(ACol, ARow : Integer; VAR AStyle : TEditStyle); Virtual;
Procedure DoCellChange; Virtual;
Procedure DoExit; Override;
Public
Constructor Create(AOwner : TComponent); Override;
Procedure AddPickListItem(AString : String);
Procedure ClearPickList;
Published
Property OnGetEditStyle : TGetEditStyleEvent Read FOnGetEditStyle Write FOnGetEditStyle;
Property OnGetPickListItems : TGetPickListItemsEvent Read FOnGetPickListItems Write FOnGetPickListItems;
Property OnEditButtonClick : TEditButtonClickEvent Read FOnEditButtonClick Write FOnEditButtonClick;
Property OnCellChange : TCellChangeEvent Read FOnCellChange Write FOnCellChange;
End;
implementation
Uses Dialogs, Windows;
{==============================================================================}
{ TInplaceEditListEx :: Methodes Protected }
{==============================================================================}
PRocedure TInplaceEditListEx.WndProc(var Message: TMessage);
Begin
Inherited WndProc(Message);
Case MEssage.Msg of
WM_KillFocus : Self.DoKillFocus;
End;
End;
{==============================================================================}
{==============================================================================}
Procedure TInplaceEditListEx.DoKillFocus;
Begin
If Assigned(Self.FOnKillFocus) Then Self.FOnKillFocus(Self);
End;
{==============================================================================}
{ TStringGridEx :: Constructeur / Destructeur }
{==============================================================================}
Constructor TStringGridEx.Create(AOwner : TComponent);
Begin
Inherited Create(AOwner);
self._Cellchange := False;
End;
{==============================================================================}
{ TStringGridEx :: Methodes Privées }
{==============================================================================}
Procedure TStringGridEx.InplaceListGetPickListItems(ACol, ARow : Integer; AList : TStrings);
Begin
If Self._InplaceList.EditStyle <> esPickList then Exit;
If Assigned(Self.FOnGetPickListItems) then Self.FOnGetPickListItems(Self, ACol, ARow, AList);
End;
{==============================================================================}
{==============================================================================}
Procedure TStringGridEx.InplaceListEditButtonClick(Sender : TObject);
Var Value : String;
Begin
If Self._InplaceList.EditStyle <> esEllipsis then Exit;
If Not Assigned(Self.FonEditButtonClick) Then Exit;
Value := Self.Cells[Self.Col, Self.Row];
Self.FOnEditButtonClick(Sender, Self.Col, Self.Row, Value);
Self._InplaceList.Text := Value;
end;
{==============================================================================}
{==============================================================================}
Procedure TStringGridEx.InplaceListEditKillFocus(Sender : TObject);
Begin
If Self._InplaceList.Visible then Exit;
Self.EditorMode := false;
Self.DoCellChange;
End;
{==============================================================================}
{ TStringGridEx :: Methodes Protected }
{==============================================================================}
Function TStringGridEx.CreateEditor : TInplaceEdit;
Begin
Self._InplaceList := TInplaceEditListEx.Create(Self);
Self._InplaceList.OnGetPickListitems := Self.InplaceListGetPickListItems;
Self._InplaceList.OnEditButtonClick := Self.InplaceListEditButtonClick;
Self._InplaceList.OnKillFocus := Self.InplaceListEditKillFocus;
Result := Self._InplaceList;
End;
{==============================================================================}
{==============================================================================}
Function TStringGridEx.GetEditStyle(ACol, ARow: Longint): TEditStyle;
Begin
Result := Inherited GetEditStyle(aCol, ARow);
Self.DoGetEditStyle(ACol, ARow, Result);
End;
{==============================================================================}
{==============================================================================}
Procedure TStringGridEx.DoGetEditStyle(ACol, ARow: Longint; VAR AStyle : TEditStyle);
Begin
If Assigned(Self.FOnGetEditStyle) Then
Self.FOnGetEditStyle(Self, ACol, ARow, AStyle);
End;
{==============================================================================}
{==============================================================================}
Procedure TStringGridEx.DoCellChange;
Begin
If Assigned(Self.FOnCellChange) Then
Self.FOnCellChange(Self, Self.Col, Self.Row, Self.Cells[col, Row]);
End;
{==============================================================================}
{==============================================================================}
Procedure TStringGridEx.DoExit;
Begin
If Self.EditorMode Then Self.DoCellChange;
Inherited DoExit;
End;
{==============================================================================}
{TStringGridEx :: Methodes Public }
{==============================================================================}
Procedure TStringGridEx.AddPickListItem(AString : String);
Begin
Self._InplaceList.PickList.Items.Add(AString);
End;
{==============================================================================}
{==============================================================================}
Procedure TStringGridEx.ClearPickList;
Begin
Self._InplaceList.PickList.Clear;
End; |