RxFPC: RxDBLookupCombo new property - Style

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6177 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2018-02-05 13:55:19 +00:00
parent 713dd4bc78
commit 91a180f58b

View File

@@ -51,6 +51,7 @@ type
{For deciding, what we need to show in combobox in case we cannot find curvalue in lookup table.} {For deciding, what we need to show in combobox in case we cannot find curvalue in lookup table.}
TRxDBValueVariant = (rxufNone, rxufLastSuccessful, rxufOriginal); TRxDBValueVariant = (rxufNone, rxufLastSuccessful, rxufOriginal);
TRxDBLookupStyle = (rxcsDropDown, rxcsDropDownList);
{ TLookupSourceLink } { TLookupSourceLink }
TDataSourceLink = class(TDataLink) TDataSourceLink = class(TDataLink)
@@ -154,6 +155,7 @@ type
FOnChangeData: TNotifyEvent; FOnChangeData: TNotifyEvent;
// //
FStopClick:boolean; FStopClick:boolean;
FMouseDown:boolean;
//FDataLink:TFieldDataLink; //FDataLink:TFieldDataLink;
FDataLink:TDataSourceLink; FDataLink:TDataSourceLink;
FDataFieldName: string; FDataFieldName: string;
@@ -176,6 +178,7 @@ type
// //
FRxPopUpForm:TPopUpForm; FRxPopUpForm:TPopUpForm;
FFieldList:TStringList; FFieldList:TStringList;
FStyle: TRxDBLookupStyle;
FValuesList:TStringList; FValuesList:TStringList;
FValue:string; FValue:string;
//Visual //Visual
@@ -189,6 +192,7 @@ type
FSuccesfullyFind : boolean; FSuccesfullyFind : boolean;
FOnSelect : TNotifyEvent; FOnSelect : TNotifyEvent;
procedure SetStyle(AValue: TRxDBLookupStyle);
procedure SetValue(const Value: string); procedure SetValue(const Value: string);
function GetKeyValue: Variant; function GetKeyValue: Variant;
procedure SetKeyValue(const Value: Variant); procedure SetKeyValue(const Value: Variant);
@@ -231,7 +235,7 @@ type
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS; procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
procedure CMExit(var Message:TLMessage); message CM_EXIT; procedure CMExit(var Message:TLMessage); message CM_EXIT;
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK; procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
procedure PaintDisplayValues(ACanvas: TCanvas; R: TRect; ALeft: Integer); procedure PaintDisplayValues(ACanvas: TCanvas; R: TRect; ALeft: Integer; AThemedDetails : PThemedElementDetails);
procedure CheckNotCircular; procedure CheckNotCircular;
procedure DisplayValueChanged; procedure DisplayValueChanged;
procedure DataLinkActiveChanged; procedure DataLinkActiveChanged;
@@ -265,6 +269,12 @@ type
procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure CMVisibleChanged(var Msg: TLMessage); message CM_VISIBLECHANGED; procedure CMVisibleChanged(var Msg: TLMessage); message CM_VISIBLECHANGED;
procedure CMEnabledChanged(var Msg: TLMessage); message CM_ENABLEDCHANGED; procedure CMEnabledChanged(var Msg: TLMessage); message CM_ENABLEDCHANGED;
procedure MouseEnter; override;
procedure MouseLeave; override;
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
procedure Click; override; procedure Click; override;
function RealGetText: TCaption; override; function RealGetText: TCaption; override;
procedure RealSetText(const Value: TCaption); override; procedure RealSetText(const Value: TCaption); override;
@@ -309,6 +319,7 @@ type
property OnClosePopup:TClosePopup read FOnClosePopup write FOnClosePopup; property OnClosePopup:TClosePopup read FOnClosePopup write FOnClosePopup;
property UnfindedValue : TRxDBValueVariant read FUnfindedValue write FUnfindedValue default rxufNone; property UnfindedValue : TRxDBValueVariant read FUnfindedValue write FUnfindedValue default rxufNone;
property Style:TRxDBLookupStyle read FStyle write SetStyle default rxcsDropDown;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@@ -348,6 +359,8 @@ type
property Glyph; property Glyph;
property EmptyValue; property EmptyValue;
property EmptyItemColor; property EmptyItemColor;
property Style;
// property MaxLength; // property MaxLength;
property NumGlyphs; property NumGlyphs;
Property OnButtonClick; Property OnButtonClick;
@@ -697,8 +710,12 @@ end;
procedure TRxCustomDBLookupCombo.CheckButtonVisible; procedure TRxCustomDBLookupCombo.CheckButtonVisible;
begin begin
if Assigned(FButton) then if Assigned(FButton) then
FButton.Visible:=(csdesigning in ComponentState) or FButton.Visible:=((FStyle = rxcsDropDown) or (not ThemeServices.ThemesEnabled)) and
(Visible and (Focused or not FButtonNeedsFocus)); (
(csdesigning in ComponentState)
or
(Visible and (Focused or not FButtonNeedsFocus))
);
end; end;
function TRxCustomDBLookupCombo.GetButtonWidth: Integer; function TRxCustomDBLookupCombo.GetButtonWidth: Integer;
@@ -887,7 +904,7 @@ end;
procedure TRxCustomDBLookupCombo.WMSetFocus(var Message: TLMSetFocus); procedure TRxCustomDBLookupCombo.WMSetFocus(var Message: TLMSetFocus);
begin begin
FButton.Visible:=True; FButton.Visible:=(FStyle = rxcsDropDown) or (not ThemeServices.ThemesEnabled);
inherited WMSetFocus(Message); inherited WMSetFocus(Message);
Invalidate; Invalidate;
end; end;
@@ -911,12 +928,14 @@ begin
end; end;
procedure TRxCustomDBLookupCombo.PaintDisplayValues(ACanvas: TCanvas; R: TRect; procedure TRxCustomDBLookupCombo.PaintDisplayValues(ACanvas: TCanvas; R: TRect;
ALeft: Integer); ALeft: Integer; AThemedDetails: PThemedElementDetails);
var var
I, LastIndex, TxtWidth: Integer; I, LastIndex, TxtWidth: Integer;
X, W, ATop, ARight: Integer; X, W, ATop, ARight: Integer;
S: string; S: string;
F:TField; F:TField;
Details: TThemedElementDetails;
R1: TRect;
begin begin
if (FValuesList.Count=0) or (not LookupSource.DataSet.Active) then exit; if (FValuesList.Count=0) or (not LookupSource.DataSet.Active) then exit;
if ColorToRGB(Self.Color) <> ColorToRGB(clBtnFace) then if ColorToRGB(Self.Color) <> ColorToRGB(clBtnFace) then
@@ -950,12 +969,30 @@ begin
taRightJustify: X := W - ACanvas.TextWidth(S) - 3; taRightJustify: X := W - ACanvas.TextWidth(S) - 3;
taCenter: X := (W - ACanvas.TextWidth(S)) div 2; taCenter: X := (W - ACanvas.TextWidth(S)) div 2;
end; end;
ACanvas.TextRect(R, R.Left + Max(0, X), ATop, S);
if ThemeServices.ThemesEnabled and (FStyle = rxcsDropDownList) and Assigned(AThemedDetails) then
begin
R1:=R;
R1.Left:=R1.Left + Max(0, X);
ThemeServices.DrawText(ACanvas, AThemedDetails^, S, R1, DT_LEFT or DT_VCENTER or DT_SINGLELINE, 0)
end
else
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
begin begin
ACanvas.MoveTo(R.Right, R.Top); if ThemeServices.ThemesEnabled and (FStyle = rxcsDropDownList) then
ACanvas.LineTo(R.Right, R.Bottom); begin
R1:=Rect(R.Right - 1, R.Top + 2, R.Right, R.Bottom - 2);
Details := ThemeServices.GetElementDetails(tcComboBoxRoot);
ThemeServices.DrawElement(ACanvas.Handle, Details, R1, nil);
end
else
begin
ACanvas.MoveTo(R.Right, R.Top);
ACanvas.LineTo(R.Right, R.Bottom);
end;
Inc(R.Left); Inc(R.Left);
end; end;
if R.Left >= ARight then if R.Left >= ARight then
@@ -1393,6 +1430,36 @@ begin
FButton.Enabled:=Enabled; FButton.Enabled:=Enabled;
end; end;
procedure TRxCustomDBLookupCombo.MouseEnter;
begin
inherited MouseEnter;
FMouseDown:=false;
Invalidate;
end;
procedure TRxCustomDBLookupCombo.MouseLeave;
begin
inherited MouseLeave;
FMouseDown:=false;
Invalidate;
end;
procedure TRxCustomDBLookupCombo.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
FMouseDown:=true;
Invalidate;
end;
procedure TRxCustomDBLookupCombo.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
FMouseDown:=false;
Invalidate;
end;
procedure TRxCustomDBLookupCombo.Click; procedure TRxCustomDBLookupCombo.Click;
begin begin
inherited Click; inherited Click;
@@ -1435,16 +1502,15 @@ end;
procedure TRxCustomDBLookupCombo.SetBorderStyle(NewStyle: TBorderStyle); procedure TRxCustomDBLookupCombo.SetBorderStyle(NewStyle: TBorderStyle);
begin begin
if FStyle = rxcsDropDownList then
NewStyle:=bsNone;
inherited SetBorderStyle(NewStyle); inherited SetBorderStyle(NewStyle);
if BorderStyle = bsNone then if BorderStyle = bsNone then
begin FButton.BorderSpacing.Around := 2
FButton.BorderSpacing.Around := 2;
end
else else
begin
FButton.BorderSpacing.Around := 0; FButton.BorderSpacing.Around := 0;
end;
end; end;
procedure TRxCustomDBLookupCombo.Paint; procedure TRxCustomDBLookupCombo.Paint;
@@ -1452,72 +1518,134 @@ const
padding : Integer = 1; padding : Integer = 1;
var var
Selected:boolean; Selected:boolean;
R, R1: TRect; R, R1, R2: TRect;
AText: string; AText: string;
border : Integer; border : Integer;
Details, DetailsBtn: TThemedElementDetails;
BtnSize: TSize;
pr: PRect;
begin begin
Canvas.Font := Font;
Canvas.Brush.Color := Color;
Selected := Focused and (not (csPaintCopy in ControlState)) and (not PopupVisible);
if Selected then
begin
Canvas.Font.Color := clHighlightText;
Canvas.Brush.Color := clHighlight;
end
else
if not Enabled {and NewStyleControls }then
begin
Canvas.Font.Color := clInactiveCaption;
end;
R := Rect(0, 0, ClientWidth, ClientHeight); R := Rect(0, 0, ClientWidth, ClientHeight);
if BorderStyle = bsNone then if ThemeServices.ThemesEnabled and (FStyle = rxcsDropDownList) then
begin begin
border := 3; if Enabled then
if Flat then
begin begin
Canvas.Frame3d(R, border, bvLowered); if MouseInClient then
begin
if FMouseDown then
begin
Details := ThemeServices.GetElementDetails(tbPushButtonPressed);
DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonPressed);
end
else
begin
Details := ThemeServices.GetElementDetails(tbPushButtonHot);
DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonHot);
end;
end
else
begin
Details := ThemeServices.GetElementDetails(tbPushButtonNormal);
DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
end;
end end
else else
begin begin
RxFrame3D(Canvas, R, clWindowFrame, clBtnHighlight, 1); Details := ThemeServices.GetElementDetails(tbPushButtonDisabled);
RxFrame3D(Canvas, R, clBtnShadow, clBtnFace, 1); DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonDisabled);
end; end;
end ThemeServices.DrawElement(Canvas.Handle, Details, R, nil);
else
begin
border := 1; //BtnSize:=ThemeServices.GetDetailSize(DetailsBtn);
end; BtnSize.Width:=20;
// adjust this for each OS, on windows looks fine
R1 := Rect(ClientWidth - BtnSize.Width, 1, ClientWidth, ClientHeight - 1);
R2 := Rect(r1.Left+1, r1.Top+1, r1.Right-2, r1.Bottom-1);
pr := @R2;
ThemeServices.DrawElement(Canvas.Handle, DetailsBtn, R1, pr);
R.Right:=R.Right - BtnSize.Width;
if ClientWidth > 2*border then
begin
R1 := Rect(border, border, ClientWidth - border, ClientHeight - border);
Canvas.FillRect(R1);
R.Right := R.Right - GetButtonWidth;
if PopupVisible and (Caption<>'') then
begin
AText := Caption;
Canvas.TextRect(R, TextMargin, Max(0, (HeightOf(R) - Canvas.TextHeight('Wg')) div 2), AText);
end
else
if FDisplayAll then if FDisplayAll then
PaintDisplayValues(Canvas, R, TextMargin) PaintDisplayValues(Canvas, R, TextMargin, @Details)
else else
begin begin
if Assigned(FDataField) and FDataField.IsNull then if Assigned(FDataField) and FDataField.IsNull then
begin
R1 := Rect(border + padding, border + padding, ClientWidth - (border + padding) - GetButtonWidth, ClientHeight - (border + padding));
Canvas.Brush.Color:=FEmptyItemColor;
Canvas.FillRect(R1);
AText:=FEmptyValue AText:=FEmptyValue
end
else else
if FValuesList.Count > 0 then if FValuesList.Count > 0 then
AText:=FValuesList[FLookupDisplayIndex] AText:=FValuesList[FLookupDisplayIndex]
else else
AText:=''; AText:='';
Canvas.TextRect(R, TextMargin, Max(0, (HeightOf(R) - Canvas.TextHeight('Wg')) div 2), AText); R.Left:=R.Left + TextMargin;
ThemeServices.DrawText(Canvas, Details, AText, R, DT_LEFT or DT_VCENTER or DT_SINGLELINE, 0);
end;
end
else
begin
Canvas.Font := Font;
Canvas.Brush.Color := Color;
Selected := Focused and (not (csPaintCopy in ControlState)) and (not PopupVisible);
if Selected then
begin
Canvas.Font.Color := clHighlightText;
Canvas.Brush.Color := clHighlight;
end end
else
if not Enabled {and NewStyleControls }then
begin
Canvas.Font.Color := clInactiveCaption;
end;
if BorderStyle = bsNone then
begin
border := 3;
if Flat then
begin
Canvas.Frame3d(R, border, bvLowered);
end
else
begin
RxFrame3D(Canvas, R, clWindowFrame, clBtnHighlight, 1);
RxFrame3D(Canvas, R, clBtnShadow, clBtnFace, 1);
end;
end
else
begin
border := 1;
end;
if ClientWidth > 2*border then
begin
R1 := Rect(border, border, ClientWidth - border, ClientHeight - border);
Canvas.FillRect(R1);
R.Right := R.Right - GetButtonWidth;
if PopupVisible and (Caption<>'') then
begin
AText := Caption;
Canvas.TextRect(R, TextMargin, Max(0, (HeightOf(R) - Canvas.TextHeight('Wg')) div 2), AText);
end
else
if FDisplayAll then
PaintDisplayValues(Canvas, R, TextMargin, nil)
else
begin
if Assigned(FDataField) and FDataField.IsNull then
begin
R1 := Rect(border + padding, border + padding, ClientWidth - (border + padding) - GetButtonWidth, ClientHeight - (border + padding));
Canvas.Brush.Color:=FEmptyItemColor;
Canvas.FillRect(R1);
AText:=FEmptyValue
end
else
if FValuesList.Count > 0 then
AText:=FValuesList[FLookupDisplayIndex]
else
AText:='';
Canvas.TextRect(R, TextMargin, Max(0, (HeightOf(R) - Canvas.TextHeight('Wg')) div 2), AText);
end
end;
end; end;
end; end;
@@ -1571,6 +1699,16 @@ begin
end; end;
end; end;
procedure TRxCustomDBLookupCombo.SetStyle(AValue: TRxDBLookupStyle);
begin
if FStyle=AValue then Exit;
FStyle:=AValue;
CheckButtonVisible;
if FStyle = rxcsDropDownList then
BorderStyle:=bsNone;
Invalidate;
end;
function TRxCustomDBLookupCombo.GetKeyValue: Variant; function TRxCustomDBLookupCombo.GetKeyValue: Variant;
begin begin
if Value = FEmptyValue then if Value = FEmptyValue then
@@ -1589,6 +1727,8 @@ var
ArrowBmp:TBitmap; ArrowBmp:TBitmap;
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FMouseDown:=false;
FStyle:=rxcsDropDown;
FStopClick:=false; FStopClick:=false;
Width := 100; Width := 100;
AutoSize:=true; AutoSize:=true;