mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 15:59:13 +02:00
LCL: Prevent opening custom color selection dialog in ColorBox wrongly. Issue #28549, patch from Janusz Tomczak.
git-svn-id: trunk@49699 -
This commit is contained in:
parent
806d5df569
commit
57795c6d42
@ -20,8 +20,8 @@ unit ColorBox;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LResources, SysUtils, LCLProc, LCLType, Classes, Graphics, Controls, Forms,
|
LResources, SysUtils, Types, Classes,
|
||||||
Dialogs, StdCtrls, LCLStrConsts;
|
LCLProc, LCLType, LCLStrConsts, Graphics, Controls, Forms, Dialogs, StdCtrls;
|
||||||
|
|
||||||
const
|
const
|
||||||
cDefaultColorRectWidth = 14;
|
cDefaultColorRectWidth = 14;
|
||||||
@ -40,6 +40,7 @@ type
|
|||||||
cbPrettyNames, // use good looking color names - like Red for clRed
|
cbPrettyNames, // use good looking color names - like Red for clRed
|
||||||
cbCustomColors); // call OnGetColors after all other colors processing
|
cbCustomColors); // call OnGetColors after all other colors processing
|
||||||
TColorBoxStyle = set of TColorBoxStyles;
|
TColorBoxStyle = set of TColorBoxStyles;
|
||||||
|
TColorBoxCloseKey = (cbckNone, cbckReturn, cbckOther);
|
||||||
TGetColorsEvent = procedure(Sender: TCustomColorBox; Items: TStrings) of object;
|
TGetColorsEvent = procedure(Sender: TCustomColorBox; Items: TStrings) of object;
|
||||||
|
|
||||||
TCustomColorBox = class(TCustomComboBox)
|
TCustomColorBox = class(TCustomComboBox)
|
||||||
@ -51,6 +52,7 @@ type
|
|||||||
FOnGetColors: TGetColorsEvent;
|
FOnGetColors: TGetColorsEvent;
|
||||||
FStyle: TColorBoxStyle;
|
FStyle: TColorBoxStyle;
|
||||||
FSelected: TColor;
|
FSelected: TColor;
|
||||||
|
FCloseMode: TColorBoxCloseKey;
|
||||||
function GetColor(Index : Integer): TColor;
|
function GetColor(Index : Integer): TColor;
|
||||||
function GetColorName(Index: Integer): string;
|
function GetColorName(Index: Integer): string;
|
||||||
function GetSelected: TColor;
|
function GetSelected: TColor;
|
||||||
@ -68,7 +70,9 @@ type
|
|||||||
procedure Loaded; override;
|
procedure Loaded; override;
|
||||||
procedure InitializeWnd; override;
|
procedure InitializeWnd; override;
|
||||||
procedure DoGetColors; virtual;
|
procedure DoGetColors; virtual;
|
||||||
|
procedure DropDown; override;
|
||||||
procedure CloseUp; override;
|
procedure CloseUp; override;
|
||||||
|
procedure KeyDownBeforeInterface(var Key: Word; Shift: TShiftState); override;
|
||||||
function PickCustomColor: Boolean; virtual;
|
function PickCustomColor: Boolean; virtual;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
@ -378,7 +382,6 @@ begin
|
|||||||
FNoneColorColor := clBlack;
|
FNoneColorColor := clBlack;
|
||||||
FDefaultColorColor := clBlack;
|
FDefaultColorColor := clBlack;
|
||||||
FSelected := clBlack;
|
FSelected := clBlack;
|
||||||
|
|
||||||
SetColorList;
|
SetColorList;
|
||||||
end;
|
end;
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -667,10 +670,36 @@ begin
|
|||||||
OnGetColors(Self, Items)
|
OnGetColors(Self, Items)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomColorBox.CloseUp;
|
procedure TCustomColorBox.KeyDownBeforeInterface(var Key: Word; Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
if (cbCustomColor in Style) and (ItemIndex = 0) then // custom color has been selected
|
if DroppedDown then
|
||||||
PickCustomColor;
|
begin
|
||||||
|
if Key = VK_Return then
|
||||||
|
FCloseMode := cbckReturn
|
||||||
|
else
|
||||||
|
FCloseMode := cbckOther; // other keys: Escape, Tab, Space etc.
|
||||||
|
end;
|
||||||
|
inherited KeyDownBeforeInterface(Key, Shift);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomColorBox.DropDown;
|
||||||
|
begin
|
||||||
|
FCloseMode := cbckNone;
|
||||||
|
inherited DropDown;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomColorBox.CloseUp;
|
||||||
|
var
|
||||||
|
mp, co: TPoint;
|
||||||
|
cr: TRect;
|
||||||
|
begin
|
||||||
|
mp := Mouse.CursorPos;
|
||||||
|
co := ClientOrigin;
|
||||||
|
cr := Rect(co.x, co.y+Height+BorderWidth, co.x+Width, co.y+Height+ItemHeight);
|
||||||
|
if (cbCustomColor in Style) and (ItemIndex = 0) and (
|
||||||
|
(PtInRect(cr, mp) and (FCloseMode <> cbckOther)) or (FCloseMode = cbckReturn)
|
||||||
|
) then
|
||||||
|
PickCustomColor; // custom color has been selected
|
||||||
if ItemIndex <> -1 then
|
if ItemIndex <> -1 then
|
||||||
Selected := Colors[ItemIndex];
|
Selected := Colors[ItemIndex];
|
||||||
inherited CloseUp;
|
inherited CloseUp;
|
||||||
|
Loading…
Reference in New Issue
Block a user