fpspreadsheet: Introduce HorAlignment(s) and VertAlignment(s) properties to tsWorksheetGrid.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3035 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-05-10 12:32:05 +00:00
parent e00fedff8b
commit ee011598e4
5 changed files with 1298 additions and 1156 deletions

View File

@ -116,7 +116,7 @@
<WindowIndex Value="0"/>
<TopLine Value="1"/>
<CursorPos X="10" Y="7"/>
<UsageCount Value="182"/>
<UsageCount Value="184"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -126,11 +126,15 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="mainform"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<WindowIndex Value="0"/>
<TopLine Value="356"/>
<CursorPos X="64" Y="364"/>
<UsageCount Value="182"/>
<TopLine Value="378"/>
<CursorPos X="1" Y="410"/>
<UsageCount Value="184"/>
<Bookmarks Count="1">
<Item0 X="31" Y="442" ID="1"/>
</Bookmarks>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
@ -141,7 +145,7 @@
<WindowIndex Value="0"/>
<TopLine Value="1906"/>
<CursorPos X="32" Y="1918"/>
<UsageCount Value="85"/>
<UsageCount Value="86"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
@ -149,12 +153,9 @@
<UnitName Value="fpspreadsheetgrid"/>
<EditorIndex Value="2"/>
<WindowIndex Value="0"/>
<TopLine Value="1007"/>
<CursorPos X="3" Y="1022"/>
<UsageCount Value="86"/>
<Bookmarks Count="1">
<Item0 X="25" Y="1018" ID="1"/>
</Bookmarks>
<TopLine Value="1351"/>
<CursorPos X="1" Y="1380"/>
<UsageCount Value="87"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
@ -225,9 +226,9 @@
<UnitName Value="Grids"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="144"/>
<CursorPos X="31" Y="158"/>
<UsageCount Value="33"/>
<TopLine Value="992"/>
<CursorPos X="15" Y="1010"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
@ -267,7 +268,7 @@
<WindowIndex Value="0"/>
<TopLine Value="1493"/>
<CursorPos X="1" Y="1514"/>
<UsageCount Value="60"/>
<UsageCount Value="61"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
@ -292,18 +293,17 @@
<WindowIndex Value="0"/>
<TopLine Value="20"/>
<CursorPos X="3" Y="51"/>
<UsageCount Value="56"/>
<UsageCount Value="57"/>
<Loaded Value="True"/>
</Unit20>
<Unit21>
<Filename Value="..\..\xlsbiff5.pas"/>
<UnitName Value="xlsbiff5"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="7"/>
<WindowIndex Value="0"/>
<TopLine Value="1250"/>
<CursorPos X="60" Y="1273"/>
<UsageCount Value="43"/>
<UsageCount Value="44"/>
<Loaded Value="True"/>
</Unit21>
<Unit22>
@ -313,7 +313,7 @@
<WindowIndex Value="0"/>
<TopLine Value="547"/>
<CursorPos X="1" Y="563"/>
<UsageCount Value="44"/>
<UsageCount Value="45"/>
<Loaded Value="True"/>
</Unit22>
<Unit23>
@ -548,124 +548,124 @@
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1653" Column="1" TopLine="1629"/>
<Filename Value="mainform.pas"/>
<Caret Line="456" Column="1" TopLine="431"/>
</Position1>
<Position2>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1654" Column="1" TopLine="1629"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="5203" Column="1" TopLine="5184"/>
</Position2>
<Position3>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1666" Column="1" TopLine="1634"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="5204" Column="1" TopLine="5184"/>
</Position3>
<Position4>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1905" Column="1" TopLine="1886"/>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1370" Column="1" TopLine="1351"/>
</Position4>
<Position5>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1677" Column="1" TopLine="1658"/>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1371" Column="1" TopLine="1351"/>
</Position5>
<Position6>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1905" Column="1" TopLine="1886"/>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1372" Column="1" TopLine="1351"/>
</Position6>
<Position7>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1906" Column="1" TopLine="1886"/>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1373" Column="1" TopLine="1351"/>
</Position7>
<Position8>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1908" Column="1" TopLine="1886"/>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1374" Column="1" TopLine="1351"/>
</Position8>
<Position9>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1912" Column="1" TopLine="1886"/>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1375" Column="1" TopLine="1351"/>
</Position9>
<Position10>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1913" Column="1" TopLine="1886"/>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1380" Column="1" TopLine="1351"/>
</Position10>
<Position11>
<Filename Value="mainform.pas"/>
<Caret Line="404" Column="25" TopLine="404"/>
<Caret Line="457" Column="1" TopLine="431"/>
</Position11>
<Position12>
<Filename Value="mainform.pas"/>
<Caret Line="286" Column="3" TopLine="282"/>
<Caret Line="458" Column="1" TopLine="431"/>
</Position12>
<Position13>
<Filename Value="mainform.pas"/>
<Caret Line="364" Column="64" TopLine="356"/>
<Caret Line="459" Column="1" TopLine="431"/>
</Position13>
<Position14>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1913" Column="1" TopLine="1886"/>
<Filename Value="mainform.pas"/>
<Caret Line="458" Column="1" TopLine="431"/>
</Position14>
<Position15>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1677" Column="1" TopLine="1658"/>
<Filename Value="mainform.pas"/>
<Caret Line="459" Column="1" TopLine="431"/>
</Position15>
<Position16>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="1913" Column="1" TopLine="1886"/>
<Filename Value="mainform.pas"/>
<Caret Line="460" Column="17" TopLine="431"/>
</Position16>
<Position17>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="382" Column="62" TopLine="362"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="5184" Column="33" TopLine="5184"/>
</Position17>
<Position18>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1104" Column="52" TopLine="1073"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position18>
<Position19>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1379" Column="58" TopLine="1347"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="310" Column="16" TopLine="278"/>
</Position19>
<Position20>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1384" Column="56" TopLine="1353"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="1032" Column="25" TopLine="1002"/>
</Position20>
<Position21>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1395" Column="54" TopLine="1364"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="1213" Column="33" TopLine="1181"/>
</Position21>
<Position22>
<Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1401" Column="53" TopLine="1370"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="1239" Column="25" TopLine="1208"/>
</Position22>
<Position23>
<Filename Value="..\..\xlscommon.pas"/>
<Caret Line="1269" Column="46" TopLine="1269"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="1373" Column="85" TopLine="1343"/>
</Position23>
<Position24>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1659" Column="53" TopLine="1659"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="1480" Column="26" TopLine="1450"/>
</Position24>
<Position25>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="1699" Column="26" TopLine="1669"/>
</Position25>
<Position26>
<Filename Value="..\..\xlsbiff5.pas"/>
<Caret Line="1319" Column="3" TopLine="1319"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="3692" Column="32" TopLine="3660"/>
</Position26>
<Position27>
<Filename Value="..\..\xlsbiff5.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="7048" Column="20" TopLine="7032"/>
</Position27>
<Position28>
<Filename Value="..\..\xlscommon.pas"/>
<Caret Line="852" Column="22" TopLine="852"/>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="6948" Column="3" TopLine="6942"/>
</Position28>
<Position29>
<Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1694" Column="3" TopLine="1690"/>
<Filename Value="mainform.pas"/>
<Caret Line="377" Column="31" TopLine="377"/>
</Position29>
<Position30>
<Filename Value="..\..\xlsbiff5.pas"/>
<Caret Line="1610" Column="3" TopLine="1606"/>
<Filename Value="mainform.pas"/>
<Caret Line="2" Column="37" TopLine="76"/>
</Position30>
</JumpHistory>
</ProjectOptions>
@ -695,6 +695,15 @@
</Other>
</CompilerOptions>
<Debugging>
<BreakPoints Count="1">
<Item1>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="mainform.pas"/>
<Line Value="456"/>
</Item1>
</BreakPoints>
<Watches Count="2">
<Item1>
<Expression Value="acol"/>

