Recent

Author Topic: Can't set title and PreviewText in FontDialog  (Read 2464 times)

HexLaden

  • New member
  • *
  • Posts: 8
Can't set title and PreviewText in FontDialog
« on: February 06, 2023, 01:00:28 pm »
Hello!
Code: Pascal  [Select][+][-]
  1. ...
  2. dlgfont: TFontDialog;
  3. ...
  4.  
  5. procedure Tfrorm.btnFontClick(Sender: TObject);
  6. begin
  7.   dlgFont.Title:= 'Select font';
  8.   dlgFont.PreviewText:= 'The quick brown fox jumps';
  9.   dlgFont.Options:= dlgFont.Options + [fdEffects, fdApplyButton];
  10.   if not dlgFont.Execute then Exit;
  11.   ...
  12. end;

I'm using Lazarus 2.2.4 in Win 10.

Font dialog remains with standard title caption and standard 'Abcd' as preview text.

Tried to set them in object inspector's properties also, but had the same result.

Are these properties managed by the operating system only?

Thank you!

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Can't set title and PreviewText in FontDialog
« Reply #1 on: February 06, 2023, 01:39:40 pm »
For the property PreviewText
Quote
Please note that use of PreviewText is dependent on platform / widgetset support. For instance, Windows does render PreviewText. It uses its own "Sample", and renders the font name in the selection list using the typeface. QT and QT5 have the same behavior as Windows. It is implemented for the GTK, GTK2 and MUI widgetsets.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Can't set title and PreviewText in FontDialog
« Reply #2 on: February 06, 2023, 01:42:53 pm »
For the property Title
It is defined in commondialog.inc as
Code: Pascal  [Select][+][-]
  1. constructor TCommonDialog.Create (TheOwner: TComponent);
  2. begin
  3.   inherited Create(TheOwner);
  4.   FTitle := DefaultTitle;
  5. end;
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

balazsszekely

  • Guest
Re: Can't set title and PreviewText in FontDialog
« Reply #3 on: February 06, 2023, 03:04:57 pm »
Hello!
Code: Pascal  [Select][+][-]
  1. ...
  2. dlgfont: TFontDialog;
  3. ...
  4.  
  5. procedure Tfrorm.btnFontClick(Sender: TObject);
  6. begin
  7.   dlgFont.Title:= 'Select font';
  8.   dlgFont.PreviewText:= 'The quick brown fox jumps';
  9.   dlgFont.Options:= dlgFont.Options + [fdEffects, fdApplyButton];
  10.   if not dlgFont.Execute then Exit;
  11.   ...
  12. end;

I'm using Lazarus 2.2.4 in Win 10.

Font dialog remains with standard title caption and standard 'Abcd' as preview text.

Tried to set them in object inspector's properties also, but had the same result.

Are these properties managed by the operating system only?

Thank you!
Welcome to the forum! I hope you're not a spammer or even worse a lurker.  :D
Almost everything is possible on windows. Please test attached project.

HexLaden

  • New member
  • *
  • Posts: 8
Re: Can't set title and PreviewText in FontDialog
« Reply #4 on: February 06, 2023, 05:25:03 pm »
@KodeZwerg. Thank you, I searched in the forum and over the net for the PreviewText information you provided now, but could't find it.

@GetMem: Thank you for the warm welcome. The forum community has nothing to worry about: I'm neither a spammer nor a lurker. I've been clarifying my doubts reading lots of excelent forum contributions on the past year and a half, or so. They are so good that I never needed to post any question, till now.
Your handler works perfectly. Very clever and elegant solution. Thank you!

balazsszekely

  • Guest
Re: Can't set title and PreviewText in FontDialog
« Reply #5 on: February 06, 2023, 06:08:23 pm »
@HexLaden
Quote
I'm neither a spammer nor a lurker. I've been clarifying my doubts reading lots of excelent forum contributions on the past year and a half, or so. They are so good that I never needed to post any question, till now.
OK then, I owe you an apology. Unfortunately there are a lot of annoying spammers lately(the lurker part was a joke).

Quote
Your handler works perfectly. Very clever and elegant solution. Thank you!
I'm glad it's working, you're more then welcome!
« Last Edit: February 06, 2023, 07:36:13 pm by GetMem »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Can't set title and PreviewText in FontDialog
« Reply #6 on: February 06, 2023, 06:12:49 pm »
You can turn on the hints/informations inside the IDE to see what I copy/paste for you.
Look on my attached image, the pop-up menu.
On second there the text I copied.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

HexLaden

  • New member
  • *
  • Posts: 8
