jvcllaz: TJvDBLookupCombo improvements by Michal Gawrycki (issue #36403):

- Leaves parent form active under Windows.
- Publish several properties and events.
- Support for AutoSize.
- Use the "FDataListForm.Close" method instead of "FDataListForm..Visible := false" property to hide popup because DoClose method is not called when hidden by "Visible" property.
- Control drawing fixes.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7204 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-12-06 10:43:57 +00:00
parent fcd60c1925
commit a7bc63964a

View File

@ -34,6 +34,7 @@ Known Issues:
unit JvDBLookup; unit JvDBLookup;
{.$I jvcl.inc} {.$I jvcl.inc}
{$mode objfpc}{$H+}
interface interface
@ -344,14 +345,18 @@ type
property OnKeyPress; property OnKeyPress;
property OnKeyUp; property OnKeyUp;
property OnMouseDown; property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove; property OnMouseMove;
property OnMouseUp; property OnMouseUp;
property OnStartDrag; property OnStartDrag;
property OnContextPopup; property OnContextPopup;
property OnMouseWheel;
property OnMouseWheelDown; property OnMouseWheelDown;
property OnMouseWheelUp; property OnMouseWheelUp;
property OnEndDock; property OnEndDock;
property OnStartDock; property OnStartDock;
property OnUTF8KeyPress;
end; end;
//TJvPopupDataListWindow = class; //TJvPopupDataListWindow = class;
@ -380,6 +385,9 @@ type
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure DoShow; override; procedure DoShow; override;
procedure DoClose(var CloseAction: TCloseAction); override; procedure DoClose(var CloseAction: TCloseAction); override;
{$IFDEF WINDOWS}
procedure WMActivate(var Message: TLMActivate); message LM_ACTIVATE;
{$ENDIF}
public public
constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override;
end; end;
@ -438,6 +446,8 @@ type
protected protected
procedure CreateWnd; override; procedure CreateWnd; override;
procedure SetReadOnly(AValue: Boolean); override; procedure SetReadOnly(AValue: Boolean); override;
procedure GetPreferredSize(var PreferredWidth, PreferredHeight: integer;
Raw: boolean = false; WithThemeSpace: boolean = true); override;
function GetDropDownButtonRect: TRect; function GetDropDownButtonRect: TRect;
procedure InvalidateFrame; procedure InvalidateFrame;
procedure InvalidateDropDownButton; procedure InvalidateDropDownButton;
@ -485,6 +495,8 @@ type
property KeyValue; property KeyValue;
published published
property Align; property Align;
property AutoSize;
property DoubleBuffered;
property BorderSpacing; property BorderSpacing;
property BorderStyle default bsSingle; property BorderStyle default bsSingle;
property DropDownAlign: TDropDownAlign read FDropDownAlign write FDropDownAlign default daLeft; property DropDownAlign: TDropDownAlign read FDropDownAlign write FDropDownAlign default daLeft;
@ -522,6 +534,7 @@ type
property LookupFormat; property LookupFormat;
property LookupSource; property LookupSource;
property ParentColor; property ParentColor;
property ParentDoubleBuffered;
property ParentFont; property ParentFont;
property ParentShowHint; property ParentShowHint;
property PopupMenu; property PopupMenu;
@ -544,17 +557,21 @@ type
property OnGetImage; property OnGetImage;
property OnGetImageIndex; property OnGetImageIndex;
property OnKeyDown; property OnKeyDown;
property OnMouseEnter;
property OnMouseLeave;
property OnKeyPress; property OnKeyPress;
property OnKeyUp; property OnKeyUp;
property OnMouseDown; property OnMouseDown;
property OnMouseMove; property OnMouseMove;
property OnMouseUp; property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown; property OnMouseWheelDown;
property OnMouseWheelUp; property OnMouseWheelUp;
property OnStartDrag; property OnStartDrag;
property OnContextPopup; property OnContextPopup;
property OnEndDock; property OnEndDock;
property OnStartDock; property OnStartDock;
property OnUTF8KeyPress;
end; end;
(* TJvPopupDataWindow = class(TJvPopupDataList) (* TJvPopupDataWindow = class(TJvPopupDataList)
@ -2497,6 +2514,15 @@ begin
Application.RemoveOnDeactivateHandler(@AppDeactivate); Application.RemoveOnDeactivateHandler(@AppDeactivate);
end; end;
{$IFDEF WINDOWS}
procedure TJvPopupDataListForm.WMActivate(var Message: TLMActivate);
begin
if (Message.Active <> WA_INACTIVE) and Assigned(Self.GetRealPopupParent) then
SendMessage(Self.GetRealPopupParent.Handle, LM_NCACTIVATE, WPARAM(True), -1);
inherited;
end;
{$ENDIF}
procedure TJvPopupDataListForm.AppDeactivate(Sender: TObject); procedure TJvPopupDataListForm.AppDeactivate(Sender: TObject);
begin begin
if Assigned(FCombo) and (FCombo is TJvDBLookupCombo) then if Assigned(FCombo) and (FCombo is TJvDBLookupCombo) then
@ -2521,7 +2547,12 @@ begin
ShowInTaskBar := stNever; ShowInTaskBar := stNever;
BorderStyle := bsNone; BorderStyle := bsNone;
FormStyle := fsStayOnTop; FormStyle := fsStayOnTop;
{$IFDEF WINDOWS}
PopupMode := pmExplicit;
PopupParent := GetParentForm(TControl(AOwner));
{$ELSE}
PopupMode := pmAuto; PopupMode := pmAuto;
{$ENDIF}
KeyPreview := True; KeyPreview := True;
AutoSize := True; AutoSize := True;
FList := TJvPopupDataList.Create(Self); FList := TJvPopupDataList.Create(Self);
@ -2612,7 +2643,7 @@ begin
if ParentFormVisible(Self) and CanFocus then if ParentFormVisible(Self) and CanFocus then
SetFocus; SetFocus;
ListValue := FDataListForm.FList.Value; ListValue := FDataListForm.FList.Value;
FDataListForm.Visible := False; FDataListForm.Close;
FListVisible := False; FListVisible := False;
FDataListForm.FList.LookupSource := nil; FDataListForm.FList.LookupSource := nil;
InvalidateDropDownButton; InvalidateDropDownButton;
@ -2840,7 +2871,7 @@ end;
function TJvDBLookupCombo.GetMinHeight: Integer; function TJvDBLookupCombo.GetMinHeight: Integer;
begin begin
Result := DefaultTextHeight + GetBorderSize + 3; Result := DefaultTextHeight + GetBorderSize {+ 3};
end; end;
procedure TJvDBLookupCombo.UpdateFieldText; procedure TJvDBLookupCombo.UpdateFieldText;
@ -3214,9 +3245,17 @@ begin
InvalidateFrame; InvalidateFrame;
end; end;
procedure TJvDBLookupCombo.GetPreferredSize(var PreferredWidth,
PreferredHeight: integer; Raw: boolean; WithThemeSpace: boolean);
begin
inherited GetPreferredSize(PreferredWidth, PreferredHeight, Raw,
WithThemeSpace);
Height := GetMinHeight;
end;
function TJvDBLookupCombo.GetDropDownButtonRect: TRect; function TJvDBLookupCombo.GetDropDownButtonRect: TRect;
begin begin
Result := Rect(ClientWidth - (FButtonWidth - (Width - ClientWidth) div 2), 0, Width, ClientHeight); Result := Rect(ClientWidth - FButtonWidth - Round((Width - ClientWidth) / 2), 0, Width, ClientHeight);
end; end;
procedure TJvDBLookupCombo.InvalidateFrame; procedure TJvDBLookupCombo.InvalidateFrame;
@ -3285,6 +3324,7 @@ var
I, LastIndex, TxtWidth: Integer; I, LastIndex, TxtWidth: Integer;
X, W, ATop, ARight: Integer; X, W, ATop, ARight: Integer;
S: string; S: string;
TStyle: TTextStyle;
begin begin
if ColorToRGB(Self.Color) <> ColorToRGB(clBtnFace) then if ColorToRGB(Self.Color) <> ColorToRGB(clBtnFace) then
ACanvas.Pen.Color := clBtnFace ACanvas.Pen.Color := clBtnFace
@ -3292,7 +3332,7 @@ begin
ACanvas.Pen.Color := clBtnShadow; ACanvas.Pen.Color := clBtnShadow;
LastIndex := FDisplayValues.Count - 1; LastIndex := FDisplayValues.Count - 1;
TxtWidth := ACanvas.TextWidth('M'); TxtWidth := ACanvas.TextWidth('M');
ATop := Max(0, (RectHeight(R) - CanvasMaxTextHeight(ACanvas)) div 2); ATop := 0;
ARight := R.Right; ARight := R.Right;
Inc(R.Left, ALeft); Inc(R.Left, ALeft);
for I := 0 to LastIndex do for I := 0 to LastIndex do
@ -3311,6 +3351,9 @@ begin
taCenter: taCenter:
X := (W - ACanvas.TextWidth(S)) div 2; X := (W - ACanvas.TextWidth(S)) div 2;
end; end;
TStyle := ACanvas.TextStyle;
TStyle.Layout := tlCenter;
ACanvas.TextStyle := TStyle;
ACanvas.TextRect(R, R.Left + Max(0, X), ATop, S); ACanvas.TextRect(R, R.Left + Max(0, X), ATop, S);
Inc(R.Left, W); Inc(R.Left, W);
if I < LastIndex then if I < LastIndex then
@ -3369,6 +3412,7 @@ var
Alignment: TAlignment; Alignment: TAlignment;
State: TThemedComboBox; State: TThemedComboBox;
Details: TThemedElementDetails; Details: TThemedElementDetails;
TStyle: TTextStyle;
begin begin
if csDestroying in ComponentState then if csDestroying in ComponentState then
Exit; Exit;
@ -3451,7 +3495,7 @@ begin
if W > 4 then if W > 4 then
begin begin
R := Rect(1, 1, W - 1, ClientHeight - 1); R := Rect({1}0, {1}0, W - 2, ClientHeight {- 1});
if TextMargin > 0 then if TextMargin > 0 then
Inc(TextMargin); Inc(TextMargin);
X := 4 + TextMargin; X := 4 + TextMargin;
@ -3488,7 +3532,12 @@ begin
PaintDisplayValues(Canvas, ImageRect, TextMargin); PaintDisplayValues(Canvas, ImageRect, TextMargin);
end end
else else
Canvas.TextRect(ImageRect, X, R.Top + Max(0, (RectHeight(R) - Canvas.TextHeight(AText)) div 2), AText); begin
TStyle := Canvas.TextStyle;
TStyle.Layout := tlCenter;
Canvas.TextStyle := TStyle;
Canvas.TextRect(ImageRect, X, R.Top, AText);
end;
if Image <> nil then if Image <> nil then
begin begin