grids patch from Jesus for painting

git-svn-id: trunk@3796 -
This commit is contained in:
mattias 2003-01-09 07:42:58 +00:00
parent a05e851b0e
commit a8cf6d44d0
2 changed files with 329 additions and 219 deletions

View File

@ -27,8 +27,8 @@
Author: Mattias Gaertner Author: Mattias Gaertner
Abstract: Abstract:
The TClipBoardHistory form a front end for clipboard history, which stores The TClipBoardHistory form is a frontend for the clipboard history, which
the texts of the last copy to clipboard actions. stores the texts of the last "copy to clipboard" actions.
ToDo: ToDo:
Everything. Everything.

View File

@ -16,6 +16,36 @@ This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
VERSION: 0.8.3
---------------
CHANGES - Better Editor Support
Renamed Editor functions
Editors uses .Dispatch instead of .Perform
Introduced EditorOptions:
EO_AUTOSIZE = Let the grid automatically resize the editor
EO_HOOKKEYS = Let the grid process known keydows first
EO_HOOKEXIT = Let the grid handle the focus
EO_SELECTALL = Editor wants to receive SelectAll msg on Key RETURN
EO_WANTCHAR = Editor wants to Preview Keys on the grid (soon)
EO_GETSETVAL = Editor wants to receive GetValue,SetValue msgs (soon)
This Options should be set in GM_SETGRID message (msg.Options:= ..)
- Deleted Scr1 Conditional
FIXES Painting and Crashes at desing time
TODOS Better editor Support
TCustomgrid Inherited from TCustomControl to get rid of
- published VertScrollBar
- published HorzScrollBar
- published AutoScroll
- translucid look at design time?
Detect ReadOnly grid in editors
Detect changes in the grid.
Column Resizing at design time
...
VERSION: 0.8.2 VERSION: 0.8.2
--------------- ---------------
CHANGES Demo Program CHANGES Demo Program
@ -185,9 +215,11 @@ Const
GRIDFILEVERSION = 2; // Introduced goSmoothScroll GRIDFILEVERSION = 2; // Introduced goSmoothScroll
Const Const
GM_SETVALUE = LM_USER + 100; GM_SETVALUE = LM_USER + 100;
GM_GETVALUE = LM_USER + 101; GM_GETVALUE = LM_USER + 101;
GM_SETGRID = LM_USER + 102; GM_SETGRID = LM_USER + 102;
GM_SETPOS = LM_USER + 103;
GM_SELECTALL = LM_USER + 104;
Const Const
CA_LEFT = $1; CA_LEFT = $1;
@ -197,6 +229,13 @@ Const
CL_CENTER = $10; CL_CENTER = $10;
CL_BOTTOM = $20; CL_BOTTOM = $20;
Const
EO_AUTOSIZE = $1;
EO_HOOKKEYS = $2;
EO_HOOKEXIT = $4;
EO_SELECTALL = $8;
EO_WANTCHAR = $10;
Type Type
EGridException = class(Exception); EGridException = class(Exception);
@ -263,9 +302,12 @@ Type
PGridMessage=^TGridMessage; PGridMessage=^TGridMessage;
TGridMessage=Record TGridMessage=Record
MsgID: Cardinal;
Grid: TCustomGrid; Grid: TCustomGrid;
Col,Row: Integer; Col,Row: Integer;
Value: String; Value: String;
CellRect: TRect;
Options: Integer;
End; End;
{ Default cell editor for TStringGrid } { Default cell editor for TStringGrid }
@ -273,11 +315,11 @@ Type
Private Private
FGrid: TCustomGrid; FGrid: TCustomGrid;
Protected Protected
Procedure doExit; Override;
procedure KeyDown(var Key : Word; Shift : TShiftState); Override; procedure KeyDown(var Key : Word; Shift : TShiftState); Override;
Procedure msg_SetValue(Var Msg: TLMessage); Message GM_SETVALUE; Procedure msg_SetValue(Var Msg: TGridMessage); Message GM_SETVALUE;
Procedure msg_GetValue(Var Msg: TLMessage); Message GM_GETVALUE; Procedure msg_GetValue(Var Msg: TGridMessage); Message GM_GETVALUE;
Procedure msg_SetGrid(Var Msg: TLMessage); Message GM_SETGRID; Procedure msg_SetGrid(Var Msg: TGridMessage); Message GM_SETGRID;
Procedure msg_SelectAll(Var Msg: TGridMessage); MEssage GM_SELECTALL;
End; End;
@ -386,6 +428,7 @@ Type
FUpdateCount: Integer; FUpdateCount: Integer;
FUpdateScrollBarsCount: Integer; FUpdateScrollBarsCount: Integer;
FFocusing: Boolean;
// Cached Values // Cached Values
@ -487,6 +530,7 @@ Type
procedure KeyDown(var Key : Word; Shift : TShiftState); Override; procedure KeyDown(var Key : Word; Shift : TShiftState); Override;
procedure KeyUp(var Key : Word; Shift : TShiftState); Override; procedure KeyUp(var Key : Word; Shift : TShiftState); Override;
Procedure LoadContent(cfg: TXMLConfig); Virtual; Procedure LoadContent(cfg: TXMLConfig); Virtual;
procedure Loaded; override;
Procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override; Procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
Procedure MouseMove(Shift: TShiftState; X,Y: Integer);Override; Procedure MouseMove(Shift: TShiftState; X,Y: Integer);Override;
Procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override; Procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
@ -506,16 +550,22 @@ Type
Protected Protected
FEditorHiding: Boolean; FEditorHiding: Boolean;
FEditorKey: Boolean; FEditorKey: Boolean;
Procedure CancelEditor; Virtual; FEditorOptions: Integer;
Procedure GetEditorValue; Virtual; Procedure EditorCancel; Virtual;
Procedure HideEditor; Procedure EditorGetValue;
Procedure SetEditorValue; Virtual; Procedure EditorHide;
Procedure ShowEditor; Procedure EditorSetValue;
Procedure PosEditor; Procedure EditorShow;
Procedure ExitEditor(Sender: TWinControl); Procedure EditorPos;
procedure EditorKeyDown(var Key : Word; Shift : TShiftState); Procedure EditorReset;
Procedure EditorSelectAll;
Procedure doEditorGetValue; Virtual;
Procedure doEditorSetValue; Virtual;
Public
Procedure EditorExit(Sender: TObject);
procedure EditorKeyDown(Sender: TObject; var Key:Word; Shift:TShiftState);
Protected
Property AutoAdvance: TAutoAdvance Read FAutoAdvance Write FAutoAdvance default aaRight; Property AutoAdvance: TAutoAdvance Read FAutoAdvance Write FAutoAdvance default aaRight;
Property ColWidths[aCol: Integer]: Integer Read GetColWidths Write SetColWidths; Property ColWidths[aCol: Integer]: Integer Read GetColWidths Write SetColWidths;
Property ColCount: Integer Read GetColCount Write SetColCount; Property ColCount: Integer Read GetColCount Write SetColCount;
@ -658,6 +708,8 @@ Type
Property CellAlign[ACol,ARow: Integer]: Integer read GetCellAlign write SetCellAlign; Property CellAlign[ACol,ARow: Integer]: Integer read GetCellAlign write SetCellAlign;
Property DefaultCellAttr: TCellAttr read fDefCellAttr write SetDefaultCellAttr; Property DefaultCellAttr: TCellAttr read fDefCellAttr write SetDefaultCellAttr;
Property Editor;
property Col; property Col;
property ColWidths; property ColWidths;
//property EditorMode; //property EditorMode;
@ -737,8 +789,8 @@ Type
Procedure AutoAdjustColumn(aCol: Integer); Override; Procedure AutoAdjustColumn(aCol: Integer); Override;
Procedure CalcCellExtent(acol, aRow: Integer; Var aRect: TRect); Override; Procedure CalcCellExtent(acol, aRow: Integer; Var aRect: TRect); Override;
Procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); Override; Procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); Override;
Procedure GetEditorValue; Override; Procedure doEditorGetValue; Override;
Procedure SetEditorValue; Override; Procedure doEditorSetValue; Override;
Procedure SaveContent(cfg: TXMLConfig); Override; Procedure SaveContent(cfg: TXMLConfig); Override;
Procedure LoadContent(cfg: TXMLConfig); Override; Procedure LoadContent(cfg: TXMLConfig); Override;
Procedure DrawInteriorCells; Override; Procedure DrawInteriorCells; Override;
@ -943,11 +995,32 @@ Begin
End; End;
procedure TCustomGrid.SetEditor(const AValue: TWinControl); procedure TCustomGrid.SetEditor(const AValue: TWinControl);
Var
Msg: TGridMessage;
begin begin
if FEditor=AValue then exit; if Not(goEditing in Options) or (FEditor=AValue) then exit;
FEditor:=AValue; FEditor:=AValue;
if FEditor<>nil Then Begin if FEditor<>nil Then Begin
FEditor.Perform(GM_SETGRID, LongInt(Self), 0); Msg.MsgID:=GM_SETGRID;
Msg.Grid:=Self;
Msg.Options:=0;
FEditor.Dispatch(Msg);
FEditorOptions:=Msg.Options;
If Msg.Options And EO_HOOKKEYS = EO_HOOKKEYS Then begin
FEditor.OnKeyDown:=@EditorKeyDown;
End;
If Msg.Options And EO_HOOKEXIT = EO_HOOKEXIT Then begin
FEditor.OnExit:=@EditorExit;
End;
{$IfDef EditorDbg}
Write('SetEditor-> Editor=',FEditor.Name,' ');
If FEditorOptions And EO_AUTOSIZE = EO_AUTOSIZE Then Write('EO_AUTOSIZE ');
If FEditorOptions And EO_HOOKKEYS = EO_HOOKKEYS Then Write('EO_HOOKKEYS ');
If FEditorOptions And EO_HOOKEXIT = EO_HOOKEXIT Then Write('EO_HOOKEXIT ');
if FEditorOptions And EO_SELECTALL= EO_SELECTALL Then Write('EO_SELECTALL ');
if FEditorOptions And EO_WANTCHAR = EO_WANTCHAR Then Write('EO_WANTCHAR ');
WriteLn;
{$Endif}
End; End;
end; end;
@ -992,6 +1065,11 @@ begin
FOptions:=FOptions - [goAlwaysShowEditor]; FOptions:=FOptions - [goAlwaysShowEditor];
End End
Else FRange:=Rect(FCol,FRow,FCol,FRow); Else FRange:=Rect(FCol,FRow,FCol,FRow);
If goAlwaysShowEditor in Options Then begin
EditorShow;
End Else begin
EditorHide;
End;
VisualChange; VisualChange;
end; end;
@ -1399,7 +1477,8 @@ end;
procedure TCustomGrid.TopLeftChanged; procedure TCustomGrid.TopLeftChanged;
begin begin
If Assigned(OnTopLeftChange) Then OnTopLeftChange(Self); If Assigned(OnTopLeftChange) And Not (csDesigning in ComponentState) Then
OnTopLeftChange(Self);
end; end;
procedure TCustomGrid.HeaderClick(IsColumn: Boolean; Index: Integer); procedure TCustomGrid.HeaderClick(IsColumn: Boolean; Index: Integer);
@ -1587,8 +1666,13 @@ begin
If (ARow=FRow) And If (ARow=FRow) And
(IsCellVisible(FCol,ARow) Or (Rs And (ARow>=Top) And (ARow<=Bottom))) (IsCellVisible(FCol,ARow) Or (Rs And (ARow>=Top) And (ARow<=Bottom)))
Then Begin Then Begin
ColRowToOffset(True, True, FCol, R.Left, R.Right); If (goEditing in Options)And(goAlwaysShowEditor in Options)And
DrawFocusRect(FCol,FRow, R{ColRowToClienTCellRect(FCol,FRow)}, [gdFocused]); (Editor<>nil) Then begin
//WriteLn('No Draw Focus Rect');
End Else begin
ColRowToOffset(True, True, FCol, R.Left, R.Right);
DrawFocusRect(FCol,FRow, R{ColRowToClienTCellRect(FCol,FRow)}, [gdFocused]);
End;
End; End;
End; // Else Begin End; // Else Begin
@ -1747,19 +1831,6 @@ end;
// NOTE: WMHScroll and VMHScroll // NOTE: WMHScroll and VMHScroll
// This methods are used to pre-calculate the scroll position // This methods are used to pre-calculate the scroll position
// //
{$IFDEF Scr1}
{
-- This is the original 'row' scroll method
-- in WMHScroll.Pos arrives a value from 0 .. [Max TopLeft Column]-FixedCols
-- in WMVScroll.Pos arrives a value from 0 .. [Max TopLeft Row ]-FixedRows
-- Scrollbar sizes are not proportional :(
}
{$ELSE}
{
-- This is the new 'not so pixel' scroll method,
}
{$Endif}
procedure TCustomGrid.WMHScroll(var Message: TLMHScroll); procedure TCustomGrid.WMHScroll(var Message: TLMHScroll);
Var Var
C,Tl: Integer; C,Tl: Integer;
@ -1775,47 +1846,36 @@ begin
WriteLn('HSCROLL: Code=',Message.ScrollCode,' Position=', Message.Pos); WriteLn('HSCROLL: Code=',Message.ScrollCode,' Position=', Message.Pos);
{$Endif} {$Endif}
If FGCache.HScrDiv<=0 Then Exit;
If FEditor<>nil then EditorGetValue;
{$IfDef Scr1} If goThumbTracking in Options Then Begin
TL:=FFixedCols+ Message.Pos; C:=FFixedCols + Round( Message.Pos * FGCache.HScrDiv );
If FEditor<>nil then getEditorValue; If (FCol<>C) Then begin
Inc(FUpdateScrollBarsCount); Inc(FUpdateScrollBarsCount);
TryScrollTo(Tl, FTopLeft.Y); MoveExtend(False, C, FRow);
Dec(FUpdateScrollBarsCount); Dec(FUpdateScrollBarsCount);
Message.Result:=1;
{$Else}
If FGCache.HScrDiv<=0 Then Exit;
If FEditor<>nil then getEditorValue;
If goThumbTracking in Options Then Begin
C:=FFixedCols + Round( Message.Pos * FGCache.HScrDiv );
If (FCol<>C) Then begin
Inc(FUpdateScrollBarsCount);
MoveExtend(False, C, FRow);
Dec(FUpdateScrollBarsCount);
End;
End Else begin
C:=Message.Pos+FGCache.FixedWidth;
TL:=OffsetToColRow(True, False, C, FGCache.TLColOff);
{$Ifdef dbgScroll}
WriteLn('---- Offset=',C, ' TL=',TL, ' TLColOFf=', FGCache.TLColOff);
{$Endif}
If Not (goSmoothScroll in Options) then FGCache.TLColOff:=0;
If TL<>FTopLeft.X Then begin
Inc(FUpdateScrollBarsCount);
TryScrollTo(Tl, FTopLeft.Y);
Dec(FUpdateScrollBarsCount);
End Else
If goSmoothScroll in Options Then begin
CacheVisibleGrid;
Invalidate;
End;
End; End;
{$Endif} End Else begin
C:=Message.Pos+FGCache.FixedWidth;
TL:=OffsetToColRow(True, False, C, FGCache.TLColOff);
{$Ifdef dbgScroll}
WriteLn('---- Offset=',C, ' TL=',TL, ' TLColOFf=', FGCache.TLColOff);
{$Endif}
If Not (goSmoothScroll in Options) then FGCache.TLColOff:=0;
If TL<>FTopLeft.X Then begin
Inc(FUpdateScrollBarsCount);
TryScrollTo(Tl, FTopLeft.Y);
Dec(FUpdateScrollBarsCount);
End Else
If goSmoothScroll in Options Then begin
CacheVisibleGrid;
Invalidate;
End;
End;
end; end;
procedure TCustomGrid.WMVScroll(var Message: TLMVScroll); procedure TCustomGrid.WMVScroll(var Message: TLMVScroll);
@ -1834,43 +1894,34 @@ begin
WriteLn('VSCROLL: Code=',Message.ScrollCode,' Position=', Message.Pos); WriteLn('VSCROLL: Code=',Message.ScrollCode,' Position=', Message.Pos);
{$Endif} {$Endif}
If FGCache.VScrDiv<=0 Then Exit;
{$IfDef Scr1} If FEditor<>nil then EditorGetValue;
TL:= Message.pos+FFixedRows; If goThumbTracking in Options Then begin
If FEditor<>nil then getEditorValue; C:=FFixedRows + Round( Message.Pos * FGCache.VScrDiv );
Inc(FUpdateScrollBarsCount); If (C<>FRow) Then begin
TryScrollTo(FtopLeft.x, TL); Inc(FUpdateScrollBarsCount);
Dec(FUpdateScrollBarsCount); MoveExtend(False, FCol, C);
{$Else} Dec(FUpdateScrollBarsCount);
If FGCache.VScrDiv<=0 Then Exit;
If FEditor<>nil then getEditorValue;
If goThumbTracking in Options Then begin
C:=FFixedRows + Round( Message.Pos * FGCache.VScrDiv );
If (C<>FRow) Then begin
Inc(FUpdateScrollBarsCount);
MoveExtend(False, FCol, C);
Dec(FUpdateScrollBarsCount);
End;
End Else begin
C:=Message.Pos+FGCache.Fixedheight;
TL:=OffsetToColRow(False, False, C, FGCache.TLRowOff);
{$Ifdef dbgScroll}
WriteLn('---- Offset=',C, ' TL=',TL, ' TLRowOFf=', FGCache.TLRowOff);
{$Endif}
If Not (goSmoothScroll in Options) Then FGCache.TLRowOff:=0;
If TL<>FTopLeft.Y Then begin
Inc(FUpdateScrollBarsCount);
TryScrollTo(FTopLeft.X, Tl);
Dec(FUpdateScrollBarsCount);
End Else
If goSmoothScroll in Options Then begin
CacheVisibleGrid;
Invalidate;
End;
End; End;
{$Endif} End Else begin
C:=Message.Pos+FGCache.Fixedheight;
TL:=OffsetToColRow(False, False, C, FGCache.TLRowOff);
{$Ifdef dbgScroll}
WriteLn('---- Offset=',C, ' TL=',TL, ' TLRowOFf=', FGCache.TLRowOff);
{$Endif}
If Not (goSmoothScroll in Options) Then FGCache.TLRowOff:=0;
If TL<>FTopLeft.Y Then begin
Inc(FUpdateScrollBarsCount);
TryScrollTo(FTopLeft.X, Tl);
Dec(FUpdateScrollBarsCount);
End Else
If goSmoothScroll in Options Then begin
CacheVisibleGrid;
Invalidate;
End;
End;
end; end;
procedure TCustomGrid.WMSize(var Msg: TWMSize); procedure TCustomGrid.WMSize(var Msg: TWMSize);
@ -1903,47 +1954,26 @@ end;
procedure TCustomGrid.UpdateScrollbarPos(Which: TControlScrollbar); procedure TCustomGrid.UpdateScrollbarPos(Which: TControlScrollbar);
begin begin
// Adjust ScrollBar Positions // Adjust ScrollBar Positions
{$IfDef Scr1} // Special condition only When scrolling by draging
Write('UptateScrollbarPos: Scr1 - '); // the scrollbars see: WMHScroll and WVHScroll
If (FScrollBars in [ssAutoHorizontal, ssAutoBoth]) And If FUpdateScrollBarsCount=0 Then begin
HorzScrolLBar.Visible Then begin
I:=fTopLeft.X-FFixedCols;
{$IfDef dbgScroll}
Write('HorzScrollBar Pos=', I);
{$Endif}
HorzScrolLBar.Position:=I;
End;
If (FScrolLBars in [ssAutoVertical, ssAutoBoth]) And
VertScrolLBar.Visible Then Begin
I:=fTopLeft.Y-FFixedRows;
{$IfDef dbgScroll}
Write(' VertScrollBar Pos=', I);
{$Endif}
VertScrolLBar.Position:=I;
End;
WriteLn(' Done');
{$Else Scr1}
// Special condition only When scrolling by draging
// the scrollbars see: WMHScroll and WVHScroll
If FUpdateScrollBarsCount=0 Then begin
if (Which=HorzScrollBar)or(Which=nil) Then if (Which=HorzScrollBar)or(Which=nil) Then
If (FScrollBars in [ssAutoHorizontal, ssAutoBoth]) And If (FScrollBars in [ssAutoHorizontal, ssAutoBoth]) And
HorzScrolLBar.Visible Then begin HorzScrolLBar.Visible Then begin
With FGCache do With FGCache do
HorzScrollBar.Position:= HorzScrollBar.Position:=
Integer(AccumWidth[FTopLeft.x])-TLColOff-FixedWidth; Integer(AccumWidth[FTopLeft.x])-TLColOff-FixedWidth;
End; End;
If (Which=VertScrollBar)Or(Which=nil) Then If (Which=VertScrollBar)Or(Which=nil) Then
If (FScrolLBars in [ssAutoVertical, ssAutoBoth]) And If (FScrolLBars in [ssAutoVertical, ssAutoBoth]) And
VertScrolLBar.Visible Then begin VertScrolLBar.Visible Then begin
With FGCache do With FGCache do
VertScrollBar.Position:= VertScrollBar.Position:=
Integer(AccumHeight[FTopLeft.y])-TLRowOff-FixedHeight; Integer(AccumHeight[FTopLeft.y])-TLRowOff-FixedHeight;
End; End;
End; {If FUpd...} End; {If FUpd...}
{$Endif}
end; end;
procedure TCustomGrid.CheckFixedCount(aCol,aRow,aFCol,aFRow: Integer); procedure TCustomGrid.CheckFixedCount(aCol,aRow,aFCol,aFRow: Integer);
@ -2382,8 +2412,10 @@ begin
Case fGridState of Case fGridState of
gsSelecting: gsSelecting:
begin begin
P:=MouseToLogcell(Point(X,Y)); If Not (goEditing in Options) Then begin
MoveExtend(False, P.x, P.y); P:=MouseToLogcell(Point(X,Y));
MoveExtend(False, P.x, P.y);
End;
End; End;
gsColMoving: If goColMoving in Options Then doColMoving(X,Y); gsColMoving: If goColMoving in Options Then doColMoving(X,Y);
gsRowMoving: If goRowMoving in Options Then doRowMoving(X,Y); gsRowMoving: If goRowMoving in Options Then doRowMoving(X,Y);
@ -2403,7 +2435,6 @@ begin
inherited MouseUp(Button, Shift, X, Y); inherited MouseUp(Button, Shift, X, Y);
If Not FGCache.ValidGrid Then Exit; If Not FGCache.ValidGrid Then Exit;
Cur:=MouseToCell(Point(x,y)); Cur:=MouseToCell(Point(x,y));
Case fGridState of Case fGridState of
gsSelecting: gsSelecting:
Begin Begin
@ -2458,17 +2489,28 @@ end;
procedure TCustomGrid.doEnter; procedure TCustomGrid.doEnter;
begin begin
inherited doEnter; inherited doEnter;
//If (goEditing in Options)And(goAlwaysShowEditor in Options) Then ShowEditor; If FEditorHiding Then begin
// Self generated doEnter
End Else begin
// Got the focus for some other reason
Invalidate; // redraw the focused cell
// Handle click on focused cell, still needs to show the editor
// when focusing from other way than mouse clicks
FFocusing:=True;
End;
end; end;
procedure TCustomGrid.KeyDown(var Key: Word; Shift: TShiftState); procedure TCustomGrid.KeyDown(var Key: Word; Shift: TShiftState);
Var
Sh: Boolean;
Procedure MoveSel(Rel: Boolean; aCol,aRow: Integer); Procedure MoveSel(Rel: Boolean; aCol,aRow: Integer);
begin begin
// Always reset Offset in kerboard Events // Always reset Offset in kerboard Events
FGCache.TLColOff:=0; FGCache.TLColOff:=0; FGCache.TLRowOff:=0;
FGCache.TLRowOff:=0; SelectActive:=Sh;
SelectActive:=(ssShift in Shift); MoveExtend(Rel,aCol,aRow);
If MoveExtend(Rel, aCol, aRow) Then Key:=0; Key:=0;
End; End;
Var Var
R: TRect; R: TRect;
@ -2476,9 +2518,20 @@ Var
begin begin
inherited KeyDown(Key, Shift); inherited KeyDown(Key, Shift);
If Not FGCache.ValidGrid Then Exit; If Not FGCache.ValidGrid Then Exit;
Sh:=(ssShift in Shift);
Relaxed:=Not (goRowSelect in Options) or (goRelaxedRowSelect in Options); Relaxed:=Not (goRowSelect in Options) or (goRelaxedRowSelect in Options);
If (Key=Vk_TAB)And(goTabs in Options) Then begin
Case FAutoAdvance of
aaRight:
If Sh Then Key:=VK_LEFT
Else Key:=VK_RIGHT;
aaDown:
If Sh Then Key:=VK_UP
Else Key:=VK_DOWN;
End;
End;
Case Key of Case Key of
VK_LEFT: VK_LEFT:
Begin Begin
@ -2522,11 +2575,13 @@ begin
if Relaxed Then MoveSel(False, ColCount-1, FRow) if Relaxed Then MoveSel(False, ColCount-1, FRow)
Else MoveSel(False, FCol, RowCount-1); Else MoveSel(False, FCol, RowCount-1);
End; End;
VK_F2: VK_F2, VK_RETURN:
begin begin
ShowEditor; EditorShow;
If Key=VK_RETURN Then EditorSelectAll;
Key:=0; Key:=0;
End; End;
{$IfDef Dbg} {$IfDef Dbg}
Else WriteLn('KeyDown: ', Key); Else WriteLn('KeyDown: ', Key);
{$Endif} {$Endif}
@ -2644,14 +2699,24 @@ begin
If dRow>RowCount-1 Then dRow:=RowCount-1; If dRow>RowCount-1 Then dRow:=RowCount-1;
// Change on Focused cell? // Change on Focused cell?
If (Dcol=FCol)And(DRow=FRow) Then Exit; If (Dcol=FCol)And(DRow=FRow) Then begin
If FFocusing
And(goEditing in Options)
And(goAlwaysShowEditor In Options)
And(EDitor<>nil) Then Begin
EditorShow;
End;
FFocusing:=False;
Exit;
End;
FFocusing:=False;
Result:=True; Result:=True;
if Assigned(OnBeforeSelection) Then OnBeforeSelection(Self, DCol, DRow, Result); if Assigned(OnBeforeSelection) Then OnBeforeSelection(Self, DCol, DRow, Result);
If Not Result Then Exit; If Not Result Then Exit;
// Going to change selection, get editor value before that // Going to change selection, get editor value before that
GetEditorValue; EditorGetValue;
// default range // default range
If goRowSelect in Options Then FRange:=Rect(FFixedCols, DRow, Colcount-1, DRow) If goRowSelect in Options Then FRange:=Rect(FFixedCols, DRow, Colcount-1, DRow)
@ -2687,7 +2752,7 @@ begin
if //Not SelectActive And if //Not SelectActive And
(goEditing in Options) And (goEditing in Options) And
(goAlwaysShowEditor in Options) And (goAlwaysShowEditor in Options) And
Not(goRowSelect in Options) Then ShowEditor; Not(goRowSelect in Options) Then EditorShow;
end; end;
procedure TCustomGrid.MoveSelection; procedure TCustomGrid.MoveSelection;
@ -2746,20 +2811,23 @@ begin
inherited Invalidate; inherited Invalidate;
end; end;
procedure TCustomGrid.GetEditorValue; procedure TCustomGrid.EditorGetValue;
begin begin
If Not (csDesigning in ComponentState) Then begin If Not (csDesigning in ComponentState) Then begin
HideEditor; EditorHide;
doEditorGetValue;
End; End;
end; end;
procedure TCustomGrid.SetEditorValue; procedure TCustomGrid.EditorSetValue;
begin begin
If Not (csDesigning in ComponentState) Then If Not (csDesigning in ComponentState) Then begin
PosEditor; EditorPos;
doEditorSetValue;
End;
end; end;
procedure TCustomGrid.HideEditor; procedure TCustomGrid.EditorHide;
begin begin
if (Editor<>nil) And Editor.HandleAllocated And Editor.Visible Then begin if (Editor<>nil) And Editor.HandleAllocated And Editor.Visible Then begin
If Not FEditorHiding Then begin If Not FEditorHiding Then begin
@ -2772,36 +2840,71 @@ begin
End; End;
end; end;
procedure TCustomGrid.ShowEditor; procedure TCustomGrid.EditorShow;
begin begin
If Not (csDesigning in ComponentState)And(goEditing in Options) Then If Not (csDesigning in ComponentState)And(goEditing in Options) Then
If (Editor<>nil) And Not Editor.Visible Then Begin If (Editor<>nil) And Not Editor.Visible Then Begin
ResetOffset(True, True); ResetOffset(True, True);
Editor.Parent:=Self; EditorReset;
SetEditorValue;
Editor.Visible:=True;
LCLLinux.SetFocus(Editor.Handle); LCLLinux.SetFocus(Editor.Handle);
End; End;
end; end;
procedure TCustomGrid.PosEditor; procedure TCustomGrid.EditorPos;
Var Var
R: TRect; msg: TGridMessage;
begin begin
If fEditor<>nil Then begin if FEditor<>nil Then begin
R:=ColRowToClientCellRect(FCol,FRow); Msg.CellRect:=ColRowToClientCellRect(FCol,FRow);
FEditor.SetBounds(R.Left, R.Top, R.Right-R.Left, R.Bottom-R.Top); If FEditorOptions And EO_AUTOSIZE = EO_AUTOSIZE Then begin
With Msg.CellRect do
FEditor.SetBounds(Left, Top, Right-Left, Bottom-Top);
End Else Begin
Msg.MsgID:=GM_SETPOS;
Msg.Grid:=Self;
Msg.Col:=FCol;
Msg.Row:=FRow;
FEditor.Dispatch(Msg);
End;
End; End;
end; end;
procedure TCustomGrid.ExitEditor(Sender: TWinControl); procedure TCustomGrid.EditorReset;
begin
Editor.Parent:=Self;
EditorSetValue;
Editor.Visible:=True;
end;
procedure TCustomGrid.EditorSelectAll;
Var
Msg: TGridMessage;
begin
If FEditor<>nil Then
If FEditorOptions And EO_SELECTALL = EO_SELECTALL Then begin
Msg.MsgID:=GM_SELECTALL;
FEditor.Dispatch(Msg);
End;
end;
procedure TCustomGrid.doEditorGetValue;
begin
//
end;
procedure TCustomGrid.doEditorSetValue;
begin
//
end;
procedure TCustomGrid.EditorExit(Sender: TObject);
begin begin
//WriteLn('Editor is losing the focus..'); //WriteLn('Editor is losing the focus..');
If Not FEditorHiding Then begin If Not FEditorHiding Then begin
// Editor losing focus for any reason // Editor losing focus for any reason
//WriteLn('Hey, What is happening here?'); //WriteLn('Hey, What is happening here?');
FEditorHiding:=True; FEditorHiding:=True;
GetEditorValue; EditorGetValue;
If Editor<>nil Then Begin If Editor<>nil Then Begin
Editor.Visible:=False; Editor.Visible:=False;
Editor.Parent:=nil; Editor.Parent:=nil;
@ -2810,7 +2913,7 @@ begin
End; End;
end; end;
procedure TCustomGrid.EditorKeyDown(var Key: Word; Shift: TShiftState); procedure TCustomGrid.EditorKeyDown(Sender: TObject; var Key:Word; Shift:TShiftState);
begin begin
FEditorKey:=True; // Just a flag to see from where the event comes FEditorKey:=True; // Just a flag to see from where the event comes
Case Key of Case Key of
@ -2831,8 +2934,8 @@ begin
aaDown : Key:=VK_DOWN * Integer( FRow<RowCount-1 ); aaDown : Key:=VK_DOWN * Integer( FRow<RowCount-1 );
End; End;
If Key=0 Then begin If Key=0 Then begin
GetEditorValue; EditorGetValue;
ShowEditor; EditorShow;
// Select All ! // Select All !
End Else KeyDown(Key, Shift); End Else KeyDown(Key, Shift);
End; End;
@ -2840,9 +2943,9 @@ begin
FEditorKey:=False; FEditorKey:=False;
end; end;
procedure TCustomGrid.CancelEditor; procedure TCustomGrid.EditorCancel;
begin begin
HideEditor; EditorHide;
SetFocus; SetFocus;
end; end;
@ -3023,6 +3126,12 @@ begin
end; end;
end; end;
procedure TCustomGrid.Loaded;
begin
inherited Loaded;
VisualChange;
end;
constructor TCustomGrid.Create(AOwner: TComponent); constructor TCustomGrid.Create(AOwner: TComponent);
begin begin
// Inherited create Calls SetBounds->WM_SIZE->VisualChange so // Inherited create Calls SetBounds->WM_SIZE->VisualChange so
@ -3329,42 +3438,37 @@ begin
end; end;
{ TStringCellEditor } { TStringCellEditor }
procedure TStringCellEditor.doExit;
begin
inherited doExit;
FGrid.ExitEditor(Self);
end;
procedure TStringCellEditor.KeyDown(var Key: Word; Shift: TShiftState); procedure TStringCellEditor.KeyDown(var Key: Word; Shift: TShiftState);
begin begin
{$IfDef dbg} {$IfDef dbg}
WriteLn('INI: Key=',Key,' SelStart=',SelStart,' SelLenght=',SelLength); WriteLn('INI: Key=',Key,' SelStart=',SelStart,' SelLenght=',SelLength);
{$Endif} {$Endif}
If FGrid<>nil then Fgrid.EditorKeyDown(Key, Shift); If FGrid<>nil then Fgrid.EditorKeyDown(Self, Key, Shift);
{$IfDef dbg} {$IfDef dbg}
WriteLn('FIN: Key=',Key,' SelStart=',SelStart,' SelLenght=',SelLength); WriteLn('FIN: Key=',Key,' SelStart=',SelStart,' SelLenght=',SelLength);
{$Endif} {$Endif}
inherited KeyDown(Key, Shift); inherited KeyDown(Key, Shift);
end; end;
procedure TStringCellEditor.msg_SetValue(var Msg: TLMessage); procedure TStringCellEditor.msg_SetValue(var Msg: TGridMessage);
begin begin
With PGridMessage(Msg.LParam)^ do begin Text:=Msg.Value;
Text:= Value;
End;
end; end;
procedure TStringCellEditor.msg_GetValue(var Msg: TLMessage); procedure TStringCellEditor.msg_GetValue(var Msg: TGridMessage);
begin begin
With PGridMessage(Msg.LParam)^ do begin Msg.Value:=Text;
Value:=Text;
End;
end; end;
procedure TStringCellEditor.msg_SetGrid(var Msg: TLMessage); procedure TStringCellEditor.msg_SetGrid(var Msg: TGridMessage);
begin begin
FGrid:=TCustomGrid(Msg.WParam); FGrid:=Msg.Grid;
Msg.Options:=EO_AUTOSIZE or EO_HOOKEXIT or EO_SELECTALL;
end;
procedure TStringCellEditor.msg_SelectAll(var Msg: TGridMessage);
begin
SelectAll;
end; end;
{ TDrawGrid } { TDrawGrid }
@ -3616,8 +3720,10 @@ end;
procedure TDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect; procedure TDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect;
aState:TGridDrawState); aState:TGridDrawState);
Begin Begin
If Assigned(OnDrawCell) Then OnDrawCell(Self,aCol,aRow,aRect,aState) If Assigned(OnDrawCell) And Not(CsDesigning in ComponentState) Then
Else DefaultDrawCell(aCol,aRow,aRect,aState); OnDrawCell(Self,aCol,aRow,aRect,aState)
Else
DefaultDrawCell(aCol,aRow,aRect,aState);
Inherited DrawCellGrid(aRect,aCol,aRow,aState); // Draw the grid Inherited DrawCellGrid(aRect,aCol,aRow,aState); // Draw the grid
End; End;
@ -3815,8 +3921,9 @@ Var
c: PcellProps; c: PcellProps;
begin begin
// Set draw Cell Attributes // Set draw Cell Attributes
if DefaultDrawing then Begin if DefaultDrawing or (csDesigning in ComponentState) then Begin
fCellAttr.Color:=Self.Color; if gdFixed in aState Then FCellAttr.Color:=clBtnFace
Else fCellAttr.Color:=Self.Color;
FCellAttr.FontColor:=Self.Font.Color; FCellAttr.FontColor:=Self.Font.Color;
FCellAttr.TextStyle.Clipping:=False; FCellAttr.TextStyle.Clipping:=False;
End Else begin End Else begin
@ -3990,33 +4097,36 @@ begin
End; End;
end; end;
procedure TStringGrid.GetEditorValue; procedure TStringGrid.doEditorGetValue;
Var Var
msg: TGridMessage; msg: TGridMessage;
begin begin
If (FEditor<>nil) And FEditor.Visible Then Begin If (FEditor<>nil) And FEditor.Visible Then Begin
Msg.MsgID:=GM_GETVALUE;
Msg.grid:=Self; Msg.grid:=Self;
Msg.Col:=FCol; Msg.Col:=FCol;
msg.Row:=FRow; msg.Row:=FRow;
msg.Value:=''; msg.Value:=Cells[FCol,FRow];
FEditor.Perform(GM_GETVALUE, Integer(Self), Integer(@Msg)); FEditor.Dispatch(Msg);
Cells[FCol,FRow]:=msg.Value; Cells[FCol,FRow]:=msg.Value;
//FEditor.Perform(GM_GETVALUE, Integer(Self), Integer(@Msg));
End; End;
inherited GetEditorValue; //inherited EditorGetValue;
end; end;
procedure TStringGrid.SetEditorValue; procedure TStringGrid.doEditorSetValue;
Var Var
msg: TGridMessage; msg: TGridMessage;
begin begin
if FEditor<>nil Then begin if FEditor<>nil Then begin
Msg.MsgID:=GM_SETVALUE;
Msg.Grid:=Self; Msg.Grid:=Self;
Msg.Col:=FCol; Msg.Col:=FCol;
Msg.Row:=FRow; Msg.Row:=FRow;
Msg.Value:=Cells[FCol,FRow]; Msg.Value:=Cells[FCol,FRow];
FEditor.Perform(GM_SETVALUE, Integer(Self), Integer(@msg)); FEditor.Dispatch(Msg);
End; End;
inherited SetEditorValue; //inherited EditorSetValue;
end; end;
procedure TStringGrid.SaveContent(cfg: TXMLConfig); procedure TStringGrid.SaveContent(cfg: TXMLConfig);