NiceChart: Introduce TNiceGridstate to avoid using the cursor shape to define the state of the grid.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8868 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
579bdde011
commit
dafa0ba164
@ -37,12 +37,12 @@
|
||||
<PackageName Value="NiceGridLaz"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="10">
|
||||
<Units Count="14">
|
||||
<Unit0>
|
||||
<Filename Value="basic_demo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<CursorPos X="47" Y="15"/>
|
||||
<UsageCount Value="30"/>
|
||||
<UsageCount Value="31"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
@ -66,10 +66,11 @@
|
||||
<Unit3>
|
||||
<Filename Value="C:\Lazarus\lazarus-main_fpc3.2.2\lcl\controls.pp"/>
|
||||
<UnitName Value="Controls"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="2386"/>
|
||||
<CursorPos X="20" Y="2414"/>
|
||||
<EditorIndex Value="5"/>
|
||||
<TopLine Value="234"/>
|
||||
<CursorPos X="3" Y="258"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
<Filename Value="C:\Lazarus\lazarus-main_fpc3.2.2\components\lazutils\laztracer.pas"/>
|
||||
@ -100,8 +101,9 @@
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="Main"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<CursorPos X="74" Y="23"/>
|
||||
<UsageCount Value="28"/>
|
||||
<TopLine Value="18"/>
|
||||
<CursorPos X="7" Y="35"/>
|
||||
<UsageCount Value="29"/>
|
||||
<Loaded Value="True"/>
|
||||
<LoadedDesigner Value="True"/>
|
||||
</Unit7>
|
||||
@ -110,9 +112,9 @@
|
||||
<UnitName Value="NiceGrid"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<TopLine Value="1305"/>
|
||||
<CursorPos X="32" Y="1323"/>
|
||||
<UsageCount Value="11"/>
|
||||
<TopLine Value="534"/>
|
||||
<CursorPos X="56" Y="558"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit8>
|
||||
<Unit9>
|
||||
@ -120,127 +122,163 @@
|
||||
<EditorIndex Value="2"/>
|
||||
<TopLine Value="740"/>
|
||||
<CursorPos Y="771"/>
|
||||
<UsageCount Value="11"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit9>
|
||||
<Unit10>
|
||||
<Filename Value="C:\Lazarus\lazarus-main_fpc3.2.2\lcl\include\winapih.inc"/>
|
||||
<EditorIndex Value="7"/>
|
||||
<TopLine Value="287"/>
|
||||
<CursorPos X="10" Y="305"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit10>
|
||||
<Unit11>
|
||||
<Filename Value="C:\Lazarus\lazarus-main_fpc3.2.2\lcl\lcltype.pp"/>
|
||||
<UnitName Value="LCLType"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<TopLine Value="1202"/>
|
||||
<CursorPos X="3" Y="1220"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit11>
|
||||
<Unit12>
|
||||
<Filename Value="..\..\..\source\nicegridreg.pas"/>
|
||||
<UnitName Value="NiceGridReg"/>
|
||||
<EditorIndex Value="4"/>
|
||||
<TopLine Value="46"/>
|
||||
<CursorPos X="14" Y="64"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit12>
|
||||
<Unit13>
|
||||
<Filename Value="C:\Lazarus\fpc-3.2.2\source\rtl\objpas\types.pp"/>
|
||||
<UnitName Value="Types"/>
|
||||
<EditorIndex Value="8"/>
|
||||
<TopLine Value="317"/>
|
||||
<CursorPos X="10" Y="335"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit13>
|
||||
</Units>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="311" Column="15" TopLine="295"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="1157" Column="24" TopLine="1126"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="1334" Column="63" TopLine="1334"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="1154" Column="21" TopLine="1154"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="64" Column="84" TopLine="34"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="311" Column="27" TopLine="283"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="205" Column="12" TopLine="175"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="1145" Column="33" TopLine="1115"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="249" Column="13" TopLine="221"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="1472" Column="3" TopLine="1447"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="222" Column="13" TopLine="222"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="1447" Column="22" TopLine="1447"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="264" Column="3" TopLine="264"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="251" Column="16" TopLine="223"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="627" Column="14" TopLine="598"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="289" Column="24" TopLine="261"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="1325" Column="21" TopLine="1296"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="300" Column="47" TopLine="272"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="1331" Column="21" TopLine="1302"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="2927" TopLine="2895"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="1339" Column="16" TopLine="1310"/>
|
||||
<Filename Value="..\common\main.pas"/>
|
||||
<Caret Line="33" Column="22" TopLine="13"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2369" Column="16" TopLine="2340"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="401" Column="23" TopLine="386"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2385" Column="16" TopLine="2356"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="695" Column="3" TopLine="679"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2485" Column="20" TopLine="2456"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="701" Column="11" TopLine="678"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2499" Column="20" TopLine="2455"/>
|
||||
<Filename Value="..\common\main.pas"/>
|
||||
<Caret Line="35" Column="7" TopLine="18"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="547" Column="10" TopLine="529"/>
|
||||
<Filename Value="..\..\..\source\nicegridreg.pas"/>
|
||||
<Caret Line="63" Column="9" TopLine="48"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="553" Column="35" TopLine="529"/>
|
||||
<Filename Value="..\..\..\source\nicegridreg.pas"/>
|
||||
<Caret Line="64" Column="14" TopLine="46"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="633" Column="25" TopLine="604"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="519" Column="43" TopLine="501"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2360" Column="23" TopLine="2331"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="3711" Column="57" TopLine="3693"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2447" Column="44" TopLine="2447"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="3684" Column="36" TopLine="3666"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="290" Column="30" TopLine="274"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="636" Column="12" TopLine="607"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="1505" Column="21" TopLine="1483"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2437" Column="14" TopLine="2407"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="1306" Column="74" TopLine="1292"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2535" Column="14" TopLine="2506"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="2786" Column="13" TopLine="2745"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="423" Column="14" TopLine="405"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="2696" Column="30" TopLine="2683"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="2306" Column="20" TopLine="2286"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="353" Column="15" TopLine="336"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="332" Column="14" TopLine="319"/>
|
||||
<Filename Value="..\..\..\source\NiceGrid.pas"/>
|
||||
<Caret Line="415" Column="13" TopLine="412"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="..\..\..\source\nicegrid.pas"/>
|
||||
<Caret Line="627" Column="14" TopLine="598"/>
|
||||
<Caret Line="642" Column="50" TopLine="625"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
|
@ -48,7 +48,7 @@ uses
|
||||
{$ELSE}
|
||||
Windows, Messages,
|
||||
{$ENDIF}
|
||||
Forms, Controls, SysUtils, Classes, Graphics, Contnrs,
|
||||
Forms, Controls, SysUtils, Types, Classes, Graphics, Contnrs,
|
||||
StdCtrls, ExtCtrls, Clipbrd;
|
||||
|
||||
type
|
||||
@ -62,6 +62,7 @@ type
|
||||
TVertAlign = (vaTop, vaCenter, vaBottom);
|
||||
TGutterKind = (gkNone, gkBlank, gkPointer, gkNumber, gkString);
|
||||
TGridHittest = (gtNone, gtLeftTop, gtLeft, gtTop, gtCell, gtColSizing, gtSmallBox);
|
||||
TNiceGridState = (gsNormal, gsSelAll, gsSelRow, gsSelCol, gsCell, gsColSize, gsBoxDrag);
|
||||
|
||||
TNiceGrid = class;
|
||||
|
||||
@ -216,6 +217,7 @@ type
|
||||
FDefRowHeight: Integer;
|
||||
FDefColWidth: Integer;
|
||||
FFlat: Boolean;
|
||||
FGridState: TNiceGridState;
|
||||
|
||||
FHeaderLine: Integer;
|
||||
FHeaderInfos: TList;
|
||||
@ -361,6 +363,7 @@ type
|
||||
function SafeGetCell(X, Y: Integer): string;
|
||||
function GetCellColor(X, Y: Integer): TColor;
|
||||
procedure DrawCell(X, Y: Integer);
|
||||
procedure InvalidateCell(X, Y: Integer);
|
||||
function FastDrawCell(X, Y: Integer; IsEditing: Boolean): TPoint;
|
||||
procedure ForceHideCaret;
|
||||
procedure ForceShowCaret;
|
||||
@ -403,6 +406,7 @@ type
|
||||
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure KeyPress(var Key: Char); override;
|
||||
function TextExtent(const s: String): TSize;
|
||||
{$IFDEF FPC}
|
||||
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double); override;
|
||||
{$ENDIF}
|
||||
@ -550,7 +554,14 @@ const
|
||||
|
||||
CursorArray: array [TGridHitTest] of TCursor =
|
||||
//(gtNone, gtLeftTop, gtLeft, gtTop, gtCell, gtColSizing, gtSmallBox);
|
||||
{$IFDEF LCLGtk3}
|
||||
(crDefault, crSizeSE, crSizeE, crSizeS, crHandPoint, crHSplit, crCross);
|
||||
{$ELSE}
|
||||
(crDefault, crLeftTop, crRight, crDown, crPlus, crHSplit, crSmallCross);
|
||||
{$ENDIF}
|
||||
|
||||
GridStateArray: array[TGridHitTest] of TNiceGridState =
|
||||
(gsNormal, gsSelAll, gsSelRow, gsSelCol, gsCell, gsColSize, gsBoxDrag);
|
||||
|
||||
MergeID = -2;
|
||||
|
||||
@ -627,13 +638,21 @@ begin
|
||||
SmallBoxPos := 0;
|
||||
SizingCol := -1;
|
||||
SizingColX := -1;
|
||||
|
||||
{$IFDEF LCLGtk3}
|
||||
Screen.Cursors[crPlus] := Screen.Cursors[crHandPoint];
|
||||
Screen.Cursors[crSmallCross] := Screen.Cursors[crCross];
|
||||
Screen.Cursors[crRight] := Screen.Cursors[crSizeE];
|
||||
Screen.Cursors[crDown] := Screen.Cursors[crSizeS];
|
||||
Screen.Cursors[crLeftTop] := Screen.Cursors[crSizeSE];
|
||||
{$ELSE}
|
||||
Screen.Cursors[crPlus] := LoadCursor(hinstance, 'CR_PLUS');
|
||||
Screen.Cursors[crSmallCross] := LoadCursor(hInstance, 'CR_CROSS');
|
||||
Screen.Cursors[crRight] := LoadCursor(hinstance, 'CR_RIGHT');
|
||||
Screen.Cursors[crDown] := LoadCursor(hinstance, 'CR_DOWN');
|
||||
Screen.Cursors[crLeftTop] := LoadCursor(hinstance, 'CR_LEFTTOP');
|
||||
{$ENDIF}
|
||||
Cursor := crPlus;
|
||||
FGridState := gsNormal;
|
||||
|
||||
FColumns := TNiceColumns.Create(Self);
|
||||
FEdit := TNiceInplace.Create(Self);
|
||||
@ -816,6 +835,8 @@ var
|
||||
WidthAvail, HeightAvail: Integer;
|
||||
v: Integer;
|
||||
LastBodyWidth: Integer;
|
||||
bmp: TBitmap;
|
||||
lCanvas: TCanvas;
|
||||
|
||||
function GetColAutoWidth(i: Integer): Integer;
|
||||
var
|
||||
@ -824,8 +845,8 @@ var
|
||||
begin
|
||||
Result := 0;
|
||||
t := Columns[i].FStrings;
|
||||
for n := 0 to t.Count-1
|
||||
do Result := Max(Result, Canvas.TextWidth(t[n]) + 7);
|
||||
for n := 0 to t.Count-1 do
|
||||
Result := Max(Result, lCanvas.TextWidth(t[n]) + 7);
|
||||
Result := Max(Result, 20);
|
||||
end;
|
||||
|
||||
@ -835,6 +856,19 @@ begin
|
||||
|
||||
BuildMergeData;
|
||||
|
||||
if Canvas.HandleAllocated then
|
||||
begin
|
||||
lCanvas := Canvas;
|
||||
bmp := nil;
|
||||
end else
|
||||
begin
|
||||
bmp := TBitmap.Create;
|
||||
bmp.Width := 100;
|
||||
bmp.Height := 100;
|
||||
bmp.Canvas.Font.Assign(Font);
|
||||
lCanvas := bmp.Canvas;
|
||||
end;
|
||||
|
||||
VisCount := 0;
|
||||
for x := 0 to FColumns.Count-1 do
|
||||
begin
|
||||
@ -854,7 +888,7 @@ begin
|
||||
|
||||
if FAutoColWidth then
|
||||
begin
|
||||
Canvas.Font.Assign(Font);
|
||||
lCanvas.Font.Assign(Font);
|
||||
for x := 0 to FColumns.Count-1
|
||||
do FColumns[x].FWidth := Max(FDefColWidth, GetColAutoWidth(x));
|
||||
end;
|
||||
@ -968,6 +1002,8 @@ begin
|
||||
AllHeight := Min(ClientHeight, BodyHeight + FixedHeight);
|
||||
CellBox := Rect(FixedWidth, FixedHeight, ClientWidth, ClientHeight);
|
||||
end;
|
||||
|
||||
bmp.Free;
|
||||
end;
|
||||
|
||||
function DrawString(Canvas: TCanvas; Str: string; Rc: TRect;
|
||||
@ -1243,6 +1279,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TNiceGrid.InvalidateCell(X, Y: Integer);
|
||||
var
|
||||
Rc: TRect;
|
||||
begin
|
||||
Rc := GetCellRect(X, Y);
|
||||
InvalidateRect(Handle, @Rc, false);
|
||||
end;
|
||||
|
||||
function TNiceGrid.FastDrawCell(X, Y: Integer; IsEditing: Boolean): TPoint;
|
||||
var
|
||||
R, Dummy: TRect;
|
||||
@ -1711,7 +1755,8 @@ begin
|
||||
end else
|
||||
t[Y] := Value;
|
||||
if not FUpdating
|
||||
then FastDrawCell(X, Y, False);
|
||||
then InvalidateCell(X, Y);
|
||||
// then FastDrawCell(X, Y, False);
|
||||
end;
|
||||
|
||||
procedure TNiceGrid.SetCell(X, Y: Integer; Value: string);
|
||||
@ -2102,6 +2147,28 @@ begin
|
||||
UpdateColRow;
|
||||
end;
|
||||
|
||||
{$IFDEF FPC}
|
||||
VK_F2:
|
||||
begin
|
||||
{
|
||||
BuffString := '';
|
||||
Pt := GetCellAtPos(X, Y);
|
||||
FCol := Pt.X;
|
||||
FRow := Pt.Y;
|
||||
// if (Pt.X = FCol) and (Pt.Y = FRow) then
|
||||
begin
|
||||
}
|
||||
EnsureVisible(FCol, FRow);
|
||||
if (not FReadOnly) and (not FColumns[FCol].FReadOnly) then
|
||||
begin
|
||||
IsEditing := True;
|
||||
FEdit.ShowEdit(FCol, FRow);
|
||||
FEdit.SelectAll;
|
||||
end;
|
||||
//end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
VK_RETURN:
|
||||
begin
|
||||
OldS := GetCell(Col, Row);
|
||||
@ -2272,6 +2339,27 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
function TNiceGrid.TextExtent(const s: String): TSize;
|
||||
var
|
||||
bmp: TBitmap;
|
||||
begin
|
||||
if Canvas.HandleAllocated then
|
||||
Result := Canvas.TextExtent(s)
|
||||
else
|
||||
begin
|
||||
bmp := TBitmap.Create;
|
||||
try
|
||||
bmp.Width := 100;
|
||||
bmp.Height := 100;
|
||||
bmp.Canvas.Font.Assign(self.Font);
|
||||
Result := bmp.Canvas.TextExtent(s);
|
||||
finally
|
||||
bmp.Free;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TNiceGrid.GetHitTestInfo(X, Y: Integer): TGridHitTest;
|
||||
var
|
||||
a, i1, i2: Integer;
|
||||
@ -2334,6 +2422,85 @@ begin
|
||||
Exit;
|
||||
end;
|
||||
|
||||
case FGridState of
|
||||
gsColSize:
|
||||
begin
|
||||
ForceHideCaret;
|
||||
SizingColX := GetColCoord(SizingCol);
|
||||
end;
|
||||
gsBoxDrag:
|
||||
begin
|
||||
ForceHideCaret;
|
||||
SmallBoxArea := FSelectArea;
|
||||
end;
|
||||
gsSelAll:
|
||||
begin
|
||||
FRow := 0;
|
||||
FCol := 0;
|
||||
BuffString := '';
|
||||
EnsureVisible(0, 0);
|
||||
FCol2 := ColCount-1;
|
||||
FRow2 := FRowCount-1;
|
||||
SetSelectArea(Rect(0, 0, ColCount-1, FRowCount-1));
|
||||
ColRowChanged;
|
||||
end;
|
||||
gsSelRow:
|
||||
begin
|
||||
FRow := GetRowFromY(Y);
|
||||
FCol := 0;
|
||||
LastHover := FRow;
|
||||
BuffString := '';
|
||||
EnsureVisible(FCol, FRow);
|
||||
FCol2 := ColCount-1;
|
||||
FRow2 := FRow;
|
||||
SmallBoxPos := 2;
|
||||
AdjustSelection(Rect(0, FRow, ColCount-1, FRow), True);
|
||||
ColRowChanged;
|
||||
if Assigned(OnGutterClick)
|
||||
then FOnGutterClick(Self, FRow, Button, Shift);
|
||||
end;
|
||||
gsSelCol:
|
||||
begin
|
||||
FCol := GetColFromX(X);
|
||||
FRow := 0;
|
||||
LastHover := FCol;
|
||||
BuffString := '';
|
||||
EnsureVisible(FCol, FRow);
|
||||
FCol2 := FCol;
|
||||
FRow2 := FRowCount-1;
|
||||
SmallBoxPos := 1;
|
||||
AdjustSelection(Rect(FCol, 0, FCol, FRowCount-1), True);
|
||||
ColRowChanged;
|
||||
if Assigned(FOnHeaderClick)
|
||||
then FOnHeaderClick(Self, FCol, Button, Shift);
|
||||
end;
|
||||
gsCell:
|
||||
begin
|
||||
BuffString := '';
|
||||
Pt := GetCellAtPos(X, Y);
|
||||
if (Pt.X = FCol) and (Pt.Y = FRow) then
|
||||
begin
|
||||
EnsureVisible(FCol, FRow);
|
||||
if (not FReadOnly) and (not FColumns[FCol].FReadOnly) then
|
||||
begin
|
||||
IsEditing := True;
|
||||
FEdit.ShowEdit(FCol, FRow);
|
||||
end;
|
||||
end else
|
||||
if (Pt.X <> -1) and (pt.Y <> -1) then
|
||||
begin
|
||||
EnsureVisible(Pt.X, Pt.Y);
|
||||
FCol := Pt.X;
|
||||
FRow := Pt.Y;
|
||||
BuffString := '';
|
||||
FCol2 := FCol;
|
||||
FRow2 := FRow;
|
||||
SetSelectArea(Rect(FCol, FRow, FCol, FRow));
|
||||
end;
|
||||
ColRowChanged;
|
||||
end;
|
||||
end;
|
||||
(*
|
||||
if (Cursor = crHSplit) then
|
||||
begin
|
||||
ForceHideCaret;
|
||||
@ -2415,6 +2582,7 @@ begin
|
||||
end;
|
||||
ColRowChanged;
|
||||
end;
|
||||
*)
|
||||
SetCapture(Handle);
|
||||
|
||||
SetFocus;
|
||||
@ -2432,9 +2600,9 @@ var
|
||||
i: Integer;
|
||||
|
||||
begin
|
||||
|
||||
if not FEnabled then
|
||||
begin
|
||||
FGridState := gsNormal;
|
||||
Cursor := crDefault;
|
||||
inherited;
|
||||
Exit;
|
||||
@ -2442,6 +2610,93 @@ begin
|
||||
|
||||
if (ssLeft in Shift) then
|
||||
begin
|
||||
case FGridState of
|
||||
gsCell:
|
||||
begin
|
||||
Pt := GetCellAtPos(X, Y);
|
||||
if (Pt.X <> -1) and (Pt.Y <> -1) then
|
||||
begin
|
||||
l := Min(Pt.X, FCol);
|
||||
t := Min(Pt.Y, FRow);
|
||||
r := Max(Pt.X, FCol);
|
||||
b := Max(Pt.Y, FRow);
|
||||
FCol2 := Pt.X;
|
||||
FRow2 := Pt.Y;
|
||||
SetSelectArea(Rect(l, t, r, b));
|
||||
EnsureVisible(FCol2, FRow2);
|
||||
end;
|
||||
end;
|
||||
gsBoxDrag:
|
||||
begin
|
||||
Pt := GetCellAtPos(X, Y);
|
||||
if (Pt.X <> -1) and (Pt.Y <> -1) then
|
||||
begin
|
||||
l := Min(Pt.X, SmallBoxArea.Left);
|
||||
t := Min(Pt.Y, SmallBoxArea.Top);
|
||||
r := Max(Pt.X, SmallBoxArea.Right);
|
||||
b := Max(Pt.Y, SmallBoxArea.Bottom);
|
||||
FCol2 := Pt.X;
|
||||
FRow2 := Pt.Y;
|
||||
SetSelectArea(Rect(l, t, r, b));
|
||||
EnsureVisible(FCol2, FRow2);
|
||||
end;
|
||||
end;
|
||||
gsSelRow:
|
||||
begin
|
||||
i := GetRowFromY(Y);
|
||||
if (i <> -1) and (i <> LastHover) then
|
||||
begin
|
||||
LastHover := i;
|
||||
t := Min(i, FRow);
|
||||
b := Max(i, FRow);
|
||||
FRow2 := i;
|
||||
SmallBoxPos := 2;
|
||||
AdjustSelection(Rect(0, t, ColCount-1, b), True);
|
||||
end;
|
||||
end;
|
||||
gsSelCol:
|
||||
begin
|
||||
i := GetColFromX(X);
|
||||
if (i <> -1) and (i <> LastHover) then
|
||||
begin
|
||||
LastHover := i;
|
||||
l := Min(i, FCol);
|
||||
r := Max(i, FCol);
|
||||
FCol2 := i;
|
||||
SmallBoxPos := 1;
|
||||
AdjustSelection(Rect(l, 0, r, FRowCount-1), True);
|
||||
end;
|
||||
end;
|
||||
gsColSize:
|
||||
begin
|
||||
Suggested := Max(5, X + FHorzOffset - SizingColX - FixedWidth);
|
||||
if FFitToWidth then
|
||||
begin
|
||||
if (SizingCol = ColCount-1) or (SizingCol = -1) then
|
||||
begin
|
||||
inherited;
|
||||
Exit;
|
||||
end;
|
||||
Total2Col := (ClientWidth - FixedWidth) - (TotalWidth - Columns[SizingCol].FWidth - Columns[SizingCol+1].FWidth);
|
||||
if (Total2Col > 10) then
|
||||
begin
|
||||
Columns[SizingCol].FWidth := Suggested;
|
||||
Columns[SizingCol+1].FWidth := Total2Col - Suggested;
|
||||
end;
|
||||
if (Columns[SizingCol+1].FWidth < 5) then
|
||||
begin
|
||||
Columns[SizingCol].FWidth := Total2Col - 5;
|
||||
Columns[SizingCol+1].FWidth := 5;
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
Columns[SizingCol].FWidth := Suggested;
|
||||
end;
|
||||
Recalculate;
|
||||
InvalidateRightWard(FixedWidth);
|
||||
end;
|
||||
end;
|
||||
(*
|
||||
if (Cursor = crPlus) then
|
||||
begin
|
||||
Pt := GetCellAtPos(X, Y);
|
||||
@ -2529,11 +2784,12 @@ begin
|
||||
end;
|
||||
Recalculate;
|
||||
InvalidateRightWard(FixedWidth);
|
||||
end;
|
||||
end; *)
|
||||
|
||||
end else
|
||||
begin
|
||||
Cursor := CursorArray[GetHitTestInfo(X, Y)];
|
||||
FGridState := GridStateArray[GetHitTestInfo(X, Y)];
|
||||
end;
|
||||
|
||||
inherited;
|
||||
@ -2600,6 +2856,7 @@ begin
|
||||
end;
|
||||
|
||||
Cursor := CursorArray[GetHitTestInfo(X, Y)];
|
||||
FGridState := GridStateArray[GetHitTestInfo(X, Y)];
|
||||
ReleaseCapture;
|
||||
LastHover := -1;
|
||||
|
||||
@ -3815,6 +4072,10 @@ begin
|
||||
SetAlignment(Column.FHorzAlign);
|
||||
Text := FGrid.SafeGetCell(X, Y);
|
||||
Font.Assign(Column.FFont);
|
||||
{$IFDEF FPC}
|
||||
if Font.Height = 0 then
|
||||
Font.Height := GetFontData(Font.Reference.Handle).Height;
|
||||
{$ENDIF}
|
||||
|
||||
Rc := FGrid.GetCellRect(X, Y);
|
||||
Rc := FGrid.CellRectToClient(Rc);
|
||||
@ -3826,6 +4087,7 @@ begin
|
||||
l := Rc.Left;
|
||||
w := Rc.Right - Rc.Left;
|
||||
t := 0;
|
||||
// h := FGrid.TextExtent('gM').CY;
|
||||
h := FGrid.Canvas.TextHeight('gM');
|
||||
case Column.FVertAlign of
|
||||
vaTop: t := Rc.Top - 1;
|
||||
|
@ -60,7 +60,7 @@ uses
|
||||
|
||||
type
|
||||
TNiceGridEditor = class(TComponentEditor)
|
||||
protected
|
||||
public
|
||||
function GetVerbCount: Integer; override;
|
||||
function GetVerb(Index: Integer): string; override;
|
||||
procedure ExecuteVerb(Index: Integer); override;
|
||||
|
Loading…
Reference in New Issue
Block a user