LCL: Allow external ColorDialog for custom operations in TColorBox and TColorListBox. issue #39189, patch by jamie philbrook.

git-svn-id: trunk@65426 -
This commit is contained in:
juha 2021-07-09 09:14:19 +00:00
parent 2bf2902c91
commit 9278af1408

View File

@ -49,6 +49,7 @@ type
FColorRectOffset: Integer; FColorRectOffset: Integer;
FDefaultColorColor: TColor; FDefaultColorColor: TColor;
FNoneColorColor: TColor; FNoneColorColor: TColor;
FcolorDialog:TColorDialog;
FOnGetColors: TGetColorsEvent; FOnGetColors: TGetColorsEvent;
FStyle: TColorBoxStyle; FStyle: TColorBoxStyle;
FSelected: TColor; FSelected: TColor;
@ -87,6 +88,7 @@ type
property DefaultColorColor: TColor read FDefaultColorColor write SetDefaultColorColor default clBlack; property DefaultColorColor: TColor read FDefaultColorColor write SetDefaultColorColor default clBlack;
property NoneColorColor: TColor read FNoneColorColor write SetNoneColorColor default clBlack; property NoneColorColor: TColor read FNoneColorColor write SetNoneColorColor default clBlack;
property OnGetColors: TGetColorsEvent read FOnGetColors write FOnGetColors; property OnGetColors: TGetColorsEvent read FOnGetColors write FOnGetColors;
property ColorDialog:TcolorDialog read FColorDialog write FcolorDialog;
end; end;
{ TColorBox } { TColorBox }
@ -100,7 +102,7 @@ type
property Selected; property Selected;
property Style; property Style;
property OnGetColors; property OnGetColors;
property ColorDialog;
property Align; property Align;
property Anchors; property Anchors;
property ArrowKeysTraverseList; property ArrowKeysTraverseList;
@ -170,6 +172,7 @@ type
FDefaultColorColor: TColor; FDefaultColorColor: TColor;
FNoneColorColor: TColor; FNoneColorColor: TColor;
FOnGetColors: TLBGetColorsEvent; FOnGetColors: TLBGetColorsEvent;
FColorDialog:TColorDialog;
FSelected: TColor; FSelected: TColor;
FStyle: TColorBoxStyle; FStyle: TColorBoxStyle;
function GetColorRectWidth: Integer; function GetColorRectWidth: Integer;
@ -207,6 +210,7 @@ type
property DefaultColorColor: TColor read FDefaultColorColor write SetDefaultColorColor default clBlack; property DefaultColorColor: TColor read FDefaultColorColor write SetDefaultColorColor default clBlack;
property NoneColorColor: TColor read FNoneColorColor write SetNoneColorColor default clBlack; property NoneColorColor: TColor read FNoneColorColor write SetNoneColorColor default clBlack;
property OnGetColors: TLBGetColorsEvent read FOnGetColors write FOnGetColors; property OnGetColors: TLBGetColorsEvent read FOnGetColors write FOnGetColors;
property ColorDialog:TColorDialog read fcolorDialog write FColorDialog;
end; end;
{ TColorListBox } { TColorListBox }
@ -220,7 +224,7 @@ type
property Selected; property Selected;
property Style; property Style;
property OnGetColors; property OnGetColors;
property ColorDialog;
property Align; property Align;
property Anchors; property Anchors;
property BidiMode; property BidiMode;
@ -708,23 +712,29 @@ begin
end; end;
function TCustomColorBox.PickCustomColor: Boolean; function TCustomColorBox.PickCustomColor: Boolean;
Var
FreeDialog:Boolean;
begin begin
if csDesigning in ComponentState then if csDesigning in ComponentState then
begin begin
Result := False; Result := False;
Exit; Exit;
end; end;
FreeDialog := FcolorDialog = NIL;
with TColorDialog.Create(Self) do If FColorDialog = Nil Then FcolorDialog := TcolorDialog.Create(GetTopParent);
begin Try
Color := Colors[0]; With FColorDialog do
Result := Execute; Begin
if Result then Color := Colors[0];
begin Result := Execute;
Items.Objects[0] := TObject(PtrInt(Color)); If Result Then
invalidate; Begin
items.objects[0]:= TObject(PtrInt(COlor));
Invalidate;
end;
end; end;
Free; finally
If FreeDialog Then FreeAndNil(FcolorDialog);
end; end;
end; end;
@ -1059,23 +1069,29 @@ begin
end; end;
function TCustomColorListBox.PickCustomColor: Boolean; function TCustomColorListBox.PickCustomColor: Boolean;
Var
FreeDialog:Boolean;
begin begin
if csDesigning in ComponentState then if csDesigning in ComponentState then
begin begin
Result := False; Result := False;
Exit; Exit;
end; end;
FreeDialog := FcolorDialog = NIL;
with TColorDialog.Create(Self) do If FColorDialog = Nil Then FcolorDialog := TcolorDialog.Create(GetTopParent);
begin Try
Color := Colors[0]; With FColorDialog do
Result := Execute; Begin
if Result then Color := Colors[0];
begin Result := Execute;
Items.Objects[0] := TObject(PtrInt(Color)); If Result Then
invalidate; Begin
items.objects[0]:= TObject(PtrInt(COlor));
Invalidate;
end;
end; end;
Free; finally
If FreeDialog Then FreeAndNil(FcolorDialog);
end; end;
end; end;