[fixed] [bug 39155] Title of TColorDialog is not shown lazarus / 31-LCL ---------------------------------------------------------------------- Muso · 2021-07-04 13:40 I use Lazarus 2.3.0 r65354 FPC 3.2.2 x86_64-win64-win32/win64 and when executing a TColorDialog, the content of its Title property is not shown. In my case the title is "Select Chart Background Color" but when the color dialog is shown, I can't see the title anywhere, see the attached screenshot. Is there a further setting necessary to get the title displayed? Another issue is that my program is in English because since the Windows is a German ones not every colleague who should use the program can read German well. So how can I translate the dialog to English? I found how to translate in general: https://wiki.lazarus.freepascal.org/Translations_/_i18n_/_localization s_for_programs#Translating_at_start_of_program but maybe the standard dialogs are already translated and I just have to call them differently to get them in English? ---------------------------------------------------------------------- wp · 2021-07-04 15:27 Debugging into this issue I noticed that the TColorDialog.Execute in case of the win32_64 widgetset calls the Windows function ChooseColor - this means that all you see is done by Windows. ChooseColor accepts a pointer to a record with parameters, but the form Title is not among them. So, you either live with this deficiency, or you write your own color dialog. ---------------------------------------------------------------------- jamie · 2021-07-04 16:51 ChooseColor can have its caption altered but because its a modal form its hard to get to the handle unless you scan for the active form which would be the Dialog at the time. I guess this could be done in the OnShow maybe but I am not so sure if the form is ready at that time ?  But in any case, the real issue is that a Callback was never created in the widget (flag and Callback address) for the dialog initiation event. In this event you can use the Windows.SetWindowText('xxxxx') and you will get what you need.  Looking in the other Win32WSDilogs examples you can see how it's done. ---------------------------------------------------------------------- Muso · 2021-07-04 17:02 Quote from: wp on July 04, 2021, 05:27:36 pmChooseColor accepts a pointer to a record with parameters, but the form Title is not among them. So, you either live with this deficiency, or you write your own color dialog. I don't fully understand because for example the SaveDialog works fine - I get the title displayed. Is it not possible to fix the ColorDialog to behave like the SaveDialog or FileOpen dialog of the LCL? ---------------------------------------------------------------------- Muso · 2021-07-04 17:09 Quote from: jamie on July 04, 2021, 06:51:31 pmBut in any case, the real issue is that a Callback was never created in the widget (flag and Callback address) for the dialog initiation event. In this event you can use the Windows.SetWindowText('xxxxx') and you will get what you need. Looking in the other Win32WSDilogs examples you can see how it's done. Maybe because I am still quite a noob, I don't understand your post. I mean I develop a 64bit program, so no Win32 specials should be used. I only use the dialogs provided by the LCL and since TFileOpenDialog has a title I thought TColorDialog's title works the same way. if not, I think that the Title property should then not be offered in the IDE. In any case, what should I do as bug report? Report that the title is not shown or that this property is offered while it won't be used? ---------------------------------------------------------------------- jamie · 2021-07-04 17:13 You can file a bug report If you wish.  If you do, make sure you point back to this thread and explain a little that it needs a callback for the dialog in the Widget, the DEVS will understand. ---------------------------------------------------------------------- Muso · 2021-07-04 22:03 Quote from: jamie on July 04, 2021, 07:13:16 pm You can file a bug report If you wish.   If you do, make sure you point back to this thread and explain a little that it needs a callback for the dialog in the Widget, the DEVS will understand. Done, here is the bug report: https://bugs.freepascal.org/view.php?id=39155 ---------------------------------------------------------------------- Bart · 2021-07-05 08:58 Quote from: Muso on July 05, 2021, 12:03:57 amDone, here is the bug report: https://bugs.freepascal.org/view.php?id=39155 As explained to you by wp, this is not a bug. As Lazarus tries to use (by design) native dialogs (as in: native to the underlying OS/widgetset), it simply displays the normal colordialog that Windows provides. And you cannot set the title of that dialog. I therefore resolve this bugreport as "no change required". Please close it. W.r.t. TOpen/TSaveDialog: Windows (and most other widgetsets) let you specify it's title, since the dialog can be used to select one or mer files and then do with those files (actually the filenames) whatever the progeam sees fit: open them, displaye the names in a TMemo, send the names to another process, upload them to somewehere else etc etc. If the dialog would alway have the title "Open" then this would not be correct in most of these scenario's. Bart ---------------------------------------------------------------------- Muso · 2021-07-05 09:07 Quote from: Bart on July 05, 2021, 10:58:14 amAs explained to you by wp, this is not a bug. Sorry, but I still don't understand the IDE then. * TOpenDialog: I set "Title" to "Open Sensor Definition File" and get correctly the dialog with this title, see attached. * TColorDialog: The IDE provides a "Title" but this will never appear. So either the bug is that the title handling is different for color than wit the other dialogs or the bug is that a title is offered at all. As it is it is definitely a bug because it costs time for the user to find out why the offered property is not used. ---------------------------------------------------------------------- Soner · 2021-07-05 09:12 Somethings are going wrong on creation of the colordialog. Look at my notice on the bug report. The handle of colordialog is invalid when onshow fired while the handle of opendialog is valid. I could not find the error, I think it is bug. ---------------------------------------------------------------------- wp · 2021-07-05 09:18 Quote from: Muso on July 05, 2021, 11:07:45 am* TColorDialog: The IDE provides a "Title" but this will never appear. This statement is correct only for Windows. On Linux gtk2, the user- defined title will be used. It is similar to the Font or Color properties of some controls - the properties are there, but it depends on the widgetset if they can be used or not. When you look at page "Restricted" of the object inspector you'll see the entry "Title" for the TColorDialog - this means that there are restrictions regarding this TColorDialog property ---------------------------------------------------------------------- Bart · 2021-07-05 10:12 I closed that bugreport. Bart ---------------------------------------------------------------------- Muso · 2021-07-05 11:40 Quote from: Bart on July 05, 2021, 12:12:57 pmI closed that bugreport. Despite user Soner just stated that he too thinks it is a bug? ---------------------------------------------------------------------- Muso · 2021-07-05 11:44 Quote from: wp on July 05, 2021, 11:18:48 amWhen you look at page "Restricted" of the object inspector you'll see the entry "Title" for the TColorDialog - this means that there are restrictions regarding this TColorDialog .property Interesting, I did not know this. To make this more clear for the users, restricted fields should become disabled in the IDE However, the question remains why does the title work for the other dialogs but not for the ColorDialog? In the bugreports users posted methods how to achieve the title in Delphi and I thought what is possible with system dialogs in Delphi is then also possible on Windows in general and therefore should also be somehow doable in Lazarus. ---------------------------------------------------------------------- jamie · 2021-07-05 12:34 Sorry.. I have both a local work around and patch ready for submission to include the Callback hook in the Widget so the title can be assigned.. I see the report was closed, no surprise.. I'll file this back in my archives for my use if I ever decide I need it. I can't deal with the politics of a few individuals, someone else will have to fight the battle. Enjoy. ---------------------------------------------------------------------- Muso · 2021-07-05 13:04 Quote from: jamie on July 05, 2021, 02:34:24 pmI have both a local work around and patch ready for submission to include the Callback hook in the Widget so the title can be assigned..   Thanks. Can you please post your patch here that even when the admin refuse it, I could use it for my programs? ---------------------------------------------------------------------- jamie · 2021-07-05 14:31 what I will do is post the local work around as a demo project, you can take it from there. P.S.   Be very careful to only make changes in the hook procedure when the WM_InitDialg message comes in, ignore all others. there is lots of traffic that comes through  there you don't want to be playing games. ---------------------------------------------------------------------- wp · 2021-07-05 15:16 Quote from: jamie on July 05, 2021, 02:34:24 pmI see the report was closed, no surprise.. What does this mean? Rather than being pissed off, extract the essentials out of your demo project and put it into the win32 widgetset infrastructure, create a proper patch, reopen Muso's bug report (or create a new one if you are not allowed to), and I dont't see a reason why this should not make it into the LCL. ---------------------------------------------------------------------- jamie · 2021-07-05 15:36 I am not pissed off, just frustrated with certain situations. If I was pissed off I wouldn't be here any more..   Appended  is a mod to make it easier to use the same code for  multiple color dialogs using what is already provided by windows for since the beginning of color dialogs.  Any one is free to do as they wish with this code, even wedge it into the widget if they feel like it.  I need to review the patch again, I only did with my local copy here which is 2.0.4 . Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function CCHookProc(H:THandle; msg:Cardinal; W:Wparam; L:Lparam):UintPtr; StdCall;var  S:String;Begin  If (H <> 0) and (Msg = Wm_InitDialog) then   Begin     S := TColorDialog(PchooseColor(L)^.lCustData).Title ;     SetWindowText(H, Pchar(S));   end;  Result := 0;end; procedure TForm1.ColorDialog1Show(Sender: TObject);Var  C:PChooseColor;begin  With TColorDialog(Sender) do    Begin     C := Pointer(Handle); //This handle is actually a pointer to a ChoseColor record;     C^.lpfnHook := @CCHookPRoc;     C^.lCustData := UintPtr(Sender); //Give the callback the Color dialog instance to play with.     C^.Flags := C^.Flags or CC_ENABLEHOOK;    end; end; ---------------------------------------------------------------------- Muso · 2021-07-05 15:44 Quote from: jamie on July 05, 2021, 05:36:16 pmI am not pissed off, just frustrated with certain situations. If I was pissed off I wouldn't be here any more.. Very good to hear. Frustrations go away, and the best way is when a patch is accepted.  I can confirm that your code fixes the problem and the output is exactly as I expected it. Can you therefore please make a patch to have it included to the LCL? ---------------------------------------------------------------------- wp · 2021-07-05 16:23 Integrated jamie's code into the windows widgetset (and fixed the character encoding issue) --> works. Please test from trunk. ---------------------------------------------------------------------- jamie · 2021-07-05 16:32 @WP   Did you go by my last mod so that it properly assigns different dialogs when they show ?   The ChoseColor record has the customData pointer in it that passes it to the call back so you can determine who or which Dialog it is.  But looking at it, I thought it to be a 2 file process.? Anyways, I just built the trunk and it looks good but I only did one color dialog. ---------------------------------------------------------------------- wp · 2021-07-05 16:41 No idea what you mean.... This is the code that I added to/modified in win32wsdialog.pp, and in my tests it is working correctly in both 32bit and 64bit: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function CCHookProc(H: THandle; msg: Cardinal; W: WParam; L: LParam): UintPtr; StdCall;  // <--- addedvar  ws: WideString;begin  if (H <> 0) and (Msg = WM_InitDialog) then  begin    ws := TColorDialog(PChooseColor(L)^.lCustData).Title;    SetWindowTextW(H, PWideChar(ws));  end;  Result := 0;end; class function TWin32WSColorDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle;var  CC: PChooseColor;  ColorDialog: TColorDialog absolute ACommonDialog;   procedure FillCustomColors;  var    i, AIndex: integer;    AColor: TColor;  begin    for i := 0 to ColorDialog.CustomColors.Count - 1 do      if ExtractColorIndexAndColor(ColorDialog.CustomColors, i, AIndex, AColor) then      begin        if AIndex < 16 then          CC^.lpCustColors[AIndex] := AColor;      end;  end; begin  CC := AllocMem(SizeOf(TChooseColor));  with CC^ Do  begin    LStructSize := sizeof(TChooseColor);    HWndOwner := GetOwnerHandle(ACommonDialog);  RGBResult := ColorToRGB(ColorDialog.Color);    LPCustColors := AllocMem(16 * SizeOf(DWord));    FillCustomColors;    lCustData := LParam(ACommonDialog);      // <--- added    lpfnHook := @CCHookProc;                // <--- added    Flags := CC_FULLOPEN or CC_RGBINIT or CC_ENABLEHOOK;  // <--- extended  end;  Result := THandle(CC);end; ---------------------------------------------------------------------- jamie · 2021-07-05 16:42 Perfect..  yes, I forgot it all up in the widget.. Thanks. ---------------------------------------------------------------------- Muso · 2021-07-05 18:14 Quote from: wp on July 05, 2021, 06:23:22 pmIntegrated jamie's code into the windows widgetset (and fixed the character encoding issue) --> works. Please test from trunk. Many thanks! I can confirm that the bug is now fixed in latest Lazarus trunk. ---------------------------------------------------------------------- Muso · 2021-07-05 18:17 Concerning Jamie's frustration, maybe the next time bugs are not immediately be closed. We all code in our spare time and thus time is necessary to think about and for users to look at the different forum threads. ---------------------------------------------------------------------- jamie · 2021-07-05 19:04 Glad things worked out I just came up with an idea that relates to this.. There are three color pick controls. ColorBUtton, ColorListBox and ColorBox. none of which have a property to define the title of the internal TcolorDialog that is used..    Would be nice if these controls had a dialogTitle property  btw.  We can all thank WP for pushing this through.. ---------------------------------------------------------------------- Bart · 2021-07-05 21:30 Quote from: jamie on July 05, 2021, 09:04:28 pmThere are three color pick controls. ColorBUtton, ColorListBox and ColorBox. none of which have a property to define the title of the internal TcolorDialog that is used..   Would be nice if these controls had a dialogTitle property  TColorButton has a property ColorDialog, so it is accessible through that. The other 2 controls could use that in their PickCustomColor function I guess? Feel free to provide a patch in a (new) bugtracker issue. Bart ---------------------------------------------------------------------- Bart · 2021-07-05 21:54 Quote from: Muso on July 05, 2021, 08:14:44 pmQuote from: wp on July 05, 2021, 06:23:22 pmIntegrated jamie's code into the windows widgetset (and fixed the character encoding issue) --> works. Please test from trunk. Many thanks! I can confirm that the bug is now fixed in latest Lazarus trunk. And it caused a regression, see the associated bugreport. Bart ---------------------------------------------------------------------- jamie · 2021-07-06 01:45 Quote from: Bart on July 05, 2021, 11:54:06 pmQuote from: Muso on July 05, 2021, 08:14:44 pmQuote from: wp on July 05, 2021, 06:23:22 pmIntegrated jamie's code into the windows widgetset (and fixed the character encoding issue) --> works. Please test from trunk. Many thanks! I can confirm that the bug is now fixed in latest Lazarus trunk. And it caused a regression, see the associated bugreport. Bart Bart, Please stop it...  There is no regression. The fact is that it has been stated it worked in the other widgets and if that is the case then they must of been displaying "Select Color" because that is the default string in the TColorDialog and that never got changed.  For those that grew up on windows and have used many other tools knows that having an optional display at the top has always been the case. I am sorry that you just can't see it that way. This isn't any hack. its actual documented features of windows and I get the feeling you already know this. Or, maybe you don't?  I do think I understand the real problem and it has nothing to do with the changes made.. I believe most of us are adults here, aren't we?