LCL: combobox, listbox: fix drawing of customdrawn items. Change TOwnerDrawStateType.odPainted to odBackgroundPainted

git-svn-id: trunk@55304 -
This commit is contained in:
ondrej 2017-06-10 11:43:19 +00:00
parent 7a420f8326
commit 0cd8ed04e5
14 changed files with 68 additions and 93 deletions

View File

@ -3450,7 +3450,6 @@ begin
else
ItemValue:='';
AState:=[];
if odPainted in State then Include(AState,pedsPainted);
if odSelected in State then Include(AState,pedsSelected);
if odFocused in State then Include(AState,pedsFocused);
if odComboBoxEdit in State then
@ -3458,13 +3457,9 @@ begin
else
Include(AState,pedsInComboList);
// clear background
with ValueComboBox.Canvas do begin
Brush.Color:=clWhite;
Pen.Color:=clBlack;
Font.Color:=Pen.Color;
FillRect(ARect);
end;
if not(odBackgroundPainted in State) then
ValueComboBox.Canvas.FillRect(ARect);
ValueComboBox.Canvas.Font.Assign(FDefaultValueFont);
if CurRow.Editor.HasDefaultValue and (ItemValue = CurRow.Editor.GetDefaultValue) then
ValueComboBox.Canvas.Font.Style := ValueComboBox.Canvas.Font.Style + [fsItalic];

View File