View File

@ -106,7 +106,7 @@ object Form1: TForm1
RowCount = 2
TabOrder = 0
TitleStyle = tsNative
OnSelectCell = sWorksheetGrid1SelectCell
OnSelection = sWorksheetGrid1Selection
ColWidths = (
42
64
@ -531,12 +531,14 @@ object Form1: TForm1
Caption = 'Horizontal alignment'
object MnuHorDefault: TMenuItem
Action = AcHorDefaultAlign
AutoCheck = True
end
object MenuItem6: TMenuItem
Caption = '-'
end
object MenuItem3: TMenuItem
Action = AcLeftAlign
AutoCheck = True
Bitmap.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@ -576,6 +578,7 @@ object Form1: TForm1
end
object MenuItem4: TMenuItem
Action = AcHorCenterAlign
AutoCheck = True
Bitmap.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@ -615,6 +618,7 @@ object Form1: TForm1
end
object MenuItem5: TMenuItem
Action = AcRightAlign
AutoCheck = True
Bitmap.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@ -657,12 +661,14 @@ object Form1: TForm1
Caption = 'Vertical alignment'
object MnuVertDefault: TMenuItem
Action = AcVAlignDefault
AutoCheck = True
end
object MenuItem7: TMenuItem
Caption = '-'
end
object MnuVertTop: TMenuItem
Action = AcVAlignTop
AutoCheck = True
Bitmap.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@ -702,6 +708,7 @@ object Form1: TForm1
end
object MnuVertCentered: TMenuItem
Action = AcVAlignCenter
AutoCheck = True
Bitmap.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@ -741,6 +748,7 @@ object Form1: TForm1
end
object MnuVertBottom: TMenuItem
Action = AcVAlignBottom
AutoCheck = True
Bitmap.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@ -1489,6 +1497,7 @@ object Form1: TForm1
object AcHorDefaultAlign: TAction
Tag = 100
Category = 'Format'
AutoCheck = True
Caption = 'Default'
Checked = True
OnExecute = AcHorAlignmentExecute
@ -1496,6 +1505,7 @@ object Form1: TForm1
object AcLeftAlign: TAction
Tag = 101
Category = 'Format'
AutoCheck = True
Caption = 'Left'
ImageIndex = 4
OnExecute = AcHorAlignmentExecute
@ -1503,6 +1513,7 @@ object Form1: TForm1
object AcHorCenterAlign: TAction
Tag = 102
Category = 'Format'
AutoCheck = True
Caption = 'Centered'
ImageIndex = 5
OnExecute = AcHorAlignmentExecute
@ -1510,6 +1521,7 @@ object Form1: TForm1
object AcRightAlign: TAction
Tag = 103
Category = 'Format'
AutoCheck = True
Caption = 'Right'
ImageIndex = 6
OnExecute = AcHorAlignmentExecute
@ -1559,12 +1571,14 @@ object Form1: TForm1
object AcVAlignDefault: TAction
Tag = 110
Category = 'Format'
AutoCheck = True
Caption = 'Default'
OnExecute = AcVertAlignmentExecute
end
object AcVAlignTop: TAction
Tag = 111
Category = 'Format'
AutoCheck = True
Caption = 'Top'
ImageIndex = 12
OnExecute = AcVertAlignmentExecute
@ -1572,6 +1586,7 @@ object Form1: TForm1
object AcVAlignCenter: TAction
Tag = 112
Category = 'Format'
AutoCheck = True
Caption = 'Centered'
ImageIndex = 13
OnExecute = AcVertAlignmentExecute
@ -1579,6 +1594,7 @@ object Form1: TForm1
object AcVAlignBottom: TAction
Tag = 113
Category = 'Format'
AutoCheck = True
Caption = 'Bottom'
ImageIndex = 14
OnExecute = AcVertAlignmentExecute

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Menus, ExtCtrls, ComCtrls, ActnList, Spin, ColorBox,graphutil,
StdCtrls, Menus, ExtCtrls, ComCtrls, ActnList, Spin, Grids, graphutil,
fpspreadsheetgrid, fpspreadsheet, fpsallformats;
type
@ -120,15 +120,14 @@ type
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure sWorksheetGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure sWorksheetGrid1Selection(Sender: TObject; aCol, aRow: Integer);
private
{ private declarations }
procedure LoadFile(const AFileName: String);
procedure UpdateBorders(ACell: PCell);
procedure UpdateHorAlignment(AValue: TsHorAlignment);
procedure UpdateFont(AFont: TsFont);
procedure UpdateVertAlignment(AValue: TsVertAlignment);
procedure UpdateBorderActions(ACell: PCell);
procedure UpdateHorAlignmentActions;
procedure UpdateFontActions(AFont: TsFont);
procedure UpdateVertAlignmentActions;
public
{ public declarations }
end;
@ -139,7 +138,7 @@ var
implementation
uses
fpcanvas, Grids;
fpcanvas;
const
HORALIGN_TAG = 100;
@ -238,36 +237,26 @@ end;
procedure TForm1.AcHorAlignmentExecute(Sender: TObject);
var
horalign: TsHorAlignment;
c, r: Cardinal;
hor_align: TsHorAlignment;
begin
horalign := TsHorAlignment(TAction(Sender).Tag - HORALIGN_TAG);
if TAction(Sender).Checked then
horalign := haDefault;
UpdateHorAlignment(horalign);
with sWorksheetGrid1 do begin
c := GetWorksheetCol(Col);
r := GetWorksheetRow(Row);
if Worksheet <> nil then
Worksheet.WriteHorAlignment(r, c, horalign);
end;
hor_align := TsHorAlignment(TAction(Sender).Tag - HORALIGN_TAG)
else
hor_align := haDefault;
with sWorksheetGrid1 do HorAlignments[Selection] := hor_align;
UpdateHorAlignmentActions;
end;
procedure TForm1.AcVertAlignmentExecute(Sender: TObject);
var
vertalign: TsVertAlignment;
c, r: Cardinal;
vert_align: TsVertAlignment;
begin
vertalign := TsVertAlignment(TAction(Sender).Tag - VERTALIGN_TAG);
if TAction(Sender).Checked then
vertalign := vaDefault;
UpdateVertAlignment(vertalign);
with sWorksheetGrid1 do begin
c := GetWorksheetCol(Col);
r := GetWorksheetRow(Row);
if Worksheet <> nil then
Worksheet.WriteVertAlignment(r, c, vertalign);
end;
vert_align := TsVertAlignment(TAction(Sender).Tag - VERTALIGN_TAG)
else
vert_align := vaDefault;
with sWorksheetGrid1 do VertAlignments[Selection] := vert_align;
UpdateVertAlignmentActions;
end;
procedure TForm1.CbShowHeadersClick(Sender: TObject);
@ -394,8 +383,7 @@ begin
sWorksheetGrid1.SelectSheetByIndex(PageControl1.ActivePageIndex);
end;
procedure TForm1.sWorksheetGrid1SelectCell(Sender: TObject;
aCol, aRow: Integer; var CanSelect: Boolean);
procedure TForm1.sWorksheetGrid1Selection(Sender: TObject; aCol, aRow: Integer);
var
cell: PCell;
c, r: Cardinal;
@ -403,20 +391,22 @@ var
begin
with sWorksheetGrid1 do begin
if Worksheet = nil then exit;
c := GetWorksheetCol(ACol);
r := GetWorksheetRow(ARow);
cell := Worksheet.FindCell(r, c);
end;
UpdateBorders(cell);
UpdateHorAlignmentActions;
UpdateVertAlignmentActions;
UpdateBorderactions(cell);
if cell = nil then
exit;
UpdateHorAlignment(cell^.HorAlignment);
UpdateVertAlignment(cell^.VertAlignment);
lFont := sWorksheetGrid1.Workbook.GetFont(cell^.FontIndex);
UpdateFont(lFont);
UpdateFontActions(lFont);
end;
procedure TForm1.UpdateBorders(ACell: PCell);
procedure TForm1.UpdateBorderActions(ACell: PCell);
begin
AcBorderTop.Checked := (ACell <> nil) and (cbNorth in ACell^.Border);
AcBorderLeft.Checked := (ACell <> nil) and (cbWest in ACell^.Border);
@ -429,19 +419,21 @@ begin
(ACell^.BorderStyles[cbSouth].LineStyle = lsMedium);
end;
procedure TForm1.UpdateHorAlignment(AValue: TsHorAlignment);
procedure TForm1.UpdateHorAlignmentActions;
var
i: Integer;
ac: TAction;
hor_align: TsHorAlignment;
begin
with sWorksheetGrid1 do hor_align := HorAlignments[Selection];
for i:=0 to ActionList1.ActionCount-1 do begin
ac := TAction(ActionList1.Actions[i]);
if (ac.Tag >= HORALIGN_TAG) and (ac.Tag < HORALIGN_TAG+10) then
ac.Checked := ((ac.Tag - HORALIGN_TAG) = ord(AValue));
ac.Checked := ((ac.Tag - HORALIGN_TAG) = ord(hor_align));
end;
end;
procedure TForm1.UpdateFont(AFont: TsFont);
procedure TForm1.UpdateFontActions(AFont: TsFont);
begin
FontCombobox.ItemIndex := FontCombobox.Items.IndexOf(AFont.FontName);
FontsizeCombobox.ItemIndex := FontSizeCombobox.Items.IndexOf(IntToStr(Round(AFont.Size)));
@ -451,15 +443,19 @@ begin
AcFontStrikeout.Checked := fssStrikeOut in AFont.Style;
end;
procedure TForm1.UpdateVertAlignment(AValue: TsVertAlignment);
procedure TForm1.UpdateVertAlignmentActions;
var
i: Integer;
ac: TAction;
vert_align: TsVertAlignment;
t: Integer;
begin
with sWorksheetGrid1 do vert_align := VertAlignments[Selection];
for i:=0 to ActionList1.ActionCount-1 do begin
ac := TAction(ActionList1.Actions[i]);
t := ac.tag;
if (ac.Tag >= VERTALIGN_TAG) and (ac.Tag < VERTALIGN_TAG+10) then
ac.Checked := ((ac.Tag - VERTALIGN_TAG) = ord(AValue));
ac.Checked := ((ac.Tag - VERTALIGN_TAG) = ord(vert_align));
end;
end;

View File

@ -42,25 +42,31 @@ type
function CalcRowHeight(AHeight: Single): Integer;
procedure ChangedCellHandler(ASender: TObject; ARow, ACol: Cardinal);
procedure ChangedFontHandler(ASender: TObject; ARow, ACol: Cardinal);
function GetHorAlignment(ACol, ARow: Integer): TsHorAlignment;
function GetHorAlignments(ARect: TGridRect): TsHorAlignment;
function GetShowGridLines: Boolean;
function GetShowHeaders: Boolean;
function GetVertAlignment(ACol, ARow: Integer): TsVertAlignment;
function GetVertAlignments(ARect: TGridRect): TsVertAlignment;
function IsSelection(ACol, ARow: Integer; ABorder: TsCellBorder): Boolean;
function IsSelectionNeighbor(ACol, ARow: Integer; ABorder: TsCellBorder): Boolean;
procedure SetFrozenCols(AValue: Integer);
procedure SetFrozenRows(AValue: Integer);
procedure SetHorAlignment(ACol, ARow: Integer; AValue: TsHorAlignment);
procedure SetHorAlignments(ARect: TGridRect; AValue: TsHorAlignment);
procedure SetShowGridLines(AValue: Boolean);
procedure SetShowHeaders(AValue: Boolean);
procedure SetVertAlignment(ACol, ARow: Integer; AValue: TsVertAlignment);
procedure SetVertAlignments(ARect: TGridRect; AValue: TsVertAlignment);
protected
{ Protected declarations }
procedure DefaultDrawCell(ACol, ARow: Integer; var ARect: TRect; AState: TGridDrawState); override;
procedure DoPrepareCanvas(ACol, ARow: Integer; AState: TGridDrawState); override;
// procedure DrawAllRows; override;
procedure DrawCellBorders(ACol, ARow: Integer; ARect: TRect);
procedure DrawCellGrid(aCol,aRow: Integer; aRect: TRect; aState: TGridDrawState); override;
procedure DrawFocusRect(aCol,aRow:Integer; ARect:TRect); override;
procedure DrawSelectionBorders(ACol, ARow: Integer; ARect: TRect);
// procedure DrawSelectionBorders(ACol, ARow: Integer; ARect: TRect);
procedure DrawTextInCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState); override;
function GetBorderStyle(ACol, ARow, ADeltaCol, ADeltaRow: Integer;
var ABorderStyle: TsCellBorderStyle): Boolean;
@ -110,6 +116,16 @@ type
property Worksheet: TsWorksheet read FWorksheet;
property Workbook: TsWorkbook read FWorkbook;
property HeaderCount: Integer read FHeaderCount;
{ maybe these should become published ... }
property HorAlignment[ACol, ARow: Integer]: TsHorAlignment
read GetHorAlignment write SetHorAlignment;
property HorAlignments[ARect: TGridRect]: TsHorAlignment
read GetHorAlignments write SetHorAlignments;
property VertAlignment[ACol, ARow: Integer]: TsVertAlignment
read GetVertAlignment write SetVertAlignment;
property VertAlignments[ARect: TGridRect]: TsVertAlignment
read GetVertAlignments write SetVertAlignments;
end;
{ TsWorksheetGrid }
@ -1283,6 +1299,35 @@ begin
Result := false;
end;
function TsCustomWorksheetGrid.GetHorAlignment(ACol, ARow: Integer): TsHorAlignment;
var
cell: PCell;
begin
Result := haDefault;
if Assigned(FWorksheet) then begin
cell := FWorksheet.FindCell(GetWorksheetRow(ARow), GetWorksheetCol(ACol));
if cell <> nil then
Result := cell^.HorAlignment;
end;
end;
function TsCustomWorksheetGrid.GetHorAlignments(ARect: TGridRect): TsHorAlignment;
var
c, r: Integer;
horalign: TsHorAlignment;
begin
Result := GetHorAlignment(ARect.Left, ARect.Top);
horalign := Result;
for c := ARect.Left to ARect.Right do
for r := ARect.Top to ARect.Bottom do begin
Result := GetHorAlignment(c, r);
if Result <> horalign then begin
Result := haDefault;
exit;
end;
end;
end;
{ Returns a list of worksheets contained in the file. Useful for assigning to
user controls like TabControl, Combobox etc. in order to select a sheet. }
procedure TsCustomWorksheetGrid.GetSheets(const ASheets: TStrings);
@ -1305,6 +1350,35 @@ begin
Result := FHeaderCount <> 0;
end;
function TsCustomWorksheetGrid.GetVertAlignment(ACol, ARow: Integer): TsVertAlignment;
var
cell: PCell;
begin
Result := vaDefault;
if Assigned(FWorksheet) then begin
cell := FWorksheet.FindCell(GetWorksheetRow(ARow), GetWorksheetCol(ACol));
if cell <> nil then
Result := cell^.VertAlignment;
end;
end;
function TsCustomWorksheetGrid.GetVertAlignments(ARect: TGridRect): TsVertAlignment;
var
c, r: Integer;
vertalign: TsVertAlignment;
begin
Result := GetVertalignment(ARect.Left, ARect.Top);
vertalign := Result;
for c := ARect.Left to ARect.Right do
for r := ARect.Top to ARect.Bottom do begin
Result := GetVertAlignment(c, r);
if Result <> vertalign then begin
Result := vaDefault;
exit;
end;
end;
end;
{ Calculates the index of the worksheet column that is displayed in the
given column of the grid. If the sheet headers are turned on, both numbers
differ by 1, otherwise they are equal. Saves an "if" in cases. }
@ -1431,6 +1505,28 @@ begin
Setup;
end;
procedure TsCustomWorksheetGrid.SetHorAlignment(ACol, ARow: Integer;
AValue: TsHorAlignment);
begin
if Assigned(FWorkbook) then
FWorksheet.WriteHorAlignment(GetWorksheetRow(ARow), GetWorksheetCol(ACol), AValue);
end;
procedure TsCustomWorksheetGrid.SetHorAlignments(ARect: TGridRect;
AValue: TsHorAlignment);
var
c,r: Integer;
begin
BeginUpdate;
try
for c := ARect.Left to ARect.Right do
for r := ARect.Top to ARect.Bottom do
SetHorAlignment(c, r, AValue);
finally
EndUpdate;
end;
end;
{ Shows / hides the worksheet's grid lines }
procedure TsCustomWorksheetGrid.SetShowGridLines(AValue: Boolean);
begin
@ -1506,6 +1602,28 @@ begin
Invalidate;
end;
procedure TsCustomWorksheetGrid.SetVertAlignment(ACol, ARow: Integer;
AValue: TsVertAlignment);
begin
if Assigned(FWorkbook) then
FWorksheet.WriteVertAlignment(GetWorksheetRow(ARow), GetWorksheetCol(ACol), AValue);
end;
procedure TsCustomWorksheetGrid.SetVertAlignments(ARect: TGridRect;
AValue: TsVertAlignment);
var
c,r: Integer;
begin
BeginUpdate;
try
for c := ARect.Left to ARect.Right do
for r := ARect.Top to ARect.Bottom do
SetVertAlignment(c, r, AValue);
finally
EndUpdate;
end;
end;
procedure TsCustomWorksheetGrid.LoadFromWorksheet(AWorksheet: TsWorksheet);
begin
FWorksheet := AWorksheet;