procedure TJvEdit.WndProc(
var Msg: TMessage);
begin
case Msg.Msg
of
CN_CTLCOLORSTATIC,
CN_CTLCOLOREDIT:
if Images <>
nil then
ExcludeClipRect(Msg.WParam, 1, 1, Images.Width + FImageMarginRight + 2, Images.Height);
end;
inherited WndProc(Msg);
case Msg.Msg
of
WM_SIZE, WM_SETFONT, WM_FONTCHANGE, WM_WINDOWPOSCHANGED,
CM_FONTCHANGED, CM_BORDERCHANGED, CM_CTL3DCHANGED:
if not (csLoading
in ComponentState)
then
UpdateEditMargins;
end;
end;
procedure TJvEdit.WMPaint(
var Msg: TWMPaint);
var
MyDC: Boolean;
ps: TPaintStruct;
NewPen, OldPen: HPEN;
Canvas: TCanvas;
begin
if Images <>
nil then
begin
if UpdateEditMargins
then
Exit;
// UpdateEditMargins called Invalidate()
MyDC := Msg.DC = 0;
if MyDC
then
Msg.DC := BeginPaint(
Handle, ps);
inherited;
// Draw gradient filled rectangle
Canvas := TCanvas.Create;
Canvas.Handle := Msg.DC;
GradientFillCanvas(Canvas, FPrefixColorFrom, FPrefixColorTo,
Rect(0, 0, Images.Width + FImageMarginRight + 2, Images.Height + 1),
FPrefixColorDirection);
// Draw bitmap
if ImageIndex <> -1
then
case FImageAlignment
of
taLeftJustify : ImageList_Draw(Images.Handle, ImageIndex,
Msg.DC, 0, 1, ILD_NORMAL);
taRightJustify: ImageList_Draw(Images.Handle, ImageIndex,
Msg.DC, FImageMarginRight, 1, ILD_NORMAL);
taCenter: ImageList_Draw(Images.Handle, ImageIndex, Msg.DC,
(FImageMarginRight
div 2), 1, ILD_NORMAL);
end;
// Show separator line
if FShowLine
then
begin
NewPen := CreatePen(PS_SOLID, 1, ColorToRGB(FLineColor));
OldPen := SelectObject(Msg.DC, NewPen);
MoveToEx(Msg.DC, Images.Width + FImageMarginRight + 1, 0,
Nil );
LineTo(Msg.DC, Images.Width + FImageMarginRight + 1, Height);
SelectObject(Msg.DC, OldPen);
DeleteObject(NewPen);
end;
if MyDC
then
EndPaint(
Handle, ps);
Canvas.Free;
end
else
inherited;
end;
function TJvEdit.UpdateEditMargins: Boolean;
var
Margins: Integer;
LeftMargin: Integer;
begin
Result := False;
if HandleAllocated
then
begin
LeftMargin := 0;
if Images <>
nil then
LeftMargin := Images.Width + FImageMarginRight + 2;
Margins := SendMessage(
Handle, EM_GETMARGINS, 0, 0);
if (Margins
and $FFFF) <> LeftMargin
then
begin
SendMessage(
Handle, EM_SETMARGINS, EC_LEFTMARGIN, MakeLong(LeftMargin, 0));
Invalidate;
Result := True;
end;
end;
end;