diff --git a/examples/spreadsheet/main.lfm b/examples/spreadsheet/main.lfm index a0c179cdb5..7288478124 100644 --- a/examples/spreadsheet/main.lfm +++ b/examples/spreadsheet/main.lfm @@ -51,7 +51,7 @@ object Form1: TForm1 BorderSpacing.CellAlignHorizontal = ccaFill BorderSpacing.CellAlignVertical = ccaFill BorderStyle = bsSingle - ColCount = 255 + ColCount = 257 DefaultColWidth = 90 DefaultDrawing = True DragCursor = crDrag @@ -80,6 +80,7 @@ object Form1: TForm1 UseXORFeatures = False Visible = True OnBeforeSelection = gridBeforeSelection + OnDrawCell = gridDrawCell OnPrepareCanvas = gridPrepareCanvas ColWidths = ( 43 @@ -337,6 +338,8 @@ object Form1: TForm1 90 90 90 + 90 + 90 ) end end diff --git a/examples/spreadsheet/main.lrs b/examples/spreadsheet/main.lrs index 79ee155016..707503e7b7 100644 --- a/examples/spreadsheet/main.lrs +++ b/examples/spreadsheet/main.lrs @@ -19,8 +19,8 @@ LazarusResources.Add('TForm1','FORMDATA',[ +'erSpacing.Top'#2#0#19'BorderSpacing.Right'#2#0#20'BorderSpacing.Bottom'#2#0 +#20'BorderSpacing.Around'#2#0'!BorderSpacing.CellAlignHorizontal'#7#7'ccaFil' +'l'#31'BorderSpacing.CellAlignVertical'#7#7'ccaFill'#11'BorderStyle'#7#8'bsS' - +'ingle'#8'ColCount'#3#255#0#15'DefaultColWidth'#2'Z'#14'DefaultDrawing'#9#10 - +'DragCursor'#7#6'crDrag'#8'DragKind'#7#6'dkDrag'#8'DragMode'#7#8'dmManual'#7 + +'ingle'#8'ColCount'#3#1#1#15'DefaultColWidth'#2'Z'#14'DefaultDrawing'#9#10'D' + +'ragCursor'#7#6'crDrag'#8'DragKind'#7#6'dkDrag'#8'DragMode'#7#8'dmManual'#7 +'Enabled'#9#14'ExtendedSelect'#9#10'FixedColor'#7#9'clBtnFace'#9'FixedCols'#2 +#1#9'FixedRows'#2#1#4'Flat'#8#13'GridLineWidth'#2#1#14'HeaderHotZones'#11#11 +'gz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'Z'#2'Z'#2'Z'#2 +'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2 - +'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#0#0#0#0 + +'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2 + +'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#2'Z'#0#0#0#0 ]); diff --git a/examples/spreadsheet/main.pas b/examples/spreadsheet/main.pas index 68a2679fb6..cb4a3e7837 100644 --- a/examples/spreadsheet/main.pas +++ b/examples/spreadsheet/main.pas @@ -15,10 +15,13 @@ type TForm1 = class(TForm) grid: TStringGrid; procedure gridBeforeSelection(Sender: TObject; aCol, aRow: Integer); + procedure gridDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; + aState: TGridDrawState); procedure gridPrepareCanvas(sender: TObject; aCol, aRow: Integer; aState: TGridDrawState); private { private declarations } + function IndexToAlphaIndex(AIndex: Integer): string; public { public declarations } end; @@ -48,6 +51,40 @@ begin end; +procedure TForm1.gridDrawCell(Sender: TObject; aCol, aRow: Integer; + aRect: TRect; aState: TGridDrawState); + + procedure HorizontalCenter; + var + aTextStyle : TTextStyle; + begin + aTextStyle := grid.Canvas.TextStyle; + aTextStyle.Alignment:=taCenter; + grid.Canvas.TextStyle:=aTextStyle; + end; + +begin + + if gdFixed in aState then + begin + if (aCol=0) and (aRow>=Grid.FixedRows) then + begin + HorizontalCenter; + grid.Canvas.TextRect(aRect, aRect.Left, aRect.Top, IntToStr(aRow)); + exit; + end else + if (aRow=0) and (aCol>=Grid.FixedCols) then + begin + HorizontalCenter; + grid.Canvas.TextRect(aRect, aRect.Left, aRect.Top, + IndexToAlphaIndex(aCol-Grid.FixedCols)); + exit; + end; + end; + + grid.DefaultDrawCell(aCol,aRow,aRect,aState); +end; + procedure TForm1.gridPrepareCanvas(sender: TObject; aCol, aRow: Integer; aState: TGridDrawState); begin @@ -58,6 +95,19 @@ begin end; end; +function TForm1.IndexToAlphaIndex(AIndex: Integer): string; +var + i: Integer; +begin + Result := chr((AIndex mod 26) + ord('A')); + i := (AIndex div 26)-1; + if i>25 then + result := '['+IntToStr(AIndex)+']' + else + if i>=0 then + result := chr(i + ord('A')) + Result; +end; + initialization {$I main.lrs} diff --git a/examples/spreadsheet/spreadsheet.lpi b/examples/spreadsheet/spreadsheet.lpi index 6423e7f36b..a85a93e319 100644 --- a/examples/spreadsheet/spreadsheet.lpi +++ b/examples/spreadsheet/spreadsheet.lpi @@ -1,9 +1,13 @@ - + + + + + @@ -14,7 +18,6 @@ - @@ -22,7 +25,7 @@ - + @@ -48,7 +51,6 @@ - diff --git a/examples/spreadsheet/spreadsheet.rc b/examples/spreadsheet/spreadsheet.rc index c0ceb8e8da..ef81695027 100644 --- a/examples/spreadsheet/spreadsheet.rc +++ b/examples/spreadsheet/spreadsheet.rc @@ -1 +1 @@ -MAINICON ICON "D:\\lazarus\\source\\lazarus\\examples\\spreadsheet\\spreadsheet.ico" +MAINICON ICON "/home/prog/lazarus/examples/spreadsheet/spreadsheet.ico"