@ -277,7 +277,7 @@ type
TGetPropEditProc = procedure(Prop: TPropertyEditor) of object;
TPropEditDrawStateType = (pedsSelected, pedsFocused, pedsInEdit,
pedsInComboList, pedsPainted);
pedsInComboList);
TPropEditDrawState = set of TPropEditDrawStateType;
TPropEditHint = (
@ -3342,26 +3342,12 @@ procedure TPropertyEditor.ListDrawValue(const AValue:ansistring; Index:integer;
ACanvas:TCanvas; const ARect:TRect; AState: TPropEditDrawState);
var
Style : TTextStyle;
OldColor : TColor;
begin
OldColor := ACanvas.Brush.Color;
If (pedsInComboList in AState) and not (pedsInEdit in AState)
then begin
If pedsSelected in AState then begin
ACanvas.Brush.Color := clHighlight;
ACanvas.Font.Color := clHighlightText;
end
else begin
ACanvas.Brush.Color := clwhite{clWindow};
ACanvas.Font.Color := clWindowText;
end;
ACanvas.FillRect(ARect);
end;
FillChar(Style{%H-},SizeOf(Style),0);
With Style do begin
Alignment := taLeftJustify;
Layout := tlCenter;
Opaque := (pedsInEdit in AState) and (ACanvas.Brush.Color <> clNone);
Opaque := False;
Clipping := True;
ShowPrefix := True;
WordBreak := False;
@ -3369,7 +3355,6 @@ begin
SystemFont := False;
end;
ACanvas.TextRect(ARect, ARect.Left+2,ARect.Top,AValue, Style);
ACanvas.Brush.Color := OldColor;
end;
{ these three procedures implement the default render behavior of the

View File

@ -2374,7 +2374,6 @@ begin
ItemValue:=Text;
AState:=[];
if odPainted in State then Include(AState,pedsPainted);
if odSelected in State then Include(AState,pedsSelected);
if odFocused in State then Include(AState,pedsFocused);
if odComboBoxEdit in State then
@ -3586,7 +3585,6 @@ begin
ItemValue:=Text;
AState:=[];
if odPainted in State then Include(AState,pedsPainted);
if odSelected in State then Include(AState,pedsSelected);
if odFocused in State then Include(AState,pedsFocused);
Include(AState,pedsInEdit);

View File

@ -611,46 +611,45 @@ begin
r.bottom := Rect.bottom - ColorRectOffset;
r.left := Rect.left + ColorRectOffset;
r.right := r.left + ColorRectWidth;
Exclude(State, odPainted);
noFill := false;
with Canvas do
if not(odBackgroundPainted in State) then
Canvas.FillRect(Rect);
BrushColor := Canvas.Brush.Color;
PenColor := Canvas.Pen.Color;
NewColor := Colors[Index];
if NewColor = clNone then
begin
FillRect(Rect);
NewColor := NoneColorColor;
noFill := true;
end
else
if NewColor = clDefault then
NewColor := DefaultColorColor;
BrushColor := Brush.Color;
PenColor := Pen.Color;
Canvas.Brush.Color := NewColor;
Canvas.Pen.Color := clBlack;
NewColor := Self.Colors[Index];
r := BiDiFlipRect(r, Rect, UseRightToLeftAlignment);
Canvas.Rectangle(r);
if NewColor = clNone then
begin
NewColor := NoneColorColor;
noFill := true;
end
else
if NewColor = clDefault then
NewColor := DefaultColorColor;
Brush.Color := NewColor;
Pen.Color := clBlack;
r := BiDiFlipRect(r, Rect, UseRightToLeftAlignment);
Rectangle(r);
if noFill then
begin
Line(r.Left, r.Top, r.Right-1, r.Bottom-1);
Line(r.Left, r.Bottom-1, r.Right-1, r.Top);
end;
Brush.Color := BrushColor;
Pen.Color := PenColor;
if noFill then
begin
Canvas.Line(r.Left, r.Top, r.Right-1, r.Bottom-1);
Canvas.Line(r.Left, r.Bottom-1, r.Right-1, r.Top);
end;
Canvas.Brush.Color := BrushColor;
Canvas.Pen.Color := PenColor;
r := Rect;
r.left := r.left + ColorRectWidth + ColorRectOffset + 1;
Include(State, odBackgroundPainted);
inherited DrawItem(Index, BidiFlipRect(r, Rect, UseRightToLeftAlignment), State);
end;
{------------------------------------------------------------------------------
@ -966,33 +965,33 @@ begin
r.bottom := Rect.bottom - ColorRectOffset;
r.left := Rect.left + ColorRectOffset;
r.right := r.left + ColorRectWidth;
Exclude(State,odPainted);
with Canvas do
begin
FillRect(Rect);
BrushColor := Brush.Color;
PenColor := Pen.Color;
if not(odBackgroundPainted in State) then
Canvas.FillRect(Rect);
NewColor := Self.Colors[Index];
BrushColor := Canvas.Brush.Color;
PenColor := Canvas.Pen.Color;
if NewColor = clNone then
NewColor := NoneColorColor
else
if NewColor = clDefault then
NewColor := DefaultColorColor;
NewColor := Colors[Index];
Brush.Color := NewColor;
Pen.Color := clBlack;
if NewColor = clNone then
NewColor := NoneColorColor
else
if NewColor = clDefault then
NewColor := DefaultColorColor;
Rectangle(BidiFlipRect(r, Rect, UseRightToLeftAlignment));
Canvas.Brush.Color := NewColor;
Canvas.Pen.Color := clBlack;
Canvas.Rectangle(BidiFlipRect(r, Rect, UseRightToLeftAlignment));
Canvas.Brush.Color := BrushColor;
Canvas.Pen.Color := PenColor;
Brush.Color := BrushColor;
Pen.Color := PenColor;
end;
r := Rect;
r.left := r.left + ColorRectWidth + ColorRectOffset + 1;
Include(State,odBackgroundPainted);
inherited DrawItem(Index, BidiFlipRect(r, Rect, UseRightToLeftAlignment), State);
end;
{------------------------------------------------------------------------------

View File

@ -108,9 +108,10 @@ begin
//TControlCanvas(FCanvas).UpdateTextFlags;
if Assigned(FOnDrawItem) then
FOnDrawItem(Self, Index, ARect, State)
else if not (odPainted in State) then
else
begin
FCanvas.FillRect(ARect);
if not (odBackgroundPainted in State) then
FCanvas.FillRect(ARect);
InternalDrawItem(Self, FCanvas, ARect, Items[Index])
end;
end;

View File

@ -464,9 +464,10 @@ procedure TCustomListBox.DrawItem(Index: Integer; ARect: TRect;
begin
if Assigned(FOnDrawItem) then
FOnDrawItem(Self, Index, ARect, State)
else if not (odPainted in State) then
else
begin
FCanvas.FillRect(ARect);
if not(odBackgroundPainted in State) then
FCanvas.FillRect(ARect);
if (Index>=0) and (Index < Items.Count) then
InternalDrawItem(Self, FCanvas, ARect, Items[Index]);
end;

View File

@ -83,7 +83,7 @@ begin
{$ENDIF}
// collect state flags
State:=[odPainted];
State:=[odBackgroundPainted];
if g_list_index(GtkList^.selection,Widget)>=0 then
Include(State,odSelected);
if not GTK_WIDGET_SENSITIVE(Widget) then

View File

@ -269,7 +269,7 @@ begin
ItemIndex := 0;
// collect state flags
State:=[odPainted];
State:=[odBackgroundPainted];
if (flags and GTK_CELL_RENDERER_SELECTED)>0 then
Include(State, odSelected);
if not GTK_WIDGET_SENSITIVE(Widget) then

View File

@ -79,7 +79,7 @@ begin
end;
// collect state flags
State:=[odPainted];
State:=[odBackgroundPainted];
if g_list_index(GtkList^.selection,Widget)>=0 then
Include(State,odSelected);
if not GTK_WIDGET_SENSITIVE(Widget) then

View File

@ -511,7 +511,7 @@ begin
ItemIndex := 0;
// collect state flags
State:=[odPainted];
State:=[odBackgroundPainted];
if (flags and GTK_CELL_RENDERER_SELECTED)>0 then
Include(State, odSelected);
if not Widget^.is_sensitive then

View File

@ -13443,8 +13443,7 @@ begin
odGrayed, odChecked,
odDefault, odInactive, odNoAccel,
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit,
odPainted
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit
}
Msg.Msg := LM_DRAWLISTITEM;
Msg.DrawListItemStruct := @DrawStruct;
@ -14897,8 +14896,7 @@ begin
odGrayed, odChecked,
odDefault, odInactive, odNoAccel,
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit,
odPainted
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit
}
Msg.Msg := CN_DRAWITEM;
Msg.DrawListItemStruct := @DrawStruct;

View File

@ -13417,8 +13417,7 @@ begin
odGrayed, odChecked,
odDefault, odInactive, odNoAccel,
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit,
odPainted
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit
}
Msg.Msg := LM_DRAWLISTITEM;
Msg.DrawListItemStruct := @DrawStruct;
@ -14877,8 +14876,7 @@ begin
odGrayed, odChecked,
odDefault, odInactive, odNoAccel,
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit,
odPainted
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit
}
Msg.Msg := CN_DRAWITEM;
Msg.DrawListItemStruct := @DrawStruct;

View File

@ -1143,7 +1143,7 @@ type
odSelected, odGrayed, odDisabled, odChecked,
odFocused, odDefault, odHotLight, odInactive, odNoAccel,
odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit,
odPainted // item already painted
odBackgroundPainted // item background already painted
);
TOwnerDrawState = set of TOwnerDrawStateType;

View File

@ -254,12 +254,12 @@ var
TheCanvas: TCanvas;
begin
//Objective: draw only the FileName, not the fully qualified path.
//if (odPainted in State) then Exit;
TheCanvas := (Control as TCustomListBox).Canvas;
ItemText := ExtractFileName(FileListBox.Items[Index]);
TheCanvas.FillRect(ARect);
if not(odBackgroundPainted in State) then
TheCanvas.FillRect(ARect);
OldBrushStyle := TheCanvas.Brush.Style;
TheCanvas.Brush.Style := bsClear;