diff --git a/components/rx/trunk/demos/rxdbgrid/MergeCell/project1.lps b/components/rx/trunk/demos/rxdbgrid/MergeCell/project1.lps index e7fda2701..ca885a074 100644 --- a/components/rx/trunk/demos/rxdbgrid/MergeCell/project1.lps +++ b/components/rx/trunk/demos/rxdbgrid/MergeCell/project1.lps @@ -3,7 +3,7 @@ - + @@ -11,7 +11,7 @@ - + @@ -20,40 +20,40 @@ + - - + + - - - + + + - + - - - - + + + + - - - - - + + + + @@ -72,16 +72,16 @@ - + - + - - + + @@ -107,11 +107,10 @@ - + - @@ -130,152 +129,178 @@ - - - + + + - - + - + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + - + + - - + + - - + + - - + + - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - - - - + - + + + + + + + + + + diff --git a/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.lfm b/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.lfm index 94c15b72b..77666edbc 100644 --- a/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.lfm +++ b/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.lfm @@ -18,6 +18,7 @@ object Form1: TForm1 AutoSort = True Columns = < item + Alignment = taCenter Title.Alignment = taCenter Title.Orientation = toHorizontal Title.Caption = 'CODE' @@ -30,6 +31,8 @@ object Form1: TForm1 Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 Footers = <> + WordWrap = True + OnDrawColumnCell = RxDBGrid1Columns0DrawColumnCell end item Title.Alignment = taCenter @@ -128,6 +131,7 @@ object Form1: TForm1 DataSource = dsData Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColumnMove, dgColLines, dgRowLines, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit] TabOrder = 0 + OnMergeCells = RxDBGrid1MergeCells end object Panel1: TPanel Left = 0 @@ -135,7 +139,6 @@ object Form1: TForm1 Top = 0 Width = 770 Align = alTop - Caption = 'Panel1' ClientHeight = 50 ClientWidth = 770 TabOrder = 1 @@ -151,20 +154,6 @@ object Form1: TForm1 OnChange = CheckBox1Change TabOrder = 0 end - object Label1: TLabel - AnchorSideTop.Control = Panel1 - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = Panel1 - AnchorSideRight.Side = asrBottom - Left = 721 - Height = 20 - Top = 15 - Width = 42 - Anchors = [akTop, akRight] - BorderSpacing.Right = 6 - Caption = 'Label1' - ParentColor = False - end end object rxData: TRxMemoryData FieldDefs = < @@ -181,7 +170,6 @@ object Form1: TForm1 DataType = ftString Size = 150 end> - AfterScroll = rxDataAfterScroll PacketRecords = 0 Left = 293 Top = 165 diff --git a/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.pas b/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.pas index bacf9f951..ae26d9311 100644 --- a/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.pas +++ b/components/rx/trunk/demos/rxdbgrid/MergeCell/unit1.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, FileUtil, rxdbgrid, rxmemds, Forms, Controls, Graphics, - Dialogs, ExtCtrls, StdCtrls, db; + Dialogs, ExtCtrls, StdCtrls, db, Grids, DBGrids; type @@ -15,7 +15,6 @@ type TForm1 = class(TForm) CheckBox1: TCheckBox; dsData: TDataSource; - Label1: TLabel; Panel1: TPanel; rxDataCODE: TLongintField; rxDataDATE: TDateTimeField; @@ -24,10 +23,13 @@ type rxData: TRxMemoryData; procedure CheckBox1Change(Sender: TObject); procedure FormCreate(Sender: TObject); - procedure rxDataAfterScroll(DataSet: TDataSet); + procedure RxDBGrid1Columns0DrawColumnCell(Sender: TObject; + const Rect: TRect; DataCol: Integer; Column: TColumn; + State: TGridDrawState); + procedure RxDBGrid1MergeCells(Sender: TObject; ACol: Integer; var ALeft, + ARight: Integer; var ADisplayColumn: TRxColumn); private - procedure RxDBGridMergeCellsEvent(Sender: TObject; ACol: Integer; Column: TRxColumn; - var ALeft, ARight: Integer); + public end; @@ -36,15 +38,11 @@ var Form1: TForm1; implementation -uses Grids; {$R *.lfm} { TForm1 } -type - THackDataGrid = class(TRxDBGrid); - procedure TForm1.FormCreate(Sender: TObject); var i: Integer; @@ -55,13 +53,32 @@ begin rxData.AppendRecord([i, Date - i, 'Line '+IntToStr(i)]); rxData.First; rxData.EnableControls; - - RxDBGrid1.OnMergeCells:=@RxDBGridMergeCellsEvent; end; -procedure TForm1.rxDataAfterScroll(DataSet: TDataSet); +procedure TForm1.RxDBGrid1Columns0DrawColumnCell(Sender: TObject; + const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); +var + S: String; + FAl: TAlignment; begin - Label1.Caption:=Format('Datalink.ActiveRecord=%d, Row = %d', [THackDataGrid(RxDBGrid1).Datalink.ActiveRecord, TDrawGrid(RxDBGrid1).Row]); + S:=rxDataCODE.DisplayText; + if CheckBox1.Checked and (rxDataCODE.AsInteger mod 10 = 1) then + FAl:=taCenter + else + FAl:=taRightJustify; + WriteTextHeader(RxDBGrid1.Canvas, Rect, S, FAl) +end; + +procedure TForm1.RxDBGrid1MergeCells(Sender: TObject; ACol: Integer; var ALeft, + ARight: Integer; var ADisplayColumn: TRxColumn); +begin + if rxDataCODE.AsInteger mod 10 = 1 then + begin + ALeft:=1; + ARight:=3; +{ if rxDataCODE.AsInteger > 10 then + AColumn:=RxDBGrid1.ColumnByFieldName('DATE');} + end; end; procedure TForm1.CheckBox1Change(Sender: TObject); @@ -72,15 +89,5 @@ begin RxDBGrid1.OptionsRx:=RxDBGrid1.OptionsRx - [rdgColSpanning]; end; -procedure TForm1.RxDBGridMergeCellsEvent(Sender: TObject; ACol: Integer; - Column: TRxColumn; var ALeft, ARight: Integer); -begin - if rxDataCODE.AsInteger mod 10 = 1 then - begin - ALeft:=1; - ARight:=3; - end; -end; - end. diff --git a/components/rx/trunk/languages/rxdconst.es.po b/components/rx/trunk/languages/rxdconst.es.po index a17a6dd0b..fbf9b94a0 100644 --- a/components/rx/trunk/languages/rxdconst.es.po +++ b/components/rx/trunk/languages/rxdconst.es.po @@ -179,7 +179,9 @@ msgid "Error symbol in expression: '%s'" msgstr "Error simbolo en expresión: '%s'" #: rxdconst.sexprnameerror -msgid "Error in filed name" +#, fuzzy +#| msgid "Error in filed name\" " +msgid "Error in filed name" msgstr "Error en nombre del fichero" #: rxdconst.sexprnorparen diff --git a/components/rx/trunk/rxdb/rxdbgrid.pas b/components/rx/trunk/rxdb/rxdbgrid.pas index 1a9ac61e7..f1b06bba1 100644 --- a/components/rx/trunk/rxdb/rxdbgrid.pas +++ b/components/rx/trunk/rxdb/rxdbgrid.pas @@ -74,8 +74,8 @@ type var Processed: boolean) of object; TRxDBGridCalcRowHeight = procedure(Sender: TRxDBGrid; var ARowHegth:integer) of object; - TRxDBGridMergeCellsEvent = procedure (Sender: TObject; ACol{, ARow}: Integer; Column: TRxColumn; - var ALeft, {ATop,} ARight{, ABottom}: Integer) of object; + TRxDBGridMergeCellsEvent = procedure (Sender: TObject; ACol : Integer; + var ALeft, ARight : Integer; var ADisplayColumn: TRxColumn) of object; //Freeman35 added TOnRxCalcFooterValues = procedure(Sender: TObject; Column: TRxColumn; var AValue : Variant) of object; @@ -918,8 +918,8 @@ type procedure CheckNewCachedSizes(var AGCache:TGridDataCache); override; procedure CalcCellExtent(ACol, ARow: Integer; var ARect: TRect); - function IsMerged(ACol{, ARow}: Integer): Boolean; overload; - function IsMerged(ACol{, ARow}: Integer; out ALeft, {ATop, }ARight{, ABottom}: Integer): Boolean; overload; + function IsMerged(ACol : Integer): Boolean; overload; + function IsMerged(ACol : Integer; out ALeft, ARight: Integer; out AColumn: TRxColumn): Boolean; overload; function GetEditMask(aCol, aRow: Longint): string; override; function GetEditText(aCol, aRow: Longint): string; override; @@ -1138,6 +1138,8 @@ type procedure RegisterRxDBGridSortEngine(RxDBGridSortEngineClass: TRxDBGridSortEngineClass; DataSetClassName: string); +procedure WriteTextHeader(ACanvas: TCanvas; ARect: TRect; const Text: string; Alignment: TAlignment); + implementation uses Math, rxdconst, rxstrutils, rxutils, strutils, rxdbgrid_findunit, @@ -2940,13 +2942,36 @@ const DT_RIGHT or {DT_EXPANDTABS or }DT_NOPREFIX, DT_CENTER or {DT_EXPANDTABS or }DT_NOPREFIX); -procedure WriteTextHeader(ACanvas: TCanvas; ARect: TRect; const Text: string; - Alignment: TAlignment); +procedure WriteTextHeader(ACanvas: TCanvas; ARect: TRect; const Text: string; Alignment: TAlignment); var DrawRect: TRect; W, CnvW: integer; begin - DrawRect := Rect(ARect.Left + 1, ARect.Top + 1, ARect.Right, ARect.Bottom); +(* +dec(ARect.Right, constCellPadding); +case Canvas.TextStyle.Alignment of + Classes.taLeftJustify: Inc(ARect.Left, constCellPadding); + Classes.taRightJustify: Dec(ARect.Right, 1); +end; +case Canvas.TextStyle.Layout of + tlTop: Inc(ARect.Top, constCellPadding); + tlBottom: Dec(ARect.Bottom, constCellPadding); +end; + +if ARect.RightARect.Right then + ARect.Left:=ARect.Right; +if ARect.BottomARect.Bottom then + ARect.Top:=ARect.Bottom; + +if (ARect.Left<>ARect.Right) and (ARect.Top<>ARect.Bottom) then +*) + + + DrawRect := Rect(ARect.Left + constCellPadding, ARect.Top + constCellPadding, ARect.Right - constCellPadding, ARect.Bottom - constCellPadding); CnvW := Max(DrawRect.Right - DrawRect.Left, 1); W := (ACanvas.TextWidth(Text) div CnvW) + 1; @@ -4322,27 +4347,36 @@ var F: TField; C: TRxColumn; j, DataCol, L, R: integer; - TS, TS1: TTextStyle; + FIsMerged: Boolean; begin + FIsMerged:=false; + + C:=nil; + F:=nil; + + if rdgColSpanning in OptionsRx then + if IsMerged(aCol, L, R, C) then + begin + aCol:=L; + FIsMerged:=true; + end; + if Assigned(OnDrawColumnCell) and not (CsDesigning in ComponentState) then begin DataCol := ColumnIndexFromGridColumn(aCol); - OnDrawColumnCell(Self, aRect, DataCol, TColumn(ColumnFromGridColumn(aCol)), aState) + if not Assigned(C) then + C:=TRxColumn(ColumnFromGridColumn(aCol)); + OnDrawColumnCell(Self, aRect, DataCol, C, aState) end else begin - TS:=Canvas.TextStyle; - if rdgColSpanning in OptionsRx then - if IsMerged(aCol, L, R) then - begin - aCol:=L; - TS1:=Canvas.TextStyle; - TS1.Clipping:=false; - Canvas.TextStyle:=TS1; - end; - F := GetFieldFromGridColumn(aCol); - C := ColumnFromGridColumn(aCol) as TRxColumn; + + if not Assigned(C) then + C := ColumnFromGridColumn(aCol) as TRxColumn; + if Assigned(C) then + F:=C.Field; + if Assigned(C) and Assigned(C.FOnDrawColumnCell) then C.OnDrawColumnCell(Self, aRect, aCol, TColumn(ColumnFromGridColumn(aCol)), aState) else @@ -4368,15 +4402,12 @@ begin else S := ''; -// S:='11'; - - if (rdgWordWrap in FOptionsRx) and Assigned(C) and (C.WordWrap) then + if ((rdgWordWrap in FOptionsRx) and Assigned(C) and (C.WordWrap)) or (FIsMerged) then WriteTextHeader(Canvas, aRect, S, C.Alignment) else DrawCellText(aCol, aRow, aRect, aState, S); end; end; - Canvas.TextStyle:=TS; end; end; @@ -4558,6 +4589,9 @@ end; procedure TRxDBGrid.DrawFocusRect(aCol, aRow: Integer; ARect: TRect); begin + CalcCellExtent(acol, arow, aRect); + CalcCellExtent(ACol, ARow, ARect); + if FGroupItems.Active and Assigned(FGroupItemDrawCur) then ARect.Bottom:=ARect.Bottom - DefaultRowHeight; inherited DrawFocusRect(aCol, aRow, ARect); @@ -5181,10 +5215,12 @@ var S: string; begin if (rdgColSpanning in OptionsRx) then - if IsMerged(aCol, L, R) then + if IsMerged(aCol, L, R, C) then aCol:=L; - C := ColumnFromGridColumn(aCol) as TRxColumn; + if not Assigned(C) then + C := ColumnFromGridColumn(aCol) as TRxColumn; + S := Value; if Assigned(C) and (C.KeyList.Count > 0) and (C.PickList.Count > 0) then begin @@ -6259,83 +6295,100 @@ end; procedure TRxDBGrid.CalcCellExtent(ACol, ARow: Integer; var ARect: TRect); var L, T, R, B: Integer; + C: TRxColumn; begin - if IsMerged(ACol, {ARow, }L{, T}, R{, B}) then + if IsMerged(ACol, L, R, C) then begin ARect.TopLeft := CellRect(L, ARow).TopLeft; ARect.BottomRight := CellRect(R, ARow).BottomRight; -{ ARect.Left := CellRect(L, ARow).Left; - ARect.Right := CellRect(R, ARow).Right;} end; end; -function TRxDBGrid.IsMerged(ACol{, ARow}: Integer): Boolean; +function TRxDBGrid.IsMerged(ACol: Integer): Boolean; var - L, T, R, B: Integer; + L, R: Integer; + C: TRxColumn; begin - Result := IsMerged(ACol, {ARow,} L, {T,} R{, B}); + Result := IsMerged(ACol, L, R, C); end; -function TRxDBGrid.IsMerged(ACol{, ARow}: Integer; out ALeft{, ATop}, ARight{, - ABottom}: Integer): Boolean; -var - FColumn: TRxColumn; +function TRxDBGrid.IsMerged(ACol: Integer; out ALeft, ARight: Integer; out + AColumn: TRxColumn): Boolean; begin Result := false; - if not (rdgColSpanning in OptionsRx) then exit; - if not Assigned(FOnMergeCells) then exit; - inc(FMergeLock); - + AColumn:=nil; ALeft := ACol; ARight := ACol; - FColumn:=TRxColumn(ColumnFromGridColumn(ACol)); - - FOnMergeCells(Self, ACol, {ARow,} FColumn, ALeft, {ATop, }ARight{, ABottom}); - if ALeft > ARight then - SwapValues(ALeft, ARight); - - Result := (ALeft <> ARight) {or (ATop <> ABottom)}; - dec(FMergeLock); + if (rdgColSpanning in OptionsRx) and Assigned(FOnMergeCells) then + begin + inc(FMergeLock); + FOnMergeCells(Self, ACol, ALeft, ARight, AColumn); + if ALeft > ARight then + SwapValues(ALeft, ARight); + Result := (ALeft <> ARight); + dec(FMergeLock); + end; end; function TRxDBGrid.GetEditMask(aCol, aRow: Longint): string; var L, R: Integer; + C: TRxColumn; begin if (rdgColSpanning in OptionsRx) then - if IsMerged(aCol, L, R) then - aCol:=L; + if IsMerged(aCol, L, R, C) then + begin + if Assigned(C) then + aCol:=C.Index + else + aCol:=L; + end; Result:=inherited GetEditMask(aCol, aRow); end; function TRxDBGrid.GetEditText(aCol, aRow: Longint): string; var R, L: Integer; + C: TRxColumn; begin if (rdgColSpanning in OptionsRx) then - if IsMerged(aCol, L, R) then - aCol:=L; + if IsMerged(aCol, L, R, C) then + begin + if Assigned(C) then + aCol:=C.Index + else + aCol:=L; + end; Result:=inherited GetEditText(aCol, aRow); end; function TRxDBGrid.GetDefaultEditor(Column: Integer): TWinControl; var L, R: Integer; + C: TRxColumn; begin if (rdgColSpanning in OptionsRx) then - if IsMerged(Column, L, R) then - Column:=L; + if IsMerged(Column, L, R, C) then + begin + if Assigned(C) then + Column:=C.Index + else + Column:=L; + end; Result:=inherited GetDefaultEditor(Column); end; procedure TRxDBGrid.PrepareCanvas(aCol, aRow: Integer; AState: TGridDrawState); var L, R, RR: Integer; + C: TRxColumn; begin if (rdgColSpanning in OptionsRx) then - if ((Row - FixedRows) = Datalink.ActiveRecord) and IsMerged(ACol, L, R) and (aCol >= L) and (aCol <= R) then - AState := AState + [gdSelected, gdFocused]; + if not ((gdFixed in aState) and (aRow = 0)) then + if ((Row - FixedRows) = Datalink.ActiveRecord) and IsMerged(ACol, L, R, C) then + if (aCol >= L) and (aCol <= R) then + AState := AState + [gdSelected, gdFocused]; inherited PrepareCanvas(aCol, aRow, AState); end;