Re: Can't set title and PreviewText in FontDialog
« Reply #7 on: February 06, 2023, 08:30:40 pm »
Quote
You can turn on the hints/informations inside the IDE to see what I copy/paste for you.
My mistake. I haven't read them carefully when I first consulted the object inspector's property tips. They usually point out relevant information.
Quote
OK then, I owe you an apology. Unfortunately there are a lot of annoying spammers lately(the lurker part was a joke).
You were correct: I lurked your code  :) and I played with it:
Code: Pascal  [Select][+][-]
  1.     SetDlgItemTextW(dlgFontHandle,    1, PWideChar('That''s ok'   ));  // Ok btn
  2.     SetDlgItemTextW(dlgFontHandle,    2, PWideChar('Cancel this'  ));  // Cancel btn
  3.     SetDlgItemTextW(dlgFontHandle, 1026, PWideChar('Apply this'   ));  // Apply btn
  4.     SetDlgItemTextW(dlgFontHandle, 1040, PWideChar('Strike it'    ));  // Strikeout
  5.     SetDlgItemTextW(dlgFontHandle, 1041, PWideChar('Line under'   ));  // Underline
  6.     SetDlgItemTextW(dlgFontHandle, 1072, PWideChar('What about...'));  // Efects
  7.     SetDlgItemTextW(dlgFontHandle, 1073, PWideChar('Final effect' ));  // Sample
  8.     SetDlgItemTextW(dlgFontHandle, 1088, PWideChar('Choose font'  ));  // Font
  9.     SetDlgItemTextW(dlgFontHandle, 1089, PWideChar('Style it!'    ));  // Style
  10.     SetDlgItemTextW(dlgFontHandle, 1090, PWideChar('How big?'     ));  // Size
  11.     SetDlgItemTextW(dlgFontHandle, 1091, PWideChar('Colorize'     ));  // Color
  12.     SetDlgItemTextW(dlgFontHandle, 1093, PWideChar('Footnote comment'));
  13.  

Still didn't find how to reach sample 'AaBbCc...' text, thoug.

« Last Edit: February 06, 2023, 08:38:52 pm by HexLaden »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Can't set title and PreviewText in FontDialog
« Reply #8 on: February 06, 2023, 08:55:05 pm »
On Window OS machines you can EnumWindow the PID to compare found HWNDs Text property for "AaBbCc", exemplary as shown with a spy app.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

balazsszekely

  • Guest
Re: Can't set title and PreviewText in FontDialog
« Reply #9 on: February 06, 2023, 09:05:21 pm »
@HexLaden @KodeZwerg
Quote
On Window OS machines you can EnumWindow the PID to compare found HWNDs Text property for "AaBbCc", exemplary as shown with a spy app.
You can easily replace the preview text, but then when the font type, size, etc changes, the font dialog redraws the original text, so you have to change it again.

I attach a demo application which replace the text after the font dialog is shown. I did not go further because honestly it's not worth the effort(at least for me).

« Last Edit: February 06, 2023, 09:36:36 pm by GetMem »

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Can't set title and PreviewText in FontDialog
« Reply #10 on: February 06, 2023, 09:21:39 pm »
... or even worse a lurker.  :D

Heh, good one. Hah! :D

HexLaden

  • New member
  • *
  • Posts: 8
Re: Can't set title and PreviewText in FontDialog
« Reply #11 on: February 06, 2023, 10:41:05 pm »
I intended to understand if and how it would be possible to implement both properties. In the context of the program I'm working on, implementing font prediction would add a small layer of comfort to the user, though it's neither fundamental nor imperative. I agree that the OS solution seems disproportionate. From the example you proposed, I now understood how to reach and replace the text. Thank you very much!

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Can't set title and PreviewText in FontDialog
« Reply #12 on: February 06, 2023, 11:15:55 pm »
@GetMem, nice, but I am not interested in such :-[
@HexLaden, if the systems Dialog ain't fit your needs, you can simple create your own, to start with:
Code: Pascal  [Select][+][-]
  1. ListBox1.Items.AddStrings(Screen.Fonts);
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Can't set title and PreviewText in FontDialog
« Reply #13 on: February 07, 2023, 12:03:35 am »
The Title issue can be fixed.

The Dialog Initiate message can set the title at that point if the given property isn't empty, otherwise it will use the default one.

 Also, I believe one can use the SetWindowText API to also do this at some point.

 But for the Preview/Sample text, that is another story.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Can't set title and PreviewText in FontDialog
« Reply #14 on: February 07, 2023, 12:25:13 am »
jamie, you once submitted a patch for the same Title issue with TColorDialog (https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39155). Could you try to do the same for TFontDialog?

 

TinyPortal © 2005-2018