From eecc3645f1cae4efeaae3ef43d742c708dafac3a Mon Sep 17 00:00:00 2001 From: Bart <9132501-flyingsheep@users.noreply.gitlab.com> Date: Sun, 8 Dec 2024 13:56:18 +0100 Subject: [PATCH] LCL: implement TColorDialog.Options. Currently only supported for Win32/Win64 widgetset. Issue #22717. The default value differs from Delphi (7) for backwards compatibility (CC_FULLOPEN flag was always set in Windows). (cherry picked from commit 9077ef32a28b9736cad2528ca889a7338c9189e3) --- lcl/dialogs.pp | 18 +++++++++++++++++- lcl/include/lclcolordialog.inc | 1 + lcl/interfaces/win32/win32wsdialogs.pp | 17 ++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lcl/dialogs.pp b/lcl/dialogs.pp index 01f27aca68..693e13f995 100644 --- a/lcl/dialogs.pp +++ b/lcl/dialogs.pp @@ -287,12 +287,27 @@ type constructor Create(AOwner: TComponent); override; end; + TColorDialogOption = ( + cdFullOpen, // Causes the dialog box to display the additional controls that allow the user to create custom colors. + cdPreventFullOpen, // Disables the Define Custom Color button. + cdShowHelp, // Causes the dialog box to display the Help button. + cdSolidColor, // Causes the dialog box to display only solid colors in the set of basic colors. + cdAnyColor // Causes the dialog box to display all available colors in the set of basic colors. + ); + TColorDialogOptions = set of TColorDialogOption; + +const + DefaultColorDialogOptions = [cdFullOpen]; //for backwards compatibility, probably not Delphi compatible + { TColorDialog } - +type + TColorDialog = class(TCommonDialog) private FColor: TColor; FCustomColors: TStrings; + FOptions: TColorDialogOptions; + procedure SetCustomColors(const AValue: TStrings); procedure AddDefaultColor(const s: AnsiString); protected @@ -306,6 +321,7 @@ type property Color: TColor read FColor write FColor; // entry looks like ColorA = FFFF00 ... ColorX = C0C0C0 property CustomColors: TStrings read FCustomColors write SetCustomColors; + property Options: TColorDialogOptions read FOptions write FOptions default DefaultColorDialogOptions; end; diff --git a/lcl/include/lclcolordialog.inc b/lcl/include/lclcolordialog.inc index 9a68fe250b..37af28b189 100644 --- a/lcl/include/lclcolordialog.inc +++ b/lcl/include/lclcolordialog.inc @@ -52,6 +52,7 @@ begin // add default colors GetColorValues(@AddDefaultColor); fCompStyle := csColorDialog; + FOptions := DefaultColorDialogOptions; end; destructor TColorDialog.Destroy; diff --git a/lcl/interfaces/win32/win32wsdialogs.pp b/lcl/interfaces/win32/win32wsdialogs.pp index 744fa3a048..07cc924976 100644 --- a/lcl/interfaces/win32/win32wsdialogs.pp +++ b/lcl/interfaces/win32/win32wsdialogs.pp @@ -114,6 +114,8 @@ type { TWin32WSColorDialog } TWin32WSColorDialog = class(TWSColorDialog) + public + class function ColorDialogOptionsToFlags(Options: TColorDialogOptions): DWORD; published class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override; class procedure ShowModal(const ACommonDialog: TCommonDialog); override; @@ -369,6 +371,18 @@ begin Result := 0; end; +class function TWin32WSColorDialog.ColorDialogOptionsToFlags(Options: TColorDialogOptions): DWORD; +const + CC_ANYCOLOR = $00000100; +begin + Result := 0; + if cdFullOpen in Options then Result := Result or CC_FULLOPEN; + if cdPreventFullOpen in Options then Result := Result or CC_PREVENTFULLOPEN; + if cdShowHelp in Options then Result := Result or CC_SHOWHELP; + if cdSolidColor in Options then Result := Result or CC_SOLIDCOLOR; + if cdAnyColor in Options then Result := Result or CC_ANYCOLOR; +end; + class function TWin32WSColorDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle; var CC: PChooseColor; @@ -398,7 +412,8 @@ begin FillCustomColors; lCustData := LParam(ACommonDialog); lpfnHook := @CCHookProc; - Flags := CC_FULLOPEN or CC_RGBINIT or CC_ENABLEHOOK; + Flags := {CC_FULLOPEN or }CC_RGBINIT or CC_ENABLEHOOK; + Flags := Flags or ColorDialogOptionsToFlags(ColorDialog.Options); end; Result := THandle(CC); end;