Skip to content

Commit 8a0230f

Browse files
committed
TLabeledDbGrid: added Property WrapAllText to wrap all text that can wrap, not just memo fields
1 parent e322abc commit 8a0230f

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

Source/Vcl.LabeledDBCtrls.pas

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ TLabeledDbGrid = class(TDBGrid)
319319
FOnIsCheckBoxedColumn: TCBCheckBoxedColumnEvent;
320320
FLinesPerRow: Integer;
321321
FRowMargin: Integer;
322+
FWrapAllText: Boolean;
322323
function TitleOffset: Integer;
323324
procedure OnSearchTimer(Sender : TObject);
324325
procedure SetBoundCaption(const Value: TCaption);
@@ -356,6 +357,7 @@ TLabeledDbGrid = class(TDBGrid)
356357
procedure WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integer;
357358
const AField: TField; Const AColumn: TColumn);
358359
function CalcRowMargin(const ARect: TRect): Integer;
360+
procedure SetWrapAllText(const Value: Boolean);
359361
protected
360362
procedure SetParent(AParent: TWinControl); override;
361363
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
@@ -428,6 +430,7 @@ TLabeledDbGrid = class(TDBGrid)
428430
property UnsortableFields: string read FUnsortableFields write FUnsortableFields;
429431
property CanEditColumn: TCBCanEditColumn read FCanEditColumn write FCanEditColumn;
430432
property RowMargin: Integer read FRowMargin write SetRowMargin default 0;
433+
property WrapAllText: Boolean read FWrapAllText write SetWrapAllText default False;
431434
end;
432435

433436
TNavInsMode = (imInsert, imAppend);
@@ -1076,14 +1079,15 @@ procedure TLabeledDbGrid.WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integ
10761079
DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX );
10771080
RTL: array [Boolean] of Integer = (0, DT_RTLREADING);
10781081
var
1079-
Text: string;
1082+
Text, TruncText: string;
10801083
Alignment: TAlignment;
10811084
ARightToLeft: Boolean;
10821085
B, R: TRect;
10831086
Hold, Left: Integer;
10841087
I: TColorRef;
10851088
LFormat: Integer;
10861089
LMemoField: Boolean;
1090+
LWrapText: Boolean;
10871091
begin
10881092
ACanvas.Font.Name := Font.Name;
10891093
ACanvas.Font.Style := Font.Style;
@@ -1092,17 +1096,25 @@ procedure TLabeledDbGrid.WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integ
10921096
//Verifiy that Field is a Memofield
10931097
LMemoField := Assigned(AField) and (AField.DataType in [ftMemo, ftFmtMemo, ftWideMemo]);
10941098
if LMemoField then
1095-
begin
1096-
Text := AField.AsString;
1097-
ACanvas.FillRect(ARect);
1098-
end
1099+
Text := AField.AsString
10991100
else if Assigned(AField) and not (FDrawCheckBoxImages and isCheckBoxedField(AField)) then //Empty Text if drawing checkbox
11001101
Text := AField.DisplayText
11011102
else
11021103
Text := '';
11031104

1104-
if LinesPerRow=1 then
1105-
Text := TruncStringInRect(Canvas, ARect, Text, DX) ;
1105+
TruncText := TruncStringInRect(Canvas, ARect, Text, DX) ;
1106+
1107+
if (LinesPerRow = 1) or (Text = TruncText) or not FWrapAllText or
1108+
((Text <> TruncText) and not Text.Contains(' ')) then
1109+
begin
1110+
Text := TruncText;
1111+
LWrapText := False
1112+
end
1113+
else
1114+
LWrapText := True;
1115+
1116+
if LMemoField or LWrapText then
1117+
ACanvas.FillRect(ARect);
11061118

11071119
Alignment := AColumn.Alignment;
11081120
ARightToLeft := UseRightToLeftAlignmentForField(AField, AColumn.Alignment);
@@ -1124,7 +1136,7 @@ procedure TLabeledDbGrid.WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integ
11241136
- (ACanvas.TextWidth(Text) div 2);
11251137
end;
11261138
//Se il campo è un memo lo stampa su n righe:
1127-
if LMemoField then
1139+
if LMemoField or LWrapText then
11281140
begin
11291141
LFormat := dt_WordBreak or dt_NoPrefix;
11301142
//Riduce l'area di stampa in base ai margini
@@ -1485,6 +1497,15 @@ procedure TLabeledDbGrid.SetTitleFont(const Value: TFont);
14851497
inherited TitleFont.Assign(Value);
14861498
end;
14871499

1500+
procedure TLabeledDbGrid.SetWrapAllText(const Value: Boolean);
1501+
begin
1502+
if FWrapAllText <> Value then
1503+
begin
1504+
FWrapAllText := Value;
1505+
Invalidate;
1506+
end;
1507+
end;
1508+
14881509
procedure TLabeledDbGrid.StandardSort(Field: TField; var SortOrder: TCBSortOrder);
14891510
var
14901511
DataSet: TDataSet;

0 commit comments

Comments
 (0)