Files
lazarus-ccr/components/rx/tooledit.pas

167 lines
4.5 KiB
ObjectPascal
Raw Normal View History

unit tooledit;
{$I rx.inc}
interface
uses
Classes, SysUtils, LCLType, LMessages, Graphics, MaskEdit, Controls;
function PaintComboEdit(Editor: TCustomMaskEdit; const AText: string;
AAlignment: TAlignment; StandardPaint: Boolean;
var ACanvas: TControlCanvas; var Message: TLMPaint): Boolean;
function EditorTextMargins(Editor: TCustomMaskEdit): TPoint;
implementation
uses lclintf;
function EditorTextMargins(Editor: TCustomMaskEdit): TPoint;
var
DC: HDC;
SaveFont: HFont;
I: Integer;
SysMetrics, Metrics: TTextMetric;
begin
with Editor do
begin
if NewStyleControls then
begin
if BorderStyle = bsNone then
I := 0
else
{ if Ctl3D then
I := 1
else}
I := 2;
Result.X := {SendMessage(Handle, LM_GETMARGINS, 0, 0) and $0000FFFF} + I;
Result.Y := I;
end
else
begin
if BorderStyle = bsNone then
I := 0
else
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
I := SysMetrics.tmHeight;
if I > Metrics.tmHeight then
I := Metrics.tmHeight;
I := I div 4;
end;
Result.X := I;
Result.Y := I;
end;
end;
end;
function PaintComboEdit(Editor: TCustomMaskEdit; const AText: string;
AAlignment: TAlignment; StandardPaint: Boolean;
var ACanvas: TControlCanvas; var Message: TLMPaint): Boolean;
var
AWidth, ALeft: Integer;
Margins: TPoint;
R: TRect;
DC: HDC;
PS: TPaintStruct;
S: string;
{$IFDEF RX_D4}
ExStyle: DWORD;
const
AlignStyle: array[Boolean, TAlignment] of DWORD =
((WS_EX_LEFT, WS_EX_RIGHT, WS_EX_LEFT),
(WS_EX_RIGHT, WS_EX_LEFT, WS_EX_LEFT));
{$ENDIF}
begin
Result := True;
with Editor do
begin
{$IFDEF RX_D4}
// if UseRightToLeftAlignment then ChangeBiDiModeAlignment(AAlignment);
{$ENDIF}
if StandardPaint and not(csPaintCopy in ControlState) then
begin
{$IFDEF RX_D4}
(* if SysLocale.MiddleEast and HandleAllocated and (IsRightToLeft) then
begin { This keeps the right aligned text, right aligned }
ExStyle := DWORD(GetWindowLong(Handle, GWL_EXSTYLE)) and (not WS_EX_RIGHT) and
(not WS_EX_RTLREADING) and (not WS_EX_LEFTSCROLLBAR);
if UseRightToLeftReading then
ExStyle := ExStyle or WS_EX_RTLREADING;
if UseRightToLeftScrollbar then
ExStyle := ExStyle or WS_EX_LEFTSCROLLBAR;
ExStyle := ExStyle or
AlignStyle[UseRightToLeftAlignment, AAlignment];
if DWORD(GetWindowLong(Handle, GWL_EXSTYLE)) <> ExStyle then
SetWindowLong(Handle, GWL_EXSTYLE, ExStyle);
end; *)
{$ENDIF RX_D4}
Result := False;
{ return false if we need to use standard paint handler }
Exit;
end;
{ Since edit controls do not handle justification unless multi-line (and
then only poorly) we will draw right and center justify manually unless
the edit has the focus. }
if ACanvas = nil then
begin
ACanvas := TControlCanvas.Create;
ACanvas.Control := Editor;
end;
DC := Message.DC;
if DC = 0 then DC := BeginPaint(Handle, PS);
ACanvas.Handle := DC;
try
ACanvas.Font := Font;
if not Enabled and NewStyleControls and not
(csDesigning in ComponentState) and
(ColorToRGB(Color) <> ColorToRGB(clGrayText)) then
ACanvas.Font.Color := clGrayText;
with ACanvas do
begin
R := ClientRect;
if not (NewStyleControls {and Ctl3D}) and (BorderStyle = bsSingle) then
begin
Brush.Color := clWindowFrame;
{ FrameRect(R);
InflateRect(R, -1, -1);}
end;
Brush.Color := Color;
S := AText;
AWidth := TextWidth(S);
Margins := EditorTextMargins(Editor);
{ if PopupVisible then
ALeft := Margins.X
else
begin}
// if ButtonWidth > 0 then Inc(AWidth);
case AAlignment of
taLeftJustify:
ALeft := Margins.X;
taRightJustify:
ALeft := ClientWidth {- ButtonWidth} - AWidth - Margins.X - 2;
else
ALeft := (ClientWidth {- ButtonWidth} - AWidth) div 2;
end;
{ end;}
{$IFDEF RX_D4}
if SysLocale.MiddleEast then UpdateTextFlags;
{$ENDIF}
Brush.Style := bsClear;
TextRect(R, ALeft, Margins.Y, S);
end;
finally
ACanvas.Handle := 0;
if Message.DC = 0 then EndPaint(Handle, PS);
end;
end;
end;
end.