You've already forked lazarus-ccr
fpspreadsheet: add new demo "wikitablemaker" which implements an editor for wiki tables and shows the generated wiki code in a SynEdit.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3609 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
10
components/fpspreadsheet/examples/wikitablemaker/readme.txt
Normal file
10
components/fpspreadsheet/examples/wikitablemaker/readme.txt
Normal file
@ -0,0 +1,10 @@
|
||||
WikiTableMaker implements an editor for tables to be used in wikis.
|
||||
|
||||
Load a spreadsheet file into the worksheet grid, or type in the data needed.
|
||||
Go to page "code" to see the wiki code. Copy it to the clipboard and paste it
|
||||
into the wiki source page.
|
||||
|
||||
Technically, WikiTableMaker is a moderately stripped-down version of the
|
||||
spready demo. The worksheet grid, however, is created at run-time. Therefore,
|
||||
it is not necessary to install the laz_fpspreadsheet package to run this
|
||||
sample project.
|
@ -0,0 +1,730 @@
|
||||
unit SynHighlighterWikitable;
|
||||
|
||||
{$IFDEF FPC}
|
||||
{$MODE OBJFPC}{$H+}
|
||||
{$ENDIF}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Classes,
|
||||
LCLIntf, LCLType,
|
||||
Controls, Graphics,
|
||||
SynEditTypes, SynEditHighlighter;
|
||||
|
||||
type
|
||||
TtkTokenKind = (tkAmpersand, tkComment, tkIdentifier, tkNull, tkNumber,
|
||||
tkSpace, tkString, tkSymbol, tkText, tkUnknown);
|
||||
{
|
||||
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkSpace,
|
||||
tkString, tkSymbol, tkUnknown);
|
||||
}
|
||||
|
||||
TRangeState = (rsUnknown, rsSymbol, rsParam, rsValue, rsComment, rsText, rsAmpersand);
|
||||
|
||||
TProcTableProc = procedure of object;
|
||||
|
||||
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
|
||||
TIdentFuncTableFunc = function: TtkTokenKind of object;
|
||||
|
||||
TSynWikiTableSyn = class(TSynCustomHighlighter)
|
||||
private
|
||||
FLine: PChar;
|
||||
FLineNumber: Integer;
|
||||
FTokenPos: Integer;
|
||||
FTokenID: TtkTokenKind;
|
||||
FRange: TRangeState;
|
||||
Run: LongInt;
|
||||
FAmpersandCode: Integer;
|
||||
FStringLen: Integer;
|
||||
FToIdent: PChar;
|
||||
FProcTable: array[#0..#255] of TProcTableProc;
|
||||
FIdentFuncTable: array[0..255] of TIdentFuncTableFunc;
|
||||
FCommentAttri: TSynHighlighterAttributes;
|
||||
FNumberAttri: TSynHighlighterAttributes;
|
||||
FSpaceAttri: TSynHighlighterAttributes;
|
||||
FSymbolAttri: TSynHighlighterAttributes;
|
||||
(*
|
||||
FIdentifierAttri: TSynHighlighterAttributes;
|
||||
FKeyAttri: TSynHighlighterAttributes;
|
||||
FNumberAttri: TSynHighlighterAttributes;
|
||||
FStringAttri: TSynHighlighterAttributes;
|
||||
*)
|
||||
procedure InitIdent;
|
||||
function IdentKind(MayBe: PChar): TtkTokenKind;
|
||||
function KeyHash(ToHash: PChar): Integer;
|
||||
function KeyComp(const aKey: string): Boolean;
|
||||
procedure MakeMethodTables;
|
||||
|
||||
procedure AmpersandProc;
|
||||
procedure BarProc;
|
||||
procedure BeginProc;
|
||||
procedure CommentProc;
|
||||
procedure CRProc;
|
||||
procedure ExclamProc;
|
||||
procedure LFProc;
|
||||
procedure IdentProc;
|
||||
procedure NullProc;
|
||||
procedure NumberProc;
|
||||
procedure SpaceProc;
|
||||
procedure StringProc;
|
||||
procedure TextProc;
|
||||
procedure UnknownProc;
|
||||
protected
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes; override;
|
||||
function GetEol: Boolean; override;
|
||||
function GetToken: string; override;
|
||||
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
|
||||
function GetTokenID: TtkTokenKind;
|
||||
function GetTokenAttribute: TSynHighlighterAttributes; override;
|
||||
function GetTokenKind: integer; override;
|
||||
function GetTokenPos: Integer; override;
|
||||
procedure Next; override;
|
||||
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
|
||||
published
|
||||
property CommentAttri: TSynHighlighterAttributes
|
||||
read FCommentAttri write FCommentAttri;
|
||||
property NumberAttri: TSynHighlighterAttributes
|
||||
read FNumberAttri write FNumberAttri;
|
||||
property SpaceAttri: TSynHighlighterAttributes
|
||||
read FSpaceAttri write FSpaceAttri;
|
||||
property SymbolAttri: TSynHighlighterAttributes
|
||||
read FSymbolAttri write FSymbolAttri;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
SynEditStrConst;
|
||||
|
||||
const
|
||||
// to do: remove next line when this identifier is in stable
|
||||
SYN_ATTR_NUMBER = 6; // not available in Laz 1.2.4
|
||||
|
||||
MAX_ESCAPEAMPS = 159;
|
||||
|
||||
EscapeAmps: array[0..MAX_ESCAPEAMPS - 1] of PChar = (
|
||||
('&'), { & }
|
||||
('<'), { > }
|
||||
('>'), { < }
|
||||
('"'), { " }
|
||||
('™'), { }
|
||||
(' '), { space }
|
||||
('©'), { © }
|
||||
('®'), { ® }
|
||||
('À'), { À }
|
||||
('Á'), { Á }
|
||||
('Â'), { Â }
|
||||
('Ã'), { Ã }
|
||||
('Ä'), { Ä }
|
||||
('Å'), { Å }
|
||||
('Æ'), { Æ }
|
||||
('Ç'), { Ç }
|
||||
('È'), { È }
|
||||
('É'), { É }
|
||||
('Ê'), { Ê }
|
||||
('Ë'), { Ë }
|
||||
('Ì'), { Ì }
|
||||
('Í'), { Í }
|
||||
('Î'), { Î }
|
||||
('Ï'), { Ï }
|
||||
('Ð'), { Ð }
|
||||
('Ñ'), { Ñ }
|
||||
('Ò'), { Ò }
|
||||
('Ó'), { Ó }
|
||||
('Ô'), { Ô }
|
||||
('Õ'), { Õ }
|
||||
('Ö'), { Ö }
|
||||
('Ø'), { Ø }
|
||||
('Ù'), { Ù }
|
||||
('Ú'), { Ú }
|
||||
('Û'), { Û }
|
||||
('Ü'), { Ü }
|
||||
('Ý'), { Ý }
|
||||
('Þ'), { Þ }
|
||||
('ß'), { ß }
|
||||
('à'), { à }
|
||||
('á'), { á }
|
||||
('â'), { â }
|
||||
('ã'), { ã }
|
||||
('ä'), { ä }
|
||||
('å'), { å }
|
||||
('æ'), { æ }
|
||||
('ç'), { ç }
|
||||
('è'), { è }
|
||||
('é'), { é }
|
||||
('ê'), { ê }
|
||||
('ë'), { ë }
|
||||
('ì'), { ì }
|
||||
('í'), { í }
|
||||
('î'), { î }
|
||||
('ï'), { ï }
|
||||
('ð'), { ð }
|
||||
('ñ'), { ñ }
|
||||
('ò'), { ò }
|
||||
('ó'), { ó }
|
||||
('ô'), { ô }
|
||||
('õ'), { õ }
|
||||
('ö'), { ö }
|
||||
('ø'), { ø }
|
||||
('ù'), { ù }
|
||||
('ú'), { ú }
|
||||
('û'), { û }
|
||||
('ü'), { ü }
|
||||
('ý'), { ý }
|
||||
('þ'), { þ }
|
||||
('ÿ'), { ÿ }
|
||||
('¡'), { ¡ }
|
||||
('¢'), { ¢ }
|
||||
('£'), { £ }
|
||||
('¤'), { ¤ }
|
||||
('¥'), { ¥ }
|
||||
('¦'), { ¦ }
|
||||
('§'), { § }
|
||||
('¨'), { ¨ }
|
||||
('ª'), { ª }
|
||||
('«'), { « }
|
||||
('­'), { ¬ }
|
||||
('¯'), { ¯ }
|
||||
('°'), { ° }
|
||||
('±'), { ± }
|
||||
('²'), { ² }
|
||||
('³'), { ³ }
|
||||
('´'), { ´ }
|
||||
('µ'), { µ }
|
||||
('·'), { · }
|
||||
('¸'), { ¸ }
|
||||
('¹'), { ¹ }
|
||||
('º'), { º }
|
||||
('»'), { » }
|
||||
('¼'), { ¼ }
|
||||
('½'), { ½ }
|
||||
('¾'), { ¾ }
|
||||
('¿'), { ¿ }
|
||||
('×'), { × }
|
||||
('÷'), { ÷ }
|
||||
('€'), { }
|
||||
('‰'),
|
||||
('„'),
|
||||
('”'),
|
||||
('‘'),
|
||||
('’'),
|
||||
('–'),
|
||||
('—'),
|
||||
('•'),
|
||||
//used by very old HTML editors
|
||||
('	'), { TAB }
|
||||
(''), { }
|
||||
('€'), { }
|
||||
(''), { }
|
||||
('‚'), { }
|
||||
('ƒ'), { }
|
||||
('„'), { }
|
||||
('&ldots;'), {
}
|
||||
('†'), { }
|
||||
('‡'), { }
|
||||
('ˆ'), { }
|
||||
('‰'), { }
|
||||
('Š'), { }
|
||||
('‹'), { }
|
||||
('Œ'), { }
|
||||
(''), { }
|
||||
('Ž'), { }
|
||||
(''), { }
|
||||
(''), { }
|
||||
('˜'), { }
|
||||
('™'), { }
|
||||
('š'), { }
|
||||
('›'), { }
|
||||
('œ'), { }
|
||||
(''), { }
|
||||
('ž'), { }
|
||||
('Ÿ'), { }
|
||||
('¡'), { ¡ }
|
||||
('¢'), { ¢ }
|
||||
('£'), { £ }
|
||||
('¤'), { ¤ }
|
||||
('¥'), { ¥ }
|
||||
('¦'), { ¦ }
|
||||
('§'), { § }
|
||||
('¨'), { ¨ }
|
||||
('ª'), { ª }
|
||||
('¯'), { » }
|
||||
('°'), { ° }
|
||||
('±'), { ± }
|
||||
('²'), { ² }
|
||||
('´'), { ´ }
|
||||
('µ'), { µ }
|
||||
('·'), { · }
|
||||
('¸'), { ¸ }
|
||||
('¹'), { ¹ }
|
||||
('º'), { º }
|
||||
('¼'), { ¼ }
|
||||
('½'), { ½ }
|
||||
('¾'), { ¾ }
|
||||
('¿'), { ¿ }
|
||||
('×')); { Ô }
|
||||
|
||||
var
|
||||
Identifiers: array[#0..#255] of ByteBool;
|
||||
mHashTable: array[#0..#255] of Integer;
|
||||
|
||||
procedure MakeIdentTable;
|
||||
var
|
||||
I, J: Char;
|
||||
begin
|
||||
for I := #0 to #255 do begin
|
||||
case I of
|
||||
'a'..'z', 'A'..'Z', '-', '_', '0'..'9','@': Identifiers[I] := True;
|
||||
else
|
||||
Identifiers[I] := False;
|
||||
end;
|
||||
J := UpCase(I);
|
||||
if I in ['a'..'z', 'A'..'Z', '-', '_','@'] then
|
||||
mHashTable[I] := Ord(J) - 64
|
||||
else
|
||||
mHashTable[I] := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TSynWikiTableSyn.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
|
||||
FCommentAttri := TSynHighlighterAttributes.Create(@SYNS_AttrComment, SYNS_XML_AttrComment);
|
||||
FCommentAttri.Style := [fsItalic];
|
||||
FCommentAttri.Foreground := clTeal;
|
||||
AddAttribute(FCommentAttri);
|
||||
|
||||
FNumberAttri := TSynHighlighterAttributes.Create(@SYNS_AttrNumber, SYNS_XML_AttrNumber);
|
||||
FNumberAttri.Foreground := clBlue;
|
||||
AddAttribute(fNumberAttri);
|
||||
|
||||
FSpaceAttri := TSynHighlighterAttributes.Create(@SYNS_AttrSpace, SYNS_XML_AttrSpace);
|
||||
AddAttribute(FSpaceAttri);
|
||||
|
||||
FSymbolAttri := TSynHighlighterAttributes.Create(@SYNS_AttrSymbol, SYNS_XML_AttrSymbol);
|
||||
FSymbolAttri.Style := [fsBold];
|
||||
FSymbolAttri.Foreground := clPurple;
|
||||
AddAttribute(fSymbolAttri);
|
||||
|
||||
(*
|
||||
fIdentifierAttri := TSynHighlighterAttributes.Create(@SYNS_AttrIdentifier, SYNS_XML_AttrIdentifier);
|
||||
AddAttribute(fIdentifierAttri);
|
||||
|
||||
fKeyAttri := TSynHighlighterAttributes.Create(@SYNS_AttrKey, SYNS_XML_AttrKey);
|
||||
fKeyAttri.Style := [fsBold];
|
||||
AddAttribute(fKeyAttri);
|
||||
|
||||
fStringAttri := TSynHighlighterAttributes.Create(@SYNS_AttrString, SYNS_XML_AttrString);
|
||||
AddAttribute(fStringAttri);
|
||||
*)
|
||||
|
||||
SetAttributesOnChange(@DefHighlightChange);
|
||||
InitIdent;
|
||||
MakeMethodTables;
|
||||
// fDefaultFilter := SYNS_FilterCSS;
|
||||
FRange := rsUnknown;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.AmpersandProc;
|
||||
begin
|
||||
case FAmpersandCode of
|
||||
Low(EscapeAmps)..High(EscapeAmps):
|
||||
begin
|
||||
FTokenID := tkAmpersand;
|
||||
inc(Run, StrLen(EscapeAmps[FAmpersandCode]));
|
||||
end;
|
||||
end;
|
||||
FAmpersandCode := -1;
|
||||
FRange := rsText;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.BarProc;
|
||||
begin
|
||||
FTokenID := tkSymbol;
|
||||
FRange := rsSymbol;
|
||||
inc(Run);
|
||||
if FLine[Run] in ['-', '}'] then inc(Run);
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.BeginProc;
|
||||
begin
|
||||
inc(Run);
|
||||
if FLine[Run] = '|' then begin
|
||||
FTokenID := tkSymbol;
|
||||
FRange := rsSymbol;
|
||||
inc(Run);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynWikitableSyn.CommentProc;
|
||||
begin
|
||||
FTokenID := tkComment;
|
||||
|
||||
if (FLine[Run] in [#0, #10, #13]) then begin
|
||||
FProcTable[FLine[Run]];
|
||||
Exit;
|
||||
end;
|
||||
|
||||
while not (FLine[Run] in [#0, #10, #13]) do begin
|
||||
if (FLine[Run] = '>') and (FLine[Run - 1] = '-') and (FLine[Run - 2] = '-')
|
||||
then begin
|
||||
FRange := rsText;
|
||||
inc(Run);
|
||||
{
|
||||
if TopHtmlCodeFoldBlockType = cfbtHtmlComment then
|
||||
EndHtmlNodeCodeFoldBlock;
|
||||
}
|
||||
break;
|
||||
end;
|
||||
inc(Run);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.CRProc;
|
||||
begin
|
||||
FTokenID := tkSpace;
|
||||
inc(Run);
|
||||
if FLine[Run] = #10 then inc(Run);
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.ExclamProc;
|
||||
begin
|
||||
FTokenID := tkSymbol;
|
||||
inc(Run);
|
||||
if FLine[Run] = '-' then inc(Run);
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.GetDefaultAttribute(Index: Integer): TSynHighlighterAttributes;
|
||||
begin
|
||||
case Index of
|
||||
SYN_ATTR_COMMENT : Result := FCommentAttri;
|
||||
SYN_ATTR_SYMBOL : Result := FSymbolAttri;
|
||||
SYN_ATTR_NUMBER : Result := FNumberAttri;
|
||||
SYN_ATTR_WHITESPACE : Result := FSpaceAttri;
|
||||
(*
|
||||
SYN_ATTR_IDENTIFIER : Result := FIdentifierAttri;
|
||||
SYN_ATTR_KEYWORD : Result := FKeyAttri;
|
||||
SYN_ATTR_STRING : Result := FStringAttri;
|
||||
*)
|
||||
else
|
||||
Result := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.GetEol: Boolean;
|
||||
begin
|
||||
Result := (FTokenID = tkNull);
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.GetToken: string;
|
||||
var
|
||||
Len: LongInt;
|
||||
begin
|
||||
Result := '';
|
||||
Len := Run - FTokenPos;
|
||||
SetString(Result, (FLine + FTokenPos), Len);
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.GetTokenAttribute: TSynHighlighterAttributes;
|
||||
begin
|
||||
case GetTokenID of
|
||||
tkComment : Result := FCommentAttri;
|
||||
tkSymbol : Result := FSymbolAttri;
|
||||
tkNumber : Result := FNumberAttri;
|
||||
tkSpace : Result := FSpaceAttri;
|
||||
{
|
||||
tkIdentifier: Result := FIdentifierAttri;
|
||||
tkKey : Result := FKeyAttri;
|
||||
tkNumber : Result := FNumberAttri;
|
||||
tkString : Result := FStringAttri;
|
||||
tkUnknown : Result := FIdentifierAttri;
|
||||
}
|
||||
else
|
||||
Result := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.GetTokenEx(out TokenStart: PChar;
|
||||
out TokenLength: integer);
|
||||
begin
|
||||
TokenLength := Run - FTokenPos;
|
||||
TokenStart := FLine + FTokenPos;
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.GetTokenID: TtkTokenKind;
|
||||
begin
|
||||
Result := FTokenId;
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.GetTokenKind: integer;
|
||||
begin
|
||||
Result := Ord(FTokenId);
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.GetTokenPos: Integer;
|
||||
begin
|
||||
Result := FTokenPos;
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.IdentKind(MayBe: PChar): TtkTokenKind;
|
||||
var
|
||||
HashKey: Integer;
|
||||
begin
|
||||
FToIdent := MayBe;
|
||||
HashKey := KeyHash(MayBe);
|
||||
if (HashKey >= 16) and (HashKey <= 275) then
|
||||
Result := fIdentFuncTable[HashKey]()
|
||||
else
|
||||
Result := tkIdentifier;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.IdentProc;
|
||||
begin
|
||||
FTokenID := IdentKind((FLine + Run));
|
||||
inc(Run, FStringLen);
|
||||
while Identifiers[FLine[Run]] do
|
||||
Inc(Run);
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.InitIdent;
|
||||
var
|
||||
i: Integer;
|
||||
begin (*
|
||||
for i := 0 to 255 do
|
||||
case i of
|
||||
1: FIdentFuncTable[i] := @Func1;
|
||||
2: FIdentFuncTable[i] := @Func2;
|
||||
8: FIdentFuncTable[i] := @Func8;
|
||||
9: FIdentFuncTable[i] := @Func9;
|
||||
10: FIdentFuncTable[i] := @Func10;
|
||||
11: FIdentFuncTable[i] := @Func11;
|
||||
12: FIdentFuncTable[i] := @Func12;
|
||||
13: FIdentFuncTable[i] := @Func13;
|
||||
14: FIdentFuncTable[i] := @Func14;
|
||||
15: FIdentFuncTable[i] := @Func15;
|
||||
16: FIdentFuncTable[i] := @Func16;
|
||||
17: FIdentFuncTable[i] := @Func17;
|
||||
18: FIdentFuncTable[i] := @Func18;
|
||||
19: FIdentFuncTable[i] := @Func19;
|
||||
20: FIdentFuncTable[i] := @Func20;
|
||||
21: FIdentFuncTable[i] := @Func21;
|
||||
23: FIdentFuncTable[i] := @Func23;
|
||||
24: FIdentFuncTable[i] := @Func24;
|
||||
25: FIdentFuncTable[i] := @Func25;
|
||||
end;
|
||||
*)
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.KeyComp(const aKey: string): Boolean;
|
||||
var
|
||||
i: Integer;
|
||||
Temp: PChar;
|
||||
begin
|
||||
Temp := FToIdent;
|
||||
if Length(aKey) = FStringLen then begin
|
||||
Result := True;
|
||||
for i := 1 to FStringLen do begin
|
||||
if mHashTable[Temp^] <> mHashTable[aKey[i]] then begin
|
||||
Result := False;
|
||||
Break;
|
||||
end;
|
||||
inc(Temp);
|
||||
end;
|
||||
end else
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
function TSynWikiTableSyn.KeyHash(ToHash: PChar): Integer;
|
||||
begin
|
||||
Result := 0;
|
||||
While (ToHash^ In ['a'..'z', 'A'..'Z', '!', '/']) do begin
|
||||
Inc(Result, mHashTable[ToHash^]);
|
||||
Inc(ToHash);
|
||||
end;
|
||||
While (ToHash^ In ['0'..'9']) do begin
|
||||
Inc(Result, (Ord(ToHash^) - Ord('0')) );
|
||||
Inc(ToHash);
|
||||
end;
|
||||
FStringLen := (ToHash - FToIdent);
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.LFProc;
|
||||
begin
|
||||
FTokenID := tkSpace;
|
||||
inc(Run);
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.MakeMethodTables;
|
||||
var
|
||||
ch: Char;
|
||||
begin
|
||||
for ch := #0 to #255 do
|
||||
case ch of
|
||||
#0 : FProcTable[ch] := @NullProc;
|
||||
#10 : FProcTable[ch] := @LFProc;
|
||||
#13 : FProcTable[ch] := @CRProc;
|
||||
#1..#9, #11, #12, #14..#32 : FProcTable[ch] := @SpaceProc;
|
||||
'"' : FProcTable[ch] := @StringProc;
|
||||
'0'..'9' : FProcTable[ch] := @NumberProc;
|
||||
'A'..'Z', 'a'..'z', '_','@' : FProcTable[ch] := @IdentProc;
|
||||
'&' : FProcTable[ch] := @AmpersandProc;
|
||||
'<' : FProcTable[ch] := @CommentProc;
|
||||
'{' : FProcTable[ch] := @BeginProc;
|
||||
'|' : FProcTable[ch] := @BarProc;
|
||||
'!' : FProcTable[ch] := @ExclamProc;
|
||||
|
||||
// '{', '}' : FProcTable[ch] := @AsciiCharProc;
|
||||
// '-' : FProcTable[ch] := @DashProc;
|
||||
// '#', '$' : FProcTable[ch] := @IntegerProc;
|
||||
// ')', '(' : FProcTable[ch] := @RoundOpenProc;
|
||||
// '/' : FProcTable[ch] := @SlashProc;
|
||||
else
|
||||
FProcTable[ch] := @UnknownProc;
|
||||
end;
|
||||
end;
|
||||
(*
|
||||
var
|
||||
i: Char;
|
||||
begin
|
||||
For i := #0 To #255 do begin
|
||||
case i of
|
||||
#0 : FProcTable[i] := @NullProc;
|
||||
#10 : FProcTable[i] := @LFProc;
|
||||
#13 : FProcTable[i] := @CRProc;
|
||||
#1..#9, #11, #12, #14..#32 : FProcTable[i] := @SpaceProc;
|
||||
'"' : FProcTable[i] := @StringProc;
|
||||
// '<' : FProcTable[i] := @BraceOpenProc;
|
||||
// '>' : FProcTable[i] := @BraceCloseProc;
|
||||
{ '&':
|
||||
begin
|
||||
fProcTable[i] := @AmpersandProc;
|
||||
end;
|
||||
'=':
|
||||
begin
|
||||
fProcTable[i] := @EqualProc;
|
||||
end;
|
||||
}
|
||||
else
|
||||
fProcTable[i] := @IdentProc;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
*)
|
||||
procedure TSynWikiTableSyn.Next;
|
||||
begin
|
||||
FTokenPos := Run;
|
||||
case FRange of
|
||||
rsText : TextProc;
|
||||
rsComment : CommentProc;
|
||||
else FProcTable[FLine[Run]];
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
if FRange = rsCStyle then
|
||||
CStyleCommentProc
|
||||
else
|
||||
FProcTable[FLine[Run]]();
|
||||
}
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.NullProc;
|
||||
begin
|
||||
fTokenID := tkNull;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.NumberProc;
|
||||
begin
|
||||
inc(Run);
|
||||
FTokenID := tkNumber;
|
||||
while FLine[Run] in ['0'..'9', '.', 'e', 'E'] do begin
|
||||
if ((FLine[Run] = '.') and (FLine[Run + 1] = '.')) or
|
||||
((FLine[Run] = 'e') and ((FLine[Run + 1] = 'x') or (FLine[Run + 1] = 'm'))) then
|
||||
Break;
|
||||
Inc(Run);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.SetLine(const NewValue: String; LineNumber: Integer);
|
||||
begin
|
||||
inherited;
|
||||
FLine := PChar(NewValue);
|
||||
Run := 0;
|
||||
FLineNumber := LineNumber;
|
||||
Next;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.SpaceProc;
|
||||
begin
|
||||
inc(Run);
|
||||
FTokenID := tkSpace;
|
||||
while FLine[Run] <= #32 do begin
|
||||
if FLine[Run] in [#0, #9, #10, #13] then break;
|
||||
inc(Run);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.StringProc;
|
||||
begin
|
||||
(*
|
||||
if (FRange = rsValue) then begin
|
||||
FRange := rsParam;
|
||||
FTokenID := tkValue;
|
||||
end else begin
|
||||
fTokenID := tkString;
|
||||
end;
|
||||
*)
|
||||
FTokenID := tkString;
|
||||
inc(Run); // first '"'
|
||||
while not (FLine[Run] in [#0, #10, #13, '"']) do inc(Run);
|
||||
if FLine[Run] = '"' then inc(Run); // last '"'
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.TextProc;
|
||||
const
|
||||
StopSet = [#0..#31, '<', '&', '{', '|'];
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if FLine[Run] in (StopSet - ['&']) then begin
|
||||
FProcTable[fLine[Run]];
|
||||
exit;
|
||||
end;
|
||||
|
||||
FTokenID := tkText;
|
||||
while True do begin
|
||||
while not (FLine[Run] in StopSet) do inc(Run);
|
||||
|
||||
if (FLine[Run] = '&') then begin
|
||||
for i:=Low(EscapeAmps) To High(EscapeAmps) do begin
|
||||
if (StrLIComp((fLine + Run), PChar(EscapeAmps[i]), StrLen(EscapeAmps[i])) = 0) then begin
|
||||
fAmpersandCode := i;
|
||||
fRange := rsAmpersand;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
Inc(Run);
|
||||
end else begin
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynWikiTableSyn.UnknownProc;
|
||||
begin
|
||||
inc(Run);
|
||||
while (FLine[Run] in [#128..#191]) or // continued utf8 subcode
|
||||
((FLine[Run] <> #0) and (FProcTable[fLine[Run]] = @UnknownProc)) do inc(Run);
|
||||
FTokenID := tkUnknown;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="wikitablemaker"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<Language Value=""/>
|
||||
<CharSet Value=""/>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="3">
|
||||
<Item1 Name="default" Default="True"/>
|
||||
<Item2 Name="Debug">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="wikitablemaker"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="../.."/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</Item2>
|
||||
<Item3 Name="Release">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="wikitablemaker"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<SmartLinkUnit Value="True"/>
|
||||
<Optimizations>
|
||||
<OptimizationLevel Value="3"/>
|
||||
</Optimizations>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
</Debugging>
|
||||
<LinkSmart Value="True"/>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</Item3>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="3">
|
||||
<Item1>
|
||||
<PackageName Value="LazControls"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="SynEdit"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item3>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Unit0>
|
||||
<Filename Value="wikitablemaker.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="wtmain.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="MainFrm"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="wtMain"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="wtmain.lfm"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit2>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="wikitablemaker"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="..\.."/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<UseExternalDbgSyms Value="True"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="5">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
<Item4>
|
||||
<Name Value="Exception"/>
|
||||
</Item4>
|
||||
<Item5>
|
||||
<Name Value="EStreamError"/>
|
||||
</Item5>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,17 @@
|
||||
program wikitablemaker;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, lazcontrols, wtMain;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TMainFrm, MainFrm);
|
||||
MainFrm.BeforeRun;
|
||||
Application.Run;
|
||||
end.
|
||||
|
3808
components/fpspreadsheet/examples/wikitablemaker/wtmain.lfm
Normal file
3808
components/fpspreadsheet/examples/wikitablemaker/wtmain.lfm
Normal file
File diff suppressed because it is too large
Load Diff
826
components/fpspreadsheet/examples/wikitablemaker/wtmain.pas
Normal file
826
components/fpspreadsheet/examples/wikitablemaker/wtmain.pas
Normal file
@ -0,0 +1,826 @@
|
||||
unit wtMain;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, Menus, ExtCtrls, ComCtrls, ActnList, Grids, ColorBox,
|
||||
SynEdit, SynEditHighlighter,
|
||||
SynHighlighterHTML, SynHighlighterMulti, SynHighlighterCss,
|
||||
fpspreadsheetgrid, fpspreadsheet, fpsallformats;
|
||||
|
||||
type
|
||||
|
||||
{ TMainFrm }
|
||||
|
||||
TMainFrm = class(TForm)
|
||||
AcOpen: TAction;
|
||||
AcSaveAs: TAction;
|
||||
AcQuit: TAction;
|
||||
AcLeftAlign: TAction;
|
||||
AcHorCenterAlign: TAction;
|
||||
AcRightAlign: TAction;
|
||||
AcHorDefaultAlign: TAction;
|
||||
AcFontBold: TAction;
|
||||
AcFontItalic: TAction;
|
||||
AcFontStrikeout: TAction;
|
||||
AcFontUnderline: TAction;
|
||||
AcDefaultFont: TAction;
|
||||
AcBorderTop: TAction;
|
||||
AcBorderBottom: TAction;
|
||||
AcBorderBottomDbl: TAction;
|
||||
AcBorderBottomMedium: TAction;
|
||||
AcBorderLeft: TAction;
|
||||
AcBorderRight: TAction;
|
||||
AcBorderNone: TAction;
|
||||
AcBorderHCenter: TAction;
|
||||
AcBorderVCenter: TAction;
|
||||
AcBorderTopBottom: TAction;
|
||||
AcBorderTopBottomThick: TAction;
|
||||
AcBorderInner: TAction;
|
||||
AcBorderAll: TAction;
|
||||
AcBorderOuter: TAction;
|
||||
AcBorderOuterMedium: TAction;
|
||||
AcCopyFormat: TAction;
|
||||
AcNew: TAction;
|
||||
AcAddColumn: TAction;
|
||||
AcAddRow: TAction;
|
||||
AcMergeCells: TAction;
|
||||
AcShowHeaders: TAction;
|
||||
AcShowGridlines: TAction;
|
||||
AcDeleteColumn: TAction;
|
||||
AcDeleteRow: TAction;
|
||||
AcCopyToClipboard: TAction;
|
||||
AcColumnTitles: TAction;
|
||||
AcRowTitles: TAction;
|
||||
AcVAlignDefault: TAction;
|
||||
AcVAlignTop: TAction;
|
||||
AcVAlignCenter: TAction;
|
||||
AcVAlignBottom: TAction;
|
||||
ActionList: TActionList;
|
||||
MnuBorderBottom: TMenuItem;
|
||||
MnuBorderBottomDbl: TMenuItem;
|
||||
MnuBorderBottomThick: TMenuItem;
|
||||
MnuBorderInner: TMenuItem;
|
||||
MnuBorderLeft: TMenuItem;
|
||||
MnuBorderRight: TMenuItem;
|
||||
MnuBordersAll: TMenuItem;
|
||||
MnuBordersInner: TMenuItem;
|
||||
MnuBordersOuter: TMenuItem;
|
||||
MnuBordersOuterThick: TMenuItem;
|
||||
MnuBordersSeparator1: TMenuItem;
|
||||
MnuBordersSeparator2: TMenuItem;
|
||||
MnuBordersSeparator3: TMenuItem;
|
||||
MnuBordersSeparator4: TMenuItem;
|
||||
MnuBordersSeparator5: TMenuItem;
|
||||
MnuBorderTop: TMenuItem;
|
||||
MnuBorderTopBottom: TMenuItem;
|
||||
MnuBorderTopBottomThick: TMenuItem;
|
||||
MnuBorderVCenter: TMenuItem;
|
||||
MnuFileSeparator1: TMenuItem;
|
||||
MnuNew: TMenuItem;
|
||||
MnuNoBorders: TMenuItem;
|
||||
MnuTableSeparator1: TMenuItem;
|
||||
ToolbarBevel: TBevel;
|
||||
CbBackgroundColor: TColorBox;
|
||||
FontComboBox: TComboBox;
|
||||
FontDialog: TFontDialog;
|
||||
FontSizeComboBox: TComboBox;
|
||||
ImageList: TImageList;
|
||||
MainMenu: TMainMenu;
|
||||
MnuRowHeaders: TMenuItem;
|
||||
MnuColHeaders: TMenuItem;
|
||||
MnuDeleteCol: TMenuItem;
|
||||
MnuTableSeparator2: TMenuItem;
|
||||
MnuAddRow: TMenuItem;
|
||||
MnuTableSeparator3: TMenuItem;
|
||||
MnuGridlines: TMenuItem;
|
||||
MnuAddCol: TMenuItem;
|
||||
MnuFormatSeparator: TMenuItem;
|
||||
MnuMergeCells: TMenuItem;
|
||||
MnuDeleteRow: TMenuItem;
|
||||
MnuLeftAlignment: TMenuItem;
|
||||
MnuCenterAlignment: TMenuItem;
|
||||
MnuRightAligment: TMenuItem;
|
||||
MnuHorAlignmentSeparator: TMenuItem;
|
||||
MnuVertAlignmentSeparator: TMenuItem;
|
||||
MnuVertBottom: TMenuItem;
|
||||
MnuVertCentered: TMenuItem;
|
||||
MnuVertTop: TMenuItem;
|
||||
MnuVertDefault: TMenuItem;
|
||||
MnuVertAlignment: TMenuItem;
|
||||
MnuFont: TMenuItem;
|
||||
MnuHorDefault: TMenuItem;
|
||||
MnuHorAlignment: TMenuItem;
|
||||
MnuFormat: TMenuItem;
|
||||
MnuTable: TMenuItem;
|
||||
MnuFile: TMenuItem;
|
||||
MnuOpen: TMenuItem;
|
||||
MnuQuit: TMenuItem;
|
||||
MnuSaveAs: TMenuItem;
|
||||
OpenDialog: TOpenDialog;
|
||||
BordersPopupMenu: TPopupMenu;
|
||||
PageControl: TPageControl;
|
||||
SaveDialog: TSaveDialog;
|
||||
SynCssSyn1: TSynCssSyn;
|
||||
SynEdit: TSynEdit;
|
||||
SynHTMLSyn1: TSynHTMLSyn;
|
||||
SynMultiSyn1: TSynMultiSyn;
|
||||
TabControl: TTabControl;
|
||||
PgTable: TTabSheet;
|
||||
PgCode: TTabSheet;
|
||||
CodeToolBar: TToolBar;
|
||||
TbDeleteColumn: TToolButton;
|
||||
TbAddRow: TToolButton;
|
||||
TbMergeCells: TToolButton;
|
||||
FormatToolBar: TToolBar;
|
||||
TbLeftAlign: TToolButton;
|
||||
TbFontStrikeout: TToolButton;
|
||||
TbHorCenterAlign: TToolButton;
|
||||
TbRightAlign: TToolButton;
|
||||
TbVAlignTop: TToolButton;
|
||||
TbVAlignCenter: TToolButton;
|
||||
TbVAlignBottom: TToolButton;
|
||||
TbBorders: TToolButton;
|
||||
TbCopyFormat: TToolButton;
|
||||
TbDefaultFont: TToolButton;
|
||||
TbDeleteRow: TToolButton;
|
||||
TbAddColumn: TToolButton;
|
||||
TbFontBold: TToolButton;
|
||||
TbFontItalic: TToolButton;
|
||||
TbFontUnderline: TToolButton;
|
||||
procedure AcAddColumnExecute(Sender: TObject);
|
||||
procedure AcAddRowExecute(Sender: TObject);
|
||||
procedure AcBorderExecute(Sender: TObject);
|
||||
procedure AcColumnTitlesExecute(Sender: TObject);
|
||||
procedure AcCopyFormatExecute(Sender: TObject);
|
||||
procedure AcCopyToClipboardExecute(Sender: TObject);
|
||||
procedure AcDeleteColumnExecute(Sender: TObject);
|
||||
procedure AcDeleteRowExecute(Sender: TObject);
|
||||
procedure AcDefaultFontExecute(Sender: TObject);
|
||||
procedure AcFontStyleExecute(Sender: TObject);
|
||||
procedure AcHorAlignmentExecute(Sender: TObject);
|
||||
procedure AcMergeCellsExecute(Sender: TObject);
|
||||
procedure AcNewExecute(Sender: TObject);
|
||||
procedure AcOpenExecute(Sender: TObject);
|
||||
procedure AcQuitExecute(Sender: TObject);
|
||||
procedure AcRowTitlesExecute(Sender: TObject);
|
||||
procedure AcSaveAsExecute(Sender: TObject);
|
||||
procedure AcShowGridlinesExecute(Sender: TObject);
|
||||
procedure AcShowHeadersExecute(Sender: TObject);
|
||||
procedure AcVertAlignmentExecute(Sender: TObject);
|
||||
procedure AcWordwrapExecute(Sender: TObject);
|
||||
procedure CbBackgroundColorSelect(Sender: TObject);
|
||||
procedure CbBackgroundColorGetColors(Sender: TCustomColorBox; Items: TStrings);
|
||||
procedure FontComboBoxSelect(Sender: TObject);
|
||||
procedure FontSizeComboBoxSelect(Sender: TObject);
|
||||
procedure FormActivate(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure PageControlChange(Sender: TObject);
|
||||
procedure TabControlChange(Sender: TObject);
|
||||
procedure WorksheetGridSelection(Sender: TObject; aCol, aRow: Integer);
|
||||
private
|
||||
WorksheetGrid: TsWorksheetGrid;
|
||||
FCopiedFormat: TCell;
|
||||
FHighlighter: TSynCustomHighlighter;
|
||||
procedure LoadFile(const AFileName: String);
|
||||
procedure SetupBackgroundColorBox;
|
||||
procedure UpdateBackgroundColorIndex;
|
||||
procedure UpdateFontNameIndex;
|
||||
procedure UpdateFontSizeIndex;
|
||||
procedure UpdateFontStyleActions;
|
||||
procedure UpdateHorAlignmentActions;
|
||||
procedure UpdateVertAlignmentActions;
|
||||
|
||||
public
|
||||
procedure BeforeRun;
|
||||
|
||||
end;
|
||||
|
||||
var
|
||||
MainFrm: TMainFrm;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
TypInfo, LCLIntf, LCLType, clipbrd, fpcanvas,
|
||||
SynHighlighterWikiTable,
|
||||
fpsutils;
|
||||
|
||||
const
|
||||
DROPDOWN_COUNT = 24;
|
||||
|
||||
HORALIGN_TAG = 100;
|
||||
VERTALIGN_TAG = 110;
|
||||
|
||||
LEFT_BORDER_THIN = $0001;
|
||||
LEFT_BORDER_THICK = $0002;
|
||||
LR_INNER_BORDER_THIN = $0008;
|
||||
RIGHT_BORDER_THIN = $0010;
|
||||
RIGHT_BORDER_THICK = $0020;
|
||||
TOP_BORDER_THIN = $0100;
|
||||
TOP_BORDER_THICK = $0200;
|
||||
TB_INNER_BORDER_THIN = $0800;
|
||||
BOTTOM_BORDER_THIN = $1000;
|
||||
BOTTOM_BORDER_THICK = $2000;
|
||||
BOTTOM_BORDER_DOUBLE = $3000;
|
||||
LEFT_BORDER_MASK = $0007;
|
||||
RIGHT_BORDER_MASK = $0070;
|
||||
TOP_BORDER_MASK = $0700;
|
||||
BOTTOM_BORDER_MASK = $7000;
|
||||
LR_INNER_BORDER = $0008;
|
||||
TB_INNER_BORDER = $0800;
|
||||
// Use a combination of these bits for the "Tag" of the Border actions - see FormCreate.
|
||||
|
||||
|
||||
{ TMainFrm }
|
||||
|
||||
procedure TMainFrm.AcBorderExecute(Sender: TObject);
|
||||
const
|
||||
LINESTYLES: Array[1..3] of TsLinestyle = (lsThin, lsMedium, lsDouble);
|
||||
var
|
||||
r,c: Integer;
|
||||
ls: integer;
|
||||
bs: TsCellBorderStyle;
|
||||
begin
|
||||
bs.Color := scBlack;
|
||||
|
||||
with WorksheetGrid do begin
|
||||
TbBorders.Action := TAction(Sender);
|
||||
|
||||
BeginUpdate;
|
||||
try
|
||||
if TAction(Sender).Tag = 0 then begin
|
||||
CellBorders[Selection] := [];
|
||||
exit;
|
||||
end;
|
||||
// Top and bottom edges
|
||||
for c := Selection.Left to Selection.Right do begin
|
||||
ls := (TAction(Sender).Tag and TOP_BORDER_MASK) shr 8;
|
||||
if (ls <> 0) then begin
|
||||
CellBorder[c, Selection.Top] := CellBorder[c, Selection.Top] + [cbNorth];
|
||||
bs.LineStyle := LINESTYLES[ls];
|
||||
CellBorderStyle[c, Selection.Top, cbNorth] := bs;
|
||||
end;
|
||||
ls := (TAction(Sender).Tag and BOTTOM_BORDER_MASK) shr 12;
|
||||
if ls <> 0 then begin
|
||||
CellBorder[c, Selection.Bottom] := CellBorder[c, Selection.Bottom] + [cbSouth];
|
||||
bs.LineStyle := LINESTYLES[ls];
|
||||
CellBorderStyle[c, Selection.Bottom, cbSouth] := bs;
|
||||
end;
|
||||
end;
|
||||
// Left and right edges
|
||||
for r := Selection.Top to Selection.Bottom do begin
|
||||
ls := (TAction(Sender).Tag and LEFT_BORDER_MASK);
|
||||
if ls <> 0 then begin
|
||||
CellBorder[Selection.Left, r] := CellBorder[Selection.Left, r] + [cbWest];
|
||||
bs.LineStyle := LINESTYLES[ls];
|
||||
CellBorderStyle[Selection.Left, r, cbWest] := bs;
|
||||
end;
|
||||
ls := (TAction(Sender).Tag and RIGHT_BORDER_MASK) shr 4;
|
||||
if ls <> 0 then begin
|
||||
CellBorder[Selection.Right, r] := CellBorder[Selection.Right, r] + [cbEast];
|
||||
bs.LineStyle := LINESTYLES[ls];
|
||||
CellBorderStyle[Selection.Right, r, cbEast] := bs;
|
||||
end;
|
||||
end;
|
||||
// Inner edges along row (vertical border lines) - we assume only thin lines.
|
||||
bs.LineStyle := lsThin;
|
||||
if (TAction(Sender).Tag and LR_INNER_BORDER <> 0) and (Selection.Right > Selection.Left)
|
||||
then
|
||||
for r := Selection.Top to Selection.Bottom do begin
|
||||
CellBorder[Selection.Left, r] := CellBorder[Selection.Left, r] + [cbEast];
|
||||
CellBorderStyle[Selection.Left, r, cbEast] := bs;
|
||||
for c := Selection.Left+1 to Selection.Right-1 do begin
|
||||
CellBorder[c,r] := CellBorder[c, r] + [cbEast, cbWest];
|
||||
CellBorderStyle[c, r, cbEast] := bs;
|
||||
CellBorderStyle[c, r, cbWest] := bs;
|
||||
end;
|
||||
CellBorder[Selection.Right, r] := CellBorder[Selection.Right, r] + [cbWest];
|
||||
CellBorderStyle[Selection.Right, r, cbWest] := bs;
|
||||
end;
|
||||
// Inner edges along column (horizontal border lines)
|
||||
if (TAction(Sender).Tag and TB_INNER_BORDER <> 0) and (Selection.Bottom > Selection.Top)
|
||||
then
|
||||
for c := Selection.Left to Selection.Right do begin
|
||||
CellBorder[c, Selection.Top] := CellBorder[c, Selection.Top] + [cbSouth];
|
||||
CellBorderStyle[c, Selection.Top, cbSouth] := bs;
|
||||
for r := Selection.Top+1 to Selection.Bottom-1 do begin
|
||||
CellBorder[c, r] := CellBorder[c, r] + [cbNorth, cbSouth];
|
||||
CellBorderStyle[c, r, cbNorth] := bs;
|
||||
CellBorderStyle[c, r, cbSouth] := bs;
|
||||
end;
|
||||
CellBorder[c, Selection.Bottom] := CellBorder[c, Selection.Bottom] + [cbNorth];
|
||||
CellBorderStyle[c, Selection.Bottom, cbNorth] := bs;
|
||||
end;
|
||||
finally
|
||||
EndUpdate;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcColumnTitlesExecute(Sender: TObject);
|
||||
begin
|
||||
if AcColumnTitles.Checked then
|
||||
WorksheetGrid.FrozenRows := 1
|
||||
else
|
||||
WorksheetGrid.FrozenRows := 0;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcAddColumnExecute(Sender: TObject);
|
||||
begin
|
||||
WorksheetGrid.InsertCol(WorksheetGrid.Col);
|
||||
WorksheetGrid.Col := WorksheetGrid.Col + 1;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcAddRowExecute(Sender: TObject);
|
||||
begin
|
||||
WorksheetGrid.InsertRow(WorksheetGrid.Row);
|
||||
WorksheetGrid.Row := WorksheetGrid.Row + 1;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcCopyFormatExecute(Sender: TObject);
|
||||
var
|
||||
cell: PCell;
|
||||
r, c: Cardinal;
|
||||
begin
|
||||
with WorksheetGrid do begin
|
||||
if Workbook = nil then
|
||||
exit;
|
||||
|
||||
if AcCopyFormat.Checked then begin
|
||||
r := GetWorksheetRow(Row);
|
||||
c := GetWorksheetCol(Col);
|
||||
cell := Worksheet.FindCell(r, c);
|
||||
if cell <> nil then
|
||||
FCopiedFormat := cell^;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcCopyToClipboardExecute(Sender: TObject);
|
||||
begin
|
||||
if SynEdit.Lines.Count > 0 then
|
||||
Clipboard.AsText := SynEdit.Lines.Text;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcDeleteColumnExecute(Sender: TObject);
|
||||
var
|
||||
c: Integer;
|
||||
begin
|
||||
c := WorksheetGrid.Col;
|
||||
WorksheetGrid.DeleteCol(c);
|
||||
WorksheetGrid.Col := c;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcDeleteRowExecute(Sender: TObject);
|
||||
var
|
||||
r: Integer;
|
||||
begin
|
||||
r := WorksheetGrid.Row;
|
||||
WorksheetGrid.DeleteRow(r);
|
||||
WorksheetGrid.Row := r;
|
||||
end;
|
||||
|
||||
{ Changes the default font of the workbook by calling a standard font dialog. }
|
||||
procedure TMainFrm.AcDefaultFontExecute(Sender: TObject);
|
||||
begin
|
||||
with WorksheetGrid do begin
|
||||
if Workbook = nil then
|
||||
exit;
|
||||
Convert_sFont_to_Font(Workbook.GetDefaultFont, FontDialog.Font);
|
||||
if FontDialog.Execute then begin
|
||||
Workbook.SetDefaultFont(FontDialog.Font.Name, FontDialog.Font.Size);
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcFontStyleExecute(Sender: TObject);
|
||||
var
|
||||
style: TsFontstyles;
|
||||
begin
|
||||
with WorksheetGrid do begin
|
||||
if Workbook = nil then
|
||||
exit;
|
||||
style := [];
|
||||
if AcFontBold.Checked then Include(style, fssBold);
|
||||
if AcFontItalic.Checked then Include(style, fssItalic);
|
||||
if AcFontStrikeout.Checked then Include(style, fssStrikeout);
|
||||
if AcFontUnderline.Checked then Include(style, fssUnderline);
|
||||
CellFontStyles[Selection] := style;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcHorAlignmentExecute(Sender: TObject);
|
||||
var
|
||||
hor_align: TsHorAlignment;
|
||||
begin
|
||||
if TAction(Sender).Checked then
|
||||
hor_align := TsHorAlignment(TAction(Sender).Tag - HORALIGN_TAG)
|
||||
else
|
||||
hor_align := haDefault;
|
||||
with WorksheetGrid do HorAlignments[Selection] := hor_align;
|
||||
UpdateHorAlignmentActions;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcMergeCellsExecute(Sender: TObject);
|
||||
begin
|
||||
AcMergeCells.Checked := not AcMergeCells.Checked;
|
||||
if AcMergeCells.Checked then
|
||||
WorksheetGrid.MergeCells
|
||||
else
|
||||
WorksheetGrid.UnmergeCells;
|
||||
WorksheetGridSelection(nil, WorksheetGrid.Col, WorksheetGrid.Row);
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcNewExecute(Sender: TObject);
|
||||
begin
|
||||
WorksheetGrid.NewWorkbook(26, 100);
|
||||
|
||||
WorksheetGrid.BeginUpdate;
|
||||
try
|
||||
WorksheetGrid.Col := WorksheetGrid.FixedCols;
|
||||
WorksheetGrid.Row := WorksheetGrid.FixedRows;
|
||||
SetupBackgroundColorBox;
|
||||
WorksheetGridSelection(nil, WorksheetGrid.Col, WorksheetGrid.Row);
|
||||
finally
|
||||
WorksheetGrid.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcOpenExecute(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog.Execute then
|
||||
LoadFile(OpenDialog.FileName);
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcQuitExecute(Sender: TObject);
|
||||
begin
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcRowTitlesExecute(Sender: TObject);
|
||||
begin
|
||||
if AcRowTitles.Checked then
|
||||
WorksheetGrid.FrozenCols := 1
|
||||
else
|
||||
WorksheetGrid.FrozenCols := 0;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcSaveAsExecute(Sender: TObject);
|
||||
// Saves sheet in grid to file, overwriting existing file
|
||||
var
|
||||
err: String = '';
|
||||
begin
|
||||
if WorksheetGrid.Workbook = nil then
|
||||
exit;
|
||||
|
||||
if SaveDialog.Execute then
|
||||
begin
|
||||
Screen.Cursor := crHourglass;
|
||||
try
|
||||
WorksheetGrid.SaveToSpreadsheetFile(SaveDialog.FileName);
|
||||
finally
|
||||
Screen.Cursor := crDefault;
|
||||
err := WorksheetGrid.Workbook.ErrorMsg;
|
||||
if err <> '' then
|
||||
MessageDlg(err, mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcShowGridlinesExecute(Sender: TObject);
|
||||
begin
|
||||
WorksheetGrid.ShowGridLines := AcShowGridLines.Checked;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcShowHeadersExecute(Sender: TObject);
|
||||
begin
|
||||
WorksheetGrid.ShowHeaders := AcShowHeaders.Checked;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcVertAlignmentExecute(Sender: TObject);
|
||||
var
|
||||
vert_align: TsVertAlignment;
|
||||
begin
|
||||
if TAction(Sender).Checked then
|
||||
vert_align := TsVertAlignment(TAction(Sender).Tag - VERTALIGN_TAG)
|
||||
else
|
||||
vert_align := vaDefault;
|
||||
with WorksheetGrid do VertAlignments[Selection] := vert_align;
|
||||
UpdateVertAlignmentActions;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.AcWordwrapExecute(Sender: TObject);
|
||||
begin
|
||||
with WorksheetGrid do Wordwraps[Selection] := TAction(Sender).Checked;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.BeforeRun;
|
||||
begin
|
||||
if ParamCount > 0 then
|
||||
LoadFile(ParamStr(1));
|
||||
end;
|
||||
|
||||
procedure TMainFrm.CbBackgroundColorGetColors(Sender: TCustomColorBox; Items: TStrings);
|
||||
var
|
||||
clr: TColor;
|
||||
clrName: String;
|
||||
i: Integer;
|
||||
begin
|
||||
if (WorksheetGrid <> nil) and (WorksheetGrid.Workbook <> nil) then begin
|
||||
Items.Clear;
|
||||
Items.AddObject('no fill', TObject(PtrInt(clNone)));
|
||||
for i:=0 to WorksheetGrid.Workbook.GetPaletteSize-1 do begin
|
||||
clr := WorksheetGrid.Workbook.GetPaletteColor(i);
|
||||
clrName := WorksheetGrid.Workbook.GetColorName(i);
|
||||
Items.AddObject(Format('%d: %s', [i, clrName]), TObject(PtrInt(clr)));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.CbBackgroundColorSelect(Sender: TObject);
|
||||
begin
|
||||
if CbBackgroundColor.ItemIndex <= 0 then
|
||||
with WorksheetGrid do BackgroundColors[Selection] := scNotDefined
|
||||
else
|
||||
with WorksheetGrid do BackgroundColors[Selection] := CbBackgroundColor.ItemIndex - 1;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.FontComboBoxSelect(Sender: TObject);
|
||||
var
|
||||
fname: String;
|
||||
begin
|
||||
fname := FontCombobox.Items[FontCombobox.ItemIndex];
|
||||
if fname <> '' then
|
||||
with WorksheetGrid do CellFontNames[Selection] := fName;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.FontSizeComboBoxSelect(Sender: TObject);
|
||||
var
|
||||
sz: Integer;
|
||||
begin
|
||||
sz := StrToInt(FontSizeCombobox.Items[FontSizeCombobox.ItemIndex]);
|
||||
if sz > 0 then
|
||||
with WorksheetGrid do CellFontSizes[Selection] := sz;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.FormActivate(Sender: TObject);
|
||||
begin
|
||||
WorksheetGridSelection(nil, WorksheetGrid.Col, WorksheetGrid.Row);
|
||||
end;
|
||||
|
||||
procedure TMainFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
// Create the worksheet grid
|
||||
WorksheetGrid := TsWorksheetGrid.Create(self);
|
||||
with WorksheetGrid do begin
|
||||
Parent := TabControl;
|
||||
Align := alClient;
|
||||
AutoAdvance := aaDown;
|
||||
BorderStyle := bsNone;
|
||||
MouseWheelOption := mwGrid;
|
||||
Options := [goEditing, goFixedVertLine, goFixedHorzLine, goVertLine,
|
||||
goHorzLine, goRangeSelect, goRowSizing, goColSizing, goThumbTracking,
|
||||
goSmoothScroll, goFixedColSizing];
|
||||
TitleStyle := tsNative;
|
||||
OnSelection := @WorksheetGridSelection;
|
||||
end;
|
||||
|
||||
// Create the syntax highlighter
|
||||
FHighlighter := TSynWikitableSyn.Create(self);
|
||||
SynEdit.Highlighter := FHighlighter;
|
||||
// SynEdit.Highlighter := SynCSSSyn1;
|
||||
|
||||
// Adjust format toolbar height, looks strange at 120 dpi
|
||||
//FormatToolbar.Height := FontCombobox.Height + 2*FontCombobox.Top;
|
||||
//FormatToolbar.ButtonHeight := FormatToolbar.Height - 4;
|
||||
|
||||
|
||||
// Set the Tags of the Border actions
|
||||
AcBorderNone.Tag := 0;
|
||||
AcBorderLeft.Tag := LEFT_BORDER_THIN;
|
||||
AcBorderHCenter.Tag := LR_INNER_BORDER_THIN;
|
||||
AcBorderRight.Tag := RIGHT_BORDER_THIN;
|
||||
AcBorderTop.Tag := TOP_BORDER_THIN;
|
||||
AcBorderVCenter.Tag := TB_INNER_BORDER_THIN;
|
||||
AcBorderBottom.Tag := BOTTOM_BORDER_THIN;
|
||||
AcBorderBottomDbl.Tag := BOTTOM_BORDER_DOUBLE;
|
||||
AcBorderBottomMedium.Tag := BOTTOM_BORDER_THICK;
|
||||
AcBorderTopBottom.Tag := TOP_BORDER_THIN + BOTTOM_BORDER_THIN;
|
||||
AcBorderTopBottomThick.Tag := TOP_BORDER_THIN + BOTTOM_BORDER_THICK;
|
||||
AcBorderInner.Tag := LR_INNER_BORDER_THIN + TB_INNER_BORDER_THIN;
|
||||
AcBorderOuter.Tag := LEFT_BORDER_THIN + RIGHT_BORDER_THIN + TOP_BORDER_THIN + BOTTOM_BORDER_THIN;
|
||||
AcBorderOuterMedium.Tag := LEFT_BORDER_THICK + RIGHT_BORDER_THICK + TOP_BORDER_THICK + BOTTOM_BORDER_THICK;
|
||||
AcBorderAll.Tag := AcBorderOuter.Tag + AcBorderInner.Tag;
|
||||
|
||||
// Some initialization
|
||||
FontCombobox.Items.Assign(Screen.Fonts); // Populate font combobox
|
||||
FontCombobox.DropDownCount := DROPDOWN_COUNT;
|
||||
FontSizeCombobox.DropDownCount := DROPDOWN_COUNT;
|
||||
CbBackgroundColor.DropDownCount := DROPDOWN_COUNT;
|
||||
// CbBackgroundColor.ItemHeight := FontCombobox.ItemHeight;
|
||||
CbBackgroundColor.ColorRectWidth := CbBackgroundColor.ItemHeight - 6; // to get a square box...
|
||||
|
||||
// Initialize a new empty workbook
|
||||
AcNewExecute(nil);
|
||||
|
||||
// Acitve control etc.
|
||||
PageControl.ActivePage := PgTable;
|
||||
ActiveControl := WorksheetGrid;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.PageControlChange(Sender: TObject);
|
||||
var
|
||||
stream: TMemoryStream;
|
||||
begin
|
||||
// Switch toolbars according to the selection of the pagecontrol
|
||||
CodeToolbar.Visible := PageControl.ActivePage = PgCode;
|
||||
FormatToolbar.Visible := PageControl.ActivePage = PgTable;
|
||||
ToolbarBevel.Top := Height;
|
||||
|
||||
if (WorksheetGrid = nil) or (WorksheetGrid.Workbook = nil) then
|
||||
exit;
|
||||
|
||||
if PageControl.ActivePage = PgCode then begin
|
||||
stream := TMemoryStream.Create;
|
||||
try
|
||||
WorksheetGrid.Workbook.WriteToStream(stream, sfWikitable_wikimedia);
|
||||
stream.Position := 0;
|
||||
SynEdit.Lines.LoadFromStream(stream);
|
||||
finally
|
||||
stream.Free;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.LoadFile(const AFileName: String);
|
||||
// Loads first worksheet from file into grid
|
||||
var
|
||||
pages: TStrings;
|
||||
i: Integer;
|
||||
err: String;
|
||||
begin
|
||||
// Load file
|
||||
Screen.Cursor := crHourglass;
|
||||
try
|
||||
try
|
||||
WorksheetGrid.LoadFromSpreadsheetFile(UTF8ToSys(AFileName));
|
||||
except
|
||||
on E: Exception do begin
|
||||
// In an error occurs show at least an empty valid worksheet
|
||||
AcNewExecute(nil);
|
||||
MessageDlg(E.Message, mtError, [mbOk], 0);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
// Update user interface
|
||||
Caption := Format('spready - %s (%s)', [
|
||||
AFilename,
|
||||
GetFileFormatName(WorksheetGrid.Workbook.FileFormat)
|
||||
]);
|
||||
AcShowGridLines.Checked := WorksheetGrid.ShowGridLines;
|
||||
AcShowHeaders.Checked := WorksheetGrid.ShowHeaders;
|
||||
AcRowTitles.Checked := WorksheetGrid.FrozenCols <> 0;
|
||||
AcColumnTitles.Checked := WorksheetGrid.FrozenRows <> 0;
|
||||
SetupBackgroundColorBox;
|
||||
|
||||
// Load names of worksheets into tabcontrol and show first sheet
|
||||
WorksheetGrid.GetSheets(TabControl.Tabs);
|
||||
TabControl.TabIndex := 0;
|
||||
// Update display
|
||||
WorksheetGridSelection(nil, WorksheetGrid.Col, WorksheetGrid.Row);
|
||||
|
||||
finally
|
||||
Screen.Cursor := crDefault;
|
||||
|
||||
err := WorksheetGrid.Workbook.ErrorMsg;
|
||||
if err <> '' then
|
||||
MessageDlg(err, mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.SetupBackgroundColorBox;
|
||||
begin
|
||||
// This change triggers re-reading of the workbooks palette by the OnGetColors
|
||||
// event of the ColorBox.
|
||||
CbBackgroundColor.Style := CbBackgroundColor.Style - [cbCustomColors];
|
||||
CbBackgroundColor.Style := CbBackgroundColor.Style + [cbCustomColors];
|
||||
Application.ProcessMessages;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.TabControlChange(Sender: TObject);
|
||||
begin
|
||||
WorksheetGrid.SelectSheetByIndex(TabControl.TabIndex);
|
||||
WorksheetGridSelection(self, WorksheetGrid.Col, WorksheetGrid.Row);
|
||||
end;
|
||||
|
||||
procedure TMainFrm.UpdateBackgroundColorIndex;
|
||||
var
|
||||
sClr: TsColor;
|
||||
begin
|
||||
with WorksheetGrid do sClr := BackgroundColors[Selection];
|
||||
if sClr = scNotDefined then
|
||||
CbBackgroundColor.ItemIndex := 0 // no fill
|
||||
else
|
||||
CbBackgroundColor.ItemIndex := sClr + 1;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.UpdateHorAlignmentActions;
|
||||
var
|
||||
i: Integer;
|
||||
ac: TAction;
|
||||
hor_align: TsHorAlignment;
|
||||
begin
|
||||
with WorksheetGrid do hor_align := HorAlignments[Selection];
|
||||
for i:=0 to ActionList.ActionCount-1 do begin
|
||||
ac := TAction(ActionList.Actions[i]);
|
||||
if (ac.Tag >= HORALIGN_TAG) and (ac.Tag < HORALIGN_TAG+10) then
|
||||
ac.Checked := ((ac.Tag - HORALIGN_TAG) = ord(hor_align));
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.UpdateFontNameIndex;
|
||||
var
|
||||
fname: String;
|
||||
begin
|
||||
with WorksheetGrid do fname := CellFontNames[Selection];
|
||||
if fname = '' then
|
||||
FontCombobox.ItemIndex := -1
|
||||
else
|
||||
FontCombobox.ItemIndex := FontCombobox.Items.IndexOf(fname);
|
||||
end;
|
||||
|
||||
procedure TMainFrm.UpdateFontSizeIndex;
|
||||
var
|
||||
sz: Single;
|
||||
begin
|
||||
with WorksheetGrid do sz := CellFontSizes[Selection];
|
||||
if sz < 0 then
|
||||
FontSizeCombobox.ItemIndex := -1
|
||||
else
|
||||
FontSizeCombobox.ItemIndex := FontSizeCombobox.Items.IndexOf(IntToStr(Round(sz)));
|
||||
end;
|
||||
|
||||
procedure TMainFrm.UpdateFontStyleActions;
|
||||
var
|
||||
style: TsFontStyles;
|
||||
begin
|
||||
with WorksheetGrid do style := CellFontStyles[Selection];
|
||||
AcFontBold.Checked := fssBold in style;
|
||||
AcFontItalic.Checked := fssItalic in style;
|
||||
AcFontUnderline.Checked := fssUnderline in style;
|
||||
AcFontStrikeout.Checked := fssStrikeOut in style;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.UpdateVertAlignmentActions;
|
||||
var
|
||||
i: Integer;
|
||||
ac: TAction;
|
||||
vert_align: TsVertAlignment;
|
||||
begin
|
||||
with WorksheetGrid do vert_align := VertAlignments[Selection];
|
||||
for i:=0 to ActionList.ActionCount-1 do begin
|
||||
ac := TAction(ActionList.Actions[i]);
|
||||
if (ac.Tag >= VERTALIGN_TAG) and (ac.Tag < VERTALIGN_TAG+10) then
|
||||
ac.Checked := ((ac.Tag - VERTALIGN_TAG) = ord(vert_align));
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainFrm.WorksheetGridSelection(Sender: TObject; ACol, ARow: Integer);
|
||||
var
|
||||
r, c: Cardinal;
|
||||
cell: PCell;
|
||||
begin
|
||||
if WorksheetGrid.Workbook = nil then
|
||||
exit;
|
||||
|
||||
r := WorksheetGrid.GetWorksheetRow(ARow);
|
||||
c := WorksheetGrid.GetWorksheetCol(ACol);
|
||||
|
||||
if AcCopyFormat.Checked then begin
|
||||
WorksheetGrid.Worksheet.CopyFormat(@FCopiedFormat, r, c);
|
||||
AcCopyFormat.Checked := false;
|
||||
end;
|
||||
|
||||
cell := WorksheetGrid.Worksheet.FindCell(r, c);
|
||||
AcMergeCells.Checked := WorksheetGrid.Worksheet.IsMerged(cell);
|
||||
|
||||
UpdateHorAlignmentActions;
|
||||
UpdateVertAlignmentActions;
|
||||
UpdateBackgroundColorIndex;
|
||||
UpdateFontNameIndex;
|
||||
UpdateFontSizeIndex;
|
||||
UpdateFontStyleActions;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
{$I wtmain.lrs}
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user