Jump to content
Carlo Barazzetta

Help: preview of Svg image in Open-Dialog works only with VCLStyle active.

Recommended Posts

I have a question about a problem developing SVGIconImageList components:

At design-time, the component editor cannot show the svg icon preview into the OpenDialog when loading files from "Add..." button.
Compiling the demo, *and* and activating any VCLStyle, the icon is visibile:

image.thumb.png.9acf0a1d741a15a9afd62e875bf2bd21.png

Disabling the VCL style, the preview is not visible also at run-time (I'm using Windows in dark mode):

image.thumb.png.fcffd3c5463b763f0e609f738b6d12ee.png

Could it be possible to have the same functionality at design time? It is very important to see the preview, during selection of svg files using the editor!
Do I need some OpenDialog "hook" to have the preview also in "normal" style?

Thansk for any suggestions.

Carlo

Edited by Carlo Barazzetta

Share this post


Link to post

It should be mentioned that one of the package units registers the new file format:

initialization
  TPicture.RegisterFileFormat('SVG', 'Scalable Vector Graphics', TSVGGraphic);

 

Use PowerToys to get SVG preview at run time when you disable Vcl styles. (Also in File Explorer)

Edited by pyscripter
  • Like 1

Share this post


Link to post
1 hour ago, pyscripter said:

It should be mentioned that one of the package units registers the new file format:


initialization
  TPicture.RegisterFileFormat('SVG', 'Scalable Vector Graphics', TSVGGraphic);

 

Yes! I've notice now that the two Dialog are quite different... but the call is always the same: OpenDialog.Execute.
The TOpenDialog properties:
  object OpenDialog: TOpenPictureDialog
    Filter = 'Scalable Vector Graphics (*.svg)|*.svg'
    Options = [ofHideReadOnly, ofAllowMultiSelect, ofPathMustExist, ofFileMustExist, ofEnableSizing]
    Left = 328
    Top = 96
  end
 

Share this post


Link to post

Ok, I've resolved, with this solution:

I'm using a new class, implementing Execute without call the "inherited" metod, because the "magic" OpenDialog with the preview is activated by :  Template := 'DLGTEMPLATE' but it's used only when TStyleManager.IsCustomStyleActive

Using Template 'DLGTEMPLATE' also without CustomStyleActive shows always the dialog with the preview:
 

TOpenPictureDialogSvg = class(TOpenPictureDialog)

function TOpenPictureDialogSvg.Execute(ParentWnd: HWND): Boolean;
begin
  Template := 'DLGTEMPLATE';
  Result := DoExecute(@GetOpenFileName, ParentWnd);
end;

Not very elegant, but it works...

Edited by Carlo Barazzetta
  • Thanks 1

Share this post


Link to post
On 9/3/2020 at 1:49 PM, Carlo Barazzetta said:

 

Could it be possible to have the same functionality at design time? It is very important to see the preview, during selection of svg files using the editor!
Do I need some OpenDialog "hook" to have the preview also in "normal" style?

Thansk for any suggestions.

Carlo

You need an interface IPreviewHandler implementation in COM DLL that supports displaying SVG-graphics

After that you can use   classic new TOpenDialog

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×