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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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